From efc0b08f2b66a17585aefb2b7af1a4e6df34a8cf Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 27 Oct 2015 21:17:06 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251452 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/CallingConv.h | 5 ++++- include/llvm/IR/Function.h | 18 +++++++++++------- include/llvm/IR/Instructions.h | 8 ++++++-- lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++++++---- test/Bitcode/compatibility-3.6.ll | 4 ++-- test/Bitcode/compatibility-3.6.ll.bc | Bin 10192 -> 10192 bytes test/Bitcode/compatibility-3.7.ll | 4 ++-- test/Bitcode/compatibility-3.7.ll.bc | Bin 11584 -> 11584 bytes test/Bitcode/compatibility.ll | 4 ++-- test/Bitcode/tailcall.ll | 16 ++++++++-------- 10 files changed, 42 insertions(+), 28 deletions(-) diff --git a/include/llvm/IR/CallingConv.h b/include/llvm/IR/CallingConv.h index 5c82de62dfd..ac7cc9b74ab 100644 --- a/include/llvm/IR/CallingConv.h +++ b/include/llvm/IR/CallingConv.h @@ -156,7 +156,10 @@ namespace CallingConv { 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 diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index a97c196ced0..b8e22af4bfe 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -61,10 +61,12 @@ private: /* * 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 @@ public: /// 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. diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index 58d5221dea8..509753bb96c 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -1558,8 +1558,10 @@ public: 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 @@ public: 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. diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 318b2368cd9..58b9b4a189a 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/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; diff --git a/test/Bitcode/compatibility-3.6.ll b/test/Bitcode/compatibility-3.6.ll index 53f061da00d..dcec8dc17bd 100644 --- a/test/Bitcode/compatibility-3.6.ll +++ b/test/Bitcode/compatibility-3.6.ll @@ -375,8 +375,8 @@ declare cc80 void @f.cc80() ; 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() diff --git a/test/Bitcode/compatibility-3.6.ll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8c@Rxx#aM8Zd9svo<;9mbfD`EN(_`anfPLBcA!kj8=2d{DasQqZ z5r21=4tEz=i4CV9+{=D)xNE`SH(ekXw_Tt%E7HELA zIF3D?qE+DRYu&~#?bKmGFz_4W4#sCVpW;c?U)-SqHL;7KHoueYGhcw$a@vxOKLwKIj`au-U7Ve1D_;-vRzNSdTLJNF z@LN}}j=zJ`0Pq!9_7Ixz$9X^(#lRq|J-AC*HDE@X7Kgq+=S*-H$ z8Slr~sah+b;imCz_;vi)i$iUTMYahV$L865ArV$Wp)P~YcxhSaOix6@Sb7sBq*}*V zg3QmOnV=9JGz31!(3SPRsi0ZzU)9=goO)>;o*Rb}>@RiqFUoJsKV^RIcZ@ zb2)hvmLkUw4KDPr{#ls2uH1;($+4@QXgjzuyZnlMOS#ZW+oi%y6TYh{7as8I*G`VE z))f6#(3)0m3`Dm*IoP^)9*#t!Vc%c<+gE?ToDNB~WXV_|dp7fvx!WSm^x~=TS}V6P c6#K!@Cp&gYolBEaDfYAr)?zF7$3G1I3##-iZU6uP diff --git a/test/Bitcode/compatibility-3.7.ll b/test/Bitcode/compatibility-3.7.ll index af1eb5d297f..da1471e84ef 100644 --- a/test/Bitcode/compatibility-3.7.ll +++ b/test/Bitcode/compatibility-3.7.ll @@ -375,8 +375,8 @@ declare cc80 void @f.cc80() ; 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() diff --git a/test/Bitcode/compatibility-3.7.ll.bc b/test/Bitcode/compatibility-3.7.ll.bc index 1bd87c08d04ae1a53d9fc5418bd68bd44923aada..14c0f1a6d6f1bda8998e601301911f825864703d 100644 GIT binary patch delta 2018 zcmZ9Me`s4(6vxkdN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PCq8b= z6rTY3uH+&VOMrwwwlI${fhF!}mfj2)kmV>{whs9;c$mX@B-EXpf8#l{D#OmQw%AvkB6}J{VKF${cMF79@k))gLvgd15R;} zE`LX0hXYJsl6Fvub`L8v|LF!7=@BN1vJsvi?jOZ*b0bo>R%`#;Hd}r4tGk@S zoVa`V;eUD?UK8pWoQ9?I9Y$$?G0a>e?S-kyUh&sXxGnUvR!PYN>-*|{q zox((wp6>rNsWKM8`}xpJp0*cpfaJ5G`bE-Fi)go+lLK* z`u%%~Gk7eLpPJmBy}CEPrNNCJCD36eFAR-+l1@$>co5T)xrwsA(is>!*PL4VH5=9X PzD?GFt5@c`xAy%9+ox|e diff --git a/test/Bitcode/compatibility.ll b/test/Bitcode/compatibility.ll index e18c239d530..4c6349c803c 100644 --- a/test/Bitcode/compatibility.ll +++ b/test/Bitcode/compatibility.ll @@ -377,8 +377,8 @@ declare cc80 void @f.cc80() ; 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() diff --git a/test/Bitcode/tailcall.ll b/test/Bitcode/tailcall.ll index 01190d74c34..6a4b8885847 100644 --- a/test/Bitcode/tailcall.ll +++ b/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 }