public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR 78534, 83704 Large character lengths
@ 2018-01-09 12:07 Janne Blomqvist
  0 siblings, 0 replies; 13+ messages in thread
From: Janne Blomqvist @ 2018-01-09 12:07 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Janne Blomqvist

This patch fixes various parts of the code to use a larger type than
int for the character length. Depending on the situation,
HOST_WIDE_INT, size_t, or gfc_charlen_t is appropriate.

Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu, Ok for trunk?

gcc/fortran/ChangeLog:

2018-01-09  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 78534
	PR 83704
	* arith.c (gfc_arith_concat): Use size_t for string length.
	(gfc_compare_string): Likewise.
	(gfc_compare_with_Cstring): Likewise.
	* array.c (gfc_resolve_character_array_constructor): Use
	HOST_WIDE_INT, gfc_mpz_get_hwi.
	* check.c (gfc_check_fe_runtime_error): Use size_t.
	* data.c (create_character_initializer): Use HOST_WIDE_INT,
	gfc_extract_hwi.
	* decl.c (gfc_set_constant_character_len): Use gfc_charlen_t.
	(add_init_expr_to_sym): Use HOST_WIDE_INT.
	* expr.c (gfc_build_init_expr): Use HOST_WIDE_INT,
	gfc_extract_hwi.
	(gfc_apply_init): Likewise.
	* match.h (gfc_set_constant_character_len): Update prototype.
	* primary.c (match_string_constant): Use size_t.
	* resolve.c (resolve_ordinary_assign): Use HOST_WIDE_INT,
	gfc_mpz_get_hwi.
	* simplify.c (init_result_expr): Likewise.
	(gfc_simplify_len_trim): Use size_t.
	* target-memory.c (gfc_encode_character): Use size_t.
	(gfc_target_encode_expr): Use HOST_WIDE_INT, gfc_mpz_get_hwi.
	(interpret_array): Use size_t.
	(gfc_interpret_character): Likewise.
	* target-memory.h (gfc_encode_character): Update prototype.
	(gfc_interpret_character): Likewise.
	(gfc_target_interpret_expr): Likewise.
	* trans-const.c (gfc_build_string_const): Use size_t for length
	argument.
	(gfc_build_wide_string_const): Likewise.
	* trans-const.h (gfc_build_string_const): Likewise.
	(gfc_build_wide_string_const): Likewise.
---
 gcc/fortran/arith.c         |  6 +++---
 gcc/fortran/array.c         | 31 ++++++++++++-------------------
 gcc/fortran/check.c         |  2 +-
 gcc/fortran/data.c          | 14 +++++++-------
 gcc/fortran/decl.c          | 19 +++++++++++--------
 gcc/fortran/expr.c          | 13 ++++---------
 gcc/fortran/match.h         |  3 ++-
 gcc/fortran/primary.c       |  5 +++--
 gcc/fortran/resolve.c       | 10 +++++-----
 gcc/fortran/simplify.c      |  8 ++++----
 gcc/fortran/target-memory.c | 31 +++++++++++++++----------------
 gcc/fortran/target-memory.h |  6 +++---
 gcc/fortran/trans-const.c   |  4 ++--
 gcc/fortran/trans-const.h   |  4 ++--
 14 files changed, 74 insertions(+), 82 deletions(-)

diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c
index 92067ac..8f328fe 100644
--- a/gcc/fortran/arith.c
+++ b/gcc/fortran/arith.c
@@ -980,7 +980,7 @@ static arith
 gfc_arith_concat (gfc_expr *op1, gfc_expr *op2, gfc_expr **resultp)
 {
   gfc_expr *result;
-  int len;
+  size_t len;
 
   gcc_assert (op1->ts.kind == op2->ts.kind);
   result = gfc_get_constant_expr (BT_CHARACTER, op1->ts.kind,
@@ -1089,7 +1089,7 @@ compare_complex (gfc_expr *op1, gfc_expr *op2)
 int
 gfc_compare_string (gfc_expr *a, gfc_expr *b)
 {
-  int len, alen, blen, i;
+  size_t len, alen, blen, i;
   gfc_char_t ac, bc;
 
   alen = a->value.character.length;
@@ -1116,7 +1116,7 @@ gfc_compare_string (gfc_expr *a, gfc_expr *b)
 int
 gfc_compare_with_Cstring (gfc_expr *a, const char *b, bool case_sensitive)
 {
-  int len, alen, blen, i;
+  size_t len, alen, blen, i;
   gfc_char_t ac, bc;
 
   alen = a->value.character.length;
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 882fe57..ed5fdb2 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1962,7 +1962,7 @@ bool
 gfc_resolve_character_array_constructor (gfc_expr *expr)
 {
   gfc_constructor *p;
-  int found_length;
+  HOST_WIDE_INT found_length;
 
   gcc_assert (expr->expr_type == EXPR_ARRAY);
   gcc_assert (expr->ts.type == BT_CHARACTER);
@@ -1994,7 +1994,7 @@ got_charlen:
       for (p = gfc_constructor_first (expr->value.constructor);
 	   p; p = gfc_constructor_next (p))
 	{
-	  int current_length = -1;
+	  HOST_WIDE_INT current_length = -1;
 	  gfc_ref *ref;
 	  for (ref = p->expr->ref; ref; ref = ref->next)
 	    if (ref->type == REF_SUBSTRING
@@ -2005,19 +2005,11 @@ got_charlen:
 	  if (p->expr->expr_type == EXPR_CONSTANT)
 	    current_length = p->expr->value.character.length;
 	  else if (ref)
-	    {
-	      long j;
-	      j = mpz_get_ui (ref->u.ss.end->value.integer)
-		- mpz_get_ui (ref->u.ss.start->value.integer) + 1;
-	      current_length = (int) j;
-	    }
+	    current_length = gfc_mpz_get_hwi (ref->u.ss.end->value.integer)
+	      - gfc_mpz_get_hwi (ref->u.ss.start->value.integer) + 1;
 	  else if (p->expr->ts.u.cl && p->expr->ts.u.cl->length
 		   && p->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT)
-	    {
-	      long j;
-	      j = mpz_get_si (p->expr->ts.u.cl->length->value.integer);
-	      current_length = (int) j;
-	    }
+	    current_length = gfc_mpz_get_hwi (p->expr->ts.u.cl->length->value.integer);
 	  else
 	    return true;
 
@@ -2027,9 +2019,10 @@ got_charlen:
 	    found_length = current_length;
 	  else if (found_length != current_length)
 	    {
-	      gfc_error ("Different CHARACTER lengths (%d/%d) in array"
-			 " constructor at %L", found_length, current_length,
-			 &p->expr->where);
+	      gfc_error ("Different CHARACTER lengths ("
+			 HOST_WIDE_INT_PRINT_DEC "/" HOST_WIDE_INT_PRINT_DEC
+			 ") in array constructor at %L", found_length,
+			 current_length, &p->expr->where);
 	      return false;
 	    }
 
@@ -2051,7 +2044,7 @@ got_charlen:
       /* If we've got a constant character length, pad according to this.
 	 gfc_extract_int does check for BT_INTEGER and EXPR_CONSTANT and sets
 	 max_length only if they pass.  */
-      gfc_extract_int (expr->ts.u.cl->length, &found_length);
+      gfc_extract_hwi (expr->ts.u.cl->length, &found_length);
 
       /* Now pad/truncate the elements accordingly to the specified character
 	 length.  This is ok inside this conditional, as in the case above
@@ -2063,13 +2056,13 @@ got_charlen:
 	  if (p->expr->expr_type == EXPR_CONSTANT)
 	    {
 	      gfc_expr *cl = NULL;
-	      int current_length = -1;
+	      HOST_WIDE_INT current_length = -1;
 	      bool has_ts;
 
 	      if (p->expr->ts.u.cl && p->expr->ts.u.cl->length)
 	      {
 		cl = p->expr->ts.u.cl->length;
-		gfc_extract_int (cl, &current_length);
+		gfc_extract_hwi (cl, &current_length);
 	      }
 
 	      /* If gfc_extract_int above set current_length, we implicitly
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index fccb927..40e4b86 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5839,7 +5839,7 @@ bool
 gfc_check_fe_runtime_error (gfc_actual_arglist *a)
 {
   gfc_expr *e;
-  int len, i;
+  size_t len, i;
   int num_percent, nargs;
 
   e = a->expr;
diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 6313f2e..45bb5c0 100644
--- a/gcc/fortran/data.c
+++ b/gcc/fortran/data.c
@@ -104,11 +104,11 @@ static gfc_expr *
 create_character_initializer (gfc_expr *init, gfc_typespec *ts,
 			      gfc_ref *ref, gfc_expr *rvalue)
 {
-  int len, start, end, tlen;
+  HOST_WIDE_INT len, start, end, tlen;
   gfc_char_t *dest;
   bool alloced_init = false;
 	    
-  gfc_extract_int (ts->u.cl->length, &len);
+  gfc_extract_hwi (ts->u.cl->length, &len);
 
   if (init == NULL)
     {
@@ -143,10 +143,10 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts,
 	  return NULL;
 	}
 
-      gfc_extract_int (start_expr, &start);
+      gfc_extract_hwi (start_expr, &start);
       gfc_free_expr (start_expr);
       start--;
-      gfc_extract_int (end_expr, &end);
+      gfc_extract_hwi (end_expr, &end);
       gfc_free_expr (end_expr);
     }
   else
@@ -174,7 +174,8 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts,
       else
 	{
 	  gfc_warning_now (0, "Initialization string at %L was truncated to "
-			   "fit the variable (%d/%d)", &rvalue->where,
+			   "fit the variable (" HOST_WIDE_INT_PRINT_DEC "/"
+			   HOST_WIDE_INT_PRINT_DEC ")", &rvalue->where,
 			   tlen, len);
 	  len = tlen;
 	}
@@ -182,8 +183,7 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts,
 
   if (rvalue->ts.type == BT_HOLLERITH)
     {
-      int i;
-      for (i = 0; i < len; i++)
+      for (size_t i = 0; i < (size_t) len; i++)
 	dest[start+i] = rvalue->representation.string[i];
     }
   else
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index cb23534..14c8072 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1538,10 +1538,11 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
    means no checking.  */
 
 void
-gfc_set_constant_character_len (int len, gfc_expr *expr, int check_len)
+gfc_set_constant_character_len (gfc_charlen_t len, gfc_expr *expr,
+				gfc_charlen_t check_len)
 {
   gfc_char_t *s;
-  int slen;
+  gfc_charlen_t slen;
 
   if (expr->ts.type != BT_CHARACTER)
     return;
@@ -1564,15 +1565,19 @@ gfc_set_constant_character_len (int len, gfc_expr *expr, int check_len)
       if (warn_character_truncation && slen > len)
 	gfc_warning_now (OPT_Wcharacter_truncation,
 			 "CHARACTER expression at %L is being truncated "
-			 "(%d/%d)", &expr->where, slen, len);
+			 "(" HOST_WIDE_INT_PRINT_DEC "/"
+			 HOST_WIDE_INT_PRINT_DEC ")", &expr->where,
+			 (HOST_WIDE_INT) slen, (HOST_WIDE_INT) len);
 
       /* Apply the standard by 'hand' otherwise it gets cleared for
 	 initializers.  */
       if (check_len != -1 && slen != check_len
           && !(gfc_option.allow_std & GFC_STD_GNU))
 	gfc_error_now ("The CHARACTER elements of the array constructor "
-		       "at %L must have the same length (%d/%d)",
-			&expr->where, slen, check_len);
+		       "at %L must have the same length ("
+		       HOST_WIDE_INT_PRINT_DEC "/" HOST_WIDE_INT_PRINT_DEC ")",
+		       &expr->where, (HOST_WIDE_INT) slen,
+		       (HOST_WIDE_INT) check_len);
 
       s[len] = '\0';
       free (expr->value.character.string);
@@ -1751,12 +1756,10 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
 	  /* Update initializer character length according symbol.  */
 	  else if (sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)
 	    {
-	      int len;
-
 	      if (!gfc_specification_expr (sym->ts.u.cl->length))
 		return false;
 
-	      len = mpz_get_si (sym->ts.u.cl->length->value.integer);
+	      HOST_WIDE_INT len = gfc_mpz_get_hwi (sym->ts.u.cl->length->value.integer);
 
 	      if (init->expr_type == EXPR_CONSTANT)
 		gfc_set_constant_character_len (len, init, -1);
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index a8f0f0f..db2b54f 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -4088,9 +4088,7 @@ gfc_build_default_init_expr (gfc_typespec *ts, locus *where)
 gfc_expr *
 gfc_build_init_expr (gfc_typespec *ts, locus *where, bool force)
 {
-  int char_len;
   gfc_expr *init_expr;
-  int i;
 
   /* Try to build an initializer expression.  */
   init_expr = gfc_get_constant_expr (ts->type, ts->kind, where);
@@ -4202,10 +4200,10 @@ gfc_build_init_expr (gfc_typespec *ts, locus *where, bool force)
           && ts->u.cl->length
           && ts->u.cl->length->expr_type == EXPR_CONSTANT)
         {
-          char_len = mpz_get_si (ts->u.cl->length->value.integer);
+          HOST_WIDE_INT char_len = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
           init_expr->value.character.length = char_len;
           init_expr->value.character.string = gfc_get_wide_string (char_len+1);
-          for (i = 0; i < char_len; i++)
+          for (size_t i = 0; i < (size_t) char_len; i++)
             init_expr->value.character.string[i]
               = (unsigned char) gfc_option.flag_init_character_value;
         }
@@ -4255,13 +4253,11 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
       && ts->u.cl
       && ts->u.cl->length && ts->u.cl->length->expr_type == EXPR_CONSTANT)
     {
-      int len;
-
       gcc_assert (ts->u.cl && ts->u.cl->length);
       gcc_assert (ts->u.cl->length->expr_type == EXPR_CONSTANT);
       gcc_assert (ts->u.cl->length->ts.type == BT_INTEGER);
 
-      len = mpz_get_si (ts->u.cl->length->value.integer);
+      HOST_WIDE_INT len = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
 
       if (init->expr_type == EXPR_CONSTANT)
         gfc_set_constant_character_len (len, init, -1);
@@ -4276,7 +4272,6 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
 
           if (ctor)
             {
-              int first_len;
               bool has_ts = (init->ts.u.cl
                              && init->ts.u.cl->length_from_typespec);
 
@@ -4285,7 +4280,7 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
                  length.  This need not be the length of the LHS!  */
               gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
               gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
-              first_len = ctor->expr->value.character.length;
+              gfc_charlen_t first_len = ctor->expr->value.character.length;
 
               for ( ; ctor; ctor = gfc_constructor_next (ctor))
                 if (ctor->expr->expr_type == EXPR_CONSTANT)
diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h
index 2e04b3e..6f12b13 100644
--- a/gcc/fortran/match.h
+++ b/gcc/fortran/match.h
@@ -230,7 +230,8 @@ match gfc_match_type (gfc_statement *);
 match gfc_match_implicit_none (void);
 match gfc_match_implicit (void);
 
-void gfc_set_constant_character_len (int, gfc_expr *, int);
+void gfc_set_constant_character_len (gfc_charlen_t, gfc_expr *,
+				     gfc_charlen_t);
 
 /* Matchers for attribute declarations.  */
 match gfc_match_allocatable (void);
diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index 4b6ad47..3d07673 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -1006,7 +1006,8 @@ static match
 match_string_constant (gfc_expr **result)
 {
   char name[GFC_MAX_SYMBOL_LEN + 1], peek;
-  int i, kind, length, save_warn_ampersand, ret;
+  size_t length;
+  int kind,save_warn_ampersand, ret;
   locus old_locus, start_locus;
   gfc_symbol *sym;
   gfc_expr *e;
@@ -1125,7 +1126,7 @@ got_delim:
   warn_ampersand = false;
 
   p = e->value.character.string;
-  for (i = 0; i < length; i++)
+  for (size_t i = 0; i < length; i++)
     {
       c = next_string_char (delimiter, &ret);
 
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 57155cd..d32fe96 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -10120,8 +10120,6 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
   bool rval = false;
   gfc_expr *lhs;
   gfc_expr *rhs;
-  int llen = 0;
-  int rlen = 0;
   int n;
   gfc_ref *ref;
   symbol_attribute attr;
@@ -10203,10 +10201,11 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
   if (lhs->ts.type == BT_CHARACTER
 	&& warn_character_truncation)
     {
+      HOST_WIDE_INT llen = 0, rlen = 0;
       if (lhs->ts.u.cl != NULL
 	    && lhs->ts.u.cl->length != NULL
 	    && lhs->ts.u.cl->length->expr_type == EXPR_CONSTANT)
-	llen = mpz_get_si (lhs->ts.u.cl->length->value.integer);
+	llen = gfc_mpz_get_hwi (lhs->ts.u.cl->length->value.integer);
 
       if (rhs->expr_type == EXPR_CONSTANT)
  	rlen = rhs->value.character.length;
@@ -10214,12 +10213,13 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
       else if (rhs->ts.u.cl != NULL
 		 && rhs->ts.u.cl->length != NULL
 		 && rhs->ts.u.cl->length->expr_type == EXPR_CONSTANT)
-	rlen = mpz_get_si (rhs->ts.u.cl->length->value.integer);
+	rlen = gfc_mpz_get_hwi (rhs->ts.u.cl->length->value.integer);
 
       if (rlen && llen && rlen > llen)
 	gfc_warning_now (OPT_Wcharacter_truncation,
 			 "CHARACTER expression will be truncated "
-			 "in assignment (%d/%d) at %L",
+			 "in assignment (" HOST_WIDE_INT_PRINT_DEC "/"
+			 HOST_WIDE_INT_PRINT_DEC ") at %L",
 			 llen, rlen, &code->loc);
     }
 
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 3e5abd4..1f6520c 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -275,7 +275,7 @@ init_result_expr (gfc_expr *e, int init, gfc_expr *array)
   else if (e && e->expr_type == EXPR_CONSTANT)
     {
       int i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
-      int length;
+      HOST_WIDE_INT length;
       gfc_char_t *string;
 
       switch (e->ts.type)
@@ -313,14 +313,14 @@ init_result_expr (gfc_expr *e, int init, gfc_expr *array)
 	    if (init == INT_MIN)
 	      {
 		gfc_expr *len = gfc_simplify_len (array, NULL);
-		gfc_extract_int (len, &length);
+		gfc_extract_hwi (len, &length);
 		string = gfc_get_wide_string (length + 1);
 		gfc_wide_memset (string, 0, length);
 	      }
 	    else if (init == INT_MAX)
 	      {
 		gfc_expr *len = gfc_simplify_len (array, NULL);
-		gfc_extract_int (len, &length);
+		gfc_extract_hwi (len, &length);
 		string = gfc_get_wide_string (length + 1);
 		gfc_wide_memset (string, 255, length);
 	      }
@@ -4415,7 +4415,7 @@ gfc_expr *
 gfc_simplify_len_trim (gfc_expr *e, gfc_expr *kind)
 {
   gfc_expr *result;
-  int count, len, i;
+  size_t count, len, i;
   int k = get_kind (BT_INTEGER, kind, "LEN_TRIM", gfc_default_integer_kind);
 
   if (k == -1)
diff --git a/gcc/fortran/target-memory.c b/gcc/fortran/target-memory.c
index c708b17..e445fbe 100644
--- a/gcc/fortran/target-memory.c
+++ b/gcc/fortran/target-memory.c
@@ -216,8 +216,8 @@ encode_logical (int kind, int logical, unsigned char *buffer, size_t buffer_size
 }
 
 
-int
-gfc_encode_character (int kind, gfc_charlen_t length, const gfc_char_t *string,
+size_t
+gfc_encode_character (int kind, size_t length, const gfc_char_t *string,
 		      unsigned char *buffer, size_t buffer_size)
 {
   size_t elsize = size_character (1, kind);
@@ -225,7 +225,7 @@ gfc_encode_character (int kind, gfc_charlen_t length, const gfc_char_t *string,
 
   gcc_assert (buffer_size >= size_character (length, kind));
 
-  for (size_t i = 0; i < (size_t) length; i++)
+  for (size_t i = 0; i < length; i++)
     native_encode_expr (build_int_cst (type, string[i]), &buffer[i*elsize],
 			elsize);
 
@@ -318,11 +318,11 @@ gfc_target_encode_expr (gfc_expr *source, unsigned char *buffer,
 				     buffer, buffer_size);
       else
 	{
-	  int start, end;
+	  HOST_WIDE_INT start, end;
 
 	  gcc_assert (source->expr_type == EXPR_SUBSTRING);
-	  gfc_extract_int (source->ref->u.ss.start, &start);
-	  gfc_extract_int (source->ref->u.ss.end, &end);
+	  gfc_extract_hwi (source->ref->u.ss.start, &start);
+	  gfc_extract_hwi (source->ref->u.ss.end, &end);
 	  return gfc_encode_character (source->ts.kind, MAX(end - start + 1, 0),
 				       &source->value.character.string[start-1],
 				       buffer, buffer_size);
@@ -348,22 +348,21 @@ gfc_target_encode_expr (gfc_expr *source, unsigned char *buffer,
 }
 
 
-static int
+static size_t
 interpret_array (unsigned char *buffer, size_t buffer_size, gfc_expr *result)
 {
   gfc_constructor_base base = NULL;
-  int array_size = 1;
-  int i;
-  int ptr = 0;
+  size_t array_size = 1;
+  size_t ptr = 0;
 
   /* Calculate array size from its shape and rank.  */
   gcc_assert (result->rank > 0 && result->shape);
 
-  for (i = 0; i < result->rank; i++)
-    array_size *= (int)mpz_get_ui (result->shape[i]);
+  for (int i = 0; i < result->rank; i++)
+    array_size *= mpz_get_ui (result->shape[i]);
 
   /* Iterate over array elements, producing constructors.  */
-  for (i = 0; i < array_size; i++)
+  for (size_t i = 0; i < array_size; i++)
     {
       gfc_expr *e = gfc_get_constant_expr (result->ts.type, result->ts.kind,
 					   &result->where);
@@ -433,7 +432,7 @@ gfc_interpret_logical (int kind, unsigned char *buffer, size_t buffer_size,
 }
 
 
-int
+size_t
 gfc_interpret_character (unsigned char *buffer, size_t buffer_size,
 			 gfc_expr *result)
 {
@@ -452,7 +451,7 @@ gfc_interpret_character (unsigned char *buffer, size_t buffer_size,
   else
     {
       mpz_t integer;
-      unsigned bytes = size_character (1, result->ts.kind);
+      size_t bytes = size_character (1, result->ts.kind);
       mpz_init (integer);
       gcc_assert (bytes <= sizeof (unsigned long));
 
@@ -556,7 +555,7 @@ gfc_interpret_derived (unsigned char *buffer, size_t buffer_size, gfc_expr *resu
 
 
 /* Read a binary buffer to a constant expression.  */
-int
+size_t
 gfc_target_interpret_expr (unsigned char *buffer, size_t buffer_size,
 			   gfc_expr *result, bool convert_widechar)
 {
diff --git a/gcc/fortran/target-memory.h b/gcc/fortran/target-memory.h
index a9141a6..8f25899 100644
--- a/gcc/fortran/target-memory.h
+++ b/gcc/fortran/target-memory.h
@@ -28,7 +28,7 @@ size_t gfc_element_size (gfc_expr *);
 size_t gfc_target_expr_size (gfc_expr *);
 
 /* Write a constant expression in binary form to a target buffer.  */
-int gfc_encode_character (int, gfc_charlen_t, const gfc_char_t *, unsigned char *,
+size_t gfc_encode_character (int, size_t, const gfc_char_t *, unsigned char *,
 			  size_t);
 unsigned HOST_WIDE_INT gfc_target_encode_expr (gfc_expr *, unsigned char *,
 					       size_t);
@@ -39,9 +39,9 @@ int gfc_interpret_integer (int, unsigned char *, size_t, mpz_t);
 int gfc_interpret_float (int, unsigned char *, size_t, mpfr_t);
 int gfc_interpret_complex (int, unsigned char *, size_t, mpc_t);
 int gfc_interpret_logical (int, unsigned char *, size_t, int *);
-int gfc_interpret_character (unsigned char *, size_t, gfc_expr *);
+size_t gfc_interpret_character (unsigned char *, size_t, gfc_expr *);
 int gfc_interpret_derived (unsigned char *, size_t, gfc_expr *);
-int gfc_target_interpret_expr (unsigned char *, size_t, gfc_expr *, bool);
+size_t gfc_target_interpret_expr (unsigned char *, size_t, gfc_expr *, bool);
 
 /* Merge overlapping equivalence initializers for trans-common.c. */
 size_t gfc_merge_initializers (gfc_typespec, gfc_expr *, locus *,
diff --git a/gcc/fortran/trans-const.c b/gcc/fortran/trans-const.c
index 028e6d2..4b6adbf 100644
--- a/gcc/fortran/trans-const.c
+++ b/gcc/fortran/trans-const.c
@@ -69,7 +69,7 @@ gfc_build_const (tree type, tree intval)
 /* Build a string constant with C char type.  */
 
 tree
-gfc_build_string_const (int length, const char *s)
+gfc_build_string_const (size_t length, const char *s)
 {
   tree str;
   tree len;
@@ -89,7 +89,7 @@ gfc_build_string_const (int length, const char *s)
    non-default character kinds.  */
 
 tree
-gfc_build_wide_string_const (int kind, int length, const gfc_char_t *string)
+gfc_build_wide_string_const (int kind, size_t length, const gfc_char_t *string)
 {
   int i;
   tree str, len;
diff --git a/gcc/fortran/trans-const.h b/gcc/fortran/trans-const.h
index 39693bb..4f5a520 100644
--- a/gcc/fortran/trans-const.h
+++ b/gcc/fortran/trans-const.h
@@ -44,8 +44,8 @@ tree gfc_conv_constant_to_tree (gfc_expr *);
    structures.  Also sets the length of CHARACTER strings in the gfc_se.  */
 void gfc_conv_constant (gfc_se *, gfc_expr *);
 
-tree gfc_build_string_const (int, const char *);
-tree gfc_build_wide_string_const (int, int, const gfc_char_t *);
+tree gfc_build_string_const (size_t, const char *);
+tree gfc_build_wide_string_const (int, size_t, const gfc_char_t *);
 tree gfc_build_cstring_const (const char *);
 tree gfc_build_localized_cstring_const (const char *);
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-21 19:49               ` Janne Blomqvist
@ 2018-01-21 19:58                 ` Steve Kargl
  0 siblings, 0 replies; 13+ messages in thread
From: Steve Kargl @ 2018-01-21 19:58 UTC (permalink / raw)
  To: Janne Blomqvist
  Cc: Dominique d'Humières, Joseph Myers, gfortran, gcc-patches

On Sun, Jan 21, 2018 at 09:49:47PM +0200, Janne Blomqvist wrote:
> On Sun, Jan 21, 2018 at 8:30 PM, Steve Kargl
> <sgk@troutmask.apl.washington.edu> wrote:
> > On Sun, Jan 21, 2018 at 01:11:28PM +0200, Janne Blomqvist wrote:
> >> PING
> >>
> >
> > Janne,
> >
> > I didn't see anything wrong with the patch.  Other than Dominiq's
> > concerns about slow downs with -m32, I think it is fine.
> 
> Thanks, I guess that's an Ok? I'll rebase on the latest trunk, run my
> tests again and commit.

Yes, it's an ok from me.

> > I do wonder why you use gfc_charlen_t in some place and
> > HOST_WIDE_INT in other places as gfortran.h defines
> > gfc_charlen_t to be HOST_WIDE_INT.
> 
> gfc_extract_hwi takes a pointer to a HOST_WIDE_INT, so if we at some
> point change the typedef for gfc_charlen_t that would break. Also,
> similarly, gfc_mpz_get_hwi returns a HOST_WIDE_INT so I thought it's
> better to use that type than converting to some other which might or
> might not be the same. Similarly, for things like array indices in
> loops etc. I preferred size_t.

Thanks for the explanation.  

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-21 18:30             ` Steve Kargl
@ 2018-01-21 19:49               ` Janne Blomqvist
  2018-01-21 19:58                 ` Steve Kargl
  0 siblings, 1 reply; 13+ messages in thread
From: Janne Blomqvist @ 2018-01-21 19:49 UTC (permalink / raw)
  To: Steve Kargl
  Cc: Dominique d'Humières, Joseph Myers, gfortran, gcc-patches

On Sun, Jan 21, 2018 at 8:30 PM, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Sun, Jan 21, 2018 at 01:11:28PM +0200, Janne Blomqvist wrote:
>> PING
>>
>
> Janne,
>
> I didn't see anything wrong with the patch.  Other than Dominiq's
> concerns about slow downs with -m32, I think it is fine.

Thanks, I guess that's an Ok? I'll rebase on the latest trunk, run my
tests again and commit.

I think those issues Dominique mentioned are due to wraparound with
the old code, so now it's at least correct even if slow.

> I do wonder why you use gfc_charlen_t in some place and
> HOST_WIDE_INT in other places as gfortran.h defines
> gfc_charlen_t to be HOST_WIDE_INT.

gfc_extract_hwi takes a pointer to a HOST_WIDE_INT, so if we at some
point change the typedef for gfc_charlen_t that would break. Also,
similarly, gfc_mpz_get_hwi returns a HOST_WIDE_INT so I thought it's
better to use that type than converting to some other which might or
might not be the same. Similarly, for things like array indices in
loops etc. I preferred size_t.


-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-21 11:11           ` Janne Blomqvist
  2018-01-21 14:04             ` Dominique d'Humières
@ 2018-01-21 18:30             ` Steve Kargl
  2018-01-21 19:49               ` Janne Blomqvist
  1 sibling, 1 reply; 13+ messages in thread
From: Steve Kargl @ 2018-01-21 18:30 UTC (permalink / raw)
  To: Janne Blomqvist
  Cc: Dominique d'Humières, Joseph Myers, gfortran, gcc-patches

On Sun, Jan 21, 2018 at 01:11:28PM +0200, Janne Blomqvist wrote:
> PING
> 

Janne,

I didn't see anything wrong with the patch.  Other than Dominiq's
concerns about slow downs with -m32, I think it is fine.

I do wonder why you use gfc_charlen_t in some place and 
HOST_WIDE_INT in other places as gfortran.h defines
gfc_charlen_t to be HOST_WIDE_INT. 

-- 
Steve

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-21 11:11           ` Janne Blomqvist
@ 2018-01-21 14:04             ` Dominique d'Humières
  2018-01-21 18:30             ` Steve Kargl
  1 sibling, 0 replies; 13+ messages in thread
From: Dominique d'Humières @ 2018-01-21 14:04 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Joseph Myers, gfortran, gcc-patches

I use x86_64-apple-darwin17 and I run the test with -m32. Without the patch, a plain compilation leads to four errors and a timing

0.011u 0.008s 0:00.02 50.0%	0+0k 0+0io 13pf+0w

With the patch I get the four errors plus "Result of LEN overflows its kind » and a timing much slower

12.454u 21.185s 0:35.29 95.2%	0+0k 0+0io 955pf+0w

Dominique

> Le 21 janv. 2018 à 12:11, Janne Blomqvist <blomqvist.janne@gmail.com> a écrit :
> 
> PING
> 
> On Sun, Jan 14, 2018 at 2:33 PM, Janne Blomqvist
> <blomqvist.janne@gmail.com> wrote:
>> On Sun, Jan 14, 2018 at 12:45 PM, Janne Blomqvist
>> <blomqvist.janne@gmail.com> wrote:
>>> On Sat, Jan 13, 2018 at 7:35 PM, Dominique d'Humières
>>> <dominiq@tournesol.lps.ens.fr> wrote:
>>>> I have finally bootstrapped gfortran with the two patches applied and the spurious warnings with -Wall are now gone (limited testing), but I see a regression for gfortran.dg/string_1.f90 due to an additional error
>>>> 
>>>> /opt/gcc/_clean/gcc/testsuite/gfortran.dg/string_1.f90:13:15:
>>>> 
>>>>   print *, len(s)
>>>>               1
>>>> Error: Result of LEN overflows its kind at (1)
>>>> 
>>>> No idea why this was not emitted without the patch.
>>> 
>>> Thanks for testing, I'll look into this. Was it on a 32 or 64-bit target?
>> 
>> I can't recreate this on i686-pc-linux-gnu. What host/target are you
>> using exactly, is it part of the normal testsuite run or do you
>> compile it with some special options?
>> 
>> In any case, that line isn't particularly relevant to what the
>> testcase is testing, so it could be removed completely, or by
>> specifying kind=8 to len().
>> 
>> 
>> 
>> 
>> --
>> Janne Blomqvist
> 
> 
> 
> -- 
> Janne Blomqvist

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-14 12:33         ` Janne Blomqvist
@ 2018-01-21 11:11           ` Janne Blomqvist
  2018-01-21 14:04             ` Dominique d'Humières
  2018-01-21 18:30             ` Steve Kargl
  0 siblings, 2 replies; 13+ messages in thread
From: Janne Blomqvist @ 2018-01-21 11:11 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: Joseph Myers, gfortran, gcc-patches

PING

On Sun, Jan 14, 2018 at 2:33 PM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> On Sun, Jan 14, 2018 at 12:45 PM, Janne Blomqvist
> <blomqvist.janne@gmail.com> wrote:
>> On Sat, Jan 13, 2018 at 7:35 PM, Dominique d'Humières
>> <dominiq@tournesol.lps.ens.fr> wrote:
>>> I have finally bootstrapped gfortran with the two patches applied and the spurious warnings with -Wall are now gone (limited testing), but I see a regression for gfortran.dg/string_1.f90 due to an additional error
>>>
>>> /opt/gcc/_clean/gcc/testsuite/gfortran.dg/string_1.f90:13:15:
>>>
>>>    print *, len(s)
>>>                1
>>> Error: Result of LEN overflows its kind at (1)
>>>
>>> No idea why this was not emitted without the patch.
>>
>> Thanks for testing, I'll look into this. Was it on a 32 or 64-bit target?
>
> I can't recreate this on i686-pc-linux-gnu. What host/target are you
> using exactly, is it part of the normal testsuite run or do you
> compile it with some special options?
>
> In any case, that line isn't particularly relevant to what the
> testcase is testing, so it could be removed completely, or by
> specifying kind=8 to len().
>
>
>
>
> --
> Janne Blomqvist



-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-14 10:45       ` Janne Blomqvist
  2018-01-14 10:55         ` Thomas Koenig
@ 2018-01-14 12:33         ` Janne Blomqvist
  2018-01-21 11:11           ` Janne Blomqvist
  1 sibling, 1 reply; 13+ messages in thread
From: Janne Blomqvist @ 2018-01-14 12:33 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: Joseph Myers, gfortran, gcc-patches

On Sun, Jan 14, 2018 at 12:45 PM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> On Sat, Jan 13, 2018 at 7:35 PM, Dominique d'Humières
> <dominiq@tournesol.lps.ens.fr> wrote:
>> I have finally bootstrapped gfortran with the two patches applied and the spurious warnings with -Wall are now gone (limited testing), but I see a regression for gfortran.dg/string_1.f90 due to an additional error
>>
>> /opt/gcc/_clean/gcc/testsuite/gfortran.dg/string_1.f90:13:15:
>>
>>    print *, len(s)
>>                1
>> Error: Result of LEN overflows its kind at (1)
>>
>> No idea why this was not emitted without the patch.
>
> Thanks for testing, I'll look into this. Was it on a 32 or 64-bit target?

I can't recreate this on i686-pc-linux-gnu. What host/target are you
using exactly, is it part of the normal testsuite run or do you
compile it with some special options?

In any case, that line isn't particularly relevant to what the
testcase is testing, so it could be removed completely, or by
specifying kind=8 to len().




-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-14 10:45       ` Janne Blomqvist
@ 2018-01-14 10:55         ` Thomas Koenig
  2018-01-14 12:33         ` Janne Blomqvist
  1 sibling, 0 replies; 13+ messages in thread
From: Thomas Koenig @ 2018-01-14 10:55 UTC (permalink / raw)
  To: Janne Blomqvist, Dominique d'Humières
  Cc: Joseph Myers, gfortran, gcc-patches

Am 14.01.2018 um 11:45 schrieb Janne Blomqvist:
>> I have tried to use %wp, but it didn’t work:
>>
>> ../../work/gcc/fortran/decl.c: In function 'void gfc_set_constant_character_len(gfc_charlen_t, gfc_expr*, gfc_charlen_t)':
>> ../../work/gcc/fortran/decl.c:1567:5: error: unknown conversion type character 'w' in format [-Werror=format=]
>>       "CHARACTER expression at %L is being truncated "
>>       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> gfortran diagnostics stuff, as it seems %wd is used in the middle end.
> Anyway, that's stage1 stuff IMHO.

I'd suggest using %ld and casting the value to long int, or %lld and
casting to long long int, at least for the time being.

Regards

	Thomas

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-13 17:35     ` Dominique d'Humières
@ 2018-01-14 10:45       ` Janne Blomqvist
  2018-01-14 10:55         ` Thomas Koenig
  2018-01-14 12:33         ` Janne Blomqvist
  0 siblings, 2 replies; 13+ messages in thread
From: Janne Blomqvist @ 2018-01-14 10:45 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: Joseph Myers, gfortran, gcc-patches

On Sat, Jan 13, 2018 at 7:35 PM, Dominique d'Humières
<dominiq@tournesol.lps.ens.fr> wrote:
> I have finally bootstrapped gfortran with the two patches applied and the spurious warnings with -Wall are now gone (limited testing), but I see a regression for gfortran.dg/string_1.f90 due to an additional error
>
> /opt/gcc/_clean/gcc/testsuite/gfortran.dg/string_1.f90:13:15:
>
>    print *, len(s)
>                1
> Error: Result of LEN overflows its kind at (1)
>
> No idea why this was not emitted without the patch.

Thanks for testing, I'll look into this. Was it on a 32 or 64-bit target?

(I suspect the issue could be that the 32-bit truncated value fits in
[0,INT_MAX] and hence no problem is detected, but I'll have to look
into it further to say something definite).

>> Le 12 janv. 2018 à 21:43, Joseph Myers <joseph@codesourcery.com> a écrit :
>>
>> On Fri, 12 Jan 2018, Janne Blomqvist wrote:
>>
>>> (I don't know why HOST_WIDE_INT_PRINT_DEC doesn't work with the
>>> diagnostics machinery on darwin, but IMHO at this point it's too late
>>
>> HOST_WIDE_INT_PRINT_DEC is a host-specific printf format; for example, it
>> might use %I64d on Windows host or %lld elsewhere.  The formats used in
>> diagnostic functions must *not* be host-specific or use macros anywhere in
>> them at all, because that won't work with translation.  Diagnostic
>> functions have their own host-independent formats; %wd is the correct
>> format for HOST_WIDE_INT in diagnostic functions.
>>
>> --
>> Joseph S. Myers
>> joseph@codesourcery.com
>
> I have tried to use %wp, but it didn’t work:
>
> ../../work/gcc/fortran/decl.c: In function 'void gfc_set_constant_character_len(gfc_charlen_t, gfc_expr*, gfc_charlen_t)':
> ../../work/gcc/fortran/decl.c:1567:5: error: unknown conversion type character 'w' in format [-Werror=format=]
>      "CHARACTER expression at %L is being truncated "
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>      "(%wd/%wd)", &expr->where,
>      ~~~~~~~~~~~
> ../../work/gcc/fortran/decl.c:1567:5: error: unknown conversion type character 'w' in format [-Werror=format=]
> ../../work/gcc/fortran/decl.c:1567:5: error: too many arguments for format [-Werror=format-extra-args]
> ../../work/gcc/fortran/decl.c:1575:17: error: unknown conversion type character 'w' in format [-Werror=format=]
>   gfc_error_now ("The CHARACTER elements of the array constructor "
>                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>           "at %L must have the same length (%wd/%wd)",
>           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../../work/gcc/fortran/decl.c:1575:17: error: unknown conversion type character 'w' in format [-Werror=format=]
> ../../work/gcc/fortran/decl.c:1575:17: error: too many arguments for format [-Werror=format-extra-args]

Yes, same for the on x86-64 Linux. Might be something weird on the
gfortran diagnostics stuff, as it seems %wd is used in the middle end.
Anyway, that's stage1 stuff IMHO.



-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-12 20:43   ` Joseph Myers
@ 2018-01-13 17:35     ` Dominique d'Humières
  2018-01-14 10:45       ` Janne Blomqvist
  0 siblings, 1 reply; 13+ messages in thread
From: Dominique d'Humières @ 2018-01-13 17:35 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Joseph Myers, gfortran, gcc-patches

I have finally bootstrapped gfortran with the two patches applied and the spurious warnings with -Wall are now gone (limited testing), but I see a regression for gfortran.dg/string_1.f90 due to an additional error

/opt/gcc/_clean/gcc/testsuite/gfortran.dg/string_1.f90:13:15:

   print *, len(s)
               1
Error: Result of LEN overflows its kind at (1)

No idea why this was not emitted without the patch.

> Le 12 janv. 2018 à 21:43, Joseph Myers <joseph@codesourcery.com> a écrit :
> 
> On Fri, 12 Jan 2018, Janne Blomqvist wrote:
> 
>> (I don't know why HOST_WIDE_INT_PRINT_DEC doesn't work with the
>> diagnostics machinery on darwin, but IMHO at this point it's too late
> 
> HOST_WIDE_INT_PRINT_DEC is a host-specific printf format; for example, it 
> might use %I64d on Windows host or %lld elsewhere.  The formats used in 
> diagnostic functions must *not* be host-specific or use macros anywhere in 
> them at all, because that won't work with translation.  Diagnostic 
> functions have their own host-independent formats; %wd is the correct 
> format for HOST_WIDE_INT in diagnostic functions.
> 
> -- 
> Joseph S. Myers
> joseph@codesourcery.com

I have tried to use %wp, but it didn’t work:

../../work/gcc/fortran/decl.c: In function 'void gfc_set_constant_character_len(gfc_charlen_t, gfc_expr*, gfc_charlen_t)':
../../work/gcc/fortran/decl.c:1567:5: error: unknown conversion type character 'w' in format [-Werror=format=]
     "CHARACTER expression at %L is being truncated "
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     "(%wd/%wd)", &expr->where,
     ~~~~~~~~~~~
../../work/gcc/fortran/decl.c:1567:5: error: unknown conversion type character 'w' in format [-Werror=format=]
../../work/gcc/fortran/decl.c:1567:5: error: too many arguments for format [-Werror=format-extra-args]
../../work/gcc/fortran/decl.c:1575:17: error: unknown conversion type character 'w' in format [-Werror=format=]
  gfc_error_now ("The CHARACTER elements of the array constructor "
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          "at %L must have the same length (%wd/%wd)",
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../work/gcc/fortran/decl.c:1575:17: error: unknown conversion type character 'w' in format [-Werror=format=]
../../work/gcc/fortran/decl.c:1575:17: error: too many arguments for format [-Werror=format-extra-args]

Dominique


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-12 19:57 ` Janne Blomqvist
@ 2018-01-12 20:43   ` Joseph Myers
  2018-01-13 17:35     ` Dominique d'Humières
  0 siblings, 1 reply; 13+ messages in thread
From: Joseph Myers @ 2018-01-12 20:43 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Dominique d'Humières, gfortran, gcc-patches

On Fri, 12 Jan 2018, Janne Blomqvist wrote:

> (I don't know why HOST_WIDE_INT_PRINT_DEC doesn't work with the
> diagnostics machinery on darwin, but IMHO at this point it's too late

HOST_WIDE_INT_PRINT_DEC is a host-specific printf format; for example, it 
might use %I64d on Windows host or %lld elsewhere.  The formats used in 
diagnostic functions must *not* be host-specific or use macros anywhere in 
them at all, because that won't work with translation.  Diagnostic 
functions have their own host-independent formats; %wd is the correct 
format for HOST_WIDE_INT in diagnostic functions.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
  2018-01-10 13:35 Dominique d'Humières
@ 2018-01-12 19:57 ` Janne Blomqvist
  2018-01-12 20:43   ` Joseph Myers
  0 siblings, 1 reply; 13+ messages in thread
From: Janne Blomqvist @ 2018-01-12 19:57 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

On Wed, Jan 10, 2018 at 3:35 PM, Dominique d'Humières
<dominiq@tournesol.lps.ens.fr> wrote:
> Hi Janne,
>
> With this patch, bootstrap fails with
>
> ../../work/gcc/fortran/array.c: In function 'bool gfc_resolve_character_array_constructor(gfc_expr*)':
> ../../work/gcc/fortran/array.c:2062:36: error: unknown conversion type character 'l' in format [-Werror=format=]
>      current_length, &p->expr->where);
>                                     ^
> ../../work/gcc/fortran/array.c:2062:36: error: unknown conversion type character 'l' in format [-Werror=format=]
> ../../work/gcc/fortran/array.c:2062:36: error: format '%L' expects argument of type 'locus*', but argument 2 has type 'long long int' [-Werror=format]
> ../../work/gcc/fortran/array.c:2062:36: error: too many arguments for format [-Werror=format-extra-args]
>
> Note that trying to only update I saw the same problem for data.c:179 and decl.c:1570/1580.

Please try the attached patch on top of the original.

Ok for trunk with that change?

(I don't know why HOST_WIDE_INT_PRINT_DEC doesn't work with the
diagnostics machinery on darwin, but IMHO at this point it's too late
to do surgery there for the GCC-8 release. So I suggest the attached
patch, and then at some future stage1 someone with an interest in
win64 or crosscompiling from a 32-bit host to a 64-bit target can look
into the issue.)



-- 
Janne Blomqvist

[-- Attachment #2: long.diff --]
[-- Type: text/plain, Size: 3066 bytes --]

diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index ed5fdb2..93deb0d 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -2019,10 +2019,9 @@ got_charlen:
 	    found_length = current_length;
 	  else if (found_length != current_length)
 	    {
-	      gfc_error ("Different CHARACTER lengths ("
-			 HOST_WIDE_INT_PRINT_DEC "/" HOST_WIDE_INT_PRINT_DEC
-			 ") in array constructor at %L", found_length,
-			 current_length, &p->expr->where);
+	      gfc_error ("Different CHARACTER lengths (%ld/%ld) in array"
+			 " constructor at %L", (long) found_length,
+			 (long) current_length, &p->expr->where);
 	      return false;
 	    }
 
diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 45bb5c0..fdd7052 100644
--- a/gcc/fortran/data.c
+++ b/gcc/fortran/data.c
@@ -174,9 +174,8 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts,
       else
 	{
 	  gfc_warning_now (0, "Initialization string at %L was truncated to "
-			   "fit the variable (" HOST_WIDE_INT_PRINT_DEC "/"
-			   HOST_WIDE_INT_PRINT_DEC ")", &rvalue->where,
-			   tlen, len);
+			   "fit the variable (%ld/%ld)", &rvalue->where,
+			   (long) tlen, (long) len);
 	  len = tlen;
 	}
     }
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 14c8072..6adfbde 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1565,19 +1565,17 @@ gfc_set_constant_character_len (gfc_charlen_t len, gfc_expr *expr,
       if (warn_character_truncation && slen > len)
 	gfc_warning_now (OPT_Wcharacter_truncation,
 			 "CHARACTER expression at %L is being truncated "
-			 "(" HOST_WIDE_INT_PRINT_DEC "/"
-			 HOST_WIDE_INT_PRINT_DEC ")", &expr->where,
-			 (HOST_WIDE_INT) slen, (HOST_WIDE_INT) len);
+			 "(%ld/%ld)", &expr->where,
+			 (long) slen, (long) len);
 
       /* Apply the standard by 'hand' otherwise it gets cleared for
 	 initializers.  */
       if (check_len != -1 && slen != check_len
           && !(gfc_option.allow_std & GFC_STD_GNU))
 	gfc_error_now ("The CHARACTER elements of the array constructor "
-		       "at %L must have the same length ("
-		       HOST_WIDE_INT_PRINT_DEC "/" HOST_WIDE_INT_PRINT_DEC ")",
-		       &expr->where, (HOST_WIDE_INT) slen,
-		       (HOST_WIDE_INT) check_len);
+		       "at %L must have the same length (%ld/%ld)",
+		       &expr->where, (long) slen,
+		       (long) check_len);
 
       s[len] = '\0';
       free (expr->value.character.string);
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index d32fe96..efa5b26 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -10218,9 +10218,8 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
       if (rlen && llen && rlen > llen)
 	gfc_warning_now (OPT_Wcharacter_truncation,
 			 "CHARACTER expression will be truncated "
-			 "in assignment (" HOST_WIDE_INT_PRINT_DEC "/"
-			 HOST_WIDE_INT_PRINT_DEC ") at %L",
-			 llen, rlen, &code->loc);
+			 "in assignment (%ld/%ld) at %L",
+			 (long) llen, (long) rlen, &code->loc);
     }
 
   /* Ensure that a vector index expression for the lvalue is evaluated

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] PR 78534, 83704 Large character lengths
@ 2018-01-10 13:35 Dominique d'Humières
  2018-01-12 19:57 ` Janne Blomqvist
  0 siblings, 1 reply; 13+ messages in thread
From: Dominique d'Humières @ 2018-01-10 13:35 UTC (permalink / raw)
  To: jb at gcc dot gnu.org; +Cc: gfortran, gcc-patches

Hi Janne,

With this patch, bootstrap fails with

../../work/gcc/fortran/array.c: In function 'bool gfc_resolve_character_array_constructor(gfc_expr*)':
../../work/gcc/fortran/array.c:2062:36: error: unknown conversion type character 'l' in format [-Werror=format=]
     current_length, &p->expr->where);
                                    ^
../../work/gcc/fortran/array.c:2062:36: error: unknown conversion type character 'l' in format [-Werror=format=]
../../work/gcc/fortran/array.c:2062:36: error: format '%L' expects argument of type 'locus*', but argument 2 has type 'long long int' [-Werror=format]
../../work/gcc/fortran/array.c:2062:36: error: too many arguments for format [-Werror=format-extra-args]

Note that trying to only update I saw the same problem for data.c:179 and decl.c:1570/1580.

TIA

Dominique

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-01-21 19:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 12:07 [PATCH] PR 78534, 83704 Large character lengths Janne Blomqvist
2018-01-10 13:35 Dominique d'Humières
2018-01-12 19:57 ` Janne Blomqvist
2018-01-12 20:43   ` Joseph Myers
2018-01-13 17:35     ` Dominique d'Humières
2018-01-14 10:45       ` Janne Blomqvist
2018-01-14 10:55         ` Thomas Koenig
2018-01-14 12:33         ` Janne Blomqvist
2018-01-21 11:11           ` Janne Blomqvist
2018-01-21 14:04             ` Dominique d'Humières
2018-01-21 18:30             ` Steve Kargl
2018-01-21 19:49               ` Janne Blomqvist
2018-01-21 19:58                 ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).