Blame SOURCES/0004-Allow-CHARACTER-literals-in-assignments-and-data-sta.patch

9805c9
From c1d6c81730ffda61eff8fccf4d0c7efa3ae6fd8d Mon Sep 17 00:00:00 2001
9805c9
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
Date: Thu, 4 Feb 2016 17:18:30 +0000
9805c9
Subject: [PATCH 04/16] Allow CHARACTER literals in assignments and data
9805c9
 statements
9805c9
9805c9
Warnings are raised when this happens.
9805c9
9805c9
Enable using -fdec-char-as-int or -fdec
9805c9
---
9805c9
 gcc/fortran/arith.c                                | 96 +++++++++++++++++++++-
9805c9
 gcc/fortran/arith.h                                |  4 +
9805c9
 gcc/fortran/expr.c                                 |  5 ++
9805c9
 gcc/fortran/intrinsic.c                            | 32 +++++++-
9805c9
 gcc/fortran/lang.opt                               |  5 ++
9805c9
 gcc/fortran/options.c                              |  1 +
9805c9
 gcc/fortran/resolve.c                              | 11 ++-
9805c9
 gcc/fortran/simplify.c                             | 29 ++++++-
9805c9
 gcc/fortran/trans-const.c                          |  3 +-
9805c9
 .../dec_char_conversion_in_assignment_1.f90        | 61 ++++++++++++++
9805c9
 .../dec_char_conversion_in_assignment_2.f90        | 61 ++++++++++++++
9805c9
 .../dec_char_conversion_in_assignment_3.f90        | 61 ++++++++++++++
9805c9
 .../gfortran.dg/dec_char_conversion_in_data_1.f90  | 69 ++++++++++++++++
9805c9
 .../gfortran.dg/dec_char_conversion_in_data_2.f90  | 69 ++++++++++++++++
9805c9
 .../gfortran.dg/dec_char_conversion_in_data_3.f90  | 69 ++++++++++++++++
9805c9
 gcc/testsuite/gfortran.dg/hollerith5.f90           |  5 +-
9805c9
 gcc/testsuite/gfortran.dg/hollerith_legacy.f90     |  2 +-
9805c9
 .../gfortran.dg/no_char_to_int_assign.f90          | 20 +++++
9805c9
 18 files changed, 589 insertions(+), 14 deletions(-)
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_1.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_2.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_3.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_1.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_2.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_3.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/no_char_to_int_assign.f90
9805c9
9805c9
diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c
9805c9
index f2d311c044c..7e6d6dd3bb8 100644
9805c9
--- a/gcc/fortran/arith.c
9805c9
+++ b/gcc/fortran/arith.c
9805c9
@@ -2553,11 +2553,11 @@ hollerith2representation (gfc_expr *result, gfc_expr *src)
9805c9
   src_len = src->representation.length - src->ts.u.pad;
9805c9
   gfc_target_expr_size (result, &result_len);
9805c9
 
9805c9
-  if (src_len > result_len)
9805c9
+  if (src_len > result_len && warn_character_truncation)
9805c9
     {
9805c9
-      gfc_warning (0,
9805c9
-		   "The Hollerith constant at %L is too long to convert to %qs",
9805c9
-		   &src->where, gfc_typename(&result->ts));
9805c9
+      gfc_warning (OPT_Wcharacter_truncation, "The Hollerith constant at %L "
9805c9
+		   "is truncated in conversion to %qs", &src->where,
9805c9
+		   gfc_typename(&result->ts));
9805c9
     }
9805c9
 
9805c9
   result->representation.string = XCNEWVEC (char, result_len + 1);
9805c9
@@ -2572,6 +2572,36 @@ hollerith2representation (gfc_expr *result, gfc_expr *src)
9805c9
 }
9805c9
 
9805c9
 
