re PR tree-optimization/47391 (read from const volatile incorrectly eliminated)
authorJakub Jelinek <jakub@redhat.com>
Fri, 21 Jan 2011 12:57:52 +0000 (13:57 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 21 Jan 2011 12:57:52 +0000 (13:57 +0100)
PR tree-optimization/47391
* varpool.c (const_value_known_p): Return false if
decl is volatile.

* gcc.dg/pr47391.c: New test.

From-SVN: r169084

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr47391.c [new file with mode: 0644]
gcc/varpool.c

index acb1eb7c35e2a40441a6bdef520397bab9de0bf9..edfc258e5da3c6b9afef8d82df0b780f2ba5dfce 100644 (file)
@@ -3,6 +3,10 @@
        * tree-ssa-live.c (remove_unused_scope_block_p): Don't remove
        DECL_IGNORED_P non-reg vars if they are used.
 
+       PR tree-optimization/47391
+       * varpool.c (const_value_known_p): Return false if
+       decl is volatile.
+
 2011-01-21  Kai Tietz  <kai.tietz@onevision.com>
 
        PR bootstrap/47215
index 0b2d9e6ee44c2398d70e11a56932892610973db9..02b48bb40bfc763edbeb6c573e6b0a0342c213eb 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/47391
+       * gcc.dg/pr47391.c: New test.
+
 2011-01-21  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * g++.dg/template/char1.C: Use signed char.
diff --git a/gcc/testsuite/gcc.dg/pr47391.c b/gcc/testsuite/gcc.dg/pr47391.c
new file mode 100644 (file)
index 0000000..5ec98f1
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR tree-optimization/47391 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+const volatile int v = 1;
+int i = 0;
+
+void
+foo (void)
+{
+  i = v;
+}
+
+int
+main (void)
+{
+  foo ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "i = 1;" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index d266ce9a8cf1fb10bbbb57e055463aada15e90c1..2e37255636cb224dc7ea22b0fa52821b6952b779 100644 (file)
@@ -1,5 +1,5 @@
 /* Callgraph handling code.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011
    Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
@@ -370,7 +370,7 @@ const_value_known_p (tree decl)
 
   gcc_assert (TREE_CODE (decl) == VAR_DECL);
 
-  if (!TREE_READONLY (decl))
+  if (!TREE_READONLY (decl) || TREE_THIS_VOLATILE (decl))
     return false;
 
   /* Gimplifier takes away constructors of local vars  */