-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang] Create PointerToBoolean casts for C casts #155368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesDon't create CK_BitCast casts from Fixes #155126 Full diff: https://github.com/llvm/llvm-project/pull/155368.diff 3 Files Affected:
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 933a6c558e7ac..72c5e37c8e2ea 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -3171,7 +3171,12 @@ void CastOperation::CheckCStyleCast() {
SrcExpr = ExprError();
return;
}
- if (!DestType->isNullPtrType()) {
+ if (DestType->isBooleanType()) {
+ SrcExpr = ImplicitCastExpr::Create(
+ Self.Context, DestType, CK_PointerToBoolean, SrcExpr.get(), nullptr,
+ VK_PRValue, Self.CurFPFeatureOverrides());
+
+ } else if (!DestType->isNullPtrType()) {
// Implicitly cast from the null pointer type to the type of the
// destination.
CastKind CK = DestType->isPointerType() ? CK_NullToPointer : CK_BitCast;
diff --git a/clang/test/CodeGen/issue155126.c b/clang/test/CodeGen/issue155126.c
new file mode 100644
index 0000000000000..ec15355d8d7df
--- /dev/null
+++ b/clang/test/CodeGen/issue155126.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c23 -verify %s
+// RUN: %clang_cc1 -std=c23 -verify -fexperimental-new-constant-interpreter %s
+
+// expected-no-diagnostics
+
+enum e : bool { b = true };
+void foo ()
+{
+ enum e e1;
+ e1 = (bool) nullptr;
+}
diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c
index 3dcb0b3a7d95f..e8f0700c5894f 100644
--- a/clang/test/Sema/constexpr.c
+++ b/clang/test/Sema/constexpr.c
@@ -391,3 +391,5 @@ void ghissue109095() {
_Static_assert(i == c[0]); // expected-error {{static assertion expression is not an integral constant expression}}\
// expected-note {{initializer of 'i' is not a constant expression}}
}
+constexpr bool b2 = (bool)nullptr;
+_Static_assert(!b2);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A release note probably makes sense.
Don't create CK_BitCast casts from `nullptr_t` to `bool`. Fixes llvm#155126
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/26289 Here is the relevant piece of the build log for the reference
|
Don't create CK_BitCast casts from
nullptr_t
tobool
.Fixes #155126