llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

ast-print generates empty parameter for attributes with optional string parameter

Open strimo378 opened this issue 3 years ago • 8 comments

Hi all,

the AST printer (-Xclang -ast-print) always generates an empty parameter for attributes with optional string parameters.

The following code (see https://godbolt.org/z/v69YW7rsb)

int a() __attribute__((warn_unused_result));

int b1() __attribute__((deprecated));
int b2() __attribute__((deprecated("xyz")));
int b3() __attribute__((deprecated("xyz", "y")));

is generates as

int a() __attribute__((warn_unused_result("")));
int b1() __attribute__((deprecated("")));
int b2() __attribute__((deprecated("xyz")));
int b3() __attribute__((deprecated("xyz", "y")));

For the attributes of the function a and b1 an empty parameter ("") is added to the output code. In principle, the code is correct for Clang. It is only problematic that for warn_unused_result the optional parameter is not supported by GCC and the code becomes incompatible.

The Clang source code to output an attributes is within the *Attr::printPretty functions within the TableGen'erated file Attrs.inc.

strimo378 avatar May 30 '23 01:05 strimo378

@llvm/issue-subscribers-clang-frontend

llvmbot avatar May 30 '23 02:05 llvmbot

any plan to fix this?

yangdiangzb avatar Jul 14 '23 08:07 yangdiangzb

Not from my side as I am lacking experience how Attrs.inc is generated...

strimo378 avatar Jul 14 '23 08:07 strimo378

Not from my side as I am lacking experience how Attrs.inc is generated...

me neither. and since nodiscard and warn_unused_result are sharing the same rule. i have no idea how to fix this without effecting nodiscard

image

image

yangdiangzb avatar Jul 15 '23 01:07 yangdiangzb

seems your commit doesnt fix this issue problem? @strimo378

yangdiangzb avatar Sep 21 '23 08:09 yangdiangzb

@yangdiangzb Hmm, yes that is correct. it seems I used the wrong link for the commit. Thanks for the information.

strimo378 avatar Sep 21 '23 08:09 strimo378

Sorry about this. My private fork accidentally closed this issue.

ken-matsui avatar May 31 '24 13:05 ken-matsui

I've opened #239378 which omits empty optional string arguments for all affected attributes, including deprecated. Feedback welcome.

max-winkler avatar Nov 07 '26 15:11 max-winkler