public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7869] gccrs: Fix ICE by adding check for enum candidate's in TypePath resolution
@ 2024-01-16 18:05 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:05 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:432cdee6a6e28c52dae6b69079db301b9681485b
commit r14-7869-g432cdee6a6e28c52dae6b69079db301b9681485b
Author: Philip Herron <herron.philip@googlemail.com>
Date: Sun Jul 30 18:59:06 2023 +0100
gccrs: Fix ICE by adding check for enum candidate's in TypePath resolution
Fixes #2479
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
always resolve the type even when its an a mandatory trait item
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Add check for enum candidates otherwise you get undefined behaviour
gcc/testsuite/ChangeLog:
* rust/compile/issue-2479.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diff:
---
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 6 +++---
gcc/rust/typecheck/rust-hir-type-check-type.cc | 18 ++++++++++++++++++
gcc/testsuite/rust/compile/issue-2479.rs | 22 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 17827753198..b99fe2341af 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -339,13 +339,13 @@ TraitItemReference::resolve_item (HIR::TraitItemConst &constant)
void
TraitItemReference::resolve_item (HIR::TraitItemFunc &func)
{
- if (!is_optional ())
- return;
-
TyTy::BaseType *item_tyty = get_tyty ();
if (item_tyty->get_kind () == TyTy::TypeKind::ERROR)
return;
+ if (!is_optional ())
+ return;
+
// check the block and return types
rust_assert (item_tyty->get_kind () == TyTy::TypeKind::FNDEF);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 03ee74aeb10..b3125f7e1a5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -440,6 +440,16 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
*root_resolved_node_id = ref_node_id;
*offset = *offset + 1;
root_tyty = lookup;
+
+ // this enforces the proper get_segments checks to take place
+ bool is_adt = root_tyty->get_kind () == TyTy::TypeKind::ADT;
+ if (is_adt)
+ {
+ const TyTy::ADTType &adt
+ = *static_cast<const TyTy::ADTType *> (root_tyty);
+ if (adt.is_enum ())
+ return root_tyty;
+ }
}
return root_tyty;
@@ -498,6 +508,14 @@ TypeCheckType::resolve_segments (
prev_segment = tyseg;
tyseg = candidate.ty;
+ if (candidate.is_enum_candidate ())
+ {
+ rust_error_at (seg->get_locus (),
+ "expected type, found variant of %s",
+ tyseg->get_name ().c_str ());
+ return new TyTy::ErrorType (expr_id);
+ }
+
if (candidate.is_impl_candidate ())
{
resolved_node_id
diff --git a/gcc/testsuite/rust/compile/issue-2479.rs b/gcc/testsuite/rust/compile/issue-2479.rs
new file mode 100644
index 00000000000..4a0d3547b75
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2479.rs
@@ -0,0 +1,22 @@
+#![allow(unused)]
+fn main() {
+enum Dragon {
+ Born,
+}
+
+fn oblivion() -> Dragon::Born {
+// { dg-error "expected type, found variant of Dragon" "" { target *-*-* } .-1 }
+// { dg-error "failed to resolve return type" "" { target *-*-* } .-2 }
+ Dragon::Born
+}
+
+enum Wizard {
+ Gandalf,
+ Saruman,
+}
+
+trait Isengard {
+ fn wizard(_: Wizard::Saruman);
+ // { dg-error "expected type, found variant of Wizard" "" { target *-*-* } .-1 }
+}
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 18:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:05 [gcc r14-7869] gccrs: Fix ICE by adding check for enum candidate's in TypePath resolution Arthur Cohen
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).