]> granicus.if.org Git - clang/commitdiff
Warn on 64-to-32 for source value of x bits where 64 >= x > 32.
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 12 Apr 2012 22:40:54 +0000 (22:40 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 12 Apr 2012 22:40:54 +0000 (22:40 +0000)
The codepath already only works for source bits > target bits, it's just that
it was testing for the source expr bits to be exactly 64. This meant simple
cases (int i = x_long / 2) were missed & ended up under the general
-Wconversion warning, which a user might not have enabled.

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

lib/Sema/SemaChecking.cpp
test/Sema/conversion-64-32.c

index 1606e336ee7337e2d20f2d9921012c43adce84d3..7fabfaf565c016bc40d6f3260d5150c765d145c5 100644 (file)
@@ -4233,7 +4233,7 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
     if (S.SourceMgr.isInSystemMacro(CC))
       return;
     
-    if (SourceRange.Width == 64 && TargetRange.Width == 32)
+    if (TargetRange.Width == 32 && S.Context.getIntWidth(E->getType()) == 64)
       return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_64_32,
                              /* pruneControlFlow */ true);
     return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_precision);
index 112e995102c59e6aac0ab9e1842136934ae31e66..3de20cb0fda3aa626198f7279da9a32ea6724e02 100644 (file)
@@ -13,3 +13,7 @@ int4 test1(long2 a) {
   int4  v127 = a;  // no warning.
   return v127; 
 }
+
+int test2(long v) {
+  return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
+}