diff options
author | Adrian Prantl <aprantl@apple.com> | 2016-05-06 22:53:06 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2016-05-06 22:53:06 +0000 |
commit | 85338cbdb63215abefa45d51fe7e5f4f913a6ba4 (patch) | |
tree | a700220f85e581904cc22dd78a24efae428cd4f4 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 22152acf7b5d05bea25672cf5eb287893f85fa41 (diff) | |
download | bcm5719-llvm-85338cbdb63215abefa45d51fe7e5f4f913a6ba4.tar.gz bcm5719-llvm-85338cbdb63215abefa45d51fe7e5f4f913a6ba4.zip |
Implement a safer bitcode upgrade for DISubprogram.
The bitcode upgrade I added for DISubprogram in r266446 was based on the
assumption that the CU node for the subprogram was already materialized by the
time the DISubprogram is visited. This assumption may not hold true as future
versions of LLVM may decide to write out bitcode in a different order. This
patch corrects this by introducing a versioning bit next to the distinct flag to
unambiguously differentiate the new from the old record layouts.
Note for people stabilizing LLVM out-of-tree: This patch introduces a bitcode
incompatibility with llvm trunk revisions from r266446 — this commit. (But
D19987 will ensure that it degrades gracefully).
http://reviews.llvm.org/D20004
rdar://problem/26074194
llvm-svn: 268816
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 11ddd013516..f3bd5508aa0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2472,28 +2472,30 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) { return error("Invalid record"); IsDistinct = - Record[0] || Record[8]; // All definitions should be distinct. + (Record[0] & 1) || Record[8]; // All definitions should be distinct. // Version 1 has a Function as Record[15]. // Version 2 has removed Record[15]. // Version 3 has the Unit as Record[15]. + bool HasUnit = Record[0] >= 2; + if (HasUnit && Record.size() != 19) + return error("Invalid record"); Metadata *CUorFn = getMDOrNull(Record[15]); unsigned Offset = Record.size() == 19 ? 1 : 0; - bool HasFn = Offset && dyn_cast_or_null<ConstantAsMetadata>(CUorFn); - bool HasCU = Offset && !HasFn; + bool HasFn = Offset && !HasUnit; DISubprogram *SP = GET_OR_DISTINCT( DISubprogram, (Context, getDITypeRefOrNull(Record[1]), getMDString(Record[2]), getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], getMDOrNull(Record[6]), Record[7], Record[8], Record[9], getDITypeRefOrNull(Record[10]), Record[11], Record[12], Record[13], - Record[14], HasCU ? CUorFn : nullptr, + Record[14], HasUnit ? CUorFn : nullptr, getMDOrNull(Record[15 + Offset]), getMDOrNull(Record[16 + Offset]), getMDOrNull(Record[17 + Offset]))); MetadataList.assignValue(SP, NextMetadataNo++); // Upgrade sp->function mapping to function->sp mapping. if (HasFn) { - if (auto *CMD = dyn_cast<ConstantAsMetadata>(CUorFn)) + if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(CUorFn)) if (auto *F = dyn_cast<Function>(CMD->getValue())) { if (F->isMaterializable()) // Defer until materialized; unmaterialized functions may not have |