Skip to content

Commit

Permalink
[clang][dataflow] Avoid putting an assertion in an LLVM_DEBUG block. (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
martinboehme committed Sep 26, 2023
1 parent 834cb91 commit 9f276d4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions clang/lib/Analysis/FlowSensitive/Transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,19 +696,23 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
FieldLocs.insert({Field, &Loc});
}

LLVM_DEBUG({
// Check that we satisfy the invariant that a `RecordStorageLoation`
// contains exactly the set of modeled fields for that type.
// `ModeledFields` includes fields from all the bases, but only the
// modeled ones. However, if a class type is initialized with an
// `InitListExpr`, all fields in the class, including those from base
// classes, are included in the set of modeled fields. The code above
// should therefore populate exactly the modeled fields.
auto ModeledFields = Env.getDataflowAnalysisContext().getModeledFields(Type);
assert(ModeledFields.size() == FieldLocs.size());
// Check that we satisfy the invariant that a `RecordStorageLoation`
// contains exactly the set of modeled fields for that type.
// `ModeledFields` includes fields from all the bases, but only the
// modeled ones. However, if a class type is initialized with an
// `InitListExpr`, all fields in the class, including those from base
// classes, are included in the set of modeled fields. The code above
// should therefore populate exactly the modeled fields.
assert([&]() {
auto ModeledFields =
Env.getDataflowAnalysisContext().getModeledFields(Type);
if (ModeledFields.size() != FieldLocs.size())
return false;
for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
assert(ModeledFields.contains(cast_or_null<FieldDecl>(Field)));
});
if (!ModeledFields.contains(cast_or_null<FieldDecl>(Field)))
return false;
return true;
}());

auto &Loc =
Env.getDataflowAnalysisContext().arena().create<RecordStorageLocation>(
Expand Down

0 comments on commit 9f276d4

Please sign in to comment.