summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGDecl.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-25 20:08:33 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-25 20:08:33 +0000
commit1cdbc5404b408dfe241392dc9c2d25bece69178d (patch)
treec95739ba47416a7e3e56cf9143c1c2adc1f00349 /clang/lib/CodeGen/CGDecl.cpp
parent441f24118a292e1c8052cf0f4308749cef9968cc (diff)
downloadbcm5719-llvm-1cdbc5404b408dfe241392dc9c2d25bece69178d.tar.gz
bcm5719-llvm-1cdbc5404b408dfe241392dc9c2d25bece69178d.zip
Allow constant initializers to reference their defining decl.
- PR3662. llvm-svn: 65472
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r--clang/lib/CodeGen/CGDecl.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 349656f58b8..ee2516a8508 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -106,6 +106,10 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
llvm::GlobalVariable *GV =
CreateStaticBlockVarDecl(D, ".", llvm::GlobalValue::InternalLinkage);
+ // Store into LocalDeclMap before generating initializer to handle
+ // circular references.
+ DMEntry = GV;
+
if (D.getInit()) {
llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), this);
@@ -162,6 +166,11 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
if (D.getAttr<UsedAttr>())
CGM.AddUsedGlobal(GV);
+ // We may have to cast the constant because of the initializer
+ // mismatch above.
+ //
+ // FIXME: It is really dangerous to store this in the map; if anyone
+ // RAUW's the GV uses of this constant will be invalid.
const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType());
const llvm::Type *LPtrTy =
llvm::PointerType::get(LTy, D.getType().getAddressSpace());
OpenPOWER on IntegriCloud