]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
wrong code with points-to and volatile
authorRichard Biener <rguenther@suse.de>
Thu, 16 May 2024 10:35:28 +0000 (12:35 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 16 May 2024 12:44:17 +0000 (14:44 +0200)
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.

gcc/testsuite/gcc.dg/tree-ssa/alias-38.c [new file with mode: 0644]
gcc/tree-ssa-structalias.cc

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 (file)
index 0000000..a5c4149
--- /dev/null
@@ -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" } } */
index bb59c6a7c0236267b1f3ca05c9dde081156dd855..0bac1a1f045ac34be259bdeb5bc64abc30b5168f 100644 (file)
@@ -3575,6 +3575,10 @@ get_constraint_for_1 (tree t, vec<ce_s> *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<ce_s> *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;
       }