Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
strimo378 opened this issue May 30, 2023 · 7 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@strimo378
Copy link
Contributor

strimo378 commented May 30, 2023

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.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels May 30, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented May 30, 2023

@llvm/issue-subscribers-clang-frontend

@yangdiangzb
Copy link

any plan to fix this?

@strimo378
Copy link
Contributor Author

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

@yangdiangzb
Copy link

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

razmser pushed a commit to razmser/llvm-project that referenced this issue Sep 8, 2023
…hat are definitions without having a body

DeclPrinter used FunctionDecl::isThisDeclarationADefinition to decide if the decl requires a semicolon at the end. However, there are several methods without body (that require a semicolon) that are definitions.

Fixes llvm#62996

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156533
@yangdiangzb
Copy link

seems your commit doesnt fix this issue problem? @strimo378

@strimo378
Copy link
Contributor Author

strimo378 commented Sep 21, 2023

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

@ken-matsui
Copy link
Member

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

@ken-matsui ken-matsui reopened this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

5 participants