This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix crash in CIndex, when visiting a static_assert without message
ClosedPublic

Authored by kiloalphaindia on Jul 23 2023, 6:58 AM.

Details

Summary

After implementation of "[Clang] Implement P2741R3 - user-generated static_assert messages" (47ccfd7a89e2a9a747a7114db18db1376324799c) the c indexer crashes when handling a static_assert w/o any message.
This is caused by using dyn_cast to get the literal string, which isn't working on nullptr.

Diff Detail

Event Timeline

kiloalphaindia created this revision.Jul 23 2023, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 6:58 AM
Herald added a subscriber: arphaman. · View Herald Transcript
kiloalphaindia requested review of this revision.Jul 23 2023, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2023, 6:58 AM
kiloalphaindia edited the summary of this revision. (Show Details)Jul 23 2023, 7:00 AM
cor3ntin added inline comments.Jul 23 2023, 7:22 AM
clang/tools/libclang/CIndex.cpp
1297

It's probably better to cast to Expr and visit it unconditionally. But it could always be null, so dyn_cast_if_present is probably correct.
dyn_cast_if_present<Expr> should be what we want then

Yes, that's a good idea. Now kdevelop also highlights the message-expression properly.

Sorry... forgot formatting... removed commented code... changed "Hallo Welt!" to english

There is a failed unit test, can you look into it?

aaron.ballman added inline comments.
clang/unittests/libclang/LibclangTest.cpp
1201

This is going to be testing whatever STL headers are installed on the developer's machine; instead of including the STL header, you should mock up the std::string_view class so we're always testing something consistently.

Yes, I think so, too. Will have a look this evening.

The test is no more using any includes now. Hopefully this fixes it, otherwise I will have to add something that prints the diagnostic.

I don't have write permissions on the repository. Please commit it when OK.

The test is no more using any includes now. Hopefully this fixes it, otherwise I will have to add something that prints the diagnostic.

I don't have write permissions on the repository. Please commit it when OK.

Will do! (once the test pass) What name / email address should we use for commiting?

Please use Kai Stierand <kai.stierand@swplusplus.de> as in 5d859a1cdee3c15dce692767ee3e9ad03a8c4c1b

cor3ntin accepted this revision.Jul 25 2023, 1:38 AM
This revision is now accepted and ready to land.Jul 25 2023, 1:38 AM
This revision was landed with ongoing or failed builds.Jul 25 2023, 1:53 AM
This revision was automatically updated to reflect the committed changes.