This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: don't output strings just because of debug information
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Ian Lance Taylor <iant at google dot com>, gcc-patches at gcc dot gnu dot org
- Date: Sat, 15 Dec 2007 18:17:13 -0200
- Subject: Re: don't output strings just because of debug information
- References: <orlk8g539o.fsf@oliva.athome.lsd.ic.unicamp.br> <m38x49i216.fsf@localhost.localdomain> <475C873D.6070004@codesourcery.com>
On Dec 9, 2007, Mark Mitchell <mark@codesourcery.com> wrote:
> Ian Lance Taylor wrote:
>> Alexandre Oliva <aoliva@redhat.com> writes:
>>
>>> From Alexandre Oliva <aoliva@redhat.com>
>>>
>>> * dwarf2out.c (reference_to_unused): Don't emit strings in
>>> initializers just because of debug information.
>>
>> This is OK.
> I think it's OK too, but I have a couple of follow-on requests. :-)
> 1. tree.h doesn't document TREE_ASM_WRITTEN as applying to STRING_CST.
> I didn't know that we set it on STRING_CST, so I was initially surprised
> by Alexandre's patch. Alexandre, would you mind updating that?
> 2. Is it possible to write a test case?
Thanks, here's what I've just checked in:
for gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* dwarf2out.c (reference_to_unused): Don't emit strings in
initializers just because of debug information.
* tree.h (TREE_ASM_WRITTEN): Document use for STRING_CSTs.
for gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* gcc.dg/debug/const-3.c: New.
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c.orig 2007-12-14 04:11:00.000000000 -0200
+++ gcc/dwarf2out.c 2007-12-14 04:13:03.000000000 -0200
@@ -10365,6 +10365,8 @@ reference_to_unused (tree * tp, int * wa
if (!node->output)
return *tp;
}
+ else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
+ return *tp;
return NULL_TREE;
}
Index: gcc/tree.h
===================================================================
--- gcc/tree.h.orig 2007-12-14 04:11:00.000000000 -0200
+++ gcc/tree.h 2007-12-14 04:14:08.000000000 -0200
@@ -546,7 +546,7 @@ struct gimple_stmt GTY(())
TREE_ASM_WRITTEN in
VAR_DECL, FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE
- BLOCK, SSA_NAME
+ BLOCK, SSA_NAME, STRING_CST
used_flag:
@@ -1300,7 +1300,7 @@ extern void omp_clause_range_check_faile
/* In integral and pointer types, means an unsigned type. */
#define TYPE_UNSIGNED(NODE) (TYPE_CHECK (NODE)->base.unsigned_flag)
-/* Nonzero in a VAR_DECL means assembler code has been written.
+/* Nonzero in a VAR_DECL or STRING_CST means assembler code has been written.
Nonzero in a FUNCTION_DECL means that the function has been compiled.
This is interesting in an inline function, since it might not need
to be compiled separately.
Index: gcc/testsuite/gcc.dg/debug/const-3.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/debug/const-3.c 2007-12-14 04:23:45.000000000 -0200
@@ -0,0 +1,7 @@
+/* Make sure we don't emit strings just because of debug information
+ for string initializers. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g" } */
+/* { dg-final { scan-assembler-not "dontgenerate" } } */
+static const char *p = "dontgenerate1";
+static const char *q[2] = { 0, "dontgenerate2" };
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}