[cfe-commits] r103904 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGenCXX/references.cpp

Chandler Carruth chandlerc at gmail.com
Sun May 16 02:32:51 PDT 2010


Author: chandlerc
Date: Sun May 16 04:32:51 2010
New Revision: 103904

URL: http://llvm.org/viewvc/llvm-project?rev=103904&view=rev
Log:
When constant folding reference variables with an initializer to the
initializer, don't fold paramters. Their initializers are just default
arguments which can be overridden. This fixes some spectacular regressions due
to more things making it into the constant folding.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/CodeGenCXX/references.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=103904&r1=103903&r2=103904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun May 16 04:32:51 2010
@@ -355,6 +355,10 @@
   } else if (VarDecl* VD = dyn_cast<VarDecl>(E->getDecl())) {
     if (!VD->getType()->isReferenceType())
       return Success(E);
+    // Reference parameters can refer to anything even if they have an
+    // "initializer" in the form of a default argument.
+    if (isa<ParmVarDecl>(VD))
+      return false;
     // FIXME: Check whether VD might be overridden!
     if (const Expr *Init = VD->getAnyInitializer())
       return Visit(const_cast<Expr *>(Init));

Modified: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=103904&r1=103903&r2=103904&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Sun May 16 04:32:51 2010
@@ -155,3 +155,16 @@
 // CHECK: load
 // CHECK: ret
 const int &f2() { return 0; }
+
+// Don't constant fold const reference parameters with default arguments to
+// their default arguments.
+namespace N1 {
+  const int foo = 1;
+  // CHECK: @_ZN2N14test
+  int test(const int& arg = foo) {
+    // Ensure this array is on the stack where we can set values instead of
+    // being a global constant.
+    // CHECK: %args_array = alloca
+    const int* const args_array[] = { &arg };
+  }
+}





More information about the cfe-commits mailing list