summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-02 14:55:01 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-02 14:55:01 +0000
commitbfce5b2915497c048cafc3f00deb0ea716be8b74 (patch)
tree47df92a28cdd791997f029921bbcf425bc4e7271
parentc3ddf2dea3b054664e59d3c763e5f9fc4ddd1ae7 (diff)
BitcodeReader: Check for unresolved function metadata
A follow-up commit will start using function metadata blocks more heavily. This commit adds some error checking to confirm that metadata is fully resolved before (and after) materializing each function. This is valid even when reading very old bitcode from before the metadata/value split. The global metadata block always came before the function blocks. However, in case somehow this causes a regression (i.e., an old LLVM did produce such bitcode after all) I'm committing separately. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265223 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 3598debd636..e784c88344d 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -123,6 +123,7 @@ public:
void shrinkTo(unsigned N) {
assert(N <= size() && "Invalid shrinkTo request!");
+ assert(!AnyFwdRefs && "Unexpected forward refs");
MetadataPtrs.resize(N);
}
@@ -130,6 +131,7 @@ public:
MDNode *getMDNodeFwdRefOrNull(unsigned Idx);
void assignValue(Metadata *MD, unsigned Idx);
void tryToResolveCycles();
+ bool hasFwdRefs() const { return AnyFwdRefs; }
};
class BitcodeReader : public GVMaterializer {
@@ -1929,6 +1931,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
IsMetadataMaterialized = true;
unsigned NextMetadataNo = MetadataList.size();
+ if (!ModuleLevel && MetadataList.hasFwdRefs())
+ return error("Invalid metadata: fwd refs into function blocks");
+
if (Stream.EnterSubBlock(bitc::METADATA_BLOCK_ID))
return error("Invalid record");
@@ -3968,6 +3973,10 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
if (Stream.EnterSubBlock(bitc::FUNCTION_BLOCK_ID))
return error("Invalid record");
+ // Unexpected unresolved metadata when parsing function.
+ if (MetadataList.hasFwdRefs())
+ return error("Invalid function metadata: incoming forward references");
+
InstructionList.clear();
unsigned ModuleValueListSize = ValueList.size();
unsigned ModuleMetadataListSize = MetadataList.size();
@@ -5227,8 +5236,9 @@ OutOfRecordLoop:
}
}
- // FIXME: Check for unresolved forward-declared metadata references
- // and clean up leaks.
+ // Unexpected unresolved metadata about to be dropped.
+ if (MetadataList.hasFwdRefs())
+ return error("Invalid function metadata: outgoing forward refs");
// Trim the value list down to the size it was before we parsed this function.
ValueList.shrinkTo(ModuleValueListSize);