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

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 24 02:41:43 PST 2019


Author: ibiryukov
Date: Thu Jan 24 02:41:43 2019
New Revision: 352040

URL: http://llvm.org/viewvc/llvm-project?rev=352040&view=rev
Log:
[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

Added:
    cfe/trunk/test/CodeCompletion/crash-null-type.cpp
Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=352040&r1=352039&r2=352040&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Jan 24 02:41:43 2019
@@ -680,7 +680,8 @@ QualType clang::getDeclUsageType(ASTCont
     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

Added: cfe/trunk/test/CodeCompletion/crash-null-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/crash-null-type.cpp?rev=352040&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/crash-null-type.cpp (added)
+++ cfe/trunk/test/CodeCompletion/crash-null-type.cpp Thu Jan 24 02:41:43 2019
@@ -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




More information about the cfe-commits mailing list