aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2002-04-03 14:39:51 -0800
committerRichard Henderson <rth@gcc.gnu.org>2002-04-03 14:39:51 -0800
commitef4f94ac977780ceb14adc8dcbcc2eb2c23b5425 (patch)
treefd1d1d700f54be42454fcc88e95011014edff3f4 /gcc/cp
parent599bba86dffe8bd03676f4bf50bca436d3112b90 (diff)
downloadgcc-ef4f94ac977780ceb14adc8dcbcc2eb2c23b5425.zip
gcc-ef4f94ac977780ceb14adc8dcbcc2eb2c23b5425.tar.gz
gcc-ef4f94ac977780ceb14adc8dcbcc2eb2c23b5425.tar.bz2
re PR rtl-optimization/4330 (Optimizer generates illegal assembly code)
PR opt/4330 * langhooks.h (lang_hooks.decls.warn_unused_global): New. * toplev.c (check_global_declarations): Use it. * langhooks-def.h (lhd_warn_unused_global_decl): Declare. (LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL): New. (LANG_HOOKS_DECLS): Add it. * langhooks.c (lhd_warn_unused_global_decl): New. * c-decl.c (LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL): New. * c-objc-common.c (c_warn_unused_global_decl): New. * c-tree.h (c_warn_unused_global_decl): Declare. * objc/objc-lang.c (LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL): New. * cp-lang.c (cxx_warn_unused_global_decl): New. (LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL): New. * g++.dg/warn/Wunused-2.C: New. * gcc.dg/unused-4.c: New. From-SVN: r51818
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/cp-lang.c103
2 files changed, 67 insertions, 41 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a7ffd32..50dfde8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2002-04-03 Richard Henderson <rth@redhat.com>
+
+ * cp-lang.c (cxx_warn_unused_global_decl): New.
+ (LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL): New.
+
2002-04-03 Neil Booth <neil@daikokuya.demon.co.uk>
* cp-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Redefine.
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index b7d129a..3c086ca 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -30,6 +30,7 @@ Boston, MA 02111-1307, USA. */
static HOST_WIDE_INT cxx_get_alias_set PARAMS ((tree));
static bool ok_to_generate_alias_set_for_type PARAMS ((tree));
+static bool cxx_warn_unused_global_decl PARAMS ((tree));
#undef LANG_HOOKS_NAME
#define LANG_HOOKS_NAME "GNU C++"
@@ -87,6 +88,8 @@ static bool ok_to_generate_alias_set_for_type PARAMS ((tree));
#define LANG_HOOKS_PRINT_ERROR_FUNCTION cxx_print_error_function
#undef LANG_HOOKS_SET_YYDEBUG
#define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug
+#undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
+#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl
#undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES
#define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \
@@ -133,6 +136,47 @@ static bool ok_to_generate_alias_set_for_type PARAMS ((tree));
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
+/* Tree code classes. */
+
+#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
+
+const char tree_code_type[] = {
+#include "tree.def"
+ 'x',
+#include "c-common.def"
+ 'x',
+#include "cp-tree.def"
+};
+#undef DEFTREECODE
+
+/* Table indexed by tree code giving number of expression
+ operands beyond the fixed part of the node structure.
+ Not used for types or decls. */
+
+#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
+
+const unsigned char tree_code_length[] = {
+#include "tree.def"
+ 0,
+#include "c-common.def"
+ 0,
+#include "cp-tree.def"
+};
+#undef DEFTREECODE
+
+/* Names of tree components.
+ Used for printing out the tree and error messages. */
+#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
+
+const char *const tree_code_name[] = {
+#include "tree.def"
+ "@@dummy",
+#include "c-common.def"
+ "@@dummy",
+#include "cp-tree.def"
+};
+#undef DEFTREECODE
+
/* Check if a C++ type is safe for aliasing.
Return TRUE if T safe for aliasing FALSE otherwise. */
@@ -185,47 +229,6 @@ ok_to_generate_alias_set_for_type (t)
return true;
}
-/* Tree code classes. */
-
-#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
-
-const char tree_code_type[] = {
-#include "tree.def"
- 'x',
-#include "c-common.def"
- 'x',
-#include "cp-tree.def"
-};
-#undef DEFTREECODE
-
-/* Table indexed by tree code giving number of expression
- operands beyond the fixed part of the node structure.
- Not used for types or decls. */
-
-#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
-
-const unsigned char tree_code_length[] = {
-#include "tree.def"
- 0,
-#include "c-common.def"
- 0,
-#include "cp-tree.def"
-};
-#undef DEFTREECODE
-
-/* Names of tree components.
- Used for printing out the tree and error messages. */
-#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
-
-const char *const tree_code_name[] = {
-#include "tree.def"
- "@@dummy",
-#include "c-common.def"
- "@@dummy",
-#include "cp-tree.def"
-};
-#undef DEFTREECODE
-
/* Special routine to get the alias set for C++. */
static HOST_WIDE_INT
@@ -238,3 +241,21 @@ cxx_get_alias_set (t)
return c_common_get_alias_set (t);
}
+
+/* Called from check_global_declarations. */
+
+static bool
+cxx_warn_unused_global_decl (decl)
+ tree decl;
+{
+ if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
+ return false;
+ if (DECL_IN_SYSTEM_HEADER (decl))
+ return false;
+
+ /* Const variables take the place of #defines in C++. */
+ if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl))
+ return false;
+
+ return true;
+}