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