Stream: t-compiler/wg-prioritization/alerts

Topic: #80556 ICE when returning an repr(i8) enum from an extern c…


triagebot (Dec 31 2020 at 13:41, on Zulip):

@WG-prioritization/alerts issue #80556 has been requested for prioritization.

Procedure

lcnr (Dec 31 2020 at 13:42, on Zulip):

hmm, P-medium or P-high imo.

apiraino (Dec 31 2020 at 13:53, on Zulip):

IIUC the sample provided is trying to cast to an i8 a custom Type that should fit the representation, right?

apiraino (Dec 31 2020 at 13:54, on Zulip):

I mean, is the code there legal or should return an error?

apiraino (Dec 31 2020 at 13:55, on Zulip):

also I don't understand if the LLVM error suggests an issue at the llvm level

lcnr (Dec 31 2020 at 13:56, on Zulip):

apiraino said:

IIUC the sample provided is trying to cast to an i8 a custom Type that should fit the representation, right?

does it? the example tries to use an ffi safe enum in an extern function afaict

lcnr (Dec 31 2020 at 13:56, on Zulip):

the issue looks to me like we shouldn't use zeroext for repr(iN) enums

lcnr (Dec 31 2020 at 13:56, on Zulip):

though i am not too familiar with llvm myself

lcnr (Dec 31 2020 at 13:57, on Zulip):

so the issue is during codegen and probably a bug on our side

apiraino (Dec 31 2020 at 14:00, on Zulip):

make sense, thanks for clarifying (am trying to understand the context)

Camelid (Jan 01 2021 at 01:34, on Zulip):

Seems like maybe P-medium because it's been around since 1.24 (according to matthiaskrgr).

Camelid (Jan 01 2021 at 01:34, on Zulip):

So is this code supposed to compile? It seems like yes.

Stu (Jan 01 2021 at 01:40, on Zulip):

Yea I agree with medium. Rust Enums are usually not used in a FFI API

Camelid (Jan 01 2021 at 20:16, on Zulip):

The enum is repr(i8), which (I think?) means it's FFI-safe.

Stu (Jan 01 2021 at 20:18, on Zulip):

I'm not sure, but even if it is, it's not often used in FFI (I guess), because it can produce invalid values if the FFI function returns an out of bounds number. So a "constified enum" or "newtyped enum", like bindgen can generate, are more often used.

Use this with caution, creating this in unsafe code (including FFI) with an invalid value will invoke undefined behaviour. You may want to use the newtype enum style instead.

Bindgen also warns about it

lcnr (Jan 01 2021 at 20:26, on Zulip):

repr(i8) is ffi safe

Ryan Levick (Jan 04 2021 at 08:56, on Zulip):

I would have considered this a P-high but it's been a regression since 1.24... Shall we do P-medium?

Stu (Jan 04 2021 at 11:33, on Zulip):

Yea I think P-medium is fine

triagebot (Jan 04 2021 at 11:36, on Zulip):

Issue #80556's prioritization request has been removed.

Last update: Apr 15 2021 at 01:15UTC