@@ -122,8 +122,11 @@ static void emitAttributeMacroDecls(const AttributeMap &MacroAttr,
122
122
});
123
123
// 1. If __cplusplus is defined and cxx11 style is provided, define the
124
124
// macro using cxx11 version with the following priority:
125
- // 1a. If the attribute is a clang attribute, check for __clang__.
126
- // 2b. If the attribute is a gnu attribute, check for __GNUC__.
125
+ // 1a. If there is no namespace (so the macro is supposed to be
126
+ // compiler-independent),
127
+ // use this version first.
128
+ // 1b. If the attribute is a clang attribute, check for __clang__.
129
+ // 1c. If the attribute is a gnu attribute, check for __GNUC__.
127
130
// 2. Otherwise, if __GNUC__ is defined and gnu
128
131
// style is provided, define the macro using gnu version;
129
132
// 3. Otherwise, if _MSC_VER is defined and __declspec is provided, define
@@ -139,30 +142,35 @@ static void emitAttributeMacroDecls(const AttributeMap &MacroAttr,
139
142
llvm::StringRef Attr = Instance->getValueAsString (" Attr" );
140
143
if (Style == AttributeStyle::Cxx11) {
141
144
OS << " #if !defined(" << Macro << " ) && defined(__cplusplus)" ;
142
- if (isAsciiIdentifier (Attr))
143
- OS << " && __has_attribute(" << Attr << " )" ;
144
145
AttributeNamespace Namespace = getAttributeNamespace (Instance);
145
146
if (Namespace == AttributeNamespace::Clang)
146
147
OS << " && defined(__clang__)\n " ;
147
148
else if (Namespace == AttributeNamespace::Gnu)
148
149
OS << " && defined(__GNUC__)\n " ;
149
150
else
150
151
OS << ' \n ' ;
152
+ if (isAsciiIdentifier (Attr) && Namespace != AttributeNamespace::None)
153
+ OS << " #if __has_attribute(" << Attr << " )\n " ;
154
+ else
155
+ OS << " #if __has_cpp_attribute(" << Attr << " )\n " ;
151
156
OS << " #define " << Macro << " [[" ;
152
157
if (Namespace == AttributeNamespace::Clang)
153
158
OS << " clang::" ;
154
159
else if (Namespace == AttributeNamespace::Gnu)
155
160
OS << " gnu::" ;
156
161
OS << Attr << " ]]\n " ;
162
+ if (isAsciiIdentifier (Attr))
163
+ OS << " #endif\n " ;
157
164
OS << " #endif\n " ;
158
165
}
159
166
if (Style == AttributeStyle::Gnu) {
160
- OS << " #if !defined(" << Macro << " ) && defined(__GNUC__)" ;
167
+ OS << " #if !defined(" << Macro << " ) && defined(__GNUC__)\n " ;
161
168
if (isAsciiIdentifier (Attr))
162
- OS << " && __has_attribute(" << Attr << " )" ;
163
- OS << ' \n ' ;
169
+ OS << " #if __has_attribute(" << Attr << " )\n " ;
164
170
OS << " #define " << Macro << " __attribute__((" ;
165
171
OS << Attr << " ))\n " ;
172
+ if (isAsciiIdentifier (Attr))
173
+ OS << " #endif\n " ;
166
174
OS << " #endif\n " ;
167
175
}
168
176
if (Style == AttributeStyle::Declspec) {
0 commit comments