[PATCH] Fortran: Diagnose all operands with constraint violations [PR101337]

Bernhard Reutner-Fischer rep.dot.nop@gmail.com
Sun Oct 31 19:50:59 GMT 2021


From: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>

	PR fortran/101337

gcc/fortran/ChangeLog:

	* resolve.c (resolve_operator): Continue resolving on op2 error.

---
The PR rightfully notes that we only diagnose the right operator
and do not check the left operator if the right one was faulty.

c407b-2 is one of the testcases with respective XFAILs.
Since that testcase is rather big (and full of errors) i'm listing an
abbreviated version here, including the output we'd generate with the
attached patch.

Note: I did not address the XFAILs! Sandra, please take over if you like
      the patch!

Bootstrapped and regtested without new regressions (XFAILs are
apparently ignored and not flagged if they are auto-fixed).
As said, Sandra please take over, i'm deleting this locally.

$ cat c407b-2-b.f90;echo EOF; gfortran -c c407b-2-b.f90
subroutine s2 (x, y)
  implicit none
  type(*) :: x, y
  integer :: i

  ! relational operations
  if (x & ! { dg-error "Assumed.type" "pr101337, failure to diagnose both operands" { xfail *-*-*} }
      .eq. y) then  ! { dg-error "Assumed.type" }
    return
  end if
  if (.not. (x & ! { dg-error "Assumed.type" "pr101337, failure to diagnose both operands" { xfail *-*-*} }
             .ne. y)) then  ! { dg-error "Assumed.type" }
    return
  end if
  i = (x & ! { dg-error "Assumed.type" "pr101337, failure to diagnose both operands" { xfail *-*-*} }
       + y)  ! { dg-error "Assumed.type" }

end subroutine
EOF
c407b-2-b.f90:8:10:

    8 |       .eq. y) then  ! { dg-error "Assumed.type" }
      |          1
Error: Assumed-type variable y at (1) may only be used as actual argument
c407b-2-b.f90:7:6:

    7 |   if (x & ! { dg-error "Assumed.type" "pr101337, failure to diagnose both operands" { xfail *-*-*} }
      |      1
Error: Assumed-type variable x at (1) may only be used as actual argument
c407b-2-b.f90:12:17:

   12 |              .ne. y)) then  ! { dg-error "Assumed.type" }
      |                 1
Error: Assumed-type variable y at (1) may only be used as actual argument
c407b-2-b.f90:11:13:

   11 |   if (.not. (x & ! { dg-error "Assumed.type" "pr101337, failure to diagnose both operands" { xfail *-*-*} }
      |             1
Error: Assumed-type variable x at (1) may only be used as actual argument
c407b-2-b.f90:16:10:

   16 |        + y)  ! { dg-error "Assumed.type" }
      |          1
Error: Assumed-type variable y at (1) may only be used as actual argument
c407b-2-b.f90:15:7:

   15 |   i = (x & ! { dg-error "Assumed.type" "pr101337, failure to diagnose both operands" { xfail *-*-*} }
      |       1
Error: Assumed-type variable x at (1) may only be used as actual argument
---
 gcc/fortran/resolve.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 1f4abd08720..705d2326a29 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -4064,7 +4064,7 @@ resolve_operator (gfc_expr *e)
     {
     default:
       if (!gfc_resolve_expr (e->value.op.op2))
-	return false;
+	t = false;
 
     /* Fall through.  */
 
@@ -4091,6 +4091,9 @@ resolve_operator (gfc_expr *e)
   op2 = e->value.op.op2;
   if (op1 == NULL && op2 == NULL)
     return false;
+  /* Error out if op2 did not resolve. We already diagnosed op1.  */
+  if (t == false)
+    return false;
 
   dual_locus_error = false;
 
-- 
2.33.0



More information about the Gcc-patches mailing list