浏览代码

[CodeComplete] [clangd] Fix crash on ValueDecl with a null type

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D57093

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352040 91177308-0d34-0410-b5e6-96231b3b80d8
Ilya Biryukov 6 年之前
父节点
当前提交
2975e47340
共有 2 个文件被更改,包括 10 次插入1 次删除
  1. 2 1
      lib/Sema/SemaCodeComplete.cpp
  2. 8 0
      test/CodeCompletion/crash-null-type.cpp

+ 2 - 1
lib/Sema/SemaCodeComplete.cpp

@@ -680,7 +680,8 @@ QualType clang::getDeclUsageType(ASTContext &C, const NamedDecl *ND) {
     T = Property->getType();
   else if (const auto *Value = dyn_cast<ValueDecl>(ND))
     T = Value->getType();
-  else
+
+  if (T.isNull())
     return QualType();
 
   // Dig through references, function pointers, and block pointers to

+ 8 - 0
test/CodeCompletion/crash-null-type.cpp

@@ -0,0 +1,8 @@
+void test() {
+  for (auto [loopVar] : y) { // y has to be unresolved
+    loopVa
+  }
+}
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:3:11 %s -o - \
+// RUN:            | FileCheck %s
+// CHECK: COMPLETION: loopVar