This is an archive of the discontinued LLVM Phabricator instance.

[clang][NFC] Standard substitution checking cleanup
ClosedPublic

Authored by urnathan on Feb 9 2022, 6:34 AM.

Details

Summary

In preparing for module mangling changes I noticed some issues with the way we check for std::basic_string instantiations and friends.

*) there's a single routine for std::basic_{i,o,io}stream but it is templatized on the length of the name. Really? just use a StringRef, rather than clone the entire routine just for 'basic_iostream'.

*) We have a helper routine to check for char type, and call it from several places. But given all the instantiations are of the form TPL<char, Other<char> ...> we could just check the first arg is char and the later templated args are instantiating that same type. A simpler type comparison.

*) Because basic_string has a third allocator parameter, it is open coded, which I found a little confusing. But otherwise it's exactly the same pattern as the iostream ones. Just tell that checker about whether there's an expected allocator argument.[*]

*) We may as well return in each block of mangleStandardSubstitution once we determine it is not one of the entities of interest -- it certainly cannot be one of the other kinds of entities.

FWIW this shaves about 500 bytes off the compiler executable.

  • I suppose we could also have this routine a tri-value, with one to indicat 'it is this name, but it's not the one you're looking for', to avoid later calls trying different names?

Diff Detail

Event Timeline

urnathan requested review of this revision.Feb 9 2022, 6:34 AM
urnathan created this revision.
ChuanqiXu accepted this revision.Feb 9 2022, 6:27 PM

LGTM with nit suggestions.

clang/lib/AST/ItaniumMangle.cpp
5972–5975

Returns whether S is a template specialization of std::Name with a single

6016–6017

This would be simpler: if (!A && !B)

6066

The code style of clang would require to add param name for boolean value:

isStdCharSpecialization(SD, "basic_string", /*HasAllocator=*/true)

Same for following.

This revision is now accepted and ready to land.Feb 9 2022, 6:27 PM
urnathan marked 3 inline comments as done.Feb 10 2022, 4:36 AM
urnathan added inline comments.
clang/lib/AST/ItaniumMangle.cpp
6016–6017

Yeah, I um'ed an ah'd over that too :)

This revision was automatically updated to reflect the committed changes.
urnathan marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2022, 4:45 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript