public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFA gfortran] PR 25071: dummy argument larger than actual argument
@ 2017-09-28 12:57 Dominique d'Humières
  2017-09-29  8:09 ` Janne Blomqvist
  2017-09-29 13:07 ` Dominique d'Humières
  0 siblings, 2 replies; 4+ messages in thread
From: Dominique d'Humières @ 2017-09-28 12:57 UTC (permalink / raw)
  To: Janus Weil; +Cc: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 673 bytes --]

Hi all,

In the PR there was some consensus to turn the warnings into errors. 

This is what the patch does: the warnings are kept with -std=legacy, errors are emitted otherwise.
 I am sure it may exist a better solution, but I did not find it. 

While regtesting I have found several regressions on top of gfortran.dg/warn_argument_mismatch_1.f90

At this point, I had two options: use -std=legacy everywhere or replace the dg-warning with dg-error. I have chosen the later except for warn_argument_mismatch_1.f90.

Regtested on x86_64-apple-darwin16.

Comments are welcome and I’ll provide the change logs once the dust has settled.

TIA

Dominique


[-- Attachment #2: patch-25071b --]
[-- Type: application/octet-stream, Size: 12368 bytes --]

--- ../_clean/gcc/fortran/interface.c	2017-09-10 01:19:10.000000000 +0200
+++ gcc/fortran/interface.c	2017-09-25 09:01:22.000000000 +0200
@@ -2991,11 +2991,20 @@ compare_actual_formal (gfc_actual_arglis
 			 f->sym->name, actual_size, formal_size,
 			 &a->expr->where);
           else if (where)
-	    gfc_warning (OPT_Wargument_mismatch,
-			 "Actual argument contains too few "
-			 "elements for dummy argument %qs (%lu/%lu) at %L",
-			 f->sym->name, actual_size, formal_size,
-			 &a->expr->where);
+	    {
+	      /* Emit a warning for -std=legacy and an error otherwise. */
+	      if (gfc_option.warn_std == 0)
+	        gfc_warning (OPT_Wargument_mismatch,
+			     "Actual argument contains too few "
+			     "elements for dummy argument %qs (%lu/%lu) "
+			     "at %L", f->sym->name, actual_size,
+			     formal_size, &a->expr->where);
+	      else
+	        gfc_error_now ("Actual argument contains too few "
+			       "elements for dummy argument %qs (%lu/%lu) "
+			       "at %L", f->sym->name, actual_size,
+			       formal_size, &a->expr->where);
+	    }
 	  return false;
 	}
 
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_3.f90	2011-02-18 17:40:36.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_3.f90	2017-09-25 07:41:35.000000000 +0200
@@ -25,12 +25,12 @@ end interface
   call foo(len2) ! { dg-error "Rank mismatch in argument" }
   call foo("ca") ! { dg-error "Rank mismatch in argument" }
   call bar("ca") ! { dg-error "Rank mismatch in argument" }
-  call foobar(len2) ! { dg-warning "contains too few elements" }
+  call foobar(len2) ! { dg-error "contains too few elements" }
   call foobar(len4)
-  call foobar("bar") ! { dg-warning "contains too few elements" }
+  call foobar("bar") ! { dg-error "contains too few elements" }
   call foobar("bar33")
-  call arr(len2) ! { dg-warning "contains too few elements" }
+  call arr(len2) ! { dg-error "contains too few elements" }
   call arr(len4)
-  call arr("bar") ! { dg-warning "contains too few elements" }
+  call arr("bar") ! { dg-error "contains too few elements" }
   call arr("bar33")
 end program test
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_4.f90	2009-11-25 18:17:40.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_4.f90	2017-09-25 07:42:12.000000000 +0200
@@ -12,10 +12,10 @@ interface
   end subroutine arr
 end interface
 
-  call foobar( [ "bar" ]) ! { dg-warning "contains too few elements" }
+  call foobar( [ "bar" ]) ! { dg-error "contains too few elements" }
   call foobar( ["ba ","r33"])
-  call arr( [ "bar" ]) ! { dg-warning "contains too few elements" }
+  call arr( [ "bar" ]) ! { dg-error "contains too few elements" }
   call arr( reshape(["b","a","r","3"], [2,2]))
