]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Introduce GFC_STD_UNSIGNED.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 11 Oct 2024 20:58:51 +0000 (22:58 +0200)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Fri, 11 Oct 2024 21:03:11 +0000 (23:03 +0200)
This 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.

gcc/fortran/ChangeLog:

* intrinsic.cc (add_functions): Convert uint and
selected_unsigned_kind to GFC_STD_UNSIGNED.
(gfc_check_intrinsic_standard): Handle GFC_STD_UNSIGNED.
* libgfortran.h (GFC_STD_UNSIGNED): Add.
* options.cc (gfc_post_options): Set GFC_STD_UNSIGNED
if -funsigned is set.

gcc/fortran/intrinsic.cc
gcc/fortran/libgfortran.h
gcc/fortran/options.cc

index 0a6be2158252de5273fe5cce95e28dfa89d4d70d..c6fb0a6de45a6369199f3a910f2d67db0024d6d4 100644 (file)
@@ -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);
index 895629d6f8015dfe7806d6e5cd4d0596f9f4e62f..773f2a0b049ff4bfcffdb9710d060bbf0c8b67c2 100644 (file)
@@ -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.  */
index 6f2579ad9de5dc0198b2fd1ccd330f5e73ed4c93..d998d0e61170bbb01717051275be08bb9d260cb9 100644 (file)
@@ -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 ();
 }