Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 571600 | Differences between
and this patch

Collapse All | Expand All

(-)llvm-3.8.0.src.orig/clang/docs/ItaniumMangleAbiTags.rst (+101 lines)
Line 0 Link Here
1
========
2
ABI tags
3
========
4
5
Introduction
6
============
7
8
This text tries to describe gcc semantic for mangling "abi_tag" attributes
9
described in https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
10
11
There is no guarantee the following rules are correct, complete or make sense
12
in any way as they were determined empirically by experiments with gcc5.
13
14
Declaration
15
===========
16
17
ABI tags are declared in an abi_tag attribute and can be applied to a
18
function, variable, class or inline namespace declaration. The attribute takes
19
one or more strings (called tags); the order does not matter.
20
21
See https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html for
22
details.
23
24
Tags on an inline namespace are called "implicit tags", all other tags are
25
"explicit tags".
26
27
Mangling
28
========
29
30
All tags that are "active" on an <unqualified-name> are emitted after the
31
<unqualified-name>, before <template-args> or <discriminator>, and are part of
32
the same <substitution> the <unqualified-name> is.
33
34
They are mangled as:
35
36
    <abi-tags> ::= <abi-tag>*   # sort by name
37
    <abi-tag> ::= B <tag source-name>
38
39
Example:
40
41
    __attribute__((abi_tag("test")))
42
    void Func();
43
44
    gets mangled as: _Z4FuncB4testv (prettified as `Func[abi:test]()`)
45
46
Active tags
47
===========
48
49
A namespace does not have any active tags. For types (class / struct / union /
50
enum), the explicit tags are the active tags.
51
52
For variables and functions, the active tags are the explicit tags plus any
53
"required tags" which are not in the "available tags" set:
54
55
    derived-tags := (required-tags - available-tags)
56
    active-tags := explicit-tags + derived-tags
57
58
Required tags for a function
59
============================
60
61
If a function is used as a local scope for another name, and is part of
62
another function as local scope, it doesn't have any required tags.
63
64
If a function is used as a local scope for a guard variable name, it doesn't
65
have any required tags.
66
67
Otherwise the function requires any implicit or explicit tag used in the name
68
for the return type.
69
70
Example:
71
    namespace A {
72
      inline namespace B __attribute__((abi_tag)) {
73
        struct C { int x; };
74
      }
75
    }
76
77
    A::C foo();
78
79
    gets mangled as: _Z3fooB1Bv (prettified as `foo[abi:B]()`)
80
81
Required tags for a variable
82
============================
83
84
A variable requires any implicit or explicit tag used in its type.
85
86
Available tags
87
==============
88
89
All tags used in the prefix and in the template arguments for a name are
90
available. Also, for functions, all tags from the <bare-function-type>
91
(which might include the return type for template functions) are available.
92
93
For <local-name>s all active tags used in the local part (<function-
94
encoding>) are available, but not implicit tags which were not active.
95
96
Implicit and explicit tags used in the <unqualified-name> for a function (as
97
in the type of a cast operator) are NOT available.
98
99
Example: a cast operator to std::string (which is
100
std::__cxx11::basic_string<...>) will use 'cxx11' as an active tag, as it is
101
required from the return type `std::string` but not available.
(-)llvm-3.8.0.src.orig/tools/clang/docs/ItaniumMangleAbiTags.rst (+101 lines)
Line 0 Link Here
1
========
2
ABI tags
3
========
4
5
Introduction
6
============
7
8
This text tries to describe gcc semantic for mangling "abi_tag" attributes
9
described in https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
10
11
There is no guarantee the following rules are correct, complete or make sense
12
in any way as they were determined empirically by experiments with gcc5.
13
14
Declaration
15
===========
16
17
ABI tags are declared in an abi_tag attribute and can be applied to a
18
function, variable, class or inline namespace declaration. The attribute takes
19
one or more strings (called tags); the order does not matter.
20
21
See https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html for
22
details.
23
24
Tags on an inline namespace are called "implicit tags", all other tags are
25
"explicit tags".
26
27
Mangling
28
========
29
30
All tags that are "active" on an <unqualified-name> are emitted after the
31
<unqualified-name>, before <template-args> or <discriminator>, and are part of
32
the same <substitution> the <unqualified-name> is.
33
34
They are mangled as:
35
36
    <abi-tags> ::= <abi-tag>*   # sort by name
