[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

This passed precommit CI before and the only difference is that there are 
formatting changes removed, so I'm landing this before precommit CI finishes.

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM, thank you for the fix!

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread Pil Eghoff via cfe-commits

pileghoff wrote:

> It looks like a bunch of formatting changes came in with SemaChecking.cpp. 
> You should only be formatting the code that your patch needs to touch. We've 
> got a script for that: 
> https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting or 
> https://clang.llvm.org/docs/ClangFormat.html#git-integration
> 
> Can you back out the unrelated formatting changes?

Whoops, my editor got a bit trigger happy. It should restored now.

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From ee164634ffd2db4a7e590faeba7a3a631e8e75db Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  5 ++-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9473867c1f231..89302dfc09734 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -122,6 +122,8 @@ Bug Fixes in This Version
 - Clang now accepts elaborated-type-specifiers that explicitly specialize
   a member class template for an implicit instantiation of a class template.
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435 
`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b4..a9f08354b3497 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16134,7 +16134,10 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  // While C23 does have bool as a keyword, we still need to run the bool-like
+  // conversion checks as bools are still not used as the return type from
+  // "boolean" operators or as the input type for conditional operators.
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af480..99661b1fb39eb 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman requested changes to this pull request.

It looks like a bunch of formatting changes came in with SemaChecking.cpp. You 
should only be formatting the code that your patch needs to touch. We've got a 
script for that: 
https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting or 
https://clang.llvm.org/docs/ClangFormat.html#git-integration

Can you back out the unrelated formatting changes?

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-30 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff e37a6008831b38477516362892dd3c0d97087eff 
aea883b73a072e8a7bd261a4d6b5885660bd215f -- clang/lib/Sema/SemaChecking.cpp 
clang/test/C/C2x/n3042.c clang/test/Sema/warn-int-in-bool-context.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 6c31dc7245..86879e097e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16134,8 +16134,8 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  // While C23 does have bool as a keyword, we still need to run the bool-like 
-  // conversion checks as bools are still not used as the return type from 
+  // While C23 does have bool as a keyword, we still need to run the bool-like
+  // conversion checks as bools are still not used as the return type from
   // "boolean" operators or as the input type for conditional operator.
   if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;

``




https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-29 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 38d96aba5818091d48c40a46738f5adbf881b2a8 Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9d68be469dac39..df502b50a9536a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -117,6 +117,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435 
`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b42..3e08f44a5b84b7 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16134,7 +16134,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af4807..99661b1fb39eba 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit conversion of 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From f22d0a6888be86c5105a00e3f83201f71165f78f Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1..b184eb378cd02a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435 
`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af4807..99661b1fb39eba 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit conversion of 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From b059e03eb5330054e76c833699611fdc9bfb1967 Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1d..55b76a273906b45 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435: 
`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c25..8e3bd1cd46076d6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af48070..99661b1fb39eba1 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 6ea74d7aa0eadd4093350c04de95cbb2bdbaf0eb Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1d..641fa14ab069ed5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435: 
https://github.com/llvm/llvm-project/issues/79435`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c25..8e3bd1cd46076d6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af48070..99661b1fb39eba1 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 29a1eea6b27210ba35ad035b3c10aa8f5c73d86c Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1d..641fa14ab069ed5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435: 
https://github.com/llvm/llvm-project/issues/79435`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c25..8e3bd1cd46076d6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af48070..99661b1fb39eba1 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 34bb01d59005059c7f8f1156a164993c1839ee36 Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1..1a8e17b2b3065a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 
[#79435](https://github.com/llvm/llvm-project/issues/79435).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af4807..99661b1fb39eba 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit conversion of 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 2c942f755c147a8413af4784f85da46f1f5384bd Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c25..8e3bd1cd46076d6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af48070..99661b1fb39eba1 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
   _Generic(typed_ptr ?: null_val, typeof(typed_ptr) : 0);
-  _Generic(null_val ?: typed_ptr, typeof(typed_ptr) : 0);
-  _Generic(nullptr ?: typed_ptr, typeof(typed_ptr) : 0);
+  _Generic(null_val ?: typed_ptr, typeof(typed_ptr) : 0); // expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(nullptr ?: typed_ptr, typeof(typed_ptr) : 0);  // expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
   _Generic(typed_ptr ?: nullptr, typeof(typed_ptr) : 0);
 
   // Do 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

pileghoff wrote:

For testing i have fixed the new warnings in `n3042.c` and i have expanded 
`warn-int-in-bool-context.c` to check c23 specefically (which was broken, but 
is now fixed) and i added a few extra cases to the test. I will take a look at 
the release notes later today.

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-28 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 43241ab75d4c15e6885337be1b0ce4cf0217f384 Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af4807..99661b1fb39eba 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
   _Generic(typed_ptr ?: null_val, typeof(typed_ptr) : 0);
-  _Generic(null_val ?: typed_ptr, typeof(typed_ptr) : 0);
-  _Generic(nullptr ?: typed_ptr, typeof(typed_ptr) : 0);
+  _Generic(null_val ?: typed_ptr, typeof(typed_ptr) : 0); // expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(nullptr ?: typed_ptr, typeof(typed_ptr) : 0);  // expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
   _Generic(typed_ptr ?: nullptr, typeof(typed_ptr) : 0);
 
   // Do we 

[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

pileghoff wrote:

I can also see i broke the `n3042.c` test. Stuff like `if (null_val) {}` now 
throws a warning, since `null_val` is a constant.

I would expect this warning to be okay in that scenario?

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

pileghoff wrote:

> Thank you for the Fix! Your summary should be a description of the problem 
> and how your solution fixes that problem. You should also link to the github 
> issue in the summary.
> 
> Questions about the changes in the PR should go as a comment to the PR.
> 
> Please add a release note and this will need tests as well.

Noted. I have updated the description.

With regards to testing, I think I get how to write them, but I'm still unsure 
about where I'm suppose to put them. Would a new file 
(`implicit-boolike-conversion.c`?) be appropriate? 

Is the PR requirements/process documented anywhere? I had a look at 
[here](https://llvm.org/docs/Contributing.html) and i was looking around if 
there was a template, but i have found nothing.

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff edited 
https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Thank you for the Fix! Your summary should be a description of the problem and 
how your solution fixes that problem. You should also link to the github issue 
in the summary.

Questions about the changes in the PR should go as a comment to the PR.

Please add a release note and this will need tests as well.

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

pileghoff wrote:

@AaronBallman If you have time for review, the PR is ready  

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pil Eghoff (pileghoff)


Changes

Fixes #79435 

Im not sure if this is the best solution, but it seems to work well.
Should i be adding tests for this? If i should, i would need some help on how. 
I was able to run the test suite, but i have no idea where this test would go. 
My guess would be `tautological-constant-compare.c`, but that test seems to be 
C++ specific.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;

``




https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/79588
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-26 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff created 
https://github.com/llvm/llvm-project/pull/79588

Fixes #79435 

Im not sure if this is the best solution, but it seems to work well.
Should i be adding tests for this? If i should, i would need some help on how. 
I was able to run the test suite, but i have no idea where this test would go. 
My guess would be `tautological-constant-compare.c`, but that test seems to be 
C++ specific.

>From cdacba44198ed9925cbc2cd9e6c79a9b74265b4f Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/lib/Sema/SemaChecking.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d280f25cc04c2..8e3bd1cd46076d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16166,7 +16166,7 @@ static void CheckConditionalOperator(Sema , 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema , Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits