Bug 58809 - [4.7 Regression] ICE with complex variable in OpenMP reduction clause
Summary: [4.7 Regression] ICE with complex variable in OpenMP reduction clause
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.0
: P2 normal
Target Milestone: 4.7.4
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, openmp
Depends on:
Blocks:
 
Reported: 2013-10-19 22:31 UTC by Volker Reichelt
Modified: 2014-05-07 16:23 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.10.0, 4.2.0, 4.7.4, 4.8.3, 4.9.0
Known to fail: 4.3.0, 4.4.0, 4.5.0, 4.6.0, 4.7.0, 4.8.2
Last reconfirmed: 2013-10-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2013-10-19 22:31:05 UTC
The following valid code snippet (compiled with "-fopenmp -O") triggers an ICE since GCC 4.3.0:

======================================================
int i;
#pragma omp threadprivate (i)

void foo()
{
  _Complex int j;
#pragma omp parallel copyin (i) reduction (&&:j)
  ;
}
======================================================

bug.c: In function 'foo':
bug.c:7:9: internal compiler error: in build_int_cst_wide, at tree.c:1258
 #pragma omp parallel copyin (i) reduction (&&:j)
         ^
0xb6dcd3 build_int_cst_wide(tree_node*, unsigned long, long)
        ../../gcc/gcc/tree.c:1258
0xb6e010 double_int_to_tree(tree_node*, double_int)
        ../../gcc/gcc/tree.c:1112
0xb6e05a build_int_cst(tree_node*, long)
        ../../gcc/gcc/tree.c:1089
0x7804b3 make_range(tree_node*, int*, tree_node**, tree_node**, bool*)
        ../../gcc/gcc/fold-const.c:4231
0x785533 fold_range_test
        ../../gcc/gcc/fold-const.c:4987
0x785533 fold_truth_andor
        ../../gcc/gcc/fold-const.c:8629
0x74d86c fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
        ../../gcc/gcc/fold-const.c:12711
0x76a86a fold_build2_stat_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
        ../../gcc/gcc/fold-const.c:15051
0x8a2e7a lower_reduction_clauses
        ../../gcc/gcc/omp-low.c:3799
0x8a4fbe lower_omp_taskreg
        ../../gcc/gcc/omp-low.c:9383
0x89e0ab lower_omp_1
        ../../gcc/gcc/omp-low.c:9907
0x89e0ab lower_omp
        ../../gcc/gcc/omp-low.c:10029
0x89e82e lower_omp_1
        ../../gcc/gcc/omp-low.c:9899
0x89e82e lower_omp
        ../../gcc/gcc/omp-low.c:10029
0x89fe5c execute_lower_omp
        ../../gcc/gcc/omp-low.c:10064
0x89fe5c execute
        ../../gcc/gcc/omp-low.c:10103
Please submit a full bug report, [etc.]


A similar code snippet triggers an ICE in a different position on trunk:

======================================================
int i;
#pragma omp threadprivate (i)

void foo()
{
  _Complex int j;
#pragma omp parallel copyin (i) reduction (&:j)
  ;
}
======================================================

bug.c: In function 'foo._omp_fn.0':
bug.c:17:9: internal compiler error: in expand_expr_real_2, at expr.c:9119
 #pragma omp parallel copyin (i) reduction (&:j)
         ^
0x723807 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)
        ../../gcc/gcc/expr.c:9119
0x710127 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**)
        ../../gcc/gcc/expr.c:10487
0x710e86 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**)
        ../../gcc/gcc/expr.c:9296
0x71b5b8 store_expr(tree_node*, rtx_def*, int, bool)
        ../../gcc/gcc/expr.c:5208
0x71d663 expand_assignment(tree_node*, tree_node*, bool)
        ../../gcc/gcc/expr.c:4994
0x64667d expand_gimple_stmt_1
        ../../gcc/gcc/cfgexpand.c:2277
0x64667d expand_gimple_stmt
        ../../gcc/gcc/cfgexpand.c:2373
0x6480e3 expand_gimple_basic_block
        ../../gcc/gcc/cfgexpand.c:4212
0x649a2c gimple_expand_cfg
        ../../gcc/gcc/cfgexpand.c:4731
0x649a2c execute
        ../../gcc/gcc/cfgexpand.c:4945
Please submit a full bug report, [etc.]
Comment 1 Marek Polacek 2013-10-21 11:17:49 UTC
Confirmed, but no clue whether it is valid or not.
Comment 2 Marek Polacek 2013-10-21 12:41:07 UTC
Maybe fold_range_test should just return 0 when the type is not INTEGRAL_TYPE_P.  If that's the case, I can take this one.
Comment 3 Marek Polacek 2013-10-21 15:18:32 UTC
Patch posted for the first testcase: http://gcc.gnu.org/ml/gcc-patches/2013-10/msg01714.html
Comment 4 Marek Polacek 2013-10-21 18:40:36 UTC
Author: mpolacek
Date: Mon Oct 21 18:40:34 2013
New Revision: 203907

