This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix assert in Sema::LookupTemplateName so that it does not attempt an unconditional cast to TagType
ClosedPublic

Authored by shafik on Aug 25 2022, 5:35 PM.

Details

Summary

In Sema::LookupTemplateName(...) seeks to assert that the ObjectType is complete or being defined. If the type is incomplete it will attempt to unconditionally cast it to a TagType and not all incomplete types are a TagType. For example the type could be void or it could be an IncompleteArray.

This change adds an additional check to confirm it is a TagType before attempting to check if it is incomplete or being defined.

Diff Detail

Event Timeline

shafik created this revision.Aug 25 2022, 5:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 5:35 PM
shafik requested review of this revision.Aug 25 2022, 5:35 PM
shafik updated this revision to Diff 455784.Aug 25 2022, 8:38 PM

Apply clang-format

aaron.ballman accepted this revision.Aug 26 2022, 4:10 AM

Good catch! LGTM, but please add a release note for the fix.

This revision is now accepted and ready to land.Aug 26 2022, 4:10 AM
erichkeane accepted this revision.Aug 26 2022, 5:59 AM

Looking through isCompleteType I note that arrays of an elements of incomplete types would have also hit this crash, as would member-pointers in MicrosoftABI (in some weird cases?), and some ObjC types.

Anyway, other than the nit above, LGTM.

clang/lib/Sema/SemaTemplate.cpp
401–402

Slight preference for making the getAs happen after the completeness check, since that is in the 'order of costliness'.

Also, not sure the assert message here makes any sense, but I don't know of anything better here.

shafik updated this revision to Diff 455935.Aug 26 2022, 9:00 AM
shafik marked an inline comment as done.
  • Change to order of operations in assert to put off more costly check
  • Add release note
This revision was landed with ongoing or failed builds.Aug 26 2022, 9:43 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 9:43 AM