Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
125k
static inline const VariableArrayType *FindVA(const Type* t) {
26
132k
  while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
27
8.14k
    if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
28
1.44k
      if (vat->getSizeExpr())
29
1.44k
        return vat;
30
6.69k
31
6.69k
    t = vt->getElementType().getTypePtr();
32
6.69k
  }
33
125k
34
125k
  
return nullptr124k
;
35
125k
}
36
37
1.46k
void StmtIteratorBase::NextVA() {
38
1.46k
  assert(getVAPtr());
39
1.46k
40
1.46k
  const VariableArrayType *p = getVAPtr();
41
1.46k
  p = FindVA(p->getElementType().getTypePtr());
42
1.46k
  setVAPtr(p);
43
1.46k
44
1.46k
  if (p)
45
449
    return;
46
1.01k
47
1.01k
  if (inDeclGroup()) {
48
997
    if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
49
993
      if (VD->hasInit())
50
12
        return;
51
985
52
985
    NextDecl();
53
985
  }
54
14
  else {
55
14
    assert(inSizeOfTypeVA());
56
14
    RawVAPtr = 0;
57
14
  }
58
1.01k
}
59
60
349k
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
61
349k
  assert(getVAPtr() == nullptr);
62
349k
  assert(inDeclGroup());
63
349k
64
349k
  if (ImmediateAdvance)
65
104k
    ++DGI;
66
349k
67
370k
  for ( ; DGI != DGE; 
++DGI20.9k
)
68
125k
    if (HandleDecl(*DGI))
69
104k
      return;
70
349k
71
349k
  RawVAPtr = 0;
72
244k
}
73
74
125k
bool StmtIteratorBase::HandleDecl(Decl* D) {
75
125k
  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
76
122k
    if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
77
993
      setVAPtr(VAPtr);
78
993
      return true;
79
993
    }
80
121k
81
121k
    if (VD->getInit())
82
103k
      return true;
83
2.51k
  }
84
2.51k
  else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) {
85
1.24k
    if (const VariableArrayType* VAPtr =
86
4
        FindVA(TD->getUnderlyingType().getTypePtr())) {
87
4
      setVAPtr(VAPtr);
88
4
      return true;
89
4
    }
90
1.27k
  }
91
1.27k
  else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
92
0
    if (ECD->getInitExpr())
93
0
      return true;
94
20.9k
  }
95
20.9k
96
20.9k
  return false;
97
20.9k
}
98
99
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
100
244k
    : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
101
244k
  NextDecl(false);
102
244k
}
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
104k
Stmt*& StmtIteratorBase::GetDeclExpr() const {
110
104k
  if (const VariableArrayType* VAPtr = getVAPtr()) {
111
1.46k
    assert(VAPtr->SizeExpr);
112
1.46k
    return const_cast<Stmt*&>(VAPtr->SizeExpr);
113
1.46k
  }
114
103k
115
103k
  assert(inDeclGroup());
116
103k
  VarDecl* VD = cast<VarDecl>(*DGI);
117
103k
  return *VD->getInitAddress();
118
103k
}