Index: llvm/trunk/include/llvm/IR/CallingConv.h =================================================================== --- llvm/trunk/include/llvm/IR/CallingConv.h +++ llvm/trunk/include/llvm/IR/CallingConv.h @@ -156,7 +156,10 @@ HHVM = 81, /// \brief HHVM calling convention for invoking C/C++ helpers. - HHVM_C = 82 + HHVM_C = 82, + + /// The highest possible calling convention ID. Must be some 2^k - 1. + MaxID = 1023 }; } // End CallingConv namespace Index: llvm/trunk/include/llvm/IR/Function.h =================================================================== --- llvm/trunk/include/llvm/IR/Function.h +++ llvm/trunk/include/llvm/IR/Function.h @@ -61,10 +61,12 @@ /* * Value::SubclassData * - * bit 0 : HasLazyArguments - * bit 1 : HasPrefixData - * bit 2 : HasPrologueData - * bit 3-6: CallingConvention + * bit 0 : HasLazyArguments + * bit 1 : HasPrefixData + * bit 2 : HasPrologueData + * bit 3 : [reserved] + * bits 4-13 : CallingConvention + * bits 14-15 : [reserved] */ /// Bits from GlobalObject::GlobalObjectSubclassData. @@ -158,11 +160,13 @@ /// calling convention of this function. The enum values for the known /// calling conventions are defined in CallingConv.h. CallingConv::ID getCallingConv() const { - return static_cast(getSubclassDataFromValue() >> 3); + return static_cast((getSubclassDataFromValue() >> 4) & + CallingConv::MaxID); } void setCallingConv(CallingConv::ID CC) { - setValueSubclassData((getSubclassDataFromValue() & 7) | - (static_cast(CC) << 3)); + auto ID = static_cast(CC); + assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); + setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4)); } /// @brief Return the attribute list for this Function. Index: llvm/trunk/include/llvm/IR/Instructions.h =================================================================== --- llvm/trunk/include/llvm/IR/Instructions.h +++ llvm/trunk/include/llvm/IR/Instructions.h @@ -1558,8 +1558,10 @@ return static_cast(getSubclassDataFromInstruction() >> 2); } void setCallingConv(CallingConv::ID CC) { + auto ID = static_cast(CC); + assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); setInstructionSubclassData((getSubclassDataFromInstruction() & 3) | - (static_cast(CC) << 2)); + (ID << 2)); } /// getAttributes - Return the parameter attributes for this call. @@ -3436,7 +3438,9 @@ return static_cast(getSubclassDataFromInstruction()); } void setCallingConv(CallingConv::ID CC) { - setInstructionSubclassData(static_cast(CC)); + auto ID = static_cast(CC); + assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention"); + setInstructionSubclassData(ID); } /// getAttributes - Return the parameter attributes for this invoke. Index: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3443,11 +3443,14 @@ 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 @@ 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 @@ 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; Index: llvm/trunk/test/Bitcode/compatibility-3.6.ll =================================================================== --- llvm/trunk/test/Bitcode/compatibility-3.6.ll +++ llvm/trunk/test/Bitcode/compatibility-3.6.ll @@ -375,8 +375,8 @@ ; CHECK: declare x86_vectorcallcc void @f.cc80() declare x86_vectorcallcc void @f.x86_vectorcallcc() ; CHECK: declare x86_vectorcallcc void @f.x86_vectorcallcc() -declare cc8191 void @f.cc8191() -; CHECK: declare cc8191 void @f.cc8191() +declare cc1023 void @f.cc1023() +; CHECK: declare cc1023 void @f.cc1023() ; Functions -- ret attrs (Return attributes) declare zeroext i64 @f.zeroext() Index: llvm/trunk/test/Bitcode/compatibility-3.7.ll =================================================================== --- llvm/trunk/test/Bitcode/compatibility-3.7.ll +++ llvm/trunk/test/Bitcode/compatibility-3.7.ll @@ -375,8 +375,8 @@ ; CHECK: declare x86_vectorcallcc void @f.cc80() declare x86_vectorcallcc void @f.x86_vectorcallcc() ; CHECK: declare x86_vectorcallcc void @f.x86_vectorcallcc() -declare cc8191 void @f.cc8191() -; CHECK: declare cc8191 void @f.cc8191() +declare cc1023 void @f.cc1023() +; CHECK: declare cc1023 void @f.cc1023() ; Functions -- ret attrs (Return attributes) declare zeroext i64 @f.zeroext() Index: llvm/trunk/test/Bitcode/compatibility.ll =================================================================== --- llvm/trunk/test/Bitcode/compatibility.ll +++ llvm/trunk/test/Bitcode/compatibility.ll @@ -377,8 +377,8 @@ ; CHECK: declare x86_vectorcallcc void @f.cc80() declare x86_vectorcallcc void @f.x86_vectorcallcc() ; CHECK: declare x86_vectorcallcc void @f.x86_vectorcallcc() -declare cc8191 void @f.cc8191() -; CHECK: declare cc8191 void @f.cc8191() +declare cc1023 void @f.cc1023() +; CHECK: declare cc1023 void @f.cc1023() ; Functions -- ret attrs (Return attributes) declare zeroext i64 @f.zeroext() Index: llvm/trunk/test/Bitcode/tailcall.ll =================================================================== --- llvm/trunk/test/Bitcode/tailcall.ll +++ llvm/trunk/test/Bitcode/tailcall.ll @@ -3,16 +3,16 @@ ; Check that musttail and tail roundtrip. -declare cc8191 void @t1_callee() -define cc8191 void @t1() { -; CHECK: tail call cc8191 void @t1_callee() - tail call cc8191 void @t1_callee() +declare cc1023 void @t1_callee() +define cc1023 void @t1() { +; CHECK: tail call cc1023 void @t1_callee() + tail call cc1023 void @t1_callee() ret void } -declare cc8191 void @t2_callee() -define cc8191 void @t2() { -; CHECK: musttail call cc8191 void @t2_callee() - musttail call cc8191 void @t2_callee() +declare cc1023 void @t2_callee() +define cc1023 void @t2() { +; CHECK: musttail call cc1023 void @t2_callee() + musttail call cc1023 void @t2_callee() ret void }