authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-02 15:34:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-02 15:34:58-05:00
logf7835000b62fb5b501f1d84c90f56e2aa11bc55a
tree92a0b659ac6f077359ba1e5fbdc1c1de86b297e6
parentea5cedced1aa6bb5e1c1a07fcd16c5bed08c971f
signaturelock-open Commit is signed but in an unrecognized format.

@returnAddress and @frameAddress return usize now


5 files changed, 15 insertions(+), 16 deletions(-)

doc/langref.html.in+6-5
......@@ -6116,7 +6116,7 @@ test "main" {
61166116 {#header_close#}
61176117
61186118 {#header_open|@frameAddress#}
6119 <pre>{#syntax#}@frameAddress(){#endsyntax#}</pre>
6119 <pre>{#syntax#}@frameAddress() usize{#endsyntax#}</pre>
61206120 <p>
61216121 This function returns the base pointer of the current stack frame.
61226122 </p>
......@@ -6482,17 +6482,18 @@ test "call foo" {
64826482 {#header_close#}
64836483
64846484 {#header_open|@returnAddress#}
6485 <pre>{#syntax#}@returnAddress(){#endsyntax#}</pre>
6485 <pre>{#syntax#}@returnAddress() usize{#endsyntax#}</pre>
64866486 <p>
6487 This function returns a pointer to the return address of the current stack
6488 frame.
6487 This function returns the address of the next machine code instruction that will be executed
6488 when the current function returns.
64896489 </p>
64906490 <p>
64916491 The implications of this are target specific and not consistent across
64926492 all platforms.
64936493 </p>
64946494 <p>
6495 This function is only valid within function scope.
6495 This function is only valid within function scope. If the function gets inlined into
6496 a calling function, the returned address will apply to the calling function.
64966497 </p>
64976498 {#header_close#}
64986499 {#header_open|@setAlignStack#}
src/codegen.cpp+4-2
......@@ -4661,7 +4661,8 @@ static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executabl
46614661 IrInstructionReturnAddress *instruction)
46624662{
46634663 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->type_ref);
4664 return LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
4664 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
4665 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->type_ref, "");
46654666}
46664667
46674668static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
......@@ -4682,7 +4683,8 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
46824683 IrInstructionFrameAddress *instruction)
46834684{
46844685 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->type_ref);
4685 return LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
4686 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
4687 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->type_ref, "");
46864688}
46874689
46884690static LLVMValueRef get_handle_fn_val(CodeGen *g) {
src/ir.cpp+2-6
......@@ -20142,18 +20142,14 @@ static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstru
2014220142static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
2014320143 IrInstruction *result = ir_build_return_address(&ira->new_irb,
2014420144 instruction->base.scope, instruction->base.source_node);
20145 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
20146 ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
20147 result->value.type = u8_ptr_const;
20145 result->value.type = ira->codegen->builtin_types.entry_usize;
2014820146 return result;
2014920147}
2015020148
2015120149static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
2015220150 IrInstruction *result = ir_build_frame_address(&ira->new_irb,
2015320151 instruction->base.scope, instruction->base.source_node);
20154 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
20155 ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
20156 result->value.type = u8_ptr_const;
20152 result->value.type = ira->codegen->builtin_types.entry_usize;
2015720153 return result;
2015820154}
2015920155
std/debug/index.zig+2-2
......@@ -171,7 +171,7 @@ pub fn assert(ok: bool) void {
171171
172172pub fn panic(comptime format: []const u8, args: ...) noreturn {
173173 @setCold(true);
174 const first_trace_addr = @ptrToInt(@returnAddress());
174 const first_trace_addr = @returnAddress();
175175 panicExtra(null, first_trace_addr, format, args);
176176}
177177
......@@ -232,7 +232,7 @@ pub const StackIterator = struct {
232232 pub fn init(first_addr: ?usize) StackIterator {
233233 return StackIterator{
234234 .first_addr = first_addr,
235 .fp = @ptrToInt(@frameAddress()),
235 .fp = @frameAddress(),
236236 };
237237 }
238238
std/special/panic.zig+1-1
......@@ -18,7 +18,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
1818 std.os.abort();
1919 },
2020 else => {
21 const first_trace_addr = @ptrToInt(@returnAddress());
21 const first_trace_addr = @returnAddress();
2222 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);
2323 },
2424 }