Commit 0e193637 by Tobias Burnus Committed by Tobias Burnus

lang.opt (Wc-binding-type): New flag.

2012-03-03  Tobias Burnus  <burnus@net-b.de>

        * lang.opt (Wc-binding-type): New flag.
        * options.c (gfc_init_options, gfc_handle_option): Handle it.
        * invoke.texi (Wc-binding-type): Document it.
        * gfortran.h (gfc_option_t): Add warn_c_binding_type.
        * decl.c (verify_bind_c_sym): Handle -Wc-binding-type.
        * symbol.c (gfc_set_default_type, verify_bind_c_derived_type):
        Ditto.

2012-03-03  Tobias Burnus  <burnus@net-b.de>

        * gfortran.dg/bind_c_dts_4.f03: Add dg-options -Wc-binding-type.
        * gfortran.dg/bind_c_implicit_vars.f03: Ditto.
        * gfortran.dg/bind_c_usage_8.f03: Ditto.
        * gfortran.dg/c_kind_tests_2.f03: Ditto.
        * gfortran.dg/class_30.f90: Remove dg-warning line.
        * gfortran.dg/bind_c_usage_25.f90: New.

From-SVN: r184858
parent 905f067c
2012-03-03 Tobias Burnus <burnus@net-b.de> 2012-03-03 Tobias Burnus <burnus@net-b.de>
* lang.opt (Wc-binding-type): New flag.
* options.c (gfc_init_options, gfc_handle_option): Handle it.
* invoke.texi (Wc-binding-type): Document it.
* gfortran.h (gfc_option_t): Add warn_c_binding_type.
* decl.c (verify_bind_c_sym): Handle -Wc-binding-type.
* symbol.c (gfc_set_default_type, verify_bind_c_derived_type):
Ditto.
2012-03-03 Tobias Burnus <burnus@net-b.de>
PR fortran/48820 PR fortran/48820
* decl.c (gfc_match_decl_type_spec): Support type(*). * decl.c (gfc_match_decl_type_spec): Support type(*).
(gfc_verify_c_interop): Allow type(*). (gfc_verify_c_interop): Allow type(*).
......
...@@ -3930,7 +3930,7 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts, ...@@ -3930,7 +3930,7 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts,
{ {
tmp_sym = tmp_sym->result; tmp_sym = tmp_sym->result;
/* Make sure it wasn't an implicitly typed result. */ /* Make sure it wasn't an implicitly typed result. */
if (tmp_sym->attr.implicit_type) if (tmp_sym->attr.implicit_type && gfc_option.warn_c_binding_type)
{ {
gfc_warning ("Implicitly declared BIND(C) function '%s' at " gfc_warning ("Implicitly declared BIND(C) function '%s' at "
"%L may not be C interoperable", tmp_sym->name, "%L may not be C interoperable", tmp_sym->name,
...@@ -3951,7 +3951,7 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts, ...@@ -3951,7 +3951,7 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts,
if (gfc_verify_c_interop (&(tmp_sym->ts)) != SUCCESS) if (gfc_verify_c_interop (&(tmp_sym->ts)) != SUCCESS)
{ {
/* See if we're dealing with a sym in a common block or not. */ /* See if we're dealing with a sym in a common block or not. */
if (is_in_common == 1) if (is_in_common == 1 && gfc_option.warn_c_binding_type)
{ {
gfc_warning ("Variable '%s' in common block '%s' at %L " gfc_warning ("Variable '%s' in common block '%s' at %L "
"may not be a C interoperable " "may not be a C interoperable "
...@@ -3965,7 +3965,7 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts, ...@@ -3965,7 +3965,7 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts,
gfc_error ("Type declaration '%s' at %L is not C " gfc_error ("Type declaration '%s' at %L is not C "
"interoperable but it is BIND(C)", "interoperable but it is BIND(C)",
tmp_sym->name, &(tmp_sym->declared_at)); tmp_sym->name, &(tmp_sym->declared_at));
else else if (gfc_option.warn_c_binding_type)
gfc_warning ("Variable '%s' at %L " gfc_warning ("Variable '%s' at %L "
"may not be a C interoperable " "may not be a C interoperable "
"kind but it is bind(c)", "kind but it is bind(c)",
......
...@@ -2200,6 +2200,7 @@ typedef struct ...@@ -2200,6 +2200,7 @@ typedef struct
int warn_aliasing; int warn_aliasing;
int warn_ampersand; int warn_ampersand;
int gfc_warn_conversion; int gfc_warn_conversion;
int warn_c_binding_type;
int warn_conversion_extra; int warn_conversion_extra;
int warn_function_elimination; int warn_function_elimination;
int warn_implicit_interface; int warn_implicit_interface;
......
...@@ -142,7 +142,7 @@ by type. Explanations are in the following sections. ...@@ -142,7 +142,7 @@ by type. Explanations are in the following sections.
@xref{Error and Warning Options,,Options to request or suppress errors @xref{Error and Warning Options,,Options to request or suppress errors
and warnings}. and warnings}.
@gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds @gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
-Wcharacter-truncation @gol -Wc-binding-type -Wcharacter-truncation @gol
-Wconversion -Wfunction-elimination -Wimplicit-interface @gol -Wconversion -Wfunction-elimination -Wimplicit-interface @gol
-Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol -Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol
-Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol -Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol
...@@ -773,6 +773,14 @@ Warn about array temporaries generated by the compiler. The information ...@@ -773,6 +773,14 @@ Warn about array temporaries generated by the compiler. The information
generated by this warning is sometimes useful in optimization, in order to generated by this warning is sometimes useful in optimization, in order to
avoid such temporaries. avoid such temporaries.
@item -Wc-binding-type
@opindex @code{Wc-binding-type}
@cindex warning, C binding type
Warn if the a variable might not be C interoperable. In particular, warn if
the variable has been declared using an intrinsic type with default kind
instead of using a kind parameter defined for C interoperability in the
intrinsic @code{ISO_C_Binding} module.
@item -Wcharacter-truncation @item -Wcharacter-truncation
@opindex @code{Wcharacter-truncation} @opindex @code{Wcharacter-truncation}
@cindex warnings, character truncation @cindex warnings, character truncation
......
...@@ -210,6 +210,10 @@ Warray-temporaries ...@@ -210,6 +210,10 @@ Warray-temporaries
Fortran Warning Fortran Warning
Warn about creation of array temporaries Warn about creation of array temporaries
Wc-binding-type
Fortran Warning
Warn if the type of a variable might be not interoperable with C
Wcharacter-truncation Wcharacter-truncation
Fortran Warning Fortran Warning
Warn about truncated character expressions Warn about truncated character expressions
......
...@@ -97,6 +97,7 @@ gfc_init_options (unsigned int decoded_options_count, ...@@ -97,6 +97,7 @@ gfc_init_options (unsigned int decoded_options_count,
gfc_option.warn_ampersand = 0; gfc_option.warn_ampersand = 0;
gfc_option.warn_character_truncation = 0; gfc_option.warn_character_truncation = 0;
gfc_option.warn_array_temp = 0; gfc_option.warn_array_temp = 0;
gfc_option.warn_c_binding_type = 0;
gfc_option.gfc_warn_conversion = 0; gfc_option.gfc_warn_conversion = 0;
gfc_option.warn_conversion_extra = 0; gfc_option.warn_conversion_extra = 0;
gfc_option.warn_function_elimination = 0; gfc_option.warn_function_elimination = 0;
...@@ -456,6 +457,7 @@ set_Wall (int setting) ...@@ -456,6 +457,7 @@ set_Wall (int setting)
{ {
gfc_option.warn_aliasing = setting; gfc_option.warn_aliasing = setting;
gfc_option.warn_ampersand = setting; gfc_option.warn_ampersand = setting;
gfc_option.warn_c_binding_type = setting;
gfc_option.gfc_warn_conversion = setting; gfc_option.gfc_warn_conversion = setting;
gfc_option.warn_line_truncation = setting; gfc_option.warn_line_truncation = setting;
gfc_option.warn_surprising = setting; gfc_option.warn_surprising = setting;
...@@ -620,6 +622,10 @@ gfc_handle_option (size_t scode, const char *arg, int value, ...@@ -620,6 +622,10 @@ gfc_handle_option (size_t scode, const char *arg, int value,
gfc_option.warn_array_temp = value; gfc_option.warn_array_temp = value;
break; break;
case OPT_Wc_binding_type:
gfc_option.warn_c_binding_type = value;
break;
case OPT_Wcharacter_truncation: case OPT_Wcharacter_truncation:
gfc_option.warn_character_truncation = value; gfc_option.warn_character_truncation = value;
break; break;
......
...@@ -274,7 +274,7 @@ gfc_set_default_type (gfc_symbol *sym, int error_flag, gfc_namespace *ns) ...@@ -274,7 +274,7 @@ gfc_set_default_type (gfc_symbol *sym, int error_flag, gfc_namespace *ns)
if (ts->type == BT_CHARACTER && ts->u.cl) if (ts->type == BT_CHARACTER && ts->u.cl)
sym->ts.u.cl = gfc_new_charlen (sym->ns, ts->u.cl); sym->ts.u.cl = gfc_new_charlen (sym->ns, ts->u.cl);
if (sym->attr.is_bind_c == 1) if (sym->attr.is_bind_c == 1 && gfc_option.warn_c_binding_type)
{ {
/* BIND(C) variables should not be implicitly declared. */ /* BIND(C) variables should not be implicitly declared. */
gfc_warning_now ("Implicitly declared BIND(C) variable '%s' at %L may " gfc_warning_now ("Implicitly declared BIND(C) variable '%s' at %L may "
...@@ -287,7 +287,8 @@ gfc_set_default_type (gfc_symbol *sym, int error_flag, gfc_namespace *ns) ...@@ -287,7 +287,8 @@ gfc_set_default_type (gfc_symbol *sym, int error_flag, gfc_namespace *ns)
if (sym->ns->proc_name != NULL if (sym->ns->proc_name != NULL
&& (sym->ns->proc_name->attr.subroutine != 0 && (sym->ns->proc_name->attr.subroutine != 0
|| sym->ns->proc_name->attr.function != 0) || sym->ns->proc_name->attr.function != 0)
&& sym->ns->proc_name->attr.is_bind_c != 0) && sym->ns->proc_name->attr.is_bind_c != 0
&& gfc_option.warn_c_binding_type)
{ {
/* Dummy args to a BIND(C) routine may not be interoperable if /* Dummy args to a BIND(C) routine may not be interoperable if
they are implicitly typed. */ they are implicitly typed. */
...@@ -3694,7 +3695,8 @@ verify_bind_c_derived_type (gfc_symbol *derived_sym) ...@@ -3694,7 +3695,8 @@ verify_bind_c_derived_type (gfc_symbol *derived_sym)
recompiles with different flags (e.g., -m32 and -m64 on recompiles with different flags (e.g., -m32 and -m64 on
x86_64 and using integer(4) to claim interop with a x86_64 and using integer(4) to claim interop with a
C_LONG). */ C_LONG). */
if (derived_sym->attr.is_bind_c == 1) if (derived_sym->attr.is_bind_c == 1
&& gfc_option.warn_c_binding_type)
/* If the derived type is bind(c), all fields must be /* If the derived type is bind(c), all fields must be
interop. */ interop. */
gfc_warning ("Component '%s' in derived type '%s' at %L " gfc_warning ("Component '%s' in derived type '%s' at %L "
...@@ -3702,7 +3704,7 @@ verify_bind_c_derived_type (gfc_symbol *derived_sym) ...@@ -3702,7 +3704,7 @@ verify_bind_c_derived_type (gfc_symbol *derived_sym)
"derived type '%s' is BIND(C)", "derived type '%s' is BIND(C)",
curr_comp->name, derived_sym->name, curr_comp->name, derived_sym->name,
&(curr_comp->loc), derived_sym->name); &(curr_comp->loc), derived_sym->name);
else else if (gfc_option.warn_c_binding_type)
/* If derived type is param to bind(c) routine, or to one /* If derived type is param to bind(c) routine, or to one
of the iso_c_binding procs, it must be interoperable, so of the iso_c_binding procs, it must be interoperable, so
all fields must interop too. */ all fields must interop too. */
......
2012-03-03 Tobias Burnus <burnus@net-b.de> 2012-03-03 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/bind_c_dts_4.f03: Add dg-options -Wc-binding-type.
* gfortran.dg/bind_c_implicit_vars.f03: Ditto.
* gfortran.dg/bind_c_usage_8.f03: Ditto.
* gfortran.dg/c_kind_tests_2.f03: Ditto.
* gfortran.dg/class_30.f90: Remove dg-warning line.
* gfortran.dg/bind_c_usage_25.f90: New.
2012-03-03 Tobias Burnus <burnus@net-b.de>
PR fortran/48820 PR fortran/48820
* gfortran.dg/assumed_type_1.f90: Correct dg-error. * gfortran.dg/assumed_type_1.f90: Correct dg-error.
* gfortran.dg/assumed_type_3.f90: Correct dg-error. * gfortran.dg/assumed_type_3.f90: Correct dg-error.
......
! { dg-do compile } ! { dg-do compile }
! { dg-options "-Wc-binding-type" }
module test module test
use iso_c_binding, only: c_int use iso_c_binding, only: c_int
type, bind(c) :: foo type, bind(c) :: foo
......
! { dg-do compile } ! { dg-do compile }
! { dg-options "-Wc-binding-type" }
module bind_c_implicit_vars module bind_c_implicit_vars
bind(c) :: j ! { dg-warning "may not be C interoperable" } bind(c) :: j ! { dg-warning "may not be C interoperable" }
......
! { dg-do compile }
! { dg-options "-Wno-c-binding-type" }
!
! That's a copy of "bind_c_usage_8.f03", "bind_c_dts_4.f03",
! "bind_c_implicit_vars.f03" and "c_kind_tests_2.f03"
! to check that with -Wno-c-binding-type no warning is printed.
!
MODULE ISO_C_UTILITIES
USE ISO_C_BINDING
implicit none
CHARACTER(C_CHAR), DIMENSION(1), SAVE, TARGET, PRIVATE :: dummy_string="?"
CONTAINS
FUNCTION C_F_STRING(CPTR) RESULT(FPTR)
use, intrinsic :: iso_c_binding
TYPE(C_PTR), INTENT(IN) :: CPTR ! The C address
CHARACTER(KIND=C_CHAR), DIMENSION(:), POINTER :: FPTR
INTERFACE
FUNCTION strlen(string) RESULT(len) BIND(C,NAME="strlen")
USE ISO_C_BINDING
TYPE(C_PTR), VALUE :: string ! A C pointer
END FUNCTION
END INTERFACE
CALL C_F_POINTER(FPTR=FPTR, CPTR=CPTR, SHAPE=[strlen(CPTR)])
END FUNCTION
END MODULE ISO_C_UTILITIES
module test
use iso_c_binding, only: c_int
type, bind(c) :: foo
integer :: p
end type
type(foo), bind(c) :: cp
end module test
module bind_c_implicit_vars
bind(c) :: j
contains
subroutine sub0(i) bind(c)
i = 0
end subroutine sub0
end module bind_c_implicit_vars
module c_kind_tests_2
use, intrinsic :: iso_c_binding
integer, parameter :: myF = c_float
real(myF), bind(c) :: myCFloat
integer(myF), bind(c) :: myCInt ! { dg-warning "is for type REAL" }
integer(c_double), bind(c) :: myCInt2 ! { dg-warning "is for type REAL" }
integer, parameter :: myI = c_int
real(myI) :: myReal ! { dg-warning "is for type INTEGER" }
real(myI), bind(c) :: myCFloat2 ! { dg-warning "is for type INTEGER" }
real(4), bind(c) :: myFloat
end module c_kind_tests_2
! { dg-final { cleanup-modules "c_kind_tests_2" } }
! { dg-final { cleanup-modules "bind_c_implicit_vars" } }
! { dg-final { cleanup-modules "test" } }
! { dg-final { cleanup-modules "iso_c_utilities" } }
! { dg-do compile } ! { dg-do compile }
! { dg-options "-Wc-binding-type" }
! This should compile, though there is a warning about the type of len ! This should compile, though there is a warning about the type of len
! (return variable of strlen()) for being implicit. ! (return variable of strlen()) for being implicit.
! PR fortran/32797 ! PR fortran/32797
......
! { dg-do compile } ! { dg-do compile }
! { dg-options "-Wc-binding-type" }
module c_kind_tests_2 module c_kind_tests_2
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
......
...@@ -15,7 +15,6 @@ end type t2 ...@@ -15,7 +15,6 @@ end type t2
type, bind(C):: t3 type, bind(C):: t3
class(t), pointer :: y class(t), pointer :: y
! { dg-warning "may not be C interoperable" "" { target *-*-* } 17 }
! { dg-error "Polymorphic component y at .1. in SEQUENCE or BIND" "" { target *-*-* } 17 } ! { dg-error "Polymorphic component y at .1. in SEQUENCE or BIND" "" { target *-*-* } 17 }
end type t3 end type t3
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment