From 89e19b43b81a6b5d092a81d2ebf6ec9a4097a48d Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 3 Jan 2013 00:39:26 +0000 Subject: [PATCH] Don't assert/crash on reference variables in lambdas bound to a static local variable from the parent scope. PR14773. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171433 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 6 ++---- lib/CodeGen/CodeGenFunction.h | 5 ----- test/CodeGenCXX/lambda-expressions.cpp | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index f5bf2a2fe7..7a604013b7 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -905,10 +905,8 @@ public: 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; diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index e8f70555c5..acc12fe6b6 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1687,11 +1687,6 @@ public: /// 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(GetAddrOfLocalVar(BVD)); - } - /// GetAddrOfLocalVar - Return the address of a local variable. llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) { llvm::Value *Res = LocalDeclMap[VD]; diff --git a/test/CodeGenCXX/lambda-expressions.cpp b/test/CodeGenCXX/lambda-expressions.cpp index a8967dce80..ce20399c57 100644 --- a/test/CodeGenCXX/lambda-expressions.cpp +++ b/test/CodeGenCXX/lambda-expressions.cpp @@ -80,9 +80,20 @@ int g() { 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() { -- 2.40.0