[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/Xazax-hun approved this pull request. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/isuckatcs approved this pull request. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s imdj wrote: > Duplicating the lines is the only way right now. I added a line for the c++26 standard for now https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
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
Date: Thu, 3 Jul 2025 13:50:55 +0300
Subject: [PATCH 1/6] 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(Term)->isConsteval())
+ return nullptr;
Cond = cast(Term)->getCond();
break;
case Stmt::ConditionalOperatorClass:
>From 27b793fcf2347d631991f9f83df7ef5787df17d6 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Thu, 3 Jul 2025 15:52:35 +0300
Subject: [PATCH 2/6] 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 0..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
Date: Thu, 3 Jul 2025 16:30:32 +0300
Subject: [PATCH 3/6] Update test formatting
Co-authored-by: Balazs Benics
---
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
+}
>From d5015902c9faad0858c99b7b462055e48cc4 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Mon, 7 Jul 2025 10:47:18 +0300
Subject: [PATCH 4/6] Improve code style
---
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 10 ++
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index d81a3f5a2858b..4631e0cad5546 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2793,12 +2793,14 @@ PathDiagnosticPieceRef
ConditionBRVisitor::VisitTerminator(
// more tricky because there are more than two branches to account for.
default:
return nullptr;
- case Stmt::IfStmtClass:
-// Handle if consteval which doesn't have a traditional condition
-if (cast(Term)->isConsteval())
+ case Stmt::IfStmtClass: {
+const auto *IfStatement = cast(Term);
+// Handle if consteval which doesn't have a traditional condition.
+if (IfStatement->isConsteval())
return nullptr;
-Cond = cast(Term)->getCond();
+Cond = IfStatement->getCond();
break;
+ }
case Stmt::ConditionalOperatorClass:
Cond = cast(Term)->getCond();
break;
>From 82a47298049a11d918e4e0d2a62bbd2683ce9aa1 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Mon, 7 Jul 2025 10:47:23 +0300
Subject: [PATCH 5/6] Add test for not consteval
---
clang/test/Analysis/consteval-if.cpp | 7 +++
1 file changed, 7 insertions(+)
diff --git a/clang/test/Analysis/consteval-if.cpp
b/clang/test/Analysis/consteval-if.cpp
index b7eae9db6a239..f9caacf2949c9 100644
--- a/clang/test/Analysis/consteval-if.cpp
+++ b/clang/test/Analysis/consteval-if.cpp
@@ -6,3 +6,10 @@ void test_consteval() {
*ptr = 42; // expected-warning{{Dereference of null pointer (loaded from
variable 'ptr')}}
}
}
+
+void test_not_consteval() {
+ if !consteval {
+int *ptr = nullptr;
+*ptr = 42; // expected-warning{{Dereference of null pointer (loaded from
variable 'ptr')}}
+ }
+}
>From 1ee1dc7aac719765068deac983fb7978daf07836 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Mon, 7 Jul 2025 12:31:52 +0300
Subject: [PATCH 6/6] Add run with c++26 standard as well
---
clang/test/Analysis/consteval-if.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/test/Analysis/consteval-if
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
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
Date: Thu, 3 Jul 2025 13:50:55 +0300
Subject: [PATCH 1/5] 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(Term)->isConsteval())
+ return nullptr;
Cond = cast(Term)->getCond();
break;
case Stmt::ConditionalOperatorClass:
>From 27b793fcf2347d631991f9f83df7ef5787df17d6 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Thu, 3 Jul 2025 15:52:35 +0300
Subject: [PATCH 2/5] 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 0..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
Date: Thu, 3 Jul 2025 16:30:32 +0300
Subject: [PATCH 3/5] Update test formatting
Co-authored-by: Balazs Benics
---
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
+}
>From d5015902c9faad0858c99b7b462055e48cc4 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Mon, 7 Jul 2025 10:47:18 +0300
Subject: [PATCH 4/5] Improve code style
---
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 10 ++
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index d81a3f5a2858b..4631e0cad5546 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2793,12 +2793,14 @@ PathDiagnosticPieceRef
ConditionBRVisitor::VisitTerminator(
// more tricky because there are more than two branches to account for.
default:
return nullptr;
- case Stmt::IfStmtClass:
-// Handle if consteval which doesn't have a traditional condition
-if (cast(Term)->isConsteval())
+ case Stmt::IfStmtClass: {
+const auto *IfStatement = cast(Term);
+// Handle if consteval which doesn't have a traditional condition.
+if (IfStatement->isConsteval())
return nullptr;
-Cond = cast(Term)->getCond();
+Cond = IfStatement->getCond();
break;
+ }
case Stmt::ConditionalOperatorClass:
Cond = cast(Term)->getCond();
break;
>From 82a47298049a11d918e4e0d2a62bbd2683ce9aa1 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Mon, 7 Jul 2025 10:47:23 +0300
Subject: [PATCH 5/5] Add test for not consteval
---
clang/test/Analysis/consteval-if.cpp | 7 +++
1 file changed, 7 insertions(+)
diff --git a/clang/test/Analysis/consteval-if.cpp
b/clang/test/Analysis/consteval-if.cpp
index b7eae9db6a239..f9caacf2949c9 100644
--- a/clang/test/Analysis/consteval-if.cpp
+++ b/clang/test/Analysis/consteval-if.cpp
@@ -6,3 +6,10 @@ void test_consteval() {
*ptr = 42; // expected-warning{{Dereference of null pointer (loaded from
variable 'ptr')}}
}
}
+
+void test_not_consteval() {
+ if !consteval {
+int *ptr = nullptr;
+*ptr = 42; // expected-warning{{Dereference of null pointer (loaded from
variable 'ptr')}}
+ }
+}
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s steakhal wrote: I'd reject the idea of sprinkling ifdefs and feature detections. Let's just move on. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s steakhal wrote: I don't think it's possible to create RUN lines for standards of which the flags are rejected by clang right now. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/isuckatcs edited https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s isuckatcs wrote: I don't have anything against, but I don't see this pattern in the analyzer tests, so I'm a bit hesitant. We however have a lot of the `#if __cplusplus >= XXX` pattern, so I would prefer to check for the standard to keep things consistent. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@
+// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s
imdj wrote:
Could we rely on feature detection? like
```
// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
#if __cpp_if_consteval >= 202106L
void test_consteval() {
...
#endif
```
https://github.com/llvm/llvm-project/pull/146859
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s isuckatcs wrote: I thought the [infrastructure used in clang-tidy](https://github.com/llvm/llvm-project/blob/c50415bb82a740426a5559ff7f1e350f394e9fcf/clang-tools-extra/test/clang-tidy/check_clang_tidy.py#L40) was incorporated into other projects as well, but it seems like it wasn't. For clang we do have an automatic standard picker in our [`config.py`](https://github.com/llvm/llvm-project/blob/c50415bb82a740426a5559ff7f1e350f394e9fcf/llvm/utils/lit/lit/llvm/config.py#L711) though. 😅 > What is the best approach to do this? I noticed in some files they duplicate > the line for each subsequent standard but that seems impractical. Duplicating the lines is the only way right now. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s steakhal wrote: I don't think we have tools for doing this. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s imdj wrote: > Please check every standard from C++23 and up What is the best approach to do this? I noticed in some files they duplicate the line for each subsequent standard but that seems impractical. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/isuckatcs edited https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@ +// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s isuckatcs wrote: Please check every standard from C++23 and up. We want to ensure that this case is handled properly for C++2, and every later standard as well. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -0,0 +1,8 @@
+// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core -verify %s
+
+void test_consteval() {
+ if consteval {
isuckatcs wrote:
Please add one more test for the `if !consteval` case too.
https://github.com/llvm/llvm-project/pull/146859
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -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(Term)->isConsteval()) + return nullptr; Cond = cast(Term)->getCond(); break; isuckatcs wrote: Nit: ```suggestion const auto *IfStmt = cast(Term); // Handle if consteval which doesn't have a traditional condition. if (IfStmt->isConsteval()) return nullptr; Cond = IfStmt->getCond(); break; ``` https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/isuckatcs requested changes to this pull request. https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
steakhal wrote: > Hey, could you add a LIT test that fails before your changes but passes after? Merge it once you are good. The added test should crash the analyzer without the fix, [see](https://godbolt.org/z/jxTMnGEY7). https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
imdj wrote: > Could you search the github issues for issues having the static analyzer > label and `consteval` to see if we missed anything? (I don't think we have, > but better be sure) There's only one result returned, and it's the same issue this PR is aimed at. https://github.com/llvm/llvm-project/issues?q=is%3Aissue%20consteval%20label%3A%22clang%3Astatic%20analyzer%22 https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/steakhal approved this pull request. Could you search the github issues for issues having the static analyzer label and `consteval` to see if we missed anything? (I don't think we have, but better be sure) https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
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
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(Term)->isConsteval())
+ return nullptr;
Cond = cast(Term)->getCond();
break;
case Stmt::ConditionalOperatorClass:
>From 27b793fcf2347d631991f9f83df7ef5787df17d6 Mon Sep 17 00:00:00 2001
From: Imad Aldij
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 0..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
Date: Thu, 3 Jul 2025 16:30:32 +0300
Subject: [PATCH 3/3] Update test formatting
Co-authored-by: Balazs Benics
---
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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
@@ -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')}}
+ }
+}
steakhal wrote:
```suggestion
}
```
https://github.com/llvm/llvm-project/pull/146859
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
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
Date: Thu, 3 Jul 2025 13:50:55 +0300
Subject: [PATCH 1/2] 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(Term)->isConsteval())
+ return nullptr;
Cond = cast(Term)->getCond();
break;
case Stmt::ConditionalOperatorClass:
>From 27b793fcf2347d631991f9f83df7ef5787df17d6 Mon Sep 17 00:00:00 2001
From: Imad Aldij
Date: Thu, 3 Jul 2025 15:52:35 +0300
Subject: [PATCH 2/2] 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 0..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
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
Xazax-hun wrote: Hey, could you add a LIT test that fails before your changes but passes after? https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Imad Aldij (imdj) Changes Fix crash when ConditionBRVisitor::VisitTerminator is faced with `if consteval` which doesn't have the expected traditional condition Close - #139130 --- Full diff: https://github.com/llvm/llvm-project/pull/146859.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (+3) ``diff 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(Term)->isConsteval()) + return nullptr; Cond = cast(Term)->getCond(); break; case Stmt::ConditionalOperatorClass: `` https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Imad Aldij (imdj) Changes Fix crash when ConditionBRVisitor::VisitTerminator is faced with `if consteval` which doesn't have the expected traditional condition Close - #139130 --- Full diff: https://github.com/llvm/llvm-project/pull/146859.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (+3) ``diff 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(Term)->isConsteval()) + return nullptr; Cond = cast(Term)->getCond(); break; case Stmt::ConditionalOperatorClass: `` https://github.com/llvm/llvm-project/pull/146859 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add support for consteval in ConditionBRVisitor::VisitTerminator (PR #146859)
https://github.com/imdj created https://github.com/llvm/llvm-project/pull/146859 Fix crash when ConditionBRVisitor::VisitTerminator is faced with `if consteval` which doesn't have the expected traditional condition Close - #139130 >From 1077e164158965e824097542dc4c3ecc8821d6dc Mon Sep 17 00:00:00 2001 From: Imad Aldij Date: Thu, 3 Jul 2025 13:50:55 +0300 Subject: [PATCH] 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(Term)->isConsteval()) + return nullptr; Cond = cast(Term)->getCond(); break; case Stmt::ConditionalOperatorClass: ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
