[cfe-commits] r113307 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CGExpr.cpp test/CodeGenObjC/local-static-block.m
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 7 16:26:17 PDT 2010
Author: fjahanian
Date: Tue Sep 7 18:26:17 2010
New Revision: 113307
URL: http://llvm.org/viewvc/llvm-project?rev=113307&view=rev
Log:
Local static block variable referecned in its
block-literal initializer expression causes IRgen to crash.
This patch fixes by saving it in StaticLocalDecl map
already used for such purposes. (radar 8390455).
Added:
cfe/trunk/test/CodeGenObjC/local-static-block.m
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=113307&r1=113306&r2=113307&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Sep 7 18:26:17 2010
@@ -244,6 +244,10 @@
// Make sure to evaluate VLA bounds now so that we have them for later.
if (D.getType()->isVariablyModifiedType())
EmitVLASize(D.getType());
+
+ // Local static block variables must be treated as globals as they may be
+ // referenced in their RHS initializer block-literal expresion.
+ CGM.setStaticLocalDeclAddress(&D, GV);
// If this value has an initializer, emit it.
if (D.getInit())
@@ -266,9 +270,6 @@
if (D.hasAttr<UsedAttr>())
CGM.AddUsedGlobal(GV);
- if (getContext().getLangOptions().CPlusPlus)
- CGM.setStaticLocalDeclAddress(&D, GV);
-
// We may have to cast the constant because of the initializer
// mismatch above.
//
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=113307&r1=113306&r2=113307&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Sep 7 18:26:17 2010
@@ -1152,8 +1152,7 @@
bool NonGCable = VD->hasLocalStorage() && !VD->hasAttr<BlocksAttr>();
llvm::Value *V = LocalDeclMap[VD];
- if (!V && getContext().getLangOptions().CPlusPlus &&
- VD->isStaticLocal())
+ if (!V && VD->isStaticLocal())
V = CGM.getStaticLocalDeclAddress(VD);
assert(V && "DeclRefExpr not entered in LocalDeclMap?");
Added: cfe/trunk/test/CodeGenObjC/local-static-block.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/local-static-block.m?rev=113307&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/local-static-block.m (added)
+++ cfe/trunk/test/CodeGenObjC/local-static-block.m Tue Sep 7 18:26:17 2010
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin -emit-llvm %s -o %t-64.ll
+// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.ll %s
+// rdar: // 8390455
+
+ at class NSArray;
+
+static NSArray *(^ArrayRecurs)(NSArray *addresses, unsigned long level) = ^(NSArray *addresses, unsigned long level) {
+
+ for(id rawAddress in addresses)
+ {
+ NSArray *separatedAddresses = ((NSArray*)0);
+ separatedAddresses = ArrayRecurs((NSArray *)rawAddress, level+1);
+ }
+ return (NSArray *)0;
+};
+
+void FUNC()
+{
+ static NSArray *(^ArrayRecurs)(NSArray *addresses, unsigned long level) = ^(NSArray *addresses, unsigned long level) {
+
+ for(id rawAddress in addresses)
+ {
+ NSArray *separatedAddresses = ((NSArray*)0);
+ separatedAddresses = ArrayRecurs((NSArray *)rawAddress, level+1);
+ }
+ return (NSArray *)0;
+ };
+
+ if (ArrayRecurs) {
+ static NSArray *(^ArrayRecurs)(NSArray *addresses, unsigned long level) = ^(NSArray *addresses, unsigned long level) {
+
+ for(id rawAddress in addresses)
+ {
+ NSArray *separatedAddresses = ((NSArray*)0);
+ separatedAddresses = ArrayRecurs((NSArray *)rawAddress, level+1);
+ }
+ return (NSArray *)0;
+ };
+ }
+}
+
+void FUNC1()
+{
+ static NSArray *(^ArrayRecurs)(NSArray *addresses, unsigned long level) = ^(NSArray *addresses, unsigned long level) {
+
+ for(id rawAddress in addresses)
+ {
+ NSArray *separatedAddresses = ((NSArray*)0);
+ separatedAddresses = ArrayRecurs((NSArray *)rawAddress, level+1);
+ }
+ return (NSArray *)0;
+ };
+}
+// CHECK-LP64: @ArrayRecurs = internal global
+// CHECK-LP64: @FUNC.ArrayRecurs = internal global
+// CHECK-LP64: @FUNC.ArrayRecurs3 = internal global
+// CHECK-LP64: @FUNC1.ArrayRecurs = internal global
More information about the cfe-commits
mailing list