https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/155284
Backport 0a1eff2ecedcb11acb3e9d4b75ee1e1bebd69a70 6c9f1ce429809e5a91683ed6cef9a435047bebd1 Requested by: @steakhal >From 5957089de666805deb1e1d442cf30f4f42d5f51b Mon Sep 17 00:00:00 2001 From: Balazs Benics <benicsbal...@gmail.com> Date: Tue, 5 Aug 2025 17:03:53 +0200 Subject: [PATCH 1/2] [analyzer] Drop assertion enforcing that assume args are known constants (#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 #151854 (cherry picked from commit 0a1eff2ecedcb11acb3e9d4b75ee1e1bebd69a70) --- clang/lib/StaticAnalyzer/Checkers/AssumeModeling.cpp | 1 - clang/test/Analysis/cxx23-assume-attribute.cpp | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 +} >From 3bdd65de3c64058361f1b2b3352e87f7940c7fa9 Mon Sep 17 00:00:00 2001 From: Balazs Benics <benicsbal...@gmail.com> Date: Tue, 5 Aug 2025 17:28:49 +0200 Subject: [PATCH 2/2] [analyzer] Add missing expected-warning after #151908 (cherry picked from commit 6c9f1ce429809e5a91683ed6cef9a435047bebd1) --- clang/test/Analysis/cxx23-assume-attribute.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/test/Analysis/cxx23-assume-attribute.cpp b/clang/test/Analysis/cxx23-assume-attribute.cpp index dd15ff5d43505..4cc16446572dc 100644 --- a/clang/test/Analysis/cxx23-assume-attribute.cpp +++ b/clang/test/Analysis/cxx23-assume-attribute.cpp @@ -73,4 +73,5 @@ int assume_and_fallthrough_at_the_same_attrstmt(int a, int b) { 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}} } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits