From abbc51e5c34df90872c510b3221e817e714fccda Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Wed, 10 Oct 2018 00:40:50 +0000 Subject: [PATCH] [Basic] Split out -Wimplicit-int-conversion and -Wimplicit-float-conversion from -Wconversion These two diagnostics are noisy, so its reasonable for users to opt-out of them when -Wconversion is enabled. rdar://45058981 Differential revision: https://reviews.llvm.org/D53048 llvm-svn: 344101 --- clang/include/clang/Basic/DiagnosticGroups.td | 4 ++++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 8 ++++---- clang/test/Sema/implicit-int-conversion.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 clang/test/Sema/implicit-int-conversion.c diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 4b77d0859441..d14aa8da29bb 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -59,6 +59,8 @@ def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion, UndefinedBoolConversion]>; def IntConversion : DiagGroup<"int-conversion">; def EnumConversion : DiagGroup<"enum-conversion">; +def ImplicitIntConversion : DiagGroup<"implicit-int-conversion">; +def ImplicitFloatConversion : DiagGroup<"implicit-float-conversion">; def FloatOverflowConversion : DiagGroup<"float-overflow-conversion">; def FloatZeroConversion : DiagGroup<"float-zero-conversion">; @@ -709,6 +711,8 @@ def Conversion : DiagGroup<"conversion", FloatConversion, Shorten64To32, IntConversion, + ImplicitIntConversion, + ImplicitFloatConversion, LiteralConversion, NonLiteralNullConversion, // (1-1)->pointer (etc) NullConversion, // NULL->non-pointer diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b00e8b1ad6c8..86b43e37bb41 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3181,10 +3181,10 @@ def err_impcast_complex_scalar : Error< "implicit conversion from %0 to %1 is not permitted in C++">; def warn_impcast_float_precision : Warning< "implicit conversion loses floating-point precision: %0 to %1">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def warn_impcast_float_result_precision : Warning< "implicit conversion when assigning computation result loses floating-point precision: %0 to %1">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def warn_impcast_double_promotion : Warning< "implicit conversion increases floating-point precision: %0 to %1">, InGroup, DefaultIgnore; @@ -3196,10 +3196,10 @@ def warn_impcast_integer_sign_conditional : Warning< InGroup, DefaultIgnore; def warn_impcast_integer_precision : Warning< "implicit conversion loses integer precision: %0 to %1">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def warn_impcast_high_order_zero_bits : Warning< "higher order bits are zeroes after implicit conversion">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def warn_impcast_nonnegative_result : Warning< "the resulting value is always non-negative after implicit conversion">, InGroup, DefaultIgnore; diff --git a/clang/test/Sema/implicit-int-conversion.c b/clang/test/Sema/implicit-int-conversion.c new file mode 100644 index 000000000000..6d07d385e0bd --- /dev/null +++ b/clang/test/Sema/implicit-int-conversion.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -verify -Wconversion -Wno-implicit-int-conversion -DSMALL=char -DBIG=int -DNO_DIAG +// RUN: %clang_cc1 %s -verify -Wno-conversion -Wimplicit-int-conversion -DSMALL=char -DBIG=int +// RUN: %clang_cc1 %s -verify -Wconversion -Wno-implicit-float-conversion -DSMALL=float -DBIG=double -DNO_DIAG +// RUN: %clang_cc1 %s -verify -Wno-conversion -Wimplicit-float-conversion -DSMALL=float -DBIG=double + +void f() { + SMALL a; + BIG b = 0; + a = b; +#ifndef NO_DIAG + // expected-warning@-2 {{implicit conversion}} +#else + // expected-no-diagnostics +#endif +}