Implement extern block var.

llvm-svn: 47223
This commit is contained in:
Lauro Ramos Venancio 2008-02-16 22:30:38 +00:00
parent 573b3f89e4
commit bada8d4b5b
3 changed files with 16 additions and 4 deletions

View File

@ -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 ||

View File

@ -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)) {

View File

@ -0,0 +1,6 @@
// RUN: clang %s -emit-llvm
int f() {
extern int a;
return a;
}