9805c9
+/* Helper function to set the representation in a character conversion.
9805c9
+   This assumes that the ts.type and ts.kind of the result have already
9805c9
+   been set.  */
9805c9
+
9805c9
+static void
9805c9
+character2representation (gfc_expr *result, gfc_expr *src)
9805c9
+{
9805c9
+  size_t src_len, result_len;
9805c9
+  int i;
9805c9
+  src_len = src->value.character.length;
9805c9
+  gfc_target_expr_size (result, &result_len);
9805c9
+
9805c9
+  if (src_len > result_len && warn_character_truncation)
9805c9
+    gfc_warning (OPT_Wcharacter_truncation, "The character constant at %L is "
9805c9
+		 "is truncated in conversion to %s", &src->where,
9805c9
+		 gfc_typename(&result->ts));
9805c9
+
9805c9
+  result->representation.string = XCNEWVEC (char, result_len + 1);
9805c9
+
9805c9
+  for (i = 0; i < MIN (result_len, src_len); i++)
9805c9
+    result->representation.string[i] = (char) src->value.character.string[i];
9805c9
+
9805c9
+  if (src_len < result_len)
9805c9
+    memset (&result->representation.string[src_len], ' ',
9805c9
+	    result_len - src_len);
9805c9
+
9805c9
+  result->representation.string[result_len] = '\0'; /* For debugger  */
9805c9
+  result->representation.length = result_len;
9805c9
+}
9805c9
+
9805c9
 /* Convert Hollerith to integer. The constant will be padded or truncated.  */
9805c9
 
9805c9
 gfc_expr *
9805c9
@@ -2587,6 +2617,19 @@ gfc_hollerith2int (gfc_expr *src, int kind)
9805c9
   return result;
9805c9
 }
9805c9
 
9805c9
+/* Convert character to integer. The constant will be padded or truncated. */
9805c9
+
9805c9
+gfc_expr *
9805c9
+gfc_character2int (gfc_expr *src, int kind)
9805c9
+{
9805c9
+  gfc_expr *result;
9805c9
+  result = gfc_get_constant_expr (BT_INTEGER, kind, &src->where);
9805c9
+
9805c9
+  character2representation (result, src);
9805c9
+  gfc_interpret_integer (kind, (unsigned char *) result->representation.string,
9805c9
+			 result->representation.length, result->value.integer);
9805c9
+  return result;
9805c9
+}
9805c9
 
9805c9
 /* Convert Hollerith to real. The constant will be padded or truncated.  */
9805c9
 
9805c9
@@ -2603,6 +2646,21 @@ gfc_hollerith2real (gfc_expr *src, int kind)
9805c9
   return result;
9805c9
 }
9805c9
 
9805c9
+/* Convert character to real. The constant will be padded or truncated.  */
9805c9
+
9805c9
+gfc_expr *
9805c9
+gfc_character2real (gfc_expr *src, int kind)
9805c9
+{
9805c9
+  gfc_expr *result;
9805c9
+  result = gfc_get_constant_expr (BT_REAL, kind, &src->where);
9805c9
+
9805c9
+  character2representation (result, src);
9805c9
+  gfc_interpret_float (kind, (unsigned char *) result->representation.string,
9805c9
+		       result->representation.length, result->value.real);
9805c9
+
9805c9
+  return result;
9805c9
+}
9805c9
+
9805c9
 
9805c9
 /* Convert Hollerith to complex. The constant will be padded or truncated.  */
9805c9
 
9805c9
@@ -2619,6 +2677,21 @@ gfc_hollerith2complex (gfc_expr *src, int kind)
9805c9
   return result;
9805c9
 }
9805c9
 
9805c9
+/* Convert character to complex. The constant will be padded or truncated.  */
9805c9
+
9805c9
+gfc_expr *
9805c9
+gfc_character2complex (gfc_expr *src, int kind)
9805c9
+{
9805c9
+  gfc_expr *result;
9805c9
+  result = gfc_get_constant_expr (BT_COMPLEX, kind, &src->where);
9805c9
+
9805c9
+  character2representation (result, src);
9805c9
+  gfc_interpret_complex (kind, (unsigned char *) result->representation.string,
9805c9
+			 result->representation.length, result->value.complex);
9805c9
+
9805c9
+  return result;
9805c9
+}
9805c9
+
9805c9
 
9805c9
 /* Convert Hollerith to character.  */
9805c9
 
9805c9
@@ -2654,3 +2727,18 @@ gfc_hollerith2logical (gfc_expr *src, int kind)
9805c9
 
9805c9
   return result;
9805c9
 }
