[llvm-commits] [llvm] r61451 - in /llvm/trunk: lib/Analysis/IPA/Andersens.cpp test/Analysis/Andersens/2008-12-27-BuiltinWrongType.ll

Nick Lewycky nicholas at mxc.ca
Sat Dec 27 08:20:55 PST 2008


Author: nicholas
Date: Sat Dec 27 10:20:53 2008
New Revision: 61451

URL: http://llvm.org/viewvc/llvm-project?rev=61451&view=rev
Log:
Check that the function prototypes are correct before assuming that the 
parameters are pointers.

Added:
    llvm/trunk/test/Analysis/Andersens/2008-12-27-BuiltinWrongType.ll
Modified:
    llvm/trunk/lib/Analysis/IPA/Andersens.cpp

Modified: llvm/trunk/lib/Analysis/IPA/Andersens.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/Andersens.cpp?rev=61451&r1=61450&r2=61451&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/IPA/Andersens.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/Andersens.cpp Sat Dec 27 10:20:53 2008
@@ -945,30 +945,40 @@
       F->getName() == "llvm.memmove" ||
       F->getName() == "memmove") {
 
-    // *Dest = *Src, which requires an artificial graph node to represent the
-    // constraint.  It is broken up into *Dest = temp, temp = *Src
-    unsigned FirstArg = getNode(CS.getArgument(0));
-    unsigned SecondArg = getNode(CS.getArgument(1));
-    unsigned TempArg = GraphNodes.size();
-    GraphNodes.push_back(Node());
-    Constraints.push_back(Constraint(Constraint::Store,
-                                     FirstArg, TempArg));
-    Constraints.push_back(Constraint(Constraint::Load,
-                                     TempArg, SecondArg));
-    // In addition, Dest = Src
-    Constraints.push_back(Constraint(Constraint::Copy,
-                                     FirstArg, SecondArg));
-    return true;
+    const FunctionType *FTy = F->getFunctionType();
+    if (FTy->getNumParams() > 1 && 
+        isa<PointerType>(FTy->getParamType(0)) &&
+        isa<PointerType>(FTy->getParamType(1))) {
+
+      // *Dest = *Src, which requires an artificial graph node to represent the
+      // constraint.  It is broken up into *Dest = temp, temp = *Src
+      unsigned FirstArg = getNode(CS.getArgument(0));
+      unsigned SecondArg = getNode(CS.getArgument(1));
+      unsigned TempArg = GraphNodes.size();
+      GraphNodes.push_back(Node());
+      Constraints.push_back(Constraint(Constraint::Store,
+                                       FirstArg, TempArg));
+      Constraints.push_back(Constraint(Constraint::Load,
+                                       TempArg, SecondArg));
+      // In addition, Dest = Src
+      Constraints.push_back(Constraint(Constraint::Copy,
+                                       FirstArg, SecondArg));
+      return true;
+    }
   }
 
   // Result = Arg0
   if (F->getName() == "realloc" || F->getName() == "strchr" ||
       F->getName() == "strrchr" || F->getName() == "strstr" ||
       F->getName() == "strtok") {
-    Constraints.push_back(Constraint(Constraint::Copy,
-                                     getNode(CS.getInstruction()),
-                                     getNode(CS.getArgument(0))));
-    return true;
+    const FunctionType *FTy = F->getFunctionType();
+    if (FTy->getNumParams() > 0 && 
+        isa<PointerType>(FTy->getParamType(0))) {
+      Constraints.push_back(Constraint(Constraint::Copy,
+                                       getNode(CS.getInstruction()),
+                                       getNode(CS.getArgument(0))));
+      return true;
+    }
   }
 
   return false;

Added: llvm/trunk/test/Analysis/Andersens/2008-12-27-BuiltinWrongType.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/Andersens/2008-12-27-BuiltinWrongType.ll?rev=61451&view=auto

==============================================================================
--- llvm/trunk/test/Analysis/Andersens/2008-12-27-BuiltinWrongType.ll (added)
+++ llvm/trunk/test/Analysis/Andersens/2008-12-27-BuiltinWrongType.ll Sat Dec 27 10:20:53 2008
@@ -0,0 +1,19 @@
+; RUN: llvm-as < %s | opt -anders-aa
+; PR3262
+
+ at .str15 = external global [3 x i8]              ; <[3 x i8]*> [#uses=1]
+
+declare i8* @strtok(...)
+declare i8* @memmove(...)
+
+define void @test1(i8* %want1) nounwind {
+entry:
+        %0 = call i8* (...)* @strtok(i32 0, i8* getelementptr ([3 x i8]* @.str15, i32 0, i32 0)) nounwind               ; <i8*> [#uses=0]
+        unreachable
+}
+
+define void @test2() nounwind {
+entry:
+        %0 = call i8* (...)* @memmove()
+        unreachable
+}





More information about the llvm-commits mailing list