]> granicus.if.org Git - clang/commitdiff
Don't try to fold DeclRefExprs that point to ParmVarDecls. This had the side-effect...
authorAnders Carlsson <andersca@mac.com>
Wed, 3 Feb 2010 21:58:41 +0000 (21:58 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 3 Feb 2010 21:58:41 +0000 (21:58 +0000)
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!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95262 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/CodeGenCXX/member-initializers.cpp

index a0b2aa993faa746b4aab1d1a001e4c2e45939c54..382bfe59b5b71a1d01406c4f2c8e543f47c29daa 100644 (file)
@@ -878,6 +878,10 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
   // 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()) {
index 1a27b7d202d5dfd9d3ba7ba95fdf76ff7c2a8c11..81dcee7e407a0658d6d2bb21e1f31307707c06b9 100644 (file)
@@ -20,3 +20,15 @@ int f() {
   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;
+}
+