Coverage Report

Created: 2021-08-24 07:12

/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
362k
static inline const VariableArrayType *FindVA(const Type* t) {
26
381k
  while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
27
24.8k
    if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
28
5.48k
      if (vat->getSizeExpr())
29
5.48k
        return vat;
30
31
19.3k
    t = vt->getElementType().getTypePtr();
32
19.3k
  }
33
34
356k
  return nullptr;
35
362k
}
36
37
5.51k
void StmtIteratorBase::NextVA() {
38
5.51k
  assert(getVAPtr());
39
40
0
  const VariableArrayType *p = getVAPtr();
41
5.51k
  p = FindVA(p->getElementType().getTypePtr());
42
5.51k
  setVAPtr(p);
43
44
5.51k
  if (p)
45
1.92k
    return;
46
47
3.59k
  if (inDeclGroup()) {
48
3.56k
    if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
49
3.52k
      if (VD->hasInit())
50
13
        return;
51
52
3.54k
    NextDecl();
53
3.54k
  }
54
28
  else {
55
28
    assert(inSizeOfTypeVA());
56
0
    RawVAPtr = 0;
57
28
  }
58
3.59k
}
59
60
989k
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
61
989k
  assert(getVAPtr() == nullptr);
62
0
  assert(inDeclGroup());
63
64
989k
  if (ImmediateAdvance)
65
294k
    ++DGI;
66
67
1.05M
  for ( ; DGI != DGE; 
++DGI66.9k
)
68
361k
    if (HandleDecl(*DGI))
69
294k
      return;
70
71
694k
  RawVAPtr = 0;
72
694k
}
73
74
361k
bool StmtIteratorBase::HandleDecl(Decl* D) {
75
361k
  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
76
347k
    if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
77
3.52k
      setVAPtr(VAPtr);
78
3.52k
      return true;
79
3.52k
    }
80
81
344k
    if (VD->getInit())
82
291k
      return true;
83
344k
  }
84
14.1k
  else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) {
85
9.23k
    if (const VariableArrayType* VAPtr =
86
9.23k
        FindVA(TD->getUnderlyingType().getTypePtr())) {
87
35
      setVAPtr(VAPtr);
88
35
      return true;
89
35
    }
90
9.23k
  }
91
4.93k
  else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
92
0
    if (ECD->getInitExpr())
93
0
      return true;
94
0
  }
95
96
66.9k
  return false;
97
361k
}
98
99
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
100
695k
    : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
101
695k
  NextDecl(false);
102
695k
}
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.51k
    assert(VAPtr->SizeExpr);
112
0
    return const_cast<Stmt*&>(VAPtr->SizeExpr);
113
5.51k
  }
114
115
291k
  assert(inDeclGroup());
116
0
  VarDecl* VD = cast<VarDecl>(*DGI);
117
291k
  return *VD->getInitAddress();
118
296k
}