Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit f054cc1

Browse files
committed
Make this code less brittle. The benefits of a fixed-size array aren't worth the maintenance cost.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266359 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 38f7925 commit f054cc1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

include/clang/Serialization/ASTWriter.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,10 @@ class ASTRecordWriter {
704704
/// declaration or type.
705705
SmallVector<Stmt *, 16> StmtsToEmit;
706706

707-
/// Worst case: bases, vbases, visible and lexical contents, local redecls.
708-
static const int MaxOffsetIndices = 5;
709707
/// \brief Indices of record elements that describe offsets within the
710708
/// bitcode. These will be converted to offsets relative to the current
711709
/// record when emitted.
712-
unsigned OffsetIndices[MaxOffsetIndices];
713-
unsigned NumOffsetIndices = 0;
710+
SmallVector<unsigned, 8> OffsetIndices;
714711

715712
/// \brief Flush all of the statements and expressions that have
716713
/// been added to the queue via AddStmt().
@@ -719,13 +716,13 @@ class ASTRecordWriter {
719716

720717
void PrepareToEmit(uint64_t MyOffset) {
721718
// Convert offsets into relative form.
722-
for (unsigned I = 0; I != NumOffsetIndices; ++I) {
723-
auto &StoredOffset = (*Record)[OffsetIndices[I]];
719+
for (unsigned I : OffsetIndices) {
720+
auto &StoredOffset = (*Record)[I];
724721
assert(StoredOffset < MyOffset && "invalid offset");
725722
if (StoredOffset)
726723
StoredOffset = MyOffset - StoredOffset;
727724
}
728-
NumOffsetIndices = 0;
725+
OffsetIndices.clear();
729726
}
730727

731728
public:
@@ -779,8 +776,7 @@ class ASTRecordWriter {
779776
/// \brief Add a bit offset into the record. This will be converted into an
780777
/// offset relative to the current record when emitted.
781778
void AddOffset(uint64_t BitOffset) {
782-
assert(NumOffsetIndices != MaxOffsetIndices && "too many offset indices");
783-
OffsetIndices[NumOffsetIndices++] = Record->size();
779+
OffsetIndices.push_back(Record->size());
784780
Record->push_back(BitOffset);
785781
}
786782

0 commit comments

Comments
 (0)