From 4c4be718fb65f9b8dd06d83c6fa3f697a5369d52 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 27 Jun 2019 11:41:34 +0200 Subject: [PATCH] Fix ICE when __builtin_calloc has no LHS (PR tree-optimization/91014). 2019-06-27 Martin Liska PR tree-optimization/91014 * tree-ssa-dse.c (initialize_ao_ref_for_dse): Bail out when LHS is NULL_TREE. 2019-06-27 Martin Liska PR tree-optimization/91014 * gcc.target/s390/pr91014.c: New test. From-SVN: r272738 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/s390/pr91014.c | 8 ++++++++ gcc/tree-ssa-dse.c | 5 +++-- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/s390/pr91014.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 16d26bd8db2..a1bd7985efa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-06-27 Martin Liska + + PR tree-optimization/91014 + * tree-ssa-dse.c (initialize_ao_ref_for_dse): Bail out + when LHS is NULL_TREE. + 2019-06-27 Martin Liska * symbol-summary.h (traverse): Pass diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f7b774af239..c48ceefebe4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-27 Martin Liska + + PR tree-optimization/91014 + * gcc.target/s390/pr91014.c: New test. + 2019-06-27 Richard Biener PR testsuite/91004 diff --git a/gcc/testsuite/gcc.target/s390/pr91014.c b/gcc/testsuite/gcc.target/s390/pr91014.c new file mode 100644 index 00000000000..eb37b333b5b --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/pr91014.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O" } */ +/* { dg-require-effective-target alloca } */ + +void foo(void) +{ + __builtin_calloc (1, 1); /* { dg-warning "ignoring return value of '__builtin_calloc' declared with attribute 'warn_unused_result'" } */ +} diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 1b1a9f34230..df05a55ce78 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -129,10 +129,11 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write) { tree nelem = gimple_call_arg (stmt, 0); tree selem = gimple_call_arg (stmt, 1); + tree lhs; if (TREE_CODE (nelem) == INTEGER_CST - && TREE_CODE (selem) == INTEGER_CST) + && TREE_CODE (selem) == INTEGER_CST + && (lhs = gimple_call_lhs (stmt)) != NULL_TREE) { - tree lhs = gimple_call_lhs (stmt); tree size = fold_build2 (MULT_EXPR, TREE_TYPE (nelem), nelem, selem); ao_ref_init_from_ptr_and_size (write, lhs, size); -- 2.30.2