Coverage Report

Created: 2020-11-24 06:42

/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
358k
static inline const VariableArrayType *FindVA(const Type* t) {
26
378k
  while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
27
24.9k
    if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
28
5.55k
      if (vat->getSizeExpr())
29
5.55k
        return vat;
30
31
19.4k
    t = vt->getElementType().getTypePtr();
32
19.4k
  }
33
34
353k
  return nullptr;
35
358k
}
36
37
5.58k
void StmtIteratorBase::NextVA() {
38
5.58k
  assert(getVAPtr());
39
40
5.58k
  const VariableArrayType *p = getVAPtr();
41
5.58k
  p = FindVA(p->getElementType().getTypePtr());
42
5.58k
  setVAPtr(p);
43
44
5.58k
  if (p)
45
1.91k
    return;
46
47
3.66k
  if (inDeclGroup()) {
48
3.64k
    if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
49
3.60k
      if (VD->hasInit())
50
12
        return;
51
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
980k
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
61
980k
  assert(getVAPtr() == nullptr);
62
980k
  assert(inDeclGroup());
63
64
980k
  if (ImmediateAdvance)
65
292k
    ++DGI;
66
67
1.04M
  for ( ; DGI != DGE; 
++DGI65.6k
)
68
358k
    if (HandleDecl(*DGI))
69
292k
      return;
70
71
687k
  RawVAPtr = 0;
72
687k
}
73
74
358k
bool StmtIteratorBase::HandleDecl(Decl* D) {
75
358k
  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
76
343k
    if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
77
3.60k
      setVAPtr(VAPtr);
78
3.60k
      return true;
79
3.60k
    }
80
81
340k
    if (VD->getInit())
82
288k
      return true;
83
14.1k
  }
84
14.1k
  else if (TypedefNameDecl* TD = dyn_cast<TypedefNameDecl>(D)) {
85
9.33k
    if (const VariableArrayType* VAPtr =
86
35
        FindVA(TD->getUnderlyingType().getTypePtr())) {
87
35
      setVAPtr(VAPtr);
88
35
      return true;
89
35
    }
90
4.83k
  }
91
4.83k
  else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
92
0
    if (ECD->getInitExpr())
93
0
      return true;
94
65.6k
  }
95
96
65.6k
  return false;
97
65.6k
}
98
99
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
100
687k
    : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
101
687k
  NextDecl(false);
102
687k
}
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
294k
Stmt*& StmtIteratorBase::GetDeclExpr() const {
110
294k
  if (const VariableArrayType* VAPtr = getVAPtr()) {
111
5.58k
    assert(VAPtr->SizeExpr);
112
5.58k
    return const_cast<Stmt*&>(VAPtr->SizeExpr);
113
5.58k
  }
114
115
288k
  assert(inDeclGroup());
116
288k
  VarDecl* VD = cast<VarDecl>(*DGI);
117
288k
  return *VD->getInitAddress();
118
288k
}