-  call arr( reshape(["b","a"], [1,2])) ! { dg-warning "contains too few elements" }
-  call arr( reshape(["b","a"], [2,1])) ! { dg-warning "contains too few elements" }
+  call arr( reshape(["b","a"], [1,2])) ! { dg-error "contains too few elements" }
+  call arr( reshape(["b","a"], [2,1])) ! { dg-error "contains too few elements" }
 end program test
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_5.f90	2009-11-25 18:17:47.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_5.f90	2017-09-25 07:43:03.000000000 +0200
@@ -13,23 +13,23 @@ interface
 end interface
 
 integer a(3), b(5)
-call foobar(a) ! { dg-warning "contains too few elements" }
+call foobar(a) ! { dg-error "contains too few elements" }
 call foobar(b)
-call foobar(b(1:3)) ! { dg-warning "contains too few elements" }
+call foobar(b(1:3)) ! { dg-error "contains too few elements" }
 call foobar(b(1:5))
-call foobar(b(1:5:2)) ! { dg-warning "contains too few elements" }
+call foobar(b(1:5:2)) ! { dg-error "contains too few elements" }
 call foobar(b(2))
-call foobar(b(3)) ! { dg-warning "Actual argument contains too few elements" }
-call foobar(reshape(a(1:3),[2,1])) ! { dg-warning "contains too few elements" }
+call foobar(b(3)) ! { dg-error "Actual argument contains too few elements" }
+call foobar(reshape(a(1:3),[2,1])) ! { dg-error "contains too few elements" }
 call foobar(reshape(b(2:5),[2,2]))
 
-call arr(a) ! { dg-warning "contains too few elements" }
+call arr(a) ! { dg-error "contains too few elements" }
 call arr(b)
-call arr(b(1:3)) ! { dg-warning "contains too few elements" }
+call arr(b(1:3)) ! { dg-error "contains too few elements" }
 call arr(b(1:5))
-call arr(b(1:5:2)) ! { dg-warning "contains too few elements" }
+call arr(b(1:5:2)) ! { dg-error "contains too few elements" }
 call arr(b(2))
-call arr(b(3)) ! { dg-warning "contains too few elements" }
-call arr(reshape(a(1:3),[2,1])) ! { dg-warning "contains too few elements" }
+call arr(b(3)) ! { dg-error "contains too few elements" }
+call arr(reshape(a(1:3),[2,1])) ! { dg-error "contains too few elements" }
 call arr(reshape(b(2:5),[2,2]))
 end program test
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_6.f90	2011-02-18 17:40:36.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_6.f90	2017-09-25 07:43:28.000000000 +0200
@@ -14,7 +14,7 @@ real,dimension(-1:2) ::  z
 call sub(x(:))
 call sub(y(:))
 call sub(z(:))
-call sub(w(:)) ! { dg-warning "too few elements" }
+call sub(w(:)) ! { dg-error "too few elements" }
 
 contains
   subroutine sub(a)
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_10.f90	2009-11-25 18:17:47.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_10.f90	2017-09-25 07:44:04.000000000 +0200
@@ -8,7 +8,7 @@ IMPLICIT NONE
 INTEGER :: i(-1:1)
 INTEGER :: j(-2:-1)
 CALL S(i)
-CALL S(j) ! { dg-warning "Actual argument contains too few elements for dummy argument 'i' .2/3." }
+CALL S(j) ! { dg-error "Actual argument contains too few elements for dummy argument 'i' .2/3." }
 CONTAINS
  SUBROUTINE S(i)
   INTEGER :: i(0:2)
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_13.f90	2011-02-13 22:04:06.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_13.f90	2017-09-25 07:44:51.000000000 +0200
@@ -53,8 +53,8 @@ call rlv2(pointer_dummy(1,1,1))    ! Val
 ! We warn nonetheless as the result is not what is intented
 ! and also formally wrong.
 ! Using (1:string_length) would be ok.
-call rlv2(ptr(1,1,1)(1:1))              ! { dg-warning "contains too few elements" }
-call rlv2(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-warning "contains too few elements" }
+call rlv2(ptr(1,1,1)(1:1))              ! { dg-error "contains too few elements" }
+call rlv2(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-error "contains too few elements" }
 call rlv2(pointer_dummy(1,1,1)(1:3))    ! Valid F2003
 end
 
