[clang-tools-extra] r313016 - [clang-tidy] SuspiciousEnumUsageCheck bugfix
Peter Szecsi via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 02:40:13 PDT 2017
Author: szepet
Date: Tue Sep 12 02:40:13 2017
New Revision: 313016
URL: http://llvm.org/viewvc/llvm-project?rev=313016&view=rev
Log:
[clang-tidy] SuspiciousEnumUsageCheck bugfix
iThere is a reported bug on the checker not handling the some APSInt values
correctly: https://bugs.llvm.org/show_bug.cgi?id=34400
This patch aims to fix it.
Differential Revision: https://reviews.llvm.org/D37572
Modified:
clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp?rev=313016&r1=313015&r2=313016&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SuspiciousEnumUsageCheck.cpp Tue Sep 12 02:40:13 2017
@@ -42,7 +42,8 @@ struct ValueRange {
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 int enumLength(const EnumDecl *En
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) {
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp?rev=313016&r1=313015&r2=313016&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-suspicious-enum-usage.cpp Tue Sep 12 02:40:13 2017
@@ -54,7 +54,7 @@ int trigger() {
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 @@ int dont_trigger() {
return 1;
return 42;
}
+
+namespace PR34400 {
+enum { E1 = 0 };
+enum { E2 = -1 };
+enum { l = E1 | E2 };
+}
More information about the cfe-commits
mailing list