[clang-tools-extra] 54435b5 - [clang-tidy] Ignore implicit casts with errors in bugprone-implicit-widening-of-multiplication-result (#92025)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 10:17:51 PDT 2024
Author: Piotr Zegar
Date: 2024-05-14T19:17:47+02:00
New Revision: 54435b5df32d80c68c94acf96a7565ffd3d86542
URL: https://github.com/llvm/llvm-project/commit/54435b5df32d80c68c94acf96a7565ffd3d86542
DIFF: https://github.com/llvm/llvm-project/commit/54435b5df32d80c68c94acf96a7565ffd3d86542.diff
LOG: [clang-tidy] Ignore implicit casts with errors in bugprone-implicit-widening-of-multiplication-result (#92025)
When expression got errors (missing typedef) and clang-tidy is compiled
with asserts enabled, then we crash in this check on assert because type
with errors is visible as an dependent one. This is issue caused by
invalid input.
But as there is not point to crash in such case and generate additional
confusion, such expressions with errors will be now ignored.
Fixes #89515, #55293
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
index 6f22f02f30183..f99beac668ce7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
@@ -9,20 +9,20 @@
#include "ImplicitWideningOfMultiplicationResultCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
#include "clang/Lex/Lexer.h"
#include <optional>
using namespace clang::ast_matchers;
-namespace clang {
+namespace clang::tidy::bugprone {
+
namespace {
AST_MATCHER(ImplicitCastExpr, isPartOfExplicitCast) {
return Node.isPartOfExplicitCast();
}
+AST_MATCHER(Expr, containsErrors) { return Node.containsErrors(); }
} // namespace
-} // namespace clang
-
-namespace clang::tidy::bugprone {
static const Expr *getLHSOfMulBinOp(const Expr *E) {
assert(E == E->IgnoreParens() && "Already skipped all parens!");
@@ -250,7 +250,8 @@ void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
void ImplicitWideningOfMultiplicationResultCheck::registerMatchers(
MatchFinder *Finder) {
- Finder->addMatcher(implicitCastExpr(unless(anyOf(isInTemplateInstantiation(),
+ Finder->addMatcher(implicitCastExpr(unless(anyOf(containsErrors(),
+ isInTemplateInstantiation(),
isPartOfExplicitCast())),
hasCastKind(CK_IntegralCast))
.bind("x"),
More information about the cfe-commits
mailing list