authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-09 22:40:36-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-09 22:40:36-05:00
logacdf4048b478f500edd13c6e50ca52376ce55a12
tree4314be4e87c91b45e519d3d2942b58ba7febfc36
parent5ea79bfc4a0a1269930d98faee36a8f6cb0b0401
signaturelock-open Commit is signed but in an unrecognized format.

allow local variable address detection to regress

See #3180 for a more comprehensive plan to catch this problem. More sophisticated control flow analysis is needed to provide compile errors for returning local variable addresses from a function.

1 files changed, 0 insertions(+), 19 deletions(-)

test/compile_errors.zig-19
......@@ -5292,25 +5292,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
52925292 "tmp.zig:2:30: error: cannot set section of local variable 'foo'",
52935293 });
52945294
5295 cases.add("returning address of local variable - simple",
5296 \\export fn foo() *i32 {
5297 \\ var a: i32 = undefined;
5298 \\ return &a;
5299 \\}
5300 , &[_][]const u8{
5301 "tmp.zig:3:13: error: function returns address of local variable",
5302 });
5303
5304 cases.add("returning address of local variable - phi",
5305 \\export fn foo(c: bool) *i32 {
5306 \\ var a: i32 = undefined;
5307 \\ var b: i32 = undefined;
5308 \\ return if (c) &a else &b;
5309 \\}
5310 , &[_][]const u8{
5311 "tmp.zig:4:12: error: function returns address of local variable",
5312 });
5313
53145295 cases.add("inner struct member shadowing outer struct member",
53155296 \\fn A() type {
53165297 \\ return struct {