Skip to content

Conversation

@llvmbot
Copy link
Member

@llvmbot llvmbot commented Aug 25, 2025

Backport 0a1eff2 6c9f1ce

Requested by: steakhal

@llvmbot
Copy link
Member Author

llvmbot commented Aug 25, 2025

@Xazax-hun What do you think about merging this PR to the release branch?

@llvmbot
Copy link
Member Author

llvmbot commented Aug 25, 2025

@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (llvmbot)

Changes

Backport 0a1eff2 6c9f1ce

Requested by: @steakhal


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

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp (-1)
  • (modified) clang/test/Analysis/cxx23-assume-attribute.cpp (+6)
diff --git a/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp
index 1e3adb4f266ca..789c7772d123a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp
@@ -45,7 +45,6 @@ void AssumeModelingChecker::checkPostStmt(const AttributedStmt *A,
       continue;
 
     const auto *Assumption = AssumptionVal.getAsInteger();
-    assert(Assumption && "We should know the exact outcome of an assume expr");
     if (Assumption && Assumption->isZero()) {
       C.addSink();
     }
diff --git a/clang/test/Analysis/cxx23-assume-attribute.cpp b/clang/test/Analysis/cxx23-assume-attribute.cpp
index 86e7662cd2af9..4cc16446572dc 100644
--- a/clang/test/Analysis/cxx23-assume-attribute.cpp
+++ b/clang/test/Analysis/cxx23-assume-attribute.cpp
@@ -69,3 +69,9 @@ int assume_and_fallthrough_at_the_same_attrstmt(int a, int b) {
 
   return 0;
 }
+
+void assume_opaque_gh151854_no_crash() {
+  extern bool opaque();
+  [[assume(opaque())]]; // no-crash
+  // expected-warning@-1 {{assumption is ignored because it contains (potential) side-effects}}
+}

@llvmbot
Copy link
Member Author

llvmbot commented Aug 25, 2025

@llvm/pr-subscribers-clang

Author: None (llvmbot)

Changes

Backport 0a1eff2 6c9f1ce

Requested by: @steakhal


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

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp (-1)
  • (modified) clang/test/Analysis/cxx23-assume-attribute.cpp (+6)
diff --git a/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp
index 1e3adb4f266ca..789c7772d123a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp
@@ -45,7 +45,6 @@ void AssumeModelingChecker::checkPostStmt(const AttributedStmt *A,
       continue;
 
     const auto *Assumption = AssumptionVal.getAsInteger();
-    assert(Assumption && "We should know the exact outcome of an assume expr");
     if (Assumption && Assumption->isZero()) {
       C.addSink();
     }
diff --git a/clang/test/Analysis/cxx23-assume-attribute.cpp b/clang/test/Analysis/cxx23-assume-attribute.cpp
index 86e7662cd2af9..4cc16446572dc 100644
--- a/clang/test/Analysis/cxx23-assume-attribute.cpp
+++ b/clang/test/Analysis/cxx23-assume-attribute.cpp
@@ -69,3 +69,9 @@ int assume_and_fallthrough_at_the_same_attrstmt(int a, int b) {
 
   return 0;
 }
+
+void assume_opaque_gh151854_no_crash() {
+  extern bool opaque();
+  [[assume(opaque())]]; // no-crash
+  // expected-warning@-1 {{assumption is ignored because it contains (potential) side-effects}}
+}

@steakhal steakhal changed the title release/21.x: [analyzer] Add missing expected-warning after #151908 release/21.x: [analyzer] Drop false asserts in handling assume attribures Aug 25, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Aug 26, 2025
@Xazax-hun
Copy link
Collaborator

Looks great, this is a low risk fix, good idea to backport.

@tru tru merged commit d618b40 into llvm:release/21.x Aug 26, 2025
5 of 10 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Aug 26, 2025
…nts (llvm#151908)

We sometimes don't know if the operand of [[assume]] is true/false, and
that's okay. We can just ignore the attribute in that case.

If we wanted something more fancy, we could bring the assumption to the
constraints, but dropping them should be just as fine for now.

Fixes llvm#151854

(cherry picked from commit 0a1eff2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

4 participants