Coverage Report

Created: 2020-02-25 14:32

/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(AttrSyntax Syntax, const IdentifierInfo *Scope,
9
                        const IdentifierInfo *Attr, const TargetInfo &Target,
10
89.3k
                        const LangOptions &LangOpts) {
11
89.3k
  StringRef Name = Attr->getName();
12
89.3k
  // Normalize the attribute name, __foo__ becomes foo.
13
89.3k
  if (Name.size() >= 4 && 
Name.startswith("__")89.3k
&&
Name.endswith("__")11.5k
)
14
11.5k
    Name = Name.substr(2, Name.size() - 4);
15
89.3k
16
89.3k
  // Normalize the scope name, but only for gnu and clang attributes.
17
89.3k
  StringRef ScopeName = Scope ? 
Scope->getName()1.83k
:
""87.5k
;
18
89.3k
  if (ScopeName == "__gnu__")
19
3
    ScopeName = "gnu";
20
89.3k
  else if (ScopeName == "_Clang")
21
8
    ScopeName = "clang";
22
89.3k
23
89.3k
#include "clang/Basic/AttrHasAttributeImpl.inc"
24
89.3k
25
89.3k
  
return 011
;
26
89.3k
}
27
28
131
const char *attr::getSubjectMatchRuleSpelling(attr::SubjectMatchRule Rule) {
29
131
  switch (Rule) {
30
0
#define ATTR_MATCH_RULE(NAME, SPELLING, IsAbstract)                            \
31
131
  case attr::NAME:                                                             \
32
131
    return SPELLING;
33
0
#include "clang/Basic/AttrSubMatchRulesList.inc"
34
131
  }
35
131
  
llvm_unreachable0
("Invalid subject match rule");
36
131
}
37
38
static StringRef
39
normalizeAttrScopeName(StringRef ScopeName,
40
3.85k
                       AttributeCommonInfo::Syntax SyntaxUsed) {
41
3.85k
  // Normalize the "__gnu__" scope name to be "gnu" and the "_Clang" scope name
42
3.85k
  // to be "clang".
43
3.85k
  if (SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
44
3.85k
      
SyntaxUsed == AttributeCommonInfo::AS_C2x122
) {
45
3.85k
    if (ScopeName == "__gnu__")
46
4
      ScopeName = "gnu";
47
3.85k
    else if (ScopeName == "_Clang")
48
32
      ScopeName = "clang";
49
3.85k
  }
50
3.85k
  return ScopeName;
51
3.85k
}
52
53
static StringRef normalizeAttrName(StringRef AttrName,
54
                                   StringRef NormalizedScopeName,
55
32.5M
                                   AttributeCommonInfo::Syntax SyntaxUsed) {
56
32.5M
  // Normalize the attribute name, __foo__ becomes foo. This is only allowable
57
32.5M
  // for GNU attributes, and attributes using the double square bracket syntax.
58
32.5M
  bool ShouldNormalize =
59
32.5M
      SyntaxUsed == AttributeCommonInfo::AS_GNU ||
60
32.5M
      
(4.69M
(4.69M
SyntaxUsed == AttributeCommonInfo::AS_CXX114.69M
||
61
4.69M
        
SyntaxUsed == AttributeCommonInfo::AS_C2x4.66M
) &&
62
4.69M
       
(23.8k
NormalizedScopeName.empty()23.8k
||
NormalizedScopeName == "gnu"3.85k
||
63
23.8k
        
NormalizedScopeName == "clang"3.50k
));
64
32.5M
  if (ShouldNormalize && 
AttrName.size() >= 427.8M
&&
AttrName.startswith("__")27.8M
&&
65
32.5M
      
AttrName.endswith("__")13.4M
)
66
10.3M
    AttrName = AttrName.slice(2, AttrName.size() - 2);
67
32.5M
68
32.5M
  return AttrName;
69
32.5M
}
70
71
11.4k
bool AttributeCommonInfo::isGNUScope() const {
72
11.4k
  return ScopeName && 
(510
ScopeName->isStr("gnu")510
||
ScopeName->isStr("__gnu__")369
);
73
11.4k
}
74
75
#include "clang/Sema/AttrParsedAttrKinds.inc"
76
77
AttributeCommonInfo::Kind
78
AttributeCommonInfo::getParsedKind(const IdentifierInfo *Name,
79
                                   const IdentifierInfo *ScopeName,
80
32.3M
                                   Syntax SyntaxUsed) {
81
32.3M
  StringRef AttrName = Name->getName();
82
32.3M
83
32.3M
  SmallString<64> FullName;
84
32.3M
  if (ScopeName)
85
3.31k
    FullName += normalizeAttrScopeName(ScopeName->getName(), SyntaxUsed);
86
32.3M
87
32.3M
  AttrName = normalizeAttrName(AttrName, FullName, SyntaxUsed);
88
32.3M
89
32.3M
  // Ensure that in the case of C++11 attributes, we look for '::foo' if it is
90
32.3M
  // unscoped.
91
32.3M
  if (ScopeName || 
SyntaxUsed == AS_CXX1132.3M
||
SyntaxUsed == AS_C2x32.3M
)
92
23.2k
    FullName += "::";
93
32.3M
  FullName += AttrName;
94
32.3M
95
32.3M
  return ::getAttrKind(FullName, SyntaxUsed);
96
32.3M
}
97
98
224k
unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
99
224k
  // Both variables will be used in tablegen generated
100
224k
  // attribute spell list index matching code.
101
224k
  auto Syntax = static_cast<AttributeCommonInfo::Syntax>(getSyntax());
102
224k
  StringRef Scope =
103
224k
      getScopeName() ? 
normalizeAttrScopeName(getScopeName()->getName(), Syntax)545
104
224k
                     : 
""224k
;
105
224k
  StringRef Name = normalizeAttrName(getAttrName()->getName(), Scope, Syntax);
106
224k
107
224k
#include "clang/Sema/AttrSpellingListIndex.inc"
108
}