[GHC] #12849: hsc2hs trouble with floating-point constants in cross-compilation mode

#12849: hsc2hs trouble with floating-point constants in cross-compilation mode -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 7.8.4 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Split off from #7983. GCC 4.6 rejects some uses of floating-point constants in the declaration of a local static array. From ticket:7983#comment:5:
This is caused by a regression in GCC from gcc-4.4 to gcc-4.6: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46028
{{{ $ cat Test_hsc_test0.c void _hsc2hs_test1() { static int test_array[(89.) > 0 ? 2 : 1]; }
$ /usr/bin/gcc-4.4 -c ./Test_hsc_test0.c
$ /usr/bin/gcc-4.6 -c ./Test_hsc_test0.c ./Test_hsc_test0.c: In function ‘_hsc2hs_test1’: ./Test_hsc_test0.c:3:16: error: storage size of ‘test_array’ isn’t constant }}}
This means that (if your C compiler is affected by this issue) hsc2hs can't handle {{{ (#const 89.) }}} in cross-compilation mode. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12849 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12849: hsc2hs trouble with floating-point constants in cross-compilation mode -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): I did some experiments with {{{ gcc (Debian 5.3.1-6) 5.3.1 20160114 }}} which also has this issue and {{{ Debian clang version 3.6.2-3 (tags/RELEASE_362/final) (based on LLVM 3.6.2) }}} which does not. There seems to be a class of what appear to be constant expressions involving floating-point constants which has the following behavior: * If used as the size of a local static array, gcc gives an error like `storage size of ‘x’ isn’t constant`. * If used as the size of a global array, gcc gives a ''warning'' `variably modified ‘x’ at file scope`. But it's not fatal, and clearly gcc must know the actual size of the array. Very strange! (If the size of a global array is not a constant expression at all, then gcc gives the same message but as an ''error''.) The simplest example of such an expression I found was `(int)(1.0 + 1)`. Clang seems to have no problem with floating-point numbers in constant expressions. So, if we can switch to use global arrays instead of local static arrays for the tests, and ignore these `variably modified` warnings from gcc, we should be able to handle constant expressions involving floating-point numbers correctly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12849#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12849: hsc2hs trouble with floating-point constants in cross-compilation mode -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: hsc2hs | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): A separate issue about hsc2hs and floating-point types: the argument to `#const` gets cast to `long` in direct mode. The hsc2hs manual alludes to this, but does not state it explicitly. So for example, `#const (-1.9)` produces the output `-1`. We should state this explicitly in the manual, and also insert a cast to `long` in the cross-compilation code path to ensure that it matches the direct code path output. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12849#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC