From patchwork Fri Nov 12 17:39:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1554496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=gTWgOntk; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrQsw4Vnhz9sCD for ; Sat, 13 Nov 2021 04:43:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E07B3857C53 for ; Fri, 12 Nov 2021 17:43:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E07B3857C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636738994; bh=qq46Ytw9gCNzVfaZjLuGT9J08ea+BrwnnbLhFMYFQmY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gTWgOntkEyaArU78VrcbUpQNnq89f2ZeN4UGf8uYlbh/31Gtj8DVNrkuctD0gSU4b KxeOxlN4PmXRY0S6765zOaFTxAPfySlcNVcMVALQTXjMYe7+Pb1lMGQIQsKeaIeA+4 03ppkXplVlClCFyFlQA5vGEm2QFv5U4Mw5aC+LxU= 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.17.20]) by sourceware.org (Postfix) with ESMTPS id 575F13858015; Fri, 12 Nov 2021 17:39:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 575F13858015 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.11.75] ([79.251.11.75]) by web-mail.gmx.net (3c-app-gmx-bap24.server.lan [172.19.172.94]) (via HTTP); Fri, 12 Nov 2021 18:39:48 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/102368 - Failure to compile program using the C_SIZEOF function in ISO_C_BINDING Date: Fri, 12 Nov 2021 18:39:48 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:pNQREE+iwSLT7DGnSlUxqAwc0UqKpOoKiXg7F+L2BnJU2FWWyFHN/+D9cDZmjWXP9TseZ 9INMjPIukI5C4FWOyA1T4lw0pvW//GhdBSivQ+y7dxaDQAZmlgo0T5RuDAyYDVaRaF6FXchFdE+Q 9wXXiXpqzkU6aTR3epmotj/xVd0MpBnQ8atRq+a+o7FC9TSL+juw9T4KxJ30FhBKzY5qgtliVstG h0s1BlCJJ//bso2PSxeGHrF9nXsnnt3pJBzKF3go+JMeDyU7y64XH3p/FXgVeLaxeH/80+M5zX6e GU= X-UI-Out-Filterresults: notjunk:1;V03:K0:FtiEi4iWI80=:s4dGvn/Tp6z6OnRDz833MM yY5/gzOV+3IBsnmGJFZ6Dn5L5GsRTLZAw++Z3iQPwVy2UpVH5z/l0ryYQ9Q92r+Nrv9Zev1U8 Zd45wfPN/bTahnRm6AhbaoaRGSXnW+IRGXee1mKoy6rfvU6UtuNJ95wzThrITL5EiPOODCdQ9 9lSrnbOc5VnMB19IOCb0C9v/zlBimMC167OChqfP243nt5M6QYmMtQNCzAb9R/2La2A2HU3rx GfQkbZ/3sUK3wms+RhFly5kU1TgVfA+XavSPiYd8Bgw4HLkpIQinbfotIx6Sq+t6ODGBR9hUI Uqage88rhokSuYm8C7Kiz630Ern0I0eRQcXWRc4ssVXMdOJipe8hDXpsByhUGQgD1M2Cb4iic nZ1tVEwxAC5qCM5QBUSjAuBdP/TTPlHMJ4txD2iy9VrKJe+blqQYJtIDRR/620atZDgtlcTh2 /+3yXz4iksuAIqjFYk6yklaOnVuiFz4u81pSIuc+aSDriUtDuByetbx5qHP06ghfWWyt2qOCd 3In/VBovudo6nArk+3Fq6fktADDbz65uJ7S2rCDwXHEP9bpSnrnKd7B1R9Jkx99a0ZOYXALDR 4niSycxVGbyX7kOuCfMZHvYpWF/yLjXxJc4genWxUZrulPwOAugyUFMcI1YrVIf9VHTDmUWWa 9iyiBXf2BbhI1a0wSR77VPPyvvLAt03VTwv5U8lEQuoT1UJvWzSn0tvccpEgMDEEZ44ZWJsEz 7zygIa6NmYBy5MY/KbPeJ4mFr5FxQqNLfiOwQspc7tzo4tUzUPTwrRXnI+Ii5huctzoY3O+uj 706rk1d X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Dear Fortranners, F2008:15.3.5 relaxed the condition on interoperable character variables and now allows values different from one. Similar text in F2018:18.3.4. This required an adjustment in the interoperability check. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 1fc44a5bf0b294021490f3c0a1539982a09000f5 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 12 Nov 2021 18:32:18 +0100 Subject: [PATCH] Fortran: fix interoperability check for character variables for F2008 gcc/fortran/ChangeLog: PR fortran/102368 * check.c (is_c_interoperable): F2008:15.3.5 relaxed the condition on interoperable character variables and allows values different from one. gcc/testsuite/ChangeLog: PR fortran/102368 * gfortran.dg/c_sizeof_7.f90: New test. --- gcc/fortran/check.c | 20 ++++++++++++++------ gcc/testsuite/gfortran.dg/c_sizeof_7.f90 | 13 +++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/c_sizeof_7.f90 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index ffa07b510cd..69a2e35e81b 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -5272,13 +5272,21 @@ is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr) && !gfc_simplify_expr (expr->ts.u.cl->length, 0)) gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed"); - if (!c_loc && expr->ts.u.cl - && (!expr->ts.u.cl->length - || expr->ts.u.cl->length->expr_type != EXPR_CONSTANT - || mpz_cmp_si (expr->ts.u.cl->length->value.integer, 1) != 0)) + if (!c_loc && expr->ts.u.cl) { - *msg = "Type shall have a character length of 1"; - return false; + bool len_ok = (expr->ts.u.cl->length + && expr->ts.u.cl->length->expr_type == EXPR_CONSTANT); + + /* F2003:15.2.1 required the length of a character variable to be one. + F2008:15.3.5 relaxed this to constant length. */ + if (len_ok && !(gfc_option.allow_std & GFC_STD_F2008)) + len_ok = mpz_cmp_si (expr->ts.u.cl->length->value.integer, 1) == 0; + + if (!len_ok) + { + *msg = "Type shall have a character length of 1"; + return false; + } } } diff --git a/gcc/testsuite/gfortran.dg/c_sizeof_7.f90 b/gcc/testsuite/gfortran.dg/c_sizeof_7.f90 new file mode 100644 index 00000000000..3cfa3371f72 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/c_sizeof_7.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! { dg-options "-std=f2008 -fdump-tree-original" } +! { dg-final { scan-tree-dump-times "_gfortran_stop_numeric" 0 "original" } } +! PR fortran/102368 + +program main + use, intrinsic :: iso_c_binding + implicit none + character(kind=c_char, len=*), parameter :: a = 'abc' + character(kind=c_char, len=8) :: b + if (c_sizeof (a) /= 3) stop 1 + if (c_sizeof (b) /= 8) stop 2 +end program main -- 2.26.2