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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-analysis

Author: Congcong Cai (HerrCai0907)

<details>
<summary>Changes</summary>

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`


---
Full diff: https://github.com/llvm/llvm-project/pull/122915.diff


1 Files Affected:

- (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+2) 


``````````diff
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);

``````````

</details>


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


More information about the cfe-commits mailing list