Skip to content

Commit 9c25095

Browse files
Fix intrinsic error location
When an intrisic is used with an incorrect type, prin 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 9c25095

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 8 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

@@ -218,7 +218,7 @@ build_atomic_builtin_name (const std::string &prefix, location_t locus,
218218

219219
auto type_size_str = allowed_types.find (type_name);
220220

221-
if (!check_for_basic_integer_type ("atomic", locus, operand_type))
221+
if (!check_for_basic_integer_type ("atomic operation", locus, operand_type))
222222
return "";
223223

224224
result += type_size_str->second;
@@ -255,7 +255,8 @@ unchecked_op (Context *ctx, TyTy::FnType *fntype, tree_code op)
255255
auto *monomorphized_type
256256
= fntype->get_substs ().at (0).get_param_ty ()->resolve ();
257257

258-
check_for_basic_integer_type ("unchecked operation", fntype->get_locus (),
258+
auto call_locus = ctx->get_mappings ().lookup_location (fntype->get_ref ());
259+
check_for_basic_integer_type ("unchecked operation", call_locus,
259260
monomorphized_type);
260261

261262
auto expr = build2 (op, TREE_TYPE (x), x, y);
@@ -660,9 +661,9 @@ atomic_store (Context *ctx, TyTy::FnType *fntype, int ordering)
660661
auto monomorphized_type
661662
= fntype->get_substs ()[0].get_param_ty ()->resolve ();
662663

663-
auto builtin_name
664-
= build_atomic_builtin_name ("atomic_store_", fntype->get_locus (),
665-
monomorphized_type);
664+
auto call_locus = ctx->get_mappings ().lookup_location (fntype->get_ref ());
665+
auto builtin_name = build_atomic_builtin_name ("atomic_store_", call_locus,
666+
monomorphized_type);
666667
if (builtin_name.empty ())
667668
return error_mark_node;
668669

@@ -1397,8 +1398,8 @@ bswap_handler (Context *ctx, TyTy::FnType *fntype)
13971398
auto *monomorphized_type
13981399
= fntype->get_substs ().at (0).get_param_ty ()->resolve ();
13991400

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

14031404
tree template_parameter_type
14041405
= 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 intrinsic can only be used with basic integer types .got .bool.." }
1717
}

gcc/testsuite/rust/compile/torture/intrinsics-5.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ mod copy_impls {
6565

6666
extern "rust-intrinsic" {
6767
pub fn atomic_store_seqcst<T: Copy>(dst: *mut T, value: T);
68-
// { dg-error "atomic intrinsics can only be used with basic integer types .got .VeryLargeType.." "" { target *-*-* } .-1 }
69-
// { dg-error "atomic intrinsics can only be used with basic integer types .got .bool.." "" { target *-*-* } .-2 }
7068
}
7169

7270
struct VeryLargeType {
@@ -100,6 +98,8 @@ fn main() {
10098

10199
unsafe {
102100
atomic_store_seqcst(&mut dst, VeryLargeType::new(1));
101+
// { dg-error "atomic operation intrinsic can only be used with basic integer types .got .VeryLargeType.." "" { target *-*-* } .-1 }
103102
atomic_store_seqcst(&mut b, true);
103+
// { dg-error "atomic operation intrinsic can only be used with basic integer types .got .bool.." "" { target *-*-* } .-1 }
104104
}
105105
}

gcc/testsuite/rust/compile/torture/intrinsics-7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ pub trait Sized {}
99

1010
extern "rust-intrinsic" {
1111
pub fn unchecked_add<T>(x: T, y: T) -> T;
12-
// { dg-error "unchecked operation intrinsics can only be used with basic integer types .got .NotAdd.." "" { target *-*-* } .-1 }
1312
}
1413

1514
fn main() {
1615
struct NotAdd;
1716

1817
unsafe { unchecked_add(NotAdd, NotAdd) };
18+
// { dg-error "unchecked operation intrinsic can only be used with basic integer types .got .NotAdd.." "" { target *-*-* } .-1 }
1919
}

0 commit comments

Comments
 (0)