Coverage Report

Created: 2021-09-21 08:58

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/IgnoreExpr.h
Line
Count
Source (jump to first uncovered line)
1
//===--- IgnoreExpr.h - Ignore intermediate Expressions -----------------===//
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 common functions to ignore intermediate expression nodes
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_IGNOREEXPR_H
14
#define LLVM_CLANG_AST_IGNOREEXPR_H
15
16
#include "clang/AST/Expr.h"
17
#include "clang/AST/ExprCXX.h"
18
19
namespace clang {
20
namespace detail {
21
/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
22
/// Return Fn_n(...(Fn_1(E)))
23
392M
inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
24
template <typename FnTy, typename... FnTys>
25
663M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
663M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
663M
}
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*))
Line
Count
Source
25
392M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
392M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
392M
}
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*))
Line
Count
Source
25
270M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
270M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
270M
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&)
Line
Count
Source
25
27.5k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
27.5k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
27.5k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&>(clang::Expr*, clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&)
Line
Count
Source
25
27.5k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
27.5k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
27.5k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
25
38.7k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.7k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.7k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
25
38.7k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.7k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.7k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
25
38.7k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.7k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.7k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
25
38.7k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.7k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.7k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
25
38.7k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.7k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.7k
}
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*))
Line
Count
Source
25
11.4k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
11.4k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
11.4k
}
28
} // namespace detail
29
30
/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
31
/// Recursively apply each of the functions to E until reaching a fixed point.
32
/// Note that a null E is valid; in this case nothing is done.
33
309M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
309M
  Expr *LastE = nullptr;
35
702M
  while (E != LastE) {
36
392M
    LastE = E;
37
392M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
392M
  }
39
309M
  return E;
40
309M
}
clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*))
Line
Count
Source
33
112M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
112M
  Expr *LastE = nullptr;
35
234M
  while (E != LastE) {
36
122M
    LastE = E;
37
122M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
122M
  }
39
112M
  return E;
40
112M
}
clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*))
Line
Count
Source
33
196M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
196M
  Expr *LastE = nullptr;
35
467M
  while (E != LastE) {
36
270M
    LastE = E;
37
270M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
270M
  }
39
196M
  return E;
40
196M
}
Expr.cpp:clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreParenNoopCasts(clang::ASTContext const&)::$_3&)
Line
Count
Source
33
23.8k
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
23.8k
  Expr *LastE = nullptr;
35
51.3k
  while (E != LastE) {
36
27.5k
    LastE = E;
37
27.5k
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
27.5k
  }
39
23.8k
  return E;
40
23.8k
}
Expr.cpp:clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr::IgnoreUnlessSpelledInSource()::$_4&, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
33
35.8k
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
35.8k
  Expr *LastE = nullptr;
35
74.5k
  while (E != LastE) {
36
38.7k
    LastE = E;
37
38.7k
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
38.7k
  }
39
35.8k
  return E;
40
35.8k
}
clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*), clang::Expr* (&)(clang::Expr*))
Line
Count
Source
33
9.42k
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
9.42k
  Expr *LastE = nullptr;
35
20.9k
  while (E != LastE) {
36
11.4k
    LastE = E;
37
11.4k
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
11.4k
  }
39
9.42k
  return E;
40
9.42k
}
41
42
template <typename... FnTys>
43
const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
44
  return IgnoreExprNodes(const_cast<Expr *>(E), std::forward<FnTys>(Fns)...);