9805c9
+
9805c9
+/* Convert character to logical. The constant will be padded or truncated.  */
9805c9
+
9805c9
+gfc_expr *
9805c9
+gfc_character2logical (gfc_expr *src, int kind)
9805c9
+{
9805c9
+  gfc_expr *result;
9805c9
+  result = gfc_get_constant_expr (BT_LOGICAL, kind, &src->where);
9805c9
+
9805c9
+  character2representation (result, src);
9805c9
+  gfc_interpret_logical (kind, (unsigned char *) result->representation.string,
9805c9
+			 result->representation.length, &result->value.logical);
9805c9
+
9805c9
+  return result;
9805c9
+}
9805c9
diff --git a/gcc/fortran/arith.h b/gcc/fortran/arith.h
9805c9
index e06c7059885..13ffd8d0b6c 100644
9805c9
--- a/gcc/fortran/arith.h
9805c9
+++ b/gcc/fortran/arith.h
9805c9
@@ -82,7 +82,11 @@ gfc_expr *gfc_hollerith2real (gfc_expr *, int);
9805c9
 gfc_expr *gfc_hollerith2complex (gfc_expr *, int);
9805c9
 gfc_expr *gfc_hollerith2character (gfc_expr *, int);
9805c9
 gfc_expr *gfc_hollerith2logical (gfc_expr *, int);
9805c9
+gfc_expr *gfc_character2int (gfc_expr *, int);
9805c9
+gfc_expr *gfc_character2real (gfc_expr *, int);
9805c9
+gfc_expr *gfc_character2complex (gfc_expr *, int);
9805c9
 gfc_expr *gfc_character2character (gfc_expr *, int);
9805c9
+gfc_expr *gfc_character2logical (gfc_expr *, int);
9805c9
 
9805c9
 #endif /* GFC_ARITH_H  */
9805c9
 
9805c9
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
9805c9
index 474e9ecc401..77600a5f2e8 100644
9805c9
--- a/gcc/fortran/expr.c
9805c9
+++ b/gcc/fortran/expr.c
9805c9
@@ -3695,6 +3695,11 @@ gfc_check_assign (gfc_expr *lvalue, gfc_expr *rvalue, int conform,
9805c9
 	  || rvalue->ts.type == BT_HOLLERITH)
9805c9
 	return true;
9805c9
 
9805c9
+      if (flag_dec_char_conversions && (gfc_numeric_ts (&lvalue->ts)
9805c9
+	  || lvalue->ts.type == BT_LOGICAL)     
9805c9
+          && rvalue->ts.type == BT_CHARACTER)
9805c9
+	return true;
9805c9
+
9805c9
       if (lvalue->ts.type == BT_LOGICAL && rvalue->ts.type == BT_LOGICAL)
9805c9
 	return true;
9805c9
 
9805c9
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
9805c9
index c21fbddd5fb..e94d5d3225f 100644
9805c9
--- a/gcc/fortran/intrinsic.c
9805c9
+++ b/gcc/fortran/intrinsic.c
9805c9
@@ -4017,6 +4017,28 @@ add_conversions (void)
9805c9
 	  add_conv (BT_LOGICAL, gfc_logical_kinds[j].kind,
9805c9
 		    BT_INTEGER, gfc_integer_kinds[i].kind, GFC_STD_LEGACY);
9805c9
 	}
9805c9
+
9805c9
+  /* Flang allows character conversions similar to Hollerith conversions
9805c9
+     - the first characters will be turned into ascii values. */
9805c9
+  if (flag_dec_char_conversions)
9805c9
+    {
9805c9
+      /* Character-Integer conversions.  */
9805c9
+      for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
9805c9
+	add_conv (BT_CHARACTER, gfc_default_character_kind,
9805c9
+		  BT_INTEGER, gfc_integer_kinds[i].kind, GFC_STD_LEGACY);
9805c9
+      /* Character-Real conversions.  */
9805c9
+      for (i = 0; gfc_real_kinds[i].kind != 0; i++)
9805c9
+	add_conv (BT_CHARACTER, gfc_default_character_kind,
9805c9
+		  BT_REAL, gfc_real_kinds[i].kind, GFC_STD_LEGACY);
9805c9
+      /* Character-Complex conversions.  */
9805c9
+      for (i = 0; gfc_real_kinds[i].kind != 0; i++)
9805c9
+	add_conv (BT_CHARACTER, gfc_default_character_kind,
9805c9
+		  BT_COMPLEX, gfc_real_kinds[i].kind, GFC_STD_LEGACY);
9805c9
+      /* Character-Logical conversions.  */
9805c9
+      for (i = 0; gfc_logical_kinds[i].kind != 0; i++)
9805c9
+	add_conv (BT_CHARACTER, gfc_default_character_kind,
9805c9
+		  BT_LOGICAL, gfc_logical_kinds[i].kind, GFC_STD_LEGACY);
9805c9
+    }
9805c9
 }
