From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 6DF153894C1F; Thu, 14 Jan 2021 03:42:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6DF153894C1F Received: by mail-pf1-x436.google.com with SMTP id b3so2576002pft.3; Wed, 13 Jan 2021 19:42:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=XewtP6wKAD9qPyNI5oB3Big22liF5VHnalmg4KR4PCo=; b=Dpomg2vzlAUHTy6c9gkbFt+6pzsbYQmGTqbpetafAswinkvY5PF5cqaciEagkDT8Vm P+0QQeIxhfOzpTRtMC2b7z5VAx4b62aRgJxt9fhcOHKOlmlmo96FfEfaurTgl66qUtYQ W67StS1X0abHa/Td/MDJTZJM04er2G6vFzz9OV7zPuRVe6sVtQqF4iJi+OCbX8cVRag8 IMCr3bWgW/5zADuDF6KdvzsW4W6+jKWBr2JkXBxyZkx+10svypWYM33VNT+mwkSMlkx6 V/J+GB36SC/ki1UEPPcA0ZkW4T8kF/4MZP2PSVQaZ6egls+6Y6U5YcPHl/j2jMDcPTgE l4Iw== X-Gm-Message-State: AOAM5319UdR2NCsl3hvCyd5tdrQh0U0+lo4bgnBmS1siW13w7gcfEJIz CX4QZ/52WGXqZa47m9Kl//i+/6//whhP9A== X-Google-Smtp-Source: ABdhPJyelSHF9SjE9PxbSuzP261eXF+Any5EW7kmvk88qEO75Yl35mwokAqm4gPsPuUDFsezMy74ww== X-Received: by 2002:a62:33c5:0:b029:1a1:c2f2:d771 with SMTP id z188-20020a6233c50000b02901a1c2f2d771mr5673072pfz.29.1610595741710; Wed, 13 Jan 2021 19:42:21 -0800 (PST) Received: from ?IPv6:2600:6c54:7a00:c2b4:9e30:5bff:fea3:6d6f? ([2600:6c54:7a00:c2b4:9e30:5bff:fea3:6d6f]) by smtp.gmail.com with ESMTPSA id c5sm4175753pjo.4.2021.01.13.19.42.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Jan 2021 19:42:20 -0800 (PST) Subject: Re: [PATCH, Fortran] PR fortran/93524 - ISO_Fortran_binding signed char arrays To: Harris Snyder , fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org References: <8D9008DE-BC31-42DA-AFAD-EF665920E20A@structura.bio> From: Jerry DeLisle Message-ID: Date: Wed, 13 Jan 2021 19:42:18 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jan 2021 03:42:25 -0000 Looks good and I have tested. I will commit after one more double check for regressions with the test case in the testsuite I have been following Harris on this one for several days and tested the patch before submitted here. Thanks for patch Harris, much appreciated. Regards, Jerry On 1/13/21 8:02 AM, Harris Snyder wrote: > On Wed, Jan 13, 2021 at 1:34 AM Harris Snyder wrote: >> Hi everyone, >> >> Sorry, my previous email erroneously referred to unsigned chars / uint8_t, >> when I in fact meant signed chars / int8_t. The actual patch works, but the >> test case files have ‘uint’ in the file names. I’ll provide a corrected patch >> tomorrow to fix the file names. >> >> Harris > Corrected patch below. > > OK for master? I don't have write access so I will need someone else > to commit this for me if possible. > > Thanks, > Harris Snyder > > > Fixes a bug in ISO_Fortran_binding.c whereby signed char or int8_t > arrays would cause crashes unless an element size is specified. > Related to PR fortran/93524. > > libgfortran/ChangeLog: > > * runtime/ISO_Fortran_binding.c (CFI_establish): fixed signed char arrays. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/iso_fortran_binding_int8_array.f90: New test. > * gfortran.dg/iso_fortran_binding_int8_array_driver.c: New test. > > diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array.f90 > b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array.f90 > new file mode 100644 > index 00000000000..31fdf863e0a > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array.f90 > @@ -0,0 +1,11 @@ > +! { dg-do run } > +! { dg-additional-sources iso_fortran_binding_int8_array_driver.c } > + > +module m > + use iso_c_binding > +contains > + subroutine fsub( x ) bind(C, name="fsub") > + integer(c_int8_t), intent(inout) :: x(:) > + x = x+1 > + end subroutine > +end module > diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array_driver.c > b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array_driver.c > new file mode 100644 > index 00000000000..84ed127d525 > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_int8_array_driver.c > @@ -0,0 +1,25 @@ > +#include > +#include > +#include > +#include "ISO_Fortran_binding.h" > + > +extern void fsub(CFI_cdesc_t *); > + > +int main(void) > +{ > + int8_t x[] = {1,2,3,4}; > + int N = sizeof(x)/sizeof(x[0]); > + > + CFI_CDESC_T(1) dat; > + CFI_index_t ext[1]; > + ext[0] = (CFI_index_t)N; > + int rc = CFI_establish((CFI_cdesc_t *)&dat, &x, CFI_attribute_other, > + CFI_type_int8_t, 0, (CFI_rank_t)1, ext); > + printf("CFI_establish call returned: %d\n", rc); > + > + fsub((CFI_cdesc_t *)&dat ); > + > + for (int i=0; i + printf("%"PRId8"\n", x[i]); > + return 0; > +} > diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90 > b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array.f90 > deleted file mode 100644 > index e69de29bb2d..00000000000 > diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c > b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c > deleted file mode 100644 > index e69de29bb2d..00000000000 > diff --git a/libgfortran/runtime/ISO_Fortran_binding.c > b/libgfortran/runtime/ISO_Fortran_binding.c > index 86ff25afb23..3746ec1c681 100644 > --- a/libgfortran/runtime/ISO_Fortran_binding.c > +++ b/libgfortran/runtime/ISO_Fortran_binding.c > @@ -345,8 +345,7 @@ int CFI_establish (CFI_cdesc_t *dv, void > *base_addr, CFI_attribute_t attribute, > dv->base_addr = base_addr; > > if (type == CFI_type_char || type == CFI_type_ucs4_char || > - type == CFI_type_signed_char || type == CFI_type_struct || > - type == CFI_type_other) > + type == CFI_type_struct || type == CFI_type_other) > dv->elem_len = elem_len; > else > {