Skip to content

[clang][dataflow] Avoid putting an assertion in an LLVM_DEBUG block. #67313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

martinboehme
Copy link
Contributor

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.

`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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang:analysis labels Sep 25, 2023
@martinboehme martinboehme requested review from kinu and ymand September 25, 2023 11:18
@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/67313.diff

1 Files Affected:

  • (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+16-12)
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 2414a1cc026af5f..2ad3f9d7c94a80c 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -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>(

@martinboehme martinboehme merged commit 9f276d4 into llvm:main Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants