This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ISO_C_BINDING patch commited to fortran-experiments branch


Hi,

Tobias Burnus wrote:
> FAIL: gfortran.dg/bind_c_coms.f90  -O0  (test for excess errors)
>   
The problem is that one cannot use:

   real(c_double) :: r

this gives the error:

  C kind param 'c_double' at (1) not valid for REAL

The reason is: In iso-c-binding.def, one uses NAMED_INTCST for
everything, e.g.

NAMED_INTCST (ISOCBINDING_INT, "c_int", gfc_c_int_kind)
NAMED_INTCST (ISOCBINDING_FLOAT, "c_float", \
              get_real_kind_from_node (float_type_node))
NAMED_INTCST (ISOCBINDING_DOUBLE_COMPLEX, "c_double_complex", \
              get_real_kind_from_node (double_type_node))
NAMED_INTCST (ISOCBINDING_CHAR, "c_char", gfc_default_character_kind)

Attached patch fixes this. Is this the right approach?


In any case, it then regtests fine on x86_64-unknown-linux-gnu, except for:

* gfortran.dg/c_kind_params.f90:
    integer(c_int_fast8_t), value :: my_int_fast8_t
                        1
Error: Kind -2 not supported for type INTEGER at (1)

Which is expected, but I think it should be supported as well,
at least when /usr/include/stdint.h provides them.

NAMED_INTCST (ISOCBINDING_INT_FAST8_T, "c_int_fast8_t", -2)
NAMED_INTCST (ISOCBINDING_INT_FAST16_T, "c_int_fast16_t", -2)
NAMED_INTCST (ISOCBINDING_INT_FAST32_T, "c_int_fast32_t", -2)
NAMED_INTCST (ISOCBINDING_INT_FAST64_T, "c_int_fast64_t", -2)