9805c9
 
9805c9
 
9805c9
@@ -5128,8 +5150,16 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
9805c9
 			     gfc_typename (&from_ts), gfc_typename (ts),
9805c9
 			     &expr->where);
9805c9
 	}
9805c9
+      else if (flag_dec_char_conversions && from_ts.type == BT_CHARACTER
9805c9
+	       && (gfc_numeric_ts (ts) || ts->type == BT_LOGICAL))
9805c9
+	{
9805c9
+	  if (warn_conversion)
9805c9
+	    gfc_warning_now (OPT_Wconversion, "Conversion from %s to %s at %L",
9805c9
+			     gfc_typename (&from_ts), gfc_typename (ts),
9805c9
+			     &expr->where);
9805c9
+	}
9805c9
       else
9805c9
-        gcc_unreachable ();
9805c9
+	gcc_unreachable ();
9805c9
     }
9805c9
 
9805c9
   /* Insert a pre-resolved function call to the right function.  */
9805c9
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
9805c9
index 13a8e9778bb..5746b99b1d4 100644
9805c9
--- a/gcc/fortran/lang.opt
9805c9
+++ b/gcc/fortran/lang.opt
9805c9
@@ -444,6 +444,11 @@ fdec-duplicates
9805c9
 Fortran Var(flag_dec_duplicates)
9805c9
 Allow varibles to be duplicated in the type specification matches.
9805c9
 
9805c9
+fdec-char-conversions
9805c9
+Fortran Var(flag_dec_char_conversions)
9805c9
+Enable the use of character literals in assignments and data statements
9805c9
+for non-character variables.
9805c9
+
9805c9
 fdec-include
9805c9
 Fortran Var(flag_dec_include)
9805c9
 Enable legacy parsing of INCLUDE as statement.
9805c9
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
9805c9
index f93db8b6d7c..e97b1568810 100644
9805c9
--- a/gcc/fortran/options.c
9805c9
+++ b/gcc/fortran/options.c
9805c9
@@ -76,6 +76,7 @@ set_dec_flags (int value)
9805c9
   SET_BITFLAG (flag_dec_include, value, value);
9805c9
   SET_BITFLAG (flag_dec_format_defaults, value, value);
9805c9
   SET_BITFLAG (flag_dec_duplicates, value, value);
9805c9
+  SET_BITFLAG (flag_dec_char_conversions, value, value);
9805c9
 }
9805c9
 
9805c9
 /* Finalize DEC flags.  */
9805c9
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
9805c9
index 32b8d504ff6..43559185481 100644
9805c9
--- a/gcc/fortran/resolve.c
9805c9
+++ b/gcc/fortran/resolve.c
9805c9
@@ -4320,7 +4320,6 @@ bad_op:
9805c9
   return false;
9805c9
 }
9805c9
 
9805c9
-
9805c9
 /************** Array resolution subroutines **************/
9805c9
 
9805c9
 enum compare_result
9805c9
@@ -10498,6 +10497,16 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
9805c9
   lhs = code->expr1;
9805c9
   rhs = code->expr2;
9805c9
 
