Skip to content

Commit

Permalink
devel/clazy: unbreak with LLVM >= 17
Browse files Browse the repository at this point in the history
Reported by:	poudriere failure
  • Loading branch information
fluffykhv committed Dec 29, 2023
1 parent cbe669b commit 44e78a2
Showing 1 changed file with 28 additions and 0 deletions.
@@ -0,0 +1,28 @@
--- src/checks/manuallevel/unexpected-flag-enumerator-value.cpp.orig 2022-01-20 23:18:47 UTC
+++ src/checks/manuallevel/unexpected-flag-enumerator-value.cpp
@@ -61,8 +61,13 @@ static bool isIntentionallyNotPowerOf2(EnumConstantDec
if (val.isMask() && val.countTrailingOnes() >= MinOnesToQualifyAsMask)
return true;

+#if LLVM_VERSION_MAJOR >= 17
+ if (val.isMask() && val.popcount() >= MinOnesToQualifyAsMask)
+ return true;
+#else
if (val.isShiftedMask() && val.countPopulation() >= MinOnesToQualifyAsMask)
return true;
+#endif

if (clazy::contains_lower(en->getName(), "mask"))
return true;
@@ -158,7 +163,11 @@ void UnexpectedFlagEnumeratorValue::VisitDecl(clang::D

for (EnumConstantDecl* enumerator : enumerators) {
const auto &initVal = enumerator->getInitVal();
+#if LLVM_VERSION_MAJOR >= 17
+ if (!initVal.isPowerOf2() && !initVal.isZero() && !initVal.isNegative()) {
+#else
if (!initVal.isPowerOf2() && !initVal.isNullValue() && !initVal.isNegative()) {
+#endif
if (isIntentionallyNotPowerOf2(enumerator))
continue;
const auto value = enumerator->getInitVal().getLimitedValue();

0 comments on commit 44e78a2

Please sign in to comment.