[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 10 04:09:49 PDT 2023
https://github.com/vabridgers created https://github.com/llvm/llvm-project/pull/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
>From 9ecb065a60a67cef568b0c5d60c760a72e9bac93 Mon Sep 17 00:00:00 2001
From: Vince Bridgers <vince.a.bridgers at gmail.com>
Date: Sat, 9 Sep 2023 17:01:56 +0200
Subject: [PATCH] [clang-tidy] Avoid checking magic numbers if _BitInt
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
---
.../clang-tidy/readability/MagicNumbersCheck.cpp | 3 +++
.../test/clang-tidy/checkers/readability/bitint-no-crash.c | 6 ++++++
2 files changed, 9 insertions(+)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index 7f3c2cb9a0434cc..97c20cf200fa21c 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -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)
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
new file mode 100644
index 000000000000000..f8660924cbef5a0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t --
+
+// Don't crash
+
+_BitInt(128) A = 4533629751480627964421wb;
+// CHECK-MESSAGES: warning
More information about the cfe-commits
mailing list