[PATCH] D12618: Reserve a vendor reserved block ID for bitcode
Rafael Espíndola via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 07:59:15 PDT 2015
> What about when LLVM 4.0 will be here? What if some 4.0 bitcode is fed
> through LLVM 3.8?
It should not crash.
> Even if we don’t crash on the Bitcode *format*, which shouldn’t really
> happen, what about the optimizer generating intrinsics that are not
> supported by the backend?
Still, it should not crash. It should error saying it got an unknown intrinsic.
> I am confident we can get there by fuzz testing.
>
> Good idea!
>
> With what we have in trunk we should be able to implement errors like:
>
> Error: unknown linkage number XX. Input is likely from a newer llvm version.
>
> Would that be sufficient?
>
>
> Possibly, can you point me to the mechanism involved here?
Right now we have
static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val) {
switch (Val) {
default: // Map unknown/new linkages to external
case 0:
Which is IMHO a really bad idea. It should look something like the
attached patch (which is missing the error propagation). With it
llvm-dis on the attached testcase prints
./bin/llvm-dis: error: unknown linkage number 20. Input is likely from
a newer llvm version.
Cheers,
Rafael
-------------- next part --------------
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index be39b88..99589a4 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -527,9 +527,13 @@ static bool hasImplicitComdat(size_t Val) {
}
}
-static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val) {
+static GlobalValue::LinkageTypes
+getDecodedLinkage(DiagnosticHandlerFunction DiagnosticHandler, unsigned Val) {
switch (Val) {
- default: // Map unknown/new linkages to external
+ default:
+ error(DiagnosticHandler,
+ Twine("unknown linkage number ") + Twine(Val) +
+ ". Input is likely from a newer llvm version.");
case 0:
return GlobalValue::ExternalLinkage;
case 2:
@@ -3006,7 +3010,8 @@ std::error_code BitcodeReader::parseModule(bool Resume,
}
uint64_t RawLinkage = Record[3];
- GlobalValue::LinkageTypes Linkage = getDecodedLinkage(RawLinkage);
+ GlobalValue::LinkageTypes Linkage =
+ getDecodedLinkage(DiagnosticHandler, RawLinkage);
unsigned Alignment;
if (std::error_code EC = parseAlignmentValue(Record[4], Alignment))
return EC;
@@ -3086,7 +3091,7 @@ std::error_code BitcodeReader::parseModule(bool Resume,
Func->setCallingConv(static_cast<CallingConv::ID>(Record[1]));
bool isProto = Record[2];
uint64_t RawLinkage = Record[3];
- Func->setLinkage(getDecodedLinkage(RawLinkage));
+ Func->setLinkage(getDecodedLinkage(DiagnosticHandler, RawLinkage));
Func->setAttributes(getAttributes(Record[4]));
unsigned Alignment;
@@ -3158,8 +3163,8 @@ std::error_code BitcodeReader::parseModule(bool Resume,
if (!PTy)
return error("Invalid type for value");
- auto *NewGA =
- GlobalAlias::create(PTy, getDecodedLinkage(Record[2]), "", TheModule);
+ auto *NewGA = GlobalAlias::create(
+ PTy, getDecodedLinkage(DiagnosticHandler, Record[2]), "", TheModule);
// Old bitcode files didn't have visibility field.
// Local linkage must have default visibility.
if (Record.size() > 3 && !NewGA->hasLocalLinkage())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.bc
Type: application/octet-stream
Size: 508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150908/791f314d/attachment.obj>
More information about the llvm-commits
mailing list