diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c new file mode 100644 index 00000000000000..cfb64c10fe46ce --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c @@ -0,0 +1,9 @@ +// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t + +_BitInt(8) v_401_0() { + 0 && ({ + _BitInt(5) y = 0; + 16777215wb ?: ++y; + }); +} +// CHECK-MESSAGES: warning diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 46dbadd8b878bf..4799f89db82fa7 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -6642,7 +6642,7 @@ class BitIntType final : public Type, public llvm::FoldingSetNode { bool isSugared() const { return false; } QualType desugar() const { return QualType(this, 0); } - void Profile(llvm::FoldingSetNodeID &ID) { + void Profile(llvm::FoldingSetNodeID &ID) const { Profile(ID, isUnsigned(), getNumBits()); } diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 27f71edd6f99b3..2e4f15f83ac26e 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -1333,7 +1333,13 @@ void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { VisitExpr(S); S->getValue().Profile(ID); - ID.AddInteger(S->getType()->castAs()->getKind()); + + QualType T = S->getType(); + ID.AddInteger(T->getTypeClass()); + if (auto BitIntT = T->getAs()) + BitIntT->Profile(ID); + else + ID.AddInteger(T->castAs()->getKind()); } void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {