61#include "llvm/ADT/STLExtras.h"
62#include "llvm/ADT/STLForwardCompat.h"
63#include "llvm/ADT/StringExtras.h"
64#include "llvm/Support/ConvertUTF.h"
65#include "llvm/Support/SaveAndRestore.h"
66#include "llvm/Support/TimeProfiler.h"
67#include "llvm/Support/TypeSize.h"
91 if (TreatUnavailableAsInvalid &&
101 if (isa<UnresolvedUsingIfExistsDecl>(
D))
109 if (
const auto *A =
D->
getAttr<UnusedAttr>()) {
112 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
113 A->getSemanticSpelling() != UnusedAttr::C23_maybe_unused) {
115 if (DC && !DC->
hasAttr<UnusedAttr>())
116 S.
Diag(
Loc, diag::warn_used_but_marked_unused) <<
D;
124 if (
Decl->isDefaulted()) {
135 auto *Ctor = dyn_cast<CXXConstructorDecl>(
Decl);
136 if (Ctor && Ctor->isInheritingConstructor())
147 if (I->getStorageClass() !=
SC_None)
174 if (!Current->isInlined())
176 if (!Current->isExternallyVisible())
192 if (!DowngradeWarning && UsedFn)
195 S.
Diag(
Loc, DowngradeWarning ? diag::ext_internal_in_extern_inline_quiet
196 : diag::ext_internal_in_extern_inline)
211 Diag(DeclBegin, diag::note_convert_inline_to_static)
218 bool ObjCPropertyAccess,
219 bool AvoidPartialAvailabilityChecks,
221 bool SkipTrailingRequiresClause) {
229 Diag(Suppressed.first, Suppressed.second);
240 if (cast<FunctionDecl>(
D)->isMain())
241 Diag(
Loc, diag::ext_main_used);
248 if (isa<BindingDecl>(
D)) {
249 Diag(
Loc, diag::err_binding_cannot_appear_in_own_initializer)
252 Diag(
Loc, diag::err_auto_variable_cannot_appear_in_own_initializer)
253 <<
D->getDeclName() << cast<VarDecl>(
D)->getType();
260 if (FD->isDeleted()) {
261 auto *Ctor = dyn_cast<CXXConstructorDecl>(FD);
262 if (Ctor && Ctor->isInheritingConstructor())
263 Diag(
Loc, diag::err_deleted_inherited_ctor_use)
265 << Ctor->getInheritedConstructor().getConstructor()->getParent();
268 Diag(
Loc, diag::err_deleted_function_use)
269 << (Msg !=
nullptr) << (Msg ? Msg->
getString() : StringRef());
283 if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) {
292 diag::err_reference_to_function_with_unsatisfied_constraints)
310 if (
auto *
Concept = dyn_cast<ConceptDecl>(
D);
314 if (
auto *MD = dyn_cast<CXXMethodDecl>(
D)) {
316 if (MD->getParent()->isLambda() &&
317 ((isa<CXXConstructorDecl>(MD) &&
318 cast<CXXConstructorDecl>(MD)->isDefaultConstructor()) ||
319 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) {
320 Diag(
Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign)
321 << !isa<CXXConstructorDecl>(MD);
325 auto getReferencedObjCProp = [](
const NamedDecl *
D) ->
327 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D))
342 auto *DRD = dyn_cast<OMPDeclareReductionDecl>(
CurContext);
345 Diag(
Loc, diag::err_omp_wrong_var_in_declare_reduction)
356 if (
LangOpts.OpenMP && isa<VarDecl>(
D) &&
357 !
OpenMP().isOpenMPDeclareMapperVarDeclAllowed(cast<VarDecl>(
D))) {
358 Diag(
Loc, diag::err_omp_declare_mapper_wrong_var)
364 if (
const auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(
D)) {
365 Diag(
Loc, diag::err_use_of_empty_using_if_exists);
366 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here);
371 AvoidPartialAvailabilityChecks, ClassReceiver);
377 if (
D->
hasAttr<AvailableOnlyInDefaultEvalMethodAttr>()) {
383 diag::err_type_available_only_in_default_eval_method)
387 if (
auto *VD = dyn_cast<ValueDecl>(
D))
393 if (
const auto *VD = dyn_cast<VarDecl>(
D))
395 targetDiag(*Locs.begin(), diag::err_thread_unsupported);
398 if (isa<ParmVarDecl>(
D) && isa<RequiresExprBodyDecl>(
D->
getDeclContext()) &&
403 Diag(
Loc, diag::err_requires_expr_parameter_referenced_in_evaluated_context)
419 unsigned NumFormalParams;
423 enum { CK_Function, CK_Method, CK_Block } CalleeKind;
425 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
426 NumFormalParams = MD->param_size();
427 CalleeKind = CK_Method;
428 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
429 NumFormalParams = FD->param_size();
430 CalleeKind = CK_Function;
431 }
else if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
438 CalleeKind = CK_Function;
441 CalleeKind = CK_Block;
446 if (
const auto *proto = dyn_cast<FunctionProtoType>(Fn))
447 NumFormalParams = proto->getNumParams();
458 unsigned NullPos =
Attr->getNullPos();
459 assert((NullPos == 0 || NullPos == 1) &&
"invalid null position on sentinel");
460 NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - NullPos);
463 unsigned NumArgsAfterSentinel =
Attr->getSentinel();
467 if (Args.size() < NumFormalParams + NumArgsAfterSentinel + 1) {
468 Diag(
Loc, diag::warn_not_enough_argument) <<
D->getDeclName();
474 const Expr *SentinelExpr = Args[Args.size() - NumArgsAfterSentinel - 1];
487 std::string NullValue;
491 NullValue =
"nullptr";
495 NullValue =
"(void*) 0";
498 Diag(
Loc, diag::warn_missing_sentinel) <<
int(CalleeKind);
500 Diag(MissingNilLoc, diag::warn_missing_sentinel)
525 assert(!Ty.
isNull() &&
"DefaultFunctionArrayConversion - missing type");
529 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
534 CK_FunctionToPointerDecay).
get();
549 CK_ArrayToPointerDecay);
565 if (UO && UO->getOpcode() == UO_Deref &&
566 UO->getSubExpr()->getType()->isPointerType()) {
568 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
571 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
573 !UO->getType().isVolatileQualified()) {
575 S.
PDiag(diag::warn_indirection_through_null)
576 << UO->getSubExpr()->getSourceRange());
578 S.
PDiag(diag::note_indirection_through_null));
610 if (ObjectSetClass) {
654 assert(!
T.isNull() &&
"r-value conversion on typeless expression?");
696 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()),
")");
713 if (
T.hasQualifiers())
714 T =
T.getUnqualifiedType();
744 T =
Atomic->getValueType().getUnqualifiedType();
769 CK_FunctionToPointerDecay);
792 assert(!Ty.
isNull() &&
"UsualUnaryConversions - missing type");
799 switch (EvalMethod) {
801 llvm_unreachable(
"Unrecognized float evaluation method");
804 llvm_unreachable(
"Float evaluation method should be set by now");
812 CK_FloatingComplexCast)
821 CK_FloatingComplexCast)
869 assert(!Ty.
isNull() &&
"DefaultArgumentPromotion - missing type");
881 if (BTy && (BTy->
getKind() == BuiltinType::Half ||
882 BTy->
getKind() == BuiltinType::Float)) {
885 if (BTy->
getKind() == BuiltinType::Half) {
903 "Unexpected typesize for LongLongTy");
972 if (!
Record->hasNonTrivialCopyConstructor() &&
973 !
Record->hasNonTrivialMoveConstructor() &&
974 !
Record->hasNonTrivialDestructor())
1007 PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
1014 PDiag(diag::warn_pass_class_arg_to_vararg)
1022 PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
1029 diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
1033 PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
1037 << isa<InitListExpr>(
E) << Ty << CT;
1046 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast &&
1048 (FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>()))) {
1087 if (
Call.isInvalid())
1092 if (Comma.isInvalid())
1099 diag::err_call_incomplete_argument))
1117 if (SkipCast)
return false;
1124 CK_IntegralComplexToFloatingComplex);
1142 bool PromotePrecision) {
1147 if (PromotePrecision) {
1152 if (LongerIsComplex)
1164 QualType RHSType,
bool IsCompAssign) {
1189 bool ConvertFloat,
bool ConvertInt) {
1194 CK_IntegralToFloating);
1205 CK_IntegralComplexToFloatingComplex);
1210 CK_FloatingRealToComplex);
1219 QualType RHSType,
bool IsCompAssign) {
1229 else if (!IsCompAssign)
1231 return LHSFloat ? LHSType : RHSType;
1236 if (LHSFloat && RHSFloat) {
1243 assert(order < 0 &&
"illegal float comparison");
1277 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType;
1283 if ((&LHSSem != &llvm::APFloat::PPCDoubleDouble() ||
1284 &RHSSem != &llvm::APFloat::IEEEquad()) &&
1285 (&LHSSem != &llvm::APFloat::IEEEquad() ||
1286 &RHSSem != &llvm::APFloat::PPCDoubleDouble()))
1303 CK_IntegralComplexCast);
1309template <PerformCastFn doLHSCast, PerformCastFn doRHSCast>
1312 QualType RHSType,
bool IsCompAssign) {
1317 if (LHSSigned == RHSSigned) {
1320 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1322 }
else if (!IsCompAssign)
1323 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1325 }
else if (order != (LHSSigned ? 1 : -1)) {
1329 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1331 }
else if (!IsCompAssign)
1332 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1339 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1341 }
else if (!IsCompAssign)
1342 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1351 RHS = (*doRHSCast)(S, RHS.
get(), result);
1353 LHS = (*doLHSCast)(S, LHS.
get(), result);
1363 bool IsCompAssign) {
1367 if (LHSComplexInt && RHSComplexInt) {
1371 handleIntegerConversion<doComplexIntegralCast, doComplexIntegralCast>
1372 (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign);
1377 if (LHSComplexInt) {
1380 handleIntegerConversion<doComplexIntegralCast, doIntegralCast>
1381 (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign);
1384 CK_IntegralRealToComplex);
1389 assert(RHSComplexInt);
1393 handleIntegerConversion<doIntegralCast, doComplexIntegralCast>
1394 (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign);
1399 CK_IntegralRealToComplex);
1408 assert(BTy &&
"Expected a builtin type.");
1410 switch (BTy->getKind()) {
1411 case BuiltinType::ShortFract:
1412 case BuiltinType::UShortFract:
1413 case BuiltinType::SatShortFract:
1414 case BuiltinType::SatUShortFract:
1416 case BuiltinType::Fract:
1417 case BuiltinType::UFract:
1418 case BuiltinType::SatFract:
1419 case BuiltinType::SatUFract:
1421 case BuiltinType::LongFract:
1422 case BuiltinType::ULongFract:
1423 case BuiltinType::SatLongFract:
1424 case BuiltinType::SatULongFract:
1426 case BuiltinType::ShortAccum:
1427 case BuiltinType::UShortAccum:
1428 case BuiltinType::SatShortAccum:
1429 case BuiltinType::SatUShortAccum:
1431 case BuiltinType::Accum:
1432 case BuiltinType::UAccum:
1433 case BuiltinType::SatAccum:
1434 case BuiltinType::SatUAccum:
1436 case BuiltinType::LongAccum:
1437 case BuiltinType::ULongAccum:
1438 case BuiltinType::SatLongAccum:
1439 case BuiltinType::SatULongAccum:
1442 if (BTy->isInteger())
1444 llvm_unreachable(
"Unexpected fixed point or integer type");
1456 "Expected at least one of the operands to be a fixed point type");
1459 "Special fixed point arithmetic operation conversions are only "
1460 "applied to ints or other fixed point types");
1482 QualType ResultTy = LHSTyRank > RHSTyRank ? LHSTy : RHSTy;
1505 REnum = R->isUnscopedEnumerationType();
1507 if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
1510 ? diag::err_arith_conv_enum_float_cxx26
1512 ? diag::warn_arith_conv_enum_float_cxx20
1513 : diag::warn_arith_conv_enum_float)
1516 }
else if (!IsCompAssign && LEnum && REnum &&
1522 DiagID = diag::err_conv_mixed_enum_types_cxx26;
1524 !R->castAs<
EnumType>()->getDecl()->hasNameForLinkage()) {
1529 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
1530 : diag::warn_arith_conv_mixed_anon_enum_types;
1535 ? diag::warn_conditional_mixed_enum_types_cxx20
1536 : diag::warn_conditional_mixed_enum_types;
1541 ? diag::warn_comparison_mixed_enum_types_cxx20
1542 : diag::warn_comparison_mixed_enum_types;
1545 ? diag::warn_arith_conv_mixed_enum_types_cxx20
1546 : diag::warn_arith_conv_mixed_enum_types;
1549 << (
int)ACK << L << R;
1579 LHSType = AtomicLHS->getValueType();
1591 QualType LHSUnpromotedType = LHSType;
1595 if (!LHSBitfieldPromoteTy.
isNull())
1596 LHSType = LHSBitfieldPromoteTy;
1630 return handleIntegerConversion<doIntegralCast, doIntegralCast>
1641 bool PredicateIsExpr,
void *ControllingExprOrType,
1643 unsigned NumAssocs = ArgTypes.size();
1644 assert(NumAssocs == ArgExprs.size());
1647 for (
unsigned i = 0; i < NumAssocs; ++i) {
1656 if (!PredicateIsExpr) {
1660 assert(ControllingType &&
"couldn't get the type out of the parser");
1661 ControllingExprOrType = ControllingType;
1665 KeyLoc, DefaultLoc, RParenLoc, PredicateIsExpr, ControllingExprOrType,
1673 bool PredicateIsExpr,
void *ControllingExprOrType,
1675 unsigned NumAssocs = Types.size();
1676 assert(NumAssocs == Exprs.size());
1677 assert(ControllingExprOrType &&
1678 "Must have either a controlling expression or a controlling type");
1680 Expr *ControllingExpr =
nullptr;
1682 if (PredicateIsExpr) {
1689 reinterpret_cast<Expr *
>(ControllingExprOrType));
1692 ControllingExpr = R.
get();
1695 ControllingType =
reinterpret_cast<TypeSourceInfo *
>(ControllingExprOrType);
1696 if (!ControllingType)
1700 bool TypeErrorFound =
false,
1701 IsResultDependent = ControllingExpr
1704 ContainsUnexpandedParameterPack =
1714 diag::warn_side_effects_unevaluated_context);
1716 for (
unsigned i = 0; i < NumAssocs; ++i) {
1717 if (Exprs[i]->containsUnexpandedParameterPack())
1718 ContainsUnexpandedParameterPack =
true;
1721 if (Types[i]->getType()->containsUnexpandedParameterPack())
1722 ContainsUnexpandedParameterPack =
true;
1724 if (Types[i]->getType()->isDependentType()) {
1725 IsResultDependent =
true;
1738 if (ControllingExpr && Types[i]->getType()->isIncompleteType())
1739 D = diag::err_assoc_type_incomplete;
1740 else if (ControllingExpr && !Types[i]->getType()->isObjectType())
1741 D = diag::err_assoc_type_nonobject;
1742 else if (Types[i]->getType()->isVariablyModifiedType())
1743 D = diag::err_assoc_type_variably_modified;
1744 else if (ControllingExpr) {
1763 unsigned Reason = 0;
1772 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1773 diag::warn_unreachable_association)
1774 << QT << (Reason - 1);
1778 Diag(Types[i]->getTypeLoc().getBeginLoc(),
D)
1779 << Types[i]->getTypeLoc().getSourceRange()
1780 << Types[i]->getType();
1781 TypeErrorFound =
true;
1786 for (
unsigned j = i+1; j < NumAssocs; ++j)
1787 if (Types[j] && !Types[j]->getType()->isDependentType() &&
1789 Types[j]->getType())) {
1790 Diag(Types[j]->getTypeLoc().getBeginLoc(),
1791 diag::err_assoc_compatible_types)
1792 << Types[j]->getTypeLoc().getSourceRange()
1793 << Types[j]->getType()
1794 << Types[i]->getType();
1795 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1796 diag::note_compat_assoc)
1797 << Types[i]->getTypeLoc().getSourceRange()
1798 << Types[i]->getType();
1799 TypeErrorFound =
true;
1809 if (IsResultDependent) {
1810 if (ControllingExpr)
1812 Types, Exprs, DefaultLoc, RParenLoc,
1813 ContainsUnexpandedParameterPack);
1815 Exprs, DefaultLoc, RParenLoc,
1816 ContainsUnexpandedParameterPack);
1820 unsigned DefaultIndex = -1U;
1824 for (
unsigned i = 0; i < NumAssocs; ++i) {
1827 else if (ControllingExpr &&
1830 Types[i]->getType()))
1831 CompatIndices.push_back(i);
1832 else if (ControllingType &&
1835 Types[i]->getType()))
1836 CompatIndices.push_back(i);
1839 auto GetControllingRangeAndType = [](
Expr *ControllingExpr,
1843 if (ControllingExpr)
1852 return std::make_pair(SR, QT);
1858 if (CompatIndices.size() > 1) {
1859 auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
1862 << SR <<
P.second << (
unsigned)CompatIndices.size();
1863 for (
unsigned I : CompatIndices) {
1864 Diag(Types[I]->getTypeLoc().getBeginLoc(),
1865 diag::note_compat_assoc)
1866 << Types[I]->getTypeLoc().getSourceRange()
1867 << Types[I]->getType();
1875 if (DefaultIndex == -1U && CompatIndices.size() == 0) {
1876 auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
1878 Diag(SR.
getBegin(), diag::err_generic_sel_no_match) << SR <<
P.second;
1887 unsigned ResultIndex =
1888 CompatIndices.size() ? CompatIndices[0] : DefaultIndex;
1890 if (ControllingExpr) {
1892 Context, KeyLoc, ControllingExpr, Types, Exprs, DefaultLoc, RParenLoc,
1893 ContainsUnexpandedParameterPack, ResultIndex);
1896 Context, KeyLoc, ControllingType, Types, Exprs, DefaultLoc, RParenLoc,
1897 ContainsUnexpandedParameterPack, ResultIndex);
1903 llvm_unreachable(
"unexpected TokenKind");
1904 case tok::kw___func__:
1906 case tok::kw___FUNCTION__:
1908 case tok::kw___FUNCDNAME__:
1910 case tok::kw___FUNCSIG__:
1912 case tok::kw_L__FUNCTION__:
1914 case tok::kw_L__FUNCSIG__:
1916 case tok::kw___PRETTY_FUNCTION__:
1925 while (DC && !isa<BlockDecl, CapturedDecl, FunctionDecl, ObjCMethodDecl>(DC))
1927 return cast_or_null<Decl>(DC);
1945 assert(Args.size() <= 2 &&
"too many arguments for literal operator");
1948 for (
unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
1949 ArgTy[ArgIdx] = Args[ArgIdx]->getType();
1950 if (ArgTy[ArgIdx]->isArrayType())
1971 std::vector<Token> ExpandedToks;
1977 if (Literal.hadError)
1981 for (
const Token &Tok : StringToks)
1982 StringTokLocs.push_back(Tok.getLocation());
1986 &StringTokLocs[0], StringTokLocs.size());
1988 if (!Literal.getUDSuffix().empty()) {
1991 Literal.getUDSuffixOffset());
1992 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
2014 std::vector<Token> ExpandedToks;
2015 ExpandedToks.reserve(Toks.size());
2016 for (
const Token &Tok : Toks) {
2019 ExpandedToks.emplace_back(Tok);
2022 if (isa<TranslationUnitDecl>(CurrentDecl))
2023 Diag(Tok.getLocation(), diag::ext_predef_outside_function);
2025 Diag(Tok.getLocation(), diag::ext_string_literal_from_predefined)
2028 llvm::raw_svector_ostream
OS(Str);
2029 Token &Exp = ExpandedToks.emplace_back();
2031 if (Tok.getKind() == tok::kw_L__FUNCTION__ ||
2032 Tok.getKind() == tok::kw_L__FUNCSIG__) {
2034 Exp.
setKind(tok::wide_string_literal);
2036 Exp.
setKind(tok::string_literal);
2044 return ExpandedToks;
2049 assert(!StringToks.empty() &&
"Must have at least one string!");
2052 std::vector<Token> ExpandedToks;
2057 if (Literal.hadError)
2061 for (
const Token &Tok : StringToks)
2062 StringTokLocs.push_back(Tok.getLocation());
2066 if (Literal.isWide()) {
2069 }
else if (Literal.isUTF8()) {
2075 }
else if (Literal.isUTF16()) {
2078 }
else if (Literal.isUTF32()) {
2081 }
else if (Literal.isPascal()) {
2094 ? diag::warn_cxx20_compat_utf8_string
2095 : diag::warn_c23_compat_utf8_string);
2101 auto RemovalDiag =
PDiag(diag::note_cxx20_c23_compat_utf8_string_remove_u8);
2103 for (
const Token &Tok : StringToks) {
2104 if (Tok.getKind() == tok::utf8_string_literal) {
2106 RemovalDiagLoc = Tok.getLocation();
2113 Diag(RemovalDiagLoc, RemovalDiag);
2121 Kind, Literal.Pascal, StrTy,
2123 StringTokLocs.size());
2124 if (Literal.getUDSuffix().empty())
2131 Literal.getUDSuffixOffset());
2135 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
2160 Expr *Args[] = { Lit, LenArg };
2179 llvm::APSInt
Value(CharBits, CharIsUnsigned);
2185 for (
unsigned I = 0, N = Lit->
getLength(); I != N; ++I) {
2196 llvm_unreachable(
"unexpected literal operator lookup result");
2200 llvm_unreachable(
"unexpected literal operator lookup result");
2232 auto *DRE = dyn_cast<DeclRefExpr>(VD->
getInit());
2235 auto *Referee = dyn_cast<VarDecl>(DRE->getDecl());
2236 if (!Referee || !Referee->hasGlobalStorage() ||
2237 Referee->hasAttr<CUDADeviceAttr>())
2243 auto *MD = dyn_cast_or_null<CXXMethodDecl>(S.
CurContext);
2244 if (MD && MD->getParent()->isLambda() &&
2245 MD->getOverloadedOperator() == OO_Call && MD->hasAttr<CUDADeviceAttr>() &&
2267 if (
VarDecl *VD = dyn_cast<VarDecl>(
D)) {
2268 if (VD->getType()->isReferenceType() &&
2271 VD->isUsableInConstantExpressions(
Context))
2286 bool RefersToCapturedVariable = isa<VarDecl, BindingDecl>(
D) &&
2290 Context, NNS, TemplateKWLoc,
D, RefersToCapturedVariable, NameInfo, Ty,
2318 const auto *FD = dyn_cast<FieldDecl>(
D);
2319 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(
D))
2320 FD = IFD->getAnonField();
2324 if (FD->isBitField())
2330 if (
const auto *BD = dyn_cast<BindingDecl>(
D))
2331 if (
const auto *BE = BD->getBinding())
2347 Id.TemplateId->NumArgs);
2353 TemplateArgs = &Buffer;
2356 TemplateArgs =
nullptr;
2363 unsigned DiagnosticID,
unsigned DiagnosticSuggestID) {
2370 SemaRef.
Diag(TypoLoc, diag::err_no_member) << Typo << Ctx
2373 SemaRef.
Diag(TypoLoc, DiagnosticID) << Typo;
2378 bool DroppedSpecifier =
2381 ? diag::note_implicit_param_decl
2382 : diag::note_previous_decl;
2385 SemaRef.
PDiag(NoteID));
2388 << Typo << Ctx << DroppedSpecifier
2390 SemaRef.
PDiag(NoteID));
2397 bool isDefaultArgument =
2401 const auto *CurMethod = dyn_cast<CXXMethodDecl>(
CurContext);
2402 bool isInstance = CurMethod && CurMethod->isInstance() &&
2411 unsigned DiagID = diag::err_found_in_dependent_base;
2412 unsigned NoteID = diag::note_member_declared_at;
2414 DiagID =
getLangOpts().MSVCCompat ? diag::ext_found_later_in_class
2415 : diag::err_found_later_in_class;
2417 DiagID = diag::ext_found_in_dependent_base;
2418 NoteID = diag::note_dependent_member_use;
2443 if (isDefaultArgument && ((*R.
begin())->isCXXInstanceMember())) {
2459 unsigned diagnostic = diag::err_undeclared_var_use;
2460 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
2464 diagnostic = diag::err_undeclared_use;
2465 diagnostic_suggest = diag::err_undeclared_use_suggest;
2475 if (isa<CXXRecordDecl>(DC)) {
2476 if (ExplicitTemplateArgs) {
2499 R.
addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
2516 assert(!ExplicitTemplateArgs &&
2517 "Diagnosing an empty lookup with explicit template args!");
2521 emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args,
2522 diagnostic, diagnostic_suggest);
2527 }
else if (S && (Corrected =
2531 bool DroppedSpecifier =
2535 bool AcceptableWithRecovery =
false;
2536 bool AcceptableWithoutRecovery =
false;
2545 dyn_cast<FunctionTemplateDecl>(CD))
2549 else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(CD))
2550 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->
size() == 0)
2556 ND = Best->FoundDecl;
2557 Corrected.setCorrectionDecl(ND);
2561 Corrected.setCorrectionDecl(ND);
2573 Record = cast<CXXRecordDecl>(
2579 AcceptableWithRecovery = isa<ValueDecl>(UnderlyingND) ||
2580 isa<FunctionTemplateDecl>(UnderlyingND);
2586 AcceptableWithoutRecovery = isa<TypeDecl>(UnderlyingND) ||
2588 isa<ObjCInterfaceDecl>(UnderlyingND);
2592 AcceptableWithoutRecovery =
true;
2595 if (AcceptableWithRecovery || AcceptableWithoutRecovery) {
2597 ? diag::note_implicit_param_decl
2598 : diag::note_previous_decl;
2601 PDiag(NoteID), AcceptableWithRecovery);
2605 << DroppedSpecifier << SS.
getRange(),
2606 PDiag(NoteID), AcceptableWithRecovery);
2609 return !AcceptableWithRecovery;
2645 else if (
auto *MD = dyn_cast<CXXMethodDecl>(S.
CurContext))
2653 auto DB = S.
Diag(
Loc, diag::ext_undeclared_unqual_id_with_dependent_base);
2654 DB << NameInfo.
getName() << RD;
2656 if (!ThisType.
isNull()) {
2659 Context,
nullptr, ThisType,
true,
2661 nullptr, NameInfo, TemplateArgs);
2678 bool HasTrailingLParen,
bool IsAddressOfOperand,
2680 bool IsInlineAsmIdentifier,
Token *KeywordReplacement) {
2681 assert(!(IsAddressOfOperand && HasTrailingLParen) &&
2682 "cannot be direct & operand and have a trailing lparen");
2711 if (
auto *VD = dyn_cast<ValueDecl>(R.
getFoundDecl())) {
2725 if (TemplateKWLoc.
isValid() || TemplateArgs) {
2733 false, TemplateKWLoc,
2739 IsAddressOfOperand, TemplateArgs);
2743 !IvarLookupFollowUp);
2749 IsAddressOfOperand, TemplateArgs);
2753 if (IvarLookupFollowUp) {
2768 if (R.
empty() && HasTrailingLParen && II &&
2778 if (R.
empty() && !ADL) {
2781 TemplateKWLoc, TemplateArgs))
2786 if (IsInlineAsmIdentifier)
2796 "Typo correction callback misconfigured");
2807 {},
nullptr, &TE)) {
2808 if (TE && KeywordReplacement) {
2810 auto BestTC = State.Consumer->getNextCorrection();
2811 if (BestTC.isKeyword()) {
2812 auto *II = BestTC.getCorrectionAsIdentifierInfo();
2813 if (State.DiagHandler)
2814 State.DiagHandler(BestTC);
2818 KeywordReplacement->
setLocation(BestTC.getCorrectionRange().getBegin());
2824 return (
Expr*)
nullptr;
2826 State.Consumer->resetCorrectionStream();
2831 assert(!R.
empty() &&
2832 "DiagnoseEmptyLookup returned false but added no results");
2842 if (!
E.isInvalid() && !
E.get())
2849 assert(!R.
empty() || ADL);
2879 if (TemplateArgs || TemplateKWLoc.
isValid()) {
2887 "There should only be one declaration found.");
2915 if (
const auto *CD = dyn_cast<CXXRecordDecl>(DC))
2916 if (CD->isInvalidDecl())
2927 unsigned DiagID = diag::err_typename_missing;
2929 DiagID = diag::ext_typename_missing;
2973 const auto *RD = dyn_cast<CXXRecordDecl>(
Member->getDeclContext());
2981 bool PointerConversions =
false;
2982 if (isa<FieldDecl>(
Member)) {
2986 DestRecordType, FromPtrType
2993 PointerConversions =
true;
2995 DestType = DestRecordType;
2996 FromRecordType = FromType;
2998 }
else if (
const auto *Method = dyn_cast<CXXMethodDecl>(
Member)) {
2999 if (!Method->isImplicitObjectMemberFunction())
3002 DestType = Method->getThisType().getNonReferenceType();
3003 DestRecordType = Method->getFunctionObjectParameterType();
3007 PointerConversions =
true;
3009 FromRecordType = FromType;
3010 DestType = DestRecordType;
3015 if (FromAS != DestAS) {
3020 if (PointerConversions)
3061 if (Qualifier && Qualifier->getAsType()) {
3063 assert(QType->
isRecordType() &&
"lookup done with non-record type");
3073 FromLoc, FromRange, &BasePath))
3076 if (PointerConversions)
3079 VK, &BasePath).
get();
3082 FromRecordType = QRecordType;
3093 FromLoc, FromRange, &BasePath,
3103 bool HasTrailingLParen) {
3105 if (!HasTrailingLParen)
3123 if (
D->isCXXClassMember())
3132 if (isa<UsingShadowDecl>(
D))
3133 D = cast<UsingShadowDecl>(
D)->getTargetDecl();
3141 if (
const auto *FDecl = dyn_cast<FunctionDecl>(
D)) {
3143 if (FDecl->getBuiltinID() && FDecl->isImplicit())
3145 }
else if (!isa<FunctionTemplateDecl>(
D))
3158 bool AcceptInvalid) {
3162 if (isa<TypedefNameDecl>(
D)) {
3163 S.
Diag(
Loc, diag::err_unexpected_typedef) <<
D->getDeclName();
3167 if (isa<ObjCInterfaceDecl>(
D)) {
3168 S.
Diag(
Loc, diag::err_unexpected_interface) <<
D->getDeclName();
3172 if (isa<NamespaceDecl>(
D)) {
3173 S.
Diag(
Loc, diag::err_unexpected_namespace) <<
D->getDeclName();
3184 const auto *FD = dyn_cast<FunctionDecl>(R.
getFoundDecl());
3186 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion());
3191 bool AcceptInvalidDecl) {
3229 bool AcceptInvalidDecl) {
3230 assert(
D &&
"Cannot refer to a NULL declaration");
3231 assert(!isa<FunctionTemplateDecl>(
D) &&
3232 "Cannot refer unambiguously to a function template");
3250 if (!isa<ValueDecl, UnresolvedUsingIfExistsDecl>(
D)) {
3263 auto *VD = cast<ValueDecl>(
D);
3266 if (VD->isInvalidDecl() && !AcceptInvalidDecl)
3272 if (
auto *IndirectField = dyn_cast<IndirectFieldDecl>(VD);
3273 IndirectField && !IndirectField->isCXXClassMember())
3285 type =
type.getNonPackExpansionType();
3289#define ABSTRACT_DECL(kind)
3290#define VALUE(type, base)
3291#define DECL(type, base) case Decl::type:
3292#include "clang/AST/DeclNodes.inc"
3293 llvm_unreachable(
"invalid value decl kind");
3296 case Decl::ObjCAtDefsField:
3297 llvm_unreachable(
"forming non-member reference to ivar?");
3301 case Decl::EnumConstant:
3302 case Decl::UnresolvedUsingValue:
3303 case Decl::OMPDeclareReduction:
3304 case Decl::OMPDeclareMapper:
3313 case Decl::IndirectField:
3314 case Decl::ObjCIvar:
3316 "building reference to field in C?");
3326 case Decl::NonTypeTemplateParm: {
3328 type = reftype->getPointeeType();
3338 if (
type->isRecordType()) {
3339 type =
type.getUnqualifiedType().withConst();
3352 case Decl::VarTemplateSpecialization:
3353 case Decl::VarTemplatePartialSpecialization:
3354 case Decl::Decomposition:
3356 case Decl::OMPCapturedExpr:
3359 type->isVoidType()) {
3365 case Decl::ImplicitParam:
3366 case Decl::ParmVar: {
3376 if (!CapturedType.
isNull())
3377 type = CapturedType;
3382 case Decl::Function: {
3383 if (
unsigned BID = cast<FunctionDecl>(VD)->getBuiltinID()) {
3412 if (!cast<FunctionDecl>(VD)->hasPrototype() && isa<FunctionProtoType>(fty))
3421 case Decl::CXXDeductionGuide:
3422 llvm_unreachable(
"building reference to deduction guide");
3424 case Decl::MSProperty:
3426 case Decl::TemplateParamObject:
3432 case Decl::UnnamedGlobalConstant:
3436 case Decl::CXXMethod:
3441 dyn_cast<FunctionProtoType>(VD->getType()))
3449 if (cast<CXXMethodDecl>(VD)->isStatic()) {
3455 case Decl::CXXConversion:
3456 case Decl::CXXDestructor:
3457 case Decl::CXXConstructor:
3469 if (VD->isInvalidDecl() &&
E)
3476 Target.resize(CharByteWidth * (Source.size() + 1));
3477 char *ResultPtr = &
Target[0];
3478 const llvm::UTF8 *ErrorPtr;
3480 llvm::ConvertUTF8toWide(CharByteWidth, Source, ResultPtr, ErrorPtr);
3490 Diag(
Loc, diag::ext_predef_outside_function);
3496 if (cast<DeclContext>(currentDecl)->isDependentContext())
3501 bool ForceElaboratedPrinting =
3505 unsigned Length = Str.length();
3507 llvm::APInt LengthI(32, Length + 1);
3547 if (Literal.hadError())
3551 if (Literal.isWide())
3557 else if (Literal.isUTF16())
3559 else if (Literal.isUTF32())
3568 if (Literal.isWide())
3570 else if (Literal.isUTF16())
3572 else if (Literal.isUTF32())
3574 else if (Literal.isUTF8())
3580 if (Literal.getUDSuffix().empty())
3590 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_character_udl));
3601 llvm::APInt(IntSize, Val,
true),
3609 using llvm::APFloat;
3610 APFloat Val(Format);
3613 if (RM == llvm::RoundingMode::Dynamic)
3614 RM = llvm::RoundingMode::NearestTiesToEven;
3615 APFloat::opStatus result = Literal.GetFloatValue(Val, RM);
3619 if ((result & APFloat::opOverflow) ||
3620 ((result & APFloat::opUnderflow) && Val.isZero())) {
3621 unsigned diagnostic;
3623 if (result & APFloat::opOverflow) {
3624 diagnostic = diag::warn_float_overflow;
3625 APFloat::getLargest(Format).toString(buffer);
3627 diagnostic = diag::warn_float_underflow;
3628 APFloat::getSmallest(Format).toString(buffer);
3631 S.
Diag(
Loc, diagnostic) << Ty << buffer.str();
3634 bool isExact = (result == APFloat::opOK);
3639 assert(
E &&
"Invalid expression");
3646 Diag(
E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT;
3650 llvm::APSInt ValueAPS;
3661 bool ValueIsPositive =
3662 AllowZero ? ValueAPS.isNonNegative() : ValueAPS.isStrictlyPositive();
3663 if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
3665 <<
toString(ValueAPS, 10) << ValueIsPositive;
3685 SpellingBuffer.resize(Tok.
getLength() + 1);
3696 if (Literal.hadError)
3699 if (Literal.hasUDSuffix()) {
3707 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_numeric_udl));
3710 if (Literal.isFloatingLiteral()) {
3735 !Literal.isImaginary)) {
3744 if (Literal.isFloatingLiteral()) {
3748 if (Literal.GetIntegerValue(ResultVal))
3761 unsigned Length = Literal.getUDSuffixOffset();
3768 false, StrTy, &TokLoc, 1);
3779 bool CharIsUnsigned =
Context.
CharTy->isUnsignedIntegerType();
3780 llvm::APSInt
Value(CharBits, CharIsUnsigned);
3781 for (
unsigned I = 0, N = Literal.getUDSuffixOffset(); I != N; ++I) {
3782 Value = TokSpelling[I];
3790 llvm_unreachable(
"unexpected literal operator lookup result");
3796 if (Literal.isFixedPointLiteral()) {
3799 if (Literal.isAccum) {
3800 if (Literal.isHalf) {
3802 }
else if (Literal.isLong) {
3807 }
else if (Literal.isFract) {
3808 if (Literal.isHalf) {
3810 }
else if (Literal.isLong) {
3819 bool isSigned = !Literal.isUnsigned;
3823 llvm::APInt Val(bit_width, 0, isSigned);
3824 bool Overflowed = Literal.GetFixedPointValue(Val, scale);
3825 bool ValIsZero = Val.isZero() && !Overflowed;
3828 if (Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
3834 else if (Val.ugt(MaxVal) || Overflowed)
3839 }
else if (Literal.isFloatingLiteral()) {
3841 if (Literal.isHalf){
3849 }
else if (Literal.isFloat)
3851 else if (Literal.isLong)
3853 else if (Literal.isFloat16)
3855 else if (Literal.isFloat128)
3877 }
else if (!Literal.isIntegerLiteral()) {
3883 if (Literal.isSizeT)
3886 ? diag::warn_cxx20_compat_size_t_suffix
3887 : diag::ext_cxx23_size_t_suffix
3888 : diag::err_cxx23_size_t_suffix);
3895 if (Literal.isBitInt)
3899 : diag::ext_c23_bitint_suffix);
3908 unsigned BitsNeeded =
3909 Literal.isBitInt ? llvm::APInt::getSufficientBitsNeeded(
3910 Literal.getLiteralDigits(), Literal.getRadix())
3912 llvm::APInt ResultVal(BitsNeeded, 0);
3914 if (Literal.GetIntegerValue(ResultVal)) {
3920 "long long is not intmax_t?");
3927 bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
3934 Literal.isLong =
true;
3935 Literal.isLongLong =
false;
3942 if (Literal.MicrosoftInteger) {
3943 if (Literal.MicrosoftInteger == 8 && !Literal.isUnsigned) {
3947 Width = Literal.MicrosoftInteger;
3949 !Literal.isUnsigned);
3955 if (Literal.isBitInt) {
3958 Width = std::max(ResultVal.getActiveBits(), 1u) +
3959 (Literal.isUnsigned ? 0u : 1u);
3963 unsigned int MaxBitIntWidth =
3965 if (Width > MaxBitIntWidth) {
3967 << Literal.isUnsigned;
3968 Width = MaxBitIntWidth;
3975 ResultVal = ResultVal.zextOrTrunc(Width);
3980 if (Literal.isSizeT) {
3981 assert(!Literal.MicrosoftInteger &&
3982 "size_t literals can't be Microsoft literals");
3987 if (ResultVal.isIntN(SizeTSize)) {
3989 if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
3991 else if (AllowUnsigned)
3997 if (Ty.
isNull() && !Literal.isLong && !Literal.isLongLong &&
4003 if (ResultVal.isIntN(IntSize)) {
4005 if (!Literal.isUnsigned && ResultVal[IntSize-1] == 0)
4007 else if (AllowUnsigned)
4014 if (Ty.
isNull() && !Literal.isLongLong && !Literal.isSizeT) {
4018 if (ResultVal.isIntN(LongSize)) {
4020 if (!Literal.isUnsigned && ResultVal[LongSize-1] == 0)
4022 else if (AllowUnsigned)
4027 const unsigned LongLongSize =
4032 ? diag::warn_old_implicitly_unsigned_long_cxx
4034 ext_old_implicitly_unsigned_long_cxx
4035 : diag::warn_old_implicitly_unsigned_long)
4036 << (LongLongSize > LongSize ? 0
4045 if (Ty.
isNull() && !Literal.isSizeT) {
4049 if (ResultVal.isIntN(LongLongSize)) {
4053 if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
4054 (
getLangOpts().MSVCCompat && Literal.isLongLong)))
4056 else if (AllowUnsigned)
4058 Width = LongLongSize;
4064 ? diag::warn_cxx98_compat_longlong
4065 : diag::ext_cxx11_longlong);
4075 if (Literal.isSizeT)
4077 << Literal.isUnsigned;
4080 diag::ext_integer_literal_too_large_for_signed);
4085 if (ResultVal.getBitWidth() != Width)
4086 ResultVal = ResultVal.trunc(Width);
4092 if (Literal.isImaginary) {
4099 DiagId = diag::ext_gnu_imaginary_constant;
4101 DiagId = diag::warn_c23_compat_imaginary_constant;
4103 DiagId = diag::ext_c2y_imaginary_constant;
4110 assert(
E &&
"ActOnParenExpr() missing expr");
4126 S.
Diag(
Loc, diag::err_vecstep_non_scalar_vector_type)
4132 "Scalar types should always be complete");
4141 return S.
Diag(
Loc, diag::err_builtin_non_vector_type)
4143 <<
"__builtin_vectorelements" <<
T << ArgRange;
4156 S.
Diag(
Loc, diag::err_ptrauth_type_disc_undiscriminated) <<
T << ArgRange;
4173 (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
4174 TraitKind == UETT_PreferredAlignOf)) {
4176 S.
Diag(
Loc, diag::ext_sizeof_alignof_function_type)
4184 unsigned DiagID = S.
LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
4185 : diag::ext_sizeof_alignof_void_type;
4200 S.
Diag(
Loc, diag::err_sizeof_nonfragile_interface)
4201 <<
T << (TraitKind == UETT_SizeOf)
4218 const auto *ICE = dyn_cast<ImplicitCastExpr>(
E);
4219 if (!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay)
4222 S.
Diag(
Loc, diag::warn_sizeof_array_decay) << ICE->getSourceRange()
4224 << ICE->getSubExpr()->getType();
4232 bool IsUnevaluatedOperand =
4233 (ExprKind == UETT_SizeOf || ExprKind == UETT_DataSizeOf ||
4234 ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4235 ExprKind == UETT_VecStep);
4236 if (IsUnevaluatedOperand) {
4254 if (ExprKind == UETT_VecStep)
4258 if (ExprKind == UETT_VectorElements)
4280 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4283 diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4288 E, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4307 if (ExprKind == UETT_SizeOf) {
4308 if (
const auto *DeclRef = dyn_cast<DeclRefExpr>(
E->
IgnoreParens())) {
4309 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
4310 QualType OType = PVD->getOriginalType();
4315 Diag(PVD->getLocation(), diag::note_declared_at);
4323 if (
const auto *BO = dyn_cast<BinaryOperator>(
E->
IgnoreParens())) {
4347 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Inner)) {
4349 }
else if (
MemberExpr *ME = dyn_cast<MemberExpr>(Inner)) {
4350 D = ME->getMemberDecl();
4370 if (
FieldDecl *FD = dyn_cast_or_null<FieldDecl>(
D)) {
4373 if (!FD->getParent()->isCompleteDefinition()) {
4383 if (!FD->getType()->isReferenceType())
4403 assert(CSI !=
nullptr);
4407 const Type *Ty =
T.getTypePtr();
4409#define TYPE(Class, Base)
4410#define ABSTRACT_TYPE(Class, Base)
4411#define NON_CANONICAL_TYPE(Class, Base)
4412#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4413#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
4414#include "clang/AST/TypeNodes.inc"
4421 case Type::ExtVector:
4422 case Type::ConstantMatrix:
4425 case Type::TemplateSpecialization:
4426 case Type::ObjCObject:
4427 case Type::ObjCInterface:
4428 case Type::ObjCObjectPointer:
4429 case Type::ObjCTypeParam:
4432 llvm_unreachable(
"type class is never variably-modified!");
4433 case Type::Elaborated:
4434 T = cast<ElaboratedType>(Ty)->getNamedType();
4436 case Type::Adjusted:
4437 T = cast<AdjustedType>(Ty)->getOriginalType();
4442 case Type::ArrayParameter:
4443 T = cast<ArrayParameterType>(Ty)->getElementType();
4448 case Type::BlockPointer:
4451 case Type::LValueReference:
4452 case Type::RValueReference:
4455 case Type::MemberPointer:
4458 case Type::ConstantArray:
4459 case Type::IncompleteArray:
4461 T = cast<ArrayType>(Ty)->getElementType();
4463 case Type::VariableArray: {
4471 (isa<CapturedRegionScopeInfo>(CSI) || isa<LambdaScopeInfo>(CSI)))
4477 case Type::FunctionProto:
4478 case Type::FunctionNoProto:
4483 case Type::UnaryTransform:
4484 case Type::Attributed:
4485 case Type::BTFTagAttributed:
4486 case Type::HLSLAttributedResource:
4487 case Type::SubstTemplateTypeParm:
4488 case Type::MacroQualified:
4489 case Type::CountAttributed:
4491 T =
T.getSingleStepDesugaredType(Context);
4494 T = cast<TypedefType>(Ty)->
desugar();
4496 case Type::Decltype:
4497 T = cast<DecltypeType>(Ty)->
desugar();
4499 case Type::PackIndexing:
4500 T = cast<PackIndexingType>(Ty)->
desugar();
4503 T = cast<UsingType>(Ty)->
desugar();
4506 case Type::DeducedTemplateSpecialization:
4507 T = cast<DeducedType>(Ty)->getDeducedType();
4509 case Type::TypeOfExpr:
4510 T = cast<TypeOfExprType>(Ty)->getUnderlyingExpr()->getType();
4513 T = cast<AtomicType>(Ty)->getValueType();
4539 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4540 ExprKind == UETT_OpenMPRequiredSimdAlign) {
4546 ? diag::warn_c2y_compat_alignof_incomplete_array
4547 : diag::ext_c2y_alignof_incomplete_array);
4551 if (ExprKind == UETT_VecStep)
4554 if (ExprKind == UETT_VectorElements)
4558 if (ExprKind == UETT_PtrAuthTypeDiscriminator)
4568 OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4573 Diag(OpLoc, diag::err_sizeof_alignof_function_type) << KWName << ExprRange;
4581 Diag(OpLoc, diag::err_wasm_table_invalid_uett_operand)
4595 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
4599 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
4600 DC = LSI->CallOperator;
4601 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
4602 DC = CRSI->TheCapturedDecl;
4603 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
4655 }
else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4657 }
else if (ExprKind == UETT_VecStep) {
4659 }
else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
4665 }
else if (ExprKind == UETT_VectorElements) {
4708 UETT_AlignOf, KWName);
4721 if (
V.get()->isTypeDependent())
4733 return CT->getElementType();
4736 if (
V.get()->getType()->isArithmeticType())
4737 return V.get()->getType();
4742 if (PR.
get() !=
V.get()) {
4748 S.
Diag(
Loc, diag::err_realimag_invalid_type) <<
V.get()->getType()
4749 << (IsReal ?
"__real" :
"__imag");
4760 default: llvm_unreachable(
"Unknown unary op!");
4761 case tok::plusplus: Opc = UO_PostInc;
break;
4762 case tok::minusminus: Opc = UO_PostDec;
break;
4781 !S.
LangOpts.ObjCSubscriptingLegacyRuntime)
4784 S.
Diag(opLoc, diag::err_arithmetic_nonfragile_interface)
4791 auto *BaseNoParens =
Base->IgnoreParens();
4792 if (
auto *MSProp = dyn_cast<MSPropertyRefExpr>(BaseNoParens))
4793 return MSProp->getPropertyDecl()->getType()->isArrayType();
4794 return isa<MSPropertySubscriptExpr>(BaseNoParens);
4814 if (RTy->isIntegralOrUnscopedEnumerationType()) {
4816 Result = PT->getPointeeType();
4818 Result = AT->getElementType();
4821 Result = PT->getPointeeType();
4823 Result = AT->getElementType();
4836 auto *AS = cast<ArraySectionExpr>(base);
4837 if (AS->isOMPArraySection())
4849 if (isa<ParenListExpr>(base)) {
4853 base = result.
get();
4860 auto CheckAndReportCommaError = [
this, base, rbLoc](
Expr *
E) {
4861 if (isa<BinaryOperator>(
E) && cast<BinaryOperator>(
E)->isCommaOp()) {
4872 !isa<MatrixSubscriptExpr>(base)) {
4873 Diag(base->
getExprLoc(), diag::err_matrix_separate_incomplete_index)
4879 auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
4880 if (matSubscriptE) {
4881 assert(ArgExprs.size() == 1);
4882 if (CheckAndReportCommaError(ArgExprs.front()))
4885 assert(matSubscriptE->isIncomplete() &&
4886 "base has to be an incomplete matrix subscript");
4888 matSubscriptE->getRowIdx(),
4889 ArgExprs.front(), rbLoc);
4897 CheckInvalidBuiltinCountedByRef(base, ArraySubscriptKind);
4904 bool IsMSPropertySubscript =
false;
4907 if (!IsMSPropertySubscript) {
4911 base = result.
get();
4917 assert(ArgExprs.size() == 1);
4918 if (CheckAndReportCommaError(ArgExprs.front()))
4926 Expr *idx = ArgExprs[0];
4927 if ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) ||
4928 (isa<CXXOperatorCallExpr>(idx) &&
4929 cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma)) {
4935 if (ArgExprs.size() == 1 &&
4936 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) {
4940 ArgExprs[0] = result.
get();
4950 !isa<PackExpansionExpr>(ArgExprs[0])) {
4952 base, ArgExprs.front(),
4965 if (IsMSPropertySubscript) {
4966 assert(ArgExprs.size() == 1);
4984 (ArgExprs.size() != 1 || isa<PackExpansionExpr>(ArgExprs[0]) ||
4985 ArgExprs[0]->getType()->isRecordType())))) {
4992 if (!Res.
isInvalid() && isa<ArraySubscriptExpr>(Res.
get()))
4993 CheckSubscriptAccessOfNoDeref(cast<ArraySubscriptExpr>(Res.
get()));
5003 return InitSeq.
Perform(*
this, Entity, Kind,
E);
5017 RowIdx = RowR.
get();
5032 ColumnIdx = ColumnR.
get();
5037 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5038 bool IsColumnIdx) ->
Expr * {
5046 if (std::optional<llvm::APSInt> Idx =
5048 if ((*Idx < 0 || *Idx >=
Dim)) {
5050 << IsColumnIdx <<
Dim;
5057 "should be able to convert any integer type to size type");
5058 return ConvExpr.
get();
5062 RowIdx = IsIndexValid(RowIdx, MTy->getNumRows(),
false);
5063 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(),
true);
5064 if (!RowIdx || !ColumnIdx)
5068 MTy->getElementType(), RBLoc);
5071void Sema::CheckAddressOfNoDeref(
const Expr *
E) {
5078 while ((
Member = dyn_cast<MemberExpr>(StrippedExpr)) && !
Member->isArrow())
5079 StrippedExpr =
Member->getBase()->IgnoreParenImpCasts();
5081 LastRecord.PossibleDerefs.erase(StrippedExpr);
5092 if (isa<ArrayType>(ResultTy))
5095 if (ResultTy->
hasAttr(attr::NoDeref)) {
5096 LastRecord.PossibleDerefs.insert(
E);
5104 if (!(isa<ArrayType>(BaseTy) || isa<PointerType>(BaseTy)))
5109 while ((
Member = dyn_cast<MemberExpr>(
Base->IgnoreParenCasts())) &&
5113 if (
const auto *Ptr = dyn_cast<PointerType>(
Base->getType())) {
5114 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
5115 LastRecord.PossibleDerefs.insert(
E);
5131 for (
auto *Op : {LHSExp, RHSExp}) {
5132 Op = Op->IgnoreImplicit();
5133 if (Op->getType()->isArrayType() && !Op->isLValue())
5156 Expr *BaseExpr, *IndexExpr;
5191 Diag(LLoc, diag::err_subscript_nonfragile_interface)
5215 LHSExp = Materialized.
get();
5224 Qualifiers Combined = BaseQuals + MemberQuals;
5225 if (Combined != MemberQuals)
5236 CK_ArrayToPointerDecay).
get();
5242 }
else if (RHSTy->isArrayType()) {
5247 CK_ArrayToPointerDecay).
get();
5254 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_value)
5259 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_not_integer)
5265 std::optional<llvm::APSInt> IntegerContantExpr =
5267 if (!IntegerContantExpr.has_value() ||
5268 IntegerContantExpr.value().isNegative())
5284 Diag(LLoc, diag::ext_gnu_subscript_void_type)
5295 diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
5308 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
5312 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
5313 DC = LSI->CallOperator;
5314 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
5315 DC = CRSI->TheCapturedDecl;
5316 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
5334 bool SkipImmediateInvocations) {
5336 assert(!RewrittenInit &&
"Should not have a rewritten init expression yet");
5340 Diag(Param->
getBeginLoc(), diag::err_recursive_default_argument) << FD;
5341 Diag(CallLoc, diag::note_recursive_default_argument_used_here);
5346 Diag(CallLoc, diag::err_use_of_default_argument_to_function_declared_later)
5349 diag::note_default_argument_declared_here);
5354 assert(!RewrittenInit &&
"Should not have a rewitten init expression yet");
5360 assert(
Init &&
"default argument but no initializer?");
5369 if (
auto *InitWithCleanup = dyn_cast<ExprWithCleanups>(
Init)) {
5376 assert(!InitWithCleanup->getNumObjects() &&
5377 "default argument expression has capturing blocks?");
5390 SkipImmediateInvocations;
5400 ShouldVisitImplicitCode =
true;
5403 bool HasImmediateCalls =
false;
5407 HasImmediateCalls |= FD->isImmediateFunction();
5413 HasImmediateCalls |= FD->isImmediateFunction();
5422 HasImmediateCalls =
true;
5433 return VisitCXXMethodDecl(
E->getCallOperator());
5437 return TraverseStmt(
E->getExpr());
5441 return TraverseStmt(
E->getExpr());
5467 if (DC == SemaRef.CurContext)
5478 if (!SemaRef.CurrentInstantiationScope ||
5480 DC = SemaRef.CurContext;
5482 return getDerived().RebuildSourceLocExpr(
5490 assert(Param->
hasDefaultArg() &&
"can't build nonexistent default arg");
5494 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5495 InitializationContext =
5497 if (!InitializationContext.has_value())
5498 InitializationContext.emplace(CallLoc, Param,
CurContext);
5524 if (!NestedDefaultChecking)
5525 V.TraverseDecl(Param);
5529 if (
V.HasImmediateCalls ||
5530 (NeedRebuild && isa_and_present<ExprWithCleanups>(Param->
getInit()))) {
5531 if (
V.HasImmediateCalls)
5541 Res = Immediate.TransformInitializer(Param->
getInit(),
5555 CallLoc, FD, Param,
Init,
5556 NestedDefaultChecking))
5560 Init, InitializationContext->Context);
5567 auto *ParentRD = cast<CXXRecordDecl>(Field->getParent());
5570 ClassPattern->
lookup(Field->getDeclName());
5571 auto Rng = llvm::make_filter_range(
5572 Lookup, [](
auto &&L) {
return isa<FieldDecl>(*L); });
5578 return cast<FieldDecl>(*Rng.begin());
5582 assert(Field->hasInClassInitializer());
5586 auto *ParentRD = cast<CXXRecordDecl>(Field->getParent());
5588 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5589 InitializationContext =
5591 if (!InitializationContext.has_value())
5601 if (!Field->getInClassInitializer()) {
5607 assert(Pattern &&
"We must have set the Pattern!");
5611 Field->setInvalidDecl();
5623 if (!NestedDefaultChecking)
5624 V.TraverseDecl(Field);
5633 bool ContainsAnyTemporaries =
5634 isa_and_present<ExprWithCleanups>(Field->getInClassInitializer());
5635 if (Field->getInClassInitializer() &&
5636 !Field->getInClassInitializer()->containsErrors() &&
5637 (
V.HasImmediateCalls || (NeedRebuild && ContainsAnyTemporaries))) {
5641 NestedDefaultChecking;
5649 Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
5655 Field->setInvalidDecl();
5661 if (Field->getInClassInitializer()) {
5663 if (!NestedDefaultChecking)
5674 Field->setInvalidDecl();
5680 Field, InitializationContext->Context,
5699 Diag(
Loc, diag::err_default_member_initializer_not_yet_parsed)
5700 << OutermostClass << Field;
5701 Diag(Field->getEndLoc(),
5702 diag::note_default_member_initializer_not_yet_parsed);
5705 Field->setInvalidDecl();
5713 if (isa_and_nonnull<CXXConstructorDecl>(FDecl))
5715 else if (Fn && Fn->getType()->isBlockPointerType())
5718 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
5719 if (Method->isInstance())
5734 FunctionName(FuncName) {}
5736 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
5745 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
5746 return std::make_unique<FunctionCallCCC>(*
this);
5766 if (
NamedDecl *ND = Corrected.getFoundDecl()) {
5767 if (Corrected.isOverloaded()) {
5777 ND = Best->FoundDecl;
5778 Corrected.setCorrectionDecl(ND);
5784 ND = ND->getUnderlyingDecl();
5785 if (isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND))
5796 if (!isa<ParenExpr>(Fn))
5799 Fn = Fn->IgnoreParens();
5801 auto *UO = dyn_cast<UnaryOperator>(Fn);
5802 if (!UO || UO->getOpcode() != clang::UO_AddrOf)
5804 if (
auto *DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr()->IgnoreParens())) {
5805 return DRE->hasQualifier();
5807 if (
auto *OVL = dyn_cast<OverloadExpr>(UO->getSubExpr()->IgnoreParens()))
5808 return OVL->getQualifier();
5818 bool IsExecConfig) {
5829 bool HasExplicitObjectParameter =
5831 unsigned ExplicitObjectParameterOffset = HasExplicitObjectParameter ? 1 : 0;
5835 unsigned FnKind = Fn->getType()->isBlockPointerType()
5842 if (Args.size() < NumParams) {
5843 if (Args.size() < MinArgs) {
5848 ? diag::err_typecheck_call_too_few_args_suggest
5849 : diag::err_typecheck_call_too_few_args_at_least_suggest;
5852 << FnKind << MinArgs - ExplicitObjectParameterOffset
5853 <<
static_cast<unsigned>(Args.size()) -
5854 ExplicitObjectParameterOffset
5856 }
else if (MinArgs - ExplicitObjectParameterOffset == 1 && FDecl &&
5861 ? diag::err_typecheck_call_too_few_args_one
5862 : diag::err_typecheck_call_too_few_args_at_least_one)
5863 << FnKind << FDecl->
getParamDecl(ExplicitObjectParameterOffset)
5864 << HasExplicitObjectParameter << Fn->getSourceRange();
5867 ? diag::err_typecheck_call_too_few_args
5868 : diag::err_typecheck_call_too_few_args_at_least)
5869 << FnKind << MinArgs - ExplicitObjectParameterOffset
5870 <<
static_cast<unsigned>(Args.size()) -
5871 ExplicitObjectParameterOffset
5872 << HasExplicitObjectParameter << Fn->getSourceRange();
5875 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
5883 assert((
Call->getNumArgs() == NumParams) &&
5884 "We should have reserved space for the default arguments before!");
5889 if (Args.size() > NumParams) {
5895 ? diag::err_typecheck_call_too_many_args_suggest
5896 : diag::err_typecheck_call_too_many_args_at_most_suggest;
5899 << FnKind << NumParams - ExplicitObjectParameterOffset
5900 <<
static_cast<unsigned>(Args.size()) -
5901 ExplicitObjectParameterOffset
5903 }
else if (NumParams - ExplicitObjectParameterOffset == 1 && FDecl &&
5906 Diag(Args[NumParams]->getBeginLoc(),
5907 MinArgs == NumParams
5908 ? diag::err_typecheck_call_too_many_args_one
5909 : diag::err_typecheck_call_too_many_args_at_most_one)
5910 << FnKind << FDecl->
getParamDecl(ExplicitObjectParameterOffset)
5911 <<
static_cast<unsigned>(Args.size()) -
5912 ExplicitObjectParameterOffset
5913 << HasExplicitObjectParameter << Fn->getSourceRange()
5915 Args.back()->getEndLoc());
5917 Diag(Args[NumParams]->getBeginLoc(),
5918 MinArgs == NumParams
5919 ? diag::err_typecheck_call_too_many_args
5920 : diag::err_typecheck_call_too_many_args_at_most)
5921 << FnKind << NumParams - ExplicitObjectParameterOffset
5922 <<
static_cast<unsigned>(Args.size()) -
5923 ExplicitObjectParameterOffset
5924 << HasExplicitObjectParameter << Fn->getSourceRange()
5926 Args.back()->getEndLoc());
5929 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
5934 Call->shrinkNumArgs(NumParams);
5945 unsigned TotalNumArgs = AllArgs.size();
5946 for (
unsigned i = 0; i < TotalNumArgs; ++i)
5947 Call->setArg(i, AllArgs[i]);
5949 Call->computeDependence();
5958 bool IsListInitialization) {
5963 for (
unsigned i = FirstParam; i < NumParams; i++) {
5968 if (ArgIx < Args.size()) {
5969 Arg = Args[ArgIx++];
5972 diag::err_call_incomplete_argument, Arg))
5976 bool CFAudited =
false;
5978 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
5979 (!Param || !Param->
hasAttr<CFConsumedAttr>()))
5982 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
5983 (!Param || !Param->
hasAttr<CFConsumedAttr>()))
5989 BE->getBlockDecl()->setDoesNotEscape();
6009 Entity,
SourceLocation(), Arg, IsListInitialization, AllowExplicit);
6015 assert(Param &&
"can't use default arguments without a known callee");
6027 CheckArrayAccess(Arg);
6032 AllArgs.push_back(Arg);
6041 for (
Expr *A : Args.slice(ArgIx)) {
6045 AllArgs.push_back(arg.get());
6050 for (
Expr *A : Args.slice(ArgIx)) {
6053 AllArgs.push_back(Arg.
get());
6058 for (
Expr *A : Args.slice(ArgIx))
6059 CheckArrayAccess(A);
6067 TL = DTL.getOriginalLoc();
6070 << ATL.getLocalSourceRange();
6076 const Expr *ArgExpr) {
6106 Diag(CallLoc, diag::warn_static_array_too_small)
6114 std::optional<CharUnits> ArgSize =
6116 std::optional<CharUnits> ParmSize =
6118 if (ArgSize && ParmSize && *ArgSize < *ParmSize) {
6119 Diag(CallLoc, diag::warn_static_array_too_small)
6121 << (
unsigned)ParmSize->getQuantity() << 1;
6135 if (!placeholder)
return false;
6137 switch (placeholder->
getKind()) {
6139#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
6140 case BuiltinType::Id:
6141#include "clang/Basic/OpenCLImageTypes.def"
6142#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
6143 case BuiltinType::Id:
6144#include "clang/Basic/OpenCLExtensionTypes.def"
6147#define SVE_TYPE(Name, Id, SingletonId) \
6148 case BuiltinType::Id:
6149#include "clang/Basic/AArch64SVEACLETypes.def"
6150#define PPC_VECTOR_TYPE(Name, Id, Size) \
6151 case BuiltinType::Id:
6152#include "clang/Basic/PPCTypes.def"
6153#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6154#include "clang/Basic/RISCVVTypes.def"
6155#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6156#include "clang/Basic/WebAssemblyReferenceTypes.def"
6157#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
6158#include "clang/Basic/AMDGPUTypes.def"
6159#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6160#include "clang/Basic/HLSLIntangibleTypes.def"
6161#define PLACEHOLDER_TYPE(ID, SINGLETON_ID)
6162#define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID:
6163#include "clang/AST/BuiltinTypes.def"
6166 case BuiltinType::UnresolvedTemplate:
6169 case BuiltinType::Overload:
6174 case BuiltinType::ARCUnbridgedCast:
6178 case BuiltinType::PseudoObject:
6183 case BuiltinType::UnknownAny:
6187 case BuiltinType::BoundMember:
6188 case BuiltinType::BuiltinFn:
6189 case BuiltinType::IncompleteMatrixIdx:
6190 case BuiltinType::ArraySection:
6191 case BuiltinType::OMPArrayShaping:
6192 case BuiltinType::OMPIterator:
6196 llvm_unreachable(
"bad builtin type kind");
6202 bool hasInvalid =
false;
6203 for (
size_t i = 0, e = args.size(); i != e; i++) {
6206 if (result.
isInvalid()) hasInvalid =
true;
6207 else args[i] = result.
get();
6235 bool NeedsNewDecl =
false;
6248 if (!ParamType->isPointerType() || ParamType.hasAddressSpace() ||
6252 OverloadParams.push_back(ParamType);
6260 NeedsNewDecl =
true;
6273 OverloadParams, EPI);
6282 FT = cast<FunctionProtoType>(OverloadTy);
6283 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
6290 Params.push_back(Parm);
6292 OverloadDecl->setParams(Params);
6294 return OverloadDecl;
6305 !Callee->isVariadic())
6307 if (Callee->getMinRequiredArguments() > ArgExprs.size())
6310 if (
const EnableIfAttr *
Attr =
6311 S.
CheckEnableIf(Callee, Fn->getBeginLoc(), ArgExprs,
true)) {
6312 S.
Diag(Fn->getBeginLoc(),
6313 isa<CXXMethodDecl>(Callee)
6314 ? diag::err_ovl_no_viable_member_function_in_call
6315 : diag::err_ovl_no_viable_function_in_call)
6316 << Callee << Callee->getSourceRange();
6317 S.
Diag(Callee->getLocation(),
6318 diag::note_ovl_candidate_disabled_by_function_cond_attr)
6319 <<
Attr->getCond()->getSourceRange() <<
Attr->getMessage();
6327 const auto GetFunctionLevelDCIfCXXClass =
6335 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
6336 return MD->
getParent()->getCanonicalDecl();
6339 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
6340 return RD->getCanonicalDecl();
6347 const CXXRecordDecl *
const CurParentClass = GetFunctionLevelDCIfCXXClass(S);
6348 if (!CurParentClass)
6355 assert(NamingClass &&
"Must have naming class even for implicit access");
6361 return CurParentClass == NamingClass ||
6410 if (
Call->getNumArgs() != 1)
6413 const Expr *
E =
Call->getCallee()->IgnoreParenImpCasts();
6414 if (!
E || isa<UnresolvedLookupExpr>(
E))
6416 const DeclRefExpr *DRE = dyn_cast_if_present<DeclRefExpr>(
E);
6429 if (BuiltinID != Builtin::BImove && BuiltinID != Builtin::BIforward)
6432 S.
Diag(DRE->
getLocation(), diag::warn_unqualified_call_to_std_cast_function)
6443 if (
Call.isInvalid())
6448 if (
const auto *ULE = dyn_cast<UnresolvedLookupExpr>(Fn);
6449 ULE && ULE->hasExplicitTemplateArgs() &&
6450 ULE->decls_begin() == ULE->decls_end()) {
6452 ? diag::warn_cxx17_compat_adl_only_template_id
6453 : diag::ext_adl_only_template_id)
6461 if (
const auto *CE = dyn_cast<CallExpr>(
Call.get()))
6467 if (
auto *DRE = dyn_cast<DeclRefExpr>(Fn->IgnoreParens());
6468 DRE &&
Call.get()->isValueDependent()) {
6477 Expr *ExecConfig,
bool IsExecConfig,
6478 bool AllowRecovery) {
6489 for (
const Expr *Arg : ArgExprs)
6490 if (CheckInvalidBuiltinCountedByRef(Arg, FunctionArgKind))
6495 if (isa<CXXPseudoDestructorExpr>(Fn)) {
6496 if (!ArgExprs.empty()) {
6498 Diag(Fn->getBeginLoc(), diag::err_pseudo_dtor_call_with_args)
6501 ArgExprs.back()->getEndLoc()));
6518 cast<CallExpr>(ExecConfig), ArgExprs,
6524 *
this, dyn_cast<UnresolvedMemberExpr>(Fn->IgnoreParens()),
6533 if (Fn->getType()->isRecordType())
6545 RParenLoc, ExecConfig, IsExecConfig,
6562 Scope, Fn, ULE, LParenLoc, ArgExprs, RParenLoc, ExecConfig,
6565 RParenLoc, ExecConfig, IsExecConfig,
6577 Expr *NakedFn = Fn->IgnoreParens();
6579 bool CallingNDeclIndirectly =
false;
6581 if (
UnaryOperator *UnOp = dyn_cast<UnaryOperator>(NakedFn)) {
6582 if (UnOp->getOpcode() == UO_AddrOf) {
6583 CallingNDeclIndirectly =
true;
6588 if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
6589 NDecl = DRE->getDecl();
6602 nullptr, DRE->isNonOdrUse());
6605 }
else if (
auto *ME = dyn_cast<MemberExpr>(NakedFn))
6606 NDecl = ME->getMemberDecl();
6608 if (
FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(NDecl)) {
6610 FD,
true, Fn->getBeginLoc()))
6622 FD->getBuiltinID()) {
6623 for (
unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size();
6627 !ArgExprs[Idx]->getType()->isPointerType())
6631 auto ArgTy = ArgExprs[Idx]->getType();
6632 auto ArgPtTy = ArgTy->getPointeeType();
6633 auto ArgAS = ArgPtTy.getAddressSpace();
6636 bool NeedImplicitASC =
6641 if (!NeedImplicitASC)
6645 if (ArgExprs[Idx]->isGLValue()) {
6647 Context, ArgExprs[Idx]->getType(), CK_NoOp, ArgExprs[Idx],
6652 Qualifiers ArgPtQuals = ArgPtTy.getQualifiers();
6662 CK_AddressSpaceConversion)
6671 assert((Fn->containsErrors() ||
6672 llvm::any_of(ArgExprs,
6673 [](
clang::Expr *
E) { return E->containsErrors(); })) &&
6674 "should only occur in error-recovery path.");
6679 ExecConfig, IsExecConfig);
6690 assert(BuiltInDecl &&
"failed to find builtin declaration");
6694 assert(DeclRef.
isUsable() &&
"Builtin reference cannot fail");
6699 assert(!
Call.isInvalid() &&
"Call to builtin cannot fail!");
6719 Diag(BuiltinLoc, diag::err_invalid_astype_of_different_size)
6737 FunctionDecl *FDecl = dyn_cast_or_null<FunctionDecl>(NDecl);
6738 unsigned BuiltinID = (FDecl ? FDecl->
getBuiltinID() : 0);
6742 if (FDecl->
hasAttr<AnyX86InterruptAttr>()) {
6743 Diag(Fn->getExprLoc(), diag::err_anyx86_interrupt_called);
6746 if (FDecl->
hasAttr<ARMInterruptAttr>()) {
6747 Diag(Fn->getExprLoc(), diag::err_arm_interrupt_called);
6756 if (Caller->hasAttr<AnyX86InterruptAttr>() ||
6757 Caller->hasAttr<AnyX86NoCallerSavedRegistersAttr>()) {
6759 bool HasNonGPRRegisters =
6761 if (HasNonGPRRegisters &&
6762 (!FDecl || !FDecl->
hasAttr<AnyX86NoCallerSavedRegistersAttr>())) {
6763 Diag(Fn->getExprLoc(), diag::warn_anyx86_excessive_regsave)
6764 << (Caller->hasAttr<AnyX86InterruptAttr>() ? 0 : 1);
6777 Fn->getType()->isSpecificBuiltinType(BuiltinType::BuiltinFn)) {
6804 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
6805 << Fn->getType() << Fn->getSourceRange());
6819 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
6820 << Fn->getType() << Fn->getSourceRange());
6827 const auto *Proto = dyn_cast_or_null<FunctionProtoType>(FuncT);
6828 unsigned NumParams = Proto ? Proto->getNumParams() : 0;
6832 assert(UsesADL == ADLCallKind::NotADL &&
6833 "CUDAKernelCallExpr should not use ADL");
6854 TheCall = dyn_cast<CallExpr>(
Result.get());
6855 bool CorrectedTypos = TheCall != TheOldCall;
6856 if (!TheCall)
return Result;
6863 if (CorrectedTypos && Args.size() < NumParams) {
6879 ExprResult E = CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
6888 if (FDecl && !FDecl->
hasAttr<CUDAGlobalAttr>())
6889 return ExprError(
Diag(LParenLoc,diag::err_kern_call_not_global_function)
6890 << FDecl << Fn->getSourceRange());
6896 return ExprError(
Diag(LParenLoc, diag::err_kern_type_not_void_return)
6897 << Fn->getType() << Fn->getSourceRange());
6900 if (FDecl && FDecl->
hasAttr<CUDAGlobalAttr>())
6901 return ExprError(
Diag(LParenLoc, diag::err_global_call_not_config)
6902 << FDecl << Fn->getSourceRange());
6917 for (
const Expr *Arg : Args) {
6918 if (Arg && Arg->getType()->isWebAssemblyTableType()) {
6920 diag::err_wasm_table_as_function_parameter));
6930 assert(isa<FunctionNoProtoType>(FuncT) &&
"Unknown FunctionType!");
6938 if (!Proto || !(Proto->isVariadic() && Args.size() >= Def->
param_size()))
6939 Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
6940 << (Args.size() > Def->
param_size()) << FDecl << Fn->getSourceRange();
6959 if (!Proto && !Args.empty() &&
6963 Diag(LParenLoc, diag::warn_strict_uses_without_prototype)
6964 << (FDecl !=
nullptr) << FDecl;
6967 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
6968 Expr *Arg = Args[i];
6970 if (Proto && i < Proto->getNumParams()) {
6972 Context, Proto->getParamType(i), Proto->isParamConsumed(i));
6990 diag::err_call_incomplete_argument, Arg))
6998 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
6999 if (Method->isImplicitObjectMemberFunction())
7000 return ExprError(
Diag(LParenLoc, diag::err_member_call_without_object)
7001 << Fn->getSourceRange() << 0);
7009 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7010 if (
const auto *RT =
7011 dyn_cast<RecordType>(Args[i]->getType().getCanonicalType())) {
7012 if (RT->getDecl()->isOrContainsUnion())
7013 Diag(Args[i]->getBeginLoc(), diag::warn_cmse_nonsecure_union)
7024 checkFortifiedBuiltinMemoryFunction(FDecl, TheCall);
7027 return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7029 if (CheckPointerCall(NDecl, TheCall, Proto))
7032 if (CheckOtherCall(TheCall, Proto))
7042 assert(Ty &&
"ActOnCompoundLiteral(): missing type");
7043 assert(InitExpr &&
"ActOnCompoundLiteral(): missing expression");
7061 diag::err_array_incomplete_or_sizeless_type,
7084 ? diag::err_variable_object_no_init
7085 : diag::err_compound_literal_with_vla_type;
7092 diag::err_typecheck_decl_incomplete_type,
7107 LiteralExpr =
Result.get();
7135 if (
auto ILE = dyn_cast<InitListExpr>(LiteralExpr))
7136 for (
unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
7142 VK, LiteralExpr, isFileScope);
7154 Diag(LParenLoc, diag::err_compound_literal_with_address_space)
7190 bool DiagnosedArrayDesignator =
false;
7191 bool DiagnosedNestedDesignator =
false;
7192 bool DiagnosedMixedDesignator =
false;
7196 for (
unsigned I = 0,
E = InitArgList.size(); I !=
E; ++I) {
7197 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(InitArgList[I])) {
7199 FirstDesignator = DIE->getBeginLoc();
7204 if (!DiagnosedNestedDesignator && DIE->size() > 1) {
7205 DiagnosedNestedDesignator =
true;
7206 Diag(DIE->getBeginLoc(), diag::ext_designated_init_nested)
7207 << DIE->getDesignatorsSourceRange();
7210 for (
auto &Desig : DIE->designators()) {
7211 if (!Desig.isFieldDesignator() && !DiagnosedArrayDesignator) {
7212 DiagnosedArrayDesignator =
true;
7213 Diag(Desig.getBeginLoc(), diag::ext_designated_init_array)
7214 << Desig.getSourceRange();
7218 if (!DiagnosedMixedDesignator &&
7219 !isa<DesignatedInitExpr>(InitArgList[0])) {
7220 DiagnosedMixedDesignator =
true;
7221 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7222 << DIE->getSourceRange();
7223 Diag(InitArgList[0]->getBeginLoc(), diag::note_designated_init_mixed)
7224 << InitArgList[0]->getSourceRange();
7227 isa<DesignatedInitExpr>(InitArgList[0])) {
7228 DiagnosedMixedDesignator =
true;
7229 auto *DIE = cast<DesignatedInitExpr>(InitArgList[0]);
7230 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7231 << DIE->getSourceRange();
7232 Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
7233 << InitArgList[I]->getSourceRange();
7237 if (FirstDesignator.
isValid()) {
7241 !DiagnosedNestedDesignator && !DiagnosedMixedDesignator) {
7243 ? diag::warn_cxx17_compat_designated_init
7244 : diag::ext_cxx_designated_init);
7246 Diag(FirstDesignator, diag::ext_designated_init);
7261 for (
unsigned I = 0,
E = InitArgList.size(); I !=
E; ++I) {
7262 if (InitArgList[I]->getType()->isNonOverloadPlaceholderType()) {
7269 InitArgList[I] = result.
get();
7303 llvm_unreachable(
"member pointer type in C");
7312 if (SrcAS != DestAS)
7313 return CK_AddressSpaceConversion;
7320 ? CK_BitCast : CK_AnyPointerToBlockPointerCast);
7325 return CK_CPointerToObjCPointerCast;
7327 return CK_BlockPointerToObjCPointerCast;
7329 return CK_PointerToBoolean;
7331 return CK_PointerToIntegral;
7337 llvm_unreachable(
"illegal cast from pointer");
7339 llvm_unreachable(
"Should have returned before this");
7344 return CK_FixedPointCast;
7346 return CK_FixedPointToBoolean;
7348 return CK_FixedPointToIntegral;
7350 return CK_FixedPointToFloating;
7354 diag::err_unimplemented_conversion_with_fixed_point_type)
7356 return CK_IntegralCast;
7361 llvm_unreachable(
"illegal cast to pointer type");
7363 llvm_unreachable(
"Should have returned before this");
7373 return CK_NullToPointer;
7374 return CK_IntegralToPointer;
7376 return CK_IntegralToBoolean;
7378 return CK_IntegralCast;
7380 return CK_IntegralToFloating;
7385 return CK_IntegralRealToComplex;
7389 CK_IntegralToFloating);
7390 return CK_FloatingRealToComplex;
7392 llvm_unreachable(
"member pointer type in C");
7394 return CK_IntegralToFixedPoint;
7396 llvm_unreachable(
"Should have returned before this");
7401 return CK_FloatingCast;
7403 return CK_FloatingToBoolean;
7405 return CK_FloatingToIntegral;
7410 return CK_FloatingRealToComplex;
7414 CK_FloatingToIntegral);
7415 return CK_IntegralRealToComplex;
7419 llvm_unreachable(
"valid float->pointer cast?");
7421 llvm_unreachable(
"member pointer type in C");
7423 return CK_FloatingToFixedPoint;
7425 llvm_unreachable(
"Should have returned before this");
7430 return CK_FloatingComplexCast;
7432 return CK_FloatingComplexToIntegralComplex;
7436 return CK_FloatingComplexToReal;
7438 return CK_FloatingCast;
7441 return CK_FloatingComplexToBoolean;
7445 CK_FloatingComplexToReal);
7446 return CK_FloatingToIntegral;
7450 llvm_unreachable(
"valid complex float->pointer cast?");
7452 llvm_unreachable(
"member pointer type in C");
7455 diag::err_unimplemented_conversion_with_fixed_point_type)
7457 return CK_IntegralCast;
7459 llvm_unreachable(
"Should have returned before this");
7464 return CK_IntegralComplexToFloatingComplex;
7466 return CK_IntegralComplexCast;
7470 return CK_IntegralComplexToReal;
7472 return CK_IntegralCast;
7475 return CK_IntegralComplexToBoolean;
7479 CK_IntegralComplexToReal);
7480 return CK_IntegralToFloating;
7484 llvm_unreachable(
"valid complex int->pointer cast?");
7486 llvm_unreachable(
"member pointer type in C");
7489 diag::err_unimplemented_conversion_with_fixed_point_type)
7491 return CK_IntegralCast;
7493 llvm_unreachable(
"Should have returned before this");
7496 llvm_unreachable(
"Unhandled scalar cast");
7503 len = vecType->getNumElements();
7504 eltType = vecType->getElementType();
7511 if (!
type->isRealType())
return false;
7521 auto ValidScalableConversion = [](
QualType FirstType,
QualType SecondType) {
7525 const auto *VecTy = SecondType->getAs<
VectorType>();
7529 return ValidScalableConversion(srcTy, destTy) ||
7530 ValidScalableConversion(destTy, srcTy);
7540 return matSrcType->
getNumRows() == matDestType->getNumRows() &&
7541 matSrcType->
getNumColumns() == matDestType->getNumColumns();
7547 uint64_t SrcLen, DestLen;
7560 return (SrcLen * SrcEltSize == DestLen * DestEltSize);
7565 "expected at least one type to be a vector here");
7567 bool IsSrcTyAltivec =
7583 return (IsSrcTyAltivec || IsDestTyAltivec);
7610 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
7615 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
7632 return Diag(R.
getBegin(), diag::err_invalid_conversion_between_matrixes)
7633 << DestTy << SrcTy << R;
7637 diag::err_invalid_conversion_between_matrix_and_type)
7638 << SrcTy << DestTy << R;
7641 diag::err_invalid_conversion_between_matrix_and_type)
7642 << DestTy << SrcTy << R;
7645 Kind = CK_MatrixCast;
7651 assert(VectorTy->
isVectorType() &&
"Not a vector type!");
7657 diag::err_invalid_conversion_between_vectors :
7658 diag::err_invalid_conversion_between_vector_and_integer)
7659 << VectorTy << Ty << R;
7662 diag::err_invalid_conversion_between_vector_and_scalar)
7663 << VectorTy << Ty << R;
7672 if (DestElemTy == SplattedExpr->
getType())
7673 return SplattedExpr;
7686 CK_BooleanToSignedIntegral);
7687 SplattedExpr = CastExprRes.
get();
7688 CK = CK_IntegralToFloating;
7690 CK = CK_BooleanToSignedIntegral;
7697 SplattedExpr = CastExprRes.
get();
7716 Diag(R.
getBegin(),diag::err_invalid_conversion_between_ext_vectors)
7717 << DestTy << SrcTy << R;
7729 diag::err_invalid_conversion_between_vector_and_scalar)
7730 << DestTy << SrcTy << R;
7732 Kind = CK_VectorSplat;
7740 assert(!
D.isInvalidType() && (
CastExpr !=
nullptr) &&
7741 "ActOnCastExpr(): missing type or expr");
7744 if (
D.isInvalidType())
7763 bool isVectorLiteral =
false;
7778 isVectorLiteral =
true;
7781 isVectorLiteral =
true;
7786 if (isVectorLiteral)
7792 if (isa<ParenListExpr>(
CastExpr)) {
7813 assert((isa<ParenListExpr>(
E) || isa<ParenExpr>(
E)) &&
7814 "Expected paren or paren list expression");
7821 LiteralLParenLoc = PE->getLParenLoc();
7822 LiteralRParenLoc = PE->getRParenLoc();
7823 exprs = PE->getExprs();
7824 numExprs = PE->getNumExprs();
7826 LiteralLParenLoc = cast<ParenExpr>(
E)->getLParen();
7827 LiteralRParenLoc = cast<ParenExpr>(
E)->getRParen();
7828 subExpr = cast<ParenExpr>(
E)->getSubExpr();
7851 if (numExprs == 1) {
7854 if (Literal.isInvalid())
7860 else if (numExprs < numElems) {
7862 diag::err_incorrect_number_of_vector_initializers);
7866 initExprs.append(exprs, exprs + numExprs);
7875 if (Literal.isInvalid())
7882 initExprs.append(exprs, exprs + numExprs);
7887 initExprs, LiteralRParenLoc);
7900 for (
unsigned i = 1, e =
E->getNumExprs(); i != e && !
Result.isInvalid(); ++i)
7917 const Expr *NullExpr = LHSExpr;
7918 const Expr *NonPointerExpr = RHSExpr;
7925 NonPointerExpr = LHSExpr;
7947 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands_null)
7948 << NonPointerExpr->
getType() << DiagType
7960 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
7968 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
8002 bool IsBlockPointer =
false;
8006 IsBlockPointer =
true;
8031 ResultAddrSpace = LAddrSpace;
8033 ResultAddrSpace = RAddrSpace;
8035 S.
Diag(
Loc, diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
8042 auto LHSCastKind = CK_BitCast, RHSCastKind = CK_BitCast;
8057 LAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8059 RAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8067 lhptee, rhptee,
false,
false,
8070 if (CompositeTy.
isNull()) {
8087 S.
Diag(
Loc, diag::ext_typecheck_cond_incompatible_pointers)
8098 QualType ResultTy = [&, ResultAddrSpace]() {
8104 .withCVRQualifiers(MergedCVRQual);
8133 S.
Diag(
Loc, diag::err_typecheck_cond_incompatible_operands)
8186 bool IsIntFirstExpr) {
8188 !Int.get()->getType()->isIntegerType())
8191 Expr *Expr1 = IsIntFirstExpr ? Int.get() : PointerExpr;
8192 Expr *Expr2 = IsIntFirstExpr ? PointerExpr : Int.get();
8194 S.
Diag(
Loc, diag::ext_typecheck_cond_pointer_integer_mismatch)
8198 CK_IntegralToPointer);
8232 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8238 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8244 if (LHSType == RHSType)
8253 return handleIntegerConversion<doIntegralCast, doIntegralCast>
8254 (S, LHS, RHS, LHSType, RHSType,
false);
8288 llvm::raw_svector_ostream OS(Str);
8289 OS <<
"(vector of " << NumElements <<
" '" << EleTyName <<
"' values)";
8290 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8291 << CondTy << OS.str();
8312 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8330 S.
Diag(QuestionLoc, diag::err_conditional_vector_size)
8331 << CondTy << VecResTy;
8336 QualType RVE = RV->getElementType();
8339 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8340 << CondTy << VecResTy;
8366 bool IsBoolVecLang =
8390 if (
const CallExpr *CE = dyn_cast<CallExpr>(
E)) {
8391 QualType Ty = CE->getCallee()->getType();
8429 "should only occur in error-recovery path.");
8464 Diag(QuestionLoc, diag::err_wasm_table_conditional_expression)
8473 diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy
8492 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
8508 if (LHSRT->getDecl() == RHSRT->getDecl())
8552 if (!compositeType.
isNull())
8553 return compositeType;
8587 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
8626 const Expr **RHSExprs) {
8631 if (
const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(
E)) {
8632 E = MTE->getSubExpr();
8637 if (
const auto *OP = dyn_cast<BinaryOperator>(
E);
8639 *Opcode = OP->getOpcode();
8640 *RHSExprs = OP->getRHS();
8645 if (
const auto *
Call = dyn_cast<CXXOperatorCallExpr>(
E)) {
8646 if (
Call->getNumArgs() != 2)
8652 if (OO < OO_Plus || OO > OO_Arrow ||
8653 OO == OO_PlusPlus || OO == OO_MinusMinus)
8659 *RHSExprs =
Call->getArg(1);
8675 if (
const auto *OP = dyn_cast<BinaryOperator>(
E))
8676 return OP->isComparisonOp() || OP->isLogicalOp();
8677 if (
const auto *OP = dyn_cast<UnaryOperator>(
E))
8678 return OP->getOpcode() == UO_LNot;
8693 const Expr *RHSExpr) {
8695 const Expr *CondRHS;
8706 ? diag::warn_precedence_bitwise_conditional
8707 : diag::warn_precedence_conditional;
8709 Self.Diag(OpLoc, DiagID)
8715 Self.PDiag(diag::note_precedence_silence)
8720 Self.PDiag(diag::note_precedence_conditional_first),
8731 auto GetNullability = [](
QualType Ty) {
8732 std::optional<NullabilityKind> Kind = Ty->getNullability();
8742 auto LHSKind = GetNullability(LHSTy), RHSKind = GetNullability(RHSTy);
8750 MergedKind = RHSKind;
8757 MergedKind = RHSKind;
8759 MergedKind = LHSKind;
8765 if (GetNullability(ResTy) == MergedKind)
8799 CondExpr = CondResult.
get();
8800 LHSExpr = LHSResult.
get();
8801 RHSExpr = RHSResult.
get();
8807 Expr *commonExpr =
nullptr;
8809 commonExpr = CondExpr;
8816 commonExpr = result.
get();
8830 commonExpr = commonRes.
get();
8840 commonExpr = MatExpr.
get();
8848 LHSExpr = CondExpr = opaqueValue;
8854 ExprResult Cond = CondExpr, LHS = LHSExpr, RHS = RHSExpr;
8856 VK, OK, QuestionLoc);
8864 CheckBoolLikeConversion(Cond.
get(), QuestionLoc);
8872 RHS.get(), result, VK, OK);
8875 commonExpr, opaqueValue, Cond.
get(), LHS.get(), RHS.get(), QuestionLoc,
8876 ColonLoc, result, VK, OK);
8880 unsigned FromAttributes = 0, ToAttributes = 0;
8881 if (
const auto *FromFn =
8885 if (
const auto *ToFn =
8890 return FromAttributes != ToAttributes;
8898 if (
const auto *ToFn =
8900 if (
const auto *FromFn =
8919 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
8920 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
8923 const Type *lhptee, *rhptee;
8925 std::tie(lhptee, lhq) =
8926 cast<PointerType>(LHSType)->getPointeeType().split().asPair();
8927 std::tie(rhptee, rhq) =
8928 cast<PointerType>(RHSType)->getPointeeType().split().asPair();
8988 diag::warn_typecheck_convert_incompatible_function_pointer_strict,
9011 if (ltrans == rtrans) {
9025 if (isa<PointerType>(lhptee) && isa<PointerType>(rhptee)) {
9027 std::tie(lhptee, lhq) =
9028 cast<PointerType>(lhptee)->getPointeeType().split().asPair();
9029 std::tie(rhptee, rhq) =
9030 cast<PointerType>(rhptee)->getPointeeType().split().asPair();
9043 }
while (isa<PointerType>(lhptee) && isa<PointerType>(rhptee));
9045 if (lhptee == rhptee)
9071 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9072 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9093 if (LQuals != RQuals)
9122 assert(LHSType.
isCanonical() &&
"LHS was not canonicalized!");
9123 assert(RHSType.
isCanonical() &&
"RHS was not canonicalized!");
9171 return VT->getElementType().getCanonicalType() == ElementType;
9204 if (LHSType == RHSType) {
9211 if (
const auto *AT = dyn_cast<AutoType>(LHSType)) {
9212 if (AT->isGNUAutoType()) {
9220 if (
const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
9225 if (Kind != CK_NoOp && ConvertRHS)
9227 Kind = CK_NonAtomicToAtomic;
9240 Kind = CK_LValueBitCast;
9255 Kind = CK_VectorSplat;
9281 << RHSType << LHSType;
9300 << RHSType << LHSType;
9350 if (
const PointerType *LHSPointer = dyn_cast<PointerType>(LHSType)) {
9352 if (isa<PointerType>(RHSType)) {
9353 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9355 if (AddrSpaceL != AddrSpaceR)
9356 Kind = CK_AddressSpaceConversion;
9367 Kind = CK_IntegralToPointer;
9373 if (isa<ObjCObjectPointerType>(RHSType)) {
9375 if (LHSPointer->getPointeeType()->isVoidType()) {
9394 if (LHSPointer->getPointeeType()->isVoidType()) {
9395 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9400 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9409 if (isa<BlockPointerType>(LHSType)) {
9418 Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9424 Kind = CK_IntegralToPointer;
9430 Kind = CK_AnyPointerToBlockPointerCast;
9436 if (RHSPT->getPointeeType()->isVoidType()) {
9437 Kind = CK_AnyPointerToBlockPointerCast;
9445 if (isa<ObjCObjectPointerType>(LHSType)) {
9451 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
9453 !
ObjC().CheckObjCARCUnavailableWeakConversion(OrigLHSType, RHSType))
9460 Kind = CK_IntegralToPointer;
9466 if (isa<PointerType>(RHSType)) {
9467 Kind = CK_CPointerToObjCPointerCast;
9489 Kind = CK_BlockPointerToObjCPointerCast;
9501 Kind = CK_NullToPointer;
9506 if (isa<PointerType>(RHSType)) {
9509 Kind = CK_PointerToBoolean;
9515 Kind = CK_PointerToIntegral;
9523 if (isa<ObjCObjectPointerType>(RHSType)) {
9526 Kind = CK_PointerToBoolean;
9532 Kind = CK_PointerToIntegral;
9540 if (isa<TagType>(LHSType) && isa<TagType>(RHSType)) {
9548 Kind = CK_IntToOCLSampler;
9590 for (
auto *it : UD->
fields()) {
9591 if (it->getType()->isPointerType()) {
9630 bool DiagnoseCFAudited,
9634 assert((ConvertRHS || !
Diagnose) &&
"can't indicate whether we diagnosed");
9640 ExprResult &RHS = ConvertRHS ? CallerRHS : LocalRHS;
9644 if (RHSPtrType->getPointeeType()->hasAttr(attr::NoDeref) &&
9645 !LHSPtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
9647 diag::warn_noderef_to_dereferenceable_pointer)
9666 AllowedExplicit::None,
9678 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
9679 !
ObjC().CheckObjCARCUnavailableWeakConversion(LHSType, RHSType))
9693 RHS.
get(), LHSType,
false, DAP))
9784 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
9794 ObjC().CheckConversionToObjCLiteral(LHSType,
E,
Diagnose))) {
9814struct OriginalOperand {
9815 explicit OriginalOperand(
Expr *Op) : Orig(Op), Conversion(nullptr) {
9816 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Op))
9817 Op = MTE->getSubExpr();
9818 if (
auto *BTE = dyn_cast<CXXBindTemporaryExpr>(Op))
9819 Op = BTE->getSubExpr();
9820 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(Op)) {
9821 Orig = ICE->getSubExprAsWritten();
9822 Conversion = ICE->getConversionFunction();
9826 QualType getType()
const {
return Orig->getType(); }
9835 OriginalOperand OrigLHS(LHS.
get()), OrigRHS(RHS.
get());
9837 Diag(
Loc, diag::err_typecheck_invalid_operands)
9838 << OrigLHS.getType() << OrigRHS.getType()
9843 if (OrigLHS.Conversion) {
9844 Diag(OrigLHS.Conversion->getLocation(),
9845 diag::note_typecheck_invalid_operands_converted)
9848 if (OrigRHS.Conversion) {
9849 Diag(OrigRHS.Conversion->getLocation(),
9850 diag::note_typecheck_invalid_operands_converted)
9865 if (!(LHSNatVec && RHSNatVec)) {
9867 Expr *NonVector = !LHSNatVec ? LHS.
get() : RHS.
get();
9868 Diag(
Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
9870 <<
Vector->getSourceRange();
9874 Diag(
Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
9903 scalarCast = CK_IntegralToBoolean;
9908 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
9913 scalarCast = CK_IntegralCast;
9918 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
9921 scalarCast = CK_FloatingCast;
9924 scalarCast = CK_IntegralToFloating;
9933 if (scalarCast != CK_NoOp)
9944 assert(VecTy &&
"Expression E must be a vector");
9949 VecTy->getVectorKind());
9953 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(
E))
9954 if (ICE->getSubExpr()->getType() == NewVecTy)
9955 return ICE->getSubExpr();
9957 auto Cast = ElementType->
isIntegerType() ? CK_IntegralCast : CK_FloatingCast;
9965 if (Int->get()->containsErrors())
9968 QualType IntTy = Int->get()->getType().getUnqualifiedType();
9974 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.
Context);
9983 unsigned NumBits = IntSigned
9985 :
Result.getActiveBits())
9986 :
Result.getActiveBits();
9993 return (IntSigned != OtherIntSigned &&
10006 if (Int->get()->containsErrors())
10009 QualType IntTy = Int->get()->getType().getUnqualifiedType();
10014 bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.
Context);
10026 llvm::APFloat::rmTowardZero);
10029 bool Ignored =
false;
10030 Float.convertToInteger(ConvertBack, llvm::APFloat::rmNearestTiesToEven,
10032 if (
Result != ConvertBack)
10038 unsigned FloatPrec = llvm::APFloat::semanticsPrecision(
10040 if (Bits > FloatPrec)
10053 QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType();
10054 QualType VectorTy =
Vector->get()->getType().getUnqualifiedType();
10058 assert(!isa<ExtVectorType>(VT) &&
10059 "ExtVectorTypes should not be handled here!");
10060 VectorEltTy = VT->getElementType();
10065 llvm_unreachable(
"Only Fixed-Length and SVE Vector types are handled here");
10091 ScalarCast = CK_IntegralCast;
10095 ScalarCast = CK_FloatingToIntegral;
10103 llvm::APFloat
Result(0.0);
10109 bool CstScalar = Scalar->get()->isValueDependent() ||
10112 if (!CstScalar && Order < 0)
10118 bool Truncated =
false;
10120 llvm::APFloat::rmNearestTiesToEven, &Truncated);
10125 ScalarCast = CK_FloatingCast;
10130 ScalarCast = CK_IntegralToFloating;
10137 if (ScalarCast != CK_NoOp)
10145 bool AllowBothBool,
10146 bool AllowBoolConversions,
10147 bool AllowBoolOperation,
10148 bool ReportInvalid) {
10149 if (!IsCompAssign) {
10165 assert(LHSVecType || RHSVecType);
10173 if (!AllowBothBool && LHSVecType &&
10179 if (!AllowBoolOperation &&
10188 if (LHSVecType && RHSVecType &&
10190 if (isa<ExtVectorType>(LHSVecType)) {
10203 if (AllowBoolConversions && LHSVecType && RHSVecType &&
10213 if (!IsCompAssign &&
10216 RHSVecType->getElementType()->isIntegerType()) {
10225 unsigned &SVEorRVV) {
10246 if (IsSveRVVConversion(LHSType, RHSType, SVEorRVV) ||
10247 IsSveRVVConversion(RHSType, LHSType, SVEorRVV)) {
10248 Diag(
Loc, diag::err_typecheck_sve_rvv_ambiguous)
10249 << SVEorRVV << LHSType << RHSType;
10256 unsigned &SVEorRVV) {
10261 if (FirstVecType && SecondVecType) {
10264 SecondVecType->getVectorKind() ==
10269 SecondVecType->getVectorKind() ==
10271 SecondVecType->getVectorKind() ==
10273 SecondVecType->getVectorKind() ==
10282 if (SecondVecType &&
10295 if (IsSveRVVGnuConversion(LHSType, RHSType, SVEorRVV) ||
10296 IsSveRVVGnuConversion(RHSType, LHSType, SVEorRVV)) {
10297 Diag(
Loc, diag::err_typecheck_sve_rvv_gnu_ambiguous)
10298 << SVEorRVV << LHSType << RHSType;
10304 unsigned DiagID = diag::err_typecheck_vector_not_convertable;
10306 if (isa<ExtVectorType>(LHSVecType)) {
10317 if (isa<ExtVectorType>(RHSVecType)) {
10319 LHSType, RHSVecType->getElementType(),
10332 QualType VecType = LHSVecType ? LHSType : RHSType;
10333 const VectorType *VT = LHSVecType ? LHSVecType : RHSVecType;
10334 QualType OtherType = LHSVecType ? RHSType : LHSType;
10335 ExprResult *OtherExpr = LHSVecType ? &RHS : &LHS;
10340 Diag(
Loc, diag::warn_deprecated_lax_vec_conv_all) << RHSType << LHSType;
10344 if (!IsCompAssign) {
10363 if ((!RHSVecType && !RHSType->
isRealType()) ||
10365 Diag(
Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10366 << LHSType << RHSType
10376 RHSVecType && isa<ExtVectorType>(RHSVecType) &&
10377 LHSVecType && isa<ExtVectorType>(LHSVecType)) {
10378 Diag(
Loc, diag::err_opencl_implicit_vector_conversion) << LHSType
10387 if ((RHSVecType && !isa<ExtVectorType>(RHSVecType)) ||
10388 (LHSVecType && !isa<ExtVectorType>(LHSVecType))) {
10389 QualType Scalar = LHSVecType ? RHSType : LHSType;
10391 unsigned ScalarOrVector = LHSVecType && RHSVecType ? 1 : 0;
10393 diag::err_typecheck_vector_not_convertable_implict_truncation)
10394 << ScalarOrVector << Scalar <<
Vector;
10401 << LHSType << RHSType
10410 if (!IsCompAssign) {
10425 unsigned DiagID = diag::err_typecheck_invalid_operands;
10427 ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
10428 (RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) {
10449 Diag(
Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10458 Diag(
Loc, diag::err_typecheck_vector_lengths_not_equal)
10467 bool ScalarOrVector =
10470 Diag(
Loc, diag::err_typecheck_vector_not_convertable_implict_truncation)
10471 << ScalarOrVector << Scalar <<
Vector;
10503 S.
Diag(
Loc, diag::warn_null_in_arithmetic_operation)
10515 S.
Diag(
Loc, diag::warn_null_in_comparison_operation)
10516 << LHSNull << NonNullType
10522 const auto *LUE = dyn_cast<UnaryExprOrTypeTraitExpr>(LHS);
10523 const auto *RUE = dyn_cast<UnaryExprOrTypeTraitExpr>(RHS);
10526 if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
10527 RUE->getKind() != UETT_SizeOf)
10534 if (RUE->isArgumentType())
10535 RHSTy = RUE->getArgumentType().getNonReferenceType();
10537 RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
10544 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
10545 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
10546 S.
Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
10550 QualType ArrayElemTy = ArrayTy->getElementType();
10556 S.
Diag(
Loc, diag::warn_division_sizeof_array)
10558 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
10559 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
10560 S.
Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
10564 S.
Diag(
Loc, diag::note_precedence_silence) << RHS;
10577 S.
PDiag(diag::warn_remainder_division_by_zero)
10583 bool IsCompAssign,
bool IsDiv) {
10661 ? diag::err_typecheck_pointer_arith_void_type
10662 : diag::ext_gnu_void_ptr)
10671 ? diag::err_typecheck_pointer_arith_void_type
10672 : diag::ext_gnu_void_ptr)
10673 << 0 <<
Pointer->getSourceRange();
10684 S.
Diag(
Loc, diag::warn_gnu_null_ptr_arith)
10685 <<
Pointer->getSourceRange();
10687 S.
Diag(
Loc, diag::warn_pointer_arith_null_ptr)
10704 S.
PDiag(diag::warn_pointer_sub_null_ptr)
10706 <<
Pointer->getSourceRange());
10715 ? diag::err_typecheck_pointer_arith_function_type
10716 : diag::ext_gnu_ptr_func_arith)
10728 assert(
Pointer->getType()->isAnyPointerType());
10730 ? diag::err_typecheck_pointer_arith_function_type
10731 : diag::ext_gnu_ptr_func_arith)
10732 << 0 <<
Pointer->getType()->getPointeeType()
10734 <<
Pointer->getSourceRange();
10742 QualType ResType = Operand->getType();
10744 ResType = ResAtomicType->getValueType();
10750 diag::err_typecheck_arithmetic_incomplete_or_sizeless_type,
10751 Operand->getSourceRange());
10764 QualType ResType = Operand->getType();
10766 ResType = ResAtomicType->getValueType();
10798 if (!isLHSPointer && !isRHSPointer)
return true;
10800 QualType LHSPointeeTy, RHSPointeeTy;
10805 if (isLHSPointer && isRHSPointer) {
10809 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
10817 bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->
isVoidType();
10818 bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->
isVoidType();
10819 if (isLHSVoidPtr || isRHSVoidPtr) {
10827 bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->
isFunctionType();
10828 bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->
isFunctionType();
10829 if (isLHSFuncPtr || isRHSFuncPtr) {
10851 Expr* IndexExpr = RHSExpr;
10854 IndexExpr = LHSExpr;
10857 bool IsStringPlusInt = StrExpr &&
10863 Self.Diag(OpLoc, diag::warn_string_plus_int)
10867 if (IndexExpr == RHSExpr) {
10869 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence)
10874 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence);
10880 const Expr *StringRefExpr = LHSExpr;
10885 CharExpr = dyn_cast<CharacterLiteral>(LHSExpr->
IgnoreImpCasts());
10886 StringRefExpr = RHSExpr;
10889 if (!CharExpr || !StringRefExpr)
10909 Self.Diag(OpLoc, diag::warn_string_plus_char)
10910 << DiagRange << Ctx.
CharTy;
10912 Self.Diag(OpLoc, diag::warn_string_plus_char)
10913 << DiagRange << CharExpr->
getType();
10919 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence)
10924 Self.Diag(OpLoc, diag::note_string_plus_scalar_silence);
10933 S.
Diag(
Loc, diag::err_typecheck_sub_ptr_compatible)
10952 if (CompLHSTy) *CompLHSTy = compType;
10961 *CompLHSTy = compType;
10970 *CompLHSTy = compType;
10980 if (Opc == BO_Add) {
10987 if (CompLHSTy) *CompLHSTy = compType;
11001 std::swap(PExp, IExp);
11012 if (!IExp->getType()->isIntegerType())
11021 (!IExp->isValueDependent() &&
11022 (!IExp->EvaluateAsInt(KnownVal,
Context) ||
11026 Context, BO_Add, PExp, IExp);
11039 if (isa<AddrLabelExpr>(PExp) &&
getLangOpts().PointerAuthIndirectGotos) {
11040 Diag(
Loc, diag::err_ptrauth_indirect_goto_addrlabel_arithmetic)
11046 CheckArrayAccess(PExp, IExp);
11055 *CompLHSTy = LHSTy;
11075 if (CompLHSTy) *CompLHSTy = compType;
11084 *CompLHSTy = compType;
11093 *CompLHSTy = compType;
11106 if (CompLHSTy) *CompLHSTy = compType;
11121 if (isa<AddrLabelExpr>(LHS.
get()) &&
11123 Diag(
Loc, diag::err_ptrauth_indirect_goto_addrlabel_arithmetic)
11149 CheckArrayAccess(LHS.
get(), RHS.
get(),
nullptr,
11152 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11196 if (ElementSize.
isZero()) {
11197 Diag(
Loc,diag::warn_sub_ptr_zero_size_types)
11203 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11213 return ET->getDecl()->isScoped();
11230 llvm::APSInt Right = RHSResult.
Val.
getInt();
11232 if (Right.isNegative()) {
11234 S.
PDiag(diag::warn_shift_negative)
11245 LeftSize = FXSema.getWidth() - (
unsigned)FXSema.hasUnsignedPadding();
11247 if (Right.uge(LeftSize)) {
11249 S.
PDiag(diag::warn_shift_gt_typewidth)
11269 llvm::APSInt Left = LHSResult.
Val.
getInt();
11280 if (Left.isNegative()) {
11282 S.
PDiag(diag::warn_shift_lhs_negative)
11287 llvm::APInt ResultBits =
11288 static_cast<llvm::APInt &
>(Right) + Left.getSignificantBits();
11289 if (ResultBits.ule(LeftSize))
11291 llvm::APSInt
Result = Left.extend(ResultBits.getLimitedValue());
11297 Result.toString(HexResult, 16,
false,
true);
11303 if (ResultBits - 1 == LeftSize) {
11304 S.
Diag(
Loc, diag::warn_shift_result_sets_sign_bit)
11305 << HexResult << LHSType
11310 S.
Diag(
Loc, diag::warn_shift_result_gt_typewidth)
11311 << HexResult.str() <<
Result.getSignificantBits() << LHSType
11323 S.
Diag(
Loc, diag::err_shift_rhs_only_vector)
11329 if (!IsCompAssign) {
11351 S.
Diag(
Loc, diag::err_typecheck_invalid_operands)
11358 if (!LHSEleType->isIntegerType()) {
11359 S.
Diag(
Loc, diag::err_typecheck_expect_int)
11364 if (!RHSEleType->isIntegerType()) {
11365 S.
Diag(
Loc, diag::err_typecheck_expect_int)
11374 if (LHSEleType != RHSEleType) {
11376 LHSEleType = RHSEleType;
11382 }
else if (RHSVecTy) {
11387 S.
Diag(
Loc, diag::err_typecheck_vector_lengths_not_equal)
11395 if (LHSBT != RHSBT &&
11397 S.
Diag(
Loc, diag::warn_typecheck_vector_element_sizes_not_equal)
11414 bool IsCompAssign) {
11415 if (!IsCompAssign) {
11438 if ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
11439 (RHSBuiltinTy && RHSBuiltinTy->
isSVEBool())) {
11440 S.
Diag(
Loc, diag::err_typecheck_invalid_operands)
11445 if (!LHSEleType->isIntegerType()) {
11446 S.
Diag(
Loc, diag::err_typecheck_expect_int)
11451 if (!RHSEleType->isIntegerType()) {
11452 S.
Diag(
Loc, diag::err_typecheck_expect_int)
11460 S.
Diag(
Loc, diag::err_typecheck_invalid_operands)
11470 if (LHSEleType != RHSEleType) {
11472 LHSEleType = RHSEleType;
11474 const llvm::ElementCount VecSize =
11483 S.
Diag(
Loc, diag::err_typecheck_vector_lengths_not_equal)
11489 const llvm::ElementCount VecSize =
11491 if (LHSEleType != RHSEleType) {
11493 RHSEleType = LHSEleType;
11506 bool IsCompAssign) {
11540 if (IsCompAssign) LHS = OldLHS;
11571 S.
Diag(
Loc, IsError ? diag::err_typecheck_comparison_of_distinct_pointers
11572 : diag::ext_typecheck_comparison_of_distinct_pointers)
11612 S.
Diag(
Loc, IsError ? diag::err_typecheck_comparison_of_fptr_to_void
11613 : diag::ext_typecheck_comparison_of_fptr_to_void)
11620 case Stmt::ObjCArrayLiteralClass:
11621 case Stmt::ObjCDictionaryLiteralClass:
11622 case Stmt::ObjCStringLiteralClass:
11623 case Stmt::ObjCBoxedExprClass:
11684 Literal = LHS.
get();
11687 Literal = RHS.
get();
11703 llvm_unreachable(
"Unknown Objective-C object literal kind");
11707 S.
Diag(
Loc, diag::warn_objc_string_literal_comparison)
11708 << Literal->getSourceRange();
11710 S.
Diag(
Loc, diag::warn_objc_literal_comparison)
11711 << LiteralKind << Literal->getSourceRange();
11720 S.
Diag(
Loc, diag::note_objc_literal_comparison_isequal)
11733 if (!UO || UO->
getOpcode() != UO_LNot)
return;
11743 bool IsBitwiseOp = Opc == BO_And || Opc == BO_Or || Opc == BO_Xor;
11745 <<
Loc << IsBitwiseOp;
11772 if (
const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(
E)) {
11774 }
else if (
const MemberExpr *Mem = dyn_cast<MemberExpr>(
E)) {
11775 if (Mem->isImplicitAccess())
11776 D = Mem->getMemberDecl();
11780 return D->getType()->isArrayType() && !
D->isWeak();
11791 return std::nullopt;
11799 std::swap(LHS, RHS);
11803 std::swap(LHS, RHS);
11807 return std::nullopt;
11810 auto *BO = dyn_cast<BinaryOperator>(LHS);
11811 if (!BO || BO->getOpcode() != BO_Add)
11812 return std::nullopt;
11816 Other = BO->getRHS();
11818 Other = BO->getLHS();
11820 return std::nullopt;
11822 if (!
Other->getType()->isUnsignedIntegerType())
11823 return std::nullopt;
11825 return Opc == BO_GE;
11879 auto IsDeprArrayComparionIgnored =
11882 ? diag::warn_array_comparison_cxx26
11883 : !S.
getLangOpts().CPlusPlus20 || IsDeprArrayComparionIgnored
11884 ? diag::warn_array_comparison
11885 : diag::warn_depr_array_comparison;
11911 Result = AlwaysConstant;
11915 S.
PDiag(diag::warn_comparison_always)
11930 Result = AlwaysConstant;
11934 S.
PDiag(diag::warn_comparison_always)
11937 }
else if (std::optional<bool> Res =
11940 S.
PDiag(diag::warn_comparison_always)
11942 << (*Res ? AlwaysTrue : AlwaysFalse));
11946 if (isa<CastExpr>(LHSStripped))
11948 if (isa<CastExpr>(RHSStripped))
11953 Expr *LiteralString =
nullptr;
11954 Expr *LiteralStringStripped =
nullptr;
11955 if ((isa<StringLiteral>(LHSStripped) || isa<ObjCEncodeExpr>(LHSStripped)) &&
11958 LiteralString = LHS;
11959 LiteralStringStripped = LHSStripped;
11960 }
else if ((isa<StringLiteral>(RHSStripped) ||
11961 isa<ObjCEncodeExpr>(RHSStripped)) &&
11964 LiteralString = RHS;
11965 LiteralStringStripped = RHSStripped;
11968 if (LiteralString) {
11970 S.
PDiag(diag::warn_stringcompare)
11971 << isa<ObjCEncodeExpr>(LiteralStringStripped)
11983 llvm_unreachable(
"unhandled cast kind");
11985 case CK_UserDefinedConversion:
11987 case CK_LValueToRValue:
11989 case CK_ArrayToPointerDecay:
11991 case CK_FunctionToPointerDecay:
11993 case CK_IntegralCast:
11995 case CK_FloatingCast:
11997 case CK_IntegralToFloating:
11998 case CK_FloatingToIntegral:
12000 case CK_IntegralComplexCast:
12001 case CK_FloatingComplexCast:
12002 case CK_FloatingComplexToIntegralComplex:
12003 case CK_IntegralComplexToFloatingComplex:
12005 case CK_FloatingComplexToReal:
12006 case CK_FloatingRealToComplex:
12007 case CK_IntegralComplexToReal:
12008 case CK_IntegralRealToComplex:
12010 case CK_HLSLArrayRValue:
12023 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(
E))
12050 << 0 << FromType << ToType;
12055 llvm_unreachable(
"unhandled case in switch");
12082 if (NumEnumArgs == 1) {
12084 QualType OtherTy = LHSIsEnum ? RHSStrippedType : LHSStrippedType;
12090 if (NumEnumArgs == 2) {
12099 LHSStrippedType->
castAs<
EnumType>()->getDecl()->getIntegerType();
12110 LHSType = RHSType = IntType;
12122 std::optional<ComparisonCategoryType> CCT =
12134 assert(!
Type.isNull() &&
"composite type for <=> has not been set");
12175 if (
const auto *CL = dyn_cast<CharacterLiteral>(
E.get())) {
12176 if (CL->getValue() == 0)
12180 NullValue ?
"NULL" :
"(void *)0");
12181 }
else if (
const auto *CE = dyn_cast<CStyleCastExpr>(
E.get())) {
12188 NullValue ?
"NULL" :
"(void *)0");
12198 bool IsThreeWay = Opc == BO_Cmp;
12199 bool IsOrdered = IsRelational || IsThreeWay;
12210 if (!IsThreeWay || IsAnyPointerType(LHS) || IsAnyPointerType(RHS)) {
12263 auto computeResultTy = [&]() {
12272 std::optional<ComparisonCategoryType> CCT =
12277 if (CompositeTy->
isPointerType() && LHSIsNull != RHSIsNull) {
12281 Diag(
Loc, diag::err_typecheck_three_way_comparison_of_pointer_and_zero)
12291 if (!IsOrdered && LHSIsNull != RHSIsNull) {
12292 bool IsEquality = Opc == BO_EQ;
12304 bool IsError = Opc == BO_Cmp;
12306 IsError ? diag::err_typecheck_ordered_comparison_of_function_pointers
12308 ? diag::warn_typecheck_ordered_comparison_of_function_pointers
12309 : diag::ext_typecheck_ordered_comparison_of_function_pointers;
12338 return computeResultTy();
12354 (IsOrdered ? 2 : 1) &&
12359 return computeResultTy();
12373 if (IsRelational) {
12378 Diag(
Loc, diag::ext_typecheck_compare_complete_incomplete_pointers)
12384 }
else if (!IsRelational &&
12388 && !LHSIsNull && !RHSIsNull)
12395 if (LCanPointeeTy != RCanPointeeTy) {
12401 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
12402 << LHSType << RHSType << 0
12408 CastKind Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion
12410 if (LHSIsNull && !RHSIsNull)
12415 return computeResultTy();
12427 if (!IsOrdered && LHSIsNull && RHSIsNull) {
12430 return computeResultTy();
12434 return computeResultTy();
12445 return computeResultTy();
12449 return computeResultTy();
12458 return computeResultTy();
12463 return computeResultTy();
12467 if (IsRelational &&
12476 if (isa<FunctionDecl>(DC))
12478 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
12479 if (CTSD->isInStdNamespace() &&
12480 llvm::StringSwitch<bool>(CTSD->getName())
12481 .Cases(
"less",
"less_equal",
"greater",
"greater_equal",
true)
12487 return computeResultTy();
12500 return computeResultTy();
12510 if (!LHSIsNull && !RHSIsNull &&
12512 Diag(
Loc, diag::err_typecheck_comparison_of_distinct_blocks)
12517 return computeResultTy();
12524 if (!LHSIsNull && !RHSIsNull) {
12529 Diag(
Loc, diag::err_typecheck_comparison_of_distinct_blocks)
12533 if (LHSIsNull && !RHSIsNull)
12536 : CK_AnyPointerToBlockPointerCast);
12540 : CK_AnyPointerToBlockPointerCast);
12541 return computeResultTy();
12550 bool RPtrToVoid = RPT ? RPT->getPointeeType()->isVoidType() :
false;
12552 if (!LPtrToVoid && !RPtrToVoid &&
12560 if (LHSIsNull && !RHSIsNull) {
12566 RPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
12576 LPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
12578 return computeResultTy();
12588 if (LHSIsNull && !RHSIsNull)
12592 return computeResultTy();
12598 CK_BlockPointerToObjCPointerCast);
12599 return computeResultTy();
12600 }
else if (!IsOrdered &&
12604 CK_BlockPointerToObjCPointerCast);
12605 return computeResultTy();
12610 unsigned DiagID = 0;
12611 bool isError =
false;
12620 isError ? diag::err_typecheck_ordered_comparison_of_pointer_and_zero
12621 : diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
12624 DiagID = diag::err_typecheck_comparison_of_pointer_integer;
12626 }
else if (IsOrdered)
12627 DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
12629 DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
12641 LHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
12644 RHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
12645 return computeResultTy();
12649 if (!IsOrdered && RHSIsNull
12652 return computeResultTy();
12654 if (!IsOrdered && LHSIsNull
12657 return computeResultTy();
12660 if (
getLangOpts().getOpenCLCompatibleVersion() >= 200) {
12662 return computeResultTy();
12666 return computeResultTy();
12669 if (LHSIsNull && RHSType->
isQueueT()) {
12671 return computeResultTy();
12674 if (LHSType->
isQueueT() && RHSIsNull) {
12676 return computeResultTy();
12687 if (isa<ExtVectorType>(VTy)) {
12701 "Unhandled vector element size in vector compare");
12721 "Unhandled vector element size in vector compare");
12741 if (Opc == BO_Cmp) {
12742 Diag(
Loc, diag::err_three_way_vector_comparison);
12773 Diag(
Loc, diag::warn_deprecated_altivec_src_compat);
12803 if (Opc == BO_Cmp) {
12804 Diag(
Loc, diag::err_three_way_vector_comparison);
12832 if (LHSBuiltinTy && RHSBuiltinTy && LHSBuiltinTy->
isSVEBool() &&
12833 RHSBuiltinTy->isSVEBool())
12852 bool Negative =
false;
12853 bool ExplicitPlus =
false;
12854 const auto *LHSInt = dyn_cast<IntegerLiteral>(XorLHS.
get());
12855 const auto *RHSInt = dyn_cast<IntegerLiteral>(XorRHS.
get());
12861 if (
const auto *UO = dyn_cast<UnaryOperator>(XorRHS.
get())) {
12863 if (Opc != UO_Minus && Opc != UO_Plus)
12865 RHSInt = dyn_cast<IntegerLiteral>(UO->getSubExpr());
12868 Negative = (Opc == UO_Minus);
12869 ExplicitPlus = !Negative;
12875 const llvm::APInt &LeftSideValue = LHSInt->getValue();
12876 llvm::APInt RightSideValue = RHSInt->getValue();
12877 if (LeftSideValue != 2 && LeftSideValue != 10)
12880 if (LeftSideValue.getBitWidth() != RightSideValue.getBitWidth())
12885 llvm::StringRef ExprStr =
12890 llvm::StringRef XorStr =
12893 if (XorStr ==
"xor")
12904 RightSideValue = -RightSideValue;
12905 RHSStr =
"-" + RHSStr;
12906 }
else if (ExplicitPlus) {
12907 RHSStr =
"+" + RHSStr;
12910 StringRef LHSStrRef = LHSStr;
12911 StringRef RHSStrRef = RHSStr;
12914 if (LHSStrRef.starts_with(
"0b") || LHSStrRef.starts_with(
"0B") ||
12915 RHSStrRef.starts_with(
"0b") || RHSStrRef.starts_with(
"0B") ||
12916 LHSStrRef.starts_with(
"0x") || LHSStrRef.starts_with(
"0X") ||
12917 RHSStrRef.starts_with(
"0x") || RHSStrRef.starts_with(
"0X") ||
12918 (LHSStrRef.size() > 1 && LHSStrRef.starts_with(
"0")) ||
12919 (RHSStrRef.size() > 1 && RHSStrRef.starts_with(
"0")) ||
12920 LHSStrRef.contains(
'\'') || RHSStrRef.contains(
'\''))
12925 const llvm::APInt XorValue = LeftSideValue ^ RightSideValue;
12926 int64_t RightSideIntValue = RightSideValue.getSExtValue();
12927 if (LeftSideValue == 2 && RightSideIntValue >= 0) {
12928 std::string SuggestedExpr =
"1 << " + RHSStr;
12929 bool Overflow =
false;
12930 llvm::APInt One = (LeftSideValue - 1);
12931 llvm::APInt PowValue = One.sshl_ov(RightSideValue, Overflow);
12933 if (RightSideIntValue < 64)
12934 S.
Diag(
Loc, diag::warn_xor_used_as_pow_base)
12935 << ExprStr <<
toString(XorValue, 10,
true) << (
"1LL << " + RHSStr)
12937 else if (RightSideIntValue == 64)
12938 S.
Diag(
Loc, diag::warn_xor_used_as_pow)
12939 << ExprStr <<
toString(XorValue, 10,
true);
12943 S.
Diag(
Loc, diag::warn_xor_used_as_pow_base_extra)
12944 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedExpr
12947 ExprRange, (RightSideIntValue == 0) ?
"1" : SuggestedExpr);
12950 S.
Diag(
Loc, diag::note_xor_used_as_pow_silence)
12951 << (
"0x2 ^ " + RHSStr) << SuggestXor;
12952 }
else if (LeftSideValue == 10) {
12953 std::string SuggestedValue =
"1e" + std::to_string(RightSideIntValue);
12954 S.
Diag(
Loc, diag::warn_xor_used_as_pow_base)
12955 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedValue
12957 S.
Diag(
Loc, diag::note_xor_used_as_pow_silence)
12958 << (
"0xA ^ " + RHSStr) << SuggestXor;
12975 getLangOpts().getOpenCLCompatibleVersion() < 120 &&
12999 bool IsCompAssign) {
13000 if (!IsCompAssign) {
13016 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13025 if (LHSMatType && !RHSMatType) {
13033 if (!LHSMatType && RHSMatType) {
13045 bool IsCompAssign) {
13046 if (!IsCompAssign) {
13057 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13059 if (LHSMatType && RHSMatType) {
13060 if (LHSMatType->getNumColumns() != RHSMatType->
getNumRows())
13068 QualType LHSELTy = LHSMatType->getElementType(),
13099 bool IsCompAssign =
13100 Opc == BO_AndAssign || Opc == BO_OrAssign || Opc == BO_XorAssign;
13111 LegalBoolVecOperator,
13141 ExprResult LHSResult = LHS, RHSResult = RHS;
13144 if (LHSResult.
isInvalid() || RHSResult.isInvalid())
13146 LHS = LHSResult.
get();
13147 RHS = RHSResult.
get();
13166 bool EnumConstantInBoolContext =
false;
13168 if (
const auto *DREHS = dyn_cast<DeclRefExpr>(HS.get())) {
13169 const auto *ECDHS = dyn_cast<EnumConstantDecl>(DREHS->getDecl());
13170 if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1)
13171 EnumConstantInBoolContext =
true;
13175 if (EnumConstantInBoolContext)
13176 Diag(
Loc, diag::warn_enum_constant_in_bool_context);
13181 const auto *LHSATy = dyn_cast<ArrayType>(LHSTy);
13182 const auto *RHSATy = dyn_cast<ArrayType>(RHSTy);
13183 if ((LHSATy && LHSATy->getElementType().isWebAssemblyReferenceType()) ||
13184 (RHSATy && RHSATy->getElementType().isWebAssemblyReferenceType())) {
13206 Diag(
Loc, diag::warn_logical_instead_of_bitwise)
13209 Diag(
Loc, diag::note_logical_instead_of_bitwise_change_operator)
13210 << (Opc == BO_LAnd ?
"&" :
"|")
13213 Opc == BO_LAnd ?
"&" :
"|");
13214 if (Opc == BO_LAnd)
13216 Diag(
Loc, diag::note_logical_instead_of_bitwise_remove_constant)
13273 if (!ME)
return false;
13277 if (!
Base)
return false;
13278 return Base->getMethodDecl() !=
nullptr;
13302 assert(S.
getLangOpts().CPlusPlus &&
"BindingDecl outside of C++?");
13311 assert(Var->
hasLocalStorage() &&
"capture added 'const' to non-local?");
13319 if (
auto *FD = dyn_cast<FunctionDecl>(DC))
13362 bool DiagnosticEmitted =
false;
13366 bool IsDereference =
false;
13367 bool NextIsDereference =
false;
13371 IsDereference = NextIsDereference;
13374 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(
E)) {
13375 NextIsDereference = ME->isArrow();
13376 const ValueDecl *VD = ME->getMemberDecl();
13377 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(VD)) {
13379 if (Field->isMutable()) {
13380 assert(DiagnosticEmitted &&
"Expected diagnostic not emitted.");
13385 if (!DiagnosticEmitted) {
13386 S.
Diag(
Loc, diag::err_typecheck_assign_const)
13388 << Field->getType();
13389 DiagnosticEmitted =
true;
13392 <<
ConstMember <<
false << Field << Field->getType()
13393 << Field->getSourceRange();
13397 }
else if (
const VarDecl *VDecl = dyn_cast<VarDecl>(VD)) {
13398 if (VDecl->getType().isConstQualified()) {
13399 if (!DiagnosticEmitted) {
13400 S.
Diag(
Loc, diag::err_typecheck_assign_const)
13402 << VDecl->getType();
13403 DiagnosticEmitted =
true;
13406 <<
ConstMember <<
true << VDecl << VDecl->getType()
13407 << VDecl->getSourceRange();
13414 dyn_cast<ArraySubscriptExpr>(
E)) {
13418 dyn_cast<ExtVectorElementExpr>(
E)) {
13425 if (
const CallExpr *CE = dyn_cast<CallExpr>(
E)) {
13429 if (!DiagnosticEmitted) {
13430 S.
Diag(
Loc, diag::err_typecheck_assign_const) << ExprRange
13432 DiagnosticEmitted =
true;
13435 diag::note_typecheck_assign_const)
13439 }
else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(
E)) {
13441 if (
const ValueDecl *VD = DRE->getDecl()) {
13443 if (!DiagnosticEmitted) {
13444 S.
Diag(
Loc, diag::err_typecheck_assign_const)
13446 DiagnosticEmitted =
true;
13448 S.
Diag(VD->getLocation(), diag::note_typecheck_assign_const)
13449 <<
ConstVariable << VD << VD->getType() << VD->getSourceRange();
13452 }
else if (isa<CXXThisExpr>(
E)) {
13454 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) {
13455 if (MD->isConst()) {
13456 if (!DiagnosticEmitted) {
13457 S.
Diag(
Loc, diag::err_typecheck_assign_const) << ExprRange
13459 DiagnosticEmitted =
true;
13461 S.
Diag(MD->getLocation(), diag::note_typecheck_assign_const)
13468 if (DiagnosticEmitted)
13485 bool &DiagnosticEmitted) {
13486 std::vector<const RecordType *> RecordTypeList;
13487 RecordTypeList.push_back(Ty);
13488 unsigned NextToCheckIndex = 0;
13491 while (RecordTypeList.size() > NextToCheckIndex) {
13492 bool IsNested = NextToCheckIndex > 0;
13494 RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
13496 QualType FieldTy = Field->getType();
13498 if (!DiagnosticEmitted) {
13499 S.
Diag(
Loc, diag::err_typecheck_assign_const)
13501 << IsNested << Field;
13502 DiagnosticEmitted =
true;
13504 S.
Diag(Field->getLocation(), diag::note_typecheck_assign_const)
13506 << FieldTy << Field->getSourceRange();
13512 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
13513 RecordTypeList.push_back(FieldRecTy);
13516 ++NextToCheckIndex;
13525 assert(Ty->
isRecordType() &&
"lvalue was not record?");
13528 bool DiagEmitted =
false;
13530 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(
E))
13533 else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(
E))
13558 unsigned DiagID = 0;
13559 bool NeedType =
false;
13566 DiagID = diag::err_block_decl_ref_not_modifiable_lvalue;
13568 DiagID = diag::err_lambda_decl_ref_not_modifiable_lvalue;
13576 if (declRef && isa<VarDecl>(declRef->
getDecl())) {
13581 if (var->isARCPseudoStrong() &&
13582 (!var->getTypeSourceInfo() ||
13583 !var->getTypeSourceInfo()->getType().isConstQualified())) {
13589 ? diag::err_typecheck_arc_assign_self_class_method
13590 : diag::err_typecheck_arc_assign_self;
13593 }
else if (var->hasAttr<ObjCExternallyRetainedAttr>() ||
13594 isa<ParmVarDecl>(var)) {
13595 DiagID = diag::err_typecheck_arc_assign_externally_retained;
13599 DiagID = diag::err_typecheck_arr_assign_enumeration;
13603 if (
Loc != OrigLoc)
13629 DiagID = diag::err_typecheck_array_not_modifiable_lvalue;
13633 DiagID = diag::err_typecheck_non_object_not_modifiable_lvalue;
13637 DiagID = diag::err_typecheck_lvalue_casts_not_supported;
13640 llvm_unreachable(
"did not take early return for MLV_Valid");
13644 DiagID = diag::err_typecheck_expression_not_modifiable_lvalue;
13649 diag::err_typecheck_incomplete_type_not_modifiable_lvalue,
E);
13651 DiagID = diag::err_typecheck_duplicate_vector_components_not_mlvalue;
13654 llvm_unreachable(
"readonly properties should be processed differently");
13656 DiagID = diag::err_readonly_message_assignment;
13659 DiagID = diag::err_no_subobject_property_setting;
13664 if (
Loc != OrigLoc)
13686 MemberExpr *ML = dyn_cast<MemberExpr>(LHSExpr);
13687 MemberExpr *MR = dyn_cast<MemberExpr>(RHSExpr);
13689 if (!(isa<CXXThisExpr>(ML->
getBase()) && isa<CXXThisExpr>(MR->
getBase())))
13695 if (LHSDecl != RHSDecl)
13700 if (RefTy->getPointeeType().isVolatileQualified())
13703 Sema.
Diag(
Loc, diag::warn_identity_field_assign) << 0;
13713 Sema.
Diag(
Loc, diag::warn_identity_field_assign) << 1;
13737 Diag(
Loc, diag::err_opencl_half_load_store) << 1
13744 Diag(
Loc, diag::err_wasm_table_art) << 0;
13749 if (CompoundType.
isNull()) {
13768 Diag(
Loc, diag::err_objc_object_assignment)
13775 RHSCheck = ICE->getSubExpr();
13776 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(RHSCheck)) {
13777 if ((UO->getOpcode() == UO_Plus || UO->getOpcode() == UO_Minus) &&
13778 Loc.
isFileID() && UO->getOperatorLoc().isFileID() &&
13784 UO->getSubExpr()->getBeginLoc().
isFileID()) {
13785 Diag(
Loc, diag::warn_not_compound_assign)
13786 << (UO->getOpcode() == UO_Plus ?
"+" :
"-")
13787 <<
SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc());
13797 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InnerLHS);
13836 if (CompoundType.
isNull()) {
13862 if (
const CastExpr *CE = dyn_cast<CastExpr>(
E)) {
13863 if (CE->getCastKind() == CK_ToVoid) {
13869 CE->getSubExpr()->getType()->isDependentType()) {
13874 if (
const auto *CE = dyn_cast<CallExpr>(
E))
13875 return CE->getCallReturnType(Context)->isVoidType();
13895 const unsigned ForIncrementFlags =
13901 if ((ScopeFlags & ForIncrementFlags) == ForIncrementFlags ||
13902 (ScopeFlags & ForInitFlags) == ForInitFlags)
13907 while (
const BinaryOperator *BO = dyn_cast<BinaryOperator>(LHS)) {
13908 if (BO->getOpcode() != BO_Comma)
13910 LHS = BO->getRHS();
13917 Diag(
Loc, diag::warn_comma_operator);
13921 LangOpts.CPlusPlus ?
"static_cast<void>("
13953 diag::err_incomplete_type);
13974 ResType = ResAtomicType->getValueType();
13976 assert(!ResType.
isNull() &&
"no type for increment/decrement expression");
13986 : diag::warn_increment_bool)
13990 S.
Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType;
14006 S.
Diag(OpLoc, S.
getLangOpts().C2y ? diag::warn_c2y_compat_increment_complex
14007 : diag::ext_c2y_increment_complex)
14024 S.
Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
14035 S.
Diag(OpLoc, diag::warn_deprecated_increment_decrement_volatile)
14036 << IsInc << ResType;
14068 case Stmt::DeclRefExprClass:
14069 return cast<DeclRefExpr>(
E)->getDecl();
14070 case Stmt::MemberExprClass:
14074 if (cast<MemberExpr>(
E)->isArrow())
14078 case Stmt::ArraySubscriptExprClass: {
14081 Expr*
Base = cast<ArraySubscriptExpr>(
E)->getBase();
14083 if (ICE->getSubExpr()->getType()->isArrayType())
14088 case Stmt::UnaryOperatorClass: {
14100 case Stmt::ParenExprClass:
14102 case Stmt::ImplicitCastExprClass:
14106 case Stmt::CXXUuidofExprClass:
14107 return cast<CXXUuidofExpr>(
E)->getGuidDecl();
14116 AO_Vector_Element = 1,
14117 AO_Property_Expansion = 2,
14118 AO_Register_Variable = 3,
14119 AO_Matrix_Element = 4,
14134 const auto *DRE = cast<DeclRefExpr>(Op->
IgnoreParens());
14137 return Diag(OpLoc, diag::err_parens_pointer_member_function)
14141 if (isa<CXXDestructorDecl>(MD))
14142 return Diag(OpLoc, diag::err_typecheck_addrof_dtor)
14143 << DRE->getSourceRange();
14145 if (DRE->getQualifier())
14149 return Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14150 << DRE->getSourceRange();
14154 return Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14155 << DRE->getSourceRange()
14161 if (PTy->getKind() == BuiltinType::Overload) {
14163 if (!isa<OverloadExpr>(
E)) {
14164 assert(cast<UnaryOperator>(
E)->getOpcode() == UO_AddrOf);
14165 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof_addrof_function)
14171 if (isa<UnresolvedMemberExpr>(Ovl))
14173 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14181 if (PTy->getKind() == BuiltinType::UnknownAny)
14184 if (PTy->getKind() == BuiltinType::BoundMember) {
14185 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14208 auto* VarRef = dyn_cast<DeclRefExpr>(op);
14209 if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
14210 Diag(op->
getExprLoc(), diag::err_opencl_taking_address_capture);
14218 if (uOp->getOpcode() == UO_Deref)
14221 return uOp->getSubExpr()->getType();
14228 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(dcl))
14234 unsigned AddressOfError = AO_No_Error;
14239 : diag::ext_typecheck_addrof_temporary)
14246 }
else if (isa<ObjCSelectorExpr>(op)) {
14253 if (!isa<DeclRefExpr>(op)) {
14254 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14273 auto ReturnOrParamTypeIsIncomplete = [&](
QualType T,
14278 diag::note_ptrauth_virtual_function_pointer_incomplete_arg_ret);
14279 Diag(RetArgTypeLoc,
14280 diag::note_ptrauth_virtual_function_incomplete_arg_ret_type)
14287 bool IsIncomplete =
14289 ReturnOrParamTypeIsIncomplete(
14292 IsIncomplete |= ReturnOrParamTypeIsIncomplete(PVD->getType(), OpLoc,
14293 PVD->getBeginLoc());
14307 if (isa<PseudoObjectExpr>(op)) {
14308 AddressOfError = AO_Property_Expansion;
14310 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof)
14314 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(op)) {
14315 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl()))
14321 AddressOfError = AO_Bit_Field;
14324 AddressOfError = AO_Vector_Element;
14327 AddressOfError = AO_Matrix_Element;
14331 if (
const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
14336 AddressOfError = AO_Register_Variable;
14338 }
else if (isa<MSPropertyDecl>(dcl)) {
14339 AddressOfError = AO_Property_Expansion;
14340 }
else if (isa<FunctionTemplateDecl>(dcl)) {
14342 }
else if (isa<FieldDecl>(dcl) || isa<IndirectFieldDecl>(dcl)) {
14352 if (isa<DeclRefExpr>(op) && cast<DeclRefExpr>(op)->getQualifier() &&
14353 !isa<ParenExpr>(OrigOp.
get())) {
14358 diag::err_cannot_form_pointer_to_member_of_reference_type)
14363 while (cast<RecordDecl>(Ctx)->isAnonymousStructOrUnion())
14377 llvm_unreachable(
"Unknown/unexpected decl type");
14380 if (AddressOfError != AO_No_Error) {
14400 Diag(OpLoc, diag::err_wasm_ca_reference)
14405 Diag(OpLoc, diag::err_wasm_table_pr)
14411 CheckAddressOfPackedMember(op);
14417 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Exp);
14427 if (!FD->hasAttr<NonNullAttr>() && !Param->
hasAttr<NonNullAttr>())
14430 FD->ModifiedNonNullParams.insert(Param);
14436 bool IsAfterAmp =
false) {
14440 Op = ConvResult.
get();
14444 if (isa<CXXReinterpretCastExpr>(Op)) {
14452 Result = PT->getPointeeType();
14456 Result = OPT->getPointeeType();
14460 if (PR.
get() != Op)
14465 S.
Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer)
14470 if (
Result->isVoidType()) {
14476 S.
Diag(OpLoc, diag::err_typecheck_indirection_through_void_pointer_cpp)
14479 S.
Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
14496 default: llvm_unreachable(
"Unknown binop!");
14497 case tok::periodstar: Opc = BO_PtrMemD;
break;
14498 case tok::arrowstar: Opc = BO_PtrMemI;
break;
14499 case tok::star: Opc = BO_Mul;
break;
14500 case tok::slash: Opc = BO_Div;
break;
14501 case tok::percent: Opc = BO_Rem;
break;
14502 case tok::plus: Opc = BO_Add;
break;
14503 case tok::minus: Opc = BO_Sub;
break;
14504 case tok::lessless: Opc = BO_Shl;
break;
14505 case tok::greatergreater: Opc = BO_Shr;
break;
14506 case tok::lessequal: Opc = BO_LE;
break;
14507 case tok::less: Opc = BO_LT;
break;
14508 case tok::greaterequal: Opc = BO_GE;
break;
14509 case tok::greater: Opc = BO_GT;
break;
14510 case tok::exclaimequal: Opc = BO_NE;
break;
14511 case tok::equalequal: Opc = BO_EQ;
break;
14512 case tok::spaceship: Opc = BO_Cmp;
break;
14513 case tok::amp: Opc = BO_And;
break;
14514 case tok::caret: Opc = BO_Xor;
break;
14515 case tok::pipe: Opc = BO_Or;
break;
14516 case tok::ampamp: Opc = BO_LAnd;
break;
14517 case tok::pipepipe: Opc = BO_LOr;
break;
14518 case tok::equal: Opc = BO_Assign;
break;
14519 case tok::starequal: Opc = BO_MulAssign;
break;
14520 case tok::slashequal: Opc = BO_DivAssign;
break;
14521 case tok::percentequal: Opc = BO_RemAssign;
break;
14522 case tok::plusequal: Opc = BO_AddAssign;
break;
14523 case tok::minusequal: Opc = BO_SubAssign;
break;
14524 case tok::lesslessequal: Opc = BO_ShlAssign;
break;
14525 case tok::greatergreaterequal: Opc = BO_ShrAssign;
break;
14526 case tok::ampequal: Opc = BO_AndAssign;
break;
14527 case tok::caretequal: Opc = BO_XorAssign;
break;
14528 case tok::pipeequal: Opc = BO_OrAssign;
break;
14529 case tok::comma: Opc = BO_Comma;
break;
14538 default: llvm_unreachable(
"Unknown unary op!");
14539 case tok::plusplus: Opc = UO_PreInc;
break;
14540 case tok::minusminus: Opc = UO_PreDec;
break;
14541 case tok::amp: Opc = UO_AddrOf;
break;
14542 case tok::star: Opc = UO_Deref;
break;
14543 case tok::plus: Opc = UO_Plus;
break;
14544 case tok::minus: Opc = UO_Minus;
break;
14545 case tok::tilde: Opc = UO_Not;
break;
14546 case tok::exclaim: Opc = UO_LNot;
break;
14547 case tok::kw___real: Opc = UO_Real;
break;
14548 case tok::kw___imag: Opc = UO_Imag;
break;
14549 case tok::kw___extension__: Opc = UO_Extension;
break;
14565 if (!isa<ParmVarDecl>(SelfAssigned))
14567 const auto *Method =
14581 llvm::find_if(
Parent->fields(),
14583 return F->getDeclName() == Name;
14585 return (Field !=
Parent->field_end()) ? *Field :
nullptr;
14600 const DeclRefExpr *LHSDeclRef = dyn_cast<DeclRefExpr>(LHSExpr);
14601 const DeclRefExpr *RHSDeclRef = dyn_cast<DeclRefExpr>(RHSExpr);
14602 if (!LHSDeclRef || !RHSDeclRef ||
14610 if (LHSDecl != RHSDecl)
14615 if (RefTy->getPointeeType().isVolatileQualified())
14618 auto Diag = S.
Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
14619 : diag::warn_self_assignment_overloaded)
14624 Diag << 1 << SelfAssignField
14637 const Expr *ObjCPointerExpr =
nullptr, *OtherExpr =
nullptr;
14642 ObjCPointerExpr = LHS;
14646 ObjCPointerExpr = RHS;
14654 if (ObjCPointerExpr && isa<IntegerLiteral>(OtherExpr->IgnoreParenCasts())) {
14655 unsigned Diag = diag::warn_objc_pointer_masking;
14663 StringRef SelArg0 = S.getNameForSlot(0);
14664 if (SelArg0.starts_with(
"performSelector"))
14665 Diag = diag::warn_objc_pointer_masking_performSelector;
14676 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E))
14677 return DRE->getDecl();
14678 if (
auto *ME = dyn_cast<MemberExpr>(
E))
14679 return ME->getMemberDecl();
14680 if (
auto *IRE = dyn_cast<ObjCIvarRefExpr>(
E))
14681 return IRE->getDecl();
14696 "Result must be a vector of half or short");
14699 "both operands expected to be a half vector");
14711 ResultTy, VK, OK, OpLoc, FPFeatures,
14712 BinOpResTy, BinOpResTy);
14716 BinOpResTy, VK, OK, OpLoc, FPFeatures);
14720static std::pair<ExprResult, ExprResult>
14730 RHS,
nullptr,
false,
14731 [Opc, LHS](
Expr *
E) {
14732 if (Opc != BO_Assign)
14739 return std::make_pair(LHS, RHS);
14746 if (!OpRequiresConversion || Ctx.
getLangOpts().NativeHalfType ||
14750 auto HasVectorOfHalfType = [&Ctx](
Expr *
E) {
14760 return VT->getElementType().getCanonicalType() == Ctx.
HalfTy;
14765 return HasVectorOfHalfType(E0) && (!E1 || HasVectorOfHalfType(E1));
14784 if (
Init.isInvalid())
14786 RHSExpr =
Init.get();
14796 bool ConvertHalfVec =
false;
14799 if (!LHS.
isUsable() || !RHS.isUsable())
14809 if (BO_Assign == Opc)
14810 Diag(OpLoc, diag::err_opencl_atomic_init) << 0 << SR;
14838 if (!ResultTy.
isNull()) {
14855 if (
auto *BE = dyn_cast<BlockExpr>(RHS.get()->IgnoreParens()))
14857 if (
auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
14858 if (VD->hasLocalStorage() &&
getCurScope()->isDeclScope(VD))
14859 BE->getBlockDecl()->setCanAvoidCopyToHeap();
14870 Opc == BO_PtrMemI);
14874 ConvertHalfVec =
true;
14882 ConvertHalfVec =
true;
14886 ConvertHalfVec =
true;
14897 ConvertHalfVec =
true;
14900 if (
const auto *BI = dyn_cast<BinaryOperator>(LHSExpr);
14901 BI && BI->isComparisonOp())
14902 Diag(OpLoc, diag::warn_consecutive_comparison);
14907 ConvertHalfVec =
true;
14911 ConvertHalfVec =
true;
14924 ConvertHalfVec =
true;
14929 ConvertHalfVec =
true;
14931 Opc == BO_DivAssign);
14932 CompLHSTy = CompResultTy;
14939 CompLHSTy = CompResultTy;
14945 ConvertHalfVec =
true;
14952 ConvertHalfVec =
true;
14961 CompLHSTy = CompResultTy;
14972 CompLHSTy = CompResultTy;
14980 VK = RHS.get()->getValueKind();
14981 OK = RHS.get()->getObjectKind();
14995 "both sides are half vectors or neither sides are");
15000 CheckArrayAccess(LHS.
get());
15001 CheckArrayAccess(RHS.get());
15007 if (ObjectSetClass && isa<ObjCIsaExpr>(LHS.
get())) {
15011 "object_setClass(")
15024 if (CompResultTy.
isNull()) {
15025 if (ConvertHalfVec)
15045 if (ConvertHalfVec)
15050 Context, LHS.
get(), RHS.get(), Opc, ResultTy, VK, OK, OpLoc,
15067 if (isLeftComp == isRightComp)
15072 bool isLeftBitwise = LHSBO && LHSBO->
isBitwiseOp();
15073 bool isRightBitwise = RHSBO && RHSBO->
isBitwiseOp();
15074 if (isLeftBitwise || isRightBitwise)
15086 Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
15089 Self.PDiag(diag::note_precedence_silence) << OpStr,
15090 (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange());
15092 Self.PDiag(diag::note_precedence_bitwise_first)
15107 Self.PDiag(diag::note_precedence_silence)
15116 if (Bop->getOpcode() == BO_LAnd) {
15119 if (!isa<StringLiteral>(Bop->getLHS()->IgnoreParenImpCasts()))
15121 }
else if (Bop->getOpcode() == BO_LOr) {
15122 if (
BinaryOperator *RBop = dyn_cast<BinaryOperator>(Bop->getRHS())) {
15125 if (RBop->getOpcode() == BO_LAnd &&
15126 isa<StringLiteral>(RBop->getRHS()->IgnoreParenImpCasts()))
15137 if (Bop->getOpcode() == BO_LAnd) {
15140 if (!isa<StringLiteral>(Bop->getRHS()->IgnoreParenImpCasts()))
15152 if (Bop->isBitwiseOp() && Bop->getOpcode() < Opc) {
15153 S.
Diag(Bop->getOperatorLoc(), diag::warn_bitwise_op_in_bitwise_op)
15155 << Bop->getSourceRange() << OpLoc;
15157 S.
PDiag(diag::note_precedence_silence)
15158 << Bop->getOpcodeStr(),
15159 Bop->getSourceRange());
15165 Expr *SubExpr, StringRef Shift) {
15167 if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) {
15168 StringRef Op = Bop->getOpcodeStr();
15169 S.
Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift)
15170 << Bop->getSourceRange() << OpLoc << Shift << Op;
15172 S.
PDiag(diag::note_precedence_silence) << Op,
15173 Bop->getSourceRange());
15189 if (Kind != OO_LessLess && Kind != OO_GreaterGreater)
15192 S.
Diag(OpLoc, diag::warn_overloaded_shift_in_comparison)
15194 << (Kind == OO_LessLess);
15196 S.
PDiag(diag::note_precedence_silence)
15197 << (Kind == OO_LessLess ?
"<<" :
">>"),
15200 S, OpLoc, S.
PDiag(diag::note_evaluate_comparison_first),
15214 if ((Opc == BO_Or || Opc == BO_Xor) &&
15222 if (Opc == BO_LOr && !OpLoc.
isMacroID()) {
15228 || Opc == BO_Shr) {
15242 if (
auto *CT = Operand->getType()->getAs<
ComplexType>()) {
15243 QualType ElementType = CT->getElementType();
15244 bool IsComplexRangePromoted = S.
getLangOpts().getComplexRange() ==
15249 const llvm::fltSemantics &ElementTypeSemantics =
15251 const llvm::fltSemantics &HigherElementTypeSemantics =
15253 if (llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 >
15254 llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) {
15259 if (
Type == HigherElementType) {
15275 assert(LHSExpr &&
"ActOnBinOp(): missing left expression");
15276 assert(RHSExpr &&
"ActOnBinOp(): missing right expression");
15283 if (Kind == tok::TokenKind::slash)
15286 BuiltinCountedByRefKind K =
15289 CheckInvalidBuiltinCountedByRef(LHSExpr, K);
15290 CheckInvalidBuiltinCountedByRef(RHSExpr, K);
15292 return BuildBinOp(S, TokLoc, Opc, LHSExpr, RHSExpr);
15298 if (OverOp !=
OO_None && OverOp != OO_Equal)
15352 LHSExpr = LHS.
get();
15353 RHSExpr = RHS.
get();
15364 if (pty->getKind() == BuiltinType::PseudoObject &&
15377 RHSExpr = resolvedRHS.
get();
15391 (pty->getKind() == BuiltinType::BoundMember ||
15392 pty->getKind() == BuiltinType::Overload)) {
15393 auto *OE = dyn_cast<OverloadExpr>(LHSExpr);
15394 if (OE && !OE->hasTemplateKeyword() && !OE->hasExplicitTemplateArgs() &&
15395 llvm::any_of(OE->decls(), [](
NamedDecl *ND) {
15396 return isa<FunctionTemplateDecl>(ND);
15398 Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc()
15399 : OE->getNameLoc(),
15400 diag::err_template_kw_missing)
15401 << OE->getName().getAsString() <<
"";
15408 LHSExpr = LHS.
get();
15415 if (Opc == BO_Assign && pty->getKind() == BuiltinType::Overload) {
15431 RHSExpr = resolvedRHS.
get();
15447 "Should only occur in error-recovery path.");
15453 Context, LHSExpr, RHSExpr, Opc,
15473 ResultType = RHSExpr->
getType();
15505 bool CanOverflow =
false;
15507 bool ConvertHalfVec =
false;
15516 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15523 if (Opc == UO_AddrOf)
15524 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
15525 if (Opc == UO_Deref)
15526 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
15540 Opc == UO_PreInc || Opc == UO_PostInc,
15541 Opc == UO_PreInc || Opc == UO_PreDec);
15546 CheckAddressOfNoDeref(InputExpr);
15559 CanOverflow = Opc == UO_Minus &&
15571 if (ConvertHalfVec)
15588 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15599 Diag(OpLoc, diag::ext_integer_complement_complex)
15608 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15611 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15633 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15649 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15659 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15669 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15676 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15710 "the co_await expression must be non-dependant before "
15711 "building operator co_await");
15722 if (Opc != UO_AddrOf && Opc != UO_Deref)
15723 CheckArrayAccess(Input.
get());
15729 if (Opc == UO_Deref && UO->getType()->hasAttr(attr::NoDeref) &&
15730 !isa<ArrayType>(UO->getType().getDesugaredType(
Context)) &&
15735 if (ConvertHalfVec)
15742 if (!DRE->getQualifier())
15749 if (isa<FieldDecl>(VD) || isa<IndirectFieldDecl>(VD))
15752 return Method->isImplicitObjectMemberFunction();
15758 if (!ULE->getQualifier())
15763 if (Method->isImplicitObjectMemberFunction())
15784 if (pty->getKind() == BuiltinType::PseudoObject &&
15789 if (Opc == UO_Extension)
15794 if (Opc == UO_AddrOf &&
15795 (pty->getKind() == BuiltinType::Overload ||
15796 pty->getKind() == BuiltinType::UnknownAny ||
15797 pty->getKind() == BuiltinType::BoundMember))
15822 Expr *Input,
bool IsAfterAmp) {
15861 assert(SubStmt && isa<CompoundStmt>(SubStmt) &&
"Invalid action invocation!");
15867 "cleanups within StmtExpr not correctly bound!");
15877 bool StmtExprMayBindToTemp =
false;
15880 if (
const auto *LastStmt =
15882 if (
const Expr *
Value = LastStmt->getExprStmt()) {
15883 StmtExprMayBindToTemp =
true;
15891 Expr *ResStmtExpr =
15893 if (StmtExprMayBindToTemp)
15895 return ResStmtExpr;
15918 auto *Cast = dyn_cast<ImplicitCastExpr>(
E);
15919 if (Cast && Cast->getCastKind() == CK_ARCConsumeObject)
15920 return Cast->getSubExpr();
15941 return ExprError(
Diag(BuiltinLoc, diag::err_offsetof_record_type)
15942 << ArgTy << TypeRange);
15948 diag::err_offsetof_incomplete_type, TypeRange))
15951 bool DidWarnAboutNonPOD =
false;
15956 if (OC.isBrackets) {
15961 return ExprError(
Diag(OC.LocEnd, diag::err_offsetof_array_type)
15981 Comps.push_back(
OffsetOfNode(OC.LocStart, Exprs.size(), OC.LocEnd));
15982 Exprs.push_back(Idx);
15990 Comps.push_back(
OffsetOfNode(OC.LocStart, OC.U.IdentInfo, OC.LocEnd));
15997 diag::err_offsetof_incomplete_type))
16003 return ExprError(
Diag(OC.LocEnd, diag::err_offsetof_record_type)
16015 bool IsSafe =
LangOpts.CPlusPlus11? CRD->isStandardLayout() : CRD->isPOD();
16017 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
16018 : diag::ext_offsetof_non_pod_type;
16021 Diag(BuiltinLoc, DiagID)
16022 <<
SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
16023 DidWarnAboutNonPOD =
true;
16034 MemberDecl = IndirectMemberDecl->getAnonField();
16042 Diag(BuiltinLoc, diag::err_no_member)
16043 << OC.U.IdentInfo << RD <<
SourceRange(OC.LocStart, OC.LocEnd);
16052 Diag(OC.LocEnd, diag::err_offsetof_bitfield)
16060 if (IndirectMemberDecl)
16061 Parent = cast<RecordDecl>(IndirectMemberDecl->getDeclContext());
16068 if (Paths.getDetectedVirtual()) {
16069 Diag(OC.LocEnd, diag::err_offsetof_field_of_virtual_base)
16080 if (IndirectMemberDecl) {
16081 for (
auto *FI : IndirectMemberDecl->chain()) {
16082 assert(isa<FieldDecl>(FI));
16084 cast<FieldDecl>(FI), OC.LocEnd));
16087 Comps.push_back(
OffsetOfNode(OC.LocStart, MemberDecl, OC.LocEnd));
16093 Comps, Exprs, RParenLoc);
16119 assert((CondExpr && LHSExpr && RHSExpr) &&
"Missing type argument(s)");
16124 bool CondIsTrue =
false;
16129 llvm::APSInt condEval(32);
16131 CondExpr, &condEval, diag::err_typecheck_choose_expr_requires_constant);
16134 CondExpr = CondICE.
get();
16135 CondIsTrue = condEval.getZExtValue();
16138 Expr *ActiveExpr = CondIsTrue ? LHSExpr : RHSExpr;
16140 resType = ActiveExpr->
getType();
16146 resType, VK, OK, RPLoc, CondIsTrue);
16158 Decl *ManglingContextDecl;
16159 std::tie(MCtx, ManglingContextDecl) =
16163 Block->setBlockMangling(ManglingNumber, ManglingContextDecl);
16185 "block-id should have no identifier!");
16197 "GetTypeForDeclarator made a non-function block signature");
16213 unsigned Size =
Result.getFullDataSize();
16225 QualType RetTy = Fn->getReturnType();
16227 (isa<FunctionProtoType>(Fn) && cast<FunctionProtoType>(Fn)->isVariadic());
16243 if (ExplicitSignature) {
16244 for (
unsigned I = 0,
E = ExplicitSignature.
getNumParams(); I !=
E; ++I) {
16252 Params.push_back(Param);
16258 for (
const auto &I : Fn->param_types()) {
16261 Params.push_back(Param);
16266 if (!Params.empty()) {
16277 AI->setOwningFunction(CurBlock->
TheDecl);
16280 if (AI->getIdentifier()) {
16286 if (AI->isInvalidDecl())
16305 Diag(CaretLoc, diag::err_blocks_disable) <<
LangOpts.OpenCL;
16311 "cleanups within block not correctly bound!");
16326 bool NoReturn = BD->
hasAttr<NoReturnAttr>();
16334 if (NoReturn && !Ext.getNoReturn()) Ext = Ext.
withNoReturn(
true);
16337 if (isa<FunctionNoProtoType>(FTy)) {
16372 BD->
setBody(cast<CompoundStmt>(Body));
16374 if (Body &&
getCurFunction()->HasPotentialAvailabilityViolations)
16399 Expr *CopyExpr =
nullptr;
16408 if (isa<ParmVarDecl>(Var))
16427 if (!
Result.isInvalid() &&
16428 !
Result.get()->getType().isConstQualified()) {
16430 Result.get()->getType().withConst(),
16434 if (!
Result.isInvalid()) {
16444 if (!
Result.isInvalid() &&
16445 !cast<CXXConstructExpr>(
Result.get())->getConstructor()
16448 CopyExpr =
Result.get();
16455 Captures.push_back(NewCap);
16468 if (
Result->getBlockDecl()->hasCaptures()) {
16475 for (
const auto &CI :
Result->getBlockDecl()->captures()) {
16476 const VarDecl *var = CI.getVariable();
16491 {Result},
Result->getType());
16505 Expr *OrigExpr =
E;
16555 if (
Init.isInvalid())
16571 diag::err_first_argument_to_va_arg_not_of_type_va_list)
16576 diag::err_second_parameter_to_va_arg_incomplete,
16582 diag::err_second_parameter_to_va_arg_abstract,
16589 ? diag::warn_second_parameter_to_va_arg_ownership_qualified
16590 : diag::warn_second_parameter_to_va_arg_not_pod)
16597 PDiag(diag::warn_second_parameter_to_va_arg_array)
16630 UnderlyingType = ET->getDecl()->getIntegerType();
16653 if (!PromoteType.
isNull())
16655 PDiag(diag::warn_second_parameter_to_va_arg_never_compatible)
16677 llvm_unreachable(
"I don't know size of pointer!");
16694 if ((SLDecl->isCompleteDefinition() || SLDecl->isBeingDefined()) &&
16703 S.
Diag(
Loc, diag::err_std_source_location_impl_not_found);
16711 S.
Diag(
Loc, diag::err_std_source_location_impl_malformed);
16715 unsigned Count = 0;
16717 StringRef Name = F->getName();
16719 if (Name ==
"_M_file_name") {
16720 if (F->getType() !=
16724 }
else if (Name ==
"_M_function_name") {
16725 if (F->getType() !=
16729 }
else if (Name ==
"_M_line") {
16730 if (!F->getType()->isIntegerType())
16733 }
else if (Name ==
"_M_column") {
16734 if (!F->getType()->isIntegerType())
16743 S.
Diag(
Loc, diag::err_std_source_location_impl_malformed);
16794 Data->BinaryData = BinaryData;
16797 Data->getDataElementCount());
16801 const Expr *SrcExpr) {
16810 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
16823 bool *Complained) {
16825 *Complained =
false;
16828 bool CheckInferredResultType =
false;
16830 unsigned DiagKind = 0;
16832 bool MayHaveConvFixit =
false;
16833 bool MayHaveFunctionDiff =
false;
16844 DiagKind = diag::err_typecheck_convert_pointer_int;
16847 DiagKind = diag::ext_typecheck_convert_pointer_int;
16850 MayHaveConvFixit =
true;
16854 DiagKind = diag::err_typecheck_convert_int_pointer;
16857 DiagKind = diag::ext_typecheck_convert_int_pointer;
16860 MayHaveConvFixit =
true;
16864 diag::warn_typecheck_convert_incompatible_function_pointer_strict;
16866 MayHaveConvFixit =
true;
16870 DiagKind = diag::err_typecheck_convert_incompatible_function_pointer;
16873 DiagKind = diag::ext_typecheck_convert_incompatible_function_pointer;
16876 MayHaveConvFixit =
true;
16880 DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer;
16882 DiagKind = diag::err_typecheck_convert_incompatible_pointer;
16885 DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
16889 if (CheckInferredResultType) {
16895 MayHaveConvFixit =
true;
16899 DiagKind = diag::err_typecheck_convert_incompatible_pointer_sign;
16902 DiagKind = diag::ext_typecheck_convert_incompatible_pointer_sign;
16907 DiagKind = diag::err_typecheck_convert_pointer_void_func;
16910 DiagKind = diag::ext_typecheck_convert_pointer_void_func;
16922 DiagKind = diag::err_typecheck_incompatible_address_space;
16925 DiagKind = diag::err_typecheck_incompatible_ownership;
16929 llvm_unreachable(
"unknown error case for discarding qualifiers!");
16946 DiagKind = diag::err_typecheck_convert_discards_qualifiers;
16949 DiagKind = diag::ext_typecheck_convert_discards_qualifiers;
16956 DiagKind = diag::err_nested_pointer_qualifier_mismatch;
16958 DiagKind = diag::ext_nested_pointer_qualifier_mismatch;
16962 DiagKind = diag::err_typecheck_incompatible_nested_address_space;
16966 DiagKind = diag::err_int_to_block_pointer;
16970 DiagKind = diag::err_typecheck_convert_incompatible_block_pointer;
16977 for (
auto *srcProto : srcOPT->
quals()) {
16983 IFace = IFaceT->getDecl();
16988 for (
auto *dstProto : dstOPT->
quals()) {
16994 IFace = IFaceT->getDecl();
16997 DiagKind = diag::err_incompatible_qualified_id;
17000 DiagKind = diag::warn_incompatible_qualified_id;
17006 DiagKind = diag::err_incompatible_vectors;
17009 DiagKind = diag::warn_incompatible_vectors;
17013 DiagKind = diag::err_arc_weak_unavailable_assign;
17019 *Complained =
true;
17023 DiagKind = diag::err_typecheck_convert_incompatible;
17025 MayHaveConvFixit =
true;
17027 MayHaveFunctionDiff =
true;
17036 FirstType = DstType;
17037 SecondType = SrcType;
17047 FirstType = SrcType;
17048 SecondType = DstType;
17057 FDiag << FirstType << SecondType << ActionForDiag
17060 if (DiagKind == diag::ext_typecheck_convert_incompatible_pointer_sign ||
17061 DiagKind == diag::err_typecheck_convert_incompatible_pointer_sign) {
17071 if (!ConvHints.
isNull()) {
17076 if (MayHaveConvFixit) { FDiag << (
unsigned) (ConvHints.
Kind); }
17078 if (MayHaveFunctionDiff)
17082 if ((DiagKind == diag::warn_incompatible_qualified_id ||
17083 DiagKind == diag::err_incompatible_qualified_id) &&
17085 Diag(IFace->
getLocation(), diag::note_incomplete_class_and_qualified_id)
17092 if (CheckInferredResultType)
17099 *Complained =
true;
17110 return S.
Diag(
Loc, diag::err_ice_not_integral)
17129 IDDiagnoser(
unsigned DiagID)
17135 } Diagnoser(DiagID);
17170 BaseDiagnoser(BaseDiagnoser) {}
17179 return S.
Diag(
Loc, diag::err_ice_incomplete_type) <<
T;
17184 return S.
Diag(
Loc, diag::err_ice_explicit_conversion) <<
T << ConvTy;
17195 return S.
Diag(
Loc, diag::err_ice_ambiguous_conversion) <<
T;
17206 llvm_unreachable(
"conversion functions are permitted");
17208 } ConvertDiagnoser(Diagnoser);
17214 E = Converted.
get();
17219 if (isa<RecoveryExpr>(
E))
17235 E = RValueExpr.
get();
17243 if (!isa<ConstantExpr>(
E))
17253 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
17254 diag::note_invalid_subexpr_in_const_expr) {
17255 DiagLoc = Notes[0].first;
17277 EvalResult.
Diag = &Notes;
17286 if (!isa<ConstantExpr>(
E))
17292 if (Folded &&
getLangOpts().CPlusPlus11 && Notes.empty()) {
17301 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
17302 diag::note_invalid_subexpr_in_const_expr) {
17303 DiagLoc = Notes[0].first;
17307 if (!Folded || !CanFold) {
17329 class TransformToPE :
public TreeTransform<TransformToPE> {
17333 TransformToPE(
Sema &SemaRef) : BaseTransform(SemaRef) { }
17336 bool AlwaysRebuild() {
return true; }
17337 bool ReplacingOriginal() {
return true; }
17347 if (isa<FieldDecl>(
E->getDecl()) &&
17348 !SemaRef.isUnevaluatedContext())
17349 return SemaRef.Diag(
E->getLocation(),
17350 diag::err_invalid_non_static_member_use)
17353 return BaseTransform::TransformDeclRefExpr(
E);
17361 return BaseTransform::TransformUnaryOperator(
E);
17369 return SkipLambdaBody(
E, Body);
17376 "Should only transform unevaluated expressions");
17381 return TransformToPE(*this).TransformExpr(
E);
17386 "Should only transform unevaluated expressions");
17390 return TransformToPE(*this).TransformType(TInfo);
17398 LambdaContextDecl, ExprContext);
17412 Prev.isImmediateFunctionContext() || Prev.isConstantEvaluated();
17415 Prev.InImmediateEscalatingFunctionContext;
17434 if (
const auto *
E = dyn_cast<UnaryOperator>(PossibleDeref)) {
17435 if (
E->getOpcode() == UO_Deref)
17436 return CheckPossibleDeref(S,
E->getSubExpr());
17437 }
else if (
const auto *
E = dyn_cast<ArraySubscriptExpr>(PossibleDeref)) {
17438 return CheckPossibleDeref(S,
E->getBase());
17439 }
else if (
const auto *
E = dyn_cast<MemberExpr>(PossibleDeref)) {
17440 return CheckPossibleDeref(S,
E->getBase());
17441 }
else if (
const auto E = dyn_cast<DeclRefExpr>(PossibleDeref)) {
17445 Inner = Ptr->getPointeeType();
17447 Inner = Arr->getElementType();
17451 if (Inner->hasAttr(attr::NoDeref))
17461 const DeclRefExpr *DeclRef = CheckPossibleDeref(*
this,
E);
17468 Diag(
E->
getExprLoc(), diag::warn_dereference_of_noderef_type_no_decl)
17483 if (BO->getOpcode() == BO_Assign) {
17485 llvm::erase(LHSs, BO->getLHS());
17493 "Cannot mark an immediate escalating expression outside of an "
17494 "immediate escalating context");
17497 if (
auto *DeclRef =
17498 dyn_cast<DeclRefExpr>(
Call->getCallee()->IgnoreImplicit()))
17499 DeclRef->setIsImmediateEscalating(
true);
17500 }
else if (
auto *Ctr = dyn_cast<CXXConstructExpr>(
E->
IgnoreImplicit())) {
17501 Ctr->setIsImmediateEscalating(
true);
17502 }
else if (
auto *DeclRef = dyn_cast<DeclRefExpr>(
E->
IgnoreImplicit())) {
17503 DeclRef->setIsImmediateEscalating(
true);
17505 assert(
false &&
"expected an immediately escalating expression");
17508 FI->FoundImmediateEscalatingExpression =
true;
17523 if (
auto *DeclRef =
17524 dyn_cast<DeclRefExpr>(
Call->getCallee()->IgnoreImplicit()))
17533 auto CheckConstantExpressionAndKeepResult = [&]() {
17536 Eval.
Diag = &Notes;
17538 Eval,
getASTContext(), ConstantExprKind::ImmediateInvocation);
17539 if (Res && Notes.empty()) {
17540 Cached = std::move(Eval.
Val);
17548 !CheckConstantExpressionAndKeepResult()) {
17583 ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
17591 Eval.
Diag = &Notes;
17595 if (!
Result || !Notes.empty()) {
17598 if (
auto *
FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr))
17601 if (
auto *
Call = dyn_cast<CallExpr>(InnerExpr))
17602 FD = cast<FunctionDecl>(
Call->getCalleeDecl());
17603 else if (
auto *
Call = dyn_cast<CXXConstructExpr>(InnerExpr))
17604 FD =
Call->getConstructor();
17605 else if (
auto *Cast = dyn_cast<CastExpr>(InnerExpr))
17606 FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction());
17609 "could not find an immediate function in this expression");
17622 for (
auto &
Note : Notes)
17634 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
17638 ComplexRemove(
Sema &SemaRef, llvm::SmallPtrSetImpl<DeclRefExpr *> &DR,
17641 4>::reverse_iterator Current)
17642 :
Base(SemaRef), DRSet(DR), IISet(II), CurrentII(Current) {}
17644 auto It = std::find_if(CurrentII, IISet.rend(),
17646 return Elem.getPointer() == E;
17652 if (It == IISet.rend()) {
17654 CurrentII->setInt(1);
17660 if (!
E->isImmediateInvocation())
17661 return Base::TransformConstantExpr(
E);
17662 RemoveImmediateInvocation(
E);
17663 return Base::TransformExpr(
E->getSubExpr());
17669 return Base::TransformCXXOperatorCallExpr(
E);
17683 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(
Init))
17684 Init = ICE->getSubExpr();
17685 else if (
auto *ICE = dyn_cast<MaterializeTemporaryExpr>(
Init))
17686 Init = ICE->getSubExpr();
17692 if (
auto *CE = dyn_cast<ConstantExpr>(
Init);
17693 CE && CE->isImmediateInvocation())
17694 RemoveImmediateInvocation(CE);
17695 return Base::TransformInitializer(
Init, NotCopyInit);
17706 bool AlwaysRebuild() {
return false; }
17707 bool ReplacingOriginal() {
return true; }
17708 bool AllowSkippingCXXConstructExpr() {
17709 bool Res = AllowSkippingFirstCXXConstructExpr;
17710 AllowSkippingFirstCXXConstructExpr =
true;
17713 bool AllowSkippingFirstCXXConstructExpr =
true;
17723 if (isa<CXXConstructExpr>(It->getPointer()->IgnoreImplicit()))
17724 Transformer.AllowSkippingFirstCXXConstructExpr =
false;
17726 ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
17732 It->getPointer()->setSubExpr(Res.
get());
17767 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
17768 SimpleRemove(llvm::SmallPtrSetImpl<DeclRefExpr *> &S) : DRSet(S) {}
17771 return DRSet.size();
17774 Visitor.TraverseStmt(
17784 if (DR->isImmediateEscalating())
17786 auto *FD = cast<FunctionDecl>(DR->getDecl());
17788 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND);
17790 ND = MD->getParent();
17797 bool ImmediateEscalating =
false;
17798 bool IsPotentiallyEvaluated =
17808 SemaRef.
Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
17809 << ND << isa<CXXRecordDecl>(ND) << FD->isConsteval();
17810 if (!FD->getBuiltinID())
17818 if (FD->isImmediateEscalating() && !FD->isConsteval())
17834 (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument ||
17842 D = diag::err_lambda_unevaluated_operand;
17848 D = diag::err_lambda_in_constant_expression;
17849 }
else if (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument) {
17852 D = diag::err_lambda_in_invalid_context;
17854 llvm_unreachable(
"Couldn't infer lambda error message.");
17856 for (
const auto *L : Rec.
Lambdas)
17857 Diag(L->getBeginLoc(),
D);
17877 Diag(BO->getBeginLoc(), diag::warn_deprecated_simple_assign_volatile)
17950 llvm_unreachable(
"Invalid context");
17959 if (!TT.isOSWindows() || !TT.isX86())
17997 : FD(FD), Param(Param) {}
18004 CCName =
"stdcall";
18007 CCName =
"fastcall";
18010 CCName =
"vectorcall";
18013 llvm_unreachable(
"CC does not need mangling");
18016 S.
Diag(
Loc, diag::err_cconv_incomplete_param_type)
18022 ParamIncompleteTypeDiagnoser Diagnoser(FD, Param);
18028enum class OdrUseContext {
18050 return OdrUseContext::None;
18055 Result = OdrUseContext::Used;
18059 Result = OdrUseContext::FormallyOdrUsed;
18065 Result = OdrUseContext::FormallyOdrUsed;
18070 return OdrUseContext::Dependent;
18076 if (!
Func->isConstexpr())
18079 if (
Func->isImplicitlyInstantiable() || !
Func->isUserProvided())
18081 auto *CCD = dyn_cast<CXXConstructorDecl>(
Func);
18082 return CCD && CCD->getInheritedConstructor();
18086 bool MightBeOdrUse) {
18087 assert(
Func &&
"No function?");
18089 Func->setReferenced();
18102 OdrUseContext OdrUse =
18104 if (IsRecursiveCall && OdrUse == OdrUseContext::Used)
18105 OdrUse = OdrUseContext::FormallyOdrUsed;
18109 if (
Func->isTrivial() && !
Func->hasAttr<DLLExportAttr>() &&
18110 OdrUse == OdrUseContext::Used) {
18111 if (
auto *Constructor = dyn_cast<CXXConstructorDecl>(
Func))
18112 if (Constructor->isDefaultConstructor())
18113 OdrUse = OdrUseContext::FormallyOdrUsed;
18114 if (isa<CXXDestructorDecl>(
Func))
18115 OdrUse = OdrUseContext::FormallyOdrUsed;
18122 bool NeededForConstantEvaluation =
18147 bool NeedDefinition =
18148 !IsRecursiveCall &&
18149 (OdrUse == OdrUseContext::Used ||
18150 (NeededForConstantEvaluation && !
Func->isPureVirtual()));
18157 if (NeedDefinition &&
18159 Func->getMemberSpecializationInfo()))
18166 if (NeedDefinition && !
Func->getBody()) {
18169 dyn_cast<CXXConstructorDecl>(
Func)) {
18170 Constructor = cast<CXXConstructorDecl>(Constructor->getFirstDecl());
18171 if (Constructor->isDefaulted() && !Constructor->isDeleted()) {
18172 if (Constructor->isDefaultConstructor()) {
18173 if (Constructor->isTrivial() &&
18174 !Constructor->hasAttr<DLLExportAttr>())
18177 }
else if (Constructor->isCopyConstructor()) {
18179 }
else if (Constructor->isMoveConstructor()) {
18182 }
else if (Constructor->getInheritedConstructor()) {
18186 dyn_cast<CXXDestructorDecl>(
Func)) {
18196 if (MethodDecl->isOverloadedOperator() &&
18197 MethodDecl->getOverloadedOperator() == OO_Equal) {
18198 MethodDecl = cast<CXXMethodDecl>(MethodDecl->getFirstDecl());
18199 if (MethodDecl->isDefaulted() && !MethodDecl->isDeleted()) {
18200 if (MethodDecl->isCopyAssignmentOperator())
18202 else if (MethodDecl->isMoveAssignmentOperator())
18205 }
else if (isa<CXXConversionDecl>(MethodDecl) &&
18206 MethodDecl->getParent()->isLambda()) {
18208 cast<CXXConversionDecl>(MethodDecl->getFirstDecl());
18213 }
else if (MethodDecl->isVirtual() &&
getLangOpts().AppleKext)
18217 if (
Func->isDefaulted() && !
Func->isDeleted()) {
18225 if (
Func->isImplicitlyInstantiable()) {
18227 Func->getTemplateSpecializationKindForInstantiation();
18229 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
18230 if (FirstInstantiation) {
18231 PointOfInstantiation =
Loc;
18232 if (
auto *MSI =
Func->getMemberSpecializationInfo())
18233 MSI->setPointOfInstantiation(
Loc);
18236 Func->setTemplateSpecializationKind(TSK, PointOfInstantiation);
18241 PointOfInstantiation =
Loc;
18245 Func->isConstexpr()) {
18246 if (isa<CXXRecordDecl>(
Func->getDeclContext()) &&
18247 cast<CXXRecordDecl>(
Func->getDeclContext())->isLocalClass() &&
18250 std::make_pair(
Func, PointOfInstantiation));
18251 else if (
Func->isConstexpr())
18257 Func->setInstantiationIsPending(
true);
18259 std::make_pair(
Func, PointOfInstantiation));
18260 if (llvm::isTimeTraceVerbose()) {
18261 llvm::timeTraceAddInstantEvent(
"DeferInstantiation", [&] {
18263 llvm::raw_string_ostream
OS(Name);
18275 for (
auto *i :
Func->redecls()) {
18276 if (!i->isUsed(
false) && i->isImplicitlyInstantiable())
18289 Constructor->isImmediateFunction()
18294 if (
Init->isInClassMemberInitializer())
18296 MarkDeclarationsReferencedInExpr(Init->getInit());
18317 if (
LangOpts.OffloadImplicitHostDeviceTemplates &&
LangOpts.CUDAIsDevice &&
18322 if (OdrUse == OdrUseContext::Used && !
Func->isUsed(
false)) {
18324 if (!
Func->isDefined()) {
18325 if (mightHaveNonExternalLinkage(
Func))
18327 else if (
Func->getMostRecentDecl()->isInlined() &&
18329 !
Func->getMostRecentDecl()->hasAttr<GNUInlineAttr>())
18348 if (
auto *Dtor = dyn_cast<CXXDestructorDecl>(
Func)) {
18350 if (
Parent->getNumVBases() > 0 && !Dtor->getBody())
18368 const unsigned *
const FunctionScopeIndexToStopAt =
nullptr) {
18371 VarDecl *Var =
V->getPotentiallyDecomposedVarDecl();
18372 assert(Var &&
"expected a capturable variable");
18382 QualType CaptureType, DeclRefType;
18388 DeclRefType, FunctionScopeIndexToStopAt);
18404 << llvm::to_underlying(UserTarget);
18407 ? diag::note_cuda_const_var_unpromoted
18408 : diag::note_cuda_host_var);
18411 !Var->
hasAttr<CUDASharedAttr>() &&
18427 (!FD || (!FD->getDescribedFunctionTemplate() &&
18439 unsigned CapturingScopeIndex) {
18450 if (isa<ParmVarDecl>(var) &&
18451 isa<TranslationUnitDecl>(VarDC))
18464 unsigned ValueKind = isa<BindingDecl>(var) ? 1 : 0;
18465 unsigned ContextKind = 3;
18466 if (isa<CXXMethodDecl>(VarDC) &&
18467 cast<CXXRecordDecl>(VarDC->
getParent())->isLambda()) {
18469 }
else if (isa<FunctionDecl>(VarDC)) {
18471 }
else if (isa<BlockDecl>(VarDC)) {
18475 S.
Diag(loc, diag::err_reference_to_local_in_enclosing_context)
18476 << var << ValueKind << ContextKind << VarDC;
18477 S.
Diag(var->getLocation(), diag::note_entity_declared_at)
18486 bool &SubCapturesAreNested,
18492 SubCapturesAreNested =
true;
18509 !(isa<LambdaScopeInfo>(CSI) &&
18510 !cast<LambdaScopeInfo>(CSI)->lambdaCaptureShouldBeConst()) &&
18511 !(isa<CapturedRegionScopeInfo>(CSI) &&
18512 cast<CapturedRegionScopeInfo>(CSI)->CapRegionKind ==
CR_OpenMP))
18544 assert((isa<VarDecl, BindingDecl>(Var)) &&
18545 "Only variables and structured bindings can be captured");
18547 bool IsBlock = isa<BlockScopeInfo>(CSI);
18548 bool IsLambda = isa<LambdaScopeInfo>(CSI);
18556 S.
Diag(
Loc, diag::err_lambda_capture_anonymous_var);
18565 S.
Diag(
Loc, diag::err_ref_vm_type);
18573 if (VTTy->getDecl()->hasFlexibleArrayMember()) {
18576 S.
Diag(
Loc, diag::err_ref_flexarray_type);
18578 S.
Diag(
Loc, diag::err_lambda_capture_flexarray_type) << Var;
18584 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
18587 if (HasBlocksAttr && (IsLambda || isa<CapturedRegionScopeInfo>(CSI))) {
18589 S.
Diag(
Loc, diag::err_capture_block_variable) << Var << !IsLambda;
18598 S.
Diag(
Loc, diag::err_opencl_block_ref_block);
18602 if (isa<BindingDecl>(Var)) {
18609 ? diag::warn_cxx17_compat_capture_binding
18610 : diag::ext_capture_binding)
18624 bool ByRef =
false;
18630 if (BuildAndDiagnose) {
18631 S.
Diag(
Loc, diag::err_ref_array_type);
18642 if (BuildAndDiagnose) {
18643 S.
Diag(
Loc, diag::err_arc_autoreleasing_capture)
18659 if (BuildAndDiagnose) {
18661 S.
Diag(
Loc, diag::warn_block_capture_autoreleasing);
18662 S.
Diag(VarLoc, diag::note_declare_parameter_strong);
18667 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
18676 DeclRefType = CaptureType;
18680 if (BuildAndDiagnose)
18690 const bool BuildAndDiagnose,
QualType &CaptureType,
QualType &DeclRefType,
18717 CaptureType = DeclRefType;
18720 if (BuildAndDiagnose)
18721 RSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
18731 const bool RefersToCapturedVariable,
18736 bool ByRef =
false;
18740 ByRef = (LSI->
ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
18745 S.
Diag(
Loc, diag::err_wasm_ca_reference) << 0;
18776 if (!RefType->getPointeeType()->isFunctionType())
18783 if (BuildAndDiagnose) {
18784 S.
Diag(
Loc, diag::err_arc_autoreleasing_capture) << 1;
18794 if (!
Invalid && BuildAndDiagnose) {
18798 diag::err_capture_of_incomplete_or_sizeless_type,
18802 diag::err_capture_of_abstract_type))
18828 if (BuildAndDiagnose)
18829 LSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
18841 if (
T.isTriviallyCopyableType(
Context))
18845 if (!(RD = RD->getDefinition()))
18847 if (RD->hasSimpleCopyConstructor())
18849 if (RD->hasUserDeclaredCopyConstructor())
18851 if (Ctor->isCopyConstructor())
18852 return !Ctor->isDeleted();
18872 if (ShouldOfferCopyFix) {
18876 FixBuffer.assign({Separator, Var->
getName()});
18877 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
18882 FixBuffer.assign({Separator,
"&", Var->
getName()});
18883 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
18895 return !C.isThisCapture() && !C.isInitCapture();
18904 if (ShouldOfferCopyFix) {
18905 bool CanDefaultCopyCapture =
true;
18914 if (CanDefaultCopyCapture && llvm::none_of(LSI->
Captures, [](
Capture &
C) {
18915 return !C.isThisCapture() && !C.isInitCapture() && C.isCopyCapture();
18917 FixBuffer.assign({
"=", Separator});
18918 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
18927 return !C.isInitCapture() && C.isReferenceCapture() &&
18928 !C.isThisCapture();
18930 FixBuffer.assign({
"&", Separator});
18931 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
18940 QualType &DeclRefType,
const unsigned *
const FunctionScopeIndexToStopAt) {
18963 const auto *VD = dyn_cast<VarDecl>(Var);
18965 if (VD->isInitCapture())
18970 assert(VD &&
"Cannot capture a null variable");
18972 const unsigned MaxFunctionScopesIndex = FunctionScopeIndexToStopAt
18976 if (FunctionScopeIndexToStopAt) {
18977 assert(!
FunctionScopes.empty() &&
"No function scopes to stop at?");
18982 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(
FunctionScopes[FSIndex]);
18983 FSIndex && LSI && !LSI->AfterParameterList)
18985 assert(MaxFunctionScopesIndex <= FSIndex &&
18986 "FunctionScopeIndexToStopAt should be no greater than FSIndex into "
18987 "FunctionScopes.");
18988 while (FSIndex != MaxFunctionScopesIndex) {
18996 bool IsGlobal = !VD->hasLocalStorage();
18997 if (IsGlobal && !(
LangOpts.OpenMP &&
18998 OpenMP().isOpenMPCapturedDecl(Var,
true,
18999 MaxFunctionScopesIndex)))
19002 if (isa<VarDecl>(Var))
19013 CaptureType = Var->
getType();
19015 bool Nested =
false;
19017 unsigned FunctionScopesIndex = MaxFunctionScopesIndex;
19022 LSI = dyn_cast_or_null<LambdaScopeInfo>(
19025 bool IsInScopeDeclarationContext =
19036 if (IsInScopeDeclarationContext &&
19037 FunctionScopesIndex == MaxFunctionScopesIndex && VarDC == DC)
19043 !IsInScopeDeclarationContext
19046 BuildAndDiagnose, *
this);
19052 FunctionScopesIndex = MaxFunctionScopesIndex - 1;
19071 if (
const auto *Parm = dyn_cast<ParmVarDecl>(Var);
19072 Parm && Parm->getDeclContext() == DC)
19080 if (BuildAndDiagnose) {
19083 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19098 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19099 QTy = PVD->getOriginalType();
19104 if (
auto *RSI = dyn_cast<CapturedRegionScopeInfo>(CSI)) {
19110 if (isa<BindingDecl>(Var)) {
19111 if (BuildAndDiagnose) {
19112 Diag(ExprLoc, diag::err_capture_binding_openmp) << Var;
19118 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
19123 if (IsOpenMPPrivateDecl != OMPC_unknown &&
19126 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19127 QTy = PVD->getOriginalType();
19129 E =
OpenMP().getNumberOfConstructScopes(RSI->OpenMPLevel);
19131 auto *OuterRSI = cast<CapturedRegionScopeInfo>(
19133 assert(RSI->OpenMPLevel == OuterRSI->OpenMPLevel &&
19134 "Wrong number of captured regions associated with the "
19135 "OpenMP construct.");
19140 IsOpenMPPrivateDecl != OMPC_private &&
19142 RSI->OpenMPCaptureLevel);
19146 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
19152 OpenMP().adjustOpenMPTargetScopeIndex(FunctionScopesIndex,
19155 if (IsTargetCap || IsOpenMPPrivateDecl == OMPC_private ||
19156 (IsGlobal && !IsGlobalCap)) {
19157 Nested = !IsTargetCap;
19172 if (BuildAndDiagnose) {
19173 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19175 auto *LSI = cast<LambdaScopeInfo>(CSI);
19195 FunctionScopesIndex--;
19196 if (IsInScopeDeclarationContext)
19198 }
while (!VarDC->
Equals(DC));
19206 for (
unsigned I = ++FunctionScopesIndex, N = MaxFunctionScopesIndex + 1; I != N;
19219 if (
Invalid && !BuildAndDiagnose)
19224 DeclRefType, Nested, *
this,
Invalid);
19228 RSI, Var, ExprLoc, BuildAndDiagnose, CaptureType, DeclRefType, Nested,
19229 Kind, I == N - 1, *
this,
Invalid);
19235 DeclRefType, Nested, Kind, EllipsisLoc,
19240 if (
Invalid && !BuildAndDiagnose)
19252 DeclRefType,
nullptr);
19259 false, CaptureType,
19260 DeclRefType,
nullptr);
19264 assert(Var &&
"Null value cannot be captured");
19271 false, CaptureType,
19272 DeclRefType,
nullptr))
19275 return DeclRefType;
19283class CopiedTemplateArgs {
19287 template<
typename RefExpr>
19288 CopiedTemplateArgs(RefExpr *
E) : HasArgs(
E->hasExplicitTemplateArgs()) {
19290 E->copyTemplateArgumentsInto(TemplateArgStorage);
19293#ifdef __has_cpp_attribute
19294#
if __has_cpp_attribute(clang::lifetimebound)
19295 [[clang::lifetimebound]]
19299 return HasArgs ? &TemplateArgStorage :
nullptr;
19325 auto Rebuild = [&](
Expr *Sub) {
19330 auto IsPotentialResultOdrUsed = [&](
NamedDecl *
D) {
19333 auto *VD = dyn_cast<VarDecl>(
D);
19356 llvm_unreachable(
"unexpected non-odr-use-reason");
19360 if (VD->getType()->isReferenceType())
19362 if (
auto *RD = VD->getType()->getAsCXXRecordDecl())
19363 if (RD->hasDefinition() && RD->hasMutableFields())
19365 if (!VD->isUsableInConstantExpressions(S.
Context))
19370 if (VD->getType()->isReferenceType())
19378 auto MarkNotOdrUsed = [&] {
19381 LSI->markVariableExprAsNonODRUsed(
E);
19388 case Expr::DeclRefExprClass: {
19389 auto *DRE = cast<DeclRefExpr>(
E);
19390 if (DRE->isNonOdrUse() || IsPotentialResultOdrUsed(DRE->getDecl()))
19396 S.
Context, DRE->getQualifierLoc(), DRE->getTemplateKeywordLoc(),
19397 DRE->getDecl(), DRE->refersToEnclosingVariableOrCapture(),
19398 DRE->getNameInfo(), DRE->getType(), DRE->getValueKind(),
19399 DRE->getFoundDecl(), CopiedTemplateArgs(DRE), NOUR);
19402 case Expr::FunctionParmPackExprClass: {
19403 auto *FPPE = cast<FunctionParmPackExpr>(
E);
19407 if (IsPotentialResultOdrUsed(
D))
19418 case Expr::ArraySubscriptExprClass: {
19419 auto *ASE = cast<ArraySubscriptExpr>(
E);
19424 if (!
Base.isUsable())
19426 Expr *LHS = ASE->getBase() == ASE->getLHS() ?
Base.get() : ASE->getLHS();
19427 Expr *RHS = ASE->getBase() == ASE->getRHS() ?
Base.get() : ASE->getRHS();
19430 ASE->getRBracketLoc());
19433 case Expr::MemberExprClass: {
19434 auto *ME = cast<MemberExpr>(
E);
19437 if (isa<FieldDecl>(ME->getMemberDecl())) {
19439 if (!
Base.isUsable())
19442 S.
Context,
Base.get(), ME->isArrow(), ME->getOperatorLoc(),
19443 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(),
19444 ME->getMemberDecl(), ME->getFoundDecl(), ME->getMemberNameInfo(),
19445 CopiedTemplateArgs(ME), ME->getType(), ME->getValueKind(),
19446 ME->getObjectKind(), ME->isNonOdrUse());
19449 if (ME->getMemberDecl()->isCXXInstanceMember())
19454 if (ME->isNonOdrUse() || IsPotentialResultOdrUsed(ME->getMemberDecl()))
19460 S.
Context, ME->getBase(), ME->isArrow(), ME->getOperatorLoc(),
19461 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(), ME->getMemberDecl(),
19462 ME->getFoundDecl(), ME->getMemberNameInfo(), CopiedTemplateArgs(ME),
19463 ME->getType(), ME->getValueKind(), ME->getObjectKind(), NOUR);
19466 case Expr::BinaryOperatorClass: {
19467 auto *BO = cast<BinaryOperator>(
E);
19468 Expr *LHS = BO->getLHS();
19469 Expr *RHS = BO->getRHS();
19471 if (BO->getOpcode() == BO_PtrMemD) {
19473 if (!Sub.isUsable())
19475 BO->setLHS(Sub.get());
19477 }
else if (BO->getOpcode() == BO_Comma) {
19479 if (!Sub.isUsable())
19481 BO->setRHS(Sub.get());
19489 case Expr::ParenExprClass: {
19490 auto *PE = cast<ParenExpr>(
E);
19492 if (!Sub.isUsable())
19494 return S.
ActOnParenExpr(PE->getLParen(), PE->getRParen(), Sub.get());
19499 case Expr::ConditionalOperatorClass: {
19500 auto *CO = cast<ConditionalOperator>(
E);
19510 LHS = CO->getLHS();
19512 RHS = CO->getRHS();
19514 CO->getCond(), LHS.
get(), RHS.
get());
19519 case Expr::UnaryOperatorClass: {
19520 auto *UO = cast<UnaryOperator>(
E);
19521 if (UO->getOpcode() != UO_Extension)
19524 if (!Sub.isUsable())
19526 return S.
BuildUnaryOp(
nullptr, UO->getOperatorLoc(), UO_Extension,
19533 case Expr::GenericSelectionExprClass: {
19534 auto *GSE = cast<GenericSelectionExpr>(
E);
19537 bool AnyChanged =
false;
19538 for (
Expr *OrigAssocExpr : GSE->getAssocExprs()) {
19539 ExprResult AssocExpr = Rebuild(OrigAssocExpr);
19543 AssocExprs.push_back(AssocExpr.
get());
19546 AssocExprs.push_back(OrigAssocExpr);
19550 void *ExOrTy =
nullptr;
19551 bool IsExpr = GSE->isExprPredicate();
19553 ExOrTy = GSE->getControllingExpr();
19555 ExOrTy = GSE->getControllingType();
19557 GSE->getGenericLoc(), GSE->getDefaultLoc(),
19558 GSE->getRParenLoc(), IsExpr, ExOrTy,
19559 GSE->getAssocTypeSourceInfos(), AssocExprs)
19567 case Expr::ChooseExprClass: {
19568 auto *CE = cast<ChooseExpr>(
E);
19578 if (!LHS.
get() && !RHS.
get())
19581 LHS = CE->getLHS();
19583 RHS = CE->getRHS();
19586 RHS.
get(), CE->getRParenLoc());
19590 case Expr::ConstantExprClass: {
19591 auto *CE = cast<ConstantExpr>(
E);
19593 if (!Sub.isUsable())
19600 case Expr::ImplicitCastExprClass: {
19601 auto *ICE = cast<ImplicitCastExpr>(
E);
19605 switch (ICE->getCastKind()) {
19607 case CK_DerivedToBase:
19608 case CK_UncheckedDerivedToBase: {
19609 ExprResult Sub = Rebuild(ICE->getSubExpr());
19610 if (!Sub.isUsable())
19614 ICE->getValueKind(), &
Path);
19673 for (
Expr *
E : LocalMaybeODRUseExprs) {
19674 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E)) {
19676 DRE->getLocation(), *
this);
19677 }
else if (
auto *ME = dyn_cast<MemberExpr>(
E)) {
19680 }
else if (
auto *FP = dyn_cast<FunctionParmPackExpr>(
E)) {
19684 llvm_unreachable(
"Unexpected expression");
19689 "MarkVarDeclODRUsed failed to cleanup MaybeODRUseExprs?");
19698 const bool RefersToEnclosingScope =
19701 if (RefersToEnclosingScope) {
19716 assert(
E &&
"Capture variable should be used in an expression.");
19727 assert((!
E || isa<DeclRefExpr>(
E) || isa<MemberExpr>(
E) ||
19728 isa<FunctionParmPackExpr>(
E)) &&
19729 "Invalid Expr argument to DoMarkVarDeclReferenced");
19740 bool UsableInConstantExpr =
19752 bool NeededForConstantEvaluation =
19755 bool NeedDefinition =
19756 OdrUse == OdrUseContext::Used || NeededForConstantEvaluation;
19758 assert(!isa<VarTemplatePartialSpecializationDecl>(Var) &&
19759 "Can't instantiate a partial template specialization.");
19765 !isa<VarTemplateSpecializationDecl>(Var))
19776 bool TryInstantiating =
19780 if (TryInstantiating) {
19783 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
19784 if (FirstInstantiation) {
19785 PointOfInstantiation =
Loc;
19787 MSI->setPointOfInstantiation(PointOfInstantiation);
19793 if (UsableInConstantExpr) {
19802 if (
auto *DRE = dyn_cast_or_null<DeclRefExpr>(
E))
19803 DRE->setDecl(DRE->getDecl());
19804 else if (
auto *ME = dyn_cast_or_null<MemberExpr>(
E))
19805 ME->setMemberDecl(ME->getMemberDecl());
19806 }
else if (FirstInstantiation) {
19808 .push_back(std::make_pair(Var, PointOfInstantiation));
19810 bool Inserted =
false;
19812 auto Iter = llvm::find_if(
19814 return P.first == Var;
19816 if (
Iter != I.end()) {
19829 if (isa<VarTemplateSpecializationDecl>(Var) && !Inserted)
19831 .push_back(std::make_pair(Var, PointOfInstantiation));
19855 if (
DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(
E))
19856 if (DRE->isNonOdrUse())
19858 if (
MemberExpr *ME = dyn_cast_or_null<MemberExpr>(
E))
19859 if (ME->isNonOdrUse())
19863 case OdrUseContext::None:
19866 assert((!
E || isa<FunctionParmPackExpr>(
E) ||
19868 "missing non-odr-use marking for unevaluated decl ref");
19871 case OdrUseContext::FormallyOdrUsed:
19876 case OdrUseContext::Used:
19885 case OdrUseContext::Dependent:
19903 if (OdrUse == OdrUseContext::Used) {
19904 QualType CaptureType, DeclRefType;
19910 }
else if (OdrUse == OdrUseContext::Dependent) {
19926 auto *ID = dyn_cast<DeclRefExpr>(
E);
19927 if (!ID || ID->isTypeDependent() || !ID->refersToEnclosingVariableOrCapture())
19934 auto IsDependent = [&]() {
19936 auto *LSI = dyn_cast<sema::LambdaScopeInfo>(
Scope);
19941 LSI->AfterParameterList)
19944 const auto *MD = LSI->CallOperator;
19945 if (MD->getType().isNull())
19949 if (!Ty || !MD->isExplicitObjectMemberFunction() ||
19953 if (
auto *
C = LSI->CaptureMap.count(
D) ? &LSI->getCapture(
D) :
nullptr) {
19954 if (
C->isCopyCapture())
19959 if (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByval)
19965 ID->setCapturedByCopyInLambdaWithExplicitObjectParameter(
19971 bool MightBeOdrUse,
19976 if (
VarDecl *Var = dyn_cast<VarDecl>(
D)) {
20002 bool IsVirtualCall = MD->
isVirtual() &&
20004 if (!IsVirtualCall)
20019 bool OdrUse =
true;
20020 if (
const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(
E->getDecl()))
20021 if (Method->isVirtual() &&
20025 if (
auto *FD = dyn_cast<FunctionDecl>(
E->getDecl())) {
20030 !FD->isDependentContext())
20044 bool MightBeOdrUse =
true;
20046 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(
E->getMemberDecl()))
20047 if (Method->isPureVirtual())
20048 MightBeOdrUse =
false;
20051 E->getMemberLoc().isValid() ?
E->getMemberLoc() :
E->
getBeginLoc();
20067 bool MightBeOdrUse) {
20068 if (MightBeOdrUse) {
20069 if (
auto *VD = dyn_cast<VarDecl>(
D)) {
20074 if (
auto *FD = dyn_cast<FunctionDecl>(
D)) {
20100bool MarkReferencedDecls::TraverseTemplateArgument(
20118 MarkReferencedDecls Marker(*
this,
Loc);
20119 Marker.TraverseType(
T);
20125class EvaluatedExprMarker :
public UsedDeclVisitor<EvaluatedExprMarker> {
20128 bool SkipLocalVariables;
20131 EvaluatedExprMarker(
Sema &S,
bool SkipLocalVariables,
20133 : Inherited(S), SkipLocalVariables(SkipLocalVariables), StopAt(StopAt) {}
20139 void Visit(
Expr *
E) {
20140 if (llvm::is_contained(StopAt,
E))
20142 Inherited::Visit(
E);
20152 if (SkipLocalVariables) {
20153 if (
VarDecl *VD = dyn_cast<VarDecl>(
E->getDecl()))
20154 if (VD->hasLocalStorage())
20166 Visit(
E->getBase());
20172 bool SkipLocalVariables,
20174 EvaluatedExprMarker(*
this, SkipLocalVariables, StopAt).Visit(
E);
20196 if (
auto *VD = dyn_cast_or_null<VarDecl>(
20198 if (VD->isConstexpr() ||
20199 (VD->isStaticDataMember() && VD->isFirstDecl() && !VD->isInline()))
20272 class CallReturnIncompleteDiagnoser :
public TypeDiagnoser {
20278 : FD(FD), CE(CE) { }
20282 S.
Diag(
Loc, diag::err_call_incomplete_return)
20287 S.
Diag(
Loc, diag::err_call_function_incomplete_return)
20292 } Diagnoser(FD, CE);
20305 unsigned diagnostic = diag::warn_condition_is_assignment;
20306 bool IsOrAssign =
false;
20309 if (Op->getOpcode() != BO_Assign && Op->getOpcode() != BO_OrAssign)
20312 IsOrAssign = Op->getOpcode() == BO_OrAssign;
20320 if (
ObjC().isSelfExpr(Op->getLHS()) && ME->getMethodFamily() ==
OMF_init)
20321 diagnostic = diag::warn_condition_is_idiomatic_assignment;
20325 diagnostic = diag::warn_condition_is_idiomatic_assignment;
20328 Loc = Op->getOperatorLoc();
20330 if (Op->getOperator() != OO_Equal && Op->getOperator() != OO_PipeEqual)
20333 IsOrAssign = Op->getOperator() == OO_PipeEqual;
20334 Loc = Op->getOperatorLoc();
20346 Diag(
Loc, diag::note_condition_assign_silence)
20351 Diag(
Loc, diag::note_condition_or_assign_to_comparison)
20354 Diag(
Loc, diag::note_condition_assign_to_comparison)
20372 if (opE->getOpcode() == BO_EQ &&
20373 opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(
Context)
20379 Diag(
Loc, diag::note_equality_comparison_silence)
20382 Diag(
Loc, diag::note_equality_comparison_to_assign)
20388 bool IsConstexpr) {
20390 if (
ParenExpr *parenE = dyn_cast<ParenExpr>(
E))
20408 Diag(
Loc, diag::err_typecheck_statement_requires_scalar)
20412 CheckBoolLikeConversion(
E,
Loc);
20458 struct RebuildUnknownAnyFunction
20459 :
StmtVisitor<RebuildUnknownAnyFunction, ExprResult> {
20463 RebuildUnknownAnyFunction(
Sema &S) : S(S) {}
20466 llvm_unreachable(
"unexpected statement!");
20477 template <
class T>
ExprResult rebuildSugarExpr(
T *
E) {
20481 Expr *SubExpr = SubResult.
get();
20482 E->setSubExpr(SubExpr);
20490 return rebuildSugarExpr(
E);
20494 return rebuildSugarExpr(
E);
20501 Expr *SubExpr = SubResult.
get();
20502 E->setSubExpr(SubExpr);
20510 if (!isa<FunctionDecl>(VD))
return VisitExpr(
E);
20516 !(isa<CXXMethodDecl>(VD) &&
20517 cast<CXXMethodDecl>(VD)->isInstance()))
20524 return resolveDecl(
E,
E->getMemberDecl());
20528 return resolveDecl(
E,
E->getDecl());
20546 struct RebuildUnknownAnyExpr
20547 :
StmtVisitor<RebuildUnknownAnyExpr, ExprResult> {
20558 llvm_unreachable(
"unexpected statement!");
20572 template <
class T>
ExprResult rebuildSugarExpr(
T *
E) {
20575 Expr *SubExpr = SubResult.
get();
20576 E->setSubExpr(SubExpr);
20584 return rebuildSugarExpr(
E);
20588 return rebuildSugarExpr(
E);
20594 S.
Diag(
E->getOperatorLoc(), diag::err_unknown_any_addrof)
20599 if (isa<CallExpr>(
E->getSubExpr())) {
20600 S.
Diag(
E->getOperatorLoc(), diag::err_unknown_any_addrof_call)
20613 E->setSubExpr(SubResult.
get());
20622 return resolveDecl(
E,
E->getMemberDecl());
20626 return resolveDecl(
E,
E->getDecl());
20633 Expr *CalleeExpr =
E->getCallee();
20637 FK_FunctionPointer,
20644 assert(isa<CXXMemberCallExpr>(
E) || isa<CXXOperatorCallExpr>(
E));
20645 Kind = FK_MemberFunction;
20649 Kind = FK_FunctionPointer;
20652 Kind = FK_BlockPointer;
20658 unsigned diagID = diag::err_func_returning_array_function;
20659 if (Kind == FK_BlockPointer)
20660 diagID = diag::err_block_returning_array_function;
20696 if (ParamTypes.empty() && Proto->
isVariadic()) {
20697 ArgTypes.reserve(
E->getNumArgs());
20698 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; ++i) {
20701 ParamTypes = ArgTypes;
20712 case FK_MemberFunction:
20716 case FK_FunctionPointer:
20720 case FK_BlockPointer:
20726 ExprResult CalleeResult = Visit(CalleeExpr);
20728 E->setCallee(CalleeResult.
get());
20745 Method->setReturnType(DestType);
20757 if (
E->getCastKind() == CK_FunctionToPointerDecay) {
20771 }
else if (
E->getCastKind() == CK_LValueToRValue) {
20775 assert(isa<BlockPointerType>(
E->
getType()));
20788 llvm_unreachable(
"Unhandled cast type!");
20821 if (DRE && Proto && Proto->getParamTypes().empty() && Proto->isVariadic()) {
20825 FD->getNameInfo().getName(), DestType, FD->getTypeSourceInfo(),
20827 false , FD->hasPrototype(),
20830 if (FD->getQualifier())
20834 for (
const auto &AI : FT->param_types()) {
20838 Params.push_back(Param);
20840 NewFD->setParams(Params);
20847 if (MD->isInstance()) {
20857 }
else if (isa<VarDecl>(VD)) {
20887 diag::err_typecheck_cast_to_incomplete))
20902 return RebuildUnknownAnyExpr(*
this, ToType).Visit(
E);
20909 ExplicitCastExpr *castArg = dyn_cast<ExplicitCastExpr>(arg->IgnoreParens());
20918 assert(!arg->hasPlaceholderType());
20930 unsigned diagID = diag::err_uncasted_use_of_unknown_any;
20933 if (
CallExpr *call = dyn_cast<CallExpr>(
E)) {
20934 E = call->getCallee();
20935 diagID = diag::err_uncasted_call_of_unknown_any;
20944 loc = ref->getLocation();
20945 d = ref->getDecl();
20946 }
else if (
MemberExpr *mem = dyn_cast<MemberExpr>(
E)) {
20947 loc = mem->getMemberLoc();
20948 d = mem->getMemberDecl();
20950 diagID = diag::err_uncasted_call_of_unknown_any;
20951 loc = msg->getSelectorStartLoc();
20952 d = msg->getMethodDecl();
20954 S.
Diag(loc, diag::err_uncasted_send_to_unknown_any_method)
20955 <<
static_cast<unsigned>(msg->isClassMessage()) << msg->getSelector()
20982 if (!placeholderType)
return E;
20984 switch (placeholderType->
getKind()) {
20985 case BuiltinType::UnresolvedTemplate: {
20986 auto *ULE = cast<UnresolvedLookupExpr>(
E);
20991 const bool IsTypeAliasTemplateDecl = isa<TypeAliasTemplateDecl>(Temp);
20994 Diag(NameInfo.
getLoc(), diag::err_template_kw_refers_to_type_template)
20996 <<
Loc.getSourceRange() << IsTypeAliasTemplateDecl;
20998 Diag(NameInfo.
getLoc(), diag::err_template_kw_refers_to_type_template)
21000 << IsTypeAliasTemplateDecl;
21002 << IsTypeAliasTemplateDecl;
21008 case BuiltinType::Overload: {
21028 case BuiltinType::BoundMember: {
21033 if (isa<CXXPseudoDestructorExpr>(BME)) {
21034 PD =
PDiag(diag::err_dtor_expr_without_call) << 1;
21035 }
else if (
const auto *ME = dyn_cast<MemberExpr>(BME)) {
21036 if (ME->getMemberNameInfo().getName().getNameKind() ==
21038 PD =
PDiag(diag::err_dtor_expr_without_call) << 0;
21046 case BuiltinType::ARCUnbridgedCast: {
21053 case BuiltinType::UnknownAny:
21057 case BuiltinType::PseudoObject:
21060 case BuiltinType::BuiltinFn: {
21064 auto *FD = cast<FunctionDecl>(DRE->
getDecl());
21065 unsigned BuiltinID = FD->getBuiltinID();
21066 if (BuiltinID == Builtin::BI__noop) {
21068 CK_BuiltinFnToFnPtr)
21081 ? diag::err_use_of_unaddressable_function
21082 : diag::warn_cxx20_compat_use_of_unaddressable_function);
21083 if (FD->isImplicitlyInstantiable()) {
21110 case BuiltinType::IncompleteMatrixIdx:
21114 diag::err_matrix_incomplete_index);
21118 case BuiltinType::ArraySection:
21120 << cast<ArraySectionExpr>(
E)->isOMPArraySection();
21124 case BuiltinType::OMPArrayShaping:
21127 case BuiltinType::OMPIterator:
21131#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
21132 case BuiltinType::Id:
21133#include "clang/Basic/OpenCLImageTypes.def"
21134#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
21135 case BuiltinType::Id:
21136#include "clang/Basic/OpenCLExtensionTypes.def"
21137#define SVE_TYPE(Name, Id, SingletonId) \
21138 case BuiltinType::Id:
21139#include "clang/Basic/AArch64SVEACLETypes.def"
21140#define PPC_VECTOR_TYPE(Name, Id, Size) \
21141 case BuiltinType::Id:
21142#include "clang/Basic/PPCTypes.def"
21143#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
21144#include "clang/Basic/RISCVVTypes.def"
21145#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
21146#include "clang/Basic/WebAssemblyReferenceTypes.def"
21147#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) case BuiltinType::Id:
21148#include "clang/Basic/AMDGPUTypes.def"
21149#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
21150#include "clang/Basic/HLSLIntangibleTypes.def"
21151#define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id:
21152#define PLACEHOLDER_TYPE(Id, SingletonId)
21153#include "clang/AST/BuiltinTypes.def"
21157 llvm_unreachable(
"invalid placeholder type!");
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
static bool isObjCPointer(const MemRegion *R)
Defines enum values for all the target-independent builtin functions.
Defines the C++ template declaration subclasses.
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
Defines the clang::Expr interface and subclasses for C++ expressions.
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 std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file declares semantic analysis for CUDA constructs.
static Sema::AssignConvertType checkObjCPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType)
checkObjCPointerTypesForAssignment - Compares two objective-c pointer types for assignment compatibil...
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 captureInCapturedRegion(CapturedRegionScopeInfo *RSI, ValueDecl *Var, SourceLocation Loc, const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const bool RefersToCapturedVariable, Sema::TryCaptureKind Kind, bool IsTopScope, Sema &S, bool Invalid)
Capture the given variable in the captured region.
static bool checkArithmeticOpPointerOperand(Sema &S, SourceLocation Loc, Expr *Operand)
Check the validity of an arithmetic pointer operand.
static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
DiagnoseBitwisePrecedence - Emit a warning when bitwise and comparison operators are mixed in a way t...
static bool isPlaceholderToRemoveAsArg(QualType type)
Is the given type a placeholder that we need to lower out immediately during argument processing?
static void diagnoseArithmeticOnNullPointer(Sema &S, SourceLocation Loc, Expr *Pointer, bool IsGNUIdiom)
Diagnose invalid arithmetic on a null pointer.
static void DiagnoseConditionalPrecedence(Sema &Self, SourceLocation OpLoc, Expr *Condition, const Expr *LHSExpr, const Expr *RHSExpr)
DiagnoseConditionalPrecedence - Emit a warning when a conditional operator and binary operator are mi...
static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D, bool AcceptInvalid)
Diagnoses obvious problems with the use of the given declaration as an expression.
static 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 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 void DetectPrecisionLossInComplexDivision(Sema &S, SourceLocation OpLoc, Expr *Operand)
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 void FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter(Sema &SemaRef, ValueDecl *D, Expr *E)
static bool isVariableCapturable(CapturingScopeInfo *CSI, ValueDecl *Var, SourceLocation Loc, const bool Diagnose, Sema &S)
static bool maybeDiagnoseAssignmentToFunction(Sema &S, QualType DstType, const Expr *SrcExpr)
static void SuggestParentheses(Sema &Self, SourceLocation Loc, const PartialDiagnostic &Note, SourceRange ParenRange)
SuggestParentheses - Emit a note with a fixit hint that wraps ParenRange in parentheses.
static Decl * getPredefinedExprDecl(DeclContext *DC)
getPredefinedExprDecl - Returns Decl of a given DeclContext that can be used to determine the value o...
static CXXRecordDecl * LookupStdSourceLocationImpl(Sema &S, SourceLocation Loc)
static bool IgnoreCommaOperand(const Expr *E, const ASTContext &Context)
static QualType CheckRealImagOperand(Sema &S, ExprResult &V, SourceLocation Loc, bool IsReal)
static QualType checkArithmeticOrEnumeralCompare(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, BinaryOperatorKind Opc)
static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK, SourceLocation OpLoc, bool IsAfterAmp=false)
CheckIndirectionOperand - Type check unary indirection (prefix '*').
static bool CheckAlignOfExpr(Sema &S, Expr *E, UnaryExprOrTypeTrait ExprKind)
static bool ExprLooksBoolean(const Expr *E)
ExprLooksBoolean - Returns true if E looks boolean, i.e.
static bool isPotentiallyConstantEvaluatedContext(Sema &SemaRef)
Are we in a context that is potentially constant evaluated per C++20 [expr.const]p12?
static void DiagnoseSelfAssignment(Sema &S, Expr *LHSExpr, Expr *RHSExpr, SourceLocation OpLoc, bool IsBuiltin)
DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
static void diagnoseStringPlusInt(Sema &Self, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
diagnoseStringPlusInt - Emit a warning when adding an integer to a string literal.
static QualType checkConditionalPointerCompatibility(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
Checks compatibility between two pointers and return the resulting type.
static void DoMarkVarDeclReferenced(Sema &SemaRef, SourceLocation Loc, VarDecl *Var, Expr *E, llvm::DenseMap< const VarDecl *, int > &RefsMinusAssignments)
static bool ShouldLookupResultBeMultiVersionOverload(const LookupResult &R)
static bool checkCondition(Sema &S, const Expr *Cond, SourceLocation QuestionLoc)
Return false if the condition expression is valid, true otherwise.
static bool checkForArray(const Expr *E)
static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, const CallExpr *Call)
static void DiagnoseRecursiveConstFields(Sema &S, const ValueDecl *VD, const RecordType *Ty, SourceLocation Loc, SourceRange Range, OriginalExprKind OEK, bool &DiagnosticEmitted)
static void MarkExprReferenced(Sema &SemaRef, SourceLocation Loc, Decl *D, Expr *E, bool MightBeOdrUse, llvm::DenseMap< const VarDecl *, int > &RefsMinusAssignments)
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 NamedDecl * getDeclFromExpr(Expr *E)
static bool checkArithmeticOnObjCPointer(Sema &S, SourceLocation opLoc, Expr *op)
Diagnose if arithmetic on the given ObjC pointer is illegal.
static bool IsInvalidCmseNSCallConversion(Sema &S, QualType FromType, QualType ToType)
static void RemoveNestedImmediateInvocation(Sema &SemaRef, Sema::ExpressionEvaluationContextRecord &Rec, SmallVector< Sema::ImmediateInvocationCandidate, 4 >::reverse_iterator It)
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 void emitEmptyLookupTypoDiagnostic(const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS, DeclarationName Typo, SourceLocation TypoLoc, ArrayRef< Expr * > Args, unsigned DiagnosticID, unsigned DiagnosticSuggestID)
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 Sema::AssignConvertType checkBlockPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType)
checkBlockPointerTypesForAssignment - This routine determines whether two block pointer types are com...
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 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 bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var, SourceLocation Loc, const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const bool RefersToCapturedVariable, const Sema::TryCaptureKind Kind, SourceLocation EllipsisLoc, const bool IsTopScope, Sema &S, bool Invalid)
Capture the given variable in the lambda.
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 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 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 void diagnoseUncapturableValueReferenceOrBinding(Sema &S, SourceLocation loc, ValueDecl *var)
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 Sema::AssignConvertType checkPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType, SourceLocation Loc)
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 checkEnumArithmeticConversions(Sema &S, Expr *LHS, Expr *RHS, SourceLocation Loc, Sema::ArithConvKind ACK)
Check that the usual arithmetic conversions can be performed on this pair of expressions that might b...
static void diagnosePointerIncompatibility(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr)
Emit error when two pointers are incompatible.
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 std::pair< ExprResult, ExprResult > CorrectDelayedTyposInBinOp(Sema &S, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
static void checkObjCPointerIntrospection(Sema &S, ExprResult &L, ExprResult &R, SourceLocation OpLoc)
Check if a bitwise-& is performed on an Objective-C pointer.
static void DiagnoseDirectIsaAccess(Sema &S, const ObjCIvarRefExpr *OIRE, SourceLocation AssignLoc, const Expr *RHS)
static ExprResult rebuildUnknownAnyFunction(Sema &S, Expr *fn)
Given a function expression of unknown-any type, try to rebuild it to have a function type.
static QualType handleIntToFloatConversion(Sema &S, ExprResult &FloatExpr, ExprResult &IntExpr, QualType FloatTy, QualType IntTy, bool ConvertFloat, bool ConvertInt)
Handle arithmetic conversion from integer to float.
static bool hasIsEqualMethod(Sema &S, const Expr *LHS, const Expr *RHS)
static QualType handleComplexFloatConversion(Sema &S, ExprResult &Shorter, QualType ShorterType, QualType LongerType, bool PromotePrecision)
static FunctionDecl * rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context, FunctionDecl *FDecl, MultiExprArg ArgExprs)
If a builtin function has a pointer argument with no explicit address space, then it should be able t...
static void DoMarkBindingDeclReferenced(Sema &SemaRef, SourceLocation Loc, BindingDecl *BD, Expr *E)
static PredefinedIdentKind getPredefinedExprKind(tok::TokenKind Kind)
static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc)
static QualType handleFixedPointConversion(Sema &S, QualType LHSTy, QualType RHSTy)
handleFixedPointConversion - Fixed point operations between fixed point types and integers or other f...
static QualType handleComplexConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
Handle arithmetic conversion with complex types.
static QualType CheckCommaOperands(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
static bool canCaptureVariableByCopy(ValueDecl *Var, const ASTContext &Context)
static void diagnoseArithmeticOnTwoVoidPointers(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr)
Diagnose invalid arithmetic on two void pointers.
static void diagnoseDistinctPointerComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, bool IsError)
Diagnose bad pointer comparisons.
static bool needsConversionOfHalfVec(bool OpRequiresConversion, ASTContext &Ctx, Expr *E0, Expr *E1=nullptr)
Returns true if conversion between vectors of halfs and vectors of floats is needed.
static bool isObjCObjectLiteral(ExprResult &E)
static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E)
static QualType checkConditionalBlockPointerCompatibility(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc)
Return the resulting type when the operands are both block pointers.
static void DiagnoseShiftCompare(Sema &S, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr)
static void DiagnoseAdditionInShift(Sema &S, SourceLocation OpLoc, Expr *SubExpr, StringRef Shift)
static void diagnoseFunctionPointerToVoidComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, bool IsError)
static void EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, BinaryOperator *Bop)
It accepts a '&&' expr that is inside a '||' one.
static void captureVariablyModifiedType(ASTContext &Context, QualType T, CapturingScopeInfo *CSI)
static bool canConvertIntToOtherIntTy(Sema &S, ExprResult *Int, QualType OtherIntTy)
Test if a (constant) integer Int can be casted to another integer type IntTy without losing precision...
static DeclContext * getParentOfCapturingContextOrNull(DeclContext *DC, ValueDecl *Var, SourceLocation Loc, const bool Diagnose, Sema &S)
static bool isOverflowingIntegerType(ASTContext &Ctx, QualType T)
static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr, SourceLocation Loc, Sema &Sema)
static bool isLegalBoolVectorBinaryOp(BinaryOperatorKind Opc)
static ExprResult rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E, NonOdrUseReason NOUR)
Walk the set of potential results of an expression and mark them all as non-odr-uses if they satisfy ...
static void CheckCompleteParameterTypesForMangler(Sema &S, FunctionDecl *FD, SourceLocation Loc)
Require that all of the parameter types of function be complete.
static bool isScopedEnumerationType(QualType T)
static bool checkArithmeticBinOpPointerOperands(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr)
Check the validity of a binary arithmetic operation w.r.t.
static bool breakDownVectorType(QualType type, uint64_t &len, QualType &eltType)
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis for expressions involving.
static bool isInvalid(LocType Loc, bool *Invalid)
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
static QualType getPointeeType(const MemRegion *R)
Defines the clang::TypeLoc interface and its subclasses.
Defines enumerations for the type traits support.
C Language Family Type Representation.
@ Open
The standard open() call: int open(const char *path, int oflag, ...);.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D)
Invoked when a function is implicitly instantiated.
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...
TranslationUnitDecl * getTranslationUnitDecl() const
const ConstantArrayType * getAsConstantArrayType(QualType T) const
bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType)
Return true if the given vector types are lax-compatible SVE vector types, false otherwise.
CanQualType ARCUnbridgedCastTy
unsigned getIntWidth(QualType T) const
bool areCompatibleRVVTypes(QualType FirstType, QualType SecondType)
Return true if the given types are an RISC-V vector builtin type and a VectorType that is a fixed-len...
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.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
QualType getBuiltinVaListType() const
Retrieve the type of the __builtin_va_list 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 getRecordType(const RecordDecl *Decl) 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 getBuiltinMSVaListType() const
Retrieve the type of the __builtin_ms_va_list type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getCorrespondingSignedFixedPointType(QualType Ty) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
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.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Builtin::Context & BuiltinInfo
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
bool areLaxCompatibleRVVTypes(QualType FirstType, QualType SecondType)
Return true if the given vector types are lax-compatible RISC-V vector types as defined by -flax-vect...
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.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
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....
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
CanQualType UnsignedLongTy
llvm::DenseSet< const FunctionDecl * > CUDAImplicitHostDeviceFunUsedByDevice
Keep track of CUDA/HIP implicit host device functions used on device side in device compilation.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const
Return a type for a constant array for a string literal of the specified element type and length.
QualType getCorrespondingSaturatedType(QualType Ty) const
CanQualType BoundMemberTy
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
llvm::DenseSet< const VarDecl * > CUDADeviceVarODRUsedByHost
Keep track of CUDA/HIP device-side variables ODR-used by host code.
CanQualType PseudoObjectTy
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
bool areComparableObjCPointerTypes(QualType LHS, QualType RHS)
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
llvm::FixedPointSemantics getFixedPointSemantics(QualType Ty) const
QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, bool Unqualified=false, bool BlockReturnType=false, bool IsConditionalOperator=false)
static bool isObjCNSObjectType(QualType Ty)
Return true if this is an NSObject object with its NSObject attribute set.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
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.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType UnsignedCharTy
CanQualType UnsignedIntTy
TypeSourceInfo * CreateTypeSourceInfo(QualType T, unsigned Size=0) const
Allocate an uninitialized TypeSourceInfo.
QualType getObjCClassRedefinitionType() const
Retrieve the type that Class has been defined to, which may be different from the built-in Class if C...
FieldDecl * getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) const
CanQualType UnsignedLongLongTy
QualType getCommonSugaredType(QualType X, QualType Y, bool Unqualified=false)
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.
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
llvm::APFixedPoint getFixedPointMax(QualType Ty) const
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
bool areCompatibleSveTypes(QualType FirstType, QualType SecondType)
Return true if the given types are an SVE builtin and a VectorType that is a fixed-length representat...
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.
bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec)
Return true if the given vector types are of the same unqualified type or if they are equivalent to t...
DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const
const TargetInfo & getTargetInfo() const
CanQualType IncompleteMatrixIdxTy
std::optional< CharUnits > getTypeSizeInCharsIfKnown(QualType Ty) 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 ...
QualType getCorrespondingSignedType(QualType T) const
unsigned getTargetAddressSpace(LangAS AS) const
QualType getWideCharType() const
Return the type of wide characters.
bool isPromotableIntegerType(QualType T) const
More type predicates useful for type checking/promotion.
CanQualType getSignedSizeType() const
Return the unique signed counterpart of the integer type corresponding to size_t.
QualType getLogicalOperationType() const
The result type of logical operations, '<', '>', '!=', etc.
unsigned char getFixedPointScale(QualType Ty) const
QualType adjustStringLiteralBaseType(QualType StrLTy) const
bool hasCvrSimilarType(QualType T1, QualType T2)
Determine if two types are similar, ignoring only CVR qualifiers.
bool isDependenceAllowed() const
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns) const
Return the unique reference to the matrix type of the specified element type and size.
QualType isPromotableBitField(Expr *E) const
Whether this is a promotable bitfield reference according to C99 6.3.1.1p2, bullet 2 (and GCC extensi...
bool isSentinelNullExpr(const Expr *E)
uint64_t getCharWidth() const
Return the size of the character type, in bits.
QualType getBitIntType(bool Unsigned, unsigned NumBits) const
Return a bit-precise integer type with the specified signedness and bit count.
AddrLabelExpr - The GNU address of label extension, representing &&label.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
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
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
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 OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
static bool isComparisonOp(Opcode Opc)
bool isComparisonOp() const
StringRef getOpcodeStr() const
bool isRelationalOp() const
SourceLocation getOperatorLoc() const
bool isCompoundAssignmentOp() const
bool isMultiplicativeOp() const
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
bool isEqualityOp() const
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 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 isBitwiseOp(Opcode Opc)
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'.
bool hasPtrArgsOrResult(unsigned ID) const
Determines whether this builtin has a result or any arguments which are pointer types.
llvm::StringRef getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
bool isImmediate(unsigned ID) const
Returns true if this is an immediate (consteval) function.
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
bool isInStdNamespace(unsigned ID) const
Determines whether this builtin is a C++ standard library function that lives in (possibly-versioned)...
bool isDirectlyAddressable(unsigned ID) const
Determines whether this builtin can have its address taken with no special action required.
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...
Represents a call to a C++ constructor.
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.
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
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.
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.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
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.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
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.
Expr ** getArgs()
Retrieve the call arguments.
void setNumArgsUnsafe(unsigned NewNumArgs)
Bluntly set a new number of arguments without doing any checks whatsoever.
void shrinkNumArgs(unsigned NewNumArgs)
Reduce the number of arguments in this call expression.
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...
const char * getCastKindName() const
CharLiteralParser - Perform interpretation and semantic analysis of a character literal.
Represents a character-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.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
unsigned getValue() const
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
void mergeFrom(CleanupInfo Rhs)
void setExprNeedsCleanups(bool SideEffects)
bool cleanupsHaveSideEffects() const
bool exprNeedsCleanups() const
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 }.
Stmt * getStmtExprResult()
ConditionalOperator - The ?: ternary operator.
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)
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...
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
void setTypoName(const IdentifierInfo *II)
void setTypoNNS(NestedNameSpecifier *NNS)
Wrapper for source info for pointers decayed from arrays and functions.
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
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
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 ...
void addDecl(Decl *D)
Add the declaration D into this context.
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 encloses the declaration context DC.
A reference to a declared variable, function, enum, etc.
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
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.
SourceLocation getBeginLoc() const LLVM_READONLY
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 getLocation() const
NestedNameSpecifier * getQualifier() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name.
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 isInvalidDecl() const
SourceLocation getLocation() const
void setReferenced(bool R=true)
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
DeclContext * getDeclContext()
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
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
bool isIdentifier() const
Predicate functions for querying what type of name this is.
SourceLocation getBeginLoc() const LLVM_READONLY
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
TypeSourceInfo * getTypeSourceInfo() const
Information about one declarator, including the parsed type information and the identifier.
DeclaratorContext getContext() const
SourceLocation getBeginLoc() const LLVM_READONLY
const IdentifierInfo * getIdentifier() const
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool getSuppressSystemWarnings() const
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool VisitStmt(Stmt *S)
virtual bool TraverseTemplateArgument(const TemplateArgument &Arg)
Recursively visit a template argument and dispatch to the appropriate method for the argument type.
void setElaboratedKeywordLoc(SourceLocation Loc)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Represents a reference to #emded data.
RAII object that enters a new expression evaluation context.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
EnumDecl * getDecl() const
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,...
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...
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, e.g.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
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.
bool isIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
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.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant 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_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)
FullExpr - Represents a "full-expression" node.
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.
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.
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, Expr *TrailingRequiresClause=nullptr)
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 or init-capture pack that has been substituted bu...
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.
bool getCmseNSCall() const
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.
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.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
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.
Describes the sequence of initializations required to initialize a given object or reference with a s...
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...
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
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.
@ 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 isSubscriptPointerArithmetic() const
bool isSignedOverflowDefined() 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.
bool wasNotFoundInCurrentInstantiation() const
Determine whether no result was found because we could not search into dependent base classes of the ...
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
DeclClass * getAsSingle() const
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
void setLookupName(DeclarationName Name)
Sets the name to look up.
bool empty() const
Return true if no decls were found.
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
SourceLocation getNameLoc() const
Gets the location of the identifier.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
CXXRecordDecl * getNamingClass() const
Returns the 'naming class' for this lookup, i.e.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
DeclarationName getLookupName() const
Gets the name to look up.
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
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...
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.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
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
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>::".
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
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
Interfaces are the core concept in Objective-C for object oriented design.
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.
ObjCMethodDecl - Represents an instance or class method declaration.
ImplicitParamDecl * getSelfDecl() const
ArrayRef< ParmVarDecl * > parameters() const
QualType getReturnType() 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 a class type in Objective C.
Represents one property declaration in an Objective-C interface.
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
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.
bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const
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.
Represents a parameter to a function.
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
bool hasUninstantiatedDefaultArg() const
QualType getOriginalType() const
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl, bool ForceElaboratedPrinting=false)
SourceLocation getLastFPEvalPragmaLocation() const
void CreateString(StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
Plop the specified string into a scratch buffer and set the specified token's location and length to ...
LangOptions::FPEvalMethodKind getCurrentFPEvalMethod() const
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
uint8_t getSpellingOfSingleCharacterNumericConstant(const Token &Tok, bool *Invalid=nullptr) const
Given a Token Tok that is a numeric constant with length 1, return the value of constant as an unsign...
SourceManager & getSourceManager() const
bool isMacroDefined(StringRef Id)
const TargetInfo & getTargetInfo() const
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
IdentifierTable & getIdentifierTable()
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
bool isAddressSpaceOverlapping(QualType T, const ASTContext &Ctx) const
Returns true if address space qualifiers overlap with T address space qualifiers.
QualType withConst() const
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isCXX98PODType(const ASTContext &Context) const
Return true if this is a POD type according to the rules of the C++98 standard, regardless of the cur...
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
QualType withCVRQualifiers(unsigned CVR) const
bool isCForbiddenLValueType() const
Determine whether expressions of the given type are forbidden from being lvalues in C.
bool isConstQualified() const
Determine whether this type is const-qualified.
bool hasAddressSpace() const
Check if this type has any address space qualifier.
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
The collection of all-type qualifiers we support.