[cfe-commits] r171433 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/lambda-expressions.cpp

Eli Friedman eli.friedman at gmail.com
Wed Jan 2 16:39:27 PST 2013


Author: efriedma
Date: Wed Jan  2 18:39:26 2013
New Revision: 171433

URL: http://llvm.org/viewvc/llvm-project?rev=171433&view=rev
Log:
Don't assert/crash on reference variables in lambdas bound to a
static local variable from the parent scope.  PR14773.


Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=171433&r1=171432&r2=171433&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed Jan  2 18:39:26 2013
@@ -905,10 +905,8 @@
         if (!VD->hasLocalStorage()) {
           if (VD->isFileVarDecl() || VD->hasExternalStorage())
             return CGM.GetAddrOfGlobalVar(VD);
-          else if (VD->isLocalVarDecl()) {
-            assert(CGF && "Can't access static local vars without CGF");
-            return CGF->GetAddrOfStaticLocalVar(VD);
-          }
+          else if (VD->isLocalVarDecl())
+            return CGM.getStaticLocalDeclAddress(VD);
         }
       }
       return 0;

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=171433&r1=171432&r2=171433&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Jan  2 18:39:26 2013
@@ -1687,11 +1687,6 @@
   /// then reuse it.
   void StartBlock(const char *N);
 
-  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
-  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD) {
-    return cast<llvm::Constant>(GetAddrOfLocalVar(BVD));
-  }
-
   /// GetAddrOfLocalVar - Return the address of a local variable.
   llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) {
     llvm::Value *Res = LocalDeclMap[VD];

Modified: cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=171433&r1=171432&r2=171433&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp Wed Jan  2 18:39:26 2013
@@ -80,9 +80,20 @@
   return [] { return r; } ();
 };
 
-// CHECK: define internal void @"_ZZ1hvEN3$_78__invokeEv"(%struct.A* noalias sret %agg.result)
+// PR14773
+// CHECK: [[ARRVAL:%[0-9a-zA-Z]*]] = load i32* getelementptr inbounds ([0 x i32]* bitcast (<{}>* @_ZZ14staticarrayrefvE5array to [0 x i32]*), i32 0, i64 0), align 4
+// CHECK-NEXT: store i32 [[ARRVAL]]
+void staticarrayref(){
+  static int array[] = {};
+  (void)[](){
+    int (&xxx)[0] = array;
+    int y = xxx[0];
+  }();
+}
+
+// CHECK: define internal void @"_ZZ1hvEN3$_88__invokeEv"(%struct.A* noalias sret %agg.result)
 // CHECK-NOT: =
-// CHECK: call void @"_ZZ1hvENK3$_7clEv"(%struct.A* sret %agg.result,
+// CHECK: call void @"_ZZ1hvENK3$_8clEv"(%struct.A* sret %agg.result,
 // CHECK-NEXT: ret void
 struct A { ~A(); };
 void h() {





More information about the cfe-commits mailing list