diff --git a/doc/langref.html.in b/doc/langref.html.in index 959bbcfc07..b816d65289 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -6116,7 +6116,7 @@ test "main" { {#header_close#} {#header_open|@frameAddress#} -
{#syntax#}@frameAddress(){#endsyntax#}
+ {#syntax#}@frameAddress() usize{#endsyntax#}
This function returns the base pointer of the current stack frame.
@@ -6482,17 +6482,18 @@ test "call foo" { {#header_close#} {#header_open|@returnAddress#} -{#syntax#}@returnAddress(){#endsyntax#}
+ {#syntax#}@returnAddress() usize{#endsyntax#}
- This function returns a pointer to the return address of the current stack - frame. + This function returns the address of the next machine code instruction that will be executed + when the current function returns.
The implications of this are target specific and not consistent across all platforms.
- This function is only valid within function scope. + This function is only valid within function scope. If the function gets inlined into + a calling function, the returned address will apply to the calling function.
{#header_close#} {#header_open|@setAlignStack#} diff --git a/src/codegen.cpp b/src/codegen.cpp index 52e20108de..071dd1fde4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4661,7 +4661,8 @@ static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executabl IrInstructionReturnAddress *instruction) { LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->type_ref); - return LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, ""); + LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, ""); + return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->type_ref, ""); } static LLVMValueRef get_frame_address_fn_val(CodeGen *g) { @@ -4682,7 +4683,8 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable IrInstructionFrameAddress *instruction) { LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->type_ref); - return LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, ""); + LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, ""); + return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->type_ref, ""); } static LLVMValueRef get_handle_fn_val(CodeGen *g) { diff --git a/src/ir.cpp b/src/ir.cpp index e081b4b052..4e07221ecd 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -20142,18 +20142,14 @@ static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstru static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { IrInstruction *result = ir_build_return_address(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - ZigType *u8 = ira->codegen->builtin_types.entry_u8; - ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); - result->value.type = u8_ptr_const; + result->value.type = ira->codegen->builtin_types.entry_usize; return result; } static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { IrInstruction *result = ir_build_frame_address(&ira->new_irb, instruction->base.scope, instruction->base.source_node); - ZigType *u8 = ira->codegen->builtin_types.entry_u8; - ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); - result->value.type = u8_ptr_const; + result->value.type = ira->codegen->builtin_types.entry_usize; return result; } diff --git a/std/debug/index.zig b/std/debug/index.zig index 538fb5ef28..1523eea57c 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -171,7 +171,7 @@ pub fn assert(ok: bool) void { pub fn panic(comptime format: []const u8, args: ...) noreturn { @setCold(true); - const first_trace_addr = @ptrToInt(@returnAddress()); + const first_trace_addr = @returnAddress(); panicExtra(null, first_trace_addr, format, args); } @@ -232,7 +232,7 @@ pub const StackIterator = struct { pub fn init(first_addr: ?usize) StackIterator { return StackIterator{ .first_addr = first_addr, - .fp = @ptrToInt(@frameAddress()), + .fp = @frameAddress(), }; } diff --git a/std/special/panic.zig b/std/special/panic.zig index bd3ad971e0..7cb7143955 100644 --- a/std/special/panic.zig +++ b/std/special/panic.zig @@ -18,7 +18,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn std.os.abort(); }, else => { - const first_trace_addr = @ptrToInt(@returnAddress()); + const first_trace_addr = @returnAddress(); std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg); }, }