Skip to content

Commit 4b5366c

Browse files
authored
[clang-tidy] Avoid checking magic numbers if _BitInt (#65888)
Recent changes to add _BitInt support have caused our internal random testing to fail. This change just avoids a readability magic numbers check for now if a _BitInt. The crash seen (edited for clarity) is shown below. <src-root>/llvm/include/llvm/ADT/APInt.h:1488: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"' failed. ... #9 <address> llvm::APInt::getZExtValue() const <src-root>/llvm/include/llvm/ADT/APInt.h:1488:5 clang::IntegerLiteral const*) const <src-root>/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:198:47 <clang::IntegerLiteral>(clang::ast_matchers::MatchFinder::MatchResult const&, char const*) <src-root>/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h:67:5 clang::ast_matchers::MatchFinder::MatchResult const&) <src-root>/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:152:35 ... Reviewed By: donat.nagy
1 parent e6a007f commit 4b5366c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ bool MagicNumbersCheck::isConstant(const MatchFinder::MatchResult &Result,
191191
}
192192

193193
bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
194+
if (Literal->getType()->isBitIntType()) {
195+
return true;
196+
}
194197
const llvm::APInt IntValue = Literal->getValue();
195198
const int64_t Value = IntValue.getZExtValue();
196199
if (Value == 0)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %check_clang_tidy %s readability-magic-numbers %t --
2+
3+
// Don't crash
4+
5+
_BitInt(128) A = 4533629751480627964421wb;
6+
// CHECK-MESSAGES: warning

0 commit comments

Comments
 (0)