From 03ada815f3c6242b11b0593460d2c9af434c7fd9 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Wed, 19 Nov 2008 00:15:52 +0000 Subject: [PATCH] re PR debug/27574 (MIssing debug info at -O0 for a local variable in a C++ constructor) gcc/ChangeLog: 2008-11-14 Dodji Seketeli PR c++/27574 * gcc/cgraph.c (cgraph_remove_node): Do not remove the body of abstract functions. It might be useful to emit debugging information. This is a patch from Ian Lance Taylor. * cgraphunit.c (cgraph_optimize): Do not cry when bodies of abstract functions are still around. They are useful to output debug info. gcc/testsuite/ChangeLog 2008-11-14 Dodji Seketeli PR c++/27574 * testsuite/g++.dg/debug/dwarf2/dwarf2.exp: Backport this here from gcc-4_3-branch. * g++.dg/debug/dwarf2/local-var-in-contructor.C: New testcase. From-SVN: r141984 --- gcc/ChangeLog | 9 ++++ gcc/cgraph.c | 8 ++++ gcc/cgraphunit.c | 5 ++- gcc/testsuite/ChangeLog | 7 +++ gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp | 43 +++++++++++++++++++ .../debug/dwarf2/local-var-in-contructor.C | 30 +++++++++++++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d2ed2733781..a90b8f4c09a4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2008-11-17 Dodji Seketeli + + PR c++/27574 + * gcc/cgraph.c (cgraph_remove_node): Do not remove the body of + abstract functions. It might be useful to emit debugging + information. This is a patch from Ian Lance Taylor. + * cgraphunit.c (cgraph_optimize): Do not cry when bodies of abstract + functions are still around. They are useful to output debug info. + 2008-11-16 Eric Botcazou * config/sparc/sparc.c (function_arg_vector_value): Remove 'base_mode' diff --git a/gcc/cgraph.c b/gcc/cgraph.c index b7029d91445b..0031893cc992 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -593,6 +593,14 @@ cgraph_remove_node (struct cgraph_node *node) && (TREE_ASM_WRITTEN (n->decl) || DECL_EXTERNAL (n->decl)))) kill_body = true; } + /* We don't release the body of abstract functions, because they may + be needed when emitting debugging information. In particular + this will happen for C++ constructors/destructors. FIXME: + Ideally we would check to see whether there are any reachable + functions whose DECL_ABSTRACT_ORIGIN points to this decl. */ + if (DECL_ABSTRACT (node->decl)) + kill_body = false; + if (kill_body && flag_unit_at_a_time) { diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 5e860052630e..4d88148db829 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1609,7 +1609,10 @@ cgraph_optimize (void) for (node = cgraph_nodes; node; node = node->next) if (node->analyzed && (node->global.inlined_to - || DECL_SAVED_TREE (node->decl))) + || DECL_SAVED_TREE (node->decl)) + /* Abstract functions are needed to output debug info, + so don't complain about them if they are still around. */ + && !DECL_ABSTRACT (node->decl)) { error_found = true; dump_cgraph_node (stderr, node); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c849d0a1a5b2..8c14705db7b8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-11-14 Dodji Seketeli + + PR c++/27574 + * testsuite/g++.dg/debug/dwarf2/dwarf2.exp: Backport this here from + gcc-4_3-branch. + * g++.dg/debug/dwarf2/local-var-in-contructor.C: New testcase. + 2008-11-13 Uros Bizjak <<<<<<< .working diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp b/gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp new file mode 100644 index 000000000000..1255d0630e75 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp @@ -0,0 +1,43 @@ +# Copyright (C) 2007, 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# G++ testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib g++-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS " -gdwarf-2" +} + +# Initialize `dg'. +dg-init + +# Main loop. +set comp_output [g++_target_compile \ + "$srcdir/$subdir/../trivial.C" "trivial.S" assembly \ + "additional_flags=-gdwarf-2"] +if { ! [string match "*: target system does not support the * debug format*" \ + $comp_output] } { + remove-build-file "trivial.S" + dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[C\]]] \ + "" $DEFAULT_CFLAGS +} + +# All done. +dg-finish diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C b/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C new file mode 100644 index 000000000000..d61d27fe7e4a --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C @@ -0,0 +1,30 @@ +// Contributed by Dodji Seketeli +// Origin PR27574 +// { dg-do compile } +// { dg-options "-O0 -g" } +// { dg-final { scan-assembler "problem" } } + +void f (int *) +{ +} + +class A +{ +public: + A(int i); +}; + +A::A(int i) +{ + int *problem = new int(i); + f (problem); +} + +int +main (void) +{ + A a (0); + + return 0; +} + -- 2.47.2