Lines Matching +full:ovl +full:- +full:2 +full:l
1 //===--- SemaExpr.cpp - Semantic Analysis for Expressions -----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
73 // See if this is an auto-typed variable whose initializer we are parsing. in CanUseDecl()
79 if (FD->isDeleted()) in CanUseDecl()
84 if (getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() && in CanUseDecl()
96 if (TreatUnavailableAsInvalid && D->getAvailability() == AR_Unavailable && in CanUseDecl()
97 cast<Decl>(CurContext)->getAvailability() != AR_Unavailable) in CanUseDecl()
108 if (const auto *A = D->getAttr<UnusedAttr>()) { in DiagnoseUnusedOfDecl()
111 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused && in DiagnoseUnusedOfDecl()
112 A->getSemanticSpelling() != UnusedAttr::C23_maybe_unused) { in DiagnoseUnusedOfDecl()
114 if (DC && !DC->hasAttr<UnusedAttr>()) in DiagnoseUnusedOfDecl()
121 assert(Decl && Decl->isDeleted()); in NoteDeletedFunction()
123 if (Decl->isDefaulted()) { in NoteDeletedFunction()
125 if (!Decl->isImplicit()) in NoteDeletedFunction()
126 Diag(Decl->getLocation(), diag::note_implicitly_deleted); in NoteDeletedFunction()
135 if (Ctor && Ctor->isInheritingConstructor()) in NoteDeletedFunction()
138 Diag(Decl->getLocation(), diag::note_availability_specified_here) in NoteDeletedFunction()
145 for (auto *I : D->redecls()) { in hasAnyExplicitStorageClass()
146 if (I->getStorageClass() != SC_None) in hasAnyExplicitStorageClass()
173 if (!Current->isInlined()) in diagnoseUseOfInternalDeclInInlineFunction()
175 if (!Current->isExternallyVisible()) in diagnoseUseOfInternalDeclInInlineFunction()
179 if (D->getFormalLinkage() != Linkage::Internal) in diagnoseUseOfInternalDeclInInlineFunction()
185 // (2) the thing we're referencing is a pure function. in diagnoseUseOfInternalDeclInInlineFunction()
192 DowngradeWarning = UsedFn->isInlined() || UsedFn->hasAttr<ConstAttr>(); in diagnoseUseOfInternalDeclInInlineFunction()
200 S.Diag(D->getCanonicalDecl()->getLocation(), diag::note_entity_declared_at) in diagnoseUseOfInternalDeclInInlineFunction()
205 const FunctionDecl *First = Cur->getFirstDecl(); in MaybeSuggestAddingStaticToDecl()
209 SourceLocation DeclBegin = First->getSourceRange().getBegin(); in MaybeSuggestAddingStaticToDecl()
225 auto Pos = SuppressedDiagnostics.find(D->getCanonicalDecl()); in DiagnoseUseOfDecl()
227 for (const PartialDiagnosticAt &Suppressed : Pos->second) in DiagnoseUseOfDecl()
234 Pos->second.clear(); in DiagnoseUseOfDecl()
239 if (cast<FunctionDecl>(D)->isMain()) in DiagnoseUseOfDecl()
245 // See if this is an auto-typed variable whose initializer we are parsing. in DiagnoseUseOfDecl()
249 << D->getDeclName(); in DiagnoseUseOfDecl()
252 << D->getDeclName() << cast<VarDecl>(D)->getType(); in DiagnoseUseOfDecl()
259 if (FD->isDeleted()) { in DiagnoseUseOfDecl()
261 if (Ctor && Ctor->isInheritingConstructor()) in DiagnoseUseOfDecl()
263 << Ctor->getParent() in DiagnoseUseOfDecl()
264 << Ctor->getInheritedConstructor().getConstructor()->getParent(); in DiagnoseUseOfDecl()
266 StringLiteral *Msg = FD->getDeletedMessage(); in DiagnoseUseOfDecl()
268 << (Msg != nullptr) << (Msg ? Msg->getString() : StringRef()); in DiagnoseUseOfDecl()
276 // trailing requires-clause whose constraint-expression is not satisfied, in DiagnoseUseOfDecl()
277 // other than to declare it, is ill-formed. [...] in DiagnoseUseOfDecl()
282 if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) { in DiagnoseUseOfDecl()
286 // A diagnostic will have already been generated (non-constant in DiagnoseUseOfDecl()
300 if (getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() && in DiagnoseUseOfDecl()
310 // Lambdas are only default-constructible or assignable in C++2a onwards. in DiagnoseUseOfDecl()
311 if (MD->getParent()->isLambda() && in DiagnoseUseOfDecl()
313 cast<CXXConstructorDecl>(MD)->isDefaultConstructor()) || in DiagnoseUseOfDecl()
314 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) { in DiagnoseUseOfDecl()
320 auto getReferencedObjCProp = [](const NamedDecl *D) -> in DiagnoseUseOfDecl()
323 return MD->findPropertyDecl(); in DiagnoseUseOfDecl()
336 // initializer-clause. in DiagnoseUseOfDecl()
338 if (LangOpts.OpenMP && DRD && !CurContext->containsDecl(D) && in DiagnoseUseOfDecl()
341 << getCurFunction()->HasOMPDeclareReductionCombiner; in DiagnoseUseOfDecl()
342 Diag(D->getLocation(), diag::note_entity_declared_at) << D; in DiagnoseUseOfDecl()
347 // List-items in map clauses on this construct may only refer to the declared in DiagnoseUseOfDecl()
355 Diag(D->getLocation(), diag::note_entity_declared_at) << D; in DiagnoseUseOfDecl()
361 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here); in DiagnoseUseOfDecl()
372 if (D->hasAttr<AvailableOnlyInDefaultEvalMethodAttr>()) { in DiagnoseUseOfDecl()
377 Diag(D->getLocation(), in DiagnoseUseOfDecl()
379 << D->getName(); in DiagnoseUseOfDecl()
383 checkTypeSupport(VD->getType(), Loc, VD); in DiagnoseUseOfDecl()
389 if (VD->getTLSKind() != VarDecl::TLS_None) in DiagnoseUseOfDecl()
393 if (isa<ParmVarDecl>(D) && isa<RequiresExprBodyDecl>(D->getDeclContext()) && in DiagnoseUseOfDecl()
397 // (Clause 8) within the constraint-expression. in DiagnoseUseOfDecl()
400 Diag(D->getLocation(), diag::note_entity_declared_at) << D; in DiagnoseUseOfDecl()
409 const SentinelAttr *Attr = D->getAttr<SentinelAttr>(); in DiagnoseSentinelCalls()
421 NumFormalParams = MD->param_size(); in DiagnoseSentinelCalls()
424 NumFormalParams = FD->param_size(); in DiagnoseSentinelCalls()
427 QualType Ty = VD->getType(); in DiagnoseSentinelCalls()
429 if (const auto *PtrTy = Ty->getAs<PointerType>()) { in DiagnoseSentinelCalls()
430 Fn = PtrTy->getPointeeType()->getAs<FunctionType>(); in DiagnoseSentinelCalls()
434 } else if (const auto *PtrTy = Ty->getAs<BlockPointerType>()) { in DiagnoseSentinelCalls()
435 Fn = PtrTy->getPointeeType()->castAs<FunctionType>(); in DiagnoseSentinelCalls()
442 NumFormalParams = proto->getNumParams(); in DiagnoseSentinelCalls()
453 unsigned NullPos = Attr->getNullPos(); in DiagnoseSentinelCalls()
455 NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - NullPos); in DiagnoseSentinelCalls()
458 unsigned NumArgsAfterSentinel = Attr->getSentinel(); in DiagnoseSentinelCalls()
463 Diag(Loc, diag::warn_not_enough_argument) << D->getDeclName(); in DiagnoseSentinelCalls()
464 Diag(D->getLocation(), diag::note_sentinel_here) << int(CalleeKind); in DiagnoseSentinelCalls()
469 const Expr *SentinelExpr = Args[Args.size() - NumArgsAfterSentinel - 1]; in DiagnoseSentinelCalls()
472 if (SentinelExpr->isValueDependent()) in DiagnoseSentinelCalls()
481 SourceLocation MissingNilLoc = getLocForEndOfToken(SentinelExpr->getEndLoc()); in DiagnoseSentinelCalls()
498 Diag(D->getLocation(), diag::note_sentinel_here) in DiagnoseSentinelCalls()
499 << int(CalleeKind) << Attr->getRange(); in DiagnoseSentinelCalls()
503 return E ? E->getSourceRange() : SourceRange(); in getExprRange()
506 //===----------------------------------------------------------------------===//
508 //===----------------------------------------------------------------------===//
513 if (E->hasPlaceholderType()) { in DefaultFunctionArrayConversion()
519 QualType Ty = E->getType(); in DefaultFunctionArrayConversion()
520 assert(!Ty.isNull() && "DefaultFunctionArrayConversion - missing type"); in DefaultFunctionArrayConversion()
522 if (Ty->isFunctionType()) { in DefaultFunctionArrayConversion()
523 if (auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenCasts())) in DefaultFunctionArrayConversion()
524 if (auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) in DefaultFunctionArrayConversion()
525 if (!checkAddressOfFunctionIsAvailable(FD, Diagnose, E->getExprLoc())) in DefaultFunctionArrayConversion()
530 } else if (Ty->isArrayType()) { in DefaultFunctionArrayConversion()
542 if (getLangOpts().C99 || getLangOpts().CPlusPlus || E->isLValue()) { in DefaultFunctionArrayConversion()
555 // and if not volatile-qualified, this is undefined behavior that the in CheckForNullPointerDereference()
559 const auto *UO = dyn_cast<UnaryOperator>(E->IgnoreParenCasts()); in CheckForNullPointerDereference()
560 if (UO && UO->getOpcode() == UO_Deref && in CheckForNullPointerDereference()
561 UO->getSubExpr()->getType()->isPointerType()) { in CheckForNullPointerDereference()
563 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace(); in CheckForNullPointerDereference()
566 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant( in CheckForNullPointerDereference()
568 !UO->getType().isVolatileQualified()) { in CheckForNullPointerDereference()
569 S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, in CheckForNullPointerDereference()
571 << UO->getSubExpr()->getSourceRange()); in CheckForNullPointerDereference()
572 S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, in CheckForNullPointerDereference()
581 const ObjCIvarDecl *IV = OIRE->getDecl(); in DiagnoseDirectIsaAccess()
585 DeclarationName MemberName = IV->getDeclName(); in DiagnoseDirectIsaAccess()
587 if (!Member || !Member->isStr("isa")) in DiagnoseDirectIsaAccess()
590 const Expr *Base = OIRE->getBase(); in DiagnoseDirectIsaAccess()
591 QualType BaseType = Base->getType(); in DiagnoseDirectIsaAccess()
592 if (OIRE->isArrow()) in DiagnoseDirectIsaAccess()
593 BaseType = BaseType->getPointeeType(); in DiagnoseDirectIsaAccess()
594 if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) in DiagnoseDirectIsaAccess()
595 if (ObjCInterfaceDecl *IDecl = OTy->getInterface()) { in DiagnoseDirectIsaAccess()
597 ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); in DiagnoseDirectIsaAccess()
598 if (!ClassDeclared->getSuperClass() in DiagnoseDirectIsaAccess()
599 && (*ClassDeclared->ivar_begin()) == IV) { in DiagnoseDirectIsaAccess()
606 SourceLocation RHSLocEnd = S.getLocForEndOfToken(RHS->getEndLoc()); in DiagnoseDirectIsaAccess()
607 S.Diag(OIRE->getExprLoc(), diag::warn_objc_isa_assign) in DiagnoseDirectIsaAccess()
608 << FixItHint::CreateInsertion(OIRE->getBeginLoc(), in DiagnoseDirectIsaAccess()
611 SourceRange(OIRE->getOpLoc(), AssignLoc), ",") in DiagnoseDirectIsaAccess()
615 S.Diag(OIRE->getLocation(), diag::warn_objc_isa_assign); in DiagnoseDirectIsaAccess()
622 S.Diag(OIRE->getExprLoc(), diag::warn_objc_isa_use) in DiagnoseDirectIsaAccess()
623 << FixItHint::CreateInsertion(OIRE->getBeginLoc(), in DiagnoseDirectIsaAccess()
626 SourceRange(OIRE->getOpLoc(), OIRE->getEndLoc()), ")"); in DiagnoseDirectIsaAccess()
628 S.Diag(OIRE->getLocation(), diag::warn_objc_isa_use); in DiagnoseDirectIsaAccess()
630 S.Diag(IV->getLocation(), diag::note_ivar_decl); in DiagnoseDirectIsaAccess()
637 if (E->hasPlaceholderType()) { in DefaultLvalueConversion()
644 // A glvalue of a non-function, non-array type T can be in DefaultLvalueConversion()
646 if (!E->isGLValue()) return E; in DefaultLvalueConversion()
648 QualType T = E->getType(); in DefaultLvalueConversion()
649 assert(!T.isNull() && "r-value conversion on typeless expression?"); in DefaultLvalueConversion()
651 // lvalue-to-rvalue conversion cannot be applied to types that decay to in DefaultLvalueConversion()
653 if (T->canDecayToPointerType()) in DefaultLvalueConversion()
656 // We don't want to throw lvalue-to-rvalue casts on top of in DefaultLvalueConversion()
659 if (T == Context.OverloadTy || T->isRecordType() || in DefaultLvalueConversion()
660 (T->isDependentType() && !T->isAnyPointerType() && in DefaultLvalueConversion()
661 !T->isMemberPointerType())) in DefaultLvalueConversion()
668 // lvalue-to-rvalue at all. Note that expressions of unqualified in DefaultLvalueConversion()
669 // 'void' type are never l-values, but qualified void can be. in DefaultLvalueConversion()
670 if (T->isVoidType()) in DefaultLvalueConversion()
676 T->isHalfType()) { in DefaultLvalueConversion()
677 Diag(E->getExprLoc(), diag::err_opencl_half_load_store) in DefaultLvalueConversion()
683 if (const ObjCIsaExpr *OISA = dyn_cast<ObjCIsaExpr>(E->IgnoreParenCasts())) { in DefaultLvalueConversion()
688 Diag(E->getExprLoc(), diag::warn_objc_isa_use) in DefaultLvalueConversion()
689 << FixItHint::CreateInsertion(OISA->getBeginLoc(), "object_getClass(") in DefaultLvalueConversion()
691 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()), ")"); in DefaultLvalueConversion()
693 Diag(E->getExprLoc(), diag::warn_objc_isa_use); in DefaultLvalueConversion()
696 dyn_cast<ObjCIvarRefExpr>(E->IgnoreParenCasts())) in DefaultLvalueConversion()
700 // [...] If T is a non-class type, the type of the prvalue is the in DefaultLvalueConversion()
701 // cv-unqualified version of T. Otherwise, the type of the in DefaultLvalueConversion()
712 if (T->isMemberPointerType() && in DefaultLvalueConversion()
714 (void)isCompleteType(E->getExprLoc(), T); in DefaultLvalueConversion()
723 if (E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) in DefaultLvalueConversion()
726 if (E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct) in DefaultLvalueConversion()
731 CastKind CK = T->isNullPtrType() ? CK_NullToPointer : CK_LValueToRValue; in DefaultLvalueConversion()
736 // ... if the lvalue has atomic type, the value has the non-atomic version in DefaultLvalueConversion()
738 if (const AtomicType *Atomic = T->getAs<AtomicType>()) { in DefaultLvalueConversion()
739 T = Atomic->getValueType().getUnqualifiedType(); in DefaultLvalueConversion()
758 QualType Ty = E->getType(); in CallExprUnaryConversions()
762 if (Ty->isFunctionType()) { in CallExprUnaryConversions()
774 /// UsualUnaryConversions - Performs various conversions that are common to most
776 /// sometimes suppressed. For example, the array->pointer conversion doesn't
780 // First, convert to an r-value. in UsualUnaryConversions()
786 QualType Ty = E->getType(); in UsualUnaryConversions()
787 assert(!Ty.isNull() && "UsualUnaryConversions - missing type"); in UsualUnaryConversions()
790 if (EvalMethod != LangOptions::FEM_Source && Ty->isFloatingType() && in UsualUnaryConversions()
804 return Ty->isComplexType() in UsualUnaryConversions()
813 return Ty->isComplexType() in UsualUnaryConversions()
824 if (Ty->isHalfType() && !getLangOpts().NativeHalfType) in UsualUnaryConversions()
829 if (Ty->isIntegralOrUnscopedEnumerationType()) { in UsualUnaryConversions()
834 // - an object or expression with an integer type whose integer in UsualUnaryConversions()
837 // - A bit-field of type _Bool, int, signed int, or unsigned int. in UsualUnaryConversions()
863 QualType Ty = E->getType(); in DefaultArgumentPromotion()
864 assert(!Ty.isNull() && "DefaultArgumentPromotion - missing type"); in DefaultArgumentPromotion()
875 const BuiltinType *BTy = Ty->getAs<BuiltinType>(); in DefaultArgumentPromotion()
876 if (BTy && (BTy->getKind() == BuiltinType::Half || in DefaultArgumentPromotion()
877 BTy->getKind() == BuiltinType::Float)) { in DefaultArgumentPromotion()
880 if (BTy->getKind() == BuiltinType::Half) { in DefaultArgumentPromotion()
890 Context.getTargetInfo().supportsExtendIntArgs() && Ty->isIntegerType() && in DefaultArgumentPromotion()
893 E = (Ty->isUnsignedIntegerType()) in DefaultArgumentPromotion()
901 // C++ performs lvalue-to-rvalue conversion as a default argument in DefaultArgumentPromotion()
904 // When an lvalue-to-rvalue conversion occurs in an unevaluated in DefaultArgumentPromotion()
907 // has a class type, the conversion copy-initializes a temporary in DefaultArgumentPromotion()
912 if (getLangOpts().CPlusPlus && E->isGLValue() && !isUnevaluatedContext()) { in DefaultArgumentPromotion()
914 InitializedEntity::InitializeTemporary(E->getType()), in DefaultArgumentPromotion()
915 E->getExprLoc(), E); in DefaultArgumentPromotion()
925 if (Ty->isIncompleteType()) { in isValidVarArgType()
929 // is ill-formed. in isValidVarArgType()
931 // Since we've already performed array-to-pointer and function-to-pointer in isValidVarArgType()
934 if (Ty->isVoidType()) in isValidVarArgType()
937 if (Ty->isObjCObjectType()) in isValidVarArgType()
954 // Passing a potentially-evaluated argument of class type (Clause 9) in isValidVarArgType()
955 // having a non-trivial copy constructor, a non-trivial move constructor, in isValidVarArgType()
956 // or a non-trivial destructor, with no corresponding parameter, in isValidVarArgType()
957 // is conditionally-supported with implementation-defined semantics. in isValidVarArgType()
958 if (getLangOpts().CPlusPlus11 && !Ty->isDependentType()) in isValidVarArgType()
959 if (CXXRecordDecl *Record = Ty->getAsCXXRecordDecl()) in isValidVarArgType()
960 if (!Record->hasNonTrivialCopyConstructor() && in isValidVarArgType()
961 !Record->hasNonTrivialMoveConstructor() && in isValidVarArgType()
962 !Record->hasNonTrivialDestructor()) in isValidVarArgType()
965 if (getLangOpts().ObjCAutoRefCount && Ty->isObjCLifetimeType()) in isValidVarArgType()
968 if (Ty->isObjCObjectType()) in isValidVarArgType()
974 // FIXME: In C++11, these cases are conditionally-supported, meaning we're in isValidVarArgType()
980 // Don't allow one to pass an Objective-C interface to a vararg. in checkVariadicArgument()
981 const QualType &Ty = E->getType(); in checkVariadicArgument()
984 // Complain about passing non-POD types through varargs. in checkVariadicArgument()
988 E->getBeginLoc(), nullptr, in checkVariadicArgument()
992 if (Ty->isRecordType()) { in checkVariadicArgument()
995 DiagRuntimeBehavior(E->getBeginLoc(), nullptr, in checkVariadicArgument()
1003 DiagRuntimeBehavior(E->getBeginLoc(), nullptr, in checkVariadicArgument()
1010 Diag(E->getBeginLoc(), in checkVariadicArgument()
1013 else if (Ty->isObjCObjectType()) in checkVariadicArgument()
1014 DiagRuntimeBehavior(E->getBeginLoc(), nullptr, in checkVariadicArgument()
1018 Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg) in checkVariadicArgument()
1026 if (const BuiltinType *PlaceholderTy = E->getType()->getAsPlaceholderType()) { in DefaultVariadicArgumentPromotion()
1027 // Strip the unbridged-cast placeholder expression off, if applicable. in DefaultVariadicArgumentPromotion()
1028 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast && in DefaultVariadicArgumentPromotion()
1030 (FDecl && FDecl->hasAttr<CFAuditedTransferAttr>()))) { in DefaultVariadicArgumentPromotion()
1047 if (ExprRes.get()->getType()->isBlockPointerType()) in DefaultVariadicArgumentPromotion()
1052 // Diagnostics regarding non-POD argument types are in DefaultVariadicArgumentPromotion()
1054 if (isValidVarArgType(E->getType()) == VAK_Undefined) { in DefaultVariadicArgumentPromotion()
1060 E->getBeginLoc()); in DefaultVariadicArgumentPromotion()
1067 ExprResult Call = BuildCallExpr(TUScope, TrapFn.get(), E->getBeginLoc(), in DefaultVariadicArgumentPromotion()
1068 std::nullopt, E->getEndLoc()); in DefaultVariadicArgumentPromotion()
1073 ActOnBinOp(TUScope, E->getBeginLoc(), tok::comma, Call.get(), E); in DefaultVariadicArgumentPromotion()
1080 RequireCompleteType(E->getExprLoc(), E->getType(), in DefaultVariadicArgumentPromotion()
1098 if (IntTy->isComplexType() || IntTy->isRealFloatingType()) return true; in handleComplexIntegerToFloatConversion()
1100 if (IntTy->isIntegerType()) { in handleComplexIntegerToFloatConversion()
1101 QualType fpTy = ComplexTy->castAs<ComplexType>()->getElementType(); in handleComplexIntegerToFloatConversion()
1104 assert(IntTy->isComplexIntegerType()); in handleComplexIntegerToFloatConversion()
1114 // to what is done when combining two real floating-point operands.
1117 // floating-point type, the less precise type is converted, within it's
1135 LongerType = LongerType->castAs<ComplexType>()->getElementType(); in handleComplexFloatConversion()
1172 if (IntTy->isIntegerType()) { in handleIntToFloatConversion()
1181 assert(IntTy->isComplexIntegerType()); in handleIntToFloatConversion()
1184 // _Complex int -> _Complex float in handleIntToFloatConversion()
1189 // float -> _Complex float in handleIntToFloatConversion()
1202 bool LHSFloat = LHSType->isRealFloatingType(); in handleFloatConversion()
1203 bool RHSFloat = RHSType->isRealFloatingType(); in handleFloatConversion()
1206 // operand has a fixed-point type, the fixed-point operand in handleFloatConversion()
1208 if (LHSType->isFixedPointType() || RHSType->isFixedPointType()) { in handleFloatConversion()
1233 if (LHSType->isHalfType() && !S.getLangOpts().NativeHalfType) in handleFloatConversion()
1252 if (!LHSType->isFloatingType() || !RHSType->isFloatingType()) in unsupportedTypeConversion()
1255 // No issue if both have the same 128-bit float semantics. in unsupportedTypeConversion()
1256 auto *LHSComplex = LHSType->getAs<ComplexType>(); in unsupportedTypeConversion()
1257 auto *RHSComplex = RHSType->getAs<ComplexType>(); in unsupportedTypeConversion()
1259 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType; in unsupportedTypeConversion()
1260 QualType RHSElem = RHSComplex ? RHSComplex->getElementType() : RHSType; in unsupportedTypeConversion()
1297 bool LHSSigned = LHSType->hasSignedIntegerRepresentation(); in handleIntegerConversion()
1298 bool RHSSigned = RHSType->hasSignedIntegerRepresentation(); in handleIntegerConversion()
1300 // Same signedness; use the higher-ranked type in handleIntegerConversion()
1307 } else if (order != (LHSSigned ? 1 : -1)) { in handleIntegerConversion()
1327 // The signed type is higher-ranked than the unsigned type, in handleIntegerConversion()
1329 // on most 32-bit systems). Use the unsigned type corresponding in handleIntegerConversion()
1346 const ComplexType *LHSComplexInt = LHSType->getAsComplexIntegerType(); in handleComplexIntConversion()
1347 const ComplexType *RHSComplexInt = RHSType->getAsComplexIntegerType(); in handleComplexIntConversion()
1350 QualType LHSEltType = LHSComplexInt->getElementType(); in handleComplexIntConversion()
1351 QualType RHSEltType = RHSComplexInt->getElementType(); in handleComplexIntConversion()
1360 QualType LHSEltType = LHSComplexInt->getElementType(); in handleComplexIntConversion()
1373 QualType RHSEltType = RHSComplexInt->getElementType(); in handleComplexIntConversion()
1389 const auto *BTy = Ty->getAs<BuiltinType>(); in GetFixedPointRank()
1392 switch (BTy->getKind()) { in GetFixedPointRank()
1402 return 2; in GetFixedPointRank()
1424 if (BTy->isInteger()) in GetFixedPointRank()
1430 /// handleFixedPointConversion - Fixed point operations between fixed
1437 assert((LHSTy->isFixedPointType() || RHSTy->isFixedPointType()) && in handleFixedPointConversion()
1439 assert((LHSTy->isFixedPointOrIntegerType() || in handleFixedPointConversion()
1440 RHSTy->isFixedPointOrIntegerType()) && in handleFixedPointConversion()
1444 // If one operand has signed fixed-point type and the other operand has in handleFixedPointConversion()
1445 // unsigned fixed-point type, then the unsigned fixed-point operand is in handleFixedPointConversion()
1446 // converted to its corresponding signed fixed-point type and the resulting in handleFixedPointConversion()
1448 if (RHSTy->isSignedFixedPointType() && LHSTy->isUnsignedFixedPointType()) in handleFixedPointConversion()
1450 else if (RHSTy->isUnsignedFixedPointType() && LHSTy->isSignedFixedPointType()) in handleFixedPointConversion()
1453 // The result type is the type with the highest rank, whereby a fixed-point in handleFixedPointConversion()
1456 // type shall be the saturating fixed-point type corresponding to the type in handleFixedPointConversion()
1466 if (LHSTy->isSaturatedFixedPointType() || RHSTy->isSaturatedFixedPointType()) in handleFixedPointConversion()
1477 // C++2a [expr.arith.conv]p1: in checkEnumArithmeticConversions()
1479 // different enumeration type or a floating-point type, this behavior is in checkEnumArithmeticConversions()
1484 QualType L = LHS->getEnumCoercedType(S.Context), in checkEnumArithmeticConversions() local
1485 R = RHS->getEnumCoercedType(S.Context); in checkEnumArithmeticConversions()
1486 bool LEnum = L->isUnscopedEnumerationType(), in checkEnumArithmeticConversions()
1487 REnum = R->isUnscopedEnumerationType(); in checkEnumArithmeticConversions()
1489 if ((!IsCompAssign && LEnum && R->isFloatingType()) || in checkEnumArithmeticConversions()
1490 (REnum && L->isFloatingType())) { in checkEnumArithmeticConversions()
1496 << LHS->getSourceRange() << RHS->getSourceRange() << (int)ACK << LEnum in checkEnumArithmeticConversions()
1497 << L << R; in checkEnumArithmeticConversions()
1499 !S.Context.hasSameUnqualifiedType(L, R)) { in checkEnumArithmeticConversions()
1501 // In C++ 26, usual arithmetic conversions between 2 different enum types in checkEnumArithmeticConversions()
1502 // are ill-formed. in checkEnumArithmeticConversions()
1505 else if (!L->castAs<EnumType>()->getDecl()->hasNameForLinkage() || in checkEnumArithmeticConversions()
1506 !R->castAs<EnumType>()->getDecl()->hasNameForLinkage()) { in checkEnumArithmeticConversions()
1509 // C++2a. Use a different warning group. in checkEnumArithmeticConversions()
1530 S.Diag(Loc, DiagID) << LHS->getSourceRange() << RHS->getSourceRange() in checkEnumArithmeticConversions()
1531 << (int)ACK << L << R; in checkEnumArithmeticConversions()
1535 /// UsualArithmeticConversions - Performs various conversions that are common to
1537 /// routine returns the first non-arithmetic type found. The client is
1556 QualType LHSType = LHS.get()->getType().getUnqualifiedType(); in UsualArithmeticConversions()
1557 QualType RHSType = RHS.get()->getType().getUnqualifiedType(); in UsualArithmeticConversions()
1560 if (const AtomicType *AtomicLHS = LHSType->getAs<AtomicType>()) in UsualArithmeticConversions()
1561 LHSType = AtomicLHS->getValueType(); in UsualArithmeticConversions()
1567 // If either side is a non-arithmetic type (e.g. a pointer), we are done. in UsualArithmeticConversions()
1569 if (!LHSType->isArithmeticType() || !RHSType->isArithmeticType()) in UsualArithmeticConversions()
1594 if (LHSType->isComplexType() || RHSType->isComplexType()) in UsualArithmeticConversions()
1599 if (LHSType->isRealFloatingType() || RHSType->isRealFloatingType()) in UsualArithmeticConversions()
1604 if (LHSType->isComplexIntegerType() || RHSType->isComplexIntegerType()) in UsualArithmeticConversions()
1608 if (LHSType->isFixedPointType() || RHSType->isFixedPointType()) in UsualArithmeticConversions()
1616 //===----------------------------------------------------------------------===//
1618 //===----------------------------------------------------------------------===//
1684 ? ControllingExpr->isTypeDependent() in CreateGenericSelectionExpr()
1685 : ControllingType->getType()->isDependentType(), in CreateGenericSelectionExpr()
1688 ? ControllingExpr->containsUnexpandedParameterPack() in CreateGenericSelectionExpr()
1689 : ControllingType->getType()->containsUnexpandedParameterPack(); in CreateGenericSelectionExpr()
1694 ControllingExpr->HasSideEffects(Context, false)) in CreateGenericSelectionExpr()
1695 Diag(ControllingExpr->getExprLoc(), in CreateGenericSelectionExpr()
1699 if (Exprs[i]->containsUnexpandedParameterPack()) in CreateGenericSelectionExpr()
1703 if (Types[i]->getType()->containsUnexpandedParameterPack()) in CreateGenericSelectionExpr()
1706 if (Types[i]->getType()->isDependentType()) { in CreateGenericSelectionExpr()
1709 // We relax the restriction on use of incomplete types and non-object in CreateGenericSelectionExpr()
1710 // types with the type-based extension of _Generic. Allowing incomplete in CreateGenericSelectionExpr()
1711 // objects means those can be used as "tags" for a type-safe way to map in CreateGenericSelectionExpr()
1720 if (ControllingExpr && Types[i]->getType()->isIncompleteType()) in CreateGenericSelectionExpr()
1722 else if (ControllingExpr && !Types[i]->getType()->isObjectType()) in CreateGenericSelectionExpr()
1724 else if (Types[i]->getType()->isVariablyModifiedType()) in CreateGenericSelectionExpr()
1736 // If T is a non-class type, the type of the prvalue is the cv- in CreateGenericSelectionExpr()
1739 // association in C are unreachable, and in C++, only qualified non- in CreateGenericSelectionExpr()
1746 QualType QT = Types[i]->getType(); in CreateGenericSelectionExpr()
1747 if (QT->isArrayType()) in CreateGenericSelectionExpr()
1750 (!LangOpts.CPlusPlus || !QT->isRecordType())) in CreateGenericSelectionExpr()
1751 Reason = 2; in CreateGenericSelectionExpr()
1754 Diag(Types[i]->getTypeLoc().getBeginLoc(), in CreateGenericSelectionExpr()
1756 << QT << (Reason - 1); in CreateGenericSelectionExpr()
1760 Diag(Types[i]->getTypeLoc().getBeginLoc(), D) in CreateGenericSelectionExpr()
1761 << Types[i]->getTypeLoc().getSourceRange() in CreateGenericSelectionExpr()
1762 << Types[i]->getType(); in CreateGenericSelectionExpr()
1769 if (Types[j] && !Types[j]->getType()->isDependentType() && in CreateGenericSelectionExpr()
1770 Context.typesAreCompatible(Types[i]->getType(), in CreateGenericSelectionExpr()
1771 Types[j]->getType())) { in CreateGenericSelectionExpr()
1772 Diag(Types[j]->getTypeLoc().getBeginLoc(), in CreateGenericSelectionExpr()
1774 << Types[j]->getTypeLoc().getSourceRange() in CreateGenericSelectionExpr()
1775 << Types[j]->getType() in CreateGenericSelectionExpr()
1776 << Types[i]->getType(); in CreateGenericSelectionExpr()
1777 Diag(Types[i]->getTypeLoc().getBeginLoc(), in CreateGenericSelectionExpr()
1779 << Types[i]->getTypeLoc().getSourceRange() in CreateGenericSelectionExpr()
1780 << Types[i]->getType(); in CreateGenericSelectionExpr()
1789 // If we determined that the generic selection is result-dependent, don't in CreateGenericSelectionExpr()
1802 unsigned DefaultIndex = -1U; in CreateGenericSelectionExpr()
1811 ControllingExpr->getType().getCanonicalType(), in CreateGenericSelectionExpr()
1812 Types[i]->getType())) in CreateGenericSelectionExpr()
1816 ControllingType->getType().getCanonicalType(), in CreateGenericSelectionExpr()
1817 Types[i]->getType())) in CreateGenericSelectionExpr()
1826 ControllingExpr = ControllingExpr->IgnoreParens(); in CreateGenericSelectionExpr()
1829 ? ControllingExpr->getSourceRange() in CreateGenericSelectionExpr()
1830 : ControllingType->getTypeLoc().getSourceRange(); in CreateGenericSelectionExpr()
1831 QualType QT = ControllingExpr ? ControllingExpr->getType() in CreateGenericSelectionExpr()
1832 : ControllingType->getType(); in CreateGenericSelectionExpr()
1846 Diag(Types[I]->getTypeLoc().getBeginLoc(), in CreateGenericSelectionExpr()
1848 << Types[I]->getTypeLoc().getSourceRange() in CreateGenericSelectionExpr()
1849 << Types[I]->getType(); in CreateGenericSelectionExpr()
1857 if (DefaultIndex == -1U && CompatIndices.size() == 0) { in CreateGenericSelectionExpr()
1903 /// getPredefinedExprDecl - Returns Decl of a given DeclContext that can be used
1908 DC = DC->getParent(); in getPredefinedExprDecl()
1912 /// getUDSuffixLoc - Create a SourceLocation for a ud-suffix, given the
1913 /// location of the token and the offset of the ud-suffix within it.
1920 /// BuildCookedLiteralOperatorCall - A user-defined literal was found. Look up
1921 /// the corresponding cooked (non-raw) literal operator, and build a call to it.
1927 assert(Args.size() <= 2 && "too many arguments for literal operator"); in BuildCookedLiteralOperatorCall()
1929 QualType ArgTy[2]; in BuildCookedLiteralOperatorCall()
1931 ArgTy[ArgIdx] = Args[ArgIdx]->getType(); in BuildCookedLiteralOperatorCall()
1932 if (ArgTy[ArgIdx]->isArrayType()) in BuildCookedLiteralOperatorCall()
2015 OS << 'L'; in ExpandFunctionLocalPredefinedMacros()
2081 // built by non-Clang compilers for which the execution character set is in ActOnStringLiteral()
2082 // not always UTF-8). in ActOnStringLiteral()
2091 Lexer::AdvanceToTokenCharacter(Tok.getLocation(), 2, in ActOnStringLiteral()
2109 // We're building a user-defined literal. in ActOnStringLiteral()
2115 // Make sure we're allowed user-defined literals here. in ActOnStringLiteral()
2119 // C++11 [lex.ext]p5: The literal L is treated as a call of the form in ActOnStringLiteral()
2160 bool CharIsUnsigned = CharTy->isUnsignedIntegerType(); in ActOnStringLiteral()
2167 for (unsigned I = 0, N = Lit->getLength(); I != N; ++I) { in ActOnStringLiteral()
2168 Value = Lit->getCodeUnit(I); in ActOnStringLiteral()
2189 DeclarationNameInfo NameInfo(D->getDeclName(), Loc); in BuildDeclRefExpr()
2200 SS ? SS->getWithLocInContext(Context) : NestedNameSpecifierLoc(); in BuildDeclRefExpr()
2209 if (!S.getLangOpts().CUDA || !VD->hasInit()) in isCapturingReferenceToHostVarInCUDADeviceLambda()
2211 assert(VD->getType()->isReferenceType()); in isCapturingReferenceToHostVarInCUDADeviceLambda()
2214 auto *DRE = dyn_cast<DeclRefExpr>(VD->getInit()); in isCapturingReferenceToHostVarInCUDADeviceLambda()
2217 auto *Referee = dyn_cast<VarDecl>(DRE->getDecl()); in isCapturingReferenceToHostVarInCUDADeviceLambda()
2218 if (!Referee || !Referee->hasGlobalStorage() || in isCapturingReferenceToHostVarInCUDADeviceLambda()
2219 Referee->hasAttr<CUDADeviceAttr>()) in isCapturingReferenceToHostVarInCUDADeviceLambda()
2226 if (MD && MD->getParent()->isLambda() && in isCapturingReferenceToHostVarInCUDADeviceLambda()
2227 MD->getOverloadedOperator() == OO_Call && MD->hasAttr<CUDADeviceAttr>() && in isCapturingReferenceToHostVarInCUDADeviceLambda()
2228 VD->getDeclContext() != MD) in isCapturingReferenceToHostVarInCUDADeviceLambda()
2235 // A declaration named in an unevaluated operand never constitutes an odr-use. in getNonOdrUseReasonInCurrentContext()
2239 // C++2a [basic.def.odr]p4: in getNonOdrUseReasonInCurrentContext()
2240 // A variable x whose name appears as a potentially-evaluated expression e in getNonOdrUseReasonInCurrentContext()
2241 // is odr-used by e unless [...] x is a reference that is usable in in getNonOdrUseReasonInCurrentContext()
2246 // to the capture and the reference variable must be treated as odr-use in getNonOdrUseReasonInCurrentContext()
2250 if (VD->getType()->isReferenceType() && in getNonOdrUseReasonInCurrentContext()
2253 VD->isUsableInConstantExpressions(Context)) in getNonOdrUseReasonInCurrentContext()
2257 // All remaining non-variable cases constitute an odr-use. For variables, we in getNonOdrUseReasonInCurrentContext()
2277 // An exception-specification is considered to be needed when: in BuildDeclRefExpr()
2278 // - in an expression, the function is the unique lookup result or in BuildDeclRefExpr()
2288 if (const auto *FPT = Ty->getAs<FunctionProtoType>()) { in BuildDeclRefExpr()
2289 if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { in BuildDeclRefExpr()
2291 E->setType(Context.getQualifiedType(NewFPT, Ty.getQualifiers())); in BuildDeclRefExpr()
2297 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getBeginLoc())) in BuildDeclRefExpr()
2298 getCurFunction()->recordUseOfWeak(E); in BuildDeclRefExpr()
2302 FD = IFD->getAnonField(); in BuildDeclRefExpr()
2305 // Just in case we're building an illegal pointer-to-member. in BuildDeclRefExpr()
2306 if (FD->isBitField()) in BuildDeclRefExpr()
2307 E->setObjectKind(OK_BitField); in BuildDeclRefExpr()
2310 // C++ [expr.prim]/8: The expression [...] is a bit-field if the identifier in BuildDeclRefExpr()
2311 // designates a bit-field. in BuildDeclRefExpr()
2313 if (const auto *BE = BD->getBinding()) in BuildDeclRefExpr()
2314 E->setObjectKind(BE->getObjectKind()); in BuildDeclRefExpr()
2325 Buffer.setLAngleLoc(Id.TemplateId->LAngleLoc); in DecomposeUnqualifiedId()
2326 Buffer.setRAngleLoc(Id.TemplateId->RAngleLoc); in DecomposeUnqualifiedId()
2328 ASTTemplateArgsPtr TemplateArgsPtr(Id.TemplateId->getTemplateArgs(), in DecomposeUnqualifiedId()
2329 Id.TemplateId->NumArgs); in DecomposeUnqualifiedId()
2332 TemplateName TName = Id.TemplateId->Template.get(); in DecomposeUnqualifiedId()
2333 SourceLocation TNameLoc = Id.TemplateId->TemplateNameLoc; in DecomposeUnqualifiedId()
2377 // to a CXXMethodDecl; but we can't apply a this-> fixit inside a in DiagnoseDependentMemberLookup()
2384 bool isInstance = CurMethod && CurMethod->isInstance() && in DiagnoseDependentMemberLookup()
2385 R.getNamingClass() == CurMethod->getParent() && in DiagnoseDependentMemberLookup()
2388 // There are two ways we can find a class-scope declaration during template in DiagnoseDependentMemberLookup()
2395 if (R.getRepresentativeDecl()->getDeclContext()->Equals(R.getNamingClass())) { in DiagnoseDependentMemberLookup()
2404 // Give a code modification hint to insert 'this->'. in DiagnoseDependentMemberLookup()
2407 << FixItHint::CreateInsertion(R.getNameLoc(), "this->"); in DiagnoseDependentMemberLookup()
2416 Diag(D->getLocation(), NoteID); in DiagnoseDependentMemberLookup()
2425 if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) { in DiagnoseDependentMemberLookup()
2473 R.addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess()); in DiagnoseEmptyLookup()
2483 DC = DC->getLookupParent(); in DiagnoseEmptyLookup()
2524 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->size() == 0) in DiagnoseEmptyLookup()
2530 ND = Best->FoundDecl; in DiagnoseEmptyLookup()
2540 if (getLangOpts().CPlusPlus && ND->isCXXClassMember()) { in DiagnoseEmptyLookup()
2543 const Type *Ty = Corrected.getCorrectionSpecifier()->getAsType(); in DiagnoseEmptyLookup()
2544 Record = Ty->getAsCXXRecordDecl(); in DiagnoseEmptyLookup()
2548 ND->getDeclContext()->getRedeclContext()); in DiagnoseEmptyLookup()
2552 auto *UnderlyingND = ND->getUnderlyingDecl(); in DiagnoseEmptyLookup()
2556 // Objective-C class name, we're in trouble because the parser in DiagnoseEmptyLookup()
2558 // correction, but don't make it a fix-it since we're not going in DiagnoseEmptyLookup()
2564 // FIXME: We found a keyword. Suggest it, but don't provide a fix-it in DiagnoseEmptyLookup()
2618 RD = ThisType->getPointeeType()->getAsCXXRecordDecl(); in recoverFromMSUnqualifiedLookup()
2620 RD = MD->getParent(); in recoverFromMSUnqualifiedLookup()
2621 if (!RD || !RD->hasDefinition() || !RD->hasAnyDependentBases()) in recoverFromMSUnqualifiedLookup()
2625 // is available, suggest inserting 'this->' as a fixit. in recoverFromMSUnqualifiedLookup()
2631 DB << FixItHint::CreateInsertion(Loc, "this->"); in recoverFromMSUnqualifiedLookup()
2642 NestedNameSpecifier::Create(Context, nullptr, true, RD->getTypeForDecl()); in recoverFromMSUnqualifiedLookup()
2671 if (II && II->isEditorPlaceholder()) { in ActOnIdExpression()
2680 if (isAttrContext() && !getLangOpts().CPlusPlus && S->isClassScope()) { in ActOnIdExpression()
2686 QualType type = VD->getType().getNonReferenceType(); in ActOnIdExpression()
2720 // id-expression. in ActOnIdExpression()
2725 // If this reference is in an Objective-C method, then we need to do in ActOnIdExpression()
2726 // some special Objective-C lookup, too. in ActOnIdExpression()
2749 // argument-dependent lookup. in ActOnIdExpression()
2769 assert((!CCC || CCC->IsAddressOfOperand == IsAddressOfOperand) && in ActOnIdExpression()
2773 CCC->setTypoName(II); in ActOnIdExpression()
2775 CCC->setTypoNNS(SS.getScopeRep()); in ActOnIdExpression()
2784 auto BestTC = State.Consumer->getNextCorrection(); in ActOnIdExpression()
2789 KeywordReplacement->startToken(); in ActOnIdExpression()
2790 KeywordReplacement->setKind(II->getTokenID()); in ActOnIdExpression()
2791 KeywordReplacement->setIdentifierInfo(II); in ActOnIdExpression()
2792 KeywordReplacement->setLocation(BestTC.getCorrectionRange().getBegin()); in ActOnIdExpression()
2797 // valid-but-null ExprResult. in ActOnIdExpression()
2800 State.Consumer->resetCorrectionStream(); in ActOnIdExpression()
2808 // If we found an Objective-C instance variable, let in ActOnIdExpression()
2813 ExprResult E(ObjC().LookupInObjCMethod(R, S, Ivar->getIdentifier())); in ActOnIdExpression()
2814 // In a hopelessly buggy code, Objective-C instance variable in ActOnIdExpression()
2826 // C++ [class.mfct.non-static]p3: in ActOnIdExpression()
2827 // When an id-expression that is not part of a class member access in ActOnIdExpression()
2829 // body of a non-static member function of class X, if name lookup in ActOnIdExpression()
2830 // resolves the name in the id-expression to a non-static non-type in ActOnIdExpression()
2831 // member of some class C, the id-expression is transformed into a in ActOnIdExpression()
2833 // postfix-expression to the left of the . operator. in ActOnIdExpression()
2837 // expression is ill-formed if it actually works out to be a in ActOnIdExpression()
2838 // non-static member function: in ActOnIdExpression()
2841 // Otherwise, if E1.E2 refers to a non-static member function. . . in ActOnIdExpression()
2842 // [t]he expression can be used only as the left-hand operand of a in ActOnIdExpression()
2859 Id.TemplateId->Kind == TNK_Var_template) { in ActOnIdExpression()
2890 if (CD->isInvalidDecl()) in BuildQualifiedDeclarationNameExpr()
2947 const auto *RD = dyn_cast<CXXRecordDecl>(Member->getDeclContext()); in PerformObjectMemberConversion()
2954 QualType FromType = From->getType(); in PerformObjectMemberConversion()
2958 auto FromPtrType = FromType->getAs<PointerType>(); in PerformObjectMemberConversion()
2961 ? FromType->getPointeeType().getAddressSpace() in PerformObjectMemberConversion()
2966 FromRecordType = FromPtrType->getPointeeType(); in PerformObjectMemberConversion()
2973 if (!Method->isImplicitObjectMemberFunction()) in PerformObjectMemberConversion()
2976 DestType = Method->getThisType().getNonReferenceType(); in PerformObjectMemberConversion()
2977 DestRecordType = Method->getFunctionObjectParameterType(); in PerformObjectMemberConversion()
2979 if (FromType->getAs<PointerType>()) { in PerformObjectMemberConversion()
2980 FromRecordType = FromType->getPointeeType(); in PerformObjectMemberConversion()
2997 CK_AddressSpaceConversion, From->getValueKind()) in PerformObjectMemberConversion()
3005 if (DestType->isDependentType() || FromType->isDependentType()) in PerformObjectMemberConversion()
3012 SourceRange FromRange = From->getSourceRange(); in PerformObjectMemberConversion()
3015 ExprValueKind VK = From->getValueKind(); in PerformObjectMemberConversion()
3024 // one to resolve ambiguities in, e.g., a diamond-shaped hierarchy such as: in PerformObjectMemberConversion()
3035 if (Qualifier && Qualifier->getAsType()) { in PerformObjectMemberConversion()
3036 QualType QType = QualType(Qualifier->getAsType(), 0); in PerformObjectMemberConversion()
3037 assert(QType->isRecordType() && "lookup done with non-record type"); in PerformObjectMemberConversion()
3039 QualType QRecordType = QualType(QType->castAs<RecordType>(), 0); in PerformObjectMemberConversion()
3078 // Only when used directly as the postfix-expression of a call. in UseArgumentDependentLookup()
3094 // -- a declaration of a class member in UseArgumentDependentLookup()
3097 if (D->isCXXClassMember()) in UseArgumentDependentLookup()
3101 // -- a block-scope function declaration that is not a in UseArgumentDependentLookup()
3102 // using-declaration in UseArgumentDependentLookup()
3107 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in UseArgumentDependentLookup()
3108 else if (D->getLexicalDeclContext()->isFunctionOrMethod()) in UseArgumentDependentLookup()
3112 // -- a declaration that is neither a function or a function in UseArgumentDependentLookup()
3117 if (FDecl->getBuiltinID() && FDecl->isImplicit()) in UseArgumentDependentLookup()
3133 if (D->isInvalidDecl() && !AcceptInvalid) in CheckDeclInExpr()
3137 S.Diag(Loc, diag::err_unexpected_typedef) << D->getDeclName(); in CheckDeclInExpr()
3142 S.Diag(Loc, diag::err_unexpected_interface) << D->getDeclName(); in CheckDeclInExpr()
3147 S.Diag(Loc, diag::err_unexpected_namespace) << D->getDeclName(); in CheckDeclInExpr()
3160 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion()); in ShouldLookupResultBeMultiVersionOverload()
3166 // If this is a single, fully-resolved result and we don't need ADL, in BuildDeclarationNameExpr()
3184 // any lookup-related diagnostics; we'll hash these out later, when in BuildDeclarationNameExpr()
3211 // We use the dependent type for the RecoveryExpr to prevent bogus follow-up in BuildDeclarationNameExpr()
3226 Diag(D->getLocation(), diag::note_declared_at); in BuildDeclarationNameExpr()
3231 // this check when we're going to perform argument-dependent lookup in BuildDeclarationNameExpr()
3240 if (VD->isInvalidDecl() && !AcceptInvalidDecl) in BuildDeclarationNameExpr()
3245 // must be the subject of a pointer-to-member expression. in BuildDeclarationNameExpr()
3247 IndirectField && !IndirectField->isCXXClassMember()) in BuildDeclarationNameExpr()
3251 QualType type = VD->getType(); in BuildDeclarationNameExpr()
3261 switch (D->getKind()) { in BuildDeclarationNameExpr()
3262 // Ignore all the non-ValueDecl kinds. in BuildDeclarationNameExpr()
3271 llvm_unreachable("forming non-member reference to ivar?"); in BuildDeclarationNameExpr()
3273 // Enum constants are always r-values and never references. in BuildDeclarationNameExpr()
3283 // pointer-to-member expressions; we just call them l-values for in BuildDeclarationNameExpr()
3285 // exist in the high-level semantics. in BuildDeclarationNameExpr()
3292 // These can't have reference type in well-formed programs, but in BuildDeclarationNameExpr()
3298 // Non-type template parameters are either l-values or r-values in BuildDeclarationNameExpr()
3301 if (const ReferenceType *reftype = type->getAs<ReferenceType>()) { in BuildDeclarationNameExpr()
3302 type = reftype->getPointeeType(); in BuildDeclarationNameExpr()
3303 valueKind = VK_LValue; // even if the parameter is an r-value reference in BuildDeclarationNameExpr()
3312 if (type->isRecordType()) { in BuildDeclarationNameExpr()
3318 // For non-references, we need to strip qualifiers just in case in BuildDeclarationNameExpr()
3330 // In C, "extern void blah;" is valid and is an r-value. in BuildDeclarationNameExpr()
3332 type->isVoidType()) { in BuildDeclarationNameExpr()
3340 // These are always l-values. in BuildDeclarationNameExpr()
3345 // potentially-evaluated contexts? Since the variable isn't actually in BuildDeclarationNameExpr()
3363 if (unsigned BID = cast<FunctionDecl>(VD)->getBuiltinID()) { in BuildDeclarationNameExpr()
3371 const FunctionType *fty = type->castAs<FunctionType>(); in BuildDeclarationNameExpr()
3375 if (fty->getReturnType() == Context.UnknownAnyTy) { in BuildDeclarationNameExpr()
3381 // Functions are l-values in C++. in BuildDeclarationNameExpr()
3392 if (!cast<FunctionDecl>(VD)->hasPrototype() && isa<FunctionProtoType>(fty)) in BuildDeclarationNameExpr()
3393 type = Context.getFunctionNoProtoType(fty->getReturnType(), in BuildDeclarationNameExpr()
3394 fty->getExtInfo()); in BuildDeclarationNameExpr()
3396 // Functions are r-values in C. in BuildDeclarationNameExpr()
3421 dyn_cast<FunctionProtoType>(VD->getType())) in BuildDeclarationNameExpr()
3422 if (proto->getReturnType() == Context.UnknownAnyTy) { in BuildDeclarationNameExpr()
3428 // C++ methods are l-values if static, r-values if non-static. in BuildDeclarationNameExpr()
3429 if (cast<CXXMethodDecl>(VD)->isStatic()) { in BuildDeclarationNameExpr()
3446 // wrap a DeclRefExpr referring to an invalid decl with a dependent-type in BuildDeclarationNameExpr()
3447 // RecoveryExpr to avoid follow-up semantic analysis (thus prevent bogus in BuildDeclarationNameExpr()
3449 if (VD->isInvalidDecl() && E) in BuildDeclarationNameExpr()
3450 return CreateRecoveryExpr(E->getBeginLoc(), E->getEndLoc(), {E}); in BuildDeclarationNameExpr()
3463 Target.resize(ResultPtr - &Target[0]); in ConvertUTF8ToWideString()
3476 if (cast<DeclContext>(currentDecl)->isDependentContext()) in BuildPredefinedExpr()
3479 // Pre-defined identifiers are of type char[x], where x is the length of in BuildPredefinedExpr()
3532 Ty = Context.WideCharTy; // L'x' -> wchar_t in C and C++. in ActOnCharacterConstant()
3534 Ty = Context.UnsignedCharTy; // u8'x' -> unsigned char in C23 in ActOnCharacterConstant()
3536 Ty = Context.Char8Ty; // u8'x' -> char8_t when it exists. in ActOnCharacterConstant()
3538 Ty = Context.Char16Ty; // u'x' -> char16_t in C11 and C++11. in ActOnCharacterConstant()
3540 Ty = Context.Char32Ty; // U'x' -> char32_t in C11 and C++11. in ActOnCharacterConstant()
3542 Ty = Context.IntTy; // 'x' -> int in C, 'wxyz' -> int in C++. in ActOnCharacterConstant()
3544 Ty = Context.CharTy; // 'x' -> char in C++; in ActOnCharacterConstant()
3545 // u8'x' -> char in C11-C17 and in C++ without char8_t. in ActOnCharacterConstant()
3563 // We're building a user-defined literal. in ActOnCharacterConstant()
3568 // Make sure we're allowed user-defined literals here. in ActOnCharacterConstant()
3572 // C++11 [lex.ext]p6: The literal L is treated as a call of the form in ActOnCharacterConstant()
3620 if (E->isValueDependent()) in CheckLoopHintExpr()
3623 QualType QT = E->getType(); in CheckLoopHintExpr()
3624 if (!QT->isIntegerType() || QT->isBooleanType() || QT->isCharType()) { in CheckLoopHintExpr()
3625 Diag(E->getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT; in CheckLoopHintExpr()
3636 // https://gcc.gnu.org/onlinedocs/gcc/Loop-Specific-Pragmas.html says in CheckLoopHintExpr()
3643 Diag(E->getExprLoc(), diag::err_requires_positive_value) in CheckLoopHintExpr()
3679 // We're building a user-defined literal. in ActOnNumericConstant()
3684 // Make sure we're allowed user-defined literals here. in ActOnNumericConstant()
3692 // operator "" X (f L) in ActOnNumericConstant()
3753 // template), L is treated as a call fo the form in ActOnNumericConstant()
3758 bool CharIsUnsigned = Context.CharTy->isUnsignedIntegerType(); in ActOnNumericConstant()
3809 // Clause 6.4.4 - The value of a constant shall be in the range of in ActOnNumericConstant()
3813 --Val; in ActOnNumericConstant()
3846 if (Ty->castAs<BuiltinType>()->getKind() != BuiltinType::Float) { in ActOnNumericConstant()
3851 // Impose single-precision float type when cl_khr_fp64 is not enabled. in ActOnNumericConstant()
3881 // Get the value in the widest-possible width. What is "widest" depends on in ActOnNumericConstant()
3882 // whether the literal is a bit-precise integer or not. For a bit-precise in ActOnNumericConstant()
3885 // to get the integer value from an overly-wide APInt is *extremely* in ActOnNumericConstant()
3910 // suffix for portability of code with C++, but both `l` and `ll` are in ActOnNumericConstant()
3911 // 64-bit integer types, and we want the type of `1l` and `1ll` to be the in ActOnNumericConstant()
3933 // Bit-precise integer literals are automagically-sized based on the in ActOnNumericConstant()
3937 // zero-width bit-precise integers, even if the literal value is 0. in ActOnNumericConstant()
3953 // literal itself is always an unsigned value (a preceeding - is a in ActOnNumericConstant()
3969 if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0) in ActOnNumericConstant()
3985 if (!Literal.isUnsigned && ResultVal[IntSize-1] == 0) in ActOnNumericConstant()
4000 if (!Literal.isUnsigned && ResultVal[LongSize-1] == 0) in ActOnNumericConstant()
4017 : /*will be ill-formed*/ 1); in ActOnNumericConstant()
4033 if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 || in ActOnNumericConstant()
4074 Context.getComplexType(Res->getType())); in ActOnNumericConstant()
4081 ExprResult Sema::ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E) { in ActOnParenExpr() argument
4083 QualType ExprTy = E->getType(); in ActOnParenExpr()
4085 !E->isLValue() && ExprTy->hasFloatingRepresentation()) in ActOnParenExpr()
4087 return new (Context) ParenExpr(L, R, E); in ActOnParenExpr()
4093 // [OpenCL 1.1 6.11.12] "The vec_step built-in function takes a built-in in CheckVecStepTraitOperandType()
4095 // Every built-in scalar type (OpenCL 1.1 6.1.1) is either an arithmetic in CheckVecStepTraitOperandType()
4097 if (!(T->isArithmeticType() || T->isVoidType() || T->isVectorType())) { in CheckVecStepTraitOperandType()
4103 assert((T->isVoidType() || !T->isIncompleteType()) && in CheckVecStepTraitOperandType()
4111 // builtin_vectorelements supports both fixed-sized and scalable vectors. in CheckVectorElementsTraitOperandType()
4112 if (!T->isVectorType() && !T->isSizelessVectorType()) in CheckVectorElementsTraitOperandType()
4126 if (!T->isFunctionType() && !T->isFunctionPointerType() && in checkPtrAuthTypeDiscriminatorOperandType()
4127 !T->isFunctionReferenceType() && !T->isMemberFunctionPointerType()) { in checkPtrAuthTypeDiscriminatorOperandType()
4144 if (T->isFunctionType() && in CheckExtensionTraitOperandType()
4155 if (T->isVoidType()) { in CheckExtensionTraitOperandType()
4171 if (!S.LangOpts.ObjCRuntime.allowsSizeofAlignof() && T->isObjCObjectType()) { in CheckObjCTraitOperandConstraints()
4186 if (T != E->getType()) in warnOnSizeofOnArrayDecay()
4191 if (!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay) in warnOnSizeofOnArrayDecay()
4194 S.Diag(Loc, diag::warn_sizeof_array_decay) << ICE->getSourceRange() in warnOnSizeofOnArrayDecay()
4195 << ICE->getType() in warnOnSizeofOnArrayDecay()
4196 << ICE->getSubExpr()->getType(); in warnOnSizeofOnArrayDecay()
4201 QualType ExprTy = E->getType(); in CheckUnaryExprOrTypeTraitOperand()
4202 assert(!ExprTy->isReferenceType()); in CheckUnaryExprOrTypeTraitOperand()
4217 // Exclude instantiation-dependent expressions, because 'sizeof' is sometimes in CheckUnaryExprOrTypeTraitOperand()
4219 // FIXME: Should we consider instantiation-dependent operands to 'alignof'? in CheckUnaryExprOrTypeTraitOperand()
4221 !E->isInstantiationDependent() && in CheckUnaryExprOrTypeTraitOperand()
4222 !E->getType()->isVariableArrayType() && in CheckUnaryExprOrTypeTraitOperand()
4223 E->HasSideEffects(Context, false)) in CheckUnaryExprOrTypeTraitOperand()
4224 Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); in CheckUnaryExprOrTypeTraitOperand()
4227 return CheckVecStepTraitOperandType(*this, ExprTy, E->getExprLoc(), in CheckUnaryExprOrTypeTraitOperand()
4228 E->getSourceRange()); in CheckUnaryExprOrTypeTraitOperand()
4231 return CheckVectorElementsTraitOperandType(*this, ExprTy, E->getExprLoc(), in CheckUnaryExprOrTypeTraitOperand()
4232 E->getSourceRange()); in CheckUnaryExprOrTypeTraitOperand()
4235 if (!CheckExtensionTraitOperandType(*this, ExprTy, E->getExprLoc(), in CheckUnaryExprOrTypeTraitOperand()
4236 E->getSourceRange(), ExprKind)) in CheckUnaryExprOrTypeTraitOperand()
4242 E->getType()->isWebAssemblyTableType()) { in CheckUnaryExprOrTypeTraitOperand()
4243 Diag(E->getExprLoc(), diag::err_wasm_table_invalid_uett_operand) in CheckUnaryExprOrTypeTraitOperand()
4254 E->getExprLoc(), Context.getBaseElementType(E->getType()), in CheckUnaryExprOrTypeTraitOperand()
4256 getTraitSpelling(ExprKind), E->getSourceRange())) in CheckUnaryExprOrTypeTraitOperand()
4261 getTraitSpelling(ExprKind), E->getSourceRange())) in CheckUnaryExprOrTypeTraitOperand()
4266 ExprTy = E->getType(); in CheckUnaryExprOrTypeTraitOperand()
4267 assert(!ExprTy->isReferenceType()); in CheckUnaryExprOrTypeTraitOperand()
4269 if (ExprTy->isFunctionType()) { in CheckUnaryExprOrTypeTraitOperand()
4270 Diag(E->getExprLoc(), diag::err_sizeof_alignof_function_type) in CheckUnaryExprOrTypeTraitOperand()
4271 << getTraitSpelling(ExprKind) << E->getSourceRange(); in CheckUnaryExprOrTypeTraitOperand()
4275 if (CheckObjCTraitOperandConstraints(*this, ExprTy, E->getExprLoc(), in CheckUnaryExprOrTypeTraitOperand()
4276 E->getSourceRange(), ExprKind)) in CheckUnaryExprOrTypeTraitOperand()
4280 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(E->IgnoreParens())) { in CheckUnaryExprOrTypeTraitOperand()
4281 if (const auto *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) { in CheckUnaryExprOrTypeTraitOperand()
4282 QualType OType = PVD->getOriginalType(); in CheckUnaryExprOrTypeTraitOperand()
4283 QualType Type = PVD->getType(); in CheckUnaryExprOrTypeTraitOperand()
4284 if (Type->isPointerType() && OType->isArrayType()) { in CheckUnaryExprOrTypeTraitOperand()
4285 Diag(E->getExprLoc(), diag::warn_sizeof_array_param) in CheckUnaryExprOrTypeTraitOperand()
4287 Diag(PVD->getLocation(), diag::note_declared_at); in CheckUnaryExprOrTypeTraitOperand()
4295 if (const auto *BO = dyn_cast<BinaryOperator>(E->IgnoreParens())) { in CheckUnaryExprOrTypeTraitOperand()
4296 warnOnSizeofOnArrayDecay(*this, BO->getOperatorLoc(), BO->getType(), in CheckUnaryExprOrTypeTraitOperand()
4297 BO->getLHS()); in CheckUnaryExprOrTypeTraitOperand()
4298 warnOnSizeofOnArrayDecay(*this, BO->getOperatorLoc(), BO->getType(), in CheckUnaryExprOrTypeTraitOperand()
4299 BO->getRHS()); in CheckUnaryExprOrTypeTraitOperand()
4308 if (E->isTypeDependent()) in CheckAlignOfExpr()
4311 if (E->getObjectKind() == OK_BitField) { in CheckAlignOfExpr()
4312 S.Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) in CheckAlignOfExpr()
4313 << 1 << E->getSourceRange(); in CheckAlignOfExpr()
4318 Expr *Inner = E->IgnoreParens(); in CheckAlignOfExpr()
4320 D = DRE->getDecl(); in CheckAlignOfExpr()
4322 D = ME->getMemberDecl(); in CheckAlignOfExpr()
4331 // in a trailing-return-type. in CheckAlignOfExpr()
4337 // We don't really need the layout here --- we could instead just in CheckAlignOfExpr()
4338 // directly check for all the appropriate alignment-lowing in CheckAlignOfExpr()
4339 // attributes --- but that would require duplicating a lot of in CheckAlignOfExpr()
4341 // use-case. in CheckAlignOfExpr()
4345 if (!FD->getParent()->isCompleteDefinition()) { in CheckAlignOfExpr()
4346 S.Diag(E->getExprLoc(), diag::err_alignof_member_of_incomplete_type) in CheckAlignOfExpr()
4347 << E->getSourceRange(); in CheckAlignOfExpr()
4354 // white-list anyway), which makes the following checks trivial. in CheckAlignOfExpr()
4355 if (!FD->getType()->isReferenceType()) in CheckAlignOfExpr()
4363 E = E->IgnoreParens(); in CheckVecStepExpr()
4366 if (E->isTypeDependent()) in CheckVecStepExpr()
4374 assert(T->isVariablyModifiedType()); in captureVariablyModifiedType()
4380 switch (Ty->getTypeClass()) { in captureVariablyModifiedType()
4389 // These types are never variably-modified. in captureVariablyModifiedType()
4404 llvm_unreachable("type class is never variably-modified!"); in captureVariablyModifiedType()
4406 T = cast<ElaboratedType>(Ty)->getNamedType(); in captureVariablyModifiedType()
4409 T = cast<AdjustedType>(Ty)->getOriginalType(); in captureVariablyModifiedType()
4412 T = cast<DecayedType>(Ty)->getPointeeType(); in captureVariablyModifiedType()
4415 T = cast<ArrayParameterType>(Ty)->getElementType(); in captureVariablyModifiedType()
4418 T = cast<PointerType>(Ty)->getPointeeType(); in captureVariablyModifiedType()
4421 T = cast<BlockPointerType>(Ty)->getPointeeType(); in captureVariablyModifiedType()
4425 T = cast<ReferenceType>(Ty)->getPointeeType(); in captureVariablyModifiedType()
4428 T = cast<MemberPointerType>(Ty)->getPointeeType(); in captureVariablyModifiedType()
4433 T = cast<ArrayType>(Ty)->getElementType(); in captureVariablyModifiedType()
4441 auto Size = VAT->getSizeExpr(); in captureVariablyModifiedType()
4442 if (Size && !CSI->isVLATypeCaptured(VAT) && in captureVariablyModifiedType()
4444 CSI->addVLATypeCapture(Size->getExprLoc(), VAT, Context.getSizeType()); in captureVariablyModifiedType()
4446 T = VAT->getElementType(); in captureVariablyModifiedType()
4451 T = cast<FunctionType>(Ty)->getReturnType(); in captureVariablyModifiedType()
4465 T = cast<TypedefType>(Ty)->desugar(); in captureVariablyModifiedType()
4468 T = cast<DecltypeType>(Ty)->desugar(); in captureVariablyModifiedType()
4471 T = cast<PackIndexingType>(Ty)->desugar(); in captureVariablyModifiedType()
4474 T = cast<UsingType>(Ty)->desugar(); in captureVariablyModifiedType()
4478 T = cast<DeducedType>(Ty)->getDeducedType(); in captureVariablyModifiedType()
4481 T = cast<TypeOfExprType>(Ty)->getUnderlyingExpr()->getType(); in captureVariablyModifiedType()
4484 T = cast<AtomicType>(Ty)->getValueType(); in captureVariablyModifiedType()
4487 } while (!T.isNull() && T->isVariablyModifiedType()); in captureVariablyModifiedType()
4495 if (ExprType->isDependentType()) in CheckUnaryExprOrTypeTraitOperand()
4504 if (const ReferenceType *Ref = ExprType->getAs<ReferenceType>()) in CheckUnaryExprOrTypeTraitOperand()
4505 ExprType = Ref->getPointeeType(); in CheckUnaryExprOrTypeTraitOperand()
4515 ExprType->isIncompleteArrayType()) in CheckUnaryExprOrTypeTraitOperand()
4543 if (ExprType->isFunctionType()) { in CheckUnaryExprOrTypeTraitOperand()
4551 ExprType->isWebAssemblyTableType()) { in CheckUnaryExprOrTypeTraitOperand()
4561 if (ExprType->isVariablyModifiedType() && FunctionScopes.size() > 1) { in CheckUnaryExprOrTypeTraitOperand()
4562 if (auto *TT = ExprType->getAs<TypedefType>()) { in CheckUnaryExprOrTypeTraitOperand()
4571 DC = LSI->CallOperator; in CheckUnaryExprOrTypeTraitOperand()
4573 DC = CRSI->TheCapturedDecl; in CheckUnaryExprOrTypeTraitOperand()
4575 DC = BSI->TheDecl; in CheckUnaryExprOrTypeTraitOperand()
4577 if (DC->containsDecl(TT->getDecl())) in CheckUnaryExprOrTypeTraitOperand()
4595 QualType T = TInfo->getType(); in CreateUnaryExprOrTypeTraitExpr()
4597 if (!T->isDependentType() && in CreateUnaryExprOrTypeTraitExpr()
4605 TInfo->getType()->isVariablyModifiedType()) in CreateUnaryExprOrTypeTraitExpr()
4624 if (E->isTypeDependent()) { in CreateUnaryExprOrTypeTraitExpr()
4625 // Delay type-checking for type-dependent expressions. in CreateUnaryExprOrTypeTraitExpr()
4631 Diag(E->getExprLoc(), diag::err_openmp_default_simd_align_expr); in CreateUnaryExprOrTypeTraitExpr()
4633 } else if (E->refersToBitField()) { // C99 6.5.3.4p1. in CreateUnaryExprOrTypeTraitExpr()
4634 Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0; in CreateUnaryExprOrTypeTraitExpr()
4645 if (ExprKind == UETT_SizeOf && E->getType()->isVariableArrayType()) { in CreateUnaryExprOrTypeTraitExpr()
4653 ExprKind, E, Context.getSizeType(), OpLoc, E->getSourceRange().getEnd()); in CreateUnaryExprOrTypeTraitExpr()
4678 return CheckUnaryExprOrTypeTraitOperand(TInfo->getType(), OpLoc, R, in CheckAlignasTypeArgument()
4692 if (V.get()->isTypeDependent()) in CheckRealImagOperand()
4695 // _Real and _Imag are only l-values for normal l-values. in CheckRealImagOperand()
4696 if (V.get()->getObjectKind() != OK_Ordinary) { in CheckRealImagOperand()
4703 if (const ComplexType *CT = V.get()->getType()->getAs<ComplexType>()) in CheckRealImagOperand()
4704 return CT->getElementType(); in CheckRealImagOperand()
4707 if (V.get()->getType()->isArithmeticType()) in CheckRealImagOperand()
4708 return V.get()->getType(); in CheckRealImagOperand()
4719 S.Diag(Loc, diag::err_realimag_invalid_type) << V.get()->getType() in CheckRealImagOperand()
4750 assert(op->getType()->isObjCObjectPointerType()); in checkArithmeticOnObjCPointer()
4756 << op->getType()->castAs<ObjCObjectPointerType>()->getPointeeType() in checkArithmeticOnObjCPointer()
4757 << op->getSourceRange(); in checkArithmeticOnObjCPointer()
4762 auto *BaseNoParens = Base->IgnoreParens(); in isMSPropertySubscriptExpr()
4764 return MSProp->getPropertyDecl()->getType()->isArrayType(); in isMSPropertySubscriptExpr()
4768 // Returns the type used for LHS[RHS], given one of LHS, RHS is type-dependent.
4771 // There are cases when we could determine a non-dependent type:
4772 // - LHS and RHS may have non-dependent types despite being type-dependent
4774 // - one may be a dependent-sized array with known element type
4775 // - one may be a dependent-typed valid index (enum in current instantiation)
4778 // This avoids creating type-dependent expressions with non-dependent types.
4782 assert(LHS->isTypeDependent() || RHS->isTypeDependent()); in getDependentArraySubscriptType()
4783 QualType LTy = LHS->getType(), RTy = RHS->getType(); in getDependentArraySubscriptType()
4785 if (RTy->isIntegralOrUnscopedEnumerationType()) { in getDependentArraySubscriptType()
4786 if (const PointerType *PT = LTy->getAs<PointerType>()) in getDependentArraySubscriptType()
4787 Result = PT->getPointeeType(); in getDependentArraySubscriptType()
4788 else if (const ArrayType *AT = LTy->getAsArrayTypeUnsafe()) in getDependentArraySubscriptType()
4789 Result = AT->getElementType(); in getDependentArraySubscriptType()
4790 } else if (LTy->isIntegralOrUnscopedEnumerationType()) { in getDependentArraySubscriptType()
4791 if (const PointerType *PT = RTy->getAs<PointerType>()) in getDependentArraySubscriptType()
4792 Result = PT->getPointeeType(); in getDependentArraySubscriptType()
4793 else if (const ArrayType *AT = RTy->getAsArrayTypeUnsafe()) in getDependentArraySubscriptType()
4794 Result = AT->getElementType(); in getDependentArraySubscriptType()
4797 return Result->isDependentType() ? Result : Ctx.DependentTy; in getDependentArraySubscriptType()
4805 if (base && !base->getType().isNull() && in ActOnArraySubscriptExpr()
4806 base->hasPlaceholderType(BuiltinType::ArraySection)) { in ActOnArraySubscriptExpr()
4808 if (AS->isOMPArraySection()) in ActOnArraySubscriptExpr()
4832 if (isa<BinaryOperator>(E) && cast<BinaryOperator>(E)->isCommaOp()) { in ActOnArraySubscriptExpr()
4833 Diag(E->getExprLoc(), diag::err_matrix_subscript_comma) in ActOnArraySubscriptExpr()
4834 << SourceRange(base->getBeginLoc(), rbLoc); in ActOnArraySubscriptExpr()
4841 if (base && !base->getType().isNull() && in ActOnArraySubscriptExpr()
4842 base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) && in ActOnArraySubscriptExpr()
4844 Diag(base->getExprLoc(), diag::err_matrix_separate_incomplete_index) in ActOnArraySubscriptExpr()
4845 << SourceRange(base->getBeginLoc(), rbLoc); in ActOnArraySubscriptExpr()
4856 assert(matSubscriptE->isIncomplete() && in ActOnArraySubscriptExpr()
4858 return CreateBuiltinMatrixSubscriptExpr(matSubscriptE->getBase(), in ActOnArraySubscriptExpr()
4859 matSubscriptE->getRowIdx(), in ActOnArraySubscriptExpr()
4862 if (base->getType()->isWebAssemblyTableType()) { in ActOnArraySubscriptExpr()
4863 Diag(base->getExprLoc(), diag::err_wasm_table_art) in ActOnArraySubscriptExpr()
4864 << SourceRange(base->getBeginLoc(), rbLoc) << 3; in ActOnArraySubscriptExpr()
4868 // Handle any non-overload placeholder types in the base and index in ActOnArraySubscriptExpr()
4874 if (base->getType()->isNonOverloadPlaceholderType()) { in ActOnArraySubscriptExpr()
4885 if (base->getType()->isMatrixType()) { in ActOnArraySubscriptExpr()
4896 if ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) || in ActOnArraySubscriptExpr()
4898 cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma)) { in ActOnArraySubscriptExpr()
4899 Diag(idx->getExprLoc(), diag::warn_deprecated_comma_subscript) in ActOnArraySubscriptExpr()
4900 << SourceRange(base->getBeginLoc(), rbLoc); in ActOnArraySubscriptExpr()
4905 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) { in ActOnArraySubscriptExpr()
4915 // Build an unanalyzed expression if either operand is type-dependent. in ActOnArraySubscriptExpr()
4917 (base->isTypeDependent() || in ActOnArraySubscriptExpr()
4927 // https://msdn.microsoft.com/en-us/library/yhfk0thd(v=vs.120).aspx in ActOnArraySubscriptExpr()
4932 // indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), in ActOnArraySubscriptExpr()
4933 // and p->x[a][b] = i will be turned into p->PutX(a, b, i); in ActOnArraySubscriptExpr()
4943 // Use C++ overloaded-operator rules if either operand has record in ActOnArraySubscriptExpr()
4951 if (getLangOpts().CPlusPlus && !base->getType()->isObjCObjectPointerType() && in ActOnArraySubscriptExpr()
4952 ((base->getType()->isRecordType() || in ActOnArraySubscriptExpr()
4954 ArgExprs[0]->getType()->isRecordType())))) { in ActOnArraySubscriptExpr()
4970 InitializationKind::CreateCopy(E->getBeginLoc(), SourceLocation()); in tryConvertExprToType()
4992 // Build an unanalyzed expression if any of the operands is type-dependent. in CreateBuiltinMatrixSubscriptExpr()
4993 if (Base->isTypeDependent() || RowIdx->isTypeDependent() || in CreateBuiltinMatrixSubscriptExpr()
4994 ColumnIdx->isTypeDependent()) in CreateBuiltinMatrixSubscriptExpr()
5007 bool IsColumnIdx) -> Expr * { in CreateBuiltinMatrixSubscriptExpr()
5008 if (!IndexExpr->getType()->isIntegerType() && in CreateBuiltinMatrixSubscriptExpr()
5009 !IndexExpr->isTypeDependent()) { in CreateBuiltinMatrixSubscriptExpr()
5010 Diag(IndexExpr->getBeginLoc(), diag::err_matrix_index_not_integer) in CreateBuiltinMatrixSubscriptExpr()
5016 IndexExpr->getIntegerConstantExpr(Context)) { in CreateBuiltinMatrixSubscriptExpr()
5018 Diag(IndexExpr->getBeginLoc(), diag::err_matrix_index_outside_range) in CreateBuiltinMatrixSubscriptExpr()
5031 auto *MTy = Base->getType()->getAs<ConstantMatrixType>(); in CreateBuiltinMatrixSubscriptExpr()
5032 RowIdx = IsIndexValid(RowIdx, MTy->getNumRows(), false); in CreateBuiltinMatrixSubscriptExpr()
5033 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(), true); in CreateBuiltinMatrixSubscriptExpr()
5038 MTy->getElementType(), RBLoc); in CreateBuiltinMatrixSubscriptExpr()
5043 const Expr *StrippedExpr = E->IgnoreParenImpCasts(); in CheckAddressOfNoDeref()
5048 while ((Member = dyn_cast<MemberExpr>(StrippedExpr)) && !Member->isArrow()) in CheckAddressOfNoDeref()
5049 StrippedExpr = Member->getBase()->IgnoreParenImpCasts(); in CheckAddressOfNoDeref()
5058 QualType ResultTy = E->getType(); in CheckSubscriptAccessOfNoDeref()
5065 if (ResultTy->hasAttr(attr::NoDeref)) { in CheckSubscriptAccessOfNoDeref()
5072 const Expr *Base = E->getBase(); in CheckSubscriptAccessOfNoDeref()
5073 QualType BaseTy = Base->getType(); in CheckSubscriptAccessOfNoDeref()
5079 while ((Member = dyn_cast<MemberExpr>(Base->IgnoreParenCasts())) && in CheckSubscriptAccessOfNoDeref()
5080 Member->isArrow()) in CheckSubscriptAccessOfNoDeref()
5081 Base = Member->getBase(); in CheckSubscriptAccessOfNoDeref()
5083 if (const auto *Ptr = dyn_cast<PointerType>(Base->getType())) { in CheckSubscriptAccessOfNoDeref()
5084 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref)) in CheckSubscriptAccessOfNoDeref()
5099 // a non-lvalue array, and an lvalue otherwise. in CreateBuiltinArraySubscriptExpr()
5102 Op = Op->IgnoreImplicit(); in CreateBuiltinArraySubscriptExpr()
5103 if (Op->getType()->isArrayType() && !Op->isLValue()) in CreateBuiltinArraySubscriptExpr()
5109 if (!LHSExp->getType()->isSubscriptableVectorType()) { in CreateBuiltinArraySubscriptExpr()
5120 QualType LHSTy = LHSExp->getType(), RHSTy = RHSExp->getType(); in CreateBuiltinArraySubscriptExpr()
5128 if (LHSTy->isDependentType() || RHSTy->isDependentType()) { in CreateBuiltinArraySubscriptExpr()
5133 } else if (const PointerType *PTy = LHSTy->getAs<PointerType>()) { in CreateBuiltinArraySubscriptExpr()
5136 ResultType = PTy->getPointeeType(); in CreateBuiltinArraySubscriptExpr()
5138 LHSTy->getAs<ObjCObjectPointerType>()) { in CreateBuiltinArraySubscriptExpr()
5142 // Use custom logic if this should be the pseudo-object subscript in CreateBuiltinArraySubscriptExpr()
5148 ResultType = PTy->getPointeeType(); in CreateBuiltinArraySubscriptExpr()
5149 } else if (const PointerType *PTy = RHSTy->getAs<PointerType>()) { in CreateBuiltinArraySubscriptExpr()
5153 ResultType = PTy->getPointeeType(); in CreateBuiltinArraySubscriptExpr()
5155 RHSTy->getAs<ObjCObjectPointerType>()) { in CreateBuiltinArraySubscriptExpr()
5159 ResultType = PTy->getPointeeType(); in CreateBuiltinArraySubscriptExpr()
5162 << ResultType << BaseExpr->getSourceRange(); in CreateBuiltinArraySubscriptExpr()
5165 } else if (LHSTy->isSubscriptableVectorType()) { in CreateBuiltinArraySubscriptExpr()
5166 if (LHSTy->isBuiltinType() && in CreateBuiltinArraySubscriptExpr()
5167 LHSTy->getAs<BuiltinType>()->isSveVLSBuiltinType()) { in CreateBuiltinArraySubscriptExpr()
5168 const BuiltinType *BTy = LHSTy->getAs<BuiltinType>(); in CreateBuiltinArraySubscriptExpr()
5169 if (BTy->isSVEBool()) in CreateBuiltinArraySubscriptExpr()
5171 << LHSExp->getSourceRange() in CreateBuiltinArraySubscriptExpr()
5172 << RHSExp->getSourceRange()); in CreateBuiltinArraySubscriptExpr()
5173 ResultType = BTy->getSveEltType(Context); in CreateBuiltinArraySubscriptExpr()
5175 const VectorType *VTy = LHSTy->getAs<VectorType>(); in CreateBuiltinArraySubscriptExpr()
5176 ResultType = VTy->getElementType(); in CreateBuiltinArraySubscriptExpr()
5181 if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) { in CreateBuiltinArraySubscriptExpr()
5187 VK = LHSExp->getValueKind(); in CreateBuiltinArraySubscriptExpr()
5191 QualType BaseType = BaseExpr->getType(); in CreateBuiltinArraySubscriptExpr()
5197 } else if (LHSTy->isArrayType()) { in CreateBuiltinArraySubscriptExpr()
5201 // allow promoting non-lvalue arrays. Warn, then in CreateBuiltinArraySubscriptExpr()
5203 Diag(LHSExp->getBeginLoc(), diag::ext_subscript_non_lvalue) in CreateBuiltinArraySubscriptExpr()
5204 << LHSExp->getSourceRange(); in CreateBuiltinArraySubscriptExpr()
5207 LHSTy = LHSExp->getType(); in CreateBuiltinArraySubscriptExpr()
5211 ResultType = LHSTy->castAs<PointerType>()->getPointeeType(); in CreateBuiltinArraySubscriptExpr()
5212 } else if (RHSTy->isArrayType()) { in CreateBuiltinArraySubscriptExpr()
5214 Diag(RHSExp->getBeginLoc(), diag::ext_subscript_non_lvalue) in CreateBuiltinArraySubscriptExpr()
5215 << RHSExp->getSourceRange(); in CreateBuiltinArraySubscriptExpr()
5218 RHSTy = RHSExp->getType(); in CreateBuiltinArraySubscriptExpr()
5222 ResultType = RHSTy->castAs<PointerType>()->getPointeeType(); in CreateBuiltinArraySubscriptExpr()
5225 << LHSExp->getSourceRange() << RHSExp->getSourceRange()); in CreateBuiltinArraySubscriptExpr()
5228 if (!IndexExpr->getType()->isIntegerType() && !IndexExpr->isTypeDependent()) in CreateBuiltinArraySubscriptExpr()
5230 << IndexExpr->getSourceRange()); in CreateBuiltinArraySubscriptExpr()
5232 if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) || in CreateBuiltinArraySubscriptExpr()
5233 IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) && in CreateBuiltinArraySubscriptExpr()
5234 !IndexExpr->isTypeDependent()) { in CreateBuiltinArraySubscriptExpr()
5236 IndexExpr->getIntegerConstantExpr(getASTContext()); in CreateBuiltinArraySubscriptExpr()
5239 Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange(); in CreateBuiltinArraySubscriptExpr()
5243 // C++ [expr.sub]p1: The type "T" shall be a completely-defined object in CreateBuiltinArraySubscriptExpr()
5246 if (ResultType->isFunctionType()) { in CreateBuiltinArraySubscriptExpr()
5247 Diag(BaseExpr->getBeginLoc(), diag::err_subscript_function_type) in CreateBuiltinArraySubscriptExpr()
5248 << ResultType << BaseExpr->getSourceRange(); in CreateBuiltinArraySubscriptExpr()
5252 if (ResultType->isVoidType() && !getLangOpts().CPlusPlus) { in CreateBuiltinArraySubscriptExpr()
5255 << BaseExpr->getSourceRange(); in CreateBuiltinArraySubscriptExpr()
5257 // C forbids expressions of unqualified void type from being l-values. in CreateBuiltinArraySubscriptExpr()
5261 } else if (!ResultType->isDependentType() && in CreateBuiltinArraySubscriptExpr()
5271 if (LHSExp->IgnoreParenImpCasts()->getType()->isVariablyModifiedType() && in CreateBuiltinArraySubscriptExpr()
5274 LHSExp->IgnoreParenImpCasts()->getType()->getAs<TypedefType>()) { in CreateBuiltinArraySubscriptExpr()
5283 DC = LSI->CallOperator; in CreateBuiltinArraySubscriptExpr()
5285 DC = CRSI->TheCapturedDecl; in CreateBuiltinArraySubscriptExpr()
5287 DC = BSI->TheDecl; in CreateBuiltinArraySubscriptExpr()
5289 if (DC->containsDecl(TT->getDecl())) in CreateBuiltinArraySubscriptExpr()
5292 Context, LHSExp->IgnoreParenImpCasts()->getType(), CSI); in CreateBuiltinArraySubscriptExpr()
5305 if (Param->hasUnparsedDefaultArg()) { in CheckCXXDefaultArgExpr()
5310 Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD; in CheckCXXDefaultArgExpr()
5312 Param->setInvalidDecl(); in CheckCXXDefaultArgExpr()
5317 << FD << cast<CXXRecordDecl>(FD->getDeclContext()); in CheckCXXDefaultArgExpr()
5323 if (Param->hasUninstantiatedDefaultArg()) { in CheckCXXDefaultArgExpr()
5329 Expr *Init = RewrittenInit ? RewrittenInit : Param->getInit(); in CheckCXXDefaultArgExpr()
5342 Cleanup.setExprNeedsCleanups(InitWithCleanup->cleanupsHaveSideEffects()); in CheckCXXDefaultArgExpr()
5344 // should always be a no-op, because blocks in default argument in CheckCXXDefaultArgExpr()
5346 assert(!InitWithCleanup->getNumObjects() && in CheckCXXDefaultArgExpr()
5351 // potentially evaluated and [...] its innermost enclosing non-block scope in CheckCXXDefaultArgExpr()
5355 FD->isImmediateFunction() in CheckCXXDefaultArgExpr()
5375 if (const FunctionDecl *FD = E->getDirectCallee()) in VisitCallExpr()
5376 HasImmediateCalls |= FD->isImmediateFunction(); in VisitCallExpr()
5381 if (const FunctionDecl *FD = E->getConstructor()) in VisitCXXConstructExpr()
5382 HasImmediateCalls |= FD->isImmediateFunction(); in VisitCXXConstructExpr()
5402 return VisitCXXMethodDecl(E->getCallOperator()); in VisitLambdaExpr()
5406 return TraverseStmt(E->getExpr()); in VisitCXXDefaultArgExpr()
5410 return TraverseStmt(E->getExpr()); in VisitCXXDefaultInitExpr()
5433 DeclContext *DC = E->getParentContext(); in TransformSourceLocExpr()
5446 !SemaRef.CurContext->isDependentContext() || DC->isDependentContext()) in TransformSourceLocExpr()
5450 E->getIdentKind(), E->getType(), E->getBeginLoc(), E->getEndLoc(), DC); in TransformSourceLocExpr()
5457 assert(Param->hasDefaultArg() && "can't build nonexistent default arg"); in BuildCXXDefaultArgExpr()
5467 if (!Init && !Param->hasUnparsedDefaultArg()) { in BuildCXXDefaultArgExpr()
5473 // is potentially evaluated and [...] its innermost enclosing non-block in BuildCXXDefaultArgExpr()
5477 FD->isImmediateFunction() in BuildCXXDefaultArgExpr()
5482 if (Param->hasUninstantiatedDefaultArg()) { in BuildCXXDefaultArgExpr()
5506 Res = Immediate.TransformInitializer(Param->getInit(), in BuildCXXDefaultArgExpr()
5512 Res.get()->getBeginLoc()); in BuildCXXDefaultArgExpr()
5524 return CXXDefaultArgExpr::Create(Context, InitializationContext->Loc, Param, in BuildCXXDefaultArgExpr()
5525 Init, InitializationContext->Context); in BuildCXXDefaultArgExpr()
5529 assert(Field->hasInClassInitializer()); in BuildCXXDefaultInitExpr()
5532 if (Field->isInvalidDecl()) in BuildCXXDefaultInitExpr()
5535 CXXThisScopeRAII This(*this, Field->getParent(), Qualifiers()); in BuildCXXDefaultInitExpr()
5537 auto *ParentRD = cast<CXXRecordDecl>(Field->getParent()); in BuildCXXDefaultInitExpr()
5552 if (!Field->getInClassInitializer()) { in BuildCXXDefaultInitExpr()
5553 // Maybe we haven't instantiated the in-class initializer. Go check the in BuildCXXDefaultInitExpr()
5555 if (isTemplateInstantiation(ParentRD->getTemplateSpecializationKind())) { in BuildCXXDefaultInitExpr()
5556 CXXRecordDecl *ClassPattern = ParentRD->getTemplateInstantiationPattern(); in BuildCXXDefaultInitExpr()
5558 ClassPattern->lookup(Field->getDeclName()); in BuildCXXDefaultInitExpr()
5561 for (auto *L : Lookup) { in BuildCXXDefaultInitExpr() local
5562 if ((Pattern = dyn_cast<FieldDecl>(L))) in BuildCXXDefaultInitExpr()
5566 if (!Pattern->hasInClassInitializer() || in BuildCXXDefaultInitExpr()
5569 Field->setInvalidDecl(); in BuildCXXDefaultInitExpr()
5592 Res = Immediate.TransformInitializer(Field->getInClassInitializer(), in BuildCXXDefaultInitExpr()
5598 Field->setInvalidDecl(); in BuildCXXDefaultInitExpr()
5604 if (Field->getInClassInitializer()) { in BuildCXXDefaultInitExpr()
5605 Expr *E = Init ? Init : Field->getInClassInitializer(); in BuildCXXDefaultInitExpr()
5612 // full-expression. in BuildCXXDefaultInitExpr()
5615 Field->setInvalidDecl(); in BuildCXXDefaultInitExpr()
5620 return CXXDefaultInitExpr::Create(Context, InitializationContext->Loc, in BuildCXXDefaultInitExpr()
5621 Field, InitializationContext->Context, in BuildCXXDefaultInitExpr()
5626 // If the brace-or-equal-initializer of a non-static data member in BuildCXXDefaultInitExpr()
5629 // program is ill-formed. in BuildCXXDefaultInitExpr()
5633 // particular, in the operand of a noexcept-expression, and we can be in BuildCXXDefaultInitExpr()
5639 RecordDecl *OutermostClass = ParentRD->getOuterLexicalRecordContext(); in BuildCXXDefaultInitExpr()
5642 Diag(Field->getEndLoc(), in BuildCXXDefaultInitExpr()
5646 Field->setInvalidDecl(); in BuildCXXDefaultInitExpr()
5653 if (Proto && Proto->isVariadic()) { in getVariadicCallType()
5656 else if (Fn && Fn->getType()->isBlockPointerType()) in getVariadicCallType()
5660 if (Method->isInstance()) in getVariadicCallType()
5662 } else if (Fn && Fn->getType() == Context.BoundMemberTy) in getVariadicCallType()
5699 DeclarationName FuncName = FDecl->getDeclName(); in TryTypoCorrectionForCall()
5700 SourceLocation NameLoc = ME ? ME->getMemberLoc() : Fn->getBeginLoc(); in TryTypoCorrectionForCall()
5718 ND = Best->FoundDecl; in TryTypoCorrectionForCall()
5725 ND = ND->getUnderlyingDecl(); in TryTypoCorrectionForCall()
5735 // is used and its operand is a qualified-id not enclosed in parentheses.
5740 Fn = Fn->IgnoreParens(); in isParenthetizedAndQualifiedAddressOfExpr()
5743 if (!UO || UO->getOpcode() != clang::UO_AddrOf) in isParenthetizedAndQualifiedAddressOfExpr()
5745 if (auto *DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr()->IgnoreParens())) { in isParenthetizedAndQualifiedAddressOfExpr()
5746 return DRE->hasQualifier(); in isParenthetizedAndQualifiedAddressOfExpr()
5748 if (auto *OVL = dyn_cast<OverloadExpr>(UO->getSubExpr()->IgnoreParens())) in isParenthetizedAndQualifiedAddressOfExpr() local
5749 return OVL->getQualifier(); in isParenthetizedAndQualifiedAddressOfExpr()
5762 if (unsigned ID = FDecl->getBuiltinID()) in ConvertArgumentsForCall()
5766 // C99 6.5.2.2p7 - the arguments are implicitly converted, as if by in ConvertArgumentsForCall()
5771 !AddressOf && FDecl && FDecl->hasCXXExplicitFunctionObjectParameter(); in ConvertArgumentsForCall()
5773 unsigned NumParams = Proto->getNumParams(); in ConvertArgumentsForCall()
5775 unsigned MinArgs = FDecl ? FDecl->getMinRequiredArguments() : NumParams; in ConvertArgumentsForCall()
5776 unsigned FnKind = Fn->getType()->isBlockPointerType() in ConvertArgumentsForCall()
5788 MinArgs == NumParams && !Proto->isVariadic() in ConvertArgumentsForCall()
5793 << FnKind << MinArgs - ExplicitObjectParameterOffset in ConvertArgumentsForCall()
5794 << static_cast<unsigned>(Args.size()) - in ConvertArgumentsForCall()
5797 } else if (MinArgs - ExplicitObjectParameterOffset == 1 && FDecl && in ConvertArgumentsForCall()
5798 FDecl->getParamDecl(ExplicitObjectParameterOffset) in ConvertArgumentsForCall()
5799 ->getDeclName()) in ConvertArgumentsForCall()
5801 MinArgs == NumParams && !Proto->isVariadic() in ConvertArgumentsForCall()
5804 << FnKind << FDecl->getParamDecl(ExplicitObjectParameterOffset) in ConvertArgumentsForCall()
5805 << HasExplicitObjectParameter << Fn->getSourceRange(); in ConvertArgumentsForCall()
5807 Diag(RParenLoc, MinArgs == NumParams && !Proto->isVariadic() in ConvertArgumentsForCall()
5810 << FnKind << MinArgs - ExplicitObjectParameterOffset in ConvertArgumentsForCall()
5811 << static_cast<unsigned>(Args.size()) - in ConvertArgumentsForCall()
5813 << HasExplicitObjectParameter << Fn->getSourceRange(); in ConvertArgumentsForCall()
5816 if (!TC && FDecl && !FDecl->getBuiltinID() && !IsExecConfig) in ConvertArgumentsForCall()
5817 Diag(FDecl->getLocation(), diag::note_callee_decl) in ConvertArgumentsForCall()
5818 << FDecl << FDecl->getParametersSourceRange(); in ConvertArgumentsForCall()
5824 assert((Call->getNumArgs() == NumParams) && in ConvertArgumentsForCall()
5831 if (!Proto->isVariadic()) { in ConvertArgumentsForCall()
5835 MinArgs == NumParams && !Proto->isVariadic() in ConvertArgumentsForCall()
5840 << FnKind << NumParams - ExplicitObjectParameterOffset in ConvertArgumentsForCall()
5841 << static_cast<unsigned>(Args.size()) - in ConvertArgumentsForCall()
5844 } else if (NumParams - ExplicitObjectParameterOffset == 1 && FDecl && in ConvertArgumentsForCall()
5845 FDecl->getParamDecl(ExplicitObjectParameterOffset) in ConvertArgumentsForCall()
5846 ->getDeclName()) in ConvertArgumentsForCall()
5847 Diag(Args[NumParams]->getBeginLoc(), in ConvertArgumentsForCall()
5851 << FnKind << FDecl->getParamDecl(ExplicitObjectParameterOffset) in ConvertArgumentsForCall()
5852 << static_cast<unsigned>(Args.size()) - in ConvertArgumentsForCall()
5854 << HasExplicitObjectParameter << Fn->getSourceRange() in ConvertArgumentsForCall()
5855 << SourceRange(Args[NumParams]->getBeginLoc(), in ConvertArgumentsForCall()
5856 Args.back()->getEndLoc()); in ConvertArgumentsForCall()
5858 Diag(Args[NumParams]->getBeginLoc(), in ConvertArgumentsForCall()
5862 << FnKind << NumParams - ExplicitObjectParameterOffset in ConvertArgumentsForCall()
5863 << static_cast<unsigned>(Args.size()) - in ConvertArgumentsForCall()
5865 << HasExplicitObjectParameter << Fn->getSourceRange() in ConvertArgumentsForCall()
5866 << SourceRange(Args[NumParams]->getBeginLoc(), in ConvertArgumentsForCall()
5867 Args.back()->getEndLoc()); in ConvertArgumentsForCall()
5870 if (!TC && FDecl && !FDecl->getBuiltinID() && !IsExecConfig) in ConvertArgumentsForCall()
5871 Diag(FDecl->getLocation(), diag::note_callee_decl) in ConvertArgumentsForCall()
5872 << FDecl << FDecl->getParametersSourceRange(); in ConvertArgumentsForCall()
5875 Call->shrinkNumArgs(NumParams); in ConvertArgumentsForCall()
5882 Invalid = GatherArgumentsForCall(Call->getBeginLoc(), FDecl, Proto, 0, Args, in ConvertArgumentsForCall()
5888 Call->setArg(i, AllArgs[i]); in ConvertArgumentsForCall()
5890 Call->computeDependence(); in ConvertArgumentsForCall()
5900 unsigned NumParams = Proto->getNumParams(); in GatherArgumentsForCall()
5905 QualType ProtoArgType = Proto->getParamType(i); in GatherArgumentsForCall()
5908 ParmVarDecl *Param = FDecl ? FDecl->getParamDecl(i) : nullptr; in GatherArgumentsForCall()
5912 if (RequireCompleteType(Arg->getBeginLoc(), ProtoArgType, in GatherArgumentsForCall()
5916 // Strip the unbridged-cast placeholder expression off, if applicable. in GatherArgumentsForCall()
5918 if (Arg->getType() == Context.ARCUnbridgedCastTy && in GatherArgumentsForCall()
5919 FDecl && FDecl->hasAttr<CFAuditedTransferAttr>() && in GatherArgumentsForCall()
5920 (!Param || !Param->hasAttr<CFConsumedAttr>())) in GatherArgumentsForCall()
5923 FDecl && FDecl->hasAttr<CFAuditedTransferAttr>() && in GatherArgumentsForCall()
5924 (!Param || !Param->hasAttr<CFConsumedAttr>())) in GatherArgumentsForCall()
5927 if (Proto->getExtParameterInfo(i).isNoEscape() && in GatherArgumentsForCall()
5928 ProtoArgType->isBlockPointerType()) in GatherArgumentsForCall()
5929 if (auto *BE = dyn_cast<BlockExpr>(Arg->IgnoreParenNoopCasts(Context))) in GatherArgumentsForCall()
5930 BE->getBlockDecl()->setDoesNotEscape(); in GatherArgumentsForCall()
5936 Context, ProtoArgType, Proto->isParamConsumed(i)); in GatherArgumentsForCall()
5973 if (Proto->getReturnType() == Context.UnknownAnyTy && FDecl && in GatherArgumentsForCall()
5974 FDecl->isExternC()) { in GatherArgumentsForCall()
5999 TypeLoc TL = PVD->getTypeSourceInfo()->getTypeLoc(); in DiagnoseCalleeStaticArrayParam()
6003 S.Diag(PVD->getLocation(), diag::note_callee_static_array) in DiagnoseCalleeStaticArrayParam()
6015 QualType OrigTy = Param->getOriginalType(); in CheckStaticArrayArgument()
6018 if (!AT || AT->getSizeModifier() != ArraySizeModifier::Static) in CheckStaticArrayArgument()
6021 if (ArgExpr->isNullPointerConstant(Context, in CheckStaticArrayArgument()
6023 Diag(CallLoc, diag::warn_null_arg) << ArgExpr->getSourceRange(); in CheckStaticArrayArgument()
6033 Context.getAsConstantArrayType(ArgExpr->IgnoreParenCasts()->getType()); in CheckStaticArrayArgument()
6037 if (getASTContext().hasSameUnqualifiedType(CAT->getElementType(), in CheckStaticArrayArgument()
6038 ArgCAT->getElementType())) { in CheckStaticArrayArgument()
6039 if (ArgCAT->getSize().ult(CAT->getSize())) { in CheckStaticArrayArgument()
6041 << ArgExpr->getSourceRange() << (unsigned)ArgCAT->getZExtSize() in CheckStaticArrayArgument()
6042 << (unsigned)CAT->getZExtSize() << 0; in CheckStaticArrayArgument()
6054 << ArgExpr->getSourceRange() << (unsigned)ArgSize->getQuantity() in CheckStaticArrayArgument()
6055 << (unsigned)ParmSize->getQuantity() << 1; in CheckStaticArrayArgument()
6060 /// Given a function expression of unknown-any type, try to rebuild it
6071 switch (placeholder->getKind()) { in isPlaceholderToRemoveAsArg()
6072 // Ignore all the non-placeholder types. in isPlaceholderToRemoveAsArg()
6109 // Pseudo-objects should be converted as soon as possible. in isPlaceholderToRemoveAsArg()
6114 // to resolve unknown-typed arguments based on known parameter types. in isPlaceholderToRemoveAsArg()
6136 if (isPlaceholderToRemoveAsArg(args[i]->getType())) { in CheckArgsForPlaceholders()
6160 QualType DeclType = FDecl->getType(); in rewriteBuiltinFunctionDecl()
6163 if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->getBuiltinID()) || !FT || in rewriteBuiltinFunctionDecl()
6164 ArgExprs.size() < FT->getNumParams()) in rewriteBuiltinFunctionDecl()
6171 for (QualType ParamType : FT->param_types()) { in rewriteBuiltinFunctionDecl()
6175 Sema->DefaultFunctionArrayLvalueConversion(ArgExprs[i++]); in rewriteBuiltinFunctionDecl()
6179 QualType ArgType = Arg->getType(); in rewriteBuiltinFunctionDecl()
6180 if (!ParamType->isPointerType() || ParamType.hasAddressSpace() || in rewriteBuiltinFunctionDecl()
6181 !ArgType->isPointerType() || in rewriteBuiltinFunctionDecl()
6182 !ArgType->getPointeeType().hasAddressSpace() || in rewriteBuiltinFunctionDecl()
6183 isPtrSizeAddressSpace(ArgType->getPointeeType().getAddressSpace())) { in rewriteBuiltinFunctionDecl()
6188 QualType PointeeType = ParamType->getPointeeType(); in rewriteBuiltinFunctionDecl()
6193 LangAS AS = ArgType->getPointeeType().getAddressSpace(); in rewriteBuiltinFunctionDecl()
6203 EPI.Variadic = FT->isVariadic(); in rewriteBuiltinFunctionDecl()
6204 QualType OverloadTy = Context.getFunctionType(FT->getReturnType(), in rewriteBuiltinFunctionDecl()
6206 DeclContext *Parent = FDecl->getParent(); in rewriteBuiltinFunctionDecl()
6208 Context, Parent, FDecl->getLocation(), FDecl->getLocation(), in rewriteBuiltinFunctionDecl()
6209 FDecl->getIdentifier(), OverloadTy, in rewriteBuiltinFunctionDecl()
6210 /*TInfo=*/nullptr, SC_Extern, Sema->getCurFPFeatures().isFPConstrained(), in rewriteBuiltinFunctionDecl()
6215 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { in rewriteBuiltinFunctionDecl()
6216 QualType ParamType = FT->getParamType(i); in rewriteBuiltinFunctionDecl()
6221 Parm->setScopeInfo(0, i); in rewriteBuiltinFunctionDecl()
6224 OverloadDecl->setParams(Params); in rewriteBuiltinFunctionDecl()
6225 Sema->mergeDeclAttributes(OverloadDecl, FDecl); in rewriteBuiltinFunctionDecl()
6232 // `Callee` (when called with ArgExprs) may be ill-formed. enable_if (and in checkDirectCallValidity()
6235 if (S.TooManyArguments(Callee->getNumParams(), ArgExprs.size(), in checkDirectCallValidity()
6237 !Callee->isVariadic()) in checkDirectCallValidity()
6239 if (Callee->getMinRequiredArguments() > ArgExprs.size()) in checkDirectCallValidity()
6243 S.CheckEnableIf(Callee, Fn->getBeginLoc(), ArgExprs, true)) { in checkDirectCallValidity()
6244 S.Diag(Fn->getBeginLoc(), in checkDirectCallValidity()
6248 << Callee << Callee->getSourceRange(); in checkDirectCallValidity()
6249 S.Diag(Callee->getLocation(), in checkDirectCallValidity()
6251 << Attr->getCond()->getSourceRange() << Attr->getMessage(); in checkDirectCallValidity()
6260 [](Sema &S) -> const CXXRecordDecl * { in enclosingClassIsRelatedToClassInWhichMembersWereFound()
6262 if (!DC || !DC->getParent()) in enclosingClassIsRelatedToClassInWhichMembersWereFound()
6268 return MD->getParent()->getCanonicalDecl(); in enclosingClassIsRelatedToClassInWhichMembersWereFound()
6272 return RD->getCanonicalDecl(); in enclosingClassIsRelatedToClassInWhichMembersWereFound()
6286 UME->getNamingClass()->getCanonicalDecl(); in enclosingClassIsRelatedToClassInWhichMembersWereFound()
6294 CurParentClass->isDerivedFrom(NamingClass); in enclosingClassIsRelatedToClassInWhichMembersWereFound()
6308 if (!CurLSI || CurLSI->ImpCaptureStyle == CurLSI->ImpCap_None || in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6309 !UME->isImplicitAccess() || CurLSI->isCXXThisCaptured()) in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6319 DeclContext *EnclosingFunctionCtx = S.CurContext->getParent()->getParent(); in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6322 if (!EnclosingFunctionCtx->isDependentContext()) { in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6323 // If the current lambda and all enclosing lambdas can capture 'this' - in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6325 // contains at least one non-static member function). in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6328 } else if (S.CurContext->isDependentContext()) { in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6332 if (CurLSI->ImpCaptureStyle != CurLSI->ImpCap_None) in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6333 CurLSI->addPotentialThisCapture(CallLoc); in tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs()
6342 if (Call->getNumArgs() != 1) in DiagnosedUnqualifiedCallsToStdFunctions()
6345 const Expr *E = Call->getCallee()->IgnoreParenImpCasts(); in DiagnosedUnqualifiedCallsToStdFunctions()
6349 if (!DRE || !DRE->getLocation().isValid()) in DiagnosedUnqualifiedCallsToStdFunctions()
6352 if (DRE->getQualifier()) in DiagnosedUnqualifiedCallsToStdFunctions()
6355 const FunctionDecl *FD = Call->getDirectCallee(); in DiagnosedUnqualifiedCallsToStdFunctions()
6360 unsigned BuiltinID = FD->getBuiltinID(); in DiagnosedUnqualifiedCallsToStdFunctions()
6364 S.Diag(DRE->getLocation(), diag::warn_unqualified_call_to_std_cast_function) in DiagnosedUnqualifiedCallsToStdFunctions()
6365 << FD->getQualifiedNameAsString() in DiagnosedUnqualifiedCallsToStdFunctions()
6366 << FixItHint::CreateInsertion(DRE->getLocation(), "std::"); in DiagnosedUnqualifiedCallsToStdFunctions()
6378 // Diagnose uses of the C++20 "ADL-only template-id call" feature in earlier in ActOnCallExpr()
6381 ULE && ULE->hasExplicitTemplateArgs() && in ActOnCallExpr()
6382 ULE->decls_begin() == ULE->decls_end()) { in ActOnCallExpr()
6383 Diag(Fn->getExprLoc(), getLangOpts().CPlusPlus20 in ActOnCallExpr()
6386 << ULE->getName(); in ActOnCallExpr()
6396 // If we previously found that the id-expression of this call refers to a in ActOnCallExpr()
6399 if (auto *DRE = dyn_cast<DeclRefExpr>(Fn->IgnoreParens()); in ActOnCallExpr()
6400 DRE && Call.get()->isValueDependent()) { in ActOnCallExpr()
6420 // If this is a pseudo-destructor expression, build the call immediately. in BuildCallExpr()
6423 // Pseudo-destructor calls should not have any arguments. in BuildCallExpr()
6424 Diag(Fn->getBeginLoc(), diag::err_pseudo_dtor_call_with_args) in BuildCallExpr()
6426 SourceRange(ArgExprs.front()->getBeginLoc(), in BuildCallExpr()
6427 ArgExprs.back()->getEndLoc())); in BuildCallExpr()
6433 if (Fn->getType() == Context.PseudoObjectTy) { in BuildCallExpr()
6441 if (Fn->isTypeDependent() || Expr::hasAnyTypeDependentArguments(ArgExprs)) { in BuildCallExpr()
6450 *this, dyn_cast<UnresolvedMemberExpr>(Fn->IgnoreParens()), in BuildCallExpr()
6451 Fn->getBeginLoc()); in BuildCallExpr()
6459 if (Fn->getType()->isRecordType()) in BuildCallExpr()
6463 if (Fn->getType() == Context.UnknownAnyTy) { in BuildCallExpr()
6469 if (Fn->getType() == Context.BoundMemberTy) { in BuildCallExpr()
6477 if (Fn->getType() == Context.OverloadTy) { in BuildCallExpr()
6485 OverloadExpr *ovl = find.Expression; in BuildCallExpr() local
6486 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(ovl)) in BuildCallExpr()
6497 if (Fn->getType() == Context.UnknownAnyTy) { in BuildCallExpr()
6503 Expr *NakedFn = Fn->IgnoreParens(); in BuildCallExpr()
6508 if (UnOp->getOpcode() == UO_AddrOf) { in BuildCallExpr()
6510 NakedFn = UnOp->getSubExpr()->IgnoreParens(); in BuildCallExpr()
6515 NDecl = DRE->getDecl(); in BuildCallExpr()
6518 if (FDecl && FDecl->getBuiltinID()) { in BuildCallExpr()
6526 Context, FDecl->getQualifierLoc(), SourceLocation(), FDecl, false, in BuildCallExpr()
6527 SourceLocation(), FDecl->getType(), Fn->getValueKind(), FDecl, in BuildCallExpr()
6528 nullptr, DRE->isNonOdrUse()); in BuildCallExpr()
6532 NDecl = ME->getMemberDecl(); in BuildCallExpr()
6536 FD, /*Complain=*/true, Fn->getBeginLoc())) in BuildCallExpr()
6542 // compilation, allow a pointer-type argument to default address space to be in BuildCallExpr()
6543 // passed as a pointer-type parameter to a non-default address space. in BuildCallExpr()
6545 // in a non-default address space, perform an implicit address space cast to in BuildCallExpr()
6548 FD->getBuiltinID()) { in BuildCallExpr()
6549 for (unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size(); in BuildCallExpr()
6551 ParmVarDecl *Param = FD->getParamDecl(Idx); in BuildCallExpr()
6552 if (!ArgExprs[Idx] || !Param || !Param->getType()->isPointerType() || in BuildCallExpr()
6553 !ArgExprs[Idx]->getType()->isPointerType()) in BuildCallExpr()
6556 auto ParamAS = Param->getType()->getPointeeType().getAddressSpace(); in BuildCallExpr()
6557 auto ArgTy = ArgExprs[Idx]->getType(); in BuildCallExpr()
6558 auto ArgPtTy = ArgTy->getPointeeType(); in BuildCallExpr()
6571 if (ArgExprs[Idx]->isGLValue()) { in BuildCallExpr()
6573 Context, ArgExprs[Idx]->getType(), CK_NoOp, ArgExprs[Idx], in BuildCallExpr()
6595 (Fn->isTypeDependent() || Expr::hasAnyTypeDependentArguments(ArgExprs))) { in BuildCallExpr()
6597 assert((Fn->containsErrors() || in BuildCallExpr()
6599 [](clang::Expr *E) { return E->containsErrors(); })) && in BuildCallExpr()
6600 "should only occur in error-recovery path."); in BuildCallExpr()
6619 BuildDeclRefExpr(BuiltInDecl, BuiltInDecl->getType(), VK_LValue, Loc); in BuildBuiltinCallExpr()
6641 QualType SrcTy = E->getType(); in BuildAsTypeExpr()
6642 if (!SrcTy->isDependentType() && in BuildAsTypeExpr()
6646 << DestTy << SrcTy << E->getSourceRange()); in BuildAsTypeExpr()
6664 unsigned BuiltinID = (FDecl ? FDecl->getBuiltinID() : 0); in BuildResolvedCallExpr()
6668 if (FDecl->hasAttr<AnyX86InterruptAttr>()) { in BuildResolvedCallExpr()
6669 Diag(Fn->getExprLoc(), diag::err_anyx86_interrupt_called); in BuildResolvedCallExpr()
6672 if (FDecl->hasAttr<ARMInterruptAttr>()) { in BuildResolvedCallExpr()
6673 Diag(Fn->getExprLoc(), diag::err_arm_interrupt_called); in BuildResolvedCallExpr()
6680 // save and restore the non-GPR state. in BuildResolvedCallExpr()
6682 if (Caller->hasAttr<AnyX86InterruptAttr>() || in BuildResolvedCallExpr()
6683 Caller->hasAttr<AnyX86NoCallerSavedRegistersAttr>()) { in BuildResolvedCallExpr()
6688 (!FDecl || !FDecl->hasAttr<AnyX86NoCallerSavedRegistersAttr>())) { in BuildResolvedCallExpr()
6689 Diag(Fn->getExprLoc(), diag::warn_anyx86_excessive_regsave) in BuildResolvedCallExpr()
6690 << (Caller->hasAttr<AnyX86InterruptAttr>() ? 0 : 1); in BuildResolvedCallExpr()
6692 Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl; in BuildResolvedCallExpr()
6698 // We special-case function promotion here because we only allow promoting in BuildResolvedCallExpr()
6703 Fn->getType()->isSpecificBuiltinType(BuiltinType::BuiltinFn)) { in BuildResolvedCallExpr()
6708 QualType FnPtrTy = Context.getPointerType(FDecl->getType()); in BuildResolvedCallExpr()
6710 ResultTy = FDecl->getCallResultType(); in BuildResolvedCallExpr()
6725 if (const PointerType *PT = Fn->getType()->getAs<PointerType>()) { in BuildResolvedCallExpr()
6726 // C99 6.5.2.2p1 - "The expression that denotes the called function shall in BuildResolvedCallExpr()
6728 FuncT = PT->getPointeeType()->getAs<FunctionType>(); in BuildResolvedCallExpr()
6731 << Fn->getType() << Fn->getSourceRange()); in BuildResolvedCallExpr()
6733 Fn->getType()->getAs<BlockPointerType>()) { in BuildResolvedCallExpr()
6734 FuncT = BPT->getPointeeType()->castAs<FunctionType>(); in BuildResolvedCallExpr()
6736 // Handle calls to expressions of unknown-any type. in BuildResolvedCallExpr()
6737 if (Fn->getType() == Context.UnknownAnyTy) { in BuildResolvedCallExpr()
6746 << Fn->getType() << Fn->getSourceRange()); in BuildResolvedCallExpr()
6754 unsigned NumParams = Proto ? Proto->getNumParams() : 0; in BuildResolvedCallExpr()
6772 TheCall->shrinkNumArgs(Args.size()); in BuildResolvedCallExpr()
6783 Args = llvm::ArrayRef(TheCall->getArgs(), TheCall->getNumArgs()); in BuildResolvedCallExpr()
6800 TheCall->setNumArgsUnsafe(std::max<unsigned>(Args.size(), NumParams)); in BuildResolvedCallExpr()
6814 if (FDecl && !FDecl->hasAttr<CUDAGlobalAttr>()) in BuildResolvedCallExpr()
6816 << FDecl << Fn->getSourceRange()); in BuildResolvedCallExpr()
6819 if (!FuncT->getReturnType()->isVoidType() && in BuildResolvedCallExpr()
6820 !FuncT->getReturnType()->getAs<AutoType>() && in BuildResolvedCallExpr()
6821 !FuncT->getReturnType()->isInstantiationDependentType()) in BuildResolvedCallExpr()
6823 << Fn->getType() << Fn->getSourceRange()); in BuildResolvedCallExpr()
6826 if (FDecl && FDecl->hasAttr<CUDAGlobalAttr>()) in BuildResolvedCallExpr()
6828 << FDecl << Fn->getSourceRange()); in BuildResolvedCallExpr()
6833 if (CheckCallReturnType(FuncT->getReturnType(), Fn->getBeginLoc(), TheCall, in BuildResolvedCallExpr()
6838 TheCall->setType(FuncT->getCallResultType(Context)); in BuildResolvedCallExpr()
6839 TheCall->setValueKind(Expr::getValueKindForType(FuncT->getReturnType())); in BuildResolvedCallExpr()
6844 if (Arg && Arg->getType()->isWebAssemblyTableType()) { in BuildResolvedCallExpr()
6845 return ExprError(Diag(Arg->getExprLoc(), in BuildResolvedCallExpr()
6862 if (FDecl->hasBody(Def) && Args.size() != Def->param_size()) { in BuildResolvedCallExpr()
6863 Proto = Def->getType()->getAs<FunctionProtoType>(); in BuildResolvedCallExpr()
6864 if (!Proto || !(Proto->isVariadic() && Args.size() >= Def->param_size())) in BuildResolvedCallExpr()
6866 << (Args.size() > Def->param_size()) << FDecl << Fn->getSourceRange(); in BuildResolvedCallExpr()
6871 if (!FDecl->hasPrototype()) in BuildResolvedCallExpr()
6872 Proto = FDecl->getType()->getAs<FunctionProtoType>(); in BuildResolvedCallExpr()
6878 // -Wdeprecated-non-prototype was disabled where the function was declared. in BuildResolvedCallExpr()
6886 (!FDecl || (!FDecl->isImplicit() && in BuildResolvedCallExpr()
6888 FDecl->getLocation())))) in BuildResolvedCallExpr()
6896 if (Proto && i < Proto->getNumParams()) { in BuildResolvedCallExpr()
6898 Context, Proto->getParamType(i), Proto->isParamConsumed(i)); in BuildResolvedCallExpr()
6915 if (RequireCompleteType(Arg->getBeginLoc(), Arg->getType(), in BuildResolvedCallExpr()
6919 TheCall->setArg(i, Arg); in BuildResolvedCallExpr()
6921 TheCall->computeDependence(); in BuildResolvedCallExpr()
6925 if (Method->isImplicitObjectMemberFunction()) in BuildResolvedCallExpr()
6927 << Fn->getSourceRange() << 0); in BuildResolvedCallExpr()
6934 if (FuncT != nullptr && FuncT->getCmseNSCallAttr()) { in BuildResolvedCallExpr()
6937 dyn_cast<RecordType>(Args[i]->getType().getCanonicalType())) { in BuildResolvedCallExpr()
6938 if (RT->getDecl()->isOrContainsUnion()) in BuildResolvedCallExpr()
6939 Diag(Args[i]->getBeginLoc(), diag::warn_cmse_nonsecure_union) in BuildResolvedCallExpr()
6982 QualType literalType = TInfo->getType(); in BuildCompoundLiteralExpr()
6984 if (literalType->isArrayType()) { in BuildCompoundLiteralExpr()
6988 SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()))) in BuildCompoundLiteralExpr()
6990 if (literalType->isVariableArrayType()) { in BuildCompoundLiteralExpr()
6998 // init a VLA in C++ in all cases (such as with non-trivial constructors). in BuildCompoundLiteralExpr()
7002 // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name in BuildCompoundLiteralExpr()
7016 } else if (!literalType->isDependentType() && in BuildCompoundLiteralExpr()
7019 SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()))) in BuildCompoundLiteralExpr()
7035 bool isFileScope = !CurContext->isFunctionOrMethod(); in BuildCompoundLiteralExpr()
7037 // In C, compound literals are l-values for some reason. in BuildCompoundLiteralExpr()
7038 // For GCC compatibility, in C++, file-scope array compound literals with in BuildCompoundLiteralExpr()
7039 // constant initializers are also l-values, and compound literals are in BuildCompoundLiteralExpr()
7042 // (GCC also treats C++ list-initialized file-scope array prvalues with in BuildCompoundLiteralExpr()
7043 // constant initializers as l-values, but that's non-conforming, so we don't in BuildCompoundLiteralExpr()
7047 // lifetime-extending a temporary object, but our materialized temporaries in BuildCompoundLiteralExpr()
7050 // FIXME: For C++, we might want to instead lifetime-extend only if a pointer in BuildCompoundLiteralExpr()
7051 // is bound to the result of applying array-to-pointer decay to the compound in BuildCompoundLiteralExpr()
7056 (getLangOpts().CPlusPlus && !(isFileScope && literalType->isArrayType())) in BuildCompoundLiteralExpr()
7062 for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) { in BuildCompoundLiteralExpr()
7063 Expr *Init = ILE->getInit(i); in BuildCompoundLiteralExpr()
7064 ILE->setInit(i, ConstantExpr::Create(Context, Init)); in BuildCompoundLiteralExpr()
7070 if (!LiteralExpr->isTypeDependent() && in BuildCompoundLiteralExpr()
7071 !LiteralExpr->isValueDependent() && in BuildCompoundLiteralExpr()
7072 !literalType->isDependentType()) // C99 6.5.2.5p3 in BuildCompoundLiteralExpr()
7077 // Embedded-C extensions to C99 6.5.2.5: in BuildCompoundLiteralExpr()
7079 // type name shall not be qualified by an address-space qualifier." in BuildCompoundLiteralExpr()
7081 << SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()); in BuildCompoundLiteralExpr()
7089 // Emit diagnostics if it is or contains a C union type that is non-trivial in BuildCompoundLiteralExpr()
7091 if (E->getType().hasNonTrivialToPrimitiveDestructCUnion()) in BuildCompoundLiteralExpr()
7092 checkNonTrivialCUnion(E->getType(), E->getExprLoc(), in BuildCompoundLiteralExpr()
7099 getCurFunction()->setHasBranchProtectedScope(); in BuildCompoundLiteralExpr()
7103 if (E->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion() || in BuildCompoundLiteralExpr()
7104 E->getType().hasNonTrivialToPrimitiveCopyCUnion()) in BuildCompoundLiteralExpr()
7105 checkNonTrivialCUnionInInitializer(E->getInitializer(), in BuildCompoundLiteralExpr()
7106 E->getInitializer()->getExprLoc()); in BuildCompoundLiteralExpr()
7125 FirstDesignator = DIE->getBeginLoc(); in ActOnInitList()
7130 if (!DiagnosedNestedDesignator && DIE->size() > 1) { in ActOnInitList()
7132 Diag(DIE->getBeginLoc(), diag::ext_designated_init_nested) in ActOnInitList()
7133 << DIE->getDesignatorsSourceRange(); in ActOnInitList()
7136 for (auto &Desig : DIE->designators()) { in ActOnInitList()
7147 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed) in ActOnInitList()
7148 << DIE->getSourceRange(); in ActOnInitList()
7149 Diag(InitArgList[0]->getBeginLoc(), diag::note_designated_init_mixed) in ActOnInitList()
7150 << InitArgList[0]->getSourceRange(); in ActOnInitList()
7156 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed) in ActOnInitList()
7157 << DIE->getSourceRange(); in ActOnInitList()
7158 Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed) in ActOnInitList()
7159 << InitArgList[I]->getSourceRange(); in ActOnInitList()
7165 // already diagnose use of (non-C++20) C99 designator syntax. in ActOnInitList()
7183 // CheckInitializer() - it requires knowledge of the object being initialized. in BuildInitList()
7185 // Immediately handle non-overload placeholders. Overloads can be in BuildInitList()
7188 if (InitArgList[I]->getType()->isNonOverloadPlaceholderType()) { in BuildInitList()
7201 E->setType(Context.VoidTy); // FIXME: just a place holder for now. in BuildInitList()
7206 assert(E.get()->getType()->isBlockPointerType()); in maybeExtendBlockObject()
7207 assert(E.get()->isPRValue()); in maybeExtendBlockObject()
7209 // Only do this in an r-value context. in maybeExtendBlockObject()
7213 Context, E.get()->getType(), CK_ARCExtendBlockObject, E.get(), in maybeExtendBlockObject()
7223 QualType SrcTy = Src.get()->getType(); in PrepareScalarCast()
7227 switch (Type::ScalarTypeKind SrcKind = SrcTy->getScalarTypeKind()) { in PrepareScalarCast()
7234 switch (DestTy->getScalarTypeKind()) { in PrepareScalarCast()
7236 LangAS SrcAS = SrcTy->getPointeeType().getAddressSpace(); in PrepareScalarCast()
7237 LangAS DestAS = DestTy->getPointeeType().getAddressSpace(); in PrepareScalarCast()
7268 switch (DestTy->getScalarTypeKind()) { in PrepareScalarCast()
7279 Diag(Src.get()->getExprLoc(), in PrepareScalarCast()
7293 switch (DestTy->getScalarTypeKind()) { in PrepareScalarCast()
7297 if (Src.get()->isNullPointerConstant(Context, in PrepareScalarCast()
7309 DestTy->castAs<ComplexType>()->getElementType(), in PrepareScalarCast()
7314 DestTy->castAs<ComplexType>()->getElementType(), in PrepareScalarCast()
7325 switch (DestTy->getScalarTypeKind()) { in PrepareScalarCast()
7334 DestTy->castAs<ComplexType>()->getElementType(), in PrepareScalarCast()
7339 DestTy->castAs<ComplexType>()->getElementType(), in PrepareScalarCast()
7345 llvm_unreachable("valid float->pointer cast?"); in PrepareScalarCast()
7354 switch (DestTy->getScalarTypeKind()) { in PrepareScalarCast()
7360 QualType ET = SrcTy->castAs<ComplexType>()->getElementType(); in PrepareScalarCast()
7370 SrcTy->castAs<ComplexType>()->getElementType(), in PrepareScalarCast()
7376 llvm_unreachable("valid complex float->pointer cast?"); in PrepareScalarCast()
7380 Diag(Src.get()->getExprLoc(), in PrepareScalarCast()
7388 switch (DestTy->getScalarTypeKind()) { in PrepareScalarCast()
7394 QualType ET = SrcTy->castAs<ComplexType>()->getElementType(); in PrepareScalarCast()
7404 SrcTy->castAs<ComplexType>()->getElementType(), in PrepareScalarCast()
7410 llvm_unreachable("valid complex int->pointer cast?"); in PrepareScalarCast()
7414 Diag(Src.get()->getExprLoc(), in PrepareScalarCast()
7428 if (const VectorType *vecType = type->getAs<VectorType>()) { in breakDownVectorType()
7429 len = vecType->getNumElements(); in breakDownVectorType()
7430 eltType = vecType->getElementType(); in breakDownVectorType()
7431 assert(eltType->isScalarType()); in breakDownVectorType()
7435 // We allow lax conversion to and from non-vector types, but only if in breakDownVectorType()
7436 // they're real types (i.e. non-complex, non-pointer scalar types). in breakDownVectorType()
7437 if (!type->isRealType()) return false; in breakDownVectorType()
7445 assert(srcTy->isVectorType() || destTy->isVectorType()); in isValidSveBitcast()
7448 if (!FirstType->isSVESizelessBuiltinType()) in isValidSveBitcast()
7451 const auto *VecTy = SecondType->getAs<VectorType>(); in isValidSveBitcast()
7452 return VecTy && VecTy->getVectorKind() == VectorKind::SveFixedLengthData; in isValidSveBitcast()
7460 if (!destTy->isMatrixType() || !srcTy->isMatrixType()) in areMatrixTypesOfTheSameDimension()
7463 const ConstantMatrixType *matSrcType = srcTy->getAs<ConstantMatrixType>(); in areMatrixTypesOfTheSameDimension()
7464 const ConstantMatrixType *matDestType = destTy->getAs<ConstantMatrixType>(); in areMatrixTypesOfTheSameDimension()
7466 return matSrcType->getNumRows() == matDestType->getNumRows() && in areMatrixTypesOfTheSameDimension()
7467 matSrcType->getNumColumns() == matDestType->getNumColumns(); in areMatrixTypesOfTheSameDimension()
7471 assert(DestTy->isVectorType() || SrcTy->isVectorType()); in areVectorTypesSameSize()
7481 // power of 2, so instead of using that, we need to use the raw in areVectorTypesSameSize()
7490 assert((DestTy->isVectorType() || SrcTy->isVectorType()) && in anyAltivecTypes()
7494 SrcTy->isVectorType() && ((SrcTy->castAs<VectorType>()->getVectorKind() == in anyAltivecTypes()
7496 (SrcTy->castAs<VectorType>()->getVectorKind() == in anyAltivecTypes()
7498 (SrcTy->castAs<VectorType>()->getVectorKind() == in anyAltivecTypes()
7501 bool IsDestTyAltivec = DestTy->isVectorType() && in anyAltivecTypes()
7502 ((DestTy->castAs<VectorType>()->getVectorKind() == in anyAltivecTypes()
7504 (DestTy->castAs<VectorType>()->getVectorKind() == in anyAltivecTypes()
7506 (DestTy->castAs<VectorType>()->getVectorKind() == in anyAltivecTypes()
7513 assert(destTy->isVectorType() || srcTy->isVectorType()); in areLaxCompatibleVectorTypes()
7520 if (srcTy->isScalarType() && destTy->isExtVectorType()) return false; in areLaxCompatibleVectorTypes()
7521 if (destTy->isScalarType() && srcTy->isExtVectorType()) return false; in areLaxCompatibleVectorTypes()
7527 assert(destTy->isVectorType() || srcTy->isVectorType()); in isLaxVectorConversion()
7534 if (!srcTy->isIntegralOrEnumerationType()) { in isLaxVectorConversion()
7535 auto *Vec = srcTy->getAs<VectorType>(); in isLaxVectorConversion()
7536 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType()) in isLaxVectorConversion()
7539 if (!destTy->isIntegralOrEnumerationType()) { in isLaxVectorConversion()
7540 auto *Vec = destTy->getAs<VectorType>(); in isLaxVectorConversion()
7541 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType()) in isLaxVectorConversion()
7544 // OK, integer (vector) -> integer (vector) bitcast. in isLaxVectorConversion()
7556 if (SrcTy->isMatrixType() && DestTy->isMatrixType()) { in CheckMatrixCast()
7561 } else if (SrcTy->isMatrixType()) { in CheckMatrixCast()
7565 } else if (DestTy->isMatrixType()) { in CheckMatrixCast()
7577 assert(VectorTy->isVectorType() && "Not a vector type!"); in CheckVectorCast()
7579 if (Ty->isVectorType() || Ty->isIntegralType(Context)) { in CheckVectorCast()
7582 Ty->isVectorType() ? in CheckVectorCast()
7596 QualType DestElemTy = VectorTy->castAs<VectorType>()->getElementType(); in prepareVectorSplat()
7598 if (DestElemTy == SplattedExpr->getType()) in prepareVectorSplat()
7601 assert(DestElemTy->isFloatingType() || in prepareVectorSplat()
7602 DestElemTy->isIntegralOrEnumerationType()); in prepareVectorSplat()
7605 if (VectorTy->isExtVectorType() && SplattedExpr->getType()->isBooleanType()) { in prepareVectorSplat()
7606 // OpenCL requires that we convert `true` boolean expressions to -1, but in prepareVectorSplat()
7608 if (DestElemTy->isFloatingType()) { in prepareVectorSplat()
7630 assert(DestTy->isExtVectorType() && "Not an extended vector type!"); in CheckExtVectorCast()
7632 QualType SrcTy = CastExpr->getType(); in CheckExtVectorCast()
7638 if (SrcTy->isVectorType()) { in CheckExtVectorCast()
7650 // All non-pointer scalars can be cast to ExtVector type. The appropriate in CheckExtVectorCast()
7653 if (SrcTy->isPointerType()) in CheckExtVectorCast()
7669 TypeSourceInfo *castTInfo = GetTypeForDeclaratorCast(D, CastExpr->getType()); in ActOnCastExpr()
7686 QualType castType = castTInfo->getType(); in ActOnCastExpr()
7696 && castType->isVectorType() && (PE || PLE)) { in ActOnCastExpr()
7697 if (PLE && PLE->getNumExprs() == 0) { in ActOnCastExpr()
7698 Diag(PLE->getExprLoc(), diag::err_altivec_empty_initializer); in ActOnCastExpr()
7701 if (PE || PLE->getNumExprs() == 1) { in ActOnCastExpr()
7702 Expr *E = (PE ? PE->getSubExpr() : PLE->getExpr(0)); in ActOnCastExpr()
7703 if (!E->isTypeDependent() && !E->getType()->isVectorType()) in ActOnCastExpr()
7716 // This is not an AltiVec-style cast, so turn the ParenListExpr into a in ActOnCastExpr()
7724 if (getLangOpts().CPlusPlus && !castType->isVoidType()) in ActOnCastExpr()
7725 Diag(LParenLoc, diag::warn_old_style_cast) << CastExpr->getSourceRange(); in ActOnCastExpr()
7747 LiteralLParenLoc = PE->getLParenLoc(); in BuildVectorLiteral()
7748 LiteralRParenLoc = PE->getRParenLoc(); in BuildVectorLiteral()
7749 exprs = PE->getExprs(); in BuildVectorLiteral()
7750 numExprs = PE->getNumExprs(); in BuildVectorLiteral()
7752 LiteralLParenLoc = cast<ParenExpr>(E)->getLParen(); in BuildVectorLiteral()
7753 LiteralRParenLoc = cast<ParenExpr>(E)->getRParen(); in BuildVectorLiteral()
7754 subExpr = cast<ParenExpr>(E)->getSubExpr(); in BuildVectorLiteral()
7759 QualType Ty = TInfo->getType(); in BuildVectorLiteral()
7760 assert(Ty->isVectorType() && "Expected vector type"); in BuildVectorLiteral()
7763 const VectorType *VTy = Ty->castAs<VectorType>(); in BuildVectorLiteral()
7764 unsigned numElems = VTy->getNumElements(); in BuildVectorLiteral()
7770 if (CheckAltivecInitFromScalar(E->getSourceRange(), Ty, in BuildVectorLiteral()
7771 VTy->getElementType())) in BuildVectorLiteral()
7778 QualType ElemTy = VTy->getElementType(); in BuildVectorLiteral()
7787 Diag(E->getExprLoc(), in BuildVectorLiteral()
7797 if (getLangOpts().OpenCL && VTy->getVectorKind() == VectorKind::Generic && in BuildVectorLiteral()
7799 QualType ElemTy = VTy->getElementType(); in BuildVectorLiteral()
7810 // FIXME: This means that pretty-printing the final AST will produce curly in BuildVectorLiteral()
7814 initE->setType(Ty); in BuildVectorLiteral()
7824 ExprResult Result(E->getExpr(0)); in MaybeConvertParenListExprToParenExpr()
7826 for (unsigned i = 1, e = E->getNumExprs(); i != e && !Result.isInvalid(); ++i) in MaybeConvertParenListExprToParenExpr()
7827 Result = ActOnBinOp(S, E->getExprLoc(), tok::comma, Result.get(), in MaybeConvertParenListExprToParenExpr()
7828 E->getExpr(i)); in MaybeConvertParenListExprToParenExpr()
7832 return ActOnParenExpr(E->getLParenLoc(), E->getRParenLoc(), Result.get()); in MaybeConvertParenListExprToParenExpr()
7835 ExprResult Sema::ActOnParenListExpr(SourceLocation L, in ActOnParenListExpr() argument
7838 return ParenListExpr::Create(Context, L, Val, R); in ActOnParenListExpr()
7846 NullExpr->isNullPointerConstant(Context, in DiagnoseConditionalForNull()
7853 NullExpr->isNullPointerConstant(Context, in DiagnoseConditionalForNull()
7866 NullExpr = NullExpr->IgnoreParenImpCasts(); in DiagnoseConditionalForNull()
7867 SourceLocation loc = NullExpr->getExprLoc(); in DiagnoseConditionalForNull()
7874 << NonPointerExpr->getType() << DiagType in DiagnoseConditionalForNull()
7875 << NonPointerExpr->getSourceRange(); in DiagnoseConditionalForNull()
7882 QualType CondTy = Cond->getType(); in checkCondition()
7885 if (S.getLangOpts().OpenCL && CondTy->isFloatingType()) { in checkCondition()
7887 << CondTy << Cond->getSourceRange(); in checkCondition()
7892 if (CondTy->isScalarType()) return false; in checkCondition()
7895 << CondTy << Cond->getSourceRange(); in checkCondition()
7903 if ((!PointerTy->isAnyPointerType() && !PointerTy->isBlockPointerType()) || in checkConditionalNullPointer()
7904 !NullExpr.get()->isNullPointerConstant(S.Context, in checkConditionalNullPointer()
7917 QualType LHSTy = LHS.get()->getType(); in checkConditionalPointerCompatibility()
7918 QualType RHSTy = RHS.get()->getType(); in checkConditionalPointerCompatibility()
7929 if (const BlockPointerType *LHSBTy = LHSTy->getAs<BlockPointerType>()) { in checkConditionalPointerCompatibility()
7930 lhptee = LHSBTy->getPointeeType(); in checkConditionalPointerCompatibility()
7931 rhptee = RHSTy->castAs<BlockPointerType>()->getPointeeType(); in checkConditionalPointerCompatibility()
7934 lhptee = LHSTy->castAs<PointerType>()->getPointeeType(); in checkConditionalPointerCompatibility()
7935 rhptee = RHSTy->castAs<PointerType>()->getPointeeType(); in checkConditionalPointerCompatibility()
7943 // Only CVR-qualifiers exist in the standard, and the differently-qualified in checkConditionalPointerCompatibility()
7944 // clause doesn't make sense for our extensions. E.g. address space 2 should in checkConditionalPointerCompatibility()
7954 // OpenCL v1.1 s6.5 - Conversion between pointers to distinct address in checkConditionalPointerCompatibility()
7962 << LHSTy << RHSTy << 2 << LHS.get()->getSourceRange() in checkConditionalPointerCompatibility()
7963 << RHS.get()->getSourceRange(); in checkConditionalPointerCompatibility()
8014 << LHSTy << RHSTy << LHS.get()->getSourceRange() in checkConditionalPointerCompatibility()
8015 << RHS.get()->getSourceRange(); in checkConditionalPointerCompatibility()
8022 // which is a superset of address spaces of both the 2nd and the 3rd in checkConditionalPointerCompatibility()
8049 QualType LHSTy = LHS.get()->getType(); in checkConditionalBlockPointerCompatibility()
8050 QualType RHSTy = RHS.get()->getType(); in checkConditionalBlockPointerCompatibility()
8052 if (!LHSTy->isBlockPointerType() || !RHSTy->isBlockPointerType()) { in checkConditionalBlockPointerCompatibility()
8053 if (LHSTy->isVoidPointerType() || RHSTy->isVoidPointerType()) { in checkConditionalBlockPointerCompatibility()
8060 << LHSTy << RHSTy << LHS.get()->getSourceRange() in checkConditionalBlockPointerCompatibility()
8061 << RHS.get()->getSourceRange(); in checkConditionalBlockPointerCompatibility()
8065 // We have 2 block pointer types. in checkConditionalBlockPointerCompatibility()
8075 QualType LHSTy = LHS.get()->getType(); in checkConditionalObjectPointersCompatibility()
8076 QualType RHSTy = RHS.get()->getType(); in checkConditionalObjectPointersCompatibility()
8079 QualType lhptee = LHSTy->castAs<PointerType>()->getPointeeType(); in checkConditionalObjectPointersCompatibility()
8080 QualType rhptee = RHSTy->castAs<PointerType>()->getPointeeType(); in checkConditionalObjectPointersCompatibility()
8083 if (lhptee->isVoidType() && rhptee->isIncompleteOrObjectType()) { in checkConditionalObjectPointersCompatibility()
8094 if (rhptee->isVoidType() && lhptee->isIncompleteOrObjectType()) { in checkConditionalObjectPointersCompatibility()
8113 if (!PointerExpr->getType()->isPointerType() || in checkPointerIntegerMismatch()
8114 !Int.get()->getType()->isIntegerType()) in checkPointerIntegerMismatch()
8121 << Expr1->getType() << Expr2->getType() in checkPointerIntegerMismatch()
8122 << Expr1->getSourceRange() << Expr2->getSourceRange(); in checkPointerIntegerMismatch()
8123 Int = S.ImpCastExprToType(Int.get(), PointerExpr->getType(), in checkPointerIntegerMismatch()
8153 S.Context.getCanonicalType(LHS.get()->getType()).getUnqualifiedType(); in OpenCLArithmeticConversions()
8155 S.Context.getCanonicalType(RHS.get()->getType()).getUnqualifiedType(); in OpenCLArithmeticConversions()
8157 if (!LHSType->isIntegerType() && !LHSType->isRealFloatingType()) { in OpenCLArithmeticConversions()
8159 << LHSType << LHS.get()->getSourceRange(); in OpenCLArithmeticConversions()
8163 if (!RHSType->isIntegerType() && !RHSType->isRealFloatingType()) { in OpenCLArithmeticConversions()
8165 << RHSType << RHS.get()->getSourceRange(); in OpenCLArithmeticConversions()
8174 if (LHSType->isRealFloatingType() || RHSType->isRealFloatingType()) in OpenCLArithmeticConversions()
8200 const VectorType *CV = CondTy->getAs<VectorType>(); in OpenCLConvertScalarsToVectors()
8204 unsigned NumElements = CV->getNumElements(); in OpenCLConvertScalarsToVectors()
8208 if (S.Context.getTypeSize(CV->getElementType()) in OpenCLConvertScalarsToVectors()
8233 const VectorType *CondTy = Cond->getType()->getAs<VectorType>(); in checkOpenCLConditionVector()
8235 QualType EleTy = CondTy->getElementType(); in checkOpenCLConditionVector()
8236 if (EleTy->isIntegerType()) return false; in checkOpenCLConditionVector()
8239 << Cond->getType() << Cond->getSourceRange(); in checkOpenCLConditionVector()
8251 const VectorType *CV = CondTy->getAs<VectorType>(); in checkVectorResult()
8252 const VectorType *RV = VecResTy->getAs<VectorType>(); in checkVectorResult()
8255 if (CV->getNumElements() != RV->getNumElements()) { in checkVectorResult()
8261 QualType CVE = CV->getElementType(); in checkVectorResult()
8262 QualType RVE = RV->getElementType(); in checkVectorResult()
8283 QualType CondTy = Cond.get()->getType(); in OpenCLCheckVectorConditional()
8290 if (LHS.get()->getType()->isVectorType() || in OpenCLCheckVectorConditional()
8291 RHS.get()->getType()->isVectorType()) { in OpenCLCheckVectorConditional()
8317 QualType Ty = CE->getCallee()->getType(); in checkBlockType()
8318 if (Ty->isBlockPointerType()) { in checkBlockType()
8319 S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block); in checkBlockType()
8350 (Cond.get()->isTypeDependent() || LHS.get()->isTypeDependent() || in CheckConditionalOperands()
8351 RHS.get()->isTypeDependent())) { in CheckConditionalOperands()
8353 assert((Cond.get()->containsErrors() || LHS.get()->containsErrors() || in CheckConditionalOperands()
8354 RHS.get()->containsErrors()) && in CheckConditionalOperands()
8355 "should only occur in error-recovery path."); in CheckConditionalOperands()
8361 if ((getLangOpts().OpenCL && Cond.get()->getType()->isVectorType()) || in CheckConditionalOperands()
8362 Cond.get()->getType()->isExtVectorType()) in CheckConditionalOperands()
8373 if (LHS.get()->getType()->isVectorType() || in CheckConditionalOperands()
8374 RHS.get()->getType()->isVectorType()) in CheckConditionalOperands()
8387 QualType LHSTy = LHS.get()->getType(); in CheckConditionalOperands()
8388 QualType RHSTy = RHS.get()->getType(); in CheckConditionalOperands()
8389 if (LHSTy->isWebAssemblyTableType() || RHSTy->isWebAssemblyTableType()) { in CheckConditionalOperands()
8391 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in CheckConditionalOperands()
8400 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in CheckConditionalOperands()
8404 // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary in CheckConditionalOperands()
8413 if (LHSTy->isArithmeticType() && RHSTy->isArithmeticType()) { in CheckConditionalOperands()
8414 // Disallow invalid arithmetic conversions, such as those between bit- in CheckConditionalOperands()
8415 // precise integers types of different sizes, or between a bit-precise in CheckConditionalOperands()
8417 if (ResTy.isNull() && (LHSTy->isBitIntType() || RHSTy->isBitIntType())) { in CheckConditionalOperands()
8419 << LHSTy << RHSTy << LHS.get()->getSourceRange() in CheckConditionalOperands()
8420 << RHS.get()->getSourceRange(); in CheckConditionalOperands()
8432 if (const RecordType *LHSRT = LHSTy->getAs<RecordType>()) { // C99 6.5.15p3 in CheckConditionalOperands()
8433 if (const RecordType *RHSRT = RHSTy->getAs<RecordType>()) in CheckConditionalOperands()
8434 if (LHSRT->getDecl() == RHSRT->getDecl()) in CheckConditionalOperands()
8443 // The following || allows only one side to be void (a GCC-ism). in CheckConditionalOperands()
8444 if (LHSTy->isVoidType() || RHSTy->isVoidType()) { in CheckConditionalOperands()
8446 if (LHSTy->isVoidType() && RHSTy->isVoidType()) { in CheckConditionalOperands()
8448 } else if (RHSTy->isVoidType()) { in CheckConditionalOperands()
8450 Diag(RHS.get()->getBeginLoc(), diag::ext_typecheck_cond_one_void) in CheckConditionalOperands()
8451 << RHS.get()->getSourceRange(); in CheckConditionalOperands()
8454 Diag(LHS.get()->getBeginLoc(), diag::ext_typecheck_cond_one_void) in CheckConditionalOperands()
8455 << LHS.get()->getSourceRange(); in CheckConditionalOperands()
8465 if (LHSTy->isNullPtrType() && Context.hasSameType(LHSTy, RHSTy)) in CheckConditionalOperands()
8468 // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has in CheckConditionalOperands()
8473 // All objective-c pointer type analysis is done here. in CheckConditionalOperands()
8483 if (LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) in CheckConditionalOperands()
8488 if (LHSTy->isPointerType() && RHSTy->isPointerType()) in CheckConditionalOperands()
8514 << LHSTy << RHSTy << LHS.get()->getSourceRange() in CheckConditionalOperands()
8515 << RHS.get()->getSourceRange(); in CheckConditionalOperands()
8519 /// SuggestParentheses - Emit a note with a fixit hint that wraps
8540 // This only checks for bitwise-or and bitwise-and, but not bitwise-xor and in IsArithmeticOp()
8541 // not any of the logical operators. Bitwise-xor is commonly used as a in IsArithmeticOp()
8542 // logical-xor because there is no logical-xor operator. The logical in IsArithmeticOp()
8547 /// IsArithmeticBinaryExpr - Returns true if E is an arithmetic binary
8548 /// expression, either using a built-in or overloaded operator,
8549 /// and sets *OpCode to the opcode and *RHSExprs to the right-hand side
8554 E = E->IgnoreImpCasts(); in IsArithmeticBinaryExpr()
8555 E = E->IgnoreConversionOperatorSingleStep(); in IsArithmeticBinaryExpr()
8556 E = E->IgnoreImpCasts(); in IsArithmeticBinaryExpr()
8558 E = MTE->getSubExpr(); in IsArithmeticBinaryExpr()
8559 E = E->IgnoreImpCasts(); in IsArithmeticBinaryExpr()
8562 // Built-in binary operator. in IsArithmeticBinaryExpr()
8564 OP && IsArithmeticOp(OP->getOpcode())) { in IsArithmeticBinaryExpr()
8565 *Opcode = OP->getOpcode(); in IsArithmeticBinaryExpr()
8566 *RHSExprs = OP->getRHS(); in IsArithmeticBinaryExpr()
8572 if (Call->getNumArgs() != 2) in IsArithmeticBinaryExpr()
8577 OverloadedOperatorKind OO = Call->getOperator(); in IsArithmeticBinaryExpr()
8585 *RHSExprs = Call->getArg(1); in IsArithmeticBinaryExpr()
8593 /// ExprLooksBoolean - Returns true if E looks boolean, i.e. it has boolean type
8597 E = E->IgnoreParenImpCasts(); in ExprLooksBoolean()
8599 if (E->getType()->isBooleanType()) in ExprLooksBoolean()
8602 return OP->isComparisonOp() || OP->isLogicalOp(); in ExprLooksBoolean()
8604 return OP->getOpcode() == UO_LNot; in ExprLooksBoolean()
8605 if (E->getType()->isPointerType()) in ExprLooksBoolean()
8608 // type"s (commonly pointer-to-members)? in ExprLooksBoolean()
8613 /// DiagnoseConditionalPrecedence - Emit a warning when a conditional operator
8616 /// "int x = a + someBinaryCondition ? 1 : 2".
8628 // The condition is an arithmetic binary expression, with a right- in DiagnoseConditionalPrecedence()
8636 << Condition->getSourceRange() in DiagnoseConditionalPrecedence()
8643 SourceRange(Condition->getBeginLoc(), Condition->getEndLoc())); in DiagnoseConditionalPrecedence()
8647 SourceRange(CondRHS->getBeginLoc(), RHSExpr->getEndLoc())); in DiagnoseConditionalPrecedence()
8654 if (!ResTy->isAnyPointerType()) in computeConditionalNullability()
8658 std::optional<NullabilityKind> Kind = Ty->getNullability(); in computeConditionalNullability()
8695 while (ResTy->getNullability()) in computeConditionalNullability()
8739 // as Objective-C++'s dictionary subscripting syntax. in ActOnConditionalOp()
8740 if (commonExpr->hasPlaceholderType()) { in ActOnConditionalOp()
8746 // in the special case of a C++ l-value conditional. in ActOnConditionalOp()
8748 && !commonExpr->isTypeDependent() in ActOnConditionalOp()
8749 && commonExpr->getValueKind() == RHSExpr->getValueKind() in ActOnConditionalOp()
8750 && commonExpr->isGLValue() in ActOnConditionalOp()
8751 && commonExpr->isOrdinaryOrBitFieldObject() in ActOnConditionalOp()
8752 && RHSExpr->isOrdinaryOrBitFieldObject() in ActOnConditionalOp()
8753 && Context.hasSameType(commonExpr->getType(), RHSExpr->getType()))) { in ActOnConditionalOp()
8762 if (commonExpr->isPRValue() && (commonExpr->getType()->isRecordType() || in ActOnConditionalOp()
8763 commonExpr->getType()->isArrayType())) { in ActOnConditionalOp()
8770 opaqueValue = new (Context) OpaqueValueExpr(commonExpr->getExprLoc(), in ActOnConditionalOp()
8771 commonExpr->getType(), in ActOnConditionalOp()
8772 commonExpr->getValueKind(), in ActOnConditionalOp()
8773 commonExpr->getObjectKind(), in ActOnConditionalOp()
8778 QualType LHSTy = LHSExpr->getType(), RHSTy = RHSExpr->getType(); in ActOnConditionalOp()
8811 FromFn->getAArch64SMEAttributes() & FunctionType::SME_AttributeMask; in IsInvalidSMECallConversion()
8815 ToFn->getAArch64SMEAttributes() & FunctionType::SME_AttributeMask; in IsInvalidSMECallConversion()
8829 FunctionType::ExtInfo ToEInfo = ToFn->getExtInfo(); in IsInvalidCmseNSCallConversion()
8830 FunctionType::ExtInfo FromEInfo = FromFn->getExtInfo(); in IsInvalidCmseNSCallConversion()
8838 // checkPointerTypesForAssignment - This is a very tricky routine (despite
8839 // being closely modeled after the C99 spec:-). The odd characteristic of this
8841 // This circumvents the usual type rules specified in 6.2.7p1 & 6.7.5.[1-3].
8853 cast<PointerType>(LHSType)->getPointeeType().split().asPair(); in checkPointerTypesForAssignment()
8855 cast<PointerType>(RHSType)->getPointeeType().split().asPair(); in checkPointerTypesForAssignment()
8863 // As a special case, 'non-__weak A *' -> 'non-__weak const *' is okay. in checkPointerTypesForAssignment()
8872 // Treat address-space mismatches as fatal. in checkPointerTypesForAssignment()
8881 && (lhptee->isVoidType() || rhptee->isVoidType())) in checkPointerTypesForAssignment()
8896 if (lhptee->isVoidType()) { in checkPointerTypesForAssignment()
8897 if (rhptee->isIncompleteOrObjectType()) in checkPointerTypesForAssignment()
8901 assert(rhptee->isFunctionType()); in checkPointerTypesForAssignment()
8905 if (rhptee->isVoidType()) { in checkPointerTypesForAssignment()
8906 if (lhptee->isIncompleteOrObjectType()) in checkPointerTypesForAssignment()
8910 assert(lhptee->isFunctionType()); in checkPointerTypesForAssignment()
8917 RHSType->isFunctionPointerType() && LHSType->isFunctionPointerType() && in checkPointerTypesForAssignment()
8928 if (lhptee->isCharType()) in checkPointerTypesForAssignment()
8930 else if (lhptee->hasSignedIntegerRepresentation()) in checkPointerTypesForAssignment()
8933 if (rhptee->isCharType()) in checkPointerTypesForAssignment()
8935 else if (rhptee->hasSignedIntegerRepresentation()) in checkPointerTypesForAssignment()
8948 // If we are a multi-level pointer, it's possible that our issue is simply in checkPointerTypesForAssignment()
8949 // one of qualification - e.g. char ** -> const char ** is not allowed. If in checkPointerTypesForAssignment()
8955 cast<PointerType>(lhptee)->getPointeeType().split().asPair(); in checkPointerTypesForAssignment()
8957 cast<PointerType>(rhptee)->getPointeeType().split().asPair(); in checkPointerTypesForAssignment()
8977 if (RHSType->isFunctionPointerType() && LHSType->isFunctionPointerType()) in checkPointerTypesForAssignment()
8991 /// checkBlockPointerTypesForAssignment - This routine determines whether two
9004 lhptee = cast<BlockPointerType>(LHSType)->getPointeeType(); in checkBlockPointerTypesForAssignment()
9005 rhptee = cast<BlockPointerType>(RHSType)->getPointeeType(); in checkBlockPointerTypesForAssignment()
9044 /// checkObjCPointerTypesForAssignment - Compares two objective-c pointer types
9052 if (LHSType->isObjCBuiltinType()) { in checkObjCPointerTypesForAssignment()
9054 if (LHSType->isObjCClassType() && !RHSType->isObjCBuiltinType() && in checkObjCPointerTypesForAssignment()
9055 !RHSType->isObjCQualifiedClassType()) in checkObjCPointerTypesForAssignment()
9059 if (RHSType->isObjCBuiltinType()) { in checkObjCPointerTypesForAssignment()
9060 if (RHSType->isObjCClassType() && !LHSType->isObjCBuiltinType() && in checkObjCPointerTypesForAssignment()
9061 !LHSType->isObjCQualifiedClassType()) in checkObjCPointerTypesForAssignment()
9065 QualType lhptee = LHSType->castAs<ObjCObjectPointerType>()->getPointeeType(); in checkObjCPointerTypesForAssignment()
9066 QualType rhptee = RHSType->castAs<ObjCObjectPointerType>()->getPointeeType(); in checkObjCPointerTypesForAssignment()
9070 !LHSType->isObjCQualifiedIdType()) in checkObjCPointerTypesForAssignment()
9075 if (LHSType->isObjCQualifiedIdType() || RHSType->isObjCQualifiedIdType()) in checkObjCPointerTypesForAssignment()
9097 if (const VectorType *VT = QT->getAs<VectorType>()) in isVector()
9098 return VT->getElementType().getCanonicalType() == ElementType; in isVector()
9102 /// CheckAssignmentConstraints (C99 6.5.16) - This routine currently
9122 QualType RHSType = RHS.get()->getType(); in CheckAssignmentConstraints()
9139 if (AT->isGNUAutoType()) { in CheckAssignmentConstraints()
9145 // If we have an atomic type, try a non-atomic assignment, then just add an in CheckAssignmentConstraints()
9149 CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind); in CheckAssignmentConstraints()
9153 RHS = ImpCastExprToType(RHS.get(), AtomicTy->getValueType(), Kind); in CheckAssignmentConstraints()
9158 // If the left-hand side is a reference type, then we are in a in CheckAssignmentConstraints()
9160 // e.g., as a parameter type in a built-in function. In this case, in CheckAssignmentConstraints()
9162 // right-hand side type. The caller is responsible for adjusting in CheckAssignmentConstraints()
9165 if (const ReferenceType *LHSTypeRef = LHSType->getAs<ReferenceType>()) { in CheckAssignmentConstraints()
9166 if (Context.typesAreCompatible(LHSTypeRef->getPointeeType(), RHSType)) { in CheckAssignmentConstraints()
9175 if (LHSType->isExtVectorType()) { in CheckAssignmentConstraints()
9176 if (RHSType->isExtVectorType()) in CheckAssignmentConstraints()
9178 if (RHSType->isArithmeticType()) { in CheckAssignmentConstraints()
9179 // CK_VectorSplat does T -> vector T, so first cast to the element type. in CheckAssignmentConstraints()
9188 if (LHSType->isVectorType() || RHSType->isVectorType()) { in CheckAssignmentConstraints()
9189 if (LHSType->isVectorType() && RHSType->isVectorType()) { in CheckAssignmentConstraints()
9207 Diag(RHS.get()->getExprLoc(), diag::warn_deprecated_lax_vec_conv_all) in CheckAssignmentConstraints()
9218 if (LHSType->isScalarType()) { in CheckAssignmentConstraints()
9219 const VectorType *VecType = RHSType->getAs<VectorType>(); in CheckAssignmentConstraints()
9220 if (VecType && VecType->getNumElements() == 1 && in CheckAssignmentConstraints()
9223 (VecType->getVectorKind() == VectorKind::AltiVecVector || in CheckAssignmentConstraints()
9224 VecType->getVectorKind() == VectorKind::AltiVecBool || in CheckAssignmentConstraints()
9225 VecType->getVectorKind() == VectorKind::AltiVecPixel)) in CheckAssignmentConstraints()
9226 Diag(RHS.get()->getExprLoc(), diag::warn_deprecated_lax_vec_conv_all) in CheckAssignmentConstraints()
9229 *VecExpr = ImpCastExprToType(VecExpr->get(), LHSType, CK_BitCast); in CheckAssignmentConstraints()
9235 // Allow assignments between fixed-length and sizeless SVE vectors. in CheckAssignmentConstraints()
9236 if ((LHSType->isSVESizelessBuiltinType() && RHSType->isVectorType()) || in CheckAssignmentConstraints()
9237 (LHSType->isVectorType() && RHSType->isSVESizelessBuiltinType())) in CheckAssignmentConstraints()
9244 // Allow assignments between fixed-length and sizeless RVV vectors. in CheckAssignmentConstraints()
9245 if ((LHSType->isRVVSizelessBuiltinType() && RHSType->isVectorType()) || in CheckAssignmentConstraints()
9246 (LHSType->isVectorType() && RHSType->isRVVSizelessBuiltinType())) { in CheckAssignmentConstraints()
9264 if (getLangOpts().CPlusPlus && RHSType->getAs<ComplexType>() && in CheckAssignmentConstraints()
9265 !LHSType->getAs<ComplexType>()) in CheckAssignmentConstraints()
9269 if (LHSType->isArithmeticType() && RHSType->isArithmeticType() && in CheckAssignmentConstraints()
9270 !(getLangOpts().CPlusPlus && LHSType->isEnumeralType())) { in CheckAssignmentConstraints()
9278 // U* -> T* in CheckAssignmentConstraints()
9280 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace(); in CheckAssignmentConstraints()
9281 LangAS AddrSpaceR = RHSType->getPointeeType().getAddressSpace(); in CheckAssignmentConstraints()
9289 RHS.get()->getBeginLoc()); in CheckAssignmentConstraints()
9292 // int -> T* in CheckAssignmentConstraints()
9293 if (RHSType->isIntegerType()) { in CheckAssignmentConstraints()
9301 // - conversions to void* in CheckAssignmentConstraints()
9302 if (LHSPointer->getPointeeType()->isVoidType()) { in CheckAssignmentConstraints()
9307 // - conversions from 'Class' to the redefinition type in CheckAssignmentConstraints()
9308 if (RHSType->isObjCClassType() && in CheckAssignmentConstraints()
9319 // U^ -> void* in CheckAssignmentConstraints()
9320 if (RHSType->getAs<BlockPointerType>()) { in CheckAssignmentConstraints()
9321 if (LHSPointer->getPointeeType()->isVoidType()) { in CheckAssignmentConstraints()
9322 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace(); in CheckAssignmentConstraints()
9323 LangAS AddrSpaceR = RHSType->getAs<BlockPointerType>() in CheckAssignmentConstraints()
9324 ->getPointeeType() in CheckAssignmentConstraints()
9337 // U^ -> T^ in CheckAssignmentConstraints()
9338 if (RHSType->isBlockPointerType()) { in CheckAssignmentConstraints()
9339 LangAS AddrSpaceL = LHSType->getAs<BlockPointerType>() in CheckAssignmentConstraints()
9340 ->getPointeeType() in CheckAssignmentConstraints()
9342 LangAS AddrSpaceR = RHSType->getAs<BlockPointerType>() in CheckAssignmentConstraints()
9343 ->getPointeeType() in CheckAssignmentConstraints()
9349 // int or null -> T^ in CheckAssignmentConstraints()
9350 if (RHSType->isIntegerType()) { in CheckAssignmentConstraints()
9355 // id -> T^ in CheckAssignmentConstraints()
9356 if (getLangOpts().ObjC && RHSType->isObjCIdType()) { in CheckAssignmentConstraints()
9361 // void* -> T^ in CheckAssignmentConstraints()
9362 if (const PointerType *RHSPT = RHSType->getAs<PointerType>()) in CheckAssignmentConstraints()
9363 if (RHSPT->getPointeeType()->isVoidType()) { in CheckAssignmentConstraints()
9371 // Conversions to Objective-C pointers. in CheckAssignmentConstraints()
9373 // A* -> B* in CheckAssignmentConstraints()
9374 if (RHSType->isObjCObjectPointerType()) { in CheckAssignmentConstraints()
9385 // int or null -> A* in CheckAssignmentConstraints()
9386 if (RHSType->isIntegerType()) { in CheckAssignmentConstraints()
9396 // - conversions from 'void*' in CheckAssignmentConstraints()
9397 if (RHSType->isVoidPointerType()) { in CheckAssignmentConstraints()
9401 // - conversions to 'Class' from its redefinition type in CheckAssignmentConstraints()
9402 if (LHSType->isObjCClassType() && in CheckAssignmentConstraints()
9411 // Only under strict condition T^ is compatible with an Objective-C pointer. in CheckAssignmentConstraints()
9412 if (RHSType->isBlockPointerType() && in CheckAssignmentConstraints()
9413 LHSType->isBlockCompatibleObjCPointerType(Context)) { in CheckAssignmentConstraints()
9424 if (getLangOpts().C23 && LHSType->isNullPtrType() && in CheckAssignmentConstraints()
9425 RHS.get()->isNullPointerConstant(Context, in CheckAssignmentConstraints()
9427 // null -> nullptr_t in CheckAssignmentConstraints()
9434 // T* -> _Bool in CheckAssignmentConstraints()
9440 // T* -> int in CheckAssignmentConstraints()
9441 if (LHSType->isIntegerType()) { in CheckAssignmentConstraints()
9449 // Conversions from Objective-C pointers that are not covered by the above. in CheckAssignmentConstraints()
9451 // T* -> _Bool in CheckAssignmentConstraints()
9457 // T* -> int in CheckAssignmentConstraints()
9458 if (LHSType->isIntegerType()) { in CheckAssignmentConstraints()
9466 // struct A -> struct B in CheckAssignmentConstraints()
9474 if (LHSType->isSamplerT() && RHSType->isIntegerType()) { in CheckAssignmentConstraints()
9492 Initializer->setType(UnionType); in ConstructTransparentUnion()
9493 Initializer->setInitializedFieldInUnion(Field); in ConstructTransparentUnion()
9505 QualType RHSType = RHS.get()->getType(); in CheckTransparentUnionArgumentConstraints()
9509 const RecordType *UT = ArgType->getAsUnionType(); in CheckTransparentUnionArgumentConstraints()
9510 if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>()) in CheckTransparentUnionArgumentConstraints()
9514 RecordDecl *UD = UT->getDecl(); in CheckTransparentUnionArgumentConstraints()
9517 for (auto *it : UD->fields()) { in CheckTransparentUnionArgumentConstraints()
9518 if (it->getType()->isPointerType()) { in CheckTransparentUnionArgumentConstraints()
9521 // 2) null pointer constant in CheckTransparentUnionArgumentConstraints()
9522 if (RHSType->isPointerType()) in CheckTransparentUnionArgumentConstraints()
9523 if (RHSType->castAs<PointerType>()->getPointeeType()->isVoidType()) { in CheckTransparentUnionArgumentConstraints()
9524 RHS = ImpCastExprToType(RHS.get(), it->getType(), CK_BitCast); in CheckTransparentUnionArgumentConstraints()
9529 if (RHS.get()->isNullPointerConstant(Context, in CheckTransparentUnionArgumentConstraints()
9531 RHS = ImpCastExprToType(RHS.get(), it->getType(), in CheckTransparentUnionArgumentConstraints()
9539 if (CheckAssignmentConstraints(it->getType(), RHS, Kind) in CheckTransparentUnionArgumentConstraints()
9541 RHS = ImpCastExprToType(RHS.get(), it->getType(), Kind); in CheckTransparentUnionArgumentConstraints()
9569 if (const auto *LHSPtrType = LHSType->getAs<PointerType>()) { in CheckSingleAssignmentConstraints()
9570 if (const auto *RHSPtrType = RHS.get()->getType()->getAs<PointerType>()) { in CheckSingleAssignmentConstraints()
9571 if (RHSPtrType->getPointeeType()->hasAttr(attr::NoDeref) && in CheckSingleAssignmentConstraints()
9572 !LHSPtrType->getPointeeType()->hasAttr(attr::NoDeref)) { in CheckSingleAssignmentConstraints()
9573 Diag(RHS.get()->getExprLoc(), in CheckSingleAssignmentConstraints()
9575 << RHS.get()->getSourceRange(); in CheckSingleAssignmentConstraints()
9581 if (!LHSType->isRecordType() && !LHSType->isAtomicType()) { in CheckSingleAssignmentConstraints()
9584 // cv-unqualified type of the left operand. in CheckSingleAssignmentConstraints()
9585 QualType RHSType = RHS.get()->getType(); in CheckSingleAssignmentConstraints()
9615 } else if (RHS.get()->getType() == Context.OverloadTy) { in CheckSingleAssignmentConstraints()
9637 if (!LHSType->isReferenceType()) { in CheckSingleAssignmentConstraints()
9650 if ((LHSTypeAfterConversion->isPointerType() || in CheckSingleAssignmentConstraints()
9651 LHSTypeAfterConversion->isObjCObjectPointerType() || in CheckSingleAssignmentConstraints()
9652 LHSTypeAfterConversion->isBlockPointerType()) && in CheckSingleAssignmentConstraints()
9653 ((getLangOpts().C23 && RHS.get()->getType()->isNullPtrType()) || in CheckSingleAssignmentConstraints()
9654 RHS.get()->isNullPointerConstant(Context, in CheckSingleAssignmentConstraints()
9669 if (getLangOpts().C23 && LHSType->isBooleanType() && in CheckSingleAssignmentConstraints()
9670 RHS.get()->getType()->isNullPtrType()) { in CheckSingleAssignmentConstraints()
9671 // NB: T* -> _Bool is handled in CheckAssignmentConstraints, this only in CheckSingleAssignmentConstraints()
9672 // only handles nullptr -> _Bool due to needing an extra conversion in CheckSingleAssignmentConstraints()
9674 // We model this by converting from nullptr -> void * and then let the in CheckSingleAssignmentConstraints()
9675 // conversion from void * -> _Bool happen naturally. in CheckSingleAssignmentConstraints()
9688 if (LHSType->isQueueT() && RHS.get()->isNullPointerConstant( in CheckSingleAssignmentConstraints()
9700 // CheckAssignmentConstraints allows the left-hand side to be a reference, in CheckSingleAssignmentConstraints()
9701 // so that we can use references in built-in functions even in C. in CheckSingleAssignmentConstraints()
9704 if (result != Incompatible && RHS.get()->getType() != LHSType) { in CheckSingleAssignmentConstraints()
9708 // Check for various Objective-C errors. If we are not reporting in CheckSingleAssignmentConstraints()
9719 (ObjC().CheckObjCBridgeRelatedConversions(E->getBeginLoc(), LHSType, in CheckSingleAssignmentConstraints()
9720 E->getType(), E, Diagnose) || in CheckSingleAssignmentConstraints()
9744 Op = MTE->getSubExpr(); in OriginalOperand()
9746 Op = BTE->getSubExpr(); in OriginalOperand()
9748 Orig = ICE->getSubExprAsWritten(); in OriginalOperand()
9749 Conversion = ICE->getConversionFunction(); in OriginalOperand()
9753 QualType getType() const { return Orig->getType(); } in getType()
9766 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in InvalidOperands()
9768 // If a user-defined conversion was applied to either of the operands prior in InvalidOperands()
9769 // to applying the built-in operator rules, tell the user about it. in InvalidOperands()
9771 Diag(OrigLHS.Conversion->getLocation(), in InvalidOperands()
9773 << 0 << LHS.get()->getType(); in InvalidOperands()
9776 Diag(OrigRHS.Conversion->getLocation(), in InvalidOperands()
9778 << 1 << RHS.get()->getType(); in InvalidOperands()
9786 QualType LHSType = LHS.get()->IgnoreImpCasts()->getType(); in InvalidLogicalVectorOperands()
9787 QualType RHSType = RHS.get()->IgnoreImpCasts()->getType(); in InvalidLogicalVectorOperands()
9789 bool LHSNatVec = LHSType->isVectorType(); in InvalidLogicalVectorOperands()
9790 bool RHSNatVec = RHSType->isVectorType(); in InvalidLogicalVectorOperands()
9796 << 0 << Vector->getType() << NonVector->IgnoreImpCasts()->getType() in InvalidLogicalVectorOperands()
9797 << Vector->getSourceRange(); in InvalidLogicalVectorOperands()
9802 << 1 << LHSType << RHSType << LHS.get()->getSourceRange() in InvalidLogicalVectorOperands()
9803 << RHS.get()->getSourceRange(); in InvalidLogicalVectorOperands()
9808 /// Try to convert a value of non-vector type to a vector type by converting
9811 /// rank; for C, Obj-C, and C++ we allow any real scalar conversion except
9812 /// for float->int.
9818 /// \param scalar - if non-null, actually perform the conversions
9829 if (vectorEltTy->isIntegralType(S.Context)) { in tryVectorConvertAndSplat()
9830 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() || in tryVectorConvertAndSplat()
9831 (scalarTy->isIntegerType() && in tryVectorConvertAndSplat()
9836 if (!scalarTy->isIntegralType(S.Context)) in tryVectorConvertAndSplat()
9839 } else if (vectorEltTy->isRealFloatingType()) { in tryVectorConvertAndSplat()
9840 if (scalarTy->isRealFloatingType()) { in tryVectorConvertAndSplat()
9848 else if (scalarTy->isIntegralType(S.Context)) in tryVectorConvertAndSplat()
9859 *scalar = S.ImpCastExprToType(scalar->get(), vectorEltTy, scalarCast); in tryVectorConvertAndSplat()
9860 *scalar = S.ImpCastExprToType(scalar->get(), vectorTy, CK_VectorSplat); in tryVectorConvertAndSplat()
9868 const auto *VecTy = E->getType()->getAs<VectorType>(); in convertVector()
9871 VecTy->isExtVectorType() in convertVector()
9872 ? S.Context.getExtVectorType(ElementType, VecTy->getNumElements()) in convertVector()
9873 : S.Context.getVectorType(ElementType, VecTy->getNumElements(), in convertVector()
9874 VecTy->getVectorKind()); in convertVector()
9879 if (ICE->getSubExpr()->getType() == NewVecTy) in convertVector()
9880 return ICE->getSubExpr(); in convertVector()
9882 auto Cast = ElementType->isIntegerType() ? CK_IntegralCast : CK_FloatingCast; in convertVector()
9890 QualType IntTy = Int->get()->getType().getUnqualifiedType(); in canConvertIntToOtherIntTy()
9896 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.Context); in canConvertIntToOtherIntTy()
9898 bool IntSigned = IntTy->hasSignedIntegerRepresentation(); in canConvertIntToOtherIntTy()
9899 bool OtherIntSigned = OtherIntTy->hasSignedIntegerRepresentation(); in canConvertIntToOtherIntTy()
9928 QualType IntTy = Int->get()->getType().getUnqualifiedType(); in canConvertIntTyToFloatTy()
9933 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.Context); in canConvertIntTyToFloatTy()
9944 Float.convertFromAPInt(Result, IntTy->hasSignedIntegerRepresentation(), in canConvertIntTyToFloatTy()
9947 !IntTy->hasSignedIntegerRepresentation()); in canConvertIntTyToFloatTy()
9972 QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType(); in tryGCCVectorConvertAndSplat()
9973 QualType VectorTy = Vector->get()->getType().getUnqualifiedType(); in tryGCCVectorConvertAndSplat()
9976 if (const auto *VT = VectorTy->getAs<VectorType>()) { in tryGCCVectorConvertAndSplat()
9979 VectorEltTy = VT->getElementType(); in tryGCCVectorConvertAndSplat()
9980 } else if (VectorTy->isSveVLSBuiltinType()) { in tryGCCVectorConvertAndSplat()
9982 VectorTy->castAs<BuiltinType>()->getSveEltType(S.getASTContext()); in tryGCCVectorConvertAndSplat()
9984 llvm_unreachable("Only Fixed-Length and SVE Vector types are handled here"); in tryGCCVectorConvertAndSplat()
9989 if (!VectorEltTy->isArithmeticType() || !ScalarTy->isArithmeticType()) in tryGCCVectorConvertAndSplat()
10003 if (VectorEltTy->isIntegralType(S.Context) && in tryGCCVectorConvertAndSplat()
10004 ScalarTy->isIntegralType(S.Context) && in tryGCCVectorConvertAndSplat()
10011 } else if (VectorEltTy->isIntegralType(S.Context) && in tryGCCVectorConvertAndSplat()
10012 ScalarTy->isRealFloatingType()) { in tryGCCVectorConvertAndSplat()
10017 } else if (VectorEltTy->isRealFloatingType()) { in tryGCCVectorConvertAndSplat()
10018 if (ScalarTy->isRealFloatingType()) { in tryGCCVectorConvertAndSplat()
10028 bool CstScalar = Scalar->get()->isValueDependent() || in tryGCCVectorConvertAndSplat()
10029 Scalar->get()->EvaluateAsFloat(Result, S.Context); in tryGCCVectorConvertAndSplat()
10045 } else if (ScalarTy->isIntegralType(S.Context)) { in tryGCCVectorConvertAndSplat()
10052 } else if (ScalarTy->isEnumeralType()) in tryGCCVectorConvertAndSplat()
10057 *Scalar = S.ImpCastExprToType(Scalar->get(), VectorEltTy, ScalarCast); in tryGCCVectorConvertAndSplat()
10058 *Scalar = S.ImpCastExprToType(Scalar->get(), VectorTy, CK_VectorSplat); in tryGCCVectorConvertAndSplat()
10079 QualType LHSType = LHS.get()->getType().getUnqualifiedType(); in CheckVectorOperands()
10080 QualType RHSType = RHS.get()->getType().getUnqualifiedType(); in CheckVectorOperands()
10082 const VectorType *LHSVecType = LHSType->getAs<VectorType>(); in CheckVectorOperands()
10083 const VectorType *RHSVecType = RHSType->getAs<VectorType>(); in CheckVectorOperands()
10086 // AltiVec-style "vector bool op vector bool" combinations are allowed in CheckVectorOperands()
10089 LHSVecType->getVectorKind() == VectorKind::AltiVecBool && RHSVecType && in CheckVectorOperands()
10090 RHSVecType->getVectorKind() == VectorKind::AltiVecBool) in CheckVectorOperands()
10095 (LHSType->isExtVectorBoolType() || RHSType->isExtVectorBoolType())) in CheckVectorOperands()
10115 // AllowBoolConversions says that bool and non-bool AltiVec vectors in CheckVectorOperands()
10116 // can be mixed, with the result being the non-bool type. The non-bool in CheckVectorOperands()
10119 LHSVecType->getNumElements() == RHSVecType->getNumElements() && in CheckVectorOperands()
10120 (Context.getTypeSize(LHSVecType->getElementType()) == in CheckVectorOperands()
10121 Context.getTypeSize(RHSVecType->getElementType()))) { in CheckVectorOperands()
10122 if (LHSVecType->getVectorKind() == VectorKind::AltiVecVector && in CheckVectorOperands()
10123 LHSVecType->getElementType()->isIntegerType() && in CheckVectorOperands()
10124 RHSVecType->getVectorKind() == VectorKind::AltiVecBool) { in CheckVectorOperands()
10129 LHSVecType->getVectorKind() == VectorKind::AltiVecBool && in CheckVectorOperands()
10130 RHSVecType->getVectorKind() == VectorKind::AltiVecVector && in CheckVectorOperands()
10131 RHSVecType->getElementType()->isIntegerType()) { in CheckVectorOperands()
10137 // Expressions containing fixed-length and sizeless SVE/RVV vectors are in CheckVectorOperands()
10141 const VectorType *VecType = SecondType->getAs<VectorType>(); in CheckVectorOperands()
10143 if (FirstType->isSizelessBuiltinType() && VecType) { in CheckVectorOperands()
10144 if (VecType->getVectorKind() == VectorKind::SveFixedLengthData || in CheckVectorOperands()
10145 VecType->getVectorKind() == VectorKind::SveFixedLengthPredicate) in CheckVectorOperands()
10147 if (VecType->getVectorKind() == VectorKind::RVVFixedLengthData || in CheckVectorOperands()
10148 VecType->getVectorKind() == VectorKind::RVVFixedLengthMask) { in CheckVectorOperands()
10169 const VectorType *FirstVecType = FirstType->getAs<VectorType>(); in CheckVectorOperands()
10170 const VectorType *SecondVecType = SecondType->getAs<VectorType>(); in CheckVectorOperands()
10174 if (FirstVecType->getVectorKind() == VectorKind::Generic) { in CheckVectorOperands()
10175 if (SecondVecType->getVectorKind() == VectorKind::SveFixedLengthData || in CheckVectorOperands()
10176 SecondVecType->getVectorKind() == in CheckVectorOperands()
10179 if (SecondVecType->getVectorKind() == VectorKind::RVVFixedLengthData || in CheckVectorOperands()
10180 SecondVecType->getVectorKind() == VectorKind::RVVFixedLengthMask) { in CheckVectorOperands()
10189 SecondVecType->getVectorKind() == VectorKind::Generic) { in CheckVectorOperands()
10190 if (FirstType->isSVESizelessBuiltinType()) in CheckVectorOperands()
10192 if (FirstType->isRVVSizelessBuiltinType()) { in CheckVectorOperands()
10214 LHSVecType->getElementType(), LHSType, in CheckVectorOperands()
10225 LHSType, RHSVecType->getElementType(), in CheckVectorOperands()
10229 if (LHS.get()->isLValue() || in CheckVectorOperands()
10236 // non-scalars, we should break this down into fine grained specific checks in CheckVectorOperands()
10251 *OtherExpr = ImpCastExprToType(OtherExpr->get(), VecType, CK_BitCast); in CheckVectorOperands()
10255 // type. Note that this is already done by non-compound assignments in in CheckVectorOperands()
10257 // <1 x T> -> T. The result is also a vector type. in CheckVectorOperands()
10258 } else if (OtherType->isExtVectorType() || OtherType->isVectorType() || in CheckVectorOperands()
10259 (OtherType->isScalarType() && VT->getNumElements() == 1)) { in CheckVectorOperands()
10261 *RHSExpr = ImpCastExprToType(RHSExpr->get(), LHSType, CK_BitCast); in CheckVectorOperands()
10268 // If there's a non-vector, non-real operand, diagnose that. in CheckVectorOperands()
10269 if ((!RHSVecType && !RHSType->isRealType()) || in CheckVectorOperands()
10270 (!LHSVecType && !LHSType->isRealType())) { in CheckVectorOperands()
10273 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in CheckVectorOperands()
10308 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in CheckVectorOperands()
10325 QualType LHSType = LHS.get()->getType().getUnqualifiedType(); in CheckSizelessVectorOperands()
10326 QualType RHSType = RHS.get()->getType().getUnqualifiedType(); in CheckSizelessVectorOperands()
10328 const BuiltinType *LHSBuiltinTy = LHSType->getAs<BuiltinType>(); in CheckSizelessVectorOperands()
10329 const BuiltinType *RHSBuiltinTy = RHSType->getAs<BuiltinType>(); in CheckSizelessVectorOperands()
10333 ((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) || in CheckSizelessVectorOperands()
10334 (RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) { in CheckSizelessVectorOperands()
10335 Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange() in CheckSizelessVectorOperands()
10336 << RHS.get()->getSourceRange(); in CheckSizelessVectorOperands()
10343 if (LHSType->isSveVLSBuiltinType() && !RHSType->isSveVLSBuiltinType()) { in CheckSizelessVectorOperands()
10347 if (RHSType->isSveVLSBuiltinType() && !LHSType->isSveVLSBuiltinType()) { in CheckSizelessVectorOperands()
10348 if (LHS.get()->isLValue() || in CheckSizelessVectorOperands()
10353 if ((!LHSType->isSveVLSBuiltinType() && !LHSType->isRealType()) || in CheckSizelessVectorOperands()
10354 (!RHSType->isSveVLSBuiltinType() && !RHSType->isRealType())) { in CheckSizelessVectorOperands()
10356 << LHSType << RHSType << LHS.get()->getSourceRange() in CheckSizelessVectorOperands()
10357 << RHS.get()->getSourceRange(); in CheckSizelessVectorOperands()
10361 if (LHSType->isSveVLSBuiltinType() && RHSType->isSveVLSBuiltinType() && in CheckSizelessVectorOperands()
10365 << LHSType << RHSType << LHS.get()->getSourceRange() in CheckSizelessVectorOperands()
10366 << RHS.get()->getSourceRange(); in CheckSizelessVectorOperands()
10370 if (LHSType->isSveVLSBuiltinType() || RHSType->isSveVLSBuiltinType()) { in CheckSizelessVectorOperands()
10371 QualType Scalar = LHSType->isSveVLSBuiltinType() ? RHSType : LHSType; in CheckSizelessVectorOperands()
10372 QualType Vector = LHSType->isSveVLSBuiltinType() ? LHSType : RHSType; in CheckSizelessVectorOperands()
10374 LHSType->isSveVLSBuiltinType() && RHSType->isSveVLSBuiltinType(); in CheckSizelessVectorOperands()
10382 Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange() in CheckSizelessVectorOperands()
10383 << RHS.get()->getSourceRange(); in CheckSizelessVectorOperands()
10387 // checkArithmeticNull - Detect when a NULL constant is used improperly in an
10395 bool LHSNull = isa<GNUNullExpr>(LHS.get()->IgnoreParenImpCasts()); in checkArithmeticNull()
10396 bool RHSNull = isa<GNUNullExpr>(RHS.get()->IgnoreParenImpCasts()); in checkArithmeticNull()
10398 QualType NonNullType = LHSNull ? RHS.get()->getType() : LHS.get()->getType(); in checkArithmeticNull()
10402 if ((!LHSNull && !RHSNull) || NonNullType->isBlockPointerType() || in checkArithmeticNull()
10403 NonNullType->isMemberPointerType() || NonNullType->isFunctionType()) in checkArithmeticNull()
10410 << (LHSNull ? LHS.get()->getSourceRange() : SourceRange()) in checkArithmeticNull()
10411 << (RHSNull ? RHS.get()->getSourceRange() : SourceRange()); in checkArithmeticNull()
10417 if (LHSNull == RHSNull || NonNullType->isAnyPointerType() || in checkArithmeticNull()
10418 NonNullType->canDecayToPointerType()) in checkArithmeticNull()
10423 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in checkArithmeticNull()
10432 if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() || in DiagnoseDivisionSizeofPointerOrArray()
10433 RUE->getKind() != UETT_SizeOf) in DiagnoseDivisionSizeofPointerOrArray()
10436 const Expr *LHSArg = LUE->getArgumentExpr()->IgnoreParens(); in DiagnoseDivisionSizeofPointerOrArray()
10437 QualType LHSTy = LHSArg->getType(); in DiagnoseDivisionSizeofPointerOrArray()
10440 if (RUE->isArgumentType()) in DiagnoseDivisionSizeofPointerOrArray()
10441 RHSTy = RUE->getArgumentType().getNonReferenceType(); in DiagnoseDivisionSizeofPointerOrArray()
10443 RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType(); in DiagnoseDivisionSizeofPointerOrArray()
10445 if (LHSTy->isPointerType() && !RHSTy->isPointerType()) { in DiagnoseDivisionSizeofPointerOrArray()
10446 if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(), RHSTy)) in DiagnoseDivisionSizeofPointerOrArray()
10449 S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS << LHS->getSourceRange(); in DiagnoseDivisionSizeofPointerOrArray()
10451 if (const ValueDecl *LHSArgDecl = DRE->getDecl()) in DiagnoseDivisionSizeofPointerOrArray()
10452 S.Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here) in DiagnoseDivisionSizeofPointerOrArray()
10456 QualType ArrayElemTy = ArrayTy->getElementType(); in DiagnoseDivisionSizeofPointerOrArray()
10458 ArrayElemTy->isDependentType() || RHSTy->isDependentType() || in DiagnoseDivisionSizeofPointerOrArray()
10459 RHSTy->isReferenceType() || ArrayElemTy->isCharType() || in DiagnoseDivisionSizeofPointerOrArray()
10463 << LHSArg->getSourceRange() << ArrayElemTy << RHSTy; in DiagnoseDivisionSizeofPointerOrArray()
10465 if (const ValueDecl *LHSArgDecl = DRE->getDecl()) in DiagnoseDivisionSizeofPointerOrArray()
10466 S.Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here) in DiagnoseDivisionSizeofPointerOrArray()
10479 if (!RHS.get()->isValueDependent() && in DiagnoseBadDivideOrRemainderValues()
10480 RHS.get()->EvaluateAsInt(RHSValue, S.Context) && in DiagnoseBadDivideOrRemainderValues()
10484 << IsDiv << RHS.get()->getSourceRange()); in DiagnoseBadDivideOrRemainderValues()
10492 QualType LHSTy = LHS.get()->getType(); in CheckMultiplyDivideOperands()
10493 QualType RHSTy = RHS.get()->getType(); in CheckMultiplyDivideOperands()
10494 if (LHSTy->isVectorType() || RHSTy->isVectorType()) in CheckMultiplyDivideOperands()
10500 if (LHSTy->isSveVLSBuiltinType() || RHSTy->isSveVLSBuiltinType()) in CheckMultiplyDivideOperands()
10504 (LHSTy->isConstantMatrixType() || RHSTy->isConstantMatrixType())) in CheckMultiplyDivideOperands()
10506 // For division, only matrix-by-scalar is supported. Other combinations with in CheckMultiplyDivideOperands()
10508 if (IsDiv && LHSTy->isConstantMatrixType() && RHSTy->isArithmeticType()) in CheckMultiplyDivideOperands()
10517 if (compType.isNull() || !compType->isArithmeticType()) in CheckMultiplyDivideOperands()
10530 if (LHS.get()->getType()->isVectorType() || in CheckRemainderOperands()
10531 RHS.get()->getType()->isVectorType()) { in CheckRemainderOperands()
10532 if (LHS.get()->getType()->hasIntegerRepresentation() && in CheckRemainderOperands()
10533 RHS.get()->getType()->hasIntegerRepresentation()) in CheckRemainderOperands()
10542 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckRemainderOperands()
10543 RHS.get()->getType()->isSveVLSBuiltinType()) { in CheckRemainderOperands()
10544 if (LHS.get()->getType()->hasIntegerRepresentation() && in CheckRemainderOperands()
10545 RHS.get()->getType()->hasIntegerRepresentation()) in CheckRemainderOperands()
10557 if (compType.isNull() || !compType->isIntegerType()) in CheckRemainderOperands()
10569 << 1 /* two pointers */ << LHSExpr->getSourceRange() in diagnoseArithmeticOnTwoVoidPointers()
10570 << RHSExpr->getSourceRange(); in diagnoseArithmeticOnTwoVoidPointers()
10579 << 0 /* one pointer */ << Pointer->getSourceRange(); in diagnoseArithmeticOnVoidPointer()
10591 << Pointer->getSourceRange(); in diagnoseArithmeticOnNullPointer()
10594 << S.getLangOpts().CPlusPlus << Pointer->getSourceRange(); in diagnoseArithmeticOnNullPointer()
10601 // Null - null is valid in C++ [expr.add]p7 in diagnoseSubtractionOnNullPointer()
10612 << Pointer->getSourceRange()); in diagnoseSubtractionOnNullPointer()
10618 assert(LHS->getType()->isAnyPointerType()); in diagnoseArithmeticOnTwoFunctionPointers()
10619 assert(RHS->getType()->isAnyPointerType()); in diagnoseArithmeticOnTwoFunctionPointers()
10623 << 1 /* two pointers */ << LHS->getType()->getPointeeType() in diagnoseArithmeticOnTwoFunctionPointers()
10625 << (unsigned)!S.Context.hasSameUnqualifiedType(LHS->getType(), in diagnoseArithmeticOnTwoFunctionPointers()
10626 RHS->getType()) in diagnoseArithmeticOnTwoFunctionPointers()
10627 << RHS->getType()->getPointeeType() in diagnoseArithmeticOnTwoFunctionPointers()
10628 << LHS->getSourceRange() << RHS->getSourceRange(); in diagnoseArithmeticOnTwoFunctionPointers()
10634 assert(Pointer->getType()->isAnyPointerType()); in diagnoseArithmeticOnFunctionPointer()
10638 << 0 /* one pointer */ << Pointer->getType()->getPointeeType() in diagnoseArithmeticOnFunctionPointer()
10640 << Pointer->getSourceRange(); in diagnoseArithmeticOnFunctionPointer()
10648 QualType ResType = Operand->getType(); in checkArithmeticIncompletePointerType()
10649 if (const AtomicType *ResAtomicType = ResType->getAs<AtomicType>()) in checkArithmeticIncompletePointerType()
10650 ResType = ResAtomicType->getValueType(); in checkArithmeticIncompletePointerType()
10652 assert(ResType->isAnyPointerType()); in checkArithmeticIncompletePointerType()
10653 QualType PointeeTy = ResType->getPointeeType(); in checkArithmeticIncompletePointerType()
10657 Operand->getSourceRange()); in checkArithmeticIncompletePointerType()
10670 QualType ResType = Operand->getType(); in checkArithmeticOpPointerOperand()
10671 if (const AtomicType *ResAtomicType = ResType->getAs<AtomicType>()) in checkArithmeticOpPointerOperand()
10672 ResType = ResAtomicType->getValueType(); in checkArithmeticOpPointerOperand()
10674 if (!ResType->isAnyPointerType()) return true; in checkArithmeticOpPointerOperand()
10676 QualType PointeeTy = ResType->getPointeeType(); in checkArithmeticOpPointerOperand()
10677 if (PointeeTy->isVoidType()) { in checkArithmeticOpPointerOperand()
10681 if (PointeeTy->isFunctionType()) { in checkArithmeticOpPointerOperand()
10702 bool isLHSPointer = LHSExpr->getType()->isAnyPointerType(); in checkArithmeticBinOpPointerOperands()
10703 bool isRHSPointer = RHSExpr->getType()->isAnyPointerType(); in checkArithmeticBinOpPointerOperands()
10707 if (isLHSPointer) LHSPointeeTy = LHSExpr->getType()->getPointeeType(); in checkArithmeticBinOpPointerOperands()
10708 if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType(); in checkArithmeticBinOpPointerOperands()
10715 << LHSExpr->getType() << RHSExpr->getType() << 1 /*arithmetic op*/ in checkArithmeticBinOpPointerOperands()
10716 << LHSExpr->getSourceRange() << RHSExpr->getSourceRange(); in checkArithmeticBinOpPointerOperands()
10722 bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->isVoidType(); in checkArithmeticBinOpPointerOperands()
10723 bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->isVoidType(); in checkArithmeticBinOpPointerOperands()
10732 bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->isFunctionType(); in checkArithmeticBinOpPointerOperands()
10733 bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->isFunctionType(); in checkArithmeticBinOpPointerOperands()
10751 /// diagnoseStringPlusInt - Emit a warning when adding an integer to a string
10755 StringLiteral* StrExpr = dyn_cast<StringLiteral>(LHSExpr->IgnoreImpCasts()); in diagnoseStringPlusInt()
10758 StrExpr = dyn_cast<StringLiteral>(RHSExpr->IgnoreImpCasts()); in diagnoseStringPlusInt()
10763 IndexExpr->getType()->isIntegralOrUnscopedEnumerationType(); in diagnoseStringPlusInt()
10764 if (!IsStringPlusInt || IndexExpr->isValueDependent()) in diagnoseStringPlusInt()
10767 SourceRange DiagRange(LHSExpr->getBeginLoc(), RHSExpr->getEndLoc()); in diagnoseStringPlusInt()
10769 << DiagRange << IndexExpr->IgnoreImpCasts()->getType(); in diagnoseStringPlusInt()
10773 SourceLocation EndLoc = Self.getLocForEndOfToken(RHSExpr->getEndLoc()); in diagnoseStringPlusInt()
10775 << FixItHint::CreateInsertion(LHSExpr->getBeginLoc(), "&") in diagnoseStringPlusInt()
10787 dyn_cast<CharacterLiteral>(RHSExpr->IgnoreImpCasts()); in diagnoseStringPlusChar()
10790 CharExpr = dyn_cast<CharacterLiteral>(LHSExpr->IgnoreImpCasts()); in diagnoseStringPlusChar()
10797 const QualType StringType = StringRefExpr->getType(); in diagnoseStringPlusChar()
10800 if (!StringType->isAnyPointerType()) in diagnoseStringPlusChar()
10804 if (!StringType->getPointeeType()->isAnyCharacterType()) in diagnoseStringPlusChar()
10808 SourceRange DiagRange(LHSExpr->getBeginLoc(), RHSExpr->getEndLoc()); in diagnoseStringPlusChar()
10810 const QualType CharType = CharExpr->getType(); in diagnoseStringPlusChar()
10811 if (!CharType->isAnyCharacterType() && in diagnoseStringPlusChar()
10812 CharType->isIntegerType() && in diagnoseStringPlusChar()
10813 llvm::isUIntN(Ctx.getCharWidth(), CharExpr->getValue())) { in diagnoseStringPlusChar()
10818 << DiagRange << CharExpr->getType(); in diagnoseStringPlusChar()
10822 if (isa<CharacterLiteral>(RHSExpr->IgnoreImpCasts())) { in diagnoseStringPlusChar()
10823 SourceLocation EndLoc = Self.getLocForEndOfToken(RHSExpr->getEndLoc()); in diagnoseStringPlusChar()
10825 << FixItHint::CreateInsertion(LHSExpr->getBeginLoc(), "&") in diagnoseStringPlusChar()
10836 assert(LHSExpr->getType()->isAnyPointerType()); in diagnosePointerIncompatibility()
10837 assert(RHSExpr->getType()->isAnyPointerType()); in diagnosePointerIncompatibility()
10839 << LHSExpr->getType() << RHSExpr->getType() << LHSExpr->getSourceRange() in diagnosePointerIncompatibility()
10840 << RHSExpr->getSourceRange(); in diagnosePointerIncompatibility()
10849 if (LHS.get()->getType()->isVectorType() || in CheckAdditionOperands()
10850 RHS.get()->getType()->isVectorType()) { in CheckAdditionOperands()
10861 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckAdditionOperands()
10862 RHS.get()->getType()->isSveVLSBuiltinType()) { in CheckAdditionOperands()
10870 if (LHS.get()->getType()->isConstantMatrixType() || in CheckAdditionOperands()
10871 RHS.get()->getType()->isConstantMatrixType()) { in CheckAdditionOperands()
10891 if (!compType.isNull() && compType->isArithmeticType()) { in CheckAdditionOperands()
10896 // Type-checking. Ultimately the pointer's going to be in PExp; in CheckAdditionOperands()
10901 if (PExp->getType()->isPointerType()) { in CheckAdditionOperands()
10903 } else if (PExp->getType()->isObjCObjectPointerType()) { in CheckAdditionOperands()
10907 if (PExp->getType()->isPointerType()) { in CheckAdditionOperands()
10909 } else if (PExp->getType()->isObjCObjectPointerType()) { in CheckAdditionOperands()
10915 assert(PExp->getType()->isAnyPointerType()); in CheckAdditionOperands()
10917 if (!IExp->getType()->isIntegerType()) in CheckAdditionOperands()
10921 if (PExp->IgnoreParenCasts()->isNullPointerConstant( in CheckAdditionOperands()
10926 (!IExp->isValueDependent() && in CheckAdditionOperands()
10927 (!IExp->EvaluateAsInt(KnownVal, Context) || in CheckAdditionOperands()
10956 LHSTy = LHS.get()->getType(); in CheckAdditionOperands()
10963 return PExp->getType(); in CheckAdditionOperands()
10972 if (LHS.get()->getType()->isVectorType() || in CheckSubtractionOperands()
10973 RHS.get()->getType()->isVectorType()) { in CheckSubtractionOperands()
10984 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckSubtractionOperands()
10985 RHS.get()->getType()->isSveVLSBuiltinType()) { in CheckSubtractionOperands()
10993 if (LHS.get()->getType()->isConstantMatrixType() || in CheckSubtractionOperands()
10994 RHS.get()->getType()->isConstantMatrixType()) { in CheckSubtractionOperands()
11010 if (!compType.isNull() && compType->isArithmeticType()) { in CheckSubtractionOperands()
11015 // Either ptr - int or ptr - ptr. in CheckSubtractionOperands()
11016 if (LHS.get()->getType()->isAnyPointerType()) { in CheckSubtractionOperands()
11017 QualType lpointee = LHS.get()->getType()->getPointeeType(); in CheckSubtractionOperands()
11020 if (LHS.get()->getType()->isObjCObjectPointerType() && in CheckSubtractionOperands()
11033 // The result type of a pointer-int computation is the pointer type. in CheckSubtractionOperands()
11034 if (RHS.get()->getType()->isIntegerType()) { in CheckSubtractionOperands()
11037 // GNU int-to-pointer idiom. in CheckSubtractionOperands()
11038 if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(Context, in CheckSubtractionOperands()
11043 (!RHS.get()->isValueDependent() && in CheckSubtractionOperands()
11044 (!RHS.get()->EvaluateAsInt(KnownVal, Context) || in CheckSubtractionOperands()
11057 if (CompLHSTy) *CompLHSTy = LHS.get()->getType(); in CheckSubtractionOperands()
11058 return LHS.get()->getType(); in CheckSubtractionOperands()
11061 // Handle pointer-pointer subtractions. in CheckSubtractionOperands()
11063 = RHS.get()->getType()->getAs<PointerType>()) { in CheckSubtractionOperands()
11064 QualType rpointee = RHSPTy->getPointeeType(); in CheckSubtractionOperands()
11085 bool LHSIsNullPtr = LHS.get()->IgnoreParenCasts()->isNullPointerConstant( in CheckSubtractionOperands()
11087 bool RHSIsNullPtr = RHS.get()->IgnoreParenCasts()->isNullPointerConstant( in CheckSubtractionOperands()
11099 if (!rpointee->isVoidType() && !rpointee->isFunctionType()) { in CheckSubtractionOperands()
11104 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in CheckSubtractionOperands()
11108 if (CompLHSTy) *CompLHSTy = LHS.get()->getType(); in CheckSubtractionOperands()
11117 if (const EnumType *ET = T->getAs<EnumType>()) in isScopedEnumerationType()
11118 return ET->getDecl()->isScoped(); in isScopedEnumerationType()
11132 if (RHS.get()->isValueDependent() || in DiagnoseBadShiftValues()
11133 !RHS.get()->EvaluateAsInt(RHSResult, S.Context)) in DiagnoseBadShiftValues()
11140 << RHS.get()->getSourceRange()); in DiagnoseBadShiftValues()
11144 QualType LHSExprType = LHS.get()->getType(); in DiagnoseBadShiftValues()
11146 if (LHSExprType->isBitIntType()) in DiagnoseBadShiftValues()
11148 else if (LHSExprType->isFixedPointType()) { in DiagnoseBadShiftValues()
11150 LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding(); in DiagnoseBadShiftValues()
11155 << RHS.get()->getSourceRange()); in DiagnoseBadShiftValues()
11160 if (Opc != BO_Shl || LHSExprType->isFixedPointType()) in DiagnoseBadShiftValues()
11164 // according to C++ standards prior to C++2a has undefined behavior in DiagnoseBadShiftValues()
11165 // ([expr.shift] 5.8/2). Unsigned integers have defined behavior modulo one in DiagnoseBadShiftValues()
11167 // warn for those. (FIXME: Unsigned left-shift overflow in a constant in DiagnoseBadShiftValues()
11170 if (LHS.get()->isValueDependent() || in DiagnoseBadShiftValues()
11171 LHSType->hasUnsignedIntegerRepresentation() || in DiagnoseBadShiftValues()
11172 !LHS.get()->EvaluateAsInt(LHSResult, S.Context)) in DiagnoseBadShiftValues()
11183 // If LHS does not have a non-negative value then, the in DiagnoseBadShiftValues()
11184 // behavior is undefined before C++2a. Warn about it. in DiagnoseBadShiftValues()
11188 << LHS.get()->getSourceRange()); in DiagnoseBadShiftValues()
11205 // bugs -- if the result is cast back to an unsigned type, it will have the in DiagnoseBadShiftValues()
11208 if (ResultBits - 1 == LeftSize) { in DiagnoseBadShiftValues()
11211 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in DiagnoseBadShiftValues()
11217 << Left.getBitWidth() << LHS.get()->getSourceRange() in DiagnoseBadShiftValues()
11218 << RHS.get()->getSourceRange(); in DiagnoseBadShiftValues()
11227 !LHS.get()->getType()->isVectorType()) { in checkVectorShift()
11229 << RHS.get()->getType() << LHS.get()->getType() in checkVectorShift()
11230 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in checkVectorShift()
11242 QualType LHSType = LHS.get()->getType(); in checkVectorShift()
11245 const VectorType *LHSVecTy = LHSType->getAs<VectorType>(); in checkVectorShift()
11246 QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType; in checkVectorShift()
11249 QualType RHSType = RHS.get()->getType(); in checkVectorShift()
11250 const VectorType *RHSVecTy = RHSType->getAs<VectorType>(); in checkVectorShift()
11251 QualType RHSEleType = RHSVecTy ? RHSVecTy->getElementType() : RHSType; in checkVectorShift()
11254 if ((LHSVecTy && LHSVecTy->isExtVectorBoolType()) || in checkVectorShift()
11255 (RHSVecTy && RHSVecTy->isExtVectorBoolType())) { in checkVectorShift()
11257 << LHS.get()->getType() << RHS.get()->getType() in checkVectorShift()
11258 << LHS.get()->getSourceRange(); in checkVectorShift()
11263 if (!LHSEleType->isIntegerType()) { in checkVectorShift()
11265 << LHS.get()->getType() << LHS.get()->getSourceRange(); in checkVectorShift()
11269 if (!RHSEleType->isIntegerType()) { in checkVectorShift()
11271 << RHS.get()->getType() << RHS.get()->getSourceRange(); in checkVectorShift()
11284 S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements()); in checkVectorShift()
11289 // are applied component-wise. So if RHS is a vector, then ensure in checkVectorShift()
11291 if (RHSVecTy->getNumElements() != LHSVecTy->getNumElements()) { in checkVectorShift()
11293 << LHS.get()->getType() << RHS.get()->getType() in checkVectorShift()
11294 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in checkVectorShift()
11298 const BuiltinType *LHSBT = LHSEleType->getAs<clang::BuiltinType>(); in checkVectorShift()
11299 const BuiltinType *RHSBT = RHSEleType->getAs<clang::BuiltinType>(); in checkVectorShift()
11303 << LHS.get()->getType() << RHS.get()->getType() in checkVectorShift()
11304 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in checkVectorShift()
11310 S.Context.getExtVectorType(RHSEleType, LHSVecTy->getNumElements()); in checkVectorShift()
11330 QualType LHSType = LHS.get()->getType(); in checkSizelessVectorShift()
11331 const BuiltinType *LHSBuiltinTy = LHSType->castAs<BuiltinType>(); in checkSizelessVectorShift()
11332 QualType LHSEleType = LHSType->isSveVLSBuiltinType() in checkSizelessVectorShift()
11333 ? LHSBuiltinTy->getSveEltType(S.getASTContext()) in checkSizelessVectorShift()
11337 QualType RHSType = RHS.get()->getType(); in checkSizelessVectorShift()
11338 const BuiltinType *RHSBuiltinTy = RHSType->castAs<BuiltinType>(); in checkSizelessVectorShift()
11339 QualType RHSEleType = RHSType->isSveVLSBuiltinType() in checkSizelessVectorShift()
11340 ? RHSBuiltinTy->getSveEltType(S.getASTContext()) in checkSizelessVectorShift()
11343 if ((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) || in checkSizelessVectorShift()
11344 (RHSBuiltinTy && RHSBuiltinTy->isSVEBool())) { in checkSizelessVectorShift()
11346 << LHSType << RHSType << LHS.get()->getSourceRange(); in checkSizelessVectorShift()
11350 if (!LHSEleType->isIntegerType()) { in checkSizelessVectorShift()
11352 << LHS.get()->getType() << LHS.get()->getSourceRange(); in checkSizelessVectorShift()
11356 if (!RHSEleType->isIntegerType()) { in checkSizelessVectorShift()
11358 << RHS.get()->getType() << RHS.get()->getSourceRange(); in checkSizelessVectorShift()
11362 if (LHSType->isSveVLSBuiltinType() && RHSType->isSveVLSBuiltinType() && in checkSizelessVectorShift()
11366 << LHSType << RHSType << LHS.get()->getSourceRange() in checkSizelessVectorShift()
11367 << RHS.get()->getSourceRange(); in checkSizelessVectorShift()
11371 if (!LHSType->isSveVLSBuiltinType()) { in checkSizelessVectorShift()
11372 assert(RHSType->isSveVLSBuiltinType()); in checkSizelessVectorShift()
11385 } else if (RHSBuiltinTy && RHSBuiltinTy->isSveVLSBuiltinType()) { in checkSizelessVectorShift()
11389 << LHSType << RHSType << LHS.get()->getSourceRange() in checkSizelessVectorShift()
11390 << RHS.get()->getSourceRange(); in checkSizelessVectorShift()
11415 if (LHS.get()->getType()->isVectorType() || in CheckShiftOperands()
11416 RHS.get()->getType()->isVectorType()) { in CheckShiftOperands()
11421 if (auto LHSVecType = LHS.get()->getType()->getAs<VectorType>()) in CheckShiftOperands()
11422 if (LHSVecType->getVectorKind() == VectorKind::AltiVecBool) in CheckShiftOperands()
11424 if (auto RHSVecType = RHS.get()->getType()->getAs<VectorType>()) in CheckShiftOperands()
11425 if (RHSVecType->getVectorKind() == VectorKind::AltiVecBool) in CheckShiftOperands()
11431 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckShiftOperands()
11432 RHS.get()->getType()->isSveVLSBuiltinType()) in CheckShiftOperands()
11444 QualType LHSType = LHS.get()->getType(); in CheckShiftOperands()
11451 QualType RHSType = RHS.get()->getType(); in CheckShiftOperands()
11454 // Embedded-C 4.1.6.2.2: The LHS may also be fixed-point. in CheckShiftOperands()
11455 if ((!LHSType->isFixedPointOrIntegerType() && in CheckShiftOperands()
11456 !LHSType->hasIntegerRepresentation()) || in CheckShiftOperands()
11457 !RHSType->hasIntegerRepresentation()) in CheckShiftOperands()
11478 << LHS.get()->getType() << RHS.get()->getType() in diagnoseDistinctPointerComparison()
11479 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in diagnoseDistinctPointerComparison()
11495 QualType LHSType = LHS.get()->getType(); in convertPointersToCompositeType()
11496 QualType RHSType = RHS.get()->getType(); in convertPointersToCompositeType()
11497 assert(LHSType->isPointerType() || RHSType->isPointerType() || in convertPointersToCompositeType()
11498 LHSType->isMemberPointerType() || RHSType->isMemberPointerType()); in convertPointersToCompositeType()
11502 if ((LHSType->isAnyPointerType() || LHSType->isMemberPointerType()) && in convertPointersToCompositeType()
11503 (RHSType->isAnyPointerType() || RHSType->isMemberPointerType())) in convertPointersToCompositeType()
11519 << LHS.get()->getType() << RHS.get()->getType() in diagnoseFunctionPointerToVoidComparison()
11520 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in diagnoseFunctionPointerToVoidComparison()
11524 switch (E.get()->IgnoreParenImpCasts()->getStmtClass()) { in isObjCObjectLiteral()
11538 LHS->getType()->getAs<ObjCObjectPointerType>(); in hasIsEqualMethod()
11540 // If this is not actually an Objective-C object, bail out. in hasIsEqualMethod()
11545 QualType InterfaceType = Type->getPointeeType(); in hasIsEqualMethod()
11547 // If the RHS isn't an Objective-C object, bail out. in hasIsEqualMethod()
11548 if (!RHS->getType()->isObjCObjectPointerType()) in hasIsEqualMethod()
11551 // Try to find the -isEqual: method. in hasIsEqualMethod()
11552 Selector IsEqualSel = S.ObjC().NSAPIObj->getIsEqualSelector(); in hasIsEqualMethod()
11557 if (Type->isObjCIdType()) { in hasIsEqualMethod()
11572 QualType T = Method->parameters()[0]->getType(); in hasIsEqualMethod()
11573 if (!T->isObjCObjectPointerType()) in hasIsEqualMethod()
11576 QualType R = Method->getReturnType(); in hasIsEqualMethod()
11577 if (!R->isScalarType()) in hasIsEqualMethod()
11597 Other = Other->IgnoreParenCasts(); in diagnoseObjCLiteralComparison()
11598 if (Other->isNullPointerConstant(S.getASTContext(), in diagnoseObjCLiteralComparison()
11608 llvm_unreachable("Unknown Objective-C object literal kind"); in diagnoseObjCLiteralComparison()
11613 << Literal->getSourceRange(); in diagnoseObjCLiteralComparison()
11616 << LiteralKind << Literal->getSourceRange(); in diagnoseObjCLiteralComparison()
11620 SourceLocation Start = LHS.get()->getBeginLoc(); in diagnoseObjCLiteralComparison()
11621 SourceLocation End = S.getLocForEndOfToken(RHS.get()->getEndLoc()); in diagnoseObjCLiteralComparison()
11637 UnaryOperator *UO = dyn_cast<UnaryOperator>(LHS.get()->IgnoreImpCasts()); in diagnoseLogicalNotOnLHSofCheck()
11638 if (!UO || UO->getOpcode() != UO_LNot) return; in diagnoseLogicalNotOnLHSofCheck()
11640 // Only check if the right hand side is non-bool arithmetic type. in diagnoseLogicalNotOnLHSofCheck()
11641 if (RHS.get()->isKnownToHaveBooleanValue()) return; in diagnoseLogicalNotOnLHSofCheck()
11644 Expr *SubExpr = UO->getSubExpr()->IgnoreImpCasts(); in diagnoseLogicalNotOnLHSofCheck()
11645 if (SubExpr->isKnownToHaveBooleanValue()) return; in diagnoseLogicalNotOnLHSofCheck()
11649 S.Diag(UO->getOperatorLoc(), diag::warn_logical_not_on_lhs_of_check) in diagnoseLogicalNotOnLHSofCheck()
11653 SourceLocation FirstOpen = SubExpr->getBeginLoc(); in diagnoseLogicalNotOnLHSofCheck()
11654 SourceLocation FirstClose = RHS.get()->getEndLoc(); in diagnoseLogicalNotOnLHSofCheck()
11658 S.Diag(UO->getOperatorLoc(), diag::note_logical_not_fix) in diagnoseLogicalNotOnLHSofCheck()
11664 SourceLocation SecondOpen = LHS.get()->getBeginLoc(); in diagnoseLogicalNotOnLHSofCheck()
11665 SourceLocation SecondClose = LHS.get()->getEndLoc(); in diagnoseLogicalNotOnLHSofCheck()
11669 S.Diag(UO->getOperatorLoc(), diag::note_logical_not_silence_with_parens) in diagnoseLogicalNotOnLHSofCheck()
11674 // Returns true if E refers to a non-weak array.
11678 D = DR->getDecl(); in checkForArray()
11680 if (Mem->isImplicitAccess()) in checkForArray()
11681 D = Mem->getMemberDecl(); in checkForArray()
11685 return D->getType()->isArrayType() && !D->isWeak(); in checkForArray()
11688 /// Diagnose some forms of syntactically-obvious tautological comparison.
11692 Expr *LHSStripped = LHS->IgnoreParenImpCasts(); in diagnoseTautologicalComparison()
11693 Expr *RHSStripped = RHS->IgnoreParenImpCasts(); in diagnoseTautologicalComparison()
11695 QualType LHSType = LHS->getType(); in diagnoseTautologicalComparison()
11696 QualType RHSType = RHS->getType(); in diagnoseTautologicalComparison()
11697 if (LHSType->hasFloatingRepresentation() || in diagnoseTautologicalComparison()
11698 (LHSType->isBlockPointerType() && !BinaryOperator::isEqualityOp(Opc)) || in diagnoseTautologicalComparison()
11704 if (LHSType->isWebAssemblyTableType() || RHSType->isWebAssemblyTableType()) in diagnoseTautologicalComparison()
11707 // Comparisons between two array types are ill-formed for operator<=>, so in diagnoseTautologicalComparison()
11709 if (Opc == BO_Cmp && LHSType->isArrayType() && RHSType->isArrayType()) in diagnoseTautologicalComparison()
11712 // For non-floating point types, check for self-comparisons of the form in diagnoseTautologicalComparison()
11731 // C++2a [depr.array.comp]: in diagnoseTautologicalComparison()
11734 if (S.getLangOpts().CPlusPlus20 && LHSStripped->getType()->isArrayType() && in diagnoseTautologicalComparison()
11735 RHSStripped->getType()->isArrayType()) { in diagnoseTautologicalComparison()
11737 << LHS->getSourceRange() << RHS->getSourceRange() in diagnoseTautologicalComparison()
11738 << LHSStripped->getType() << RHSStripped->getType(); in diagnoseTautologicalComparison()
11740 // expression is potentially-evaluated, we can resolve the array to a in diagnoseTautologicalComparison()
11741 // non-weak declaration, and so on. in diagnoseTautologicalComparison()
11744 if (!LHS->getBeginLoc().isMacroID() && !RHS->getBeginLoc().isMacroID()) { in diagnoseTautologicalComparison()
11767 << 0 /*self-comparison*/ in diagnoseTautologicalComparison()
11792 LHSStripped = LHSStripped->IgnoreParenCasts(); in diagnoseTautologicalComparison()
11794 RHSStripped = RHSStripped->IgnoreParenCasts(); in diagnoseTautologicalComparison()
11801 !RHSStripped->isNullPointerConstant(S.Context, in diagnoseTautologicalComparison()
11807 !LHSStripped->isNullPointerConstant(S.Context, in diagnoseTautologicalComparison()
11817 << LiteralString->getSourceRange()); in diagnoseTautologicalComparison()
11869 SCS.Second = castKindToImplicitConversionKind(ICE->getCastKind()); in checkThreeWayNarrowingConversion()
11878 // value-dependent so we can't tell whether it's actually narrowing. in checkThreeWayNarrowingConversion()
11885 S.Diag(E->getBeginLoc(), diag::err_spaceship_argument_narrowing) in checkThreeWayNarrowingConversion()
11894 S.Diag(E->getBeginLoc(), diag::err_spaceship_argument_narrowing) in checkThreeWayNarrowingConversion()
11907 QualType LHSType = LHS.get()->getType(); in checkArithmeticOrEnumeralThreeWayCompare()
11908 QualType RHSType = RHS.get()->getType(); in checkArithmeticOrEnumeralThreeWayCompare()
11912 ExprResult LHSStripped = LHS.get()->IgnoreParenImpCasts(); in checkArithmeticOrEnumeralThreeWayCompare()
11913 ExprResult RHSStripped = RHS.get()->IgnoreParenImpCasts(); in checkArithmeticOrEnumeralThreeWayCompare()
11914 QualType LHSStrippedType = LHSStripped.get()->getType(); in checkArithmeticOrEnumeralThreeWayCompare()
11915 QualType RHSStrippedType = RHSStripped.get()->getType(); in checkArithmeticOrEnumeralThreeWayCompare()
11917 // C++2a [expr.spaceship]p3: If one of the operands is of type bool and the in checkArithmeticOrEnumeralThreeWayCompare()
11918 // other is not, the program is ill-formed. in checkArithmeticOrEnumeralThreeWayCompare()
11919 if (LHSStrippedType->isBooleanType() != RHSStrippedType->isBooleanType()) { in checkArithmeticOrEnumeralThreeWayCompare()
11925 int NumEnumArgs = (int)LHSStrippedType->isEnumeralType() + in checkArithmeticOrEnumeralThreeWayCompare()
11926 RHSStrippedType->isEnumeralType(); in checkArithmeticOrEnumeralThreeWayCompare()
11928 bool LHSIsEnum = LHSStrippedType->isEnumeralType(); in checkArithmeticOrEnumeralThreeWayCompare()
11930 if (OtherTy->hasFloatingRepresentation()) { in checkArithmeticOrEnumeralThreeWayCompare()
11935 if (NumEnumArgs == 2) { in checkArithmeticOrEnumeralThreeWayCompare()
11936 // C++2a [expr.spaceship]p5: If both operands have the same enumeration in checkArithmeticOrEnumeralThreeWayCompare()
11944 LHSStrippedType->castAs<EnumType>()->getDecl()->getIntegerType(); in checkArithmeticOrEnumeralThreeWayCompare()
11945 assert(IntType->isArithmeticType()); in checkArithmeticOrEnumeralThreeWayCompare()
11958 // C++2a [expr.spaceship]p4: If both operands have arithmetic types, the in checkArithmeticOrEnumeralThreeWayCompare()
11973 S, Type, LHS.get(), LHSType, LHS.get()->getBeginLoc()); in checkArithmeticOrEnumeralThreeWayCompare()
11975 RHS.get()->getBeginLoc()); in checkArithmeticOrEnumeralThreeWayCompare()
11999 assert(Type->isArithmeticType() || Type->isEnumeralType()); in checkArithmeticOrEnumeralCompare()
12001 if (Type->isAnyComplexType() && BinaryOperator::isRelationalOp(Opc)) in checkArithmeticOrEnumeralCompare()
12005 if (Type->hasFloatingRepresentation()) in checkArithmeticOrEnumeralCompare()
12013 if (!NullE.get()->getType()->isAnyPointerType()) in CheckPtrComparisonWithNullChar()
12016 if (!E.get()->getType()->isAnyPointerType() && in CheckPtrComparisonWithNullChar()
12017 E.get()->isNullPointerConstant(Context, in CheckPtrComparisonWithNullChar()
12021 if (CL->getValue() == 0) in CheckPtrComparisonWithNullChar()
12022 Diag(E.get()->getExprLoc(), diag::warn_pointer_compare) in CheckPtrComparisonWithNullChar()
12024 << FixItHint::CreateReplacement(E.get()->getExprLoc(), in CheckPtrComparisonWithNullChar()
12027 TypeSourceInfo *TI = CE->getTypeInfoAsWritten(); in CheckPtrComparisonWithNullChar()
12028 QualType T = Context.getCanonicalType(TI->getType()).getUnqualifiedType(); in CheckPtrComparisonWithNullChar()
12030 Diag(E.get()->getExprLoc(), diag::warn_pointer_compare) in CheckPtrComparisonWithNullChar()
12032 << FixItHint::CreateReplacement(E.get()->getExprLoc(), in CheckPtrComparisonWithNullChar()
12046 QualType Ty = E.get()->getType(); in CheckCompareOperands()
12047 return Ty->isPointerType() || Ty->isMemberPointerType(); in CheckCompareOperands()
12050 // C++2a [expr.spaceship]p6: If at least one of the operands is of pointer in CheckCompareOperands()
12051 // type, array-to-pointer, ..., conversions are performed on both operands to in CheckCompareOperands()
12054 // any type-related checks. in CheckCompareOperands()
12078 if (LHS.get()->getType()->isVectorType() || in CheckCompareOperands()
12079 RHS.get()->getType()->isVectorType()) in CheckCompareOperands()
12082 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckCompareOperands()
12083 RHS.get()->getType()->isSveVLSBuiltinType()) in CheckCompareOperands()
12089 QualType LHSType = LHS.get()->getType(); in CheckCompareOperands()
12090 QualType RHSType = RHS.get()->getType(); in CheckCompareOperands()
12091 if ((LHSType->isArithmeticType() || LHSType->isEnumeralType()) && in CheckCompareOperands()
12092 (RHSType->isArithmeticType() || RHSType->isEnumeralType())) in CheckCompareOperands()
12095 if ((LHSType->isPointerType() && in CheckCompareOperands()
12096 LHSType->getPointeeType().isWebAssemblyReferenceType()) || in CheckCompareOperands()
12097 (RHSType->isPointerType() && in CheckCompareOperands()
12098 RHSType->getPointeeType().isWebAssemblyReferenceType())) in CheckCompareOperands()
12102 LHS.get()->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull); in CheckCompareOperands()
12104 RHS.get()->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull); in CheckCompareOperands()
12112 assert(Context.hasSameType(LHS.get()->getType(), RHS.get()->getType())); in CheckCompareOperands()
12114 QualType CompositeTy = LHS.get()->getType(); in CheckCompareOperands()
12115 assert(!CompositeTy->isReferenceType()); in CheckCompareOperands()
12122 if (CompositeTy->isPointerType() && LHSIsNull != RHSIsNull) { in CheckCompareOperands()
12124 // pointer result in std::strong_equality, which is ill-formed under in CheckCompareOperands()
12127 << (LHSIsNull ? LHS.get()->getSourceRange() in CheckCompareOperands()
12128 : RHS.get()->getSourceRange()); in CheckCompareOperands()
12140 RHS.get()->getSourceRange()); in CheckCompareOperands()
12143 LHS.get()->getSourceRange()); in CheckCompareOperands()
12146 if (IsOrdered && LHSType->isFunctionPointerType() && in CheckCompareOperands()
12147 RHSType->isFunctionPointerType()) { in CheckCompareOperands()
12155 Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange() in CheckCompareOperands()
12156 << RHS.get()->getSourceRange(); in CheckCompareOperands()
12161 if ((LHSType->isIntegerType() && !LHSIsNull) || in CheckCompareOperands()
12162 (RHSType->isIntegerType() && !RHSIsNull)) { in CheckCompareOperands()
12171 ((LHSType->isFunctionPointerType() && RHSType->isVoidPointerType()) || in CheckCompareOperands()
12172 (RHSType->isFunctionPointerType() && LHSType->isVoidPointerType()))) { in CheckCompareOperands()
12195 // For <=>, the only valid non-pointer types are arrays and functions, and in CheckCompareOperands()
12198 if ((int)LHSType->isPointerType() + (int)RHSType->isPointerType() >= in CheckCompareOperands()
12199 (IsOrdered ? 2 : 1) && in CheckCompareOperands()
12200 (!LangOpts.ObjCAutoRefCount || !(LHSType->isObjCObjectPointerType() || in CheckCompareOperands()
12201 RHSType->isObjCObjectPointerType()))) { in CheckCompareOperands()
12206 } else if (LHSType->isPointerType() && in CheckCompareOperands()
12207 RHSType->isPointerType()) { // C99 6.5.8p2 in CheckCompareOperands()
12208 // All of the following pointer-related warnings are GCC extensions, except in CheckCompareOperands()
12211 LHSType->castAs<PointerType>()->getPointeeType().getCanonicalType(); in CheckCompareOperands()
12213 RHSType->castAs<PointerType>()->getPointeeType().getCanonicalType(); in CheckCompareOperands()
12220 if ((LCanPointeeTy->isIncompleteType() != in CheckCompareOperands()
12221 RCanPointeeTy->isIncompleteType()) && in CheckCompareOperands()
12224 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange() in CheckCompareOperands()
12225 << LHSType << RHSType << LCanPointeeTy->isIncompleteType() in CheckCompareOperands()
12226 << RCanPointeeTy->isIncompleteType(); in CheckCompareOperands()
12230 (LCanPointeeTy->isVoidType() || RCanPointeeTy->isVoidType())) { in CheckCompareOperands()
12231 // Valid unless comparison between non-null pointer and function pointer in CheckCompareOperands()
12232 if ((LCanPointeeTy->isFunctionType() || RCanPointeeTy->isFunctionType()) in CheckCompareOperands()
12247 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); in CheckCompareOperands()
12272 if (LHSType->isNullPtrType()) { in CheckCompareOperands()
12276 if (RHSType->isNullPtrType()) { in CheckCompareOperands()
12287 if (LHSIsNull && RHSType->isPointerType()) { in CheckCompareOperands()
12291 if (RHSIsNull && LHSType->isPointerType()) { in CheckCompareOperands()
12297 // Comparison of Objective-C pointers and block pointers against nullptr_t. in CheckCompareOperands()
12299 if (!IsOrdered && RHSType->isNullPtrType() && in CheckCompareOperands()
12300 (LHSType->isObjCObjectPointerType() || LHSType->isBlockPointerType())) { in CheckCompareOperands()
12304 if (!IsOrdered && LHSType->isNullPtrType() && in CheckCompareOperands()
12305 (RHSType->isObjCObjectPointerType() || RHSType->isBlockPointerType())) { in CheckCompareOperands()
12312 ((LHSType->isNullPtrType() && RHSType->isPointerType()) || in CheckCompareOperands()
12313 (RHSType->isNullPtrType() && LHSType->isPointerType()))) { in CheckCompareOperands()
12321 DC = DC->getParent(); in CheckCompareOperands()
12323 if (CTSD->isInStdNamespace() && in CheckCompareOperands()
12324 llvm::StringSwitch<bool>(CTSD->getName()) in CheckCompareOperands()
12327 if (RHSType->isNullPtrType()) in CheckCompareOperands()
12340 (LHSType->isMemberPointerType() || RHSType->isMemberPointerType())) { in CheckCompareOperands()
12349 if (!IsOrdered && LHSType->isBlockPointerType() && in CheckCompareOperands()
12350 RHSType->isBlockPointerType()) { in CheckCompareOperands()
12351 QualType lpointee = LHSType->castAs<BlockPointerType>()->getPointeeType(); in CheckCompareOperands()
12352 QualType rpointee = RHSType->castAs<BlockPointerType>()->getPointeeType(); in CheckCompareOperands()
12357 << LHSType << RHSType << LHS.get()->getSourceRange() in CheckCompareOperands()
12358 << RHS.get()->getSourceRange(); in CheckCompareOperands()
12366 && ((LHSType->isBlockPointerType() && RHSType->isPointerType()) in CheckCompareOperands()
12367 || (LHSType->isPointerType() && RHSType->isBlockPointerType()))) { in CheckCompareOperands()
12369 if (!((RHSType->isPointerType() && RHSType->castAs<PointerType>() in CheckCompareOperands()
12370 ->getPointeeType()->isVoidType()) in CheckCompareOperands()
12371 || (LHSType->isPointerType() && LHSType->castAs<PointerType>() in CheckCompareOperands()
12372 ->getPointeeType()->isVoidType()))) in CheckCompareOperands()
12374 << LHSType << RHSType << LHS.get()->getSourceRange() in CheckCompareOperands()
12375 << RHS.get()->getSourceRange(); in CheckCompareOperands()
12379 RHSType->isPointerType() ? CK_BitCast in CheckCompareOperands()
12383 LHSType->isPointerType() ? CK_BitCast in CheckCompareOperands()
12388 if (LHSType->isObjCObjectPointerType() || in CheckCompareOperands()
12389 RHSType->isObjCObjectPointerType()) { in CheckCompareOperands()
12390 const PointerType *LPT = LHSType->getAs<PointerType>(); in CheckCompareOperands()
12391 const PointerType *RPT = RHSType->getAs<PointerType>(); in CheckCompareOperands()
12393 bool LPtrToVoid = LPT ? LPT->getPointeeType()->isVoidType() : false; in CheckCompareOperands()
12394 bool RPtrToVoid = RPT ? RPT->getPointeeType()->isVoidType() : false; in CheckCompareOperands()
12424 if (LHSType->isObjCObjectPointerType() && in CheckCompareOperands()
12425 RHSType->isObjCObjectPointerType()) { in CheckCompareOperands()
12439 if (!IsOrdered && LHSType->isBlockPointerType() && in CheckCompareOperands()
12440 RHSType->isBlockCompatibleObjCPointerType(Context)) { in CheckCompareOperands()
12445 LHSType->isBlockCompatibleObjCPointerType(Context) && in CheckCompareOperands()
12446 RHSType->isBlockPointerType()) { in CheckCompareOperands()
12452 if ((LHSType->isAnyPointerType() && RHSType->isIntegerType()) || in CheckCompareOperands()
12453 (LHSType->isIntegerType() && RHSType->isAnyPointerType())) { in CheckCompareOperands()
12459 } else if ((LHSIsNull && LHSType->isIntegerType()) || in CheckCompareOperands()
12460 (RHSIsNull && RHSType->isIntegerType())) { in CheckCompareOperands()
12477 << LHSType << RHSType << LHS.get()->getSourceRange() in CheckCompareOperands()
12478 << RHS.get()->getSourceRange(); in CheckCompareOperands()
12483 if (LHSType->isIntegerType()) in CheckCompareOperands()
12494 && LHSType->isBlockPointerType() && RHSType->isIntegerType()) { in CheckCompareOperands()
12499 && LHSType->isIntegerType() && RHSType->isBlockPointerType()) { in CheckCompareOperands()
12505 if (LHSType->isClkEventT() && RHSType->isClkEventT()) { in CheckCompareOperands()
12509 if (LHSType->isQueueT() && RHSType->isQueueT()) { in CheckCompareOperands()
12513 if (LHSIsNull && RHSType->isQueueT()) { in CheckCompareOperands()
12518 if (LHSType->isQueueT() && RHSIsNull) { in CheckCompareOperands()
12528 const VectorType *VTy = V->castAs<VectorType>(); in GetSignedVectorType()
12529 unsigned TypeSize = Context.getTypeSize(VTy->getElementType()); in GetSignedVectorType()
12532 if (VTy->isExtVectorBoolType()) in GetSignedVectorType()
12533 return Context.getExtVectorType(Context.BoolTy, VTy->getNumElements()); in GetSignedVectorType()
12535 return Context.getExtVectorType(Context.CharTy, VTy->getNumElements()); in GetSignedVectorType()
12537 return Context.getExtVectorType(Context.ShortTy, VTy->getNumElements()); in GetSignedVectorType()
12539 return Context.getExtVectorType(Context.IntTy, VTy->getNumElements()); in GetSignedVectorType()
12541 return Context.getExtVectorType(Context.Int128Ty, VTy->getNumElements()); in GetSignedVectorType()
12543 return Context.getExtVectorType(Context.LongTy, VTy->getNumElements()); in GetSignedVectorType()
12546 return Context.getExtVectorType(Context.LongLongTy, VTy->getNumElements()); in GetSignedVectorType()
12550 return Context.getVectorType(Context.Int128Ty, VTy->getNumElements(), in GetSignedVectorType()
12553 return Context.getVectorType(Context.LongLongTy, VTy->getNumElements(), in GetSignedVectorType()
12556 return Context.getVectorType(Context.LongTy, VTy->getNumElements(), in GetSignedVectorType()
12559 return Context.getVectorType(Context.IntTy, VTy->getNumElements(), in GetSignedVectorType()
12562 return Context.getVectorType(Context.ShortTy, VTy->getNumElements(), in GetSignedVectorType()
12566 return Context.getVectorType(Context.CharTy, VTy->getNumElements(), in GetSignedVectorType()
12571 const BuiltinType *VTy = V->castAs<BuiltinType>(); in GetSignedSizelessVectorType()
12572 assert(VTy->isSizelessBuiltinType() && "expected sizeless type"); in GetSignedSizelessVectorType()
12574 const QualType ETy = V->getSveEltType(Context); in GetSignedSizelessVectorType()
12601 QualType LHSType = LHS.get()->getType(); in CheckVectorCompareOperands()
12613 if (vType->castAs<VectorType>()->getVectorKind() == in CheckVectorCompareOperands()
12628 // For non-floating point types, check for self-comparisons of the form in CheckVectorCompareOperands()
12634 if (LHSType->hasFloatingRepresentation()) { in CheckVectorCompareOperands()
12635 assert(RHS.get()->getType()->hasFloatingRepresentation()); in CheckVectorCompareOperands()
12660 QualType LHSType = LHS.get()->getType(); in CheckSizelessVectorCompareOperands()
12662 // For non-floating point types, check for self-comparisons of the form in CheckSizelessVectorCompareOperands()
12668 if (LHSType->hasFloatingRepresentation()) { in CheckSizelessVectorCompareOperands()
12669 assert(RHS.get()->getType()->hasFloatingRepresentation()); in CheckSizelessVectorCompareOperands()
12673 const BuiltinType *LHSBuiltinTy = LHSType->getAs<BuiltinType>(); in CheckSizelessVectorCompareOperands()
12674 const BuiltinType *RHSBuiltinTy = RHS.get()->getType()->getAs<BuiltinType>(); in CheckSizelessVectorCompareOperands()
12676 if (LHSBuiltinTy && RHSBuiltinTy && LHSBuiltinTy->isSVEBool() && in CheckSizelessVectorCompareOperands()
12677 RHSBuiltinTy->isSVEBool()) in CheckSizelessVectorCompareOperands()
12692 if (XorLHS.get()->getExprLoc().isMacroID() && in diagnoseXorMisusedAsPow()
12693 XorRHS.get()->getExprLoc().isMacroID()) in diagnoseXorMisusedAsPow()
12706 UnaryOperatorKind Opc = UO->getOpcode(); in diagnoseXorMisusedAsPow()
12709 RHSInt = dyn_cast<IntegerLiteral>(UO->getSubExpr()); in diagnoseXorMisusedAsPow()
12719 const llvm::APInt &LeftSideValue = LHSInt->getValue(); in diagnoseXorMisusedAsPow()
12720 llvm::APInt RightSideValue = RHSInt->getValue(); in diagnoseXorMisusedAsPow()
12721 if (LeftSideValue != 2 && LeftSideValue != 10) in diagnoseXorMisusedAsPow()
12728 LHSInt->getBeginLoc(), S.getLocForEndOfToken(RHSInt->getLocation())); in diagnoseXorMisusedAsPow()
12741 CharSourceRange::getTokenRange(LHSInt->getSourceRange()), in diagnoseXorMisusedAsPow()
12744 CharSourceRange::getTokenRange(RHSInt->getSourceRange()), in diagnoseXorMisusedAsPow()
12748 RightSideValue = -RightSideValue; in diagnoseXorMisusedAsPow()
12749 RHSStr = "-" + RHSStr; in diagnoseXorMisusedAsPow()
12771 if (LeftSideValue == 2 && RightSideIntValue >= 0) { in diagnoseXorMisusedAsPow()
12774 llvm::APInt One = (LeftSideValue - 1); in diagnoseXorMisusedAsPow()
12819 vType->hasFloatingRepresentation()) in CheckVectorLogicalOperands()
12825 !(isa<ExtVectorType>(vType->getAs<VectorType>()))) in CheckVectorLogicalOperands()
12828 return GetSignedVectorType(LHS.get()->getType()); in CheckVectorLogicalOperands()
12845 QualType LHSType = LHS.get()->getType().getUnqualifiedType(); in CheckMatrixElementwiseOperands()
12846 QualType RHSType = RHS.get()->getType().getUnqualifiedType(); in CheckMatrixElementwiseOperands()
12848 const MatrixType *LHSMatType = LHSType->getAs<MatrixType>(); in CheckMatrixElementwiseOperands()
12849 const MatrixType *RHSMatType = RHSType->getAs<MatrixType>(); in CheckMatrixElementwiseOperands()
12860 RHS = tryConvertExprToType(RHS.get(), LHSMatType->getElementType()); in CheckMatrixElementwiseOperands()
12868 LHS = tryConvertExprToType(LHS.get(), RHSMatType->getElementType()); in CheckMatrixElementwiseOperands()
12889 auto *LHSMatType = LHS.get()->getType()->getAs<ConstantMatrixType>(); in CheckMatrixMultiplyOperands()
12890 auto *RHSMatType = RHS.get()->getType()->getAs<ConstantMatrixType>(); in CheckMatrixMultiplyOperands()
12894 if (LHSMatType->getNumColumns() != RHSMatType->getNumRows()) in CheckMatrixMultiplyOperands()
12899 LHS.get()->getType().getUnqualifiedType(), in CheckMatrixMultiplyOperands()
12900 RHS.get()->getType().getUnqualifiedType()); in CheckMatrixMultiplyOperands()
12902 QualType LHSELTy = LHSMatType->getElementType(), in CheckMatrixMultiplyOperands()
12903 RHSELTy = RHSMatType->getElementType(); in CheckMatrixMultiplyOperands()
12909 LHSMatType->getNumRows(), RHSMatType->getNumColumns()); in CheckMatrixMultiplyOperands()
12938 if (LHS.get()->getType()->isVectorType() || in CheckBitwiseOperands()
12939 RHS.get()->getType()->isVectorType()) { in CheckBitwiseOperands()
12940 if (LHS.get()->getType()->hasIntegerRepresentation() && in CheckBitwiseOperands()
12941 RHS.get()->getType()->hasIntegerRepresentation()) in CheckBitwiseOperands()
12950 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckBitwiseOperands()
12951 RHS.get()->getType()->isSveVLSBuiltinType()) { in CheckBitwiseOperands()
12952 if (LHS.get()->getType()->hasIntegerRepresentation() && in CheckBitwiseOperands()
12953 RHS.get()->getType()->hasIntegerRepresentation()) in CheckBitwiseOperands()
12959 if (LHS.get()->getType()->isSveVLSBuiltinType() || in CheckBitwiseOperands()
12960 RHS.get()->getType()->isSveVLSBuiltinType()) { in CheckBitwiseOperands()
12961 if (LHS.get()->getType()->hasIntegerRepresentation() && in CheckBitwiseOperands()
12962 RHS.get()->getType()->hasIntegerRepresentation()) in CheckBitwiseOperands()
12971 if (LHS.get()->getType()->hasFloatingRepresentation() || in CheckBitwiseOperands()
12972 RHS.get()->getType()->hasFloatingRepresentation()) in CheckBitwiseOperands()
12986 if (!compType.isNull() && compType->isIntegralOrUnscopedEnumerationType()) in CheckBitwiseOperands()
12996 if (LHS.get()->getType()->isVectorType() || in CheckLogicalOperands()
12997 RHS.get()->getType()->isVectorType()) in CheckLogicalOperands()
13003 const auto *ECDHS = dyn_cast<EnumConstantDecl>(DREHS->getDecl()); in CheckLogicalOperands()
13004 if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1) in CheckLogicalOperands()
13013 QualType LHSTy = LHS.get()->getType(); in CheckLogicalOperands()
13014 QualType RHSTy = RHS.get()->getType(); in CheckLogicalOperands()
13017 if ((LHSATy && LHSATy->getElementType().isWebAssemblyReferenceType()) || in CheckLogicalOperands()
13018 (RHSATy && RHSATy->getElementType().isWebAssemblyReferenceType())) { in CheckLogicalOperands()
13023 // bitwise one. We do this when the LHS is a non-bool integer and the RHS in CheckLogicalOperands()
13025 if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() && in CheckLogicalOperands()
13026 !LHS.get()->getType()->isBooleanType() && in CheckLogicalOperands()
13027 RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() && in CheckLogicalOperands()
13035 if (RHS.get()->EvaluateAsInt(EVResult, Context)) { in CheckLogicalOperands()
13037 if ((getLangOpts().CPlusPlus && !RHS.get()->getType()->isBooleanType() && in CheckLogicalOperands()
13038 !RHS.get()->getExprLoc().isMacroID()) || in CheckLogicalOperands()
13041 << RHS.get()->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||"); in CheckLogicalOperands()
13052 SourceRange(getLocForEndOfToken(LHS.get()->getEndLoc()), in CheckLogicalOperands()
13053 RHS.get()->getEndLoc())); in CheckLogicalOperands()
13060 // not operate on the built-in scalar and vector float types. in CheckLogicalOperands()
13063 if (LHS.get()->getType()->isFloatingType() || in CheckLogicalOperands()
13064 RHS.get()->getType()->isFloatingType()) in CheckLogicalOperands()
13076 if (!LHS.get()->getType()->isScalarType() || in CheckLogicalOperands()
13077 !RHS.get()->getType()->isScalarType()) in CheckLogicalOperands()
13084 // non-overloadable operands. in CheckLogicalOperands()
13108 if (!isa<FieldDecl>(ME->getMemberDecl())) return false; in IsReadonlyMessage()
13110 ME->getBase()->IgnoreImplicit()->IgnoreParenImpCasts()); in IsReadonlyMessage()
13112 return Base->getMethodDecl() != nullptr; in IsReadonlyMessage()
13116 /// variable which was originally non-const, but which has become
13120 assert(E->isLValue() && E->getType().isConstQualified()); in isReferenceToNonConstCapture()
13121 E = E->IgnoreParens(); in isReferenceToNonConstCapture()
13126 if (!DRE->refersToEnclosingVariableOrCapture()) return NCCK_None; in isReferenceToNonConstCapture()
13129 VarDecl *var = dyn_cast<VarDecl>(DRE->getDecl()); in isReferenceToNonConstCapture()
13131 if (var->getType().isConstQualified()) return NCCK_None; in isReferenceToNonConstCapture()
13132 assert(var->hasLocalStorage() && "capture added 'const' to non-local?"); in isReferenceToNonConstCapture()
13138 // For init-capture, it is possible that the variable belongs to the in isReferenceToNonConstCapture()
13141 if (var->isInitCapture() && in isReferenceToNonConstCapture()
13142 FD->getTemplateInstantiationPattern() == var->getDeclContext()) in isReferenceToNonConstCapture()
13144 if (DC == var->getDeclContext()) in isReferenceToNonConstCapture()
13147 DC = DC->getParent(); in isReferenceToNonConstCapture()
13149 // Unless we have an init-capture, we've gone one step too far. in isReferenceToNonConstCapture()
13150 if (!var->isInitCapture()) in isReferenceToNonConstCapture()
13157 if (IsDereference && Ty->isPointerType()) in IsTypeModifiable()
13158 Ty = Ty->getPointeeType(); in IsTypeModifiable()
13173 /// Emit the "read-only variable not assignable" error and print notes to give
13179 SourceRange ExprRange = E->getSourceRange(); in DiagnoseConstAssignment()
13194 E = E->IgnoreImplicit()->IgnoreParenImpCasts(); in DiagnoseConstAssignment()
13196 NextIsDereference = ME->isArrow(); in DiagnoseConstAssignment()
13197 const ValueDecl *VD = ME->getMemberDecl(); in DiagnoseConstAssignment()
13200 if (Field->isMutable()) { in DiagnoseConstAssignment()
13205 if (!IsTypeModifiable(Field->getType(), IsDereference)) { in DiagnoseConstAssignment()
13209 << Field->getType(); in DiagnoseConstAssignment()
13212 S.Diag(VD->getLocation(), diag::note_typecheck_assign_const) in DiagnoseConstAssignment()
13213 << ConstMember << false /*static*/ << Field << Field->getType() in DiagnoseConstAssignment()
13214 << Field->getSourceRange(); in DiagnoseConstAssignment()
13216 E = ME->getBase(); in DiagnoseConstAssignment()
13219 if (VDecl->getType().isConstQualified()) { in DiagnoseConstAssignment()
13223 << VDecl->getType(); in DiagnoseConstAssignment()
13226 S.Diag(VD->getLocation(), diag::note_typecheck_assign_const) in DiagnoseConstAssignment()
13227 << ConstMember << true /*static*/ << VDecl << VDecl->getType() in DiagnoseConstAssignment()
13228 << VDecl->getSourceRange(); in DiagnoseConstAssignment()
13236 E = ASE->getBase()->IgnoreParenImpCasts(); in DiagnoseConstAssignment()
13240 E = EVE->getBase()->IgnoreParenImpCasts(); in DiagnoseConstAssignment()
13248 const FunctionDecl *FD = CE->getDirectCallee(); in DiagnoseConstAssignment()
13249 if (FD && !IsTypeModifiable(FD->getReturnType(), IsDereference)) { in DiagnoseConstAssignment()
13255 S.Diag(FD->getReturnTypeSourceRange().getBegin(), in DiagnoseConstAssignment()
13257 << ConstFunction << FD << FD->getReturnType() in DiagnoseConstAssignment()
13258 << FD->getReturnTypeSourceRange(); in DiagnoseConstAssignment()
13262 if (const ValueDecl *VD = DRE->getDecl()) { in DiagnoseConstAssignment()
13263 if (!IsTypeModifiable(VD->getType(), IsDereference)) { in DiagnoseConstAssignment()
13266 << ExprRange << ConstVariable << VD << VD->getType(); in DiagnoseConstAssignment()
13269 S.Diag(VD->getLocation(), diag::note_typecheck_assign_const) in DiagnoseConstAssignment()
13270 << ConstVariable << VD << VD->getType() << VD->getSourceRange(); in DiagnoseConstAssignment()
13276 if (MD->isConst()) { in DiagnoseConstAssignment()
13282 S.Diag(MD->getLocation(), diag::note_typecheck_assign_const) in DiagnoseConstAssignment()
13283 << ConstMethod << MD << MD->getSourceRange(); in DiagnoseConstAssignment()
13310 // We walk the record hierarchy breadth-first to ensure that we print in DiagnoseRecursiveConstFields()
13315 RecordTypeList[NextToCheckIndex]->getDecl()->fields()) { in DiagnoseRecursiveConstFields()
13317 QualType FieldTy = Field->getType(); in DiagnoseRecursiveConstFields()
13325 S.Diag(Field->getLocation(), diag::note_typecheck_assign_const) in DiagnoseRecursiveConstFields()
13327 << FieldTy << Field->getSourceRange(); in DiagnoseRecursiveConstFields()
13332 if (const auto *FieldRecTy = FieldTy->getAs<RecordType>()) { in DiagnoseRecursiveConstFields()
13342 /// const-qualified field somewhere in its hierarchy.
13345 QualType Ty = E->getType(); in DiagnoseRecursiveConstFields()
13346 assert(Ty->isRecordType() && "lvalue was not record?"); in DiagnoseRecursiveConstFields()
13347 SourceRange Range = E->getSourceRange(); in DiagnoseRecursiveConstFields()
13348 const RecordType *RTy = Ty.getCanonicalType()->getAs<RecordType>(); in DiagnoseRecursiveConstFields()
13352 DiagnoseRecursiveConstFields(S, ME->getMemberDecl(), RTy, Loc, in DiagnoseRecursiveConstFields()
13355 DiagnoseRecursiveConstFields(S, DRE->getDecl(), RTy, Loc, in DiagnoseRecursiveConstFields()
13364 /// CheckForModifiableLvalue - Verify that E is a modifiable lvalue. If not,
13367 assert(!E->hasPlaceholderType(BuiltinType::PseudoObject)); in CheckForModifiableLvalue()
13372 Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context, in CheckForModifiableLvalue()
13394 // infer 'const'. These are always pseudo-strong variables. in CheckForModifiableLvalue()
13396 DeclRefExpr *declRef = dyn_cast<DeclRefExpr>(E->IgnoreParenCasts()); in CheckForModifiableLvalue()
13397 if (declRef && isa<VarDecl>(declRef->getDecl())) { in CheckForModifiableLvalue()
13398 VarDecl *var = cast<VarDecl>(declRef->getDecl()); in CheckForModifiableLvalue()
13400 // Use the normal diagnostic if it's pseudo-__strong but the in CheckForModifiableLvalue()
13402 if (var->isARCPseudoStrong() && in CheckForModifiableLvalue()
13403 (!var->getTypeSourceInfo() || in CheckForModifiableLvalue()
13404 !var->getTypeSourceInfo()->getType().isConstQualified())) { in CheckForModifiableLvalue()
13405 // There are three pseudo-strong cases: in CheckForModifiableLvalue()
13406 // - self in CheckForModifiableLvalue()
13408 if (method && var == method->getSelfDecl()) { in CheckForModifiableLvalue()
13409 DiagID = method->isClassMethod() in CheckForModifiableLvalue()
13413 // - Objective-C externally_retained attribute. in CheckForModifiableLvalue()
13414 } else if (var->hasAttr<ObjCExternallyRetainedAttr>() || in CheckForModifiableLvalue()
13418 // - fast enumeration variables in CheckForModifiableLvalue()
13426 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign; in CheckForModifiableLvalue()
13469 return S.RequireCompleteType(Loc, E->getType(), in CheckForModifiableLvalue()
13488 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign; in CheckForModifiableLvalue()
13490 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign; in CheckForModifiableLvalue()
13503 if (LHSExpr->getExprLoc().isMacroID() || RHSExpr->getExprLoc().isMacroID()) in CheckIdentityFieldAssignment()
13510 if (!(isa<CXXThisExpr>(ML->getBase()) && isa<CXXThisExpr>(MR->getBase()))) in CheckIdentityFieldAssignment()
13513 cast<ValueDecl>(ML->getMemberDecl()->getCanonicalDecl()); in CheckIdentityFieldAssignment()
13515 cast<ValueDecl>(MR->getMemberDecl()->getCanonicalDecl()); in CheckIdentityFieldAssignment()
13518 if (LHSDecl->getType().isVolatileQualified()) in CheckIdentityFieldAssignment()
13520 if (const ReferenceType *RefTy = LHSDecl->getType()->getAs<ReferenceType>()) in CheckIdentityFieldAssignment()
13521 if (RefTy->getPointeeType().isVolatileQualified()) in CheckIdentityFieldAssignment()
13527 // Objective-C instance variables in CheckIdentityFieldAssignment()
13530 if (OL && OR && OL->getDecl() == OR->getDecl()) { in CheckIdentityFieldAssignment()
13531 DeclRefExpr *RL = dyn_cast<DeclRefExpr>(OL->getBase()->IgnoreImpCasts()); in CheckIdentityFieldAssignment()
13532 DeclRefExpr *RR = dyn_cast<DeclRefExpr>(OR->getBase()->IgnoreImpCasts()); in CheckIdentityFieldAssignment()
13533 if (RL && RR && RL->getDecl() == RR->getDecl()) in CheckIdentityFieldAssignment()
13543 assert(!LHSExpr->hasPlaceholderType(BuiltinType::PseudoObject)); in CheckAssignmentOperands()
13549 QualType LHSType = LHSExpr->getType(); in CheckAssignmentOperands()
13550 QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : in CheckAssignmentOperands()
13552 // OpenCL v1.2 s6.1.1.1 p2: in CheckAssignmentOperands()
13557 LHSType->isHalfType()) { in CheckAssignmentOperands()
13564 if (RHSType->isWebAssemblyTableType()) { in CheckAssignmentOperands()
13579 // Special case of NSObject attributes on c-style pointer types. in CheckAssignmentOperands()
13582 RHSType->isObjCObjectPointerType()) || in CheckAssignmentOperands()
13584 LHSType->isObjCObjectPointerType()))) in CheckAssignmentOperands()
13588 LHSType->isObjCObjectType()) in CheckAssignmentOperands()
13596 RHSCheck = ICE->getSubExpr(); in CheckAssignmentOperands()
13598 if ((UO->getOpcode() == UO_Plus || UO->getOpcode() == UO_Minus) && in CheckAssignmentOperands()
13599 Loc.isFileID() && UO->getOperatorLoc().isFileID() && in CheckAssignmentOperands()
13601 Loc.getLocWithOffset(1) == UO->getOperatorLoc() && in CheckAssignmentOperands()
13603 // unary +/-. We don't want to warn on "x=-1". in CheckAssignmentOperands()
13604 Loc.getLocWithOffset(2) != UO->getSubExpr()->getBeginLoc() && in CheckAssignmentOperands()
13605 UO->getSubExpr()->getBeginLoc().isFileID()) { in CheckAssignmentOperands()
13607 << (UO->getOpcode() == UO_Plus ? "+" : "-") in CheckAssignmentOperands()
13608 << SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc()); in CheckAssignmentOperands()
13617 const Expr *InnerLHS = LHSExpr->IgnoreParenCasts(); in CheckAssignmentOperands()
13619 if (!DRE || DRE->getDecl()->hasAttr<BlocksAttr>()) in CheckAssignmentOperands()
13631 // -Wrepeated-use-of-weak is made flow-sensitive. in CheckAssignmentOperands()
13632 // For ObjCWeak only, we do not warn if the assign is to a non-weak in CheckAssignmentOperands()
13635 RHS.get()->getBeginLoc())) in CheckAssignmentOperands()
13636 getCurFunction()->markSafeWeakUse(RHS.get()); in CheckAssignmentOperands()
13658 // C++2a [expr.ass]p5: in CheckAssignmentOperands()
13659 // A simple-assignment whose left operand is of a volatile-qualified in CheckAssignmentOperands()
13660 // type is deprecated unless the assignment is either a discarded-value in CheckAssignmentOperands()
13671 // non-atomic version of the type of the lvalue. in CheckAssignmentOperands()
13679 // 2. a function call expression that returns void
13681 E = E->IgnoreParens(); in IgnoreCommaOperand()
13684 if (CE->getCastKind() == CK_ToVoid) { in IgnoreCommaOperand()
13689 if (CE->getCastKind() == CK_Dependent && E->getType()->isVoidType() && in IgnoreCommaOperand()
13690 CE->getSubExpr()->getType()->isDependentType()) { in IgnoreCommaOperand()
13696 return CE->getCallReturnType(Context)->isVoidType(); in IgnoreCommaOperand()
13709 // Scope isn't fine-grained enough to explicitly list the specific cases, so in DiagnoseCommaOperator()
13721 const unsigned ScopeFlags = getCurScope()->getFlags(); in DiagnoseCommaOperator()
13729 if (BO->getOpcode() != BO_Comma) in DiagnoseCommaOperator()
13731 LHS = BO->getRHS(); in DiagnoseCommaOperator()
13739 Diag(LHS->getBeginLoc(), diag::note_cast_to_void) in DiagnoseCommaOperator()
13740 << LHS->getSourceRange() in DiagnoseCommaOperator()
13741 << FixItHint::CreateInsertion(LHS->getBeginLoc(), in DiagnoseCommaOperator()
13744 << FixItHint::CreateInsertion(PP.getLocForEndOfToken(LHS->getEndLoc()), in DiagnoseCommaOperator()
13772 if (!RHS.get()->getType()->isVoidType()) in CheckCommaOperands()
13773 S.RequireCompleteType(Loc, RHS.get()->getType(), in CheckCommaOperands()
13780 return RHS.get()->getType(); in CheckCommaOperands()
13783 /// CheckIncrementDecrementOperand - unlike most "Check" methods, this routine
13790 QualType ResType = Op->getType(); in CheckIncrementDecrementOperand()
13791 // Atomic types can be used for increment / decrement where the non-atomic in CheckIncrementDecrementOperand()
13794 if (const AtomicType *ResAtomicType = ResType->getAs<AtomicType>()) in CheckIncrementDecrementOperand()
13795 ResType = ResAtomicType->getValueType(); in CheckIncrementDecrementOperand()
13799 if (S.getLangOpts().CPlusPlus && ResType->isBooleanType()) { in CheckIncrementDecrementOperand()
13802 S.Diag(OpLoc, diag::err_decrement_bool) << Op->getSourceRange(); in CheckIncrementDecrementOperand()
13808 << Op->getSourceRange(); in CheckIncrementDecrementOperand()
13809 } else if (S.getLangOpts().CPlusPlus && ResType->isEnumeralType()) { in CheckIncrementDecrementOperand()
13813 } else if (ResType->isRealType()) { in CheckIncrementDecrementOperand()
13815 } else if (ResType->isPointerType()) { in CheckIncrementDecrementOperand()
13819 } else if (ResType->isObjCObjectPointerType()) { in CheckIncrementDecrementOperand()
13825 } else if (ResType->isAnyComplexType()) { in CheckIncrementDecrementOperand()
13826 // C99 does not support ++/-- on complex types, we allow as an extension. in CheckIncrementDecrementOperand()
13829 << IsInc << Op->getSourceRange(); in CheckIncrementDecrementOperand()
13830 } else if (ResType->isPlaceholderType()) { in CheckIncrementDecrementOperand()
13835 } else if (S.getLangOpts().AltiVec && ResType->isVectorType()) { in CheckIncrementDecrementOperand()
13837 } else if (S.getLangOpts().ZVector && ResType->isVectorType() && in CheckIncrementDecrementOperand()
13838 (ResType->castAs<VectorType>()->getVectorKind() != in CheckIncrementDecrementOperand()
13840 // The z vector extensions allow ++ and -- for non-bool vectors. in CheckIncrementDecrementOperand()
13841 } else if (S.getLangOpts().OpenCL && ResType->isVectorType() && in CheckIncrementDecrementOperand()
13842 ResType->castAs<VectorType>()->getElementType()->isIntegerType()) { in CheckIncrementDecrementOperand()
13843 // OpenCL V1.2 6.3 says dec/inc ops operate on integer vector types. in CheckIncrementDecrementOperand()
13846 << ResType << int(IsInc) << Op->getSourceRange(); in CheckIncrementDecrementOperand()
13854 // C++2a [expr.pre.inc]p1, [expr.post.inc]p1: in CheckIncrementDecrementOperand()
13855 // An operand with volatile-qualified type is deprecated in CheckIncrementDecrementOperand()
13864 OK = Op->getObjectKind(); in CheckIncrementDecrementOperand()
13872 /// getPrimaryDecl - Helper function for CheckAddressOfOperand().
13877 /// - &(x) => x
13878 /// - &*****f => f for f a function designator.
13879 /// - &s.xx => s
13880 /// - &s.zz[1].yy -> s, if zz is an array
13881 /// - *(x + 1) -> x, if x is an array
13882 /// - &"123"[2] -> 0
13883 /// - & __real__ x -> x
13888 switch (E->getStmtClass()) { in getPrimaryDecl()
13890 return cast<DeclRefExpr>(E)->getDecl(); in getPrimaryDecl()
13895 if (cast<MemberExpr>(E)->isArrow()) in getPrimaryDecl()
13898 return getPrimaryDecl(cast<MemberExpr>(E)->getBase()); in getPrimaryDecl()
13902 Expr* Base = cast<ArraySubscriptExpr>(E)->getBase(); in getPrimaryDecl()
13904 if (ICE->getSubExpr()->getType()->isArrayType()) in getPrimaryDecl()
13905 return getPrimaryDecl(ICE->getSubExpr()); in getPrimaryDecl()
13912 switch(UO->getOpcode()) { in getPrimaryDecl()
13916 return getPrimaryDecl(UO->getSubExpr()); in getPrimaryDecl()
13922 return getPrimaryDecl(cast<ParenExpr>(E)->getSubExpr()); in getPrimaryDecl()
13924 // If the result of an implicit cast is an l-value, we care about in getPrimaryDecl()
13925 // the sub-expression; otherwise, the result here doesn't matter. in getPrimaryDecl()
13926 return getPrimaryDecl(cast<ImplicitCastExpr>(E)->getSubExpr()); in getPrimaryDecl()
13928 return cast<CXXUuidofExpr>(E)->getGuidDecl(); in getPrimaryDecl()
13938 AO_Property_Expansion = 2,
13949 S.Diag(Loc, diag::err_typecheck_address_of) << Type << E->getSourceRange(); in diagnoseAddressOfInvalidType()
13955 const auto *DRE = cast<DeclRefExpr>(Op->IgnoreParens()); in CheckUseOfCXXMethodAsAddressOfOperand()
13959 << Op->getSourceRange(); in CheckUseOfCXXMethodAsAddressOfOperand()
13964 << DRE->getSourceRange(); in CheckUseOfCXXMethodAsAddressOfOperand()
13966 if (DRE->getQualifier()) in CheckUseOfCXXMethodAsAddressOfOperand()
13969 if (MD->getParent()->getName().empty()) in CheckUseOfCXXMethodAsAddressOfOperand()
13971 << DRE->getSourceRange(); in CheckUseOfCXXMethodAsAddressOfOperand()
13974 StringRef Qual = (MD->getParent()->getName() + "::").toStringRef(Str); in CheckUseOfCXXMethodAsAddressOfOperand()
13976 << DRE->getSourceRange() in CheckUseOfCXXMethodAsAddressOfOperand()
13977 << FixItHint::CreateInsertion(DRE->getSourceRange().getBegin(), Qual); in CheckUseOfCXXMethodAsAddressOfOperand()
13981 if (const BuiltinType *PTy = OrigOp.get()->getType()->getAsPlaceholderType()){ in CheckAddressOfOperand()
13982 if (PTy->getKind() == BuiltinType::Overload) { in CheckAddressOfOperand()
13983 Expr *E = OrigOp.get()->IgnoreParens(); in CheckAddressOfOperand()
13985 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf); in CheckAddressOfOperand()
13987 << OrigOp.get()->getSourceRange(); in CheckAddressOfOperand()
13991 OverloadExpr *Ovl = cast<OverloadExpr>(E); in CheckAddressOfOperand() local
13992 if (isa<UnresolvedMemberExpr>(Ovl)) in CheckAddressOfOperand()
13993 if (!ResolveSingleFunctionTemplateSpecialization(Ovl)) { in CheckAddressOfOperand()
13995 << OrigOp.get()->getSourceRange(); in CheckAddressOfOperand()
14002 if (PTy->getKind() == BuiltinType::UnknownAny) in CheckAddressOfOperand()
14005 if (PTy->getKind() == BuiltinType::BoundMember) { in CheckAddressOfOperand()
14007 << OrigOp.get()->getSourceRange(); in CheckAddressOfOperand()
14015 if (OrigOp.get()->isTypeDependent()) in CheckAddressOfOperand()
14018 assert(!OrigOp.get()->hasPlaceholderType()); in CheckAddressOfOperand()
14021 Expr *op = OrigOp.get()->IgnoreParens(); in CheckAddressOfOperand()
14030 if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) { in CheckAddressOfOperand()
14031 Diag(op->getExprLoc(), diag::err_opencl_taking_address_capture); in CheckAddressOfOperand()
14037 // Implement C99-only parts of addressof rules. in CheckAddressOfOperand()
14039 if (uOp->getOpcode() == UO_Deref) in CheckAddressOfOperand()
14042 return uOp->getSubExpr()->getType(); in CheckAddressOfOperand()
14051 op->getBeginLoc())) in CheckAddressOfOperand()
14054 Expr::LValueClassification lval = op->ClassifyLValue(Context); in CheckAddressOfOperand()
14061 << op->getType() << op->getSourceRange(); in CheckAddressOfOperand()
14066 CreateMaterializeTemporaryExpr(op->getType(), OrigOp.get(), true); in CheckAddressOfOperand()
14068 return Context.getPointerType(op->getType()); in CheckAddressOfOperand()
14076 << OrigOp.get()->getSourceRange(); in CheckAddressOfOperand()
14080 CXXMethodDecl *MD = cast<CXXMethodDecl>(DRE->getDecl()); in CheckAddressOfOperand()
14085 op->getType(), Context.getTypeDeclType(MD->getParent()).getTypePtr()); in CheckAddressOfOperand()
14087 if (getLangOpts().PointerAuthCalls && MD->isVirtual() && in CheckAddressOfOperand()
14088 !isUnevaluatedContext() && !MPTy->isDependentType()) { in CheckAddressOfOperand()
14107 QualType RetTy = MD->getReturnType(); in CheckAddressOfOperand()
14109 !RetTy->isVoidType() && in CheckAddressOfOperand()
14111 RetTy, OpLoc, MD->getReturnTypeSourceRange().getBegin()); in CheckAddressOfOperand()
14112 for (auto *PVD : MD->parameters()) in CheckAddressOfOperand()
14113 IsIncomplete |= ReturnOrParamTypeIsIncomplete(PVD->getType(), OpLoc, in CheckAddressOfOperand()
14114 PVD->getBeginLoc()); in CheckAddressOfOperand()
14125 // The operand must be either an l-value or a function designator in CheckAddressOfOperand()
14126 if (!op->getType()->isFunctionType()) { in CheckAddressOfOperand()
14132 << op->getType() << op->getSourceRange(); in CheckAddressOfOperand()
14136 if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl())) in CheckAddressOfOperand()
14140 } else if (op->getObjectKind() == OK_BitField) { // C99 6.5.3.2p1 in CheckAddressOfOperand()
14141 // The operand cannot be a bit-field in CheckAddressOfOperand()
14143 } else if (op->getObjectKind() == OK_VectorComponent) { in CheckAddressOfOperand()
14146 } else if (op->getObjectKind() == OK_MatrixComponent) { in CheckAddressOfOperand()
14151 // with the register storage-class specifier. in CheckAddressOfOperand()
14155 if (vd->getStorageClass() == SC_Register && in CheckAddressOfOperand()
14169 // If an id-expression E denotes a non-static non-type member in CheckAddressOfOperand()
14170 // of some class C [...] and if E is a qualified-id, E is in CheckAddressOfOperand()
14171 // not the un-parenthesized operand of the unary & operator [...] in CheckAddressOfOperand()
14172 // the id-expression is transformed into a class member access expression. in CheckAddressOfOperand()
14173 if (isa<DeclRefExpr>(op) && cast<DeclRefExpr>(op)->getQualifier() && in CheckAddressOfOperand()
14175 DeclContext *Ctx = dcl->getDeclContext(); in CheckAddressOfOperand()
14176 if (Ctx && Ctx->isRecord()) { in CheckAddressOfOperand()
14177 if (dcl->getType()->isReferenceType()) { in CheckAddressOfOperand()
14180 << dcl->getDeclName() << dcl->getType(); in CheckAddressOfOperand()
14184 while (cast<RecordDecl>(Ctx)->isAnonymousStructOrUnion()) in CheckAddressOfOperand()
14185 Ctx = Ctx->getParent(); in CheckAddressOfOperand()
14188 op->getType(), in CheckAddressOfOperand()
14210 Diag(OpLoc, diag::ext_typecheck_addrof_void) << op->getSourceRange(); in CheckAddressOfOperand()
14214 if (op->getType()->isObjCObjectType()) in CheckAddressOfOperand()
14215 return Context.getObjCObjectPointerType(op->getType()); in CheckAddressOfOperand()
14219 QualType OpTy = op->getType(); in CheckAddressOfOperand()
14222 << 1 << OrigOp.get()->getSourceRange(); in CheckAddressOfOperand()
14225 if (OpTy->isWebAssemblyTableType()) { in CheckAddressOfOperand()
14227 << 1 << OrigOp.get()->getSourceRange(); in CheckAddressOfOperand()
14234 return Context.getPointerType(op->getType()); in CheckAddressOfOperand()
14241 const Decl *D = DRE->getDecl(); in RecordModifiableNonNullParam()
14247 if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(Param->getDeclContext())) in RecordModifiableNonNullParam()
14248 if (!FD->hasAttr<NonNullAttr>() && !Param->hasAttr<NonNullAttr>()) in RecordModifiableNonNullParam()
14251 FD->ModifiedNonNullParams.insert(Param); in RecordModifiableNonNullParam()
14254 /// CheckIndirectionOperand - Type check unary indirection (prefix '*').
14262 QualType OpTy = Op->getType(); in CheckIndirectionOperand()
14266 QualType OpOrigType = Op->IgnoreParenCasts()->getType(); in CheckIndirectionOperand()
14268 Op->getSourceRange()); in CheckIndirectionOperand()
14271 if (const PointerType *PT = OpTy->getAs<PointerType>()) in CheckIndirectionOperand()
14273 Result = PT->getPointeeType(); in CheckIndirectionOperand()
14276 OpTy->getAs<ObjCObjectPointerType>()) in CheckIndirectionOperand()
14277 Result = OPT->getPointeeType(); in CheckIndirectionOperand()
14287 << OpTy << Op->getSourceRange(); in CheckIndirectionOperand()
14291 if (Result->isVoidType()) { in CheckIndirectionOperand()
14298 << OpTy << Op->getSourceRange(); in CheckIndirectionOperand()
14301 << OpTy << Op->getSourceRange(); in CheckIndirectionOperand()
14304 // Dereferences are usually l-values... in CheckIndirectionOperand()
14307 // ...except that certain expressions are never l-values in C. in CheckIndirectionOperand()
14377 // Explore the case for adding 'this->' to the LHS of a self assignment, very in getSelfAssignmentClassMemberCandidate()
14381 // -void setX(int X) { X = X; } in getSelfAssignmentClassMemberCandidate()
14382 // +void setX(int X) { this->X = X; } in getSelfAssignmentClassMemberCandidate()
14393 const CXXRecordDecl *Parent = Method->getParent(); in getSelfAssignmentClassMemberCandidate()
14396 if (Parent->isLambda()) in getSelfAssignmentClassMemberCandidate()
14402 llvm::find_if(Parent->fields(), in getSelfAssignmentClassMemberCandidate()
14403 [Name(SelfAssigned->getDeclName())](const FieldDecl *F) { in getSelfAssignmentClassMemberCandidate()
14404 return F->getDeclName() == Name; in getSelfAssignmentClassMemberCandidate()
14406 return (Field != Parent->field_end()) ? *Field : nullptr; in getSelfAssignmentClassMemberCandidate()
14409 /// DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
14419 LHSExpr = LHSExpr->IgnoreParenImpCasts(); in DiagnoseSelfAssignment()
14420 RHSExpr = RHSExpr->IgnoreParenImpCasts(); in DiagnoseSelfAssignment()
14424 LHSDeclRef->getLocation().isMacroID() || in DiagnoseSelfAssignment()
14425 RHSDeclRef->getLocation().isMacroID()) in DiagnoseSelfAssignment()
14428 cast<ValueDecl>(LHSDeclRef->getDecl()->getCanonicalDecl()); in DiagnoseSelfAssignment()
14430 cast<ValueDecl>(RHSDeclRef->getDecl()->getCanonicalDecl()); in DiagnoseSelfAssignment()
14433 if (LHSDecl->getType().isVolatileQualified()) in DiagnoseSelfAssignment()
14435 if (const ReferenceType *RefTy = LHSDecl->getType()->getAs<ReferenceType>()) in DiagnoseSelfAssignment()
14436 if (RefTy->getPointeeType().isVolatileQualified()) in DiagnoseSelfAssignment()
14441 << LHSDeclRef->getType() << LHSExpr->getSourceRange() in DiagnoseSelfAssignment()
14442 << RHSExpr->getSourceRange(); in DiagnoseSelfAssignment()
14446 << FixItHint::CreateInsertion(LHSDeclRef->getBeginLoc(), "this->"); in DiagnoseSelfAssignment()
14451 /// Check if a bitwise-& is performed on an Objective-C pointer. This
14452 /// is usually indicative of introspection within the Objective-C pointer.
14453 static void checkObjCPointerIntrospection(Sema &S, ExprResult &L, ExprResult &R, in checkObjCPointerIntrospection() argument
14459 const Expr *LHS = L.get(); in checkObjCPointerIntrospection()
14462 if (LHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) { in checkObjCPointerIntrospection()
14466 else if (RHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) { in checkObjCPointerIntrospection()
14475 if (ObjCPointerExpr && isa<IntegerLiteral>(OtherExpr->IgnoreParenCasts())) { in checkObjCPointerIntrospection()
14478 const Expr *Ex = ObjCPointerExpr->IgnoreParenCasts(); in checkObjCPointerIntrospection()
14479 // Special case messages to -performSelector and friends, which in checkObjCPointerIntrospection()
14480 // can return non-pointer values boxed in a pointer value. in checkObjCPointerIntrospection()
14483 Selector S = ME->getSelector(); in checkObjCPointerIntrospection()
14490 << ObjCPointerExpr->getSourceRange(); in checkObjCPointerIntrospection()
14498 return DRE->getDecl(); in getDeclFromExpr()
14500 return ME->getMemberDecl(); in getDeclFromExpr()
14502 return IRE->getDecl(); in getDeclFromExpr()
14518 assert(isVector(LHS.get()->getType(), Context.HalfTy) && in convertHalfVecBinOp()
14519 isVector(RHS.get()->getType(), Context.HalfTy) && in convertHalfVecBinOp()
14523 QualType BinOpResTy = RHS.get()->getType(); in convertHalfVecBinOp()
14538 return convertVector(BO, ResultTy->castAs<VectorType>()->getElementType(), S); in convertHalfVecBinOp()
14572 QualType Ty = E->IgnoreImplicit()->getType(); in needsConversionOfHalfVec()
14576 // the vectors shouldn't be treated as storage-only types. See the in needsConversionOfHalfVec()
14578 if (const VectorType *VT = Ty->getAs<VectorType>()) { in needsConversionOfHalfVec()
14579 if (VT->getVectorKind() == VectorKind::Neon) in needsConversionOfHalfVec()
14581 return VT->getElementType().getCanonicalType() == Ctx.HalfTy; in needsConversionOfHalfVec()
14595 // non-assignment operators. in CreateBuiltinBinOp()
14600 RHSExpr->getBeginLoc(), RHSExpr->getBeginLoc(), RHSExpr->getEndLoc()); in CreateBuiltinBinOp()
14602 InitializedEntity::InitializeTemporary(LHSExpr->getType()); in CreateBuiltinBinOp()
14624 QualType LHSTy = LHSExpr->getType(); in CreateBuiltinBinOp()
14625 QualType RHSTy = RHSExpr->getType(); in CreateBuiltinBinOp()
14628 if (LHSTy->isAtomicType() || RHSTy->isAtomicType()) { in CreateBuiltinBinOp()
14629 SourceRange SR(LHSExpr->getBeginLoc(), RHSExpr->getEndLoc()); in CreateBuiltinBinOp()
14637 // OpenCL special types - image, sampler, pipe, and blocks are to be used in CreateBuiltinBinOp()
14639 if (LHSTy->isImageType() || RHSTy->isImageType() || in CreateBuiltinBinOp()
14640 LHSTy->isSamplerT() || RHSTy->isSamplerT() || in CreateBuiltinBinOp()
14641 LHSTy->isPipeType() || RHSTy->isPipeType() || in CreateBuiltinBinOp()
14642 LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) { in CreateBuiltinBinOp()
14648 checkTypeSupport(LHSExpr->getType(), OpLoc, /*ValueDecl*/ nullptr); in CreateBuiltinBinOp()
14649 checkTypeSupport(RHSExpr->getType(), OpLoc, /*ValueDecl*/ nullptr); in CreateBuiltinBinOp()
14655 LHS.get()->getObjectKind() != OK_ObjCProperty) { in CreateBuiltinBinOp()
14656 VK = LHS.get()->getValueKind(); in CreateBuiltinBinOp()
14657 OK = LHS.get()->getObjectKind(); in CreateBuiltinBinOp()
14676 if (auto *BE = dyn_cast<BlockExpr>(RHS.get()->IgnoreParens())) in CreateBuiltinBinOp()
14677 if (auto *DRE = dyn_cast<DeclRefExpr>(LHS.get()->IgnoreParens())) in CreateBuiltinBinOp()
14678 if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) in CreateBuiltinBinOp()
14679 if (VD->hasLocalStorage() && getCurScope()->isDeclScope(VD)) in CreateBuiltinBinOp()
14680 BE->getBlockDecl()->setCanAvoidCopyToHeap(); in CreateBuiltinBinOp()
14682 if (LHS.get()->getType().hasNonTrivialToPrimitiveCopyCUnion()) in CreateBuiltinBinOp()
14683 checkNonTrivialCUnion(LHS.get()->getType(), LHS.get()->getExprLoc(), in CreateBuiltinBinOp()
14722 BI && BI->isComparisonOp()) in CreateBuiltinBinOp()
14734 assert(ResultTy.isNull() || ResultTy->getAsCXXRecordDecl()); in CreateBuiltinBinOp()
14801 VK = RHS.get()->getValueKind(); in CreateBuiltinBinOp()
14802 OK = RHS.get()->getObjectKind(); in CreateBuiltinBinOp()
14814 (Opc == BO_Comma || isVector(RHS.get()->getType(), Context.HalfTy) == in CreateBuiltinBinOp()
14815 isVector(LHS.get()->getType(), Context.HalfTy)) && in CreateBuiltinBinOp()
14824 if (const ObjCIsaExpr *OISA = dyn_cast<ObjCIsaExpr>(LHS.get()->IgnoreParenCasts())) { in CreateBuiltinBinOp()
14829 SourceLocation RHSLocEnd = getLocForEndOfToken(RHS.get()->getEndLoc()); in CreateBuiltinBinOp()
14830 Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign) in CreateBuiltinBinOp()
14831 << FixItHint::CreateInsertion(LHS.get()->getBeginLoc(), in CreateBuiltinBinOp()
14833 << FixItHint::CreateReplacement(SourceRange(OISA->getOpLoc(), OpLoc), in CreateBuiltinBinOp()
14838 Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign); in CreateBuiltinBinOp()
14841 dyn_cast<ObjCIvarRefExpr>(LHS.get()->IgnoreParenCasts())) in CreateBuiltinBinOp()
14854 if (getLangOpts().CPlusPlus && LHS.get()->getObjectKind() != in CreateBuiltinBinOp()
14857 OK = LHS.get()->getObjectKind(); in CreateBuiltinBinOp()
14860 // The LHS is not converted to the result type for fixed-point compound in CreateBuiltinBinOp()
14863 if (CompResultTy->isFixedPointType()) in CreateBuiltinBinOp()
14864 CompLHSTy = UsualUnaryConversions(LHS.get()).get()->getType(); in CreateBuiltinBinOp()
14875 /// DiagnoseBitwisePrecedence - Emit a warning when bitwise and comparison
14886 bool isLeftComp = LHSBO && LHSBO->isComparisonOp(); in DiagnoseBitwisePrecedence()
14887 bool isRightComp = RHSBO && RHSBO->isComparisonOp(); in DiagnoseBitwisePrecedence()
14893 bool isLeftBitwise = LHSBO && LHSBO->isBitwiseOp(); in DiagnoseBitwisePrecedence()
14894 bool isRightBitwise = RHSBO && RHSBO->isBitwiseOp(); in DiagnoseBitwisePrecedence()
14899 ? SourceRange(LHSExpr->getBeginLoc(), OpLoc) in DiagnoseBitwisePrecedence()
14900 : SourceRange(OpLoc, RHSExpr->getEndLoc()); in DiagnoseBitwisePrecedence()
14901 StringRef OpStr = isLeftComp ? LHSBO->getOpcodeStr() : RHSBO->getOpcodeStr(); in DiagnoseBitwisePrecedence()
14904 ? SourceRange(LHSBO->getRHS()->getBeginLoc(), RHSExpr->getEndLoc()) in DiagnoseBitwisePrecedence()
14905 : SourceRange(LHSExpr->getBeginLoc(), RHSBO->getLHS()->getEndLoc()); in DiagnoseBitwisePrecedence()
14911 (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange()); in DiagnoseBitwisePrecedence()
14924 assert(Bop->getOpcode() == BO_LAnd); in EmitDiagnosticForLogicalAndInLogicalOr()
14925 Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or) in EmitDiagnosticForLogicalAndInLogicalOr()
14926 << Bop->getSourceRange() << OpLoc; in EmitDiagnosticForLogicalAndInLogicalOr()
14927 SuggestParentheses(Self, Bop->getOperatorLoc(), in EmitDiagnosticForLogicalAndInLogicalOr()
14929 << Bop->getOpcodeStr(), in EmitDiagnosticForLogicalAndInLogicalOr()
14930 Bop->getSourceRange()); in EmitDiagnosticForLogicalAndInLogicalOr()
14937 if (Bop->getOpcode() == BO_LAnd) { in DiagnoseLogicalAndInLogicalOrLHS()
14940 if (!isa<StringLiteral>(Bop->getLHS()->IgnoreParenImpCasts())) in DiagnoseLogicalAndInLogicalOrLHS()
14942 } else if (Bop->getOpcode() == BO_LOr) { in DiagnoseLogicalAndInLogicalOrLHS()
14943 if (BinaryOperator *RBop = dyn_cast<BinaryOperator>(Bop->getRHS())) { in DiagnoseLogicalAndInLogicalOrLHS()
14946 if (RBop->getOpcode() == BO_LAnd && in DiagnoseLogicalAndInLogicalOrLHS()
14947 isa<StringLiteral>(RBop->getRHS()->IgnoreParenImpCasts())) in DiagnoseLogicalAndInLogicalOrLHS()
14958 if (Bop->getOpcode() == BO_LAnd) { in DiagnoseLogicalAndInLogicalOrRHS()
14961 if (!isa<StringLiteral>(Bop->getRHS()->IgnoreParenImpCasts())) in DiagnoseLogicalAndInLogicalOrRHS()
14973 if (Bop->isBitwiseOp() && Bop->getOpcode() < Opc) { in DiagnoseBitwiseOpInBitwiseOp()
14974 S.Diag(Bop->getOperatorLoc(), diag::warn_bitwise_op_in_bitwise_op) in DiagnoseBitwiseOpInBitwiseOp()
14975 << Bop->getOpcodeStr() << BinaryOperator::getOpcodeStr(Opc) in DiagnoseBitwiseOpInBitwiseOp()
14976 << Bop->getSourceRange() << OpLoc; in DiagnoseBitwiseOpInBitwiseOp()
14977 SuggestParentheses(S, Bop->getOperatorLoc(), in DiagnoseBitwiseOpInBitwiseOp()
14979 << Bop->getOpcodeStr(), in DiagnoseBitwiseOpInBitwiseOp()
14980 Bop->getSourceRange()); in DiagnoseBitwiseOpInBitwiseOp()
14988 if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) { in DiagnoseAdditionInShift()
14989 StringRef Op = Bop->getOpcodeStr(); in DiagnoseAdditionInShift()
14990 S.Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift) in DiagnoseAdditionInShift()
14991 << Bop->getSourceRange() << OpLoc << Shift << Op; in DiagnoseAdditionInShift()
14992 SuggestParentheses(S, Bop->getOperatorLoc(), in DiagnoseAdditionInShift()
14994 Bop->getSourceRange()); in DiagnoseAdditionInShift()
15005 FunctionDecl *FD = OCE->getDirectCallee(); in DiagnoseShiftCompare()
15006 if (!FD || !FD->isOverloadedOperator()) in DiagnoseShiftCompare()
15009 OverloadedOperatorKind Kind = FD->getOverloadedOperator(); in DiagnoseShiftCompare()
15014 << LHSExpr->getSourceRange() << RHSExpr->getSourceRange() in DiagnoseShiftCompare()
15016 SuggestParentheses(S, OCE->getOperatorLoc(), in DiagnoseShiftCompare()
15019 OCE->getSourceRange()); in DiagnoseShiftCompare()
15022 SourceRange(OCE->getArg(1)->getBeginLoc(), RHSExpr->getEndLoc())); in DiagnoseShiftCompare()
15025 /// DiagnoseBinOpPrecedence - Emit warnings for expressions with tricky
15048 if ((Opc == BO_Shl && LHSExpr->getType()->isIntegralType(Self.getASTContext())) in DiagnoseBinOpPrecedence()
15093 // In the non-overloaded case, we warn about self-assignment (x = x) for in BuildOverloadedBinOp()
15097 // those algebraic identities still apply; for example, a path-building in BuildOverloadedBinOp()
15100 // and so self-assignment is likely a bug. in BuildOverloadedBinOp()
15119 // Build the (potentially-overloaded, potentially-dependent) in BuildOverloadedBinOp()
15135 // (if the LHS is a pseudo-object), BuildOverloadedBinOp (if in BuildBinOp()
15136 // both expressions are overloadable or either is type-dependent), in BuildBinOp()
15140 // Handle pseudo-objects in the LHS. in BuildBinOp()
15141 if (const BuiltinType *pty = LHSExpr->getType()->getAsPlaceholderType()) { in BuildBinOp()
15142 // Assignments with a pseudo-object l-value need special analysis. in BuildBinOp()
15143 if (pty->getKind() == BuiltinType::PseudoObject && in BuildBinOp()
15148 if (getLangOpts().CPlusPlus && pty->getKind() == BuiltinType::Overload) { in BuildBinOp()
15152 // that an overload set can be dependently-typed, but it never in BuildBinOp()
15158 if (RHSExpr->isTypeDependent() || in BuildBinOp()
15159 RHSExpr->getType()->isOverloadableType()) in BuildBinOp()
15170 (pty->getKind() == BuiltinType::BoundMember || in BuildBinOp()
15171 pty->getKind() == BuiltinType::Overload)) { in BuildBinOp()
15173 if (OE && !OE->hasTemplateKeyword() && !OE->hasExplicitTemplateArgs() && in BuildBinOp()
15174 llvm::any_of(OE->decls(), [](NamedDecl *ND) { in BuildBinOp()
15177 Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc() in BuildBinOp()
15178 : OE->getNameLoc(), in BuildBinOp()
15180 << OE->getName().getAsString() << ""; in BuildBinOp()
15190 // Handle pseudo-objects in the RHS. in BuildBinOp()
15191 if (const BuiltinType *pty = RHSExpr->getType()->getAsPlaceholderType()) { in BuildBinOp()
15194 if (Opc == BO_Assign && pty->getKind() == BuiltinType::Overload) { in BuildBinOp()
15196 (LHSExpr->isTypeDependent() || RHSExpr->isTypeDependent() || in BuildBinOp()
15197 LHSExpr->getType()->isOverloadableType())) in BuildBinOp()
15204 if (getLangOpts().CPlusPlus && pty->getKind() == BuiltinType::Overload && in BuildBinOp()
15205 LHSExpr->getType()->isOverloadableType()) in BuildBinOp()
15214 // Otherwise, build an overloaded op if either expression is type-dependent in BuildBinOp()
15216 if (LHSExpr->isTypeDependent() || RHSExpr->isTypeDependent() || in BuildBinOp()
15217 LHSExpr->getType()->isOverloadableType() || in BuildBinOp()
15218 RHSExpr->getType()->isOverloadableType()) in BuildBinOp()
15223 (LHSExpr->isTypeDependent() || RHSExpr->isTypeDependent())) { in BuildBinOp()
15225 assert((LHSExpr->containsErrors() || RHSExpr->containsErrors()) && in BuildBinOp()
15226 "Should only occur in error-recovery path."); in BuildBinOp()
15233 LHSExpr->getType().getUnqualifiedType(), VK_PRValue, OK_Ordinary, in BuildBinOp()
15238 ResultType = LHSExpr->getType().getUnqualifiedType(); in BuildBinOp()
15252 ResultType = RHSExpr->getType(); in BuildBinOp()
15263 // Build a built-in binary operation. in BuildBinOp()
15268 if (T.isNull() || T->isDependentType()) in isOverflowingIntegerType()
15288 QualType Ty = InputExpr->getType(); in CreateBuiltinUnaryOp()
15290 if ((Opc != UO_AddrOf && Ty->isAtomicType()) || in CreateBuiltinUnaryOp()
15291 // OpenCL special types - image, sampler, pipe, and blocks are to be used in CreateBuiltinUnaryOp()
15293 (Ty->isImageType() || Ty->isSamplerT() || Ty->isPipeType() in CreateBuiltinUnaryOp()
15294 || Ty->isBlockPointerType())) { in CreateBuiltinUnaryOp()
15296 << InputExpr->getType() in CreateBuiltinUnaryOp()
15297 << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15308 if (InputExpr->isTypeDependent() && in CreateBuiltinUnaryOp()
15309 InputExpr->getType()->isSpecificBuiltinType(BuiltinType::Dependent)) { in CreateBuiltinUnaryOp()
15339 isOverflowingIntegerType(Context, Input.get()->getType()); in CreateBuiltinUnaryOp()
15352 resultType = Input.get()->getType(); in CreateBuiltinUnaryOp()
15353 if (resultType->isArithmeticType()) // C99 6.5.3.3p1 in CreateBuiltinUnaryOp()
15355 else if (resultType->isVectorType() && in CreateBuiltinUnaryOp()
15356 // The z vector extensions don't allow + or - with bool vectors. in CreateBuiltinUnaryOp()
15358 resultType->castAs<VectorType>()->getVectorKind() != in CreateBuiltinUnaryOp()
15361 else if (resultType->isSveVLSBuiltinType()) // SVE vectors allow + and - in CreateBuiltinUnaryOp()
15364 Opc == UO_Plus && resultType->isPointerType()) in CreateBuiltinUnaryOp()
15368 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15374 resultType = Input.get()->getType(); in CreateBuiltinUnaryOp()
15376 if (resultType->isComplexType() || resultType->isComplexIntegerType()) in CreateBuiltinUnaryOp()
15379 << resultType << Input.get()->getSourceRange(); in CreateBuiltinUnaryOp()
15380 else if (resultType->hasIntegerRepresentation()) in CreateBuiltinUnaryOp()
15382 else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) { in CreateBuiltinUnaryOp()
15385 QualType T = resultType->castAs<ExtVectorType>()->getElementType(); in CreateBuiltinUnaryOp()
15386 if (!T->isIntegerType()) in CreateBuiltinUnaryOp()
15388 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15391 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15396 // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5). in CreateBuiltinUnaryOp()
15400 resultType = Input.get()->getType(); in CreateBuiltinUnaryOp()
15403 if (resultType->isHalfType() && !Context.getLangOpts().NativeHalfType) { in CreateBuiltinUnaryOp()
15410 if (resultType->isPointerType() && in CreateBuiltinUnaryOp()
15411 resultType->getPointeeType().isWebAssemblyReferenceType()) { in CreateBuiltinUnaryOp()
15413 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15416 if (resultType->isScalarType() && !isScopedEnumerationType(resultType)) { in CreateBuiltinUnaryOp()
15427 if (!resultType->isIntegerType() && !resultType->isPointerType()) in CreateBuiltinUnaryOp()
15429 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15431 } else if (resultType->isExtVectorType()) { in CreateBuiltinUnaryOp()
15436 QualType T = resultType->castAs<ExtVectorType>()->getElementType(); in CreateBuiltinUnaryOp()
15437 if (!T->isIntegerType()) in CreateBuiltinUnaryOp()
15439 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15445 resultType->isVectorType()) { in CreateBuiltinUnaryOp()
15446 const VectorType *VTy = resultType->castAs<VectorType>(); in CreateBuiltinUnaryOp()
15447 if (VTy->getVectorKind() != VectorKind::Generic) in CreateBuiltinUnaryOp()
15449 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15456 << resultType << Input.get()->getSourceRange()); in CreateBuiltinUnaryOp()
15466 // _Real maps ordinary l-values into ordinary l-values. _Imag maps in CreateBuiltinUnaryOp()
15467 // ordinary complex l-values to ordinary l-values and all other values to in CreateBuiltinUnaryOp()
15468 // r-values. in CreateBuiltinUnaryOp()
15471 if (Opc == UO_Real || Input.get()->getType()->isAnyComplexType()) { in CreateBuiltinUnaryOp()
15472 if (Input.get()->isGLValue() && in CreateBuiltinUnaryOp()
15473 Input.get()->getObjectKind() == OK_Ordinary) in CreateBuiltinUnaryOp()
15474 VK = Input.get()->getValueKind(); in CreateBuiltinUnaryOp()
15481 resultType = Input.get()->getType(); in CreateBuiltinUnaryOp()
15482 VK = Input.get()->getValueKind(); in CreateBuiltinUnaryOp()
15483 OK = Input.get()->getObjectKind(); in CreateBuiltinUnaryOp()
15486 // It's unnecessary to represent the pass-through operator co_await in the in CreateBuiltinUnaryOp()
15488 assert(!Input.get()->getType()->isDependentType() && in CreateBuiltinUnaryOp()
15489 "the co_await expression must be non-dependant before " in CreateBuiltinUnaryOp()
15508 if (Opc == UO_Deref && UO->getType()->hasAttr(attr::NoDeref) && in CreateBuiltinUnaryOp()
15509 !isa<ArrayType>(UO->getType().getDesugaredType(Context)) && in CreateBuiltinUnaryOp()
15521 if (!DRE->getQualifier()) in isQualifiedMemberAccess()
15524 ValueDecl *VD = DRE->getDecl(); in isQualifiedMemberAccess()
15525 if (!VD->isCXXClassMember()) in isQualifiedMemberAccess()
15531 return Method->isImplicitObjectMemberFunction(); in isQualifiedMemberAccess()
15537 if (!ULE->getQualifier()) in isQualifiedMemberAccess()
15540 for (NamedDecl *D : ULE->decls()) { in isQualifiedMemberAccess()
15542 if (Method->isImplicitObjectMemberFunction()) in isQualifiedMemberAccess()
15560 // overloaded-operator check considers the right type. in BuildUnaryOp()
15561 if (const BuiltinType *pty = Input->getType()->getAsPlaceholderType()) { in BuildUnaryOp()
15562 // Increment and decrement of pseudo-object references. in BuildUnaryOp()
15563 if (pty->getKind() == BuiltinType::PseudoObject && in BuildUnaryOp()
15574 (pty->getKind() == BuiltinType::Overload || in BuildUnaryOp()
15575 pty->getKind() == BuiltinType::UnknownAny || in BuildUnaryOp()
15576 pty->getKind() == BuiltinType::BoundMember)) in BuildUnaryOp()
15585 if (getLangOpts().CPlusPlus && Input->getType()->isOverloadableType() && in BuildUnaryOp()
15608 TheDecl->markUsed(Context); in ActOnAddrLabel()
15614 getCurFunction()->AddrLabels.push_back(Res); in ActOnAddrLabel()
15653 // If there are sub-stmts in the compound stmt, take the type of the last one in BuildStmtExpr()
15657 if (!Compound->body_empty()) { in BuildStmtExpr()
15660 dyn_cast<ValueStmt>(Compound->getStmtExprResult())) { in BuildStmtExpr()
15661 if (const Expr *Value = LastStmt->getExprStmt()) { in BuildStmtExpr()
15663 Ty = Value->getType(); in BuildStmtExpr()
15668 // FIXME: Check that expression type is complete/non-abstract; statement in BuildStmtExpr()
15682 // lvalue-to-rvalue. However, initialize an unqualified type. in ActOnStmtExprResult()
15688 if (E->isTypeDependent()) in ActOnStmtExprResult()
15698 if (Cast && Cast->getCastKind() == CK_ARCConsumeObject) in ActOnStmtExprResult()
15699 return Cast->getSubExpr(); in ActOnStmtExprResult()
15704 E->getBeginLoc(), E->getType().getUnqualifiedType()), in ActOnStmtExprResult()
15712 QualType ArgTy = TInfo->getType(); in BuildBuiltinOffsetOf()
15713 bool Dependent = ArgTy->isDependentType(); in BuildBuiltinOffsetOf()
15714 SourceRange TypeRange = TInfo->getTypeLoc().getLocalSourceRange(); in BuildBuiltinOffsetOf()
15719 if (!Dependent && !ArgTy->isRecordType()) in BuildBuiltinOffsetOf()
15724 // with an incomplete type would be ill-formed. in BuildBuiltinOffsetOf()
15736 // Offset of an array sub-field. TODO: Should we allow vector elements? in BuildBuiltinOffsetOf()
15737 if (!CurrentType->isDependentType()) { in BuildBuiltinOffsetOf()
15742 CurrentType = AT->getElementType(); in BuildBuiltinOffsetOf()
15753 if (!Idx->isTypeDependent() && !Idx->isValueDependent() && in BuildBuiltinOffsetOf()
15754 !Idx->getType()->isIntegerType()) in BuildBuiltinOffsetOf()
15756 Diag(Idx->getBeginLoc(), diag::err_typecheck_subscript_not_integer) in BuildBuiltinOffsetOf()
15757 << Idx->getSourceRange()); in BuildBuiltinOffsetOf()
15766 if (CurrentType->isDependentType()) { in BuildBuiltinOffsetOf()
15780 const RecordType *RC = CurrentType->getAs<RecordType>(); in BuildBuiltinOffsetOf()
15784 RecordDecl *RD = RC->getDecl(); in BuildBuiltinOffsetOf()
15791 // If type is not a standard-layout class (Clause 9), the results are in BuildBuiltinOffsetOf()
15794 bool IsSafe = LangOpts.CPlusPlus11? CRD->isStandardLayout() : CRD->isPOD(); in BuildBuiltinOffsetOf()
15813 MemberDecl = IndirectMemberDecl->getAnonField(); in BuildBuiltinOffsetOf()
15827 // (If the specified member is a bit-field, the behavior is undefined.) in BuildBuiltinOffsetOf()
15830 if (MemberDecl->isBitField()) { in BuildBuiltinOffsetOf()
15832 << MemberDecl->getDeclName() in BuildBuiltinOffsetOf()
15834 Diag(MemberDecl->getLocation(), diag::note_bitfield_decl); in BuildBuiltinOffsetOf()
15838 RecordDecl *Parent = MemberDecl->getParent(); in BuildBuiltinOffsetOf()
15840 Parent = cast<RecordDecl>(IndirectMemberDecl->getDeclContext()); in BuildBuiltinOffsetOf()
15849 << MemberDecl->getDeclName() in BuildBuiltinOffsetOf()
15860 for (auto *FI : IndirectMemberDecl->chain()) { in BuildBuiltinOffsetOf()
15868 CurrentType = MemberDecl->getType().getNonReferenceType(); in BuildBuiltinOffsetOf()
15904 if (CondExpr->isTypeDependent() || CondExpr->isValueDependent()) { in ActOnChooseExpr()
15919 resType = ActiveExpr->getType(); in ActOnChooseExpr()
15920 VK = ActiveExpr->getValueKind(); in ActOnChooseExpr()
15921 OK = ActiveExpr->getObjectKind(); in ActOnChooseExpr()
15928 //===----------------------------------------------------------------------===//
15930 //===----------------------------------------------------------------------===//
15939 getCurrentMangleNumberContext(Block->getDeclContext()); in ActOnBlockStart()
15941 unsigned ManglingNumber = MCtx->getManglingNumber(Block); in ActOnBlockStart()
15942 Block->setBlockMangling(ManglingNumber, ManglingContextDecl); in ActOnBlockStart()
15947 CurContext->addDecl(Block); in ActOnBlockStart()
15953 getCurBlock()->HasImplicitReturnType = true; in ActOnBlockStart()
15956 // cleanups from the enclosing full-expression. in ActOnBlockStart()
15964 "block-id should have no identifier!"); in ActOnBlockArguments()
15969 QualType T = Sig->getType(); in ActOnBlockArguments()
15985 assert(T->isFunctionType() && in ActOnBlockArguments()
15986 "GetTypeForDeclarator made a non-function block signature"); in ActOnBlockArguments()
15991 if ((ExplicitSignature = Sig->getTypeLoc() in ActOnBlockArguments()
16004 Sig->getTypeLoc().initializeFullCopy(Result, Size); in ActOnBlockArguments()
16010 CurBlock->TheDecl->setSignatureAsWritten(Sig); in ActOnBlockArguments()
16011 CurBlock->FunctionType = T; in ActOnBlockArguments()
16013 const auto *Fn = T->castAs<FunctionType>(); in ActOnBlockArguments()
16014 QualType RetTy = Fn->getReturnType(); in ActOnBlockArguments()
16016 (isa<FunctionProtoType>(Fn) && cast<FunctionProtoType>(Fn)->isVariadic()); in ActOnBlockArguments()
16018 CurBlock->TheDecl->setIsVariadic(isVariadic); in ActOnBlockArguments()
16025 CurBlock->ReturnType = RetTy; in ActOnBlockArguments()
16026 CurBlock->TheDecl->setBlockMissingReturnType(false); in ActOnBlockArguments()
16027 CurBlock->HasImplicitReturnType = false; in ActOnBlockArguments()
16035 if (Param->getIdentifier() == nullptr && !Param->isImplicit() && in ActOnBlockArguments()
16036 !Param->isInvalidDecl() && !getLangOpts().CPlusPlus) { in ActOnBlockArguments()
16039 Diag(Param->getLocation(), diag::ext_parameter_name_omitted_c23); in ActOnBlockArguments()
16046 } else if (const FunctionProtoType *Fn = T->getAs<FunctionProtoType>()) { in ActOnBlockArguments()
16047 for (const auto &I : Fn->param_types()) { in ActOnBlockArguments()
16049 CurBlock->TheDecl, ParamInfo.getBeginLoc(), I); in ActOnBlockArguments()
16056 CurBlock->TheDecl->setParams(Params); in ActOnBlockArguments()
16057 CheckParmsForFunctionDef(CurBlock->TheDecl->parameters(), in ActOnBlockArguments()
16062 ProcessDeclAttributes(CurScope, CurBlock->TheDecl, ParamInfo); in ActOnBlockArguments()
16065 for (auto *AI : CurBlock->TheDecl->parameters()) { in ActOnBlockArguments()
16066 AI->setOwningFunction(CurBlock->TheDecl); in ActOnBlockArguments()
16069 if (AI->getIdentifier()) { in ActOnBlockArguments()
16070 CheckShadow(CurBlock->TheScope, AI); in ActOnBlockArguments()
16072 PushOnScopeChains(AI, CurBlock->TheScope); in ActOnBlockArguments()
16075 if (AI->isInvalidDecl()) in ActOnBlockArguments()
16076 CurBlock->TheDecl->setInvalidDecl(); in ActOnBlockArguments()
16081 // Leave the expression-evaluation context. in ActOnBlockError()
16096 // Leave the expression-evaluation context. in ActOnBlockStmtExpr()
16104 BlockDecl *BD = BSI->TheDecl; in ActOnBlockStmtExpr()
16106 if (BSI->HasImplicitReturnType) in ActOnBlockStmtExpr()
16110 if (!BSI->ReturnType.isNull()) in ActOnBlockStmtExpr()
16111 RetTy = BSI->ReturnType; in ActOnBlockStmtExpr()
16113 bool NoReturn = BD->hasAttr<NoReturnAttr>(); in ActOnBlockStmtExpr()
16117 if (!BSI->FunctionType.isNull()) { in ActOnBlockStmtExpr()
16118 const FunctionType *FTy = BSI->FunctionType->castAs<FunctionType>(); in ActOnBlockStmtExpr()
16120 FunctionType::ExtInfo Ext = FTy->getExtInfo(); in ActOnBlockStmtExpr()
16131 } else if (FTy->getReturnType() == RetTy && in ActOnBlockStmtExpr()
16132 (!NoReturn || FTy->getNoReturnAttr())) { in ActOnBlockStmtExpr()
16133 BlockTy = BSI->FunctionType; in ActOnBlockStmtExpr()
16138 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); in ActOnBlockStmtExpr()
16141 BlockTy = Context.getFunctionType(RetTy, FPT->getParamTypes(), EPI); in ActOnBlockStmtExpr()
16151 DiagnoseUnusedParameters(BD->parameters()); in ActOnBlockStmtExpr()
16155 if (getCurFunction()->NeedsScopeChecking() && in ActOnBlockStmtExpr()
16159 BD->setBody(cast<CompoundStmt>(Body)); in ActOnBlockStmtExpr()
16161 if (Body && getCurFunction()->HasPotentialAvailabilityViolations) in ActOnBlockStmtExpr()
16167 if (getLangOpts().CPlusPlus && RetTy->isRecordType() && in ActOnBlockStmtExpr()
16168 !BD->isDependentContext()) in ActOnBlockStmtExpr()
16173 checkNonTrivialCUnion(RetTy, BD->getCaretLocation(), NTCUC_FunctionReturn, in ActOnBlockStmtExpr()
16180 for (Capture &Cap : BSI->Captures) { in ActOnBlockStmtExpr()
16189 Cap.getCaptureType()->getAs<RecordType>()) { in ActOnBlockStmtExpr()
16198 // Enter a separate potentially-evaluated context while building block in ActOnBlockStmtExpr()
16209 CXXScopeSpec(), DeclarationNameInfo(Var->getDeclName(), Loc), Var); in ActOnBlockStmtExpr()
16215 !Result.get()->getType().isConstQualified()) { in ActOnBlockStmtExpr()
16217 Result.get()->getType().withConst(), in ActOnBlockStmtExpr()
16223 InitializedEntity::InitializeBlock(Var->getLocation(), in ActOnBlockStmtExpr()
16228 // Build a full-expression copy expression if initialization in ActOnBlockStmtExpr()
16229 // succeeded and used a non-trivial constructor. Recover from in ActOnBlockStmtExpr()
16232 !cast<CXXConstructExpr>(Result.get())->getConstructor() in ActOnBlockStmtExpr()
16233 ->isTrivial()) { in ActOnBlockStmtExpr()
16244 BD->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0); in ActOnBlockStmtExpr()
16254 if (Result->getBlockDecl()->hasCaptures()) { in ActOnBlockStmtExpr()
16256 ExprCleanupObjects.push_back(Result->getBlockDecl()); in ActOnBlockStmtExpr()
16259 // It also gets a branch-protected scope if any of the captured in ActOnBlockStmtExpr()
16261 for (const auto &CI : Result->getBlockDecl()->captures()) { in ActOnBlockStmtExpr()
16263 if (var->getType().isDestructedType() != QualType::DK_none) { in ActOnBlockStmtExpr()
16271 getCurFunction()->addBlock(BD); in ActOnBlockStmtExpr()
16273 if (BD->isInvalidDecl()) in ActOnBlockStmtExpr()
16274 return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(), in ActOnBlockStmtExpr()
16275 {Result}, Result->getType()); in ActOnBlockStmtExpr()
16298 return ExprError(Diag(E->getBeginLoc(), diag::err_va_arg_in_device)); in BuildVAArgExpr()
16305 targetDiag(E->getBeginLoc(), diag::err_va_arg_in_device); in BuildVAArgExpr()
16310 if (!E->isTypeDependent() && Context.getTargetInfo().hasBuiltinMSVaList() && in BuildVAArgExpr()
16313 if (Context.hasSameType(MSVaListType, E->getType())) { in BuildVAArgExpr()
16323 if (VaListType->isArrayType()) { in BuildVAArgExpr()
16324 // Deal with implicit array decay; for example, on x86-64, in BuildVAArgExpr()
16333 } else if (VaListType->isRecordType() && getLangOpts().CPlusPlus) { in BuildVAArgExpr()
16343 // Otherwise, the va_list argument must be an l-value because in BuildVAArgExpr()
16345 if (!E->isTypeDependent() && in BuildVAArgExpr()
16351 if (!IsMS && !E->isTypeDependent() && in BuildVAArgExpr()
16352 !Context.hasSameType(VaListType, E->getType())) in BuildVAArgExpr()
16354 Diag(E->getBeginLoc(), in BuildVAArgExpr()
16356 << OrigExpr->getType() << E->getSourceRange()); in BuildVAArgExpr()
16358 if (!TInfo->getType()->isDependentType()) { in BuildVAArgExpr()
16359 if (RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), TInfo->getType(), in BuildVAArgExpr()
16361 TInfo->getTypeLoc())) in BuildVAArgExpr()
16364 if (RequireNonAbstractType(TInfo->getTypeLoc().getBeginLoc(), in BuildVAArgExpr()
16365 TInfo->getType(), in BuildVAArgExpr()
16367 TInfo->getTypeLoc())) in BuildVAArgExpr()
16370 if (!TInfo->getType().isPODType(Context)) { in BuildVAArgExpr()
16371 Diag(TInfo->getTypeLoc().getBeginLoc(), in BuildVAArgExpr()
16372 TInfo->getType()->isObjCLifetimeType() in BuildVAArgExpr()
16375 << TInfo->getType() in BuildVAArgExpr()
16376 << TInfo->getTypeLoc().getSourceRange(); in BuildVAArgExpr()
16382 if (Context.isPromotableIntegerType(TInfo->getType())) { in BuildVAArgExpr()
16383 PromoteType = Context.getPromotedIntegerType(TInfo->getType()); in BuildVAArgExpr()
16389 // - both types are pointers to qualified or unqualified versions of in BuildVAArgExpr()
16391 // - one type is compatible with a signed integer type, the other in BuildVAArgExpr()
16394 // - one type is pointer to qualified or unqualified void and the in BuildVAArgExpr()
16396 // - or, the type of the next argument is nullptr_t and type is a in BuildVAArgExpr()
16405 QualType UnderlyingType = TInfo->getType(); in BuildVAArgExpr()
16406 if (const auto *ET = UnderlyingType->getAs<EnumType>()) in BuildVAArgExpr()
16407 UnderlyingType = ET->getDecl()->getIntegerType(); in BuildVAArgExpr()
16416 if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() && in BuildVAArgExpr()
16417 PromoteType->isUnsignedIntegerType() != in BuildVAArgExpr()
16418 UnderlyingType->isUnsignedIntegerType()) { in BuildVAArgExpr()
16420 UnderlyingType->isUnsignedIntegerType() in BuildVAArgExpr()
16428 if (TInfo->getType()->isSpecificBuiltinType(BuiltinType::Float)) in BuildVAArgExpr()
16431 DiagRuntimeBehavior(TInfo->getTypeLoc().getBeginLoc(), E, in BuildVAArgExpr()
16433 << TInfo->getType() in BuildVAArgExpr()
16435 << TInfo->getTypeLoc().getSourceRange()); in BuildVAArgExpr()
16438 QualType T = TInfo->getType().getNonLValueExprType(Context); in BuildVAArgExpr()
16471 if ((SLDecl->isCompleteDefinition() || SLDecl->isBeingDefined()) && in LookupStdSourceLocationImpl()
16479 if (!ImplDecl || !ImplDecl->isCompleteDefinition()) { in LookupStdSourceLocationImpl()
16486 if (ImplDecl->isUnion() || !ImplDecl->isStandardLayout() || in LookupStdSourceLocationImpl()
16487 ImplDecl->getNumBases() != 0) { in LookupStdSourceLocationImpl()
16493 for (FieldDecl *F : ImplDecl->fields()) { in LookupStdSourceLocationImpl()
16494 StringRef Name = F->getName(); in LookupStdSourceLocationImpl()
16497 if (F->getType() != in LookupStdSourceLocationImpl()
16502 if (F->getType() != in LookupStdSourceLocationImpl()
16507 if (!F->getType()->isIntegerType()) in LookupStdSourceLocationImpl()
16511 if (!F->getType()->isIntegerType()) in LookupStdSourceLocationImpl()
16538 Context.getPointerType(ArrTy->getAsArrayTypeUnsafe()->getElementType()); in ActOnSourceLocExpr()
16571 Data->BinaryData = BinaryData; in ActOnEmbedExpr()
16574 Data->getDataElementCount()); in ActOnEmbedExpr()
16579 if (!DstType->isFunctionPointerType() || in maybeDiagnoseAssignmentToFunction()
16580 !SrcExpr->getType()->isFunctionType()) in maybeDiagnoseAssignmentToFunction()
16583 auto *DRE = dyn_cast<DeclRefExpr>(SrcExpr->IgnoreParenImpCasts()); in maybeDiagnoseAssignmentToFunction()
16587 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()); in maybeDiagnoseAssignmentToFunction()
16593 SrcExpr->getBeginLoc()); in maybeDiagnoseAssignmentToFunction()
16664 CheckInferredResultType = DstType->isObjCObjectPointerType() && in DiagnoseAssignmentResult()
16665 SrcType->isObjCObjectPointerType(); in DiagnoseAssignmentResult()
16691 // Perform array-to-pointer decay if necessary. in DiagnoseAssignmentResult()
16692 if (SrcType->isArrayType()) SrcType = Context.getArrayDecayedType(SrcType); in DiagnoseAssignmentResult()
16696 Qualifiers lhq = SrcType->getPointeeType().getQualifiers(); in DiagnoseAssignmentResult()
16697 Qualifiers rhq = DstType->getPointeeType().getQualifiers(); in DiagnoseAssignmentResult()
16751 if (SrcType->isObjCQualifiedIdType()) { in DiagnoseAssignmentResult()
16753 SrcType->castAs<ObjCObjectPointerType>(); in DiagnoseAssignmentResult()
16754 for (auto *srcProto : srcOPT->quals()) { in DiagnoseAssignmentResult()
16759 DstType->castAs<ObjCObjectPointerType>()->getInterfaceType()) in DiagnoseAssignmentResult()
16760 IFace = IFaceT->getDecl(); in DiagnoseAssignmentResult()
16762 else if (DstType->isObjCQualifiedIdType()) { in DiagnoseAssignmentResult()
16764 DstType->castAs<ObjCObjectPointerType>(); in DiagnoseAssignmentResult()
16765 for (auto *dstProto : dstOPT->quals()) { in DiagnoseAssignmentResult()
16770 SrcType->castAs<ObjCObjectPointerType>()->getInterfaceType()) in DiagnoseAssignmentResult()
16771 IFace = IFaceT->getDecl(); in DiagnoseAssignmentResult()
16835 << SrcExpr->getSourceRange(); in DiagnoseAssignmentResult()
16840 return Type->isSpecificBuiltinType(BuiltinType::Char_S) || in DiagnoseAssignmentResult()
16841 Type->isSpecificBuiltinType(BuiltinType::Char_U); in DiagnoseAssignmentResult()
16843 FDiag << (isPlainChar(FirstType->getPointeeOrArrayElementType()) || in DiagnoseAssignmentResult()
16844 isPlainChar(SecondType->getPointeeOrArrayElementType())); in DiagnoseAssignmentResult()
16861 PDecl && IFace && !IFace->hasDefinition()) in DiagnoseAssignmentResult()
16862 Diag(IFace->getLocation(), diag::note_incomplete_class_and_qualified_id) in DiagnoseAssignmentResult()
16932 SourceLocation DiagLoc = E->getBeginLoc(); in VerifyIntegerConstantExpression()
16938 // have a single non-explicit conversion function to an integral or in VerifyIntegerConstantExpression()
16966 return S.Diag(Conv->getLocation(), diag::note_ice_conversion_here) in VerifyIntegerConstantExpression()
16967 << ConvTy->isEnumeralType() << ConvTy; in VerifyIntegerConstantExpression()
16977 return S.Diag(Conv->getLocation(), diag::note_ice_conversion_here) in VerifyIntegerConstantExpression()
16978 << ConvTy->isEnumeralType() << ConvTy; in VerifyIntegerConstantExpression()
16998 if (!E->getType()->isIntegralOrUnscopedEnumerationType()) in VerifyIntegerConstantExpression()
17000 } else if (!E->getType()->isIntegralOrUnscopedEnumerationType()) { in VerifyIntegerConstantExpression()
17003 Diagnoser.diagnoseNotICEType(*this, DiagLoc, E->getType()) in VerifyIntegerConstantExpression()
17004 << E->getSourceRange(); in VerifyIntegerConstantExpression()
17015 // in the non-ICE case. in VerifyIntegerConstantExpression()
17016 if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) { in VerifyIntegerConstantExpression()
17019 *Result = E->EvaluateKnownConstIntCheckOverflow(Context, &Notes); in VerifyIntegerConstantExpression()
17038 Diagnoser.diagnoseNotICE(*this, DiagLoc) << E->getSourceRange(); in VerifyIntegerConstantExpression()
17045 Diagnoser.diagnoseFold(*this, DiagLoc) << E->getSourceRange(); in VerifyIntegerConstantExpression()
17057 // not a constant expression as a side-effect. in VerifyIntegerConstantExpression()
17059 E->EvaluateAsRValue(EvalResult, Context, /*isConstantContext*/ true) && in VerifyIntegerConstantExpression()
17086 Diagnoser.diagnoseNotICE(*this, DiagLoc) << E->getSourceRange(); in VerifyIntegerConstantExpression()
17094 Diagnoser.diagnoseFold(*this, DiagLoc) << E->getSourceRange(); in VerifyIntegerConstantExpression()
17116 // We need to special-case DeclRefExprs referring to FieldDecls which
17124 if (isa<FieldDecl>(E->getDecl()) && in TransformDeclRefExpr()
17126 return SemaRef.Diag(E->getLocation(), in TransformDeclRefExpr()
17128 << E->getDecl() << E->getSourceRange(); in TransformDeclRefExpr()
17135 if (E->getOpcode() == UO_AddrOf && E->getType()->isMemberPointerType()) in TransformUnaryOperator()
17141 // The body of a lambda-expression is in a separate expression evaluation
17155 ExprEvalContexts[ExprEvalContexts.size()-2].Context; in TransformToPotentiallyEvaluated()
17185 // it is a subexpression of a manifestly constant-evaluated expression or in PushExpressionEvaluationContext()
17210 PossibleDeref = PossibleDeref->IgnoreParenImpCasts(); in CheckPossibleDeref()
17212 if (E->getOpcode() == UO_Deref) in CheckPossibleDeref()
17213 return CheckPossibleDeref(S, E->getSubExpr()); in CheckPossibleDeref()
17215 return CheckPossibleDeref(S, E->getBase()); in CheckPossibleDeref()
17217 return CheckPossibleDeref(S, E->getBase()); in CheckPossibleDeref()
17220 QualType Ty = E->getType(); in CheckPossibleDeref()
17221 if (const auto *Ptr = Ty->getAs<PointerType>()) in CheckPossibleDeref()
17222 Inner = Ptr->getPointeeType(); in CheckPossibleDeref()
17224 Inner = Arr->getElementType(); in CheckPossibleDeref()
17228 if (Inner->hasAttr(attr::NoDeref)) in CheckPossibleDeref()
17240 const ValueDecl *Decl = DeclRef->getDecl(); in WarnOnPendingNoDerefs()
17241 Diag(E->getExprLoc(), diag::warn_dereference_of_noderef_type) in WarnOnPendingNoDerefs()
17242 << Decl->getName() << E->getSourceRange(); in WarnOnPendingNoDerefs()
17243 Diag(Decl->getLocation(), diag::note_previous_decl) << Decl->getName(); in WarnOnPendingNoDerefs()
17245 Diag(E->getExprLoc(), diag::warn_dereference_of_noderef_type_no_decl) in WarnOnPendingNoDerefs()
17246 << E->getSourceRange(); in WarnOnPendingNoDerefs()
17253 if (!E->getType().isVolatileQualified() || !getLangOpts().CPlusPlus20) in CheckUnusedVolatileAssignment()
17259 if (auto *BO = dyn_cast<BinaryOperator>(E->IgnoreParenImpCasts())) { in CheckUnusedVolatileAssignment()
17260 if (BO->getOpcode() == BO_Assign) { in CheckUnusedVolatileAssignment()
17262 llvm::erase(LHSs, BO->getLHS()); in CheckUnusedVolatileAssignment()
17272 if (auto *Call = dyn_cast<CallExpr>(E->IgnoreImplicit()); in MarkExpressionAsImmediateEscalating()
17273 Call && Call->getCallee()) { in MarkExpressionAsImmediateEscalating()
17275 dyn_cast<DeclRefExpr>(Call->getCallee()->IgnoreImplicit())) in MarkExpressionAsImmediateEscalating()
17276 DeclRef->setIsImmediateEscalating(true); in MarkExpressionAsImmediateEscalating()
17277 } else if (auto *Ctr = dyn_cast<CXXConstructExpr>(E->IgnoreImplicit())) { in MarkExpressionAsImmediateEscalating()
17278 Ctr->setIsImmediateEscalating(true); in MarkExpressionAsImmediateEscalating()
17279 } else if (auto *DeclRef = dyn_cast<DeclRefExpr>(E->IgnoreImplicit())) { in MarkExpressionAsImmediateEscalating()
17280 DeclRef->setIsImmediateEscalating(true); in MarkExpressionAsImmediateEscalating()
17285 FI->FoundImmediateEscalatingExpression = true; in MarkExpressionAsImmediateEscalating()
17290 !Decl->isImmediateFunction() || isAlwaysConstantEvaluatedContext() || in CheckForImmediateInvocation()
17299 if (auto *Call = dyn_cast<CallExpr>(E.get()->IgnoreImplicit())) in CheckForImmediateInvocation()
17301 dyn_cast<DeclRefExpr>(Call->getCallee()->IgnoreImplicit())) in CheckForImmediateInvocation()
17305 // An expression or conversion is immediate-escalating if it is not initially in CheckForImmediateInvocation()
17314 bool Res = E.get()->EvaluateAsConstantExpr( in CheckForImmediateInvocation()
17323 if (!E.get()->isValueDependent() && in CheckForImmediateInvocation()
17331 // Since an immediate invocation is a full expression itself - it requires in CheckForImmediateInvocation()
17339 // - compound literals do not create cleanup objects in C++ and immediate in CheckForImmediateInvocation()
17340 // invocations are C++-only. in CheckForImmediateInvocation()
17341 // - blocks are not allowed inside constant expressions and compiler will in CheckForImmediateInvocation()
17352 ConstantExpr::getStorageKind(Decl->getReturnType().getTypePtr(), in CheckForImmediateInvocation()
17356 Res->MoveIntoResult(Cached, getASTContext()); in CheckForImmediateInvocation()
17357 /// Value-dependent constant expressions should not be immediately in CheckForImmediateInvocation()
17359 if (!Res->isValueDependent()) in CheckForImmediateInvocation()
17370 bool Result = CE->EvaluateAsConstantExpr( in EvaluateAndDiagnoseImmediateInvocation()
17374 Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); in EvaluateAndDiagnoseImmediateInvocation()
17376 InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit(); in EvaluateAndDiagnoseImmediateInvocation()
17379 FD = cast<FunctionDecl>(Call->getCalleeDecl()); in EvaluateAndDiagnoseImmediateInvocation()
17381 FD = Call->getConstructor(); in EvaluateAndDiagnoseImmediateInvocation()
17383 FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction()); in EvaluateAndDiagnoseImmediateInvocation()
17385 assert(FD && FD->isImmediateFunction() && in EvaluateAndDiagnoseImmediateInvocation()
17387 if (FD->isInvalidDecl()) in EvaluateAndDiagnoseImmediateInvocation()
17389 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call) in EvaluateAndDiagnoseImmediateInvocation()
17390 << FD << FD->isConsteval(); in EvaluateAndDiagnoseImmediateInvocation()
17393 SemaRef.Diag(Context->Loc, diag::note_invalid_consteval_initializer) in EvaluateAndDiagnoseImmediateInvocation()
17394 << Context->Decl; in EvaluateAndDiagnoseImmediateInvocation()
17395 SemaRef.Diag(Context->Decl->getBeginLoc(), diag::note_declared_at); in EvaluateAndDiagnoseImmediateInvocation()
17397 if (!FD->isConsteval()) in EvaluateAndDiagnoseImmediateInvocation()
17403 CE->MoveIntoResult(Eval.Val, SemaRef.getASTContext()); in EvaluateAndDiagnoseImmediateInvocation()
17431 CurrentII->setInt(1); in RemoveNestedImmediateInvocation()
17433 It->setInt(1); // Mark as deleted in RemoveNestedImmediateInvocation()
17437 if (!E->isImmediateInvocation()) in RemoveNestedImmediateInvocation()
17440 return Base::TransformExpr(E->getSubExpr()); in RemoveNestedImmediateInvocation()
17445 DRSet.erase(cast<DeclRefExpr>(E->getCallee()->IgnoreImplicit())); in RemoveNestedImmediateInvocation()
17459 if (CE->isImmediateInvocation()) in RemoveNestedImmediateInvocation()
17485 /// can only occur for the top-level CXXConstructExpr because it is used in RemoveNestedImmediateInvocation()
17489 if (isa<CXXConstructExpr>(It->getPointer()->IgnoreImplicit())) in RemoveNestedImmediateInvocation()
17492 ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr()); in RemoveNestedImmediateInvocation()
17498 It->getPointer()->setSubExpr(Res.get()); in RemoveNestedImmediateInvocation()
17528 if (!It->getInt()) in HandleImmediateInvocations()
17541 Rec.ImmediateInvocationCandidates.front().getPointer()->getSubExpr()); in HandleImmediateInvocations()
17550 if (DR->isImmediateEscalating()) in HandleImmediateInvocations()
17552 auto *FD = cast<FunctionDecl>(DR->getDecl()); in HandleImmediateInvocations()
17555 MD && (MD->isLambdaStaticInvoker() || isLambdaCallOperator(MD))) in HandleImmediateInvocations()
17556 ND = MD->getParent(); in HandleImmediateInvocations()
17559 // An expression or conversion is immediate-escalating if it is not in HandleImmediateInvocations()
17561 // potentially-evaluated id-expression that denotes an immediate function in HandleImmediateInvocations()
17574 SemaRef.Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address) in HandleImmediateInvocations()
17575 << ND << isa<CXXRecordDecl>(ND) << FD->isConsteval(); in HandleImmediateInvocations()
17576 SemaRef.Diag(ND->getLocation(), diag::note_declared_at); in HandleImmediateInvocations()
17579 SemaRef.Diag(Context->Loc, diag::note_invalid_consteval_initializer) in HandleImmediateInvocations()
17580 << Context->Decl; in HandleImmediateInvocations()
17581 SemaRef.Diag(Context->Decl->getBeginLoc(), diag::note_declared_at); in HandleImmediateInvocations()
17583 if (FD->isImmediateEscalating() && !FD->isConsteval()) in HandleImmediateInvocations()
17605 // A lambda-expression shall not appear in an unevaluated operand in PopExpressionEvaluationContext()
17610 // A conditional-expression e is a core constant expression unless the in PopExpressionEvaluationContext()
17612 // evaluate [...] a lambda-expression. in PopExpressionEvaluationContext()
17616 // A lambda-expression shall not appear [...] in a template-argument. in PopExpressionEvaluationContext()
17621 for (const auto *L : Rec.Lambdas) in PopExpressionEvaluationContext() local
17622 Diag(L->getBeginLoc(), D); in PopExpressionEvaluationContext()
17639 // Warn on any volatile-qualified simple-assignments that are not discarded- in PopExpressionEvaluationContext()
17643 Diag(BO->getBeginLoc(), diag::warn_deprecated_simple_assign_volatile) in PopExpressionEvaluationContext()
17644 << BO->getType(); in PopExpressionEvaluationContext()
17683 if (!E->getType()->isVariablyModifiedType()) in HandleExprEvaluationContextForTypeof()
17691 /// C++2a [expr.const]p12: in isPotentiallyConstantEvaluatedContext()
17697 // -- a manifestly constant-evaluated expression, in isPotentiallyConstantEvaluatedContext()
17701 // -- a potentially-evaluated expression, in isPotentiallyConstantEvaluatedContext()
17703 // -- an immediate subexpression of a braced-init-list, in isPotentiallyConstantEvaluatedContext()
17705 // -- [FIXME] an expression of the form & cast-expression that occurs in isPotentiallyConstantEvaluatedContext()
17707 // -- a subexpression of one of the above that is not a subexpression of in isPotentiallyConstantEvaluatedContext()
17722 // These manglings don't do anything on non-Windows or non-x86 platforms, so in funcHasParameterSizeMangling()
17731 if (S.getLangOpts().CPlusPlus && !FD->isExternC()) in funcHasParameterSizeMangling()
17735 CallingConv CC = FD->getType()->castAs<FunctionType>()->getCallConv(); in funcHasParameterSizeMangling()
17766 CallingConv CC = FD->getType()->castAs<FunctionType>()->getCallConv(); in CheckCompleteParameterTypesForMangler()
17783 << Param->getDeclName() << FD->getDeclName() << CCName; in CheckCompleteParameterTypesForMangler()
17787 for (ParmVarDecl *Param : FD->parameters()) { in CheckCompleteParameterTypesForMangler()
17789 S.RequireCompleteType(Loc, Param->getType(), Diagnoser); in CheckCompleteParameterTypesForMangler()
17795 /// Declarations in this context are not odr-used.
17797 /// Declarations in this context are formally odr-used, but this is a
17800 /// Declarations in this context are odr-used but not actually used (yet).
17808 /// variables result in odr-use?
17829 // A default argument formally results in odr-use, but doesn't actually in isOdrUseContext()
17835 if (SemaRef.CurContext->isDependentContext()) in isOdrUseContext()
17842 if (!Func->isConstexpr()) in isImplicitlyDefinableConstexprFunction()
17845 if (Func->isImplicitlyInstantiable() || !Func->isUserProvided()) in isImplicitlyDefinableConstexprFunction()
17848 return CCD && CCD->getInheritedConstructor(); in isImplicitlyDefinableConstexprFunction()
17855 Func->setReferenced(); in MarkFunctionReferenced()
17862 // A function whose name appears as a potentially-evaluated expression is in MarkFunctionReferenced()
17863 // odr-used if it is the unique lookup result or the selected member of a in MarkFunctionReferenced()
17875 if (Func->isTrivial() && !Func->hasAttr<DLLExportAttr>() && in MarkFunctionReferenced()
17878 if (Constructor->isDefaultConstructor()) in MarkFunctionReferenced()
17903 // Every program shall contain exactly one definition of every non-inline in MarkFunctionReferenced()
17904 // function or variable that is odr-used in that program outside of a in MarkFunctionReferenced()
17908 // if they are odr-used or needed for constant evaluation. in MarkFunctionReferenced()
17912 // This is formally non-conforming, but seems reasonable in practice. in MarkFunctionReferenced()
17916 (NeededForConstantEvaluation && !Func->isPureVirtual())); in MarkFunctionReferenced()
17924 (Func->getTemplateSpecializationKind() != TSK_Undeclared || in MarkFunctionReferenced()
17925 Func->getMemberSpecializationInfo())) in MarkFunctionReferenced()
17932 if (NeedDefinition && !Func->getBody()) { in MarkFunctionReferenced()
17936 Constructor = cast<CXXConstructorDecl>(Constructor->getFirstDecl()); in MarkFunctionReferenced()
17937 if (Constructor->isDefaulted() && !Constructor->isDeleted()) { in MarkFunctionReferenced()
17938 if (Constructor->isDefaultConstructor()) { in MarkFunctionReferenced()
17939 if (Constructor->isTrivial() && in MarkFunctionReferenced()
17940 !Constructor->hasAttr<DLLExportAttr>()) in MarkFunctionReferenced()
17943 } else if (Constructor->isCopyConstructor()) { in MarkFunctionReferenced()
17945 } else if (Constructor->isMoveConstructor()) { in MarkFunctionReferenced()
17948 } else if (Constructor->getInheritedConstructor()) { in MarkFunctionReferenced()
17953 Destructor = cast<CXXDestructorDecl>(Destructor->getFirstDecl()); in MarkFunctionReferenced()
17954 if (Destructor->isDefaulted() && !Destructor->isDeleted()) { in MarkFunctionReferenced()
17955 if (Destructor->isTrivial() && !Destructor->hasAttr<DLLExportAttr>()) in MarkFunctionReferenced()
17959 if (Destructor->isVirtual() && getLangOpts().AppleKext) in MarkFunctionReferenced()
17960 MarkVTableUsed(Loc, Destructor->getParent()); in MarkFunctionReferenced()
17962 if (MethodDecl->isOverloadedOperator() && in MarkFunctionReferenced()
17963 MethodDecl->getOverloadedOperator() == OO_Equal) { in MarkFunctionReferenced()
17964 MethodDecl = cast<CXXMethodDecl>(MethodDecl->getFirstDecl()); in MarkFunctionReferenced()
17965 if (MethodDecl->isDefaulted() && !MethodDecl->isDeleted()) { in MarkFunctionReferenced()
17966 if (MethodDecl->isCopyAssignmentOperator()) in MarkFunctionReferenced()
17968 else if (MethodDecl->isMoveAssignmentOperator()) in MarkFunctionReferenced()
17972 MethodDecl->getParent()->isLambda()) { in MarkFunctionReferenced()
17974 cast<CXXConversionDecl>(MethodDecl->getFirstDecl()); in MarkFunctionReferenced()
17975 if (Conversion->isLambdaToBlockPointerConversion()) in MarkFunctionReferenced()
17979 } else if (MethodDecl->isVirtual() && getLangOpts().AppleKext) in MarkFunctionReferenced()
17980 MarkVTableUsed(Loc, MethodDecl->getParent()); in MarkFunctionReferenced()
17983 if (Func->isDefaulted() && !Func->isDeleted()) { in MarkFunctionReferenced()
17991 if (Func->isImplicitlyInstantiable()) { in MarkFunctionReferenced()
17993 Func->getTemplateSpecializationKindForInstantiation(); in MarkFunctionReferenced()
17994 SourceLocation PointOfInstantiation = Func->getPointOfInstantiation(); in MarkFunctionReferenced()
17998 if (auto *MSI = Func->getMemberSpecializationInfo()) in MarkFunctionReferenced()
17999 MSI->setPointOfInstantiation(Loc); in MarkFunctionReferenced()
18002 Func->setTemplateSpecializationKind(TSK, PointOfInstantiation); in MarkFunctionReferenced()
18011 Func->isConstexpr()) { in MarkFunctionReferenced()
18012 if (isa<CXXRecordDecl>(Func->getDeclContext()) && in MarkFunctionReferenced()
18013 cast<CXXRecordDecl>(Func->getDeclContext())->isLocalClass() && in MarkFunctionReferenced()
18017 else if (Func->isConstexpr()) in MarkFunctionReferenced()
18023 Func->setInstantiationIsPending(true); in MarkFunctionReferenced()
18032 for (auto *i : Func->redecls()) { in MarkFunctionReferenced()
18033 if (!i->isUsed(false) && i->isImplicitlyInstantiable()) in MarkFunctionReferenced()
18046 Constructor->isImmediateFunction() in MarkFunctionReferenced()
18050 for (CXXCtorInitializer *Init : Constructor->inits()) { in MarkFunctionReferenced()
18051 if (Init->isInClassMemberInitializer()) in MarkFunctionReferenced()
18052 runWithSufficientStackSpace(Init->getSourceLocation(), [&]() { in MarkFunctionReferenced()
18053 MarkDeclarationsReferencedInExpr(Init->getInit()); in MarkFunctionReferenced()
18059 // An exception-specification is considered to be needed when: in MarkFunctionReferenced()
18060 // - the function is odr-used or, if it appears in an unevaluated operand, in MarkFunctionReferenced()
18061 // would be odr-used if the expression were potentially-evaluated; in MarkFunctionReferenced()
18067 const FunctionProtoType *FPT = Func->getType()->getAs<FunctionProtoType>(); in MarkFunctionReferenced()
18068 if (FPT && isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) in MarkFunctionReferenced()
18079 if (OdrUse == OdrUseContext::Used && !Func->isUsed(/*CheckUsedAttr=*/false)) { in MarkFunctionReferenced()
18081 if (!Func->isDefined()) { in MarkFunctionReferenced()
18083 UndefinedButUsed.insert(std::make_pair(Func->getCanonicalDecl(), Loc)); in MarkFunctionReferenced()
18084 else if (Func->getMostRecentDecl()->isInlined() && in MarkFunctionReferenced()
18086 !Func->getMostRecentDecl()->hasAttr<GNUInlineAttr>()) in MarkFunctionReferenced()
18087 UndefinedButUsed.insert(std::make_pair(Func->getCanonicalDecl(), Loc)); in MarkFunctionReferenced()
18089 UndefinedButUsed.insert(std::make_pair(Func->getCanonicalDecl(), Loc)); in MarkFunctionReferenced()
18106 CXXRecordDecl *Parent = Dtor->getParent(); in MarkFunctionReferenced()
18107 if (Parent->getNumVBases() > 0 && !Dtor->getBody()) in MarkFunctionReferenced()
18112 Func->markUsed(Context); in MarkFunctionReferenced()
18116 /// Directly mark a variable odr-used. Given a choice, prefer to use
18120 /// - if FunctionScopeIndexToStopAt is null, capture it in the CurContext
18121 /// - else capture it in the DeclContext that maps to the
18128 VarDecl *Var = V->getPotentiallyDecomposedVarDecl(); in MarkVarDeclODRUsed()
18131 if (Var->hasDefinition(SemaRef.Context) == VarDecl::DeclarationOnly && in MarkVarDeclODRUsed()
18132 (!Var->isExternallyVisible() || Var->isInline() || in MarkVarDeclODRUsed()
18134 !(Var->isStaticDataMember() && Var->hasInit())) { in MarkVarDeclODRUsed()
18135 SourceLocation &old = SemaRef.UndefinedButUsed[Var->getCanonicalDecl()]; in MarkVarDeclODRUsed()
18147 if (SemaRef.LangOpts.CUDA && Var->hasGlobalStorage()) { in MarkVarDeclODRUsed()
18155 // Diagnose ODR-use of host global variables in device functions. in MarkVarDeclODRUsed()
18160 << /*host*/ 2 << /*variable*/ 1 << Var in MarkVarDeclODRUsed()
18162 SemaRef.targetDiag(Var->getLocation(), in MarkVarDeclODRUsed()
18163 Var->getType().isConstQualified() in MarkVarDeclODRUsed()
18168 !Var->hasAttr<CUDASharedAttr>() && in MarkVarDeclODRUsed()
18171 // Record a CUDA/HIP device side variable if it is ODR-used in MarkVarDeclODRUsed()
18174 // - a non-function context in MarkVarDeclODRUsed()
18175 // - a host function in MarkVarDeclODRUsed()
18176 // - a host device function in MarkVarDeclODRUsed()
18177 // This makes the ODR-use of the device side variable by host code to in MarkVarDeclODRUsed()
18180 // externalize the static device side variable ODR-used by host code. in MarkVarDeclODRUsed()
18181 if (!Var->hasExternalStorage()) in MarkVarDeclODRUsed()
18184 (!FD || (!FD->getDescribedFunctionTemplate() && in MarkVarDeclODRUsed()
18191 V->markUsed(SemaRef.Context); in MarkVarDeclODRUsed()
18202 DeclContext *VarDC = var->getDeclContext(); in diagnoseUncapturableValueReferenceOrBinding()
18212 // right now; it's impossible to write a non-constant expression outside of in diagnoseUncapturableValueReferenceOrBinding()
18218 if (!S.getLangOpts().CPlusPlus && !S.CurContext->isFunctionOrMethod()) in diagnoseUncapturableValueReferenceOrBinding()
18224 cast<CXXRecordDecl>(VarDC->getParent())->isLambda()) { in diagnoseUncapturableValueReferenceOrBinding()
18225 ContextKind = 2; in diagnoseUncapturableValueReferenceOrBinding()
18234 S.Diag(var->getLocation(), diag::note_entity_declared_at) in diagnoseUncapturableValueReferenceOrBinding()
18247 if (CSI->CaptureMap.count(Var)) { in isVariableAlreadyCapturedInScopeInfo()
18252 CaptureType = CSI->getCapture(Var).getCaptureType(); in isVariableAlreadyCapturedInScopeInfo()
18258 // are mutable in the sense that user can change their value - they are in isVariableAlreadyCapturedInScopeInfo()
18260 const Capture &Cap = CSI->getCapture(Var); in isVariableAlreadyCapturedInScopeInfo()
18263 !cast<LambdaScopeInfo>(CSI)->lambdaCaptureShouldBeConst()) && in isVariableAlreadyCapturedInScopeInfo()
18265 cast<CapturedRegionScopeInfo>(CSI)->CapRegionKind == CR_OpenMP)) in isVariableAlreadyCapturedInScopeInfo()
18282 VarDecl *Underlying = Var->getPotentiallyDecomposedVarDecl(); in getParentOfCapturingContextOrNull()
18284 if (Underlying->hasLocalStorage() && Diagnose) in getParentOfCapturingContextOrNull()
18307 if (IsLambda && !Var->getDeclName()) { in isVariableCapturable()
18310 S.Diag(Var->getLocation(), diag::note_declared_at); in isVariableCapturable()
18315 // Prohibit variably-modified types in blocks; they're difficult to deal with. in isVariableCapturable()
18316 if (Var->getType()->isVariablyModifiedType() && IsBlock) { in isVariableCapturable()
18319 S.Diag(Var->getLocation(), diag::note_previous_decl) << Var; in isVariableCapturable()
18325 if (const RecordType *VTTy = Var->getType()->getAs<RecordType>()) { in isVariableCapturable()
18326 if (VTTy->getDecl()->hasFlexibleArrayMember()) { in isVariableCapturable()
18332 S.Diag(Var->getLocation(), diag::note_previous_decl) << Var; in isVariableCapturable()
18337 const bool HasBlocksAttr = Var->hasAttr<BlocksAttr>(); in isVariableCapturable()
18343 S.Diag(Var->getLocation(), diag::note_previous_decl) << Var; in isVariableCapturable()
18349 Var->getType()->isBlockPointerType()) { in isVariableCapturable()
18365 S.Diag(Var->getLocation(), diag::note_entity_declared_at) << Var; in isVariableCapturable()
18382 if (!Invalid && !S.getLangOpts().OpenCL && CaptureType->isArrayType()) { in captureInBlock()
18385 S.Diag(Var->getLocation(), diag::note_previous_decl) << Var; in captureInBlock()
18392 // Forbid the block-capture of autoreleasing variables. in captureInBlock()
18398 S.Diag(Var->getLocation(), diag::note_previous_decl) << Var; in captureInBlock()
18406 if (const auto *PT = CaptureType->getAs<PointerType>()) { in captureInBlock()
18407 QualType PointeeTy = PT->getPointeeType(); in captureInBlock()
18409 if (!Invalid && PointeeTy->getAs<ObjCObjectPointerType>() && in captureInBlock()
18413 SourceLocation VarLoc = Var->getLocation(); in captureInBlock()
18420 const bool HasBlocksAttr = Var->hasAttr<BlocksAttr>(); in captureInBlock()
18421 if (HasBlocksAttr || CaptureType->isReferenceType() || in captureInBlock()
18434 BSI->addCapture(Var, HasBlocksAttr, ByRef, Nested, Loc, SourceLocation(), in captureInBlock()
18450 } else if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) { in captureInCapturedRegion()
18460 if (S.OpenMP().isOpenMPPrivateDecl(Var, RSI->OpenMPLevel, in captureInCapturedRegion()
18461 RSI->OpenMPCaptureLevel) != OMPC_unknown) in captureInCapturedRegion()
18463 ByRef = S.OpenMP().isOpenMPCapturedByRef(Var, RSI->OpenMPLevel, in captureInCapturedRegion()
18464 RSI->OpenMPCaptureLevel); in captureInCapturedRegion()
18474 RSI->addCapture(Var, /*isBlock*/ false, ByRef, RefersToCapturedVariable, in captureInCapturedRegion()
18493 ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref); in captureInLambda()
18507 // unspecified whether additional unnamed non-static data in captureInLambda()
18519 // For each entity captured by copy, an unnamed non-static in captureInLambda()
18527 // function. - end note ] in captureInLambda()
18528 if (const ReferenceType *RefType = CaptureType->getAs<ReferenceType>()){ in captureInLambda()
18529 if (!RefType->getPointeeType()->isFunctionType()) in captureInLambda()
18530 CaptureType = RefType->getPointeeType(); in captureInLambda()
18533 // Forbid the lambda copy-capture of autoreleasing variables. in captureInLambda()
18538 S.Diag(Var->getLocation(), diag::note_previous_decl) in captureInLambda()
18539 << Var->getDeclName(); in captureInLambda()
18546 // Make sure that by-copy captures are of a complete and non-abstract type. in captureInLambda()
18548 if (!CaptureType->isDependentType() && in captureInLambda()
18552 Var->getDeclName())) in captureInLambda()
18565 // The closure type for a lambda-expression has a public inline in captureInLambda()
18567 // declared const (9.3.1) if and only if the lambda-expression's in captureInLambda()
18568 // parameter-declaration-clause is not followed by mutable. in captureInLambda()
18570 bool Const = LSI->lambdaCaptureShouldBeConst(); in captureInLambda()
18571 if (Const && !CaptureType->isReferenceType()) in captureInLambda()
18577 LSI->addCapture(Var, /*isBlock=*/false, ByRef, RefersToCapturedVariable, in captureInLambda()
18586 if (Var->getType()->isDependentType()) in canCaptureVariableByCopy()
18588 QualType T = Var->getType().getNonReferenceType(); in canCaptureVariableByCopy()
18591 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) { in canCaptureVariableByCopy()
18593 if (!(RD = RD->getDefinition())) in canCaptureVariableByCopy()
18595 if (RD->hasSimpleCopyConstructor()) in canCaptureVariableByCopy()
18597 if (RD->hasUserDeclaredCopyConstructor()) in canCaptureVariableByCopy()
18598 for (CXXConstructorDecl *Ctor : RD->ctors()) in canCaptureVariableByCopy()
18599 if (Ctor->isCopyConstructor()) in canCaptureVariableByCopy()
18600 return !Ctor->isDeleted(); in canCaptureVariableByCopy()
18605 /// Create up to 4 fix-its for explicit reference and value capture of \p Var or
18607 /// standard, for example we can't emit a default copy capture fix-it if we
18611 assert(LSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None); in buildLambdaCaptureFixit()
18617 StringRef Separator = LSI->NumExplicitCaptures > 0 ? ", " : ""; in buildLambdaCaptureFixit()
18618 if (Var->getDeclName().isIdentifier() && !Var->getName().empty()) { in buildLambdaCaptureFixit()
18619 SourceLocation VarInsertLoc = LSI->IntroducerRange.getEnd(); in buildLambdaCaptureFixit()
18622 // [] -> [VarName] in buildLambdaCaptureFixit()
18623 // [OtherCapture] -> [OtherCapture, VarName] in buildLambdaCaptureFixit()
18624 FixBuffer.assign({Separator, Var->getName()}); in buildLambdaCaptureFixit()
18630 FixBuffer.assign({Separator, "&", Var->getName()}); in buildLambdaCaptureFixit()
18642 if (llvm::any_of(LSI->Captures, [](Capture &C) { in buildLambdaCaptureFixit()
18650 LSI->IntroducerRange.getBegin().getLocWithOffset(1); in buildLambdaCaptureFixit()
18656 if (LSI->isCXXThisCaptured() && !Sema.getLangOpts().CPlusPlus20) in buildLambdaCaptureFixit()
18658 ? LSI->getCXXThisCapture().isCopyCapture() in buildLambdaCaptureFixit()
18662 if (CanDefaultCopyCapture && llvm::none_of(LSI->Captures, [](Capture &C) { in buildLambdaCaptureFixit()
18674 if (llvm::none_of(LSI->Captures, [](Capture &C) { in buildLambdaCaptureFixit()
18689 // An init-capture is notionally from the context surrounding its in tryCaptureVariable()
18691 DeclContext *VarDC = Var->getDeclContext(); in tryCaptureVariable()
18695 while (DC->isRequiresExprBody()) in tryCaptureVariable()
18696 DC = DC->getParent(); in tryCaptureVariable()
18699 // it can therefore have non-negigible impact on performances. in tryCaptureVariable()
18707 // in an out-of-bounds error while traversing DC and its parents. in tryCaptureVariable()
18708 if (isa<ParmVarDecl>(Var) && !VarDC->isFunctionOrMethod()) in tryCaptureVariable()
18713 if (VD->isInitCapture()) in tryCaptureVariable()
18714 VarDC = VarDC->getParent(); in tryCaptureVariable()
18716 VD = Var->getPotentiallyDecomposedVarDecl(); in tryCaptureVariable()
18721 ? *FunctionScopeIndexToStopAt : FunctionScopes.size() - 1; in tryCaptureVariable()
18725 unsigned FSIndex = FunctionScopes.size() - 1; in tryCaptureVariable()
18728 --FSIndex; in tryCaptureVariable()
18734 bool IsGlobal = !VD->hasLocalStorage(); in tryCaptureVariable()
18741 Var = cast<VarDecl>(Var->getCanonicalDecl()); in tryCaptureVariable()
18746 // capture of that variable. We start from the innermost capturing-entity in tryCaptureVariable()
18747 // (the DC) and ensure that all intervening capturing-entities in tryCaptureVariable()
18751 CaptureType = Var->getType(); in tryCaptureVariable()
18764 !LSI || LSI->AfterParameterList || CurContext == LSI->CallOperator; in tryCaptureVariable()
18766 if (LSI && !LSI->AfterParameterList) { in tryCaptureVariable()
18769 if (isa<ParmVarDecl>(Var) && !Var->getDeclContext()->isFunctionOrMethod()) in tryCaptureVariable()
18782 ? DC->getParent() in tryCaptureVariable()
18786 // private-captured a global variable, we need to recursively capture it in in tryCaptureVariable()
18790 FunctionScopesIndex = MaxFunctionScopesIndex - 1; in tryCaptureVariable()
18802 CSI->getCapture(Var).markUsed(BuildAndDiagnose); in tryCaptureVariable()
18810 Parm && Parm->getDeclContext() == DC) in tryCaptureVariable()
18820 if (LSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None) { in tryCaptureVariable()
18822 Diag(Var->getLocation(), diag::note_previous_decl) << Var; in tryCaptureVariable()
18823 Diag(LSI->Lambda->getBeginLoc(), diag::note_lambda_decl); in tryCaptureVariable()
18831 // Try to capture variable-length arrays types. in tryCaptureVariable()
18832 if (Var->getType()->isVariablyModifiedType()) { in tryCaptureVariable()
18835 QualType QTy = Var->getType(); in tryCaptureVariable()
18837 QTy = PVD->getOriginalType(); in tryCaptureVariable()
18846 if (RSI->CapRegionKind == CR_OpenMP) { in tryCaptureVariable()
18851 Diag(Var->getLocation(), diag::note_entity_declared_at) << Var; in tryCaptureVariable()
18856 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel); in tryCaptureVariable()
18862 Var->getType()->isVariablyModifiedType()) { in tryCaptureVariable()
18863 QualType QTy = Var->getType(); in tryCaptureVariable()
18865 QTy = PVD->getOriginalType(); in tryCaptureVariable()
18867 E = OpenMP().getNumberOfConstructScopes(RSI->OpenMPLevel); in tryCaptureVariable()
18870 FunctionScopes[FunctionScopesIndex - I]); in tryCaptureVariable()
18871 assert(RSI->OpenMPLevel == OuterRSI->OpenMPLevel && in tryCaptureVariable()
18879 OpenMP().isOpenMPTargetCapturedDecl(Var, RSI->OpenMPLevel, in tryCaptureVariable()
18880 RSI->OpenMPCaptureLevel); in tryCaptureVariable()
18884 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel); in tryCaptureVariable()
18891 RSI->OpenMPLevel); in tryCaptureVariable()
18907 if (CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None && !Explicit) { in tryCaptureVariable()
18908 // No capture-default, and this is not an explicit capture in tryCaptureVariable()
18912 Diag(Var->getLocation(), diag::note_previous_decl) << Var; in tryCaptureVariable()
18914 if (LSI->Lambda) { in tryCaptureVariable()
18915 Diag(LSI->Lambda->getBeginLoc(), diag::note_lambda_decl); in tryCaptureVariable()
18920 // should have the inner lambda do the explicit capture - because in tryCaptureVariable()
18925 // - create const bool VariableCaptureWasInitiallyExplicit = Explicit in tryCaptureVariable()
18927 // - cache the StartingDeclContext - this must be a lambda in tryCaptureVariable()
18928 // - captureInLambda in the innermost lambda the variable. in tryCaptureVariable()
18933 FunctionScopesIndex--; in tryCaptureVariable()
18936 } while (!VarDC->Equals(DC)); in tryCaptureVariable()
18939 // computing the type of the capture at each step, checking type-specific in tryCaptureVariable()
18956 // capturing in nested contexts to suppress any follow-on diagnostics. in tryCaptureVariable()
18967 Kind, /*IsTopScope*/ I == N - 1, *this, Invalid); in tryCaptureVariable()
18974 /*IsTopScope*/ I == N - 1, *this, Invalid); in tryCaptureVariable()
19024 CopiedTemplateArgs(RefExpr *E) : HasArgs(E->hasExplicitTemplateArgs()) { in CopiedTemplateArgs()
19026 E->copyTemplateArgumentsInto(TemplateArgStorage); in CopiedTemplateArgs()
19041 /// non-odr-uses if they satisfy the side-conditions of the NonOdrUseReason.
19047 // Per C++11 [basic.def.odr], a variable is odr-used "unless it is in rebuildPotentialResultsAsNonOdrUsed()
19049 // constant expression (5.19) and the lvalue-to-rvalue conversion (4.1) in rebuildPotentialResultsAsNonOdrUsed()
19050 // is immediately applied." This function handles the lvalue-to-rvalue in rebuildPotentialResultsAsNonOdrUsed()
19053 // If we encounter a node that claims to be an odr-use but shouldn't be, we in rebuildPotentialResultsAsNonOdrUsed()
19054 // transform it into the relevant kind of non-odr-use node and rebuild the in rebuildPotentialResultsAsNonOdrUsed()
19057 // This is a mini-TreeTransform that only transforms a restricted subset of in rebuildPotentialResultsAsNonOdrUsed()
19067 // Any entity other than a VarDecl is always odr-used whenever it's named in rebuildPotentialResultsAsNonOdrUsed()
19068 // in a potentially-evaluated expression. in rebuildPotentialResultsAsNonOdrUsed()
19073 // C++2a [basic.def.odr]p4: in rebuildPotentialResultsAsNonOdrUsed()
19074 // A variable x whose name appears as a potentially-evalauted expression in rebuildPotentialResultsAsNonOdrUsed()
19075 // e is odr-used by e unless in rebuildPotentialResultsAsNonOdrUsed()
19076 // -- x is a reference that is usable in constant expressions, or in rebuildPotentialResultsAsNonOdrUsed()
19077 // -- x is a variable of non-reference type that is usable in constant in rebuildPotentialResultsAsNonOdrUsed()
19080 // non-volatile-qualified non-class type to which the lvalue-to-rvalue in rebuildPotentialResultsAsNonOdrUsed()
19082 // -- x is a variable of non-reference type, and e is an element of the in rebuildPotentialResultsAsNonOdrUsed()
19083 // set of potential results of a discarded-value expression to which in rebuildPotentialResultsAsNonOdrUsed()
19084 // the lvalue-to-rvalue conversion is not applied in rebuildPotentialResultsAsNonOdrUsed()
19086 // We check the first bullet and the "potentially-evaluated" condition in in rebuildPotentialResultsAsNonOdrUsed()
19092 llvm_unreachable("unexpected non-odr-use-reason"); in rebuildPotentialResultsAsNonOdrUsed()
19096 if (VD->getType()->isReferenceType()) in rebuildPotentialResultsAsNonOdrUsed()
19098 if (auto *RD = VD->getType()->getAsCXXRecordDecl()) in rebuildPotentialResultsAsNonOdrUsed()
19099 if (RD->hasMutableFields()) in rebuildPotentialResultsAsNonOdrUsed()
19101 if (!VD->isUsableInConstantExpressions(S.Context)) in rebuildPotentialResultsAsNonOdrUsed()
19106 if (VD->getType()->isReferenceType()) in rebuildPotentialResultsAsNonOdrUsed()
19113 // Mark that this expression does not constitute an odr-use. in rebuildPotentialResultsAsNonOdrUsed()
19117 LSI->markVariableExprAsNonODRUsed(E); in rebuildPotentialResultsAsNonOdrUsed()
19120 // C++2a [basic.def.odr]p2: in rebuildPotentialResultsAsNonOdrUsed()
19122 switch (E->getStmtClass()) { in rebuildPotentialResultsAsNonOdrUsed()
19123 // -- If e is an id-expression, ... in rebuildPotentialResultsAsNonOdrUsed()
19126 if (DRE->isNonOdrUse() || IsPotentialResultOdrUsed(DRE->getDecl())) in rebuildPotentialResultsAsNonOdrUsed()
19129 // Rebuild as a non-odr-use DeclRefExpr. in rebuildPotentialResultsAsNonOdrUsed()
19132 S.Context, DRE->getQualifierLoc(), DRE->getTemplateKeywordLoc(), in rebuildPotentialResultsAsNonOdrUsed()
19133 DRE->getDecl(), DRE->refersToEnclosingVariableOrCapture(), in rebuildPotentialResultsAsNonOdrUsed()
19134 DRE->getNameInfo(), DRE->getType(), DRE->getValueKind(), in rebuildPotentialResultsAsNonOdrUsed()
19135 DRE->getFoundDecl(), CopiedTemplateArgs(DRE), NOUR); in rebuildPotentialResultsAsNonOdrUsed()
19140 // If any of the declarations in the pack is odr-used, then the expression in rebuildPotentialResultsAsNonOdrUsed()
19141 // as a whole constitutes an odr-use. in rebuildPotentialResultsAsNonOdrUsed()
19146 // FIXME: Rebuild as a non-odr-use FunctionParmPackExpr? In practice, in rebuildPotentialResultsAsNonOdrUsed()
19147 // nothing cares about whether we marked this as an odr-use, but it might in rebuildPotentialResultsAsNonOdrUsed()
19148 // be useful for non-compiler tools. in rebuildPotentialResultsAsNonOdrUsed()
19153 // -- If e is a subscripting operation with an array operand... in rebuildPotentialResultsAsNonOdrUsed()
19156 Expr *OldBase = ASE->getBase()->IgnoreImplicit(); in rebuildPotentialResultsAsNonOdrUsed()
19157 if (!OldBase->getType()->isArrayType()) in rebuildPotentialResultsAsNonOdrUsed()
19162 Expr *LHS = ASE->getBase() == ASE->getLHS() ? Base.get() : ASE->getLHS(); in rebuildPotentialResultsAsNonOdrUsed()
19163 Expr *RHS = ASE->getBase() == ASE->getRHS() ? Base.get() : ASE->getRHS(); in rebuildPotentialResultsAsNonOdrUsed()
19164 SourceLocation LBracketLoc = ASE->getBeginLoc(); // FIXME: Not stored. in rebuildPotentialResultsAsNonOdrUsed()
19166 ASE->getRBracketLoc()); in rebuildPotentialResultsAsNonOdrUsed()
19171 // -- If e is a class member access expression [...] naming a non-static in rebuildPotentialResultsAsNonOdrUsed()
19173 if (isa<FieldDecl>(ME->getMemberDecl())) { in rebuildPotentialResultsAsNonOdrUsed()
19174 ExprResult Base = Rebuild(ME->getBase()); in rebuildPotentialResultsAsNonOdrUsed()
19178 S.Context, Base.get(), ME->isArrow(), ME->getOperatorLoc(), in rebuildPotentialResultsAsNonOdrUsed()
19179 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(), in rebuildPotentialResultsAsNonOdrUsed()
19180 ME->getMemberDecl(), ME->getFoundDecl(), ME->getMemberNameInfo(), in rebuildPotentialResultsAsNonOdrUsed()
19181 CopiedTemplateArgs(ME), ME->getType(), ME->getValueKind(), in rebuildPotentialResultsAsNonOdrUsed()
19182 ME->getObjectKind(), ME->isNonOdrUse()); in rebuildPotentialResultsAsNonOdrUsed()
19185 if (ME->getMemberDecl()->isCXXInstanceMember()) in rebuildPotentialResultsAsNonOdrUsed()
19188 // -- If e is a class member access expression naming a static data member, in rebuildPotentialResultsAsNonOdrUsed()
19190 if (ME->isNonOdrUse() || IsPotentialResultOdrUsed(ME->getMemberDecl())) in rebuildPotentialResultsAsNonOdrUsed()
19193 // Rebuild as a non-odr-use MemberExpr. in rebuildPotentialResultsAsNonOdrUsed()
19196 S.Context, ME->getBase(), ME->isArrow(), ME->getOperatorLoc(), in rebuildPotentialResultsAsNonOdrUsed()
19197 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(), ME->getMemberDecl(), in rebuildPotentialResultsAsNonOdrUsed()
19198 ME->getFoundDecl(), ME->getMemberNameInfo(), CopiedTemplateArgs(ME), in rebuildPotentialResultsAsNonOdrUsed()
19199 ME->getType(), ME->getValueKind(), ME->getObjectKind(), NOUR); in rebuildPotentialResultsAsNonOdrUsed()
19204 Expr *LHS = BO->getLHS(); in rebuildPotentialResultsAsNonOdrUsed()
19205 Expr *RHS = BO->getRHS(); in rebuildPotentialResultsAsNonOdrUsed()
19206 // -- If e is a pointer-to-member expression of the form e1 .* e2 ... in rebuildPotentialResultsAsNonOdrUsed()
19207 if (BO->getOpcode() == BO_PtrMemD) { in rebuildPotentialResultsAsNonOdrUsed()
19211 BO->setLHS(Sub.get()); in rebuildPotentialResultsAsNonOdrUsed()
19212 // -- If e is a comma expression, ... in rebuildPotentialResultsAsNonOdrUsed()
19213 } else if (BO->getOpcode() == BO_Comma) { in rebuildPotentialResultsAsNonOdrUsed()
19217 BO->setRHS(Sub.get()); in rebuildPotentialResultsAsNonOdrUsed()
19224 // -- If e has the form (e1)... in rebuildPotentialResultsAsNonOdrUsed()
19227 ExprResult Sub = Rebuild(PE->getSubExpr()); in rebuildPotentialResultsAsNonOdrUsed()
19230 return S.ActOnParenExpr(PE->getLParen(), PE->getRParen(), Sub.get()); in rebuildPotentialResultsAsNonOdrUsed()
19233 // -- If e is a glvalue conditional expression, ... in rebuildPotentialResultsAsNonOdrUsed()
19237 ExprResult LHS = Rebuild(CO->getLHS()); in rebuildPotentialResultsAsNonOdrUsed()
19240 ExprResult RHS = Rebuild(CO->getRHS()); in rebuildPotentialResultsAsNonOdrUsed()
19246 LHS = CO->getLHS(); in rebuildPotentialResultsAsNonOdrUsed()
19248 RHS = CO->getRHS(); in rebuildPotentialResultsAsNonOdrUsed()
19249 return S.ActOnConditionalOp(CO->getQuestionLoc(), CO->getColonLoc(), in rebuildPotentialResultsAsNonOdrUsed()
19250 CO->getCond(), LHS.get(), RHS.get()); in rebuildPotentialResultsAsNonOdrUsed()
19254 // -- If e has the form __extension__ e1... in rebuildPotentialResultsAsNonOdrUsed()
19257 if (UO->getOpcode() != UO_Extension) in rebuildPotentialResultsAsNonOdrUsed()
19259 ExprResult Sub = Rebuild(UO->getSubExpr()); in rebuildPotentialResultsAsNonOdrUsed()
19262 return S.BuildUnaryOp(nullptr, UO->getOperatorLoc(), UO_Extension, in rebuildPotentialResultsAsNonOdrUsed()
19267 // -- If e has the form _Generic(...), the set of potential results is the in rebuildPotentialResultsAsNonOdrUsed()
19274 for (Expr *OrigAssocExpr : GSE->getAssocExprs()) { in rebuildPotentialResultsAsNonOdrUsed()
19287 bool IsExpr = GSE->isExprPredicate(); in rebuildPotentialResultsAsNonOdrUsed()
19289 ExOrTy = GSE->getControllingExpr(); in rebuildPotentialResultsAsNonOdrUsed()
19291 ExOrTy = GSE->getControllingType(); in rebuildPotentialResultsAsNonOdrUsed()
19293 GSE->getGenericLoc(), GSE->getDefaultLoc(), in rebuildPotentialResultsAsNonOdrUsed()
19294 GSE->getRParenLoc(), IsExpr, ExOrTy, in rebuildPotentialResultsAsNonOdrUsed()
19295 GSE->getAssocTypeSourceInfos(), AssocExprs) in rebuildPotentialResultsAsNonOdrUsed()
19300 // -- If e has the form __builtin_choose_expr(...), the set of potential in rebuildPotentialResultsAsNonOdrUsed()
19306 ExprResult LHS = Rebuild(CE->getLHS()); in rebuildPotentialResultsAsNonOdrUsed()
19310 ExprResult RHS = Rebuild(CE->getLHS()); in rebuildPotentialResultsAsNonOdrUsed()
19317 LHS = CE->getLHS(); in rebuildPotentialResultsAsNonOdrUsed()
19319 RHS = CE->getRHS(); in rebuildPotentialResultsAsNonOdrUsed()
19321 return S.ActOnChooseExpr(CE->getBuiltinLoc(), CE->getCond(), LHS.get(), in rebuildPotentialResultsAsNonOdrUsed()
19322 RHS.get(), CE->getRParenLoc()); in rebuildPotentialResultsAsNonOdrUsed()
19325 // Step through non-syntactic nodes. in rebuildPotentialResultsAsNonOdrUsed()
19328 ExprResult Sub = Rebuild(CE->getSubExpr()); in rebuildPotentialResultsAsNonOdrUsed()
19341 switch (ICE->getCastKind()) { in rebuildPotentialResultsAsNonOdrUsed()
19345 ExprResult Sub = Rebuild(ICE->getSubExpr()); in rebuildPotentialResultsAsNonOdrUsed()
19348 CXXCastPath Path(ICE->path()); in rebuildPotentialResultsAsNonOdrUsed()
19349 return S.ImpCastExprToType(Sub.get(), ICE->getType(), ICE->getCastKind(), in rebuildPotentialResultsAsNonOdrUsed()
19350 ICE->getValueKind(), &Path); in rebuildPotentialResultsAsNonOdrUsed()
19368 // Check whether the operand is or contains an object of non-trivial C union in CheckLValueToRValueConversionOperand()
19370 if (E->getType().isVolatileQualified() && in CheckLValueToRValueConversionOperand()
19371 (E->getType().hasNonTrivialToPrimitiveDestructCUnion() || in CheckLValueToRValueConversionOperand()
19372 E->getType().hasNonTrivialToPrimitiveCopyCUnion())) in CheckLValueToRValueConversionOperand()
19373 checkNonTrivialCUnion(E->getType(), E->getExprLoc(), in CheckLValueToRValueConversionOperand()
19377 // C++2a [basic.def.odr]p4: in CheckLValueToRValueConversionOperand()
19378 // [...] an expression of non-volatile-qualified non-class type to which in CheckLValueToRValueConversionOperand()
19379 // the lvalue-to-rvalue conversion is applied [...] in CheckLValueToRValueConversionOperand()
19380 if (E->getType().isVolatileQualified() || E->getType()->getAs<RecordType>()) in CheckLValueToRValueConversionOperand()
19396 // If a constant-expression is a reference to a variable where we delay in ActOnConstantExpression()
19397 // deciding whether it is an odr-use, just assume we will apply the in ActOnConstantExpression()
19398 // lvalue-to-rvalue conversion. In the one case where this doesn't happen in ActOnConstantExpression()
19399 // (a non-type template argument), we have special handling anyway. in ActOnConstantExpression()
19411 MarkVarDeclODRUsed(cast<VarDecl>(DRE->getDecl()), in CleanupVarDeclMarking()
19412 DRE->getLocation(), *this); in CleanupVarDeclMarking()
19414 MarkVarDeclODRUsed(cast<VarDecl>(ME->getMemberDecl()), ME->getMemberLoc(), in CleanupVarDeclMarking()
19418 MarkVarDeclODRUsed(VD, FP->getParameterPackLocation(), *this); in CleanupVarDeclMarking()
19430 VarDecl *VD = Var->getPotentiallyDecomposedVarDecl(); in DoMarkPotentialCapture()
19435 (SemaRef.CurContext != VD->getDeclContext() && in DoMarkPotentialCapture()
19436 VD->getDeclContext()->isFunctionOrMethod() && VD->hasLocalStorage()); in DoMarkPotentialCapture()
19440 if (LSI && (!LSI->CallOperator || in DoMarkPotentialCapture()
19441 !LSI->CallOperator->Encloses(Var->getDeclContext()))) { in DoMarkPotentialCapture()
19442 // If a variable could potentially be odr-used, defer marking it so in DoMarkPotentialCapture()
19444 // lvalue-to-rvalue in DoMarkPotentialCapture()
19445 // or discarded value conversions that would obviate odr-use. in DoMarkPotentialCapture()
19447 // later (ActOnFinishFullExpr) for eventual capture and odr-use marking in DoMarkPotentialCapture()
19449 // expression (this will never need to be captured or odr-used). in DoMarkPotentialCapture()
19453 if (!Var->getType()->isReferenceType() || in DoMarkPotentialCapture()
19454 !VD->isUsableInConstantExpressions(SemaRef.Context)) in DoMarkPotentialCapture()
19455 LSI->addPotentialCapture(E->IgnoreParens()); in DoMarkPotentialCapture()
19466 Var->setReferenced(); in DoMarkVarDeclReferenced()
19468 if (Var->isInvalidDecl()) in DoMarkVarDeclReferenced()
19471 auto *MSI = Var->getMemberSpecializationInfo(); in DoMarkVarDeclReferenced()
19472 TemplateSpecializationKind TSK = MSI ? MSI->getTemplateSpecializationKind() in DoMarkVarDeclReferenced()
19473 : Var->getTemplateSpecializationKind(); in DoMarkVarDeclReferenced()
19477 Var->mightBeUsableInConstantExpressions(SemaRef.Context); in DoMarkVarDeclReferenced()
19479 if (Var->isLocalVarDeclOrParm() && !Var->hasExternalStorage()) { in DoMarkVarDeclReferenced()
19480 RefsMinusAssignments.insert({Var, 0}).first->getSecond()++; in DoMarkVarDeclReferenced()
19486 // expression that is either a contexpr variable or is of non-volatile in DoMarkVarDeclReferenced()
19487 // const-qualified integral type or of reference type in DoMarkVarDeclReferenced()
19518 MSI ? MSI->getPointOfInstantiation() : Var->getPointOfInstantiation(); in DoMarkVarDeclReferenced()
19523 MSI->setPointOfInstantiation(PointOfInstantiation); in DoMarkVarDeclReferenced()
19526 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); in DoMarkVarDeclReferenced()
19536 // Re-set the member to trigger a recomputation of the dependence bits in DoMarkVarDeclReferenced()
19539 DRE->setDecl(DRE->getDecl()); in DoMarkVarDeclReferenced()
19541 ME->setMemberDecl(ME->getMemberDecl()); in DoMarkVarDeclReferenced()
19572 // C++2a [basic.def.odr]p4: in DoMarkVarDeclReferenced()
19573 // A variable x whose name appears as a potentially-evaluated expression e in DoMarkVarDeclReferenced()
19574 // is odr-used by e unless in DoMarkVarDeclReferenced()
19575 // -- x is a reference that is usable in constant expressions in DoMarkVarDeclReferenced()
19576 // -- x is a variable of non-reference type that is usable in constant in DoMarkVarDeclReferenced()
19579 // non-volatile-qualified non-class type to which the lvalue-to-rvalue in DoMarkVarDeclReferenced()
19581 // -- x is a variable of non-reference type, and e is an element of the set in DoMarkVarDeclReferenced()
19582 // of potential results of a discarded-value expression to which the in DoMarkVarDeclReferenced()
19583 // lvalue-to-rvalue conversion is not applied [FIXME] in DoMarkVarDeclReferenced()
19590 // If we already know this isn't an odr-use, there's nothing more to do. in DoMarkVarDeclReferenced()
19592 if (DRE->isNonOdrUse()) in DoMarkVarDeclReferenced()
19595 if (ME->isNonOdrUse()) in DoMarkVarDeclReferenced()
19604 "missing non-odr-use marking for unevaluated decl ref"); in DoMarkVarDeclReferenced()
19608 // FIXME: Ignoring formal odr-uses results in incorrect lambda capture in DoMarkVarDeclReferenced()
19613 // If we might later find that this expression isn't actually an odr-use, in DoMarkVarDeclReferenced()
19615 if (E && Var->isUsableInConstantExpressions(SemaRef.Context)) in DoMarkVarDeclReferenced()
19623 // odr-used, but we may still need to track them for lambda capture. in DoMarkVarDeclReferenced()
19633 BD->setReferenced(); in DoMarkBindingDeclReferenced()
19635 if (BD->isInvalidDecl()) in DoMarkBindingDeclReferenced()
19656 // An id-expression is type-dependent if it contains:
19657 // - an identifier associated by name lookup with an entity captured by copy
19658 // in a lambda-expression that has an explicit object parameter whose type
19663 if (!ID || ID->isTypeDependent() || !ID->refersToEnclosingVariableOrCapture()) in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19676 if (LSI->Lambda && !LSI->Lambda->Encloses(SemaRef.CurContext) && in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19677 LSI->AfterParameterList) in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19680 const auto *MD = LSI->CallOperator; in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19681 if (MD->getType().isNull()) in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19684 const auto *Ty = MD->getType()->getAs<FunctionProtoType>(); in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19685 if (!Ty || !MD->isExplicitObjectMemberFunction() || in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19686 !Ty->getParamType(0)->isDependentType()) in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19689 if (auto *C = LSI->CaptureMap.count(D) ? &LSI->getCapture(D) : nullptr) { in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19690 if (C->isCopyCapture()) in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19695 if (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByval) in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19701 ID->setCapturedByCopyInLambdaWithExplicitObjectParameter( in FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter()
19734 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ME->getMemberDecl()); in MarkExprReferenced()
19738 bool IsVirtualCall = MD->isVirtual() && in MarkExprReferenced()
19739 ME->performsVirtualDispatch(SemaRef.getLangOpts()); in MarkExprReferenced()
19745 CXXMethodDecl *DM = MD->getDevirtualizedMethod( in MarkExprReferenced()
19746 ME->getBase(), SemaRef.getLangOpts().AppleKext); in MarkExprReferenced()
19756 if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(E->getDecl())) in MarkDeclRefReferenced()
19757 if (Method->isVirtual() && in MarkDeclRefReferenced()
19758 !Method->getDevirtualizedMethod(Base, getLangOpts().AppleKext)) in MarkDeclRefReferenced()
19761 if (auto *FD = dyn_cast<FunctionDecl>(E->getDecl())) { in MarkDeclRefReferenced()
19765 FD->isImmediateFunction() && !RebuildingImmediateInvocation && in MarkDeclRefReferenced()
19766 !FD->isDependentContext()) in MarkDeclRefReferenced()
19769 MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse, in MarkDeclRefReferenced()
19775 // A non-overloaded function whose name appears as a potentially-evaluated in MarkMemberReferenced()
19777 // overload resolution when referred to from a potentially-evaluated in MarkMemberReferenced()
19778 // expression, is odr-used, unless it is a pure virtual function and its in MarkMemberReferenced()
19781 if (E->performsVirtualDispatch(getLangOpts())) { in MarkMemberReferenced()
19782 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(E->getMemberDecl())) in MarkMemberReferenced()
19783 if (Method->isPureVirtual()) in MarkMemberReferenced()
19787 E->getMemberLoc().isValid() ? E->getMemberLoc() : E->getBeginLoc(); in MarkMemberReferenced()
19788 MarkExprReferenced(*this, Loc, E->getMemberDecl(), E, MightBeOdrUse, in MarkMemberReferenced()
19794 MarkExprReferenced(*this, E->getParameterPackLocation(), VD, E, true, in MarkFunctionParmPackReferenced()
19799 /// marks the declaration referenced, and performs odr-use checking for
19814 D->setReferenced(); in MarkAnyDeclReferenced()
19821 // FIXME: This is and EvaluatedExprMarker are more-or-less equivalent to
19841 // A non-type template argument is a constant-evaluated context. in TraverseTemplateArgument()
19862 /// potentially-evaluated subexpressions as "referenced".
19891 if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) in VisitDeclRefExpr()
19892 if (VD->hasLocalStorage()) in VisitDeclRefExpr()
19897 // variable, which can cause the expression to become value-dependent in VisitDeclRefExpr()
19898 // or error-dependent. Do we need to propagate the new dependence bits? in VisitDeclRefExpr()
19904 Visit(E->getBase()); in VisitMemberExpr()
19919 /// namespace { auto *p = new double[3][false ? (1, 2) : 3]; }
19924 FunctionScopes.back()->PossiblyUnreachableDiags.push_back( in DiagIfReachable()
19936 if (VD->isConstexpr() || in DiagIfReachable()
19937 (VD->isStaticDataMember() && VD->isFirstDecl() && !VD->isInline())) in DiagIfReachable()
19947 /// Emit a diagnostic that describes an effect on the run-time behavior
19951 /// type-checked is "potentially evaluated", meaning that there is a
19959 /// This routine should be used for all diagnostics that describe the run-time
19960 /// behavior of a program, such as passing a non-POD value through an ellipsis.
19998 if (ReturnType->isVoidType() || !ReturnType->isIncompleteType()) in CheckCallReturnType()
20020 << T << CE->getSourceRange(); in CheckCallReturnType()
20025 << CE->getSourceRange() << FD << T; in CheckCallReturnType()
20026 S.Diag(FD->getLocation(), diag::note_entity_declared_at) in CheckCallReturnType()
20027 << FD->getDeclName(); in CheckCallReturnType()
20046 if (Op->getOpcode() != BO_Assign && Op->getOpcode() != BO_OrAssign) in DiagnoseAssignmentAsCondition()
20049 IsOrAssign = Op->getOpcode() == BO_OrAssign; in DiagnoseAssignmentAsCondition()
20053 = dyn_cast<ObjCMessageExpr>(Op->getRHS()->IgnoreParenCasts())) { in DiagnoseAssignmentAsCondition()
20054 Selector Sel = ME->getSelector(); in DiagnoseAssignmentAsCondition()
20057 if (ObjC().isSelfExpr(Op->getLHS()) && ME->getMethodFamily() == OMF_init) in DiagnoseAssignmentAsCondition()
20065 Loc = Op->getOperatorLoc(); in DiagnoseAssignmentAsCondition()
20067 if (Op->getOperator() != OO_Equal && Op->getOperator() != OO_PipeEqual) in DiagnoseAssignmentAsCondition()
20070 IsOrAssign = Op->getOperator() == OO_PipeEqual; in DiagnoseAssignmentAsCondition()
20071 Loc = Op->getOperatorLoc(); in DiagnoseAssignmentAsCondition()
20073 return DiagnoseAssignmentAsCondition(POE->getSyntacticForm()); in DiagnoseAssignmentAsCondition()
20079 Diag(Loc, diagnostic) << E->getSourceRange(); in DiagnoseAssignmentAsCondition()
20081 SourceLocation Open = E->getBeginLoc(); in DiagnoseAssignmentAsCondition()
20082 SourceLocation Close = getLocForEndOfToken(E->getSourceRange().getEnd()); in DiagnoseAssignmentAsCondition()
20097 SourceLocation parenLoc = ParenE->getBeginLoc(); in DiagnoseEqualityWithExtraParens()
20101 if (ParenE->isTypeDependent()) in DiagnoseEqualityWithExtraParens()
20104 Expr *E = ParenE->IgnoreParens(); in DiagnoseEqualityWithExtraParens()
20107 if (opE->getOpcode() == BO_EQ && in DiagnoseEqualityWithExtraParens()
20108 opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(Context) in DiagnoseEqualityWithExtraParens()
20110 SourceLocation Loc = opE->getOperatorLoc(); in DiagnoseEqualityWithExtraParens()
20112 Diag(Loc, diag::warn_equality_with_extra_parens) << E->getSourceRange(); in DiagnoseEqualityWithExtraParens()
20113 SourceRange ParenERange = ParenE->getSourceRange(); in DiagnoseEqualityWithExtraParens()
20132 if (!E->isTypeDependent()) { in CheckBooleanCondition()
20141 QualType T = E->getType(); in CheckBooleanCondition()
20142 if (!T->isScalarType()) { // C99 6.8.4.1p1 in CheckBooleanCondition()
20144 << T << E->getSourceRange(); in CheckBooleanCondition()
20176 Cond = CreateRecoveryExpr(SubExpr->getBeginLoc(), SubExpr->getEndLoc(), in ActOnCondition()
20205 S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_call) in VisitExpr()
20206 << E->getSourceRange(); in VisitExpr()
20213 ExprResult SubResult = Visit(E->getSubExpr()); in rebuildSugarExpr()
20217 E->setSubExpr(SubExpr); in rebuildSugarExpr()
20218 E->setType(SubExpr->getType()); in rebuildSugarExpr()
20219 E->setValueKind(SubExpr->getValueKind()); in rebuildSugarExpr()
20220 assert(E->getObjectKind() == OK_Ordinary); in rebuildSugarExpr()
20233 ExprResult SubResult = Visit(E->getSubExpr()); in VisitUnaryAddrOf()
20237 E->setSubExpr(SubExpr); in VisitUnaryAddrOf()
20238 E->setType(S.Context.getPointerType(SubExpr->getType())); in VisitUnaryAddrOf()
20239 assert(E->isPRValue()); in VisitUnaryAddrOf()
20240 assert(E->getObjectKind() == OK_Ordinary); in VisitUnaryAddrOf()
20247 E->setType(VD->getType()); in resolveDecl()
20249 assert(E->isPRValue()); in resolveDecl()
20252 cast<CXXMethodDecl>(VD)->isInstance())) in resolveDecl()
20253 E->setValueKind(VK_LValue); in resolveDecl()
20259 return resolveDecl(E, E->getMemberDecl()); in VisitMemberExpr()
20263 return resolveDecl(E, E->getDecl()); in VisitDeclRefExpr()
20268 /// Given a function expression of unknown-any type, try to rebuild it
20297 S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_expr) in VisitExpr()
20298 << E->getSourceRange(); in VisitExpr()
20308 ExprResult SubResult = Visit(E->getSubExpr()); in rebuildSugarExpr()
20311 E->setSubExpr(SubExpr); in rebuildSugarExpr()
20312 E->setType(SubExpr->getType()); in rebuildSugarExpr()
20313 E->setValueKind(SubExpr->getValueKind()); in rebuildSugarExpr()
20314 assert(E->getObjectKind() == OK_Ordinary); in rebuildSugarExpr()
20327 const PointerType *Ptr = DestType->getAs<PointerType>(); in VisitUnaryAddrOf()
20329 S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof) in VisitUnaryAddrOf()
20330 << E->getSourceRange(); in VisitUnaryAddrOf()
20334 if (isa<CallExpr>(E->getSubExpr())) { in VisitUnaryAddrOf()
20335 S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof_call) in VisitUnaryAddrOf()
20336 << E->getSourceRange(); in VisitUnaryAddrOf()
20340 assert(E->isPRValue()); in VisitUnaryAddrOf()
20341 assert(E->getObjectKind() == OK_Ordinary); in VisitUnaryAddrOf()
20342 E->setType(DestType); in VisitUnaryAddrOf()
20344 // Build the sub-expression as if it were an object of the pointee type. in VisitUnaryAddrOf()
20345 DestType = Ptr->getPointeeType(); in VisitUnaryAddrOf()
20346 ExprResult SubResult = Visit(E->getSubExpr()); in VisitUnaryAddrOf()
20348 E->setSubExpr(SubResult.get()); in VisitUnaryAddrOf()
20357 return resolveDecl(E, E->getMemberDecl()); in VisitMemberExpr()
20361 return resolveDecl(E, E->getDecl()); in VisitDeclRefExpr()
20368 Expr *CalleeExpr = E->getCallee(); in VisitCallExpr()
20377 QualType CalleeType = CalleeExpr->getType(); in VisitCallExpr()
20382 } else if (const PointerType *Ptr = CalleeType->getAs<PointerType>()) { in VisitCallExpr()
20383 CalleeType = Ptr->getPointeeType(); in VisitCallExpr()
20386 CalleeType = CalleeType->castAs<BlockPointerType>()->getPointeeType(); in VisitCallExpr()
20389 const FunctionType *FnType = CalleeType->castAs<FunctionType>(); in VisitCallExpr()
20392 if (DestType->isArrayType() || DestType->isFunctionType()) { in VisitCallExpr()
20397 S.Diag(E->getExprLoc(), diagID) in VisitCallExpr()
20398 << DestType->isFunctionType() << DestType; in VisitCallExpr()
20403 E->setType(DestType.getNonLValueExprType(S.Context)); in VisitCallExpr()
20404 E->setValueKind(Expr::getValueKindForType(DestType)); in VisitCallExpr()
20405 assert(E->getObjectKind() == OK_Ordinary); in VisitCallExpr()
20417 // portably just call the function under a non-variadic type; see in VisitCallExpr()
20418 // the comment on IR-gen's TargetInfo::isNoProtoCallVariadic. in VisitCallExpr()
20427 // corresponding target-specific code from IR-gen to Sema/AST. in VisitCallExpr()
20429 ArrayRef<QualType> ParamTypes = Proto->getParamTypes(); in VisitCallExpr()
20431 if (ParamTypes.empty() && Proto->isVariadic()) { // the special case in VisitCallExpr()
20432 ArgTypes.reserve(E->getNumArgs()); in VisitCallExpr()
20433 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { in VisitCallExpr()
20434 ArgTypes.push_back(S.Context.getReferenceQualifiedType(E->getArg(i))); in VisitCallExpr()
20439 Proto->getExtProtoInfo()); in VisitCallExpr()
20442 FnType->getExtInfo()); in VisitCallExpr()
20445 // Rebuild the appropriate pointer-to-function type. in VisitCallExpr()
20463 E->setCallee(CalleeResult.get()); in VisitCallExpr()
20471 if (DestType->isArrayType() || DestType->isFunctionType()) { in VisitObjCMessageExpr()
20472 S.Diag(E->getExprLoc(), diag::err_func_returning_array_function) in VisitObjCMessageExpr()
20473 << DestType->isFunctionType() << DestType; in VisitObjCMessageExpr()
20478 if (ObjCMethodDecl *Method = E->getMethodDecl()) { in VisitObjCMessageExpr()
20479 assert(Method->getReturnType() == S.Context.UnknownAnyTy); in VisitObjCMessageExpr()
20480 Method->setReturnType(DestType); in VisitObjCMessageExpr()
20484 E->setType(DestType.getNonReferenceType()); in VisitObjCMessageExpr()
20485 E->setValueKind(Expr::getValueKindForType(DestType)); in VisitObjCMessageExpr()
20491 // The only case we should ever see here is a function-to-pointer decay. in VisitImplicitCastExpr()
20492 if (E->getCastKind() == CK_FunctionToPointerDecay) { in VisitImplicitCastExpr()
20493 assert(E->isPRValue()); in VisitImplicitCastExpr()
20494 assert(E->getObjectKind() == OK_Ordinary); in VisitImplicitCastExpr()
20496 E->setType(DestType); in VisitImplicitCastExpr()
20498 // Rebuild the sub-expression as the pointee (function) type. in VisitImplicitCastExpr()
20499 DestType = DestType->castAs<PointerType>()->getPointeeType(); in VisitImplicitCastExpr()
20501 ExprResult Result = Visit(E->getSubExpr()); in VisitImplicitCastExpr()
20504 E->setSubExpr(Result.get()); in VisitImplicitCastExpr()
20506 } else if (E->getCastKind() == CK_LValueToRValue) { in VisitImplicitCastExpr()
20507 assert(E->isPRValue()); in VisitImplicitCastExpr()
20508 assert(E->getObjectKind() == OK_Ordinary); in VisitImplicitCastExpr()
20510 assert(isa<BlockPointerType>(E->getType())); in VisitImplicitCastExpr()
20512 E->setType(DestType); in VisitImplicitCastExpr()
20514 // The sub-expression has to be a lvalue reference, so rebuild it as such. in VisitImplicitCastExpr()
20517 ExprResult Result = Visit(E->getSubExpr()); in VisitImplicitCastExpr()
20520 E->setSubExpr(Result.get()); in VisitImplicitCastExpr()
20533 // - functions in resolveDecl()
20535 if (const PointerType *Ptr = Type->getAs<PointerType>()) { in resolveDecl()
20536 DestType = Ptr->getPointeeType(); in resolveDecl()
20543 if (!Type->isFunctionType()) { in resolveDecl()
20544 S.Diag(E->getExprLoc(), diag::err_unknown_any_function) in resolveDecl()
20545 << VD << E->getSourceRange(); in resolveDecl()
20548 if (const FunctionProtoType *FT = Type->getAs<FunctionProtoType>()) { in resolveDecl()
20552 QualType FDT = FD->getType(); in resolveDecl()
20553 const FunctionType *FnType = FDT->castAs<FunctionType>(); in resolveDecl()
20556 if (DRE && Proto && Proto->getParamTypes().empty() && Proto->isVariadic()) { in resolveDecl()
20557 SourceLocation Loc = FD->getLocation(); in resolveDecl()
20559 S.Context, FD->getDeclContext(), Loc, Loc, in resolveDecl()
20560 FD->getNameInfo().getName(), DestType, FD->getTypeSourceInfo(), in resolveDecl()
20562 false /*isInlineSpecified*/, FD->hasPrototype(), in resolveDecl()
20565 if (FD->getQualifier()) in resolveDecl()
20566 NewFD->setQualifierInfo(FD->getQualifierLoc()); in resolveDecl()
20569 for (const auto &AI : FT->param_types()) { in resolveDecl()
20572 Param->setScopeInfo(0, Params.size()); in resolveDecl()
20575 NewFD->setParams(Params); in resolveDecl()
20576 DRE->setDecl(NewFD); in resolveDecl()
20577 VD = DRE->getDecl(); in resolveDecl()
20582 if (MD->isInstance()) { in resolveDecl()
20587 // Function references aren't l-values in C. in resolveDecl()
20591 // - variables in resolveDecl()
20593 if (const ReferenceType *RefTy = Type->getAs<ReferenceType>()) { in resolveDecl()
20594 Type = RefTy->getPointeeType(); in resolveDecl()
20595 } else if (Type->isFunctionType()) { in resolveDecl()
20596 S.Diag(E->getExprLoc(), diag::err_unknown_any_var_function_type) in resolveDecl()
20597 << VD << E->getSourceRange(); in resolveDecl()
20601 // - nothing else in resolveDecl()
20603 S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_decl) in resolveDecl()
20604 << VD << E->getSourceRange(); in resolveDecl()
20608 // Modifying the declaration like this is friendly to IR-gen but in resolveDecl()
20610 VD->setType(DestType); in resolveDecl()
20611 E->setType(Type); in resolveDecl()
20612 E->setValueKind(ValueKind); in resolveDecl()
20620 if (!CastType->isVoidType() && in checkUnknownAnyCast()
20630 VK = CastExpr->getValueKind(); in checkUnknownAnyCast()
20644 ExplicitCastExpr *castArg = dyn_cast<ExplicitCastExpr>(arg->IgnoreParens()); in checkUnknownAnyArg()
20648 paramType = result.get()->getType(); in checkUnknownAnyArg()
20653 assert(!arg->hasPlaceholderType()); in checkUnknownAnyArg()
20654 paramType = castArg->getTypeAsWritten(); in checkUnknownAnyArg()
20656 // Copy-initialize a parameter of that type. in checkUnknownAnyArg()
20667 E = E->IgnoreParenImpCasts(); in diagnoseUnknownAnyExpr()
20669 E = call->getCallee(); in diagnoseUnknownAnyExpr()
20679 loc = ref->getLocation(); in diagnoseUnknownAnyExpr()
20680 d = ref->getDecl(); in diagnoseUnknownAnyExpr()
20682 loc = mem->getMemberLoc(); in diagnoseUnknownAnyExpr()
20683 d = mem->getMemberDecl(); in diagnoseUnknownAnyExpr()
20686 loc = msg->getSelectorStartLoc(); in diagnoseUnknownAnyExpr()
20687 d = msg->getMethodDecl(); in diagnoseUnknownAnyExpr()
20690 << static_cast<unsigned>(msg->isClassMessage()) << msg->getSelector() in diagnoseUnknownAnyExpr()
20691 << orig->getSourceRange(); in diagnoseUnknownAnyExpr()
20695 S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_expr) in diagnoseUnknownAnyExpr()
20696 << E->getSourceRange(); in diagnoseUnknownAnyExpr()
20700 S.Diag(loc, diagID) << d << orig->getSourceRange(); in diagnoseUnknownAnyExpr()
20716 const BuiltinType *placeholderType = E->getType()->getAsPlaceholderType(); in CheckPlaceholderExpr()
20719 switch (placeholderType->getKind()) { in CheckPlaceholderExpr()
20722 const DeclarationNameInfo &NameInfo = ULE->getNameInfo(); in CheckPlaceholderExpr()
20725 NamedDecl *Temp = *ULE->decls_begin(); in CheckPlaceholderExpr()
20728 if (NestedNameSpecifierLoc Loc = ULE->getQualifierLoc(); Loc.hasQualifier()) in CheckPlaceholderExpr()
20734 << "" << NameInfo.getName().getAsString() << ULE->getSourceRange() in CheckPlaceholderExpr()
20736 Diag(Temp->getLocation(), diag::note_referenced_type_template) in CheckPlaceholderExpr()
20765 const Expr *BME = E->IgnoreParens(); in CheckPlaceholderExpr()
20769 PD = PDiag(diag::err_dtor_expr_without_call) << /*pseudo-destructor*/ 1; in CheckPlaceholderExpr()
20771 if (ME->getMemberNameInfo().getName().getNameKind() == in CheckPlaceholderExpr()
20791 // Pseudo-objects. in CheckPlaceholderExpr()
20797 auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()); in CheckPlaceholderExpr()
20799 auto *FD = cast<FunctionDecl>(DRE->getDecl()); in CheckPlaceholderExpr()
20800 unsigned BuiltinID = FD->getBuiltinID(); in CheckPlaceholderExpr()
20802 E = ImpCastExprToType(E, Context.getPointerType(FD->getType()), in CheckPlaceholderExpr()
20811 // Any use of these other than a direct call is ill-formed as of C++20, in CheckPlaceholderExpr()
20814 Diag(E->getBeginLoc(), in CheckPlaceholderExpr()
20818 if (FD->isImplicitlyInstantiable()) { in CheckPlaceholderExpr()
20823 InstantiateFunctionDefinition(E->getBeginLoc(), FD, in CheckPlaceholderExpr()
20828 // Produce a properly-typed reference to the function. in CheckPlaceholderExpr()
20830 SS.Adopt(DRE->getQualifierLoc()); in CheckPlaceholderExpr()
20832 DRE->copyTemplateArgumentsInto(TemplateArgs); in CheckPlaceholderExpr()
20834 FD, FD->getType(), VK_LValue, DRE->getNameInfo(), in CheckPlaceholderExpr()
20835 DRE->hasQualifier() ? &SS : nullptr, DRE->getFoundDecl(), in CheckPlaceholderExpr()
20836 DRE->getTemplateKeywordLoc(), in CheckPlaceholderExpr()
20837 DRE->hasExplicitTemplateArgs() ? &TemplateArgs : nullptr); in CheckPlaceholderExpr()
20841 Diag(E->getBeginLoc(), diag::err_builtin_fn_use); in CheckPlaceholderExpr()
20846 Diag(cast<MatrixSubscriptExpr>(E->IgnoreParens()) in CheckPlaceholderExpr()
20847 ->getRowIdx() in CheckPlaceholderExpr()
20848 ->getBeginLoc(), in CheckPlaceholderExpr()
20854 Diag(E->getBeginLoc(), diag::err_array_section_use) in CheckPlaceholderExpr()
20855 << cast<ArraySectionExpr>(E)->isOMPArraySection(); in CheckPlaceholderExpr()
20860 return ExprError(Diag(E->getBeginLoc(), diag::err_omp_array_shaping_use)); in CheckPlaceholderExpr()
20863 return ExprError(Diag(E->getBeginLoc(), diag::err_omp_iterator_use)); in CheckPlaceholderExpr()
20894 if (E->isTypeDependent()) in CheckCaseExpression()
20896 if (E->isValueDependent() || E->isIntegerConstantExpr(Context)) in CheckCaseExpression()
20897 return E->getType()->isIntegralOrEnumerationType(); in CheckCaseExpression()
20909 if (T.isNull() || T->isUndeducedType() || in CreateRecoveryExpr()