From 3f5fabc0eab4b2145d7f4fd7cf310b9b5bf022ed Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Thu, 22 Feb 2018 11:44:31 +0200 Subject: [PATCH] Character length cleanup for Coarray Fortran library Following the change to use size_t for Fortran character lengths (PR 78534), this patch modifies the Coarray ABI in a similar way. The single-image implementation that is included in libgfortran is updated, but this needs corresponding work in the OpenCoarray library as well for multi-image support. I also fixed the types for the STOP and ERROR STOP implementation in libgfortran, as the calling of them is somewhat intertwined with the calling of the corresponding CAF functions. I'll send the OpenCoarray changes as a separate pull request to the OpenCoarrays repository. Regtested on x86_64-pc-linux-gnu. gcc/fortran/ChangeLog: 2018-02-22 Janne Blomqvist * gfortran.texi: Update Coarray API description. * trans-decl.c (gfc_build_builtin_function_decls): Use size_t for character lengths, int for exit codes. (generate_coarray_sym_init): Use size_t for character length. * trans-intrinsic.c (conv_co_collective): Likewise. * trans-stmt.c (gfc_trans_lock_unlock): Likewise. (gfc_trans_event_post_wait): Likewise. (gfc_trans_sync): Likewise. (gfc_trans_stop): Use size_t for character lengths, int for exit codes. libgfortran/ChangeLog: 2018-02-22 Janne Blomqvist * libgfortran.h (stop_string): Use size_t for character length. * runtime/stop.c (stop_string): Likewise. (error_stop_string): Likewise. (stop_numeric): Use int for exit code. (error_stop_numeric): Likewise. * caf/libcaf.h: Remove stdint.h include. (_gfortran_caf_register): Use size_t for character length. (_gfortran_caf_deregister): Likewise. (_gfortran_caf_sync_all): Likewise. (_gfortran_caf_sync_memory): Likewise. (_gfortran_caf_sync_images): Likewise. (_gfortran_caf_stop_numeric): Use int for exit code. (_gfortran_caf_stop_str): Use size_t for character length. (_gfortran_caf_error_stop_str): Likewise. (_gfortran_caf_error_stop): Use int for exit code. (_gfortran_caf_co_broadcast): Use size_t for character length. (_gfortran_caf_co_sum): Likewise. (_gfortran_caf_co_min): Likewise. (_gfortran_caf_co_max): Likewise. (_gfortran_caf_co_reduce): Likewise. (_gfortran_caf_lock): Likewise. (_gfortran_caf_unlock): Likewise. (_gfortran_caf_event_post): Likewise. (_gfortran_caf_event_wait): Likewise. * caf/mpi.c (_gfortran_caf_register): Update implementation to match prototype. (_gfortran_caf_deregister): Likewise. (_gfortran_caf_sync_all): Likewise. (_gfortran_caf_sync_images): Likewise. (_gfortran_caf_error_stop_str): Likewise. (_gfortran_caf_error_stop): Likewise. * caf/single.c (caf_internal_error): Likewise. (_gfortran_caf_register): Likewise. (_gfortran_caf_deregister): Likewise. (_gfortran_caf_sync_all): Likewise. (_gfortran_caf_sync_memory): Likewise. (_gfortran_caf_sync_images): Likewise. (_gfortran_caf_stop_numeric): Likewise. (_gfortran_caf_stop_str): Likewise. (_gfortran_caf_error_stop_str): Likewise. (_gfortran_caf_error_stop): Likewise. (_gfortran_caf_co_broadcast): Likewise. (_gfortran_caf_co_sum): Likewise. (_gfortran_caf_co_min): Likewise. (_gfortran_caf_co_max): Likewise. (_gfortran_caf_co_reduce): Likewise. (_gfortran_caf_event_post): Likewise. (_gfortran_caf_event_wait): Likewise. (_gfortran_caf_lock): Likewise. (_gfortran_caf_unlock): Likewise. From-SVN: r257894 --- gcc/fortran/ChangeLog | 13 +++++++++ gcc/fortran/gfortran.texi | 32 ++++++++++---------- gcc/fortran/trans-decl.c | 46 ++++++++++++++--------------- gcc/fortran/trans-intrinsic.c | 4 +-- gcc/fortran/trans-stmt.c | 20 ++++++------- libgfortran/ChangeLog | 53 +++++++++++++++++++++++++++++++++ libgfortran/caf/libcaf.h | 37 ++++++++++++----------- libgfortran/caf/mpi.c | 28 +++++++++--------- libgfortran/caf/single.c | 55 ++++++++++++++++++----------------- libgfortran/libgfortran.h | 2 +- libgfortran/runtime/stop.c | 18 ++++++------ 11 files changed, 187 insertions(+), 121 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d6d66c5e3f3..49b2ce9aae0 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2018-02-22 Janne Blomqvist + + * gfortran.texi: Update Coarray API description. + * trans-decl.c (gfc_build_builtin_function_decls): Use size_t for + character lengths, int for exit codes. + (generate_coarray_sym_init): Use size_t for character length. + * trans-intrinsic.c (conv_co_collective): Likewise. + * trans-stmt.c (gfc_trans_lock_unlock): Likewise. + (gfc_trans_event_post_wait): Likewise. + (gfc_trans_sync): Likewise. + (gfc_trans_stop): Use size_t for character lengths, int for exit + codes. + 2018-02-20 Thomas Koenig PR fortran/48890 diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index db48a713661..6f894816c62 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -4458,7 +4458,7 @@ in the @var{DESC}'s data-ptr is registered or allocate when the data-ptr is @item @emph{Syntax}: @code{void caf_register (size_t size, caf_register_t type, caf_token_t *token, -gfc_descriptor_t *desc, int *stat, char *errmsg, int errmsg_len)} +gfc_descriptor_t *desc, int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -4510,7 +4510,7 @@ during a call to @code{_gfortran_caf_register}. @item @emph{Syntax}: @code{void caf_deregister (caf_token_t *token, caf_deregister_t type, -int *stat, char *errmsg, int errmsg_len)} +int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -4949,7 +4949,7 @@ which has already been locked by the same image is an error. @item @emph{Syntax}: @code{void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index, -int *aquired_lock, int *stat, char *errmsg, int errmsg_len)} +int *aquired_lock, int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -4984,7 +4984,7 @@ which is unlocked or has been locked by a different image is an error. @item @emph{Syntax}: @code{void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index, -int *stat, char *errmsg, int errmsg_len)} +int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5016,7 +5016,7 @@ Increment the event count of the specified event variable. @item @emph{Syntax}: @code{void _gfortran_caf_event_post (caf_token_t token, size_t index, -int image_index, int *stat, char *errmsg, int errmsg_len)} +int image_index, int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5053,7 +5053,7 @@ amount and return. @item @emph{Syntax}: @code{void _gfortran_caf_event_wait (caf_token_t token, size_t index, -int until_count, int *stat, char *errmsg, int errmsg_len)} +int until_count, int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5131,7 +5131,7 @@ current team. Additionally, it ensures that all pending data transfers of previous segment have completed. @item @emph{Syntax}: -@code{void _gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len)} +@code{void _gfortran_caf_sync_all (int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5159,7 +5159,7 @@ transfers of previous segments have completed. @item @emph{Syntax}: @code{void _gfortran_caf_sync_images (int count, int images[], int *stat, -char *errmsg, int errmsg_len)} +char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5187,7 +5187,7 @@ Acts as optimization barrier between different segments. It also ensures that all pending memory operations of this image have been completed. @item @emph{Syntax}: -@code{void _gfortran_caf_sync_memory (int *stat, char *errmsg, int errmsg_len)} +@code{void _gfortran_caf_sync_memory (int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5214,7 +5214,7 @@ function should terminate the program with the specified exit code. @item @emph{Syntax}: -@code{void _gfortran_caf_error_stop (int32_t error)} +@code{void _gfortran_caf_error_stop (int error)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5234,7 +5234,7 @@ Invoked for an @code{ERROR STOP} statement which has a string as argument. The function should terminate the program with a nonzero-exit code. @item @emph{Syntax}: -@code{void _gfortran_caf_error_stop (const char *string, int32_t len)} +@code{void _gfortran_caf_error_stop (const char *string, size_t len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5412,7 +5412,7 @@ be called collectively. @item @emph{Syntax}: @code{void _gfortran_caf_co_broadcast (gfc_descriptor_t *a, -int source_image, int *stat, char *errmsg, int errmsg_len)} +int source_image, int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5443,7 +5443,7 @@ strings. @item @emph{Syntax}: @code{void _gfortran_caf_co_max (gfc_descriptor_t *a, int result_image, -int *stat, char *errmsg, int a_len, int errmsg_len)} +int *stat, char *errmsg, int a_len, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5480,7 +5480,7 @@ strings. @item @emph{Syntax}: @code{void _gfortran_caf_co_min (gfc_descriptor_t *a, int result_image, -int *stat, char *errmsg, int a_len, int errmsg_len)} +int *stat, char *errmsg, int a_len, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5516,7 +5516,7 @@ specified image. This function operates on numeric values only. @item @emph{Syntax}: @code{void _gfortran_caf_co_sum (gfc_descriptor_t *a, int result_image, -int *stat, char *errmsg, int errmsg_len)} +int *stat, char *errmsg, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 @@ -5561,7 +5561,7 @@ string lengths shall be specified as hidden arguments; @item @emph{Syntax}: @code{void _gfortran_caf_co_reduce (gfc_descriptor_t *a, void * (*opr) (void *, void *), int opr_flags, int result_image, -int *stat, char *errmsg, int a_len, int errmsg_len)} +int *stat, char *errmsg, int a_len, size_t errmsg_len)} @item @emph{Arguments}: @multitable @columnfractions .15 .70 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index a50c50da206..63336b31772 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -3503,25 +3503,25 @@ gfc_build_builtin_function_decls (void) gfor_fndecl_stop_numeric = gfc_build_library_function_decl ( get_identifier (PREFIX("stop_numeric")), - void_type_node, 1, gfc_int4_type_node); + void_type_node, 1, integer_type_node); /* STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_stop_numeric) = 1; gfor_fndecl_stop_string = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("stop_string")), ".R.", - void_type_node, 2, pchar_type_node, gfc_int4_type_node); + void_type_node, 2, pchar_type_node, size_type_node); /* STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_stop_string) = 1; gfor_fndecl_error_stop_numeric = gfc_build_library_function_decl ( get_identifier (PREFIX("error_stop_numeric")), - void_type_node, 1, gfc_int4_type_node); + void_type_node, 1, integer_type_node); /* ERROR STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_error_stop_numeric) = 1; gfor_fndecl_error_stop_string = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("error_stop_string")), ".R.", - void_type_node, 2, pchar_type_node, gfc_int4_type_node); + void_type_node, 2, pchar_type_node, size_type_node); /* ERROR STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_error_stop_string) = 1; @@ -3636,12 +3636,12 @@ gfc_build_builtin_function_decls (void) gfor_fndecl_caf_register = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_register")), "RRWWWWR", void_type_node, 7, size_type_node, integer_type_node, ppvoid_type_node, pvoid_type_node, - pint_type, pchar_type_node, integer_type_node); + pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_deregister = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_deregister")), "WRWWR", void_type_node, 5, ppvoid_type_node, integer_type_node, pint_type, pchar_type_node, - integer_type_node); + size_type_node); gfor_fndecl_caf_get = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_get")), ".R.RRWRRRW", void_type_node, 10, @@ -3685,38 +3685,38 @@ gfc_build_builtin_function_decls (void) gfor_fndecl_caf_sync_all = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_sync_all")), ".WW", void_type_node, - 3, pint_type, pchar_type_node, integer_type_node); + 3, pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_sync_memory = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_sync_memory")), ".WW", void_type_node, - 3, pint_type, pchar_type_node, integer_type_node); + 3, pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_sync_images = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_sync_images")), ".RRWW", void_type_node, 5, integer_type_node, pint_type, pint_type, - pchar_type_node, integer_type_node); + pchar_type_node, size_type_node); gfor_fndecl_caf_error_stop = gfc_build_library_function_decl ( get_identifier (PREFIX("caf_error_stop")), - void_type_node, 1, gfc_int4_type_node); + void_type_node, 1, integer_type_node); /* CAF's ERROR STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_caf_error_stop) = 1; gfor_fndecl_caf_error_stop_str = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_error_stop_str")), ".R.", - void_type_node, 2, pchar_type_node, gfc_int4_type_node); + void_type_node, 2, pchar_type_node, size_type_node); /* CAF's ERROR STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_caf_error_stop_str) = 1; gfor_fndecl_caf_stop_numeric = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_stop_numeric")), ".R.", - void_type_node, 1, gfc_int4_type_node); + void_type_node, 1, integer_type_node); /* CAF's STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_caf_stop_numeric) = 1; gfor_fndecl_caf_stop_str = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_stop_str")), ".R.", - void_type_node, 2, pchar_type_node, gfc_int4_type_node); + void_type_node, 2, pchar_type_node, size_type_node); /* CAF's STOP doesn't return. */ TREE_THIS_VOLATILE (gfor_fndecl_caf_stop_str) = 1; @@ -3745,22 +3745,22 @@ gfc_build_builtin_function_decls (void) gfor_fndecl_caf_lock = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_lock")), "R..WWW", void_type_node, 7, pvoid_type_node, size_type_node, integer_type_node, - pint_type, pint_type, pchar_type_node, integer_type_node); + pint_type, pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_unlock = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_unlock")), "R..WW", void_type_node, 6, pvoid_type_node, size_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node); + pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_event_post = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_event_post")), "R..WW", void_type_node, 6, pvoid_type_node, size_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node); + pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_event_wait = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_event_wait")), "R..WW", void_type_node, 6, pvoid_type_node, size_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node); + pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_event_query = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_event_query")), "R..WW", @@ -3824,17 +3824,17 @@ gfc_build_builtin_function_decls (void) gfor_fndecl_co_broadcast = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_co_broadcast")), "W.WW", void_type_node, 5, pvoid_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node); + pint_type, pchar_type_node, size_type_node); gfor_fndecl_co_max = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_co_max")), "W.WW", void_type_node, 6, pvoid_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node, integer_type_node); + pint_type, pchar_type_node, integer_type_node, size_type_node); gfor_fndecl_co_min = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_co_min")), "W.WW", void_type_node, 6, pvoid_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node, integer_type_node); + pint_type, pchar_type_node, integer_type_node, size_type_node); gfor_fndecl_co_reduce = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_co_reduce")), "W.R.WW", @@ -3842,12 +3842,12 @@ gfc_build_builtin_function_decls (void) build_pointer_type (build_varargs_function_type_list (void_type_node, NULL_TREE)), integer_type_node, integer_type_node, pint_type, pchar_type_node, - integer_type_node, integer_type_node); + integer_type_node, size_type_node); gfor_fndecl_co_sum = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_co_sum")), "W.WW", void_type_node, 5, pvoid_type_node, integer_type_node, - pint_type, pchar_type_node, integer_type_node); + pint_type, pchar_type_node, size_type_node); gfor_fndecl_caf_is_present = gfc_build_library_function_decl_with_spec ( get_identifier (PREFIX("caf_is_present")), "RRR", @@ -5350,7 +5350,7 @@ generate_coarray_sym_init (gfc_symbol *sym) token, gfc_build_addr_expr (pvoid_type_node, desc), null_pointer_node, /* stat. */ null_pointer_node, /* errgmsg. */ - integer_zero_node); /* errmsg_len. */ + build_zero_cst (size_type_node)); /* errmsg_len. */ gfc_add_expr_to_block (&caf_init_block, tmp); gfc_add_modify (&caf_init_block, decl, fold_convert (TREE_TYPE (decl), gfc_conv_descriptor_data_get (desc))); diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index dd4921681fc..c4a3775d858 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -9824,12 +9824,12 @@ conv_co_collective (gfc_code *code) gfc_add_block_to_block (&block, &argse.pre); gfc_add_block_to_block (&post_block, &argse.post); errmsg = argse.expr; - errmsg_len = fold_convert (integer_type_node, argse.string_length); + errmsg_len = fold_convert (size_type_node, argse.string_length); } else { errmsg = null_pointer_node; - errmsg_len = integer_zero_node; + errmsg_len = build_zero_cst (size_type_node); } /* Generate the function call. */ diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 71e22d80e98..e9e84565549 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -623,7 +623,6 @@ gfc_trans_pause (gfc_code * code) tree gfc_trans_stop (gfc_code *code, bool error_stop) { - tree gfc_int4_type_node = gfc_get_int_type (4); gfc_se se; tree tmp; @@ -633,7 +632,7 @@ gfc_trans_stop (gfc_code *code, bool error_stop) if (code->expr1 == NULL) { - tmp = build_int_cst (gfc_int4_type_node, 0); + tmp = build_int_cst (size_type_node, 0); tmp = build_call_expr_loc (input_location, error_stop ? (flag_coarray == GFC_FCOARRAY_LIB @@ -655,7 +654,7 @@ gfc_trans_stop (gfc_code *code, bool error_stop) : (flag_coarray == GFC_FCOARRAY_LIB ? gfor_fndecl_caf_stop_numeric : gfor_fndecl_stop_numeric), 1, - fold_convert (gfc_int4_type_node, se.expr)); + fold_convert (integer_type_node, se.expr)); } else { @@ -668,7 +667,8 @@ gfc_trans_stop (gfc_code *code, bool error_stop) : (flag_coarray == GFC_FCOARRAY_LIB ? gfor_fndecl_caf_stop_str : gfor_fndecl_stop_string), - 2, se.expr, se.string_length); + 2, se.expr, fold_convert (size_type_node, + se.string_length)); } gfc_add_expr_to_block (&se.pre, tmp); @@ -913,12 +913,12 @@ gfc_trans_lock_unlock (gfc_code *code, gfc_exec_op op) gfc_conv_expr (&argse, code->expr3); gfc_add_block_to_block (&se.pre, &argse.pre); errmsg = argse.expr; - errmsg_len = fold_convert (integer_type_node, argse.string_length); + errmsg_len = fold_convert (size_type_node, argse.string_length); } else { errmsg = null_pointer_node; - errmsg_len = integer_zero_node; + errmsg_len = build_zero_cst (size_type_node); } if (stat != null_pointer_node && TREE_TYPE (stat) != integer_type_node) @@ -1112,12 +1112,12 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op) gfc_conv_expr (&argse, code->expr3); gfc_add_block_to_block (&se.pre, &argse.pre); errmsg = argse.expr; - errmsg_len = fold_convert (integer_type_node, argse.string_length); + errmsg_len = fold_convert (size_type_node, argse.string_length); } else { errmsg = null_pointer_node; - errmsg_len = integer_zero_node; + errmsg_len = build_zero_cst (size_type_node); } if (stat != null_pointer_node && TREE_TYPE (stat) != integer_type_node) @@ -1196,12 +1196,12 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type) gfc_conv_expr (&argse, code->expr3); gfc_conv_string_parameter (&argse); errmsg = gfc_build_addr_expr (NULL, argse.expr); - errmsglen = argse.string_length; + errmsglen = fold_convert (size_type_node, argse.string_length); } else if (flag_coarray == GFC_FCOARRAY_LIB) { errmsg = null_pointer_node; - errmsglen = build_int_cst (integer_type_node, 0); + errmsglen = build_int_cst (size_type_node, 0); } /* Check SYNC IMAGES(imageset) for valid image index. diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 67ddbee606f..4db4968e209 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,56 @@ +2018-02-22 Janne Blomqvist + + * libgfortran.h (stop_string): Use size_t for character length. + * runtime/stop.c (stop_string): Likewise. + (error_stop_string): Likewise. + (stop_numeric): Use int for exit code. + (error_stop_numeric): Likewise. + * caf/libcaf.h: Remove stdint.h include. + (_gfortran_caf_register): Use size_t for character length. + (_gfortran_caf_deregister): Likewise. + (_gfortran_caf_sync_all): Likewise. + (_gfortran_caf_sync_memory): Likewise. + (_gfortran_caf_sync_images): Likewise. + (_gfortran_caf_stop_numeric): Use int for exit code. + (_gfortran_caf_stop_str): Use size_t for character length. + (_gfortran_caf_error_stop_str): Likewise. + (_gfortran_caf_error_stop): Use int for exit code. + (_gfortran_caf_co_broadcast): Use size_t for character length. + (_gfortran_caf_co_sum): Likewise. + (_gfortran_caf_co_min): Likewise. + (_gfortran_caf_co_max): Likewise. + (_gfortran_caf_co_reduce): Likewise. + (_gfortran_caf_lock): Likewise. + (_gfortran_caf_unlock): Likewise. + (_gfortran_caf_event_post): Likewise. + (_gfortran_caf_event_wait): Likewise. + * caf/mpi.c (_gfortran_caf_register): Update implementation to + match prototype. + (_gfortran_caf_deregister): Likewise. + (_gfortran_caf_sync_all): Likewise. + (_gfortran_caf_sync_images): Likewise. + (_gfortran_caf_error_stop_str): Likewise. + (_gfortran_caf_error_stop): Likewise. + * caf/single.c (caf_internal_error): Likewise. + (_gfortran_caf_register): Likewise. + (_gfortran_caf_deregister): Likewise. + (_gfortran_caf_sync_all): Likewise. + (_gfortran_caf_sync_memory): Likewise. + (_gfortran_caf_sync_images): Likewise. + (_gfortran_caf_stop_numeric): Likewise. + (_gfortran_caf_stop_str): Likewise. + (_gfortran_caf_error_stop_str): Likewise. + (_gfortran_caf_error_stop): Likewise. + (_gfortran_caf_co_broadcast): Likewise. + (_gfortran_caf_co_sum): Likewise. + (_gfortran_caf_co_min): Likewise. + (_gfortran_caf_co_max): Likewise. + (_gfortran_caf_co_reduce): Likewise. + (_gfortran_caf_event_post): Likewise. + (_gfortran_caf_event_wait): Likewise. + (_gfortran_caf_lock): Likewise. + (_gfortran_caf_unlock): Likewise. + 2018-02-19 Andre Vehreschild * caf/libcaf.h: Add type parameters to the caf_*_by_ref prototypes. diff --git a/libgfortran/caf/libcaf.h b/libgfortran/caf/libcaf.h index f3428a63fae..198a0e9efd3 100644 --- a/libgfortran/caf/libcaf.h +++ b/libgfortran/caf/libcaf.h @@ -28,7 +28,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include #include /* For size_t. */ -#include /* For int32_t. */ #include "libgfortran.h" @@ -190,29 +189,29 @@ int _gfortran_caf_this_image (int); int _gfortran_caf_num_images (int, int); void _gfortran_caf_register (size_t, caf_register_t, caf_token_t *, - gfc_descriptor_t *, int *, char *, int); + gfc_descriptor_t *, int *, char *, size_t); void _gfortran_caf_deregister (caf_token_t *, caf_deregister_t, int *, char *, - int); + size_t); -void _gfortran_caf_sync_all (int *, char *, int); -void _gfortran_caf_sync_memory (int *, char *, int); -void _gfortran_caf_sync_images (int, int[], int *, char *, int); +void _gfortran_caf_sync_all (int *, char *, size_t); +void _gfortran_caf_sync_memory (int *, char *, size_t); +void _gfortran_caf_sync_images (int, int[], int *, char *, size_t); -void _gfortran_caf_stop_numeric (int32_t) +void _gfortran_caf_stop_numeric (int) __attribute__ ((noreturn)); -void _gfortran_caf_stop_str (const char *, int32_t) +void _gfortran_caf_stop_str (const char *, size_t) __attribute__ ((noreturn)); -void _gfortran_caf_error_stop_str (const char *, int32_t) +void _gfortran_caf_error_stop_str (const char *, size_t) __attribute__ ((noreturn)); -void _gfortran_caf_error_stop (int32_t) __attribute__ ((noreturn)); +void _gfortran_caf_error_stop (int) __attribute__ ((noreturn)); void _gfortran_caf_fail_image (void) __attribute__ ((noreturn)); -void _gfortran_caf_co_broadcast (gfc_descriptor_t *, int, int *, char *, int); -void _gfortran_caf_co_sum (gfc_descriptor_t *, int, int *, char *, int); -void _gfortran_caf_co_min (gfc_descriptor_t *, int, int *, char *, int, int); -void _gfortran_caf_co_max (gfc_descriptor_t *, int, int *, char *, int, int); +void _gfortran_caf_co_broadcast (gfc_descriptor_t *, int, int *, char *, size_t); +void _gfortran_caf_co_sum (gfc_descriptor_t *, int, int *, char *, size_t); +void _gfortran_caf_co_min (gfc_descriptor_t *, int, int *, char *, int, size_t); +void _gfortran_caf_co_max (gfc_descriptor_t *, int, int *, char *, int, size_t); void _gfortran_caf_co_reduce (gfc_descriptor_t *, void* (*) (void *, void*), - int, int, int *, char *, int, int); + int, int, int *, char *, int, size_t); void _gfortran_caf_get (caf_token_t, size_t, int, gfc_descriptor_t *, caf_vector_t *, gfc_descriptor_t *, int, int, bool, @@ -247,10 +246,10 @@ void _gfortran_caf_atomic_cas (caf_token_t, size_t, int, void *, void *, void _gfortran_caf_atomic_op (int, caf_token_t, size_t, int, void *, void *, int *, int, int); -void _gfortran_caf_lock (caf_token_t, size_t, int, int *, int *, char *, int); -void _gfortran_caf_unlock (caf_token_t, size_t, int, int *, char *, int); -void _gfortran_caf_event_post (caf_token_t, size_t, int, int *, char *, int); -void _gfortran_caf_event_wait (caf_token_t, size_t, int, int *, char *, int); +void _gfortran_caf_lock (caf_token_t, size_t, int, int *, int *, char *, size_t); +void _gfortran_caf_unlock (caf_token_t, size_t, int, int *, char *, size_t); +void _gfortran_caf_event_post (caf_token_t, size_t, int, int *, char *, size_t); +void _gfortran_caf_event_wait (caf_token_t, size_t, int, int *, char *, size_t); void _gfortran_caf_event_query (caf_token_t, size_t, int, int *, int *); void _gfortran_caf_failed_images (gfc_descriptor_t *, diff --git a/libgfortran/caf/mpi.c b/libgfortran/caf/mpi.c index 0f7977fc007..14c10b536e3 100644 --- a/libgfortran/caf/mpi.c +++ b/libgfortran/caf/mpi.c @@ -131,7 +131,7 @@ _gfortran_caf_num_images (int distance __attribute__ ((unused)), void * _gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token, - int *stat, char *errmsg, int errmsg_len, + int *stat, char *errmsg, size_t errmsg_len, int num_alloc_comps __attribute__ ((unused))) { void *local; @@ -189,8 +189,8 @@ error: *stat = caf_is_finalized ? STAT_STOPPED_IMAGE : 1; if (errmsg_len > 0) { - int len = ((int) strlen (msg) > errmsg_len) ? errmsg_len - : (int) strlen (msg); + size_t len = (strlen (msg) > errmsg_len) ? errmsg_len + : strlen (msg); memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); @@ -205,7 +205,7 @@ error: void -_gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, int errmsg_len) +_gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, size_t errmsg_len) { if (unlikely (caf_is_finalized)) { @@ -217,8 +217,8 @@ _gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, int errms if (errmsg_len > 0) { - int len = ((int) sizeof (msg) - 1 > errmsg_len) - ? errmsg_len : (int) sizeof (msg) - 1; + size_t len = (sizeof (msg) - 1 > errmsg_len) + ? errmsg_len : sizeof (msg) - 1; memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); @@ -239,7 +239,7 @@ _gfortran_caf_deregister (caf_token_t *token, int *stat, char *errmsg, int errms void -_gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len) +_gfortran_caf_sync_all (int *stat, char *errmsg, size_t errmsg_len) { int ierr; @@ -261,8 +261,8 @@ _gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len) if (errmsg_len > 0) { - int len = ((int) strlen (msg) > errmsg_len) ? errmsg_len - : (int) strlen (msg); + size_t len = (strlen (msg) > errmsg_len) ? errmsg_len + : strlen (msg); memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); @@ -278,7 +278,7 @@ _gfortran_caf_sync_all (int *stat, char *errmsg, int errmsg_len) is not equivalent to SYNC ALL. */ void _gfortran_caf_sync_images (int count, int images[], int *stat, char *errmsg, - int errmsg_len) + size_t errmsg_len) { int ierr; if (count == 0 || (count == 1 && images[0] == caf_this_image)) @@ -329,8 +329,8 @@ _gfortran_caf_sync_images (int count, int images[], int *stat, char *errmsg, if (errmsg_len > 0) { - int len = ((int) strlen (msg) > errmsg_len) ? errmsg_len - : (int) strlen (msg); + size_t len = (strlen (msg) > errmsg_len) ? errmsg_len + : strlen (msg); memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); @@ -358,7 +358,7 @@ error_stop (int error) /* ERROR STOP function for string arguments. */ void -_gfortran_caf_error_stop_str (const char *string, int32_t len) +_gfortran_caf_error_stop_str (const char *string, size_t len) { fputs ("ERROR STOP ", stderr); while (len--) @@ -372,7 +372,7 @@ _gfortran_caf_error_stop_str (const char *string, int32_t len) /* ERROR STOP function for numerical arguments. */ void -_gfortran_caf_error_stop (int32_t error) +_gfortran_caf_error_stop (int error) { fprintf (stderr, "ERROR STOP %d\n", error); error_stop (error); diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c index 18906e99a94..053ec87d562 100644 --- a/libgfortran/caf/single.c +++ b/libgfortran/caf/single.c @@ -28,6 +28,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include /* For exit and malloc. */ #include /* For memcpy and memset. */ #include /* For variadic arguments. */ +#include #include /* Define GFC_CAF_CHECK to enable run-time checking. */ @@ -74,7 +75,7 @@ caf_runtime_error (const char *message, ...) /* Error handling is similar everytime. */ static void caf_internal_error (const char *msg, int *stat, char *errmsg, - int errmsg_len, ...) + size_t errmsg_len, ...) { va_list args; va_start (args, errmsg_len); @@ -83,8 +84,8 @@ caf_internal_error (const char *msg, int *stat, char *errmsg, *stat = 1; if (errmsg_len > 0) { - size_t len = snprintf (errmsg, errmsg_len, msg, args); - if ((size_t)errmsg_len > len) + int len = snprintf (errmsg, errmsg_len, msg, args); + if (len >= 0 && errmsg_len > (size_t) len) memset (&errmsg[len], ' ', errmsg_len - len); } va_end (args); @@ -134,7 +135,7 @@ _gfortran_caf_num_images (int distance __attribute__ ((unused)), void _gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token, gfc_descriptor_t *data, int *stat, char *errmsg, - int errmsg_len) + size_t errmsg_len) { const char alloc_fail_msg[] = "Failed to allocate coarray"; void *local; @@ -195,7 +196,7 @@ _gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token, void _gfortran_caf_deregister (caf_token_t *token, caf_deregister_t type, int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { caf_single_token_t single_token = TOKEN (*token); @@ -221,7 +222,7 @@ _gfortran_caf_deregister (caf_token_t *token, caf_deregister_t type, int *stat, void _gfortran_caf_sync_all (int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { __asm__ __volatile__ ("":::"memory"); if (stat) @@ -232,7 +233,7 @@ _gfortran_caf_sync_all (int *stat, void _gfortran_caf_sync_memory (int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { __asm__ __volatile__ ("":::"memory"); if (stat) @@ -245,7 +246,7 @@ _gfortran_caf_sync_images (int count __attribute__ ((unused)), int images[] __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { #ifdef GFC_CAF_CHECK int i; @@ -266,7 +267,7 @@ _gfortran_caf_sync_images (int count __attribute__ ((unused)), void -_gfortran_caf_stop_numeric(int32_t stop_code) +_gfortran_caf_stop_numeric(int stop_code) { fprintf (stderr, "STOP %d\n", stop_code); exit (0); @@ -274,7 +275,7 @@ _gfortran_caf_stop_numeric(int32_t stop_code) void -_gfortran_caf_stop_str(const char *string, int32_t len) +_gfortran_caf_stop_str(const char *string, size_t len) { fputs ("STOP ", stderr); while (len--) @@ -286,7 +287,7 @@ _gfortran_caf_stop_str(const char *string, int32_t len) void -_gfortran_caf_error_stop_str (const char *string, int32_t len) +_gfortran_caf_error_stop_str (const char *string, size_t len) { fputs ("ERROR STOP ", stderr); while (len--) @@ -366,7 +367,7 @@ _gfortran_caf_stopped_images (gfc_descriptor_t *array, void -_gfortran_caf_error_stop (int32_t error) +_gfortran_caf_error_stop (int error) { fprintf (stderr, "ERROR STOP %d\n", error); exit (error); @@ -377,7 +378,7 @@ void _gfortran_caf_co_broadcast (gfc_descriptor_t *a __attribute__ ((unused)), int source_image __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { if (stat) *stat = 0; @@ -387,7 +388,7 @@ void _gfortran_caf_co_sum (gfc_descriptor_t *a __attribute__ ((unused)), int result_image __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { if (stat) *stat = 0; @@ -398,7 +399,7 @@ _gfortran_caf_co_min (gfc_descriptor_t *a __attribute__ ((unused)), int result_image __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), int a_len __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { if (stat) *stat = 0; @@ -409,7 +410,7 @@ _gfortran_caf_co_max (gfc_descriptor_t *a __attribute__ ((unused)), int result_image __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), int a_len __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { if (stat) *stat = 0; @@ -424,7 +425,7 @@ _gfortran_caf_co_reduce (gfc_descriptor_t *a __attribute__ ((unused)), int result_image __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), int a_len __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { if (stat) *stat = 0; @@ -2910,7 +2911,7 @@ void _gfortran_caf_event_post (caf_token_t token, size_t index, int image_index __attribute__ ((unused)), int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { uint32_t value = 1; uint32_t *event = (uint32_t *) ((char *) MEMTOK (token) + index @@ -2925,7 +2926,7 @@ void _gfortran_caf_event_wait (caf_token_t token, size_t index, int until_count, int *stat, char *errmsg __attribute__ ((unused)), - int errmsg_len __attribute__ ((unused))) + size_t errmsg_len __attribute__ ((unused))) { uint32_t *event = (uint32_t *) ((char *) MEMTOK (token) + index * sizeof (uint32_t)); @@ -2952,7 +2953,7 @@ _gfortran_caf_event_query (caf_token_t token, size_t index, void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index __attribute__ ((unused)), - int *aquired_lock, int *stat, char *errmsg, int errmsg_len) + int *aquired_lock, int *stat, char *errmsg, size_t errmsg_len) { const char *msg = "Already locked"; bool *lock = &((bool *) MEMTOK (token))[index]; @@ -2981,22 +2982,22 @@ _gfortran_caf_lock (caf_token_t token, size_t index, *stat = 1; if (errmsg_len > 0) { - int len = ((int) sizeof (msg) > errmsg_len) ? errmsg_len - : (int) sizeof (msg); + size_t len = (sizeof (msg) > errmsg_len) ? errmsg_len + : sizeof (msg); memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); } return; } - _gfortran_caf_error_stop_str (msg, (int32_t) strlen (msg)); + _gfortran_caf_error_stop_str (msg, strlen (msg)); } void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index __attribute__ ((unused)), - int *stat, char *errmsg, int errmsg_len) + int *stat, char *errmsg, size_t errmsg_len) { const char *msg = "Variable is not locked"; bool *lock = &((bool *) MEMTOK (token))[index]; @@ -3014,15 +3015,15 @@ _gfortran_caf_unlock (caf_token_t token, size_t index, *stat = 1; if (errmsg_len > 0) { - int len = ((int) sizeof (msg) > errmsg_len) ? errmsg_len - : (int) sizeof (msg); + size_t len = (sizeof (msg) > errmsg_len) ? errmsg_len + : sizeof (msg); memcpy (errmsg, msg, len); if (errmsg_len > len) memset (&errmsg[len], ' ', errmsg_len-len); } return; } - _gfortran_caf_error_stop_str (msg, (int32_t) strlen (msg)); + _gfortran_caf_error_stop_str (msg, strlen (msg)); } int diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index 38e364f1012..072dc869be8 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -888,7 +888,7 @@ internal_proto(filename_from_unit); /* stop.c */ -extern _Noreturn void stop_string (const char *, GFC_INTEGER_4); +extern _Noreturn void stop_string (const char *, size_t); export_proto(stop_string); /* reshape_packed.c */ diff --git a/libgfortran/runtime/stop.c b/libgfortran/runtime/stop.c index 6f8b62f8385..3ef1350c281 100644 --- a/libgfortran/runtime/stop.c +++ b/libgfortran/runtime/stop.c @@ -81,14 +81,14 @@ report_exception (void) /* A numeric STOP statement. */ -extern _Noreturn void stop_numeric (GFC_INTEGER_4); +extern _Noreturn void stop_numeric (int); export_proto(stop_numeric); void -stop_numeric (GFC_INTEGER_4 code) +stop_numeric (int code) { report_exception (); - st_printf ("STOP %d\n", (int)code); + st_printf ("STOP %d\n", code); exit (code); } @@ -96,7 +96,7 @@ stop_numeric (GFC_INTEGER_4 code) /* A character string or blank STOP statement. */ void -stop_string (const char *string, GFC_INTEGER_4 len) +stop_string (const char *string, size_t len) { report_exception (); if (string) @@ -114,11 +114,11 @@ stop_string (const char *string, GFC_INTEGER_4 len) initiates error termination of execution." Thus, error_stop_string returns a nonzero exit status code. */ -extern _Noreturn void error_stop_string (const char *, GFC_INTEGER_4); +extern _Noreturn void error_stop_string (const char *, size_t); export_proto(error_stop_string); void -error_stop_string (const char *string, GFC_INTEGER_4 len) +error_stop_string (const char *string, size_t len) { report_exception (); estr_write ("ERROR STOP "); @@ -131,13 +131,13 @@ error_stop_string (const char *string, GFC_INTEGER_4 len) /* A numeric ERROR STOP statement. */ -extern _Noreturn void error_stop_numeric (GFC_INTEGER_4); +extern _Noreturn void error_stop_numeric (int); export_proto(error_stop_numeric); void -error_stop_numeric (GFC_INTEGER_4 code) +error_stop_numeric (int code) { report_exception (); - st_printf ("ERROR STOP %d\n", (int) code); + st_printf ("ERROR STOP %d\n", code); exit_error (code); } -- 2.30.2