public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/42958]  New: Weird temporary array allocation
@ 2010-02-04 16:56 rguenth at gcc dot gnu dot org
  2010-02-04 19:33 ` [Bug fortran/42958] " burnus at gcc dot gnu dot org
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-02-04 16:56 UTC (permalink / raw)
  To: gcc-bugs

I see

                            D.1631 = izz.dim[0].lbound;
                            D.1632 = izz.dim[0].ubound;
                            D.1643 = D.1632 - D.1631;
                            D.1647 = D.1643 < 0;
                            D.1648 = D.1643 + 1;
                            D.1649 = D.1647 ? 0 : D.1648 * 8;
                            if (D.1649 < 0)
                              {
                                _gfortran_runtime_error (&"Attempt to allocate
a negative amount of memory."[1]{lb: 1 sz: 1});
                              }
                            D.1650 = (void * restrict) __builtin_malloc
(MAX_EXPR <D.1649, 1>);
                            if (D.1650 == 0B)
                              {
                                _gfortran_os_error (&"Memory allocation
failed"[1]{lb: 1 sz: 1});
                              }
                            D.1651 = D.1650;
                            atmp.5.data = D.1651;

so, we check if the array-size is empty, ubound - lbound < 0.  In that
case we set size to zero.  Otherwise we compute it as (ubound - lbound + 1) *
8.
Then we check whether size is negative and error out.
Then we actually allocate max(1,size).

Why do we at all check for this "negative" amount allocation?  Are you
trying to detect overflow here?  (which won't work, you do the
computation with signed arithmetic so VRP will screw you anyway)

Why not simply do

  size = (ubound - lbound + 1) * 8;
  malloc (size);

which surely fails very quickly on you for negative size and the allocation
fails.

?

Surely for compiler-generated temporary allocations nothing more fancy
should be required (even the check of the allocation could be removed
when optimizing).


-- 
           Summary: Weird temporary array allocation
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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


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

end of thread, other threads:[~2010-04-29 19:09 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-04 16:56 [Bug fortran/42958] New: Weird temporary array allocation rguenth at gcc dot gnu dot org
2010-02-04 19:33 ` [Bug fortran/42958] " burnus at gcc dot gnu dot org
2010-02-05  5:36 ` pault at gcc dot gnu dot org
2010-02-05  9:32 ` rguenther at suse dot de
2010-02-05 14:24 ` rguenth at gcc dot gnu dot org
2010-02-17 20:17 ` jvdelisle at gcc dot gnu dot org
2010-02-20  8:31 ` burnus at gcc dot gnu dot org
2010-03-27 18:55 ` pault at gcc dot gnu dot org
2010-03-27 19:06 ` rguenth at gcc dot gnu dot org
2010-03-27 19:06 ` rguenth at gcc dot gnu dot org
2010-03-27 19:08 ` rguenth at gcc dot gnu dot org
2010-03-27 19:12 ` rguenth at gcc dot gnu dot org
2010-03-28 12:57 ` burnus at gcc dot gnu dot org
2010-03-28 13:05 ` burnus at gcc dot gnu dot org
2010-03-28 13:57 ` burnus at gcc dot gnu dot org
2010-03-28 14:11 ` burnus at gcc dot gnu dot org
2010-03-28 14:45 ` rguenther at suse dot de
2010-04-16  8:18 ` burnus at gcc dot gnu dot org
2010-04-28 14:52 ` rguenth at gcc dot gnu dot org
2010-04-28 15:16 ` amonakov at gcc dot gnu dot org
2010-04-28 15:20 ` jv244 at cam dot ac dot uk
2010-04-28 15:43 ` jb at gcc dot gnu dot org
2010-04-29 10:02 ` paul dot richard dot thomas at gmail dot com
2010-04-29 13:19 ` jakub at gcc dot gnu dot org
2010-04-29 19:09 ` tkoenig at gcc dot gnu dot 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).