[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 18 23:36:40 PST 2018


erik.pilkington updated this revision to Diff 178837.
erik.pilkington added a comment.

After looking through some users of `#pragma clang attribute`, I don't think that the begin/end solution is what we want here. Some users of this attribute write macros that can expand to different attributes depending on their arguments, for instance:

  AVAILABILITY_BEGIN(macos(10.12)) // expands to an availability attribute
  AVAILABILITY_BEGIN(ios(10))
  // some code...
  AVAILABILITY_END
  AVAILABILITY_END

This code makes sense and is safe, but in this case rewriting AVAILABILITY_BEGIN to use a hypothetical `pragma clang attribute begin`/`end` would be a breaking change, which isn't acceptable. So I think that we want stack semantics, but scoped within the `AVAILABILITY_BEGIN` macro's namespace. That way, we can support multiple `push`es in the same macro, without having having different macros accidentally pop each other.

As for a syntax for this, I chose the following (basically, @dexonsmith's idea with a '.'):

  #pragma clang attribute NoReturn.push (__attribute__((noreturn)), apply_to=function)
  int foo();
  #pragma clang attribute NoReturn.pop

I think the '.' makes the nested relationship (i.e. the push is contained within the namespace) more clear to C programmers, and hopefully clears up the confusion. @AaronBallman: WDYT?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55628/new/

https://reviews.llvm.org/D55628

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Sema/pragma-attribute-namespace.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55628.178837.patch
Type: text/x-patch
Size: 12648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181219/580cc6e6/attachment-0001.bin>


More information about the cfe-commits mailing list