Hello world,

the attached patch creates an unsigned "standard" for the
gfc_option.allow_std field.

One of the main reason why people want UNSIGNED for Fortran is
interfacing for C.

This is a preparation for further work on the ISO_C_BINDING constants.
That, we do via iso-c-binding.def , whose last field is a standard
for the constant to be defined for the standard in question, which is
then checked.  I could try and invent a different method for this,
but I'd rather not.

So, OK for trunk? Other, better ideas?

Best regards

        Thomas
diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc
index 0a6be215825..c6fb0a6de45 100644
--- a/gcc/fortran/intrinsic.cc
+++ b/gcc/fortran/intrinsic.cc
@@ -2264,7 +2264,7 @@ add_functions (void)
   make_generic ("long", GFC_ISYM_LONG, GFC_STD_GNU);
 
   add_sym_2 ("uint", GFC_ISYM_UINT, CLASS_ELEMENTAL, ACTUAL_NO, BT_UNSIGNED,
-	     di, GFC_STD_GNU, gfc_check_uint, gfc_simplify_uint,
+	     di, GFC_STD_UNSIGNED, gfc_check_uint, gfc_simplify_uint,
 	     gfc_resolve_uint, a, BT_REAL, dr, REQUIRED, kind, BT_INTEGER, di,
 	     OPTIONAL);
 
@@ -2966,17 +2966,13 @@ add_functions (void)
 
   make_generic ("selected_int_kind", GFC_ISYM_SI_KIND, GFC_STD_F95);
 
-  if (flag_unsigned)
-    {
-
-      add_sym_1 ("selected_unsigned_kind", GFC_ISYM_SU_KIND,
-		 CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di,
-		 GFC_STD_GNU, gfc_check_selected_int_kind,
-		 gfc_simplify_selected_unsigned_kind, NULL, r, BT_INTEGER, di,
-		 REQUIRED);
+  add_sym_1 ("selected_unsigned_kind", GFC_ISYM_SU_KIND,
+	     CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di,
+	     GFC_STD_UNSIGNED, gfc_check_selected_int_kind,
+	     gfc_simplify_selected_unsigned_kind, NULL, r, BT_INTEGER, di,
+	     REQUIRED);
 
       make_generic ("selected_unsigned_kind", GFC_ISYM_SU_KIND, GFC_STD_GNU);
-    }
 
   add_sym_1 ("selected_logical_kind", GFC_ISYM_SL_KIND, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di,
 	     GFC_STD_F2023, /* it has the same requirements */ gfc_check_selected_int_kind,
@@ -4945,6 +4941,10 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
       symstd_msg = _("for backward compatibility");
       break;
 
+    case GFC_STD_UNSIGNED:
+      symstd_msg = _("unsigned");
+      break;
+
     default:
       gfc_internal_error ("Invalid standard code on intrinsic %qs (%d)",
 			  isym->name, isym->standard);
diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h
index 895629d6f80..773f2a0b049 100644
--- a/gcc/fortran/libgfortran.h
+++ b/gcc/fortran/libgfortran.h
@@ -23,6 +23,8 @@ along with GCC; see the file COPYING3.  If not see
    Nevertheless, some features available in F2018 are prohibited in F2023.
    Please remember to keep those definitions in sync with
    gfortran.texi.  */
+#define GFC_STD_UNSIGNED	(1<<14) /* Not really a standard, but
+					   better for error handling.  */
 #define GFC_STD_F2023_DEL	(1<<13)	/* Prohibited in F2023.  */
 #define GFC_STD_F2023		(1<<12)	/* New in F2023.  */
 #define GFC_STD_F2018_DEL	(1<<11)	/* Deleted in F2018.  */
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index 6f2579ad9de..d998d0e6117 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -539,6 +539,10 @@ gfc_post_options (const char **pfilename)
   else if (gfc_option.allow_std & GFC_STD_F2003)
     lang_hooks.name = "GNU Fortran2003";
 
+  /* Set the unsigned "standard".  */
+  if (flag_unsigned)
+    gfc_option.allow_std |= GFC_STD_UNSIGNED;
+
   return gfc_cpp_preprocess_only ();
 }
 

Reply via email to