Skip to content

Conversation

@el-ev
Copy link
Member

@el-ev el-ev commented Aug 1, 2025

ParenExpr should be ignored before reaching ExprEngine::Visit. Failing to do so triggers the assertion.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Aug 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2025

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

Author: Iris Shi (el-ev)

Changes
  • Closes #151529

ParenExpr should be ignored before reaching ExprEngine::Visit. Failing to do so triggers the assertion.


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

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+2)
  • (modified) clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (+1-1)
  • (added) clang/test/Analysis/issue-151529.cpp (+7)
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;
+}

@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2025

@llvm/pr-subscribers-clang

Author: Iris Shi (el-ev)

Changes
  • Closes #151529

ParenExpr should be ignored before reaching ExprEngine::Visit. Failing to do so triggers the assertion.


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

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+2)
  • (modified) clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (+1-1)
  • (added) clang/test/Analysis/issue-151529.cpp (+7)
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;
+}

@el-ev el-ev force-pushed the users/el-ev/issue151529 branch from efb9dcb to fa6335d Compare August 1, 2025 10:38
Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thank you for the patch. It looks like it was an easy fix!
I left a couple of minor remarks inline to address before we could merge this.
Thanks again!

@el-ev el-ev requested a review from steakhal August 1, 2025 10:54
@el-ev el-ev force-pushed the users/el-ev/issue151529 branch from 7d2587d to 05984ff Compare August 1, 2025 10:55
Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks. Let's wait the CI to finish then we can merge this.

@el-ev el-ev merged commit f9088f1 into main Aug 1, 2025
10 checks passed
@el-ev el-ev deleted the users/el-ev/issue151529 branch August 1, 2025 11:29
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

None yet

Development

Successfully merging this pull request may close these issues.

[analyzer] Assertion `!isa<Expr>(S) || S == cast<Expr>(S)->IgnoreParens()' failed.

4 participants