public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108693] New: Update shared character array inside OpenMP critical section causes internal compiler error
@ 2023-02-07 11:28 hamchugh at amd dot com
  2023-02-07 20:32 ` [Bug fortran/108693] " anlauf at gcc dot gnu.org
  2023-02-15  9:33 ` burnus at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: hamchugh at amd dot com @ 2023-02-07 11:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108693
           Summary: Update shared character array inside OpenMP critical
                    section causes internal compiler error
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hamchugh at amd dot com
  Target Milestone: ---

Created attachment 54417
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54417&action=edit
source code

Good morning, 

I have a small FORTRAN source code where a shared character array is updated
inside an OpenMP critical region. The source code is provided as
openmp_test.F90.

The code is compiled as:

gfortran -v -O0 -Wall -Wextra -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -fopenmp -save-temps openmp_test.F90 -o
openmp-test-gfortran

This causes an internal compiler error:

Driving: gfortran -v -O0 -Wall -Wextra -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -fopenmp -save-temps openmp_test.F90 -o
openmp-test-gfortran -l gfortran -l m -shared-libgcc
Reading specs from
/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib/gcc/x86_64-pc-linux-gnu/12.2.0/specs
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/libexec/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/configure
--prefix=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4
--with-pkgversion='Spack GCC'
--with-bugurl=https://github.com/spack/spack/issues --disable-multilib
--enable-languages=c,c++,fortran --disable-nls
--disable-canonical-system-headers --with-system-zlib
--with-zstd-include=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/zstd-1.5.2-m4lztdopwi2qzqvt3jtfaznftfdwv47n/include
--with-zstd-lib=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/zstd-1.5.2-m4lztdopwi2qzqvt3jtfaznftfdwv47n/lib
--enable-bootstrap
--with-mpfr-include=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpfr-4.1.0-3cmjotnpqe4o4jrfqj4trvnpefv5us6y/include
--with-mpfr-lib=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpfr-4.1.0-3cmjotnpqe4o4jrfqj4trvnpefv5us6y/lib
--with-gmp-include=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gmp-6.2.1-wo7ihyuv7rdybfgoxj3lgspjpqfipkn7/include
--with-gmp-lib=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gmp-6.2.1-wo7ihyuv7rdybfgoxj3lgspjpqfipkn7/lib
--with-mpc-include=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpc-1.2.1-66jzajqy27dj57ltanedqoqq5l7glu2v/include
--with-mpc-lib=/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpc-1.2.1-66jzajqy27dj57ltanedqoqq5l7glu2v/lib
--without-isl
--with-stage1-ldflags='-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib64
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gmp-6.2.1-wo7ihyuv7rdybfgoxj3lgspjpqfipkn7/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpc-1.2.1-66jzajqy27dj57ltanedqoqq5l7glu2v/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpfr-4.1.0-3cmjotnpqe4o4jrfqj4trvnpefv5us6y/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/zlib-1.2.13-4sy72bkxib5hfr2zuhmn2wmieakmxolq/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/zstd-1.5.2-m4lztdopwi2qzqvt3jtfaznftfdwv47n/lib'
--with-boot-ldflags='-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib64
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gmp-6.2.1-wo7ihyuv7rdybfgoxj3lgspjpqfipkn7/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpc-1.2.1-66jzajqy27dj57ltanedqoqq5l7glu2v/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/mpfr-4.1.0-3cmjotnpqe4o4jrfqj4trvnpefv5us6y/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/zlib-1.2.13-4sy72bkxib5hfr2zuhmn2wmieakmxolq/lib
-Wl,-rpath,/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/zstd-1.5.2-m4lztdopwi2qzqvt3jtfaznftfdwv47n/lib
-static-libstdc++ -static-libgcc' --with-build-config=spack
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Spack GCC) 
COLLECT_GCC_OPTIONS='-v' '-O0' '-Wall' '-Wextra' '-fno-strict-aliasing'
'-fwrapv' '-fno-aggressive-loop-optimizations' '-fopenmp' '-save-temps' '-o'
'openmp-test-gfortran' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
'-pthread' '-dumpdir' 'openmp-test-gfortran-'

/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/libexec/gcc/x86_64-pc-linux-gnu/12.2.0/f951
openmp_test.F90 -cpp=openmp-test-gfortran-openmp_test.f90 -quiet -v -imultiarch
x86_64-linux-gnu -D_REENTRANT openmp_test.F90 -quiet -dumpdir
openmp-test-gfortran- -dumpbase openmp_test.F90 -dumpbase-ext .F90
-mtune=generic -march=x86-64 -O0 -Wall -Wextra -version -fno-strict-aliasing
-fwrapv -fno-aggressive-loop-optimizations -fopenmp -fintrinsic-modules-path
/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib/gcc/x86_64-pc-linux-gnu/12.2.0/finclude
-fpre-include=/usr/include/finclude/math-vector-fortran.h -o
openmp-test-gfortran-openmp_test.s
GNU Fortran (Spack GCC) version 12.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib/gcc/x86_64-pc-linux-gnu/12.2.0/finclude
 .
 /home/harry/amd/aocc-compiler-4.0.0/include

