/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Expr.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// |
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 implements the Expr class and subclasses. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/AST/Expr.h" |
14 | | #include "clang/AST/APValue.h" |
15 | | #include "clang/AST/ASTContext.h" |
16 | | #include "clang/AST/Attr.h" |
17 | | #include "clang/AST/ComputeDependence.h" |
18 | | #include "clang/AST/DeclCXX.h" |
19 | | #include "clang/AST/DeclObjC.h" |
20 | | #include "clang/AST/DeclTemplate.h" |
21 | | #include "clang/AST/DependenceFlags.h" |
22 | | #include "clang/AST/EvaluatedExprVisitor.h" |
23 | | #include "clang/AST/ExprCXX.h" |
24 | | #include "clang/AST/IgnoreExpr.h" |
25 | | #include "clang/AST/Mangle.h" |
26 | | #include "clang/AST/RecordLayout.h" |
27 | | #include "clang/AST/StmtVisitor.h" |
28 | | #include "clang/Basic/Builtins.h" |
29 | | #include "clang/Basic/CharInfo.h" |
30 | | #include "clang/Basic/SourceManager.h" |
31 | | #include "clang/Basic/TargetInfo.h" |
32 | | #include "clang/Lex/Lexer.h" |
33 | | #include "clang/Lex/LiteralSupport.h" |
34 | | #include "clang/Lex/Preprocessor.h" |
35 | | #include "llvm/Support/ErrorHandling.h" |
36 | | #include "llvm/Support/Format.h" |
37 | | #include "llvm/Support/raw_ostream.h" |
38 | | #include <algorithm> |
39 | | #include <cstring> |
40 | | #include <optional> |
41 | | using namespace clang; |
42 | | |
43 | 100k | const Expr *Expr::getBestDynamicClassTypeExpr() const { |
44 | 100k | const Expr *E = this; |
45 | 101k | while (true) { |
46 | 101k | E = E->IgnoreParenBaseCasts(); |
47 | | |
48 | | // Follow the RHS of a comma operator. |
49 | 101k | if (auto *BO = dyn_cast<BinaryOperator>(E)) { |
50 | 60 | if (BO->getOpcode() == BO_Comma) { |
51 | 18 | E = BO->getRHS(); |
52 | 18 | continue; |
53 | 18 | } |
54 | 60 | } |
55 | | |
56 | | // Step into initializer for materialized temporaries. |
57 | 100k | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) { |
58 | 294 | E = MTE->getSubExpr(); |
59 | 294 | continue; |
60 | 294 | } |
61 | | |
62 | 100k | break; |
63 | 100k | } |
64 | | |
65 | 100k | return E; |
66 | 100k | } |
67 | | |
68 | 52.3k | const CXXRecordDecl *Expr::getBestDynamicClassType() const { |
69 | 52.3k | const Expr *E = getBestDynamicClassTypeExpr(); |
70 | 52.3k | QualType DerivedType = E->getType(); |
71 | 52.3k | if (const PointerType *PTy = DerivedType->getAs<PointerType>()) |
72 | 46.4k | DerivedType = PTy->getPointeeType(); |
73 | | |
74 | 52.3k | if (DerivedType->isDependentType()) |
75 | 18.1k | return nullptr; |
76 | | |
77 | 34.1k | const RecordType *Ty = DerivedType->castAs<RecordType>(); |
78 | 34.1k | Decl *D = Ty->getDecl(); |
79 | 34.1k | return cast<CXXRecordDecl>(D); |
80 | 52.3k | } |
81 | | |
82 | | const Expr *Expr::skipRValueSubobjectAdjustments( |
83 | | SmallVectorImpl<const Expr *> &CommaLHSs, |
84 | 11.4M | SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { |
85 | 11.4M | const Expr *E = this; |
86 | 11.7M | while (true) { |
87 | 11.7M | E = E->IgnoreParens(); |
88 | | |
89 | 11.7M | if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { |
90 | 4.74M | if ((CE->getCastKind() == CK_DerivedToBase || |
91 | 4.74M | CE->getCastKind() == CK_UncheckedDerivedToBase4.73M ) && |
92 | 4.74M | E->getType()->isRecordType()3.95k ) { |
93 | 3.31k | E = CE->getSubExpr(); |
94 | 3.31k | auto *Derived = |
95 | 3.31k | cast<CXXRecordDecl>(E->getType()->castAs<RecordType>()->getDecl()); |
96 | 3.31k | Adjustments.push_back(SubobjectAdjustment(CE, Derived)); |
97 | 3.31k | continue; |
98 | 3.31k | } |
99 | | |
100 | 4.73M | if (CE->getCastKind() == CK_NoOp) { |
101 | 318k | E = CE->getSubExpr(); |
102 | 318k | continue; |
103 | 318k | } |
104 | 7.05M | } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { |
105 | 136k | if (!ME->isArrow()) { |
106 | 70.0k | assert(ME->getBase()->getType()->isRecordType()); |
107 | 70.0k | if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) { |
108 | 69.8k | if (!Field->isBitField() && !Field->getType()->isReferenceType()67.3k ) { |
109 | 65.9k | E = ME->getBase(); |
110 | 65.9k | Adjustments.push_back(SubobjectAdjustment(Field)); |
111 | 65.9k | continue; |
112 | 65.9k | } |
113 | 69.8k | } |
114 | 70.0k | } |
115 | 6.91M | } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { |
116 | 715k | if (BO->getOpcode() == BO_PtrMemD) { |
117 | 117 | assert(BO->getRHS()->isPRValue()); |
118 | 117 | E = BO->getLHS(); |
119 | 117 | const MemberPointerType *MPT = |
120 | 117 | BO->getRHS()->getType()->getAs<MemberPointerType>(); |
121 | 117 | Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); |
122 | 117 | continue; |
123 | 117 | } |
124 | 714k | if (BO->getOpcode() == BO_Comma) { |
125 | 2.25k | CommaLHSs.push_back(BO->getLHS()); |
126 | 2.25k | E = BO->getRHS(); |
127 | 2.25k | continue; |
128 | 2.25k | } |
129 | 714k | } |
130 | | |
131 | | // Nothing changed. |
132 | 11.4M | break; |
133 | 11.7M | } |
134 | 11.4M | return E; |
135 | 11.4M | } |
136 | | |
137 | 691k | bool Expr::isKnownToHaveBooleanValue(bool Semantic) const { |
138 | 691k | const Expr *E = IgnoreParens(); |
139 | | |
140 | | // If this value has _Bool type, it is obvious 0/1. |
141 | 691k | if (E->getType()->isBooleanType()) return true1.01k ; |
142 | | // If this is a non-scalar-integer type, we don't care enough to try. |
143 | 690k | if (!E->getType()->isIntegralOrEnumerationType()) return false50.8k ; |
144 | | |
145 | 639k | if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) { |
146 | 9.52k | switch (UO->getOpcode()) { |
147 | 2 | case UO_Plus: |
148 | 2 | return UO->getSubExpr()->isKnownToHaveBooleanValue(Semantic); |
149 | 126 | case UO_LNot: |
150 | 126 | return true; |
151 | 9.40k | default: |
152 | 9.40k | return false; |
153 | 9.52k | } |
154 | 9.52k | } |
155 | | |
156 | | // Only look through implicit casts. If the user writes |
157 | | // '(int) (a && b)' treat it as an arbitrary int. |
158 | | // FIXME: Should we look through any cast expression in !Semantic mode? |
159 | 629k | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) |
160 | 131k | return CE->getSubExpr()->isKnownToHaveBooleanValue(Semantic); |
161 | | |
162 | 498k | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { |
163 | 75.8k | switch (BO->getOpcode()) { |
164 | 25.2k | default: return false; |
165 | 54 | case BO_LT: // Relational operators. |
166 | 70 | case BO_GT: |
167 | 72 | case BO_LE: |
168 | 73 | case BO_GE: |
169 | 141 | case BO_EQ: // Equality operators. |
170 | 170 | case BO_NE: |
171 | 584 | case BO_LAnd: // AND operator. |
172 | 616 | case BO_LOr: // Logical OR operator. |
173 | 616 | return true; |
174 | | |
175 | 8.47k | case BO_And: // Bitwise AND operator. |
176 | 8.49k | case BO_Xor: // Bitwise XOR operator. |
177 | 49.6k | case BO_Or: // Bitwise OR operator. |
178 | | // Handle things like (x==2)|(y==12). |
179 | 49.6k | return BO->getLHS()->isKnownToHaveBooleanValue(Semantic) && |
180 | 49.6k | BO->getRHS()->isKnownToHaveBooleanValue(Semantic)8 ; |
181 | | |
182 | 28 | case BO_Comma: |
183 | 328 | case BO_Assign: |
184 | 328 | return BO->getRHS()->isKnownToHaveBooleanValue(Semantic); |
185 | 75.8k | } |
186 | 75.8k | } |
187 | | |
188 | 422k | if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) |
189 | 6 | return CO->getTrueExpr()->isKnownToHaveBooleanValue(Semantic) && |
190 | 6 | CO->getFalseExpr()->isKnownToHaveBooleanValue(Semantic)0 ; |
191 | | |
192 | 422k | if (isa<ObjCBoolLiteralExpr>(E)) |
193 | 3 | return true; |
194 | | |
195 | 422k | if (const auto *OVE = dyn_cast<OpaqueValueExpr>(E)) |
196 | 0 | return OVE->getSourceExpr()->isKnownToHaveBooleanValue(Semantic); |
197 | | |
198 | 422k | if (const FieldDecl *FD = E->getSourceBitField()) |
199 | 739 | if (!Semantic && FD->getType()->isUnsignedIntegerType()26 && |
200 | 739 | !FD->getBitWidth()->isValueDependent()22 && |
201 | 739 | FD->getBitWidthValue(FD->getASTContext()) == 122 ) |
202 | 11 | return true; |
203 | | |
204 | 422k | return false; |
205 | 422k | } |
206 | | |
207 | | bool Expr::isFlexibleArrayMemberLike( |
208 | | ASTContext &Context, |
209 | | LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, |
210 | 59.1k | bool IgnoreTemplateOrMacroSubstitution) const { |
211 | | |
212 | | // For compatibility with existing code, we treat arrays of length 0 or |
213 | | // 1 as flexible array members. |
214 | 59.1k | const auto *CAT = Context.getAsConstantArrayType(getType()); |
215 | 59.1k | if (CAT) { |
216 | 59.0k | llvm::APInt Size = CAT->getSize(); |
217 | | |
218 | 59.0k | using FAMKind = LangOptions::StrictFlexArraysLevelKind; |
219 | | |
220 | 59.0k | if (StrictFlexArraysLevel == FAMKind::IncompleteOnly) |
221 | 88 | return false; |
222 | | |
223 | | // GCC extension, only allowed to represent a FAM. |
224 | 59.0k | if (Size == 0) |
225 | 2.03k | return true; |
226 | | |
227 | 56.9k | if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete && Size.uge(1)72 ) |
228 | 72 | return false; |
229 | | |
230 | 56.8k | if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete && Size.uge(2)66 ) |
231 | 33 | return false; |
232 | 56.8k | } else if (18 !Context.getAsIncompleteArrayType(getType())18 ) |
233 | 1 | return false; |
234 | | |
235 | 56.8k | const Expr *E = IgnoreParens(); |
236 | | |
237 | 56.8k | const NamedDecl *ND = nullptr; |
238 | 56.8k | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
239 | 40.5k | ND = DRE->getDecl(); |
240 | 16.3k | else if (const auto *ME = dyn_cast<MemberExpr>(E)) |
241 | 14.3k | ND = ME->getMemberDecl(); |
242 | 1.97k | else if (const auto *IRE = dyn_cast<ObjCIvarRefExpr>(E)) |
243 | 27 | return IRE->getDecl()->getNextIvar() == nullptr; |
244 | | |
245 | 56.8k | if (!ND) |
246 | 1.95k | return false; |
247 | | |
248 | | // A flexible array member must be the last member in the class. |
249 | | // FIXME: If the base type of the member expr is not FD->getParent(), |
250 | | // this should not be treated as a flexible array member access. |
251 | 54.9k | if (const auto *FD = dyn_cast<FieldDecl>(ND)) { |
252 | | // GCC treats an array memeber of a union as an FAM if the size is one or |
253 | | // zero. |
254 | 14.3k | if (CAT) { |
255 | 14.3k | llvm::APInt Size = CAT->getSize(); |
256 | 14.3k | if (FD->getParent()->isUnion() && (99 Size.isZero()99 || Size.isOne()99 )) |
257 | 19 | return true; |
258 | 14.3k | } |
259 | | |
260 | | // Don't consider sizes resulting from macro expansions or template argument |
261 | | // substitution to form C89 tail-padded arrays. |
262 | 14.3k | if (IgnoreTemplateOrMacroSubstitution) { |
263 | 14.2k | TypeSourceInfo *TInfo = FD->getTypeSourceInfo(); |
264 | 14.2k | while (TInfo) { |
265 | 14.2k | TypeLoc TL = TInfo->getTypeLoc(); |
266 | | // Look through typedefs. |
267 | 14.2k | if (TypedefTypeLoc TTL = TL.getAsAdjusted<TypedefTypeLoc>()) { |
268 | 2 | const TypedefNameDecl *TDL = TTL.getTypedefNameDecl(); |
269 | 2 | TInfo = TDL->getTypeSourceInfo(); |
270 | 2 | continue; |
271 | 2 | } |
272 | 14.2k | if (ConstantArrayTypeLoc CTL = TL.getAs<ConstantArrayTypeLoc>()) { |
273 | 14.2k | const Expr *SizeExpr = dyn_cast<IntegerLiteral>(CTL.getSizeExpr()); |
274 | 14.2k | if (!SizeExpr || SizeExpr->getExprLoc().isMacroID()7.85k ) |
275 | 6.66k | return false; |
276 | 14.2k | } |
277 | 7.58k | break; |
278 | 14.2k | } |
279 | 14.2k | } |
280 | | |
281 | 7.64k | RecordDecl::field_iterator FI( |
282 | 7.64k | DeclContext::decl_iterator(const_cast<FieldDecl *>(FD))); |
283 | 7.64k | return ++FI == FD->getParent()->field_end(); |
284 | 14.3k | } |
285 | | |
286 | 40.5k | return false; |
287 | 54.9k | } |
288 | | |
289 | | const ValueDecl * |
290 | 26 | Expr::getAsBuiltinConstantDeclRef(const ASTContext &Context) const { |
291 | 26 | Expr::EvalResult Eval; |
292 | | |
293 | 26 | if (EvaluateAsConstantExpr(Eval, Context)) { |
294 | 24 | APValue &Value = Eval.Val; |
295 | | |
296 | 24 | if (Value.isMemberPointer()) |
297 | 8 | return Value.getMemberPointerDecl(); |
298 | | |
299 | 16 | if (Value.isLValue() && Value.getLValueOffset().isZero()) |
300 | 16 | return Value.getLValueBase().dyn_cast<const ValueDecl *>(); |
301 | 16 | } |
302 | | |
303 | 2 | return nullptr; |
304 | 26 | } |
305 | | |
306 | | // Amusing macro metaprogramming hack: check whether a class provides |
307 | | // a more specific implementation of getExprLoc(). |
308 | | // |
309 | | // See also Stmt.cpp:{getBeginLoc(),getEndLoc()}. |
310 | | namespace { |
311 | | /// This implementation is used when a class provides a custom |
312 | | /// implementation of getExprLoc. |
313 | | template <class E, class T> |
314 | | SourceLocation getExprLocImpl(const Expr *expr, |
315 | 23.8M | SourceLocation (T::*v)() const) { |
316 | 23.8M | return static_cast<const E*>(expr)->getExprLoc(); |
317 | 23.8M | } Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArraySubscriptExpr, clang::ArraySubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::ArraySubscriptExpr::*)() const) Line | Count | Source | 315 | 574k | SourceLocation (T::*v)() const) { | 316 | 574k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 574k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BinaryOperator, clang::BinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::BinaryOperator::*)() const) Line | Count | Source | 315 | 12.6M | SourceLocation (T::*v)() const) { | 316 | 12.6M | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 12.6M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CompoundAssignOperator, clang::BinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::BinaryOperator::*)() const) Line | Count | Source | 315 | 408k | SourceLocation (T::*v)() const) { | 316 | 408k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 408k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDefaultArgExpr, clang::CXXDefaultArgExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXDefaultArgExpr::*)() const) Line | Count | Source | 315 | 64.1k | SourceLocation (T::*v)() const) { | 316 | 64.1k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 64.1k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXRewrittenBinaryOperator, clang::CXXRewrittenBinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::CXXRewrittenBinaryOperator::*)() const) Line | Count | Source | 315 | 587 | SourceLocation (T::*v)() const) { | 316 | 587 | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 587 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXMemberCallExpr, clang::CXXMemberCallExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXMemberCallExpr::*)() const) Line | Count | Source | 315 | 1.56M | SourceLocation (T::*v)() const) { | 316 | 1.56M | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 1.56M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXOperatorCallExpr, clang::CXXOperatorCallExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXOperatorCallExpr::*)() const) Line | Count | Source | 315 | 923k | SourceLocation (T::*v)() const) { | 316 | 923k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 923k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MSPropertySubscriptExpr, clang::MSPropertySubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::MSPropertySubscriptExpr::*)() const) Line | Count | Source | 315 | 618 | SourceLocation (T::*v)() const) { | 316 | 618 | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 618 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MatrixSubscriptExpr, clang::MatrixSubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::MatrixSubscriptExpr::*)() const) Line | Count | Source | 315 | 167 | SourceLocation (T::*v)() const) { | 316 | 167 | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 167 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MemberExpr, clang::MemberExpr>(clang::Expr const*, clang::SourceLocation (clang::MemberExpr::*)() const) Line | Count | Source | 315 | 3.23M | SourceLocation (T::*v)() const) { | 316 | 3.23M | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 3.23M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPArraySectionExpr, clang::OMPArraySectionExpr>(clang::Expr const*, clang::SourceLocation (clang::OMPArraySectionExpr::*)() const) Line | Count | Source | 315 | 58.8k | SourceLocation (T::*v)() const) { | 316 | 58.8k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 58.8k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIndirectCopyRestoreExpr, clang::ObjCIndirectCopyRestoreExpr>(clang::Expr const*, clang::SourceLocation (clang::ObjCIndirectCopyRestoreExpr::*)() const) Line | Count | Source | 315 | 161 | SourceLocation (T::*v)() const) { | 316 | 161 | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 161 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIsaExpr, clang::ObjCIsaExpr>(clang::Expr const*, clang::SourceLocation (clang::ObjCIsaExpr::*)() const) Line | Count | Source | 315 | 178 | SourceLocation (T::*v)() const) { | 316 | 178 | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 178 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OpaqueValueExpr, clang::OpaqueValueExpr>(clang::Expr const*, clang::SourceLocation (clang::OpaqueValueExpr::*)() const) Line | Count | Source | 315 | 98.1k | SourceLocation (T::*v)() const) { | 316 | 98.1k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 98.1k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnresolvedMemberExpr, clang::UnresolvedMemberExpr>(clang::Expr const*, clang::SourceLocation (clang::UnresolvedMemberExpr::*)() const) Line | Count | Source | 315 | 381 | SourceLocation (T::*v)() const) { | 316 | 381 | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 381 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PseudoObjectExpr, clang::PseudoObjectExpr>(clang::Expr const*, clang::SourceLocation (clang::PseudoObjectExpr::*)() const) Line | Count | Source | 315 | 13.7k | SourceLocation (T::*v)() const) { | 316 | 13.7k | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 13.7k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnaryOperator, clang::UnaryOperator>(clang::Expr const*, clang::SourceLocation (clang::UnaryOperator::*)() const) Line | Count | Source | 315 | 4.23M | SourceLocation (T::*v)() const) { | 316 | 4.23M | return static_cast<const E*>(expr)->getExprLoc(); | 317 | 4.23M | } |
|
318 | | |
319 | | /// This implementation is used when a class doesn't provide |
320 | | /// a custom implementation of getExprLoc. Overload resolution |
321 | | /// should pick it over the implementation above because it's |
322 | | /// more specialized according to function template partial ordering. |
323 | | template <class E> |
324 | | SourceLocation getExprLocImpl(const Expr *expr, |
325 | 103M | SourceLocation (Expr::*v)() const) { |
326 | 103M | return static_cast<const E *>(expr)->getBeginLoc(); |
327 | 103M | } Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BinaryConditionalOperator>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 316 | SourceLocation (Expr::*v)() const) { | 326 | 316 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 316 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConditionalOperator>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 352k | SourceLocation (Expr::*v)() const) { | 326 | 352k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 352k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AddrLabelExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 761 | SourceLocation (Expr::*v)() const) { | 326 | 761 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 761 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayInitIndexExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 165 | SourceLocation (Expr::*v)() const) { | 326 | 165 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 165 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayInitLoopExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 209 | SourceLocation (Expr::*v)() const) { | 326 | 209 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 209 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayTypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 544 | SourceLocation (Expr::*v)() const) { | 326 | 544 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 544 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AsTypeExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 103 | SourceLocation (Expr::*v)() const) { | 326 | 103 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 103 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AtomicExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 16.0k | SourceLocation (Expr::*v)() const) { | 326 | 16.0k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 16.0k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BlockExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 7.64k | SourceLocation (Expr::*v)() const) { | 326 | 7.64k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 7.64k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXBindTemporaryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 78.4k | SourceLocation (Expr::*v)() const) { | 326 | 78.4k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 78.4k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXBoolLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.22M | SourceLocation (Expr::*v)() const) { | 326 | 1.22M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.22M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXConstructExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 843k | SourceLocation (Expr::*v)() const) { | 326 | 843k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 843k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXTemporaryObjectExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 420k | SourceLocation (Expr::*v)() const) { | 326 | 420k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 420k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDefaultInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.99k | SourceLocation (Expr::*v)() const) { | 326 | 2.99k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.99k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDeleteExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 17.4k | SourceLocation (Expr::*v)() const) { | 326 | 17.4k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 17.4k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDependentScopeMemberExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 118k | SourceLocation (Expr::*v)() const) { | 326 | 118k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 118k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXFoldExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 175 | SourceLocation (Expr::*v)() const) { | 326 | 175 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 175 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXInheritedCtorInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 257 | SourceLocation (Expr::*v)() const) { | 326 | 257 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 257 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNewExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 61.8k | SourceLocation (Expr::*v)() const) { | 326 | 61.8k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 61.8k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNoexceptExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 13.4k | SourceLocation (Expr::*v)() const) { | 326 | 13.4k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 13.4k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNullPtrLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 348k | SourceLocation (Expr::*v)() const) { | 326 | 348k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 348k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXParenListInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 294 | SourceLocation (Expr::*v)() const) { | 326 | 294 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 294 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXPseudoDestructorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 651 | SourceLocation (Expr::*v)() const) { | 326 | 651 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 651 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXScalarValueInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 24.4k | SourceLocation (Expr::*v)() const) { | 326 | 24.4k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 24.4k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXStdInitializerListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.65k | SourceLocation (Expr::*v)() const) { | 326 | 2.65k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.65k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXThisExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.21M | SourceLocation (Expr::*v)() const) { | 326 | 2.21M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.21M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXThrowExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 54.3k | SourceLocation (Expr::*v)() const) { | 326 | 54.3k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 54.3k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXTypeidExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 5.77k | SourceLocation (Expr::*v)() const) { | 326 | 5.77k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 5.77k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXUnresolvedConstructExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 10.2k | SourceLocation (Expr::*v)() const) { | 326 | 10.2k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 10.2k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXUuidofExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 295 | SourceLocation (Expr::*v)() const) { | 326 | 295 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 295 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CallExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 19.3M | SourceLocation (Expr::*v)() const) { | 326 | 19.3M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 19.3M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CUDAKernelCallExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.18k | SourceLocation (Expr::*v)() const) { | 326 | 1.18k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.18k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UserDefinedLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 3.55k | SourceLocation (Expr::*v)() const) { | 326 | 3.55k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 3.55k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BuiltinBitCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.23k | SourceLocation (Expr::*v)() const) { | 326 | 2.23k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.23k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CStyleCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 8.09M | SourceLocation (Expr::*v)() const) { | 326 | 8.09M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 8.09M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXFunctionalCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 69.3k | SourceLocation (Expr::*v)() const) { | 326 | 69.3k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 69.3k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXAddrspaceCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 5 | SourceLocation (Expr::*v)() const) { | 326 | 5 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 5 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXConstCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 587 | SourceLocation (Expr::*v)() const) { | 326 | 587 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 587 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDynamicCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 538 | SourceLocation (Expr::*v)() const) { | 326 | 538 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 538 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXReinterpretCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 3.64k | SourceLocation (Expr::*v)() const) { | 326 | 3.64k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 3.64k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXStaticCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 59.6k | SourceLocation (Expr::*v)() const) { | 326 | 59.6k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 59.6k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBridgedCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 298 | SourceLocation (Expr::*v)() const) { | 326 | 298 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 298 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImplicitCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 14.2M | SourceLocation (Expr::*v)() const) { | 326 | 14.2M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 14.2M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CharacterLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 817k | SourceLocation (Expr::*v)() const) { | 326 | 817k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 817k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ChooseExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 31 | SourceLocation (Expr::*v)() const) { | 326 | 31 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 31 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CompoundLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 90.7k | SourceLocation (Expr::*v)() const) { | 326 | 90.7k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 90.7k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConceptSpecializationExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 12.0k | SourceLocation (Expr::*v)() const) { | 326 | 12.0k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 12.0k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConvertVectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 27.2k | SourceLocation (Expr::*v)() const) { | 326 | 27.2k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 27.2k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CoawaitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.84k | SourceLocation (Expr::*v)() const) { | 326 | 2.84k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.84k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CoyieldExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 378 | SourceLocation (Expr::*v)() const) { | 326 | 378 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 378 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DeclRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 34.2M | SourceLocation (Expr::*v)() const) { | 326 | 34.2M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 34.2M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DependentCoawaitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 93 | SourceLocation (Expr::*v)() const) { | 326 | 93 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 93 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DependentScopeDeclRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 3.01k | SourceLocation (Expr::*v)() const) { | 326 | 3.01k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 3.01k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DesignatedInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 10 | SourceLocation (Expr::*v)() const) { | 326 | 10 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 10 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DesignatedInitUpdateExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 75 | SourceLocation (Expr::*v)() const) { | 326 | 75 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 75 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExpressionTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 24 | SourceLocation (Expr::*v)() const) { | 326 | 24 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 24 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExtVectorElementExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.72k | SourceLocation (Expr::*v)() const) { | 326 | 1.72k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.72k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FixedPointLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.69k | SourceLocation (Expr::*v)() const) { | 326 | 1.69k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.69k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FloatingLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 148k | SourceLocation (Expr::*v)() const) { | 326 | 148k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 148k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConstantExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 276k | SourceLocation (Expr::*v)() const) { | 326 | 276k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 276k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExprWithCleanups>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 29.5k | SourceLocation (Expr::*v)() const) { | 326 | 29.5k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 29.5k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FunctionParmPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 190 | SourceLocation (Expr::*v)() const) { | 326 | 190 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 190 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::GNUNullExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 5.89k | SourceLocation (Expr::*v)() const) { | 326 | 5.89k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 5.89k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::GenericSelectionExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 158 | SourceLocation (Expr::*v)() const) { | 326 | 158 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 158 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImaginaryLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 576 | SourceLocation (Expr::*v)() const) { | 326 | 576 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 576 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImplicitValueInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 19.7k | SourceLocation (Expr::*v)() const) { | 326 | 19.7k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 19.7k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::InitListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 145k | SourceLocation (Expr::*v)() const) { | 326 | 145k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 145k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::IntegerLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 14.1M | SourceLocation (Expr::*v)() const) { | 326 | 14.1M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 14.1M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::LambdaExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 48.6k | SourceLocation (Expr::*v)() const) { | 326 | 48.6k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 48.6k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MSPropertyRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 763 | SourceLocation (Expr::*v)() const) { | 326 | 763 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 763 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MaterializeTemporaryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 198k | SourceLocation (Expr::*v)() const) { | 326 | 198k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 198k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::NoInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 102 | SourceLocation (Expr::*v)() const) { | 326 | 102 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 102 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPArrayShapingExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 459 | SourceLocation (Expr::*v)() const) { | 326 | 459 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 459 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPIteratorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 8 | SourceLocation (Expr::*v)() const) { | 326 | 8 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 8 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCArrayLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 689 | SourceLocation (Expr::*v)() const) { | 326 | 689 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 689 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCAvailabilityCheckExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 285 | SourceLocation (Expr::*v)() const) { | 326 | 285 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 285 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBoolLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.25k | SourceLocation (Expr::*v)() const) { | 326 | 2.25k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.25k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBoxedExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 3.66k | SourceLocation (Expr::*v)() const) { | 326 | 3.66k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 3.66k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCDictionaryLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 509 | SourceLocation (Expr::*v)() const) { | 326 | 509 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 509 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCEncodeExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 374 | SourceLocation (Expr::*v)() const) { | 326 | 374 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 374 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIvarRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 8.11k | SourceLocation (Expr::*v)() const) { | 326 | 8.11k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 8.11k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCMessageExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 78.8k | SourceLocation (Expr::*v)() const) { | 326 | 78.8k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 78.8k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCPropertyRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 6.82k | SourceLocation (Expr::*v)() const) { | 326 | 6.82k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 6.82k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCProtocolExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 96 | SourceLocation (Expr::*v)() const) { | 326 | 96 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 96 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCSelectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 786 | SourceLocation (Expr::*v)() const) { | 326 | 786 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 786 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCStringLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 18.2k | SourceLocation (Expr::*v)() const) { | 326 | 18.2k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 18.2k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCSubscriptRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 670 | SourceLocation (Expr::*v)() const) { | 326 | 670 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 670 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OffsetOfExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.31k | SourceLocation (Expr::*v)() const) { | 326 | 1.31k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.31k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnresolvedLookupExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.56M | SourceLocation (Expr::*v)() const) { | 326 | 1.56M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.56M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PackExpansionExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 31 | SourceLocation (Expr::*v)() const) { | 326 | 31 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 31 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ParenExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 766k | SourceLocation (Expr::*v)() const) { | 326 | 766k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 766k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ParenListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 7.44k | SourceLocation (Expr::*v)() const) { | 326 | 7.44k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 7.44k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PredefinedExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 2.11k | SourceLocation (Expr::*v)() const) { | 326 | 2.11k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 2.11k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::RecoveryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 15.8k | SourceLocation (Expr::*v)() const) { | 326 | 15.8k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 15.8k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::RequiresExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 3.89k | SourceLocation (Expr::*v)() const) { | 326 | 3.89k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 3.89k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SYCLUniqueStableNameExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 167 | SourceLocation (Expr::*v)() const) { | 326 | 167 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 167 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ShuffleVectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 414k | SourceLocation (Expr::*v)() const) { | 326 | 414k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 414k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SizeOfPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 55.4k | SourceLocation (Expr::*v)() const) { | 326 | 55.4k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 55.4k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SourceLocExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.93k | SourceLocation (Expr::*v)() const) { | 326 | 1.93k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.93k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::StmtExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 10.8k | SourceLocation (Expr::*v)() const) { | 326 | 10.8k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 10.8k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::StringLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 449k | SourceLocation (Expr::*v)() const) { | 326 | 449k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 449k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SubstNonTypeTemplateParmExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 1.55M | SourceLocation (Expr::*v)() const) { | 326 | 1.55M | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 1.55M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SubstNonTypeTemplateParmPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 9 | SourceLocation (Expr::*v)() const) { | 326 | 9 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 9 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::TypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 534k | SourceLocation (Expr::*v)() const) { | 326 | 534k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 534k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::TypoExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 110 | SourceLocation (Expr::*v)() const) { | 326 | 110 | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 110 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnaryExprOrTypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 254k | SourceLocation (Expr::*v)() const) { | 326 | 254k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 254k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::VAArgExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 325 | 3.31k | SourceLocation (Expr::*v)() const) { | 326 | 3.31k | return static_cast<const E *>(expr)->getBeginLoc(); | 327 | 3.31k | } |
|
328 | | } |
329 | | |
330 | 127M | SourceLocation Expr::getExprLoc() const { |
331 | 127M | switch (getStmtClass()) { |
332 | 0 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
333 | 0 | #define ABSTRACT_STMT(type) |
334 | 0 | #define STMT(type, base) \ |
335 | 0 | case Stmt::type##Class: break; |
336 | 0 | #define EXPR(type, base) \ |
337 | 127M | case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); |
338 | 127M | #include "clang/AST/StmtNodes.inc"0 |
339 | 127M | } |
340 | 0 | llvm_unreachable("unknown expression kind"); |
341 | 0 | } |
342 | | |
343 | | //===----------------------------------------------------------------------===// |
344 | | // Primary Expressions. |
345 | | //===----------------------------------------------------------------------===// |
346 | | |
347 | 6.13M | static void AssertResultStorageKind(ConstantExpr::ResultStorageKind Kind) { |
348 | 6.13M | assert((Kind == ConstantExpr::RSK_APValue || |
349 | 6.13M | Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) && |
350 | 6.13M | "Invalid StorageKind Value"); |
351 | 6.13M | (void)Kind; |
352 | 6.13M | } |
353 | | |
354 | | ConstantExpr::ResultStorageKind |
355 | 12.0M | ConstantExpr::getStorageKind(const APValue &Value) { |
356 | 12.0M | switch (Value.getKind()) { |
357 | 14.9k | case APValue::None: |
358 | 14.9k | case APValue::Indeterminate: |
359 | 14.9k | return ConstantExpr::RSK_None; |
360 | 11.9M | case APValue::Int: |
361 | 11.9M | if (!Value.getInt().needsCleanup()) |
362 | 11.9M | return ConstantExpr::RSK_Int64; |
363 | 11.9M | [[fallthrough]];119 |
364 | 6.82k | default: |
365 | 6.82k | return ConstantExpr::RSK_APValue; |
366 | 12.0M | } |
367 | 12.0M | } |
368 | | |
369 | | ConstantExpr::ResultStorageKind |
370 | 502 | ConstantExpr::getStorageKind(const Type *T, const ASTContext &Context) { |
371 | 502 | if (T->isIntegralOrEnumerationType() && Context.getTypeInfo(T).Width <= 64144 ) |
372 | 141 | return ConstantExpr::RSK_Int64; |
373 | 361 | return ConstantExpr::RSK_APValue; |
374 | 502 | } |
375 | | |
376 | | ConstantExpr::ConstantExpr(Expr *SubExpr, ResultStorageKind StorageKind, |
377 | | bool IsImmediateInvocation) |
378 | 6.01M | : FullExpr(ConstantExprClass, SubExpr) { |
379 | 6.01M | ConstantExprBits.ResultKind = StorageKind; |
380 | 6.01M | ConstantExprBits.APValueKind = APValue::None; |
381 | 6.01M | ConstantExprBits.IsUnsigned = false; |
382 | 6.01M | ConstantExprBits.BitWidth = 0; |
383 | 6.01M | ConstantExprBits.HasCleanup = false; |
384 | 6.01M | ConstantExprBits.IsImmediateInvocation = IsImmediateInvocation; |
385 | | |
386 | 6.01M | if (StorageKind == ConstantExpr::RSK_APValue) |
387 | 3.64k | ::new (getTrailingObjects<APValue>()) APValue(); |
388 | 6.01M | } |
389 | | |
390 | | ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E, |
391 | | ResultStorageKind StorageKind, |
392 | 6.01M | bool IsImmediateInvocation) { |
393 | 6.01M | assert(!isa<ConstantExpr>(E)); |
394 | 6.01M | AssertResultStorageKind(StorageKind); |
395 | | |
396 | 6.01M | unsigned Size = totalSizeToAlloc<APValue, uint64_t>( |
397 | 6.01M | StorageKind == ConstantExpr::RSK_APValue, |
398 | 6.01M | StorageKind == ConstantExpr::RSK_Int64); |
399 | 6.01M | void *Mem = Context.Allocate(Size, alignof(ConstantExpr)); |
400 | 6.01M | return new (Mem) ConstantExpr(E, StorageKind, IsImmediateInvocation); |
401 | 6.01M | } |
402 | | |
403 | | ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E, |
404 | 6.00M | const APValue &Result) { |
405 | 6.00M | ResultStorageKind StorageKind = getStorageKind(Result); |
406 | 6.00M | ConstantExpr *Self = Create(Context, E, StorageKind); |
407 | 6.00M | Self->SetResult(Result, Context); |
408 | 6.00M | return Self; |
409 | 6.00M | } |
410 | | |
411 | | ConstantExpr::ConstantExpr(EmptyShell Empty, ResultStorageKind StorageKind) |
412 | 115k | : FullExpr(ConstantExprClass, Empty) { |
413 | 115k | ConstantExprBits.ResultKind = StorageKind; |
414 | | |
415 | 115k | if (StorageKind == ConstantExpr::RSK_APValue) |
416 | 34 | ::new (getTrailingObjects<APValue>()) APValue(); |
417 | 115k | } |
418 | | |
419 | | ConstantExpr *ConstantExpr::CreateEmpty(const ASTContext &Context, |
420 | 115k | ResultStorageKind StorageKind) { |
421 | 115k | AssertResultStorageKind(StorageKind); |
422 | | |
423 | 115k | unsigned Size = totalSizeToAlloc<APValue, uint64_t>( |
424 | 115k | StorageKind == ConstantExpr::RSK_APValue, |
425 | 115k | StorageKind == ConstantExpr::RSK_Int64); |
426 | 115k | void *Mem = Context.Allocate(Size, alignof(ConstantExpr)); |
427 | 115k | return new (Mem) ConstantExpr(EmptyShell(), StorageKind); |
428 | 115k | } |
429 | | |
430 | 6.00M | void ConstantExpr::MoveIntoResult(APValue &Value, const ASTContext &Context) { |
431 | 6.00M | assert((unsigned)getStorageKind(Value) <= ConstantExprBits.ResultKind && |
432 | 6.00M | "Invalid storage for this value kind"); |
433 | 6.00M | ConstantExprBits.APValueKind = Value.getKind(); |
434 | 6.00M | switch (ConstantExprBits.ResultKind) { |
435 | 7.46k | case RSK_None: |
436 | 7.46k | return; |
437 | 5.99M | case RSK_Int64: |
438 | 5.99M | Int64Result() = *Value.getInt().getRawData(); |
439 | 5.99M | ConstantExprBits.BitWidth = Value.getInt().getBitWidth(); |
440 | 5.99M | ConstantExprBits.IsUnsigned = Value.getInt().isUnsigned(); |
441 | 5.99M | return; |
442 | 3.55k | case RSK_APValue: |
443 | 3.55k | if (!ConstantExprBits.HasCleanup && Value.needsCleanup()) { |
444 | 706 | ConstantExprBits.HasCleanup = true; |
445 | 706 | Context.addDestruction(&APValueResult()); |
446 | 706 | } |
447 | 3.55k | APValueResult() = std::move(Value); |
448 | 3.55k | return; |
449 | 6.00M | } |
450 | 0 | llvm_unreachable("Invalid ResultKind Bits"); |
451 | 0 | } |
452 | | |
453 | 0 | llvm::APSInt ConstantExpr::getResultAsAPSInt() const { |
454 | 0 | switch (ConstantExprBits.ResultKind) { |
455 | 0 | case ConstantExpr::RSK_APValue: |
456 | 0 | return APValueResult().getInt(); |
457 | 0 | case ConstantExpr::RSK_Int64: |
458 | 0 | return llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()), |
459 | 0 | ConstantExprBits.IsUnsigned); |
460 | 0 | default: |
461 | 0 | llvm_unreachable("invalid Accessor"); |
462 | 0 | } |
463 | 0 | } |
464 | | |
465 | 310k | APValue ConstantExpr::getAPValueResult() const { |
466 | | |
467 | 310k | switch (ConstantExprBits.ResultKind) { |
468 | 288 | case ConstantExpr::RSK_APValue: |
469 | 288 | return APValueResult(); |
470 | 310k | case ConstantExpr::RSK_Int64: |
471 | 310k | return APValue( |
472 | 310k | llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()), |
473 | 310k | ConstantExprBits.IsUnsigned)); |
474 | 4 | case ConstantExpr::RSK_None: |
475 | 4 | if (ConstantExprBits.APValueKind == APValue::Indeterminate) |
476 | 0 | return APValue::IndeterminateValue(); |
477 | 4 | return APValue(); |
478 | 310k | } |
479 | 0 | llvm_unreachable("invalid ResultKind"); |
480 | 0 | } |
481 | | |
482 | | DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, ValueDecl *D, |
483 | | bool RefersToEnclosingVariableOrCapture, QualType T, |
484 | | ExprValueKind VK, SourceLocation L, |
485 | | const DeclarationNameLoc &LocInfo, |
486 | | NonOdrUseReason NOUR) |
487 | 1.15M | : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D), DNLoc(LocInfo) { |
488 | 1.15M | DeclRefExprBits.HasQualifier = false; |
489 | 1.15M | DeclRefExprBits.HasTemplateKWAndArgsInfo = false; |
490 | 1.15M | DeclRefExprBits.HasFoundDecl = false; |
491 | 1.15M | DeclRefExprBits.HadMultipleCandidates = false; |
492 | 1.15M | DeclRefExprBits.RefersToEnclosingVariableOrCapture = |
493 | 1.15M | RefersToEnclosingVariableOrCapture; |
494 | 1.15M | DeclRefExprBits.NonOdrUseReason = NOUR; |
495 | 1.15M | DeclRefExprBits.Loc = L; |
496 | 1.15M | setDependence(computeDependence(this, Ctx)); |
497 | 1.15M | } |
498 | | |
499 | | DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, |
500 | | NestedNameSpecifierLoc QualifierLoc, |
501 | | SourceLocation TemplateKWLoc, ValueDecl *D, |
502 | | bool RefersToEnclosingVariableOrCapture, |
503 | | const DeclarationNameInfo &NameInfo, NamedDecl *FoundD, |
504 | | const TemplateArgumentListInfo *TemplateArgs, |
505 | | QualType T, ExprValueKind VK, NonOdrUseReason NOUR) |
506 | | : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D), |
507 | 27.8M | DNLoc(NameInfo.getInfo()) { |
508 | 27.8M | DeclRefExprBits.Loc = NameInfo.getLoc(); |
509 | 27.8M | DeclRefExprBits.HasQualifier = QualifierLoc ? 12.43M : 025.4M ; |
510 | 27.8M | if (QualifierLoc) |
511 | 2.43M | new (getTrailingObjects<NestedNameSpecifierLoc>()) |
512 | 2.43M | NestedNameSpecifierLoc(QualifierLoc); |
513 | 27.8M | DeclRefExprBits.HasFoundDecl = FoundD ? 1553k : 027.2M ; |
514 | 27.8M | if (FoundD) |
515 | 553k | *getTrailingObjects<NamedDecl *>() = FoundD; |
516 | 27.8M | DeclRefExprBits.HasTemplateKWAndArgsInfo |
517 | 27.8M | = (TemplateArgs || TemplateKWLoc.isValid()27.4M ) ? 1357k : 027.4M ; |
518 | 27.8M | DeclRefExprBits.RefersToEnclosingVariableOrCapture = |
519 | 27.8M | RefersToEnclosingVariableOrCapture; |
520 | 27.8M | DeclRefExprBits.NonOdrUseReason = NOUR; |
521 | 27.8M | if (TemplateArgs) { |
522 | 357k | auto Deps = TemplateArgumentDependence::None; |
523 | 357k | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
524 | 357k | TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(), |
525 | 357k | Deps); |
526 | 357k | assert(!(Deps & TemplateArgumentDependence::Dependent) && |
527 | 357k | "built a DeclRefExpr with dependent template args"); |
528 | 27.4M | } else if (TemplateKWLoc.isValid()) { |
529 | 19 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
530 | 19 | TemplateKWLoc); |
531 | 19 | } |
532 | 27.8M | DeclRefExprBits.HadMultipleCandidates = 0; |
533 | 27.8M | setDependence(computeDependence(this, Ctx)); |
534 | 27.8M | } |
535 | | |
536 | | DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, |
537 | | NestedNameSpecifierLoc QualifierLoc, |
538 | | SourceLocation TemplateKWLoc, ValueDecl *D, |
539 | | bool RefersToEnclosingVariableOrCapture, |
540 | | SourceLocation NameLoc, QualType T, |
541 | | ExprValueKind VK, NamedDecl *FoundD, |
542 | | const TemplateArgumentListInfo *TemplateArgs, |
543 | 3.39M | NonOdrUseReason NOUR) { |
544 | 3.39M | return Create(Context, QualifierLoc, TemplateKWLoc, D, |
545 | 3.39M | RefersToEnclosingVariableOrCapture, |
546 | 3.39M | DeclarationNameInfo(D->getDeclName(), NameLoc), |
547 | 3.39M | T, VK, FoundD, TemplateArgs, NOUR); |
548 | 3.39M | } |
549 | | |
550 | | DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, |
551 | | NestedNameSpecifierLoc QualifierLoc, |
552 | | SourceLocation TemplateKWLoc, ValueDecl *D, |
553 | | bool RefersToEnclosingVariableOrCapture, |
554 | | const DeclarationNameInfo &NameInfo, |
555 | | QualType T, ExprValueKind VK, |
556 | | NamedDecl *FoundD, |
557 | | const TemplateArgumentListInfo *TemplateArgs, |
558 | 27.8M | NonOdrUseReason NOUR) { |
559 | | // Filter out cases where the found Decl is the same as the value refenenced. |
560 | 27.8M | if (D == FoundD) |
561 | 23.3M | FoundD = nullptr; |
562 | | |
563 | 27.8M | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid()27.4M ; |
564 | 27.8M | std::size_t Size = |
565 | 27.8M | totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *, |
566 | 27.8M | ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
567 | 27.8M | QualifierLoc ? 12.43M : 025.4M , FoundD ? 1553k : 027.2M , |
568 | 27.8M | HasTemplateKWAndArgsInfo ? 1357k : 027.4M , |
569 | 27.8M | TemplateArgs ? TemplateArgs->size()357k : 027.4M ); |
570 | | |
571 | 27.8M | void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); |
572 | 27.8M | return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, |
573 | 27.8M | RefersToEnclosingVariableOrCapture, NameInfo, |
574 | 27.8M | FoundD, TemplateArgs, T, VK, NOUR); |
575 | 27.8M | } |
576 | | |
577 | | DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext &Context, |
578 | | bool HasQualifier, |
579 | | bool HasFoundDecl, |
580 | | bool HasTemplateKWAndArgsInfo, |
581 | 1.55M | unsigned NumTemplateArgs) { |
582 | 1.55M | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
583 | 1.55M | std::size_t Size = |
584 | 1.55M | totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *, |
585 | 1.55M | ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
586 | 1.55M | HasQualifier ? 192.0k : 01.45M , HasFoundDecl ? 129.3k : 01.52M , HasTemplateKWAndArgsInfo, |
587 | 1.55M | NumTemplateArgs); |
588 | 1.55M | void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); |
589 | 1.55M | return new (Mem) DeclRefExpr(EmptyShell()); |
590 | 1.55M | } |
591 | | |
592 | 984k | void DeclRefExpr::setDecl(ValueDecl *NewD) { |
593 | 984k | D = NewD; |
594 | 984k | if (getType()->isUndeducedType()) |
595 | 1 | setType(NewD->getType()); |
596 | 984k | setDependence(computeDependence(this, NewD->getASTContext())); |
597 | 984k | } |
598 | | |
599 | 144M | SourceLocation DeclRefExpr::getBeginLoc() const { |
600 | 144M | if (hasQualifier()) |
601 | 13.7M | return getQualifierLoc().getBeginLoc(); |
602 | 131M | return getNameInfo().getBeginLoc(); |
603 | 144M | } |
604 | 14.0M | SourceLocation DeclRefExpr::getEndLoc() const { |
605 | 14.0M | if (hasExplicitTemplateArgs()) |
606 | 329k | return getRAngleLoc(); |
607 | 13.7M | return getNameInfo().getEndLoc(); |
608 | 14.0M | } |
609 | | |
610 | | SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(SourceLocation OpLoc, |
611 | | SourceLocation LParen, |
612 | | SourceLocation RParen, |
613 | | QualType ResultTy, |
614 | | TypeSourceInfo *TSI) |
615 | | : Expr(SYCLUniqueStableNameExprClass, ResultTy, VK_PRValue, OK_Ordinary), |
616 | 84 | OpLoc(OpLoc), LParen(LParen), RParen(RParen) { |
617 | 84 | setTypeSourceInfo(TSI); |
618 | 84 | setDependence(computeDependence(this)); |
619 | 84 | } |
620 | | |
621 | | SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(EmptyShell Empty, |
622 | | QualType ResultTy) |
623 | 0 | : Expr(SYCLUniqueStableNameExprClass, ResultTy, VK_PRValue, OK_Ordinary) {} |
624 | | |
625 | | SYCLUniqueStableNameExpr * |
626 | | SYCLUniqueStableNameExpr::Create(const ASTContext &Ctx, SourceLocation OpLoc, |
627 | | SourceLocation LParen, SourceLocation RParen, |
628 | 84 | TypeSourceInfo *TSI) { |
629 | 84 | QualType ResultTy = Ctx.getPointerType(Ctx.CharTy.withConst()); |
630 | 84 | return new (Ctx) |
631 | 84 | SYCLUniqueStableNameExpr(OpLoc, LParen, RParen, ResultTy, TSI); |
632 | 84 | } |
633 | | |
634 | | SYCLUniqueStableNameExpr * |
635 | 0 | SYCLUniqueStableNameExpr::CreateEmpty(const ASTContext &Ctx) { |
636 | 0 | QualType ResultTy = Ctx.getPointerType(Ctx.CharTy.withConst()); |
637 | 0 | return new (Ctx) SYCLUniqueStableNameExpr(EmptyShell(), ResultTy); |
638 | 0 | } |
639 | | |
640 | 46 | std::string SYCLUniqueStableNameExpr::ComputeName(ASTContext &Context) const { |
641 | 46 | return SYCLUniqueStableNameExpr::ComputeName(Context, |
642 | 46 | getTypeSourceInfo()->getType()); |
643 | 46 | } |
644 | | |
645 | | std::string SYCLUniqueStableNameExpr::ComputeName(ASTContext &Context, |
646 | 46 | QualType Ty) { |
647 | 46 | auto MangleCallback = [](ASTContext &Ctx, |
648 | 118 | const NamedDecl *ND) -> std::optional<unsigned> { |
649 | 118 | if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) |
650 | 118 | return RD->getDeviceLambdaManglingNumber(); |
651 | 0 | return std::nullopt; |
652 | 118 | }; |
653 | | |
654 | 46 | std::unique_ptr<MangleContext> Ctx{ItaniumMangleContext::create( |
655 | 46 | Context, Context.getDiagnostics(), MangleCallback)}; |
656 | | |
657 | 46 | std::string Buffer; |
658 | 46 | Buffer.reserve(128); |
659 | 46 | llvm::raw_string_ostream Out(Buffer); |
660 | 46 | Ctx->mangleTypeName(Ty, Out); |
661 | | |
662 | 46 | return Out.str(); |
663 | 46 | } |
664 | | |
665 | | PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK, |
666 | | bool IsTransparent, StringLiteral *SL) |
667 | 893 | : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary) { |
668 | 893 | PredefinedExprBits.Kind = IK; |
669 | 893 | assert((getIdentKind() == IK) && |
670 | 893 | "IdentKind do not fit in PredefinedExprBitfields!"); |
671 | 893 | bool HasFunctionName = SL != nullptr; |
672 | 893 | PredefinedExprBits.HasFunctionName = HasFunctionName; |
673 | 893 | PredefinedExprBits.IsTransparent = IsTransparent; |
674 | 893 | PredefinedExprBits.Loc = L; |
675 | 893 | if (HasFunctionName) |
676 | 801 | setFunctionName(SL); |
677 | 893 | setDependence(computeDependence(this)); |
678 | 893 | } |
679 | | |
680 | | PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName) |
681 | 18 | : Expr(PredefinedExprClass, Empty) { |
682 | 18 | PredefinedExprBits.HasFunctionName = HasFunctionName; |
683 | 18 | } |
684 | | |
685 | | PredefinedExpr *PredefinedExpr::Create(const ASTContext &Ctx, SourceLocation L, |
686 | | QualType FNTy, IdentKind IK, |
687 | 893 | bool IsTransparent, StringLiteral *SL) { |
688 | 893 | bool HasFunctionName = SL != nullptr; |
689 | 893 | void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName), |
690 | 893 | alignof(PredefinedExpr)); |
691 | 893 | return new (Mem) PredefinedExpr(L, FNTy, IK, IsTransparent, SL); |
692 | 893 | } |
693 | | |
694 | | PredefinedExpr *PredefinedExpr::CreateEmpty(const ASTContext &Ctx, |
695 | 18 | bool HasFunctionName) { |
696 | 18 | void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName), |
697 | 18 | alignof(PredefinedExpr)); |
698 | 18 | return new (Mem) PredefinedExpr(EmptyShell(), HasFunctionName); |
699 | 18 | } |
700 | | |
701 | 606 | StringRef PredefinedExpr::getIdentKindName(PredefinedExpr::IdentKind IK) { |
702 | 606 | switch (IK) { |
703 | 264 | case Func: |
704 | 264 | return "__func__"; |
705 | 153 | case Function: |
706 | 153 | return "__FUNCTION__"; |
707 | 1 | case FuncDName: |
708 | 1 | return "__FUNCDNAME__"; |
709 | 1 | case LFunction: |
710 | 1 | return "L__FUNCTION__"; |
711 | 177 | case PrettyFunction: |
712 | 177 | return "__PRETTY_FUNCTION__"; |
713 | 10 | case FuncSig: |
714 | 10 | return "__FUNCSIG__"; |
715 | 0 | case LFuncSig: |
716 | 0 | return "L__FUNCSIG__"; |
717 | 0 | case PrettyFunctionNoVirtual: |
718 | 0 | break; |
719 | 606 | } |
720 | 0 | llvm_unreachable("Unknown ident kind for PredefinedExpr"); |
721 | 0 | } |
722 | | |
723 | | // FIXME: Maybe this should use DeclPrinter with a special "print predefined |
724 | | // expr" policy instead. |
725 | 3.13k | std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { |
726 | 3.13k | ASTContext &Context = CurrentDecl->getASTContext(); |
727 | | |
728 | 3.13k | if (IK == PredefinedExpr::FuncDName) { |
729 | 10 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) { |
730 | 10 | std::unique_ptr<MangleContext> MC; |
731 | 10 | MC.reset(Context.createMangleContext()); |
732 | | |
733 | 10 | if (MC->shouldMangleDeclName(ND)) { |
734 | 9 | SmallString<256> Buffer; |
735 | 9 | llvm::raw_svector_ostream Out(Buffer); |
736 | 9 | GlobalDecl GD; |
737 | 9 | if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND)) |
738 | 2 | GD = GlobalDecl(CD, Ctor_Base); |
739 | 7 | else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND)) |
740 | 2 | GD = GlobalDecl(DD, Dtor_Base); |
741 | 5 | else if (ND->hasAttr<CUDAGlobalAttr>()) |
742 | 0 | GD = GlobalDecl(cast<FunctionDecl>(ND)); |
743 | 5 | else |
744 | 5 | GD = GlobalDecl(ND); |
745 | 9 | MC->mangleName(GD, Out); |
746 | | |
747 | 9 | if (!Buffer.empty() && Buffer.front() == '\01') |
748 | 0 | return std::string(Buffer.substr(1)); |
749 | 9 | return std::string(Buffer.str()); |
750 | 9 | } |
751 | 1 | return std::string(ND->getIdentifier()->getName()); |
752 | 10 | } |
753 | 0 | return ""; |
754 | 10 | } |
755 | 3.12k | if (isa<BlockDecl>(CurrentDecl)) { |
756 | | // For blocks we only emit something if it is enclosed in a function |
757 | | // For top-level block we'd like to include the name of variable, but we |
758 | | // don't have it at this point. |
759 | 43 | auto DC = CurrentDecl->getDeclContext(); |
760 | 43 | if (DC->isFileContext()) |
761 | 5 | return ""; |
762 | | |
763 | 38 | SmallString<256> Buffer; |
764 | 38 | llvm::raw_svector_ostream Out(Buffer); |
765 | 38 | if (auto *DCBlock = dyn_cast<BlockDecl>(DC)) |
766 | | // For nested blocks, propagate up to the parent. |
767 | 5 | Out << ComputeName(IK, DCBlock); |
768 | 33 | else if (auto *DCDecl = dyn_cast<Decl>(DC)) |
769 | 33 | Out << ComputeName(IK, DCDecl) << "_block_invoke"; |
770 | 38 | return std::string(Out.str()); |
771 | 43 | } |
772 | 3.08k | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { |
773 | 2.82k | if (IK != PrettyFunction && IK != PrettyFunctionNoVirtual2.33k && |
774 | 2.82k | IK != FuncSig607 && IK != LFuncSig547 ) |
775 | 541 | return FD->getNameAsString(); |
776 | | |
777 | 2.28k | SmallString<256> Name; |
778 | 2.28k | llvm::raw_svector_ostream Out(Name); |
779 | | |
780 | 2.28k | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
781 | 1.95k | if (MD->isVirtual() && IK != PrettyFunctionNoVirtual1.72k ) |
782 | 2 | Out << "virtual "; |
783 | 1.95k | if (MD->isStatic()) |
784 | 2 | Out << "static "; |
785 | 1.95k | } |
786 | | |
787 | 2.28k | PrintingPolicy Policy(Context.getLangOpts()); |
788 | 2.28k | std::string Proto; |
789 | 2.28k | llvm::raw_string_ostream POut(Proto); |
790 | | |
791 | 2.28k | const FunctionDecl *Decl = FD; |
792 | 2.28k | if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) |
793 | 134 | Decl = Pattern; |
794 | 2.28k | const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); |
795 | 2.28k | const FunctionProtoType *FT = nullptr; |
796 | 2.28k | if (FD->hasWrittenPrototype()) |
797 | 2.27k | FT = dyn_cast<FunctionProtoType>(AFT); |
798 | | |
799 | 2.28k | if (IK == FuncSig || IK == LFuncSig2.22k ) { |
800 | 66 | switch (AFT->getCallConv()) { |
801 | 60 | case CC_C: POut << "__cdecl "; break; |
802 | 0 | case CC_X86StdCall: POut << "__stdcall "; break; |
803 | 0 | case CC_X86FastCall: POut << "__fastcall "; break; |
804 | 6 | case CC_X86ThisCall: POut << "__thiscall "; break; |
805 | 0 | case CC_X86VectorCall: POut << "__vectorcall "; break; |
806 | 0 | case CC_X86RegCall: POut << "__regcall "; break; |
807 | | // Only bother printing the conventions that MSVC knows about. |
808 | 0 | default: break; |
809 | 66 | } |
810 | 66 | } |
811 | | |
812 | 2.28k | FD->printQualifiedName(POut, Policy); |
813 | | |
814 | 2.28k | POut << "("; |
815 | 2.28k | if (FT) { |
816 | 2.60k | for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i332 ) { |
817 | 332 | if (i) POut << ", "100 ; |
818 | 332 | POut << Decl->getParamDecl(i)->getType().stream(Policy); |
819 | 332 | } |
820 | | |
821 | 2.27k | if (FT->isVariadic()) { |
822 | 4 | if (FD->getNumParams()) POut << ", "3 ; |
823 | 4 | POut << "..."; |
824 | 2.26k | } else if ((IK == FuncSig || IK == LFuncSig2.21k || |
825 | 2.26k | !Context.getLangOpts().CPlusPlus2.20k ) && |
826 | 2.26k | !Decl->getNumParams()79 ) { |
827 | 66 | POut << "void"; |
828 | 66 | } |
829 | 2.27k | } |
830 | 2.28k | POut << ")"; |
831 | | |
832 | 2.28k | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
833 | 1.95k | assert(FT && "We must have a written prototype in this case."); |
834 | 1.95k | if (FT->isConst()) |
835 | 29 | POut << " const"; |
836 | 1.95k | if (FT->isVolatile()) |
837 | 2 | POut << " volatile"; |
838 | 1.95k | RefQualifierKind Ref = MD->getRefQualifier(); |
839 | 1.95k | if (Ref == RQ_LValue) |
840 | 1 | POut << " &"; |
841 | 1.95k | else if (Ref == RQ_RValue) |
842 | 1 | POut << " &&"; |
843 | 1.95k | } |
844 | | |
845 | 2.28k | typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; |
846 | 2.28k | SpecsTy Specs; |
847 | 2.28k | const DeclContext *Ctx = FD->getDeclContext(); |
848 | 6.06k | while (Ctx && isa<NamedDecl>(Ctx)) { |
849 | 3.78k | const ClassTemplateSpecializationDecl *Spec |
850 | 3.78k | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); |
851 | 3.78k | if (Spec && !Spec->isExplicitSpecialization()54 ) |
852 | 53 | Specs.push_back(Spec); |
853 | 3.78k | Ctx = Ctx->getParent(); |
854 | 3.78k | } |
855 | | |
856 | 2.28k | std::string TemplateParams; |
857 | 2.28k | llvm::raw_string_ostream TOut(TemplateParams); |
858 | 2.28k | for (const ClassTemplateSpecializationDecl *D : llvm::reverse(Specs)) { |
859 | 53 | const TemplateParameterList *Params = |
860 | 53 | D->getSpecializedTemplate()->getTemplateParameters(); |
861 | 53 | const TemplateArgumentList &Args = D->getTemplateArgs(); |
862 | 53 | assert(Params->size() == Args.size()); |
863 | 149 | for (unsigned i = 0, numParams = Params->size(); 53 i != numParams; ++i96 ) { |
864 | 96 | StringRef Param = Params->getParam(i)->getName(); |
865 | 96 | if (Param.empty()) continue26 ; |
866 | 70 | TOut << Param << " = "; |
867 | 70 | Args.get(i).print(Policy, TOut, |
868 | 70 | TemplateParameterList::shouldIncludeTypeForArgument( |
869 | 70 | Policy, Params, i)); |
870 | 70 | TOut << ", "; |
871 | 70 | } |
872 | 53 | } |
873 | | |
874 | 2.28k | FunctionTemplateSpecializationInfo *FSI |
875 | 2.28k | = FD->getTemplateSpecializationInfo(); |
876 | 2.28k | if (FSI && !FSI->isExplicitSpecialization()92 ) { |
877 | 91 | const TemplateParameterList* Params |
878 | 91 | = FSI->getTemplate()->getTemplateParameters(); |
879 | 91 | const TemplateArgumentList* Args = FSI->TemplateArguments; |
880 | 91 | assert(Params->size() == Args->size()); |
881 | 244 | for (unsigned i = 0, e = Params->size(); 91 i != e; ++i153 ) { |
882 | 153 | StringRef Param = Params->getParam(i)->getName(); |
883 | 153 | if (Param.empty()) continue1 ; |
884 | 152 | TOut << Param << " = "; |
885 | 152 | Args->get(i).print(Policy, TOut, /*IncludeType*/ true); |
886 | 152 | TOut << ", "; |
887 | 152 | } |
888 | 91 | } |
889 | | |
890 | 2.28k | TOut.flush(); |
891 | 2.28k | if (!TemplateParams.empty()) { |
892 | | // remove the trailing comma and space |
893 | 132 | TemplateParams.resize(TemplateParams.size() - 2); |
894 | 132 | POut << " [" << TemplateParams << "]"; |
895 | 132 | } |
896 | | |
897 | 2.28k | POut.flush(); |
898 | | |
899 | | // Print "auto" for all deduced return types. This includes C++1y return |
900 | | // type deduction and lambdas. For trailing return types resolve the |
901 | | // decltype expression. Otherwise print the real type when this is |
902 | | // not a constructor or destructor. |
903 | 2.28k | if (isa<CXXMethodDecl>(FD) && |
904 | 2.28k | cast<CXXMethodDecl>(FD)->getParent()->isLambda()1.95k ) |
905 | 14 | Proto = "auto " + Proto; |
906 | 2.27k | else if (FT && FT->getReturnType()->getAs<DecltypeType>()2.25k ) |
907 | 1 | FT->getReturnType() |
908 | 1 | ->getAs<DecltypeType>() |
909 | 1 | ->getUnderlyingType() |
910 | 1 | .getAsStringInternal(Proto, Policy); |
911 | 2.27k | else if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD)2.16k ) |
912 | 2.02k | AFT->getReturnType().getAsStringInternal(Proto, Policy); |
913 | | |
914 | 2.28k | Out << Proto; |
915 | | |
916 | 2.28k | return std::string(Name); |
917 | 2.28k | } |
918 | 258 | if (const CapturedDecl *CD = dyn_cast<CapturedDecl>(CurrentDecl)) { |
919 | 22 | for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent()3 ) |
920 | | // Skip to its enclosing function or method, but not its enclosing |
921 | | // CapturedDecl. |
922 | 22 | if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) { |
923 | 19 | const Decl *D = Decl::castFromDeclContext(DC); |
924 | 19 | return ComputeName(IK, D); |
925 | 19 | } |
926 | 0 | llvm_unreachable("CapturedDecl not inside a function or method"); |
927 | 0 | } |
928 | 239 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { |
929 | 92 | SmallString<256> Name; |
930 | 92 | llvm::raw_svector_ostream Out(Name); |
931 | 92 | Out << (MD->isInstanceMethod() ? '-'76 : '+'16 ); |
932 | 92 | Out << '['; |
933 | | |
934 | | // For incorrect code, there might not be an ObjCInterfaceDecl. Do |
935 | | // a null check to avoid a crash. |
936 | 92 | if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) |
937 | 91 | Out << *ID; |
938 | | |
939 | 92 | if (const ObjCCategoryImplDecl *CID = |
940 | 92 | dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) |
941 | 7 | Out << '(' << *CID << ')'; |
942 | | |
943 | 92 | Out << ' '; |
944 | 92 | MD->getSelector().print(Out); |
945 | 92 | Out << ']'; |
946 | | |
947 | 92 | return std::string(Name); |
948 | 92 | } |
949 | 147 | if (isa<TranslationUnitDecl>(CurrentDecl) && IK == PrettyFunction24 ) { |
950 | | // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. |
951 | 2 | return "top level"; |
952 | 2 | } |
953 | 145 | return ""; |
954 | 147 | } |
955 | | |
956 | | void APNumericStorage::setIntValue(const ASTContext &C, |
957 | 11.4M | const llvm::APInt &Val) { |
958 | 11.4M | if (hasAllocation()) |
959 | 0 | C.Deallocate(pVal); |
960 | | |
961 | 11.4M | BitWidth = Val.getBitWidth(); |
962 | 11.4M | unsigned NumWords = Val.getNumWords(); |
963 | 11.4M | const uint64_t* Words = Val.getRawData(); |
964 | 11.4M | if (NumWords > 1) { |
965 | 4.46k | pVal = new (C) uint64_t[NumWords]; |
966 | 4.46k | std::copy(Words, Words + NumWords, pVal); |
967 | 11.4M | } else if (NumWords == 1) |
968 | 11.4M | VAL = Words[0]; |
969 | 0 | else |
970 | 0 | VAL = 0; |
971 | 11.4M | } |
972 | | |
973 | | IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V, |
974 | | QualType type, SourceLocation l) |
975 | 11.0M | : Expr(IntegerLiteralClass, type, VK_PRValue, OK_Ordinary), Loc(l) { |
976 | 11.0M | assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); |
977 | 11.0M | assert(V.getBitWidth() == C.getIntWidth(type) && |
978 | 11.0M | "Integer type is not the correct size for constant."); |
979 | 11.0M | setValue(C, V); |
980 | 11.0M | setDependence(ExprDependence::None); |
981 | 11.0M | } |
982 | | |
983 | | IntegerLiteral * |
984 | | IntegerLiteral::Create(const ASTContext &C, const llvm::APInt &V, |
985 | 11.0M | QualType type, SourceLocation l) { |
986 | 11.0M | return new (C) IntegerLiteral(C, V, type, l); |
987 | 11.0M | } |
988 | | |
989 | | IntegerLiteral * |
990 | 310k | IntegerLiteral::Create(const ASTContext &C, EmptyShell Empty) { |
991 | 310k | return new (C) IntegerLiteral(Empty); |
992 | 310k | } |
993 | | |
994 | | FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, |
995 | | QualType type, SourceLocation l, |
996 | | unsigned Scale) |
997 | | : Expr(FixedPointLiteralClass, type, VK_PRValue, OK_Ordinary), Loc(l), |
998 | 816 | Scale(Scale) { |
999 | 816 | assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral"); |
1000 | 816 | assert(V.getBitWidth() == C.getTypeInfo(type).Width && |
1001 | 816 | "Fixed point type is not the correct size for constant."); |
1002 | 816 | setValue(C, V); |
1003 | 816 | setDependence(ExprDependence::None); |
1004 | 816 | } |
1005 | | |
1006 | | FixedPointLiteral *FixedPointLiteral::CreateFromRawInt(const ASTContext &C, |
1007 | | const llvm::APInt &V, |
1008 | | QualType type, |
1009 | | SourceLocation l, |
1010 | 808 | unsigned Scale) { |
1011 | 808 | return new (C) FixedPointLiteral(C, V, type, l, Scale); |
1012 | 808 | } |
1013 | | |
1014 | | FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C, |
1015 | 56 | EmptyShell Empty) { |
1016 | 56 | return new (C) FixedPointLiteral(Empty); |
1017 | 56 | } |
1018 | | |
1019 | 128 | std::string FixedPointLiteral::getValueAsString(unsigned Radix) const { |
1020 | | // Currently the longest decimal number that can be printed is the max for an |
1021 | | // unsigned long _Accum: 4294967295.99999999976716935634613037109375 |
1022 | | // which is 43 characters. |
1023 | 128 | SmallString<64> S; |
1024 | 128 | FixedPointValueToString( |
1025 | 128 | S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale); |
1026 | 128 | return std::string(S.str()); |
1027 | 128 | } |
1028 | | |
1029 | | void CharacterLiteral::print(unsigned Val, CharacterKind Kind, |
1030 | 675 | raw_ostream &OS) { |
1031 | 675 | switch (Kind) { |
1032 | 476 | case CharacterLiteral::Ascii: |
1033 | 476 | break; // no prefix. |
1034 | 64 | case CharacterLiteral::Wide: |
1035 | 64 | OS << 'L'; |
1036 | 64 | break; |
1037 | 52 | case CharacterLiteral::UTF8: |
1038 | 52 | OS << "u8"; |
1039 | 52 | break; |
1040 | 32 | case CharacterLiteral::UTF16: |
1041 | 32 | OS << 'u'; |
1042 | 32 | break; |
1043 | 51 | case CharacterLiteral::UTF32: |
1044 | 51 | OS << 'U'; |
1045 | 51 | break; |
1046 | 675 | } |
1047 | | |
1048 | 675 | StringRef Escaped = escapeCStyle<EscapeChar::Single>(Val); |
1049 | 675 | if (!Escaped.empty()) { |
1050 | 113 | OS << "'" << Escaped << "'"; |
1051 | 562 | } else { |
1052 | | // A character literal might be sign-extended, which |
1053 | | // would result in an invalid \U escape sequence. |
1054 | | // FIXME: multicharacter literals such as '\xFF\xFF\xFF\xFF' |
1055 | | // are not correctly handled. |
1056 | 562 | if ((Val & ~0xFFu) == ~0xFFu && Kind == CharacterLiteral::Ascii1 ) |
1057 | 1 | Val &= 0xFFu; |
1058 | 562 | if (Val < 256 && isPrintable((unsigned char)Val)523 ) |
1059 | 374 | OS << "'" << (char)Val << "'"; |
1060 | 188 | else if (Val < 256) |
1061 | 149 | OS << "'\\x" << llvm::format("%02x", Val) << "'"; |
1062 | 39 | else if (Val <= 0xFFFF) |
1063 | 31 | OS << "'\\u" << llvm::format("%04x", Val) << "'"; |
1064 | 8 | else |
1065 | 8 | OS << "'\\U" << llvm::format("%08x", Val) << "'"; |
1066 | 562 | } |
1067 | 675 | } |
1068 | | |
1069 | | FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, |
1070 | | bool isexact, QualType Type, SourceLocation L) |
1071 | 71.4k | : Expr(FloatingLiteralClass, Type, VK_PRValue, OK_Ordinary), Loc(L) { |
1072 | 71.4k | setSemantics(V.getSemantics()); |
1073 | 71.4k | FloatingLiteralBits.IsExact = isexact; |
1074 | 71.4k | setValue(C, V); |
1075 | 71.4k | setDependence(ExprDependence::None); |
1076 | 71.4k | } |
1077 | | |
1078 | | FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty) |
1079 | 4.13k | : Expr(FloatingLiteralClass, Empty) { |
1080 | 4.13k | setRawSemantics(llvm::APFloatBase::S_IEEEhalf); |
1081 | 4.13k | FloatingLiteralBits.IsExact = false; |
1082 | 4.13k | } |
1083 | | |
1084 | | FloatingLiteral * |
1085 | | FloatingLiteral::Create(const ASTContext &C, const llvm::APFloat &V, |
1086 | 71.4k | bool isexact, QualType Type, SourceLocation L) { |
1087 | 71.4k | return new (C) FloatingLiteral(C, V, isexact, Type, L); |
1088 | 71.4k | } |
1089 | | |
1090 | | FloatingLiteral * |
1091 | 4.13k | FloatingLiteral::Create(const ASTContext &C, EmptyShell Empty) { |
1092 | 4.13k | return new (C) FloatingLiteral(C, Empty); |
1093 | 4.13k | } |
1094 | | |
1095 | | /// getValueAsApproximateDouble - This returns the value as an inaccurate |
1096 | | /// double. Note that this may cause loss of precision, but is useful for |
1097 | | /// debugging dumps, etc. |
1098 | 216 | double FloatingLiteral::getValueAsApproximateDouble() const { |
1099 | 216 | llvm::APFloat V = getValue(); |
1100 | 216 | bool ignored; |
1101 | 216 | V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, |
1102 | 216 | &ignored); |
1103 | 216 | return V.convertToDouble(); |
1104 | 216 | } |
1105 | | |
1106 | | unsigned StringLiteral::mapCharByteWidth(TargetInfo const &Target, |
1107 | 7.34M | StringKind SK) { |
1108 | 7.34M | unsigned CharByteWidth = 0; |
1109 | 7.34M | switch (SK) { |
1110 | 7.34M | case Ordinary: |
1111 | 7.34M | case UTF8: |
1112 | 7.34M | CharByteWidth = Target.getCharWidth(); |
1113 | 7.34M | break; |
1114 | 1.19k | case Wide: |
1115 | 1.19k | CharByteWidth = Target.getWCharWidth(); |
1116 | 1.19k | break; |
1117 | 163 | case UTF16: |
1118 | 163 | CharByteWidth = Target.getChar16Width(); |
1119 | 163 | break; |
1120 | 137 | case UTF32: |
1121 | 137 | CharByteWidth = Target.getChar32Width(); |
1122 | 137 | break; |
1123 | 7.34M | } |
1124 | 7.34M | assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); |
1125 | 7.34M | CharByteWidth /= 8; |
1126 | 7.34M | assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) && |
1127 | 7.34M | "The only supported character byte widths are 1,2 and 4!"); |
1128 | 7.34M | return CharByteWidth; |
1129 | 7.34M | } |
1130 | | |
1131 | | StringLiteral::StringLiteral(const ASTContext &Ctx, StringRef Str, |
1132 | | StringKind Kind, bool Pascal, QualType Ty, |
1133 | | const SourceLocation *Loc, |
1134 | | unsigned NumConcatenated) |
1135 | 7.32M | : Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary) { |
1136 | 7.32M | assert(Ctx.getAsConstantArrayType(Ty) && |
1137 | 7.32M | "StringLiteral must be of constant array type!"); |
1138 | 7.32M | unsigned CharByteWidth = mapCharByteWidth(Ctx.getTargetInfo(), Kind); |
1139 | 7.32M | unsigned ByteLength = Str.size(); |
1140 | 7.32M | assert((ByteLength % CharByteWidth == 0) && |
1141 | 7.32M | "The size of the data must be a multiple of CharByteWidth!"); |
1142 | | |
1143 | | // Avoid the expensive division. The compiler should be able to figure it |
1144 | | // out by itself. However as of clang 7, even with the appropriate |
1145 | | // llvm_unreachable added just here, it is not able to do so. |
1146 | 7.32M | unsigned Length; |
1147 | 7.32M | switch (CharByteWidth) { |
1148 | 7.32M | case 1: |
1149 | 7.32M | Length = ByteLength; |
1150 | 7.32M | break; |
1151 | 477 | case 2: |
1152 | 477 | Length = ByteLength / 2; |
1153 | 477 | break; |
1154 | 1.00k | case 4: |
1155 | 1.00k | Length = ByteLength / 4; |
1156 | 1.00k | break; |
1157 | 0 | default: |
1158 | 0 | llvm_unreachable("Unsupported character width!"); |
1159 | 7.32M | } |
1160 | | |
1161 | 7.32M | StringLiteralBits.Kind = Kind; |
1162 | 7.32M | StringLiteralBits.CharByteWidth = CharByteWidth; |
1163 | 7.32M | StringLiteralBits.IsPascal = Pascal; |
1164 | 7.32M | StringLiteralBits.NumConcatenated = NumConcatenated; |
1165 | 7.32M | *getTrailingObjects<unsigned>() = Length; |
1166 | | |
1167 | | // Initialize the trailing array of SourceLocation. |
1168 | | // This is safe since SourceLocation is POD-like. |
1169 | 7.32M | std::memcpy(getTrailingObjects<SourceLocation>(), Loc, |
1170 | 7.32M | NumConcatenated * sizeof(SourceLocation)); |
1171 | | |
1172 | | // Initialize the trailing array of char holding the string data. |
1173 | 7.32M | std::memcpy(getTrailingObjects<char>(), Str.data(), ByteLength); |
1174 | | |
1175 | 7.32M | setDependence(ExprDependence::None); |
1176 | 7.32M | } |
1177 | | |
1178 | | StringLiteral::StringLiteral(EmptyShell Empty, unsigned NumConcatenated, |
1179 | | unsigned Length, unsigned CharByteWidth) |
1180 | 16.3k | : Expr(StringLiteralClass, Empty) { |
1181 | 16.3k | StringLiteralBits.CharByteWidth = CharByteWidth; |
1182 | 16.3k | StringLiteralBits.NumConcatenated = NumConcatenated; |
1183 | 16.3k | *getTrailingObjects<unsigned>() = Length; |
1184 | 16.3k | } |
1185 | | |
1186 | | StringLiteral *StringLiteral::Create(const ASTContext &Ctx, StringRef Str, |
1187 | | StringKind Kind, bool Pascal, QualType Ty, |
1188 | | const SourceLocation *Loc, |
1189 | 7.32M | unsigned NumConcatenated) { |
1190 | 7.32M | void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>( |
1191 | 7.32M | 1, NumConcatenated, Str.size()), |
1192 | 7.32M | alignof(StringLiteral)); |
1193 | 7.32M | return new (Mem) |
1194 | 7.32M | StringLiteral(Ctx, Str, Kind, Pascal, Ty, Loc, NumConcatenated); |
1195 | 7.32M | } |
1196 | | |
1197 | | StringLiteral *StringLiteral::CreateEmpty(const ASTContext &Ctx, |
1198 | | unsigned NumConcatenated, |
1199 | | unsigned Length, |
1200 | 16.3k | unsigned CharByteWidth) { |
1201 | 16.3k | void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>( |
1202 | 16.3k | 1, NumConcatenated, Length * CharByteWidth), |
1203 | 16.3k | alignof(StringLiteral)); |
1204 | 16.3k | return new (Mem) |
1205 | 16.3k | StringLiteral(EmptyShell(), NumConcatenated, Length, CharByteWidth); |
1206 | 16.3k | } |
1207 | | |
1208 | 1.17k | void StringLiteral::outputString(raw_ostream &OS) const { |
1209 | 1.17k | switch (getKind()) { |
1210 | 1.06k | case Ordinary: |
1211 | 1.06k | break; // no prefix. |
1212 | 52 | case Wide: OS << 'L'; break; |
1213 | 15 | case UTF8: OS << "u8"; break; |
1214 | 22 | case UTF16: OS << 'u'; break; |
1215 | 21 | case UTF32: OS << 'U'; break; |
1216 | 1.17k | } |
1217 | 1.17k | OS << '"'; |
1218 | 1.17k | static const char Hex[] = "0123456789ABCDEF"; |
1219 | | |
1220 | 1.17k | unsigned LastSlashX = getLength(); |
1221 | 32.4k | for (unsigned I = 0, N = getLength(); I != N; ++I31.2k ) { |
1222 | 31.2k | uint32_t Char = getCodeUnit(I); |
1223 | 31.2k | StringRef Escaped = escapeCStyle<EscapeChar::Double>(Char); |
1224 | 31.2k | if (Escaped.empty()) { |
1225 | | // FIXME: Convert UTF-8 back to codepoints before rendering. |
1226 | | |
1227 | | // Convert UTF-16 surrogate pairs back to codepoints before rendering. |
1228 | | // Leave invalid surrogates alone; we'll use \x for those. |
1229 | 31.1k | if (getKind() == UTF16 && I != N - 1132 && Char >= 0xd800117 && |
1230 | 31.1k | Char <= 0xdbff1 ) { |
1231 | 1 | uint32_t Trail = getCodeUnit(I + 1); |
1232 | 1 | if (Trail >= 0xdc00 && Trail <= 0xdfff) { |
1233 | 1 | Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00); |
1234 | 1 | ++I; |
1235 | 1 | } |
1236 | 1 | } |
1237 | | |
1238 | 31.1k | if (Char > 0xff) { |
1239 | | // If this is a wide string, output characters over 0xff using \x |
1240 | | // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a |
1241 | | // codepoint: use \x escapes for invalid codepoints. |
1242 | 80 | if (getKind() == Wide || |
1243 | 80 | (41 Char >= 0xd80041 && Char <= 0xdfff23 ) || Char >= 0x11000041 ) { |
1244 | | // FIXME: Is this the best way to print wchar_t? |
1245 | 39 | OS << "\\x"; |
1246 | 39 | int Shift = 28; |
1247 | 200 | while ((Char >> Shift) == 0) |
1248 | 161 | Shift -= 4; |
1249 | 190 | for (/**/; Shift >= 0; Shift -= 4151 ) |
1250 | 151 | OS << Hex[(Char >> Shift) & 15]; |
1251 | 39 | LastSlashX = I; |
1252 | 39 | continue; |
1253 | 39 | } |
1254 | | |
1255 | 41 | if (Char > 0xffff) |
1256 | 22 | OS << "\\U00" |
1257 | 22 | << Hex[(Char >> 20) & 15] |
1258 | 22 | << Hex[(Char >> 16) & 15]; |
1259 | 19 | else |
1260 | 19 | OS << "\\u"; |
1261 | 41 | OS << Hex[(Char >> 12) & 15] |
1262 | 41 | << Hex[(Char >> 8) & 15] |
1263 | 41 | << Hex[(Char >> 4) & 15] |
1264 | 41 | << Hex[(Char >> 0) & 15]; |
1265 | 41 | continue; |
1266 | 80 | } |
1267 | | |
1268 | | // If we used \x... for the previous character, and this character is a |
1269 | | // hexadecimal digit, prevent it being slurped as part of the \x. |
1270 | 31.0k | if (LastSlashX + 1 == I) { |
1271 | 13 | switch (Char) { |
1272 | 1 | case '0': case '1': case '2': case '3': case '4': |
1273 | 1 | case '5': case '6': case '7': case '8': case '9': |
1274 | 2 | case 'a': 1 case 'b': 1 case 'c': 1 case 'd': 1 case 'e': 1 case 'f': |
1275 | 2 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': |
1276 | 2 | OS << "\"\""; |
1277 | 13 | } |
1278 | 13 | } |
1279 | | |
1280 | 31.0k | assert(Char <= 0xff && |
1281 | 31.0k | "Characters above 0xff should already have been handled."); |
1282 | | |
1283 | 31.0k | if (isPrintable(Char)) |
1284 | 30.9k | OS << (char)Char; |
1285 | 74 | else // Output anything hard as an octal escape. |
1286 | 74 | OS << '\\' |
1287 | 74 | << (char)('0' + ((Char >> 6) & 7)) |
1288 | 74 | << (char)('0' + ((Char >> 3) & 7)) |
1289 | 74 | << (char)('0' + ((Char >> 0) & 7)); |
1290 | 31.0k | } else { |
1291 | | // Handle some common non-printable cases to make dumps prettier. |
1292 | 139 | OS << Escaped; |
1293 | 139 | } |
1294 | 31.2k | } |
1295 | 1.17k | OS << '"'; |
1296 | 1.17k | } |
1297 | | |
1298 | | /// getLocationOfByte - Return a source location that points to the specified |
1299 | | /// byte of this string literal. |
1300 | | /// |
1301 | | /// Strings are amazingly complex. They can be formed from multiple tokens and |
1302 | | /// can have escape sequences in them in addition to the usual trigraph and |
1303 | | /// escaped newline business. This routine handles this complexity. |
1304 | | /// |
1305 | | /// The *StartToken sets the first token to be searched in this function and |
1306 | | /// the *StartTokenByteOffset is the byte offset of the first token. Before |
1307 | | /// returning, it updates the *StartToken to the TokNo of the token being found |
1308 | | /// and sets *StartTokenByteOffset to the byte offset of the token in the |
1309 | | /// string. |
1310 | | /// Using these two parameters can reduce the time complexity from O(n^2) to |
1311 | | /// O(n) if one wants to get the location of byte for all the tokens in a |
1312 | | /// string. |
1313 | | /// |
1314 | | SourceLocation |
1315 | | StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM, |
1316 | | const LangOptions &Features, |
1317 | | const TargetInfo &Target, unsigned *StartToken, |
1318 | 30.8k | unsigned *StartTokenByteOffset) const { |
1319 | 30.8k | assert((getKind() == StringLiteral::Ordinary || |
1320 | 30.8k | getKind() == StringLiteral::UTF8) && |
1321 | 30.8k | "Only narrow string literals are currently supported"); |
1322 | | |
1323 | | // Loop over all of the tokens in this string until we find the one that |
1324 | | // contains the byte we're looking for. |
1325 | 30.8k | unsigned TokNo = 0; |
1326 | 30.8k | unsigned StringOffset = 0; |
1327 | 30.8k | if (StartToken) |
1328 | 18.5k | TokNo = *StartToken; |
1329 | 30.8k | if (StartTokenByteOffset) { |
1330 | 18.5k | StringOffset = *StartTokenByteOffset; |
1331 | 18.5k | ByteNo -= StringOffset; |
1332 | 18.5k | } |
1333 | 33.0k | while (true) { |
1334 | 33.0k | assert(TokNo < getNumConcatenated() && "Invalid byte number!"); |
1335 | 33.0k | SourceLocation StrTokLoc = getStrTokenLoc(TokNo); |
1336 | | |
1337 | | // Get the spelling of the string so that we can get the data that makes up |
1338 | | // the string literal, not the identifier for the macro it is potentially |
1339 | | // expanded through. |
1340 | 33.0k | SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); |
1341 | | |
1342 | | // Re-lex the token to get its length and original spelling. |
1343 | 33.0k | std::pair<FileID, unsigned> LocInfo = |
1344 | 33.0k | SM.getDecomposedLoc(StrTokSpellingLoc); |
1345 | 33.0k | bool Invalid = false; |
1346 | 33.0k | StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); |
1347 | 33.0k | if (Invalid) { |
1348 | 6 | if (StartTokenByteOffset != nullptr) |
1349 | 0 | *StartTokenByteOffset = StringOffset; |
1350 | 6 | if (StartToken != nullptr) |
1351 | 0 | *StartToken = TokNo; |
1352 | 6 | return StrTokSpellingLoc; |
1353 | 6 | } |
1354 | | |
1355 | 33.0k | const char *StrData = Buffer.data()+LocInfo.second; |
1356 | | |
1357 | | // Create a lexer starting at the beginning of this token. |
1358 | 33.0k | Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, |
1359 | 33.0k | Buffer.begin(), StrData, Buffer.end()); |
1360 | 33.0k | Token TheTok; |
1361 | 33.0k | TheLexer.LexFromRawLexer(TheTok); |
1362 | | |
1363 | | // Use the StringLiteralParser to compute the length of the string in bytes. |
1364 | 33.0k | StringLiteralParser SLP(TheTok, SM, Features, Target); |
1365 | 33.0k | unsigned TokNumBytes = SLP.GetStringLength(); |
1366 | | |
1367 | | // If the byte is in this token, return the location of the byte. |
1368 | 33.0k | if (ByteNo < TokNumBytes || |
1369 | 33.0k | (3.79k ByteNo == TokNumBytes3.79k && TokNo == getNumConcatenated() - 11.65k )) { |
1370 | 30.8k | unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); |
1371 | | |
1372 | | // Now that we know the offset of the token in the spelling, use the |
1373 | | // preprocessor to get the offset in the original source. |
1374 | 30.8k | if (StartTokenByteOffset != nullptr) |
1375 | 18.5k | *StartTokenByteOffset = StringOffset; |
1376 | 30.8k | if (StartToken != nullptr) |
1377 | 18.5k | *StartToken = TokNo; |
1378 | 30.8k | return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); |
1379 | 30.8k | } |
1380 | | |
1381 | | // Move to the next string token. |
1382 | 2.24k | StringOffset += TokNumBytes; |
1383 | 2.24k | ++TokNo; |
1384 | 2.24k | ByteNo -= TokNumBytes; |
1385 | 2.24k | } |
1386 | 30.8k | } |
1387 | | |
1388 | | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
1389 | | /// corresponds to, e.g. "sizeof" or "[pre]++". |
1390 | 74.5k | StringRef UnaryOperator::getOpcodeStr(Opcode Op) { |
1391 | 74.5k | switch (Op) { |
1392 | 74.5k | #define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling; |
1393 | 74.5k | #include "clang/AST/OperationKinds.def"0 |
1394 | 74.5k | } |
1395 | 0 | llvm_unreachable("Unknown unary operator"); |
1396 | 0 | } |
1397 | | |
1398 | | UnaryOperatorKind |
1399 | 1.06k | UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { |
1400 | 1.06k | switch (OO) { |
1401 | 0 | default: llvm_unreachable("No unary operator for overloaded function"); |
1402 | 158 | case OO_PlusPlus: return Postfix ? UO_PostInc1 : UO_PreInc157 ; |
1403 | 0 | case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec; |
1404 | 333 | case OO_Amp: return UO_AddrOf; |
1405 | 405 | case OO_Star: return UO_Deref; |
1406 | 0 | case OO_Plus: return UO_Plus; |
1407 | 57 | case OO_Minus: return UO_Minus; |
1408 | 109 | case OO_Tilde: return UO_Not; |
1409 | 1 | case OO_Exclaim: return UO_LNot; |
1410 | 0 | case OO_Coawait: return UO_Coawait; |
1411 | 1.06k | } |
1412 | 1.06k | } |
1413 | | |
1414 | 3.79M | OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { |
1415 | 3.79M | switch (Opc) { |
1416 | 735k | case UO_PostInc: 54.7k case UO_PreInc: return OO_PlusPlus; |
1417 | 189k | case UO_PostDec: 2.25k case UO_PreDec: return OO_MinusMinus; |
1418 | 192k | case UO_AddrOf: return OO_Amp; |
1419 | 1.54M | case UO_Deref: return OO_Star; |
1420 | 517 | case UO_Plus: return OO_Plus; |
1421 | 25.1k | case UO_Minus: return OO_Minus; |
1422 | 137k | case UO_Not: return OO_Tilde; |
1423 | 974k | case UO_LNot: return OO_Exclaim; |
1424 | 1.50k | case UO_Coawait: return OO_Coawait; |
1425 | 9 | default: return OO_None; |
1426 | 3.79M | } |
1427 | 3.79M | } |
1428 | | |
1429 | | |
1430 | | //===----------------------------------------------------------------------===// |
1431 | | // Postfix Operators. |
1432 | | //===----------------------------------------------------------------------===// |
1433 | | |
1434 | | CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs, |
1435 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
1436 | | SourceLocation RParenLoc, FPOptionsOverride FPFeatures, |
1437 | | unsigned MinNumArgs, ADLCallKind UsesADL) |
1438 | 10.5M | : Expr(SC, Ty, VK, OK_Ordinary), RParenLoc(RParenLoc) { |
1439 | 10.5M | NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); |
1440 | 10.5M | unsigned NumPreArgs = PreArgs.size(); |
1441 | 10.5M | CallExprBits.NumPreArgs = NumPreArgs; |
1442 | 10.5M | assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!"); |
1443 | | |
1444 | 10.5M | unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC); |
1445 | 10.5M | CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects; |
1446 | 10.5M | assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && |
1447 | 10.5M | "OffsetToTrailingObjects overflow!"); |
1448 | | |
1449 | 10.5M | CallExprBits.UsesADL = static_cast<bool>(UsesADL); |
1450 | | |
1451 | 10.5M | setCallee(Fn); |
1452 | 10.5M | for (unsigned I = 0; I != NumPreArgs; ++I195 ) |
1453 | 195 | setPreArg(I, PreArgs[I]); |
1454 | 26.4M | for (unsigned I = 0; I != Args.size(); ++I15.9M ) |
1455 | 15.9M | setArg(I, Args[I]); |
1456 | 10.5M | for (unsigned I = Args.size(); I != NumArgs; ++I10.9k ) |
1457 | 10.9k | setArg(I, nullptr); |
1458 | | |
1459 | 10.5M | this->computeDependence(); |
1460 | | |
1461 | 10.5M | CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(); |
1462 | 10.5M | if (hasStoredFPFeatures()) |
1463 | 82.4k | setStoredFPFeatures(FPFeatures); |
1464 | 10.5M | } |
1465 | | |
1466 | | CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs, |
1467 | | bool HasFPFeatures, EmptyShell Empty) |
1468 | 763k | : Expr(SC, Empty), NumArgs(NumArgs) { |
1469 | 763k | CallExprBits.NumPreArgs = NumPreArgs; |
1470 | 763k | assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!"); |
1471 | | |
1472 | 763k | unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC); |
1473 | 763k | CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects; |
1474 | 763k | assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) && |
1475 | 763k | "OffsetToTrailingObjects overflow!"); |
1476 | 763k | CallExprBits.HasFPFeatures = HasFPFeatures; |
1477 | 763k | } |
1478 | | |
1479 | | CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn, |
1480 | | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
1481 | | SourceLocation RParenLoc, |
1482 | | FPOptionsOverride FPFeatures, unsigned MinNumArgs, |
1483 | 8.01M | ADLCallKind UsesADL) { |
1484 | 8.01M | unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); |
1485 | 8.01M | unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( |
1486 | 8.01M | /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage()); |
1487 | 8.01M | void *Mem = |
1488 | 8.01M | Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr)); |
1489 | 8.01M | return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, |
1490 | 8.01M | RParenLoc, FPFeatures, MinNumArgs, UsesADL); |
1491 | 8.01M | } |
1492 | | |
1493 | | CallExpr *CallExpr::CreateTemporary(void *Mem, Expr *Fn, QualType Ty, |
1494 | | ExprValueKind VK, SourceLocation RParenLoc, |
1495 | 804k | ADLCallKind UsesADL) { |
1496 | 804k | assert(!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) && |
1497 | 804k | "Misaligned memory in CallExpr::CreateTemporary!"); |
1498 | 804k | return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty, |
1499 | 804k | VK, RParenLoc, FPOptionsOverride(), |
1500 | 804k | /*MinNumArgs=*/0, UsesADL); |
1501 | 804k | } |
1502 | | |
1503 | | CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, |
1504 | 511k | bool HasFPFeatures, EmptyShell Empty) { |
1505 | 511k | unsigned SizeOfTrailingObjects = |
1506 | 511k | CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures); |
1507 | 511k | void *Mem = |
1508 | 511k | Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr)); |
1509 | 511k | return new (Mem) |
1510 | 511k | CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty); |
1511 | 511k | } |
1512 | | |
1513 | 11.3M | unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) { |
1514 | 11.3M | switch (SC) { |
1515 | 9.33M | case CallExprClass: |
1516 | 9.33M | return sizeof(CallExpr); |
1517 | 1.67M | case CXXOperatorCallExprClass: |
1518 | 1.67M | return sizeof(CXXOperatorCallExpr); |
1519 | 332k | case CXXMemberCallExprClass: |
1520 | 332k | return sizeof(CXXMemberCallExpr); |
1521 | 302 | case UserDefinedLiteralClass: |
1522 | 302 | return sizeof(UserDefinedLiteral); |
1523 | 196 | case CUDAKernelCallExprClass: |
1524 | 196 | return sizeof(CUDAKernelCallExpr); |
1525 | 0 | default: |
1526 | 0 | llvm_unreachable("unexpected class deriving from CallExpr!"); |
1527 | 11.3M | } |
1528 | 11.3M | } |
1529 | | |
1530 | 18.8M | Decl *Expr::getReferencedDeclOfCallee() { |
1531 | 18.8M | Expr *CEE = IgnoreParenImpCasts(); |
1532 | | |
1533 | 18.8M | while (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) |
1534 | 0 | CEE = NTTP->getReplacement()->IgnoreParenImpCasts(); |
1535 | | |
1536 | | // If we're calling a dereference, look at the pointer instead. |
1537 | 18.8M | while (true) { |
1538 | 18.8M | if (auto *BO = dyn_cast<BinaryOperator>(CEE)) { |
1539 | 2.01k | if (BO->isPtrMemOp()) { |
1540 | 1.98k | CEE = BO->getRHS()->IgnoreParenImpCasts(); |
1541 | 1.98k | continue; |
1542 | 1.98k | } |
1543 | 18.8M | } else if (auto *UO = dyn_cast<UnaryOperator>(CEE)) { |
1544 | 21.8k | if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf5.75k || |
1545 | 21.8k | UO->getOpcode() == UO_Plus28 ) { |
1546 | 21.8k | CEE = UO->getSubExpr()->IgnoreParenImpCasts(); |
1547 | 21.8k | continue; |
1548 | 21.8k | } |
1549 | 21.8k | } |
1550 | 18.8M | break; |
1551 | 18.8M | } |
1552 | | |
1553 | 18.8M | if (auto *DRE = dyn_cast<DeclRefExpr>(CEE)) |
1554 | 16.9M | return DRE->getDecl(); |
1555 | 1.89M | if (auto *ME = dyn_cast<MemberExpr>(CEE)) |
1556 | 1.77M | return ME->getMemberDecl(); |
1557 | 120k | if (auto *BE = dyn_cast<BlockExpr>(CEE)) |
1558 | 2.37k | return BE->getBlockDecl(); |
1559 | | |
1560 | 117k | return nullptr; |
1561 | 120k | } |
1562 | | |
1563 | | /// If this is a call to a builtin, return the builtin ID. If not, return 0. |
1564 | 5.89M | unsigned CallExpr::getBuiltinCallee() const { |
1565 | 5.89M | const auto *FDecl = getDirectCallee(); |
1566 | 5.89M | return FDecl ? FDecl->getBuiltinID()5.81M : 074.8k ; |
1567 | 5.89M | } |
1568 | | |
1569 | 4.48M | bool CallExpr::isUnevaluatedBuiltinCall(const ASTContext &Ctx) const { |
1570 | 4.48M | if (unsigned BI = getBuiltinCallee()) |
1571 | 2.16M | return Ctx.BuiltinInfo.isUnevaluated(BI); |
1572 | 2.31M | return false; |
1573 | 4.48M | } |
1574 | | |
1575 | 2.43M | QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const { |
1576 | 2.43M | const Expr *Callee = getCallee(); |
1577 | 2.43M | QualType CalleeType = Callee->getType(); |
1578 | 2.43M | if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) { |
1579 | 2.05M | CalleeType = FnTypePtr->getPointeeType(); |
1580 | 2.05M | } else if (const auto *381k BPT381k = CalleeType->getAs<BlockPointerType>()) { |
1581 | 2.71k | CalleeType = BPT->getPointeeType(); |
1582 | 378k | } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) { |
1583 | 376k | if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens())) |
1584 | 150 | return Ctx.VoidTy; |
1585 | | |
1586 | 376k | if (isa<UnresolvedMemberExpr>(Callee->IgnoreParens())) |
1587 | 1 | return Ctx.DependentTy; |
1588 | | |
1589 | | // This should never be overloaded and so should never return null. |
1590 | 376k | CalleeType = Expr::findBoundMemberType(Callee); |
1591 | 376k | assert(!CalleeType.isNull()); |
1592 | 376k | } else if (1.62k CalleeType->isDependentType()1.62k || |
1593 | 1.62k | CalleeType->isSpecificPlaceholderType(BuiltinType::Overload)1.62k ) { |
1594 | 2 | return Ctx.DependentTy; |
1595 | 2 | } |
1596 | | |
1597 | 2.43M | const FunctionType *FnType = CalleeType->castAs<FunctionType>(); |
1598 | 2.43M | return FnType->getReturnType(); |
1599 | 2.43M | } |
1600 | | |
1601 | 624k | const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const { |
1602 | | // If the return type is a struct, union, or enum that is marked nodiscard, |
1603 | | // then return the return type attribute. |
1604 | 624k | if (const TagDecl *TD = getCallReturnType(Ctx)->getAsTagDecl()) |
1605 | 8.43k | if (const auto *A = TD->getAttr<WarnUnusedResultAttr>()) |
1606 | 92 | return A; |
1607 | | |
1608 | 645k | for (const auto *TD = getCallReturnType(Ctx)->getAs<TypedefType>(); 624k TD; |
1609 | 624k | TD = TD->desugar()->getAs<TypedefType>()21.5k ) |
1610 | 21.5k | if (const auto *A = TD->getDecl()->getAttr<WarnUnusedResultAttr>()) |
1611 | 10 | return A; |
1612 | | |
1613 | | // Otherwise, see if the callee is marked nodiscard and return that attribute |
1614 | | // instead. |
1615 | 623k | const Decl *D = getCalleeDecl(); |
1616 | 623k | return D ? D->getAttr<WarnUnusedResultAttr>() : nullptr0 ; |
1617 | 624k | } |
1618 | | |
1619 | 32.7M | SourceLocation CallExpr::getBeginLoc() const { |
1620 | 32.7M | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this)) |
1621 | 18 | return OCE->getBeginLoc(); |
1622 | | |
1623 | 32.7M | SourceLocation begin = getCallee()->getBeginLoc(); |
1624 | 32.7M | if (begin.isInvalid() && getNumArgs() > 01.39k && getArg(0)1.29k ) |
1625 | 1.29k | begin = getArg(0)->getBeginLoc(); |
1626 | 32.7M | return begin; |
1627 | 32.7M | } |
1628 | 4.00M | SourceLocation CallExpr::getEndLoc() const { |
1629 | 4.00M | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this)) |
1630 | 0 | return OCE->getEndLoc(); |
1631 | | |
1632 | 4.00M | SourceLocation end = getRParenLoc(); |
1633 | 4.00M | if (end.isInvalid() && getNumArgs() > 08 && getArg(getNumArgs() - 1)8 ) |
1634 | 8 | end = getArg(getNumArgs() - 1)->getEndLoc(); |
1635 | 4.00M | return end; |
1636 | 4.00M | } |
1637 | | |
1638 | | OffsetOfExpr *OffsetOfExpr::Create(const ASTContext &C, QualType type, |
1639 | | SourceLocation OperatorLoc, |
1640 | | TypeSourceInfo *tsi, |
1641 | | ArrayRef<OffsetOfNode> comps, |
1642 | | ArrayRef<Expr*> exprs, |
1643 | 487 | SourceLocation RParenLoc) { |
1644 | 487 | void *Mem = C.Allocate( |
1645 | 487 | totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size())); |
1646 | | |
1647 | 487 | return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, |
1648 | 487 | RParenLoc); |
1649 | 487 | } |
1650 | | |
1651 | | OffsetOfExpr *OffsetOfExpr::CreateEmpty(const ASTContext &C, |
1652 | 2 | unsigned numComps, unsigned numExprs) { |
1653 | 2 | void *Mem = |
1654 | 2 | C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs)); |
1655 | 2 | return new (Mem) OffsetOfExpr(numComps, numExprs); |
1656 | 2 | } |
1657 | | |
1658 | | OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type, |
1659 | | SourceLocation OperatorLoc, TypeSourceInfo *tsi, |
1660 | | ArrayRef<OffsetOfNode> comps, ArrayRef<Expr *> exprs, |
1661 | | SourceLocation RParenLoc) |
1662 | | : Expr(OffsetOfExprClass, type, VK_PRValue, OK_Ordinary), |
1663 | | OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), |
1664 | 487 | NumComps(comps.size()), NumExprs(exprs.size()) { |
1665 | 1.12k | for (unsigned i = 0; i != comps.size(); ++i638 ) |
1666 | 638 | setComponent(i, comps[i]); |
1667 | 549 | for (unsigned i = 0; i != exprs.size(); ++i62 ) |
1668 | 62 | setIndexExpr(i, exprs[i]); |
1669 | | |
1670 | 487 | setDependence(computeDependence(this)); |
1671 | 487 | } |
1672 | | |
1673 | 19 | IdentifierInfo *OffsetOfNode::getFieldName() const { |
1674 | 19 | assert(getKind() == Field || getKind() == Identifier); |
1675 | 19 | if (getKind() == Field) |
1676 | 2 | return getField()->getIdentifier(); |
1677 | | |
1678 | 17 | return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); |
1679 | 19 | } |
1680 | | |
1681 | | UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr( |
1682 | | UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType, |
1683 | | SourceLocation op, SourceLocation rp) |
1684 | | : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue, OK_Ordinary), |
1685 | 25.2k | OpLoc(op), RParenLoc(rp) { |
1686 | 25.2k | assert(ExprKind <= UETT_Last && "invalid enum value!"); |
1687 | 25.2k | UnaryExprOrTypeTraitExprBits.Kind = ExprKind; |
1688 | 25.2k | assert(static_cast<unsigned>(ExprKind) == UnaryExprOrTypeTraitExprBits.Kind && |
1689 | 25.2k | "UnaryExprOrTypeTraitExprBits.Kind overflow!"); |
1690 | 25.2k | UnaryExprOrTypeTraitExprBits.IsType = false; |
1691 | 25.2k | Argument.Ex = E; |
1692 | 25.2k | setDependence(computeDependence(this)); |
1693 | 25.2k | } |
1694 | | |
1695 | | MemberExpr::MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc, |
1696 | | ValueDecl *MemberDecl, |
1697 | | const DeclarationNameInfo &NameInfo, QualType T, |
1698 | | ExprValueKind VK, ExprObjectKind OK, |
1699 | | NonOdrUseReason NOUR) |
1700 | | : Expr(MemberExprClass, T, VK, OK), Base(Base), MemberDecl(MemberDecl), |
1701 | 2.02M | MemberDNLoc(NameInfo.getInfo()), MemberLoc(NameInfo.getLoc()) { |
1702 | 2.02M | assert(!NameInfo.getName() || |
1703 | 2.02M | MemberDecl->getDeclName() == NameInfo.getName()); |
1704 | 2.02M | MemberExprBits.IsArrow = IsArrow; |
1705 | 2.02M | MemberExprBits.HasQualifierOrFoundDecl = false; |
1706 | 2.02M | MemberExprBits.HasTemplateKWAndArgsInfo = false; |
1707 | 2.02M | MemberExprBits.HadMultipleCandidates = false; |
1708 | 2.02M | MemberExprBits.NonOdrUseReason = NOUR; |
1709 | 2.02M | MemberExprBits.OperatorLoc = OperatorLoc; |
1710 | 2.02M | setDependence(computeDependence(this)); |
1711 | 2.02M | } |
1712 | | |
1713 | | MemberExpr *MemberExpr::Create( |
1714 | | const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, |
1715 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
1716 | | ValueDecl *MemberDecl, DeclAccessPair FoundDecl, |
1717 | | DeclarationNameInfo NameInfo, const TemplateArgumentListInfo *TemplateArgs, |
1718 | 2.02M | QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR) { |
1719 | 2.02M | bool HasQualOrFound = QualifierLoc || FoundDecl.getDecl() != MemberDecl2.01M || |
1720 | 2.02M | FoundDecl.getAccess() != MemberDecl->getAccess()1.98M ; |
1721 | 2.02M | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid()2.02M ; |
1722 | 2.02M | std::size_t Size = |
1723 | 2.02M | totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo, |
1724 | 2.02M | TemplateArgumentLoc>( |
1725 | 2.02M | HasQualOrFound ? 155.0k : 01.97M , HasTemplateKWAndArgsInfo ? 12.38k : 02.02M , |
1726 | 2.02M | TemplateArgs ? TemplateArgs->size()2.35k : 02.02M ); |
1727 | | |
1728 | 2.02M | void *Mem = C.Allocate(Size, alignof(MemberExpr)); |
1729 | 2.02M | MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl, |
1730 | 2.02M | NameInfo, T, VK, OK, NOUR); |
1731 | | |
1732 | | // FIXME: remove remaining dependence computation to computeDependence(). |
1733 | 2.02M | auto Deps = E->getDependence(); |
1734 | 2.02M | if (HasQualOrFound) { |
1735 | | // FIXME: Wrong. We should be looking at the member declaration we found. |
1736 | 55.0k | if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()12.9k ) |
1737 | 8 | Deps |= ExprDependence::TypeValueInstantiation; |
1738 | 55.0k | else if (QualifierLoc && |
1739 | 55.0k | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()12.9k ) |
1740 | 0 | Deps |= ExprDependence::Instantiation; |
1741 | | |
1742 | 55.0k | E->MemberExprBits.HasQualifierOrFoundDecl = true; |
1743 | | |
1744 | 55.0k | MemberExprNameQualifier *NQ = |
1745 | 55.0k | E->getTrailingObjects<MemberExprNameQualifier>(); |
1746 | 55.0k | NQ->QualifierLoc = QualifierLoc; |
1747 | 55.0k | NQ->FoundDecl = FoundDecl; |
1748 | 55.0k | } |
1749 | | |
1750 | 2.02M | E->MemberExprBits.HasTemplateKWAndArgsInfo = |
1751 | 2.02M | TemplateArgs || TemplateKWLoc.isValid()2.02M ; |
1752 | | |
1753 | 2.02M | if (TemplateArgs) { |
1754 | 2.35k | auto TemplateArgDeps = TemplateArgumentDependence::None; |
1755 | 2.35k | E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1756 | 2.35k | TemplateKWLoc, *TemplateArgs, |
1757 | 2.35k | E->getTrailingObjects<TemplateArgumentLoc>(), TemplateArgDeps); |
1758 | 2.35k | if (TemplateArgDeps & TemplateArgumentDependence::Instantiation) |
1759 | 0 | Deps |= ExprDependence::Instantiation; |
1760 | 2.02M | } else if (TemplateKWLoc.isValid()) { |
1761 | 35 | E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1762 | 35 | TemplateKWLoc); |
1763 | 35 | } |
1764 | 2.02M | E->setDependence(Deps); |
1765 | | |
1766 | 2.02M | return E; |
1767 | 2.02M | } |
1768 | | |
1769 | | MemberExpr *MemberExpr::CreateEmpty(const ASTContext &Context, |
1770 | | bool HasQualifier, bool HasFoundDecl, |
1771 | | bool HasTemplateKWAndArgsInfo, |
1772 | 238k | unsigned NumTemplateArgs) { |
1773 | 238k | assert((!NumTemplateArgs || HasTemplateKWAndArgsInfo) && |
1774 | 238k | "template args but no template arg info?"); |
1775 | 238k | bool HasQualOrFound = HasQualifier || HasFoundDecl237k ; |
1776 | 238k | std::size_t Size = |
1777 | 238k | totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo, |
1778 | 238k | TemplateArgumentLoc>(HasQualOrFound ? 15.35k : 0233k , |
1779 | 238k | HasTemplateKWAndArgsInfo ? 164 : 0238k , |
1780 | 238k | NumTemplateArgs); |
1781 | 238k | void *Mem = Context.Allocate(Size, alignof(MemberExpr)); |
1782 | 238k | return new (Mem) MemberExpr(EmptyShell()); |
1783 | 238k | } |
1784 | | |
1785 | 124 | void MemberExpr::setMemberDecl(ValueDecl *NewD) { |
1786 | 124 | MemberDecl = NewD; |
1787 | 124 | if (getType()->isUndeducedType()) |
1788 | 0 | setType(NewD->getType()); |
1789 | 124 | setDependence(computeDependence(this)); |
1790 | 124 | } |
1791 | | |
1792 | 6.02M | SourceLocation MemberExpr::getBeginLoc() const { |
1793 | 6.02M | if (isImplicitAccess()) { |
1794 | 2.64M | if (hasQualifier()) |
1795 | 28.7k | return getQualifierLoc().getBeginLoc(); |
1796 | 2.62M | return MemberLoc; |
1797 | 2.64M | } |
1798 | | |
1799 | | // FIXME: We don't want this to happen. Rather, we should be able to |
1800 | | // detect all kinds of implicit accesses more cleanly. |
1801 | 3.37M | SourceLocation BaseStartLoc = getBase()->getBeginLoc(); |
1802 | 3.37M | if (BaseStartLoc.isValid()) |
1803 | 3.37M | return BaseStartLoc; |
1804 | 1.24k | return MemberLoc; |
1805 | 3.37M | } |
1806 | 816k | SourceLocation MemberExpr::getEndLoc() const { |
1807 | 816k | SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); |
1808 | 816k | if (hasExplicitTemplateArgs()) |
1809 | 2.24k | EndLoc = getRAngleLoc(); |
1810 | 814k | else if (EndLoc.isInvalid()) |
1811 | 11.9k | EndLoc = getBase()->getEndLoc(); |
1812 | 816k | return EndLoc; |
1813 | 816k | } |
1814 | | |
1815 | 30.9M | bool CastExpr::CastConsistency() const { |
1816 | 30.9M | switch (getCastKind()) { |
1817 | 19.2k | case CK_DerivedToBase: |
1818 | 51.6k | case CK_UncheckedDerivedToBase: |
1819 | 51.7k | case CK_DerivedToBaseMemberPointer: |
1820 | 52.6k | case CK_BaseToDerived: |
1821 | 53.0k | case CK_BaseToDerivedMemberPointer: |
1822 | 53.0k | assert(!path_empty() && "Cast kind should have a base path!"); |
1823 | 53.0k | break; |
1824 | | |
1825 | 53.0k | case CK_CPointerToObjCPointerCast: |
1826 | 5.73k | assert(getType()->isObjCObjectPointerType()); |
1827 | 5.73k | assert(getSubExpr()->getType()->isPointerType()); |
1828 | 5.73k | goto CheckNoBasePath; |
1829 | | |
1830 | 5.73k | case CK_BlockPointerToObjCPointerCast: |
1831 | 91 | assert(getType()->isObjCObjectPointerType()); |
1832 | 91 | assert(getSubExpr()->getType()->isBlockPointerType()); |
1833 | 91 | goto CheckNoBasePath; |
1834 | | |
1835 | 91 | case CK_ReinterpretMemberPointer: |
1836 | 62 | assert(getType()->isMemberPointerType()); |
1837 | 62 | assert(getSubExpr()->getType()->isMemberPointerType()); |
1838 | 62 | goto CheckNoBasePath; |
1839 | | |
1840 | 4.90M | case CK_BitCast: |
1841 | | // Arbitrary casts to C pointer types count as bitcasts. |
1842 | | // Otherwise, we should only have block and ObjC pointer casts |
1843 | | // here if they stay within the type kind. |
1844 | 4.90M | if (!getType()->isPointerType()) { |
1845 | 4.64M | assert(getType()->isObjCObjectPointerType() == |
1846 | 4.64M | getSubExpr()->getType()->isObjCObjectPointerType()); |
1847 | 4.64M | assert(getType()->isBlockPointerType() == |
1848 | 4.64M | getSubExpr()->getType()->isBlockPointerType()); |
1849 | 4.64M | } |
1850 | 4.90M | goto CheckNoBasePath; |
1851 | | |
1852 | 4.90M | case CK_AnyPointerToBlockPointerCast: |
1853 | 62 | assert(getType()->isBlockPointerType()); |
1854 | 62 | assert(getSubExpr()->getType()->isAnyPointerType() && |
1855 | 62 | !getSubExpr()->getType()->isBlockPointerType()); |
1856 | 62 | goto CheckNoBasePath; |
1857 | | |
1858 | 62 | case CK_CopyAndAutoreleaseBlockObject: |
1859 | 12 | assert(getType()->isBlockPointerType()); |
1860 | 12 | assert(getSubExpr()->getType()->isBlockPointerType()); |
1861 | 12 | goto CheckNoBasePath; |
1862 | | |
1863 | 3.05M | case CK_FunctionToPointerDecay: |
1864 | 3.05M | assert(getType()->isPointerType()); |
1865 | 3.05M | assert(getSubExpr()->getType()->isFunctionType()); |
1866 | 3.05M | goto CheckNoBasePath; |
1867 | | |
1868 | 3.05M | case CK_AddressSpaceConversion: { |
1869 | 1.34k | auto Ty = getType(); |
1870 | 1.34k | auto SETy = getSubExpr()->getType(); |
1871 | 1.34k | assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy)); |
1872 | 1.34k | if (isPRValue() && !Ty->isDependentType()1.22k && !SETy->isDependentType()1.22k ) { |
1873 | 1.22k | Ty = Ty->getPointeeType(); |
1874 | 1.22k | SETy = SETy->getPointeeType(); |
1875 | 1.22k | } |
1876 | 1.34k | assert((Ty->isDependentType() || SETy->isDependentType()) || |
1877 | 1.34k | (!Ty.isNull() && !SETy.isNull() && |
1878 | 1.34k | Ty.getAddressSpace() != SETy.getAddressSpace())); |
1879 | 1.34k | goto CheckNoBasePath; |
1880 | 1.34k | } |
1881 | | // These should not have an inheritance path. |
1882 | 1.34k | case CK_Dynamic: |
1883 | 255 | case CK_ToUnion: |
1884 | 270k | case CK_ArrayToPointerDecay: |
1885 | 271k | case CK_NullToMemberPointer: |
1886 | 358k | case CK_NullToPointer: |
1887 | 394k | case CK_ConstructorConversion: |
1888 | 399k | case CK_IntegralToPointer: |
1889 | 406k | case CK_PointerToIntegral: |
1890 | 507k | case CK_ToVoid: |
1891 | 511k | case CK_VectorSplat: |
1892 | 3.53M | case CK_IntegralCast: |
1893 | 3.53M | case CK_BooleanToSignedIntegral: |
1894 | 3.58M | case CK_IntegralToFloating: |
1895 | 3.59M | case CK_FloatingToIntegral: |
1896 | 3.62M | case CK_FloatingCast: |
1897 | 3.62M | case CK_ObjCObjectLValueCast: |
1898 | 3.62M | case CK_FloatingRealToComplex: |
1899 | 3.62M | case CK_FloatingComplexToReal: |
1900 | 3.62M | case CK_FloatingComplexCast: |
1901 | 3.62M | case CK_FloatingComplexToIntegralComplex: |
1902 | 3.62M | case CK_IntegralRealToComplex: |
1903 | 3.62M | case CK_IntegralComplexToReal: |
1904 | 3.62M | case CK_IntegralComplexCast: |
1905 | 3.62M | case CK_IntegralComplexToFloatingComplex: |
1906 | 3.62M | case CK_ARCProduceObject: |
1907 | 3.62M | case CK_ARCConsumeObject: |
1908 | 3.62M | case CK_ARCReclaimReturnedObject: |
1909 | 3.62M | case CK_ARCExtendBlockObject: |
1910 | 3.62M | case CK_ZeroToOCLOpaqueType: |
1911 | 3.62M | case CK_IntToOCLSampler: |
1912 | 3.62M | case CK_FloatingToFixedPoint: |
1913 | 3.62M | case CK_FixedPointToFloating: |
1914 | 3.62M | case CK_FixedPointCast: |
1915 | 3.62M | case CK_FixedPointToIntegral: |
1916 | 3.62M | case CK_IntegralToFixedPoint: |
1917 | 3.62M | case CK_MatrixCast: |
1918 | 3.62M | assert(!getType()->isBooleanType() && "unheralded conversion to bool"); |
1919 | 3.62M | goto CheckNoBasePath; |
1920 | | |
1921 | 3.62M | case CK_Dependent: |
1922 | 15.0M | case CK_LValueToRValue: |
1923 | 16.7M | case CK_NoOp: |
1924 | 16.7M | case CK_AtomicToNonAtomic: |
1925 | 16.7M | case CK_NonAtomicToAtomic: |
1926 | 16.7M | case CK_PointerToBoolean: |
1927 | 16.8M | case CK_IntegralToBoolean: |
1928 | 16.8M | case CK_FloatingToBoolean: |
1929 | 16.8M | case CK_MemberPointerToBoolean: |
1930 | 16.8M | case CK_FloatingComplexToBoolean: |
1931 | 16.8M | case CK_IntegralComplexToBoolean: |
1932 | 16.8M | case CK_LValueBitCast: // -> bool& |
1933 | 16.8M | case CK_LValueToRValueBitCast: |
1934 | 16.8M | case CK_UserDefinedConversion: // operator bool() |
1935 | 19.2M | case CK_BuiltinFnToFnPtr: |
1936 | 19.2M | case CK_FixedPointToBoolean: |
1937 | 30.8M | CheckNoBasePath: |
1938 | 30.8M | assert(path_empty() && "Cast kind should not have a base path!"); |
1939 | 30.8M | break; |
1940 | 30.9M | } |
1941 | 30.9M | return true; |
1942 | 30.9M | } |
1943 | | |
1944 | 8.47k | const char *CastExpr::getCastKindName(CastKind CK) { |
1945 | 8.47k | switch (CK) { |
1946 | 8.47k | #define CAST_OPERATION(Name) case CK_##Name: return #Name; |
1947 | 8.47k | #include "clang/AST/OperationKinds.def"0 |
1948 | 8.47k | } |
1949 | 0 | llvm_unreachable("Unhandled cast kind!"); |
1950 | 0 | } |
1951 | | |
1952 | | namespace { |
1953 | | // Skip over implicit nodes produced as part of semantic analysis. |
1954 | | // Designed for use with IgnoreExprNodes. |
1955 | 1.98M | static Expr *ignoreImplicitSemaNodes(Expr *E) { |
1956 | 1.98M | if (auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(E)) |
1957 | 4.01k | return Materialize->getSubExpr(); |
1958 | | |
1959 | 1.97M | if (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
1960 | 13.0k | return Binder->getSubExpr(); |
1961 | | |
1962 | 1.96M | if (auto *Full = dyn_cast<FullExpr>(E)) |
1963 | 61 | return Full->getSubExpr(); |
1964 | | |
1965 | 1.96M | if (auto *CPLIE = dyn_cast<CXXParenListInitExpr>(E); |
1966 | 1.96M | CPLIE && CPLIE->getInitExprs().size() == 12 ) |
1967 | 1 | return CPLIE->getInitExprs()[0]; |
1968 | | |
1969 | 1.96M | return E; |
1970 | 1.96M | } |
1971 | | } // namespace |
1972 | | |
1973 | 1.87M | Expr *CastExpr::getSubExprAsWritten() { |
1974 | 1.87M | const Expr *SubExpr = nullptr; |
1975 | | |
1976 | 3.83M | for (const CastExpr *E = this; E; E = dyn_cast<ImplicitCastExpr>(SubExpr)1.96M ) { |
1977 | 1.96M | SubExpr = IgnoreExprNodes(E->getSubExpr(), ignoreImplicitSemaNodes); |
1978 | | |
1979 | | // Conversions by constructor and conversion functions have a |
1980 | | // subexpression describing the call; strip it off. |
1981 | 1.96M | if (E->getCastKind() == CK_ConstructorConversion) { |
1982 | 3.81k | SubExpr = IgnoreExprNodes(cast<CXXConstructExpr>(SubExpr)->getArg(0), |
1983 | 3.81k | ignoreImplicitSemaNodes); |
1984 | 1.95M | } else if (E->getCastKind() == CK_UserDefinedConversion) { |
1985 | 1.76k | assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) && |
1986 | 1.76k | "Unexpected SubExpr for CK_UserDefinedConversion."); |
1987 | 1.76k | if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr)) |
1988 | 1.76k | SubExpr = MCE->getImplicitObjectArgument(); |
1989 | 1.76k | } |
1990 | 1.96M | } |
1991 | | |
1992 | 1.87M | return const_cast<Expr *>(SubExpr); |
1993 | 1.87M | } |
1994 | | |
1995 | 1.39k | NamedDecl *CastExpr::getConversionFunction() const { |
1996 | 1.39k | const Expr *SubExpr = nullptr; |
1997 | | |
1998 | 2.82k | for (const CastExpr *E = this; E; E = dyn_cast<ImplicitCastExpr>(SubExpr)1.43k ) { |
1999 | 1.50k | SubExpr = IgnoreExprNodes(E->getSubExpr(), ignoreImplicitSemaNodes); |
2000 | | |
2001 | 1.50k | if (E->getCastKind() == CK_ConstructorConversion) |
2002 | 1 | return cast<CXXConstructExpr>(SubExpr)->getConstructor(); |
2003 | | |
2004 | 1.49k | if (E->getCastKind() == CK_UserDefinedConversion) { |
2005 | 67 | if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr)) |
2006 | 67 | return MCE->getMethodDecl(); |
2007 | 67 | } |
2008 | 1.49k | } |
2009 | | |
2010 | 1.32k | return nullptr; |
2011 | 1.39k | } |
2012 | | |
2013 | 3.29M | CXXBaseSpecifier **CastExpr::path_buffer() { |
2014 | 3.29M | switch (getStmtClass()) { |
2015 | 0 | #define ABSTRACT_STMT(x) |
2016 | 0 | #define CASTEXPR(Type, Base) \ |
2017 | 3.29M | case Stmt::Type##Class: \ |
2018 | 3.29M | return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>(); |
2019 | 0 | #define STMT(Type, Base) |
2020 | 0 | #include "clang/AST/StmtNodes.inc" |
2021 | 0 | default: |
2022 | 0 | llvm_unreachable("non-cast expressions not possible here"); |
2023 | 3.29M | } |
2024 | 3.29M | } |
2025 | | |
2026 | | const FieldDecl *CastExpr::getTargetFieldForToUnionCast(QualType unionType, |
2027 | 4 | QualType opType) { |
2028 | 4 | auto RD = unionType->castAs<RecordType>()->getDecl(); |
2029 | 4 | return getTargetFieldForToUnionCast(RD, opType); |
2030 | 4 | } |
2031 | | |
2032 | | const FieldDecl *CastExpr::getTargetFieldForToUnionCast(const RecordDecl *RD, |
2033 | 29 | QualType OpType) { |
2034 | 29 | auto &Ctx = RD->getASTContext(); |
2035 | 29 | RecordDecl::field_iterator Field, FieldEnd; |
2036 | 29 | for (Field = RD->field_begin(), FieldEnd = RD->field_end(); |
2037 | 46 | Field != FieldEnd; ++Field17 ) { |
2038 | 43 | if (Ctx.hasSameUnqualifiedType(Field->getType(), OpType) && |
2039 | 43 | !Field->isUnnamedBitfield()27 ) { |
2040 | 26 | return *Field; |
2041 | 26 | } |
2042 | 43 | } |
2043 | 3 | return nullptr; |
2044 | 29 | } |
2045 | | |
2046 | 426k | FPOptionsOverride *CastExpr::getTrailingFPFeatures() { |
2047 | 426k | assert(hasStoredFPFeatures()); |
2048 | 426k | switch (getStmtClass()) { |
2049 | 257k | case ImplicitCastExprClass: |
2050 | 257k | return static_cast<ImplicitCastExpr *>(this) |
2051 | 257k | ->getTrailingObjects<FPOptionsOverride>(); |
2052 | 169k | case CStyleCastExprClass: |
2053 | 169k | return static_cast<CStyleCastExpr *>(this) |
2054 | 169k | ->getTrailingObjects<FPOptionsOverride>(); |
2055 | 6 | case CXXFunctionalCastExprClass: |
2056 | 6 | return static_cast<CXXFunctionalCastExpr *>(this) |
2057 | 6 | ->getTrailingObjects<FPOptionsOverride>(); |
2058 | 6 | case CXXStaticCastExprClass: |
2059 | 6 | return static_cast<CXXStaticCastExpr *>(this) |
2060 | 6 | ->getTrailingObjects<FPOptionsOverride>(); |
2061 | 0 | default: |
2062 | 0 | llvm_unreachable("Cast does not have FPFeatures"); |
2063 | 426k | } |
2064 | 426k | } |
2065 | | |
2066 | | ImplicitCastExpr *ImplicitCastExpr::Create(const ASTContext &C, QualType T, |
2067 | | CastKind Kind, Expr *Operand, |
2068 | | const CXXCastPath *BasePath, |
2069 | | ExprValueKind VK, |
2070 | 23.9M | FPOptionsOverride FPO) { |
2071 | 23.9M | unsigned PathSize = (BasePath ? BasePath->size()588k : 023.3M ); |
2072 | 23.9M | void *Buffer = |
2073 | 23.9M | C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
2074 | 23.9M | PathSize, FPO.requiresTrailingStorage())); |
2075 | | // Per C++ [conv.lval]p3, lvalue-to-rvalue conversions on class and |
2076 | | // std::nullptr_t have special semantics not captured by CK_LValueToRValue. |
2077 | 23.9M | assert((Kind != CK_LValueToRValue || |
2078 | 23.9M | !(T->isNullPtrType() || T->getAsCXXRecordDecl())) && |
2079 | 23.9M | "invalid type for lvalue-to-rvalue conversion"); |
2080 | 23.9M | ImplicitCastExpr *E = |
2081 | 23.9M | new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, FPO, VK); |
2082 | 23.9M | if (PathSize) |
2083 | 51.9k | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
2084 | 51.9k | E->getTrailingObjects<CXXBaseSpecifier *>()); |
2085 | 23.9M | return E; |
2086 | 23.9M | } |
2087 | | |
2088 | | ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(const ASTContext &C, |
2089 | | unsigned PathSize, |
2090 | 788k | bool HasFPFeatures) { |
2091 | 788k | void *Buffer = |
2092 | 788k | C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
2093 | 788k | PathSize, HasFPFeatures)); |
2094 | 788k | return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize, HasFPFeatures); |
2095 | 788k | } |
2096 | | |
2097 | | CStyleCastExpr *CStyleCastExpr::Create(const ASTContext &C, QualType T, |
2098 | | ExprValueKind VK, CastKind K, Expr *Op, |
2099 | | const CXXCastPath *BasePath, |
2100 | | FPOptionsOverride FPO, |
2101 | | TypeSourceInfo *WrittenTy, |
2102 | 5.73M | SourceLocation L, SourceLocation R) { |
2103 | 5.73M | unsigned PathSize = (BasePath ? BasePath->size()5.72M : 03.23k ); |
2104 | 5.73M | void *Buffer = |
2105 | 5.73M | C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
2106 | 5.73M | PathSize, FPO.requiresTrailingStorage())); |
2107 | 5.73M | CStyleCastExpr *E = |
2108 | 5.73M | new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, FPO, WrittenTy, L, R); |
2109 | 5.73M | if (PathSize) |
2110 | 220 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
2111 | 220 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
2112 | 5.73M | return E; |
2113 | 5.73M | } |
2114 | | |
2115 | | CStyleCastExpr *CStyleCastExpr::CreateEmpty(const ASTContext &C, |
2116 | | unsigned PathSize, |
2117 | 16.3k | bool HasFPFeatures) { |
2118 | 16.3k | void *Buffer = |
2119 | 16.3k | C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>( |
2120 | 16.3k | PathSize, HasFPFeatures)); |
2121 | 16.3k | return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize, HasFPFeatures); |
2122 | 16.3k | } |
2123 | | |
2124 | | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
2125 | | /// corresponds to, e.g. "<<=". |
2126 | 382k | StringRef BinaryOperator::getOpcodeStr(Opcode Op) { |
2127 | 382k | switch (Op) { |
2128 | 382k | #define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling; |
2129 | 382k | #include "clang/AST/OperationKinds.def"0 |
2130 | 382k | } |
2131 | 0 | llvm_unreachable("Invalid OpCode!"); |
2132 | 0 | } |
2133 | | |
2134 | | BinaryOperatorKind |
2135 | 105k | BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { |
2136 | 105k | switch (OO) { |
2137 | 0 | default: llvm_unreachable("Not an overloadable binary operator"); |
2138 | 18.8k | case OO_Plus: return BO_Add; |
2139 | 15.6k | case OO_Minus: return BO_Sub; |
2140 | 186 | case OO_Star: return BO_Mul; |
2141 | 403 | case OO_Slash: return BO_Div; |
2142 | 2 | case OO_Percent: return BO_Rem; |
2143 | 261 | case OO_Caret: return BO_Xor; |
2144 | 172 | case OO_Amp: return BO_And; |
2145 | 82 | case OO_Pipe: return BO_Or; |
2146 | 136 | case OO_Equal: return BO_Assign; |
2147 | 189 | case OO_Spaceship: return BO_Cmp; |
2148 | 11.9k | case OO_Less: return BO_LT; |
2149 | 10.5k | case OO_Greater: return BO_GT; |
2150 | 58 | case OO_PlusEqual: return BO_AddAssign; |
2151 | 0 | case OO_MinusEqual: return BO_SubAssign; |
2152 | 0 | case OO_StarEqual: return BO_MulAssign; |
2153 | 0 | case OO_SlashEqual: return BO_DivAssign; |
2154 | 0 | case OO_PercentEqual: return BO_RemAssign; |
2155 | 60 | case OO_CaretEqual: return BO_XorAssign; |
2156 | 0 | case OO_AmpEqual: return BO_AndAssign; |
2157 | 0 | case OO_PipeEqual: return BO_OrAssign; |
2158 | 318 | case OO_LessLess: return BO_Shl; |
2159 | 251 | case OO_GreaterGreater: return BO_Shr; |
2160 | 0 | case OO_LessLessEqual: return BO_ShlAssign; |
2161 | 0 | case OO_GreaterGreaterEqual: return BO_ShrAssign; |
2162 | 23.4k | case OO_EqualEqual: return BO_EQ; |
2163 | 7.98k | case OO_ExclaimEqual: return BO_NE; |
2164 | 2.33k | case OO_LessEqual: return BO_LE; |
2165 | 3.57k | case OO_GreaterEqual: return BO_GE; |
2166 | 8.81k | case OO_AmpAmp: return BO_LAnd; |
2167 | 249 | case OO_PipePipe: return BO_LOr; |
2168 | 0 | case OO_Comma: return BO_Comma; |
2169 | 5 | case OO_ArrowStar: return BO_PtrMemI; |
2170 | 105k | } |
2171 | 105k | } |
2172 | | |
2173 | 5.25M | OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { |
2174 | 5.25M | static const OverloadedOperatorKind OverOps[] = { |
2175 | 5.25M | /* .* Cannot be overloaded */OO_None, OO_ArrowStar, |
2176 | 5.25M | OO_Star, OO_Slash, OO_Percent, |
2177 | 5.25M | OO_Plus, OO_Minus, |
2178 | 5.25M | OO_LessLess, OO_GreaterGreater, |
2179 | 5.25M | OO_Spaceship, |
2180 | 5.25M | OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, |
2181 | 5.25M | OO_EqualEqual, OO_ExclaimEqual, |
2182 | 5.25M | OO_Amp, |
2183 | 5.25M | OO_Caret, |
2184 | 5.25M | OO_Pipe, |
2185 | 5.25M | OO_AmpAmp, |
2186 | 5.25M | OO_PipePipe, |
2187 | 5.25M | OO_Equal, OO_StarEqual, |
2188 | 5.25M | OO_SlashEqual, OO_PercentEqual, |
2189 | 5.25M | OO_PlusEqual, OO_MinusEqual, |
2190 | 5.25M | OO_LessLessEqual, OO_GreaterGreaterEqual, |
2191 | 5.25M | OO_AmpEqual, OO_CaretEqual, |
2192 | 5.25M | OO_PipeEqual, |
2193 | 5.25M | OO_Comma |
2194 | 5.25M | }; |
2195 | 5.25M | return OverOps[Opc]; |
2196 | 5.25M | } |
2197 | | |
2198 | | bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, |
2199 | | Opcode Opc, |
2200 | | const Expr *LHS, |
2201 | 19.2k | const Expr *RHS) { |
2202 | 19.2k | if (Opc != BO_Add) |
2203 | 638 | return false; |
2204 | | |
2205 | | // Check that we have one pointer and one integer operand. |
2206 | 18.5k | const Expr *PExp; |
2207 | 18.5k | if (LHS->getType()->isPointerType()) { |
2208 | 18.4k | if (!RHS->getType()->isIntegerType()) |
2209 | 0 | return false; |
2210 | 18.4k | PExp = LHS; |
2211 | 18.4k | } else if (99 RHS->getType()->isPointerType()99 ) { |
2212 | 98 | if (!LHS->getType()->isIntegerType()) |
2213 | 0 | return false; |
2214 | 98 | PExp = RHS; |
2215 | 98 | } else { |
2216 | 1 | return false; |
2217 | 1 | } |
2218 | | |
2219 | | // Check that the pointer is a nullptr. |
2220 | 18.5k | if (!PExp->IgnoreParenCasts() |
2221 | 18.5k | ->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull)) |
2222 | 17.0k | return false; |
2223 | | |
2224 | | // Check that the pointee type is char-sized. |
2225 | 1.52k | const PointerType *PTy = PExp->getType()->getAs<PointerType>(); |
2226 | 1.52k | if (!PTy || !PTy->getPointeeType()->isCharType()) |
2227 | 1.48k | return false; |
2228 | | |
2229 | 40 | return true; |
2230 | 1.52k | } |
2231 | | |
2232 | | SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, IdentKind Kind, |
2233 | | QualType ResultTy, SourceLocation BLoc, |
2234 | | SourceLocation RParenLoc, |
2235 | | DeclContext *ParentContext) |
2236 | | : Expr(SourceLocExprClass, ResultTy, VK_PRValue, OK_Ordinary), |
2237 | 397 | BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) { |
2238 | 397 | SourceLocExprBits.Kind = Kind; |
2239 | 397 | setDependence(ExprDependence::None); |
2240 | 397 | } |
2241 | | |
2242 | 36 | StringRef SourceLocExpr::getBuiltinStr() const { |
2243 | 36 | switch (getIdentKind()) { |
2244 | 12 | case File: |
2245 | 12 | return "__builtin_FILE"; |
2246 | 12 | case FileName: |
2247 | 12 | return "__builtin_FILE_NAME"; |
2248 | 0 | case Function: |
2249 | 0 | return "__builtin_FUNCTION"; |
2250 | 0 | case FuncSig: |
2251 | 0 | return "__builtin_FUNCSIG"; |
2252 | 0 | case Line: |
2253 | 0 | return "__builtin_LINE"; |
2254 | 12 | case Column: |
2255 | 12 | return "__builtin_COLUMN"; |
2256 | 0 | case SourceLocStruct: |
2257 | 0 | return "__builtin_source_location"; |
2258 | 36 | } |
2259 | 0 | llvm_unreachable("unexpected IdentKind!"); |
2260 | 0 | } |
2261 | | |
2262 | | APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx, |
2263 | 1.49k | const Expr *DefaultExpr) const { |
2264 | 1.49k | SourceLocation Loc; |
2265 | 1.49k | const DeclContext *Context; |
2266 | | |
2267 | 1.49k | std::tie(Loc, |
2268 | 1.49k | Context) = [&]() -> std::pair<SourceLocation, const DeclContext *> { |
2269 | 1.49k | if (auto *DIE = dyn_cast_or_null<CXXDefaultInitExpr>(DefaultExpr)) |
2270 | 394 | return {DIE->getUsedLocation(), DIE->getUsedContext()}; |
2271 | 1.10k | if (auto *DAE = dyn_cast_or_null<CXXDefaultArgExpr>(DefaultExpr)) |
2272 | 625 | return {DAE->getUsedLocation(), DAE->getUsedContext()}; |
2273 | 478 | return {this->getLocation(), this->getParentContext()}; |
2274 | 1.10k | }(); |
2275 | | |
2276 | 1.49k | PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc( |
2277 | 1.49k | Ctx.getSourceManager().getExpansionRange(Loc).getEnd()); |
2278 | | |
2279 | 1.49k | auto MakeStringLiteral = [&](StringRef Tmp) { |
2280 | 1.33k | using LValuePathEntry = APValue::LValuePathEntry; |
2281 | 1.33k | StringLiteral *Res = Ctx.getPredefinedStringLiteralFromCache(Tmp); |
2282 | | // Decay the string to a pointer to the first character. |
2283 | 1.33k | LValuePathEntry Path[1] = {LValuePathEntry::ArrayIndex(0)}; |
2284 | 1.33k | return APValue(Res, CharUnits::Zero(), Path, /*OnePastTheEnd=*/false); |
2285 | 1.33k | }; |
2286 | | |
2287 | 1.49k | switch (getIdentKind()) { |
2288 | 116 | case SourceLocExpr::FileName: { |
2289 | | // __builtin_FILE_NAME() is a Clang-specific extension that expands to the |
2290 | | // the last part of __builtin_FILE(). |
2291 | 116 | SmallString<256> FileName; |
2292 | 116 | clang::Preprocessor::processPathToFileName( |
2293 | 116 | FileName, PLoc, Ctx.getLangOpts(), Ctx.getTargetInfo()); |
2294 | 116 | return MakeStringLiteral(FileName); |
2295 | 0 | } |
2296 | 93 | case SourceLocExpr::File: { |
2297 | 93 | SmallString<256> Path(PLoc.getFilename()); |
2298 | 93 | clang::Preprocessor::processPathForFileMacro(Path, Ctx.getLangOpts(), |
2299 | 93 | Ctx.getTargetInfo()); |
2300 | 93 | return MakeStringLiteral(Path); |
2301 | 0 | } |
2302 | 115 | case SourceLocExpr::Function: |
2303 | 158 | case SourceLocExpr::FuncSig: { |
2304 | 158 | const auto *CurDecl = dyn_cast<Decl>(Context); |
2305 | 158 | const auto Kind = getIdentKind() == SourceLocExpr::Function |
2306 | 158 | ? PredefinedExpr::Function115 |
2307 | 158 | : PredefinedExpr::FuncSig43 ; |
2308 | 158 | return MakeStringLiteral( |
2309 | 158 | CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string("")0 ); |
2310 | 115 | } |
2311 | 577 | case SourceLocExpr::Line: |
2312 | 647 | case SourceLocExpr::Column: { |
2313 | 647 | llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy), |
2314 | 647 | /*isUnsigned=*/true); |
2315 | 647 | IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()577 |
2316 | 647 | : PLoc.getColumn()70 ; |
2317 | 647 | return APValue(IntVal); |
2318 | 577 | } |
2319 | 483 | case SourceLocExpr::SourceLocStruct: { |
2320 | | // Fill in a std::source_location::__impl structure, by creating an |
2321 | | // artificial file-scoped CompoundLiteralExpr, and returning a pointer to |
2322 | | // that. |
2323 | 483 | const CXXRecordDecl *ImplDecl = getType()->getPointeeCXXRecordDecl(); |
2324 | 483 | assert(ImplDecl); |
2325 | | |
2326 | | // Construct an APValue for the __impl struct, and get or create a Decl |
2327 | | // corresponding to that. Note that we've already verified that the shape of |
2328 | | // the ImplDecl type is as expected. |
2329 | | |
2330 | 483 | APValue Value(APValue::UninitStruct(), 0, 4); |
2331 | 1.93k | for (FieldDecl *F : ImplDecl->fields()) { |
2332 | 1.93k | StringRef Name = F->getName(); |
2333 | 1.93k | if (Name == "_M_file_name") { |
2334 | 483 | SmallString<256> Path(PLoc.getFilename()); |
2335 | 483 | clang::Preprocessor::processPathForFileMacro(Path, Ctx.getLangOpts(), |
2336 | 483 | Ctx.getTargetInfo()); |
2337 | 483 | Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(Path); |
2338 | 1.44k | } else if (Name == "_M_function_name") { |
2339 | | // Note: this emits the PrettyFunction name -- different than what |
2340 | | // __builtin_FUNCTION() above returns! |
2341 | 483 | const auto *CurDecl = dyn_cast<Decl>(Context); |
2342 | 483 | Value.getStructField(F->getFieldIndex()) = MakeStringLiteral( |
2343 | 483 | CurDecl && !isa<TranslationUnitDecl>(CurDecl) |
2344 | 483 | ? StringRef(PredefinedExpr::ComputeName( |
2345 | 402 | PredefinedExpr::PrettyFunction, CurDecl)) |
2346 | 483 | : ""81 ); |
2347 | 966 | } else if (Name == "_M_line") { |
2348 | 483 | QualType Ty = F->getType(); |
2349 | 483 | llvm::APSInt IntVal(Ctx.getIntWidth(Ty), |
2350 | 483 | Ty->hasUnsignedIntegerRepresentation()); |
2351 | 483 | IntVal = PLoc.getLine(); |
2352 | 483 | Value.getStructField(F->getFieldIndex()) = APValue(IntVal); |
2353 | 483 | } else if (Name == "_M_column") { |
2354 | 483 | QualType Ty = F->getType(); |
2355 | 483 | llvm::APSInt IntVal(Ctx.getIntWidth(Ty), |
2356 | 483 | Ty->hasUnsignedIntegerRepresentation()); |
2357 | 483 | IntVal = PLoc.getColumn(); |
2358 | 483 | Value.getStructField(F->getFieldIndex()) = APValue(IntVal); |
2359 | 483 | } |
2360 | 1.93k | } |
2361 | | |
2362 | 483 | UnnamedGlobalConstantDecl *GV = |
2363 | 483 | Ctx.getUnnamedGlobalConstantDecl(getType()->getPointeeType(), Value); |
2364 | | |
2365 | 483 | return APValue(GV, CharUnits::Zero(), ArrayRef<APValue::LValuePathEntry>{}, |
2366 | 483 | false); |
2367 | 483 | } |
2368 | 1.49k | } |
2369 | 0 | llvm_unreachable("unhandled case"); |
2370 | 0 | } |
2371 | | |
2372 | | InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, |
2373 | | ArrayRef<Expr *> initExprs, SourceLocation rbraceloc) |
2374 | | : Expr(InitListExprClass, QualType(), VK_PRValue, OK_Ordinary), |
2375 | | InitExprs(C, initExprs.size()), LBraceLoc(lbraceloc), |
2376 | 276k | RBraceLoc(rbraceloc), AltForm(nullptr, true) { |
2377 | 276k | sawArrayRangeDesignator(false); |
2378 | 276k | InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); |
2379 | | |
2380 | 276k | setDependence(computeDependence(this)); |
2381 | 276k | } |
2382 | | |
2383 | 111k | void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) { |
2384 | 111k | if (NumInits > InitExprs.size()) |
2385 | 88.9k | InitExprs.reserve(C, NumInits); |
2386 | 111k | } |
2387 | | |
2388 | 7.13k | void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) { |
2389 | 7.13k | InitExprs.resize(C, NumInits, nullptr); |
2390 | 7.13k | } |
2391 | | |
2392 | 523k | Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) { |
2393 | 523k | if (Init >= InitExprs.size()) { |
2394 | 518k | InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr); |
2395 | 518k | setInit(Init, expr); |
2396 | 518k | return nullptr; |
2397 | 518k | } |
2398 | | |
2399 | 5.01k | Expr *Result = cast_or_null<Expr>(InitExprs[Init]); |
2400 | 5.01k | setInit(Init, expr); |
2401 | 5.01k | return Result; |
2402 | 523k | } |
2403 | | |
2404 | 9.39k | void InitListExpr::setArrayFiller(Expr *filler) { |
2405 | 9.39k | assert(!hasArrayFiller() && "Filler already set!"); |
2406 | 9.39k | ArrayFillerOrUnionFieldInit = filler; |
2407 | | // Fill out any "holes" in the array due to designated initializers. |
2408 | 9.39k | Expr **inits = getInits(); |
2409 | 25.4k | for (unsigned i = 0, e = getNumInits(); i != e; ++i16.0k ) |
2410 | 16.0k | if (inits[i] == nullptr) |
2411 | 5.35k | inits[i] = filler; |
2412 | 9.39k | } |
2413 | | |
2414 | 7.58k | bool InitListExpr::isStringLiteralInit() const { |
2415 | 7.58k | if (getNumInits() != 1) |
2416 | 6.53k | return false; |
2417 | 1.04k | const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); |
2418 | 1.04k | if (!AT || !AT->getElementType()->isIntegerType()1.04k ) |
2419 | 385 | return false; |
2420 | | // It is possible for getInit() to return null. |
2421 | 663 | const Expr *Init = getInit(0); |
2422 | 663 | if (!Init) |
2423 | 0 | return false; |
2424 | 663 | Init = Init->IgnoreParenImpCasts(); |
2425 | 663 | return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init)526 ; |
2426 | 663 | } |
2427 | | |
2428 | 140k | bool InitListExpr::isTransparent() const { |
2429 | 140k | assert(isSemanticForm() && "syntactic form never semantically transparent"); |
2430 | | |
2431 | | // A glvalue InitListExpr is always just sugar. |
2432 | 140k | if (isGLValue()) { |
2433 | 73 | assert(getNumInits() == 1 && "multiple inits in glvalue init list"); |
2434 | 73 | return true; |
2435 | 73 | } |
2436 | | |
2437 | | // Otherwise, we're sugar if and only if we have exactly one initializer that |
2438 | | // is of the same type. |
2439 | 140k | if (getNumInits() != 1 || !getInit(0)28.1k ) |
2440 | 111k | return false; |
2441 | | |
2442 | | // Don't confuse aggregate initialization of a struct X { X &x; }; with a |
2443 | | // transparent struct copy. |
2444 | 28.1k | if (!getInit(0)->isPRValue() && getType()->isRecordType()706 ) |
2445 | 706 | return false; |
2446 | | |
2447 | 27.4k | return getType().getCanonicalType() == |
2448 | 27.4k | getInit(0)->getType().getCanonicalType(); |
2449 | 28.1k | } |
2450 | | |
2451 | 51.1k | bool InitListExpr::isIdiomaticZeroInitializer(const LangOptions &LangOpts) const { |
2452 | 51.1k | assert(isSyntacticForm() && "only test syntactic form as zero initializer"); |
2453 | | |
2454 | 51.1k | if (LangOpts.CPlusPlus || getNumInits() != 18.65k || !getInit(0)2.52k ) { |
2455 | 48.6k | return false; |
2456 | 48.6k | } |
2457 | | |
2458 | 2.52k | const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(getInit(0)->IgnoreImplicit()); |
2459 | 2.52k | return Lit && Lit->getValue() == 0797 ; |
2460 | 51.1k | } |
2461 | | |
2462 | 636k | SourceLocation InitListExpr::getBeginLoc() const { |
2463 | 636k | if (InitListExpr *SyntacticForm = getSyntacticForm()) |
2464 | 148k | return SyntacticForm->getBeginLoc(); |
2465 | 487k | SourceLocation Beg = LBraceLoc; |
2466 | 487k | if (Beg.isInvalid()) { |
2467 | | // Find the first non-null initializer. |
2468 | 267 | for (InitExprsTy::const_iterator I = InitExprs.begin(), |
2469 | 267 | E = InitExprs.end(); |
2470 | 267 | I != E; ++I0 ) { |
2471 | 267 | if (Stmt *S = *I) { |
2472 | 267 | Beg = S->getBeginLoc(); |
2473 | 267 | break; |
2474 | 267 | } |
2475 | 267 | } |
2476 | 267 | } |
2477 | 487k | return Beg; |
2478 | 636k | } |
2479 | | |
2480 | 449k | SourceLocation InitListExpr::getEndLoc() const { |
2481 | 449k | if (InitListExpr *SyntacticForm = getSyntacticForm()) |
2482 | 97.4k | return SyntacticForm->getEndLoc(); |
2483 | 351k | SourceLocation End = RBraceLoc; |
2484 | 351k | if (End.isInvalid()) { |
2485 | | // Find the first non-null initializer from the end. |
2486 | 72 | for (Stmt *S : llvm::reverse(InitExprs)) { |
2487 | 72 | if (S) { |
2488 | 72 | End = S->getEndLoc(); |
2489 | 72 | break; |
2490 | 72 | } |
2491 | 72 | } |
2492 | 72 | } |
2493 | 351k | return End; |
2494 | 449k | } |
2495 | | |
2496 | | /// getFunctionType - Return the underlying function type for this block. |
2497 | | /// |
2498 | 1.73k | const FunctionProtoType *BlockExpr::getFunctionType() const { |
2499 | | // The block pointer is never sugared, but the function type might be. |
2500 | 1.73k | return cast<BlockPointerType>(getType()) |
2501 | 1.73k | ->getPointeeType()->castAs<FunctionProtoType>(); |
2502 | 1.73k | } |
2503 | | |
2504 | 25.2k | SourceLocation BlockExpr::getCaretLocation() const { |
2505 | 25.2k | return TheBlock->getCaretLocation(); |
2506 | 25.2k | } |
2507 | 6.87k | const Stmt *BlockExpr::getBody() const { |
2508 | 6.87k | return TheBlock->getBody(); |
2509 | 6.87k | } |
2510 | 834 | Stmt *BlockExpr::getBody() { |
2511 | 834 | return TheBlock->getBody(); |
2512 | 834 | } |
2513 | | |
2514 | | |
2515 | | //===----------------------------------------------------------------------===// |
2516 | | // Generic Expression Routines |
2517 | | //===----------------------------------------------------------------------===// |
2518 | | |
2519 | 781k | bool Expr::isReadIfDiscardedInCPlusPlus11() const { |
2520 | | // In C++11, discarded-value expressions of a certain form are special, |
2521 | | // according to [expr]p10: |
2522 | | // The lvalue-to-rvalue conversion (4.1) is applied only if the |
2523 | | // expression is a glvalue of volatile-qualified type and it has |
2524 | | // one of the following forms: |
2525 | 781k | if (!isGLValue() || !getType().isVolatileQualified()780k ) |
2526 | 779k | return false; |
2527 | | |
2528 | 1.64k | const Expr *E = IgnoreParens(); |
2529 | | |
2530 | | // - id-expression (5.1.1), |
2531 | 1.64k | if (isa<DeclRefExpr>(E)) |
2532 | 63 | return true; |
2533 | | |
2534 | | // - subscripting (5.2.1), |
2535 | 1.58k | if (isa<ArraySubscriptExpr>(E)) |
2536 | 4 | return true; |
2537 | | |
2538 | | // - class member access (5.2.5), |
2539 | 1.58k | if (isa<MemberExpr>(E)) |
2540 | 10 | return true; |
2541 | | |
2542 | | // - indirection (5.3.1), |
2543 | 1.57k | if (auto *UO = dyn_cast<UnaryOperator>(E)) |
2544 | 131 | if (UO->getOpcode() == UO_Deref) |
2545 | 85 | return true; |
2546 | | |
2547 | 1.48k | if (auto *BO = dyn_cast<BinaryOperator>(E)) { |
2548 | | // - pointer-to-member operation (5.5), |
2549 | 1.36k | if (BO->isPtrMemOp()) |
2550 | 1 | return true; |
2551 | | |
2552 | | // - comma expression (5.18) where the right operand is one of the above. |
2553 | 1.36k | if (BO->getOpcode() == BO_Comma) |
2554 | 8 | return BO->getRHS()->isReadIfDiscardedInCPlusPlus11(); |
2555 | 1.36k | } |
2556 | | |
2557 | | // - conditional expression (5.16) where both the second and the third |
2558 | | // operands are one of the above, or |
2559 | 1.47k | if (auto *CO = dyn_cast<ConditionalOperator>(E)) |
2560 | 3 | return CO->getTrueExpr()->isReadIfDiscardedInCPlusPlus11() && |
2561 | 3 | CO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11()1 ; |
2562 | | // The related edge case of "*x ?: *x". |
2563 | 1.47k | if (auto *BCO = |
2564 | 1.47k | dyn_cast<BinaryConditionalOperator>(E)) { |
2565 | 1 | if (auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr())) |
2566 | 1 | return OVE->getSourceExpr()->isReadIfDiscardedInCPlusPlus11() && |
2567 | 1 | BCO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11(); |
2568 | 1 | } |
2569 | | |
2570 | | // Objective-C++ extensions to the rule. |
2571 | 1.47k | if (isa<ObjCIvarRefExpr>(E)) |
2572 | 0 | return true; |
2573 | 1.47k | if (const auto *POE = dyn_cast<PseudoObjectExpr>(E)) { |
2574 | 0 | if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(POE->getSyntacticForm())) |
2575 | 0 | return true; |
2576 | 0 | } |
2577 | | |
2578 | 1.47k | return false; |
2579 | 1.47k | } |
2580 | | |
2581 | | /// isUnusedResultAWarning - Return true if this immediate expression should |
2582 | | /// be warned about if the result is unused. If so, fill in Loc and Ranges |
2583 | | /// with location to warn on and the source range[s] to report with the |
2584 | | /// warning. |
2585 | | bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, |
2586 | | SourceRange &R1, SourceRange &R2, |
2587 | 3.49M | ASTContext &Ctx) const { |
2588 | | // Don't warn if the expr is type dependent. The type could end up |
2589 | | // instantiating to void. |
2590 | 3.49M | if (isTypeDependent()) |
2591 | 1.36M | return false; |
2592 | | |
2593 | 2.13M | switch (getStmtClass()) { |
2594 | 24.1k | default: |
2595 | 24.1k | if (getType()->isVoidType()) |
2596 | 18.1k | return false; |
2597 | 5.99k | WarnE = this; |
2598 | 5.99k | Loc = getExprLoc(); |
2599 | 5.99k | R1 = getSourceRange(); |
2600 | 5.99k | return true; |
2601 | 75.7k | case ParenExprClass: |
2602 | 75.7k | return cast<ParenExpr>(this)->getSubExpr()-> |
2603 | 75.7k | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2604 | 54 | case GenericSelectionExprClass: |
2605 | 54 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> |
2606 | 54 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2607 | 326 | case CoawaitExprClass: |
2608 | 366 | case CoyieldExprClass: |
2609 | 366 | return cast<CoroutineSuspendExpr>(this)->getResumeExpr()-> |
2610 | 366 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2611 | 4 | case ChooseExprClass: |
2612 | 4 | return cast<ChooseExpr>(this)->getChosenSubExpr()-> |
2613 | 4 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2614 | 298k | case UnaryOperatorClass: { |
2615 | 298k | const UnaryOperator *UO = cast<UnaryOperator>(this); |
2616 | | |
2617 | 298k | switch (UO->getOpcode()) { |
2618 | 35 | case UO_Plus: |
2619 | 90 | case UO_Minus: |
2620 | 236 | case UO_AddrOf: |
2621 | 267 | case UO_Not: |
2622 | 434 | case UO_LNot: |
2623 | 1.65k | case UO_Deref: |
2624 | 1.65k | break; |
2625 | 0 | case UO_Coawait: |
2626 | | // This is just the 'operator co_await' call inside the guts of a |
2627 | | // dependent co_await call. |
2628 | 61.7k | case UO_PostInc: |
2629 | 62.5k | case UO_PostDec: |
2630 | 284k | case UO_PreInc: |
2631 | 294k | case UO_PreDec: // ++/-- |
2632 | 294k | return false; // Not a warning. |
2633 | 24 | case UO_Real: |
2634 | 44 | case UO_Imag: |
2635 | | // accessing a piece of a volatile complex is a side-effect. |
2636 | 44 | if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) |
2637 | 44 | .isVolatileQualified()) |
2638 | 11 | return false; |
2639 | 33 | break; |
2640 | 2.78k | case UO_Extension: |
2641 | 2.78k | return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2642 | 298k | } |
2643 | 1.69k | WarnE = this; |
2644 | 1.69k | Loc = UO->getOperatorLoc(); |
2645 | 1.69k | R1 = UO->getSubExpr()->getSourceRange(); |
2646 | 1.69k | return true; |
2647 | 298k | } |
2648 | 930k | case BinaryOperatorClass: { |
2649 | 930k | const BinaryOperator *BO = cast<BinaryOperator>(this); |
2650 | 930k | switch (BO->getOpcode()) { |
2651 | 923k | default: |
2652 | 923k | break; |
2653 | | // Consider the RHS of comma for side effects. LHS was checked by |
2654 | | // Sema::CheckCommaOperands. |
2655 | 923k | case BO_Comma: |
2656 | | // ((foo = <blah>), 0) is an idiom for hiding the result (and |
2657 | | // lvalue-ness) of an assignment written in a macro. |
2658 | 6.53k | if (IntegerLiteral *IE = |
2659 | 6.53k | dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) |
2660 | 121 | if (IE->getValue() == 0) |
2661 | 62 | return false; |
2662 | 6.47k | return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2663 | | // Consider '||', '&&' to have side effects if the LHS or RHS does. |
2664 | 75 | case BO_LAnd: |
2665 | 210 | case BO_LOr: |
2666 | 210 | if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || |
2667 | 210 | !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)175 ) |
2668 | 83 | return false; |
2669 | 127 | break; |
2670 | 930k | } |
2671 | 923k | if (BO->isAssignmentOp()) |
2672 | 920k | return false; |
2673 | 2.48k | WarnE = this; |
2674 | 2.48k | Loc = BO->getOperatorLoc(); |
2675 | 2.48k | R1 = BO->getLHS()->getSourceRange(); |
2676 | 2.48k | R2 = BO->getRHS()->getSourceRange(); |
2677 | 2.48k | return true; |
2678 | 923k | } |
2679 | 86.7k | case CompoundAssignOperatorClass: |
2680 | 86.7k | case VAArgExprClass: |
2681 | 88.7k | case AtomicExprClass: |
2682 | 88.7k | return false; |
2683 | | |
2684 | 732 | case ConditionalOperatorClass: { |
2685 | | // If only one of the LHS or RHS is a warning, the operator might |
2686 | | // be being used for control flow. Only warn if both the LHS and |
2687 | | // RHS are warnings. |
2688 | 732 | const auto *Exp = cast<ConditionalOperator>(this); |
2689 | 732 | return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) && |
2690 | 732 | Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)212 ; |
2691 | 86.7k | } |
2692 | 48 | case BinaryConditionalOperatorClass: { |
2693 | 48 | const auto *Exp = cast<BinaryConditionalOperator>(this); |
2694 | 48 | return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2695 | 86.7k | } |
2696 | | |
2697 | 2.38k | case MemberExprClass: |
2698 | 2.38k | WarnE = this; |
2699 | 2.38k | Loc = cast<MemberExpr>(this)->getMemberLoc(); |
2700 | 2.38k | R1 = SourceRange(Loc, Loc); |
2701 | 2.38k | R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); |
2702 | 2.38k | return true; |
2703 | | |
2704 | 279 | case ArraySubscriptExprClass: |
2705 | 279 | WarnE = this; |
2706 | 279 | Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); |
2707 | 279 | R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); |
2708 | 279 | R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); |
2709 | 279 | return true; |
2710 | | |
2711 | 30.1k | case CXXOperatorCallExprClass: { |
2712 | | // Warn about operator ==,!=,<,>,<=, and >= even when user-defined operator |
2713 | | // overloads as there is no reasonable way to define these such that they |
2714 | | // have non-trivial, desirable side-effects. See the -Wunused-comparison |
2715 | | // warning: operators == and != are commonly typo'ed, and so warning on them |
2716 | | // provides additional value as well. If this list is updated, |
2717 | | // DiagnoseUnusedComparison should be as well. |
2718 | 30.1k | const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); |
2719 | 30.1k | switch (Op->getOperator()) { |
2720 | 30.0k | default: |
2721 | 30.0k | break; |
2722 | 30.0k | case OO_EqualEqual: |
2723 | 29 | case OO_ExclaimEqual: |
2724 | 52 | case OO_Less: |
2725 | 61 | case OO_Greater: |
2726 | 66 | case OO_GreaterEqual: |
2727 | 71 | case OO_LessEqual: |
2728 | 71 | if (Op->getCallReturnType(Ctx)->isReferenceType() || |
2729 | 71 | Op->getCallReturnType(Ctx)->isVoidType()70 ) |
2730 | 8 | break; |
2731 | 63 | WarnE = this; |
2732 | 63 | Loc = Op->getOperatorLoc(); |
2733 | 63 | R1 = Op->getSourceRange(); |
2734 | 63 | return true; |
2735 | 30.1k | } |
2736 | | |
2737 | | // Fallthrough for generic call handling. |
2738 | 30.1k | [[fallthrough]]; |
2739 | 30.0k | } |
2740 | 543k | case CallExprClass: |
2741 | 623k | case CXXMemberCallExprClass: |
2742 | 623k | case UserDefinedLiteralClass: { |
2743 | | // If this is a direct call, get the callee. |
2744 | 623k | const CallExpr *CE = cast<CallExpr>(this); |
2745 | 623k | if (const Decl *FD = CE->getCalleeDecl()) { |
2746 | | // If the callee has attribute pure, const, or warn_unused_result, warn |
2747 | | // about it. void foo() { strlen("bar"); } should warn. |
2748 | | // |
2749 | | // Note: If new cases are added here, DiagnoseUnusedExprResult should be |
2750 | | // updated to match for QoI. |
2751 | 622k | if (CE->hasUnusedResultAttr(Ctx) || |
2752 | 622k | FD->hasAttr<PureAttr>()622k || FD->hasAttr<ConstAttr>()622k ) { |
2753 | 2.45k | WarnE = this; |
2754 | 2.45k | Loc = CE->getCallee()->getBeginLoc(); |
2755 | 2.45k | R1 = CE->getCallee()->getSourceRange(); |
2756 | | |
2757 | 2.45k | if (unsigned NumArgs = CE->getNumArgs()) |
2758 | 2.33k | R2 = SourceRange(CE->getArg(0)->getBeginLoc(), |
2759 | 2.33k | CE->getArg(NumArgs - 1)->getEndLoc()); |
2760 | 2.45k | return true; |
2761 | 2.45k | } |
2762 | 622k | } |
2763 | 621k | return false; |
2764 | 623k | } |
2765 | | |
2766 | | // If we don't know precisely what we're looking at, let's not warn. |
2767 | 0 | case UnresolvedLookupExprClass: |
2768 | 78 | case CXXUnresolvedConstructExprClass: |
2769 | 1.65k | case RecoveryExprClass: |
2770 | 1.65k | return false; |
2771 | | |
2772 | 656 | case CXXTemporaryObjectExprClass: |
2773 | 764 | case CXXConstructExprClass: { |
2774 | 764 | if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) { |
2775 | 764 | const auto *WarnURAttr = Type->getAttr<WarnUnusedResultAttr>(); |
2776 | 764 | if (Type->hasAttr<WarnUnusedAttr>() || |
2777 | 764 | (752 WarnURAttr752 && WarnURAttr->IsCXX11NoDiscard()4 )) { |
2778 | 16 | WarnE = this; |
2779 | 16 | Loc = getBeginLoc(); |
2780 | 16 | R1 = getSourceRange(); |
2781 | 16 | return true; |
2782 | 16 | } |
2783 | 764 | } |
2784 | | |
2785 | 748 | const auto *CE = cast<CXXConstructExpr>(this); |
2786 | 748 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) { |
2787 | 748 | const auto *WarnURAttr = Ctor->getAttr<WarnUnusedResultAttr>(); |
2788 | 748 | if (WarnURAttr && WarnURAttr->IsCXX11NoDiscard()12 ) { |
2789 | 9 | WarnE = this; |
2790 | 9 | Loc = getBeginLoc(); |
2791 | 9 | R1 = getSourceRange(); |
2792 | | |
2793 | 9 | if (unsigned NumArgs = CE->getNumArgs()) |
2794 | 6 | R2 = SourceRange(CE->getArg(0)->getBeginLoc(), |
2795 | 6 | CE->getArg(NumArgs - 1)->getEndLoc()); |
2796 | 9 | return true; |
2797 | 9 | } |
2798 | 748 | } |
2799 | | |
2800 | 739 | return false; |
2801 | 748 | } |
2802 | | |
2803 | 8.61k | case ObjCMessageExprClass: { |
2804 | 8.61k | const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); |
2805 | 8.61k | if (Ctx.getLangOpts().ObjCAutoRefCount && |
2806 | 8.61k | ME->isInstanceMessage()727 && |
2807 | 8.61k | !ME->getType()->isVoidType()692 && |
2808 | 8.61k | ME->getMethodFamily() == OMF_init180 ) { |
2809 | 23 | WarnE = this; |
2810 | 23 | Loc = getExprLoc(); |
2811 | 23 | R1 = ME->getSourceRange(); |
2812 | 23 | return true; |
2813 | 23 | } |
2814 | | |
2815 | 8.58k | if (const ObjCMethodDecl *MD = ME->getMethodDecl()) |
2816 | 8.09k | if (MD->hasAttr<WarnUnusedResultAttr>()) { |
2817 | 2 | WarnE = this; |
2818 | 2 | Loc = getExprLoc(); |
2819 | 2 | return true; |
2820 | 2 | } |
2821 | | |
2822 | 8.58k | return false; |
2823 | 8.58k | } |
2824 | | |
2825 | 0 | case ObjCPropertyRefExprClass: |
2826 | 0 | case ObjCSubscriptRefExprClass: |
2827 | 0 | WarnE = this; |
2828 | 0 | Loc = getExprLoc(); |
2829 | 0 | R1 = getSourceRange(); |
2830 | 0 | return true; |
2831 | | |
2832 | 1.22k | case PseudoObjectExprClass: { |
2833 | 1.22k | const auto *POE = cast<PseudoObjectExpr>(this); |
2834 | | |
2835 | | // For some syntactic forms, we should always warn. |
2836 | 1.22k | if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>( |
2837 | 1.22k | POE->getSyntacticForm())) { |
2838 | 117 | WarnE = this; |
2839 | 117 | Loc = getExprLoc(); |
2840 | 117 | R1 = getSourceRange(); |
2841 | 117 | return true; |
2842 | 117 | } |
2843 | | |
2844 | | // For others, we should never warn. |
2845 | 1.10k | if (auto *BO = dyn_cast<BinaryOperator>(POE->getSyntacticForm())) |
2846 | 911 | if (BO->isAssignmentOp()) |
2847 | 911 | return false; |
2848 | 196 | if (auto *UO = dyn_cast<UnaryOperator>(POE->getSyntacticForm())) |
2849 | 30 | if (UO->isIncrementDecrementOp()) |
2850 | 30 | return false; |
2851 | | |
2852 | | // Otherwise, warn if the result expression would warn. |
2853 | 166 | const Expr *Result = POE->getResultExpr(); |
2854 | 166 | return Result && Result->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)154 ; |
2855 | 196 | } |
2856 | | |
2857 | 2.88k | case StmtExprClass: { |
2858 | | // Statement exprs don't logically have side effects themselves, but are |
2859 | | // sometimes used in macros in ways that give them a type that is unused. |
2860 | | // For example ({ blah; foo(); }) will end up with a type if foo has a type. |
2861 | | // however, if the result of the stmt expr is dead, we don't want to emit a |
2862 | | // warning. |
2863 | 2.88k | const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); |
2864 | 2.88k | if (!CS->body_empty()) { |
2865 | 2.86k | if (const Expr *E = dyn_cast<Expr>(CS->body_back())) |
2866 | 2.06k | return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2867 | 794 | if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back())) |
2868 | 2 | if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt())) |
2869 | 2 | return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2870 | 794 | } |
2871 | | |
2872 | 810 | if (getType()->isVoidType()) |
2873 | 806 | return false; |
2874 | 4 | WarnE = this; |
2875 | 4 | Loc = cast<StmtExpr>(this)->getLParenLoc(); |
2876 | 4 | R1 = getSourceRange(); |
2877 | 4 | return true; |
2878 | 810 | } |
2879 | 406 | case CXXFunctionalCastExprClass: |
2880 | 61.9k | case CStyleCastExprClass: { |
2881 | | // Ignore an explicit cast to void, except in C++98 if the operand is a |
2882 | | // volatile glvalue for which we would trigger an implicit read in any |
2883 | | // other language mode. (Such an implicit read always happens as part of |
2884 | | // the lvalue conversion in C, and happens in C++ for expressions of all |
2885 | | // forms where it seems likely the user intended to trigger a volatile |
2886 | | // load.) |
2887 | 61.9k | const CastExpr *CE = cast<CastExpr>(this); |
2888 | 61.9k | const Expr *SubE = CE->getSubExpr()->IgnoreParens(); |
2889 | 61.9k | if (CE->getCastKind() == CK_ToVoid) { |
2890 | 61.3k | if (Ctx.getLangOpts().CPlusPlus && !Ctx.getLangOpts().CPlusPlus1152.4k && |
2891 | 61.3k | SubE->isReadIfDiscardedInCPlusPlus11()822 ) { |
2892 | | // Suppress the "unused value" warning for idiomatic usage of |
2893 | | // '(void)var;' used to suppress "unused variable" warnings. |
2894 | 13 | if (auto *DRE = dyn_cast<DeclRefExpr>(SubE)) |
2895 | 12 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
2896 | 12 | if (!VD->isExternallyVisible()) |
2897 | 7 | return false; |
2898 | | |
2899 | | // The lvalue-to-rvalue conversion would have no effect for an array. |
2900 | | // It's implausible that the programmer expected this to result in a |
2901 | | // volatile array load, so don't warn. |
2902 | 6 | if (SubE->getType()->isArrayType()) |
2903 | 1 | return false; |
2904 | | |
2905 | 5 | return SubE->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2906 | 6 | } |
2907 | 61.3k | return false; |
2908 | 61.3k | } |
2909 | | |
2910 | | // If this is a cast to a constructor conversion, check the operand. |
2911 | | // Otherwise, the result of the cast is unused. |
2912 | 596 | if (CE->getCastKind() == CK_ConstructorConversion) |
2913 | 95 | return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2914 | 501 | if (CE->getCastKind() == CK_Dependent) |
2915 | 7 | return false; |
2916 | | |
2917 | 494 | WarnE = this; |
2918 | 494 | if (const CXXFunctionalCastExpr *CXXCE = |
2919 | 494 | dyn_cast<CXXFunctionalCastExpr>(this)) { |
2920 | 93 | Loc = CXXCE->getBeginLoc(); |
2921 | 93 | R1 = CXXCE->getSubExpr()->getSourceRange(); |
2922 | 401 | } else { |
2923 | 401 | const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); |
2924 | 401 | Loc = CStyleCE->getLParenLoc(); |
2925 | 401 | R1 = CStyleCE->getSubExpr()->getSourceRange(); |
2926 | 401 | } |
2927 | 494 | return true; |
2928 | 501 | } |
2929 | 1.70k | case ImplicitCastExprClass: { |
2930 | 1.70k | const CastExpr *ICE = cast<ImplicitCastExpr>(this); |
2931 | | |
2932 | | // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. |
2933 | 1.70k | if (ICE->getCastKind() == CK_LValueToRValue && |
2934 | 1.70k | ICE->getSubExpr()->getType().isVolatileQualified()1.22k ) |
2935 | 62 | return false; |
2936 | | |
2937 | 1.64k | return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2938 | 1.70k | } |
2939 | 0 | case CXXDefaultArgExprClass: |
2940 | 0 | return (cast<CXXDefaultArgExpr>(this) |
2941 | 0 | ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); |
2942 | 0 | case CXXDefaultInitExprClass: |
2943 | 0 | return (cast<CXXDefaultInitExpr>(this) |
2944 | 0 | ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); |
2945 | | |
2946 | 1.36k | case CXXNewExprClass: |
2947 | | // FIXME: In theory, there might be new expressions that don't have side |
2948 | | // effects (e.g. a placement new with an uninitialized POD). |
2949 | 8.13k | case CXXDeleteExprClass: |
2950 | 8.13k | return false; |
2951 | 0 | case MaterializeTemporaryExprClass: |
2952 | 0 | return cast<MaterializeTemporaryExpr>(this) |
2953 | 0 | ->getSubExpr() |
2954 | 0 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2955 | 350 | case CXXBindTemporaryExprClass: |
2956 | 350 | return cast<CXXBindTemporaryExpr>(this)->getSubExpr() |
2957 | 350 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2958 | 769 | case ExprWithCleanupsClass: |
2959 | 769 | return cast<ExprWithCleanups>(this)->getSubExpr() |
2960 | 769 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2961 | 2.13M | } |
2962 | 2.13M | } |
2963 | | |
2964 | | /// isOBJCGCCandidate - Check if an expression is objc gc'able. |
2965 | | /// returns true, if it is; false otherwise. |
2966 | 495 | bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { |
2967 | 495 | const Expr *E = IgnoreParens(); |
2968 | 495 | switch (E->getStmtClass()) { |
2969 | 4 | default: |
2970 | 4 | return false; |
2971 | 64 | case ObjCIvarRefExprClass: |
2972 | 64 | return true; |
2973 | 15 | case Expr::UnaryOperatorClass: |
2974 | 15 | return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); |
2975 | 149 | case ImplicitCastExprClass: |
2976 | 149 | return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); |
2977 | 0 | case MaterializeTemporaryExprClass: |
2978 | 0 | return cast<MaterializeTemporaryExpr>(E)->getSubExpr()->isOBJCGCCandidate( |
2979 | 0 | Ctx); |
2980 | 3 | case CStyleCastExprClass: |
2981 | 3 | return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); |
2982 | 69 | case DeclRefExprClass: { |
2983 | 69 | const Decl *D = cast<DeclRefExpr>(E)->getDecl(); |
2984 | | |
2985 | 69 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
2986 | 69 | if (VD->hasGlobalStorage()) |
2987 | 56 | return true; |
2988 | 13 | QualType T = VD->getType(); |
2989 | | // dereferencing to a pointer is always a gc'able candidate, |
2990 | | // unless it is __weak. |
2991 | 13 | return T->isPointerType() && |
2992 | 13 | (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak)11 ; |
2993 | 69 | } |
2994 | 0 | return false; |
2995 | 69 | } |
2996 | 56 | case MemberExprClass: { |
2997 | 56 | const MemberExpr *M = cast<MemberExpr>(E); |
2998 | 56 | return M->getBase()->isOBJCGCCandidate(Ctx); |
2999 | 69 | } |
3000 | 135 | case ArraySubscriptExprClass: |
3001 | 135 | return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); |
3002 | 495 | } |
3003 | 495 | } |
3004 | | |
3005 | 0 | bool Expr::isBoundMemberFunction(ASTContext &Ctx) const { |
3006 | 0 | if (isTypeDependent()) |
3007 | 0 | return false; |
3008 | 0 | return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; |
3009 | 0 | } |
3010 | | |
3011 | 401k | QualType Expr::findBoundMemberType(const Expr *expr) { |
3012 | 401k | assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); |
3013 | | |
3014 | | // Bound member expressions are always one of these possibilities: |
3015 | | // x->m x.m x->*y x.*y |
3016 | | // (possibly parenthesized) |
3017 | | |
3018 | 401k | expr = expr->IgnoreParens(); |
3019 | 401k | if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) { |
3020 | 401k | assert(isa<CXXMethodDecl>(mem->getMemberDecl())); |
3021 | 401k | return mem->getMemberDecl()->getType(); |
3022 | 401k | } |
3023 | | |
3024 | 704 | if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) { |
3025 | 701 | QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() |
3026 | 701 | ->getPointeeType(); |
3027 | 701 | assert(type->isFunctionType()); |
3028 | 701 | return type; |
3029 | 701 | } |
3030 | | |
3031 | 3 | assert(isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr)); |
3032 | 3 | return QualType(); |
3033 | 3 | } |
3034 | | |
3035 | 11.1M | Expr *Expr::IgnoreImpCasts() { |
3036 | 11.1M | return IgnoreExprNodes(this, IgnoreImplicitCastsSingleStep); |
3037 | 11.1M | } |
3038 | | |
3039 | 1.28k | Expr *Expr::IgnoreCasts() { |
3040 | 1.28k | return IgnoreExprNodes(this, IgnoreCastsSingleStep); |
3041 | 1.28k | } |
3042 | | |
3043 | 6.55M | Expr *Expr::IgnoreImplicit() { |
3044 | 6.55M | return IgnoreExprNodes(this, IgnoreImplicitSingleStep); |
3045 | 6.55M | } |
3046 | | |
3047 | 3.69k | Expr *Expr::IgnoreImplicitAsWritten() { |
3048 | 3.69k | return IgnoreExprNodes(this, IgnoreImplicitAsWrittenSingleStep); |
3049 | 3.69k | } |
3050 | | |
3051 | 122M | Expr *Expr::IgnoreParens() { |
3052 | 122M | return IgnoreExprNodes(this, IgnoreParensSingleStep); |
3053 | 122M | } |
3054 | | |
3055 | 144M | Expr *Expr::IgnoreParenImpCasts() { |
3056 | 144M | return IgnoreExprNodes(this, IgnoreParensSingleStep, |
3057 | 144M | IgnoreImplicitCastsExtraSingleStep); |
3058 | 144M | } |
3059 | | |
3060 | 96.4M | Expr *Expr::IgnoreParenCasts() { |
3061 | 96.4M | return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreCastsSingleStep); |
3062 | 96.4M | } |
3063 | | |
3064 | 297k | Expr *Expr::IgnoreConversionOperatorSingleStep() { |
3065 | 297k | if (auto *MCE = dyn_cast<CXXMemberCallExpr>(this)) { |
3066 | 1.19k | if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl())1.19k ) |
3067 | 75 | return MCE->getImplicitObjectArgument(); |
3068 | 1.19k | } |
3069 | 297k | return this; |
3070 | 297k | } |
3071 | | |
3072 | 70.0k | Expr *Expr::IgnoreParenLValueCasts() { |
3073 | 70.0k | return IgnoreExprNodes(this, IgnoreParensSingleStep, |
3074 | 70.0k | IgnoreLValueCastsSingleStep); |
3075 | 70.0k | } |
3076 | | |
3077 | 104k | Expr *Expr::IgnoreParenBaseCasts() { |
3078 | 104k | return IgnoreExprNodes(this, IgnoreParensSingleStep, |
3079 | 104k | IgnoreBaseCastsSingleStep); |
3080 | 104k | } |
3081 | | |
3082 | 190k | Expr *Expr::IgnoreParenNoopCasts(const ASTContext &Ctx) { |
3083 | 194k | auto IgnoreNoopCastsSingleStep = [&Ctx](Expr *E) { |
3084 | 194k | if (auto *CE = dyn_cast<CastExpr>(E)) { |
3085 | | // We ignore integer <-> casts that are of the same width, ptr<->ptr and |
3086 | | // ptr<->int casts of the same width. We also ignore all identity casts. |
3087 | 3.90k | Expr *SubExpr = CE->getSubExpr(); |
3088 | 3.90k | bool IsIdentityCast = |
3089 | 3.90k | Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType()); |
3090 | 3.90k | bool IsSameWidthCast = (E->getType()->isPointerType() || |
3091 | 3.90k | E->getType()->isIntegralType(Ctx)3.05k ) && |
3092 | 3.90k | (2.22k SubExpr->getType()->isPointerType()2.22k || |
3093 | 2.22k | SubExpr->getType()->isIntegralType(Ctx)1.89k ) && |
3094 | 3.90k | (Ctx.getTypeSize(E->getType()) == |
3095 | 1.70k | Ctx.getTypeSize(SubExpr->getType())); |
3096 | | |
3097 | 3.90k | if (IsIdentityCast || IsSameWidthCast1.20k ) |
3098 | 2.99k | return SubExpr; |
3099 | 191k | } else if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) |
3100 | 0 | return NTTP->getReplacement(); |
3101 | | |
3102 | 191k | return E; |
3103 | 194k | }; |
3104 | 190k | return IgnoreExprNodes(this, IgnoreParensSingleStep, |
3105 | 190k | IgnoreNoopCastsSingleStep); |
3106 | 190k | } |
3107 | | |
3108 | 35.8k | Expr *Expr::IgnoreUnlessSpelledInSource() { |
3109 | 38.8k | auto IgnoreImplicitConstructorSingleStep = [](Expr *E) { |
3110 | 38.8k | if (auto *Cast = dyn_cast<CXXFunctionalCastExpr>(E)) { |
3111 | 28 | auto *SE = Cast->getSubExpr(); |
3112 | 28 | if (SE->getSourceRange() == E->getSourceRange()) |
3113 | 10 | return SE; |
3114 | 28 | } |
3115 | | |
3116 | 38.8k | if (auto *C = dyn_cast<CXXConstructExpr>(E)) { |
3117 | 5.41k | auto NumArgs = C->getNumArgs(); |
3118 | 5.41k | if (NumArgs == 1 || |
3119 | 5.41k | (4.81k NumArgs > 14.81k && isa<CXXDefaultArgExpr>(C->getArg(1))23 )) { |
3120 | 610 | Expr *A = C->getArg(0); |
3121 | 610 | if (A->getSourceRange() == E->getSourceRange() || C->isElidable()517 ) |
3122 | 125 | return A; |
3123 | 610 | } |
3124 | 5.41k | } |
3125 | 38.6k | return E; |
3126 | 38.8k | }; |
3127 | 38.8k | auto IgnoreImplicitMemberCallSingleStep = [](Expr *E) { |
3128 | 38.8k | if (auto *C = dyn_cast<CXXMemberCallExpr>(E)) { |
3129 | 29 | Expr *ExprNode = C->getImplicitObjectArgument(); |
3130 | 29 | if (ExprNode->getSourceRange() == E->getSourceRange()) { |
3131 | 18 | return ExprNode; |
3132 | 18 | } |
3133 | 11 | if (auto *PE = dyn_cast<ParenExpr>(ExprNode)) { |
3134 | 1 | if (PE->getSourceRange() == C->getSourceRange()) { |
3135 | 0 | return cast<Expr>(PE); |
3136 | 0 | } |
3137 | 1 | } |
3138 | 11 | ExprNode = ExprNode->IgnoreParenImpCasts(); |
3139 | 11 | if (ExprNode->getSourceRange() == E->getSourceRange()) |
3140 | 0 | return ExprNode; |
3141 | 11 | } |
3142 | 38.8k | return E; |
3143 | 38.8k | }; |
3144 | 35.8k | return IgnoreExprNodes( |
3145 | 35.8k | this, IgnoreImplicitSingleStep, IgnoreImplicitCastsExtraSingleStep, |
3146 | 35.8k | IgnoreParensOnlySingleStep, IgnoreImplicitConstructorSingleStep, |
3147 | 35.8k | IgnoreImplicitMemberCallSingleStep); |
3148 | 35.8k | } |
3149 | | |
3150 | 1.10M | bool Expr::isDefaultArgument() const { |
3151 | 1.10M | const Expr *E = this; |
3152 | 1.10M | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) |
3153 | 203k | E = M->getSubExpr(); |
3154 | | |
3155 | 1.27M | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) |
3156 | 167k | E = ICE->getSubExprAsWritten(); |
3157 | | |
3158 | 1.10M | return isa<CXXDefaultArgExpr>(E); |
3159 | 1.10M | } |
3160 | | |
3161 | | /// Skip over any no-op casts and any temporary-binding |
3162 | | /// expressions. |
3163 | 205k | static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { |
3164 | 205k | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) |
3165 | 124k | E = M->getSubExpr(); |
3166 | | |
3167 | 269k | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
3168 | 69.8k | if (ICE->getCastKind() == CK_NoOp) |
3169 | 64.1k | E = ICE->getSubExpr(); |
3170 | 5.74k | else |
3171 | 5.74k | break; |
3172 | 69.8k | } |
3173 | | |
3174 | 222k | while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) |
3175 | 16.7k | E = BE->getSubExpr(); |
3176 | | |
3177 | 205k | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
3178 | 9.70k | if (ICE->getCastKind() == CK_NoOp) |
3179 | 0 | E = ICE->getSubExpr(); |
3180 | 9.70k | else |
3181 | 9.70k | break; |
3182 | 9.70k | } |
3183 | | |
3184 | 205k | return E->IgnoreParens(); |
3185 | 205k | } |
3186 | | |
3187 | | /// isTemporaryObject - Determines if this expression produces a |
3188 | | /// temporary of the given class type. |
3189 | 205k | bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { |
3190 | 205k | if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) |
3191 | 29 | return false; |
3192 | | |
3193 | 205k | const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); |
3194 | | |
3195 | | // Temporaries are by definition pr-values of class type. |
3196 | 205k | if (!E->Classify(C).isPRValue()) { |
3197 | | // In this context, property reference is a message call and is pr-value. |
3198 | 74.9k | if (!isa<ObjCPropertyRefExpr>(E)) |
3199 | 74.9k | return false; |
3200 | 74.9k | } |
3201 | | |
3202 | | // Black-list a few cases which yield pr-values of class type that don't |
3203 | | // refer to temporaries of that type: |
3204 | | |
3205 | | // - implicit derived-to-base conversions |
3206 | 130k | if (isa<ImplicitCastExpr>(E)) { |
3207 | 8.60k | switch (cast<ImplicitCastExpr>(E)->getCastKind()) { |
3208 | 0 | case CK_DerivedToBase: |
3209 | 0 | case CK_UncheckedDerivedToBase: |
3210 | 0 | return false; |
3211 | 8.60k | default: |
3212 | 8.60k | break; |
3213 | 8.60k | } |
3214 | 8.60k | } |
3215 | | |
3216 | | // - member expressions (all) |
3217 | 130k | if (isa<MemberExpr>(E)) |
3218 | 0 | return false; |
3219 | | |
3220 | 130k | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) |
3221 | 51 | if (BO->isPtrMemOp()) |
3222 | 0 | return false; |
3223 | | |
3224 | | // - opaque values (all) |
3225 | 130k | if (isa<OpaqueValueExpr>(E)) |
3226 | 12 | return false; |
3227 | | |
3228 | 130k | return true; |
3229 | 130k | } |
3230 | | |
3231 | 13.3M | bool Expr::isImplicitCXXThis() const { |
3232 | 13.3M | const Expr *E = this; |
3233 | | |
3234 | | // Strip away parentheses and casts we don't care about. |
3235 | 14.8M | while (true) { |
3236 | 14.8M | if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) { |
3237 | 70.2k | E = Paren->getSubExpr(); |
3238 | 70.2k | continue; |
3239 | 70.2k | } |
3240 | | |
3241 | 14.7M | if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
3242 | 1.34M | if (ICE->getCastKind() == CK_NoOp || |
3243 | 1.34M | ICE->getCastKind() == CK_LValueToRValue881k || |
3244 | 1.34M | ICE->getCastKind() == CK_DerivedToBase73.2k || |
3245 | 1.34M | ICE->getCastKind() == CK_UncheckedDerivedToBase73.2k ) { |
3246 | 1.34M | E = ICE->getSubExpr(); |
3247 | 1.34M | continue; |
3248 | 1.34M | } |
3249 | 1.34M | } |
3250 | | |
3251 | 13.4M | if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) { |
3252 | 13.8k | if (UnOp->getOpcode() == UO_Extension) { |
3253 | 0 | E = UnOp->getSubExpr(); |
3254 | 0 | continue; |
3255 | 0 | } |
3256 | 13.8k | } |
3257 | | |
3258 | 13.4M | if (const MaterializeTemporaryExpr *M |
3259 | 13.4M | = dyn_cast<MaterializeTemporaryExpr>(E)) { |
3260 | 112k | E = M->getSubExpr(); |
3261 | 112k | continue; |
3262 | 112k | } |
3263 | | |
3264 | 13.3M | break; |
3265 | 13.4M | } |
3266 | | |
3267 | 13.3M | if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) |
3268 | 4.03M | return This->isImplicit(); |
3269 | | |
3270 | 9.30M | return false; |
3271 | 13.3M | } |
3272 | | |
3273 | | /// hasAnyTypeDependentArguments - Determines if any of the expressions |
3274 | | /// in Exprs is type-dependent. |
3275 | 23.5M | bool Expr::hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs) { |
3276 | 50.1M | for (unsigned I = 0; I < Exprs.size(); ++I26.6M ) |
3277 | 27.5M | if (Exprs[I]->isTypeDependent()) |
3278 | 930k | return true; |
3279 | | |
3280 | 22.6M | return false; |
3281 | 23.5M | } |
3282 | | |
3283 | | bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef, |
3284 | 69.1k | const Expr **Culprit) const { |
3285 | 69.1k | assert(!isValueDependent() && |
3286 | 69.1k | "Expression evaluator can't be called on a dependent expression."); |
3287 | | |
3288 | | // This function is attempting whether an expression is an initializer |
3289 | | // which can be evaluated at compile-time. It very closely parallels |
3290 | | // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it |
3291 | | // will lead to unexpected results. Like ConstExprEmitter, it falls back |
3292 | | // to isEvaluatable most of the time. |
3293 | | // |
3294 | | // If we ever capture reference-binding directly in the AST, we can |
3295 | | // kill the second parameter. |
3296 | | |
3297 | 69.1k | if (IsForRef) { |
3298 | 151 | EvalResult Result; |
3299 | 151 | if (EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects107 ) |
3300 | 107 | return true; |
3301 | 44 | if (Culprit) |
3302 | 44 | *Culprit = this; |
3303 | 44 | return false; |
3304 | 151 | } |
3305 | | |
3306 | 68.9k | switch (getStmtClass()) { |
3307 | 15.8k | default: break; |
3308 | 15.8k | case Stmt::ExprWithCleanupsClass: |
3309 | 410 | return cast<ExprWithCleanups>(this)->getSubExpr()->isConstantInitializer( |
3310 | 410 | Ctx, IsForRef, Culprit); |
3311 | 279 | case StringLiteralClass: |
3312 | 341 | case ObjCEncodeExprClass: |
3313 | 341 | return true; |
3314 | 21 | case CXXTemporaryObjectExprClass: |
3315 | 6.62k | case CXXConstructExprClass: { |
3316 | 6.62k | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); |
3317 | | |
3318 | 6.62k | if (CE->getConstructor()->isTrivial() && |
3319 | 6.62k | CE->getConstructor()->getParent()->hasTrivialDestructor()4.61k ) { |
3320 | | // Trivial default constructor |
3321 | 4.60k | if (!CE->getNumArgs()) return true4.11k ; |
3322 | | |
3323 | | // Trivial copy constructor |
3324 | 485 | assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument"); |
3325 | 485 | return CE->getArg(0)->isConstantInitializer(Ctx, false, Culprit); |
3326 | 485 | } |
3327 | | |
3328 | 2.02k | break; |
3329 | 6.62k | } |
3330 | 4.87k | case ConstantExprClass: { |
3331 | | // FIXME: We should be able to return "true" here, but it can lead to extra |
3332 | | // error messages. E.g. in Sema/array-init.c. |
3333 | 4.87k | const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr(); |
3334 | 4.87k | return Exp->isConstantInitializer(Ctx, false, Culprit); |
3335 | 6.62k | } |
3336 | 91 | case CompoundLiteralExprClass: { |
3337 | | // This handles gcc's extension that allows global initializers like |
3338 | | // "struct x {int x;} x = (struct x) {};". |
3339 | | // FIXME: This accepts other cases it shouldn't! |
3340 | 91 | const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); |
3341 | 91 | return Exp->isConstantInitializer(Ctx, false, Culprit); |
3342 | 6.62k | } |
3343 | 30 | case DesignatedInitUpdateExprClass: { |
3344 | 30 | const DesignatedInitUpdateExpr *DIUE = cast<DesignatedInitUpdateExpr>(this); |
3345 | 30 | return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) && |
3346 | 30 | DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit)24 ; |
3347 | 6.62k | } |
3348 | 8.38k | case InitListExprClass: { |
3349 | 8.38k | const InitListExpr *ILE = cast<InitListExpr>(this); |
3350 | 8.38k | assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form"); |
3351 | 8.38k | if (ILE->getType()->isArrayType()) { |
3352 | 3.46k | unsigned numInits = ILE->getNumInits(); |
3353 | 21.1k | for (unsigned i = 0; i < numInits; i++17.7k ) { |
3354 | 17.8k | if (!ILE->getInit(i)->isConstantInitializer(Ctx, false, Culprit)) |
3355 | 156 | return false; |
3356 | 17.8k | } |
3357 | 3.31k | return true; |
3358 | 3.46k | } |
3359 | | |
3360 | 4.91k | if (ILE->getType()->isRecordType()) { |
3361 | 4.56k | unsigned ElementNo = 0; |
3362 | 4.56k | RecordDecl *RD = ILE->getType()->castAs<RecordType>()->getDecl(); |
3363 | 11.8k | for (const auto *Field : RD->fields()) { |
3364 | | // If this is a union, skip all the fields that aren't being initialized. |
3365 | 11.8k | if (RD->isUnion() && ILE->getInitializedFieldInUnion() != Field905 ) |
3366 | 422 | continue; |
3367 | | |
3368 | | // Don't emit anonymous bitfields, they just affect layout. |
3369 | 11.4k | if (Field->isUnnamedBitfield()) |
3370 | 59 | continue; |
3371 | | |
3372 | 11.3k | if (ElementNo < ILE->getNumInits()) { |
3373 | 11.2k | const Expr *Elt = ILE->getInit(ElementNo++); |
3374 | 11.2k | if (Field->isBitField()) { |
3375 | | // Bitfields have to evaluate to an integer. |
3376 | 264 | EvalResult Result; |
3377 | 264 | if (!Elt->EvaluateAsInt(Result, Ctx)) { |
3378 | 3 | if (Culprit) |
3379 | 3 | *Culprit = Elt; |
3380 | 3 | return false; |
3381 | 3 | } |
3382 | 11.0k | } else { |
3383 | 11.0k | bool RefType = Field->getType()->isReferenceType(); |
3384 | 11.0k | if (!Elt->isConstantInitializer(Ctx, RefType, Culprit)) |
3385 | 155 | return false; |
3386 | 11.0k | } |
3387 | 11.2k | } |
3388 | 11.3k | } |
3389 | 4.41k | return true; |
3390 | 4.56k | } |
3391 | | |
3392 | 345 | break; |
3393 | 4.91k | } |
3394 | 6.42k | case ImplicitValueInitExprClass: |
3395 | 6.48k | case NoInitExprClass: |
3396 | 6.48k | return true; |
3397 | 666 | case ParenExprClass: |
3398 | 666 | return cast<ParenExpr>(this)->getSubExpr() |
3399 | 666 | ->isConstantInitializer(Ctx, IsForRef, Culprit); |
3400 | 5 | case GenericSelectionExprClass: |
3401 | 5 | return cast<GenericSelectionExpr>(this)->getResultExpr() |
3402 | 5 | ->isConstantInitializer(Ctx, IsForRef, Culprit); |
3403 | 4 | case ChooseExprClass: |
3404 | 4 | if (cast<ChooseExpr>(this)->isConditionDependent()) { |
3405 | 0 | if (Culprit) |
3406 | 0 | *Culprit = this; |
3407 | 0 | return false; |
3408 | 0 | } |
3409 | 4 | return cast<ChooseExpr>(this)->getChosenSubExpr() |
3410 | 4 | ->isConstantInitializer(Ctx, IsForRef, Culprit); |
3411 | 1.28k | case UnaryOperatorClass: { |
3412 | 1.28k | const UnaryOperator* Exp = cast<UnaryOperator>(this); |
3413 | 1.28k | if (Exp->getOpcode() == UO_Extension) |
3414 | 9 | return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); |
3415 | 1.27k | break; |
3416 | 1.28k | } |
3417 | 1.27k | case CXXFunctionalCastExprClass: |
3418 | 88 | case CXXStaticCastExprClass: |
3419 | 21.8k | case ImplicitCastExprClass: |
3420 | 23.5k | case CStyleCastExprClass: |
3421 | 23.5k | case ObjCBridgedCastExprClass: |
3422 | 23.5k | case CXXDynamicCastExprClass: |
3423 | 23.6k | case CXXReinterpretCastExprClass: |
3424 | 23.6k | case CXXAddrspaceCastExprClass: |
3425 | 23.6k | case CXXConstCastExprClass: { |
3426 | 23.6k | const CastExpr *CE = cast<CastExpr>(this); |
3427 | | |
3428 | | // Handle misc casts we want to ignore. |
3429 | 23.6k | if (CE->getCastKind() == CK_NoOp || |
3430 | 23.6k | CE->getCastKind() == CK_LValueToRValue22.4k || |
3431 | 23.6k | CE->getCastKind() == CK_ToUnion20.9k || |
3432 | 23.6k | CE->getCastKind() == CK_ConstructorConversion20.8k || |
3433 | 23.6k | CE->getCastKind() == CK_NonAtomicToAtomic20.8k || |
3434 | 23.6k | CE->getCastKind() == CK_AtomicToNonAtomic20.8k || |
3435 | 23.6k | CE->getCastKind() == CK_NullToPointer20.7k || |
3436 | 23.6k | CE->getCastKind() == CK_IntToOCLSampler19.1k ) |
3437 | 4.55k | return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); |
3438 | | |
3439 | 19.0k | break; |
3440 | 23.6k | } |
3441 | 19.0k | case MaterializeTemporaryExprClass: |
3442 | 324 | return cast<MaterializeTemporaryExpr>(this) |
3443 | 324 | ->getSubExpr() |
3444 | 324 | ->isConstantInitializer(Ctx, false, Culprit); |
3445 | | |
3446 | 18 | case SubstNonTypeTemplateParmExprClass: |
3447 | 18 | return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement() |
3448 | 18 | ->isConstantInitializer(Ctx, false, Culprit); |
3449 | 0 | case CXXDefaultArgExprClass: |
3450 | 0 | return cast<CXXDefaultArgExpr>(this)->getExpr() |
3451 | 0 | ->isConstantInitializer(Ctx, false, Culprit); |
3452 | 0 | case CXXDefaultInitExprClass: |
3453 | 0 | return cast<CXXDefaultInitExpr>(this)->getExpr() |
3454 | 0 | ->isConstantInitializer(Ctx, false, Culprit); |
3455 | 68.9k | } |
3456 | | // Allow certain forms of UB in constant initializers: signed integer |
3457 | | // overflow and floating-point division by zero. We'll give a warning on |
3458 | | // these, but they're common enough that we have to accept them. |
3459 | 38.5k | if (isEvaluatable(Ctx, SE_AllowUndefinedBehavior)) |
3460 | 33.6k | return true; |
3461 | 4.91k | if (Culprit) |
3462 | 2.94k | *Culprit = this; |
3463 | 4.91k | return false; |
3464 | 38.5k | } |
3465 | | |
3466 | 290k | bool CallExpr::isBuiltinAssumeFalse(const ASTContext &Ctx) const { |
3467 | 290k | unsigned BuiltinID = getBuiltinCallee(); |
3468 | 290k | if (BuiltinID != Builtin::BI__assume && |
3469 | 290k | BuiltinID != Builtin::BI__builtin_assume) |
3470 | 290k | return false; |
3471 | | |
3472 | 65 | const Expr* Arg = getArg(0); |
3473 | 65 | bool ArgVal; |
3474 | 65 | return !Arg->isValueDependent() && |
3475 | 65 | Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && !ArgVal31 ; |
3476 | 290k | } |
3477 | | |
3478 | 101k | bool CallExpr::isCallToStdMove() const { |
3479 | 101k | return getBuiltinCallee() == Builtin::BImove; |
3480 | 101k | } |
3481 | | |
3482 | | namespace { |
3483 | | /// Look for any side effects within a Stmt. |
3484 | | class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> { |
3485 | | typedef ConstEvaluatedExprVisitor<SideEffectFinder> Inherited; |
3486 | | const bool IncludePossibleEffects; |
3487 | | bool HasSideEffects; |
3488 | | |
3489 | | public: |
3490 | | explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible) |
3491 | | : Inherited(Context), |
3492 | 26 | IncludePossibleEffects(IncludePossible), HasSideEffects(false) { } |
3493 | | |
3494 | 26 | bool hasSideEffects() const { return HasSideEffects; } |
3495 | | |
3496 | 5 | void VisitDecl(const Decl *D) { |
3497 | 5 | if (!D) |
3498 | 0 | return; |
3499 | | |
3500 | | // We assume the caller checks subexpressions (eg, the initializer, VLA |
3501 | | // bounds) for side-effects on our behalf. |
3502 | 5 | if (auto *VD = dyn_cast<VarDecl>(D)) { |
3503 | | // Registering a destructor is a side-effect. |
3504 | 3 | if (IncludePossibleEffects && VD->isThisDeclarationADefinition()2 && |
3505 | 3 | VD->needsDestruction(Context)2 ) |
3506 | 2 | HasSideEffects = true; |
3507 | 3 | } |
3508 | 5 | } |
3509 | | |
3510 | 5 | void VisitDeclStmt(const DeclStmt *DS) { |
3511 | 5 | for (auto *D : DS->decls()) |
3512 | 5 | VisitDecl(D); |
3513 | 5 | Inherited::VisitDeclStmt(DS); |
3514 | 5 | } |
3515 | | |
3516 | 49 | void VisitExpr(const Expr *E) { |
3517 | 49 | if (!HasSideEffects && |
3518 | 49 | E->HasSideEffects(Context, IncludePossibleEffects)37 ) |
3519 | 13 | HasSideEffects = true; |
3520 | 49 | } |
3521 | | }; |
3522 | | } |
3523 | | |
3524 | | bool Expr::HasSideEffects(const ASTContext &Ctx, |
3525 | 1.13M | bool IncludePossibleEffects) const { |
3526 | | // In circumstances where we care about definite side effects instead of |
3527 | | // potential side effects, we want to ignore expressions that are part of a |
3528 | | // macro expansion as a potential side effect. |
3529 | 1.13M | if (!IncludePossibleEffects && getExprLoc().isMacroID()25.8k ) |
3530 | 4.24k | return false; |
3531 | | |
3532 | 1.13M | switch (getStmtClass()) { |
3533 | 0 | case NoStmtClass: |
3534 | 0 | #define ABSTRACT_STMT(Type) |
3535 | 0 | #define STMT(Type, Base) case Type##Class: |
3536 | 0 | #define EXPR(Type, Base) |
3537 | 0 | #include "clang/AST/StmtNodes.inc" |
3538 | 0 | llvm_unreachable("unexpected Expr kind"); |
3539 | |
|
3540 | 1 | case DependentScopeDeclRefExprClass: |
3541 | 9 | case CXXUnresolvedConstructExprClass: |
3542 | 9 | case CXXDependentScopeMemberExprClass: |
3543 | 11 | case UnresolvedLookupExprClass: |
3544 | 11 | case UnresolvedMemberExprClass: |
3545 | 11 | case PackExpansionExprClass: |
3546 | 11 | case SubstNonTypeTemplateParmPackExprClass: |
3547 | 11 | case FunctionParmPackExprClass: |
3548 | 11 | case TypoExprClass: |
3549 | 176 | case RecoveryExprClass: |
3550 | 176 | case CXXFoldExprClass: |
3551 | | // Make a conservative assumption for dependent nodes. |
3552 | 176 | return IncludePossibleEffects; |
3553 | | |
3554 | 220k | case DeclRefExprClass: |
3555 | 221k | case ObjCIvarRefExprClass: |
3556 | 221k | case PredefinedExprClass: |
3557 | 317k | case IntegerLiteralClass: |
3558 | 317k | case FixedPointLiteralClass: |
3559 | 320k | case FloatingLiteralClass: |
3560 | 320k | case ImaginaryLiteralClass: |
3561 | 323k | case StringLiteralClass: |
3562 | 365k | case CharacterLiteralClass: |
3563 | 365k | case OffsetOfExprClass: |
3564 | 380k | case ImplicitValueInitExprClass: |
3565 | 382k | case UnaryExprOrTypeTraitExprClass: |
3566 | 382k | case AddrLabelExprClass: |
3567 | 382k | case GNUNullExprClass: |
3568 | 384k | case ArrayInitIndexExprClass: |
3569 | 384k | case NoInitExprClass: |
3570 | 453k | case CXXBoolLiteralExprClass: |
3571 | 458k | case CXXNullPtrLiteralExprClass: |
3572 | 459k | case CXXThisExprClass: |
3573 | 459k | case CXXScalarValueInitExprClass: |
3574 | 469k | case TypeTraitExprClass: |
3575 | 469k | case ArrayTypeTraitExprClass: |
3576 | 469k | case ExpressionTraitExprClass: |
3577 | 469k | case CXXNoexceptExprClass: |
3578 | 469k | case SizeOfPackExprClass: |
3579 | 469k | case ObjCStringLiteralClass: |
3580 | 469k | case ObjCEncodeExprClass: |
3581 | 469k | case ObjCBoolLiteralExprClass: |
3582 | 469k | case ObjCAvailabilityCheckExprClass: |
3583 | 469k | case CXXUuidofExprClass: |
3584 | 472k | case OpaqueValueExprClass: |
3585 | 473k | case SourceLocExprClass: |
3586 | 473k | case ConceptSpecializationExprClass: |
3587 | 473k | case RequiresExprClass: |
3588 | 473k | case SYCLUniqueStableNameExprClass: |
3589 | | // These never have a side-effect. |
3590 | 473k | return false; |
3591 | | |
3592 | 11.5k | case ConstantExprClass: |
3593 | | // FIXME: Move this into the "return false;" block above. |
3594 | 11.5k | return cast<ConstantExpr>(this)->getSubExpr()->HasSideEffects( |
3595 | 11.5k | Ctx, IncludePossibleEffects); |
3596 | | |
3597 | 21.2k | case CallExprClass: |
3598 | 22.0k | case CXXOperatorCallExprClass: |
3599 | 24.9k | case CXXMemberCallExprClass: |
3600 | 24.9k | case CUDAKernelCallExprClass: |
3601 | 25.0k | case UserDefinedLiteralClass: { |
3602 | | // We don't know a call definitely has side effects, except for calls |
3603 | | // to pure/const functions that definitely don't. |
3604 | | // If the call itself is considered side-effect free, check the operands. |
3605 | 25.0k | const Decl *FD = cast<CallExpr>(this)->getCalleeDecl(); |
3606 | 25.0k | bool IsPure = FD && (24.9k FD->hasAttr<ConstAttr>()24.9k || FD->hasAttr<PureAttr>()9.13k ); |
3607 | 25.0k | if (IsPure || !IncludePossibleEffects9.12k ) |
3608 | 16.7k | break; |
3609 | 8.23k | return true; |
3610 | 25.0k | } |
3611 | | |
3612 | 52 | case BlockExprClass: |
3613 | 297 | case CXXBindTemporaryExprClass: |
3614 | 297 | if (!IncludePossibleEffects) |
3615 | 225 | break; |
3616 | 72 | return true; |
3617 | | |
3618 | 0 | case MSPropertyRefExprClass: |
3619 | 0 | case MSPropertySubscriptExprClass: |
3620 | 3.07k | case CompoundAssignOperatorClass: |
3621 | 3.07k | case VAArgExprClass: |
3622 | 3.07k | case AtomicExprClass: |
3623 | 3.08k | case CXXThrowExprClass: |
3624 | 3.22k | case CXXNewExprClass: |
3625 | 3.22k | case CXXDeleteExprClass: |
3626 | 3.22k | case CoawaitExprClass: |
3627 | 3.22k | case DependentCoawaitExprClass: |
3628 | 3.22k | case CoyieldExprClass: |
3629 | | // These always have a side-effect. |
3630 | 3.22k | return true; |
3631 | | |
3632 | 26 | case StmtExprClass: { |
3633 | | // StmtExprs have a side-effect if any substatement does. |
3634 | 26 | SideEffectFinder Finder(Ctx, IncludePossibleEffects); |
3635 | 26 | Finder.Visit(cast<StmtExpr>(this)->getSubStmt()); |
3636 | 26 | return Finder.hasSideEffects(); |
3637 | 3.22k | } |
3638 | | |
3639 | 14.1k | case ExprWithCleanupsClass: |
3640 | 14.1k | if (IncludePossibleEffects) |
3641 | 14.1k | if (cast<ExprWithCleanups>(this)->cleanupsHaveSideEffects()) |
3642 | 246 | return true; |
3643 | 13.9k | break; |
3644 | | |
3645 | 13.9k | case ParenExprClass: |
3646 | 16.2k | case ArraySubscriptExprClass: |
3647 | 16.2k | case MatrixSubscriptExprClass: |
3648 | 16.2k | case OMPArraySectionExprClass: |
3649 | 16.2k | case OMPArrayShapingExprClass: |
3650 | 16.2k | case OMPIteratorExprClass: |
3651 | 68.6k | case MemberExprClass: |
3652 | 81.4k | case ConditionalOperatorClass: |
3653 | 81.5k | case BinaryConditionalOperatorClass: |
3654 | 81.7k | case CompoundLiteralExprClass: |
3655 | 81.7k | case ExtVectorElementExprClass: |
3656 | 81.7k | case DesignatedInitExprClass: |
3657 | 81.8k | case DesignatedInitUpdateExprClass: |
3658 | 83.3k | case ArrayInitLoopExprClass: |
3659 | 83.3k | case ParenListExprClass: |
3660 | 83.3k | case CXXPseudoDestructorExprClass: |
3661 | 83.3k | case CXXRewrittenBinaryOperatorClass: |
3662 | 83.4k | case CXXStdInitializerListExprClass: |
3663 | 144k | case SubstNonTypeTemplateParmExprClass: |
3664 | 154k | case MaterializeTemporaryExprClass: |
3665 | 154k | case ShuffleVectorExprClass: |
3666 | 154k | case ConvertVectorExprClass: |
3667 | 154k | case AsTypeExprClass: |
3668 | 154k | case CXXParenListInitExprClass: |
3669 | | // These have a side-effect if any subexpression does. |
3670 | 154k | break; |
3671 | | |
3672 | 13.1k | case UnaryOperatorClass: |
3673 | 13.1k | if (cast<UnaryOperator>(this)->isIncrementDecrementOp()) |
3674 | 752 | return true; |
3675 | 12.3k | break; |
3676 | | |
3677 | 41.4k | case BinaryOperatorClass: |
3678 | 41.4k | if (cast<BinaryOperator>(this)->isAssignmentOp()) |
3679 | 1.41k | return true; |
3680 | 39.9k | break; |
3681 | | |
3682 | 39.9k | case InitListExprClass: |
3683 | | // FIXME: The children for an InitListExpr doesn't include the array filler. |
3684 | 11.7k | if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller()) |
3685 | 683 | if (E->HasSideEffects(Ctx, IncludePossibleEffects)) |
3686 | 17 | return true; |
3687 | 11.7k | break; |
3688 | | |
3689 | 11.7k | case GenericSelectionExprClass: |
3690 | 1 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> |
3691 | 1 | HasSideEffects(Ctx, IncludePossibleEffects); |
3692 | | |
3693 | 4 | case ChooseExprClass: |
3694 | 4 | return cast<ChooseExpr>(this)->getChosenSubExpr()->HasSideEffects( |
3695 | 4 | Ctx, IncludePossibleEffects); |
3696 | | |
3697 | 10 | case CXXDefaultArgExprClass: |
3698 | 10 | return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects( |
3699 | 10 | Ctx, IncludePossibleEffects); |
3700 | | |
3701 | 3.22k | case CXXDefaultInitExprClass: { |
3702 | 3.22k | const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)->getField(); |
3703 | 3.22k | if (const Expr *E = FD->getInClassInitializer()) |
3704 | 3.22k | return E->HasSideEffects(Ctx, IncludePossibleEffects); |
3705 | | // If we've not yet parsed the initializer, assume it has side-effects. |
3706 | 0 | return true; |
3707 | 3.22k | } |
3708 | | |
3709 | 89 | case CXXDynamicCastExprClass: { |
3710 | | // A dynamic_cast expression has side-effects if it can throw. |
3711 | 89 | const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this); |
3712 | 89 | if (DCE->getTypeAsWritten()->isReferenceType() && |
3713 | 89 | DCE->getCastKind() == CK_Dynamic25 ) |
3714 | 25 | return true; |
3715 | 89 | } |
3716 | 89 | [[fallthrough]];64 |
3717 | 280k | case ImplicitCastExprClass: |
3718 | 284k | case CStyleCastExprClass: |
3719 | 322k | case CXXStaticCastExprClass: |
3720 | 322k | case CXXReinterpretCastExprClass: |
3721 | 323k | case CXXConstCastExprClass: |
3722 | 323k | case CXXAddrspaceCastExprClass: |
3723 | 331k | case CXXFunctionalCastExprClass: |
3724 | 331k | case BuiltinBitCastExprClass: { |
3725 | | // While volatile reads are side-effecting in both C and C++, we treat them |
3726 | | // as having possible (not definite) side-effects. This allows idiomatic |
3727 | | // code to behave without warning, such as sizeof(*v) for a volatile- |
3728 | | // qualified pointer. |
3729 | 331k | if (!IncludePossibleEffects) |
3730 | 3.00k | break; |
3731 | | |
3732 | 328k | const CastExpr *CE = cast<CastExpr>(this); |
3733 | 328k | if (CE->getCastKind() == CK_LValueToRValue && |
3734 | 328k | CE->getSubExpr()->getType().isVolatileQualified()153k ) |
3735 | 1.18k | return true; |
3736 | 327k | break; |
3737 | 328k | } |
3738 | | |
3739 | 327k | case CXXTypeidExprClass: |
3740 | | // typeid might throw if its subexpression is potentially-evaluated, so has |
3741 | | // side-effects in that case whether or not its subexpression does. |
3742 | 52 | return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); |
3743 | | |
3744 | 39.6k | case CXXConstructExprClass: |
3745 | 48.7k | case CXXTemporaryObjectExprClass: { |
3746 | 48.7k | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); |
3747 | 48.7k | if (!CE->getConstructor()->isTrivial() && IncludePossibleEffects18.7k ) |
3748 | 18.5k | return true; |
3749 | | // A trivial constructor does not add any side-effects of its own. Just look |
3750 | | // at its arguments. |
3751 | 30.1k | break; |
3752 | 48.7k | } |
3753 | | |
3754 | 30.1k | case CXXInheritedCtorInitExprClass: { |
3755 | 0 | const auto *ICIE = cast<CXXInheritedCtorInitExpr>(this); |
3756 | 0 | if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects) |
3757 | 0 | return true; |
3758 | 0 | break; |
3759 | 0 | } |
3760 | | |
3761 | 2.03k | case LambdaExprClass: { |
3762 | 2.03k | const LambdaExpr *LE = cast<LambdaExpr>(this); |
3763 | 2.03k | for (Expr *E : LE->capture_inits()) |
3764 | 119 | if (E && E->HasSideEffects(Ctx, IncludePossibleEffects)118 ) |
3765 | 6 | return true; |
3766 | 2.02k | return false; |
3767 | 2.03k | } |
3768 | | |
3769 | 15 | case PseudoObjectExprClass: { |
3770 | | // Only look for side-effects in the semantic form, and look past |
3771 | | // OpaqueValueExpr bindings in that form. |
3772 | 15 | const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); |
3773 | 15 | for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), |
3774 | 15 | E = PO->semantics_end(); |
3775 | 41 | I != E; ++I26 ) { |
3776 | 28 | const Expr *Subexpr = *I; |
3777 | 28 | if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr)) |
3778 | 13 | Subexpr = OVE->getSourceExpr(); |
3779 | 28 | if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects)) |
3780 | 2 | return true; |
3781 | 28 | } |
3782 | 13 | return false; |
3783 | 15 | } |
3784 | | |
3785 | 0 | case ObjCBoxedExprClass: |
3786 | 0 | case ObjCArrayLiteralClass: |
3787 | 0 | case ObjCDictionaryLiteralClass: |
3788 | 0 | case ObjCSelectorExprClass: |
3789 | 0 | case ObjCProtocolExprClass: |
3790 | 0 | case ObjCIsaExprClass: |
3791 | 0 | case ObjCIndirectCopyRestoreExprClass: |
3792 | 0 | case ObjCSubscriptRefExprClass: |
3793 | 7 | case ObjCBridgedCastExprClass: |
3794 | 58 | case ObjCMessageExprClass: |
3795 | 58 | case ObjCPropertyRefExprClass: |
3796 | | // FIXME: Classify these cases better. |
3797 | 58 | if (IncludePossibleEffects) |
3798 | 39 | return true; |
3799 | 19 | break; |
3800 | 1.13M | } |
3801 | | |
3802 | | // Recurse to children. |
3803 | 609k | for (const Stmt *SubStmt : children()) |
3804 | 789k | if (SubStmt && |
3805 | 789k | cast<Expr>(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects)789k ) |
3806 | 16.6k | return true; |
3807 | | |
3808 | 593k | return false; |
3809 | 609k | } |
3810 | | |
3811 | 1.74M | FPOptions Expr::getFPFeaturesInEffect(const LangOptions &LO) const { |
3812 | 1.74M | if (auto Call = dyn_cast<CallExpr>(this)) |
3813 | 5.52k | return Call->getFPFeaturesInEffect(LO); |
3814 | 1.73M | if (auto UO = dyn_cast<UnaryOperator>(this)) |
3815 | 1.12k | return UO->getFPFeaturesInEffect(LO); |
3816 | 1.73M | if (auto BO = dyn_cast<BinaryOperator>(this)) |
3817 | 108k | return BO->getFPFeaturesInEffect(LO); |
3818 | 1.62M | if (auto Cast = dyn_cast<CastExpr>(this)) |
3819 | 1.62M | return Cast->getFPFeaturesInEffect(LO); |
3820 | 2.81k | return FPOptions::defaultWithoutTrailingStorage(LO); |
3821 | 1.62M | } |
3822 | | |
3823 | | namespace { |
3824 | | /// Look for a call to a non-trivial function within an expression. |
3825 | | class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder> |
3826 | | { |
3827 | | typedef ConstEvaluatedExprVisitor<NonTrivialCallFinder> Inherited; |
3828 | | |
3829 | | bool NonTrivial; |
3830 | | |
3831 | | public: |
3832 | | explicit NonTrivialCallFinder(const ASTContext &Context) |
3833 | 8.08k | : Inherited(Context), NonTrivial(false) { } |
3834 | | |
3835 | 8.08k | bool hasNonTrivialCall() const { return NonTrivial; } |
3836 | | |
3837 | 797 | void VisitCallExpr(const CallExpr *E) { |
3838 | 797 | if (const CXXMethodDecl *Method |
3839 | 797 | = dyn_cast_or_null<const CXXMethodDecl>(E->getCalleeDecl())) { |
3840 | 572 | if (Method->isTrivial()) { |
3841 | | // Recurse to children of the call. |
3842 | 290 | Inherited::VisitStmt(E); |
3843 | 290 | return; |
3844 | 290 | } |
3845 | 572 | } |
3846 | | |
3847 | 507 | NonTrivial = true; |
3848 | 507 | } |
3849 | | |
3850 | 326 | void VisitCXXConstructExpr(const CXXConstructExpr *E) { |
3851 | 326 | if (E->getConstructor()->isTrivial()) { |
3852 | | // Recurse to children of the call. |
3853 | 260 | Inherited::VisitStmt(E); |
3854 | 260 | return; |
3855 | 260 | } |
3856 | | |
3857 | 66 | NonTrivial = true; |
3858 | 66 | } |
3859 | | |
3860 | 128 | void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) { |
3861 | 128 | if (E->getTemporary()->getDestructor()->isTrivial()) { |
3862 | 0 | Inherited::VisitStmt(E); |
3863 | 0 | return; |
3864 | 0 | } |
3865 | | |
3866 | 128 | NonTrivial = true; |
3867 | 128 | } |
3868 | | }; |
3869 | | } |
3870 | | |
3871 | 8.08k | bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const { |
3872 | 8.08k | NonTrivialCallFinder Finder(Ctx); |
3873 | 8.08k | Finder.Visit(this); |
3874 | 8.08k | return Finder.hasNonTrivialCall(); |
3875 | 8.08k | } |
3876 | | |
3877 | | /// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null |
3878 | | /// pointer constant or not, as well as the specific kind of constant detected. |
3879 | | /// Null pointer constants can be integer constant expressions with the |
3880 | | /// value zero, casts of zero to void*, nullptr (C++0X), or __null |
3881 | | /// (a GNU extension). |
3882 | | Expr::NullPointerConstantKind |
3883 | | Expr::isNullPointerConstant(ASTContext &Ctx, |
3884 | 2.04M | NullPointerConstantValueDependence NPC) const { |
3885 | 2.04M | if (isValueDependent() && |
3886 | 2.04M | (38.5k !Ctx.getLangOpts().CPlusPlus1138.5k || Ctx.getLangOpts().MSVCCompat38.5k )) { |
3887 | | // Error-dependent expr should never be a null pointer. |
3888 | 32 | if (containsErrors()) |
3889 | 6 | return NPCK_NotNull; |
3890 | 26 | switch (NPC) { |
3891 | 0 | case NPC_NeverValueDependent: |
3892 | 0 | llvm_unreachable("Unexpected value dependent expression!"); |
3893 | 19 | case NPC_ValueDependentIsNull: |
3894 | 19 | if (isTypeDependent() || getType()->isIntegralType(Ctx)) |
3895 | 10 | return NPCK_ZeroExpression; |
3896 | 9 | else |
3897 | 9 | return NPCK_NotNull; |
3898 | | |
3899 | 7 | case NPC_ValueDependentIsNotNull: |
3900 | 7 | return NPCK_NotNull; |
3901 | 26 | } |
3902 | 26 | } |
3903 | | |
3904 | | // Strip off a cast to void*, if it exists. Except in C++. |
3905 | 2.04M | if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { |
3906 | 114k | if (!Ctx.getLangOpts().CPlusPlus) { |
3907 | | // Check that it is a cast to void*. |
3908 | 92.4k | if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { |
3909 | 91.1k | QualType Pointee = PT->getPointeeType(); |
3910 | 91.1k | Qualifiers Qs = Pointee.getQualifiers(); |
3911 | | // Only (void*)0 or equivalent are treated as nullptr. If pointee type |
3912 | | // has non-default address space it is not treated as nullptr. |
3913 | | // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr |
3914 | | // since it cannot be assigned to a pointer to constant address space. |
3915 | 91.1k | if (Ctx.getLangOpts().OpenCL && |
3916 | 91.1k | Pointee.getAddressSpace() == Ctx.getDefaultOpenCLPointeeAddrSpace()4.64k ) |
3917 | 1.29k | Qs.removeAddressSpace(); |
3918 | | |
3919 | 91.1k | if (Pointee->isVoidType() && Qs.empty()7.01k && // to void* |
3920 | 91.1k | CE->getSubExpr()->getType()->isIntegerType()5.12k ) // from int |
3921 | 4.19k | return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3922 | 91.1k | } |
3923 | 92.4k | } |
3924 | 1.93M | } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { |
3925 | | // Ignore the ImplicitCastExpr type entirely. |
3926 | 439k | return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3927 | 1.49M | } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { |
3928 | | // Accept ((void*)0) as a null pointer constant, as many other |
3929 | | // implementations do. |
3930 | 28.2k | return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3931 | 1.46M | } else if (const GenericSelectionExpr *GE = |
3932 | 1.46M | dyn_cast<GenericSelectionExpr>(this)) { |
3933 | 1 | if (GE->isResultDependent()) |
3934 | 0 | return NPCK_NotNull; |
3935 | 1 | return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); |
3936 | 1.46M | } else if (const ChooseExpr *CE = dyn_cast<ChooseExpr>(this)) { |
3937 | 1 | if (CE->isConditionDependent()) |
3938 | 0 | return NPCK_NotNull; |
3939 | 1 | return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC); |
3940 | 1.46M | } else if (const CXXDefaultArgExpr *DefaultArg |
3941 | 1.46M | = dyn_cast<CXXDefaultArgExpr>(this)) { |
3942 | | // See through default argument expressions. |
3943 | 120 | return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); |
3944 | 1.46M | } else if (const CXXDefaultInitExpr *DefaultInit |
3945 | 1.46M | = dyn_cast<CXXDefaultInitExpr>(this)) { |
3946 | | // See through default initializer expressions. |
3947 | 0 | return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC); |
3948 | 1.46M | } else if (isa<GNUNullExpr>(this)) { |
3949 | | // The GNU __null extension is always a null pointer constant. |
3950 | 7.63k | return NPCK_GNUNull; |
3951 | 1.45M | } else if (const MaterializeTemporaryExpr *M |
3952 | 1.45M | = dyn_cast<MaterializeTemporaryExpr>(this)) { |
3953 | 3 | return M->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3954 | 1.45M | } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) { |
3955 | 1.81k | if (const Expr *Source = OVE->getSourceExpr()) |
3956 | 963 | return Source->isNullPointerConstant(Ctx, NPC); |
3957 | 1.81k | } |
3958 | | |
3959 | | // If the expression has no type information, it cannot be a null pointer |
3960 | | // constant. |
3961 | 1.56M | if (getType().isNull()) |
3962 | 0 | return NPCK_NotNull; |
3963 | | |
3964 | | // C++11/C2x nullptr_t is always a null pointer constant. |
3965 | 1.56M | if (getType()->isNullPtrType()) |
3966 | 128k | return NPCK_CXX11_nullptr; |
3967 | | |
3968 | 1.43M | if (const RecordType *UT = getType()->getAsUnionType()) |
3969 | 6 | if (!Ctx.getLangOpts().CPlusPlus11 && |
3970 | 6 | UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) |
3971 | 6 | if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){ |
3972 | 0 | const Expr *InitExpr = CLE->getInitializer(); |
3973 | 0 | if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) |
3974 | 0 | return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); |
3975 | 0 | } |
3976 | | // This expression must be an integer type. |
3977 | 1.43M | if (!getType()->isIntegerType() || |
3978 | 1.43M | (128k Ctx.getLangOpts().CPlusPlus128k && getType()->isEnumeralType()99.3k )) |
3979 | 1.31M | return NPCK_NotNull; |
3980 | | |
3981 | 128k | if (Ctx.getLangOpts().CPlusPlus11) { |
3982 | | // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with |
3983 | | // value zero or a prvalue of type std::nullptr_t. |
3984 | | // Microsoft mode permits C++98 rules reflecting MSVC behavior. |
3985 | 92.8k | const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this); |
3986 | 92.8k | if (Lit && !Lit->getValue()87.8k ) |
3987 | 83.5k | return NPCK_ZeroLiteral; |
3988 | 9.26k | if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx)46 ) |
3989 | 9.24k | return NPCK_NotNull; |
3990 | 35.3k | } else { |
3991 | | // If we have an integer constant expression, we need to *evaluate* it and |
3992 | | // test for the value 0. |
3993 | 35.3k | if (!isIntegerConstantExpr(Ctx)) |
3994 | 5.10k | return NPCK_NotNull; |
3995 | 35.3k | } |
3996 | | |
3997 | 30.3k | if (EvaluateKnownConstInt(Ctx) != 0) |
3998 | 498 | return NPCK_NotNull; |
3999 | | |
4000 | 29.8k | if (isa<IntegerLiteral>(this)) |
4001 | 29.6k | return NPCK_ZeroLiteral; |
4002 | 200 | return NPCK_ZeroExpression; |
4003 | 29.8k | } |
4004 | | |
4005 | | /// If this expression is an l-value for an Objective C |
4006 | | /// property, find the underlying property reference expression. |
4007 | 0 | const ObjCPropertyRefExpr *Expr::getObjCProperty() const { |
4008 | 0 | const Expr *E = this; |
4009 | 0 | while (true) { |
4010 | 0 | assert((E->isLValue() && E->getObjectKind() == OK_ObjCProperty) && |
4011 | 0 | "expression is not a property reference"); |
4012 | 0 | E = E->IgnoreParenCasts(); |
4013 | 0 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) { |
4014 | 0 | if (BO->getOpcode() == BO_Comma) { |
4015 | 0 | E = BO->getRHS(); |
4016 | 0 | continue; |
4017 | 0 | } |
4018 | 0 | } |
4019 | | |
4020 | 0 | break; |
4021 | 0 | } |
4022 | | |
4023 | 0 | return cast<ObjCPropertyRefExpr>(E); |
4024 | 0 | } |
4025 | | |
4026 | 385 | bool Expr::isObjCSelfExpr() const { |
4027 | 385 | const Expr *E = IgnoreParenImpCasts(); |
4028 | | |
4029 | 385 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); |
4030 | 385 | if (!DRE) |
4031 | 146 | return false; |
4032 | | |
4033 | 239 | const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); |
4034 | 239 | if (!Param) |
4035 | 113 | return false; |
4036 | | |
4037 | 126 | const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); |
4038 | 126 | if (!M) |
4039 | 0 | return false; |
4040 | | |
4041 | 126 | return M->getSelfDecl() == Param; |
4042 | 126 | } |
4043 | | |
4044 | 18.0M | FieldDecl *Expr::getSourceBitField() { |
4045 | 18.0M | Expr *E = this->IgnoreParens(); |
4046 | | |
4047 | 21.5M | while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
4048 | 3.59M | if (ICE->getCastKind() == CK_LValueToRValue || |
4049 | 3.59M | (41.5k ICE->isGLValue()41.5k && ICE->getCastKind() == CK_NoOp57 )) |
4050 | 3.54M | E = ICE->getSubExpr()->IgnoreParens(); |
4051 | 41.5k | else |
4052 | 41.5k | break; |
4053 | 3.59M | } |
4054 | | |
4055 | 18.0M | if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) |
4056 | 258k | if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) |
4057 | 258k | if (Field->isBitField()) |
4058 | 10.8k | return Field; |
4059 | | |
4060 | 17.9M | if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) { |
4061 | 1.58k | FieldDecl *Ivar = IvarRef->getDecl(); |
4062 | 1.58k | if (Ivar->isBitField()) |
4063 | 212 | return Ivar; |
4064 | 1.58k | } |
4065 | | |
4066 | 17.9M | if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) { |
4067 | 6.92M | if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) |
4068 | 18 | if (Field->isBitField()) |
4069 | 0 | return Field; |
4070 | | |
4071 | 6.92M | if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl())) |
4072 | 978 | if (Expr *E = BD->getBinding()) |
4073 | 978 | return E->getSourceBitField(); |
4074 | 6.92M | } |
4075 | | |
4076 | 17.9M | if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) { |
4077 | 2.55M | if (BinOp->isAssignmentOp() && BinOp->getLHS()921 ) |
4078 | 921 | return BinOp->getLHS()->getSourceBitField(); |
4079 | | |
4080 | 2.55M | if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS()154 ) |
4081 | 154 | return BinOp->getRHS()->getSourceBitField(); |
4082 | 2.55M | } |
4083 | | |
4084 | 17.9M | if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) |
4085 | 137k | if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp()3.87k ) |
4086 | 3.87k | return UnOp->getSubExpr()->getSourceBitField(); |
4087 | | |
4088 | 17.9M | return nullptr; |
4089 | 17.9M | } |
4090 | | |
4091 | 501k | bool Expr::refersToVectorElement() const { |
4092 | | // FIXME: Why do we not just look at the ObjectKind here? |
4093 | 501k | const Expr *E = this->IgnoreParens(); |
4094 | | |
4095 | 509k | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) { |
4096 | 21.3k | if (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp) |
4097 | 7.82k | E = ICE->getSubExpr()->IgnoreParens(); |
4098 | 13.4k | else |
4099 | 13.4k | break; |
4100 | 21.3k | } |
4101 | | |
4102 | 501k | if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) |
4103 | 6.22k | return ASE->getBase()->getType()->isVectorType(); |
4104 | | |
4105 | 495k | if (isa<ExtVectorElementExpr>(E)) |
4106 | 9 | return true; |
4107 | | |
4108 | 495k | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
4109 | 306k | if (auto *BD = dyn_cast<BindingDecl>(DRE->getDecl())) |
4110 | 35 | if (auto *E = BD->getBinding()) |
4111 | 35 | return E->refersToVectorElement(); |
4112 | | |
4113 | 495k | return false; |
4114 | 495k | } |
4115 | | |
4116 | 932 | bool Expr::refersToGlobalRegisterVar() const { |
4117 | 932 | const Expr *E = this->IgnoreParenImpCasts(); |
4118 | | |
4119 | 932 | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) |
4120 | 623 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
4121 | 623 | if (VD->getStorageClass() == SC_Register && |
4122 | 623 | VD->hasAttr<AsmLabelAttr>()145 && !VD->isLocalVarDecl()2 ) |
4123 | 2 | return true; |
4124 | | |
4125 | 930 | return false; |
4126 | 932 | } |
4127 | | |
4128 | 791k | bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) { |
4129 | 791k | E1 = E1->IgnoreParens(); |
4130 | 791k | E2 = E2->IgnoreParens(); |
4131 | | |
4132 | 791k | if (E1->getStmtClass() != E2->getStmtClass()) |
4133 | 440k | return false; |
4134 | | |
4135 | 350k | switch (E1->getStmtClass()) { |
4136 | 87.9k | default: |
4137 | 87.9k | return false; |
4138 | 9 | case CXXThisExprClass: |
4139 | 9 | return true; |
4140 | 6.45k | case DeclRefExprClass: { |
4141 | | // DeclRefExpr without an ImplicitCastExpr can happen for integral |
4142 | | // template parameters. |
4143 | 6.45k | const auto *DRE1 = cast<DeclRefExpr>(E1); |
4144 | 6.45k | const auto *DRE2 = cast<DeclRefExpr>(E2); |
4145 | 6.45k | return DRE1->isPRValue() && DRE2->isPRValue()6.00k && |
4146 | 6.45k | DRE1->getDecl() == DRE2->getDecl()6.00k ; |
4147 | 0 | } |
4148 | 256k | case ImplicitCastExprClass: { |
4149 | | // Peel off implicit casts. |
4150 | 257k | while (true) { |
4151 | 257k | const auto *ICE1 = dyn_cast<ImplicitCastExpr>(E1); |
4152 | 257k | const auto *ICE2 = dyn_cast<ImplicitCastExpr>(E2); |
4153 | 257k | if (!ICE1 || !ICE2256k ) |
4154 | 1.42k | return false; |
4155 | 256k | if (ICE1->getCastKind() != ICE2->getCastKind()) |
4156 | 1.69k | return false; |
4157 | 254k | E1 = ICE1->getSubExpr()->IgnoreParens(); |
4158 | 254k | E2 = ICE2->getSubExpr()->IgnoreParens(); |
4159 | | // The final cast must be one of these types. |
4160 | 254k | if (ICE1->getCastKind() == CK_LValueToRValue || |
4161 | 254k | ICE1->getCastKind() == CK_ArrayToPointerDecay1.68k || |
4162 | 254k | ICE1->getCastKind() == CK_FunctionToPointerDecay1.49k ) { |
4163 | 253k | break; |
4164 | 253k | } |
4165 | 254k | } |
4166 | | |
4167 | 253k | const auto *DRE1 = dyn_cast<DeclRefExpr>(E1); |
4168 | 253k | const auto *DRE2 = dyn_cast<DeclRefExpr>(E2); |
4169 | 253k | if (DRE1 && DRE2243k ) |
4170 | 237k | return declaresSameEntity(DRE1->getDecl(), DRE2->getDecl()); |
4171 | | |
4172 | 15.0k | const auto *Ivar1 = dyn_cast<ObjCIvarRefExpr>(E1); |
4173 | 15.0k | const auto *Ivar2 = dyn_cast<ObjCIvarRefExpr>(E2); |
4174 | 15.0k | if (Ivar1 && Ivar217 ) { |
4175 | 8 | return Ivar1->isFreeIvar() && Ivar2->isFreeIvar()7 && |
4176 | 8 | declaresSameEntity(Ivar1->getDecl(), Ivar2->getDecl())7 ; |
4177 | 8 | } |
4178 | | |
4179 | 15.0k | const auto *Array1 = dyn_cast<ArraySubscriptExpr>(E1); |
4180 | 15.0k | const auto *Array2 = dyn_cast<ArraySubscriptExpr>(E2); |
4181 | 15.0k | if (Array1 && Array2247 ) { |
4182 | 219 | if (!isSameComparisonOperand(Array1->getBase(), Array2->getBase())) |
4183 | 130 | return false; |
4184 | | |
4185 | 89 | auto Idx1 = Array1->getIdx(); |
4186 | 89 | auto Idx2 = Array2->getIdx(); |
4187 | 89 | const auto Integer1 = dyn_cast<IntegerLiteral>(Idx1); |
4188 | 89 | const auto Integer2 = dyn_cast<IntegerLiteral>(Idx2); |
4189 | 89 | if (Integer1 && Integer281 ) { |
4190 | 81 | if (!llvm::APInt::isSameValue(Integer1->getValue(), |
4191 | 81 | Integer2->getValue())) |
4192 | 78 | return false; |
4193 | 81 | } else { |
4194 | 8 | if (!isSameComparisonOperand(Idx1, Idx2)) |
4195 | 3 | return false; |
4196 | 8 | } |
4197 | | |
4198 | 8 | return true; |
4199 | 89 | } |
4200 | | |
4201 | | // Walk the MemberExpr chain. |
4202 | 17.2k | while (14.8k isa<MemberExpr>(E1) && isa<MemberExpr>(E2)6.35k ) { |
4203 | 4.60k | const auto *ME1 = cast<MemberExpr>(E1); |
4204 | 4.60k | const auto *ME2 = cast<MemberExpr>(E2); |
4205 | 4.60k | if (!declaresSameEntity(ME1->getMemberDecl(), ME2->getMemberDecl())) |
4206 | 2.21k | return false; |
4207 | 2.39k | if (const auto *D = dyn_cast<VarDecl>(ME1->getMemberDecl())) |
4208 | 1 | if (D->isStaticDataMember()) |
4209 | 1 | return true; |
4210 | 2.38k | E1 = ME1->getBase()->IgnoreParenImpCasts(); |
4211 | 2.38k | E2 = ME2->getBase()->IgnoreParenImpCasts(); |
4212 | 2.38k | } |
4213 | | |
4214 | 12.6k | if (isa<CXXThisExpr>(E1) && isa<CXXThisExpr>(E2)148 ) |
4215 | 2 | return true; |
4216 | | |
4217 | | // A static member variable can end the MemberExpr chain with either |
4218 | | // a MemberExpr or a DeclRefExpr. |
4219 | 25.2k | auto getAnyDecl = [](const Expr *E) -> const ValueDecl * 12.6k { |
4220 | 25.2k | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
4221 | 14.1k | return DRE->getDecl(); |
4222 | 11.0k | if (const auto *ME = dyn_cast<MemberExpr>(E)) |
4223 | 6.79k | return ME->getMemberDecl(); |
4224 | 4.24k | return nullptr; |
4225 | 11.0k | }; |
4226 | | |
4227 | 12.6k | const ValueDecl *VD1 = getAnyDecl(E1); |
4228 | 12.6k | const ValueDecl *VD2 = getAnyDecl(E2); |
4229 | 12.6k | return declaresSameEntity(VD1, VD2); |
4230 | 12.6k | } |
4231 | 350k | } |
4232 | 350k | } |
4233 | | |
4234 | | /// isArrow - Return true if the base expression is a pointer to vector, |
4235 | | /// return false if the base expression is a vector. |
4236 | 405 | bool ExtVectorElementExpr::isArrow() const { |
4237 | 405 | return getBase()->getType()->isPointerType(); |
4238 | 405 | } |
4239 | | |
4240 | 323 | unsigned ExtVectorElementExpr::getNumElements() const { |
4241 | 323 | if (const VectorType *VT = getType()->getAs<VectorType>()) |
4242 | 81 | return VT->getNumElements(); |
4243 | 242 | return 1; |
4244 | 323 | } |
4245 | | |
4246 | | /// containsDuplicateElements - Return true if any element access is repeated. |
4247 | 97 | bool ExtVectorElementExpr::containsDuplicateElements() const { |
4248 | | // FIXME: Refactor this code to an accessor on the AST node which returns the |
4249 | | // "type" of component access, and share with code below and in Sema. |
4250 | 97 | StringRef Comp = Accessor->getName(); |
4251 | | |
4252 | | // Halving swizzles do not contain duplicate elements. |
4253 | 97 | if (Comp == "hi" || Comp == "lo"95 || Comp == "even"81 || Comp == "odd"70 ) |
4254 | 28 | return false; |
4255 | | |
4256 | | // Advance past s-char prefix on hex swizzles. |
4257 | 69 | if (Comp[0] == 's' || Comp[0] == 'S') |
4258 | 0 | Comp = Comp.substr(1); |
4259 | | |
4260 | 155 | for (unsigned i = 0, e = Comp.size(); i != e; ++i86 ) |
4261 | 94 | if (Comp.substr(i + 1).contains(Comp[i])) |
4262 | 8 | return true; |
4263 | | |
4264 | 61 | return false; |
4265 | 69 | } |
4266 | | |
4267 | | /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. |
4268 | | void ExtVectorElementExpr::getEncodedElementAccess( |
4269 | 323 | SmallVectorImpl<uint32_t> &Elts) const { |
4270 | 323 | StringRef Comp = Accessor->getName(); |
4271 | 323 | bool isNumericAccessor = false; |
4272 | 323 | if (Comp[0] == 's' || Comp[0] == 'S'312 ) { |
4273 | 11 | Comp = Comp.substr(1); |
4274 | 11 | isNumericAccessor = true; |
4275 | 11 | } |
4276 | | |
4277 | 323 | bool isHi = Comp == "hi"; |
4278 | 323 | bool isLo = Comp == "lo"; |
4279 | 323 | bool isEven = Comp == "even"; |
4280 | 323 | bool isOdd = Comp == "odd"; |
4281 | | |
4282 | 797 | for (unsigned i = 0, e = getNumElements(); i != e; ++i474 ) { |
4283 | 474 | uint64_t Index; |
4284 | | |
4285 | 474 | if (isHi) |
4286 | 14 | Index = e + i; |
4287 | 460 | else if (isLo) |
4288 | 46 | Index = i; |
4289 | 414 | else if (isEven) |
4290 | 5 | Index = 2 * i; |
4291 | 409 | else if (isOdd) |
4292 | 2 | Index = 2 * i + 1; |
4293 | 407 | else |
4294 | 407 | Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor); |
4295 | | |
4296 | 474 | Elts.push_back(Index); |
4297 | 474 | } |
4298 | 323 | } |
4299 | | |
4300 | | ShuffleVectorExpr::ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr *> args, |
4301 | | QualType Type, SourceLocation BLoc, |
4302 | | SourceLocation RP) |
4303 | | : Expr(ShuffleVectorExprClass, Type, VK_PRValue, OK_Ordinary), |
4304 | 174k | BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) { |
4305 | 174k | SubExprs = new (C) Stmt*[args.size()]; |
4306 | 1.78M | for (unsigned i = 0; i != args.size(); i++1.60M ) |
4307 | 1.60M | SubExprs[i] = args[i]; |
4308 | | |
4309 | 174k | setDependence(computeDependence(this)); |
4310 | 174k | } |
4311 | | |
4312 | 2 | void ShuffleVectorExpr::setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs) { |
4313 | 2 | if (SubExprs) C.Deallocate(SubExprs)0 ; |
4314 | | |
4315 | 2 | this->NumExprs = Exprs.size(); |
4316 | 2 | SubExprs = new (C) Stmt*[NumExprs]; |
4317 | 2 | memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size()); |
4318 | 2 | } |
4319 | | |
4320 | | GenericSelectionExpr::GenericSelectionExpr( |
4321 | | const ASTContext &, SourceLocation GenericLoc, Expr *ControllingExpr, |
4322 | | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, |
4323 | | SourceLocation DefaultLoc, SourceLocation RParenLoc, |
4324 | | bool ContainsUnexpandedParameterPack, unsigned ResultIndex) |
4325 | | : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(), |
4326 | | AssocExprs[ResultIndex]->getValueKind(), |
4327 | | AssocExprs[ResultIndex]->getObjectKind()), |
4328 | | NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), |
4329 | 555 | DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { |
4330 | 555 | assert(AssocTypes.size() == AssocExprs.size() && |
4331 | 555 | "Must have the same number of association expressions" |
4332 | 555 | " and TypeSourceInfo!"); |
4333 | 555 | assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!"); |
4334 | | |
4335 | 555 | GenericSelectionExprBits.GenericLoc = GenericLoc; |
4336 | 555 | getTrailingObjects<Stmt *>()[ControllingIndex] = ControllingExpr; |
4337 | 555 | std::copy(AssocExprs.begin(), AssocExprs.end(), |
4338 | 555 | getTrailingObjects<Stmt *>() + AssocExprStartIndex); |
4339 | 555 | std::copy(AssocTypes.begin(), AssocTypes.end(), |
4340 | 555 | getTrailingObjects<TypeSourceInfo *>()); |
4341 | | |
4342 | 555 | setDependence(computeDependence(this, ContainsUnexpandedParameterPack)); |
4343 | 555 | } |
4344 | | |
4345 | | GenericSelectionExpr::GenericSelectionExpr( |
4346 | | const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, |
4347 | | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, |
4348 | | SourceLocation DefaultLoc, SourceLocation RParenLoc, |
4349 | | bool ContainsUnexpandedParameterPack) |
4350 | | : Expr(GenericSelectionExprClass, Context.DependentTy, VK_PRValue, |
4351 | | OK_Ordinary), |
4352 | | NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex), |
4353 | 14 | DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { |
4354 | 14 | assert(AssocTypes.size() == AssocExprs.size() && |
4355 | 14 | "Must have the same number of association expressions" |
4356 | 14 | " and TypeSourceInfo!"); |
4357 | | |
4358 | 14 | GenericSelectionExprBits.GenericLoc = GenericLoc; |
4359 | 14 | getTrailingObjects<Stmt *>()[ControllingIndex] = ControllingExpr; |
4360 | 14 | std::copy(AssocExprs.begin(), AssocExprs.end(), |
4361 | 14 | getTrailingObjects<Stmt *>() + AssocExprStartIndex); |
4362 | 14 | std::copy(AssocTypes.begin(), AssocTypes.end(), |
4363 | 14 | getTrailingObjects<TypeSourceInfo *>()); |
4364 | | |
4365 | 14 | setDependence(computeDependence(this, ContainsUnexpandedParameterPack)); |
4366 | 14 | } |
4367 | | |
4368 | | GenericSelectionExpr::GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs) |
4369 | 9 | : Expr(GenericSelectionExprClass, Empty), NumAssocs(NumAssocs) {} |
4370 | | |
4371 | | GenericSelectionExpr *GenericSelectionExpr::Create( |
4372 | | const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, |
4373 | | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, |
4374 | | SourceLocation DefaultLoc, SourceLocation RParenLoc, |
4375 | 555 | bool ContainsUnexpandedParameterPack, unsigned ResultIndex) { |
4376 | 555 | unsigned NumAssocs = AssocExprs.size(); |
4377 | 555 | void *Mem = Context.Allocate( |
4378 | 555 | totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs), |
4379 | 555 | alignof(GenericSelectionExpr)); |
4380 | 555 | return new (Mem) GenericSelectionExpr( |
4381 | 555 | Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc, |
4382 | 555 | RParenLoc, ContainsUnexpandedParameterPack, ResultIndex); |
4383 | 555 | } |
4384 | | |
4385 | | GenericSelectionExpr *GenericSelectionExpr::Create( |
4386 | | const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, |
4387 | | ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs, |
4388 | | SourceLocation DefaultLoc, SourceLocation RParenLoc, |
4389 | 14 | bool ContainsUnexpandedParameterPack) { |
4390 | 14 | unsigned NumAssocs = AssocExprs.size(); |
4391 | 14 | void *Mem = Context.Allocate( |
4392 | 14 | totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs), |
4393 | 14 | alignof(GenericSelectionExpr)); |
4394 | 14 | return new (Mem) GenericSelectionExpr( |
4395 | 14 | Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc, |
4396 | 14 | RParenLoc, ContainsUnexpandedParameterPack); |
4397 | 14 | } |
4398 | | |
4399 | | GenericSelectionExpr * |
4400 | | GenericSelectionExpr::CreateEmpty(const ASTContext &Context, |
4401 | 9 | unsigned NumAssocs) { |
4402 | 9 | void *Mem = Context.Allocate( |
4403 | 9 | totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs), |
4404 | 9 | alignof(GenericSelectionExpr)); |
4405 | 9 | return new (Mem) GenericSelectionExpr(EmptyShell(), NumAssocs); |
4406 | 9 | } |
4407 | | |
4408 | | //===----------------------------------------------------------------------===// |
4409 | | // DesignatedInitExpr |
4410 | | //===----------------------------------------------------------------------===// |
4411 | | |
4412 | 4.83k | const IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { |
4413 | 4.83k | assert(isFieldDesignator() && "Only valid on a field designator"); |
4414 | 4.83k | if (FieldInfo.NameOrField & 0x01) |
4415 | 4.73k | return reinterpret_cast<IdentifierInfo *>(FieldInfo.NameOrField & ~0x01); |
4416 | 108 | return getFieldDecl()->getIdentifier(); |
4417 | 4.83k | } |
4418 | | |
4419 | | DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty, |
4420 | | llvm::ArrayRef<Designator> Designators, |
4421 | | SourceLocation EqualOrColonLoc, |
4422 | | bool GNUSyntax, |
4423 | | ArrayRef<Expr *> IndexExprs, Expr *Init) |
4424 | | : Expr(DesignatedInitExprClass, Ty, Init->getValueKind(), |
4425 | | Init->getObjectKind()), |
4426 | | EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), |
4427 | 2.38k | NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) { |
4428 | 2.38k | this->Designators = new (C) Designator[NumDesignators]; |
4429 | | |
4430 | | // Record the initializer itself. |
4431 | 2.38k | child_iterator Child = child_begin(); |
4432 | 2.38k | *Child++ = Init; |
4433 | | |
4434 | | // Copy the designators and their subexpressions, computing |
4435 | | // value-dependence along the way. |
4436 | 2.38k | unsigned IndexIdx = 0; |
4437 | 5.13k | for (unsigned I = 0; I != NumDesignators; ++I2.75k ) { |
4438 | 2.75k | this->Designators[I] = Designators[I]; |
4439 | 2.75k | if (this->Designators[I].isArrayDesignator()) { |
4440 | | // Copy the index expressions into permanent storage. |
4441 | 434 | *Child++ = IndexExprs[IndexIdx++]; |
4442 | 2.32k | } else if (this->Designators[I].isArrayRangeDesignator()) { |
4443 | | // Copy the start/end expressions into permanent storage. |
4444 | 27 | *Child++ = IndexExprs[IndexIdx++]; |
4445 | 27 | *Child++ = IndexExprs[IndexIdx++]; |
4446 | 27 | } |
4447 | 2.75k | } |
4448 | | |
4449 | 2.38k | assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions"); |
4450 | 2.38k | setDependence(computeDependence(this)); |
4451 | 2.38k | } |
4452 | | |
4453 | | DesignatedInitExpr * |
4454 | | DesignatedInitExpr::Create(const ASTContext &C, |
4455 | | llvm::ArrayRef<Designator> Designators, |
4456 | | ArrayRef<Expr*> IndexExprs, |
4457 | | SourceLocation ColonOrEqualLoc, |
4458 | 2.38k | bool UsesColonSyntax, Expr *Init) { |
4459 | 2.38k | void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1), |
4460 | 2.38k | alignof(DesignatedInitExpr)); |
4461 | 2.38k | return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators, |
4462 | 2.38k | ColonOrEqualLoc, UsesColonSyntax, |
4463 | 2.38k | IndexExprs, Init); |
4464 | 2.38k | } |
4465 | | |
4466 | | DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(const ASTContext &C, |
4467 | 52 | unsigned NumIndexExprs) { |
4468 | 52 | void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1), |
4469 | 52 | alignof(DesignatedInitExpr)); |
4470 | 52 | return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); |
4471 | 52 | } |
4472 | | |
4473 | | void DesignatedInitExpr::setDesignators(const ASTContext &C, |
4474 | | const Designator *Desigs, |
4475 | 52 | unsigned NumDesigs) { |
4476 | 52 | Designators = new (C) Designator[NumDesigs]; |
4477 | 52 | NumDesignators = NumDesigs; |
4478 | 113 | for (unsigned I = 0; I != NumDesigs; ++I61 ) |
4479 | 61 | Designators[I] = Desigs[I]; |
4480 | 52 | } |
4481 | | |
4482 | 68 | SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { |
4483 | 68 | DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); |
4484 | 68 | if (size() == 1) |
4485 | 0 | return DIE->getDesignator(0)->getSourceRange(); |
4486 | 68 | return SourceRange(DIE->getDesignator(0)->getBeginLoc(), |
4487 | 68 | DIE->getDesignator(size() - 1)->getEndLoc()); |
4488 | 68 | } |
4489 | | |
4490 | 6.02k | SourceLocation DesignatedInitExpr::getBeginLoc() const { |
4491 | 6.02k | auto *DIE = const_cast<DesignatedInitExpr *>(this); |
4492 | 6.02k | Designator &First = *DIE->getDesignator(0); |
4493 | 6.02k | if (First.isFieldDesignator()) |
4494 | 5.63k | return GNUSyntax ? First.getFieldLoc()24 : First.getDotLoc()5.61k ; |
4495 | 390 | return First.getLBracketLoc(); |
4496 | 6.02k | } |
4497 | | |
4498 | 1.03k | SourceLocation DesignatedInitExpr::getEndLoc() const { |
4499 | 1.03k | return getInit()->getEndLoc(); |
4500 | 1.03k | } |
4501 | | |
4502 | 1.30k | Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) const { |
4503 | 1.30k | assert(D.isArrayDesignator() && "Requires array designator"); |
4504 | 1.30k | return getSubExpr(D.getArrayIndex() + 1); |
4505 | 1.30k | } |
4506 | | |
4507 | 90 | Expr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const { |
4508 | 90 | assert(D.isArrayRangeDesignator() && "Requires array range designator"); |
4509 | 90 | return getSubExpr(D.getArrayIndex() + 1); |
4510 | 90 | } |
4511 | | |
4512 | 132 | Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const { |
4513 | 132 | assert(D.isArrayRangeDesignator() && "Requires array range designator"); |
4514 | 132 | return getSubExpr(D.getArrayIndex() + 2); |
4515 | 132 | } |
4516 | | |
4517 | | /// Replaces the designator at index @p Idx with the series |
4518 | | /// of designators in [First, Last). |
4519 | | void DesignatedInitExpr::ExpandDesignator(const ASTContext &C, unsigned Idx, |
4520 |