diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-02-10 10:19:24 -0500 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-02-14 19:42:29 +0000 |
commit | ca071f897cc70bd235087da925aba050dc8a1506 (patch) | |
tree | f664896285391c337af09253f8e3a4dbd454e6c6 /gcc/rust | |
parent | e07ef308523105b8f407d4b66dbc7c34155cf753 (diff) | |
download | gcc-ca071f897cc70bd235087da925aba050dc8a1506.zip gcc-ca071f897cc70bd235087da925aba050dc8a1506.tar.gz gcc-ca071f897cc70bd235087da925aba050dc8a1506.tar.bz2 |
Add variadic argument type checking
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc
(TypeCheckCallExpr::visit): Add variadic argument type checking.
(TypeCheckCallExpr::visit): Fix comment spelling ("varadic").
gcc/testsuite/ChangeLog:
* rust/execute/torture/overflow1.rs: Fix test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-call.cc | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 67e2866..f0846ae 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -122,7 +122,7 @@ TypeCheckCallExpr::visit (FnType &type) return; } - // it might be a varadic function + // it might be a variadic function if (i < type.num_params ()) { auto fnparam = type.param_at (i); @@ -143,6 +143,60 @@ TypeCheckCallExpr::visit (FnType &type) return; } } + else + { + switch (argument_expr_tyty->get_kind ()) + { + case TyTy::TypeKind::ERROR: + return; + case TyTy::TypeKind::INT: { + auto &int_ty + = static_cast<TyTy::IntType &> (*argument_expr_tyty); + if ((int_ty.get_int_kind () == TyTy::IntType::IntKind::I8) + || (int_ty.get_int_kind () == TyTy::IntType::IntKind::I16)) + { + rust_error_at (arg_locus, + "expected %<c_int%> variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::UINT: { + auto &uint_ty + = static_cast<TyTy::UintType &> (*argument_expr_tyty); + if ((uint_ty.get_uint_kind () == TyTy::UintType::UintKind::U8) + || (uint_ty.get_uint_kind () + == TyTy::UintType::UintKind::U16)) + { + rust_error_at (arg_locus, + "expected %<c_uint%> variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::FLOAT: { + if (static_cast<TyTy::FloatType &> (*argument_expr_tyty) + .get_float_kind () + == TyTy::FloatType::FloatKind::F32) + { + rust_error_at (arg_locus, + "expected %<c_double%> variadic argument"); + return; + } + break; + } + case TyTy::TypeKind::BOOL: + rust_error_at (arg_locus, "expected %<c_int%> variadic argument"); + return; + case TyTy::TypeKind::FNDEF: + rust_error_at (arg_locus, + "unexpected function definition type as variadic " + "argument - cast to function pointer"); + return; + default: + break; + } + } i++; } |