[clang-tools-extra] [clang-tidy] Ignore implicit casts with errors in bugprone-implicit-widening-of-multiplication-result (PR #92025)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 13:29:51 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
Author: Piotr Zegar (PiotrZSL)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/92025.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp (+6-5)
``````````diff
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"),
``````````
</details>
https://github.com/llvm/llvm-project/pull/92025
More information about the cfe-commits
mailing list