Bug 85956 - [8 Regression] ICE in wide_int_to_tree_1, at tree.c:1549
Summary: [8 Regression] ICE in wide_int_to_tree_1, at tree.c:1549
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 9.0
: P2 normal
Target Milestone: 8.3
Assignee: Jakub Jelinek
URL:
Keywords: openmp, patch
Depends on:
Blocks:
 
Reported: 2018-05-28 18:53 UTC by G. Steinmetz
Modified: 2019-01-11 21:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 9.0
Known to fail: 8.1.0
Last reconfirmed: 2018-05-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2018-05-28 18:53:47 UTC
Changed between 20180506 and 20180513, ICE at -O[s23].
Derived from gomp/pr85696.c :


$ cat z1.c
void
foo (int n, void *p)
{
  int (*a)[n] = (int (*)[n]) p;
  #pragma omp parallel shared(a) default(none)
  #pragma omp master
    a[-1][-1] = 42;
}


$ gcc-9-20180527 -c z1.c -Wall -fopenmp -O1
$
$ gcc-9-20180527 -c z1.c -Wall -fopenmp -O2
'int[
during GIMPLE pass: vrp
In function 'foo._omp_fn.0':
in wide_int_to_tree_1, at tree.c:1549
   #pragma omp parallel shared(a) default(none)
           ^~~
0xd38643 wide_int_to_tree_1
        ../../gcc/tree.c:1549
0xd38bbb wide_int_to_tree(tree_node*, poly_int<1u, generic_wide_int<wide_int_ref_storage<false, true> > > const&)
        ../../gcc/tree.c:1674
0xd38bbb build_int_cst(tree_node*, poly_int<1u, long>)
        ../../gcc/tree.c:1342
0x701f60 c_pretty_printer::direct_abstract_declarator(tree_node*)
        ../../gcc/c-family/c-pretty-print.c:582
0x693ef3 c_tree_printer
        ../../gcc/c/c-objc-common.c:147
0x1257043 pp_format(pretty_printer*, text_info*)
        ../../gcc/pretty-print.c:1375
0x125004b diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        ../../gcc/diagnostic.c:984
0x12504c3 diagnostic_impl
        ../../gcc/diagnostic.c:1108
0x12508e0 warning_at(unsigned int, int, char const*, ...)
        ../../gcc/diagnostic.c:1223
0xd18056 vrp_prop::check_array_ref(unsigned int, tree_node*, bool)
        ../../gcc/tree-vrp.c:4990
0xd247bf vrp_prop::check_array_ref(unsigned int, tree_node*, bool)
        ../../gcc/tree-vrp.c:4876
0xd247bf check_array_bounds
        ../../gcc/tree-vrp.c:5090
0xd3e483 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc/tree.c:11400
0x8c26e3 walk_gimple_op(gimple*, tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*)
        ../../gcc/gimple-walk.c:221
0xd11cfc check_array_bounds_dom_walker::before_dom_children(basic_block_def*)
        ../../gcc/tree-vrp.c:5144
0x1145c9f dom_walker::walk(basic_block_def*)
        ../../gcc/domwalk.c:353
0xd14e1c vrp_prop::check_all_array_refs()
        ../../gcc/tree-vrp.c:5161
0xd15d8d vrp_prop::vrp_finalize(bool)
        ../../gcc/tree-vrp.c:6937
0xd250d3 execute_vrp
        ../../gcc/tree-vrp.c:7010
Comment 1 Martin Liška 2018-05-29 10:13:36 UTC
Confirmed, started with r260156.
Comment 2 Jakub Jelinek 2018-05-29 10:32:44 UTC
It actually started with r254830 if you drop the default(none) so that you don't hit the bug r260156 was fixing.
Not really sure if it is desirable to slow down code at runtime for warnings though, by forcing passing around array lengths for the cases of pointers to VLA, even when nothing in the code refers to those temporaries.

The problem is in:
      warning_at (location, OPT_Warray_bounds,
                  "array subscript %E is below array bounds of %qT",
                  low_sub, artype);
where we've checked that low_bound is INTEGER_CST, but up_bound is error_mark_node (what the temporary VAR_DECL that doesn't get passed to the parallel region is replaced with).

So, either we shouldn't try to print %qT in this case, at least when up_bound is error_mark_node, or the type printing should handle the case of error_mark_node bounds gracefully (say print it as [] rather than crash), or perhaps omp expansion could just try to replace these error_mark_node array bounds with NULLs somewhere (no idea if that is actually possible though).
Comment 3 Jakub Jelinek 2018-05-30 16:29:21 UTC
Note even without -fopenmp this prints:
pr85956.c:7:10: warning: array subscript -1 is below array bounds of ‘int[<Ucf30> + 1]’ [-Warray-bounds]
     a[-1][-1] = 42;
     ~~~~~^~~~
which is not what we want - the <Ucf30> in there at least...
Comment 4 Martin Sebor 2018-05-30 20:40:04 UTC
Patch: https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01763.html
Comment 5 Jakub Jelinek 2018-07-26 11:01:26 UTC
GCC 8.2 has been released.
Comment 6 Jakub Jelinek 2019-01-11 21:04:24 UTC
Author: jakub
Date: Fri Jan 11 21:03:53 2019
New Revision: 267858

URL: https://gcc.gnu.org/viewcvs?rev=267858&root=gcc&view=rev
Log:
	PR middle-end/85956
	PR lto/88733
	* tree-inline.h (struct copy_body_data): Add adjust_array_error_bounds
	field.
	* tree-inline.c (remap_type_1): Formatting fix.  If TYPE_MAX_VALUE of
	ARRAY_TYPE's TYPE_DOMAIN is newly error_mark_node, replace it with
	a dummy "omp dummy var" variable if id->adjust_array_error_bounds.
	* omp-low.c (new_omp_context): Set cb.adjust_array_error_bounds.
fortran/
	* trans-openmp.c: Include attribs.h.
	(gfc_walk_alloc_comps, gfc_omp_clause_linear_ctor): Handle
	VAR_DECL max bound with "omp dummy var" attribute like NULL or
	error_mark_node - recompute number of elts independently.
testsuite/
	* c-c++-common/gomp/pr85956.c: New test.
	* g++.dg/gomp/pr88733.C: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/gomp/pr85956.c
    trunk/gcc/testsuite/g++.dg/gomp/pr88733.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-openmp.c
    trunk/gcc/omp-low.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-inline.c
    trunk/gcc/tree-inline.h
Comment 7 Jakub Jelinek 2019-01-11 21:05:36 UTC
Fixed on the trunk only so far.