https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91146
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Seems even with that patch 3677 if (stmt_may_clobber_ref_p_1 (def_stmt, ref, tbaa_p)) in tree-ssa-sccvn.c thinks the .ASAN_MARK (UNPOISON, &D.48886, 4); call may clobber MEM[(struct small_vector_template_common *)&v].D.48455.BeginX With the following completely untested patch we optimize like withouf -fsanitize=address and don't warn. --- gcc/internal-fn.def.jj 2020-01-18 13:47:09.517357706 +0100 +++ gcc/internal-fn.def 2020-03-17 16:32:41.210800195 +0100 @@ -309,7 +309,7 @@ DEF_INTERNAL_FN (UBSAN_OBJECT_SIZE, ECF_ DEF_INTERNAL_FN (ABNORMAL_DISPATCHER, ECF_NORETURN, NULL) DEF_INTERNAL_FN (BUILTIN_EXPECT, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (ASAN_CHECK, ECF_TM_PURE | ECF_LEAF | ECF_NOTHROW, "..R..") -DEF_INTERNAL_FN (ASAN_MARK, ECF_LEAF | ECF_NOTHROW, NULL) +DEF_INTERNAL_FN (ASAN_MARK, ECF_LEAF | ECF_NOTHROW, "..W.") DEF_INTERNAL_FN (ASAN_POISON, ECF_LEAF | ECF_NOTHROW | ECF_NOVOPS, NULL) DEF_INTERNAL_FN (ASAN_POISON_USE, ECF_LEAF | ECF_NOTHROW | ECF_NOVOPS, NULL) DEF_INTERNAL_FN (ADD_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) --- gcc/tree-ssa-alias.c.jj 2020-03-03 11:04:46.367821907 +0100 +++ gcc/tree-ssa-alias.c 2020-03-17 17:40:22.295385869 +0100 @@ -3032,6 +3032,14 @@ call_may_clobber_ref_p_1 (gcall *call, a default: /* Fallthru to general call handling. */; } + else if (gimple_call_internal_p (call) + && gimple_call_internal_fn (call) == IFN_ASAN_MARK) + { + ao_ref dref; + tree size = gimple_call_arg (call, 2); + ao_ref_init_from_ptr_and_size (&dref, gimple_call_arg (call, 1), size); + return refs_may_alias_p_1 (&dref, ref, false); + } /* Check if base is a global static variable that is not written by the function. */