This is an archive of the discontinued LLVM Phabricator instance.

Dump functions attribute right before their return type
Needs ReviewPublic

Authored by giulianobelinassi on Mar 3 2023, 12:47 PM.



GCC rejects the following kind of dumps:

int f(void) attribute((unused))

return 0;


because of the following reason: Assume the function is K&R declared:

int f(i) attribute((unused))

int i;


return 0;


Now, to which symbol should the attribute((unused)) be applied?
Depending of the parsing strategy, this will be either applied to
f or i, but likely this will be applied to f as the compiler parses
from left-to-right.

GCC, therefore, rejects this kind of declarations altogether. Clang
even warns that such declarations won't be accepted by GCC. Since
an user may be using clang dumps as a library to do static analysis
and outputing code that will be fed into GCC, then instead of dumping:

int f(void) attribute((unused));

this patch modifies such cases to output to:

int attribute((unused)) f(void);

causing GCC to also accept such dumps.

Signed-off-by: Giuliano Belinassi <>

Depends on: D141714

Diff Detail