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

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 24 14:27:42 PST 2019


Merged in r352118 (cfe) and r352120 (clang-tools-extra). Please let me
know if there are any follow-ups.

Thanks,
Hans

On Thu, Jan 24, 2019 at 5:11 AM Ilya Biryukov <ibiryukov at google.com> wrote:
>
> +Hans Wennborg, could you please merge this fix into the release branch?
>
> On Thu, Jan 24, 2019 at 1:41 PM Ilya Biryukov via cfe-commits <cfe-commits at lists.llvm.org> wrote:
>>
>> 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
>>
>> Modified:
>>     clang-tools-extra/trunk/clangd/ExpectedTypes.cpp
>>     clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
>>
>> Modified: clang-tools-extra/trunk/clangd/ExpectedTypes.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ExpectedTypes.cpp?rev=352040&r1=352039&r2=352040&view=diff
>> ==============================================================================
>> --- clang-tools-extra/trunk/clangd/ExpectedTypes.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/ExpectedTypes.cpp Thu Jan 24 02:41:43 2019
>> @@ -35,8 +35,10 @@ static llvm::Optional<QualType>
>>  typeOfCompletion(const CodeCompletionResult &R) {
>>    auto *VD = dyn_cast_or_null<ValueDecl>(R.Declaration);
>>    if (!VD)
>> -    return None; // We handle only variables and functions below.
>> +    return llvm::None; // We handle only variables and functions below.
>>    auto T = VD->getType();
>> +  if (T.isNull())
>> +    return llvm::None;
>>    if (auto FuncT = T->getAs<FunctionType>()) {
>>      // Functions are a special case. They are completed as 'foo()' and we want
>>      // to match their return type rather than the function type itself.
>>
>> Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=352040&r1=352039&r2=352040&view=diff
>> ==============================================================================
>> --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
>> +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Jan 24 02:41:43 2019
>> @@ -2319,6 +2319,17 @@ TEST(CompletionTest, ObjectiveCMethodTwo
>>    EXPECT_THAT(C, ElementsAre(SnippetSuffix("${1:(unsigned int)}")));
>>  }
>>
>> +TEST(CompletionTest, WorksWithNullType) {
>> +  auto R = completions(R"cpp(
>> +    int main() {
>> +      for (auto [loopVar] : y ) { // y has to be unresolved.
>> +        int z = loopV^;
>> +      }
>> +    }
>> +  )cpp");
>> +  EXPECT_THAT(R.Completions, ElementsAre(Named("loopVar")));
>> +}
>> +
>>  } // namespace
>>  } // namespace clangd
>>  } // namespace clang
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
>
> --
> Regards,
> Ilya Biryukov


More information about the cfe-commits mailing list