public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/42801]  New: C VLAs should use DW_AT_allocated
@ 2010-01-19 10:18 jan dot kratochvil at redhat dot com
  2010-01-19 10:58 ` [Bug debug/42801] " jan dot kratochvil at redhat dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jan dot kratochvil at redhat dot com @ 2010-01-19 10:18 UTC (permalink / raw)
  To: gcc-bugs

FAIL: gcc (GCC) 4.4.3 20100119 (prerelease)
FAIL: gcc-4.4.2-20.fc12.x86_64 (Fedora 12)
SKIP: gcc (GCC) 4.5.0 20100119 (experimental) - N/A - blocked by PR debug/42800
------------------------------------------------------------------------------
Currently the type of a VLA (Variable Length Array) contains incorrect bounds
before the specific variable is allocated.  Fortran uses DW_AT_allocated in
such case and GDB with archer-jankratochvil-vla patch properly avoids
evaluating the invalid bounds printing:
(gdb) ptype varx
type = <object is not allocated>

Currently with -O0 its DW_AT_location is defined even before it is allocated. 
With -O2 its DW_AT_location is never defined (suboptimal VTA?).  Offtopic here.

Still IMO the type should have DW_AT_allocated indicator and not depend on
never being evaluated when its variable has DW_AT_location undefined
(=<optimized out>).

This is not a regression bug.

------------------------------------------------------------------------------
static long
f (void)
{
  long l = 0x7ffffffe;  /* Pre-fill DW_AT_upper_bound of `a'.  */
  long unused = l;

  return l | unused;
}

static int
g (long l)
{
  char a[l];    /* gdb -ex 'b 13' -ex r -ex 'ptype a' */

  return a[0];
}

int
main (void)
{
  f ();
  return g (5);
}
------------------------------------------------------------------------------
(gcc -o 1 1.c -m64 -Wall -g; ulimit -v 500000; gdb -nx -ex 'b 13' -ex r -ex
'ptype a' ./1)
------------------------------------------------------------------------------
Breakpoint 1, g (l=5) at 1.c:13
13        char a[l];    /* gdb -ex 'b 13' -ex r -ex 'ptype a' */
../../gdb/utils.c:1205: internal-error: virtual memory exhausted: can't
allocate 2147483647 bytes.

The problem is GDB internally allocates the type being printed (which is
suboptimal).  Still it shows the type is valid but with incorrect bounds there.

Reducing the size will print the incorrect bound:
type = char [134217727]


-- 
           Summary: C VLAs should use DW_AT_allocated
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jan dot kratochvil at redhat dot com
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug debug/42801] C VLAs should use DW_AT_allocated
  2010-01-19 10:18 [Bug debug/42801] New: C VLAs should use DW_AT_allocated jan dot kratochvil at redhat dot com
@ 2010-01-19 10:58 ` jan dot kratochvil at redhat dot com
  2010-05-24  8:52 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jan dot kratochvil at redhat dot com @ 2010-01-19 10:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jan dot kratochvil at redhat dot com  2010-01-19 10:57 -------
Maybe properly limiting DW_AT_location even in -O0 -g mode would be the same.


-- 


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


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

* [Bug debug/42801] C VLAs should use DW_AT_allocated
  2010-01-19 10:18 [Bug debug/42801] New: C VLAs should use DW_AT_allocated jan dot kratochvil at redhat dot com
  2010-01-19 10:58 ` [Bug debug/42801] " jan dot kratochvil at redhat dot com
