[cfe-commits] r65657 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp CodeGenModule.h

Mike Stump mrs at apple.com
Fri Feb 27 14:42:51 PST 2009


Author: mrs
Date: Fri Feb 27 16:42:30 2009
New Revision: 65657

URL: http://llvm.org/viewvc/llvm-project?rev=65657&view=rev
Log:
Fix PR3612.  We ensure that we add builtins to the GlobalDeclMap and
we ensure that things added to the module can be found even when they
are not in GlobalDeclMap.  The later is for increased flexibility,
should someone want to do something tricky like extern "Ada" in the
same module.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Feb 27 16:42:30 2009
@@ -794,6 +794,8 @@
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)];
   if (!Entry)
+    Entry = getModule().getFunction(getMangledName(D));
+  if (!Entry)
     Entry = EmitForwardFunctionDefinition(D, 0);
 
   return llvm::ConstantExpr::getBitCast(Entry, PTy);
@@ -872,14 +874,14 @@
 
 
 /// getBuiltinLibFunction
-llvm::Function *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) {
+llvm::Value *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) {
   if (BuiltinID > BuiltinFunctions.size())
     BuiltinFunctions.resize(BuiltinID);
   
   // Cache looked up functions.  Since builtin id #0 is invalid we don't reserve
   // a slot for it.
   assert(BuiltinID && "Invalid Builtin ID");
-  llvm::Function *&FunctionSlot = BuiltinFunctions[BuiltinID-1];
+  llvm::Value *&FunctionSlot = BuiltinFunctions[BuiltinID-1];
   if (FunctionSlot)
     return FunctionSlot;
   
@@ -913,8 +915,15 @@
     assert(Existing == 0 && "FIXME: Name collision");
   }
 
+  llvm::GlobalValue *&ExitingFn = GlobalDeclMap[getContext().Idents.get(Name).getName()];
+  if (ExitingFn) {
+    llvm::Function *Fn = dyn_cast<llvm::Function>(ExitingFn);
+    assert(Fn && "builting mixing with non-function");
+    return FunctionSlot = llvm::ConstantExpr::getBitCast(Fn, Ty);
+  }
+
   // FIXME: param attributes for sext/zext etc.
-  return FunctionSlot = 
+  return FunctionSlot = ExitingFn =
     llvm::Function::Create(Ty, llvm::Function::ExternalLinkage, Name,
                            &getModule());
 }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Feb 27 16:42:30 2009
@@ -154,7 +154,7 @@
     int GlobalUniqueCount;
   } Block;
 
-  std::vector<llvm::Function *> BuiltinFunctions;
+  std::vector<llvm::Value *> BuiltinFunctions;
 public:
   CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
                 const llvm::TargetData &TD, Diagnostic &Diags,
@@ -243,7 +243,7 @@
 
   /// getBuiltinLibFunction - Given a builtin id for a function like
   /// "__builtin_fabsf", return a Function* for "fabsf".
-  llvm::Function *getBuiltinLibFunction(unsigned BuiltinID);
+  llvm::Value *getBuiltinLibFunction(unsigned BuiltinID);
 
   llvm::Function *getMemCpyFn();
   llvm::Function *getMemMoveFn();





More information about the cfe-commits mailing list