public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
@ 2023-01-18 22:06 burnus at gcc dot gnu.org
  2023-01-19 10:39 ` [Bug middle-end/108459] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-01-18 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108459
           Summary: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in
                    expand_omp_for_init_counts
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code, openmp
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

The following innocent looking code gives an ICE. As probably visible from the
look of the code, it was found via Fortran code, related to patch work for
PR fortran/107424.

This affects all versions down to GCC 11, which is the first one to support
non-rectangular loop nests.


Compiling the C test below with '-fopenmp' gives:

during GIMPLE pass: ompexp
ff.c: In function ‘s1’:
ff.c:12:13: internal compiler error: Segmentation fault
   12 |     #pragma omp for collapse(2)
      |             ^~~
0xef701f crash_signal
        ../../repos/gcc-trunk-commit/gcc/toplev.cc:314
0x7f9f608ce51f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xbc5560 is_gimple_val(tree_node*)
        ../../repos/gcc-trunk-commit/gcc/gimple-expr.cc:837
0xc368f3 force_gimple_operand_1(tree_node*, gimple**, bool (*)(tree_node*),
tree_node*)
        ../../repos/gcc-trunk-commit/gcc/gimplify-me.cc:55
0xc36b0f force_gimple_operand_gsi_1(gimple_stmt_iterator*, tree_node*, bool
(*)(tree_node*), tree_node*, bool, gsi_iterator_update)
        ../../repos/gcc-trunk-commit/gcc/gimplify-me.cc:115
0xc36b0f force_gimple_operand_gsi(gimple_stmt_iterator*, tree_node*, bool,
tree_node*, bool, gsi_iterator_update)
        ../../repos/gcc-trunk-commit/gcc/gimplify-me.cc:141
0x1de8b5e expand_omp_for_init_counts
        ../../repos/gcc-trunk-commit/gcc/omp-expand.cc:2011



void s1 (int *a1, int *a2)
{
  int i;
  int j;

  {
    int D4266;
    int D4267;

    D4266 = -*a1;
    D4267 = *a2;
    #pragma omp for collapse(2)
    for (i = 1; i <= 16; i = i + 1)
      for (j = i * D4266 + D4267; j <= 16; j = j + 1)
        {
        }
  }
}

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
@ 2023-01-19 10:39 ` jakub at gcc dot gnu.org
  2023-01-19 11:03 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-19 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Slightly simplified:
void
foo (int x)
{
  #pragma omp for collapse(2)
  for (int i = 1; i <= 16; i++)
    for (int j = i * x; j <= 16; j++)
      ;
}

Started with my r11-2537-g29e0ad452cdf001bcc commit, will have a look.

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
  2023-01-19 10:39 ` [Bug middle-end/108459] " jakub at gcc dot gnu.org
@ 2023-01-19 11:03 ` jakub at gcc dot gnu.org
  2023-01-19 11:08 ` burnus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-19 11:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
--- gcc/omp-expand.cc.jj        2023-01-02 09:32:49.399894958 +0100
+++ gcc/omp-expand.cc   2023-01-19 12:01:05.103410564 +0100
@@ -2003,8 +2003,8 @@ expand_omp_for_init_counts (struct omp_f
            t = fold_build2 (MINUS_EXPR, itype, unshare_expr (fd->loops[i].m2),
                             unshare_expr (fd->loops[i].m1));
          else if (fd->loops[i].m1)
-           t = fold_unary (NEGATE_EXPR, itype,
-                           unshare_expr (fd->loops[i].m1));
+           t = fold_build1 (NEGATE_EXPR, itype,
+                            unshare_expr (fd->loops[i].m1));
          else
            t = unshare_expr (fd->loops[i].m2);
          tree m2minusm1
fixes this, just need to play with testcases.

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
  2023-01-19 10:39 ` [Bug middle-end/108459] " jakub at gcc dot gnu.org
  2023-01-19 11:03 ` jakub at gcc dot gnu.org
@ 2023-01-19 11:08 ` burnus at gcc dot gnu.org
  2023-01-19 11:17 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-01-19 11:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> --- gcc/omp-expand.cc.jj	2023-01-02 09:32:49.399894958 +0100
> +++ gcc/omp-expand.cc	2023-01-19 12:01:05.103410564 +0100
> -	    t = fold_unary (NEGATE_EXPR, itype,
> -			    unshare_expr (fd->loops[i].m1));
> +	    t = fold_build1 (NEGATE_EXPR, itype,
> +			     unshare_expr (fd->loops[i].m1));

Confirmed - fold_unary only hands constants, fold_build1 calls the same but if
it fails (i.e. "tem == NULL"), it calls then
  build1_loc (loc, code, type, op0 PASS_MEM_STAT);

Question: Is the following needed or not? I have not fully followed whether
"diff" and/or "ostep" could be a non-constant or not. At a glance, it looks as
if a variable could be possible.

--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -730,5 +730,4 @@ omp_extract_for_data (gomp_for *for_stmt, struct
omp_for_data *fd,
                    diff = fold_binary (TRUNC_DIV_EXPR, itype,
-                                       fold_unary (NEGATE_EXPR, itype, diff),
-                                       fold_unary (NEGATE_EXPR, itype,
-                                                   ostep));
+                                       build1 (NEGATE_EXPR, itype, diff),
+                                       build1 (NEGATE_EXPR, itype, ostep));
                  else

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-01-19 11:08 ` burnus at gcc dot gnu.org
@ 2023-01-19 11:17 ` jakub at gcc dot gnu.org
  2023-01-19 11:33 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-19 11:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think that ought to be fine.
