Skip to content

Conversation

@HerrCai0907
Copy link
Contributor

@HerrCai0907 HerrCai0907 commented Jan 14, 2025

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.

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`
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:analysis labels Jan 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-clang-analysis

Author: Congcong Cai (HerrCai0907)

Changes

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

@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)

Changes

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

Copy link
Contributor Author

HerrCai0907 commented Jan 17, 2025

Merge activity

  • Jan 17, 8:44 AM EST: A user started a stack merge that includes this pull request via Graphite.
  • Jan 17, 8:46 AM EST: Graphite couldn't merge this PR because it failed for an unknown reason (Stack merges are not currently supported for forked repositories. Please create a branch in the target repository in order to merge).

@HerrCai0907 HerrCai0907 merged commit eb7dea8 into llvm:main Jan 17, 2025
11 checks passed
@HerrCai0907 HerrCai0907 deleted the expr-mutation branch January 17, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:analysis clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants