[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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(nullp

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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 con

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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 conve

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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 conve

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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);
 
   //

[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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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 

[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 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 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 &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, 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