[clang-tools-extra] r260667 - [clang-tidy] Fix failure in 'misc-misplaced-widening-cast' test.

Daniel Marjamaki via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 01:38:38 PST 2016


Author: danielmarjamaki
Date: Fri Feb 12 03:38:38 2016
New Revision: 260667

URL: http://llvm.org/viewvc/llvm-project?rev=260667&view=rev
Log:
[clang-tidy] Fix failure in 'misc-misplaced-widening-cast' test.

I added portability warnings when int results are casted to long. I forgot to handle uint, ulong and ulonglong.

Tested on x86 and powerpc targets, hope it works now on all buildbots.

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp?rev=260667&r1=260666&r2=260667&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp Fri Feb 12 03:38:38 2016
@@ -96,14 +96,19 @@ void MisplacedWideningCastCheck::check(c
   // If CalcType and CastType have same size then there is no real danger, but
   // there can be a portability problem.
   if (Context.getIntWidth(CastType) == Context.getIntWidth(CalcType)) {
-    if (CalcType->isSpecificBuiltinType(BuiltinType::Int)) {
+    if (CalcType->isSpecificBuiltinType(BuiltinType::Int) ||
+        CalcType->isSpecificBuiltinType(BuiltinType::UInt)) {
       // There should be a warning when casting from int to long or long long.
       if (!CastType->isSpecificBuiltinType(BuiltinType::Long) &&
-          !CastType->isSpecificBuiltinType(BuiltinType::LongLong))
+          !CastType->isSpecificBuiltinType(BuiltinType::ULong) &&
+          !CastType->isSpecificBuiltinType(BuiltinType::LongLong) &&
+          !CastType->isSpecificBuiltinType(BuiltinType::ULongLong))
         return;
-    } else if (CalcType->isSpecificBuiltinType(BuiltinType::Long)) {
+    } else if (CalcType->isSpecificBuiltinType(BuiltinType::Long) ||
+               CalcType->isSpecificBuiltinType(BuiltinType::ULong)) {
       // There should be a warning when casting from long to long long.
-      if (!CastType->isSpecificBuiltinType(BuiltinType::LongLong))
+      if (!CastType->isSpecificBuiltinType(BuiltinType::LongLong) &&
+          !CastType->isSpecificBuiltinType(BuiltinType::ULongLong))
         return;
     } else {
       return;




More information about the cfe-commits mailing list