[cfe-commits] r67484 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/builtins.c

Chris Lattner sabre at nondot.org
Sun Mar 22 14:56:56 PDT 2009


Author: lattner
Date: Sun Mar 22 16:56:56 2009
New Revision: 67484

URL: http://llvm.org/viewvc/llvm-project?rev=67484&view=rev
Log:
switch getBuiltinLibFunction to use the new GetOrCreateLLVMFunction 
functionality, fixing a crash on the attached testcase.  Eliminate the
BuiltinFunctions cache, as it can contain dangling pointers.  This fixes
a bunch of valgrind errors on test/CodeGen/builtins.c

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/test/CodeGen/builtins.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Mar 22 16:56:56 2009
@@ -929,18 +929,9 @@
 }
 
 
-/// getBuiltinLibFunction
+/// getBuiltinLibFunction - Given a builtin id for a function like
+/// "__builtin_fabsf", return a Function* for "fabsf".
 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::Value *&FunctionSlot = BuiltinFunctions[BuiltinID-1];
-  if (FunctionSlot)
-    return FunctionSlot;
-  
   assert((Context.BuiltinInfo.isLibFunction(BuiltinID) ||
           Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) && 
          "isn't a lib fn");
@@ -958,27 +949,10 @@
   const llvm::FunctionType *Ty = 
     cast<llvm::FunctionType>(getTypes().ConvertType(Type));
 
-  // FIXME: This has a serious problem with code like this:
-  //  void abs() {}
-  //    ... __builtin_abs(x);
-  // The two versions of abs will collide.  The fix is for the builtin to win,
-  // and for the existing one to be turned into a constantexpr cast of the
-  // builtin.  In the case where the existing one is a static function, it
-  // should just be renamed.
-  if (llvm::Function *Existing = getModule().getFunction(Name)) {
-    if (Existing->getFunctionType() == Ty && Existing->hasExternalLinkage())
-      return FunctionSlot = Existing;
-    assert(Existing == 0 && "FIXME: Name collision");
-  }
-
-  llvm::GlobalValue *&ExistingFn =
-    GlobalDeclMap[getContext().Idents.get(Name).getName()];
-  assert(!ExistingFn && "Asking for the same builtin multiple times?");
-
+  // Unique the name through the identifier table.
+  Name = getContext().Idents.get(Name).getName();
   // FIXME: param attributes for sext/zext etc.
-  return FunctionSlot = ExistingFn =
-    llvm::Function::Create(Ty, llvm::Function::ExternalLinkage, Name,
-                           &getModule());
+  return GetOrCreateLLVMFunction(Name, Ty, 0);
 }
 
 llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Sun Mar 22 16:56:56 2009
@@ -137,11 +137,6 @@
   /// CFConstantStringClassRef - Cached reference to the class for constant
   /// strings. This value has type int * but is actually an Obj-C class pointer.
   llvm::Constant *CFConstantStringClassRef;
-
-  /// BuiltinFunctions - This is the cached set of Function*'s that have been
-  /// created for each builtin, indexed by the Builtin ID.  This is null if the
-  /// Function* has not yet been created.
-  std::vector<llvm::Value *> BuiltinFunctions;
 public:
   CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
                 const llvm::TargetData &TD, Diagnostic &Diags,

Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=67484&r1=67483&r2=67484&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Sun Mar 22 16:56:56 2009
@@ -112,3 +112,11 @@
   return 0;
 }
 
+
+
+void strcat() {}
+
+void foo() {
+ __builtin_strcat(0, 0);
+}
+





More information about the cfe-commits mailing list