Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Sema/Scope.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Scope.cpp - Lexical scope information --------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the Scope class, which is used for recording
10
// information about a lexical scope.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Sema/Scope.h"
15
#include "clang/AST/Decl.h"
16
#include "llvm/Support/raw_ostream.h"
17
18
using namespace clang;
19
20
19.7M
void Scope::setFlags(Scope *parent, unsigned flags) {
21
19.7M
  AnyParent = parent;
22
19.7M
  Flags = flags;
23
19.7M
24
19.7M
  if (parent && 
!(flags & FnScope)19.6M
) {
25
16.3M
    BreakParent    = parent->BreakParent;
26
16.3M
    ContinueParent = parent->ContinueParent;
27
16.3M
  } else {
28
3.38M
    // Control scopes do not contain the contents of nested function scopes for
29
3.38M
    // control flow purposes.
30
3.38M
    BreakParent = ContinueParent = nullptr;
31
3.38M
  }
32
19.7M
33
19.7M
  if (parent) {
34
19.6M
    Depth = parent->Depth + 1;
35
19.6M
    PrototypeDepth = parent->PrototypeDepth;
36
19.6M
    PrototypeIndex = 0;
37
19.6M
    FnParent       = parent->FnParent;
38
19.6M
    BlockParent    = parent->BlockParent;
39
19.6M
    TemplateParamParent = parent->TemplateParamParent;
40
19.6M
    MSLastManglingParent = parent->MSLastManglingParent;
41
19.6M
    MSCurManglingNumber = getMSLastManglingNumber();
42
19.6M
    if ((Flags & (FnScope | ClassScope | BlockScope | TemplateParamScope |
43
19.6M
                  FunctionPrototypeScope | AtCatchScope | ObjCMethodScope)) ==
44
19.6M
        0)
45
3.68M
      Flags |= parent->getFlags() & OpenMPSimdDirectiveScope;
46
19.6M
  } else {
47
41.4k
    Depth = 0;
48
41.4k
    PrototypeDepth = 0;
49
41.4k
    PrototypeIndex = 0;
50
41.4k
    MSLastManglingParent = FnParent = BlockParent = nullptr;
51
41.4k
    TemplateParamParent = nullptr;
52
41.4k
    MSLastManglingNumber = 1;
53
41.4k
    MSCurManglingNumber = 1;
54
41.4k
  }
55
19.7M
56
19.7M
  // If this scope is a function or contains breaks/continues, remember it.
57
19.7M
  if (flags & FnScope)            
FnParent = this3.34M
;
58
19.7M
  // The MS mangler uses the number of scopes that can hold declarations as
59
19.7M
  // part of an external name.
60
19.7M
  if (Flags & (ClassScope | FnScope)) {
61
7.81M
    MSLastManglingNumber = getMSLastManglingNumber();
62
7.81M
    MSLastManglingParent = this;
63
7.81M
    MSCurManglingNumber = 1;
64
7.81M
  }
65
19.7M
  if (flags & BreakScope)         
BreakParent = this186k
;
66
19.7M
  if (flags & ContinueScope)      
ContinueParent = this186k
;
67
19.7M
  if (flags & BlockScope)         
BlockParent = this7.97k
;
68
19.7M
  if (flags & TemplateParamScope) 
TemplateParamParent = this1.62M
;
69
19.7M
70
19.7M
  // If this is a prototype scope, record that.
71
19.7M
  if (flags & FunctionPrototypeScope) 
PrototypeDepth++6.54M
;
72
19.7M
73
19.7M
  if (flags & DeclScope) {
74
17.5M
    if (flags & FunctionPrototypeScope)
75
6.54M
      ; // Prototype scopes are uninteresting.
76
10.9M
    else if ((flags & ClassScope) && 
getParent()->isClassScope()4.47M
)
77
354k
      ; // Nested class scopes aren't ambiguous.
78
10.6M
    else if ((flags & ClassScope) && 
getParent()->getFlags() == DeclScope4.11M
)
79
1.66M
      ; // Classes inside of namespaces aren't ambiguous.
80
8.97M
    else if ((flags & EnumScope))
81
47.7k
      ; // Don't increment for enum scopes.
82
8.92M
    else
83
8.92M
      incrementMSManglingNumber();
84
17.5M
  }
85
19.7M
}
86
87
16.4M
void Scope::Init(Scope *parent, unsigned flags) {
88
16.4M
  setFlags(parent, flags);
89
16.4M
90
16.4M
  DeclsInScope.clear();
91
16.4M
  UsingDirectives.clear();
92
16.4M
  Entity = nullptr;
93
16.4M
  ErrorTrap.reset();
94
16.4M
  NRVO.setPointerAndInt(nullptr, 0);
95
16.4M
}
96
97
5
bool Scope::containedInPrototypeScope() const {
98
5
  const Scope *S = this;
99
10
  while (S) {
100
8
    if (S->isFunctionPrototypeScope())
101
3
      return true;
102
5
    S = S->getParent();
103
5
  }
104
5
  
return false2
;
105
5
}
106
107
225k
void Scope::AddFlags(unsigned FlagsToSet) {
108
225k
  assert((FlagsToSet & ~(BreakScope | ContinueScope)) == 0 &&
109
225k
         "Unsupported scope flags");
110
225k
  if (FlagsToSet & BreakScope) {
111
225k
    assert((Flags & BreakScope) == 0 && "Already set");
112
225k
    BreakParent = this;
113
225k
  }
114
225k
  if (FlagsToSet & ContinueScope) {
115
214k
    assert((Flags & ContinueScope) == 0 && "Already set");
116
214k
    ContinueParent = this;
117
214k
  }
118
225k
  Flags |= FlagsToSet;
119
225k
}
120
121
16.3M
void Scope::mergeNRVOIntoParent() {
122
16.3M
  if (VarDecl *Candidate = NRVO.getPointer()) {
123
54.8k
    if (isDeclScope(Candidate))
124
38.5k
      Candidate->setNRVOVariable(true);
125
54.8k
  }
126
16.3M
127
16.3M
  if (getEntity())
128
4.98M
    return;
129
11.3M
130
11.3M
  if (NRVO.getInt())
131
677k
    getParent()->setNoNRVO();
132
10.6M
  else if (NRVO.getPointer())
133
17.1k
    getParent()->addNRVOCandidate(NRVO.getPointer());
134
11.3M
}
135
136
0
LLVM_DUMP_METHOD void Scope::dump() const { dumpImpl(llvm::errs()); }
137
138
0
void Scope::dumpImpl(raw_ostream &OS) const {
139
0
  unsigned Flags = getFlags();
140
0
  bool HasFlags = Flags != 0;
141
0
142
0
  if (HasFlags)
143
0
    OS << "Flags: ";
144
0
145
0
  std::pair<unsigned, const char *> FlagInfo[] = {
146
0
      {FnScope, "FnScope"},
147
0
      {BreakScope, "BreakScope"},
148
0
      {ContinueScope, "ContinueScope"},
149
0
      {DeclScope, "DeclScope"},
150
0
      {ControlScope, "ControlScope"},
151
0
      {ClassScope, "ClassScope"},
152
0
      {BlockScope, "BlockScope"},
153
0
      {TemplateParamScope, "TemplateParamScope"},
154
0
      {FunctionPrototypeScope, "FunctionPrototypeScope"},
155
0
      {FunctionDeclarationScope, "FunctionDeclarationScope"},
156
0
      {AtCatchScope, "AtCatchScope"},
157
0
      {ObjCMethodScope, "ObjCMethodScope"},
158
0
      {SwitchScope, "SwitchScope"},
159
0
      {TryScope, "TryScope"},
160
0
      {FnTryCatchScope, "FnTryCatchScope"},
161
0
      {OpenMPDirectiveScope, "OpenMPDirectiveScope"},
162
0
      {OpenMPLoopDirectiveScope, "OpenMPLoopDirectiveScope"},
163
0
      {OpenMPSimdDirectiveScope, "OpenMPSimdDirectiveScope"},
164
0
      {EnumScope, "EnumScope"},
165
0
      {SEHTryScope, "SEHTryScope"},
166
0
      {SEHExceptScope, "SEHExceptScope"},
167
0
      {SEHFilterScope, "SEHFilterScope"},
168
0
      {CompoundStmtScope, "CompoundStmtScope"},
169
0
      {ClassInheritanceScope, "ClassInheritanceScope"},
170
0
      {CatchScope, "CatchScope"},
171
0
  };
172
0
173
0
  for (auto Info : FlagInfo) {
174
0
    if (Flags & Info.first) {
175
0
      OS << Info.second;
176
0
      Flags &= ~Info.first;
177
0
      if (Flags)
178
0
        OS << " | ";
179
0
    }
180
0
  }
181
0
182
0
  assert(Flags == 0 && "Unknown scope flags");
183
0
184
0
  if (HasFlags)
185
0
    OS << '\n';
186
0
187
0
  if (const Scope *Parent = getParent())
188
0
    OS << "Parent: (clang::Scope*)" << Parent << '\n';
189
0
190
0
  OS << "Depth: " << Depth << '\n';
191
0
  OS << "MSLastManglingNumber: " << getMSLastManglingNumber() << '\n';
192
0
  OS << "MSCurManglingNumber: " << getMSCurManglingNumber() << '\n';
193
0
  if (const DeclContext *DC = getEntity())
194
0
    OS << "Entity : (clang::DeclContext*)" << DC << '\n';
195
0
196
0
  if (NRVO.getInt())
197
0
    OS << "NRVO not allowed\n";
198
0
  else if (NRVO.getPointer())
199
0
    OS << "NRVO candidate : (clang::VarDecl*)" << NRVO.getPointer() << '\n';
200
0
}