https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/146859
>From 1077e164158965e824097542dc4c3ecc8821d6dc Mon Sep 17 00:00:00 2001 From: Imad Aldij <o...@imadij.com> Date: Thu, 3 Jul 2025 13:50:55 +0300 Subject: [PATCH 1/3] Add support for consteval if in ConditionBRVisitor --- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 3686bd4488877..d81a3f5a2858b 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -2794,6 +2794,9 @@ PathDiagnosticPieceRef ConditionBRVisitor::VisitTerminator( default: return nullptr; case Stmt::IfStmtClass: + // Handle if consteval which doesn't have a traditional condition + if (cast<IfStmt>(Term)->isConsteval()) + return nullptr; Cond = cast<IfStmt>(Term)->getCond(); break; case Stmt::ConditionalOperatorClass: >From 27b793fcf2347d631991f9f83df7ef5787df17d6 Mon Sep 17 00:00:00 2001 From: Imad Aldij <o...@imadij.com> Date: Thu, 3 Jul 2025 15:52:35 +0300 Subject: [PATCH 2/3] add test case for consteval and ConditionBRVisitor --- clang/test/Analysis/consteval-if.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 clang/test/Analysis/consteval-if.cpp diff --git a/clang/test/Analysis/consteval-if.cpp b/clang/test/Analysis/consteval-if.cpp new file mode 100644 index 0000000000000..2ce9a69067951 --- /dev/null +++ b/clang/test/Analysis/consteval-if.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s + +void test_consteval() { + if consteval { + int *ptr = nullptr; + *ptr = 42; // expected-warning{{Dereference of null pointer (loaded from variable 'ptr')}} + } +} \ No newline at end of file >From 90a235dfff9c6eaaa47f62d542de03868154a806 Mon Sep 17 00:00:00 2001 From: Imad Aldij <m...@imadij.com> Date: Thu, 3 Jul 2025 16:30:32 +0300 Subject: [PATCH 3/3] Update test formatting Co-authored-by: Balazs Benics <benicsbal...@gmail.com> --- clang/test/Analysis/consteval-if.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Analysis/consteval-if.cpp b/clang/test/Analysis/consteval-if.cpp index 2ce9a69067951..b7eae9db6a239 100644 --- a/clang/test/Analysis/consteval-if.cpp +++ b/clang/test/Analysis/consteval-if.cpp @@ -5,4 +5,4 @@ void test_consteval() { int *ptr = nullptr; *ptr = 42; // expected-warning{{Dereference of null pointer (loaded from variable 'ptr')}} } -} \ No newline at end of file +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits