diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-20 03:17:58 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-20 03:17:58 +0000 |
commit | ad6eb127c9e4c48cfdff1f47e5efe83255b15565 (patch) | |
tree | 71e1ad8c031e75dc9c2f40fadab44abecda59e33 /llvm/lib/Bitcode | |
parent | 847e05f5695870a5adc0bf17d9207ed395d30d02 (diff) | |
download | bcm5719-llvm-ad6eb127c9e4c48cfdff1f47e5efe83255b15565.tar.gz bcm5719-llvm-ad6eb127c9e4c48cfdff1f47e5efe83255b15565.zip |
Bitcode: Stop assuming non-null fields
When writing the bitcode serialization for the new debug info hierarchy,
I assumed two fields would never be null.
Drop that assumption, since it's brittle (and crashes the
`BitcodeWriter` if wrong), and is a check better left for the verifier
anyway. (No need for a bitcode upgrade here, since the new hierarchy is
still not in place.)
The fields in question are `MDCompileUnit::getFile()` and
`MDDerivedType::getBaseType()`, the latter of which isn't null in
test/Transforms/Mem2Reg/ConvertDebugInfo2.ll (see !14, a pointer to
nothing). While the testcase might have bitrotted, there's no reason
for the bitcode format to rely on non-null for metadata operands.
This also fixes a bug in `AsmWriter` where if the `file:` is null it
isn't emitted (caught by the double-round trip in the testcase I'm
adding) -- this is a required field in `LLParser`.
I'll circle back to ConvertDebugInfo2. Once the specialized nodes are
in place, I'll be trying to turn the debug info verifier back on by
default (in the newer module pass form committed r206300) and throwing
more logic in there. If the testcase has bitrotted (as opposed to me
not understanding the schema correctly) I'll fix it then.
llvm-svn: 229960
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 4 |
2 files changed, 12 insertions, 11 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 649057dddf0..bb6ba6fc6e1 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1407,8 +1407,8 @@ std::error_code BitcodeReader::ParseMetadata() { GET_OR_DISTINCT(MDDerivedType, Record[0], (Context, Record[1], getMDString(Record[2]), getMDOrNull(Record[3]), Record[4], - getMDOrNull(Record[5]), getMD(Record[6]), Record[7], - Record[8], Record[9], Record[10], + getMDOrNull(Record[5]), getMDOrNull(Record[6]), + Record[7], Record[8], Record[9], Record[10], getMDOrNull(Record[11]))), NextMDValueNo++); break; @@ -1454,13 +1454,14 @@ std::error_code BitcodeReader::ParseMetadata() { return Error("Invalid record"); MDValueList.AssignValue( - GET_OR_DISTINCT( - MDCompileUnit, Record[0], - (Context, Record[1], getMD(Record[2]), getMDString(Record[3]), - Record[4], getMDString(Record[5]), Record[6], - getMDString(Record[7]), Record[8], getMDOrNull(Record[9]), - getMDOrNull(Record[10]), getMDOrNull(Record[11]), - getMDOrNull(Record[12]), getMDOrNull(Record[13]))), + GET_OR_DISTINCT(MDCompileUnit, Record[0], + (Context, Record[1], getMDOrNull(Record[2]), + getMDString(Record[3]), Record[4], + getMDString(Record[5]), Record[6], + getMDString(Record[7]), Record[8], + getMDOrNull(Record[9]), getMDOrNull(Record[10]), + getMDOrNull(Record[11]), getMDOrNull(Record[12]), + getMDOrNull(Record[13]))), NextMDValueNo++); break; } diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 932381926c7..ec43035b22e 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -864,7 +864,7 @@ static void WriteMDDerivedType(const MDDerivedType *N, Record.push_back(VE.getMetadataOrNullID(N->getFile())); Record.push_back(N->getLine()); Record.push_back(VE.getMetadataOrNullID(N->getScope())); - Record.push_back(VE.getMetadataID(N->getBaseType())); + Record.push_back(VE.getMetadataOrNullID(N->getBaseType())); Record.push_back(N->getSizeInBits()); Record.push_back(N->getAlignInBits()); Record.push_back(N->getOffsetInBits()); @@ -932,7 +932,7 @@ static void WriteMDCompileUnit(const MDCompileUnit *N, unsigned Abbrev) { Record.push_back(N->isDistinct()); Record.push_back(N->getSourceLanguage()); - Record.push_back(VE.getMetadataID(N->getFile())); + Record.push_back(VE.getMetadataOrNullID(N->getFile())); Record.push_back(VE.getMetadataOrNullID(N->getRawProducer())); Record.push_back(N->isOptimized()); Record.push_back(VE.getMetadataOrNullID(N->getRawFlags())); |