diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index c99336cb19d..de0e8fb0314 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -170,6 +170,7 @@ tree gfor_fndecl_co_min; tree gfor_fndecl_co_reduce; tree gfor_fndecl_co_sum; tree gfor_fndecl_caf_is_present; +tree gfor_fndecl_caf_random_init; /* Math functions. Many other math functions are handled in @@ -234,7 +235,6 @@ tree gfor_fndecl_zgemm; /* RANDOM_INIT function. */ tree gfor_fndecl_random_init; /* libgfortran, 1 image only. */ -tree gfor_fndecl_caf_random_init; /* OpenCoarray call. */ tree gfor_fndecl_cas_random_init; /* Shared memory coarray. */ static void @@ -3517,23 +3517,17 @@ gfc_build_intrinsic_function_decls (void) void_type_node, 3, gfc_logical4_type_node, gfc_logical4_type_node, gfc_int4_type_node); + // gfor_fndecl_caf_rand_init is defined in the lib-coarray section below. + /* FIXME: This is a temporary workaround until someone that uses coarray Fortran and random_init() can implement the OpenCoarray and/or the shared memory routines. Both require communication between images, so these routines cannot live in libgfortran. */ #if 1 - gfor_fndecl_caf_random_init = gfc_build_library_function_decl ( - get_identifier (PREFIX("random_init_foobar")), - void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); - gfor_fndecl_cas_random_init = gfc_build_library_function_decl ( get_identifier (PREFIX("random_init_foobar")), void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); #else - gfor_fndecl_caf_random_init = gfc_build_library_function_decl ( - get_identifier (PREFIX("caf_random_init")), - void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); - gfor_fndecl_cas_random_init = gfc_build_library_function_decl ( get_identifier (PREFIX("cas_random_init")), void_type_node, 2, gfc_logical4_type_node, gfc_logical4_type_node); @@ -4104,6 +4098,10 @@ gfc_build_builtin_function_decls (void) get_identifier (PREFIX("caf_is_present")), ". r . r ", integer_type_node, 3, pvoid_type_node, integer_type_node, pvoid_type_node); + + gfor_fndecl_caf_random_init = gfc_build_library_function_decl ( + get_identifier (PREFIX("caf_random_init")), + void_type_node, 2, logical_type_node, logical_type_node); } gfc_build_intrinsic_function_decls (); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 900c6198d9e..8319e94b893 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -3828,27 +3828,27 @@ conv_intrinsic_random_init (gfc_code *code) stmtblock_t block; gfc_se se; tree arg1, arg2, tmp; - tree logical4_type_node = gfc_get_logical_type (4); + /* On none coarray == lib compiles use LOGICAL(4) else regular LOGICAL. */ + tree used_bool_type_node = flag_coarray == GFC_FCOARRAY_LIB + ? logical_type_node + : gfc_get_logical_type (4); /* Make the function call. */ gfc_init_block (&block); gfc_init_se (&se, NULL); - /* Convert REPEATABLE to a LOGICAL(4) entity. */ + /* Convert REPEATABLE to the desired LOGICAL entity. */ gfc_conv_expr (&se, code->ext.actual->expr); gfc_add_block_to_block (&block, &se.pre); - arg1 = fold_convert (logical4_type_node, gfc_evaluate_now (se.expr, &block)); + arg1 = fold_convert (used_bool_type_node, gfc_evaluate_now (se.expr, &block)); gfc_add_block_to_block (&block, &se.post); - /* Convert IMAGE_DISTINCT to a LOGICAL(4) entity. */ + /* Convert IMAGE_DISTINCT to the desired LOGICAL entity. */ gfc_conv_expr (&se, code->ext.actual->next->expr); gfc_add_block_to_block (&block, &se.pre); - arg2 = fold_convert (logical4_type_node, gfc_evaluate_now (se.expr, &block)); + arg2 = fold_convert (used_bool_type_node, gfc_evaluate_now (se.expr, &block)); gfc_add_block_to_block (&block, &se.post); - /* Create the hidden argument. For non-coarray codes and -fcoarray=single, - simply set this to 0. For -fcoarray=lib, generate a call to - THIS_IMAGE() without arguments. */ if (flag_coarray == GFC_FCOARRAY_LIB) { tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_random_init, diff --git a/libgfortran/caf/libcaf.h b/libgfortran/caf/libcaf.h index 5abb753f6fd..c66d0379042 100644 --- a/libgfortran/caf/libcaf.h +++ b/libgfortran/caf/libcaf.h @@ -261,4 +261,6 @@ void _gfortran_caf_stopped_images (gfc_descriptor_t *, int _gfortran_caf_is_present (caf_token_t, int, caf_reference_t *); +void _gfortran_caf_random_init (bool, bool); + #endif /* LIBCAF_H */ diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c index a291c4452c9..fc8e3b3b94a 100644 --- a/libgfortran/caf/single.c +++ b/libgfortran/caf/single.c @@ -3135,3 +3135,13 @@ _gfortran_caf_is_present (caf_token_t token, } return memptr != NULL; } + +/* Reference the libraries implementation. */ +extern void _gfortran_random_init (int32_t, int32_t, int32_t); + +void _gfortran_caf_random_init (bool repeatable, bool image_distinct) +{ + /* In a single image implementation always forward to the gfortran + routine. */ + _gfortran_random_init (repeatable, image_distinct, 1); +} diff --git a/libgfortran/gfortran.map b/libgfortran/gfortran.map index b594b59849a..626804c37dd 100644 --- a/libgfortran/gfortran.map +++ b/libgfortran/gfortran.map @@ -1634,3 +1634,8 @@ GFORTRAN_11 { global: _gfortran_random_init_foobar; } GFORTRAN_10.2; + +GFORTRAN_12 { + global: + _gfortran_caf_random_init; +} GFORTRAN_11; diff --git a/libgfortran/intrinsics/random_init.f90 b/libgfortran/intrinsics/random_init.f90 index bbb45937087..233a1ca073a 100644 --- a/libgfortran/intrinsics/random_init.f90 +++ b/libgfortran/intrinsics/random_init.f90 @@ -100,7 +100,7 @@ impure subroutine _gfortran_random_init(repeatable, image_distinct, image_num) end subroutine _gfortran_random_init ! ! This is a temporary stub implementation until random_init is -! implemented for -fcoarray=shared and -fcoarray=lib. +! implemented for -fcoarray=shared. ! subroutine _gfortran_random_init_foobar(repeatable, image_distinct)