From: John McCall Date: Sat, 7 Nov 2009 09:03:53 +0000 (+0000) Subject: Support -Wshorten-64-to-32 for integer types only, which seems to satisfy the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc767a1f560ae936a08eeead8164be6f82b6b0f7;p=clang Support -Wshorten-64-to-32 for integer types only, which seems to satisfy the core requirements. Fixes rdar://problem/6389954 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86364 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 76147ffed8..0c1ae8d10a 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -28,7 +28,6 @@ def : DiagGroup<"cast-align">; def : DiagGroup<"cast-qual">; def : DiagGroup<"char-align">; def Comment : DiagGroup<"comment">; -def Conversion : DiagGroup<"conversion">; def : DiagGroup<"declaration-after-statement">; def : DiagGroup<"disabled-optimization">; def : DiagGroup<"discard-qual">; @@ -114,6 +113,10 @@ def CharSubscript : DiagGroup<"char-subscripts">; // Aggregation warning settings. +// -Wconversion has its own warnings, but we split this one out for +// legacy reasons. +def Conversion : DiagGroup<"conversion", + [DiagGroup<"shorten-64-to-32">]>; def Unused : DiagGroup<"unused", [UnusedArgument, UnusedFunction, UnusedLabel, diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index e1cbab692e..29b207927f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -647,6 +647,9 @@ def warn_impcast_float_integer : Warning< def warn_impcast_integer_precision : Warning< "implicit cast loses integer precision: %0 to %1">, InGroup>, DefaultIgnore; +def warn_impcast_integer_64_32 : Warning< + "implicit cast loses integer precision: %0 to %1">, + InGroup>, DefaultIgnore; def warn_attribute_ignored_for_field_of_type : Warning< "%0 attribute ignored for field of type %1">; diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 951856db71..38063ac018 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -665,6 +665,10 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T) { if (IsExprValueWithinWidth(S.Context, E, TargetWidth)) return; + // People want to build with -Wshorten-64-to-32 and not -Wconversion + // and by god we'll let them. + if (SourceWidth == 64 && TargetWidth == 32) + return DiagnoseImpCast(S, E, T, diag::warn_impcast_integer_64_32); return DiagnoseImpCast(S, E, T, diag::warn_impcast_integer_precision); } diff --git a/test/Sema/conversion-64-32.c b/test/Sema/conversion-64-32.c new file mode 100644 index 0000000000..53830fd061 --- /dev/null +++ b/test/Sema/conversion-64-32.c @@ -0,0 +1,5 @@ +// RUN: clang-cc -fsyntax-only -verify -Wshorten-64-to-32 -triple x86_64-apple-darwin %s + +int test0(long v) { + return v; // expected-warning {{implicit cast loses integer precision}} +}