]> granicus.if.org Git - clang/commitdiff
[CodeComplete] [clangd] Fix crash on ValueDecl with a null type
authorIlya Biryukov <ibiryukov@google.com>
Thu, 24 Jan 2019 10:41:43 +0000 (10:41 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Thu, 24 Jan 2019 10:41:43 +0000 (10:41 +0000)
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

lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/crash-null-type.cpp [new file with mode: 0644]

index ab18d7fb5e0257b9ebc126f4fe5a5a5bec232238..9bed545a528a3e848d10160be021c2b2cb1abf9f 100644 (file)
@@ -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
diff --git a/test/CodeCompletion/crash-null-type.cpp b/test/CodeCompletion/crash-null-type.cpp
new file mode 100644 (file)
index 0000000..c5b3d1e
--- /dev/null
@@ -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