From patchwork Wed Feb 12 20:49:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry D X-Patchwork-Id: 106403 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 808853858C35 for ; Wed, 12 Feb 2025 20:50:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 808853858C35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iuBiN1Ii X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 64FD43858C42; Wed, 12 Feb 2025 20:49:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64FD43858C42 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 64FD43858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739393366; cv=none; b=c0cg2Tjb1gf82BvBhIJRVp6Eyj9xInCJBGywyFtEs5js9iR7/VX5q+13Uv3kgn11TIEAPHuWhZUqBAe+MrHMnmgADRsyyp7huJnN0b6kt788c1uSDCjlO27Bt1l/M4nwQV1TUuh42pbFzvy6jVQXW6NpCAAvIVAnriMrjCVpGTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739393366; c=relaxed/simple; bh=OVrOX6W8Z4FypON38Sq/daP/1Y/oLRYXGW8tK7pTlZo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=JgDGPbwz/nAd9SbEZ00tPhIOR41+gzSU40G8GtGPJ8+tl4D3vC01RojIAIWT4amU6iBiKLoE4Snt6ZNDTxiJI363r0R7QUeNlwi9Qog1BsGdvukYYfoSeA/F+M1oIY4rCxF3FAG2BhgIgEuoWjettRJAgY6p0HR/suboq3I8b04= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64FD43858C42 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-21f6d2642faso2544555ad.1; Wed, 12 Feb 2025 12:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739393364; x=1739998164; darn=gcc.gnu.org; h=autocrypt:subject:from:to:content-language:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Nvv1o+pgJrGVjvPGlChxRQjmTqfTaCORtIknckfSrw4=; b=iuBiN1Ii8IXe3tthilCzIspYk8vC4DKDjZ/FNISVCUXemuF8LXFTbCLBczdBK9ydu/ fMRfm23lnsWxKsVL3qeIgHbKd8CvRLgKzATQBipK+89f836qBmdygAVWcp9TSNpcJ0o6 vGBFO62s4Xfra9T68KVPDBSpU32huYd9vr6BQZ/z0GAvSEy9aENwzabah8pgb9/gSLRW c69+9JpjFAUAsHvI+eiaKlfDQXhuU1mx0U091oWosgxYoeLe1b1F5PkoKBrG0S9qRF3Z 6vjrUXY3Gz7wuN++nlwQavhukJuJuWzKnFxhuStkJJHjahg6y1Z17JxSFQ6Yd//nP4Rt 90dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739393364; x=1739998164; h=autocrypt:subject:from:to:content-language:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Nvv1o+pgJrGVjvPGlChxRQjmTqfTaCORtIknckfSrw4=; b=FKydVL9Phe8yKel1gPJzCQ7oIV7+FhQ3uQJEP+miblo7UzRiG5oX3qULaJo9nExkpk YkTcDXGc6tFecuHuHpslFoudARB7ZY4HfpAd7QWyOJMrpQHUSoFFdZWscGNsVIxOpPG0 Fu5tpfkjO380rv0w9vHXVnm8Aj0gZdBSkvMy0mmzgKKqzPepbMKQeyfk8HY14KL+s3C9 H/ay1NPIKuhjTLsFkNbFomBHAvaiB/1gQynEogAA7tV32e+iuj0PU8sjKPgourSzgPk9 hYvRrNrRvGWctzNchdGIhosU4qjnsXBJ9pwS+PyU8y9k+AkflCk3UzHmavE+CK5xbSHO Zq3g== X-Forwarded-Encrypted: i=1; AJvYcCXqrHf+FquPNP0v6AQRgCSdiOa3YY2ceTTEg9qu8FT+KO5xBz6BtGztJKdv53IaBUNlC4ZAsFZezlukeA==@gcc.gnu.org X-Gm-Message-State: AOJu0Yw9HFa08E2vbljeH4tZbSSj6eOdgZCp2nL5BPgf8/l4edNJ8qIn m9IxK0WQIsVie6rHbLZu5Rmr3h64s6kGoiwn8MADeY43oO5sJV2Ih8EBwg== X-Gm-Gg: ASbGncuR2k3bW0CoOGnYistpPMNSQkxof5e3tCd3iIr/AXi6EyDm4AMqh4RVgE3SWAr WZ3NboYlwTWTvHYeNM01XCC3ns3nMiwgbW7Yr4Xpb/0BpDu/2w6S7bIdip7hocWMnS+8xafnCFc 9qn05lr/Ktb2fkfiS2PfFE8Oah9LemQhS1shA5N3rSPkLb75/c1sDqqdiw7GeUgiYetg9dAOCUK HjIgmFnNTssCV14uEIIjhg3sQCgTmSpqUOKJtftKaF7WmjtaKKRjV0ovZHWsu3UVIj+dNWW0Cnv D6ViGmJ5mS7r0dj+mxk= X-Google-Smtp-Source: AGHT+IF5Szr5yeS2Lg0WMpN1n8qzQfEgJwpAk7Wo3mF9E2NOLk8WjO0kT349uzL0mvChoihSDeAHHw== X-Received: by 2002:a05:6a00:1804:b0:732:24ad:8e15 with SMTP id d2e1a72fcca58-7322c39ac1amr7071886b3a.11.1739393364326; Wed, 12 Feb 2025 12:49:24 -0800 (PST) Received: from [192.168.0.149] ([50.37.189.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7309709027bsm5181047b3a.44.2025.02.12.12.49.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Feb 2025 12:49:23 -0800 (PST) Message-ID: Date: Wed, 12 Feb 2025 12:49:22 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gfortran , gcc-patches From: Jerry D Subject: [patch, fortran] PR117430 gfortran allows type(C_ptr) in I/O list Autocrypt: addr=jvdelisle2@gmail.com; keydata= xjMEY5TlkxYJKwYBBAHaRw8BAQdAyrkRDhmJhSTTlV/50gJLlvliU6/Lm5C9ViKV8T9y1GnN HkplcnJ5IEQgPGp2ZGVsaXNsZTJAZ21haWwuY29tPsKJBBMWCAAxFiEEOFR0TS0390uh8dRV uWXAJaWpwWoFAmOU5ZMCGwMECwkIBwUVCAkKCwUWAgMBAAAKCRC5ZcAlpanBalsJAP4wdCiH 2Of9oZv1QWgZ/AVdbWFM3Fv47/WZQHOXfoZ9HgD6AkXrKeJ+6usST7PEaDJjptaViT1fLiYY V/6XaOKSsgLOOARjlOWTEgorBgEEAZdVAQUBAQdAdA7PczYnl07vnOT9oP/wvvMDd4HP09Zl g3LzwXQJWT8DAQgHwngEGBYIACAWIQQ4VHRNLTf3S6Hx1FW5ZcAlpanBagUCY5TlkwIbDAAK CRC5ZcAlpanBasF/AQCa5WjlsVpLsEiggZyT18MOJNAdeRd7wkGDUrwedHrvawD/cE1H+/Ms L1ZwvQiLfGdx8crigQqWTQyos4kH8Wx82wc= X-Spam-Status: No, score=-8.2 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, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org The attached patch is fairly obvious. The use of notify_std is changed to a gfc_error. Several test cases had to be adjusted. Regression tested on x86_64. OK for trunk? Regards, Jerry Author: Jerry DeLisle Date: Tue Feb 11 20:57:50 2025 -0800 Fortran: gfortran allows type(C_ptr) in I/O list Before this patch, gfortran was accepting invalid use of type(c_ptr) in I/O statements. The fix affects several existing test cases so no new test case needed. Existing tests were modified to pass by either using the transfer function to convert to an acceptable value or using an assignment to a like type (non-I/O). PR fortran/117430 gcc/fortran/ChangeLog: * resolve.cc (resolve_transfer): Issue the error with no exceptions allowed. gcc/testsuite/ChangeLog: * gfortran.dg/c_loc_test_17.f90: Modify to pass. * gfortran.dg/c_ptr_tests_10.f03: Likewise. * gfortran.dg/c_ptr_tests_16.f90: Likewise. * gfortran.dg/c_ptr_tests_9.f03: Likewise. * gfortran.dg/init_flag_17.f90: Likewise. * gfortran.dg/pr32601_1.f03: Likewise. diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 1a4799dac78..3d3f117216c 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -11824,8 +11824,8 @@ resolve_transfer (gfc_code *code) the component to be printed to help debugging. */ if (ts->u.derived->ts.f90_type == BT_VOID) { - if (!gfc_notify_std (GFC_STD_GNU, "Data transfer element at %L " - "cannot have PRIVATE components", &code->loc)) + gfc_error ("Data transfer element at %L " + "cannot have PRIVATE components", &code->loc); return; } else if (derived_inaccessible (ts->u.derived) && dtio_sub == NULL) diff --git a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90 b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90 index 4c2a7d657ee..92bfca4363d 100644 --- a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90 +++ b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90 @@ -1,5 +1,4 @@ ! { dg-do compile } -! { dg-options "" } ! ! PR fortran/56378 ! PR fortran/52426 @@ -24,5 +23,5 @@ contains end module use iso_c_binding -print *, c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have either the POINTER or the TARGET attribute" } +i = c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have either the POINTER or the TARGET attribute" } end diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03 b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03 index 4ce1c6809e4..834570cb74d 100644 --- a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03 +++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03 @@ -1,5 +1,4 @@ ! { dg-do run } -! { dg-options "-std=gnu" } ! This test case exists because gfortran had an error in converting the ! expressions for the derived types from iso_c_binding in some cases. module c_ptr_tests_10 @@ -7,7 +6,7 @@ module c_ptr_tests_10 contains subroutine sub0() bind(c) - print *, 'c_null_ptr is: ', c_null_ptr + print *, 'c_null_ptr is: ', transfer (cptr, C_LONG_LONG) end subroutine sub0 end module c_ptr_tests_10 diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 b/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 index 68c1da161a0..d1f74857c78 100644 --- a/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 +++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 @@ -22,13 +22,13 @@ end program test subroutine bug1 use ISO_C_BINDING implicit none - type(c_ptr) :: m + type(c_ptr) :: m, i type mytype integer a, b, c end type mytype type(mytype) x print *, transfer(32512, x) ! Works. - print *, transfer(32512, m) ! Caused ICE. + i = transfer(32512, m) ! Caused ICE. end subroutine bug1 subroutine bug6 diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03 b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03 index 5a32553b8c5..711b9c157d4 100644 --- a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03 +++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03 @@ -16,9 +16,9 @@ contains type(myF90Derived), pointer :: my_f90_type_ptr my_f90_type%my_c_ptr = c_null_ptr - print *, 'my_f90_type is: ', my_f90_type%my_c_ptr + print *, 'my_f90_type is: ', transfer(my_f90_type%my_c_ptr, C_LONG_LONG) my_f90_type_ptr => my_f90_type - print *, 'my_f90_type_ptr is: ', my_f90_type_ptr%my_c_ptr + print *, 'my_f90_type_ptr is: ', transfer(my_f90_type_ptr%my_c_ptr, C_LONG_LONG) end subroutine sub0 end module c_ptr_tests_9 diff --git a/gcc/testsuite/gfortran.dg/init_flag_17.f90 b/gcc/testsuite/gfortran.dg/init_flag_17.f90 index 401830fccbc..8bb9f7b1ef7 100644 --- a/gcc/testsuite/gfortran.dg/init_flag_17.f90 +++ b/gcc/testsuite/gfortran.dg/init_flag_17.f90 @@ -19,8 +19,8 @@ program init_flag_17 type(ty) :: t - print *, t%ptr - print *, t%fptr + print *, transfer(t%ptr, c_long_long) + print *, transfer(t%fptr, c_long_long) end program diff --git a/gcc/testsuite/gfortran.dg/pr32601_1.f03 b/gcc/testsuite/gfortran.dg/pr32601_1.f03 index a297e1728ec..1a48419112d 100644 --- a/gcc/testsuite/gfortran.dg/pr32601_1.f03 +++ b/gcc/testsuite/gfortran.dg/pr32601_1.f03 @@ -4,9 +4,9 @@ ! PR fortran/32601 use, intrinsic :: iso_c_binding, only: c_loc, c_ptr implicit none - +integer i ! This was causing an ICE, but is an error because the argument to C_LOC ! needs to be a variable. -print *, c_loc(4) ! { dg-error "shall have either the POINTER or the TARGET attribute" } +i = c_loc(4) ! { dg-error "shall have either the POINTER or the TARGET attribute" } end