From patchwork Fri Aug 27 00:47:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 62817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 15198B70DB for ; Fri, 27 Aug 2010 10:48:09 +1000 (EST) Received: (qmail 3510 invoked by alias); 27 Aug 2010 00:48:06 -0000 Received: (qmail 3493 invoked by uid 22791); 27 Aug 2010 00:48:04 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from out01.roch.ny.frontiernet.net (HELO out01.roch.ny.frontiernet.net) (66.133.183.226) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Aug 2010 00:47:58 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAOOndkxA6lwO/2dsb2JhbACgVMEKhTcEhDo Received: from relay03.roch.ny.frontiernet.net ([66.133.182.166]) by out01.roch.ny.frontiernet.net with ESMTP; 27 Aug 2010 00:47:55 +0000 X-Previous-IP: 64.234.92.14 Received: from [192.168.1.7] (host-64-234-92-14.nctv.com [64.234.92.14]) by relay03.roch.ny.frontiernet.net (Postfix) with ESMTPA id 84E941026D; Fri, 27 Aug 2010 00:47:54 +0000 (UTC) Message-ID: <4C770B39.7000309@frontier.com> Date: Thu, 26 Aug 2010 17:47:53 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: gfortran CC: gcc patches Subject: Re: [patch, fortran] PR43217 Output of Hollerith constants which are not a multiple of 4 bytes References: <4C75C037.1030606@frontier.com> <4C75E045.80604@frontier.com> In-Reply-To: <4C75E045.80604@frontier.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 08/25/2010 08:32 PM, Jerry DeLisle wrote: > On 08/25/2010 06:15 PM, Jerry DeLisle wrote: >> Hi, >> >> The attached patch fixes this by padding the constant when it is created >> to fit into a default integer size. >> I have updated the patch to include saving the pad size in the expressions type specification so that calculated lengths used later can be adjusted to avoid spurious warnings. Test case attached. I expect to revise this to handle platforms that may have different endian-ness. Regression tested on i686-Gnu-linux. OK for trunk. 2010-08-26 Jerry DeLisle PR fortran/43217 * primary.c (match_hollerith_constant): Calculate padding needed to fill default integer and allocate string for that size. Set pad bytes to ' '. * gfortran.h: Add hollerith pad value to type spec union. * data.c (create_character_initializer): Fix spelling of function name. Use hollerith pad value to calculate length. * arith.c (hollerith2representation); Use hollerith pad value to calculate length. Index: gfortran.h =================================================================== --- gfortran.h (revision 163560) +++ gfortran.h (working copy) @@ -880,6 +880,7 @@ typedef struct { struct gfc_symbol *derived; /* For derived types only. */ gfc_charlen *cl; /* For character types only. */ + int pad; /* For hollerith types only. */ } u; Index: ChangeLog =================================================================== --- ChangeLog (revision 163560) +++ ChangeLog (working copy) @@ -1,3 +1,10 @@ +2010-08-25 Jerry DeLisle + + PR fortran/43217 + * primary.c (match_hollerith_constant): Calculate padding needed to + fill default integer and allocate string for that size. Set pad bytes + to ' '. + 2010-08-25 Jakub Jelinek * trans-decl.c (gfc_build_intrinsic_function_decls): Set Index: data.c =================================================================== --- data.c (revision 163560) +++ data.c (working copy) @@ -100,8 +100,8 @@ find_con_by_component (gfc_component *com, gfc_con according to normal assignment rules. */ static gfc_expr * -create_character_intializer (gfc_expr *init, gfc_typespec *ts, - gfc_ref *ref, gfc_expr *rvalue) +create_character_initializer (gfc_expr *init, gfc_typespec *ts, + gfc_ref *ref, gfc_expr *rvalue) { int len, start, end; gfc_char_t *dest; @@ -149,7 +149,7 @@ static gfc_expr * /* Copy the initial value. */ if (rvalue->ts.type == BT_HOLLERITH) - len = rvalue->representation.length; + len = rvalue->representation.length - rvalue->ts.u.pad; else len = rvalue->value.character.length; @@ -342,7 +342,7 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr { if (lvalue->ts.u.cl->length == NULL && !(ref && ref->u.ss.length != NULL)) return FAILURE; - expr = create_character_intializer (init, last_ts, ref, rvalue); + expr = create_character_initializer (init, last_ts, ref, rvalue); } else { Index: arith.c =================================================================== --- arith.c (revision 163560) +++ arith.c (working copy) @@ -2260,7 +2260,7 @@ hollerith2representation (gfc_expr *result, gfc_ex { int src_len, result_len; - src_len = src->representation.length; + src_len = src->representation.length - src->ts.u.pad; result_len = gfc_target_expr_size (result); if (src_len > result_len) Index: primary.c =================================================================== --- primary.c (revision 163560) +++ primary.c (working copy) @@ -242,7 +242,7 @@ match_hollerith_constant (gfc_expr **result) locus old_loc; gfc_expr *e = NULL; const char *msg; - int num; + int num, pad; int i; old_loc = gfc_current_locus; @@ -279,8 +279,11 @@ match_hollerith_constant (gfc_expr **result) e = gfc_get_constant_expr (BT_HOLLERITH, gfc_default_character_kind, &gfc_current_locus); - e->representation.string = XCNEWVEC (char, num + 1); + /* Calculate padding needed to fit default integer memory. */ + pad = gfc_default_integer_kind - (num % gfc_default_integer_kind); + e->representation.string = XCNEWVEC (char, num + pad + 1); + for (i = 0; i < num; i++) { gfc_char_t c = gfc_next_char_literal (1); @@ -294,9 +297,14 @@ match_hollerith_constant (gfc_expr **result) e->representation.string[i] = (unsigned char) c; } - e->representation.string[num] = '\0'; - e->representation.length = num; + /* Now pad with blanks and end with a null char. */ + for (i = 0; i < pad; i++) + e->representation.string[num + i] = ' '; + e->representation.string[num + i] = '\0 '; + e->representation.length = num + pad; + e->ts.u.pad = pad; + *result = e; return MATCH_YES; }