7 Commits

Author SHA1 Message Date
Giuliano Belinassi
46f3ade508 Fix ast print of variables with attributes
Previously clang AST prints the following declaration:

int fun_var_unused() {

  int x __attribute__((unused)) = 0;
  return x;
}

and

int __declspec(thread) x = 0;

as:

int fun_var_unused() {

  int x = 0 __attribute__((unused));
  return x;
}

and

int x = __declspec(thread) 0;

which is rejected by C/C++ parser. This patch modifies the logic to
print old C attributes for variables as:

int __attribute__((unused)) x = 0;
and the __declspec case as:

int __declspec(thread) x = 0;
Fixes: https://github.com/llvm/llvm-project/issues/59973

Previous version: D141714.

Differential Revision:https://reviews.llvm.org/D141714
2023-09-07 13:35:50 -07:00
Timo Stripf
291eb2589f [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers
DeclPrinter::PrintConstructorInitializers did output non-written constructor initiaizers. In particular, implicit constructor initializers of base classes were output.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156523
2023-08-07 23:13:50 +00:00
Timo Stripf
3e66a174df Reland [clang][DeclPrinter] Fix missing semicolon in AST print for methods that 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 https://github.com/llvm/llvm-project/issues/62996

Initial commit had a failing test case on targets not supporting `__attribute__((alias))`. Added `-triple i386-linux-gnu` to the specific test case.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156533
2023-08-07 22:14:15 +00:00
Steven Wu
4098e13a71 Revert "[clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body"
This reverts commit a3da6284c23affdd9092b2641017e99d85c2d89b. It breaks
tests on macOS as macOS doesn't support attribute alias.
2023-07-28 11:39:46 -07:00
Timo Stripf
a3da6284c2 [clang][DeclPrinter] Fix missing semicolon in AST print for methods that 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 https://github.com/llvm/llvm-project/issues/62996

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156533
2023-07-28 14:50:17 +00:00
Timo Stripf
0e4c5cc56c [clang][DeclPrinter] Fix AST print of curly constructor initializers
DeclPrinter::PrintConstructorInitializers did not consider curly constructor initializers. Any curly constructor initializers (e.g. `A() : Field{}`) was printed with round brackets (e.g. `A() : Field({})`).

https://github.com/llvm/llvm-project/issues/64061

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156307
2023-07-27 15:43:39 +00:00
Timo Stripf
2ca7416225 [clang][DeclPrinter] Fix AST print of delegating constructors
DeclPrinter::PrintConstructorInitializers did not consider delegating initializers. As result, the output contained an "NULL TYPE" for delegating constructors.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D154186
2023-07-26 09:26:53 +00:00