public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53667] New: Cray pointer: Wrong result with optimizations
@ 2012-06-14  7:05 burnus at gcc dot gnu.org
  2012-06-14  8:36 ` [Bug fortran/53667] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-14  7:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53667

             Bug #: 53667
           Summary: Cray pointer: Wrong result with optimizations
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Cf. thread at http://gcc.gnu.org/ml/fortran/2012-06/msg00077.html

For the program at http://gcc.gnu.org/ml/fortran/2012-06/txt00004.txt, GCC
generates (original dump) the code:

  object_holder_init (&object_holder);
  set_vals (&object_holder);
  print_vals (&object_holder);

When using -O2, the latter becomes (optimized dump):

  object_holder_init (&object_holder);
  print_vals (&object_holder);
  object_holder ={v} {CLOBBER};


Both set_vals and print_vals contains code of the form:

  subroutine set_vals(oh)
    implicit none
    integer*8, intent(inout):: oh
    integer*8 :: obj(3)
    pointer(pobj, obj)

    pobj = oh

which translates into:

  set_vals (integer(kind=8) & restrict oh)
  {
    integer(kind=8) pobj;
    integer(kind=8) obj[3] [value-expr: *(integer(kind=8)[3] *) pobj];

    pobj = *oh;


If one marks "print_val"'s dummy argument "oh" as "target" (and, hence, removes
the "restrict"), GCC inlines "set_val" and the result is correct.

The program also works (at any optimization level) with
-fno-inline-small-functions. Or if all functions are inlined via
-fwhole-program.


It also works if one has a Cray-pointer dummy argument at:
  subroutine print_vals(pobj)
    integer*8 :: obj(3)
    pointer(pobj, obj)
    ...
    call free(pobj)

 * * *

Related issue: Currently, gfortran calls
    *oh = _gfortran_malloc (&C.1885);
    ...
    _gfortran_free ((integer(kind=8) *) oh);

(Cf. iresolve.c.) If one looks into libgfortran/intrinsics/malloc.c, it uses
the trivial implementation. But then a simple BUILT_IN_MALLOC / BUILT_IN_FREE
would do!


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

end of thread, other threads:[~2013-04-12 16:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-14  7:05 [Bug fortran/53667] New: Cray pointer: Wrong result with optimizations burnus at gcc dot gnu.org
2012-06-14  8:36 ` [Bug fortran/53667] " rguenth at gcc dot gnu.org
2012-06-14  9:07 ` [Bug middle-end/53667] " burnus at gcc dot gnu.org
2012-06-21  6:32 ` [Bug middle-end/53667] [4.6/4.7/4.8 Regression] " burnus at gcc dot gnu.org
2012-09-06 15:11 ` rguenth at gcc dot gnu.org
2012-09-07  9:01 ` rguenth at gcc dot gnu.org
2012-09-07  9:39 ` burnus at gcc dot gnu.org
2012-09-07 10:27 ` rguenth at gcc dot gnu.org
2012-09-07 10:30 ` rguenth at gcc dot gnu.org
2012-09-07 10:32 ` [Bug middle-end/53667] [4.6 " rguenth at gcc dot gnu.org
2013-04-12 16:27 ` jakub 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).