Coverage Report

Created: 2022-01-25 06:29

/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
371M
inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
24
template <typename FnTy, typename... FnTys>
25
624M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
624M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
624M
}
clang::Expr* clang::detail::IgnoreExprNodesImpl<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*))
Line
Count
Source
25
371M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
371M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
371M
}
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
252M
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
252M
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
252M
}
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
20.5k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
20.5k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
20.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
20.5k
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26
20.5k
  return IgnoreExprNodesImpl(Fn(E), std::forward<FnTys>(Fns)...);
27
20.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.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
294M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
294M
  Expr *LastE = nullptr;
35
665M
  while (E != LastE) {
36
371M
    LastE = E;
37
371M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
371M
  }
39
294M
  return E;
40
294M
}
clang::Expr* clang::IgnoreExprNodes<clang::Expr* (&)(clang::Expr*)>(clang::Expr*, clang::Expr* (&)(clang::Expr*))
Line
Count
Source
33
109M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
109M
  Expr *LastE = nullptr;
35
228M
  while (E != LastE) {
36
119M
    LastE = E;
37
119M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
119M
  }
39
109M
  return E;
40
109M
}
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
184M
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
184M
  Expr *LastE = nullptr;
35
436M
  while (E != LastE) {
36
252M
    LastE = E;
37
252M
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
252M
  }
39
184M
  return E;
40
184M
}
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
17.0k
template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
34
17.0k
  Expr *LastE = nullptr;
35
37.5k
  while (E != LastE) {
36
20.5k
    LastE = E;
37
20.5k
    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
38
20.5k
  }
39
17.0k
  return E;
40
17.0k
}
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
const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
44
  return IgnoreExprNodes(const_cast<Expr *>(E), std::forward<FnTys>(Fns)...);
45
}
46
47
179M
inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {
48
179M
  if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
49
48.7M
    return ICE->getSubExpr();
50
51
130M
  if (auto *FE = dyn_cast<FullExpr>(E))
52
277k
    return FE->getSubExpr();
53
54
130M
  return E;
55
130M
}
56
57
159M
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
159M
  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
62
159M
  if (SubE != E)
63
43.8M
    return SubE;
64
65
116M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
66
269k
    return MTE->getSubExpr();
67
68
115M
  if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
69
1.53M
    return NTTP->getReplacement();
70
71
114M
  return E;
72
115M
}
73
74
92.5M
inline Expr *IgnoreCastsSingleStep(Expr *E) {
75
92.5M
  if (auto *CE = dyn_cast<CastExpr>(E))
76
14.8M
    return CE->getSubExpr();
77
78
77.7M
  if (auto *FE = dyn_cast<FullExpr>(E))
79
96.4k
    return FE->getSubExpr();
80
81
77.6M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
82
29.1k
    return MTE->getSubExpr();
83
84
77.6M
  if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
85
278k
    return NTTP->getReplacement();
86
87
77.3M
  return E;
88
77.6M
}
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.27k
    if (CE->getCastKind() != CK_LValueToRValue)
95
287
      return E;
96
97
67.7k
  return IgnoreCastsSingleStep(E);
98
68.0k
}
99
100
41.2k
inline Expr *IgnoreBaseCastsSingleStep(Expr *E) {
101
41.2k
  if (auto *CE = dyn_cast<CastExpr>(E))
102
8.62k
    if (CE->getCastKind() == CK_DerivedToBase ||
103
8.62k
        
CE->getCastKind() == CK_UncheckedDerivedToBase8.53k
||
104
8.62k
        
CE->getCastKind() == CK_NoOp8.19k
)
105
4.44k
      return CE->getSubExpr();
106
107
36.8k
  return E;
108
41.2k
}
109
110
7.40M
inline Expr *IgnoreImplicitSingleStep(Expr *E) {
111
7.40M
  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
112
7.40M
  if (SubE != E)
113
2.05M
    return SubE;
114
115
5.34M
  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
116
790
    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
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
2.87k
inline Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E) {
137
2.87k
  if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
138
1.05k
    return ICE->getSubExprAsWritten();
139
140
1.81k
  return IgnoreImplicitSingleStep(E);
141
2.87k
}
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
352M
inline Expr *IgnoreParensSingleStep(Expr *E) {
150
352M
  if (auto *PE = dyn_cast<ParenExpr>(E))
151
11.2M
    return PE->getSubExpr();
152
153
340M
  if (auto *UO = dyn_cast<UnaryOperator>(E)) {
154
5.40M
    if (UO->getOpcode() == UO_Extension)
155
221k
      return UO->getSubExpr();
156
5.40M
  }
157
158
335M
  else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) {
159
981
    if (!GSE->isResultDependent())
160
971
      return GSE->getResultExpr();
161
981
  }
162
163
335M
  else if (auto *CE = dyn_cast<ChooseExpr>(E)) {
164
273
    if (!CE->isConditionDependent())
165
270
      return CE->getChosenSubExpr();
166
273
  }
167
168
340M
  return E;
169
340M
}
170
171
} // namespace clang
172
173
#endif // LLVM_CLANG_AST_IGNOREEXPR_H