Check that the function prototypes are correct before assuming that the
parameters are pointers. llvm-svn: 61451
This commit is contained in:
parent
1d1087113c
commit
d80ff135b5
|
@ -945,6 +945,11 @@ bool Andersens::AddConstraintsForExternalCall(CallSite CS, Function *F) {
|
|||
F->getName() == "llvm.memmove" ||
|
||||
F->getName() == "memmove") {
|
||||
|
||||
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));
|
||||
|
@ -960,16 +965,21 @@ bool Andersens::AddConstraintsForExternalCall(CallSite CS, Function *F) {
|
|||
FirstArg, SecondArg));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Result = Arg0
|
||||
if (F->getName() == "realloc" || F->getName() == "strchr" ||
|
||||
F->getName() == "strrchr" || F->getName() == "strstr" ||
|
||||
F->getName() == "strtok") {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
; RUN: llvm-as < %s | opt -anders-aa
|
||||
; PR3262
|
||||
|
||||
@.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
|
||||
}
|
Loading…
Reference in New Issue