public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Fix ICE in generic subsitution of enums containing dataless variants Date: Wed, 8 Jun 2022 11:58:31 +0000 (GMT) [thread overview] Message-ID: <20220608115831.176C73AA8C26@sourceware.org> (raw) https://gcc.gnu.org/g:5b369a61484c52ea0298cfab11858c3fff8bcc00 commit 5b369a61484c52ea0298cfab11858c3fff8bcc00 Author: Philip Herron <philip.herron@embecosm.com> Date: Tue Jan 4 16:15:26 2022 +0000 Fix ICE in generic subsitution of enums containing dataless variants Dataless variants do not contain fields that can be substituted, which then hits an assertion on access of the fields for the variant. This patch adds a guard against the substitution of dataless variants. We could have removed the assertion which would have also been a good fix but keeping the assertion for now is very helpful in debugging issues. Fixs #851 Diff: --- gcc/rust/typecheck/rust-tyty.cc | 3 +++ gcc/rust/typecheck/rust-tyty.h | 2 ++ gcc/testsuite/rust/execute/torture/issue-851.rs | 35 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 25fdfa9db79..f141a4118c8 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -822,6 +822,9 @@ ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings) for (auto &variant : adt->get_variants ()) { + if (variant->is_dataless_variant ()) + continue; + for (auto &field : variant->get_fields ()) { bool ok = ::Rust::TyTy::handle_substitions (subst_mappings, field); diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 012e8464ee2..40c06a57783 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1069,6 +1069,8 @@ public: HirId get_id () const { return id; } VariantType get_variant_type () const { return type; } + bool is_data_variant () const { return type != VariantType::NUM; } + bool is_dataless_variant () const { return type == VariantType::NUM; } std::string get_identifier () const { return identifier; } int get_discriminant () const { return discriminant; } diff --git a/gcc/testsuite/rust/execute/torture/issue-851.rs b/gcc/testsuite/rust/execute/torture/issue-851.rs new file mode 100644 index 00000000000..3881c7a2ada --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-851.rs @@ -0,0 +1,35 @@ +/* { dg-output "Result: 123\n" } */ +extern "C" { + fn printf(s: *const i8, ...); +} + +enum Foo<T> { + A, + B(T), +} + +fn inspect(a: Foo<i32>) { + match a { + Foo::A => unsafe { + let a = "A\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c); + }, + Foo::B(x) => unsafe { + let a = "Result: %i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, x); + }, + } +} + +fn main() -> i32 { + let a = Foo::B(123); + inspect(a); + + 0 +}
reply other threads:[~2022-06-08 11:58 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608115831.176C73AA8C26@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).