fix crash when the malloc/free function is defined or is a declaration with 0 parameters.
authorNuno Lopes <nunoplopes@sapo.pt>
Sat, 6 Sep 2008 17:44:06 +0000 (17:44 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Sat, 6 Sep 2008 17:44:06 +0000 (17:44 +0000)
this pass doesnt seem to be used, but still it's now a little more correct

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55873 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/IndMemRemoval.cpp

index 2e09fe967f4fc88d37fdbcbbd7ca4ff669c7edc3..b251ab4b09c11331673503039d58a8b44c69d1fd 100644 (file)
@@ -51,8 +51,7 @@ bool IndMemRemPass::runOnModule(Module &M) {
   //happen through intrinsics.
   bool changed = false;
   if (Function* F = M.getFunction("free")) {
-    assert(F->isDeclaration() && "free not external?");
-    if (!F->use_empty()) {
+    if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) {
       Function* FN = Function::Create(F->getFunctionType(),
                                       GlobalValue::LinkOnceLinkage,
                                       "free_llvm_bounce", &M);
@@ -66,8 +65,7 @@ bool IndMemRemPass::runOnModule(Module &M) {
     }
   }
   if (Function* F = M.getFunction("malloc")) {
-    assert(F->isDeclaration() && "malloc not external?");
-    if (!F->use_empty()) {
+    if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) {
       Function* FN = Function::Create(F->getFunctionType(), 
                                       GlobalValue::LinkOnceLinkage, 
                                       "malloc_llvm_bounce", &M);