forked from OSchip/llvm-project
[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 llvm-svn: 313016
This commit is contained in:
parent
38029d3c89
commit
2087113f6c
|
@ -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 *EnumDec) {
|
|||
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) {
|
||||
|
|
|
@ -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 };
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue