re PR middle-end/27382 (ICE in c_common_truthvalue_conversion with label address)

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.


Co-Authored-By: Andrew Pinski <pinskia@physics.uc.edu>

From-SVN: r114380
This commit is contained in:
Roger Sayle 2006-06-05 02:28:20 +00:00 committed by Roger Sayle
parent 5c076987a4
commit ffbf5f7f20
6 changed files with 43 additions and 3 deletions

View File

@ -1,3 +1,14 @@
2006-06-04 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.
2006-06-05 Joseph S. Myers <joseph@codesourcery.com>
PR c/25161

View File

@ -2501,7 +2501,9 @@ c_common_truthvalue_conversion (tree expr)
{
tree inner = TREE_OPERAND (expr, 0);
if (DECL_P (inner)
&& (TREE_CODE (inner) == PARM_DECL || !DECL_WEAK (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. */

View File

@ -7996,7 +7996,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
{
if (TREE_CODE (op0) == ADDR_EXPR
&& DECL_P (TREE_OPERAND (op0, 0))
&& !DECL_WEAK (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;
@ -8005,7 +8007,9 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
{
if (TREE_CODE (op1) == ADDR_EXPR
&& DECL_P (TREE_OPERAND (op1, 0))
&& !DECL_WEAK (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;

View File

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

View File

@ -0,0 +1,8 @@
/* { dg-do compile } */
/* { dg-options "-O2" } */
void foo()
{
L:
!&&L;
}

View File

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