Fix PR2267, by allowing indirect outputs to be intermixed
[oota-llvm.git] / lib / VMCore / Module.cpp
index c66032388baf4ba23d380f580db06eb0169d46b4..429cf1a4c69508066e17a9f8569a22ce7a21871e 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -23,7 +23,6 @@
 #include <algorithm>
 #include <cstdarg>
 #include <cstdlib>
-#include <map>
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -33,7 +32,7 @@ using namespace llvm;
 Function *ilist_traits<Function>::createSentinel() {
   FunctionType *FTy =
     FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
-  Function *Ret = new Function(FTy, GlobalValue::ExternalLinkage);
+  Function *Ret = Function::Create(FTy, GlobalValue::ExternalLinkage);
   // This should not be garbage monitored.
   LeakDetector::removeGarbageObject(Ret);
   return Ret;
@@ -46,7 +45,8 @@ GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
   return Ret;
 }
 GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
-  GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, GlobalValue::ExternalLinkage);
+  GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
+                                     GlobalValue::ExternalLinkage);
   // This should not be garbage monitored.
   LeakDetector::removeGarbageObject(Ret);
   return Ret;
@@ -149,7 +149,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
   GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
   if (F == 0) {
     // Nope, add it
-    Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
+    Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
     FunctionList.push_back(New);
     return New;                    // Return the new prototype.
   }
@@ -164,8 +164,8 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
 
   // If the function exists but has the wrong type, return a bitcast to the
   // right type.
-  if (F->getType() != PointerType::get(Ty))
-    return ConstantExpr::getBitCast(F, PointerType::get(Ty));
+  if (F->getType() != PointerType::getUnqual(Ty))
+    return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
   
   // Otherwise, we just found the existing function or a prototype.
   return F;  
@@ -298,6 +298,9 @@ void Module::dropAllReferences() {
 
   for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I)
     I->dropAllReferences();
+
+  for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I)
+    I->dropAllReferences();
 }
 
 void Module::addLibrary(const std::string& Lib) {