https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81524
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org Status|NEW |RESOLVED Target Milestone|--- |12.0 Resolution|--- |FIXED Blocks| |104077 --- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> --- As far as I can see this works as requested without sanitization in GCC 12: $ (set -x; for p in PARAM RETURN BLOCK; do for m in READ WRITE; do gcc -DTEST_${p}_$m -S -Wall pr81524.c; done; done) + for p in PARAM RETURN BLOCK + for m in READ WRITE + gcc -DTEST_PARAM_READ -S -Wall pr81524.c pr81524.c: In function ‘test_param_local’: pr81524.c:33:7: warning: storing the address of local variable ‘local’ in ‘*pp’ [-Wdangling-pointer=] 33 | *pp = &local; | ~~~~^~~~~~~~ pr81524.c:32:7: note: ‘local’ declared here 32 | int local = 1; | ^~~~~ pr81524.c:32:7: note: ‘pp’ declared here + for m in READ WRITE + gcc -DTEST_PARAM_WRITE -S -Wall pr81524.c pr81524.c: In function ‘test_param_local’: pr81524.c:33:7: warning: storing the address of local variable ‘local’ in ‘*pp’ [-Wdangling-pointer=] 33 | *pp = &local; | ~~~~^~~~~~~~ pr81524.c:32:7: note: ‘local’ declared here 32 | int local = 1; | ^~~~~ pr81524.c:32:7: note: ‘pp’ declared here + for p in PARAM RETURN BLOCK + for m in READ WRITE + gcc -DTEST_RETURN_READ -S -Wall pr81524.c pr81524.c: In function ‘test_return_local’: pr81524.c:42:10: warning: function returns address of local variable [-Wreturn-local-addr] 42 | return &local; | ^~~~~~ + for m in READ WRITE + gcc -DTEST_RETURN_WRITE -S -Wall pr81524.c pr81524.c: In function ‘test_return_local’: pr81524.c:42:10: warning: function returns address of local variable [-Wreturn-local-addr] 42 | return &local; | ^~~~~~ + for p in PARAM RETURN BLOCK + for m in READ WRITE + gcc -DTEST_BLOCK_READ -S -Wall pr81524.c pr81524.c: In function ‘main’: pr81524.c:88:10: warning: using dangling pointer ‘p’ to ‘local’ [-Wdangling-pointer=] 88 | return *p; | ^~ pr81524.c:76:9: note: ‘local’ declared here 76 | int local = 1; | ^~~~~ pr81524.c:81:3: warning: using dangling pointer ‘p’ to ‘local’ [-Wdangling-pointer=] 81 | printf("%d\n", *p); | ^~~~~~~~~~~~~~~~~~ pr81524.c:76:9: note: ‘local’ declared here 76 | int local = 1; | ^~~~~ + for m in READ WRITE + gcc -DTEST_BLOCK_WRITE -S -Wall pr81524.c pr81524.c: In function ‘main’: pr81524.c:88:10: warning: using dangling pointer ‘p’ to ‘local’ [-Wdangling-pointer=] 88 | return *p; | ^~ pr81524.c:76:9: note: ‘local’ declared here 76 | int local = 1; | ^~~~~ pr81524.c:84:6: warning: using dangling pointer ‘p’ to ‘local’ [-Wdangling-pointer=] 84 | *p = 1; | ~~~^~~ pr81524.c:76:9: note: ‘local’ declared here 76 | int local = 1; | ^~~~~ Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104077 [Bug 104077] bogus/missing -Wdangling-pointer