From patchwork Tue Dec 20 20:40:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 35188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3171216wrn; Tue, 20 Dec 2022 12:41:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXu0E4wSeSmwcdx+no7VnAVjDfIBx/VqvTo9IDnq3/NP7SvDv2VyX0igSudcAQMfZPrRoYQ8 X-Received: by 2002:a17:906:3c17:b0:7c0:dfb7:4476 with SMTP id h23-20020a1709063c1700b007c0dfb74476mr14617020ejg.57.1671568885107; Tue, 20 Dec 2022 12:41:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671568885; cv=none; d=google.com; s=arc-20160816; b=niBvygNeNyHdav8/mNtedP05qB6JkXfbIm2GW1+hSE7ScLLNAl9zYjOSneZWEz89XE UHlBtSHj/OdVeCRmgz6ARYgA7tIQkrlmHYvQfzOwNiqr+zOgOs4xWrpOGS4T0Mjc1eHL YrbIHfx4swuPABOXs9TKQrJOL3+CfHU7oIqtHrqh0iNv2JozM1elJmFxeoA/tdi9kZKQ tDhLTRmWgffRNLUKoV1+wI0M8VnKxWPgw3BZ7MkoVt+8/vKFkU42h0Oh1JPyck+jHWSr KW3P9lwyVqHwAM5dJx/NZZfgJWOzj0q1N+HeJZM+gTPgxCsatC5fMgdll7U4rsTausQx I+UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=HEk71N8AirA2iWSmkwpw33DF/nye7AuxBD0uONCh7yQ=; b=PxKPKteJ4vZFZ24LVY2ToPfBpN58v1dv6iHpkmK/9RozkX1K3szto1iQ+3gZ7iirCX 04jvcHjcF9syhVlr7I8AcEa4SIa6aFR/39LvDMvt721oIVWYcASPGGjz9HW+lhkmej8f vah7TnHd+mcbt++RWgu79Bmk0adWq3JVxSgyWPHkCfrI2Uov2wV2t7jBk8we1H2uHmLU csoAIlPycG3jlNITpu0uu1qIWRGIA7hUjho+RH0ruecaYq3C1faq5EGlk0N77xWcXV9w PyKqjOmODd6OwoOcC2A39Yd1BBtCbbmxk9/TKijyYKd4DOz8aJJer2GZ6R9BOs2WorfC TGmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oCVvyK36; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hr39-20020a1709073fa700b0078849a014e9si1423721ejc.196.2022.12.20.12.41.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 12:41:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oCVvyK36; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEB91385B510 for ; Tue, 20 Dec 2022 20:41:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEB91385B510 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671568883; bh=HEk71N8AirA2iWSmkwpw33DF/nye7AuxBD0uONCh7yQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oCVvyK36Yx0gDHphPGCRnJZDHkxcHNN5MDje6RnrJMd1o6jFnsC/DWzP6Kh4S2u4h GDxExPN6H0RDoRK/q/VvlRdtErcrgD26ehJeG0I3N2nNF8YYHPq2vnbcWECK0WwvdM dhgWApqmJgFID8ONJlrOWry7uCyOHd3Lt2icbmxc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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: To: fortran , gcc-patches Subject: [PATCH] Fortran: a C interoperable function cannot have the CLASS attribute [PR95375] Date: Tue, 20 Dec 2022 21:40:23 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:/KRmY4wDymDYr1pvMRHeFHForSgcFhMUKnTGtlCH6i4LqZgm+oM60cNceCybjYSNvJWMm jgXuvpRk2PQbmm5WK77H6PVojguqqhGHhJTf1bVxr/d1xqUPodpe3h9ZRpGJk5DFfVM8xnoHC1AN OmGXDa9LdN/193mPAlXyu5UPgBBl4aAA6oJ9KJboiS6RlGONR0NfMvJMAtyOlgp6AiLf5yeApTJN hk2IZzSyHfntV6/NDQDAmOAD19ZLIE8HtE1R+Zu7lgJQsVfeyoMDDJdNoJpiyAj4U2/Iffro7ia8 xU= UI-OutboundReport: notjunk:1;M01:P0:ZSLuoUeKlqU=;opTsf0K8lhU4ior3o07GICXVtyi PbgHqL9QXba/AUo/nFuLsWXGAi28ZrTEjS9CdxWyMrytCkVPSx9iODA3s4VfBZ1HVuw+SJj+o 7ZSe6mCZgqM5TJq+8dIy9/SEW/+1M7xtUC7AwdfV40XGeeytD3G1Krf7Kz2JbmNCo+AMqobSC jEw+aGWZfwcW9zbgyPcJmjCLgl8i6idUJ79qAwedigtapN72/taHMTFwRc06ec4x/Q5N2JlZM 60UMt99UNRsdjPj7il55XWq7r6VfvDdo7pXrA5/aBF3gn2iV9nkp66EFkLgpw54qCKfNvjDfA Zl6xv5b++k02gDnk317aeU4IOWiqnP8cvZ2bS6WLzTtitl9ugqpWfGTR7T/rSwkVCpbfJutEd IPVtLemJylpzzjyt17CGAR2YCDLZFLxDdxlyr/mHPPiv9UGeSipaI5f1P9nrP1Nt/43gDwuWM gVB3uburn2ROXffv61DLS1iIg0H+gLTCdTSyoAv0V89MCQVou1pQylXNMMIztsb00JohO6iNP SddVLtEEyQHUdLXr9+OJEyCvLUsvGruDQ8iGn6VYmE9/tDTvQEbwQXn1g4Xkz/OODaCiIsScR eYHkWOWKb1Iexkk/tfVjp1AHSVqpSvaNJm0eCIGj7ThYNMb1jbZXPiEy2x6NCR6jhA7k7LooZ +lnlGqxOn3jUWfXqrhEc0kMrQrRo8gn17W48E9U412Mhs32pEF/BK83QGvyF0+CqkFFO3TRX2 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752767015248623687?= X-GMAIL-MSGID: =?utf-8?q?1752767015248623687?= 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 From 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. --- 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 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -5998,10 +5998,14 @@ verify_bind_c_sym (gfc_symbol *tmp_sym, gfc_typespec *ts, } else { - if (tmp_sym->ts.type == BT_DERIVED || ts->type == BT_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 == BT_DERIVED || ts->type == BT_DERIVED + || tmp_sym->ts.type == BT_CLASS || ts->type == 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 = 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 --- /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() /= 0 ) stop +end + +! { dg-prune-output "Type mismatch" } -- 2.35.3