Support -Wshorten-64-to-32 for integer types only, which seems to satisfy the

core requirements.  Fixes rdar://problem/6389954

llvm-svn: 86364
This commit is contained in:
John McCall 2009-11-07 09:03:53 +00:00
parent db5f24ce77
commit b61e9d03c1
4 changed files with 16 additions and 1 deletions

View File

@ -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,

View File

@ -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<DiagGroup<"conversion">>, DefaultIgnore;
def warn_impcast_integer_64_32 : Warning<
"implicit cast loses integer precision: %0 to %1">,
InGroup<DiagGroup<"shorten-64-to-32">>, DefaultIgnore;
def warn_attribute_ignored_for_field_of_type : Warning<
"%0 attribute ignored for field of type %1">;

View File

@ -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);
}

View File

@ -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}}
}