@@ -72,12 +72,12 @@ character(2), pointer :: pointer_dummy(:
 character(2), allocatable :: deferred(:,:,:)
 character(2), pointer     :: ptr(:,:,:)
 call rlv3(deferred(1,1,1))         ! Valid since contiguous
-call rlv3(ptr(1,1,1))              ! { dg-warning "contains too few elements" }
-call rlv3(assumed_sh_dummy(1,1,1)) ! { dg-warning "contains too few elements" }
-call rlv3(pointer_dummy(1,1,1))    ! { dg-warning "contains too few elements" }
+call rlv3(ptr(1,1,1))              ! { dg-error "contains too few elements" }
+call rlv3(assumed_sh_dummy(1,1,1)) ! { dg-error "contains too few elements" }
+call rlv3(pointer_dummy(1,1,1))    ! { dg-error "contains too few elements" }
 
 call rlv3(deferred(1,1,1)(1:2))         ! Valid since contiguous
-call rlv3(ptr(1,1,1)(1:2))              ! { dg-warning "contains too few elements" }
-call rlv3(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-warning "contains too few elements" }
-call rlv3(pointer_dummy(1,1,1)(1:2))    ! { dg-warning "contains too few elements" }
+call rlv3(ptr(1,1,1)(1:2))              ! { dg-error "contains too few elements" }
+call rlv3(assumed_sh_dummy(1,1,1)(1:2)) ! { dg-error "contains too few elements" }
+call rlv3(pointer_dummy(1,1,1)(1:2))    ! { dg-error "contains too few elements" }
 end
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_15.f90	2011-02-18 17:40:36.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_15.f90	2017-09-25 07:47:25.000000000 +0200
@@ -14,20 +14,20 @@ character(len=4) :: str2(2,2)
 
 call test()
 
-call foo(i(8)) ! { dg-warning "too few elements for dummy argument 'a' .3/4." }
+call foo(i(8)) ! { dg-error "too few elements for dummy argument 'a' .3/4." }
 call foo(j(1,1))
-call foo(j(2,1)) ! { dg-warning "too few elements for dummy argument 'a' .3/4." }
-call foo(j(1,2)) ! { dg-warning "too few elements for dummy argument 'a' .2/4." }
+call foo(j(2,1)) ! { dg-error "too few elements for dummy argument 'a' .3/4." }
+call foo(j(1,2)) ! { dg-error "too few elements for dummy argument 'a' .2/4." }
 
 str = 'FORT'
 str2 = 'fort'
-call bar(str(:)(1:2)) ! { dg-warning "too few elements for dummy argument 'c' .4/6." }
-call bar(str(1:2)(1:1)) ! { dg-warning "too few elements for dummy argument 'c' .2/6." }
-call bar(str(2)) ! { dg-warning "too few elements for dummy argument 'c' .4/6." }
+call bar(str(:)(1:2)) ! { dg-error "too few elements for dummy argument 'c' .4/6." }
+call bar(str(1:2)(1:1)) ! { dg-error "too few elements for dummy argument 'c' .2/6." }
+call bar(str(2)) ! { dg-error "too few elements for dummy argument 'c' .4/6." }
 call bar(str(1)(2:1)) ! OK
 call bar(str2(2,1)(4:1)) ! OK
 call bar(str2(1,2)(3:4)) ! OK
-call bar(str2(1,2)(4:4)) ! { dg-warning "too few elements for dummy argument 'c' .5/6." }
+call bar(str2(1,2)(4:4)) ! { dg-error "too few elements for dummy argument 'c' .5/6." }
 contains
   subroutine foo(a)
     integer :: a(4)
--- ../_clean/gcc/testsuite/gfortran.dg/argument_checking_18.f90	2011-02-14 13:04:55.000000000 +0100
+++ gcc/testsuite/gfortran.dg/argument_checking_18.f90	2017-09-25 07:45:50.000000000 +0200
@@ -14,8 +14,8 @@
 
  tt%j = i
 
- call sub1 (i)     ! { dg-warning "Actual argument contains too few elements" }
- call sub1 (tt%j)  ! { dg-warning "Actual argument contains too few elements" }
+ call sub1 (i)     ! { dg-error "Actual argument contains too few elements" }
+ call sub1 (tt%j)  ! { dg-error "Actual argument contains too few elements" }
  call sub2 (i)     ! { dg-error "Rank mismatch in argument" }
  call sub2 (tt%j)  ! { dg-error "Rank mismatch in argument" }
 
--- ../_clean/gcc/testsuite/gfortran.dg/gomp/udr8.f90	2014-06-24 10:07:34.000000000 +0200
+++ gcc/testsuite/gfortran.dg/gomp/udr8.f90	2017-09-25 06:48:54.000000000 +0200
@@ -274,11 +274,11 @@ subroutine test13
   use m
 !$omp declare reduction (foo : integer : omp_out = omp_out + omp_in) initializer (omp_priv = 0)
 !$omp declare reduction (bar : integer : omp_out = & ! { dg-error "Different shape for array assignment at \[^\n\r]* on dimension 1 .9 and 10" }
-!$omp & fn5 (omp_out, omp_in)) & ! { dg-warning "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
-!$omp & initializer (sub5 (omp_priv, omp_orig)) ! { dg-warning "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
-!$omp declare reduction (baz : integer : sub6 (omp_out, omp_in)) & ! { dg-warning "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
+!$omp & fn5 (omp_out, omp_in)) & ! { dg-error "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
+!$omp & initializer (sub5 (omp_priv, omp_orig)) ! { dg-error "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
+!$omp declare reduction (baz : integer : sub6 (omp_out, omp_in)) & ! { dg-error "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
 !$omp initializer (omp_priv = & ! { dg-error "Different shape for array assignment at \[^\n\r]* on dimension 1 .9 and 10" }
-!$omp & fn6 (omp_orig)) ! { dg-warning "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
+!$omp & fn6 (omp_orig)) ! { dg-error "Actual argument contains too few elements for dummy argument \[^\n\r]* .9/10" }
   integer :: a(9)
 !$omp parallel reduction (foo : a)
 !$omp end parallel
--- ../_clean/gcc/testsuite/gfortran.dg/warn_argument_mismatch_1.f90	2016-11-02 16:00:00.000000000 +0100
+++ gcc/testsuite/gfortran.dg/warn_argument_mismatch_1.f90	2017-09-25 00:45:27.000000000 +0200
@@ -1,5 +1,5 @@
 ! { dg-do compile }
-! { dg-options "-Wno-argument-mismatch" }
+! { dg-options "-std=legacy -Wno-argument-mismatch" }
 !
 ! No warnings should be output here with -Wno-argument-mismatch.
 !

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA gfortran] PR 25071: dummy argument larger than actual argument
  2017-09-28 12:57 [RFA gfortran] PR 25071: dummy argument larger than actual argument Dominique d'Humières
@ 2017-09-29  8:09 ` Janne Blomqvist
  2017-09-29 13:07 ` Dominique d'Humières
  1 sibling, 0 replies; 4+ messages in thread
From: Janne Blomqvist @ 2017-09-29  8:09 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: Janus Weil, gfortran, gcc-patches

On Thu, Sep 28, 2017 at 3:57 PM, Dominique d'Humières
<dominiq@lps.ens.fr> wrote:
> Hi all,
>
> In the PR there was some consensus to turn the warnings into errors.
>
> This is what the patch does: the warnings are kept with -std=legacy, errors are emitted otherwise.
>  I am sure it may exist a better solution, but I did not find it.
>
> While regtesting I have found several regressions on top of gfortran.dg/warn_argument_mismatch_1.f90
>
> At this point, I had two options: use -std=legacy everywhere or replace the dg-warning with dg-error. I have chosen the later except for warn_argument_mismatch_1.f90.
>
> Regtested on x86_64-apple-darwin16.
>
> Comments are welcome and I’ll provide the change logs once the dust has settled.

Thanks for picking this up. I do think your solution is good enough,
and I also agree with how you've dealt with the testsuite changes.

So from my point of view, Ok for trunk along with a ChangeLog entry.



-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA gfortran] PR 25071: dummy argument larger than actual argument
  2017-09-28 12:57 [RFA gfortran] PR 25071: dummy argument larger than actual argument Dominique d'Humières
  2017-09-29  8:09 ` Janne Blomqvist
@ 2017-09-29 13:07 ` Dominique d'Humières
  2017-09-29 13:25   ` Dominique d'Humières
  1 sibling, 1 reply; 4+ messages in thread
From: Dominique d'Humières @ 2017-09-29 13:07 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Janus Weil, gfortran, gcc-patches

Thanks for the quick review. The change logs are

2017-09-29  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/25071
	* interface.c (compare_actual_formal): Change warnings to errors
	when "Actual argument contains too few elements for dummy
	argument", unless -std=legacy is used.

2017-09-29  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/25071
	* gfortran.dg/argument_checking_3.f90: Change warnings to errors.
	* gfortran.dg/argument_checking_4.f90: Likewise.
	* gfortran.dg/argument_checking_5.f90: Likewise.
	* gfortran.dg/argument_checking_6.f90: Likewise.
	* gfortran.dg/argument_checking_10.f90: Likewise.
	* gfortran.dg/argument_checking_13.f90: Likewise.
	* gfortran.dg/argument_checking_15.f90: Likewise.
	* gfortran.dg/argument_checking_18.f90: Likewise.
	* gfortran.dg/gomp/udr8.f90: Likewise.
	* gfortran.dg/warn_argument_mismatch_1.f90: Add -std=legacy to
	the dg-options.

Dominique

> Le 28 sept. 2017 à 14:57, Dominique d'Humières <dominiq@lps.ens.fr> a écrit :
> 
> Hi all,
> 
> In the PR there was some consensus to turn the warnings into errors. 
> 
> This is what the patch does: the warnings are kept with -std=legacy, errors are emitted otherwise.
> I am sure it may exist a better solution, but I did not find it. 
> 
> While regtesting I have found several regressions on top of gfortran.dg/warn_argument_mismatch_1.f90
> 
> At this point, I had two options: use -std=legacy everywhere or replace the dg-warning with dg-error. I have chosen the later except for warn_argument_mismatch_1.f90.
> 
> Regtested on x86_64-apple-darwin16.
> 
> Comments are welcome and I’ll provide the change logs once the dust has settled.
> 
> TIA
> 
> Dominique
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA gfortran] PR 25071: dummy argument larger than actual argument
  2017-09-29 13:07 ` Dominique d'Humières
@ 2017-09-29 13:25   ` Dominique d'Humières
  0 siblings, 0 replies; 4+ messages in thread
From: Dominique d'Humières @ 2017-09-29 13:25 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Janus Weil, gfortran, gcc-patches

Committed as revisions r253286 and r253287.

Dominique

 
> Le 29 sept. 2017 à 15:07, Dominique d'Humières <dominiq@lps.ens.fr> a écrit :
> 
> Thanks for the quick review. The change logs are
> 
> 2017-09-29  Dominique d'Humieres  <dominiq@lps.ens.fr>
> 
> 	PR fortran/25071
> 	* interface.c (compare_actual_formal): Change warnings to errors
> 	when "Actual argument contains too few elements for dummy
> 	argument", unless -std=legacy is used.
> 
> 2017-09-29  Dominique d'Humieres  <dominiq@lps.ens.fr>
> 
> 	PR fortran/25071
> 	* gfortran.dg/argument_checking_3.f90: Change warnings to errors.
> 	* gfortran.dg/argument_checking_4.f90: Likewise.
> 	* gfortran.dg/argument_checking_5.f90: Likewise.
> 	* gfortran.dg/argument_checking_6.f90: Likewise.
> 	* gfortran.dg/argument_checking_10.f90: Likewise.
> 	* gfortran.dg/argument_checking_13.f90: Likewise.
> 	* gfortran.dg/argument_checking_15.f90: Likewise.
> 	* gfortran.dg/argument_checking_18.f90: Likewise.
> 	* gfortran.dg/gomp/udr8.f90: Likewise.
> 	* gfortran.dg/warn_argument_mismatch_1.f90: Add -std=legacy to
> 	the dg-options.
> 
> Dominique
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-29 13:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-28 12:57 [RFA gfortran] PR 25071: dummy argument larger than actual argument Dominique d'Humières
2017-09-29  8:09 ` Janne Blomqvist
2017-09-29 13:07 ` Dominique d'Humières
2017-09-29 13:25   ` Dominique d'Humières

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).