From 5b23b0c44692cc5e4d5e726f96497bff73094e7b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 17 Apr 2020 09:07:49 +0200 Subject: [PATCH] inliner: Don't ICE on NULL TYPE_DOMAIN [PR94621] When I've added the VLA tweak for OpenMP to avoid error_mark_nodes in the IL in type, I forgot that TYPE_DOMAIN could be NULL. Furthermore, as an optimization, this patch checks the hopefully cheapest condition that is very likely false most of the time (enabled only during OpenMP handling) first. 2020-04-17 Jakub Jelinek PR tree-optimization/94621 * tree-inline.c (remap_type_1): Don't dereference NULL TYPE_DOMAIN. Move id->adjust_array_error_bounds check first in the condition. * gcc.c-torture/compile/pr94621.c: New test. (cherry picked from commit c58cb6ac6891886b7aa01c440ac71a5e7cbcba97) --- gcc/testsuite/gcc.c-torture/compile/pr94621.c | 16 ++++++++++++++++ gcc/tree-inline.c | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr94621.c diff --git a/gcc/testsuite/gcc.c-torture/compile/pr94621.c b/gcc/testsuite/gcc.c-torture/compile/pr94621.c new file mode 100644 index 000000000000..0d98dfd53a5b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr94621.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/94621 */ + +struct S { int c, e[]; }; + +static inline int +foo (struct S *m, int r, int c) +{ + int (*a)[][m->c] = (int (*)[][m->c])&m->e; + return (*a)[r][c]; +} + +void +bar (struct S *a) +{ + foo (a, 0, 0); +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 7a41f64bcc34..878f1631a179 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -543,8 +543,9 @@ remap_type_1 (tree type, copy_body_data *id) /* For array bounds where we have decided not to copy over the bounds variable which isn't used in OpenMP/OpenACC region, change them to an uninitialized VAR_DECL temporary. */ - if (TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node - && id->adjust_array_error_bounds + if (id->adjust_array_error_bounds + && TYPE_DOMAIN (new_tree) + && TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node) { tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree))); -- 2.47.2