Coverage Report

Created: 2022-05-21 09:15

/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
282k
static inline const VariableArrayType *FindVA(const Type* t) {
26
297k
  while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
27
20.8k
    if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
28
5.29k
      if (vat->getSizeExpr())
29
5.29k
        return vat;
30
31
15.5k
    t = vt->getElementType().getTypePtr();
32
15.5k
  }
33
34
277k
  return nullptr;
35
282k
}
36
37
5.32k
void StmtIteratorBase::NextVA() {
38
5.32k
  assert(getVAPtr());
39
40
0
  const VariableArrayType *p = getVAPtr();
41
5.32k
  p = FindVA(p->getElementType().getTypePtr());
42
5.32k
  setVAPtr(p);
43
44
5.32k
  if (p)
45
1.86k
    return;
46
47
3.46k
  if (inDeclGroup()) {
48
3.43k
    if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
49
3.39k
      if (VD->hasInit())
50
12
        return;
51
52
3.42k
    NextDecl();
53
3.42k
  }
54
28
  else {
55
28
    assert(inSizeOfTypeVA());
56
0
    RawVAPtr = 0;
57
28
  }
58
3.46k
}
59
60
784k
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
61
784k
  assert(getVAPtr() == nullptr);
62
0
  assert(inDeclGroup());
63
64
784k
  if (ImmediateAdvance)
65
234k
    ++DGI;
66
67
831k
  for ( ; DGI != DGE; 
++DGI47.1k
)
68
281k
    if (HandleDecl(*DGI))
69
234k
      return;
70
71
550k
  RawVAPtr = 0;
72
550k
}
73
74
281k
bool StmtIteratorBase::HandleDecl(Decl* D) {
75
281k
  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
76
268k
    if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
77
3.39k
      setVAPtr(VAPtr);
78
3.39k
      return true;
79
3.39k
    }
80
81
265k
    if (VD->getInit())
82
231k
      return true;
83
265k
  }
84
12.9k
  else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) {
85
8.32k
    if (const VariableArrayType* VAPtr =
86
8.32k
        FindVA(TD->getUnderlyingType().getTypePtr())) {
87
35
      setVAPtr(VAPtr);
88
35
      return true;
89
35
    }
90
8.32k
  }
91
4.61k
  else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
92
0
    if (ECD->getInitExpr())
93
0
      return true;
94
0
  }
95
96
47.1k
  return false;
97
281k
}
98
99
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
100
550k
    : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
101
550k
  NextDecl(false);
102
550k
}
103
104
StmtIteratorBase::StmtIteratorBase(const VariableArrayType* t)
105
28
    : DGI(nullptr), RawVAPtr(SizeOfTypeVAMode) {
106
28
  RawVAPtr |= reinterpret_cast<uintptr_t>(t);
107
28
}
108
109
236k
Stmt*& StmtIteratorBase::GetDeclExpr() const {
110
236k
  if (const VariableArrayType* VAPtr = getVAPtr()) {
111
5.32k
    assert(VAPtr->SizeExpr);
112
0
    return const_cast<Stmt*&>(VAPtr->SizeExpr);
113
5.32k
  }
114
115
231k
  assert(inDeclGroup());
116
0
  VarDecl* VD = cast<VarDecl>(*DGI);
117
231k
  return *VD->getInitAddress();
118
236k
}