This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warning policy?
- To: jbuck at Synopsys dot COM
- Subject: Re: Warning policy?
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Fri, 1 Jan 1999 19:28:46 -0500 (EST)
- Cc: chip at perlsupport dot com, egcs-patches at cygnus dot com, egcs at cygnus dot com, pfeifer at dbai dot tuwien dot ac dot at, schwab at issan dot informatik dot uni-dortmund dot de
> From: Joe Buck <jbuck@Synopsys.COM>
>
> > > Andreas Schwab writes:
> > > > Well, the brute force method would be to just emit a `goto L' before
> > > > each label L.
> > >
> > > That would only create more warnings, as some of these gotos would be
> > > unreachable code, which produces a warning.
> >
> > Good point, but I'm not seeing this in actual practice from gcc.
> > I wrote a small patch to attempt what Andreas suggested and gcc does not
> > complain about unreachable code. Various stage1-cc's might complain,
> > e.g. SunOS4 cc does in fact, but we could arrange to only output the
> > goto when __GNUC__ is defined.
>
> Ah, but if gcc's ability to detect dead code improves, the warnings come
> back.
My impression was that gcc's response to dead code was to
eliminate it, not warn about it. At least that's what the comments/docs
suggest...
> Now, if there were an attribute that can be attached to a label that says
> "this label may be unused, if so, don't warn about it" that would be
> the simplest way to fix things.
I'd call it a better solution, not a simpler one. :-)
Anyway, I went ahead and implemented it. How's this?
Okay to install?
--Kaveh
Fri Jan 1 19:11:54 1999 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* c-common.c (decl_attributes): Allow applying attribute `unused'
on a LABEL_DECL.
* c-parse.in (label): Parse attributes after a label, and call
`decl_attributes' to handle them.
* gansidecl.h (ATTRIBUTE_UNUSED_LABEL): Define.
* genrecog.c (OUTPUT_LABEL, write_tree_1, write_tree): When
generating labels, mark them with ATTRIBUTE_UNUSED_LABEL.
* invoke.texi: Note that labels can be marked `unused'.
diff -rup orig/egcs-CVS19981231/gcc/c-common.c egcs-CVS19981231/gcc/c-common.c
--- orig/egcs-CVS19981231/gcc/c-common.c Thu Dec 31 12:05:12 1998
+++ egcs-CVS19981231/gcc/c-common.c Thu Dec 31 23:05:54 1998
@@ -521,7 +521,8 @@ decl_attributes (node, attributes, prefi
TREE_USED (type) = 1;
else if (TREE_CODE (decl) == PARM_DECL
|| TREE_CODE (decl) == VAR_DECL
- || TREE_CODE (decl) == FUNCTION_DECL)
+ || TREE_CODE (decl) == FUNCTION_DECL
+ || TREE_CODE (decl) == LABEL_DECL)
TREE_USED (decl) = 1;
else
warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
diff -rup orig/egcs-CVS19981231/gcc/c-parse.in egcs-CVS19981231/gcc/c-parse.in
--- orig/egcs-CVS19981231/gcc/c-parse.in Thu Dec 31 12:05:15 1998
+++ egcs-CVS19981231/gcc/c-parse.in Thu Dec 31 23:05:54 1998
@@ -2214,12 +2214,15 @@ label: CASE expr_no_commas ':'
error_with_decl (duplicate, "this is the first default label");
}
position_after_white_space (); }
- | identifier ':'
+ | identifier ':' maybe_attribute
{ tree label = define_label (input_filename, lineno, $1);
stmt_count++;
emit_nop ();
if (label)
- expand_label (label);
+ {
+ expand_label (label);
+ decl_attributes (label, $3, NULL_TREE);
+ }
position_after_white_space (); }
;
diff -rup orig/egcs-CVS19981231/gcc/gansidecl.h egcs-CVS19981231/gcc/gansidecl.h
--- orig/egcs-CVS19981231/gcc/gansidecl.h Thu Dec 31 12:05:11 1998
+++ egcs-CVS19981231/gcc/gansidecl.h Thu Dec 31 23:05:55 1998
@@ -38,6 +38,14 @@ Boston, MA 02111-1307, USA. */
# define __attribute__(x)
#endif
+#ifndef ATTRIBUTE_UNUSED_LABEL
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 92)
+# define ATTRIBUTE_UNUSED_LABEL
+# else
+# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
+# endif /* GNUC < 2.92 */
+#endif /* ATTRIBUTE_UNUSED_LABEL */
+
#ifndef ATTRIBUTE_UNUSED
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif /* ATTRIBUTE_UNUSED */
diff -rup orig/egcs-CVS19981231/gcc/genrecog.c egcs-CVS19981231/gcc/genrecog.c
--- orig/egcs-CVS19981231/gcc/genrecog.c Thu Dec 31 12:06:07 1998
+++ egcs-CVS19981231/gcc/genrecog.c Thu Dec 31 23:05:55 1998
@@ -51,6 +51,9 @@ Boston, MA 02111-1307, USA. */
#include "rtl.h"
#include "obstack.h"
+#define OUTPUT_LABEL(INDENT_STRING, LABEL_NUMBER) \
+ printf("%sL%d: ATTRIBUTE_UNUSED_LABEL\n", (INDENT_STRING), (LABEL_NUMBER))
+
static struct obstack obstack;
struct obstack *rtl_obstack = &obstack;
@@ -1103,7 +1106,7 @@ write_tree_1 (tree, prevpos, afterward,
printf ("\n");
if (tree && tree->subroutine_number == 0)
{
- printf (" L%d:\n", tree->number);
+ OUTPUT_LABEL (" ", tree->number);
tree->label_needed = 0;
}
@@ -1239,7 +1242,7 @@ write_tree_1 (tree, prevpos, afterward,
if (p->label_needed && (p->retest_mode || p->retest_code))
{
- printf ("%sL%d:\n", indents[indent - 2], p->number);
+ OUTPUT_LABEL (indents[indent - 2], p->number);
p->label_needed = 0;
}
@@ -1330,7 +1333,7 @@ write_tree_1 (tree, prevpos, afterward,
/* Now that most mode and code tests have been done, we can write out
a label for an inner node, if we haven't already. */
if (p->label_needed)
- printf ("%sL%d:\n", indents[indent - 2], p->number);
+ OUTPUT_LABEL (indents[indent - 2], p->number);
inner_indent = indent;
@@ -1563,7 +1566,7 @@ write_tree (tree, prevpos, afterward, in
if (! initial && tree->subroutine_number > 0)
{
- printf (" L%d:\n", tree->number);
+ OUTPUT_LABEL (" ", tree->number);
if (afterward)
{
diff -rup orig/egcs-CVS19981231/gcc/invoke.texi egcs-CVS19981231/gcc/invoke.texi
--- orig/egcs-CVS19981231/gcc/invoke.texi Thu Dec 31 12:06:17 1998
+++ egcs-CVS19981231/gcc/invoke.texi Thu Dec 31 23:05:55 1998
@@ -1340,7 +1340,7 @@ In order to get a warning about an unuse
specify both @samp{-W} and @samp{-Wunused}.
To suppress this warning for an expression, simply cast it to void. For
-unused variables and parameters, use the @samp{unused} attribute
+unused variables, parameters and labels, use the @samp{unused} attribute
(@pxref{Variable Attributes}).
@item -Wuninitialized