[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix
Peter Szecsi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 02:41:37 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313016: [clang-tidy] SuspiciousEnumUsageCheck bugfix (authored by szepet).
Changed prior to commit:
https://reviews.llvm.org/D37572?vs=114567&id=114788#toc
Repository:
rL LLVM
https://reviews.llvm.org/D37572
Files:
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp
Index: clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp
@@ -54,7 +54,7 @@
int emptytest = EmptyVal | B;
if (bestDay() | A)
return 1;
- // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different enum types
+ // CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different enum types
if (I | Y)
return 1;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different enum types
@@ -88,3 +88,9 @@
return 1;
return 42;
}
+
+namespace PR34400 {
+enum { E1 = 0 };
+enum { E2 = -1 };
+enum { l = E1 | E2 };
+}
Index: clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
@@ -42,7 +42,8 @@
const auto MinMaxVal = std::minmax_element(
EnumDec->enumerator_begin(), EnumDec->enumerator_end(),
[](const EnumConstantDecl *E1, const EnumConstantDecl *E2) {
- return E1->getInitVal() < E2->getInitVal();
+ return llvm::APSInt::compareValues(E1->getInitVal(),
+ E2->getInitVal()) < 0;
});
MinVal = MinMaxVal.first->getInitVal();
MaxVal = MinMaxVal.second->getInitVal();
@@ -57,7 +58,8 @@
static bool hasDisjointValueRange(const EnumDecl *Enum1,
const EnumDecl *Enum2) {
ValueRange Range1(Enum1), Range2(Enum2);
- return (Range1.MaxVal < Range2.MinVal) || (Range2.MaxVal < Range1.MinVal);
+ return llvm::APSInt::compareValues(Range1.MaxVal, Range2.MinVal) < 0 ||
+ llvm::APSInt::compareValues(Range2.MaxVal, Range1.MinVal) < 0;
}
static bool isNonPowerOf2NorNullLiteral(const EnumConstantDecl *EnumConst) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37572.114788.patch
Type: text/x-patch
Size: 2092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170912/527e5ecd/attachment.bin>
More information about the cfe-commits
mailing list