Skip to content

Commit 9f276d4

Browse files
authored
[clang][dataflow] Avoid putting an assertion in an LLVM_DEBUG block. (#67313)
`LLVM_DEBUG` blocks are only run if the `-debug` command line flag is passed. We don't do this in any of our CI builds, so the assertion has limited value and it's likely it will start failing over time.
1 parent 834cb91 commit 9f276d4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -696,19 +696,23 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
696696
FieldLocs.insert({Field, &Loc});
697697
}
698698

699-
LLVM_DEBUG({
700-
// Check that we satisfy the invariant that a `RecordStorageLoation`
701-
// contains exactly the set of modeled fields for that type.
702-
// `ModeledFields` includes fields from all the bases, but only the
703-
// modeled ones. However, if a class type is initialized with an
704-
// `InitListExpr`, all fields in the class, including those from base
705-
// classes, are included in the set of modeled fields. The code above
706-
// should therefore populate exactly the modeled fields.
707-
auto ModeledFields = Env.getDataflowAnalysisContext().getModeledFields(Type);
708-
assert(ModeledFields.size() == FieldLocs.size());
699+
// Check that we satisfy the invariant that a `RecordStorageLoation`
700+
// contains exactly the set of modeled fields for that type.
701+
// `ModeledFields` includes fields from all the bases, but only the
702+
// modeled ones. However, if a class type is initialized with an
703+
// `InitListExpr`, all fields in the class, including those from base
704+
// classes, are included in the set of modeled fields. The code above
705+
// should therefore populate exactly the modeled fields.
706+
assert([&]() {
707+
auto ModeledFields =
708+
Env.getDataflowAnalysisContext().getModeledFields(Type);
709+
if (ModeledFields.size() != FieldLocs.size())
710+
return false;
709711
for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
710-
assert(ModeledFields.contains(cast_or_null<FieldDecl>(Field)));
711-
});
712+
if (!ModeledFields.contains(cast_or_null<FieldDecl>(Field)))
713+
return false;
714+
return true;
715+
}());
712716

713717
auto &Loc =
714718
Env.getDataflowAnalysisContext().arena().create<RecordStorageLocation>(

0 commit comments

Comments
 (0)