diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8f4c296bb56d..66df5a9763fc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2006-06-04 Roger Sayle + Andrew Pinski + + 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 PR c/25161 diff --git a/gcc/c-common.c b/gcc/c-common.c index 1fb5a6a4a4b8..1cef321c8c3e 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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. */ diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 2c5736cf769e..7898d9954e3e 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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; diff --git a/gcc/testsuite/gcc.dg/pr27150-1.c b/gcc/testsuite/gcc.dg/pr27150-1.c new file mode 100644 index 000000000000..03810cd7e15c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr27150-1.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +int g(int f) +{ + return (&f)!=0; +} + diff --git a/gcc/testsuite/gcc.dg/pr27382-1.c b/gcc/testsuite/gcc.dg/pr27382-1.c new file mode 100644 index 000000000000..0b25a7b380da --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr27382-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +void foo() +{ + L: + !&&L; +} + diff --git a/gcc/testsuite/gcc.dg/pr27382-2.c b/gcc/testsuite/gcc.dg/pr27382-2.c new file mode 100644 index 000000000000..97365247ec14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr27382-2.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +void foo() +{ + L: + &&L != 0; +} +