37
    <abi-tag> ::= B <tag source-name>
38
39
Example:
40
41
    __attribute__((abi_tag("test")))
42
    void Func();
43
44
    gets mangled as: _Z4FuncB4testv (prettified as `Func[abi:test]()`)
45
46
Active tags
47
===========
48
49
A namespace does not have any active tags. For types (class / struct / union /
50
enum), the explicit tags are the active tags.
51
52
For variables and functions, the active tags are the explicit tags plus any
53
"required tags" which are not in the "available tags" set:
54
55
    derived-tags := (required-tags - available-tags)
56
    active-tags := explicit-tags + derived-tags
57
58
Required tags for a function
59
============================
60
61
If a function is used as a local scope for another name, and is part of
62
another function as local scope, it doesn't have any required tags.
63
64
If a function is used as a local scope for a guard variable name, it doesn't
65
have any required tags.
66
67
Otherwise the function requires any implicit or explicit tag used in the name
68
for the return type.
69
70
Example:
71
    namespace A {
72
      inline namespace B __attribute__((abi_tag)) {
73
        struct C { int x; };
74
      }
75
    }
76
77
    A::C foo();
78
79
    gets mangled as: _Z3fooB1Bv (prettified as `foo[abi:B]()`)
80
81
Required tags for a variable
82
============================
83
84
A variable requires any implicit or explicit tag used in its type.
85
86
Available tags
87
==============
88
89
All tags used in the prefix and in the template arguments for a name are
90
available. Also, for functions, all tags from the <bare-function-type>
91
(which might include the return type for template functions) are available.
92
93
For <local-name>s all active tags used in the local part (<function-
94
encoding>) are available, but not implicit tags which were not active.
95
96
Implicit and explicit tags used in the <unqualified-name> for a function (as
97
in the type of a cast operator) are NOT available.
98
99
Example: a cast operator to std::string (which is
100
std::__cxx11::basic_string<...>) will use 'cxx11' as an active tag, as it is
101
required from the return type `std::string` but not available.
(-)llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/AttrDocs.td (+13 lines)
Lines 1859-1861 Link Here
1859
1859
1860
  }];
1860
  }];
