[PATCH] D37572: [clang-tidy] SuspiciousEnumUsageCheck bugfix
Peter Szecsi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 11 04:32:00 PDT 2017
szepet updated this revision to Diff 114567.
szepet marked 3 inline comments as done.
szepet added a comment.
Updates based on the comments. Thanks for the reduced test case and the fast review!
Not sure if in these cases am I allowed to commit (since it was accepted) or since it was accepted a lot of comments ago I should wait for another response?
https://reviews.llvm.org/D37572
Files:
clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
test/clang-tidy/misc-suspicious-enum-usage.cpp
Index: test/clang-tidy/misc-suspicious-enum-usage.cpp
===================================================================
--- test/clang-tidy/misc-suspicious-enum-usage.cpp
+++ 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-tidy/misc/SuspiciousEnumUsageCheck.cpp
===================================================================
--- clang-tidy/misc/SuspiciousEnumUsageCheck.cpp
+++ 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.114567.patch
Type: text/x-patch
Size: 1948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170911/06fb5bd6/attachment.bin>
More information about the cfe-commits
mailing list