Tobias
Index: gcc/fortran/symbol.c
===================================================================
*** gcc/fortran/symbol.c	(Revision 120008)
--- gcc/fortran/symbol.c	(Arbeitskopie)
*************** generate_isocbinding_symbol (const char 
*** 3997,4002 ****
--- 3997,4006 ----
      {
  
  #define NAMED_INTCST(a,b,c) case a :
+ #define NAMED_REALCST(a,b,c) case a :
+ #define NAMED_CMPXCST(a,b,c) case a :
+ #define NAMED_LOGCST(a,b,c) case a :
+ #define NAMED_CHARKNDCST(a,b,c) case a :
  #include "iso-c-binding.def"
  
  	tmp_sym->value = gfc_int_expr (c_interop_kinds_table[s].value);
Index: gcc/fortran/gfortran.h
===================================================================
*** gcc/fortran/gfortran.h	(Revision 120008)
--- gcc/fortran/gfortran.h	(Arbeitskopie)
*************** typedef enum gfc_generic_isym_id gfc_gen
*** 480,485 ****
--- 480,489 ----
  #define BBT_HEADER(self) int priority; struct self *left, *right
  
  #define NAMED_INTCST(a,b,c) a,
+ #define NAMED_REALCST(a,b,c) a,
+ #define NAMED_CMPXCST(a,b,c) a,
+ #define NAMED_LOGCST(a,b,c) a,
+ #define NAMED_CHARKNDCST(a,b,c) a,
  #define NAMED_CHARCST(a,b,c) a,
  #define DERIVED_TYPE(a,b,c) a,
  #define PROCEDURE(a,b) a,
Index: gcc/fortran/iso-c-binding.def
===================================================================
*** gcc/fortran/iso-c-binding.def	(Revision 120008)
--- gcc/fortran/iso-c-binding.def	(Arbeitskopie)
*************** Software Foundation, 51 Franklin Street,
*** 24,30 ****
  # define NAMED_INTCST(a,b,c) 
  #endif
  
! /* The arguments to NAMED_INTCST are:
       -- an internal name
       -- the symbol name in the module, as seen by Fortran code
       -- the value it has, for use in trans-types.c  */
--- 24,46 ----
  # define NAMED_INTCST(a,b,c) 
  #endif
  
! #ifndef NAMED_REALCST
! # define NAMED_REALCST(a,b,c) 
! #endif
! 
! #ifndef NAMED_CMPXCST
! # define NAMED_CMPXCST(a,b,c) 
! #endif
! 
! #ifndef NAMED_LOGCST
! # define NAMED_LOGCST(a,b,c) 
! #endif
! 
! #ifndef NAMED_CHARKNDCST
! # define NAMED_CHARKNDCST(a,b,c) 
! #endif
! 
! /* The arguments to NAMED_*CST are:
       -- an internal name
       -- the symbol name in the module, as seen by Fortran code
       -- the value it has, for use in trans-types.c  */
*************** NAMED_INTCST (ISOCBINDING_INT_FAST16_T, 
*** 65,86 ****
  NAMED_INTCST (ISOCBINDING_INT_FAST32_T, "c_int_fast32_t", -2)
  NAMED_INTCST (ISOCBINDING_INT_FAST64_T, "c_int_fast64_t", -2)
  
! NAMED_INTCST (ISOCBINDING_FLOAT, "c_float", \
!               get_real_kind_from_node (float_type_node))
! NAMED_INTCST (ISOCBINDING_DOUBLE, "c_double", \
!               get_real_kind_from_node (double_type_node))
! NAMED_INTCST (ISOCBINDING_LONG_DOUBLE, "c_long_double", \
!               get_real_kind_from_node (long_double_type_node))
! NAMED_INTCST (ISOCBINDING_FLOAT_COMPLEX, "c_float_complex", \
!               get_real_kind_from_node (float_type_node))
! NAMED_INTCST (ISOCBINDING_DOUBLE_COMPLEX, "c_double_complex", \
!               get_real_kind_from_node (double_type_node))
! NAMED_INTCST (ISOCBINDING_LONG_DOUBLE_COMPLEX, "c_long_double_complex", \
!               get_real_kind_from_node (long_double_type_node))
  
! NAMED_INTCST (ISOCBINDING_BOOL, "c_bool", \
                get_int_kind_from_width (BOOL_TYPE_SIZE))
! NAMED_INTCST (ISOCBINDING_CHAR, "c_char", gfc_default_character_kind)
  
  #ifndef NAMED_CHARCST
  # define NAMED_CHARCST(a,b,c) 
--- 81,103 ----
  NAMED_INTCST (ISOCBINDING_INT_FAST32_T, "c_int_fast32_t", -2)
  NAMED_INTCST (ISOCBINDING_INT_FAST64_T, "c_int_fast64_t", -2)
  
! NAMED_REALCST (ISOCBINDING_FLOAT, "c_float", \
!                get_real_kind_from_node (float_type_node))
! NAMED_REALCST (ISOCBINDING_DOUBLE, "c_double", \
!                get_real_kind_from_node (double_type_node))
! NAMED_REALCST (ISOCBINDING_LONG_DOUBLE, "c_long_double", \
!                get_real_kind_from_node (long_double_type_node))
! NAMED_CMPXCST (ISOCBINDING_FLOAT_COMPLEX, "c_float_complex", \
!                get_real_kind_from_node (float_type_node))
! NAMED_CMPXCST (ISOCBINDING_DOUBLE_COMPLEX, "c_double_complex", \
!                get_real_kind_from_node (double_type_node))
! NAMED_CMPXCST (ISOCBINDING_LONG_DOUBLE_COMPLEX, "c_long_double_complex", \
!                get_real_kind_from_node (long_double_type_node))
  
! NAMED_LOGCST (ISOCBINDING_BOOL, "c_bool", \
                get_int_kind_from_width (BOOL_TYPE_SIZE))
! 
! NAMED_CHARKNDCST (ISOCBINDING_CHAR, "c_char", gfc_default_character_kind)
  
  #ifndef NAMED_CHARCST
  # define NAMED_CHARCST(a,b,c) 
*************** PROCEDURE (ISOCBINDING_LOC, "c_loc")
*** 116,121 ****
--- 133,142 ----
  PROCEDURE (ISOCBINDING_F_PROCPOINTER, "c_f_procpointer")
  
  #undef NAMED_INTCST
+ #undef NAMED_REALCST
+ #undef NAMED_CMPXCST
+ #undef NAMED_LOGCST
  #undef NAMED_CHARCST
+ #undef NAMED_CHARKNDCST
  #undef DERIVED_TYPE
  #undef PROCEDURE
Index: gcc/fortran/trans-types.c
===================================================================
*** gcc/fortran/trans-types.c	(Revision 120008)
--- gcc/fortran/trans-types.c	(Arbeitskopie)
*************** void init_c_interop_kinds(void)
*** 205,210 ****
--- 205,226 ----
    strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
    c_interop_kinds_table[a].f90_type = BT_INTEGER; \
    c_interop_kinds_table[a].value = c;
+ #define NAMED_REALCST(a,b,c) \
+   strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
+   c_interop_kinds_table[a].f90_type = BT_REAL; \
+   c_interop_kinds_table[a].value = c;
+ #define NAMED_CMPXCST(a,b,c) \
+   strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
+   c_interop_kinds_table[a].f90_type = BT_COMPLEX; \
+   c_interop_kinds_table[a].value = c;
+ #define NAMED_LOGCST(a,b,c) \
+   strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
+   c_interop_kinds_table[a].f90_type = BT_LOGICAL; \
+   c_interop_kinds_table[a].value = c;
+ #define NAMED_CHARKNDCST(a,b,c) \
+   strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
+   c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
+   c_interop_kinds_table[a].value = c;
  #define NAMED_CHARCST(a,b,c) \
    strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
    c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
Index: gcc/testsuite/gfortran.dg/use_iso_c_binding.f90
===================================================================
--- gcc/testsuite/gfortran.dg/use_iso_c_binding.f90	(Revision 120008)
+++ gcc/testsuite/gfortran.dg/use_iso_c_binding.f90	(Arbeitskopie)
@@ -7,12 +7,12 @@
 ! intrinsic one.  --Rickett, 09.26.06
 module use_stmt_0
   ! this is an error because c_ptr_2 does not exist 
-  use, intrinsic :: iso_c_binding, only: c_ptr_2 ! { dg-error "Symbol c_ptr_2 does not exist" }
+  use, intrinsic :: iso_c_binding, only: c_ptr_2 ! { dg-error "Symbol 'c_ptr_2' referenced at \\(1\\) does not exist" }
 end module use_stmt_0
 
 module use_stmt_1
   ! this is an error because c_ptr_2 does not exist 
-  use iso_c_binding, only: c_ptr_2 ! { dg-error "Symbol c_ptr_2 does not exist" }
+  use iso_c_binding, only: c_ptr_2 ! { dg-error "Symbol 'c_ptr_2' referenced at \\(1\\) does not exist" }
 end module use_stmt_1
 
 module use_stmt_2

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]