C++ PATCH for c++/57551 (ICE with undefined constant expression)

Message ID 51DC4917.7030500@redhat.com
State New
Headers show

Commit Message

Jason Merrill July 9, 2013, 5:32 p.m.
In this testcase, we were assuming that if we have an INDIRECT_REF of an 
ADDR_EXPR where the address operand has the same type as the ref, we 
should have been able to fold that away.  We were applying this 
assumption to the offset case as well, for arrays.  But in this testcase 
we're indexing off a pointer to a non-array, so there's nothing there to 
fold to.  The simplest way to fix this ICE is to just drop the array 
handling; I don't think it actually worked, anyway.

Tested x86_64-pc-linux-gnu, applying to trunk, 4.8, 4.7.


commit 42146ead7b57cd197746a23ce71a1feede1a1303
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jul 9 00:28:33 2013 -0400

    	PR c++/57551
    	* semantics.c (cxx_eval_indirect_ref): Don't try to look through
    	a POINTER_PLUS_EXPR for type punning diagnostic.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 0a6c775..9e49060 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7709,11 +7709,6 @@  cxx_eval_indirect_ref (const constexpr_call *call, tree t,
       tree sub = op0;
       STRIP_NOPS (sub);
-      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
diff --git a/gcc/testsuite/g++.dg/expr/const1.C b/gcc/testsuite/g++.dg/expr/const1.C
new file mode 100644
index 0000000..9371b27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/expr/const1.C
@@ -0,0 +1,9 @@ 
+// PR c++/57551
+extern unsigned long ADDR;
+unsigned long f(){
+  const unsigned long* const var=&ADDR;
+  const unsigned long retval=var[1];
+  return retval;