Patchwork [Fortran] PR53985 add missing case to -Wc-binding-type

login
register
mail settings
Submitter Tobias Burnus
Date July 17, 2012, 8:13 a.m.
Message ID <50051EC2.5000802@net-b.de>
Download mbox | patch
Permalink /patch/171355/
State New
Headers show

Comments

Tobias Burnus - July 17, 2012, 8:13 a.m.
gfortran always warned for BIND(C) procedures if one used "integer", 
"integer(4)" etc. instead of "integer(c_int)". While the latter is 
surely more portable than the former, all of them are identical on 
nearly all systems. Hence, the other versions are rahter widely used.

In order to reduce the clutter due to default warnings, since GCC 4.8 
there is a new warning -Wc-binding-type, which is turned off by default. 
However, for some reason, it misses the most common case. That's now 
fixed in the attachment. I also corrected the wording.

Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias
Mikael Morin - July 17, 2012, 7:08 p.m.
On 17/07/2012 10:13, Tobias Burnus wrote:
> gfortran always warned for BIND(C) procedures if one used "integer",
> "integer(4)" etc. instead of "integer(c_int)". While the latter is
> surely more portable than the former, all of them are identical on
> nearly all systems. Hence, the other versions are rahter widely used.
> 
> In order to reduce the clutter due to default warnings, since GCC 4.8
> there is a new warning -Wc-binding-type, which is turned off by default.
> However, for some reason, it misses the most common case. That's now
> fixed in the attachment. I also corrected the wording.
> 
> Build and regtested on x86-64-gnu-linux.
> OK for the trunk?
> 
> Tobias

OK, thanks.

Mikael

Patch

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

	PR fortran/53985
	* decl.c (gfc_verify_c_interop_param): Make warning conditional
	on -Wc-binding-type works and improve the wording.

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

	PR fortran/53985
	* gfortran.dg/bind_c_usage_26.f90: New.
	* gfortran.dg/bind_c_procs.f03: Add dg-options "-Wc-binding-type".
	* gfortran.dg/bind_c_usage_13.f03: Ditto.
	* gfortran.dg/bind_c_usage_18.f90: Ditto.
	* gfortran.dg/interop_params.f03: Ditto.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index c3644b6..c6ba43e 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1027,8 +1032,8 @@  gfc_verify_c_interop_param (gfc_symbol *sym)
 			   "because it is polymorphic",
 			   sym->name, &(sym->declared_at),
 			   sym->ns->proc_name->name);
-	      else
-		gfc_warning ("Variable '%s' at %L is a parameter to the "
+	      else if (gfc_option.warn_c_binding_type)
+		gfc_warning ("Variable '%s' at %L is a dummy argument of the "
 			     "BIND(C) procedure '%s' but may not be C "
 			     "interoperable",
 			     sym->name, &(sym->declared_at),
--- /dev/null	2012-07-17 07:28:04.995717470 +0200
+++ gcc/gcc/testsuite/gfortran.dg/bind_c_usage_26.f90	2012-07-17 09:05:56.000000000 +0200
@@ -0,0 +1,14 @@ 
+! { dg-do compile }
+!
+! PR fortran/53985
+!
+! Check that the (default) -Wno-c-binding-type works
+! and no warning is printed.
+!
+! With -Wc-binding-type, one gets:
+!  Warning: Variable 'x' at (1) is a dummy argument to the BIND(C) procedure
+!           'test' but may not be C interoperable )
+!
+subroutine test(x) bind(C)
+  integer :: x
+end subroutine test
diff --git a/gcc/testsuite/gfortran.dg/bind_c_procs.f03 b/gcc/testsuite/gfortran.dg/bind_c_procs.f03
index eaf0672..3bb6ea3 100644
--- a/gcc/testsuite/gfortran.dg/bind_c_procs.f03
+++ b/gcc/testsuite/gfortran.dg/bind_c_procs.f03
@@ -1,4 +1,5 @@ 
 ! { dg-do compile }
+! { dg-options "-Wc-binding-type" }
 module bind_c_procs
   use, intrinsic :: iso_c_binding, only: c_int
 
diff --git a/gcc/testsuite/gfortran.dg/bind_c_usage_13.f03 b/gcc/testsuite/gfortran.dg/bind_c_usage_13.f03
index d89963d..b8c2261 100644
--- a/gcc/testsuite/gfortran.dg/bind_c_usage_13.f03
+++ b/gcc/testsuite/gfortran.dg/bind_c_usage_13.f03
@@ -1,5 +1,5 @@ 
 ! { dg-do compile }
-! { dg-options "-fdump-tree-original" }
+! { dg-options "-fdump-tree-original -Wc-binding-type" }
 !
 ! PR fortran/34079
 ! Character bind(c) arguments shall not pass the length as additional argument
diff --git a/gcc/testsuite/gfortran.dg/bind_c_usage_18.f90 b/gcc/testsuite/gfortran.dg/bind_c_usage_18.f90
index 2bce215..ede9f60 100644
--- a/gcc/testsuite/gfortran.dg/bind_c_usage_18.f90
+++ b/gcc/testsuite/gfortran.dg/bind_c_usage_18.f90
@@ -1,4 +1,5 @@ 
 ! { dg-do compile }
+! { dg-options "-Wc-binding-type" }
 !
 ! PR fortran/38160
 !
diff --git a/gcc/testsuite/gfortran.dg/interop_params.f03 b/gcc/testsuite/gfortran.dg/interop_params.f03
index ea3dada..6eafba0 100644
--- a/gcc/testsuite/gfortran.dg/interop_params.f03
+++ b/gcc/testsuite/gfortran.dg/interop_params.f03
@@ -1,4 +1,5 @@ 
 ! { dg-do compile }
+! { dg-options "-Wc-binding-type" }
 module interop_params
 use, intrinsic :: iso_c_binding