Cleanup sema checking for buitlin_memcpy_inline

This commit is contained in:
Guillaume Chatelet 2022-06-07 09:49:36 +00:00
parent 997ecb0036
commit d8b540cd31
3 changed files with 5 additions and 14 deletions

View File

@ -555,7 +555,7 @@ BUILTIN(__builtin_malloc, "v*z", "nF")
BUILTIN(__builtin_memchr, "v*vC*iz", "nF")
BUILTIN(__builtin_memcmp, "ivC*vC*z", "nF")
BUILTIN(__builtin_memcpy, "v*v*vC*z", "nF")
BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "nt")
BUILTIN(__builtin_memcpy_inline, "vv*vC*Iz", "n")
BUILTIN(__builtin_memmove, "v*v*vC*z", "nF")
BUILTIN(__builtin_mempcpy, "v*v*vC*z", "nF")
BUILTIN(__builtin_memset, "v*v*iz", "nF")

View File

@ -2265,19 +2265,6 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
case Builtin::BI__builtin_nontemporal_store:
return SemaBuiltinNontemporalOverloaded(TheCallResult);
case Builtin::BI__builtin_memcpy_inline: {
if (checkArgCount(*this, TheCall, 3))
return ExprError();
auto ArgArrayConversionFailed = [&](unsigned Arg) {
ExprResult ArgExpr =
DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
if (ArgExpr.isInvalid())
return true;
TheCall->setArg(Arg, ArgExpr.get());
return false;
};
if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
return true;
clang::Expr *SizeOp = TheCall->getArg(2);
// We warn about copying to or from `nullptr` pointers when `size` is
// greater than 0. When `size` is value dependent we cannot evaluate its

View File

@ -7,6 +7,10 @@
// expected-warning@-1 {{defined as expected}}
#endif
void test_memcpy_inline_invalid_arg_types() {
__builtin_memcpy_inline(1, 2, 3); // expected-error {{cannot initialize a parameter of type 'void *' with an rvalue of type 'int'}}
}
void test_memcpy_inline_null_src(void *ptr) {
__builtin_memcpy_inline(ptr, NULL, 4); // expected-warning {{null passed to a callee that requires a non-null argument}}
}