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"
60 using namespace clang;
67 if (ParsingInitForAutoVars.count(D))
77 if (getLangOpts().
CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
83 if (TreatUnavailableAsInvalid &&
84 isUnavailableAlignedAllocationFunction(*FD))
93 if (isa<UnresolvedUsingIfExistsDecl>(D))
101 if (
const auto *A = D->
getAttr<UnusedAttr>()) {
104 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
105 A->getSemanticSpelling() != UnusedAttr::C2x_maybe_unused) {
107 if (DC && !DC->
hasAttr<UnusedAttr>())
108 S.
Diag(Loc, diag::warn_used_but_marked_unused) << D;
117 if (
Decl->isDefaulted()) {
124 DiagnoseDeletedDefaultedFunction(
Decl);
128 auto *Ctor = dyn_cast<CXXConstructorDecl>(
Decl);
129 if (Ctor && Ctor->isInheritingConstructor())
130 return NoteDeletedInheritingConstructor(Ctor);
140 if (I->getStorageClass() !=
SC_None)
167 if (!Current->isInlined())
169 if (!Current->isExternallyVisible())
185 if (!DowngradeWarning && UsedFn)
188 S.
Diag(Loc, DowngradeWarning ? diag::ext_internal_in_extern_inline_quiet
189 : diag::ext_internal_in_extern_inline)
194 S.
Diag(D->getCanonicalDecl()->getLocation(), diag::note_entity_declared_at)
204 Diag(DeclBegin, diag::note_convert_inline_to_static)
223 bool ObjCPropertyAccess,
224 bool AvoidPartialAvailabilityChecks,
227 if (getLangOpts().
CPlusPlus && isa<FunctionDecl>(D)) {
231 if (Pos != SuppressedDiagnostics.end()) {
233 Diag(Suppressed.first, Suppressed.second);
244 if (cast<FunctionDecl>(D)->isMain())
245 Diag(Loc, diag::ext_main_used);
247 diagnoseUnavailableAlignedAllocation(*cast<FunctionDecl>(D), Loc);
251 if (ParsingInitForAutoVars.count(D)) {
252 if (isa<BindingDecl>(D)) {
253 Diag(Loc, diag::err_binding_cannot_appear_in_own_initializer)
256 Diag(Loc, diag::err_auto_variable_cannot_appear_in_own_initializer)
257 << D->
getDeclName() << cast<VarDecl>(D)->getType();
264 if (FD->isDeleted()) {
265 auto *Ctor = dyn_cast<CXXConstructorDecl>(FD);
266 if (Ctor && Ctor->isInheritingConstructor())
267 Diag(Loc, diag::err_deleted_inherited_ctor_use)
269 << Ctor->getInheritedConstructor().getConstructor()->getParent();
271 Diag(Loc, diag::err_deleted_function_use);
272 NoteDeletedFunction(FD);
284 if (FD->getTrailingRequiresClause()) {
286 if (CheckFunctionConstraints(FD, Satisfaction, Loc))
292 diag::err_reference_to_function_with_unsatisfied_constraints)
294 DiagnoseUnsatisfiedConstraint(Satisfaction);
301 if (getLangOpts().
CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
302 DeduceReturnType(FD, Loc))
305 if (getLangOpts().
CUDA && !CheckCUDACall(Loc, FD))
308 if (getLangOpts().SYCLIsDevice && !checkSYCLDeviceFunction(Loc, FD))
312 if (
auto *MD = dyn_cast<CXXMethodDecl>(D)) {
314 if (MD->getParent()->isLambda() &&
315 ((isa<CXXConstructorDecl>(MD) &&
316 cast<CXXConstructorDecl>(MD)->isDefaultConstructor()) ||
317 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) {
318 Diag(Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign)
319 << !isa<CXXConstructorDecl>(MD);
323 auto getReferencedObjCProp = [](
const NamedDecl *D) ->
325 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
330 if (diagnoseArgIndependentDiagnoseIfAttrs(ObjCPDecl, Loc))
332 }
else if (diagnoseArgIndependentDiagnoseIfAttrs(D, Loc)) {
340 auto *DRD = dyn_cast<OMPDeclareReductionDecl>(CurContext);
341 if (LangOpts.OpenMP && DRD && !CurContext->containsDecl(D) &&
343 Diag(Loc, diag::err_omp_wrong_var_in_declare_reduction)
344 << getCurFunction()->HasOMPDeclareReductionCombiner;
353 if (LangOpts.OpenMP && isa<VarDecl>(D) &&
354 !isOpenMPDeclareMapperVarDeclAllowed(cast<VarDecl>(D))) {
355 Diag(Loc, diag::err_omp_declare_mapper_wrong_var)
356 << getOpenMPDeclareMapperVarName();
361 if (
const auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(D)) {
362 Diag(Loc, diag::err_use_of_empty_using_if_exists);
363 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here);
367 DiagnoseAvailabilityOfDecl(D, Locs, UnknownObjCClass, ObjCPropertyAccess,
368 AvoidPartialAvailabilityChecks, ClassReceiver);
374 if (
auto *VD = dyn_cast<ValueDecl>(D))
375 checkTypeSupport(VD->getType(), Loc, VD);
377 if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice)) {
379 if (
const auto *VD = dyn_cast<VarDecl>(D))
381 targetDiag(*Locs.begin(), diag::err_thread_unsupported);
384 if (isa<ParmVarDecl>(D) && isa<RequiresExprBodyDecl>(D->
getDeclContext()) &&
385 !isUnevaluatedContext()) {
389 Diag(Loc, diag::err_requires_expr_parameter_referenced_in_evaluated_context)
404 const SentinelAttr *
attr = D->
getAttr<SentinelAttr>();
409 unsigned numFormalParams;
413 enum CalleeType { CT_Function, CT_Method, CT_Block } calleeType;
416 numFormalParams = MD->param_size();
417 calleeType = CT_Method;
418 }
else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
419 numFormalParams = FD->param_size();
420 calleeType = CT_Function;
421 }
else if (isa<VarDecl>(D)) {
427 calleeType = CT_Function;
430 calleeType = CT_Block;
436 numFormalParams = proto->getNumParams();
448 unsigned nullPos =
attr->getNullPos();
449 assert((nullPos == 0 || nullPos == 1) &&
"invalid null position on sentinel");
450 numFormalParams = (nullPos > numFormalParams ? 0 : numFormalParams - nullPos);
453 unsigned numArgsAfterSentinel =
attr->getSentinel();
457 if (Args.size() < numFormalParams + numArgsAfterSentinel + 1) {
464 Expr *sentinelExpr = Args[Args.size() - numArgsAfterSentinel - 1];
465 if (!sentinelExpr)
return;
475 if (calleeType == CT_Method && PP.isMacroDefined(
"nil"))
478 NullValue =
"nullptr";
479 else if (PP.isMacroDefined(
"NULL"))
482 NullValue =
"(void*) 0";
485 Diag(Loc, diag::warn_missing_sentinel) <<
int(calleeType);
487 Diag(MissingNilLoc, diag::warn_missing_sentinel)
511 assert(!Ty.
isNull() &&
"DefaultFunctionArrayConversion - missing type");
515 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
520 CK_FunctionToPointerDecay).get();
535 CK_ArrayToPointerDecay);
551 if (UO && UO->getOpcode() == UO_Deref &&
552 UO->getSubExpr()->getType()->isPointerType()) {
554 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
557 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
559 !UO->getType().isVolatileQualified()) {
561 S.
PDiag(diag::warn_indirection_through_null)
562 << UO->getSubExpr()->getSourceRange());
564 S.
PDiag(diag::note_indirection_through_null));
596 if (ObjectSetClass) {
640 assert(!T.
isNull() &&
"r-value conversion on typeless expression?");
663 if (getLangOpts().
OpenCL &&
664 !getOpenCLOptions().isAvailableOption(
"cl_khr_fp16", getLangOpts()) &&
673 NamedDecl *ObjectGetClass = LookupSingleName(TUScope,
680 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()),
")");
705 ExprResult Res = CheckLValueToRValueConversionOperand(E);
713 Cleanup.setExprNeedsCleanups(
true);
716 Cleanup.setExprNeedsCleanups(
true);
722 CurFPFeatureOverrides());
728 T = Atomic->getValueType().getUnqualifiedType();
737 ExprResult Res = DefaultFunctionArrayConversion(E, Diagnose);
740 Res = DefaultLvalueConversion(Res.
get());
755 CK_FunctionToPointerDecay);
759 Res = DefaultLvalueConversion(Res.
get());
772 ExprResult Res = DefaultFunctionArrayLvalueConversion(E);
778 assert(!Ty.
isNull() &&
"UsualUnaryConversions - missing type");
782 (getLangOpts().getFPEvalMethod() !=
783 LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine ||
784 PP.getLastFPEvalPragmaLocation().isValid())) {
785 switch (EvalMethod) {
787 llvm_unreachable(
"Unrecognized float evaluation method");
790 llvm_unreachable(
"Float evaluation method should be set by now");
796 ? ImpCastExprToType(E,
798 CK_FloatingComplexCast)
799 : ImpCastExprToType(E, Context.
DoubleTy, CK_FloatingCast);
807 CK_FloatingComplexCast)
815 if (Ty->
isHalfType() && !getLangOpts().NativeHalfType)
816 return ImpCastExprToType(Res.
get(), Context.
FloatTy, CK_FloatingCast);
837 E = ImpCastExprToType(E, PTy, CK_IntegralCast).get();
842 E = ImpCastExprToType(E, PT, CK_IntegralCast).get();
855 assert(!Ty.
isNull() &&
"DefaultArgumentPromotion - missing type");
867 if (BTy && (BTy->
getKind() == BuiltinType::Half ||
869 if (getLangOpts().OpenCL &&
870 !getOpenCLOptions().isAvailableOption(
"cl_khr_fp64", getLangOpts())) {
871 if (BTy->
getKind() == BuiltinType::Half) {
872 E = ImpCastExprToType(E, Context.
FloatTy, CK_FloatingCast).get();
875 E = ImpCastExprToType(E, Context.
DoubleTy, CK_FloatingCast).get();
879 getLangOpts().getExtendIntArgs() ==
887 : ImpCastExprToType(E, Context.
LongLongTy, CK_IntegralCast).get();
889 "Unexpected typesize for LongLongTy");
949 if (!Record->hasNonTrivialCopyConstructor() &&
950 !Record->hasNonTrivialMoveConstructor() &&
951 !Record->hasNonTrivialDestructor())
952 return VAK_ValidInCXX11;
960 if (getLangOpts().MSVCCompat)
961 return VAK_MSVCUndefined;
965 return VAK_Undefined;
975 case VAK_ValidInCXX11:
978 PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
985 PDiag(diag::warn_pass_class_arg_to_vararg)
986 << Ty << CT << hasCStrMethod(E) <<
".c_str()");
991 case VAK_MSVCUndefined:
993 PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
1000 diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
1004 PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
1008 << isa<InitListExpr>(E) << Ty << CT;
1019 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast &&
1020 (CT == VariadicMethod ||
1021 (FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>()))) {
1022 E = stripARCUnbridgedCast(E);
1026 ExprResult ExprRes = CheckPlaceholderExpr(E);
1033 ExprResult ExprRes = DefaultArgumentPromotion(E);
1039 maybeExtendBlockObject(ExprRes);
1045 if (isValidVarArgType(E->
getType()) == VAK_Undefined) {
1050 Name.setIdentifier(PP.getIdentifierInfo(
"__builtin_trap"),
1052 ExprResult TrapFn = ActOnIdExpression(TUScope, SS, TemplateKWLoc, Name,
1060 if (Call.isInvalid())
1064 ActOnBinOp(TUScope, E->
getBeginLoc(), tok::comma, Call.get(), E);
1065 if (Comma.isInvalid())
1072 diag::err_call_incomplete_argument))
1089 if (SkipCast)
return false;
1091 QualType fpTy = cast<ComplexType>(ComplexTy)->getElementType();
1094 CK_FloatingRealToComplex);
1098 CK_IntegralComplexToFloatingComplex);
1108 bool IsCompAssign) {
1131 auto *LHSComplexType = dyn_cast<ComplexType>(LHSType);
1132 auto *RHSComplexType = dyn_cast<ComplexType>(RHSType);
1134 LHSComplexType ? LHSComplexType->getElementType() : LHSType;
1136 RHSComplexType ? RHSComplexType->getElementType() : RHSType;
1142 if (!IsCompAssign) {
1149 }
else if (Order > 0) {
1164 bool ConvertFloat,
bool ConvertInt) {
1169 CK_IntegralToFloating);
1180 CK_IntegralComplexToFloatingComplex);
1185 CK_FloatingRealToComplex);
1194 QualType RHSType,
bool IsCompAssign) {
1204 else if (!IsCompAssign)
1206 return LHSFloat ? LHSType : RHSType;
1211 if (LHSFloat && RHSFloat) {
1218 assert(order < 0 &&
"illegal float comparison");
1252 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType;
1258 if ((&LHSSem != &llvm::APFloat::PPCDoubleDouble() ||
1259 &RHSSem != &llvm::APFloat::IEEEquad()) &&
1260 (&LHSSem != &llvm::APFloat::IEEEquad() ||
1261 &RHSSem != &llvm::APFloat::PPCDoubleDouble()))
1278 CK_IntegralComplexCast);
1284 template <PerformCastFn doLHSCast, PerformCastFn doRHSCast>
1287 QualType RHSType,
bool IsCompAssign) {
1292 if (LHSSigned == RHSSigned) {
1295 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1297 }
else if (!IsCompAssign)
1298 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1300 }
else if (order != (LHSSigned ? 1 : -1)) {
1304 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1306 }
else if (!IsCompAssign)
1307 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1314 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1316 }
else if (!IsCompAssign)
1317 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1326 RHS = (*doRHSCast)(S, RHS.
get(), result);
1328 LHS = (*doLHSCast)(S, LHS.
get(), result);
1338 bool IsCompAssign) {
1342 if (LHSComplexInt && RHSComplexInt) {
1346 handleIntegerConversion<doComplexIntegralCast, doComplexIntegralCast>
1347 (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign);
1352 if (LHSComplexInt) {
1355 handleIntegerConversion<doComplexIntegralCast, doIntegralCast>
1356 (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign);
1359 CK_IntegralRealToComplex);
1364 assert(RHSComplexInt);
1368 handleIntegerConversion<doIntegralCast, doComplexIntegralCast>
1369 (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign);
1374 CK_IntegralRealToComplex);
1383 assert(BTy &&
"Expected a builtin type.");
1385 switch (BTy->getKind()) {
1386 case BuiltinType::ShortFract:
1387 case BuiltinType::UShortFract:
1388 case BuiltinType::SatShortFract:
1389 case BuiltinType::SatUShortFract:
1391 case BuiltinType::Fract:
1392 case BuiltinType::UFract:
1393 case BuiltinType::SatFract:
1394 case BuiltinType::SatUFract:
1396 case BuiltinType::LongFract:
1397 case BuiltinType::ULongFract:
1398 case BuiltinType::SatLongFract:
1399 case BuiltinType::SatULongFract:
1401 case BuiltinType::ShortAccum:
1402 case BuiltinType::UShortAccum:
1403 case BuiltinType::SatShortAccum:
1404 case BuiltinType::SatUShortAccum:
1406 case BuiltinType::Accum:
1407 case BuiltinType::UAccum:
1408 case BuiltinType::SatAccum:
1409 case BuiltinType::SatUAccum:
1411 case BuiltinType::LongAccum:
1412 case BuiltinType::ULongAccum:
1413 case BuiltinType::SatLongAccum:
1414 case BuiltinType::SatULongAccum:
1417 if (BTy->isInteger())
1419 llvm_unreachable(
"Unexpected fixed point or integer type");
1431 "Expected at least one of the operands to be a fixed point type");
1434 "Special fixed point arithmetic operation conversions are only "
1435 "applied to ints or other fixed point types");
1457 QualType ResultTy = LHSTyRank > RHSTyRank ? LHSTy : RHSTy;
1479 REnum = R->isUnscopedEnumerationType();
1481 if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
1484 ? diag::warn_arith_conv_enum_float_cxx20
1485 : diag::warn_arith_conv_enum_float)
1487 << (
int)ACK << LEnum << L << R;
1488 }
else if (!IsCompAssign && LEnum && REnum &&
1492 !R->castAs<
EnumType>()->getDecl()->hasNameForLinkage()) {
1497 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
1498 : diag::warn_arith_conv_mixed_anon_enum_types;
1503 ? diag::warn_conditional_mixed_enum_types_cxx20
1504 : diag::warn_conditional_mixed_enum_types;
1509 ? diag::warn_comparison_mixed_enum_types_cxx20
1510 : diag::warn_comparison_mixed_enum_types;
1513 ? diag::warn_arith_conv_mixed_enum_types_cxx20
1514 : diag::warn_arith_conv_mixed_enum_types;
1517 << (
int)ACK << L << R;
1530 if (ACK != ACK_CompAssign) {
1531 LHS = UsualUnaryConversions(LHS.
get());
1536 RHS = UsualUnaryConversions(RHS.
get());
1549 LHSType = AtomicLHS->getValueType();
1552 if (LHSType == RHSType)
1561 QualType LHSUnpromotedType = LHSType;
1565 if (!LHSBitfieldPromoteTy.
isNull())
1566 LHSType = LHSBitfieldPromoteTy;
1567 if (LHSType != LHSUnpromotedType && ACK != ACK_CompAssign)
1568 LHS = ImpCastExprToType(LHS.
get(), LHSType, CK_IntegralCast);
1571 if (LHSType == RHSType)
1584 ACK == ACK_CompAssign);
1589 ACK == ACK_CompAssign);
1594 ACK == ACK_CompAssign);
1600 return handleIntegerConversion<doIntegralCast, doIntegralCast>
1601 (*
this, LHS, RHS, LHSType, RHSType, ACK == ACK_CompAssign);
1613 Expr *ControllingExpr,
1616 unsigned NumAssocs = ArgTypes.size();
1617 assert(NumAssocs == ArgExprs.size());
1620 for (
unsigned i = 0; i < NumAssocs; ++i) {
1622 (void) GetTypeFromParser(ArgTypes[i], &Types[i]);
1627 ExprResult ER = CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1629 llvm::makeArrayRef(Types, NumAssocs),
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, None, StringTokLocs.back(),
1971 case LOLR_StringTemplatePack: {
1982 for (
unsigned I = 0, N = Lit->
getLength(); I != N; ++I) {
1988 return BuildLiteralOperatorCall(R, OpNameInfo, None, StringTokLocs.back(),
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 =
2087 NeedToCaptureVariable(cast<VarDecl>(D), NameInfo.
getLoc());
2090 Context, NNS, TemplateKWLoc, D, RefersToCapturedVariable, NameInfo, Ty,
2091 VK, FoundD, TemplateArgs, getNonOdrUseReasonInCurrentContext(D));
2092 MarkDeclRefReferenced(E);
2108 if (
auto *NewFPT = ResolveExceptionSpec(NameInfo.
getLoc(), FPT))
2113 if (getLangOpts().ObjCWeak && isa<VarDecl>(D) &&
2115 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->
getBeginLoc()))
2116 getCurFunction()->recordUseOfWeak(E);
2120 FD = IFD->getAnonField();
2122 UnusedPrivateFields.remove(FD);
2130 if (
auto *BD = dyn_cast<BindingDecl>(D))
2131 if (
auto *BE = BD->getBinding())
2156 Id.TemplateId->NumArgs);
2157 translateTemplateArguments(TemplateArgsPtr, Buffer);
2162 TemplateArgs = &Buffer;
2164 NameInfo = GetNameFromUnqualifiedId(
Id);
2165 TemplateArgs =
nullptr;
2172 unsigned DiagnosticID,
unsigned DiagnosticSuggestID) {
2179 SemaRef.
Diag(TypoLoc, diag::err_no_member) << Typo << Ctx
2182 SemaRef.
Diag(TypoLoc, DiagnosticID) << Typo;
2187 bool DroppedSpecifier =
2190 ? diag::note_implicit_param_decl
2191 : diag::note_previous_decl;
2194 SemaRef.
PDiag(NoteID));
2197 << Typo << Ctx << DroppedSpecifier
2199 SemaRef.
PDiag(NoteID));
2214 bool isDefaultArgument =
2215 !CodeSynthesisContexts.empty() &&
2216 CodeSynthesisContexts.back().Kind ==
2217 CodeSynthesisContext::DefaultFunctionArgumentInstantiation;
2218 CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext);
2219 bool isInstance = CurMethod && CurMethod->
isInstance() &&
2228 unsigned DiagID = diag::err_found_in_dependent_base;
2229 unsigned NoteID = diag::note_member_declared_at;
2231 DiagID = getLangOpts().MSVCCompat ? diag::ext_found_later_in_class
2232 : diag::err_found_later_in_class;
2233 }
else if (getLangOpts().MSVCCompat) {
2234 DiagID = diag::ext_found_in_dependent_base;
2235 NoteID = diag::note_dependent_member_use;
2251 Diag(D->getLocation(), NoteID);
2260 if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) {
2261 Diag(R.getNameLoc(), diag::err_member_call_without_object);
2278 unsigned diagnostic = diag::err_undeclared_var_use;
2279 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
2283 diagnostic = diag::err_undeclared_use;
2284 diagnostic_suggest = diag::err_undeclared_use_suggest;
2293 if (isa<CXXRecordDecl>(DC)) {
2294 LookupQualifiedName(R, DC);
2304 AddOverloadedCallCandidates(R, ExplicitTemplateArgs, Args, Candidates);
2309 R.
addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
2313 return DiagnoseDependentMemberLookup(R);
2326 assert(!ExplicitTemplateArgs &&
2327 "Diagnosing an empty lookup with explicit template args!");
2328 *Out = CorrectTypoDelayed(
2331 emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args,
2332 diagnostic, diagnostic_suggest);
2334 nullptr, CTK_ErrorRecovery);
2339 S, &SS, CCC, CTK_ErrorRecovery))) {
2341 bool DroppedSpecifier =
2345 bool AcceptableWithRecovery =
false;
2346 bool AcceptableWithoutRecovery =
false;
2355 dyn_cast<FunctionTemplateDecl>(CD))
2356 AddTemplateOverloadCandidate(
2359 else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(CD))
2360 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->
size() == 0)
2366 ND = Best->FoundDecl;
2367 Corrected.setCorrectionDecl(ND);
2371 Corrected.setCorrectionDecl(ND);
2383 Record = cast<CXXRecordDecl>(
2389 AcceptableWithRecovery = isa<ValueDecl>(UnderlyingND) ||
2390 isa<FunctionTemplateDecl>(UnderlyingND);
2396 AcceptableWithoutRecovery = isa<TypeDecl>(UnderlyingND) ||
2398 isa<ObjCInterfaceDecl>(UnderlyingND);
2402 AcceptableWithoutRecovery =
true;
2405 if (AcceptableWithRecovery || AcceptableWithoutRecovery) {
2407 ? diag::note_implicit_param_decl
2408 : diag::note_previous_decl;
2410 diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name,
2411 PDiag(NoteID), AcceptableWithRecovery);
2413 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
2414 << Name << computeDeclContext(SS,
false)
2415 << DroppedSpecifier << SS.
getRange(),
2416 PDiag(NoteID), AcceptableWithRecovery);
2419 return !AcceptableWithRecovery;
2428 << Name << computeDeclContext(SS,
false)
2455 else if (
auto *MD = dyn_cast<CXXMethodDecl>(S.
CurContext))
2463 auto DB = S.
Diag(Loc, diag::ext_undeclared_unqual_id_with_dependent_base);
2464 DB << NameInfo.
getName() << RD;
2466 if (!ThisType.
isNull()) {
2469 Context,
nullptr, ThisType,
true,
2471 nullptr, NameInfo, TemplateArgs);
2488 bool HasTrailingLParen,
bool IsAddressOfOperand,
2490 bool IsInlineAsmIdentifier,
Token *KeywordReplacement) {
2491 assert(!(IsAddressOfOperand && HasTrailingLParen) &&
2492 "cannot be direct & operand and have a trailing lparen");
2501 DecomposeUnqualifiedId(
Id, TemplateArgsBuffer, NameInfo, TemplateArgs);
2524 bool DependentID =
false;
2526 Name.getCXXNameType()->isDependentType()) {
2528 }
else if (SS.
isSet()) {
2529 if (
DeclContext *DC = computeDeclContext(SS,
false)) {
2530 if (RequireCompleteDeclContext(SS, DC))
2538 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2539 IsAddressOfOperand, TemplateArgs);
2544 ? LookupObjCImplicitSelfParam
2545 : LookupOrdinaryName);
2546 if (TemplateKWLoc.
isValid() || TemplateArgs) {
2552 bool MemberOfUnknownSpecialization;
2554 if (LookupTemplateName(R, S, SS,
QualType(),
false,
2555 MemberOfUnknownSpecialization, TemplateKWLoc,
2559 if (MemberOfUnknownSpecialization ||
2561 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2562 IsAddressOfOperand, TemplateArgs);
2564 bool IvarLookupFollowUp = II && !SS.
isSet() && getCurMethodDecl();
2565 LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
2570 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2571 IsAddressOfOperand, TemplateArgs);
2575 if (IvarLookupFollowUp) {
2576 ExprResult E(LookupInObjCMethod(R, S, II,
true));
2590 if (R.
empty() && HasTrailingLParen && II &&
2591 getLangOpts().implicitFunctionsAllowed()) {
2592 NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *II, S);
2598 bool ADL = UseArgumentDependentLookup(SS, R, HasTrailingLParen);
2600 if (R.
empty() && !ADL) {
2601 if (SS.
isEmpty() && getLangOpts().MSVCCompat) {
2603 TemplateKWLoc, TemplateArgs))
2608 if (IsInlineAsmIdentifier)
2618 "Typo correction callback misconfigured");
2628 if (DiagnoseEmptyLookup(S, SS, R, CCC ? *CCC : DefaultValidator,
nullptr,
2630 if (TE && KeywordReplacement) {
2631 auto &
State = getTypoExprState(TE);
2632 auto BestTC =
State.Consumer->getNextCorrection();
2633 if (BestTC.isKeyword()) {
2634 auto *II = BestTC.getCorrectionAsIdentifierInfo();
2635 if (
State.DiagHandler)
2636 State.DiagHandler(BestTC);
2640 KeywordReplacement->
setLocation(BestTC.getCorrectionRange().getBegin());
2643 clearDelayedTypo(TE);
2646 return (
Expr*)
nullptr;
2648 State.Consumer->resetCorrectionStream();
2653 assert(!R.
empty() &&
2654 "DiagnoseEmptyLookup returned false but added no results");
2661 ExprResult E(LookupInObjCMethod(R, S, Ivar->getIdentifier()));
2671 assert(!R.
empty() || ADL);
2697 if (!R.
empty() && (*R.
begin())->isCXXClassMember()) {
2698 bool MightBeImplicitMember;
2699 if (!IsAddressOfOperand)
2700 MightBeImplicitMember =
true;
2702 MightBeImplicitMember =
false;
2704 MightBeImplicitMember =
false;
2706 MightBeImplicitMember =
true;
2708 MightBeImplicitMember = isa<FieldDecl>(R.
getFoundDecl()) ||
2712 if (MightBeImplicitMember)
2713 return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc,
2714 R, TemplateArgs, S);
2717 if (TemplateArgs || TemplateKWLoc.
isValid()) {
2725 "There should only be one declaration found.");
2728 return BuildTemplateIdExpr(SS, TemplateKWLoc, R, ADL, TemplateArgs);
2731 return BuildDeclarationNameExpr(SS, R, ADL);
2746 if (RequireCompleteDeclContext(SS, DC))
2750 LookupQualifiedName(R, DC);
2764 if (
const auto *CD = dyn_cast<CXXRecordDecl>(DC))
2765 if (CD->isInvalidDecl())
2776 unsigned DiagID = diag::err_typename_missing;
2777 if (RecoveryTSI && getLangOpts().MSVCCompat)
2778 DiagID = diag::ext_typename_missing;
2780 auto D =
Diag(Loc, DiagID);
2811 if (!R.
empty() && (*R.
begin())->isCXXClassMember() && !IsAddressOfOperand)
2812 return BuildPossibleImplicitMemberExpr(SS,
2816 return BuildDeclarationNameExpr(SS, R,
false);
2847 LookForIvars =
true;
2848 else if (IsClassMethod)
2849 LookForIvars =
false;
2860 if (IsClassMethod) {
2868 !getLangOpts().DebuggerSupport)
2881 Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
2889 Diag(Loc, diag::err_ivar_use_in_class_method) << IV->getDeclName();
2902 "should not reference ivar from this context");
2905 assert(IFace &&
"should not reference ivar from this context");
2913 if (DiagnoseUseOfDecl(IV, Loc))
2924 ActOnIdExpression(S, SelfScopeSpec, TemplateKWLoc, SelfName,
2930 SelfExpr = DefaultLvalueConversion(SelfExpr.
get());
2934 MarkAnyDeclReferenced(Loc, IV,
true);
2938 !IvarBacksCurrentMethodAccessor(IFace, CurMethod, IV))
2946 if (!isUnevaluatedContext() &&
2947 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, Loc))
2948 getCurFunction()->recordUseOfWeak(Result);
2950 if (getLangOpts().ObjCAutoRefCount)
2952 ImplicitlyRetainedSelfLocs.push_back({Loc, BD});
2970 cast<ObjCIvarDecl>(Ivar.
get()));
2972 if (Lookup.
empty() && II && AllowBuiltinCreation)
3012 bool PointerConversions =
false;
3013 if (isa<FieldDecl>(
Member)) {
3017 DestRecordType, FromPtrType
3024 PointerConversions =
true;
3026 DestType = DestRecordType;
3027 FromRecordType = FromType;
3030 if (Method->isStatic())
3033 DestType = Method->getThisType();
3038 PointerConversions =
true;
3040 FromRecordType = FromType;
3041 DestType = DestRecordType;
3046 if (FromAS != DestAS) {
3051 if (PointerConversions)
3092 if (Qualifier && Qualifier->getAsType()) {
3094 assert(QType->
isRecordType() &&
"lookup done with non-record type");
3104 FromLoc, FromRange, &BasePath))
3107 if (PointerConversions)
3110 VK, &BasePath).
get();
3113 FromRecordType = QRecordType;
3124 FromLoc, FromRange, &BasePath,
3134 bool HasTrailingLParen) {
3136 if (!HasTrailingLParen)
3154 if (D->isCXXClassMember())
3163 if (isa<UsingShadowDecl>(D))
3164 D = cast<UsingShadowDecl>(D)->getTargetDecl();
3165 else if (D->getLexicalDeclContext()->isFunctionOrMethod())
3172 if (isa<FunctionDecl>(D)) {
3178 }
else if (!isa<FunctionTemplateDecl>(D))
3194 if (isa<TypedefNameDecl>(D)) {
3199 if (isa<ObjCInterfaceDecl>(D)) {
3204 if (isa<NamespaceDecl>(D)) {
3216 const auto *FD = dyn_cast<FunctionDecl>(R.
getFoundDecl());
3218 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion());
3223 bool AcceptInvalidDecl) {
3262 bool AcceptInvalidDecl) {
3263 assert(D &&
"Cannot refer to a NULL declaration");
3264 assert(!isa<FunctionTemplateDecl>(D) &&
3265 "Cannot refer unambiguously to a function template");
3275 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) {
3283 if (!isa<ValueDecl, UnresolvedUsingIfExistsDecl>(D)) {
3284 Diag(Loc, diag::err_ref_non_value) << D << SS.
getRange();
3296 auto *VD = cast<ValueDecl>(D);
3299 if (VD->isInvalidDecl() && !AcceptInvalidDecl)
3306 if (!indirectField->isCXXClassMember())
3318 type =
type.getNonPackExpansionType();
3322 #define ABSTRACT_DECL(kind)
3323 #define VALUE(type, base)
3324 #define DECL(type, base) case Decl::type:
3325 #include "clang/AST/DeclNodes.inc"
3326 llvm_unreachable(
"invalid value decl kind");
3329 case Decl::ObjCAtDefsField:
3330 llvm_unreachable(
"forming non-member reference to ivar?");
3334 case Decl::EnumConstant:
3335 case Decl::UnresolvedUsingValue:
3336 case Decl::OMPDeclareReduction:
3337 case Decl::OMPDeclareMapper:
3346 case Decl::IndirectField:
3347 case Decl::ObjCIvar:
3358 case Decl::NonTypeTemplateParm: {
3360 type = reftype->getPointeeType();
3370 if (
type->isRecordType()) {
3371 type =
type.getUnqualifiedType().withConst();
3384 case Decl::VarTemplateSpecialization:
3385 case Decl::VarTemplatePartialSpecialization:
3386 case Decl::Decomposition:
3387 case Decl::OMPCapturedExpr:
3390 type->isVoidType()) {
3396 case Decl::ImplicitParam:
3397 case Decl::ParmVar: {
3407 if (!CapturedType.
isNull())
3408 type = CapturedType;
3414 case Decl::Binding: {
3420 auto *BD = cast<BindingDecl>(VD);
3422 auto *DD = dyn_cast_or_null<VarDecl>(BD->getDecomposedDecl());
3423 if (DD && DD->hasLocalStorage())
3429 case Decl::Function: {
3430 if (
unsigned BID = cast<FunctionDecl>(VD)->getBuiltinID()) {
3459 if (!cast<FunctionDecl>(VD)->hasPrototype() && isa<FunctionProtoType>(fty))
3468 case Decl::CXXDeductionGuide:
3469 llvm_unreachable(
"building reference to deduction guide");
3471 case Decl::MSProperty:
3473 case Decl::TemplateParamObject:
3479 case Decl::UnnamedGlobalConstant:
3483 case Decl::CXXMethod:
3488 dyn_cast<FunctionProtoType>(VD->getType()))
3496 if (cast<CXXMethodDecl>(VD)->isStatic()) {
3502 case Decl::CXXConversion:
3503 case Decl::CXXDestructor:
3504 case Decl::CXXConstructor:
3516 Target.resize(CharByteWidth * (Source.size() + 1));
3517 char *ResultPtr = &
Target[0];
3518 const llvm::UTF8 *ErrorPtr;
3520 llvm::ConvertUTF8toWide(CharByteWidth, Source, ResultPtr, ErrorPtr);
3529 Decl *currentDecl =
nullptr;
3531 currentDecl = BSI->TheDecl;
3533 currentDecl = LSI->CallOperator;
3535 currentDecl = CSI->TheCapturedDecl;
3540 Diag(Loc, diag::ext_predef_outside_function);
3546 if (cast<DeclContext>(currentDecl)->isDependentContext())
3552 unsigned Length = Str.length();
3605 default: llvm_unreachable(
"Unknown simple primary expr!");
3620 bool Invalid =
false;
3621 StringRef ThisTok =
PP.
getSpelling(Tok, CharBuffer, &Invalid);
3660 if (
Literal.getUDSuffix().empty())
3670 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_character_udl));
3688 using llvm::APFloat;
3689 APFloat Val(Format);
3691 APFloat::opStatus result =
Literal.GetFloatValue(Val);
3695 if ((result & APFloat::opOverflow) ||
3696 ((result & APFloat::opUnderflow) && Val.isZero())) {
3697 unsigned diagnostic;
3699 if (result & APFloat::opOverflow) {
3700 diagnostic = diag::warn_float_overflow;
3701 APFloat::getLargest(Format).toString(buffer);
3703 diagnostic = diag::warn_float_underflow;
3704 APFloat::getSmallest(Format).toString(buffer);
3707 S.
Diag(Loc, diagnostic)
3709 << StringRef(buffer.data(), buffer.size());
3712 bool isExact = (result == APFloat::opOK);
3717 assert(E &&
"Invalid expression");
3724 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT;
3734 bool ValueIsPositive = ValueAPS.isStrictlyPositive();
3735 if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
3736 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_value)
3737 <<
toString(ValueAPS, 10) << ValueIsPositive;
3757 SpellingBuffer.resize(Tok.
getLength() + 1);
3760 bool Invalid =
false;
3761 StringRef TokSpelling =
PP.
getSpelling(Tok, SpellingBuffer, &Invalid);
3779 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_numeric_udl));
3782 if (
Literal.isFloatingLiteral()) {
3816 if (
Literal.isFloatingLiteral()) {
3820 if (
Literal.GetIntegerValue(ResultVal))
3833 unsigned Length =
Literal.getUDSuffixOffset();
3839 false, StrTy, &TokLoc, 1);
3850 bool CharIsUnsigned =
Context.
CharTy->isUnsignedIntegerType();
3852 for (
unsigned I = 0, N =
Literal.getUDSuffixOffset(); I != N; ++I) {
3853 Value = TokSpelling[I];
3862 llvm_unreachable(
"unexpected literal operator lookup result");
3868 if (
Literal.isFixedPointLiteral()) {
3891 bool isSigned = !
Literal.isUnsigned;
3896 bool Overflowed =
Literal.GetFixedPointValue(Val, scale);
3897 bool ValIsZero = Val.isZero() && !Overflowed;
3900 if (
Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
3906 else if (Val.ugt(MaxVal) || Overflowed)
3911 }
else if (
Literal.isFloatingLiteral()) {
3946 }
else if (!
Literal.isIntegerLiteral()) {
3956 diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
3965 ? diag::warn_cxx20_compat_size_t_suffix
3966 : diag::ext_cxx2b_size_t_suffix
3967 : diag::err_cxx2b_size_t_suffix);
3975 ? diag::warn_c2x_compat_bitint_suffix
3976 : diag::ext_c2x_bitint_suffix);
3985 unsigned BitsNeeded =
3986 Literal.isBitInt ? llvm::APInt::getSufficientBitsNeeded(
3991 if (
Literal.GetIntegerValue(ResultVal)) {
3997 "long long is not intmax_t?");
4004 bool AllowUnsigned =
Literal.isUnsigned ||
Literal.getRadix() != 10;
4010 if (
Literal.MicrosoftInteger) {
4015 Width =
Literal.MicrosoftInteger;
4026 Width =
std::max(ResultVal.getActiveBits(), 1u) +
4027 (
Literal.isUnsigned ? 0u : 1u);
4031 unsigned int MaxBitIntWidth =
4033 if (Width > MaxBitIntWidth) {
4036 Width = MaxBitIntWidth;
4043 ResultVal = ResultVal.zextOrTrunc(Width);
4049 assert(!
Literal.MicrosoftInteger &&
4050 "size_t literals can't be Microsoft literals");
4055 if (ResultVal.isIntN(SizeTSize)) {
4057 if (!
Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
4059 else if (AllowUnsigned)
4071 if (ResultVal.isIntN(IntSize)) {
4073 if (!
Literal.isUnsigned && ResultVal[IntSize-1] == 0)
4075 else if (AllowUnsigned)
4086 if (ResultVal.isIntN(LongSize)) {
4088 if (!
Literal.isUnsigned && ResultVal[LongSize-1] == 0)
4090 else if (AllowUnsigned)
4095 const unsigned LongLongSize =
4100 ? diag::warn_old_implicitly_unsigned_long_cxx
4102 ext_old_implicitly_unsigned_long_cxx
4103 : diag::warn_old_implicitly_unsigned_long)
4104 << (LongLongSize > LongSize ? 0
4117 if (ResultVal.isIntN(LongLongSize)) {
4121 if (!
Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
4124 else if (AllowUnsigned)
4126 Width = LongLongSize;
4139 diag::ext_integer_literal_too_large_for_signed);
4144 if (ResultVal.getBitWidth() != Width)
4145 ResultVal = ResultVal.trunc(Width);
4161 assert(E &&
"ActOnParenExpr() missing expr");
4177 S.
Diag(Loc, diag::err_vecstep_non_scalar_vector_type)
4183 "Scalar types should always be complete");
4197 (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
4198 TraitKind == UETT_PreferredAlignOf)) {
4200 S.
Diag(Loc, diag::ext_sizeof_alignof_function_type)
4208 unsigned DiagID = S.
LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
4209 : diag::ext_sizeof_alignof_void_type;
4224 S.
Diag(Loc, diag::err_sizeof_nonfragile_interface)
4225 << T << (TraitKind == UETT_SizeOf)
4243 if (!ICE || ICE->
getCastKind() != CK_ArrayToPointerDecay)
4263 bool IsUnevaluatedOperand =
4264 (ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf ||
4265 ExprKind == UETT_PreferredAlignOf || ExprKind == UETT_VecStep);
4266 if (IsUnevaluatedOperand) {
4268 if (Result.isInvalid())
4282 Diag(E->
getExprLoc(), diag::warn_side_effects_unevaluated_context);
4284 if (ExprKind == UETT_VecStep)
4297 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4300 diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4305 E, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4324 if (ExprKind == UETT_SizeOf) {
4326 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
4327 QualType OType = PVD->getOriginalType();
4332 Diag(PVD->getLocation(), diag::note_declared_at);
4385 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4386 ExprKind == UETT_OpenMPRequiredSimdAlign)
4389 if (ExprKind == UETT_VecStep)
4398 OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4403 Diag(OpLoc, diag::err_sizeof_alignof_function_type)
4421 S.
Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield)
4428 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Inner)) {
4430 }
else if (
MemberExpr *ME = dyn_cast<MemberExpr>(Inner)) {
4431 D = ME->getMemberDecl();
4451 if (
FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
4454 if (!FD->getParent()->isCompleteDefinition()) {
4455 S.
Diag(E->
getExprLoc(), diag::err_alignof_member_of_incomplete_type)
4464 if (!FD->getType()->isReferenceType())
4484 assert(CSI !=
nullptr);
4490 #define TYPE(Class, Base)
4491 #define ABSTRACT_TYPE(Class, Base)
4492 #define NON_CANONICAL_TYPE(Class, Base)
4493 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
4494 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
4495 #include "clang/AST/TypeNodes.inc"
4502 case Type::ExtVector:
4503 case Type::ConstantMatrix:
4506 case Type::Elaborated:
4507 case Type::TemplateSpecialization:
4508 case Type::ObjCObject:
4509 case Type::ObjCInterface:
4510 case Type::ObjCObjectPointer:
4511 case Type::ObjCTypeParam:
4514 llvm_unreachable(
"type class is never variably-modified!");
4515 case Type::Adjusted:
4516 T = cast<AdjustedType>(Ty)->getOriginalType();
4524 case Type::BlockPointer:
4527 case Type::LValueReference:
4528 case Type::RValueReference:
4531 case Type::MemberPointer:
4534 case Type::ConstantArray:
4535 case Type::IncompleteArray:
4537 T = cast<ArrayType>(Ty)->getElementType();
4539 case Type::VariableArray: {
4547 (isa<CapturedRegionScopeInfo>(CSI) || isa<LambdaScopeInfo>(CSI)))
4553 case Type::FunctionProto:
4554 case Type::FunctionNoProto:
4555 T = cast<FunctionType>(Ty)->getReturnType();
4559 case Type::UnaryTransform:
4560 case Type::Attributed:
4561 case Type::BTFTagAttributed:
4562 case Type::SubstTemplateTypeParm:
4563 case Type::MacroQualified:
4568 T = cast<TypedefType>(Ty)->desugar();
4570 case Type::Decltype:
4571 T = cast<DecltypeType>(Ty)->desugar();
4574 T = cast<UsingType>(Ty)->desugar();
4577 case Type::DeducedTemplateSpecialization:
4578 T = cast<DeducedType>(Ty)->getDeducedType();
4580 case Type::TypeOfExpr:
4581 T = cast<TypeOfExprType>(Ty)->getUnderlyingExpr()->getType();
4584 T = cast<AtomicType>(Ty)->getValueType();
4610 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
4614 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
4615 DC = LSI->CallOperator;
4616 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
4617 DC = CRSI->TheCapturedDecl;
4618 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
4653 }
else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4655 }
else if (ExprKind == UETT_VecStep) {
4657 }
else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
4661 Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0;
4704 if (
V.get()->isTypeDependent())
4716 return CT->getElementType();
4719 if (
V.get()->getType()->isArithmeticType())
4720 return V.get()->getType();
4725 if (PR.
get() !=
V.get()) {
4731 S.
Diag(Loc, diag::err_realimag_invalid_type) <<
V.get()->getType()
4732 << (IsReal ?
"__real" :
"__imag");
4743 default: llvm_unreachable(
"Unknown unary op!");
4744 case tok::plusplus: Opc = UO_PostInc;
break;
4745 case tok::minusminus: Opc = UO_PostDec;
break;
4750 if (Result.isInvalid())
return ExprError();
4751 Input = Result.get();
4764 !S.
LangOpts.ObjCSubscriptingLegacyRuntime)
4767 S.
Diag(opLoc, diag::err_arithmetic_nonfragile_interface)
4774 auto *BaseNoParens =
Base->IgnoreParens();
4775 if (
auto *MSProp = dyn_cast<MSPropertyRefExpr>(BaseNoParens))
4776 return MSProp->getPropertyDecl()->getType()->isArrayType();
4777 return isa<MSPropertySubscriptExpr>(BaseNoParens);
4797 if (RTy->isIntegralOrUnscopedEnumerationType()) {
4799 Result = PT->getPointeeType();
4801 Result = AT->getElementType();
4804 Result = PT->getPointeeType();
4806 Result = AT->getElementType();
4809 return Result->isDependentType() ? Result : Ctx.
DependentTy;
4826 if (isa<ParenListExpr>(base)) {
4830 base = result.
get();
4837 auto CheckAndReportCommaError = [
this, base, rbLoc](
Expr *E) {
4838 if (isa<BinaryOperator>(E) && cast<BinaryOperator>(E)->isCommaOp()) {
4839 Diag(E->getExprLoc(), diag::err_matrix_subscript_comma)
4848 !isa<MatrixSubscriptExpr>(base)) {
4849 Diag(base->
getExprLoc(), diag::err_matrix_separate_incomplete_index)
4855 auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
4856 if (matSubscriptE) {
4857 assert(ArgExprs.size() == 1);
4858 if (CheckAndReportCommaError(ArgExprs.front()))
4861 assert(matSubscriptE->isIncomplete() &&
4862 "base has to be an incomplete matrix subscript");
4864 matSubscriptE->getRowIdx(),
4865 ArgExprs.front(), rbLoc);
4873 bool IsMSPropertySubscript =
false;
4876 if (!IsMSPropertySubscript) {
4880 base = result.
get();
4886 assert(ArgExprs.size() == 1);
4887 if (CheckAndReportCommaError(ArgExprs.front()))
4895 Expr *idx = ArgExprs[0];
4896 if ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) ||
4897 (isa<CXXOperatorCallExpr>(idx) &&
4898 cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma)) {
4904 if (ArgExprs.size() == 1 &&
4905 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) {
4909 ArgExprs[0] = result.
get();
4920 base, ArgExprs.front(),
4933 if (IsMSPropertySubscript) {
4934 assert(ArgExprs.size() == 1);
4952 (ArgExprs.size() != 1 || ArgExprs[0]->getType()->isRecordType())))) {
4959 if (!Res.
isInvalid() && isa<ArraySubscriptExpr>(Res.
get()))
4960 CheckSubscriptAccessOfNoDeref(cast<ArraySubscriptExpr>(Res.
get()));
4984 RowIdx = RowR.
get();
4999 ColumnIdx = ColumnR.
get();
5004 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5005 bool IsColumnIdx) ->
Expr * {
5015 if ((*Idx < 0 || *Idx >= Dim)) {
5017 << IsColumnIdx << Dim;
5025 "should be able to convert any integer type to size type");
5026 return ConvExpr.
get();
5030 RowIdx = IsIndexValid(RowIdx, MTy->
getNumRows(),
false);
5031 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(),
true);
5032 if (!RowIdx || !ColumnIdx)
5036 MTy->getElementType(), RBLoc);
5039 void Sema::CheckAddressOfNoDeref(
const Expr *E) {
5046 while ((Member = dyn_cast<MemberExpr>(StrippedExpr)) && !
Member->isArrow())
5047 StrippedExpr =
Member->getBase()->IgnoreParenImpCasts();
5049 LastRecord.PossibleDerefs.erase(StrippedExpr);
5060 if (isa<ArrayType>(ResultTy))
5063 if (ResultTy->
hasAttr(attr::NoDeref)) {
5064 LastRecord.PossibleDerefs.insert(E);
5072 if (!(isa<ArrayType>(BaseTy) || isa<PointerType>(BaseTy)))
5077 while ((Member = dyn_cast<MemberExpr>(
Base->IgnoreParenCasts())) &&
5081 if (
const auto *Ptr = dyn_cast<PointerType>(
Base->getType())) {
5082 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
5083 LastRecord.PossibleDerefs.insert(E);
5093 if (
Base->hasPlaceholderType() &&
5094 !
Base->hasPlaceholderType(BuiltinType::OMPArraySection)) {
5096 if (Result.isInvalid())
5098 Base = Result.get();
5102 if (Result.isInvalid())
5105 if (Result.isInvalid())
5107 LowerBound = Result.get();
5111 if (Result.isInvalid())
5114 if (Result.isInvalid())
5116 Length = Result.get();
5120 if (Result.isInvalid())
5123 if (Result.isInvalid())
5125 Stride = Result.get();
5129 if (
Base->isTypeDependent() ||
5136 OK_Ordinary, ColonLocFirst, ColonLocSecond, RBLoc);
5148 Diag(
Base->getExprLoc(), diag::err_omp_typecheck_section_value)
5149 <<
Base->getSourceRange());
5155 if (Res.isInvalid())
5157 diag::err_omp_typecheck_section_not_integer)
5159 LowerBound = Res.get();
5169 if (Res.isInvalid())
5171 diag::err_omp_typecheck_section_not_integer)
5185 diag::err_omp_typecheck_section_not_integer)
5200 Diag(
Base->getExprLoc(), diag::err_omp_section_function_type)
5201 << ResultTy <<
Base->getSourceRange();
5206 diag::err_omp_section_incomplete_type,
Base))
5215 if (LowerBoundValue.isNegative()) {
5216 Diag(LowerBound->
getExprLoc(), diag::err_omp_section_not_subset_of_array)
5229 if (LengthValue.isNegative()) {
5230 Diag(Length->
getExprLoc(), diag::err_omp_section_length_negative)
5236 }
else if (ColonLocFirst.
isValid() &&
5242 Diag(ColonLocFirst, diag::err_omp_section_length_undefined)
5253 if (!StrideValue.isStrictlyPositive()) {
5254 Diag(Stride->
getExprLoc(), diag::err_omp_section_stride_non_positive)
5262 if (!
Base->hasPlaceholderType(BuiltinType::OMPArraySection)) {
5264 if (Result.isInvalid())
5266 Base = Result.get();
5270 OK_Ordinary, ColonLocFirst, ColonLocSecond, RBLoc);
5277 if (
Base->hasPlaceholderType()) {
5279 if (Result.isInvalid())
5282 if (Result.isInvalid())
5284 Base = Result.get();
5291 LParenLoc, RParenLoc, Dims, Brackets);
5293 (!
Base->isTypeDependent() &&
5296 diag::err_omp_non_pointer_type_array_shaping_base)
5297 <<
Base->getSourceRange());
5300 bool ErrorFound =
false;
5301 for (
Expr *Dim : Dims) {
5302 if (Dim->hasPlaceholderType()) {
5304 if (Result.isInvalid()) {
5309 if (Result.isInvalid()) {
5315 if (!Dim->isTypeDependent()) {
5318 if (Result.isInvalid()) {
5320 Diag(Dim->getExprLoc(), diag::err_omp_typecheck_shaping_not_integer)
5321 << Dim->getSourceRange();
5326 if (!Dim->isValueDependent() && Dim->EvaluateAsInt(EvResult,
Context)) {
5331 if (!
Value.isStrictlyPositive()) {
5332 Diag(Dim->getExprLoc(), diag::err_omp_shaping_dimension_not_positive)
5334 << Dim->getSourceRange();
5340 NewDims.push_back(Dim);
5345 LParenLoc, RParenLoc, NewDims, Brackets);
5352 bool IsCorrect =
true;