[Metadata] Extend 'count' field of DISubrange to take a metadata node
Summary:
This patch extends the DISubrange 'count' field to take either a
(signed) constant integer value or a reference to a DILocalVariable
or DIGlobalVariable.
This is patch [1/3] in a series to extend LLVM's DISubrange Metadata
node to support debugging of C99 variable length arrays and vectors with
runtime length like the Scalable Vector Extension for AArch64. It is
also a first step towards representing more complex cases like arrays
in Fortran.
Reviewers: echristo, pcc, aprantl, dexonsmith, clayborg, kristof.beyls, dblaikie
Reviewed By: aprantl
Subscribers: rnk, probinson, fhahn, aemerson, rengolin, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D41695
llvm-svn: 323313
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 7d79956..5250ac5 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1174,14 +1174,25 @@
break;
}
case bitc::METADATA_SUBRANGE: {
- if (Record.size() != 3)
- return error("Invalid record");
+ Metadata *Val = nullptr;
+ // Operand 'count' is interpreted as:
+ // - Signed integer (version 0)
+ // - Metadata node (version 1)
+ switch (Record[0] >> 1) {
+ case 0:
+ Val = GET_OR_DISTINCT(DISubrange,
+ (Context, Record[1], unrotateSign(Record.back())));
+ break;
+ case 1:
+ Val = GET_OR_DISTINCT(DISubrange, (Context, getMDOrNull(Record[1]),
+ unrotateSign(Record.back())));
+ break;
+ default:
+ return error("Invalid record: Unsupported version of DISubrange");
+ }
- IsDistinct = Record[0];
- MetadataList.assignValue(
- GET_OR_DISTINCT(DISubrange,
- (Context, Record[1], unrotateSign(Record[2]))),
- NextMetadataNo);
+ MetadataList.assignValue(Val, NextMetadataNo);
+ IsDistinct = Record[0] & 1;
NextMetadataNo++;
break;
}