2014-06-10 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 10 Jun 2014 14:10:57 +0000 (14:10 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 10 Jun 2014 14:10:57 +0000 (14:10 +0000)
PR middle-end/61456
* tree-ssa-alias.c (nonoverlapping_component_refs_of_decl_p):
Do not use the main variant for the type comparison.
(ncr_compar): Likewise.
(nonoverlapping_component_refs_p): Likewise.

* g++.dg/opt/pr61456.C: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211411 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr61456.C [new file with mode: 0644]
gcc/tree-ssa-alias.c

index 00f23b4..7d37ddb 100644 (file)
@@ -1,3 +1,11 @@
+2014-06-10  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/61456
+       * tree-ssa-alias.c (nonoverlapping_component_refs_of_decl_p):
+       Do not use the main variant for the type comparison.
+       (ncr_compar): Likewise.
+       (nonoverlapping_component_refs_p): Likewise.
+
 2014-06-10  Marcus Shawcroft  <marcus.shawcroft@arm.com>
 
        * config/aarch64/aarch64.c (aarch64_save_or_restore_fprs): Fix
index 175bbeb..f3f1162 100644 (file)
@@ -1,3 +1,8 @@
+2014-06-10  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/61456
+       * g++.dg/opt/pr61456.C: New testcase.
+
 2014-06-10  Dominique d'Humieres <dominiq@lps.ens.fr>
            Mikael Morin <mikael@gcc.gnu.org>
 
diff --git a/gcc/testsuite/g++.dg/opt/pr61456.C b/gcc/testsuite/g++.dg/opt/pr61456.C
new file mode 100644 (file)
index 0000000..14a118b
--- /dev/null
@@ -0,0 +1,26 @@
+// { dg-do compile }
+// { dg-options "-O2 -std=c++11 -Werror=uninitialized" }
+
+int rand ();
+
+class Funcs
+{
+public:
+    int *f1 ();
+    int *f2 ();
+};
+typedef decltype (&Funcs::f1) pfunc;
+
+static int Set (Funcs * f, const pfunc & fp)
+{
+  (f->*fp) ();
+}
+
+void
+Foo ()
+{
+  pfunc fp = &Funcs::f1;
+  if (rand ())
+    fp = &Funcs::f2;
+  Set (0, fp);
+}
index f18cb48..5cc9cb5 100644 (file)
@@ -835,8 +835,8 @@ nonoverlapping_component_refs_of_decl_p (tree ref1, tree ref2)
       /* ??? We cannot simply use the type of operand #0 of the refs here
         as the Fortran compiler smuggles type punning into COMPONENT_REFs
         for common blocks instead of using unions like everyone else.  */
-      tree type1 = TYPE_MAIN_VARIANT (DECL_CONTEXT (field1));
-      tree type2 = TYPE_MAIN_VARIANT (DECL_CONTEXT (field2));
+      tree type1 = DECL_CONTEXT (field1);
+      tree type2 = DECL_CONTEXT (field2);
 
       /* We cannot disambiguate fields in a union or qualified union.  */
       if (type1 != type2 || TREE_CODE (type1) != RECORD_TYPE)
@@ -866,10 +866,8 @@ ncr_compar (const void *field1_, const void *field2_)
 {
   const_tree field1 = *(const_tree *) const_cast <void *>(field1_);
   const_tree field2 = *(const_tree *) const_cast <void *>(field2_);
-  unsigned int uid1
-    = TYPE_UID (TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (field1)));
-  unsigned int uid2
-    = TYPE_UID (TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (field2)));
+  unsigned int uid1 = TYPE_UID (DECL_FIELD_CONTEXT (field1));
+  unsigned int uid2 = TYPE_UID (DECL_FIELD_CONTEXT (field2));
   if (uid1 < uid2)
     return -1;
   else if (uid1 > uid2)
@@ -893,7 +891,7 @@ nonoverlapping_component_refs_p (const_tree x, const_tree y)
   while (TREE_CODE (x) == COMPONENT_REF)
     {
       tree field = TREE_OPERAND (x, 1);
-      tree type = TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (field));
+      tree type = DECL_FIELD_CONTEXT (field);
       if (TREE_CODE (type) == RECORD_TYPE)
        fieldsx.safe_push (field);
       x = TREE_OPERAND (x, 0);
@@ -904,7 +902,7 @@ nonoverlapping_component_refs_p (const_tree x, const_tree y)
   while (TREE_CODE (y) == COMPONENT_REF)
     {
       tree field = TREE_OPERAND (y, 1);
-      tree type = TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (field));
+      tree type = DECL_FIELD_CONTEXT (field);
       if (TREE_CODE (type) == RECORD_TYPE)
        fieldsy.safe_push (TREE_OPERAND (y, 1));
       y = TREE_OPERAND (y, 0);
@@ -915,8 +913,8 @@ nonoverlapping_component_refs_p (const_tree x, const_tree y)
   /* Most common case first.  */
   if (fieldsx.length () == 1
       && fieldsy.length () == 1)
-    return ((TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldsx[0]))
-            == TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldsy[0])))
+    return ((DECL_FIELD_CONTEXT (fieldsx[0])
+            == DECL_FIELD_CONTEXT (fieldsy[0]))
            && fieldsx[0] != fieldsy[0]
            && !(DECL_BIT_FIELD (fieldsx[0]) && DECL_BIT_FIELD (fieldsy[0])));
 
@@ -949,8 +947,8 @@ nonoverlapping_component_refs_p (const_tree x, const_tree y)
     {
       const_tree fieldx = fieldsx[i];
       const_tree fieldy = fieldsy[j];
-      tree typex = TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldx));
-      tree typey = TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldy));
+      tree typex = DECL_FIELD_CONTEXT (fieldx);
+      tree typey = DECL_FIELD_CONTEXT (fieldy);
       if (typex == typey)
        {
          /* We're left with accessing different fields of a structure,