From ad6d6e742316e4ddc0c2879b92c85398b0847e31 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 27 Oct 2015 21:17:06 +0000 Subject: [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 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 318b236..58b9b4a 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(Ty); if (!FTy) return error("Invalid type for value"); + auto CC = static_cast(Record[1]); + if (CC & ~CallingConv::MaxID) + return error("Invalid calling convention ID"); Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage, "", TheModule); - Func->setCallingConv(static_cast(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(I) - ->setCallingConv(static_cast(~(1U << 13) & CCInfo)); + cast(I)->setCallingConv( + static_cast(CallingConv::MaxID & CCInfo)); cast(I)->setAttributes(PAL); break; } @@ -4965,7 +4968,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) { OperandBundles.clear(); InstructionList.push_back(I); cast(I)->setCallingConv( - static_cast((~(1U << 14) & CCInfo) >> 1)); + static_cast((0x7ff & CCInfo) >> 1)); CallInst::TailCallKind TCK = CallInst::TCK_None; if (CCInfo & 1) TCK = CallInst::TCK_Tail; -- cgit v1.1