This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Make MatchesAnyListedNameMatcher cope with unnamed Decl
ClosedPublic

Authored by mikecrowe on Jul 10 2023, 1:27 PM.

Details

Summary

If MatchesAnyListedNameMatcher::NameMatcher::match() is called in
MatchMode::MatchUnqualified mode with a NamedDecl that has no name then
calling NamedDecl::getName() will assert with:
`Name.isIdentifier() && "Name is not a simple identifier"'

It seems unfair to force all matchers using
matchers::matchesAnyListedName to defend against this, particularly
since test cases are unlikely to provoke the problem. Let's just check
whether the identifier has a name before attempting to use it instead.

Add test case that reproduces the problem to the
use-std-print-custom.cpp lit check.

Diff Detail

Event Timeline

mikecrowe created this revision.Jul 10 2023, 1:27 PM
Herald added a project: Restricted Project. · View Herald Transcript
mikecrowe requested review of this revision.Jul 10 2023, 1:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2023, 1:27 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Remove example from commit message, it's already included in patch.
Simply commit message should be properly formatted without unnecessary information.

clang-tools-extra/clang-tidy/utils/Matchers.h
115–117

Not needed.

mikecrowe marked an inline comment as done.

Remove unnecessary init-statement and test case in commit message

mikecrowe edited the summary of this revision. (Show Details)Jul 11 2023, 12:54 AM

Thanks for the review.

This revision is now accepted and ready to land.Jul 11 2023, 10:00 AM