[Patches, Fortran] ALLOCATE & CAF library.
Tobias Burnus
burnus@net-b.de
Thu Jul 21 17:10:00 GMT 2011
On 07/21/2011 06:01 PM, Daniel Carrera wrote:
> I was using Mercurial wrong. I've been experimenting with using
> Mercurial to work with GCC and was doing the diff wrong. The attached
> file should be correct (fingers crossed).
Looks better :-)
The patch is OK after regtesting and fixing the following nits.
Changelog from http://gcc.gnu.org/ml/fortran/2011-07/txt00008.txt:
> * trans.c (gfc_allocate_with_status): Split into two functions
> gfc_allocate_using_malloc ad gfc_allocate_usig_lib.
Typo: "and" and "gfc_allocate_using_lib" (usig->using).
> @@ -4881,2 +4889,21 @@ gfc_trans_allocate (gfc_code * code)
>
> + /* Error checking -- Note: ERRMS only makes sense with STAT. */
Typo: ERRMSG.
> @@ -676,2 +638,72 @@ gfc_allocate_with_status (stmtblock_t *
>
> +/* Allocate memory, using an optional status argument.
> +
> + This function follows the following pseudo-code:
> +
> + void *
> + allocate (size_t size, integer_type stat)
> + {
> + void *newmem;
> +
> + if (stat requested)
> + stat = 0;
No need to set "stat = 0". caf_registering always sets stat (if present).
> + newmem = _caf_register ( size, regtype, NULL,&stat, NULL, NULL);
> + if (newmem == NULL)
> + {
> + if (!stat requested)
> + runtime_error ("Allocation would exceed memory limit");
> + }
Remove the if block - it's not in the actual code and the library
function already aborts.
> + return newmem;
> + } */
> +tree
> +gfc_allocate_using_lib (stmtblock_t * block, tree size, tree status,
> + tree errmsg, tree errlen)
> +{
> + tree res, pstat;
> + tree status_type = status ? TREE_TYPE (status) : NULL_TREE;
> +
> + /* Evaluate size only once, and make sure it has the right type. */
> + size = gfc_evaluate_now (size, block);
> + if (TREE_TYPE (size) != TREE_TYPE (size_type_node))
> + size = fold_convert (size_type_node, size);
> +
> + /* Create a variable to hold the result. */
> + res = gfc_create_var (prvoid_type_node, NULL);
> +
> + /* Set the optional status variable to zero. */
> + if (status != NULL_TREE)
> + gfc_add_expr_to_block (block,
> + fold_build2_loc (input_location, MODIFY_EXPR, status_type,
> + status, build_int_cst (status_type, 0)));
As written above - just for the actual code.
Tobias
More information about the Gcc-patches
mailing list