1861
}
1861
}
1862
1863
def AbiTagsDocs : Documentation {
1864
  let Content = [{
1865
The ``abi_tag`` attribute can be applied to a function, variable, class or
1866
inline namespace declaration to modify the mangled name of the entity. It gives
1867
the ability to distinguish between different versions of the same entity but
1868
with different ABI versions supported. For example, a newer version of a class
1869
could have a different set of data members and thus have a different size. Using
1870
the ``abi_tag`` attribute, it is possible to have different mangled names for
1871
a global variable of the class type. Therefor, the old code could keep using
1872
the old manged name and the new code will use the new mangled name with tags.
1873
  }];
1874
}
(-)llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/Attr.td (+8 lines)
Lines 349-354 Link Here
349
// Attributes begin here
349
// Attributes begin here
350
//
350
//
351
351
352
def AbiTag : Attr {
353
  let Spellings = [GCC<"abi_tag">];
354
  let Args = [VariadicStringArgument<"Tags">];
355
  let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
356
      "ExpectedStructClassVariableFunctionOrInlineNamespace">;
357
  let Documentation = [AbiTagsDocs];
358
}
359
352
def AddressSpace : TypeAttr {
360
def AddressSpace : TypeAttr {
353
  let Spellings = [GNU<"address_space">];
361
  let Spellings = [GNU<"address_space">];
354
  let Args = [IntArgument<"AddressSpace">];
362
  let Args = [IntArgument<"AddressSpace">];
(-)llvm-3.8.0.src.orig/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td (-1 / +9 lines)
Lines 2434-2440 Link Here
2434
  "Objective-C instance methods|init methods of interface or class extension declarations|"
2434
  "Objective-C instance methods|init methods of interface or class extension declarations|"
2435
  "variables, functions and classes|Objective-C protocols|"
2435
  "variables, functions and classes|Objective-C protocols|"
2436
  "functions and global variables|structs, unions, and typedefs|structs and typedefs|"
2436
  "functions and global variables|structs, unions, and typedefs|structs and typedefs|"
2437
  "interface or protocol declarations|kernel functions|non-K&R-style functions}1">,
2437
  "interface or protocol declarations|kernel functions|non-K&R-style functions|"
2438
  "structs, classes, variables, functions, and inline namespaces}1">,
2438
  InGroup<IgnoredAttributes>;
2439
  InGroup<IgnoredAttributes>;
2439
def err_attribute_wrong_decl_type : Error<warn_attribute_wrong_decl_type.Text>;
2440
def err_attribute_wrong_decl_type : Error<warn_attribute_wrong_decl_type.Text>;
2440
def warn_type_attribute_wrong_type : Warning<
2441
def warn_type_attribute_wrong_type : Warning<
Lines 4144-4149 Link Here
4144
def err_redefinition_extern_inline : Error<
4145
def err_redefinition_extern_inline : Error<
4145
  "redefinition of a 'extern inline' function %0 is not supported in "
4146
  "redefinition of a 'extern inline' function %0 is not supported in "
4146
  "%select{C99 mode|C++}1">;
4147
  "%select{C99 mode|C++}1">;
4148
def warn_attr_abi_tag_namespace : Warning<
4149
  "'abi_tag' attribute on %select{non-inline|anonymous}0 namespace ignored">,
4150
  InGroup<IgnoredAttributes>;
4151
def err_abi_tag_on_redeclaration : Error<
4152
  "cannot add 'abi_tag' attribute in a redeclaration">;
4153
def err_new_abi_tag_on_redeclaration : Error<
4154
  "'abi_tag' %0 missing in original declaration">;
4147
4155
4148
def note_deleted_dtor_no_operator_delete : Note<
4156
def note_deleted_dtor_no_operator_delete : Note<
4149
  "virtual destructor requires an unambiguous, accessible 'operator delete'">;
4157
  "virtual destructor requires an unambiguous, accessible 'operator delete'">;
(-)llvm-3.8.0.src.orig/tools/clang/include/clang/Sema/AttributeList.h (-1 / +2 lines)
Lines 855-861 Link Here
855
  ExpectedStructOrTypedef,
855
  ExpectedStructOrTypedef,
856
  ExpectedObjectiveCInterfaceOrProtocol,
856
  ExpectedObjectiveCInterfaceOrProtocol,
857
  ExpectedKernelFunction,
857
  ExpectedKernelFunction,
858
  ExpectedFunctionWithProtoType
858
  ExpectedFunctionWithProtoType,
859
  ExpectedStructClassVariableFunctionOrInlineNamespace
859
};
860
};
860
861
861
}  // end namespace clang
862
}  // end namespace clang
(-)llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDeclAttr.cpp (+39 lines)
Lines 4446-4451 Link Here
4446
      Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
4446
      Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
4447
}
4447
}
4448
4448
4449
static void handleAbiTagAttr(Sema &S, Decl *D, const AttributeList &Attr) {
4450
  SmallVector<std::string, 4> Tags;
4451
  for (unsigned I = 0, E = Attr.getNumArgs(); I != E; ++I) {
4452
    StringRef Tag;
4453
    if (!S.checkStringLiteralArgumentAttr(Attr, I, Tag))
4454
      return;
4455
    Tags.push_back(Tag);
4456
  }
4457
4458
  if (const auto *NS = dyn_cast<NamespaceDecl>(D)) {
4459
    if (!NS->isInline()) {
4460
      S.Diag(Attr.getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
4461
      return;
4462
    }
4463
    if (NS->isAnonymousNamespace()) {
4464
      S.Diag(Attr.getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
4465
      return;
4466
    }
4467
    if (Attr.getNumArgs() == 0)
4468
      Tags.push_back(NS->getName());
4469
  } else if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
4470
    return;
4471
4472
  // Store tags sorted and without duplicates.
4473
  std::sort(Tags.begin(), Tags.end());
4474
  Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
4475
4476
  D->addAttr(::new (S.Context)
4477
             AbiTagAttr(Attr.getRange(), S.Context, Tags.data(), Tags.size(),
4478
                        Attr.getAttributeSpellingListIndex()));
4479
4480
  // FIXME: remove this warning as soon as mangled part is ready.
4481
  S.Diag(Attr.getRange().getBegin(), diag::warn_attribute_ignored)
4482
        << Attr.getName();
4483
}
4484
4449
static void handleARMInterruptAttr(Sema &S, Decl *D,
4485
static void handleARMInterruptAttr(Sema &S, Decl *D,
4450
                                   const AttributeList &Attr) {
4486
                                   const AttributeList &Attr) {
4451
  // Check the attribute arguments.
4487
  // Check the attribute arguments.
Lines 5360-5365 Link Here
5360
  case AttributeList::AT_Thread:
5396
  case AttributeList::AT_Thread:
5361
    handleDeclspecThreadAttr(S, D, Attr);
5397
    handleDeclspecThreadAttr(S, D, Attr);
5362
    break;
5398
    break;
5399
  case AttributeList::AT_AbiTag:
5400
    handleAbiTagAttr(S, D, Attr);
5401
    break;
5363
5402
5364
  // Thread safety attributes:
5403
  // Thread safety attributes:
5365
  case AttributeList::AT_AssertExclusiveLock:
5404
  case AttributeList::AT_AssertExclusiveLock:
(-)llvm-3.8.0.src.orig/tools/clang/lib/Sema/SemaDecl.cpp (+18 lines)
Lines 2396-2401 Link Here
2396
    }
2396
    }
2397
  }
2397
  }
