[all-commits] [llvm/llvm-project] a30662: Rework the printing of attributes (#87281)

Vassil Vassilev via All-commits all-commits at lists.llvm.org
Mon Apr 8 21:15:04 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a30662fc2acdd73ca1a9217716299a4676999fb4
      https://github.com/llvm/llvm-project/commit/a30662fc2acdd73ca1a9217716299a4676999fb4
  Author: Vassil Vassilev <v.g.vassilev at gmail.com>
  Date:   2024-04-09 (Tue, 09 Apr 2024)

  Changed paths:
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/CMakeLists.txt
    M clang/lib/AST/DeclPrinter.cpp
    M clang/lib/AST/StmtPrinter.cpp
    M clang/test/AST/ast-print-method-decl.cpp
    M clang/test/AST/ast-print-no-sanitize.cpp
    M clang/test/AST/attr-print-emit.cpp
    M clang/test/Analysis/scopes-cfg-output.cpp
    M clang/test/OpenMP/assumes_codegen.cpp
    M clang/test/OpenMP/assumes_print.cpp
    M clang/test/OpenMP/assumes_template_print.cpp
    M clang/test/OpenMP/declare_simd_ast_print.cpp
    M clang/test/SemaCXX/attr-no-sanitize.cpp
    M clang/test/SemaCXX/cxx11-attr-print.cpp
    M clang/utils/TableGen/ClangAttrEmitter.cpp
    M clang/utils/TableGen/TableGen.cpp
    M clang/utils/TableGen/TableGenBackends.h

  Log Message:
  -----------
  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



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list