[cfe-commits] r154626 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/conversion-64-32.c

David Blaikie dblaikie at gmail.com
Thu Apr 12 15:40:54 PDT 2012


Author: dblaikie
Date: Thu Apr 12 17:40:54 2012
New Revision: 154626

URL: http://llvm.org/viewvc/llvm-project?rev=154626&view=rev
Log:
Warn on 64-to-32 for source value of x bits where 64 >= x > 32.

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.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/conversion-64-32.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=154626&r1=154625&r2=154626&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Apr 12 17:40:54 2012
@@ -4233,7 +4233,7 @@
     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);

Modified: cfe/trunk/test/Sema/conversion-64-32.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/conversion-64-32.c?rev=154626&r1=154625&r2=154626&view=diff
==============================================================================
--- cfe/trunk/test/Sema/conversion-64-32.c (original)
+++ cfe/trunk/test/Sema/conversion-64-32.c Thu Apr 12 17:40:54 2012
@@ -13,3 +13,7 @@
   int4  v127 = a;  // no warning.
   return v127; 
 }
+
+int test2(long v) {
+  return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
+}





More information about the cfe-commits mailing list