From acdf4048b478f500edd13c6e50ca52376ce55a12 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 9 Feb 2020 22:40:36 -0500 Subject: [PATCH] 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. --- test/compile_errors.zig | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 85491fa0f..53858dd6a 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -5292,25 +5292,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:2:30: error: cannot set section of local variable 'foo'", }); - cases.add("returning address of local variable - simple", - \\export fn foo() *i32 { - \\ var a: i32 = undefined; - \\ return &a; - \\} - , &[_][]const u8{ - "tmp.zig:3:13: error: function returns address of local variable", - }); - - cases.add("returning address of local variable - phi", - \\export fn foo(c: bool) *i32 { - \\ var a: i32 = undefined; - \\ var b: i32 = undefined; - \\ return if (c) &a else &b; - \\} - , &[_][]const u8{ - "tmp.zig:4:12: error: function returns address of local variable", - }); - cases.add("inner struct member shadowing outer struct member", \\fn A() type { \\ return struct {