]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: avoid NULL pointer dereference on bad EQUIVALENCEs [PR107559]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 9 Nov 2022 20:05:28 +0000 (21:05 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 9 Nov 2022 20:05:28 +0000 (21:05 +0100)
gcc/fortran/ChangeLog:

PR fortran/107559
* resolve.cc (resolve_equivalence): Avoid NULL pointer dereference
while emitting diagnostics for bad EQUIVALENCEs.

gcc/testsuite/ChangeLog:

PR fortran/107559
* gfortran.dg/pr107559.f90: New test.

gcc/fortran/resolve.cc
gcc/testsuite/gfortran.dg/pr107559.f90 [new file with mode: 0644]

index 9202e2f10ad6d27bb90100fd0936523b98bf1d39..5ff1cd070ac14a1eb4ffd91f91f92a1898bdc388 100644 (file)
@@ -17218,6 +17218,7 @@ resolve_equivalence (gfc_equiv *eq)
            "statement at %L with different type objects";
       if ((object ==2
           && last_eq_type == SEQ_MIXED
+          && last_where
           && !gfc_notify_std (GFC_STD_GNU, msg, first_sym->name, last_where))
          || (eq_type == SEQ_MIXED
              && !gfc_notify_std (GFC_STD_GNU, msg, sym->name, &e->where)))
@@ -17227,6 +17228,7 @@ resolve_equivalence (gfc_equiv *eq)
            "statement at %L with objects of different type";
       if ((object ==2
           && last_eq_type == SEQ_NONDEFAULT
+          && last_where
           && !gfc_notify_std (GFC_STD_GNU, msg, first_sym->name, last_where))
          || (eq_type == SEQ_NONDEFAULT
              && !gfc_notify_std (GFC_STD_GNU, msg, sym->name, &e->where)))
diff --git a/gcc/testsuite/gfortran.dg/pr107559.f90 b/gcc/testsuite/gfortran.dg/pr107559.f90
new file mode 100644 (file)
index 0000000..714e236
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+! PR fortran/107559 - ICE in resolve_equivalence
+! Contributed by G.Steinmetz
+
+module m
+  implicit none
+  integer, protected :: a ! { dg-error "Fortran 2003: PROTECTED attribute" }
+  integer :: b
+  equivalence (a, b)      ! { dg-error "has no IMPLICIT type" }
+end