/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/lib/AST/Expr.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- Expr.cpp - Expression AST Node Implementation --------------------===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements the Expr class and subclasses. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "clang/AST/ASTContext.h" |
15 | | #include "clang/AST/Attr.h" |
16 | | #include "clang/AST/DeclCXX.h" |
17 | | #include "clang/AST/DeclObjC.h" |
18 | | #include "clang/AST/DeclTemplate.h" |
19 | | #include "clang/AST/EvaluatedExprVisitor.h" |
20 | | #include "clang/AST/Expr.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 "clang/Sema/SemaDiagnostic.h" |
32 | | #include "llvm/Support/ErrorHandling.h" |
33 | | #include "llvm/Support/raw_ostream.h" |
34 | | #include <algorithm> |
35 | | #include <cstring> |
36 | | using namespace clang; |
37 | | |
38 | 60.3k | const Expr *Expr::getBestDynamicClassTypeExpr() const { |
39 | 60.3k | const Expr *E = this; |
40 | 60.6k | while (true60.6k ) { |
41 | 60.6k | E = E->ignoreParenBaseCasts(); |
42 | 60.6k | |
43 | 60.6k | // Follow the RHS of a comma operator. |
44 | 60.6k | if (auto *BO60.6k = dyn_cast<BinaryOperator>(E)) { |
45 | 60 | if (BO->getOpcode() == BO_Comma60 ) { |
46 | 18 | E = BO->getRHS(); |
47 | 18 | continue; |
48 | 18 | } |
49 | 60.6k | } |
50 | 60.6k | |
51 | 60.6k | // Step into initializer for materialized temporaries. |
52 | 60.6k | if (auto *60.6k MTE60.6k = dyn_cast<MaterializeTemporaryExpr>(E)) { |
53 | 230 | E = MTE->GetTemporaryExpr(); |
54 | 230 | continue; |
55 | 230 | } |
56 | 60.3k | |
57 | 60.3k | break; |
58 | 60.3k | } |
59 | 60.3k | |
60 | 60.3k | return E; |
61 | 60.3k | } |
62 | | |
63 | 30.2k | const CXXRecordDecl *Expr::getBestDynamicClassType() const { |
64 | 30.2k | const Expr *E = getBestDynamicClassTypeExpr(); |
65 | 30.2k | QualType DerivedType = E->getType(); |
66 | 30.2k | if (const PointerType *PTy = DerivedType->getAs<PointerType>()) |
67 | 24.1k | DerivedType = PTy->getPointeeType(); |
68 | 30.2k | |
69 | 30.2k | if (DerivedType->isDependentType()) |
70 | 8 | return nullptr; |
71 | 30.2k | |
72 | 30.2k | const RecordType *Ty = DerivedType->castAs<RecordType>(); |
73 | 30.2k | Decl *D = Ty->getDecl(); |
74 | 30.2k | return cast<CXXRecordDecl>(D); |
75 | 30.2k | } |
76 | | |
77 | | const Expr *Expr::skipRValueSubobjectAdjustments( |
78 | | SmallVectorImpl<const Expr *> &CommaLHSs, |
79 | 98.9k | SmallVectorImpl<SubobjectAdjustment> &Adjustments) const { |
80 | 98.9k | const Expr *E = this; |
81 | 122k | while (true122k ) { |
82 | 122k | E = E->IgnoreParens(); |
83 | 122k | |
84 | 122k | if (const CastExpr *CE122k = dyn_cast<CastExpr>(E)) { |
85 | 28.2k | if ((CE->getCastKind() == CK_DerivedToBase || |
86 | 28.1k | CE->getCastKind() == CK_UncheckedDerivedToBase) && |
87 | 28.2k | E->getType()->isRecordType()124 ) { |
88 | 110 | E = CE->getSubExpr(); |
89 | 110 | CXXRecordDecl *Derived |
90 | 110 | = cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl()); |
91 | 110 | Adjustments.push_back(SubobjectAdjustment(CE, Derived)); |
92 | 110 | continue; |
93 | 110 | } |
94 | 28.1k | |
95 | 28.1k | if (28.1k CE->getCastKind() == CK_NoOp28.1k ) { |
96 | 22.3k | E = CE->getSubExpr(); |
97 | 22.3k | continue; |
98 | 22.3k | } |
99 | 94.1k | } else if (const MemberExpr *94.1k ME94.1k = dyn_cast<MemberExpr>(E)) { |
100 | 3.70k | if (!ME->isArrow()3.70k ) { |
101 | 1.15k | assert(ME->getBase()->getType()->isRecordType()); |
102 | 1.15k | if (FieldDecl *Field1.15k = dyn_cast<FieldDecl>(ME->getMemberDecl())) { |
103 | 1.15k | if (!Field->isBitField() && 1.15k !Field->getType()->isReferenceType()1.14k ) { |
104 | 918 | E = ME->getBase(); |
105 | 918 | Adjustments.push_back(SubobjectAdjustment(Field)); |
106 | 918 | continue; |
107 | 918 | } |
108 | 94.1k | } |
109 | 1.15k | } |
110 | 90.4k | } else if (const BinaryOperator *90.4k BO90.4k = dyn_cast<BinaryOperator>(E)) { |
111 | 119 | if (BO->isPtrMemOp()119 ) { |
112 | 10 | assert(BO->getRHS()->isRValue()); |
113 | 10 | E = BO->getLHS(); |
114 | 10 | const MemberPointerType *MPT = |
115 | 10 | BO->getRHS()->getType()->getAs<MemberPointerType>(); |
116 | 10 | Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); |
117 | 10 | continue; |
118 | 109 | } else if (109 BO->getOpcode() == BO_Comma109 ) { |
119 | 51 | CommaLHSs.push_back(BO->getLHS()); |
120 | 51 | E = BO->getRHS(); |
121 | 51 | continue; |
122 | 51 | } |
123 | 98.9k | } |
124 | 98.9k | |
125 | 98.9k | // Nothing changed. |
126 | 98.9k | break; |
127 | 98.9k | } |
128 | 98.9k | return E; |
129 | 98.9k | } |
130 | | |
131 | | /// isKnownToHaveBooleanValue - Return true if this is an integer expression |
132 | | /// that is known to return 0 or 1. This happens for _Bool/bool expressions |
133 | | /// but also int expressions which are produced by things like comparisons in |
134 | | /// C. |
135 | 765k | bool Expr::isKnownToHaveBooleanValue() const { |
136 | 765k | const Expr *E = IgnoreParens(); |
137 | 765k | |
138 | 765k | // If this value has _Bool type, it is obvious 0/1. |
139 | 765k | if (E->getType()->isBooleanType()765k ) return true796 ; |
140 | 764k | // If this is a non-scalar-integer type, we don't care enough to try. |
141 | 764k | if (764k !E->getType()->isIntegralOrEnumerationType()764k ) return false52.1k ; |
142 | 712k | |
143 | 712k | if (const UnaryOperator *712k UO712k = dyn_cast<UnaryOperator>(E)) { |
144 | 17.2k | switch (UO->getOpcode()) { |
145 | 4 | case UO_Plus: |
146 | 4 | return UO->getSubExpr()->isKnownToHaveBooleanValue(); |
147 | 118 | case UO_LNot: |
148 | 118 | return true; |
149 | 17.1k | default: |
150 | 17.1k | return false; |
151 | 695k | } |
152 | 695k | } |
153 | 695k | |
154 | 695k | // Only look through implicit casts. If the user writes |
155 | 695k | // '(int) (a && b)' treat it as an arbitrary int. |
156 | 695k | if (const ImplicitCastExpr *695k CE695k = dyn_cast<ImplicitCastExpr>(E)) |
157 | 209k | return CE->getSubExpr()->isKnownToHaveBooleanValue(); |
158 | 486k | |
159 | 486k | if (const BinaryOperator *486k BO486k = dyn_cast<BinaryOperator>(E)) { |
160 | 40.3k | switch (BO->getOpcode()) { |
161 | 23.7k | default: return false; |
162 | 115 | case BO_LT: // Relational operators. |
163 | 115 | case BO_GT: |
164 | 115 | case BO_LE: |
165 | 115 | case BO_GE: |
166 | 115 | case BO_EQ: // Equality operators. |
167 | 115 | case BO_NE: |
168 | 115 | case BO_LAnd: // AND operator. |
169 | 115 | case BO_LOr: // Logical OR operator. |
170 | 115 | return true; |
171 | 115 | |
172 | 11.0k | case BO_And: // Bitwise AND operator. |
173 | 11.0k | case BO_Xor: // Bitwise XOR operator. |
174 | 11.0k | case BO_Or: // Bitwise OR operator. |
175 | 11.0k | // Handle things like (x==2)|(y==12). |
176 | 11.0k | return BO->getLHS()->isKnownToHaveBooleanValue() && |
177 | 0 | BO->getRHS()->isKnownToHaveBooleanValue(); |
178 | 11.0k | |
179 | 5.40k | case BO_Comma: |
180 | 5.40k | case BO_Assign: |
181 | 5.40k | return BO->getRHS()->isKnownToHaveBooleanValue(); |
182 | 445k | } |
183 | 445k | } |
184 | 445k | |
185 | 445k | if (const ConditionalOperator *445k CO445k = dyn_cast<ConditionalOperator>(E)) |
186 | 558 | return CO->getTrueExpr()->isKnownToHaveBooleanValue() && |
187 | 0 | CO->getFalseExpr()->isKnownToHaveBooleanValue(); |
188 | 445k | |
189 | 445k | return false; |
190 | 445k | } |
191 | | |
192 | | // Amusing macro metaprogramming hack: check whether a class provides |
193 | | // a more specific implementation of getExprLoc(). |
194 | | // |
195 | | // See also Stmt.cpp:{getLocStart(),getLocEnd()}. |
196 | | namespace { |
197 | | /// This implementation is used when a class provides a custom |
198 | | /// implementation of getExprLoc. |
199 | | template <class E, class T> |
200 | | SourceLocation getExprLocImpl(const Expr *expr, |
201 | 16.6M | SourceLocation (T::*v)() const) { |
202 | 16.6M | return static_cast<const E*>(expr)->getExprLoc(); |
203 | 16.6M | } Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnaryOperator, clang::UnaryOperator>(clang::Expr const*, clang::SourceLocation (clang::UnaryOperator::*)() const) Line | Count | Source | 201 | 2.44M | SourceLocation (T::*v)() const) { | 202 | 2.44M | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 2.44M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PseudoObjectExpr, clang::PseudoObjectExpr>(clang::Expr const*, clang::SourceLocation (clang::PseudoObjectExpr::*)() const) Line | Count | Source | 201 | 6.65k | SourceLocation (T::*v)() const) { | 202 | 6.65k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 6.65k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnresolvedMemberExpr, clang::UnresolvedMemberExpr>(clang::Expr const*, clang::SourceLocation (clang::UnresolvedMemberExpr::*)() const) Line | Count | Source | 201 | 21.7k | SourceLocation (T::*v)() const) { | 202 | 21.7k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 21.7k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OpaqueValueExpr, clang::OpaqueValueExpr>(clang::Expr const*, clang::SourceLocation (clang::OpaqueValueExpr::*)() const) Line | Count | Source | 201 | 22.9k | SourceLocation (T::*v)() const) { | 202 | 22.9k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 22.9k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIsaExpr, clang::ObjCIsaExpr>(clang::Expr const*, clang::SourceLocation (clang::ObjCIsaExpr::*)() const) Line | Count | Source | 201 | 158 | SourceLocation (T::*v)() const) { | 202 | 158 | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 158 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIndirectCopyRestoreExpr, clang::ObjCIndirectCopyRestoreExpr>(clang::Expr const*, clang::SourceLocation (clang::ObjCIndirectCopyRestoreExpr::*)() const) Line | Count | Source | 201 | 95 | SourceLocation (T::*v)() const) { | 202 | 95 | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 95 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPArraySectionExpr, clang::OMPArraySectionExpr>(clang::Expr const*, clang::SourceLocation (clang::OMPArraySectionExpr::*)() const) Line | Count | Source | 201 | 6.09k | SourceLocation (T::*v)() const) { | 202 | 6.09k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 6.09k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MemberExpr, clang::MemberExpr>(clang::Expr const*, clang::SourceLocation (clang::MemberExpr::*)() const) Line | Count | Source | 201 | 4.11M | SourceLocation (T::*v)() const) { | 202 | 4.11M | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 4.11M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MSPropertySubscriptExpr, clang::MSPropertySubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::MSPropertySubscriptExpr::*)() const) Line | Count | Source | 201 | 396 | SourceLocation (T::*v)() const) { | 202 | 396 | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 396 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXOperatorCallExpr, clang::CXXOperatorCallExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXOperatorCallExpr::*)() const) Line | Count | Source | 201 | 394k | SourceLocation (T::*v)() const) { | 202 | 394k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 394k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXMemberCallExpr, clang::CXXMemberCallExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXMemberCallExpr::*)() const) Line | Count | Source | 201 | 788k | SourceLocation (T::*v)() const) { | 202 | 788k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 788k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDefaultArgExpr, clang::CXXDefaultArgExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXDefaultArgExpr::*)() const) Line | Count | Source | 201 | 13.7k | SourceLocation (T::*v)() const) { | 202 | 13.7k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 13.7k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CompoundAssignOperator, clang::BinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::BinaryOperator::*)() const) Line | Count | Source | 201 | 286k | SourceLocation (T::*v)() const) { | 202 | 286k | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 286k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BinaryOperator, clang::BinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::BinaryOperator::*)() const) Line | Count | Source | 201 | 6.75M | SourceLocation (T::*v)() const) { | 202 | 6.75M | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 6.75M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArraySubscriptExpr, clang::ArraySubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::ArraySubscriptExpr::*)() const) Line | Count | Source | 201 | 1.80M | SourceLocation (T::*v)() const) { | 202 | 1.80M | return static_cast<const E*>(expr)->getExprLoc(); | 203 | 1.80M | } |
|
204 | | |
205 | | /// This implementation is used when a class doesn't provide |
206 | | /// a custom implementation of getExprLoc. Overload resolution |
207 | | /// should pick it over the implementation above because it's |
208 | | /// more specialized according to function template partial ordering. |
209 | | template <class E> |
210 | | SourceLocation getExprLocImpl(const Expr *expr, |
211 | 48.9M | SourceLocation (Expr::*v)() const) { |
212 | 48.9M | return static_cast<const E*>(expr)->getLocStart(); |
213 | 48.9M | } Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDependentScopeMemberExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 212 | SourceLocation (Expr::*v)() const) { | 212 | 212 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 212 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXFoldExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 40 | SourceLocation (Expr::*v)() const) { | 212 | 40 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 40 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXInheritedCtorInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 137 | SourceLocation (Expr::*v)() const) { | 212 | 137 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 137 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNewExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 16.0k | SourceLocation (Expr::*v)() const) { | 212 | 16.0k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 16.0k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNoexceptExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 683 | SourceLocation (Expr::*v)() const) { | 212 | 683 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 683 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNullPtrLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 32.0k | SourceLocation (Expr::*v)() const) { | 212 | 32.0k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 32.0k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXPseudoDestructorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 218 | SourceLocation (Expr::*v)() const) { | 212 | 218 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 218 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXScalarValueInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 2.23k | SourceLocation (Expr::*v)() const) { | 212 | 2.23k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 2.23k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXStdInitializerListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 1.31k | SourceLocation (Expr::*v)() const) { | 212 | 1.31k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 1.31k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXThisExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 477k | SourceLocation (Expr::*v)() const) { | 212 | 477k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 477k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXThrowExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 3.29k | SourceLocation (Expr::*v)() const) { | 212 | 3.29k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 3.29k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXTypeidExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 808 | SourceLocation (Expr::*v)() const) { | 212 | 808 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 808 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXUnresolvedConstructExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 147 | SourceLocation (Expr::*v)() const) { | 212 | 147 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 147 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXUuidofExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 185 | SourceLocation (Expr::*v)() const) { | 212 | 185 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 185 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CallExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 5.56M | SourceLocation (Expr::*v)() const) { | 212 | 5.56M | return static_cast<const E*>(expr)->getLocStart(); | 213 | 5.56M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CUDAKernelCallExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 70 | SourceLocation (Expr::*v)() const) { | 212 | 70 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 70 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UserDefinedLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 3.11k | SourceLocation (Expr::*v)() const) { | 212 | 3.11k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 3.11k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CStyleCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 1.92M | SourceLocation (Expr::*v)() const) { | 212 | 1.92M | return static_cast<const E*>(expr)->getLocStart(); | 213 | 1.92M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXFunctionalCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 16.3k | SourceLocation (Expr::*v)() const) { | 212 | 16.3k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 16.3k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXConstCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 399 | SourceLocation (Expr::*v)() const) { | 212 | 399 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 399 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDynamicCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 2.01k | SourceLocation (Expr::*v)() const) { | 212 | 2.01k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 2.01k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXReinterpretCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 2.01k | SourceLocation (Expr::*v)() const) { | 212 | 2.01k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 2.01k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXStaticCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 1.70k | SourceLocation (Expr::*v)() const) { | 212 | 1.70k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 1.70k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBridgedCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 235 | SourceLocation (Expr::*v)() const) { | 212 | 235 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 235 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImplicitCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 9.12M | SourceLocation (Expr::*v)() const) { | 212 | 9.12M | return static_cast<const E*>(expr)->getLocStart(); | 213 | 9.12M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CharacterLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 139k | SourceLocation (Expr::*v)() const) { | 212 | 139k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 139k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ChooseExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 22 | SourceLocation (Expr::*v)() const) { | 212 | 22 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 22 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CompoundLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 51.5k | SourceLocation (Expr::*v)() const) { | 212 | 51.5k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 51.5k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConvertVectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 6.91k | SourceLocation (Expr::*v)() const) { | 212 | 6.91k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 6.91k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CoawaitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 931 | SourceLocation (Expr::*v)() const) { | 212 | 931 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 931 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CoyieldExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 111 | SourceLocation (Expr::*v)() const) { | 212 | 111 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 111 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DeclRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 19.0M | SourceLocation (Expr::*v)() const) { | 212 | 19.0M | return static_cast<const E*>(expr)->getLocStart(); | 213 | 19.0M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DependentCoawaitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 30 | SourceLocation (Expr::*v)() const) { | 212 | 30 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 30 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DependentScopeDeclRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 124 | SourceLocation (Expr::*v)() const) { | 212 | 124 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 124 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DesignatedInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 5 | SourceLocation (Expr::*v)() const) { | 212 | 5 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 5 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DesignatedInitUpdateExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 38 | SourceLocation (Expr::*v)() const) { | 212 | 38 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 38 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExprWithCleanups>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 25.0k | SourceLocation (Expr::*v)() const) { | 212 | 25.0k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 25.0k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExpressionTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 5 | SourceLocation (Expr::*v)() const) { | 212 | 5 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 5 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExtVectorElementExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 1.26k | SourceLocation (Expr::*v)() const) { | 212 | 1.26k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 1.26k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FloatingLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 611k | SourceLocation (Expr::*v)() const) { | 212 | 611k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 611k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FunctionParmPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 70 | SourceLocation (Expr::*v)() const) { | 212 | 70 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 70 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::GNUNullExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 8.48k | SourceLocation (Expr::*v)() const) { | 212 | 8.48k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 8.48k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::GenericSelectionExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 85 | SourceLocation (Expr::*v)() const) { | 212 | 85 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 85 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImaginaryLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 599 | SourceLocation (Expr::*v)() const) { | 212 | 599 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 599 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImplicitValueInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 14.5k | SourceLocation (Expr::*v)() const) { | 212 | 14.5k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 14.5k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::InitListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 117k | SourceLocation (Expr::*v)() const) { | 212 | 117k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 117k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::IntegerLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 7.91M | SourceLocation (Expr::*v)() const) { | 212 | 7.91M | return static_cast<const E*>(expr)->getLocStart(); | 213 | 7.91M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::LambdaExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 13.8k | SourceLocation (Expr::*v)() const) { | 212 | 13.8k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 13.8k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MSPropertyRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 590 | SourceLocation (Expr::*v)() const) { | 212 | 590 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 590 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MaterializeTemporaryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 7.83k | SourceLocation (Expr::*v)() const) { | 212 | 7.83k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 7.83k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::NoInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 51 | SourceLocation (Expr::*v)() const) { | 212 | 51 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 51 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCArrayLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 384 | SourceLocation (Expr::*v)() const) { | 212 | 384 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 384 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCAvailabilityCheckExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 181 | SourceLocation (Expr::*v)() const) { | 212 | 181 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 181 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBoolLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 518 | SourceLocation (Expr::*v)() const) { | 212 | 518 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 518 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBoxedExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 1.62k | SourceLocation (Expr::*v)() const) { | 212 | 1.62k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 1.62k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCDictionaryLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 250 | SourceLocation (Expr::*v)() const) { | 212 | 250 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 250 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCEncodeExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 150 | SourceLocation (Expr::*v)() const) { | 212 | 150 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 150 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIvarRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 3.79k | SourceLocation (Expr::*v)() const) { | 212 | 3.79k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 3.79k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCMessageExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 37.9k | SourceLocation (Expr::*v)() const) { | 212 | 37.9k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 37.9k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCPropertyRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 5.35k | SourceLocation (Expr::*v)() const) { | 212 | 5.35k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 5.35k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCProtocolExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 165 | SourceLocation (Expr::*v)() const) { | 212 | 165 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 165 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCSelectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 415 | SourceLocation (Expr::*v)() const) { | 212 | 415 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 415 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCStringLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 3.80k | SourceLocation (Expr::*v)() const) { | 212 | 3.80k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 3.80k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCSubscriptRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 470 | SourceLocation (Expr::*v)() const) { | 212 | 470 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 470 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OffsetOfExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 905 | SourceLocation (Expr::*v)() const) { | 212 | 905 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 905 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnresolvedLookupExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 680k | SourceLocation (Expr::*v)() const) { | 212 | 680k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 680k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PackExpansionExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 5 | SourceLocation (Expr::*v)() const) { | 212 | 5 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 5 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ParenExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 1.18M | SourceLocation (Expr::*v)() const) { | 212 | 1.18M | return static_cast<const E*>(expr)->getLocStart(); | 213 | 1.18M | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ParenListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 588 | SourceLocation (Expr::*v)() const) { | 212 | 588 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 588 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PredefinedExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 4.35k | SourceLocation (Expr::*v)() const) { | 212 | 4.35k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 4.35k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ShuffleVectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 114k | SourceLocation (Expr::*v)() const) { | 212 | 114k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 114k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SizeOfPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 895 | SourceLocation (Expr::*v)() const) { | 212 | 895 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 895 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::StmtExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 39.6k | SourceLocation (Expr::*v)() const) { | 212 | 39.6k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 39.6k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::StringLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 873k | SourceLocation (Expr::*v)() const) { | 212 | 873k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 873k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SubstNonTypeTemplateParmExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 32.5k | SourceLocation (Expr::*v)() const) { | 212 | 32.5k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 32.5k | } |
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 | 211 | 2.21k | SourceLocation (Expr::*v)() const) { | 212 | 2.21k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 2.21k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::TypoExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 29 | SourceLocation (Expr::*v)() const) { | 212 | 29 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 29 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnaryExprOrTypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 232k | SourceLocation (Expr::*v)() const) { | 212 | 232k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 232k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::VAArgExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 2.75k | SourceLocation (Expr::*v)() const) { | 212 | 2.75k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 2.75k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BinaryConditionalOperator>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 301 | SourceLocation (Expr::*v)() const) { | 212 | 301 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 301 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConditionalOperator>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 89.4k | SourceLocation (Expr::*v)() const) { | 212 | 89.4k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 89.4k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDeleteExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 15.5k | SourceLocation (Expr::*v)() const) { | 212 | 15.5k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 15.5k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDefaultInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 234 | SourceLocation (Expr::*v)() const) { | 212 | 234 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 234 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXTemporaryObjectExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 127k | SourceLocation (Expr::*v)() const) { | 212 | 127k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 127k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXConstructExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 137k | SourceLocation (Expr::*v)() const) { | 212 | 137k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 137k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXBoolLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 161k | SourceLocation (Expr::*v)() const) { | 212 | 161k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 161k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXBindTemporaryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 16.9k | SourceLocation (Expr::*v)() const) { | 212 | 16.9k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 16.9k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BlockExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 3.92k | SourceLocation (Expr::*v)() const) { | 212 | 3.92k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 3.92k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AtomicExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 7.13k | SourceLocation (Expr::*v)() const) { | 212 | 7.13k | return static_cast<const E*>(expr)->getLocStart(); | 213 | 7.13k | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AsTypeExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 57 | SourceLocation (Expr::*v)() const) { | 212 | 57 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 57 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayTypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 6 | SourceLocation (Expr::*v)() const) { | 212 | 6 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 6 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayInitLoopExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 50 | SourceLocation (Expr::*v)() const) { | 212 | 50 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 50 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayInitIndexExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 40 | SourceLocation (Expr::*v)() const) { | 212 | 40 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 40 | } |
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AddrLabelExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const) Line | Count | Source | 211 | 601 | SourceLocation (Expr::*v)() const) { | 212 | 601 | return static_cast<const E*>(expr)->getLocStart(); | 213 | 601 | } |
|
214 | | } |
215 | | |
216 | 65.6M | SourceLocation Expr::getExprLoc() const { |
217 | 65.6M | switch (getStmtClass()) { |
218 | 0 | case Stmt::NoStmtClass: 0 llvm_unreachable0 ("statement without class"); |
219 | 65.6M | #define ABSTRACT_STMT(type) |
220 | 65.6M | #define STMT(type, base) \ |
221 | 0 | case Stmt::type##Class: break; |
222 | 65.6M | #define EXPR(type, base) \ |
223 | 65.6M | case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc); |
224 | 0 | #include "clang/AST/StmtNodes.inc" |
225 | 65.6M | } |
226 | 0 | llvm_unreachable0 ("unknown expression kind"); |
227 | 0 | } |
228 | | |
229 | | //===----------------------------------------------------------------------===// |
230 | | // Primary Expressions. |
231 | | //===----------------------------------------------------------------------===// |
232 | | |
233 | | /// \brief Compute the type-, value-, and instantiation-dependence of a |
234 | | /// declaration reference |
235 | | /// based on the declaration being referenced. |
236 | | static void computeDeclRefDependence(const ASTContext &Ctx, NamedDecl *D, |
237 | | QualType T, bool &TypeDependent, |
238 | | bool &ValueDependent, |
239 | 10.6M | bool &InstantiationDependent) { |
240 | 10.6M | TypeDependent = false; |
241 | 10.6M | ValueDependent = false; |
242 | 10.6M | InstantiationDependent = false; |
243 | 10.6M | |
244 | 10.6M | // (TD) C++ [temp.dep.expr]p3: |
245 | 10.6M | // An id-expression is type-dependent if it contains: |
246 | 10.6M | // |
247 | 10.6M | // and |
248 | 10.6M | // |
249 | 10.6M | // (VD) C++ [temp.dep.constexpr]p2: |
250 | 10.6M | // An identifier is value-dependent if it is: |
251 | 10.6M | |
252 | 10.6M | // (TD) - an identifier that was declared with dependent type |
253 | 10.6M | // (VD) - a name declared with a dependent type, |
254 | 10.6M | if (T->isDependentType()10.6M ) { |
255 | 256k | TypeDependent = true; |
256 | 256k | ValueDependent = true; |
257 | 256k | InstantiationDependent = true; |
258 | 256k | return; |
259 | 10.4M | } else if (10.4M T->isInstantiationDependentType()10.4M ) { |
260 | 18 | InstantiationDependent = true; |
261 | 18 | } |
262 | 10.6M | |
263 | 10.6M | // (TD) - a conversion-function-id that specifies a dependent type |
264 | 10.4M | if (10.4M D->getDeclName().getNameKind() |
265 | 10.4M | == DeclarationName::CXXConversionFunctionName) { |
266 | 1.80M | QualType T = D->getDeclName().getCXXNameType(); |
267 | 1.80M | if (T->isDependentType()1.80M ) { |
268 | 0 | TypeDependent = true; |
269 | 0 | ValueDependent = true; |
270 | 0 | InstantiationDependent = true; |
271 | 0 | return; |
272 | 0 | } |
273 | 1.80M | |
274 | 1.80M | if (1.80M T->isInstantiationDependentType()1.80M ) |
275 | 0 | InstantiationDependent = true; |
276 | 1.80M | } |
277 | 10.4M | |
278 | 10.4M | // (VD) - the name of a non-type template parameter, |
279 | 10.4M | if (10.4M isa<NonTypeTemplateParmDecl>(D)10.4M ) { |
280 | 48.2k | ValueDependent = true; |
281 | 48.2k | InstantiationDependent = true; |
282 | 48.2k | return; |
283 | 48.2k | } |
284 | 10.3M | |
285 | 10.3M | // (VD) - a constant with integral or enumeration type and is |
286 | 10.3M | // initialized with an expression that is value-dependent. |
287 | 10.3M | // (VD) - a constant with literal type and is initialized with an |
288 | 10.3M | // expression that is value-dependent [C++11]. |
289 | 10.3M | // (VD) - FIXME: Missing from the standard: |
290 | 10.3M | // - an entity with reference type and is initialized with an |
291 | 10.3M | // expression that is value-dependent [C++11] |
292 | 10.3M | if (VarDecl *10.3M Var10.3M = dyn_cast<VarDecl>(D)) { |
293 | 6.70M | if ((Ctx.getLangOpts().CPlusPlus11 ? |
294 | 857k | Var->getType()->isLiteralType(Ctx) : |
295 | 5.84M | Var->getType()->isIntegralOrEnumerationType()) && |
296 | 2.94M | (Var->getType().isConstQualified() || |
297 | 6.70M | Var->getType()->isReferenceType()2.82M )) { |
298 | 132k | if (const Expr *Init = Var->getAnyInitializer()) |
299 | 116k | if (116k Init->isValueDependent()116k ) { |
300 | 39.3k | ValueDependent = true; |
301 | 39.3k | InstantiationDependent = true; |
302 | 39.3k | } |
303 | 132k | } |
304 | 6.70M | |
305 | 6.70M | // (VD) - FIXME: Missing from the standard: |
306 | 6.70M | // - a member function or a static data member of the current |
307 | 6.70M | // instantiation |
308 | 6.70M | if (Var->isStaticDataMember() && |
309 | 6.70M | Var->getDeclContext()->isDependentContext()40.7k ) { |
310 | 33.5k | ValueDependent = true; |
311 | 33.5k | InstantiationDependent = true; |
312 | 33.5k | TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo(); |
313 | 33.5k | if (TInfo->getType()->isIncompleteArrayType()) |
314 | 18 | TypeDependent = true; |
315 | 33.5k | } |
316 | 6.70M | |
317 | 6.70M | return; |
318 | 6.70M | } |
319 | 3.68M | |
320 | 3.68M | // (VD) - FIXME: Missing from the standard: |
321 | 3.68M | // - a member function or a static data member of the current |
322 | 3.68M | // instantiation |
323 | 3.68M | if (3.68M isa<CXXMethodDecl>(D) && 3.68M D->getDeclContext()->isDependentContext()1.89M ) { |
324 | 6.73k | ValueDependent = true; |
325 | 6.73k | InstantiationDependent = true; |
326 | 6.73k | } |
327 | 10.6M | } |
328 | | |
329 | 10.6M | void DeclRefExpr::computeDependence(const ASTContext &Ctx) { |
330 | 10.6M | bool TypeDependent = false; |
331 | 10.6M | bool ValueDependent = false; |
332 | 10.6M | bool InstantiationDependent = false; |
333 | 10.6M | computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent, |
334 | 10.6M | ValueDependent, InstantiationDependent); |
335 | 10.6M | |
336 | 10.6M | ExprBits.TypeDependent |= TypeDependent; |
337 | 10.6M | ExprBits.ValueDependent |= ValueDependent; |
338 | 10.6M | ExprBits.InstantiationDependent |= InstantiationDependent; |
339 | 10.6M | |
340 | 10.6M | // Is the declaration a parameter pack? |
341 | 10.6M | if (getDecl()->isParameterPack()) |
342 | 1.14k | ExprBits.ContainsUnexpandedParameterPack = true; |
343 | 10.6M | } |
344 | | |
345 | | DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, |
346 | | NestedNameSpecifierLoc QualifierLoc, |
347 | | SourceLocation TemplateKWLoc, |
348 | | ValueDecl *D, bool RefersToEnclosingVariableOrCapture, |
349 | | const DeclarationNameInfo &NameInfo, |
350 | | NamedDecl *FoundD, |
351 | | const TemplateArgumentListInfo *TemplateArgs, |
352 | | QualType T, ExprValueKind VK) |
353 | | : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), |
354 | 8.72M | D(D), Loc(NameInfo.getLoc()), DNLoc(NameInfo.getInfo()) { |
355 | 8.72M | DeclRefExprBits.HasQualifier = QualifierLoc ? 157.7k : 08.66M ; |
356 | 8.72M | if (QualifierLoc8.72M ) { |
357 | 57.7k | new (getTrailingObjects<NestedNameSpecifierLoc>()) |
358 | 57.7k | NestedNameSpecifierLoc(QualifierLoc); |
359 | 57.7k | auto *NNS = QualifierLoc.getNestedNameSpecifier(); |
360 | 57.7k | if (NNS->isInstantiationDependent()) |
361 | 49 | ExprBits.InstantiationDependent = true; |
362 | 57.7k | if (NNS->containsUnexpandedParameterPack()) |
363 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
364 | 57.7k | } |
365 | 8.72M | DeclRefExprBits.HasFoundDecl = FoundD ? 128.2k : 08.69M ; |
366 | 8.72M | if (FoundD) |
367 | 28.2k | *getTrailingObjects<NamedDecl *>() = FoundD; |
368 | 8.72M | DeclRefExprBits.HasTemplateKWAndArgsInfo |
369 | 8.72M | = (TemplateArgs || TemplateKWLoc.isValid()8.71M ) ? 17.56k : 08.71M ; |
370 | 8.72M | DeclRefExprBits.RefersToEnclosingVariableOrCapture = |
371 | 8.72M | RefersToEnclosingVariableOrCapture; |
372 | 8.72M | if (TemplateArgs8.72M ) { |
373 | 7.56k | bool Dependent = false; |
374 | 7.56k | bool InstantiationDependent = false; |
375 | 7.56k | bool ContainsUnexpandedParameterPack = false; |
376 | 7.56k | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
377 | 7.56k | TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(), |
378 | 7.56k | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
379 | 7.56k | assert(!Dependent && "built a DeclRefExpr with dependent template args"); |
380 | 7.56k | ExprBits.InstantiationDependent |= InstantiationDependent; |
381 | 7.56k | ExprBits.ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack; |
382 | 8.72M | } else if (8.71M TemplateKWLoc.isValid()8.71M ) { |
383 | 6 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
384 | 6 | TemplateKWLoc); |
385 | 6 | } |
386 | 8.72M | DeclRefExprBits.HadMultipleCandidates = 0; |
387 | 8.72M | |
388 | 8.72M | computeDependence(Ctx); |
389 | 8.72M | } |
390 | | |
391 | | DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, |
392 | | NestedNameSpecifierLoc QualifierLoc, |
393 | | SourceLocation TemplateKWLoc, |
394 | | ValueDecl *D, |
395 | | bool RefersToEnclosingVariableOrCapture, |
396 | | SourceLocation NameLoc, |
397 | | QualType T, |
398 | | ExprValueKind VK, |
399 | | NamedDecl *FoundD, |
400 | 503k | const TemplateArgumentListInfo *TemplateArgs) { |
401 | 503k | return Create(Context, QualifierLoc, TemplateKWLoc, D, |
402 | 503k | RefersToEnclosingVariableOrCapture, |
403 | 503k | DeclarationNameInfo(D->getDeclName(), NameLoc), |
404 | 503k | T, VK, FoundD, TemplateArgs); |
405 | 503k | } |
406 | | |
407 | | DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context, |
408 | | NestedNameSpecifierLoc QualifierLoc, |
409 | | SourceLocation TemplateKWLoc, |
410 | | ValueDecl *D, |
411 | | bool RefersToEnclosingVariableOrCapture, |
412 | | const DeclarationNameInfo &NameInfo, |
413 | | QualType T, |
414 | | ExprValueKind VK, |
415 | | NamedDecl *FoundD, |
416 | 8.72M | const TemplateArgumentListInfo *TemplateArgs) { |
417 | 8.72M | // Filter out cases where the found Decl is the same as the value refenenced. |
418 | 8.72M | if (D == FoundD) |
419 | 8.18M | FoundD = nullptr; |
420 | 8.72M | |
421 | 8.71M | bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid(); |
422 | 8.72M | std::size_t Size = |
423 | 8.72M | totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *, |
424 | 8.72M | ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
425 | 8.72M | QualifierLoc ? 157.7k : 08.66M , FoundD ? 128.2k : 08.69M , |
426 | 8.72M | HasTemplateKWAndArgsInfo ? 17.56k : 08.71M , |
427 | 8.72M | TemplateArgs ? TemplateArgs->size()7.56k : 08.71M ); |
428 | 8.72M | |
429 | 8.72M | void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); |
430 | 8.72M | return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, |
431 | 8.72M | RefersToEnclosingVariableOrCapture, |
432 | 8.72M | NameInfo, FoundD, TemplateArgs, T, VK); |
433 | 8.72M | } |
434 | | |
435 | | DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext &Context, |
436 | | bool HasQualifier, |
437 | | bool HasFoundDecl, |
438 | | bool HasTemplateKWAndArgsInfo, |
439 | 27.3k | unsigned NumTemplateArgs) { |
440 | 27.3k | assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo); |
441 | 27.3k | std::size_t Size = |
442 | 27.3k | totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *, |
443 | 27.3k | ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>( |
444 | 27.3k | HasQualifier ? 1146 : 027.1k , HasFoundDecl ? 1304 : 027.0k , HasTemplateKWAndArgsInfo, |
445 | 27.3k | NumTemplateArgs); |
446 | 27.3k | void *Mem = Context.Allocate(Size, alignof(DeclRefExpr)); |
447 | 27.3k | return new (Mem) DeclRefExpr(EmptyShell()); |
448 | 27.3k | } |
449 | | |
450 | 64.6M | SourceLocation DeclRefExpr::getLocStart() const { |
451 | 64.6M | if (hasQualifier()) |
452 | 675k | return getQualifierLoc().getBeginLoc(); |
453 | 63.9M | return getNameInfo().getLocStart(); |
454 | 63.9M | } |
455 | 4.44M | SourceLocation DeclRefExpr::getLocEnd() const { |
456 | 4.44M | if (hasExplicitTemplateArgs()) |
457 | 6.86k | return getRAngleLoc(); |
458 | 4.43M | return getNameInfo().getLocEnd(); |
459 | 4.43M | } |
460 | | |
461 | | PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentType IT, |
462 | | StringLiteral *SL) |
463 | | : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary, |
464 | | FNTy->isDependentType(), FNTy->isDependentType(), |
465 | | FNTy->isInstantiationDependentType(), |
466 | | /*ContainsUnexpandedParameterPack=*/false), |
467 | 1.29k | Loc(L), Type(IT), FnName(SL) {} |
468 | | |
469 | 1.13k | StringLiteral *PredefinedExpr::getFunctionName() { |
470 | 1.13k | return cast_or_null<StringLiteral>(FnName); |
471 | 1.13k | } |
472 | | |
473 | 1.13k | StringRef PredefinedExpr::getIdentTypeName(PredefinedExpr::IdentType IT) { |
474 | 1.13k | switch (IT) { |
475 | 877 | case Func: |
476 | 877 | return "__func__"; |
477 | 146 | case Function: |
478 | 146 | return "__FUNCTION__"; |
479 | 0 | case FuncDName: |
480 | 0 | return "__FUNCDNAME__"; |
481 | 1 | case LFunction: |
482 | 1 | return "L__FUNCTION__"; |
483 | 102 | case PrettyFunction: |
484 | 102 | return "__PRETTY_FUNCTION__"; |
485 | 9 | case FuncSig: |
486 | 9 | return "__FUNCSIG__"; |
487 | 0 | case PrettyFunctionNoVirtual: |
488 | 0 | break; |
489 | 0 | } |
490 | 0 | llvm_unreachable0 ("Unknown ident type for PredefinedExpr"); |
491 | 0 | } |
492 | | |
493 | | // FIXME: Maybe this should use DeclPrinter with a special "print predefined |
494 | | // expr" policy instead. |
495 | 3.02k | std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { |
496 | 3.02k | ASTContext &Context = CurrentDecl->getASTContext(); |
497 | 3.02k | |
498 | 3.02k | if (IT == PredefinedExpr::FuncDName3.02k ) { |
499 | 5 | if (const NamedDecl *ND5 = dyn_cast<NamedDecl>(CurrentDecl)) { |
500 | 5 | std::unique_ptr<MangleContext> MC; |
501 | 5 | MC.reset(Context.createMangleContext()); |
502 | 5 | |
503 | 5 | if (MC->shouldMangleDeclName(ND)5 ) { |
504 | 4 | SmallString<256> Buffer; |
505 | 4 | llvm::raw_svector_ostream Out(Buffer); |
506 | 4 | if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND)) |
507 | 1 | MC->mangleCXXCtor(CD, Ctor_Base, Out); |
508 | 3 | else if (const CXXDestructorDecl *3 DD3 = dyn_cast<CXXDestructorDecl>(ND)) |
509 | 1 | MC->mangleCXXDtor(DD, Dtor_Base, Out); |
510 | 3 | else |
511 | 2 | MC->mangleName(ND, Out); |
512 | 4 | |
513 | 4 | if (!Buffer.empty() && 4 Buffer.front() == '\01'4 ) |
514 | 4 | return Buffer.substr(1); |
515 | 0 | return Buffer.str(); |
516 | 0 | } else |
517 | 1 | return ND->getIdentifier()->getName(); |
518 | 0 | } |
519 | 0 | return ""; |
520 | 0 | } |
521 | 3.02k | if (3.02k isa<BlockDecl>(CurrentDecl)3.02k ) { |
522 | 43 | // For blocks we only emit something if it is enclosed in a function |
523 | 43 | // For top-level block we'd like to include the name of variable, but we |
524 | 43 | // don't have it at this point. |
525 | 43 | auto DC = CurrentDecl->getDeclContext(); |
526 | 43 | if (DC->isFileContext()) |
527 | 5 | return ""; |
528 | 38 | |
529 | 38 | SmallString<256> Buffer; |
530 | 38 | llvm::raw_svector_ostream Out(Buffer); |
531 | 38 | if (auto *DCBlock = dyn_cast<BlockDecl>(DC)) |
532 | 38 | // For nested blocks, propagate up to the parent. |
533 | 5 | Out << ComputeName(IT, DCBlock); |
534 | 33 | else if (auto *33 DCDecl33 = dyn_cast<Decl>(DC)) |
535 | 33 | Out << ComputeName(IT, DCDecl) << "_block_invoke"; |
536 | 43 | return Out.str(); |
537 | 43 | } |
538 | 2.98k | if (const FunctionDecl *2.98k FD2.98k = dyn_cast<FunctionDecl>(CurrentDecl)) { |
539 | 2.85k | if (IT != PrettyFunction && 2.85k IT != PrettyFunctionNoVirtual2.75k && IT != FuncSig1.02k ) |
540 | 1.01k | return FD->getNameAsString(); |
541 | 1.84k | |
542 | 1.84k | SmallString<256> Name; |
543 | 1.84k | llvm::raw_svector_ostream Out(Name); |
544 | 1.84k | |
545 | 1.84k | if (const CXXMethodDecl *MD1.84k = dyn_cast<CXXMethodDecl>(FD)) { |
546 | 1.78k | if (MD->isVirtual() && 1.78k IT != PrettyFunctionNoVirtual1.72k ) |
547 | 2 | Out << "virtual "; |
548 | 1.78k | if (MD->isStatic()) |
549 | 2 | Out << "static "; |
550 | 1.78k | } |
551 | 1.84k | |
552 | 1.84k | PrintingPolicy Policy(Context.getLangOpts()); |
553 | 1.84k | std::string Proto; |
554 | 1.84k | llvm::raw_string_ostream POut(Proto); |
555 | 1.84k | |
556 | 1.84k | const FunctionDecl *Decl = FD; |
557 | 1.84k | if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) |
558 | 30 | Decl = Pattern; |
559 | 1.84k | const FunctionType *AFT = Decl->getType()->getAs<FunctionType>(); |
560 | 1.84k | const FunctionProtoType *FT = nullptr; |
561 | 1.84k | if (FD->hasWrittenPrototype()) |
562 | 1.81k | FT = dyn_cast<FunctionProtoType>(AFT); |
563 | 1.84k | |
564 | 1.84k | if (IT == FuncSig1.84k ) { |
565 | 9 | switch (AFT->getCallConv()) { |
566 | 7 | case CC_C: POut << "__cdecl "; break; |
567 | 0 | case CC_X86StdCall: POut << "__stdcall "; break; |
568 | 0 | case CC_X86FastCall: POut << "__fastcall "; break; |
569 | 2 | case CC_X86ThisCall: POut << "__thiscall "; break; |
570 | 0 | case CC_X86VectorCall: POut << "__vectorcall "; break; |
571 | 0 | case CC_X86RegCall: POut << "__regcall "; break; |
572 | 9 | // Only bother printing the conventions that MSVC knows about. |
573 | 0 | default: break; |
574 | 1.84k | } |
575 | 1.84k | } |
576 | 1.84k | |
577 | 1.84k | FD->printQualifiedName(POut, Policy); |
578 | 1.84k | |
579 | 1.84k | POut << "("; |
580 | 1.84k | if (FT1.84k ) { |
581 | 1.94k | for (unsigned i = 0, e = Decl->getNumParams(); i != e1.94k ; ++i133 ) { |
582 | 133 | if (i133 ) POut << ", "10 ; |
583 | 133 | POut << Decl->getParamDecl(i)->getType().stream(Policy); |
584 | 133 | } |
585 | 1.81k | |
586 | 1.81k | if (FT->isVariadic()1.81k ) { |
587 | 4 | if (FD->getNumParams()4 ) POut << ", "3 ; |
588 | 4 | POut << "..."; |
589 | 1.81k | } else if (1.81k (IT == FuncSig || 1.81k !Context.getLangOpts().CPlusPlus1.80k ) && |
590 | 1.81k | !Decl->getNumParams()8 ) { |
591 | 3 | POut << "void"; |
592 | 3 | } |
593 | 1.81k | } |
594 | 1.84k | POut << ")"; |
595 | 1.84k | |
596 | 1.84k | if (const CXXMethodDecl *MD1.84k = dyn_cast<CXXMethodDecl>(FD)) { |
597 | 1.78k | assert(FT && "We must have a written prototype in this case."); |
598 | 1.78k | if (FT->isConst()) |
599 | 17 | POut << " const"; |
600 | 1.78k | if (FT->isVolatile()) |
601 | 2 | POut << " volatile"; |
602 | 1.78k | RefQualifierKind Ref = MD->getRefQualifier(); |
603 | 1.78k | if (Ref == RQ_LValue) |
604 | 1 | POut << " &"; |
605 | 1.78k | else if (1.78k Ref == RQ_RValue1.78k ) |
606 | 1 | POut << " &&"; |
607 | 1.78k | } |
608 | 1.84k | |
609 | 1.84k | typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy; |
610 | 1.84k | SpecsTy Specs; |
611 | 1.84k | const DeclContext *Ctx = FD->getDeclContext(); |
612 | 5.10k | while (Ctx && 5.10k isa<NamedDecl>(Ctx)5.10k ) { |
613 | 3.26k | const ClassTemplateSpecializationDecl *Spec |
614 | 3.26k | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); |
615 | 3.26k | if (Spec && 3.26k !Spec->isExplicitSpecialization()12 ) |
616 | 11 | Specs.push_back(Spec); |
617 | 3.26k | Ctx = Ctx->getParent(); |
618 | 3.26k | } |
619 | 1.84k | |
620 | 1.84k | std::string TemplateParams; |
621 | 1.84k | llvm::raw_string_ostream TOut(TemplateParams); |
622 | 1.84k | for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend(); |
623 | 1.85k | I != E1.85k ; ++I11 ) { |
624 | 11 | const TemplateParameterList *Params |
625 | 11 | = (*I)->getSpecializedTemplate()->getTemplateParameters(); |
626 | 11 | const TemplateArgumentList &Args = (*I)->getTemplateArgs(); |
627 | 11 | assert(Params->size() == Args.size()); |
628 | 23 | for (unsigned i = 0, numParams = Params->size(); i != numParams23 ; ++i12 ) { |
629 | 12 | StringRef Param = Params->getParam(i)->getName(); |
630 | 12 | if (Param.empty()12 ) continue0 ; |
631 | 12 | TOut << Param << " = "; |
632 | 12 | Args.get(i).print(Policy, TOut); |
633 | 12 | TOut << ", "; |
634 | 12 | } |
635 | 11 | } |
636 | 1.84k | |
637 | 1.84k | FunctionTemplateSpecializationInfo *FSI |
638 | 1.84k | = FD->getTemplateSpecializationInfo(); |
639 | 1.84k | if (FSI && 1.84k !FSI->isExplicitSpecialization()20 ) { |
640 | 19 | const TemplateParameterList* Params |
641 | 19 | = FSI->getTemplate()->getTemplateParameters(); |
642 | 19 | const TemplateArgumentList* Args = FSI->TemplateArguments; |
643 | 19 | assert(Params->size() == Args->size()); |
644 | 40 | for (unsigned i = 0, e = Params->size(); i != e40 ; ++i21 ) { |
645 | 21 | StringRef Param = Params->getParam(i)->getName(); |
646 | 21 | if (Param.empty()21 ) continue1 ; |
647 | 20 | TOut << Param << " = "; |
648 | 20 | Args->get(i).print(Policy, TOut); |
649 | 20 | TOut << ", "; |
650 | 20 | } |
651 | 19 | } |
652 | 1.84k | |
653 | 1.84k | TOut.flush(); |
654 | 1.84k | if (!TemplateParams.empty()1.84k ) { |
655 | 28 | // remove the trailing comma and space |
656 | 28 | TemplateParams.resize(TemplateParams.size() - 2); |
657 | 28 | POut << " [" << TemplateParams << "]"; |
658 | 28 | } |
659 | 1.84k | |
660 | 1.84k | POut.flush(); |
661 | 1.84k | |
662 | 1.84k | // Print "auto" for all deduced return types. This includes C++1y return |
663 | 1.84k | // type deduction and lambdas. For trailing return types resolve the |
664 | 1.84k | // decltype expression. Otherwise print the real type when this is |
665 | 1.84k | // not a constructor or destructor. |
666 | 1.84k | if (isa<CXXMethodDecl>(FD) && |
667 | 1.78k | cast<CXXMethodDecl>(FD)->getParent()->isLambda()) |
668 | 6 | Proto = "auto " + Proto; |
669 | 1.83k | else if (1.83k FT && 1.83k FT->getReturnType()->getAs<DecltypeType>()1.80k ) |
670 | 1 | FT->getReturnType() |
671 | 1 | ->getAs<DecltypeType>() |
672 | 1 | ->getUnderlyingType() |
673 | 1 | .getAsStringInternal(Proto, Policy); |
674 | 1.83k | else if (1.83k !isa<CXXConstructorDecl>(FD) && 1.83k !isa<CXXDestructorDecl>(FD)1.82k ) |
675 | 1.68k | AFT->getReturnType().getAsStringInternal(Proto, Policy); |
676 | 2.85k | |
677 | 2.85k | Out << Proto; |
678 | 2.85k | |
679 | 2.85k | return Name.str().str(); |
680 | 2.85k | } |
681 | 123 | if (const CapturedDecl *123 CD123 = dyn_cast<CapturedDecl>(CurrentDecl)) { |
682 | 22 | for (const DeclContext *DC = CD->getParent(); DC22 ; DC = DC->getParent()3 ) |
683 | 19 | // Skip to its enclosing function or method, but not its enclosing |
684 | 19 | // CapturedDecl. |
685 | 22 | if (22 DC->isFunctionOrMethod() && 22 (DC->getDeclKind() != Decl::Captured)22 ) { |
686 | 19 | const Decl *D = Decl::castFromDeclContext(DC); |
687 | 19 | return ComputeName(IT, D); |
688 | 19 | } |
689 | 0 | llvm_unreachable0 ("CapturedDecl not inside a function or method"); |
690 | 104 | } |
691 | 104 | if (const ObjCMethodDecl *104 MD104 = dyn_cast<ObjCMethodDecl>(CurrentDecl)) { |
692 | 99 | SmallString<256> Name; |
693 | 99 | llvm::raw_svector_ostream Out(Name); |
694 | 99 | Out << (MD->isInstanceMethod() ? '-'78 : '+'21 ); |
695 | 99 | Out << '['; |
696 | 99 | |
697 | 99 | // For incorrect code, there might not be an ObjCInterfaceDecl. Do |
698 | 99 | // a null check to avoid a crash. |
699 | 99 | if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) |
700 | 98 | Out << *ID; |
701 | 99 | |
702 | 99 | if (const ObjCCategoryImplDecl *CID = |
703 | 99 | dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext())) |
704 | 7 | Out << '(' << *CID << ')'; |
705 | 99 | |
706 | 99 | Out << ' '; |
707 | 99 | MD->getSelector().print(Out); |
708 | 99 | Out << ']'; |
709 | 99 | |
710 | 99 | return Name.str().str(); |
711 | 99 | } |
712 | 5 | if (5 isa<TranslationUnitDecl>(CurrentDecl) && 5 IT == PrettyFunction5 ) { |
713 | 2 | // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string. |
714 | 2 | return "top level"; |
715 | 2 | } |
716 | 3 | return ""; |
717 | 3 | } |
718 | | |
719 | | void APNumericStorage::setIntValue(const ASTContext &C, |
720 | 5.32M | const llvm::APInt &Val) { |
721 | 5.32M | if (hasAllocation()) |
722 | 0 | C.Deallocate(pVal); |
723 | 5.32M | |
724 | 5.32M | BitWidth = Val.getBitWidth(); |
725 | 5.32M | unsigned NumWords = Val.getNumWords(); |
726 | 5.32M | const uint64_t* Words = Val.getRawData(); |
727 | 5.32M | if (NumWords > 15.32M ) { |
728 | 349 | pVal = new (C) uint64_t[NumWords]; |
729 | 349 | std::copy(Words, Words + NumWords, pVal); |
730 | 5.32M | } else if (5.32M NumWords == 15.32M ) |
731 | 5.32M | VAL = Words[0]; |
732 | 5.32M | else |
733 | 0 | VAL = 0; |
734 | 5.32M | } |
735 | | |
736 | | IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V, |
737 | | QualType type, SourceLocation l) |
738 | | : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, |
739 | | false, false), |
740 | 4.88M | Loc(l) { |
741 | 4.88M | assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); |
742 | 4.88M | assert(V.getBitWidth() == C.getIntWidth(type) && |
743 | 4.88M | "Integer type is not the correct size for constant."); |
744 | 4.88M | setValue(C, V); |
745 | 4.88M | } |
746 | | |
747 | | IntegerLiteral * |
748 | | IntegerLiteral::Create(const ASTContext &C, const llvm::APInt &V, |
749 | 4.87M | QualType type, SourceLocation l) { |
750 | 4.87M | return new (C) IntegerLiteral(C, V, type, l); |
751 | 4.87M | } |
752 | | |
753 | | IntegerLiteral * |
754 | 19.7k | IntegerLiteral::Create(const ASTContext &C, EmptyShell Empty) { |
755 | 19.7k | return new (C) IntegerLiteral(Empty); |
756 | 19.7k | } |
757 | | |
758 | | FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, |
759 | | bool isexact, QualType Type, SourceLocation L) |
760 | | : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, |
761 | 424k | false, false), Loc(L) { |
762 | 424k | setSemantics(V.getSemantics()); |
763 | 424k | FloatingLiteralBits.IsExact = isexact; |
764 | 424k | setValue(C, V); |
765 | 424k | } |
766 | | |
767 | | FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty) |
768 | 319 | : Expr(FloatingLiteralClass, Empty) { |
769 | 319 | setRawSemantics(IEEEhalf); |
770 | 319 | FloatingLiteralBits.IsExact = false; |
771 | 319 | } |
772 | | |
773 | | FloatingLiteral * |
774 | | FloatingLiteral::Create(const ASTContext &C, const llvm::APFloat &V, |
775 | 424k | bool isexact, QualType Type, SourceLocation L) { |
776 | 424k | return new (C) FloatingLiteral(C, V, isexact, Type, L); |
777 | 424k | } |
778 | | |
779 | | FloatingLiteral * |
780 | 319 | FloatingLiteral::Create(const ASTContext &C, EmptyShell Empty) { |
781 | 319 | return new (C) FloatingLiteral(C, Empty); |
782 | 319 | } |
783 | | |
784 | 254k | const llvm::fltSemantics &FloatingLiteral::getSemantics() const { |
785 | 254k | switch(FloatingLiteralBits.Semantics) { |
786 | 60 | case IEEEhalf: |
787 | 60 | return llvm::APFloat::IEEEhalf(); |
788 | 58.6k | case IEEEsingle: |
789 | 58.6k | return llvm::APFloat::IEEEsingle(); |
790 | 194k | case IEEEdouble: |
791 | 194k | return llvm::APFloat::IEEEdouble(); |
792 | 263 | case x87DoubleExtended: |
793 | 263 | return llvm::APFloat::x87DoubleExtended(); |
794 | 171 | case IEEEquad: |
795 | 171 | return llvm::APFloat::IEEEquad(); |
796 | 27 | case PPCDoubleDouble: |
797 | 27 | return llvm::APFloat::PPCDoubleDouble(); |
798 | 0 | } |
799 | 0 | llvm_unreachable0 ("Unrecognised floating semantics"); |
800 | 0 | } |
801 | | |
802 | 424k | void FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) { |
803 | 424k | if (&Sem == &llvm::APFloat::IEEEhalf()) |
804 | 44 | FloatingLiteralBits.Semantics = IEEEhalf; |
805 | 424k | else if (424k &Sem == &llvm::APFloat::IEEEsingle()424k ) |
806 | 316k | FloatingLiteralBits.Semantics = IEEEsingle; |
807 | 107k | else if (107k &Sem == &llvm::APFloat::IEEEdouble()107k ) |
808 | 107k | FloatingLiteralBits.Semantics = IEEEdouble; |
809 | 340 | else if (340 &Sem == &llvm::APFloat::x87DoubleExtended()340 ) |
810 | 197 | FloatingLiteralBits.Semantics = x87DoubleExtended; |
811 | 143 | else if (143 &Sem == &llvm::APFloat::IEEEquad()143 ) |
812 | 126 | FloatingLiteralBits.Semantics = IEEEquad; |
813 | 17 | else if (17 &Sem == &llvm::APFloat::PPCDoubleDouble()17 ) |
814 | 17 | FloatingLiteralBits.Semantics = PPCDoubleDouble; |
815 | 17 | else |
816 | 0 | llvm_unreachable("Unknown floating semantics"); |
817 | 424k | } |
818 | | |
819 | | /// getValueAsApproximateDouble - This returns the value as an inaccurate |
820 | | /// double. Note that this may cause loss of precision, but is useful for |
821 | | /// debugging dumps, etc. |
822 | 53 | double FloatingLiteral::getValueAsApproximateDouble() const { |
823 | 53 | llvm::APFloat V = getValue(); |
824 | 53 | bool ignored; |
825 | 53 | V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, |
826 | 53 | &ignored); |
827 | 53 | return V.convertToDouble(); |
828 | 53 | } |
829 | | |
830 | 957k | int StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) { |
831 | 957k | int CharByteWidth = 0; |
832 | 957k | switch(k) { |
833 | 955k | case Ascii: |
834 | 955k | case UTF8: |
835 | 955k | CharByteWidth = target.getCharWidth(); |
836 | 955k | break; |
837 | 1.22k | case Wide: |
838 | 1.22k | CharByteWidth = target.getWCharWidth(); |
839 | 1.22k | break; |
840 | 54 | case UTF16: |
841 | 54 | CharByteWidth = target.getChar16Width(); |
842 | 54 | break; |
843 | 51 | case UTF32: |
844 | 51 | CharByteWidth = target.getChar32Width(); |
845 | 51 | break; |
846 | 957k | } |
847 | 957k | assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple"); |
848 | 957k | CharByteWidth /= 8; |
849 | 957k | assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) |
850 | 957k | && "character byte widths supported are 1, 2, and 4 only"); |
851 | 957k | return CharByteWidth; |
852 | 957k | } |
853 | | |
854 | | StringLiteral *StringLiteral::Create(const ASTContext &C, StringRef Str, |
855 | | StringKind Kind, bool Pascal, QualType Ty, |
856 | | const SourceLocation *Loc, |
857 | 956k | unsigned NumStrs) { |
858 | 956k | assert(C.getAsConstantArrayType(Ty) && |
859 | 956k | "StringLiteral must be of constant array type!"); |
860 | 956k | |
861 | 956k | // Allocate enough space for the StringLiteral plus an array of locations for |
862 | 956k | // any concatenated string tokens. |
863 | 956k | void *Mem = |
864 | 956k | C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1), |
865 | 956k | alignof(StringLiteral)); |
866 | 956k | StringLiteral *SL = new (Mem) StringLiteral(Ty); |
867 | 956k | |
868 | 956k | // OPTIMIZE: could allocate this appended to the StringLiteral. |
869 | 956k | SL->setString(C,Str,Kind,Pascal); |
870 | 956k | |
871 | 956k | SL->TokLocs[0] = Loc[0]; |
872 | 956k | SL->NumConcatenated = NumStrs; |
873 | 956k | |
874 | 956k | if (NumStrs != 1) |
875 | 195k | memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); |
876 | 956k | return SL; |
877 | 956k | } |
878 | | |
879 | | StringLiteral *StringLiteral::CreateEmpty(const ASTContext &C, |
880 | 192 | unsigned NumStrs) { |
881 | 192 | void *Mem = |
882 | 192 | C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1), |
883 | 192 | alignof(StringLiteral)); |
884 | 192 | StringLiteral *SL = new (Mem) StringLiteral(QualType()); |
885 | 192 | SL->CharByteWidth = 0; |
886 | 192 | SL->Length = 0; |
887 | 192 | SL->NumConcatenated = NumStrs; |
888 | 192 | return SL; |
889 | 192 | } |
890 | | |
891 | 801 | void StringLiteral::outputString(raw_ostream &OS) const { |
892 | 801 | switch (getKind()) { |
893 | 785 | case Ascii: break; // no prefix. |
894 | 7 | case Wide: OS << 'L'; break; |
895 | 4 | case UTF8: OS << "u8"; break; |
896 | 3 | case UTF16: OS << 'u'; break; |
897 | 2 | case UTF32: OS << 'U'; break; |
898 | 801 | } |
899 | 801 | OS << '"'; |
900 | 801 | static const char Hex[] = "0123456789ABCDEF"; |
901 | 801 | |
902 | 801 | unsigned LastSlashX = getLength(); |
903 | 8.01k | for (unsigned I = 0, N = getLength(); I != N8.01k ; ++I7.21k ) { |
904 | 7.21k | switch (uint32_t Char = getCodeUnit(I)) { |
905 | 7.16k | default: |
906 | 7.16k | // FIXME: Convert UTF-8 back to codepoints before rendering. |
907 | 7.16k | |
908 | 7.16k | // Convert UTF-16 surrogate pairs back to codepoints before rendering. |
909 | 7.16k | // Leave invalid surrogates alone; we'll use \x for those. |
910 | 7.16k | if (getKind() == UTF16 && 7.16k I != N - 115 && Char >= 0xd80013 && |
911 | 7.16k | Char <= 0xdbff1 ) { |
912 | 1 | uint32_t Trail = getCodeUnit(I + 1); |
913 | 1 | if (Trail >= 0xdc00 && 1 Trail <= 0xdfff1 ) { |
914 | 1 | Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00); |
915 | 1 | ++I; |
916 | 1 | } |
917 | 1 | } |
918 | 7.16k | |
919 | 7.16k | if (Char > 0xff7.16k ) { |
920 | 16 | // If this is a wide string, output characters over 0xff using \x |
921 | 16 | // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a |
922 | 16 | // codepoint: use \x escapes for invalid codepoints. |
923 | 16 | if (getKind() == Wide || |
924 | 16 | (Char >= 0xd800 && 7 Char <= 0xdfff3 ) || Char >= 0x1100007 ) { |
925 | 9 | // FIXME: Is this the best way to print wchar_t? |
926 | 9 | OS << "\\x"; |
927 | 9 | int Shift = 28; |
928 | 34 | while ((Char >> Shift) == 0) |
929 | 25 | Shift -= 4; |
930 | 56 | for (/**/; Shift >= 056 ; Shift -= 447 ) |
931 | 47 | OS << Hex[(Char >> Shift) & 15]; |
932 | 9 | LastSlashX = I; |
933 | 9 | break; |
934 | 9 | } |
935 | 7 | |
936 | 7 | if (7 Char > 0xffff7 ) |
937 | 3 | OS << "\\U00" |
938 | 3 | << Hex[(Char >> 20) & 15] |
939 | 3 | << Hex[(Char >> 16) & 15]; |
940 | 7 | else |
941 | 4 | OS << "\\u"; |
942 | 16 | OS << Hex[(Char >> 12) & 15] |
943 | 16 | << Hex[(Char >> 8) & 15] |
944 | 16 | << Hex[(Char >> 4) & 15] |
945 | 16 | << Hex[(Char >> 0) & 15]; |
946 | 16 | break; |
947 | 16 | } |
948 | 7.15k | |
949 | 7.15k | // If we used \x... for the previous character, and this character is a |
950 | 7.15k | // hexadecimal digit, prevent it being slurped as part of the \x. |
951 | 7.15k | if (7.15k LastSlashX + 1 == I7.15k ) { |
952 | 3 | switch (Char) { |
953 | 2 | case '0': 2 case '1': 2 case '2': 2 case '3': 2 case '4': |
954 | 2 | case '5': 2 case '6': 2 case '7': 2 case '8': 2 case '9': |
955 | 2 | case 'a': 2 case 'b': 2 case 'c': 2 case 'd': 2 case 'e': 2 case 'f': |
956 | 2 | case 'A': 2 case 'B': 2 case 'C': 2 case 'D': 2 case 'E': 2 case 'F': |
957 | 2 | OS << "\"\""; |
958 | 3 | } |
959 | 3 | } |
960 | 7.15k | |
961 | 7.15k | assert(Char <= 0xff && |
962 | 7.15k | "Characters above 0xff should already have been handled."); |
963 | 7.15k | |
964 | 7.15k | if (isPrintable(Char)) |
965 | 7.12k | OS << (char)Char; |
966 | 7.15k | else // Output anything hard as an octal escape. |
967 | 21 | OS << '\\' |
968 | 21 | << (char)('0' + ((Char >> 6) & 7)) |
969 | 21 | << (char)('0' + ((Char >> 3) & 7)) |
970 | 21 | << (char)('0' + ((Char >> 0) & 7)); |
971 | 7.15k | break; |
972 | 7.15k | // Handle some common non-printable cases to make dumps prettier. |
973 | 9 | case '\\': OS << "\\\\"; break; |
974 | 10 | case '"': OS << "\\\""; break; |
975 | 9 | case '\a': OS << "\\a"; break; |
976 | 9 | case '\b': OS << "\\b"; break; |
977 | 1 | case '\f': OS << "\\f"; break; |
978 | 1 | case '\n': OS << "\\n"; break; |
979 | 1 | case '\r': OS << "\\r"; break; |
980 | 9 | case '\t': OS << "\\t"; break; |
981 | 1 | case '\v': OS << "\\v"; break; |
982 | 7.21k | } |
983 | 7.21k | } |
984 | 801 | OS << '"'; |
985 | 801 | } |
986 | | |
987 | | void StringLiteral::setString(const ASTContext &C, StringRef Str, |
988 | 957k | StringKind Kind, bool IsPascal) { |
989 | 957k | //FIXME: we assume that the string data comes from a target that uses the same |
990 | 957k | // code unit size and endianness for the type of string. |
991 | 957k | this->Kind = Kind; |
992 | 957k | this->IsPascal = IsPascal; |
993 | 957k | |
994 | 957k | CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind); |
995 | 957k | assert((Str.size()%CharByteWidth == 0) |
996 | 957k | && "size of data must be multiple of CharByteWidth"); |
997 | 957k | Length = Str.size()/CharByteWidth; |
998 | 957k | |
999 | 957k | switch(CharByteWidth) { |
1000 | 955k | case 1: { |
1001 | 955k | char *AStrData = new (C) char[Length]; |
1002 | 955k | std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); |
1003 | 955k | StrData.asChar = AStrData; |
1004 | 955k | break; |
1005 | 957k | } |
1006 | 345 | case 2: { |
1007 | 345 | uint16_t *AStrData = new (C) uint16_t[Length]; |
1008 | 345 | std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); |
1009 | 345 | StrData.asUInt16 = AStrData; |
1010 | 345 | break; |
1011 | 957k | } |
1012 | 985 | case 4: { |
1013 | 985 | uint32_t *AStrData = new (C) uint32_t[Length]; |
1014 | 985 | std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); |
1015 | 985 | StrData.asUInt32 = AStrData; |
1016 | 985 | break; |
1017 | 957k | } |
1018 | 0 | default: |
1019 | 0 | llvm_unreachable("unsupported CharByteWidth"); |
1020 | 957k | } |
1021 | 957k | } |
1022 | | |
1023 | | /// getLocationOfByte - Return a source location that points to the specified |
1024 | | /// byte of this string literal. |
1025 | | /// |
1026 | | /// Strings are amazingly complex. They can be formed from multiple tokens and |
1027 | | /// can have escape sequences in them in addition to the usual trigraph and |
1028 | | /// escaped newline business. This routine handles this complexity. |
1029 | | /// |
1030 | | /// The *StartToken sets the first token to be searched in this function and |
1031 | | /// the *StartTokenByteOffset is the byte offset of the first token. Before |
1032 | | /// returning, it updates the *StartToken to the TokNo of the token being found |
1033 | | /// and sets *StartTokenByteOffset to the byte offset of the token in the |
1034 | | /// string. |
1035 | | /// Using these two parameters can reduce the time complexity from O(n^2) to |
1036 | | /// O(n) if one wants to get the location of byte for all the tokens in a |
1037 | | /// string. |
1038 | | /// |
1039 | | SourceLocation |
1040 | | StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM, |
1041 | | const LangOptions &Features, |
1042 | | const TargetInfo &Target, unsigned *StartToken, |
1043 | 20.3k | unsigned *StartTokenByteOffset) const { |
1044 | 20.3k | assert((Kind == StringLiteral::Ascii || Kind == StringLiteral::UTF8) && |
1045 | 20.3k | "Only narrow string literals are currently supported"); |
1046 | 20.3k | |
1047 | 20.3k | // Loop over all of the tokens in this string until we find the one that |
1048 | 20.3k | // contains the byte we're looking for. |
1049 | 20.3k | unsigned TokNo = 0; |
1050 | 20.3k | unsigned StringOffset = 0; |
1051 | 20.3k | if (StartToken) |
1052 | 14.4k | TokNo = *StartToken; |
1053 | 20.3k | if (StartTokenByteOffset20.3k ) { |
1054 | 14.4k | StringOffset = *StartTokenByteOffset; |
1055 | 14.4k | ByteNo -= StringOffset; |
1056 | 14.4k | } |
1057 | 22.7k | while (122.7k ) { |
1058 | 22.7k | assert(TokNo < getNumConcatenated() && "Invalid byte number!"); |
1059 | 22.7k | SourceLocation StrTokLoc = getStrTokenLoc(TokNo); |
1060 | 22.7k | |
1061 | 22.7k | // Get the spelling of the string so that we can get the data that makes up |
1062 | 22.7k | // the string literal, not the identifier for the macro it is potentially |
1063 | 22.7k | // expanded through. |
1064 | 22.7k | SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc); |
1065 | 22.7k | |
1066 | 22.7k | // Re-lex the token to get its length and original spelling. |
1067 | 22.7k | std::pair<FileID, unsigned> LocInfo = |
1068 | 22.7k | SM.getDecomposedLoc(StrTokSpellingLoc); |
1069 | 22.7k | bool Invalid = false; |
1070 | 22.7k | StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); |
1071 | 22.7k | if (Invalid22.7k ) { |
1072 | 0 | if (StartTokenByteOffset != nullptr) |
1073 | 0 | *StartTokenByteOffset = StringOffset; |
1074 | 0 | if (StartToken != nullptr) |
1075 | 0 | *StartToken = TokNo; |
1076 | 0 | return StrTokSpellingLoc; |
1077 | 0 | } |
1078 | 22.7k | |
1079 | 22.7k | const char *StrData = Buffer.data()+LocInfo.second; |
1080 | 22.7k | |
1081 | 22.7k | // Create a lexer starting at the beginning of this token. |
1082 | 22.7k | Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features, |
1083 | 22.7k | Buffer.begin(), StrData, Buffer.end()); |
1084 | 22.7k | Token TheTok; |
1085 | 22.7k | TheLexer.LexFromRawLexer(TheTok); |
1086 | 22.7k | |
1087 | 22.7k | // Use the StringLiteralParser to compute the length of the string in bytes. |
1088 | 22.7k | StringLiteralParser SLP(TheTok, SM, Features, Target); |
1089 | 22.7k | unsigned TokNumBytes = SLP.GetStringLength(); |
1090 | 22.7k | |
1091 | 22.7k | // If the byte is in this token, return the location of the byte. |
1092 | 22.7k | if (ByteNo < TokNumBytes || |
1093 | 22.7k | (ByteNo == TokNumBytes && 3.76k TokNo == getNumConcatenated() - 11.40k )) { |
1094 | 20.3k | unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo); |
1095 | 20.3k | |
1096 | 20.3k | // Now that we know the offset of the token in the spelling, use the |
1097 | 20.3k | // preprocessor to get the offset in the original source. |
1098 | 20.3k | if (StartTokenByteOffset != nullptr) |
1099 | 14.4k | *StartTokenByteOffset = StringOffset; |
1100 | 20.3k | if (StartToken != nullptr) |
1101 | 14.4k | *StartToken = TokNo; |
1102 | 20.3k | return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features); |
1103 | 20.3k | } |
1104 | 2.43k | |
1105 | 2.43k | // Move to the next string token. |
1106 | 2.43k | StringOffset += TokNumBytes; |
1107 | 2.43k | ++TokNo; |
1108 | 2.43k | ByteNo -= TokNumBytes; |
1109 | 2.43k | } |
1110 | 20.3k | } |
1111 | | |
1112 | | |
1113 | | |
1114 | | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
1115 | | /// corresponds to, e.g. "sizeof" or "[pre]++". |
1116 | 4.90k | StringRef UnaryOperator::getOpcodeStr(Opcode Op) { |
1117 | 4.90k | switch (Op) { |
1118 | 4.90k | #define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling; |
1119 | 697 | #include "clang/AST/OperationKinds.def" |
1120 | 4.90k | } |
1121 | 0 | llvm_unreachable0 ("Unknown unary operator"); |
1122 | 0 | } |
1123 | | |
1124 | | UnaryOperatorKind |
1125 | 33 | UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { |
1126 | 33 | switch (OO) { |
1127 | 0 | default: 0 llvm_unreachable0 ("No unary operator for overloaded function"); |
1128 | 6 | case OO_PlusPlus: return Postfix ? 6 UO_PostInc0 : UO_PreInc6 ; |
1129 | 0 | case OO_MinusMinus: return Postfix ? 0 UO_PostDec0 : UO_PreDec0 ; |
1130 | 1 | case OO_Amp: return UO_AddrOf; |
1131 | 3 | case OO_Star: return UO_Deref; |
1132 | 0 | case OO_Plus: return UO_Plus; |
1133 | 0 | case OO_Minus: return UO_Minus; |
1134 | 1 | case OO_Tilde: return UO_Not; |
1135 | 0 | case OO_Exclaim: return UO_LNot; |
1136 | 22 | case OO_Coawait: return UO_Coawait; |
1137 | 0 | } |
1138 | 0 | } |
1139 | | |
1140 | 269k | OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { |
1141 | 269k | switch (Opc) { |
1142 | 18.0k | case UO_PostInc: 18.0k case UO_PreInc: return OO_PlusPlus18.0k ; |
1143 | 2.61k | case UO_PostDec: 2.61k case UO_PreDec: return OO_MinusMinus2.61k ; |
1144 | 125k | case UO_AddrOf: return OO_Amp; |
1145 | 71.7k | case UO_Deref: return OO_Star; |
1146 | 262 | case UO_Plus: return OO_Plus; |
1147 | 5.54k | case UO_Minus: return OO_Minus; |
1148 | 520 | case UO_Not: return OO_Tilde; |
1149 | 45.0k | case UO_LNot: return OO_Exclaim; |
1150 | 709 | case UO_Coawait: return OO_Coawait; |
1151 | 5 | default: return OO_None; |
1152 | 0 | } |
1153 | 0 | } |
1154 | | |
1155 | | |
1156 | | //===----------------------------------------------------------------------===// |
1157 | | // Postfix Operators. |
1158 | | //===----------------------------------------------------------------------===// |
1159 | | |
1160 | | CallExpr::CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, |
1161 | | ArrayRef<Expr *> preargs, ArrayRef<Expr *> args, QualType t, |
1162 | | ExprValueKind VK, SourceLocation rparenloc) |
1163 | | : Expr(SC, t, VK, OK_Ordinary, fn->isTypeDependent(), |
1164 | | fn->isValueDependent(), fn->isInstantiationDependent(), |
1165 | | fn->containsUnexpandedParameterPack()), |
1166 | 4.01M | NumArgs(args.size()) { |
1167 | 4.01M | |
1168 | 4.01M | unsigned NumPreArgs = preargs.size(); |
1169 | 4.01M | SubExprs = new (C) Stmt *[args.size()+PREARGS_START+NumPreArgs]; |
1170 | 4.01M | SubExprs[FN] = fn; |
1171 | 4.01M | for (unsigned i = 0; i != NumPreArgs4.01M ; ++i26 ) { |
1172 | 26 | updateDependenciesFromArg(preargs[i]); |
1173 | 26 | SubExprs[i+PREARGS_START] = preargs[i]; |
1174 | 26 | } |
1175 | 8.45M | for (unsigned i = 0; i != args.size()8.45M ; ++i4.44M ) { |
1176 | 4.44M | updateDependenciesFromArg(args[i]); |
1177 | 4.44M | SubExprs[i+PREARGS_START+NumPreArgs] = args[i]; |
1178 | 4.44M | } |
1179 | 4.01M | |
1180 | 4.01M | CallExprBits.NumPreArgs = NumPreArgs; |
1181 | 4.01M | RParenLoc = rparenloc; |
1182 | 4.01M | } |
1183 | | |
1184 | | CallExpr::CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, |
1185 | | ArrayRef<Expr *> args, QualType t, ExprValueKind VK, |
1186 | | SourceLocation rparenloc) |
1187 | 401k | : CallExpr(C, SC, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) {} clang::CallExpr::CallExpr(clang::ASTContext const&, clang::Stmt::StmtClass, clang::Expr*, llvm::ArrayRef<clang::Expr*>, clang::QualType, clang::ExprValueKind, clang::SourceLocation) Line | Count | Source | 1187 | 401k | : CallExpr(C, SC, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) {} |
Unexecuted instantiation: clang::CallExpr::CallExpr(clang::ASTContext const&, clang::Stmt::StmtClass, clang::Expr*, llvm::ArrayRef<clang::Expr*>, clang::QualType, clang::ExprValueKind, clang::SourceLocation) |
1188 | | |
1189 | | CallExpr::CallExpr(const ASTContext &C, Expr *fn, ArrayRef<Expr *> args, |
1190 | | QualType t, ExprValueKind VK, SourceLocation rparenloc) |
1191 | 3.60M | : CallExpr(C, CallExprClass, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) { |
1192 | 3.60M | } Unexecuted instantiation: clang::CallExpr::CallExpr(clang::ASTContext const&, clang::Expr*, llvm::ArrayRef<clang::Expr*>, clang::QualType, clang::ExprValueKind, clang::SourceLocation) clang::CallExpr::CallExpr(clang::ASTContext const&, clang::Expr*, llvm::ArrayRef<clang::Expr*>, clang::QualType, clang::ExprValueKind, clang::SourceLocation) Line | Count | Source | 1191 | 3.60M | : CallExpr(C, CallExprClass, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) { | 1192 | 3.60M | } |
|
1193 | | |
1194 | | CallExpr::CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty) |
1195 | 1.54k | : CallExpr(C, SC, /*NumPreArgs=*/0, Empty) {} clang::CallExpr::CallExpr(clang::ASTContext const&, clang::Stmt::StmtClass, clang::Stmt::EmptyShell) Line | Count | Source | 1195 | 990 | : CallExpr(C, SC, /*NumPreArgs=*/0, Empty) {} |
clang::CallExpr::CallExpr(clang::ASTContext const&, clang::Stmt::StmtClass, clang::Stmt::EmptyShell) Line | Count | Source | 1195 | 559 | : CallExpr(C, SC, /*NumPreArgs=*/0, Empty) {} |
|
1196 | | |
1197 | | CallExpr::CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, |
1198 | | EmptyShell Empty) |
1199 | 1.54k | : Expr(SC, Empty), SubExprs(nullptr), NumArgs(0) { |
1200 | 1.54k | // FIXME: Why do we allocate this? |
1201 | 1.54k | SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs](); |
1202 | 1.54k | CallExprBits.NumPreArgs = NumPreArgs; |
1203 | 1.54k | } |
1204 | | |
1205 | 4.44M | void CallExpr::updateDependenciesFromArg(Expr *Arg) { |
1206 | 4.44M | if (Arg->isTypeDependent()) |
1207 | 129k | ExprBits.TypeDependent = true; |
1208 | 4.44M | if (Arg->isValueDependent()) |
1209 | 143k | ExprBits.ValueDependent = true; |
1210 | 4.44M | if (Arg->isInstantiationDependent()) |
1211 | 143k | ExprBits.InstantiationDependent = true; |
1212 | 4.44M | if (Arg->containsUnexpandedParameterPack()) |
1213 | 46 | ExprBits.ContainsUnexpandedParameterPack = true; |
1214 | 4.44M | } |
1215 | | |
1216 | 1.40M | FunctionDecl *CallExpr::getDirectCallee() { |
1217 | 1.40M | return dyn_cast_or_null<FunctionDecl>(getCalleeDecl()); |
1218 | 1.40M | } |
1219 | | |
1220 | 2.22M | Decl *CallExpr::getCalleeDecl() { |
1221 | 2.22M | return getCallee()->getReferencedDeclOfCallee(); |
1222 | 2.22M | } |
1223 | | |
1224 | 2.23M | Decl *Expr::getReferencedDeclOfCallee() { |
1225 | 2.23M | Expr *CEE = IgnoreParenImpCasts(); |
1226 | 2.23M | |
1227 | 2.23M | while (SubstNonTypeTemplateParmExpr *NTTP |
1228 | 0 | = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) { |
1229 | 0 | CEE = NTTP->getReplacement()->IgnoreParenCasts(); |
1230 | 0 | } |
1231 | 2.23M | |
1232 | 2.23M | // If we're calling a dereference, look at the pointer instead. |
1233 | 2.23M | if (BinaryOperator *BO2.23M = dyn_cast<BinaryOperator>(CEE)) { |
1234 | 453 | if (BO->isPtrMemOp()) |
1235 | 444 | CEE = BO->getRHS()->IgnoreParenCasts(); |
1236 | 2.23M | } else if (UnaryOperator *2.23M UO2.23M = dyn_cast<UnaryOperator>(CEE)) { |
1237 | 11.9k | if (UO->getOpcode() == UO_Deref) |
1238 | 11.9k | CEE = UO->getSubExpr()->IgnoreParenCasts(); |
1239 | 2.23M | } |
1240 | 2.23M | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) |
1241 | 1.97M | return DRE->getDecl(); |
1242 | 254k | if (MemberExpr *254k ME254k = dyn_cast<MemberExpr>(CEE)) |
1243 | 251k | return ME->getMemberDecl(); |
1244 | 2.88k | |
1245 | 2.88k | return nullptr; |
1246 | 2.88k | } |
1247 | | |
1248 | | /// setNumArgs - This changes the number of arguments present in this call. |
1249 | | /// Any orphaned expressions are deleted by this, and any new operands are set |
1250 | | /// to null. |
1251 | 8.23k | void CallExpr::setNumArgs(const ASTContext& C, unsigned NumArgs) { |
1252 | 8.23k | // No change, just return. |
1253 | 8.23k | if (NumArgs == getNumArgs()8.23k ) return709 ; |
1254 | 7.52k | |
1255 | 7.52k | // If shrinking # arguments, just delete the extras and forgot them. |
1256 | 7.52k | if (7.52k NumArgs < getNumArgs()7.52k ) { |
1257 | 48 | this->NumArgs = NumArgs; |
1258 | 48 | return; |
1259 | 48 | } |
1260 | 7.48k | |
1261 | 7.48k | // Otherwise, we are growing the # arguments. New an bigger argument array. |
1262 | 7.48k | unsigned NumPreArgs = getNumPreArgs(); |
1263 | 7.48k | Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; |
1264 | 7.48k | // Copy over args. |
1265 | 25.5k | for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs25.5k ; ++i18.0k ) |
1266 | 18.0k | NewSubExprs[i] = SubExprs[i]; |
1267 | 7.48k | // Null out new args. |
1268 | 7.48k | for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs; |
1269 | 16.2k | i != NumArgs+PREARGS_START+NumPreArgs16.2k ; ++i8.79k ) |
1270 | 8.79k | NewSubExprs[i] = nullptr; |
1271 | 7.48k | |
1272 | 7.48k | if (SubExprs7.48k ) C.Deallocate(SubExprs)7.48k ; |
1273 | 8.23k | SubExprs = NewSubExprs; |
1274 | 8.23k | this->NumArgs = NumArgs; |
1275 | 8.23k | } |
1276 | | |
1277 | | /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID. If |
1278 | | /// not, return 0. |
1279 | 2.88M | unsigned CallExpr::getBuiltinCallee() const { |
1280 | 2.88M | // All simple function calls (e.g. func()) are implicitly cast to pointer to |
1281 | 2.88M | // function. As a result, we try and obtain the DeclRefExpr from the |
1282 | 2.88M | // ImplicitCastExpr. |
1283 | 2.88M | const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); |
1284 | 2.88M | if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). |
1285 | 390k | return 0; |
1286 | 2.49M | |
1287 | 2.49M | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); |
1288 | 2.49M | if (!DRE) |
1289 | 7.68k | return 0; |
1290 | 2.49M | |
1291 | 2.49M | const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); |
1292 | 2.49M | if (!FDecl) |
1293 | 4.09k | return 0; |
1294 | 2.48M | |
1295 | 2.48M | if (2.48M !FDecl->getIdentifier()2.48M ) |
1296 | 102k | return 0; |
1297 | 2.38M | |
1298 | 2.38M | return FDecl->getBuiltinID(); |
1299 | 2.38M | } |
1300 | | |
1301 | 1.94M | bool CallExpr::isUnevaluatedBuiltinCall(const ASTContext &Ctx) const { |
1302 | 1.94M | if (unsigned BI = getBuiltinCallee()) |
1303 | 670k | return Ctx.BuiltinInfo.isUnevaluated(BI); |
1304 | 1.27M | return false; |
1305 | 1.27M | } |
1306 | | |
1307 | 1.42M | QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const { |
1308 | 1.42M | const Expr *Callee = getCallee(); |
1309 | 1.42M | QualType CalleeType = Callee->getType(); |
1310 | 1.42M | if (const auto *FnTypePtr1.42M = CalleeType->getAs<PointerType>()) { |
1311 | 1.25M | CalleeType = FnTypePtr->getPointeeType(); |
1312 | 1.42M | } else if (const auto *165k BPT165k = CalleeType->getAs<BlockPointerType>()) { |
1313 | 305 | CalleeType = BPT->getPointeeType(); |
1314 | 165k | } else if (165k CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)165k ) { |
1315 | 165k | if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens())) |
1316 | 5 | return Ctx.VoidTy; |
1317 | 165k | |
1318 | 165k | // This should never be overloaded and so should never return null. |
1319 | 165k | CalleeType = Expr::findBoundMemberType(Callee); |
1320 | 165k | } |
1321 | 1.42M | |
1322 | 1.42M | const FunctionType *FnType = CalleeType->castAs<FunctionType>(); |
1323 | 1.42M | return FnType->getReturnType(); |
1324 | 1.42M | } |
1325 | | |
1326 | 10.0M | SourceLocation CallExpr::getLocStart() const { |
1327 | 10.0M | if (isa<CXXOperatorCallExpr>(this)) |
1328 | 18 | return cast<CXXOperatorCallExpr>(this)->getLocStart(); |
1329 | 10.0M | |
1330 | 10.0M | SourceLocation begin = getCallee()->getLocStart(); |
1331 | 10.0M | if (begin.isInvalid() && 10.0M getNumArgs() > 0292 && getArg(0)176 ) |
1332 | 176 | begin = getArg(0)->getLocStart(); |
1333 | 10.0M | return begin; |
1334 | 10.0M | } |
1335 | 805k | SourceLocation CallExpr::getLocEnd() const { |
1336 | 805k | if (isa<CXXOperatorCallExpr>(this)) |
1337 | 0 | return cast<CXXOperatorCallExpr>(this)->getLocEnd(); |
1338 | 805k | |
1339 | 805k | SourceLocation end = getRParenLoc(); |
1340 | 805k | if (end.isInvalid() && 805k getNumArgs() > 00 && getArg(getNumArgs() - 1)0 ) |
1341 | 0 | end = getArg(getNumArgs() - 1)->getLocEnd(); |
1342 | 805k | return end; |
1343 | 805k | } |
1344 | | |
1345 | | OffsetOfExpr *OffsetOfExpr::Create(const ASTContext &C, QualType type, |
1346 | | SourceLocation OperatorLoc, |
1347 | | TypeSourceInfo *tsi, |
1348 | | ArrayRef<OffsetOfNode> comps, |
1349 | | ArrayRef<Expr*> exprs, |
1350 | 2.94k | SourceLocation RParenLoc) { |
1351 | 2.94k | void *Mem = C.Allocate( |
1352 | 2.94k | totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size())); |
1353 | 2.94k | |
1354 | 2.94k | return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs, |
1355 | 2.94k | RParenLoc); |
1356 | 2.94k | } |
1357 | | |
1358 | | OffsetOfExpr *OffsetOfExpr::CreateEmpty(const ASTContext &C, |
1359 | 3 | unsigned numComps, unsigned numExprs) { |
1360 | 3 | void *Mem = |
1361 | 3 | C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs)); |
1362 | 3 | return new (Mem) OffsetOfExpr(numComps, numExprs); |
1363 | 3 | } |
1364 | | |
1365 | | OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type, |
1366 | | SourceLocation OperatorLoc, TypeSourceInfo *tsi, |
1367 | | ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, |
1368 | | SourceLocation RParenLoc) |
1369 | | : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary, |
1370 | | /*TypeDependent=*/false, |
1371 | | /*ValueDependent=*/tsi->getType()->isDependentType(), |
1372 | | tsi->getType()->isInstantiationDependentType(), |
1373 | | tsi->getType()->containsUnexpandedParameterPack()), |
1374 | | OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi), |
1375 | | NumComps(comps.size()), NumExprs(exprs.size()) |
1376 | 2.94k | { |
1377 | 5.95k | for (unsigned i = 0; i != comps.size()5.95k ; ++i3.00k ) { |
1378 | 3.00k | setComponent(i, comps[i]); |
1379 | 3.00k | } |
1380 | 2.94k | |
1381 | 2.98k | for (unsigned i = 0; i != exprs.size()2.98k ; ++i35 ) { |
1382 | 35 | if (exprs[i]->isTypeDependent() || 35 exprs[i]->isValueDependent()35 ) |
1383 | 9 | ExprBits.ValueDependent = true; |
1384 | 35 | if (exprs[i]->containsUnexpandedParameterPack()) |
1385 | 1 | ExprBits.ContainsUnexpandedParameterPack = true; |
1386 | 35 | |
1387 | 35 | setIndexExpr(i, exprs[i]); |
1388 | 35 | } |
1389 | 2.94k | } |
1390 | | |
1391 | 15 | IdentifierInfo *OffsetOfNode::getFieldName() const { |
1392 | 15 | assert(getKind() == Field || getKind() == Identifier); |
1393 | 15 | if (getKind() == Field) |
1394 | 2 | return getField()->getIdentifier(); |
1395 | 13 | |
1396 | 13 | return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask); |
1397 | 13 | } |
1398 | | |
1399 | | UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr( |
1400 | | UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType, |
1401 | | SourceLocation op, SourceLocation rp) |
1402 | | : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, |
1403 | | false, // Never type-dependent (C++ [temp.dep.expr]p3). |
1404 | | // Value-dependent if the argument is type-dependent. |
1405 | | E->isTypeDependent(), E->isInstantiationDependent(), |
1406 | | E->containsUnexpandedParameterPack()), |
1407 | 17.3k | OpLoc(op), RParenLoc(rp) { |
1408 | 17.3k | UnaryExprOrTypeTraitExprBits.Kind = ExprKind; |
1409 | 17.3k | UnaryExprOrTypeTraitExprBits.IsType = false; |
1410 | 17.3k | Argument.Ex = E; |
1411 | 17.3k | |
1412 | 17.3k | // Check to see if we are in the situation where alignof(decl) should be |
1413 | 17.3k | // dependent because decl's alignment is dependent. |
1414 | 17.3k | if (ExprKind == UETT_AlignOf17.3k ) { |
1415 | 103 | if (!isValueDependent() || 103 !isInstantiationDependent()4 ) { |
1416 | 99 | E = E->IgnoreParens(); |
1417 | 99 | |
1418 | 99 | const ValueDecl *D = nullptr; |
1419 | 99 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
1420 | 64 | D = DRE->getDecl(); |
1421 | 35 | else if (const auto *35 ME35 = dyn_cast<MemberExpr>(E)) |
1422 | 24 | D = ME->getMemberDecl(); |
1423 | 99 | |
1424 | 99 | if (D99 ) { |
1425 | 31 | for (const auto *I : D->specific_attrs<AlignedAttr>()) { |
1426 | 31 | if (I->isAlignmentDependent()31 ) { |
1427 | 1 | setValueDependent(true); |
1428 | 1 | setInstantiationDependent(true); |
1429 | 1 | break; |
1430 | 1 | } |
1431 | 17.3k | } |
1432 | 88 | } |
1433 | 99 | } |
1434 | 103 | } |
1435 | 17.3k | } |
1436 | | |
1437 | | MemberExpr *MemberExpr::Create( |
1438 | | const ASTContext &C, Expr *base, bool isarrow, SourceLocation OperatorLoc, |
1439 | | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
1440 | | ValueDecl *memberdecl, DeclAccessPair founddecl, |
1441 | | DeclarationNameInfo nameinfo, const TemplateArgumentListInfo *targs, |
1442 | 1.49M | QualType ty, ExprValueKind vk, ExprObjectKind ok) { |
1443 | 1.49M | |
1444 | 1.49M | bool hasQualOrFound = (QualifierLoc || |
1445 | 1.48M | founddecl.getDecl() != memberdecl || |
1446 | 1.48M | founddecl.getAccess() != memberdecl->getAccess()); |
1447 | 1.49M | |
1448 | 1.49M | bool HasTemplateKWAndArgsInfo = targs || TemplateKWLoc.isValid(); |
1449 | 1.49M | std::size_t Size = |
1450 | 1.49M | totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo, |
1451 | 1.49M | TemplateArgumentLoc>(hasQualOrFound ? 115.9k : 01.47M , |
1452 | 1.49M | HasTemplateKWAndArgsInfo ? 11.21k : 01.49M , |
1453 | 1.49M | targs ? targs->size()1.18k : 01.49M ); |
1454 | 1.49M | |
1455 | 1.49M | void *Mem = C.Allocate(Size, alignof(MemberExpr)); |
1456 | 1.49M | MemberExpr *E = new (Mem) |
1457 | 1.49M | MemberExpr(base, isarrow, OperatorLoc, memberdecl, nameinfo, ty, vk, ok); |
1458 | 1.49M | |
1459 | 1.49M | if (hasQualOrFound1.49M ) { |
1460 | 15.9k | // FIXME: Wrong. We should be looking at the member declaration we found. |
1461 | 15.9k | if (QualifierLoc && 15.9k QualifierLoc.getNestedNameSpecifier()->isDependent()6.54k ) { |
1462 | 2 | E->setValueDependent(true); |
1463 | 2 | E->setTypeDependent(true); |
1464 | 2 | E->setInstantiationDependent(true); |
1465 | 2 | } |
1466 | 15.9k | else if (15.9k QualifierLoc && |
1467 | 6.54k | QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) |
1468 | 0 | E->setInstantiationDependent(true); |
1469 | 15.9k | |
1470 | 15.9k | E->HasQualifierOrFoundDecl = true; |
1471 | 15.9k | |
1472 | 15.9k | MemberExprNameQualifier *NQ = |
1473 | 15.9k | E->getTrailingObjects<MemberExprNameQualifier>(); |
1474 | 15.9k | NQ->QualifierLoc = QualifierLoc; |
1475 | 15.9k | NQ->FoundDecl = founddecl; |
1476 | 15.9k | } |
1477 | 1.49M | |
1478 | 1.49M | E->HasTemplateKWAndArgsInfo = (targs || TemplateKWLoc.isValid()); |
1479 | 1.49M | |
1480 | 1.49M | if (targs1.49M ) { |
1481 | 1.18k | bool Dependent = false; |
1482 | 1.18k | bool InstantiationDependent = false; |
1483 | 1.18k | bool ContainsUnexpandedParameterPack = false; |
1484 | 1.18k | E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1485 | 1.18k | TemplateKWLoc, *targs, E->getTrailingObjects<TemplateArgumentLoc>(), |
1486 | 1.18k | Dependent, InstantiationDependent, ContainsUnexpandedParameterPack); |
1487 | 1.18k | if (InstantiationDependent) |
1488 | 0 | E->setInstantiationDependent(true); |
1489 | 1.49M | } else if (1.49M TemplateKWLoc.isValid()1.49M ) { |
1490 | 29 | E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom( |
1491 | 29 | TemplateKWLoc); |
1492 | 29 | } |
1493 | 1.49M | |
1494 | 1.49M | return E; |
1495 | 1.49M | } |
1496 | | |
1497 | 7.92M | SourceLocation MemberExpr::getLocStart() const { |
1498 | 7.92M | if (isImplicitAccess()7.92M ) { |
1499 | 2.76M | if (hasQualifier()) |
1500 | 13.5k | return getQualifierLoc().getBeginLoc(); |
1501 | 2.75M | return MemberLoc; |
1502 | 2.75M | } |
1503 | 5.16M | |
1504 | 5.16M | // FIXME: We don't want this to happen. Rather, we should be able to |
1505 | 5.16M | // detect all kinds of implicit accesses more cleanly. |
1506 | 5.16M | SourceLocation BaseStartLoc = getBase()->getLocStart(); |
1507 | 5.16M | if (BaseStartLoc.isValid()) |
1508 | 5.16M | return BaseStartLoc; |
1509 | 4 | return MemberLoc; |
1510 | 4 | } |
1511 | 579k | SourceLocation MemberExpr::getLocEnd() const { |
1512 | 579k | SourceLocation EndLoc = getMemberNameInfo().getEndLoc(); |
1513 | 579k | if (hasExplicitTemplateArgs()) |
1514 | 1.18k | EndLoc = getRAngleLoc(); |
1515 | 578k | else if (578k EndLoc.isInvalid()578k ) |
1516 | 49.0k | EndLoc = getBase()->getLocEnd(); |
1517 | 579k | return EndLoc; |
1518 | 579k | } |
1519 | | |
1520 | 0 | bool CastExpr::CastConsistency() const { |
1521 | 0 | switch (getCastKind()) { |
1522 | 0 | case CK_DerivedToBase: |
1523 | 0 | case CK_UncheckedDerivedToBase: |
1524 | 0 | case CK_DerivedToBaseMemberPointer: |
1525 | 0 | case CK_BaseToDerived: |
1526 | 0 | case CK_BaseToDerivedMemberPointer: |
1527 | 0 | assert(!path_empty() && "Cast kind should have a base path!"); |
1528 | 0 | break; |
1529 | 0 |
|
1530 | 0 | case CK_CPointerToObjCPointerCast: |
1531 | 0 | assert(getType()->isObjCObjectPointerType()); |
1532 | 0 | assert(getSubExpr()->getType()->isPointerType()); |
1533 | 0 | goto CheckNoBasePath; |
1534 | 0 |
|
1535 | 0 | case CK_BlockPointerToObjCPointerCast: |
1536 | 0 | assert(getType()->isObjCObjectPointerType()); |
1537 | 0 | assert(getSubExpr()->getType()->isBlockPointerType()); |
1538 | 0 | goto CheckNoBasePath; |
1539 | 0 |
|
1540 | 0 | case CK_ReinterpretMemberPointer: |
1541 | 0 | assert(getType()->isMemberPointerType()); |
1542 | 0 | assert(getSubExpr()->getType()->isMemberPointerType()); |
1543 | 0 | goto CheckNoBasePath; |
1544 | 0 |
|
1545 | 0 | case CK_BitCast: |
1546 | 0 | // Arbitrary casts to C pointer types count as bitcasts. |
1547 | 0 | // Otherwise, we should only have block and ObjC pointer casts |
1548 | 0 | // here if they stay within the type kind. |
1549 | 0 | if (!getType()->isPointerType()0 ) { |
1550 | 0 | assert(getType()->isObjCObjectPointerType() == |
1551 | 0 | getSubExpr()->getType()->isObjCObjectPointerType()); |
1552 | 0 | assert(getType()->isBlockPointerType() == |
1553 | 0 | getSubExpr()->getType()->isBlockPointerType()); |
1554 | 0 | } |
1555 | 0 | goto CheckNoBasePath; |
1556 | 0 |
|
1557 | 0 | case CK_AnyPointerToBlockPointerCast: |
1558 | 0 | assert(getType()->isBlockPointerType()); |
1559 | 0 | assert(getSubExpr()->getType()->isAnyPointerType() && |
1560 | 0 | !getSubExpr()->getType()->isBlockPointerType()); |
1561 | 0 | goto CheckNoBasePath; |
1562 | 0 |
|
1563 | 0 | case CK_CopyAndAutoreleaseBlockObject: |
1564 | 0 | assert(getType()->isBlockPointerType()); |
1565 | 0 | assert(getSubExpr()->getType()->isBlockPointerType()); |
1566 | 0 | goto CheckNoBasePath; |
1567 | 0 |
|
1568 | 0 | case CK_FunctionToPointerDecay: |
1569 | 0 | assert(getType()->isPointerType()); |
1570 | 0 | assert(getSubExpr()->getType()->isFunctionType()); |
1571 | 0 | goto CheckNoBasePath; |
1572 | 0 |
|
1573 | 0 | case CK_AddressSpaceConversion: |
1574 | 0 | assert(getType()->isPointerType() || getType()->isBlockPointerType()); |
1575 | 0 | assert(getSubExpr()->getType()->isPointerType() || |
1576 | 0 | getSubExpr()->getType()->isBlockPointerType()); |
1577 | 0 | assert(getType()->getPointeeType().getAddressSpace() != |
1578 | 0 | getSubExpr()->getType()->getPointeeType().getAddressSpace()); |
1579 | 0 | LLVM_FALLTHROUGH; |
1580 | 0 | // These should not have an inheritance path. |
1581 | 0 | case CK_Dynamic: |
1582 | 0 | case CK_ToUnion: |
1583 | 0 | case CK_ArrayToPointerDecay: |
1584 | 0 | case CK_NullToMemberPointer: |
1585 | 0 | case CK_NullToPointer: |
1586 | 0 | case CK_ConstructorConversion: |
1587 | 0 | case CK_IntegralToPointer: |
1588 | 0 | case CK_PointerToIntegral: |
1589 | 0 | case CK_ToVoid: |
1590 | 0 | case CK_VectorSplat: |
1591 | 0 | case CK_IntegralCast: |
1592 | 0 | case CK_BooleanToSignedIntegral: |
1593 | 0 | case CK_IntegralToFloating: |
1594 | 0 | case CK_FloatingToIntegral: |
1595 | 0 | case CK_FloatingCast: |
1596 | 0 | case CK_ObjCObjectLValueCast: |
1597 | 0 | case CK_FloatingRealToComplex: |
1598 | 0 | case CK_FloatingComplexToReal: |
1599 | 0 | case CK_FloatingComplexCast: |
1600 | 0 | case CK_FloatingComplexToIntegralComplex: |
1601 | 0 | case CK_IntegralRealToComplex: |
1602 | 0 | case CK_IntegralComplexToReal: |
1603 | 0 | case CK_IntegralComplexCast: |
1604 | 0 | case CK_IntegralComplexToFloatingComplex: |
1605 | 0 | case CK_ARCProduceObject: |
1606 | 0 | case CK_ARCConsumeObject: |
1607 | 0 | case CK_ARCReclaimReturnedObject: |
1608 | 0 | case CK_ARCExtendBlockObject: |
1609 | 0 | case CK_ZeroToOCLEvent: |
1610 | 0 | case CK_ZeroToOCLQueue: |
1611 | 0 | case CK_IntToOCLSampler: |
1612 | 0 | assert(!getType()->isBooleanType() && "unheralded conversion to bool"); |
1613 | 0 | goto CheckNoBasePath; |
1614 | 0 |
|
1615 | 0 | case CK_Dependent: |
1616 | 0 | case CK_LValueToRValue: |
1617 | 0 | case CK_NoOp: |
1618 | 0 | case CK_AtomicToNonAtomic: |
1619 | 0 | case CK_NonAtomicToAtomic: |
1620 | 0 | case CK_PointerToBoolean: |
1621 | 0 | case CK_IntegralToBoolean: |
1622 | 0 | case CK_FloatingToBoolean: |
1623 | 0 | case CK_MemberPointerToBoolean: |
1624 | 0 | case CK_FloatingComplexToBoolean: |
1625 | 0 | case CK_IntegralComplexToBoolean: |
1626 | 0 | case CK_LValueBitCast: // -> bool& |
1627 | 0 | case CK_UserDefinedConversion: // operator bool() |
1628 | 0 | case CK_BuiltinFnToFnPtr: |
1629 | 0 | CheckNoBasePath: |
1630 | 0 | assert(path_empty() && "Cast kind should not have a base path!"); |
1631 | 0 | break; |
1632 | 0 | } |
1633 | 0 | return true; |
1634 | 0 | } |
1635 | | |
1636 | 1.24k | const char *CastExpr::getCastKindName() const { |
1637 | 1.24k | switch (getCastKind()) { |
1638 | 1.24k | #define CAST_OPERATION(Name) case CK_##Name: return #Name; |
1639 | 0 | #include "clang/AST/OperationKinds.def" |
1640 | 1.24k | } |
1641 | 0 | llvm_unreachable0 ("Unhandled cast kind!"); |
1642 | 0 | } |
1643 | | |
1644 | | namespace { |
1645 | 245k | Expr *skipImplicitTemporary(Expr *expr) { |
1646 | 245k | // Skip through reference binding to temporary. |
1647 | 245k | if (MaterializeTemporaryExpr *Materialize |
1648 | 245k | = dyn_cast<MaterializeTemporaryExpr>(expr)) |
1649 | 81 | expr = Materialize->GetTemporaryExpr(); |
1650 | 245k | |
1651 | 245k | // Skip any temporary bindings; they're implicit. |
1652 | 245k | if (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(expr)) |
1653 | 1.29k | expr = Binder->getSubExpr(); |
1654 | 245k | |
1655 | 245k | return expr; |
1656 | 245k | } |
1657 | | } |
1658 | | |
1659 | 229k | Expr *CastExpr::getSubExprAsWritten() { |
1660 | 229k | Expr *SubExpr = nullptr; |
1661 | 229k | CastExpr *E = this; |
1662 | 245k | do { |
1663 | 245k | SubExpr = skipImplicitTemporary(E->getSubExpr()); |
1664 | 245k | |
1665 | 245k | // Conversions by constructor and conversion functions have a |
1666 | 245k | // subexpression describing the call; strip it off. |
1667 | 245k | if (E->getCastKind() == CK_ConstructorConversion) |
1668 | 150 | SubExpr = |
1669 | 150 | skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr)->getArg(0)); |
1670 | 245k | else if (245k E->getCastKind() == CK_UserDefinedConversion245k ) { |
1671 | 119 | assert((isa<CXXMemberCallExpr>(SubExpr) || |
1672 | 119 | isa<BlockExpr>(SubExpr)) && |
1673 | 119 | "Unexpected SubExpr for CK_UserDefinedConversion."); |
1674 | 119 | if (isa<CXXMemberCallExpr>(SubExpr)) |
1675 | 118 | SubExpr = cast<CXXMemberCallExpr>(SubExpr)->getImplicitObjectArgument(); |
1676 | 245k | } |
1677 | 245k | |
1678 | 245k | // If the subexpression we're left with is an implicit cast, look |
1679 | 245k | // through that, too. |
1680 | 245k | } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr))); |
1681 | 229k | |
1682 | 229k | return SubExpr; |
1683 | 229k | } |
1684 | | |
1685 | 412k | CXXBaseSpecifier **CastExpr::path_buffer() { |
1686 | 412k | switch (getStmtClass()) { |
1687 | 412k | #define ABSTRACT_STMT(x) |
1688 | 412k | #define CASTEXPR(Type, Base) \ |
1689 | 412k | case Stmt::Type##Class: \ |
1690 | 412k | return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>(); |
1691 | 412k | #define STMT(Type, Base) |
1692 | 412k | #include "clang/AST/StmtNodes.inc"412k |
1693 | 0 | default: |
1694 | 0 | llvm_unreachable("non-cast expressions not possible here"); |
1695 | 0 | } |
1696 | 0 | } |
1697 | | |
1698 | | const FieldDecl *CastExpr::getTargetFieldForToUnionCast(QualType unionType, |
1699 | 4 | QualType opType) { |
1700 | 4 | auto RD = unionType->castAs<RecordType>()->getDecl(); |
1701 | 4 | return getTargetFieldForToUnionCast(RD, opType); |
1702 | 4 | } |
1703 | | |
1704 | | const FieldDecl *CastExpr::getTargetFieldForToUnionCast(const RecordDecl *RD, |
1705 | 28 | QualType OpType) { |
1706 | 28 | auto &Ctx = RD->getASTContext(); |
1707 | 28 | RecordDecl::field_iterator Field, FieldEnd; |
1708 | 28 | for (Field = RD->field_begin(), FieldEnd = RD->field_end(); |
1709 | 47 | Field != FieldEnd47 ; ++Field19 ) { |
1710 | 44 | if (Ctx.hasSameUnqualifiedType(Field->getType(), OpType) && |
1711 | 44 | !Field->isUnnamedBitfield()26 ) { |
1712 | 25 | return *Field; |
1713 | 25 | } |
1714 | 44 | } |
1715 | 3 | return nullptr; |
1716 | 28 | } |
1717 | | |
1718 | | ImplicitCastExpr *ImplicitCastExpr::Create(const ASTContext &C, QualType T, |
1719 | | CastKind Kind, Expr *Operand, |
1720 | | const CXXCastPath *BasePath, |
1721 | 11.8M | ExprValueKind VK) { |
1722 | 11.8M | unsigned PathSize = (BasePath ? BasePath->size()196k : 011.6M ); |
1723 | 11.8M | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
1724 | 11.8M | ImplicitCastExpr *E = |
1725 | 11.8M | new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); |
1726 | 11.8M | if (PathSize) |
1727 | 118k | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
1728 | 118k | E->getTrailingObjects<CXXBaseSpecifier *>()); |
1729 | 11.8M | return E; |
1730 | 11.8M | } |
1731 | | |
1732 | | ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(const ASTContext &C, |
1733 | 21.3k | unsigned PathSize) { |
1734 | 21.3k | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
1735 | 21.3k | return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize); |
1736 | 21.3k | } |
1737 | | |
1738 | | |
1739 | | CStyleCastExpr *CStyleCastExpr::Create(const ASTContext &C, QualType T, |
1740 | | ExprValueKind VK, CastKind K, Expr *Op, |
1741 | | const CXXCastPath *BasePath, |
1742 | | TypeSourceInfo *WrittenTy, |
1743 | 2.03M | SourceLocation L, SourceLocation R) { |
1744 | 2.03M | unsigned PathSize = (BasePath ? BasePath->size()2.03M : 01.67k ); |
1745 | 2.03M | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
1746 | 2.03M | CStyleCastExpr *E = |
1747 | 2.03M | new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); |
1748 | 2.03M | if (PathSize) |
1749 | 459 | std::uninitialized_copy_n(BasePath->data(), BasePath->size(), |
1750 | 459 | E->getTrailingObjects<CXXBaseSpecifier *>()); |
1751 | 2.03M | return E; |
1752 | 2.03M | } |
1753 | | |
1754 | | CStyleCastExpr *CStyleCastExpr::CreateEmpty(const ASTContext &C, |
1755 | 207 | unsigned PathSize) { |
1756 | 207 | void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize)); |
1757 | 207 | return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize); |
1758 | 207 | } |
1759 | | |
1760 | | /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it |
1761 | | /// corresponds to, e.g. "<<=". |
1762 | 154k | StringRef BinaryOperator::getOpcodeStr(Opcode Op) { |
1763 | 154k | switch (Op) { |
1764 | 154k | #define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling; |
1765 | 3 | #include "clang/AST/OperationKinds.def" |
1766 | 154k | } |
1767 | 0 | llvm_unreachable0 ("Invalid OpCode!"); |
1768 | 0 | } |
1769 | | |
1770 | | BinaryOperatorKind |
1771 | 2.47k | BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { |
1772 | 2.47k | switch (OO) { |
1773 | 0 | default: 0 llvm_unreachable0 ("Not an overloadable binary operator"); |
1774 | 110 | case OO_Plus: return BO_Add; |
1775 | 1 | case OO_Minus: return BO_Sub; |
1776 | 0 | case OO_Star: return BO_Mul; |
1777 | 0 | case OO_Slash: return BO_Div; |
1778 | 2 | case OO_Percent: return BO_Rem; |
1779 | 0 | case OO_Caret: return BO_Xor; |
1780 | 2 | case OO_Amp: return BO_And; |
1781 | 0 | case OO_Pipe: return BO_Or; |
1782 | 0 | case OO_Equal: return BO_Assign; |
1783 | 43 | case OO_Less: return BO_LT; |
1784 | 2 | case OO_Greater: return BO_GT; |
1785 | 12 | case OO_PlusEqual: return BO_AddAssign; |
1786 | 0 | case OO_MinusEqual: return BO_SubAssign; |
1787 | 0 | case OO_StarEqual: return BO_MulAssign; |
1788 | 0 | case OO_SlashEqual: return BO_DivAssign; |
1789 | 0 | case OO_PercentEqual: return BO_RemAssign; |
1790 | 0 | case OO_CaretEqual: return BO_XorAssign; |
1791 | 0 | case OO_AmpEqual: return BO_AndAssign; |
1792 | 0 | case OO_PipeEqual: return BO_OrAssign; |
1793 | 5 | case OO_LessLess: return BO_Shl; |
1794 | 0 | case OO_GreaterGreater: return BO_Shr; |
1795 | 0 | case OO_LessLessEqual: return BO_ShlAssign; |
1796 | 0 | case OO_GreaterGreaterEqual: return BO_ShrAssign; |
1797 | 1.22k | case OO_EqualEqual: return BO_EQ; |
1798 | 1.06k | case OO_ExclaimEqual: return BO_NE; |
1799 | 0 | case OO_LessEqual: return BO_LE; |
1800 | 4 | case OO_GreaterEqual: return BO_GE; |
1801 | 4 | case OO_AmpAmp: return BO_LAnd; |
1802 | 0 | case OO_PipePipe: return BO_LOr; |
1803 | 0 | case OO_Comma: return BO_Comma; |
1804 | 0 | case OO_ArrowStar: return BO_PtrMemI; |
1805 | 0 | } |
1806 | 0 | } |
1807 | | |
1808 | 489k | OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { |
1809 | 489k | static const OverloadedOperatorKind OverOps[] = { |
1810 | 489k | /* .* Cannot be overloaded */OO_None, OO_ArrowStar, |
1811 | 489k | OO_Star, OO_Slash, OO_Percent, |
1812 | 489k | OO_Plus, OO_Minus, |
1813 | 489k | OO_LessLess, OO_GreaterGreater, |
1814 | 489k | OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, |
1815 | 489k | OO_EqualEqual, OO_ExclaimEqual, |
1816 | 489k | OO_Amp, |
1817 | 489k | OO_Caret, |
1818 | 489k | OO_Pipe, |
1819 | 489k | OO_AmpAmp, |
1820 | 489k | OO_PipePipe, |
1821 | 489k | OO_Equal, OO_StarEqual, |
1822 | 489k | OO_SlashEqual, OO_PercentEqual, |
1823 | 489k | OO_PlusEqual, OO_MinusEqual, |
1824 | 489k | OO_LessLessEqual, OO_GreaterGreaterEqual, |
1825 | 489k | OO_AmpEqual, OO_CaretEqual, |
1826 | 489k | OO_PipeEqual, |
1827 | 489k | OO_Comma |
1828 | 489k | }; |
1829 | 489k | return OverOps[Opc]; |
1830 | 489k | } |
1831 | | |
1832 | | bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, |
1833 | | Opcode Opc, |
1834 | 25.1k | Expr *LHS, Expr *RHS) { |
1835 | 25.1k | if (Opc != BO_Add) |
1836 | 8.24k | return false; |
1837 | 16.9k | |
1838 | 16.9k | // Check that we have one pointer and one integer operand. |
1839 | 16.9k | Expr *PExp; |
1840 | 16.9k | if (LHS->getType()->isPointerType()16.9k ) { |
1841 | 16.8k | if (!RHS->getType()->isIntegerType()) |
1842 | 0 | return false; |
1843 | 16.8k | PExp = LHS; |
1844 | 16.9k | } else if (71 RHS->getType()->isPointerType()71 ) { |
1845 | 70 | if (!LHS->getType()->isIntegerType()) |
1846 | 0 | return false; |
1847 | 70 | PExp = RHS; |
1848 | 71 | } else { |
1849 | 1 | return false; |
1850 | 1 | } |
1851 | 16.9k | |
1852 | 16.9k | // Check that the pointer is a nullptr. |
1853 | 16.9k | if (16.9k !PExp->IgnoreParenCasts() |
1854 | 16.9k | ->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull)) |
1855 | 16.5k | return false; |
1856 | 399 | |
1857 | 399 | // Check that the pointee type is char-sized. |
1858 | 399 | const PointerType *PTy = PExp->getType()->getAs<PointerType>(); |
1859 | 399 | if (!PTy || 399 !PTy->getPointeeType()->isCharType()399 ) |
1860 | 369 | return false; |
1861 | 30 | |
1862 | 30 | return true; |
1863 | 30 | } |
1864 | | InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc, |
1865 | | ArrayRef<Expr*> initExprs, SourceLocation rbraceloc) |
1866 | | : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false, |
1867 | | false, false), |
1868 | | InitExprs(C, initExprs.size()), |
1869 | | LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(nullptr, true) |
1870 | 228k | { |
1871 | 228k | sawArrayRangeDesignator(false); |
1872 | 1.93M | for (unsigned I = 0; I != initExprs.size()1.93M ; ++I1.70M ) { |
1873 | 1.70M | if (initExprs[I]->isTypeDependent()) |
1874 | 584 | ExprBits.TypeDependent = true; |
1875 | 1.70M | if (initExprs[I]->isValueDependent()) |
1876 | 600 | ExprBits.ValueDependent = true; |
1877 | 1.70M | if (initExprs[I]->isInstantiationDependent()) |
1878 | 600 | ExprBits.InstantiationDependent = true; |
1879 | 1.70M | if (initExprs[I]->containsUnexpandedParameterPack()) |
1880 | 6 | ExprBits.ContainsUnexpandedParameterPack = true; |
1881 | 1.70M | } |
1882 | 228k | |
1883 | 228k | InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end()); |
1884 | 228k | } |
1885 | | |
1886 | 105k | void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) { |
1887 | 105k | if (NumInits > InitExprs.size()) |
1888 | 92.5k | InitExprs.reserve(C, NumInits); |
1889 | 105k | } |
1890 | | |
1891 | 3.93k | void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) { |
1892 | 3.93k | InitExprs.resize(C, NumInits, nullptr); |
1893 | 3.93k | } |
1894 | | |
1895 | 1.70M | Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) { |
1896 | 1.70M | if (Init >= InitExprs.size()1.70M ) { |
1897 | 1.69M | InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr); |
1898 | 1.69M | setInit(Init, expr); |
1899 | 1.69M | return nullptr; |
1900 | 1.69M | } |
1901 | 2.69k | |
1902 | 2.69k | Expr *Result = cast_or_null<Expr>(InitExprs[Init]); |
1903 | 2.69k | setInit(Init, expr); |
1904 | 2.69k | return Result; |
1905 | 2.69k | } |
1906 | | |
1907 | 3.60k | void InitListExpr::setArrayFiller(Expr *filler) { |
1908 | 3.60k | assert(!hasArrayFiller() && "Filler already set!"); |
1909 | 3.60k | ArrayFillerOrUnionFieldInit = filler; |
1910 | 3.60k | // Fill out any "holes" in the array due to designated initializers. |
1911 | 3.60k | Expr **inits = getInits(); |
1912 | 18.0k | for (unsigned i = 0, e = getNumInits(); i != e18.0k ; ++i14.4k ) |
1913 | 14.4k | if (14.4k inits[i] == nullptr14.4k ) |
1914 | 5.42k | inits[i] = filler; |
1915 | 3.60k | } |
1916 | | |
1917 | 2.30k | bool InitListExpr::isStringLiteralInit() const { |
1918 | 2.30k | if (getNumInits() != 1) |
1919 | 1.01k | return false; |
1920 | 1.29k | const ArrayType *AT = getType()->getAsArrayTypeUnsafe(); |
1921 | 1.29k | if (!AT || 1.29k !AT->getElementType()->isIntegerType()1.29k ) |
1922 | 43 | return false; |
1923 | 1.25k | // It is possible for getInit() to return null. |
1924 | 1.25k | const Expr *Init = getInit(0); |
1925 | 1.25k | if (!Init) |
1926 | 0 | return false; |
1927 | 1.25k | Init = Init->IgnoreParens(); |
1928 | 1.24k | return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init); |
1929 | 2.30k | } |
1930 | | |
1931 | 252k | bool InitListExpr::isTransparent() const { |
1932 | 252k | assert(isSemanticForm() && "syntactic form never semantically transparent"); |
1933 | 252k | |
1934 | 252k | // A glvalue InitListExpr is always just sugar. |
1935 | 252k | if (isGLValue()252k ) { |
1936 | 4 | assert(getNumInits() == 1 && "multiple inits in glvalue init list"); |
1937 | 4 | return true; |
1938 | 4 | } |
1939 | 252k | |
1940 | 252k | // Otherwise, we're sugar if and only if we have exactly one initializer that |
1941 | 252k | // is of the same type. |
1942 | 252k | if (252k getNumInits() != 1 || 252k !getInit(0)21.4k ) |
1943 | 231k | return false; |
1944 | 21.4k | |
1945 | 21.4k | // Don't confuse aggregate initialization of a struct X { X &x; }; with a |
1946 | 21.4k | // transparent struct copy. |
1947 | 21.4k | if (21.4k !getInit(0)->isRValue() && 21.4k getType()->isRecordType()267 ) |
1948 | 183 | return false; |
1949 | 21.3k | |
1950 | 21.3k | return getType().getCanonicalType() == |
1951 | 21.3k | getInit(0)->getType().getCanonicalType(); |
1952 | 21.3k | } |
1953 | | |
1954 | 563k | SourceLocation InitListExpr::getLocStart() const { |
1955 | 563k | if (InitListExpr *SyntacticForm = getSyntacticForm()) |
1956 | 118k | return SyntacticForm->getLocStart(); |
1957 | 445k | SourceLocation Beg = LBraceLoc; |
1958 | 445k | if (Beg.isInvalid()445k ) { |
1959 | 169 | // Find the first non-null initializer. |
1960 | 169 | for (InitExprsTy::const_iterator I = InitExprs.begin(), |
1961 | 169 | E = InitExprs.end(); |
1962 | 169 | I != E169 ; ++I0 ) { |
1963 | 169 | if (Stmt *S169 = *I) { |
1964 | 169 | Beg = S->getLocStart(); |
1965 | 169 | break; |
1966 | 169 | } |
1967 | 169 | } |
1968 | 169 | } |
1969 | 563k | return Beg; |
1970 | 563k | } |
1971 | | |
1972 | 640k | SourceLocation InitListExpr::getLocEnd() const { |
1973 | 640k | if (InitListExpr *SyntacticForm = getSyntacticForm()) |
1974 | 188k | return SyntacticForm->getLocEnd(); |
1975 | 452k | SourceLocation End = RBraceLoc; |
1976 | 452k | if (End.isInvalid()452k ) { |
1977 | 15 | // Find the first non-null initializer from the end. |
1978 | 15 | for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(), |
1979 | 15 | E = InitExprs.rend(); |
1980 | 15 | I != E15 ; ++I0 ) { |
1981 | 15 | if (Stmt *S15 = *I) { |
1982 | 15 | End = S->getLocEnd(); |
1983 | 15 | break; |
1984 | 15 | } |
1985 | 15 | } |
1986 | 15 | } |
1987 | 640k | return End; |
1988 | 640k | } |
1989 | | |
1990 | | /// getFunctionType - Return the underlying function type for this block. |
1991 | | /// |
1992 | 984 | const FunctionProtoType *BlockExpr::getFunctionType() const { |
1993 | 984 | // The block pointer is never sugared, but the function type might be. |
1994 | 984 | return cast<BlockPointerType>(getType()) |
1995 | 984 | ->getPointeeType()->castAs<FunctionProtoType>(); |
1996 | 984 | } |
1997 | | |
1998 | 13.8k | SourceLocation BlockExpr::getCaretLocation() const { |
1999 | 13.8k | return TheBlock->getCaretLocation(); |
2000 | 13.8k | } |
2001 | 3.24k | const Stmt *BlockExpr::getBody() const { |
2002 | 3.24k | return TheBlock->getBody(); |
2003 | 3.24k | } |
2004 | 813 | Stmt *BlockExpr::getBody() { |
2005 | 813 | return TheBlock->getBody(); |
2006 | 813 | } |
2007 | | |
2008 | | |
2009 | | //===----------------------------------------------------------------------===// |
2010 | | // Generic Expression Routines |
2011 | | //===----------------------------------------------------------------------===// |
2012 | | |
2013 | | /// isUnusedResultAWarning - Return true if this immediate expression should |
2014 | | /// be warned about if the result is unused. If so, fill in Loc and Ranges |
2015 | | /// with location to warn on and the source range[s] to report with the |
2016 | | /// warning. |
2017 | | bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, |
2018 | | SourceRange &R1, SourceRange &R2, |
2019 | 1.84M | ASTContext &Ctx) const { |
2020 | 1.84M | // Don't warn if the expr is type dependent. The type could end up |
2021 | 1.84M | // instantiating to void. |
2022 | 1.84M | if (isTypeDependent()) |
2023 | 139k | return false; |
2024 | 1.70M | |
2025 | 1.70M | switch (getStmtClass()) { |
2026 | 3.02k | default: |
2027 | 3.02k | if (getType()->isVoidType()) |
2028 | 1.04k | return false; |
2029 | 1.98k | WarnE = this; |
2030 | 1.98k | Loc = getExprLoc(); |
2031 | 1.98k | R1 = getSourceRange(); |
2032 | 1.98k | return true; |
2033 | 18.5k | case ParenExprClass: |
2034 | 18.5k | return cast<ParenExpr>(this)->getSubExpr()-> |
2035 | 18.5k | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2036 | 0 | case GenericSelectionExprClass: |
2037 | 0 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> |
2038 | 0 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2039 | 6 | case ChooseExprClass: |
2040 | 6 | return cast<ChooseExpr>(this)->getChosenSubExpr()-> |
2041 | 6 | isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2042 | 131k | case UnaryOperatorClass: { |
2043 | 131k | const UnaryOperator *UO = cast<UnaryOperator>(this); |
2044 | 131k | |
2045 | 131k | switch (UO->getOpcode()) { |
2046 | 185 | case UO_Plus: |
2047 | 185 | case UO_Minus: |
2048 | 185 | case UO_AddrOf: |
2049 | 185 | case UO_Not: |
2050 | 185 | case UO_LNot: |
2051 | 185 | case UO_Deref: |
2052 | 185 | break; |
2053 | 123k | case UO_Coawait: |
2054 | 123k | // This is just the 'operator co_await' call inside the guts of a |
2055 | 123k | // dependent co_await call. |
2056 | 123k | case UO_PostInc: |
2057 | 123k | case UO_PostDec: |
2058 | 123k | case UO_PreInc: |
2059 | 123k | case UO_PreDec: // ++/-- |
2060 | 123k | return false; // Not a warning. |
2061 | 16 | case UO_Real: |
2062 | 16 | case UO_Imag: |
2063 | 16 | // accessing a piece of a volatile complex is a side-effect. |
2064 | 16 | if (Ctx.getCanonicalType(UO->getSubExpr()->getType()) |
2065 | 16 | .isVolatileQualified()) |
2066 | 11 | return false; |
2067 | 5 | break; |
2068 | 8.06k | case UO_Extension: |
2069 | 8.06k | return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2070 | 190 | } |
2071 | 190 | WarnE = this; |
2072 | 190 | Loc = UO->getOperatorLoc(); |
2073 | 190 | R1 = UO->getSubExpr()->getSourceRange(); |
2074 | 190 | return true; |
2075 | 190 | } |
2076 | 933k | case BinaryOperatorClass: { |
2077 | 933k | const BinaryOperator *BO = cast<BinaryOperator>(this); |
2078 | 933k | switch (BO->getOpcode()) { |
2079 | 905k | default: |
2080 | 905k | break; |
2081 | 933k | // Consider the RHS of comma for side effects. LHS was checked by |
2082 | 933k | // Sema::CheckCommaOperands. |
2083 | 28.6k | case BO_Comma: |
2084 | 28.6k | // ((foo = <blah>), 0) is an idiom for hiding the result (and |
2085 | 28.6k | // lvalue-ness) of an assignment written in a macro. |
2086 | 28.6k | if (IntegerLiteral *IE = |
2087 | 28.6k | dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens())) |
2088 | 85 | if (85 IE->getValue() == 085 ) |
2089 | 42 | return false; |
2090 | 28.6k | return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2091 | 28.6k | // Consider '||', '&&' to have side effects if the LHS or RHS does. |
2092 | 164 | case BO_LAnd: |
2093 | 164 | case BO_LOr: |
2094 | 164 | if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) || |
2095 | 138 | !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) |
2096 | 142 | return false; |
2097 | 22 | break; |
2098 | 905k | } |
2099 | 905k | if (905k BO->isAssignmentOp()905k ) |
2100 | 904k | return false; |
2101 | 374 | WarnE = this; |
2102 | 374 | Loc = BO->getOperatorLoc(); |
2103 | 374 | R1 = BO->getLHS()->getSourceRange(); |
2104 | 374 | R2 = BO->getRHS()->getSourceRange(); |
2105 | 374 | return true; |
2106 | 374 | } |
2107 | 72.0k | case CompoundAssignOperatorClass: |
2108 | 72.0k | case VAArgExprClass: |
2109 | 72.0k | case AtomicExprClass: |
2110 | 72.0k | return false; |
2111 | 72.0k | |
2112 | 4.02k | case ConditionalOperatorClass: { |
2113 | 4.02k | // If only one of the LHS or RHS is a warning, the operator might |
2114 | 4.02k | // be being used for control flow. Only warn if both the LHS and |
2115 | 4.02k | // RHS are warnings. |
2116 | 4.02k | const ConditionalOperator *Exp = cast<ConditionalOperator>(this); |
2117 | 4.02k | if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) |
2118 | 3.33k | return false; |
2119 | 688 | if (688 !Exp->getLHS()688 ) |
2120 | 0 | return true; |
2121 | 688 | return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2122 | 688 | } |
2123 | 688 | |
2124 | 123 | case MemberExprClass: |
2125 | 123 | WarnE = this; |
2126 | 123 | Loc = cast<MemberExpr>(this)->getMemberLoc(); |
2127 | 123 | R1 = SourceRange(Loc, Loc); |
2128 | 123 | R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); |
2129 | 123 | return true; |
2130 | 688 | |
2131 | 24 | case ArraySubscriptExprClass: |
2132 | 24 | WarnE = this; |
2133 | 24 | Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); |
2134 | 24 | R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); |
2135 | 24 | R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); |
2136 | 24 | return true; |
2137 | 688 | |
2138 | 28.3k | case CXXOperatorCallExprClass: { |
2139 | 28.3k | // Warn about operator ==,!=,<,>,<=, and >= even when user-defined operator |
2140 | 28.3k | // overloads as there is no reasonable way to define these such that they |
2141 | 28.3k | // have non-trivial, desirable side-effects. See the -Wunused-comparison |
2142 | 28.3k | // warning: operators == and != are commonly typo'ed, and so warning on them |
2143 | 28.3k | // provides additional value as well. If this list is updated, |
2144 | 28.3k | // DiagnoseUnusedComparison should be as well. |
2145 | 28.3k | const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this); |
2146 | 28.3k | switch (Op->getOperator()) { |
2147 | 28.3k | default: |
2148 | 28.3k | break; |
2149 | 18 | case OO_EqualEqual: |
2150 | 18 | case OO_ExclaimEqual: |
2151 | 18 | case OO_Less: |
2152 | 18 | case OO_Greater: |
2153 | 18 | case OO_GreaterEqual: |
2154 | 18 | case OO_LessEqual: |
2155 | 18 | if (Op->getCallReturnType(Ctx)->isReferenceType() || |
2156 | 17 | Op->getCallReturnType(Ctx)->isVoidType()) |
2157 | 2 | break; |
2158 | 16 | WarnE = this; |
2159 | 16 | Loc = Op->getOperatorLoc(); |
2160 | 16 | R1 = Op->getSourceRange(); |
2161 | 16 | return true; |
2162 | 28.3k | } |
2163 | 28.3k | |
2164 | 28.3k | // Fallthrough for generic call handling. |
2165 | 28.3k | LLVM_FALLTHROUGH28.3k ; |
2166 | 28.3k | } |
2167 | 473k | case CallExprClass: |
2168 | 473k | case CXXMemberCallExprClass: |
2169 | 473k | case UserDefinedLiteralClass: { |
2170 | 473k | // If this is a direct call, get the callee. |
2171 | 473k | const CallExpr *CE = cast<CallExpr>(this); |
2172 | 473k | if (const Decl *FD473k = CE->getCalleeDecl()) { |
2173 | 473k | const FunctionDecl *Func = dyn_cast<FunctionDecl>(FD); |
2174 | 468k | bool HasWarnUnusedResultAttr = Func ? Func->hasUnusedResultAttr() |
2175 | 4.37k | : FD->hasAttr<WarnUnusedResultAttr>(); |
2176 | 473k | |
2177 | 473k | // If the callee has attribute pure, const, or warn_unused_result, warn |
2178 | 473k | // about it. void foo() { strlen("bar"); } should warn. |
2179 | 473k | // |
2180 | 473k | // Note: If new cases are added here, DiagnoseUnusedExprResult should be |
2181 | 473k | // updated to match for QoI. |
2182 | 473k | if (HasWarnUnusedResultAttr || |
2183 | 473k | FD->hasAttr<PureAttr>()473k || FD->hasAttr<ConstAttr>()473k ) { |
2184 | 1.65k | WarnE = this; |
2185 | 1.65k | Loc = CE->getCallee()->getLocStart(); |
2186 | 1.65k | R1 = CE->getCallee()->getSourceRange(); |
2187 | 1.65k | |
2188 | 1.65k | if (unsigned NumArgs = CE->getNumArgs()) |
2189 | 1.62k | R2 = SourceRange(CE->getArg(0)->getLocStart(), |
2190 | 1.62k | CE->getArg(NumArgs-1)->getLocEnd()); |
2191 | 1.65k | return true; |
2192 | 1.65k | } |
2193 | 472k | } |
2194 | 472k | return false; |
2195 | 472k | } |
2196 | 472k | |
2197 | 472k | // If we don't know precisely what we're looking at, let's not warn. |
2198 | 8 | case UnresolvedLookupExprClass: |
2199 | 8 | case CXXUnresolvedConstructExprClass: |
2200 | 8 | return false; |
2201 | 8 | |
2202 | 335 | case CXXTemporaryObjectExprClass: |
2203 | 335 | case CXXConstructExprClass: { |
2204 | 335 | if (const CXXRecordDecl *Type335 = getType()->getAsCXXRecordDecl()) { |
2205 | 335 | if (Type->hasAttr<WarnUnusedAttr>()335 ) { |
2206 | 9 | WarnE = this; |
2207 | 9 | Loc = getLocStart(); |
2208 | 9 | R1 = getSourceRange(); |
2209 | 9 | return true; |
2210 | 9 | } |
2211 | 326 | } |
2212 | 326 | return false; |
2213 | 326 | } |
2214 | 326 | |
2215 | 5.49k | case ObjCMessageExprClass: { |
2216 | 5.49k | const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this); |
2217 | 5.49k | if (Ctx.getLangOpts().ObjCAutoRefCount && |
2218 | 584 | ME->isInstanceMessage() && |
2219 | 553 | !ME->getType()->isVoidType() && |
2220 | 5.49k | ME->getMethodFamily() == OMF_init169 ) { |
2221 | 23 | WarnE = this; |
2222 | 23 | Loc = getExprLoc(); |
2223 | 23 | R1 = ME->getSourceRange(); |
2224 | 23 | return true; |
2225 | 23 | } |
2226 | 5.47k | |
2227 | 5.47k | if (const ObjCMethodDecl *5.47k MD5.47k = ME->getMethodDecl()) |
2228 | 5.01k | if (5.01k MD->hasAttr<WarnUnusedResultAttr>()5.01k ) { |
2229 | 2 | WarnE = this; |
2230 | 2 | Loc = getExprLoc(); |
2231 | 2 | return true; |
2232 | 2 | } |
2233 | 5.47k | |
2234 | 5.47k | return false; |
2235 | 5.47k | } |
2236 | 5.47k | |
2237 | 0 | case ObjCPropertyRefExprClass: |
2238 | 0 | WarnE = this; |
2239 | 0 | Loc = getExprLoc(); |
2240 | 0 | R1 = getSourceRange(); |
2241 | 0 | return true; |
2242 | 5.47k | |
2243 | 945 | case PseudoObjectExprClass: { |
2244 | 945 | const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); |
2245 | 945 | |
2246 | 945 | // Only complain about things that have the form of a getter. |
2247 | 945 | if (isa<UnaryOperator>(PO->getSyntacticForm()) || |
2248 | 916 | isa<BinaryOperator>(PO->getSyntacticForm())) |
2249 | 854 | return false; |
2250 | 91 | |
2251 | 91 | WarnE = this; |
2252 | 91 | Loc = getExprLoc(); |
2253 | 91 | R1 = getSourceRange(); |
2254 | 91 | return true; |
2255 | 91 | } |
2256 | 91 | |
2257 | 8.12k | case StmtExprClass: { |
2258 | 8.12k | // Statement exprs don't logically have side effects themselves, but are |
2259 | 8.12k | // sometimes used in macros in ways that give them a type that is unused. |
2260 | 8.12k | // For example ({ blah; foo(); }) will end up with a type if foo has a type. |
2261 | 8.12k | // however, if the result of the stmt expr is dead, we don't want to emit a |
2262 | 8.12k | // warning. |
2263 | 8.12k | const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); |
2264 | 8.12k | if (!CS->body_empty()8.12k ) { |
2265 | 8.10k | if (const Expr *E = dyn_cast<Expr>(CS->body_back())) |
2266 | 3.46k | return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2267 | 4.64k | if (const LabelStmt *4.64k Label4.64k = dyn_cast<LabelStmt>(CS->body_back())) |
2268 | 0 | if (const Expr *0 E0 = dyn_cast<Expr>(Label->getSubStmt())) |
2269 | 0 | return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2270 | 4.66k | } |
2271 | 4.66k | |
2272 | 4.66k | if (4.66k getType()->isVoidType()4.66k ) |
2273 | 4.66k | return false; |
2274 | 0 | WarnE = this; |
2275 | 0 | Loc = cast<StmtExpr>(this)->getLParenLoc(); |
2276 | 0 | R1 = getSourceRange(); |
2277 | 0 | return true; |
2278 | 0 | } |
2279 | 23.3k | case CXXFunctionalCastExprClass: |
2280 | 23.3k | case CStyleCastExprClass: { |
2281 | 23.3k | // Ignore an explicit cast to void unless the operand is a non-trivial |
2282 | 23.3k | // volatile lvalue. |
2283 | 23.3k | const CastExpr *CE = cast<CastExpr>(this); |
2284 | 23.3k | if (CE->getCastKind() == CK_ToVoid23.3k ) { |
2285 | 22.4k | if (CE->getSubExpr()->isGLValue() && |
2286 | 22.4k | CE->getSubExpr()->getType().isVolatileQualified()6.08k ) { |
2287 | 122 | const DeclRefExpr *DRE = |
2288 | 122 | dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens()); |
2289 | 122 | if (!(DRE && 122 isa<VarDecl>(DRE->getDecl())6 && |
2290 | 122 | cast<VarDecl>(DRE->getDecl())->hasLocalStorage()6 )) { |
2291 | 120 | return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, |
2292 | 120 | R1, R2, Ctx); |
2293 | 120 | } |
2294 | 22.3k | } |
2295 | 22.3k | return false; |
2296 | 22.3k | } |
2297 | 868 | |
2298 | 868 | // If this is a cast to a constructor conversion, check the operand. |
2299 | 868 | // Otherwise, the result of the cast is unused. |
2300 | 868 | if (868 CE->getCastKind() == CK_ConstructorConversion868 ) |
2301 | 42 | return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2302 | 826 | |
2303 | 826 | WarnE = this; |
2304 | 826 | if (const CXXFunctionalCastExpr *CXXCE = |
2305 | 40 | dyn_cast<CXXFunctionalCastExpr>(this)) { |
2306 | 40 | Loc = CXXCE->getLocStart(); |
2307 | 40 | R1 = CXXCE->getSubExpr()->getSourceRange(); |
2308 | 826 | } else { |
2309 | 786 | const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this); |
2310 | 786 | Loc = CStyleCE->getLParenLoc(); |
2311 | 786 | R1 = CStyleCE->getSubExpr()->getSourceRange(); |
2312 | 786 | } |
2313 | 826 | return true; |
2314 | 826 | } |
2315 | 1.38k | case ImplicitCastExprClass: { |
2316 | 1.38k | const CastExpr *ICE = cast<ImplicitCastExpr>(this); |
2317 | 1.38k | |
2318 | 1.38k | // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect. |
2319 | 1.38k | if (ICE->getCastKind() == CK_LValueToRValue && |
2320 | 1.00k | ICE->getSubExpr()->getType().isVolatileQualified()) |
2321 | 40 | return false; |
2322 | 1.34k | |
2323 | 1.34k | return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2324 | 1.34k | } |
2325 | 0 | case CXXDefaultArgExprClass: |
2326 | 0 | return (cast<CXXDefaultArgExpr>(this) |
2327 | 0 | ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); |
2328 | 0 | case CXXDefaultInitExprClass: |
2329 | 0 | return (cast<CXXDefaultInitExpr>(this) |
2330 | 0 | ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)); |
2331 | 1.34k | |
2332 | 4.73k | case CXXNewExprClass: |
2333 | 4.73k | // FIXME: In theory, there might be new expressions that don't have side |
2334 | 4.73k | // effects (e.g. a placement new with an uninitialized POD). |
2335 | 4.73k | case CXXDeleteExprClass: |
2336 | 4.73k | return false; |
2337 | 0 | case MaterializeTemporaryExprClass: |
2338 | 0 | return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() |
2339 | 0 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2340 | 203 | case CXXBindTemporaryExprClass: |
2341 | 203 | return cast<CXXBindTemporaryExpr>(this)->getSubExpr() |
2342 | 203 | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2343 | 20.4k | case ExprWithCleanupsClass: |
2344 | 20.4k | return cast<ExprWithCleanups>(this)->getSubExpr() |
2345 | 20.4k | ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); |
2346 | 0 | } |
2347 | 0 | } |
2348 | | |
2349 | | /// isOBJCGCCandidate - Check if an expression is objc gc'able. |
2350 | | /// returns true, if it is; false otherwise. |
2351 | 495 | bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { |
2352 | 495 | const Expr *E = IgnoreParens(); |
2353 | 495 | switch (E->getStmtClass()) { |
2354 | 4 | default: |
2355 | 4 | return false; |
2356 | 64 | case ObjCIvarRefExprClass: |
2357 | 64 | return true; |
2358 | 15 | case Expr::UnaryOperatorClass: |
2359 | 15 | return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); |
2360 | 149 | case ImplicitCastExprClass: |
2361 | 149 | return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); |
2362 | 0 | case MaterializeTemporaryExprClass: |
2363 | 0 | return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr() |
2364 | 0 | ->isOBJCGCCandidate(Ctx); |
2365 | 3 | case CStyleCastExprClass: |
2366 | 3 | return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); |
2367 | 69 | case DeclRefExprClass: { |
2368 | 69 | const Decl *D = cast<DeclRefExpr>(E)->getDecl(); |
2369 | 69 | |
2370 | 69 | if (const VarDecl *VD69 = dyn_cast<VarDecl>(D)) { |
2371 | 69 | if (VD->hasGlobalStorage()) |
2372 | 56 | return true; |
2373 | 13 | QualType T = VD->getType(); |
2374 | 13 | // dereferencing to a pointer is always a gc'able candidate, |
2375 | 13 | // unless it is __weak. |
2376 | 13 | return T->isPointerType() && |
2377 | 11 | (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak); |
2378 | 69 | } |
2379 | 0 | return false; |
2380 | 0 | } |
2381 | 56 | case MemberExprClass: { |
2382 | 56 | const MemberExpr *M = cast<MemberExpr>(E); |
2383 | 56 | return M->getBase()->isOBJCGCCandidate(Ctx); |
2384 | 0 | } |
2385 | 135 | case ArraySubscriptExprClass: |
2386 | 135 | return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx); |
2387 | 0 | } |
2388 | 0 | } |
2389 | | |
2390 | 0 | bool Expr::isBoundMemberFunction(ASTContext &Ctx) const { |
2391 | 0 | if (isTypeDependent()) |
2392 | 0 | return false; |
2393 | 0 | return ClassifyLValue(Ctx) == Expr::LV_MemberFunction; |
2394 | 0 | } |
2395 | | |
2396 | 201k | QualType Expr::findBoundMemberType(const Expr *expr) { |
2397 | 201k | assert(expr->hasPlaceholderType(BuiltinType::BoundMember)); |
2398 | 201k | |
2399 | 201k | // Bound member expressions are always one of these possibilities: |
2400 | 201k | // x->m x.m x->*y x.*y |
2401 | 201k | // (possibly parenthesized) |
2402 | 201k | |
2403 | 201k | expr = expr->IgnoreParens(); |
2404 | 201k | if (const MemberExpr *mem201k = dyn_cast<MemberExpr>(expr)) { |
2405 | 201k | assert(isa<CXXMethodDecl>(mem->getMemberDecl())); |
2406 | 201k | return mem->getMemberDecl()->getType(); |
2407 | 201k | } |
2408 | 258 | |
2409 | 258 | if (const BinaryOperator *258 op258 = dyn_cast<BinaryOperator>(expr)) { |
2410 | 256 | QualType type = op->getRHS()->getType()->castAs<MemberPointerType>() |
2411 | 256 | ->getPointeeType(); |
2412 | 256 | assert(type->isFunctionType()); |
2413 | 256 | return type; |
2414 | 256 | } |
2415 | 2 | |
2416 | 258 | assert(isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr)); |
2417 | 2 | return QualType(); |
2418 | 2 | } |
2419 | | |
2420 | 199M | Expr* Expr::IgnoreParens() { |
2421 | 199M | Expr* E = this; |
2422 | 208M | while (true208M ) { |
2423 | 208M | if (ParenExpr* P208M = dyn_cast<ParenExpr>(E)) { |
2424 | 8.51M | E = P->getSubExpr(); |
2425 | 8.51M | continue; |
2426 | 8.51M | } |
2427 | 199M | if (UnaryOperator* 199M P199M = dyn_cast<UnaryOperator>(E)) { |
2428 | 4.93M | if (P->getOpcode() == UO_Extension4.93M ) { |
2429 | 135k | E = P->getSubExpr(); |
2430 | 135k | continue; |
2431 | 135k | } |
2432 | 199M | } |
2433 | 199M | if (GenericSelectionExpr* 199M P199M = dyn_cast<GenericSelectionExpr>(E)) { |
2434 | 403 | if (!P->isResultDependent()403 ) { |
2435 | 401 | E = P->getResultExpr(); |
2436 | 401 | continue; |
2437 | 401 | } |
2438 | 199M | } |
2439 | 199M | if (ChooseExpr* 199M P199M = dyn_cast<ChooseExpr>(E)) { |
2440 | 182 | if (!P->isConditionDependent()182 ) { |
2441 | 179 | E = P->getChosenSubExpr(); |
2442 | 179 | continue; |
2443 | 179 | } |
2444 | 199M | } |
2445 | 199M | return E; |
2446 | 199M | } |
2447 | 199M | } |
2448 | | |
2449 | | /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr |
2450 | | /// or CastExprs or ImplicitCastExprs, returning their operand. |
2451 | 48.3M | Expr *Expr::IgnoreParenCasts() { |
2452 | 48.3M | Expr *E = this; |
2453 | 58.9M | while (true58.9M ) { |
2454 | 58.9M | E = E->IgnoreParens(); |
2455 | 58.9M | if (CastExpr *P58.9M = dyn_cast<CastExpr>(E)) { |
2456 | 10.5M | E = P->getSubExpr(); |
2457 | 10.5M | continue; |
2458 | 10.5M | } |
2459 | 48.4M | if (MaterializeTemporaryExpr *48.4M Materialize48.4M |
2460 | 2.04k | = dyn_cast<MaterializeTemporaryExpr>(E)) { |
2461 | 2.04k | E = Materialize->GetTemporaryExpr(); |
2462 | 2.04k | continue; |
2463 | 2.04k | } |
2464 | 48.4M | if (SubstNonTypeTemplateParmExpr *48.4M NTTP48.4M |
2465 | 40.9k | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { |
2466 | 40.9k | E = NTTP->getReplacement(); |
2467 | 40.9k | continue; |
2468 | 40.9k | } |
2469 | 48.3M | return E; |
2470 | 48.3M | } |
2471 | 48.3M | } |
2472 | | |
2473 | 867 | Expr *Expr::IgnoreCasts() { |
2474 | 867 | Expr *E = this; |
2475 | 874 | while (true874 ) { |
2476 | 874 | if (CastExpr *P874 = dyn_cast<CastExpr>(E)) { |
2477 | 7 | E = P->getSubExpr(); |
2478 | 7 | continue; |
2479 | 7 | } |
2480 | 867 | if (MaterializeTemporaryExpr *867 Materialize867 |
2481 | 0 | = dyn_cast<MaterializeTemporaryExpr>(E)) { |
2482 | 0 | E = Materialize->GetTemporaryExpr(); |
2483 | 0 | continue; |
2484 | 0 | } |
2485 | 867 | if (SubstNonTypeTemplateParmExpr *867 NTTP867 |
2486 | 0 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { |
2487 | 0 | E = NTTP->getReplacement(); |
2488 | 0 | continue; |
2489 | 0 | } |
2490 | 867 | return E; |
2491 | 867 | } |
2492 | 867 | } |
2493 | | |
2494 | | /// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue |
2495 | | /// casts. This is intended purely as a temporary workaround for code |
2496 | | /// that hasn't yet been rewritten to do the right thing about those |
2497 | | /// casts, and may disappear along with the last internal use. |
2498 | 12.2k | Expr *Expr::IgnoreParenLValueCasts() { |
2499 | 12.2k | Expr *E = this; |
2500 | 14.4k | while (true14.4k ) { |
2501 | 14.4k | E = E->IgnoreParens(); |
2502 | 14.4k | if (CastExpr *P14.4k = dyn_cast<CastExpr>(E)) { |
2503 | 2.42k | if (P->getCastKind() == CK_LValueToRValue2.42k ) { |
2504 | 2.19k | E = P->getSubExpr(); |
2505 | 2.19k | continue; |
2506 | 2.19k | } |
2507 | 12.0k | } else if (MaterializeTemporaryExpr *12.0k Materialize12.0k |
2508 | 0 | = dyn_cast<MaterializeTemporaryExpr>(E)) { |
2509 | 0 | E = Materialize->GetTemporaryExpr(); |
2510 | 0 | continue; |
2511 | 12.0k | } else if (SubstNonTypeTemplateParmExpr *12.0k NTTP12.0k |
2512 | 24 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { |
2513 | 24 | E = NTTP->getReplacement(); |
2514 | 24 | continue; |
2515 | 24 | } |
2516 | 12.2k | break; |
2517 | 12.2k | } |
2518 | 12.2k | return E; |
2519 | 12.2k | } |
2520 | | |
2521 | 61.1k | Expr *Expr::ignoreParenBaseCasts() { |
2522 | 61.1k | Expr *E = this; |
2523 | 63.6k | while (true63.6k ) { |
2524 | 63.6k | E = E->IgnoreParens(); |
2525 | 63.6k | if (CastExpr *CE63.6k = dyn_cast<CastExpr>(E)) { |
2526 | 27.4k | if (CE->getCastKind() == CK_DerivedToBase || |
2527 | 27.3k | CE->getCastKind() == CK_UncheckedDerivedToBase || |
2528 | 27.4k | CE->getCastKind() == CK_NoOp25.4k ) { |
2529 | 2.50k | E = CE->getSubExpr(); |
2530 | 2.50k | continue; |
2531 | 2.50k | } |
2532 | 61.1k | } |
2533 | 61.1k | |
2534 | 61.1k | return E; |
2535 | 61.1k | } |
2536 | 61.1k | } |
2537 | | |
2538 | 60.2M | Expr *Expr::IgnoreParenImpCasts() { |
2539 | 60.2M | Expr *E = this; |
2540 | 83.3M | while (true83.3M ) { |
2541 | 83.3M | E = E->IgnoreParens(); |
2542 | 83.3M | if (ImplicitCastExpr *P83.3M = dyn_cast<ImplicitCastExpr>(E)) { |
2543 | 22.6M | E = P->getSubExpr(); |
2544 | 22.6M | continue; |
2545 | 22.6M | } |
2546 | 60.7M | if (MaterializeTemporaryExpr *60.7M Materialize60.7M |
2547 | 274k | = dyn_cast<MaterializeTemporaryExpr>(E)) { |
2548 | 274k | E = Materialize->GetTemporaryExpr(); |
2549 | 274k | continue; |
2550 | 274k | } |
2551 | 60.4M | if (SubstNonTypeTemplateParmExpr *60.4M NTTP60.4M |
2552 | 137k | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { |
2553 | 137k | E = NTTP->getReplacement(); |
2554 | 137k | continue; |
2555 | 137k | } |
2556 | 60.2M | return E; |
2557 | 60.2M | } |
2558 | 60.2M | } |
2559 | | |
2560 | 147k | Expr *Expr::IgnoreConversionOperator() { |
2561 | 147k | if (CXXMemberCallExpr *MCE147k = dyn_cast<CXXMemberCallExpr>(this)) { |
2562 | 1.85k | if (MCE->getMethodDecl() && 1.85k isa<CXXConversionDecl>(MCE->getMethodDecl())1.85k ) |
2563 | 56 | return MCE->getImplicitObjectArgument(); |
2564 | 147k | } |
2565 | 147k | return this; |
2566 | 147k | } |
2567 | | |
2568 | | /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the |
2569 | | /// value (including ptr->int casts of the same size). Strip off any |
2570 | | /// ParenExpr or CastExprs, returning their operand. |
2571 | 582k | Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { |
2572 | 582k | Expr *E = this; |
2573 | 675k | while (true675k ) { |
2574 | 675k | E = E->IgnoreParens(); |
2575 | 675k | |
2576 | 675k | if (CastExpr *P675k = dyn_cast<CastExpr>(E)) { |
2577 | 191k | // We ignore integer <-> casts that are of the same width, ptr<->ptr and |
2578 | 191k | // ptr<->int casts of the same width. We also ignore all identity casts. |
2579 | 191k | Expr *SE = P->getSubExpr(); |
2580 | 191k | |
2581 | 191k | if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())191k ) { |
2582 | 64.8k | E = SE; |
2583 | 64.8k | continue; |
2584 | 64.8k | } |
2585 | 127k | |
2586 | 127k | if (127k (E->getType()->isPointerType() || |
2587 | 58.0k | E->getType()->isIntegralType(Ctx)) && |
2588 | 126k | (SE->getType()->isPointerType() || |
2589 | 126k | SE->getType()->isIntegralType(Ctx)) && |
2590 | 127k | Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())66.8k ) { |
2591 | 28.0k | E = SE; |
2592 | 28.0k | continue; |
2593 | 28.0k | } |
2594 | 583k | } |
2595 | 583k | |
2596 | 583k | if (SubstNonTypeTemplateParmExpr *583k NTTP583k |
2597 | 74 | = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) { |
2598 | 74 | E = NTTP->getReplacement(); |
2599 | 74 | continue; |
2600 | 74 | } |
2601 | 582k | |
2602 | 582k | return E; |
2603 | 582k | } |
2604 | 582k | } |
2605 | | |
2606 | 131k | bool Expr::isDefaultArgument() const { |
2607 | 131k | const Expr *E = this; |
2608 | 131k | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) |
2609 | 31.9k | E = M->GetTemporaryExpr(); |
2610 | 131k | |
2611 | 200k | while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) |
2612 | 68.8k | E = ICE->getSubExprAsWritten(); |
2613 | 131k | |
2614 | 131k | return isa<CXXDefaultArgExpr>(E); |
2615 | 131k | } |
2616 | | |
2617 | | /// \brief Skip over any no-op casts and any temporary-binding |
2618 | | /// expressions. |
2619 | 49.6k | static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { |
2620 | 49.6k | if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E)) |
2621 | 33.7k | E = M->GetTemporaryExpr(); |
2622 | 49.6k | |
2623 | 85.2k | while (const ImplicitCastExpr *ICE85.2k = dyn_cast<ImplicitCastExpr>(E)) { |
2624 | 36.8k | if (ICE->getCastKind() == CK_NoOp) |
2625 | 35.5k | E = ICE->getSubExpr(); |
2626 | 36.8k | else |
2627 | 1.24k | break; |
2628 | 36.8k | } |
2629 | 49.6k | |
2630 | 52.9k | while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E)) |
2631 | 3.31k | E = BE->getSubExpr(); |
2632 | 49.6k | |
2633 | 49.6k | while (const ImplicitCastExpr *ICE49.6k = dyn_cast<ImplicitCastExpr>(E)) { |
2634 | 2.79k | if (ICE->getCastKind() == CK_NoOp) |
2635 | 0 | E = ICE->getSubExpr(); |
2636 | 2.79k | else |
2637 | 2.79k | break; |
2638 | 2.79k | } |
2639 | 49.6k | |
2640 | 49.6k | return E->IgnoreParens(); |
2641 | 49.6k | } |
2642 | | |
2643 | | /// isTemporaryObject - Determines if this expression produces a |
2644 | | /// temporary of the given class type. |
2645 | 49.6k | bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const { |
2646 | 49.6k | if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy))) |
2647 | 19 | return false; |
2648 | 49.6k | |
2649 | 49.6k | const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this); |
2650 | 49.6k | |
2651 | 49.6k | // Temporaries are by definition pr-values of class type. |
2652 | 49.6k | if (!E->Classify(C).isPRValue()49.6k ) { |
2653 | 14.1k | // In this context, property reference is a message call and is pr-value. |
2654 | 14.1k | if (!isa<ObjCPropertyRefExpr>(E)) |
2655 | 14.1k | return false; |
2656 | 35.4k | } |
2657 | 35.4k | |
2658 | 35.4k | // Black-list a few cases which yield pr-values of class type that don't |
2659 | 35.4k | // refer to temporaries of that type: |
2660 | 35.4k | |
2661 | 35.4k | // - implicit derived-to-base conversions |
2662 | 35.4k | if (35.4k isa<ImplicitCastExpr>(E)35.4k ) { |
2663 | 2.57k | switch (cast<ImplicitCastExpr>(E)->getCastKind()) { |
2664 | 0 | case CK_DerivedToBase: |
2665 | 0 | case CK_UncheckedDerivedToBase: |
2666 | 0 | return false; |
2667 | 2.57k | default: |
2668 | 2.57k | break; |
2669 | 35.4k | } |
2670 | 35.4k | } |
2671 | 35.4k | |
2672 | 35.4k | // - member expressions (all) |
2673 | 35.4k | if (35.4k isa<MemberExpr>(E)35.4k ) |
2674 | 13 | return false; |
2675 | 35.4k | |
2676 | 35.4k | if (const BinaryOperator *35.4k BO35.4k = dyn_cast<BinaryOperator>(E)) |
2677 | 34 | if (34 BO->isPtrMemOp()34 ) |
2678 | 1 | return false; |
2679 | 35.4k | |
2680 | 35.4k | // - opaque values (all) |
2681 | 35.4k | if (35.4k isa<OpaqueValueExpr>(E)35.4k ) |
2682 | 14 | return false; |
2683 | 35.4k | |
2684 | 35.4k | return true; |
2685 | 35.4k | } |
2686 | | |
2687 | 8.18M | bool Expr::isImplicitCXXThis() const { |
2688 | 8.18M | const Expr *E = this; |
2689 | 8.18M | |
2690 | 8.18M | // Strip away parentheses and casts we don't care about. |
2691 | 11.6M | while (true11.6M ) { |
2692 | 11.6M | if (const ParenExpr *Paren11.6M = dyn_cast<ParenExpr>(E)) { |
2693 | 457k | E = Paren->getSubExpr(); |
2694 | 457k | continue; |
2695 | 457k | } |
2696 | 11.1M | |
2697 | 11.1M | if (const ImplicitCastExpr *11.1M ICE11.1M = dyn_cast<ImplicitCastExpr>(E)) { |
2698 | 2.97M | if (ICE->getCastKind() == CK_NoOp || |
2699 | 2.71M | ICE->getCastKind() == CK_LValueToRValue || |
2700 | 515k | ICE->getCastKind() == CK_DerivedToBase || |
2701 | 2.97M | ICE->getCastKind() == CK_UncheckedDerivedToBase515k ) { |
2702 | 2.97M | E = ICE->getSubExpr(); |
2703 | 2.97M | continue; |
2704 | 2.97M | } |
2705 | 8.18M | } |
2706 | 8.18M | |
2707 | 8.18M | if (const UnaryOperator* 8.18M UnOp8.18M = dyn_cast<UnaryOperator>(E)) { |
2708 | 23.5k | if (UnOp->getOpcode() == UO_Extension23.5k ) { |
2709 | 0 | E = UnOp->getSubExpr(); |
2710 | 0 | continue; |
2711 | 0 | } |
2712 | 8.18M | } |
2713 | 8.18M | |
2714 | 8.18M | if (const MaterializeTemporaryExpr *8.18M M8.18M |
2715 | 8.54k | = dyn_cast<MaterializeTemporaryExpr>(E)) { |
2716 | 8.54k | E = M->GetTemporaryExpr(); |
2717 | 8.54k | continue; |
2718 | 8.54k | } |
2719 | 8.18M | |
2720 | 8.18M | break; |
2721 | 8.18M | } |
2722 | 8.18M | |
2723 | 8.18M | if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E)) |
2724 | 2.88M | return This->isImplicit(); |
2725 | 5.29M | |
2726 | 5.29M | return false; |
2727 | 5.29M | } |
2728 | | |
2729 | | /// hasAnyTypeDependentArguments - Determines if any of the expressions |
2730 | | /// in Exprs is type-dependent. |
2731 | 10.2M | bool Expr::hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs) { |
2732 | 20.4M | for (unsigned I = 0; I < Exprs.size()20.4M ; ++I10.1M ) |
2733 | 10.2M | if (10.2M Exprs[I]->isTypeDependent()10.2M ) |
2734 | 55.1k | return true; |
2735 | 10.2M | |
2736 | 10.1M | return false; |
2737 | 10.2M | } |
2738 | | |
2739 | | bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef, |
2740 | 993k | const Expr **Culprit) const { |
2741 | 993k | // This function is attempting whether an expression is an initializer |
2742 | 993k | // which can be evaluated at compile-time. It very closely parallels |
2743 | 993k | // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it |
2744 | 993k | // will lead to unexpected results. Like ConstExprEmitter, it falls back |
2745 | 993k | // to isEvaluatable most of the time. |
2746 | 993k | // |
2747 | 993k | // If we ever capture reference-binding directly in the AST, we can |
2748 | 993k | // kill the second parameter. |
2749 | 993k | |
2750 | 993k | if (IsForRef993k ) { |
2751 | 23 | EvalResult Result; |
2752 | 23 | if (EvaluateAsLValue(Result, Ctx) && 23 !Result.HasSideEffects19 ) |
2753 | 19 | return true; |
2754 | 4 | if (4 Culprit4 ) |
2755 | 4 | *Culprit = this; |
2756 | 23 | return false; |
2757 | 23 | } |
2758 | 993k | |
2759 | 993k | switch (getStmtClass()) { |
2760 | 107k | default: break; |
2761 | 1.05k | case StringLiteralClass: |
2762 | 1.05k | case ObjCEncodeExprClass: |
2763 | 1.05k | return true; |
2764 | 2.02k | case CXXTemporaryObjectExprClass: |
2765 | 2.02k | case CXXConstructExprClass: { |
2766 | 2.02k | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); |
2767 | 2.02k | |
2768 | 2.02k | if (CE->getConstructor()->isTrivial() && |
2769 | 2.02k | CE->getConstructor()->getParent()->hasTrivialDestructor()1.59k ) { |
2770 | 1.59k | // Trivial default constructor |
2771 | 1.59k | if (!CE->getNumArgs()1.59k ) return true1.40k ; |
2772 | 183 | |
2773 | 183 | // Trivial copy constructor |
2774 | 0 | assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument"); |
2775 | 183 | return CE->getArg(0)->isConstantInitializer(Ctx, false, Culprit); |
2776 | 183 | } |
2777 | 433 | |
2778 | 433 | break; |
2779 | 433 | } |
2780 | 64 | case CompoundLiteralExprClass: { |
2781 | 64 | // This handles gcc's extension that allows global initializers like |
2782 | 64 | // "struct x {int x;} x = (struct x) {};". |
2783 | 64 | // FIXME: This accepts other cases it shouldn't! |
2784 | 64 | const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); |
2785 | 64 | return Exp->isConstantInitializer(Ctx, false, Culprit); |
2786 | 433 | } |
2787 | 22 | case DesignatedInitUpdateExprClass: { |
2788 | 22 | const DesignatedInitUpdateExpr *DIUE = cast<DesignatedInitUpdateExpr>(this); |
2789 | 22 | return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) && |
2790 | 16 | DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit); |
2791 | 433 | } |
2792 | 61.5k | case InitListExprClass: { |
2793 | 61.5k | const InitListExpr *ILE = cast<InitListExpr>(this); |
2794 | 61.5k | if (ILE->getType()->isArrayType()61.5k ) { |
2795 | 33.6k | unsigned numInits = ILE->getNumInits(); |
2796 | 894k | for (unsigned i = 0; i < numInits894k ; i++860k ) { |
2797 | 860k | if (!ILE->getInit(i)->isConstantInitializer(Ctx, false, Culprit)) |
2798 | 100 | return false; |
2799 | 860k | } |
2800 | 33.5k | return true; |
2801 | 27.8k | } |
2802 | 27.8k | |
2803 | 27.8k | if (27.8k ILE->getType()->isRecordType()27.8k ) { |
2804 | 27.5k | unsigned ElementNo = 0; |
2805 | 27.5k | RecordDecl *RD = ILE->getType()->getAs<RecordType>()->getDecl(); |
2806 | 88.5k | for (const auto *Field : RD->fields()) { |
2807 | 88.5k | // If this is a union, skip all the fields that aren't being initialized. |
2808 | 88.5k | if (RD->isUnion() && 88.5k ILE->getInitializedFieldInUnion() != Field4.75k ) |
2809 | 2.04k | continue; |
2810 | 86.4k | |
2811 | 86.4k | // Don't emit anonymous bitfields, they just affect layout. |
2812 | 86.4k | if (86.4k Field->isUnnamedBitfield()86.4k ) |
2813 | 41 | continue; |
2814 | 86.4k | |
2815 | 86.4k | if (86.4k ElementNo < ILE->getNumInits()86.4k ) { |
2816 | 86.3k | const Expr *Elt = ILE->getInit(ElementNo++); |
2817 | 86.3k | if (Field->isBitField()86.3k ) { |
2818 | 147 | // Bitfields have to evaluate to an integer. |
2819 | 147 | llvm::APSInt ResultTmp; |
2820 | 147 | if (!Elt->EvaluateAsInt(ResultTmp, Ctx)147 ) { |
2821 | 1 | if (Culprit) |
2822 | 1 | *Culprit = Elt; |
2823 | 1 | return false; |
2824 | 1 | } |
2825 | 86.2k | } else { |
2826 | 86.2k | bool RefType = Field->getType()->isReferenceType(); |
2827 | 86.2k | if (!Elt->isConstantInitializer(Ctx, RefType, Culprit)) |
2828 | 1.40k | return false; |
2829 | 26.1k | } |
2830 | 86.3k | } |
2831 | 88.5k | } |
2832 | 26.1k | return true; |
2833 | 26.1k | } |
2834 | 303 | |
2835 | 303 | break; |
2836 | 303 | } |
2837 | 6.42k | case ImplicitValueInitExprClass: |
2838 | 6.42k | case NoInitExprClass: |
2839 | 6.42k | return true; |
2840 | 1.68k | case ParenExprClass: |
2841 | 1.68k | return cast<ParenExpr>(this)->getSubExpr() |
2842 | 1.68k | ->isConstantInitializer(Ctx, IsForRef, Culprit); |
2843 | 2 | case GenericSelectionExprClass: |
2844 | 2 | return cast<GenericSelectionExpr>(this)->getResultExpr() |
2845 | 2 | ->isConstantInitializer(Ctx, IsForRef, Culprit); |
2846 | 3 | case ChooseExprClass: |
2847 | 3 | if (cast<ChooseExpr>(this)->isConditionDependent()3 ) { |
2848 | 0 | if (Culprit) |
2849 | 0 | *Culprit = this; |
2850 | 0 | return false; |
2851 | 0 | } |
2852 | 3 | return cast<ChooseExpr>(this)->getChosenSubExpr() |
2853 | 3 | ->isConstantInitializer(Ctx, IsForRef, Culprit); |
2854 | 19.1k | case UnaryOperatorClass: { |
2855 | 19.1k | const UnaryOperator* Exp = cast<UnaryOperator>(this); |
2856 | 19.1k | if (Exp->getOpcode() == UO_Extension) |
2857 | 7 | return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); |
2858 | 19.1k | break; |
2859 | 19.1k | } |
2860 | 793k | case CXXFunctionalCastExprClass: |
2861 | 793k | case CXXStaticCastExprClass: |
2862 | 793k | case ImplicitCastExprClass: |
2863 | 793k | case CStyleCastExprClass: |
2864 | 793k | case ObjCBridgedCastExprClass: |
2865 | 793k | case CXXDynamicCastExprClass: |
2866 | 793k | case CXXReinterpretCastExprClass: |
2867 | 793k | case CXXConstCastExprClass: { |
2868 | 793k | const CastExpr *CE = cast<CastExpr>(this); |
2869 | 793k | |
2870 | 793k | // Handle misc casts we want to ignore. |
2871 | 793k | if (CE->getCastKind() == CK_NoOp || |
2872 | 792k | CE->getCastKind() == CK_LValueToRValue || |
2873 | 789k | CE->getCastKind() == CK_ToUnion || |
2874 | 789k | CE->getCastKind() == CK_ConstructorConversion || |
2875 | 789k | CE->getCastKind() == CK_NonAtomicToAtomic || |
2876 | 789k | CE->getCastKind() == CK_AtomicToNonAtomic || |
2877 | 789k | CE->getCastKind() == CK_IntToOCLSampler) |
2878 | 3.60k | return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); |
2879 | 789k | |
2880 | 789k | break; |
2881 | 789k | } |
2882 | 0 | case MaterializeTemporaryExprClass: |
2883 | 0 | return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr() |
2884 | 0 | ->isConstantInitializer(Ctx, false, Culprit); |
2885 | 789k | |
2886 | 29 | case SubstNonTypeTemplateParmExprClass: |
2887 | 29 | return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement() |
2888 | 29 | ->isConstantInitializer(Ctx, false, Culprit); |
2889 | 0 | case CXXDefaultArgExprClass: |
2890 | 0 | return cast<CXXDefaultArgExpr>(this)->getExpr() |
2891 | 0 | ->isConstantInitializer(Ctx, false, Culprit); |
2892 | 0 | case CXXDefaultInitExprClass: |
2893 | 0 | return cast<CXXDefaultInitExpr>(this)->getExpr() |
2894 | 0 | ->isConstantInitializer(Ctx, false, Culprit); |
2895 | 917k | } |
2896 | 917k | // Allow certain forms of UB in constant initializers: signed integer |
2897 | 917k | // overflow and floating-point division by zero. We'll give a warning on |
2898 | 917k | // these, but they're common enough that we have to accept them. |
2899 | 917k | if (917k isEvaluatable(Ctx, SE_AllowUndefinedBehavior)917k ) |
2900 | 914k | return true; |
2901 | 3.15k | if (3.15k Culprit3.15k ) |
2902 | 84 | *Culprit = this; |
2903 | 993k | return false; |
2904 | 993k | } |
2905 | | |
2906 | | namespace { |
2907 | | /// \brief Look for any side effects within a Stmt. |
2908 | | class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> { |
2909 | | typedef ConstEvaluatedExprVisitor<SideEffectFinder> Inherited; |
2910 | | const bool IncludePossibleEffects; |
2911 | | bool HasSideEffects; |
2912 | | |
2913 | | public: |
2914 | | explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible) |
2915 | | : Inherited(Context), |
2916 | 11 | IncludePossibleEffects(IncludePossible), HasSideEffects(false) { } |
2917 | | |
2918 | 11 | bool hasSideEffects() const { return HasSideEffects; } |
2919 | | |
2920 | 19 | void VisitExpr(const Expr *E) { |
2921 | 19 | if (!HasSideEffects && |
2922 | 18 | E->HasSideEffects(Context, IncludePossibleEffects)) |
2923 | 2 | HasSideEffects = true; |
2924 | 19 | } |
2925 | | }; |
2926 | | } |
2927 | | |
2928 | | bool Expr::HasSideEffects(const ASTContext &Ctx, |
2929 | 5.79M | bool IncludePossibleEffects) const { |
2930 | 5.79M | // In circumstances where we care about definite side effects instead of |
2931 | 5.79M | // potential side effects, we want to ignore expressions that are part of a |
2932 | 5.79M | // macro expansion as a potential side effect. |
2933 | 5.79M | if (!IncludePossibleEffects && 5.79M getExprLoc().isMacroID()22.8k ) |
2934 | 6.13k | return false; |
2935 | 5.79M | |
2936 | 5.79M | if (5.79M isInstantiationDependent()5.79M ) |
2937 | 1.20k | return IncludePossibleEffects; |
2938 | 5.79M | |
2939 | 5.79M | switch (getStmtClass()) { |
2940 | 0 | case NoStmtClass: |
2941 | 0 | #define ABSTRACT_STMT(Type) |
2942 | 0 | #define STMT(Type, Base) case Type##Class: |
2943 | 0 | #define EXPR(Type, Base) |
2944 | 0 | #include "clang/AST/StmtNodes.inc"0 |
2945 | 0 | llvm_unreachable("unexpected Expr kind"); |
2946 | 0 |
|
2947 | 0 | case DependentScopeDeclRefExprClass: |
2948 | 0 | case CXXUnresolvedConstructExprClass: |
2949 | 0 | case CXXDependentScopeMemberExprClass: |
2950 | 0 | case UnresolvedLookupExprClass: |
2951 | 0 | case UnresolvedMemberExprClass: |
2952 | 0 | case PackExpansionExprClass: |
2953 | 0 | case SubstNonTypeTemplateParmPackExprClass: |
2954 | 0 | case FunctionParmPackExprClass: |
2955 | 0 | case TypoExprClass: |
2956 | 0 | case CXXFoldExprClass: |
2957 | 0 | llvm_unreachable("shouldn't see dependent / unresolved nodes here"); |
2958 | 0 |
|
2959 | 2.82M | case DeclRefExprClass: |
2960 | 2.82M | case ObjCIvarRefExprClass: |
2961 | 2.82M | case PredefinedExprClass: |
2962 | 2.82M | case IntegerLiteralClass: |
2963 | 2.82M | case FloatingLiteralClass: |
2964 | 2.82M | case ImaginaryLiteralClass: |
2965 | 2.82M | case StringLiteralClass: |
2966 | 2.82M | case CharacterLiteralClass: |
2967 | 2.82M | case OffsetOfExprClass: |
2968 | 2.82M | case ImplicitValueInitExprClass: |
2969 | 2.82M | case UnaryExprOrTypeTraitExprClass: |
2970 | 2.82M | case AddrLabelExprClass: |
2971 | 2.82M | case GNUNullExprClass: |
2972 | 2.82M | case ArrayInitIndexExprClass: |
2973 | 2.82M | case NoInitExprClass: |
2974 | 2.82M | case CXXBoolLiteralExprClass: |
2975 | 2.82M | case CXXNullPtrLiteralExprClass: |
2976 | 2.82M | case CXXThisExprClass: |
2977 | 2.82M | case CXXScalarValueInitExprClass: |
2978 | 2.82M | case TypeTraitExprClass: |
2979 | 2.82M | case ArrayTypeTraitExprClass: |
2980 | 2.82M | case ExpressionTraitExprClass: |
2981 | 2.82M | case CXXNoexceptExprClass: |
2982 | 2.82M | case SizeOfPackExprClass: |
2983 | 2.82M | case ObjCStringLiteralClass: |
2984 | 2.82M | case ObjCEncodeExprClass: |
2985 | 2.82M | case ObjCBoolLiteralExprClass: |
2986 | 2.82M | case ObjCAvailabilityCheckExprClass: |
2987 | 2.82M | case CXXUuidofExprClass: |
2988 | 2.82M | case OpaqueValueExprClass: |
2989 | 2.82M | // These never have a side-effect. |
2990 | 2.82M | return false; |
2991 | 2.82M | |
2992 | 3.33k | case CallExprClass: |
2993 | 3.33k | case CXXOperatorCallExprClass: |
2994 | 3.33k | case CXXMemberCallExprClass: |
2995 | 3.33k | case CUDAKernelCallExprClass: |
2996 | 3.33k | case UserDefinedLiteralClass: { |
2997 | 3.33k | // We don't know a call definitely has side effects, except for calls |
2998 | 3.33k | // to pure/const functions that definitely don't. |
2999 | 3.33k | // If the call itself is considered side-effect free, check the operands. |
3000 | 3.33k | const Decl *FD = cast<CallExpr>(this)->getCalleeDecl(); |
3001 | 3.32k | bool IsPure = FD && (FD->hasAttr<ConstAttr>() || 3.32k FD->hasAttr<PureAttr>()3.26k ); |
3002 | 3.33k | if (IsPure || 3.33k !IncludePossibleEffects3.27k ) |
3003 | 469 | break; |
3004 | 2.87k | return true; |
3005 | 2.87k | } |
3006 | 2.87k | |
3007 | 144 | case BlockExprClass: |
3008 | 144 | case CXXBindTemporaryExprClass: |
3009 | 144 | if (!IncludePossibleEffects) |
3010 | 101 | break; |
3011 | 43 | return true; |
3012 | 43 | |
3013 | 116 | case MSPropertyRefExprClass: |
3014 | 116 | case MSPropertySubscriptExprClass: |
3015 | 116 | case CompoundAssignOperatorClass: |
3016 | 116 | case VAArgExprClass: |
3017 | 116 | case AtomicExprClass: |
3018 | 116 | case CXXThrowExprClass: |
3019 | 116 | case CXXNewExprClass: |
3020 | 116 | case CXXDeleteExprClass: |
3021 | 116 | case CoawaitExprClass: |
3022 | 116 | case DependentCoawaitExprClass: |
3023 | 116 | case CoyieldExprClass: |
3024 | 116 | // These always have a side-effect. |
3025 | 116 | return true; |
3026 | 116 | |
3027 | 11 | case StmtExprClass: { |
3028 | 11 | // StmtExprs have a side-effect if any substatement does. |
3029 | 11 | SideEffectFinder Finder(Ctx, IncludePossibleEffects); |
3030 | 11 | Finder.Visit(cast<StmtExpr>(this)->getSubStmt()); |
3031 | 11 | return Finder.hasSideEffects(); |
3032 | 116 | } |
3033 | 116 | |
3034 | 1.41k | case ExprWithCleanupsClass: |
3035 | 1.41k | if (IncludePossibleEffects) |
3036 | 1.41k | if (1.41k cast<ExprWithCleanups>(this)->cleanupsHaveSideEffects()1.41k ) |
3037 | 52 | return true; |
3038 | 1.36k | break; |
3039 | 1.36k | |
3040 | 57.5k | case ParenExprClass: |
3041 | 57.5k | case ArraySubscriptExprClass: |
3042 | 57.5k | case OMPArraySectionExprClass: |
3043 | 57.5k | case MemberExprClass: |
3044 | 57.5k | case ConditionalOperatorClass: |
3045 | 57.5k | case BinaryConditionalOperatorClass: |
3046 | 57.5k | case CompoundLiteralExprClass: |
3047 | 57.5k | case ExtVectorElementExprClass: |
3048 | 57.5k | case DesignatedInitExprClass: |
3049 | 57.5k | case DesignatedInitUpdateExprClass: |
3050 | 57.5k | case ArrayInitLoopExprClass: |
3051 | 57.5k | case ParenListExprClass: |
3052 | 57.5k | case CXXPseudoDestructorExprClass: |
3053 | 57.5k | case CXXStdInitializerListExprClass: |
3054 | 57.5k | case SubstNonTypeTemplateParmExprClass: |
3055 | 57.5k | case MaterializeTemporaryExprClass: |
3056 | 57.5k | case ShuffleVectorExprClass: |
3057 | 57.5k | case ConvertVectorExprClass: |
3058 | 57.5k | case AsTypeExprClass: |
3059 | 57.5k | // These have a side-effect if any subexpression does. |
3060 | 57.5k | break; |
3061 | 57.5k | |
3062 | 177k | case UnaryOperatorClass: |
3063 | 177k | if (cast<UnaryOperator>(this)->isIncrementDecrementOp()) |
3064 | 156 | return true; |
3065 | 177k | break; |
3066 | 177k | |
3067 | 21.6k | case BinaryOperatorClass: |
3068 | 21.6k | if (cast<BinaryOperator>(this)->isAssignmentOp()) |
3069 | 23 | return true; |
3070 | 21.6k | break; |
3071 | 21.6k | |
3072 | 137k | case InitListExprClass: |
3073 | 137k | // FIXME: The children for an InitListExpr doesn't include the array filler. |
3074 | 137k | if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller()) |
3075 | 4.42k | if (4.42k E->HasSideEffects(Ctx, IncludePossibleEffects)4.42k ) |
3076 | 12 | return true; |
3077 | 137k | break; |
3078 | 137k | |
3079 | 0 | case GenericSelectionExprClass: |
3080 | 0 | return cast<GenericSelectionExpr>(this)->getResultExpr()-> |
3081 | 0 | HasSideEffects(Ctx, IncludePossibleEffects); |
3082 | 137k | |
3083 | 3 | case ChooseExprClass: |
3084 | 3 | return cast<ChooseExpr>(this)->getChosenSubExpr()->HasSideEffects( |
3085 | 3 | Ctx, IncludePossibleEffects); |
3086 | 137k | |
3087 | 0 | case CXXDefaultArgExprClass: |
3088 | 0 | return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects( |
3089 | 0 | Ctx, IncludePossibleEffects); |
3090 | 137k | |
3091 | 503 | case CXXDefaultInitExprClass: { |
3092 | 503 | const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)->getField(); |
3093 | 503 | if (const Expr *E = FD->getInClassInitializer()) |
3094 | 503 | return E->HasSideEffects(Ctx, IncludePossibleEffects); |
3095 | 0 | // If we've not yet parsed the initializer, assume it has side-effects. |
3096 | 0 | return true; |
3097 | 0 | } |
3098 | 0 |
|
3099 | 39 | case CXXDynamicCastExprClass: { |
3100 | 39 | // A dynamic_cast expression has side-effects if it can throw. |
3101 | 39 | const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this); |
3102 | 39 | if (DCE->getTypeAsWritten()->isReferenceType() && |
3103 | 9 | DCE->getCastKind() == CK_Dynamic) |
3104 | 9 | return true; |
3105 | 30 | } // Fall through. |
3106 | 2.54M | case ImplicitCastExprClass: |
3107 | 2.54M | case CStyleCastExprClass: |
3108 | 2.54M | case CXXStaticCastExprClass: |
3109 | 2.54M | case CXXReinterpretCastExprClass: |
3110 | 2.54M | case CXXConstCastExprClass: |
3111 | 2.54M | case CXXFunctionalCastExprClass: { |
3112 | 2.54M | // While volatile reads are side-effecting in both C and C++, we treat them |
3113 | 2.54M | // as having possible (not definite) side-effects. This allows idiomatic |
3114 | 2.54M | // code to behave without warning, such as sizeof(*v) for a volatile- |
3115 | 2.54M | // qualified pointer. |
3116 | 2.54M | if (!IncludePossibleEffects) |
3117 | 2.02k | break; |
3118 | 2.53M | |
3119 | 2.53M | const CastExpr *CE = cast<CastExpr>(this); |
3120 | 2.53M | if (CE->getCastKind() == CK_LValueToRValue && |
3121 | 48.8k | CE->getSubExpr()->getType().isVolatileQualified()) |
3122 | 151 | return true; |
3123 | 2.53M | break; |
3124 | 2.53M | } |
3125 | 2.53M | |
3126 | 27 | case CXXTypeidExprClass: |
3127 | 27 | // typeid might throw if its subexpression is potentially-evaluated, so has |
3128 | 27 | // side-effects in that case whether or not its subexpression does. |
3129 | 27 | return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); |
3130 | 2.53M | |
3131 | 25.1k | case CXXConstructExprClass: |
3132 | 25.1k | case CXXTemporaryObjectExprClass: { |
3133 | 25.1k | const CXXConstructExpr *CE = cast<CXXConstructExpr>(this); |
3134 | 25.1k | if (!CE->getConstructor()->isTrivial() && 25.1k IncludePossibleEffects16.3k ) |
3135 | 16.2k | return true; |
3136 | 8.90k | // A trivial constructor does not add any side-effects of its own. Just look |
3137 | 8.90k | // at its arguments. |
3138 | 8.90k | break; |
3139 | 8.90k | } |
3140 | 8.90k | |
3141 | 0 | case CXXInheritedCtorInitExprClass: { |
3142 | 0 | const auto *ICIE = cast<CXXInheritedCtorInitExpr>(this); |
3143 | 0 | if (!ICIE->getConstructor()->isTrivial() && 0 IncludePossibleEffects0 ) |
3144 | 0 | return true; |
3145 | 0 | break; |
3146 | 0 | } |
3147 | 0 |
|
3148 | 366 | case LambdaExprClass: { |
3149 | 366 | const LambdaExpr *LE = cast<LambdaExpr>(this); |
3150 | 366 | for (LambdaExpr::capture_iterator I = LE->capture_begin(), |
3151 | 371 | E = LE->capture_end(); I != E371 ; ++I5 ) |
3152 | 45 | if (45 I->getCaptureKind() == LCK_ByCopy45 ) |
3153 | 45 | // FIXME: Only has a side-effect if the variable is volatile or if |
3154 | 45 | // the copy would invoke a non-trivial copy constructor. |
3155 | 40 | return true; |
3156 | 326 | return false; |
3157 | 366 | } |
3158 | 366 | |
3159 | 9 | case PseudoObjectExprClass: { |
3160 | 9 | // Only look for side-effects in the semantic form, and look past |
3161 | 9 | // OpaqueValueExpr bindings in that form. |
3162 | 9 | const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this); |
3163 | 9 | for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), |
3164 | 9 | E = PO->semantics_end(); |
3165 | 27 | I != E27 ; ++I18 ) { |
3166 | 20 | const Expr *Subexpr = *I; |
3167 | 20 | if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr)) |
3168 | 11 | Subexpr = OVE->getSourceExpr(); |
3169 | 20 | if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects)) |
3170 | 2 | return true; |
3171 | 20 | } |
3172 | 7 | return false; |
3173 | 9 | } |
3174 | 9 | |
3175 | 45 | case ObjCBoxedExprClass: |
3176 | 45 | case ObjCArrayLiteralClass: |
3177 | 45 | case ObjCDictionaryLiteralClass: |
3178 | 45 | case ObjCSelectorExprClass: |
3179 | 45 | case ObjCProtocolExprClass: |
3180 | 45 | case ObjCIsaExprClass: |
3181 | 45 | case ObjCIndirectCopyRestoreExprClass: |
3182 | 45 | case ObjCSubscriptRefExprClass: |
3183 | 45 | case ObjCBridgedCastExprClass: |
3184 | 45 | case ObjCMessageExprClass: |
3185 | 45 | case ObjCPropertyRefExprClass: |
3186 | 45 | // FIXME: Classify these cases better. |
3187 | 45 | if (IncludePossibleEffects) |
3188 | 34 | return true; |
3189 | 11 | break; |
3190 | 2.94M | } |
3191 | 2.94M | |
3192 | 2.94M | // Recurse to children. |
3193 | 2.94M | for (const Stmt *SubStmt : children()) |
3194 | 5.60M | if (5.60M SubStmt && |
3195 | 5.60M | cast<Expr>(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects)) |
3196 | 3.30k | return true; |
3197 | 2.94M | |
3198 | 2.94M | return false; |
3199 | 2.94M | } |
3200 | | |
3201 | | namespace { |
3202 | | /// \brief Look for a call to a non-trivial function within an expression. |
3203 | | class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder> |
3204 | | { |
3205 | | typedef ConstEvaluatedExprVisitor<NonTrivialCallFinder> Inherited; |
3206 | | |
3207 | | bool NonTrivial; |
3208 | | |
3209 | | public: |
3210 | | explicit NonTrivialCallFinder(const ASTContext &Context) |
3211 | 490 | : Inherited(Context), NonTrivial(false) { } |
3212 | | |
3213 | 490 | bool hasNonTrivialCall() const { return NonTrivial; } |
3214 | | |
3215 | 184 | void VisitCallExpr(const CallExpr *E) { |
3216 | 184 | if (const CXXMethodDecl *Method |
3217 | 184 | = dyn_cast_or_null<const CXXMethodDecl>(E->getCalleeDecl())) { |
3218 | 184 | if (Method->isTrivial()184 ) { |
3219 | 123 | // Recurse to children of the call. |
3220 | 123 | Inherited::VisitStmt(E); |
3221 | 123 | return; |
3222 | 123 | } |
3223 | 61 | } |
3224 | 61 | |
3225 | 61 | NonTrivial = true; |
3226 | 61 | } |
3227 | | |
3228 | 154 | void VisitCXXConstructExpr(const CXXConstructExpr *E) { |
3229 | 154 | if (E->getConstructor()->isTrivial()154 ) { |
3230 | 118 | // Recurse to children of the call. |
3231 | 118 | Inherited::VisitStmt(E); |
3232 | 118 | return; |
3233 | 118 | } |
3234 | 36 | |
3235 | 36 | NonTrivial = true; |
3236 | 36 | } |
3237 | | |
3238 | 15 | void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) { |
3239 | 15 | if (E->getTemporary()->getDestructor()->isTrivial()15 ) { |
3240 | 0 | Inherited::VisitStmt(E); |
3241 | 0 | return; |
3242 | 0 | } |
3243 | 15 | |
3244 | 15 | NonTrivial = true; |
3245 | 15 | } |
3246 | | }; |
3247 | | } |
3248 | | |
3249 | 490 | bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const { |
3250 | 490 | NonTrivialCallFinder Finder(Ctx); |
3251 | 490 | Finder.Visit(this); |
3252 | 490 | return Finder.hasNonTrivialCall(); |
3253 | 490 | } |
3254 | | |
3255 | | /// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null |
3256 | | /// pointer constant or not, as well as the specific kind of constant detected. |
3257 | | /// Null pointer constants can be integer constant expressions with the |
3258 | | /// value zero, casts of zero to void*, nullptr (C++0X), or __null |
3259 | | /// (a GNU extension). |
3260 | | Expr::NullPointerConstantKind |
3261 | | Expr::isNullPointerConstant(ASTContext &Ctx, |
3262 | 3.07M | NullPointerConstantValueDependence NPC) const { |
3263 | 3.07M | if (isValueDependent() && |
3264 | 3.07M | (!Ctx.getLangOpts().CPlusPlus11 || 135 Ctx.getLangOpts().MSVCCompat55 )) { |
3265 | 84 | switch (NPC) { |
3266 | 0 | case NPC_NeverValueDependent: |
3267 | 0 | llvm_unreachable("Unexpected value dependent expression!"); |
3268 | 39 | case NPC_ValueDependentIsNull: |
3269 | 39 | if (isTypeDependent() || 39 getType()->isIntegralType(Ctx)39 ) |
3270 | 26 | return NPCK_ZeroExpression; |
3271 | 39 | else |
3272 | 13 | return NPCK_NotNull; |
3273 | 0 | |
3274 | 45 | case NPC_ValueDependentIsNotNull: |
3275 | 45 | return NPCK_NotNull; |
3276 | 3.07M | } |
3277 | 3.07M | } |
3278 | 3.07M | |
3279 | 3.07M | // Strip off a cast to void*, if it exists. Except in C++. |
3280 | 3.07M | if (const ExplicitCastExpr *3.07M CE3.07M = dyn_cast<ExplicitCastExpr>(this)) { |
3281 | 155k | if (!Ctx.getLangOpts().CPlusPlus155k ) { |
3282 | 144k | // Check that it is a cast to void*. |
3283 | 144k | if (const PointerType *PT144k = CE->getType()->getAs<PointerType>()) { |
3284 | 140k | QualType Pointee = PT->getPointeeType(); |
3285 | 140k | Qualifiers Q = Pointee.getQualifiers(); |
3286 | 140k | // In OpenCL v2.0 generic address space acts as a placeholder |
3287 | 140k | // and should be ignored. |
3288 | 140k | bool IsASValid = true; |
3289 | 140k | if (Ctx.getLangOpts().OpenCLVersion >= 200140k ) { |
3290 | 590 | if (Pointee.getAddressSpace() == LangAS::opencl_generic) |
3291 | 352 | Q.removeAddressSpace(); |
3292 | 590 | else |
3293 | 238 | IsASValid = false; |
3294 | 590 | } |
3295 | 140k | |
3296 | 140k | if (IsASValid && 140k !Q.hasQualifiers()139k && |
3297 | 129k | Pointee->isVoidType() && // to void* |
3298 | 47.6k | CE->getSubExpr()->getType()->isIntegerType()) // from int. |
3299 | 44.7k | return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3300 | 3.07M | } |
3301 | 144k | } |
3302 | 2.91M | } else if (const ImplicitCastExpr *2.91M ICE2.91M = dyn_cast<ImplicitCastExpr>(this)) { |
3303 | 94.3k | // Ignore the ImplicitCastExpr type entirely. |
3304 | 94.3k | return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3305 | 2.82M | } else if (const ParenExpr *2.82M PE2.82M = dyn_cast<ParenExpr>(this)) { |
3306 | 101k | // Accept ((void*)0) as a null pointer constant, as many other |
3307 | 101k | // implementations do. |
3308 | 101k | return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); |
3309 | 2.72M | } else if (const GenericSelectionExpr *2.72M GE2.72M = |
3310 | 1 | dyn_cast<GenericSelectionExpr>(this)) { |
3311 | 1 | if (GE->isResultDependent()) |
3312 | 0 | return NPCK_NotNull; |
3313 | 1 | return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); |
3314 | 2.72M | } else if (const ChooseExpr *2.72M CE2.72M = dyn_cast<ChooseExpr>(this)) { |
3315 | 1 | if (CE->isConditionDependent()) |
3316 | 0 | return NPCK_NotNull; |
3317 | 1 | return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC); |
3318 | 2.72M | } else if (const CXXDefaultArgExpr *2.72M DefaultArg2.72M |
3319 | 20 | = dyn_cast<CXXDefaultArgExpr>(this)) { |
3320 | 20 | // See through default argument expressions. |
3321 | 20 | return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); |
3322 | 2.72M | } else if (const CXXDefaultInitExpr *2.72M DefaultInit2.72M |
3323 | 0 | = dyn_cast<CXXDefaultInitExpr>(this)) { |
3324 | 0 | // See through default initializer expressions. |
3325 | 0 | return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC); |
3326 | 2.72M | } else if (2.72M isa<GNUNullExpr>(this)2.72M ) { |
3327 | 16.2k | // The GNU __null extension is always a null pointer constant. |
3328 | 16.2k | return NPCK_GNUNull; |
3329 | 2.70M | } else if (const MaterializeTemporaryExpr *2.70M M2.70M |
3330 | 1 | = dyn_cast<MaterializeTemporaryExpr>(this)) { |
3331 | 1 | return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); |
3332 | 2.70M | } else if (const OpaqueValueExpr *2.70M OVE2.70M = dyn_cast<OpaqueValueExpr>(this)) { |
3333 | 1.86k | if (const Expr *Source = OVE->getSourceExpr()) |
3334 | 1.46k | return Source->isNullPointerConstant(Ctx, NPC); |
3335 | 2.81M | } |
3336 | 2.81M | |
3337 | 2.81M | // C++11 nullptr_t is always a null pointer constant. |
3338 | 2.81M | if (2.81M getType()->isNullPtrType()2.81M ) |
3339 | 53.5k | return NPCK_CXX11_nullptr; |
3340 | 2.76M | |
3341 | 2.76M | if (const RecordType *2.76M UT2.76M = getType()->getAsUnionType()) |
3342 | 5 | if (5 !Ctx.getLangOpts().CPlusPlus11 && |
3343 | 5 | UT5 && UT->getDecl()->hasAttr<TransparentUnionAttr>()5 ) |
3344 | 5 | if (const CompoundLiteralExpr *5 CLE5 = dyn_cast<CompoundLiteralExpr>(this)){ |
3345 | 0 | const Expr *InitExpr = CLE->getInitializer(); |
3346 | 0 | if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr)) |
3347 | 0 | return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); |
3348 | 2.76M | } |
3349 | 2.76M | // This expression must be an integer type. |
3350 | 2.76M | if (2.76M !getType()->isIntegerType() || |
3351 | 619k | (Ctx.getLangOpts().CPlusPlus && 619k getType()->isEnumeralType()345k )) |
3352 | 2.17M | return NPCK_NotNull; |
3353 | 585k | |
3354 | 585k | if (585k Ctx.getLangOpts().CPlusPlus11585k ) { |
3355 | 200k | // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with |
3356 | 200k | // value zero or a prvalue of type std::nullptr_t. |
3357 | 200k | // Microsoft mode permits C++98 rules reflecting MSVC behavior. |
3358 | 200k | const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this); |
3359 | 200k | if (Lit && 200k !Lit->getValue()116k ) |
3360 | 80.5k | return NPCK_ZeroLiteral; |
3361 | 119k | else if (119k !Ctx.getLangOpts().MSVCCompat || 119k !isCXX98IntegralConstantExpr(Ctx)45 ) |
3362 | 119k | return NPCK_NotNull; |
3363 | 384k | } else { |
3364 | 384k | // If we have an integer constant expression, we need to *evaluate* it and |
3365 | 384k | // test for the value 0. |
3366 | 384k | if (!isIntegerConstantExpr(Ctx)) |
3367 | 124k | return NPCK_NotNull; |
3368 | 259k | } |
3369 | 259k | |
3370 | 259k | if (259k EvaluateKnownConstInt(Ctx) != 0259k ) |
3371 | 66.7k | return NPCK_NotNull; |
3372 | 192k | |
3373 | 192k | if (192k isa<IntegerLiteral>(this)192k ) |
3374 | 190k | return NPCK_ZeroLiteral; |
3375 | 2.88k | return NPCK_ZeroExpression; |
3376 | 2.88k | } |
3377 | | |
3378 | | /// \brief If this expression is an l-value for an Objective C |
3379 | | /// property, find the underlying property reference expression. |
3380 | 0 | const ObjCPropertyRefExpr *Expr::getObjCProperty() const { |
3381 | 0 | const Expr *E = this; |
3382 | 0 | while (true0 ) { |
3383 | 0 | assert((E->getValueKind() == VK_LValue && |
3384 | 0 | E->getObjectKind() == OK_ObjCProperty) && |
3385 | 0 | "expression is not a property reference"); |
3386 | 0 | E = E->IgnoreParenCasts(); |
3387 | 0 | if (const BinaryOperator *BO0 = dyn_cast<BinaryOperator>(E)) { |
3388 | 0 | if (BO->getOpcode() == BO_Comma0 ) { |
3389 | 0 | E = BO->getRHS(); |
3390 | 0 | continue; |
3391 | 0 | } |
3392 | 0 | } |
3393 | 0 |
|
3394 | 0 | break; |
3395 | 0 | } |
3396 | 0 |
|
3397 | 0 | return cast<ObjCPropertyRefExpr>(E); |
3398 | 0 | } |
3399 | | |
3400 | 116 | bool Expr::isObjCSelfExpr() const { |
3401 | 116 | const Expr *E = IgnoreParenImpCasts(); |
3402 | 116 | |
3403 | 116 | const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E); |
3404 | 116 | if (!DRE) |
3405 | 23 | return false; |
3406 | 93 | |
3407 | 93 | const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl()); |
3408 | 93 | if (!Param) |
3409 | 66 | return false; |
3410 | 27 | |
3411 | 27 | const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext()); |
3412 | 27 | if (!M) |
3413 | 0 | return false; |
3414 | 27 | |
3415 | 27 | return M->getSelfDecl() == Param; |
3416 | 27 | } |
3417 | | |
3418 | 11.5M | FieldDecl *Expr::getSourceBitField() { |
3419 | 11.5M | Expr *E = this->IgnoreParens(); |
3420 | 11.5M | |
3421 | 13.0M | while (ImplicitCastExpr *ICE13.0M = dyn_cast<ImplicitCastExpr>(E)) { |
3422 | 1.55M | if (ICE->getCastKind() == CK_LValueToRValue || |
3423 | 21.6k | (ICE->getValueKind() != VK_RValue && 21.6k ICE->getCastKind() == CK_NoOp47 )) |
3424 | 1.53M | E = ICE->getSubExpr()->IgnoreParens(); |
3425 | 1.55M | else |
3426 | 21.6k | break; |
3427 | 1.55M | } |
3428 | 11.5M | |
3429 | 11.5M | if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) |
3430 | 409k | if (FieldDecl *409k Field409k = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) |
3431 | 408k | if (408k Field->isBitField()408k ) |
3432 | 6.53k | return Field; |
3433 | 11.5M | |
3434 | 11.5M | if (ObjCIvarRefExpr *11.5M IvarRef11.5M = dyn_cast<ObjCIvarRefExpr>(E)) |
3435 | 824 | if (FieldDecl *824 Ivar824 = dyn_cast<FieldDecl>(IvarRef->getDecl())) |
3436 | 824 | if (824 Ivar->isBitField()824 ) |
3437 | 108 | return Ivar; |
3438 | 11.5M | |
3439 | 11.5M | if (DeclRefExpr *11.5M DeclRef11.5M = dyn_cast<DeclRefExpr>(E)) { |
3440 | 4.31M | if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) |
3441 | 11 | if (11 Field->isBitField()11 ) |
3442 | 0 | return Field; |
3443 | 4.31M | |
3444 | 4.31M | if (BindingDecl *4.31M BD4.31M = dyn_cast<BindingDecl>(DeclRef->getDecl())) |
3445 | 36 | if (Expr *36 E36 = BD->getBinding()) |
3446 | 36 | return E->getSourceBitField(); |
3447 | 11.5M | } |
3448 | 11.5M | |
3449 | 11.5M | if (BinaryOperator *11.5M BinOp11.5M = dyn_cast<BinaryOperator>(E)) { |
3450 | 1.21M | if (BinOp->isAssignmentOp() && 1.21M BinOp->getLHS()6.49k ) |
3451 | 6.49k | return BinOp->getLHS()->getSourceBitField(); |
3452 | 1.21M | |
3453 | 1.21M | if (1.21M BinOp->getOpcode() == BO_Comma && 1.21M BinOp->getRHS()309 ) |
3454 | 309 | return BinOp->getRHS()->getSourceBitField(); |
3455 | 11.5M | } |
3456 | 11.5M | |
3457 | 11.5M | if (UnaryOperator *11.5M UnOp11.5M = dyn_cast<UnaryOperator>(E)) |
3458 | 346k | if (346k UnOp->isPrefix() && 346k UnOp->isIncrementDecrementOp()8.11k ) |
3459 | 8.11k | return UnOp->getSubExpr()->getSourceBitField(); |
3460 | 11.5M | |
3461 | 11.5M | return nullptr; |
3462 | 11.5M | } |
3463 | | |
3464 | 198k | bool Expr::refersToVectorElement() const { |
3465 | 198k | // FIXME: Why do we not just look at the ObjectKind here? |
3466 | 198k | const Expr *E = this->IgnoreParens(); |
3467 | 198k | |
3468 | 198k | while (const ImplicitCastExpr *ICE198k = dyn_cast<ImplicitCastExpr>(E)) { |
3469 | 1.92k | if (ICE->getValueKind() != VK_RValue && |
3470 | 1.92k | ICE->getCastKind() == CK_NoOp) |
3471 | 377 | E = ICE->getSubExpr()->IgnoreParens(); |
3472 | 1.92k | else |
3473 | 1.54k | break; |
3474 | 1.92k | } |
3475 | 198k | |
3476 | 198k | if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) |
3477 | 27.5k | return ASE->getBase()->getType()->isVectorType(); |
3478 | 171k | |
3479 | 171k | if (171k isa<ExtVectorElementExpr>(E)171k ) |
3480 | 3 | return true; |
3481 | 171k | |
3482 | 171k | if (auto *171k DRE171k = dyn_cast<DeclRefExpr>(E)) |
3483 | 108k | if (auto *108k BD108k = dyn_cast<BindingDecl>(DRE->getDecl())) |
3484 | 1 | if (auto *1 E1 = BD->getBinding()) |
3485 | 1 | return E->refersToVectorElement(); |
3486 | 171k | |
3487 | 171k | return false; |
3488 | 171k | } |
3489 | | |
3490 | 4.59k | bool Expr::refersToGlobalRegisterVar() const { |
3491 | 4.59k | const Expr *E = this->IgnoreParenImpCasts(); |
3492 | 4.59k | |
3493 | 4.59k | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) |
3494 | 2.45k | if (const auto *2.45k VD2.45k = dyn_cast<VarDecl>(DRE->getDecl())) |
3495 | 2.45k | if (2.45k VD->getStorageClass() == SC_Register && |
3496 | 2.45k | VD->hasAttr<AsmLabelAttr>()145 && !VD->isLocalVarDecl()2 ) |
3497 | 2 | return true; |
3498 | 4.58k | |
3499 | 4.58k | return false; |
3500 | 4.58k | } |
3501 | | |
3502 | | /// isArrow - Return true if the base expression is a pointer to vector, |
3503 | | /// return false if the base expression is a vector. |
3504 | 331 | bool ExtVectorElementExpr::isArrow() const { |
3505 | 331 | return getBase()->getType()->isPointerType(); |
3506 | 331 | } |
3507 | | |
3508 | 261 | unsigned ExtVectorElementExpr::getNumElements() const { |
3509 | 261 | if (const VectorType *VT = getType()->getAs<VectorType>()) |
3510 | 61 | return VT->getNumElements(); |
3511 | 200 | return 1; |
3512 | 200 | } |
3513 | | |
3514 | | /// containsDuplicateElements - Return true if any element access is repeated. |
3515 | 78 | bool ExtVectorElementExpr::containsDuplicateElements() const { |
3516 | 78 | // FIXME: Refactor this code to an accessor on the AST node which returns the |
3517 | 78 | // "type" of component access, and share with code below and in Sema. |
3518 | 78 | StringRef Comp = Accessor->getName(); |
3519 | 78 | |
3520 | 78 | // Halving swizzles do not contain duplicate elements. |
3521 | 78 | if (Comp == "hi" || 78 Comp == "lo"76 || Comp == "even"61 || Comp == "odd"49 ) |
3522 | 30 | return false; |
3523 | 48 | |
3524 | 48 | // Advance past s-char prefix on hex swizzles. |
3525 | 48 | if (48 Comp[0] == 's' || 48 Comp[0] == 'S'48 ) |
3526 | 0 | Comp = Comp.substr(1); |
3527 | 48 | |
3528 | 110 | for (unsigned i = 0, e = Comp.size(); i != e110 ; ++i62 ) |
3529 | 70 | if (70 Comp.substr(i + 1).find(Comp[i]) != StringRef::npos70 ) |
3530 | 8 | return true; |
3531 | 48 | |
3532 | 40 | return false; |
3533 | 78 | } |
3534 | | |
3535 | | /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. |
3536 | | void ExtVectorElementExpr::getEncodedElementAccess( |
3537 | 261 | SmallVectorImpl<uint32_t> &Elts) const { |
3538 | 261 | StringRef Comp = Accessor->getName(); |
3539 | 261 | bool isNumericAccessor = false; |
3540 | 261 | if (Comp[0] == 's' || 261 Comp[0] == 'S'258 ) { |
3541 | 3 | Comp = Comp.substr(1); |
3542 | 3 | isNumericAccessor = true; |
3543 | 3 | } |
3544 | 261 | |
3545 | 261 | bool isHi = Comp == "hi"; |
3546 | 261 | bool isLo = Comp == "lo"; |
3547 | 261 | bool isEven = Comp == "even"; |
3548 | 261 | bool isOdd = Comp == "odd"; |
3549 | 261 | |
3550 | 637 | for (unsigned i = 0, e = getNumElements(); i != e637 ; ++i376 ) { |
3551 | 376 | uint64_t Index; |
3552 | 376 | |
3553 | 376 | if (isHi) |
3554 | 14 | Index = e + i; |
3555 | 362 | else if (362 isLo362 ) |
3556 | 46 | Index = i; |
3557 | 316 | else if (316 isEven316 ) |
3558 | 5 | Index = 2 * i; |
3559 | 311 | else if (311 isOdd311 ) |
3560 | 2 | Index = 2 * i + 1; |
3561 | 311 | else |
3562 | 309 | Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor); |
3563 | 376 | |
3564 | 376 | Elts.push_back(Index); |
3565 | 376 | } |
3566 | 261 | } |
3567 | | |
3568 | | ShuffleVectorExpr::ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, |
3569 | | QualType Type, SourceLocation BLoc, |
3570 | | SourceLocation RP) |
3571 | | : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary, |
3572 | | Type->isDependentType(), Type->isDependentType(), |
3573 | | Type->isInstantiationDependentType(), |
3574 | | Type->containsUnexpandedParameterPack()), |
3575 | | BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) |
3576 | 79.2k | { |
3577 | 79.2k | SubExprs = new (C) Stmt*[args.size()]; |
3578 | 837k | for (unsigned i = 0; i != args.size()837k ; i++757k ) { |
3579 | 757k | if (args[i]->isTypeDependent()) |
3580 | 0 | ExprBits.TypeDependent = true; |
3581 | 757k | if (args[i]->isValueDependent()) |
3582 | 2 | ExprBits.ValueDependent = true; |
3583 | 757k | if (args[i]->isInstantiationDependent()) |
3584 | 2 | ExprBits.InstantiationDependent = true; |
3585 | 757k | if (args[i]->containsUnexpandedParameterPack()) |
3586 | 0 | ExprBits.ContainsUnexpandedParameterPack = true; |
3587 | 757k | |
3588 | 757k | SubExprs[i] = args[i]; |
3589 | 757k | } |
3590 | 79.2k | } |
3591 | | |
3592 | 2 | void ShuffleVectorExpr::setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs) { |
3593 | 2 | if (SubExprs2 ) C.Deallocate(SubExprs)0 ; |
3594 | 2 | |
3595 | 2 | this->NumExprs = Exprs.size(); |
3596 | 2 | SubExprs = new (C) Stmt*[NumExprs]; |
3597 | 2 | memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size()); |
3598 | 2 | } |
3599 | | |
3600 | | GenericSelectionExpr::GenericSelectionExpr(const ASTContext &Context, |
3601 | | SourceLocation GenericLoc, Expr *ControllingExpr, |
3602 | | ArrayRef<TypeSourceInfo*> AssocTypes, |
3603 | | ArrayRef<Expr*> AssocExprs, |
3604 | | SourceLocation DefaultLoc, |
3605 | | SourceLocation RParenLoc, |
3606 | | bool ContainsUnexpandedParameterPack, |
3607 | | unsigned ResultIndex) |
3608 | | : Expr(GenericSelectionExprClass, |
3609 | | AssocExprs[ResultIndex]->getType(), |
3610 | | AssocExprs[ResultIndex]->getValueKind(), |
3611 | | AssocExprs[ResultIndex]->getObjectKind(), |
3612 | | AssocExprs[ResultIndex]->isTypeDependent(), |
3613 | | AssocExprs[ResultIndex]->isValueDependent(), |
3614 | | AssocExprs[ResultIndex]->isInstantiationDependent(), |
3615 | | ContainsUnexpandedParameterPack), |
3616 | | AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), |
3617 | | SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), |
3618 | | NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex), |
3619 | 82 | GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { |
3620 | 82 | SubExprs[CONTROLLING] = ControllingExpr; |
3621 | 82 | assert(AssocTypes.size() == AssocExprs.size()); |
3622 | 82 | std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); |
3623 | 82 | std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); |
3624 | 82 | } |
3625 | | |
3626 | | GenericSelectionExpr::GenericSelectionExpr(const ASTContext &Context, |
3627 | | SourceLocation GenericLoc, Expr *ControllingExpr, |
3628 | | ArrayRef<TypeSourceInfo*> AssocTypes, |
3629 | | ArrayRef<Expr*> AssocExprs, |
3630 | | SourceLocation DefaultLoc, |
3631 | | SourceLocation RParenLoc, |
3632 | | bool ContainsUnexpandedParameterPack) |
3633 | | : Expr(GenericSelectionExprClass, |
3634 | | Context.DependentTy, |
3635 | | VK_RValue, |
3636 | | OK_Ordinary, |
3637 | | /*isTypeDependent=*/true, |
3638 | | /*isValueDependent=*/true, |
3639 | | /*isInstantiationDependent=*/true, |
3640 | | ContainsUnexpandedParameterPack), |
3641 | | AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]), |
3642 | | SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]), |
3643 | | NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc), |
3644 | 2 | DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) { |
3645 | 2 | SubExprs[CONTROLLING] = ControllingExpr; |
3646 | 2 | assert(AssocTypes.size() == AssocExprs.size()); |
3647 | 2 | std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes); |
3648 | 2 | std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR); |
3649 | 2 | } |
3650 | | |
3651 | | //===----------------------------------------------------------------------===// |
3652 | | // DesignatedInitExpr |
3653 | | //===----------------------------------------------------------------------===// |
3654 | | |
3655 | 5.00k | IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { |
3656 | 5.00k | assert(Kind == FieldDesignator && "Only valid on a field designator"); |
3657 | 5.00k | if (Field.NameOrField & 0x01) |
3658 | 4.94k | return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); |
3659 | 5.00k | else |
3660 | 59 | return getField()->getIdentifier(); |
3661 | 0 | } |
3662 | | |
3663 | | DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty, |
3664 | | llvm::ArrayRef<Designator> Designators, |
3665 | | SourceLocation EqualOrColonLoc, |
3666 | | bool GNUSyntax, |
3667 | | ArrayRef<Expr*> IndexExprs, |
3668 | | Expr *Init) |
3669 | | : Expr(DesignatedInitExprClass, Ty, |
3670 | | Init->getValueKind(), Init->getObjectKind(), |
3671 | | Init->isTypeDependent(), Init->isValueDependent(), |
3672 | | Init->isInstantiationDependent(), |
3673 | | Init->containsUnexpandedParameterPack()), |
3674 | | EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), |
3675 | 2.58k | NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) { |
3676 | 2.58k | this->Designators = new (C) Designator[NumDesignators]; |
3677 | 2.58k | |
3678 | 2.58k | // Record the initializer itself. |
3679 | 2.58k | child_iterator Child = child_begin(); |
3680 | 2.58k | *Child++ = Init; |
3681 | 2.58k | |
3682 | 2.58k | // Copy the designators and their subexpressions, computing |
3683 | 2.58k | // value-dependence along the way. |
3684 | 2.58k | unsigned IndexIdx = 0; |
3685 | 5.37k | for (unsigned I = 0; I != NumDesignators5.37k ; ++I2.79k ) { |
3686 | 2.79k | this->Designators[I] = Designators[I]; |
3687 | 2.79k | |
3688 | 2.79k | if (this->Designators[I].isArrayDesignator()2.79k ) { |
3689 | 252 | // Compute type- and value-dependence. |
3690 | 252 | Expr *Index = IndexExprs[IndexIdx]; |
3691 | 252 | if (Index->isTypeDependent() || 252 Index->isValueDependent()252 ) |
3692 | 7 | ExprBits.TypeDependent = ExprBits.ValueDependent = true; |
3693 | 252 | if (Index->isInstantiationDependent()) |
3694 | 7 | ExprBits.InstantiationDependent = true; |
3695 | 252 | // Propagate unexpanded parameter packs. |
3696 | 252 | if (Index->containsUnexpandedParameterPack()) |
3697 | 0 | ExprBits.ContainsUnexpandedParameterPack = true; |
3698 | 252 | |
3699 | 252 | // Copy the index expressions into permanent storage. |
3700 | 252 | *Child++ = IndexExprs[IndexIdx++]; |
3701 | 2.79k | } else if (2.54k this->Designators[I].isArrayRangeDesignator()2.54k ) { |
3702 | 25 | // Compute type- and value-dependence. |
3703 | 25 | Expr *Start = IndexExprs[IndexIdx]; |
3704 | 25 | Expr *End = IndexExprs[IndexIdx + 1]; |
3705 | 25 | if (Start->isTypeDependent() || 25 Start->isValueDependent()25 || |
3706 | 25 | End->isTypeDependent()22 || End->isValueDependent()22 ) { |
3707 | 3 | ExprBits.TypeDependent = ExprBits.ValueDependent = true; |
3708 | 3 | ExprBits.InstantiationDependent = true; |
3709 | 25 | } else if (22 Start->isInstantiationDependent() || |
3710 | 22 | End->isInstantiationDependent()22 ) { |
3711 | 0 | ExprBits.InstantiationDependent = true; |
3712 | 0 | } |
3713 | 25 | |
3714 | 25 | // Propagate unexpanded parameter packs. |
3715 | 25 | if (Start->containsUnexpandedParameterPack() || |
3716 | 25 | End->containsUnexpandedParameterPack()) |
3717 | 0 | ExprBits.ContainsUnexpandedParameterPack = true; |
3718 | 2.54k | |
3719 | 2.54k | // Copy the start/end expressions into permanent storage. |
3720 | 2.54k | *Child++ = IndexExprs[IndexIdx++]; |
3721 | 2.54k | *Child++ = IndexExprs[IndexIdx++]; |
3722 | 2.54k | } |
3723 | 2.79k | } |
3724 | 2.58k | |
3725 | 2.58k | assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions"); |
3726 | 2.58k | } |
3727 | | |
3728 | | DesignatedInitExpr * |
3729 | | DesignatedInitExpr::Create(const ASTContext &C, |
3730 | | llvm::ArrayRef<Designator> Designators, |
3731 | | ArrayRef<Expr*> IndexExprs, |
3732 | | SourceLocation ColonOrEqualLoc, |
3733 | 2.58k | bool UsesColonSyntax, Expr *Init) { |
3734 | 2.58k | void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1), |
3735 | 2.58k | alignof(DesignatedInitExpr)); |
3736 | 2.58k | return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators, |
3737 | 2.58k | ColonOrEqualLoc, UsesColonSyntax, |
3738 | 2.58k | IndexExprs, Init); |
3739 | 2.58k | } |
3740 | | |
3741 | | DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(const ASTContext &C, |
3742 | 9 | unsigned NumIndexExprs) { |
3743 | 9 | void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1), |
3744 | 9 | alignof(DesignatedInitExpr)); |
3745 | 9 | return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); |
3746 | 9 | } |
3747 | | |
3748 | | void DesignatedInitExpr::setDesignators(const ASTContext &C, |
3749 | | const Designator *Desigs, |
3750 | 9 | unsigned NumDesigs) { |
3751 | 9 | Designators = new (C) Designator[NumDesigs]; |
3752 | 9 | NumDesignators = NumDesigs; |
3753 | 27 | for (unsigned I = 0; I != NumDesigs27 ; ++I18 ) |
3754 | 18 | Designators[I] = Desigs[I]; |
3755 | 9 | } |
3756 | | |
3757 | 0 | SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { |
3758 | 0 | DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this); |
3759 | 0 | if (size() == 1) |
3760 | 0 | return DIE->getDesignator(0)->getSourceRange(); |
3761 | 0 | return SourceRange(DIE->getDesignator(0)->getLocStart(), |
3762 | 0 | DIE->getDesignator(size()-1)->getLocEnd()); |
3763 | 0 | } |
3764 | | |
3765 | 456 | SourceLocation DesignatedInitExpr::getLocStart() const { |
3766 | 456 | SourceLocation StartLoc; |
3767 | 456 | auto *DIE = const_cast<DesignatedInitExpr *>(this); |
3768 | 456 | Designator &First = *DIE->getDesignator(0); |
3769 | 456 | if (First.isFieldDesignator()456 ) { |
3770 | 320 | if (GNUSyntax) |
3771 | 2 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); |
3772 | 320 | else |
3773 | 318 | StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); |
3774 | 320 | } else |
3775 | 136 | StartLoc = |
3776 | 136 | SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); |
3777 | 456 | return StartLoc; |
3778 | 456 | } |
3779 | | |
3780 | 486 | SourceLocation DesignatedInitExpr::getLocEnd() const { |
3781 | 486 | return getInit()->getLocEnd(); |
3782 | 486 | } |
3783 | | |
3784 | 511 | Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) const { |
3785 | 511 | assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); |
3786 | 511 | return getSubExpr(D.ArrayOrRange.Index + 1); |
3787 | 511 | } |
3788 | | |
3789 | 57 | Expr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const { |
3790 | 57 | assert(D.Kind == Designator::ArrayRangeDesignator && |
3791 | 57 | "Requires array range designator"); |
3792 | 57 | return getSubExpr(D.ArrayOrRange.Index + 1); |
3793 | 57 | } |
3794 | | |
3795 | 93 | Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const { |
3796 | 93 | assert(D.Kind == Designator::ArrayRangeDesignator && |
3797 | 93 | "Requires array range designator"); |
3798 | 93 | return getSubExpr(D.ArrayOrRange.Index + 2); |
3799 | 93 | } |
3800 | | |
3801 | | /// \brief Replaces the designator at index @p Idx with the series |
3802 | | /// of designators in [First, Last). |
3803 | | void DesignatedInitExpr::ExpandDesignator(const ASTContext &C, unsigned Idx, |
3804 | | const Designator *First, |
3805 | 28 | const Designator *Last) { |
3806 | 28 | unsigned NumNewDesignators = Last - First; |
3807 | 28 | if (NumNewDesignators == 028 ) { |
3808 | 0 | std::copy_backward(Designators + Idx + 1, |
3809 | 0 | Designators + NumDesignators, |
3810 | 0 | Designators + Idx); |
3811 | 0 | --NumNewDesignators; |
3812 | 0 | return; |
3813 | 28 | } else if (28 NumNewDesignators == 128 ) { |
3814 | 0 | Designators[Idx] = *First; |
3815 | 0 | return; |
3816 | 0 | } |
3817 | 28 | |
3818 | 28 | Designator *NewDesignators |
3819 | 28 | = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; |
3820 | 28 | std::copy(Designators, Designators + Idx, NewDesignators); |
3821 | 28 | std::copy(First, Last, NewDesignators + Idx); |
3822 | 28 | std::copy(Designators + Idx + 1, Designators + NumDesignators, |
3823 | 28 | NewDesignators + Idx + NumNewDesignators); |
3824 | 28 | Designators = NewDesignators; |
3825 | 28 | NumDesignators = NumDesignators - 1 + NumNewDesignators; |
3826 | 28 | } |
3827 | | |
3828 | | DesignatedInitUpdateExpr::DesignatedInitUpdateExpr(const ASTContext &C, |
3829 | | SourceLocation lBraceLoc, Expr *baseExpr, SourceLocation rBraceLoc) |
3830 | | : Expr(DesignatedInitUpdateExprClass, baseExpr->getType(), VK_RValue, |
3831 | 34 | OK_Ordinary, false, false, false, false) { |
3832 | 34 | BaseAndUpdaterExprs[0] = baseExpr; |
3833 | 34 | |
3834 | 34 | InitListExpr *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc); |
3835 | 34 | ILE->setType(baseExpr->getType()); |
3836 | 34 | BaseAndUpdaterExprs[1] = ILE; |
3837 | 34 | } |
3838 | | |
3839 | 68 | SourceLocation DesignatedInitUpdateExpr::getLocStart() const { |
3840 | 68 | return getBase()->getLocStart(); |
3841 | 68 | } |
3842 | | |
3843 | 20 | SourceLocation DesignatedInitUpdateExpr::getLocEnd() const { |
3844 | 20 | return getBase()->getLocEnd(); |
3845 | 20 | } |
3846 | | |
3847 | | ParenListExpr::ParenListExpr(const ASTContext& C, SourceLocation lparenloc, |
3848 | | ArrayRef<Expr*> exprs, |
3849 | | SourceLocation rparenloc) |
3850 | | : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, |
3851 | | false, false, false, false), |
3852 | 328k | NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) { |
3853 | 328k | Exprs = new (C) Stmt*[exprs.size()]; |
3854 | 722k | for (unsigned i = 0; i != exprs.size()722k ; ++i393k ) { |
3855 | 393k | if (exprs[i]->isTypeDependent()) |
3856 | 37.8k | ExprBits.TypeDependent = true; |
3857 | 393k | if (exprs[i]->isValueDependent()) |
3858 | 46.9k | ExprBits.ValueDependent = true; |
3859 | 393k | if (exprs[i]->isInstantiationDependent()) |
3860 | 46.9k | ExprBits.InstantiationDependent = true; |
3861 | 393k | if (exprs[i]->containsUnexpandedParameterPack()) |
3862 | 68 | ExprBits.ContainsUnexpandedParameterPack = true; |
3863 | 393k | |
3864 | 393k | Exprs[i] = exprs[i]; |
3865 | 393k | } |
3866 | 328k | } |
3867 | | |
3868 | 7 | const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { |
3869 | 7 | if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e)) |
3870 | 2 | e = ewc->getSubExpr(); |
3871 | 7 | if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e)) |
3872 | 0 | e = m->GetTemporaryExpr(); |
3873 | 7 | e = cast<CXXConstructExpr>(e)->getArg(0); |
3874 | 14 | while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) |
3875 | 7 | e = ice->getSubExpr(); |
3876 | 7 | return cast<OpaqueValueExpr>(e); |
3877 | 7 | } |
3878 | | |
3879 | | PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &Context, |
3880 | | EmptyShell sh, |
3881 | 34 | unsigned numSemanticExprs) { |
3882 | 34 | void *buffer = |
3883 | 34 | Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs), |
3884 | 34 | alignof(PseudoObjectExpr)); |
3885 | 34 | return new(buffer) PseudoObjectExpr(sh, numSemanticExprs); |
3886 | 34 | } |
3887 | | |
3888 | | PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) |
3889 | 34 | : Expr(PseudoObjectExprClass, shell) { |
3890 | 34 | PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; |
3891 | 34 | } |
3892 | | |
3893 | | PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax, |
3894 | | ArrayRef<Expr*> semantics, |
3895 | 2.56k | unsigned resultIndex) { |
3896 | 2.56k | assert(syntax && "no syntactic expression!"); |
3897 | 2.56k | assert(semantics.size() && "no semantic expressions!"); |
3898 | 2.56k | |
3899 | 2.56k | QualType type; |
3900 | 2.56k | ExprValueKind VK; |
3901 | 2.56k | if (resultIndex == NoResult2.56k ) { |
3902 | 47 | type = C.VoidTy; |
3903 | 47 | VK = VK_RValue; |
3904 | 2.56k | } else { |
3905 | 2.51k | assert(resultIndex < semantics.size()); |
3906 | 2.51k | type = semantics[resultIndex]->getType(); |
3907 | 2.51k | VK = semantics[resultIndex]->getValueKind(); |
3908 | 2.51k | assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary); |
3909 | 2.51k | } |
3910 | 2.56k | |
3911 | 2.56k | void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1), |
3912 | 2.56k | alignof(PseudoObjectExpr)); |
3913 | 2.56k | return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics, |
3914 | 2.56k | resultIndex); |
3915 | 2.56k | } |
3916 | | |
3917 | | PseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK, |
3918 | | Expr *syntax, ArrayRef<Expr*> semantics, |
3919 | | unsigned resultIndex) |
3920 | | : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary, |
3921 | 2.56k | /*filled in at end of ctor*/ false, false, false, false) { |
3922 | 2.56k | PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; |
3923 | 2.56k | PseudoObjectExprBits.ResultIndex = resultIndex + 1; |
3924 | 2.56k | |
3925 | 11.7k | for (unsigned i = 0, e = semantics.size() + 1; i != e11.7k ; ++i9.14k ) { |
3926 | 9.14k | Expr *E = (i == 0 ? syntax2.56k : semantics[i-1]6.58k ); |
3927 | 9.14k | getSubExprsBuffer()[i] = E; |
3928 | 9.14k | |
3929 | 9.14k | if (E->isTypeDependent()) |
3930 | 73 | ExprBits.TypeDependent = true; |
3931 | 9.14k | if (E->isValueDependent()) |
3932 | 106 | ExprBits.ValueDependent = true; |
3933 | 9.14k | if (E->isInstantiationDependent()) |
3934 | 111 | ExprBits.InstantiationDependent = true; |
3935 | 9.14k | if (E->containsUnexpandedParameterPack()) |
3936 | 0 | ExprBits.ContainsUnexpandedParameterPack = true; |
3937 | 9.14k | |
3938 | 9.14k | if (isa<OpaqueValueExpr>(E)) |
3939 | 9.14k | assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr && |
3940 | 9.14k | "opaque-value semantic expressions for pseudo-object " |
3941 | 9.14k | "operations must have sources"); |
3942 | 9.14k | } |
3943 | 2.56k | } |
3944 | | |
3945 | | //===----------------------------------------------------------------------===// |
3946 | | // Child Iterators for iterating over subexpressions/substatements |
3947 | | //===----------------------------------------------------------------------===// |
3948 | | |
3949 | | // UnaryExprOrTypeTraitExpr |
3950 | 33.9k | Stmt::child_range UnaryExprOrTypeTraitExpr::children() { |
3951 | 33.9k | const_child_range CCR = |
3952 | 33.9k | const_cast<const UnaryExprOrTypeTraitExpr *>(this)->children(); |
3953 | 33.9k | return child_range(cast_away_const(CCR.begin()), cast_away_const(CCR.end())); |
3954 | 33.9k | } |
3955 | | |
3956 | 33.9k | Stmt::const_child_range UnaryExprOrTypeTraitExpr::children() const { |
3957 | 33.9k | // If this is of a type and the type is a VLA type (and not a typedef), the |
3958 | 33.9k | // size expression of the VLA needs to be treated as an executable expression. |
3959 | 33.9k | // Why isn't this weirdness documented better in StmtIterator? |
3960 | 33.9k | if (isArgumentType()33.9k ) { |
3961 | 27.4k | if (const VariableArrayType *T = |
3962 | 27.4k | dyn_cast<VariableArrayType>(getArgumentType().getTypePtr())) |
3963 | 10 | return const_child_range(const_child_iterator(T), const_child_iterator()); |
3964 | 27.4k | return const_child_range(const_child_iterator(), const_child_iterator()); |
3965 | 27.4k | } |
3966 | 6.51k | return const_child_range(&Argument.Ex, &Argument.Ex + 1); |
3967 | 6.51k | } |
3968 | | |
3969 | | AtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, |
3970 | | QualType t, AtomicOp op, SourceLocation RP) |
3971 | | : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary, |
3972 | | false, false, false, false), |
3973 | | NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) |
3974 | 2.18k | { |
3975 | 2.18k | assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions"); |
3976 | 9.44k | for (unsigned i = 0; i != args.size()9.44k ; i++7.25k ) { |
3977 | 7.25k | if (args[i]->isTypeDependent()) |
3978 | 0 | ExprBits.TypeDependent = true; |
3979 | 7.25k | if (args[i]->isValueDependent()) |
3980 | 3 | ExprBits.ValueDependent = true; |
3981 | 7.25k | if (args[i]->isInstantiationDependent()) |
3982 | 3 | ExprBits.InstantiationDependent = true; |
3983 | 7.25k | if (args[i]->containsUnexpandedParameterPack()) |
3984 | 0 | ExprBits.ContainsUnexpandedParameterPack = true; |
3985 | 7.25k | |
3986 | 7.25k | SubExprs[i] = args[i]; |
3987 | 7.25k | } |
3988 | 2.18k | } |
3989 | | |
3990 | 112 | unsigned AtomicExpr::getNumSubExprs(AtomicOp Op) { |
3991 | 112 | switch (Op) { |
3992 | 14 | case AO__c11_atomic_init: |
3993 | 14 | case AO__opencl_atomic_init: |
3994 | 14 | case AO__c11_atomic_load: |
3995 | 14 | case AO__atomic_load_n: |
3996 | 14 | return 2; |
3997 | 14 | |
3998 | 58 | case AO__opencl_atomic_load: |
3999 | 58 | case AO__c11_atomic_store: |
4000 | 58 | case AO__c11_atomic_exchange: |
4001 | 58 | case AO__atomic_load: |
4002 | 58 | case AO__atomic_store: |
4003 | 58 | case AO__atomic_store_n: |
4004 | 58 | case AO__atomic_exchange_n: |
4005 | 58 | case AO__c11_atomic_fetch_add: |
4006 | 58 | case AO__c11_atomic_fetch_sub: |
4007 | 58 | case AO__c11_atomic_fetch_and: |
4008 | 58 | case AO__c11_atomic_fetch_or: |
4009 | 58 | case AO__c11_atomic_fetch_xor: |
4010 | 58 | case AO__atomic_fetch_add: |
4011 | 58 | case AO__atomic_fetch_sub: |
4012 | 58 | case AO__atomic_fetch_and: |
4013 | 58 | case AO__atomic_fetch_or: |
4014 | 58 | case AO__atomic_fetch_xor: |
4015 | 58 | case AO__atomic_fetch_nand: |
4016 | 58 | case AO__atomic_add_fetch: |
4017 | 58 | case AO__atomic_sub_fetch: |
4018 | 58 | case AO__atomic_and_fetch: |
4019 | 58 | case AO__atomic_or_fetch: |
4020 | 58 | case AO__atomic_xor_fetch: |
4021 | 58 | case AO__atomic_nand_fetch: |
4022 | 58 | return 3; |
4023 | 58 | |
4024 | 16 | case AO__opencl_atomic_store: |
4025 | 16 | case AO__opencl_atomic_exchange: |
4026 | 16 | case AO__opencl_atomic_fetch_add: |
4027 | 16 | case AO__opencl_atomic_fetch_sub: |
4028 | 16 | case AO__opencl_atomic_fetch_and: |
4029 | 16 | case AO__opencl_atomic_fetch_or: |
4030 | 16 | case AO__opencl_atomic_fetch_xor: |
4031 | 16 | case AO__opencl_atomic_fetch_min: |
4032 | 16 | case AO__opencl_atomic_fetch_max: |
4033 | 16 | case AO__atomic_exchange: |
4034 | 16 | return 4; |
4035 | 16 | |
4036 | 9 | case AO__c11_atomic_compare_exchange_strong: |
4037 | 9 | case AO__c11_atomic_compare_exchange_weak: |
4038 | 9 | return 5; |
4039 | 9 | |
4040 | 15 | case AO__opencl_atomic_compare_exchange_strong: |
4041 | 15 | case AO__opencl_atomic_compare_exchange_weak: |
4042 | 15 | case AO__atomic_compare_exchange: |
4043 | 15 | case AO__atomic_compare_exchange_n: |
4044 | 15 | return 6; |
4045 | 0 | } |
4046 | 0 | llvm_unreachable0 ("unknown atomic op"); |
4047 | 0 | } |
4048 | | |
4049 | 12 | QualType AtomicExpr::getValueType() const { |
4050 | 12 | auto T = getPtr()->getType()->castAs<PointerType>()->getPointeeType(); |
4051 | 12 | if (auto AT = T->getAs<AtomicType>()) |
4052 | 12 | return AT->getValueType(); |
4053 | 0 | return T; |
4054 | 0 | } |
4055 | | |
4056 | 3.58k | QualType OMPArraySectionExpr::getBaseOriginalType(const Expr *Base) { |
4057 | 3.58k | unsigned ArraySectionCount = 0; |
4058 | 4.74k | while (auto *OASE4.74k = dyn_cast<OMPArraySectionExpr>(Base->IgnoreParens())) { |
4059 | 1.15k | Base = OASE->getBase(); |
4060 | 1.15k | ++ArraySectionCount; |
4061 | 1.15k | } |
4062 | 3.82k | while (auto *ASE = |
4063 | 244 | dyn_cast<ArraySubscriptExpr>(Base->IgnoreParenImpCasts())) { |
4064 | 244 | Base = ASE->getBase(); |
4065 | 244 | ++ArraySectionCount; |
4066 | 244 | } |
4067 | 3.58k | Base = Base->IgnoreParenImpCasts(); |
4068 | 3.58k | auto OriginalTy = Base->getType(); |
4069 | 3.58k | if (auto *DRE = dyn_cast<DeclRefExpr>(Base)) |
4070 | 3.10k | if (auto *3.10k PVD3.10k = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
4071 | 346 | OriginalTy = PVD->getOriginalType().getNonReferenceType(); |
4072 | 3.58k | |
4073 | 4.98k | for (unsigned Cnt = 0; Cnt < ArraySectionCount4.98k ; ++Cnt1.40k ) { |
4074 | 1.40k | if (OriginalTy->isAnyPointerType()) |
4075 | 405 | OriginalTy = OriginalTy->getPointeeType(); |
4076 | 997 | else { |
4077 | 997 | assert (OriginalTy->isArrayType()); |
4078 | 997 | OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType(); |
4079 | 997 | } |
4080 | 1.40k | } |
4081 | 3.58k | return OriginalTy; |
4082 | 3.58k | } |