]> granicus.if.org Git - clang/commitdiff
Support -Wshorten-64-to-32 for integer types only, which seems to satisfy the
authorJohn McCall <rjmccall@apple.com>
Sat, 7 Nov 2009 09:03:53 +0000 (09:03 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 7 Nov 2009 09:03:53 +0000 (09:03 +0000)
core requirements.  Fixes rdar://problem/6389954

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86364 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/Sema.cpp
test/Sema/conversion-64-32.c [new file with mode: 0644]

index 76147ffed8b780bd879c5b539afb1d7f5c1f8f63..0c1ae8d10a7532cd8da67ac7472a746ceecdc229 100644 (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,
index e1cbab692e17228053f4269aa9a55096a7bc0a06..29b207927f2802e21ca14ec13fa1377e3ba219f5 100644 (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">;
index 951856db713a6dd96a7e48cc72e0a7f1fa34cb4a..38063ac01858e39ad8d28646f4be8a0f8fc77039 100644 (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);
   }
 
diff --git a/test/Sema/conversion-64-32.c b/test/Sema/conversion-64-32.c
new file mode 100644 (file)
index 0000000..53830fd
--- /dev/null
@@ -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}}
+}