Coverage Report

Created: 2022-05-17 06:19

/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
383M
inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
24
template <typename FnTy, typename... FnTys>
25
645M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
645M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
645M
}
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*))
Line
Count
Source
25
383M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
383M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
383M
}
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
261M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
261M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
261M
}
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
204k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
204k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
204k
}
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
204k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
204k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
204k
}
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.8k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.8k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.8k
}
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.8k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.8k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.8k
}
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.8k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.8k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.8k
}
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.8k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.8k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.8k
}
Expr.cpp:clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr::IgnoreUnlessSpelledInSource()::$_5&>(clang::Expr*, clang::Expr::IgnoreUnlessSpelledInSource()::$_5&)
Line
Count
Source
25
38.8k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
38.8k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
38.8k
}
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
302M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
302M
  Expr *LastE = nullptr;
35
686M
  while (E != LastE) {
36
383M
    LastE = E;
37
383M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
383M
  }
39
302M
  return E;
40
302M
}
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
121M
    LastE = E;
37
121M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
121M
  }
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
189M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
189M
  Expr *LastE = nullptr;
35
451M
  while (E != LastE) {
36
261M
    LastE = E;
37
261M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
261M
  }
39
189M
  return E;
40
189M
}
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
200k
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
200k
  Expr *LastE = nullptr;
35
404k
  while (E != LastE) {
36
204k
    LastE = E;
37
204k
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
204k
  }
39
200k
  return E;
40
200k
}
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.6k
  while (E != LastE) {
36
38.8k
    LastE = E;
37
38.8k
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
38.8k
  }
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
1.85M
const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
44
1.85M
  return IgnoreExprNodes(const_cast<Expr *>(E), std::forward<FnTys>(Fns)...);
45
1.85M
}
46
47
186M
inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {
48
186M
  if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
49
51.4M
    return ICE->getSubExpr();
50
51
134M
  if (auto *FE = dyn_cast<FullExpr>(E))
52
292k
    return FE->getSubExpr();
53
54
134M
  return E;
55
134M
}
56
57
166M
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
166M
  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
62
166M
  if (SubE != E)
63
46.5M
    return SubE;
64
65
120M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
66
281k
    return MTE->getSubExpr();
67
68
120M
  if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
69
1.40M
    return NTTP->getReplacement();
70
71
118M
  return E;
72
120M
}
73
74
94.4M
inline Expr *IgnoreCastsSingleStep(Expr *E) {
75
94.4M
  if (auto *CE = dyn_cast<CastExpr>(E))
76
15.3M
    return CE->getSubExpr();
77
78
79.1M
  if (auto *FE = dyn_cast<FullExpr>(E))
79
100k
    return FE->getSubExpr();
80
81
79.0M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
82
30.7k
    return MTE->getSubExpr();
83
84
79.0M
  if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
85
260k
    return NTTP->getReplacement();
86
87
78.7M
  return E;
88
79.0M
}
89
90
69.1k
inline Expr *IgnoreLValueCastsSingleStep(Expr *E) {
91
  // Skip what IgnoreCastsSingleStep skips, except that only
92
  // lvalue-to-rvalue casts are skipped.
93
69.1k
  if (auto *CE = dyn_cast<CastExpr>(E))
94
3.30k
    if (CE->getCastKind() != CK_LValueToRValue)
95
287
      return E;
96
97
68.8k
  return IgnoreCastsSingleStep(E);
98
69.1k
}
99
100
40.6k
inline Expr *IgnoreBaseCastsSingleStep(Expr *E) {
101
40.6k
  if (auto *CE = dyn_cast<CastExpr>(E))
102
8.48k
    if (CE->getCastKind() == CK_DerivedToBase ||
103
8.48k
        
CE->getCastKind() == CK_UncheckedDerivedToBase8.39k
||
104
8.48k
        
CE->getCastKind() == CK_NoOp8.06k
)
105
4.43k
      return CE->getSubExpr();
106
107
36.1k
  return E;
108
40.6k
}
109
110
7.47M
inline Expr *IgnoreImplicitSingleStep(Expr *E) {
111
7.47M
  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
112
7.47M
  if (SubE != E)
113
2.07M
    return SubE;
114
115
5.39M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
116
827
    return MTE->getSubExpr();
117
118
5.39M
  if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
119
189
    return BTE->getSubExpr();
120
121
5.39M
  return E;
122
5.39M
}
123
124
217
inline Expr *IgnoreElidableImplicitConstructorSingleStep(Expr *E) {
125
217
  auto *CCE = dyn_cast<CXXConstructExpr>(E);
126
217
  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
202
  return E;
134
217
}
135
136
3.83k
inline Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E) {
137
3.83k
  if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
138
1.42k
    return ICE->getSubExprAsWritten();
139
140
2.40k
  return IgnoreImplicitSingleStep(E);
141
3.83k
}
142
143
38.8k
inline Expr *IgnoreParensOnlySingleStep(Expr *E) {
144
38.8k
  if (auto *PE = dyn_cast<ParenExpr>(E))
145
5
    return PE->getSubExpr();
146
38.8k
  return E;
147
38.8k
}
148
149
362M
inline Expr *IgnoreParensSingleStep(Expr *E) {
150
362M
  if (auto *PE = dyn_cast<ParenExpr>(E))
151
11.4M
    return PE->getSubExpr();
152
153
350M
  if (auto *UO = dyn_cast<UnaryOperator>(E)) {
154
5.29M
    if (UO->getOpcode() == UO_Extension)
155
235k
      return UO->getSubExpr();
156
5.29M
  }
157
158
345M
  else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) {
159
1.06k
    if (!GSE->isResultDependent())
160
1.05k
      return GSE->getResultExpr();
161
1.06k
  }
162
163
345M
  else if (auto *CE = dyn_cast<ChooseExpr>(E)) {
164
275
    if (!CE->isConditionDependent())
165
272
      return CE->getChosenSubExpr();
166
275
  }
167
168
350M
  return E;
169
350M
}
170
171
} // namespace clang
172
173
#endif // LLVM_CLANG_AST_IGNOREEXPR_H