/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Attributes.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include "clang/Basic/Attributes.h" |
2 | | #include "clang/Basic/AttrSubjectMatchRules.h" |
3 | | #include "clang/Basic/AttributeCommonInfo.h" |
4 | | #include "clang/Basic/IdentifierTable.h" |
5 | | #include "llvm/ADT/StringSwitch.h" |
6 | | using namespace clang; |
7 | | |
8 | | int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax, |
9 | | const IdentifierInfo *Scope, const IdentifierInfo *Attr, |
10 | 64.7k | const TargetInfo &Target, const LangOptions &LangOpts) { |
11 | 64.7k | StringRef Name = Attr->getName(); |
12 | | // Normalize the attribute name, __foo__ becomes foo. |
13 | 64.7k | if (Name.size() >= 4 && Name.startswith("__")64.7k && Name.endswith("__")7.63k ) |
14 | 7.63k | Name = Name.substr(2, Name.size() - 4); |
15 | | |
16 | | // Normalize the scope name, but only for gnu and clang attributes. |
17 | 64.7k | StringRef ScopeName = Scope ? Scope->getName()2.19k : ""62.5k ; |
18 | 64.7k | if (ScopeName == "__gnu__") |
19 | 5 | ScopeName = "gnu"; |
20 | 64.7k | else if (ScopeName == "_Clang") |
21 | 13 | ScopeName = "clang"; |
22 | | |
23 | | // As a special case, look for the omp::sequence and omp::directive |
24 | | // attributes. We support those, but not through the typical attribute |
25 | | // machinery that goes through TableGen. We support this in all OpenMP modes |
26 | | // so long as double square brackets are enabled. |
27 | 64.7k | if (LangOpts.OpenMP && LangOpts.DoubleSquareBracketAttributes676 && |
28 | 64.7k | ScopeName == "omp"676 ) |
29 | 658 | return (Name == "directive" || Name == "sequence"121 ) ? 1652 : 06 ; |
30 | | |
31 | 64.7k | #include "clang/Basic/AttrHasAttributeImpl.inc" |
32 | | |
33 | 970 | return 0; |
34 | 64.0k | } |
35 | | |
36 | 140 | const char *attr::getSubjectMatchRuleSpelling(attr::SubjectMatchRule Rule) { |
37 | 140 | switch (Rule) { |
38 | 0 | #define ATTR_MATCH_RULE(NAME, SPELLING, IsAbstract) \ |
39 | 140 | case attr::NAME: \ |
40 | 140 | return SPELLING; |
41 | 140 | #include "clang/Basic/AttrSubMatchRulesList.inc"0 |
42 | 140 | } |
43 | 0 | llvm_unreachable("Invalid subject match rule"); |
44 | 0 | } |
45 | | |
46 | | static StringRef |
47 | | normalizeAttrScopeName(const IdentifierInfo *Scope, |
48 | 132M | AttributeCommonInfo::Syntax SyntaxUsed) { |
49 | 132M | if (!Scope) |
50 | 132M | return ""; |
51 | | |
52 | | // Normalize the "__gnu__" scope name to be "gnu" and the "_Clang" scope name |
53 | | // to be "clang". |
54 | 3.07k | StringRef ScopeName = Scope->getName(); |
55 | 3.07k | if (SyntaxUsed == AttributeCommonInfo::AS_CXX11 || |
56 | 3.07k | SyntaxUsed == AttributeCommonInfo::AS_C2x476 ) { |
57 | 3.07k | if (ScopeName == "__gnu__") |
58 | 13 | ScopeName = "gnu"; |
59 | 3.05k | else if (ScopeName == "_Clang") |
60 | 22 | ScopeName = "clang"; |
61 | 3.07k | } |
62 | 3.07k | return ScopeName; |
63 | 132M | } |
64 | | |
65 | | static StringRef normalizeAttrName(const IdentifierInfo *Name, |
66 | | StringRef NormalizedScopeName, |
67 | 132M | AttributeCommonInfo::Syntax SyntaxUsed) { |
68 | | // Normalize the attribute name, __foo__ becomes foo. This is only allowable |
69 | | // for GNU attributes, and attributes using the double square bracket syntax. |
70 | 132M | bool ShouldNormalize = |
71 | 132M | SyntaxUsed == AttributeCommonInfo::AS_GNU || |
72 | 132M | (3.82M (3.82M SyntaxUsed == AttributeCommonInfo::AS_CXX113.82M || |
73 | 3.82M | SyntaxUsed == AttributeCommonInfo::AS_C2x3.80M ) && |
74 | 3.82M | (20.3k NormalizedScopeName.empty()20.3k || NormalizedScopeName == "gnu"3.07k || |
75 | 20.3k | NormalizedScopeName == "clang"2.45k )); |
76 | 132M | StringRef AttrName = Name->getName(); |
77 | 132M | if (ShouldNormalize && AttrName.size() >= 4128M && AttrName.startswith("__")128M && |
78 | 132M | AttrName.endswith("__")113M ) |
79 | 58.7M | AttrName = AttrName.slice(2, AttrName.size() - 2); |
80 | | |
81 | 132M | return AttrName; |
82 | 132M | } |
83 | | |
84 | 18.1k | bool AttributeCommonInfo::isGNUScope() const { |
85 | 18.1k | return ScopeName && (975 ScopeName->isStr("gnu")975 || ScopeName->isStr("__gnu__")704 ); |
86 | 18.1k | } |
87 | | |
88 | 1.90k | bool AttributeCommonInfo::isClangScope() const { |
89 | 1.90k | return ScopeName && (63 ScopeName->isStr("clang")63 || ScopeName->isStr("_Clang")5 ); |
90 | 1.90k | } |
91 | | |
92 | | #include "clang/Sema/AttrParsedAttrKinds.inc" |
93 | | |
94 | | static SmallString<64> normalizeName(const IdentifierInfo *Name, |
95 | | const IdentifierInfo *Scope, |
96 | 131M | AttributeCommonInfo::Syntax SyntaxUsed) { |
97 | 131M | StringRef ScopeName = normalizeAttrScopeName(Scope, SyntaxUsed); |
98 | 131M | StringRef AttrName = normalizeAttrName(Name, ScopeName, SyntaxUsed); |
99 | | |
100 | 131M | SmallString<64> FullName = ScopeName; |
101 | 131M | if (!ScopeName.empty()) { |
102 | 2.31k | assert(SyntaxUsed == AttributeCommonInfo::AS_CXX11 || |
103 | 2.31k | SyntaxUsed == AttributeCommonInfo::AS_C2x); |
104 | 0 | FullName += "::"; |
105 | 2.31k | } |
106 | 0 | FullName += AttrName; |
107 | | |
108 | 131M | return FullName; |
109 | 131M | } |
110 | | |
111 | | AttributeCommonInfo::Kind |
112 | | AttributeCommonInfo::getParsedKind(const IdentifierInfo *Name, |
113 | | const IdentifierInfo *ScopeName, |
114 | 131M | Syntax SyntaxUsed) { |
115 | 131M | return ::getAttrKind(normalizeName(Name, ScopeName, SyntaxUsed), SyntaxUsed); |
116 | 131M | } |
117 | | |
118 | 224 | std::string AttributeCommonInfo::getNormalizedFullName() const { |
119 | 224 | return static_cast<std::string>( |
120 | 224 | normalizeName(getAttrName(), getScopeName(), getSyntax())); |
121 | 224 | } |
122 | | |
123 | 401k | unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const { |
124 | | // Both variables will be used in tablegen generated |
125 | | // attribute spell list index matching code. |
126 | 401k | auto Syntax = static_cast<AttributeCommonInfo::Syntax>(getSyntax()); |
127 | 401k | StringRef Scope = normalizeAttrScopeName(getScopeName(), Syntax); |
128 | 401k | StringRef Name = normalizeAttrName(getAttrName(), Scope, Syntax); |
129 | | |
130 | 401k | #include "clang/Sema/AttrSpellingListIndex.inc"0 |
131 | 401k | } |