diff options
author | Vedant Kumar <vsk@apple.com> | 2015-10-27 21:17:06 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2015-10-27 21:17:06 +0000 |
commit | ad6d6e742316e4ddc0c2879b92c85398b0847e31 (patch) | |
tree | 8000f0baad9981e02888f23e33f1c28c11cb2b8f /llvm/lib/Bitcode | |
parent | b1bb7391660e30ae5d51391407fc9956c4c55fb0 (diff) | |
download | bcm5719-llvm-ad6d6e742316e4ddc0c2879b92c85398b0847e31.tar.gz bcm5719-llvm-ad6d6e742316e4ddc0c2879b92c85398b0847e31.zip |
[IR] Limit bits used for CallingConv::ID, update tests
Use 10 bits to represent calling convention ID's instead of 13, and
update the bitcode compatibility tests accordingly. We now error-out in
the bitcode reader when we see bad calling conv ID's.
Thanks to rnk and dexonsmith for feedback!
Differential Revision: http://reviews.llvm.org/D13826
llvm-svn: 251452
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 318b2368cd9..58b9b4a189a 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3443,11 +3443,14 @@ std::error_code BitcodeReader::parseModule(uint64_t ResumeBit, auto *FTy = dyn_cast<FunctionType>(Ty); if (!FTy) return error("Invalid type for value"); + auto CC = static_cast<CallingConv::ID>(Record[1]); + if (CC & ~CallingConv::MaxID) + return error("Invalid calling convention ID"); Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage, "", TheModule); - Func->setCallingConv(static_cast<CallingConv::ID>(Record[1])); + Func->setCallingConv(CC); bool isProto = Record[2]; uint64_t RawLinkage = Record[3]; Func->setLinkage(getDecodedLinkage(RawLinkage)); @@ -4580,8 +4583,8 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) { I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops, OperandBundles); OperandBundles.clear(); InstructionList.push_back(I); - cast<InvokeInst>(I) - ->setCallingConv(static_cast<CallingConv::ID>(~(1U << 13) & CCInfo)); + cast<InvokeInst>(I)->setCallingConv( + static_cast<CallingConv::ID>(CallingConv::MaxID & CCInfo)); cast<InvokeInst>(I)->setAttributes(PAL); break; } @@ -4965,7 +4968,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) { OperandBundles.clear(); InstructionList.push_back(I); cast<CallInst>(I)->setCallingConv( - static_cast<CallingConv::ID>((~(1U << 14) & CCInfo) >> 1)); + static_cast<CallingConv::ID>((0x7ff & CCInfo) >> 1)); CallInst::TailCallKind TCK = CallInst::TCK_None; if (CCInfo & 1) TCK = CallInst::TCK_Tail; |