Hi! On Tue, 11 Feb 2014 13:43:46 +0100, I wrote: > Ping again for test case and rather trivial patch to cure a GCC trunk ICE > in the Cilk Plus structured block checker if both -fcilkplus and -fopenmp > are specified.
Jakub asked me to »please repost just the (hopefully small) trunk patch alone«, so here we go: Consider the following code: void baz() { bad1: #pragma omp parallel goto bad1; } Then, if both -fcilkplus and -fopenmp are specified, that will run into a SIGSEGV/ICE because of label_ctx == NULL in omp-low.c:diagnose_sb_0. The testcase is basically a concatenation of gcc.dg/cilk-plus/jump.c and gcc.dg/gomp/block-1.c -- should this be done differently/better? Fix potential ICE (null pointer dereference) in omp-low.c:diagnose_sb_0. gcc/ * omp-low.c (diagnose_sb_0): Make sure label_ctx is valid to dereference. gcc/testsuite/ * gcc.dg/cilk-plus/jump-openmp.c: New file. diff --git gcc/omp-low.c gcc/omp-low.c index e0f7d1d..91221c0 100644 --- gcc/omp-low.c +++ gcc/omp-low.c @@ -10865,7 +10865,8 @@ diagnose_sb_0 (gimple_stmt_iterator *gsi_p, if ((branch_ctx && gimple_code (branch_ctx) == GIMPLE_OMP_FOR && gimple_omp_for_kind (branch_ctx) == GF_OMP_FOR_KIND_CILKSIMD) - || (gimple_code (label_ctx) == GIMPLE_OMP_FOR + || (label_ctx + && gimple_code (label_ctx) == GIMPLE_OMP_FOR && gimple_omp_for_kind (label_ctx) == GF_OMP_FOR_KIND_CILKSIMD)) cilkplus_block = true; } diff --git gcc/testsuite/gcc.dg/cilk-plus/jump-openmp.c gcc/testsuite/gcc.dg/cilk-plus/jump-openmp.c new file mode 100644 index 0000000..95e6b2d --- /dev/null +++ gcc/testsuite/gcc.dg/cilk-plus/jump-openmp.c @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* { dg-options "-fcilkplus -fopenmp" } */ +/* { dg-require-effective-target fopenmp } */ + +int *a, *b, c; + +void foo() +{ +#pragma simd + for (int i=0; i < 1000; ++i) + { + a[i] = b[i]; + if (c == 5) + return; /* { dg-error "invalid branch to/from a Cilk Plus structured block" } */ + } +} + +void bar() +{ +#pragma simd + for (int i=0; i < 1000; ++i) + { + lab: + a[i] = b[i]; + } + if (c == 6) + goto lab; /* { dg-error "invalid entry to Cilk Plus structured block" } */ +} + +void baz() +{ + bad1: + #pragma omp parallel + goto bad1; /* { dg-error "invalid branch to/from an OpenMP structured block" } */ + + goto bad2; /* { dg-error "invalid entry to OpenMP structured block" } */ + #pragma omp parallel + { + bad2: ; + } + + #pragma omp parallel + { + int i; + goto ok1; + for (i = 0; i < 10; ++i) + { ok1: break; } + } +} Grüße, Thomas
pgpmmBQ4hAZPQ.pgp
Description: PGP signature