diff options
author | Justin Lebar <jlebar@google.com> | 2017-01-05 16:51:54 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2017-01-05 16:51:54 +0000 |
commit | 15128fbc1ca9faa41ec780756662930bb264e9a5 (patch) | |
tree | 62b773527173577ef09c0068a1e4f664eee74a9d /utils | |
parent | 76b76dc49910be865a9b0e6735008f80dd73c6e4 (diff) |
[TableGen] Only normalize the spelling of GNU-style attributes.
Summary:
When Sema looks up an attribute name, it strips off leading and trailing
"__" if the attribute is GNU-style. That is, __attribute__((foo)) and
__attribute__((__foo__)) are equivalent.
This is only true for GNU-style attributes. In particular,
__declspec(__foo__) is not equivalent to __declspec(foo), and Sema
respects this difference.
This patch fixes TableGen to match Sema's behavior. The spelling
'GNU<"__foo__">' should be normalized to 'GNU<"foo">', but
'Declspec<"__foo__">' should not be changed.
This is necessary to make CUDA compilation work on Windows, because e.g.
the __device__ attribute is spelled __declspec(__device__).
Attr.td does not contain any Declspec spellings that start or end with
"__", so this change should not affect any other attributes.
Reviewers: rnk
Subscribers: cfe-commits, tra
Differential Revision: https://reviews.llvm.org/D28318
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291129 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/TableGen/ClangAttrEmitter.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index d65794e863..27ab34c130 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -133,10 +133,9 @@ static StringRef NormalizeNameForSpellingComparison(StringRef Name) { return Name.trim("_"); } -// Normalize attribute spelling only if the spelling has both leading -// and trailing underscores. For example, __ms_struct__ will be -// normalized to "ms_struct"; __cdecl will remain intact. -static StringRef NormalizeAttrSpelling(StringRef AttrSpelling) { +// Normalize the spelling of a GNU attribute (i.e. "x" in "__attribute__((x))"), +// removing "__" if it appears at the beginning and end of the attribute's name. +static StringRef NormalizeGNUAttrSpelling(StringRef AttrSpelling) { if (AttrSpelling.startswith("__") && AttrSpelling.endswith("__")) { AttrSpelling = AttrSpelling.substr(2, AttrSpelling.size() - 4); } @@ -3045,7 +3044,11 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) { assert(Matches && "Unsupported spelling variety found"); - Spelling += NormalizeAttrSpelling(RawSpelling); + if (Variety == "GNU") + Spelling += NormalizeGNUAttrSpelling(RawSpelling); + else + Spelling += RawSpelling; + if (SemaHandler) Matches->push_back(StringMatcher::StringPair(Spelling, "return AttributeList::AT_" + AttrName + ";")); |