Lines Matching +full:row +full:- +full:stride
1 //===- SemaChecking.cpp - Extra Semantic Checking -------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
125 return SL->getLocationOfByte(ByteNo, getSourceManager(), LangOpts,
135 unsigned ArgCount = Call->getNumArgs();
139 return Diag(Call->getEndLoc(), diag::err_typecheck_call_too_few_args)
141 << /*is non object*/ 0 << Call->getSourceRange();
145 unsigned ArgCount = Call->getNumArgs();
148 return Diag(Call->getEndLoc(), diag::err_typecheck_call_too_many_args_at_most)
150 << /*is non object*/ 0 << Call->getSourceRange();
160 unsigned ArgCount = Call->getNumArgs();
169 SourceRange Range(Call->getArg(DesiredArgCount)->getBeginLoc(),
170 Call->getArg(ArgCount - 1)->getEndLoc());
174 << /*is non object*/ 0 << Call->getArg(1)->getSourceRange();
180 for (unsigned I = 0; I < Call->getNumArgs(); ++I) {
181 Expr *Arg = Call->getArg(I);
183 if (Arg->isValueDependent())
186 std::optional<std::string> ArgString = Arg->tryEvaluateString(S.Context);
187 int DiagMsgKind = -1;
191 else if (ArgString->find('$') != std::string::npos)
195 S.Diag(Arg->getBeginLoc(), diag::err_builtin_verbose_trap_arg)
196 << DiagMsgKind << Arg->getSourceRange();
205 if (Value->isTypeDependent())
219 /// and the second argument is a non-wide string literal.
225 Expr *ValArg = TheCall->getArg(0);
226 QualType Ty = ValArg->getType();
227 if (!Ty->isIntegerType()) {
228 S.Diag(ValArg->getBeginLoc(), diag::err_builtin_annotation_first_arg)
229 << ValArg->getSourceRange();
234 Expr *StrArg = TheCall->getArg(1)->IgnoreParenCasts();
236 if (!Literal || !Literal->isOrdinary()) {
237 S.Diag(StrArg->getBeginLoc(), diag::err_builtin_annotation_second_arg)
238 << StrArg->getSourceRange();
242 TheCall->setType(Ty);
248 if (TheCall->getNumArgs() < 1) {
249 S.Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
250 << 0 << 1 << TheCall->getNumArgs() << /*is non object*/ 0
251 << TheCall->getCallee()->getSourceRange();
256 for (Expr *Arg : TheCall->arguments()) {
257 auto *Literal = dyn_cast<StringLiteral>(Arg->IgnoreParenCasts());
258 if (!Literal || !Literal->isWide()) {
259 S.Diag(Arg->getBeginLoc(), diag::err_msvc_annotation_wide_str)
260 << Arg->getSourceRange();
274 ExprResult Arg(TheCall->getArg(0));
275 QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc());
279 TheCall->setArg(0, Arg.get());
280 TheCall->setType(ResultType);
289 ExprResult Arg = S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(0));
293 TheCall->setArg(0, Arg.get());
295 Arg.get()->getAsBuiltinConstantDeclRef(S.getASTContext()));
298 S.Diag(TheCall->getBeginLoc(), diag::err_function_start_invalid_type)
299 << TheCall->getSourceRange();
304 TheCall->getBeginLoc());
313 TheCall->setType(TheCall->getArg(0)->getType());
319 /// type (but not a function pointer) and that the alignment is a power-of-two.
324 clang::Expr *Source = TheCall->getArg(0);
328 return Ty->isIntegerType() && !Ty->isEnumeralType() && !Ty->isBooleanType();
330 QualType SrcTy = Source->getType();
332 if (SrcTy->canDecayToPointerType() && SrcTy->isArrayType()) {
335 if ((!SrcTy->isPointerType() && !IsValidIntegerType(SrcTy)) ||
336 SrcTy->isFunctionPointerType()) {
339 S.Diag(Source->getExprLoc(), diag::err_typecheck_expect_scalar_operand)
344 clang::Expr *AlignOp = TheCall->getArg(1);
345 if (!IsValidIntegerType(AlignOp->getType())) {
346 S.Diag(AlignOp->getExprLoc(), diag::err_typecheck_expect_int)
347 << AlignOp->getType();
351 unsigned MaxAlignmentBits = S.Context.getIntWidth(SrcTy) - 1;
353 if (!AlignOp->isValueDependent() &&
354 AlignOp->EvaluateAsInt(AlignResult, S.Context,
360 S.Diag(AlignOp->getExprLoc(), diag::err_alignment_too_small) << 1;
364 S.Diag(AlignOp->getExprLoc(), diag::err_alignment_too_big)
369 S.Diag(AlignOp->getExprLoc(), diag::err_alignment_not_power_of_two);
373 S.Diag(AlignOp->getExprLoc(), diag::warn_alignment_builtin_useless)
383 TheCall->setArg(0, SrcArg.get());
386 S.Context, AlignOp->getType(), false),
390 TheCall->setArg(1, AlignArg.get());
394 TheCall->setType(IsBooleanAlignBuiltin ? S.Context.BoolTy : SrcTy);
410 return BuiltinID == P.first && TheCall->getExprLoc().isMacroID() &&
411 Lexer::getImmediateMacroName(TheCall->getExprLoc(),
417 // bool, a bit-precise type, or an enumeration type.
418 if (const auto *BT = QT.getCanonicalType()->getAs<BuiltinType>())
419 return (BT->getKind() >= BuiltinType::Short &&
420 BT->getKind() <= BuiltinType::Int128) || (
421 BT->getKind() >= BuiltinType::UShort &&
422 BT->getKind() <= BuiltinType::UInt128) ||
423 BT->getKind() == BuiltinType::UChar ||
424 BT->getKind() == BuiltinType::SChar;
430 ExprResult Arg = S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(I));
432 TheCall->setArg(I, Arg.get());
434 QualType Ty = Arg.get()->getType();
435 bool IsValid = CkdOperation ? ValidCkdIntType(Ty) : Ty->isIntegerType();
437 S.Diag(Arg.get()->getBeginLoc(), diag::err_overflow_builtin_must_be_int)
438 << CkdOperation << Ty << Arg.get()->getSourceRange();
443 // Third argument should be a pointer to a non-const integer.
447 ExprResult Arg = S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(2));
449 TheCall->setArg(2, Arg.get());
451 QualType Ty = Arg.get()->getType();
452 const auto *PtrTy = Ty->getAs<PointerType>();
454 !PtrTy->getPointeeType()->isIntegerType() ||
455 (!ValidCkdIntType(PtrTy->getPointeeType()) && CkdOperation) ||
456 PtrTy->getPointeeType().isConstQualified()) {
457 S.Diag(Arg.get()->getBeginLoc(),
459 << CkdOperation << Ty << Arg.get()->getSourceRange();
464 // Disallow signed bit-precise integer args larger than 128 bits to mul
468 const auto Arg = TheCall->getArg(I);
470 auto Ty = I < 2 ? Arg->getType() : Arg->getType()->getPointeeType();
471 if (Ty->isBitIntType() && Ty->isSignedIntegerType() &&
473 return S.Diag(Arg->getBeginLoc(),
486 SourceLocation Loc = TheCall->getBeginLoc();
499 OpaqueValueExpr(Loc, Inner->getType(), Inner->getValueKind(),
500 Inner->getObjectKind(), Inner);
514 assert(TheCall->getNumArgs() >= 2);
515 Args.reserve((TheCall->getNumArgs() - 2) + /*Format*/ 1 + Exprs.size());
516 Args.assign(TheCall->arg_begin() + 2, TheCall->arg_end());
529 S.BuildCallExpr(/*Scope=*/nullptr, TheCall->getArg(1),
530 TheCall->getBeginLoc(), Args, TheCall->getRParenLoc());
558 if (auto *BT = T->getAs<BuiltinType>()) {
559 switch (BT->getKind()) {
581 // Wrap double-quotes around a '%s' specifier and limit its maximum
597 if (T->isPointerType()) {
625 // triggering re-evaluation.
627 bool RecordArgIsPtr = RecordArg->getType()->isPointerType();
634 for (const auto &Base : CXXRD->bases()) {
642 dumpUnnamedRecord(Base.getType()->getAsRecordDecl(), BasePtr.get(),
651 for (auto *D : RD->decls()) {
653 auto *FD = IFD ? IFD->getAnonField() : dyn_cast<FieldDecl>(D);
654 if (!FD || FD->isUnnamedBitField() || FD->isAnonymousStructOrUnion())
659 getTypeString(FD->getType()),
660 getStringLiteral(FD->getName())};
662 if (FD->isBitField()) {
666 FD->getBitWidthValue(S.Context));
679 DeclarationNameInfo(FD->getDeclName(), Loc));
683 auto *InnerRD = FD->getType()->getAsRecordDecl();
685 if (InnerRD && (!InnerCXXRD || InnerCXXRD->isAggregate())) {
692 if (appendFormatSpecifier(FD->getType(), Format)) {
719 TheCall->setType(Wrapper->getType());
720 TheCall->setValueKind(Wrapper->getValueKind());
730 ExprResult PtrArgResult = S.DefaultLvalueConversion(TheCall->getArg(0));
733 TheCall->setArg(0, PtrArgResult.get());
736 QualType PtrArgType = PtrArgResult.get()->getType();
737 if (!PtrArgType->isPointerType() ||
738 !PtrArgType->getPointeeType()->isRecordType()) {
739 S.Diag(PtrArgResult.get()->getBeginLoc(),
741 << 1 << TheCall->getDirectCallee() << PtrArgType;
744 QualType Pointee = PtrArgType->getPointeeType();
745 const RecordDecl *RD = Pointee->getAsRecordDecl();
748 if (S.RequireCompleteType(PtrArgResult.get()->getBeginLoc(), Pointee,
753 QualType FnArgType = TheCall->getArg(1)->getType();
754 if (!FnArgType->isFunctionType() && !FnArgType->isFunctionPointerType() &&
755 !FnArgType->isBlockPointerType() &&
756 !(S.getLangOpts().CPlusPlus && FnArgType->isRecordType())) {
757 auto *BT = FnArgType->getAs<BuiltinType>();
758 switch (BT ? BT->getKind() : BuiltinType::Void) {
769 S.Diag(TheCall->getArg(1)->getBeginLoc(),
771 << 2 << TheCall->getDirectCallee() << FnArgType;
779 // correct code generation, but it means that when we pretty-print the call
780 // arguments in our diagnostics we will produce '(&s)->n' instead of the
781 // incorrect '&s->n'.
784 ParenExpr(PtrArg->getBeginLoc(),
785 S.getLocForEndOfToken(PtrArg->getEndLoc()), PtrArg);
796 SourceLocation BuiltinLoc = BuiltinCall->getBeginLoc();
797 Expr *Builtin = BuiltinCall->getCallee()->IgnoreImpCasts();
798 Expr *Call = BuiltinCall->getArg(0);
799 Expr *Chain = BuiltinCall->getArg(1);
801 if (Call->getStmtClass() != Stmt::CallExprClass) {
803 << Call->getSourceRange();
808 if (CE->getCallee()->getType()->isBlockPointerType()) {
810 << Call->getSourceRange();
814 const Decl *TargetDecl = CE->getCalleeDecl();
816 if (FD->getBuiltinID()) {
818 << Call->getSourceRange();
822 if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens())) {
824 << Call->getSourceRange();
831 if (!ChainResult.get()->getType()->isPointerType()) {
833 << Chain->getSourceRange();
837 QualType ReturnTy = CE->getCallReturnType(S.Context);
838 QualType ArgTys[2] = { ReturnTy, ChainResult.get()->getType() };
846 BuiltinCall->setType(CE->getType());
847 BuiltinCall->setValueKind(CE->getValueKind());
848 BuiltinCall->setObjectKind(CE->getObjectKind());
849 BuiltinCall->setCallee(Builtin);
850 BuiltinCall->setArg(1, ChainResult.get());
907 unsigned DestSize = DestSizeAPS->getZExtValue();
973 // Floating point number in the form '[-]d.ddde[+-]dd'.
983 // Floating point number in the form '[-]0xh.hhhhp±dd'.
990 1 /* p or P letter */ + 1 /* + or - */ + 1 /* value */);
1003 // https://docs.kernel.org/core-api/printk-formats.html#pointer-types
1032 // (prefix_width <= FieldWidth - formatted_length) holds,
1039 // the result of converting a floating-point number always contains a
1040 // decimal-point
1057 Size -= SpecifierLen;
1125 Format && (Format->isOrdinary() || Format->isUTF8())) {
1126 FormatStrRef = Format->getString();
1128 Context.getAsConstantArrayType(Format->getType());
1130 size_t TypeSize = T->getZExtSize();
1132 StrLen = std::min(std::max(TypeSize, size_t(1)) - 1, FormatStrRef.find(0));
1140 if (TheCall->isValueDependent() || TheCall->isTypeDependent() ||
1147 const auto *DABAttr = FD->getAttr<DiagnoseAsBuiltinAttr>();
1149 UseDecl = DABAttr->getFunction();
1154 unsigned BuiltinID = UseDecl->getBuiltinID(/*ConsiderWrappers=*/true);
1162 auto TranslateIndex = [&](unsigned Index) -> std::optional<unsigned> {
1169 unsigned DABIndices = DABAttr->argIndices_size();
1171 ? DABAttr->argIndices_begin()[Index]
1172 : Index - DABIndices + FD->getNumParams();
1173 if (NewIndex >= TheCall->getNumArgs())
1179 [&](unsigned Index) -> std::optional<llvm::APSInt> {
1185 Expr *SizeArg = TheCall->getArg(NewIndex);
1186 if (!SizeArg->EvaluateAsInt(Result, getASTContext()))
1194 [&](unsigned Index) -> std::optional<llvm::APSInt> {
1200 if (Index < FD->getNumParams()) {
1202 FD->getParamDecl(Index)->getAttr<PassObjectSizeAttr>())
1203 BOSType = POS->getType();
1211 if (NewIndex >= TheCall->getNumArgs())
1214 const Expr *ObjArg = TheCall->getArg(NewIndex);
1216 if (!ObjArg->tryEvaluateObjectSize(Result, getASTContext(), BOSType))
1224 [&](unsigned Index) -> std::optional<llvm::APSInt> {
1230 const Expr *ObjArg = TheCall->getArg(NewIndex);
1232 if (!ObjArg->tryEvaluateStrLen(Result, getASTContext()))
1287 TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
1299 DiagRuntimeBehavior(TheCall->getArg(Index)->getBeginLoc(), TheCall,
1322 auto *FormatExpr = TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
1359 SourceSize = ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 2);
1361 ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
1387 SourceSize = ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
1401 SourceSize = ComputeExplicitObjectSizeArgument(TheCall->getNumArgs() - 1);
1411 const auto *FormatExpr = TheCall->getArg(2)->IgnoreParenImpCasts();
1430 SourceSize->toString(SpecifiedSizeStr, /*Radix=*/10);
1432 DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
1451 DestinationSize->toString(DestinationStr, /*Radix=*/10);
1452 SourceSize->toString(SourceStr, /*Radix=*/10);
1453 DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
1468 while (S && !S->isSEHExceptScope())
1469 S = S->getParent();
1470 if (!S || !(S->getFlags() & NeededScopeFlags)) {
1471 auto *DRE = cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
1472 SemaRef.Diag(TheCall->getExprLoc(), DiagID)
1473 << DRE->getDecl()->getIdentifier();
1501 return S.checkPointerAuthEnabled(E->getExprLoc(), E->getSourceRange());
1509 // Value-dependent expressions are okay; wait for template instantiation.
1510 if (Arg->isValueDependent())
1518 // Attempt to constant-evaluate the expression.
1519 std::optional<llvm::APSInt> KeyValue = Arg->getIntegerConstantExpr(Context);
1521 Diag(Arg->getExprLoc(), diag::err_expr_not_ice)
1522 << 0 << Arg->getSourceRange();
1534 Diag(Arg->getExprLoc(), diag::err_ptrauth_invalid_key)
1535 << Value << Arg->getSourceRange();
1539 Result = KeyValue->getZExtValue();
1547 if (!E->EvaluateAsRValue(Result, S.Context) || !Result.Val.isLValue())
1560 if (Arg->hasPlaceholderType()) {
1577 if (AllowsPointer(OpKind) && Arg->getType()->isPointerType()) {
1578 ExpectedTy = Arg->getType().getUnqualifiedType();
1579 } else if (AllowsPointer(OpKind) && Arg->getType()->isNullPtrType()) {
1582 Arg->getType()->isIntegralOrUnscopedEnumerationType()) {
1587 S.Diag(Arg->getExprLoc(), diag::err_ptrauth_value_bad_type)
1593 << Arg->getType() << Arg->getSourceRange();
1597 // Convert to that type. This should just be an lvalue-to-rvalue
1603 // Warn about null pointers for non-generic sign and auth operations.
1605 Arg->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNull)) {
1606 S.Diag(Arg->getExprLoc(), OpKind == PAO_Sign
1609 << Arg->getSourceRange();
1636 S.Diag(Arg->getExprLoc(), diag::err_ptrauth_bad_constant_pointer);
1646 if (auto *Call = dyn_cast<CallExpr>(Arg->IgnoreParens())) {
1647 if (Call->getBuiltinCallee() ==
1649 Pointer = Call->getArg(0);
1650 Integer = Call->getArg(1);
1654 if (Arg->getType()->isPointerType())
1663 assert(Pointer->getType()->isPointerType());
1667 // never really be feasible and we'll have to catch it at link-time.
1675 assert(Integer->getType()->isIntegerType());
1676 if (!Integer->isEvaluatable(S.Context))
1681 S.Diag(Arg->getExprLoc(), diag::err_ptrauth_bad_constant_discriminator);
1690 if (checkPointerAuthValue(S, Call->getArgs()[0], PAO_Strip) ||
1691 checkPointerAuthKey(S, Call->getArgs()[1]))
1694 Call->setType(Call->getArgs()[0]->getType());
1703 if (checkPointerAuthValue(S, Call->getArgs()[0], PAO_BlendPointer) ||
1704 checkPointerAuthValue(S, Call->getArgs()[1], PAO_BlendInteger))
1707 Call->setType(S.Context.getUIntPtrType());
1716 if (checkPointerAuthValue(S, Call->getArgs()[0], PAO_SignGeneric) ||
1717 checkPointerAuthValue(S, Call->getArgs()[1], PAO_Discriminator))
1720 Call->setType(S.Context.getUIntPtrType());
1731 if (checkPointerAuthValue(S, Call->getArgs()[0], OpKind, RequireConstant) ||
1732 checkPointerAuthKey(S, Call->getArgs()[1]) ||
1733 checkPointerAuthValue(S, Call->getArgs()[2], PAO_Discriminator,
1737 Call->setType(Call->getArgs()[0]->getType());
1746 if (checkPointerAuthValue(S, Call->getArgs()[0], PAO_Auth) ||
1747 checkPointerAuthKey(S, Call->getArgs()[1]) ||
1748 checkPointerAuthValue(S, Call->getArgs()[2], PAO_Discriminator) ||
1749 checkPointerAuthKey(S, Call->getArgs()[3]) ||
1750 checkPointerAuthValue(S, Call->getArgs()[4], PAO_Discriminator))
1753 Call->setType(Call->getArgs()[0]->getType());
1761 // We've already performed normal call type-checking.
1762 const Expr *Arg = Call->getArg(0)->IgnoreParenImpCasts();
1764 // Operand must be an ordinary or UTF-8 string literal.
1766 if (!Literal || Literal->getCharByteWidth() != 1) {
1767 S.Diag(Arg->getExprLoc(), diag::err_ptrauth_string_not_literal)
1768 << (Literal ? 1 : 0) << Arg->getSourceRange();
1785 QualType ArgTy = TheCall->getArg(0)->getType();
1786 if (const ArrayType *Ty = ArgTy->getAsArrayTypeUnsafe())
1787 return S.Context.getPointerType(Ty->getElementType());
1788 if (ArgTy->isFunctionType()) {
1794 TheCall->setType(ParamTy);
1796 auto DiagSelect = [&]() -> std::optional<unsigned> {
1797 if (!ParamTy->isPointerType())
1799 if (ParamTy->isFunctionPointerType())
1801 if (ParamTy->isVoidPointerType())
1806 S.Diag(TheCall->getBeginLoc(), diag::err_builtin_launder_invalid_arg)
1807 << *DiagSelect << TheCall->getSourceRange();
1817 if (S.RequireCompleteType(TheCall->getBeginLoc(), ParamTy->getPointeeType(),
1821 assert(ParamTy->getPointeeType()->isObjectType() &&
1822 "Unhandled non-object pointer case");
1827 S.PerformCopyInitialization(Entity, SourceLocation(), TheCall->getArg(0));
1830 TheCall->setArg(0, Arg.get());
1843 S.Diag(TheCall->getBeginLoc(), diag::err_builtin_target_unsupported)
1844 << TheCall->getSourceRange();
1859 S.Diag(TheCall->getBeginLoc(), diag::err_builtin_target_unsupported)
1860 << TheCall->getSourceRange();
1926 if (!ArgTy->getAs<VectorType>() &&
1938 if (auto *VecTy = EltTy->getAs<VectorType>())
1939 EltTy = VecTy->getElementType();
1941 if (!EltTy->isRealFloatingType()) {
1949 /// BuiltinCpu{Supports|Is} - Handle __builtin_cpu_{supports|is}(char *).
1961 return TInfo && ((IsCPUSupports && TInfo->supportsCpuSupports()) ||
1962 (!IsCPUSupports && TInfo->supportsCpuIs()));
1967 if ((!IsCPUSupports && !TheTI->supportsCpuIs()) ||
1968 (IsCPUSupports && !TheTI->supportsCpuSupports()))
1969 return S.Diag(TheCall->getBeginLoc(),
1973 << SourceRange(TheCall->getBeginLoc(), TheCall->getEndLoc());
1975 Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
1978 return S.Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
1979 << Arg->getSourceRange();
1982 StringRef Feature = cast<StringLiteral>(Arg)->getString();
1983 if (IsCPUSupports && !TheTI->validateCpuSupports(Feature)) {
1984 S.Diag(TheCall->getBeginLoc(), diag::warn_invalid_cpu_supports)
1985 << Arg->getSourceRange();
1988 if (!IsCPUSupports && !TheTI->validateCpuIs(Feature))
1989 return S.Diag(TheCall->getBeginLoc(), diag::err_invalid_cpu_is)
1990 << Arg->getSourceRange();
2000 ExprResult ArgRes = S.DefaultLvalueConversion(TheCall->getArg(0));
2005 TheCall->setArg(0, Arg);
2007 QualType ArgTy = Arg->getType();
2009 if (!ArgTy->isUnsignedIntegerType()) {
2010 S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2024 ExprResult Arg0Res = S.DefaultLvalueConversion(TheCall->getArg(0));
2029 TheCall->setArg(0, Arg0);
2031 QualType Arg0Ty = Arg0->getType();
2033 if (!Arg0Ty->isUnsignedIntegerType()) {
2034 S.Diag(Arg0->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2039 if (TheCall->getNumArgs() > 1) {
2040 ExprResult Arg1Res = S.UsualUnaryConversions(TheCall->getArg(1));
2045 TheCall->setArg(1, Arg1);
2047 QualType Arg1Ty = Arg1->getType();
2049 if (!Arg1Ty->isSpecificBuiltinType(BuiltinType::Int)) {
2050 S.Diag(Arg1->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2079 if (ArgNo < TheCall->getNumArgs() &&
2095 Diag(TheCall->getBeginLoc(), diag::err_builtin_target_unsupported)
2096 << SourceRange(TheCall->getBeginLoc(), TheCall->getEndLoc());
2107 assert(TheCall->getNumArgs() == 1 &&
2109 if (ObjC().CheckObjCString(TheCall->getArg(0)))
2147 // The 64-bit bittest variants are x64, ARM, and AArch64 only.
2215 Diag(TheCall->getBeginLoc(), diag::warn_alloca)
2216 << TheCall->getDirectCallee();
2247 TheCall->setType(Context.IntTy);
2256 ExprResult Arg = DefaultFunctionArrayLvalueConversion(TheCall->getArg(0));
2258 TheCall->setArg(0, Arg.get());
2259 TheCall->setType(Context.IntTy);
2368 Diag(TheCall->getBeginLoc(), diag::warn_atomic_implicit_seq_cst)
2369 << TheCall->getCallee()->getSourceRange();
2375 clang::Expr *SizeOp = TheCall->getArg(2);
2379 if (SizeOp->isValueDependent())
2381 if (!SizeOp->EvaluateKnownConstInt(Context).isZero()) {
2382 CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
2383 CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
2388 clang::Expr *SizeOp = TheCall->getArg(2);
2392 if (SizeOp->isValueDependent())
2394 if (!SizeOp->EvaluateKnownConstInt(Context).isZero())
2395 CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
2447 const Expr *ProbArg = TheCall->getArg(2);
2451 if ((!ProbArg->EvaluateAsConstantExpr(Eval, Context)) ||
2453 Diag(ProbArg->getBeginLoc(), diag::err_probability_not_constant_float)
2454 << ProbArg->getSourceRange();
2465 Diag(ProbArg->getBeginLoc(), diag::err_probability_out_of_range)
2466 << ProbArg->getSourceRange();
2496 TheCall->getBeginLoc(),
2497 Context.getExceptionObjectType(FDecl->getParamDecl(0)->getType()),
2501 TheCall->setType(Context.VoidPtrTy);
2515 QualType Param = FDecl->getParamDecl(0)->getType();
2516 QualType Result = FDecl->getReturnType();
2519 if (!(Param->isReferenceType() &&
2520 (ReturnsPointer ? Result->isAnyPointerType()
2521 : Result->isReferenceType()) &&
2522 Context.hasSameUnqualifiedType(Param->getPointeeType(),
2523 Result->getPointeeType()))) {
2524 Diag(TheCall->getBeginLoc(), diag::err_builtin_move_forward_unsupported)
2549 // OpenCL v2.0, s6.13.16 - Pipe functions
2594 // OpenCL v2.0, s6.13.17 - Enqueue kernel functions.
2621 // -Wframe-address warning if non-zero passed to builtin
2624 if (!TheCall->getArg(0)->isValueDependent() &&
2625 TheCall->getArg(0)->EvaluateAsInt(Result, getASTContext()) &&
2627 Diag(TheCall->getBeginLoc(), diag::warn_frame_address)
2631 << TheCall->getSourceRange();
2647 QualType ArgTy = TheCall->getArg(0)->getType();
2650 if (auto *VecTy = EltTy->getAs<VectorType>())
2651 EltTy = VecTy->getElementType();
2652 if (EltTy->isUnsignedIntegerType()) {
2653 Diag(TheCall->getArg(0)->getBeginLoc(),
2689 QualType ArgTy = TheCall->getArg(0)->getType();
2690 if (checkFPMathBuiltinElementType(*this, TheCall->getArg(0)->getBeginLoc(),
2707 QualType ArgTy = TheCall->getArg(0)->getType();
2708 if (checkFPMathBuiltinElementType(*this, TheCall->getArg(0)->getBeginLoc(),
2710 checkFPMathBuiltinElementType(*this, TheCall->getArg(1)->getBeginLoc(),
2723 const Expr *Arg = TheCall->getArg(0);
2724 QualType ArgTy = Arg->getType();
2727 if (auto *VecTy = EltTy->getAs<VectorType>())
2728 EltTy = VecTy->getElementType();
2730 if (!EltTy->isIntegerType()) {
2731 Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2748 const Expr *Arg = TheCall->getArg(0);
2749 QualType ArgTy = Arg->getType();
2752 if (auto *VecTy = EltTy->getAs<VectorType>())
2753 EltTy = VecTy->getElementType();
2755 if (!EltTy->isIntegerType()) {
2756 Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2767 ExprResult Magnitude = UsualUnaryConversions(TheCall->getArg(0));
2768 ExprResult Sign = UsualUnaryConversions(TheCall->getArg(1));
2772 QualType MagnitudeTy = Magnitude.get()->getType();
2773 QualType SignTy = Sign.get()->getType();
2774 if (checkFPMathBuiltinElementType(*this, TheCall->getArg(0)->getBeginLoc(),
2776 checkFPMathBuiltinElementType(*this, TheCall->getArg(1)->getBeginLoc(),
2782 return Diag(Sign.get()->getBeginLoc(),
2787 TheCall->setArg(0, Magnitude.get());
2788 TheCall->setArg(1, Sign.get());
2789 TheCall->setType(Magnitude.get()->getType());
2797 const Expr *Arg = TheCall->getArg(0);
2798 const auto *TyA = Arg->getType()->getAs<VectorType>();
2802 ElTy = TyA->getElementType();
2803 else if (Arg->getType()->isSizelessVectorType())
2804 ElTy = Arg->getType()->getSizelessVectorEltType(Context);
2807 Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2808 << 1 << /* vector ty*/ 4 << Arg->getType();
2812 TheCall->setType(ElTy);
2817 // TODO: ADD/MUL should support floating-point types.
2826 const Expr *Arg = TheCall->getArg(0);
2827 const auto *TyA = Arg->getType()->getAs<VectorType>();
2831 ElTy = TyA->getElementType();
2832 else if (Arg->getType()->isSizelessVectorType())
2833 ElTy = Arg->getType()->getSizelessVectorEltType(Context);
2835 if (ElTy.isNull() || !ElTy->isIntegerType()) {
2836 Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
2837 << 1 << /* vector of integers */ 6 << Arg->getType();
2841 TheCall->setType(ElTy);
2861 if (TheCall->getNumArgs() != 1)
2863 auto *DRE = dyn_cast<DeclRefExpr>(TheCall->getArg(0)->IgnoreImpCasts());
2866 auto *D = DRE->getDecl();
2869 return D->hasAttr<CUDAGlobalAttr>() || D->hasAttr<CUDADeviceAttr>() ||
2870 D->hasAttr<CUDAConstantAttr>() || D->hasAttr<HIPManagedAttr>();
2873 Diag(TheCall->getBeginLoc(),
2890 Expr *Arg = TheCall->getArg(0);
2892 if (!isa<StringLiteral>(Arg->IgnoreParenImpCasts())) {
2893 Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
2894 << Arg->getSourceRange();
2928 Expr *Arg = TheCall->getArg(ArgNum);
2929 if (Arg->isTypeDependent() || Arg->isValueDependent())
2932 // Check constant-ness first.
2940 return Diag(TheCall->getBeginLoc(),
2942 << ArgNum << Arg->getSourceRange();
2947 if (Format->getFirstArg() == 0)
2948 FSI->ArgPassingKind = FAPK_VAList;
2950 FSI->ArgPassingKind = FAPK_Variadic;
2952 FSI->ArgPassingKind = FAPK_Fixed;
2953 FSI->FormatIdx = Format->getFormatIdx() - 1;
2954 FSI->FirstDataArg =
2955 FSI->ArgPassingKind == FAPK_VAList ? 0 : Format->getFirstArg() - 1;
2961 if(FSI->FormatIdx == 0)
2963 --FSI->FormatIdx;
2964 if (FSI->FirstDataArg != 0)
2965 --FSI->FirstDataArg;
2975 // const-evaluate them or not.
2982 // If the expression has non-null type, it doesn't evaluate to null.
2983 if (auto nullability = Expr->IgnoreImplicit()->getType()->getNullability()) {
2990 if (const RecordType *UT = Expr->getType()->getAsUnionType();
2991 UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
2993 if (const auto *ILE = dyn_cast<InitListExpr>(CLE->getInitializer()))
2994 Expr = ILE->getInit(0);
2998 return (!Expr->isValueDependent() &&
2999 Expr->EvaluateAsBooleanCondition(Result, S.Context) &&
3009 << ArgExpr->getSourceRange());
3012 /// Determine whether the given type has a non-null nullability annotation.
3014 if (auto nullability = type->getNullability())
3034 for (const auto *NonNull : FDecl->specific_attrs<NonNullAttr>()) {
3035 if (!NonNull->args_size()) {
3038 if (S.isValidPointerAttrType(Arg->getType()))
3043 for (const ParamIdx &Idx : NonNull->args()) {
3059 parms = FD->parameters();
3061 parms = cast<ObjCMethodDecl>(FDecl)->parameters();
3067 if (PVD->hasAttr<NonNullAttr>() || isNonNullType(PVD->getType())) {
3075 // If we have a non-function, non-method declaration but no
3079 QualType type = VD->getType().getNonReferenceType();
3080 if (auto pointerType = type->getAs<PointerType>())
3081 type = pointerType->getPointeeType();
3082 else if (auto blockType = type->getAs<BlockPointerType>())
3083 type = blockType->getPointeeType();
3087 Proto = type->getAs<FunctionProtoType>();
3091 // Fill in non-null argument information from the nullability
3095 for (auto paramType : Proto->getParamTypes()) {
3108 // Check for non-null arguments.
3112 CheckNonNullArgument(S, Args[ArgIndex], Args[ArgIndex]->getExprLoc());
3121 if (!ParamTy->isPointerType() && !ParamTy->isReferenceType())
3127 if (ParamTy->isPointerType())
3128 ArgTy = ArgTy->getPointeeType();
3131 ParamTy = ParamTy->getPointeeType();
3135 if (ArgTy.isNull() || ParamTy->isDependentType() ||
3136 ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
3137 ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
3156 if (CurContext->isDependentContext())
3162 for (const auto *I : FDecl->specific_attrs<FormatAttr>()) {
3175 (!FD || FD->getBuiltinID() != Builtin::BI__noop)) {
3176 unsigned NumParams = Proto ? Proto->getNumParams()
3178 ? cast<FunctionDecl>(FDecl)->getNumParams()
3180 ? cast<ObjCMethodDecl>(FDecl)->param_size()
3197 for (const auto *I : FDecl->specific_attrs<ArgumentWithTypeTagAttr>())
3205 const auto *FT = FDecl->getFunctionType();
3207 Proto = cast<FunctionProtoType>(FDecl->getFunctionType());
3212 const auto N = std::min<unsigned>(Proto->getNumParams(), Args.size());
3213 bool IsScalableRet = Proto->getReturnType()->isSizelessVectorType();
3218 if (Arg->containsErrors())
3222 FDecl->hasLinkage() &&
3223 FDecl->getFormalLinkage() != Linkage::Internal &&
3225 PPC().checkAIXMemberAlignment((Arg->getExprLoc()), Arg);
3227 QualType ParamTy = Proto->getParamType(ArgIdx);
3228 if (ParamTy->isSizelessVectorType())
3230 QualType ArgTy = Arg->getType();
3231 CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1),
3238 FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo();
3250 // If the call requires a streaming-mode change and has scalable vector
3252 // non-streaming vector lengths may be different.
3254 if (CallerFD && (!FD || !FD->getBuiltinID()) &&
3283 auto *Attr = CallerFD->getAttr<ArmNewAttr>();
3284 if (Attr && Attr->isNewZA())
3286 if (Attr && Attr->isNewZT0())
3288 if (const auto *FPT = CallerFD->getType()->getAs<FunctionProtoType>()) {
3291 FPT->getExtProtoInfo().AArch64SMEAttributes) !=
3295 FPT->getExtProtoInfo().AArch64SMEAttributes) !=
3314 if (FDecl && FDecl->hasAttr<AllocAlignAttr>()) {
3315 auto *AA = FDecl->getAttr<AllocAlignAttr>();
3316 const Expr *Arg = Args[AA->getParamIndex().getASTIndex()];
3317 if (!Arg->isValueDependent()) {
3319 if (Arg->EvaluateAsInt(Align, Context)) {
3322 Diag(Arg->getExprLoc(), diag::warn_alignment_not_power_of_two)
3323 << Arg->getSourceRange();
3326 Diag(Arg->getExprLoc(), diag::warn_assume_aligned_too_great)
3327 << Arg->getSourceRange() << Sema::MaximumAlignment;
3337 if (ConceptDecl *Decl = AutoT->getTypeConstraintConcept()) {
3347 Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
3352 Context.getPointerType(Ctor->getFunctionObjectParameterType()));
3365 TheCall->getCallee());
3366 Expr** Args = TheCall->getArgs();
3367 unsigned NumArgs = TheCall->getNumArgs();
3370 if (IsMemberOperatorCall && !FDecl->hasCXXExplicitFunctionObjectParameter()) {
3376 --NumArgs;
3377 } else if (IsMemberFunction && !FDecl->isStatic() &&
3378 !FDecl->hasCXXExplicitFunctionObjectParameter())
3380 cast<CXXMemberCallExpr>(TheCall)->getImplicitObjectArgument();
3383 // ImplicitThis may or may not be a pointer, depending on whether . or -> is
3385 QualType ThisType = ImplicitThis->getType();
3386 if (!ThisType->isPointerType()) {
3387 assert(!ThisType->isReferenceType());
3392 cast<CXXMethodDecl>(FDecl)->getFunctionObjectParameterType());
3394 CheckArgAlignment(TheCall->getRParenLoc(), FDecl, "'this'", ThisType,
3399 IsMemberFunction, TheCall->getRParenLoc(),
3400 TheCall->getCallee()->getSourceRange(), CallType);
3402 IdentifierInfo *FnInfo = FDecl->getIdentifier();
3409 if (FDecl->getBuiltinID() == 0)
3410 CheckTCBEnforcement(TheCall->getExprLoc(), FDecl);
3419 unsigned CMId = FDecl->getMemoryFunctionKind();
3446 Ty = V->getType().getNonReferenceType();
3448 Ty = F->getType().getNonReferenceType();
3452 if (!Ty->isBlockPointerType() && !Ty->isFunctionPointerType() &&
3453 !Ty->isFunctionProtoType())
3457 if (!Proto || !Proto->isVariadic()) {
3459 } else if (Ty->isBlockPointerType()) {
3461 } else { // Ty->isFunctionPointerType()
3466 llvm::ArrayRef(TheCall->getArgs(), TheCall->getNumArgs()),
3467 /*IsMemberFunction=*/false, TheCall->getRParenLoc(),
3468 TheCall->getCallee()->getSourceRange(), CallType);
3475 TheCall->getCallee());
3477 llvm::ArrayRef(TheCall->getArgs(), TheCall->getNumArgs()),
3478 /*IsMemberFunction=*/false, TheCall->getRParenLoc(),
3479 TheCall->getCallee()->getSourceRange(), CallType);
3523 DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
3524 MultiExprArg Args{TheCall->getArgs(), TheCall->getNumArgs()};
3525 return BuildAtomicExpr({TheCall->getBeginLoc(), TheCall->getEndLoc()},
3526 DRE->getSourceRange(), TheCall->getRParenLoc(), Args,
3534 // All the non-OpenCL operations take one of the following forms.
3742 Diag(Args[AdjustedNumArgs]->getBeginLoc(),
3756 const PointerType *pointerType = Ptr->getType()->getAs<PointerType>();
3759 << Ptr->getType() << 0 << Ptr->getSourceRange();
3764 QualType AtomTy = pointerType->getPointeeType(); // 'A'
3767 if (!AtomTy->isAtomicType()) {
3769 << Ptr->getType() << Ptr->getSourceRange();
3775 << (AtomTy.isConstQualified() ? 0 : 1) << Ptr->getType()
3776 << Ptr->getSourceRange();
3779 ValType = AtomTy->castAs<AtomicType>()->getValueType();
3783 << Ptr->getType() << Ptr->getSourceRange();
3789 if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
3794 << Ptr->getType() << 1 << Ptr->getSourceRange();
3798 // For an arithmetic operation, the implied arithmetic must be well-formed.
3803 unsigned AllowedType) -> bool {
3804 if (ValType->isIntegerType())
3806 if (ValType->isPointerType())
3808 if (!(ValType->isFloatingType() && (AllowedType & AOEVT_FP)))
3811 if (ValType->isSpecificBuiltinType(BuiltinType::LongDouble) &&
3824 << IsC11 << Ptr->getType() << Ptr->getSourceRange();
3827 if (IsC11 && ValType->isPointerType() &&
3828 RequireCompleteType(Ptr->getBeginLoc(), ValType->getPointeeType(),
3832 } else if (IsN && !ValType->isIntegerType() && !ValType->isPointerType()) {
3836 << IsC11 << Ptr->getType() << Ptr->getSourceRange();
3841 !AtomTy->isScalarType()) {
3842 // For GNU atomics, require a trivially-copyable type. This is not part of
3844 // other atomics which generally all require a trivially-copyable type. This
3847 << Ptr->getType() << Ptr->getSourceRange();
3863 << ValType << Ptr->getSourceRange();
3868 // 'A'. We shouldn't let the volatile-ness of the pointee-type inject itself
3885 ByValType = Ptr->getType();
3926 // The first argument's non-CV pointer type is used to deduce the type of
3928 // - weak flag (always converted to bool)
3929 // - memory order (always converted to int)
3930 // - scope (always converted to int)
3942 // The second argument is the non-atomic operand. For arithmetic, this
3944 // passed by address. For the rest, GNU uses by-address and C11 uses
3945 // by-value.
3947 if (Form == Arithmetic && ValType->isPointerType())
3963 // Keep address space of non-atomic pointer type.
3965 ValArg->getType()->getAs<PointerType>()) {
3966 AS = PtrTy->getPointeeType().getAddressSpace();
3974 // value, either by-value (for the C11 and *_n variant) or as a pointer.
4040 SubExprs[1]->getIntegerConstantExpr(Context);
4041 if (Success && !isValidOrderingForOp(Success->getSExtValue(), Op)) {
4042 Diag(SubExprs[1]->getBeginLoc(),
4045 << SubExprs[1]->getSourceRange();
4049 SubExprs[3]->getIntegerConstantExpr(Context)) {
4055 (llvm::AtomicOrderingCABI)Failure->getSExtValue())) {
4056 Diag(SubExprs[3]->getBeginLoc(),
4058 << /*failure=*/2 << SubExprs[3]->getSourceRange();
4065 auto *Scope = Args[Args.size() - 1];
4067 Scope->getIntegerConstantExpr(Context)) {
4068 if (!ScopeModel->isValid(Result->getZExtValue()))
4069 Diag(Scope->getBeginLoc(), diag::err_atomic_op_has_invalid_synch_scope)
4070 << Scope->getSourceRange();
4085 Diag(AE->getBeginLoc(), diag::err_atomic_load_store_uses_lib)
4092 if (ValType->isBitIntType()) {
4093 Diag(Ptr->getExprLoc(), diag::err_atomic_builtin_bit_int_prohibit);
4100 /// checkBuiltinArgument - Given a call to a builtin function, perform
4101 /// normal type-checking on the given argument, updating the call in
4103 /// type-checking for some of its arguments but not necessarily all of
4108 FunctionDecl *Fn = E->getDirectCallee();
4111 ParmVarDecl *Param = Fn->getParamDecl(ArgIndex);
4115 ExprResult Arg = E->getArg(ArgIndex);
4120 E->setArg(ArgIndex, Arg.get());
4126 Expr *Callee = TheCall->getCallee();
4127 DeclRefExpr *DRE = cast<DeclRefExpr>(Callee->IgnoreParenCasts());
4128 FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
4131 if (TheCall->getNumArgs() < 1) {
4132 Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
4133 << 0 << 1 << TheCall->getNumArgs() << /*is non object*/ 0
4134 << Callee->getSourceRange();
4143 Expr *FirstArg = TheCall->getArg(0);
4148 TheCall->setArg(0, FirstArg);
4150 const PointerType *pointerType = FirstArg->getType()->getAs<PointerType>();
4152 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
4153 << FirstArg->getType() << 0 << FirstArg->getSourceRange();
4157 QualType ValType = pointerType->getPointeeType();
4158 if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
4159 !ValType->isBlockPointerType()) {
4160 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer_intptr)
4161 << FirstArg->getType() << 0 << FirstArg->getSourceRange();
4166 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_cannot_be_const)
4167 << FirstArg->getType() << FirstArg->getSourceRange();
4180 Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
4181 << ValType << FirstArg->getSourceRange();
4231 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_pointer_size)
4232 << FirstArg->getType() << FirstArg->getSourceRange();
4238 // that we ignore. Find out which row of BuiltinIndices to read from as well
4240 unsigned BuiltinID = FDecl->getBuiltinID();
4408 if (TheCall->getNumArgs() < 1+NumFixed) {
4409 Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
4410 << 0 << 1 + NumFixed << TheCall->getNumArgs() << /*is non object*/ 0
4411 << Callee->getSourceRange();
4415 Diag(TheCall->getEndLoc(), diag::warn_atomic_implicit_seq_cst)
4416 << Callee->getSourceRange();
4419 Diag(TheCall->getEndLoc(), diag::warn_sync_fetch_and_nand_semantics_change)
4420 << Callee->getSourceRange();
4433 LookupResult Res(*this, DN, DRE->getBeginLoc(), LookupOrdinaryName);
4441 // The first argument --- the pointer --- has a fixed type; we
4445 ExprResult Arg = TheCall->getArg(i+1);
4448 // can fail in some cases (1i -> int**), check for this error case now.
4460 // for things like 45.123 -> char, etc.
4462 TheCall->setArg(i+1, Arg.get());
4467 Context, DRE->getQualifierLoc(), SourceLocation(), NewBuiltinDecl,
4468 /*enclosing*/ false, DRE->getLocation(), Context.BuiltinFnTy,
4469 DRE->getValueKind(), nullptr, nullptr, DRE->isNonOdrUse());
4473 QualType CalleePtrTy = Context.getPointerType(NewBuiltinDecl->getType());
4476 TheCall->setCallee(PromotedCall.get());
4481 TheCall->setType(ResultType);
4483 // Prohibit problematic uses of bit-precise integer types with atomic
4486 const auto *BitIntValType = ValType->getAs<BitIntType>();
4487 if (BitIntValType && !llvm::isPowerOf2_64(BitIntValType->getNumBits())) {
4488 Diag(FirstArg->getExprLoc(), diag::err_atomic_builtin_ext_int_size);
4498 cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
4499 FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
4500 unsigned BuiltinID = FDecl->getBuiltinID();
4515 Expr *PointerArg = TheCall->getArg(numArgs - 1);
4522 TheCall->setArg(numArgs - 1, PointerArg);
4524 const PointerType *pointerType = PointerArg->getType()->getAs<PointerType>();
4526 Diag(DRE->getBeginLoc(), diag::err_nontemporal_builtin_must_be_pointer)
4527 << PointerArg->getType() << PointerArg->getSourceRange();
4531 QualType ValType = pointerType->getPointeeType();
4535 if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
4536 !ValType->isBlockPointerType() && !ValType->isFloatingType() &&
4537 !ValType->isVectorType()) {
4538 Diag(DRE->getBeginLoc(),
4540 << PointerArg->getType() << PointerArg->getSourceRange();
4545 TheCall->setType(ValType);
4549 ExprResult ValArg = TheCall->getArg(0);
4556 TheCall->setArg(0, ValArg.get());
4557 TheCall->setType(Context.VoidTy);
4561 /// CheckObjCString - Checks that the format string argument to the os_log()
4564 Arg = Arg->IgnoreParenCasts();
4568 Literal = ObjcLiteral->getString();
4572 if (!Literal || (!Literal->isOrdinary() && !Literal->isUTF8())) {
4574 Diag(Arg->getBeginLoc(), diag::err_os_log_format_not_string_constant)
4575 << Arg->getSourceRange());
4598 CC = FD->getType()->castAs<FunctionType>()->getCallConv();
4602 return S.Diag(Fn->getBeginLoc(),
4605 // On x86-64/AArch64 Unix, don't allow this in Win64 ABI functions.
4611 return S.Diag(Fn->getBeginLoc(),
4619 return S.Diag(Fn->getBeginLoc(), diag::err_builtin_x64_aarch64_only);
4625 // Determine whether the current function, block, or obj-c method is variadic
4631 IsVariadic = Block->isVariadic();
4632 Params = Block->parameters();
4634 IsVariadic = FD->isVariadic();
4635 Params = FD->parameters();
4637 IsVariadic = MD->isVariadic();
4639 Params = MD->parameters();
4642 S.Diag(Fn->getBeginLoc(), diag::err_va_start_captured_stmt);
4646 S.Diag(Fn->getBeginLoc(), diag::err_va_start_outside_function);
4651 S.Diag(Fn->getBeginLoc(), diag::err_va_start_fixed_function);
4662 Expr *Fn = TheCall->getCallee();
4673 // Type-check the first argument normally.
4687 const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts();
4689 TheCall->getArg(1)->getIntegerConstantExpr(Context);
4700 if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) {
4703 Type = PV->getType();
4704 ParamLoc = PV->getLocation();
4706 PV->getStorageClass() == SC_Register && !getLangOpts().CPlusPlus;
4711 Diag(TheCall->getArg(1)->getBeginLoc(),
4713 else if (IsCRegister || Type->isReferenceType() ||
4714 Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
4719 if (!Type->isEnumeralType())
4721 const EnumDecl *ED = Type->castAs<EnumType>()->getDecl();
4723 Context.typesAreCompatible(ED->getPromotionType(), Type));
4726 if (Type->isReferenceType()) Reason = 1;
4728 Diag(Arg->getBeginLoc(), diag::warn_va_start_type_is_undefined) << Reason;
4736 auto IsSuitablyTypedFormatArgument = [this](const Expr *Arg) -> bool {
4740 return Arg->getType()
4743 ->getPointeeType()
4754 Expr *Func = Call->getCallee();
4756 if (Call->getNumArgs() < 3)
4757 return Diag(Call->getEndLoc(),
4759 << 0 /*function call*/ << 3 << Call->getNumArgs()
4762 // Type-check the first argument normally.
4772 const Expr *Arg1 = Call->getArg(1)->IgnoreParens();
4773 const Type *Arg1Ty = Arg1->getType().getCanonicalType().getTypePtr();
4775 const Expr *Arg2 = Call->getArg(2)->IgnoreParens();
4776 const Type *Arg2Ty = Arg2->getType().getCanonicalType().getTypePtr();
4780 if (!Arg1Ty->isPointerType() || !IsSuitablyTypedFormatArgument(Arg1))
4781 Diag(Arg1->getBeginLoc(), diag::err_typecheck_convert_incompatible)
4782 << Arg1->getType() << ConstCharPtrTy << 1 /* different class */
4785 << 2 << Arg1->getType() << ConstCharPtrTy;
4788 if (Arg2Ty->getCanonicalTypeInternal().withoutLocalFastQualifiers() != SizeTy)
4789 Diag(Arg2->getBeginLoc(), diag::err_typecheck_convert_incompatible)
4790 << Arg2->getType() << SizeTy << 1 /* different class */
4793 << 3 << Arg2->getType() << SizeTy;
4803 TheCall->getFPFeaturesInEffect(getLangOpts()).getNoHonorNaNs())
4804 Diag(TheCall->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
4805 << 1 << 0 << TheCall->getSourceRange();
4807 ExprResult OrigArg0 = TheCall->getArg(0);
4808 ExprResult OrigArg1 = TheCall->getArg(1);
4813 OrigArg0, OrigArg1, TheCall->getExprLoc(), ACK_Comparison);
4820 TheCall->setArg(0, OrigArg0.get());
4821 TheCall->setArg(1, OrigArg1.get());
4823 if (OrigArg0.get()->isTypeDependent() || OrigArg1.get()->isTypeDependent())
4828 if (Res.isNull() || !Res->isRealFloatingType())
4829 return Diag(OrigArg0.get()->getBeginLoc(),
4831 << OrigArg0.get()->getType() << OrigArg1.get()->getType()
4832 << SourceRange(OrigArg0.get()->getBeginLoc(),
4833 OrigArg1.get()->getEndLoc());
4843 FPOptions FPO = TheCall->getFPFeaturesInEffect(getLangOpts());
4847 Diag(TheCall->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
4848 << 0 << 0 << TheCall->getSourceRange();
4852 Diag(TheCall->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
4853 << 1 << 0 << TheCall->getSourceRange();
4857 // Find out position of floating-point argument.
4858 unsigned FPArgNo = IsFPClass ? 0 : NumArgs - 1;
4860 // We can count on all parameters preceding the floating-point just being int.
4863 Expr *Arg = TheCall->getArg(i);
4865 if (Arg->isTypeDependent())
4872 TheCall->setArg(i, Res.get());
4875 Expr *OrigArg = TheCall->getArg(FPArgNo);
4877 if (OrigArg->isTypeDependent())
4882 // type how it is, but do normal L->Rvalue conversions.
4887 TheCall->setArg(FPArgNo, OrigArg);
4890 QualType ElementTy = OrigArg->getType();
4893 if (ElementTy->isVectorType() && IsFPClass) {
4895 ElementTy = ElementTy->castAs<VectorType>()->getElementType();
4898 // This operation requires a non-_Complex floating-point number.
4899 if (!ElementTy->isRealFloatingType())
4900 return Diag(OrigArg->getBeginLoc(),
4902 << OrigArg->getType() << OrigArg->getSourceRange();
4917 TheCall->setType(ResultTy);
4929 Expr *Arg = TheCall->getArg(I);
4930 QualType T = Arg->getType();
4931 if (T->isDependentType()) {
4938 if (!T->isRealFloatingType()) {
4939 return Diag(Arg->getBeginLoc(), diag::err_typecheck_call_requires_real_fp)
4940 << Arg->getType() << Arg->getSourceRange();
4946 TheCall->setArg(I, Converted.get());
4950 TheCall->setType(Context.DependentTy);
4954 Expr *Real = TheCall->getArg(0);
4955 Expr *Imag = TheCall->getArg(1);
4956 if (!Context.hasSameType(Real->getType(), Imag->getType())) {
4957 return Diag(Real->getBeginLoc(),
4959 << Real->getType() << Imag->getType()
4960 << Real->getSourceRange() << Imag->getSourceRange();
4966 if (Real->getType()->isFloat16Type())
4967 return Diag(TheCall->getBeginLoc(), diag::err_invalid_complex_spec)
4969 if (Real->getType()->isHalfType())
4970 return Diag(TheCall->getBeginLoc(), diag::err_invalid_complex_spec)
4973 TheCall->setType(Context.getComplexType(Real->getType()));
4977 /// BuiltinShuffleVector - Handle __builtin_shufflevector.
4980 if (TheCall->getNumArgs() < 2)
4981 return ExprError(Diag(TheCall->getEndLoc(),
4983 << 0 /*function call*/ << 2 << TheCall->getNumArgs()
4984 << /*is non object*/ 0 << TheCall->getSourceRange());
4989 QualType resType = TheCall->getArg(0)->getType();
4992 if (!TheCall->getArg(0)->isTypeDependent() &&
4993 !TheCall->getArg(1)->isTypeDependent()) {
4994 QualType LHSType = TheCall->getArg(0)->getType();
4995 QualType RHSType = TheCall->getArg(1)->getType();
4997 if (!LHSType->isVectorType() || !RHSType->isVectorType())
4999 Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
5000 << TheCall->getDirectCallee() << /*isMorethantwoArgs*/ false
5001 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5002 TheCall->getArg(1)->getEndLoc()));
5004 numElements = LHSType->castAs<VectorType>()->getNumElements();
5005 unsigned numResElements = TheCall->getNumArgs() - 2;
5010 if (TheCall->getNumArgs() == 2) {
5011 if (!RHSType->hasIntegerRepresentation() ||
5012 RHSType->castAs<VectorType>()->getNumElements() != numElements)
5013 return ExprError(Diag(TheCall->getBeginLoc(),
5015 << TheCall->getDirectCallee()
5017 << SourceRange(TheCall->getArg(1)->getBeginLoc(),
5018 TheCall->getArg(1)->getEndLoc()));
5020 return ExprError(Diag(TheCall->getBeginLoc(),
5022 << TheCall->getDirectCallee()
5024 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5025 TheCall->getArg(1)->getEndLoc()));
5027 QualType eltType = LHSType->castAs<VectorType>()->getElementType();
5033 for (unsigned i = 2; i < TheCall->getNumArgs(); i++) {
5034 if (TheCall->getArg(i)->isTypeDependent() ||
5035 TheCall->getArg(i)->isValueDependent())
5039 if (!(Result = TheCall->getArg(i)->getIntegerConstantExpr(Context)))
5040 return ExprError(Diag(TheCall->getBeginLoc(),
5042 << TheCall->getArg(i)->getSourceRange());
5044 // Allow -1 which will be translated to undef in the IR.
5045 if (Result->isSigned() && Result->isAllOnes())
5048 if (Result->getActiveBits() > 64 ||
5049 Result->getZExtValue() >= numElements * 2)
5050 return ExprError(Diag(TheCall->getBeginLoc(),
5052 << TheCall->getArg(i)->getSourceRange());
5057 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; i++) {
5058 exprs.push_back(TheCall->getArg(i));
5059 TheCall->setArg(i, nullptr);
5063 TheCall->getCallee()->getBeginLoc(),
5064 TheCall->getRParenLoc());
5072 QualType DstTy = TInfo->getType();
5073 QualType SrcTy = E->getType();
5075 if (!SrcTy->isVectorType() && !SrcTy->isDependentType())
5078 << E->getSourceRange());
5079 if (!DstTy->isVectorType() && !DstTy->isDependentType())
5084 if (!SrcTy->isDependentType() && !DstTy->isDependentType()) {
5085 unsigned SrcElts = SrcTy->castAs<VectorType>()->getNumElements();
5086 unsigned DstElts = DstTy->castAs<VectorType>()->getNumElements();
5090 << E->getSourceRange());
5098 unsigned NumArgs = TheCall->getNumArgs();
5101 return Diag(TheCall->getEndLoc(),
5104 << TheCall->getSourceRange();
5117 return Diag(TheCall->getBeginLoc(), diag::err_builtin_target_unsupported)
5118 << SourceRange(TheCall->getBeginLoc(), TheCall->getEndLoc());
5121 Expr *Arg = TheCall->getArg(0);
5122 if (Arg->isInstantiationDependent())
5125 QualType ArgTy = Arg->getType();
5126 if (!ArgTy->hasFloatingRepresentation())
5127 return Diag(TheCall->getEndLoc(), diag::err_typecheck_expect_flt_or_vector)
5129 if (Arg->isLValue()) {
5131 TheCall->setArg(0, FirstArg.get());
5133 TheCall->setType(TheCall->getArg(0)->getType());
5138 Expr *Arg = TheCall->getArg(0);
5139 if (Arg->isInstantiationDependent()) return false;
5141 if (Arg->HasSideEffects(Context))
5142 Diag(Arg->getBeginLoc(), diag::warn_assume_side_effects)
5143 << Arg->getSourceRange()
5144 << cast<FunctionDecl>(TheCall->getCalleeDecl())->getIdentifier();
5151 Expr *Arg = TheCall->getArg(1);
5154 if (!Arg->isTypeDependent() && !Arg->isValueDependent()) {
5156 dyn_cast<UnaryExprOrTypeTraitExpr>(Arg->IgnoreParenImpCasts()))
5157 if (UE->getKind() == UETT_AlignOf ||
5158 UE->getKind() == UETT_PreferredAlignOf)
5159 Diag(TheCall->getBeginLoc(), diag::warn_alloca_align_alignof)
5160 << Arg->getSourceRange();
5162 llvm::APSInt Result = Arg->EvaluateKnownConstInt(Context);
5165 return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
5166 << Arg->getSourceRange();
5169 return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_small)
5170 << (unsigned)Context.getCharWidth() << Arg->getSourceRange();
5173 return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_big)
5174 << std::numeric_limits<int32_t>::max() << Arg->getSourceRange();
5184 unsigned NumArgs = TheCall->getNumArgs();
5185 Expr *FirstArg = TheCall->getArg(0);
5192 /// In-place updation of FirstArg by checkBuiltinArgument is ignored.
5193 TheCall->setArg(0, FirstArgResult.get());
5197 Expr *SecondArg = TheCall->getArg(1);
5200 if (!SecondArg->isValueDependent()) {
5206 return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two)
5207 << SecondArg->getSourceRange();
5210 Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great)
5211 << SecondArg->getSourceRange() << Sema::MaximumAlignment;
5215 Expr *ThirdArg = TheCall->getArg(2);
5218 TheCall->setArg(2, ThirdArg);
5226 cast<FunctionDecl>(TheCall->getCalleeDecl())->getBuiltinID();
5229 unsigned NumArgs = TheCall->getNumArgs();
5232 return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
5234 << /*is non object*/ 0 << TheCall->getSourceRange();
5237 return Diag(TheCall->getEndLoc(),
5240 << /*is non object*/ 0 << TheCall->getSourceRange();
5246 ExprResult Arg(TheCall->getArg(i));
5252 TheCall->setArg(i, Arg.get());
5259 ExprResult Arg = CheckOSLogFormatStringArg(TheCall->getArg(i));
5262 TheCall->setArg(i, Arg.get());
5270 TheCall->getArg(i), VariadicFunction, nullptr);
5273 CharUnits ArgSize = Context.getTypeSizeInChars(Arg.get()->getType());
5275 return Diag(Arg.get()->getEndLoc(), diag::err_os_log_argument_too_big)
5277 << TheCall->getSourceRange();
5279 TheCall->setArg(i, Arg.get());
5283 // Check formatting specifiers. NOTE: We're only doing this for the non-size
5287 ArrayRef<const Expr *> Args(TheCall->getArgs(), TheCall->getNumArgs());
5290 VariadicFunction, TheCall->getBeginLoc(), SourceRange(),
5297 TheCall->setType(Context.getSizeType());
5299 TheCall->setType(Context.VoidPtrTy);
5306 Expr *Arg = TheCall->getArg(ArgNum);
5307 DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
5308 FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
5310 if (Arg->isTypeDependent() || Arg->isValueDependent()) return false;
5313 if (!(R = Arg->getIntegerConstantExpr(Context)))
5314 return Diag(TheCall->getBeginLoc(), diag::err_constant_integer_arg_type)
5315 << FDecl->getDeclName() << Arg->getSourceRange();
5327 Expr *Arg = TheCall->getArg(ArgNum);
5328 if (Arg->isTypeDependent() || Arg->isValueDependent())
5331 // Check constant-ness first.
5337 return Diag(TheCall->getBeginLoc(), diag::err_argument_invalid_range)
5338 << toString(Result, 10) << Low << High << Arg->getSourceRange();
5342 DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall,
5345 << Arg->getSourceRange());
5356 Expr *Arg = TheCall->getArg(ArgNum);
5357 if (Arg->isTypeDependent() || Arg->isValueDependent())
5360 // Check constant-ness first.
5365 return Diag(TheCall->getBeginLoc(), diag::err_argument_not_multiple)
5366 << Num << Arg->getSourceRange();
5375 Expr *Arg = TheCall->getArg(ArgNum);
5376 if (Arg->isTypeDependent() || Arg->isValueDependent())
5379 // Check constant-ness first.
5383 // Bit-twiddling to test for a power of 2: for x > 0, x & (x-1) is zero if
5385 if (Result.isStrictlyPositive() && (Result & (Result - 1)) == 0)
5388 return Diag(TheCall->getBeginLoc(), diag::err_argument_not_power_of_2)
5389 << Arg->getSourceRange();
5419 Expr *Arg = TheCall->getArg(ArgNum);
5420 if (Arg->isTypeDependent() || Arg->isValueDependent())
5423 // Check constant-ness first.
5434 return Diag(TheCall->getBeginLoc(), diag::err_argument_not_shifted_byte)
5435 << Arg->getSourceRange();
5443 Expr *Arg = TheCall->getArg(ArgNum);
5444 if (Arg->isTypeDependent() || Arg->isValueDependent())
5447 // Check constant-ness first.
5460 return Diag(TheCall->getBeginLoc(),
5462 << Arg->getSourceRange();
5467 return Diag(TheCall->getBeginLoc(), diag::err_builtin_longjmp_unsupported)
5468 << SourceRange(TheCall->getBeginLoc(), TheCall->getEndLoc());
5470 Expr *Arg = TheCall->getArg(1);
5478 return Diag(TheCall->getBeginLoc(), diag::err_builtin_longjmp_invalid_val)
5479 << SourceRange(Arg->getBeginLoc(), Arg->getEndLoc());
5486 return Diag(TheCall->getBeginLoc(), diag::err_builtin_setjmp_unsupported)
5487 << SourceRange(TheCall->getBeginLoc(), TheCall->getEndLoc());
5494 enum { Unknown = -1, AllCovered = -2 };
5602 return FExpr->getString().drop_front(Offset);
5606 return FExpr->getByteLength() - getCharByteWidth() * Offset;
5609 unsigned getLength() const { return FExpr->getLength() - Offset; }
5610 unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
5612 StringLiteralKind getKind() const { return FExpr->getKind(); }
5614 QualType getType() const { return FExpr->getType(); }
5616 bool isAscii() const { return FExpr->isOrdinary(); }
5617 bool isWide() const { return FExpr->isWide(); }
5618 bool isUTF8() const { return FExpr->isUTF8(); }
5619 bool isUTF16() const { return FExpr->isUTF16(); }
5620 bool isUTF32() const { return FExpr->isUTF32(); }
5621 bool isPascal() const { return FExpr->isPascal(); }
5627 return FExpr->getLocationOfByte(ByteNo + Offset, SM, Features, Target,
5632 return FExpr->getBeginLoc().getLocWithOffset(Offset);
5635 SourceLocation getEndLoc() const LLVM_READONLY { return FExpr->getEndLoc(); }
5668 if (E->isTypeDependent() || E->isValueDependent())
5671 E = E->IgnoreParenCasts();
5673 if (E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull))
5674 // Technically -Wformat-nonliteral does not warn about this case.
5680 switch (E->getStmtClass()) {
5692 // The expression is a literal if both sub-expressions were, and it was
5693 // completely checked only if both sub-expressions were checked.
5697 // Determine whether it is necessary to check both sub-expressions, for
5703 if (C->getCond()->EvaluateAsBooleanCondition(
5719 Left = checkFormatStringExpr(S, C->getTrueExpr(), Args, APK, format_idx,
5729 S, C->getFalseExpr(), Args, APK, format_idx, firstDataArg, Type,
5737 E = cast<ImplicitCastExpr>(E)->getSubExpr();
5741 if (const Expr *src = cast<OpaqueValueExpr>(E)->getSourceExpr()) {
5758 if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
5760 QualType T = DR->getType();
5763 isConstant = AT->getElementType().isConstant(S.Context);
5764 } else if (const PointerType *PT = T->getAs<PointerType>()) {
5766 PT->getPointeeType().isConstant(S.Context);
5767 } else if (T->isObjCObjectPointerType()) {
5774 if (const Expr *Init = VD->getAnyInitializer()) {
5777 if (InitList->isStringLiteralInit())
5778 Init = InitList->getInit(0)->IgnoreParenImpCasts();
5824 if (const auto *D = dyn_cast<Decl>(PV->getDeclContext())) {
5825 for (const auto *PVFormat : D->specific_attrs<FormatAttr>()) {
5828 IsCXXMember = MD->isInstance();
5831 if (const FunctionType *FnTy = D->getFunctionType())
5832 IsVariadic = cast<FunctionProtoType>(FnTy)->isVariadic();
5834 IsVariadic = BD->isVariadic();
5836 IsVariadic = OMD->isVariadic();
5843 if (PV->getFunctionScopeIndex() == CallerFSI.FormatIdx &&
5871 if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) {
5874 for (const auto *FA : ND->specific_attrs<FormatArgAttr>()) {
5875 const Expr *Arg = CE->getArg(FA->getFormatIdx().getASTIndex());
5889 unsigned BuiltinID = FD->getBuiltinID();
5892 const Expr *Arg = CE->getArg(0);
5909 if (const auto *MD = ME->getMethodDecl()) {
5910 if (const auto *FA = MD->getAttr<FormatArgAttr>()) {
5911 // As a special case heuristic, if we're using the method -[NSBundle
5919 if (MD->isInstanceMethod() && (IFace = MD->getClassInterface()) &&
5920 IFace->getIdentifier()->isStr("NSBundle") &&
5921 MD->getSelector().isKeywordSelector(
5926 const Expr *Arg = ME->getArg(FA->getFormatIdx().getASTIndex());
5941 StrE = ObjCFExpr->getString();
5946 if (Offset.isNegative() || Offset > StrE->getLength()) {
5964 if (BinOp->isAdditiveOp()) {
5967 bool LIsInt = BinOp->getLHS()->EvaluateAsInt(
5970 bool RIsInt = BinOp->getRHS()->EvaluateAsInt(
5975 BinaryOperatorKind BinOpKind = BinOp->getOpcode();
5980 E = BinOp->getRHS();
5985 E = BinOp->getLHS();
5995 auto ASE = dyn_cast<ArraySubscriptExpr>(UnaOp->getSubExpr());
5996 if (UnaOp->getOpcode() == UO_AddrOf && ASE) {
5998 if (ASE->getRHS()->EvaluateAsInt(IndexResult, S.Context,
6003 E = ASE->getBase();
6016 // If this expression can be evaluated at compile-time,
6022 if (E->EvaluateAsRValue(Result, Context) && Result.Val.isLValue()) {
6031 return llvm::StringSwitch<FormatStringType>(Format->getType()->getName())
6065 // CHECK: printf/scanf-like function is called with no format string.
6071 const Expr *OrigFormatExpr = Args[format_idx]->IgnoreParenCasts();
6104 // so it is safe to pass a non-literal string.
6112 SourceLocation FormatLoc = Args[format_idx]->getBeginLoc();
6116 // If there are no arguments specified, warn with -Wformat-security, otherwise
6117 // warn only with -Wformat-nonliteral.
6120 << OrigFormatExpr->getSourceRange();
6137 << OrigFormatExpr->getSourceRange();
6250 return OrigFormatExpr->getSourceRange();
6256 SourceLocation End = getLocationOfByte(startSpecifier + specifierLen - 1);
6258 // Advance the end SourceLocation by one due to half-open ranges.
6265 return FExpr->getLocationOfByte(x - Beg, S.getSourceManager(),
6295 << FixedLM->toString()
6296 << FixItHint::CreateReplacement(LMRange, FixedLM->toString());
6329 << FixedLM->toString()
6330 << FixItHint::CreateReplacement(LMRange, FixedLM->toString());
6357 << FixedCS->toString()
6358 << FixItHint::CreateReplacement(CSRange, FixedCS->toString());
6433 SourceLocation Loc = ArgExpr->getBeginLoc();
6440 PDiag << E->getSourceRange();
6445 DiagnosticExprs[0]->getSourceRange());
6472 // If the specifier in non-printable, it could be the first byte of a UTF-8
6473 // sequence. In that case, print the UTF-8 code point. If not, print the byte
6586 S.Diag(IsStringLocation ? ArgumentExpr->getExprLoc() : Loc, PDiag)
6587 << ArgumentExpr->getSourceRange();
6598 //===--- CHECK: Printf format string checking -----------------------------===//
6714 QualType T = Arg->getType();
6722 << T << Arg->getSourceRange(),
6813 auto Range = getSpecifierRange(flagsStart, flagsEnd - flagsStart + 1);
6827 const RecordType *RT = Ty->getAs<RecordType>();
6832 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
6833 if (!RD || !RD->getDefinition())
6842 if (S.LookupQualifiedName(R, RT->getDecl()))
6844 NamedDecl *decl = (*I)->getUnderlyingDecl();
6853 /// FIXME: This returns the wrong results in some cases (if cv-qualifiers don't
6859 CXXRecordMembersNamed<CXXMethodDecl>("c_str", *this, E->getType());
6862 if ((*MI)->getMinRequiredArguments() == 0)
6875 CXXRecordMembersNamed<CXXMethodDecl>("c_str", S, E->getType());
6880 if (Method->getMinRequiredArguments() == 0 &&
6881 AT.matchesType(S.Context, Method->getReturnType())) {
6883 SourceLocation EndLoc = S.getLocForEndOfToken(E->getEndLoc());
6884 S.Diag(E->getBeginLoc(), diag::note_printf_c_str)
6955 if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType()))
6958 << AT.getRepresentativeTypeName(S.Context) << Ex->getType()
6959 << false << Ex->getSourceRange(),
6960 Ex->getBeginLoc(), /*IsStringLocation*/ false,
6966 if (AT2.isValid() && !AT2.matchesType(S.Context, Ex->getType()))
6969 << AT2.getRepresentativeTypeName(S.Context) << Ex->getType()
6970 << false << Ex->getSourceRange(),
6971 Ex->getBeginLoc(), /*IsStringLocation*/ false,
6977 // Check for using an Objective-C specific conversion specifier
6978 // in a non-ObjC literal.
7075 if (FS.hasLeadingZeros() && FS.isLeftJustified()) // '0' ignored by '-'
7111 const Expr *Inside = E->IgnoreImpCasts();
7113 Inside = POE->getSyntacticForm()->IgnoreImpCasts();
7115 switch (Inside->getStmtClass()) {
7149 while (const TypedefType *UserTy = TyTy->getAs<TypedefType>()) {
7150 StringRef Name = UserTy->getDecl()->getName();
7162 TyTy = UserTy->desugar();
7168 PE->getSubExpr()->getType(),
7169 PE->getSubExpr());
7181 CO->getTrueExpr()->getType(),
7182 CO->getTrueExpr());
7185 CO->getFalseExpr()->getType(),
7186 CO->getFalseExpr());
7200 /// type. Bit-field 'promotions' from a higher ranked type to a lower ranked
7204 QualType From = ICE->getSubExpr()->getType();
7205 QualType To = ICE->getType();
7208 if (ICE->getCastKind() == CK_IntegralCast &&
7214 if (const auto *VecTy = From->getAs<ExtVectorType>())
7215 From = VecTy->getElementType();
7216 if (const auto *VecTy = To->getAs<ExtVectorType>())
7217 To = VecTy->getElementType();
7219 return ICE->getCastKind() == CK_FloatingCast &&
7250 QualType ExprTy = E->getType();
7252 ExprTy = TET->getUnderlyingExpr()->getType();
7258 if (ExprTy->canDecayToPointerType())
7262 // -Wformat diagnostics, this is fine from a type perspective, but it still
7265 E->isKnownToHaveBooleanValue()) {
7273 E->getExprLoc(), false, CSR);
7278 // dumping raw class data (like is-a pointer), not actual data.
7280 ExprTy->isObjCObjectPointerType()) {
7284 E->getExprLoc(), false, CSR);
7292 Match = handleFormatSignedness(Match, S.getDiagnostics(), E->getExprLoc());
7306 E = ICE->getSubExpr();
7307 ExprTy = E->getType();
7312 if (ICE->getType() == S.Context.IntTy ||
7313 ICE->getType() == S.Context.UnsignedIntTy) {
7320 // might introduce new unexpected warnings from -Wformat-signedness.
7323 ImplicitMatch, S.getDiagnostics(), E->getExprLoc());
7336 if (llvm::isUIntN(S.Context.getCharWidth(), CL->getValue())) {
7348 // For NSLog in ObjC, just preserve -Wformat behavior
7364 if (auto EnumTy = ExprTy->getAs<EnumType>()) {
7365 IntendedTy = EnumTy->getDecl()->getIntegerType();
7366 if (EnumTy->isUnscopedEnumerationType()) {
7376 // %C in an Objective-C context prints a unichar, not a wchar_t.
7381 if (ExprTy->isIntegralOrUnscopedEnumerationType() &&
7382 !ExprTy->isCharType()) {
7390 const llvm::APInt &V = IL->getValue();
7395 LookupResult Result(S, &S.Context.Idents.get("unichar"), E->getBeginLoc(),
7400 if (TD->getUnderlyingType() == IntendedTy)
7406 // Special-case some of Darwin's platform-independence types by suggesting
7446 llvm_unreachable("expected non-matching");
7462 << IntendedTy << IsEnum << E->getSourceRange(),
7463 E->getBeginLoc(),
7469 // NSInteger on 32-bit platforms, where it is typedef'd as 'int', but
7470 // should be printed as 'long' for 64-bit compatibility.)
7483 E->getExprLoc());
7489 SourceRange CastRange(CCast->getLParenLoc(), CCast->getRParenLoc());
7494 // just write the C-style cast.
7496 FixItHint::CreateInsertion(E->getBeginLoc(), CastFix.str()));
7501 FixItHint::CreateInsertion(E->getBeginLoc(), CastFix.str()));
7505 SourceLocation EndLoc = S.SourceMgr.getSpellingLoc(E->getEndLoc());
7516 if (const auto *TypedefTy = ExprTy->getAs<TypedefType>())
7517 Name = TypedefTy->getDecl()->getName();
7524 << E->getSourceRange(),
7525 E->getBeginLoc(), /*IsStringLocation=*/false,
7539 << IsEnum << E->getSourceRange(),
7540 E->getBeginLoc(), /*IsStringLocation*/ false, SpecRange, Hints);
7546 // Since the warning for passing non-POD types to variadic functions
7547 // was deferred until now, we emit a warning for non-POD
7559 llvm_unreachable("expected non-matching");
7573 << IsEnum << CSR << E->getSourceRange(),
7574 E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
7586 << E->getSourceRange(),
7587 E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
7595 else if (ExprTy->isObjCObjectType())
7600 << E->getSourceRange(),
7601 E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
7605 S.Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg_format)
7607 << AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
7620 << E->getSourceRange(),
7621 E->getBeginLoc(), false, CSR);
7632 //===--- CHECK: Scanf format string checking ------------------------------===//
7669 getSpecifierRange(start, end - start));
7708 // Check if the field with is non-zero.
7769 AT.matchesType(S.Context, Ex->getType());
7770 Match = handleFormatSignedness(Match, S.getDiagnostics(), Ex->getExprLoc());
7776 bool Success = fixedFS.fixType(Ex->getType(), Ex->IgnoreImpCasts()->getType(),
7791 << Ex->getType() << false << Ex->getSourceRange(),
7792 Ex->getBeginLoc(),
7800 << Ex->getType() << false << Ex->getSourceRange(),
7801 Ex->getBeginLoc(),
7817 if (!FExpr->isAscii() && !FExpr->isUTF8()) {
7820 S.PDiag(diag::warn_format_string_is_wide_literal), FExpr->getBeginLoc(),
7821 /*IsStringLocation*/ true, OrigFormatExpr->getSourceRange());
7825 // Str - The format string. NOTE: this is NOT null-terminated!
7826 StringRef StrRef = FExpr->getString();
7830 S.Context.getAsConstantArrayType(FExpr->getType());
7832 size_t TypeSize = T->getZExtSize();
7833 size_t StrLen = std::min(std::max(TypeSize, size_t(1)) - 1, StrRef.size());
7834 const unsigned numDataArgs = Args.size() - firstDataArg;
7847 FExpr->getBeginLoc(),
7848 /*IsStringLocation=*/true, OrigFormatExpr->getSourceRange());
7856 S.PDiag(diag::warn_empty_format_string), FExpr->getBeginLoc(),
7857 /*IsStringLocation*/ true, OrigFormatExpr->getSourceRange());
7886 // Str - The format string. NOTE: this is NOT null-terminated!
7887 StringRef StrRef = FExpr->getString();
7890 const ConstantArrayType *T = Context.getAsConstantArrayType(FExpr->getType());
7892 size_t TypeSize = T->getZExtSize();
7893 size_t StrLen = std::min(std::max(TypeSize, size_t(1)) - 1, StrRef.size());
7899 //===--- CHECK: Warn on use of wrong absolute value function. -------------===//
7963 const FunctionProtoType *FT = BuiltinType->getAs<FunctionProtoType>();
7967 if (FT->getNumParams() != 1)
7970 return FT->getParamType(0);
8001 if (T->isIntegralOrEnumerationType())
8003 if (T->isRealFloatingType())
8005 if (T->isAnyComplexType())
8078 const IdentifierInfo *FnInfo = FDecl->getIdentifier();
8082 switch (FDecl->getBuiltinID()) {
8103 return FDecl->getBuiltinID();
8115 if (S.getLangOpts().CPlusPlus && !ArgType->isAnyComplexType()) {
8117 if (ArgType->isIntegralOrEnumerationType()) {
8119 } else if (ArgType->isRealFloatingType()) {
8134 FDecl = dyn_cast<FunctionDecl>(UsingD->getTargetDecl());
8142 if (FDecl->getNumParams() != 1)
8146 QualType ParamType = FDecl->getParamDecl(0)->getType();
8168 if (FD && FD->getBuiltinID() == AbsKind) {
8197 if (!FDecl->getIdentifier() || !FDecl->getIdentifier()->isStr(Str))
8199 if (!FDecl->isInStdNamespace())
8207 FPOptions FPO = Call->getFPFeaturesInEffect(getLangOpts());
8209 (Call->getBuiltinCallee() == Builtin::BI__builtin_nanf)) &&
8211 Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
8212 << 1 << 0 << Call->getSourceRange();
8215 (FDecl->getIdentifier() && FDecl->getName() == "infinity"))) &&
8217 Diag(Call->getBeginLoc(), diag::warn_fp_nan_inf_when_disabled)
8218 << 0 << 0 << Call->getSourceRange();
8223 if (Call->getNumArgs() != 1)
8231 QualType ArgType = Call->getArg(0)->IgnoreParenImpCasts()->getType();
8232 QualType ParamType = Call->getArg(0)->getType();
8236 if (ArgType->isUnsignedIntegerType()) {
8239 Diag(Call->getExprLoc(), diag::warn_unsigned_abs) << ArgType << ParamType;
8240 Diag(Call->getExprLoc(), diag::note_remove_abs)
8242 << FixItHint::CreateRemoval(Call->getCallee()->getSourceRange());
8248 if (ArgType->isPointerType() || ArgType->canDecayToPointerType()) {
8250 if (ArgType->isFunctionType())
8252 else if (ArgType->isArrayType())
8255 Diag(Call->getExprLoc(), diag::warn_pointer_abs) << DiagType << ArgType;
8274 Diag(Call->getExprLoc(), diag::warn_abs_too_small)
8280 emitReplacement(*this, Call->getExprLoc(),
8281 Call->getCallee()->getSourceRange(), NewAbsKind, ArgType);
8293 Diag(Call->getExprLoc(), diag::warn_wrong_absolute_value_type)
8296 emitReplacement(*this, Call->getExprLoc(),
8297 Call->getCallee()->getSourceRange(), NewAbsKind, ArgType);
8300 //===--- CHECK: Warn on use of std::max and unsigned zero. r---------------===//
8307 if (Call->getExprLoc().isMacroID()) return;
8310 if (Call->getNumArgs() != 2) return;
8312 const auto * ArgList = FDecl->getTemplateSpecializationArgs();
8314 if (ArgList->size() != 1) return;
8317 const auto& TA = ArgList->get(0);
8320 if (!ArgType->isUnsignedIntegerType()) return;
8323 auto IsLiteralZeroArg = [](const Expr* E) -> bool {
8326 const auto *Num = dyn_cast<IntegerLiteral>(MTE->getSubExpr());
8328 if (Num->getValue() != 0) return false;
8332 const Expr *FirstArg = Call->getArg(0);
8333 const Expr *SecondArg = Call->getArg(1);
8340 SourceRange FirstRange = FirstArg->getSourceRange();
8341 SourceRange SecondRange = SecondArg->getSourceRange();
8345 Diag(Call->getExprLoc(), diag::warn_max_unsigned_zero)
8346 << IsFirstArgZero << Call->getCallee()->getSourceRange() << ZeroRange;
8352 SecondRange.getBegin().getLocWithOffset(-1));
8358 Diag(Call->getExprLoc(), diag::note_remove_max_call)
8359 << FixItHint::CreateRemoval(Call->getCallee()->getSourceRange())
8363 //===--- CHECK: Standard memory functions ---------------------------------===//
8378 if (!Size->isComparisonOp() && !Size->isLogicalOp())
8381 SourceRange SizeRange = Size->getSourceRange();
8382 S.Diag(Size->getOperatorLoc(), diag::warn_memsize_comparison)
8387 S.getLocForEndOfToken(Size->getLHS()->getEndLoc()), ")")
8402 const Type *Ty = T->getBaseElementTypeUnsafe();
8405 const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
8406 RD = RD ? RD->getDefinition() : nullptr;
8407 if (!RD || RD->isInvalidDecl())
8410 if (RD->isDynamicClass())
8416 for (auto *FD : RD->fields()) {
8419 getContainedDynamicClass(FD->getType(), SubContained)) {
8430 if (Unary->getKind() == UETT_SizeOf)
8439 if (!SizeOf->isArgumentType())
8440 return SizeOf->getArgumentExpr()->IgnoreParenImpCasts();
8447 return SizeOf->getTypeOfArgument();
8477 for (const FieldDecl *FD : FT->castAs<RecordType>()->getDecl()->fields())
8478 visit(FD->getType(), FD->getLocation());
8519 for (const FieldDecl *FD : FT->castAs<RecordType>()->getDecl()->fields())
8520 visit(FD->getType(), FD->getLocation());
8545 SizeofExpr = SizeofExpr->IgnoreParenImpCasts();
8548 if (BO->getOpcode() != BO_Mul && BO->getOpcode() != BO_Add)
8551 return doesExprLikelyComputeSize(BO->getLHS()) ||
8552 doesExprLikelyComputeSize(BO->getRHS());
8585 Call->getArg(BId == Builtin::BImemset ? 2 : 1)->IgnoreImpCasts();
8589 cast<IntegerLiteral>(E)->getValue() == 0) ||
8591 cast<CharacterLiteral>(E)->getValue() == 0);
8595 SourceLocation CallLoc = Call->getRParenLoc();
8598 !isArgumentExpandedFromMacro(SM, CallLoc, SizeArg->getExprLoc())) {
8600 SourceLocation DiagLoc = SizeArg->getExprLoc();
8609 } else if (!isLiteralZero(Call->getArg(1)->IgnoreImpCasts())) {
8620 doesExprLikelyComputeSize(Call->getArg(1)) &&
8621 !doesExprLikelyComputeSize(Call->getArg(2))) {
8622 SourceLocation DiagLoc = Call->getArg(1)->getExprLoc();
8634 // It is possible to have a non-standard definition of memset. Validate
8638 if (Call->getNumArgs() < ExpectedNumArgs)
8645 const Expr *LenExpr = Call->getArg(LenArg)->IgnoreParenImpCasts();
8648 Call->getBeginLoc(), Call->getRParenLoc()))
8662 QualType FirstArgTy = Call->getArg(0)->IgnoreParenImpCasts()->getType();
8663 if (BId == Builtin::BIbzero && !FirstArgTy->getAs<PointerType>())
8667 const Expr *Dest = Call->getArg(ArgIdx)->IgnoreParenImpCasts();
8668 SourceRange ArgRange = Call->getArg(ArgIdx)->getSourceRange();
8670 QualType DestTy = Dest->getType();
8672 if (const PointerType *DestPtrTy = DestTy->getAs<PointerType>()) {
8673 PointeeTy = DestPtrTy->getPointeeType();
8677 if (PointeeTy->isVoidType())
8680 // Catch "memset(p, 0, sizeof(p))" -- needs to be sizeof(*p). Do this by
8686 SizeOfArg->getExprLoc())) {
8690 SizeOfArg->Profile(SizeOfArgID, Context, true);
8692 Dest->Profile(DestID, Context, true);
8697 StringRef ReadableName = FnName->getName();
8700 if (UnaryOp->getOpcode() == UO_AddrOf)
8701 ActionIdx = 1; // If its an address-of operator, just remove it.
8702 if (!PointeeTy->isIncompleteType() &&
8709 SourceLocation SL = SizeOfArg->getExprLoc();
8710 SourceRange DSR = Dest->getSourceRange();
8711 SourceRange SSR = SizeOfArg->getSourceRange();
8740 // type as the memory argument, and where it points to a user-defined
8743 if (PointeeTy->isRecordType() &&
8745 DiagRuntimeBehavior(LenExpr->getExprLoc(), Dest,
8748 << PointeeTy << Dest->getSourceRange()
8749 << LenExpr->getSourceRange());
8753 } else if (DestTy->isArrayType()) {
8778 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
8782 << Call->getCallee()->getSourceRange());
8786 Dest->getExprLoc(), Dest,
8789 << Call->getCallee()->getSourceRange());
8790 else if (const auto *RT = PointeeTy->getAs<RecordType>()) {
8792 RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize()) {
8793 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
8798 RT->getDecl()->isNonTrivialToPrimitiveCopy()) {
8799 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
8810 Dest->getExprLoc(), Dest,
8821 Ex = Ex->IgnoreParenCasts();
8825 if (!BO || !BO->isAdditiveOp())
8828 const Expr *RHS = BO->getRHS()->IgnoreParenCasts();
8829 const Expr *LHS = BO->getLHS()->IgnoreParenCasts();
8844 // Only handle constant-sized or VLAs, but not flexible members.
8847 if (CAT->getZExtSize() <= 1)
8849 } else if (!Ty->isVariableArrayType()) {
8859 unsigned NumArgs = Call->getNumArgs();
8863 const Expr *SrcArg = ignoreLiteralAdditions(Call->getArg(1), Context);
8864 const Expr *SizeArg = ignoreLiteralAdditions(Call->getArg(2), Context);
8868 Call->getBeginLoc(), Call->getRParenLoc()))
8877 if (SizeCall->getBuiltinCallee() == Builtin::BIstrlen &&
8878 SizeCall->getNumArgs() == 1)
8879 CompareWithSrc = ignoreLiteralAdditions(SizeCall->getArg(0), Context);
8896 SrcArgDRE->getDecl() != CompareWithSrcDRE->getDecl())
8899 const Expr *OriginalSizeArg = Call->getArg(2);
8900 Diag(CompareWithSrcDRE->getBeginLoc(), diag::warn_strlcpycat_wrong_size)
8901 << OriginalSizeArg->getSourceRange() << FnName;
8906 // we could say 'sizeof(array)-2'.
8907 const Expr *DstArg = Call->getArg(0)->IgnoreParenImpCasts();
8908 if (!isConstantSizeArrayWithMoreThanOneElement(DstArg->getType(), Context))
8914 DstArg->printPretty(OS, nullptr, getPrintingPolicy());
8917 Diag(OriginalSizeArg->getBeginLoc(), diag::note_strlcpycat_wrong_size)
8918 << FixItHint::CreateReplacement(OriginalSizeArg->getSourceRange(),
8926 return D1->getDecl() == D2->getDecl();
8932 const FunctionDecl *FD = CE->getDirectCallee();
8933 if (!FD || FD->getMemoryFunctionKind() != Builtin::BIstrlen)
8935 return CE->getArg(0)->IgnoreParenCasts();
8943 if (CE->getNumArgs() < 3)
8945 const Expr *DstArg = CE->getArg(0)->IgnoreParenCasts();
8946 const Expr *SrcArg = CE->getArg(1)->IgnoreParenCasts();
8947 const Expr *LenArg = CE->getArg(2)->IgnoreParenCasts();
8949 if (CheckMemorySizeofForComparison(*this, LenArg, FnName, CE->getBeginLoc(),
8950 CE->getRParenLoc()))
8957 // - sizeof(dst)
8960 // - sizeof(src)
8964 if (BE->getOpcode() == BO_Sub) {
8965 const Expr *L = BE->getLHS()->IgnoreParenCasts();
8966 const Expr *R = BE->getRHS()->IgnoreParenCasts();
8967 // - sizeof(dst) - strlen(dst)
8971 // - sizeof(src) - (anything)
8981 SourceLocation SL = LenArg->getBeginLoc();
8982 SourceRange SR = LenArg->getSourceRange();
8993 QualType DstTy = DstArg->getType();
9012 DstArg->printPretty(OS, nullptr, getPrintingPolicy());
9013 OS << ") - ";
9015 DstArg->printPretty(OS, nullptr, getPrintingPolicy());
9016 OS << ") - 1";
9026 S.Diag(UnaryExpr->getBeginLoc(), diag::warn_free_nonheap_object)
9034 if (const auto *Lvalue = dyn_cast<DeclRefExpr>(UnaryExpr->getSubExpr())) {
9035 const Decl *D = Lvalue->getDecl();
9037 if (!dyn_cast<DeclaratorDecl>(D)->getType()->isReferenceType())
9041 if (const auto *Lvalue = dyn_cast<MemberExpr>(UnaryExpr->getSubExpr()))
9043 Lvalue->getMemberDecl());
9049 UnaryExpr->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens());
9053 S.Diag(Lambda->getBeginLoc(), diag::warn_free_nonheap_object)
9059 const auto *Var = dyn_cast<VarDecl>(Lvalue->getDecl());
9063 S.Diag(Lvalue->getBeginLoc(), diag::warn_free_nonheap_object)
9072 clang::CastKind Kind = Cast->getCastKind();
9074 !Cast->getSubExpr()->getType()->isFunctionPointerType())
9078 Cast->getSubExpr()->IgnoreParenImpCasts()->IgnoreParens()))
9081 switch (Cast->getCastKind()) {
9086 Cast->printPretty(OS, nullptr, S.getPrintingPolicy());
9093 S.Diag(Cast->getBeginLoc(), diag::warn_free_nonheap_object)
9100 cast<FunctionDecl>(E->getCalleeDecl())->getQualifiedNameAsString();
9103 const Expr *Arg = E->getArg(0)->IgnoreParenCasts();
9105 switch (UnaryExpr->getOpcode()) {
9115 if (Lvalue->getType()->isArrayType())
9119 Diag(Label->getBeginLoc(), diag::warn_free_nonheap_object)
9120 << CalleeName << 0 /*object: */ << Label->getLabel()->getIdentifier();
9125 Diag(Arg->getBeginLoc(), diag::warn_free_nonheap_object)
9131 if (const auto *Cast = dyn_cast<CastExpr>(E->getArg(0)))
9146 << (isObjCMethod ? 1 : 0) << RetValExp->getSourceRange();
9149 // If an allocation function declared with a non-throwing
9150 // exception-specification fails to allocate storage, it shall return
9154 OverloadedOperatorKind Op = FD->getOverloadedOperator();
9157 = FD->getType()->castAs<FunctionProtoType>();
9158 if (!Proto->isNothrow(/*ResultIfDependent*/true) &&
9165 if (RetValExp && RetValExp->getType()->isWebAssemblyTableType()) {
9169 // PPC MMA non-pointer types are not allowed as return type. Checking the type
9172 PPC().CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
9184 FPLiteral = dyn_cast<FloatingLiteral>(L->IgnoreParens());
9185 FPCast = dyn_cast<CastExpr>(R->IgnoreParens());
9190 auto *SourceTy = FPCast->getSubExpr()->getType()->getAs<BuiltinType>();
9191 auto *TargetTy = FPLiteral->getType()->getAs<BuiltinType>();
9192 if (SourceTy && TargetTy && SourceTy->isFloatingPoint() &&
9193 TargetTy->isFloatingPoint()) {
9195 llvm::APFloat TargetC = FPLiteral->getValue();
9203 << LHS->getSourceRange() << RHS->getSourceRange();
9209 // Match a more general floating-point equality comparison (-Wfloat-equal).
9210 Expr* LeftExprSansParen = LHS->IgnoreParenImpCasts();
9211 Expr* RightExprSansParen = RHS->IgnoreParenImpCasts();
9217 if (DRL->getDecl() == DRR->getDecl())
9226 if (FLL->isExact())
9230 if (FLR->isExact())
9235 if (CL->getBuiltinCallee())
9239 if (CR->getBuiltinCallee())
9244 << LHS->getSourceRange() << RHS->getSourceRange();
9247 //===--- CHECK: Integer mixed-sign comparisons (-Wsign-compare) --------===//
9248 //===--- CHECK: Lossy implicit conversions (-Wconversion) --------------===//
9252 /// Structure recording the 'active' range of an integer-valued
9269 return NonNegative ? Width : Width - 1;
9280 T->getCanonicalTypeInternal().getTypePtr());
9285 assert(T->isCanonicalUnqualified());
9288 T = VT->getElementType().getTypePtr();
9290 T = CT->getElementType().getTypePtr();
9292 T = AT->getValueType().getTypePtr();
9297 T = ET->getDecl()->getIntegerType().getDesugaredType(C).getTypePtr();
9300 EnumDecl *Enum = ET->getDecl();
9303 if (Enum->isFixed()) {
9305 !ET->isSignedIntegerOrEnumerationType());
9308 unsigned NumPositive = Enum->getNumPositiveBits();
9309 unsigned NumNegative = Enum->getNumNegativeBits();
9319 return IntRange(EIT->getNumBits(), EIT->isUnsigned());
9322 assert(BT->isInteger());
9324 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
9333 assert(T->isCanonicalUnqualified());
9336 T = VT->getElementType().getTypePtr();
9338 T = CT->getElementType().getTypePtr();
9340 T = AT->getValueType().getTypePtr();
9342 T = C.getCanonicalType(ET->getDecl()->getIntegerType()).getTypePtr();
9345 return IntRange(EIT->getNumBits(), EIT->isUnsigned());
9348 assert(BT->isInteger());
9350 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
9360 /// Return the range of a bitwise-AND of the two ranges.
9384 // We need a 1-bit-wider range if:
9397 // -2^L * -2^R = 2^(L + R)
9456 return IntRange(MaxWidth, Ty->isUnsignedIntegerOrEnumerationType());
9460 QualType Ty = E->getType();
9461 if (const AtomicType *AtomicRHS = Ty->getAs<AtomicType>())
9462 Ty = AtomicRHS->getValueType();
9466 /// Pseudo-evaluate the given integer expression, estimating the
9476 E = E->IgnoreParens();
9480 if (E->EvaluateAsRValue(result, C, InConstantContext))
9487 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
9488 return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
9493 bool isIntegerCast = CE->getCastKind() == CK_IntegralCast ||
9494 CE->getCastKind() == CK_BooleanToSignedIntegral;
9496 // Assume that non-integer casts can span the full range of the type.
9500 IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
9508 // Otherwise, we take the smaller width, and we're non-negative if
9517 if (CO->getCond()->EvaluateAsBooleanCondition(CondResult, C))
9519 CondResult ? CO->getTrueExpr() : CO->getFalseExpr(),
9525 Expr *E = CO->getTrueExpr();
9526 IntRange L = E->getType()->isVoidType()
9529 E = CO->getFalseExpr();
9530 IntRange R = E->getType()->isVoidType()
9539 switch (BO->getOpcode()) {
9543 // Boolean-valued operations are single-bit and positive.
9570 return GetExprRange(C, BO->getRHS(), MaxWidth, InConstantContext,
9573 // Operations with opaque sources are black-listed.
9578 // Bitwise-and uses the *infinum* of the two source ranges.
9584 // Left shift gets black-listed based on a judgement call.
9589 = dyn_cast<IntegerLiteral>(BO->getLHS()->IgnoreParenCasts())) {
9590 if (I->getValue() == 1) {
9603 IntRange L = GetExprRange(C, BO->getLHS(), MaxWidth, InConstantContext,
9609 BO->getRHS()->getIntegerConstantExpr(C)) {
9610 if (shift->isNonNegative()) {
9611 if (shift->uge(L.Width))
9614 L.Width -= shift->getZExtValue();
9623 return GetExprRange(C, BO->getRHS(), MaxWidth, InConstantContext,
9632 if (BO->getLHS()->getType()->isPointerType())
9646 // Don't 'pre-truncate' the operands.
9648 IntRange L = GetExprRange(C, BO->getLHS(), opWidth, InConstantContext,
9653 BO->getRHS()->getIntegerConstantExpr(C)) {
9654 unsigned log2 = divisor->logBase2(); // floor(log_2(divisor))
9658 L.Width = std::min(L.Width - log2, MaxWidth);
9664 // could be -1.
9665 IntRange R = GetExprRange(C, BO->getRHS(), opWidth, InConstantContext,
9685 GetExprRange(C, BO->getLHS(), opWidth, InConstantContext, Approximate);
9687 GetExprRange(C, BO->getRHS(), opWidth, InConstantContext, Approximate);
9689 C.NonNegative |= T->isUnsignedIntegerOrEnumerationType();
9695 switch (UO->getOpcode()) {
9696 // Boolean-valued operations are white-listed.
9700 // Operations with opaque sources are black-listed.
9706 return GetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
9712 return GetExprRange(C, OVE->getSourceExpr(), MaxWidth, InConstantContext,
9715 if (const auto *BitField = E->getSourceBitField())
9716 return IntRange(BitField->getBitWidthValue(C),
9717 BitField->getType()->isUnsignedIntegerOrEnumerationType());
9772 dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
9773 if (isa<EnumConstantDecl>(DR->getDecl()))
9778 // and Objective-C.
9779 SourceLocation BeginLoc = E->getBeginLoc();
9791 return E->getType()->isIntegerType() &&
9792 (!E->getType()->isSignedIntegerType() ||
9793 !E->IgnoreParenImpCasts()->getType()->isSignedIntegerType());
9800 /// |-----------| . . . |-----------|
9818 // a < 32-bit unsigned / <= 32-bit signed bit-field to 'signed int'.
9869 case -1: return Less;
9873 case -1: return InRange;
9924 if (ICE->getCastKind() != CK_IntegralCast &&
9925 ICE->getCastKind() != CK_NoOp)
9927 E = ICE->getSubExpr();
9930 return E->getType()->isEnumeralType();
9942 return BL->getValue() ? ConstantValueKind::LiteralTrue
9956 Constant = Constant->IgnoreParenImpCasts();
9957 Other = Other->IgnoreParenImpCasts();
9961 // - If the constant is outside the range of representable values of
9964 // - If the constant is the maximum / minimum in-range value. For an
9966 if (Constant->getType()->isEnumeralType() &&
9967 S.Context.hasSameUnqualifiedType(Constant->getType(), Other->getType()))
9973 QualType OtherT = Other->getType();
9974 if (const auto *AT = OtherT->getAs<AtomicType>())
9975 OtherT = AT->getValueType();
9981 S.ObjC().NSAPIObj->isObjCBOOLType(OtherT) &&
9982 OtherT->isSpecificBuiltinType(BuiltinType::SChar);
9987 !OtherT->isBooleanType() && Other->isKnownToHaveBooleanValue();
9996 auto Result = PromotedRange::constantValue(E->getOpcode(), Cmp, RhsConstant);
10007 if (auto TypeResult = PromotedRange::constantValue(E->getOpcode(), TypeCmp,
10015 // Don't warn if the non-constant operand actually always evaluates to the
10020 // Suppress the diagnostic for an in-range comparison if the constant comes
10030 // A comparison of an unsigned bit-field against 0 is really a type problem,
10031 // even though at the type level the bit-field might promote to 'signed int'.
10032 if (Other->refersToBitField() && InRange && Value == 0 &&
10033 Other->getType()->isUnsignedIntegerOrEnumerationType())
10040 ED = dyn_cast<EnumConstantDecl>(DR->getDecl());
10048 Constant->IgnoreParenImpCasts())) {
10049 OS << (BL->getValue() ? "YES" : "NO");
10055 S.Diag(E->getOperatorLoc(), diag::warn_tautological_compare_value_range)
10057 << E->getOpcodeStr() << OS.str() << *Result
10058 << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
10063 S.DiagRuntimeBehavior(E->getOperatorLoc(), E,
10069 // FIXME: We use a somewhat different formatting for the in-range cases and
10072 if (!InRange || Other->isKnownToHaveBooleanValue()) {
10075 E->getOperatorLoc(), E,
10080 << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange());
10091 S.Diag(E->getOperatorLoc(), Diag)
10092 << RhsConstant << OtherT << E->getOpcodeStr() << OS.str() << *Result
10093 << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
10102 AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
10103 AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
10106 /// Implements -Wsign-compare.
10111 QualType T = E->getLHS()->getType();
10115 if (!S.Context.hasSameUnqualifiedType(T, E->getRHS()->getType()))
10118 // Don't analyze value-dependent comparisons directly.
10119 if (E->isValueDependent())
10122 Expr *LHS = E->getLHS();
10123 Expr *RHS = E->getRHS();
10125 if (T->isIntegralType(S.Context)) {
10127 RHS->getIntegerConstantExpr(S.Context);
10129 LHS->getIntegerConstantExpr(S.Context);
10150 if (!T->hasUnsignedIntegerRepresentation()) {
10157 LHS = LHS->IgnoreParenImpCasts();
10158 RHS = RHS->IgnoreParenImpCasts();
10164 if (const auto *TET = dyn_cast<TypeOfExprType>(LHS->getType()))
10165 LHS = TET->getUnderlyingExpr()->IgnoreParenImpCasts();
10166 if (const auto *TET = dyn_cast<TypeOfExprType>(RHS->getType()))
10167 RHS = TET->getUnderlyingExpr()->IgnoreParenImpCasts();
10173 if (LHS->getType()->hasSignedIntegerRepresentation()) {
10174 assert(!RHS->getType()->hasSignedIntegerRepresentation() &&
10178 } else if (RHS->getType()->hasSignedIntegerRepresentation()) {
10192 AnalyzeImplicitConversions(S, LHS, E->getOperatorLoc());
10193 AnalyzeImplicitConversions(S, RHS, E->getOperatorLoc());
10195 // If the signed range is non-negative, -Wsign-compare won't fire.
10203 if (E->isEqualityOp()) {
10210 // non-negative.
10217 S.DiagRuntimeBehavior(E->getOperatorLoc(), E,
10219 << LHS->getType() << RHS->getType()
10220 << LHS->getSourceRange() << RHS->getSourceRange());
10228 assert(Bitfield->isBitField());
10229 if (Bitfield->isInvalidDecl())
10232 // White-list bool bitfields.
10233 QualType BitfieldType = Bitfield->getType();
10234 if (BitfieldType->isBooleanType())
10237 if (BitfieldType->isEnumeralType()) {
10238 EnumDecl *BitfieldEnumDecl = BitfieldType->castAs<EnumType>()->getDecl();
10243 !BitfieldEnumDecl->getIntegerTypeSourceInfo() &&
10244 BitfieldEnumDecl->getNumPositiveBits() > 0 &&
10245 BitfieldEnumDecl->getNumNegativeBits() == 0) {
10251 // Ignore value- or type-dependent expressions.
10252 if (Bitfield->getBitWidth()->isValueDependent() ||
10253 Bitfield->getBitWidth()->isTypeDependent() ||
10254 Init->isValueDependent() ||
10255 Init->isTypeDependent())
10258 Expr *OriginalInit = Init->IgnoreParenImpCasts();
10259 unsigned FieldWidth = Bitfield->getBitWidthValue(S.Context);
10262 if (!OriginalInit->EvaluateAsInt(Result, S.Context,
10267 if (const auto *EnumTy = OriginalInit->getType()->getAs<EnumType>()) {
10268 EnumDecl *ED = EnumTy->getDecl();
10269 bool SignedBitfield = BitfieldType->isSignedIntegerType();
10274 bool SignedEnum = ED->getNumNegativeBits() > 0;
10285 ED->getNumPositiveBits() == FieldWidth) {
10291 TypeSourceInfo *TSI = Bitfield->getTypeSourceInfo();
10293 TSI ? TSI->getTypeLoc().getSourceRange() : SourceRange();
10294 S.Diag(Bitfield->getTypeSpecStartLoc(), diag::note_change_bitfield_sign)
10301 unsigned BitsNeeded = SignedEnum ? std::max(ED->getNumPositiveBits() + 1,
10302 ED->getNumNegativeBits())
10303 : ED->getNumPositiveBits();
10307 Expr *WidthExpr = Bitfield->getBitWidth();
10310 S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
10311 << BitsNeeded << ED << WidthExpr->getSourceRange();
10324 // bit-field as a Boolean, check to see if the value is 1 and we're assigning
10325 // to a one-bit bit-field to see if the value came from a macro named 'true'.
10328 SourceLocation MaybeMacroLoc = OriginalInit->getBeginLoc();
10336 if (UO->getOpcode() == UO_Minus || UO->getOpcode() == UO_Not)
10344 TruncatedValue.setIsSigned(BitfieldType->isSignedIntegerType());
10357 << PrettyValue << PrettyTrunc << OriginalInit->getType()
10358 << Init->getSourceRange();
10363 /// Analyze the given simple or compound assignment for warning-worthy
10367 AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
10371 if (FieldDecl *Bitfield = E->getLHS()->getSourceBitField()) {
10372 if (AnalyzeBitFieldAssignment(S, Bitfield, E->getRHS(),
10373 E->getOperatorLoc())) {
10375 return AnalyzeImplicitConversions(S, E->getRHS()->IgnoreParenImpCasts(),
10376 E->getOperatorLoc());
10380 AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
10382 // Diagnose implicitly sequentially-consistent atomic assignment.
10383 if (E->getLHS()->getType()->isAtomicType())
10384 S.Diag(E->getRHS()->getBeginLoc(), diag::warn_atomic_implicit_seq_cst);
10392 S.DiagRuntimeBehavior(E->getExprLoc(), E,
10394 << SourceType << T << E->getSourceRange()
10398 S.Diag(E->getExprLoc(), diag)
10399 << SourceType << T << E->getSourceRange() << SourceRange(CContext);
10406 DiagnoseImpCast(S, E, E->getType(), T, CContext, diag, pruneControlFlow);
10412 const bool IsBool = T->isSpecificBuiltinType(BuiltinType::Bool);
10415 Expr *InnerE = E->IgnoreParenImpCasts();
10416 // We also want to warn on, e.g., "int i = -1.234"
10418 if (UOp->getOpcode() == UO_Minus || UOp->getOpcode() == UO_Plus)
10419 InnerE = UOp->getSubExpr()->IgnoreParenImpCasts();
10426 E->EvaluateAsFloat(Value, S.Context, Expr::SE_AllowSideEffects);
10431 << E->getType());
10441 T->hasUnsignedIntegerRepresentation());
10467 // Conversion of a floating-point value to a non-bool integer where the
10481 if (Value.isZero()) { // Skip -0.0 to 0 conversion.
10485 // Warn on non-zero to zero conversion.
10511 S.DiagRuntimeBehavior(E->getExprLoc(), E,
10513 << E->getType() << T.getUnqualifiedType()
10515 << E->getSourceRange() << SourceRange(CContext));
10517 S.Diag(E->getExprLoc(), DiagID)
10518 << E->getType() << T.getUnqualifiedType() << PrettySourceValue
10519 << PrettyTargetValue << E->getSourceRange() << SourceRange(CContext);
10524 /// floating-point precision.
10529 AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
10530 AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
10532 if (E->getLHS()->getType()->isAtomicType())
10533 S.Diag(E->getOperatorLoc(), diag::warn_atomic_implicit_seq_cst);
10536 const auto *ResultBT = E->getLHS()->getType()->getAs<BuiltinType>();
10538 ->getComputationResultType()
10539 ->getAs<BuiltinType>();
10542 if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
10545 if (ResultBT->isInteger())
10546 return DiagnoseImpCast(S, E, E->getRHS()->getType(), E->getLHS()->getType(),
10547 E->getExprLoc(), diag::warn_impcast_float_integer);
10549 if (!ResultBT->isFloatingPoint())
10555 if (Order < 0 && !S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
10557 DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(), E->getOperatorLoc(),
10575 Expr *InnerE = Ex->IgnoreParenImpCasts();
10576 const Type *Target = S.Context.getCanonicalType(Ex->getType()).getTypePtr();
10578 S.Context.getCanonicalType(InnerE->getType()).getTypePtr();
10579 if (Target->isDependentType())
10586 return (BoolCandidateType->isSpecificBuiltinType(BuiltinType::Bool) &&
10587 FloatCandidateBT && (FloatCandidateBT->isFloatingPoint()));
10592 unsigned NumArgs = TheCall->getNumArgs();
10594 Expr *CurrA = TheCall->getArg(i);
10599 IsImplicitBoolFloatConversion(S, TheCall->getArg(i - 1), false));
10600 IsSwapped |= ((i < (NumArgs - 1)) &&
10601 IsImplicitBoolFloatConversion(S, TheCall->getArg(i + 1), false));
10603 // Warn on this floating-point to bool conversion.
10604 DiagnoseImpCast(S, CurrA->IgnoreParenImpCasts(),
10605 CurrA->getType(), CC,
10614 E->getExprLoc()))
10622 const Expr *NewE = E->IgnoreParenImpCasts();
10624 bool HasNullPtrType = NewE->getType()->isNullPtrType();
10629 if (T->isAnyPointerType() || T->isBlockPointerType() ||
10630 T->isMemberPointerType() || !T->isScalarType() || T->isNullPtrType())
10633 SourceLocation Loc = E->getSourceRange().getBegin();
10660 // Don't warn on char array initialization or for non-decimal values.
10666 if (auto *IntLit = dyn_cast<IntegerLiteral>(E->IgnoreParenImpCasts())) {
10668 S.getSourceManager().getCharacterData(IntLit->getBeginLoc())[0];
10675 if (CC.isValid() && T->isCharType()) {
10689 if (UO->getOpcode() == UO_Minus)
10690 return dyn_cast<IntegerLiteral>(UO->getSubExpr());
10698 E = E->IgnoreParenImpCasts();
10699 SourceLocation ExprLoc = E->getExprLoc();
10702 BinaryOperator::Opcode Opc = BO->getOpcode();
10706 const auto *LHS = getIntegerLiteral(BO->getLHS());
10707 const auto *RHS = getIntegerLiteral(BO->getRHS());
10708 if (LHS && LHS->getValue() == 0)
10710 else if (!E->isValueDependent() && LHS && RHS &&
10711 RHS->getValue().isNonNegative() &&
10712 E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects))
10715 else if (E->getType()->isSignedIntegerType())
10721 const auto *LHS = getIntegerLiteral(CO->getTrueExpr());
10722 const auto *RHS = getIntegerLiteral(CO->getFalseExpr());
10725 if ((LHS->getValue() == 0 || LHS->getValue() == 1) &&
10726 (RHS->getValue() == 0 || RHS->getValue() == 1))
10729 if (LHS->getValue() != 0 && RHS->getValue() != 0)
10736 if (E->isTypeDependent() || E->isValueDependent()) return;
10738 const Type *Source = Context.getCanonicalType(E->getType()).getTypePtr();
10741 if (Target->isDependentType()) return;
10751 if (Source->isAtomicType())
10752 Diag(E->getExprLoc(), diag::warn_atomic_implicit_seq_cst);
10755 if (Target->isSpecificBuiltinType(BuiltinType::Bool)) {
10764 // This covers the literal expressions that evaluate to Objective-C
10769 if (Source->isPointerType() || Source->canDecayToPointerType()) {
10779 if (ObjC().isSignedCharBool(T) && Source->isIntegralType(Context)) {
10781 if (E->EvaluateAsInt(Result, getASTContext(), Expr::SE_AllowSideEffects)) {
10791 // Check implicit casts from Objective-C collection literals to specialized
10800 if (Target->isSveVLSBuiltinType() &&
10807 if (Target->isRVVVLSBuiltinType() &&
10819 Target->castAs<VectorType>()->getNumElements() <
10820 Source->castAs<VectorType>()->getNumElements()) {
10833 Source = cast<VectorType>(Source)->getElementType().getTypePtr();
10834 Target = cast<VectorType>(Target)->getElementType().getTypePtr();
10837 Target = VecTy->getElementType().getTypePtr();
10842 if (SourceMgr.isInSystemMacro(CC) || Target->isBooleanType())
10851 Source = cast<ComplexType>(Source)->getElementType().getTypePtr();
10852 Target = cast<ComplexType>(Target)->getElementType().getTypePtr();
10859 if (SourceBT && SourceBT->isSveVLSBuiltinType()) {
10862 // Handle conversion from scalable to fixed when msve-vector-bits is
10875 Source = SourceBT->getSveEltType(Context).getTypePtr();
10878 if (TargetBT && TargetBT->isSveVLSBuiltinType())
10879 Target = TargetBT->getSveEltType(Context).getTypePtr();
10882 if (SourceBT && SourceBT->isFloatingPoint()) {
10884 if (TargetBT && TargetBT->isFloatingPoint()) {
10893 if (E->EvaluateAsRValue(result, Context)) {
10918 if (TargetBT && TargetBT->isInteger()) {
10925 // Detect the case where a call result is converted from floating-point to
10932 // way to detect this class of misplaced-parentheses bug?
10933 if (Target->isBooleanType() && isa<CallExpr>(E)) {
10938 if (unsigned NumArgs = CEx->getNumArgs()) {
10939 Expr *LastA = CEx->getArg(NumArgs - 1);
10940 Expr *InnerE = LastA->IgnoreParenImpCasts();
10942 InnerE->getType()->isBooleanType()) {
10943 // Warn on this floating-point to bool conversion
10953 if (Source->isFixedPointType()) {
10954 if (Target->isUnsaturatedFixedPointType()) {
10956 if (E->EvaluateAsFixedPoint(Result, Context, Expr::SE_AllowSideEffects,
10962 DiagRuntimeBehavior(E->getExprLoc(), E,
10965 << E->getSourceRange()
10970 } else if (Target->isIntegerType()) {
10973 E->EvaluateAsFixedPoint(Result, Context, Expr::SE_AllowSideEffects)) {
10978 Context.getIntWidth(T), Target->isSignedIntegerOrEnumerationType(),
10982 DiagRuntimeBehavior(E->getExprLoc(), E,
10985 << E->getSourceRange()
10991 } else if (Target->isUnsaturatedFixedPointType()) {
10992 if (Source->isIntegerType()) {
10995 E->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects)) {
11003 DiagRuntimeBehavior(E->getExprLoc(), E,
11006 << E->getSourceRange()
11015 // initialization-list syntax, we might lose accuracy if the floating
11017 if (SourceBT && TargetBT && SourceBT->isIntegerType() &&
11018 TargetBT->isFloatingType() && !IsListInit) {
11034 E->getIntegerConstantExpr(Context)) {
11042 *SourceInt, SourceBT->isSignedInteger(),
11047 SourceInt->toString(PrettySourceValue, 10);
11052 E->getExprLoc(), E,
11054 << PrettySourceValue << PrettyTargetValue << E->getType() << T
11055 << E->getSourceRange() << clang::SourceRange(CC));
11069 if (Target->isBooleanType())
11072 if (!Source->isIntegerType() || !Target->isIntegerType())
11075 // TODO: remove this early return once the false positives for constant->bool
11077 if (Target->isSpecificBuiltinType(BuiltinType::Bool))
11080 if (ObjC().isSignedCharBool(T) && !Source->isCharType() &&
11081 !E->isKnownToHaveBooleanValue(/*Semantic=*/false)) {
11084 << E->getType());
11094 // If the source is a constant, use a default-on diagnostic.
11097 if (E->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects,
11108 DiagRuntimeBehavior(E->getExprLoc(), E,
11111 << E->getType() << T << E->getSourceRange()
11116 // People want to build with -Wshorten-64-to-32 and not -Wconversion.
11120 if (TargetRange.Width == 32 && Context.getIntWidth(E->getType()) == 64)
11129 if (UO->getOpcode() == UO_Minus)
11130 if (Source->isUnsignedIntegerType()) {
11131 if (Target->isUnsignedIntegerType())
11134 if (Target->isSignedIntegerType())
11142 Source->isSignedIntegerType()) {
11148 if (E->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects) &&
11155 Diag(E->getExprLoc(),
11157 << PrettySourceValue << PrettyTargetValue << E->getType() << T
11158 << E->getSourceRange() << SourceRange(CC));
11163 // Fall through for non-constants to give a sign conversion warning.
11173 if (SourceBT && SourceBT->isInteger() && TargetBT &&
11174 TargetBT->isInteger() &&
11175 Source->isSignedIntegerType() == Target->isSignedIntegerType()) {
11181 // Traditionally, gcc has warned about this under -Wsign-compare.
11182 // We also want to warn about it in -Wconversion.
11183 // So if -Wconversion is off, use a completely identical diagnostic
11184 // in the sign-compare group.
11185 // The conditional-checking code will
11197 QualType SourceType = E->getEnumCoercedType(Context);
11200 if (const EnumType *SourceEnum = Source->getAs<EnumType>())
11201 if (const EnumType *TargetEnum = Target->getAs<EnumType>())
11202 if (SourceEnum->getDecl()->hasNameForLinkage() &&
11203 TargetEnum->getDecl()->hasNameForLinkage() &&
11218 E = E->IgnoreParenImpCasts();
11220 if (!S.getLangOpts().CPlusPlus && E->getType()->isRecordType())
11227 if (E->getType() != T)
11233 AnalyzeImplicitConversions(S, E->getCond(), E->getQuestionLoc());
11235 Expr *TrueExpr = E->getTrueExpr();
11237 TrueExpr = BCO->getCommon();
11241 CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
11243 if (T->isBooleanType())
11246 // If -Wconversion would have warned about either of the candidates
11256 if (E->getType() == T) return;
11259 S.CheckImplicitConversion(TrueExpr->IgnoreParenImpCasts(), E->getType(), CC,
11262 S.CheckImplicitConversion(E->getFalseExpr()->IgnoreParenImpCasts(),
11263 E->getType(), CC, &Suspicious);
11269 // Run the bool-like conversion checks only for C since there bools are
11274 if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
11276 S.CheckImplicitConversion(E->IgnoreParenImpCasts(), S.Context.BoolTy, CC);
11295 QualType T = OrigE->getType();
11296 Expr *E = OrigE->IgnoreParenImpCasts();
11299 // If so, we do not issue warnings for implicit int-float conversion
11304 if (E->isTypeDependent() || E->isValueDependent())
11313 if (auto *Src = OVE->getSourceExpr())
11317 if (UO->getOpcode() == UO_Not &&
11318 UO->getSubExpr()->isKnownToHaveBooleanValue())
11319 S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool)
11320 << OrigE->getSourceRange() << T->isBooleanType()
11321 << FixItHint::CreateReplacement(UO->getBeginLoc(), "!");
11324 if ((BO->getOpcode() == BO_And || BO->getOpcode() == BO_Or) &&
11325 BO->getLHS()->isKnownToHaveBooleanValue() &&
11326 BO->getRHS()->isKnownToHaveBooleanValue() &&
11327 BO->getLHS()->HasSideEffects(S.Context) &&
11328 BO->getRHS()->HasSideEffects(S.Context)) {
11331 SourceLocation BLoc = BO->getOperatorLoc();
11341 S.Diag(BO->getBeginLoc(), diag::warn_bitwise_instead_of_logical)
11342 << (BO->getOpcode() == BO_And ? "&" : "|")
11343 << OrigE->getSourceRange()
11345 BO->getOperatorLoc(),
11346 (BO->getOpcode() == BO_And ? "&&" : "||"));
11347 S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int);
11363 // The non-canonical typecheck is just an optimization;
11365 if (SourceExpr->getType() != T)
11374 for (auto *SE : POE->semantics())
11376 WorkList.push_back({OVE->getSourceExpr(), CC, IsListInit});
11381 E = CE->getSubExpr()->IgnoreParenImpCasts();
11382 if (!CE->getType()->isVoidType() && E->getType()->isAtomicType())
11383 S.Diag(E->getBeginLoc(), diag::warn_atomic_implicit_seq_cst);
11390 if (BO->isComparisonOp())
11394 if (BO->getOpcode() == BO_Assign)
11397 if (BO->isAssignmentOp())
11401 // These break the otherwise-useful invariant below. Fortunately,
11411 CC = E->getExprLoc();
11413 bool IsLogicalAndOperator = BO && BO->getOpcode() == BO_LAnd;
11414 for (Stmt *SubStmt : E->children()) {
11420 if (ChildExpr == CSE->getOperand())
11427 isa<StringLiteral>(ChildExpr->IgnoreParenImpCasts()))
11434 if (BO && BO->isLogicalOp()) {
11435 Expr *SubExpr = BO->getLHS()->IgnoreParenImpCasts();
11437 ::CheckBoolLikeConversion(S, SubExpr, BO->getExprLoc());
11439 SubExpr = BO->getRHS()->IgnoreParenImpCasts();
11441 ::CheckBoolLikeConversion(S, SubExpr, BO->getExprLoc());
11445 if (U->getOpcode() == UO_LNot) {
11446 ::CheckBoolLikeConversion(S, U->getSubExpr(), CC);
11447 } else if (U->getOpcode() != UO_AddrOf) {
11448 if (U->getSubExpr()->getType()->isAtomicType())
11449 S.Diag(U->getSubExpr()->getBeginLoc(),
11455 /// AnalyzeImplicitConversions - Find and report any interesting
11457 /// of competing diagnostics here, -Wconversion and -Wsign-compare.
11470 E = E->IgnoreParenImpCasts();
11475 if (!DRE->getDecl()->getType()->isReferenceType())
11478 if (!M->getMemberDecl()->getType()->isReferenceType())
11481 if (!Call->getCallReturnType(SemaRef.Context)->isReferenceType())
11483 FD = Call->getDirectCallee();
11488 SemaRef.Diag(E->getExprLoc(), PD);
11492 SemaRef.Diag(FD->getLocation(), diag::note_reference_is_return_value) << FD;
11500 // expansion, or is from expanded from a top-level macro argument.
11521 if (E->getExprLoc().isMacroID()) {
11523 if (IsInAnyMacroBody(SM, E->getExprLoc()) ||
11527 E = E->IgnoreImpCasts();
11534 Diag(E->getExprLoc(), DiagID) << E->getSourceRange() << Range << IsEqual;
11540 if (auto *UO = dyn_cast<UnaryOperator>(E->IgnoreParens())) {
11541 if (UO->getOpcode() != UO_AddrOf)
11544 E = UO->getSubExpr();
11551 PartialDiagnostic PD = PDiag(DiagID) << E->getSourceRange() << Range
11562 E->printPretty(S, nullptr, getPrintingPolicy());
11565 Diag(E->getExprLoc(), DiagID) << IsParam << S.str()
11566 << E->getSourceRange() << Range << IsEqual;
11567 Diag(NonnullAttr->getLocation(), diag::note_declared_nonnull) << IsParam;
11571 if (auto *Call = dyn_cast<CallExpr>(E->IgnoreParenImpCasts())) {
11572 if (auto *Callee = Call->getDirectCallee()) {
11573 if (const Attr *A = Callee->getAttr<ReturnsNonNullAttr>()) {
11584 if (const auto *MRecordDecl = MCallExpr->getRecordDecl();
11585 MRecordDecl && MRecordDecl->isLambda()) {
11586 Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
11588 << MRecordDecl->getSourceRange() << Range << IsEqual;
11597 D = R->getDecl();
11599 D = M->getMemberDecl();
11603 if (!D || D->isWeak())
11609 !getCurFunction()->ModifiedNonNullParams.count(PV)) {
11610 if (const Attr *A = PV->getAttr<NonNullAttr>()) {
11615 if (const auto *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
11617 if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
11619 auto ParamIter = llvm::find(FD->parameters(), PV);
11620 assert(ParamIter != FD->param_end());
11621 unsigned ParamNo = std::distance(FD->param_begin(), ParamIter);
11623 for (const auto *NonNull : FD->specific_attrs<NonNullAttr>()) {
11624 if (!NonNull->args_size()) {
11629 for (const ParamIdx &ArgNo : NonNull->args()) {
11640 QualType T = D->getType();
11641 const bool IsArray = T->isArrayType();
11642 const bool IsFunction = T->isFunctionType();
11656 E->printPretty(S, nullptr, getPrintingPolicy());
11673 Diag(E->getExprLoc(), DiagID) << DiagType << S.str() << E->getSourceRange()
11680 Diag(E->getExprLoc(), diag::note_function_warning_silence)
11681 << FixItHint::CreateInsertion(E->getBeginLoc(), "&");
11694 if (!ReturnType->isPointerType()) {
11697 if (!ReturnType->isIntegerType())
11706 if (!ReturnType->isSpecificBuiltinType(BuiltinType::Bool))
11709 Diag(E->getExprLoc(), diag::note_function_to_function_call)
11710 << FixItHint::CreateInsertion(getLocForEndOfToken(E->getEndLoc()), "()");
11718 // Don't diagnose for value- or type-dependent expressions.
11719 if (E->isTypeDependent() || E->isValueDependent())
11741 const Expr *E = OriginalE->IgnoreParenCasts();
11744 E->EvaluateForOverflow(Context);
11749 Exprs.append(InitList->inits().begin(), InitList->inits().end());
11751 E->EvaluateForOverflow(Context);
11753 Exprs.append(Call->arg_begin(), Call->arg_end());
11755 Exprs.append(Message->arg_begin(), Message->arg_end());
11757 Exprs.append(Construct->arg_begin(), Construct->arg_end());
11759 Exprs.push_back(Temporary->getSubExpr());
11761 Exprs.push_back(Array->getIdx());
11763 Exprs.push_back(Compound->getInitializer());
11765 New && New->isArray()) {
11766 if (auto ArraySize = New->getArraySize())
11815 return Seq(Values.size() - 1);
11851 /// least-sequenced usage of each kind.
11897 /// Filled in with declarations which were modified as a side-effect
11898 /// (that is, post-increment operations).
11906 /// expression. At the end of this process, the side-effects of the evaluation
11936 /// found to be non-constant, this allows us to suppress the evaluation of
11948 Prev->EvalOK &= EvalOK;
11952 if (!EvalOK || E->isValueDependent())
11954 EvalOK = E->EvaluateAsBooleanCondition(
11969 E = E->IgnoreParenCasts();
11971 if (Mod && (UO->getOpcode() == UO_PreInc || UO->getOpcode() == UO_PreDec))
11972 return getObject(UO->getSubExpr(), Mod);
11974 if (BO->getOpcode() == BO_Comma)
11975 return getObject(BO->getRHS(), Mod);
11976 if (Mod && BO->isAssignmentOp())
11977 return getObject(BO->getLHS(), Mod);
11980 if (isa<CXXThisExpr>(ME->getBase()->IgnoreParenCasts()))
11981 return ME->getMemberDecl();
11984 return DRE->getDecl();
11999 ModAsSideEffect->push_back(std::make_pair(O, U));
12009 /// \p IsModMod is true when we are checking for a mod-mod unsequenced
12010 /// usage and false we are checking for a mod-use unsequenced usage.
12026 Mod->getExprLoc(), {Mod, ModOrUse},
12029 << O << SourceRange(ModOrUse->getExprLoc()));
12037 // operations before C++17 and both are well-defined in C++17).
12040 // or notePreMod before visiting its sub-expression(s). At this point the
12052 // the visitation of such a sub-expression (for example: the LHS of || or ,)
12091 // Silence a -Wunused-private-field since WorkList is now unused.
12093 (void)this->WorkList;
12106 for (auto *Sub : CSE->children()) {
12111 if (ChildExpr == CSE->getOperand())
12124 if (E->getCastKind() == CK_LValueToRValue)
12125 O = getObject(E->getSubExpr(), false);
12160 VisitSequencedExpressions(ASE->getLHS(), ASE->getRHS());
12162 Visit(ASE->getLHS());
12163 Visit(ASE->getRHS());
12171 // Abbreviating pm-expression.*cast-expression as E1.*E2, [...]
12174 VisitSequencedExpressions(BO->getLHS(), BO->getRHS());
12176 Visit(BO->getLHS());
12177 Visit(BO->getRHS());
12187 VisitSequencedExpressions(BO->getLHS(), BO->getRHS());
12189 Visit(BO->getLHS());
12190 Visit(BO->getRHS());
12199 VisitSequencedExpressions(BO->getLHS(), BO->getRHS());
12220 Object O = getObject(BO->getLHS(), /*Mod=*/true);
12230 Visit(BO->getRHS());
12234 Visit(BO->getLHS());
12242 Visit(BO->getLHS());
12248 Visit(BO->getRHS());
12273 Object O = getObject(UO->getSubExpr(), true);
12278 Visit(UO->getSubExpr());
12289 Object O = getObject(UO->getSubExpr(), true);
12294 Visit(UO->getSubExpr());
12312 Visit(BO->getLHS());
12319 bool EvalOK = Eval.evaluate(BO->getLHS(), EvalResult);
12323 Visit(BO->getRHS());
12345 Visit(BO->getLHS());
12351 bool EvalOK = Eval.evaluate(BO->getLHS(), EvalResult);
12355 Visit(BO->getRHS());
12392 Visit(CO->getCond());
12402 bool EvalOK = Eval.evaluate(CO->getCond(), EvalResult);
12407 Visit(CO->getTrueExpr());
12411 Visit(CO->getFalseExpr());
12423 if (CE->isUnevaluatedBuiltinCall(Context))
12433 SemaRef.runWithSufficientStackSpace(CE->getExprLoc(), [&] {
12435 // The postfix-expression is sequenced before each expression in the
12436 // expression-list and any default argument. [...]
12452 Visit(CE->getCallee());
12454 Visit(CE->getCallee());
12459 for (const Expr *Argument : CE->arguments())
12473 // function-call notation as summarized in Table 12 (where @ denotes one
12475 // operands are sequenced in the order prescribed for the built-in
12482 (CXXOCE->getNumArgs() != 2 && CXXOCE->getOperator() != OO_Call))
12491 switch (CXXOCE->getOperator()) {
12531 SemaRef.runWithSufficientStackSpace(CXXOCE->getExprLoc(), [&] {
12534 assert((CXXOCE->getNumArgs() == 2 || CXXOCE->getOperator() == OO_Call) &&
12539 assert(CXXOCE->getOperator() == OO_Call &&
12543 // C++17 case. The postfix-expression is the first argument of the
12544 // CXXOperatorCallExpr. The expressions in the expression-list, if any,
12553 assert(CXXOCE->getNumArgs() >= 1 &&
12555 " for the postfix-expression!");
12556 const Expr *PostfixExpr = CXXOCE->getArgs()[0];
12557 llvm::ArrayRef<const Expr *> Args(CXXOCE->getArgs() + 1,
12558 CXXOCE->getNumArgs() - 1);
12560 // Visit the postfix-expression first.
12576 assert(CXXOCE->getNumArgs() == 2 &&
12584 const Expr *E1 = CXXOCE->getArg(0);
12585 const Expr *E2 = CXXOCE->getArg(1);
12598 if (!CCE->isListInitialization())
12603 llvm::ArrayRef(CCE->getArgs(), CCE->getNumArgs()));
12611 SequenceExpressionsInOrder(ILE->inits());
12617 SequenceExpressionsInOrder(PLIE->getInitExprs());
12657 if (!E->isInstantiationDependent())
12659 if (!IsConstexpr && !E->isValueDependent())
12672 if (!PType->isVariablyModifiedType())
12675 diagnoseArrayStarInParamType(S, PointerTy->getPointeeType(), Loc);
12679 diagnoseArrayStarInParamType(S, ReferenceTy->getPointeeType(), Loc);
12683 diagnoseArrayStarInParamType(S, ParenTy->getInnerType(), Loc);
12691 if (AT->getSizeModifier() != ArraySizeModifier::Star) {
12692 diagnoseArrayStarInParamType(S, AT->getElementType(), Loc);
12710 // shall not be a (possibly cv-qualified) class type that is incomplete
12712 if (!Param->isInvalidDecl() &&
12713 (RequireCompleteType(Param->getLocation(), Param->getType(),
12715 RequireNonAbstractType(Param->getBeginLoc(), Param->getOriginalType(),
12718 Param->setInvalidDecl();
12724 if (CheckParameterNames && Param->getIdentifier() == nullptr &&
12725 !Param->isImplicit() && !getLangOpts().CPlusPlus) {
12728 Diag(Param->getLocation(), diag::ext_parameter_name_omitted_c23);
12736 QualType PType = Param->getOriginalType();
12737 // FIXME: This diagnostic should point the '[*]' if source-location
12739 diagnoseArrayStarInParamType(*this, PType, Param->getLocation());
12744 if (!Param->isInvalidDecl()) {
12745 if (CXXRecordDecl *ClassDecl = Param->getType()->getAsCXXRecordDecl()) {
12746 if (!ClassDecl->isInvalidDecl() &&
12747 !ClassDecl->hasIrrelevantDestructor() &&
12748 !ClassDecl->isDependentContext() &&
12749 ClassDecl->isParamDestroyedInCallee()) {
12751 MarkFunctionReferenced(Param->getLocation(), Destructor);
12752 DiagnoseUseOfDecl(Destructor, Param->getLocation());
12761 if (const auto *Attr = Param->getAttr<PassObjectSizeAttr>())
12762 if (!Param->getType().isConstQualified())
12763 Diag(Param->getLocation(), diag::err_attribute_pointers_only)
12764 << Attr->getSpelling() << 1;
12767 if (LangOpts.CPlusPlus && !Param->isInvalidDecl()) {
12770 DeclContext *DC = Param->getDeclContext();
12771 if (DC && DC->isFunctionOrMethod()) {
12772 if (auto *RD = dyn_cast<CXXRecordDecl>(DC->getParent()))
12773 CheckShadowInheritedFields(Param->getLocation(), Param->getDeclName(),
12778 if (!Param->isInvalidDecl() &&
12779 Param->getOriginalType()->isWebAssemblyTableType()) {
12780 Param->setInvalidDecl();
12782 Diag(Param->getLocation(), diag::err_wasm_table_as_function_parameter);
12796 /// derived-to-base cast expression and the alignment and offset of the derived
12802 for (auto PathI = CE->path_begin(), PathE = CE->path_end(); PathI != PathE;
12805 const CXXRecordDecl *BaseDecl = Base->getType()->getAsCXXRecordDecl();
12806 if (Base->isVirtual()) {
12807 // The complete object may have a lower alignment than the non-virtual
12809 // the smaller of the non-virtual alignment and BaseAlignment, which is a
12817 Ctx.getASTRecordLayout(DerivedType->getAsCXXRecordDecl());
12820 DerivedType = Base->getType();
12830 QualType PointeeType = PtrE->getType()->getPointeeType();
12832 if (!PointeeType->isConstantSizeType())
12841 if (std::optional<llvm::APSInt> IdxRes = IntE->getIntegerConstantExpr(Ctx)) {
12842 CharUnits Offset = EltSize * IdxRes->getExtValue();
12844 Offset = -Offset;
12845 return std::make_pair(P->first, P->second + Offset);
12852 P->first.alignmentAtOffset(P->second).alignmentAtOffset(EltSize),
12862 E = E->IgnoreParens();
12863 switch (E->getStmtClass()) {
12870 const Expr *From = CE->getSubExpr();
12871 switch (CE->getCastKind()) {
12881 return getDerivedToBaseAlignmentAndOffset(CE, From->getType(), P->first,
12882 P->second, Ctx);
12889 return getAlignmentAndOffsetFromBinAddOrSub(ASE->getBase(), ASE->getIdx(),
12893 if (auto *VD = dyn_cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl())) {
12896 if (!VD->getType()->isReferenceType()) {
12897 // Dependent alignment cannot be resolved -> bail out.
12898 if (VD->hasDependentAlignment())
12902 if (VD->hasInit())
12903 return getBaseAlignmentAndOffsetFromLValue(VD->getInit(), Ctx);
12909 auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
12910 if (!FD || FD->getType()->isReferenceType() ||
12911 FD->getParent()->isInvalidDecl())
12914 if (ME->isArrow())
12915 P = getBaseAlignmentAndOffsetFromPtr(ME->getBase(), Ctx);
12917 P = getBaseAlignmentAndOffsetFromLValue(ME->getBase(), Ctx);
12920 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(FD->getParent());
12921 uint64_t Offset = Layout.getFieldOffset(FD->getFieldIndex());
12922 return std::make_pair(P->first,
12923 P->second + CharUnits::fromQuantity(Offset));
12927 switch (UO->getOpcode()) {
12931 return getBaseAlignmentAndOffsetFromPtr(UO->getSubExpr(), Ctx);
12937 auto Opcode = BO->getOpcode();
12942 return getBaseAlignmentAndOffsetFromLValue(BO->getRHS(), Ctx);
12957 E = E->IgnoreParens();
12958 switch (E->getStmtClass()) {
12965 const Expr *From = CE->getSubExpr();
12966 switch (CE->getCastKind()) {
12979 CE, From->getType()->getPointeeType(), P->first, P->second, Ctx);
12985 auto *RD = E->getType()->getPointeeType()->getAsCXXRecordDecl();
12991 if (UO->getOpcode() == UO_AddrOf)
12992 return getBaseAlignmentAndOffsetFromLValue(UO->getSubExpr(), Ctx);
12997 auto Opcode = BO->getOpcode();
13003 const Expr *LHS = BO->getLHS(), *RHS = BO->getRHS();
13004 if (Opcode == BO_Add && !RHS->getType()->isIntegralOrEnumerationType())
13010 return getBaseAlignmentAndOffsetFromPtr(BO->getRHS(), Ctx);
13024 return P->first.alignmentAtOffset(P->second);
13027 return S.Context.getTypeAlignInChars(E->getType()->getPointeeType());
13032 // cast; don't do it if we're ignoring -Wcast_align (as is the default).
13037 if (T->isDependentType() || Op->getType()->isDependentType())
13041 const PointerType *DestPtr = T->getAs<PointerType>();
13045 QualType DestPointee = DestPtr->getPointeeType();
13046 if (DestPointee->isIncompleteType()) return;
13051 const PointerType *SrcPtr = Op->getType()->getAs<PointerType>();
13053 QualType SrcPointee = SrcPtr->getPointeeType();
13059 if (SrcPointee->isIncompleteType()) return;
13066 << Op->getType() << T
13069 << TRange << Op->getSourceRange();
13079 IndexExpr = IndexExpr->IgnoreParenImpCasts();
13080 if (IndexExpr->isValueDependent())
13084 BaseExpr->getType()->getPointeeOrArrayElementType();
13085 BaseExpr = BaseExpr->IgnoreParenCasts();
13087 Context.getAsConstantArrayType(BaseExpr->getType());
13093 ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
13095 BaseType == nullptr || BaseExpr->isFlexibleArrayMemberLike(
13098 if (EffectiveType->isDependentType() ||
13099 (!IsUnboundedArray && BaseType->isDependentType()))
13103 if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
13109 index = -index;
13113 if (EffectiveType->isFunctionType())
13118 EffectiveType->getCanonicalTypeInternal().getAddressSpace());
13123 // PR50741 - If EffectiveType has unknown size (e.g., if it's a void
13124 // pointer) bounds-checking isn't meaningful.
13125 if (!ElemCharUnits || ElemCharUnits->isZero())
13127 llvm::APInt ElemBytes(index.getBitWidth(), ElemCharUnits->getQuantity());
13153 // Diag message shows element size in bits and in "bytes" (platform-
13155 DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
13162 << IndexExpr->getSourceRange());
13167 BaseExpr = ASE->getBase()->IgnoreParenCasts();
13169 ND = DRE->getDecl();
13171 ND = ME->getMemberDecl();
13174 DiagRuntimeBehavior(ND->getBeginLoc(), BaseExpr,
13187 if (BaseType->isIncompleteType())
13190 llvm::APInt size = ArrayTy->getSize();
13222 // commonly done e.g. in C++ iterators and range-based for loops.
13231 ASE->getRBracketLoc());
13234 SourceMgr.getSpellingLoc(IndexExpr->getBeginLoc());
13243 QualType CastMsgTy = ASE ? ASE->getLHS()->getType() : QualType();
13246 BaseExpr->getBeginLoc(), BaseExpr,
13247 PDiag(DiagID) << toString(index, 10, true) << ArrayTy->desugar()
13248 << CastMsg << CastMsgTy << IndexExpr->getSourceRange());
13253 if (index.isNegative()) index = -index;
13256 DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
13258 << IndexExpr->getSourceRange());
13264 BaseExpr = ASE->getBase()->IgnoreParenCasts();
13266 ND = DRE->getDecl();
13268 ND = ME->getMemberDecl();
13271 DiagRuntimeBehavior(ND->getBeginLoc(), BaseExpr,
13278 expr = expr->IgnoreParenImpCasts();
13279 switch (expr->getStmtClass()) {
13282 CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE,
13284 expr = ASE->getBase();
13288 expr = cast<MemberExpr>(expr)->getBase();
13295 if (ASE->getLowerBound())
13296 CheckArrayAccess(ASE->getBase(), ASE->getLowerBound(),
13303 expr = UO->getSubExpr();
13304 switch (UO->getOpcode()) {
13309 AllowOnePastEnd--;
13318 if (const Expr *lhs = cond->getLHS())
13320 if (const Expr *rhs = cond->getRHS())
13326 for (const auto *Arg : OCE->arguments())
13338 // Check if RHS is an Objective-C object literal, which also can get
13341 RHS = RHS->IgnoreParenImpCasts();
13344 // warn_objc_arc_literal_assign (off-by-1).
13352 << RHS->getSourceRange();
13360 // Strip off any implicit cast added to get to the one ARC-specific.
13362 if (cast->getCastKind() == CK_ARCConsumeObject) {
13366 << RHS->getSourceRange();
13369 RHS = cast->getSubExpr();
13398 = dyn_cast<ObjCPropertyRefExpr>(LHS->IgnoreParens());
13399 if (PRE && !PRE->isImplicitProperty()) {
13400 const ObjCPropertyDecl *PD = PRE->getExplicitProperty();
13402 LHSType = PD->getType();
13406 LHSType = LHS->getType();
13412 getCurFunction()->markSafeWeakUse(LHS);
13423 if (PRE->isImplicitProperty())
13425 const ObjCPropertyDecl *PD = PRE->getExplicitProperty();
13429 unsigned Attributes = PD->getPropertyAttributes();
13434 unsigned AsWrittenAttr = PD->getPropertyAttributesAsWritten();
13436 LHSType->isObjCRetainableType())
13440 if (cast->getCastKind() == CK_ARCConsumeObject) {
13442 << RHS->getSourceRange();
13445 RHS = cast->getSubExpr();
13454 //===--- CHECK: Empty statement body (-Wempty-body) ---------------------===//
13464 if (Body->hasLeadingEmptyMacro())
13475 unsigned BodyLine = SourceMgr.getSpellingLineNumber(Body->getSemiLoc(),
13504 Diag(NBody->getSemiLoc(), DiagID);
13505 Diag(NBody->getSemiLoc(), diag::note_empty_body_on_separate_line);
13516 StmtLoc = FS->getRParenLoc();
13517 Body = FS->getBody();
13520 StmtLoc = WS->getRParenLoc();
13521 Body = WS->getBody();
13532 if (Diags.isIgnored(DiagID, NBody->getSemiLoc()))
13554 PossibleBody->getBeginLoc(), &BodyColInvalid);
13560 SourceMgr.getPresumedColumnNumber(S->getBeginLoc(), &StmtColInvalid);
13569 Diag(NBody->getSemiLoc(), DiagID);
13570 Diag(NBody->getSemiLoc(), diag::note_empty_body_on_separate_line);
13574 //===--- CHECK: Warn on self move with std::move. -------------------------===//
13585 LHSExpr = LHSExpr->IgnoreParenImpCasts();
13586 RHSExpr = RHSExpr->IgnoreParenImpCasts();
13591 CE && CE->getNumArgs() == 1 && CE->isCallToStdMove())
13592 RHSExpr = CE->getArg(0);
13594 CXXSCE && CXXSCE->isXValue())
13595 RHSExpr = CXXSCE->getSubExpr();
13604 if (!LHSDeclRef->getDecl() || !RHSDeclRef->getDecl())
13606 if (LHSDeclRef->getDecl()->getCanonicalDecl() !=
13607 RHSDeclRef->getDecl()->getCanonicalDecl())
13611 << LHSExpr->getType() << LHSExpr->getSourceRange()
13612 << RHSExpr->getSourceRange();
13614 getSelfAssignmentClassMemberCandidate(RHSDeclRef->getDecl()))
13616 << FixItHint::CreateInsertion(LHSDeclRef->getBeginLoc(), "this->");
13634 if (LHSME->getMemberDecl()->getCanonicalDecl() !=
13635 RHSME->getMemberDecl()->getCanonicalDecl())
13638 LHSBase = LHSME->getBase();
13639 RHSBase = RHSME->getBase();
13647 if (!LHSDeclRef->getDecl() || !RHSDeclRef->getDecl())
13649 if (LHSDeclRef->getDecl()->getCanonicalDecl() !=
13650 RHSDeclRef->getDecl()->getCanonicalDecl())
13654 << LHSExpr->getType() << 0 << LHSExpr->getSourceRange()
13655 << RHSExpr->getSourceRange();
13661 << LHSExpr->getType() << 0 << LHSExpr->getSourceRange()
13662 << RHSExpr->getSourceRange();
13665 //===--- Layout compatibility ----------------------------------------------//
13669 /// Check if two enumeration types are layout-compatible.
13673 // Two enumeration types are layout-compatible if they have the same
13675 return ED1->isComplete() && ED2->isComplete() &&
13676 C.hasSameType(ED1->getIntegerType(), ED2->getIntegerType());
13679 /// Check if two fields are layout-compatible.
13686 Field1->getParent()->getTypeForDecl();
13688 Field2->getParent()->getTypeForDecl();
13689 assert(((Field1Parent->isStructureOrClassType() &&
13690 Field2Parent->isStructureOrClassType()) ||
13691 (Field1Parent->isUnionType() && Field2Parent->isUnionType())) &&
13694 assert(((!AreUnionMembers && Field1Parent->isStructureOrClassType()) ||
13695 (AreUnionMembers && Field1Parent->isUnionType())) &&
13698 if (!isLayoutCompatible(C, Field1->getType(), Field2->getType()))
13701 if (Field1->isBitField() != Field2->isBitField())
13704 if (Field1->isBitField()) {
13705 // Make sure that the bit-fields are the same length.
13706 unsigned Bits1 = Field1->getBitWidthValue(C);
13707 unsigned Bits2 = Field2->getBitWidthValue(C);
13713 if (Field1->hasAttr<clang::NoUniqueAddressAttr>() ||
13714 Field2->hasAttr<clang::NoUniqueAddressAttr>())
13718 Field1->getMaxAlignment() != Field2->getMaxAlignment())
13724 /// Check if two standard-layout structs are layout-compatible.
13730 RD1 = D1CXX->getStandardLayoutBaseWithFields();
13733 RD2 = D2CXX->getStandardLayoutBaseWithFields();
13736 return llvm::equal(RD1->fields(), RD2->fields(),
13737 [&C](const FieldDecl *F1, const FieldDecl *F2) -> bool {
13742 /// Check if two standard-layout unions are layout-compatible.
13747 for (auto *Field2 : RD2->fields())
13750 for (auto *Field1 : RD1->fields()) {
13771 if (RD1->isUnion() != RD2->isUnion())
13774 if (RD1->isUnion())
13780 /// Check if two types are layout-compatible in C++11 sense.
13786 // Two types cv1 T1 and cv2 T2 are layout-compatible types
13787 // if T1 and T2 are the same type, layout-compatible enumerations (9.7.1),
13788 // or layout-compatible standard-layout class types (11.4).
13795 const Type::TypeClass TC1 = T1->getTypeClass();
13796 const Type::TypeClass TC2 = T2->getTypeClass();
13803 cast<EnumType>(T1)->getDecl(),
13804 cast<EnumType>(T2)->getDecl());
13806 if (!T1->isStandardLayoutType() || !T2->isStandardLayoutType())
13810 cast<RecordType>(T1)->getDecl(),
13811 cast<RecordType>(T2)->getDecl());
13821 //===-------------- Pointer interconvertibility ----------------------------//
13825 QualType BaseT = Base->getType()->getCanonicalTypeUnqualified();
13826 QualType DerivedT = Derived->getType()->getCanonicalTypeUnqualified();
13828 if (BaseT->isStructureOrClassType() && DerivedT->isStructureOrClassType() &&
13832 if (!IsDerivedFrom(Derived->getTypeLoc().getBeginLoc(), DerivedT, BaseT))
13835 // Per [basic.compound]/4.3, containing object has to be standard-layout.
13836 if (DerivedT->getAsCXXRecordDecl()->isStandardLayout())
13842 //===--- CHECK: pointer_with_type_tag attribute: datatypes should match ----//
13862 TypeExpr = TypeExpr->IgnoreParenImpCasts()->IgnoreParenCasts();
13864 switch (TypeExpr->getStmtClass()) {
13867 if (UO->getOpcode() == UO_AddrOf || UO->getOpcode() == UO_Deref) {
13868 TypeExpr = UO->getSubExpr();
13876 *VD = DRE->getDecl();
13882 llvm::APInt MagicValueAPInt = IL->getValue();
13895 if (ACO->getCond()->EvaluateAsBooleanCondition(Result, Ctx,
13898 TypeExpr = ACO->getTrueExpr();
13900 TypeExpr = ACO->getFalseExpr();
13908 if (BO->getOpcode() == BO_Comma) {
13909 TypeExpr = BO->getRHS();
13954 if (TypeTagForDatatypeAttr *I = VD->getAttr<TypeTagForDatatypeAttr>()) {
13955 if (I->getArgumentKind() != ArgumentKind) {
13959 TypeInfo.Type = I->getMatchingCType();
13960 TypeInfo.LayoutCompatible = I->getLayoutCompatible();
13961 TypeInfo.MustBeNull = I->getMustBeNull();
13972 MagicValues->find(std::make_pair(ArgumentKind, MagicValue));
13973 if (I == MagicValues->end())
13976 TypeInfo = I->second;
13994 const BuiltinType *BT1 = T1->getAs<BuiltinType>();
13998 const BuiltinType *BT2 = T2->getAs<BuiltinType>();
14002 BuiltinType::Kind T1Kind = BT1->getKind();
14003 BuiltinType::Kind T2Kind = BT2->getKind();
14014 const IdentifierInfo *ArgumentKind = Attr->getArgumentKind();
14015 bool IsPointerAttr = Attr->getIsPointer();
14018 unsigned TypeTagIdxAST = Attr->getTypeTagIdx().getASTIndex();
14021 << 0 << Attr->getTypeTagIdx().getSourceIndex();
14031 Diag(TypeTagExpr->getExprLoc(),
14033 << TypeTagExpr->getSourceRange();
14038 unsigned ArgumentIdxAST = Attr->getArgumentIdx().getASTIndex();
14041 << 1 << Attr->getArgumentIdx().getSourceIndex();
14048 if (ICE->getType()->isVoidPointerType() &&
14049 ICE->getCastKind() == CK_BitCast)
14050 ArgumentExpr = ICE->getSubExpr();
14052 QualType ArgumentType = ArgumentExpr->getType();
14055 if (IsPointerAttr && ArgumentType->isVoidPointerType())
14060 if (!ArgumentExpr->isNullPointerConstant(Context,
14062 Diag(ArgumentExpr->getExprLoc(),
14064 << ArgumentKind->getName()
14065 << ArgumentExpr->getSourceRange()
14066 << TypeTagExpr->getSourceRange();
14085 if ((IsPointerAttr && IsSameCharType(ArgumentType->getPointeeType(),
14086 RequiredType->getPointeeType())) ||
14092 ArgumentType->getPointeeType(),
14093 RequiredType->getPointeeType());
14098 Diag(ArgumentExpr->getExprLoc(), diag::warn_type_safety_type_mismatch)
14101 << ArgumentExpr->getSourceRange()
14102 << TypeTagExpr->getSourceRange();
14113 if (ND->getName().empty()) {
14114 if (const TypedefNameDecl *TD = m.RD->getTypedefNameForAnonDecl())
14117 Diag(m.E->getBeginLoc(), diag::warn_taking_address_of_packed_member)
14118 << m.MD << ND << m.E->getSourceRange();
14124 E = E->IgnoreParens();
14125 if (!T->isPointerType() && !T->isIntegerType() && !T->isDependentType())
14128 cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf) {
14129 auto *Op = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
14133 (T->isDependentType() || T->isIntegerType() ||
14134 (T->isPointerType() && (T->getPointeeType()->isIncompleteType() ||
14136 T->getPointeeType()) <= MA->Alignment))))
14150 // No need to check expressions with an __unaligned-qualified type.
14151 if (E->getType().getQualifiers().hasUnaligned())
14160 QualType BaseType = ME->getBase()->getType();
14161 if (BaseType->isDependentType())
14163 if (ME->isArrow())
14164 BaseType = BaseType->getPointeeType();
14165 RecordDecl *RD = BaseType->castAs<RecordType>()->getDecl();
14166 if (RD->isInvalidDecl())
14169 ValueDecl *MD = ME->getMemberDecl();
14171 // We do not care about non-data members.
14172 if (!FD || FD->isInvalidDecl())
14176 AnyIsPacked || (RD->hasAttr<PackedAttr>() || MD->hasAttr<PackedAttr>());
14180 ME = dyn_cast<MemberExpr>(ME->getBase()->IgnoreParens());
14188 const Expr *TopBase = TopME->getBase()->IgnoreParenImpCasts();
14197 CharUnits ExpectedAlignment = Context.getTypeAlignInChars(E->getType());
14210 ReverseMemberChain.back()->getParent()->getTypeForDecl());
14214 if (DRE && !TopME->isArrow()) {
14215 const ValueDecl *VD = DRE->getDecl();
14216 if (!VD->getType()->isReferenceType())
14237 if (FDI->hasAttr<PackedAttr>() ||
14238 FDI->getParent()->hasAttr<PackedAttr>()) {
14241 Context.getTypeAlignInChars(FD->getType()),
14242 Context.getTypeAlignInChars(FD->getParent()->getTypeForDecl()));
14247 Action(E, FD->getParent(), FD, Alignment);
14263 ExprResult A = UsualUnaryConversions(TheCall->getArg(0));
14267 TheCall->setArg(0, A.get());
14268 QualType TyA = A.get()->getType();
14270 if (checkMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA, 1))
14273 TheCall->setType(TyA);
14281 TheCall->setType(Res);
14290 if (auto *VecTy0 = Res->getAs<VectorType>())
14291 TheCall->setType(VecTy0->getElementType());
14293 TheCall->setType(Res);
14302 ExprResult A = TheCall->getArg(0);
14303 ExprResult B = TheCall->getArg(1);
14306 Res = UsualArithmeticConversions(A, B, TheCall->getExprLoc(), ACK_Comparison);
14310 QualType TyA = A.get()->getType();
14311 QualType TyB = B.get()->getType();
14314 return Diag(A.get()->getBeginLoc(),
14318 if (checkMathBuiltinElementType(*this, A.get()->getBeginLoc(), TyA, 1))
14321 TheCall->setArg(0, A.get());
14322 TheCall->setArg(1, B.get());
14333 ExprResult Converted = UsualUnaryConversions(TheCall->getArg(I));
14342 if (checkFPMathBuiltinElementType(*this, Arg->getBeginLoc(),
14343 Arg->getType(), ArgOrdinal++))
14349 if (checkMathBuiltinElementType(*this, Arg->getBeginLoc(), Arg->getType(),
14356 if (Args[0]->getType().getCanonicalType() !=
14357 Args[I]->getType().getCanonicalType()) {
14358 return Diag(Args[0]->getBeginLoc(),
14360 << Args[0]->getType() << Args[I]->getType();
14363 TheCall->setArg(I, Args[I]);
14366 TheCall->setType(Args[0]->getType());
14374 ExprResult A = UsualUnaryConversions(TheCall->getArg(0));
14378 TheCall->setArg(0, A.get());
14386 ExprResult Arg = TheCall->getArg(0);
14387 QualType TyArg = Arg.get()->getType();
14389 if (!TyArg->isBuiltinType() && !TyArg->isVectorType())
14390 return Diag(TheCall->getArg(0)->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14393 TheCall->setType(TyArg);
14402 ExprResult MatrixArg = DefaultLvalueConversion(TheCall->getArg(0));
14407 auto *MType = Matrix->getType()->getAs<ConstantMatrixType>();
14409 Diag(Matrix->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14410 << 1 << /* matrix ty*/ 1 << Matrix->getType();
14417 MType->getElementType(), MType->getNumColumns(), MType->getNumRows());
14420 TheCall->setType(ResultType);
14423 TheCall->setArg(0, Matrix);
14432 Expr->getIntegerConstantExpr(S.Context, &ErrorPos);
14434 S.Diag(Expr->getBeginLoc(), diag::err_builtin_matrix_scalar_unsigned_arg)
14438 uint64_t Dim = Value->getZExtValue();
14440 S.Diag(Expr->getBeginLoc(), diag::err_builtin_matrix_invalid_dimension)
14450 Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_disabled);
14458 Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
14459 Expr *RowsExpr = TheCall->getArg(1);
14460 Expr *ColumnsExpr = TheCall->getArg(2);
14461 Expr *StrideExpr = TheCall->getArg(3);
14471 TheCall->setArg(0, PtrExpr);
14472 if (PtrExpr->isTypeDependent()) {
14473 TheCall->setType(Context.DependentTy);
14478 auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
14481 Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14482 << PtrArgIdx + 1 << /*pointer to element ty*/ 2 << PtrExpr->getType();
14485 ElementTy = PtrTy->getPointeeType().getUnqualifiedType();
14488 Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14490 << PtrExpr->getType();
14504 // Apply conversion to row and column expressions.
14508 TheCall->setArg(1, RowsExpr);
14515 TheCall->setArg(2, ColumnsExpr);
14521 if ((RowsExpr && RowsExpr->isTypeDependent()) ||
14522 (ColumnsExpr && ColumnsExpr->isTypeDependent())) {
14523 TheCall->setType(Context.DependentTy);
14527 // Check row and column dimensions.
14530 MaybeRows = getAndVerifyMatrixDimension(RowsExpr, "row", *this);
14536 // Check stride argument.
14541 TheCall->setArg(3, StrideExpr);
14545 StrideExpr->getIntegerConstantExpr(Context)) {
14546 uint64_t Stride = Value->getZExtValue();
14547 if (Stride < *MaybeRows) {
14548 Diag(StrideExpr->getBeginLoc(),
14558 TheCall->setType(
14569 Expr *MatrixExpr = TheCall->getArg(0);
14570 Expr *PtrExpr = TheCall->getArg(PtrArgIdx);
14571 Expr *StrideExpr = TheCall->getArg(2);
14580 TheCall->setArg(0, MatrixExpr);
14582 if (MatrixExpr->isTypeDependent()) {
14583 TheCall->setType(Context.DependentTy);
14587 auto *MatrixTy = MatrixExpr->getType()->getAs<ConstantMatrixType>();
14589 Diag(MatrixExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14590 << 1 << /*matrix ty */ 1 << MatrixExpr->getType();
14599 TheCall->setArg(1, PtrExpr);
14600 if (PtrExpr->isTypeDependent()) {
14601 TheCall->setType(Context.DependentTy);
14607 auto *PtrTy = PtrExpr->getType()->getAs<PointerType>();
14609 Diag(PtrExpr->getBeginLoc(), diag::err_builtin_invalid_arg_type)
14610 << PtrArgIdx + 1 << /*pointer to element ty*/ 2 << PtrExpr->getType();
14613 QualType ElementTy = PtrTy->getPointeeType();
14615 Diag(PtrExpr->getBeginLoc(), diag::err_builtin_matrix_store_to_const);
14620 !Context.hasSameType(ElementTy, MatrixTy->getElementType())) {
14621 Diag(PtrExpr->getBeginLoc(),
14623 << ElementTy << MatrixTy->getElementType();
14628 // Apply default Lvalue conversions and convert the stride expression to
14639 TheCall->setArg(2, StrideExpr);
14642 // Check stride argument.
14645 StrideExpr->getIntegerConstantExpr(Context)) {
14646 uint64_t Stride = Value->getZExtValue();
14647 if (Stride < MatrixTy->getNumRows()) {
14648 Diag(StrideExpr->getBeginLoc(),
14669 if (!Caller || !Caller->hasAttr<EnforceTCBAttr>())
14675 for (const auto *A : Callee->specific_attrs<EnforceTCBAttr>())
14676 CalleeTCBs.insert(A->getTCBName());
14677 for (const auto *A : Callee->specific_attrs<EnforceTCBLeafAttr>())
14678 CalleeTCBs.insert(A->getTCBName());
14682 for (const auto *A : Caller->specific_attrs<EnforceTCBAttr>()) {
14683 StringRef CallerTCB = A->getTCBName();
14685 this->Diag(CallExprLoc, diag::warn_tcb_enforcement_violation)