45
}
46
47
186M
inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {
48
186M
  if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
49
52.0M
    return ICE->getSubExpr();
50
51
134M
  if (auto *FE = dyn_cast<FullExpr>(E))
52
230k
    return FE->getSubExpr();
53
54
134M
  return E;
55
134M
}
56
57
167M
inline Expr *IgnoreImplicitCastsExtraSingleStep(Expr *E) {
58
  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
59
  // addition to what IgnoreImpCasts() skips to account for the current
60
  // behaviour of IgnoreParenImpCasts().
61
167M
  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
62
167M
  if (SubE != E)
63
46.9M
    return SubE;
64
65
120M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
66
272k
    return MTE->getSubExpr();
67
68
119M
  if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
69
1.50M
    return NTTP->getReplacement();
70
71
118M
  return E;
72
119M
}
73
74
103M
inline Expr *IgnoreCastsSingleStep(Expr *E) {
75
103M
  if (auto *CE = dyn_cast<CastExpr>(E))
76
16.0M
    return CE->getSubExpr();
77
78
87.3M
  if (auto *FE = dyn_cast<FullExpr>(E))
79
81.7k
    return FE->getSubExpr();
80
81
87.2M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
82
28.7k
    return MTE->getSubExpr();
83
84
87.1M
  if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
85
287k
    return NTTP->getReplacement();
86
87
86.9M
  return E;
88
87.1M
}
89
90
68.0k
inline Expr *IgnoreLValueCastsSingleStep(Expr *E) {
91
  // Skip what IgnoreCastsSingleStep skips, except that only
92
  // lvalue-to-rvalue casts are skipped.
93
68.0k
  if (auto *CE = dyn_cast<CastExpr>(E))
94
3.26k
    if (CE->getCastKind() != CK_LValueToRValue)
95
287
      return E;
96
97
67.8k
  return IgnoreCastsSingleStep(E);
98
68.0k
}
99
100
40.9k
inline Expr *IgnoreBaseCastsSingleStep(Expr *E) {
101
40.9k
  if (auto *CE = dyn_cast<CastExpr>(E))
102
8.57k
    if (CE->getCastKind() == CK_DerivedToBase ||
103
8.57k
        
CE->getCastKind() == CK_UncheckedDerivedToBase8.48k
||
104
8.57k
        
CE->getCastKind() == CK_NoOp8.15k
)
105
4.43k
      return CE->getSubExpr();
106
107
36.5k
  return E;
108
40.9k
}
109
110
7.40M
inline Expr *IgnoreImplicitSingleStep(Expr *E) {
111
7.40M
  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
112
7.40M
  if (SubE != E)
113
2.06M
    return SubE;
114
115
5.34M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
116
840
    return MTE->getSubExpr();
117
118
5.34M
  if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
119
120
    return BTE->getSubExpr();
120
121
5.34M
  return E;
122
5.34M
}
123
124
213
inline Expr *IgnoreElidableImplicitConstructorSingleStep(Expr *E) {
125
213
  auto *CCE = dyn_cast<CXXConstructExpr>(E);
126
213
  if (CCE && 
CCE->isElidable()17
&&
!isa<CXXTemporaryObjectExpr>(CCE)15
) {
127
15
    unsigned NumArgs = CCE->getNumArgs();
128
15
    if ((NumArgs == 1 ||
129
15
         
(0
NumArgs > 10
&&
CCE->getArg(1)->isDefaultArgument()0
)) &&
130
15
        !CCE->getArg(0)->isDefaultArgument() && !CCE->isListInitialization())
131
15
      return CCE->getArg(0);
132
15
  }
133
198
  return E;
134
213
}
135
136
2.69k
inline Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E) {
137
2.69k
  if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
138
1.01k
    return ICE->getSubExprAsWritten();
139
140
1.68k
  return IgnoreImplicitSingleStep(E);
141
2.69k
}
142
143
38.7k
inline Expr *IgnoreParensOnlySingleStep(Expr *E) {
144
38.7k
  if (auto *PE = dyn_cast<ParenExpr>(E))
145
5
    return PE->getSubExpr();
146
38.7k
  return E;
147
38.7k
}
148
149
373M
inline Expr *IgnoreParensSingleStep(Expr *E) {
150
373M
  if (auto *PE = dyn_cast<ParenExpr>(E))
151
12.4M
    return PE->getSubExpr();
152
153
360M
  if (auto *UO = dyn_cast<UnaryOperator>(E)) {
154
5.44M
    if (UO->getOpcode() == UO_Extension)
155
221k
      return UO->getSubExpr();
156
5.44M
  }
157
158
355M
  else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) {
159
2.16k
    if (!GSE->isResultDependent())
160
2.15k
      return GSE->getResultExpr();
161
2.16k
  }
162
163
355M
  else if (auto *CE = dyn_cast<ChooseExpr>(E)) {
164
273
    if (!CE->isConditionDependent())
165
270
      return CE->getChosenSubExpr();
166
273
  }
167
168
360M
  return E;
169
360M
}
170
171
} // namespace clang
172
173
#endif // LLVM_CLANG_AST_IGNOREEXPR_H