[PATCH] D145269: Dump functions attribute right before their return type

Giuliano Belinassi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 3 12:47:56 PST 2023


giulianobelinassi created this revision.
Herald added a project: All.
giulianobelinassi requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

GCC rejects the following kind of dumps:

int f(void) __attribute__((unused))
{

  return 0;

}

because of the following reason: Assume the function is K&R declared:

int f(i) __attribute__((unused))

  int i;

{

  return 0;

}

Now, to which symbol should the __attribute__((unused)) be applied?
Depending of the parsing strategy, this will be either applied to
f or i, but likely this will be applied to f as the compiler parses
from left-to-right.

GCC, therefore, rejects this kind of declarations altogether. Clang
even warns that such declarations won't be accepted by GCC. Since
an user may be using clang dumps as a library to do static analysis
and outputing code that will be fed into GCC, then instead of dumping:

int f(void) __attribute__((unused));

this patch modifies such cases to output to:

int __attribute__((unused)) f(void);

causing GCC to also accept such dumps.

Signed-off-by: Giuliano Belinassi <gbelinassi at suse.de>

Depends on: D141714 <https://reviews.llvm.org/D141714>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145269

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-attr-knr.c
  clang/test/AST/ast-print-attr.c
  clang/test/AST/ast-print-no-sanitize.cpp
  clang/test/AST/attr-print-emit.cpp
  clang/test/Analysis/std-c-library-functions-arg-weakdeps.c
  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.c
  clang/test/OpenMP/declare_simd_ast_print.cpp
  clang/test/Sema/attr-print.c
  clang/test/SemaCXX/attr-no-sanitize.cpp
  clang/test/SemaCXX/attr-print.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145269.502230.patch
Type: text/x-patch
Size: 30344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230303/bdec3bd2/attachment-0001.bin>


More information about the cfe-commits mailing list