summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/IR/CallingConv.h5
-rw-r--r--llvm/include/llvm/IR/Function.h18
-rw-r--r--llvm/include/llvm/IR/Instructions.h8
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp11
-rw-r--r--llvm/test/Bitcode/compatibility-3.6.ll4
-rw-r--r--llvm/test/Bitcode/compatibility-3.6.ll.bcbin10192 -> 10192 bytes
-rw-r--r--llvm/test/Bitcode/compatibility-3.7.ll4
-rw-r--r--llvm/test/Bitcode/compatibility-3.7.ll.bcbin11584 -> 11584 bytes
-rw-r--r--llvm/test/Bitcode/compatibility.ll4
-rw-r--r--llvm/test/Bitcode/tailcall.ll16
10 files changed, 42 insertions, 28 deletions
diff --git a/llvm/include/llvm/IR/CallingConv.h b/llvm/include/llvm/IR/CallingConv.h
index 5c82de62dfd..ac7cc9b74ab 100644
--- a/llvm/include/llvm/IR/CallingConv.h
+++ b/llvm/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/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index a97c196ced0..b8e22af4bfe 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/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<CallingConv::ID>(getSubclassDataFromValue() >> 3);
+ return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
+ CallingConv::MaxID);
}
void setCallingConv(CallingConv::ID CC) {
- setValueSubclassData((getSubclassDataFromValue() & 7) |
- (static_cast<unsigned>(CC) << 3));
+ auto ID = static_cast<unsigned>(CC);
+ assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
+ setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4));
}
/// @brief Return the attribute list for this Function.
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 58d5221dea8..509753bb96c 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1558,8 +1558,10 @@ public:
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
}
void setCallingConv(CallingConv::ID CC) {
+ auto ID = static_cast<unsigned>(CC);
+ assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
- (static_cast<unsigned>(CC) << 2));
+ (ID << 2));
}
/// getAttributes - Return the parameter attributes for this call.
@@ -3436,7 +3438,9 @@ public:
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
}
void setCallingConv(CallingConv::ID CC) {
- setInstructionSubclassData(static_cast<unsigned>(CC));
+ auto ID = static_cast<unsigned>(CC);
+ assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
+ setInstructionSubclassData(ID);
}
/// getAttributes - Return the parameter attributes for this invoke.
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;
diff --git a/llvm/test/Bitcode/compatibility-3.6.ll b/llvm/test/Bitcode/compatibility-3.6.ll
index 53f061da00d..dcec8dc17bd 100644
--- a/llvm/test/Bitcode/compatibility-3.6.ll
+++ b/llvm/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/llvm/test/Bitcode/compatibility-3.6.ll.bc b/llvm/test/Bitcode/compatibility-3.6.ll.bc
index d75cbca7fb1..86b66200031 100644
--- a/llvm/test/Bitcode/compatibility-3.6.ll.bc
+++ b/llvm/test/Bitcode/compatibility-3.6.ll.bc
Binary files differ
diff --git a/llvm/test/Bitcode/compatibility-3.7.ll b/llvm/test/Bitcode/compatibility-3.7.ll
index af1eb5d297f..da1471e84ef 100644
--- a/llvm/test/Bitcode/compatibility-3.7.ll
+++ b/llvm/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/llvm/test/Bitcode/compatibility-3.7.ll.bc b/llvm/test/Bitcode/compatibility-3.7.ll.bc
index 1bd87c08d04..14c0f1a6d6f 100644
--- a/llvm/test/Bitcode/compatibility-3.7.ll.bc
+++ b/llvm/test/Bitcode/compatibility-3.7.ll.bc
Binary files differ
diff --git a/llvm/test/Bitcode/compatibility.ll b/llvm/test/Bitcode/compatibility.ll
index e18c239d530..4c6349c803c 100644
--- a/llvm/test/Bitcode/compatibility.ll
+++ b/llvm/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/llvm/test/Bitcode/tailcall.ll b/llvm/test/Bitcode/tailcall.ll
index 01190d74c34..6a4b8885847 100644
--- a/llvm/test/Bitcode/tailcall.ll
+++ b/llvm/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
}
OpenPOWER on IntegriCloud