libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libjit] Creating constant values of different types


From: Eli Zaretskii
Subject: [Libjit] Creating constant values of different types
Date: Mon, 20 Aug 2018 22:11:10 +0300

There seem to be some hidden assumptions/dependencies between the
various jit_value_create_TYPE_constant functions and the TYPE argument
they accept.

For example, jit_value_create_long_constant is documented to always
create a 64-bit integer value, but it actually stores with the value
the TYPE passed to it as its last argument, so one could put any type
there.  If you do use type other than jit_long or jit_ulong, then
getting the value back, e.g. with jit_value_get_long_constant will
fail, and using other functions, like jit_value_get_nint_constant,
will work on 64-bit platforms, but silently produce the wrong value on
32-bit ones.

As an example,

  jit_value_t v1 = jit_value_create_long_constant (f, x1, jit_type_nint);

will create a value v1 whose type is jit_type_nint, so one might be
tempted to use jit_value_get_nint_constant to obtain the value of x1
back, which won't work.  Thus, it could be argued that
jit_value_create_long_constant should not allow any TYPE except
jit_long or jit_ulong.

Another subtlety is the jit_nint type and jit_value_get_nint_constant
that creates values of that type.  The documentation says that this
function can be used to create "all pointer types" -- does that mean
this is a 64-bit type on 64-bit hosts?  (If so, the "int" part of
"nint" is mildly misleading, IMO.)

Finally, the documentation mentions the sys_longlong type, but doesn't
say what function can create constants of that type; I understand that
only jit_value_create_long_constant can do that safely, is that true?

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]