aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-03 13:19:35 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-06 15:45:51 +0000
commit7098b373172354a9d68d319fdbfcc07f99970914 (patch)
tree400fbf63fbcf009f2be67eee51b150895e1451ad /gcc
parent75b6fc46bd64599e565582b46bf6f2197b2bc53f (diff)
downloadgcc-7098b373172354a9d68d319fdbfcc07f99970914.zip
gcc-7098b373172354a9d68d319fdbfcc07f99970914.tar.gz
gcc-7098b373172354a9d68d319fdbfcc07f99970914.tar.bz2
Fix unreachable crash when a struct contains another algebraic data type
When we have a nested struct this must resolve to the existing compiled struct and not create a new record type.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-context.h3
-rw-r--r--gcc/testsuite/rust.test/compilable/nested_struct1.rs17
2 files changed, 18 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 194ee06..7d131f2 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -283,8 +283,7 @@ public:
{
TyTy::StructFieldType *field = type.get_field (i);
Btype *compiled_field_ty
- = TyTyCompile::compile (ctx->get_backend (),
- field->get_field_type ());
+ = TyTyResolveCompile::compile (ctx, field->get_field_type ());
Backend::Btyped_identifier f (field->get_name (), compiled_field_ty,
ctx->get_mappings ()->lookup_location (
diff --git a/gcc/testsuite/rust.test/compilable/nested_struct1.rs b/gcc/testsuite/rust.test/compilable/nested_struct1.rs
new file mode 100644
index 0000000..3880be0
--- /dev/null
+++ b/gcc/testsuite/rust.test/compilable/nested_struct1.rs
@@ -0,0 +1,17 @@
+struct Point {
+ x: f64,
+ y: f64,
+}
+
+struct Rectangle {
+ p1: Point,
+ p2: Point,
+}
+
+fn main() {
+ let p1 = Point { x: 0.0, y: 0.0 };
+ let p2 = Point { x: 2.0, y: 4.0 };
+ let rect = Rectangle { p1, p2 };
+
+ let a = rect.p1.x;
+}