Rework the printing of attributes (#87281)
commita30662fc2acdd73ca1a9217716299a4676999fb4
authorVassil Vassilev <v.g.vassilev@gmail.com>
Tue, 9 Apr 2024 04:14:43 +0000 (9 07:14 +0300)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2024 04:14:43 +0000 (9 07:14 +0300)
tree9c1b46ab8c66803d4072e112f78dd8061c085b5d
parent04f33a3ac2e8ca96840606f812eaef974ff61c80
Rework the printing of attributes (#87281)

Commit https://github.com/llvm/llvm-project/commit/46f3ade introduced a
notion of printing the attributes on the left to improve the printing of
attributes attached to variable declarations. The intent was to produce
more GCC compatible code because clang tends to print the attributes on
the right hand side which is not accepted by gcc.

This approach has increased the complexity in tablegen and the
attrubutes themselves as now the are supposed to know where they could
appear. That lead to mishandling of the `override` keyword which is
modelled as an attribute in clang.

This patch takes an inspiration from the existing approach and tries to
keep the position of the attributes as they were written. To do so we
use simpler heuristic which checks if the source locations of the
attribute precedes the declaration. If so, it is considered to be
printed before the declaration.

Fixes https://github.com/llvm/llvm-project/issues/87151
17 files changed:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/CMakeLists.txt
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/StmtPrinter.cpp
clang/test/AST/ast-print-method-decl.cpp
clang/test/AST/ast-print-no-sanitize.cpp
clang/test/AST/attr-print-emit.cpp
clang/test/Analysis/scopes-cfg-output.cpp
clang/test/OpenMP/assumes_codegen.cpp
clang/test/OpenMP/assumes_print.cpp
clang/test/OpenMP/assumes_template_print.cpp
clang/test/OpenMP/declare_simd_ast_print.cpp
clang/test/SemaCXX/attr-no-sanitize.cpp
clang/test/SemaCXX/cxx11-attr-print.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/utils/TableGen/TableGen.cpp
clang/utils/TableGen/TableGenBackends.h