diff options
author | Lauro Ramos Venancio <lauro.venancio@gmail.com> | 2008-02-16 22:30:38 +0000 |
---|---|---|
committer | Lauro Ramos Venancio <lauro.venancio@gmail.com> | 2008-02-16 22:30:38 +0000 |
commit | fea90b89482aa12168b0a874775255bad89e4013 (patch) | |
tree | dd018fe82a4a214352eb6d5a2c7eab739708ebdf | |
parent | 5a1b0c4d91bd2d846f91121ffd71508b7bb7ddf6 (diff) |
Implement extern block var.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47223 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | CodeGen/CGDecl.cpp | 3 | ||||
-rw-r--r-- | CodeGen/CGExpr.cpp | 11 | ||||
-rw-r--r-- | test/CodeGen/extern-block-var.c | 6 |
3 files changed, 16 insertions, 4 deletions
diff --git a/CodeGen/CGDecl.cpp b/CodeGen/CGDecl.cpp index d8e8f4e1ca..cd31fa7a7d 100644 --- a/CodeGen/CGDecl.cpp +++ b/CodeGen/CGDecl.cpp @@ -54,7 +54,8 @@ void CodeGenFunction::EmitBlockVarDecl(const BlockVarDecl &D) { case VarDecl::Static: return EmitStaticBlockVarDecl(D); case VarDecl::Extern: - assert(0 && "FIXME: should call up to codegenmodule"); + // Don't emit it now, allow it to be emitted lazily on its first use. + return; default: assert((D.getStorageClass() == VarDecl::None || D.getStorageClass() == VarDecl::Auto || diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index 24e929188b..879f29ab60 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -336,9 +336,14 @@ void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst, LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { const ValueDecl *D = E->getDecl(); if (isa<BlockVarDecl>(D) || isa<ParmVarDecl>(D)) { - llvm::Value *V = LocalDeclMap[D]; - assert(V && "BlockVarDecl not entered in LocalDeclMap?"); - return LValue::MakeAddr(V); + const VarDecl *VD = cast<VarDecl>(D); + if (VD->getStorageClass() == VarDecl::Extern) + return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false)); + else { + llvm::Value *V = LocalDeclMap[D]; + assert(V && "BlockVarDecl not entered in LocalDeclMap?"); + return LValue::MakeAddr(V); + } } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false)); } else if (const FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) { diff --git a/test/CodeGen/extern-block-var.c b/test/CodeGen/extern-block-var.c new file mode 100644 index 0000000000..ea8df7bfc6 --- /dev/null +++ b/test/CodeGen/extern-block-var.c @@ -0,0 +1,6 @@ +// RUN: clang %s -emit-llvm + +int f() { + extern int a; + return a; +} |