This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST][DeclPrinter] Change "__attribute__" AST printing location for the sake of GCC compatibility.
Needs ReviewPublic

Authored by mstachyraa on Sep 1 2023, 8:48 AM.

Details

Reviewers
rarutyun
Summary

When printing C representation of AST, clang puts the "attribute" elements after the name of printed function.
In order for the generated code to be GCC compatible, these attributes should be printed at the beginning of function.

For example when executing clang -cc1 -ast-print test.c we recieve:
void test() __attribute__((cold)) {}

Instead we should see:
__attribute__((cold))void test() {}
because the former causes GCC incompatibility

warning: GCC does not allow 'cold' attribute in this position on a function definition [-Wgcc-compat]

Diff Detail

Event Timeline

mstachyraa created this revision.Sep 1 2023, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 8:48 AM
mstachyraa requested review of this revision.Sep 1 2023, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 8:48 AM
Herald added a subscriber: wangpc. · View Herald Transcript
mstachyraa edited the summary of this revision. (Show Details)Sep 1 2023, 9:00 AM