On Fri, Feb 09, 2018 at 05:08:24PM +0100, Paolo Bonzini wrote: > PR sanitizer/84307 > * gcc.dg/asan/pr84307.c: New test.
BTW, your testcase shows a more severe problem, that we actually don't handle compound literals correctly. C99 says that: "If the compound literal occurs outside the body of a function, the object has static storage duration; otherwise, it has automatic storage duration associated with the enclosing block." but if we create an object with automatic storage duration, we don't actually put that object into the scope of the enclosing block, but of the enclosing function, which explains the weird ASAN_MARK UNPOISON present, but corresponding ASAN_MARK POISON not present. The following testcase should IMHO FAIL with -fsanitize=address on the second bar call, but doesn't, even at -O0 without any DSE. When optimizing we because of this don't emit CLOBBER stmts when the compound literal object goes out of scope, and with -fsanitize=address -fsanitize-address-use-after-scope we don't emit the POISON. struct S { int s; } *p; static inline void foo (struct S *x) { p = x; } static inline void bar (void) { p->s = 5; } int main () { { foo (&(struct S) { 1 }); bar (); } { foo (&(struct S) { 2 }); } bar (); return 0; } The following untested patch seems to cure thatm will see how much it will break. 2018-02-13 Jakub Jelinek <ja...@redhat.com> PR sanitizer/84340 * c-decl.c (build_compound_literal): Call pushdecl (decl) even when it is not TREE_STATIC. --- gcc/c/c-decl.c.jj 2018-01-03 10:20:20.114537949 +0100 +++ gcc/c/c-decl.c 2018-02-13 15:17:47.091186077 +0100 @@ -5348,6 +5348,8 @@ build_compound_literal (location_t loc, pushdecl (decl); rest_of_decl_compilation (decl, 1, 0); } + else + pushdecl (decl); if (non_const) { Jakub