<div dir="ltr"><a class="gmail_plusreply" id="plusReplyChip-7" href="mailto:hwennborg@google.com" tabindex="-1">+Hans Wennborg</a>, could you please merge this fix into the release branch?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 24, 2019 at 1:41 PM Ilya Biryukov via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: ibiryukov<br>
Date: Thu Jan 24 02:41:43 2019<br>
New Revision: 352040<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=352040&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=352040&view=rev</a><br>
Log:<br>
[CodeComplete] [clangd] Fix crash on ValueDecl with a null type<br>
<br>
Reviewers: kadircet<br>
<br>
Reviewed By: kadircet<br>
<br>
Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D57093" rel="noreferrer" target="_blank">https://reviews.llvm.org/D57093</a><br>
<br>
Modified:<br>
clang-tools-extra/trunk/clangd/ExpectedTypes.cpp<br>
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clangd/ExpectedTypes.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ExpectedTypes.cpp?rev=352040&r1=352039&r2=352040&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ExpectedTypes.cpp?rev=352040&r1=352039&r2=352040&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clangd/ExpectedTypes.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd/ExpectedTypes.cpp Thu Jan 24 02:41:43 2019<br>
@@ -35,8 +35,10 @@ static llvm::Optional<QualType><br>
typeOfCompletion(const CodeCompletionResult &R) {<br>
auto *VD = dyn_cast_or_null<ValueDecl>(R.Declaration);<br>
if (!VD)<br>
- return None; // We handle only variables and functions below.<br>
+ return llvm::None; // We handle only variables and functions below.<br>
auto T = VD->getType();<br>
+ if (T.isNull())<br>
+ return llvm::None;<br>
if (auto FuncT = T->getAs<FunctionType>()) {<br>
// Functions are a special case. They are completed as 'foo()' and we want<br>
// to match their return type rather than the function type itself.<br>
<br>
Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=352040&r1=352039&r2=352040&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=352040&r1=352039&r2=352040&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)<br>
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Jan 24 02:41:43 2019<br>
@@ -2319,6 +2319,17 @@ TEST(CompletionTest, ObjectiveCMethodTwo<br>
EXPECT_THAT(C, ElementsAre(SnippetSuffix("${1:(unsigned int)}")));<br>
}<br>
<br>
+TEST(CompletionTest, WorksWithNullType) {<br>
+ auto R = completions(R"cpp(<br>
+ int main() {<br>
+ for (auto [loopVar] : y ) { // y has to be unresolved.<br>
+ int z = loopV^;<br>
+ }<br>
+ }<br>
+ )cpp");<br>
+ EXPECT_THAT(R.Completions, ElementsAre(Named("loopVar")));<br>
+}<br>
+<br>
} // namespace<br>
} // namespace clangd<br>
} // namespace clang<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>