[clang] [mutation analyzer] enhance stability for `hasAnyInit` matcher (PR #122915)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 14 07:17:17 PST 2025


https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/122915

I cannot minial produce it, but when I run clangd with `misc-const-correctness` check in a big project
clangd crashed due to deref nullptr here.
There are suspicious code in clang which may pass a nullptr to `InitExprs`


>From d0a1dd69e4681b30c8080c09d49e519aa178c989 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Tue, 14 Jan 2025 23:16:23 +0800
Subject: [PATCH] [mutation analyzer] enhance stability for `hasAnyInit`
 matcher

I cannot minial produce it, but when I run clangd with `misc-const-correctness` check in a big project
clangd crashed due to deref nullptr here.
There are suspicious code in clang which may pass a nullptr to `InitExprs`
---
 clang/lib/Analysis/ExprMutationAnalyzer.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 53b838e9ede4d7..cefe64409c9776 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -104,6 +104,8 @@ AST_MATCHER_P(Stmt, canResolveToExpr, const Stmt *, Inner) {
 AST_MATCHER_P(InitListExpr, hasAnyInit, ast_matchers::internal::Matcher<Expr>,
               InnerMatcher) {
   for (const Expr *Arg : Node.inits()) {
+    if (Arg == nullptr)
+      continue;
     ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
     if (InnerMatcher.matches(*Arg, Finder, &Result)) {
       *Builder = std::move(Result);



More information about the cfe-commits mailing list