53 #include "llvm/ADT/STLExtras.h"
54 #include "llvm/ADT/StringExtras.h"
55 #include "llvm/Support/Casting.h"
56 #include "llvm/Support/ConvertUTF.h"
57 #include "llvm/Support/SaveAndRestore.h"
58 #include "llvm/Support/TypeSize.h"
61 using namespace clang;
68 if (ParsingInitForAutoVars.count(D))
78 if (getLangOpts().
CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
84 if (TreatUnavailableAsInvalid &&
85 isUnavailableAlignedAllocationFunction(*FD))
94 if (isa<UnresolvedUsingIfExistsDecl>(D))
102 if (
const auto *A = D->
getAttr<UnusedAttr>()) {
105 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
106 A->getSemanticSpelling() != UnusedAttr::C2x_maybe_unused) {
108 if (DC && !DC->
hasAttr<UnusedAttr>())
109 S.
Diag(Loc, diag::warn_used_but_marked_unused) << D;
118 if (
Decl->isDefaulted()) {
125 DiagnoseDeletedDefaultedFunction(
Decl);
129 auto *Ctor = dyn_cast<CXXConstructorDecl>(
Decl);
130 if (Ctor && Ctor->isInheritingConstructor())
131 return NoteDeletedInheritingConstructor(Ctor);
141 if (I->getStorageClass() !=
SC_None)
168 if (!Current->isInlined())
170 if (!Current->isExternallyVisible())
186 if (!DowngradeWarning && UsedFn)
189 S.
Diag(Loc, DowngradeWarning ? diag::ext_internal_in_extern_inline_quiet
190 : diag::ext_internal_in_extern_inline)
195 S.
Diag(D->getCanonicalDecl()->getLocation(), diag::note_entity_declared_at)
205 Diag(DeclBegin, diag::note_convert_inline_to_static)
224 bool ObjCPropertyAccess,
225 bool AvoidPartialAvailabilityChecks,
227 bool SkipTrailingRequiresClause) {
229 if (getLangOpts().
CPlusPlus && isa<FunctionDecl>(D)) {
233 if (Pos != SuppressedDiagnostics.end()) {
235 Diag(Suppressed.first, Suppressed.second);
246 if (cast<FunctionDecl>(D)->isMain())
247 Diag(Loc, diag::ext_main_used);
249 diagnoseUnavailableAlignedAllocation(*cast<FunctionDecl>(D), Loc);
253 if (ParsingInitForAutoVars.count(D)) {
254 if (isa<BindingDecl>(D)) {
255 Diag(Loc, diag::err_binding_cannot_appear_in_own_initializer)
258 Diag(Loc, diag::err_auto_variable_cannot_appear_in_own_initializer)
259 << D->
getDeclName() << cast<VarDecl>(D)->getType();
266 if (FD->isDeleted()) {
267 auto *Ctor = dyn_cast<CXXConstructorDecl>(FD);
268 if (Ctor && Ctor->isInheritingConstructor())
269 Diag(Loc, diag::err_deleted_inherited_ctor_use)
271 << Ctor->getInheritedConstructor().getConstructor()->getParent();
273 Diag(Loc, diag::err_deleted_function_use);
274 NoteDeletedFunction(FD);
286 if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) {
288 if (CheckFunctionConstraints(FD, Satisfaction, Loc,
295 diag::err_reference_to_function_with_unsatisfied_constraints)
297 DiagnoseUnsatisfiedConstraint(Satisfaction);
304 if (getLangOpts().
CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
305 DeduceReturnType(FD, Loc))
308 if (getLangOpts().
CUDA && !CheckCUDACall(Loc, FD))
311 if (getLangOpts().SYCLIsDevice && !checkSYCLDeviceFunction(Loc, FD))
315 if (
auto *MD = dyn_cast<CXXMethodDecl>(D)) {
317 if (MD->getParent()->isLambda() &&
318 ((isa<CXXConstructorDecl>(MD) &&
319 cast<CXXConstructorDecl>(MD)->isDefaultConstructor()) ||
320 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) {
321 Diag(Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign)
322 << !isa<CXXConstructorDecl>(MD);
326 auto getReferencedObjCProp = [](
const NamedDecl *D) ->
328 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
333 if (diagnoseArgIndependentDiagnoseIfAttrs(ObjCPDecl, Loc))
335 }
else if (diagnoseArgIndependentDiagnoseIfAttrs(D, Loc)) {
343 auto *DRD = dyn_cast<OMPDeclareReductionDecl>(CurContext);
344 if (LangOpts.OpenMP && DRD && !CurContext->containsDecl(D) &&
346 Diag(Loc, diag::err_omp_wrong_var_in_declare_reduction)
347 << getCurFunction()->HasOMPDeclareReductionCombiner;
357 if (LangOpts.OpenMP && isa<VarDecl>(D) &&
358 !isOpenMPDeclareMapperVarDeclAllowed(cast<VarDecl>(D))) {
359 Diag(Loc, diag::err_omp_declare_mapper_wrong_var)
360 << getOpenMPDeclareMapperVarName();
365 if (
const auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(D)) {
366 Diag(Loc, diag::err_use_of_empty_using_if_exists);
367 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here);
371 DiagnoseAvailabilityOfDecl(D, Locs, UnknownObjCClass, ObjCPropertyAccess,
372 AvoidPartialAvailabilityChecks, ClassReceiver);
378 if (
auto *VD = dyn_cast<ValueDecl>(D))
379 checkTypeSupport(VD->getType(), Loc, VD);
381 if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice)) {
383 if (
const auto *VD = dyn_cast<VarDecl>(D))
385 targetDiag(*Locs.begin(), diag::err_thread_unsupported);
388 if (isa<ParmVarDecl>(D) && isa<RequiresExprBodyDecl>(D->
getDeclContext()) &&
389 !isUnevaluatedContext()) {
393 Diag(Loc, diag::err_requires_expr_parameter_referenced_in_evaluated_context)
408 const SentinelAttr *
attr = D->
getAttr<SentinelAttr>();
413 unsigned numFormalParams;
417 enum CalleeType { CT_Function, CT_Method, CT_Block } calleeType;
420 numFormalParams = MD->param_size();
421 calleeType = CT_Method;
422 }
else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
423 numFormalParams = FD->param_size();
424 calleeType = CT_Function;
425 }
else if (isa<VarDecl>(D)) {
431 calleeType = CT_Function;
434 calleeType = CT_Block;
440 numFormalParams = proto->getNumParams();
452 unsigned nullPos =
attr->getNullPos();
453 assert((nullPos == 0 || nullPos == 1) &&
"invalid null position on sentinel");
454 numFormalParams = (nullPos > numFormalParams ? 0 : numFormalParams - nullPos);
457 unsigned numArgsAfterSentinel =
attr->getSentinel();
461 if (Args.size() < numFormalParams + numArgsAfterSentinel + 1) {
468 Expr *sentinelExpr = Args[Args.size() - numArgsAfterSentinel - 1];
469 if (!sentinelExpr)
return;
479 if (calleeType == CT_Method && PP.isMacroDefined(
"nil"))
482 NullValue =
"nullptr";
483 else if (PP.isMacroDefined(
"NULL"))
486 NullValue =
"(void*) 0";
489 Diag(Loc, diag::warn_missing_sentinel) <<
int(calleeType);
491 Diag(MissingNilLoc, diag::warn_missing_sentinel)
515 assert(!Ty.
isNull() &&
"DefaultFunctionArrayConversion - missing type");
519 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
524 CK_FunctionToPointerDecay).get();
539 CK_ArrayToPointerDecay);
555 if (UO && UO->getOpcode() == UO_Deref &&
556 UO->getSubExpr()->getType()->isPointerType()) {
558 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
561 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
563 !UO->getType().isVolatileQualified()) {
565 S.
PDiag(diag::warn_indirection_through_null)
566 << UO->getSubExpr()->getSourceRange());
568 S.
PDiag(diag::note_indirection_through_null));
600 if (ObjectSetClass) {
644 assert(!T.
isNull() &&
"r-value conversion on typeless expression?");
667 if (getLangOpts().
OpenCL &&
668 !getOpenCLOptions().isAvailableOption(
"cl_khr_fp16", getLangOpts()) &&
677 NamedDecl *ObjectGetClass = LookupSingleName(TUScope,
684 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()),
")");
709 ExprResult Res = CheckLValueToRValueConversionOperand(E);
717 Cleanup.setExprNeedsCleanups(
true);
720 Cleanup.setExprNeedsCleanups(
true);
726 CurFPFeatureOverrides());
732 T = Atomic->getValueType().getUnqualifiedType();
741 ExprResult Res = DefaultFunctionArrayConversion(E, Diagnose);
744 Res = DefaultLvalueConversion(Res.
get());
759 CK_FunctionToPointerDecay);
763 Res = DefaultLvalueConversion(Res.
get());
776 ExprResult Res = DefaultFunctionArrayLvalueConversion(E);
782 assert(!Ty.
isNull() &&
"UsualUnaryConversions - missing type");
786 (getLangOpts().getFPEvalMethod() !=
787 LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine ||
788 PP.getLastFPEvalPragmaLocation().isValid())) {
789 switch (EvalMethod) {
791 llvm_unreachable(
"Unrecognized float evaluation method");
794 llvm_unreachable(
"Float evaluation method should be set by now");
800 ? ImpCastExprToType(E,
802 CK_FloatingComplexCast)
803 : ImpCastExprToType(E, Context.
DoubleTy, CK_FloatingCast);
811 CK_FloatingComplexCast)
819 if (Ty->
isHalfType() && !getLangOpts().NativeHalfType)
820 return ImpCastExprToType(Res.
get(), Context.
FloatTy, CK_FloatingCast);
841 E = ImpCastExprToType(E, PTy, CK_IntegralCast).get();
846 E = ImpCastExprToType(E, PT, CK_IntegralCast).get();
859 assert(!Ty.
isNull() &&
"DefaultArgumentPromotion - missing type");
871 if (BTy && (BTy->
getKind() == BuiltinType::Half ||
873 if (getLangOpts().OpenCL &&
874 !getOpenCLOptions().isAvailableOption(
"cl_khr_fp64", getLangOpts())) {
875 if (BTy->
getKind() == BuiltinType::Half) {
876 E = ImpCastExprToType(E, Context.
FloatTy, CK_FloatingCast).get();
879 E = ImpCastExprToType(E, Context.
DoubleTy, CK_FloatingCast).get();
883 getLangOpts().getExtendIntArgs() ==
891 : ImpCastExprToType(E, Context.
LongLongTy, CK_IntegralCast).get();
893 "Unexpected typesize for LongLongTy");
953 if (!Record->hasNonTrivialCopyConstructor() &&
954 !Record->hasNonTrivialMoveConstructor() &&
955 !Record->hasNonTrivialDestructor())
956 return VAK_ValidInCXX11;
964 if (getLangOpts().MSVCCompat)
965 return VAK_MSVCUndefined;
969 return VAK_Undefined;
979 case VAK_ValidInCXX11:
982 PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
989 PDiag(diag::warn_pass_class_arg_to_vararg)
990 << Ty << CT << hasCStrMethod(E) <<
".c_str()");
995 case VAK_MSVCUndefined:
997 PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
1004 diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
1008 PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
1012 << isa<InitListExpr>(E) << Ty << CT;
1023 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast &&
1024 (CT == VariadicMethod ||
1025 (FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>()))) {
1026 E = stripARCUnbridgedCast(E);
1030 ExprResult ExprRes = CheckPlaceholderExpr(E);
1037 ExprResult ExprRes = DefaultArgumentPromotion(E);
1043 maybeExtendBlockObject(ExprRes);
1049 if (isValidVarArgType(E->
getType()) == VAK_Undefined) {
1054 Name.setIdentifier(PP.getIdentifierInfo(
"__builtin_trap"),
1056 ExprResult TrapFn = ActOnIdExpression(TUScope, SS, TemplateKWLoc, Name,
1064 if (Call.isInvalid())
1068 ActOnBinOp(TUScope, E->
getBeginLoc(), tok::comma, Call.get(), E);
1069 if (Comma.isInvalid())
1076 diag::err_call_incomplete_argument))
1093 if (SkipCast)
return false;
1098 CK_FloatingRealToComplex);
1102 CK_IntegralComplexToFloatingComplex);
1120 bool PromotePrecision) {
1125 if (PromotePrecision) {
1130 if (LongerIsComplex)
1142 QualType RHSType,
bool IsCompAssign) {
1167 bool ConvertFloat,
bool ConvertInt) {
1172 CK_IntegralToFloating);
1183 CK_IntegralComplexToFloatingComplex);
1188 CK_FloatingRealToComplex);
1197 QualType RHSType,
bool IsCompAssign) {
1207 else if (!IsCompAssign)
1209 return LHSFloat ? LHSType : RHSType;
1214 if (LHSFloat && RHSFloat) {
1221 assert(order < 0 &&
"illegal float comparison");
1255 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType;
1261 if ((&LHSSem != &llvm::APFloat::PPCDoubleDouble() ||
1262 &RHSSem != &llvm::APFloat::IEEEquad()) &&
1263 (&LHSSem != &llvm::APFloat::IEEEquad() ||
1264 &RHSSem != &llvm::APFloat::PPCDoubleDouble()))
1281 CK_IntegralComplexCast);
1287 template <PerformCastFn doLHSCast, PerformCastFn doRHSCast>
1290 QualType RHSType,
bool IsCompAssign) {
1295 if (LHSSigned == RHSSigned) {
1298 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1300 }
else if (!IsCompAssign)
1301 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1303 }
else if (order != (LHSSigned ? 1 : -1)) {
1307 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1309 }
else if (!IsCompAssign)
1310 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1317 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1319 }
else if (!IsCompAssign)
1320 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1329 RHS = (*doRHSCast)(S, RHS.
get(), result);
1331 LHS = (*doLHSCast)(S, LHS.
get(), result);
1341 bool IsCompAssign) {
1345 if (LHSComplexInt && RHSComplexInt) {
1349 handleIntegerConversion<doComplexIntegralCast, doComplexIntegralCast>
1350 (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign);
1355 if (LHSComplexInt) {
1358 handleIntegerConversion<doComplexIntegralCast, doIntegralCast>
1359 (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign);
1362 CK_IntegralRealToComplex);
1367 assert(RHSComplexInt);
1371 handleIntegerConversion<doIntegralCast, doComplexIntegralCast>
1372 (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign);
1377 CK_IntegralRealToComplex);
1386 assert(BTy &&
"Expected a builtin type.");
1388 switch (BTy->getKind()) {
1389 case BuiltinType::ShortFract:
1390 case BuiltinType::UShortFract:
1391 case BuiltinType::SatShortFract:
1392 case BuiltinType::SatUShortFract:
1394 case BuiltinType::Fract:
1395 case BuiltinType::UFract:
1396 case BuiltinType::SatFract:
1397 case BuiltinType::SatUFract:
1399 case BuiltinType::LongFract:
1400 case BuiltinType::ULongFract:
1401 case BuiltinType::SatLongFract:
1402 case BuiltinType::SatULongFract:
1404 case BuiltinType::ShortAccum:
1405 case BuiltinType::UShortAccum:
1406 case BuiltinType::SatShortAccum:
1407 case BuiltinType::SatUShortAccum:
1409 case BuiltinType::Accum:
1410 case BuiltinType::UAccum:
1411 case BuiltinType::SatAccum:
1412 case BuiltinType::SatUAccum:
1414 case BuiltinType::LongAccum:
1415 case BuiltinType::ULongAccum:
1416 case BuiltinType::SatLongAccum:
1417 case BuiltinType::SatULongAccum:
1420 if (BTy->isInteger())
1422 llvm_unreachable(
"Unexpected fixed point or integer type");
1434 "Expected at least one of the operands to be a fixed point type");
1437 "Special fixed point arithmetic operation conversions are only "
1438 "applied to ints or other fixed point types");
1460 QualType ResultTy = LHSTyRank > RHSTyRank ? LHSTy : RHSTy;
1482 REnum = R->isUnscopedEnumerationType();
1484 if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
1487 ? diag::warn_arith_conv_enum_float_cxx20
1488 : diag::warn_arith_conv_enum_float)
1490 << (
int)ACK << LEnum << L << R;
1491 }
else if (!IsCompAssign && LEnum && REnum &&
1495 !R->castAs<
EnumType>()->getDecl()->hasNameForLinkage()) {
1500 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
1501 : diag::warn_arith_conv_mixed_anon_enum_types;
1506 ? diag::warn_conditional_mixed_enum_types_cxx20
1507 : diag::warn_conditional_mixed_enum_types;
1512 ? diag::warn_comparison_mixed_enum_types_cxx20
1513 : diag::warn_comparison_mixed_enum_types;
1516 ? diag::warn_arith_conv_mixed_enum_types_cxx20
1517 : diag::warn_arith_conv_mixed_enum_types;
1520 << (
int)ACK << L << R;
1533 if (ACK != ACK_CompAssign) {
1534 LHS = UsualUnaryConversions(LHS.
get());
1539 RHS = UsualUnaryConversions(RHS.
get());
1550 LHSType = AtomicLHS->getValueType();
1562 QualType LHSUnpromotedType = LHSType;
1566 if (!LHSBitfieldPromoteTy.
isNull())
1567 LHSType = LHSBitfieldPromoteTy;
1568 if (LHSType != LHSUnpromotedType && ACK != ACK_CompAssign)
1569 LHS = ImpCastExprToType(LHS.
get(), LHSType, CK_IntegralCast);
1585 ACK == ACK_CompAssign);
1590 ACK == ACK_CompAssign);
1595 ACK == ACK_CompAssign);
1601 return handleIntegerConversion<doIntegralCast, doIntegralCast>
1602 (*
this, LHS, RHS, LHSType, RHSType, ACK == ACK_CompAssign);
1614 Expr *ControllingExpr,
1617 unsigned NumAssocs = ArgTypes.size();
1618 assert(NumAssocs == ArgExprs.size());
1621 for (
unsigned i = 0; i < NumAssocs; ++i) {
1623 (void) GetTypeFromParser(ArgTypes[i], &Types[i]);
1629 CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, ControllingExpr,
1639 Expr *ControllingExpr,
1642 unsigned NumAssocs = Types.size();
1643 assert(NumAssocs == Exprs.size());
1650 ExprResult R = DefaultFunctionArrayLvalueConversion(ControllingExpr);
1653 ControllingExpr = R.
get();
1656 bool TypeErrorFound =
false,
1658 ContainsUnexpandedParameterPack
1663 if (!inTemplateInstantiation() && !IsResultDependent &&
1666 diag::warn_side_effects_unevaluated_context);
1668 for (
unsigned i = 0; i < NumAssocs; ++i) {
1669 if (Exprs[i]->containsUnexpandedParameterPack())
1670 ContainsUnexpandedParameterPack =
true;
1673 if (Types[i]->getType()->containsUnexpandedParameterPack())
1674 ContainsUnexpandedParameterPack =
true;
1676 if (Types[i]->getType()->isDependentType()) {
1677 IsResultDependent =
true;
1682 if (Types[i]->getType()->isIncompleteType())
1683 D = diag::err_assoc_type_incomplete;
1684 else if (!Types[i]->getType()->isObjectType())
1685 D = diag::err_assoc_type_nonobject;
1686 else if (Types[i]->getType()->isVariablyModifiedType())
1687 D = diag::err_assoc_type_variably_modified;
1703 unsigned Reason = 0;
1712 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1713 diag::warn_unreachable_association)
1714 << QT << (Reason - 1);
1718 Diag(Types[i]->getTypeLoc().getBeginLoc(), D)
1719 << Types[i]->getTypeLoc().getSourceRange()
1720 << Types[i]->getType();
1721 TypeErrorFound =
true;
1726 for (
unsigned j = i+1; j < NumAssocs; ++j)
1727 if (Types[j] && !Types[j]->getType()->isDependentType() &&
1729 Types[j]->getType())) {
1730 Diag(Types[j]->getTypeLoc().getBeginLoc(),
1731 diag::err_assoc_compatible_types)
1732 << Types[j]->getTypeLoc().getSourceRange()
1733 << Types[j]->getType()
1734 << Types[i]->getType();
1735 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1736 diag::note_compat_assoc)
1737 << Types[i]->getTypeLoc().getSourceRange()
1738 << Types[i]->getType();
1739 TypeErrorFound =
true;
1749 if (IsResultDependent)
1751 Exprs, DefaultLoc, RParenLoc,
1752 ContainsUnexpandedParameterPack);
1755 unsigned DefaultIndex = -1
U;
1759 for (
unsigned i = 0; i < NumAssocs; ++i) {
1764 Types[i]->getType()))
1765 CompatIndices.push_back(i);
1771 if (CompatIndices.size() > 1) {
1775 Diag(ControllingExpr->
getBeginLoc(), diag::err_generic_sel_multi_match)
1778 for (
unsigned I : CompatIndices) {
1779 Diag(Types[I]->getTypeLoc().getBeginLoc(),
1780 diag::note_compat_assoc)
1781 << Types[I]->getTypeLoc().getSourceRange()
1782 << Types[I]->getType();
1790 if (DefaultIndex == -1
U && CompatIndices.size() == 0) {
1804 unsigned ResultIndex =
1805 CompatIndices.size() ? CompatIndices[0] : DefaultIndex;
1808 Context, KeyLoc, ControllingExpr, Types, Exprs, DefaultLoc, RParenLoc,
1809 ContainsUnexpandedParameterPack, ResultIndex);
1827 assert(Args.size() <= 2 &&
"too many arguments for literal operator");
1830 for (
unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
1831 ArgTy[ArgIdx] = Args[ArgIdx]->getType();
1832 if (ArgTy[ArgIdx]->isArrayType())
1859 assert(!StringToks.empty() &&
"Must have at least one string!");
1866 for (
const Token &Tok : StringToks)
1867 StringTokLocs.push_back(Tok.getLocation());
1874 }
else if (
Literal.isUTF8()) {
1875 if (getLangOpts().Char8)
1878 }
else if (
Literal.isUTF16()) {
1881 }
else if (
Literal.isUTF32()) {
1884 }
else if (
Literal.isPascal()) {
1892 Diag(StringTokLocs.front(), diag::warn_cxx20_compat_utf8_string);
1898 auto RemovalDiag = PDiag(diag::note_cxx20_compat_utf8_string_remove_u8);
1900 for (
const Token &Tok : StringToks) {
1901 if (Tok.getKind() == tok::utf8_string_literal) {
1903 RemovalDiagLoc = Tok.getLocation();
1907 getSourceManager(), getLangOpts())));
1910 Diag(RemovalDiagLoc, RemovalDiag);
1920 StringTokLocs.size());
1921 if (
Literal.getUDSuffix().empty())
1932 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
1947 LookupResult R(*
this, OpName, UDSuffixLoc, LookupOrdinaryName);
1948 switch (LookupLiteralOperator(UDLScope, R, ArgTy,
1957 Expr *Args[] = { Lit, LenArg };
1959 return BuildLiteralOperatorCall(R, OpNameInfo, Args, StringTokLocs.back());
1962 case LOLR_Template: {
1967 return BuildLiteralOperatorCall(R, OpNameInfo, std::nullopt,
1968 StringTokLocs.back(), &ExplicitArgs);
1971 case LOLR_StringTemplatePack: {
1982 for (
unsigned I = 0, N = Lit->
getLength(); I != N; ++I) {
1988 return BuildLiteralOperatorCall(R, OpNameInfo, std::nullopt,
1989 StringTokLocs.back(), &ExplicitArgs);
1992 case LOLR_ErrorNoDiagnostic:
1993 llvm_unreachable(
"unexpected literal operator lookup result");
1997 llvm_unreachable(
"unexpected literal operator lookup result");
2005 return BuildDeclRefExpr(D, Ty, VK, NameInfo, SS);
2016 return BuildDeclRefExpr(D, Ty, VK, NameInfo, NNS, FoundD, TemplateKWLoc,
2029 auto *DRE = dyn_cast<DeclRefExpr>(VD->
getInit());
2032 auto *Referee = dyn_cast<VarDecl>(DRE->getDecl());
2033 if (!Referee || !Referee->hasGlobalStorage() ||
2034 Referee->hasAttr<CUDADeviceAttr>())
2040 auto *MD = dyn_cast_or_null<CXXMethodDecl>(S.
CurContext);
2041 if (MD && MD->getParent()->isLambda() &&
2042 MD->getOverloadedOperator() == OO_Call && MD->hasAttr<CUDADeviceAttr>() &&
2051 if (isUnevaluatedContext())
2064 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2065 if (VD->getType()->isReferenceType() &&
2066 !(getLangOpts().OpenMP && isOpenMPCapturedDecl(D)) &&
2068 VD->isUsableInConstantExpressions(Context))
2085 bool RefersToCapturedVariable = isa<VarDecl, BindingDecl>(D) &&
2086 NeedToCaptureVariable(D, NameInfo.
getLoc());
2089 Context, NNS, TemplateKWLoc, D, RefersToCapturedVariable, NameInfo, Ty,
2090 VK, FoundD, TemplateArgs, getNonOdrUseReasonInCurrentContext(D));
2091 MarkDeclRefReferenced(E);
2107 if (
auto *NewFPT = ResolveExceptionSpec(NameInfo.
getLoc(), FPT))
2112 if (getLangOpts().ObjCWeak && isa<VarDecl>(D) &&
2114 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->
getBeginLoc()))
2115 getCurFunction()->recordUseOfWeak(E);
2119 FD = IFD->getAnonField();
2121 UnusedPrivateFields.remove(FD);
2129 if (
auto *BD = dyn_cast<BindingDecl>(D))
2130 if (
auto *BE = BD->getBinding())
2155 Id.TemplateId->NumArgs);
2156 translateTemplateArguments(TemplateArgsPtr, Buffer);
2161 TemplateArgs = &Buffer;
2163 NameInfo = GetNameFromUnqualifiedId(
Id);
2164 TemplateArgs =
nullptr;
2171 unsigned DiagnosticID,
unsigned DiagnosticSuggestID) {
2178 SemaRef.
Diag(TypoLoc, diag::err_no_member) << Typo << Ctx
2181 SemaRef.
Diag(TypoLoc, DiagnosticID) << Typo;
2186 bool DroppedSpecifier =
2189 ? diag::note_implicit_param_decl
2190 : diag::note_previous_decl;
2193 SemaRef.
PDiag(NoteID));
2196 << Typo << Ctx << DroppedSpecifier
2198 SemaRef.
PDiag(NoteID));
2213 bool isDefaultArgument =
2214 !CodeSynthesisContexts.empty() &&
2215 CodeSynthesisContexts.back().Kind ==
2216 CodeSynthesisContext::DefaultFunctionArgumentInstantiation;
2217 CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext);
2218 bool isInstance = CurMethod && CurMethod->
isInstance() &&
2227 unsigned DiagID = diag::err_found_in_dependent_base;
2228 unsigned NoteID = diag::note_member_declared_at;
2230 DiagID = getLangOpts().MSVCCompat ? diag::ext_found_later_in_class
2231 : diag::err_found_later_in_class;
2232 }
else if (getLangOpts().MSVCCompat) {
2233 DiagID = diag::ext_found_in_dependent_base;
2234 NoteID = diag::note_dependent_member_use;
2250 Diag(D->getLocation(), NoteID);
2259 if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) {
2260 Diag(R.getNameLoc(), diag::err_member_call_without_object);
2277 unsigned diagnostic = diag::err_undeclared_var_use;
2278 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
2282 diagnostic = diag::err_undeclared_use;
2283 diagnostic_suggest = diag::err_undeclared_use_suggest;
2292 if (isa<CXXRecordDecl>(DC)) {
2293 LookupQualifiedName(R, DC);
2303 AddOverloadedCallCandidates(R, ExplicitTemplateArgs, Args, Candidates);
2308 R.
addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
2312 return DiagnoseDependentMemberLookup(R);
2325 assert(!ExplicitTemplateArgs &&
2326 "Diagnosing an empty lookup with explicit template args!");
2327 *Out = CorrectTypoDelayed(
2330 emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args,
2331 diagnostic, diagnostic_suggest);
2333 nullptr, CTK_ErrorRecovery);
2338 S, &SS, CCC, CTK_ErrorRecovery))) {
2340 bool DroppedSpecifier =
2344 bool AcceptableWithRecovery =
false;
2345 bool AcceptableWithoutRecovery =
false;
2354 dyn_cast<FunctionTemplateDecl>(CD))
2355 AddTemplateOverloadCandidate(
2358 else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(CD))
2359 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->
size() == 0)
2365 ND = Best->FoundDecl;
2366 Corrected.setCorrectionDecl(ND);
2370 Corrected.setCorrectionDecl(ND);
2382 Record = cast<CXXRecordDecl>(
2388 AcceptableWithRecovery = isa<ValueDecl>(UnderlyingND) ||
2389 isa<FunctionTemplateDecl>(UnderlyingND);
2395 AcceptableWithoutRecovery = isa<TypeDecl>(UnderlyingND) ||
2397 isa<ObjCInterfaceDecl>(UnderlyingND);
2401 AcceptableWithoutRecovery =
true;
2404 if (AcceptableWithRecovery || AcceptableWithoutRecovery) {
2406 ? diag::note_implicit_param_decl
2407 : diag::note_previous_decl;
2409 diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name,
2410 PDiag(NoteID), AcceptableWithRecovery);
2412 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
2413 << Name << computeDeclContext(SS,
false)
2414 << DroppedSpecifier << SS.
getRange(),
2415 PDiag(NoteID), AcceptableWithRecovery);
2418 return !AcceptableWithRecovery;
2427 << Name << computeDeclContext(SS,
false)
2454 else if (
auto *MD = dyn_cast<CXXMethodDecl>(S.
CurContext))
2462 auto DB = S.
Diag(Loc, diag::ext_undeclared_unqual_id_with_dependent_base);
2463 DB << NameInfo.
getName() << RD;
2465 if (!ThisType.
isNull()) {
2468 Context,
nullptr, ThisType,
true,
2470 nullptr, NameInfo, TemplateArgs);
2487 bool HasTrailingLParen,
bool IsAddressOfOperand,
2489 bool IsInlineAsmIdentifier,
Token *KeywordReplacement) {
2490 assert(!(IsAddressOfOperand && HasTrailingLParen) &&
2491 "cannot be direct & operand and have a trailing lparen");
2500 DecomposeUnqualifiedId(
Id, TemplateArgsBuffer, NameInfo, TemplateArgs);
2523 bool DependentID =
false;
2525 Name.getCXXNameType()->isDependentType()) {
2527 }
else if (SS.
isSet()) {
2528 if (
DeclContext *DC = computeDeclContext(SS,
false)) {
2529 if (RequireCompleteDeclContext(SS, DC))
2537 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2538 IsAddressOfOperand, TemplateArgs);
2543 ? LookupObjCImplicitSelfParam
2544 : LookupOrdinaryName);
2545 if (TemplateKWLoc.
isValid() || TemplateArgs) {
2551 bool MemberOfUnknownSpecialization;
2553 if (LookupTemplateName(R, S, SS,
QualType(),
false,
2554 MemberOfUnknownSpecialization, TemplateKWLoc,
2558 if (MemberOfUnknownSpecialization ||
2560 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2561 IsAddressOfOperand, TemplateArgs);
2563 bool IvarLookupFollowUp = II && !SS.
isSet() && getCurMethodDecl();
2564 LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
2569 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2570 IsAddressOfOperand, TemplateArgs);
2574 if (IvarLookupFollowUp) {
2575 ExprResult E(LookupInObjCMethod(R, S, II,
true));
2589 if (R.
empty() && HasTrailingLParen && II &&
2590 getLangOpts().implicitFunctionsAllowed()) {
2591 NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *II, S);
2597 bool ADL = UseArgumentDependentLookup(SS, R, HasTrailingLParen);
2599 if (R.
empty() && !ADL) {
2600 if (SS.
isEmpty() && getLangOpts().MSVCCompat) {
2602 TemplateKWLoc, TemplateArgs))
2607 if (IsInlineAsmIdentifier)
2617 "Typo correction callback misconfigured");
2627 if (DiagnoseEmptyLookup(S, SS, R, CCC ? *CCC : DefaultValidator,
nullptr,
2628 std::nullopt, &TE)) {
2629 if (TE && KeywordReplacement) {
2630 auto &
State = getTypoExprState(TE);
2631 auto BestTC =
State.Consumer->getNextCorrection();
2632 if (BestTC.isKeyword()) {
2633 auto *II = BestTC.getCorrectionAsIdentifierInfo();
2634 if (
State.DiagHandler)
2635 State.DiagHandler(BestTC);
2639 KeywordReplacement->
setLocation(BestTC.getCorrectionRange().getBegin());
2642 clearDelayedTypo(TE);
2645 return (
Expr*)
nullptr;
2647 State.Consumer->resetCorrectionStream();
2652 assert(!R.
empty() &&
2653 "DiagnoseEmptyLookup returned false but added no results");
2660 ExprResult E(LookupInObjCMethod(R, S, Ivar->getIdentifier()));
2670 assert(!R.
empty() || ADL);
2696 if (!R.
empty() && (*R.
begin())->isCXXClassMember()) {
2697 bool MightBeImplicitMember;
2698 if (!IsAddressOfOperand)
2699 MightBeImplicitMember =
true;
2701 MightBeImplicitMember =
false;
2703 MightBeImplicitMember =
false;
2705 MightBeImplicitMember =
true;
2707 MightBeImplicitMember = isa<FieldDecl>(R.
getFoundDecl()) ||
2711 if (MightBeImplicitMember)
2712 return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc,
2713 R, TemplateArgs, S);
2716 if (TemplateArgs || TemplateKWLoc.
isValid()) {
2724 "There should only be one declaration found.");
2727 return BuildTemplateIdExpr(SS, TemplateKWLoc, R, ADL, TemplateArgs);
2730 return BuildDeclarationNameExpr(SS, R, ADL);
2749 if (RequireCompleteDeclContext(SS, DC))
2753 LookupQualifiedName(R, DC);
2767 if (
const auto *CD = dyn_cast<CXXRecordDecl>(DC))
2768 if (CD->isInvalidDecl())
2779 unsigned DiagID = diag::err_typename_missing;
2780 if (RecoveryTSI && getLangOpts().MSVCCompat)
2781 DiagID = diag::ext_typename_missing;
2783 auto D =
Diag(Loc, DiagID);
2814 if (!R.
empty() && (*R.
begin())->isCXXClassMember() && !IsAddressOfOperand)
2815 return BuildPossibleImplicitMemberExpr(SS,
2819 return BuildDeclarationNameExpr(SS, R,
false);
2850 LookForIvars =
true;
2851 else if (IsClassMethod)
2852 LookForIvars =
false;
2863 if (IsClassMethod) {
2871 !getLangOpts().DebuggerSupport)
2884 Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
2892 Diag(Loc, diag::err_ivar_use_in_class_method) << IV->getDeclName();
2905 "should not reference ivar from this context");
2908 assert(IFace &&
"should not reference ivar from this context");
2916 if (DiagnoseUseOfDecl(IV, Loc))
2927 ActOnIdExpression(S, SelfScopeSpec, TemplateKWLoc, SelfName,
2933 SelfExpr = DefaultLvalueConversion(SelfExpr.
get());
2937 MarkAnyDeclReferenced(Loc, IV,
true);
2941 !IvarBacksCurrentMethodAccessor(IFace, CurMethod, IV))
2949 if (!isUnevaluatedContext() &&
2950 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, Loc))
2951 getCurFunction()->recordUseOfWeak(Result);
2953 if (getLangOpts().ObjCAutoRefCount && !isUnevaluatedContext())
2955 ImplicitlyRetainedSelfLocs.push_back({Loc, BD});
2973 cast<ObjCIvarDecl>(Ivar.
get()));
2975 if (Lookup.
empty() && II && AllowBuiltinCreation)
3015 bool PointerConversions =
false;
3016 if (isa<FieldDecl>(
Member)) {
3020 DestRecordType, FromPtrType
3027 PointerConversions =
true;
3029 DestType = DestRecordType;
3030 FromRecordType = FromType;
3033 if (Method->isStatic())
3036 DestType = Method->getThisType();
3041 PointerConversions =
true;
3043 FromRecordType = FromType;
3044 DestType = DestRecordType;
3049 if (FromAS != DestAS) {
3054 if (PointerConversions)
3095 if (Qualifier && Qualifier->getAsType()) {
3097 assert(QType->
isRecordType() &&
"lookup done with non-record type");
3107 FromLoc, FromRange, &BasePath))
3110 if (PointerConversions)
3113 VK, &BasePath).
get();
3116 FromRecordType = QRecordType;
3127 FromLoc, FromRange, &BasePath,
3137 bool HasTrailingLParen) {
3139 if (!HasTrailingLParen)
3157 if (D->isCXXClassMember())
3166 if (isa<UsingShadowDecl>(D))
3167 D = cast<UsingShadowDecl>(D)->getTargetDecl();
3168 else if (D->getLexicalDeclContext()->isFunctionOrMethod())
3175 if (isa<FunctionDecl>(D)) {
3181 }
else if (!isa<FunctionTemplateDecl>(D))
3194 bool AcceptInvalid) {
3198 if (isa<TypedefNameDecl>(D)) {
3203 if (isa<ObjCInterfaceDecl>(D)) {
3208 if (isa<NamespaceDecl>(D)) {
3220 const auto *FD = dyn_cast<FunctionDecl>(R.
getFoundDecl());
3222 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion());
3227 bool AcceptInvalidDecl) {
3268 bool AcceptInvalidDecl) {
3269 assert(D &&
"Cannot refer to a NULL declaration");
3270 assert(!isa<FunctionTemplateDecl>(D) &&
3271 "Cannot refer unambiguously to a function template");
3281 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) {
3289 if (!isa<ValueDecl, UnresolvedUsingIfExistsDecl>(D)) {
3290 Diag(Loc, diag::err_ref_non_value) << D << SS.
getRange();
3302 auto *VD = cast<ValueDecl>(D);
3305 if (VD->isInvalidDecl() && !AcceptInvalidDecl)
3312 if (!indirectField->isCXXClassMember())
3324 type =
type.getNonPackExpansionType();
3328 #define ABSTRACT_DECL(kind)
3329 #define VALUE(type, base)
3330 #define DECL(type, base) case Decl::type:
3331 #include "clang/AST/DeclNodes.inc"
3332 llvm_unreachable(
"invalid value decl kind");
3335 case Decl::ObjCAtDefsField:
3336 llvm_unreachable(
"forming non-member reference to ivar?");
3340 case Decl::EnumConstant:
3341 case Decl::UnresolvedUsingValue:
3342 case Decl::OMPDeclareReduction:
3343 case Decl::OMPDeclareMapper:
3352 case Decl::IndirectField:
3353 case Decl::ObjCIvar:
3364 case Decl::NonTypeTemplateParm: {
3366 type = reftype->getPointeeType();
3376 if (
type->isRecordType()) {
3377 type =
type.getUnqualifiedType().withConst();
3390 case Decl::VarTemplateSpecialization:
3391 case Decl::VarTemplatePartialSpecialization:
3392 case Decl::Decomposition:
3393 case Decl::OMPCapturedExpr:
3396 type->isVoidType()) {
3402 case Decl::ImplicitParam:
3403 case Decl::ParmVar: {
3413 if (!CapturedType.
isNull())
3414 type = CapturedType;
3426 case Decl::Function: {
3427 if (
unsigned BID = cast<FunctionDecl>(VD)->getBuiltinID()) {
3456 if (!cast<FunctionDecl>(VD)->hasPrototype() && isa<FunctionProtoType>(fty))
3465 case Decl::CXXDeductionGuide:
3466 llvm_unreachable(
"building reference to deduction guide");
3468 case Decl::MSProperty:
3470 case Decl::TemplateParamObject:
3476 case Decl::UnnamedGlobalConstant:
3480 case Decl::CXXMethod:
3485 dyn_cast<FunctionProtoType>(VD->getType()))
3493 if (cast<CXXMethodDecl>(VD)->isStatic()) {
3499 case Decl::CXXConversion:
3500 case Decl::CXXDestructor:
3501 case Decl::CXXConstructor:
3513 if (VD->isInvalidDecl() && E)
3520 Target.resize(CharByteWidth * (Source.size() + 1));
3521 char *ResultPtr = &
Target[0];
3522 const llvm::UTF8 *ErrorPtr;
3524 llvm::ConvertUTF8toWide(CharByteWidth, Source, ResultPtr, ErrorPtr);
3533 Decl *currentDecl =
nullptr;
3535 currentDecl = BSI->TheDecl;
3537 currentDecl = LSI->CallOperator;
3539 currentDecl = CSI->TheCapturedDecl;
3544 Diag(Loc, diag::ext_predef_outside_function);
3550 if (cast<DeclContext>(currentDecl)->isDependentContext())
3556 unsigned Length = Str.length();
3609 default: llvm_unreachable(
"Unknown simple primary expr!");
3624 bool Invalid =
false;
3625 StringRef ThisTok =
PP.
getSpelling(Tok, CharBuffer, &Invalid);
3664 if (
Literal.getUDSuffix().empty())
3674 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_character_udl));
3695 APFloat::opStatus result =
Literal.GetFloatValue(Val);
3699 if ((result & APFloat::opOverflow) ||
3700 ((result & APFloat::opUnderflow) && Val.isZero())) {
3701 unsigned diagnostic;
3703 if (result & APFloat::opOverflow) {
3704 diagnostic = diag::warn_float_overflow;
3705 APFloat::getLargest(Format).toString(buffer);
3707 diagnostic = diag::warn_float_underflow;
3708 APFloat::getSmallest(Format).toString(buffer);
3711 S.
Diag(Loc, diagnostic)
3713 << StringRef(buffer.data(), buffer.size());
3716 bool isExact = (result == APFloat::opOK);
3721 assert(E &&
"Invalid expression");
3728 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT;
3738 bool ValueIsPositive = ValueAPS.isStrictlyPositive();
3739 if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
3740 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_value)
3741 <<
toString(ValueAPS, 10) << ValueIsPositive;
3761 SpellingBuffer.resize(Tok.
getLength() + 1);
3764 bool Invalid =
false;
3765 StringRef TokSpelling =
PP.
getSpelling(Tok, SpellingBuffer, &Invalid);
3783 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_numeric_udl));
3786 if (
Literal.isFloatingLiteral()) {
3820 if (
Literal.isFloatingLiteral()) {
3824 if (
Literal.GetIntegerValue(ResultVal))
3837 unsigned Length =
Literal.getUDSuffixOffset();
3844 false, StrTy, &TokLoc, 1);
3855 bool CharIsUnsigned =
Context.
CharTy->isUnsignedIntegerType();
3857 for (
unsigned I = 0, N =
Literal.getUDSuffixOffset(); I != N; ++I) {
3858 Value = TokSpelling[I];
3867 llvm_unreachable(
"unexpected literal operator lookup result");
3873 if (
Literal.isFixedPointLiteral()) {
3896 bool isSigned = !
Literal.isUnsigned;
3901 bool Overflowed =
Literal.GetFixedPointValue(Val, scale);
3902 bool ValIsZero = Val.isZero() && !Overflowed;
3905 if (
Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
3911 else if (Val.ugt(MaxVal) || Overflowed)
3916 }
else if (
Literal.isFloatingLiteral()) {
3951 }
else if (!
Literal.isIntegerLiteral()) {
3960 ? diag::warn_cxx20_compat_size_t_suffix
3961 : diag::ext_cxx2b_size_t_suffix
3962 : diag::err_cxx2b_size_t_suffix);
3970 ? diag::warn_c2x_compat_bitint_suffix
3971 : diag::ext_c2x_bitint_suffix);
3980 unsigned BitsNeeded =
3981 Literal.isBitInt ? llvm::APInt::getSufficientBitsNeeded(
3986 if (
Literal.GetIntegerValue(ResultVal)) {
3992 "long long is not intmax_t?");
3999 bool AllowUnsigned =
Literal.isUnsigned ||
Literal.getRadix() != 10;
4005 if (
Literal.MicrosoftInteger) {
4010 Width =
Literal.MicrosoftInteger;
4021 Width =
std::max(ResultVal.getActiveBits(), 1u) +
4022 (
Literal.isUnsigned ? 0u : 1u);
4026 unsigned int MaxBitIntWidth =
4028 if (Width > MaxBitIntWidth) {
4031 Width = MaxBitIntWidth;
4038 ResultVal = ResultVal.zextOrTrunc(Width);
4044 assert(!
Literal.MicrosoftInteger &&
4045 "size_t literals can't be Microsoft literals");
4050 if (ResultVal.isIntN(SizeTSize)) {
4052 if (!
Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
4054 else if (AllowUnsigned)
4066 if (ResultVal.isIntN(IntSize)) {
4068 if (!
Literal.isUnsigned && ResultVal[IntSize-1] == 0)
4070 else if (AllowUnsigned)
4081 if (ResultVal.isIntN(LongSize)) {
4083 if (!
Literal.isUnsigned && ResultVal[LongSize-1] == 0)
4085 else if (AllowUnsigned)
4090 const unsigned LongLongSize =
4095 ? diag::warn_old_implicitly_unsigned_long_cxx
4097 ext_old_implicitly_unsigned_long_cxx
4098 : diag::warn_old_implicitly_unsigned_long)
4099 << (LongLongSize > LongSize ? 0
4112 if (ResultVal.isIntN(LongLongSize)) {
4116 if (!
Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
4119 else if (AllowUnsigned)
4121 Width = LongLongSize;
4127 ? diag::warn_cxx98_compat_longlong
4128 : diag::ext_cxx11_longlong);
4143 diag::ext_integer_literal_too_large_for_signed);
4148 if (ResultVal.getBitWidth() != Width)
4149 ResultVal = ResultVal.trunc(Width);
4165 assert(E &&
"ActOnParenExpr() missing expr");
4181 S.
Diag(Loc, diag::err_vecstep_non_scalar_vector_type)
4187 "Scalar types should always be complete");
4201 (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
4202 TraitKind == UETT_PreferredAlignOf)) {
4204 S.
Diag(Loc, diag::ext_sizeof_alignof_function_type)
4212 unsigned DiagID = S.
LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
4213 : diag::ext_sizeof_alignof_void_type;
4228 S.
Diag(Loc, diag::err_sizeof_nonfragile_interface)
4229 << T << (TraitKind == UETT_SizeOf)
4247 if (!ICE || ICE->
getCastKind() != CK_ArrayToPointerDecay)
4267 bool IsUnevaluatedOperand =
4268 (ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf ||
4269 ExprKind == UETT_PreferredAlignOf || ExprKind == UETT_VecStep);
4270 if (IsUnevaluatedOperand) {
4272 if (Result.isInvalid())
4286 Diag(E->
getExprLoc(), diag::warn_side_effects_unevaluated_context);
4288 if (ExprKind == UETT_VecStep)
4301 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4304 diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4309 E, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4328 if (ExprKind == UETT_SizeOf) {
4330 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
4331 QualType OType = PVD->getOriginalType();
4336 Diag(PVD->getLocation(), diag::note_declared_at);
4389 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4390 ExprKind == UETT_OpenMPRequiredSimdAlign)
4393 if (ExprKind == UETT_VecStep)
4402 OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4407 Diag(OpLoc, diag::err_sizeof_alignof_function_type)
4425 S.
Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield)
4432 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Inner)) {
4434 }
else if (
MemberExpr *ME = dyn_cast<MemberExpr>(Inner)) {
4435 D = ME->getMemberDecl();
4455 if (
FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
4458 if (!FD->getParent()->isCompleteDefinition()) {
4459 S.
Diag(E->
getExprLoc(), diag::err_alignof_member_of_incomplete_type)
4468 if (!FD->getType()->isReferenceType())
4488 assert(CSI !=
nullptr);
4494 #define TYPE(Class, Base)
4495 #define ABSTRACT_TYPE(Class, Base)
4496 #define NON_CANONICAL_TYPE(Class, Base)
4497 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
4498 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
4499 #include "clang/AST/TypeNodes.inc"
4506 case Type::ExtVector:
4507 case Type::ConstantMatrix:
4510 case Type::TemplateSpecialization:
4511 case Type::ObjCObject:
4512 case Type::ObjCInterface:
4513 case Type::ObjCObjectPointer:
4514 case Type::ObjCTypeParam:
4517 llvm_unreachable(
"type class is never variably-modified!");
4518 case Type::Elaborated:
4519 T = cast<ElaboratedType>(Ty)->getNamedType();
4521 case Type::Adjusted:
4522 T = cast<AdjustedType>(Ty)->getOriginalType();
4530 case Type::BlockPointer:
4533 case Type::LValueReference:
4534 case Type::RValueReference:
4537 case Type::MemberPointer:
4540 case Type::ConstantArray:
4541 case Type::IncompleteArray:
4543 T = cast<ArrayType>(Ty)->getElementType();
4545 case Type::VariableArray: {
4553 (isa<CapturedRegionScopeInfo>(CSI) || isa<LambdaScopeInfo>(CSI)))
4559 case Type::FunctionProto:
4560 case Type::FunctionNoProto:
4561 T = cast<FunctionType>(Ty)->getReturnType();
4565 case Type::UnaryTransform:
4566 case Type::Attributed:
4567 case Type::BTFTagAttributed:
4568 case Type::SubstTemplateTypeParm:
4569 case Type::MacroQualified:
4574 T = cast<TypedefType>(Ty)->desugar();
4576 case Type::Decltype:
4577 T = cast<DecltypeType>(Ty)->desugar();
4580 T = cast<UsingType>(Ty)->desugar();
4583 case Type::DeducedTemplateSpecialization:
4584 T = cast<DeducedType>(Ty)->getDeducedType();
4586 case Type::TypeOfExpr:
4587 T = cast<TypeOfExprType>(Ty)->getUnderlyingExpr()->getType();
4590 T = cast<AtomicType>(Ty)->getValueType();
4616 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
4620 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
4621 DC = LSI->CallOperator;
4622 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
4623 DC = CRSI->TheCapturedDecl;
4624 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
4659 }
else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4661 }
else if (ExprKind == UETT_VecStep) {
4663 }
else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
4667 Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0;
4710 if (
V.get()->isTypeDependent())
4722 return CT->getElementType();
4725 if (
V.get()->getType()->isArithmeticType())
4726 return V.get()->getType();
4731 if (PR.
get() !=
V.get()) {
4737 S.
Diag(Loc, diag::err_realimag_invalid_type) <<
V.get()->getType()
4738 << (IsReal ?
"__real" :
"__imag");
4749 default: llvm_unreachable(
"Unknown unary op!");
4750 case tok::plusplus: Opc = UO_PostInc;
break;
4751 case tok::minusminus: Opc = UO_PostDec;
break;
4756 if (Result.isInvalid())
return ExprError();
4757 Input = Result.get();
4770 !S.
LangOpts.ObjCSubscriptingLegacyRuntime)
4773 S.
Diag(opLoc, diag::err_arithmetic_nonfragile_interface)
4780 auto *BaseNoParens =
Base->IgnoreParens();
4781 if (
auto *MSProp = dyn_cast<MSPropertyRefExpr>(BaseNoParens))
4782 return MSProp->getPropertyDecl()->getType()->isArrayType();
4783 return isa<MSPropertySubscriptExpr>(BaseNoParens);
4803 if (RTy->isIntegralOrUnscopedEnumerationType()) {
4805 Result = PT->getPointeeType();
4807 Result = AT->getElementType();
4810 Result = PT->getPointeeType();
4812 Result = AT->getElementType();
4815 return Result->isDependentType() ? Result : Ctx.
DependentTy;
4832 if (isa<ParenListExpr>(base)) {
4836 base = result.
get();
4843 auto CheckAndReportCommaError = [
this, base, rbLoc](
Expr *E) {
4844 if (isa<BinaryOperator>(E) && cast<BinaryOperator>(E)->isCommaOp()) {
4845 Diag(E->getExprLoc(), diag::err_matrix_subscript_comma)
4854 !isa<MatrixSubscriptExpr>(base)) {
4855 Diag(base->
getExprLoc(), diag::err_matrix_separate_incomplete_index)
4861 auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
4862 if (matSubscriptE) {
4863 assert(ArgExprs.size() == 1);
4864 if (CheckAndReportCommaError(ArgExprs.front()))
4867 assert(matSubscriptE->isIncomplete() &&
4868 "base has to be an incomplete matrix subscript");
4870 matSubscriptE->getRowIdx(),
4871 ArgExprs.front(), rbLoc);
4879 bool IsMSPropertySubscript =
false;
4882 if (!IsMSPropertySubscript) {
4886 base = result.
get();
4892 assert(ArgExprs.size() == 1);
4893 if (CheckAndReportCommaError(ArgExprs.front()))
4901 Expr *idx = ArgExprs[0];
4902 if ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) ||
4903 (isa<CXXOperatorCallExpr>(idx) &&
4904 cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma)) {
4910 if (ArgExprs.size() == 1 &&
4911 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) {
4915 ArgExprs[0] = result.
get();
4926 base, ArgExprs.front(),
4939 if (IsMSPropertySubscript) {
4940 assert(ArgExprs.size() == 1);
4958 (ArgExprs.size() != 1 || ArgExprs[0]->getType()->isRecordType())))) {
4965 if (!Res.
isInvalid() && isa<ArraySubscriptExpr>(Res.
get()))
4966 CheckSubscriptAccessOfNoDeref(cast<ArraySubscriptExpr>(Res.
get()));
4990 RowIdx = RowR.
get();
5005 ColumnIdx = ColumnR.
get();
5010 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5011 bool IsColumnIdx) ->
Expr * {
5019 if (std::optional<llvm::APSInt> Idx =
5021 if ((*Idx < 0 || *Idx >= Dim)) {
5023 << IsColumnIdx << Dim;
5031 "should be able to convert any integer type to size type");
5032 return ConvExpr.
get();
5036 RowIdx = IsIndexValid(RowIdx, MTy->
getNumRows(),
false);
5037 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(),
true);
5038 if (!RowIdx || !ColumnIdx)
5042 MTy->getElementType(), RBLoc);
5045 void Sema::CheckAddressOfNoDeref(
const Expr *E) {
5052 while ((Member = dyn_cast<MemberExpr>(StrippedExpr)) && !
Member->isArrow())
5053 StrippedExpr =
Member->getBase()->IgnoreParenImpCasts();
5055 LastRecord.PossibleDerefs.erase(StrippedExpr);
5066 if (isa<ArrayType>(ResultTy))
5069 if (ResultTy->
hasAttr(attr::NoDeref)) {
5070 LastRecord.PossibleDerefs.insert(E);
5078 if (!(isa<ArrayType>(BaseTy) || isa<PointerType>(BaseTy)))
5083 while ((Member = dyn_cast<MemberExpr>(
Base->IgnoreParenCasts())) &&
5087 if (
const auto *Ptr = dyn_cast<PointerType>(
Base->getType())) {
5088 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
5089 LastRecord.PossibleDerefs.insert(E);
5099 if (
Base->hasPlaceholderType() &&
5100 !
Base->hasPlaceholderType(BuiltinType::OMPArraySection)) {
5102 if (Result.isInvalid())
5104 Base = Result.get();
5108 if (Result.isInvalid())
5111 if (Result.isInvalid())
5113 LowerBound = Result.get();
5117 if (Result.isInvalid())
5120 if (Result.isInvalid())
5122 Length = Result.get();
5126 if (Result.isInvalid())
5129 if (Result.isInvalid())
5131 Stride = Result.get();
5135 if (
Base->isTypeDependent() ||
5142 OK_Ordinary, ColonLocFirst, ColonLocSecond, RBLoc);
5154 Diag(
Base->getExprLoc(), diag::err_omp_typecheck_section_value)
5155 <<
Base->getSourceRange());
5161 if (Res.isInvalid())
5163 diag::err_omp_typecheck_section_not_integer)
5165 LowerBound = Res.get();
5175 if (Res.isInvalid())
5177 diag::err_omp_typecheck_section_not_integer)
5191 diag::err_omp_typecheck_section_not_integer)
5206 Diag(
Base->getExprLoc(), diag::err_omp_section_function_type)
5207 << ResultTy <<
Base->getSourceRange();
5212 diag::err_omp_section_incomplete_type,
Base))
5221 if (LowerBoundValue.isNegative()) {
5222 Diag(LowerBound->
getExprLoc(), diag::err_omp_section_not_subset_of_array)
5235 if (LengthValue.isNegative()) {
5236 Diag(Length->
getExprLoc(), diag::err_omp_section_length_negative)
5242 }
else if (ColonLocFirst.
isValid() &&
5248 Diag(ColonLocFirst, diag::err_omp_section_length_undefined)
5259 if (!StrideValue.isStrictlyPositive()) {
5260 Diag(Stride->
getExprLoc(), diag::err_omp_section_stride_non_positive)
5268 if (!
Base->hasPlaceholderType(BuiltinType::OMPArraySection)) {
5270 if (Result.isInvalid())
5272 Base = Result.get();
5276 OK_Ordinary, ColonLocFirst, ColonLocSecond, RBLoc);
5283 if (
Base->hasPlaceholderType()) {
5285 if (Result.isInvalid())
5288 if (Result.isInvalid())
5290 Base = Result.get();
5297 LParenLoc, RParenLoc, Dims, Brackets);
5299 (!
Base->isTypeDependent() &&
5302 diag::err_omp_non_pointer_type_array_shaping_base)
5303 <<
Base->getSourceRange());
5306 bool ErrorFound =
false;
5307 for (
Expr *Dim : Dims) {
5308 if (Dim->hasPlaceholderType()) {
5310 if (Result.isInvalid()) {
5315 if (Result.isInvalid()) {
5321 if (!Dim->isTypeDependent()) {
5324 if (Result.isInvalid()) {
5326 Diag(Dim->getExprLoc(), diag::err_omp_typecheck_shaping_not_integer)
5327 << Dim->getSourceRange();
5332 if (!Dim->isValueDependent() && Dim->EvaluateAsInt(EvResult,
Context)) {
5337 if (!
Value.isStrictlyPositive()) {
5338 Diag(Dim->getExprLoc(), diag::err_omp_shaping_dimension_not_positive)
5340 << Dim->getSourceRange();