From: Harald Anlauf Date: Thu, 3 Dec 2020 19:33:22 +0000 (+0100) Subject: PR fortran/95342 - ICE in gfc_match_subroutine, at fortran/decl.c:7913 X-Git-Tag: releases/gcc-10.3.0~542 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=316a185ee29c9e6ec060762e76d25b64c60fd665;p=thirdparty%2Fgcc.git PR fortran/95342 - ICE in gfc_match_subroutine, at fortran/decl.c:7913 Add checks for NULL pointers before dereferencing them. gcc/fortran/ChangeLog: PR fortran/95342 * decl.c (gfc_match_function_decl): Avoid NULL pointer dereference. (gfc_match_subroutine): Likewise. gcc/testsuite/ChangeLog: PR fortran/95342 * gfortran.dg/pr95342.f90: New test. (cherry picked from commit 30b606bb9b9314010a446ea4bed3481632008f75) --- diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index c1a15f1a84ae..9273976aa9a1 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -7390,6 +7390,7 @@ gfc_match_function_decl (void) procedure interface body. */ if (sym->attr.is_bind_c && sym->attr.module_procedure && sym->old_symbol && strcmp (sym->name, sym->old_symbol->name) == 0 + && sym->binding_label && sym->old_symbol->binding_label && strcmp (sym->binding_label, sym->old_symbol->binding_label) != 0) { const char *null = "NULL", *s1, *s2; @@ -7905,6 +7906,7 @@ gfc_match_subroutine (void) procedure interface body. */ if (sym->attr.module_procedure && sym->old_symbol && strcmp (sym->name, sym->old_symbol->name) == 0 + && sym->binding_label && sym->old_symbol->binding_label && strcmp (sym->binding_label, sym->old_symbol->binding_label) != 0) { const char *null = "NULL", *s1, *s2; diff --git a/gcc/testsuite/gfortran.dg/pr95342.f90 b/gcc/testsuite/gfortran.dg/pr95342.f90 new file mode 100644 index 000000000000..41c987d3bbbe --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr95342.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } +! PR fortran/95342 - ICE in gfc_match_subroutine, at fortran/decl.c:7913 + +module m1 + interface + module subroutine s() + end + subroutine s() bind(c) ! { dg-error "EXTERNAL attribute conflicts" } + end ! { dg-error "END INTERFACE" } + end interface +end + +module m2 + interface + module function f() + end + function f() bind(c) + end ! { dg-error "Duplicate EXTERNAL attribute" } + end interface +end