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