There is
              if (single_nonrect == -1
                  || (loop->m1 && TREE_CODE (loop->m1) != INTEGER_CST)
                  || (loop->m2 && TREE_CODE (loop->m2) != INTEGER_CST)
                  || TREE_CODE (loop->n1) != INTEGER_CST
                  || TREE_CODE (loop->n2) != INTEGER_CST
                  || TREE_CODE (loop->step) != INTEGER_CST)
                {
                  count = NULL_TREE;
                  continue;
                }
some lines above that, after all, it is also using fold_binary rather than
fold_build2 etc.  All that code is there to compute the constant number of
iterations and other helper values for non-rectangular loops with all constant
expressions.

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-01-19 11:17 ` jakub at gcc dot gnu.org
@ 2023-01-19 11:33 ` jakub at gcc dot gnu.org
  2023-01-19 20:02 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-19 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2023-01-19
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 54305
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54305&action=edit
gcc13-pr108459.patch

Full untested patch.

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-01-19 11:33 ` jakub at gcc dot gnu.org
@ 2023-01-19 20:02 ` cvs-commit at gcc dot gnu.org
  2023-01-19 20:19 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-19 20:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:46644ec99cb355845b23bb1d02775c057ed8ee88

commit r13-5262-g46644ec99cb355845b23bb1d02775c057ed8ee88
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jan 19 21:00:08 2023 +0100

    openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

    expand_omp_for_init_counts was using for the case where collapse(2)
    inner loop has init expression dependent on non-constant multiple of
    the outer iterator and the condition upper bound expression doesn't
    depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
    will just return NULL if it can't be folded, we need fold_build1
    instead.

    2023-01-19  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/108459
            * omp-expand.cc (expand_omp_for_init_counts): Use fold_build1
rather
            than fold_unary for NEGATE_EXPR.

            * testsuite/libgomp.c/pr108459.c: New test.

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-01-19 20:02 ` cvs-commit at gcc dot gnu.org
@ 2023-01-19 20:19 ` jakub at gcc dot gnu.org
  2023-02-10 17:45 ` cvs-commit at gcc dot gnu.org
  2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-19 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk, will backport later.

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-01-19 20:19 ` jakub at gcc dot gnu.org
@ 2023-02-10 17:45 ` cvs-commit at gcc dot gnu.org
  2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-10 17:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:629907bff87e238d45afe609716880e8acf9e541

commit r12-9141-g629907bff87e238d45afe609716880e8acf9e541
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jan 19 21:00:08 2023 +0100

    openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

    expand_omp_for_init_counts was using for the case where collapse(2)
    inner loop has init expression dependent on non-constant multiple of
    the outer iterator and the condition upper bound expression doesn't
    depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
    will just return NULL if it can't be folded, we need fold_build1
    instead.

    2023-01-19  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/108459
            * omp-expand.cc (expand_omp_for_init_counts): Use fold_build1
rather
            than fold_unary for NEGATE_EXPR.

            * testsuite/libgomp.c/pr108459.c: New test.

    (cherry picked from commit 46644ec99cb355845b23bb1d02775c057ed8ee88)

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

* [Bug middle-end/108459] [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts
  2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-02-10 17:45 ` cvs-commit at gcc dot gnu.org
@ 2023-05-02 20:13 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-02 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:23d16b36eb41366841af052c35f335f35ee203cc

commit r11-10699-g23d16b36eb41366841af052c35f335f35ee203cc
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Jan 19 21:00:08 2023 +0100

    openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

    expand_omp_for_init_counts was using for the case where collapse(2)
    inner loop has init expression dependent on non-constant multiple of
    the outer iterator and the condition upper bound expression doesn't
    depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
    will just return NULL if it can't be folded, we need fold_build1
    instead.

    2023-01-19  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/108459
            * omp-expand.c (expand_omp_for_init_counts): Use fold_build1 rather
            than fold_unary for NEGATE_EXPR.

            * testsuite/libgomp.c/pr108459.c: New test.

    (cherry picked from commit 46644ec99cb355845b23bb1d02775c057ed8ee88)

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

end of thread, other threads:[~2023-05-02 20:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18 22:06 [Bug middle-end/108459] New: [OpenMP] ICE during GIMPLE pass: ompexp (segfault) in expand_omp_for_init_counts burnus at gcc dot gnu.org
2023-01-19 10:39 ` [Bug middle-end/108459] " jakub at gcc dot gnu.org
2023-01-19 11:03 ` jakub at gcc dot gnu.org
2023-01-19 11:08 ` burnus at gcc dot gnu.org
2023-01-19 11:17 ` jakub at gcc dot gnu.org
2023-01-19 11:33 ` jakub at gcc dot gnu.org
2023-01-19 20:02 ` cvs-commit at gcc dot gnu.org
2023-01-19 20:19 ` jakub at gcc dot gnu.org
2023-02-10 17:45 ` cvs-commit at gcc dot gnu.org
2023-05-02 20:13 ` cvs-commit 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).