Skip to content

Conversation

@steakhal
Copy link
Contributor

@steakhal steakhal commented Aug 4, 2025

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 #151854

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.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-clang

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

Author: Balazs Benics (steakhal)

Changes

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 #151854


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

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp (-1)
  • (modified) clang/test/Analysis/cxx23-assume-attribute.cpp (+5)
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..dd15ff5d43505 100644
--- a/clang/test/Analysis/cxx23-assume-attribute.cpp
+++ b/clang/test/Analysis/cxx23-assume-attribute.cpp
@@ -69,3 +69,8 @@ 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
+}

@steakhal steakhal merged commit 0a1eff2 into llvm:main Aug 5, 2025
8 of 10 checks passed
@steakhal steakhal deleted the bb/drop-assertion branch August 5, 2025 15:03
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 5, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/32123

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Analysis/cxx23-assume-attribute.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/22/include -nostdsysteminc -analyze -setup-static-analyzer -std=c++23 -triple x86_64-pc-linux-gnu    -analyzer-checker=core,debug.ExprInspection -verify /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/cxx23-assume-attribute.cpp # RUN: at line 1
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/22/include -nostdsysteminc -analyze -setup-static-analyzer -std=c++23 -triple x86_64-pc-linux-gnu -analyzer-checker=core,debug.ExprInspection -verify /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/cxx23-assume-attribute.cpp
error: 'expected-warning' diagnostics seen but not expected: 
  File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/Analysis/cxx23-assume-attribute.cpp Line 75: assumption is ignored because it contains (potential) side-effects
1 error generated.

--

********************


@steakhal
Copy link
Contributor Author

steakhal commented Aug 5, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/32123
Here is the relevant piece of the build log for the reference

Fixed by 6c9f1ce.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 5, 2025

LLVM Buildbot has detected a new failure on builder clang-x86_64-debian-fast running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/32629

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Analysis/cxx23-assume-attribute.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/22/include -nostdsysteminc -analyze -setup-static-analyzer -std=c++23 -triple x86_64-pc-linux-gnu    -analyzer-checker=core,debug.ExprInspection -verify /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/cxx23-assume-attribute.cpp # RUN: at line 1
+ /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/22/include -nostdsysteminc -analyze -setup-static-analyzer -std=c++23 -triple x86_64-pc-linux-gnu -analyzer-checker=core,debug.ExprInspection -verify /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/cxx23-assume-attribute.cpp
error: 'expected-warning' diagnostics seen but not expected: 
  File /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/cxx23-assume-attribute.cpp Line 75: assumption is ignored because it contains (potential) side-effects
1 error generated.

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 5, 2025

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building clang at step 6 "test-build-unified-tree-check-clang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/34807

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-clang) failure: test (failure)
******************** TEST 'Clang :: Analysis/cxx23-assume-attribute.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/22/include -nostdsysteminc -analyze -setup-static-analyzer -std=c++23 -triple x86_64-pc-linux-gnu    -analyzer-checker=core,debug.ExprInspection -verify /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/cxx23-assume-attribute.cpp # RUN: at line 1
+ /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/22/include -nostdsysteminc -analyze -setup-static-analyzer -std=c++23 -triple x86_64-pc-linux-gnu -analyzer-checker=core,debug.ExprInspection -verify /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/cxx23-assume-attribute.cpp
error: 'expected-warning' diagnostics seen but not expected: 
  File /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Analysis/cxx23-assume-attribute.cpp Line 75: assumption is ignored because it contains (potential) side-effects
1 error generated.

--

********************


searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Aug 6, 2025
@steakhal steakhal added this to the LLVM 21.x Release milestone Aug 21, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Aug 21, 2025
@steakhal
Copy link
Contributor Author

@tru I have this (0a1eff2) simple patch that I want to backport to clang-21, however, it broke the CI build on main, so there was a followup patch (6c9f1ce) that consolidated the bots.
Do you prefer having these commits separate or squashed on the release/21.x branch?

FYI: both of these should apply cleanly if applied in the respective order.

@tru
Copy link
Collaborator

tru commented Aug 25, 2025

@steakhal you can cherry-pick both at the same time with cherry-pick that works for me.

@steakhal
Copy link
Contributor Author

/cherry-pick 0a1eff2 6c9f1ce

@llvmbot
Copy link
Member

llvmbot commented Aug 25, 2025

/pull-request #155284

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Aug 25, 2025
tru pushed a commit to llvmbot/llvm-project that referenced this pull request 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)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 26, 2025
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.

[analyzer] Assertion `Assumption && "We should know the exact outcome of an assume expr"' failed.

5 participants