Stream: t-compiler/const-eval

Topic: [MIRI] Integer sizes for cross-interpetation


Christian Poveda (Oct 07 2019 at 21:03, on Zulip):

So, lately I've been running into some problems because of the different integer types used in several shims inside miri. The most prominent one has been clock_gettime because the sizes of long and time_t change with the processor architecture and miri crashes when running the tests in CI for 32 bits linux.

Is it there any way to know which is the target platform when interpreting a program?

oli (Oct 08 2019 at 08:58, on Zulip):

you can ask for the type from libc I think

oli (Oct 08 2019 at 08:58, on Zulip):

basically like we resolve constants

Christian Poveda (Oct 08 2019 at 13:19, on Zulip):

whaAaaAaAaat?

Christian Poveda (Oct 08 2019 at 13:20, on Zulip):

what do you mean by asking for the type?

Christian Poveda (Oct 08 2019 at 14:12, on Zulip):

are you telling me that if I do ecx.resolve_path(&["libc", "long"])?.ty(tcx) that would give me the actual ty::Ty?

oli (Oct 08 2019 at 14:16, on Zulip):

oh sorry, I got lost in my tabs and forgot about this one

oli (Oct 08 2019 at 14:16, on Zulip):

https://github.com/rust-lang/rust-clippy/blob/df80193bda8ae3a5e720612fe24fa313af098812/clippy_lints/src/utils/mod.rs#L240

oli (Oct 08 2019 at 14:16, on Zulip):

is what we use in clippy

Christian Poveda (Oct 08 2019 at 14:26, on Zulip):

Ohhh ok, I'll check it out

Christian Poveda (Oct 08 2019 at 14:27, on Zulip):

What happens with Scalar::from_int(t, Size::from_bits(n)) when the size of the type of t is larger/smaller than n?

oli (Oct 08 2019 at 14:34, on Zulip):

idk ^^

Christian Poveda (Oct 08 2019 at 15:09, on Zulip):

Hahahaha

Christian Poveda (Oct 08 2019 at 15:24, on Zulip):

For the future generations: It truncates t removing the most significant bytes.

RalfJ (Oct 09 2019 at 13:38, on Zulip):

actually it should ICE if t is too big for the given size

Christian Poveda (Oct 09 2019 at 13:39, on Zulip):

But it does not

RalfJ (Oct 09 2019 at 13:40, on Zulip):

but we have an assert right here:
https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc/mir/interpret/value.rs.html#269-276

RalfJ (Oct 09 2019 at 13:41, on Zulip):

@Christian Poveda what exactly did you test? I have seen that ICE several times, and was glad for it each time as it caught critical bugs.

RalfJ (Oct 09 2019 at 13:41, on Zulip):

oh wait @Christian Poveda what exactly do you mean by "the size of the type of t"?

RalfJ (Oct 09 2019 at 13:41, on Zulip):

the type of t does not matter

Christian Poveda (Oct 09 2019 at 13:41, on Zulip):

is that the size of t given by its type or just how many bits/bytes t uses?

RalfJ (Oct 09 2019 at 13:41, on Zulip):

it is always cast to i128 first

Christian Poveda (Oct 09 2019 at 13:41, on Zulip):

hahahaha

RalfJ (Oct 09 2019 at 13:41, on Zulip):

it will never truncate but if you have an i64 that can be loslessly turned into an i32 you are good

Christian Poveda (Oct 09 2019 at 13:42, on Zulip):

yeah that's the confusion

RalfJ (Oct 09 2019 at 13:42, on Zulip):

here we think of t as an abstract integer, not a machine-integer with some bitwidth

Christian Poveda (Oct 09 2019 at 13:42, on Zulip):

yes got it

RalfJ (Oct 09 2019 at 13:42, on Zulip):

and we check if that abstract integer fits into the given size

RalfJ (Oct 09 2019 at 13:43, on Zulip):

it seems like a code smell though if you have a "too big" type there

RalfJ (Oct 09 2019 at 13:43, on Zulip):

as it might mean that ICE is reachable, which it never should be

Christian Poveda (Oct 09 2019 at 13:45, on Zulip):

yes so, for the particular case I'm using it, that would mean that this might blow up if the host platform returns Integers that are too large for the target platform

Christian Poveda (Oct 09 2019 at 13:48, on Zulip):

so do we want an ice happening there? because the other option would be to let those Integers overflow which might produce undesired results without erroring anywhere

RalfJ (Oct 09 2019 at 14:14, on Zulip):

throw_unsup sounds like the best reaction for that case

Christian Poveda (Oct 09 2019 at 15:57, on Zulip):

Ok then, I added the same check that Scalar::from_int has but it errors instead.

RalfJ (Oct 09 2019 at 16:02, on Zulip):

sounds reasonable

Christian Poveda (Oct 09 2019 at 16:03, on Zulip):

I wanted to get the target's type max and min values and compare but I think it's not worth the trouble

Christian Poveda (Oct 09 2019 at 16:08, on Zulip):

In particular because that would need to cast the values again to i128 to compare in the first place

RalfJ (Oct 09 2019 at 16:36, on Zulip):

yeah

Last update: Nov 15 2019 at 21:00UTC