This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/51073] _gfortran_caf_register incorrectly assumes malloc(0) returns non-NULL
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 10 Nov 2011 11:02:06 +0000
- Subject: [Bug fortran/51073] _gfortran_caf_register incorrectly assumes malloc(0) returns non-NULL
- Auto-submitted: auto-generated
- References: <bug-51073-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51073
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-10 11:02:06 UTC ---
Patch which makes sure that for static coarrays the minimal size is 1.
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -4234,6 +4238,11 @@ 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));