9805c9
+  if ((gfc_numeric_ts (&lhs->ts) || lhs->ts.type == BT_LOGICAL)
9805c9
+      && rhs->ts.type == BT_CHARACTER
9805c9
+      && rhs->expr_type != EXPR_CONSTANT)
9805c9
+    {
9805c9
+      gfc_error ("Cannot convert CHARACTER into %s at %L",
9805c9
+                 gfc_typename (&lhs->ts),     
9805c9
+                 &rhs->where);
9805c9
+      return false;
9805c9
+    }
9805c9
+
9805c9
   if (rhs->is_boz
9805c9
       && !gfc_notify_std (GFC_STD_GNU, "BOZ literal at %L outside "
9805c9
 			  "a DATA statement and outside INT/REAL/DBLE/CMPLX",
9805c9
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
9805c9
index 6c1f4bd4fce..7d7e3f22f73 100644
9805c9
--- a/gcc/fortran/simplify.c
9805c9
+++ b/gcc/fortran/simplify.c
9805c9
@@ -8457,10 +8457,31 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind)
9805c9
       break;
9805c9
 
9805c9
     case BT_CHARACTER:
9805c9
-      if (type == BT_CHARACTER)
9805c9
-	f = gfc_character2character;
9805c9
-      else
9805c9
-	goto oops;
9805c9
+      switch (type)
9805c9
+	{
9805c9
+	case BT_INTEGER:
9805c9
+	  f = gfc_character2int;
9805c9
+	  break;
9805c9
+
9805c9
+	case BT_REAL:
9805c9
+	  f = gfc_character2real;
9805c9
+	  break;
9805c9
+
9805c9
+	case BT_COMPLEX:
9805c9
+	  f = gfc_character2complex;
9805c9
+	  break;
9805c9
+
9805c9
+	case BT_CHARACTER:
9805c9
+	  f = gfc_character2character;
9805c9
+	  break;
9805c9
+
9805c9
+	case BT_LOGICAL:
9805c9
+	  f = gfc_character2logical;
9805c9
+	  break;
9805c9
+
9805c9
+	default:
9805c9
+	  goto oops;
9805c9
+	}
9805c9
       break;
9805c9
 
9805c9
     default:
9805c9
diff --git a/gcc/fortran/trans-const.c b/gcc/fortran/trans-const.c
9805c9
index 432d12bf168..b155e35cbdd 100644
9805c9
--- a/gcc/fortran/trans-const.c
9805c9
+++ b/gcc/fortran/trans-const.c
9805c9
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
9805c9
 #include "coretypes.h"
9805c9
 #include "tree.h"
9805c9
 #include "gfortran.h"
9805c9
+#include "options.h"
9805c9
 #include "trans.h"
9805c9
 #include "fold-const.h"
9805c9
 #include "stor-layout.h"
9805c9
@@ -330,7 +331,7 @@ gfc_conv_constant_to_tree (gfc_expr * expr)
9805c9
 			gfc_get_int_type (expr->ts.kind),
9805c9
 			gfc_build_string_const (expr->representation.length,
9805c9
 						expr->representation.string));
9805c9
-	  if (!integer_zerop (tmp) && !integer_onep (tmp))
9805c9
+	  if (!integer_zerop (tmp) && !integer_onep (tmp) && warn_surprising)
9805c9
 	    gfc_warning (0, "Assigning value other than 0 or 1 to LOGICAL"
9805c9
 			 " has undefined result at %L", &expr->where);
