From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id F40A43857838; Tue, 20 Dec 2022 20:40:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F40A43857838 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1671568823; bh=8uugnPHm21uggl5EQ0hJ4rc66MZLEiW8OoZhIQlz0K4=; h=X-UI-Sender-Class:From:To:Subject:Date; b=BftoywHvdmqmtMJiqzadwDLJrLj+Se4QPraHV+u86GJa/x8htpCSLZqNxUOUFQ3Lx yqAb2AwcImbzgrVN4tgjGQyWF7v8hXtLaX8j9OF+LumgB094AHXtFILyTk4RK7GhXO ka3vsbY9Vgl6UR9w+buu0+mwbLoR1K5kA19QbaEol8zGI5c22Ry8aG6QMrw1AWMgum bOKVRCt8ASBLZwLgB1FG95DrOURE/Z8EHAkExfvO/WfVhFvc+3ntvDYvOKiGd7Tlv+ DasbAI1J6mCcfZpvUHKwqfxbinVq1h12/hXuQM1CaYqYBBlduJY1fyjPUVYApMeiAD h9bXYnUXg/dUQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.80.44] ([93.207.80.44]) by web-mail.gmx.net (3c-app-gmx-bs49.server.lan [172.19.170.102]) (via HTTP); Tue, 20 Dec 2022 21:40:23 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: a C interoperable function cannot have the CLASS attribute [PR95375] Content-Type: multipart/mixed; boundary=refeik-c9c89582-b33b-489f-a940-197a90635d07 Date: Tue, 20 Dec 2022 21:40:23 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:/KRmY4wDym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O3TRX2 85u0P9PEKYSAvbg7ucNzjCIJZqVmQRza5EO+8ai+v99vcmDMO1+/Lm8Wp4Z2mbJo7c8MfWsfE UXeV/Z5Q+GpbwgRUMKhXPCsK4KB1VAgKbMrylPlM/FFGk= X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --refeik-c9c89582-b33b-489f-a940-197a90635d07 Content-Type: text/plain; charset=UTF-8 Dear all, we obviously forgot to extend the C interoperability check of the type of function results to CLASS variables and thus did not reject them. Wrong code could lead to an ICE, see testcase by Gerhard. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --refeik-c9c89582-b33b-489f-a940-197a90635d07 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr95375.diff Content-Transfer-Encoding: quoted-printable =46rom dc22544c2412cf8810a4956f537a2f50e0711a05 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 20 Dec 2022 21:17:08 +0100 Subject: [PATCH] Fortran: a C interoperable function cannot have the CLASS attribute [PR95375] gcc/fortran/ChangeLog: PR fortran/95375 * decl.cc (verify_bind_c_sym): Extend interoperability check to CLASS variables. gcc/testsuite/ChangeLog: PR fortran/95375 * gfortran.dg/bind_c_procs_4.f90: New test. =2D-- gcc/fortran/decl.cc | 12 ++++++++---- gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 1562dc22bc6..e593518a77e 100644 =2D-- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -5998,10 +5998,14 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typesp= ec *ts, } else { - if (tmp_sym->ts.type =3D=3D BT_DERIVED || ts->type =3D=3D B= T_DERIVED) - gfc_error ("Type declaration %qs at %L is not C " - "interoperable but it is BIND(C)", - tmp_sym->name, &(tmp_sym->declared_at)); + if (tmp_sym->ts.type =3D=3D BT_DERIVED || ts->type =3D=3D BT_DERIV= ED + || tmp_sym->ts.type =3D=3D BT_CLASS || ts->type =3D=3D BT_CLASS) + { + gfc_error ("Type declaration %qs at %L is not C " + "interoperable but it is BIND(C)", + tmp_sym->name, &(tmp_sym->declared_at)); + retval =3D false; + } else if (warn_c_binding_type) gfc_warning (OPT_Wc_binding_type, "Variable %qs at %L " "may not be a C interoperable " diff --git a/gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 b/gcc/testsuite/= gfortran.dg/bind_c_procs_4.f90 new file mode 100644 index 00000000000..407d8bb9afc =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_procs_4.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! PR fortran/95375 - ICE in add_use_op +! Contributed by G.Steinmetz + +function f() result(n) bind(c) ! { dg-error "not C interoperable" } + class(*), allocatable :: n +end +program p + interface + function f() result(n) bind(c) + integer :: n + end + end interface + if ( f() /=3D 0 ) stop +end + +! { dg-prune-output "Type mismatch" } =2D- 2.35.3 --refeik-c9c89582-b33b-489f-a940-197a90635d07--