Coverage Report

Created: 2020-09-15 12:33

/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
359k
static inline const VariableArrayType *FindVA(const Type* t) {
26
378k
  while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
27
24.6k
    if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
28
5.55k
      if (vat->getSizeExpr())
29
5.55k
        return vat;
30
19.0k
31
19.0k
    t = vt->getElementType().getTypePtr();
32
19.0k
  }
33
359k
34
354k
  return nullptr;
35
359k
}
36
37
5.58k
void StmtIteratorBase::NextVA() {
38
5.58k
  assert(getVAPtr());
39
5.58k
40
5.58k
  const VariableArrayType *p = getVAPtr();
41
5.58k
  p = FindVA(p->getElementType().getTypePtr());
42
5.58k
  setVAPtr(p);
43
5.58k
44
5.58k
  if (p)
45
1.91k
    return;
46
3.66k
47
3.66k
  if (inDeclGroup()) {
48
3.63k
    if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
49
3.60k
      if (VD->hasInit())
50
12
        return;
51
3.62k
52
3.62k
    NextDecl();
53
3.62k
  }
54
28
  else {
55
28
    assert(inSizeOfTypeVA());
56
28
    RawVAPtr = 0;
57
28
  }
58
3.66k
}
59
60
984k
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
61
984k
  assert(getVAPtr() == nullptr);
62
984k
  assert(inDeclGroup());
63
984k
64
984k
  if (ImmediateAdvance)
65
294k
    ++DGI;
66
984k
67
1.04M
  for ( ; DGI != DGE; 
++DGI64.3k
)
68
359k
    if (HandleDecl(*DGI))
69
294k
      return;
70
984k
71
689k
  RawVAPtr = 0;
72
689k
}
73
74
359k
bool StmtIteratorBase::HandleDecl(Decl* D) {
75
359k
  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
76
345k
    if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
77
3.60k
      setVAPtr(VAPtr);
78
3.60k
      return true;
79
3.60k
    }
80
341k
81
341k
    if (VD->getInit())
82
291k
      return true;
83
13.5k
  }
84
13.5k
  else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) {
85
8.75k
    if (const VariableArrayType* VAPtr =
86
35
        FindVA(TD->getUnderlyingType().getTypePtr())) {
87
35
      setVAPtr(VAPtr);
88
35
      return true;
89
35
    }
90
4.80k
  }
91
4.80k
  else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
92
0
    if (ECD->getInitExpr())
93
0
      return true;
94
64.3k
  }
95
64.3k
96
64.3k
  return false;
97
64.3k
}
98
99
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
100
689k
    : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
101
689k
  NextDecl(false);
102
689k
}
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
296k
Stmt*& StmtIteratorBase::GetDeclExpr() const {
110
296k
  if (const VariableArrayType* VAPtr = getVAPtr()) {
111
5.58k
    assert(VAPtr->SizeExpr);
112
5.58k
    return const_cast<Stmt*&>(VAPtr->SizeExpr);
113
5.58k
  }
114
291k
115
291k
  assert(inDeclGroup());
116
291k
  VarDecl* VD = cast<VarDecl>(*DGI);
117
291k
  return *VD->getInitAddress();
118
291k
}