public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
@ 2024-06-07 22:15 daklishch at gmail dot com
  2024-06-07 23:30 ` [Bug fortran/115390] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: daklishch at gmail dot com @ 2024-06-07 22:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115390
           Summary: Bogus -Wuninitialized warning when using CHARACTER(*)
                    argument in BIND(C) function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daklishch at gmail dot com
  Target Milestone: ---

The following code produces -Wuninitialized warning when compiled with -Wall.

MODULE test
IMPLICIT NONE
CONTAINS
    SUBROUTINE foo(s)
        CHARACTER(*), INTENT(IN) :: s
    END

    SUBROUTINE bar(s) BIND(C)
        CHARACTER(*), INTENT(IN) :: s
        CALL foo(s)
    END
END

Quick look at the tree right after the frontend reveals that indeed, something
fishy is going on.

Godbolt link: https://godbolt.org/z/TfnKb1fPT

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

* [Bug fortran/115390] Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
  2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
@ 2024-06-07 23:30 ` pinskia at gcc dot gnu.org
  2024-06-08 19:51 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-07 23:30 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-06-07
           Keywords|                            |diagnostic, wrong-code
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug fortran/115390] Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
  2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
  2024-06-07 23:30 ` [Bug fortran/115390] " pinskia at gcc dot gnu.org
@ 2024-06-08 19:51 ` anlauf at gcc dot gnu.org
  2024-06-17 21:06 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-06-08 19:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from anlauf at gcc dot gnu.org ---
Slightly rewritten (we only need the interface of foo):

module test
  implicit none
  interface
     subroutine foo(s)
       character(*), intent(in) :: s
     end subroutine foo
  end interface
contains
  subroutine bar(s) bind(c)
    character(*), intent(in) :: s
    call foo(s)
  end
end

This gives:

__attribute__((fn spec (". r ")))
void bar (struct CFI_cdesc_t00 & restrict _s)
{
  integer(kind=8) s.0;
  character(kind=1)[1:s.0] * s;
  bitsizetype D.4279;
  sizetype D.4280;

  D.4279 = (bitsizetype) (sizetype) NON_LVALUE_EXPR <s.0> * 8;
  D.4280 = (sizetype) NON_LVALUE_EXPR <s.0>;
  s.0 = (integer(kind=8)) _s->elem_len;
  s = (character(kind=1)[1:s.0] *) _s->base_addr;
  foo ((character(kind=1)[1:s.0] *) s, s.0);
}

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

* [Bug fortran/115390] Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
  2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
  2024-06-07 23:30 ` [Bug fortran/115390] " pinskia at gcc dot gnu.org
  2024-06-08 19:51 ` anlauf at gcc dot gnu.org
@ 2024-06-17 21:06 ` anlauf at gcc dot gnu.org
  2024-06-18 20:12 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-06-17 21:06 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #3 from anlauf at gcc dot gnu.org ---
Created attachment 58455
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58455&action=edit
Patch

The attached patch fixes the ordering such that the bogus warning does no
longer appear and gives for the reduced test:

__attribute__((fn spec (". r ")))
void bar (struct CFI_cdesc_t00 & restrict _s)
{
  integer(kind=8) s.0;
  character(kind=1)[1:s.0] * s;
  bitsizetype D.4279;
  sizetype D.4280;

  s.0 = (integer(kind=8)) _s->elem_len;
  D.4279 = (bitsizetype) (sizetype) NON_LVALUE_EXPR <s.0> * 8;
  D.4280 = (sizetype) NON_LVALUE_EXPR <s.0>;
  s = (character(kind=1)[1:s.0] *) _s->base_addr;
  foo ((character(kind=1)[1:s.0] *) s, s.0);
}

Currently regtesting ...

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

* [Bug fortran/115390] Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
  2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
                   ` (2 preceding siblings ...)
  2024-06-17 21:06 ` anlauf at gcc dot gnu.org
@ 2024-06-18 20:12 ` anlauf at gcc dot gnu.org
  2024-06-19 16:34 ` cvs-commit at gcc dot gnu.org
  2024-06-19 19:22 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-06-18 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org

--- Comment #4 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2024-June/060591.html

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

* [Bug fortran/115390] Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
  2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
                   ` (3 preceding siblings ...)
  2024-06-18 20:12 ` anlauf at gcc dot gnu.org
@ 2024-06-19 16:34 ` cvs-commit at gcc dot gnu.org
  2024-06-19 19:22 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-19 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 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:954f9011c4923b72f42cc6ca8460333e7c7aad98

commit r15-1449-g954f9011c4923b72f42cc6ca8460333e7c7aad98
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Jun 18 21:57:19 2024 +0200

    Fortran: fix for CHARACTER(len=*) dummies with bind(C) [PR115390]

    gcc/fortran/ChangeLog:

            PR fortran/115390
            * trans-decl.cc (gfc_conv_cfi_to_gfc): Move derivation of type
sizes
            for character via gfc_trans_vla_type_sizes to after character
length
            has been set.

    gcc/testsuite/ChangeLog:

            PR fortran/115390
            * gfortran.dg/bind_c_char_11.f90: New test.

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

* [Bug fortran/115390] Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function
  2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
                   ` (4 preceding siblings ...)
  2024-06-19 16:34 ` cvs-commit at gcc dot gnu.org
@ 2024-06-19 19:22 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-06-19 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #6 from anlauf at gcc dot gnu.org ---
Fixed.

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

end of thread, other threads:[~2024-06-19 19:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-07 22:15 [Bug fortran/115390] New: Bogus -Wuninitialized warning when using CHARACTER(*) argument in BIND(C) function daklishch at gmail dot com
2024-06-07 23:30 ` [Bug fortran/115390] " pinskia at gcc dot gnu.org
2024-06-08 19:51 ` anlauf at gcc dot gnu.org
2024-06-17 21:06 ` anlauf at gcc dot gnu.org
2024-06-18 20:12 ` anlauf at gcc dot gnu.org
2024-06-19 16:34 ` cvs-commit at gcc dot gnu.org
2024-06-19 19:22 ` 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).