re PR fortran/35719 (pointer to zero sized array not associated)
2008-05-11 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/35719 * trans.c (gfc_call_malloc): If size equals zero, allocate one byte; don't return a null pointer. 2008-05-11 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/35719 * gfortran.dg/associated_5.f90: New test. From-SVN: r135187
This commit is contained in:
parent
8ffb4ce0b0
commit
8f0aaee5db
@ -1,3 +1,9 @@
|
||||
2008-05-11 Thomas Koenig <tkoenig@gcc.gnu.org>
|
||||
|
||||
PR fortran/35719
|
||||
* trans.c (gfc_call_malloc): If size equals zero, allocate one
|
||||
byte; don't return a null pointer.
|
||||
|
||||
2008-05-10 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
|
||||
|
||||
PR fortran/36197
|
||||
|
@ -440,12 +440,12 @@ gfc_trans_runtime_check (tree cond, stmtblock_t * pblock, locus * where,
|
||||
|
||||
/* Call malloc to allocate size bytes of memory, with special conditions:
|
||||
+ if size < 0, generate a runtime error,
|
||||
+ if size == 0, return a NULL pointer,
|
||||
+ if size == 0, return a malloced area of size 1,
|
||||
+ if malloc returns NULL, issue a runtime error. */
|
||||
tree
|
||||
gfc_call_malloc (stmtblock_t * block, tree type, tree size)
|
||||
{
|
||||
tree tmp, msg, negative, zero, malloc_result, null_result, res;
|
||||
tree tmp, msg, negative, malloc_result, null_result, res;
|
||||
stmtblock_t block2;
|
||||
|
||||
size = gfc_evaluate_now (size, block);
|
||||
@ -468,6 +468,10 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree size)
|
||||
|
||||
/* Call malloc and check the result. */
|
||||
gfc_start_block (&block2);
|
||||
|
||||
size = fold_build2 (MAX_EXPR, size_type_node, size,
|
||||
build_int_cst (size_type_node, 1));
|
||||
|
||||
gfc_add_modify_expr (&block2, res,
|
||||
build_call_expr (built_in_decls[BUILT_IN_MALLOC], 1,
|
||||
size));
|
||||
@ -481,13 +485,7 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree size)
|
||||
gfc_add_expr_to_block (&block2, tmp);
|
||||
malloc_result = gfc_finish_block (&block2);
|
||||
|
||||
/* size == 0 */
|
||||
zero = fold_build2 (EQ_EXPR, boolean_type_node, size,
|
||||
build_int_cst (size_type_node, 0));
|
||||
tmp = fold_build2 (MODIFY_EXPR, pvoid_type_node, res,
|
||||
build_int_cst (pvoid_type_node, 0));
|
||||
tmp = fold_build3 (COND_EXPR, void_type_node, zero, tmp, malloc_result);
|
||||
gfc_add_expr_to_block (block, tmp);
|
||||
gfc_add_expr_to_block (block, malloc_result);
|
||||
|
||||
if (type != NULL)
|
||||
res = fold_convert (type, res);
|
||||
|
@ -1,3 +1,8 @@
|
||||
2008-05-11 Thomas Koenig <tkoenig@gcc.gnu.org>
|
||||
|
||||
PR fortran/35719
|
||||
* gfortran.dg/associated_5.f90: New test.
|
||||
|
||||
2008-05-11 Richard Sandiford <rdsandiford@googlemail.com>
|
||||
|
||||
* gcc.target/mips/scc-1.c: Require mips16_attribute, and add
|
||||
|
19
gcc/testsuite/gfortran.dg/associated_5.f90
Normal file
19
gcc/testsuite/gfortran.dg/associated_5.f90
Normal file
@ -0,0 +1,19 @@
|
||||
! { dg-do run }
|
||||
! PR 35719 - associated used to fail with zero-sized automatic arrays
|
||||
! Test case contributed by Dick Hendrickson
|
||||
|
||||
program try_mf1053
|
||||
|
||||
call mf1053 ( 1, 2, 3, 4)
|
||||
end
|
||||
|
||||
SUBROUTINE MF1053 (nf1, nf2, nf3, nf4)
|
||||
INTEGER, pointer :: ptr(:,:)
|
||||
INTEGER, target :: ILA1(NF2,NF4:NF3)
|
||||
|
||||
ptr => ILA1
|
||||
|
||||
if (ASSOCIATED (ptr, ILA1(NF1:NF2,NF4:NF3) ) ) call abort
|
||||
if ( .not. ASSOCIATED(ptr) ) call abort
|
||||
|
||||
END SUBROUTINE
|
Loading…
Reference in New Issue
Block a user