forked from OSchip/llvm-project
Don't emit pointer to int cast warnings under -Wmicrosoft-cast
Summary: MSVC also warns on this: $ cat /tmp/a.c int f(void* p) { return (int) p; } $ cl /c /tmp/a.c C:/src/tmp/a.c(1): warning C4311: 'type cast': pointer truncation from 'void *' to 'int' Warnings originally added in https://reviews.llvm.org/D72231. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75643
This commit is contained in:
parent
1f5b471b8b
commit
51d7f64544
|
@ -3682,9 +3682,6 @@ def warn_void_pointer_to_int_cast : Warning<
|
|||
def warn_void_pointer_to_enum_cast : Warning<
|
||||
warn_void_pointer_to_int_cast.Text>,
|
||||
InGroup<VoidPointerToEnumCast>;
|
||||
def ext_ms_pointer_to_int_cast : ExtWarn<
|
||||
"cast to smaller integer type %1 from %0 is a Microsoft extension">,
|
||||
InGroup<MicrosoftCast>;
|
||||
|
||||
def warn_attribute_ignored_for_field_of_type : Warning<
|
||||
"%0 attribute ignored for field of type %1">,
|
||||
|
|
|
@ -2778,9 +2778,7 @@ void CastOperation::CheckCStyleCast() {
|
|||
// is undefined. The result need not be in the range of values of any
|
||||
// integer type.
|
||||
unsigned Diag;
|
||||
if (Self.getLangOpts().MicrosoftExt)
|
||||
Diag = diag::ext_ms_pointer_to_int_cast;
|
||||
else if (SrcType->isVoidPointerType())
|
||||
if (SrcType->isVoidPointerType())
|
||||
Diag = DestType->isEnumeralType() ? diag::warn_void_pointer_to_enum_cast
|
||||
: diag::warn_void_pointer_to_int_cast;
|
||||
else if (DestType->isEnumeralType())
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
|
||||
|
||||
// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-extensions
|
||||
|
||||
struct A
|
||||
{
|
||||
|
@ -93,13 +92,13 @@ enum : long long { // expected-warning{{enumeration types with a fixed underlyi
|
|||
};
|
||||
|
||||
void pointer_to_integral_type_conv(char* ptr) {
|
||||
char ch = (char)ptr; // expected-warning{{cast to smaller integer type 'char' from 'char *' is a Microsoft extension}}
|
||||
short sh = (short)ptr; // expected-warning{{cast to smaller integer type 'short' from 'char *' is a Microsoft extension}}
|
||||
ch = (char)ptr; // expected-warning{{cast to smaller integer type 'char' from 'char *' is a Microsoft extension}}
|
||||
sh = (short)ptr; // expected-warning{{cast to smaller integer type 'short' from 'char *' is a Microsoft extension}}
|
||||
char ch = (char)ptr;
|
||||
short sh = (short)ptr;
|
||||
ch = (char)ptr;
|
||||
sh = (short)ptr;
|
||||
|
||||
// This is valid ISO C.
|
||||
_Bool b = (_Bool)ptr;
|
||||
// This is valid ISO C.
|
||||
_Bool b = (_Bool)ptr;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Reference in New Issue