diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-12-15 20:33:33 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-12-15 22:28:12 +0000 |
commit | 24dd9a6aef8493a46e61735b17c9c26bd7c164ef (patch) | |
tree | d14617885960c60ecb777993479bbe967302ec02 | |
parent | 310968874db1902084012cf767ad0b6e93f028c2 (diff) | |
download | gcc-24dd9a6aef8493a46e61735b17c9c26bd7c164ef.zip gcc-24dd9a6aef8493a46e61735b17c9c26bd7c164ef.tar.gz gcc-24dd9a6aef8493a46e61735b17c9c26bd7c164ef.tar.bz2 |
BugFix bad range in typechecking of enum ADTTypes
The type checking over the fields of each variant was using the wrong
iterator causing the type checker to go out of bound in the case where
there were more variants than fields within the variant.
```
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 1)
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
...
-7 0x000000000119dcfc in std::vector<Rust::TyTy::StructFieldType*, std::allocator<Rust::TyTy::StructFieldType*> >::_M_range_check (this=0x426fb90, __n=2) at /usr/include/c++/9/bits/stl_vector.h:1070
-8 0x000000000119a2e5 in std::vector<Rust::TyTy::StructFieldType*, std::allocator<Rust::TyTy::StructFieldType*> >::at (this=0x426fb90, __n=2) at /usr/include/c++/9/bits/stl_vector.h:1091
-9 0x000000000117ead7 in Rust::TyTy::VariantDef::get_field_at_index (this=0x426fb60, index=2) at ../../gccrs/gcc/rust/typecheck/rust-tyty.h:1080
-10 0x00000000011c7523 in Rust::TyTy::ADTRules::visit (this=0x7fffffffce90, type=...) at ../../gccrs/gcc/rust/typecheck/rust-tyty-rules.h:1050
-11 0x00000000011b52a4 in Rust::TyTy::ADTType::accept_vis (this=0x4271120, vis=...) at ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:642
-12 0x00000000011c2d80 in Rust::TyTy::BaseRules::unify (this=0x7fffffffce90, other=0x4271120) at ../../gccrs/gcc/rust/typecheck/rust-tyty-rules.h:85
-13 0x00000000011b552e in Rust::TyTy::ADTType::unify (this=0x426fe30, other=0x4271120) at ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:670
-14 0x000000000118e49f in Rust::Resolver::TypeCheckExpr::visit (this=0x7fffffffd070, expr=...) at ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.h:1302
```
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-cmp.h | 4 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-coercion.h | 4 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-rules.h | 4 |
3 files changed, 6 insertions, 6 deletions
diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index a23855e..291e590 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -1021,8 +1021,8 @@ public: for (size_t j = 0; j < a->num_fields (); j++) { - TyTy::StructFieldType *base_field = a->get_field_at_index (i); - TyTy::StructFieldType *other_field = b->get_field_at_index (i); + TyTy::StructFieldType *base_field = a->get_field_at_index (j); + TyTy::StructFieldType *other_field = b->get_field_at_index (j); TyTy::BaseType *this_field_ty = base_field->get_field_type (); TyTy::BaseType *other_field_ty = other_field->get_field_type (); diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h index 6525da3..b483130 100644 --- a/gcc/rust/typecheck/rust-tyty-coercion.h +++ b/gcc/rust/typecheck/rust-tyty-coercion.h @@ -1031,8 +1031,8 @@ public: for (size_t j = 0; j < a->num_fields (); j++) { - TyTy::StructFieldType *base_field = a->get_field_at_index (i); - TyTy::StructFieldType *other_field = b->get_field_at_index (i); + TyTy::StructFieldType *base_field = a->get_field_at_index (j); + TyTy::StructFieldType *other_field = b->get_field_at_index (j); TyTy::BaseType *this_field_ty = base_field->get_field_type (); TyTy::BaseType *other_field_ty = other_field->get_field_type (); diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h index f044d0e..5dc2d2f 100644 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ b/gcc/rust/typecheck/rust-tyty-rules.h @@ -1047,8 +1047,8 @@ public: for (size_t j = 0; j < a->num_fields (); j++) { - TyTy::StructFieldType *base_field = a->get_field_at_index (i); - TyTy::StructFieldType *other_field = b->get_field_at_index (i); + TyTy::StructFieldType *base_field = a->get_field_at_index (j); + TyTy::StructFieldType *other_field = b->get_field_at_index (j); TyTy::BaseType *this_field_ty = base_field->get_field_type (); TyTy::BaseType *other_field_ty = other_field->get_field_type (); |