Bug 82968 - gfortran.dg/ieee/ieee_6.f90 fails at -O0
Summary: gfortran.dg/ieee/ieee_6.f90 fails at -O0
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 12.5
Assignee: Francois-Xavier Coudert
URL:
Keywords: wrong-code
Depends on:
Blocks: fortran-ieee
  Show dependency treegraph
 
Reported: 2017-11-13 17:05 UTC by Eric Botcazou
Modified: 2024-06-20 08:55 UTC (History)
1 user (show)

See Also:
Host: sparc64-linux
Target: sparc64-linux
Build: sparc64-linux
Known to work:
Known to fail:
Last reconfirmed: 2018-01-24 00:00:00


Attachments
Tentative patch (1.60 KB, patch)
2021-12-29 16:06 UTC, Francois-Xavier Coudert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Botcazou 2017-11-13 17:05:21 UTC
The test raises SIGBUS at run time:

Starting program: /1/ebotcazou/build/ieee_6 

Program received signal SIGBUS, Bus error.
__GI___fegetenv (envp=0x7fefffff14c) at ../sysdeps/sparc/fpu/fegetenv.c:25
25      ../sysdeps/sparc/fpu/fegetenv.c: No such file or directory.
(gdb) bt
#0  __GI___fegetenv (envp=0x7fefffff14c) at ../sysdeps/sparc/fpu/fegetenv.c:25
#1  0x0000000000100c68 in MAIN__ () at ieee_6.f90:23

because envp is not a multiple of 8.  On this platform, fenv_t is defined as:

/* Type representing floating-point environment.  */
typedef unsigned long int fenv_t;

so fegetenv expects an address multiple of 8 (the size of 'long').


The problematic Fortran type is apparently declared in ieee_exceptions.F90:

  type, public :: IEEE_STATUS_TYPE
    private
    character(len=GFC_FPE_STATE_BUFFER_SIZE) :: hidden
  end type

with the GFC_FPE_STATE_BUFFER_SIZE parameter coming from libgfortran.h:

/* Size of the buffer required to store FPU state for any target.
   In particular, this has to be larger than fenv_t on all glibc targets.
   Currently, the winner is x86_64 with 32 bytes.  */
#define GFC_FPE_STATE_BUFFER_SIZE 32

This obviously overlooks alignment constraints.
Comment 1 Dominique d'Humieres 2018-01-24 17:44:37 UTC
Target issue?
Comment 2 Eric Botcazou 2019-02-19 09:04:41 UTC
Still present.  The type really needs to be properly aligned...
Comment 3 Francois-Xavier Coudert 2021-12-29 16:06:11 UTC
Created attachment 52084 [details]
Tentative patch
Comment 4 Francois-Xavier Coudert 2021-12-29 16:06:42 UTC
Specifying specific alignment in Fortran code is not directly possibly, sadly. The only way I see how of this is to make that variable an integer, instead of char array.

Eric, could you kindly test the patch attached, and let me know if it fixes gfortran.dg/ieee/ieee_6.f90? Does it introduce any other failure?

I am wondering if this is breaking libgfortran ABI. I think not, but not 100% sure.
Comment 5 Eric Botcazou 2022-01-04 09:07:08 UTC
> Eric, could you kindly test the patch attached, and let me know if it fixes
> gfortran.dg/ieee/ieee_6.f90? Does it introduce any other failure?

The SPARC64/Linux machine of the Compile Farm apparently has network issues.
Comment 6 Eric Botcazou 2022-01-17 22:43:35 UTC
I get this compilation error:

In file included from /home/ebotcazou/src/libgfortran/runtime/fpu.c:29:
./fpu-target.h:36:24: error: invalid application of 'sizeof' to incomplete type 'struct fenv'
   36 | _Static_assert (sizeof(struct fenv) <= 8 * GFC_FPE_STATE_INT_KIND,
      |                        ^~~~~~
./fpu-target.h:36:17: error: expression in static assertion is not an integer
   36 | _Static_assert (sizeof(struct fenv) <= 8 * GFC_FPE_STATE_INT_KIND,
      |                 ^~~~~~
make[2]: *** [Makefile:3071: fpu.lo] Error 1
make[2]: Leaving directory '/home/ebotcazou/build/sparc64-linux-gnu/libgfortran'
make[1]: *** [Makefile:1692: all] Error 2
make[1]: Leaving directory '/home/ebotcazou/build/sparc64-linux-gnu/libgfortran'
make: *** [Makefile:23173: all-target-libgfortran] Error 2
Comment 7 Jakub Jelinek 2022-05-06 08:30:03 UTC
GCC 12.1 is being released, retargeting bugs to GCC 12.2.
Comment 8 Richard Biener 2022-08-19 08:23:28 UTC
GCC 12.2 is being released, retargeting bugs to GCC 12.3.
Comment 9 Richard Biener 2023-05-08 12:21:29 UTC
GCC 12.3 is being released, retargeting bugs to GCC 12.4.
Comment 10 Richard Biener 2024-06-20 08:55:24 UTC
GCC 12.4 is being released, retargeting bugs to GCC 12.5.