[cfe-commits] r44507 - /cfe/trunk/CodeGen/CodeGenModule.cpp

Chris Lattner sabre at nondot.org
Sat Dec 1 22:30:47 PST 2007


Author: lattner
Date: Sun Dec  2 00:30:46 2007
New Revision: 44507

URL: http://llvm.org/viewvc/llvm-project?rev=44507&view=rev
Log:
merge the llvm global variable when there are multiple C decls.

Modified:
    cfe/trunk/CodeGen/CodeGenModule.cpp

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Sun Dec  2 00:30:46 2007
@@ -51,21 +51,28 @@
   QualType ASTTy = cast<ValueDecl>(D)->getType();
   const llvm::Type *Ty = getTypes().ConvertType(ASTTy);
   if (isa<FunctionDecl>(D)) {
-    const llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
-    
     // Check to see if the function already exists.
     if (llvm::Function *F = getModule().getFunction(D->getName())) {
       // If so, make sure it is the correct type.
-      return llvm::ConstantExpr::getBitCast(F, llvm::PointerType::get(FTy));
+      return Entry = llvm::ConstantExpr::getBitCast(F,
+                                                    llvm::PointerType::get(Ty));
     }
     
     // FIXME: param attributes for sext/zext etc.
+    const llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
     return Entry = new llvm::Function(FTy, llvm::Function::ExternalLinkage,
                                       D->getName(), &getModule());
   }
   
   assert(isa<FileVarDecl>(D) && "Unknown global decl!");
   
+  if (llvm::GlobalVariable *GV = getModule().getGlobalVariable(D->getName())) {
+    // If so, make sure it is the correct type.
+    return Entry = llvm::ConstantExpr::getBitCast(GV,
+                                                  llvm::PointerType::get(Ty));
+    
+  }
+  
   return Entry = new llvm::GlobalVariable(Ty, false, 
                                           llvm::GlobalValue::ExternalLinkage,
                                           0, D->getName(), &getModule());





More information about the cfe-commits mailing list