[clang] [static analyzer] Fix crash on parenthesized expression in assume attribute (PR #151682)
Iris Shi via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 1 03:16:15 PDT 2025
https://github.com/el-ev created https://github.com/llvm/llvm-project/pull/151682
- Closes #151529
`ParenExpr` should be ignored before reaching `ExprEngine::Visit`. Failing to do so triggers the assertion.
>From efb9dcb3a036b9c28b72bcdb1739aec2c26aa6e0 Mon Sep 17 00:00:00 2001
From: Iris Shi <0.0 at owo.li>
Date: Fri, 1 Aug 2025 18:08:48 +0800
Subject: [PATCH] [static analyzer] Fix crash on parenthesized expression in
assume attribute
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 2 +-
clang/test/Analysis/issue-151529.cpp | 7 +++++++
3 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Analysis/issue-151529.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4a2edae7509de..2dfbea312b894 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,8 @@ Bug Fixes to Attribute Support
- ``[[nodiscard]]`` is now respected on Objective-C and Objective-C++ methods.
(#GH141504)
+- Fixed a crash in the static analyzer that when the expression in an
+ ``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 85353848aa124..fe70558dfc45c 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -1227,7 +1227,7 @@ void ExprEngine::VisitAttributedStmt(const AttributedStmt *A,
for (const auto *Attr : getSpecificAttrs<CXXAssumeAttr>(A->getAttrs())) {
for (ExplodedNode *N : CheckerPreStmt) {
- Visit(Attr->getAssumption(), N, EvalSet);
+ Visit(Attr->getAssumption()->IgnoreParens(), N, EvalSet);
}
}
diff --git a/clang/test/Analysis/issue-151529.cpp b/clang/test/Analysis/issue-151529.cpp
new file mode 100644
index 0000000000000..0774587055e0c
--- /dev/null
+++ b/clang/test/Analysis/issue-151529.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=cplusplus -verify %s
+// expected-no-diagnostics
+
+int main() {
+ [[assume((true))]]; // crash
+ return 0;
+}
More information about the cfe-commits
mailing list