This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR21391: pruning unused debugging types (c++ bits)
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: rth at redhat dot com, gcc-patches at gcc dot gnu dot org
- Date: Tue, 2 May 2006 11:50:38 -0400
- Subject: Re: PR21391: pruning unused debugging types (c++ bits)
- References: <20060412013606.GA1867@redhat.com> <20060425140502.GA3410@redhat.com> <4452AA0D.1080509@codesourcery.com>
> It looks like you'll be doing this for dependent (template) types, which
> is going to waste memory for no particular purpose, since we never
> output debug information for such types anyhow. You're also not
> handling static_cast<int>('a'), etc.
Fixed. I also added tests for {static,const,reinterpret,dynamic}_cast's.
Tested on x86-64 for C and C++ languages.
OK for mainline?
PR/21391
* cp/typeck.c (build_static_cast_1): Save casted types in used types
hash table.
(build_reinterpret_cast_1): Same.
* cp/rtti.c (build_dynamic_cast_1): Same.
* testsuite/g++.dg/other/unused1.C: New.
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 113248)
+++ cp/typeck.c (working copy)
@@ -4759,6 +4759,10 @@ build_static_cast_1 (tree type, tree exp
intype = TREE_TYPE (expr);
+ /* Save casted types in the function's used types hash table. */
+ if (debug_info_level > DINFO_LEVEL_NONE)
+ used_types_insert (TREE_TYPE (type), cfun);
+
/* Determine what to do when casting away constness. */
if (c_cast_p)
{
@@ -5047,6 +5051,10 @@ build_reinterpret_cast_1 (tree type, tre
intype = TREE_TYPE (expr);
+ /* Save casted types in the function's used types hash table. */
+ if (debug_info_level > DINFO_LEVEL_NONE)
+ used_types_insert (TREE_TYPE (type), cfun);
+
/* [expr.reinterpret.cast]
An lvalue expression of type T1 can be cast to the type
"reference to T2" if an expression of type "pointer to T1" can be
@@ -5242,6 +5250,10 @@ build_const_cast_1 (tree dst_type, tree
return error_mark_node;
}
+ /* Save casted types in the function's used types hash table. */
+ if (debug_info_level > DINFO_LEVEL_NONE)
+ used_types_insert (TREE_TYPE (dst_type), cfun);
+
src_type = TREE_TYPE (expr);
/* Expressions do not really have reference types. */
if (TREE_CODE (src_type) == REFERENCE_TYPE)
Index: cp/rtti.c
===================================================================
--- cp/rtti.c (revision 113248)
+++ cp/rtti.c (working copy)
@@ -464,6 +464,10 @@ build_dynamic_cast_1 (tree type, tree ex
tree old_expr = expr;
const char *errstr = NULL;
+ /* Save casted types in the function's used types hash table. */
+ if (debug_info_level > DINFO_LEVEL_NONE)
+ used_types_insert (TREE_TYPE (type), cfun);
+
/* T shall be a pointer or reference to a complete class type, or
`pointer to cv void''. */
switch (tc)
Index: testsuite/g++.dg/other/unused1.C
===================================================================
--- testsuite/g++.dg/other/unused1.C (revision 0)
+++ testsuite/g++.dg/other/unused1.C (revision 0)
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+/* Make sure we didn't eliminate casted types because we thought they were
+ unused. */
+
+void *voidp;
+
+struct foo { int i; };
+int bar (void)
+{
+ return ((struct foo *)0x1234)->i;
+}
+
+struct boo { int i; };
+int bar2 (void)
+{
+ return reinterpret_cast<struct boo *>(0xC0FFEE)->i;
+}
+
+struct cue { int i; };
+int bar3 (void)
+{
+ return static_cast<struct cue *>(voidp)->i;
+}
+
+class printer { public: int i; };
+const printer *dotmatrix;
+int bar4 (void)
+{
+ return const_cast<printer *>(dotmatrix)->i;
+}
+
+class class1 { virtual ~class1(); } *c1;
+class class2 : class1 { char j; };
+int bar5 (void)
+{
+ if (dynamic_cast <class2 *>(c1))
+ return 5;
+ else
+ return 6;
+}
+/* { dg-final { scan-assembler "foo" } } */
+/* { dg-final { scan-assembler "boo" } } */
+/* { dg-final { scan-assembler "cue" } } */
+/* { dg-final { scan-assembler "string\t\"class2\"" } } */
+/* { dg-final { scan-assembler "string\t\"printer\"" } } */