@ 2010-05-24  8:52 ` jakub at gcc dot gnu dot org
  2010-05-24 14:38 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-24  8:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2010-05-24 08:52 -------
I think DW_AT_allocated would be wrong for C VLAs, they don't have allocated
property like Fortran arrays.
The problems I see are:
1) for -O0 we don't do any var-tracking, while we should be tracking
   i) variables that don't live in memory (vars with register keyword mostly)
   ii) everything during prologues until the stack slots of those variables
       are actually set
   iii) for VLAs even outside of prologues we need to track the lengths before
        they are actually set
   Of course this is going to slow down the compiler at -O0 somewhat, so needs
   to be done with extreme care
2) for -O2 there seems to be some issues with VLAs in inlines and cloned
   functions - the type is used from the abstract origin and thus can't have
   correct bounds.  I wonder whether it is ok to have DW_AT_abstract_origin
   and in addition to that DW_AT_type which overrides the original abstract
   origin's type (and, whether gdb will handle it right)


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aoliva at gcc dot gnu dot
                   |                            |org


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


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

* [Bug debug/42801] C VLAs should use DW_AT_allocated
  2010-01-19 10:18 [Bug debug/42801] New: C VLAs should use DW_AT_allocated jan dot kratochvil at redhat dot com
  2010-01-19 10:58 ` [Bug debug/42801] " jan dot kratochvil at redhat dot com
  2010-05-24  8:52 ` jakub at gcc dot gnu dot org
@ 2010-05-24 14:38 ` jakub at gcc dot gnu dot org
  2010-05-24 19:54 ` jan dot kratochvil at redhat dot com
  2010-05-25 16:16 ` jakub at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-24 14:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2010-05-24 14:38 -------
Created an attachment (id=20735)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20735&action=view)
gcc46-pr42801.patch

Patch for the -O2 issue.
The standard says:
"Concrete inlined instance entries may omit attributes that are not specific to
the concrete instance (but present in the abstract instance) and need include
only attributes that are specific to the concrete instance (but omitted in the
abstract instance).", which I read as not forbidding duplication of the
DW_AT_type attribute (dropping DW_AT_type in the abstract instance doesn't seem
to be a good idea, even when bounds aren't known the type otherwise gives
useful info).  Perhaps we should handle DW_TAG_formal_parameters the same way
in dwarf2out.c.
Unfortunately, gdb prints 0 instead of 24 in the second case.


-- 


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


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

* [Bug debug/42801] C VLAs should use DW_AT_allocated
  2010-01-19 10:18 [Bug debug/42801] New: C VLAs should use DW_AT_allocated jan dot kratochvil at redhat dot com
                   ` (2 preceding siblings ...)
  2010-05-24 14:38 ` jakub at gcc dot gnu dot org
@ 2010-05-24 19:54 ` jan dot kratochvil at redhat dot com
  2010-05-25 16:16 ` jakub at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: jan dot kratochvil at redhat dot com @ 2010-05-24 19:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jan dot kratochvil at redhat dot com  2010-05-24 19:53 -------
Archer counterpart (no patch now):
http://sourceware.org/bugzilla/show_bug.cgi?id=11632


-- 


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


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

* [Bug debug/42801] C VLAs should use DW_AT_allocated
  2010-01-19 10:18 [Bug debug/42801] New: C VLAs should use DW_AT_allocated jan dot kratochvil at redhat dot com
                   ` (3 preceding siblings ...)
  2010-05-24 19:54 ` jan dot kratochvil at redhat dot com
@ 2010-05-25 16:16 ` jakub at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-25 16:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2010-05-25 16:16 -------
Subject: Bug 42801

Author: jakub
Date: Tue May 25 16:15:38 2010
New Revision: 159826

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159826
Log:
        PR debug/42801
        * tree-inline.c (remap_decls): Remap DECL_VALUE_EXPR here...
        (copy_bind_expr): ... instead of here.
        (copy_tree_body_r): If id->remapping_type_depth clear TREE_BLOCK
        if the block hasn't been remapped.
        * dwarf2out.c (gen_formal_parameter_die, gen_variable_die): When
        emitting concrete instance of abstract VLA, add DW_AT_type attribute.

        * gcc.dg/guality/sra-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/guality/sra-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-inline.c


-- 


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


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

end of thread, other threads:[~2010-05-25 16:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-19 10:18 [Bug debug/42801] New: C VLAs should use DW_AT_allocated jan dot kratochvil at redhat dot com
2010-01-19 10:58 ` [Bug debug/42801] " jan dot kratochvil at redhat dot com
2010-05-24  8:52 ` jakub at gcc dot gnu dot org
2010-05-24 14:38 ` jakub at gcc dot gnu dot org
2010-05-24 19:54 ` jan dot kratochvil at redhat dot com
2010-05-25 16:16 ` jakub 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).