[cfe-commits] r47223 - in /cfe/trunk: CodeGen/CGDecl.cpp CodeGen/CGExpr.cpp test/CodeGen/extern-block-var.c

Lauro Ramos Venancio lauro.venancio at gmail.com
Sat Feb 16 14:30:39 PST 2008


Author: laurov
Date: Sat Feb 16 16:30:38 2008
New Revision: 47223

URL: http://llvm.org/viewvc/llvm-project?rev=47223&view=rev
Log:
Implement extern block var.


Added:
    cfe/trunk/test/CodeGen/extern-block-var.c
Modified:
    cfe/trunk/CodeGen/CGDecl.cpp
    cfe/trunk/CodeGen/CGExpr.cpp

Modified: cfe/trunk/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGDecl.cpp?rev=47223&r1=47222&r2=47223&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/CodeGen/CGDecl.cpp Sat Feb 16 16:30:38 2008
@@ -54,7 +54,8 @@
   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 ||

Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=47223&r1=47222&r2=47223&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Sat Feb 16 16:30:38 2008
@@ -336,9 +336,14 @@
 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)) {

Added: cfe/trunk/test/CodeGen/extern-block-var.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/extern-block-var.c?rev=47223&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/extern-block-var.c (added)
+++ cfe/trunk/test/CodeGen/extern-block-var.c Sat Feb 16 16:30:38 2008
@@ -0,0 +1,6 @@
+// RUN: clang %s -emit-llvm
+
+int f() {
+  extern int a;
+  return a;
+}





More information about the cfe-commits mailing list