Skip to content

Commit 64f7a4a

Browse files
Fix bswap intrinsic error location
When bswap is used with an incorrect type, print the location of the call site, not the declaration. Fixes #4465. gcc/rust/ChangeLog: * backend/rust-intrinsic-handlers.cc: use call site error location instead of the declaration location gcc/testsuite/ChangeLog: * rust/compile/bswap.rs: update error location Signed-off-by: Jean-Christian CÎRSTEA <jean-christian.cirstea@tuta.com>
1 parent 3deeccb commit 64f7a4a

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

gcc/rust/backend/rust-intrinsic-handlers.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ check_for_basic_integer_type (const std::string &intrinsic_str,
8080
{
8181
rust_error_at (
8282
locus,
83-
"%s intrinsics can only be used with basic integer types (got %qs)",
83+
"%s intrinsic can only be used with basic integer types (got %qs)",
8484
intrinsic_str.c_str (), type->get_name ().c_str ());
8585
}
8686

@@ -1397,8 +1397,8 @@ bswap_handler (Context *ctx, TyTy::FnType *fntype)
13971397
auto *monomorphized_type
13981398
= fntype->get_substs ().at (0).get_param_ty ()->resolve ();
13991399

1400-
check_for_basic_integer_type ("bswap", fntype->get_locus (),
1401-
monomorphized_type);
1400+
auto call_locus = ctx->get_mappings ().lookup_location (fntype->get_ref ());
1401+
check_for_basic_integer_type ("bswap", call_locus, monomorphized_type);
14021402

14031403
tree template_parameter_type
14041404
= TyTyResolveCompile::compile (ctx, monomorphized_type);

gcc/testsuite/rust/compile/bswap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub trait Sized {}
99
pub trait Copy {}
1010

1111
extern "rust-intrinsic" {
12-
pub fn bswap<T>(x: T) -> T; // { dg-error "bswap intrinsics can only be used with basic integer types .got 'bool'." }
12+
pub fn bswap<T>(x: T) -> T;
1313
}
1414

1515
fn main() {
16-
let _ = bswap(true);
16+
let _ = bswap(true); // { dg-error "bswap intrinsics can only be used with basic integer types .got 'bool'." }
1717
}

0 commit comments

Comments
 (0)