URL: http://gcc.gnu.org/viewcvs?rev=203907&root=gcc&view=rev
Log:
	PR middle-end/58809
	* fold-const.c (fold_range_test): Return 0 if the type is not
	an integral type.
testsuite/
	* gcc.dg/gomp/pr58809.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/gomp/pr58809.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Richard Biener 2013-11-05 15:04:42 UTC
Fixed on trunk sofar.
Comment 6 Volker Reichelt 2013-11-05 21:15:46 UTC
Only the first testcase was fixed on trunk.
The second one still crashes on trunk.
Comment 7 Tobias Burnus 2013-12-05 00:46:00 UTC
[second test case]
(In reply to Volker Reichelt from comment #0)
> A similar code snippet triggers an ICE in a different position on trunk:

Reduced example:

void foo()
{
  _Complex int j;
#pragma omp parallel reduction (&:j)
  ;
}


I wonder whether it is valid as the following is rejected with "error: invalid operands to binary & (have 'complex int' and 'complex int')":

_Complex int foo(_Complex int j)
{
  _Complex int k = -1;
  j &=  k;
}
Comment 8 Jakub Jelinek 2014-01-23 13:32:53 UTC
Author: jakub
Date: Thu Jan 23 13:32:19 2014
New Revision: 206962

URL: http://gcc.gnu.org/viewcvs?rev=206962&root=gcc&view=rev
Log:
	PR middle-end/58809
	* c-typeck.c (c_finish_omp_clause): Reject MIN_EXPR, MAX_EXPR,
	BIT_AND_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR on COMPLEX_TYPEs.

	* semantics.c (finish_omp_reduction_clause): Reject
	BIT_AND_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR on COMPLEX_TYPEs.

	* c-c++-common/gomp/pr58809.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/gomp/pr58809.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2014-01-23 13:34:08 UTC
Author: jakub
Date: Thu Jan 23 13:33:36 2014
New Revision: 206963

URL: http://gcc.gnu.org/viewcvs?rev=206963&root=gcc&view=rev
Log:
	PR middle-end/58809
	* c-typeck.c (c_finish_omp_clause): Reject MIN_EXPR, MAX_EXPR,
	BIT_AND_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR on COMPLEX_TYPEs.

	* semantics.c (finish_omp_clauses): Reject MIN_EXPR, MAX_EXPR,
	BIT_AND_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR on COMPLEX_TYPEs.

	* c-c++-common/gomp/pr58809.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/gomp/pr58809.c
Modified:
    branches/gcc-4_8-branch/gcc/c/ChangeLog
    branches/gcc-4_8-branch/gcc/c/c-typeck.c
    branches/gcc-4_8-branch/gcc/cp/ChangeLog
    branches/gcc-4_8-branch/gcc/cp/semantics.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Comment 10 Jakub Jelinek 2014-01-23 13:40:22 UTC
Fixed on the trunk and partly on the 4.8 branch.
Marek, could you backport your patch to 4.8?
Comment 11 Marek Polacek 2014-01-23 13:42:29 UTC
(In reply to Jakub Jelinek from comment #10)
> Marek, could you backport your patch to 4.8?

Will do.
Comment 12 Marek Polacek 2014-01-23 13:49:17 UTC
Author: mpolacek
Date: Thu Jan 23 13:48:46 2014
New Revision: 206964

URL: http://gcc.gnu.org/viewcvs?rev=206964&root=gcc&view=rev
Log:
	PR middle-end/58809
	* fold-const.c (fold_range_test): Return 0 if the type is not
	an integral type.
testsuite/
	* gcc.dg/gomp/pr58809.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/gomp/pr58809.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/fold-const.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Comment 13 Jakub Jelinek 2014-05-07 16:12:13 UTC
Author: jakub
Date: Wed May  7 16:11:42 2014
New Revision: 210180

URL: http://gcc.gnu.org/viewcvs?rev=210180&root=gcc&view=rev
Log:
	Backported from mainline
	2013-10-21  Marek Polacek  <polacek@redhat.com>

	PR middle-end/58809
	* fold-const.c (fold_range_test): Return 0 if the type is not
	an integral type.

	* gcc.dg/gomp/pr58809.c: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/gomp/pr58809.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/fold-const.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 14 Jakub Jelinek 2014-05-07 16:23:45 UTC
Fixed.