diff options
author | Edwin Török <edwintorok@gmail.com> | 2009-05-22 06:41:43 +0000 |
---|---|---|
committer | Edwin Török <edwintorok@gmail.com> | 2009-05-22 06:41:43 +0000 |
commit | a12c6a01d7b0dda0c13edc54e295a73b4bc8f0a5 (patch) | |
tree | 8a078c880c88e5a08dc99cb8904b6df94a927b00 /lib/VMCore | |
parent | ed2d10bf4a93e0f7e05bc782e5291cfa707f6b80 (diff) | |
download | external_llvm-a12c6a01d7b0dda0c13edc54e295a73b4bc8f0a5.zip external_llvm-a12c6a01d7b0dda0c13edc54e295a73b4bc8f0a5.tar.gz external_llvm-a12c6a01d7b0dda0c13edc54e295a73b4bc8f0a5.tar.bz2 |
Verify that calling conventions match function prototype.
This only rejects mismatches between target specific calling convention
and C/LLVM specific calling convention.
There are too many fastcc/C, coldcc/cc42 mismatches in the testsuite, these are
not reject by the verifier.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72248 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Verifier.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index fc4cfcf..65d0a82 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -1024,6 +1024,31 @@ void Verifier::VerifyCallSite(CallSite CS) { "Call parameter type does not match function signature!", CS.getArgument(i), FTy->getParamType(i), I); + Assert2(CS.getType() == FTy->getReturnType(), + "Call return type does not match function signature!", + CS.getInstruction(), FTy->getReturnType()); + + // Verify calling convention for direct calls + Value *CalledF = CS.getCalledValue()->stripPointerCasts(); + if (Function *F = dyn_cast<Function>(CalledF)) { + unsigned CC1 = CS.getCallingConv(); + unsigned CC2 = F->getCallingConv(); + if(CC1 != CC2) { + // tolerate some mismatch among C prototype and LLVM-specific calling conv + if (CC2 >= CallingConv::FirstTargetCC || + CC1 >= CallingConv::FirstTargetCC) { + Instruction *I = CS.getInstruction()->clone(); + if (CallInst *CI = dyn_cast<CallInst>(I)) { + CI->setCallingConv(F->getCallingConv()); + } else + cast<InvokeInst>(I)->setCallingConv(F->getCallingConv()); + Assert2(0,"Calling convention does not match function signature!", + CS.getInstruction(), I); + delete I; + } + } + } + if (CS.getCalledValue()->getNameLen() < 5 || strncmp(CS.getCalledValue()->getNameStart(), "llvm.", 5) != 0) { // Verify that none of the arguments are metadata... |