Skip to content

[🍒20240723] [clang][ExtractAPI] fix a couple crashes when used via libclang #10362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

QuietMisdreavus
Copy link

Cherry-pick of llvm#132297

This PR fixes two crashes in ExtractAPI that occur when decls are requested via libclang:

  • A null-dereference would sometimes happen in DeclarationFragmentsBuilder::getFragmentsForClassTemplateSpecialization when the template being processed was loaded indirectly via a typedef, with parameters filled in. The first commit loads the template parameter locations ahead of time to perform a null check before dereferencing.
  • An assertion (or another null-dereference) was happening in CXXRecordDecl::bases when processing a forward-declaration (i.e. a record without a definition). The second commit guards the use of bases in ExtractAPIVisitorBase::getBases by first checking that the decl in question has a complete definition.

The added test extract-api-cursor-cpp adds tests for these two scenarios to protect against the crash in the future.

Fixes rdar://140592475, fixes rdar://123430367

…#132297)

This PR fixes two crashes in ExtractAPI that occur when decls are
requested via libclang:

- A null-dereference would sometimes happen in
`DeclarationFragmentsBuilder::getFragmentsForClassTemplateSpecialization`
when the template being processed was loaded indirectly via a typedef,
with parameters filled in. The first commit loads the template parameter
locations ahead of time to perform a null check before dereferencing.
- An assertion (or another null-dereference) was happening in
`CXXRecordDecl::bases` when processing a forward-declaration (i.e. a
record without a definition). The second commit guards the use of
`bases` in `ExtractAPIVisitorBase::getBases` by first checking that the
decl in question has a complete definition.

The added test `extract-api-cursor-cpp` adds tests for these two
scenarios to protect against the crash in the future.

Fixes rdar://140592475, fixes rdar://123430367
@QuietMisdreavus QuietMisdreavus requested a review from a team as a code owner March 26, 2025 23:54
@QuietMisdreavus
Copy link
Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Author

@swift-ci Please test Windows

@QuietMisdreavus QuietMisdreavus merged commit 630285e into stable/20240723 Mar 27, 2025
3 checks passed
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/libclang-sgf-crashes branch March 27, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant