diff mbox

[fortran] PR43217 Output of Hollerith constants which are not a multiple of 4 bytes

Message ID 4C75C037.1030606@frontier.com
State New
Headers show

Commit Message

Jerry DeLisle Aug. 26, 2010, 1:15 a.m. UTC
Hi,

The attached patch fixes this by padding the constant when it is created to fit 
into a default integer size.

Regression tested on i686-gnu-linux. I will dejagnu the test case in the PR.

OK for trunk?

Regards,

Jerry

2010-08-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	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 ' '.

Comments

Jerry DeLisle Aug. 26, 2010, 3:32 a.m. UTC | #1
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.
>
> Regression tested on i686-gnu-linux. I will dejagnu the test case in the
> PR.
>
Oops! Withdraw.

I missed some extra warnings in a couple of test cases. Maybe we are going to 
have to take a different approach.  I am thinking on this.

Jerry
diff mbox

Patch

Index: primary.c
===================================================================
--- primary.c	(revision 163495)
+++ 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,13 @@  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;
+
 	  *result = e;
 	  return MATCH_YES;
 	}