[cfe-commits] r62139 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/private-extern.c

Daniel Dunbar daniel at zuster.org
Mon Jan 12 18:25:01 PST 2009


Author: ddunbar
Date: Mon Jan 12 20:25:00 2009
New Revision: 62139

URL: http://llvm.org/viewvc/llvm-project?rev=62139&view=rev
Log:
Bug fix, __private_extern__ globals were always introducing a definition.

Added:
    cfe/trunk/test/CodeGen/private-extern.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=62139&r1=62138&r2=62139&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jan 12 20:25:00 2009
@@ -150,14 +150,14 @@
 /// AddGlobalCtor - Add a function to the list that will be called before
 /// main() runs.
 void CodeGenModule::AddGlobalCtor(llvm::Function * Ctor, int Priority) {
-  // TODO: Type coercion of void()* types.
+  // FIXME: Type coercion of void()* types.
   GlobalCtors.push_back(std::make_pair(Ctor, Priority));
 }
 
 /// AddGlobalDtor - Add a function to the list that will be called
 /// when the module is unloaded.
 void CodeGenModule::AddGlobalDtor(llvm::Function * Dtor, int Priority) {
-  // TODO: Type coercion of void()* types.
+  // FIXME: Type coercion of void()* types.
   GlobalDtors.push_back(std::make_pair(Dtor, Priority));
 }
 
@@ -214,7 +214,7 @@
                                      bool IsInline,
                                      llvm::GlobalValue *GV,
                                      bool ForDefinition) {
-  // TODO: Set up linkage and many other things.  Note, this is a simple 
+  // FIXME: Set up linkage and many other things.  Note, this is a simple 
   // approximation of what we really want.
   if (!ForDefinition) {
     // Only a few attributes are set on declarations.
@@ -247,6 +247,8 @@
     }
   }
 
+  // FIXME: Figure out the relative priority of the attribute,
+  // -fvisibility, and private_extern.
   if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
     setGlobalVisibility(GV, attr->getVisibility());
   // FIXME: else handle -fvisibility
@@ -451,7 +453,9 @@
   } else if (const VarDecl *VD = cast<VarDecl>(Global)) {
     assert(VD->isFileVarDecl() && "Cannot emit local var decl as global.");
 
-    isDef = !(VD->getStorageClass() == VarDecl::Extern && VD->getInit() == 0);
+    isDef = !((VD->getStorageClass() == VarDecl::Extern ||
+               VD->getStorageClass() == VarDecl::PrivateExtern) && 
+              VD->getInit() == 0);
     isStatic = VD->getStorageClass() == VarDecl::Static;
   } else {
     assert(0 && "Invalid argument to EmitGlobal");
@@ -492,11 +496,24 @@
 
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *&Entry = GlobalDeclMap[D->getIdentifier()];
-  if (!Entry)
-    Entry = new llvm::GlobalVariable(Ty, false, 
-                                     llvm::GlobalValue::ExternalLinkage,
-                                     0, D->getNameAsString(), &getModule(), 0,
-                                     ASTTy.getAddressSpace());
+  if (!Entry) {
+    llvm::GlobalVariable *GV = 
+      new llvm::GlobalVariable(Ty, false, 
+                               llvm::GlobalValue::ExternalLinkage,
+                               0, D->getNameAsString(), &getModule(), 0,
+                               ASTTy.getAddressSpace());
+    Entry = GV;
+
+    // Handle things which are present even on external declarations.
+
+    // FIXME: This code is overly simple and should be merged with
+    // other global handling.
+
+    GV->setConstant(D->getType().isConstant(Context));
+
+    if (D->getStorageClass() == VarDecl::PrivateExtern)
+      setGlobalVisibility(GV, VisibilityAttr::HiddenVisibility);
+  }
   
   // Make sure the result is of the correct type.
   return llvm::ConstantExpr::getBitCast(Entry, PTy);
@@ -626,8 +643,12 @@
         GV->setLinkage(llvm::GlobalVariable::ExternalLinkage);
       break;
     case VarDecl::Extern:
+      // FIXME: common
+      break;
+      
     case VarDecl::PrivateExtern:
-      // todo: common
+      GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+      // FIXME: common
       break;
     }
   }

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

==============================================================================
--- cfe/trunk/test/CodeGen/private-extern.c (added)
+++ cfe/trunk/test/CodeGen/private-extern.c Mon Jan 12 20:25:00 2009
@@ -0,0 +1,10 @@
+// RUN: clang -emit-llvm -o %t %s &&
+// RUN: grep '@g0 = external hidden constant i32' %t &&
+// RUN: grep '@g1 = hidden constant i32 1' %t
+
+__private_extern__ const int g0;
+__private_extern__ const int g1 = 1;
+
+int f0(void) {
+  return g0;
+}





More information about the cfe-commits mailing list