aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/tccgen.c b/tccgen.c
index e86ff4a..3b1336c 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -3874,13 +3874,18 @@ ST_FUNC void unary(void)
}
break;
case TOK_builtin_frame_address:
+ case TOK_builtin_return_address:
{
+ int tok1 = tok;
int level;
CType type;
next();
skip('(');
if (tok != TOK_CINT || tokc.i < 0) {
- tcc_error("__builtin_frame_address only takes positive integers");
+ tcc_error("%s only takes positive integers",
+ tok1 == TOK_builtin_return_address ?
+ "__builtin_return_address" :
+ "__builtin_frame_address");
}
level = tokc.i;
next();
@@ -3892,6 +3897,13 @@ ST_FUNC void unary(void)
mk_pointer(&vtop->type);
indir(); /* -> parent frame */
}
+ if (tok1 == TOK_builtin_return_address) {
+ // assume return address is just above frame pointer on stack
+ vpushi(PTR_SIZE);
+ gen_op('+');
+ mk_pointer(&vtop->type);
+ indir();
+ }
}
break;
#ifdef TCC_TARGET_X86_64