This is an archive of the discontinued LLVM Phabricator instance.

[clang] SIGSEGV fix at clang::ASTContext::getRawCommentForDeclNoCacheImpl
ClosedPublic

Authored by ivanmurashko on Aug 11 2022, 5:56 AM.

Details

Summary

The File might point to an invalid FileID when the AST is broken. That leads to clang/clangd crashes while processing comments. The relevant part of the crash is below

 #4 0x00007f1d7fbf95bc std::_Rb_tree<unsigned int, std::pair<unsigned int const, clang::RawComment*>, std::_Select1st<std::pair<unsigned int const, clang::RawComment*>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const
, clang::RawComment*>>>::_M_lower_bound(std::_Rb_tree_node<std::pair<unsigned int const, clang::RawComment*>> const*, std::_Rb_tree_node_base const*, unsigned int const&) const /usr/include/c++/8/bits/stl_tree.h:1911:2
 #5 0x00007f1d7fbf95bc std::_Rb_tree<unsigned int, std::pair<unsigned int const, clang::RawComment*>, std::_Select1st<std::pair<unsigned int const, clang::RawComment*>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>>::lower_bound(unsigned int const&) const /usr/include/c++/8/bits/stl_tree.h:1214:56
 #6 0x00007f1d7fbf95bc std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>>::lower_bound(unsigned int const&) const /usr/include/c++/8/bits/stl_map.h:1264:36
 #7 0x00007f1d7fbf95bc clang::ASTContext::getRawCommentForDeclNoCacheImpl(clang::Decl const*, clang::SourceLocation, std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>> const&) const /home/ivanmurashko/local/llvm-project/clang/lib/AST/ASTContext.cpp:226:57

The corresponding LIT test that reproduces the crash was also added

Same issue is described at https://bugs.llvm.org/show_bug.cgi?id=49707

Diff Detail

Event Timeline

ivanmurashko created this revision.Aug 11 2022, 5:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2022, 5:56 AM
ivanmurashko requested review of this revision.Aug 11 2022, 5:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2022, 5:56 AM
ivanmurashko edited the summary of this revision. (Show Details)Aug 11 2022, 6:03 AM
ivanmurashko edited the summary of this revision. (Show Details)
ivanmurashko edited the summary of this revision. (Show Details)
ivanmurashko edited the summary of this revision. (Show Details)
ivanmurashko edited the summary of this revision. (Show Details)Aug 11 2022, 3:53 PM
gribozavr2 accepted this revision.Aug 11 2022, 4:00 PM
This revision is now accepted and ready to land.Aug 11 2022, 4:00 PM
ivanmurashko edited the summary of this revision. (Show Details)Aug 11 2022, 4:01 PM
ivanmurashko edited the summary of this revision. (Show Details)