https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118935

--- Comment #1 from chenglulu <chenglulu at loongson dot cn> ---
Upon debugging, it was discovered that if the '-O0' option is used to compile
the `find_file0` function in `libgfortran/io/unix.c`, random errors occur.
However, if the `find_file0` function is compiled with the '-O1' option, no
random errors arise.

The erroneous code is as follows:
libgfortran/io/unix.c
```
static gfc_unit *
find_file0 (gfc_unit *u, FIND_FILE0_DECL)
{
 ......
#ifdef HAVE_WORKING_STAT
  if (u->s != NULL)      // The input I provided next was: At this point, when
making the judgment, u->s is not NULL.
    {
      unix_stream *s = (unix_stream *) (u->s);   
      if (st[0].st_dev == s->st_dev && st[0].st_ino == s->st_ino) // But here
it is NULL,u->s has been modified.
        return u;
    }
```
The corresponding LoongArch assembly code here is as follows.
```
        ld.d    $r12,$r3,8
        ld.d    $r12,$r12,8
        beqz    $r12,.L4   // Here, $r12 is not NULL.
        ld.d    $r12,$r3,8
        ld.d    $r12,$r12,8  // However, when reloaded, it has already become
NULL. 
        st.d    $r12,$r3,24
        ldptr.d $r12,$r3,0
        ldptr.d $r13,$r12,0
        ld.d    $r12,$r3,24
        ld.d    $r12,$r12,72
```

Reply via email to