[clang] [clang][CodeComplete] Avoid null QualType crash on member access after dependent auto paren-init (PR #249317)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 5 19:44:15 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Shengxin Pei (TPPPP72)
<details>
<summary>Changes</summary>
In uninstantiated templates, direct-initializing an `auto` variable with a dependent expression (`auto x(r[0]);`) can produce a `ParenListExpr` whose approximate type resolves to a null `QualType` via `HeuristicResolver`.
Dereferencing it in `CodeCompleteMemberReferenceExpr` causes an assertion failure in assertion builds and a segfault in release builds.
Skip `ParenListExpr` in `HeuristicResolverImpl::simplifyType`, and add a regression test in `member-access.cpp`.
https://github.com/clice-io/clice/issues/1057#issuecomment-6723994036
---
Full diff: https://github.com/llvm/llvm-project/pull/249317.diff
2 Files Affected:
- (modified) clang/lib/Sema/HeuristicResolver.cpp (+8-2)
- (modified) clang/test/CodeCompletion/member-access.cpp (+10)
``````````diff
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index 16a6c8a04d8eb7..4d1b55d33dd48d 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -272,8 +272,14 @@ QualType HeuristicResolverImpl::simplifyType(QualType Type, const Expr *E,
if (T.E && AT->isUndeducedAutoType()) {
if (const auto *DRE = dyn_cast<DeclRefExpr>(T.E)) {
if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
- if (auto *Init = VD->getInit())
- return {resolveExprToType(Init), Init};
+ if (auto *Init = VD->getInit()) {
+ Init = Init->IgnoreImplicit();
+ if (!isa<ParenListExpr>(Init)) {
+ if (QualType InitType = resolveExprToType(Init);
+ !InitType.isNull())
+ return {InitType, Init};
+ }
+ }
}
}
}
diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp
index 2de96b43ff2ba7..dfb436c8fd85f1 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -437,3 +437,13 @@ void f(Alias<T> s) {
// CHECK-TEMPLATE-ALIAS-NESTED: [#int#]b
}
}
+
+namespace dependent_auto_paren_init{
+ template <class T> struct V { T& operator[](int); };
+ template <class T> void f(V<V<T>> r) {
+ auto x(r[0]);
+ x.
+ // RUN: %clang_cc1 -x c++ -fsyntax-only -code-completion-at=%s:445:7 %s -o - | FileCheck -check-prefix=CHECK-AUTO-PAREN-INIT --allow-empty %s
+ // CHECK-AUTO-PAREN-INIT-NOT: COMPLETION:
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/249317
More information about the cfe-commits
mailing list