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

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 17 06:14:27 PST 2025


Author: Congcong Cai
Date: 2025-01-17T22:14:23+08:00
New Revision: eb7dea8bb15a00930b676f78f3b850079e2b964c

URL: https://github.com/llvm/llvm-project/commit/eb7dea8bb15a00930b676f78f3b850079e2b964c
DIFF: https://github.com/llvm/llvm-project/commit/eb7dea8bb15a00930b676f78f3b850079e2b964c.diff

LOG: [mutation analyzer] enhance stability for `hasAnyInit` matcher (#122915)

I cannot minimal produce it, but when I run clangd with
`misc-const-correctness` check in a big project
clangd crashed due to deref nullptr here.
clang may pass a nullptr to `InitExprs` when meets some error cases.

Added: 
    

Modified: 
    clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 
    


################################################################################
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