Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions gcc/rust/typecheck/rust-tyty-call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ TypeCheckCallExpr::visit (FnType &type)
if ((int_ty.get_int_kind () == TyTy::IntType::IntKind::I8)
|| (int_ty.get_int_kind () == TyTy::IntType::IntKind::I16))
{
rust_error_at (arg_locus,
rich_location richloc (line_table, arg_locus);
richloc.add_fixit_replace (
"cast the value to c_int: as c_int");
rust_error_at (richloc, ErrorCode::E0617,
Comment on lines -187 to +190
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combining all of these into one function with different messages might seem like a bit overkill, but if it works better, I'll do that.

"expected %<c_int%> variadic argument");
return;
}
Expand All @@ -197,7 +200,10 @@ TypeCheckCallExpr::visit (FnType &type)
|| (uint_ty.get_uint_kind ()
== TyTy::UintType::UintKind::U16))
{
rust_error_at (arg_locus,
rich_location richloc (line_table, arg_locus);
richloc.add_fixit_replace (
"cast the value to c_uint: as c_uint");
rust_error_at (richloc, ErrorCode::E0617,
"expected %<c_uint%> variadic argument");
return;
}
Expand All @@ -208,19 +214,28 @@ TypeCheckCallExpr::visit (FnType &type)
.get_float_kind ()
== TyTy::FloatType::FloatKind::F32)
{
rust_error_at (arg_locus,
rich_location richloc (line_table, arg_locus);
richloc.add_fixit_replace (
"cast the value to c_double: as c_double");
rust_error_at (richloc, ErrorCode::E0617,
"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");
case TyTy::TypeKind::BOOL: {
rich_location richloc (line_table, arg_locus);
richloc.add_fixit_replace ("cast the value to c_int: as c_int");
rust_error_at (arg_locus, ErrorCode::E0617,
"expected %<c_int%> variadic argument");
return;
}
case TyTy::TypeKind::FNDEF: {
rust_error_at (
arg_locus, ErrorCode::E0617,
"unexpected function definition type as variadic "
"argument - cast to function pointer");
}
return;
default:
break;
Expand Down
8 changes: 7 additions & 1 deletion gcc/testsuite/rust/compile/variadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ extern "C" {

fn main() {
// { dg-error "expected .c_int. variadic argument" "" { target *-*-* } .+1 }
printf("%d\n" as *const str as *const i8, 1i8);
printf("%d\n" as *const str as *const i8, 1i8);

// { dg-error "expected .c_uint. variadic argument" "" { target *-*-* } .+1 }
printf("%d\n" as *const str as *const i8, 1u8);

// { dg-error "expected .c_double. variadic argument" "" { target *-*-* } .+1 }
printf("%d\n" as *const str as *const i8, 1f32);
}