9805c9
 	  return fold_convert (gfc_get_logical_type (expr->ts.kind), tmp);
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_1.f90 b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_1.f90
9805c9
new file mode 100644
9805c9
index 00000000000..d504f92fbbc
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_1.f90
9805c9
@@ -0,0 +1,61 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec -Wsurprising -Wcharacter-truncation" }
9805c9
+!
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+program test
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  a = '1234'
9805c9
+  b = '1234'
9805c9
+  c = '12341234'
9805c9
+  d = '1234'     ! { dg-warning "undefined result" }
9805c9
+  e = 4h1234
9805c9
+  f = 4h1234
9805c9
+  g = 8h12341234
9805c9
+  h = 4h1234     ! { dg-warning "undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 1
9805c9
+  if (b.ne.f) stop 2
9805c9
+  if (c.ne.g) stop 3
9805c9
+  if (d.neqv.h) stop 4
9805c9
+
9805c9
+  ! padded values
9805c9
+  a = '12'
9805c9
+  b = '12'
9805c9
+  c = '12234'
9805c9
+  d = '124'   ! { dg-warning "undefined result" }
9805c9
+  e = 2h12
9805c9
+  f = 2h12
9805c9
+  g = 5h12234
9805c9
+  h = 3h123   ! { dg-warning "undefined result" }
9805c9
+
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+
9805c9
+  ! truncated values
9805c9
+  a = '123478'       ! { dg-warning "truncated in" }
9805c9
+  b = '123478'       ! { dg-warning "truncated in" }
9805c9
+  c = '12341234987'  ! { dg-warning "truncated in" }
9805c9
+  d = '1234abc'      ! { dg-warning "truncated in|undefined result" }
9805c9
+  e = 6h123478       ! { dg-warning "truncated in" }
9805c9
+  f = 6h123478       ! { dg-warning "truncated in" }
9805c9
+  g = 11h12341234987 ! { dg-warning "truncated in" }
9805c9
+  h = 7h1234abc      ! { dg-warning "truncated in|undefined result" }
9805c9
+
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+
9805c9
+end program
9805c9
+
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_2.f90 b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_2.f90
9805c9
new file mode 100644
9805c9
index 00000000000..737ddc664de
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_2.f90
9805c9
@@ -0,0 +1,61 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec-char-conversions -std=legacy -Wcharacter-truncation -Wsurprising" }
9805c9
+!
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+program test
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  a = '1234'
9805c9
+  b = '1234'
9805c9
+  c = '12341234'
9805c9
+  d = '1234'     ! { dg-warning "undefined result" }
9805c9
+  e = 4h1234
9805c9
+  f = 4h1234
9805c9
+  g = 8h12341234
9805c9
+  h = 4h1234     ! { dg-warning "undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 1
9805c9
+  if (b.ne.f) stop 2
9805c9
+  if (c.ne.g) stop 3
9805c9
+  if (d.neqv.h) stop 4
9805c9
+
9805c9
+  ! padded values
9805c9
+  a = '12'
9805c9
+  b = '12'
9805c9
+  c = '12234'
9805c9
+  d = '124'   ! { dg-warning "undefined result" }
9805c9
+  e = 2h12
9805c9
+  f = 2h12
9805c9
+  g = 5h12234
9805c9
+  h = 3h123   ! { dg-warning "undefined result" }
9805c9
+
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+
9805c9
+  ! truncated values
9805c9
+  a = '123478'       ! { dg-warning "truncated in" }
9805c9
+  b = '123478'       ! { dg-warning "truncated in" }
9805c9
+  c = '12341234987'  ! { dg-warning "truncated in" }
9805c9
+  d = '1234abc'      ! { dg-warning "truncated in|undefined result" }
9805c9
+  e = 6h123478       ! { dg-warning "truncated in" }
9805c9
+  f = 6h123478       ! { dg-warning "truncated in" }
9805c9
+  g = 11h12341234987 ! { dg-warning "truncated in" }
9805c9
+  h = 7h1234abc      ! { dg-warning "truncated in|undefined result" }
9805c9
+
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+
9805c9
+end program
9805c9
+
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_3.f90 b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_3.f90
9805c9
new file mode 100644
9805c9
index 00000000000..0ec494c4a92
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_assignment_3.f90
9805c9
@@ -0,0 +1,61 @@
9805c9
+! { dg-do compile }
9805c9
+! { dg-options "-fdec -fno-dec-char-conversions" }
9805c9
+!
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+program test
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  a = '1234'     ! { dg-error "Cannot convert" }
9805c9
+  b = '1234'     ! { dg-error "Cannot convert" }
9805c9
+  c = '12341234' ! { dg-error "Cannot convert" }
9805c9
+  d = '1234'     ! { dg-error "Cannot convert" }
9805c9
+  e = 4h1234
9805c9
+  f = 4h1234
9805c9
+  g = 8h12341234
9805c9
+  h = 4h1234
9805c9
+  
9805c9
+  if (a.ne.e) stop 1
9805c9
+  if (b.ne.f) stop 2
9805c9
+  if (c.ne.g) stop 3
9805c9
+  if (d.neqv.h) stop 4
9805c9
+
9805c9
+  ! padded values
9805c9
+  a = '12'    ! { dg-error "Cannot convert" }
9805c9
+  b = '12'    ! { dg-error "Cannot convert" }
9805c9
+  c = '12234' ! { dg-error "Cannot convert" }
9805c9
+  d = '124'   ! { dg-error "Cannot convert" }
9805c9
+  e = 2h12
9805c9
+  f = 2h12
9805c9
+  g = 5h12234
9805c9
+  h = 3h123
9805c9
+
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+
9805c9
+  ! truncated values
9805c9
+  a = '123478'       ! { dg-error "Cannot convert" }
9805c9
+  b = '123478'       ! { dg-error "Cannot convert" }
9805c9
+  c = '12341234987'  ! { dg-error "Cannot convert" }
9805c9
+  d = '1234abc'      ! { dg-error "Cannot convert" }
9805c9
+  e = 6h123478       !
9805c9
+  f = 6h123478       !
9805c9
+  g = 11h12341234987 !
9805c9
+  h = 7h1234abc      !
9805c9
+
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+
9805c9
+end program
9805c9
+
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_1.f90 b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_1.f90
9805c9
new file mode 100644
9805c9
index 00000000000..c493be9314b
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_1.f90
9805c9
@@ -0,0 +1,69 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec -Wsurprising" }
9805c9
+!
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+
9805c9
+subroutine normal
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '1234', '1234', '12341234', '1234' / ! { dg-warning "undefined result" }
9805c9
+  data e, f, g, h / 4h1234, 4h1234, 8h12341234, 4h1234 / ! { dg-warning "undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 1
9805c9
+  if (b.ne.f) stop 2
9805c9
+  if (c.ne.g) stop 3
9805c9
+  if (d.neqv.h) stop 4
9805c9
+end subroutine
9805c9
+
9805c9
+subroutine padded
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '12', '12', '12334', '123' / ! { dg-warning "undefined result" }
9805c9
+  data e, f, g, h / 2h12, 2h12, 5h12334, 3h123 / ! { dg-warning "undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+end subroutine
9805c9
+
9805c9
+subroutine truncated
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '123478', '123478', '1234123498', '12345' /  ! { dg-warning "too long|undefined result" }
9805c9
+  data e, f, g, h / 6h123478, 6h123478, 10h1234123498, 5h12345 / ! { dg-warning "too long|undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 9
9805c9
+  if (b.ne.f) stop 10
9805c9
+  if (c.ne.g) stop 11
9805c9
+  if (d.neqv.h) stop 12
9805c9
+end subroutine
9805c9
+
9805c9
+program test
9805c9
+  call normal
9805c9
+  call padded
9805c9
+  call truncated
9805c9
+end program
9805c9
+
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_2.f90 b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_2.f90
9805c9
new file mode 100644
9805c9
index 00000000000..c7d8e241cec
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_2.f90
9805c9
@@ -0,0 +1,69 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec-char-conversions -std=legacy -Wsurprising" }
9805c9
+!
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+
9805c9
+subroutine normal
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '1234', '1234', '12341234', '1234' / ! { dg-warning "undefined result" }
9805c9
+  data e, f, g, h / 4h1234, 4h1234, 8h12341234, 4h1234 / ! { dg-warning "undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 1
9805c9
+  if (b.ne.f) stop 2
9805c9
+  if (c.ne.g) stop 3
9805c9
+  if (d.neqv.h) stop 4
9805c9
+end subroutine
9805c9
+
9805c9
+subroutine padded
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '12', '12', '12334', '123' / ! { dg-warning "undefined result" }
9805c9
+  data e, f, g, h / 2h12, 2h12, 5h12334, 3h123 / ! { dg-warning "undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+end subroutine
9805c9
+
9805c9
+subroutine truncated
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '123478', '123478', '1234123498', '12345' /  ! { dg-warning "too long|undefined result" }
9805c9
+  data e, f, g, h / 6h123478, 6h123478, 10h1234123498, 5h12345 / ! { dg-warning "too long|undefined result" }
9805c9
+  
9805c9
+  if (a.ne.e) stop 9
9805c9
+  if (b.ne.f) stop 10
9805c9
+  if (c.ne.g) stop 11
9805c9
+  if (d.neqv.h) stop 12
9805c9
+end subroutine
9805c9
+
9805c9
+program test
9805c9
+  call normal
9805c9
+  call padded
9805c9
+  call truncated
9805c9
+end program
9805c9
+
9805c9
diff --git a/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_3.f90 b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_3.f90
9805c9
new file mode 100644
9805c9
index 00000000000..e7d084b5ffc
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/dec_char_conversion_in_data_3.f90
9805c9
@@ -0,0 +1,69 @@
9805c9
+! { dg-do compile }
9805c9
+! { dg-options "-fdec -fno-dec-char-conversions" }
9805c9
+!
9805c9
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+
9805c9
+subroutine normal
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '1234', '1234', '12341234', '1234' / ! { dg-error "Incompatible types" }
9805c9
+  data e, f, g, h / 4h1234, 4h1234, 8h12341234, 4h1234 /
9805c9
+  
9805c9
+  if (a.ne.e) stop 1
9805c9
+  if (b.ne.f) stop 2
9805c9
+  if (c.ne.g) stop 3
9805c9
+  if (d.neqv.h) stop 4
9805c9
+end subroutine
9805c9
+
9805c9
+subroutine padded
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '12', '12', '12334', '123' / ! { dg-error "Incompatible types" }
9805c9
+  data e, f, g, h / 2h12, 2h12, 5h12334, 3h123 /
9805c9
+  
9805c9
+  if (a.ne.e) stop 5
9805c9
+  if (b.ne.f) stop 6
9805c9
+  if (c.ne.g) stop 7
9805c9
+  if (d.neqv.h) stop 8
9805c9
+end subroutine
9805c9
+
9805c9
+subroutine truncated
9805c9
+  integer(4) :: a
9805c9
+  real(4) :: b
9805c9
+  complex(4) :: c
9805c9
+  logical(4) :: d
9805c9
+  integer(4) :: e
9805c9
+  real(4) :: f
9805c9
+  complex(4) :: g
9805c9
+  logical(4) :: h
9805c9
+
9805c9
+  data a, b, c, d / '123478', '123478', '1234123498', '12345' /  ! { dg-error "Incompatible types" }
9805c9
+  data e, f, g, h / 6h123478, 6h123478, 10h1234123498, 5h12345 /
9805c9
+  
9805c9
+  if (a.ne.e) stop 9
9805c9
+  if (b.ne.f) stop 10
9805c9
+  if (c.ne.g) stop 11
9805c9
+  if (d.neqv.h) stop 12
9805c9
+end subroutine
9805c9
+
9805c9
+program test
9805c9
+  call normal
9805c9
+  call padded
9805c9
+  call truncated
9805c9
+end program
9805c9
+
9805c9
diff --git a/gcc/testsuite/gfortran.dg/hollerith5.f90 b/gcc/testsuite/gfortran.dg/hollerith5.f90
9805c9
index ebd0a117c4f..d17f9ae40cf 100644
9805c9
--- a/gcc/testsuite/gfortran.dg/hollerith5.f90
9805c9
+++ b/gcc/testsuite/gfortran.dg/hollerith5.f90
9805c9
@@ -1,8 +1,9 @@
9805c9
        ! { dg-do compile }
9805c9
+       ! { dg-options "-Wsurprising" }
9805c9
        implicit none
9805c9
        logical b
9805c9
        b = 4Habcd ! { dg-warning "has undefined result" }
9805c9
        end
9805c9
 
9805c9
-! { dg-warning "Hollerith constant" "const" { target *-*-* } 4 }
9805c9
-! { dg-warning "Conversion" "conversion" { target *-*-* } 4 }
9805c9
+! { dg-warning "Hollerith constant" "const" { target *-*-* } 5 }
9805c9
+! { dg-warning "Conversion" "conversion" { target *-*-* } 5 }
9805c9
diff --git a/gcc/testsuite/gfortran.dg/hollerith_legacy.f90 b/gcc/testsuite/gfortran.dg/hollerith_legacy.f90
9805c9
index c3322498345..9d7e989b552 100644
9805c9
--- a/gcc/testsuite/gfortran.dg/hollerith_legacy.f90
9805c9
+++ b/gcc/testsuite/gfortran.dg/hollerith_legacy.f90
9805c9
@@ -1,5 +1,5 @@
9805c9
 ! { dg-do compile }
9805c9
-! { dg-options "-std=legacy" }
9805c9
+! { dg-options "-std=legacy -Wsurprising" }
9805c9
 ! PR15966, PR18781 & PR16531
9805c9
 implicit none
9805c9
 complex(kind=8) x(2) 
9805c9
diff --git a/gcc/testsuite/gfortran.dg/no_char_to_int_assign.f90 b/gcc/testsuite/gfortran.dg/no_char_to_int_assign.f90
9805c9
new file mode 100644
9805c9
index 00000000000..ccfcc9ae512
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/no_char_to_int_assign.f90
9805c9
@@ -0,0 +1,20 @@
9805c9
+! { dg-do compile }
9805c9
+! { dg-options "-fdec-char-conversions" }
9805c9
+!
9805c9
+! Test character to int conversion in DATA types
9805c9
+!
9805c9
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
9805c9
+!
9805c9
+program test
9805c9
+  integer a
9805c9
+  real b
9805c9
+  complex c
9805c9
+  logical d
9805c9
+  character e
9805c9
+
9805c9
+  e = "A"
9805c9
+  a = e ! { dg-error "Cannot convert" }
9805c9
+  b = e ! { dg-error "Cannot convert" }
9805c9
+  c = e ! { dg-error "Cannot convert" }
9805c9
+  d = e ! { dg-error "Cannot convert" }
9805c9
+end program
9805c9
-- 
9805c9
2.11.0
9805c9