Skip to content

Commit fd60180

Browse files
committed
DebugInfo: Make DWARFExpression::iterator a const iterator
3d1d8c7 made DWARFExpression::iterator's Operation member `mutable`. After a few prep commits, the iterator can instead be made a `const` iterator since no caller can change the Operation. Differential Revision: https://reviews.llvm.org/D113958
1 parent a0f1f17 commit fd60180

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ class DWARFExpression {
109109
/// An iterator to go through the expression operations.
110110
class iterator
111111
: public iterator_facade_base<iterator, std::forward_iterator_tag,
112-
Operation> {
112+
const Operation> {
113113
friend class DWARFExpression;
114114
const DWARFExpression *Expr;
115115
uint64_t Offset;
116-
mutable Operation Op;
116+
Operation Op;
117117
iterator(const DWARFExpression *Expr, uint64_t Offset)
118118
: Expr(Expr), Offset(Offset) {
119119
Op.Error =
@@ -130,9 +130,7 @@ class DWARFExpression {
130130
return *this;
131131
}
132132

133-
class Operation &operator*() const {
134-
return Op;
135-
}
133+
const Operation &operator*() const { return Op; }
136134

137135
iterator skipBytes(uint64_t Add) const {
138136
return iterator(Expr, Op.EndOffset + Add);

llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
408408
SmallVector<PrintedExpr, 4> Stack;
409409

410410
while (I != E) {
411-
DWARFExpression::Operation &Op = *I;
411+
const DWARFExpression::Operation &Op = *I;
412412
uint8_t Opcode = Op.getCode();
413413
switch (Opcode) {
414414
case dwarf::DW_OP_regx: {

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,10 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die,
552552
DataExtractor Data(toStringRef(Entry.Expr), DCtx.isLittleEndian(), 0);
553553
DWARFExpression Expression(Data, U->getAddressByteSize(),
554554
U->getFormParams().Format);
555-
bool Error = any_of(Expression, [](DWARFExpression::Operation &Op) {
556-
return Op.isError();
557-
});
555+
bool Error =
556+
any_of(Expression, [](const DWARFExpression::Operation &Op) {
557+
return Op.isError();
558+
});
558559
if (Error || !Expression.verify(U))
559560
ReportError("DIE contains invalid DWARF expression:");
560561
}
@@ -1400,11 +1401,12 @@ static bool isVariableIndexable(const DWARFDie &Die, DWARFContext &DCtx) {
14001401
U->getAddressByteSize());
14011402
DWARFExpression Expression(Data, U->getAddressByteSize(),
14021403
U->getFormParams().Format);
1403-
bool IsInteresting = any_of(Expression, [](DWARFExpression::Operation &Op) {
1404-
return !Op.isError() && (Op.getCode() == DW_OP_addr ||
1405-
Op.getCode() == DW_OP_form_tls_address ||
1406-
Op.getCode() == DW_OP_GNU_push_tls_address);
1407-
});
1404+
bool IsInteresting =
1405+
any_of(Expression, [](const DWARFExpression::Operation &Op) {
1406+
return !Op.isError() && (Op.getCode() == DW_OP_addr ||
1407+
Op.getCode() == DW_OP_form_tls_address ||
1408+
Op.getCode() == DW_OP_GNU_push_tls_address);
1409+
});
14081410
if (IsInteresting)
14091411
return true;
14101412
}

llvm/tools/llvm-dwarfdump/Statistics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static void collectStatsForDie(DWARFDie Die, const std::string &FnPrefix,
322322
U->getFormParams().Format);
323323
// Consider the expression containing the DW_OP_entry_value as
324324
// an entry value.
325-
return llvm::any_of(Expression, [](DWARFExpression::Operation &Op) {
325+
return llvm::any_of(Expression, [](const DWARFExpression::Operation &Op) {
326326
return Op.getCode() == dwarf::DW_OP_entry_value ||
327327
Op.getCode() == dwarf::DW_OP_GNU_entry_value;
328328
});

0 commit comments

Comments
 (0)