This is an archive of the discontinued LLVM Phabricator instance.

[Attr] Don't print attr arg with default value
AbandonedPublic

Authored by jdenny on May 15 2018, 1:31 PM.

Details

Summary

For example, given:

class __single_inheritance T;

-ast-print -fms-extensions used to print:

class __single_inheritance(1) T;

Clang fails to parse that because the "(1)" is not valid syntax.

This was discovered at:

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180514/228390.html

To fix that, this patch generally suppresses printing any attribute
argument that has its default value unless other arguments will be
printed after it. Doing so should always maintain the original source
semantics and produce valid syntax.

However, doing so also drops arguments where attributes are legally
specified explicitly with their default values but are not followed by
other arguments. Correct syntax in the previous case seems more
important than exact textual fidelity in this case.

Diff Detail

Event Timeline

jdenny created this revision.May 15 2018, 1:31 PM

I occurs to me now that I could have fixed __single_inheritance by declaring its argument "fake". However, I still prefer the above solution because (1) it should help with any other attributes where arguments should have been declared fake (but no, I haven't identified any yet), and (2) it generally makes attribute printing more succinct, including cases where originally implicit values were printing as explicit. Again, the sacrifice is that some explicit values now print as implicit, but at least the semantics don't change.

If others disagree, I can change this.

jdenny abandoned this revision.May 15 2018, 2:52 PM

After further thought, this patch doesn't seem worthwhile. Sorry for all the noise.