/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include
 /usr/local/include

/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/include

/home/harry/spack/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.4.0/gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU Fortran2008 (Spack GCC) version 12.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
during GIMPLE pass: omplower
openmp_test.F90:38:64:

   38 |     !$OMP PARALLEL DEFAULT(NONE) SHARED(mask) PRIVATE(thread_id)
      |                                                                ^
internal compiler error: in gimplify_expr, at gimplify.cc:15428
0x67e01e gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15428
0xa3a2be gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15866
0xa3ef7f internal_get_tmp_var
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:626
0xa3c0f5 get_initialized_tmp_var(tree_node*, gimple**, gimple**, bool)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:681
0xa3c0f5 gimplify_save_expr
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:6395
0xa3c0f5 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15399
0xa3a23f gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15875
0xa3fde9 gimplify_expr
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:16157
0xa3fde9 gimplify_arg(tree_node**, gimple**, unsigned int, bool)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:3502
0xa40034 gimplify_call_expr
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:3739
0xa3abb8 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15070
0xa4586d gimplify_modify_expr
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:6085
0xa39f23 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15098
0xa3b515 gimplify_stmt(tree_node**, gimple**)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:7151
0xa3b515 gimplify_statement_list
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:2019
0xa3b515 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15543
0xa42fd2 gimplify_stmt(tree_node**, gimple**)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:7151
0xa42fd2 gimplify_cond_expr
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:4493
0xa3abd7 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:15055
0xa416fd gimplify_stmt(tree_node**, gimple**)
       
/tmp/harry/spack-stage/spack-stage-gcc-12.2.0-3m7sdjb7xtzzv6fawh5xgbd4c65zufw4/spack-src/gcc/gimplify.cc:7151
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://github.com/spack/spack/issues> for instructions.

The exact compiler version is:

GNU Fortran (Spack GCC) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Using the Godbolt compiler explorer website I can narrow this error being
introduced sometime between Gfortran v5.5 (successfully compiles) and v6.3
(does not compile).

Best regards,
Harry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/108693] Update shared character array inside OpenMP critical section causes internal compiler error
  2023-02-07 11:28 [Bug fortran/108693] New: Update shared character array inside OpenMP critical section causes internal compiler error hamchugh at amd dot com
@ 2023-02-07 20:32 ` anlauf at gcc dot gnu.org
  2023-02-15  9:33 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-02-07 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |ice-on-valid-code
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-02-07

--- Comment #1 from anlauf at gcc dot gnu.org ---
The code has a simple bug, as it violates array bounds as threads are
counted starting from 0, not 1.  This is fixed by replacing

  thread_id = OMP_GET_THREAD_NUM()

by

  thread_id = OMP_GET_THREAD_NUM() + 1

The ICE seems to occur only for deferred character length variables.
A small modification to use an array of character(len=1) seems to work.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/108693] Update shared character array inside OpenMP critical section causes internal compiler error
  2023-02-07 11:28 [Bug fortran/108693] New: Update shared character array inside OpenMP critical section causes internal compiler error hamchugh at amd dot com
  2023-02-07 20:32 ` [Bug fortran/108693] " anlauf at gcc dot gnu.org
@ 2023-02-15  9:33 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-02-15  9:33 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |97977
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Pre-remark: Allocatable scalar character variables consists of a pointer to the
actual data ('mask') and a hidden variable ('.mask') which contains the string
length.

 * * *

lower_omp_taskreg calls lower_rec_input_clauses which has:


6199                  x = build_outer_var_ref (var, ctx);

(gdb) p debug(x)
.omp_data_i->mask


So far so good, but when calling

6329       x = lang_hooks.decls.omp_clause_copy_ctor
6330                                   (c, unshare_expr (new_var), x);

But that causes too much code to be generated and that code
also has an error_mark_node:


(gdb) p debug(x)
{
  void * D.4350;

  if ((void *) .omp_data_i->mask != 0B)
    {
      mask = (character(kind=1)[1:D.4340] *) .omp_data_i->mask;
      D.4350 = __builtin_malloc (MAX_EXPR <(unsigned long) SAVE_EXPR
<(sizetype) NON_LVALUE_EXPR <<<< error >>>>>, 1>);

* * *

I think one issue is that there is no 'shared(.mask)' to make the string
available. — We had a similar discussion elsewhere. -> PR97977.

I vaguely recall some IRC discussion about this that the solution is
non-trivial in general (for implicit mapping). However, here we have an
explicit 'share(mask)', where adding an implicit 'share(.mask)' could be
easier.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97977
[Bug 97977] Fortran deferred length strings incompatible with OMP

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-15  9:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 11:28 [Bug fortran/108693] New: Update shared character array inside OpenMP critical section causes internal compiler error hamchugh at amd dot com
2023-02-07 20:32 ` [Bug fortran/108693] " anlauf at gcc dot gnu.org
2023-02-15  9:33 ` burnus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).