This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C PATCH] PR27150 and PR27382: LABEL_DECL vs DECL_WEAK


Hi Joseph,

My apologies for poaching these two PRs from Andrew, but the patch
below should resolve both PR c/27150 and PR middle-end/27382, which
are some C front-end fallout from the recent restructuring of DECL
trees.  After the recent reorganization, DECL_WEAK can no longer be
called directly on LABEL_DECLs or PARM_DECLs without ICEing the
compiler.  These mainline regressions are fixed below, by adding
the appropriate tests from LABEL_DECL and PARM_DECL in the affected
code.   The bugzila entry for 27382, showed the same issue existed
in build_binary_op, so I decided to fix 27150 at the same time.


The following patch has been tested on x86_64-unknown-linux-gnu with
a full "make bootstrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures.

Ok for mainline?



2006-06-03  Roger Sayle  <roger@eyesopen.com>
	    Andrew Pinski  <pinskia@physics.uc.edu>

	PR middle-end/27382
	* c-common.c (c_common_truthvalue_conversion): Explicitly check
	for LABEL_DECL before calling DECL_WEAK.

	PR c/27150
	* c-typeck.c (build_binary_op): Likewise, explicitly check for
	LABEL_DECL and PARM_DECL.

	* gcc.dg/pr27150-1.c: New testcase.
	* gcc.dg/pr27382-1.c: New testcase.
	* gcc.dg/pr27382-2.c: New testcase.


Index: c-common.c
===================================================================
*** c-common.c	(revision 114330)
--- c-common.c	(working copy)
*************** c_common_truthvalue_conversion (tree exp
*** 2501,2507 ****
        {
   	tree inner = TREE_OPERAND (expr, 0);
  	if (DECL_P (inner)
! 	    && (TREE_CODE (inner) == PARM_DECL || !DECL_WEAK (inner)))
  	  {
  	    /* Common Ada/Pascal programmer's mistake.  We always warn
  	       about this since it is so bad.  */
--- 2501,2509 ----
        {
   	tree inner = TREE_OPERAND (expr, 0);
  	if (DECL_P (inner)
! 	    && (TREE_CODE (inner) == PARM_DECL
! 		|| TREE_CODE (inner) == LABEL_DECL
! 		|| !DECL_WEAK (inner)))
  	  {
  	    /* Common Ada/Pascal programmer's mistake.  We always warn
  	       about this since it is so bad.  */
Index: c-typeck.c
===================================================================
*** c-typeck.c	(revision 114330)
--- c-typeck.c	(working copy)
*************** build_binary_op (enum tree_code code, tr
*** 7996,8002 ****
  	{
  	  if (TREE_CODE (op0) == ADDR_EXPR
  	      && DECL_P (TREE_OPERAND (op0, 0))
! 	      && !DECL_WEAK (TREE_OPERAND (op0, 0)))
  	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
  		     TREE_OPERAND (op0, 0));
  	  result_type = type0;
--- 7996,8004 ----
  	{
  	  if (TREE_CODE (op0) == ADDR_EXPR
  	      && DECL_P (TREE_OPERAND (op0, 0))
! 	      && (TREE_CODE (TREE_OPERAND (op0, 0)) == PARM_DECL
! 		  || TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
! 		  || !DECL_WEAK (TREE_OPERAND (op0, 0))))
  	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
  		     TREE_OPERAND (op0, 0));
  	  result_type = type0;
*************** build_binary_op (enum tree_code code, tr
*** 8005,8011 ****
  	{
  	  if (TREE_CODE (op1) == ADDR_EXPR
  	      && DECL_P (TREE_OPERAND (op1, 0))
! 	      && !DECL_WEAK (TREE_OPERAND (op1, 0)))
  	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
  		     TREE_OPERAND (op1, 0));
  	  result_type = type1;
--- 8007,8015 ----
  	{
  	  if (TREE_CODE (op1) == ADDR_EXPR
  	      && DECL_P (TREE_OPERAND (op1, 0))
! 	      && (TREE_CODE (TREE_OPERAND (op1, 0)) == PARM_DECL
! 		  || TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL
! 		  || !DECL_WEAK (TREE_OPERAND (op1, 0))))
  	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
  		     TREE_OPERAND (op1, 0));
  	  result_type = type1;


/* { dg-do compile } */
/* { dg-options "-O2" } */
int g(int f)
{
  return (&f)!=0;
}


/* { dg-do compile } */
/* { dg-options "-O2" } */
void foo()
{
    L:
    !&&L;
}


/* { dg-do compile } */
/* { dg-options "-O2" } */
void foo()
{
    L:
    &&L != 0;
}


Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]