Fix PR3754: don't mark functions that wrap MallocInst with
authorDuncan Sands <baldrick@free.fr>
Wed, 6 May 2009 08:42:00 +0000 (08:42 +0000)
committerDuncan Sands <baldrick@free.fr>
Wed, 6 May 2009 08:42:00 +0000 (08:42 +0000)
the readnone.  Since MallocInst is scheduled for deletion
it doesn't seem worth doing anything more subtle, such as
having mayWriteToMemory return true for MallocInst.

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

lib/Transforms/IPO/FunctionAttrs.cpp
test/Transforms/FunctionAttrs/2009-05-06-Malloc.ll [new file with mode: 0644]

index 65faef32e5e2b5df4d149102649886af7e7825f7..e8315247b23cbf2567c2d94b2c9cef9c71b5463a 100644 (file)
@@ -152,6 +152,11 @@ bool FunctionAttrs::AddReadAttrs(const std::vector<CallGraphNode *> &SCC) {
       if (I->mayWriteToMemory())
         // Writes memory.  Just give up.
         return false;
+
+      if (isa<MallocInst>(I))
+        // MallocInst claims not to write memory!  PR3754.
+        return false;
+
       // If this instruction may read memory, remember that.
       ReadsMemory |= I->mayReadFromMemory();
     }
diff --git a/test/Transforms/FunctionAttrs/2009-05-06-Malloc.ll b/test/Transforms/FunctionAttrs/2009-05-06-Malloc.ll
new file mode 100644 (file)
index 0000000..4022033
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep read
+; PR3754
+
+define i8* @m(i32 %size) {
+       %tmp = malloc i8, i32 %size             ; <i8*> [#uses=1]
+       ret i8* %tmp
+}