This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST] Fix crash getting name of a template decl
ClosedPublic

Authored by tblah on Apr 13 2022, 3:03 AM.

Details

Summary

NamedDecl::getIdentifier can return a nullptr when DeclarationName::isIdentifier is false, which leads to a null pointer dereference when TypePrinter::printTemplateId calls ->getName().

NamedDecl::getName does the same thing in the successful case and returns an empty string in the failure case.

This crash affects the llvm 14 packages on llvm.org.

Diff Detail

Event Timeline

tblah created this revision.Apr 13 2022, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2022, 3:03 AM
tblah requested review of this revision.Apr 13 2022, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2022, 3:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tblah edited the summary of this revision. (Show Details)Apr 13 2022, 3:07 AM
tblah added a reviewer: lattner.
aaron.ballman edited reviewers, added: aaron.ballman; removed: lattner.Apr 13 2022, 4:08 AM
aaron.ballman added a subscriber: aaron.ballman.

This looks good in general, but can you add a test case for the scenario which previously crashed and a release note for the fix?

tblah updated this revision to Diff 422906.Apr 14 2022, 10:25 AM

Added a unit test

tblah added a comment.EditedApr 21 2022, 4:15 AM

I'm not able to reproduce the test failure in CI. It looks spurious to me because I have not changed anything related to openmp. The only change in behaviour after my patch should be to avoid a null pointer dereference. In tests which did not hit that null pointer dereference before there should not be any change in behaviour.

What I tried:

  • Use a debian 11 x64 base image
  • Install a minimum set of required packages from debian repos (including clang and lld from debian)
  • Run the commands listed under "Reproduce build locally" on the CI failure report
aaron.ballman accepted this revision.Apr 22 2022, 9:45 AM

LGTM, with a commenting nit. The Precommit CI test failures look unrelated to me as well.

Do you need me to commit on your behalf? If so, what name and email address would you like me to use for patch attribution? (I can fix the commenting issue when I land, so don't worry about pushing up a new patch.)

clang/unittests/AST/TypePrinterTest.cpp
74–75
This revision is now accepted and ready to land.Apr 22 2022, 9:45 AM
tblah added a comment.Apr 22 2022, 9:47 AM

Yes please commit on my behalf. My details are

Tom Eccles

tom.eccles@codethink.co.uk

Thanks

Thank you for the fix! I've commit on your behalf in 225b91e6cbba31ff1ce787a152a67977d08fdcab.

This affects all released versions of llvm14, and potentially llvm13 too (I got a crash today on llvm13 hitting this exact code).
yet, this is not backported to llvm14 on the current 14.x github branch. Please backport so this is released on the next tarball.

This affects all released versions of llvm14, and potentially llvm13 too (I got a crash today on llvm13 hitting this exact code).
yet, this is not backported to llvm14 on the current 14.x github branch. Please backport so this is released on the next tarball.

I filed https://github.com/llvm/llvm-project/issues/55585 to see if we can get this into the 14.x branch, thanks for the request!

This affects all released versions of llvm14, and potentially llvm13 too (I got a crash today on llvm13 hitting this exact code).
yet, this is not backported to llvm14 on the current 14.x github branch. Please backport so this is released on the next tarball.

I filed https://github.com/llvm/llvm-project/issues/55585 to see if we can get this into the 14.x branch, thanks for the request!

And it looks like it was backported today.

thank you, this is really appreciated.