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

hsc2hs doesn't work with floating-point consts in cross-compilation mode #90

Open
sgillespie opened this issue Jul 9, 2024 · 3 comments

Comments

@sgillespie
Copy link

If a const is defined as floating point or double, --cross-compile fails with:

MyLib.hsc: In function ‘_hsc2hs_test1’:
MyLib.hsc:5:20: error: storage size of ‘test_array’ isn’t constant
compilation failed

In the example above, MyLib.hsc has the following construct:

#const MY_CONST

and MY_CONST is defined in a header file with #define MY_CONST ((double)-123456789.). This is the function it generates:

#include "/nix/store/sk5if9vmsykj16phb87wv7a8pv08wi62-ghc-9.6.5/lib/ghc-9.6.5/lib/template-hsc.h"
#include "../cbits/cross.h"
void _hsc2hs_test1()
{
#line 4 "MyLib.hsc"
    {
        static int test_array[(MY_CONST) > 0 ? 2 : 1];
        (void)test_array;
    }
}

@sgillespie
Copy link
Author

@sgillespie
Copy link
Author

sgillespie commented Jul 11, 2024

I did a few experiments with autoconf to see what it does. I tried passing floats/doubles to ac_fn_c_compute_int, and the results were inconsistent.

If I passed 5.0/5.0f without cross-compiling, I correctly got the integer 5. If I passed 5.1, the result was 0. With cross compiling, I got 0 either way.

@sgillespie
Copy link
Author

There are a few options, hsc2hs could completely disallow non-integrals (as it currently does only with --cross-compile), but that would break existing packages, including text-icu. Another option, would be to modify the binary search to work with floats, which would essentially result in a cast to integer.

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

1 participant