Skip to content

Commit

Permalink
[clang-tidy] Avoid checking magic numbers if _BitInt (llvm#65888)
Browse files Browse the repository at this point in the history
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.

...
 rust-lang#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
  • Loading branch information
vabridgers committed Sep 17, 2023
1 parent e6a007f commit 4b5366c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ bool MagicNumbersCheck::isConstant(const MatchFinder::MatchResult &Result,
}

bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
if (Literal->getType()->isBitIntType()) {
return true;
}
const llvm::APInt IntValue = Literal->getValue();
const int64_t Value = IntValue.getZExtValue();
if (Value == 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %check_clang_tidy %s readability-magic-numbers %t --

// Don't crash

_BitInt(128) A = 4533629751480627964421wb;
// CHECK-MESSAGES: warning

0 comments on commit 4b5366c

Please sign in to comment.