Bug 85422 - [openacc] ICE at cfgloop.c:468: segfault in flow_loops_find
Summary: [openacc] ICE at cfgloop.c:468: segfault in flow_loops_find
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, openacc, patch
Depends on:
Blocks:
 
Reported: 2018-04-16 15:45 UTC by Tom de Vries
Modified: 2018-04-26 13:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 6.4.0, 7.3.0
Last reconfirmed: 2018-04-18 00:00:00


Attachments
libgomp.log (2.16 KB, text/plain)
2018-04-18 10:29 UTC, Tom de Vries
Details
compile.log (2.42 KB, text/plain)
2018-04-18 10:31 UTC, Tom de Vries
Details
configure lines (516 bytes, text/plain)
2018-04-18 10:36 UTC, Tom de Vries
Details
Adjusted patch with testcase (588 bytes, patch)
2018-04-23 10:49 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2018-04-16 15:45:08 UTC
When compiling this program:
...
int
main (void)
{
#pragma acc parallel
#pragma acc loop
  for (int i = 1; i < 10; i++)
      for (;;)
        ;

  return 0;
}
...

we run into this ICE:
...
to1: internal compiler error: Segmentation fault
0xac51ff crash_signal
        gcc/toplev.c:325
0x62cc08 flow_loops_find(loops*)
        gcc/cfgloop.c:468
0x961b3b input_cfg
        gcc/lto-streamer-in.c:841
0x961b3b input_function
        gcc/lto-streamer-in.c:1069
0x961b3b lto_read_body_or_constructor
        gcc/lto-streamer-in.c:1287
0x961b3b lto_input_variable_constructor(lto_file_decl_data*, varpool_node*, char const*)
        gcc/lto-streamer-in.c:1345
0x651d4e cgraph_node::get_untransformed_body()
        gcc/cgraph.c:3667
0x6604d2 cgraph_node::expand()
        gcc/cgraphunit.c:2109
0x661df2 output_in_order
        gcc/cgraphunit.c:2381
0x661df2 symbol_table::compile()
        gcc/cgraphunit.c:2623
0x5adccc lto_main()
        gcc/lto/lto.c:3382
...
Comment 1 Tom de Vries 2018-04-16 15:49:12 UTC
Tentative patch was submitted here ( https://gcc.gnu.org/ml/gcc-patches/2018-04/msg00316.html ) and committed, but reverted again.
Comment 2 Tom de Vries 2018-04-17 17:23:55 UTC
Reproduces with gcc-6-branch and gcc-7-branch.
Comment 3 Richard Biener 2018-04-18 10:19:04 UTC
flags?  A simple ./xgcc -fopenacc doesn't reproduce it.  With my GCC 7 install I see

lto-wrapper: fatal error: problem with building target image for nvptx-none

but no way to see the lto1 invocations :/ (tried -Wl,-debug -Wl,-v already)
Comment 4 Tom de Vries 2018-04-18 10:29:20 UTC
Created attachment 43975 [details]
libgomp.log
Comment 5 Tom de Vries 2018-04-18 10:31:49 UTC
Created attachment 43976 [details]
compile.log

-save-temps -v output. Contains lto1 invocation.
Comment 6 Tom de Vries 2018-04-18 10:36:04 UTC
Created attachment 43978 [details]
configure lines
Comment 7 Tom de Vries 2018-04-18 11:18:13 UTC
(In reply to Richard Biener from comment #3)
> flags?  A simple ./xgcc -fopenacc doesn't reproduce it.  With my GCC 7
> install I see
> 
> lto-wrapper: fatal error: problem with building target image for nvptx-none
> 
> but no way to see the lto1 invocations :/ (tried -Wl,-debug -Wl,-v already)

I ran into the same problem when trying to use an installed compiler. Fixed by adding -B options for:
- the dir containing accel/nvptx-none/mkoffload
- the dir containing the offload gcc (in my case,
  x86_64-pc-linux-gnu-accel-nvptx-none-gcc)

So:
...
$ ./install/bin/x86_64-pc-linux-gnu-gcc \
  -fopenacc \
  src/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85422.c \
  -B $(pwd -P)/install/offload-nvptx-none/bin \
  -B $(pwd -P)/install/offload-nvptx-none/libexec/gcc/x86_64-pc-linux-gnu/8.0.1
...

The error message could certainly be be better.
Comment 8 Tom de Vries 2018-04-18 12:29:41 UTC
(In reply to Tom de Vries from comment #7)
> (In reply to Richard Biener from comment #3)
> > flags?  A simple ./xgcc -fopenacc doesn't reproduce it.  With my GCC 7
> > install I see
> > 
> > lto-wrapper: fatal error: problem with building target image for nvptx-none
> > 
> > but no way to see the lto1 invocations :/ (tried -Wl,-debug -Wl,-v already)
> 

> The error message could certainly be be better.

Filed as PR85451 - "[offloading] Improve lto-wrapper error message when not finding mkoffload"
Comment 9 Richard Biener 2018-04-18 12:56:14 UTC
Confirmed with GCC7.

> gcc-7 t.c -fopenacc
In function 'main._omp_fn.0':
lto1: internal compiler error: Segmentation fault
0x7b2d3f crash_signal
        ../../gcc/toplev.c:337
0x4a1056 flow_loops_find(loops*)
        ../../gcc/cfgloop.c:456
0x6cc63b input_cfg
        ../../gcc/lto-streamer-in.c:844
...

adjusted patch:

Index: gcc/lto-streamer-out.c
===================================================================
--- gcc/lto-streamer-out.c      (revision 259467)
+++ gcc/lto-streamer-out.c      (working copy)
@@ -2077,6 +2077,9 @@ output_function (struct cgraph_node *nod
      debug info.  */
   if (gimple_has_body_p (function))
     {
+      /* Fixup loops if required to match discovery done in the reader.  */
+      loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
+
       streamer_write_uhwi (ob, 1);
       output_struct_function_base (ob, fn);
 
@@ -2134,6 +2137,7 @@ output_function (struct cgraph_node *nod
 
       output_cfg (ob, fn);
 
+      loop_optimizer_finalize ();
       pop_cfun ();
    }
   else
Comment 10 Tom de Vries 2018-04-23 10:49:14 UTC
Created attachment 44006 [details]
Adjusted patch with testcase

(In reply to Richard Biener from comment #9)

> adjusted patch:

Added testcase.

Build x86_64 with nvptx accelerator on top of trunk r259523 and tested libgomp, no issues found.

Doing x86_64 bootstrap and reg-test now.
Comment 11 Tom de Vries 2018-04-23 12:07:56 UTC
patch submitted: https://gcc.gnu.org/ml/gcc-patches/2018-04/msg01041.html
Comment 12 Tom de Vries 2018-04-26 13:26:57 UTC
Author: vries
Date: Thu Apr 26 13:26:25 2018
New Revision: 259675

URL: https://gcc.gnu.org/viewcvs?rev=259675&root=gcc&view=rev
Log:
[lto] Fixup loops before lto write-out

2018-04-26  Richard Biener <rguenther@suse.de>
	    Tom de Vries  <tom@codesourcery.com>

	PR lto/85422
	* lto-streamer-out.c (output_function): Fixup loops if required to match
	discovery done in the reader.

	* testsuite/libgomp.oacc-c-c++-common/pr85422.c: New test.

Added:
    trunk/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85422.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lto-streamer-out.c
    trunk/libgomp/ChangeLog
Comment 13 Tom de Vries 2018-04-26 13:41:24 UTC
Patch with test-case committed, marking resolved-fixed.