This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix ClassifyImplicitMemberAccess to handle cases where the access in an unevaluated context is not within a CXXRecordDecl or CXXMethodDecl
ClosedPublic

Authored by shafik on Jan 24 2023, 9:39 AM.

Details

Summary

ClassifyImplicitMemberAccess assumes that if we are not in a static context then the DeclContext must be a CXXRecordDecl or a CXXMethodDecl. In the case of the unevaluated context this may not be true.

This will lead to a crash because contextClass will remain a nullptr.

Fixes: https://github.com/llvm/llvm-project/issues/37792 and https://github.com/llvm/llvm-project/issues/48405

Diff Detail

Event Timeline

shafik created this revision.Jan 24 2023, 9:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 24 2023, 9:39 AM
shafik requested review of this revision.Jan 24 2023, 9:39 AM
shafik edited the summary of this revision. (Show Details)
aaron.ballman accepted this revision.Feb 24 2023, 9:17 AM

LGTM, though you should add a release note as well.

clang/lib/Sema/SemaExprMember.cpp
164–170
clang/test/SemaCXX/statements.cpp
60–61

This diagnostic isn't entirely unreasonable, but I think GCC gives a better diagnostic: https://godbolt.org/z/T4dbhnoo7

This revision is now accepted and ready to land.Feb 24 2023, 9:17 AM
shafik updated this revision to Diff 505252.Mar 14 2023, 2:02 PM
shafik marked 2 inline comments as done.
  • Switched to using auto in two if statements
  • Added Release notes
clang/test/SemaCXX/statements.cpp
60–61

Yeah, probably worth filing a bug for this after I land this.

Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 4:38 PM