Coverage Report

Created: 2020-02-18 08:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/StmtIterator.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- StmtIterator.cpp - Iterators for Statements ------------------------===//
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 defines internal methods for StmtIterator.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/StmtIterator.h"
14
#include "clang/AST/Decl.h"
15
#include "clang/AST/Type.h"
16
#include "clang/Basic/LLVM.h"
17
#include "llvm/Support/Casting.h"
18
#include <cassert>
19
#include <cstdint>
20
21
using namespace clang;
22
23
// FIXME: Add support for dependent-sized array types in C++?
24
// Does it even make sense to build a CFG for an uninstantiated template?
25
367k
static inline const VariableArrayType *FindVA(const Type* t) {
26
387k
  while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
27
25.9k
    if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
28
5.77k
      if (vat->getSizeExpr())
29
5.77k
        return vat;
30
20.1k
31
20.1k
    t = vt->getElementType().getTypePtr();
32
20.1k
  }
33
367k
34
367k
  
return nullptr361k
;
35
367k
}
36
37
5.79k
void StmtIteratorBase::NextVA() {
38
5.79k
  assert(getVAPtr());
39
5.79k
40
5.79k
  const VariableArrayType *p = getVAPtr();
41
5.79k
  p = FindVA(p->getElementType().getTypePtr());
42
5.79k
  setVAPtr(p);
43
5.79k
44
5.79k
  if (p)
45
1.97k
    return;
46
3.81k
47
3.81k
  if (inDeclGroup()) {
48
3.80k
    if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
49
3.79k
      if (VD->hasInit())
50
12
        return;
51
3.78k
52
3.78k
    NextDecl();
53
3.78k
  }
54
14
  else {
55
14
    assert(inSizeOfTypeVA());
56
14
    RawVAPtr = 0;
57
14
  }
58
3.81k
}
59
60
1.00M
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
61
1.00M
  assert(getVAPtr() == nullptr);
62
1.00M
  assert(inDeclGroup());
63
1.00M
64
1.00M
  if (ImmediateAdvance)
65
296k
    ++DGI;
66
1.00M
67
1.07M
  for ( ; DGI != DGE; 
++DGI70.1k
)
68
367k
    if (HandleDecl(*DGI))
69
297k
      return;
70
1.00M
71
1.00M
  RawVAPtr = 0;
72
704k
}
73
74
367k
bool StmtIteratorBase::HandleDecl(Decl* D) {
75
367k
  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
76
348k
    if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
77
3.79k
      setVAPtr(VAPtr);
78
3.79k
      return true;
79
3.79k
    }
80
344k
81
344k
    if (VD->getInit())
82
293k
      return true;
83
18.4k
  }
84
18.4k
  else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) {
85
13.0k
    if (const VariableArrayType* VAPtr =
86
4
        FindVA(TD->getUnderlyingType().getTypePtr())) {
87
4
      setVAPtr(VAPtr);
88
4
      return true;
89
4
    }
90
5.36k
  }
91
5.36k
  else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
92
0
    if (ECD->getInitExpr())
93
0
      return true;
94
70.1k
  }
95
70.1k
96
70.1k
  return false;
97
70.1k
}
98
99
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
100
704k
    : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
101
704k
  NextDecl(false);
102
704k
}
103
104
StmtIteratorBase::StmtIteratorBase(const VariableArrayType* t)
105
14
    : DGI(nullptr), RawVAPtr(SizeOfTypeVAMode) {
106
14
  RawVAPtr |= reinterpret_cast<uintptr_t>(t);
107
14
}
108
109
299k
Stmt*& StmtIteratorBase::GetDeclExpr() const {
110
299k
  if (const VariableArrayType* VAPtr = getVAPtr()) {
111
5.79k
    assert(VAPtr->SizeExpr);
112
5.79k
    return const_cast<Stmt*&>(VAPtr->SizeExpr);
113
5.79k
  }
114
293k
115
293k
  assert(inDeclGroup());
116
293k
  VarDecl* VD = cast<VarDecl>(*DGI);
117
293k
  return *VD->getInitAddress();
118
293k
}