[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
Wed Dec 12 16:28:36 PST 2018
erik.pilkington created this revision.
erik.pilkington added reviewers: arphaman, aaron.ballman.
Herald added subscribers: dexonsmith, jkorous.
One problem with defining macros that expand to _Pragma("clang attribute")` is that they don't nest very well:
// In some header...
#define ASSUME_X_BEGIN _Pragma ("clang attribute push(__attribute__((x)), apply_to=variable)")
#define ASSUME_X_END _Pragma ("clang attribute pop")
#define ASSUME_Y_BEGIN _Pragma("clang attribute push(__attribute__((y)), apply_to=variable)")
#define ASSUME_Y_END _Pragma("clang attribute pop")
// in some source file...
ASSUME_X_BEGIN
// lots of code
ASSUME_Y_BEGIN
// some more code
ASSUME_X_END // oops! Popped Y, but meant to pop X.
// some other code
ASSUME_Y_END // ditto
This patch adds a way to fix this by adding labels to push/pop directives. A `clang attribute pop`s with a label will only pop a `push`ed group with that same label. Macro authors can then add a unique label to their BEGIN/END functions, which would cause the code above to work fine.
Thanks for taking a look!
Erik
Repository:
rC Clang
https://reviews.llvm.org/D55628
Files:
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/SemaAttr.cpp
clang/test/Sema/pragma-attribute-label.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55628.177971.patch
Type: text/x-patch
Size: 9620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181213/c0571b2e/attachment-0001.bin>
More information about the cfe-commits
mailing list