public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/108906] New: Bogus may be used uninitialized warning
@ 2023-02-23 17:32 burnus at gcc dot gnu.org
  2023-02-24 12:52 ` [Bug tree-optimization/108906] " rguenth at gcc dot gnu.org
  2023-02-25 10:56 ` cvs-commit at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-02-23 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108906
           Summary: Bogus may be used uninitialized warning
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

Split-off from  on PR fortran/108621

This shows up with code generated by gfortran internally. The warning is bogus
and (rightly!) disappears when compiled with -Og, -Os, -O1 or higher:


Warning: ‘f.dim[idx.1_32].lbound’ may be used uninitialized
[-Wmaybe-uninitialized]


If I now look at the 021t.ssa dump, I see:

  f.data = 0B;
...
  _1 = f.data;
  cfi.0.base_addr = _1;
...
  _2 = cfi.0.base_addr;
  if (_2 != 0B)
    goto <bb 3>; [INV]
  else
    goto <bb 6>; [INV]
...
  <bb 4> :
  _3 = f.dim[idx.1_32].lbound;
...
  <bb 6> :
  fun (&cfi.0);


I get the same result when I use '_2 = f.data' instead, i.e. neither value
propagation works.

The basic block <bb 4> is the only place where idx.1_32 gets used - but as
f.data == NULL, we directly jump to <bb 6>. Seemingly, the range/value
propagation from 'f.data = 0' to '_2 = ' does not work.

* * * 

Testcase – compile with "gfortran -Wall"; a variant is 'subroutine'
instead of 'program' but this does not have any effect, either.


program demo
use, intrinsic :: iso_c_binding, only : c_int
implicit none

interface
subroutine fun(f_p) bind(c)
import c_int
integer(c_int), pointer, intent(inout) :: f_p(:)
end subroutine
end interface

integer(c_int), pointer :: f(:)

nullify(f)
call fun(f)

end

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

* [Bug tree-optimization/108906] Bogus may be used uninitialized warning
  2023-02-23 17:32 [Bug middle-end/108906] New: Bogus may be used uninitialized warning burnus at gcc dot gnu.org
@ 2023-02-24 12:52 ` rguenth at gcc dot gnu.org
  2023-02-25 10:56 ` cvs-commit at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-24 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-02-24
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We diagnose this from the early diagnostic pass where propagation is limited.
At some cost we could improve things here.

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

* [Bug tree-optimization/108906] Bogus may be used uninitialized warning
  2023-02-23 17:32 [Bug middle-end/108906] New: Bogus may be used uninitialized warning burnus at gcc dot gnu.org
  2023-02-24 12:52 ` [Bug tree-optimization/108906] " rguenth at gcc dot gnu.org
@ 2023-02-25 10:56 ` cvs-commit at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-25 10:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:d3e427f684b0cd7cedbe7b93a06f455e562c5901

commit r13-6341-gd3e427f684b0cd7cedbe7b93a06f455e562c5901
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Sat Feb 25 11:55:08 2023 +0100

    Fortran: Skip bound conv in gfc_conv_gfc_desc_to_cfi_desc with intent(out)
ptr [PR108621]

    When the dummy argument of the bind(C) proc is 'pointer, intent(out)', the
conversion
    of the GFC to the CFI bounds can be skipped: it is not needed and avoids
issues with
    noninit memory.

    Note that the 'cfi->base_addr = gfc->addr' assignment is kept as the C code
of a user
    might assume that a nullified pointer arrives as NULL (or even a specific
value).
    For instance, gfortran.dg/c-interop/section-{1,2}.f90 assumes the value
NULL.

    Note 2: The PR is about a may-be-uninitialized warning with intent(out). In
the PR's
    testcase, the pointer was nullified and should not have produced that
warning.
    That is a diagnostic issue, now tracked as PR middle-end/108906 as the
issue in principle
    still exists (e.g. with 'intent(inout)'). [But no longer for intent(out).]

    Note 3: With undefined pointers and no 'intent', accessing uninit memory is
unavoidable
    on the caller side as the compiler cannot know what the C function does
(but this usage
    determines whether the pointer is permitted be undefined or whether the
bounds must be
    gfc-to-cfi converted).

    gcc/fortran/ChangeLog:

            PR fortran/108621
            * trans-expr.cc (gfc_conv_gfc_desc_to_cfi_desc): Skip setting of
            bounds of CFI desc for 'pointer,intent(out)'.

    gcc/testsuite/ChangeLog:

            PR fortran/108621
            * gfortran.dg/c-interop/fc-descriptor-pr108621.f90: New test.

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

end of thread, other threads:[~2023-02-25 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 17:32 [Bug middle-end/108906] New: Bogus may be used uninitialized warning burnus at gcc dot gnu.org
2023-02-24 12:52 ` [Bug tree-optimization/108906] " rguenth at gcc dot gnu.org
2023-02-25 10:56 ` cvs-commit 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).