Lines Matching +full:spurious +full:- +full:oc

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