[PATCH] D37436: Initial implementation of C attributes (WG14 N2137)

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 4 06:49:04 PDT 2017


aaron.ballman created this revision.
Herald added a subscriber: javed.absar.

WG14 has demonstrated sincere interest in adding C++-style attributes to C for C2x, and have added the proposal to their SD-3 document tracking features which are possibly desired for the next version of the standard. The proposal has *not* been formally adopted into the working draft (C17 needs to be finalized first), but it is at the stage where having implementation experience is important to the committee.

This patch implements the feature as proposed, but it might make sense to split the patch up, depending on what we think is the correct way to proceed. This patch adds `c2x` as a new language standard as well as `-fc-attributes` and `-fno-c-attributes` flags. The intention is that `-std=c2x` will enable `-fc-attributes` once the feature is formally adopted by WG14, but `-fc-attributes` can be used to enable the functionality in earlier standard modes (but is currently required in order to enable the functionality). `fno-c-attributes` is provided on the chance that the syntax proposed causes parsing issues for Objective-C and users need a way to work around that; however, such cases should be considered bugs that we need to work around similar to Objective-C++ and C++11-style attributes. The patch also adds support for the `deprecated` attribute (WG14 N2050), mostly so that I would have an attribute handy to test the semantic functionality. Once the basic syntax is committed, I plan to implement the other attributes: `nodiscard` (WG14 N2051), `fallthrough` (WG14 N2052), and `maybe_unused` (WG14 N2053) in separate patches.


https://reviews.llvm.org/D37436

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/Attributes.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Frontend/LangStandard.h
  include/clang/Frontend/LangStandards.def
  include/clang/Parse/Parser.h
  include/clang/Sema/AttributeList.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/Lexer.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseObjc.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Parse/ParsePragma.cpp
  lib/Parse/ParseStmt.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Parse/ParseTentative.cpp
  lib/Parse/Parser.cpp
  lib/Sema/AttributeList.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp
  test/Driver/unknown-std.c
  test/Misc/ast-dump-c-attr.c
  test/Parser/c2x-attributes.c
  test/Parser/cxx0x-attributes.cpp
  test/Sema/attr-deprecated-c2x.c
  test/Sema/c11-compat.c
  utils/TableGen/ClangAttrEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37436.113747.patch
Type: text/x-patch
Size: 73000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170904/2f8f60d5/attachment-0001.bin>


More information about the cfe-commits mailing list