Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast necessary after integer promotion sometimes omitted #3

Open
rversteegen opened this issue Jan 6, 2021 · 3 comments
Open

Cast necessary after integer promotion sometimes omitted #3

rversteegen opened this issue Jan 6, 2021 · 3 comments

Comments

@rversteegen
Copy link
Member

typedef unsigned int jit_uint;
#define	jit_label_undefined	((size_t)~((jit_uint)0))

(which has value 4294967295 on both x86-linux and x86_64-linux)
is translated by fbfrog (latest git head) to

type jit_uint as ulong
#define jit_label_undefined cuint(not cast(jit_uint, 0))

which has value 4294967295 on x86-linux and 18446744073709551615 on x86_64-linux.

On the other hand

#define	jit_label_undefined	((size_t)~((unsigned int)0))

translates to

const jit_label_undefined = cuint(culng(not culng(0)))

which has the correct value, 4294967295, on x86 and x86_64.

The double casts are necessary to paper over the difference in integer promotion rules between FB and C (which promote to integer and int respectively).

@rversteegen
Copy link
Member Author

Another example:

#define	jit_min_int		(((int)1) << (sizeof(int) * 8 - 1))

In C this evaluates to -2147483648 on x86/x86_86-linux, but fbfrog translates to

#define jit_min_int3 (clng(1) shl ((sizeof(long) * 8) - 1))

which is -2147483648 on x86 but 2147483648 on x86_64; the type is integer in both cases.

rversteegen added a commit to freebasic/fbbindings that referenced this issue Jan 6, 2021
@dkl
Copy link
Member

dkl commented Jan 6, 2021

Looks like the typedef cast is what breaks it, this seems to work:

#define	jit_label_undefined2	((size_t)~((unsigned int)0))
const jit_label_undefined2 = cuint(culng(not culng(0)))

dkl added a commit that referenced this issue Jan 6, 2021
dkl added a commit that referenced this issue Jan 6, 2021
TODO: need to check whether all changes are OK/acceptable, but might be
too much to permanently solve out known typedefs from expressions.
(not wrong, but maybe unnecessarily different from the original header)

Fixes: #3
@dkl
Copy link
Member

dkl commented Jan 6, 2021

Potential fix in fe043a7, but there are some side-effects which might require some testing with real bindings first. Also I'm pretty sure there are more missing cases, so if there's anything easy & obvious, it can probably be fixed aswell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants