This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] fix for detection of unused types.
- To: gcc-patches at gcc dot gnu dot org
- Subject: [patch] fix for detection of unused types.
- From: Catherine Moore <clm at cygnus dot com>
- Date: Thu, 04 May 2000 12:28:50 -0700
- cc: clm at cygnus dot com
For the following test case:
typedef short unused_type __attribute__ ((unused));
main ()
{
short x;
unused_type y;
}
the compiler is unable to detect that x is an unused variable
if -Wall or -Wunused is specified. This patch corrects
this deficiency. Okay to commit?
--catherine
000-05-04 Catherine Moore <clm@cygnus.com>
* c-common.c (decl_attributes): For TYPE_DECLs attach the
attribute to the decl.
* c-decl.c (pushdecl): Propagate the USED attribute to the
type copy.
Index: c-common.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/c-common.c,v
retrieving revision 1.137
diff -p -r1.137 c-common.c
*** c-common.c 2000/03/14 15:45:15 1.137
--- c-common.c 2000/05/04 18:57:15
*************** decl_attributes (node, attributes, prefi
*** 651,657 ****
case A_UNUSED:
if (is_type)
! TREE_USED (type) = 1;
else if (TREE_CODE (decl) == PARM_DECL
|| TREE_CODE (decl) == VAR_DECL
|| TREE_CODE (decl) == FUNCTION_DECL
--- 651,660 ----
case A_UNUSED:
if (is_type)
! if (decl)
! TREE_USED (decl) = 1;
! else
! TREE_USED (type) = 1;
else if (TREE_CODE (decl) == PARM_DECL
|| TREE_CODE (decl) == VAR_DECL
|| TREE_CODE (decl) == FUNCTION_DECL
Index: c-decl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/c-decl.c,v
retrieving revision 1.243
diff -p -r1.243 c-decl.c
*** c-decl.c 2000/01/11 14:58:55 1.243
--- c-decl.c 2000/05/04 18:57:48
*************** pushdecl (x)
*** 2183,2188 ****
--- 2183,2189 ----
DECL_ORIGINAL_TYPE (x) = tt;
tt = build_type_copy (tt);
TYPE_NAME (tt) = x;
+ TREE_USED (tt) = TREE_USED (x);
TREE_TYPE (x) = tt;
}
}