65#include "llvm/ADT/STLExtras.h"
66#include "llvm/ADT/StringExtras.h"
67#include "llvm/Support/ConvertUTF.h"
68#include "llvm/Support/SaveAndRestore.h"
69#include "llvm/Support/TimeProfiler.h"
70#include "llvm/Support/TypeSize.h"
95 if (TreatUnavailableAsInvalid &&
113 if (
const auto *A = D->
getAttr<UnusedAttr>()) {
116 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
117 A->getSemanticSpelling() != UnusedAttr::C23_maybe_unused) {
119 if (DC && !DC->
hasAttr<UnusedAttr>())
120 S.
Diag(Loc, diag::warn_used_but_marked_unused) << D;
128 if (
Decl->isDefaulted()) {
139 auto *Ctor = dyn_cast<CXXConstructorDecl>(
Decl);
140 if (Ctor && Ctor->isInheritingConstructor())
151 if (I->getStorageClass() !=
SC_None)
202 DiagID = diag::warn_c2y_compat_internal_in_extern_inline;
203 else if ((UsedFn && (UsedFn->
isInlined() || UsedFn->
hasAttr<ConstAttr>())) ||
205 DiagID = diag::ext_internal_in_extern_inline_quiet;
207 DiagID = diag::ext_internal_in_extern_inline;
209 S.
Diag(Loc, DiagID) << !UsedFn << D;
221 Diag(DeclBegin, diag::note_convert_inline_to_static)
228 bool ObjCPropertyAccess,
229 bool AvoidPartialAvailabilityChecks,
231 bool SkipTrailingRequiresClause) {
238 for (
const auto &[DiagLoc, PD] : Pos->second) {
252 Diag(Loc, diag::ext_main_used);
260 Diag(Loc, diag::err_binding_cannot_appear_in_own_initializer)
263 Diag(Loc, diag::err_auto_variable_cannot_appear_in_own_initializer)
272 if (FD->isDeleted()) {
273 auto *Ctor = dyn_cast<CXXConstructorDecl>(FD);
274 if (Ctor && Ctor->isInheritingConstructor())
275 Diag(Loc, diag::err_deleted_inherited_ctor_use)
277 << Ctor->getInheritedConstructor().getConstructor()->getParent();
280 Diag(Loc, diag::err_deleted_function_use)
281 << (Msg !=
nullptr) << (Msg ? Msg->
getString() : StringRef());
295 if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) {
304 diag::err_reference_to_function_with_unsatisfied_constraints)
322 if (
auto *
Concept = dyn_cast<ConceptDecl>(D);
326 if (
auto *MD = dyn_cast<CXXMethodDecl>(D)) {
328 if (MD->getParent()->isLambda() &&
331 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) {
332 Diag(Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign)
337 auto getReferencedObjCProp = [](
const NamedDecl *D) ->
339 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
340 return MD->findPropertyDecl();
354 auto *DRD = dyn_cast<OMPDeclareReductionDecl>(
CurContext);
357 Diag(Loc, diag::err_omp_wrong_var_in_declare_reduction)
370 Diag(Loc, diag::err_omp_declare_mapper_wrong_var)
376 if (
const auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(D)) {
377 Diag(Loc, diag::err_use_of_empty_using_if_exists);
378 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here);
383 AvoidPartialAvailabilityChecks, ClassReceiver);
389 if (D->
hasAttr<AvailableOnlyInDefaultEvalMethodAttr>()) {
392 PP.getLastFPEvalPragmaLocation().isValid() &&
393 PP.getCurrentFPEvalMethod() !=
getLangOpts().getFPEvalMethod())
395 diag::err_type_available_only_in_default_eval_method)
399 if (
auto *VD = dyn_cast<ValueDecl>(D))
404 if (!
Context.getTargetInfo().isTLSSupported())
405 if (
const auto *VD = dyn_cast<VarDecl>(D))
407 targetDiag(*Locs.begin(), diag::err_thread_unsupported);
418 const SentinelAttr *
Attr = D->
getAttr<SentinelAttr>();
423 unsigned NumFormalParams;
427 enum { CK_Function, CK_Method, CK_Block } CalleeKind;
429 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
430 NumFormalParams = MD->param_size();
431 CalleeKind = CK_Method;
432 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
433 NumFormalParams = FD->param_size();
434 CalleeKind = CK_Function;
435 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
442 CalleeKind = CK_Function;
445 CalleeKind = CK_Block;
450 if (
const auto *proto = dyn_cast<FunctionProtoType>(Fn))
451 NumFormalParams = proto->getNumParams();
462 unsigned NullPos =
Attr->getNullPos();
463 assert((NullPos == 0 || NullPos == 1) &&
"invalid null position on sentinel");
464 NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - NullPos);
467 unsigned NumArgsAfterSentinel =
Attr->getSentinel();
471 if (Args.size() < NumFormalParams + NumArgsAfterSentinel + 1) {
478 const Expr *SentinelExpr = Args[Args.size() - NumArgsAfterSentinel - 1];
483 if (
Context.isSentinelNullExpr(SentinelExpr))
491 std::string NullValue;
492 if (CalleeKind == CK_Method &&
PP.isMacroDefined(
"nil"))
495 NullValue =
"nullptr";
496 else if (
PP.isMacroDefined(
"NULL"))
499 NullValue =
"(void*) 0";
502 Diag(Loc, diag::warn_missing_sentinel) <<
int(CalleeKind);
504 Diag(MissingNilLoc, diag::warn_missing_sentinel)
529 assert(!Ty.
isNull() &&
"DefaultFunctionArrayConversion - missing type");
533 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
538 CK_FunctionToPointerDecay).
get();
553 CK_ArrayToPointerDecay);
569 if (UO && UO->getOpcode() == UO_Deref &&
570 UO->getSubExpr()->getType()->isPointerType()) {
572 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
575 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
577 !UO->getType().isVolatileQualified()) {
579 S.
PDiag(diag::warn_indirection_through_null)
580 << UO->getSubExpr()->getSourceRange());
582 S.
PDiag(diag::note_indirection_through_null));
602 BaseType = BaseType->getPointeeType();
614 if (ObjectSetClass) {
658 assert(!T.isNull() &&
"r-value conversion on typeless expression?");
662 if (T->canDecayToPointerType())
668 if (T ==
Context.OverloadTy || T->isRecordType() ||
669 (T->isDependentType() && !T->isAnyPointerType() &&
670 !T->isMemberPointerType()))
694 &
Context.Idents.get(
"object_getClass"),
700 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()),
")");
717 if (T.hasQualifiers())
718 T = T.getUnqualifiedType();
721 if (T->isMemberPointerType() &&
722 Context.getTargetInfo().getCXXABI().isMicrosoft())
733 Cleanup.setExprNeedsCleanups(
true);
736 Cleanup.setExprNeedsCleanups(
true);
743 CastKind CK = T->isNullPtrType() ? CK_NullToPointer : CK_LValueToRValue;
751 T =
Atomic->getValueType().getUnqualifiedType();
776 CK_FunctionToPointerDecay);
790 assert(!Ty.
isNull() &&
"UsualUnaryFPConversions - missing type");
796 PP.getLastFPEvalPragmaLocation().isValid())) {
797 switch (EvalMethod) {
799 llvm_unreachable(
"Unrecognized float evaluation method");
802 llvm_unreachable(
"Float evaluation method should be set by now");
810 CK_FloatingComplexCast)
819 CK_FloatingComplexCast)
851 assert(!Ty.
isNull() &&
"UsualUnaryConversions - missing type");
875 if (
Context.isPromotableIntegerType(Ty)) {
890 assert(!Ty.
isNull() &&
"DefaultArgumentPromotion - missing type");
902 if (BTy && (BTy->
getKind() == BuiltinType::Half ||
903 BTy->
getKind() == BuiltinType::Float)) {
906 if (BTy->
getKind() == BuiltinType::Half) {
917 Context.getTypeSizeInChars(BTy) <
923 assert(8 ==
Context.getTypeSizeInChars(
Context.LongLongTy).getQuantity() &&
924 "Unexpected typesize for LongLongTy");
978 if (
Context.getTargetInfo().getTriple().isWasm() &&
993 if (!
Record->hasNonTrivialCopyConstructor() &&
994 !
Record->hasNonTrivialMoveConstructor() &&
995 !
Record->hasNonTrivialDestructor())
1028 PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
1035 PDiag(diag::warn_pass_class_arg_to_vararg)
1043 PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
1050 diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
1054 PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
1067 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast &&
1069 (FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>()))) {
1108 if (
Call.isInvalid())
1113 if (Comma.isInvalid())
1120 diag::err_call_incomplete_argument))
1138 if (SkipCast)
return false;
1145 CK_IntegralComplexToFloatingComplex);
1163 bool PromotePrecision) {
1168 if (PromotePrecision) {
1173 if (LongerIsComplex)
1185 QualType RHSType,
bool IsCompAssign) {
1210 bool ConvertFloat,
bool ConvertInt) {
1215 CK_IntegralToFloating);
1226 CK_IntegralComplexToFloatingComplex);
1231 CK_FloatingRealToComplex);
1240 QualType RHSType,
bool IsCompAssign) {
1250 else if (!IsCompAssign)
1252 return LHSFloat ? LHSType : RHSType;
1257 if (LHSFloat && RHSFloat) {
1264 assert(order < 0 &&
"illegal float comparison");
1298 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType;
1304 if ((&LHSSem != &llvm::APFloat::PPCDoubleDouble() ||
1305 &RHSSem != &llvm::APFloat::IEEEquad()) &&
1306 (&LHSSem != &llvm::APFloat::IEEEquad() ||
1307 &RHSSem != &llvm::APFloat::PPCDoubleDouble()))
1324 CK_IntegralComplexCast);
1330template <PerformCastFn doLHSCast, PerformCastFn doRHSCast>
1333 QualType RHSType,
bool IsCompAssign) {
1338 if (LHSSigned == RHSSigned) {
1341 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1343 }
else if (!IsCompAssign)
1344 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1346 }
else if (order != (LHSSigned ? 1 : -1)) {
1350 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1352 }
else if (!IsCompAssign)
1353 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1360 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1362 }
else if (!IsCompAssign)
1363 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1372 RHS = (*doRHSCast)(S, RHS.
get(), result);
1374 LHS = (*doLHSCast)(S, LHS.
get(), result);
1384 bool IsCompAssign) {
1388 if (LHSComplexInt && RHSComplexInt) {
1393 (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign);
1398 if (LHSComplexInt) {
1402 (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign);
1405 CK_IntegralRealToComplex);
1410 assert(RHSComplexInt);
1415 (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign);
1420 CK_IntegralRealToComplex);
1428 bool IsCompAssign) {
1430 const auto *LhsOBT = LHSType->
getAs<OverflowBehaviorType>();
1431 const auto *RhsOBT = RHSType->
getAs<OverflowBehaviorType>();
1434 "Non-integer type conversion not supported for OverflowBehaviorTypes");
1437 LhsOBT && LhsOBT->getBehaviorKind() ==
1438 OverflowBehaviorType::OverflowBehaviorKind::Trap;
1440 RhsOBT && RhsOBT->getBehaviorKind() ==
1441 OverflowBehaviorType::OverflowBehaviorKind::Trap;
1443 LhsOBT && LhsOBT->getBehaviorKind() ==
1444 OverflowBehaviorType::OverflowBehaviorKind::Wrap;
1446 RhsOBT && RhsOBT->getBehaviorKind() ==
1447 OverflowBehaviorType::OverflowBehaviorKind::Wrap;
1449 QualType LHSUnderlyingType = LhsOBT ? LhsOBT->getUnderlyingType() : LHSType;
1450 QualType RHSUnderlyingType = RhsOBT ? RhsOBT->getUnderlyingType() : RHSType;
1452 std::optional<OverflowBehaviorType::OverflowBehaviorKind> DominantBehavior;
1453 if (LHSHasTrap || RHSHasTrap)
1454 DominantBehavior = OverflowBehaviorType::OverflowBehaviorKind::Trap;
1455 else if (LHSHasWrap || RHSHasWrap)
1456 DominantBehavior = OverflowBehaviorType::OverflowBehaviorKind::Wrap;
1458 QualType LHSConvType = LHSUnderlyingType;
1459 QualType RHSConvType = RHSUnderlyingType;
1460 if (DominantBehavior) {
1461 if (!LhsOBT || LhsOBT->getBehaviorKind() != *DominantBehavior)
1465 LHSConvType = LHSType;
1467 if (!RhsOBT || RhsOBT->getBehaviorKind() != *DominantBehavior)
1471 RHSConvType = RHSType;
1475 S, LHS, RHS, LHSConvType, RHSConvType, IsCompAssign);
1483 assert(BTy &&
"Expected a builtin type.");
1485 switch (BTy->getKind()) {
1486 case BuiltinType::ShortFract:
1487 case BuiltinType::UShortFract:
1488 case BuiltinType::SatShortFract:
1489 case BuiltinType::SatUShortFract:
1491 case BuiltinType::Fract:
1492 case BuiltinType::UFract:
1493 case BuiltinType::SatFract:
1494 case BuiltinType::SatUFract:
1496 case BuiltinType::LongFract:
1497 case BuiltinType::ULongFract:
1498 case BuiltinType::SatLongFract:
1499 case BuiltinType::SatULongFract:
1501 case BuiltinType::ShortAccum:
1502 case BuiltinType::UShortAccum:
1503 case BuiltinType::SatShortAccum:
1504 case BuiltinType::SatUShortAccum:
1506 case BuiltinType::Accum:
1507 case BuiltinType::UAccum:
1508 case BuiltinType::SatAccum:
1509 case BuiltinType::SatUAccum:
1511 case BuiltinType::LongAccum:
1512 case BuiltinType::ULongAccum:
1513 case BuiltinType::SatLongAccum:
1514 case BuiltinType::SatULongAccum:
1517 if (BTy->isInteger())
1519 llvm_unreachable(
"Unexpected fixed point or integer type");
1531 "Expected at least one of the operands to be a fixed point type");
1534 "Special fixed point arithmetic operation conversions are only "
1535 "applied to ints or other fixed point types");
1557 QualType ResultTy = LHSTyRank > RHSTyRank ? LHSTy : RHSTy;
1580 REnum = R->isUnscopedEnumerationType();
1582 if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
1586 ? diag::warn_arith_conv_enum_float_cxx20
1587 : diag::warn_arith_conv_enum_float)
1590 }
else if (!IsCompAssign && LEnum && REnum &&
1591 !
Context.hasSameUnqualifiedType(L, R)) {
1596 DiagID = diag::warn_conv_mixed_enum_types_cxx26;
1597 else if (!L->
castAsCanonical<EnumType>()->getDecl()->hasNameForLinkage() ||
1598 !R->castAsCanonical<EnumType>()->getDecl()->hasNameForLinkage()) {
1603 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
1604 : diag::warn_arith_conv_mixed_anon_enum_types;
1609 ? diag::warn_conditional_mixed_enum_types_cxx20
1610 : diag::warn_conditional_mixed_enum_types;
1615 ? diag::warn_comparison_mixed_enum_types_cxx20
1616 : diag::warn_comparison_mixed_enum_types;
1619 ? diag::warn_arith_conv_mixed_enum_types_cxx20
1620 : diag::warn_arith_conv_mixed_enum_types;
1623 << (int)ACK << L << R;
1641 auto IsSingleCodeUnitCP = [](
const QualType &T,
const llvm::APSInt &
Value) {
1642 if (T->isChar8Type())
1643 return llvm::IsSingleCodeUnitUTF8Codepoint(
Value.getExtValue());
1644 if (T->isChar16Type())
1645 return llvm::IsSingleCodeUnitUTF16Codepoint(
Value.getExtValue());
1646 assert(T->isChar32Type());
1647 return llvm::IsSingleCodeUnitUTF32Codepoint(
Value.getExtValue());
1660 if (LHSSuccess != RHSuccess) {
1662 if (IsSingleCodeUnitCP(LHSType, Res.
Val.
getInt()) &&
1663 IsSingleCodeUnitCP(RHSType, Res.
Val.
getInt()))
1667 if (!LHSSuccess || !RHSuccess) {
1668 SemaRef.
Diag(Loc, diag::warn_comparison_unicode_mixed_types)
1674 llvm::APSInt LHSValue(32);
1676 llvm::APSInt RHSValue(32);
1679 bool LHSSafe = IsSingleCodeUnitCP(LHSType, LHSValue);
1680 bool RHSSafe = IsSingleCodeUnitCP(RHSType, RHSValue);
1681 if (LHSSafe && RHSSafe)
1684 SemaRef.
Diag(Loc, diag::warn_comparison_unicode_mixed_types_constant)
1694 SemaRef.
Diag(Loc, diag::warn_arith_conv_mixed_unicode_types)
1728 LHSType = AtomicLHS->getValueType();
1731 if (
Context.hasSameType(LHSType, RHSType))
1732 return Context.getCommonSugaredType(LHSType, RHSType);
1740 QualType LHSUnpromotedType = LHSType;
1741 if (
Context.isPromotableIntegerType(LHSType))
1742 LHSType =
Context.getPromotedIntegerType(LHSType);
1744 if (!LHSBitfieldPromoteTy.
isNull())
1745 LHSType = LHSBitfieldPromoteTy;
1750 if (
Context.hasSameType(LHSType, RHSType))
1751 return Context.getCommonSugaredType(LHSType, RHSType);
1794 bool PredicateIsExpr,
void *ControllingExprOrType,
1796 unsigned NumAssocs = ArgTypes.size();
1797 assert(NumAssocs == ArgExprs.size());
1800 for (
unsigned i = 0; i < NumAssocs; ++i) {
1809 if (!PredicateIsExpr) {
1813 assert(ControllingType &&
"couldn't get the type out of the parser");
1814 ControllingExprOrType = ControllingType;
1818 KeyLoc, DefaultLoc, RParenLoc, PredicateIsExpr, ControllingExprOrType,
1830 const auto *TOBT = T->getAs<OverflowBehaviorType>();
1831 const auto *UOBT =
U.getCanonicalType()->getAs<OverflowBehaviorType>();
1835 if (TOBT->getBehaviorKind() == UOBT->getBehaviorKind())
1837 UOBT->getUnderlyingType());
1849 bool PredicateIsExpr,
void *ControllingExprOrType,
1851 unsigned NumAssocs = Types.size();
1852 assert(NumAssocs == Exprs.size());
1853 assert(ControllingExprOrType &&
1854 "Must have either a controlling expression or a controlling type");
1856 Expr *ControllingExpr =
nullptr;
1858 if (PredicateIsExpr) {
1865 reinterpret_cast<Expr *
>(ControllingExprOrType));
1868 ControllingExpr = R.get();
1871 ControllingType =
reinterpret_cast<TypeSourceInfo *
>(ControllingExprOrType);
1872 if (!ControllingType)
1876 bool TypeErrorFound =
false,
1877 IsResultDependent = ControllingExpr
1880 ContainsUnexpandedParameterPack =
1890 diag::warn_side_effects_unevaluated_context);
1892 for (
unsigned i = 0; i < NumAssocs; ++i) {
1893 if (Exprs[i]->containsUnexpandedParameterPack())
1894 ContainsUnexpandedParameterPack =
true;
1897 if (Types[i]->
getType()->containsUnexpandedParameterPack())
1898 ContainsUnexpandedParameterPack =
true;
1900 if (Types[i]->
getType()->isDependentType()) {
1901 IsResultDependent =
true;
1918 if (ControllingExpr && Types[i]->
getType()->isIncompleteType())
1919 D =
LangOpts.C2y ? diag::warn_c2y_compat_assoc_type_incomplete
1920 : diag::ext_assoc_type_incomplete;
1921 else if (ControllingExpr && !Types[i]->
getType()->isObjectType())
1922 D = diag::err_assoc_type_nonobject;
1923 else if (Types[i]->
getType()->isVariablyModifiedType())
1924 D = diag::err_assoc_type_variably_modified;
1925 else if (ControllingExpr) {
1944 unsigned Reason = 0;
1953 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1954 diag::warn_unreachable_association)
1955 << QT << (Reason - 1);
1959 Diag(Types[i]->getTypeLoc().getBeginLoc(), D)
1960 << Types[i]->getTypeLoc().getSourceRange() << Types[i]->getType();
1962 D, Types[i]->getTypeLoc().getBeginLoc()) >=
1964 TypeErrorFound =
true;
1969 for (
unsigned j = i+1; j < NumAssocs; ++j)
1970 if (Types[j] && !Types[j]->
getType()->isDependentType() &&
1973 Diag(Types[j]->getTypeLoc().getBeginLoc(),
1974 diag::err_assoc_compatible_types)
1975 << Types[j]->getTypeLoc().getSourceRange()
1976 << Types[j]->getType()
1977 << Types[i]->getType();
1978 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1979 diag::note_compat_assoc)
1980 << Types[i]->getTypeLoc().getSourceRange()
1981 << Types[i]->getType();
1982 TypeErrorFound =
true;
1992 if (IsResultDependent) {
1993 if (ControllingExpr)
1995 Types, Exprs, DefaultLoc, RParenLoc,
1996 ContainsUnexpandedParameterPack);
1998 Exprs, DefaultLoc, RParenLoc,
1999 ContainsUnexpandedParameterPack);
2003 unsigned DefaultIndex = std::numeric_limits<unsigned>::max();
2007 for (
unsigned i = 0; i < NumAssocs; ++i) {
2015 QualType AssocQT = Types[i]->getType();
2021 CompatIndices.push_back(i);
2025 auto GetControllingRangeAndType = [](
Expr *ControllingExpr,
2029 if (ControllingExpr)
2038 return std::make_pair(SR, QT);
2044 if (CompatIndices.size() > 1) {
2045 auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
2048 << SR << P.second << (
unsigned)CompatIndices.size();
2049 for (
unsigned I : CompatIndices) {
2050 Diag(Types[I]->getTypeLoc().getBeginLoc(),
2051 diag::note_compat_assoc)
2052 << Types[I]->getTypeLoc().getSourceRange()
2053 << Types[I]->getType();
2061 if (DefaultIndex == std::numeric_limits<unsigned>::max() &&
2062 CompatIndices.size() == 0) {
2063 auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
2065 Diag(SR.
getBegin(), diag::err_generic_sel_no_match) << SR << P.second;
2074 unsigned ResultIndex =
2075 CompatIndices.size() ? CompatIndices[0] : DefaultIndex;
2077 if (ControllingExpr) {
2079 Context, KeyLoc, ControllingExpr, Types, Exprs, DefaultLoc, RParenLoc,
2080 ContainsUnexpandedParameterPack, ResultIndex);
2083 Context, KeyLoc, ControllingType, Types, Exprs, DefaultLoc, RParenLoc,
2084 ContainsUnexpandedParameterPack, ResultIndex);
2090 llvm_unreachable(
"unexpected TokenKind");
2091 case tok::kw___func__:
2093 case tok::kw___FUNCTION__:
2095 case tok::kw___FUNCDNAME__:
2097 case tok::kw___FUNCSIG__:
2099 case tok::kw_L__FUNCTION__:
2101 case tok::kw_L__FUNCSIG__:
2103 case tok::kw___PRETTY_FUNCTION__:
2114 return cast_or_null<Decl>(DC);
2132 assert(Args.size() <= 2 &&
"too many arguments for literal operator");
2135 for (
unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
2136 ArgTy[ArgIdx] = Args[ArgIdx]->getType();
2137 if (ArgTy[ArgIdx]->isArrayType())
2158 std::vector<Token> ExpandedToks;
2164 if (Literal.hadError)
2168 for (
const Token &
Tok : StringToks)
2169 StringTokLocs.push_back(
Tok.getLocation());
2173 false, {}, StringTokLocs);
2175 if (!Literal.getUDSuffix().empty()) {
2178 Literal.getUDSuffixOffset());
2179 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
2199 CurrentDecl =
Context.getTranslationUnitDecl();
2201 std::vector<Token> ExpandedToks;
2202 ExpandedToks.reserve(Toks.size());
2206 ExpandedToks.emplace_back(
Tok);
2210 Diag(
Tok.getLocation(), diag::ext_predef_outside_function);
2212 Diag(
Tok.getLocation(), diag::ext_string_literal_from_predefined)
2215 llvm::raw_svector_ostream
OS(Str);
2216 Token &Exp = ExpandedToks.emplace_back();
2218 if (
Tok.getKind() == tok::kw_L__FUNCTION__ ||
2219 Tok.getKind() == tok::kw_L__FUNCSIG__) {
2221 Exp.
setKind(tok::wide_string_literal);
2223 Exp.
setKind(tok::string_literal);
2229 PP.CreateString(
OS.str(), Exp,
Tok.getLocation(),
Tok.getEndLoc());
2231 return ExpandedToks;
2236 assert(!StringToks.empty() &&
"Must have at least one string!");
2239 std::vector<Token> ExpandedToks;
2244 if (Literal.hadError)
2248 for (
const Token &
Tok : StringToks)
2249 StringTokLocs.push_back(
Tok.getLocation());
2253 if (Literal.isWide()) {
2254 CharTy =
Context.getWideCharType();
2256 }
else if (Literal.isUTF8()) {
2260 CharTy =
Context.UnsignedCharTy;
2262 }
else if (Literal.isUTF16()) {
2265 }
else if (Literal.isUTF32()) {
2268 }
else if (Literal.isPascal()) {
2269 CharTy =
Context.UnsignedCharTy;
2281 ? diag::warn_cxx20_compat_utf8_string
2282 : diag::warn_c23_compat_utf8_string);
2288 auto RemovalDiag =
PDiag(diag::note_cxx20_c23_compat_utf8_string_remove_u8);
2290 for (
const Token &
Tok : StringToks) {
2291 if (
Tok.getKind() == tok::utf8_string_literal) {
2293 RemovalDiagLoc =
Tok.getLocation();
2300 Diag(RemovalDiagLoc, RemovalDiag);
2304 Context.getStringLiteralArrayType(CharTy, Literal.GetNumStringChars());
2308 Context, Literal.GetString(), Kind, Literal.Pascal, StrTy, StringTokLocs);
2309 if (Literal.getUDSuffix().empty())
2316 Literal.getUDSuffixOffset());
2320 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
2327 Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix);
2332 Context.getArrayDecayedType(StrTy), SizeType
2342 llvm::APInt Len(
Context.getIntWidth(SizeType), Literal.GetNumStringChars());
2345 Expr *Args[] = { Lit, LenArg };
2362 unsigned CharBits =
Context.getIntWidth(CharTy);
2364 llvm::APSInt
Value(CharBits, CharIsUnsigned);
2371 for (
unsigned I = 0, N = Lit->
getLength(); I != N; ++I) {
2381 llvm_unreachable(
"unexpected literal operator lookup result");
2385 llvm_unreachable(
"unexpected literal operator lookup result");
2417 auto *DRE = dyn_cast<DeclRefExpr>(VD->
getInit());
2420 auto *Referee = dyn_cast<VarDecl>(DRE->getDecl());
2421 if (!Referee || !Referee->hasGlobalStorage() ||
2422 Referee->hasAttr<CUDADeviceAttr>())
2428 auto *MD = dyn_cast_or_null<CXXMethodDecl>(S.
CurContext);
2429 if (MD && MD->getParent()->isLambda() &&
2430 MD->getOverloadedOperator() == OO_Call && MD->hasAttr<CUDADeviceAttr>() &&
2452 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2453 if (VD->getType()->isReferenceType() &&
2456 VD->isUsableInConstantExpressions(
Context))
2475 Context, NNS, TemplateKWLoc, D, RefersToCapturedVariable, NameInfo, Ty,
2503 const auto *FD = dyn_cast<FieldDecl>(D);
2504 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(D))
2505 FD = IFD->getAnonField();
2509 if (FD->isBitField())
2515 if (
const auto *BD = dyn_cast<BindingDecl>(D))
2516 if (
const auto *BE = BD->getBinding())
2537 NameInfo =
Context.getNameForTemplate(TName, TNameLoc);
2538 TemplateArgs = &Buffer;
2541 TemplateArgs =
nullptr;
2549 bool isDefaultArgument =
2553 const auto *CurMethod = dyn_cast<CXXMethodDecl>(
CurContext);
2554 bool isInstance = CurMethod && CurMethod->isInstance() &&
2555 R.getNamingClass() == CurMethod->getParent() &&
2563 unsigned DiagID = diag::err_found_in_dependent_base;
2564 unsigned NoteID = diag::note_member_declared_at;
2565 if (R.getRepresentativeDecl()->getDeclContext()->Equals(R.getNamingClass())) {
2566 DiagID =
getLangOpts().MSVCCompat ? diag::ext_found_later_in_class
2567 : diag::err_found_later_in_class;
2569 DiagID = diag::ext_found_in_dependent_base;
2570 NoteID = diag::note_dependent_member_use;
2575 Diag(R.getNameLoc(), DiagID)
2576 << R.getLookupName()
2582 Diag(R.getNameLoc(), DiagID) << R.getLookupName();
2586 Diag(D->getLocation(), NoteID);
2595 if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) {
2596 Diag(R.getNameLoc(), diag::err_member_call_without_object) << 0;
2609 SourceRange NameRange = R.getLookupNameInfo().getSourceRange();
2611 unsigned diagnostic = diag::err_undeclared_var_use;
2612 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
2616 diagnostic = diag::err_undeclared_use;
2617 diagnostic_suggest = diag::err_undeclared_use_suggest;
2628 if (ExplicitTemplateArgs) {
2640 R.suppressDiagnostics();
2651 R.addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
2666 if (S && (Corrected =
2667 CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, &SS,
2670 bool DroppedSpecifier =
2674 bool AcceptableWithRecovery =
false;
2675 bool AcceptableWithoutRecovery =
false;
2684 dyn_cast<FunctionTemplateDecl>(CD))
2688 else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(CD))
2689 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->
size() == 0)
2695 ND = Best->FoundDecl;
2696 Corrected.setCorrectionDecl(ND);
2700 Corrected.setCorrectionDecl(ND);
2711 R.setNamingClass(
Record);
2728 AcceptableWithoutRecovery =
true;
2731 if (AcceptableWithRecovery || AcceptableWithoutRecovery) {
2733 ? diag::note_implicit_param_decl
2734 : diag::note_previous_decl;
2737 PDiag(NoteID), AcceptableWithRecovery);
2740 PDiag(diag::err_no_member_suggest)
2742 << DroppedSpecifier << NameRange,
2743 PDiag(NoteID), AcceptableWithRecovery);
2753 return !AcceptableWithRecovery;
2761 Diag(R.getNameLoc(), diag::err_no_member)
2767 Diag(R.getNameLoc(), diagnostic) << Name << NameRange;
2788 else if (
auto *MD = dyn_cast<CXXMethodDecl>(S.
CurContext))
2796 auto DB = S.
Diag(Loc, diag::ext_undeclared_unqual_id_with_dependent_base);
2797 DB << NameInfo.
getName() << RD;
2799 if (!ThisType.
isNull()) {
2802 Context,
nullptr, ThisType,
true,
2804 nullptr, NameInfo, TemplateArgs);
2820 bool IsAddressOfOperand,
2822 bool IsInlineAsmIdentifier) {
2823 assert(!(IsAddressOfOperand && HasTrailingLParen) &&
2824 "cannot be direct & operand and have a trailing lparen");
2853 if (
auto *VD = dyn_cast<ValueDecl>(R.getFoundDecl())) {
2867 if (TemplateKWLoc.
isValid() || TemplateArgs) {
2875 false, TemplateKWLoc,
2879 if (R.wasNotFoundInCurrentInstantiation() || SS.
isInvalid())
2881 IsAddressOfOperand, TemplateArgs);
2885 !IvarLookupFollowUp);
2889 if (R.wasNotFoundInCurrentInstantiation() || SS.
isInvalid())
2891 IsAddressOfOperand, TemplateArgs);
2895 if (IvarLookupFollowUp) {
2905 if (R.isAmbiguous())
2910 if (R.empty() && HasTrailingLParen && II &&
2913 if (D) R.addDecl(D);
2920 if (R.empty() && !ADL) {
2923 TemplateKWLoc, TemplateArgs))
2928 if (IsInlineAsmIdentifier)
2936 "Typo correction callback misconfigured");
2950 assert(!R.empty() &&
2951 "DiagnoseEmptyLookup returned false but added no results");
2958 ExprResult E(
ObjC().LookupInObjCMethod(R, S, Ivar->getIdentifier()));
2968 assert(!R.empty() || ADL);
2998 if (TemplateArgs || TemplateKWLoc.
isValid()) {
3007 "There should only be one declaration found.");
3022 if (R.isAmbiguous())
3025 if (R.wasNotFoundInCurrentInstantiation() || SS.
isInvalid())
3035 if (
const auto *CD = dyn_cast<CXXRecordDecl>(DC))
3036 if (CD->isInvalidDecl() || CD->isBeingDefined())
3046 if (
auto *TagD = dyn_cast<TagDecl>(TD)) {
3053 TL.setNameLoc(NameInfo.
getLoc());
3054 }
else if (
auto *TypedefD = dyn_cast<TypedefNameDecl>(TD)) {
3062 ET =
SemaRef.Context.getTypeDeclType(TD);
3070 unsigned DiagID = diag::err_typename_missing;
3072 DiagID = diag::ext_typename_missing;
3074 auto D =
Diag(Loc, DiagID);
3105 const auto *RD = dyn_cast<CXXRecordDecl>(
Member->getDeclContext());
3113 bool PointerConversions =
false;
3115 DestRecordType =
Context.getCanonicalTagType(RD);
3117 DestRecordType =
Context.getAddrSpaceQualType(
3118 DestRecordType, FromPtrType
3123 DestType =
Context.getPointerType(DestRecordType);
3125 PointerConversions =
true;
3127 DestType = DestRecordType;
3128 FromRecordType = FromType;
3130 }
else if (
const auto *
Method = dyn_cast<CXXMethodDecl>(
Member)) {
3131 if (!
Method->isImplicitObjectMemberFunction())
3134 DestType =
Method->getThisType().getNonReferenceType();
3135 DestRecordType =
Method->getFunctionObjectParameterType();
3139 PointerConversions =
true;
3141 FromRecordType = FromType;
3142 DestType = DestRecordType;
3147 if (FromAS != DestAS) {
3149 Context.removeAddrSpaceQualType(FromRecordType);
3151 Context.getAddrSpaceQualType(FromRecordTypeWithoutAS, DestAS);
3152 if (PointerConversions)
3153 FromTypeWithDestAS =
Context.getPointerType(FromTypeWithDestAS);
3167 if (
Context.hasSameUnqualifiedType(FromRecordType, DestRecordType))
3195 assert(QType->
isRecordType() &&
"lookup done with non-record type");
3205 FromLoc, FromRange, &BasePath))
3208 if (PointerConversions)
3209 QType =
Context.getPointerType(QType);
3211 VK, &BasePath).
get();
3214 FromRecordType = QRecordType;
3218 if (
Context.hasSameUnqualifiedType(FromRecordType, DestRecordType))
3225 FromLoc, FromRange, &BasePath,
3234 DestType =
Context.getQualifiedType(DestType, FromTypeQuals);
3242 bool HasTrailingLParen) {
3244 if (!HasTrailingLParen)
3262 if (D->isCXXClassMember())
3273 else if (D->getLexicalDeclContext()->isFunctionOrMethod())
3280 if (
const auto *FDecl = dyn_cast<FunctionDecl>(D)) {
3282 if (FDecl->getBuiltinID() && FDecl->isImplicit())
3297 bool AcceptInvalid) {
3322 assert(R.isSingleResult() &&
"Expected only a single result");
3323 const auto *FD = dyn_cast<FunctionDecl>(R.getFoundDecl());
3325 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion());
3330 bool AcceptInvalidDecl) {
3333 if (!NeedsADL && R.isSingleResult() &&
3337 R.getRepresentativeDecl(),
nullptr,
3351 R.suppressDiagnostics();
3355 R.getLookupNameInfo(), NeedsADL, R.begin(), R.end(),
3364 bool AcceptInvalidDecl) {
3365 assert(D &&
"Cannot refer to a NULL declaration");
3367 "Cannot refer unambiguously to a function template");
3386 Diag(Loc, diag::err_ref_non_value) << D << SS.
getRange();
3401 if (VD->isInvalidDecl() && !AcceptInvalidDecl)
3407 if (
auto *IndirectField = dyn_cast<IndirectFieldDecl>(VD);
3408 IndirectField && !IndirectField->isCXXClassMember())
3420 type =
type.getNonPackExpansionType();
3424#define ABSTRACT_DECL(kind)
3425#define VALUE(type, base)
3426#define DECL(type, base) case Decl::type:
3427#include "clang/AST/DeclNodes.inc"
3428 llvm_unreachable(
"invalid value decl kind");
3431 case Decl::ObjCAtDefsField:
3432 llvm_unreachable(
"forming non-member reference to ivar?");
3436 case Decl::EnumConstant:
3437 case Decl::UnresolvedUsingValue:
3438 case Decl::OMPDeclareReduction:
3439 case Decl::OMPDeclareMapper:
3448 case Decl::IndirectField:
3449 case Decl::ObjCIvar:
3451 "building reference to field in C?");
3461 case Decl::NonTypeTemplateParm: {
3463 type = reftype->getPointeeType();
3473 if (
type->isRecordType()) {
3474 type =
type.getUnqualifiedType().withConst();
3487 case Decl::VarTemplateSpecialization:
3488 case Decl::VarTemplatePartialSpecialization:
3489 case Decl::Decomposition:
3491 case Decl::OMPCapturedExpr:
3494 type->isVoidType()) {
3500 case Decl::ImplicitParam:
3501 case Decl::ParmVar: {
3511 if (!CapturedType.
isNull())
3512 type = CapturedType;
3517 case Decl::Function: {
3519 if (!
Context.BuiltinInfo.isDirectlyAddressable(BID)) {
3556 case Decl::CXXDeductionGuide:
3557 llvm_unreachable(
"building reference to deduction guide");
3559 case Decl::MSProperty:
3561 case Decl::TemplateParamObject:
3567 case Decl::UnnamedGlobalConstant:
3571 case Decl::CXXMethod:
3576 dyn_cast<FunctionProtoType>(VD->getType()))
3577 if (proto->getReturnType() ==
Context.UnknownAnyTy) {
3590 case Decl::CXXConversion:
3591 case Decl::CXXDestructor:
3592 case Decl::CXXConstructor:
3604 if (VD->isInvalidDecl() && E)
3611 Target.resize(CharByteWidth * (Source.size() + 1));
3612 char *ResultPtr = &
Target[0];
3613 const llvm::UTF8 *ErrorPtr;
3615 llvm::ConvertUTF8toWide(CharByteWidth, Source, ResultPtr, ErrorPtr);
3625 Diag(Loc, diag::ext_predef_outside_function);
3626 currentDecl =
Context.getTranslationUnitDecl();
3636 bool ForceElaboratedPrinting =
3640 unsigned Length = Str.length();
3642 llvm::APInt LengthI(32, Length + 1);
3646 Context.adjustStringLiteralBaseType(
Context.WideCharTy.withConst());
3650 ResTy =
Context.getConstantArrayType(ResTy, LengthI,
nullptr,
3656 ResTy =
Context.adjustStringLiteralBaseType(
Context.CharTy.withConst());
3657 ResTy =
Context.getConstantArrayType(ResTy, LengthI,
nullptr,
3676 StringRef ThisTok =
PP.getSpelling(
Tok, CharBuffer, &
Invalid);
3682 if (Literal.hadError())
3686 if (Literal.isWide())
3692 else if (Literal.isUTF16())
3694 else if (Literal.isUTF32())
3703 if (Literal.isWide())
3705 else if (Literal.isUTF16())
3707 else if (Literal.isUTF32())
3709 else if (Literal.isUTF8())
3715 if (Literal.getUDSuffix().empty())
3725 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_character_udl));
3730 Lit,
Tok.getLocation());
3734 unsigned IntSize =
Context.getTargetInfo().getIntWidth();
3736 llvm::APInt(IntSize, Val,
true),
3744 using llvm::APFloat;
3745 APFloat Val(Format);
3748 if (RM == llvm::RoundingMode::Dynamic)
3749 RM = llvm::RoundingMode::NearestTiesToEven;
3750 APFloat::opStatus result = Literal.GetFloatValue(Val, RM);
3754 if ((result & APFloat::opOverflow) ||
3755 ((result & APFloat::opUnderflow) && Val.isZero())) {
3756 unsigned diagnostic;
3758 if (result & APFloat::opOverflow) {
3759 diagnostic = diag::warn_float_overflow;
3760 APFloat::getLargest(Format).toString(buffer);
3762 diagnostic = diag::warn_float_underflow;
3763 APFloat::getSmallest(Format).toString(buffer);
3766 S.
Diag(Loc, diagnostic) << Ty << buffer.str();
3769 bool isExact = (result == APFloat::opOK);
3774 assert(E &&
"Invalid expression");
3781 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT;
3785 llvm::APSInt ValueAPS;
3796 bool ValueIsPositive =
3797 AllowZero ? ValueAPS.isNonNegative() : ValueAPS.isStrictlyPositive();
3798 if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
3800 <<
toString(ValueAPS, 10) << ValueIsPositive;
3810 if (
Tok.getLength() == 1 ||
Tok.getKind() == tok::binary_data) {
3811 const uint8_t Val =
PP.getSpellingOfSingleCharacterNumericConstant(
Tok);
3820 SpellingBuffer.resize(
Tok.getLength() + 1);
3824 StringRef TokSpelling =
PP.getSpelling(
Tok, SpellingBuffer, &
Invalid);
3829 PP.getSourceManager(),
PP.getLangOpts(),
3830 PP.getTargetInfo(),
PP.getDiagnostics());
3831 if (Literal.hadError)
3834 if (Literal.hasUDSuffix()) {
3842 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_numeric_udl));
3845 if (Literal.isFloatingLiteral()) {
3849 CookedTy =
Context.LongDoubleTy;
3854 CookedTy =
Context.UnsignedLongLongTy;
3858 Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix);
3870 !Literal.isImaginary)) {
3879 if (Literal.isFloatingLiteral()) {
3882 llvm::APInt ResultVal(
Context.getTargetInfo().getLongLongWidth(), 0);
3883 if (Literal.GetIntegerValue(ResultVal))
3884 Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
3896 unsigned Length = Literal.getUDSuffixOffset();
3903 false, StrTy, TokLoc);
3914 bool CharIsUnsigned =
Context.CharTy->isUnsignedIntegerType();
3915 llvm::APSInt
Value(CharBits, CharIsUnsigned);
3916 for (
unsigned I = 0, N = Literal.getUDSuffixOffset(); I != N; ++I) {
3917 Value = TokSpelling[I];
3925 llvm_unreachable(
"unexpected literal operator lookup result");
3931 if (Literal.isFixedPointLiteral()) {
3934 if (Literal.isAccum) {
3935 if (Literal.isHalf) {
3937 }
else if (Literal.isLong) {
3942 }
else if (Literal.isFract) {
3943 if (Literal.isHalf) {
3945 }
else if (Literal.isLong) {
3952 if (Literal.isUnsigned) Ty =
Context.getCorrespondingUnsignedType(Ty);
3954 bool isSigned = !Literal.isUnsigned;
3955 unsigned scale =
Context.getFixedPointScale(Ty);
3956 unsigned bit_width =
Context.getTypeInfo(Ty).Width;
3958 llvm::APInt Val(bit_width, 0, isSigned);
3959 bool Overflowed = Literal.GetFixedPointValue(Val, scale);
3960 bool ValIsZero = Val.isZero() && !Overflowed;
3962 auto MaxVal =
Context.getFixedPointMax(Ty).getValue();
3963 if (Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
3969 else if (Val.ugt(MaxVal) || Overflowed)
3970 Diag(
Tok.getLocation(), diag::err_too_large_for_fixed_point);
3973 Tok.getLocation(), scale);
3974 }
else if (Literal.isFloatingLiteral()) {
3976 if (Literal.isHalf){
3981 Diag(
Tok.getLocation(), diag::err_half_const_requires_fp16);
3984 }
else if (Literal.isFloat)
3986 else if (Literal.isLong)
3988 else if (Literal.isFloat16)
3990 else if (Literal.isFloat128)
4007 Diag(
Tok.getLocation(), diag::warn_double_const_requires_fp64)
4012 }
else if (!Literal.isIntegerLiteral()) {
4018 if (Literal.isSizeT)
4021 ? diag::warn_cxx20_compat_size_t_suffix
4022 : diag::ext_cxx23_size_t_suffix
4023 : diag::err_cxx23_size_t_suffix);
4030 if (Literal.isBitInt)
4031 PP.Diag(
Tok.getLocation(),
4034 : diag::ext_c23_bitint_suffix);
4043 unsigned BitsNeeded =
Context.getTargetInfo().getIntMaxTWidth();
4044 if (Literal.isBitInt)
4045 BitsNeeded = llvm::APInt::getSufficientBitsNeeded(
4046 Literal.getLiteralDigits(), Literal.getRadix());
4047 if (Literal.MicrosoftInteger) {
4048 if (Literal.MicrosoftInteger == 128 &&
4049 !
Context.getTargetInfo().hasInt128Type())
4050 PP.Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
4051 << Literal.isUnsigned;
4052 BitsNeeded = Literal.MicrosoftInteger;
4055 llvm::APInt ResultVal(BitsNeeded, 0);
4057 if (Literal.GetIntegerValue(ResultVal)) {
4059 Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
4061 Ty =
Context.UnsignedLongLongTy;
4062 assert(
Context.getTypeSize(Ty) == ResultVal.getBitWidth() &&
4063 "long long is not intmax_t?");
4070 bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
4077 Literal.isLong =
true;
4078 Literal.isLongLong =
false;
4085 if (Literal.MicrosoftInteger) {
4086 if (Literal.MicrosoftInteger == 8 && !Literal.isUnsigned) {
4090 Width = Literal.MicrosoftInteger;
4091 Ty =
Context.getIntTypeForBitwidth(Width,
4092 !Literal.isUnsigned);
4098 if (Literal.isBitInt) {
4101 Width = std::max(ResultVal.getActiveBits(), 1u) +
4102 (Literal.isUnsigned ? 0u : 1u);
4106 unsigned int MaxBitIntWidth =
4107 Context.getTargetInfo().getMaxBitIntWidth();
4108 if (Width > MaxBitIntWidth) {
4109 Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
4110 << Literal.isUnsigned;
4111 Width = MaxBitIntWidth;
4118 ResultVal = ResultVal.zextOrTrunc(Width);
4119 Ty =
Context.getBitIntType(Literal.isUnsigned, Width);
4123 if (Literal.isSizeT) {
4124 assert(!Literal.MicrosoftInteger &&
4125 "size_t literals can't be Microsoft literals");
4126 unsigned SizeTSize =
Context.getTargetInfo().getTypeWidth(
4127 Context.getTargetInfo().getSizeType());
4130 if (ResultVal.isIntN(SizeTSize)) {
4132 if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
4133 Ty =
Context.getSignedSizeType();
4134 else if (AllowUnsigned)
4140 if (Ty.
isNull() && !Literal.isLong && !Literal.isLongLong &&
4143 unsigned IntSize =
Context.getTargetInfo().getIntWidth();
4146 if (ResultVal.isIntN(IntSize)) {
4148 if (!Literal.isUnsigned && ResultVal[IntSize-1] == 0)
4150 else if (AllowUnsigned)
4157 if (Ty.
isNull() && !Literal.isLongLong && !Literal.isSizeT) {
4158 unsigned LongSize =
Context.getTargetInfo().getLongWidth();
4161 if (ResultVal.isIntN(LongSize)) {
4163 if (!Literal.isUnsigned && ResultVal[LongSize-1] == 0)
4165 else if (AllowUnsigned)
4170 const unsigned LongLongSize =
4171 Context.getTargetInfo().getLongLongWidth();
4175 ? diag::warn_old_implicitly_unsigned_long_cxx
4177 ext_old_implicitly_unsigned_long_cxx
4178 : diag::warn_old_implicitly_unsigned_long)
4179 << (LongLongSize > LongSize ? 0
4188 if (Ty.
isNull() && !Literal.isSizeT) {
4189 unsigned LongLongSize =
Context.getTargetInfo().getLongLongWidth();
4192 if (ResultVal.isIntN(LongLongSize)) {
4196 if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
4197 (
getLangOpts().MSVCCompat && Literal.isLongLong)))
4199 else if (AllowUnsigned)
4200 Ty =
Context.UnsignedLongLongTy;
4201 Width = LongLongSize;
4207 ? diag::warn_cxx98_compat_longlong
4208 : diag::ext_cxx11_longlong);
4210 Diag(
Tok.getLocation(), diag::ext_c99_longlong);
4218 if (Literal.isSizeT)
4219 Diag(
Tok.getLocation(), diag::err_size_t_literal_too_large)
4220 << Literal.isUnsigned;
4223 diag::ext_integer_literal_too_large_for_signed);
4224 Ty =
Context.UnsignedLongLongTy;
4225 Width =
Context.getTargetInfo().getLongLongWidth();
4228 if (ResultVal.getBitWidth() != Width)
4229 ResultVal = ResultVal.trunc(Width);
4235 if (Literal.isImaginary) {
4242 DiagId = diag::ext_gnu_imaginary_constant;
4244 DiagId = diag::warn_c23_compat_imaginary_constant;
4246 DiagId = diag::ext_c2y_imaginary_constant;
4247 Diag(
Tok.getLocation(), DiagId);
4253 assert(E &&
"ActOnParenExpr() missing expr");
4268 if (!(T->isArithmeticType() || T->isVoidType() || T->isVectorType())) {
4269 S.
Diag(Loc, diag::err_vecstep_non_scalar_vector_type)
4274 assert((T->isVoidType() || !T->isIncompleteType()) &&
4275 "Scalar types should always be complete");
4283 if (!T->isVectorType() && !T->isSizelessVectorType())
4284 return S.
Diag(Loc, diag::err_builtin_non_vector_type)
4286 <<
"__builtin_vectorelements" << T << ArgRange;
4288 if (
auto *FD = dyn_cast<FunctionDecl>(S.
CurContext)) {
4289 if (T->isSVESizelessBuiltinType()) {
4290 llvm::StringMap<bool> CallerFeatureMap;
4305 if (!T->isFunctionType() && !T->isFunctionPointerType() &&
4306 !T->isFunctionReferenceType() && !T->isMemberFunctionPointerType()) {
4307 S.
Diag(Loc, diag::err_ptrauth_type_disc_undiscriminated) << T << ArgRange;
4323 if (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
4324 TraitKind == UETT_PreferredAlignOf) {
4327 if (T->isFunctionType()) {
4328 S.
Diag(Loc, diag::ext_sizeof_alignof_function_type)
4335 if (T->isVoidType()) {
4336 unsigned DiagID = S.
LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
4337 : diag::ext_sizeof_alignof_void_type;
4352 S.
Diag(Loc, diag::err_sizeof_nonfragile_interface)
4353 << T << (TraitKind == UETT_SizeOf)
4370 const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
4371 if (!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay)
4374 S.
Diag(Loc, diag::warn_sizeof_array_decay) << ICE->getSourceRange()
4376 << ICE->getSubExpr()->getType();
4384 bool IsUnevaluatedOperand =
4385 (ExprKind == UETT_SizeOf || ExprKind == UETT_DataSizeOf ||
4386 ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4387 ExprKind == UETT_VecStep || ExprKind == UETT_CountOf);
4388 if (IsUnevaluatedOperand) {
4404 Diag(E->
getExprLoc(), diag::warn_side_effects_unevaluated_context);
4406 if (ExprKind == UETT_VecStep)
4410 if (ExprKind == UETT_VectorElements)
4421 if (
Context.getTargetInfo().getTriple().isWasm() &&
4432 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4435 diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4440 E, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4459 if (ExprKind == UETT_CountOf) {
4464 Diag(E->
getExprLoc(), diag::err_countof_arg_not_array_type) << ExprType;
4474 if (ExprKind == UETT_SizeOf) {
4475 if (
const auto *DeclRef = dyn_cast<DeclRefExpr>(E->
IgnoreParens())) {
4476 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
4477 QualType OType = PVD->getOriginalType();
4482 Diag(PVD->getLocation(), diag::note_declared_at);
4490 if (
const auto *BO = dyn_cast<BinaryOperator>(E->
IgnoreParens())) {
4507 S.
Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield)
4514 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Inner)) {
4516 }
else if (
MemberExpr *ME = dyn_cast<MemberExpr>(Inner)) {
4517 D = ME->getMemberDecl();
4537 if (
FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
4540 if (!FD->getParent()->isCompleteDefinition()) {
4541 S.
Diag(E->
getExprLoc(), diag::err_alignof_member_of_incomplete_type)
4550 if (!FD->getType()->isReferenceType())
4569 assert(T->isVariablyModifiedType());
4570 assert(CSI !=
nullptr);
4574 const Type *Ty = T.getTypePtr();
4576#define TYPE(Class, Base)
4577#define ABSTRACT_TYPE(Class, Base)
4578#define NON_CANONICAL_TYPE(Class, Base)
4579#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4580#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
4581#include "clang/AST/TypeNodes.inc"
4588 case Type::ExtVector:
4589 case Type::ConstantMatrix:
4592 case Type::TemplateSpecialization:
4593 case Type::ObjCObject:
4594 case Type::ObjCInterface:
4595 case Type::ObjCObjectPointer:
4596 case Type::ObjCTypeParam:
4599 case Type::HLSLInlineSpirv:
4600 llvm_unreachable(
"type class is never variably-modified!");
4601 case Type::Adjusted:
4607 case Type::ArrayParameter:
4613 case Type::BlockPointer:
4616 case Type::LValueReference:
4617 case Type::RValueReference:
4620 case Type::MemberPointer:
4623 case Type::ConstantArray:
4624 case Type::IncompleteArray:
4628 case Type::VariableArray: {
4642 case Type::FunctionProto:
4643 case Type::FunctionNoProto:
4648 case Type::UnaryTransform:
4649 case Type::Attributed:
4650 case Type::BTFTagAttributed:
4651 case Type::OverflowBehavior:
4652 case Type::HLSLAttributedResource:
4653 case Type::SubstTemplateTypeParm:
4654 case Type::MacroQualified:
4655 case Type::CountAttributed:
4657 T = T.getSingleStepDesugaredType(Context);
4662 case Type::Decltype:
4665 case Type::PackIndexing:
4672 case Type::DeducedTemplateSpecialization:
4675 case Type::TypeOfExpr:
4681 case Type::PredefinedSugar:
4685 }
while (!T.isNull() && T->isVariablyModifiedType());
4708 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4709 ExprKind == UETT_OpenMPRequiredSimdAlign) {
4715 ? diag::warn_c2y_compat_alignof_incomplete_array
4716 : diag::ext_c2y_alignof_incomplete_array);
4717 ExprType =
Context.getBaseElementType(ExprType);
4720 if (ExprKind == UETT_VecStep)
4723 if (ExprKind == UETT_VectorElements)
4727 if (ExprKind == UETT_PtrAuthTypeDiscriminator)
4737 OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4742 Diag(OpLoc, diag::err_sizeof_alignof_function_type) << KWName << ExprRange;
4746 if (ExprKind == UETT_CountOf) {
4750 Diag(OpLoc, diag::err_countof_arg_not_array_type) << ExprType;
4757 if (
Context.getTargetInfo().getTriple().isWasm() &&
4759 Diag(OpLoc, diag::err_wasm_table_invalid_uett_operand)
4773 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
4777 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
4778 DC = LSI->CallOperator;
4779 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
4780 DC = CRSI->TheCapturedDecl;
4781 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
4804 if (!T->isDependentType() &&
4813 (ExprKind == UETT_SizeOf || ExprKind == UETT_CountOf) &&
4823 ExprKind, TInfo,
Context.getSizeType(), OpLoc, R.getEnd());
4839 }
else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4841 }
else if (ExprKind == UETT_VecStep) {
4843 }
else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
4847 Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0;
4849 }
else if (ExprKind == UETT_VectorElements || ExprKind == UETT_SizeOf ||
4850 ExprKind == UETT_CountOf) {
4857 if ((ExprKind == UETT_SizeOf || ExprKind == UETT_CountOf) &&
4892 UETT_AlignOf, KWName);
4905 if (
V.get()->isTypeDependent())
4917 return CT->getElementType();
4920 if (
V.get()->getType()->isArithmeticType())
4921 return V.get()->getType();
4926 if (PR.
get() !=
V.get()) {
4932 S.
Diag(Loc, diag::err_realimag_invalid_type) <<
V.get()->getType()
4933 << (IsReal ?
"__real" :
"__imag");
4944 default: llvm_unreachable(
"Unknown unary op!");
4945 case tok::plusplus: Opc = UO_PostInc;
break;
4946 case tok::minusminus: Opc = UO_PostDec;
break;
4965 !S.
LangOpts.ObjCSubscriptingLegacyRuntime)
4968 S.
Diag(opLoc, diag::err_arithmetic_nonfragile_interface)
4975 auto *BaseNoParens =
Base->IgnoreParens();
4976 if (
auto *MSProp = dyn_cast<MSPropertyRefExpr>(BaseNoParens))
4977 return MSProp->getPropertyDecl()->getType()->isArrayType();
4998 if (RTy->isIntegralOrUnscopedEnumerationType()) {
5000 Result = PT->getPointeeType();
5002 Result = AT->getElementType();
5005 Result = PT->getPointeeType();
5007 Result = AT->getElementType();
5021 if (AS->isOMPArraySection())
5037 base = result.
get();
5046 auto CheckAndReportCommaError = [&](
Expr *E) {
5047 if (ArgExprs.size() > 1 ||
5049 Diag(E->getExprLoc(), diag::err_matrix_subscript_comma)
5060 Diag(base->
getExprLoc(), diag::err_matrix_separate_incomplete_index)
5066 auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
5067 if (matSubscriptE) {
5068 if (CheckAndReportCommaError(ArgExprs.front()))
5071 assert(matSubscriptE->isIncomplete() &&
5072 "base has to be an incomplete matrix subscript");
5074 matSubscriptE->getRowIdx(),
5075 ArgExprs.front(), rbLoc);
5083 CheckInvalidBuiltinCountedByRef(base,
5091 bool IsMSPropertySubscript =
false;
5094 if (!IsMSPropertySubscript) {
5098 base = result.
get();
5104 if (CheckAndReportCommaError(ArgExprs.front()))
5112 Expr *idx = ArgExprs[0];
5121 if (ArgExprs.size() == 1 &&
5122 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) {
5126 ArgExprs[0] = result.
get();
5138 base, ArgExprs.front(),
5151 if (IsMSPropertySubscript) {
5152 if (ArgExprs.size() > 1) {
5154 diag::err_ms_property_subscript_expects_single_arg);
5180 Diag(base->
getExprLoc(), diag::err_ovl_builtin_subscript_expects_single_arg)
5188 ArgExprs[0]->getType()->isRecordType())))) {
5206 return InitSeq.
Perform(*
this, Entity, Kind, E);
5220 RowIdx = RowR.
get();
5230 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5231 bool IsColumnIdx) ->
Expr * {
5239 if (std::optional<llvm::APSInt> Idx =
5241 if ((*Idx < 0 || *Idx >=
Dim)) {
5243 << IsColumnIdx <<
Dim;
5250 "should be able to convert any integer type to size type");
5251 return ConvExpr.
get();
5255 RowIdx = IsIndexValid(RowIdx, MTy->getNumRows(),
false);
5260 Context.getExtVectorType(MTy->getElementType(), MTy->getNumColumns());
5276 RowIdx = RowR.
get();
5280 Base, RowIdx, ColumnIdx,
Context.IncompleteMatrixIdxTy, RBLoc);
5291 ColumnIdx = ColumnR.
get();
5296 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5297 bool IsColumnIdx) ->
Expr * {
5305 if (std::optional<llvm::APSInt> Idx =
5307 if ((*Idx < 0 || *Idx >=
Dim)) {
5309 << IsColumnIdx <<
Dim;
5316 "should be able to convert any integer type to size type");
5317 return ConvExpr.
get();
5321 RowIdx = IsIndexValid(RowIdx, MTy->getNumRows(),
false);
5322 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(),
true);
5323 if (!RowIdx || !ColumnIdx)
5327 MTy->getElementType(), RBLoc);
5330void Sema::CheckAddressOfNoDeref(
const Expr *E) {
5337 while ((
Member = dyn_cast<MemberExpr>(StrippedExpr)) && !
Member->isArrow())
5338 StrippedExpr =
Member->getBase()->IgnoreParenImpCasts();
5340 LastRecord.PossibleDerefs.erase(StrippedExpr);
5354 if (ResultTy->
hasAttr(attr::NoDeref)) {
5355 LastRecord.PossibleDerefs.insert(E);
5362 QualType BaseTy =
Base->getType();
5367 const MemberExpr *
Member =
nullptr;
5368 while ((
Member = dyn_cast<MemberExpr>(
Base->IgnoreParenCasts())) &&
5372 if (
const auto *Ptr = dyn_cast<PointerType>(
Base->getType())) {
5373 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
5374 LastRecord.PossibleDerefs.insert(E);
5390 for (
auto *Op : {LHSExp, RHSExp}) {
5391 Op = Op->IgnoreImplicit();
5392 if (Op->getType()->isArrayType() && !Op->isLValue())
5415 Expr *BaseExpr, *IndexExpr;
5433 if (!
LangOpts.isSubscriptPointerArithmetic())
5449 if (!
LangOpts.isSubscriptPointerArithmetic()) {
5450 Diag(LLoc, diag::err_subscript_nonfragile_interface)
5474 LHSExp = Materialized.
get();
5481 Qualifiers BaseQuals = BaseType.getQualifiers();
5483 Qualifiers Combined = BaseQuals + MemberQuals;
5484 if (Combined != MemberQuals)
5485 ResultType =
Context.getQualifiedType(ResultType, Combined);
5495 CK_ArrayToPointerDecay).
get();
5501 }
else if (RHSTy->isArrayType()) {
5506 CK_ArrayToPointerDecay).
get();
5513 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_value)
5518 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_not_integer)
5524 std::optional<llvm::APSInt> IntegerContantExpr =
5526 if (!IntegerContantExpr.has_value() ||
5527 IntegerContantExpr.value().isNegative())
5543 Diag(LLoc, diag::ext_gnu_subscript_void_type)
5554 diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
5567 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
5571 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
5572 DC = LSI->CallOperator;
5573 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
5574 DC = CRSI->TheCapturedDecl;
5575 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
5593 bool SkipImmediateInvocations) {
5594 if (Param->hasUnparsedDefaultArg()) {
5595 assert(!RewrittenInit &&
"Should not have a rewritten init expression yet");
5599 Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD;
5600 Diag(CallLoc, diag::note_recursive_default_argument_used_here);
5601 Param->setInvalidDecl();
5605 Diag(CallLoc, diag::err_use_of_default_argument_to_function_declared_later)
5608 diag::note_default_argument_declared_here);
5612 if (Param->hasUninstantiatedDefaultArg()) {
5613 assert(!RewrittenInit &&
"Should not have a rewitten init expression yet");
5618 Expr *
Init = RewrittenInit ? RewrittenInit : Param->getInit();
5619 assert(
Init &&
"default argument but no initializer?");
5628 if (
auto *InitWithCleanup = dyn_cast<ExprWithCleanups>(
Init)) {
5631 Cleanup.setExprNeedsCleanups(InitWithCleanup->cleanupsHaveSideEffects());
5635 assert(!InitWithCleanup->getNumObjects() &&
5636 "default argument expression has capturing blocks?");
5649 SkipImmediateInvocations;
5737 if (!
SemaRef.CurrentInstantiationScope ||
5749 assert(Param->hasDefaultArg() &&
"can't build nonexistent default arg");
5753 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5754 InitializationContext =
5756 if (!InitializationContext.has_value())
5757 InitializationContext.emplace(CallLoc, Param,
CurContext);
5759 if (!
Init && !Param->hasUnparsedDefaultArg()) {
5774 if (Param->hasUninstantiatedDefaultArg()) {
5783 if (!NestedDefaultChecking)
5784 V.TraverseDecl(Param);
5788 if (
V.HasImmediateCalls ||
5789 (NeedRebuild && isa_and_present<ExprWithCleanups>(Param->getInit()))) {
5790 if (
V.HasImmediateCalls)
5800 Res = Immediate.TransformInitializer(Param->getInit(),
5814 CallLoc, FD, Param,
Init,
5815 NestedDefaultChecking))
5819 Init, InitializationContext->Context);
5829 ClassPattern->
lookup(Field->getDeclName());
5830 auto Rng = llvm::make_filter_range(
5841 assert(Field->hasInClassInitializer());
5847 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5848 InitializationContext =
5850 if (!InitializationContext.has_value())
5851 InitializationContext.emplace(Loc, Field,
CurContext);
5860 if (!Field->getInClassInitializer()) {
5866 assert(Pattern &&
"We must have set the Pattern!");
5870 Field->setInvalidDecl();
5882 if (!NestedDefaultChecking)
5883 V.TraverseDecl(Field);
5892 bool ContainsAnyTemporaries =
5893 isa_and_present<ExprWithCleanups>(Field->getInClassInitializer());
5894 if (Field->getInClassInitializer() &&
5895 !Field->getInClassInitializer()->containsErrors() &&
5896 (
V.HasImmediateCalls || (NeedRebuild && ContainsAnyTemporaries))) {
5900 NestedDefaultChecking;
5908 Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
5914 Field->setInvalidDecl();
5920 if (Field->getInClassInitializer()) {
5921 Expr *E =
Init ?
Init : Field->getInClassInitializer();
5922 if (!NestedDefaultChecking)
5933 Field->setInvalidDecl();
5939 Field, InitializationContext->Context,
5958 Diag(Loc, diag::err_default_member_initializer_not_yet_parsed)
5959 << OutermostClass << Field;
5960 Diag(Field->getEndLoc(),
5961 diag::note_default_member_initializer_not_yet_parsed);
5964 Field->setInvalidDecl();
5972 if (isa_and_nonnull<CXXConstructorDecl>(FDecl))
5974 else if (Fn && Fn->getType()->isBlockPointerType())
5978 if (
Method->isInstance())
5980 }
else if (Fn && Fn->getType() ==
Context.BoundMemberTy)
5993 FunctionName(FuncName) {}
5995 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
6004 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
6005 return std::make_unique<FunctionCallCCC>(*
this);
6009 const IdentifierInfo *
const FunctionName;
6025 if (
NamedDecl *ND = Corrected.getFoundDecl()) {
6026 if (Corrected.isOverloaded()) {
6036 ND = Best->FoundDecl;
6037 Corrected.setCorrectionDecl(ND);
6043 ND = ND->getUnderlyingDecl();
6058 Fn = Fn->IgnoreParens();
6060 auto *UO = dyn_cast<UnaryOperator>(Fn);
6061 if (!UO || UO->getOpcode() != clang::UO_AddrOf)
6063 if (
auto *DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr()->IgnoreParens())) {
6064 return DRE->hasQualifier();
6066 if (
auto *OVL = dyn_cast<OverloadExpr>(UO->getSubExpr()->IgnoreParens()))
6067 return bool(OVL->getQualifier());
6077 bool IsExecConfig) {
6085 if (
Context.BuiltinInfo.hasCustomTypechecking(ID) &&
6086 !(
Context.getLangOpts().HLSL && FDecl->
hasAttr<BuiltinAliasAttr>()))
6093 bool HasExplicitObjectParameter =
6095 unsigned ExplicitObjectParameterOffset = HasExplicitObjectParameter ? 1 : 0;
6099 unsigned FnKind = Fn->getType()->isBlockPointerType()
6106 if (Args.size() < NumParams) {
6107 if (Args.size() < MinArgs) {
6112 ? diag::err_typecheck_call_too_few_args_suggest
6113 : diag::err_typecheck_call_too_few_args_at_least_suggest;
6116 << FnKind << MinArgs - ExplicitObjectParameterOffset
6117 <<
static_cast<unsigned>(Args.size()) -
6118 ExplicitObjectParameterOffset
6120 }
else if (MinArgs - ExplicitObjectParameterOffset == 1 && FDecl &&
6125 ? diag::err_typecheck_call_too_few_args_one
6126 : diag::err_typecheck_call_too_few_args_at_least_one)
6127 << FnKind << FDecl->
getParamDecl(ExplicitObjectParameterOffset)
6128 << HasExplicitObjectParameter << Fn->getSourceRange();
6131 ? diag::err_typecheck_call_too_few_args
6132 : diag::err_typecheck_call_too_few_args_at_least)
6133 << FnKind << MinArgs - ExplicitObjectParameterOffset
6134 <<
static_cast<unsigned>(Args.size()) -
6135 ExplicitObjectParameterOffset
6136 << HasExplicitObjectParameter << Fn->getSourceRange();
6139 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
6147 assert((
Call->getNumArgs() == NumParams) &&
6148 "We should have reserved space for the default arguments before!");
6153 if (Args.size() > NumParams) {
6159 ? diag::err_typecheck_call_too_many_args_suggest
6160 : diag::err_typecheck_call_too_many_args_at_most_suggest;
6163 << FnKind << NumParams - ExplicitObjectParameterOffset
6164 <<
static_cast<unsigned>(Args.size()) -
6165 ExplicitObjectParameterOffset
6167 }
else if (NumParams - ExplicitObjectParameterOffset == 1 && FDecl &&
6170 Diag(Args[NumParams]->getBeginLoc(),
6171 MinArgs == NumParams
6172 ? diag::err_typecheck_call_too_many_args_one
6173 : diag::err_typecheck_call_too_many_args_at_most_one)
6174 << FnKind << FDecl->
getParamDecl(ExplicitObjectParameterOffset)
6175 <<
static_cast<unsigned>(Args.size()) -
6176 ExplicitObjectParameterOffset
6177 << HasExplicitObjectParameter << Fn->getSourceRange()
6179 Args.back()->getEndLoc());
6181 Diag(Args[NumParams]->getBeginLoc(),
6182 MinArgs == NumParams
6183 ? diag::err_typecheck_call_too_many_args
6184 : diag::err_typecheck_call_too_many_args_at_most)
6185 << FnKind << NumParams - ExplicitObjectParameterOffset
6186 <<
static_cast<unsigned>(Args.size()) -
6187 ExplicitObjectParameterOffset
6188 << HasExplicitObjectParameter << Fn->getSourceRange()
6190 Args.back()->getEndLoc());
6193 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
6198 Call->shrinkNumArgs(NumParams);
6209 unsigned TotalNumArgs = AllArgs.size();
6210 for (
unsigned i = 0; i < TotalNumArgs; ++i)
6211 Call->setArg(i, AllArgs[i]);
6213 Call->computeDependence();
6222 bool IsListInitialization) {
6227 for (
unsigned i = FirstParam; i < NumParams; i++) {
6232 if (ArgIx < Args.size()) {
6233 Arg = Args[ArgIx++];
6236 diag::err_call_incomplete_argument, Arg))
6240 bool CFAudited =
false;
6242 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
6243 (!Param || !Param->hasAttr<CFConsumedAttr>()))
6246 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
6247 (!Param || !Param->hasAttr<CFConsumedAttr>()))
6253 BE->getBlockDecl()->setDoesNotEscape();
6274 if (
const auto *OBT = Arg->
getType()->
getAs<OverflowBehaviorType>();
6277 OBT->isUnsignedIntegerOrEnumerationType() && OBT->isWrapKind();
6279 isPedantic ? diag::warn_obt_discarded_at_function_boundary_pedantic
6280 : diag::warn_obt_discarded_at_function_boundary)
6281 << Arg->
getType() << ProtoArgType;
6285 Entity,
SourceLocation(), Arg, IsListInitialization, AllowExplicit);
6291 assert(Param &&
"can't use default arguments without a known callee");
6303 CheckArrayAccess(Arg);
6308 AllArgs.push_back(Arg);
6317 for (
Expr *A : Args.slice(ArgIx)) {
6321 AllArgs.push_back(arg.get());
6326 for (
Expr *A : Args.slice(ArgIx)) {
6329 AllArgs.push_back(Arg.
get());
6334 for (
Expr *A : Args.slice(ArgIx))
6335 CheckArrayAccess(A);
6343 TL = DTL.getOriginalLoc();
6346 << ATL.getLocalSourceRange();
6352 const Expr *ArgExpr) {
6357 QualType OrigTy = Param->getOriginalType();
6382 Diag(CallLoc, diag::warn_static_array_too_small)
6390 std::optional<CharUnits> ArgSize =
6392 std::optional<CharUnits> ParmSize =
6394 if (ArgSize && ParmSize && *ArgSize < *ParmSize) {
6395 Diag(CallLoc, diag::warn_static_array_too_small)
6397 << (
unsigned)ParmSize->getQuantity() << 1;
6411 if (!placeholder)
return false;
6413 switch (placeholder->
getKind()) {
6415#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
6416 case BuiltinType::Id:
6417#include "clang/Basic/OpenCLImageTypes.def"
6418#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
6419 case BuiltinType::Id:
6420#include "clang/Basic/OpenCLExtensionTypes.def"
6423#define SVE_TYPE(Name, Id, SingletonId) \
6424 case BuiltinType::Id:
6425#include "clang/Basic/AArch64ACLETypes.def"
6426#define PPC_VECTOR_TYPE(Name, Id, Size) \
6427 case BuiltinType::Id:
6428#include "clang/Basic/PPCTypes.def"
6429#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6430#include "clang/Basic/RISCVVTypes.def"
6431#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6432#include "clang/Basic/WebAssemblyReferenceTypes.def"
6433#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
6434#include "clang/Basic/AMDGPUTypes.def"
6435#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6436#include "clang/Basic/HLSLIntangibleTypes.def"
6437#define PLACEHOLDER_TYPE(ID, SINGLETON_ID)
6438#define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID:
6439#include "clang/AST/BuiltinTypes.def"
6442 case BuiltinType::UnresolvedTemplate:
6445 case BuiltinType::Overload:
6450 case BuiltinType::ARCUnbridgedCast:
6454 case BuiltinType::PseudoObject:
6459 case BuiltinType::UnknownAny:
6463 case BuiltinType::BoundMember:
6464 case BuiltinType::BuiltinFn:
6465 case BuiltinType::IncompleteMatrixIdx:
6466 case BuiltinType::ArraySection:
6467 case BuiltinType::OMPArrayShaping:
6468 case BuiltinType::OMPIterator:
6472 llvm_unreachable(
"bad builtin type kind");
6478 bool hasInvalid =
false;
6479 for (
size_t i = 0, e = args.size(); i != e; i++) {
6482 if (result.
isInvalid()) hasInvalid =
true;
6483 else args[i] = result.
get();
6507 if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->
getBuiltinID()) || !FT ||
6511 bool NeedsNewDecl =
false;
6531 if (!ParamType->isPointerType() ||
6532 ParamType->getPointeeType().hasAddressSpace() ||
6533 !ArgType->isPointerType() ||
6534 !ArgType->getPointeeType().hasAddressSpace() ||
6536 OverloadParams.push_back(ParamType);
6541 NeedsNewDecl =
true;
6542 LangAS AS = ArgType->getPointeeType().getAddressSpace();
6544 PointeeType = Context.getAddrSpaceQualType(PointeeType, AS);
6545 OverloadParams.push_back(Context.getPointerType(PointeeType));
6555 OverloadParams, EPI);
6565 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
6572 Params.push_back(Parm);
6574 OverloadDecl->setParams(Params);
6578 if (FDecl->
hasAttr<CUDAHostAttr>())
6579 OverloadDecl->
addAttr(CUDAHostAttr::CreateImplicit(Context));
6580 if (FDecl->
hasAttr<CUDADeviceAttr>())
6581 OverloadDecl->
addAttr(CUDADeviceAttr::CreateImplicit(Context));
6584 return OverloadDecl;
6595 !Callee->isVariadic())
6597 if (Callee->getMinRequiredArguments() > ArgExprs.size())
6600 if (
const EnableIfAttr *
Attr =
6601 S.
CheckEnableIf(Callee, Fn->getBeginLoc(), ArgExprs,
true)) {
6602 S.
Diag(Fn->getBeginLoc(),
6604 ? diag::err_ovl_no_viable_member_function_in_call
6605 : diag::err_ovl_no_viable_function_in_call)
6606 << Callee << Callee->getSourceRange();
6607 S.
Diag(Callee->getLocation(),
6608 diag::note_ovl_candidate_disabled_by_function_cond_attr)
6609 <<
Attr->getCond()->getSourceRange() <<
Attr->getMessage();
6617 const auto GetFunctionLevelDCIfCXXClass =
6625 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
6626 return MD->
getParent()->getCanonicalDecl();
6629 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
6630 return RD->getCanonicalDecl();
6637 const CXXRecordDecl *
const CurParentClass = GetFunctionLevelDCIfCXXClass(S);
6638 if (!CurParentClass)
6645 assert(NamingClass &&
"Must have naming class even for implicit access");
6651 return CurParentClass == NamingClass ||
6700 if (
Call->getNumArgs() != 1)
6703 const Expr *E =
Call->getCallee()->IgnoreParenImpCasts();
6706 const DeclRefExpr *DRE = dyn_cast_if_present<DeclRefExpr>(E);
6719 if (BuiltinID != Builtin::BImove && BuiltinID != Builtin::BIforward)
6722 S.
Diag(DRE->
getLocation(), diag::warn_unqualified_call_to_std_cast_function)
6733 if (
Call.isInvalid())
6738 if (
const auto *ULE = dyn_cast<UnresolvedLookupExpr>(Fn);
6739 ULE && ULE->hasExplicitTemplateArgs() && ULE->decls().empty()) {
6740 DiagCompat(Fn->getExprLoc(), diag_compat::adl_only_template_id)
6748 if (
const auto *CE = dyn_cast<CallExpr>(
Call.get()))
6754 if (
auto *DRE = dyn_cast<DeclRefExpr>(Fn->IgnoreParens());
6755 DRE &&
Call.get()->isValueDependent()) {
6765 if (T->isDependentType())
6768 if (T == Context.BoundMemberTy || T == Context.UnknownAnyTy ||
6769 T == Context.BuiltinFnTy || T == Context.OverloadTy ||
6770 T->isFunctionType() || T->isFunctionReferenceType() ||
6771 T->isMemberFunctionPointerType() || T->isFunctionPointerType() ||
6772 T->isBlockPointerType() || T->isRecordType())
6781 Expr *ExecConfig,
bool IsExecConfig,
6782 bool AllowRecovery) {
6791 if (Fn->getType() ==
Context.BuiltinFnTy && ArgExprs.size() == 1 &&
6792 ArgExprs[0]->getType() ==
Context.BuiltinFnTy) {
6795 if (FD->getName() ==
"__builtin_amdgcn_is_invocable") {
6809 for (
const Expr *Arg : ArgExprs)
6810 if (CheckInvalidBuiltinCountedByRef(Arg,
6817 if (!ArgExprs.empty()) {
6819 Diag(Fn->getBeginLoc(), diag::err_pseudo_dtor_call_with_args)
6822 ArgExprs.back()->getEndLoc()));
6828 if (Fn->getType() ==
Context.PseudoObjectTy) {
6845 *
this, dyn_cast<UnresolvedMemberExpr>(Fn->IgnoreParens()),
6853 Diag(LParenLoc, diag::err_typecheck_call_not_function)
6854 << Fn->getType() << Fn->getSourceRange());
6862 if (Fn->getType()->isRecordType())
6866 if (Fn->getType() ==
Context.UnknownAnyTy) {
6872 if (Fn->getType() ==
Context.BoundMemberTy) {
6874 RParenLoc, ExecConfig, IsExecConfig,
6880 if (Fn->getType() ==
Context.OverloadTy) {
6891 Scope, Fn, ULE, LParenLoc, ArgExprs, RParenLoc, ExecConfig,
6894 RParenLoc, ExecConfig, IsExecConfig,
6900 if (Fn->getType() ==
Context.UnknownAnyTy) {
6906 Expr *NakedFn = Fn->IgnoreParens();
6908 bool CallingNDeclIndirectly =
false;
6910 if (
UnaryOperator *UnOp = dyn_cast<UnaryOperator>(NakedFn)) {
6911 if (UnOp->getOpcode() == UO_AddrOf) {
6912 CallingNDeclIndirectly =
true;
6917 if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
6918 NDecl = DRE->getDecl();
6922 const llvm::Triple &Triple =
Context.getTargetInfo().getTriple();
6923 if (Triple.isSPIRV() && Triple.getVendor() == llvm::Triple::AMD) {
6940 Fn->getValueKind(), FDecl,
nullptr, DRE->isNonOdrUse());
6943 }
else if (
auto *ME = dyn_cast<MemberExpr>(NakedFn))
6944 NDecl = ME->getMemberDecl();
6946 if (
FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(NDecl)) {
6948 FD,
true, Fn->getBeginLoc()))
6960 for (
unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size();
6963 if (!ArgExprs[Idx] || !Param || !Param->getType()->isPointerType() ||
6964 !ArgExprs[Idx]->getType()->isPointerType())
6968 auto ArgTy = ArgExprs[Idx]->getType();
6969 auto ArgPtTy = ArgTy->getPointeeType();
6970 auto ArgAS = ArgPtTy.getAddressSpace();
6973 bool NeedImplicitASC =
6978 if (!NeedImplicitASC)
6982 if (ArgExprs[Idx]->isGLValue()) {
6986 ArgExprs[Idx] = Res.
get();
6990 Qualifiers ArgPtQuals = ArgPtTy.getQualifiers();
6993 Context.getQualifiedType(ArgPtTy.getUnqualifiedType(), ArgPtQuals);
6996 ArgTy.getQualifiers());
7000 CK_AddressSpaceConversion)
7006 if (
Context.isDependenceAllowed() &&
7009 assert((Fn->containsErrors() ||
7010 llvm::any_of(ArgExprs,
7011 [](
clang::Expr *E) { return E->containsErrors(); })) &&
7012 "should only occur in error-recovery path.");
7017 ExecConfig, IsExecConfig);
7022 std::string Name =
Context.BuiltinInfo.getName(Id);
7028 assert(BuiltInDecl &&
"failed to find builtin declaration");
7032 assert(DeclRef.
isUsable() &&
"Builtin reference cannot fail");
7037 assert(!
Call.isInvalid() &&
"Call to builtin cannot fail!");
7057 Diag(BuiltinLoc, diag::err_invalid_astype_of_different_size)
7075 FunctionDecl *FDecl = dyn_cast_or_null<FunctionDecl>(NDecl);
7076 unsigned BuiltinID = (FDecl ? FDecl->
getBuiltinID() : 0);
7079 switch (BuiltinID) {
7080 case Builtin::BI__builtin_longjmp:
7081 case Builtin::BI__builtin_setjmp:
7082 case Builtin::BI__sigsetjmp:
7083 case Builtin::BI_longjmp:
7084 case Builtin::BI_setjmp:
7085 case Builtin::BIlongjmp:
7086 case Builtin::BIsetjmp:
7087 case Builtin::BIsiglongjmp:
7088 case Builtin::BIsigsetjmp:
7101 if (DeferParent->
Contains(*CurScope) &&
7103 Diag(Fn->getExprLoc(), diag::err_defer_invalid_sjlj) << FDecl;
7108 if (FDecl->
hasAttr<AnyX86InterruptAttr>()) {
7109 Diag(Fn->getExprLoc(), diag::err_anyx86_interrupt_called);
7112 if (FDecl->
hasAttr<ARMInterruptAttr>()) {
7113 Diag(Fn->getExprLoc(), diag::err_arm_interrupt_called);
7122 if (Caller->hasAttr<AnyX86InterruptAttr>() ||
7123 Caller->hasAttr<AnyX86NoCallerSavedRegistersAttr>()) {
7125 bool HasNonGPRRegisters =
7127 if (HasNonGPRRegisters &&
7128 (!FDecl || !FDecl->
hasAttr<AnyX86NoCallerSavedRegistersAttr>())) {
7129 Diag(Fn->getExprLoc(), diag::warn_anyx86_excessive_regsave)
7130 << (Caller->hasAttr<AnyX86InterruptAttr>() ? 0 : 1);
7149 Fn->getType()->isSpecificBuiltinType(BuiltinType::BuiltinFn)) {
7165 if (!BuiltinID || !
Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
7172 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
7173 << Fn->getType() << Fn->getSourceRange());
7179 if (Fn->getType() ==
Context.UnknownAnyTy) {
7187 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
7188 << Fn->getType() << Fn->getSourceRange());
7195 const auto *Proto = dyn_cast_or_null<FunctionProtoType>(FuncT);
7196 unsigned NumParams = Proto ? Proto->getNumParams() : 0;
7200 assert(UsesADL == ADLCallKind::NotADL &&
7201 "CUDAKernelCallExpr should not use ADL");
7212 if (BuiltinID &&
Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
7225 ExprResult E = CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7234 if (FDecl && !FDecl->
hasAttr<CUDAGlobalAttr>())
7235 return ExprError(
Diag(LParenLoc,diag::err_kern_call_not_global_function)
7236 << FDecl << Fn->getSourceRange());
7242 return ExprError(
Diag(LParenLoc, diag::err_kern_type_not_void_return)
7243 << Fn->getType() << Fn->getSourceRange());
7246 if (FDecl && FDecl->
hasAttr<CUDAGlobalAttr>())
7247 return ExprError(
Diag(LParenLoc, diag::err_global_call_not_config)
7248 << FDecl << Fn->getSourceRange());
7262 if (
Context.getTargetInfo().getTriple().isWasm()) {
7263 for (
const Expr *Arg : Args) {
7264 if (Arg && Arg->getType()->isWebAssemblyTableType()) {
7266 diag::err_wasm_table_as_function_parameter));
7284 if (!Proto || !(Proto->isVariadic() && Args.size() >= Def->
param_size()))
7285 Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
7286 << (Args.size() > Def->
param_size()) << FDecl << Fn->getSourceRange();
7305 if (!Proto && !Args.empty() &&
7307 !
Diags.isIgnored(diag::warn_strict_uses_without_prototype,
7309 Diag(LParenLoc, diag::warn_strict_uses_without_prototype)
7310 << (FDecl !=
nullptr) << FDecl;
7313 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7314 Expr *Arg = Args[i];
7316 if (Proto && i < Proto->getNumParams()) {
7318 Context, Proto->getParamType(i), Proto->isParamConsumed(i));
7336 diag::err_call_incomplete_argument, Arg))
7345 if (
Method->isImplicitObjectMemberFunction())
7346 return ExprError(
Diag(LParenLoc, diag::err_member_call_without_object)
7347 << Fn->getSourceRange() << 0);
7355 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7356 if (
const auto *RT =
7357 dyn_cast<RecordType>(Args[i]->
getType().getCanonicalType())) {
7358 if (RT->getDecl()->isOrContainsUnion())
7359 Diag(Args[i]->getBeginLoc(), diag::warn_cmse_nonsecure_union)
7370 checkFortifiedBuiltinMemoryFunction(FDecl, TheCall);
7373 return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7375 if (CheckPointerCall(NDecl, TheCall, Proto))
7378 if (CheckOtherCall(TheCall, Proto))
7388 assert(Ty &&
"ActOnCompoundLiteral(): missing type");
7389 assert(InitExpr &&
"ActOnCompoundLiteral(): missing expression");
7394 TInfo =
Context.getTrivialTypeSourceInfo(literalType);
7406 LParenLoc,
Context.getBaseElementType(literalType),
7407 diag::err_array_incomplete_or_sizeless_type,
7430 ? diag::err_variable_object_no_init
7431 : diag::err_compound_literal_with_vla_type;
7438 diag::err_typecheck_decl_incomplete_type,
7453 LiteralExpr =
Result.get();
7460 bool IsFileScope = !
CurContext->isFunctionOrMethod() &&
7491 if (
auto ILE = dyn_cast<InitListExpr>(LiteralExpr))
7492 for (
unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
7494 if (!
Init->isTypeDependent() && !
Init->isValueDependent() &&
7496 Diag(
Init->getExprLoc(), diag::err_init_element_not_constant)
7497 <<
Init->getSourceBitField();
7505 LiteralExpr, IsFileScope);
7517 Diag(LParenLoc, diag::err_compound_literal_with_address_space)
7535 Cleanup.setExprNeedsCleanups(
true);
7554 bool DiagnosedArrayDesignator =
false;
7555 bool DiagnosedNestedDesignator =
false;
7556 bool DiagnosedMixedDesignator =
false;
7560 for (
unsigned I = 0, E = InitArgList.size(); I != E; ++I) {
7561 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(InitArgList[I])) {
7563 FirstDesignator = DIE->getBeginLoc();
7568 if (!DiagnosedNestedDesignator && DIE->size() > 1) {
7569 DiagnosedNestedDesignator =
true;
7570 Diag(DIE->getBeginLoc(), diag::ext_designated_init_nested)
7571 << DIE->getDesignatorsSourceRange();
7574 for (
auto &Desig : DIE->designators()) {
7575 if (!Desig.isFieldDesignator() && !DiagnosedArrayDesignator) {
7576 DiagnosedArrayDesignator =
true;
7577 Diag(Desig.getBeginLoc(), diag::ext_designated_init_array)
7578 << Desig.getSourceRange();
7582 if (!DiagnosedMixedDesignator &&
7584 DiagnosedMixedDesignator =
true;
7585 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7586 << DIE->getSourceRange();
7587 Diag(InitArgList[0]->getBeginLoc(), diag::note_designated_init_mixed)
7588 << InitArgList[0]->getSourceRange();
7592 DiagnosedMixedDesignator =
true;
7594 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7595 << DIE->getSourceRange();
7596 Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
7597 << InitArgList[I]->getSourceRange();
7601 if (FirstDesignator.
isValid()) {
7605 !DiagnosedNestedDesignator && !DiagnosedMixedDesignator) {
7607 ? diag::warn_cxx17_compat_designated_init
7608 : diag::ext_cxx_designated_init);
7610 Diag(FirstDesignator, diag::ext_designated_init);
7614 return BuildInitList(LBraceLoc, InitArgList, RBraceLoc,
true);
7625 for (
unsigned I = 0, E = InitArgList.size(); I != E; ++I) {
7626 if (InitArgList[I]->
getType()->isNonOverloadPlaceholderType()) {
7633 InitArgList[I] = result.
get();
7653 Cleanup.setExprNeedsCleanups(
true);
7662 if (
Context.hasSameUnqualifiedType(SrcTy, DestTy))
7667 llvm_unreachable(
"member pointer type in C");
7676 if (SrcAS != DestAS)
7677 return CK_AddressSpaceConversion;
7678 if (
Context.hasCvrSimilarType(SrcTy, DestTy))
7684 ? CK_BitCast : CK_AnyPointerToBlockPointerCast);
7689 return CK_CPointerToObjCPointerCast;
7691 return CK_BlockPointerToObjCPointerCast;
7693 return CK_PointerToBoolean;
7695 return CK_PointerToIntegral;
7701 llvm_unreachable(
"illegal cast from pointer");
7703 llvm_unreachable(
"Should have returned before this");
7708 return CK_FixedPointCast;
7710 return CK_FixedPointToBoolean;
7712 return CK_FixedPointToIntegral;
7714 return CK_FixedPointToFloating;
7718 diag::err_unimplemented_conversion_with_fixed_point_type)
7720 return CK_IntegralCast;
7725 llvm_unreachable(
"illegal cast to pointer type");
7727 llvm_unreachable(
"Should have returned before this");
7737 return CK_NullToPointer;
7738 return CK_IntegralToPointer;
7740 return CK_IntegralToBoolean;
7742 return CK_IntegralCast;
7744 return CK_IntegralToFloating;
7749 return CK_IntegralRealToComplex;
7753 CK_IntegralToFloating);
7754 return CK_FloatingRealToComplex;
7756 llvm_unreachable(
"member pointer type in C");
7758 return CK_IntegralToFixedPoint;
7760 llvm_unreachable(
"Should have returned before this");
7765 return CK_FloatingCast;
7767 return CK_FloatingToBoolean;
7769 return CK_FloatingToIntegral;
7774 return CK_FloatingRealToComplex;
7778 CK_FloatingToIntegral);
7779 return CK_IntegralRealToComplex;
7783 llvm_unreachable(
"valid float->pointer cast?");
7785 llvm_unreachable(
"member pointer type in C");
7787 return CK_FloatingToFixedPoint;
7789 llvm_unreachable(
"Should have returned before this");
7794 return CK_FloatingComplexCast;
7796 return CK_FloatingComplexToIntegralComplex;
7799 if (
Context.hasSameType(ET, DestTy))
7800 return CK_FloatingComplexToReal;
7802 return CK_FloatingCast;
7805 return CK_FloatingComplexToBoolean;
7809 CK_FloatingComplexToReal);
7810 return CK_FloatingToIntegral;
7814 llvm_unreachable(
"valid complex float->pointer cast?");
7816 llvm_unreachable(
"member pointer type in C");
7819 diag::err_unimplemented_conversion_with_fixed_point_type)
7821 return CK_IntegralCast;
7823 llvm_unreachable(
"Should have returned before this");
7828 return CK_IntegralComplexToFloatingComplex;
7830 return CK_IntegralComplexCast;
7833 if (
Context.hasSameType(ET, DestTy))
7834 return CK_IntegralComplexToReal;
7836 return CK_IntegralCast;
7839 return CK_IntegralComplexToBoolean;
7843 CK_IntegralComplexToReal);
7844 return CK_IntegralToFloating;
7848 llvm_unreachable(
"valid complex int->pointer cast?");
7850 llvm_unreachable(
"member pointer type in C");
7853 diag::err_unimplemented_conversion_with_fixed_point_type)
7855 return CK_IntegralCast;
7857 llvm_unreachable(
"Should have returned before this");
7860 llvm_unreachable(
"Unhandled scalar cast");
7867 len = vecType->getNumElements();
7868 eltType = vecType->getElementType();
7875 if (!
type->isRealType())
return false;
7885 auto ValidScalableConversion = [](
QualType FirstType,
QualType SecondType) {
7889 const auto *VecTy = SecondType->getAs<
VectorType>();
7893 return ValidScalableConversion(srcTy, destTy) ||
7894 ValidScalableConversion(destTy, srcTy);
7904 return matSrcType->
getNumRows() == matDestType->getNumRows() &&
7905 matSrcType->
getNumColumns() == matDestType->getNumColumns();
7911 uint64_t SrcLen, DestLen;
7921 uint64_t SrcEltSize =
Context.getTypeSize(SrcEltTy);
7922 uint64_t DestEltSize =
Context.getTypeSize(DestEltTy);
7924 return (SrcLen * SrcEltSize == DestLen * DestEltSize);
7929 "expected at least one type to be a vector here");
7931 bool IsSrcTyAltivec =
7947 return (IsSrcTyAltivec || IsDestTyAltivec);
7967 switch (
Context.getLangOpts().getLaxVectorConversions()) {
7974 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
7979 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
7996 return Diag(R.getBegin(), diag::err_invalid_conversion_between_matrixes)
7997 << DestTy << SrcTy << R;
8000 return Diag(R.getBegin(),
8001 diag::err_invalid_conversion_between_matrix_and_type)
8002 << SrcTy << DestTy << R;
8004 return Diag(R.getBegin(),
8005 diag::err_invalid_conversion_between_matrix_and_type)
8006 << DestTy << SrcTy << R;
8009 Kind = CK_MatrixCast;
8015 assert(VectorTy->
isVectorType() &&
"Not a vector type!");
8019 return Diag(R.getBegin(),
8021 diag::err_invalid_conversion_between_vectors :
8022 diag::err_invalid_conversion_between_vector_and_integer)
8023 << VectorTy << Ty << R;
8025 return Diag(R.getBegin(),
8026 diag::err_invalid_conversion_between_vector_and_scalar)
8027 << VectorTy << Ty << R;
8036 if (DestElemTy == SplattedExpr->
getType())
8037 return SplattedExpr;
8050 CK_BooleanToSignedIntegral);
8051 SplattedExpr = CastExprRes.
get();
8052 CK = CK_IntegralToFloating;
8054 CK = CK_BooleanToSignedIntegral;
8061 SplattedExpr = CastExprRes.
get();
8069 if (DestElemTy == SplattedExpr->
getType())
8070 return SplattedExpr;
8079 SplattedExpr = CastExprRes.
get();
8097 !
Context.hasSameUnqualifiedType(DestTy, SrcTy) &&
8098 !
Context.areCompatibleVectorTypes(DestTy, SrcTy))) {
8099 Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
8100 << DestTy << SrcTy << R;
8111 return Diag(R.getBegin(),
8112 diag::err_invalid_conversion_between_vector_and_scalar)
8113 << DestTy << SrcTy << R;
8115 Kind = CK_VectorSplat;
8125 DestType == SourceType)
8133 if (!CE->getCalleeAllocSizeAttr())
8135 std::optional<llvm::APInt> AllocSize =
8136 CE->evaluateBytesReturnedByAllocSizeCall(S.
Context);
8139 if (!AllocSize || AllocSize->isZero())
8149 if (LhsSize && Size < LhsSize)
8151 << Size.getQuantity() << TargetType << LhsSize->getQuantity();
8159 "ActOnCastExpr(): missing type or expr");
8175 bool isVectorLiteral =
false;
8190 isVectorLiteral =
true;
8193 isVectorLiteral =
true;
8198 if (isVectorLiteral)
8228 "Expected paren or paren list expression");
8235 LiteralLParenLoc = PE->getLParenLoc();
8236 LiteralRParenLoc = PE->getRParenLoc();
8237 exprs = PE->getExprs();
8238 numExprs = PE->getNumExprs();
8265 if (numExprs == 1) {
8268 if (Literal.isInvalid())
8274 else if (numExprs < numElems) {
8276 diag::err_incorrect_number_of_vector_initializers);
8280 initExprs.append(exprs, exprs + numExprs);
8289 Diag(exprs[0]->getBeginLoc(), diag::err_typecheck_convert_incompatible)
8296 if (Literal.isInvalid())
8303 initExprs.append(exprs, exprs + numExprs);
8309 LiteralRParenLoc,
false);
8338 unsigned NumUserSpecifiedExprs,
8343 InitLoc, LParenLoc, RParenLoc);
8348 const Expr *NullExpr = LHSExpr;
8349 const Expr *NonPointerExpr = RHSExpr;
8356 NonPointerExpr = LHSExpr;
8378 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands_null)
8379 << NonPointerExpr->
getType() << DiagType
8391 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8392 << CondTy <<
Cond->getSourceRange();
8399 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
8400 << CondTy <<
Cond->getSourceRange();
8433 bool IsBlockPointer =
false;
8437 IsBlockPointer =
true;
8462 ResultAddrSpace = LAddrSpace;
8464 ResultAddrSpace = RAddrSpace;
8466 S.
Diag(Loc, diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
8473 auto LHSCastKind = CK_BitCast, RHSCastKind = CK_BitCast;
8478 S.
Diag(Loc, diag::err_typecheck_cond_incompatible_ptrauth)
8495 LAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8497 RAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8505 lhptee, rhptee,
false,
false,
8508 if (CompositeTy.
isNull()) {
8525 S.
Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers)
8536 QualType ResultTy = [&, ResultAddrSpace]() {
8571 S.
Diag(Loc, diag::err_typecheck_cond_incompatible_operands)
8624 bool IsIntFirstExpr) {
8626 !Int.get()->getType()->isIntegerType())
8629 Expr *Expr1 = IsIntFirstExpr ? Int.get() : PointerExpr;
8630 Expr *Expr2 = IsIntFirstExpr ? PointerExpr : Int.get();
8632 S.
Diag(Loc, diag::ext_typecheck_cond_pointer_integer_mismatch)
8636 CK_IntegralToPointer);
8670 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8676 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8682 if (LHSType == RHSType)
8692 (S, LHS, RHS, LHSType, RHSType,
false);
8726 llvm::raw_svector_ostream OS(Str);
8727 OS <<
"(vector of " << NumElements <<
" '" << EleTyName <<
"' values)";
8728 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8729 << CondTy << OS.str();
8750 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8751 <<
Cond->getType() <<
Cond->getSourceRange();
8768 S.
Diag(QuestionLoc, diag::err_conditional_vector_size)
8769 << CondTy << VecResTy;
8774 QualType RVE = RV->getElementType();
8779 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8780 << CondTy << VecResTy;
8795 if (
Cond.isInvalid())
8806 bool IsBoolVecLang =
8835 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
8836 QualType Ty = CE->getCallee()->getType();
8868 if (
Context.isDependenceAllowed() &&
8874 "should only occur in error-recovery path.");
8881 Cond.get()->getType()->isExtVectorType())
8886 if (
Cond.isInvalid())
8909 Diag(QuestionLoc, diag::err_wasm_table_conditional_expression)
8918 diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy
8937 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
8953 Context.hasSameUnqualifiedType(LHSTy, RHSTy))
8993 if (!compositeType.
isNull())
8994 return compositeType;
9024 if (
Context.hasSameType(LHSTy, RHSTy))
9025 return Context.getCommonSugaredType(LHSTy, RHSTy);
9028 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
9047 Self.Diag(Loc,
Note) << ParenRange;
9067 const Expr **RHSExprs) {
9072 if (
const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) {
9073 E = MTE->getSubExpr();
9078 if (
const auto *OP = dyn_cast<BinaryOperator>(E);
9080 *Opcode = OP->getOpcode();
9081 *RHSExprs = OP->getRHS();
9086 if (
const auto *
Call = dyn_cast<CXXOperatorCallExpr>(E)) {
9087 if (
Call->getNumArgs() != 2)
9093 if (OO < OO_Plus || OO > OO_Arrow ||
9094 OO == OO_PlusPlus || OO == OO_MinusMinus)
9100 *RHSExprs =
Call->getArg(1);
9116 if (
const auto *OP = dyn_cast<BinaryOperator>(E))
9117 return OP->isComparisonOp() || OP->isLogicalOp();
9118 if (
const auto *OP = dyn_cast<UnaryOperator>(E))
9119 return OP->getOpcode() == UO_LNot;
9134 const Expr *RHSExpr) {
9136 const Expr *CondRHS;
9147 ? diag::warn_precedence_bitwise_conditional
9148 : diag::warn_precedence_conditional;
9150 Self.Diag(OpLoc, DiagID)
9156 Self.PDiag(diag::note_precedence_silence)
9161 Self.PDiag(diag::note_precedence_conditional_first),
9172 auto GetNullability = [](
QualType Ty) {
9183 auto LHSKind = GetNullability(LHSTy), RHSKind = GetNullability(RHSTy);
9191 MergedKind = RHSKind;
9198 MergedKind = RHSKind;
9200 MergedKind = LHSKind;
9206 if (GetNullability(ResTy) == MergedKind)
9224 Expr *commonExpr =
nullptr;
9226 commonExpr = CondExpr;
9233 commonExpr = result.
get();
9247 commonExpr = commonRes.
get();
9257 commonExpr = MatExpr.
get();
9265 LHSExpr = CondExpr = opaqueValue;
9273 VK, OK, QuestionLoc);
9274 if (result.
isNull() ||
Cond.isInvalid() || LHS.isInvalid() ||
9281 CheckBoolLikeConversion(
Cond.get(), QuestionLoc);
9289 RHS.get(), result,
VK, OK);
9292 commonExpr, opaqueValue,
Cond.get(), LHS.get(), RHS.get(), QuestionLoc,
9293 ColonLoc, result,
VK, OK);
9297 unsigned FromAttributes = 0, ToAttributes = 0;
9298 if (
const auto *FromFn =
9299 dyn_cast<FunctionProtoType>(
Context.getCanonicalType(FromType)))
9302 if (
const auto *ToFn =
9303 dyn_cast<FunctionProtoType>(
Context.getCanonicalType(ToType)))
9307 return FromAttributes != ToAttributes;
9319 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9320 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9323 const Type *lhptee, *rhptee;
9325 std::tie(lhptee, lhq) =
9327 std::tie(rhptee, rhq) =
9398 diag::warn_typecheck_convert_incompatible_function_pointer_strict,
9422 ltrans = LUnderlying;
9423 rtrans = RUnderlying;
9441 if (ltrans == rtrans) {
9457 std::tie(lhptee, lhq) =
9459 std::tie(rhptee, rhq) =
9471 return AssignConvertType::
9472 IncompatibleNestedPointerAddressSpaceMismatch;
9476 if (lhptee == rhptee)
9496 const auto *LFPT = dyn_cast<FunctionProtoType>(LFT);
9497 const auto *RFPT = dyn_cast<FunctionProtoType>(RFT);
9500 LFPT->getParamTypes(),
9501 RFPT->getExtProtoInfo());
9506 LFPT->getParamTypes(), EPI);
9511 EPI.
ExtInfo = LFT->getExtInfo();
9513 RFPT->getParamTypes(), EPI);
9532 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9533 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9554 if (LQuals != RQuals)
9583 assert(LHSType.
isCanonical() &&
"LHS was not canonicalized!");
9584 assert(RHSType.
isCanonical() &&
"RHS was not canonicalized!");
9632 return VT->getElementType().getCanonicalType() == ElementType;
9662 LHSType =
Context.getCanonicalType(LHSType).getUnqualifiedType();
9663 RHSType =
Context.getCanonicalType(RHSType).getUnqualifiedType();
9666 if (LHSType == RHSType) {
9673 if (
const auto *AT = dyn_cast<AutoType>(LHSType)) {
9674 if (AT->isGNUAutoType()) {
9680 auto OBTResult =
Context.checkOBTAssignmentCompatibility(LHSType, RHSType);
9681 switch (OBTResult) {
9686 Kind = LHSType->
isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast;
9699 !
Context.areCompatibleOverflowBehaviorTypes(LHSPointee, RHSPointee)) {
9707 if (
const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
9712 if (Kind != CK_NoOp && ConvertRHS)
9714 Kind = CK_NonAtomicToAtomic;
9726 if (
Context.typesAreCompatible(LHSTypeRef->getPointeeType(), RHSType)) {
9727 Kind = CK_LValueBitCast;
9738 if (LHSExtType->getNumElements() != RHSExtType->getNumElements())
9742 RHSExtType->getElementType()->isIntegerType()) {
9743 Kind = CK_IntegralToBoolean;
9747 if (
Context.getLangOpts().OpenCL &&
9748 Context.areCompatibleVectorTypes(LHSType, RHSType)) {
9758 Kind = CK_VectorSplat;
9768 if (
Context.areCompatibleVectorTypes(LHSType, RHSType)) {
9780 if (
Context.getTargetInfo().getTriple().isPPC() &&
9782 !
Context.areCompatibleVectorTypes(RHSType, LHSType))
9784 << RHSType << LHSType;
9798 if (
Context.getTargetInfo().getTriple().isPPC() &&
9803 << RHSType << LHSType;
9814 if (
ARM().areCompatibleSveTypes(LHSType, RHSType) ||
9815 ARM().areLaxCompatibleSveTypes(LHSType, RHSType)) {
9823 if (
Context.areCompatibleRVVTypes(LHSType, RHSType) ||
9824 Context.areLaxCompatibleRVVTypes(LHSType, RHSType)) {
9853 if (
const PointerType *LHSPointer = dyn_cast<PointerType>(LHSType)) {
9856 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9858 if (AddrSpaceL != AddrSpaceR)
9859 Kind = CK_AddressSpaceConversion;
9860 else if (
Context.hasCvrSimilarType(RHSType, LHSType))
9870 Kind = CK_IntegralToPointer;
9878 if (LHSPointer->getPointeeType()->isVoidType()) {
9886 Context.getObjCClassRedefinitionType())) {
9897 if (LHSPointer->getPointeeType()->isVoidType()) {
9898 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9903 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9921 Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9927 Kind = CK_IntegralToPointer;
9933 Kind = CK_AnyPointerToBlockPointerCast;
9939 if (RHSPT->getPointeeType()->isVoidType()) {
9940 Kind = CK_AnyPointerToBlockPointerCast;
9954 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
9956 !
ObjC().CheckObjCARCUnavailableWeakConversion(OrigLHSType, RHSType))
9963 Kind = CK_IntegralToPointer;
9970 Kind = CK_CPointerToObjCPointerCast;
9980 Context.getObjCClassRedefinitionType())) {
9992 Kind = CK_BlockPointerToObjCPointerCast;
10004 Kind = CK_NullToPointer;
10011 if (LHSType ==
Context.BoolTy) {
10012 Kind = CK_PointerToBoolean;
10018 Kind = CK_PointerToIntegral;
10028 if (LHSType ==
Context.BoolTy) {
10029 Kind = CK_PointerToBoolean;
10035 Kind = CK_PointerToIntegral;
10044 if (
Context.typesAreCompatible(LHSType, RHSType)) {
10051 Kind = CK_IntToOCLSampler;
10085 const RecordType *UT =
ArgType->getAsUnionType();
10089 RecordDecl *UD = UT->getDecl()->getDefinitionOrSelf();
10090 if (!UD->
hasAttr<TransparentUnionAttr>())
10096 for (
auto *it : UD->
fields()) {
10097 if (it->getType()->isPointerType()) {
10136 bool DiagnoseCFAudited,
10140 assert((ConvertRHS || !
Diagnose) &&
"can't indicate whether we diagnosed");
10146 ExprResult &RHS = ConvertRHS ? CallerRHS : LocalRHS;
10150 if (RHSPtrType->getPointeeType()->hasAttr(attr::NoDeref) &&
10151 !LHSPtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
10153 diag::warn_noderef_to_dereferenceable_pointer)
10172 AllowedExplicit::None,
10184 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10185 !
ObjC().CheckObjCARCUnavailableWeakConversion(LHSType, RHSType))
10207 RHS.
get(), LHSType,
false, DAP))
10330 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10340 ObjC().CheckConversionToObjCLiteral(LHSType, E,
Diagnose))) {
10360struct OriginalOperand {
10361 explicit OriginalOperand(
Expr *Op) : Orig(Op), Conversion(
nullptr) {
10362 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Op))
10363 Op = MTE->getSubExpr();
10364 if (
auto *BTE = dyn_cast<CXXBindTemporaryExpr>(Op))
10365 Op = BTE->getSubExpr();
10366 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(Op)) {
10367 Orig = ICE->getSubExprAsWritten();
10368 Conversion = ICE->getConversionFunction();
10372 QualType
getType()
const {
return Orig->getType(); }
10375 NamedDecl *Conversion;
10381 OriginalOperand OrigLHS(LHS.
get()), OrigRHS(RHS.
get());
10383 Diag(Loc, diag::err_typecheck_invalid_operands)
10384 << OrigLHS.getType() << OrigRHS.getType()
10389 if (OrigLHS.Conversion) {
10390 Diag(OrigLHS.Conversion->getLocation(),
10391 diag::note_typecheck_invalid_operands_converted)
10394 if (OrigRHS.Conversion) {
10396 diag::note_typecheck_invalid_operands_converted)
10411 if (!(LHSNatVec && RHSNatVec)) {
10413 Expr *NonVector = !LHSNatVec ? LHS.
get() : RHS.
get();
10414 Diag(Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
10416 <<
Vector->getSourceRange();
10420 Diag(Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
10443 unsigned &DiagID) {
10449 scalarCast = CK_IntegralToBoolean;
10454 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
10459 scalarCast = CK_IntegralCast;
10464 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
10467 scalarCast = CK_FloatingCast;
10470 scalarCast = CK_IntegralToFloating;
10479 if (scalarCast != CK_NoOp)
10490 assert(VecTy &&
"Expression E must be a vector");
10495 VecTy->getVectorKind());
10499 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(E))
10500 if (ICE->getSubExpr()->getType() == NewVecTy)
10501 return ICE->getSubExpr();
10503 auto Cast = ElementType->
isIntegerType() ? CK_IntegralCast : CK_FloatingCast;
10511 Expr *E = Int->get();
10515 QualType IntTy = Int->get()->getType().getUnqualifiedType();
10521 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.
Context);
10530 unsigned NumBits = IntSigned
10532 :
Result.getActiveBits())
10533 :
Result.getActiveBits();
10540 return (IntSigned != OtherIntSigned &&
10546 return (Order < 0);
10553 if (Int->get()->containsErrors())
10556 QualType IntTy = Int->get()->getType().getUnqualifiedType();
10561 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.
Context);
10573 llvm::APFloat::rmTowardZero);
10576 bool Ignored =
false;
10577 Float.convertToInteger(ConvertBack, llvm::APFloat::rmNearestTiesToEven,
10579 if (
Result != ConvertBack)
10585 unsigned FloatPrec = llvm::APFloat::semanticsPrecision(
10587 if (Bits > FloatPrec)
10600 QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType();
10601 QualType VectorTy =
Vector->get()->getType().getUnqualifiedType();
10606 "ExtVectorTypes should not be handled here!");
10607 VectorEltTy = VT->getElementType();
10612 llvm_unreachable(
"Only Fixed-Length and SVE Vector types are handled here");
10638 ScalarCast = CK_IntegralCast;
10642 ScalarCast = CK_FloatingToIntegral;
10650 llvm::APFloat
Result(0.0);
10656 bool CstScalar = Scalar->get()->isValueDependent() ||
10659 if (!CstScalar && Order < 0)
10665 bool Truncated =
false;
10667 llvm::APFloat::rmNearestTiesToEven, &Truncated);
10672 ScalarCast = CK_FloatingCast;
10677 ScalarCast = CK_IntegralToFloating;
10684 if (ScalarCast != CK_NoOp)
10692 bool AllowBothBool,
10693 bool AllowBoolConversions,
10694 bool AllowBoolOperation,
10695 bool ReportInvalid) {
10696 if (!IsCompAssign) {
10712 assert(LHSVecType || RHSVecType);
10720 (RHSVecType && RHSVecType->getElementType()->isMFloat8Type()))
10725 if (!AllowBothBool && LHSVecType &&
10731 if (!AllowBoolOperation &&
10736 if (
Context.hasSameType(LHSType, RHSType))
10737 return Context.getCommonSugaredType(LHSType, RHSType);
10740 if (LHSVecType && RHSVecType &&
10741 Context.areCompatibleVectorTypes(LHSType, RHSType)) {
10755 if (AllowBoolConversions && LHSVecType && RHSVecType &&
10758 Context.getTypeSize(RHSVecType->getElementType()))) {
10765 if (!IsCompAssign &&
10768 RHSVecType->getElementType()->isIntegerType()) {
10777 unsigned &SVEorRVV) {
10798 if (IsSveRVVConversion(LHSType, RHSType, SVEorRVV) ||
10799 IsSveRVVConversion(RHSType, LHSType, SVEorRVV)) {
10800 Diag(Loc, diag::err_typecheck_sve_rvv_ambiguous)
10801 << SVEorRVV << LHSType << RHSType;
10808 unsigned &SVEorRVV) {
10813 if (FirstVecType && SecondVecType) {
10816 SecondVecType->getVectorKind() ==
10821 SecondVecType->getVectorKind() ==
10823 SecondVecType->getVectorKind() ==
10825 SecondVecType->getVectorKind() ==
10834 if (SecondVecType &&
10847 if (IsSveRVVGnuConversion(LHSType, RHSType, SVEorRVV) ||
10848 IsSveRVVGnuConversion(RHSType, LHSType, SVEorRVV)) {
10849 Diag(Loc, diag::err_typecheck_sve_rvv_gnu_ambiguous)
10850 << SVEorRVV << LHSType << RHSType;
10856 unsigned DiagID = diag::err_typecheck_vector_not_convertable;
10871 LHSType, RHSVecType->getElementType(),
10884 QualType VecType = LHSVecType ? LHSType : RHSType;
10885 const VectorType *VT = LHSVecType ? LHSVecType : RHSVecType;
10886 QualType OtherType = LHSVecType ? RHSType : LHSType;
10887 ExprResult *OtherExpr = LHSVecType ? &RHS : &LHS;
10889 if (
Context.getTargetInfo().getTriple().isPPC() &&
10891 !
Context.areCompatibleVectorTypes(RHSType, LHSType))
10892 Diag(Loc, diag::warn_deprecated_lax_vec_conv_all) << RHSType << LHSType;
10896 if (!IsCompAssign) {
10915 if ((!RHSVecType && !RHSType->
isRealType()) ||
10917 Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10918 << LHSType << RHSType
10930 Diag(Loc, diag::err_opencl_implicit_vector_conversion) << LHSType
10941 QualType Scalar = LHSVecType ? RHSType : LHSType;
10943 unsigned ScalarOrVector = LHSVecType && RHSVecType ? 1 : 0;
10945 diag::err_typecheck_vector_not_convertable_implict_truncation)
10946 << ScalarOrVector << Scalar <<
Vector;
10953 << LHSType << RHSType
10962 if (!IsCompAssign) {
10977 unsigned DiagID = diag::err_typecheck_invalid_operands;
10979 ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
10980 (RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) {
10986 if (
Context.hasSameType(LHSType, RHSType))
11001 Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
11008 Context.getBuiltinVectorTypeInfo(LHSBuiltinTy).EC !=
11009 Context.getBuiltinVectorTypeInfo(RHSBuiltinTy).EC) {
11010 Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
11019 bool ScalarOrVector =
11022 Diag(Loc, diag::err_typecheck_vector_not_convertable_implict_truncation)
11023 << ScalarOrVector << Scalar <<
Vector;
11055 S.
Diag(Loc, diag::warn_null_in_arithmetic_operation)
11067 S.
Diag(Loc, diag::warn_null_in_comparison_operation)
11068 << LHSNull << NonNullType
11080 QualType ElementType = CT->getElementType().getCanonicalType();
11081 bool IsComplexRangePromoted = S.
getLangOpts().getComplexRange() ==
11088 const llvm::fltSemantics &ElementTypeSemantics =
11090 const llvm::fltSemantics &HigherElementTypeSemantics =
11093 if ((llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
11094 llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) ||
11101 if (
Type == HigherElementType) {
11113 const auto *LUE = dyn_cast<UnaryExprOrTypeTraitExpr>(LHS);
11114 const auto *RUE = dyn_cast<UnaryExprOrTypeTraitExpr>(RHS);
11117 if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
11118 RUE->getKind() != UETT_SizeOf)
11125 if (RUE->isArgumentType())
11126 RHSTy = RUE->getArgumentType().getNonReferenceType();
11128 RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
11135 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
11136 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
11137 S.
Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
11141 QualType ArrayElemTy = ArrayTy->getElementType();
11147 S.
Diag(Loc, diag::warn_division_sizeof_array)
11149 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
11150 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
11151 S.
Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
11155 S.
Diag(Loc, diag::note_precedence_silence) << RHS;
11168 S.
PDiag(diag::warn_remainder_division_by_zero)
11177 const Expr *LHSExpr = LHS.
get();
11178 const Expr *RHSExpr = RHS.
get();
11183 if (!LHSIsScoped && !RHSIsScoped)
11195 ->getDefinitionOrSelf()
11196 ->getIntegerType();
11197 std::string InsertionString =
"static_cast<" + IntType.getAsString() +
">(";
11198 S.
Diag(BeginLoc, diag::note_no_implicit_conversion_for_scoped_enum)
11203 DiagnosticHelper(LHSExpr, LHSType);
11206 DiagnosticHelper(RHSExpr, RHSType);
11213 bool IsCompAssign = Opc == BO_MulAssign || Opc == BO_DivAssign;
11214 bool IsDiv = Opc == BO_Div || Opc == BO_DivAssign;
11308 if (compType.
isNull() ||
11313 IsCompAssign ? BO_RemAssign : BO_Rem);
11324 ? diag::err_typecheck_pointer_arith_void_type
11325 : diag::ext_gnu_void_ptr)
11334 ? diag::err_typecheck_pointer_arith_void_type
11335 : diag::ext_gnu_void_ptr)
11336 << 0 <<
Pointer->getSourceRange();
11347 S.
Diag(Loc, diag::warn_gnu_null_ptr_arith)
11348 <<
Pointer->getSourceRange();
11350 S.
Diag(Loc, diag::warn_pointer_arith_null_ptr)
11367 S.
PDiag(diag::warn_pointer_sub_null_ptr)
11369 <<
Pointer->getSourceRange());
11378 ? diag::err_typecheck_pointer_arith_function_type
11379 : diag::ext_gnu_ptr_func_arith)
11391 assert(
Pointer->getType()->isAnyPointerType());
11393 ? diag::err_typecheck_pointer_arith_function_type
11394 : diag::ext_gnu_ptr_func_arith)
11395 << 0 <<
Pointer->getType()->getPointeeType()
11397 <<
Pointer->getSourceRange();
11405 QualType ResType = Operand->getType();
11407 ResType = ResAtomicType->getValueType();
11413 diag::err_typecheck_arithmetic_incomplete_or_sizeless_type,
11414 Operand->getSourceRange());
11427 QualType ResType = Operand->getType();
11429 ResType = ResAtomicType->getValueType();
11461 if (!isLHSPointer && !isRHSPointer)
return true;
11463 QualType LHSPointeeTy, RHSPointeeTy;
11468 if (isLHSPointer && isRHSPointer) {
11472 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
11480 bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->
isVoidType();
11481 bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->
isVoidType();
11482 if (isLHSVoidPtr || isRHSVoidPtr) {
11490 bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->
isFunctionType();
11491 bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->
isFunctionType();
11492 if (isLHSFuncPtr || isRHSFuncPtr) {
11514 Expr* IndexExpr = RHSExpr;
11517 IndexExpr = LHSExpr;
11520 bool IsStringPlusInt = StrExpr &&
11526 Self.Diag(OpLoc, diag::warn_string_plus_int)
11530 if (IndexExpr == RHSExpr) {
11532 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence)
11537 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence);
11543 const Expr *StringRefExpr = LHSExpr;
11548 CharExpr = dyn_cast<CharacterLiteral>(LHSExpr->
IgnoreImpCasts());
11549 StringRefExpr = RHSExpr;
11552 if (!CharExpr || !StringRefExpr)
11572 Self.Diag(OpLoc, diag::warn_string_plus_char)
11573 << DiagRange << Ctx.
CharTy;
11575 Self.Diag(OpLoc, diag::warn_string_plus_char)
11576 << DiagRange << CharExpr->
getType();
11582 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence)
11587 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence);
11596 S.
Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
11615 if (CompLHSTy) *CompLHSTy = compType;
11624 *CompLHSTy = compType;
11633 *CompLHSTy = compType;
11644 if (Opc == BO_Add) {
11651 if (CompLHSTy) *CompLHSTy = compType;
11665 std::swap(PExp, IExp);
11678 if (!IExp->getType()->isIntegerType())
11687 (!IExp->isValueDependent() &&
11688 (!IExp->EvaluateAsInt(KnownVal,
Context) ||
11692 Context, BO_Add, PExp, IExp);
11706 Diag(Loc, diag::err_ptrauth_indirect_goto_addrlabel_arithmetic)
11712 CheckArrayAccess(PExp, IExp);
11718 if (
Context.isPromotableIntegerType(LHSTy))
11719 LHSTy =
Context.getPromotedIntegerType(LHSTy);
11721 *CompLHSTy = LHSTy;
11742 if (CompLHSTy) *CompLHSTy = compType;
11751 *CompLHSTy = compType;
11760 *CompLHSTy = compType;
11774 if (CompLHSTy) *CompLHSTy = compType;
11791 Diag(Loc, diag::err_ptrauth_indirect_goto_addrlabel_arithmetic)
11817 CheckArrayAccess(LHS.
get(), RHS.
get(),
nullptr,
11820 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11831 if (!
Context.hasSameUnqualifiedType(lpointee, rpointee)) {
11836 if (!
Context.typesAreCompatible(
11837 Context.getCanonicalType(lpointee).getUnqualifiedType(),
11838 Context.getCanonicalType(rpointee).getUnqualifiedType())) {
11864 if (ElementSize.
isZero()) {
11865 Diag(Loc,diag::warn_sub_ptr_zero_size_types)
11871 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11872 return Context.getPointerDiffType();
11882 if (
const EnumType *ET = T->getAsCanonical<EnumType>())
11883 return ET->getDecl()->isScoped();
11895 if (Opc == BO_Shr &&
11904 llvm::APSInt Right = RHSResult.
Val.
getInt();
11906 if (Right.isNegative()) {
11908 S.
PDiag(diag::warn_shift_negative)
11919 LeftSize = FXSema.getWidth() - (
unsigned)FXSema.hasUnsignedPadding();
11921 if (Right.uge(LeftSize)) {
11923 S.
PDiag(diag::warn_shift_gt_typewidth)
11943 llvm::APSInt Left = LHSResult.
Val.
getInt();
11954 if (Left.isNegative()) {
11956 S.
PDiag(diag::warn_shift_lhs_negative)
11961 llvm::APInt ResultBits =
11962 static_cast<llvm::APInt &
>(Right) + Left.getSignificantBits();
11963 if (ResultBits.ule(LeftSize))
11965 llvm::APSInt
Result = Left.extend(ResultBits.getLimitedValue());
11971 Result.toString(HexResult, 16,
false,
true);
11977 if (ResultBits - 1 == LeftSize) {
11978 S.
Diag(Loc, diag::warn_shift_result_sets_sign_bit)
11979 << HexResult << LHSType
11984 S.
Diag(Loc, diag::warn_shift_result_gt_typewidth)
11985 << HexResult.str() <<
Result.getSignificantBits() << LHSType
11997 S.
Diag(Loc, diag::err_shift_rhs_only_vector)
12003 if (!IsCompAssign) {
12025 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
12032 if (!LHSEleType->isIntegerType()) {
12033 S.
Diag(Loc, diag::err_typecheck_expect_int)
12038 if (!RHSEleType->isIntegerType()) {
12039 S.
Diag(Loc, diag::err_typecheck_expect_int)
12048 if (LHSEleType != RHSEleType) {
12050 LHSEleType = RHSEleType;
12056 }
else if (RHSVecTy) {
12061 S.
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
12069 if (LHSBT != RHSBT &&
12071 S.
Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal)
12088 bool IsCompAssign) {
12089 if (!IsCompAssign) {
12112 if ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
12113 (RHSBuiltinTy && RHSBuiltinTy->
isSVEBool())) {
12114 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
12119 if (!LHSEleType->isIntegerType()) {
12120 S.
Diag(Loc, diag::err_typecheck_expect_int)
12125 if (!RHSEleType->isIntegerType()) {
12126 S.
Diag(Loc, diag::err_typecheck_expect_int)
12134 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
12144 if (LHSEleType != RHSEleType) {
12146 LHSEleType = RHSEleType;
12148 const llvm::ElementCount VecSize =
12157 S.
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
12163 const llvm::ElementCount VecSize =
12165 if (LHSEleType != RHSEleType) {
12167 RHSEleType = LHSEleType;
12180 bool IsCompAssign) {
12214 if (IsCompAssign) LHS = OldLHS;
12242 S.
Diag(Loc, IsError ? diag::err_typecheck_comparison_of_distinct_pointers
12243 : diag::ext_typecheck_comparison_of_distinct_pointers)
12283 S.
Diag(Loc, IsError ? diag::err_typecheck_comparison_of_fptr_to_void
12284 : diag::ext_typecheck_comparison_of_fptr_to_void)
12291 case Stmt::ObjCArrayLiteralClass:
12292 case Stmt::ObjCDictionaryLiteralClass:
12293 case Stmt::ObjCStringLiteralClass:
12294 case Stmt::ObjCBoxedExprClass:
12338 QualType T = Method->parameters()[0]->getType();
12339 if (!T->isObjCObjectPointerType())
12342 QualType R = Method->getReturnType();
12343 if (!R->isScalarType())
12355 Literal = LHS.
get();
12358 Literal = RHS.
get();
12374 llvm_unreachable(
"Unknown Objective-C object literal kind");
12378 S.
Diag(Loc, diag::warn_objc_string_literal_comparison)
12379 << Literal->getSourceRange();
12381 S.
Diag(Loc, diag::warn_objc_literal_comparison)
12382 << LiteralKind << Literal->getSourceRange();
12391 S.
Diag(Loc, diag::note_objc_literal_comparison_isequal)
12404 if (!UO || UO->
getOpcode() != UO_LNot)
return;
12414 bool IsBitwiseOp = Opc == BO_And || Opc == BO_Or || Opc == BO_Xor;
12416 << Loc << IsBitwiseOp;
12443 if (
const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) {
12445 }
else if (
const MemberExpr *Mem = dyn_cast<MemberExpr>(E)) {
12446 if (Mem->isImplicitAccess())
12447 D = Mem->getMemberDecl();
12462 return std::nullopt;
12470 std::swap(LHS, RHS);
12474 std::swap(LHS, RHS);
12478 return std::nullopt;
12481 auto *BO = dyn_cast<BinaryOperator>(LHS);
12482 if (!BO || BO->getOpcode() != BO_Add)
12483 return std::nullopt;
12487 Other = BO->getRHS();
12489 Other = BO->getLHS();
12491 return std::nullopt;
12493 if (!
Other->getType()->isUnsignedIntegerType())
12494 return std::nullopt;
12496 return Opc == BO_GE;
12550 auto IsDeprArrayComparionIgnored =
12553 ? diag::warn_array_comparison_cxx26
12554 : !S.
getLangOpts().CPlusPlus20 || IsDeprArrayComparionIgnored
12555 ? diag::warn_array_comparison
12556 : diag::warn_depr_array_comparison;
12582 Result = AlwaysConstant;
12586 S.
PDiag(diag::warn_comparison_always)
12601 Result = AlwaysConstant;
12605 S.
PDiag(diag::warn_comparison_always)
12608 }
else if (std::optional<bool> Res =
12611 S.
PDiag(diag::warn_comparison_always)
12613 << (*Res ? AlwaysTrue : AlwaysFalse));
12624 Expr *LiteralString =
nullptr;
12625 Expr *LiteralStringStripped =
nullptr;
12629 LiteralString = LHS;
12630 LiteralStringStripped = LHSStripped;
12635 LiteralString = RHS;
12636 LiteralStringStripped = RHSStripped;
12639 if (LiteralString) {
12641 S.
PDiag(diag::warn_stringcompare)
12654 llvm_unreachable(
"unhandled cast kind");
12656 case CK_UserDefinedConversion:
12658 case CK_LValueToRValue:
12660 case CK_ArrayToPointerDecay:
12662 case CK_FunctionToPointerDecay:
12664 case CK_IntegralCast:
12666 case CK_FloatingCast:
12668 case CK_IntegralToFloating:
12669 case CK_FloatingToIntegral:
12671 case CK_IntegralComplexCast:
12672 case CK_FloatingComplexCast:
12673 case CK_FloatingComplexToIntegralComplex:
12674 case CK_IntegralComplexToFloatingComplex:
12676 case CK_FloatingComplexToReal:
12677 case CK_FloatingRealToComplex:
12678 case CK_IntegralComplexToReal:
12679 case CK_IntegralRealToComplex:
12681 case CK_HLSLArrayRValue:
12694 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E))
12721 << 0 << FromType << ToType;
12726 llvm_unreachable(
"unhandled case in switch");
12753 if (NumEnumArgs == 1) {
12755 QualType OtherTy = LHSIsEnum ? RHSStrippedType : LHSStrippedType;
12761 if (NumEnumArgs == 2) {
12770 assert(IntType->isArithmeticType());
12780 LHSType = RHSType = IntType;
12789 if (
Type.isNull()) {
12795 std::optional<ComparisonCategoryType> CCT =
12807 assert(!
Type.isNull() &&
"composite type for <=> has not been set");
12825 if (
Type.isNull()) {
12846 int NullValue =
PP.isMacroDefined(
"NULL") ? 0 : 1;
12851 if (
const auto *
CL = dyn_cast<CharacterLiteral>(E.
get())) {
12852 if (
CL->getValue() == 0)
12856 NullValue ?
"NULL" :
"(void *)0");
12857 }
else if (
const auto *CE = dyn_cast<CStyleCastExpr>(E.
get())) {
12864 NullValue ?
"NULL" :
"(void *)0");
12874 bool IsThreeWay = Opc == BO_Cmp;
12875 bool IsOrdered = IsRelational || IsThreeWay;
12886 if (!IsThreeWay || IsAnyPointerType(LHS) || IsAnyPointerType(RHS)) {
12939 auto computeResultTy = [&]() {
12948 std::optional<ComparisonCategoryType> CCT =
12953 if (CompositeTy->
isPointerType() && LHSIsNull != RHSIsNull) {
12957 Diag(Loc, diag::err_typecheck_three_way_comparison_of_pointer_and_zero)
12958 << (LHSIsNull ? LHS.
get()->getSourceRange()
12967 if (!IsOrdered && LHSIsNull != RHSIsNull) {
12968 bool IsEquality = Opc == BO_EQ;
12980 bool IsError = Opc == BO_Cmp;
12982 IsError ? diag::err_typecheck_ordered_comparison_of_function_pointers
12984 ? diag::warn_typecheck_ordered_comparison_of_function_pointers
12985 : diag::ext_typecheck_ordered_comparison_of_function_pointers;
13014 return computeResultTy();
13030 (IsOrdered ? 2 : 1) &&
13035 return computeResultTy();
13049 if (IsRelational) {
13054 Diag(Loc, diag::ext_typecheck_compare_complete_incomplete_pointers)
13060 }
else if (!IsRelational &&
13064 && !LHSIsNull && !RHSIsNull)
13071 if (LCanPointeeTy != RCanPointeeTy) {
13077 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
13078 << LHSType << RHSType << 0
13084 CastKind Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion
13090 bool RHSHasCFIUncheckedCallee = RFn && RFn->getCFIUncheckedCalleeAttr();
13091 bool ChangingCFIUncheckedCallee =
13092 LHSHasCFIUncheckedCallee != RHSHasCFIUncheckedCallee;
13094 if (LHSIsNull && !RHSIsNull)
13096 else if (!ChangingCFIUncheckedCallee)
13099 return computeResultTy();
13111 if (!IsOrdered && LHSIsNull && RHSIsNull) {
13114 return computeResultTy();
13118 return computeResultTy();
13129 return computeResultTy();
13133 return computeResultTy();
13142 return computeResultTy();
13147 return computeResultTy();
13151 if (IsRelational &&
13162 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
13163 if (CTSD->isInStdNamespace() &&
13164 llvm::StringSwitch<bool>(CTSD->getName())
13165 .Cases({
"less",
"less_equal",
"greater",
"greater_equal"},
true)
13171 return computeResultTy();
13184 return computeResultTy();
13194 if (!LHSIsNull && !RHSIsNull &&
13195 !
Context.typesAreCompatible(lpointee, rpointee)) {
13196 Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
13201 return computeResultTy();
13208 if (!LHSIsNull && !RHSIsNull) {
13213 Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
13217 if (LHSIsNull && !RHSIsNull)
13220 : CK_AnyPointerToBlockPointerCast);
13224 : CK_AnyPointerToBlockPointerCast);
13225 return computeResultTy();
13234 bool RPtrToVoid = RPT ? RPT->getPointeeType()->isVoidType() :
false;
13236 if (!LPtrToVoid && !RPtrToVoid &&
13237 !
Context.typesAreCompatible(LHSType, RHSType)) {
13244 if (LHSIsNull && !RHSIsNull) {
13250 RPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
13260 LPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
13262 return computeResultTy();
13266 if (!
Context.areComparableObjCPointerTypes(LHSType, RHSType))
13272 if (LHSIsNull && !RHSIsNull)
13276 return computeResultTy();
13282 CK_BlockPointerToObjCPointerCast);
13283 return computeResultTy();
13284 }
else if (!IsOrdered &&
13288 CK_BlockPointerToObjCPointerCast);
13289 return computeResultTy();
13294 unsigned DiagID = 0;
13295 bool isError =
false;
13304 isError ? diag::err_typecheck_ordered_comparison_of_pointer_and_zero
13305 : diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
13308 DiagID = diag::err_typecheck_comparison_of_pointer_integer;
13310 }
else if (IsOrdered)
13311 DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
13313 DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
13325 LHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
13328 RHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
13329 return computeResultTy();
13333 if (!IsOrdered && RHSIsNull
13336 return computeResultTy();
13338 if (!IsOrdered && LHSIsNull
13341 return computeResultTy();
13344 if (
getLangOpts().getOpenCLCompatibleVersion() >= 200) {
13346 return computeResultTy();
13350 return computeResultTy();
13353 if (LHSIsNull && RHSType->
isQueueT()) {
13355 return computeResultTy();
13358 if (LHSType->
isQueueT() && RHSIsNull) {
13360 return computeResultTy();
13385 "Unhandled vector element size in vector compare");
13405 "Unhandled vector element size in vector compare");
13415 const auto TypeSize =
Context.getTypeSize(ETy);
13417 const QualType IntTy =
Context.getIntTypeForBitwidth(TypeSize,
true);
13418 const llvm::ElementCount VecSize =
Context.getBuiltinVectorTypeInfo(VTy).EC;
13419 return Context.getScalableVectorType(IntTy, VecSize.getKnownMinValue());
13425 if (Opc == BO_Cmp) {
13426 Diag(Loc, diag::err_three_way_vector_comparison);
13455 return Context.getLogicalOperationType();
13457 Diag(Loc, diag::warn_deprecated_altivec_src_compat);
13463 return Context.getLogicalOperationType();
13487 if (Opc == BO_Cmp) {
13488 Diag(Loc, diag::err_three_way_vector_comparison);
13516 if (LHSBuiltinTy && RHSBuiltinTy && LHSBuiltinTy->
isSVEBool() &&
13517 RHSBuiltinTy->isSVEBool())
13536 bool Negative =
false;
13537 bool ExplicitPlus =
false;
13538 const auto *LHSInt = dyn_cast<IntegerLiteral>(XorLHS.
get());
13539 const auto *RHSInt = dyn_cast<IntegerLiteral>(XorRHS.
get());
13545 if (
const auto *UO = dyn_cast<UnaryOperator>(XorRHS.
get())) {
13547 if (Opc != UO_Minus && Opc != UO_Plus)
13549 RHSInt = dyn_cast<IntegerLiteral>(UO->getSubExpr());
13552 Negative = (Opc == UO_Minus);
13553 ExplicitPlus = !Negative;
13559 const llvm::APInt &LeftSideValue = LHSInt->getValue();
13560 llvm::APInt RightSideValue = RHSInt->getValue();
13561 if (LeftSideValue != 2 && LeftSideValue != 10)
13564 if (LeftSideValue.getBitWidth() != RightSideValue.getBitWidth())
13569 llvm::StringRef ExprStr =
13574 llvm::StringRef XorStr =
13577 if (XorStr ==
"xor")
13588 RightSideValue = -RightSideValue;
13589 RHSStr =
"-" + RHSStr;
13590 }
else if (ExplicitPlus) {
13591 RHSStr =
"+" + RHSStr;
13594 StringRef LHSStrRef = LHSStr;
13595 StringRef RHSStrRef = RHSStr;
13598 if (LHSStrRef.starts_with(
"0b") || LHSStrRef.starts_with(
"0B") ||
13599 RHSStrRef.starts_with(
"0b") || RHSStrRef.starts_with(
"0B") ||
13600 LHSStrRef.starts_with(
"0x") || LHSStrRef.starts_with(
"0X") ||
13601 RHSStrRef.starts_with(
"0x") || RHSStrRef.starts_with(
"0X") ||
13602 (LHSStrRef.size() > 1 && LHSStrRef.starts_with(
"0")) ||
13603 (RHSStrRef.size() > 1 && RHSStrRef.starts_with(
"0")) ||
13604 LHSStrRef.contains(
'\'') || RHSStrRef.contains(
'\''))
13609 const llvm::APInt XorValue = LeftSideValue ^ RightSideValue;
13610 int64_t RightSideIntValue = RightSideValue.getSExtValue();
13611 if (LeftSideValue == 2 && RightSideIntValue >= 0) {
13612 std::string SuggestedExpr =
"1 << " + RHSStr;
13613 bool Overflow =
false;
13614 llvm::APInt One = (LeftSideValue - 1);
13615 llvm::APInt PowValue = One.sshl_ov(RightSideValue, Overflow);
13617 if (RightSideIntValue < 64)
13618 S.
Diag(Loc, diag::warn_xor_used_as_pow_base)
13619 << ExprStr <<
toString(XorValue, 10,
true) << (
"1LL << " + RHSStr)
13621 else if (RightSideIntValue == 64)
13622 S.
Diag(Loc, diag::warn_xor_used_as_pow)
13623 << ExprStr <<
toString(XorValue, 10,
true);
13627 S.
Diag(Loc, diag::warn_xor_used_as_pow_base_extra)
13628 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedExpr
13631 ExprRange, (RightSideIntValue == 0) ?
"1" : SuggestedExpr);
13634 S.
Diag(Loc, diag::note_xor_used_as_pow_silence)
13635 << (
"0x2 ^ " + RHSStr) << SuggestXor;
13636 }
else if (LeftSideValue == 10) {
13637 std::string SuggestedValue =
"1e" + std::to_string(RightSideIntValue);
13638 S.
Diag(Loc, diag::warn_xor_used_as_pow_base)
13639 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedValue
13641 S.
Diag(Loc, diag::note_xor_used_as_pow_silence)
13642 << (
"0xA ^ " + RHSStr) << SuggestXor;
13659 getLangOpts().getOpenCLCompatibleVersion() < 120 &&
13686 assert(
false &&
"Logical operands are not supported in C\\C++");
13702 bool IsCompAssign) {
13703 if (!IsCompAssign) {
13719 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13721 if (
Context.hasSameType(LHSType, RHSType))
13722 return Context.getCommonSugaredType(LHSType, RHSType);
13728 if (LHSMatType && !RHSMatType) {
13736 if (!LHSMatType && RHSMatType) {
13748 bool IsCompAssign) {
13749 if (!IsCompAssign) {
13760 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13762 if (LHSMatType && RHSMatType) {
13763 if (LHSMatType->getNumColumns() != RHSMatType->
getNumRows())
13766 if (
Context.hasSameType(LHSMatType, RHSMatType))
13767 return Context.getCommonSugaredType(
13771 QualType LHSELTy = LHSMatType->getElementType(),
13773 if (!
Context.hasSameType(LHSELTy, RHSELTy))
13776 return Context.getConstantMatrixType(
13777 Context.getCommonSugaredType(LHSELTy, RHSELTy),
13802 bool IsCompAssign =
13803 Opc == BO_AndAssign || Opc == BO_OrAssign || Opc == BO_XorAssign;
13814 LegalBoolVecOperator,
13844 ExprResult LHSResult = LHS, RHSResult = RHS;
13846 LHSResult, RHSResult, Loc,
13848 if (LHSResult.
isInvalid() || RHSResult.isInvalid())
13850 LHS = LHSResult.
get();
13851 RHS = RHSResult.
get();
13876 bool EnumConstantInBoolContext =
false;
13878 if (
const auto *DREHS = dyn_cast<DeclRefExpr>(HS.get())) {
13879 const auto *ECDHS = dyn_cast<EnumConstantDecl>(DREHS->getDecl());
13880 if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1)
13881 EnumConstantInBoolContext =
true;
13885 if (EnumConstantInBoolContext)
13886 Diag(Loc, diag::warn_enum_constant_in_bool_context);
13891 const auto *LHSATy = dyn_cast<ArrayType>(LHSTy);
13892 const auto *RHSATy = dyn_cast<ArrayType>(RHSTy);
13893 if ((LHSATy && LHSATy->getElementType().isWebAssemblyReferenceType()) ||
13894 (RHSATy && RHSATy->getElementType().isWebAssemblyReferenceType())) {
13916 Diag(Loc, diag::warn_logical_instead_of_bitwise)
13919 Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
13920 << (Opc == BO_LAnd ?
"&" :
"|")
13923 Opc == BO_LAnd ?
"&" :
"|");
13924 if (Opc == BO_LAnd)
13926 Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
13934 if (!
Context.getLangOpts().CPlusPlus) {
13937 if (
Context.getLangOpts().OpenCL &&
13938 Context.getLangOpts().OpenCLVersion < 120) {
13993 const MemberExpr *ME = dyn_cast<MemberExpr>(E);
13994 if (!ME)
return false;
13998 if (!
Base)
return false;
13999 return Base->getMethodDecl() !=
nullptr;
14023 assert(S.
getLangOpts().CPlusPlus &&
"BindingDecl outside of C++?");
14034 assert(Var->
hasLocalStorage() &&
"capture added 'const' to non-local?");
14042 if (
auto *FD = dyn_cast<FunctionDecl>(DC))
14084 bool DiagnosticEmitted =
false;
14088 bool IsDereference =
false;
14089 bool NextIsDereference =
false;
14093 IsDereference = NextIsDereference;
14096 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
14097 NextIsDereference = ME->isArrow();
14098 const ValueDecl *VD = ME->getMemberDecl();
14099 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(VD)) {
14101 if (Field->isMutable()) {
14102 assert(DiagnosticEmitted &&
"Expected diagnostic not emitted.");
14107 if (!DiagnosticEmitted) {
14108 S.
Diag(Loc, diag::err_typecheck_assign_const)
14110 << Field->getType();
14111 DiagnosticEmitted =
true;
14114 <<
ConstMember <<
false << Field << Field->getType()
14115 << Field->getSourceRange();
14119 }
else if (
const VarDecl *VDecl = dyn_cast<VarDecl>(VD)) {
14120 if (VDecl->getType().isConstQualified()) {
14121 if (!DiagnosticEmitted) {
14122 S.
Diag(Loc, diag::err_typecheck_assign_const)
14124 << VDecl->getType();
14125 DiagnosticEmitted =
true;
14128 <<
ConstMember <<
true << VDecl << VDecl->getType()
14129 << VDecl->getSourceRange();
14136 dyn_cast<ArraySubscriptExpr>(E)) {
14140 dyn_cast<ExtVectorElementExpr>(E)) {
14147 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
14151 if (!DiagnosticEmitted) {
14152 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange
14154 DiagnosticEmitted =
true;
14157 diag::note_typecheck_assign_const)
14161 }
else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
14163 if (
const ValueDecl *VD = DRE->getDecl()) {
14165 if (!DiagnosticEmitted) {
14166 S.
Diag(Loc, diag::err_typecheck_assign_const)
14168 DiagnosticEmitted =
true;
14170 S.
Diag(VD->getLocation(), diag::note_typecheck_assign_const)
14171 <<
ConstVariable << VD << VD->getType() << VD->getSourceRange();
14176 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) {
14177 if (MD->isConst()) {
14178 if (!DiagnosticEmitted) {
14179 S.
Diag(Loc, diag::err_typecheck_assign_const_method)
14180 << ExprRange << MD;
14181 DiagnosticEmitted =
true;
14183 S.
Diag(MD->getLocation(), diag::note_typecheck_assign_const_method)
14184 << MD << MD->getSourceRange();
14190 if (DiagnosticEmitted)
14194 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange <<
ConstUnknown;
14204 const RecordType *Ty,
14207 bool &DiagnosticEmitted) {
14208 std::vector<const RecordType *> RecordTypeList;
14209 RecordTypeList.push_back(Ty);
14210 unsigned NextToCheckIndex = 0;
14213 while (RecordTypeList.size() > NextToCheckIndex) {
14214 bool IsNested = NextToCheckIndex > 0;
14215 for (
const FieldDecl *Field : RecordTypeList[NextToCheckIndex]
14220 QualType FieldTy = Field->getType();
14222 if (!DiagnosticEmitted) {
14223 S.
Diag(Loc, diag::err_typecheck_assign_const)
14225 << IsNested << Field;
14226 DiagnosticEmitted =
true;
14228 S.
Diag(Field->getLocation(), diag::note_typecheck_assign_const)
14230 << FieldTy << Field->getSourceRange();
14235 if (
const auto *FieldRecTy = FieldTy->
getAsCanonical<RecordType>()) {
14236 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
14237 RecordTypeList.push_back(FieldRecTy);
14240 ++NextToCheckIndex;
14249 assert(Ty->
isRecordType() &&
"lvalue was not record?");
14252 bool DiagEmitted =
false;
14254 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(E))
14257 else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
14282 unsigned DiagID = 0;
14283 bool NeedType =
false;
14290 DiagID = diag::err_block_decl_ref_not_modifiable_lvalue;
14292 DiagID = diag::err_lambda_decl_ref_not_modifiable_lvalue;
14305 if (var->isARCPseudoStrong() &&
14306 (!var->getTypeSourceInfo() ||
14307 !var->getTypeSourceInfo()->getType().isConstQualified())) {
14313 ? diag::err_typecheck_arc_assign_self_class_method
14314 : diag::err_typecheck_arc_assign_self;
14317 }
else if (var->hasAttr<ObjCExternallyRetainedAttr>() ||
14319 DiagID = diag::err_typecheck_arc_assign_externally_retained;
14323 DiagID = diag::err_typecheck_arr_assign_enumeration;
14327 if (Loc != OrigLoc)
14353 DiagID = diag::err_typecheck_array_not_modifiable_lvalue;
14357 DiagID = diag::err_typecheck_non_object_not_modifiable_lvalue;
14361 DiagID = diag::err_typecheck_lvalue_casts_not_supported;
14364 llvm_unreachable(
"did not take early return for MLV_Valid");
14368 DiagID = diag::err_typecheck_expression_not_modifiable_lvalue;
14373 diag::err_typecheck_incomplete_type_not_modifiable_lvalue, E);
14375 DiagID = diag::err_typecheck_duplicate_vector_components_not_mlvalue;
14378 DiagID = diag::err_typecheck_duplicate_matrix_components_not_mlvalue;
14381 llvm_unreachable(
"readonly properties should be processed differently");
14383 DiagID = diag::err_readonly_message_assignment;
14386 DiagID = diag::err_no_subobject_property_setting;
14391 if (Loc != OrigLoc)
14413 MemberExpr *ML = dyn_cast<MemberExpr>(LHSExpr);
14414 MemberExpr *MR = dyn_cast<MemberExpr>(RHSExpr);
14422 if (LHSDecl != RHSDecl)
14427 if (RefTy->getPointeeType().isVolatileQualified())
14430 Sema.
Diag(Loc, diag::warn_identity_field_assign) << 0;
14440 Sema.
Diag(Loc, diag::warn_identity_field_assign) << 1;
14464 bool ShowFullyQualifiedAssigneeName =
false;
14467 Assignee = DR->getDecl();
14468 }
else if (
auto *ME = dyn_cast<MemberExpr>(LHSExpr->
IgnoreParenCasts())) {
14469 Assignee = ME->getMemberDecl();
14470 ShowFullyQualifiedAssigneeName =
true;
14475 ShowFullyQualifiedAssigneeName);
14484 Diag(Loc, diag::err_opencl_half_load_store) << 1
14491 Diag(Loc, diag::err_wasm_table_art) << 0;
14496 if (CompoundType.
isNull()) {
14507 ((
Context.isObjCNSObjectType(LHSType) &&
14509 (
Context.isObjCNSObjectType(RHSType) &&
14514 Diag(Loc, diag::err_objc_object_assignment) << LHSType;
14520 RHSCheck = ICE->getSubExpr();
14521 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(RHSCheck)) {
14522 if ((UO->getOpcode() == UO_Plus || UO->getOpcode() == UO_Minus) &&
14523 Loc.
isFileID() && UO->getOperatorLoc().isFileID() &&
14529 UO->getSubExpr()->getBeginLoc().
isFileID()) {
14530 Diag(Loc, diag::warn_not_compound_assign)
14531 << (UO->getOpcode() == UO_Plus ?
"+" :
"-")
14532 <<
SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc());
14542 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InnerLHS);
14558 if (!
Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
14581 if (CompoundType.
isNull()) {
14607 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
14608 if (CE->getCastKind() == CK_ToVoid) {
14614 CE->getSubExpr()->getType()->isDependentType()) {
14619 if (
const auto *CE = dyn_cast<CallExpr>(E))
14620 return CE->getCallReturnType(Context)->isVoidType();
14640 const unsigned ForIncrementFlags =
14646 if ((ScopeFlags & ForIncrementFlags) == ForIncrementFlags ||
14647 (ScopeFlags & ForInitFlags) == ForInitFlags)
14652 while (
const BinaryOperator *BO = dyn_cast<BinaryOperator>(LHS)) {
14653 if (BO->getOpcode() != BO_Comma)
14655 LHS = BO->getRHS();
14662 Diag(Loc, diag::warn_comma_operator);
14666 LangOpts.CPlusPlus ?
"static_cast<void>("
14698 diag::err_incomplete_type);
14719 ResType = ResAtomicType->getValueType();
14721 assert(!ResType.
isNull() &&
"no type for increment/decrement expression");
14731 : diag::warn_increment_bool)
14735 S.
Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType;
14753 S.
Diag(OpLoc, S.
getLangOpts().C2y ? diag::warn_c2y_compat_increment_complex
14754 : diag::ext_c2y_increment_complex)
14771 S.
Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
14782 S.
Diag(OpLoc, diag::warn_deprecated_increment_decrement_volatile)
14783 << IsInc << ResType;
14815 case Stmt::DeclRefExprClass:
14817 case Stmt::MemberExprClass:
14825 case Stmt::ArraySubscriptExprClass: {
14830 if (ICE->getSubExpr()->getType()->isArrayType())
14835 case Stmt::UnaryOperatorClass: {
14847 case Stmt::ParenExprClass:
14849 case Stmt::ImplicitCastExprClass:
14853 case Stmt::CXXUuidofExprClass:
14863 AO_Vector_Element = 1,
14864 AO_Property_Expansion = 2,
14865 AO_Register_Variable = 3,
14866 AO_Matrix_Element = 4,
14884 return Diag(OpLoc, diag::err_parens_pointer_member_function)
14889 return Diag(OpLoc, diag::err_typecheck_addrof_dtor)
14890 << DRE->getSourceRange();
14892 if (DRE->getQualifier())
14896 return Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14897 << DRE->getSourceRange();
14900 StringRef Qual = (MD->
getParent()->getName() +
"::").toStringRef(Str);
14901 return Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14902 << DRE->getSourceRange()
14908 if (PTy->getKind() == BuiltinType::Overload) {
14912 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof_addrof_function)
14920 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14928 if (PTy->getKind() == BuiltinType::UnknownAny)
14931 if (PTy->getKind() == BuiltinType::BoundMember) {
14932 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14955 auto* VarRef = dyn_cast<DeclRefExpr>(op);
14956 if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
14957 Diag(op->
getExprLoc(), diag::err_opencl_taking_address_capture);
14965 if (uOp->getOpcode() == UO_Deref)
14968 return uOp->getSubExpr()->getType();
14975 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(dcl))
14981 unsigned AddressOfError = AO_No_Error;
14985 Diag(OpLoc, IsError ? diag::err_typecheck_addrof_temporary
14986 : diag::ext_typecheck_addrof_temporary)
15001 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
15019 auto ReturnOrParamTypeIsIncomplete = [&](
QualType T,
15024 diag::note_ptrauth_virtual_function_pointer_incomplete_arg_ret);
15025 Diag(RetArgTypeLoc,
15026 diag::note_ptrauth_virtual_function_incomplete_arg_ret_type)
15033 bool IsIncomplete =
15035 ReturnOrParamTypeIsIncomplete(
15038 IsIncomplete |= ReturnOrParamTypeIsIncomplete(PVD->getType(), OpLoc,
15039 PVD->getBeginLoc());
15045 if (
Context.getTargetInfo().getCXXABI().isMicrosoft())
15054 AddressOfError = AO_Property_Expansion;
15056 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof)
15060 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(op)) {
15061 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl()))
15067 AddressOfError = AO_Bit_Field;
15070 AddressOfError = AO_Vector_Element;
15073 AddressOfError = AO_Matrix_Element;
15077 if (
const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
15082 AddressOfError = AO_Register_Variable;
15085 AddressOfError = AO_Property_Expansion;
15098 if (
auto *DRE = dyn_cast<DeclRefExpr>(op);
15104 diag::err_cannot_form_pointer_to_member_of_reference_type)
15115 if (
Context.getTargetInfo().getCXXABI().isMicrosoft())
15123 llvm_unreachable(
"Unknown/unexpected decl type");
15126 if (AddressOfError != AO_No_Error) {
15143 if (
Context.getTargetInfo().getTriple().isWasm()) {
15146 Diag(OpLoc, diag::err_wasm_ca_reference)
15151 Diag(OpLoc, diag::err_wasm_table_pr)
15157 CheckAddressOfPackedMember(op);
15163 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Exp);
15169 const ParmVarDecl *Param = dyn_cast<ParmVarDecl>(D);
15172 if (
const FunctionDecl* FD = dyn_cast<FunctionDecl>(Param->getDeclContext()))
15173 if (!FD->hasAttr<NonNullAttr>() && !Param->hasAttr<NonNullAttr>())
15176 FD->ModifiedNonNullParams.insert(Param);
15182 bool IsAfterAmp =
false) {
15186 Op = ConvResult.
get();
15198 Result = PT->getPointeeType();
15202 Result = OPT->getPointeeType();
15206 if (PR.
get() != Op)
15211 S.
Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer)
15216 if (
Result->isVoidType()) {
15222 S.
Diag(OpLoc, diag::err_typecheck_indirection_through_void_pointer_cpp)
15225 S.
Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
15242 default: llvm_unreachable(
"Unknown binop!");
15243 case tok::periodstar: Opc = BO_PtrMemD;
break;
15244 case tok::arrowstar: Opc = BO_PtrMemI;
break;
15245 case tok::star: Opc = BO_Mul;
break;
15246 case tok::slash: Opc = BO_Div;
break;
15247 case tok::percent: Opc = BO_Rem;
break;
15248 case tok::plus: Opc = BO_Add;
break;
15249 case tok::minus: Opc = BO_Sub;
break;
15250 case tok::lessless: Opc = BO_Shl;
break;
15251 case tok::greatergreater: Opc = BO_Shr;
break;
15252 case tok::lessequal: Opc = BO_LE;
break;
15253 case tok::less: Opc = BO_LT;
break;
15254 case tok::greaterequal: Opc = BO_GE;
break;
15255 case tok::greater: Opc = BO_GT;
break;
15256 case tok::exclaimequal: Opc = BO_NE;
break;
15257 case tok::equalequal: Opc = BO_EQ;
break;
15258 case tok::spaceship: Opc = BO_Cmp;
break;
15259 case tok::amp: Opc = BO_And;
break;
15260 case tok::caret: Opc = BO_Xor;
break;
15261 case tok::pipe: Opc = BO_Or;
break;
15262 case tok::ampamp: Opc = BO_LAnd;
break;
15263 case tok::pipepipe: Opc = BO_LOr;
break;
15264 case tok::equal: Opc = BO_Assign;
break;
15265 case tok::starequal: Opc = BO_MulAssign;
break;
15266 case tok::slashequal: Opc = BO_DivAssign;
break;
15267 case tok::percentequal: Opc = BO_RemAssign;
break;
15268 case tok::plusequal: Opc = BO_AddAssign;
break;
15269 case tok::minusequal: Opc = BO_SubAssign;
break;
15270 case tok::lesslessequal: Opc = BO_ShlAssign;
break;
15271 case tok::greatergreaterequal: Opc = BO_ShrAssign;
break;
15272 case tok::ampequal: Opc = BO_AndAssign;
break;
15273 case tok::caretequal: Opc = BO_XorAssign;
break;
15274 case tok::pipeequal: Opc = BO_OrAssign;
break;
15275 case tok::comma: Opc = BO_Comma;
break;
15284 default: llvm_unreachable(
"Unknown unary op!");
15285 case tok::plusplus: Opc = UO_PreInc;
break;
15286 case tok::minusminus: Opc = UO_PreDec;
break;
15287 case tok::amp: Opc = UO_AddrOf;
break;
15288 case tok::star: Opc = UO_Deref;
break;
15289 case tok::plus: Opc = UO_Plus;
break;
15290 case tok::minus: Opc = UO_Minus;
break;
15291 case tok::tilde: Opc = UO_Not;
break;
15292 case tok::exclaim: Opc = UO_LNot;
break;
15293 case tok::kw___real: Opc = UO_Real;
break;
15294 case tok::kw___imag: Opc = UO_Imag;
break;
15295 case tok::kw___extension__: Opc = UO_Extension;
break;
15327 llvm::find_if(Parent->
fields(),
15329 return F->getDeclName() == Name;
15331 return (Field != Parent->
field_end()) ? *Field :
nullptr;
15346 const DeclRefExpr *LHSDeclRef = dyn_cast<DeclRefExpr>(LHSExpr);
15347 const DeclRefExpr *RHSDeclRef = dyn_cast<DeclRefExpr>(RHSExpr);
15348 if (!LHSDeclRef || !RHSDeclRef ||
15356 if (LHSDecl != RHSDecl)
15361 if (RefTy->getPointeeType().isVolatileQualified())
15364 auto Diag = S.
Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
15365 : diag::warn_self_assignment_overloaded)
15370 Diag << 1 << SelfAssignField
15383 const Expr *ObjCPointerExpr =
nullptr, *OtherExpr =
nullptr;
15385 const Expr *RHS = R.get();
15388 ObjCPointerExpr = LHS;
15392 ObjCPointerExpr = RHS;
15401 unsigned Diag = diag::warn_objc_pointer_masking;
15410 if (SelArg0.starts_with(
"performSelector"))
15411 Diag = diag::warn_objc_pointer_masking_performSelector;
15428 assert((
isVector(ResultTy, Context.HalfTy) ||
15429 isVector(ResultTy, Context.ShortTy)) &&
15430 "Result must be a vector of half or short");
15433 "both operands expected to be a half vector");
15440 if (
isVector(ResultTy, Context.ShortTy))
15445 ResultTy,
VK, OK, OpLoc, FPFeatures,
15446 BinOpResTy, BinOpResTy);
15450 BinOpResTy,
VK, OK, OpLoc, FPFeatures);
15458 if (!OpRequiresConversion || Ctx.
getLangOpts().NativeHalfType ||
15462 auto HasVectorOfHalfType = [&Ctx](
Expr *E) {
15472 return VT->getElementType().getCanonicalType() == Ctx.
HalfTy;
15477 return HasVectorOfHalfType(E0) && (!E1 || HasVectorOfHalfType(E1));
15482 Expr *RHSExpr,
bool ForFoldExpression) {
15496 if (
Init.isInvalid())
15498 RHSExpr =
Init.get();
15508 bool ConvertHalfVec =
false;
15510 if (!LHS.
isUsable() || !RHS.isUsable())
15520 if (BO_Assign == Opc)
15521 Diag(OpLoc, diag::err_opencl_atomic_init) << 0 << SR;
15549 if (!ResultTy.
isNull()) {
15566 if (
auto *BE = dyn_cast<BlockExpr>(RHS.get()->IgnoreParens()))
15568 if (
auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
15569 if (VD->hasLocalStorage() &&
getCurScope()->isDeclScope(VD))
15570 BE->getBlockDecl()->setCanAvoidCopyToHeap();
15581 Opc == BO_PtrMemI);
15585 ConvertHalfVec =
true;
15592 ConvertHalfVec =
true;
15596 ConvertHalfVec =
true;
15607 ConvertHalfVec =
true;
15610 if (
const auto *BI = dyn_cast<BinaryOperator>(LHSExpr);
15611 !ForFoldExpression && BI && BI->isComparisonOp())
15612 Diag(OpLoc, diag::warn_consecutive_comparison)
15618 ConvertHalfVec =
true;
15622 ConvertHalfVec =
true;
15635 ConvertHalfVec =
true;
15640 ConvertHalfVec =
true;
15642 CompLHSTy = CompResultTy;
15649 CompLHSTy = CompResultTy;
15655 ConvertHalfVec =
true;
15662 ConvertHalfVec =
true;
15671 CompLHSTy = CompResultTy;
15682 CompLHSTy = CompResultTy;
15690 VK = RHS.get()->getValueKind();
15691 OK = RHS.get()->getObjectKind();
15703 (Opc == BO_Comma ||
isVector(RHS.get()->getType(),
Context.HalfTy) ==
15705 "both sides are half vectors or neither sides are");
15710 CheckArrayAccess(LHS.
get());
15711 CheckArrayAccess(RHS.get());
15715 &
Context.Idents.get(
"object_setClass"),
15721 "object_setClass(")
15734 if (CompResultTy.
isNull()) {
15735 if (ConvertHalfVec)
15755 if (ConvertHalfVec)
15760 Context, LHS.
get(), RHS.get(), Opc, ResultTy,
VK, OK, OpLoc,
15777 if (isLeftComp == isRightComp)
15782 bool isLeftBitwise = LHSBO && LHSBO->
isBitwiseOp();
15783 bool isRightBitwise = RHSBO && RHSBO->
isBitwiseOp();
15784 if (isLeftBitwise || isRightBitwise)
15796 Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
15799 Self.PDiag(diag::note_precedence_silence) << OpStr,
15800 (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange());
15802 Self.PDiag(diag::note_precedence_bitwise_first)
15817 Self.PDiag(diag::note_precedence_silence)
15826 if (Bop->getOpcode() == BO_LAnd) {
15831 }
else if (Bop->getOpcode() == BO_LOr) {
15832 if (
BinaryOperator *RBop = dyn_cast<BinaryOperator>(Bop->getRHS())) {
15835 if (RBop->getOpcode() == BO_LAnd &&
15847 if (Bop->getOpcode() == BO_LAnd) {
15862 if (Bop->isBitwiseOp() && Bop->getOpcode() < Opc) {
15863 S.
Diag(Bop->getOperatorLoc(), diag::warn_bitwise_op_in_bitwise_op)
15865 << Bop->getSourceRange() << OpLoc;
15867 S.
PDiag(diag::note_precedence_silence)
15868 << Bop->getOpcodeStr(),
15869 Bop->getSourceRange());
15875 Expr *SubExpr, StringRef Shift) {
15877 if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) {
15878 StringRef Op = Bop->getOpcodeStr();
15879 S.
Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift)
15880 << Bop->getSourceRange() << OpLoc << Shift << Op;
15882 S.
PDiag(diag::note_precedence_silence) << Op,
15883 Bop->getSourceRange());
15899 if (Kind != OO_LessLess && Kind != OO_GreaterGreater)
15902 S.
Diag(OpLoc, diag::warn_overloaded_shift_in_comparison)
15904 << (Kind == OO_LessLess);
15906 S.
PDiag(diag::note_precedence_silence)
15907 << (Kind == OO_LessLess ?
"<<" :
">>"),
15910 S, OpLoc, S.
PDiag(diag::note_evaluate_comparison_first),
15924 if ((Opc == BO_Or || Opc == BO_Xor) &&
15932 if (Opc == BO_LOr && !OpLoc.
isMacroID()) {
15938 || Opc == BO_Shr) {
15954 assert(LHSExpr &&
"ActOnBinOp(): missing left expression");
15955 assert(RHSExpr &&
"ActOnBinOp(): missing right expression");
15964 CheckInvalidBuiltinCountedByRef(LHSExpr, K);
15965 CheckInvalidBuiltinCountedByRef(RHSExpr, K);
15967 return BuildBinOp(S, TokLoc, Opc, LHSExpr, RHSExpr);
15973 if (OverOp !=
OO_None && OverOp != OO_Equal)
16022 Expr *RHSExpr,
bool ForFoldExpression) {
16023 if (!LHSExpr || !RHSExpr)
16035 if (pty->getKind() == BuiltinType::PseudoObject &&
16048 RHSExpr = resolvedRHS.
get();
16062 (pty->getKind() == BuiltinType::BoundMember ||
16063 pty->getKind() == BuiltinType::Overload)) {
16064 auto *OE = dyn_cast<OverloadExpr>(LHSExpr);
16065 if (OE && !OE->hasTemplateKeyword() && !OE->hasExplicitTemplateArgs() &&
16066 llvm::any_of(OE->decls(), [](
NamedDecl *ND) {
16067 return isa<FunctionTemplateDecl>(ND);
16069 Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc()
16070 : OE->getNameLoc(),
16071 diag::err_template_kw_missing)
16072 << OE->getName().getAsIdentifierInfo();
16079 LHSExpr = LHS.
get();
16086 if (Opc == BO_Assign && pty->getKind() == BuiltinType::Overload) {
16093 ForFoldExpression);
16103 RHSExpr = resolvedRHS.
get();
16108 if (!
HLSL().CheckResourceBinOp(Opc, LHSExpr, RHSExpr, OpLoc))
16125 "Should only occur in error-recovery path.");
16131 Context, LHSExpr, RHSExpr, Opc,
16151 ResultType = RHSExpr->
getType();
16154 ResultType =
Context.DependentTy;
16167 if (T.isNull() || T->isDependentType())
16183 bool CanOverflow =
false;
16185 bool ConvertHalfVec =
false;
16194 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16201 if (Opc == UO_AddrOf)
16202 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
16203 if (Opc == UO_Deref)
16204 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
16209 resultType =
Context.DependentTy;
16218 Opc == UO_PreInc || Opc == UO_PostInc,
16219 Opc == UO_PreInc || Opc == UO_PreDec);
16224 CheckAddressOfNoDeref(InputExpr);
16237 CanOverflow = Opc == UO_Minus &&
16249 if (ConvertHalfVec)
16256 (!
Context.getLangOpts().ZVector ||
16266 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16277 Diag(OpLoc, diag::ext_integer_complement_complex)
16285 if (!T->isIntegerType())
16286 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16289 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16305 resultType =
Context.FloatTy;
16311 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16317 if (
Context.getLangOpts().CPlusPlus) {
16322 }
else if (
Context.getLangOpts().OpenCL &&
16323 Context.getLangOpts().OpenCLVersion < 120) {
16327 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16340 Input.
get(), resultType,
16345 if (
Context.getLangOpts().OpenCL &&
16346 Context.getLangOpts().getOpenCLCompatibleVersion() < 120) {
16350 if (!T->isIntegerType())
16351 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16357 }
else if (
Context.getLangOpts().CPlusPlus &&
16361 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16367 }
else if (resultType ==
Context.AMDGPUFeaturePredicateTy) {
16368 resultType =
Context.getLogicalOperationType();
16372 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16378 resultType =
Context.getLogicalOperationType();
16406 "the co_await expression must be non-dependant before "
16407 "building operator co_await");
16418 if (Opc != UO_AddrOf && Opc != UO_Deref)
16419 CheckArrayAccess(Input.
get());
16425 if (Opc == UO_Deref && UO->getType()->hasAttr(attr::NoDeref) &&
16431 if (ConvertHalfVec)
16437 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
16438 if (!DRE->getQualifier())
16448 return Method->isImplicitObjectMemberFunction();
16454 if (!ULE->getQualifier())
16459 if (
Method->isImplicitObjectMemberFunction())
16480 if (pty->getKind() == BuiltinType::PseudoObject &&
16485 if (Opc == UO_Extension)
16490 if (Opc == UO_AddrOf &&
16491 (pty->getKind() == BuiltinType::Overload ||
16492 pty->getKind() == BuiltinType::UnknownAny ||
16493 pty->getKind() == BuiltinType::BoundMember))
16518 Expr *Input,
bool IsAfterAmp) {
16528 OpLoc, LabLoc, TheDecl,
Context.getPointerType(
Context.VoidTy));
16562 assert(!
Cleanup.exprNeedsCleanups() &&
16563 "cleanups within StmtExpr not correctly bound!");
16573 bool StmtExprMayBindToTemp =
false;
16575 if (
const auto *LastStmt = dyn_cast<ValueStmt>(Compound->
body_back())) {
16576 if (
const Expr *
Value = LastStmt->getExprStmt()) {
16577 StmtExprMayBindToTemp =
true;
16585 Expr *ResStmtExpr =
16587 if (StmtExprMayBindToTemp)
16589 return ResStmtExpr;
16612 auto *Cast = dyn_cast<ImplicitCastExpr>(E);
16613 if (Cast && Cast->getCastKind() == CK_ARCConsumeObject)
16614 return Cast->getSubExpr();
16635 return ExprError(
Diag(BuiltinLoc, diag::err_offsetof_record_type)
16636 << ArgTy << TypeRange);
16642 diag::err_offsetof_incomplete_type, TypeRange))
16645 bool DidWarnAboutNonPOD =
false;
16650 if (OC.isBrackets) {
16655 return ExprError(
Diag(OC.LocEnd, diag::err_offsetof_array_type)
16659 CurrentType =
Context.DependentTy;
16675 Comps.push_back(
OffsetOfNode(OC.LocStart, Exprs.size(), OC.LocEnd));
16676 Exprs.push_back(Idx);
16684 Comps.push_back(
OffsetOfNode(OC.LocStart, OC.U.IdentInfo, OC.LocEnd));
16685 CurrentType =
Context.DependentTy;
16691 diag::err_offsetof_incomplete_type))
16697 return ExprError(
Diag(OC.LocEnd, diag::err_offsetof_record_type)
16708 bool IsSafe =
LangOpts.CPlusPlus11? CRD->isStandardLayout() : CRD->isPOD();
16710 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
16711 : diag::ext_offsetof_non_pod_type;
16714 Diag(BuiltinLoc, DiagID)
16715 <<
SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
16716 DidWarnAboutNonPOD =
true;
16727 MemberDecl = IndirectMemberDecl->getAnonField();
16734 if (!R.isAmbiguous())
16735 Diag(BuiltinLoc, diag::err_no_member)
16736 << OC.U.IdentInfo << RD <<
SourceRange(OC.LocStart, OC.LocEnd);
16745 Diag(OC.LocEnd, diag::err_offsetof_bitfield)
16753 if (IndirectMemberDecl)
16760 Context.getCanonicalTagType(Parent), Paths)) {
16762 Diag(OC.LocEnd, diag::err_offsetof_field_of_virtual_base)
16773 if (IndirectMemberDecl) {
16774 for (
auto *FI : IndirectMemberDecl->chain()) {
16780 Comps.push_back(
OffsetOfNode(OC.LocStart, MemberDecl, OC.LocEnd));
16786 Comps, Exprs, RParenLoc);
16812 assert((CondExpr && LHSExpr && RHSExpr) &&
"Missing type argument(s)");
16817 bool CondIsTrue =
false;
16819 resType =
Context.DependentTy;
16822 llvm::APSInt condEval(32);
16824 CondExpr, &condEval, diag::err_typecheck_choose_expr_requires_constant);
16827 CondExpr = CondICE.
get();
16828 CondIsTrue = condEval.getZExtValue();
16831 Expr *ActiveExpr = CondIsTrue ? LHSExpr : RHSExpr;
16833 resType = ActiveExpr->
getType();
16839 resType,
VK, OK, RPLoc, CondIsTrue);
16851 Decl *ManglingContextDecl;
16852 std::tie(MCtx, ManglingContextDecl) =
16856 Block->setBlockMangling(ManglingNumber, ManglingContextDecl);
16878 "block-id should have no identifier!");
16889 assert(T->isFunctionType() &&
16890 "GetTypeForDeclarator made a non-function block signature");
16906 unsigned Size =
Result.getFullDataSize();
16907 Sig =
Context.CreateTypeSourceInfo(
Result.getType(), Size);
16918 QualType RetTy = Fn->getReturnType();
16928 if (RetTy !=
Context.DependentTy) {
16936 if (ExplicitSignature) {
16937 for (
unsigned I = 0, E = ExplicitSignature.
getNumParams(); I != E; ++I) {
16939 if (Param->getIdentifier() ==
nullptr && !Param->isImplicit() &&
16943 Diag(Param->getLocation(), diag::ext_parameter_name_omitted_c23);
16945 Params.push_back(Param);
16951 for (
const auto &I : Fn->param_types()) {
16954 Params.push_back(Param);
16959 if (!Params.empty()) {
16970 AI->setOwningFunction(CurBlock->
TheDecl);
16973 if (AI->getIdentifier()) {
16979 if (AI->isInvalidDecl())
16998 Diag(CaretLoc, diag::err_blocks_disable) <<
LangOpts.OpenCL;
17003 assert(!
Cleanup.exprNeedsCleanups() &&
17004 "cleanups within block not correctly bound!");
17019 bool NoReturn = BD->
hasAttr<NoReturnAttr>();
17027 if (NoReturn && !Ext.getNoReturn()) Ext = Ext.
withNoReturn(
true);
17033 BlockTy =
Context.getFunctionType(RetTy, {}, EPI);
17054 BlockTy =
Context.getFunctionType(RetTy, {}, EPI);
17058 BlockTy =
Context.getBlockPointerType(BlockTy);
17062 !
PP.isCodeCompletionEnabled())
17067 if (Body &&
getCurFunction()->HasPotentialAvailabilityViolations)
17093 Expr *CopyExpr =
nullptr;
17120 if (!
Result.isInvalid() &&
17121 !
Result.get()->getType().isConstQualified()) {
17123 Result.get()->getType().withConst(),
17127 if (!
Result.isInvalid()) {
17137 if (!
Result.isInvalid() &&
17141 CopyExpr =
Result.get();
17148 Captures.push_back(NewCap);
17162 if (
Result->getBlockDecl()->hasCaptures()) {
17165 Cleanup.setExprNeedsCleanups(
true);
17169 for (
const auto &CI :
Result->getBlockDecl()->captures()) {
17170 const VarDecl *var = CI.getVariable();
17185 {Result},
Result->getType());
17199 Expr *OrigExpr = E;
17213 Context.getTargetInfo().getTriple().isNVPTX())
17236 VaListType =
Context.getArrayDecayedType(VaListType);
17248 if (
Init.isInvalid())
17264 diag::err_first_argument_to_va_arg_not_of_type_va_list)
17269 diag::err_second_parameter_to_va_arg_incomplete,
17275 diag::err_second_parameter_to_va_arg_abstract,
17282 ? diag::warn_second_parameter_to_va_arg_ownership_qualified
17283 : diag::warn_second_parameter_to_va_arg_not_pod)
17290 PDiag(diag::warn_second_parameter_to_va_arg_array)
17323 UnderlyingType = ED->getIntegerType();
17324 if (
Context.typesAreCompatible(PromoteType, UnderlyingType,
17337 ?
Context.getCorrespondingSignedType(UnderlyingType)
17338 :
Context.getCorrespondingUnsignedType(UnderlyingType);
17339 if (
Context.typesAreCompatible(PromoteType, UnderlyingType,
17345 PromoteType =
Context.DoubleTy;
17346 if (!PromoteType.
isNull())
17348 PDiag(diag::warn_second_parameter_to_va_arg_never_compatible)
17363 if (pw ==
Context.getTargetInfo().getIntWidth())
17365 else if (pw ==
Context.getTargetInfo().getLongWidth())
17367 else if (pw ==
Context.getTargetInfo().getLongLongWidth())
17370 llvm_unreachable(
"I don't know size of pointer!");
17387 if ((SLDecl->isCompleteDefinition() || SLDecl->isBeingDefined()) &&
17396 S.
Diag(Loc, diag::err_std_source_location_impl_not_found);
17404 S.
Diag(Loc, diag::err_std_source_location_impl_malformed);
17408 unsigned Count = 0;
17410 StringRef Name = F->getName();
17412 if (Name ==
"_M_file_name") {
17413 if (F->getType() !=
17417 }
else if (Name ==
"_M_function_name") {
17418 if (F->getType() !=
17422 }
else if (Name ==
"_M_line") {
17423 if (!F->getType()->isIntegerType())
17426 }
else if (Name ==
"_M_column") {
17427 if (!F->getType()->isIntegerType())
17436 S.
Diag(Loc, diag::err_std_source_location_impl_malformed);
17459 ResultTy =
Context.UnsignedIntTy;
17468 ResultTy =
Context.getPointerType(
17487 Data->BinaryData = BinaryData;
17491 Data->getDataElementCount());
17495 const Expr *SrcExpr) {
17504 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
17517 bool *Complained) {
17519 *Complained =
false;
17522 bool CheckInferredResultType =
false;
17524 unsigned DiagKind = 0;
17526 bool MayHaveConvFixit =
false;
17527 bool MayHaveFunctionDiff =
false;
17538 DiagKind = diag::warn_compatible_implicit_pointer_conv;
17542 DiagKind = diag::err_typecheck_convert_pointer_int;
17545 DiagKind = diag::ext_typecheck_convert_pointer_int;
17548 MayHaveConvFixit =
true;
17552 DiagKind = diag::err_typecheck_convert_int_pointer;
17555 DiagKind = diag::ext_typecheck_convert_int_pointer;
17558 MayHaveConvFixit =
true;
17562 diag::warn_typecheck_convert_incompatible_function_pointer_strict;
17564 MayHaveConvFixit =
true;
17568 DiagKind = diag::err_typecheck_convert_incompatible_function_pointer;
17571 DiagKind = diag::ext_typecheck_convert_incompatible_function_pointer;
17574 MayHaveConvFixit =
true;
17578 DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer;
17580 DiagKind = diag::err_typecheck_convert_incompatible_pointer;
17583 DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
17587 if (CheckInferredResultType) {
17593 MayHaveConvFixit =
true;
17597 DiagKind = diag::err_typecheck_convert_incompatible_pointer_sign;
17600 DiagKind = diag::ext_typecheck_convert_incompatible_pointer_sign;
17605 DiagKind = diag::err_typecheck_convert_pointer_void_func;
17608 DiagKind = diag::ext_typecheck_convert_pointer_void_func;
17614 SrcType =
Context.getDecayedType(SrcType);
17621 DiagKind = diag::err_typecheck_incompatible_address_space;
17624 DiagKind = diag::err_typecheck_incompatible_ownership;
17627 DiagKind = diag::err_typecheck_incompatible_ptrauth;
17631 llvm_unreachable(
"unknown error case for discarding qualifiers!");
17636 SrcType =
Context.getArrayDecayedType(SrcType);
17638 DiagKind = diag::ext_typecheck_convert_discards_overflow_behavior;
17654 DiagKind = diag::err_typecheck_convert_discards_qualifiers;
17657 DiagKind = diag::ext_typecheck_convert_discards_qualifiers;
17664 DiagKind = diag::err_nested_pointer_qualifier_mismatch;
17666 DiagKind = diag::ext_nested_pointer_qualifier_mismatch;
17670 DiagKind = diag::err_typecheck_incompatible_nested_address_space;
17674 DiagKind = diag::err_int_to_block_pointer;
17678 DiagKind = diag::err_typecheck_convert_incompatible_block_pointer;
17685 for (
auto *srcProto : srcOPT->
quals()) {
17691 IFace = IFaceT->getDecl();
17696 for (
auto *dstProto : dstOPT->
quals()) {
17702 IFace = IFaceT->getDecl();
17705 DiagKind = diag::err_incompatible_qualified_id;
17708 DiagKind = diag::warn_incompatible_qualified_id;
17714 DiagKind = diag::err_incompatible_vectors;
17717 DiagKind = diag::warn_incompatible_vectors;
17721 DiagKind = diag::err_arc_weak_unavailable_assign;
17728 "Unexpected function type found in IncompatibleOBTKinds assignment");
17730 SrcType =
Context.getDecayedType(SrcType);
17732 auto getOBTKindName = [](
QualType Ty) -> StringRef {
17733 if (Ty->isPointerType())
17734 Ty = Ty->getPointeeType();
17735 if (
const auto *OBT = Ty->getAs<OverflowBehaviorType>()) {
17736 return OBT->getBehaviorKind() ==
17737 OverflowBehaviorType::OverflowBehaviorKind::Trap
17741 llvm_unreachable(
"OBT kind unhandled");
17744 Diag(Loc, diag::err_incompatible_obt_kinds_assignment)
17745 << DstType << SrcType << getOBTKindName(DstType)
17746 << getOBTKindName(SrcType);
17753 *Complained =
true;
17757 DiagKind = diag::err_typecheck_convert_incompatible;
17759 MayHaveConvFixit =
true;
17761 MayHaveFunctionDiff =
true;
17770 FirstType = DstType;
17771 SecondType = SrcType;
17781 FirstType = SrcType;
17782 SecondType = DstType;
17791 FDiag << FirstType << SecondType << ActionForDiag
17794 if (DiagKind == diag::ext_typecheck_convert_incompatible_pointer_sign ||
17795 DiagKind == diag::err_typecheck_convert_incompatible_pointer_sign) {
17805 if (!ConvHints.
isNull()) {
17810 if (MayHaveConvFixit) { FDiag << (
unsigned) (ConvHints.
Kind); }
17812 if (MayHaveFunctionDiff)
17816 if ((DiagKind == diag::warn_incompatible_qualified_id ||
17817 DiagKind == diag::err_incompatible_qualified_id) &&
17819 Diag(IFace->
getLocation(), diag::note_incomplete_class_and_qualified_id)
17822 if (SecondType ==
Context.OverloadTy)
17826 if (CheckInferredResultType)
17834 *Complained =
true;
17845 return S.
Diag(Loc, diag::err_ice_not_integral)
17849 return S.
Diag(Loc, diag::err_expr_not_ice) << S.
LangOpts.CPlusPlus;
17864 IDDiagnoser(
unsigned DiagID)
17868 return S.
Diag(Loc, DiagID);
17870 } Diagnoser(DiagID);
17883 return S.
Diag(Loc, diag::ext_expr_not_ice) << S.
LangOpts.CPlusPlus;
17905 BaseDiagnoser(BaseDiagnoser) {}
17914 return S.
Diag(Loc, diag::err_ice_incomplete_type) << T;
17919 return S.
Diag(Loc, diag::err_ice_explicit_conversion) << T << ConvTy;
17930 return S.
Diag(Loc, diag::err_ice_ambiguous_conversion) << T;
17941 llvm_unreachable(
"conversion functions are permitted");
17943 } ConvertDiagnoser(Diagnoser);
17949 E = Converted.
get();
17970 E = RValueExpr.
get();
17988 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
17989 diag::note_invalid_subexpr_in_const_expr) {
17990 DiagLoc = Notes[0].first;
18012 EvalResult.
Diag = &Notes;
18036 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
18037 diag::note_invalid_subexpr_in_const_expr) {
18038 DiagLoc = Notes[0].first;
18064 class TransformToPE :
public TreeTransform<TransformToPE> {
18068 TransformToPE(
Sema &SemaRef) : BaseTransform(SemaRef) { }
18071 bool AlwaysRebuild() {
return true; }
18072 bool ReplacingOriginal() {
return true; }
18081 ExprResult TransformDeclRefExpr(DeclRefExpr *E) {
18083 !SemaRef.isUnevaluatedContext())
18085 diag::err_invalid_non_static_member_use)
18088 return BaseTransform::TransformDeclRefExpr(E);
18092 ExprResult TransformUnaryOperator(UnaryOperator *E) {
18096 return BaseTransform::TransformUnaryOperator(E);
18104 return SkipLambdaBody(E, Body);
18111 "Should only transform unevaluated expressions");
18116 return TransformToPE(*this).TransformExpr(E);
18121 "Should only transform unevaluated expressions");
18125 return TransformToPE(*this).TransformType(TInfo);
18133 LambdaContextDecl, ExprContext);
18147 Prev.isImmediateFunctionContext() || Prev.isConstantEvaluated();
18150 Prev.InImmediateEscalatingFunctionContext;
18218 if (
const auto *E = dyn_cast<UnaryOperator>(PossibleDeref)) {
18219 if (E->getOpcode() == UO_Deref)
18220 return CheckPossibleDeref(S, E->getSubExpr());
18221 }
else if (
const auto *E = dyn_cast<ArraySubscriptExpr>(PossibleDeref)) {
18222 return CheckPossibleDeref(S, E->getBase());
18223 }
else if (
const auto *E = dyn_cast<MemberExpr>(PossibleDeref)) {
18224 return CheckPossibleDeref(S, E->getBase());
18225 }
else if (
const auto E = dyn_cast<DeclRefExpr>(PossibleDeref)) {
18228 if (
const auto *Ptr = Ty->
getAs<PointerType>())
18231 Inner = Arr->getElementType();
18235 if (Inner->
hasAttr(attr::NoDeref))
18245 const DeclRefExpr *DeclRef = CheckPossibleDeref(*
this, E);
18252 Diag(E->
getExprLoc(), diag::warn_dereference_of_noderef_type_no_decl)
18267 if (BO->getOpcode() == BO_Assign) {
18269 llvm::erase(LHSs, BO->getLHS());
18277 "Cannot mark an immediate escalating expression outside of an "
18278 "immediate escalating context");
18281 if (
auto *DeclRef =
18282 dyn_cast<DeclRefExpr>(
Call->getCallee()->IgnoreImplicit()))
18283 DeclRef->setIsImmediateEscalating(
true);
18284 }
else if (
auto *Ctr = dyn_cast<CXXConstructExpr>(E->
IgnoreImplicit())) {
18285 Ctr->setIsImmediateEscalating(
true);
18286 }
else if (
auto *DeclRef = dyn_cast<DeclRefExpr>(E->
IgnoreImplicit())) {
18287 DeclRef->setIsImmediateEscalating(
true);
18289 assert(
false &&
"expected an immediately escalating expression");
18292 FI->FoundImmediateEscalatingExpression =
true;
18307 if (
auto *DeclRef =
18308 dyn_cast<DeclRefExpr>(
Call->getCallee()->IgnoreImplicit()))
18317 auto CheckConstantExpressionAndKeepResult = [&]() {
18320 Eval.
Diag = &Notes;
18322 Eval,
getASTContext(), ConstantExprKind::ImmediateInvocation);
18323 if (Res && Notes.empty()) {
18324 Cached = std::move(Eval.
Val);
18332 !CheckConstantExpressionAndKeepResult()) {
18337 if (
Cleanup.exprNeedsCleanups()) {
18354 Cleanup.cleanupsHaveSideEffects(), {});
18367 ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
18375 Eval.
Diag = &Notes;
18379 if (!
Result || !Notes.empty()) {
18382 if (
auto *
FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr))
18385 if (
auto *
Call = dyn_cast<CallExpr>(InnerExpr))
18387 else if (
auto *
Call = dyn_cast<CXXConstructExpr>(InnerExpr))
18388 FD =
Call->getConstructor();
18389 else if (
auto *Cast = dyn_cast<CastExpr>(InnerExpr))
18390 FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction());
18393 "could not find an immediate function in this expression");
18400 SemaRef.
Diag(Context->Loc, diag::note_invalid_consteval_initializer)
18402 SemaRef.
Diag(Context->Decl->getBeginLoc(), diag::note_declared_at);
18406 for (
auto &
Note : Notes)
18418 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
18422 ComplexRemove(
Sema &SemaRef, llvm::SmallPtrSetImpl<DeclRefExpr *> &DR,
18426 :
Base(SemaRef), DRSet(DR), IISet(II), CurrentII(Current) {}
18428 auto It = std::find_if(CurrentII, IISet.rend(),
18430 return Elem.getPointer() == E;
18436 if (It == IISet.rend()) {
18438 CurrentII->setInt(1);
18445 return Base::TransformConstantExpr(E);
18446 RemoveImmediateInvocation(E);
18447 return Base::TransformExpr(E->
getSubExpr());
18453 return Base::TransformCXXOperatorCallExpr(E);
18467 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(
Init))
18468 Init = ICE->getSubExpr();
18469 else if (
auto *ICE = dyn_cast<MaterializeTemporaryExpr>(
Init))
18470 Init = ICE->getSubExpr();
18476 if (
auto *CE = dyn_cast<ConstantExpr>(
Init);
18477 CE && CE->isImmediateInvocation())
18478 RemoveImmediateInvocation(CE);
18479 return Base::TransformInitializer(
Init, NotCopyInit);
18490 bool AlwaysRebuild() {
return false; }
18491 bool ReplacingOriginal() {
return true; }
18492 bool AllowSkippingCXXConstructExpr() {
18493 bool Res = AllowSkippingFirstCXXConstructExpr;
18494 AllowSkippingFirstCXXConstructExpr =
true;
18497 bool AllowSkippingFirstCXXConstructExpr =
true;
18508 Transformer.AllowSkippingFirstCXXConstructExpr =
false;
18510 ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
18516 It->getPointer()->setSubExpr(Res.
get());
18536 if (VD && (VD->isUsableInConstantExpressions(
SemaRef.
Context) ||
18537 VD->hasConstantInitialization())) {
18570 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
18571 SimpleRemove(llvm::SmallPtrSetImpl<DeclRefExpr *> &S) : DRSet(S) {}
18574 return DRSet.size();
18577 Visitor.TraverseStmt(
18587 if (DR->isImmediateEscalating())
18591 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND);
18593 ND = MD->getParent();
18600 bool ImmediateEscalating =
false;
18601 bool IsPotentiallyEvaluated =
18611 SemaRef.
Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
18612 << ND << isa<CXXRecordDecl>(ND) << FD->isConsteval();
18613 if (!FD->getBuiltinID())
18617 SemaRef.
Diag(Context->Loc, diag::note_invalid_consteval_initializer)
18619 SemaRef.
Diag(Context->Decl->getBeginLoc(), diag::note_declared_at);
18621 if (FD->isImmediateEscalating() && !FD->isConsteval())
18635 (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument ||
18643 D = diag::err_lambda_unevaluated_operand;
18649 D = diag::err_lambda_in_constant_expression;
18650 }
else if (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument) {
18653 D = diag::err_lambda_in_invalid_context;
18655 llvm_unreachable(
"Couldn't infer lambda error message.");
18657 for (
const auto *L : Rec.
Lambdas)
18658 Diag(L->getBeginLoc(), D);
18678 Diag(BO->getBeginLoc(), diag::warn_deprecated_simple_assign_volatile)
18749 llvm_unreachable(
"Invalid context");
18795 : FD(FD), Param(Param) {}
18802 CCName =
"stdcall";
18805 CCName =
"fastcall";
18808 CCName =
"vectorcall";
18811 llvm_unreachable(
"CC does not need mangling");
18814 S.
Diag(Loc, diag::err_cconv_incomplete_param_type)
18815 << Param->getDeclName() << FD->
getDeclName() << CCName;
18820 ParamIncompleteTypeDiagnoser Diagnoser(FD, Param);
18826enum class OdrUseContext {
18845 if (Context.isUnevaluated())
18846 return OdrUseContext::None;
18849 return OdrUseContext::Dependent;
18851 if (Context.isDiscardedStatementContext())
18852 return OdrUseContext::FormallyOdrUsed;
18854 else if (Context.Context ==
18856 return OdrUseContext::FormallyOdrUsed;
18858 return OdrUseContext::Used;
18862 if (!
Func->isConstexpr())
18865 if (
Func->isImplicitlyInstantiable() || !
Func->isUserProvided())
18872 auto *CCD = dyn_cast<CXXConstructorDecl>(
Func);
18873 return CCD && CCD->getInheritedConstructor();
18877 bool MightBeOdrUse) {
18878 assert(
Func &&
"No function?");
18880 Func->setReferenced();
18893 OdrUseContext OdrUse =
18895 if (IsRecursiveCall && OdrUse == OdrUseContext::Used)
18896 OdrUse = OdrUseContext::FormallyOdrUsed;
18900 if (
Func->isTrivial() && !
Func->hasAttr<DLLExportAttr>() &&
18901 OdrUse == OdrUseContext::Used) {
18904 OdrUse = OdrUseContext::FormallyOdrUsed;
18906 OdrUse = OdrUseContext::FormallyOdrUsed;
18913 bool NeededForConstantEvaluation =
18938 bool NeedDefinition =
18939 !IsRecursiveCall &&
18940 (OdrUse == OdrUseContext::Used ||
18941 (NeededForConstantEvaluation && !
Func->isPureVirtual()));
18948 if (NeedDefinition &&
18950 Func->getMemberSpecializationInfo()))
18957 if (NeedDefinition && !
Func->getBody()) {
18960 dyn_cast<CXXConstructorDecl>(
Func)) {
18973 }
else if (
Constructor->getInheritedConstructor()) {
18977 dyn_cast<CXXDestructorDecl>(
Func)) {
18987 if (MethodDecl->isOverloadedOperator() &&
18988 MethodDecl->getOverloadedOperator() == OO_Equal) {
18990 if (MethodDecl->isDefaulted() && !MethodDecl->isDeleted()) {
18991 if (MethodDecl->isCopyAssignmentOperator())
18993 else if (MethodDecl->isMoveAssignmentOperator())
18997 MethodDecl->getParent()->isLambda()) {
19004 }
else if (MethodDecl->isVirtual() &&
getLangOpts().AppleKext)
19008 if (
Func->isDefaulted() && !
Func->isDeleted()) {
19016 if (
Func->isImplicitlyInstantiable()) {
19018 Func->getTemplateSpecializationKindForInstantiation();
19020 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
19021 if (FirstInstantiation) {
19022 PointOfInstantiation = Loc;
19023 if (
auto *MSI =
Func->getMemberSpecializationInfo())
19024 MSI->setPointOfInstantiation(Loc);
19027 Func->setTemplateSpecializationKind(TSK, PointOfInstantiation);
19032 PointOfInstantiation = Loc;
19036 Func->isConstexpr()) {
19041 std::make_pair(
Func, PointOfInstantiation));
19042 else if (
Func->isConstexpr())
19048 Func->setInstantiationIsPending(
true);
19050 std::make_pair(
Func, PointOfInstantiation));
19051 if (llvm::isTimeTraceVerbose()) {
19052 llvm::timeTraceAddInstantEvent(
"DeferInstantiation", [&] {
19054 llvm::raw_string_ostream
OS(Name);
19061 Consumer.HandleCXXImplicitFunctionInstantiation(
Func);
19066 for (
auto *i :
Func->redecls()) {
19067 if (!i->isUsed(
false) && i->isImplicitlyInstantiable())
19085 if (
Init->isInClassMemberInitializer())
19087 MarkDeclarationsReferencedInExpr(Init->getInit());
19108 if (
LangOpts.OffloadImplicitHostDeviceTemplates &&
LangOpts.CUDAIsDevice &&
19113 if (OdrUse == OdrUseContext::Used && !
Func->isUsed(
false)) {
19115 if (!
Func->isDefined() && !
Func->isInAnotherModuleUnit()) {
19116 if (mightHaveNonExternalLinkage(
Func))
19118 else if (
Func->getMostRecentDecl()->isInlined() &&
19120 !
Func->getMostRecentDecl()->hasAttr<GNUInlineAttr>())
19138 if (
Context.getTargetInfo().getCXXABI().isMicrosoft()) {
19139 if (
auto *Dtor = dyn_cast<CXXDestructorDecl>(
Func)) {
19159 const unsigned *
const FunctionScopeIndexToStopAt =
nullptr) {
19162 VarDecl *Var =
V->getPotentiallyDecomposedVarDecl();
19163 assert(Var &&
"expected a capturable variable");
19173 QualType CaptureType, DeclRefType;
19179 DeclRefType, FunctionScopeIndexToStopAt);
19194 << 2 << 1 << Var << UserTarget;
19197 ? diag::note_cuda_const_var_unpromoted
19198 : diag::note_cuda_host_var);
19207 Var->
hasAttr<CUDADeviceAttr>() &&
19208 !Var->
getAttr<CUDADeviceAttr>()->isImplicit())) &&
19209 !Var->
hasAttr<CUDASharedAttr>() &&
19225 (!FD || (!FD->getDescribedFunctionTemplate() &&
19237 unsigned CapturingScopeIndex) {
19264 unsigned ContextKind = 3;
19274 S.
Diag(loc, diag::err_reference_to_local_in_enclosing_context)
19275 << var << ValueKind << ContextKind << VarDC;
19276 S.
Diag(var->getLocation(), diag::note_entity_declared_at)
19285 bool &SubCapturesAreNested,
19291 SubCapturesAreNested =
true;
19344 "Only variables and structured bindings can be captured");
19355 S.
Diag(Loc, diag::err_lambda_capture_anonymous_var);
19364 S.
Diag(Loc, diag::err_ref_vm_type);
19375 S.
Diag(Loc, diag::err_ref_flexarray_type);
19377 S.
Diag(Loc, diag::err_lambda_capture_flexarray_type) << Var;
19382 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
19387 S.
Diag(Loc, diag::err_capture_block_variable) << Var << !IsLambda;
19396 S.
Diag(Loc, diag::err_opencl_block_ref_block);
19407 ? diag::warn_cxx17_compat_capture_binding
19408 : diag::ext_capture_binding)
19422 bool ByRef =
false;
19428 if (BuildAndDiagnose) {
19429 S.
Diag(Loc, diag::err_ref_array_type);
19440 if (BuildAndDiagnose) {
19441 S.
Diag(Loc, diag::err_arc_autoreleasing_capture)
19457 if (BuildAndDiagnose) {
19459 S.
Diag(Loc, diag::warn_block_capture_autoreleasing);
19460 S.
Diag(VarLoc, diag::note_declare_parameter_strong);
19465 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
19474 DeclRefType = CaptureType;
19478 if (BuildAndDiagnose)
19488 const bool BuildAndDiagnose,
QualType &CaptureType,
QualType &DeclRefType,
19489 const bool RefersToCapturedVariable,
TryCaptureKind Kind,
bool IsTopScope,
19515 CaptureType = DeclRefType;
19518 if (BuildAndDiagnose)
19519 RSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
19529 const bool RefersToCapturedVariable,
19534 bool ByRef =
false;
19538 ByRef = (LSI->
ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
19543 S.
Diag(Loc, diag::err_wasm_ca_reference) << 0;
19574 if (!RefType->getPointeeType()->isFunctionType())
19581 if (BuildAndDiagnose) {
19582 S.
Diag(Loc, diag::err_arc_autoreleasing_capture) << 1;
19592 if (!
Invalid && BuildAndDiagnose) {
19596 diag::err_capture_of_incomplete_or_sizeless_type,
19600 diag::err_capture_of_abstract_type))
19626 if (BuildAndDiagnose)
19627 LSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
19628 Loc, EllipsisLoc, CaptureType,
Invalid);
19639 if (T.isTriviallyCopyableType(Context))
19643 if (!(RD = RD->getDefinition()))
19645 if (RD->hasSimpleCopyConstructor())
19647 if (RD->hasUserDeclaredCopyConstructor())
19649 if (Ctor->isCopyConstructor())
19650 return !Ctor->isDeleted();
19670 if (ShouldOfferCopyFix) {
19674 FixBuffer.assign({Separator, Var->
getName()});
19675 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
19680 FixBuffer.assign({Separator,
"&", Var->
getName()});
19681 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
19693 return !C.isThisCapture() && !C.isInitCapture();
19702 if (ShouldOfferCopyFix) {
19703 bool CanDefaultCopyCapture =
true;
19712 if (CanDefaultCopyCapture && llvm::none_of(LSI->
Captures, [](
Capture &
C) {
19713 return !C.isThisCapture() && !C.isInitCapture() && C.isCopyCapture();
19715 FixBuffer.assign({
"=", Separator});
19716 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
19725 return !C.isInitCapture() && C.isReferenceCapture() &&
19726 !C.isThisCapture();
19728 FixBuffer.assign({
"&", Separator});
19729 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
19738 QualType &DeclRefType,
const unsigned *
const FunctionScopeIndexToStopAt) {
19761 const auto *VD = dyn_cast<VarDecl>(Var);
19763 if (VD->isInitCapture())
19768 assert(VD &&
"Cannot capture a null variable");
19770 const unsigned MaxFunctionScopesIndex = FunctionScopeIndexToStopAt
19774 if (FunctionScopeIndexToStopAt) {
19775 assert(!
FunctionScopes.empty() &&
"No function scopes to stop at?");
19780 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(
FunctionScopes[FSIndex]);
19781 FSIndex && LSI && !LSI->AfterParameterList)
19783 assert(MaxFunctionScopesIndex <= FSIndex &&
19784 "FunctionScopeIndexToStopAt should be no greater than FSIndex into "
19785 "FunctionScopes.");
19786 while (FSIndex != MaxFunctionScopesIndex) {
19794 bool IsGlobal = !VD->hasLocalStorage();
19795 if (IsGlobal && !(
LangOpts.OpenMP &&
19796 OpenMP().isOpenMPCapturedDecl(Var,
true,
19797 MaxFunctionScopesIndex)))
19811 CaptureType = Var->
getType();
19813 bool Nested =
false;
19815 unsigned FunctionScopesIndex = MaxFunctionScopesIndex;
19820 LSI = dyn_cast_or_null<LambdaScopeInfo>(
19823 bool IsInScopeDeclarationContext =
19834 if (IsInScopeDeclarationContext &&
19835 FunctionScopesIndex == MaxFunctionScopesIndex && VarDC == DC)
19841 !IsInScopeDeclarationContext
19844 BuildAndDiagnose, *
this);
19850 FunctionScopesIndex = MaxFunctionScopesIndex - 1;
19869 if (
const auto *Parm = dyn_cast<ParmVarDecl>(Var);
19870 Parm && Parm->getDeclContext() == DC)
19878 if (BuildAndDiagnose) {
19881 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19896 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19897 QTy = PVD->getOriginalType();
19902 if (
auto *RSI = dyn_cast<CapturedRegionScopeInfo>(CSI)) {
19909 if (BuildAndDiagnose) {
19910 Diag(ExprLoc, diag::err_capture_binding_openmp) << Var;
19916 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
19921 if (IsOpenMPPrivateDecl != OMPC_unknown &&
19924 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19925 QTy = PVD->getOriginalType();
19927 E =
OpenMP().getNumberOfConstructScopes(RSI->OpenMPLevel);
19931 assert(RSI->OpenMPLevel == OuterRSI->OpenMPLevel &&
19932 "Wrong number of captured regions associated with the "
19933 "OpenMP construct.");
19938 IsOpenMPPrivateDecl != OMPC_private &&
19940 RSI->OpenMPCaptureLevel);
19944 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
19950 OpenMP().adjustOpenMPTargetScopeIndex(FunctionScopesIndex,
19953 if (IsTargetCap || IsOpenMPPrivateDecl == OMPC_private ||
19954 (IsGlobal && !IsGlobalCap)) {
19955 Nested = !IsTargetCap;
19961 CaptureType =
Context.getLValueReferenceType(DeclRefType);
19970 if (BuildAndDiagnose) {
19971 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19993 FunctionScopesIndex--;
19994 if (IsInScopeDeclarationContext)
19996 }
while (!VarDC->
Equals(DC));
20004 for (
unsigned I = ++FunctionScopesIndex, N = MaxFunctionScopesIndex + 1; I != N;
20017 if (
Invalid && !BuildAndDiagnose)
20022 DeclRefType, Nested, *
this,
Invalid);
20026 RSI, Var, ExprLoc, BuildAndDiagnose, CaptureType, DeclRefType, Nested,
20027 Kind, I == N - 1, *
this,
Invalid);
20033 DeclRefType, Nested, Kind, EllipsisLoc,
20038 if (
Invalid && !BuildAndDiagnose)
20050 DeclRefType,
nullptr);
20058 false, CaptureType, DeclRefType,
nullptr);
20062 assert(Var &&
"Null value cannot be captured");
20069 false, CaptureType, DeclRefType,
20073 return DeclRefType;
20081class CopiedTemplateArgs {
20085 template<
typename RefExpr>
20086 CopiedTemplateArgs(RefExpr *E) : HasArgs(E->hasExplicitTemplateArgs()) {
20088 E->copyTemplateArgumentsInto(TemplateArgStorage);
20091#ifdef __has_cpp_attribute
20092#if __has_cpp_attribute(clang::lifetimebound)
20093 [[clang::lifetimebound]]
20097 return HasArgs ? &TemplateArgStorage :
nullptr;
20123 auto Rebuild = [&](
Expr *Sub) {
20128 auto IsPotentialResultOdrUsed = [&](
NamedDecl *D) {
20131 auto *VD = dyn_cast<VarDecl>(D);
20154 llvm_unreachable(
"unexpected non-odr-use-reason");
20158 if (VD->getType()->isReferenceType())
20160 if (
auto *RD = VD->getType()->getAsCXXRecordDecl())
20161 if (RD->hasDefinition() && RD->hasMutableFields())
20163 if (!VD->isUsableInConstantExpressions(S.
Context))
20168 if (VD->getType()->isReferenceType())
20176 auto MaybeCUDAODRUsed = [&]() ->
bool {
20182 auto *DRE = dyn_cast<DeclRefExpr>(E);
20185 auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
20192 auto MarkNotOdrUsed = [&] {
20193 if (!MaybeCUDAODRUsed()) {
20196 LSI->markVariableExprAsNonODRUsed(E);
20204 case Expr::DeclRefExprClass: {
20206 if (DRE->isNonOdrUse() || IsPotentialResultOdrUsed(DRE->getDecl()))
20212 S.
Context, DRE->getQualifierLoc(), DRE->getTemplateKeywordLoc(),
20213 DRE->getDecl(), DRE->refersToEnclosingVariableOrCapture(),
20214 DRE->getNameInfo(), DRE->getType(), DRE->getValueKind(),
20215 DRE->getFoundDecl(), CopiedTemplateArgs(DRE), NOUR);
20218 case Expr::FunctionParmPackExprClass: {
20223 if (IsPotentialResultOdrUsed(D))
20234 case Expr::ArraySubscriptExprClass: {
20240 if (!
Base.isUsable())
20242 Expr *LHS = ASE->getBase() == ASE->getLHS() ?
Base.get() : ASE->getLHS();
20243 Expr *RHS = ASE->getBase() == ASE->getRHS() ?
Base.get() : ASE->getRHS();
20246 ASE->getRBracketLoc());
20249 case Expr::MemberExprClass: {
20255 if (!
Base.isUsable())
20258 S.
Context,
Base.get(), ME->isArrow(), ME->getOperatorLoc(),
20259 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(),
20260 ME->getMemberDecl(), ME->getFoundDecl(), ME->getMemberNameInfo(),
20261 CopiedTemplateArgs(ME), ME->getType(), ME->getValueKind(),
20262 ME->getObjectKind(), ME->isNonOdrUse());
20265 if (ME->getMemberDecl()->isCXXInstanceMember())
20270 if (ME->isNonOdrUse() || IsPotentialResultOdrUsed(ME->getMemberDecl()))
20276 S.
Context, ME->getBase(), ME->isArrow(), ME->getOperatorLoc(),
20277 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(), ME->getMemberDecl(),
20278 ME->getFoundDecl(), ME->getMemberNameInfo(), CopiedTemplateArgs(ME),
20279 ME->getType(), ME->getValueKind(), ME->getObjectKind(), NOUR);
20282 case Expr::BinaryOperatorClass: {
20284 Expr *LHS = BO->getLHS();
20285 Expr *RHS = BO->getRHS();
20287 if (BO->getOpcode() == BO_PtrMemD) {
20289 if (!Sub.isUsable())
20291 BO->setLHS(Sub.get());
20293 }
else if (BO->getOpcode() == BO_Comma) {
20295 if (!Sub.isUsable())
20297 BO->setRHS(Sub.get());
20305 case Expr::ParenExprClass: {
20308 if (!Sub.isUsable())
20310 return S.
ActOnParenExpr(PE->getLParen(), PE->getRParen(), Sub.get());
20315 case Expr::ConditionalOperatorClass: {
20326 LHS = CO->getLHS();
20328 RHS = CO->getRHS();
20330 CO->getCond(), LHS.
get(), RHS.
get());
20335 case Expr::UnaryOperatorClass: {
20337 if (UO->getOpcode() != UO_Extension)
20340 if (!Sub.isUsable())
20342 return S.
BuildUnaryOp(
nullptr, UO->getOperatorLoc(), UO_Extension,
20349 case Expr::GenericSelectionExprClass: {
20353 bool AnyChanged =
false;
20354 for (
Expr *OrigAssocExpr : GSE->getAssocExprs()) {
20355 ExprResult AssocExpr = Rebuild(OrigAssocExpr);
20359 AssocExprs.push_back(AssocExpr.
get());
20362 AssocExprs.push_back(OrigAssocExpr);
20366 void *ExOrTy =
nullptr;
20367 bool IsExpr = GSE->isExprPredicate();
20369 ExOrTy = GSE->getControllingExpr();
20371 ExOrTy = GSE->getControllingType();
20373 GSE->getGenericLoc(), GSE->getDefaultLoc(),
20374 GSE->getRParenLoc(), IsExpr, ExOrTy,
20375 GSE->getAssocTypeSourceInfos(), AssocExprs)
20383 case Expr::ChooseExprClass: {
20394 if (!LHS.
get() && !RHS.
get())
20397 LHS = CE->getLHS();
20399 RHS = CE->getRHS();
20402 RHS.
get(), CE->getRParenLoc());
20406 case Expr::ConstantExprClass: {
20409 if (!Sub.isUsable())
20416 case Expr::ImplicitCastExprClass: {
20421 switch (ICE->getCastKind()) {
20423 case CK_DerivedToBase:
20424 case CK_UncheckedDerivedToBase: {
20425 ExprResult Sub = Rebuild(ICE->getSubExpr());
20426 if (!Sub.isUsable())
20430 ICE->getValueKind(), &Path);
20487 for (
Expr *E : LocalMaybeODRUseExprs) {
20488 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
20490 DRE->getLocation(), *
this);
20491 }
else if (
auto *ME = dyn_cast<MemberExpr>(E)) {
20494 }
else if (
auto *FP = dyn_cast<FunctionParmPackExpr>(E)) {
20498 llvm_unreachable(
"Unexpected expression");
20503 "MarkVarDeclODRUsed failed to cleanup MaybeODRUseExprs?");
20512 const bool RefersToEnclosingScope =
20515 if (RefersToEnclosingScope) {
20530 assert(E &&
"Capture variable should be used in an expression.");
20543 "Invalid Expr argument to DoMarkVarDeclReferenced");
20554 bool UsableInConstantExpr =
20573 bool NeededForConstantEvaluation =
20576 bool NeedDefinition =
20577 OdrUse == OdrUseContext::Used || NeededForConstantEvaluation ||
20579 Var->
getType()->isUndeducedType());
20582 "Can't instantiate a partial template specialization.");
20599 bool TryInstantiating =
20603 if (TryInstantiating) {
20606 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
20607 if (FirstInstantiation) {
20608 PointOfInstantiation = Loc;
20610 MSI->setPointOfInstantiation(PointOfInstantiation);
20632 if (
auto *DRE = dyn_cast_or_null<DeclRefExpr>(E))
20633 DRE->setDecl(DRE->getDecl());
20634 else if (
auto *ME = dyn_cast_or_null<MemberExpr>(E))
20635 ME->setMemberDecl(ME->getMemberDecl());
20636 }
else if (FirstInstantiation) {
20638 .push_back(std::make_pair(Var, PointOfInstantiation));
20640 bool Inserted =
false;
20642 auto Iter = llvm::find_if(
20644 return P.first == Var;
20646 if (Iter != I.end()) {
20661 .push_back(std::make_pair(Var, PointOfInstantiation));
20685 if (
DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(E))
20686 if (DRE->isNonOdrUse())
20688 if (
MemberExpr *ME = dyn_cast_or_null<MemberExpr>(E))
20689 if (ME->isNonOdrUse())
20693 case OdrUseContext::None:
20698 "missing non-odr-use marking for unevaluated decl ref");
20701 case OdrUseContext::FormallyOdrUsed:
20706 case OdrUseContext::Used:
20715 case OdrUseContext::Dependent:
20733 if (OdrUse == OdrUseContext::Used) {
20734 QualType CaptureType, DeclRefType;
20740 }
else if (OdrUse == OdrUseContext::Dependent) {
20756 auto *ID = dyn_cast<DeclRefExpr>(E);
20757 if (!ID || ID->isTypeDependent() || !ID->refersToEnclosingVariableOrCapture())
20764 auto IsDependent = [&]() {
20766 auto *LSI = dyn_cast<sema::LambdaScopeInfo>(
Scope);
20771 LSI->AfterParameterList)
20774 const auto *MD = LSI->CallOperator;
20775 if (MD->getType().isNull())
20779 if (!Ty || !MD->isExplicitObjectMemberFunction() ||
20783 if (
auto *
C = LSI->CaptureMap.count(D) ? &LSI->getCapture(D) :
nullptr) {
20784 if (
C->isCopyCapture())
20789 if (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByval)
20795 ID->setCapturedByCopyInLambdaWithExplicitObjectParameter(
20801 bool MightBeOdrUse,
20809 if (
VarDecl *Var = dyn_cast<VarDecl>(D)) {
20828 const MemberExpr *ME = dyn_cast<MemberExpr>(E);
20835 bool IsVirtualCall = MD->
isVirtual() &&
20837 if (!IsVirtualCall)
20854 bool OdrUse =
true;
20856 if (
Method->isVirtual() &&
20860 if (
auto *FD = dyn_cast<FunctionDecl>(E->
getDecl())) {
20865 !FD->isDependentContext())
20879 bool MightBeOdrUse =
true;
20882 if (
Method->isPureVirtual())
20883 MightBeOdrUse =
false;
20902 bool MightBeOdrUse) {
20903 if (MightBeOdrUse) {
20904 if (
auto *VD = dyn_cast<VarDecl>(D)) {
20909 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
20935bool MarkReferencedDecls::TraverseTemplateArgument(
20936 const TemplateArgument &Arg) {
20939 EnterExpressionEvaluationContext
Evaluated(
20953 MarkReferencedDecls Marker(*
this, Loc);
20954 Marker.TraverseType(T);
20960class EvaluatedExprMarker :
public UsedDeclVisitor<EvaluatedExprMarker> {
20963 bool SkipLocalVariables;
20966 EvaluatedExprMarker(
Sema &S,
bool SkipLocalVariables,
20968 : Inherited(S), SkipLocalVariables(SkipLocalVariables), StopAt(StopAt) {}
20974 void Visit(Expr *E) {
20975 if (llvm::is_contained(StopAt, E))
20977 Inherited::Visit(E);
20980 void VisitConstantExpr(ConstantExpr *E) {
20985 void VisitDeclRefExpr(DeclRefExpr *E) {
20987 if (SkipLocalVariables) {
20988 if (VarDecl *VD = dyn_cast<VarDecl>(E->
getDecl()))
20989 if (VD->hasLocalStorage())
20999 void VisitMemberExpr(MemberExpr *E) {
21007 bool SkipLocalVariables,
21009 EvaluatedExprMarker(*
this, SkipLocalVariables, StopAt).Visit(E);
21021 (
Decl->isConstexpr() || (
Decl->isStaticDataMember() &&
21025 if (Stmts.empty()) {
21039 if (
Decl &&
Decl->isFileVarDecl()) {
21112 class CallReturnIncompleteDiagnoser :
public TypeDiagnoser {
21118 : FD(FD), CE(CE) { }
21122 S.
Diag(Loc, diag::err_call_incomplete_return)
21127 S.
Diag(Loc, diag::err_call_function_incomplete_return)
21132 } Diagnoser(FD, CE);
21145 unsigned diagnostic = diag::warn_condition_is_assignment;
21146 bool IsOrAssign =
false;
21149 if (Op->getOpcode() != BO_Assign && Op->getOpcode() != BO_OrAssign)
21152 IsOrAssign = Op->getOpcode() == BO_OrAssign;
21160 if (
ObjC().isSelfExpr(Op->getLHS()) && ME->getMethodFamily() ==
OMF_init)
21161 diagnostic = diag::warn_condition_is_idiomatic_assignment;
21165 diagnostic = diag::warn_condition_is_idiomatic_assignment;
21168 Loc = Op->getOperatorLoc();
21170 if (Op->getOperator() != OO_Equal && Op->getOperator() != OO_PipeEqual)
21173 IsOrAssign = Op->getOperator() == OO_PipeEqual;
21174 Loc = Op->getOperatorLoc();
21186 Diag(Loc, diag::note_condition_assign_silence)
21191 Diag(Loc, diag::note_condition_or_assign_to_comparison)
21194 Diag(Loc, diag::note_condition_assign_to_comparison)
21212 if (opE->getOpcode() == BO_EQ &&
21213 opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(
Context)
21219 Diag(Loc, diag::note_equality_comparison_silence)
21222 Diag(Loc, diag::note_equality_comparison_to_assign)
21228 bool IsConstexpr) {
21230 if (
ParenExpr *parenE = dyn_cast<ParenExpr>(E))
21250 if (!T->isScalarType()) {
21251 Diag(Loc, diag::err_typecheck_statement_requires_scalar)
21255 CheckBoolLikeConversion(E, Loc);
21284 if (
Cond.isInvalid()) {
21292 if (!
Cond.isUsable())
21302 struct RebuildUnknownAnyFunction
21303 :
StmtVisitor<RebuildUnknownAnyFunction, ExprResult> {
21307 RebuildUnknownAnyFunction(
Sema &S) : S(S) {}
21310 llvm_unreachable(
"unexpected statement!");
21321 template <
class T>
ExprResult rebuildSugarExpr(T *E) {
21322 ExprResult SubResult = Visit(E->getSubExpr());
21325 Expr *SubExpr = SubResult.
get();
21326 E->setSubExpr(SubExpr);
21327 E->setType(SubExpr->
getType());
21334 return rebuildSugarExpr(E);
21337 ExprResult VisitUnaryExtension(UnaryOperator *E) {
21338 return rebuildSugarExpr(E);
21341 ExprResult VisitUnaryAddrOf(UnaryOperator *E) {
21345 Expr *SubExpr = SubResult.
get();
21353 ExprResult resolveDecl(Expr *E, ValueDecl *VD) {
21371 ExprResult VisitDeclRefExpr(DeclRefExpr *E) {
21372 return resolveDecl(E, E->
getDecl());
21390 struct RebuildUnknownAnyExpr
21391 : StmtVisitor<RebuildUnknownAnyExpr, ExprResult> {
21398 RebuildUnknownAnyExpr(Sema &S, QualType
CastType)
21402 llvm_unreachable(
"unexpected statement!");
21412 ExprResult VisitObjCMessageExpr(ObjCMessageExpr *E);
21416 template <
class T>
ExprResult rebuildSugarExpr(T *E) {
21417 ExprResult SubResult = Visit(E->getSubExpr());
21419 Expr *SubExpr = SubResult.
get();
21420 E->setSubExpr(SubExpr);
21421 E->setType(SubExpr->
getType());
21428 return rebuildSugarExpr(E);
21431 ExprResult VisitUnaryExtension(UnaryOperator *E) {
21432 return rebuildSugarExpr(E);
21435 ExprResult VisitUnaryAddrOf(UnaryOperator *E) {
21436 const PointerType *Ptr = DestType->
getAs<PointerType>();
21461 ExprResult VisitImplicitCastExpr(ImplicitCastExpr *E);
21463 ExprResult resolveDecl(Expr *E, ValueDecl *VD);
21469 ExprResult VisitDeclRefExpr(DeclRefExpr *E) {
21470 return resolveDecl(E, E->
getDecl());
21476ExprResult RebuildUnknownAnyExpr::VisitCallExpr(CallExpr *E) {
21481 FK_FunctionPointer,
21486 QualType CalleeType = CalleeExpr->
getType();
21489 Kind = FK_MemberFunction;
21491 }
else if (
const PointerType *Ptr = CalleeType->
getAs<PointerType>()) {
21493 Kind = FK_FunctionPointer;
21496 Kind = FK_BlockPointer;
21498 const FunctionType *FnType = CalleeType->
castAs<FunctionType>();
21503 unsigned diagID = diag::err_func_returning_array_function;
21504 if (Kind == FK_BlockPointer)
21505 diagID = diag::err_block_returning_array_function;
21518 const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FnType);
21540 SmallVector<QualType, 8> ArgTypes;
21541 if (ParamTypes.empty() && Proto->
isVariadic()) {
21543 for (
unsigned i = 0, e = E->
getNumArgs(); i != e; ++i) {
21546 ParamTypes = ArgTypes;
21557 case FK_MemberFunction:
21561 case FK_FunctionPointer:
21565 case FK_BlockPointer:
21571 ExprResult CalleeResult = Visit(CalleeExpr);
21579ExprResult RebuildUnknownAnyExpr::VisitObjCMessageExpr(ObjCMessageExpr *E) {
21582 S.
Diag(E->
getExprLoc(), diag::err_func_returning_array_function)
21590 Method->setReturnType(DestType);
21600ExprResult RebuildUnknownAnyExpr::VisitImplicitCastExpr(ImplicitCastExpr *E) {
21602 if (E->
getCastKind() == CK_FunctionToPointerDecay) {
21616 }
else if (E->
getCastKind() == CK_LValueToRValue) {
21633 llvm_unreachable(
"Unhandled cast type!");
21637ExprResult RebuildUnknownAnyExpr::resolveDecl(Expr *E, ValueDecl *VD) {
21639 QualType
Type = DestType;
21644 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(VD)) {
21645 if (
const PointerType *Ptr =
Type->getAs<PointerType>()) {
21653 if (!
Type->isFunctionType()) {
21658 if (
const FunctionProtoType *FT =
Type->getAs<FunctionProtoType>()) {
21662 QualType FDT = FD->getType();
21663 const FunctionType *FnType = FDT->
castAs<FunctionType>();
21664 const FunctionProtoType *Proto = dyn_cast_or_null<FunctionProtoType>(FnType);
21665 DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
21666 if (DRE && Proto && Proto->getParamTypes().empty() && Proto->isVariadic()) {
21667 SourceLocation Loc = FD->getLocation();
21669 S.
Context, FD->getDeclContext(), Loc, Loc,
21670 FD->getNameInfo().getName(), DestType, FD->getTypeSourceInfo(),
21672 false , FD->hasPrototype(),
21675 if (FD->getQualifier())
21678 SmallVector<ParmVarDecl*, 16> Params;
21679 for (
const auto &AI : FT->param_types()) {
21680 ParmVarDecl *Param =
21683 Params.push_back(Param);
21685 NewFD->setParams(Params);
21691 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
21692 if (MD->isInstance()) {
21703 if (
const ReferenceType *RefTy =
Type->getAs<ReferenceType>()) {
21704 Type = RefTy->getPointeeType();
21705 }
else if (
Type->isFunctionType()) {
21706 S.
Diag(E->
getExprLoc(), diag::err_unknown_any_var_function_type)
21732 diag::err_typecheck_cast_to_incomplete))
21747 return RebuildUnknownAnyExpr(*
this, ToType).Visit(E);
21754 ExplicitCastExpr *castArg = dyn_cast<ExplicitCastExpr>(arg->IgnoreParens());
21763 assert(!arg->hasPlaceholderType());
21775 unsigned diagID = diag::err_uncasted_use_of_unknown_any;
21778 if (
CallExpr *call = dyn_cast<CallExpr>(E)) {
21779 E = call->getCallee();
21780 diagID = diag::err_uncasted_call_of_unknown_any;
21788 if (
DeclRefExpr *ref = dyn_cast<DeclRefExpr>(E)) {
21789 loc = ref->getLocation();
21790 d = ref->getDecl();
21791 }
else if (
MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
21792 loc = mem->getMemberLoc();
21793 d = mem->getMemberDecl();
21795 diagID = diag::err_uncasted_call_of_unknown_any;
21796 loc = msg->getSelectorStartLoc();
21797 d = msg->getMethodDecl();
21799 S.
Diag(loc, diag::err_uncasted_send_to_unknown_any_method)
21800 <<
static_cast<unsigned>(msg->isClassMessage()) << msg->getSelector()
21818 if (!placeholderType)
return E;
21820 switch (placeholderType->
getKind()) {
21821 case BuiltinType::UnresolvedTemplate: {
21834 if (
auto *TD = dyn_cast<TemplateDecl>(Temp))
21835 TN =
Context.getQualifiedTemplateName(NNS, ULE->hasTemplateKeyword(),
21840 Diag(NameInfo.
getLoc(), diag::err_template_kw_refers_to_type_template)
21841 << TN << ULE->getSourceRange() << IsTypeAliasTemplateDecl;
21843 << IsTypeAliasTemplateDecl;
21846 bool HasAnyDependentTA =
false;
21848 HasAnyDependentTA |= Arg.getArgument().
isDependent();
21860 TST =
Context.getTemplateSpecializationType(
21869 case BuiltinType::Overload: {
21889 case BuiltinType::BoundMember: {
21895 PD =
PDiag(diag::err_dtor_expr_without_call) << 1;
21896 }
else if (
const auto *ME = dyn_cast<MemberExpr>(BME)) {
21897 if (ME->getMemberNameInfo().getName().getNameKind() ==
21899 PD =
PDiag(diag::err_dtor_expr_without_call) << 0;
21907 case BuiltinType::ARCUnbridgedCast: {
21914 case BuiltinType::UnknownAny:
21918 case BuiltinType::PseudoObject:
21921 case BuiltinType::BuiltinFn: {
21926 unsigned BuiltinID = FD->getBuiltinID();
21927 if (BuiltinID == Builtin::BI__noop) {
21929 CK_BuiltinFnToFnPtr)
21936 if (
Context.BuiltinInfo.isInStdNamespace(BuiltinID)) {
21942 ? diag::err_use_of_unaddressable_function
21943 : diag::warn_cxx20_compat_use_of_unaddressable_function);
21944 if (FD->isImplicitlyInstantiable()) {
21971 case BuiltinType::IncompleteMatrixIdx: {
21977 MS->getBase(), MS->getRowIdx(), E->
getExprLoc());
21979 Diag(MS->getRowIdx()->getBeginLoc(), diag::err_matrix_incomplete_index);
21984 case BuiltinType::ArraySection:
21993 case BuiltinType::OMPArrayShaping:
21996 case BuiltinType::OMPIterator:
22000#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
22001 case BuiltinType::Id:
22002#include "clang/Basic/OpenCLImageTypes.def"
22003#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
22004 case BuiltinType::Id:
22005#include "clang/Basic/OpenCLExtensionTypes.def"
22006#define SVE_TYPE(Name, Id, SingletonId) \
22007 case BuiltinType::Id:
22008#include "clang/Basic/AArch64ACLETypes.def"
22009#define PPC_VECTOR_TYPE(Name, Id, Size) \
22010 case BuiltinType::Id:
22011#include "clang/Basic/PPCTypes.def"
22012#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22013#include "clang/Basic/RISCVVTypes.def"
22014#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22015#include "clang/Basic/WebAssemblyReferenceTypes.def"
22016#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
22017#include "clang/Basic/AMDGPUTypes.def"
22018#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22019#include "clang/Basic/HLSLIntangibleTypes.def"
22020#define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id:
22021#define PLACEHOLDER_TYPE(Id, SingletonId)
22022#include "clang/AST/BuiltinTypes.def"
22026 llvm_unreachable(
"invalid placeholder type!");
22039 if (!
Context.getLangOpts().RecoveryAST)
22045 if (T.isNull() || T->isUndeducedType() ||
22046 !
Context.getLangOpts().RecoveryASTType)
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
static bool isObjCPointer(const MemRegion *R)
Defines enum values for all the target-independent builtin functions.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
static DeclT * getDefinitionOrSelf(DeclT *D)
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
Defines the clang::Expr interface and subclasses for C++ expressions.
Result
Implement __builtin_bit_cast and related operations.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Target Target
llvm::MachO::Record Record
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::Preprocessor interface.
static QualType getUnderlyingType(const SubRegion *R)
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file declares semantic analysis functions specific to AMDGPU.
This file declares semantic analysis functions specific to ARM.
This file declares semantic analysis for CUDA constructs.
static void DetectPrecisionLossInComplexDivision(Sema &S, QualType DivisorTy, SourceLocation OpLoc)
static void HandleImmediateInvocations(Sema &SemaRef, Sema::ExpressionEvaluationContextRecord &Rec)
static ExprResult BuildCookedLiteralOperatorCall(Sema &S, Scope *Scope, IdentifierInfo *UDSuffix, SourceLocation UDSuffixLoc, ArrayRef< Expr * > Args, SourceLocation LitEndLoc)
BuildCookedLiteralOperatorCall - A user-defined literal was found.
static ExprResult BuildOverloadedBinOp(Sema &S, Scope *Sc, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS)
Build an overloaded binary operator expression in the given scope.
static bool canConvertIntTyToFloatTy(Sema &S, ExprResult *Int, QualType FloatTy)
Test if a (constant) integer Int can be casted to floating point type FloatTy without losing precisio...
static bool checkArithmeticOpPointerOperand(Sema &S, SourceLocation Loc, Expr *Operand)
Check the validity of an arithmetic pointer operand.
static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
DiagnoseBitwisePrecedence - Emit a warning when bitwise and comparison operators are mixed in a way t...
static bool isPlaceholderToRemoveAsArg(QualType type)
Is the given type a placeholder that we need to lower out immediately during argument processing?
static void diagnoseArithmeticOnNullPointer(Sema &S, SourceLocation Loc, Expr *Pointer, bool IsGNUIdiom)
Diagnose invalid arithmetic on a null pointer.
static void DiagnoseConditionalPrecedence(Sema &Self, SourceLocation OpLoc, Expr *Condition, const Expr *LHSExpr, const Expr *RHSExpr)
DiagnoseConditionalPrecedence - Emit a warning when a conditional operator and binary operator are mi...
static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D, bool AcceptInvalid)
Diagnoses obvious problems with the use of the given declaration as an expression.
static void diagnoseUncapturableValueReferenceOrBinding(Sema &S, SourceLocation loc, ValueDecl *var)
static QualType checkConditionalObjectPointersCompatibility(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
Return the resulting type when the operands are both pointers.
static QualType OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, SourceLocation QuestionLoc)
Return the resulting type for the conditional operator in OpenCL (aka "ternary selection operator",...
static void diagnoseLogicalNotOnLHSofCheck(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, BinaryOperatorKind Opc)
Warns on !x < y, !x & y where !(x < y), !(x & y) was probably intended.
static void diagnoseArithmeticOnFunctionPointer(Sema &S, SourceLocation Loc, Expr *Pointer)
Diagnose invalid arithmetic on a function pointer.
static AssignConvertType checkObjCPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType)
checkObjCPointerTypesForAssignment - Compares two objective-c pointer types for assignment compatibil...
static void diagnoseObjCLiteralComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, BinaryOperator::Opcode Opc)
static bool isParenthetizedAndQualifiedAddressOfExpr(Expr *Fn)
static bool isCapturingReferenceToHostVarInCUDADeviceLambda(const Sema &S, VarDecl *VD)
static UnaryOperatorKind ConvertTokenKindToUnaryOpcode(tok::TokenKind Kind)
static bool isImplicitlyDefinableConstexprFunction(FunctionDecl *Func)
NonConstCaptureKind
Is the given expression (which must be 'const') a reference to a variable which was originally non-co...
static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar, QualType scalarTy, QualType vectorEltTy, QualType vectorTy, unsigned &DiagID)
Try to convert a value of non-vector type to a vector type by converting the type to the element type...
static bool isVector(QualType QT, QualType ElementType)
This helper function returns true if QT is a vector type that has element type ElementType.
static void DiagnoseCalleeStaticArrayParam(Sema &S, ParmVarDecl *PVD)
static Expr * recoverFromMSUnqualifiedLookup(Sema &S, ASTContext &Context, DeclarationNameInfo &NameInfo, SourceLocation TemplateKWLoc, const TemplateArgumentListInfo *TemplateArgs)
In Microsoft mode, if we are inside a template class whose parent class has dependent base classes,...
static AssignConvertType checkBlockPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType)
checkBlockPointerTypesForAssignment - This routine determines whether two block pointer types are com...
static void FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter(Sema &SemaRef, ValueDecl *D, Expr *E)
static bool isVariableCapturable(CapturingScopeInfo *CSI, ValueDecl *Var, SourceLocation Loc, const bool Diagnose, Sema &S)
static bool maybeDiagnoseAssignmentToFunction(Sema &S, QualType DstType, const Expr *SrcExpr)
static void SuggestParentheses(Sema &Self, SourceLocation Loc, const PartialDiagnostic &Note, SourceRange ParenRange)
SuggestParentheses - Emit a note with a fixit hint that wraps ParenRange in parentheses.
static Decl * getPredefinedExprDecl(DeclContext *DC)
getPredefinedExprDecl - Returns Decl of a given DeclContext that can be used to determine the value o...
static CXXRecordDecl * LookupStdSourceLocationImpl(Sema &S, SourceLocation Loc)
static bool IgnoreCommaOperand(const Expr *E, const ASTContext &Context)
static QualType CheckRealImagOperand(Sema &S, ExprResult &V, SourceLocation Loc, bool IsReal)
static QualType checkArithmeticOrEnumeralCompare(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, BinaryOperatorKind Opc)
static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK, SourceLocation OpLoc, bool IsAfterAmp=false)
CheckIndirectionOperand - Type check unary indirection (prefix '*').
static bool CheckAlignOfExpr(Sema &S, Expr *E, UnaryExprOrTypeTrait ExprKind)
static bool ExprLooksBoolean(const Expr *E)
ExprLooksBoolean - Returns true if E looks boolean, i.e.
static bool isPotentiallyConstantEvaluatedContext(Sema &SemaRef)
Are we in a context that is potentially constant evaluated per C++20 [expr.const]p12?
static void DiagnoseSelfAssignment(Sema &S, Expr *LHSExpr, Expr *RHSExpr, SourceLocation OpLoc, bool IsBuiltin)
DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
static void diagnoseStringPlusInt(Sema &Self, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
diagnoseStringPlusInt - Emit a warning when adding an integer to a string literal.
static QualType checkConditionalPointerCompatibility(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
Checks compatibility between two pointers and return the resulting type.
static void DoMarkVarDeclReferenced(Sema &SemaRef, SourceLocation Loc, VarDecl *Var, Expr *E, llvm::DenseMap< const VarDecl *, int > &RefsMinusAssignments)
static bool ShouldLookupResultBeMultiVersionOverload(const LookupResult &R)
static bool checkCondition(Sema &S, const Expr *Cond, SourceLocation QuestionLoc)
Return false if the condition expression is valid, true otherwise.
static bool checkForArray(const Expr *E)
static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, const CallExpr *Call)
static void DiagnoseRecursiveConstFields(Sema &S, const ValueDecl *VD, const RecordType *Ty, SourceLocation Loc, SourceRange Range, OriginalExprKind OEK, bool &DiagnosticEmitted)
static bool areTypesCompatibleForGeneric(ASTContext &Ctx, QualType T, QualType U)
static void MarkExprReferenced(Sema &SemaRef, SourceLocation Loc, Decl *D, Expr *E, bool MightBeOdrUse, llvm::DenseMap< const VarDecl *, int > &RefsMinusAssignments)
static bool MayBeFunctionType(const ASTContext &Context, const Expr *E)
static ExprResult convertVector(Expr *E, QualType ElementType, Sema &S)
Convert vector E to a vector with the same number of elements but different element type.
static void DoMarkPotentialCapture(Sema &SemaRef, SourceLocation Loc, ValueDecl *Var, Expr *E)
static void RecordModifiableNonNullParam(Sema &S, const Expr *Exp)
static void EvaluateAndDiagnoseImmediateInvocation(Sema &SemaRef, Sema::ImmediateInvocationCandidate Candidate)
static bool checkThreeWayNarrowingConversion(Sema &S, QualType ToType, Expr *E, QualType FromType, SourceLocation Loc)
static bool IsArithmeticBinaryExpr(const Expr *E, BinaryOperatorKind *Opcode, const Expr **RHSExprs)
IsArithmeticBinaryExpr - Returns true if E is an arithmetic binary expression, either using a built-i...
static ExprResult convertHalfVecBinOp(Sema &S, ExprResult LHS, ExprResult RHS, BinaryOperatorKind Opc, QualType ResultTy, ExprValueKind VK, ExprObjectKind OK, bool IsCompAssign, SourceLocation OpLoc, FPOptionsOverride FPFeatures)
static QualType handleIntegerConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
Handle integer arithmetic conversions.
static void checkDirectCallValidity(Sema &S, const Expr *Fn, FunctionDecl *Callee, MultiExprArg ArgExprs)
static void ConstructTransparentUnion(Sema &S, ASTContext &C, ExprResult &EResult, QualType UnionType, FieldDecl *Field)
Constructs a transparent union from an expression that is used to initialize the transparent union.
static QualType OpenCLConvertScalarsToVectors(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType CondTy, SourceLocation QuestionLoc)
Convert scalar operands to a vector that matches the condition in length.
static bool checkConditionalNullPointer(Sema &S, ExprResult &NullExpr, QualType PointerTy)
Return false if the NullExpr can be promoted to PointerTy, true otherwise.
static void diagnoseSubtractionOnNullPointer(Sema &S, SourceLocation Loc, Expr *Pointer, bool BothNull)
Diagnose invalid subraction on a null pointer.
static bool checkArithmeticOnObjCPointer(Sema &S, SourceLocation opLoc, Expr *op)
Diagnose if arithmetic on the given ObjC pointer is illegal.
static void RemoveNestedImmediateInvocation(Sema &SemaRef, Sema::ExpressionEvaluationContextRecord &Rec, SmallVector< Sema::ImmediateInvocationCandidate, 4 >::reverse_iterator It)
static void CheckUnicodeArithmeticConversions(Sema &SemaRef, Expr *LHS, Expr *RHS, SourceLocation Loc, ArithConvKind ACK)
static void DiagnoseBitwiseOpInBitwiseOp(Sema &S, BinaryOperatorKind Opc, SourceLocation OpLoc, Expr *SubExpr)
Look for bitwise op in the left or right hand of a bitwise op with lower precedence and emit a diagno...
static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, ExprValueKind &VK, ExprObjectKind &OK, SourceLocation OpLoc, bool IsInc, bool IsPrefix)
CheckIncrementDecrementOperand - unlike most "Check" methods, this routine doesn't need to call Usual...
static QualType OpenCLArithmeticConversions(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation QuestionLoc)
Simple conversion between integer and floating point types.
static bool checkVectorResult(Sema &S, QualType CondTy, QualType VecResTy, SourceLocation QuestionLoc)
Return false if the vector condition type and the vector result type are compatible.
static void DiagnoseDivisionSizeofPointerOrArray(Sema &S, Expr *LHS, Expr *RHS, SourceLocation Loc)
static void diagnoseTautologicalComparison(Sema &S, SourceLocation Loc, Expr *LHS, Expr *RHS, BinaryOperatorKind Opc)
Diagnose some forms of syntactically-obvious tautological comparison.
static void warnOnSizeofOnArrayDecay(Sema &S, SourceLocation Loc, QualType T, const Expr *E)
Check whether E is a pointer from a decayed array type (the decayed pointer type is equal to T) and e...
static void DiagnoseBadDivideOrRemainderValues(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsDiv)
static void ConvertUTF8ToWideString(unsigned CharByteWidth, StringRef Source, SmallString< 32 > &Target)
static TypoCorrection TryTypoCorrectionForCall(Sema &S, Expr *Fn, FunctionDecl *FDecl, ArrayRef< Expr * > Args)
static bool hasAnyExplicitStorageClass(const FunctionDecl *D)
Determine whether a FunctionDecl was ever declared with an explicit storage class.
static void DiagnoseBadShiftValues(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, BinaryOperatorKind Opc, QualType LHSType)
static bool CheckVecStepTraitOperandType(Sema &S, QualType T, SourceLocation Loc, SourceRange ArgRange)
static bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var, SourceLocation Loc, const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const bool RefersToCapturedVariable, const TryCaptureKind Kind, SourceLocation EllipsisLoc, const bool IsTopScope, Sema &S, bool Invalid)
Capture the given variable in the lambda.
static bool unsupportedTypeConversion(const Sema &S, QualType LHSType, QualType RHSType)
Diagnose attempts to convert between __float128, __ibm128 and long double if there is no support for ...
static void MarkVarDeclODRUsed(ValueDecl *V, SourceLocation Loc, Sema &SemaRef, const unsigned *const FunctionScopeIndexToStopAt=nullptr)
Directly mark a variable odr-used.
static void diagnoseStringPlusChar(Sema &Self, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
Emit a warning when adding a char literal to a string.
static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S)
CheckForModifiableLvalue - Verify that E is a modifiable lvalue.
static ValueDecl * getPrimaryDecl(Expr *E)
getPrimaryDecl - Helper function for CheckAddressOfOperand().
static void diagnoseUseOfInternalDeclInInlineFunction(Sema &S, const NamedDecl *D, SourceLocation Loc)
Check whether we're in an extern inline function and referring to a variable or function with interna...
static bool funcHasParameterSizeMangling(Sema &S, FunctionDecl *FD)
Return true if this function has a calling convention that requires mangling in the size of the param...
static bool convertPointersToCompositeType(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS)
Returns false if the pointers are converted to a composite type, true otherwise.
static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
DiagnoseBinOpPrecedence - Emit warnings for expressions with tricky precedence.
static void diagnoseAddressOfInvalidType(Sema &S, SourceLocation Loc, Expr *E, unsigned Type)
Diagnose invalid operand for address of operations.
static QualType handleComplexIntConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
Handle conversions with GCC complex int extension.
static AssignConvertType checkPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType, SourceLocation Loc)
static bool isMSPropertySubscriptExpr(Sema &S, Expr *Base)
static bool tryGCCVectorConvertAndSplat(Sema &S, ExprResult *Scalar, ExprResult *Vector)
Attempt to convert and splat Scalar into a vector whose types matches Vector following GCC conversion...
static void diagnoseScopedEnums(Sema &S, const SourceLocation Loc, const ExprResult &LHS, const ExprResult &RHS, BinaryOperatorKind Opc)
static void DiagnoseLogicalAndInLogicalOrLHS(Sema &S, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
Look for '&&' in the left hand of a '||' expr.
static void CheckForNullPointerDereference(Sema &S, Expr *E)
static QualType computeConditionalNullability(QualType ResTy, bool IsBin, QualType LHSTy, QualType RHSTy, ASTContext &Ctx)
Compute the nullability of a conditional expression.
static OdrUseContext isOdrUseContext(Sema &SemaRef)
Are we within a context in which references to resolved functions or to variables result in odr-use?
static void DiagnoseConstAssignment(Sema &S, const Expr *E, SourceLocation Loc)
Emit the "read-only variable not assignable" error and print notes to give more information about why...
static Expr * BuildFloatingLiteral(Sema &S, NumericLiteralParser &Literal, QualType Ty, SourceLocation Loc)
static bool IsTypeModifiable(QualType Ty, bool IsDereference)
static bool isVariableAlreadyCapturedInScopeInfo(CapturingScopeInfo *CSI, ValueDecl *Var, bool &SubCapturesAreNested, QualType &CaptureType, QualType &DeclRefType)
static bool checkArithmeticIncompletePointerType(Sema &S, SourceLocation Loc, Expr *Operand)
Emit error if Operand is incomplete pointer type.
static bool CheckExtensionTraitOperandType(Sema &S, QualType T, SourceLocation Loc, SourceRange ArgRange, UnaryExprOrTypeTrait TraitKind)
static void CheckSufficientAllocSize(Sema &S, QualType DestType, const Expr *E)
Check that a call to alloc_size function specifies sufficient space for the destination type.
static QualType checkSizelessVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign)
static QualType checkArithmeticOrEnumeralThreeWayCompare(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
static ExprResult diagnoseUnknownAnyExpr(Sema &S, Expr *E)
static QualType handleOverflowBehaviorTypeConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
static SourceLocation getUDSuffixLoc(Sema &S, SourceLocation TokLoc, unsigned Offset)
getUDSuffixLoc - Create a SourceLocation for a ud-suffix, given the location of the token and the off...
static bool checkBlockType(Sema &S, const Expr *E)
Return true if the Expr is block type.
static bool captureInBlock(BlockScopeInfo *BSI, ValueDecl *Var, SourceLocation Loc, const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const bool Nested, Sema &S, bool Invalid)
static QualType handleFloatConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
Handle arithmethic conversion with floating point types.
static void diagnoseArithmeticOnVoidPointer(Sema &S, SourceLocation Loc, Expr *Pointer)
Diagnose invalid arithmetic on a void pointer.
static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign)
Return the resulting type when a vector is shifted by a scalar or vector shift amount.
static FieldDecl * FindFieldDeclInstantiationPattern(const ASTContext &Ctx, FieldDecl *Field)
ExprResult PerformCastFn(Sema &S, Expr *operand, QualType toType)
static void checkArithmeticNull(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompare)
static bool IsReadonlyMessage(Expr *E, Sema &S)
static std::optional< bool > isTautologicalBoundsCheck(Sema &S, const Expr *LHS, const Expr *RHS, BinaryOperatorKind Opc)
Detect patterns ptr + size >= ptr and ptr + size < ptr, where ptr is a pointer and size is an unsigne...
static void buildLambdaCaptureFixit(Sema &Sema, LambdaScopeInfo *LSI, ValueDecl *Var)
Create up to 4 fix-its for explicit reference and value capture of Var or default capture.
static void tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs(Sema &S, const UnresolvedMemberExpr *const UME, SourceLocation CallLoc)
static bool checkPtrAuthTypeDiscriminatorOperandType(Sema &S, QualType T, SourceLocation Loc, SourceRange ArgRange)
static bool CheckVectorElementsTraitOperandType(Sema &S, QualType T, SourceLocation Loc, SourceRange ArgRange)
static void DiagnoseLogicalAndInLogicalOrRHS(Sema &S, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
Look for '&&' in the right hand of a '||' expr.
static QualType getDependentArraySubscriptType(Expr *LHS, Expr *RHS, const ASTContext &Ctx)
static void diagnosePointerIncompatibility(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr)
Emit error when two pointers are incompatible.
static bool captureInCapturedRegion(CapturedRegionScopeInfo *RSI, ValueDecl *Var, SourceLocation Loc, const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const bool RefersToCapturedVariable, TryCaptureKind Kind, bool IsTopScope, Sema &S, bool Invalid)
Capture the given variable in the captured region.
static bool enclosingClassIsRelatedToClassInWhichMembersWereFound(const UnresolvedMemberExpr *const UME, Sema &S)
static unsigned GetFixedPointRank(QualType Ty)
Return the rank of a given fixed point or integer type.
static bool CheckObjCTraitOperandConstraints(Sema &S, QualType T, SourceLocation Loc, SourceRange ArgRange, UnaryExprOrTypeTrait TraitKind)
static void diagnoseArithmeticOnTwoFunctionPointers(Sema &S, SourceLocation Loc, Expr *LHS, Expr *RHS)
Diagnose invalid arithmetic on two function pointers.
static bool checkPointerIntegerMismatch(Sema &S, ExprResult &Int, Expr *PointerExpr, SourceLocation Loc, bool IsIntFirstExpr)
Return false if the first expression is not an integer and the second expression is not a pointer,...
static ImplicitConversionKind castKindToImplicitConversionKind(CastKind CK)
static void diagnoseXorMisusedAsPow(Sema &S, const ExprResult &XorLHS, const ExprResult &XorRHS, const SourceLocation Loc)
static bool checkOpenCLConditionVector(Sema &S, Expr *Cond, SourceLocation QuestionLoc)
Return false if this is a valid OpenCL condition vector.
static bool IsArithmeticOp(BinaryOperatorKind Opc)
static bool handleComplexIntegerToFloatConversion(Sema &S, ExprResult &IntExpr, ExprResult &ComplexExpr, QualType IntTy, QualType ComplexTy, bool SkipCast)
Convert complex integers to complex floats and real integers to real floats as required for complex a...
static void checkObjCPointerIntrospection(Sema &S, ExprResult &L, ExprResult &R, SourceLocation OpLoc)
Check if a bitwise-& is performed on an Objective-C pointer.
static void DiagnoseDirectIsaAccess(Sema &S, const ObjCIvarRefExpr *OIRE, SourceLocation AssignLoc, const Expr *RHS)
static ExprResult rebuildUnknownAnyFunction(Sema &S, Expr *fn)
Given a function expression of unknown-any type, try to rebuild it to have a function type.
static QualType handleIntToFloatConversion(Sema &S, ExprResult &FloatExpr, ExprResult &IntExpr, QualType FloatTy, QualType IntTy, bool ConvertFloat, bool ConvertInt)
Handle arithmetic conversion from integer to float.
static bool hasIsEqualMethod(Sema &S, const Expr *LHS, const Expr *RHS)
static QualType handleComplexFloatConversion(Sema &S, ExprResult &Shorter, QualType ShorterType, QualType LongerType, bool PromotePrecision)
static FunctionDecl * rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context, FunctionDecl *FDecl, MultiExprArg ArgExprs)
If a builtin function has a pointer argument with no explicit address space, then it should be able t...
static void DoMarkBindingDeclReferenced(Sema &SemaRef, SourceLocation Loc, BindingDecl *BD, Expr *E)
static PredefinedIdentKind getPredefinedExprKind(tok::TokenKind Kind)
static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc)
static QualType handleFixedPointConversion(Sema &S, QualType LHSTy, QualType RHSTy)
handleFixedPointConversion - Fixed point operations between fixed point types and integers or other f...
static QualType handleComplexConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
Handle arithmetic conversion with complex types.
static QualType CheckCommaOperands(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
static bool canCaptureVariableByCopy(ValueDecl *Var, const ASTContext &Context)
static void diagnoseArithmeticOnTwoVoidPointers(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr)
Diagnose invalid arithmetic on two void pointers.
static void diagnoseDistinctPointerComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, bool IsError)
Diagnose bad pointer comparisons.
static bool needsConversionOfHalfVec(bool OpRequiresConversion, ASTContext &Ctx, Expr *E0, Expr *E1=nullptr)
Returns true if conversion between vectors of halfs and vectors of floats is needed.
static bool isObjCObjectLiteral(ExprResult &E)
static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E)
static QualType checkConditionalBlockPointerCompatibility(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
Return the resulting type when the operands are both block pointers.
static void DiagnoseShiftCompare(Sema &S, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
static void DiagnoseAdditionInShift(Sema &S, SourceLocation OpLoc, Expr *SubExpr, StringRef Shift)
static void diagnoseFunctionPointerToVoidComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, bool IsError)
static void EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, BinaryOperator *Bop)
It accepts a '&&' expr that is inside a '||' one.
static void captureVariablyModifiedType(ASTContext &Context, QualType T, CapturingScopeInfo *CSI)
static bool canConvertIntToOtherIntTy(Sema &S, ExprResult *Int, QualType OtherIntTy)
Test if a (constant) integer Int can be casted to another integer type IntTy without losing precision...
static DeclContext * getParentOfCapturingContextOrNull(DeclContext *DC, ValueDecl *Var, SourceLocation Loc, const bool Diagnose, Sema &S)
static bool isOverflowingIntegerType(ASTContext &Ctx, QualType T)
static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr, SourceLocation Loc, Sema &Sema)
static bool isLegalBoolVectorBinaryOp(BinaryOperatorKind Opc)
static ExprResult rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E, NonOdrUseReason NOUR)
Walk the set of potential results of an expression and mark them all as non-odr-uses if they satisfy ...
static void CheckCompleteParameterTypesForMangler(Sema &S, FunctionDecl *FD, SourceLocation Loc)
Require that all of the parameter types of function be complete.
static bool isScopedEnumerationType(QualType T)
static bool checkArithmeticBinOpPointerOperands(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr)
Check the validity of a binary arithmetic operation w.r.t.
static bool breakDownVectorType(QualType type, uint64_t &len, QualType &eltType)
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis for expressions involving.
static bool isInvalid(LocType Loc, bool *Invalid)
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
static QualType getPointeeType(const MemRegion *R)
Defines the clang::TypeLoc interface and its subclasses.
Defines enumerations for the type traits support.
C Language Family Type Representation.
@ Open
The standard open() call: int open(const char *path, int oflag, ...);.
a trap message and trap category.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
unsigned getIntWidth(QualType T) const
const llvm::fltSemantics & getFloatTypeSemantics(QualType T) const
Return the APFloat 'semantics' for the specified scalar floating point type.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
DeclarationNameTable DeclarationNames
int getIntegerTypeOrder(QualType LHS, QualType RHS) const
Return the highest ranked integer type, see C99 6.3.1.8p1.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getScalableVectorType(QualType EltTy, unsigned NumElts, unsigned NumFields=1) const
Return the unique reference to a scalable vector type of the specified element type and scalable numb...
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getCorrespondingSignedFixedPointType(QualType Ty) const
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getReferenceQualifiedType(const Expr *e) const
getReferenceQualifiedType - Given an expr, will return the type for that expression,...
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
const LangOptions & getLangOpts() const
CanQualType getLogicalOperationType() const
The result type of logical operations, '<', '>', '!=', etc.
const QualType GetHigherPrecisionFPType(QualType ElementType) const
bool typesAreBlockPointerCompatible(QualType, QualType)
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
llvm::SetVector< const VarDecl * > CUDADeviceVarODRUsedByHost
Keep track of CUDA/HIP device-side variables ODR-used by host code.
llvm::SetVector< const ValueDecl * > CUDAExternalDeviceDeclODRUsedByHost
Keep track of CUDA/HIP external kernels or device variables ODR-used by host code.
int getFloatingTypeOrder(QualType LHS, QualType RHS) const
Compare the rank of the two specified floating point types, ignoring the domain of the type (i....
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
QualType getCorrespondingSaturatedType(QualType Ty) const
CanQualType BoundMemberTy
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false, bool BlockReturnType=false, bool IsConditionalOperator=false)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType UnsignedCharTy
FieldDecl * getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) const
QualType getArrayDecayedType(QualType T) const
Return the properly qualified result of decaying the specified array type to a pointer.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
bool hasDirectOwnershipQualifier(QualType Ty) const
Return true if the type has been explicitly qualified with ObjC ownership.
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
const TargetInfo & getTargetInfo() const
QualType getOverflowBehaviorType(const OverflowBehaviorAttr *Attr, QualType Wrapped) const
std::optional< CharUnits > getTypeSizeInCharsIfKnown(QualType Ty) const
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
QualType getCorrespondingUnsignedType(QualType T) const
bool typesAreCompatible(QualType T1, QualType T2, bool CompareUnqualified=false)
Compatibility predicates used to check assignment expressions.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
unsigned getTargetAddressSpace(LangAS AS) const
bool isPromotableIntegerType(QualType T) const
More type predicates useful for type checking/promotion.
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
QualType getCommonSugaredType(QualType X, QualType Y, bool Unqualified=false) const
uint64_t getCharWidth() const
Return the size of the character type, in bits.
AddrLabelExpr - The GNU address of label extension, representing &&label.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
SourceLocation getExprLoc() const LLVM_READONLY
Wrapper for source info for arrays.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
ArraySizeModifier getSizeModifier() const
QualType getElementType() const
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Attr - This represents one attribute.
SourceRange getRange() const
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isRelationalOp(Opcode Opc)
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
static bool isComparisonOp(Opcode Opc)
StringRef getOpcodeStr() const
bool isRelationalOp() const
SourceLocation getOperatorLoc() const
bool isMultiplicativeOp() const
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
bool isAdditiveOp() const
static bool isAssignmentOp(Opcode Opc)
static bool isCompoundAssignmentOp(Opcode Opc)
static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, const Expr *LHS, const Expr *RHS)
Return true if a binary operator using the specified opcode and operands would match the 'p = (i8*)nu...
bool isAssignmentOp() const
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
static bool isEqualityOp(Opcode Opc)
static bool isBitwiseOp(Opcode Opc)
BinaryOperatorKind Opcode
A binding in a decomposition declaration.
A class which contains all the information about a particular captured value.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
void setSignatureAsWritten(TypeSourceInfo *Sig)
void setBlockMissingReturnType(bool val=true)
void setIsVariadic(bool value)
SourceLocation getCaretLocation() const
void setBody(CompoundStmt *B)
ArrayRef< ParmVarDecl * > parameters() const
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
This class is used for builtin types like 'int'.
static CUDAKernelCallExpr * Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
const RecordType * getDetectedVirtual() const
The virtual base discovered on the path (if we are merely detecting virtuals).
Represents a call to a C++ constructor.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Represents a C++ constructor within a class.
Represents a C++ conversion function within a class.
bool isLambdaToBlockPointerConversion() const
Determine whether this conversion function is a conversion from a lambda closure type to a block poin...
Represents a C++ base or member initializer.
A default argument (C++ [dcl.fct.default]).
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
A use of a default initializer in a constructor or in aggregate initialization.
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Expr * getExpr()
Get the initialization expression that will be used.
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
CXXMethodDecl * getDevirtualizedMethod(const Expr *Base, bool IsAppleKext)
If it's possible to devirtualize a call to this method, return the called function.
A call to an overloaded operator written using operator syntax.
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
SourceRange getSourceRange() const
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Represents a C++ struct/union/class.
bool isStandardLayout() const
Determine whether this class is standard-layout per C++ [class]p7.
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
bool isLambda() const
Determine whether this class describes a lambda function object.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
bool hasDefinition() const
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
static CXXReflectExpr * Create(ASTContext &C, SourceLocation OperatorLoc, TypeSourceInfo *TL)
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Represents the this expression in C++.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
void computeDependence()
Compute and set dependence bits.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
QualType withConst() const
Retrieves a version of this type with const applied.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
const char * getCastKindName() const
CharLiteralParser - Perform interpretation and semantic analysis of a character literal.
Represents a byte-granular source range.
static CharSourceRange getCharRange(SourceRange R)
static CharSourceRange getTokenRange(SourceRange R)
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Complex values, per C99 6.2.5p11.
QualType getElementType() const
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
CompoundLiteralExpr - [C99 6.5.2.5].
CompoundStmt - This represents a group of statements like { stmt stmt }.
ConditionalOperator - The ?
Represents the canonical version of C arrays with a specified constant size.
llvm::APInt getSize() const
Return the constant array size as an APInt.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
static ConstantResultStorageKind getStorageKind(const APValue &Value)
void MoveIntoResult(APValue &Value, const ASTContext &Context)
SourceLocation getBeginLoc() const LLVM_READONLY
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
bool isImmediateInvocation() const
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
void setTypoName(const IdentifierInfo *II)
void setTypoNNS(NestedNameSpecifier NNS)
Wrapper for source info for pointers decayed from arrays and functions.
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isRequiresExprBody() const
DeclContextLookupResult lookup_result
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
bool isFunctionOrMethod() const
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context semantically encloses the declaration context DC.
A reference to a declared variable, function, enum, etc.
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
NestedNameSpecifier getQualifier() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
void setDecl(ValueDecl *NewD)
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
DeclarationNameInfo getNameInfo() const
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier,...
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
SourceLocation getBeginLoc() const
SourceLocation getLocation() const
Decl - This represents one declaration (or definition), e.g.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
bool isInvalidDecl() const
SourceLocation getLocation() const
void setReferenced(bool R=true)
DeclContext * getDeclContext()
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
std::string getAsString() const
Retrieve the human-readable string for this name.
@ CXXConversionFunctionName
NameKind getNameKind() const
Determine what kind of name this is.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
TypeSourceInfo * getTypeSourceInfo() const
Information about one declarator, including the parsed type information and the identifier.
DeclaratorContext getContext() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isInvalidType() const
const IdentifierInfo * getIdentifier() const
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
A little helper class used to produce diagnostics.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool getSuppressSystemWarnings() const
bool ShouldVisitImplicitCode
virtual bool VisitStmt(MaybeConst< Stmt > *S)
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
virtual bool TraverseTemplateArgument(const TemplateArgument &Arg)
Represents a reference to emded data.
RAII object that enters a new expression evaluation context.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
ExplicitCastExpr - An explicit cast written in the source code.
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
bool isIntegerConstantExpr(const ASTContext &Ctx) const
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, does not have an incomplet...
@ SE_AllowSideEffects
Allow any unmodeled side effect.
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
llvm::APSInt EvaluateKnownConstIntCheckOverflow(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
bool isValueDependent() const
Determines whether the value of this expression depends on.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreConversionOperatorSingleStep() LLVM_READONLY
Skip conversion operators.
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant().
@ NPCK_ZeroExpression
Expression is a Null pointer constant built from a zero integer expression that is not a simple,...
@ NPCK_ZeroLiteral
Expression is a Null pointer constant built from a literal zero.
@ NPCK_CXX11_nullptr
Expression is a C++11 nullptr.
@ NPCK_NotNull
Expression is not a Null pointer constant.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
QualType getEnumCoercedType(const ASTContext &Ctx) const
If this expression is an enumeration constant, return the enumeration type under which said constant ...
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static bool isSameComparisonOperand(const Expr *E1, const Expr *E2)
Checks that the two Expr's will refer to the same value as a comparison operand.
void setObjectKind(ExprObjectKind Cat)
setObjectKind - Set the object kind produced by this expression.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
@ MLV_DuplicateVectorComponents
@ MLV_InvalidMessageExpression
@ MLV_DuplicateMatrixComponents
@ MLV_ConstQualifiedField
@ MLV_SubObjCPropertySetting
bool isOrdinaryOrBitFieldObject() const
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
ExtVectorType - Extended vector type.
Represents difference between two FPOptions values.
bool isFPConstrained() const
RoundingMode getRoundingMode() const
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
const Expr * getSubExpr() const
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Represents a function declaration or definition.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
const ParmVarDecl * getParamDecl(unsigned i) const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
bool isImmediateFunction() const
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
bool hasCXXExplicitFunctionObjectParameter() const
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool isExternC() const
Determines whether this function is a function with external, C linkage.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool isImmediateEscalating() const
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
size_t param_size() const
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
SourceRange getParametersSourceRange() const
Attempt to compute an informative source range covering the function parameters, including the ellips...
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
Represents a prototype with parameter type info, e.g.
ExtParameterInfo getExtParameterInfo(unsigned I) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
bool isParamConsumed(unsigned I) const
unsigned getNumParams() const
QualType getParamType(unsigned i) const
bool isVariadic() const
Whether this function prototype is variadic.
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > getParamTypes() const
ArrayRef< QualType > param_types() const
Declaration of a template function.
unsigned getNumParams() const
ParmVarDecl * getParam(unsigned i) const
SourceLocation getLocalRangeEnd() const
TypeLoc getReturnLoc() const
SourceLocation getLocalRangeBegin() const
A class which abstracts out some details necessary for making a call.
ExtInfo withNoReturn(bool noReturn) const
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
bool getCFIUncheckedCalleeAttr() const
Determine whether this is a function prototype that includes the cfi_unchecked_callee attribute.
QualType getReturnType() const
bool getCmseNSCallAttr() const
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
One of these records is kept for each identifier that is lexed.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
Describes an entity that is being initialized.
void setParameterCFAudited()
static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc, QualType Type)
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type)
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI)
Create the entity for a compound literal initializer.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Represents the declaration of a label.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
FPEvalMethodKind
Possible float expression evaluation method choices.
@ FEM_Extended
Use extended type for fp arithmetic.
@ FEM_Double
Use the type double for fp arithmetic.
@ FEM_UnsetOnCommandLine
Used only for FE option processing; this is only used to indicate that the user did not specify an ex...
@ FEM_Source
Use the declared type for fp arithmetic.
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
@ None
Permit no implicit vector bitcasts.
@ Integer
Permit vector bitcasts between integer vectors with different numbers of elements but the same total ...
@ All
Permit vector bitcasts between all vectors with the same total bit-width.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
clang::ObjCRuntime ObjCRuntime
bool isSignedOverflowDefined() const
bool allowArrayReturnTypes() const
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static std::string Stringify(StringRef Str, bool Charify=false)
Stringify - Convert the specified string into a C string by i) escaping '\' and " characters and ii) ...
Represents the results of name lookup.
DeclClass * getAsSingle() const
MS property subscript expression.
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0
Retrieve the mangling number of a new lambda expression with the given call operator within this cont...
MatrixSingleSubscriptExpr - Matrix single subscript expression for the MatrixType extension when you ...
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Represents a matrix type, as defined in the Matrix Types clang extensions.
QualType getElementType() const
Returns type of the elements being stored in the matrix.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
bool performsVirtualDispatch(const LangOptions &LO) const
Returns true if virtual dispatch is performed.
SourceLocation getBeginLoc() const LLVM_READONLY
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
std::string getQualifiedNameAsString() const
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isExternallyVisible() const
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Represent a C++ namespace.
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
@ Type
A type, stored as a Type*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber,...
Represents an ObjC class declaration.
bool hasDefinition() const
Determine whether this class has been defined.
ivar_iterator ivar_begin() const
ObjCInterfaceDecl * getSuperClass() const
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getLocation() const
SourceLocation getOpLoc() const
SourceLocation getEndLoc() const LLVM_READONLY
const Expr * getBase() const
An expression that sends a message to the given Objective-C object or class.
const ObjCMethodDecl * getMethodDecl() const
ObjCMethodDecl - Represents an instance or class method declaration.
ImplicitParamDecl * getSelfDecl() const
bool isClassMethod() const
Represents a pointer to an Objective C object.
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
Represents one property declaration in an Objective-C interface.
Represents an Objective-C protocol declaration.
bool allowsSizeofAlignof() const
Does this runtime allow sizeof or alignof on object types?
bool allowsPointerArithmetic() const
Does this runtime allow pointer arithmetic on objects?
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Helper class for OffsetOfExpr.
void * getAsOpaquePtr() const
static OpaquePtr getFromOpaquePtr(void *P)
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
SmallVectorImpl< OverloadCandidate >::iterator iterator
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
ParenExpr - This represents a parenthesized expression, e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
const Expr * getSubExpr() const
bool isProducedByFoldExpansion() const
Expr * getExpr(unsigned Init)
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
unsigned getNumExprs() const
Return the number of expressions in this paren list.
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
Represents a parameter to a function.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
bool isEquivalent(PointerAuthQualifier Other) const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl, bool ForceElaboratedPrinting=false)
bool isMacroDefined(StringRef Id)
IdentifierTable & getIdentifierTable()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
bool isAddressSpaceOverlapping(QualType T, const ASTContext &Ctx) const
Returns true if address space qualifiers overlap with T address space qualifiers.
QualType withConst() const
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isCXX98PODType(const ASTContext &Context) const
Return true if this is a POD type according to the rules of the C++98 standard, regardless of the cur...
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
QualType withCVRQualifiers(unsigned CVR) const
bool isCForbiddenLValueType() const
Determine whether expressions of the given type are forbidden from being lvalues in C.
bool isConstQualified() const
Determine whether this type is const-qualified.
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
void removeCVRQualifiers(unsigned mask)
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const
Determines if these qualifiers compatibly include another set.
static bool isAddressSpaceSupersetOf(LangAS A, LangAS B, const ASTContext &Ctx)
Returns true if address space A is equal to or a superset of B.
void removeAddressSpace()
void setAddressSpace(LangAS space)
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
Qualifiers withoutObjCLifetime() const
Qualifiers withoutObjCGCAttr() const
LangAS getAddressSpace() const
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
Represents a struct/union/class.
bool hasFlexibleArrayMember() const
field_iterator field_end() const
field_range fields() const
static RecoveryExpr * Create(ASTContext &Ctx, QualType T, SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs)
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Base for LValueReferenceType and RValueReferenceType.
Scope - A scope is a transient data structure that is used while parsing the program.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isInCFunctionScope() const
isInObjcMethodScope - Return true if this scope is, or is contained, in an C function body.
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ ControlScope
The controlling scope in a if/switch/while/for statement.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ DeclScope
This is a scope that can contain a declaration.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
bool isUnarySelector() const
Expr * ExpandAMDGPUPredicateBuiltIn(Expr *CE)
Expand a valid use of the feature identification builtins into its corresponding sequence of instruct...
void AddPotentiallyUnguardedBuiltinUser(FunctionDecl *FD)
Diagnose unguarded usages of AMDGPU builtins and recommend guarding with __builtin_amdgcn_is_invocabl...
bool checkSVETypeSupport(QualType Ty, SourceLocation Loc, const FunctionDecl *FD, const llvm::StringMap< bool > &FeatureMap)
A generic diagnostic builder for errors which may or may not be deferred.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
Emit a compatibility diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
void RecordImplicitHostDeviceFuncUsedByDevice(const FunctionDecl *FD)
Record FD if it is a CUDA/HIP implicit host device function used on device side in device compilation...
CUDAFunctionTarget IdentifyTarget(const FunctionDecl *D, bool IgnoreImplicitHDAttr=false)
Determines whether the given function is a CUDA device/host/kernel/etc.
bool CheckCall(SourceLocation Loc, FunctionDecl *Callee)
Check whether we're allowed to call Callee from the current context.
@ CVT_Host
Emitted on device side with a shadow variable on host side.
@ CVT_Both
Emitted on host side only.
ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg)
void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc)
QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
ObjCMethodDecl * LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, bool receiverIdOrClass=false)
LookupInstanceMethodInGlobalPool - Returns the method and warns if there are multiple signatures.
ObjCLiteralKind CheckLiteralKind(Expr *FromE)