summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2006-05-05 19:57:38 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2006-05-05 19:57:38 +0000
commit8d8d1a280135e6530e1d2eb42c5ff8b91a8f570c (patch)
tree31aff53c7f9388180b8f468318913668e9cb42be
parentb207220873a208cab0b8fea85bf5be77bcd15914 (diff)
downloadgcc-8d8d1a280135e6530e1d2eb42c5ff8b91a8f570c.tar.gz
c-parser.c (c_parser_cast_expression): Only insert casts into hash table if pointer.
PR/21391 * c-parser.c (c_parser_cast_expression): Only insert casts into hash table if pointer. * function.c (used_types_insert_helper): Rename from used_types_insert. (used_types_insert): Call used_types_insert_helper. * function.h (used_types_insert): Accept only one argument. * 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. From-SVN: r113561
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/c-parser.c3
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/rtti.c3
-rw-r--r--gcc/cp/typeck.c9
-rw-r--r--gcc/function.c25
-rw-r--r--gcc/function.h2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/unused1.C47
9 files changed, 102 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d0e64145a93..26281ed4321 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2006-05-03 Aldy Hernandez <aldyh@redhat.com>
+
+ PR/21391
+ * c-parser.c (c_parser_cast_expression): Only insert casts into
+ hash table if pointer.
+ * function.c (used_types_insert_helper): Rename from
+ used_types_insert.
+ (used_types_insert): Call used_types_insert_helper.
+ * function.h (used_types_insert): Accept only one argument.
+
2006-05-05 David Edelsohn <edesohn@gnu.org>
* config/rs6000/rs6000.md: Mark all "X" constraints for clobbered
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 48edab70749..aad1c6bb048 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -4691,8 +4691,7 @@ c_parser_cast_expression (c_parser *parser, struct c_expr *after)
}
/* Save casted types in the function's used types hash table. */
- if (debug_info_level > DINFO_LEVEL_NONE)
- used_types_insert (type_name->specs->type, cfun);
+ used_types_insert (type_name->specs->type);
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
return c_parser_postfix_expression_after_paren_type (parser,
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d4a01fcd68f..f423f4fb4be 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2006-05-03 Aldy Hernandez <aldyh@redhat.com>
+
+ PR/21391
+ * typeck.c (build_static_cast_1): Save casted types in used types
+ hash table.
+ (build_reinterpret_cast_1): Same.
+ * rtti.c (build_dynamic_cast_1): Same.
+
2006-05-04 Jakub Jelinek <jakub@redhat.com>
PR c++/27359
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 5c6d38d8df5..6242e44c3e9 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -464,6 +464,9 @@ build_dynamic_cast_1 (tree type, tree expr)
tree old_expr = expr;
const char *errstr = NULL;
+ /* Save casted types in the function's used types hash table. */
+ used_types_insert (type);
+
/* T shall be a pointer or reference to a complete class type, or
`pointer to cv void''. */
switch (tc)
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 394a4ec0575..78e3a2b8427 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4759,6 +4759,9 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
intype = TREE_TYPE (expr);
+ /* Save casted types in the function's used types hash table. */
+ used_types_insert (type);
+
/* Determine what to do when casting away constness. */
if (c_cast_p)
{
@@ -5047,6 +5050,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
intype = TREE_TYPE (expr);
+ /* Save casted types in the function's used types hash table. */
+ used_types_insert (type);
+
/* [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 +5248,9 @@ build_const_cast_1 (tree dst_type, tree expr, bool complain,
return error_mark_node;
}
+ /* Save casted types in the function's used types hash table. */
+ used_types_insert (dst_type);
+
src_type = TREE_TYPE (expr);
/* Expressions do not really have reference types. */
if (TREE_CODE (src_type) == REFERENCE_TYPE)
diff --git a/gcc/function.c b/gcc/function.c
index cc50f50777d..bb6480118d6 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -5590,23 +5590,34 @@ rest_of_handle_check_leaf_regs (void)
return 0;
}
-/* Insert a type into the used types hash table. */
-void
-used_types_insert (tree t, struct function *func)
+/* Insert a TYPE into the used types hash table of CFUN. */
+static void
+used_types_insert_helper (tree type, struct function *func)
{
- if (t != NULL && func != NULL)
+ if (type != NULL && func != NULL)
{
void **slot;
if (func->used_types_hash == NULL)
func->used_types_hash = htab_create_ggc (37, htab_hash_pointer,
- htab_eq_pointer, NULL);
- slot = htab_find_slot (func->used_types_hash, t, INSERT);
+ htab_eq_pointer, NULL);
+ slot = htab_find_slot (func->used_types_hash, type, INSERT);
if (*slot == NULL)
- *slot = t;
+ *slot = type;
}
}
+/* Given a type, insert it into the used hash table in cfun. */
+void
+used_types_insert (tree t)
+{
+ while (POINTER_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE)
+ t = TREE_TYPE (t);
+ t = TYPE_MAIN_VARIANT (t);
+ if (debug_info_level > DINFO_LEVEL_NONE)
+ used_types_insert_helper (t, cfun);
+}
+
struct tree_opt_pass pass_leaf_regs =
{
NULL, /* name */
diff --git a/gcc/function.h b/gcc/function.h
index bce52909aeb..63295258c11 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -576,6 +576,6 @@ extern bool pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
extern bool reference_callee_copied (CUMULATIVE_ARGS *, enum machine_mode,
tree, bool);
-extern void used_types_insert (tree, struct function *);
+extern void used_types_insert (tree);
#endif /* GCC_FUNCTION_H */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4b75dbe6f2f..c6683a9ac06 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-05-03 Aldy Hernandez <aldyh@redhat.com>
+
+ PR/21391
+ * g++.dg/other/unused1.C: New.
+
2006-05-05 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR objc/27240
diff --git a/gcc/testsuite/g++.dg/other/unused1.C b/gcc/testsuite/g++.dg/other/unused1.C
new file mode 100644
index 00000000000..e50ce380fce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/unused1.C
@@ -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\"" } } */