Gentoo Archives: gentoo-commits

From: Matthias Maier <tamiko@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/llvm/, sys-devel/llvm/files/
Date: Tue, 02 Aug 2016 17:24:46
Message-Id: 1470158663.6ccd97198cc1d33b13c6aa69e73ea06b69bf59d5.tamiko@gentoo
1 commit: 6ccd97198cc1d33b13c6aa69e73ea06b69bf59d5
2 Author: Matthias Maier <tamiko <AT> gentoo <DOT> org>
3 AuthorDate: Tue Aug 2 15:19:35 2016 +0000
4 Commit: Matthias Maier <tamiko <AT> gentoo <DOT> org>
5 CommitDate: Tue Aug 2 17:24:23 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6ccd9719
7
8 sys-devel/llvm: Backport abi-tag support, bug #571600
9
10 This applies the abi-tag support patches to 3.8.1-r1.
11
12 Unfortunately, gcc-5* and gcc-6* have slightly ABI incompatible
13 implementations of the abi-tag feature (basically a bugfix in gcc-6*) [1].
14 The patchset for clang implements the gcc-6* version and is thus not fully
15 compatible with gcc-5*.
16
17 [1] https://llvm.org/bugs/show_bug.cgi?id=28511
18
19 Package-Manager: portage-2.2.28
20
21 .../files/clang-3.8-abi-tag-support-mangler.patch | 1230 ++++++++++++++++++++
22 .../files/clang-3.8-abi-tag-support-sema.patch | 419 +++++++
23 sys-devel/llvm/llvm-3.8.1-r1.ebuild | 4 +
24 3 files changed, 1653 insertions(+)
25
26 diff --git a/sys-devel/llvm/files/clang-3.8-abi-tag-support-mangler.patch b/sys-devel/llvm/files/clang-3.8-abi-tag-support-mangler.patch
27 new file mode 100644
28 index 0000000..d259757
29 --- /dev/null
30 +++ b/sys-devel/llvm/files/clang-3.8-abi-tag-support-mangler.patch
31 @@ -0,0 +1,1230 @@
32 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/lib/AST/ItaniumMangle.cpp llvm-3.8.0.src/tools/clang/lib/AST/ItaniumMangle.cpp
33 +--- llvm-3.8.0.src.orig/tools/clang/lib/AST/ItaniumMangle.cpp 2016-01-09 13:53:17.000000000 +0100
34 ++++ llvm-3.8.0.src/tools/clang/lib/AST/ItaniumMangle.cpp 2016-07-10 23:59:08.412719561 +0200
35 +@@ -212,6 +212,12 @@
36 + class CXXNameMangler {
37 + ItaniumMangleContextImpl &Context;
38 + raw_ostream &Out;
39 ++ bool NullOut = false;
40 ++ /// In the "DisableDerivedAbiTags" mode derived ABI tags are not calculated.
41 ++ /// This mode is used when mangler creates another mangler recursively to
42 ++ /// calculate ABI tags for the function return value or the variable type.
43 ++ /// Also it is required to avoid infinite recursion in some cases.
44 ++ bool DisableDerivedAbiTags = false;
45 +
46 + /// The "structor" is the top-level declaration being mangled, if
47 + /// that's not a template specialization; otherwise it's the pattern
48 +@@ -261,15 +267,131 @@
49 +
50 + } FunctionTypeDepth;
51 +
52 ++ // abi_tag is a gcc attribute, taking one or more strings called "tags".
53 ++ // The goal is to annotate against which version of a library an object was
54 ++ // built and to be able to provide backwards compatibility ("dual abi").
55 ++ // For more information see docs/ItaniumMangleAbiTags.rst.
56 ++ typedef SmallVector<StringRef, 4> AbiTagList;
57 ++ typedef llvm::SmallSetVector<StringRef, 4> AbiTagSet;
58 ++
59 ++ // State to gather all implicit and explicit tags used in a mangled name.
60 ++ // Must always have an instance of this while emitting any name to keep
61 ++ // track.
62 ++ class AbiTagState final {
63 ++ //! All abi tags used implicitly or explicitly
64 ++ AbiTagSet UsedAbiTags;
65 ++ //! All explicit abi tags (i.e. not from namespace)
66 ++ AbiTagSet EmittedAbiTags;
67 ++
68 ++ AbiTagState *&LinkHead;
69 ++ AbiTagState *Parent = nullptr;
70 ++
71 ++ bool LinkActive = false;
72 ++
73 ++ public:
74 ++ explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
75 ++ Parent = LinkHead;
76 ++ LinkHead = this;
77 ++ LinkActive = true;
78 ++ }
79 ++
80 ++ // no copy, no move
81 ++ AbiTagState(const AbiTagState &) = delete;
82 ++ AbiTagState &operator=(const AbiTagState &) = delete;
83 ++
84 ++ ~AbiTagState() { pop(); }
85 ++
86 ++ void pop() {
87 ++ if (!LinkActive)
88 ++ return;
89 ++
90 ++ assert(LinkHead == this &&
91 ++ "abi tag link head must point to us on destruction");
92 ++ LinkActive = false;
93 ++ if (Parent) {
94 ++ Parent->UsedAbiTags.insert(UsedAbiTags.begin(), UsedAbiTags.end());
95 ++ Parent->EmittedAbiTags.insert(EmittedAbiTags.begin(),
96 ++ EmittedAbiTags.end());
97 ++ }
98 ++ LinkHead = Parent;
99 ++ }
100 ++
101 ++ void write(raw_ostream &Out, const NamedDecl *ND,
102 ++ const AbiTagList *AdditionalAbiTags) {
103 ++ ND = cast<NamedDecl>(ND->getCanonicalDecl());
104 ++
105 ++ if (!isa<FunctionDecl>(ND) && !isa<VarDecl>(ND)) {
106 ++ assert(
107 ++ !AdditionalAbiTags &&
108 ++ "only function and variables need a list of additional abi tags");
109 ++ if (const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
110 ++ if (const auto *AbiTag = NS->getAttr<AbiTagAttr>()) {
111 ++ for (const auto &Tag : AbiTag->tags()) {
112 ++ UsedAbiTags.insert(Tag);
113 ++ }
114 ++ }
115 ++ // Don't emit abi tags for namespaces.
116 ++ return;
117 ++ }
118 ++ }
119 ++
120 ++ AbiTagList TagList;
121 ++ if (const auto *AbiTag = ND->getAttr<AbiTagAttr>()) {
122 ++ for (const auto &Tag : AbiTag->tags()) {
123 ++ UsedAbiTags.insert(Tag);
124 ++ // AbiTag->tags() is sorted and has no duplicates
125 ++ TagList.push_back(Tag);
126 ++ }
127 ++ }
128 ++
129 ++ if (AdditionalAbiTags) {
130 ++ for (const auto &Tag : *AdditionalAbiTags) {
131 ++ UsedAbiTags.insert(Tag);
132 ++ if (std::find(TagList.begin(), TagList.end(), Tag) == TagList.end()) {
133 ++ // don't insert duplicates
134 ++ TagList.push_back(Tag);
135 ++ }
136 ++ }
137 ++ // AbiTag->tags() are already sorted; only add if we had additional tags
138 ++ std::sort(TagList.begin(), TagList.end());
139 ++ }
140 ++
141 ++ writeSortedUniqueAbiTags(Out, TagList);
142 ++ }
143 ++
144 ++ const AbiTagSet &getUsedAbiTags() const { return UsedAbiTags; }
145 ++ void setUsedAbiTags(const AbiTagSet &AbiTags) {
146 ++ UsedAbiTags = AbiTags;
147 ++ }
148 ++
149 ++ const AbiTagSet &getEmittedAbiTags() const {
150 ++ return EmittedAbiTags;
151 ++ }
152 ++
153 ++ private:
154 ++ template <typename TagList>
155 ++ void writeSortedUniqueAbiTags(raw_ostream &Out, TagList const &AbiTags) {
156 ++ for (const auto &Tag : AbiTags) {
157 ++ EmittedAbiTags.insert(Tag);
158 ++ Out << "B";
159 ++ Out << Tag.size();
160 ++ Out << Tag;
161 ++ }
162 ++ }
163 ++ };
164 ++
165 ++ AbiTagState *AbiTags = nullptr;
166 ++ AbiTagState AbiTagsRoot;
167 ++
168 + llvm::DenseMap<uintptr_t, unsigned> Substitutions;
169 +
170 + ASTContext &getASTContext() const { return Context.getASTContext(); }
171 +
172 + public:
173 + CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_,
174 +- const NamedDecl *D = nullptr)
175 +- : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(0),
176 +- SeqID(0) {
177 ++ const NamedDecl *D = nullptr, bool NullOut_ = false)
178 ++ : Context(C), Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
179 ++ StructorType(0), SeqID(0), AbiTagsRoot(AbiTags) {
180 + // These can't be mangled without a ctor type or dtor type.
181 + assert(!D || (!isa<CXXDestructorDecl>(D) &&
182 + !isa<CXXConstructorDecl>(D)));
183 +@@ -277,11 +399,16 @@
184 + CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_,
185 + const CXXConstructorDecl *D, CXXCtorType Type)
186 + : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
187 +- SeqID(0) { }
188 ++ SeqID(0), AbiTagsRoot(AbiTags) { }
189 + CXXNameMangler(ItaniumMangleContextImpl &C, raw_ostream &Out_,
190 + const CXXDestructorDecl *D, CXXDtorType Type)
191 + : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
192 +- SeqID(0) { }
193 ++ SeqID(0), AbiTagsRoot(AbiTags) { }
194 ++
195 ++ CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
196 ++ : Context(Outer.Context), Out(Out_), NullOut(true),
197 ++ Structor(Outer.Structor), StructorType(Outer.StructorType),
198 ++ SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
199 +
200 + #if MANGLE_CHECKER
201 + ~CXXNameMangler() {
202 +@@ -296,14 +423,18 @@
203 + #endif
204 + raw_ostream &getStream() { return Out; }
205 +
206 ++ void disableDerivedAbiTags() { DisableDerivedAbiTags = true; }
207 ++ static bool shouldHaveAbiTags(ItaniumMangleContextImpl &C, const VarDecl *VD);
208 ++
209 + void mangle(const NamedDecl *D);
210 + void mangleCallOffset(int64_t NonVirtual, int64_t Virtual);
211 + void mangleNumber(const llvm::APSInt &I);
212 + void mangleNumber(int64_t Number);
213 + void mangleFloat(const llvm::APFloat &F);
214 +- void mangleFunctionEncoding(const FunctionDecl *FD);
215 ++ void mangleFunctionEncoding(const FunctionDecl *FD,
216 ++ bool ExcludeUnqualifiedName = false);
217 + void mangleSeqID(unsigned SeqID);
218 +- void mangleName(const NamedDecl *ND);
219 ++ void mangleName(const NamedDecl *ND, bool ExcludeUnqualifiedName = false);
220 + void mangleType(QualType T);
221 + void mangleNameOrStandardSubstitution(const NamedDecl *ND);
222 +
223 +@@ -334,31 +465,53 @@
224 + DeclarationName name,
225 + unsigned KnownArity = UnknownArity);
226 +
227 +- void mangleName(const TemplateDecl *TD,
228 +- const TemplateArgument *TemplateArgs,
229 +- unsigned NumTemplateArgs);
230 +- void mangleUnqualifiedName(const NamedDecl *ND) {
231 +- mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity);
232 ++ void mangleFunctionEncodingBareType(const FunctionDecl *FD);
233 ++
234 ++ void mangleNameWithAbiTags(const NamedDecl *ND,
235 ++ const AbiTagList *AdditionalAbiTags,
236 ++ bool ExcludeUnqualifiedName);
237 ++ void mangleTemplateName(const TemplateDecl *TD,
238 ++ const AbiTagList *AdditionalAbiTags,
239 ++ bool ExcludeUnqualifiedName,
240 ++ const TemplateArgument *TemplateArgs,
241 ++ unsigned NumTemplateArgs);
242 ++ void mangleUnqualifiedName(const NamedDecl *ND,
243 ++ const AbiTagList *AdditionalAbiTags) {
244 ++ mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity,
245 ++ AdditionalAbiTags);
246 + }
247 + void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name,
248 +- unsigned KnownArity);
249 +- void mangleUnscopedName(const NamedDecl *ND);
250 +- void mangleUnscopedTemplateName(const TemplateDecl *ND);
251 +- void mangleUnscopedTemplateName(TemplateName);
252 ++ unsigned KnownArity,
253 ++ const AbiTagList *AdditionalAbiTags);
254 ++ void mangleUnscopedName(const NamedDecl *ND,
255 ++ const AbiTagList *AdditionalAbiTags);
256 ++ void mangleUnscopedTemplateName(const TemplateDecl *ND,
257 ++ const AbiTagList *AdditionalAbiTags);
258 ++ void mangleUnscopedTemplateName(TemplateName,
259 ++ const AbiTagList *AdditionalAbiTags);
260 + void mangleSourceName(const IdentifierInfo *II);
261 +- void mangleLocalName(const Decl *D);
262 ++ void mangleLocalName(const Decl *D,
263 ++ const AbiTagList *AdditionalAbiTags,
264 ++ bool ExcludeUnqualifiedName);
265 + void mangleBlockForPrefix(const BlockDecl *Block);
266 + void mangleUnqualifiedBlock(const BlockDecl *Block);
267 + void mangleLambda(const CXXRecordDecl *Lambda);
268 + void mangleNestedName(const NamedDecl *ND, const DeclContext *DC,
269 +- bool NoFunction=false);
270 ++ const AbiTagList *AdditionalAbiTags,
271 ++ bool NoFunction,
272 ++ bool ExcludeUnqualifiedName);
273 + void mangleNestedName(const TemplateDecl *TD,
274 ++ const AbiTagList *AdditionalAbiTags,
275 ++ bool ExcludeUnqualifiedName,
276 + const TemplateArgument *TemplateArgs,
277 + unsigned NumTemplateArgs);
278 + void manglePrefix(NestedNameSpecifier *qualifier);
279 + void manglePrefix(const DeclContext *DC, bool NoFunction=false);
280 + void manglePrefix(QualType type);
281 +- void mangleTemplatePrefix(const TemplateDecl *ND, bool NoFunction=false);
282 ++ void mangleTemplatePrefix(const TemplateDecl *ND,
283 ++ const AbiTagList *AdditionalAbiTags,
284 ++ bool NoFunction = false,
285 ++ bool ExcludeUnqualifiedName = false);
286 + void mangleTemplatePrefix(TemplateName Template);
287 + bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
288 + StringRef Prefix = "");
289 +@@ -405,6 +558,13 @@
290 + void mangleTemplateParameter(unsigned Index);
291 +
292 + void mangleFunctionParam(const ParmVarDecl *parm);
293 ++
294 ++ void writeAbiTags(const NamedDecl *ND,
295 ++ const AbiTagList *AdditionalAbiTags = nullptr);
296 ++
297 ++ AbiTagSet getTagsFromPrefixAndTemplateArguments(const NamedDecl *ND);
298 ++ AbiTagList makeAdditionalTagsForFunction(const FunctionDecl *FD);
299 ++ AbiTagList makeAdditionalTagsForVariable(const VarDecl *VD);
300 + };
301 +
302 + }
303 +@@ -448,6 +608,7 @@
304 + while (!DC->isNamespace() && !DC->isTranslationUnit())
305 + DC = getEffectiveParentContext(DC);
306 + if (DC->isTranslationUnit() && D->getFormalLinkage() != InternalLinkage &&
307 ++ !CXXNameMangler::shouldHaveAbiTags(*this, VD) &&
308 + !isa<VarTemplateSpecializationDecl>(D))
309 + return false;
310 + }
311 +@@ -455,6 +616,12 @@
312 + return true;
313 + }
314 +
315 ++void CXXNameMangler::writeAbiTags(const NamedDecl *ND,
316 ++ const AbiTagList *AdditionalAbiTags) {
317 ++ assert(AbiTags && "require AbiTagState");
318 ++ AbiTags->write(Out, ND, DisableDerivedAbiTags ? nullptr : AdditionalAbiTags);
319 ++}
320 ++
321 + void CXXNameMangler::mangle(const NamedDecl *D) {
322 + // <mangled-name> ::= _Z <encoding>
323 + // ::= <data name>
324 +@@ -470,14 +637,31 @@
325 + mangleName(cast<FieldDecl>(D));
326 + }
327 +
328 +-void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
329 +- // <encoding> ::= <function name> <bare-function-type>
330 +- mangleName(FD);
331 +-
332 ++void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD,
333 ++ bool ExcludeUnqualifiedName) {
334 + // Don't mangle in the type if this isn't a decl we should typically mangle.
335 +- if (!Context.shouldMangleDeclName(FD))
336 ++ if (!Context.shouldMangleDeclName(FD)) {
337 ++ mangleNameWithAbiTags(FD, /* AdditionalAbiTags */ nullptr,
338 ++ ExcludeUnqualifiedName);
339 + return;
340 ++ }
341 ++
342 ++ // <encoding> ::= <function name> <bare-function-type>
343 ++
344 ++ if (ExcludeUnqualifiedName) {
345 ++ // running makeAdditionalTagsForFunction would loop, don't need it here
346 ++ // anyway
347 ++ mangleNameWithAbiTags(FD, /* AdditionalAbiTags */ nullptr,
348 ++ ExcludeUnqualifiedName);
349 ++ } else {
350 ++ AbiTagList AdditionalAbiTags = makeAdditionalTagsForFunction(FD);
351 ++ mangleNameWithAbiTags(FD, &AdditionalAbiTags, ExcludeUnqualifiedName);
352 ++ }
353 +
354 ++ mangleFunctionEncodingBareType(FD);
355 ++}
356 ++
357 ++void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) {
358 + if (FD->hasAttr<EnableIfAttr>()) {
359 + FunctionTypeDepthState Saved = FunctionTypeDepth.push();
360 + Out << "Ua9enable_ifI";
361 +@@ -581,7 +765,24 @@
362 + return nullptr;
363 + }
364 +
365 +-void CXXNameMangler::mangleName(const NamedDecl *ND) {
366 ++// Must not be run from mangleLocalName for the <entity name> as it would loop
367 ++// otherwise.
368 ++void CXXNameMangler::mangleName(const NamedDecl *ND,
369 ++ bool ExcludeUnqualifiedName) {
370 ++ if (!ExcludeUnqualifiedName) {
371 ++ if (const auto *VD = dyn_cast<VarDecl>(ND)) {
372 ++ AbiTagList VariableAdditionalAbiTags = makeAdditionalTagsForVariable(VD);
373 ++ mangleNameWithAbiTags(VD, &VariableAdditionalAbiTags,
374 ++ ExcludeUnqualifiedName);
375 ++ return;
376 ++ }
377 ++ }
378 ++ mangleNameWithAbiTags(ND, nullptr, ExcludeUnqualifiedName);
379 ++}
380 ++
381 ++void CXXNameMangler::mangleNameWithAbiTags(const NamedDecl *ND,
382 ++ const AbiTagList *AdditionalAbiTags,
383 ++ bool ExcludeUnqualifiedName) {
384 + // <name> ::= <nested-name>
385 + // ::= <unscoped-name>
386 + // ::= <unscoped-template-name> <template-args>
387 +@@ -597,7 +798,7 @@
388 + while (!DC->isNamespace() && !DC->isTranslationUnit())
389 + DC = getEffectiveParentContext(DC);
390 + else if (GetLocalClassDecl(ND)) {
391 +- mangleLocalName(ND);
392 ++ mangleLocalName(ND, AdditionalAbiTags, ExcludeUnqualifiedName);
393 + return;
394 + }
395 +
396 +@@ -607,76 +808,93 @@
397 + // Check if we have a template.
398 + const TemplateArgumentList *TemplateArgs = nullptr;
399 + if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
400 +- mangleUnscopedTemplateName(TD);
401 ++ if (!ExcludeUnqualifiedName)
402 ++ mangleUnscopedTemplateName(TD, AdditionalAbiTags);
403 + mangleTemplateArgs(*TemplateArgs);
404 + return;
405 + }
406 +
407 +- mangleUnscopedName(ND);
408 ++ if (!ExcludeUnqualifiedName)
409 ++ mangleUnscopedName(ND, AdditionalAbiTags);
410 + return;
411 + }
412 +
413 + if (isLocalContainerContext(DC)) {
414 +- mangleLocalName(ND);
415 ++ mangleLocalName(ND, AdditionalAbiTags, ExcludeUnqualifiedName);
416 + return;
417 + }
418 +
419 +- mangleNestedName(ND, DC);
420 ++ mangleNestedName(ND, DC, AdditionalAbiTags, /* NoFunction */ false,
421 ++ ExcludeUnqualifiedName);
422 + }
423 +-void CXXNameMangler::mangleName(const TemplateDecl *TD,
424 +- const TemplateArgument *TemplateArgs,
425 +- unsigned NumTemplateArgs) {
426 ++
427 ++void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD,
428 ++ const AbiTagList *AdditionalAbiTags,
429 ++ bool ExcludeUnqualifiedName,
430 ++ const TemplateArgument *TemplateArgs,
431 ++ unsigned NumTemplateArgs) {
432 + const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD));
433 +
434 + if (DC->isTranslationUnit() || isStdNamespace(DC)) {
435 +- mangleUnscopedTemplateName(TD);
436 ++ if (!ExcludeUnqualifiedName)
437 ++ mangleUnscopedTemplateName(TD, AdditionalAbiTags);
438 + mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
439 + } else {
440 +- mangleNestedName(TD, TemplateArgs, NumTemplateArgs);
441 ++ mangleNestedName(TD, AdditionalAbiTags, ExcludeUnqualifiedName,
442 ++ TemplateArgs, NumTemplateArgs);
443 + }
444 + }
445 +
446 +-void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) {
447 ++void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND,
448 ++ const AbiTagList *AdditionalAbiTags) {
449 + // <unscoped-name> ::= <unqualified-name>
450 + // ::= St <unqualified-name> # ::std::
451 +
452 + if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND))))
453 + Out << "St";
454 +
455 +- mangleUnqualifiedName(ND);
456 ++ mangleUnqualifiedName(ND, AdditionalAbiTags);
457 + }
458 +
459 +-void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) {
460 ++void CXXNameMangler::mangleUnscopedTemplateName(
461 ++ const TemplateDecl *ND, const AbiTagList *AdditionalAbiTags) {
462 + // <unscoped-template-name> ::= <unscoped-name>
463 + // ::= <substitution>
464 + if (mangleSubstitution(ND))
465 + return;
466 +
467 + // <template-template-param> ::= <template-param>
468 +- if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND))
469 ++ if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
470 ++ assert(!AdditionalAbiTags &&
471 ++ "template template param cannot have abi tags");
472 + mangleTemplateParameter(TTP->getIndex());
473 +- else
474 +- mangleUnscopedName(ND->getTemplatedDecl());
475 ++ } else {
476 ++ mangleUnscopedName(ND->getTemplatedDecl(), AdditionalAbiTags);
477 ++ }
478 +
479 + addSubstitution(ND);
480 + }
481 +
482 +-void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template) {
483 ++void CXXNameMangler::mangleUnscopedTemplateName(
484 ++ TemplateName Template, const AbiTagList *AdditionalAbiTags) {
485 + // <unscoped-template-name> ::= <unscoped-name>
486 + // ::= <substitution>
487 + if (TemplateDecl *TD = Template.getAsTemplateDecl())
488 +- return mangleUnscopedTemplateName(TD);
489 ++ return mangleUnscopedTemplateName(TD, AdditionalAbiTags);
490 +
491 + if (mangleSubstitution(Template))
492 + return;
493 +
494 ++ assert(!AdditionalAbiTags &&
495 ++ "dependent template name cannot have abi tags");
496 ++
497 + DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
498 + assert(Dependent && "Not a dependent template name?");
499 + if (const IdentifierInfo *Id = Dependent->getIdentifier())
500 + mangleSourceName(Id);
501 + else
502 + mangleOperatorName(Dependent->getOperator(), UnknownArity);
503 +-
504 ++
505 + addSubstitution(Template);
506 + }
507 +
508 +@@ -835,6 +1053,7 @@
509 + else
510 + Out << "sr";
511 + mangleSourceName(qualifier->getAsNamespace()->getIdentifier());
512 ++ writeAbiTags(qualifier->getAsNamespace());
513 + break;
514 + case NestedNameSpecifier::NamespaceAlias:
515 + if (qualifier->getPrefix())
516 +@@ -843,6 +1062,7 @@
517 + else
518 + Out << "sr";
519 + mangleSourceName(qualifier->getAsNamespaceAlias()->getIdentifier());
520 ++ writeAbiTags(qualifier->getAsNamespaceAlias());
521 + break;
522 +
523 + case NestedNameSpecifier::TypeSpec:
524 +@@ -877,6 +1097,7 @@
525 + Out << "sr";
526 +
527 + mangleSourceName(qualifier->getAsIdentifier());
528 ++ // an Identifier has no type information, so we can't emit abi tags for it
529 + break;
530 + }
531 +
532 +@@ -922,7 +1143,8 @@
533 +
534 + void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
535 + DeclarationName Name,
536 +- unsigned KnownArity) {
537 ++ unsigned KnownArity,
538 ++ const AbiTagList *AdditionalAbiTags) {
539 + unsigned Arity = KnownArity;
540 + // <unqualified-name> ::= <operator-name>
541 + // ::= <ctor-dtor-name>
542 +@@ -941,6 +1163,7 @@
543 + Out << 'L';
544 +
545 + mangleSourceName(II);
546 ++ writeAbiTags(ND, AdditionalAbiTags);
547 + break;
548 + }
549 +
550 +@@ -980,6 +1203,7 @@
551 + assert(FD->getIdentifier() && "Data member name isn't an identifier!");
552 +
553 + mangleSourceName(FD->getIdentifier());
554 ++ // Not emitting abi tags: internal name anyway
555 + break;
556 + }
557 +
558 +@@ -1000,6 +1224,10 @@
559 + assert(D->getDeclName().getAsIdentifierInfo() &&
560 + "Typedef was not named!");
561 + mangleSourceName(D->getDeclName().getAsIdentifierInfo());
562 ++ assert(!AdditionalAbiTags && "Type cannot have additional abi tags");
563 ++ // explicit abi tags are still possible; take from underlying type, not
564 ++ // from typedef.
565 ++ writeAbiTags(TD, nullptr);
566 + break;
567 + }
568 +
569 +@@ -1009,6 +1237,8 @@
570 + // <lambda-sig> ::= <parameter-type>+ # Parameter types or 'v' for 'void'.
571 + if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) {
572 + if (Record->isLambda() && Record->getLambdaManglingNumber()) {
573 ++ assert(!AdditionalAbiTags &&
574 ++ "Lambda type cannot have additional abi tags");
575 + mangleLambda(Record);
576 + break;
577 + }
578 +@@ -1020,11 +1250,13 @@
579 + if (UnnamedMangle > 1)
580 + Out << UnnamedMangle - 2;
581 + Out << '_';
582 ++ writeAbiTags(TD, AdditionalAbiTags);
583 + break;
584 + }
585 +
586 +- // Get a unique id for the anonymous struct.
587 +- unsigned AnonStructId = Context.getAnonymousStructId(TD);
588 ++ // Get a unique id for the anonymous struct. If it is not a real output
589 ++ // ID doesn't matter so use fake one.
590 ++ unsigned AnonStructId = NullOut ? 0 : Context.getAnonymousStructId(TD);
591 +
592 + // Mangle it as a source name in the form
593 + // [n] $_<id>
594 +@@ -1052,6 +1284,7 @@
595 + // Otherwise, use the complete constructor name. This is relevant if a
596 + // class with a constructor is declared within a constructor.
597 + mangleCXXCtorType(Ctor_Complete);
598 ++ writeAbiTags(ND, AdditionalAbiTags);
599 + break;
600 +
601 + case DeclarationName::CXXDestructorName:
602 +@@ -1063,6 +1296,7 @@
603 + // Otherwise, use the complete destructor name. This is relevant if a
604 + // class with a destructor is declared within a destructor.
605 + mangleCXXDtorType(Dtor_Complete);
606 ++ writeAbiTags(ND, AdditionalAbiTags);
607 + break;
608 +
609 + case DeclarationName::CXXOperatorName:
610 +@@ -1078,6 +1312,7 @@
611 + case DeclarationName::CXXConversionFunctionName:
612 + case DeclarationName::CXXLiteralOperatorName:
613 + mangleOperatorName(Name, Arity);
614 ++ writeAbiTags(ND, AdditionalAbiTags);
615 + break;
616 +
617 + case DeclarationName::CXXUsingDirective:
618 +@@ -1094,7 +1329,9 @@
619 +
620 + void CXXNameMangler::mangleNestedName(const NamedDecl *ND,
621 + const DeclContext *DC,
622 +- bool NoFunction) {
623 ++ const AbiTagList *AdditionalAbiTags,
624 ++ bool NoFunction,
625 ++ bool ExcludeUnqualifiedName) {
626 + // <nested-name>
627 + // ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
628 + // ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix>
629 +@@ -1114,30 +1351,36 @@
630 + // Check if we have a template.
631 + const TemplateArgumentList *TemplateArgs = nullptr;
632 + if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
633 +- mangleTemplatePrefix(TD, NoFunction);
634 ++ mangleTemplatePrefix(TD, AdditionalAbiTags, NoFunction,
635 ++ ExcludeUnqualifiedName);
636 + mangleTemplateArgs(*TemplateArgs);
637 + }
638 + else {
639 + manglePrefix(DC, NoFunction);
640 +- mangleUnqualifiedName(ND);
641 ++ if (!ExcludeUnqualifiedName)
642 ++ mangleUnqualifiedName(ND, AdditionalAbiTags);
643 + }
644 +
645 + Out << 'E';
646 + }
647 + void CXXNameMangler::mangleNestedName(const TemplateDecl *TD,
648 ++ const AbiTagList *AdditionalAbiTags,
649 ++ bool ExcludeUnqualifiedName,
650 + const TemplateArgument *TemplateArgs,
651 + unsigned NumTemplateArgs) {
652 + // <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
653 +
654 + Out << 'N';
655 +
656 +- mangleTemplatePrefix(TD);
657 ++ mangleTemplatePrefix(TD, AdditionalAbiTags, ExcludeUnqualifiedName);
658 + mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
659 +
660 + Out << 'E';
661 + }
662 +
663 +-void CXXNameMangler::mangleLocalName(const Decl *D) {
664 ++void CXXNameMangler::mangleLocalName(const Decl *D,
665 ++ const AbiTagList *AdditionalAbiTags,
666 ++ bool ExcludeUnqualifiedName) {
667 + // <local-name> := Z <function encoding> E <entity name> [<discriminator>]
668 + // := Z <function encoding> E s [<discriminator>]
669 + // <local-name> := Z <function encoding> E d [ <parameter number> ]
670 +@@ -1149,15 +1392,26 @@
671 +
672 + Out << 'Z';
673 +
674 +- if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
675 +- mangleObjCMethodName(MD);
676 +- else if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
677 +- mangleBlockForPrefix(BD);
678 +- else
679 +- mangleFunctionEncoding(cast<FunctionDecl>(DC));
680 ++ {
681 ++ AbiTagState LocalAbiTags(AbiTags);
682 ++
683 ++ if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
684 ++ mangleObjCMethodName(MD);
685 ++ else if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
686 ++ mangleBlockForPrefix(BD);
687 ++ else
688 ++ mangleFunctionEncoding(cast<FunctionDecl>(DC));
689 ++
690 ++ // Implicit ABI tags (from namespace) are not available in the following
691 ++ // entity; reset to actually emitted tags, which are available.
692 ++ LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
693 ++ }
694 +
695 + Out << 'E';
696 +
697 ++ // GCC 5.3.0 doesn't emit derived ABI tags for local names but that seems to
698 ++ // be a bug that is fixed in trunk.
699 ++
700 + if (RD) {
701 + // The parameter number is omitted for the last parameter, 0 for the
702 + // second-to-last parameter, 1 for the third-to-last parameter, etc. The
703 +@@ -1182,13 +1436,17 @@
704 + // Mangle the name relative to the closest enclosing function.
705 + // equality ok because RD derived from ND above
706 + if (D == RD) {
707 +- mangleUnqualifiedName(RD);
708 ++ if (!ExcludeUnqualifiedName)
709 ++ mangleUnqualifiedName(RD, AdditionalAbiTags);
710 + } else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
711 + manglePrefix(getEffectiveDeclContext(BD), true /*NoFunction*/);
712 +- mangleUnqualifiedBlock(BD);
713 ++ assert(!AdditionalAbiTags && "Block cannot have additional abi tags");
714 ++ if (!ExcludeUnqualifiedName)
715 ++ mangleUnqualifiedBlock(BD);
716 + } else {
717 + const NamedDecl *ND = cast<NamedDecl>(D);
718 +- mangleNestedName(ND, getEffectiveDeclContext(ND), true /*NoFunction*/);
719 ++ mangleNestedName(ND, getEffectiveDeclContext(ND), AdditionalAbiTags,
720 ++ true /*NoFunction*/, ExcludeUnqualifiedName);
721 + }
722 + } else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
723 + // Mangle a block in a default parameter; see above explanation for
724 +@@ -1205,30 +1463,37 @@
725 + }
726 + }
727 +
728 +- mangleUnqualifiedBlock(BD);
729 ++ assert(!AdditionalAbiTags && "Block cannot have additional abi tags");
730 ++ if (!ExcludeUnqualifiedName)
731 ++ mangleUnqualifiedBlock(BD);
732 + } else {
733 +- mangleUnqualifiedName(cast<NamedDecl>(D));
734 ++ if (!ExcludeUnqualifiedName)
735 ++ mangleUnqualifiedName(cast<NamedDecl>(D), AdditionalAbiTags);
736 + }
737 +
738 +- if (const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
739 +- unsigned disc;
740 +- if (Context.getNextDiscriminator(ND, disc)) {
741 +- if (disc < 10)
742 +- Out << '_' << disc;
743 +- else
744 +- Out << "__" << disc << '_';
745 ++ if (!ExcludeUnqualifiedName) {
746 ++ if (const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
747 ++ unsigned disc;
748 ++ if (Context.getNextDiscriminator(ND, disc)) {
749 ++ if (disc < 10)
750 ++ Out << '_' << disc;
751 ++ else
752 ++ Out << "__" << disc << '_';
753 ++ }
754 + }
755 + }
756 + }
757 +
758 + void CXXNameMangler::mangleBlockForPrefix(const BlockDecl *Block) {
759 + if (GetLocalClassDecl(Block)) {
760 +- mangleLocalName(Block);
761 ++ mangleLocalName(Block, /* AdditionalAbiTags */ nullptr,
762 ++ /* ExcludeUnqualifiedName */ false);
763 + return;
764 + }
765 + const DeclContext *DC = getEffectiveDeclContext(Block);
766 + if (isLocalContainerContext(DC)) {
767 +- mangleLocalName(Block);
768 ++ mangleLocalName(Block, /* AdditionalAbiTags */ nullptr,
769 ++ /* ExcludeUnqualifiedName */ false);
770 + return;
771 + }
772 + manglePrefix(getEffectiveDeclContext(Block));
773 +@@ -1239,10 +1504,11 @@
774 + if (Decl *Context = Block->getBlockManglingContextDecl()) {
775 + if ((isa<VarDecl>(Context) || isa<FieldDecl>(Context)) &&
776 + Context->getDeclContext()->isRecord()) {
777 +- if (const IdentifierInfo *Name
778 +- = cast<NamedDecl>(Context)->getIdentifier()) {
779 ++ const auto *ND = cast<NamedDecl>(Context);
780 ++ if (const IdentifierInfo *Name = ND->getIdentifier()) {
781 + mangleSourceName(Name);
782 +- Out << 'M';
783 ++ writeAbiTags(ND, /* AdditionalAbiTags */ nullptr);
784 ++ Out << 'M';
785 + }
786 + }
787 + }
788 +@@ -1275,7 +1541,7 @@
789 + if (const IdentifierInfo *Name
790 + = cast<NamedDecl>(Context)->getIdentifier()) {
791 + mangleSourceName(Name);
792 +- Out << 'M';
793 ++ Out << 'M';
794 + }
795 + }
796 + }
797 +@@ -1358,11 +1624,11 @@
798 + // Check if we have a template.
799 + const TemplateArgumentList *TemplateArgs = nullptr;
800 + if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
801 +- mangleTemplatePrefix(TD);
802 ++ mangleTemplatePrefix(TD, /* AdditionalAbiTags */ nullptr);
803 + mangleTemplateArgs(*TemplateArgs);
804 + } else {
805 + manglePrefix(getEffectiveDeclContext(ND), NoFunction);
806 +- mangleUnqualifiedName(ND);
807 ++ mangleUnqualifiedName(ND, /* AdditionalAbiTags */ nullptr);
808 + }
809 +
810 + addSubstitution(ND);
811 +@@ -1373,27 +1639,30 @@
812 + // ::= <template-param>
813 + // ::= <substitution>
814 + if (TemplateDecl *TD = Template.getAsTemplateDecl())
815 +- return mangleTemplatePrefix(TD);
816 ++ return mangleTemplatePrefix(TD, /* AdditionalAbiTags */ nullptr);
817 +
818 + if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName())
819 + manglePrefix(Qualified->getQualifier());
820 +-
821 ++
822 + if (OverloadedTemplateStorage *Overloaded
823 + = Template.getAsOverloadedTemplate()) {
824 + mangleUnqualifiedName(nullptr, (*Overloaded->begin())->getDeclName(),
825 +- UnknownArity);
826 ++ UnknownArity,
827 ++ /* AdditionalAbiTags */ nullptr);
828 + return;
829 + }
830 +-
831 ++
832 + DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
833 + assert(Dependent && "Unknown template name kind?");
834 + if (NestedNameSpecifier *Qualifier = Dependent->getQualifier())
835 + manglePrefix(Qualifier);
836 +- mangleUnscopedTemplateName(Template);
837 ++ mangleUnscopedTemplateName(Template, /* AdditionalAbiTags */ nullptr);
838 + }
839 +
840 + void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND,
841 +- bool NoFunction) {
842 ++ const AbiTagList *AdditionalAbiTags,
843 ++ bool NoFunction,
844 ++ bool ExcludeUnqualifiedName) {
845 + // <template-prefix> ::= <prefix> <template unqualified-name>
846 + // ::= <template-param>
847 + // ::= <substitution>
848 +@@ -1408,7 +1677,8 @@
849 + mangleTemplateParameter(TTP->getIndex());
850 + } else {
851 + manglePrefix(getEffectiveDeclContext(ND), NoFunction);
852 +- mangleUnqualifiedName(ND->getTemplatedDecl());
853 ++ if (!ExcludeUnqualifiedName)
854 ++ mangleUnqualifiedName(ND->getTemplatedDecl(), AdditionalAbiTags);
855 + }
856 +
857 + addSubstitution(ND);
858 +@@ -1452,6 +1722,7 @@
859 + // <name> ::= <nested-name>
860 + mangleUnresolvedPrefix(Dependent->getQualifier());
861 + mangleSourceName(Dependent->getIdentifier());
862 ++ // writeAbiTags(Dependent);
863 + break;
864 + }
865 +
866 +@@ -1544,16 +1815,19 @@
867 +
868 + case Type::Typedef:
869 + mangleSourceName(cast<TypedefType>(Ty)->getDecl()->getIdentifier());
870 ++ writeAbiTags(cast<TypedefType>(Ty)->getDecl());
871 + break;
872 +
873 + case Type::UnresolvedUsing:
874 + mangleSourceName(
875 + cast<UnresolvedUsingType>(Ty)->getDecl()->getIdentifier());
876 ++ writeAbiTags(cast<UnresolvedUsingType>(Ty)->getDecl());
877 + break;
878 +
879 + case Type::Enum:
880 + case Type::Record:
881 + mangleSourceName(cast<TagType>(Ty)->getDecl()->getIdentifier());
882 ++ writeAbiTags(cast<TagType>(Ty)->getDecl());
883 + break;
884 +
885 + case Type::TemplateSpecialization: {
886 +@@ -1572,6 +1846,7 @@
887 + goto unresolvedType;
888 +
889 + mangleSourceName(TD->getIdentifier());
890 ++ writeAbiTags(TD);
891 + break;
892 + }
893 +
894 +@@ -1603,16 +1878,19 @@
895 + case Type::InjectedClassName:
896 + mangleSourceName(
897 + cast<InjectedClassNameType>(Ty)->getDecl()->getIdentifier());
898 ++ writeAbiTags(cast<InjectedClassNameType>(Ty)->getDecl());
899 + break;
900 +
901 + case Type::DependentName:
902 + mangleSourceName(cast<DependentNameType>(Ty)->getIdentifier());
903 ++ // writeAbiTags(cast<DependentNameType>(Ty));
904 + break;
905 +
906 + case Type::DependentTemplateSpecialization: {
907 + const DependentTemplateSpecializationType *DTST =
908 + cast<DependentTemplateSpecializationType>(Ty);
909 + mangleSourceName(DTST->getIdentifier());
910 ++ // writeAbiTags(DTST);
911 + mangleTemplateArgs(DTST->getArgs(), DTST->getNumArgs());
912 + break;
913 + }
914 +@@ -2070,7 +2348,9 @@
915 + case BuiltinType::Id:
916 + #include "clang/AST/BuiltinTypes.def"
917 + case BuiltinType::Dependent:
918 +- llvm_unreachable("mangling a placeholder type");
919 ++ if (!NullOut)
920 ++ llvm_unreachable("mangling a placeholder type");
921 ++ break;
922 + case BuiltinType::ObjCId:
923 + Out << "11objc_object";
924 + break;
925 +@@ -2546,7 +2826,11 @@
926 +
927 + void CXXNameMangler::mangleType(const TemplateSpecializationType *T) {
928 + if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) {
929 +- mangleName(TD, T->getArgs(), T->getNumArgs());
930 ++ // types only have explicit abi tags, no addition tags
931 ++ mangleTemplateName(TD,
932 ++ /* AdditionalAbiTags */ nullptr,
933 ++ /* ExcludeUnqualifiedName */ false,
934 ++ T->getArgs(), T->getNumArgs());
935 + } else {
936 + if (mangleSubstitution(QualType(T, 0)))
937 + return;
938 +@@ -2872,12 +3156,14 @@
939 + case Expr::PseudoObjectExprClass:
940 + case Expr::AtomicExprClass:
941 + {
942 +- // As bad as this diagnostic is, it's better than crashing.
943 +- DiagnosticsEngine &Diags = Context.getDiags();
944 +- unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
945 +- "cannot yet mangle expression type %0");
946 +- Diags.Report(E->getExprLoc(), DiagID)
947 +- << E->getStmtClassName() << E->getSourceRange();
948 ++ if (!NullOut) {
949 ++ // As bad as this diagnostic is, it's better than crashing.
950 ++ DiagnosticsEngine &Diags = Context.getDiags();
951 ++ unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
952 ++ "cannot yet mangle expression type %0");
953 ++ Diags.Report(E->getExprLoc(), DiagID)
954 ++ << E->getStmtClassName() << E->getSourceRange();
955 ++ }
956 + break;
957 + }
958 +
959 +@@ -4020,6 +4306,97 @@
960 + Substitutions[Ptr] = SeqID++;
961 + }
962 +
963 ++CXXNameMangler::AbiTagSet
964 ++CXXNameMangler::getTagsFromPrefixAndTemplateArguments(const NamedDecl *ND) {
965 ++ llvm::raw_null_ostream NullOutStream;
966 ++ CXXNameMangler TrackPrefixAndTemplateArguments(*this, NullOutStream);
967 ++
968 ++ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
969 ++ TrackPrefixAndTemplateArguments.mangleFunctionEncoding(
970 ++ FD, /* ExcludeUnqualifiedName */ true);
971 ++ } else {
972 ++ TrackPrefixAndTemplateArguments.mangleName(
973 ++ ND, /* ExcludeUnqualifiedName */ true);
974 ++ }
975 ++
976 ++ return std::move(
977 ++ TrackPrefixAndTemplateArguments.AbiTagsRoot.getUsedAbiTags());
978 ++}
979 ++
980 ++CXXNameMangler::AbiTagList
981 ++CXXNameMangler::makeAdditionalTagsForFunction(const FunctionDecl *FD) {
982 ++ // when derived abi tags are disabled there is no need to make any list
983 ++ if (DisableDerivedAbiTags)
984 ++ return AbiTagList();
985 ++
986 ++ AbiTagSet ImplicitlyAvailableTags =
987 ++ getTagsFromPrefixAndTemplateArguments(FD);
988 ++ AbiTagSet ReturnTypeTags;
989 ++
990 ++ {
991 ++ llvm::raw_null_ostream NullOutStream;
992 ++ CXXNameMangler TrackReturnTypeTags(*this, NullOutStream);
993 ++ TrackReturnTypeTags.disableDerivedAbiTags();
994 ++
995 ++ const FunctionProtoType *Proto =
996 ++ cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>());
997 ++ TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
998 ++ TrackReturnTypeTags.mangleType(Proto->getReturnType());
999 ++ TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
1000 ++
1001 ++ ReturnTypeTags =
1002 ++ std::move(TrackReturnTypeTags.AbiTagsRoot.getUsedAbiTags());
1003 ++ }
1004 ++
1005 ++ AbiTagList AdditionalAbiTags;
1006 ++
1007 ++ for (const auto &Tag : ReturnTypeTags) {
1008 ++ if (ImplicitlyAvailableTags.count(Tag) == 0)
1009 ++ AdditionalAbiTags.push_back(Tag);
1010 ++ }
1011 ++
1012 ++ return AdditionalAbiTags;
1013 ++}
1014 ++
1015 ++CXXNameMangler::AbiTagList
1016 ++CXXNameMangler::makeAdditionalTagsForVariable(const VarDecl *VD) {
1017 ++ // when derived abi tags are disabled there is no need to make any list
1018 ++ if (DisableDerivedAbiTags)
1019 ++ return AbiTagList();
1020 ++
1021 ++ AbiTagSet ImplicitlyAvailableTags =
1022 ++ getTagsFromPrefixAndTemplateArguments(VD);
1023 ++ AbiTagSet VariableTypeTags;
1024 ++
1025 ++ {
1026 ++ llvm::raw_null_ostream NullOutStream;
1027 ++ CXXNameMangler TrackVariableType(*this, NullOutStream);
1028 ++ TrackVariableType.disableDerivedAbiTags();
1029 ++
1030 ++ TrackVariableType.mangleType(VD->getType());
1031 ++
1032 ++ VariableTypeTags =
1033 ++ std::move(TrackVariableType.AbiTagsRoot.getUsedAbiTags());
1034 ++ }
1035 ++
1036 ++ AbiTagList AdditionalAbiTags;
1037 ++
1038 ++ for (const auto &Tag : VariableTypeTags) {
1039 ++ if (ImplicitlyAvailableTags.count(Tag) == 0)
1040 ++ AdditionalAbiTags.push_back(Tag);
1041 ++ }
1042 ++
1043 ++ return AdditionalAbiTags;
1044 ++}
1045 ++
1046 ++bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &C,
1047 ++ const VarDecl *VD) {
1048 ++ llvm::raw_null_ostream NullOutStream;
1049 ++ CXXNameMangler TrackAbiTags(C, NullOutStream, nullptr, true);
1050 ++ TrackAbiTags.mangle(VD);
1051 ++ return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
1052 ++}
1053 ++
1054 + //
1055 +
1056 + /// Mangles the name of the declaration D and emits that name to the given
1057 +@@ -4121,6 +4498,8 @@
1058 + // <special-name> ::= GV <object name> # Guard variable for one-time
1059 + // # initialization
1060 + CXXNameMangler Mangler(*this, Out);
1061 ++ // GCC 5.3.0 doesn't emit derived ABI tags for local names but that seems to
1062 ++ // be a bug that is fixed in trunk.
1063 + Mangler.getStream() << "_ZGV";
1064 + Mangler.mangleName(D);
1065 + }
1066 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDeclAttr.cpp llvm-3.8.0.src/tools/clang/lib/Sema/SemaDeclAttr.cpp
1067 +--- llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDeclAttr.cpp 2016-07-10 23:56:02.412319038 +0200
1068 ++++ llvm-3.8.0.src/tools/clang/lib/Sema/SemaDeclAttr.cpp 2016-07-10 23:59:08.413719568 +0200
1069 +@@ -4476,10 +4476,6 @@
1070 + D->addAttr(::new (S.Context)
1071 + AbiTagAttr(Attr.getRange(), S.Context, Tags.data(), Tags.size(),
1072 + Attr.getAttributeSpellingListIndex()));
1073 +-
1074 +- // FIXME: remove this warning as soon as mangled part is ready.
1075 +- S.Diag(Attr.getRange().getBegin(), diag::warn_attribute_ignored)
1076 +- << Attr.getName();
1077 + }
1078 +
1079 + static void handleARMInterruptAttr(Sema &S, Decl *D,
1080 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/test/CodeGenCXX/mangle-abi-tag.cpp llvm-3.8.0.src/tools/clang/test/CodeGenCXX/mangle-abi-tag.cpp
1081 +--- llvm-3.8.0.src.orig/tools/clang/test/CodeGenCXX/mangle-abi-tag.cpp 1970-01-01 01:00:00.000000000 +0100
1082 ++++ llvm-3.8.0.src/tools/clang/test/CodeGenCXX/mangle-abi-tag.cpp 2016-07-10 23:59:08.413719568 +0200
1083 +@@ -0,0 +1,146 @@
1084 ++// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - | FileCheck %s
1085 ++// RUN: %clang_cc1 %s -emit-llvm -triple i686-linux-gnu -std=c++11 -o - | FileCheck %s
1086 ++// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -std=c++11 -o - | FileCheck %s
1087 ++
1088 ++struct __attribute__((abi_tag("A", "B"))) A { };
1089 ++
1090 ++struct B: A { };
1091 ++
1092 ++template<class T>
1093 ++
1094 ++struct C {
1095 ++};
1096 ++
1097 ++struct D { A* p; };
1098 ++
1099 ++template<class T>
1100 ++struct __attribute__((abi_tag("C", "D"))) E {
1101 ++};
1102 ++
1103 ++struct __attribute__((abi_tag("A", "B"))) F { };
1104 ++
1105 ++A a1;
1106 ++// CHECK: @_Z2a1B1AB1B =
1107 ++
1108 ++__attribute__((abi_tag("C", "D")))
1109 ++A a2;
1110 ++// CHECK: @_Z2a2B1AB1BB1CB1D =
1111 ++
1112 ++B a3;
1113 ++// CHECK: @a3 =
1114 ++
1115 ++C<A> a4;
1116 ++// CHECK: @_Z2a4B1AB1B =
1117 ++
1118 ++D a5;
1119 ++// CHECK: @a5 =
1120 ++
1121 ++E<int> a6;
1122 ++// CHECK: @_Z2a6B1CB1D =
1123 ++
1124 ++E<A> a7;
1125 ++// CHECK: @_Z2a7B1AB1BB1CB1D =
1126 ++
1127 ++template<>
1128 ++struct E<float> {
1129 ++ static float a8;
1130 ++};
1131 ++float E<float>::a8;
1132 ++// CHECK: @_ZN1EB1CB1DIfE2a8E =
1133 ++
1134 ++template<>
1135 ++struct E<F> {
1136 ++ static bool a9;
1137 ++};
1138 ++bool E<F>::a9;
1139 ++// CHECK: @_ZN1EB1CB1DI1FB1AB1BE2a9E =
1140 ++
1141 ++struct __attribute__((abi_tag("A", "B"))) A10 {
1142 ++ virtual ~A10() {}
1143 ++} a10;
1144 ++// vtable
1145 ++// CHECK: @_ZTV3A10B1AB1B =
1146 ++// typeinfo
1147 ++// CHECK: @_ZTI3A10B1AB1B =
1148 ++
1149 ++// Local variables from f13.
1150 ++// f13()::L::foo[abi:C][abi:D]()::a[abi:A][abi:B]
1151 ++// CHECK-DAG: @_ZZZ3f13vEN1L3fooB1CB1DEvE1aB1AB1B =
1152 ++// guard variable for f13()::L::foo[abi:C][abi:D]()::a[abi:A][abi:B]
1153 ++// CHECK-DAG: @_ZGVZZ3f13vEN1L3fooB1CB1DEvE1aB1AB1B =
1154 ++
1155 ++__attribute__ ((abi_tag("C", "D")))
1156 ++void* f1() {
1157 ++ return 0;
1158 ++}
1159 ++// CHECK: define {{.*}} @_Z2f1B1CB1Dv(
1160 ++
1161 ++__attribute__ ((abi_tag("C", "D")))
1162 ++A* f2() {
1163 ++ return 0;
1164 ++}
1165 ++// CHECK: define {{.*}} @_Z2f2B1AB1BB1CB1Dv(
1166 ++
1167 ++B* f3() {
1168 ++ return 0;
1169 ++}
1170 ++// CHECK: define {{.*}} @_Z2f3v(
1171 ++
1172 ++C<A>* f4() {
1173 ++ return 0;
1174 ++}
1175 ++// CHECK: define {{.*}} @_Z2f4B1AB1Bv(
1176 ++
1177 ++D* f5() {
1178 ++ return 0;
1179 ++}
1180 ++// CHECK: define {{.*}} @_Z2f5v(
1181 ++
1182 ++E<char>* f6() {
1183 ++ return 0;
1184 ++}
1185 ++// CHECK: define {{.*}} @_Z2f6B1CB1Dv(
1186 ++
1187 ++E<A>* f7() {
1188 ++ return 0;
1189 ++}
1190 ++// CHECK: define {{.*}} @_Z2f7B1AB1BB1CB1Dv(
1191 ++
1192 ++void f8(E<A>*) {
1193 ++}
1194 ++// CHECK: define {{.*}} @_Z2f8P1EB1CB1DI1AB1AB1BE(
1195 ++
1196 ++inline namespace Names1 __attribute__((__abi_tag__)) {
1197 ++ class C1 {};
1198 ++}
1199 ++C1 f9() { return C1(); }
1200 ++// CHECK: @_Z2f9B6Names1v(
1201 ++
1202 ++inline namespace Names2 __attribute__((__abi_tag__("Tag1", "Tag2"))) {
1203 ++ class C2 {};
1204 ++}
1205 ++C2 f10() { return C2(); }
1206 ++// CHECK: @_Z3f10B4Tag1B4Tag2v(
1207 ++
1208 ++void __attribute__((abi_tag("A"))) f11(A) {}
1209 ++// f11[abi:A](A[abi:A][abi:B])
1210 ++// CHECK: define {{.*}} @_Z3f11B1A1AB1AB1B(
1211 ++
1212 ++A f12(A) { return A(); }
1213 ++// f12(A[abi:A][abi:B])
1214 ++// CHECK: define {{.*}} @_Z3f121AB1AB1B(
1215 ++
1216 ++inline void f13() {
1217 ++ struct L {
1218 ++ static E<int>* foo() {
1219 ++ static A10 a;
1220 ++ return 0;
1221 ++ }
1222 ++ };
1223 ++ L::foo();
1224 ++}
1225 ++void f11_test() {
1226 ++ f13();
1227 ++}
1228 ++// f13()::L::foo[abi:C][abi:D]()
1229 ++// CHECK: define linkonce_odr %struct.E* @_ZZ3f13vEN1L3fooB1CB1DEv(
1230 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp llvm-3.8.0.src/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp
1231 +--- llvm-3.8.0.src.orig/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp 2016-07-10 23:56:02.415319061 +0200
1232 ++++ llvm-3.8.0.src/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp 2016-07-10 23:59:08.413719568 +0200
1233 +@@ -16,28 +16,18 @@
1234 + // expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
1235 +
1236 + inline namespace N __attribute__((__abi_tag__)) {}
1237 +-// FIXME: remove this warning as soon as attribute fully supported.
1238 +-// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
1239 +
1240 + } // namespcace N2
1241 +
1242 + __attribute__((abi_tag("B", "A"))) extern int a1;
1243 +-// FIXME: remove this warning as soon as attribute fully supported.
1244 +-// expected-warning@-2 {{'abi_tag' attribute ignored}}
1245 +
1246 + __attribute__((abi_tag("A", "B"))) extern int a1;
1247 + // expected-note@-1 {{previous declaration is here}}
1248 +-// FIXME: remove this warning as soon as attribute fully supported.
1249 +-// expected-warning@-3 {{'abi_tag' attribute ignored}}
1250 +
1251 + __attribute__((abi_tag("A", "C"))) extern int a1;
1252 + // expected-error@-1 {{'abi_tag' C missing in original declaration}}
1253 +-// FIXME: remove this warning as soon as attribute fully supported.
1254 +-// expected-warning@-3 {{'abi_tag' attribute ignored}}
1255 +
1256 + extern int a2;
1257 + // expected-note@-1 {{previous declaration is here}}
1258 + __attribute__((abi_tag("A")))extern int a2;
1259 + // expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
1260 +-// FIXME: remove this warning as soon as attribute fully supported.
1261 +-// expected-warning@-3 {{'abi_tag' attribute ignored}}
1262
1263 diff --git a/sys-devel/llvm/files/clang-3.8-abi-tag-support-sema.patch b/sys-devel/llvm/files/clang-3.8-abi-tag-support-sema.patch
1264 new file mode 100644
1265 index 0000000..079f685
1266 --- /dev/null
1267 +++ b/sys-devel/llvm/files/clang-3.8-abi-tag-support-sema.patch
1268 @@ -0,0 +1,419 @@
1269 +diff -Nuar llvm-3.8.0.src.orig/clang/docs/ItaniumMangleAbiTags.rst llvm-3.8.0.src/clang/docs/ItaniumMangleAbiTags.rst
1270 +--- llvm-3.8.0.src.orig/clang/docs/ItaniumMangleAbiTags.rst 1970-01-01 01:00:00.000000000 +0100
1271 ++++ llvm-3.8.0.src/clang/docs/ItaniumMangleAbiTags.rst 2016-07-10 23:54:47.768756996 +0200
1272 +@@ -0,0 +1,101 @@
1273 ++========
1274 ++ABI tags
1275 ++========
1276 ++
1277 ++Introduction
1278 ++============
1279 ++
1280 ++This text tries to describe gcc semantic for mangling "abi_tag" attributes
1281 ++described in https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
1282 ++
1283 ++There is no guarantee the following rules are correct, complete or make sense
1284 ++in any way as they were determined empirically by experiments with gcc5.
1285 ++
1286 ++Declaration
1287 ++===========
1288 ++
1289 ++ABI tags are declared in an abi_tag attribute and can be applied to a
1290 ++function, variable, class or inline namespace declaration. The attribute takes
1291 ++one or more strings (called tags); the order does not matter.
1292 ++
1293 ++See https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html for
1294 ++details.
1295 ++
1296 ++Tags on an inline namespace are called "implicit tags", all other tags are
1297 ++"explicit tags".
1298 ++
1299 ++Mangling
1300 ++========
1301 ++
1302 ++All tags that are "active" on an <unqualified-name> are emitted after the
1303 ++<unqualified-name>, before <template-args> or <discriminator>, and are part of
1304 ++the same <substitution> the <unqualified-name> is.
1305 ++
1306 ++They are mangled as:
1307 ++
1308 ++ <abi-tags> ::= <abi-tag>* # sort by name
1309 ++ <abi-tag> ::= B <tag source-name>
1310 ++
1311 ++Example:
1312 ++
1313 ++ __attribute__((abi_tag("test")))
1314 ++ void Func();
1315 ++
1316 ++ gets mangled as: _Z4FuncB4testv (prettified as `Func[abi:test]()`)
1317 ++
1318 ++Active tags
1319 ++===========
1320 ++
1321 ++A namespace does not have any active tags. For types (class / struct / union /
1322 ++enum), the explicit tags are the active tags.
1323 ++
1324 ++For variables and functions, the active tags are the explicit tags plus any
1325 ++"required tags" which are not in the "available tags" set:
1326 ++
1327 ++ derived-tags := (required-tags - available-tags)
1328 ++ active-tags := explicit-tags + derived-tags
1329 ++
1330 ++Required tags for a function
1331 ++============================
1332 ++
1333 ++If a function is used as a local scope for another name, and is part of
1334 ++another function as local scope, it doesn't have any required tags.
1335 ++
1336 ++If a function is used as a local scope for a guard variable name, it doesn't
1337 ++have any required tags.
1338 ++
1339 ++Otherwise the function requires any implicit or explicit tag used in the name
1340 ++for the return type.
1341 ++
1342 ++Example:
1343 ++ namespace A {
1344 ++ inline namespace B __attribute__((abi_tag)) {
1345 ++ struct C { int x; };
1346 ++ }
1347 ++ }
1348 ++
1349 ++ A::C foo();
1350 ++
1351 ++ gets mangled as: _Z3fooB1Bv (prettified as `foo[abi:B]()`)
1352 ++
1353 ++Required tags for a variable
1354 ++============================
1355 ++
1356 ++A variable requires any implicit or explicit tag used in its type.
1357 ++
1358 ++Available tags
1359 ++==============
1360 ++
1361 ++All tags used in the prefix and in the template arguments for a name are
1362 ++available. Also, for functions, all tags from the <bare-function-type>
1363 ++(which might include the return type for template functions) are available.
1364 ++
1365 ++For <local-name>s all active tags used in the local part (<function-
1366 ++encoding>) are available, but not implicit tags which were not active.
1367 ++
1368 ++Implicit and explicit tags used in the <unqualified-name> for a function (as
1369 ++in the type of a cast operator) are NOT available.
1370 ++
1371 ++Example: a cast operator to std::string (which is
1372 ++std::__cxx11::basic_string<...>) will use 'cxx11' as an active tag, as it is
1373 ++required from the return type `std::string` but not available.
1374 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/docs/ItaniumMangleAbiTags.rst llvm-3.8.0.src/tools/clang/docs/ItaniumMangleAbiTags.rst
1375 +--- llvm-3.8.0.src.orig/tools/clang/docs/ItaniumMangleAbiTags.rst 1970-01-01 01:00:00.000000000 +0100
1376 ++++ llvm-3.8.0.src/tools/clang/docs/ItaniumMangleAbiTags.rst 2016-07-10 23:55:02.544868256 +0200
1377 +@@ -0,0 +1,101 @@
1378 ++========
1379 ++ABI tags
1380 ++========
1381 ++
1382 ++Introduction
1383 ++============
1384 ++
1385 ++This text tries to describe gcc semantic for mangling "abi_tag" attributes
1386 ++described in https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
1387 ++
1388 ++There is no guarantee the following rules are correct, complete or make sense
1389 ++in any way as they were determined empirically by experiments with gcc5.
1390 ++
1391 ++Declaration
1392 ++===========
1393 ++
1394 ++ABI tags are declared in an abi_tag attribute and can be applied to a
1395 ++function, variable, class or inline namespace declaration. The attribute takes
1396 ++one or more strings (called tags); the order does not matter.
1397 ++
1398 ++See https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html for
1399 ++details.
1400 ++
1401 ++Tags on an inline namespace are called "implicit tags", all other tags are
1402 ++"explicit tags".
1403 ++
1404 ++Mangling
1405 ++========
1406 ++
1407 ++All tags that are "active" on an <unqualified-name> are emitted after the
1408 ++<unqualified-name>, before <template-args> or <discriminator>, and are part of
1409 ++the same <substitution> the <unqualified-name> is.
1410 ++
1411 ++They are mangled as:
1412 ++
1413 ++ <abi-tags> ::= <abi-tag>* # sort by name
1414 ++ <abi-tag> ::= B <tag source-name>
1415 ++
1416 ++Example:
1417 ++
1418 ++ __attribute__((abi_tag("test")))
1419 ++ void Func();
1420 ++
1421 ++ gets mangled as: _Z4FuncB4testv (prettified as `Func[abi:test]()`)
1422 ++
1423 ++Active tags
1424 ++===========
1425 ++
1426 ++A namespace does not have any active tags. For types (class / struct / union /
1427 ++enum), the explicit tags are the active tags.
1428 ++
1429 ++For variables and functions, the active tags are the explicit tags plus any
1430 ++"required tags" which are not in the "available tags" set:
1431 ++
1432 ++ derived-tags := (required-tags - available-tags)
1433 ++ active-tags := explicit-tags + derived-tags
1434 ++
1435 ++Required tags for a function
1436 ++============================
1437 ++
1438 ++If a function is used as a local scope for another name, and is part of
1439 ++another function as local scope, it doesn't have any required tags.
1440 ++
1441 ++If a function is used as a local scope for a guard variable name, it doesn't
1442 ++have any required tags.
1443 ++
1444 ++Otherwise the function requires any implicit or explicit tag used in the name
1445 ++for the return type.
1446 ++
1447 ++Example:
1448 ++ namespace A {
1449 ++ inline namespace B __attribute__((abi_tag)) {
1450 ++ struct C { int x; };
1451 ++ }
1452 ++ }
1453 ++
1454 ++ A::C foo();
1455 ++
1456 ++ gets mangled as: _Z3fooB1Bv (prettified as `foo[abi:B]()`)
1457 ++
1458 ++Required tags for a variable
1459 ++============================
1460 ++
1461 ++A variable requires any implicit or explicit tag used in its type.
1462 ++
1463 ++Available tags
1464 ++==============
1465 ++
1466 ++All tags used in the prefix and in the template arguments for a name are
1467 ++available. Also, for functions, all tags from the <bare-function-type>
1468 ++(which might include the return type for template functions) are available.
1469 ++
1470 ++For <local-name>s all active tags used in the local part (<function-
1471 ++encoding>) are available, but not implicit tags which were not active.
1472 ++
1473 ++Implicit and explicit tags used in the <unqualified-name> for a function (as
1474 ++in the type of a cast operator) are NOT available.
1475 ++
1476 ++Example: a cast operator to std::string (which is
1477 ++std::__cxx11::basic_string<...>) will use 'cxx11' as an active tag, as it is
1478 ++required from the return type `std::string` but not available.
1479 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/AttrDocs.td llvm-3.8.0.src/tools/clang/include/clang/Basic/AttrDocs.td
1480 +--- llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/AttrDocs.td 2015-12-02 22:58:08.000000000 +0100
1481 ++++ llvm-3.8.0.src/tools/clang/include/clang/Basic/AttrDocs.td 2016-07-10 23:55:02.545868263 +0200
1482 +@@ -1859,3 +1859,16 @@
1483 +
1484 + }];
1485 + }
1486 ++
1487 ++def AbiTagsDocs : Documentation {
1488 ++ let Content = [{
1489 ++The ``abi_tag`` attribute can be applied to a function, variable, class or
1490 ++inline namespace declaration to modify the mangled name of the entity. It gives
1491 ++the ability to distinguish between different versions of the same entity but
1492 ++with different ABI versions supported. For example, a newer version of a class
1493 ++could have a different set of data members and thus have a different size. Using
1494 ++the ``abi_tag`` attribute, it is possible to have different mangled names for
1495 ++a global variable of the class type. Therefor, the old code could keep using
1496 ++the old manged name and the new code will use the new mangled name with tags.
1497 ++ }];
1498 ++}
1499 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/Attr.td llvm-3.8.0.src/tools/clang/include/clang/Basic/Attr.td
1500 +--- llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/Attr.td 2015-12-02 22:58:08.000000000 +0100
1501 ++++ llvm-3.8.0.src/tools/clang/include/clang/Basic/Attr.td 2016-07-10 23:55:02.544868256 +0200
1502 +@@ -349,6 +349,14 @@
1503 + // Attributes begin here
1504 + //
1505 +
1506 ++def AbiTag : Attr {
1507 ++ let Spellings = [GCC<"abi_tag">];
1508 ++ let Args = [VariadicStringArgument<"Tags">];
1509 ++ let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
1510 ++ "ExpectedStructClassVariableFunctionOrInlineNamespace">;
1511 ++ let Documentation = [AbiTagsDocs];
1512 ++}
1513 ++
1514 + def AddressSpace : TypeAttr {
1515 + let Spellings = [GNU<"address_space">];
1516 + let Args = [IntArgument<"AddressSpace">];
1517 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td llvm-3.8.0.src/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
1518 +--- llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td 2016-01-09 13:53:17.000000000 +0100
1519 ++++ llvm-3.8.0.src/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td 2016-07-10 23:55:02.547868278 +0200
1520 +@@ -2434,7 +2434,8 @@
1521 + "Objective-C instance methods|init methods of interface or class extension declarations|"
1522 + "variables, functions and classes|Objective-C protocols|"
1523 + "functions and global variables|structs, unions, and typedefs|structs and typedefs|"
1524 +- "interface or protocol declarations|kernel functions|non-K&R-style functions}1">,
1525 ++ "interface or protocol declarations|kernel functions|non-K&R-style functions|"
1526 ++ "structs, classes, variables, functions, and inline namespaces}1">,
1527 + InGroup<IgnoredAttributes>;
1528 + def err_attribute_wrong_decl_type : Error<warn_attribute_wrong_decl_type.Text>;
1529 + def warn_type_attribute_wrong_type : Warning<
1530 +@@ -4144,6 +4145,13 @@
1531 + def err_redefinition_extern_inline : Error<
1532 + "redefinition of a 'extern inline' function %0 is not supported in "
1533 + "%select{C99 mode|C++}1">;
1534 ++def warn_attr_abi_tag_namespace : Warning<
1535 ++ "'abi_tag' attribute on %select{non-inline|anonymous}0 namespace ignored">,
1536 ++ InGroup<IgnoredAttributes>;
1537 ++def err_abi_tag_on_redeclaration : Error<
1538 ++ "cannot add 'abi_tag' attribute in a redeclaration">;
1539 ++def err_new_abi_tag_on_redeclaration : Error<
1540 ++ "'abi_tag' %0 missing in original declaration">;
1541 +
1542 + def note_deleted_dtor_no_operator_delete : Note<
1543 + "virtual destructor requires an unambiguous, accessible 'operator delete'">;
1544 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/include/clang/Sema/AttributeList.h llvm-3.8.0.src/tools/clang/include/clang/Sema/AttributeList.h
1545 +--- llvm-3.8.0.src.orig/tools/clang/include/clang/Sema/AttributeList.h 2015-12-02 18:07:30.000000000 +0100
1546 ++++ llvm-3.8.0.src/tools/clang/include/clang/Sema/AttributeList.h 2016-07-10 23:55:02.548868286 +0200
1547 +@@ -855,7 +855,8 @@
1548 + ExpectedStructOrTypedef,
1549 + ExpectedObjectiveCInterfaceOrProtocol,
1550 + ExpectedKernelFunction,
1551 +- ExpectedFunctionWithProtoType
1552 ++ ExpectedFunctionWithProtoType,
1553 ++ ExpectedStructClassVariableFunctionOrInlineNamespace
1554 + };
1555 +
1556 + } // end namespace clang
1557 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDeclAttr.cpp llvm-3.8.0.src/tools/clang/lib/Sema/SemaDeclAttr.cpp
1558 +--- llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDeclAttr.cpp 2016-01-13 02:07:35.000000000 +0100
1559 ++++ llvm-3.8.0.src/tools/clang/lib/Sema/SemaDeclAttr.cpp 2016-07-10 23:55:02.552868316 +0200
1560 +@@ -4446,6 +4446,42 @@
1561 + Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
1562 + }
1563 +
1564 ++static void handleAbiTagAttr(Sema &S, Decl *D, const AttributeList &Attr) {
1565 ++ SmallVector<std::string, 4> Tags;
1566 ++ for (unsigned I = 0, E = Attr.getNumArgs(); I != E; ++I) {
1567 ++ StringRef Tag;
1568 ++ if (!S.checkStringLiteralArgumentAttr(Attr, I, Tag))
1569 ++ return;
1570 ++ Tags.push_back(Tag);
1571 ++ }
1572 ++
1573 ++ if (const auto *NS = dyn_cast<NamespaceDecl>(D)) {
1574 ++ if (!NS->isInline()) {
1575 ++ S.Diag(Attr.getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
1576 ++ return;
1577 ++ }
1578 ++ if (NS->isAnonymousNamespace()) {
1579 ++ S.Diag(Attr.getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
1580 ++ return;
1581 ++ }
1582 ++ if (Attr.getNumArgs() == 0)
1583 ++ Tags.push_back(NS->getName());
1584 ++ } else if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
1585 ++ return;
1586 ++
1587 ++ // Store tags sorted and without duplicates.
1588 ++ std::sort(Tags.begin(), Tags.end());
1589 ++ Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
1590 ++
1591 ++ D->addAttr(::new (S.Context)
1592 ++ AbiTagAttr(Attr.getRange(), S.Context, Tags.data(), Tags.size(),
1593 ++ Attr.getAttributeSpellingListIndex()));
1594 ++
1595 ++ // FIXME: remove this warning as soon as mangled part is ready.
1596 ++ S.Diag(Attr.getRange().getBegin(), diag::warn_attribute_ignored)
1597 ++ << Attr.getName();
1598 ++}
1599 ++
1600 + static void handleARMInterruptAttr(Sema &S, Decl *D,
1601 + const AttributeList &Attr) {
1602 + // Check the attribute arguments.
1603 +@@ -5360,6 +5396,9 @@
1604 + case AttributeList::AT_Thread:
1605 + handleDeclspecThreadAttr(S, D, Attr);
1606 + break;
1607 ++ case AttributeList::AT_AbiTag:
1608 ++ handleAbiTagAttr(S, D, Attr);
1609 ++ break;
1610 +
1611 + // Thread safety attributes:
1612 + case AttributeList::AT_AssertExclusiveLock:
1613 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDecl.cpp llvm-3.8.0.src/tools/clang/lib/Sema/SemaDecl.cpp
1614 +--- llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDecl.cpp 2016-01-11 23:41:53.000000000 +0100
1615 ++++ llvm-3.8.0.src/tools/clang/lib/Sema/SemaDecl.cpp 2016-07-10 23:55:02.551868308 +0200
1616 +@@ -2396,6 +2396,24 @@
1617 + }
1618 + }
1619 +
1620 ++ // Re-declaration cannot add abi_tag's.
1621 ++ if (const auto *NewAbiTagAttr = New->getAttr<AbiTagAttr>()) {
1622 ++ if (const auto *OldAbiTagAttr = Old->getAttr<AbiTagAttr>()) {
1623 ++ for (const auto &NewTag : NewAbiTagAttr->tags()) {
1624 ++ if (std::find(OldAbiTagAttr->tags_begin(), OldAbiTagAttr->tags_end(),
1625 ++ NewTag) == OldAbiTagAttr->tags_end()) {
1626 ++ Diag(NewAbiTagAttr->getLocation(),
1627 ++ diag::err_new_abi_tag_on_redeclaration)
1628 ++ << NewTag;
1629 ++ Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
1630 ++ }
1631 ++ }
1632 ++ } else {
1633 ++ Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
1634 ++ Diag(Old->getLocation(), diag::note_previous_declaration);
1635 ++ }
1636 ++ }
1637 ++
1638 + if (!Old->hasAttrs())
1639 + return;
1640 +
1641 +diff -Nuar llvm-3.8.0.src.orig/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp llvm-3.8.0.src/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp
1642 +--- llvm-3.8.0.src.orig/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp 1970-01-01 01:00:00.000000000 +0100
1643 ++++ llvm-3.8.0.src/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp 2016-07-10 23:55:02.552868316 +0200
1644 +@@ -0,0 +1,43 @@
1645 ++// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
1646 ++
1647 ++namespace N1 {
1648 ++
1649 ++namespace __attribute__((__abi_tag__)) {}
1650 ++// expected-warning@-1 {{'abi_tag' attribute on non-inline namespace ignored}}
1651 ++
1652 ++namespace N __attribute__((__abi_tag__)) {}
1653 ++// expected-warning@-1 {{'abi_tag' attribute on non-inline namespace ignored}}
1654 ++
1655 ++} // namespace N1
1656 ++
1657 ++namespace N2 {
1658 ++
1659 ++inline namespace __attribute__((__abi_tag__)) {}
1660 ++// expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
1661 ++
1662 ++inline namespace N __attribute__((__abi_tag__)) {}
1663 ++// FIXME: remove this warning as soon as attribute fully supported.
1664 ++// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
1665 ++
1666 ++} // namespcace N2
1667 ++
1668 ++__attribute__((abi_tag("B", "A"))) extern int a1;
1669 ++// FIXME: remove this warning as soon as attribute fully supported.
1670 ++// expected-warning@-2 {{'abi_tag' attribute ignored}}
1671 ++
1672 ++__attribute__((abi_tag("A", "B"))) extern int a1;
1673 ++// expected-note@-1 {{previous declaration is here}}
1674 ++// FIXME: remove this warning as soon as attribute fully supported.
1675 ++// expected-warning@-3 {{'abi_tag' attribute ignored}}
1676 ++
1677 ++__attribute__((abi_tag("A", "C"))) extern int a1;
1678 ++// expected-error@-1 {{'abi_tag' C missing in original declaration}}
1679 ++// FIXME: remove this warning as soon as attribute fully supported.
1680 ++// expected-warning@-3 {{'abi_tag' attribute ignored}}
1681 ++
1682 ++extern int a2;
1683 ++// expected-note@-1 {{previous declaration is here}}
1684 ++__attribute__((abi_tag("A")))extern int a2;
1685 ++// expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
1686 ++// FIXME: remove this warning as soon as attribute fully supported.
1687 ++// expected-warning@-3 {{'abi_tag' attribute ignored}}
1688
1689 diff --git a/sys-devel/llvm/llvm-3.8.1-r1.ebuild b/sys-devel/llvm/llvm-3.8.1-r1.ebuild
1690 index 60e6d5e..802911c 100644
1691 --- a/sys-devel/llvm/llvm-3.8.1-r1.ebuild
1692 +++ b/sys-devel/llvm/llvm-3.8.1-r1.ebuild
1693 @@ -225,6 +225,10 @@ src_prepare() {
1694 # https://llvm.org/bugs/show_bug.cgi?id=26651
1695 eapply "${FILESDIR}"/clang-3.8-compiler-rt-fbsd.patch
1696
1697 + # Backport abi-tag support, bug #571600
1698 + eapply "${FILESDIR}"/clang-3.8-abi-tag-support-sema.patch
1699 + eapply "${FILESDIR}"/clang-3.8-abi-tag-support-mangler.patch
1700 +
1701 pushd projects/compiler-rt >/dev/null || die
1702
1703 # Fix WX sections, bug #421527