[cfe-commits] r95262 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGenCXX/member-initializers.cpp

Anders Carlsson andersca at mac.com
Wed Feb 3 13:58:41 PST 2010


Author: andersca
Date: Wed Feb  3 15:58:41 2010
New Revision: 95262

URL: http://llvm.org/viewvc/llvm-project?rev=95262&view=rev
Log:
Don't try to fold DeclRefExprs that point to ParmVarDecls. This had the side-effect of always folding the expression to the default argument of the parameter. For example:

void f(int a = 10) {
  return a;
}

would always return 10, regardless of the passed in argument.

This fixes another 600 test failures. We're now down to only 137 failures!

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/CodeGenCXX/member-initializers.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=95262&r1=95261&r2=95262&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Feb  3 15:58:41 2010
@@ -878,6 +878,10 @@
   // In C, they can also be folded, although they are not ICEs.
   if (Info.Ctx.getCanonicalType(E->getType()).getCVRQualifiers() 
                                                         == Qualifiers::Const) {
+
+    if (isa<ParmVarDecl>(D))
+      return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E);
+
     if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
       if (const Expr *Init = VD->getAnyInitializer()) {
         if (APValue *V = VD->getEvaluatedValue()) {

Modified: cfe/trunk/test/CodeGenCXX/member-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-initializers.cpp?rev=95262&r1=95261&r2=95262&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-initializers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-initializers.cpp Wed Feb  3 15:58:41 2010
@@ -20,3 +20,15 @@
   return b.i;
 }
 
+// Test that we don't try to fold the default value of j when initializing i.
+// CHECK: define i32 @_Z9test_foldv() nounwind
+int test_fold() {
+  struct A {
+    A(const int j = 1) : i(j) { } 
+    int i;
+  };
+
+  // CHECK: ret i32 2
+  return A(2).i;
+}
+





More information about the cfe-commits mailing list