From: Richard Biener Date: Thu, 16 May 2024 10:35:28 +0000 (+0200) Subject: wrong code with points-to and volatile X-Git-Tag: basepoints/gcc-16~8974 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9251ab3c91c8c559d0306838575a666ae62dff4;p=thirdparty%2Fgcc.git wrong code with points-to and volatile The following fixes points-to analysis which ignores the fact that volatile qualified refs can result in any pointer. * tree-ssa-structalias.cc (get_constraint_for_1): For volatile referenced or decls use ANYTHING. * gcc.dg/tree-ssa/alias-38.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-38.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-38.c new file mode 100644 index 00000000000..a5c41493473 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-38.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int x; +int y; + +int main () +{ + int *volatile p = &x; + return (p != &y); +} + +/* { dg-final { scan-tree-dump " != &y" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "return 1;" "optimized" } } */ diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc index bb59c6a7c02..0bac1a1f045 100644 --- a/gcc/tree-ssa-structalias.cc +++ b/gcc/tree-ssa-structalias.cc @@ -3575,6 +3575,10 @@ get_constraint_for_1 (tree t, vec *results, bool address_p, } case tcc_reference: { + if (TREE_THIS_VOLATILE (t)) + /* Fall back to anything. */ + break; + switch (TREE_CODE (t)) { case MEM_REF: @@ -3676,6 +3680,9 @@ get_constraint_for_1 (tree t, vec *results, bool address_p, } case tcc_declaration: { + if (VAR_P (t) && TREE_THIS_VOLATILE (t)) + /* Fall back to anything. */ + break; get_constraint_for_ssa_var (t, results, address_p); return; }