aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-21 16:19:30 +0000
committerGitHub <noreply@github.com>2022-01-21 16:19:30 +0000
commita6c5dbadc3c9023821244bd4af4e78ad9d8f63f2 (patch)
treeed72786f6e720f99e1648233c86bf2c77d9c393c
parentb02824c6a798a78657568e7d831bd10529d63e37 (diff)
parentb4587fb281d3066e4591a5067e2fa9a79df272aa (diff)
downloadgcc-a6c5dbadc3c9023821244bd4af4e78ad9d8f63f2.zip
gcc-a6c5dbadc3c9023821244bd4af4e78ad9d8f63f2.tar.gz
gcc-a6c5dbadc3c9023821244bd4af4e78ad9d8f63f2.tar.bz2
Merge #879
879: Record correct location when compiling ADT types r=philberty a=dafaust When compiling struct and union types, we were using the wrong HirId to lookup location information. The resulting GIMPLE nodes therefore had no source location information, which made them indistinguishable as user-declarations versus decls created by the compiler. As a result, the type names were not shown in GIMPLE dumps, e.g. using -fdump-tree-gimple. Fix the location lookup, so these types are properly printed, and add a simple test checking as much. Fixes: #877 Co-authored-by: David Faust <david.faust@oracle.com>
-rw-r--r--gcc/rust/backend/rust-compile-type.cc2
-rw-r--r--gcc/testsuite/rust/compile/torture/struct_decl.rs14
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index d7a8ae5..708f850 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -281,7 +281,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
tree named_struct
= ctx->get_backend ()->named_type (type.get_name (), type_record,
ctx->get_mappings ()->lookup_location (
- type.get_ty_ref ()));
+ type.get_ref ()));
ctx->push_type (named_struct);
translated = named_struct;
diff --git a/gcc/testsuite/rust/compile/torture/struct_decl.rs b/gcc/testsuite/rust/compile/torture/struct_decl.rs
new file mode 100644
index 0000000..3966928
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/struct_decl.rs
@@ -0,0 +1,14 @@
+// { dg-additional-options -fdump-tree-gimple }
+
+struct Foo {
+ a: u16,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+ b: u8,
+// { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+
+fn main() {
+ let my_foo = Foo { a: 1, b: 2 };
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+ // { dg-final { scan-tree-dump-times {(?n)const struct Foo my_foo;$} 1 gimple } }
+}