public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Record correct location when compiling ADT types
@ 2022-06-08 12:00 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b4587fb281d3066e4591a5067e2fa9a79df272aa

commit b4587fb281d3066e4591a5067e2fa9a79df272aa
Author: David Faust <david.faust@oracle.com>
Date:   Thu Jan 20 12:43:51 2022 -0800

    Record correct location when compiling ADT types
    
    When compiling ADTTypes, the wrong HirId was being used for location
    lookup. This produced an issue where the gimple dump would not write
    type names for struct and union types, because they were mistaken for
    built-in types.
    
    Also add new test testsuite/rust/compile/torture/struct_decl.rs.
    
    Fixes: #877

Diff:
---
 gcc/rust/backend/rust-compile-type.cc             |  2 +-
 gcc/testsuite/rust/compile/torture/struct_decl.rs | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index d7a8ae56758..708f850d96d 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 00000000000..39669285752
--- /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 } }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:00 [gcc/devel/rust/master] Record correct location when compiling ADT types Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).