[Bug fortran/103828] Type generated for CHARACTER(C_CHAR), VALUE arguments is wrong

fxcoudert at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Dec 26 17:38:56 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103828

--- Comment #4 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Wait, there is more, lower in gfc_conv_scalar_char_value():

      /* If we have a constant character expression, make it into an
         integer.  */
      if ((*expr)->expr_type == EXPR_CONSTANT)
        {
          gfc_typespec ts;
          gfc_clear_ts (&ts);

          *expr = gfc_get_int_expr (gfc_default_character_kind, NULL,
                                    (*expr)->value.character.string[0]);
          if ((*expr)->ts.kind != gfc_c_int_kind)
            {
              /* The expr needs to be compatible with a C int.  If the
                 conversion fails, then the 2 causes an ICE.  */
              ts.type = BT_INTEGER;
              ts.kind = gfc_c_int_kind;
              gfc_convert_type (*expr, &ts, 2);
            }
        }

And… we're forcing it into a C int. Again. The commit that introduced this
function is:

+2007-08-06  Christopher D. Rickett  <crickett@lanl.gov>
+
+       PR fortran/32732
+       * trans-expr.c (gfc_conv_scalar_char_value): Convert the tree and
+       actual arg expressions for scalar characters passed by-value to
+       bind(c) routines.
+       (gfc_conv_function_call): Call gfc_conv_scalar_char_value.
+       * trans.h: Add prototype for gfc_conv_scalar_char_value.
+       * trans-decl.c (generate_local_decl): Convert by-value character
+       dummy args of bind(c) procedures using
+       gfc_conv_scalar_char_value.

It's interesting to note that, at the time, the testcase was failing on IA64
HP-UX, although the bug was still marked as fixed.


More information about the Gcc-bugs mailing list