66#include "llvm/ADT/STLExtras.h"
67#include "llvm/ADT/StringExtras.h"
68#include "llvm/Support/ConvertUTF.h"
69#include "llvm/Support/SaveAndRestore.h"
70#include "llvm/Support/TimeProfiler.h"
71#include "llvm/Support/TypeSize.h"
96 if (TreatUnavailableAsInvalid &&
114 if (
const auto *A = D->
getAttr<UnusedAttr>()) {
117 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
118 A->getSemanticSpelling() != UnusedAttr::C23_maybe_unused) {
120 if (DC && !DC->
hasAttr<UnusedAttr>())
121 S.
Diag(Loc, diag::warn_used_but_marked_unused) << D;
129 if (
Decl->isDefaulted()) {
140 auto *Ctor = dyn_cast<CXXConstructorDecl>(
Decl);
141 if (Ctor && Ctor->isInheritingConstructor())
152 if (I->getStorageClass() !=
SC_None)
203 DiagID = diag::warn_c2y_compat_internal_in_extern_inline;
204 else if ((UsedFn && (UsedFn->
isInlined() || UsedFn->
hasAttr<ConstAttr>())) ||
206 DiagID = diag::ext_internal_in_extern_inline_quiet;
208 DiagID = diag::ext_internal_in_extern_inline;
210 S.
Diag(Loc, DiagID) << !UsedFn << D;
222 Diag(DeclBegin, diag::note_convert_inline_to_static)
229 bool ObjCPropertyAccess,
230 bool AvoidPartialAvailabilityChecks,
232 bool SkipTrailingRequiresClause) {
239 for (
const auto &[DiagLoc, PD] : Pos->second) {
253 Diag(Loc, diag::ext_main_used);
261 Diag(Loc, diag::err_binding_cannot_appear_in_own_initializer)
264 Diag(Loc, diag::err_auto_variable_cannot_appear_in_own_initializer)
273 if (FD->isDeleted()) {
274 auto *Ctor = dyn_cast<CXXConstructorDecl>(FD);
275 if (Ctor && Ctor->isInheritingConstructor())
276 Diag(Loc, diag::err_deleted_inherited_ctor_use)
278 << Ctor->getInheritedConstructor().getConstructor()->getParent();
281 Diag(Loc, diag::err_deleted_function_use)
282 << (Msg !=
nullptr) << (Msg ? Msg->
getString() : StringRef());
296 if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) {
305 diag::err_reference_to_function_with_unsatisfied_constraints)
323 if (
auto *
Concept = dyn_cast<ConceptDecl>(D);
327 if (
auto *MD = dyn_cast<CXXMethodDecl>(D)) {
329 if (MD->getParent()->isLambda() &&
332 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) {
333 Diag(Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign)
338 auto getReferencedObjCProp = [](
const NamedDecl *D) ->
340 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
341 return MD->findPropertyDecl();
355 auto *DRD = dyn_cast<OMPDeclareReductionDecl>(
CurContext);
358 Diag(Loc, diag::err_omp_wrong_var_in_declare_reduction)
371 Diag(Loc, diag::err_omp_declare_mapper_wrong_var)
377 if (
const auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(D)) {
378 Diag(Loc, diag::err_use_of_empty_using_if_exists);
379 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here);
384 AvoidPartialAvailabilityChecks, ClassReceiver);
390 if (D->
hasAttr<AvailableOnlyInDefaultEvalMethodAttr>()) {
393 PP.getLastFPEvalPragmaLocation().isValid() &&
394 PP.getCurrentFPEvalMethod() !=
getLangOpts().getFPEvalMethod())
396 diag::err_type_available_only_in_default_eval_method)
400 if (
auto *VD = dyn_cast<ValueDecl>(D))
405 if (!
Context.getTargetInfo().isTLSSupported())
406 if (
const auto *VD = dyn_cast<VarDecl>(D))
408 targetDiag(*Locs.begin(), diag::err_thread_unsupported);
419 const SentinelAttr *
Attr = D->
getAttr<SentinelAttr>();
424 unsigned NumFormalParams;
428 enum { CK_Function, CK_Method, CK_Block } CalleeKind;
430 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
431 NumFormalParams = MD->param_size();
432 CalleeKind = CK_Method;
433 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
434 NumFormalParams = FD->param_size();
435 CalleeKind = CK_Function;
436 if (FD->hasCXXExplicitFunctionObjectParameter())
438 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
445 CalleeKind = CK_Function;
448 CalleeKind = CK_Block;
453 if (
const auto *proto = dyn_cast<FunctionProtoType>(Fn))
454 NumFormalParams = proto->getNumParams();
465 unsigned NullPos =
Attr->getNullPos();
466 assert((NullPos == 0 || NullPos == 1) &&
"invalid null position on sentinel");
467 NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - NullPos);
470 unsigned NumArgsAfterSentinel =
Attr->getSentinel();
474 if (Args.size() < NumFormalParams + NumArgsAfterSentinel + 1) {
481 const Expr *SentinelExpr = Args[Args.size() - NumArgsAfterSentinel - 1];
486 if (
Context.isSentinelNullExpr(SentinelExpr))
494 std::string NullValue;
495 if (CalleeKind == CK_Method &&
PP.isMacroDefined(
"nil"))
498 NullValue =
"nullptr";
499 else if (
PP.isMacroDefined(
"NULL"))
502 NullValue =
"(void*) 0";
505 Diag(Loc, diag::warn_missing_sentinel) <<
int(CalleeKind);
507 Diag(MissingNilLoc, diag::warn_missing_sentinel)
532 assert(!Ty.
isNull() &&
"DefaultFunctionArrayConversion - missing type");
536 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
541 CK_FunctionToPointerDecay).
get();
556 CK_ArrayToPointerDecay);
572 if (UO && UO->getOpcode() == UO_Deref &&
573 UO->getSubExpr()->getType()->isPointerType()) {
575 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
578 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
580 !UO->getType().isVolatileQualified()) {
582 S.
PDiag(diag::warn_indirection_through_null)
583 << UO->getSubExpr()->getSourceRange());
585 S.
PDiag(diag::note_indirection_through_null));
605 BaseType = BaseType->getPointeeType();
617 if (ObjectSetClass) {
661 assert(!
T.isNull() &&
"r-value conversion on typeless expression?");
665 if (
T->canDecayToPointerType())
673 (
T->isDependentType() && !
T->isAnyPointerType() &&
674 !
T->isMemberPointerType()))
698 &
Context.Idents.get(
"object_getClass"),
704 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()),
")");
721 if (
T.hasQualifiers())
722 T =
T.getUnqualifiedType();
725 if (
T->isMemberPointerType() &&
726 Context.getTargetInfo().getCXXABI().isMicrosoft())
737 Cleanup.setExprNeedsCleanups(
true);
740 Cleanup.setExprNeedsCleanups(
true);
747 CastKind CK =
T->isNullPtrType() ? CK_NullToPointer : CK_LValueToRValue;
755 T =
Atomic->getValueType().getUnqualifiedType();
780 CK_FunctionToPointerDecay);
794 assert(!Ty.
isNull() &&
"UsualUnaryFPConversions - missing type");
800 PP.getLastFPEvalPragmaLocation().isValid())) {
801 switch (EvalMethod) {
803 llvm_unreachable(
"Unrecognized float evaluation method");
806 llvm_unreachable(
"Float evaluation method should be set by now");
814 CK_FloatingComplexCast)
823 CK_FloatingComplexCast)
855 assert(!Ty.
isNull() &&
"UsualUnaryConversions - missing type");
879 if (
Context.isPromotableIntegerType(Ty)) {
894 assert(!Ty.
isNull() &&
"DefaultArgumentPromotion - missing type");
906 if (BTy && (BTy->
getKind() == BuiltinType::Half ||
907 BTy->
getKind() == BuiltinType::Float)) {
910 if (BTy->
getKind() == BuiltinType::Half) {
921 Context.getTypeSizeInChars(BTy) <
927 assert(8 ==
Context.getTypeSizeInChars(
Context.LongLongTy).getQuantity() &&
928 "Unexpected typesize for LongLongTy");
982 if (
Context.getTargetInfo().getTriple().isWasm() &&
997 if (!
Record->hasNonTrivialCopyConstructor() &&
998 !
Record->hasNonTrivialMoveConstructor() &&
999 !
Record->hasNonTrivialDestructor())
1032 PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
1039 PDiag(diag::warn_pass_class_arg_to_vararg)
1047 PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
1054 diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
1058 PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
1071 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast &&
1073 (FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>()))) {
1112 if (
Call.isInvalid())
1117 if (Comma.isInvalid())
1124 diag::err_call_incomplete_argument))
1142 if (SkipCast)
return false;
1149 CK_IntegralComplexToFloatingComplex);
1167 bool PromotePrecision) {
1172 if (PromotePrecision) {
1177 if (LongerIsComplex)
1189 QualType RHSType,
bool IsCompAssign) {
1214 bool ConvertFloat,
bool ConvertInt) {
1219 CK_IntegralToFloating);
1230 CK_IntegralComplexToFloatingComplex);
1235 CK_FloatingRealToComplex);
1244 QualType RHSType,
bool IsCompAssign) {
1254 else if (!IsCompAssign)
1256 return LHSFloat ? LHSType : RHSType;
1261 if (LHSFloat && RHSFloat) {
1268 assert(order < 0 &&
"illegal float comparison");
1302 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType;
1308 if ((&LHSSem != &llvm::APFloat::PPCDoubleDouble() ||
1309 &RHSSem != &llvm::APFloat::IEEEquad()) &&
1310 (&LHSSem != &llvm::APFloat::IEEEquad() ||
1311 &RHSSem != &llvm::APFloat::PPCDoubleDouble()))
1328 CK_IntegralComplexCast);
1334template <PerformCastFn doLHSCast, PerformCastFn doRHSCast>
1337 QualType RHSType,
bool IsCompAssign) {
1342 if (LHSSigned == RHSSigned) {
1345 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1347 }
else if (!IsCompAssign)
1348 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1350 }
else if (order != (LHSSigned ? 1 : -1)) {
1354 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1356 }
else if (!IsCompAssign)
1357 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1364 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1366 }
else if (!IsCompAssign)
1367 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1376 RHS = (*doRHSCast)(S, RHS.
get(), result);
1378 LHS = (*doLHSCast)(S, LHS.
get(), result);
1388 bool IsCompAssign) {
1392 if (LHSComplexInt && RHSComplexInt) {
1397 (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign);
1402 if (LHSComplexInt) {
1406 (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign);
1409 CK_IntegralRealToComplex);
1414 assert(RHSComplexInt);
1419 (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign);
1424 CK_IntegralRealToComplex);
1432 bool IsCompAssign) {
1434 const auto *LhsOBT = LHSType->
getAs<OverflowBehaviorType>();
1435 const auto *RhsOBT = RHSType->
getAs<OverflowBehaviorType>();
1438 "Non-integer type conversion not supported for OverflowBehaviorTypes");
1441 LhsOBT && LhsOBT->getBehaviorKind() ==
1442 OverflowBehaviorType::OverflowBehaviorKind::Trap;
1444 RhsOBT && RhsOBT->getBehaviorKind() ==
1445 OverflowBehaviorType::OverflowBehaviorKind::Trap;
1447 LhsOBT && LhsOBT->getBehaviorKind() ==
1448 OverflowBehaviorType::OverflowBehaviorKind::Wrap;
1450 RhsOBT && RhsOBT->getBehaviorKind() ==
1451 OverflowBehaviorType::OverflowBehaviorKind::Wrap;
1453 QualType LHSUnderlyingType = LhsOBT ? LhsOBT->getUnderlyingType() : LHSType;
1454 QualType RHSUnderlyingType = RhsOBT ? RhsOBT->getUnderlyingType() : RHSType;
1456 std::optional<OverflowBehaviorType::OverflowBehaviorKind> DominantBehavior;
1457 if (LHSHasTrap || RHSHasTrap)
1458 DominantBehavior = OverflowBehaviorType::OverflowBehaviorKind::Trap;
1459 else if (LHSHasWrap || RHSHasWrap)
1460 DominantBehavior = OverflowBehaviorType::OverflowBehaviorKind::Wrap;
1462 QualType LHSConvType = LHSUnderlyingType;
1463 QualType RHSConvType = RHSUnderlyingType;
1464 if (DominantBehavior) {
1465 if (!LhsOBT || LhsOBT->getBehaviorKind() != *DominantBehavior)
1469 LHSConvType = LHSType;
1471 if (!RhsOBT || RhsOBT->getBehaviorKind() != *DominantBehavior)
1475 RHSConvType = RHSType;
1479 S, LHS, RHS, LHSConvType, RHSConvType, IsCompAssign);
1487 assert(BTy &&
"Expected a builtin type.");
1489 switch (BTy->getKind()) {
1490 case BuiltinType::ShortFract:
1491 case BuiltinType::UShortFract:
1492 case BuiltinType::SatShortFract:
1493 case BuiltinType::SatUShortFract:
1495 case BuiltinType::Fract:
1496 case BuiltinType::UFract:
1497 case BuiltinType::SatFract:
1498 case BuiltinType::SatUFract:
1500 case BuiltinType::LongFract:
1501 case BuiltinType::ULongFract:
1502 case BuiltinType::SatLongFract:
1503 case BuiltinType::SatULongFract:
1505 case BuiltinType::ShortAccum:
1506 case BuiltinType::UShortAccum:
1507 case BuiltinType::SatShortAccum:
1508 case BuiltinType::SatUShortAccum:
1510 case BuiltinType::Accum:
1511 case BuiltinType::UAccum:
1512 case BuiltinType::SatAccum:
1513 case BuiltinType::SatUAccum:
1515 case BuiltinType::LongAccum:
1516 case BuiltinType::ULongAccum:
1517 case BuiltinType::SatLongAccum:
1518 case BuiltinType::SatULongAccum:
1521 if (BTy->isInteger())
1523 llvm_unreachable(
"Unexpected fixed point or integer type");
1535 "Expected at least one of the operands to be a fixed point type");
1538 "Special fixed point arithmetic operation conversions are only "
1539 "applied to ints or other fixed point types");
1561 QualType ResultTy = LHSTyRank > RHSTyRank ? LHSTy : RHSTy;
1584 REnum = R->isUnscopedEnumerationType();
1586 if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
1590 ? diag::warn_arith_conv_enum_float_cxx20
1591 : diag::warn_arith_conv_enum_float)
1594 }
else if (!IsCompAssign && LEnum && REnum &&
1595 !
Context.hasSameUnqualifiedType(L, R)) {
1600 DiagID = diag::warn_conv_mixed_enum_types_cxx26;
1601 else if (!L->
castAsCanonical<EnumType>()->getDecl()->hasNameForLinkage() ||
1602 !R->castAsCanonical<EnumType>()->getDecl()->hasNameForLinkage()) {
1607 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
1608 : diag::warn_arith_conv_mixed_anon_enum_types;
1613 ? diag::warn_conditional_mixed_enum_types_cxx20
1614 : diag::warn_conditional_mixed_enum_types;
1619 ? diag::warn_comparison_mixed_enum_types_cxx20
1620 : diag::warn_comparison_mixed_enum_types;
1623 ? diag::warn_arith_conv_mixed_enum_types_cxx20
1624 : diag::warn_arith_conv_mixed_enum_types;
1627 << (int)ACK << L << R;
1645 auto IsSingleCodeUnitCP = [](
const QualType &
T,
const llvm::APSInt &
Value) {
1646 if (
T->isChar8Type())
1647 return llvm::IsSingleCodeUnitUTF8Codepoint(
Value.getExtValue());
1648 if (
T->isChar16Type())
1649 return llvm::IsSingleCodeUnitUTF16Codepoint(
Value.getExtValue());
1650 assert(
T->isChar32Type());
1651 return llvm::IsSingleCodeUnitUTF32Codepoint(
Value.getExtValue());
1664 if (LHSSuccess != RHSuccess) {
1666 if (IsSingleCodeUnitCP(LHSType, Res.
Val.
getInt()) &&
1667 IsSingleCodeUnitCP(RHSType, Res.
Val.
getInt()))
1671 if (!LHSSuccess || !RHSuccess) {
1672 SemaRef.
Diag(Loc, diag::warn_comparison_unicode_mixed_types)
1678 llvm::APSInt LHSValue(32);
1680 llvm::APSInt RHSValue(32);
1683 bool LHSSafe = IsSingleCodeUnitCP(LHSType, LHSValue);
1684 bool RHSSafe = IsSingleCodeUnitCP(RHSType, RHSValue);
1685 if (LHSSafe && RHSSafe)
1688 SemaRef.
Diag(Loc, diag::warn_comparison_unicode_mixed_types_constant)
1698 SemaRef.
Diag(Loc, diag::warn_arith_conv_mixed_unicode_types)
1732 LHSType = AtomicLHS->getValueType();
1735 if (
Context.hasSameType(LHSType, RHSType))
1736 return Context.getCommonSugaredType(LHSType, RHSType);
1744 QualType LHSUnpromotedType = LHSType;
1745 if (
Context.isPromotableIntegerType(LHSType))
1746 LHSType =
Context.getPromotedIntegerType(LHSType);
1748 if (!LHSBitfieldPromoteTy.
isNull())
1749 LHSType = LHSBitfieldPromoteTy;
1754 if (
Context.hasSameType(LHSType, RHSType))
1755 return Context.getCommonSugaredType(LHSType, RHSType);
1802 bool PredicateIsExpr,
void *ControllingExprOrType,
1804 unsigned NumAssocs = ArgTypes.size();
1805 assert(NumAssocs == ArgExprs.size());
1808 for (
unsigned i = 0; i < NumAssocs; ++i) {
1817 if (!PredicateIsExpr) {
1821 assert(ControllingType &&
"couldn't get the type out of the parser");
1822 ControllingExprOrType = ControllingType;
1826 KeyLoc, DefaultLoc, RParenLoc, PredicateIsExpr, ControllingExprOrType,
1838 const auto *TOBT =
T->getAs<OverflowBehaviorType>();
1839 const auto *UOBT =
U.getCanonicalType()->getAs<OverflowBehaviorType>();
1843 if (TOBT->getBehaviorKind() == UOBT->getBehaviorKind())
1845 UOBT->getUnderlyingType());
1857 bool PredicateIsExpr,
void *ControllingExprOrType,
1859 unsigned NumAssocs = Types.size();
1860 assert(NumAssocs == Exprs.size());
1861 assert(ControllingExprOrType &&
1862 "Must have either a controlling expression or a controlling type");
1864 Expr *ControllingExpr =
nullptr;
1866 if (PredicateIsExpr) {
1873 reinterpret_cast<Expr *
>(ControllingExprOrType));
1876 ControllingExpr = R.get();
1879 ControllingType =
reinterpret_cast<TypeSourceInfo *
>(ControllingExprOrType);
1880 if (!ControllingType)
1884 bool TypeErrorFound =
false,
1885 IsResultDependent = ControllingExpr
1888 ContainsUnexpandedParameterPack =
1898 diag::warn_side_effects_unevaluated_context);
1900 for (
unsigned i = 0; i < NumAssocs; ++i) {
1901 if (Exprs[i]->containsUnexpandedParameterPack())
1902 ContainsUnexpandedParameterPack =
true;
1905 if (Types[i]->
getType()->containsUnexpandedParameterPack())
1906 ContainsUnexpandedParameterPack =
true;
1908 if (Types[i]->
getType()->isDependentType()) {
1909 IsResultDependent =
true;
1926 if (ControllingExpr && Types[i]->
getType()->isIncompleteType())
1927 D =
LangOpts.C2y ? diag::compat_c2y_assoc_type_incomplete
1928 : diag::compat_pre_c2y_assoc_type_incomplete;
1929 else if (ControllingExpr && !Types[i]->
getType()->isObjectType())
1930 D = diag::err_assoc_type_nonobject;
1931 else if (Types[i]->
getType()->isVariablyModifiedType())
1932 D = diag::err_assoc_type_variably_modified;
1933 else if (ControllingExpr) {
1952 unsigned Reason = 0;
1961 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1962 diag::warn_unreachable_association)
1963 << QT << (Reason - 1);
1967 Diag(Types[i]->getTypeLoc().getBeginLoc(), D)
1968 << Types[i]->getTypeLoc().getSourceRange() << Types[i]->getType();
1970 D, Types[i]->getTypeLoc().getBeginLoc()) >=
1972 TypeErrorFound =
true;
1977 for (
unsigned j = i+1; j < NumAssocs; ++j)
1978 if (Types[j] && !Types[j]->
getType()->isDependentType() &&
1981 Diag(Types[j]->getTypeLoc().getBeginLoc(),
1982 diag::err_assoc_compatible_types)
1983 << Types[j]->getTypeLoc().getSourceRange()
1984 << Types[j]->getType()
1985 << Types[i]->getType();
1986 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1987 diag::note_compat_assoc)
1988 << Types[i]->getTypeLoc().getSourceRange()
1989 << Types[i]->getType();
1990 TypeErrorFound =
true;
2000 if (IsResultDependent) {
2001 if (ControllingExpr)
2003 Types, Exprs, DefaultLoc, RParenLoc,
2004 ContainsUnexpandedParameterPack);
2006 Exprs, DefaultLoc, RParenLoc,
2007 ContainsUnexpandedParameterPack);
2011 unsigned DefaultIndex = std::numeric_limits<unsigned>::max();
2015 for (
unsigned i = 0; i < NumAssocs; ++i) {
2023 QualType AssocQT = Types[i]->getType();
2029 CompatIndices.push_back(i);
2033 auto GetControllingRangeAndType = [](
Expr *ControllingExpr,
2037 if (ControllingExpr)
2046 return std::make_pair(SR, QT);
2052 if (CompatIndices.size() > 1) {
2053 auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
2056 << SR << P.second << (
unsigned)CompatIndices.size();
2057 for (
unsigned I : CompatIndices) {
2058 Diag(Types[I]->getTypeLoc().getBeginLoc(),
2059 diag::note_compat_assoc)
2060 << Types[I]->getTypeLoc().getSourceRange()
2061 << Types[I]->getType();
2069 if (DefaultIndex == std::numeric_limits<unsigned>::max() &&
2070 CompatIndices.size() == 0) {
2071 auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
2073 Diag(SR.
getBegin(), diag::err_generic_sel_no_match) << SR << P.second;
2082 unsigned ResultIndex =
2083 CompatIndices.size() ? CompatIndices[0] : DefaultIndex;
2085 if (ControllingExpr) {
2087 Context, KeyLoc, ControllingExpr, Types, Exprs, DefaultLoc, RParenLoc,
2088 ContainsUnexpandedParameterPack, ResultIndex);
2091 Context, KeyLoc, ControllingType, Types, Exprs, DefaultLoc, RParenLoc,
2092 ContainsUnexpandedParameterPack, ResultIndex);
2098 llvm_unreachable(
"unexpected TokenKind");
2099 case tok::kw___func__:
2101 case tok::kw___FUNCTION__:
2103 case tok::kw___FUNCDNAME__:
2105 case tok::kw___FUNCSIG__:
2107 case tok::kw_L__FUNCTION__:
2109 case tok::kw_L__FUNCSIG__:
2111 case tok::kw___PRETTY_FUNCTION__:
2122 auto tryAdjustLambdaContext = [&S, &LSI](
DeclContext *&DC) {
2128 assert(LSI != E &&
"Should be in a lambda scope info");
2129 if (dyn_cast<LambdaScopeInfo>(*LSI)->BeforeCompoundStatement)
2135 tryAdjustLambdaContext(DC);
2139 tryAdjustLambdaContext(DC);
2142 return cast_or_null<Decl>(DC);
2160 assert(Args.size() <= 2 &&
"too many arguments for literal operator");
2163 for (
unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
2164 ArgTy[ArgIdx] = Args[ArgIdx]->getType();
2165 if (ArgTy[ArgIdx]->isArrayType())
2186 std::vector<Token> ExpandedToks;
2192 if (Literal.hadError)
2196 for (
const Token &
Tok : StringToks)
2197 StringTokLocs.push_back(
Tok.getLocation());
2201 false, {}, StringTokLocs);
2203 if (!Literal.getUDSuffix().empty()) {
2206 Literal.getUDSuffixOffset());
2207 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
2227 CurrentDecl =
Context.getTranslationUnitDecl();
2229 std::vector<Token> ExpandedToks;
2230 ExpandedToks.reserve(Toks.size());
2234 ExpandedToks.emplace_back(
Tok);
2238 Diag(
Tok.getLocation(), diag::ext_predef_outside_function);
2240 Diag(
Tok.getLocation(), diag::ext_string_literal_from_predefined)
2243 llvm::raw_svector_ostream
OS(Str);
2244 Token &Exp = ExpandedToks.emplace_back();
2246 if (
Tok.getKind() == tok::kw_L__FUNCTION__ ||
2247 Tok.getKind() == tok::kw_L__FUNCSIG__) {
2249 Exp.
setKind(tok::wide_string_literal);
2251 Exp.
setKind(tok::string_literal);
2257 PP.CreateString(
OS.str(), Exp,
Tok.getLocation(),
Tok.getEndLoc());
2259 return ExpandedToks;
2264 assert(!StringToks.empty() &&
"Must have at least one string!");
2267 std::vector<Token> ExpandedToks;
2273 if (Literal.hadError)
2277 for (
const Token &
Tok : StringToks)
2278 StringTokLocs.push_back(
Tok.getLocation());
2282 if (Literal.isWide()) {
2283 CharTy =
Context.getWideCharType();
2285 }
else if (Literal.isUTF8()) {
2289 CharTy =
Context.UnsignedCharTy;
2291 }
else if (Literal.isUTF16()) {
2294 }
else if (Literal.isUTF32()) {
2297 }
else if (Literal.isPascal()) {
2298 CharTy =
Context.UnsignedCharTy;
2310 ? diag::warn_cxx20_compat_utf8_string
2311 : diag::warn_c23_compat_utf8_string);
2317 auto RemovalDiag =
PDiag(diag::note_cxx20_c23_compat_utf8_string_remove_u8);
2319 for (
const Token &
Tok : StringToks) {
2320 if (
Tok.getKind() == tok::utf8_string_literal) {
2322 RemovalDiagLoc =
Tok.getLocation();
2329 Diag(RemovalDiagLoc, RemovalDiag);
2333 Context.getStringLiteralArrayType(CharTy, Literal.GetNumStringChars());
2337 Context, Literal.GetString(), Kind, Literal.Pascal, StrTy, StringTokLocs);
2338 if (Literal.getUDSuffix().empty())
2345 Literal.getUDSuffixOffset());
2349 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
2356 Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix);
2361 Context.getArrayDecayedType(StrTy), SizeType
2371 llvm::APInt Len(
Context.getIntWidth(SizeType), Literal.GetNumStringChars());
2374 Expr *Args[] = { Lit, LenArg };
2391 unsigned CharBits =
Context.getIntWidth(CharTy);
2393 llvm::APSInt
Value(CharBits, CharIsUnsigned);
2400 for (
unsigned I = 0, N = Lit->
getLength(); I != N; ++I) {
2410 llvm_unreachable(
"unexpected literal operator lookup result");
2414 llvm_unreachable(
"unexpected literal operator lookup result");
2446 auto *DRE = dyn_cast<DeclRefExpr>(VD->
getInit());
2449 auto *Referee = dyn_cast<VarDecl>(DRE->getDecl());
2450 if (!Referee || !Referee->hasGlobalStorage() ||
2451 Referee->hasAttr<CUDADeviceAttr>())
2457 auto *MD = dyn_cast_or_null<CXXMethodDecl>(S.
CurContext);
2458 if (MD && MD->getParent()->isLambda() &&
2459 MD->getOverloadedOperator() == OO_Call && MD->hasAttr<CUDADeviceAttr>() &&
2481 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2482 if (VD->getType()->isReferenceType() &&
2485 VD->isUsableInConstantExpressions(
Context))
2504 Context, NNS, TemplateKWLoc, D, RefersToCapturedVariable, NameInfo, Ty,
2532 const auto *FD = dyn_cast<FieldDecl>(D);
2533 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(D))
2534 FD = IFD->getAnonField();
2538 if (FD->isBitField())
2544 if (
const auto *BD = dyn_cast<BindingDecl>(D))
2545 if (
const auto *BE = BD->getBinding())
2566 NameInfo =
Context.getNameForTemplate(TName, TNameLoc);
2567 TemplateArgs = &Buffer;
2570 TemplateArgs =
nullptr;
2578 bool isDefaultArgument =
2582 const auto *CurMethod = dyn_cast<CXXMethodDecl>(
CurContext);
2583 bool isInstance = CurMethod && CurMethod->isInstance() &&
2584 R.getNamingClass() == CurMethod->getParent() &&
2592 unsigned DiagID = diag::err_found_in_dependent_base;
2593 unsigned NoteID = diag::note_member_declared_at;
2594 if (R.getRepresentativeDecl()->getDeclContext()->Equals(R.getNamingClass())) {
2595 DiagID =
getLangOpts().MSVCCompat ? diag::ext_found_later_in_class
2596 : diag::err_found_later_in_class;
2598 DiagID = diag::ext_found_in_dependent_base;
2599 NoteID = diag::note_dependent_member_use;
2604 Diag(R.getNameLoc(), DiagID)
2605 << R.getLookupName()
2611 Diag(R.getNameLoc(), DiagID) << R.getLookupName();
2615 Diag(D->getLocation(), NoteID);
2624 if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) {
2625 Diag(R.getNameLoc(), diag::err_member_call_without_object) << 0;
2638 SourceRange NameRange = R.getLookupNameInfo().getSourceRange();
2640 unsigned diagnostic = diag::err_undeclared_var_use;
2641 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
2645 diagnostic = diag::err_undeclared_use;
2646 diagnostic_suggest = diag::err_undeclared_use_suggest;
2657 if (ExplicitTemplateArgs) {
2669 R.suppressDiagnostics();
2680 R.addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
2695 if (S && (Corrected =
2696 CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, &SS,
2699 bool DroppedSpecifier =
2703 bool AcceptableWithRecovery =
false;
2704 bool AcceptableWithoutRecovery =
false;
2713 dyn_cast<FunctionTemplateDecl>(CD))
2717 else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(CD))
2718 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->
size() == 0)
2724 ND = Best->FoundDecl;
2725 Corrected.setCorrectionDecl(ND);
2729 Corrected.setCorrectionDecl(ND);
2740 R.setNamingClass(
Record);
2757 AcceptableWithoutRecovery =
true;
2760 if (AcceptableWithRecovery || AcceptableWithoutRecovery) {
2762 ? diag::note_implicit_param_decl
2763 : diag::note_previous_decl;
2766 PDiag(NoteID), AcceptableWithRecovery);
2769 PDiag(diag::err_no_member_suggest)
2771 << DroppedSpecifier << NameRange,
2772 PDiag(NoteID), AcceptableWithRecovery);
2782 return !AcceptableWithRecovery;
2790 Diag(R.getNameLoc(), diag::err_no_member)
2796 Diag(R.getNameLoc(), diagnostic) << Name << NameRange;
2817 else if (
auto *MD = dyn_cast<CXXMethodDecl>(S.
CurContext))
2825 auto DB = S.
Diag(Loc, diag::ext_undeclared_unqual_id_with_dependent_base);
2826 DB << NameInfo.
getName() << RD;
2828 if (!ThisType.
isNull()) {
2831 Context,
nullptr, ThisType,
true,
2833 nullptr, NameInfo, TemplateArgs);
2849 bool IsAddressOfOperand,
2851 bool IsInlineAsmIdentifier) {
2852 assert(!(IsAddressOfOperand && HasTrailingLParen) &&
2853 "cannot be direct & operand and have a trailing lparen");
2882 if (
auto *VD = dyn_cast<ValueDecl>(R.getFoundDecl())) {
2896 if (TemplateKWLoc.
isValid() || TemplateArgs) {
2904 false, TemplateKWLoc,
2908 if (R.wasNotFoundInCurrentInstantiation() || SS.
isInvalid())
2910 IsAddressOfOperand, TemplateArgs);
2914 !IvarLookupFollowUp);
2918 if (R.wasNotFoundInCurrentInstantiation() || SS.
isInvalid())
2920 IsAddressOfOperand, TemplateArgs);
2924 if (IvarLookupFollowUp) {
2934 if (R.isAmbiguous())
2939 if (R.empty() && HasTrailingLParen && II &&
2942 if (D) R.addDecl(D);
2949 if (R.empty() && !ADL) {
2952 TemplateKWLoc, TemplateArgs))
2957 if (IsInlineAsmIdentifier)
2965 "Typo correction callback misconfigured");
2979 assert(!R.empty() &&
2980 "DiagnoseEmptyLookup returned false but added no results");
2987 ExprResult E(
ObjC().LookupInObjCMethod(R, S, Ivar->getIdentifier()));
2997 assert(!R.empty() || ADL);
3027 if (TemplateArgs || TemplateKWLoc.
isValid()) {
3036 "There should only be one declaration found.");
3051 if (R.isAmbiguous())
3054 if (R.wasNotFoundInCurrentInstantiation() || SS.
isInvalid())
3064 if (
const auto *CD = dyn_cast<CXXRecordDecl>(DC))
3065 if (CD->isInvalidDecl() || CD->isBeingDefined())
3075 if (
auto *TagD = dyn_cast<TagDecl>(TD)) {
3082 TL.setNameLoc(NameInfo.
getLoc());
3083 }
else if (
auto *TypedefD = dyn_cast<TypedefNameDecl>(TD)) {
3091 ET =
SemaRef.Context.getTypeDeclType(TD);
3099 unsigned DiagID = diag::err_typename_missing;
3101 DiagID = diag::ext_typename_missing;
3103 auto D =
Diag(Loc, DiagID);
3134 const auto *RD = dyn_cast<CXXRecordDecl>(
Member->getDeclContext());
3142 bool PointerConversions =
false;
3144 DestRecordType =
Context.getCanonicalTagType(RD);
3146 DestRecordType =
Context.getAddrSpaceQualType(
3147 DestRecordType, FromPtrType
3152 DestType =
Context.getPointerType(DestRecordType);
3154 PointerConversions =
true;
3156 DestType = DestRecordType;
3157 FromRecordType = FromType;
3159 }
else if (
const auto *
Method = dyn_cast<CXXMethodDecl>(
Member)) {
3160 if (!
Method->isImplicitObjectMemberFunction())
3163 DestType =
Method->getThisType().getNonReferenceType();
3164 DestRecordType =
Method->getFunctionObjectParameterType();
3168 PointerConversions =
true;
3170 FromRecordType = FromType;
3171 DestType = DestRecordType;
3176 if (FromAS != DestAS) {
3178 Context.removeAddrSpaceQualType(FromRecordType);
3180 Context.getAddrSpaceQualType(FromRecordTypeWithoutAS, DestAS);
3181 if (PointerConversions)
3182 FromTypeWithDestAS =
Context.getPointerType(FromTypeWithDestAS);
3196 if (
Context.hasSameUnqualifiedType(FromRecordType, DestRecordType))
3224 assert(QType->
isRecordType() &&
"lookup done with non-record type");
3234 FromLoc, FromRange, &BasePath))
3237 if (PointerConversions)
3238 QType =
Context.getPointerType(QType);
3240 VK, &BasePath).
get();
3243 FromRecordType = QRecordType;
3247 if (
Context.hasSameUnqualifiedType(FromRecordType, DestRecordType))
3254 FromLoc, FromRange, &BasePath,
3263 DestType =
Context.getQualifiedType(DestType, FromTypeQuals);
3271 bool HasTrailingLParen) {
3273 if (!HasTrailingLParen)
3291 if (D->isCXXClassMember())
3302 else if (D->getLexicalDeclContext()->isFunctionOrMethod())
3309 if (
const auto *FDecl = dyn_cast<FunctionDecl>(D)) {
3311 if (FDecl->getBuiltinID() && FDecl->isImplicit())
3326 bool AcceptInvalid) {
3351 assert(R.isSingleResult() &&
"Expected only a single result");
3352 const auto *FD = dyn_cast<FunctionDecl>(R.getFoundDecl());
3354 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion());
3359 bool AcceptInvalidDecl) {
3362 if (!NeedsADL && R.isSingleResult() &&
3366 R.getRepresentativeDecl(),
nullptr,
3380 R.suppressDiagnostics();
3384 R.getLookupNameInfo(), NeedsADL, R.begin(), R.end(),
3393 bool AcceptInvalidDecl) {
3394 assert(D &&
"Cannot refer to a NULL declaration");
3396 "Cannot refer unambiguously to a function template");
3415 Diag(Loc, diag::err_ref_non_value) << D << SS.
getRange();
3430 if (VD->isInvalidDecl() && !AcceptInvalidDecl)
3436 if (
auto *IndirectField = dyn_cast<IndirectFieldDecl>(VD);
3437 IndirectField && !IndirectField->isCXXClassMember())
3449 type =
type.getNonPackExpansionType();
3453#define ABSTRACT_DECL(kind)
3454#define VALUE(type, base)
3455#define DECL(type, base) case Decl::type:
3456#include "clang/AST/DeclNodes.inc"
3457 llvm_unreachable(
"invalid value decl kind");
3460 case Decl::ObjCAtDefsField:
3461 llvm_unreachable(
"forming non-member reference to ivar?");
3465 case Decl::EnumConstant:
3466 case Decl::UnresolvedUsingValue:
3467 case Decl::OMPDeclareReduction:
3468 case Decl::OMPDeclareMapper:
3477 case Decl::IndirectField:
3478 case Decl::ObjCIvar:
3480 "building reference to field in C?");
3490 case Decl::NonTypeTemplateParm: {
3492 type = reftype->getPointeeType();
3502 if (
type->isRecordType()) {
3503 type =
type.getUnqualifiedType().withConst();
3516 case Decl::VarTemplateSpecialization:
3517 case Decl::VarTemplatePartialSpecialization:
3518 case Decl::Decomposition:
3520 case Decl::OMPCapturedExpr:
3523 type->isVoidType()) {
3529 case Decl::ImplicitParam:
3530 case Decl::ParmVar: {
3540 if (!CapturedType.
isNull())
3541 type = CapturedType;
3546 case Decl::Function: {
3548 if (!
Context.BuiltinInfo.isDirectlyAddressable(BID)) {
3585 case Decl::CXXDeductionGuide:
3586 llvm_unreachable(
"building reference to deduction guide");
3588 case Decl::MSProperty:
3590 case Decl::TemplateParamObject:
3596 case Decl::UnnamedGlobalConstant:
3600 case Decl::CXXMethod:
3605 dyn_cast<FunctionProtoType>(VD->getType()))
3606 if (proto->getReturnType() ==
Context.UnknownAnyTy) {
3619 case Decl::CXXConversion:
3620 case Decl::CXXDestructor:
3621 case Decl::CXXConstructor:
3633 if (VD->isInvalidDecl() && E)
3640 Target.resize(CharByteWidth * (Source.size() + 1));
3641 char *ResultPtr = &
Target[0];
3642 const llvm::UTF8 *ErrorPtr;
3644 llvm::ConvertUTF8toWide(CharByteWidth, Source, ResultPtr, ErrorPtr);
3654 Diag(Loc, diag::ext_predef_outside_function);
3655 currentDecl =
Context.getTranslationUnitDecl();
3665 bool ForceElaboratedPrinting =
3669 unsigned Length = Str.length();
3671 llvm::APInt LengthI(32, Length + 1);
3675 Context.adjustStringLiteralBaseType(
Context.WideCharTy.withConst());
3679 ResTy =
Context.getConstantArrayType(ResTy, LengthI,
nullptr,
3685 ResTy =
Context.adjustStringLiteralBaseType(
Context.CharTy.withConst());
3686 ResTy =
Context.getConstantArrayType(ResTy, LengthI,
nullptr,
3705 StringRef ThisTok =
PP.getSpelling(
Tok, CharBuffer, &
Invalid);
3711 if (Literal.hadError())
3715 if (Literal.isWide())
3721 else if (Literal.isUTF16())
3723 else if (Literal.isUTF32())
3732 if (Literal.isWide())
3734 else if (Literal.isUTF16())
3736 else if (Literal.isUTF32())
3738 else if (Literal.isUTF8())
3744 if (Literal.getUDSuffix().empty())
3754 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_character_udl));
3759 Lit,
Tok.getLocation());
3763 unsigned IntSize =
Context.getTargetInfo().getIntWidth();
3765 llvm::APInt(IntSize, Val,
true),
3787 using llvm::APFloat;
3788 APFloat Val(Format);
3791 if (RM == llvm::RoundingMode::Dynamic)
3792 RM = llvm::RoundingMode::NearestTiesToEven;
3793 APFloat::opStatus result = Literal.GetFloatValue(Val, RM);
3797 if ((result & APFloat::opOverflow) ||
3798 ((result & APFloat::opUnderflow) && Val.isZero())) {
3799 unsigned diagnostic;
3801 if (result & APFloat::opOverflow) {
3802 diagnostic = diag::warn_float_overflow;
3803 APFloat::getLargest(Format).toString(buffer);
3805 diagnostic = diag::warn_float_underflow;
3806 APFloat::getSmallest(Format).toString(buffer);
3809 S.
Diag(Loc, diagnostic) << Ty << buffer.str();
3812 bool isExact = (result == APFloat::opOK);
3817 assert(E &&
"Invalid expression");
3824 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT;
3828 llvm::APSInt ValueAPS;
3839 bool ValueIsPositive =
3840 AllowZero ? ValueAPS.isNonNegative() : ValueAPS.isStrictlyPositive();
3841 if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
3843 <<
toString(ValueAPS, 10) << ValueIsPositive;
3853 if (
Tok.getLength() == 1 ||
Tok.getKind() == tok::binary_data) {
3854 const uint8_t Val =
PP.getSpellingOfSingleCharacterNumericConstant(
Tok);
3863 SpellingBuffer.resize(
Tok.getLength() + 1);
3867 StringRef TokSpelling =
PP.getSpelling(
Tok, SpellingBuffer, &
Invalid);
3872 PP.getSourceManager(),
PP.getLangOpts(),
3873 PP.getTargetInfo(),
PP.getDiagnostics());
3874 if (Literal.hadError)
3877 if (Literal.hasUDSuffix()) {
3885 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_numeric_udl));
3888 if (Literal.isFloatingLiteral()) {
3892 CookedTy =
Context.LongDoubleTy;
3897 CookedTy =
Context.UnsignedLongLongTy;
3901 Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix);
3913 !Literal.isImaginary)) {
3922 if (Literal.isFloatingLiteral()) {
3925 llvm::APInt ResultVal(
Context.getTargetInfo().getLongLongWidth(), 0);
3926 if (Literal.GetIntegerValue(ResultVal))
3927 Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
3939 unsigned Length = Literal.getUDSuffixOffset();
3946 false, StrTy, TokLoc);
3957 bool CharIsUnsigned =
Context.CharTy->isUnsignedIntegerType();
3958 llvm::APSInt
Value(CharBits, CharIsUnsigned);
3959 for (
unsigned I = 0, N = Literal.getUDSuffixOffset(); I != N; ++I) {
3960 Value = TokSpelling[I];
3968 llvm_unreachable(
"unexpected literal operator lookup result");
3974 if (Literal.isFixedPointLiteral()) {
3977 if (Literal.isAccum) {
3978 if (Literal.isHalf) {
3980 }
else if (Literal.isLong) {
3985 }
else if (Literal.isFract) {
3986 if (Literal.isHalf) {
3988 }
else if (Literal.isLong) {
3995 if (Literal.isUnsigned) Ty =
Context.getCorrespondingUnsignedType(Ty);
3997 bool isSigned = !Literal.isUnsigned;
3998 unsigned scale =
Context.getFixedPointScale(Ty);
3999 unsigned bit_width =
Context.getTypeInfo(Ty).Width;
4001 llvm::APInt Val(bit_width, 0, isSigned);
4002 bool Overflowed = Literal.GetFixedPointValue(Val, scale);
4003 bool ValIsZero = Val.isZero() && !Overflowed;
4005 auto MaxVal =
Context.getFixedPointMax(Ty).getValue();
4006 if (Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
4012 else if (Val.ugt(MaxVal) || Overflowed)
4013 Diag(
Tok.getLocation(), diag::err_too_large_for_fixed_point);
4016 Tok.getLocation(), scale);
4017 }
else if (Literal.isFloatingLiteral()) {
4019 if (Literal.isHalf){
4024 Diag(
Tok.getLocation(), diag::err_half_const_requires_fp16);
4027 }
else if (Literal.isFloat)
4029 else if (Literal.isLong)
4031 else if (Literal.isFloat16)
4033 else if (Literal.isFloat128)
4050 Diag(
Tok.getLocation(), diag::warn_double_const_requires_fp64)
4055 }
else if (!Literal.isIntegerLiteral()) {
4061 if (Literal.isSizeT)
4064 ? diag::warn_cxx20_compat_size_t_suffix
4065 : diag::ext_cxx23_size_t_suffix
4066 : diag::err_cxx23_size_t_suffix);
4073 if (Literal.isBitInt)
4074 PP.Diag(
Tok.getLocation(),
4077 : diag::ext_c23_bitint_suffix);
4086 unsigned BitsNeeded =
Context.getTargetInfo().getIntMaxTWidth();
4087 if (Literal.isBitInt)
4088 BitsNeeded = llvm::APInt::getSufficientBitsNeeded(
4089 Literal.getLiteralDigits(), Literal.getRadix());
4090 if (Literal.MicrosoftInteger) {
4091 if (Literal.MicrosoftInteger == 128 &&
4092 !
Context.getTargetInfo().hasInt128Type())
4093 PP.Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
4094 << Literal.isUnsigned;
4095 BitsNeeded = Literal.MicrosoftInteger;
4098 llvm::APInt ResultVal(BitsNeeded, 0);
4100 if (Literal.GetIntegerValue(ResultVal)) {
4102 Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
4104 Ty =
Context.UnsignedLongLongTy;
4105 assert(
Context.getTypeSize(Ty) == ResultVal.getBitWidth() &&
4106 "long long is not intmax_t?");
4113 bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
4120 Literal.isLong =
true;
4121 Literal.isLongLong =
false;
4128 if (Literal.MicrosoftInteger) {
4129 if (Literal.MicrosoftInteger == 8 && !Literal.isUnsigned) {
4133 Width = Literal.MicrosoftInteger;
4134 Ty =
Context.getIntTypeForBitwidth(Width,
4135 !Literal.isUnsigned);
4141 if (Literal.isBitInt) {
4144 Width = std::max(ResultVal.getActiveBits(), 1u) +
4145 (Literal.isUnsigned ? 0u : 1u);
4149 unsigned int MaxBitIntWidth =
4150 Context.getTargetInfo().getMaxBitIntWidth();
4151 if (Width > MaxBitIntWidth) {
4152 Diag(
Tok.getLocation(), diag::err_integer_literal_too_large)
4153 << Literal.isUnsigned;
4154 Width = MaxBitIntWidth;
4161 ResultVal = ResultVal.zextOrTrunc(Width);
4162 Ty =
Context.getBitIntType(Literal.isUnsigned, Width);
4166 if (Literal.isSizeT) {
4167 assert(!Literal.MicrosoftInteger &&
4168 "size_t literals can't be Microsoft literals");
4169 unsigned SizeTSize =
Context.getTargetInfo().getTypeWidth(
4170 Context.getTargetInfo().getSizeType());
4173 if (ResultVal.isIntN(SizeTSize)) {
4175 if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
4176 Ty =
Context.getSignedSizeType();
4177 else if (AllowUnsigned)
4183 if (Ty.
isNull() && !Literal.isLong && !Literal.isLongLong &&
4186 unsigned IntSize =
Context.getTargetInfo().getIntWidth();
4189 if (ResultVal.isIntN(IntSize)) {
4191 if (!Literal.isUnsigned && ResultVal[IntSize-1] == 0)
4193 else if (AllowUnsigned)
4200 if (Ty.
isNull() && !Literal.isLongLong && !Literal.isSizeT) {
4201 unsigned LongSize =
Context.getTargetInfo().getLongWidth();
4204 if (ResultVal.isIntN(LongSize)) {
4206 if (!Literal.isUnsigned && ResultVal[LongSize-1] == 0)
4208 else if (AllowUnsigned)
4213 const unsigned LongLongSize =
4214 Context.getTargetInfo().getLongLongWidth();
4218 ? diag::warn_old_implicitly_unsigned_long_cxx
4220 ext_old_implicitly_unsigned_long_cxx
4221 : diag::warn_old_implicitly_unsigned_long)
4222 << (LongLongSize > LongSize ? 0
4231 if (Ty.
isNull() && !Literal.isSizeT) {
4232 unsigned LongLongSize =
Context.getTargetInfo().getLongLongWidth();
4235 if (ResultVal.isIntN(LongLongSize)) {
4239 if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
4240 (
getLangOpts().MSVCCompat && Literal.isLongLong)))
4242 else if (AllowUnsigned)
4243 Ty =
Context.UnsignedLongLongTy;
4244 Width = LongLongSize;
4250 ? diag::warn_cxx98_compat_longlong
4251 : diag::ext_cxx11_longlong);
4253 Diag(
Tok.getLocation(), diag::ext_c99_longlong);
4261 if (Literal.isSizeT)
4262 Diag(
Tok.getLocation(), diag::err_size_t_literal_too_large)
4263 << Literal.isUnsigned;
4266 diag::ext_integer_literal_too_large_for_signed);
4267 Ty =
Context.UnsignedLongLongTy;
4268 Width =
Context.getTargetInfo().getLongLongWidth();
4271 if (ResultVal.getBitWidth() != Width)
4272 ResultVal = ResultVal.trunc(Width);
4278 if (Literal.isImaginary) {
4284 Diag(
Tok.getLocation(), diag::ext_gnu_imaginary_constant);
4286 DiagCompat(
Tok.getLocation(), diag_compat::imaginary_constant);
4292 assert(E &&
"ActOnParenExpr() missing expr");
4307 if (!(
T->isArithmeticType() ||
T->isVoidType() ||
T->isVectorType())) {
4308 S.
Diag(Loc, diag::err_vecstep_non_scalar_vector_type)
4313 assert((
T->isVoidType() || !
T->isIncompleteType()) &&
4314 "Scalar types should always be complete");
4322 if (!
T->isVectorType() && !
T->isSizelessVectorType())
4323 return S.
Diag(Loc, diag::err_builtin_non_vector_type)
4325 <<
"__builtin_vectorelements" <<
T << ArgRange;
4327 if (
auto *FD = dyn_cast<FunctionDecl>(S.
CurContext)) {
4328 if (
T->isSVESizelessBuiltinType()) {
4329 llvm::StringMap<bool> CallerFeatureMap;
4344 if (!
T->isFunctionType() && !
T->isFunctionPointerType() &&
4345 !
T->isFunctionReferenceType() && !
T->isMemberFunctionPointerType()) {
4346 S.
Diag(Loc, diag::err_ptrauth_type_disc_undiscriminated) <<
T << ArgRange;
4356 UnaryExprOrTypeTrait TraitKind) {
4362 if (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
4363 TraitKind == UETT_PreferredAlignOf) {
4366 if (
T->isFunctionType()) {
4367 S.
Diag(Loc, diag::ext_sizeof_alignof_function_type)
4374 if (
T->isVoidType()) {
4375 unsigned DiagID = S.
LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
4376 : diag::ext_sizeof_alignof_void_type;
4387 UnaryExprOrTypeTrait TraitKind) {
4391 S.
Diag(Loc, diag::err_sizeof_nonfragile_interface)
4392 <<
T << (TraitKind == UETT_SizeOf)
4409 const auto *ICE = dyn_cast<ImplicitCastExpr>(E);
4410 if (!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay)
4413 S.
Diag(Loc, diag::warn_sizeof_array_decay) << ICE->getSourceRange()
4415 << ICE->getSubExpr()->getType();
4419 UnaryExprOrTypeTrait ExprKind) {
4423 bool IsUnevaluatedOperand =
4424 (ExprKind == UETT_SizeOf || ExprKind == UETT_DataSizeOf ||
4425 ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4426 ExprKind == UETT_VecStep || ExprKind == UETT_CountOf);
4427 if (IsUnevaluatedOperand) {
4443 Diag(E->
getExprLoc(), diag::warn_side_effects_unevaluated_context);
4445 if (ExprKind == UETT_VecStep)
4449 if (ExprKind == UETT_VectorElements)
4460 if (
Context.getTargetInfo().getTriple().isWasm() &&
4471 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4474 diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4479 E, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4498 if (ExprKind == UETT_CountOf) {
4503 Diag(E->
getExprLoc(), diag::err_countof_arg_not_array_type) << ExprType;
4513 if (ExprKind == UETT_SizeOf) {
4514 if (
const auto *DeclRef = dyn_cast<DeclRefExpr>(E->
IgnoreParens())) {
4515 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
4516 QualType OType = PVD->getOriginalType();
4521 Diag(PVD->getLocation(), diag::note_declared_at);
4529 if (
const auto *BO = dyn_cast<BinaryOperator>(E->
IgnoreParens())) {
4546 S.
Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield)
4553 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Inner)) {
4555 }
else if (
MemberExpr *ME = dyn_cast<MemberExpr>(Inner)) {
4556 D = ME->getMemberDecl();
4576 if (
FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
4579 if (!FD->getParent()->isCompleteDefinition()) {
4580 S.
Diag(E->
getExprLoc(), diag::err_alignof_member_of_incomplete_type)
4589 if (!FD->getType()->isReferenceType())
4608 assert(
T->isVariablyModifiedType());
4609 assert(CSI !=
nullptr);
4613 const Type *Ty =
T.getTypePtr();
4615#define TYPE(Class, Base)
4616#define ABSTRACT_TYPE(Class, Base)
4617#define NON_CANONICAL_TYPE(Class, Base)
4618#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4619#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
4620#include "clang/AST/TypeNodes.inc"
4627 case Type::ExtVector:
4628 case Type::ConstantMatrix:
4631 case Type::TemplateSpecialization:
4632 case Type::ObjCObject:
4633 case Type::ObjCInterface:
4634 case Type::ObjCObjectPointer:
4635 case Type::ObjCTypeParam:
4638 case Type::HLSLInlineSpirv:
4639 llvm_unreachable(
"type class is never variably-modified!");
4640 case Type::Adjusted:
4646 case Type::ArrayParameter:
4652 case Type::BlockPointer:
4655 case Type::LValueReference:
4656 case Type::RValueReference:
4659 case Type::MemberPointer:
4662 case Type::ConstantArray:
4663 case Type::IncompleteArray:
4667 case Type::VariableArray: {
4681 case Type::FunctionProto:
4682 case Type::FunctionNoProto:
4687 case Type::UnaryTransform:
4688 case Type::Attributed:
4689 case Type::BTFTagAttributed:
4690 case Type::OverflowBehavior:
4691 case Type::HLSLAttributedResource:
4692 case Type::SubstTemplateTypeParm:
4693 case Type::MacroQualified:
4694 case Type::CountAttributed:
4695 case Type::LateParsedAttr:
4697 T =
T.getSingleStepDesugaredType(Context);
4702 case Type::Decltype:
4705 case Type::PackIndexing:
4712 case Type::DeducedTemplateSpecialization:
4715 case Type::TypeOfExpr:
4721 case Type::PredefinedSugar:
4725 }
while (!
T.isNull() &&
T->isVariablyModifiedType());
4731 UnaryExprOrTypeTrait ExprKind,
4748 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4749 ExprKind == UETT_OpenMPRequiredSimdAlign) {
4754 DiagCompat(OpLoc, diag_compat::alignof_incomplete_array);
4755 ExprType =
Context.getBaseElementType(ExprType);
4758 if (ExprKind == UETT_VecStep)
4761 if (ExprKind == UETT_VectorElements)
4765 if (ExprKind == UETT_PtrAuthTypeDiscriminator)
4775 OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4780 Diag(OpLoc, diag::err_sizeof_alignof_function_type) << KWName << ExprRange;
4784 if (ExprKind == UETT_CountOf) {
4788 Diag(OpLoc, diag::err_countof_arg_not_array_type) << ExprType;
4795 if (
Context.getTargetInfo().getTriple().isWasm() &&
4797 Diag(OpLoc, diag::err_wasm_table_invalid_uett_operand)
4811 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
4815 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
4816 DC = LSI->CallOperator;
4817 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
4818 DC = CRSI->TheCapturedDecl;
4819 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
4835 UnaryExprOrTypeTrait ExprKind,
4842 if (!
T->isDependentType() &&
4851 (ExprKind == UETT_SizeOf || ExprKind == UETT_CountOf) &&
4861 ExprKind, TInfo,
Context.getSizeType(), OpLoc, R.getEnd());
4866 UnaryExprOrTypeTrait ExprKind) {
4877 }
else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4879 }
else if (ExprKind == UETT_VecStep) {
4881 }
else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
4885 Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0;
4887 }
else if (ExprKind == UETT_VectorElements || ExprKind == UETT_SizeOf ||
4888 ExprKind == UETT_CountOf) {
4895 if ((ExprKind == UETT_SizeOf || ExprKind == UETT_CountOf) &&
4909 UnaryExprOrTypeTrait ExprKind,
bool IsType,
4930 UETT_AlignOf, KWName);
4943 if (
V.get()->isTypeDependent())
4955 return CT->getElementType();
4958 if (
V.get()->getType()->isArithmeticType())
4959 return V.get()->getType();
4964 if (PR.
get() !=
V.get()) {
4970 S.
Diag(Loc, diag::err_realimag_invalid_type) <<
V.get()->getType()
4971 << (IsReal ?
"__real" :
"__imag");
4982 default: llvm_unreachable(
"Unknown unary op!");
4983 case tok::plusplus: Opc = UO_PostInc;
break;
4984 case tok::minusminus: Opc = UO_PostDec;
break;
5003 !S.
LangOpts.ObjCSubscriptingLegacyRuntime)
5006 S.
Diag(opLoc, diag::err_arithmetic_nonfragile_interface)
5013 auto *BaseNoParens =
Base->IgnoreParens();
5014 if (
auto *MSProp = dyn_cast<MSPropertyRefExpr>(BaseNoParens))
5015 return MSProp->getPropertyDecl()->getType()->isArrayType();
5036 if (RTy->isIntegralOrUnscopedEnumerationType()) {
5038 Result = PT->getPointeeType();
5040 Result = AT->getElementType();
5043 Result = PT->getPointeeType();
5045 Result = AT->getElementType();
5059 if (AS->isOMPArraySection())
5075 base = result.
get();
5084 auto CheckAndReportCommaError = [&](
Expr *E) {
5085 if (ArgExprs.size() > 1 ||
5087 Diag(E->getExprLoc(), diag::err_matrix_subscript_comma)
5098 Diag(base->
getExprLoc(), diag::err_matrix_separate_incomplete_index)
5104 auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
5105 if (matSubscriptE && matSubscriptE->isIncomplete()) {
5106 if (CheckAndReportCommaError(ArgExprs.front()))
5110 matSubscriptE->getRowIdx(),
5111 ArgExprs.front(), rbLoc);
5119 CheckInvalidBuiltinCountedByRef(base,
5127 bool IsMSPropertySubscript =
false;
5130 if (!IsMSPropertySubscript) {
5134 base = result.
get();
5140 if (CheckAndReportCommaError(ArgExprs.front()))
5148 Expr *idx = ArgExprs[0];
5157 if (ArgExprs.size() == 1 &&
5158 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) {
5162 ArgExprs[0] = result.
get();
5174 base, ArgExprs.front(),
5187 if (IsMSPropertySubscript) {
5188 if (ArgExprs.size() > 1) {
5190 diag::err_ms_property_subscript_expects_single_arg);
5216 Diag(base->
getExprLoc(), diag::err_ovl_builtin_subscript_expects_single_arg)
5224 ArgExprs[0]->getType()->isRecordType())))) {
5242 return InitSeq.
Perform(*
this, Entity, Kind, E);
5256 RowIdx = RowR.
get();
5266 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5267 bool IsColumnIdx) ->
Expr * {
5275 if (std::optional<llvm::APSInt> Idx =
5277 if ((*Idx < 0 || *Idx >=
Dim)) {
5279 << IsColumnIdx <<
Dim;
5286 "should be able to convert any integer type to size type");
5287 return ConvExpr.
get();
5291 RowIdx = IsIndexValid(RowIdx, MTy->getNumRows(),
false);
5296 Context.getExtVectorType(MTy->getElementType(), MTy->getNumColumns());
5312 RowIdx = RowR.
get();
5316 Base, RowIdx, ColumnIdx,
Context.IncompleteMatrixIdxTy, RBLoc);
5327 ColumnIdx = ColumnR.
get();
5332 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5333 bool IsColumnIdx) ->
Expr * {
5341 if (std::optional<llvm::APSInt> Idx =
5343 if ((*Idx < 0 || *Idx >=
Dim)) {
5345 << IsColumnIdx <<
Dim;
5352 "should be able to convert any integer type to size type");
5353 return ConvExpr.
get();
5357 RowIdx = IsIndexValid(RowIdx, MTy->getNumRows(),
false);
5358 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(),
true);
5359 if (!RowIdx || !ColumnIdx)
5363 MTy->getElementType(), RBLoc);
5366void Sema::CheckAddressOfNoDeref(
const Expr *E) {
5373 while ((
Member = dyn_cast<MemberExpr>(StrippedExpr)) && !
Member->isArrow())
5374 StrippedExpr =
Member->getBase()->IgnoreParenImpCasts();
5376 LastRecord.PossibleDerefs.erase(StrippedExpr);
5390 if (ResultTy->
hasAttr(attr::NoDeref)) {
5391 LastRecord.PossibleDerefs.insert(E);
5398 QualType BaseTy =
Base->getType();
5403 const MemberExpr *
Member =
nullptr;
5404 while ((
Member = dyn_cast<MemberExpr>(
Base->IgnoreParenCasts())) &&
5408 if (
const auto *Ptr = dyn_cast<PointerType>(
Base->getType())) {
5409 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
5410 LastRecord.PossibleDerefs.insert(E);
5426 for (
auto *Op : {LHSExp, RHSExp}) {
5427 Op = Op->IgnoreImplicit();
5428 if (Op->getType()->isArrayType() && !Op->isLValue())
5451 Expr *BaseExpr, *IndexExpr;
5469 if (!
LangOpts.isSubscriptPointerArithmetic())
5485 if (!
LangOpts.isSubscriptPointerArithmetic()) {
5486 Diag(LLoc, diag::err_subscript_nonfragile_interface)
5510 LHSExp = Materialized.
get();
5517 Qualifiers BaseQuals = BaseType.getQualifiers();
5519 Qualifiers Combined = BaseQuals + MemberQuals;
5520 if (Combined != MemberQuals)
5521 ResultType =
Context.getQualifiedType(ResultType, Combined);
5531 CK_ArrayToPointerDecay).
get();
5537 }
else if (RHSTy->isArrayType()) {
5542 CK_ArrayToPointerDecay).
get();
5549 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_value)
5554 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_not_integer)
5560 std::optional<llvm::APSInt> IntegerContantExpr =
5562 if (!IntegerContantExpr.has_value() ||
5563 IntegerContantExpr.value().isNegative())
5579 Diag(LLoc, diag::ext_gnu_subscript_void_type)
5590 diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
5603 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
5607 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
5608 DC = LSI->CallOperator;
5609 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
5610 DC = CRSI->TheCapturedDecl;
5611 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
5629 bool SkipImmediateInvocations) {
5630 if (Param->hasUnparsedDefaultArg()) {
5631 assert(!RewrittenInit &&
"Should not have a rewritten init expression yet");
5635 Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD;
5636 Diag(CallLoc, diag::note_recursive_default_argument_used_here);
5637 Param->setInvalidDecl();
5641 Diag(CallLoc, diag::err_use_of_default_argument_to_function_declared_later)
5644 diag::note_default_argument_declared_here);
5648 if (Param->hasUninstantiatedDefaultArg()) {
5649 assert(!RewrittenInit &&
"Should not have a rewitten init expression yet");
5654 Expr *
Init = RewrittenInit ? RewrittenInit : Param->getInit();
5655 assert(
Init &&
"default argument but no initializer?");
5664 if (
auto *InitWithCleanup = dyn_cast<ExprWithCleanups>(
Init)) {
5667 Cleanup.setExprNeedsCleanups(InitWithCleanup->cleanupsHaveSideEffects());
5671 assert(!InitWithCleanup->getNumObjects() &&
5672 "default argument expression has capturing blocks?");
5685 SkipImmediateInvocations;
5773 if (!
SemaRef.CurrentInstantiationScope ||
5785 assert(Param->hasDefaultArg() &&
"can't build nonexistent default arg");
5789 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5790 InitializationContext =
5792 if (!InitializationContext.has_value())
5793 InitializationContext.emplace(CallLoc, Param,
CurContext);
5795 if (!
Init && !Param->hasUnparsedDefaultArg()) {
5810 if (Param->hasUninstantiatedDefaultArg()) {
5819 if (!NestedDefaultChecking)
5820 V.TraverseDecl(Param);
5824 if (
V.HasImmediateCalls ||
5825 (NeedRebuild && isa_and_present<ExprWithCleanups>(Param->getInit()))) {
5826 if (
V.HasImmediateCalls)
5836 Res = Immediate.TransformInitializer(Param->getInit(),
5850 CallLoc, FD, Param,
Init,
5851 NestedDefaultChecking))
5855 Init, InitializationContext->Context);
5865 ClassPattern->
lookup(Field->getDeclName());
5866 auto Rng = llvm::make_filter_range(
5877 assert(Field->hasInClassInitializer());
5883 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5884 InitializationContext =
5886 if (!InitializationContext.has_value())
5887 InitializationContext.emplace(Loc, Field,
CurContext);
5896 if (!Field->getInClassInitializer()) {
5902 assert(Pattern &&
"We must have set the Pattern!");
5906 Field->setInvalidDecl();
5918 if (!NestedDefaultChecking)
5919 V.TraverseDecl(Field);
5928 bool ContainsAnyTemporaries =
5929 isa_and_present<ExprWithCleanups>(Field->getInClassInitializer());
5930 if (Field->getInClassInitializer() &&
5931 !Field->getInClassInitializer()->containsErrors() &&
5932 (
V.HasImmediateCalls || (NeedRebuild && ContainsAnyTemporaries))) {
5936 NestedDefaultChecking;
5944 Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
5950 Field->setInvalidDecl();
5956 if (Field->getInClassInitializer()) {
5957 Expr *E =
Init ?
Init : Field->getInClassInitializer();
5958 if (!NestedDefaultChecking)
5969 Field->setInvalidDecl();
5975 Field, InitializationContext->Context,
5994 Diag(Loc, diag::err_default_member_initializer_not_yet_parsed)
5995 << OutermostClass << Field;
5996 Diag(Field->getEndLoc(),
5997 diag::note_default_member_initializer_not_yet_parsed);
6000 Field->setInvalidDecl();
6008 if (isa_and_nonnull<CXXConstructorDecl>(FDecl))
6010 else if (Fn && Fn->getType()->isBlockPointerType())
6014 if (
Method->isInstance())
6016 }
else if (Fn && Fn->getType() ==
Context.BoundMemberTy)
6029 FunctionName(FuncName) {}
6031 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
6040 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
6041 return std::make_unique<FunctionCallCCC>(*
this);
6045 const IdentifierInfo *
const FunctionName;
6061 if (
NamedDecl *ND = Corrected.getFoundDecl()) {
6062 if (Corrected.isOverloaded()) {
6072 ND = Best->FoundDecl;
6073 Corrected.setCorrectionDecl(ND);
6079 ND = ND->getUnderlyingDecl();
6094 Fn = Fn->IgnoreParens();
6096 auto *UO = dyn_cast<UnaryOperator>(Fn);
6097 if (!UO || UO->getOpcode() != clang::UO_AddrOf)
6099 if (
auto *DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr()->IgnoreParens())) {
6100 return DRE->hasQualifier();
6102 if (
auto *OVL = dyn_cast<OverloadExpr>(UO->getSubExpr()->IgnoreParens()))
6103 return bool(OVL->getQualifier());
6113 bool IsExecConfig) {
6121 if (
Context.BuiltinInfo.hasCustomTypechecking(ID) &&
6122 !(
Context.getLangOpts().HLSL && FDecl->
hasAttr<BuiltinAliasAttr>()))
6129 bool HasExplicitObjectParameter =
6131 unsigned ExplicitObjectParameterOffset = HasExplicitObjectParameter ? 1 : 0;
6135 unsigned FnKind = Fn->getType()->isBlockPointerType()
6142 if (Args.size() < NumParams) {
6143 if (Args.size() < MinArgs) {
6148 ? diag::err_typecheck_call_too_few_args_suggest
6149 : diag::err_typecheck_call_too_few_args_at_least_suggest;
6152 << FnKind << MinArgs - ExplicitObjectParameterOffset
6153 <<
static_cast<unsigned>(Args.size()) -
6154 ExplicitObjectParameterOffset
6156 }
else if (MinArgs - ExplicitObjectParameterOffset == 1 && FDecl &&
6161 ? diag::err_typecheck_call_too_few_args_one
6162 : diag::err_typecheck_call_too_few_args_at_least_one)
6163 << FnKind << FDecl->
getParamDecl(ExplicitObjectParameterOffset)
6164 << HasExplicitObjectParameter << Fn->getSourceRange();
6167 ? diag::err_typecheck_call_too_few_args
6168 : diag::err_typecheck_call_too_few_args_at_least)
6169 << FnKind << MinArgs - ExplicitObjectParameterOffset
6170 <<
static_cast<unsigned>(Args.size()) -
6171 ExplicitObjectParameterOffset
6172 << HasExplicitObjectParameter << Fn->getSourceRange();
6175 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
6183 assert((
Call->getNumArgs() == NumParams) &&
6184 "We should have reserved space for the default arguments before!");
6189 if (Args.size() > NumParams) {
6195 ? diag::err_typecheck_call_too_many_args_suggest
6196 : diag::err_typecheck_call_too_many_args_at_most_suggest;
6199 << FnKind << NumParams - ExplicitObjectParameterOffset
6200 <<
static_cast<unsigned>(Args.size()) -
6201 ExplicitObjectParameterOffset
6203 }
else if (NumParams - ExplicitObjectParameterOffset == 1 && FDecl &&
6206 Diag(Args[NumParams]->getBeginLoc(),
6207 MinArgs == NumParams
6208 ? diag::err_typecheck_call_too_many_args_one
6209 : diag::err_typecheck_call_too_many_args_at_most_one)
6210 << FnKind << FDecl->
getParamDecl(ExplicitObjectParameterOffset)
6211 <<
static_cast<unsigned>(Args.size()) -
6212 ExplicitObjectParameterOffset
6213 << HasExplicitObjectParameter << Fn->getSourceRange()
6215 Args.back()->getEndLoc());
6217 Diag(Args[NumParams]->getBeginLoc(),
6218 MinArgs == NumParams
6219 ? diag::err_typecheck_call_too_many_args
6220 : diag::err_typecheck_call_too_many_args_at_most)
6221 << FnKind << NumParams - ExplicitObjectParameterOffset
6222 <<
static_cast<unsigned>(Args.size()) -
6223 ExplicitObjectParameterOffset
6224 << HasExplicitObjectParameter << Fn->getSourceRange()
6226 Args.back()->getEndLoc());
6229 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
6234 Call->shrinkNumArgs(NumParams);
6245 unsigned TotalNumArgs = AllArgs.size();
6246 for (
unsigned i = 0; i < TotalNumArgs; ++i)
6247 Call->setArg(i, AllArgs[i]);
6249 Call->computeDependence();
6258 bool IsListInitialization) {
6263 for (
unsigned i = FirstParam; i < NumParams; i++) {
6268 if (ArgIx < Args.size()) {
6269 Arg = Args[ArgIx++];
6272 diag::err_call_incomplete_argument, Arg))
6276 bool CFAudited =
false;
6278 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
6279 (!Param || !Param->hasAttr<CFConsumedAttr>()))
6282 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
6283 (!Param || !Param->hasAttr<CFConsumedAttr>()))
6289 BE->getBlockDecl()->setDoesNotEscape();
6310 if (
const auto *OBT = Arg->
getType()->
getAs<OverflowBehaviorType>();
6313 OBT->isUnsignedIntegerOrEnumerationType() && OBT->isWrapKind();
6315 isPedantic ? diag::warn_obt_discarded_at_function_boundary_pedantic
6316 : diag::warn_obt_discarded_at_function_boundary)
6317 << Arg->
getType() << ProtoArgType;
6321 Entity,
SourceLocation(), Arg, IsListInitialization, AllowExplicit);
6327 assert(Param &&
"can't use default arguments without a known callee");
6339 CheckArrayAccess(Arg);
6344 AllArgs.push_back(Arg);
6353 for (
Expr *A : Args.slice(ArgIx)) {
6357 AllArgs.push_back(arg.get());
6362 for (
Expr *A : Args.slice(ArgIx)) {
6365 AllArgs.push_back(Arg.
get());
6370 for (
Expr *A : Args.slice(ArgIx))
6371 CheckArrayAccess(A);
6379 TL = DTL.getOriginalLoc();
6382 << ATL.getLocalSourceRange();
6388 const Expr *ArgExpr) {
6393 QualType OrigTy = Param->getOriginalType();
6418 Diag(CallLoc, diag::warn_static_array_too_small)
6426 std::optional<CharUnits> ArgSize =
6428 std::optional<CharUnits> ParmSize =
6430 if (ArgSize && ParmSize && *ArgSize < *ParmSize) {
6431 Diag(CallLoc, diag::warn_static_array_too_small)
6433 << (
unsigned)ParmSize->getQuantity() << 1;
6447 if (!placeholder)
return false;
6449 switch (placeholder->
getKind()) {
6451#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
6452 case BuiltinType::Id:
6453#include "clang/Basic/OpenCLImageTypes.def"
6454#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
6455 case BuiltinType::Id:
6456#include "clang/Basic/OpenCLExtensionTypes.def"
6459#define SVE_TYPE(Name, Id, SingletonId) \
6460 case BuiltinType::Id:
6461#include "clang/Basic/AArch64ACLETypes.def"
6462#define PPC_VECTOR_TYPE(Name, Id, Size) \
6463 case BuiltinType::Id:
6464#include "clang/Basic/PPCTypes.def"
6465#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6466#include "clang/Basic/RISCVVTypes.def"
6467#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6468#include "clang/Basic/WebAssemblyReferenceTypes.def"
6469#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
6470#include "clang/Basic/AMDGPUTypes.def"
6471#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6472#include "clang/Basic/HLSLIntangibleTypes.def"
6473#define SPIRV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6474#include "clang/Basic/SPIRVTypes.def"
6475#define PLACEHOLDER_TYPE(ID, SINGLETON_ID)
6476#define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID:
6477#include "clang/AST/BuiltinTypes.def"
6480 case BuiltinType::UnresolvedTemplate:
6483 case BuiltinType::Overload:
6488 case BuiltinType::ARCUnbridgedCast:
6492 case BuiltinType::PseudoObject:
6497 case BuiltinType::UnknownAny:
6501 case BuiltinType::BoundMember:
6502 case BuiltinType::BuiltinFn:
6503 case BuiltinType::IncompleteMatrixIdx:
6504 case BuiltinType::ArraySection:
6505 case BuiltinType::OMPArrayShaping:
6506 case BuiltinType::OMPIterator:
6510 llvm_unreachable(
"bad builtin type kind");
6516 bool hasInvalid =
false;
6517 for (
size_t i = 0, e = args.size(); i != e; i++) {
6520 if (result.
isInvalid()) hasInvalid =
true;
6521 else args[i] = result.
get();
6545 if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->
getBuiltinID()) || !FT ||
6549 bool NeedsNewDecl =
false;
6569 if (!ParamType->isPointerType() ||
6570 ParamType->getPointeeType().hasAddressSpace() ||
6571 !ArgType->isPointerType() ||
6572 !ArgType->getPointeeType().hasAddressSpace() ||
6574 OverloadParams.push_back(ParamType);
6579 NeedsNewDecl =
true;
6580 LangAS AS = ArgType->getPointeeType().getAddressSpace();
6582 PointeeType = Context.getAddrSpaceQualType(PointeeType, AS);
6583 OverloadParams.push_back(Context.getPointerType(PointeeType));
6593 OverloadParams, EPI);
6603 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
6610 Params.push_back(Parm);
6612 OverloadDecl->setParams(Params);
6616 if (FDecl->
hasAttr<CUDAHostAttr>())
6617 OverloadDecl->
addAttr(CUDAHostAttr::CreateImplicit(Context));
6618 if (FDecl->
hasAttr<CUDADeviceAttr>())
6619 OverloadDecl->
addAttr(CUDADeviceAttr::CreateImplicit(Context));
6622 return OverloadDecl;
6633 !Callee->isVariadic())
6635 if (Callee->getMinRequiredArguments() > ArgExprs.size())
6638 if (
const EnableIfAttr *
Attr =
6639 S.
CheckEnableIf(Callee, Fn->getBeginLoc(), ArgExprs,
true)) {
6640 S.
Diag(Fn->getBeginLoc(),
6642 ? diag::err_ovl_no_viable_member_function_in_call
6643 : diag::err_ovl_no_viable_function_in_call)
6644 << Callee << Callee->getSourceRange();
6645 S.
Diag(Callee->getLocation(),
6646 diag::note_ovl_candidate_disabled_by_function_cond_attr)
6647 <<
Attr->getCond()->getSourceRange() <<
Attr->getMessage();
6655 const auto GetFunctionLevelDCIfCXXClass =
6663 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
6664 return MD->
getParent()->getCanonicalDecl();
6667 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
6668 return RD->getCanonicalDecl();
6675 const CXXRecordDecl *
const CurParentClass = GetFunctionLevelDCIfCXXClass(S);
6676 if (!CurParentClass)
6683 assert(NamingClass &&
"Must have naming class even for implicit access");
6689 return CurParentClass == NamingClass ||
6738 if (
Call->getNumArgs() != 1)
6741 const Expr *E =
Call->getCallee()->IgnoreParenImpCasts();
6744 const DeclRefExpr *DRE = dyn_cast_if_present<DeclRefExpr>(E);
6757 if (BuiltinID != Builtin::BImove && BuiltinID != Builtin::BIforward)
6760 S.
Diag(DRE->
getLocation(), diag::warn_unqualified_call_to_std_cast_function)
6771 if (
Call.isInvalid())
6776 if (
const auto *ULE = dyn_cast<UnresolvedLookupExpr>(Fn);
6777 ULE && ULE->hasExplicitTemplateArgs() && ULE->decls().empty()) {
6778 DiagCompat(Fn->getExprLoc(), diag_compat::adl_only_template_id)
6786 if (
const auto *CE = dyn_cast<CallExpr>(
Call.get()))
6792 if (
auto *DRE = dyn_cast<DeclRefExpr>(Fn->IgnoreParens());
6793 DRE &&
Call.get()->isValueDependent()) {
6803 if (
T->isDependentType())
6806 if (
T == Context.BoundMemberTy ||
T == Context.UnknownAnyTy ||
6807 T == Context.BuiltinFnTy ||
T == Context.OverloadTy ||
6808 T->isFunctionType() ||
T->isFunctionReferenceType() ||
6809 T->isMemberFunctionPointerType() ||
T->isFunctionPointerType() ||
6810 T->isBlockPointerType() ||
T->isRecordType() ||
T->isUndeducedType())
6819 Expr *ExecConfig,
bool IsExecConfig,
6820 bool AllowRecovery) {
6829 if (Fn->getType() ==
Context.BuiltinFnTy && ArgExprs.size() == 1 &&
6830 ArgExprs[0]->getType() ==
Context.BuiltinFnTy) {
6833 if (FD->getName() ==
"__builtin_amdgcn_is_invocable") {
6847 for (
const Expr *Arg : ArgExprs)
6848 if (CheckInvalidBuiltinCountedByRef(Arg,
6855 if (!ArgExprs.empty()) {
6857 Diag(Fn->getBeginLoc(), diag::err_pseudo_dtor_call_with_args)
6860 ArgExprs.back()->getEndLoc()));
6866 if (Fn->getType() ==
Context.PseudoObjectTy) {
6883 *
this, dyn_cast<UnresolvedMemberExpr>(Fn->IgnoreParens()),
6891 Diag(LParenLoc, diag::err_typecheck_call_not_function)
6892 << Fn->getType() << Fn->getSourceRange());
6900 if (Fn->getType()->isRecordType())
6904 if (Fn->getType() ==
Context.UnknownAnyTy) {
6910 if (Fn->getType() ==
Context.BoundMemberTy) {
6912 RParenLoc, ExecConfig, IsExecConfig,
6918 if (Fn->getType() ==
Context.OverloadTy) {
6929 Scope, Fn, ULE, LParenLoc, ArgExprs, RParenLoc, ExecConfig,
6932 RParenLoc, ExecConfig, IsExecConfig,
6938 if (Fn->getType() ==
Context.UnknownAnyTy) {
6944 Expr *NakedFn = Fn->IgnoreParens();
6946 bool CallingNDeclIndirectly =
false;
6948 if (
UnaryOperator *UnOp = dyn_cast<UnaryOperator>(NakedFn)) {
6949 if (UnOp->getOpcode() == UO_AddrOf) {
6950 CallingNDeclIndirectly =
true;
6955 if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
6956 NDecl = DRE->getDecl();
6960 const llvm::Triple &Triple =
Context.getTargetInfo().getTriple();
6961 if (Triple.isSPIRV() && Triple.getVendor() == llvm::Triple::AMD) {
6978 Fn->getValueKind(), FDecl,
nullptr, DRE->isNonOdrUse());
6981 }
else if (
auto *ME = dyn_cast<MemberExpr>(NakedFn))
6982 NDecl = ME->getMemberDecl();
6984 if (
FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(NDecl)) {
6986 FD,
true, Fn->getBeginLoc()))
6998 for (
unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size();
7001 if (!ArgExprs[Idx] || !Param || !Param->getType()->isPointerType() ||
7002 !ArgExprs[Idx]->getType()->isPointerType())
7006 auto ArgTy = ArgExprs[Idx]->getType();
7007 auto ArgPtTy = ArgTy->getPointeeType();
7008 auto ArgAS = ArgPtTy.getAddressSpace();
7011 bool NeedImplicitASC =
7016 if (!NeedImplicitASC)
7020 if (ArgExprs[Idx]->isGLValue()) {
7024 ArgExprs[Idx] = Res.
get();
7028 Qualifiers ArgPtQuals = ArgPtTy.getQualifiers();
7031 Context.getQualifiedType(ArgPtTy.getUnqualifiedType(), ArgPtQuals);
7034 ArgTy.getQualifiers());
7038 CK_AddressSpaceConversion)
7044 if (
Context.isDependenceAllowed() &&
7047 assert((Fn->containsErrors() ||
7048 llvm::any_of(ArgExprs,
7049 [](
clang::Expr *E) { return E->containsErrors(); })) &&
7050 "should only occur in error-recovery path.");
7055 ExecConfig, IsExecConfig);
7060 std::string Name =
Context.BuiltinInfo.getName(Id);
7066 assert(BuiltInDecl &&
"failed to find builtin declaration");
7070 assert(DeclRef.
isUsable() &&
"Builtin reference cannot fail");
7075 assert(!
Call.isInvalid() &&
"Call to builtin cannot fail!");
7095 Diag(BuiltinLoc, diag::err_invalid_astype_of_different_size)
7113 FunctionDecl *FDecl = dyn_cast_or_null<FunctionDecl>(NDecl);
7114 unsigned BuiltinID = (FDecl ? FDecl->
getBuiltinID() : 0);
7117 switch (BuiltinID) {
7118 case Builtin::BI__builtin_longjmp:
7119 case Builtin::BI__builtin_setjmp:
7120 case Builtin::BI__sigsetjmp:
7121 case Builtin::BI_longjmp:
7122 case Builtin::BI_setjmp:
7123 case Builtin::BIlongjmp:
7124 case Builtin::BIsetjmp:
7125 case Builtin::BIsiglongjmp:
7126 case Builtin::BIsigsetjmp:
7139 if (DeferParent->
Contains(*CurScope) &&
7141 Diag(Fn->getExprLoc(), diag::err_defer_invalid_sjlj) << FDecl;
7146 if (FDecl->
hasAttr<AnyX86InterruptAttr>()) {
7147 Diag(Fn->getExprLoc(), diag::err_anyx86_interrupt_called);
7150 if (FDecl->
hasAttr<ARMInterruptAttr>()) {
7151 Diag(Fn->getExprLoc(), diag::err_arm_interrupt_called);
7160 if (Caller->hasAttr<AnyX86InterruptAttr>() ||
7161 Caller->hasAttr<AnyX86NoCallerSavedRegistersAttr>()) {
7163 bool HasNonGPRRegisters =
7165 if (HasNonGPRRegisters &&
7166 (!FDecl || !FDecl->
hasAttr<AnyX86NoCallerSavedRegistersAttr>())) {
7167 Diag(Fn->getExprLoc(), diag::warn_anyx86_excessive_regsave)
7168 << (Caller->hasAttr<AnyX86InterruptAttr>() ? 0 : 1);
7187 Fn->getType()->isSpecificBuiltinType(BuiltinType::BuiltinFn)) {
7203 if (!BuiltinID || !
Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
7210 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
7211 << Fn->getType() << Fn->getSourceRange());
7217 if (Fn->getType() ==
Context.UnknownAnyTy) {
7225 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
7226 << Fn->getType() << Fn->getSourceRange());
7233 const auto *Proto = dyn_cast_or_null<FunctionProtoType>(FuncT);
7234 unsigned NumParams = Proto ? Proto->getNumParams() : 0;
7238 assert(UsesADL == ADLCallKind::NotADL &&
7239 "CUDAKernelCallExpr should not use ADL");
7250 if (BuiltinID &&
Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) {
7263 ExprResult E = CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7272 if (FDecl && !FDecl->
hasAttr<CUDAGlobalAttr>())
7273 return ExprError(
Diag(LParenLoc,diag::err_kern_call_not_global_function)
7274 << FDecl << Fn->getSourceRange());
7280 return ExprError(
Diag(LParenLoc, diag::err_kern_type_not_void_return)
7281 << Fn->getType() << Fn->getSourceRange());
7284 if (FDecl && FDecl->
hasAttr<CUDAGlobalAttr>())
7285 return ExprError(
Diag(LParenLoc, diag::err_global_call_not_config)
7286 << FDecl << Fn->getSourceRange());
7300 if (
Context.getTargetInfo().getTriple().isWasm()) {
7301 for (
const Expr *Arg : Args) {
7302 if (Arg && Arg->getType()->isWebAssemblyTableType()) {
7304 diag::err_wasm_table_as_function_parameter));
7328 if (!Proto || !(Proto->isVariadic() && Args.size() >= Def->
param_size()))
7329 Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
7330 << (Args.size() > Def->
param_size()) << FDecl << Fn->getSourceRange();
7349 if (!Proto && !Args.empty() &&
7351 !
Diags.isIgnored(diag::warn_strict_uses_without_prototype,
7353 Diag(LParenLoc, diag::warn_strict_uses_without_prototype)
7354 << (FDecl !=
nullptr) << FDecl;
7357 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7358 Expr *Arg = Args[i];
7360 if (Proto && i < Proto->getNumParams()) {
7362 Context, Proto->getParamType(i), Proto->isParamConsumed(i));
7380 diag::err_call_incomplete_argument, Arg))
7389 if (
Method->isImplicitObjectMemberFunction())
7390 return ExprError(
Diag(LParenLoc, diag::err_member_call_without_object)
7391 << Fn->getSourceRange() << 0);
7399 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7400 if (
const auto *RT =
7401 dyn_cast<RecordType>(Args[i]->
getType().getCanonicalType())) {
7402 if (RT->getDecl()->isOrContainsUnion())
7403 Diag(Args[i]->getBeginLoc(), diag::warn_cmse_nonsecure_union)
7414 checkFortifiedBuiltinMemoryFunction(FDecl, TheCall);
7415 checkFortifiedLibcArgument(FDecl, TheCall);
7418 return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7420 if (CheckPointerCall(NDecl, TheCall, Proto))
7423 if (CheckOtherCall(TheCall, Proto))
7433 assert(Ty &&
"ActOnCompoundLiteral(): missing type");
7434 assert(InitExpr &&
"ActOnCompoundLiteral(): missing expression");
7439 TInfo =
Context.getTrivialTypeSourceInfo(literalType);
7451 LParenLoc,
Context.getBaseElementType(literalType),
7452 diag::err_array_incomplete_or_sizeless_type,
7475 ? diag::err_variable_object_no_init
7476 : diag::err_compound_literal_with_vla_type;
7483 diag::err_typecheck_decl_incomplete_type,
7498 LiteralExpr =
Result.get();
7505 bool IsFileScope = !
CurContext->isFunctionOrMethod() &&
7536 if (
auto ILE = dyn_cast<InitListExpr>(LiteralExpr))
7537 for (
unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
7539 if (!
Init->isTypeDependent() && !
Init->isValueDependent() &&
7541 Diag(
Init->getExprLoc(), diag::err_init_element_not_constant)
7542 <<
Init->getSourceBitField();
7550 LiteralExpr, IsFileScope);
7562 Diag(LParenLoc, diag::err_compound_literal_with_address_space)
7580 Cleanup.setExprNeedsCleanups(
true);
7599 bool DiagnosedArrayDesignator =
false;
7600 bool DiagnosedNestedDesignator =
false;
7601 bool DiagnosedMixedDesignator =
false;
7605 for (
unsigned I = 0, E = InitArgList.size(); I != E; ++I) {
7606 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(InitArgList[I])) {
7608 FirstDesignator = DIE->getBeginLoc();
7613 if (!DiagnosedNestedDesignator && DIE->size() > 1) {
7614 DiagnosedNestedDesignator =
true;
7615 Diag(DIE->getBeginLoc(), diag::ext_designated_init_nested)
7616 << DIE->getDesignatorsSourceRange();
7619 for (
auto &Desig : DIE->designators()) {
7620 if (!Desig.isFieldDesignator() && !DiagnosedArrayDesignator) {
7621 DiagnosedArrayDesignator =
true;
7622 Diag(Desig.getBeginLoc(), diag::ext_designated_init_array)
7623 << Desig.getSourceRange();
7627 if (!DiagnosedMixedDesignator &&
7629 DiagnosedMixedDesignator =
true;
7630 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7631 << DIE->getSourceRange();
7632 Diag(InitArgList[0]->getBeginLoc(), diag::note_designated_init_mixed)
7633 << InitArgList[0]->getSourceRange();
7637 DiagnosedMixedDesignator =
true;
7639 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7640 << DIE->getSourceRange();
7641 Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
7642 << InitArgList[I]->getSourceRange();
7646 if (FirstDesignator.
isValid()) {
7650 !DiagnosedNestedDesignator && !DiagnosedMixedDesignator) {
7652 ? diag::warn_cxx17_compat_designated_init
7653 : diag::ext_cxx_designated_init);
7655 Diag(FirstDesignator, diag::ext_designated_init);
7659 return BuildInitList(LBraceLoc, InitArgList, RBraceLoc,
true);
7670 for (
unsigned I = 0, E = InitArgList.size(); I != E; ++I) {
7671 if (InitArgList[I]->
getType()->isNonOverloadPlaceholderType()) {
7678 InitArgList[I] = result.
get();
7698 Cleanup.setExprNeedsCleanups(
true);
7707 if (
Context.hasSameUnqualifiedType(SrcTy, DestTy))
7712 llvm_unreachable(
"member pointer type in C");
7721 if (SrcAS != DestAS)
7722 return CK_AddressSpaceConversion;
7723 if (
Context.hasCvrSimilarType(SrcTy, DestTy))
7729 ? CK_BitCast : CK_AnyPointerToBlockPointerCast);
7734 return CK_CPointerToObjCPointerCast;
7736 return CK_BlockPointerToObjCPointerCast;
7738 return CK_PointerToBoolean;
7740 return CK_PointerToIntegral;
7746 llvm_unreachable(
"illegal cast from pointer");
7748 llvm_unreachable(
"Should have returned before this");
7753 return CK_FixedPointCast;
7755 return CK_FixedPointToBoolean;
7757 return CK_FixedPointToIntegral;
7759 return CK_FixedPointToFloating;
7763 diag::err_unimplemented_conversion_with_fixed_point_type)
7765 return CK_IntegralCast;
7770 llvm_unreachable(
"illegal cast to pointer type");
7772 llvm_unreachable(
"Should have returned before this");
7782 return CK_NullToPointer;
7783 return CK_IntegralToPointer;
7785 return CK_IntegralToBoolean;
7787 return CK_IntegralCast;
7789 return CK_IntegralToFloating;
7794 return CK_IntegralRealToComplex;
7798 CK_IntegralToFloating);
7799 return CK_FloatingRealToComplex;
7801 llvm_unreachable(
"member pointer type in C");
7803 return CK_IntegralToFixedPoint;
7805 llvm_unreachable(
"Should have returned before this");
7810 return CK_FloatingCast;
7812 return CK_FloatingToBoolean;
7814 return CK_FloatingToIntegral;
7819 return CK_FloatingRealToComplex;
7823 CK_FloatingToIntegral);
7824 return CK_IntegralRealToComplex;
7828 llvm_unreachable(
"valid float->pointer cast?");
7830 llvm_unreachable(
"member pointer type in C");
7832 return CK_FloatingToFixedPoint;
7834 llvm_unreachable(
"Should have returned before this");
7839 return CK_FloatingComplexCast;
7841 return CK_FloatingComplexToIntegralComplex;
7844 if (
Context.hasSameType(ET, DestTy))
7845 return CK_FloatingComplexToReal;
7847 return CK_FloatingCast;
7850 return CK_FloatingComplexToBoolean;
7854 CK_FloatingComplexToReal);
7855 return CK_FloatingToIntegral;
7859 llvm_unreachable(
"valid complex float->pointer cast?");
7861 llvm_unreachable(
"member pointer type in C");
7864 diag::err_unimplemented_conversion_with_fixed_point_type)
7866 return CK_IntegralCast;
7868 llvm_unreachable(
"Should have returned before this");
7873 return CK_IntegralComplexToFloatingComplex;
7875 return CK_IntegralComplexCast;
7878 if (
Context.hasSameType(ET, DestTy))
7879 return CK_IntegralComplexToReal;
7881 return CK_IntegralCast;
7884 return CK_IntegralComplexToBoolean;
7888 CK_IntegralComplexToReal);
7889 return CK_IntegralToFloating;
7893 llvm_unreachable(
"valid complex int->pointer cast?");
7895 llvm_unreachable(
"member pointer type in C");
7898 diag::err_unimplemented_conversion_with_fixed_point_type)
7900 return CK_IntegralCast;
7902 llvm_unreachable(
"Should have returned before this");
7905 llvm_unreachable(
"Unhandled scalar cast");
7912 len = vecType->getNumElements();
7913 eltType = vecType->getElementType();
7920 if (!
type->isRealType())
return false;
7930 auto ValidScalableConversion = [](
QualType FirstType,
QualType SecondType) {
7934 const auto *VecTy = SecondType->getAs<
VectorType>();
7938 return ValidScalableConversion(srcTy, destTy) ||
7939 ValidScalableConversion(destTy, srcTy);
7949 return matSrcType->
getNumRows() == matDestType->getNumRows() &&
7950 matSrcType->
getNumColumns() == matDestType->getNumColumns();
7956 uint64_t SrcLen, DestLen;
7966 uint64_t SrcEltSize =
Context.getTypeSize(SrcEltTy);
7967 uint64_t DestEltSize =
Context.getTypeSize(DestEltTy);
7969 return (SrcLen * SrcEltSize == DestLen * DestEltSize);
7974 "expected at least one type to be a vector here");
7976 bool IsSrcTyAltivec =
7992 return (IsSrcTyAltivec || IsDestTyAltivec);
8012 switch (
Context.getLangOpts().getLaxVectorConversions()) {
8019 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
8024 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
8041 return Diag(R.getBegin(), diag::err_invalid_conversion_between_matrixes)
8042 << DestTy << SrcTy << R;
8045 return Diag(R.getBegin(),
8046 diag::err_invalid_conversion_between_matrix_and_type)
8047 << SrcTy << DestTy << R;
8049 return Diag(R.getBegin(),
8050 diag::err_invalid_conversion_between_matrix_and_type)
8051 << DestTy << SrcTy << R;
8054 Kind = CK_MatrixCast;
8060 assert(VectorTy->
isVectorType() &&
"Not a vector type!");
8064 return Diag(R.getBegin(),
8066 diag::err_invalid_conversion_between_vectors :
8067 diag::err_invalid_conversion_between_vector_and_integer)
8068 << VectorTy << Ty << R;
8070 return Diag(R.getBegin(),
8071 diag::err_invalid_conversion_between_vector_and_scalar)
8072 << VectorTy << Ty << R;
8081 if (DestElemTy == SplattedExpr->
getType())
8082 return SplattedExpr;
8095 CK_BooleanToSignedIntegral);
8096 SplattedExpr = CastExprRes.
get();
8097 CK = CK_IntegralToFloating;
8099 CK = CK_BooleanToSignedIntegral;
8106 SplattedExpr = CastExprRes.
get();
8114 if (DestElemTy == SplattedExpr->
getType())
8115 return SplattedExpr;
8124 SplattedExpr = CastExprRes.
get();
8142 !
Context.hasSameUnqualifiedType(DestTy, SrcTy) &&
8143 !
Context.areCompatibleVectorTypes(DestTy, SrcTy))) {
8144 Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
8145 << DestTy << SrcTy << R;
8156 return Diag(R.getBegin(),
8157 diag::err_invalid_conversion_between_vector_and_scalar)
8158 << DestTy << SrcTy << R;
8160 Kind = CK_VectorSplat;
8170 DestType == SourceType)
8178 if (!CE->getCalleeAllocSizeAttr())
8180 std::optional<llvm::APInt> AllocSize =
8181 CE->evaluateBytesReturnedByAllocSizeCall(S.
Context);
8184 if (!AllocSize || AllocSize->isZero())
8194 if (LhsSize && Size < LhsSize)
8196 << Size.getQuantity() << TargetType << LhsSize->getQuantity();
8204 "ActOnCastExpr(): missing type or expr");
8220 bool isVectorLiteral =
false;
8235 isVectorLiteral =
true;
8238 isVectorLiteral =
true;
8243 if (isVectorLiteral)
8273 "Expected paren or paren list expression");
8280 LiteralLParenLoc = PE->getLParenLoc();
8281 LiteralRParenLoc = PE->getRParenLoc();
8282 exprs = PE->getExprs();
8283 numExprs = PE->getNumExprs();
8310 if (numExprs == 1) {
8313 if (Literal.isInvalid())
8319 else if (numExprs < numElems) {
8321 diag::err_incorrect_number_of_vector_initializers);
8325 initExprs.append(exprs, exprs + numExprs);
8334 Diag(exprs[0]->getBeginLoc(), diag::err_typecheck_convert_incompatible)
8341 if (Literal.isInvalid())
8348 initExprs.append(exprs, exprs + numExprs);
8354 LiteralRParenLoc,
false);
8383 unsigned NumUserSpecifiedExprs,
8388 InitLoc, LParenLoc, RParenLoc);
8393 const Expr *NullExpr = LHSExpr;
8394 const Expr *NonPointerExpr = RHSExpr;
8401 NonPointerExpr = LHSExpr;
8423 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands_null)
8424 << NonPointerExpr->
getType() << DiagType
8436 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8437 << CondTy <<
Cond->getSourceRange();
8444 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
8445 << CondTy <<
Cond->getSourceRange();
8478 bool IsBlockPointer =
false;
8482 IsBlockPointer =
true;
8507 ResultAddrSpace = LAddrSpace;
8509 ResultAddrSpace = RAddrSpace;
8511 S.
Diag(Loc, diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
8518 auto LHSCastKind = CK_BitCast, RHSCastKind = CK_BitCast;
8523 S.
Diag(Loc, diag::err_typecheck_cond_incompatible_ptrauth)
8540 LAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8542 RAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8550 lhptee, rhptee,
false,
false,
8553 if (CompositeTy.
isNull()) {
8570 S.
Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers)
8581 QualType ResultTy = [&, ResultAddrSpace]() {
8616 S.
Diag(Loc, diag::err_typecheck_cond_incompatible_operands)
8669 bool IsIntFirstExpr) {
8671 !Int.get()->getType()->isIntegerType())
8674 Expr *Expr1 = IsIntFirstExpr ? Int.get() : PointerExpr;
8675 Expr *Expr2 = IsIntFirstExpr ? PointerExpr : Int.get();
8677 S.
Diag(Loc, diag::ext_typecheck_cond_pointer_integer_mismatch)
8681 CK_IntegralToPointer);
8715 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8721 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8727 if (LHSType == RHSType)
8737 (S, LHS, RHS, LHSType, RHSType,
false);
8771 llvm::raw_svector_ostream OS(Str);
8772 OS <<
"(vector of " << NumElements <<
" '" << EleTyName <<
"' values)";
8773 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8774 << CondTy << OS.str();
8795 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8796 <<
Cond->getType() <<
Cond->getSourceRange();
8813 S.
Diag(QuestionLoc, diag::err_conditional_vector_size)
8814 << CondTy << VecResTy;
8819 QualType RVE = RV->getElementType();
8824 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8825 << CondTy << VecResTy;
8840 if (
Cond.isInvalid())
8851 bool IsBoolVecLang =
8880 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
8881 QualType Ty = CE->getCallee()->getType();
8913 if (
Context.isDependenceAllowed() &&
8919 "should only occur in error-recovery path.");
8926 Cond.get()->getType()->isExtVectorType())
8931 if (
Cond.isInvalid())
8954 Diag(QuestionLoc, diag::err_wasm_table_conditional_expression)
8963 diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy
8982 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
8998 Context.hasSameUnqualifiedType(LHSTy, RHSTy))
9038 if (!compositeType.
isNull())
9039 return compositeType;
9069 if (
Context.hasSameType(LHSTy, RHSTy))
9070 return Context.getCommonSugaredType(LHSTy, RHSTy);
9073 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
9092 Self.Diag(Loc,
Note) << ParenRange;
9112 const Expr **RHSExprs) {
9117 if (
const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) {
9118 E = MTE->getSubExpr();
9123 if (
const auto *OP = dyn_cast<BinaryOperator>(E);
9125 *Opcode = OP->getOpcode();
9126 *RHSExprs = OP->getRHS();
9131 if (
const auto *
Call = dyn_cast<CXXOperatorCallExpr>(E)) {
9132 if (
Call->getNumArgs() != 2)
9138 if (OO < OO_Plus || OO > OO_Arrow ||
9139 OO == OO_PlusPlus || OO == OO_MinusMinus)
9145 *RHSExprs =
Call->getArg(1);
9161 if (
const auto *OP = dyn_cast<BinaryOperator>(E))
9162 return OP->isComparisonOp() || OP->isLogicalOp();
9163 if (
const auto *OP = dyn_cast<UnaryOperator>(E))
9164 return OP->getOpcode() == UO_LNot;
9179 const Expr *RHSExpr) {
9181 const Expr *CondRHS;
9192 ? diag::warn_precedence_bitwise_conditional
9193 : diag::warn_precedence_conditional;
9195 Self.Diag(OpLoc, DiagID)
9201 Self.PDiag(diag::note_precedence_silence)
9206 Self.PDiag(diag::note_precedence_conditional_first),
9217 auto GetNullability = [](
QualType Ty) {
9228 auto LHSKind = GetNullability(LHSTy), RHSKind = GetNullability(RHSTy);
9236 MergedKind = RHSKind;
9243 MergedKind = RHSKind;
9245 MergedKind = LHSKind;
9251 if (GetNullability(ResTy) == MergedKind)
9269 Expr *commonExpr =
nullptr;
9271 commonExpr = CondExpr;
9278 commonExpr = result.
get();
9292 commonExpr = commonRes.
get();
9302 commonExpr = MatExpr.
get();
9310 LHSExpr = CondExpr = opaqueValue;
9318 VK, OK, QuestionLoc);
9319 if (result.
isNull() ||
Cond.isInvalid() || LHS.isInvalid() ||
9326 CheckBoolLikeConversion(
Cond.get(), QuestionLoc);
9334 RHS.get(), result,
VK, OK);
9337 commonExpr, opaqueValue,
Cond.get(), LHS.get(), RHS.get(), QuestionLoc,
9338 ColonLoc, result,
VK, OK);
9342 unsigned FromAttributes = 0, ToAttributes = 0;
9343 if (
const auto *FromFn =
9344 dyn_cast<FunctionProtoType>(
Context.getCanonicalType(FromType)))
9347 if (
const auto *ToFn =
9348 dyn_cast<FunctionProtoType>(
Context.getCanonicalType(ToType)))
9352 return FromAttributes != ToAttributes;
9364 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9365 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9368 const Type *lhptee, *rhptee;
9370 std::tie(lhptee, lhq) =
9372 std::tie(rhptee, rhq) =
9443 diag::warn_typecheck_convert_incompatible_function_pointer_strict,
9467 ltrans = LUnderlying;
9468 rtrans = RUnderlying;
9486 if (ltrans == rtrans) {
9502 std::tie(lhptee, lhq) =
9504 std::tie(rhptee, rhq) =
9516 return AssignConvertType::
9517 IncompatibleNestedPointerAddressSpaceMismatch;
9521 if (lhptee == rhptee)
9541 const auto *LFPT = dyn_cast<FunctionProtoType>(LFT);
9542 const auto *RFPT = dyn_cast<FunctionProtoType>(RFT);
9545 LFPT->getParamTypes(),
9546 RFPT->getExtProtoInfo());
9551 LFPT->getParamTypes(), EPI);
9556 EPI.
ExtInfo = LFT->getExtInfo();
9558 RFPT->getParamTypes(), EPI);
9577 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9578 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9599 if (LQuals != RQuals)
9628 assert(LHSType.
isCanonical() &&
"LHS was not canonicalized!");
9629 assert(RHSType.
isCanonical() &&
"RHS was not canonicalized!");
9677 return VT->getElementType().getCanonicalType() == ElementType;
9707 LHSType =
Context.getCanonicalType(LHSType).getUnqualifiedType();
9708 RHSType =
Context.getCanonicalType(RHSType).getUnqualifiedType();
9711 if (LHSType == RHSType) {
9718 if (
const auto *AT = dyn_cast<AutoType>(LHSType)) {
9719 if (AT->isGNUAutoType()) {
9725 auto OBTResult =
Context.checkOBTAssignmentCompatibility(LHSType, RHSType);
9726 switch (OBTResult) {
9731 Kind = LHSType->
isBooleanType() ? CK_IntegralToBoolean : CK_IntegralCast;
9744 !
Context.areCompatibleOverflowBehaviorTypes(LHSPointee, RHSPointee)) {
9752 if (
const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
9757 if (Kind != CK_NoOp && ConvertRHS)
9759 Kind = CK_NonAtomicToAtomic;
9771 if (
Context.typesAreCompatible(LHSTypeRef->getPointeeType(), RHSType)) {
9772 Kind = CK_LValueBitCast;
9783 if (LHSExtType->getNumElements() != RHSExtType->getNumElements())
9787 RHSExtType->getElementType()->isIntegerType()) {
9788 Kind = CK_IntegralToBoolean;
9792 if (
Context.getLangOpts().OpenCL &&
9793 Context.areCompatibleVectorTypes(LHSType, RHSType)) {
9803 Kind = CK_VectorSplat;
9813 if (
Context.areCompatibleVectorTypes(LHSType, RHSType)) {
9825 if (
Context.getTargetInfo().getTriple().isPPC() &&
9827 !
Context.areCompatibleVectorTypes(RHSType, LHSType))
9829 << RHSType << LHSType;
9843 if (
Context.getTargetInfo().getTriple().isPPC() &&
9848 << RHSType << LHSType;
9859 if (
ARM().areCompatibleSveTypes(LHSType, RHSType) ||
9860 ARM().areLaxCompatibleSveTypes(LHSType, RHSType)) {
9868 if (
Context.areCompatibleRVVTypes(LHSType, RHSType) ||
9869 Context.areLaxCompatibleRVVTypes(LHSType, RHSType)) {
9898 if (
const PointerType *LHSPointer = dyn_cast<PointerType>(LHSType)) {
9901 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9903 if (AddrSpaceL != AddrSpaceR)
9904 Kind = CK_AddressSpaceConversion;
9905 else if (
Context.hasCvrSimilarType(RHSType, LHSType))
9915 Kind = CK_IntegralToPointer;
9923 if (LHSPointer->getPointeeType()->isVoidType()) {
9931 Context.getObjCClassRedefinitionType())) {
9942 if (LHSPointer->getPointeeType()->isVoidType()) {
9943 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9948 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9966 Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9972 Kind = CK_IntegralToPointer;
9978 Kind = CK_AnyPointerToBlockPointerCast;
9984 if (RHSPT->getPointeeType()->isVoidType()) {
9985 Kind = CK_AnyPointerToBlockPointerCast;
9999 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10001 !
ObjC().CheckObjCARCUnavailableWeakConversion(OrigLHSType, RHSType))
10008 Kind = CK_IntegralToPointer;
10015 Kind = CK_CPointerToObjCPointerCast;
10025 Context.getObjCClassRedefinitionType())) {
10037 Kind = CK_BlockPointerToObjCPointerCast;
10049 Kind = CK_NullToPointer;
10056 if (LHSType ==
Context.BoolTy) {
10057 Kind = CK_PointerToBoolean;
10063 Kind = CK_PointerToIntegral;
10073 if (LHSType ==
Context.BoolTy) {
10074 Kind = CK_PointerToBoolean;
10080 Kind = CK_PointerToIntegral;
10089 if (
Context.typesAreCompatible(LHSType, RHSType)) {
10096 Kind = CK_IntToOCLSampler;
10130 const RecordType *UT =
ArgType->getAsUnionType();
10135 if (!UD->
hasAttr<TransparentUnionAttr>())
10141 for (
auto *it : UD->
fields()) {
10142 if (it->getType()->isPointerType()) {
10181 bool DiagnoseCFAudited,
10185 assert((ConvertRHS || !
Diagnose) &&
"can't indicate whether we diagnosed");
10191 ExprResult &RHS = ConvertRHS ? CallerRHS : LocalRHS;
10195 if (RHSPtrType->getPointeeType()->hasAttr(attr::NoDeref) &&
10196 !LHSPtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
10198 diag::warn_noderef_to_dereferenceable_pointer)
10217 AllowedExplicit::None,
10229 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10230 !
ObjC().CheckObjCARCUnavailableWeakConversion(LHSType, RHSType))
10252 RHS.
get(), LHSType,
false, DAP))
10261 if (!
Context.hasSameUnqualifiedType(RHSType, LHSType)) {
10389 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10399 ObjC().CheckConversionToObjCLiteral(LHSType, E,
Diagnose))) {
10419struct OriginalOperand {
10420 explicit OriginalOperand(
Expr *Op) : Orig(Op), Conversion(
nullptr) {
10421 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Op))
10422 Op = MTE->getSubExpr();
10423 if (
auto *BTE = dyn_cast<CXXBindTemporaryExpr>(Op))
10424 Op = BTE->getSubExpr();
10425 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(Op)) {
10426 Orig = ICE->getSubExprAsWritten();
10427 Conversion = ICE->getConversionFunction();
10431 QualType
getType()
const {
return Orig->getType(); }
10434 NamedDecl *Conversion;
10440 OriginalOperand OrigLHS(LHS.
get()), OrigRHS(RHS.
get());
10442 Diag(Loc, diag::err_typecheck_invalid_operands)
10443 << OrigLHS.getType() << OrigRHS.getType()
10448 if (OrigLHS.Conversion) {
10449 Diag(OrigLHS.Conversion->getLocation(),
10450 diag::note_typecheck_invalid_operands_converted)
10453 if (OrigRHS.Conversion) {
10455 diag::note_typecheck_invalid_operands_converted)
10470 if (!(LHSNatVec && RHSNatVec)) {
10472 Expr *NonVector = !LHSNatVec ? LHS.
get() : RHS.
get();
10473 Diag(Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
10475 <<
Vector->getSourceRange();
10479 Diag(Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
10502 unsigned &DiagID) {
10508 scalarCast = CK_IntegralToBoolean;
10513 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
10518 scalarCast = CK_IntegralCast;
10523 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
10526 scalarCast = CK_FloatingCast;
10529 scalarCast = CK_IntegralToFloating;
10538 if (scalarCast != CK_NoOp)
10549 assert(VecTy &&
"Expression E must be a vector");
10554 VecTy->getVectorKind());
10558 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(E))
10559 if (ICE->getSubExpr()->getType() == NewVecTy)
10560 return ICE->getSubExpr();
10562 auto Cast = ElementType->
isIntegerType() ? CK_IntegralCast : CK_FloatingCast;
10570 Expr *E = Int->get();
10574 QualType IntTy = Int->get()->getType().getUnqualifiedType();
10580 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.
Context);
10589 unsigned NumBits = IntSigned
10591 :
Result.getActiveBits())
10592 :
Result.getActiveBits();
10599 return (IntSigned != OtherIntSigned &&
10605 return (Order < 0);
10612 if (Int->get()->containsErrors())
10615 QualType IntTy = Int->get()->getType().getUnqualifiedType();
10620 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.
Context);
10632 llvm::APFloat::rmTowardZero);
10635 bool Ignored =
false;
10636 Float.convertToInteger(ConvertBack, llvm::APFloat::rmNearestTiesToEven,
10638 if (
Result != ConvertBack)
10644 unsigned FloatPrec = llvm::APFloat::semanticsPrecision(
10646 if (Bits > FloatPrec)
10659 QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType();
10660 QualType VectorTy =
Vector->get()->getType().getUnqualifiedType();
10665 "ExtVectorTypes should not be handled here!");
10666 VectorEltTy = VT->getElementType();
10671 llvm_unreachable(
"Only Fixed-Length and SVE Vector types are handled here");
10697 ScalarCast = CK_IntegralCast;
10701 ScalarCast = CK_FloatingToIntegral;
10709 llvm::APFloat
Result(0.0);
10715 bool CstScalar = Scalar->get()->isValueDependent() ||
10718 if (!CstScalar && Order < 0)
10724 bool Truncated =
false;
10726 llvm::APFloat::rmNearestTiesToEven, &Truncated);
10731 ScalarCast = CK_FloatingCast;
10736 ScalarCast = CK_IntegralToFloating;
10743 if (ScalarCast != CK_NoOp)
10751 bool AllowBothBool,
10752 bool AllowBoolConversions,
10753 bool AllowBoolOperation,
10754 bool ReportInvalid) {
10755 if (!IsCompAssign) {
10771 assert(LHSVecType || RHSVecType);
10779 (RHSVecType && RHSVecType->getElementType()->isMFloat8Type()))
10784 if (!AllowBothBool && LHSVecType &&
10790 if (!AllowBoolOperation &&
10795 if (
Context.hasSameType(LHSType, RHSType))
10796 return Context.getCommonSugaredType(LHSType, RHSType);
10799 if (LHSVecType && RHSVecType &&
10800 Context.areCompatibleVectorTypes(LHSType, RHSType)) {
10814 if (AllowBoolConversions && LHSVecType && RHSVecType &&
10817 Context.getTypeSize(RHSVecType->getElementType()))) {
10824 if (!IsCompAssign &&
10827 RHSVecType->getElementType()->isIntegerType()) {
10836 unsigned &SVEorRVV) {
10857 if (IsSveRVVConversion(LHSType, RHSType, SVEorRVV) ||
10858 IsSveRVVConversion(RHSType, LHSType, SVEorRVV)) {
10859 Diag(Loc, diag::err_typecheck_sve_rvv_ambiguous)
10860 << SVEorRVV << LHSType << RHSType;
10867 unsigned &SVEorRVV) {
10872 if (FirstVecType && SecondVecType) {
10875 SecondVecType->getVectorKind() ==
10880 SecondVecType->getVectorKind() ==
10882 SecondVecType->getVectorKind() ==
10884 SecondVecType->getVectorKind() ==
10893 if (SecondVecType &&
10906 if (IsSveRVVGnuConversion(LHSType, RHSType, SVEorRVV) ||
10907 IsSveRVVGnuConversion(RHSType, LHSType, SVEorRVV)) {
10908 Diag(Loc, diag::err_typecheck_sve_rvv_gnu_ambiguous)
10909 << SVEorRVV << LHSType << RHSType;
10915 unsigned DiagID = diag::err_typecheck_vector_not_convertable;
10930 LHSType, RHSVecType->getElementType(),
10943 QualType VecType = LHSVecType ? LHSType : RHSType;
10944 const VectorType *VT = LHSVecType ? LHSVecType : RHSVecType;
10945 QualType OtherType = LHSVecType ? RHSType : LHSType;
10946 ExprResult *OtherExpr = LHSVecType ? &RHS : &LHS;
10948 if (
Context.getTargetInfo().getTriple().isPPC() &&
10950 !
Context.areCompatibleVectorTypes(RHSType, LHSType))
10951 Diag(Loc, diag::warn_deprecated_lax_vec_conv_all) << RHSType << LHSType;
10955 if (!IsCompAssign) {
10974 if ((!RHSVecType && !RHSType->
isRealType()) ||
10976 Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10977 << LHSType << RHSType
10989 Diag(Loc, diag::err_opencl_implicit_vector_conversion) << LHSType
11000 QualType Scalar = LHSVecType ? RHSType : LHSType;
11002 unsigned ScalarOrVector = LHSVecType && RHSVecType ? 1 : 0;
11004 diag::err_typecheck_vector_not_convertable_implict_truncation)
11005 << ScalarOrVector << Scalar <<
Vector;
11012 << LHSType << RHSType
11021 if (!IsCompAssign) {
11036 unsigned DiagID = diag::err_typecheck_invalid_operands;
11038 ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
11039 (RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) {
11045 if (
Context.hasSameType(LHSType, RHSType))
11060 Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
11067 Context.getBuiltinVectorTypeInfo(LHSBuiltinTy).EC !=
11068 Context.getBuiltinVectorTypeInfo(RHSBuiltinTy).EC) {
11069 Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
11078 bool ScalarOrVector =
11081 Diag(Loc, diag::err_typecheck_vector_not_convertable_implict_truncation)
11082 << ScalarOrVector << Scalar <<
Vector;
11114 S.
Diag(Loc, diag::warn_null_in_arithmetic_operation)
11126 S.
Diag(Loc, diag::warn_null_in_comparison_operation)
11127 << LHSNull << NonNullType
11139 QualType ElementType = CT->getElementType().getCanonicalType();
11140 bool IsComplexRangePromoted = S.
getLangOpts().getComplexRange() ==
11147 const llvm::fltSemantics &ElementTypeSemantics =
11149 const llvm::fltSemantics &HigherElementTypeSemantics =
11152 if ((llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
11153 llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) ||
11160 if (
Type == HigherElementType) {
11172 const auto *LUE = dyn_cast<UnaryExprOrTypeTraitExpr>(LHS);
11173 const auto *RUE = dyn_cast<UnaryExprOrTypeTraitExpr>(RHS);
11176 if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
11177 RUE->getKind() != UETT_SizeOf)
11184 if (RUE->isArgumentType())
11185 RHSTy = RUE->getArgumentType().getNonReferenceType();
11187 RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
11194 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
11195 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
11196 S.
Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
11200 QualType ArrayElemTy = ArrayTy->getElementType();
11206 S.
Diag(Loc, diag::warn_division_sizeof_array)
11208 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
11209 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
11210 S.
Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
11214 S.
Diag(Loc, diag::note_precedence_silence) << RHS;
11227 S.
PDiag(diag::warn_remainder_division_by_zero)
11236 const Expr *LHSExpr = LHS.
get();
11237 const Expr *RHSExpr = RHS.
get();
11242 if (!LHSIsScoped && !RHSIsScoped)
11254 ->getDefinitionOrSelf()
11255 ->getIntegerType();
11256 std::string InsertionString =
"static_cast<" + IntType.getAsString() +
">(";
11257 S.
Diag(BeginLoc, diag::note_no_implicit_conversion_for_scoped_enum)
11262 DiagnosticHelper(LHSExpr, LHSType);
11265 DiagnosticHelper(RHSExpr, RHSType);
11272 bool IsCompAssign = Opc == BO_MulAssign || Opc == BO_DivAssign;
11273 bool IsDiv = Opc == BO_Div || Opc == BO_DivAssign;
11367 if (compType.
isNull() ||
11372 IsCompAssign ? BO_RemAssign : BO_Rem);
11383 ? diag::err_typecheck_pointer_arith_void_type
11384 : diag::ext_gnu_void_ptr)
11393 ? diag::err_typecheck_pointer_arith_void_type
11394 : diag::ext_gnu_void_ptr)
11395 << 0 <<
Pointer->getSourceRange();
11406 S.
Diag(Loc, diag::warn_gnu_null_ptr_arith)
11407 <<
Pointer->getSourceRange();
11409 S.
Diag(Loc, diag::warn_pointer_arith_null_ptr)
11426 S.
PDiag(diag::warn_pointer_sub_null_ptr)
11428 <<
Pointer->getSourceRange());
11437 ? diag::err_typecheck_pointer_arith_function_type
11438 : diag::ext_gnu_ptr_func_arith)
11450 assert(
Pointer->getType()->isAnyPointerType());
11452 ? diag::err_typecheck_pointer_arith_function_type
11453 : diag::ext_gnu_ptr_func_arith)
11454 << 0 <<
Pointer->getType()->getPointeeType()
11456 <<
Pointer->getSourceRange();
11464 QualType ResType = Operand->getType();
11466 ResType = ResAtomicType->getValueType();
11472 diag::err_typecheck_arithmetic_incomplete_or_sizeless_type,
11473 Operand->getSourceRange());
11486 QualType ResType = Operand->getType();
11488 ResType = ResAtomicType->getValueType();
11520 if (!isLHSPointer && !isRHSPointer)
return true;
11522 QualType LHSPointeeTy, RHSPointeeTy;
11527 if (isLHSPointer && isRHSPointer) {
11531 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
11539 bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->
isVoidType();
11540 bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->
isVoidType();
11541 if (isLHSVoidPtr || isRHSVoidPtr) {
11549 bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->
isFunctionType();
11550 bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->
isFunctionType();
11551 if (isLHSFuncPtr || isRHSFuncPtr) {
11573 Expr* IndexExpr = RHSExpr;
11576 IndexExpr = LHSExpr;
11579 bool IsStringPlusInt = StrExpr &&
11585 Self.Diag(OpLoc, diag::warn_string_plus_int)
11589 if (IndexExpr == RHSExpr) {
11591 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence)
11596 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence);
11602 const Expr *StringRefExpr = LHSExpr;
11607 CharExpr = dyn_cast<CharacterLiteral>(LHSExpr->
IgnoreImpCasts());
11608 StringRefExpr = RHSExpr;
11611 if (!CharExpr || !StringRefExpr)
11631 Self.Diag(OpLoc, diag::warn_string_plus_char)
11632 << DiagRange << Ctx.
CharTy;
11634 Self.Diag(OpLoc, diag::warn_string_plus_char)
11635 << DiagRange << CharExpr->
getType();
11641 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence)
11646 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence);
11655 S.
Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
11674 if (CompLHSTy) *CompLHSTy = compType;
11683 *CompLHSTy = compType;
11692 *CompLHSTy = compType;
11703 if (Opc == BO_Add) {
11710 if (CompLHSTy) *CompLHSTy = compType;
11724 std::swap(PExp, IExp);
11737 if (!IExp->getType()->isIntegerType())
11746 (!IExp->isValueDependent() &&
11747 (!IExp->EvaluateAsInt(KnownVal,
Context) ||
11751 Context, BO_Add, PExp, IExp);
11765 Diag(Loc, diag::err_ptrauth_indirect_goto_addrlabel_arithmetic)
11771 CheckArrayAccess(PExp, IExp);
11777 if (
Context.isPromotableIntegerType(LHSTy))
11778 LHSTy =
Context.getPromotedIntegerType(LHSTy);
11780 *CompLHSTy = LHSTy;
11801 if (CompLHSTy) *CompLHSTy = compType;
11810 *CompLHSTy = compType;
11819 *CompLHSTy = compType;
11833 if (CompLHSTy) *CompLHSTy = compType;
11850 Diag(Loc, diag::err_ptrauth_indirect_goto_addrlabel_arithmetic)
11876 CheckArrayAccess(LHS.
get(), RHS.
get(),
nullptr,
11879 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11890 if (!
Context.hasSameUnqualifiedType(lpointee, rpointee)) {
11895 if (!
Context.typesAreCompatible(
11896 Context.getCanonicalType(lpointee).getUnqualifiedType(),
11897 Context.getCanonicalType(rpointee).getUnqualifiedType())) {
11923 if (ElementSize.
isZero()) {
11924 Diag(Loc,diag::warn_sub_ptr_zero_size_types)
11930 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11931 return Context.getPointerDiffType();
11941 if (
const EnumType *ET =
T->getAsCanonical<EnumType>())
11942 return ET->getDecl()->isScoped();
11954 if (Opc == BO_Shr &&
11963 llvm::APSInt Right = RHSResult.
Val.
getInt();
11965 if (Right.isNegative()) {
11967 S.
PDiag(diag::warn_shift_negative)
11978 LeftSize = FXSema.getWidth() - (
unsigned)FXSema.hasUnsignedPadding();
11980 if (Right.uge(LeftSize)) {
11982 S.
PDiag(diag::warn_shift_gt_typewidth)
12002 llvm::APSInt Left = LHSResult.
Val.
getInt();
12013 if (Left.isNegative()) {
12015 S.
PDiag(diag::warn_shift_lhs_negative)
12020 llvm::APInt ResultBits =
12021 static_cast<llvm::APInt &
>(Right) + Left.getSignificantBits();
12022 if (ResultBits.ule(LeftSize))
12024 llvm::APSInt
Result = Left.extend(ResultBits.getLimitedValue());
12030 Result.toString(HexResult, 16,
false,
true);
12036 if (ResultBits - 1 == LeftSize) {
12037 S.
Diag(Loc, diag::warn_shift_result_sets_sign_bit)
12038 << HexResult << LHSType
12043 S.
Diag(Loc, diag::warn_shift_result_gt_typewidth)
12044 << HexResult.str() <<
Result.getSignificantBits() << LHSType
12056 S.
Diag(Loc, diag::err_shift_rhs_only_vector)
12062 if (!IsCompAssign) {
12084 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
12091 if (!LHSEleType->isIntegerType()) {
12092 S.
Diag(Loc, diag::err_typecheck_expect_int)
12097 if (!RHSEleType->isIntegerType()) {
12098 S.
Diag(Loc, diag::err_typecheck_expect_int)
12107 if (LHSEleType != RHSEleType) {
12109 LHSEleType = RHSEleType;
12115 }
else if (RHSVecTy) {
12120 S.
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
12128 if (LHSBT != RHSBT &&
12130 S.
Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal)
12147 bool IsCompAssign) {
12148 if (!IsCompAssign) {
12171 if ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
12172 (RHSBuiltinTy && RHSBuiltinTy->
isSVEBool())) {
12173 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
12178 if (!LHSEleType->isIntegerType()) {
12179 S.
Diag(Loc, diag::err_typecheck_expect_int)
12184 if (!RHSEleType->isIntegerType()) {
12185 S.
Diag(Loc, diag::err_typecheck_expect_int)
12193 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
12203 if (LHSEleType != RHSEleType) {
12205 LHSEleType = RHSEleType;
12207 const llvm::ElementCount VecSize =
12216 S.
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
12222 const llvm::ElementCount VecSize =
12224 if (LHSEleType != RHSEleType) {
12226 RHSEleType = LHSEleType;
12239 bool IsCompAssign) {
12273 if (IsCompAssign) LHS = OldLHS;
12301 S.
Diag(Loc, IsError ? diag::err_typecheck_comparison_of_distinct_pointers
12302 : diag::ext_typecheck_comparison_of_distinct_pointers)
12342 S.
Diag(Loc, IsError ? diag::err_typecheck_comparison_of_fptr_to_void
12343 : diag::ext_typecheck_comparison_of_fptr_to_void)
12350 case Stmt::ObjCArrayLiteralClass:
12351 case Stmt::ObjCDictionaryLiteralClass:
12352 case Stmt::ObjCStringLiteralClass:
12353 case Stmt::ObjCBoxedExprClass:
12397 QualType T = Method->parameters()[0]->getType();
12398 if (!
T->isObjCObjectPointerType())
12401 QualType R = Method->getReturnType();
12402 if (!R->isScalarType())
12414 Literal = LHS.
get();
12417 Literal = RHS.
get();
12433 llvm_unreachable(
"Unknown Objective-C object literal kind");
12437 S.
Diag(Loc, diag::warn_objc_string_literal_comparison)
12438 << Literal->getSourceRange();
12440 S.
Diag(Loc, diag::warn_objc_literal_comparison)
12441 << LiteralKind << Literal->getSourceRange();
12450 S.
Diag(Loc, diag::note_objc_literal_comparison_isequal)
12463 if (!UO || UO->
getOpcode() != UO_LNot)
return;
12473 bool IsBitwiseOp = Opc == BO_And || Opc == BO_Or || Opc == BO_Xor;
12475 << Loc << IsBitwiseOp;
12502 if (
const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) {
12504 }
else if (
const MemberExpr *Mem = dyn_cast<MemberExpr>(E)) {
12505 if (Mem->isImplicitAccess())
12506 D = Mem->getMemberDecl();
12521 return std::nullopt;
12529 std::swap(LHS, RHS);
12533 std::swap(LHS, RHS);
12537 return std::nullopt;
12540 auto *BO = dyn_cast<BinaryOperator>(LHS);
12541 if (!BO || BO->getOpcode() != BO_Add)
12542 return std::nullopt;
12546 Other = BO->getRHS();
12548 Other = BO->getLHS();
12550 return std::nullopt;
12552 if (!
Other->getType()->isUnsignedIntegerType())
12553 return std::nullopt;
12555 return Opc == BO_GE;
12609 auto IsDeprArrayComparionIgnored =
12612 ? diag::warn_array_comparison_cxx26
12613 : !S.
getLangOpts().CPlusPlus20 || IsDeprArrayComparionIgnored
12614 ? diag::warn_array_comparison
12615 : diag::warn_depr_array_comparison;
12641 Result = AlwaysConstant;
12645 S.
PDiag(diag::warn_comparison_always)
12660 Result = AlwaysConstant;
12664 S.
PDiag(diag::warn_comparison_always)
12667 }
else if (std::optional<bool> Res =
12670 S.
PDiag(diag::warn_comparison_always)
12672 << (*Res ? AlwaysTrue : AlwaysFalse));
12683 Expr *LiteralString =
nullptr;
12684 Expr *LiteralStringStripped =
nullptr;
12688 LiteralString = LHS;
12689 LiteralStringStripped = LHSStripped;
12694 LiteralString = RHS;
12695 LiteralStringStripped = RHSStripped;
12698 if (LiteralString) {
12700 S.
PDiag(diag::warn_stringcompare)
12713 llvm_unreachable(
"unhandled cast kind");
12715 case CK_UserDefinedConversion:
12717 case CK_LValueToRValue:
12719 case CK_ArrayToPointerDecay:
12721 case CK_FunctionToPointerDecay:
12723 case CK_IntegralCast:
12725 case CK_FloatingCast:
12727 case CK_IntegralToFloating:
12728 case CK_FloatingToIntegral:
12730 case CK_IntegralComplexCast:
12731 case CK_FloatingComplexCast:
12732 case CK_FloatingComplexToIntegralComplex:
12733 case CK_IntegralComplexToFloatingComplex:
12735 case CK_FloatingComplexToReal:
12736 case CK_FloatingRealToComplex:
12737 case CK_IntegralComplexToReal:
12738 case CK_IntegralRealToComplex:
12740 case CK_HLSLArrayRValue:
12753 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E))
12780 << 0 << FromType << ToType;
12785 llvm_unreachable(
"unhandled case in switch");
12812 if (NumEnumArgs == 1) {
12814 QualType OtherTy = LHSIsEnum ? RHSStrippedType : LHSStrippedType;
12820 if (NumEnumArgs == 2) {
12829 assert(IntType->isArithmeticType());
12839 LHSType = RHSType = IntType;
12848 if (
Type.isNull()) {
12854 std::optional<ComparisonCategoryType> CCT =
12866 assert(!
Type.isNull() &&
"composite type for <=> has not been set");
12884 if (
Type.isNull()) {
12905 int NullValue =
PP.isMacroDefined(
"NULL") ? 0 : 1;
12910 if (
const auto *
CL = dyn_cast<CharacterLiteral>(E.
get())) {
12911 if (
CL->getValue() == 0)
12915 NullValue ?
"NULL" :
"(void *)0");
12916 }
else if (
const auto *CE = dyn_cast<CStyleCastExpr>(E.
get())) {
12923 NullValue ?
"NULL" :
"(void *)0");
12933 bool IsThreeWay = Opc == BO_Cmp;
12934 bool IsOrdered = IsRelational || IsThreeWay;
12945 if (!IsThreeWay || IsAnyPointerType(LHS) || IsAnyPointerType(RHS)) {
12998 auto computeResultTy = [&]() {
13007 std::optional<ComparisonCategoryType> CCT =
13012 if (CompositeTy->
isPointerType() && LHSIsNull != RHSIsNull) {
13016 Diag(Loc, diag::err_typecheck_three_way_comparison_of_pointer_and_zero)
13017 << (LHSIsNull ? LHS.
get()->getSourceRange()
13026 if (!IsOrdered && LHSIsNull != RHSIsNull) {
13027 bool IsEquality = Opc == BO_EQ;
13039 bool IsError = Opc == BO_Cmp;
13041 IsError ? diag::err_typecheck_ordered_comparison_of_function_pointers
13043 ? diag::warn_typecheck_ordered_comparison_of_function_pointers
13044 : diag::ext_typecheck_ordered_comparison_of_function_pointers;
13073 return computeResultTy();
13089 (IsOrdered ? 2 : 1) &&
13094 return computeResultTy();
13108 if (IsRelational) {
13113 Diag(Loc, diag::ext_typecheck_compare_complete_incomplete_pointers)
13119 }
else if (!IsRelational &&
13123 && !LHSIsNull && !RHSIsNull)
13130 if (LCanPointeeTy != RCanPointeeTy) {
13136 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
13137 << LHSType << RHSType << 0
13143 CastKind Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion
13149 bool RHSHasCFIUncheckedCallee = RFn && RFn->getCFIUncheckedCalleeAttr();
13150 bool ChangingCFIUncheckedCallee =
13151 LHSHasCFIUncheckedCallee != RHSHasCFIUncheckedCallee;
13153 if (LHSIsNull && !RHSIsNull)
13155 else if (!ChangingCFIUncheckedCallee)
13158 return computeResultTy();
13170 if (!IsOrdered && LHSIsNull && RHSIsNull) {
13173 return computeResultTy();
13177 return computeResultTy();
13188 return computeResultTy();
13192 return computeResultTy();
13201 return computeResultTy();
13206 return computeResultTy();
13210 if (IsRelational &&
13221 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
13222 if (CTSD->isInStdNamespace() &&
13223 llvm::StringSwitch<bool>(CTSD->getName())
13224 .Cases({
"less",
"less_equal",
"greater",
"greater_equal"},
true)
13230 return computeResultTy();
13243 return computeResultTy();
13253 if (!LHSIsNull && !RHSIsNull &&
13254 !
Context.typesAreCompatible(lpointee, rpointee)) {
13255 Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
13260 return computeResultTy();
13267 if (!LHSIsNull && !RHSIsNull) {
13272 Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
13276 if (LHSIsNull && !RHSIsNull)
13279 : CK_AnyPointerToBlockPointerCast);
13283 : CK_AnyPointerToBlockPointerCast);
13284 return computeResultTy();
13293 bool RPtrToVoid = RPT ? RPT->getPointeeType()->isVoidType() :
false;
13295 if (!LPtrToVoid && !RPtrToVoid &&
13296 !
Context.typesAreCompatible(LHSType, RHSType)) {
13303 if (LHSIsNull && !RHSIsNull) {
13309 RPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
13319 LPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
13321 return computeResultTy();
13325 if (!
Context.areComparableObjCPointerTypes(LHSType, RHSType))
13331 if (LHSIsNull && !RHSIsNull)
13335 return computeResultTy();
13341 CK_BlockPointerToObjCPointerCast);
13342 return computeResultTy();
13343 }
else if (!IsOrdered &&
13347 CK_BlockPointerToObjCPointerCast);
13348 return computeResultTy();
13353 unsigned DiagID = 0;
13354 bool isError =
false;
13363 isError ? diag::err_typecheck_ordered_comparison_of_pointer_and_zero
13364 : diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
13367 DiagID = diag::err_typecheck_comparison_of_pointer_integer;
13369 }
else if (IsOrdered)
13370 DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
13372 DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
13384 LHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
13387 RHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
13388 return computeResultTy();
13392 if (!IsOrdered && RHSIsNull
13395 return computeResultTy();
13397 if (!IsOrdered && LHSIsNull
13400 return computeResultTy();
13403 if (
getLangOpts().getOpenCLCompatibleVersion() >= 200) {
13405 return computeResultTy();
13409 return computeResultTy();
13412 if (LHSIsNull && RHSType->
isQueueT()) {
13414 return computeResultTy();
13417 if (LHSType->
isQueueT() && RHSIsNull) {
13419 return computeResultTy();
13444 "Unhandled vector element size in vector compare");
13464 "Unhandled vector element size in vector compare");
13474 const auto TypeSize =
Context.getTypeSize(ETy);
13476 const QualType IntTy =
Context.getIntTypeForBitwidth(TypeSize,
true);
13477 const llvm::ElementCount VecSize =
Context.getBuiltinVectorTypeInfo(VTy).EC;
13478 return Context.getScalableVectorType(IntTy, VecSize.getKnownMinValue());
13484 if (Opc == BO_Cmp) {
13485 Diag(Loc, diag::err_three_way_vector_comparison);
13514 return Context.getLogicalOperationType();
13516 Diag(Loc, diag::warn_deprecated_altivec_src_compat);
13522 return Context.getLogicalOperationType();
13546 if (Opc == BO_Cmp) {
13547 Diag(Loc, diag::err_three_way_vector_comparison);
13575 if (LHSBuiltinTy && RHSBuiltinTy && LHSBuiltinTy->
isSVEBool() &&
13576 RHSBuiltinTy->isSVEBool())
13595 bool Negative =
false;
13596 bool ExplicitPlus =
false;
13597 const auto *LHSInt = dyn_cast<IntegerLiteral>(XorLHS.
get());
13598 const auto *RHSInt = dyn_cast<IntegerLiteral>(XorRHS.
get());
13604 if (
const auto *UO = dyn_cast<UnaryOperator>(XorRHS.
get())) {
13606 if (Opc != UO_Minus && Opc != UO_Plus)
13608 RHSInt = dyn_cast<IntegerLiteral>(UO->getSubExpr());
13611 Negative = (Opc == UO_Minus);
13612 ExplicitPlus = !Negative;
13618 const llvm::APInt &LeftSideValue = LHSInt->getValue();
13619 llvm::APInt RightSideValue = RHSInt->getValue();
13620 if (LeftSideValue != 2 && LeftSideValue != 10)
13623 if (LeftSideValue.getBitWidth() != RightSideValue.getBitWidth())
13628 llvm::StringRef ExprStr =
13633 llvm::StringRef XorStr =
13636 if (XorStr ==
"xor")
13647 RightSideValue = -RightSideValue;
13648 RHSStr =
"-" + RHSStr;
13649 }
else if (ExplicitPlus) {
13650 RHSStr =
"+" + RHSStr;
13653 StringRef LHSStrRef = LHSStr;
13654 StringRef RHSStrRef = RHSStr;
13657 if (LHSStrRef.starts_with(
"0b") || LHSStrRef.starts_with(
"0B") ||
13658 RHSStrRef.starts_with(
"0b") || RHSStrRef.starts_with(
"0B") ||
13659 LHSStrRef.starts_with(
"0x") || LHSStrRef.starts_with(
"0X") ||
13660 RHSStrRef.starts_with(
"0x") || RHSStrRef.starts_with(
"0X") ||
13661 (LHSStrRef.size() > 1 && LHSStrRef.starts_with(
"0")) ||
13662 (RHSStrRef.size() > 1 && RHSStrRef.starts_with(
"0")) ||
13663 LHSStrRef.contains(
'\'') || RHSStrRef.contains(
'\''))
13668 const llvm::APInt XorValue = LeftSideValue ^ RightSideValue;
13669 int64_t RightSideIntValue = RightSideValue.getSExtValue();
13670 if (LeftSideValue == 2 && RightSideIntValue >= 0) {
13671 std::string SuggestedExpr =
"1 << " + RHSStr;
13672 bool Overflow =
false;
13673 llvm::APInt One = (LeftSideValue - 1);
13674 llvm::APInt PowValue = One.sshl_ov(RightSideValue, Overflow);
13676 if (RightSideIntValue < 64)
13677 S.
Diag(Loc, diag::warn_xor_used_as_pow_base)
13678 << ExprStr <<
toString(XorValue, 10,
true) << (
"1LL << " + RHSStr)
13680 else if (RightSideIntValue == 64)
13681 S.
Diag(Loc, diag::warn_xor_used_as_pow)
13682 << ExprStr <<
toString(XorValue, 10,
true);
13686 S.
Diag(Loc, diag::warn_xor_used_as_pow_base_extra)
13687 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedExpr
13690 ExprRange, (RightSideIntValue == 0) ?
"1" : SuggestedExpr);
13693 S.
Diag(Loc, diag::note_xor_used_as_pow_silence)
13694 << (
"0x2 ^ " + RHSStr) << SuggestXor;
13695 }
else if (LeftSideValue == 10) {
13696 std::string SuggestedValue =
"1e" + std::to_string(RightSideIntValue);
13697 S.
Diag(Loc, diag::warn_xor_used_as_pow_base)
13698 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedValue
13700 S.
Diag(Loc, diag::note_xor_used_as_pow_silence)
13701 << (
"0xA ^ " + RHSStr) << SuggestXor;
13718 getLangOpts().getOpenCLCompatibleVersion() < 120 &&
13745 assert(
false &&
"Logical operands are not supported in C\\C++");
13761 bool IsCompAssign) {
13762 if (!IsCompAssign) {
13778 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13780 if (
Context.hasSameType(LHSType, RHSType))
13781 return Context.getCommonSugaredType(LHSType, RHSType);
13787 if (LHSMatType && !RHSMatType) {
13795 if (!LHSMatType && RHSMatType) {
13807 bool IsCompAssign) {
13808 if (!IsCompAssign) {
13819 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13821 if (LHSMatType && RHSMatType) {
13822 if (LHSMatType->getNumColumns() != RHSMatType->
getNumRows())
13825 if (
Context.hasSameType(LHSMatType, RHSMatType))
13826 return Context.getCommonSugaredType(
13830 QualType LHSELTy = LHSMatType->getElementType(),
13832 if (!
Context.hasSameType(LHSELTy, RHSELTy))
13835 return Context.getConstantMatrixType(
13836 Context.getCommonSugaredType(LHSELTy, RHSELTy),
13861 bool IsCompAssign =
13862 Opc == BO_AndAssign || Opc == BO_OrAssign || Opc == BO_XorAssign;
13873 LegalBoolVecOperator,
13903 ExprResult LHSResult = LHS, RHSResult = RHS;
13905 LHSResult, RHSResult, Loc,
13907 if (LHSResult.
isInvalid() || RHSResult.isInvalid())
13909 LHS = LHSResult.
get();
13910 RHS = RHSResult.
get();
13935 bool EnumConstantInBoolContext =
false;
13937 if (
const auto *DREHS = dyn_cast<DeclRefExpr>(HS.get())) {
13938 const auto *ECDHS = dyn_cast<EnumConstantDecl>(DREHS->getDecl());
13939 if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1)
13940 EnumConstantInBoolContext =
true;
13944 if (EnumConstantInBoolContext)
13945 Diag(Loc, diag::warn_enum_constant_in_bool_context);
13950 const auto *LHSATy = dyn_cast<ArrayType>(LHSTy);
13951 const auto *RHSATy = dyn_cast<ArrayType>(RHSTy);
13952 if ((LHSATy && LHSATy->getElementType().isWebAssemblyReferenceType()) ||
13953 (RHSATy && RHSATy->getElementType().isWebAssemblyReferenceType())) {
13975 Diag(Loc, diag::warn_logical_instead_of_bitwise)
13978 Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
13979 << (Opc == BO_LAnd ?
"&" :
"|")
13982 Opc == BO_LAnd ?
"&" :
"|");
13983 if (Opc == BO_LAnd)
13985 Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
13993 if (!
Context.getLangOpts().CPlusPlus) {
13996 if (
Context.getLangOpts().OpenCL &&
13997 Context.getLangOpts().OpenCLVersion < 120) {
14052 const MemberExpr *ME = dyn_cast<MemberExpr>(E);
14053 if (!ME)
return false;
14057 if (!
Base)
return false;
14058 return Base->getMethodDecl() !=
nullptr;
14082 assert(S.
getLangOpts().CPlusPlus &&
"BindingDecl outside of C++?");
14093 assert(Var->
hasLocalStorage() &&
"capture added 'const' to non-local?");
14101 if (
auto *FD = dyn_cast<FunctionDecl>(DC))
14143 bool DiagnosticEmitted =
false;
14147 bool IsDereference =
false;
14148 bool NextIsDereference =
false;
14152 IsDereference = NextIsDereference;
14155 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
14156 NextIsDereference = ME->isArrow();
14157 const ValueDecl *VD = ME->getMemberDecl();
14158 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(VD)) {
14160 if (Field->isMutable()) {
14161 assert(DiagnosticEmitted &&
"Expected diagnostic not emitted.");
14166 if (!DiagnosticEmitted) {
14167 S.
Diag(Loc, diag::err_typecheck_assign_const)
14169 << Field->getType();
14170 DiagnosticEmitted =
true;
14173 <<
ConstMember <<
false << Field << Field->getType()
14174 << Field->getSourceRange();
14178 }
else if (
const VarDecl *VDecl = dyn_cast<VarDecl>(VD)) {
14179 if (VDecl->getType().isConstQualified()) {
14180 if (!DiagnosticEmitted) {
14181 S.
Diag(Loc, diag::err_typecheck_assign_const)
14183 << VDecl->getType();
14184 DiagnosticEmitted =
true;
14187 <<
ConstMember <<
true << VDecl << VDecl->getType()
14188 << VDecl->getSourceRange();
14195 dyn_cast<ArraySubscriptExpr>(E)) {
14199 dyn_cast<ExtVectorElementExpr>(E)) {
14206 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
14210 if (!DiagnosticEmitted) {
14211 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange
14213 DiagnosticEmitted =
true;
14216 diag::note_typecheck_assign_const)
14220 }
else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
14222 if (
const ValueDecl *VD = DRE->getDecl()) {
14224 if (!DiagnosticEmitted) {
14225 S.
Diag(Loc, diag::err_typecheck_assign_const)
14227 DiagnosticEmitted =
true;
14229 S.
Diag(VD->getLocation(), diag::note_typecheck_assign_const)
14230 <<
ConstVariable << VD << VD->getType() << VD->getSourceRange();
14235 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) {
14236 if (MD->isConst()) {
14237 if (!DiagnosticEmitted) {
14238 S.
Diag(Loc, diag::err_typecheck_assign_const_method)
14239 << ExprRange << MD;
14240 DiagnosticEmitted =
true;
14242 S.
Diag(MD->getLocation(), diag::note_typecheck_assign_const_method)
14243 << MD << MD->getSourceRange();
14249 if (DiagnosticEmitted)
14253 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange <<
ConstUnknown;
14263 const RecordType *Ty,
14266 bool &DiagnosticEmitted) {
14267 std::vector<const RecordType *> RecordTypeList;
14268 RecordTypeList.push_back(Ty);
14269 unsigned NextToCheckIndex = 0;
14272 while (RecordTypeList.size() > NextToCheckIndex) {
14273 bool IsNested = NextToCheckIndex > 0;
14274 for (
const FieldDecl *Field : RecordTypeList[NextToCheckIndex]
14276 ->getDefinitionOrSelf()
14279 QualType FieldTy = Field->getType();
14281 if (!DiagnosticEmitted) {
14282 S.
Diag(Loc, diag::err_typecheck_assign_const)
14284 << IsNested << Field;
14285 DiagnosticEmitted =
true;
14287 S.
Diag(Field->getLocation(), diag::note_typecheck_assign_const)
14289 << FieldTy << Field->getSourceRange();
14294 if (
const auto *FieldRecTy = FieldTy->
getAsCanonical<RecordType>()) {
14295 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
14296 RecordTypeList.push_back(FieldRecTy);
14299 ++NextToCheckIndex;
14308 assert(Ty->
isRecordType() &&
"lvalue was not record?");
14311 bool DiagEmitted =
false;
14313 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(E))
14316 else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
14341 unsigned DiagID = 0;
14342 bool NeedType =
false;
14349 DiagID = diag::err_block_decl_ref_not_modifiable_lvalue;
14351 DiagID = diag::err_lambda_decl_ref_not_modifiable_lvalue;
14364 if (var->isARCPseudoStrong() &&
14365 (!var->getTypeSourceInfo() ||
14366 !var->getTypeSourceInfo()->getType().isConstQualified())) {
14372 ? diag::err_typecheck_arc_assign_self_class_method
14373 : diag::err_typecheck_arc_assign_self;
14376 }
else if (var->hasAttr<ObjCExternallyRetainedAttr>() ||
14378 DiagID = diag::err_typecheck_arc_assign_externally_retained;
14382 DiagID = diag::err_typecheck_arr_assign_enumeration;
14386 if (Loc != OrigLoc)
14412 DiagID = diag::err_typecheck_array_not_modifiable_lvalue;
14416 DiagID = diag::err_typecheck_non_object_not_modifiable_lvalue;
14420 DiagID = diag::err_typecheck_lvalue_casts_not_supported;
14423 llvm_unreachable(
"did not take early return for MLV_Valid");
14427 DiagID = diag::err_typecheck_expression_not_modifiable_lvalue;
14432 diag::err_typecheck_incomplete_type_not_modifiable_lvalue, E);
14434 DiagID = diag::err_typecheck_duplicate_vector_components_not_mlvalue;
14437 DiagID = diag::err_typecheck_duplicate_matrix_components_not_mlvalue;
14440 llvm_unreachable(
"readonly properties should be processed differently");
14442 DiagID = diag::err_readonly_message_assignment;
14445 DiagID = diag::err_no_subobject_property_setting;
14450 if (Loc != OrigLoc)
14472 MemberExpr *ML = dyn_cast<MemberExpr>(LHSExpr);
14473 MemberExpr *MR = dyn_cast<MemberExpr>(RHSExpr);
14481 if (LHSDecl != RHSDecl)
14486 if (RefTy->getPointeeType().isVolatileQualified())
14489 Sema.
Diag(Loc, diag::warn_identity_field_assign) << 0;
14499 Sema.
Diag(Loc, diag::warn_identity_field_assign) << 1;
14523 bool ShowFullyQualifiedAssigneeName =
false;
14526 Assignee = DR->getDecl();
14527 }
else if (
auto *ME = dyn_cast<MemberExpr>(LHSExpr->
IgnoreParenCasts())) {
14528 Assignee = ME->getMemberDecl();
14529 ShowFullyQualifiedAssigneeName =
true;
14534 ShowFullyQualifiedAssigneeName);
14543 Diag(Loc, diag::err_opencl_half_load_store) << 1
14550 Diag(Loc, diag::err_wasm_table_art) << 0;
14555 if (CompoundType.
isNull()) {
14566 ((
Context.isObjCNSObjectType(LHSType) &&
14568 (
Context.isObjCNSObjectType(RHSType) &&
14573 Diag(Loc, diag::err_objc_object_assignment) << LHSType;
14579 RHSCheck = ICE->getSubExpr();
14580 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(RHSCheck)) {
14581 if ((UO->getOpcode() == UO_Plus || UO->getOpcode() == UO_Minus) &&
14582 Loc.
isFileID() && UO->getOperatorLoc().isFileID() &&
14588 UO->getSubExpr()->getBeginLoc().
isFileID()) {
14589 Diag(Loc, diag::warn_not_compound_assign)
14590 << (UO->getOpcode() == UO_Plus ?
"+" :
"-")
14591 <<
SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc());
14601 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InnerLHS);
14617 if (!
Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
14640 if (CompoundType.
isNull()) {
14666 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
14667 if (CE->getCastKind() == CK_ToVoid) {
14673 CE->getSubExpr()->getType()->isDependentType()) {
14678 if (
const auto *CE = dyn_cast<CallExpr>(E))
14679 return CE->getCallReturnType(Context)->isVoidType();
14703 while (
const BinaryOperator *BO = dyn_cast<BinaryOperator>(LHS)) {
14704 if (BO->getOpcode() != BO_Comma)
14706 LHS = BO->getRHS();
14713 Diag(Loc, diag::warn_comma_operator);
14717 LangOpts.CPlusPlus ?
"static_cast<void>("
14749 diag::err_incomplete_type);
14770 ResType = ResAtomicType->getValueType();
14772 assert(!ResType.
isNull() &&
"no type for increment/decrement expression");
14782 : diag::warn_increment_bool)
14786 S.
Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType;
14804 S.
DiagCompat(OpLoc, diag_compat::increment_complex)
14821 S.
Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
14832 S.
Diag(OpLoc, diag::warn_deprecated_increment_decrement_volatile)
14833 << IsInc << ResType;
14865 case Stmt::DeclRefExprClass:
14867 case Stmt::MemberExprClass:
14875 case Stmt::ArraySubscriptExprClass: {
14880 if (ICE->getSubExpr()->getType()->isArrayType())
14885 case Stmt::UnaryOperatorClass: {
14897 case Stmt::ParenExprClass:
14899 case Stmt::ImplicitCastExprClass:
14903 case Stmt::CXXUuidofExprClass:
14913 AO_Vector_Element = 1,
14914 AO_Property_Expansion = 2,
14915 AO_Register_Variable = 3,
14916 AO_Matrix_Element = 4,
14934 return Diag(OpLoc, diag::err_parens_pointer_member_function)
14939 return Diag(OpLoc, diag::err_typecheck_addrof_dtor)
14940 << DRE->getSourceRange();
14942 if (DRE->getQualifier())
14946 return Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14947 << DRE->getSourceRange();
14950 StringRef Qual = (MD->
getParent()->getName() +
"::").toStringRef(Str);
14951 return Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14952 << DRE->getSourceRange()
14958 if (PTy->getKind() == BuiltinType::Overload) {
14962 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof_addrof_function)
14970 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14978 if (PTy->getKind() == BuiltinType::UnknownAny)
14981 if (PTy->getKind() == BuiltinType::BoundMember) {
14982 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
15005 auto* VarRef = dyn_cast<DeclRefExpr>(op);
15006 if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
15007 Diag(op->
getExprLoc(), diag::err_opencl_taking_address_capture);
15015 if (uOp->getOpcode() == UO_Deref)
15018 return uOp->getSubExpr()->getType();
15025 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(dcl))
15031 unsigned AddressOfError = AO_No_Error;
15035 Diag(OpLoc, IsError ? diag::err_typecheck_addrof_temporary
15036 : diag::ext_typecheck_addrof_temporary)
15051 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
15069 auto ReturnOrParamTypeIsIncomplete = [&](
QualType T,
15074 diag::note_ptrauth_virtual_function_pointer_incomplete_arg_ret);
15075 Diag(RetArgTypeLoc,
15076 diag::note_ptrauth_virtual_function_incomplete_arg_ret_type)
15083 bool IsIncomplete =
15085 ReturnOrParamTypeIsIncomplete(
15088 IsIncomplete |= ReturnOrParamTypeIsIncomplete(PVD->getType(), OpLoc,
15089 PVD->getBeginLoc());
15095 if (
Context.getTargetInfo().getCXXABI().isMicrosoft())
15104 AddressOfError = AO_Property_Expansion;
15106 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof)
15110 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(op)) {
15111 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl()))
15117 AddressOfError = AO_Bit_Field;
15120 AddressOfError = AO_Vector_Element;
15123 AddressOfError = AO_Matrix_Element;
15127 if (
const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
15132 AddressOfError = AO_Register_Variable;
15135 AddressOfError = AO_Property_Expansion;
15148 if (
auto *DRE = dyn_cast<DeclRefExpr>(op);
15154 diag::err_cannot_form_pointer_to_member_of_reference_type)
15165 if (
Context.getTargetInfo().getCXXABI().isMicrosoft())
15173 llvm_unreachable(
"Unknown/unexpected decl type");
15176 if (AddressOfError != AO_No_Error) {
15193 if (
Context.getTargetInfo().getTriple().isWasm()) {
15196 Diag(OpLoc, diag::err_wasm_ca_reference)
15201 Diag(OpLoc, diag::err_wasm_table_pr)
15207 CheckAddressOfPackedMember(op);
15213 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Exp);
15219 const ParmVarDecl *Param = dyn_cast<ParmVarDecl>(D);
15222 if (
const FunctionDecl* FD = dyn_cast<FunctionDecl>(Param->getDeclContext()))
15223 if (!FD->hasAttr<NonNullAttr>() && !Param->hasAttr<NonNullAttr>())
15226 FD->ModifiedNonNullParams.insert(Param);
15232 bool IsAfterAmp =
false) {
15236 Op = ConvResult.
get();
15248 Result = PT->getPointeeType();
15252 Result = OPT->getPointeeType();
15256 if (PR.
get() != Op)
15261 S.
Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer)
15266 if (
Result->isVoidType()) {
15272 S.
Diag(OpLoc, diag::err_typecheck_indirection_through_void_pointer_cpp)
15275 S.
Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
15292 default: llvm_unreachable(
"Unknown binop!");
15293 case tok::periodstar: Opc = BO_PtrMemD;
break;
15294 case tok::arrowstar: Opc = BO_PtrMemI;
break;
15295 case tok::star: Opc = BO_Mul;
break;
15296 case tok::slash: Opc = BO_Div;
break;
15297 case tok::percent: Opc = BO_Rem;
break;
15298 case tok::plus: Opc = BO_Add;
break;
15299 case tok::minus: Opc = BO_Sub;
break;
15300 case tok::lessless: Opc = BO_Shl;
break;
15301 case tok::greatergreater: Opc = BO_Shr;
break;
15302 case tok::lessequal: Opc = BO_LE;
break;
15303 case tok::less: Opc = BO_LT;
break;
15304 case tok::greaterequal: Opc = BO_GE;
break;
15305 case tok::greater: Opc = BO_GT;
break;
15306 case tok::exclaimequal: Opc = BO_NE;
break;
15307 case tok::equalequal: Opc = BO_EQ;
break;
15308 case tok::spaceship: Opc = BO_Cmp;
break;
15309 case tok::amp: Opc = BO_And;
break;
15310 case tok::caret: Opc = BO_Xor;
break;
15311 case tok::pipe: Opc = BO_Or;
break;
15312 case tok::ampamp: Opc = BO_LAnd;
break;
15313 case tok::pipepipe: Opc = BO_LOr;
break;
15314 case tok::equal: Opc = BO_Assign;
break;
15315 case tok::starequal: Opc = BO_MulAssign;
break;
15316 case tok::slashequal: Opc = BO_DivAssign;
break;
15317 case tok::percentequal: Opc = BO_RemAssign;
break;
15318 case tok::plusequal: Opc = BO_AddAssign;
break;
15319 case tok::minusequal: Opc = BO_SubAssign;
break;
15320 case tok::lesslessequal: Opc = BO_ShlAssign;
break;
15321 case tok::greatergreaterequal: Opc = BO_ShrAssign;
break;
15322 case tok::ampequal: Opc = BO_AndAssign;
break;
15323 case tok::caretequal: Opc = BO_XorAssign;
break;
15324 case tok::pipeequal: Opc = BO_OrAssign;
break;
15325 case tok::comma: Opc = BO_Comma;
break;
15334 default: llvm_unreachable(
"Unknown unary op!");
15335 case tok::plusplus: Opc = UO_PreInc;
break;
15336 case tok::minusminus: Opc = UO_PreDec;
break;
15337 case tok::amp: Opc = UO_AddrOf;
break;
15338 case tok::star: Opc = UO_Deref;
break;
15339 case tok::plus: Opc = UO_Plus;
break;
15340 case tok::minus: Opc = UO_Minus;
break;
15341 case tok::tilde: Opc = UO_Not;
break;
15342 case tok::exclaim: Opc = UO_LNot;
break;
15343 case tok::kw___real: Opc = UO_Real;
break;
15344 case tok::kw___imag: Opc = UO_Imag;
break;
15345 case tok::kw___extension__: Opc = UO_Extension;
break;
15377 llvm::find_if(Parent->
fields(),
15379 return F->getDeclName() == Name;
15381 return (Field != Parent->
field_end()) ? *Field :
nullptr;
15396 const DeclRefExpr *LHSDeclRef = dyn_cast<DeclRefExpr>(LHSExpr);
15397 const DeclRefExpr *RHSDeclRef = dyn_cast<DeclRefExpr>(RHSExpr);
15398 if (!LHSDeclRef || !RHSDeclRef ||
15406 if (LHSDecl != RHSDecl)
15411 if (RefTy->getPointeeType().isVolatileQualified())
15414 auto Diag = S.
Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
15415 : diag::warn_self_assignment_overloaded)
15420 Diag << 1 << SelfAssignField
15433 const Expr *ObjCPointerExpr =
nullptr, *OtherExpr =
nullptr;
15435 const Expr *RHS = R.get();
15438 ObjCPointerExpr = LHS;
15442 ObjCPointerExpr = RHS;
15451 unsigned Diag = diag::warn_objc_pointer_masking;
15460 if (SelArg0.starts_with(
"performSelector"))
15461 Diag = diag::warn_objc_pointer_masking_performSelector;
15478 assert((
isVector(ResultTy, Context.HalfTy) ||
15479 isVector(ResultTy, Context.ShortTy)) &&
15480 "Result must be a vector of half or short");
15483 "both operands expected to be a half vector");
15490 if (
isVector(ResultTy, Context.ShortTy))
15495 ResultTy,
VK, OK, OpLoc, FPFeatures,
15496 BinOpResTy, BinOpResTy);
15500 BinOpResTy,
VK, OK, OpLoc, FPFeatures);
15508 Expr *E1 =
nullptr) {
15509 if (!OpRequiresConversion || Ctx.
getLangOpts().NativeHalfType)
15518 auto HasVectorOfHalfType = [&Ctx](
Expr *E) {
15528 return VT->getElementType().getCanonicalType() == Ctx.
HalfTy;
15533 return HasVectorOfHalfType(E0) && (!E1 || HasVectorOfHalfType(E1));
15538 Expr *RHSExpr,
bool ForFoldExpression) {
15552 if (
Init.isInvalid())
15554 RHSExpr =
Init.get();
15564 bool ConvertHalfVec =
false;
15566 if (!LHS.
isUsable() || !RHS.isUsable())
15576 if (BO_Assign == Opc)
15577 Diag(OpLoc, diag::err_opencl_atomic_init) << 0 << SR;
15605 if (!ResultTy.
isNull()) {
15622 if (
auto *BE = dyn_cast<BlockExpr>(RHS.get()->IgnoreParens()))
15624 if (
auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
15625 if (VD->hasLocalStorage() &&
getCurScope()->isDeclScope(VD))
15626 BE->getBlockDecl()->setCanAvoidCopyToHeap();
15637 Opc == BO_PtrMemI);
15641 ConvertHalfVec =
true;
15648 ConvertHalfVec =
true;
15652 ConvertHalfVec =
true;
15663 ConvertHalfVec =
true;
15666 if (
const auto *BI = dyn_cast<BinaryOperator>(LHSExpr);
15667 !ForFoldExpression && BI && BI->isComparisonOp())
15668 Diag(OpLoc, diag::warn_consecutive_comparison)
15674 ConvertHalfVec =
true;
15678 ConvertHalfVec =
true;
15691 ConvertHalfVec =
true;
15696 ConvertHalfVec =
true;
15698 CompLHSTy = CompResultTy;
15705 CompLHSTy = CompResultTy;
15711 ConvertHalfVec =
true;
15718 ConvertHalfVec =
true;
15727 CompLHSTy = CompResultTy;
15738 CompLHSTy = CompResultTy;
15746 VK = RHS.get()->getValueKind();
15747 OK = RHS.get()->getObjectKind();
15759 (Opc == BO_Comma ||
isVector(RHS.get()->getType(),
Context.HalfTy) ==
15761 "both sides are half vectors or neither sides are");
15763 LHS.
get(), RHS.get());
15766 CheckArrayAccess(LHS.
get());
15767 CheckArrayAccess(RHS.get());
15771 &
Context.Idents.get(
"object_setClass"),
15777 "object_setClass(")
15790 if (CompResultTy.
isNull()) {
15791 if (ConvertHalfVec)
15811 if (ConvertHalfVec)
15816 Context, LHS.
get(), RHS.get(), Opc, ResultTy,
VK, OK, OpLoc,
15833 if (isLeftComp == isRightComp)
15838 bool isLeftBitwise = LHSBO && LHSBO->
isBitwiseOp();
15839 bool isRightBitwise = RHSBO && RHSBO->
isBitwiseOp();
15840 if (isLeftBitwise || isRightBitwise)
15852 Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
15855 Self.PDiag(diag::note_precedence_silence) << OpStr,
15856 (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange());
15858 Self.PDiag(diag::note_precedence_bitwise_first)
15873 Self.PDiag(diag::note_precedence_silence)
15882 if (Bop->getOpcode() == BO_LAnd) {
15887 }
else if (Bop->getOpcode() == BO_LOr) {
15888 if (
BinaryOperator *RBop = dyn_cast<BinaryOperator>(Bop->getRHS())) {
15891 if (RBop->getOpcode() == BO_LAnd &&
15903 if (Bop->getOpcode() == BO_LAnd) {
15918 if (Bop->isBitwiseOp() && Bop->getOpcode() < Opc) {
15919 S.
Diag(Bop->getOperatorLoc(), diag::warn_bitwise_op_in_bitwise_op)
15921 << Bop->getSourceRange() << OpLoc;
15923 S.
PDiag(diag::note_precedence_silence)
15924 << Bop->getOpcodeStr(),
15925 Bop->getSourceRange());
15931 Expr *SubExpr, StringRef Shift) {
15933 if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) {
15934 StringRef Op = Bop->getOpcodeStr();
15935 S.
Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift)
15936 << Bop->getSourceRange() << OpLoc << Shift << Op;
15938 S.
PDiag(diag::note_precedence_silence) << Op,
15939 Bop->getSourceRange());
15955 if (Kind != OO_LessLess && Kind != OO_GreaterGreater)
15958 S.
Diag(OpLoc, diag::warn_overloaded_shift_in_comparison)
15960 << (Kind == OO_LessLess);
15962 S.
PDiag(diag::note_precedence_silence)
15963 << (Kind == OO_LessLess ?
"<<" :
">>"),
15966 S, OpLoc, S.
PDiag(diag::note_evaluate_comparison_first),
15980 if ((Opc == BO_Or || Opc == BO_Xor) &&
15988 if (Opc == BO_LOr && !OpLoc.
isMacroID()) {
15994 || Opc == BO_Shr) {
16010 assert(LHSExpr &&
"ActOnBinOp(): missing left expression");
16011 assert(RHSExpr &&
"ActOnBinOp(): missing right expression");
16020 CheckInvalidBuiltinCountedByRef(LHSExpr, K);
16021 CheckInvalidBuiltinCountedByRef(RHSExpr, K);
16023 return BuildBinOp(S, TokLoc, Opc, LHSExpr, RHSExpr);
16029 if (OverOp !=
OO_None && OverOp != OO_Equal)
16078 Expr *RHSExpr,
bool ForFoldExpression) {
16079 if (!LHSExpr || !RHSExpr)
16091 if (pty->getKind() == BuiltinType::PseudoObject &&
16104 RHSExpr = resolvedRHS.
get();
16118 (pty->getKind() == BuiltinType::BoundMember ||
16119 pty->getKind() == BuiltinType::Overload)) {
16120 auto *OE = dyn_cast<OverloadExpr>(LHSExpr);
16121 if (OE && !OE->hasTemplateKeyword() && !OE->hasExplicitTemplateArgs() &&
16122 llvm::any_of(OE->decls(), [](
NamedDecl *ND) {
16123 return isa<FunctionTemplateDecl>(ND);
16125 Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc()
16126 : OE->getNameLoc(),
16127 diag::err_template_kw_missing)
16128 << OE->getName().getAsIdentifierInfo();
16135 LHSExpr = LHS.
get();
16142 if (Opc == BO_Assign && pty->getKind() == BuiltinType::Overload) {
16149 ForFoldExpression);
16159 RHSExpr = resolvedRHS.
get();
16165 if (!
HLSL().CheckResourceBinOp(Opc, LHSExpr, RHSExpr, OpLoc))
16168 std::optional<ExprResult> ConvRHS =
16170 if (ConvRHS &&
Context.hasSameUnqualifiedType(
16171 LHSExpr->
getType(), ConvRHS->get()->getType())) {
16172 assert(!ConvRHS->isInvalid());
16173 RHSExpr = ConvRHS->get();
16179 bool CanOverloadBinOp =
16183 bool TypeDependent =
16187 if (CanOverloadBinOp && (TypeDependent || Overloadable))
16195 "Should only occur in error-recovery path.");
16201 Context, LHSExpr, RHSExpr, Opc,
16221 ResultType = RHSExpr->
getType();
16224 ResultType =
Context.DependentTy;
16237 if (
T.isNull() ||
T->isDependentType())
16253 bool CanOverflow =
false;
16255 bool ConvertHalfVec =
false;
16264 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16271 if (Opc == UO_AddrOf)
16272 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
16273 if (Opc == UO_Deref)
16274 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
16279 resultType =
Context.DependentTy;
16288 Opc == UO_PreInc || Opc == UO_PostInc,
16289 Opc == UO_PreInc || Opc == UO_PreDec);
16294 CheckAddressOfNoDeref(InputExpr);
16307 CanOverflow = Opc == UO_Minus &&
16320 if (ConvertHalfVec)
16327 (!
Context.getLangOpts().ZVector ||
16337 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16348 Diag(OpLoc, diag::ext_integer_complement_complex)
16356 if (!
T->isIntegerType())
16357 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16360 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16376 resultType =
Context.FloatTy;
16382 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16388 if (
Context.getLangOpts().CPlusPlus) {
16393 }
else if (
Context.getLangOpts().OpenCL &&
16394 Context.getLangOpts().OpenCLVersion < 120) {
16398 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16411 Input.
get(), resultType,
16416 if (
Context.getLangOpts().OpenCL &&
16417 Context.getLangOpts().getOpenCLCompatibleVersion() < 120) {
16421 if (!
T->isIntegerType())
16422 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16428 }
else if (
Context.getLangOpts().CPlusPlus &&
16432 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16438 }
else if (resultType ==
Context.AMDGPUFeaturePredicateTy) {
16439 resultType =
Context.getLogicalOperationType();
16443 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
16449 resultType =
Context.getLogicalOperationType();
16477 "the co_await expression must be non-dependant before "
16478 "building operator co_await");
16489 if (Opc != UO_AddrOf && Opc != UO_Deref)
16490 CheckArrayAccess(Input.
get());
16496 if (Opc == UO_Deref && UO->getType()->hasAttr(attr::NoDeref) &&
16502 if (ConvertHalfVec)
16508 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
16509 if (!DRE->getQualifier())
16519 return Method->isImplicitObjectMemberFunction();
16525 if (!ULE->getQualifier())
16530 if (
Method->isImplicitObjectMemberFunction())
16551 if (pty->getKind() == BuiltinType::PseudoObject &&
16556 if (Opc == UO_Extension)
16561 if (Opc == UO_AddrOf &&
16562 (pty->getKind() == BuiltinType::Overload ||
16563 pty->getKind() == BuiltinType::UnknownAny ||
16564 pty->getKind() == BuiltinType::BoundMember))
16589 Expr *Input,
bool IsAfterAmp) {
16599 OpLoc, LabLoc, TheDecl,
Context.getPointerType(
Context.VoidTy));
16633 assert(!
Cleanup.exprNeedsCleanups() &&
16634 "cleanups within StmtExpr not correctly bound!");
16644 bool StmtExprMayBindToTemp =
false;
16646 if (
const auto *LastStmt = dyn_cast<ValueStmt>(Compound->
body_back())) {
16647 if (
const Expr *
Value = LastStmt->getExprStmt()) {
16648 StmtExprMayBindToTemp =
true;
16656 Expr *ResStmtExpr =
16658 if (StmtExprMayBindToTemp)
16660 return ResStmtExpr;
16683 auto *Cast = dyn_cast<ImplicitCastExpr>(E);
16684 if (Cast && Cast->getCastKind() == CK_ARCConsumeObject)
16685 return Cast->getSubExpr();
16706 return ExprError(
Diag(BuiltinLoc, diag::err_offsetof_record_type)
16707 << ArgTy << TypeRange);
16713 diag::err_offsetof_incomplete_type, TypeRange))
16716 bool DidWarnAboutNonPOD =
false;
16732 CurrentType =
Context.DependentTy;
16750 Exprs.push_back(Idx);
16762 CurrentType =
Context.DependentTy;
16768 diag::err_offsetof_incomplete_type))
16785 bool IsSafe =
LangOpts.CPlusPlus11? CRD->isStandardLayout() : CRD->isPOD();
16787 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
16788 : diag::ext_offsetof_non_pod_type;
16791 Diag(BuiltinLoc, DiagID)
16794 DidWarnAboutNonPOD =
true;
16805 MemberDecl = IndirectMemberDecl->getAnonField();
16812 if (!R.isAmbiguous())
16813 Diag(BuiltinLoc, diag::err_no_member)
16830 if (IndirectMemberDecl)
16837 Context.getCanonicalTagType(Parent), Paths)) {
16839 Diag(D.
getEndLoc(), diag::err_offsetof_field_of_virtual_base)
16849 if (IndirectMemberDecl) {
16850 for (
auto *FI : IndirectMemberDecl->chain()) {
16862 Comps, Exprs, RParenLoc);
16886 assert((CondExpr && LHSExpr && RHSExpr) &&
"Missing type argument(s)");
16891 bool CondIsTrue =
false;
16893 resType =
Context.DependentTy;
16896 llvm::APSInt condEval(32);
16898 CondExpr, &condEval, diag::err_typecheck_choose_expr_requires_constant);
16901 CondExpr = CondICE.
get();
16902 CondIsTrue = condEval.getZExtValue();
16905 Expr *ActiveExpr = CondIsTrue ? LHSExpr : RHSExpr;
16907 resType = ActiveExpr->
getType();
16913 resType,
VK, OK, RPLoc, CondIsTrue);
16925 Decl *ManglingContextDecl;
16926 std::tie(MCtx, ManglingContextDecl) =
16930 Block->setBlockMangling(ManglingNumber, ManglingContextDecl);
16952 "block-id should have no identifier!");
16963 assert(
T->isFunctionType() &&
16964 "GetTypeForDeclarator made a non-function block signature");
16980 unsigned Size =
Result.getFullDataSize();
16981 Sig =
Context.CreateTypeSourceInfo(
Result.getType(), Size);
16992 QualType RetTy = Fn->getReturnType();
17002 if (RetTy !=
Context.DependentTy) {
17010 if (ExplicitSignature) {
17011 for (
unsigned I = 0, E = ExplicitSignature.
getNumParams(); I != E; ++I) {
17013 if (Param->getIdentifier() ==
nullptr && !Param->isImplicit() &&
17017 Diag(Param->getLocation(), diag::ext_parameter_name_omitted_c23);
17019 Params.push_back(Param);
17025 for (
const auto &I : Fn->param_types()) {
17028 Params.push_back(Param);
17033 if (!Params.empty()) {
17044 AI->setOwningFunction(CurBlock->
TheDecl);
17047 if (AI->getIdentifier()) {
17053 if (AI->isInvalidDecl())
17072 Diag(CaretLoc, diag::err_blocks_disable) <<
LangOpts.OpenCL;
17077 assert(!
Cleanup.exprNeedsCleanups() &&
17078 "cleanups within block not correctly bound!");
17093 bool NoReturn = BD->
hasAttr<NoReturnAttr>();
17101 if (NoReturn && !Ext.getNoReturn()) Ext = Ext.
withNoReturn(
true);
17107 BlockTy =
Context.getFunctionType(RetTy, {}, EPI);
17128 BlockTy =
Context.getFunctionType(RetTy, {}, EPI);
17132 BlockTy =
Context.getBlockPointerType(BlockTy);
17136 !
PP.isCodeCompletionEnabled())
17141 if (Body &&
getCurFunction()->HasPotentialAvailabilityViolations)
17167 Expr *CopyExpr =
nullptr;
17194 if (!
Result.isInvalid() &&
17195 !
Result.get()->getType().isConstQualified()) {
17197 Result.get()->getType().withConst(),
17201 if (!
Result.isInvalid()) {
17211 if (!
Result.isInvalid() &&
17215 CopyExpr =
Result.get();
17222 Captures.push_back(NewCap);
17236 if (
Result->getBlockDecl()->hasCaptures()) {
17239 Cleanup.setExprNeedsCleanups(
true);
17243 for (
const auto &CI :
Result->getBlockDecl()->captures()) {
17244 const VarDecl *var = CI.getVariable();
17259 {Result},
Result->getType());
17273 Expr *OrigExpr = E;
17287 Context.getTargetInfo().getTriple().isNVPTX())
17314 "__builtin_zos_va_list must be an array type");
17319 VaListType = ZOSVaListType;
17328 VaListType =
Context.getArrayDecayedType(VaListType);
17340 if (
Init.isInvalid())
17356 diag::err_first_argument_to_va_arg_not_of_type_va_list)
17361 diag::err_second_parameter_to_va_arg_incomplete,
17367 diag::err_second_parameter_to_va_arg_abstract,
17374 ? diag::warn_second_parameter_to_va_arg_ownership_qualified
17375 : diag::warn_second_parameter_to_va_arg_not_pod)
17382 PDiag(diag::warn_second_parameter_to_va_arg_array)
17415 UnderlyingType = ED->getIntegerType();
17416 if (
Context.typesAreCompatible(PromoteType, UnderlyingType,
17429 ?
Context.getCorrespondingSignedType(UnderlyingType)
17430 :
Context.getCorrespondingUnsignedType(UnderlyingType);
17431 if (
Context.typesAreCompatible(PromoteType, UnderlyingType,
17437 PromoteType =
Context.DoubleTy;
17438 if (!PromoteType.
isNull())
17440 PDiag(diag::warn_second_parameter_to_va_arg_never_compatible)
17455 if (pw ==
Context.getTargetInfo().getIntWidth())
17457 else if (pw ==
Context.getTargetInfo().getLongWidth())
17459 else if (pw ==
Context.getTargetInfo().getLongLongWidth())
17462 llvm_unreachable(
"I don't know size of pointer!");
17479 if ((SLDecl->isCompleteDefinition() || SLDecl->isBeingDefined()) &&
17488 S.
Diag(Loc, diag::err_std_source_location_impl_not_found);
17496 S.
Diag(Loc, diag::err_std_source_location_impl_malformed);
17500 unsigned Count = 0;
17502 StringRef Name = F->getName();
17504 if (Name ==
"_M_file_name") {
17505 if (F->getType() !=
17509 }
else if (Name ==
"_M_function_name") {
17510 if (F->getType() !=
17514 }
else if (Name ==
"_M_line") {
17515 if (!F->getType()->isIntegerType())
17518 }
else if (Name ==
"_M_column") {
17519 if (!F->getType()->isIntegerType())
17528 S.
Diag(Loc, diag::err_std_source_location_impl_malformed);
17551 ResultTy =
Context.UnsignedIntTy;
17560 ResultTy =
Context.getPointerType(
17579 Data->BinaryData = BinaryData;
17583 Data->getDataElementCount());
17587 const Expr *SrcExpr) {
17596 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
17609 bool *Complained) {
17611 *Complained =
false;
17614 bool CheckInferredResultType =
false;
17616 unsigned DiagKind = 0;
17618 bool MayHaveConvFixit =
false;
17619 bool MayHaveFunctionDiff =
false;
17630 DiagKind = diag::warn_compatible_implicit_pointer_conv;
17634 DiagKind = diag::err_typecheck_convert_pointer_int;
17637 DiagKind = diag::ext_typecheck_convert_pointer_int;
17640 MayHaveConvFixit =
true;
17644 DiagKind = diag::err_typecheck_convert_int_pointer;
17647 DiagKind = diag::ext_typecheck_convert_int_pointer;
17650 MayHaveConvFixit =
true;
17654 diag::warn_typecheck_convert_incompatible_function_pointer_strict;
17656 MayHaveConvFixit =
true;
17660 DiagKind = diag::err_typecheck_convert_incompatible_function_pointer;
17663 DiagKind = diag::ext_typecheck_convert_incompatible_function_pointer;
17666 MayHaveConvFixit =
true;
17670 DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer;
17672 DiagKind = diag::err_typecheck_convert_incompatible_pointer;
17675 DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
17679 if (CheckInferredResultType) {
17685 MayHaveConvFixit =
true;
17689 DiagKind = diag::err_typecheck_convert_incompatible_pointer_sign;
17692 DiagKind = diag::ext_typecheck_convert_incompatible_pointer_sign;
17697 DiagKind = diag::err_typecheck_convert_pointer_void_func;
17700 DiagKind = diag::ext_typecheck_convert_pointer_void_func;
17706 SrcType =
Context.getDecayedType(SrcType);
17713 DiagKind = diag::err_typecheck_incompatible_address_space;
17716 DiagKind = diag::err_typecheck_incompatible_ownership;
17719 DiagKind = diag::err_typecheck_incompatible_ptrauth;
17723 llvm_unreachable(
"unknown error case for discarding qualifiers!");
17728 SrcType =
Context.getArrayDecayedType(SrcType);
17730 DiagKind = diag::ext_typecheck_convert_discards_overflow_behavior;
17746 DiagKind = diag::err_typecheck_convert_discards_qualifiers;
17749 DiagKind = diag::ext_typecheck_convert_discards_qualifiers;
17756 DiagKind = diag::err_nested_pointer_qualifier_mismatch;
17758 DiagKind = diag::ext_nested_pointer_qualifier_mismatch;
17762 DiagKind = diag::err_typecheck_incompatible_nested_address_space;
17766 DiagKind = diag::err_int_to_block_pointer;
17770 DiagKind = diag::err_typecheck_convert_incompatible_block_pointer;
17777 for (
auto *srcProto : srcOPT->
quals()) {
17783 IFace = IFaceT->getDecl();
17788 for (
auto *dstProto : dstOPT->
quals()) {
17794 IFace = IFaceT->getDecl();
17797 DiagKind = diag::err_incompatible_qualified_id;
17800 DiagKind = diag::warn_incompatible_qualified_id;
17806 DiagKind = diag::err_incompatible_vectors;
17809 DiagKind = diag::warn_incompatible_vectors;
17813 DiagKind = diag::err_arc_weak_unavailable_assign;
17820 "Unexpected function type found in IncompatibleOBTKinds assignment");
17822 SrcType =
Context.getDecayedType(SrcType);
17824 auto getOBTKindName = [](
QualType Ty) -> StringRef {
17825 if (Ty->isPointerType())
17826 Ty = Ty->getPointeeType();
17827 if (
const auto *OBT = Ty->getAs<OverflowBehaviorType>()) {
17828 return OBT->getBehaviorKind() ==
17829 OverflowBehaviorType::OverflowBehaviorKind::Trap
17833 llvm_unreachable(
"OBT kind unhandled");
17836 Diag(Loc, diag::err_incompatible_obt_kinds_assignment)
17837 << DstType << SrcType << getOBTKindName(DstType)
17838 << getOBTKindName(SrcType);
17845 *Complained =
true;
17849 DiagKind = diag::err_typecheck_convert_incompatible;
17851 MayHaveConvFixit =
true;
17853 MayHaveFunctionDiff =
true;
17862 FirstType = DstType;
17863 SecondType = SrcType;
17873 FirstType = SrcType;
17874 SecondType = DstType;
17883 FDiag << FirstType << SecondType << ActionForDiag
17886 if (DiagKind == diag::ext_typecheck_convert_incompatible_pointer_sign ||
17887 DiagKind == diag::err_typecheck_convert_incompatible_pointer_sign) {
17897 if (!ConvHints.
isNull()) {
17902 if (MayHaveConvFixit) { FDiag << (
unsigned) (ConvHints.
Kind); }
17904 if (MayHaveFunctionDiff)
17908 if ((DiagKind == diag::warn_incompatible_qualified_id ||
17909 DiagKind == diag::err_incompatible_qualified_id) &&
17911 Diag(IFace->
getLocation(), diag::note_incomplete_class_and_qualified_id)
17914 if (SecondType ==
Context.OverloadTy)
17918 if (CheckInferredResultType)
17926 *Complained =
true;
17937 return S.
Diag(Loc, diag::err_ice_not_integral)
17941 return S.
Diag(Loc, diag::err_expr_not_ice) << S.
LangOpts.CPlusPlus;
17956 IDDiagnoser(
unsigned DiagID)
17960 return S.
Diag(Loc, DiagID);
17962 } Diagnoser(DiagID);
17975 return S.
Diag(Loc, diag::ext_expr_not_ice) << S.
LangOpts.CPlusPlus;
17997 BaseDiagnoser(BaseDiagnoser) {}
18006 return S.
Diag(Loc, diag::err_ice_incomplete_type) <<
T;
18011 return S.
Diag(Loc, diag::err_ice_explicit_conversion) <<
T << ConvTy;
18022 return S.
Diag(Loc, diag::err_ice_ambiguous_conversion) <<
T;
18033 llvm_unreachable(
"conversion functions are permitted");
18035 } ConvertDiagnoser(Diagnoser);
18041 E = Converted.
get();
18062 E = RValueExpr.
get();
18080 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
18081 diag::note_invalid_subexpr_in_const_expr) {
18082 DiagLoc = Notes[0].first;
18104 EvalResult.
Diag = &Notes;
18128 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
18129 diag::note_invalid_subexpr_in_const_expr) {
18130 DiagLoc = Notes[0].first;
18156 class TransformToPE :
public TreeTransform<TransformToPE> {
18160 TransformToPE(
Sema &SemaRef) : BaseTransform(SemaRef) { }
18163 bool AlwaysRebuild() {
return true; }
18164 bool ReplacingOriginal() {
return true; }
18173 ExprResult TransformDeclRefExpr(DeclRefExpr *E) {
18175 !SemaRef.isUnevaluatedContext())
18177 diag::err_invalid_non_static_member_use)
18180 return BaseTransform::TransformDeclRefExpr(E);
18184 ExprResult TransformUnaryOperator(UnaryOperator *E) {
18188 return BaseTransform::TransformUnaryOperator(E);
18196 return SkipLambdaBody(E, Body);
18203 "Should only transform unevaluated expressions");
18208 return TransformToPE(*this).TransformExpr(E);
18213 "Should only transform unevaluated expressions");
18217 return TransformToPE(*this).TransformType(TInfo);
18225 LambdaContextDecl, ExprContext);
18239 Prev.isImmediateFunctionContext() || Prev.isConstantEvaluated();
18242 Prev.InImmediateEscalatingFunctionContext;
18310 if (
const auto *E = dyn_cast<UnaryOperator>(PossibleDeref)) {
18311 if (E->getOpcode() == UO_Deref)
18312 return CheckPossibleDeref(S, E->getSubExpr());
18313 }
else if (
const auto *E = dyn_cast<ArraySubscriptExpr>(PossibleDeref)) {
18314 return CheckPossibleDeref(S, E->getBase());
18315 }
else if (
const auto *E = dyn_cast<MemberExpr>(PossibleDeref)) {
18316 return CheckPossibleDeref(S, E->getBase());
18317 }
else if (
const auto E = dyn_cast<DeclRefExpr>(PossibleDeref)) {
18320 if (
const auto *Ptr = Ty->
getAs<PointerType>())
18323 Inner = Arr->getElementType();
18327 if (Inner->
hasAttr(attr::NoDeref))
18337 const DeclRefExpr *DeclRef = CheckPossibleDeref(*
this, E);
18344 Diag(E->
getExprLoc(), diag::warn_dereference_of_noderef_type_no_decl)
18359 if (BO->getOpcode() == BO_Assign) {
18361 llvm::erase(LHSs, BO->getLHS());
18369 "Cannot mark an immediate escalating expression outside of an "
18370 "immediate escalating context");
18373 if (
auto *DeclRef =
18374 dyn_cast<DeclRefExpr>(
Call->getCallee()->IgnoreImplicit()))
18375 DeclRef->setIsImmediateEscalating(
true);
18376 }
else if (
auto *Ctr = dyn_cast<CXXConstructExpr>(E->
IgnoreImplicit())) {
18377 Ctr->setIsImmediateEscalating(
true);
18378 }
else if (
auto *DeclRef = dyn_cast<DeclRefExpr>(E->
IgnoreImplicit())) {
18379 DeclRef->setIsImmediateEscalating(
true);
18381 assert(
false &&
"expected an immediately escalating expression");
18384 FI->FoundImmediateEscalatingExpression =
true;
18399 if (
auto *DeclRef =
18400 dyn_cast<DeclRefExpr>(
Call->getCallee()->IgnoreImplicit()))
18409 auto CheckConstantExpressionAndKeepResult = [&]() {
18412 Eval,
getASTContext(), ConstantExprKind::ImmediateInvocation);
18414 Cached = std::move(Eval.
Val);
18422 !CheckConstantExpressionAndKeepResult()) {
18427 if (
Cleanup.exprNeedsCleanups()) {
18444 Cleanup.cleanupsHaveSideEffects(), {});
18457 ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
18465 Eval.
Diag = &Notes;
18469 if (!
Result || !Notes.empty()) {
18472 if (
auto *
FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr))
18475 if (
auto *
Call = dyn_cast<CallExpr>(InnerExpr))
18477 else if (
auto *
Call = dyn_cast<CXXConstructExpr>(InnerExpr))
18478 FD =
Call->getConstructor();
18479 else if (
auto *Cast = dyn_cast<CastExpr>(InnerExpr))
18480 FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction());
18483 "could not find an immediate function in this expression");
18490 SemaRef.
Diag(Context->Loc, diag::note_invalid_consteval_initializer)
18492 SemaRef.
Diag(Context->Decl->getBeginLoc(), diag::note_declared_at);
18496 for (
auto &
Note : Notes)
18508 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
18512 ComplexRemove(
Sema &SemaRef, llvm::SmallPtrSetImpl<DeclRefExpr *> &DR,
18516 :
Base(SemaRef), DRSet(DR), IISet(II), CurrentII(Current) {}
18518 auto It = std::find_if(CurrentII, IISet.rend(),
18520 return Elem.getPointer() == E;
18526 if (It == IISet.rend()) {
18528 CurrentII->setInt(1);
18535 return Base::TransformConstantExpr(E);
18536 RemoveImmediateInvocation(E);
18537 return Base::TransformExpr(E->
getSubExpr());
18543 return Base::TransformCXXOperatorCallExpr(E);
18557 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(
Init))
18558 Init = ICE->getSubExpr();
18559 else if (
auto *ICE = dyn_cast<MaterializeTemporaryExpr>(
Init))
18560 Init = ICE->getSubExpr();
18566 if (
auto *CE = dyn_cast<ConstantExpr>(
Init);
18567 CE && CE->isImmediateInvocation())
18568 RemoveImmediateInvocation(CE);
18569 return Base::TransformInitializer(
Init, NotCopyInit);
18585 bool AlwaysRebuild() {
return false; }
18586 bool ReplacingOriginal() {
return true; }
18587 bool AllowSkippingCXXConstructExpr() {
18588 bool Res = AllowSkippingFirstCXXConstructExpr;
18589 AllowSkippingFirstCXXConstructExpr =
true;
18592 bool AllowSkippingFirstCXXConstructExpr =
true;
18603 Transformer.AllowSkippingFirstCXXConstructExpr =
false;
18605 ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
18611 It->getPointer()->setSubExpr(Res.
get());
18631 if (VD && (VD->isUsableInConstantExpressions(
SemaRef.
Context) ||
18632 VD->hasConstantInitialization())) {
18665 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
18666 SimpleRemove(llvm::SmallPtrSetImpl<DeclRefExpr *> &S) : DRSet(S) {}
18669 return DRSet.size();
18672 Visitor.TraverseStmt(
18682 if (DR->isImmediateEscalating())
18686 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND);
18688 ND = MD->getParent();
18695 bool ImmediateEscalating =
false;
18696 bool IsPotentiallyEvaluated =
18706 SemaRef.
Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
18707 << ND << isa<CXXRecordDecl>(ND) << FD->isConsteval();
18708 if (!FD->getBuiltinID())
18712 SemaRef.
Diag(Context->Loc, diag::note_invalid_consteval_initializer)
18714 SemaRef.
Diag(Context->Decl->getBeginLoc(), diag::note_declared_at);
18716 if (FD->isImmediateEscalating() && !FD->isConsteval())
18730 (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument ||
18738 D = diag::err_lambda_unevaluated_operand;
18744 D = diag::err_lambda_in_constant_expression;
18745 }
else if (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument) {
18748 D = diag::err_lambda_in_invalid_context;
18750 llvm_unreachable(
"Couldn't infer lambda error message.");
18752 for (
const auto *L : Rec.
Lambdas)
18753 Diag(L->getBeginLoc(), D);
18773 Diag(BO->getBeginLoc(), diag::warn_deprecated_simple_assign_volatile)
18844 llvm_unreachable(
"Invalid context");
18890 : FD(FD), Param(Param) {}
18897 CCName =
"stdcall";
18900 CCName =
"fastcall";
18903 CCName =
"vectorcall";
18906 llvm_unreachable(
"CC does not need mangling");
18909 S.
Diag(Loc, diag::err_cconv_incomplete_param_type)
18910 << Param->getDeclName() << FD->
getDeclName() << CCName;
18915 ParamIncompleteTypeDiagnoser Diagnoser(FD, Param);
18921enum class OdrUseContext {
18940 if (Context.isUnevaluated())
18941 return OdrUseContext::None;
18944 return OdrUseContext::Dependent;
18946 if (Context.isDiscardedStatementContext())
18947 return OdrUseContext::FormallyOdrUsed;
18949 else if (Context.Context ==
18951 return OdrUseContext::FormallyOdrUsed;
18953 return OdrUseContext::Used;
18957 if (!
Func->isConstexpr())
18960 if (
Func->isImplicitlyInstantiable() || !
Func->isUserProvided())
18967 auto *CCD = dyn_cast<CXXConstructorDecl>(
Func);
18968 return CCD && CCD->getInheritedConstructor();
18972 bool MightBeOdrUse) {
18973 assert(
Func &&
"No function?");
18975 Func->setReferenced();
18988 OdrUseContext OdrUse =
18990 if (IsRecursiveCall && OdrUse == OdrUseContext::Used)
18991 OdrUse = OdrUseContext::FormallyOdrUsed;
18995 if (
Func->isTrivial() && !
Func->hasAttr<DLLExportAttr>() &&
18996 OdrUse == OdrUseContext::Used) {
18999 OdrUse = OdrUseContext::FormallyOdrUsed;
19001 OdrUse = OdrUseContext::FormallyOdrUsed;
19008 bool NeededForConstantEvaluation =
19033 bool NeedDefinition =
19034 !IsRecursiveCall &&
19035 (OdrUse == OdrUseContext::Used ||
19036 (NeededForConstantEvaluation && !
Func->isPureVirtual()));
19043 if (NeedDefinition &&
19045 Func->getMemberSpecializationInfo()))
19052 if (NeedDefinition && !
Func->getBody()) {
19055 dyn_cast<CXXConstructorDecl>(
Func)) {
19068 }
else if (
Constructor->getInheritedConstructor()) {
19072 dyn_cast<CXXDestructorDecl>(
Func)) {
19082 if (MethodDecl->isOverloadedOperator() &&
19083 MethodDecl->getOverloadedOperator() == OO_Equal) {
19085 if (MethodDecl->isDefaulted() && !MethodDecl->isDeleted()) {
19086 if (MethodDecl->isCopyAssignmentOperator())
19088 else if (MethodDecl->isMoveAssignmentOperator())
19092 MethodDecl->getParent()->isLambda()) {
19099 }
else if (MethodDecl->isVirtual() &&
getLangOpts().AppleKext)
19103 if (
Func->isDefaulted() && !
Func->isDeleted()) {
19111 if (
Func->isImplicitlyInstantiable()) {
19113 Func->getTemplateSpecializationKindForInstantiation();
19115 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
19116 if (FirstInstantiation) {
19117 PointOfInstantiation = Loc;
19118 if (
auto *MSI =
Func->getMemberSpecializationInfo())
19119 MSI->setPointOfInstantiation(Loc);
19122 Func->setTemplateSpecializationKind(TSK, PointOfInstantiation);
19127 PointOfInstantiation = Loc;
19131 Func->isConstexpr()) {
19136 std::make_pair(
Func, PointOfInstantiation));
19137 else if (
Func->isConstexpr())
19143 Func->setInstantiationIsPending(
true);
19145 std::make_pair(
Func, PointOfInstantiation));
19146 if (llvm::isTimeTraceVerbose()) {
19147 llvm::timeTraceAddInstantEvent(
"DeferInstantiation", [&] {
19149 llvm::raw_string_ostream
OS(Name);
19156 Consumer.HandleCXXImplicitFunctionInstantiation(
Func);
19161 for (
auto *i :
Func->redecls()) {
19162 if (!i->isUsed(
false) && i->isImplicitlyInstantiable())
19180 if (
Init->isInClassMemberInitializer())
19182 MarkDeclarationsReferencedInExpr(Init->getInit());
19203 if (
LangOpts.OffloadImplicitHostDeviceTemplates &&
LangOpts.CUDAIsDevice &&
19208 if (OdrUse == OdrUseContext::Used && !
Func->isUsed(
false)) {
19210 if (!
Func->isDefined() && !
Func->isInAnotherModuleUnit()) {
19211 if (mightHaveNonExternalLinkage(
Func))
19213 else if (
Func->getMostRecentDecl()->isInlined() &&
19215 !
Func->getMostRecentDecl()->hasAttr<GNUInlineAttr>())
19233 if (
Context.getTargetInfo().getCXXABI().isMicrosoft()) {
19234 if (
auto *Dtor = dyn_cast<CXXDestructorDecl>(
Func)) {
19254 const unsigned *
const FunctionScopeIndexToStopAt =
nullptr) {
19257 VarDecl *Var =
V->getPotentiallyDecomposedVarDecl();
19258 assert(Var &&
"expected a capturable variable");
19268 QualType CaptureType, DeclRefType;
19274 DeclRefType, FunctionScopeIndexToStopAt);
19289 << 2 << 1 << Var << UserTarget;
19292 ? diag::note_cuda_const_var_unpromoted
19293 : diag::note_cuda_host_var);
19302 Var->
hasAttr<CUDADeviceAttr>() &&
19303 !Var->
getAttr<CUDADeviceAttr>()->isImplicit())) &&
19304 !Var->
hasAttr<CUDASharedAttr>() &&
19320 (!FD || (!FD->getDescribedFunctionTemplate() &&
19332 unsigned CapturingScopeIndex) {
19359 unsigned ContextKind = 3;
19369 S.
Diag(loc, diag::err_reference_to_local_in_enclosing_context)
19370 << var << ValueKind << ContextKind << VarDC;
19371 S.
Diag(var->getLocation(), diag::note_entity_declared_at)
19380 bool &SubCapturesAreNested,
19386 SubCapturesAreNested =
true;
19439 "Only variables and structured bindings can be captured");
19450 S.
Diag(Loc, diag::err_lambda_capture_anonymous_var);
19459 S.
Diag(Loc, diag::err_ref_vm_type);
19470 S.
Diag(Loc, diag::err_ref_flexarray_type);
19472 S.
Diag(Loc, diag::err_lambda_capture_flexarray_type) << Var;
19477 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
19482 S.
Diag(Loc, diag::err_capture_block_variable) << Var << !IsLambda;
19491 S.
Diag(Loc, diag::err_opencl_block_ref_block);
19502 ? diag::warn_cxx17_compat_capture_binding
19503 : diag::ext_capture_binding)
19517 bool ByRef =
false;
19523 if (BuildAndDiagnose) {
19524 S.
Diag(Loc, diag::err_ref_array_type);
19535 if (BuildAndDiagnose) {
19536 S.
Diag(Loc, diag::err_arc_autoreleasing_capture)
19552 if (BuildAndDiagnose) {
19554 S.
Diag(Loc, diag::warn_block_capture_autoreleasing);
19555 S.
Diag(VarLoc, diag::note_declare_parameter_strong);
19560 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
19569 DeclRefType = CaptureType;
19573 if (BuildAndDiagnose)
19583 const bool BuildAndDiagnose,
QualType &CaptureType,
QualType &DeclRefType,
19584 const bool RefersToCapturedVariable,
TryCaptureKind Kind,
bool IsTopScope,
19610 CaptureType = DeclRefType;
19613 if (BuildAndDiagnose)
19614 RSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
19624 const bool RefersToCapturedVariable,
19629 bool ByRef =
false;
19633 ByRef = (LSI->
ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
19638 S.
Diag(Loc, diag::err_wasm_ca_reference) << 0;
19669 if (!RefType->getPointeeType()->isFunctionType())
19676 if (BuildAndDiagnose) {
19677 S.
Diag(Loc, diag::err_arc_autoreleasing_capture) << 1;
19687 if (!
Invalid && BuildAndDiagnose) {
19691 diag::err_capture_of_incomplete_or_sizeless_type,
19695 diag::err_capture_of_abstract_type))
19721 if (BuildAndDiagnose)
19722 LSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
19723 Loc, EllipsisLoc, CaptureType,
Invalid);
19734 if (
T.isTriviallyCopyableType(Context))
19738 if (!(RD = RD->getDefinition()))
19740 if (RD->hasSimpleCopyConstructor())
19742 if (RD->hasUserDeclaredCopyConstructor())
19744 if (Ctor->isCopyConstructor())
19745 return !Ctor->isDeleted();
19765 if (ShouldOfferCopyFix) {
19769 FixBuffer.assign({Separator, Var->
getName()});
19770 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
19775 FixBuffer.assign({Separator,
"&", Var->
getName()});
19776 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
19788 return !C.isThisCapture() && !C.isInitCapture();
19797 if (ShouldOfferCopyFix) {
19798 bool CanDefaultCopyCapture =
true;
19807 if (CanDefaultCopyCapture && llvm::none_of(LSI->
Captures, [](
Capture &
C) {
19808 return !C.isThisCapture() && !C.isInitCapture() && C.isCopyCapture();
19810 FixBuffer.assign({
"=", Separator});
19811 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
19820 return !C.isInitCapture() && C.isReferenceCapture() &&
19821 !C.isThisCapture();
19823 FixBuffer.assign({
"&", Separator});
19824 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
19833 QualType &DeclRefType,
const unsigned *
const FunctionScopeIndexToStopAt) {
19857 const auto *VD = dyn_cast<VarDecl>(Var);
19859 if (VD->isInitCapture())
19864 assert(VD &&
"Cannot capture a null variable");
19866 const unsigned MaxFunctionScopesIndex = FunctionScopeIndexToStopAt
19870 if (FunctionScopeIndexToStopAt) {
19871 assert(!
FunctionScopes.empty() &&
"No function scopes to stop at?");
19876 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(
FunctionScopes[FSIndex]);
19877 FSIndex && LSI && !LSI->AfterParameterList)
19879 assert(MaxFunctionScopesIndex <= FSIndex &&
19880 "FunctionScopeIndexToStopAt should be no greater than FSIndex into "
19881 "FunctionScopes.");
19882 while (FSIndex != MaxFunctionScopesIndex) {
19890 bool IsGlobal = !VD->hasLocalStorage();
19891 if (IsGlobal && !(
LangOpts.OpenMP &&
19892 OpenMP().isOpenMPCapturedDecl(Var,
true,
19893 MaxFunctionScopesIndex)))
19907 CaptureType = Var->
getType();
19909 bool Nested =
false;
19911 unsigned FunctionScopesIndex = MaxFunctionScopesIndex;
19916 LSI = dyn_cast_or_null<LambdaScopeInfo>(
19919 bool IsInScopeDeclarationContext =
19930 if (IsInScopeDeclarationContext &&
19931 FunctionScopesIndex == MaxFunctionScopesIndex && VarDC == DC)
19937 !IsInScopeDeclarationContext
19940 BuildAndDiagnose, *
this);
19946 FunctionScopesIndex = MaxFunctionScopesIndex - 1;
19965 if (
const auto *Parm = dyn_cast<ParmVarDecl>(Var);
19966 Parm && Parm->getDeclContext() == DC)
19974 if (BuildAndDiagnose) {
19977 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19992 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19993 QTy = PVD->getOriginalType();
19998 if (
auto *RSI = dyn_cast<CapturedRegionScopeInfo>(CSI)) {
20005 if (BuildAndDiagnose) {
20006 Diag(ExprLoc, diag::err_capture_binding_openmp) << Var;
20012 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
20017 if (IsOpenMPPrivateDecl != OMPC_unknown &&
20020 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
20021 QTy = PVD->getOriginalType();
20023 E =
OpenMP().getNumberOfConstructScopes(RSI->OpenMPLevel);
20027 assert(RSI->OpenMPLevel == OuterRSI->OpenMPLevel &&
20028 "Wrong number of captured regions associated with the "
20029 "OpenMP construct.");
20034 IsOpenMPPrivateDecl != OMPC_private &&
20036 RSI->OpenMPCaptureLevel);
20040 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
20046 OpenMP().adjustOpenMPTargetScopeIndex(FunctionScopesIndex,
20049 if (IsTargetCap || IsOpenMPPrivateDecl == OMPC_private ||
20050 (IsGlobal && !IsGlobalCap)) {
20051 Nested = !IsTargetCap;
20057 CaptureType =
Context.getLValueReferenceType(DeclRefType);
20066 if (BuildAndDiagnose) {
20067 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
20089 FunctionScopesIndex--;
20090 if (IsInScopeDeclarationContext)
20092 }
while (!VarDC->
Equals(DC));
20100 for (
unsigned I = ++FunctionScopesIndex, N = MaxFunctionScopesIndex + 1; I != N;
20113 if (
Invalid && !BuildAndDiagnose)
20118 DeclRefType, Nested, *
this,
Invalid);
20122 RSI, Var, ExprLoc, BuildAndDiagnose, CaptureType, DeclRefType, Nested,
20123 Kind, I == N - 1, *
this,
Invalid);
20129 DeclRefType, Nested, Kind, EllipsisLoc,
20134 if (
Invalid && !BuildAndDiagnose)
20146 DeclRefType,
nullptr);
20154 false, CaptureType, DeclRefType,
nullptr);
20158 assert(Var &&
"Null value cannot be captured");
20165 false, CaptureType, DeclRefType,
20169 return DeclRefType;
20177class CopiedTemplateArgs {
20181 template<
typename RefExpr>
20182 CopiedTemplateArgs(RefExpr *E) : HasArgs(E->hasExplicitTemplateArgs()) {
20184 E->copyTemplateArgumentsInto(TemplateArgStorage);
20187#ifdef __has_cpp_attribute
20188#if __has_cpp_attribute(clang::lifetimebound)
20189 [[clang::lifetimebound]]
20193 return HasArgs ? &TemplateArgStorage :
nullptr;
20219 auto Rebuild = [&](
Expr *Sub) {
20224 auto IsPotentialResultOdrUsed = [&](
NamedDecl *D) {
20227 auto *VD = dyn_cast<VarDecl>(D);
20250 llvm_unreachable(
"unexpected non-odr-use-reason");
20254 if (VD->getType()->isReferenceType())
20256 if (
auto *RD = VD->getType()->getAsCXXRecordDecl())
20257 if (RD->hasDefinition() && RD->hasMutableFields())
20259 if (!VD->isUsableInConstantExpressions(S.
Context))
20264 if (VD->getType()->isReferenceType())
20272 auto MaybeCUDAODRUsed = [&]() ->
bool {
20278 auto *DRE = dyn_cast<DeclRefExpr>(E);
20281 auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
20288 auto MarkNotOdrUsed = [&] {
20289 if (!MaybeCUDAODRUsed()) {
20292 LSI->markVariableExprAsNonODRUsed(E);
20300 case Expr::DeclRefExprClass: {
20302 if (DRE->isNonOdrUse() || IsPotentialResultOdrUsed(DRE->getDecl()))
20308 S.
Context, DRE->getQualifierLoc(), DRE->getTemplateKeywordLoc(),
20309 DRE->getDecl(), DRE->refersToEnclosingVariableOrCapture(),
20310 DRE->getNameInfo(), DRE->getType(), DRE->getValueKind(),
20311 DRE->getFoundDecl(), CopiedTemplateArgs(DRE), NOUR);
20314 case Expr::FunctionParmPackExprClass: {
20319 if (IsPotentialResultOdrUsed(D))
20330 case Expr::ArraySubscriptExprClass: {
20336 if (!
Base.isUsable())
20338 Expr *LHS = ASE->getBase() == ASE->getLHS() ?
Base.get() : ASE->getLHS();
20339 Expr *RHS = ASE->getBase() == ASE->getRHS() ?
Base.get() : ASE->getRHS();
20342 ASE->getRBracketLoc());
20345 case Expr::MemberExprClass: {
20351 if (!
Base.isUsable())
20354 S.
Context,
Base.get(), ME->isArrow(), ME->getOperatorLoc(),
20355 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(),
20356 ME->getMemberDecl(), ME->getFoundDecl(), ME->getMemberNameInfo(),
20357 CopiedTemplateArgs(ME), ME->getType(), ME->getValueKind(),
20358 ME->getObjectKind(), ME->isNonOdrUse());
20361 if (ME->getMemberDecl()->isCXXInstanceMember())
20366 if (ME->isNonOdrUse() || IsPotentialResultOdrUsed(ME->getMemberDecl()))
20372 S.
Context, ME->getBase(), ME->isArrow(), ME->getOperatorLoc(),
20373 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(), ME->getMemberDecl(),
20374 ME->getFoundDecl(), ME->getMemberNameInfo(), CopiedTemplateArgs(ME),
20375 ME->getType(), ME->getValueKind(), ME->getObjectKind(), NOUR);
20378 case Expr::BinaryOperatorClass: {
20380 Expr *LHS = BO->getLHS();
20381 Expr *RHS = BO->getRHS();
20383 if (BO->getOpcode() == BO_PtrMemD) {
20385 if (!Sub.isUsable())
20387 BO->setLHS(Sub.get());
20389 }
else if (BO->getOpcode() == BO_Comma) {
20391 if (!Sub.isUsable())
20393 BO->setRHS(Sub.get());
20401 case Expr::ParenExprClass: {
20404 if (!Sub.isUsable())
20406 return S.
ActOnParenExpr(PE->getLParen(), PE->getRParen(), Sub.get());
20411 case Expr::ConditionalOperatorClass: {
20422 LHS = CO->getLHS();
20424 RHS = CO->getRHS();
20426 CO->getCond(), LHS.
get(), RHS.
get());
20431 case Expr::UnaryOperatorClass: {
20433 if (UO->getOpcode() != UO_Extension)
20436 if (!Sub.isUsable())
20438 return S.
BuildUnaryOp(
nullptr, UO->getOperatorLoc(), UO_Extension,
20445 case Expr::GenericSelectionExprClass: {
20449 bool AnyChanged =
false;
20450 for (
Expr *OrigAssocExpr : GSE->getAssocExprs()) {
20451 ExprResult AssocExpr = Rebuild(OrigAssocExpr);
20455 AssocExprs.push_back(AssocExpr.
get());
20458 AssocExprs.push_back(OrigAssocExpr);
20462 void *ExOrTy =
nullptr;
20463 bool IsExpr = GSE->isExprPredicate();
20465 ExOrTy = GSE->getControllingExpr();
20467 ExOrTy = GSE->getControllingType();
20469 GSE->getGenericLoc(), GSE->getDefaultLoc(),
20470 GSE->getRParenLoc(), IsExpr, ExOrTy,
20471 GSE->getAssocTypeSourceInfos(), AssocExprs)
20479 case Expr::ChooseExprClass: {
20490 if (!LHS.
get() && !RHS.
get())
20493 LHS = CE->getLHS();
20495 RHS = CE->getRHS();
20498 RHS.
get(), CE->getRParenLoc());
20502 case Expr::ConstantExprClass: {
20505 if (!Sub.isUsable())
20512 case Expr::ImplicitCastExprClass: {
20517 switch (ICE->getCastKind()) {
20519 case CK_DerivedToBase:
20520 case CK_UncheckedDerivedToBase: {
20521 ExprResult Sub = Rebuild(ICE->getSubExpr());
20522 if (!Sub.isUsable())
20526 ICE->getValueKind(), &Path);
20583 for (
Expr *E : LocalMaybeODRUseExprs) {
20584 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
20586 DRE->getLocation(), *
this);
20587 }
else if (
auto *ME = dyn_cast<MemberExpr>(E)) {
20590 }
else if (
auto *FP = dyn_cast<FunctionParmPackExpr>(E)) {
20594 llvm_unreachable(
"Unexpected expression");
20599 "MarkVarDeclODRUsed failed to cleanup MaybeODRUseExprs?");
20608 const bool RefersToEnclosingScope =
20611 if (RefersToEnclosingScope) {
20626 assert(E &&
"Capture variable should be used in an expression.");
20639 "Invalid Expr argument to DoMarkVarDeclReferenced");
20650 bool UsableInConstantExpr =
20669 bool NeededForConstantEvaluation =
20672 bool NeedDefinition =
20673 OdrUse == OdrUseContext::Used || NeededForConstantEvaluation ||
20675 Var->
getType()->isUndeducedType());
20678 "Can't instantiate a partial template specialization.");
20695 bool TryInstantiating =
20699 if (TryInstantiating) {
20702 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
20703 if (FirstInstantiation) {
20704 PointOfInstantiation = Loc;
20706 MSI->setPointOfInstantiation(PointOfInstantiation);
20728 if (
auto *DRE = dyn_cast_or_null<DeclRefExpr>(E))
20729 DRE->setDecl(DRE->getDecl());
20730 else if (
auto *ME = dyn_cast_or_null<MemberExpr>(E))
20731 ME->setMemberDecl(ME->getMemberDecl());
20732 }
else if (FirstInstantiation) {
20734 .push_back(std::make_pair(Var, PointOfInstantiation));
20736 bool Inserted =
false;
20738 auto Iter = llvm::find_if(
20740 return P.first == Var;
20742 if (Iter != I.end()) {
20757 .push_back(std::make_pair(Var, PointOfInstantiation));
20781 if (
DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(E))
20782 if (DRE->isNonOdrUse())
20784 if (
MemberExpr *ME = dyn_cast_or_null<MemberExpr>(E))
20785 if (ME->isNonOdrUse())
20789 case OdrUseContext::None:
20794 "missing non-odr-use marking for unevaluated decl ref");
20797 case OdrUseContext::FormallyOdrUsed:
20802 case OdrUseContext::Used:
20811 case OdrUseContext::Dependent:
20829 if (OdrUse == OdrUseContext::Used) {
20830 QualType CaptureType, DeclRefType;
20836 }
else if (OdrUse == OdrUseContext::Dependent) {
20852 auto *ID = dyn_cast<DeclRefExpr>(E);
20853 if (!ID || ID->isTypeDependent() || !ID->refersToEnclosingVariableOrCapture())
20860 auto IsDependent = [&]() {
20862 auto *LSI = dyn_cast<sema::LambdaScopeInfo>(
Scope);
20867 LSI->AfterParameterList)
20870 const auto *MD = LSI->CallOperator;
20871 if (MD->getType().isNull())
20875 if (!Ty || !MD->isExplicitObjectMemberFunction() ||
20879 if (
auto *
C = LSI->CaptureMap.count(D) ? &LSI->getCapture(D) :
nullptr) {
20880 if (
C->isCopyCapture())
20885 if (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByval)
20891 ID->setCapturedByCopyInLambdaWithExplicitObjectParameter(
20897 bool MightBeOdrUse,
20905 if (
VarDecl *Var = dyn_cast<VarDecl>(D)) {
20924 const MemberExpr *ME = dyn_cast<MemberExpr>(E);
20931 bool IsVirtualCall = MD->
isVirtual() &&
20933 if (!IsVirtualCall)
20950 bool OdrUse =
true;
20952 if (
Method->isVirtual() &&
20956 if (
auto *FD = dyn_cast<FunctionDecl>(E->
getDecl())) {
20961 !FD->isDependentContext())
20975 bool MightBeOdrUse =
true;
20978 if (
Method->isPureVirtual())
20979 MightBeOdrUse =
false;
20998 bool MightBeOdrUse) {
20999 if (MightBeOdrUse) {
21000 if (
auto *VD = dyn_cast<VarDecl>(D)) {
21005 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
21031bool MarkReferencedDecls::TraverseTemplateArgument(
21032 const TemplateArgument &Arg) {
21035 EnterExpressionEvaluationContext
Evaluated(
21049 MarkReferencedDecls Marker(*
this, Loc);
21050 Marker.TraverseType(
T);
21056class EvaluatedExprMarker :
public UsedDeclVisitor<EvaluatedExprMarker> {
21059 bool SkipLocalVariables;
21062 EvaluatedExprMarker(
Sema &S,
bool SkipLocalVariables,
21064 : Inherited(S), SkipLocalVariables(SkipLocalVariables), StopAt(StopAt) {}
21070 void Visit(Expr *E) {
21071 if (llvm::is_contained(StopAt, E))
21073 Inherited::Visit(E);
21076 void VisitConstantExpr(ConstantExpr *E) {
21081 void VisitDeclRefExpr(DeclRefExpr *E) {
21083 if (SkipLocalVariables) {
21084 if (VarDecl *VD = dyn_cast<VarDecl>(E->
getDecl()))
21085 if (VD->hasLocalStorage())
21095 void VisitMemberExpr(MemberExpr *E) {
21103 bool SkipLocalVariables,
21105 EvaluatedExprMarker(*
this, SkipLocalVariables, StopAt).Visit(E);
21117 (
Decl->isConstexpr() || (
Decl->isStaticDataMember() &&
21121 if (Stmts.empty()) {
21132 if (
Diags.getIgnoreAllWarnings() &&
21143 if (
Decl &&
Decl->isFileVarDecl()) {
21216 class CallReturnIncompleteDiagnoser :
public TypeDiagnoser {
21222 : FD(FD), CE(CE) { }
21226 S.
Diag(Loc, diag::err_call_incomplete_return)
21231 S.
Diag(Loc, diag::err_call_function_incomplete_return)
21236 } Diagnoser(FD, CE);
21249 unsigned diagnostic = diag::warn_condition_is_assignment;
21250 bool IsOrAssign =
false;
21253 if (Op->getOpcode() != BO_Assign && Op->getOpcode() != BO_OrAssign)
21256 IsOrAssign = Op->getOpcode() == BO_OrAssign;
21264 if (
ObjC().isSelfExpr(Op->getLHS()) && ME->getMethodFamily() ==
OMF_init)
21265 diagnostic = diag::warn_condition_is_idiomatic_assignment;
21269 diagnostic = diag::warn_condition_is_idiomatic_assignment;
21272 Loc = Op->getOperatorLoc();
21274 if (Op->getOperator() != OO_Equal && Op->getOperator() != OO_PipeEqual)
21277 IsOrAssign = Op->getOperator() == OO_PipeEqual;
21278 Loc = Op->getOperatorLoc();
21290 Diag(Loc, diag::note_condition_assign_silence)
21295 Diag(Loc, diag::note_condition_or_assign_to_comparison)
21298 Diag(Loc, diag::note_condition_assign_to_comparison)
21316 if (opE->getOpcode() == BO_EQ &&
21317 opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(
Context)
21323 Diag(Loc, diag::note_equality_comparison_silence)
21326 Diag(Loc, diag::note_equality_comparison_to_assign)
21332 bool IsConstexpr) {
21334 if (
ParenExpr *parenE = dyn_cast<ParenExpr>(E))
21354 if (!
T->isScalarType()) {
21355 Diag(Loc, diag::err_typecheck_statement_requires_scalar)
21359 CheckBoolLikeConversion(E, Loc);
21388 if (
Cond.isInvalid()) {
21396 if (!
Cond.isUsable())
21406 struct RebuildUnknownAnyFunction
21407 :
StmtVisitor<RebuildUnknownAnyFunction, ExprResult> {
21411 RebuildUnknownAnyFunction(
Sema &S) : S(S) {}
21414 llvm_unreachable(
"unexpected statement!");
21425 template <
class T>
ExprResult rebuildSugarExpr(
T *E) {
21426 ExprResult SubResult = Visit(E->getSubExpr());
21429 Expr *SubExpr = SubResult.
get();
21430 E->setSubExpr(SubExpr);
21431 E->setType(SubExpr->
getType());
21438 return rebuildSugarExpr(E);
21441 ExprResult VisitUnaryExtension(UnaryOperator *E) {
21442 return rebuildSugarExpr(E);
21445 ExprResult VisitUnaryAddrOf(UnaryOperator *E) {
21449 Expr *SubExpr = SubResult.
get();
21457 ExprResult resolveDecl(Expr *E, ValueDecl *VD) {
21475 ExprResult VisitDeclRefExpr(DeclRefExpr *E) {
21476 return resolveDecl(E, E->
getDecl());
21494 struct RebuildUnknownAnyExpr
21495 : StmtVisitor<RebuildUnknownAnyExpr, ExprResult> {
21502 RebuildUnknownAnyExpr(Sema &S, QualType
CastType)
21506 llvm_unreachable(
"unexpected statement!");
21516 ExprResult VisitObjCMessageExpr(ObjCMessageExpr *E);
21520 template <
class T>
ExprResult rebuildSugarExpr(
T *E) {
21521 ExprResult SubResult = Visit(E->getSubExpr());
21523 Expr *SubExpr = SubResult.
get();
21524 E->setSubExpr(SubExpr);
21525 E->setType(SubExpr->
getType());
21532 return rebuildSugarExpr(E);
21535 ExprResult VisitUnaryExtension(UnaryOperator *E) {
21536 return rebuildSugarExpr(E);
21539 ExprResult VisitUnaryAddrOf(UnaryOperator *E) {
21540 const PointerType *Ptr = DestType->
getAs<PointerType>();
21565 ExprResult VisitImplicitCastExpr(ImplicitCastExpr *E);
21567 ExprResult resolveDecl(Expr *E, ValueDecl *VD);
21573 ExprResult VisitDeclRefExpr(DeclRefExpr *E) {
21574 return resolveDecl(E, E->
getDecl());
21580ExprResult RebuildUnknownAnyExpr::VisitCallExpr(CallExpr *E) {
21585 FK_FunctionPointer,
21590 QualType CalleeType = CalleeExpr->
getType();
21593 Kind = FK_MemberFunction;
21595 }
else if (
const PointerType *Ptr = CalleeType->
getAs<PointerType>()) {
21597 Kind = FK_FunctionPointer;
21600 Kind = FK_BlockPointer;
21602 const FunctionType *FnType = CalleeType->
castAs<FunctionType>();
21607 unsigned diagID = diag::err_func_returning_array_function;
21608 if (Kind == FK_BlockPointer)
21609 diagID = diag::err_block_returning_array_function;
21622 const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FnType);
21644 SmallVector<QualType, 8> ArgTypes;
21645 if (ParamTypes.empty() && Proto->
isVariadic()) {
21647 for (
unsigned i = 0, e = E->
getNumArgs(); i != e; ++i) {
21650 ParamTypes = ArgTypes;
21661 case FK_MemberFunction:
21665 case FK_FunctionPointer:
21669 case FK_BlockPointer:
21675 ExprResult CalleeResult = Visit(CalleeExpr);
21683ExprResult RebuildUnknownAnyExpr::VisitObjCMessageExpr(ObjCMessageExpr *E) {
21686 S.
Diag(E->
getExprLoc(), diag::err_func_returning_array_function)
21694 Method->setReturnType(DestType);
21704ExprResult RebuildUnknownAnyExpr::VisitImplicitCastExpr(ImplicitCastExpr *E) {
21706 if (E->
getCastKind() == CK_FunctionToPointerDecay) {
21720 }
else if (E->
getCastKind() == CK_LValueToRValue) {
21737 llvm_unreachable(
"Unhandled cast type!");
21741ExprResult RebuildUnknownAnyExpr::resolveDecl(Expr *E, ValueDecl *VD) {
21743 QualType
Type = DestType;
21748 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(VD)) {
21749 if (
const PointerType *Ptr =
Type->getAs<PointerType>()) {
21757 if (!
Type->isFunctionType()) {
21762 if (
const FunctionProtoType *FT =
Type->getAs<FunctionProtoType>()) {
21766 QualType FDT = FD->getType();
21767 const FunctionType *FnType = FDT->
castAs<FunctionType>();
21768 const FunctionProtoType *Proto = dyn_cast_or_null<FunctionProtoType>(FnType);
21769 DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
21770 if (DRE && Proto && Proto->getParamTypes().empty() && Proto->isVariadic()) {
21771 SourceLocation Loc = FD->getLocation();
21773 S.
Context, FD->getDeclContext(), Loc, Loc,
21774 FD->getNameInfo().getName(), DestType, FD->getTypeSourceInfo(),
21776 false , FD->hasPrototype(),
21779 if (FD->getQualifier())
21782 SmallVector<ParmVarDecl*, 16> Params;
21783 for (
const auto &AI : FT->param_types()) {
21784 ParmVarDecl *Param =
21787 Params.push_back(Param);
21789 NewFD->setParams(Params);
21795 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
21796 if (MD->isInstance()) {
21807 if (
const ReferenceType *RefTy =
Type->getAs<ReferenceType>()) {
21808 Type = RefTy->getPointeeType();
21809 }
else if (
Type->isFunctionType()) {
21810 S.
Diag(E->
getExprLoc(), diag::err_unknown_any_var_function_type)
21836 diag::err_typecheck_cast_to_incomplete))
21851 return RebuildUnknownAnyExpr(*
this, ToType).Visit(E);
21858 ExplicitCastExpr *castArg = dyn_cast<ExplicitCastExpr>(arg->IgnoreParens());
21867 assert(!arg->hasPlaceholderType());
21879 unsigned diagID = diag::err_uncasted_use_of_unknown_any;
21882 if (
CallExpr *call = dyn_cast<CallExpr>(E)) {
21883 E = call->getCallee();
21884 diagID = diag::err_uncasted_call_of_unknown_any;
21892 if (
DeclRefExpr *ref = dyn_cast<DeclRefExpr>(E)) {
21893 loc = ref->getLocation();
21894 d = ref->getDecl();
21895 }
else if (
MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
21896 loc = mem->getMemberLoc();
21897 d = mem->getMemberDecl();
21899 diagID = diag::err_uncasted_call_of_unknown_any;
21900 loc = msg->getSelectorStartLoc();
21901 d = msg->getMethodDecl();
21903 S.
Diag(loc, diag::err_uncasted_send_to_unknown_any_method)
21904 <<
static_cast<unsigned>(msg->isClassMessage()) << msg->getSelector()
21922 if (!placeholderType)
return E;
21924 switch (placeholderType->
getKind()) {
21925 case BuiltinType::UnresolvedTemplate: {
21938 if (
auto *TD = dyn_cast<TemplateDecl>(Temp))
21939 TN =
Context.getQualifiedTemplateName(NNS, ULE->hasTemplateKeyword(),
21944 Diag(NameInfo.
getLoc(), diag::err_template_kw_refers_to_type_template)
21945 << TN << ULE->getSourceRange() << IsTypeAliasTemplateDecl;
21947 << IsTypeAliasTemplateDecl;
21950 bool HasAnyDependentTA =
false;
21952 HasAnyDependentTA |= Arg.getArgument().
isDependent();
21964 TST =
Context.getTemplateSpecializationType(
21973 case BuiltinType::Overload: {
21993 case BuiltinType::BoundMember: {
21999 PD =
PDiag(diag::err_dtor_expr_without_call) << 1;
22000 }
else if (
const auto *ME = dyn_cast<MemberExpr>(BME)) {
22001 if (ME->getMemberNameInfo().getName().getNameKind() ==
22003 PD =
PDiag(diag::err_dtor_expr_without_call) << 0;
22011 case BuiltinType::ARCUnbridgedCast: {
22018 case BuiltinType::UnknownAny:
22022 case BuiltinType::PseudoObject:
22025 case BuiltinType::BuiltinFn: {
22030 unsigned BuiltinID = FD->getBuiltinID();
22031 if (BuiltinID == Builtin::BI__noop) {
22033 CK_BuiltinFnToFnPtr)
22040 if (
Context.BuiltinInfo.isInStdNamespace(BuiltinID)) {
22046 ? diag::err_use_of_unaddressable_function
22047 : diag::warn_cxx20_compat_use_of_unaddressable_function);
22048 if (FD->isImplicitlyInstantiable()) {
22075 case BuiltinType::IncompleteMatrixIdx: {
22081 MS->getBase(), MS->getRowIdx(), E->
getExprLoc());
22083 Diag(MS->getRowIdx()->getBeginLoc(), diag::err_matrix_incomplete_index);
22088 case BuiltinType::ArraySection:
22097 case BuiltinType::OMPArrayShaping:
22100 case BuiltinType::OMPIterator:
22104#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
22105 case BuiltinType::Id:
22106#include "clang/Basic/OpenCLImageTypes.def"
22107#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
22108 case BuiltinType::Id:
22109#include "clang/Basic/OpenCLExtensionTypes.def"
22110#define SVE_TYPE(Name, Id, SingletonId) \
22111 case BuiltinType::Id:
22112#include "clang/Basic/AArch64ACLETypes.def"
22113#define PPC_VECTOR_TYPE(Name, Id, Size) \
22114 case BuiltinType::Id:
22115#include "clang/Basic/PPCTypes.def"
22116#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22117#include "clang/Basic/RISCVVTypes.def"
22118#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22119#include "clang/Basic/WebAssemblyReferenceTypes.def"
22120#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
22121#include "clang/Basic/AMDGPUTypes.def"
22122#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22123#include "clang/Basic/HLSLIntangibleTypes.def"
22124#define SPIRV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
22125#include "clang/Basic/SPIRVTypes.def"
22126#define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id:
22127#define PLACEHOLDER_TYPE(Id, SingletonId)
22128#include "clang/AST/BuiltinTypes.def"
22132 llvm_unreachable(
"invalid placeholder type!");
22145 if (!
Context.getLangOpts().RecoveryAST)
22151 if (
T.isNull() ||
T->isUndeducedType() ||
22152 !
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 enumerations for traits support.
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.
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 Decl * getPredefinedExprDecl(Sema &S, DeclContext *DC)
getPredefinedExprDecl - Returns Decl of a given DeclContext that can be used to determine the value o...
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 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, QualType ResultTy, 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 routines for OpenCL.
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.
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.
Represents a pointer type decayed from an array or function type.
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.
DeclContext * getEnclosingNonExpansionStatementContext()
Retrieve the innermost enclosing context that doesn't belong to an expansion statement.
bool isExpansionStmt() const
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)
Designation - Represent a full designation, which is a sequence of designators.
const Designator & getDesignator(unsigned Idx) const
unsigned getNumDesignators() const
Designator - A designator in a C99 designated initializer.
bool isArrayDesignator() const
SourceLocation getEndLoc() const
Returns the end location of this designator.
bool isArrayRangeDesignator() const
bool isFieldDesignator() const
const IdentifierInfo * getFieldDecl() const
SourceLocation getBeginLoc() const
Returns the start location of this designator.
Expr * getArrayIndex() const
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.