2398
2398
2399
  // Re-declaration cannot add abi_tag's.
2400
  if (const auto *NewAbiTagAttr = New->getAttr<AbiTagAttr>()) {
2401
    if (const auto *OldAbiTagAttr = Old->getAttr<AbiTagAttr>()) {
2402
      for (const auto &NewTag : NewAbiTagAttr->tags()) {
2403
        if (std::find(OldAbiTagAttr->tags_begin(), OldAbiTagAttr->tags_end(),
2404
                      NewTag) == OldAbiTagAttr->tags_end()) {
2405
          Diag(NewAbiTagAttr->getLocation(),
2406
               diag::err_new_abi_tag_on_redeclaration)
2407
              << NewTag;
2408
          Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
2409
        }
2410
      }
2411
    } else {
2412
      Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
2413
      Diag(Old->getLocation(), diag::note_previous_declaration);
2414
    }
2415
  }
2416
2399
  if (!Old->hasAttrs())
2417
  if (!Old->hasAttrs())
2400
    return;
2418
    return;
2401
2419
(-)llvm-3.8.0.src.orig/tools/clang/test/SemaCXX/attr-abi-tag-syntax.cpp (+43 lines)
Line 0 Link Here
1
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2
3
namespace N1 {
4
5
namespace __attribute__((__abi_tag__)) {}
6
// expected-warning@-1 {{'abi_tag' attribute on non-inline namespace ignored}}
7
8
namespace N __attribute__((__abi_tag__)) {}
9
// expected-warning@-1 {{'abi_tag' attribute on non-inline namespace ignored}}
10
11
} // namespace N1
12
13
namespace N2 {
14
15
inline namespace __attribute__((__abi_tag__)) {}
16
// expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
17
18
inline namespace N __attribute__((__abi_tag__)) {}
19
// FIXME: remove this warning as soon as attribute fully supported.
20
// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
21
22
} // namespcace N2
23
24
__attribute__((abi_tag("B", "A"))) extern int a1;
25
// FIXME: remove this warning as soon as attribute fully supported.
26
// expected-warning@-2 {{'abi_tag' attribute ignored}}
27
28
__attribute__((abi_tag("A", "B"))) extern int a1;
29
// expected-note@-1 {{previous declaration is here}}
30
// FIXME: remove this warning as soon as attribute fully supported.
31
// expected-warning@-3 {{'abi_tag' attribute ignored}}
32
33
__attribute__((abi_tag("A", "C"))) extern int a1;
34
// expected-error@-1 {{'abi_tag' C missing in original declaration}}
35
// FIXME: remove this warning as soon as attribute fully supported.
36
// expected-warning@-3 {{'abi_tag' attribute ignored}}
37
38
extern int a2;
39
// expected-note@-1 {{previous declaration is here}}
40
__attribute__((abi_tag("A")))extern int a2;
41
// expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
42
// FIXME: remove this warning as soon as attribute fully supported.
43
// expected-warning@-3 {{'abi_tag' attribute ignored}}

Return to bug 571600