re PR c++/51554 (ICE in cp/semantics.c:cxx_eval_indirect_ref with -Wall)
authorJason Merrill <jason@redhat.com>
Wed, 14 Dec 2011 22:26:24 +0000 (17:26 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 14 Dec 2011 22:26:24 +0000 (17:26 -0500)
PR c++/51554
* semantics.c (cxx_eval_indirect_ref): Fix sanity check.

From-SVN: r182346

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/constant1.C [new file with mode: 0644]

index 6677af341ba402c24dad69c3ae121a708a8c39f7..07816eb5c4ff68806fff7b201e50a7ea164934f8 100644 (file)
@@ -1,5 +1,8 @@
 2011-12-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51554
+       * semantics.c (cxx_eval_indirect_ref): Fix sanity check.
+
        PR c++/51248
        * decl.c (copy_type_enum): Also update variants.
        (finish_enum): Allow variants of complete enums.
index 7e1a396332c8ec1c64f77e9d5c7c7be54e817429..ef85e453ad3628378aa7d9f90cb27626259fdc1d 100644 (file)
@@ -7329,9 +7329,15 @@ cxx_eval_indirect_ref (const constexpr_call *call, tree t,
     {
       tree sub = op0;
       STRIP_NOPS (sub);
-      if (TREE_CODE (sub) == ADDR_EXPR
-         || TREE_CODE (sub) == POINTER_PLUS_EXPR)
+      if (TREE_CODE (sub) == POINTER_PLUS_EXPR)
        {
+         sub = TREE_OPERAND (sub, 0);
+         STRIP_NOPS (sub);
+       }
+      if (TREE_CODE (sub) == ADDR_EXPR)
+       {
+         /* We couldn't fold to a constant value.  Make sure it's not
+            something we should have been able to fold.  */
          gcc_assert (!same_type_ignoring_top_level_qualifiers_p
                      (TREE_TYPE (TREE_TYPE (sub)), TREE_TYPE (t)));
          /* DR 1188 says we don't have to deal with this.  */
index e27689288a0be2957b252d2fbfcb8b7a0e32fd0c..f9d8abd887a2e96d4a9822141054f675c350ee0f 100644 (file)
@@ -1,5 +1,8 @@
 2011-12-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51554
+       * g++.dg/init/constant1.C: New.
+
        PR c++/51248
        * g++.dg/other/enum2.C: New.
 
diff --git a/gcc/testsuite/g++.dg/init/constant1.C b/gcc/testsuite/g++.dg/init/constant1.C
new file mode 100644 (file)
index 0000000..386b926
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/51554
+
+typedef unsigned char uint8;
+typedef unsigned int uint32;
+
+const uint32 XX[] = { 1, 3, 7 };
+
+const uint8 V[] = {
+  *(((const uint8*)&XX[0]) + 0),
+  *(((const uint8*)&XX[0]) + 1),
+  *(((const uint8*)&XX[0]) + 2),
+  *(((const uint8*)&XX[0]) + 3),
+  *(((const uint8*)&XX[1]) + 0),
+  *(((const uint8*)&XX[1]) + 1),
+  *(((const uint8*)&XX[1]) + 2),
+  *(((const uint8*)&XX[1]) + 3),
+};