diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2008-12-27 16:20:53 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2008-12-27 16:20:53 +0000 |
commit | 3037eda1ef960209980985cb46d3d8b074c40a13 (patch) | |
tree | cc003289d2b8270b5e77edd9fe94c87f0e599269 /lib/Analysis/IPA/Andersens.cpp | |
parent | 7c3f161569293eb626bb0b4619fc6f0f87c921d5 (diff) |
Check that the function prototypes are correct before assuming that the
parameters are pointers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61451 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/IPA/Andersens.cpp')
-rw-r--r-- | lib/Analysis/IPA/Andersens.cpp | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 0cf31abf20..38b29fed0b 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -945,30 +945,40 @@ bool Andersens::AddConstraintsForExternalCall(CallSite CS, Function *F) { 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; |