[PATCH] D137979: parse: process GNU and standard attributes on top-level decls

Saleem Abdulrasool via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 14 13:25:41 PST 2022


compnerd created this revision.
compnerd added reviewers: aaron.ballman, sammccall.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
compnerd requested review of this revision.
Herald added a project: clang.

We would previously reject valid input where GNU attributes preceded the standard attributes on top-level declarations.  A previous attribute handling change had begun rejecting this whilst GCC does honour this layout.  In practice, this breaks use of `extern "C"` attributed functions which use both standard and GNU attributes as experienced by the Swift runtime.

The majority of the changes here are plumbing the parsed attributes down to the use sites.  This incidentally improves source location tracking and token handling in the source manager.  The downside of this is that it exposes a latent issue in the indexing path where we would try to backtrack to annotate attributes post-expansion.  However the proper parsing now introduced results in the token stream now retrieving the pre-expanded token whilst still associating the attribute to the declaration.  This percolates throughout the other various tests.

The one remaining failure with this test is Index/annotate-tokens.c where the leading attribute is not associated with the declaration due to the `FinalizeDeclarationGroup` not re-associating the attributes with the declarations in the declaration group.  However, the declaration still does receive the attribute.

Special thanks to Aaron Ballman for the many hints and extensive rubber ducking that was involved in identifying the various places where we accidentally dropped attributes.

Fixes: #58229


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137979

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseHLSL.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_10.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_12.c
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
  clang/test/Parser/attr-order.cpp
  clang/test/Parser/cxx-attributes.cpp
  clang/test/SemaCXX/attr-unavailable.cpp
  clang/test/SemaObjC/objc-asm-attribute-neg-test.m
  clang/unittests/Tooling/SourceCodeTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137979.475258.patch
Type: text/x-patch
Size: 76359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221114/035855bb/attachment-0001.bin>


More information about the cfe-commits mailing list