This is an archive of the discontinued LLVM Phabricator instance.

[SEMA]Uniform printing of Attributes
AbandonedPublic

Authored by erichkeane on Aug 7 2018, 8:47 AM.

Details

Summary

The recent patch that reordered parsed attributes made it clear
that the diagnostics when printing attributes were incredibly
inconsistent. in the mutual-exclusion case, the order of the
attributes would change which was printed with leading/trailing
underscores.

This is because GNU attributes are permitted to be spelled with
leading/trailing underscores, but are quickly normalized after
parsing. Therefore, any attribute that had been converted to a
Attr type would only have the non-underscored type.

This patch adds a diagnostic category for a quoted-std-string,
as well as overloads for operator<< to permit ParsedAttr to be
sent to be emitted directly.

THEN, this patch changes everywhere that we were doing PA.getName()
in a diagnostic (which got the IdentifierInfo, which hadn't been
normalized) and replaces it with a call to the new operator<<.

The result is that ALL attributes are now uniformly printed with
the normalized name, rather than a mix of names.

Diff Detail

Event Timeline

erichkeane created this revision.Aug 7 2018, 8:47 AM
erichkeane added inline comments.Aug 7 2018, 8:51 AM
include/clang/Sema/ParsedAttr.h
956

Note that the pointer-overload is required since a couple of templates are used that switch between an Attr and a ParsedAttr, so we need to have the same form as the Attr.

Also note that we cannot do what Attr does (which is store an Attr Pointer in the diagnostic) without making Basic dependent on Sema, which seemed worse than the allocation in diagnostic situations.

lib/Sema/SemaDeclAttr.cpp
3941

It was tempting to template-these, but that would require moving them (or forcing instantiation) in the header file. Additionally, since there is a difference between the spelling of how to get a location between the two types, this would become awkward.

erichkeane abandoned this revision.Aug 9 2018, 5:55 AM

After talking to Aaron, we're going to try to use the lexical names for ALL cases. This requires a bunch of of accessory work (in order to get the Identifier from the SourceRange), so it'll be split up into a couple of commits and done separately. I'll likely do the part that gives Attr a diagnostic operator<< as an NFC change in the near future.