[PATCH] D74860: [Sema] Fix pointer-to-int-cast diagnostic for _Bool
Mark de Wever via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 19 12:52:17 PST 2020
Mordante created this revision.
Mordante added reviewers: dblaikie, rjmccall, rsmith, nathanchance, nickdesaulniers.
Mordante added a project: clang.
The diagnostic added in D72231 <https://reviews.llvm.org/D72231> also shows a diagnostic when casting to a _Bool. This is unwanted. This patch removes the diagnostic for _Bool.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74860
Files:
clang/lib/Sema/SemaCast.cpp
clang/test/Sema/MicrosoftExtensions.c
clang/test/Sema/cast.c
Index: clang/test/Sema/cast.c
===================================================================
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -151,7 +151,7 @@
}
void testVoidPtr(VoidPtr v) {
- (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+ (void) (Bool) v;
(void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}
(void) (Long) v;
(void) (VoidPtr) v;
@@ -160,12 +160,12 @@
// from other -Wpointer-to-int-cast warnings.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
- (void) (Bool) v; // no-warning
+ (void) (Int) v; // no-warning
#pragma clang diagnostic pop
}
void testCharPtr(CharPtr v) {
- (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'CharPtr' (aka 'char *')}}
+ (void) (Bool) v;
(void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
(void) (Long) v;
(void) (VoidPtr) v;
@@ -174,7 +174,7 @@
// from other -Wpointer-to-int-cast warnings.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
- (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'CharPtr' (aka 'char *')}}
+ (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
#pragma clang diagnostic pop
}
Index: clang/test/Sema/MicrosoftExtensions.c
===================================================================
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -99,7 +99,7 @@
sh = (short)ptr; // expected-warning{{cast to smaller integer type 'short' from 'char *' is a Microsoft extension}}
// This is valid ISO C.
- _Bool b = (_Bool)ptr; // expected-warning{{cast to smaller integer type '_Bool' from 'char *' is a Microsoft extension}}
+ _Bool b = (_Bool)ptr;
}
typedef struct {
Index: clang/lib/Sema/SemaCast.cpp
===================================================================
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -2764,7 +2764,8 @@
}
if ((Self.Context.getTypeSize(SrcType) >
- Self.Context.getTypeSize(DestType))) {
+ Self.Context.getTypeSize(DestType)) &&
+ !DestType->isBooleanType()) {
// C 6.3.2.3p6: Any pointer type may be converted to an integer type.
// Except as previously specified, the result is implementation-defined.
// If the result cannot be represented in the integer type, the behavior
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74860.245489.patch
Type: text/x-patch
Size: 2713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200219/5d61d69e/attachment-0001.bin>
More information about the cfe-commits
mailing list