public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
@ 2021-11-30 13:54 burnus at gcc dot gnu.org
  2021-11-30 20:14 ` [Bug fortran/103496] " anlauf at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-11-30 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

            Bug ID: 103496
           Summary: [F2018][TS29113] C_SIZEOF – rejects now valid args
                    with 'must be an interoperable data entity'
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

The following should now be fine – using an array descriptor as defined in
TS29113 / F2018:

    8 | print *, c_sizeof(a(:))
      |                  1
Error: ‘x’ argument of ‘c_sizeof’ intrinsic at (1) must be an interoperable
data entity: Only whole-arrays are interoperable

   12 | print *, c_sizeof(p)
      |                  1
Error: ‘x’ argument of ‘c_sizeof’ intrinsic at (1) must be an interoperable
data entity: Only explicit-size and assumed-size arrays are interoperable

----------------------
use iso_c_binding
implicit none
integer :: a(6)
integer, pointer :: p(:)

print *, c_sizeof(a)       ! 6*4 - OK
print *, c_sizeof(a(1))    !   4 - OK
print *, c_sizeof(a(:))    ! 6*4 - OK, rejected
print *, c_sizeof(a(2::2)) ! 3*4 - rejected

allocate(p(5))
print *, c_sizeof(p)       ! 5*4 - rejected
print *, c_sizeof(p(1))    !   4 - OK
print *, c_sizeof(p(:))    ! 5*4 - rejected
print *, c_sizeof(p(2::2)) ! 2*4 - rejected
end

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
@ 2021-11-30 20:14 ` anlauf at gcc dot gnu.org
  2021-11-30 21:02 ` burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-11-30 20:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #1 from anlauf at gcc dot gnu.org ---
I learned from Steve that there is a recent interp regarding C_SIZEOF
arguments,

https://j3-fortran.org/doc/year/21/21-134r2.txt

but it still requires using interoperable types etc.

Just asking: did you simply forget to "decorate" your declarations?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
  2021-11-30 20:14 ` [Bug fortran/103496] " anlauf at gcc dot gnu.org
@ 2021-11-30 21:02 ` burnus at gcc dot gnu.org
  2024-04-10 17:19 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-11-30 21:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to anlauf from comment #1)
> https://j3-fortran.org/doc/year/21/21-134r2.txt
> but it still requires using interoperable types etc.
> Just asking: did you simply forget to "decorate" your declarations?

If you talk about something like 'kind=c_int': On most systems, c_int ==
c_int32_t == 4 - and gfortran has (by default) a default integer == 4. But also
'kind=8' is very likely to be interoperable; whether it is with c_long or only
c_int64_t or ... does not really matter in case of c_sizeof – we just need to
know that some C type exists, which is interoperable.
[Likewise,  integer(kind=c_int128_t)  may or may not be interoperable,
depending whether that kind is available - and if not, c_int128_t should be a
negative number. (Ignoring for now that c_int128_t is a vendor extension.)]

But granted, usually you want to be sure that kind matches a specific C integer
type and then c_... becomes useful and more portable.

 * * *

'interoperable type': I have to admit that I tend to get confused whether
* "18.3.5 Interoperability of array variables"
applies or whether also
* "18.3.6 Interoperability of procedures and procedure interfaces"
applies. In the latter case, array descriptors are permitted - and that permits
allocatables, pointer, sub-sections etc. The former is more restrictive by only
permitting explicit shape or assumed size – while the latter permits more.

Given that the current wording for c_sizeof is about "that is not an
assumed-size array or an assumed-rank array that is associated with an
assumed-size array."
I think one reasonable reading is that 18.3.6 applies as 18.3.5 does not permit
assumed rank.

As 21-134r2 shows, the current wording is not ideal – but at the end, the
modification just implies that 18.3.5 applies (IMHO).

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
  2021-11-30 20:14 ` [Bug fortran/103496] " anlauf at gcc dot gnu.org
  2021-11-30 21:02 ` burnus at gcc dot gnu.org
@ 2024-04-10 17:19 ` anlauf at gcc dot gnu.org
  2024-04-12  8:59 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-10 17:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

--- Comment #3 from anlauf at gcc dot gnu.org ---
The code in comment#0 compiles at r14-9893-gded646c91d2c0f
and gives the indicated results.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-04-10 17:19 ` anlauf at gcc dot gnu.org
@ 2024-04-12  8:59 ` burnus at gcc dot gnu.org
  2024-04-12 19:18 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2024-04-12  8:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to anlauf from comment #3)
> The code in comment#0 compiles at r14-9893-gded646c91d2c0f
> and gives the indicated results.

which is the commit:
 Fortran: fix argument checking of intrinsics C_SIZEOF, C_F_POINTER [PR106500]

It looks as if the issue is fixed, but gfortran misses a tescast to check that
the obtained value is correct.

c_sizeof_7.f90 contains tests, but I think there should be a run time trst that
the obtained values are correct; I think some are constants such that  a
tree-dump scan test would work as well, but for the dynamic ones, a run time
test seems zo be easier than trying to capture the generated code...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-04-12  8:59 ` burnus at gcc dot gnu.org
@ 2024-04-12 19:18 ` anlauf at gcc dot gnu.org
  2024-04-23 18:25 ` cvs-commit at gcc dot gnu.org
  2024-04-23 18:28 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-12 19:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

--- Comment #5 from anlauf at gcc dot gnu.org ---
Created attachment 57937
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57937&action=edit
c_sizeof_8.f90

Here's a testcase derived from comment#0.

Feel free to adapt it to your meet your needs, and push it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-04-12 19:18 ` anlauf at gcc dot gnu.org
@ 2024-04-23 18:25 ` cvs-commit at gcc dot gnu.org
  2024-04-23 18:28 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-23 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:0bf94da59feab2c72a02c91df310a36d33dfd1f7

commit r14-10097-g0bf94da59feab2c72a02c91df310a36d33dfd1f7
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Apr 23 20:21:43 2024 +0200

    Fortran: check C_SIZEOF on additions from TS29113/F2018 [PR103496]

    gcc/testsuite/ChangeLog:

            PR fortran/103496
            * gfortran.dg/c_sizeof_8.f90: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/103496] [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity'
  2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-04-23 18:25 ` cvs-commit at gcc dot gnu.org
@ 2024-04-23 18:28 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-23 18:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103496

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #7 from anlauf at gcc dot gnu.org ---
Pushed testcase.  Closing.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-23 18:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 13:54 [Bug fortran/103496] New: [F2018][TS29113] C_SIZEOF – rejects now valid args with 'must be an interoperable data entity' burnus at gcc dot gnu.org
2021-11-30 20:14 ` [Bug fortran/103496] " anlauf at gcc dot gnu.org
2021-11-30 21:02 ` burnus at gcc dot gnu.org
2024-04-10 17:19 ` anlauf at gcc dot gnu.org
2024-04-12  8:59 ` burnus at gcc dot gnu.org
2024-04-12 19:18 ` anlauf at gcc dot gnu.org
2024-04-23 18:25 ` cvs-commit at gcc dot gnu.org
2024-04-23 18:28 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).