From 107a9bc92c74233db8e0045826d7276247c7edb2 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Mon, 14 Nov 2011 09:15:09 +0100 Subject: re PR fortran/51073 (_gfortran_caf_register incorrectly assumes malloc(0) returns non-NULL) 2011-11-14 Tobias Burnus PR fortran/51073 * trans-decl.c (generate_coarray_sym_init): Handle zero-sized * arrays. From-SVN: r181348 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/trans-decl.c | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index dca8398..01abd74 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2011-11-14 Tobias Burnus + + PR fortran/51073 + * trans-decl.c (generate_coarray_sym_init): Handle zero-sized arrays. + 2011-11-09 Tobias Burnus * symbol.c (clear_sym_mark, traverse_ns): Remove functions. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index b90b0ab..80e4f55 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -4234,12 +4234,16 @@ generate_coarray_sym_init (gfc_symbol *sym) size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (decl))); + /* Ensure that we do not have size=0 for zero-sized arrays. */ + size = fold_build2_loc (input_location, MAX_EXPR, size_type_node, + fold_convert (size_type_node, size), + build_int_cst (size_type_node, 1)); + if (GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl))) { tmp = GFC_TYPE_ARRAY_SIZE (TREE_TYPE (decl)); size = fold_build2_loc (input_location, MULT_EXPR, size_type_node, - fold_convert (size_type_node, tmp), - fold_convert (size_type_node, size)); + fold_convert (size_type_node, tmp), size); } gcc_assert (GFC_TYPE_ARRAY_CAF_TOKEN (TREE_TYPE (decl)) != NULL_TREE); -- cgit v1.1