clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CGExprCXX.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangCodeGen/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangCodeGen/../include -I /usr/src/gnu/usr.bin/clang/libclangCodeGen/obj -I /usr/src/gnu/usr.bin/clang/libclangCodeGen/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangCodeGen/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangCodeGen/../../../llvm/clang/lib/CodeGen/CGExprCXX.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "CGCUDARuntime.h" |
| 14 | #include "CGCXXABI.h" |
| 15 | #include "CGDebugInfo.h" |
| 16 | #include "CGObjCRuntime.h" |
| 17 | #include "CodeGenFunction.h" |
| 18 | #include "ConstantEmitter.h" |
| 19 | #include "TargetInfo.h" |
| 20 | #include "clang/Basic/CodeGenOptions.h" |
| 21 | #include "clang/CodeGen/CGFunctionInfo.h" |
| 22 | #include "llvm/IR/Intrinsics.h" |
| 23 | |
| 24 | using namespace clang; |
| 25 | using namespace CodeGen; |
| 26 | |
| 27 | namespace { |
| 28 | struct MemberCallInfo { |
| 29 | RequiredArgs ReqArgs; |
| 30 | |
| 31 | unsigned PrefixSize; |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | static MemberCallInfo |
| 36 | commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD, |
| 37 | llvm::Value *This, llvm::Value *ImplicitParam, |
| 38 | QualType ImplicitParamTy, const CallExpr *CE, |
| 39 | CallArgList &Args, CallArgList *RtlArgs) { |
| 40 | assert(CE == nullptr || isa<CXXMemberCallExpr>(CE) || |
| 41 | isa<CXXOperatorCallExpr>(CE)); |
| 42 | assert(MD->isInstance() && |
| 43 | "Trying to emit a member or operator call expr on a static method!"); |
| 44 | |
| 45 | |
| 46 | const CXXRecordDecl *RD = |
| 47 | CGF.CGM.getCXXABI().getThisArgumentTypeForMethod(MD); |
| 48 | Args.add(RValue::get(This), CGF.getTypes().DeriveThisType(RD, MD)); |
| 49 | |
| 50 | |
| 51 | if (ImplicitParam) { |
| 52 | Args.add(RValue::get(ImplicitParam), ImplicitParamTy); |
| 53 | } |
| 54 | |
| 55 | const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>(); |
| 56 | RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size()); |
| 57 | unsigned PrefixSize = Args.size() - 1; |
| 58 | |
| 59 | |
| 60 | if (RtlArgs) { |
| 61 | |
| 62 | |
| 63 | |
| 64 | Args.addFrom(*RtlArgs); |
| 65 | } else if (CE) { |
| 66 | |
| 67 | unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0; |
| 68 | CGF.EmitCallArgs(Args, FPT, drop_begin(CE->arguments(), ArgsToSkip), |
| 69 | CE->getDirectCallee()); |
| 70 | } else { |
| 71 | assert( |
| 72 | FPT->getNumParams() == 0 && |
| 73 | "No CallExpr specified for function with non-zero number of arguments"); |
| 74 | } |
| 75 | return {required, PrefixSize}; |
| 76 | } |
| 77 | |
| 78 | RValue CodeGenFunction::EmitCXXMemberOrOperatorCall( |
| 79 | const CXXMethodDecl *MD, const CGCallee &Callee, |
| 80 | ReturnValueSlot ReturnValue, |
| 81 | llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, |
| 82 | const CallExpr *CE, CallArgList *RtlArgs) { |
| 83 | const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>(); |
| 84 | CallArgList Args; |
| 85 | MemberCallInfo CallInfo = commonEmitCXXMemberOrOperatorCall( |
| 86 | *this, MD, This, ImplicitParam, ImplicitParamTy, CE, Args, RtlArgs); |
| 87 | auto &FnInfo = CGM.getTypes().arrangeCXXMethodCall( |
| 88 | Args, FPT, CallInfo.ReqArgs, CallInfo.PrefixSize); |
| 89 | return EmitCall(FnInfo, Callee, ReturnValue, Args, nullptr, |
| 90 | CE && CE == MustTailCall, |
| 91 | CE ? CE->getExprLoc() : SourceLocation()); |
| 92 | } |
| 93 | |
| 94 | RValue CodeGenFunction::EmitCXXDestructorCall( |
| 95 | GlobalDecl Dtor, const CGCallee &Callee, llvm::Value *This, QualType ThisTy, |
| 96 | llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE) { |
| 97 | const CXXMethodDecl *DtorDecl = cast<CXXMethodDecl>(Dtor.getDecl()); |
| 98 | |
| 99 | assert(!ThisTy.isNull()); |
| 100 | assert(ThisTy->getAsCXXRecordDecl() == DtorDecl->getParent() && |
| 101 | "Pointer/Object mixup"); |
| 102 | |
| 103 | LangAS SrcAS = ThisTy.getAddressSpace(); |
| 104 | LangAS DstAS = DtorDecl->getMethodQualifiers().getAddressSpace(); |
| 105 | if (SrcAS != DstAS) { |
| 106 | QualType DstTy = DtorDecl->getThisType(); |
| 107 | llvm::Type *NewType = CGM.getTypes().ConvertType(DstTy); |
| 108 | This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, DstAS, |
| 109 | NewType); |
| 110 | } |
| 111 | |
| 112 | CallArgList Args; |
| 113 | commonEmitCXXMemberOrOperatorCall(*this, DtorDecl, This, ImplicitParam, |
| 114 | ImplicitParamTy, CE, Args, nullptr); |
| 115 | return EmitCall(CGM.getTypes().arrangeCXXStructorDeclaration(Dtor), Callee, |
| 116 | ReturnValueSlot(), Args, nullptr, CE && CE == MustTailCall, |
| 117 | CE ? CE->getExprLoc() : SourceLocation{}); |
| 118 | } |
| 119 | |
| 120 | RValue CodeGenFunction::EmitCXXPseudoDestructorExpr( |
| 121 | const CXXPseudoDestructorExpr *E) { |
| 122 | QualType DestroyedType = E->getDestroyedType(); |
| 123 | if (DestroyedType.hasStrongOrWeakObjCLifetime()) { |
| 124 | |
| 125 | |
| 126 | |
| 127 | Expr *BaseExpr = E->getBase(); |
| 128 | Address BaseValue = Address::invalid(); |
| 129 | Qualifiers BaseQuals; |
| 130 | |
| 131 | |
| 132 | if (E->isArrow()) { |
| 133 | BaseValue = EmitPointerWithAlignment(BaseExpr); |
| 134 | const auto *PTy = BaseExpr->getType()->castAs<PointerType>(); |
| 135 | BaseQuals = PTy->getPointeeType().getQualifiers(); |
| 136 | } else { |
| 137 | LValue BaseLV = EmitLValue(BaseExpr); |
| 138 | BaseValue = BaseLV.getAddress(*this); |
| 139 | QualType BaseTy = BaseExpr->getType(); |
| 140 | BaseQuals = BaseTy.getQualifiers(); |
| 141 | } |
| 142 | |
| 143 | switch (DestroyedType.getObjCLifetime()) { |
| 144 | case Qualifiers::OCL_None: |
| 145 | case Qualifiers::OCL_ExplicitNone: |
| 146 | case Qualifiers::OCL_Autoreleasing: |
| 147 | break; |
| 148 | |
| 149 | case Qualifiers::OCL_Strong: |
| 150 | EmitARCRelease(Builder.CreateLoad(BaseValue, |
| 151 | DestroyedType.isVolatileQualified()), |
| 152 | ARCPreciseLifetime); |
| 153 | break; |
| 154 | |
| 155 | case Qualifiers::OCL_Weak: |
| 156 | EmitARCDestroyWeak(BaseValue); |
| 157 | break; |
| 158 | } |
| 159 | } else { |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | EmitIgnoredExpr(E->getBase()); |
| 166 | } |
| 167 | |
| 168 | return RValue::get(nullptr); |
| 169 | } |
| 170 | |
| 171 | static CXXRecordDecl *getCXXRecord(const Expr *E) { |
| 172 | QualType T = E->getType(); |
| 173 | if (const PointerType *PTy = T->getAs<PointerType>()) |
| 174 | T = PTy->getPointeeType(); |
| 175 | const RecordType *Ty = T->castAs<RecordType>(); |
| 176 | return cast<CXXRecordDecl>(Ty->getDecl()); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE, |
| 182 | ReturnValueSlot ReturnValue) { |
| 183 | const Expr *callee = CE->getCallee()->IgnoreParens(); |
| 184 | |
| 185 | if (isa<BinaryOperator>(callee)) |
| 186 | return EmitCXXMemberPointerCallExpr(CE, ReturnValue); |
| 187 | |
| 188 | const MemberExpr *ME = cast<MemberExpr>(callee); |
| 189 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(ME->getMemberDecl()); |
| 190 | |
| 191 | if (MD->isStatic()) { |
| 192 | |
| 193 | CGCallee callee = |
| 194 | CGCallee::forDirect(CGM.GetAddrOfFunction(MD), GlobalDecl(MD)); |
| 195 | return EmitCall(getContext().getPointerType(MD->getType()), callee, CE, |
| 196 | ReturnValue); |
| 197 | } |
| 198 | |
| 199 | bool HasQualifier = ME->hasQualifier(); |
| 200 | NestedNameSpecifier *Qualifier = HasQualifier ? ME->getQualifier() : nullptr; |
| 201 | bool IsArrow = ME->isArrow(); |
| 202 | const Expr *Base = ME->getBase(); |
| 203 | |
| 204 | return EmitCXXMemberOrOperatorMemberCallExpr( |
| 205 | CE, MD, ReturnValue, HasQualifier, Qualifier, IsArrow, Base); |
| 206 | } |
| 207 | |
| 208 | RValue CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr( |
| 209 | const CallExpr *CE, const CXXMethodDecl *MD, ReturnValueSlot ReturnValue, |
| 210 | bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow, |
| 211 | const Expr *Base) { |
| 212 | assert(isa<CXXMemberCallExpr>(CE) || isa<CXXOperatorCallExpr>(CE)); |
| 213 | |
| 214 | |
| 215 | bool CanUseVirtualCall = MD->isVirtual() && !HasQualifier; |
| 216 | |
| 217 | const CXXMethodDecl *DevirtualizedMethod = nullptr; |
| 218 | if (CanUseVirtualCall && |
| 219 | MD->getDevirtualizedMethod(Base, getLangOpts().AppleKext)) { |
| 220 | const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType(); |
| 221 | DevirtualizedMethod = MD->getCorrespondingMethodInClass(BestDynamicDecl); |
| 222 | assert(DevirtualizedMethod); |
| 223 | const CXXRecordDecl *DevirtualizedClass = DevirtualizedMethod->getParent(); |
| 224 | const Expr *Inner = Base->IgnoreParenBaseCasts(); |
| 225 | if (DevirtualizedMethod->getReturnType().getCanonicalType() != |
| 226 | MD->getReturnType().getCanonicalType()) |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | DevirtualizedMethod = nullptr; |
| 233 | else if (getCXXRecord(Inner) == DevirtualizedClass) |
| 234 | |
| 235 | |
| 236 | Base = Inner; |
| 237 | else if (getCXXRecord(Base) != DevirtualizedClass) { |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | DevirtualizedMethod = nullptr; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | bool TrivialForCodegen = |
| 247 | MD->isTrivial() || (MD->isDefaulted() && MD->getParent()->isUnion()); |
| 248 | bool TrivialAssignment = |
| 249 | TrivialForCodegen && |
| 250 | (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()) && |
| 251 | !MD->getParent()->mayInsertExtraPadding(); |
| 252 | |
| 253 | |
| 254 | |
| 255 | CallArgList RtlArgStorage; |
| 256 | CallArgList *RtlArgs = nullptr; |
| 257 | LValue TrivialAssignmentRHS; |
| 258 | if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(CE)) { |
| 259 | if (OCE->isAssignmentOp()) { |
| 260 | if (TrivialAssignment) { |
| 261 | TrivialAssignmentRHS = EmitLValue(CE->getArg(1)); |
| 262 | } else { |
| 263 | RtlArgs = &RtlArgStorage; |
| 264 | EmitCallArgs(*RtlArgs, MD->getType()->castAs<FunctionProtoType>(), |
| 265 | drop_begin(CE->arguments(), 1), CE->getDirectCallee(), |
| 266 | 0, EvaluationOrder::ForceRightToLeft); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | LValue This; |
| 272 | if (IsArrow) { |
| 273 | LValueBaseInfo BaseInfo; |
| 274 | TBAAAccessInfo TBAAInfo; |
| 275 | Address ThisValue = EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo); |
| 276 | This = MakeAddrLValue(ThisValue, Base->getType(), BaseInfo, TBAAInfo); |
| 277 | } else { |
| 278 | This = EmitLValue(Base); |
| 279 | } |
| 280 | |
| 281 | if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(MD)) { |
| 282 | |
| 283 | |
| 284 | assert(!RtlArgs); |
| 285 | assert(ReturnValue.isNull() && "Constructor shouldn't have return value"); |
| 286 | CallArgList Args; |
| 287 | commonEmitCXXMemberOrOperatorCall( |
| 288 | *this, Ctor, This.getPointer(*this), nullptr, |
| 289 | QualType(), CE, Args, nullptr); |
| 290 | |
| 291 | EmitCXXConstructorCall(Ctor, Ctor_Complete, false, |
| 292 | false, This.getAddress(*this), Args, |
| 293 | AggValueSlot::DoesNotOverlap, CE->getExprLoc(), |
| 294 | false); |
| 295 | return RValue::get(nullptr); |
| 296 | } |
| 297 | |
| 298 | if (TrivialForCodegen) { |
| 299 | if (isa<CXXDestructorDecl>(MD)) |
| 300 | return RValue::get(nullptr); |
| 301 | |
| 302 | if (TrivialAssignment) { |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | LValue RHS = isa<CXXOperatorCallExpr>(CE) |
| 309 | ? TrivialAssignmentRHS |
| 310 | : EmitLValue(*CE->arg_begin()); |
| 311 | EmitAggregateAssign(This, RHS, CE->getType()); |
| 312 | return RValue::get(This.getPointer(*this)); |
| 313 | } |
| 314 | |
| 315 | assert(MD->getParent()->mayInsertExtraPadding() && |
| 316 | "unknown trivial member function"); |
| 317 | } |
| 318 | |
| 319 | |
| 320 | const CXXMethodDecl *CalleeDecl = |
| 321 | DevirtualizedMethod ? DevirtualizedMethod : MD; |
| 322 | const CGFunctionInfo *FInfo = nullptr; |
| 323 | if (const auto *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl)) |
| 324 | FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration( |
| 325 | GlobalDecl(Dtor, Dtor_Complete)); |
| 326 | else |
| 327 | FInfo = &CGM.getTypes().arrangeCXXMethodDeclaration(CalleeDecl); |
| 328 | |
| 329 | llvm::FunctionType *Ty = CGM.getTypes().GetFunctionType(*FInfo); |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | SourceLocation CallLoc; |
| 335 | ASTContext &C = getContext(); |
| 336 | if (CE) |
| 337 | CallLoc = CE->getExprLoc(); |
| 338 | |
| 339 | SanitizerSet SkippedChecks; |
| 340 | if (const auto *CMCE = dyn_cast<CXXMemberCallExpr>(CE)) { |
| 341 | auto *IOA = CMCE->getImplicitObjectArgument(); |
| 342 | bool IsImplicitObjectCXXThis = IsWrappedCXXThis(IOA); |
| 343 | if (IsImplicitObjectCXXThis) |
| 344 | SkippedChecks.set(SanitizerKind::Alignment, true); |
| 345 | if (IsImplicitObjectCXXThis || isa<DeclRefExpr>(IOA)) |
| 346 | SkippedChecks.set(SanitizerKind::Null, true); |
| 347 | } |
| 348 | EmitTypeCheck(CodeGenFunction::TCK_MemberCall, CallLoc, |
| 349 | This.getPointer(*this), |
| 350 | C.getRecordType(CalleeDecl->getParent()), |
| 351 | CharUnits::Zero(), SkippedChecks); |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod; |
| 360 | |
| 361 | if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(CalleeDecl)) { |
| 362 | assert(CE->arg_begin() == CE->arg_end() && |
| 363 | "Destructor shouldn't have explicit parameters"); |
| 364 | assert(ReturnValue.isNull() && "Destructor shouldn't have return value"); |
| 365 | if (UseVirtualCall) { |
| 366 | CGM.getCXXABI().EmitVirtualDestructorCall(*this, Dtor, Dtor_Complete, |
| 367 | This.getAddress(*this), |
| 368 | cast<CXXMemberCallExpr>(CE)); |
| 369 | } else { |
| 370 | GlobalDecl GD(Dtor, Dtor_Complete); |
| 371 | CGCallee Callee; |
| 372 | if (getLangOpts().AppleKext && Dtor->isVirtual() && HasQualifier) |
| 373 | Callee = BuildAppleKextVirtualCall(Dtor, Qualifier, Ty); |
| 374 | else if (!DevirtualizedMethod) |
| 375 | Callee = |
| 376 | CGCallee::forDirect(CGM.getAddrOfCXXStructor(GD, FInfo, Ty), GD); |
| 377 | else { |
| 378 | Callee = CGCallee::forDirect(CGM.GetAddrOfFunction(GD, Ty), GD); |
| 379 | } |
| 380 | |
| 381 | QualType ThisTy = |
| 382 | IsArrow ? Base->getType()->getPointeeType() : Base->getType(); |
| 383 | EmitCXXDestructorCall(GD, Callee, This.getPointer(*this), ThisTy, |
| 384 | nullptr, |
| 385 | QualType(), CE); |
| 386 | } |
| 387 | return RValue::get(nullptr); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | CGCallee Callee; |
| 394 | if (UseVirtualCall) { |
| 395 | Callee = CGCallee::forVirtual(CE, MD, This.getAddress(*this), Ty); |
| 396 | } else { |
| 397 | if (SanOpts.has(SanitizerKind::CFINVCall) && |
| 398 | MD->getParent()->isDynamicClass()) { |
| 399 | llvm::Value *VTable; |
| 400 | const CXXRecordDecl *RD; |
| 401 | std::tie(VTable, RD) = CGM.getCXXABI().LoadVTablePtr( |
| 402 | *this, This.getAddress(*this), CalleeDecl->getParent()); |
| 403 | EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getBeginLoc()); |
| 404 | } |
| 405 | |
| 406 | if (getLangOpts().AppleKext && MD->isVirtual() && HasQualifier) |
| 407 | Callee = BuildAppleKextVirtualCall(MD, Qualifier, Ty); |
| 408 | else if (!DevirtualizedMethod) |
| 409 | Callee = |
| 410 | CGCallee::forDirect(CGM.GetAddrOfFunction(MD, Ty), GlobalDecl(MD)); |
| 411 | else { |
| 412 | Callee = |
| 413 | CGCallee::forDirect(CGM.GetAddrOfFunction(DevirtualizedMethod, Ty), |
| 414 | GlobalDecl(DevirtualizedMethod)); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | if (MD->isVirtual()) { |
| 419 | Address NewThisAddr = |
| 420 | CGM.getCXXABI().adjustThisArgumentForVirtualFunctionCall( |
| 421 | *this, CalleeDecl, This.getAddress(*this), UseVirtualCall); |
| 422 | This.setAddress(NewThisAddr); |
| 423 | } |
| 424 | |
| 425 | return EmitCXXMemberOrOperatorCall( |
| 426 | CalleeDecl, Callee, ReturnValue, This.getPointer(*this), |
| 427 | nullptr, QualType(), CE, RtlArgs); |
| 428 | } |
| 429 | |
| 430 | RValue |
| 431 | CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, |
| 432 | ReturnValueSlot ReturnValue) { |
| 433 | const BinaryOperator *BO = |
| 434 | cast<BinaryOperator>(E->getCallee()->IgnoreParens()); |
| 435 | const Expr *BaseExpr = BO->getLHS(); |
| 436 | const Expr *MemFnExpr = BO->getRHS(); |
| 437 | |
| 438 | const auto *MPT = MemFnExpr->getType()->castAs<MemberPointerType>(); |
| 439 | const auto *FPT = MPT->getPointeeType()->castAs<FunctionProtoType>(); |
| 440 | const auto *RD = |
| 441 | cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl()); |
| 442 | |
| 443 | |
| 444 | Address This = Address::invalid(); |
| 445 | if (BO->getOpcode() == BO_PtrMemI) |
| 446 | This = EmitPointerWithAlignment(BaseExpr); |
| 447 | else |
| 448 | This = EmitLValue(BaseExpr).getAddress(*this); |
| 449 | |
| 450 | EmitTypeCheck(TCK_MemberCall, E->getExprLoc(), This.getPointer(), |
| 451 | QualType(MPT->getClass(), 0)); |
| 452 | |
| 453 | |
| 454 | llvm::Value *MemFnPtr = EmitScalarExpr(MemFnExpr); |
| 455 | |
| 456 | |
| 457 | llvm::Value *ThisPtrForCall = nullptr; |
| 458 | CGCallee Callee = |
| 459 | CGM.getCXXABI().EmitLoadOfMemberFunctionPointer(*this, BO, This, |
| 460 | ThisPtrForCall, MemFnPtr, MPT); |
| 461 | |
| 462 | CallArgList Args; |
| 463 | |
| 464 | QualType ThisType = |
| 465 | getContext().getPointerType(getContext().getTagDeclType(RD)); |
| 466 | |
| 467 | |
| 468 | Args.add(RValue::get(ThisPtrForCall), ThisType); |
| 469 | |
| 470 | RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, 1); |
| 471 | |
| 472 | |
| 473 | EmitCallArgs(Args, FPT, E->arguments()); |
| 474 | return EmitCall(CGM.getTypes().arrangeCXXMethodCall(Args, FPT, required, |
| 475 | 0), |
| 476 | Callee, ReturnValue, Args, nullptr, E == MustTailCall, |
| 477 | E->getExprLoc()); |
| 478 | } |
| 479 | |
| 480 | RValue |
| 481 | CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, |
| 482 | const CXXMethodDecl *MD, |
| 483 | ReturnValueSlot ReturnValue) { |
| 484 | assert(MD->isInstance() && |
| 485 | "Trying to emit a member call expr on a static method!"); |
| 486 | return EmitCXXMemberOrOperatorMemberCallExpr( |
| 487 | E, MD, ReturnValue, false, nullptr, |
| 488 | false, E->getArg(0)); |
| 489 | } |
| 490 | |
| 491 | RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, |
| 492 | ReturnValueSlot ReturnValue) { |
| 493 | return CGM.getCUDARuntime().EmitCUDAKernelCallExpr(*this, E, ReturnValue); |
| 494 | } |
| 495 | |
| 496 | static void EmitNullBaseClassInitialization(CodeGenFunction &CGF, |
| 497 | Address DestPtr, |
| 498 | const CXXRecordDecl *Base) { |
| 499 | if (Base->isEmpty()) |
| 500 | return; |
| 501 | |
| 502 | DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty); |
| 503 | |
| 504 | const ASTRecordLayout &Layout = CGF.getContext().getASTRecordLayout(Base); |
| 505 | CharUnits NVSize = Layout.getNonVirtualSize(); |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | SmallVector<std::pair<CharUnits, CharUnits>, 1> Stores; |
| 511 | Stores.emplace_back(CharUnits::Zero(), NVSize); |
| 512 | |
| 513 | |
| 514 | CharUnits VBPtrWidth = CGF.getPointerSize(); |
| 515 | std::vector<CharUnits> VBPtrOffsets = |
| 516 | CGF.CGM.getCXXABI().getVBPtrOffsets(Base); |
| 517 | for (CharUnits VBPtrOffset : VBPtrOffsets) { |
| 518 | |
| 519 | if (VBPtrOffset >= NVSize) |
| 520 | break; |
| 521 | std::pair<CharUnits, CharUnits> LastStore = Stores.pop_back_val(); |
| 522 | CharUnits LastStoreOffset = LastStore.first; |
| 523 | CharUnits LastStoreSize = LastStore.second; |
| 524 | |
| 525 | CharUnits SplitBeforeOffset = LastStoreOffset; |
| 526 | CharUnits SplitBeforeSize = VBPtrOffset - SplitBeforeOffset; |
| 527 | assert(!SplitBeforeSize.isNegative() && "negative store size!"); |
| 528 | if (!SplitBeforeSize.isZero()) |
| 529 | Stores.emplace_back(SplitBeforeOffset, SplitBeforeSize); |
| 530 | |
| 531 | CharUnits SplitAfterOffset = VBPtrOffset + VBPtrWidth; |
| 532 | CharUnits SplitAfterSize = LastStoreSize - SplitAfterOffset; |
| 533 | assert(!SplitAfterSize.isNegative() && "negative store size!"); |
| 534 | if (!SplitAfterSize.isZero()) |
| 535 | Stores.emplace_back(SplitAfterOffset, SplitAfterSize); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | llvm::Constant *NullConstantForBase = CGF.CGM.EmitNullConstantForBase(Base); |
| 545 | if (!NullConstantForBase->isNullValue()) { |
| 546 | llvm::GlobalVariable *NullVariable = new llvm::GlobalVariable( |
| 547 | CGF.CGM.getModule(), NullConstantForBase->getType(), |
| 548 | true, llvm::GlobalVariable::PrivateLinkage, |
| 549 | NullConstantForBase, Twine()); |
| 550 | |
| 551 | CharUnits Align = std::max(Layout.getNonVirtualAlignment(), |
| 552 | DestPtr.getAlignment()); |
| 553 | NullVariable->setAlignment(Align.getAsAlign()); |
| 554 | |
| 555 | Address SrcPtr = Address(CGF.EmitCastToVoidPtr(NullVariable), Align); |
| 556 | |
| 557 | |
| 558 | for (std::pair<CharUnits, CharUnits> Store : Stores) { |
| 559 | CharUnits StoreOffset = Store.first; |
| 560 | CharUnits StoreSize = Store.second; |
| 561 | llvm::Value *StoreSizeVal = CGF.CGM.getSize(StoreSize); |
| 562 | CGF.Builder.CreateMemCpy( |
| 563 | CGF.Builder.CreateConstInBoundsByteGEP(DestPtr, StoreOffset), |
| 564 | CGF.Builder.CreateConstInBoundsByteGEP(SrcPtr, StoreOffset), |
| 565 | StoreSizeVal); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | } else { |
| 572 | for (std::pair<CharUnits, CharUnits> Store : Stores) { |
| 573 | CharUnits StoreOffset = Store.first; |
| 574 | CharUnits StoreSize = Store.second; |
| 575 | llvm::Value *StoreSizeVal = CGF.CGM.getSize(StoreSize); |
| 576 | CGF.Builder.CreateMemSet( |
| 577 | CGF.Builder.CreateConstInBoundsByteGEP(DestPtr, StoreOffset), |
| 578 | CGF.Builder.getInt8(0), StoreSizeVal); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | void |
| 584 | CodeGenFunction::EmitCXXConstructExpr(const CXXConstructExpr *E, |
| 585 | AggValueSlot Dest) { |
| 586 | assert(!Dest.isIgnored() && "Must have a destination!"); |
| 587 | const CXXConstructorDecl *CD = E->getConstructor(); |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | if (E->requiresZeroInitialization() && !Dest.isZeroed()) { |
| 594 | switch (E->getConstructionKind()) { |
| 595 | case CXXConstructExpr::CK_Delegating: |
| 596 | case CXXConstructExpr::CK_Complete: |
| 597 | EmitNullInitialization(Dest.getAddress(), E->getType()); |
| 598 | break; |
| 599 | case CXXConstructExpr::CK_VirtualBase: |
| 600 | case CXXConstructExpr::CK_NonVirtualBase: |
| 601 | EmitNullBaseClassInitialization(*this, Dest.getAddress(), |
| 602 | CD->getParent()); |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | |
| 608 | if (CD->isTrivial() && CD->isDefaultConstructor()) |
| 609 | return; |
| 610 | |
| 611 | |
| 612 | if (getLangOpts().ElideConstructors && E->isElidable()) { |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | const Expr *SrcObj = E->getArg(0); |
| 619 | assert(SrcObj->isTemporaryObject(getContext(), CD->getParent())); |
| 620 | assert( |
| 621 | getContext().hasSameUnqualifiedType(E->getType(), SrcObj->getType())); |
| 622 | EmitAggExpr(SrcObj, Dest); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | if (const ArrayType *arrayType |
| 627 | = getContext().getAsArrayType(E->getType())) { |
| 628 | EmitCXXAggrConstructorCall(CD, arrayType, Dest.getAddress(), E, |
| 629 | Dest.isSanitizerChecked()); |
| 630 | } else { |
| 631 | CXXCtorType Type = Ctor_Complete; |
| 632 | bool ForVirtualBase = false; |
| 633 | bool Delegating = false; |
| 634 | |
| 635 | switch (E->getConstructionKind()) { |
| 636 | case CXXConstructExpr::CK_Delegating: |
| 637 | |
| 638 | Type = CurGD.getCtorType(); |
| 639 | Delegating = true; |
| 640 | break; |
| 641 | |
| 642 | case CXXConstructExpr::CK_Complete: |
| 643 | Type = Ctor_Complete; |
| 644 | break; |
| 645 | |
| 646 | case CXXConstructExpr::CK_VirtualBase: |
| 647 | ForVirtualBase = true; |
| 648 | LLVM_FALLTHROUGH; |
| 649 | |
| 650 | case CXXConstructExpr::CK_NonVirtualBase: |
| 651 | Type = Ctor_Base; |
| 652 | } |
| 653 | |
| 654 | |
| 655 | EmitCXXConstructorCall(CD, Type, ForVirtualBase, Delegating, Dest, E); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | void CodeGenFunction::EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, |
| 660 | const Expr *Exp) { |
| 661 | if (const ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(Exp)) |
| 662 | Exp = E->getSubExpr(); |
| 663 | assert(isa<CXXConstructExpr>(Exp) && |
| 664 | "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr"); |
| 665 | const CXXConstructExpr* E = cast<CXXConstructExpr>(Exp); |
| 666 | const CXXConstructorDecl *CD = E->getConstructor(); |
| 667 | RunCleanupsScope Scope(*this); |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | if (E->requiresZeroInitialization()) |
| 674 | EmitNullInitialization(Dest, E->getType()); |
| 675 | |
| 676 | assert(!getContext().getAsConstantArrayType(E->getType()) |
| 677 | && "EmitSynthesizedCXXCopyCtor - Copied-in Array"); |
| 678 | EmitSynthesizedCXXCopyCtorCall(CD, Dest, Src, E); |
| 679 | } |
| 680 | |
| 681 | static CharUnits CalculateCookiePadding(CodeGenFunction &CGF, |
| 682 | const CXXNewExpr *E) { |
| 683 | if (!E->isArray()) |
| 684 | return CharUnits::Zero(); |
| 685 | |
| 686 | |
| 687 | |
| 688 | if (E->getOperatorNew()->isReservedGlobalPlacementOperator()) |
| 689 | return CharUnits::Zero(); |
| 690 | |
| 691 | return CGF.CGM.getCXXABI().GetArrayCookieSize(E); |
| 692 | } |
| 693 | |
| 694 | static llvm::Value *EmitCXXNewAllocSize(CodeGenFunction &CGF, |
| 695 | const CXXNewExpr *e, |
| 696 | unsigned minElements, |
| 697 | llvm::Value *&numElements, |
| 698 | llvm::Value *&sizeWithoutCookie) { |
| 699 | QualType type = e->getAllocatedType(); |
| 700 | |
| 701 | if (!e->isArray()) { |
| |
| 702 | CharUnits typeSize = CGF.getContext().getTypeSizeInChars(type); |
| 703 | sizeWithoutCookie |
| 704 | = llvm::ConstantInt::get(CGF.SizeTy, typeSize.getQuantity()); |
| 705 | return sizeWithoutCookie; |
| 5 | | Returning without writing to 'numElements' | |
|
| 706 | } |
| 707 | |
| 708 | |
| 709 | unsigned sizeWidth = CGF.SizeTy->getBitWidth(); |
| 710 | |
| 711 | |
| 712 | llvm::APInt cookieSize(sizeWidth, |
| 713 | CalculateCookiePadding(CGF, e).getQuantity()); |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | numElements = |
| 719 | ConstantEmitter(CGF).tryEmitAbstract(*e->getArraySize(), e->getType()); |
| 720 | if (!numElements) |
| 721 | numElements = CGF.EmitScalarExpr(*e->getArraySize()); |
| 722 | assert(isa<llvm::IntegerType>(numElements->getType())); |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | bool isSigned |
| 731 | = (*e->getArraySize())->getType()->isSignedIntegerOrEnumerationType(); |
| 732 | llvm::IntegerType *numElementsType |
| 733 | = cast<llvm::IntegerType>(numElements->getType()); |
| 734 | unsigned numElementsWidth = numElementsType->getBitWidth(); |
| 735 | |
| 736 | |
| 737 | llvm::APInt arraySizeMultiplier(sizeWidth, 1); |
| 738 | while (const ConstantArrayType *CAT |
| 739 | = CGF.getContext().getAsConstantArrayType(type)) { |
| 740 | type = CAT->getElementType(); |
| 741 | arraySizeMultiplier *= CAT->getSize(); |
| 742 | } |
| 743 | |
| 744 | CharUnits typeSize = CGF.getContext().getTypeSizeInChars(type); |
| 745 | llvm::APInt typeSizeMultiplier(sizeWidth, typeSize.getQuantity()); |
| 746 | typeSizeMultiplier *= arraySizeMultiplier; |
| 747 | |
| 748 | |
| 749 | llvm::Value *size; |
| 750 | |
| 751 | |
| 752 | |
| 753 | if (llvm::ConstantInt *numElementsC = |
| 754 | dyn_cast<llvm::ConstantInt>(numElements)) { |
| 755 | const llvm::APInt &count = numElementsC->getValue(); |
| 756 | |
| 757 | bool hasAnyOverflow = false; |
| 758 | |
| 759 | |
| 760 | if (isSigned && count.isNegative()) |
| 761 | hasAnyOverflow = true; |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | else if (numElementsWidth > sizeWidth && |
| 767 | numElementsWidth - sizeWidth > count.countLeadingZeros()) |
| 768 | hasAnyOverflow = true; |
| 769 | |
| 770 | |
| 771 | llvm::APInt adjustedCount = count.zextOrTrunc(sizeWidth); |
| 772 | |
| 773 | |
| 774 | |
| 775 | if (adjustedCount.ult(minElements)) |
| 776 | hasAnyOverflow = true; |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | numElements = llvm::ConstantInt::get(CGF.SizeTy, |
| 782 | adjustedCount * arraySizeMultiplier); |
| 783 | |
| 784 | |
| 785 | bool overflow; |
| 786 | llvm::APInt allocationSize |
| 787 | = adjustedCount.umul_ov(typeSizeMultiplier, overflow); |
| 788 | hasAnyOverflow |= overflow; |
| 789 | |
| 790 | |
| 791 | if (cookieSize != 0) { |
| 792 | |
| 793 | |
| 794 | sizeWithoutCookie = llvm::ConstantInt::get(CGF.SizeTy, allocationSize); |
| 795 | |
| 796 | allocationSize = allocationSize.uadd_ov(cookieSize, overflow); |
| 797 | hasAnyOverflow |= overflow; |
| 798 | } |
| 799 | |
| 800 | |
| 801 | if (hasAnyOverflow) { |
| 802 | size = llvm::Constant::getAllOnesValue(CGF.SizeTy); |
| 803 | } else { |
| 804 | size = llvm::ConstantInt::get(CGF.SizeTy, allocationSize); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | } else { |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | llvm::Value *hasOverflow = nullptr; |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | if (numElementsWidth > sizeWidth) { |
| 828 | llvm::APInt threshold(numElementsWidth, 1); |
| 829 | threshold <<= sizeWidth; |
| 830 | |
| 831 | llvm::Value *thresholdV |
| 832 | = llvm::ConstantInt::get(numElementsType, threshold); |
| 833 | |
| 834 | hasOverflow = CGF.Builder.CreateICmpUGE(numElements, thresholdV); |
| 835 | numElements = CGF.Builder.CreateTrunc(numElements, CGF.SizeTy); |
| 836 | |
| 837 | |
| 838 | } else if (isSigned) { |
| 839 | if (numElementsWidth < sizeWidth) |
| 840 | numElements = CGF.Builder.CreateSExt(numElements, CGF.SizeTy); |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | if (typeSizeMultiplier == 1) |
| 848 | hasOverflow = CGF.Builder.CreateICmpSLT(numElements, |
| 849 | llvm::ConstantInt::get(CGF.SizeTy, minElements)); |
| 850 | |
| 851 | |
| 852 | } else if (numElementsWidth < sizeWidth) { |
| 853 | numElements = CGF.Builder.CreateZExt(numElements, CGF.SizeTy); |
| 854 | } |
| 855 | |
| 856 | assert(numElements->getType() == CGF.SizeTy); |
| 857 | |
| 858 | if (minElements) { |
| 859 | |
| 860 | if (!hasOverflow) { |
| 861 | hasOverflow = CGF.Builder.CreateICmpULT(numElements, |
| 862 | llvm::ConstantInt::get(CGF.SizeTy, minElements)); |
| 863 | } else if (numElementsWidth > sizeWidth) { |
| 864 | |
| 865 | |
| 866 | |
| 867 | hasOverflow = CGF.Builder.CreateOr(hasOverflow, |
| 868 | CGF.Builder.CreateICmpULT(numElements, |
| 869 | llvm::ConstantInt::get(CGF.SizeTy, minElements))); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | size = numElements; |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | if (typeSizeMultiplier != 1) { |
| 883 | llvm::Function *umul_with_overflow |
| 884 | = CGF.CGM.getIntrinsic(llvm::Intrinsic::umul_with_overflow, CGF.SizeTy); |
| 885 | |
| 886 | llvm::Value *tsmV = |
| 887 | llvm::ConstantInt::get(CGF.SizeTy, typeSizeMultiplier); |
| 888 | llvm::Value *result = |
| 889 | CGF.Builder.CreateCall(umul_with_overflow, {size, tsmV}); |
| 890 | |
| 891 | llvm::Value *overflowed = CGF.Builder.CreateExtractValue(result, 1); |
| 892 | if (hasOverflow) |
| 893 | hasOverflow = CGF.Builder.CreateOr(hasOverflow, overflowed); |
| 894 | else |
| 895 | hasOverflow = overflowed; |
| 896 | |
| 897 | size = CGF.Builder.CreateExtractValue(result, 0); |
| 898 | |
| 899 | |
| 900 | if (arraySizeMultiplier != 1) { |
| 901 | |
| 902 | |
| 903 | if (typeSize.isOne()) { |
| 904 | assert(arraySizeMultiplier == typeSizeMultiplier); |
| 905 | numElements = size; |
| 906 | |
| 907 | |
| 908 | } else { |
| 909 | llvm::Value *asmV = |
| 910 | llvm::ConstantInt::get(CGF.SizeTy, arraySizeMultiplier); |
| 911 | numElements = CGF.Builder.CreateMul(numElements, asmV); |
| 912 | } |
| 913 | } |
| 914 | } else { |
| 915 | |
| 916 | assert(arraySizeMultiplier == 1); |
| 917 | } |
| 918 | |
| 919 | |
| 920 | if (cookieSize != 0) { |
| 921 | sizeWithoutCookie = size; |
| 922 | |
| 923 | llvm::Function *uadd_with_overflow |
| 924 | = CGF.CGM.getIntrinsic(llvm::Intrinsic::uadd_with_overflow, CGF.SizeTy); |
| 925 | |
| 926 | llvm::Value *cookieSizeV = llvm::ConstantInt::get(CGF.SizeTy, cookieSize); |
| 927 | llvm::Value *result = |
| 928 | CGF.Builder.CreateCall(uadd_with_overflow, {size, cookieSizeV}); |
| 929 | |
| 930 | llvm::Value *overflowed = CGF.Builder.CreateExtractValue(result, 1); |
| 931 | if (hasOverflow) |
| 932 | hasOverflow = CGF.Builder.CreateOr(hasOverflow, overflowed); |
| 933 | else |
| 934 | hasOverflow = overflowed; |
| 935 | |
| 936 | size = CGF.Builder.CreateExtractValue(result, 0); |
| 937 | } |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 942 | if (hasOverflow) |
| 943 | size = CGF.Builder.CreateSelect(hasOverflow, |
| 944 | llvm::Constant::getAllOnesValue(CGF.SizeTy), |
| 945 | size); |
| 946 | } |
| 947 | |
| 948 | if (cookieSize == 0) |
| 949 | sizeWithoutCookie = size; |
| 950 | else |
| 951 | assert(sizeWithoutCookie && "didn't set sizeWithoutCookie?"); |
| 952 | |
| 953 | return size; |
| 954 | } |
| 955 | |
| 956 | static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init, |
| 957 | QualType AllocType, Address NewPtr, |
| 958 | AggValueSlot::Overlap_t MayOverlap) { |
| 959 | |
| 960 | switch (CGF.getEvaluationKind(AllocType)) { |
| 961 | case TEK_Scalar: |
| 962 | CGF.EmitScalarInit(Init, nullptr, |
| 963 | CGF.MakeAddrLValue(NewPtr, AllocType), false); |
| 964 | return; |
| 965 | case TEK_Complex: |
| 966 | CGF.EmitComplexExprIntoLValue(Init, CGF.MakeAddrLValue(NewPtr, AllocType), |
| 967 | true); |
| 968 | return; |
| 969 | case TEK_Aggregate: { |
| 970 | AggValueSlot Slot |
| 971 | = AggValueSlot::forAddr(NewPtr, AllocType.getQualifiers(), |
| 972 | AggValueSlot::IsDestructed, |
| 973 | AggValueSlot::DoesNotNeedGCBarriers, |
| 974 | AggValueSlot::IsNotAliased, |
| 975 | MayOverlap, AggValueSlot::IsNotZeroed, |
| 976 | AggValueSlot::IsSanitizerChecked); |
| 977 | CGF.EmitAggExpr(Init, Slot); |
| 978 | return; |
| 979 | } |
| 980 | } |
| 981 | llvm_unreachable("bad evaluation kind"); |
| 982 | } |
| 983 | |
| 984 | void CodeGenFunction::EmitNewArrayInitializer( |
| 985 | const CXXNewExpr *E, QualType ElementType, llvm::Type *ElementTy, |
| 986 | Address BeginPtr, llvm::Value *NumElements, |
| 987 | llvm::Value *AllocSizeWithoutCookie) { |
| 988 | |
| 989 | |
| 990 | if (!E->hasInitializer()) |
| 27 | | Calling 'CXXNewExpr::hasInitializer' | |
|
| 30 | | Returning from 'CXXNewExpr::hasInitializer' | |
|
| |
| 991 | return; |
| 992 | |
| 993 | Address CurPtr = BeginPtr; |
| 994 | |
| 995 | unsigned InitListElements = 0; |
| 996 | |
| 997 | const Expr *Init = E->getInitializer(); |
| 998 | Address EndOfInit = Address::invalid(); |
| 999 | QualType::DestructionKind DtorKind = ElementType.isDestructedType(); |
| 1000 | EHScopeStack::stable_iterator Cleanup; |
| 1001 | llvm::Instruction *CleanupDominator = nullptr; |
| 1002 | |
| 1003 | CharUnits ElementSize = getContext().getTypeSizeInChars(ElementType); |
| 1004 | CharUnits ElementAlign = |
| 1005 | BeginPtr.getAlignment().alignmentOfArrayElement(ElementSize); |
| 1006 | |
| 1007 | |
| 1008 | auto TryMemsetInitialization = [&]() -> bool { |
| 1009 | |
| 1010 | |
| 1011 | if (!CGM.getTypes().isZeroInitializable(ElementType)) |
| 1012 | return false; |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | auto *RemainingSize = AllocSizeWithoutCookie; |
| 1019 | if (InitListElements) { |
| 1020 | |
| 1021 | auto *InitializedSize = llvm::ConstantInt::get( |
| 1022 | RemainingSize->getType(), |
| 1023 | getContext().getTypeSizeInChars(ElementType).getQuantity() * |
| 1024 | InitListElements); |
| 1025 | RemainingSize = Builder.CreateSub(RemainingSize, InitializedSize); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | Builder.CreateMemSet(CurPtr, Builder.getInt8(0), RemainingSize, false); |
| 1030 | return true; |
| 1031 | }; |
| 1032 | |
| 1033 | |
| 1034 | if (const InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) { |
| 32 | | Assuming 'Init' is a 'InitListExpr' | |
|
| |
| 1035 | |
| 1036 | |
| 1037 | if (ILE->isStringLiteralInit()) { |
| 34 | | Assuming the condition is false | |
|
| |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | AggValueSlot Slot = |
| 1042 | AggValueSlot::forAddr(CurPtr, ElementType.getQualifiers(), |
| 1043 | AggValueSlot::IsDestructed, |
| 1044 | AggValueSlot::DoesNotNeedGCBarriers, |
| 1045 | AggValueSlot::IsNotAliased, |
| 1046 | AggValueSlot::DoesNotOverlap, |
| 1047 | AggValueSlot::IsNotZeroed, |
| 1048 | AggValueSlot::IsSanitizerChecked); |
| 1049 | EmitAggExpr(ILE->getInit(0), Slot); |
| 1050 | |
| 1051 | |
| 1052 | InitListElements = |
| 1053 | cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe()) |
| 1054 | ->getSize().getZExtValue(); |
| 1055 | CurPtr = |
| 1056 | Address(Builder.CreateInBoundsGEP(CurPtr.getElementType(), |
| 1057 | CurPtr.getPointer(), |
| 1058 | Builder.getSize(InitListElements), |
| 1059 | "string.init.end"), |
| 1060 | CurPtr.getAlignment().alignmentAtOffset(InitListElements * |
| 1061 | ElementSize)); |
| 1062 | |
| 1063 | |
| 1064 | llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements); |
| 1065 | if (!ConstNum || !ConstNum->equalsInt(InitListElements)) { |
| 1066 | bool OK = TryMemsetInitialization(); |
| 1067 | (void)OK; |
| 1068 | assert(OK && "couldn't memset character type?"); |
| 1069 | } |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | InitListElements = ILE->getNumInits(); |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | QualType AllocType = E->getAllocatedType(); |
| 1078 | if (const ConstantArrayType *CAT = dyn_cast_or_null<ConstantArrayType>( |
| 36 | | Assuming null pointer is passed into cast | |
|
| |
| 1079 | AllocType->getAsArrayTypeUnsafe())) { |
| 1080 | ElementTy = ConvertTypeForMem(AllocType); |
| 1081 | CurPtr = Builder.CreateElementBitCast(CurPtr, ElementTy); |
| 1082 | InitListElements *= getContext().getConstantArrayElementCount(CAT); |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | if (needsEHCleanup(DtorKind)) { |
| |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | EndOfInit = CreateTempAlloca(BeginPtr.getType(), getPointerAlign(), |
| 1092 | "array.init.end"); |
| 1093 | CleanupDominator = Builder.CreateStore(BeginPtr.getPointer(), EndOfInit); |
| 1094 | pushIrregularPartialArrayCleanup(BeginPtr.getPointer(), EndOfInit, |
| 1095 | ElementType, ElementAlign, |
| 1096 | getDestroyer(DtorKind)); |
| 1097 | Cleanup = EHStack.stable_begin(); |
| 1098 | } |
| 1099 | |
| 1100 | CharUnits StartAlign = CurPtr.getAlignment(); |
| 1101 | for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) { |
| 39 | | Assuming 'i' is equal to 'e' | |
|
| 40 | | Loop condition is false. Execution continues on line 1124 | |
|
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | if (EndOfInit.isValid()) { |
| 1106 | auto FinishedPtr = |
| 1107 | Builder.CreateBitCast(CurPtr.getPointer(), BeginPtr.getType()); |
| 1108 | Builder.CreateStore(FinishedPtr, EndOfInit); |
| 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | StoreAnyExprIntoOneUnit(*this, ILE->getInit(i), |
| 1114 | ILE->getInit(i)->getType(), CurPtr, |
| 1115 | AggValueSlot::DoesNotOverlap); |
| 1116 | CurPtr = Address(Builder.CreateInBoundsGEP(CurPtr.getElementType(), |
| 1117 | CurPtr.getPointer(), |
| 1118 | Builder.getSize(1), |
| 1119 | "array.exp.next"), |
| 1120 | StartAlign.alignmentAtOffset((i + 1) * ElementSize)); |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | Init = ILE->getArrayFiller(); |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | while (Init && Init->getType()->isConstantArrayType()) { |
| 41 | | Assuming 'Init' is null | |
|
| 42 | | Loop condition is false. Execution continues on line 1138 | |
|
| 1130 | auto *SubILE = dyn_cast<InitListExpr>(Init); |
| 1131 | if (!SubILE) |
| 1132 | break; |
| 1133 | assert(SubILE->getNumInits() == 0 && "explicit inits in array filler?"); |
| 1134 | Init = SubILE->getArrayFiller(); |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | CurPtr = Builder.CreateBitCast(CurPtr, BeginPtr.getType()); |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | llvm::ConstantInt *ConstNum = dyn_cast<llvm::ConstantInt>(NumElements); |
| 1144 | if (ConstNum && ConstNum->getZExtValue() <= InitListElements) { |
| 43 | | Assuming 'ConstNum' is null | |
|
| 1145 | |
| 1146 | if (CleanupDominator) |
| 1147 | DeactivateCleanupBlock(Cleanup, CleanupDominator); |
| 1148 | return; |
| 1149 | } |
| 1150 | |
| 1151 | assert(Init && "have trailing elements to initialize but no initializer"); |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) { |
| 44 | | Assuming 'CCE' is non-null | |
|
| |
| 1156 | CXXConstructorDecl *Ctor = CCE->getConstructor(); |
| 1157 | if (Ctor->isTrivial()) { |
| 46 | | Assuming the condition is false | |
|
| |
| 1158 | |
| 1159 | |
| 1160 | if (!CCE->requiresZeroInitialization() || Ctor->getParent()->isEmpty()) |
| 1161 | return; |
| 1162 | |
| 1163 | if (TryMemsetInitialization()) |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | if (EndOfInit.isValid()) |
| |
| 1172 | Builder.CreateStore(CurPtr.getPointer(), EndOfInit); |
| 1173 | |
| 1174 | |
| 1175 | if (InitListElements) |
| 49 | | Assuming 'InitListElements' is not equal to 0 | |
|
| |
| 1176 | NumElements = Builder.CreateSub( |
| 1177 | NumElements, |
| 1178 | llvm::ConstantInt::get(NumElements->getType(), InitListElements)); |
| 51 | | Called C++ object pointer is null |
|
| 1179 | EmitCXXAggrConstructorCall(Ctor, NumElements, CurPtr, CCE, |
| 1180 | true, |
| 1181 | CCE->requiresZeroInitialization()); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | ImplicitValueInitExpr IVIE(ElementType); |
| 1187 | if (isa<ImplicitValueInitExpr>(Init)) { |
| 1188 | if (TryMemsetInitialization()) |
| 1189 | return; |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | Init = &IVIE; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | assert(getContext().hasSameUnqualifiedType(ElementType, Init->getType()) && |
| 1200 | "got wrong type of element to initialize"); |
| 1201 | |
| 1202 | |
| 1203 | if (auto *ILE = dyn_cast<InitListExpr>(Init)) |
| 1204 | if (ILE->getNumInits() == 0 && TryMemsetInitialization()) |
| 1205 | return; |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | if (auto *ILE = dyn_cast<InitListExpr>(Init)) { |
| 1210 | if (const RecordType *RType = ILE->getType()->getAs<RecordType>()) { |
| 1211 | if (RType->getDecl()->isStruct()) { |
| 1212 | unsigned NumElements = 0; |
| 1213 | if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RType->getDecl())) |
| 1214 | NumElements = CXXRD->getNumBases(); |
| 1215 | for (auto *Field : RType->getDecl()->fields()) |
| 1216 | if (!Field->isUnnamedBitfield()) |
| 1217 | ++NumElements; |
| 1218 | |
| 1219 | if (ILE->getNumInits() == NumElements) |
| 1220 | for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) |
| 1221 | if (!isa<ImplicitValueInitExpr>(ILE->getInit(i))) |
| 1222 | --NumElements; |
| 1223 | if (ILE->getNumInits() == NumElements && TryMemsetInitialization()) |
| 1224 | return; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | llvm::BasicBlock *EntryBB = Builder.GetInsertBlock(); |
| 1231 | llvm::BasicBlock *LoopBB = createBasicBlock("new.loop"); |
| 1232 | llvm::BasicBlock *ContBB = createBasicBlock("new.loop.end"); |
| 1233 | |
| 1234 | |
| 1235 | llvm::Value *EndPtr = |
| 1236 | Builder.CreateInBoundsGEP(BeginPtr.getElementType(), BeginPtr.getPointer(), |
| 1237 | NumElements, "array.end"); |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | if (!ConstNum) { |
| 1242 | llvm::Value *IsEmpty = |
| 1243 | Builder.CreateICmpEQ(CurPtr.getPointer(), EndPtr, "array.isempty"); |
| 1244 | Builder.CreateCondBr(IsEmpty, ContBB, LoopBB); |
| 1245 | } |
| 1246 | |
| 1247 | |
| 1248 | EmitBlock(LoopBB); |
| 1249 | |
| 1250 | |
| 1251 | llvm::PHINode *CurPtrPhi = |
| 1252 | Builder.CreatePHI(CurPtr.getType(), 2, "array.cur"); |
| 1253 | CurPtrPhi->addIncoming(CurPtr.getPointer(), EntryBB); |
| 1254 | |
| 1255 | CurPtr = Address(CurPtrPhi, ElementAlign); |
| 1256 | |
| 1257 | |
| 1258 | if (EndOfInit.isValid()) |
| 1259 | Builder.CreateStore(CurPtr.getPointer(), EndOfInit); |
| 1260 | |
| 1261 | |
| 1262 | if (!CleanupDominator && needsEHCleanup(DtorKind)) { |
| 1263 | pushRegularPartialArrayCleanup(BeginPtr.getPointer(), CurPtr.getPointer(), |
| 1264 | ElementType, ElementAlign, |
| 1265 | getDestroyer(DtorKind)); |
| 1266 | Cleanup = EHStack.stable_begin(); |
| 1267 | CleanupDominator = Builder.CreateUnreachable(); |
| 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | StoreAnyExprIntoOneUnit(*this, Init, Init->getType(), CurPtr, |
| 1272 | AggValueSlot::DoesNotOverlap); |
| 1273 | |
| 1274 | |
| 1275 | if (CleanupDominator) { |
| 1276 | DeactivateCleanupBlock(Cleanup, CleanupDominator); |
| 1277 | CleanupDominator->eraseFromParent(); |
| 1278 | } |
| 1279 | |
| 1280 | |
| 1281 | llvm::Value *NextPtr = |
| 1282 | Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr.getPointer(), 1, |
| 1283 | "array.next"); |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | llvm::Value *IsEnd = Builder.CreateICmpEQ(NextPtr, EndPtr, "array.atend"); |
| 1288 | Builder.CreateCondBr(IsEnd, ContBB, LoopBB); |
| 1289 | CurPtrPhi->addIncoming(NextPtr, Builder.GetInsertBlock()); |
| 1290 | |
| 1291 | EmitBlock(ContBB); |
| 1292 | } |
| 1293 | |
| 1294 | static void EmitNewInitializer(CodeGenFunction &CGF, const CXXNewExpr *E, |
| 1295 | QualType ElementType, llvm::Type *ElementTy, |
| 1296 | Address NewPtr, llvm::Value *NumElements, |
| 1297 | llvm::Value *AllocSizeWithoutCookie) { |
| 1298 | ApplyDebugLocation DL(CGF, E); |
| 1299 | if (E->isArray()) |
| 23 | | Assuming the condition is true | |
|
| |
| 1300 | CGF.EmitNewArrayInitializer(E, ElementType, ElementTy, NewPtr, NumElements, |
| 25 | | Passing null pointer value via 5th parameter 'NumElements' | |
|
| 26 | | Calling 'CodeGenFunction::EmitNewArrayInitializer' | |
|
| 1301 | AllocSizeWithoutCookie); |
| 1302 | else if (const Expr *Init = E->getInitializer()) |
| 1303 | StoreAnyExprIntoOneUnit(CGF, Init, E->getAllocatedType(), NewPtr, |
| 1304 | AggValueSlot::DoesNotOverlap); |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | static RValue EmitNewDeleteCall(CodeGenFunction &CGF, |
| 1310 | const FunctionDecl *CalleeDecl, |
| 1311 | const FunctionProtoType *CalleeType, |
| 1312 | const CallArgList &Args) { |
| 1313 | llvm::CallBase *CallOrInvoke; |
| 1314 | llvm::Constant *CalleePtr = CGF.CGM.GetAddrOfFunction(CalleeDecl); |
| 1315 | CGCallee Callee = CGCallee::forDirect(CalleePtr, GlobalDecl(CalleeDecl)); |
| 1316 | RValue RV = |
| 1317 | CGF.EmitCall(CGF.CGM.getTypes().arrangeFreeFunctionCall( |
| 1318 | Args, CalleeType, false), |
| 1319 | Callee, ReturnValueSlot(), Args, &CallOrInvoke); |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | llvm::Function *Fn = dyn_cast<llvm::Function>(CalleePtr); |
| 1327 | if (CalleeDecl->isReplaceableGlobalAllocationFunction() && |
| 1328 | Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) { |
| 1329 | CallOrInvoke->addAttribute(llvm::AttributeList::FunctionIndex, |
| 1330 | llvm::Attribute::Builtin); |
| 1331 | } |
| 1332 | |
| 1333 | return RV; |
| 1334 | } |
| 1335 | |
| 1336 | RValue CodeGenFunction::EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, |
| 1337 | const CallExpr *TheCall, |
| 1338 | bool IsDelete) { |
| 1339 | CallArgList Args; |
| 1340 | EmitCallArgs(Args, Type, TheCall->arguments()); |
| 1341 | |
| 1342 | ASTContext &Ctx = getContext(); |
| 1343 | DeclarationName Name = Ctx.DeclarationNames |
| 1344 | .getCXXOperatorName(IsDelete ? OO_Delete : OO_New); |
| 1345 | |
| 1346 | for (auto *Decl : Ctx.getTranslationUnitDecl()->lookup(Name)) |
| 1347 | if (auto *FD = dyn_cast<FunctionDecl>(Decl)) |
| 1348 | if (Ctx.hasSameType(FD->getType(), QualType(Type, 0))) |
| 1349 | return EmitNewDeleteCall(*this, FD, Type, Args); |
| 1350 | llvm_unreachable("predeclared global operator new/delete is missing"); |
| 1351 | } |
| 1352 | |
| 1353 | namespace { |
| 1354 | |
| 1355 | struct UsualDeleteParams { |
| 1356 | bool DestroyingDelete = false; |
| 1357 | bool Size = false; |
| 1358 | bool Alignment = false; |
| 1359 | }; |
| 1360 | } |
| 1361 | |
| 1362 | static UsualDeleteParams getUsualDeleteParams(const FunctionDecl *FD) { |
| 1363 | UsualDeleteParams Params; |
| 1364 | |
| 1365 | const FunctionProtoType *FPT = FD->getType()->castAs<FunctionProtoType>(); |
| 1366 | auto AI = FPT->param_type_begin(), AE = FPT->param_type_end(); |
| 1367 | |
| 1368 | |
| 1369 | ++AI; |
| 1370 | |
| 1371 | |
| 1372 | if (FD->isDestroyingOperatorDelete()) { |
| 1373 | Params.DestroyingDelete = true; |
| 1374 | assert(AI != AE); |
| 1375 | ++AI; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | if (AI != AE && (*AI)->isIntegerType()) { |
| 1380 | Params.Size = true; |
| 1381 | ++AI; |
| 1382 | } |
| 1383 | |
| 1384 | if (AI != AE && (*AI)->isAlignValT()) { |
| 1385 | Params.Alignment = true; |
| 1386 | ++AI; |
| 1387 | } |
| 1388 | |
| 1389 | assert(AI == AE && "unexpected usual deallocation function parameter"); |
| 1390 | return Params; |
| 1391 | } |
| 1392 | |
| 1393 | namespace { |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | template<typename Traits> |
| 1398 | class CallDeleteDuringNew final : public EHScopeStack::Cleanup { |
| 1399 | |
| 1400 | typedef typename Traits::ValueTy ValueTy; |
| 1401 | |
| 1402 | typedef typename Traits::RValueTy RValueTy; |
| 1403 | struct PlacementArg { |
| 1404 | RValueTy ArgValue; |
| 1405 | QualType ArgType; |
| 1406 | }; |
| 1407 | |
| 1408 | unsigned NumPlacementArgs : 31; |
| 1409 | unsigned PassAlignmentToPlacementDelete : 1; |
| 1410 | const FunctionDecl *OperatorDelete; |
| 1411 | ValueTy Ptr; |
| 1412 | ValueTy AllocSize; |
| 1413 | CharUnits AllocAlign; |
| 1414 | |
| 1415 | PlacementArg *getPlacementArgs() { |
| 1416 | return reinterpret_cast<PlacementArg *>(this + 1); |
| 1417 | } |
| 1418 | |
| 1419 | public: |
| 1420 | static size_t getExtraSize(size_t NumPlacementArgs) { |
| 1421 | return NumPlacementArgs * sizeof(PlacementArg); |
| 1422 | } |
| 1423 | |
| 1424 | CallDeleteDuringNew(size_t NumPlacementArgs, |
| 1425 | const FunctionDecl *OperatorDelete, ValueTy Ptr, |
| 1426 | ValueTy AllocSize, bool PassAlignmentToPlacementDelete, |
| 1427 | CharUnits AllocAlign) |
| 1428 | : NumPlacementArgs(NumPlacementArgs), |
| 1429 | PassAlignmentToPlacementDelete(PassAlignmentToPlacementDelete), |
| 1430 | OperatorDelete(OperatorDelete), Ptr(Ptr), AllocSize(AllocSize), |
| 1431 | AllocAlign(AllocAlign) {} |
| 1432 | |
| 1433 | void setPlacementArg(unsigned I, RValueTy Arg, QualType Type) { |
| 1434 | assert(I < NumPlacementArgs && "index out of range"); |
| 1435 | getPlacementArgs()[I] = {Arg, Type}; |
| 1436 | } |
| 1437 | |
| 1438 | void Emit(CodeGenFunction &CGF, Flags flags) override { |
| 1439 | const auto *FPT = OperatorDelete->getType()->castAs<FunctionProtoType>(); |
| 1440 | CallArgList DeleteArgs; |
| 1441 | |
| 1442 | |
| 1443 | |
| 1444 | DeleteArgs.add(Traits::get(CGF, Ptr), FPT->getParamType(0)); |
| 1445 | |
| 1446 | |
| 1447 | UsualDeleteParams Params; |
| 1448 | if (NumPlacementArgs) { |
| 1449 | |
| 1450 | |
| 1451 | Params.Alignment = PassAlignmentToPlacementDelete; |
| 1452 | } else { |
| 1453 | |
| 1454 | |
| 1455 | Params = getUsualDeleteParams(OperatorDelete); |
| 1456 | } |
| 1457 | |
| 1458 | assert(!Params.DestroyingDelete && |
| 1459 | "should not call destroying delete in a new-expression"); |
| 1460 | |
| 1461 | |
| 1462 | if (Params.Size) |
| 1463 | DeleteArgs.add(Traits::get(CGF, AllocSize), |
| 1464 | CGF.getContext().getSizeType()); |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | if (Params.Alignment) |
| 1471 | DeleteArgs.add(RValue::get(llvm::ConstantInt::get( |
| 1472 | CGF.SizeTy, AllocAlign.getQuantity())), |
| 1473 | CGF.getContext().getSizeType()); |
| 1474 | |
| 1475 | |
| 1476 | for (unsigned I = 0; I != NumPlacementArgs; ++I) { |
| 1477 | auto Arg = getPlacementArgs()[I]; |
| 1478 | DeleteArgs.add(Traits::get(CGF, Arg.ArgValue), Arg.ArgType); |
| 1479 | } |
| 1480 | |
| 1481 | |
| 1482 | EmitNewDeleteCall(CGF, OperatorDelete, FPT, DeleteArgs); |
| 1483 | } |
| 1484 | }; |
| 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | static void EnterNewDeleteCleanup(CodeGenFunction &CGF, |
| 1490 | const CXXNewExpr *E, |
| 1491 | Address NewPtr, |
| 1492 | llvm::Value *AllocSize, |
| 1493 | CharUnits AllocAlign, |
| 1494 | const CallArgList &NewArgs) { |
| 1495 | unsigned NumNonPlacementArgs = E->passAlignment() ? 2 : 1; |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | if (!CGF.isInConditionalBranch()) { |
| 1500 | struct DirectCleanupTraits { |
| 1501 | typedef llvm::Value *ValueTy; |
| 1502 | typedef RValue RValueTy; |
| 1503 | static RValue get(CodeGenFunction &, ValueTy V) { return RValue::get(V); } |
| 1504 | static RValue get(CodeGenFunction &, RValueTy V) { return V; } |
| 1505 | }; |
| 1506 | |
| 1507 | typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup; |
| 1508 | |
| 1509 | DirectCleanup *Cleanup = CGF.EHStack |
| 1510 | .pushCleanupWithExtra<DirectCleanup>(EHCleanup, |
| 1511 | E->getNumPlacementArgs(), |
| 1512 | E->getOperatorDelete(), |
| 1513 | NewPtr.getPointer(), |
| 1514 | AllocSize, |
| 1515 | E->passAlignment(), |
| 1516 | AllocAlign); |
| 1517 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 1518 | auto &Arg = NewArgs[I + NumNonPlacementArgs]; |
| 1519 | Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty); |
| 1520 | } |
| 1521 | |
| 1522 | return; |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | DominatingValue<RValue>::saved_type SavedNewPtr = |
| 1527 | DominatingValue<RValue>::save(CGF, RValue::get(NewPtr.getPointer())); |
| 1528 | DominatingValue<RValue>::saved_type SavedAllocSize = |
| 1529 | DominatingValue<RValue>::save(CGF, RValue::get(AllocSize)); |
| 1530 | |
| 1531 | struct ConditionalCleanupTraits { |
| 1532 | typedef DominatingValue<RValue>::saved_type ValueTy; |
| 1533 | typedef DominatingValue<RValue>::saved_type RValueTy; |
| 1534 | static RValue get(CodeGenFunction &CGF, ValueTy V) { |
| 1535 | return V.restore(CGF); |
| 1536 | } |
| 1537 | }; |
| 1538 | typedef CallDeleteDuringNew<ConditionalCleanupTraits> ConditionalCleanup; |
| 1539 | |
| 1540 | ConditionalCleanup *Cleanup = CGF.EHStack |
| 1541 | .pushCleanupWithExtra<ConditionalCleanup>(EHCleanup, |
| 1542 | E->getNumPlacementArgs(), |
| 1543 | E->getOperatorDelete(), |
| 1544 | SavedNewPtr, |
| 1545 | SavedAllocSize, |
| 1546 | E->passAlignment(), |
| 1547 | AllocAlign); |
| 1548 | for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { |
| 1549 | auto &Arg = NewArgs[I + NumNonPlacementArgs]; |
| 1550 | Cleanup->setPlacementArg( |
| 1551 | I, DominatingValue<RValue>::save(CGF, Arg.getRValue(CGF)), Arg.Ty); |
| 1552 | } |
| 1553 | |
| 1554 | CGF.initFullExprCleanup(); |
| 1555 | } |
| 1556 | |
| 1557 | llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) { |
| 1558 | |
| 1559 | QualType allocType = getContext().getBaseElementType(E->getAllocatedType()); |
| 1560 | |
| 1561 | |
| 1562 | FunctionDecl *allocator = E->getOperatorNew(); |
| 1563 | |
| 1564 | |
| 1565 | unsigned minElements = 0; |
| 1566 | if (E->isArray() && E->hasInitializer()) { |
| 1 | Assuming the condition is false | |
|
| 1567 | const InitListExpr *ILE = dyn_cast<InitListExpr>(E->getInitializer()); |
| 1568 | if (ILE && ILE->isStringLiteralInit()) |
| 1569 | minElements = |
| 1570 | cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe()) |
| 1571 | ->getSize().getZExtValue(); |
| 1572 | else if (ILE) |
| 1573 | minElements = ILE->getNumInits(); |
| 1574 | } |
| 1575 | |
| 1576 | llvm::Value *numElements = nullptr; |
| 2 | | 'numElements' initialized to a null pointer value | |
|
| 1577 | llvm::Value *allocSizeWithoutCookie = nullptr; |
| 1578 | llvm::Value *allocSize = |
| 1579 | EmitCXXNewAllocSize(*this, E, minElements, numElements, |
| 3 | | Calling 'EmitCXXNewAllocSize' | |
|
| 6 | | Returning from 'EmitCXXNewAllocSize' | |
|
| 1580 | allocSizeWithoutCookie); |
| 1581 | CharUnits allocAlign = getContext().getPreferredTypeAlignInChars(allocType); |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | Address allocation = Address::invalid(); |
| 1586 | CallArgList allocatorArgs; |
| 1587 | if (allocator->isReservedGlobalPlacementOperator()) { |
| 7 | | Assuming the condition is false | |
|
| |
| 1588 | assert(E->getNumPlacementArgs() == 1); |
| 1589 | const Expr *arg = *E->placement_arguments().begin(); |
| 1590 | |
| 1591 | LValueBaseInfo BaseInfo; |
| 1592 | allocation = EmitPointerWithAlignment(arg, &BaseInfo); |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | if (BaseInfo.getAlignmentSource() != AlignmentSource::Decl) |
| 1598 | allocation = Address(allocation.getPointer(), allocAlign); |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | if (E->getOperatorDelete() && |
| 1603 | !E->getOperatorDelete()->isReservedGlobalPlacementOperator()) { |
| 1604 | allocatorArgs.add(RValue::get(allocSize), getContext().getSizeType()); |
| 1605 | allocatorArgs.add(RValue::get(allocation.getPointer()), arg->getType()); |
| 1606 | } |
| 1607 | |
| 1608 | } else { |
| 1609 | const FunctionProtoType *allocatorType = |
| 1610 | allocator->getType()->castAs<FunctionProtoType>(); |
| 9 | | The object is a 'FunctionProtoType' | |
|
| 1611 | unsigned ParamsToSkip = 0; |
| 1612 | |
| 1613 | |
| 1614 | QualType sizeType = getContext().getSizeType(); |
| 1615 | allocatorArgs.add(RValue::get(allocSize), sizeType); |
| 1616 | ++ParamsToSkip; |
| 1617 | |
| 1618 | if (allocSize != allocSizeWithoutCookie) { |
| |
| 1619 | CharUnits cookieAlign = getSizeAlign(); |
| 1620 | allocAlign = std::max(allocAlign, cookieAlign); |
| 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | if (E->passAlignment()) { |
| 11 | | Assuming the condition is false | |
|
| |
| 1625 | QualType AlignValT = sizeType; |
| 1626 | if (allocatorType->getNumParams() > 1) { |
| 1627 | AlignValT = allocatorType->getParamType(1); |
| 1628 | assert(getContext().hasSameUnqualifiedType( |
| 1629 | AlignValT->castAs<EnumType>()->getDecl()->getIntegerType(), |
| 1630 | sizeType) && |
| 1631 | "wrong type for alignment parameter"); |
| 1632 | ++ParamsToSkip; |
| 1633 | } else { |
| 1634 | |
| 1635 | assert(allocator->isVariadic() && "can't pass alignment to allocator"); |
| 1636 | } |
| 1637 | allocatorArgs.add( |
| 1638 | RValue::get(llvm::ConstantInt::get(SizeTy, allocAlign.getQuantity())), |
| 1639 | AlignValT); |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | EmitCallArgs(allocatorArgs, allocatorType, E->placement_arguments(), |
| 1644 | AbstractCallee(), ParamsToSkip); |
| 1645 | |
| 1646 | RValue RV = |
| 1647 | EmitNewDeleteCall(*this, allocator, allocatorType, allocatorArgs); |
| 1648 | |
| 1649 | |
| 1650 | if (getDebugInfo()) |
| 13 | | Assuming the condition is false | |
|
| |
| 1651 | if (auto *newCall = dyn_cast<llvm::CallBase>(RV.getScalarVal())) |
| 1652 | getDebugInfo()->addHeapAllocSiteMetadata(newCall, allocType, |
| 1653 | E->getExprLoc()); |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | CharUnits allocationAlign = allocAlign; |
| 1660 | if (!E->passAlignment() && |
| 15 | | Assuming the condition is false | |
|
| 1661 | allocator->isReplaceableGlobalAllocationFunction()) { |
| 1662 | unsigned AllocatorAlign = llvm::PowerOf2Floor(std::min<uint64_t>( |
| 1663 | Target.getNewAlign(), getContext().getTypeSize(allocType))); |
| 1664 | allocationAlign = std::max( |
| 1665 | allocationAlign, getContext().toCharUnitsFromBits(AllocatorAlign)); |
| 1666 | } |
| 1667 | |
| 1668 | allocation = Address(RV.getScalarVal(), allocationAlign); |
| 1669 | } |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | bool nullCheck = E->shouldNullCheckAllocation() && |
| 16 | | Assuming the condition is false | |
|
| 1676 | (!allocType.isPODType(getContext()) || E->hasInitializer() || |
| 1677 | sanitizePerformTypeCheck()); |
| 1678 | |
| 1679 | llvm::BasicBlock *nullCheckBB = nullptr; |
| 1680 | llvm::BasicBlock *contBB = nullptr; |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | ConditionalEvaluation conditional(*this); |
| 1685 | |
| 1686 | if (nullCheck) { |
| |
| 1687 | conditional.begin(*this); |
| 1688 | |
| 1689 | nullCheckBB = Builder.GetInsertBlock(); |
| 1690 | llvm::BasicBlock *notNullBB = createBasicBlock("new.notnull"); |
| 1691 | contBB = createBasicBlock("new.cont"); |
| 1692 | |
| 1693 | llvm::Value *isNull = |
| 1694 | Builder.CreateIsNull(allocation.getPointer(), "new.isnull"); |
| 1695 | Builder.CreateCondBr(isNull, contBB, notNullBB); |
| 1696 | EmitBlock(notNullBB); |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | EHScopeStack::stable_iterator operatorDeleteCleanup; |
| 1702 | llvm::Instruction *cleanupDominator = nullptr; |
| 1703 | if (E->getOperatorDelete() && |
| 18 | | Assuming the condition is false | |
|
| 1704 | !E->getOperatorDelete()->isReservedGlobalPlacementOperator()) { |
| 1705 | EnterNewDeleteCleanup(*this, E, allocation, allocSize, allocAlign, |
| 1706 | allocatorArgs); |
| 1707 | operatorDeleteCleanup = EHStack.stable_begin(); |
| 1708 | cleanupDominator = Builder.CreateUnreachable(); |
| 1709 | } |
| 1710 | |
| 1711 | assert((allocSize == allocSizeWithoutCookie) == |
| 1712 | CalculateCookiePadding(*this, E).isZero()); |
| 1713 | if (allocSize != allocSizeWithoutCookie) { |
| |
| 1714 | assert(E->isArray()); |
| 1715 | allocation = CGM.getCXXABI().InitializeArrayCookie(*this, allocation, |
| 1716 | numElements, |
| 1717 | E, allocType); |
| 1718 | } |
| 1719 | |
| 1720 | llvm::Type *elementTy = ConvertTypeForMem(allocType); |
| 1721 | Address result = Builder.CreateElementBitCast(allocation, elementTy); |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | if (CGM.getCodeGenOpts().StrictVTablePointers && |
| 20 | | Assuming field 'StrictVTablePointers' is 0 | |
|
| 1728 | allocator->isReservedGlobalPlacementOperator()) |
| 1729 | result = Address(Builder.CreateLaunderInvariantGroup(result.getPointer()), |
| 1730 | result.getAlignment()); |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | SanitizerSet SkippedChecks; |
| 1738 | SkippedChecks.set(SanitizerKind::Null, nullCheck); |
| 1739 | EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, |
| 1740 | E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(), |
| 1741 | result.getPointer(), allocType, result.getAlignment(), |
| 1742 | SkippedChecks, numElements); |
| 1743 | |
| 1744 | EmitNewInitializer(*this, E, allocType, elementTy, result, numElements, |
| 21 | | Passing null pointer value via 6th parameter 'NumElements' | |
|
| 22 | | Calling 'EmitNewInitializer' | |
|
| 1745 | allocSizeWithoutCookie); |
| 1746 | if (E->isArray()) { |
| 1747 | |
| 1748 | |
| 1749 | |
| 1750 | llvm::Type *resultType = ConvertTypeForMem(E->getType()); |
| 1751 | if (result.getType() != resultType) |
| 1752 | result = Builder.CreateBitCast(result, resultType); |
| 1753 | } |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | if (operatorDeleteCleanup.isValid()) { |
| 1758 | DeactivateCleanupBlock(operatorDeleteCleanup, cleanupDominator); |
| 1759 | cleanupDominator->eraseFromParent(); |
| 1760 | } |
| 1761 | |
| 1762 | llvm::Value *resultPtr = result.getPointer(); |
| 1763 | if (nullCheck) { |
| 1764 | conditional.end(*this); |
| 1765 | |
| 1766 | llvm::BasicBlock *notNullBB = Builder.GetInsertBlock(); |
| 1767 | EmitBlock(contBB); |
| 1768 | |
| 1769 | llvm::PHINode *PHI = Builder.CreatePHI(resultPtr->getType(), 2); |
| 1770 | PHI->addIncoming(resultPtr, notNullBB); |
| 1771 | PHI->addIncoming(llvm::Constant::getNullValue(resultPtr->getType()), |
| 1772 | nullCheckBB); |
| 1773 | |
| 1774 | resultPtr = PHI; |
| 1775 | } |
| 1776 | |
| 1777 | return resultPtr; |
| 1778 | } |
| 1779 | |
| 1780 | void CodeGenFunction::EmitDeleteCall(const FunctionDecl *DeleteFD, |
| 1781 | llvm::Value *Ptr, QualType DeleteTy, |
| 1782 | llvm::Value *NumElements, |
| 1783 | CharUnits CookieSize) { |
| 1784 | assert((!NumElements && CookieSize.isZero()) || |
| 1785 | DeleteFD->getOverloadedOperator() == OO_Array_Delete); |
| 1786 | |
| 1787 | const auto *DeleteFTy = DeleteFD->getType()->castAs<FunctionProtoType>(); |
| 1788 | CallArgList DeleteArgs; |
| 1789 | |
| 1790 | auto Params = getUsualDeleteParams(DeleteFD); |
| 1791 | auto ParamTypeIt = DeleteFTy->param_type_begin(); |
| 1792 | |
| 1793 | |
| 1794 | QualType ArgTy = *ParamTypeIt++; |
| 1795 | llvm::Value *DeletePtr = Builder.CreateBitCast(Ptr, ConvertType(ArgTy)); |
| 1796 | DeleteArgs.add(RValue::get(DeletePtr), ArgTy); |
| 1797 | |
| 1798 | |
| 1799 | llvm::AllocaInst *DestroyingDeleteTag = nullptr; |
| 1800 | if (Params.DestroyingDelete) { |
| 1801 | QualType DDTag = *ParamTypeIt++; |
| 1802 | llvm::Type *Ty = getTypes().ConvertType(DDTag); |
| 1803 | CharUnits Align = CGM.getNaturalTypeAlignment(DDTag); |
| 1804 | DestroyingDeleteTag = CreateTempAlloca(Ty, "destroying.delete.tag"); |
| 1805 | DestroyingDeleteTag->setAlignment(Align.getAsAlign()); |
| 1806 | DeleteArgs.add(RValue::getAggregate(Address(DestroyingDeleteTag, Align)), DDTag); |
| 1807 | } |
| 1808 | |
| 1809 | |
| 1810 | if (Params.Size) { |
| 1811 | QualType SizeType = *ParamTypeIt++; |
| 1812 | CharUnits DeleteTypeSize = getContext().getTypeSizeInChars(DeleteTy); |
| 1813 | llvm::Value *Size = llvm::ConstantInt::get(ConvertType(SizeType), |
| 1814 | DeleteTypeSize.getQuantity()); |
| 1815 | |
| 1816 | |
| 1817 | if (NumElements) |
| 1818 | Size = Builder.CreateMul(Size, NumElements); |
| 1819 | |
| 1820 | |
| 1821 | if (!CookieSize.isZero()) |
| 1822 | Size = Builder.CreateAdd( |
| 1823 | Size, llvm::ConstantInt::get(SizeTy, CookieSize.getQuantity())); |
| 1824 | |
| 1825 | DeleteArgs.add(RValue::get(Size), SizeType); |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | if (Params.Alignment) { |
| 1830 | QualType AlignValType = *ParamTypeIt++; |
| 1831 | CharUnits DeleteTypeAlign = |
| 1832 | getContext().toCharUnitsFromBits(getContext().getTypeAlignIfKnown( |
| 1833 | DeleteTy, true )); |
| 1834 | llvm::Value *Align = llvm::ConstantInt::get(ConvertType(AlignValType), |
| 1835 | DeleteTypeAlign.getQuantity()); |
| 1836 | DeleteArgs.add(RValue::get(Align), AlignValType); |
| 1837 | } |
| 1838 | |
| 1839 | assert(ParamTypeIt == DeleteFTy->param_type_end() && |
| 1840 | "unknown parameter to usual delete function"); |
| 1841 | |
| 1842 | |
| 1843 | EmitNewDeleteCall(*this, DeleteFD, DeleteFTy, DeleteArgs); |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | if (DestroyingDeleteTag && DestroyingDeleteTag->use_empty()) |
| 1848 | DestroyingDeleteTag->eraseFromParent(); |
| 1849 | } |
| 1850 | |
| 1851 | namespace { |
| 1852 | |
| 1853 | struct CallObjectDelete final : EHScopeStack::Cleanup { |
| 1854 | llvm::Value *Ptr; |
| 1855 | const FunctionDecl *OperatorDelete; |
| 1856 | QualType ElementType; |
| 1857 | |
| 1858 | CallObjectDelete(llvm::Value *Ptr, |
| 1859 | const FunctionDecl *OperatorDelete, |
| 1860 | QualType ElementType) |
| 1861 | : Ptr(Ptr), OperatorDelete(OperatorDelete), ElementType(ElementType) {} |
| 1862 | |
| 1863 | void Emit(CodeGenFunction &CGF, Flags flags) override { |
| 1864 | CGF.EmitDeleteCall(OperatorDelete, Ptr, ElementType); |
| 1865 | } |
| 1866 | }; |
| 1867 | } |
| 1868 | |
| 1869 | void |
| 1870 | CodeGenFunction::pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, |
| 1871 | llvm::Value *CompletePtr, |
| 1872 | QualType ElementType) { |
| 1873 | EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup, CompletePtr, |
| 1874 | OperatorDelete, ElementType); |
| 1875 | } |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | static void EmitDestroyingObjectDelete(CodeGenFunction &CGF, |
| 1882 | const CXXDeleteExpr *DE, Address Ptr, |
| 1883 | QualType ElementType) { |
| 1884 | auto *Dtor = ElementType->getAsCXXRecordDecl()->getDestructor(); |
| 1885 | if (Dtor && Dtor->isVirtual()) |
| 1886 | CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType, |
| 1887 | Dtor); |
| 1888 | else |
| 1889 | CGF.EmitDeleteCall(DE->getOperatorDelete(), Ptr.getPointer(), ElementType); |
| 1890 | } |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | |
| 1895 | static bool EmitObjectDelete(CodeGenFunction &CGF, |
| 1896 | const CXXDeleteExpr *DE, |
| 1897 | Address Ptr, |
| 1898 | QualType ElementType, |
| 1899 | llvm::BasicBlock *UnconditionalDeleteBlock) { |
| 1900 | |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | |
| 1905 | CGF.EmitTypeCheck(CodeGenFunction::TCK_MemberCall, |
| 1906 | DE->getExprLoc(), Ptr.getPointer(), |
| 1907 | ElementType); |
| 1908 | |
| 1909 | const FunctionDecl *OperatorDelete = DE->getOperatorDelete(); |
| 1910 | assert(!OperatorDelete->isDestroyingOperatorDelete()); |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | const CXXDestructorDecl *Dtor = nullptr; |
| 1915 | if (const RecordType *RT = ElementType->getAs<RecordType>()) { |
| 1916 | CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); |
| 1917 | if (RD->hasDefinition() && !RD->hasTrivialDestructor()) { |
| 1918 | Dtor = RD->getDestructor(); |
| 1919 | |
| 1920 | if (Dtor->isVirtual()) { |
| 1921 | bool UseVirtualCall = true; |
| 1922 | const Expr *Base = DE->getArgument(); |
| 1923 | if (auto *DevirtualizedDtor = |
| 1924 | dyn_cast_or_null<const CXXDestructorDecl>( |
| 1925 | Dtor->getDevirtualizedMethod( |
| 1926 | Base, CGF.CGM.getLangOpts().AppleKext))) { |
| 1927 | UseVirtualCall = false; |
| 1928 | const CXXRecordDecl *DevirtualizedClass = |
| 1929 | DevirtualizedDtor->getParent(); |
| 1930 | if (declaresSameEntity(getCXXRecord(Base), DevirtualizedClass)) { |
| 1931 | |
| 1932 | |
| 1933 | Dtor = DevirtualizedDtor; |
| 1934 | } else { |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | UseVirtualCall = true; |
| 1941 | } |
| 1942 | } |
| 1943 | if (UseVirtualCall) { |
| 1944 | CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType, |
| 1945 | Dtor); |
| 1946 | return false; |
| 1947 | } |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | |
| 1955 | CGF.EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup, |
| 1956 | Ptr.getPointer(), |
| 1957 | OperatorDelete, ElementType); |
| 1958 | |
| 1959 | if (Dtor) |
| 1960 | CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, |
| 1961 | false, |
| 1962 | false, |
| 1963 | Ptr, ElementType); |
| 1964 | else if (auto Lifetime = ElementType.getObjCLifetime()) { |
| 1965 | switch (Lifetime) { |
| 1966 | case Qualifiers::OCL_None: |
| 1967 | case Qualifiers::OCL_ExplicitNone: |
| 1968 | case Qualifiers::OCL_Autoreleasing: |
| 1969 | break; |
| 1970 | |
| 1971 | case Qualifiers::OCL_Strong: |
| 1972 | CGF.EmitARCDestroyStrong(Ptr, ARCPreciseLifetime); |
| 1973 | break; |
| 1974 | |
| 1975 | case Qualifiers::OCL_Weak: |
| 1976 | CGF.EmitARCDestroyWeak(Ptr); |
| 1977 | break; |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | |
| 1982 | if (CGF.CGM.getCodeGenOpts().OptimizeSize > 1) { |
| 1983 | CGF.EmitBlock(UnconditionalDeleteBlock); |
| 1984 | CGF.PopCleanupBlock(); |
| 1985 | return true; |
| 1986 | } |
| 1987 | |
| 1988 | CGF.PopCleanupBlock(); |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
| 1992 | namespace { |
| 1993 | |
| 1994 | struct CallArrayDelete final : EHScopeStack::Cleanup { |
| 1995 | llvm::Value *Ptr; |
| 1996 | const FunctionDecl *OperatorDelete; |
| 1997 | llvm::Value *NumElements; |
| 1998 | QualType ElementType; |
| 1999 | CharUnits CookieSize; |
| 2000 | |
| 2001 | CallArrayDelete(llvm::Value *Ptr, |
| 2002 | const FunctionDecl *OperatorDelete, |
| 2003 | llvm::Value *NumElements, |
| 2004 | QualType ElementType, |
| 2005 | CharUnits CookieSize) |
| 2006 | : Ptr(Ptr), OperatorDelete(OperatorDelete), NumElements(NumElements), |
| 2007 | ElementType(ElementType), CookieSize(CookieSize) {} |
| 2008 | |
| 2009 | void Emit(CodeGenFunction &CGF, Flags flags) override { |
| 2010 | CGF.EmitDeleteCall(OperatorDelete, Ptr, ElementType, NumElements, |
| 2011 | CookieSize); |
| 2012 | } |
| 2013 | }; |
| 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | static void EmitArrayDelete(CodeGenFunction &CGF, |
| 2018 | const CXXDeleteExpr *E, |
| 2019 | Address deletedPtr, |
| 2020 | QualType elementType) { |
| 2021 | llvm::Value *numElements = nullptr; |
| 2022 | llvm::Value *allocatedPtr = nullptr; |
| 2023 | CharUnits cookieSize; |
| 2024 | CGF.CGM.getCXXABI().ReadArrayCookie(CGF, deletedPtr, E, elementType, |
| 2025 | numElements, allocatedPtr, cookieSize); |
| 2026 | |
| 2027 | assert(allocatedPtr && "ReadArrayCookie didn't set allocated pointer"); |
| 2028 | |
| 2029 | |
| 2030 | const FunctionDecl *operatorDelete = E->getOperatorDelete(); |
| 2031 | CGF.EHStack.pushCleanup<CallArrayDelete>(NormalAndEHCleanup, |
| 2032 | allocatedPtr, operatorDelete, |
| 2033 | numElements, elementType, |
| 2034 | cookieSize); |
| 2035 | |
| 2036 | |
| 2037 | if (QualType::DestructionKind dtorKind = elementType.isDestructedType()) { |
| 2038 | assert(numElements && "no element count for a type with a destructor!"); |
| 2039 | |
| 2040 | CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType); |
| 2041 | CharUnits elementAlign = |
| 2042 | deletedPtr.getAlignment().alignmentOfArrayElement(elementSize); |
| 2043 | |
| 2044 | llvm::Value *arrayBegin = deletedPtr.getPointer(); |
| 2045 | llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP( |
| 2046 | deletedPtr.getElementType(), arrayBegin, numElements, "delete.end"); |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | CGF.emitArrayDestroy(arrayBegin, arrayEnd, elementType, elementAlign, |
| 2052 | CGF.getDestroyer(dtorKind), |
| 2053 | true, |
| 2054 | CGF.needsEHCleanup(dtorKind)); |
| 2055 | } |
| 2056 | |
| 2057 | |
| 2058 | CGF.PopCleanupBlock(); |
| 2059 | } |
| 2060 | |
| 2061 | void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) { |
| 2062 | const Expr *Arg = E->getArgument(); |
| 2063 | Address Ptr = EmitPointerWithAlignment(Arg); |
| 2064 | |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | |
| 2070 | |
| 2071 | |
| 2072 | llvm::BasicBlock *DeleteNotNull = createBasicBlock("delete.notnull"); |
| 2073 | llvm::BasicBlock *DeleteEnd = createBasicBlock("delete.end"); |
| 2074 | |
| 2075 | llvm::Value *IsNull = Builder.CreateIsNull(Ptr.getPointer(), "isnull"); |
| 2076 | |
| 2077 | Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull); |
| 2078 | EmitBlock(DeleteNotNull); |
| 2079 | |
| 2080 | QualType DeleteTy = E->getDestroyedType(); |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | if (E->getOperatorDelete()->isDestroyingOperatorDelete()) { |
| 2085 | EmitDestroyingObjectDelete(*this, E, Ptr, DeleteTy); |
| 2086 | EmitBlock(DeleteEnd); |
| 2087 | return; |
| 2088 | } |
| 2089 | |
| 2090 | |
| 2091 | |
| 2092 | |
| 2093 | if (DeleteTy->isConstantArrayType()) { |
| 2094 | llvm::Value *Zero = Builder.getInt32(0); |
| 2095 | SmallVector<llvm::Value*,8> GEP; |
| 2096 | |
| 2097 | GEP.push_back(Zero); |
| 2098 | |
| 2099 | |
| 2100 | while (const ConstantArrayType *Arr |
| 2101 | = getContext().getAsConstantArrayType(DeleteTy)) { |
| 2102 | |
| 2103 | DeleteTy = Arr->getElementType(); |
| 2104 | |
| 2105 | |
| 2106 | GEP.push_back(Zero); |
| 2107 | } |
| 2108 | |
| 2109 | Ptr = Address(Builder.CreateInBoundsGEP(Ptr.getElementType(), |
| 2110 | Ptr.getPointer(), GEP, "del.first"), |
| 2111 | Ptr.getAlignment()); |
| 2112 | } |
| 2113 | |
| 2114 | assert(ConvertTypeForMem(DeleteTy) == Ptr.getElementType()); |
| 2115 | |
| 2116 | if (E->isArrayForm()) { |
| 2117 | EmitArrayDelete(*this, E, Ptr, DeleteTy); |
| 2118 | EmitBlock(DeleteEnd); |
| 2119 | } else { |
| 2120 | if (!EmitObjectDelete(*this, E, Ptr, DeleteTy, DeleteEnd)) |
| 2121 | EmitBlock(DeleteEnd); |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | static bool isGLValueFromPointerDeref(const Expr *E) { |
| 2126 | E = E->IgnoreParens(); |
| 2127 | |
| 2128 | if (const auto *CE = dyn_cast<CastExpr>(E)) { |
| 2129 | if (!CE->getSubExpr()->isGLValue()) |
| 2130 | return false; |
| 2131 | return isGLValueFromPointerDeref(CE->getSubExpr()); |
| 2132 | } |
| 2133 | |
| 2134 | if (const auto *OVE = dyn_cast<OpaqueValueExpr>(E)) |
| 2135 | return isGLValueFromPointerDeref(OVE->getSourceExpr()); |
| 2136 | |
| 2137 | if (const auto *BO = dyn_cast<BinaryOperator>(E)) |
| 2138 | if (BO->getOpcode() == BO_Comma) |
| 2139 | return isGLValueFromPointerDeref(BO->getRHS()); |
| 2140 | |
| 2141 | if (const auto *ACO = dyn_cast<AbstractConditionalOperator>(E)) |
| 2142 | return isGLValueFromPointerDeref(ACO->getTrueExpr()) || |
| 2143 | isGLValueFromPointerDeref(ACO->getFalseExpr()); |
| 2144 | |
| 2145 | |
| 2146 | |
| 2147 | if (isa<ArraySubscriptExpr>(E)) |
| 2148 | return true; |
| 2149 | |
| 2150 | if (const auto *UO = dyn_cast<UnaryOperator>(E)) |
| 2151 | if (UO->getOpcode() == UO_Deref) |
| 2152 | return true; |
| 2153 | |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
| 2157 | static llvm::Value *EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E, |
| 2158 | llvm::Type *StdTypeInfoPtrTy) { |
| 2159 | |
| 2160 | Address ThisPtr = CGF.EmitLValue(E).getAddress(CGF); |
| 2161 | |
| 2162 | QualType SrcRecordTy = E->getType(); |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | CGF.EmitTypeCheck(CodeGenFunction::TCK_DynamicOperation, E->getExprLoc(), |
| 2169 | ThisPtr.getPointer(), SrcRecordTy); |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | |
| 2179 | if (CGF.CGM.getCXXABI().shouldTypeidBeNullChecked( |
| 2180 | isGLValueFromPointerDeref(E), SrcRecordTy)) { |
| 2181 | llvm::BasicBlock *BadTypeidBlock = |
| 2182 | CGF.createBasicBlock("typeid.bad_typeid"); |
| 2183 | llvm::BasicBlock *EndBlock = CGF.createBasicBlock("typeid.end"); |
| 2184 | |
| 2185 | llvm::Value *IsNull = CGF.Builder.CreateIsNull(ThisPtr.getPointer()); |
| 2186 | CGF.Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock); |
| 2187 | |
| 2188 | CGF.EmitBlock(BadTypeidBlock); |
| 2189 | CGF.CGM.getCXXABI().EmitBadTypeidCall(CGF); |
| 2190 | CGF.EmitBlock(EndBlock); |
| 2191 | } |
| 2192 | |
| 2193 | return CGF.CGM.getCXXABI().EmitTypeid(CGF, SrcRecordTy, ThisPtr, |
| 2194 | StdTypeInfoPtrTy); |
| 2195 | } |
| 2196 | |
| 2197 | llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) { |
| 2198 | llvm::Type *StdTypeInfoPtrTy = |
| 2199 | ConvertType(E->getType())->getPointerTo(); |
| 2200 | |
| 2201 | if (E->isTypeOperand()) { |
| 2202 | llvm::Constant *TypeInfo = |
| 2203 | CGM.GetAddrOfRTTIDescriptor(E->getTypeOperand(getContext())); |
| 2204 | return Builder.CreateBitCast(TypeInfo, StdTypeInfoPtrTy); |
| 2205 | } |
| 2206 | |
| 2207 | |
| 2208 | |
| 2209 | |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | if (E->isPotentiallyEvaluated() && !E->isMostDerived(getContext())) |
| 2214 | return EmitTypeidFromVTable(*this, E->getExprOperand(), |
| 2215 | StdTypeInfoPtrTy); |
| 2216 | |
| 2217 | QualType OperandTy = E->getExprOperand()->getType(); |
| 2218 | return Builder.CreateBitCast(CGM.GetAddrOfRTTIDescriptor(OperandTy), |
| 2219 | StdTypeInfoPtrTy); |
| 2220 | } |
| 2221 | |
| 2222 | static llvm::Value *EmitDynamicCastToNull(CodeGenFunction &CGF, |
| 2223 | QualType DestTy) { |
| 2224 | llvm::Type *DestLTy = CGF.ConvertType(DestTy); |
| 2225 | if (DestTy->isPointerType()) |
| 2226 | return llvm::Constant::getNullValue(DestLTy); |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | if (!CGF.CGM.getCXXABI().EmitBadCastCall(CGF)) |
| 2231 | return nullptr; |
| 2232 | |
| 2233 | CGF.EmitBlock(CGF.createBasicBlock("dynamic_cast.end")); |
| 2234 | return llvm::UndefValue::get(DestLTy); |
| 2235 | } |
| 2236 | |
| 2237 | llvm::Value *CodeGenFunction::EmitDynamicCast(Address ThisAddr, |
| 2238 | const CXXDynamicCastExpr *DCE) { |
| 2239 | CGM.EmitExplicitCastExprType(DCE, this); |
| 2240 | QualType DestTy = DCE->getTypeAsWritten(); |
| 2241 | |
| 2242 | QualType SrcTy = DCE->getSubExpr()->getType(); |
| 2243 | |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | const PointerType *DestPTy = DestTy->getAs<PointerType>(); |
| 2248 | |
| 2249 | bool isDynamicCastToVoid; |
| 2250 | QualType SrcRecordTy; |
| 2251 | QualType DestRecordTy; |
| 2252 | if (DestPTy) { |
| 2253 | isDynamicCastToVoid = DestPTy->getPointeeType()->isVoidType(); |
| 2254 | SrcRecordTy = SrcTy->castAs<PointerType>()->getPointeeType(); |
| 2255 | DestRecordTy = DestPTy->getPointeeType(); |
| 2256 | } else { |
| 2257 | isDynamicCastToVoid = false; |
| 2258 | SrcRecordTy = SrcTy; |
| 2259 | DestRecordTy = DestTy->castAs<ReferenceType>()->getPointeeType(); |
| 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | |
| 2264 | |
| 2265 | |
| 2266 | |
| 2267 | EmitTypeCheck(TCK_DynamicOperation, DCE->getExprLoc(), ThisAddr.getPointer(), |
| 2268 | SrcRecordTy); |
| 2269 | |
| 2270 | if (DCE->isAlwaysNull()) |
| 2271 | if (llvm::Value *T = EmitDynamicCastToNull(*this, DestTy)) |
| 2272 | return T; |
| 2273 | |
| 2274 | assert(SrcRecordTy->isRecordType() && "source type must be a record type!"); |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | bool ShouldNullCheckSrcValue = |
| 2280 | CGM.getCXXABI().shouldDynamicCastCallBeNullChecked(SrcTy->isPointerType(), |
| 2281 | SrcRecordTy); |
| 2282 | |
| 2283 | llvm::BasicBlock *CastNull = nullptr; |
| 2284 | llvm::BasicBlock *CastNotNull = nullptr; |
| 2285 | llvm::BasicBlock *CastEnd = createBasicBlock("dynamic_cast.end"); |
| 2286 | |
| 2287 | if (ShouldNullCheckSrcValue) { |
| 2288 | CastNull = createBasicBlock("dynamic_cast.null"); |
| 2289 | CastNotNull = createBasicBlock("dynamic_cast.notnull"); |
| 2290 | |
| 2291 | llvm::Value *IsNull = Builder.CreateIsNull(ThisAddr.getPointer()); |
| 2292 | Builder.CreateCondBr(IsNull, CastNull, CastNotNull); |
| 2293 | EmitBlock(CastNotNull); |
| 2294 | } |
| 2295 | |
| 2296 | llvm::Value *Value; |
| 2297 | if (isDynamicCastToVoid) { |
| 2298 | Value = CGM.getCXXABI().EmitDynamicCastToVoid(*this, ThisAddr, SrcRecordTy, |
| 2299 | DestTy); |
| 2300 | } else { |
| 2301 | assert(DestRecordTy->isRecordType() && |
| 2302 | "destination type must be a record type!"); |
| 2303 | Value = CGM.getCXXABI().EmitDynamicCastCall(*this, ThisAddr, SrcRecordTy, |
| 2304 | DestTy, DestRecordTy, CastEnd); |
| 2305 | CastNotNull = Builder.GetInsertBlock(); |
| 2306 | } |
| 2307 | |
| 2308 | if (ShouldNullCheckSrcValue) { |
| 2309 | EmitBranch(CastEnd); |
| 2310 | |
| 2311 | EmitBlock(CastNull); |
| 2312 | EmitBranch(CastEnd); |
| 2313 | } |
| 2314 | |
| 2315 | EmitBlock(CastEnd); |
| 2316 | |
| 2317 | if (ShouldNullCheckSrcValue) { |
| 2318 | llvm::PHINode *PHI = Builder.CreatePHI(Value->getType(), 2); |
| 2319 | PHI->addIncoming(Value, CastNotNull); |
| 2320 | PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull); |
| 2321 | |
| 2322 | Value = PHI; |
| 2323 | } |
| 2324 | |
| 2325 | return Value; |
| 2326 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_AST_EXPRCXX_H |
| 15 | #define LLVM_CLANG_AST_EXPRCXX_H |
| 16 | |
| 17 | #include "clang/AST/ASTConcept.h" |
| 18 | #include "clang/AST/ComputeDependence.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclBase.h" |
| 21 | #include "clang/AST/DeclCXX.h" |
| 22 | #include "clang/AST/DeclTemplate.h" |
| 23 | #include "clang/AST/DeclarationName.h" |
| 24 | #include "clang/AST/DependenceFlags.h" |
| 25 | #include "clang/AST/Expr.h" |
| 26 | #include "clang/AST/NestedNameSpecifier.h" |
| 27 | #include "clang/AST/OperationKinds.h" |
| 28 | #include "clang/AST/Stmt.h" |
| 29 | #include "clang/AST/StmtCXX.h" |
| 30 | #include "clang/AST/TemplateBase.h" |
| 31 | #include "clang/AST/Type.h" |
| 32 | #include "clang/AST/UnresolvedSet.h" |
| 33 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 34 | #include "clang/Basic/ExpressionTraits.h" |
| 35 | #include "clang/Basic/LLVM.h" |
| 36 | #include "clang/Basic/Lambda.h" |
| 37 | #include "clang/Basic/LangOptions.h" |
| 38 | #include "clang/Basic/OperatorKinds.h" |
| 39 | #include "clang/Basic/SourceLocation.h" |
| 40 | #include "clang/Basic/Specifiers.h" |
| 41 | #include "clang/Basic/TypeTraits.h" |
| 42 | #include "llvm/ADT/ArrayRef.h" |
| 43 | #include "llvm/ADT/None.h" |
| 44 | #include "llvm/ADT/Optional.h" |
| 45 | #include "llvm/ADT/PointerUnion.h" |
| 46 | #include "llvm/ADT/StringRef.h" |
| 47 | #include "llvm/ADT/iterator_range.h" |
| 48 | #include "llvm/Support/Casting.h" |
| 49 | #include "llvm/Support/Compiler.h" |
| 50 | #include "llvm/Support/TrailingObjects.h" |
| 51 | #include <cassert> |
| 52 | #include <cstddef> |
| 53 | #include <cstdint> |
| 54 | #include <memory> |
| 55 | |
| 56 | namespace clang { |
| 57 | |
| 58 | class ASTContext; |
| 59 | class DeclAccessPair; |
| 60 | class IdentifierInfo; |
| 61 | class LambdaCapture; |
| 62 | class NonTypeTemplateParmDecl; |
| 63 | class TemplateParameterList; |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | class CXXOperatorCallExpr final : public CallExpr { |
| 83 | friend class ASTStmtReader; |
| 84 | friend class ASTStmtWriter; |
| 85 | |
| 86 | SourceRange Range; |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | SourceRange getSourceRangeImpl() const LLVM_READONLY; |
| 92 | |
| 93 | CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn, |
| 94 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
| 95 | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, |
| 96 | ADLCallKind UsesADL); |
| 97 | |
| 98 | CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
| 99 | |
| 100 | public: |
| 101 | static CXXOperatorCallExpr * |
| 102 | Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, |
| 103 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, |
| 104 | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, |
| 105 | ADLCallKind UsesADL = NotADL); |
| 106 | |
| 107 | static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx, |
| 108 | unsigned NumArgs, bool HasFPFeatures, |
| 109 | EmptyShell Empty); |
| 110 | |
| 111 | |
| 112 | OverloadedOperatorKind getOperator() const { |
| 113 | return static_cast<OverloadedOperatorKind>( |
| 114 | CXXOperatorCallExprBits.OperatorKind); |
| 115 | } |
| 116 | |
| 117 | static bool isAssignmentOp(OverloadedOperatorKind Opc) { |
| 118 | return Opc == OO_Equal || Opc == OO_StarEqual || Opc == OO_SlashEqual || |
| 119 | Opc == OO_PercentEqual || Opc == OO_PlusEqual || |
| 120 | Opc == OO_MinusEqual || Opc == OO_LessLessEqual || |
| 121 | Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual || |
| 122 | Opc == OO_CaretEqual || Opc == OO_PipeEqual; |
| 123 | } |
| 124 | bool isAssignmentOp() const { return isAssignmentOp(getOperator()); } |
| 125 | |
| 126 | static bool isComparisonOp(OverloadedOperatorKind Opc) { |
| 127 | switch (Opc) { |
| 128 | case OO_EqualEqual: |
| 129 | case OO_ExclaimEqual: |
| 130 | case OO_Greater: |
| 131 | case OO_GreaterEqual: |
| 132 | case OO_Less: |
| 133 | case OO_LessEqual: |
| 134 | case OO_Spaceship: |
| 135 | return true; |
| 136 | default: |
| 137 | return false; |
| 138 | } |
| 139 | } |
| 140 | bool isComparisonOp() const { return isComparisonOp(getOperator()); } |
| 141 | |
| 142 | |
| 143 | bool isInfixBinaryOp() const; |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | SourceLocation getOperatorLoc() const { return getRParenLoc(); } |
| 151 | |
| 152 | SourceLocation getExprLoc() const LLVM_READONLY { |
| 153 | OverloadedOperatorKind Operator = getOperator(); |
| 154 | return (Operator < OO_Plus || Operator >= OO_Arrow || |
| 155 | Operator == OO_PlusPlus || Operator == OO_MinusMinus) |
| 156 | ? getBeginLoc() |
| 157 | : getOperatorLoc(); |
| 158 | } |
| 159 | |
| 160 | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
| 161 | SourceLocation getEndLoc() const { return Range.getEnd(); } |
| 162 | SourceRange getSourceRange() const { return Range; } |
| 163 | |
| 164 | static bool classof(const Stmt *T) { |
| 165 | return T->getStmtClass() == CXXOperatorCallExprClass; |
| 166 | } |
| 167 | }; |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | class CXXMemberCallExpr final : public CallExpr { |
| 178 | |
| 179 | |
| 180 | |
| 181 | CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty, |
| 182 | ExprValueKind VK, SourceLocation RP, |
| 183 | FPOptionsOverride FPOptions, unsigned MinNumArgs); |
| 184 | |
| 185 | CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
| 186 | |
| 187 | public: |
| 188 | static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn, |
| 189 | ArrayRef<Expr *> Args, QualType Ty, |
| 190 | ExprValueKind VK, SourceLocation RP, |
| 191 | FPOptionsOverride FPFeatures, |
| 192 | unsigned MinNumArgs = 0); |
| 193 | |
| 194 | static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, |
| 195 | bool HasFPFeatures, EmptyShell Empty); |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | Expr *getImplicitObjectArgument() const; |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | QualType getObjectType() const; |
| 206 | |
| 207 | |
| 208 | CXXMethodDecl *getMethodDecl() const; |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | CXXRecordDecl *getRecordDecl() const; |
| 217 | |
| 218 | SourceLocation getExprLoc() const LLVM_READONLY { |
| 219 | SourceLocation CLoc = getCallee()->getExprLoc(); |
| 220 | if (CLoc.isValid()) |
| 221 | return CLoc; |
| 222 | |
| 223 | return getBeginLoc(); |
| 224 | } |
| 225 | |
| 226 | static bool classof(const Stmt *T) { |
| 227 | return T->getStmtClass() == CXXMemberCallExprClass; |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | |
| 232 | class CUDAKernelCallExpr final : public CallExpr { |
| 233 | friend class ASTStmtReader; |
| 234 | |
| 235 | enum { CONFIG, END_PREARG }; |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args, |
| 241 | QualType Ty, ExprValueKind VK, SourceLocation RP, |
| 242 | FPOptionsOverride FPFeatures, unsigned MinNumArgs); |
| 243 | |
| 244 | CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
| 245 | |
| 246 | public: |
| 247 | static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn, |
| 248 | CallExpr *Config, ArrayRef<Expr *> Args, |
| 249 | QualType Ty, ExprValueKind VK, |
| 250 | SourceLocation RP, |
| 251 | FPOptionsOverride FPFeatures, |
| 252 | unsigned MinNumArgs = 0); |
| 253 | |
| 254 | static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx, |
| 255 | unsigned NumArgs, bool HasFPFeatures, |
| 256 | EmptyShell Empty); |
| 257 | |
| 258 | const CallExpr *getConfig() const { |
| 259 | return cast_or_null<CallExpr>(getPreArg(CONFIG)); |
| 260 | } |
| 261 | CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } |
| 262 | |
| 263 | static bool classof(const Stmt *T) { |
| 264 | return T->getStmtClass() == CUDAKernelCallExprClass; |
| 265 | } |
| 266 | }; |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | class CXXRewrittenBinaryOperator : public Expr { |
| 285 | friend class ASTStmtReader; |
| 286 | |
| 287 | |
| 288 | Stmt *SemanticForm; |
| 289 | |
| 290 | public: |
| 291 | CXXRewrittenBinaryOperator(Expr *SemanticForm, bool IsReversed) |
| 292 | : Expr(CXXRewrittenBinaryOperatorClass, SemanticForm->getType(), |
| 293 | SemanticForm->getValueKind(), SemanticForm->getObjectKind()), |
| 294 | SemanticForm(SemanticForm) { |
| 295 | CXXRewrittenBinaryOperatorBits.IsReversed = IsReversed; |
| 296 | setDependence(computeDependence(this)); |
| 297 | } |
| 298 | CXXRewrittenBinaryOperator(EmptyShell Empty) |
| 299 | : Expr(CXXRewrittenBinaryOperatorClass, Empty), SemanticForm() {} |
| 300 | |
| 301 | |
| 302 | Expr *getSemanticForm() { return cast<Expr>(SemanticForm); } |
| 303 | const Expr *getSemanticForm() const { return cast<Expr>(SemanticForm); } |
| 304 | |
| 305 | struct DecomposedForm { |
| 306 | |
| 307 | BinaryOperatorKind Opcode; |
| 308 | |
| 309 | const Expr *LHS; |
| 310 | |
| 311 | const Expr *RHS; |
| 312 | |
| 313 | const Expr *InnerBinOp; |
| 314 | }; |
| 315 | |
| 316 | |
| 317 | DecomposedForm getDecomposedForm() const LLVM_READONLY; |
| 318 | |
| 319 | |
| 320 | bool isReversed() const { return CXXRewrittenBinaryOperatorBits.IsReversed; } |
| 321 | |
| 322 | BinaryOperatorKind getOperator() const { return getDecomposedForm().Opcode; } |
| 323 | BinaryOperatorKind getOpcode() const { return getOperator(); } |
| 324 | static StringRef getOpcodeStr(BinaryOperatorKind Op) { |
| 325 | return BinaryOperator::getOpcodeStr(Op); |
| 326 | } |
| 327 | StringRef getOpcodeStr() const { |
| 328 | return BinaryOperator::getOpcodeStr(getOpcode()); |
| 329 | } |
| 330 | bool isComparisonOp() const { return true; } |
| 331 | bool isAssignmentOp() const { return false; } |
| 332 | |
| 333 | const Expr *getLHS() const { return getDecomposedForm().LHS; } |
| 334 | const Expr *getRHS() const { return getDecomposedForm().RHS; } |
| 335 | |
| 336 | SourceLocation getOperatorLoc() const LLVM_READONLY { |
| 337 | return getDecomposedForm().InnerBinOp->getExprLoc(); |
| 338 | } |
| 339 | SourceLocation getExprLoc() const LLVM_READONLY { return getOperatorLoc(); } |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 346 | return getDecomposedForm().LHS->getBeginLoc(); |
| 347 | } |
| 348 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 349 | return getDecomposedForm().RHS->getEndLoc(); |
| 350 | } |
| 351 | SourceRange getSourceRange() const LLVM_READONLY { |
| 352 | DecomposedForm DF = getDecomposedForm(); |
| 353 | return SourceRange(DF.LHS->getBeginLoc(), DF.RHS->getEndLoc()); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | child_range children() { |
| 358 | return child_range(&SemanticForm, &SemanticForm + 1); |
| 359 | } |
| 360 | |
| 361 | static bool classof(const Stmt *T) { |
| 362 | return T->getStmtClass() == CXXRewrittenBinaryOperatorClass; |
| 363 | } |
| 364 | }; |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | class CXXNamedCastExpr : public ExplicitCastExpr { |
| 374 | private: |
| 375 | |
| 376 | SourceLocation Loc; |
| 377 | |
| 378 | |
| 379 | SourceLocation RParenLoc; |
| 380 | |
| 381 | |
| 382 | SourceRange AngleBrackets; |
| 383 | |
| 384 | protected: |
| 385 | friend class ASTStmtReader; |
| 386 | |
| 387 | CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, CastKind kind, |
| 388 | Expr *op, unsigned PathSize, bool HasFPFeatures, |
| 389 | TypeSourceInfo *writtenTy, SourceLocation l, |
| 390 | SourceLocation RParenLoc, SourceRange AngleBrackets) |
| 391 | : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, HasFPFeatures, |
| 392 | writtenTy), |
| 393 | Loc(l), RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {} |
| 394 | |
| 395 | explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, |
| 396 | bool HasFPFeatures) |
| 397 | : ExplicitCastExpr(SC, Shell, PathSize, HasFPFeatures) {} |
| 398 | |
| 399 | public: |
| 400 | const char *getCastName() const; |
| 401 | |
| 402 | |
| 403 | |
| 404 | SourceLocation getOperatorLoc() const { return Loc; } |
| 405 | |
| 406 | |
| 407 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 408 | |
| 409 | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
| 410 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
| 411 | SourceRange getAngleBrackets() const LLVM_READONLY { return AngleBrackets; } |
| 412 | |
| 413 | static bool classof(const Stmt *T) { |
| 414 | switch (T->getStmtClass()) { |
| 415 | case CXXStaticCastExprClass: |
| 416 | case CXXDynamicCastExprClass: |
| 417 | case CXXReinterpretCastExprClass: |
| 418 | case CXXConstCastExprClass: |
| 419 | case CXXAddrspaceCastExprClass: |
| 420 | return true; |
| 421 | default: |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | }; |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | class CXXStaticCastExpr final |
| 432 | : public CXXNamedCastExpr, |
| 433 | private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *, |
| 434 | FPOptionsOverride> { |
| 435 | CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, |
| 436 | unsigned pathSize, TypeSourceInfo *writtenTy, |
| 437 | FPOptionsOverride FPO, SourceLocation l, |
| 438 | SourceLocation RParenLoc, SourceRange AngleBrackets) |
| 439 | : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, |
| 440 | FPO.requiresTrailingStorage(), writtenTy, l, RParenLoc, |
| 441 | AngleBrackets) { |
| 442 | if (hasStoredFPFeatures()) |
| 443 | *getTrailingFPFeatures() = FPO; |
| 444 | } |
| 445 | |
| 446 | explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize, |
| 447 | bool HasFPFeatures) |
| 448 | : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize, |
| 449 | HasFPFeatures) {} |
| 450 | |
| 451 | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { |
| 452 | return path_size(); |
| 453 | } |
| 454 | |
| 455 | public: |
| 456 | friend class CastExpr; |
| 457 | friend TrailingObjects; |
| 458 | |
| 459 | static CXXStaticCastExpr * |
| 460 | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, |
| 461 | Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, |
| 462 | FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, |
| 463 | SourceRange AngleBrackets); |
| 464 | static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context, |
| 465 | unsigned PathSize, bool hasFPFeatures); |
| 466 | |
| 467 | static bool classof(const Stmt *T) { |
| 468 | return T->getStmtClass() == CXXStaticCastExprClass; |
| 469 | } |
| 470 | }; |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | class CXXDynamicCastExpr final |
| 478 | : public CXXNamedCastExpr, |
| 479 | private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> { |
| 480 | CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, Expr *op, |
| 481 | unsigned pathSize, TypeSourceInfo *writtenTy, |
| 482 | SourceLocation l, SourceLocation RParenLoc, |
| 483 | SourceRange AngleBrackets) |
| 484 | : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, |
| 485 | false, writtenTy, l, RParenLoc, |
| 486 | AngleBrackets) {} |
| 487 | |
| 488 | explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) |
| 489 | : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize, |
| 490 | false) {} |
| 491 | |
| 492 | public: |
| 493 | friend class CastExpr; |
| 494 | friend TrailingObjects; |
| 495 | |
| 496 | static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T, |
| 497 | ExprValueKind VK, CastKind Kind, Expr *Op, |
| 498 | const CXXCastPath *Path, |
| 499 | TypeSourceInfo *Written, SourceLocation L, |
| 500 | SourceLocation RParenLoc, |
| 501 | SourceRange AngleBrackets); |
| 502 | |
| 503 | static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context, |
| 504 | unsigned pathSize); |
| 505 | |
| 506 | bool isAlwaysNull() const; |
| 507 | |
| 508 | static bool classof(const Stmt *T) { |
| 509 | return T->getStmtClass() == CXXDynamicCastExprClass; |
| 510 | } |
| 511 | }; |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | class CXXReinterpretCastExpr final |
| 522 | : public CXXNamedCastExpr, |
| 523 | private llvm::TrailingObjects<CXXReinterpretCastExpr, |
| 524 | CXXBaseSpecifier *> { |
| 525 | CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, |
| 526 | unsigned pathSize, TypeSourceInfo *writtenTy, |
| 527 | SourceLocation l, SourceLocation RParenLoc, |
| 528 | SourceRange AngleBrackets) |
| 529 | : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, |
| 530 | pathSize, false, writtenTy, l, |
| 531 | RParenLoc, AngleBrackets) {} |
| 532 | |
| 533 | CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) |
| 534 | : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize, |
| 535 | false) {} |
| 536 | |
| 537 | public: |
| 538 | friend class CastExpr; |
| 539 | friend TrailingObjects; |
| 540 | |
| 541 | static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T, |
| 542 | ExprValueKind VK, CastKind Kind, |
| 543 | Expr *Op, const CXXCastPath *Path, |
| 544 | TypeSourceInfo *WrittenTy, SourceLocation L, |
| 545 | SourceLocation RParenLoc, |
| 546 | SourceRange AngleBrackets); |
| 547 | static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context, |
| 548 | unsigned pathSize); |
| 549 | |
| 550 | static bool classof(const Stmt *T) { |
| 551 | return T->getStmtClass() == CXXReinterpretCastExprClass; |
| 552 | } |
| 553 | }; |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | class CXXConstCastExpr final |
| 563 | : public CXXNamedCastExpr, |
| 564 | private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> { |
| 565 | CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, |
| 566 | TypeSourceInfo *writtenTy, SourceLocation l, |
| 567 | SourceLocation RParenLoc, SourceRange AngleBrackets) |
| 568 | : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 0, |
| 569 | false, writtenTy, l, RParenLoc, |
| 570 | AngleBrackets) {} |
| 571 | |
| 572 | explicit CXXConstCastExpr(EmptyShell Empty) |
| 573 | : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0, |
| 574 | false) {} |
| 575 | |
| 576 | public: |
| 577 | friend class CastExpr; |
| 578 | friend TrailingObjects; |
| 579 | |
| 580 | static CXXConstCastExpr *Create(const ASTContext &Context, QualType T, |
| 581 | ExprValueKind VK, Expr *Op, |
| 582 | TypeSourceInfo *WrittenTy, SourceLocation L, |
| 583 | SourceLocation RParenLoc, |
| 584 | SourceRange AngleBrackets); |
| 585 | static CXXConstCastExpr *CreateEmpty(const ASTContext &Context); |
| 586 | |
| 587 | static bool classof(const Stmt *T) { |
| 588 | return T->getStmtClass() == CXXConstCastExprClass; |
| 589 | } |
| 590 | }; |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | class CXXAddrspaceCastExpr final |
| 601 | : public CXXNamedCastExpr, |
| 602 | private llvm::TrailingObjects<CXXAddrspaceCastExpr, CXXBaseSpecifier *> { |
| 603 | CXXAddrspaceCastExpr(QualType ty, ExprValueKind VK, CastKind Kind, Expr *op, |
| 604 | TypeSourceInfo *writtenTy, SourceLocation l, |
| 605 | SourceLocation RParenLoc, SourceRange AngleBrackets) |
| 606 | : CXXNamedCastExpr(CXXAddrspaceCastExprClass, ty, VK, Kind, op, 0, |
| 607 | false, writtenTy, l, RParenLoc, |
| 608 | AngleBrackets) {} |
| 609 | |
| 610 | explicit CXXAddrspaceCastExpr(EmptyShell Empty) |
| 611 | : CXXNamedCastExpr(CXXAddrspaceCastExprClass, Empty, 0, |
| 612 | false) {} |
| 613 | |
| 614 | public: |
| 615 | friend class CastExpr; |
| 616 | friend TrailingObjects; |
| 617 | |
| 618 | static CXXAddrspaceCastExpr * |
| 619 | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, |
| 620 | Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, |
| 621 | SourceLocation RParenLoc, SourceRange AngleBrackets); |
| 622 | static CXXAddrspaceCastExpr *CreateEmpty(const ASTContext &Context); |
| 623 | |
| 624 | static bool classof(const Stmt *T) { |
| 625 | return T->getStmtClass() == CXXAddrspaceCastExprClass; |
| 626 | } |
| 627 | }; |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | class UserDefinedLiteral final : public CallExpr { |
| 639 | friend class ASTStmtReader; |
| 640 | friend class ASTStmtWriter; |
| 641 | |
| 642 | |
| 643 | SourceLocation UDSuffixLoc; |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty, |
| 649 | ExprValueKind VK, SourceLocation LitEndLoc, |
| 650 | SourceLocation SuffixLoc, FPOptionsOverride FPFeatures); |
| 651 | |
| 652 | UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); |
| 653 | |
| 654 | public: |
| 655 | static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn, |
| 656 | ArrayRef<Expr *> Args, QualType Ty, |
| 657 | ExprValueKind VK, SourceLocation LitEndLoc, |
| 658 | SourceLocation SuffixLoc, |
| 659 | FPOptionsOverride FPFeatures); |
| 660 | |
| 661 | static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx, |
| 662 | unsigned NumArgs, bool HasFPOptions, |
| 663 | EmptyShell Empty); |
| 664 | |
| 665 | |
| 666 | enum LiteralOperatorKind { |
| 667 | |
| 668 | LOK_Raw, |
| 669 | |
| 670 | |
| 671 | LOK_Template, |
| 672 | |
| 673 | |
| 674 | LOK_Integer, |
| 675 | |
| 676 | |
| 677 | LOK_Floating, |
| 678 | |
| 679 | |
| 680 | LOK_String, |
| 681 | |
| 682 | |
| 683 | LOK_Character |
| 684 | }; |
| 685 | |
| 686 | |
| 687 | |
| 688 | LiteralOperatorKind getLiteralOperatorKind() const; |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | Expr *getCookedLiteral(); |
| 694 | const Expr *getCookedLiteral() const { |
| 695 | return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); |
| 696 | } |
| 697 | |
| 698 | SourceLocation getBeginLoc() const { |
| 699 | if (getLiteralOperatorKind() == LOK_Template) |
| 700 | return getRParenLoc(); |
| 701 | return getArg(0)->getBeginLoc(); |
| 702 | } |
| 703 | |
| 704 | SourceLocation getEndLoc() const { return getRParenLoc(); } |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } |
| 711 | |
| 712 | |
| 713 | const IdentifierInfo *getUDSuffix() const; |
| 714 | |
| 715 | static bool classof(const Stmt *S) { |
| 716 | return S->getStmtClass() == UserDefinedLiteralClass; |
| 717 | } |
| 718 | }; |
| 719 | |
| 720 | |
| 721 | class CXXBoolLiteralExpr : public Expr { |
| 722 | public: |
| 723 | CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc) |
| 724 | : Expr(CXXBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { |
| 725 | CXXBoolLiteralExprBits.Value = Val; |
| 726 | CXXBoolLiteralExprBits.Loc = Loc; |
| 727 | setDependence(ExprDependence::None); |
| 728 | } |
| 729 | |
| 730 | explicit CXXBoolLiteralExpr(EmptyShell Empty) |
| 731 | : Expr(CXXBoolLiteralExprClass, Empty) {} |
| 732 | |
| 733 | bool getValue() const { return CXXBoolLiteralExprBits.Value; } |
| 734 | void setValue(bool V) { CXXBoolLiteralExprBits.Value = V; } |
| 735 | |
| 736 | SourceLocation getBeginLoc() const { return getLocation(); } |
| 737 | SourceLocation getEndLoc() const { return getLocation(); } |
| 738 | |
| 739 | SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; } |
| 740 | void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; } |
| 741 | |
| 742 | static bool classof(const Stmt *T) { |
| 743 | return T->getStmtClass() == CXXBoolLiteralExprClass; |
| 744 | } |
| 745 | |
| 746 | |
| 747 | child_range children() { |
| 748 | return child_range(child_iterator(), child_iterator()); |
| 749 | } |
| 750 | |
| 751 | const_child_range children() const { |
| 752 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 753 | } |
| 754 | }; |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | class CXXNullPtrLiteralExpr : public Expr { |
| 760 | public: |
| 761 | CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc) |
| 762 | : Expr(CXXNullPtrLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { |
| 763 | CXXNullPtrLiteralExprBits.Loc = Loc; |
| 764 | setDependence(ExprDependence::None); |
| 765 | } |
| 766 | |
| 767 | explicit CXXNullPtrLiteralExpr(EmptyShell Empty) |
| 768 | : Expr(CXXNullPtrLiteralExprClass, Empty) {} |
| 769 | |
| 770 | SourceLocation getBeginLoc() const { return getLocation(); } |
| 771 | SourceLocation getEndLoc() const { return getLocation(); } |
| 772 | |
| 773 | SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; } |
| 774 | void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; } |
| 775 | |
| 776 | static bool classof(const Stmt *T) { |
| 777 | return T->getStmtClass() == CXXNullPtrLiteralExprClass; |
| 778 | } |
| 779 | |
| 780 | child_range children() { |
| 781 | return child_range(child_iterator(), child_iterator()); |
| 782 | } |
| 783 | |
| 784 | const_child_range children() const { |
| 785 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 786 | } |
| 787 | }; |
| 788 | |
| 789 | |
| 790 | |
| 791 | class CXXStdInitializerListExpr : public Expr { |
| 792 | Stmt *SubExpr = nullptr; |
| 793 | |
| 794 | CXXStdInitializerListExpr(EmptyShell Empty) |
| 795 | : Expr(CXXStdInitializerListExprClass, Empty) {} |
| 796 | |
| 797 | public: |
| 798 | friend class ASTReader; |
| 799 | friend class ASTStmtReader; |
| 800 | |
| 801 | CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr) |
| 802 | : Expr(CXXStdInitializerListExprClass, Ty, VK_PRValue, OK_Ordinary), |
| 803 | SubExpr(SubExpr) { |
| 804 | setDependence(computeDependence(this)); |
| 805 | } |
| 806 | |
| 807 | Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); } |
| 808 | const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); } |
| 809 | |
| 810 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 811 | return SubExpr->getBeginLoc(); |
| 812 | } |
| 813 | |
| 814 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 815 | return SubExpr->getEndLoc(); |
| 816 | } |
| 817 | |
| 818 | |
| 819 | SourceRange getSourceRange() const LLVM_READONLY { |
| 820 | return SubExpr->getSourceRange(); |
| 821 | } |
| 822 | |
| 823 | static bool classof(const Stmt *S) { |
| 824 | return S->getStmtClass() == CXXStdInitializerListExprClass; |
| 825 | } |
| 826 | |
| 827 | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } |
| 828 | |
| 829 | const_child_range children() const { |
| 830 | return const_child_range(&SubExpr, &SubExpr + 1); |
| 831 | } |
| 832 | }; |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | class CXXTypeidExpr : public Expr { |
| 840 | friend class ASTStmtReader; |
| 841 | |
| 842 | private: |
| 843 | llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; |
| 844 | SourceRange Range; |
| 845 | |
| 846 | public: |
| 847 | CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) |
| 848 | : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
| 849 | Range(R) { |
| 850 | setDependence(computeDependence(this)); |
| 851 | } |
| 852 | |
| 853 | CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) |
| 854 | : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
| 855 | Range(R) { |
| 856 | setDependence(computeDependence(this)); |
| 857 | } |
| 858 | |
| 859 | CXXTypeidExpr(EmptyShell Empty, bool isExpr) |
| 860 | : Expr(CXXTypeidExprClass, Empty) { |
| 861 | if (isExpr) |
| 862 | Operand = (Expr*)nullptr; |
| 863 | else |
| 864 | Operand = (TypeSourceInfo*)nullptr; |
| 865 | } |
| 866 | |
| 867 | |
| 868 | |
| 869 | bool isPotentiallyEvaluated() const; |
| 870 | |
| 871 | |
| 872 | |
| 873 | bool isMostDerived(ASTContext &Context) const; |
| 874 | |
| 875 | bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } |
| 876 | |
| 877 | |
| 878 | |
| 879 | QualType getTypeOperand(ASTContext &Context) const; |
| 880 | |
| 881 | |
| 882 | TypeSourceInfo *getTypeOperandSourceInfo() const { |
| 883 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); |
| 884 | return Operand.get<TypeSourceInfo *>(); |
| 885 | } |
| 886 | Expr *getExprOperand() const { |
| 887 | assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); |
| 888 | return static_cast<Expr*>(Operand.get<Stmt *>()); |
| 889 | } |
| 890 | |
| 891 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
| 892 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
| 893 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
| 894 | void setSourceRange(SourceRange R) { Range = R; } |
| 895 | |
| 896 | static bool classof(const Stmt *T) { |
| 897 | return T->getStmtClass() == CXXTypeidExprClass; |
| 898 | } |
| 899 | |
| 900 | |
| 901 | child_range children() { |
| 902 | if (isTypeOperand()) |
| 903 | return child_range(child_iterator(), child_iterator()); |
| 904 | auto **begin = reinterpret_cast<Stmt **>(&Operand); |
| 905 | return child_range(begin, begin + 1); |
| 906 | } |
| 907 | |
| 908 | const_child_range children() const { |
| 909 | if (isTypeOperand()) |
| 910 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 911 | |
| 912 | auto **begin = |
| 913 | reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand); |
| 914 | return const_child_range(begin, begin + 1); |
| 915 | } |
| 916 | }; |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | class MSPropertyRefExpr : public Expr { |
| 924 | Expr *BaseExpr; |
| 925 | MSPropertyDecl *TheDecl; |
| 926 | SourceLocation MemberLoc; |
| 927 | bool IsArrow; |
| 928 | NestedNameSpecifierLoc QualifierLoc; |
| 929 | |
| 930 | public: |
| 931 | friend class ASTStmtReader; |
| 932 | |
| 933 | MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow, |
| 934 | QualType ty, ExprValueKind VK, |
| 935 | NestedNameSpecifierLoc qualifierLoc, SourceLocation nameLoc) |
| 936 | : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary), BaseExpr(baseExpr), |
| 937 | TheDecl(decl), MemberLoc(nameLoc), IsArrow(isArrow), |
| 938 | QualifierLoc(qualifierLoc) { |
| 939 | setDependence(computeDependence(this)); |
| 940 | } |
| 941 | |
| 942 | MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {} |
| 943 | |
| 944 | SourceRange getSourceRange() const LLVM_READONLY { |
| 945 | return SourceRange(getBeginLoc(), getEndLoc()); |
| 946 | } |
| 947 | |
| 948 | bool isImplicitAccess() const { |
| 949 | return getBaseExpr() && getBaseExpr()->isImplicitCXXThis(); |
| 950 | } |
| 951 | |
| 952 | SourceLocation getBeginLoc() const { |
| 953 | if (!isImplicitAccess()) |
| 954 | return BaseExpr->getBeginLoc(); |
| 955 | else if (QualifierLoc) |
| 956 | return QualifierLoc.getBeginLoc(); |
| 957 | else |
| 958 | return MemberLoc; |
| 959 | } |
| 960 | |
| 961 | SourceLocation getEndLoc() const { return getMemberLoc(); } |
| 962 | |
| 963 | child_range children() { |
| 964 | return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); |
| 965 | } |
| 966 | |
| 967 | const_child_range children() const { |
| 968 | auto Children = const_cast<MSPropertyRefExpr *>(this)->children(); |
| 969 | return const_child_range(Children.begin(), Children.end()); |
| 970 | } |
| 971 | |
| 972 | static bool classof(const Stmt *T) { |
| 973 | return T->getStmtClass() == MSPropertyRefExprClass; |
| 974 | } |
| 975 | |
| 976 | Expr *getBaseExpr() const { return BaseExpr; } |
| 977 | MSPropertyDecl *getPropertyDecl() const { return TheDecl; } |
| 978 | bool isArrow() const { return IsArrow; } |
| 979 | SourceLocation getMemberLoc() const { return MemberLoc; } |
| 980 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 981 | }; |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | class MSPropertySubscriptExpr : public Expr { |
| 995 | friend class ASTStmtReader; |
| 996 | |
| 997 | enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 }; |
| 998 | |
| 999 | Stmt *SubExprs[NUM_SUBEXPRS]; |
| 1000 | SourceLocation RBracketLoc; |
| 1001 | |
| 1002 | void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; } |
| 1003 | void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; } |
| 1004 | |
| 1005 | public: |
| 1006 | MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK, |
| 1007 | ExprObjectKind OK, SourceLocation RBracketLoc) |
| 1008 | : Expr(MSPropertySubscriptExprClass, Ty, VK, OK), |
| 1009 | RBracketLoc(RBracketLoc) { |
| 1010 | SubExprs[BASE_EXPR] = Base; |
| 1011 | SubExprs[IDX_EXPR] = Idx; |
| 1012 | setDependence(computeDependence(this)); |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | explicit MSPropertySubscriptExpr(EmptyShell Shell) |
| 1017 | : Expr(MSPropertySubscriptExprClass, Shell) {} |
| 1018 | |
| 1019 | Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); } |
| 1020 | const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); } |
| 1021 | |
| 1022 | Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); } |
| 1023 | const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); } |
| 1024 | |
| 1025 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 1026 | return getBase()->getBeginLoc(); |
| 1027 | } |
| 1028 | |
| 1029 | SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; } |
| 1030 | |
| 1031 | SourceLocation getRBracketLoc() const { return RBracketLoc; } |
| 1032 | void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } |
| 1033 | |
| 1034 | SourceLocation getExprLoc() const LLVM_READONLY { |
| 1035 | return getBase()->getExprLoc(); |
| 1036 | } |
| 1037 | |
| 1038 | static bool classof(const Stmt *T) { |
| 1039 | return T->getStmtClass() == MSPropertySubscriptExprClass; |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | child_range children() { |
| 1044 | return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); |
| 1045 | } |
| 1046 | |
| 1047 | const_child_range children() const { |
| 1048 | return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); |
| 1049 | } |
| 1050 | }; |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | class CXXUuidofExpr : public Expr { |
| 1057 | friend class ASTStmtReader; |
| 1058 | |
| 1059 | private: |
| 1060 | llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; |
| 1061 | MSGuidDecl *Guid; |
| 1062 | SourceRange Range; |
| 1063 | |
| 1064 | public: |
| 1065 | CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, MSGuidDecl *Guid, |
| 1066 | SourceRange R) |
| 1067 | : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
| 1068 | Guid(Guid), Range(R) { |
| 1069 | setDependence(computeDependence(this)); |
| 1070 | } |
| 1071 | |
| 1072 | CXXUuidofExpr(QualType Ty, Expr *Operand, MSGuidDecl *Guid, SourceRange R) |
| 1073 | : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), |
| 1074 | Guid(Guid), Range(R) { |
| 1075 | setDependence(computeDependence(this)); |
| 1076 | } |
| 1077 | |
| 1078 | CXXUuidofExpr(EmptyShell Empty, bool isExpr) |
| 1079 | : Expr(CXXUuidofExprClass, Empty) { |
| 1080 | if (isExpr) |
| 1081 | Operand = (Expr*)nullptr; |
| 1082 | else |
| 1083 | Operand = (TypeSourceInfo*)nullptr; |
| 1084 | } |
| 1085 | |
| 1086 | bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | QualType getTypeOperand(ASTContext &Context) const; |
| 1091 | |
| 1092 | |
| 1093 | TypeSourceInfo *getTypeOperandSourceInfo() const { |
| 1094 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)"); |
| 1095 | return Operand.get<TypeSourceInfo *>(); |
| 1096 | } |
| 1097 | Expr *getExprOperand() const { |
| 1098 | assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)"); |
| 1099 | return static_cast<Expr*>(Operand.get<Stmt *>()); |
| 1100 | } |
| 1101 | |
| 1102 | MSGuidDecl *getGuidDecl() const { return Guid; } |
| 1103 | |
| 1104 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
| 1105 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
| 1106 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
| 1107 | void setSourceRange(SourceRange R) { Range = R; } |
| 1108 | |
| 1109 | static bool classof(const Stmt *T) { |
| 1110 | return T->getStmtClass() == CXXUuidofExprClass; |
| 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | child_range children() { |
| 1115 | if (isTypeOperand()) |
| 1116 | return child_range(child_iterator(), child_iterator()); |
| 1117 | auto **begin = reinterpret_cast<Stmt **>(&Operand); |
| 1118 | return child_range(begin, begin + 1); |
| 1119 | } |
| 1120 | |
| 1121 | const_child_range children() const { |
| 1122 | if (isTypeOperand()) |
| 1123 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 1124 | auto **begin = |
| 1125 | reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand); |
| 1126 | return const_child_range(begin, begin + 1); |
| 1127 | } |
| 1128 | }; |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | class CXXThisExpr : public Expr { |
| 1143 | public: |
| 1144 | CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit) |
| 1145 | : Expr(CXXThisExprClass, Ty, VK_PRValue, OK_Ordinary) { |
| 1146 | CXXThisExprBits.IsImplicit = IsImplicit; |
| 1147 | CXXThisExprBits.Loc = L; |
| 1148 | setDependence(computeDependence(this)); |
| 1149 | } |
| 1150 | |
| 1151 | CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} |
| 1152 | |
| 1153 | SourceLocation getLocation() const { return CXXThisExprBits.Loc; } |
| 1154 | void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; } |
| 1155 | |
| 1156 | SourceLocation getBeginLoc() const { return getLocation(); } |
| 1157 | SourceLocation getEndLoc() const { return getLocation(); } |
| 1158 | |
| 1159 | bool isImplicit() const { return CXXThisExprBits.IsImplicit; } |
| 1160 | void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; } |
| 1161 | |
| 1162 | static bool classof(const Stmt *T) { |
| 1163 | return T->getStmtClass() == CXXThisExprClass; |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | child_range children() { |
| 1168 | return child_range(child_iterator(), child_iterator()); |
| 1169 | } |
| 1170 | |
| 1171 | const_child_range children() const { |
| 1172 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 1173 | } |
| 1174 | }; |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | class CXXThrowExpr : public Expr { |
| 1182 | friend class ASTStmtReader; |
| 1183 | |
| 1184 | |
| 1185 | Stmt *Operand; |
| 1186 | |
| 1187 | public: |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc, |
| 1193 | bool IsThrownVariableInScope) |
| 1194 | : Expr(CXXThrowExprClass, Ty, VK_PRValue, OK_Ordinary), Operand(Operand) { |
| 1195 | CXXThrowExprBits.ThrowLoc = Loc; |
| 1196 | CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope; |
| 1197 | setDependence(computeDependence(this)); |
| 1198 | } |
| 1199 | CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} |
| 1200 | |
| 1201 | const Expr *getSubExpr() const { return cast_or_null<Expr>(Operand); } |
| 1202 | Expr *getSubExpr() { return cast_or_null<Expr>(Operand); } |
| 1203 | |
| 1204 | SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; } |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | bool isThrownVariableInScope() const { |
| 1212 | return CXXThrowExprBits.IsThrownVariableInScope; |
| 1213 | } |
| 1214 | |
| 1215 | SourceLocation getBeginLoc() const { return getThrowLoc(); } |
| 1216 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 1217 | if (!getSubExpr()) |
| 1218 | return getThrowLoc(); |
| 1219 | return getSubExpr()->getEndLoc(); |
| 1220 | } |
| 1221 | |
| 1222 | static bool classof(const Stmt *T) { |
| 1223 | return T->getStmtClass() == CXXThrowExprClass; |
| 1224 | } |
| 1225 | |
| 1226 | |
| 1227 | child_range children() { |
| 1228 | return child_range(&Operand, Operand ? &Operand + 1 : &Operand); |
| 1229 | } |
| 1230 | |
| 1231 | const_child_range children() const { |
| 1232 | return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand); |
| 1233 | } |
| 1234 | }; |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | class CXXDefaultArgExpr final : public Expr { |
| 1242 | friend class ASTStmtReader; |
| 1243 | |
| 1244 | |
| 1245 | ParmVarDecl *Param; |
| 1246 | |
| 1247 | |
| 1248 | DeclContext *UsedContext; |
| 1249 | |
| 1250 | CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param, |
| 1251 | DeclContext *UsedContext) |
| 1252 | : Expr(SC, |
| 1253 | Param->hasUnparsedDefaultArg() |
| 1254 | ? Param->getType().getNonReferenceType() |
| 1255 | : Param->getDefaultArg()->getType(), |
| 1256 | Param->getDefaultArg()->getValueKind(), |
| 1257 | Param->getDefaultArg()->getObjectKind()), |
| 1258 | Param(Param), UsedContext(UsedContext) { |
| 1259 | CXXDefaultArgExprBits.Loc = Loc; |
| 1260 | setDependence(computeDependence(this)); |
| 1261 | } |
| 1262 | |
| 1263 | public: |
| 1264 | CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {} |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, |
| 1269 | ParmVarDecl *Param, |
| 1270 | DeclContext *UsedContext) { |
| 1271 | return new (C) |
| 1272 | CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext); |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | const ParmVarDecl *getParam() const { return Param; } |
| 1277 | ParmVarDecl *getParam() { return Param; } |
| 1278 | |
| 1279 | |
| 1280 | const Expr *getExpr() const { return getParam()->getDefaultArg(); } |
| 1281 | Expr *getExpr() { return getParam()->getDefaultArg(); } |
| 1282 | |
| 1283 | const DeclContext *getUsedContext() const { return UsedContext; } |
| 1284 | DeclContext *getUsedContext() { return UsedContext; } |
| 1285 | |
| 1286 | |
| 1287 | SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; } |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | SourceLocation getBeginLoc() const { return SourceLocation(); } |
| 1292 | SourceLocation getEndLoc() const { return SourceLocation(); } |
| 1293 | |
| 1294 | SourceLocation getExprLoc() const { return getUsedLocation(); } |
| 1295 | |
| 1296 | static bool classof(const Stmt *T) { |
| 1297 | return T->getStmtClass() == CXXDefaultArgExprClass; |
| 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | child_range children() { |
| 1302 | return child_range(child_iterator(), child_iterator()); |
| 1303 | } |
| 1304 | |
| 1305 | const_child_range children() const { |
| 1306 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 1307 | } |
| 1308 | }; |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | class CXXDefaultInitExpr : public Expr { |
| 1319 | friend class ASTReader; |
| 1320 | friend class ASTStmtReader; |
| 1321 | |
| 1322 | |
| 1323 | FieldDecl *Field; |
| 1324 | |
| 1325 | |
| 1326 | DeclContext *UsedContext; |
| 1327 | |
| 1328 | CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, |
| 1329 | FieldDecl *Field, QualType Ty, DeclContext *UsedContext); |
| 1330 | |
| 1331 | CXXDefaultInitExpr(EmptyShell Empty) : Expr(CXXDefaultInitExprClass, Empty) {} |
| 1332 | |
| 1333 | public: |
| 1334 | |
| 1335 | |
| 1336 | static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc, |
| 1337 | FieldDecl *Field, DeclContext *UsedContext) { |
| 1338 | return new (Ctx) CXXDefaultInitExpr(Ctx, Loc, Field, Field->getType(), UsedContext); |
| 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | FieldDecl *getField() { return Field; } |
| 1343 | const FieldDecl *getField() const { return Field; } |
| 1344 | |
| 1345 | |
| 1346 | const Expr *getExpr() const { |
| 1347 | assert(Field->getInClassInitializer() && "initializer hasn't been parsed"); |
| 1348 | return Field->getInClassInitializer(); |
| 1349 | } |
| 1350 | Expr *getExpr() { |
| 1351 | assert(Field->getInClassInitializer() && "initializer hasn't been parsed"); |
| 1352 | return Field->getInClassInitializer(); |
| 1353 | } |
| 1354 | |
| 1355 | const DeclContext *getUsedContext() const { return UsedContext; } |
| 1356 | DeclContext *getUsedContext() { return UsedContext; } |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | SourceLocation getUsedLocation() const { return getBeginLoc(); } |
| 1361 | |
| 1362 | SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; } |
| 1363 | SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; } |
| 1364 | |
| 1365 | static bool classof(const Stmt *T) { |
| 1366 | return T->getStmtClass() == CXXDefaultInitExprClass; |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | child_range children() { |
| 1371 | return child_range(child_iterator(), child_iterator()); |
| 1372 | } |
| 1373 | |
| 1374 | const_child_range children() const { |
| 1375 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 1376 | } |
| 1377 | }; |
| 1378 | |
| 1379 | |
| 1380 | class CXXTemporary { |
| 1381 | |
| 1382 | const CXXDestructorDecl *Destructor; |
| 1383 | |
| 1384 | explicit CXXTemporary(const CXXDestructorDecl *destructor) |
| 1385 | : Destructor(destructor) {} |
| 1386 | |
| 1387 | public: |
| 1388 | static CXXTemporary *Create(const ASTContext &C, |
| 1389 | const CXXDestructorDecl *Destructor); |
| 1390 | |
| 1391 | const CXXDestructorDecl *getDestructor() const { return Destructor; } |
| 1392 | |
| 1393 | void setDestructor(const CXXDestructorDecl *Dtor) { |
| 1394 | Destructor = Dtor; |
| 1395 | } |
| 1396 | }; |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | class CXXBindTemporaryExpr : public Expr { |
| 1413 | CXXTemporary *Temp = nullptr; |
| 1414 | Stmt *SubExpr = nullptr; |
| 1415 | |
| 1416 | CXXBindTemporaryExpr(CXXTemporary *temp, Expr *SubExpr) |
| 1417 | : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), VK_PRValue, |
| 1418 | OK_Ordinary), |
| 1419 | Temp(temp), SubExpr(SubExpr) { |
| 1420 | setDependence(computeDependence(this)); |
| 1421 | } |
| 1422 | |
| 1423 | public: |
| 1424 | CXXBindTemporaryExpr(EmptyShell Empty) |
| 1425 | : Expr(CXXBindTemporaryExprClass, Empty) {} |
| 1426 | |
| 1427 | static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp, |
| 1428 | Expr* SubExpr); |
| 1429 | |
| 1430 | CXXTemporary *getTemporary() { return Temp; } |
| 1431 | const CXXTemporary *getTemporary() const { return Temp; } |
| 1432 | void setTemporary(CXXTemporary *T) { Temp = T; } |
| 1433 | |
| 1434 | const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } |
| 1435 | Expr *getSubExpr() { return cast<Expr>(SubExpr); } |
| 1436 | void setSubExpr(Expr *E) { SubExpr = E; } |
| 1437 | |
| 1438 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 1439 | return SubExpr->getBeginLoc(); |
| 1440 | } |
| 1441 | |
| 1442 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 1443 | return SubExpr->getEndLoc(); |
| 1444 | } |
| 1445 | |
| 1446 | |
| 1447 | static bool classof(const Stmt *T) { |
| 1448 | return T->getStmtClass() == CXXBindTemporaryExprClass; |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } |
| 1453 | |
| 1454 | const_child_range children() const { |
| 1455 | return const_child_range(&SubExpr, &SubExpr + 1); |
| 1456 | } |
| 1457 | }; |
| 1458 | |
| 1459 | |
| 1460 | class CXXConstructExpr : public Expr { |
| 1461 | friend class ASTStmtReader; |
| 1462 | |
| 1463 | public: |
| 1464 | enum ConstructionKind { |
| 1465 | CK_Complete, |
| 1466 | CK_NonVirtualBase, |
| 1467 | CK_VirtualBase, |
| 1468 | CK_Delegating |
| 1469 | }; |
| 1470 | |
| 1471 | private: |
| 1472 | |
| 1473 | CXXConstructorDecl *Constructor; |
| 1474 | |
| 1475 | SourceRange ParenOrBraceRange; |
| 1476 | |
| 1477 | |
| 1478 | unsigned NumArgs; |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | inline Stmt **getTrailingArgs(); |
| 1497 | const Stmt *const *getTrailingArgs() const { |
| 1498 | return const_cast<CXXConstructExpr *>(this)->getTrailingArgs(); |
| 1499 | } |
| 1500 | |
| 1501 | protected: |
| 1502 | |
| 1503 | CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc, |
| 1504 | CXXConstructorDecl *Ctor, bool Elidable, |
| 1505 | ArrayRef<Expr *> Args, bool HadMultipleCandidates, |
| 1506 | bool ListInitialization, bool StdInitListInitialization, |
| 1507 | bool ZeroInitialization, ConstructionKind ConstructKind, |
| 1508 | SourceRange ParenOrBraceRange); |
| 1509 | |
| 1510 | |
| 1511 | CXXConstructExpr(StmtClass SC, EmptyShell Empty, unsigned NumArgs); |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | static unsigned sizeOfTrailingObjects(unsigned NumArgs) { |
| 1516 | return NumArgs * sizeof(Stmt *); |
| 1517 | } |
| 1518 | |
| 1519 | public: |
| 1520 | |
| 1521 | static CXXConstructExpr * |
| 1522 | Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, |
| 1523 | CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, |
| 1524 | bool HadMultipleCandidates, bool ListInitialization, |
| 1525 | bool StdInitListInitialization, bool ZeroInitialization, |
| 1526 | ConstructionKind ConstructKind, SourceRange ParenOrBraceRange); |
| 1527 | |
| 1528 | |
| 1529 | static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs); |
| 1530 | |
| 1531 | |
| 1532 | CXXConstructorDecl *getConstructor() const { return Constructor; } |
| 1533 | |
| 1534 | SourceLocation getLocation() const { return CXXConstructExprBits.Loc; } |
| 1535 | void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; } |
| 1536 | |
| 1537 | |
| 1538 | bool isElidable() const { return CXXConstructExprBits.Elidable; } |
| 1539 | void setElidable(bool E) { CXXConstructExprBits.Elidable = E; } |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | bool hadMultipleCandidates() const { |
| 1544 | return CXXConstructExprBits.HadMultipleCandidates; |
| 1545 | } |
| 1546 | void setHadMultipleCandidates(bool V) { |
| 1547 | CXXConstructExprBits.HadMultipleCandidates = V; |
| 1548 | } |
| 1549 | |
| 1550 | |
| 1551 | bool isListInitialization() const { |
| 1552 | return CXXConstructExprBits.ListInitialization; |
| 1553 | } |
| 1554 | void setListInitialization(bool V) { |
| 1555 | CXXConstructExprBits.ListInitialization = V; |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | bool isStdInitListInitialization() const { |
| 1563 | return CXXConstructExprBits.StdInitListInitialization; |
| 1564 | } |
| 1565 | void setStdInitListInitialization(bool V) { |
| 1566 | CXXConstructExprBits.StdInitListInitialization = V; |
| 1567 | } |
| 1568 | |
| 1569 | |
| 1570 | |
| 1571 | bool requiresZeroInitialization() const { |
| 1572 | return CXXConstructExprBits.ZeroInitialization; |
| 1573 | } |
| 1574 | void setRequiresZeroInitialization(bool ZeroInit) { |
| 1575 | CXXConstructExprBits.ZeroInitialization = ZeroInit; |
| 1576 | } |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | ConstructionKind getConstructionKind() const { |
| 1581 | return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind); |
| 1582 | } |
| 1583 | void setConstructionKind(ConstructionKind CK) { |
| 1584 | CXXConstructExprBits.ConstructionKind = CK; |
| 1585 | } |
| 1586 | |
| 1587 | using arg_iterator = ExprIterator; |
| 1588 | using const_arg_iterator = ConstExprIterator; |
| 1589 | using arg_range = llvm::iterator_range<arg_iterator>; |
| 1590 | using const_arg_range = llvm::iterator_range<const_arg_iterator>; |
| 1591 | |
| 1592 | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } |
| 1593 | const_arg_range arguments() const { |
| 1594 | return const_arg_range(arg_begin(), arg_end()); |
| 1595 | } |
| 1596 | |
| 1597 | arg_iterator arg_begin() { return getTrailingArgs(); } |
| 1598 | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } |
| 1599 | const_arg_iterator arg_begin() const { return getTrailingArgs(); } |
| 1600 | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } |
| 1601 | |
| 1602 | Expr **getArgs() { return reinterpret_cast<Expr **>(getTrailingArgs()); } |
| 1603 | const Expr *const *getArgs() const { |
| 1604 | return reinterpret_cast<const Expr *const *>(getTrailingArgs()); |
| 1605 | } |
| 1606 | |
| 1607 | |
| 1608 | unsigned getNumArgs() const { return NumArgs; } |
| 1609 | |
| 1610 | |
| 1611 | Expr *getArg(unsigned Arg) { |
| 1612 | assert(Arg < getNumArgs() && "Arg access out of range!"); |
| 1613 | return getArgs()[Arg]; |
| 1614 | } |
| 1615 | const Expr *getArg(unsigned Arg) const { |
| 1616 | assert(Arg < getNumArgs() && "Arg access out of range!"); |
| 1617 | return getArgs()[Arg]; |
| 1618 | } |
| 1619 | |
| 1620 | |
| 1621 | void setArg(unsigned Arg, Expr *ArgExpr) { |
| 1622 | assert(Arg < getNumArgs() && "Arg access out of range!"); |
| 1623 | getArgs()[Arg] = ArgExpr; |
| 1624 | } |
| 1625 | |
| 1626 | SourceLocation getBeginLoc() const LLVM_READONLY; |
| 1627 | SourceLocation getEndLoc() const LLVM_READONLY; |
| 1628 | SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; } |
| 1629 | void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; } |
| 1630 | |
| 1631 | static bool classof(const Stmt *T) { |
| 1632 | return T->getStmtClass() == CXXConstructExprClass || |
| 1633 | T->getStmtClass() == CXXTemporaryObjectExprClass; |
| 1634 | } |
| 1635 | |
| 1636 | |
| 1637 | child_range children() { |
| 1638 | return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs()); |
| 1639 | } |
| 1640 | |
| 1641 | const_child_range children() const { |
| 1642 | auto Children = const_cast<CXXConstructExpr *>(this)->children(); |
| 1643 | return const_child_range(Children.begin(), Children.end()); |
| 1644 | } |
| 1645 | }; |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | class CXXInheritedCtorInitExpr : public Expr { |
| 1652 | private: |
| 1653 | CXXConstructorDecl *Constructor = nullptr; |
| 1654 | |
| 1655 | |
| 1656 | SourceLocation Loc; |
| 1657 | |
| 1658 | |
| 1659 | unsigned ConstructsVirtualBase : 1; |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | unsigned InheritedFromVirtualBase : 1; |
| 1664 | |
| 1665 | public: |
| 1666 | friend class ASTStmtReader; |
| 1667 | |
| 1668 | |
| 1669 | CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T, |
| 1670 | CXXConstructorDecl *Ctor, bool ConstructsVirtualBase, |
| 1671 | bool InheritedFromVirtualBase) |
| 1672 | : Expr(CXXInheritedCtorInitExprClass, T, VK_PRValue, OK_Ordinary), |
| 1673 | Constructor(Ctor), Loc(Loc), |
| 1674 | ConstructsVirtualBase(ConstructsVirtualBase), |
| 1675 | InheritedFromVirtualBase(InheritedFromVirtualBase) { |
| 1676 | assert(!T->isDependentType()); |
| 1677 | setDependence(ExprDependence::None); |
| 1678 | } |
| 1679 | |
| 1680 | |
| 1681 | explicit CXXInheritedCtorInitExpr(EmptyShell Empty) |
| 1682 | : Expr(CXXInheritedCtorInitExprClass, Empty), |
| 1683 | ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {} |
| 1684 | |
| 1685 | |
| 1686 | CXXConstructorDecl *getConstructor() const { return Constructor; } |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | bool constructsVBase() const { return ConstructsVirtualBase; } |
| 1691 | CXXConstructExpr::ConstructionKind getConstructionKind() const { |
| 1692 | return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase |
| 1693 | : CXXConstructExpr::CK_NonVirtualBase; |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | bool inheritedFromVBase() const { return InheritedFromVirtualBase; } |
| 1701 | |
| 1702 | SourceLocation getLocation() const LLVM_READONLY { return Loc; } |
| 1703 | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
| 1704 | SourceLocation getEndLoc() const LLVM_READONLY { return Loc; } |
| 1705 | |
| 1706 | static bool classof(const Stmt *T) { |
| 1707 | return T->getStmtClass() == CXXInheritedCtorInitExprClass; |
| 1708 | } |
| 1709 | |
| 1710 | child_range children() { |
| 1711 | return child_range(child_iterator(), child_iterator()); |
| 1712 | } |
| 1713 | |
| 1714 | const_child_range children() const { |
| 1715 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 1716 | } |
| 1717 | }; |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | class CXXFunctionalCastExpr final |
| 1727 | : public ExplicitCastExpr, |
| 1728 | private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *, |
| 1729 | FPOptionsOverride> { |
| 1730 | SourceLocation LParenLoc; |
| 1731 | SourceLocation RParenLoc; |
| 1732 | |
| 1733 | CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, |
| 1734 | TypeSourceInfo *writtenTy, CastKind kind, |
| 1735 | Expr *castExpr, unsigned pathSize, |
| 1736 | FPOptionsOverride FPO, SourceLocation lParenLoc, |
| 1737 | SourceLocation rParenLoc) |
| 1738 | : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, castExpr, |
| 1739 | pathSize, FPO.requiresTrailingStorage(), writtenTy), |
| 1740 | LParenLoc(lParenLoc), RParenLoc(rParenLoc) { |
| 1741 | if (hasStoredFPFeatures()) |
| 1742 | *getTrailingFPFeatures() = FPO; |
| 1743 | } |
| 1744 | |
| 1745 | explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize, |
| 1746 | bool HasFPFeatures) |
| 1747 | : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize, |
| 1748 | HasFPFeatures) {} |
| 1749 | |
| 1750 | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { |
| 1751 | return path_size(); |
| 1752 | } |
| 1753 | |
| 1754 | public: |
| 1755 | friend class CastExpr; |
| 1756 | friend TrailingObjects; |
| 1757 | |
| 1758 | static CXXFunctionalCastExpr * |
| 1759 | Create(const ASTContext &Context, QualType T, ExprValueKind VK, |
| 1760 | TypeSourceInfo *Written, CastKind Kind, Expr *Op, |
| 1761 | const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, |
| 1762 | SourceLocation RPLoc); |
| 1763 | static CXXFunctionalCastExpr * |
| 1764 | CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures); |
| 1765 | |
| 1766 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 1767 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
| 1768 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 1769 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
| 1770 | |
| 1771 | |
| 1772 | bool isListInitialization() const { return LParenLoc.isInvalid(); } |
| 1773 | |
| 1774 | SourceLocation getBeginLoc() const LLVM_READONLY; |
| 1775 | SourceLocation getEndLoc() const LLVM_READONLY; |
| 1776 | |
| 1777 | static bool classof(const Stmt *T) { |
| 1778 | return T->getStmtClass() == CXXFunctionalCastExprClass; |
| 1779 | } |
| 1780 | }; |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | class CXXTemporaryObjectExpr final : public CXXConstructExpr { |
| 1798 | friend class ASTStmtReader; |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | TypeSourceInfo *TSI; |
| 1805 | |
| 1806 | CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType Ty, |
| 1807 | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, |
| 1808 | SourceRange ParenOrBraceRange, |
| 1809 | bool HadMultipleCandidates, bool ListInitialization, |
| 1810 | bool StdInitListInitialization, |
| 1811 | bool ZeroInitialization); |
| 1812 | |
| 1813 | CXXTemporaryObjectExpr(EmptyShell Empty, unsigned NumArgs); |
| 1814 | |
| 1815 | public: |
| 1816 | static CXXTemporaryObjectExpr * |
| 1817 | Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, |
| 1818 | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, |
| 1819 | SourceRange ParenOrBraceRange, bool HadMultipleCandidates, |
| 1820 | bool ListInitialization, bool StdInitListInitialization, |
| 1821 | bool ZeroInitialization); |
| 1822 | |
| 1823 | static CXXTemporaryObjectExpr *CreateEmpty(const ASTContext &Ctx, |
| 1824 | unsigned NumArgs); |
| 1825 | |
| 1826 | TypeSourceInfo *getTypeSourceInfo() const { return TSI; } |
| 1827 | |
| 1828 | SourceLocation getBeginLoc() const LLVM_READONLY; |
| 1829 | SourceLocation getEndLoc() const LLVM_READONLY; |
| 1830 | |
| 1831 | static bool classof(const Stmt *T) { |
| 1832 | return T->getStmtClass() == CXXTemporaryObjectExprClass; |
| 1833 | } |
| 1834 | }; |
| 1835 | |
| 1836 | Stmt **CXXConstructExpr::getTrailingArgs() { |
| 1837 | if (auto *E = dyn_cast<CXXTemporaryObjectExpr>(this)) |
| 1838 | return reinterpret_cast<Stmt **>(E + 1); |
| 1839 | assert((getStmtClass() == CXXConstructExprClass) && |
| 1840 | "Unexpected class deriving from CXXConstructExpr!"); |
| 1841 | return reinterpret_cast<Stmt **>(this + 1); |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | |
| 1865 | class LambdaExpr final : public Expr, |
| 1866 | private llvm::TrailingObjects<LambdaExpr, Stmt *> { |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | SourceRange IntroducerRange; |
| 1871 | |
| 1872 | |
| 1873 | SourceLocation CaptureDefaultLoc; |
| 1874 | |
| 1875 | |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | |
| 1882 | |
| 1883 | SourceLocation ClosingBrace; |
| 1884 | |
| 1885 | |
| 1886 | LambdaExpr(QualType T, SourceRange IntroducerRange, |
| 1887 | LambdaCaptureDefault CaptureDefault, |
| 1888 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
| 1889 | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, |
| 1890 | SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack); |
| 1891 | |
| 1892 | |
| 1893 | LambdaExpr(EmptyShell Empty, unsigned NumCaptures); |
| 1894 | |
| 1895 | Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); } |
| 1896 | Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); } |
| 1897 | |
| 1898 | void initBodyIfNeeded() const; |
| 1899 | |
| 1900 | public: |
| 1901 | friend class ASTStmtReader; |
| 1902 | friend class ASTStmtWriter; |
| 1903 | friend TrailingObjects; |
| 1904 | |
| 1905 | |
| 1906 | static LambdaExpr * |
| 1907 | Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, |
| 1908 | LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, |
| 1909 | bool ExplicitParams, bool ExplicitResultType, |
| 1910 | ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace, |
| 1911 | bool ContainsUnexpandedParameterPack); |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | static LambdaExpr *CreateDeserialized(const ASTContext &C, |
| 1916 | unsigned NumCaptures); |
| 1917 | |
| 1918 | |
| 1919 | LambdaCaptureDefault getCaptureDefault() const { |
| 1920 | return static_cast<LambdaCaptureDefault>(LambdaExprBits.CaptureDefault); |
| 1921 | } |
| 1922 | |
| 1923 | |
| 1924 | SourceLocation getCaptureDefaultLoc() const { return CaptureDefaultLoc; } |
| 1925 | |
| 1926 | |
| 1927 | bool isInitCapture(const LambdaCapture *Capture) const; |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | using capture_iterator = const LambdaCapture *; |
| 1932 | |
| 1933 | |
| 1934 | using capture_range = llvm::iterator_range<capture_iterator>; |
| 1935 | |
| 1936 | |
| 1937 | capture_range captures() const; |
| 1938 | |
| 1939 | |
| 1940 | capture_iterator capture_begin() const; |
| 1941 | |
| 1942 | |
| 1943 | |
| 1944 | capture_iterator capture_end() const; |
| 1945 | |
| 1946 | |
| 1947 | unsigned capture_size() const { return LambdaExprBits.NumCaptures; } |
| 1948 | |
| 1949 | |
| 1950 | capture_range explicit_captures() const; |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | capture_iterator explicit_capture_begin() const; |
| 1955 | |
| 1956 | |
| 1957 | |
| 1958 | capture_iterator explicit_capture_end() const; |
| 1959 | |
| 1960 | |
| 1961 | capture_range implicit_captures() const; |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | capture_iterator implicit_capture_begin() const; |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | capture_iterator implicit_capture_end() const; |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | using capture_init_iterator = Expr **; |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | using const_capture_init_iterator = Expr *const *; |
| 1979 | |
| 1980 | |
| 1981 | llvm::iterator_range<capture_init_iterator> capture_inits() { |
| 1982 | return llvm::make_range(capture_init_begin(), capture_init_end()); |
| 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | llvm::iterator_range<const_capture_init_iterator> capture_inits() const { |
| 1987 | return llvm::make_range(capture_init_begin(), capture_init_end()); |
| 1988 | } |
| 1989 | |
| 1990 | |
| 1991 | |
| 1992 | capture_init_iterator capture_init_begin() { |
| 1993 | return reinterpret_cast<Expr **>(getStoredStmts()); |
| 1994 | } |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | const_capture_init_iterator capture_init_begin() const { |
| 1999 | return reinterpret_cast<Expr *const *>(getStoredStmts()); |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | capture_init_iterator capture_init_end() { |
| 2005 | return capture_init_begin() + capture_size(); |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | const_capture_init_iterator capture_init_end() const { |
| 2011 | return capture_init_begin() + capture_size(); |
| 2012 | } |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | SourceRange getIntroducerRange() const { return IntroducerRange; } |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | |
| 2024 | CXXRecordDecl *getLambdaClass() const; |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | CXXMethodDecl *getCallOperator() const; |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | FunctionTemplateDecl *getDependentCallOperator() const; |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | TemplateParameterList *getTemplateParameterList() const; |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | ArrayRef<NamedDecl *> getExplicitTemplateParameters() const; |
| 2041 | |
| 2042 | |
| 2043 | Expr *getTrailingRequiresClause() const; |
| 2044 | |
| 2045 | |
| 2046 | bool isGenericLambda() const { return getTemplateParameterList(); } |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | |
| 2052 | Stmt *getBody() const; |
| 2053 | |
| 2054 | |
| 2055 | |
| 2056 | |
| 2057 | const CompoundStmt *getCompoundStmtBody() const; |
| 2058 | CompoundStmt *getCompoundStmtBody() { |
| 2059 | const auto *ConstThis = this; |
| 2060 | return const_cast<CompoundStmt *>(ConstThis->getCompoundStmtBody()); |
| 2061 | } |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | bool isMutable() const; |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | bool hasExplicitParameters() const { return LambdaExprBits.ExplicitParams; } |
| 2070 | |
| 2071 | |
| 2072 | bool hasExplicitResultType() const { |
| 2073 | return LambdaExprBits.ExplicitResultType; |
| 2074 | } |
| 2075 | |
| 2076 | static bool classof(const Stmt *T) { |
| 2077 | return T->getStmtClass() == LambdaExprClass; |
| 2078 | } |
| 2079 | |
| 2080 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 2081 | return IntroducerRange.getBegin(); |
| 2082 | } |
| 2083 | |
| 2084 | SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; } |
| 2085 | |
| 2086 | |
| 2087 | child_range children(); |
| 2088 | const_child_range children() const; |
| 2089 | }; |
| 2090 | |
| 2091 | |
| 2092 | |
| 2093 | class CXXScalarValueInitExpr : public Expr { |
| 2094 | friend class ASTStmtReader; |
| 2095 | |
| 2096 | TypeSourceInfo *TypeInfo; |
| 2097 | |
| 2098 | public: |
| 2099 | |
| 2100 | |
| 2101 | CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo, |
| 2102 | SourceLocation RParenLoc) |
| 2103 | : Expr(CXXScalarValueInitExprClass, Type, VK_PRValue, OK_Ordinary), |
| 2104 | TypeInfo(TypeInfo) { |
| 2105 | CXXScalarValueInitExprBits.RParenLoc = RParenLoc; |
| 2106 | setDependence(computeDependence(this)); |
| 2107 | } |
| 2108 | |
| 2109 | explicit CXXScalarValueInitExpr(EmptyShell Shell) |
| 2110 | : Expr(CXXScalarValueInitExprClass, Shell) {} |
| 2111 | |
| 2112 | TypeSourceInfo *getTypeSourceInfo() const { |
| 2113 | return TypeInfo; |
| 2114 | } |
| 2115 | |
| 2116 | SourceLocation getRParenLoc() const { |
| 2117 | return CXXScalarValueInitExprBits.RParenLoc; |
| 2118 | } |
| 2119 | |
| 2120 | SourceLocation getBeginLoc() const LLVM_READONLY; |
| 2121 | SourceLocation getEndLoc() const { return getRParenLoc(); } |
| 2122 | |
| 2123 | static bool classof(const Stmt *T) { |
| 2124 | return T->getStmtClass() == CXXScalarValueInitExprClass; |
| 2125 | } |
| 2126 | |
| 2127 | |
| 2128 | child_range children() { |
| 2129 | return child_range(child_iterator(), child_iterator()); |
| 2130 | } |
| 2131 | |
| 2132 | const_child_range children() const { |
| 2133 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 2134 | } |
| 2135 | }; |
| 2136 | |
| 2137 | |
| 2138 | |
| 2139 | class CXXNewExpr final |
| 2140 | : public Expr, |
| 2141 | private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> { |
| 2142 | friend class ASTStmtReader; |
| 2143 | friend class ASTStmtWriter; |
| 2144 | friend TrailingObjects; |
| 2145 | |
| 2146 | |
| 2147 | FunctionDecl *OperatorNew; |
| 2148 | |
| 2149 | |
| 2150 | FunctionDecl *OperatorDelete; |
| 2151 | |
| 2152 | |
| 2153 | TypeSourceInfo *AllocatedTypeInfo; |
| 2154 | |
| 2155 | |
| 2156 | SourceRange Range; |
| 2157 | |
| 2158 | |
| 2159 | SourceRange DirectInitRange; |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | unsigned arraySizeOffset() const { return 0; } |
| 2177 | unsigned initExprOffset() const { return arraySizeOffset() + isArray(); } |
| 2178 | unsigned placementNewArgsOffset() const { |
| 2179 | return initExprOffset() + hasInitializer(); |
| 2180 | } |
| 2181 | |
| 2182 | unsigned numTrailingObjects(OverloadToken<Stmt *>) const { |
| 2183 | return isArray() + hasInitializer() + getNumPlacementArgs(); |
| 2184 | } |
| 2185 | |
| 2186 | unsigned numTrailingObjects(OverloadToken<SourceRange>) const { |
| 2187 | return isParenTypeId(); |
| 2188 | } |
| 2189 | |
| 2190 | public: |
| 2191 | enum InitializationStyle { |
| 2192 | |
| 2193 | NoInit, |
| 2194 | |
| 2195 | |
| 2196 | CallInit, |
| 2197 | |
| 2198 | |
| 2199 | ListInit |
| 2200 | }; |
| 2201 | |
| 2202 | private: |
| 2203 | |
| 2204 | CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, |
| 2205 | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, |
| 2206 | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, |
| 2207 | SourceRange TypeIdParens, Optional<Expr *> ArraySize, |
| 2208 | InitializationStyle InitializationStyle, Expr *Initializer, |
| 2209 | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
| 2210 | SourceRange DirectInitRange); |
| 2211 | |
| 2212 | |
| 2213 | CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs, |
| 2214 | bool IsParenTypeId); |
| 2215 | |
| 2216 | public: |
| 2217 | |
| 2218 | static CXXNewExpr * |
| 2219 | Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, |
| 2220 | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, |
| 2221 | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, |
| 2222 | SourceRange TypeIdParens, Optional<Expr *> ArraySize, |
| 2223 | InitializationStyle InitializationStyle, Expr *Initializer, |
| 2224 | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, |
| 2225 | SourceRange DirectInitRange); |
| 2226 | |
| 2227 | |
| 2228 | static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray, |
| 2229 | bool HasInit, unsigned NumPlacementArgs, |
| 2230 | bool IsParenTypeId); |
| 2231 | |
| 2232 | QualType getAllocatedType() const { |
| 2233 | return getType()->castAs<PointerType>()->getPointeeType(); |
| 2234 | } |
| 2235 | |
| 2236 | TypeSourceInfo *getAllocatedTypeSourceInfo() const { |
| 2237 | return AllocatedTypeInfo; |
| 2238 | } |
| 2239 | |
| 2240 | |
| 2241 | |
| 2242 | |
| 2243 | |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | |
| 2254 | |
| 2255 | bool shouldNullCheckAllocation() const; |
| 2256 | |
| 2257 | FunctionDecl *getOperatorNew() const { return OperatorNew; } |
| 2258 | void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } |
| 2259 | FunctionDecl *getOperatorDelete() const { return OperatorDelete; } |
| 2260 | void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } |
| 2261 | |
| 2262 | bool isArray() const { return CXXNewExprBits.IsArray; } |
| 2263 | |
| 2264 | Optional<Expr *> getArraySize() { |
| 2265 | if (!isArray()) |
| 2266 | return None; |
| 2267 | return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]); |
| 2268 | } |
| 2269 | Optional<const Expr *> getArraySize() const { |
| 2270 | if (!isArray()) |
| 2271 | return None; |
| 2272 | return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()]); |
| 2273 | } |
| 2274 | |
| 2275 | unsigned getNumPlacementArgs() const { |
| 2276 | return CXXNewExprBits.NumPlacementArgs; |
| 2277 | } |
| 2278 | |
| 2279 | Expr **getPlacementArgs() { |
| 2280 | return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() + |
| 2281 | placementNewArgsOffset()); |
| 2282 | } |
| 2283 | |
| 2284 | Expr *getPlacementArg(unsigned I) { |
| 2285 | assert((I < getNumPlacementArgs()) && "Index out of range!"); |
| 2286 | return getPlacementArgs()[I]; |
| 2287 | } |
| 2288 | const Expr *getPlacementArg(unsigned I) const { |
| 2289 | return const_cast<CXXNewExpr *>(this)->getPlacementArg(I); |
| 2290 | } |
| 2291 | |
| 2292 | bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; } |
| 2293 | SourceRange getTypeIdParens() const { |
| 2294 | return isParenTypeId() ? getTrailingObjects<SourceRange>()[0] |
| 2295 | : SourceRange(); |
| 2296 | } |
| 2297 | |
| 2298 | bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; } |
| 2299 | |
| 2300 | |
| 2301 | bool hasInitializer() const { |
| 2302 | return CXXNewExprBits.StoredInitializationStyle > 0; |
| 28 | | Assuming field 'StoredInitializationStyle' is > 0 | |
|
| 29 | | Returning the value 1, which participates in a condition later | |
|
| 2303 | } |
| 2304 | |
| 2305 | |
| 2306 | InitializationStyle getInitializationStyle() const { |
| 2307 | if (CXXNewExprBits.StoredInitializationStyle == 0) |
| 2308 | return NoInit; |
| 2309 | return static_cast<InitializationStyle>( |
| 2310 | CXXNewExprBits.StoredInitializationStyle - 1); |
| 2311 | } |
| 2312 | |
| 2313 | |
| 2314 | Expr *getInitializer() { |
| 2315 | return hasInitializer() |
| 2316 | ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()]) |
| 2317 | : nullptr; |
| 2318 | } |
| 2319 | const Expr *getInitializer() const { |
| 2320 | return hasInitializer() |
| 2321 | ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()]) |
| 2322 | : nullptr; |
| 2323 | } |
| 2324 | |
| 2325 | |
| 2326 | const CXXConstructExpr *getConstructExpr() const { |
| 2327 | return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); |
| 2328 | } |
| 2329 | |
| 2330 | |
| 2331 | |
| 2332 | bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; } |
| 2333 | |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | bool doesUsualArrayDeleteWantSize() const { |
| 2338 | return CXXNewExprBits.UsualArrayDeleteWantsSize; |
| 2339 | } |
| 2340 | |
| 2341 | using arg_iterator = ExprIterator; |
| 2342 | using const_arg_iterator = ConstExprIterator; |
| 2343 | |
| 2344 | llvm::iterator_range<arg_iterator> placement_arguments() { |
| 2345 | return llvm::make_range(placement_arg_begin(), placement_arg_end()); |
| 2346 | } |
| 2347 | |
| 2348 | llvm::iterator_range<const_arg_iterator> placement_arguments() const { |
| 2349 | return llvm::make_range(placement_arg_begin(), placement_arg_end()); |
| 2350 | } |
| 2351 | |
| 2352 | arg_iterator placement_arg_begin() { |
| 2353 | return getTrailingObjects<Stmt *>() + placementNewArgsOffset(); |
| 2354 | } |
| 2355 | arg_iterator placement_arg_end() { |
| 2356 | return placement_arg_begin() + getNumPlacementArgs(); |
| 2357 | } |
| 2358 | const_arg_iterator placement_arg_begin() const { |
| 2359 | return getTrailingObjects<Stmt *>() + placementNewArgsOffset(); |
| 2360 | } |
| 2361 | const_arg_iterator placement_arg_end() const { |
| 2362 | return placement_arg_begin() + getNumPlacementArgs(); |
| 2363 | } |
| 2364 | |
| 2365 | using raw_arg_iterator = Stmt **; |
| 2366 | |
| 2367 | raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); } |
| 2368 | raw_arg_iterator raw_arg_end() { |
| 2369 | return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>()); |
| 2370 | } |
| 2371 | const_arg_iterator raw_arg_begin() const { |
| 2372 | return getTrailingObjects<Stmt *>(); |
| 2373 | } |
| 2374 | const_arg_iterator raw_arg_end() const { |
| 2375 | return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>()); |
| 2376 | } |
| 2377 | |
| 2378 | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
| 2379 | SourceLocation getEndLoc() const { return Range.getEnd(); } |
| 2380 | |
| 2381 | SourceRange getDirectInitRange() const { return DirectInitRange; } |
| 2382 | SourceRange getSourceRange() const { return Range; } |
| 2383 | |
| 2384 | static bool classof(const Stmt *T) { |
| 2385 | return T->getStmtClass() == CXXNewExprClass; |
| 2386 | } |
| 2387 | |
| 2388 | |
| 2389 | child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); } |
| 2390 | |
| 2391 | const_child_range children() const { |
| 2392 | return const_child_range(const_cast<CXXNewExpr *>(this)->children()); |
| 2393 | } |
| 2394 | }; |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | class CXXDeleteExpr : public Expr { |
| 2399 | friend class ASTStmtReader; |
| 2400 | |
| 2401 | |
| 2402 | FunctionDecl *OperatorDelete = nullptr; |
| 2403 | |
| 2404 | |
| 2405 | Stmt *Argument = nullptr; |
| 2406 | |
| 2407 | public: |
| 2408 | CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm, |
| 2409 | bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize, |
| 2410 | FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc) |
| 2411 | : Expr(CXXDeleteExprClass, Ty, VK_PRValue, OK_Ordinary), |
| 2412 | OperatorDelete(OperatorDelete), Argument(Arg) { |
| 2413 | CXXDeleteExprBits.GlobalDelete = GlobalDelete; |
| 2414 | CXXDeleteExprBits.ArrayForm = ArrayForm; |
| 2415 | CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten; |
| 2416 | CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; |
| 2417 | CXXDeleteExprBits.Loc = Loc; |
| 2418 | setDependence(computeDependence(this)); |
| 2419 | } |
| 2420 | |
| 2421 | explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {} |
| 2422 | |
| 2423 | bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; } |
| 2424 | bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; } |
| 2425 | bool isArrayFormAsWritten() const { |
| 2426 | return CXXDeleteExprBits.ArrayFormAsWritten; |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | |
| 2431 | |
| 2432 | |
| 2433 | bool doesUsualArrayDeleteWantSize() const { |
| 2434 | return CXXDeleteExprBits.UsualArrayDeleteWantsSize; |
| 2435 | } |
| 2436 | |
| 2437 | FunctionDecl *getOperatorDelete() const { return OperatorDelete; } |
| 2438 | |
| 2439 | Expr *getArgument() { return cast<Expr>(Argument); } |
| 2440 | const Expr *getArgument() const { return cast<Expr>(Argument); } |
| 2441 | |
| 2442 | |
| 2443 | |
| 2444 | |
| 2445 | |
| 2446 | QualType getDestroyedType() const; |
| 2447 | |
| 2448 | SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; } |
| 2449 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 2450 | return Argument->getEndLoc(); |
| 2451 | } |
| 2452 | |
| 2453 | static bool classof(const Stmt *T) { |
| 2454 | return T->getStmtClass() == CXXDeleteExprClass; |
| 2455 | } |
| 2456 | |
| 2457 | |
| 2458 | child_range children() { return child_range(&Argument, &Argument + 1); } |
| 2459 | |
| 2460 | const_child_range children() const { |
| 2461 | return const_child_range(&Argument, &Argument + 1); |
| 2462 | } |
| 2463 | }; |
| 2464 | |
| 2465 | |
| 2466 | class PseudoDestructorTypeStorage { |
| 2467 | |
| 2468 | |
| 2469 | llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; |
| 2470 | |
| 2471 | |
| 2472 | SourceLocation Location; |
| 2473 | |
| 2474 | public: |
| 2475 | PseudoDestructorTypeStorage() = default; |
| 2476 | |
| 2477 | PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) |
| 2478 | : Type(II), Location(Loc) {} |
| 2479 | |
| 2480 | PseudoDestructorTypeStorage(TypeSourceInfo *Info); |
| 2481 | |
| 2482 | TypeSourceInfo *getTypeSourceInfo() const { |
| 2483 | return Type.dyn_cast<TypeSourceInfo *>(); |
| 2484 | } |
| 2485 | |
| 2486 | IdentifierInfo *getIdentifier() const { |
| 2487 | return Type.dyn_cast<IdentifierInfo *>(); |
| 2488 | } |
| 2489 | |
| 2490 | SourceLocation getLocation() const { return Location; } |
| 2491 | }; |
| 2492 | |
| 2493 | |
| 2494 | |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | |
| 2506 | |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | |
| 2511 | |
| 2512 | |
| 2513 | |
| 2514 | |
| 2515 | |
| 2516 | |
| 2517 | class CXXPseudoDestructorExpr : public Expr { |
| 2518 | friend class ASTStmtReader; |
| 2519 | |
| 2520 | |
| 2521 | Stmt *Base = nullptr; |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | bool IsArrow : 1; |
| 2526 | |
| 2527 | |
| 2528 | SourceLocation OperatorLoc; |
| 2529 | |
| 2530 | |
| 2531 | NestedNameSpecifierLoc QualifierLoc; |
| 2532 | |
| 2533 | |
| 2534 | |
| 2535 | TypeSourceInfo *ScopeType = nullptr; |
| 2536 | |
| 2537 | |
| 2538 | |
| 2539 | SourceLocation ColonColonLoc; |
| 2540 | |
| 2541 | |
| 2542 | SourceLocation TildeLoc; |
| 2543 | |
| 2544 | |
| 2545 | |
| 2546 | PseudoDestructorTypeStorage DestroyedType; |
| 2547 | |
| 2548 | public: |
| 2549 | CXXPseudoDestructorExpr(const ASTContext &Context, |
| 2550 | Expr *Base, bool isArrow, SourceLocation OperatorLoc, |
| 2551 | NestedNameSpecifierLoc QualifierLoc, |
| 2552 | TypeSourceInfo *ScopeType, |
| 2553 | SourceLocation ColonColonLoc, |
| 2554 | SourceLocation TildeLoc, |
| 2555 | PseudoDestructorTypeStorage DestroyedType); |
| 2556 | |
| 2557 | explicit CXXPseudoDestructorExpr(EmptyShell Shell) |
| 2558 | : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {} |
| 2559 | |
| 2560 | Expr *getBase() const { return cast<Expr>(Base); } |
| 2561 | |
| 2562 | |
| 2563 | |
| 2564 | |
| 2565 | bool hasQualifier() const { return QualifierLoc.hasQualifier(); } |
| 2566 | |
| 2567 | |
| 2568 | |
| 2569 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 2570 | |
| 2571 | |
| 2572 | |
| 2573 | |
| 2574 | NestedNameSpecifier *getQualifier() const { |
| 2575 | return QualifierLoc.getNestedNameSpecifier(); |
| 2576 | } |
| 2577 | |
| 2578 | |
| 2579 | |
| 2580 | bool isArrow() const { return IsArrow; } |
| 2581 | |
| 2582 | |
| 2583 | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | |
| 2588 | |
| 2589 | |
| 2590 | |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } |
| 2595 | |
| 2596 | |
| 2597 | |
| 2598 | SourceLocation getColonColonLoc() const { return ColonColonLoc; } |
| 2599 | |
| 2600 | |
| 2601 | SourceLocation getTildeLoc() const { return TildeLoc; } |
| 2602 | |
| 2603 | |
| 2604 | |
| 2605 | |
| 2606 | |
| 2607 | |
| 2608 | |
| 2609 | |
| 2610 | TypeSourceInfo *getDestroyedTypeInfo() const { |
| 2611 | return DestroyedType.getTypeSourceInfo(); |
| 2612 | } |
| 2613 | |
| 2614 | |
| 2615 | |
| 2616 | |
| 2617 | IdentifierInfo *getDestroyedTypeIdentifier() const { |
| 2618 | return DestroyedType.getIdentifier(); |
| 2619 | } |
| 2620 | |
| 2621 | |
| 2622 | QualType getDestroyedType() const; |
| 2623 | |
| 2624 | |
| 2625 | SourceLocation getDestroyedTypeLoc() const { |
| 2626 | return DestroyedType.getLocation(); |
| 2627 | } |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { |
| 2632 | DestroyedType = PseudoDestructorTypeStorage(II, Loc); |
| 2633 | } |
| 2634 | |
| 2635 | |
| 2636 | void setDestroyedType(TypeSourceInfo *Info) { |
| 2637 | DestroyedType = PseudoDestructorTypeStorage(Info); |
| 2638 | } |
| 2639 | |
| 2640 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 2641 | return Base->getBeginLoc(); |
| 2642 | } |
| 2643 | SourceLocation getEndLoc() const LLVM_READONLY; |
| 2644 | |
| 2645 | static bool classof(const Stmt *T) { |
| 2646 | return T->getStmtClass() == CXXPseudoDestructorExprClass; |
| 2647 | } |
| 2648 | |
| 2649 | |
| 2650 | child_range children() { return child_range(&Base, &Base + 1); } |
| 2651 | |
| 2652 | const_child_range children() const { |
| 2653 | return const_child_range(&Base, &Base + 1); |
| 2654 | } |
| 2655 | }; |
| 2656 | |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | |
| 2664 | |
| 2665 | class TypeTraitExpr final |
| 2666 | : public Expr, |
| 2667 | private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> { |
| 2668 | |
| 2669 | SourceLocation Loc; |
| 2670 | |
| 2671 | |
| 2672 | SourceLocation RParenLoc; |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | |
| 2677 | TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, |
| 2678 | ArrayRef<TypeSourceInfo *> Args, |
| 2679 | SourceLocation RParenLoc, |
| 2680 | bool Value); |
| 2681 | |
| 2682 | TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {} |
| 2683 | |
| 2684 | size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const { |
| 2685 | return getNumArgs(); |
| 2686 | } |
| 2687 | |
| 2688 | public: |
| 2689 | friend class ASTStmtReader; |
| 2690 | friend class ASTStmtWriter; |
| 2691 | friend TrailingObjects; |
| 2692 | |
| 2693 | |
| 2694 | static TypeTraitExpr *Create(const ASTContext &C, QualType T, |
| 2695 | SourceLocation Loc, TypeTrait Kind, |
| 2696 | ArrayRef<TypeSourceInfo *> Args, |
| 2697 | SourceLocation RParenLoc, |
| 2698 | bool Value); |
| 2699 | |
| 2700 | static TypeTraitExpr *CreateDeserialized(const ASTContext &C, |
| 2701 | unsigned NumArgs); |
| 2702 | |
| 2703 | |
| 2704 | TypeTrait getTrait() const { |
| 2705 | return static_cast<TypeTrait>(TypeTraitExprBits.Kind); |
| 2706 | } |
| 2707 | |
| 2708 | bool getValue() const { |
| 2709 | assert(!isValueDependent()); |
| 2710 | return TypeTraitExprBits.Value; |
| 2711 | } |
| 2712 | |
| 2713 | |
| 2714 | unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } |
| 2715 | |
| 2716 | |
| 2717 | TypeSourceInfo *getArg(unsigned I) const { |
| 2718 | assert(I < getNumArgs() && "Argument out-of-range"); |
| 2719 | return getArgs()[I]; |
| 2720 | } |
| 2721 | |
| 2722 | |
| 2723 | ArrayRef<TypeSourceInfo *> getArgs() const { |
| 2724 | return llvm::makeArrayRef(getTrailingObjects<TypeSourceInfo *>(), |
| 2725 | getNumArgs()); |
| 2726 | } |
| 2727 | |
| 2728 | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
| 2729 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
| 2730 | |
| 2731 | static bool classof(const Stmt *T) { |
| 2732 | return T->getStmtClass() == TypeTraitExprClass; |
| 2733 | } |
| 2734 | |
| 2735 | |
| 2736 | child_range children() { |
| 2737 | return child_range(child_iterator(), child_iterator()); |
| 2738 | } |
| 2739 | |
| 2740 | const_child_range children() const { |
| 2741 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 2742 | } |
| 2743 | }; |
| 2744 | |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | |
| 2749 | |
| 2750 | |
| 2751 | |
| 2752 | |
| 2753 | class ArrayTypeTraitExpr : public Expr { |
| 2754 | |
| 2755 | unsigned ATT : 2; |
| 2756 | |
| 2757 | |
| 2758 | uint64_t Value = 0; |
| 2759 | |
| 2760 | |
| 2761 | Expr *Dimension; |
| 2762 | |
| 2763 | |
| 2764 | SourceLocation Loc; |
| 2765 | |
| 2766 | |
| 2767 | SourceLocation RParen; |
| 2768 | |
| 2769 | |
| 2770 | TypeSourceInfo *QueriedType = nullptr; |
| 2771 | |
| 2772 | public: |
| 2773 | friend class ASTStmtReader; |
| 2774 | |
| 2775 | ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, |
| 2776 | TypeSourceInfo *queried, uint64_t value, Expr *dimension, |
| 2777 | SourceLocation rparen, QualType ty) |
| 2778 | : Expr(ArrayTypeTraitExprClass, ty, VK_PRValue, OK_Ordinary), ATT(att), |
| 2779 | Value(value), Dimension(dimension), Loc(loc), RParen(rparen), |
| 2780 | QueriedType(queried) { |
| 2781 | assert(att <= ATT_Last && "invalid enum value!"); |
| 2782 | assert(static_cast<unsigned>(att) == ATT && "ATT overflow!"); |
| 2783 | setDependence(computeDependence(this)); |
| 2784 | } |
| 2785 | |
| 2786 | explicit ArrayTypeTraitExpr(EmptyShell Empty) |
| 2787 | : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {} |
| 2788 | |
| 2789 | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
| 2790 | SourceLocation getEndLoc() const LLVM_READONLY { return RParen; } |
| 2791 | |
| 2792 | ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } |
| 2793 | |
| 2794 | QualType getQueriedType() const { return QueriedType->getType(); } |
| 2795 | |
| 2796 | TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } |
| 2797 | |
| 2798 | uint64_t getValue() const { assert(!isTypeDependent()); return Value; } |
| 2799 | |
| 2800 | Expr *getDimensionExpression() const { return Dimension; } |
| 2801 | |
| 2802 | static bool classof(const Stmt *T) { |
| 2803 | return T->getStmtClass() == ArrayTypeTraitExprClass; |
| 2804 | } |
| 2805 | |
| 2806 | |
| 2807 | child_range children() { |
| 2808 | return child_range(child_iterator(), child_iterator()); |
| 2809 | } |
| 2810 | |
| 2811 | const_child_range children() const { |
| 2812 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 2813 | } |
| 2814 | }; |
| 2815 | |
| 2816 | |
| 2817 | |
| 2818 | |
| 2819 | |
| 2820 | |
| 2821 | |
| 2822 | |
| 2823 | class ExpressionTraitExpr : public Expr { |
| 2824 | |
| 2825 | unsigned ET : 31; |
| 2826 | |
| 2827 | |
| 2828 | unsigned Value : 1; |
| 2829 | |
| 2830 | |
| 2831 | SourceLocation Loc; |
| 2832 | |
| 2833 | |
| 2834 | SourceLocation RParen; |
| 2835 | |
| 2836 | |
| 2837 | Expr* QueriedExpression = nullptr; |
| 2838 | |
| 2839 | public: |
| 2840 | friend class ASTStmtReader; |
| 2841 | |
| 2842 | ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, Expr *queried, |
| 2843 | bool value, SourceLocation rparen, QualType resultType) |
| 2844 | : Expr(ExpressionTraitExprClass, resultType, VK_PRValue, OK_Ordinary), |
| 2845 | ET(et), Value(value), Loc(loc), RParen(rparen), |
| 2846 | QueriedExpression(queried) { |
| 2847 | assert(et <= ET_Last && "invalid enum value!"); |
| 2848 | assert(static_cast<unsigned>(et) == ET && "ET overflow!"); |
| 2849 | setDependence(computeDependence(this)); |
| 2850 | } |
| 2851 | |
| 2852 | explicit ExpressionTraitExpr(EmptyShell Empty) |
| 2853 | : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {} |
| 2854 | |
| 2855 | SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; } |
| 2856 | SourceLocation getEndLoc() const LLVM_READONLY { return RParen; } |
| 2857 | |
| 2858 | ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } |
| 2859 | |
| 2860 | Expr *getQueriedExpression() const { return QueriedExpression; } |
| 2861 | |
| 2862 | bool getValue() const { return Value; } |
| 2863 | |
| 2864 | static bool classof(const Stmt *T) { |
| 2865 | return T->getStmtClass() == ExpressionTraitExprClass; |
| 2866 | } |
| 2867 | |
| 2868 | |
| 2869 | child_range children() { |
| 2870 | return child_range(child_iterator(), child_iterator()); |
| 2871 | } |
| 2872 | |
| 2873 | const_child_range children() const { |
| 2874 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 2875 | } |
| 2876 | }; |
| 2877 | |
| 2878 | |
| 2879 | |
| 2880 | class OverloadExpr : public Expr { |
| 2881 | friend class ASTStmtReader; |
| 2882 | friend class ASTStmtWriter; |
| 2883 | |
| 2884 | |
| 2885 | DeclarationNameInfo NameInfo; |
| 2886 | |
| 2887 | |
| 2888 | NestedNameSpecifierLoc QualifierLoc; |
| 2889 | |
| 2890 | protected: |
| 2891 | OverloadExpr(StmtClass SC, const ASTContext &Context, |
| 2892 | NestedNameSpecifierLoc QualifierLoc, |
| 2893 | SourceLocation TemplateKWLoc, |
| 2894 | const DeclarationNameInfo &NameInfo, |
| 2895 | const TemplateArgumentListInfo *TemplateArgs, |
| 2896 | UnresolvedSetIterator Begin, UnresolvedSetIterator End, |
| 2897 | bool KnownDependent, bool KnownInstantiationDependent, |
| 2898 | bool KnownContainsUnexpandedParameterPack); |
| 2899 | |
| 2900 | OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults, |
| 2901 | bool HasTemplateKWAndArgsInfo); |
| 2902 | |
| 2903 | |
| 2904 | inline DeclAccessPair *getTrailingResults(); |
| 2905 | const DeclAccessPair *getTrailingResults() const { |
| 2906 | return const_cast<OverloadExpr *>(this)->getTrailingResults(); |
| 2907 | } |
| 2908 | |
| 2909 | |
| 2910 | |
| 2911 | inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo(); |
| 2912 | const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const { |
| 2913 | return const_cast<OverloadExpr *>(this) |
| 2914 | ->getTrailingASTTemplateKWAndArgsInfo(); |
| 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | |
| 2919 | inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); |
| 2920 | const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const { |
| 2921 | return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc(); |
| 2922 | } |
| 2923 | |
| 2924 | bool hasTemplateKWAndArgsInfo() const { |
| 2925 | return OverloadExprBits.HasTemplateKWAndArgsInfo; |
| 2926 | } |
| 2927 | |
| 2928 | public: |
| 2929 | struct FindResult { |
| 2930 | OverloadExpr *Expression; |
| 2931 | bool IsAddressOfOperand; |
| 2932 | bool HasFormOfMemberPointer; |
| 2933 | }; |
| 2934 | |
| 2935 | |
| 2936 | |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | static FindResult find(Expr *E) { |
| 2941 | assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload)); |
| 2942 | |
| 2943 | FindResult Result; |
| 2944 | |
| 2945 | E = E->IgnoreParens(); |
| 2946 | if (isa<UnaryOperator>(E)) { |
| 2947 | assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); |
| 2948 | E = cast<UnaryOperator>(E)->getSubExpr(); |
| 2949 | auto *Ovl = cast<OverloadExpr>(E->IgnoreParens()); |
| 2950 | |
| 2951 | Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); |
| 2952 | Result.IsAddressOfOperand = true; |
| 2953 | Result.Expression = Ovl; |
| 2954 | } else { |
| 2955 | Result.HasFormOfMemberPointer = false; |
| 2956 | Result.IsAddressOfOperand = false; |
| 2957 | Result.Expression = cast<OverloadExpr>(E); |
| 2958 | } |
| 2959 | |
| 2960 | return Result; |
| 2961 | } |
| 2962 | |
| 2963 | |
| 2964 | |
| 2965 | inline CXXRecordDecl *getNamingClass(); |
| 2966 | const CXXRecordDecl *getNamingClass() const { |
| 2967 | return const_cast<OverloadExpr *>(this)->getNamingClass(); |
| 2968 | } |
| 2969 | |
| 2970 | using decls_iterator = UnresolvedSetImpl::iterator; |
| 2971 | |
| 2972 | decls_iterator decls_begin() const { |
| 2973 | return UnresolvedSetIterator(getTrailingResults()); |
| 2974 | } |
| 2975 | decls_iterator decls_end() const { |
| 2976 | return UnresolvedSetIterator(getTrailingResults() + getNumDecls()); |
| 2977 | } |
| 2978 | llvm::iterator_range<decls_iterator> decls() const { |
| 2979 | return llvm::make_range(decls_begin(), decls_end()); |
| 2980 | } |
| 2981 | |
| 2982 | |
| 2983 | unsigned getNumDecls() const { return OverloadExprBits.NumResults; } |
| 2984 | |
| 2985 | |
| 2986 | const DeclarationNameInfo &getNameInfo() const { return NameInfo; } |
| 2987 | |
| 2988 | |
| 2989 | DeclarationName getName() const { return NameInfo.getName(); } |
| 2990 | |
| 2991 | |
| 2992 | SourceLocation getNameLoc() const { return NameInfo.getLoc(); } |
| 2993 | |
| 2994 | |
| 2995 | NestedNameSpecifier *getQualifier() const { |
| 2996 | return QualifierLoc.getNestedNameSpecifier(); |
| 2997 | } |
| 2998 | |
| 2999 | |
| 3000 | |
| 3001 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3002 | |
| 3003 | |
| 3004 | |
| 3005 | SourceLocation getTemplateKeywordLoc() const { |
| 3006 | if (!hasTemplateKWAndArgsInfo()) |
| 3007 | return SourceLocation(); |
| 3008 | return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc; |
| 3009 | } |
| 3010 | |
| 3011 | |
| 3012 | |
| 3013 | SourceLocation getLAngleLoc() const { |
| 3014 | if (!hasTemplateKWAndArgsInfo()) |
| 3015 | return SourceLocation(); |
| 3016 | return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc; |
| 3017 | } |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | SourceLocation getRAngleLoc() const { |
| 3022 | if (!hasTemplateKWAndArgsInfo()) |
| 3023 | return SourceLocation(); |
| 3024 | return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc; |
| 3025 | } |
| 3026 | |
| 3027 | |
| 3028 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
| 3029 | |
| 3030 | |
| 3031 | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
| 3032 | |
| 3033 | TemplateArgumentLoc const *getTemplateArgs() const { |
| 3034 | if (!hasExplicitTemplateArgs()) |
| 3035 | return nullptr; |
| 3036 | return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc(); |
| 3037 | } |
| 3038 | |
| 3039 | unsigned getNumTemplateArgs() const { |
| 3040 | if (!hasExplicitTemplateArgs()) |
| 3041 | return 0; |
| 3042 | |
| 3043 | return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs; |
| 3044 | } |
| 3045 | |
| 3046 | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
| 3047 | return {getTemplateArgs(), getNumTemplateArgs()}; |
| 3048 | } |
| 3049 | |
| 3050 | |
| 3051 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
| 3052 | if (hasExplicitTemplateArgs()) |
| 3053 | getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List); |
| 3054 | } |
| 3055 | |
| 3056 | static bool classof(const Stmt *T) { |
| 3057 | return T->getStmtClass() == UnresolvedLookupExprClass || |
| 3058 | T->getStmtClass() == UnresolvedMemberExprClass; |
| 3059 | } |
| 3060 | }; |
| 3061 | |
| 3062 | |
| 3063 | |
| 3064 | |
| 3065 | |
| 3066 | |
| 3067 | |
| 3068 | |
| 3069 | |
| 3070 | |
| 3071 | |
| 3072 | |
| 3073 | class UnresolvedLookupExpr final |
| 3074 | : public OverloadExpr, |
| 3075 | private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair, |
| 3076 | ASTTemplateKWAndArgsInfo, |
| 3077 | TemplateArgumentLoc> { |
| 3078 | friend class ASTStmtReader; |
| 3079 | friend class OverloadExpr; |
| 3080 | friend TrailingObjects; |
| 3081 | |
| 3082 | |
| 3083 | |
| 3084 | |
| 3085 | CXXRecordDecl *NamingClass; |
| 3086 | |
| 3087 | |
| 3088 | |
| 3089 | |
| 3090 | |
| 3091 | |
| 3092 | |
| 3093 | |
| 3094 | |
| 3095 | |
| 3096 | |
| 3097 | |
| 3098 | |
| 3099 | |
| 3100 | |
| 3101 | UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass, |
| 3102 | NestedNameSpecifierLoc QualifierLoc, |
| 3103 | SourceLocation TemplateKWLoc, |
| 3104 | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
| 3105 | bool Overloaded, |
| 3106 | const TemplateArgumentListInfo *TemplateArgs, |
| 3107 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
| 3108 | |
| 3109 | UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults, |
| 3110 | bool HasTemplateKWAndArgsInfo); |
| 3111 | |
| 3112 | unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const { |
| 3113 | return getNumDecls(); |
| 3114 | } |
| 3115 | |
| 3116 | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
| 3117 | return hasTemplateKWAndArgsInfo(); |
| 3118 | } |
| 3119 | |
| 3120 | public: |
| 3121 | static UnresolvedLookupExpr * |
| 3122 | Create(const ASTContext &Context, CXXRecordDecl *NamingClass, |
| 3123 | NestedNameSpecifierLoc QualifierLoc, |
| 3124 | const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, |
| 3125 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
| 3126 | |
| 3127 | static UnresolvedLookupExpr * |
| 3128 | Create(const ASTContext &Context, CXXRecordDecl *NamingClass, |
| 3129 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 3130 | const DeclarationNameInfo &NameInfo, bool RequiresADL, |
| 3131 | const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin, |
| 3132 | UnresolvedSetIterator End); |
| 3133 | |
| 3134 | static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context, |
| 3135 | unsigned NumResults, |
| 3136 | bool HasTemplateKWAndArgsInfo, |
| 3137 | unsigned NumTemplateArgs); |
| 3138 | |
| 3139 | |
| 3140 | |
| 3141 | bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; } |
| 3142 | |
| 3143 | |
| 3144 | bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; } |
| 3145 | |
| 3146 | |
| 3147 | |
| 3148 | |
| 3149 | CXXRecordDecl *getNamingClass() { return NamingClass; } |
| 3150 | const CXXRecordDecl *getNamingClass() const { return NamingClass; } |
| 3151 | |
| 3152 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 3153 | if (NestedNameSpecifierLoc l = getQualifierLoc()) |
| 3154 | return l.getBeginLoc(); |
| 3155 | return getNameInfo().getBeginLoc(); |
| 3156 | } |
| 3157 | |
| 3158 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3159 | if (hasExplicitTemplateArgs()) |
| 3160 | return getRAngleLoc(); |
| 3161 | return getNameInfo().getEndLoc(); |
| 3162 | } |
| 3163 | |
| 3164 | child_range children() { |
| 3165 | return child_range(child_iterator(), child_iterator()); |
| 3166 | } |
| 3167 | |
| 3168 | const_child_range children() const { |
| 3169 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3170 | } |
| 3171 | |
| 3172 | static bool classof(const Stmt *T) { |
| 3173 | return T->getStmtClass() == UnresolvedLookupExprClass; |
| 3174 | } |
| 3175 | }; |
| 3176 | |
| 3177 | |
| 3178 | |
| 3179 | |
| 3180 | |
| 3181 | |
| 3182 | |
| 3183 | |
| 3184 | |
| 3185 | |
| 3186 | |
| 3187 | |
| 3188 | |
| 3189 | |
| 3190 | |
| 3191 | class DependentScopeDeclRefExpr final |
| 3192 | : public Expr, |
| 3193 | private llvm::TrailingObjects<DependentScopeDeclRefExpr, |
| 3194 | ASTTemplateKWAndArgsInfo, |
| 3195 | TemplateArgumentLoc> { |
| 3196 | friend class ASTStmtReader; |
| 3197 | friend class ASTStmtWriter; |
| 3198 | friend TrailingObjects; |
| 3199 | |
| 3200 | |
| 3201 | |
| 3202 | NestedNameSpecifierLoc QualifierLoc; |
| 3203 | |
| 3204 | |
| 3205 | DeclarationNameInfo NameInfo; |
| 3206 | |
| 3207 | DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc, |
| 3208 | SourceLocation TemplateKWLoc, |
| 3209 | const DeclarationNameInfo &NameInfo, |
| 3210 | const TemplateArgumentListInfo *Args); |
| 3211 | |
| 3212 | size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
| 3213 | return hasTemplateKWAndArgsInfo(); |
| 3214 | } |
| 3215 | |
| 3216 | bool hasTemplateKWAndArgsInfo() const { |
| 3217 | return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo; |
| 3218 | } |
| 3219 | |
| 3220 | public: |
| 3221 | static DependentScopeDeclRefExpr * |
| 3222 | Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, |
| 3223 | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, |
| 3224 | const TemplateArgumentListInfo *TemplateArgs); |
| 3225 | |
| 3226 | static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context, |
| 3227 | bool HasTemplateKWAndArgsInfo, |
| 3228 | unsigned NumTemplateArgs); |
| 3229 | |
| 3230 | |
| 3231 | const DeclarationNameInfo &getNameInfo() const { return NameInfo; } |
| 3232 | |
| 3233 | |
| 3234 | DeclarationName getDeclName() const { return NameInfo.getName(); } |
| 3235 | |
| 3236 | |
| 3237 | |
| 3238 | |
| 3239 | SourceLocation getLocation() const { return NameInfo.getLoc(); } |
| 3240 | |
| 3241 | |
| 3242 | |
| 3243 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3244 | |
| 3245 | |
| 3246 | |
| 3247 | NestedNameSpecifier *getQualifier() const { |
| 3248 | return QualifierLoc.getNestedNameSpecifier(); |
| 3249 | } |
| 3250 | |
| 3251 | |
| 3252 | |
| 3253 | SourceLocation getTemplateKeywordLoc() const { |
| 3254 | if (!hasTemplateKWAndArgsInfo()) |
| 3255 | return SourceLocation(); |
| 3256 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; |
| 3257 | } |
| 3258 | |
| 3259 | |
| 3260 | |
| 3261 | SourceLocation getLAngleLoc() const { |
| 3262 | if (!hasTemplateKWAndArgsInfo()) |
| 3263 | return SourceLocation(); |
| 3264 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; |
| 3265 | } |
| 3266 | |
| 3267 | |
| 3268 | |
| 3269 | SourceLocation getRAngleLoc() const { |
| 3270 | if (!hasTemplateKWAndArgsInfo()) |
| 3271 | return SourceLocation(); |
| 3272 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; |
| 3273 | } |
| 3274 | |
| 3275 | |
| 3276 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
| 3277 | |
| 3278 | |
| 3279 | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
| 3280 | |
| 3281 | |
| 3282 | |
| 3283 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
| 3284 | if (hasExplicitTemplateArgs()) |
| 3285 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( |
| 3286 | getTrailingObjects<TemplateArgumentLoc>(), List); |
| 3287 | } |
| 3288 | |
| 3289 | TemplateArgumentLoc const *getTemplateArgs() const { |
| 3290 | if (!hasExplicitTemplateArgs()) |
| 3291 | return nullptr; |
| 3292 | |
| 3293 | return getTrailingObjects<TemplateArgumentLoc>(); |
| 3294 | } |
| 3295 | |
| 3296 | unsigned getNumTemplateArgs() const { |
| 3297 | if (!hasExplicitTemplateArgs()) |
| 3298 | return 0; |
| 3299 | |
| 3300 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; |
| 3301 | } |
| 3302 | |
| 3303 | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
| 3304 | return {getTemplateArgs(), getNumTemplateArgs()}; |
| 3305 | } |
| 3306 | |
| 3307 | |
| 3308 | |
| 3309 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 3310 | return QualifierLoc.getBeginLoc(); |
| 3311 | } |
| 3312 | |
| 3313 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3314 | if (hasExplicitTemplateArgs()) |
| 3315 | return getRAngleLoc(); |
| 3316 | return getLocation(); |
| 3317 | } |
| 3318 | |
| 3319 | static bool classof(const Stmt *T) { |
| 3320 | return T->getStmtClass() == DependentScopeDeclRefExprClass; |
| 3321 | } |
| 3322 | |
| 3323 | child_range children() { |
| 3324 | return child_range(child_iterator(), child_iterator()); |
| 3325 | } |
| 3326 | |
| 3327 | const_child_range children() const { |
| 3328 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3329 | } |
| 3330 | }; |
| 3331 | |
| 3332 | |
| 3333 | |
| 3334 | |
| 3335 | |
| 3336 | |
| 3337 | |
| 3338 | |
| 3339 | |
| 3340 | |
| 3341 | |
| 3342 | class ExprWithCleanups final |
| 3343 | : public FullExpr, |
| 3344 | private llvm::TrailingObjects< |
| 3345 | ExprWithCleanups, |
| 3346 | llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>> { |
| 3347 | public: |
| 3348 | |
| 3349 | |
| 3350 | |
| 3351 | |
| 3352 | using CleanupObject = llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>; |
| 3353 | |
| 3354 | private: |
| 3355 | friend class ASTStmtReader; |
| 3356 | friend TrailingObjects; |
| 3357 | |
| 3358 | ExprWithCleanups(EmptyShell, unsigned NumObjects); |
| 3359 | ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects, |
| 3360 | ArrayRef<CleanupObject> Objects); |
| 3361 | |
| 3362 | public: |
| 3363 | static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty, |
| 3364 | unsigned numObjects); |
| 3365 | |
| 3366 | static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr, |
| 3367 | bool CleanupsHaveSideEffects, |
| 3368 | ArrayRef<CleanupObject> objects); |
| 3369 | |
| 3370 | ArrayRef<CleanupObject> getObjects() const { |
| 3371 | return llvm::makeArrayRef(getTrailingObjects<CleanupObject>(), |
| 3372 | getNumObjects()); |
| 3373 | } |
| 3374 | |
| 3375 | unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } |
| 3376 | |
| 3377 | CleanupObject getObject(unsigned i) const { |
| 3378 | assert(i < getNumObjects() && "Index out of range"); |
| 3379 | return getObjects()[i]; |
| 3380 | } |
| 3381 | |
| 3382 | bool cleanupsHaveSideEffects() const { |
| 3383 | return ExprWithCleanupsBits.CleanupsHaveSideEffects; |
| 3384 | } |
| 3385 | |
| 3386 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 3387 | return SubExpr->getBeginLoc(); |
| 3388 | } |
| 3389 | |
| 3390 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3391 | return SubExpr->getEndLoc(); |
| 3392 | } |
| 3393 | |
| 3394 | |
| 3395 | static bool classof(const Stmt *T) { |
| 3396 | return T->getStmtClass() == ExprWithCleanupsClass; |
| 3397 | } |
| 3398 | |
| 3399 | |
| 3400 | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } |
| 3401 | |
| 3402 | const_child_range children() const { |
| 3403 | return const_child_range(&SubExpr, &SubExpr + 1); |
| 3404 | } |
| 3405 | }; |
| 3406 | |
| 3407 | |
| 3408 | |
| 3409 | |
| 3410 | |
| 3411 | |
| 3412 | |
| 3413 | |
| 3414 | |
| 3415 | |
| 3416 | |
| 3417 | |
| 3418 | |
| 3419 | |
| 3420 | |
| 3421 | |
| 3422 | |
| 3423 | |
| 3424 | |
| 3425 | |
| 3426 | |
| 3427 | |
| 3428 | class CXXUnresolvedConstructExpr final |
| 3429 | : public Expr, |
| 3430 | private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> { |
| 3431 | friend class ASTStmtReader; |
| 3432 | friend TrailingObjects; |
| 3433 | |
| 3434 | |
| 3435 | TypeSourceInfo *TSI; |
| 3436 | |
| 3437 | |
| 3438 | SourceLocation LParenLoc; |
| 3439 | |
| 3440 | |
| 3441 | SourceLocation RParenLoc; |
| 3442 | |
| 3443 | CXXUnresolvedConstructExpr(QualType T, TypeSourceInfo *TSI, |
| 3444 | SourceLocation LParenLoc, ArrayRef<Expr *> Args, |
| 3445 | SourceLocation RParenLoc); |
| 3446 | |
| 3447 | CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) |
| 3448 | : Expr(CXXUnresolvedConstructExprClass, Empty), TSI(nullptr) { |
| 3449 | CXXUnresolvedConstructExprBits.NumArgs = NumArgs; |
| 3450 | } |
| 3451 | |
| 3452 | public: |
| 3453 | static CXXUnresolvedConstructExpr *Create(const ASTContext &Context, |
| 3454 | QualType T, TypeSourceInfo *TSI, |
| 3455 | SourceLocation LParenLoc, |
| 3456 | ArrayRef<Expr *> Args, |
| 3457 | SourceLocation RParenLoc); |
| 3458 | |
| 3459 | static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context, |
| 3460 | unsigned NumArgs); |
| 3461 | |
| 3462 | |
| 3463 | |
| 3464 | QualType getTypeAsWritten() const { return TSI->getType(); } |
| 3465 | |
| 3466 | |
| 3467 | |
| 3468 | TypeSourceInfo *getTypeSourceInfo() const { return TSI; } |
| 3469 | |
| 3470 | |
| 3471 | |
| 3472 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 3473 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } |
| 3474 | |
| 3475 | |
| 3476 | |
| 3477 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 3478 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
| 3479 | |
| 3480 | |
| 3481 | |
| 3482 | |
| 3483 | bool isListInitialization() const { return LParenLoc.isInvalid(); } |
| 3484 | |
| 3485 | |
| 3486 | unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; } |
| 3487 | |
| 3488 | using arg_iterator = Expr **; |
| 3489 | using arg_range = llvm::iterator_range<arg_iterator>; |
| 3490 | |
| 3491 | arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); } |
| 3492 | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } |
| 3493 | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } |
| 3494 | |
| 3495 | using const_arg_iterator = const Expr* const *; |
| 3496 | using const_arg_range = llvm::iterator_range<const_arg_iterator>; |
| 3497 | |
| 3498 | const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); } |
| 3499 | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } |
| 3500 | const_arg_range arguments() const { |
| 3501 | return const_arg_range(arg_begin(), arg_end()); |
| 3502 | } |
| 3503 | |
| 3504 | Expr *getArg(unsigned I) { |
| 3505 | assert(I < getNumArgs() && "Argument index out-of-range"); |
| 3506 | return arg_begin()[I]; |
| 3507 | } |
| 3508 | |
| 3509 | const Expr *getArg(unsigned I) const { |
| 3510 | assert(I < getNumArgs() && "Argument index out-of-range"); |
| 3511 | return arg_begin()[I]; |
| 3512 | } |
| 3513 | |
| 3514 | void setArg(unsigned I, Expr *E) { |
| 3515 | assert(I < getNumArgs() && "Argument index out-of-range"); |
| 3516 | arg_begin()[I] = E; |
| 3517 | } |
| 3518 | |
| 3519 | SourceLocation getBeginLoc() const LLVM_READONLY; |
| 3520 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3521 | if (!RParenLoc.isValid() && getNumArgs() > 0) |
| 3522 | return getArg(getNumArgs() - 1)->getEndLoc(); |
| 3523 | return RParenLoc; |
| 3524 | } |
| 3525 | |
| 3526 | static bool classof(const Stmt *T) { |
| 3527 | return T->getStmtClass() == CXXUnresolvedConstructExprClass; |
| 3528 | } |
| 3529 | |
| 3530 | |
| 3531 | child_range children() { |
| 3532 | auto **begin = reinterpret_cast<Stmt **>(arg_begin()); |
| 3533 | return child_range(begin, begin + getNumArgs()); |
| 3534 | } |
| 3535 | |
| 3536 | const_child_range children() const { |
| 3537 | auto **begin = reinterpret_cast<Stmt **>( |
| 3538 | const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin()); |
| 3539 | return const_child_range(begin, begin + getNumArgs()); |
| 3540 | } |
| 3541 | }; |
| 3542 | |
| 3543 | |
| 3544 | |
| 3545 | |
| 3546 | |
| 3547 | |
| 3548 | |
| 3549 | |
| 3550 | class CXXDependentScopeMemberExpr final |
| 3551 | : public Expr, |
| 3552 | private llvm::TrailingObjects<CXXDependentScopeMemberExpr, |
| 3553 | ASTTemplateKWAndArgsInfo, |
| 3554 | TemplateArgumentLoc, NamedDecl *> { |
| 3555 | friend class ASTStmtReader; |
| 3556 | friend class ASTStmtWriter; |
| 3557 | friend TrailingObjects; |
| 3558 | |
| 3559 | |
| 3560 | |
| 3561 | Stmt *Base; |
| 3562 | |
| 3563 | |
| 3564 | |
| 3565 | QualType BaseType; |
| 3566 | |
| 3567 | |
| 3568 | |
| 3569 | |
| 3570 | NestedNameSpecifierLoc QualifierLoc; |
| 3571 | |
| 3572 | |
| 3573 | |
| 3574 | |
| 3575 | |
| 3576 | DeclarationNameInfo MemberNameInfo; |
| 3577 | |
| 3578 | |
| 3579 | |
| 3580 | |
| 3581 | |
| 3582 | |
| 3583 | |
| 3584 | |
| 3585 | |
| 3586 | |
| 3587 | |
| 3588 | |
| 3589 | |
| 3590 | |
| 3591 | |
| 3592 | |
| 3593 | bool hasTemplateKWAndArgsInfo() const { |
| 3594 | return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo; |
| 3595 | } |
| 3596 | |
| 3597 | bool hasFirstQualifierFoundInScope() const { |
| 3598 | return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope; |
| 3599 | } |
| 3600 | |
| 3601 | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
| 3602 | return hasTemplateKWAndArgsInfo(); |
| 3603 | } |
| 3604 | |
| 3605 | unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const { |
| 3606 | return getNumTemplateArgs(); |
| 3607 | } |
| 3608 | |
| 3609 | unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const { |
| 3610 | return hasFirstQualifierFoundInScope(); |
| 3611 | } |
| 3612 | |
| 3613 | CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base, |
| 3614 | QualType BaseType, bool IsArrow, |
| 3615 | SourceLocation OperatorLoc, |
| 3616 | NestedNameSpecifierLoc QualifierLoc, |
| 3617 | SourceLocation TemplateKWLoc, |
| 3618 | NamedDecl *FirstQualifierFoundInScope, |
| 3619 | DeclarationNameInfo MemberNameInfo, |
| 3620 | const TemplateArgumentListInfo *TemplateArgs); |
| 3621 | |
| 3622 | CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo, |
| 3623 | bool HasFirstQualifierFoundInScope); |
| 3624 | |
| 3625 | public: |
| 3626 | static CXXDependentScopeMemberExpr * |
| 3627 | Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, |
| 3628 | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, |
| 3629 | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, |
| 3630 | DeclarationNameInfo MemberNameInfo, |
| 3631 | const TemplateArgumentListInfo *TemplateArgs); |
| 3632 | |
| 3633 | static CXXDependentScopeMemberExpr * |
| 3634 | CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, |
| 3635 | unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope); |
| 3636 | |
| 3637 | |
| 3638 | |
| 3639 | |
| 3640 | bool isImplicitAccess() const { |
| 3641 | if (!Base) |
| 3642 | return true; |
| 3643 | return cast<Expr>(Base)->isImplicitCXXThis(); |
| 3644 | } |
| 3645 | |
| 3646 | |
| 3647 | |
| 3648 | Expr *getBase() const { |
| 3649 | assert(!isImplicitAccess()); |
| 3650 | return cast<Expr>(Base); |
| 3651 | } |
| 3652 | |
| 3653 | QualType getBaseType() const { return BaseType; } |
| 3654 | |
| 3655 | |
| 3656 | |
| 3657 | bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; } |
| 3658 | |
| 3659 | |
| 3660 | SourceLocation getOperatorLoc() const { |
| 3661 | return CXXDependentScopeMemberExprBits.OperatorLoc; |
| 3662 | } |
| 3663 | |
| 3664 | |
| 3665 | NestedNameSpecifier *getQualifier() const { |
| 3666 | return QualifierLoc.getNestedNameSpecifier(); |
| 3667 | } |
| 3668 | |
| 3669 | |
| 3670 | |
| 3671 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
| 3672 | |
| 3673 | |
| 3674 | |
| 3675 | |
| 3676 | |
| 3677 | |
| 3678 | |
| 3679 | |
| 3680 | |
| 3681 | |
| 3682 | |
| 3683 | |
| 3684 | NamedDecl *getFirstQualifierFoundInScope() const { |
| 3685 | if (!hasFirstQualifierFoundInScope()) |
| 3686 | return nullptr; |
| 3687 | return *getTrailingObjects<NamedDecl *>(); |
| 3688 | } |
| 3689 | |
| 3690 | |
| 3691 | const DeclarationNameInfo &getMemberNameInfo() const { |
| 3692 | return MemberNameInfo; |
| 3693 | } |
| 3694 | |
| 3695 | |
| 3696 | DeclarationName getMember() const { return MemberNameInfo.getName(); } |
| 3697 | |
| 3698 | |
| 3699 | |
| 3700 | SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } |
| 3701 | |
| 3702 | |
| 3703 | |
| 3704 | SourceLocation getTemplateKeywordLoc() const { |
| 3705 | if (!hasTemplateKWAndArgsInfo()) |
| 3706 | return SourceLocation(); |
| 3707 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; |
| 3708 | } |
| 3709 | |
| 3710 | |
| 3711 | |
| 3712 | SourceLocation getLAngleLoc() const { |
| 3713 | if (!hasTemplateKWAndArgsInfo()) |
| 3714 | return SourceLocation(); |
| 3715 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; |
| 3716 | } |
| 3717 | |
| 3718 | |
| 3719 | |
| 3720 | SourceLocation getRAngleLoc() const { |
| 3721 | if (!hasTemplateKWAndArgsInfo()) |
| 3722 | return SourceLocation(); |
| 3723 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; |
| 3724 | } |
| 3725 | |
| 3726 | |
| 3727 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
| 3728 | |
| 3729 | |
| 3730 | |
| 3731 | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } |
| 3732 | |
| 3733 | |
| 3734 | |
| 3735 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { |
| 3736 | if (hasExplicitTemplateArgs()) |
| 3737 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( |
| 3738 | getTrailingObjects<TemplateArgumentLoc>(), List); |
| 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | |
| 3743 | const TemplateArgumentLoc *getTemplateArgs() const { |
| 3744 | if (!hasExplicitTemplateArgs()) |
| 3745 | return nullptr; |
| 3746 | |
| 3747 | return getTrailingObjects<TemplateArgumentLoc>(); |
| 3748 | } |
| 3749 | |
| 3750 | |
| 3751 | |
| 3752 | unsigned getNumTemplateArgs() const { |
| 3753 | if (!hasExplicitTemplateArgs()) |
| 3754 | return 0; |
| 3755 | |
| 3756 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; |
| 3757 | } |
| 3758 | |
| 3759 | ArrayRef<TemplateArgumentLoc> template_arguments() const { |
| 3760 | return {getTemplateArgs(), getNumTemplateArgs()}; |
| 3761 | } |
| 3762 | |
| 3763 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 3764 | if (!isImplicitAccess()) |
| 3765 | return Base->getBeginLoc(); |
| 3766 | if (getQualifier()) |
| 3767 | return getQualifierLoc().getBeginLoc(); |
| 3768 | return MemberNameInfo.getBeginLoc(); |
| 3769 | } |
| 3770 | |
| 3771 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3772 | if (hasExplicitTemplateArgs()) |
| 3773 | return getRAngleLoc(); |
| 3774 | return MemberNameInfo.getEndLoc(); |
| 3775 | } |
| 3776 | |
| 3777 | static bool classof(const Stmt *T) { |
| 3778 | return T->getStmtClass() == CXXDependentScopeMemberExprClass; |
| 3779 | } |
| 3780 | |
| 3781 | |
| 3782 | child_range children() { |
| 3783 | if (isImplicitAccess()) |
| 3784 | return child_range(child_iterator(), child_iterator()); |
| 3785 | return child_range(&Base, &Base + 1); |
| 3786 | } |
| 3787 | |
| 3788 | const_child_range children() const { |
| 3789 | if (isImplicitAccess()) |
| 3790 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3791 | return const_child_range(&Base, &Base + 1); |
| 3792 | } |
| 3793 | }; |
| 3794 | |
| 3795 | |
| 3796 | |
| 3797 | |
| 3798 | |
| 3799 | |
| 3800 | |
| 3801 | |
| 3802 | |
| 3803 | |
| 3804 | |
| 3805 | |
| 3806 | |
| 3807 | |
| 3808 | |
| 3809 | |
| 3810 | class UnresolvedMemberExpr final |
| 3811 | : public OverloadExpr, |
| 3812 | private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair, |
| 3813 | ASTTemplateKWAndArgsInfo, |
| 3814 | TemplateArgumentLoc> { |
| 3815 | friend class ASTStmtReader; |
| 3816 | friend class OverloadExpr; |
| 3817 | friend TrailingObjects; |
| 3818 | |
| 3819 | |
| 3820 | |
| 3821 | |
| 3822 | |
| 3823 | Stmt *Base; |
| 3824 | |
| 3825 | |
| 3826 | QualType BaseType; |
| 3827 | |
| 3828 | |
| 3829 | SourceLocation OperatorLoc; |
| 3830 | |
| 3831 | |
| 3832 | |
| 3833 | |
| 3834 | |
| 3835 | |
| 3836 | |
| 3837 | |
| 3838 | |
| 3839 | |
| 3840 | |
| 3841 | |
| 3842 | |
| 3843 | |
| 3844 | |
| 3845 | UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing, |
| 3846 | Expr *Base, QualType BaseType, bool IsArrow, |
| 3847 | SourceLocation OperatorLoc, |
| 3848 | NestedNameSpecifierLoc QualifierLoc, |
| 3849 | SourceLocation TemplateKWLoc, |
| 3850 | const DeclarationNameInfo &MemberNameInfo, |
| 3851 | const TemplateArgumentListInfo *TemplateArgs, |
| 3852 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
| 3853 | |
| 3854 | UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults, |
| 3855 | bool HasTemplateKWAndArgsInfo); |
| 3856 | |
| 3857 | unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const { |
| 3858 | return getNumDecls(); |
| 3859 | } |
| 3860 | |
| 3861 | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { |
| 3862 | return hasTemplateKWAndArgsInfo(); |
| 3863 | } |
| 3864 | |
| 3865 | public: |
| 3866 | static UnresolvedMemberExpr * |
| 3867 | Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, |
| 3868 | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, |
| 3869 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, |
| 3870 | const DeclarationNameInfo &MemberNameInfo, |
| 3871 | const TemplateArgumentListInfo *TemplateArgs, |
| 3872 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); |
| 3873 | |
| 3874 | static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context, |
| 3875 | unsigned NumResults, |
| 3876 | bool HasTemplateKWAndArgsInfo, |
| 3877 | unsigned NumTemplateArgs); |
| 3878 | |
| 3879 | |
| 3880 | |
| 3881 | |
| 3882 | |
| 3883 | bool isImplicitAccess() const; |
| 3884 | |
| 3885 | |
| 3886 | |
| 3887 | Expr *getBase() { |
| 3888 | assert(!isImplicitAccess()); |
| 3889 | return cast<Expr>(Base); |
| 3890 | } |
| 3891 | const Expr *getBase() const { |
| 3892 | assert(!isImplicitAccess()); |
| 3893 | return cast<Expr>(Base); |
| 3894 | } |
| 3895 | |
| 3896 | QualType getBaseType() const { return BaseType; } |
| 3897 | |
| 3898 | |
| 3899 | |
| 3900 | bool hasUnresolvedUsing() const { |
| 3901 | return UnresolvedMemberExprBits.HasUnresolvedUsing; |
| 3902 | } |
| 3903 | |
| 3904 | |
| 3905 | |
| 3906 | bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; } |
| 3907 | |
| 3908 | |
| 3909 | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
| 3910 | |
| 3911 | |
| 3912 | CXXRecordDecl *getNamingClass(); |
| 3913 | const CXXRecordDecl *getNamingClass() const { |
| 3914 | return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass(); |
| 3915 | } |
| 3916 | |
| 3917 | |
| 3918 | |
| 3919 | const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } |
| 3920 | |
| 3921 | |
| 3922 | DeclarationName getMemberName() const { return getName(); } |
| 3923 | |
| 3924 | |
| 3925 | |
| 3926 | SourceLocation getMemberLoc() const { return getNameLoc(); } |
| 3927 | |
| 3928 | |
| 3929 | |
| 3930 | SourceLocation getExprLoc() const LLVM_READONLY { return getMemberLoc(); } |
| 3931 | |
| 3932 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 3933 | if (!isImplicitAccess()) |
| 3934 | return Base->getBeginLoc(); |
| 3935 | if (NestedNameSpecifierLoc l = getQualifierLoc()) |
| 3936 | return l.getBeginLoc(); |
| 3937 | return getMemberNameInfo().getBeginLoc(); |
| 3938 | } |
| 3939 | |
| 3940 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 3941 | if (hasExplicitTemplateArgs()) |
| 3942 | return getRAngleLoc(); |
| 3943 | return getMemberNameInfo().getEndLoc(); |
| 3944 | } |
| 3945 | |
| 3946 | static bool classof(const Stmt *T) { |
| 3947 | return T->getStmtClass() == UnresolvedMemberExprClass; |
| 3948 | } |
| 3949 | |
| 3950 | |
| 3951 | child_range children() { |
| 3952 | if (isImplicitAccess()) |
| 3953 | return child_range(child_iterator(), child_iterator()); |
| 3954 | return child_range(&Base, &Base + 1); |
| 3955 | } |
| 3956 | |
| 3957 | const_child_range children() const { |
| 3958 | if (isImplicitAccess()) |
| 3959 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 3960 | return const_child_range(&Base, &Base + 1); |
| 3961 | } |
| 3962 | }; |
| 3963 | |
| 3964 | DeclAccessPair *OverloadExpr::getTrailingResults() { |
| 3965 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
| 3966 | return ULE->getTrailingObjects<DeclAccessPair>(); |
| 3967 | return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>(); |
| 3968 | } |
| 3969 | |
| 3970 | ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() { |
| 3971 | if (!hasTemplateKWAndArgsInfo()) |
| 3972 | return nullptr; |
| 3973 | |
| 3974 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
| 3975 | return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); |
| 3976 | return cast<UnresolvedMemberExpr>(this) |
| 3977 | ->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); |
| 3978 | } |
| 3979 | |
| 3980 | TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() { |
| 3981 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
| 3982 | return ULE->getTrailingObjects<TemplateArgumentLoc>(); |
| 3983 | return cast<UnresolvedMemberExpr>(this) |
| 3984 | ->getTrailingObjects<TemplateArgumentLoc>(); |
| 3985 | } |
| 3986 | |
| 3987 | CXXRecordDecl *OverloadExpr::getNamingClass() { |
| 3988 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) |
| 3989 | return ULE->getNamingClass(); |
| 3990 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); |
| 3991 | } |
| 3992 | |
| 3993 | |
| 3994 | |
| 3995 | |
| 3996 | |
| 3997 | class CXXNoexceptExpr : public Expr { |
| 3998 | friend class ASTStmtReader; |
| 3999 | |
| 4000 | Stmt *Operand; |
| 4001 | SourceRange Range; |
| 4002 | |
| 4003 | public: |
| 4004 | CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, |
| 4005 | SourceLocation Keyword, SourceLocation RParen) |
| 4006 | : Expr(CXXNoexceptExprClass, Ty, VK_PRValue, OK_Ordinary), |
| 4007 | Operand(Operand), Range(Keyword, RParen) { |
| 4008 | CXXNoexceptExprBits.Value = Val == CT_Cannot; |
| 4009 | setDependence(computeDependence(this, Val)); |
| 4010 | } |
| 4011 | |
| 4012 | CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {} |
| 4013 | |
| 4014 | Expr *getOperand() const { return static_cast<Expr *>(Operand); } |
| 4015 | |
| 4016 | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
| 4017 | SourceLocation getEndLoc() const { return Range.getEnd(); } |
| 4018 | SourceRange getSourceRange() const { return Range; } |
| 4019 | |
| 4020 | bool getValue() const { return CXXNoexceptExprBits.Value; } |
| 4021 | |
| 4022 | static bool classof(const Stmt *T) { |
| 4023 | return T->getStmtClass() == CXXNoexceptExprClass; |
| 4024 | } |
| 4025 | |
| 4026 | |
| 4027 | child_range children() { return child_range(&Operand, &Operand + 1); } |
| 4028 | |
| 4029 | const_child_range children() const { |
| 4030 | return const_child_range(&Operand, &Operand + 1); |
| 4031 | } |
| 4032 | }; |
| 4033 | |
| 4034 | |
| 4035 | |
| 4036 | |
| 4037 | |
| 4038 | |
| 4039 | |
| 4040 | |
| 4041 | |
| 4042 | |
| 4043 | |
| 4044 | |
| 4045 | |
| 4046 | |
| 4047 | |
| 4048 | |
| 4049 | |
| 4050 | |
| 4051 | class PackExpansionExpr : public Expr { |
| 4052 | friend class ASTStmtReader; |
| 4053 | friend class ASTStmtWriter; |
| 4054 | |
| 4055 | SourceLocation EllipsisLoc; |
| 4056 | |
| 4057 | |
| 4058 | |
| 4059 | |
| 4060 | |
| 4061 | |
| 4062 | unsigned NumExpansions; |
| 4063 | |
| 4064 | Stmt *Pattern; |
| 4065 | |
| 4066 | public: |
| 4067 | PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, |
| 4068 | Optional<unsigned> NumExpansions) |
| 4069 | : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), |
| 4070 | Pattern->getObjectKind()), |
| 4071 | EllipsisLoc(EllipsisLoc), |
| 4072 | NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), |
| 4073 | Pattern(Pattern) { |
| 4074 | setDependence(computeDependence(this)); |
| 4075 | } |
| 4076 | |
| 4077 | PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {} |
| 4078 | |
| 4079 | |
| 4080 | Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } |
| 4081 | |
| 4082 | |
| 4083 | const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } |
| 4084 | |
| 4085 | |
| 4086 | |
| 4087 | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } |
| 4088 | |
| 4089 | |
| 4090 | |
| 4091 | Optional<unsigned> getNumExpansions() const { |
| 4092 | if (NumExpansions) |
| 4093 | return NumExpansions - 1; |
| 4094 | |
| 4095 | return None; |
| 4096 | } |
| 4097 | |
| 4098 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 4099 | return Pattern->getBeginLoc(); |
| 4100 | } |
| 4101 | |
| 4102 | SourceLocation getEndLoc() const LLVM_READONLY { return EllipsisLoc; } |
| 4103 | |
| 4104 | static bool classof(const Stmt *T) { |
| 4105 | return T->getStmtClass() == PackExpansionExprClass; |
| 4106 | } |
| 4107 | |
| 4108 | |
| 4109 | child_range children() { |
| 4110 | return child_range(&Pattern, &Pattern + 1); |
| 4111 | } |
| 4112 | |
| 4113 | const_child_range children() const { |
| 4114 | return const_child_range(&Pattern, &Pattern + 1); |
| 4115 | } |
| 4116 | }; |
| 4117 | |
| 4118 | |
| 4119 | |
| 4120 | |
| 4121 | |
| 4122 | |
| 4123 | |
| 4124 | |
| 4125 | |
| 4126 | |
| 4127 | class SizeOfPackExpr final |
| 4128 | : public Expr, |
| 4129 | private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> { |
| 4130 | friend class ASTStmtReader; |
| 4131 | friend class ASTStmtWriter; |
| 4132 | friend TrailingObjects; |
| 4133 | |
| 4134 | |
| 4135 | SourceLocation OperatorLoc; |
| 4136 | |
| 4137 | |
| 4138 | SourceLocation PackLoc; |
| 4139 | |
| 4140 | |
| 4141 | SourceLocation RParenLoc; |
| 4142 | |
| 4143 | |
| 4144 | |
| 4145 | |
| 4146 | |
| 4147 | |
| 4148 | |
| 4149 | |
| 4150 | |
| 4151 | |
| 4152 | |
| 4153 | unsigned Length; |
| 4154 | |
| 4155 | |
| 4156 | NamedDecl *Pack = nullptr; |
| 4157 | |
| 4158 | |
| 4159 | |
| 4160 | SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, |
| 4161 | SourceLocation PackLoc, SourceLocation RParenLoc, |
| 4162 | Optional<unsigned> Length, |
| 4163 | ArrayRef<TemplateArgument> PartialArgs) |
| 4164 | : Expr(SizeOfPackExprClass, SizeType, VK_PRValue, OK_Ordinary), |
| 4165 | OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), |
| 4166 | Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { |
| 4167 | assert((!Length || PartialArgs.empty()) && |
| 4168 | "have partial args for non-dependent sizeof... expression"); |
| 4169 | auto *Args = getTrailingObjects<TemplateArgument>(); |
| 4170 | std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args); |
| 4171 | setDependence(Length ? ExprDependence::None |
| 4172 | : ExprDependence::ValueInstantiation); |
| 4173 | } |
| 4174 | |
| 4175 | |
| 4176 | SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs) |
| 4177 | : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {} |
| 4178 | |
| 4179 | public: |
| 4180 | static SizeOfPackExpr *Create(ASTContext &Context, SourceLocation OperatorLoc, |
| 4181 | NamedDecl *Pack, SourceLocation PackLoc, |
| 4182 | SourceLocation RParenLoc, |
| 4183 | Optional<unsigned> Length = None, |
| 4184 | ArrayRef<TemplateArgument> PartialArgs = None); |
| 4185 | static SizeOfPackExpr *CreateDeserialized(ASTContext &Context, |
| 4186 | unsigned NumPartialArgs); |
| 4187 | |
| 4188 | |
| 4189 | SourceLocation getOperatorLoc() const { return OperatorLoc; } |
| 4190 | |
| 4191 | |
| 4192 | SourceLocation getPackLoc() const { return PackLoc; } |
| 4193 | |
| 4194 | |
| 4195 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 4196 | |
| 4197 | |
| 4198 | NamedDecl *getPack() const { return Pack; } |
| 4199 | |
| 4200 | |
| 4201 | |
| 4202 | |
| 4203 | |
| 4204 | unsigned getPackLength() const { |
| 4205 | assert(!isValueDependent() && |
| 4206 | "Cannot get the length of a value-dependent pack size expression"); |
| 4207 | return Length; |
| 4208 | } |
| 4209 | |
| 4210 | |
| 4211 | |
| 4212 | |
| 4213 | |
| 4214 | |
| 4215 | bool isPartiallySubstituted() const { |
| 4216 | return isValueDependent() && Length; |
| 4217 | } |
| 4218 | |
| 4219 | |
| 4220 | ArrayRef<TemplateArgument> getPartialArguments() const { |
| 4221 | assert(isPartiallySubstituted()); |
| 4222 | const auto *Args = getTrailingObjects<TemplateArgument>(); |
| 4223 | return llvm::makeArrayRef(Args, Args + Length); |
| 4224 | } |
| 4225 | |
| 4226 | SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; } |
| 4227 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
| 4228 | |
| 4229 | static bool classof(const Stmt *T) { |
| 4230 | return T->getStmtClass() == SizeOfPackExprClass; |
| 4231 | } |
| 4232 | |
| 4233 | |
| 4234 | child_range children() { |
| 4235 | return child_range(child_iterator(), child_iterator()); |
| 4236 | } |
| 4237 | |
| 4238 | const_child_range children() const { |
| 4239 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 4240 | } |
| 4241 | }; |
| 4242 | |
| 4243 | |
| 4244 | |
| 4245 | class SubstNonTypeTemplateParmExpr : public Expr { |
| 4246 | friend class ASTReader; |
| 4247 | friend class ASTStmtReader; |
| 4248 | |
| 4249 | |
| 4250 | |
| 4251 | |
| 4252 | llvm::PointerIntPair<NonTypeTemplateParmDecl*, 1, bool> ParamAndRef; |
| 4253 | |
| 4254 | |
| 4255 | Stmt *Replacement; |
| 4256 | |
| 4257 | explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) |
| 4258 | : Expr(SubstNonTypeTemplateParmExprClass, Empty) {} |
| 4259 | |
| 4260 | public: |
| 4261 | SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind, |
| 4262 | SourceLocation Loc, |
| 4263 | NonTypeTemplateParmDecl *Param, bool RefParam, |
| 4264 | Expr *Replacement) |
| 4265 | : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary), |
| 4266 | ParamAndRef(Param, RefParam), Replacement(Replacement) { |
| 4267 | SubstNonTypeTemplateParmExprBits.NameLoc = Loc; |
| 4268 | setDependence(computeDependence(this)); |
| 4269 | } |
| 4270 | |
| 4271 | SourceLocation getNameLoc() const { |
| 4272 | return SubstNonTypeTemplateParmExprBits.NameLoc; |
| 4273 | } |
| 4274 | SourceLocation getBeginLoc() const { return getNameLoc(); } |
| 4275 | SourceLocation getEndLoc() const { return getNameLoc(); } |
| 4276 | |
| 4277 | Expr *getReplacement() const { return cast<Expr>(Replacement); } |
| 4278 | |
| 4279 | NonTypeTemplateParmDecl *getParameter() const { |
| 4280 | return ParamAndRef.getPointer(); |
| 4281 | } |
| 4282 | |
| 4283 | bool isReferenceParameter() const { return ParamAndRef.getInt(); } |
| 4284 | |
| 4285 | |
| 4286 | QualType getParameterType(const ASTContext &Ctx) const; |
| 4287 | |
| 4288 | static bool classof(const Stmt *s) { |
| 4289 | return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; |
| 4290 | } |
| 4291 | |
| 4292 | |
| 4293 | child_range children() { return child_range(&Replacement, &Replacement + 1); } |
| 4294 | |
| 4295 | const_child_range children() const { |
| 4296 | return const_child_range(&Replacement, &Replacement + 1); |
| 4297 | } |
| 4298 | }; |
| 4299 | |
| 4300 | |
| 4301 | |
| 4302 | |
| 4303 | |
| 4304 | |
| 4305 | |
| 4306 | |
| 4307 | |
| 4308 | |
| 4309 | |
| 4310 | |
| 4311 | |
| 4312 | class SubstNonTypeTemplateParmPackExpr : public Expr { |
| 4313 | friend class ASTReader; |
| 4314 | friend class ASTStmtReader; |
| 4315 | |
| 4316 | |
| 4317 | NonTypeTemplateParmDecl *Param; |
| 4318 | |
| 4319 | |
| 4320 | |
| 4321 | const TemplateArgument *Arguments; |
| 4322 | |
| 4323 | |
| 4324 | unsigned NumArguments; |
| 4325 | |
| 4326 | |
| 4327 | SourceLocation NameLoc; |
| 4328 | |
| 4329 | explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) |
| 4330 | : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {} |
| 4331 | |
| 4332 | public: |
| 4333 | SubstNonTypeTemplateParmPackExpr(QualType T, |
| 4334 | ExprValueKind ValueKind, |
| 4335 | NonTypeTemplateParmDecl *Param, |
| 4336 | SourceLocation NameLoc, |
| 4337 | const TemplateArgument &ArgPack); |
| 4338 | |
| 4339 | |
| 4340 | NonTypeTemplateParmDecl *getParameterPack() const { return Param; } |
| 4341 | |
| 4342 | |
| 4343 | SourceLocation getParameterPackLocation() const { return NameLoc; } |
| 4344 | |
| 4345 | |
| 4346 | |
| 4347 | TemplateArgument getArgumentPack() const; |
| 4348 | |
| 4349 | SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } |
| 4350 | SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } |
| 4351 | |
| 4352 | static bool classof(const Stmt *T) { |
| 4353 | return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; |
| 4354 | } |
| 4355 | |
| 4356 | |
| 4357 | child_range children() { |
| 4358 | return child_range(child_iterator(), child_iterator()); |
| 4359 | } |
| 4360 | |
| 4361 | const_child_range children() const { |
| 4362 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 4363 | } |
| 4364 | }; |
| 4365 | |
| 4366 | |
| 4367 | |
| 4368 | |
| 4369 | |
| 4370 | |
| 4371 | |
| 4372 | |
| 4373 | |
| 4374 | |
| 4375 | |
| 4376 | |
| 4377 | |
| 4378 | |
| 4379 | |
| 4380 | class FunctionParmPackExpr final |
| 4381 | : public Expr, |
| 4382 | private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> { |
| 4383 | friend class ASTReader; |
| 4384 | friend class ASTStmtReader; |
| 4385 | friend TrailingObjects; |
| 4386 | |
| 4387 | |
| 4388 | VarDecl *ParamPack; |
| 4389 | |
| 4390 | |
| 4391 | SourceLocation NameLoc; |
| 4392 | |
| 4393 | |
| 4394 | unsigned NumParameters; |
| 4395 | |
| 4396 | FunctionParmPackExpr(QualType T, VarDecl *ParamPack, |
| 4397 | SourceLocation NameLoc, unsigned NumParams, |
| 4398 | VarDecl *const *Params); |
| 4399 | |
| 4400 | public: |
| 4401 | static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, |
| 4402 | VarDecl *ParamPack, |
| 4403 | SourceLocation NameLoc, |
| 4404 | ArrayRef<VarDecl *> Params); |
| 4405 | static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, |
| 4406 | unsigned NumParams); |
| 4407 | |
| 4408 | |
| 4409 | VarDecl *getParameterPack() const { return ParamPack; } |
| 4410 | |
| 4411 | |
| 4412 | SourceLocation getParameterPackLocation() const { return NameLoc; } |
| 4413 | |
| 4414 | |
| 4415 | |
| 4416 | using iterator = VarDecl * const *; |
| 4417 | iterator begin() const { return getTrailingObjects<VarDecl *>(); } |
| 4418 | iterator end() const { return begin() + NumParameters; } |
| 4419 | |
| 4420 | |
| 4421 | unsigned getNumExpansions() const { return NumParameters; } |
| 4422 | |
| 4423 | |
| 4424 | VarDecl *getExpansion(unsigned I) const { return begin()[I]; } |
| 4425 | |
| 4426 | SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } |
| 4427 | SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } |
| 4428 | |
| 4429 | static bool classof(const Stmt *T) { |
| 4430 | return T->getStmtClass() == FunctionParmPackExprClass; |
| 4431 | } |
| 4432 | |
| 4433 | child_range children() { |
| 4434 | return child_range(child_iterator(), child_iterator()); |
| 4435 | } |
| 4436 | |
| 4437 | const_child_range children() const { |
| 4438 | return const_child_range(const_child_iterator(), const_child_iterator()); |
| 4439 | } |
| 4440 | }; |
| 4441 | |
| 4442 | |
| 4443 | |
| 4444 | |
| 4445 | |
| 4446 | |
| 4447 | |
| 4448 | |
| 4449 | |
| 4450 | |
| 4451 | |
| 4452 | |
| 4453 | |
| 4454 | |
| 4455 | |
| 4456 | |
| 4457 | |
| 4458 | |
| 4459 | |
| 4460 | |
| 4461 | |
| 4462 | class MaterializeTemporaryExpr : public Expr { |
| 4463 | private: |
| 4464 | friend class ASTStmtReader; |
| 4465 | friend class ASTStmtWriter; |
| 4466 | |
| 4467 | llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State; |
| 4468 | |
| 4469 | public: |
| 4470 | MaterializeTemporaryExpr(QualType T, Expr *Temporary, |
| 4471 | bool BoundToLvalueReference, |
| 4472 | LifetimeExtendedTemporaryDecl *MTD = nullptr); |
| 4473 | |
| 4474 | MaterializeTemporaryExpr(EmptyShell Empty) |
| 4475 | : Expr(MaterializeTemporaryExprClass, Empty) {} |
| 4476 | |
| 4477 | |
| 4478 | |
| 4479 | Expr *getSubExpr() const { |
| 4480 | return cast<Expr>( |
| 4481 | State.is<Stmt *>() |
| 4482 | ? State.get<Stmt *>() |
| 4483 | : State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr()); |
| 4484 | } |
| 4485 | |
| 4486 | |
| 4487 | StorageDuration getStorageDuration() const { |
| 4488 | return State.is<Stmt *>() ? SD_FullExpression |
| 4489 | : State.get<LifetimeExtendedTemporaryDecl *>() |
| 4490 | ->getStorageDuration(); |
| 4491 | } |
| 4492 | |
| 4493 | |
| 4494 | |
| 4495 | APValue *getOrCreateValue(bool MayCreate) const { |
| 4496 | assert(State.is<LifetimeExtendedTemporaryDecl *>() && |
| 4497 | "the temporary has not been lifetime extended"); |
| 4498 | return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue( |
| 4499 | MayCreate); |
| 4500 | } |
| 4501 | |
| 4502 | LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl() { |
| 4503 | return State.dyn_cast<LifetimeExtendedTemporaryDecl *>(); |
| 4504 | } |
| 4505 | const LifetimeExtendedTemporaryDecl * |
| 4506 | getLifetimeExtendedTemporaryDecl() const { |
| 4507 | return State.dyn_cast<LifetimeExtendedTemporaryDecl *>(); |
| 4508 | } |
| 4509 | |
| 4510 | |
| 4511 | |
| 4512 | ValueDecl *getExtendingDecl() { |
| 4513 | return State.is<Stmt *>() ? nullptr |
| 4514 | : State.get<LifetimeExtendedTemporaryDecl *>() |
| 4515 | ->getExtendingDecl(); |
| 4516 | } |
| 4517 | const ValueDecl *getExtendingDecl() const { |
| 4518 | return const_cast<MaterializeTemporaryExpr *>(this)->getExtendingDecl(); |
| 4519 | } |
| 4520 | |
| 4521 | void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber); |
| 4522 | |
| 4523 | unsigned getManglingNumber() const { |
| 4524 | return State.is<Stmt *>() ? 0 |
| 4525 | : State.get<LifetimeExtendedTemporaryDecl *>() |
| 4526 | ->getManglingNumber(); |
| 4527 | } |
| 4528 | |
| 4529 | |
| 4530 | |
| 4531 | bool isBoundToLvalueReference() const { return isLValue(); } |
| 4532 | |
| 4533 | |
| 4534 | |
| 4535 | bool isUsableInConstantExpressions(const ASTContext &Context) const; |
| 4536 | |
| 4537 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 4538 | return getSubExpr()->getBeginLoc(); |
| 4539 | } |
| 4540 | |
| 4541 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 4542 | return getSubExpr()->getEndLoc(); |
| 4543 | } |
| 4544 | |
| 4545 | static bool classof(const Stmt *T) { |
| 4546 | return T->getStmtClass() == MaterializeTemporaryExprClass; |
| 4547 | } |
| 4548 | |
| 4549 | |
| 4550 | child_range children() { |
| 4551 | return State.is<Stmt *>() |
| 4552 | ? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1) |
| 4553 | : State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr(); |
| 4554 | } |
| 4555 | |
| 4556 | const_child_range children() const { |
| 4557 | return State.is<Stmt *>() |
| 4558 | ? const_child_range(State.getAddrOfPtr1(), |
| 4559 | State.getAddrOfPtr1() + 1) |
| 4560 | : const_cast<const LifetimeExtendedTemporaryDecl *>( |
| 4561 | State.get<LifetimeExtendedTemporaryDecl *>()) |
| 4562 | ->childrenExpr(); |
| 4563 | } |
| 4564 | }; |
| 4565 | |
| 4566 | |
| 4567 | |
| 4568 | |
| 4569 | |
| 4570 | |
| 4571 | |
| 4572 | |
| 4573 | |
| 4574 | class CXXFoldExpr : public Expr { |
| 4575 | friend class ASTStmtReader; |
| 4576 | friend class ASTStmtWriter; |
| 4577 | |
| 4578 | enum SubExpr { Callee, LHS, RHS, Count }; |
| 4579 | |
| 4580 | SourceLocation LParenLoc; |
| 4581 | SourceLocation EllipsisLoc; |
| 4582 | SourceLocation RParenLoc; |
| 4583 | |
| 4584 | |
| 4585 | unsigned NumExpansions; |
| 4586 | Stmt *SubExprs[SubExpr::Count]; |
| 4587 | BinaryOperatorKind Opcode; |
| 4588 | |
| 4589 | public: |
| 4590 | CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee, |
| 4591 | SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode, |
| 4592 | SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, |
| 4593 | Optional<unsigned> NumExpansions) |
| 4594 | : Expr(CXXFoldExprClass, T, VK_PRValue, OK_Ordinary), |
| 4595 | LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), |
| 4596 | NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) { |
| 4597 | SubExprs[SubExpr::Callee] = Callee; |
| 4598 | SubExprs[SubExpr::LHS] = LHS; |
| 4599 | SubExprs[SubExpr::RHS] = RHS; |
| 4600 | setDependence(computeDependence(this)); |
| 4601 | } |
| 4602 | |
| 4603 | CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {} |
| 4604 | |
| 4605 | UnresolvedLookupExpr *getCallee() const { |
| 4606 | return static_cast<UnresolvedLookupExpr *>(SubExprs[SubExpr::Callee]); |
| 4607 | } |
| 4608 | Expr *getLHS() const { return static_cast<Expr*>(SubExprs[SubExpr::LHS]); } |
| 4609 | Expr *getRHS() const { return static_cast<Expr*>(SubExprs[SubExpr::RHS]); } |
| 4610 | |
| 4611 | |
| 4612 | bool isRightFold() const { |
| 4613 | return getLHS() && getLHS()->containsUnexpandedParameterPack(); |
| 4614 | } |
| 4615 | |
| 4616 | |
| 4617 | bool isLeftFold() const { return !isRightFold(); } |
| 4618 | |
| 4619 | |
| 4620 | Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); } |
| 4621 | |
| 4622 | |
| 4623 | Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); } |
| 4624 | |
| 4625 | SourceLocation getLParenLoc() const { return LParenLoc; } |
| 4626 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 4627 | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } |
| 4628 | BinaryOperatorKind getOperator() const { return Opcode; } |
| 4629 | |
| 4630 | Optional<unsigned> getNumExpansions() const { |
| 4631 | if (NumExpansions) |
| 4632 | return NumExpansions - 1; |
| 4633 | return None; |
| 4634 | } |
| 4635 | |
| 4636 | SourceLocation getBeginLoc() const LLVM_READONLY { |
| 4637 | if (LParenLoc.isValid()) |
| 4638 | return LParenLoc; |
| 4639 | if (isLeftFold()) |
| 4640 | return getEllipsisLoc(); |
| 4641 | return getLHS()->getBeginLoc(); |
| 4642 | } |
| 4643 | |
| 4644 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 4645 | if (RParenLoc.isValid()) |
| 4646 | return RParenLoc; |
| 4647 | if (isRightFold()) |
| 4648 | return getEllipsisLoc(); |
| 4649 | return getRHS()->getEndLoc(); |
| 4650 | } |
| 4651 | |
| 4652 | static bool classof(const Stmt *T) { |
| 4653 | return T->getStmtClass() == CXXFoldExprClass; |
| 4654 | } |
| 4655 | |
| 4656 | |
| 4657 | child_range children() { |
| 4658 | return child_range(SubExprs, SubExprs + SubExpr::Count); |
| 4659 | } |
| 4660 | |
| 4661 | const_child_range children() const { |
| 4662 | return const_child_range(SubExprs, SubExprs + SubExpr::Count); |
| 4663 | } |
| 4664 | }; |
| 4665 | |
| 4666 | |
| 4667 | |
| 4668 | |
| 4669 | |
| 4670 | |
| 4671 | |
| 4672 | |
| 4673 | |
| 4674 | |
| 4675 | |
| 4676 | |
| 4677 | |
| 4678 | |
| 4679 | class CoroutineSuspendExpr : public Expr { |
| 4680 | friend class ASTStmtReader; |
| 4681 | |
| 4682 | SourceLocation KeywordLoc; |
| 4683 | |
| 4684 | enum SubExpr { Common, Ready, Suspend, Resume, Count }; |
| 4685 | |
| 4686 | Stmt *SubExprs[SubExpr::Count]; |
| 4687 | OpaqueValueExpr *OpaqueValue = nullptr; |
| 4688 | |
| 4689 | public: |
| 4690 | CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Common, |
| 4691 | Expr *Ready, Expr *Suspend, Expr *Resume, |
| 4692 | OpaqueValueExpr *OpaqueValue) |
| 4693 | : Expr(SC, Resume->getType(), Resume->getValueKind(), |
| 4694 | Resume->getObjectKind()), |
| 4695 | KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) { |
| 4696 | SubExprs[SubExpr::Common] = Common; |
| 4697 | SubExprs[SubExpr::Ready] = Ready; |
| 4698 | SubExprs[SubExpr::Suspend] = Suspend; |
| 4699 | SubExprs[SubExpr::Resume] = Resume; |
| 4700 | setDependence(computeDependence(this)); |
| 4701 | } |
| 4702 | |
| 4703 | CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty, |
| 4704 | Expr *Common) |
| 4705 | : Expr(SC, Ty, VK_PRValue, OK_Ordinary), KeywordLoc(KeywordLoc) { |
| 4706 | assert(Common->isTypeDependent() && Ty->isDependentType() && |
| 4707 | "wrong constructor for non-dependent co_await/co_yield expression"); |
| 4708 | SubExprs[SubExpr::Common] = Common; |
| 4709 | SubExprs[SubExpr::Ready] = nullptr; |
| 4710 | SubExprs[SubExpr::Suspend] = nullptr; |
| 4711 | SubExprs[SubExpr::Resume] = nullptr; |
| 4712 | setDependence(computeDependence(this)); |
| 4713 | } |
| 4714 | |
| 4715 | CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { |
| 4716 | SubExprs[SubExpr::Common] = nullptr; |
| 4717 | SubExprs[SubExpr::Ready] = nullptr; |
| 4718 | SubExprs[SubExpr::Suspend] = nullptr; |
| 4719 | SubExprs[SubExpr::Resume] = nullptr; |
| 4720 | } |
| 4721 | |
| 4722 | SourceLocation getKeywordLoc() const { return KeywordLoc; } |
| 4723 | |
| 4724 | Expr *getCommonExpr() const { |
| 4725 | return static_cast<Expr*>(SubExprs[SubExpr::Common]); |
| 4726 | } |
| 4727 | |
| 4728 | |
| 4729 | OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } |
| 4730 | |
| 4731 | Expr *getReadyExpr() const { |
| 4732 | return static_cast<Expr*>(SubExprs[SubExpr::Ready]); |
| 4733 | } |
| 4734 | |
| 4735 | Expr *getSuspendExpr() const { |
| 4736 | return static_cast<Expr*>(SubExprs[SubExpr::Suspend]); |
| 4737 | } |
| 4738 | |
| 4739 | Expr *getResumeExpr() const { |
| 4740 | return static_cast<Expr*>(SubExprs[SubExpr::Resume]); |
| 4741 | } |
| 4742 | |
| 4743 | SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; } |
| 4744 | |
| 4745 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 4746 | return getCommonExpr()->getEndLoc(); |
| 4747 | } |
| 4748 | |
| 4749 | child_range children() { |
| 4750 | return child_range(SubExprs, SubExprs + SubExpr::Count); |
| 4751 | } |
| 4752 | |
| 4753 | const_child_range children() const { |
| 4754 | return const_child_range(SubExprs, SubExprs + SubExpr::Count); |
| 4755 | } |
| 4756 | |
| 4757 | static bool classof(const Stmt *T) { |
| 4758 | return T->getStmtClass() == CoawaitExprClass || |
| 4759 | T->getStmtClass() == CoyieldExprClass; |
| 4760 | } |
| 4761 | }; |
| 4762 | |
| 4763 | |
| 4764 | class CoawaitExpr : public CoroutineSuspendExpr { |
| 4765 | friend class ASTStmtReader; |
| 4766 | |
| 4767 | public: |
| 4768 | CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Ready, |
| 4769 | Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue, |
| 4770 | bool IsImplicit = false) |
| 4771 | : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Ready, |
| 4772 | Suspend, Resume, OpaqueValue) { |
| 4773 | CoawaitBits.IsImplicit = IsImplicit; |
| 4774 | } |
| 4775 | |
| 4776 | CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand, |
| 4777 | bool IsImplicit = false) |
| 4778 | : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand) { |
| 4779 | CoawaitBits.IsImplicit = IsImplicit; |
| 4780 | } |
| 4781 | |
| 4782 | CoawaitExpr(EmptyShell Empty) |
| 4783 | : CoroutineSuspendExpr(CoawaitExprClass, Empty) {} |
| 4784 | |
| 4785 | Expr *getOperand() const { |
| 4786 | |
| 4787 | return getCommonExpr(); |
| 4788 | } |
| 4789 | |
| 4790 | bool isImplicit() const { return CoawaitBits.IsImplicit; } |
| 4791 | void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; } |
| 4792 | |
| 4793 | static bool classof(const Stmt *T) { |
| 4794 | return T->getStmtClass() == CoawaitExprClass; |
| 4795 | } |
| 4796 | }; |
| 4797 | |
| 4798 | |
| 4799 | |
| 4800 | class DependentCoawaitExpr : public Expr { |
| 4801 | friend class ASTStmtReader; |
| 4802 | |
| 4803 | SourceLocation KeywordLoc; |
| 4804 | Stmt *SubExprs[2]; |
| 4805 | |
| 4806 | public: |
| 4807 | DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op, |
| 4808 | UnresolvedLookupExpr *OpCoawait) |
| 4809 | : Expr(DependentCoawaitExprClass, Ty, VK_PRValue, OK_Ordinary), |
| 4810 | KeywordLoc(KeywordLoc) { |
| 4811 | |
| 4812 | |
| 4813 | assert(Ty->isDependentType() && |
| 4814 | "wrong constructor for non-dependent co_await/co_yield expression"); |
| 4815 | SubExprs[0] = Op; |
| 4816 | SubExprs[1] = OpCoawait; |
| 4817 | setDependence(computeDependence(this)); |
| 4818 | } |
| 4819 | |
| 4820 | DependentCoawaitExpr(EmptyShell Empty) |
| 4821 | : Expr(DependentCoawaitExprClass, Empty) {} |
| 4822 | |
| 4823 | Expr *getOperand() const { return cast<Expr>(SubExprs[0]); } |
| 4824 | |
| 4825 | UnresolvedLookupExpr *getOperatorCoawaitLookup() const { |
| 4826 | return cast<UnresolvedLookupExpr>(SubExprs[1]); |
| 4827 | } |
| 4828 | |
| 4829 | SourceLocation getKeywordLoc() const { return KeywordLoc; } |
| 4830 | |
| 4831 | SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; } |
| 4832 | |
| 4833 | SourceLocation getEndLoc() const LLVM_READONLY { |
| 4834 | return getOperand()->getEndLoc(); |
| 4835 | } |
| 4836 | |
| 4837 | child_range children() { return child_range(SubExprs, SubExprs + 2); } |
| 4838 | |
| 4839 | const_child_range children() const { |
| 4840 | return const_child_range(SubExprs, SubExprs + 2); |
| 4841 | } |
| 4842 | |
| 4843 | static bool classof(const Stmt *T) { |
| 4844 | return T->getStmtClass() == DependentCoawaitExprClass; |
| 4845 | } |
| 4846 | }; |
| 4847 | |
| 4848 | |
| 4849 | class CoyieldExpr : public CoroutineSuspendExpr { |
| 4850 | friend class ASTStmtReader; |
| 4851 | |
| 4852 | public: |
| 4853 | CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Ready, |
| 4854 | Expr *Suspend, Expr *Resume, OpaqueValueExpr *OpaqueValue) |
| 4855 | : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Ready, |
| 4856 | Suspend, Resume, OpaqueValue) {} |
| 4857 | CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand) |
| 4858 | : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand) {} |
| 4859 | CoyieldExpr(EmptyShell Empty) |
| 4860 | : CoroutineSuspendExpr(CoyieldExprClass, Empty) {} |
| 4861 | |
| 4862 | Expr *getOperand() const { |
| 4863 | |
| 4864 | return getCommonExpr(); |
| 4865 | } |
| 4866 | |
| 4867 | static bool classof(const Stmt *T) { |
| 4868 | return T->getStmtClass() == CoyieldExprClass; |
| 4869 | } |
| 4870 | }; |
| 4871 | |
| 4872 | |
| 4873 | |
| 4874 | |
| 4875 | class BuiltinBitCastExpr final |
| 4876 | : public ExplicitCastExpr, |
| 4877 | private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> { |
| 4878 | friend class ASTStmtReader; |
| 4879 | friend class CastExpr; |
| 4880 | friend TrailingObjects; |
| 4881 | |
| 4882 | SourceLocation KWLoc; |
| 4883 | SourceLocation RParenLoc; |
| 4884 | |
| 4885 | public: |
| 4886 | BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr, |
| 4887 | TypeSourceInfo *DstType, SourceLocation KWLoc, |
| 4888 | SourceLocation RParenLoc) |
| 4889 | : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, false, |
| 4890 | DstType), |
| 4891 | KWLoc(KWLoc), RParenLoc(RParenLoc) {} |
| 4892 | BuiltinBitCastExpr(EmptyShell Empty) |
| 4893 | : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {} |
| 4894 | |
| 4895 | SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; } |
| 4896 | SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; } |
| 4897 | |
| 4898 | static bool classof(const Stmt *T) { |
| 4899 | return T->getStmtClass() == BuiltinBitCastExprClass; |
| 4900 | } |
| 4901 | }; |
| 4902 | |
| 4903 | } |
| 4904 | |
| 4905 | #endif // LLVM_CLANG_AST_EXPRCXX_H |