aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSteven Bosscher <steven@gcc.gnu.org>2003-10-12 22:09:29 +0000
committerSteven Bosscher <steven@gcc.gnu.org>2003-10-12 22:09:29 +0000
commit1998463c5498f70d5add37cdbeb3e73277a47851 (patch)
treed8508ce937bd1981385a02639c802f8107997f26 /gcc
parentd60004eecf62e69a63dae2a66f4688e003ca3a62 (diff)
downloadgcc-1998463c5498f70d5add37cdbeb3e73277a47851.zip
gcc-1998463c5498f70d5add37cdbeb3e73277a47851.tar.gz
gcc-1998463c5498f70d5add37cdbeb3e73277a47851.tar.bz2
c-common.c (c_common_truthvalue_conversion): Warn if the address of a non-weak function is used as a truth value.
gcc/ * c-common.c (c_common_truthvalue_conversion): Warn if the address of a non-weak function is used as a truth value. cp/ * cvt.c (ocp_convert): Move warning to C common code. testsuite/ * gcc.dg/weak/weak-3.c: Fix for new warning. From-SVN: r72409
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-common.c35
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/cvt.c16
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/weak/weak-3.c2
6 files changed, 41 insertions, 25 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index be5de23..052e74c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2003-10-12 Steven Bosscher <steven@gcc.gnu.org>
+
+ * c-common.c (c_common_truthvalue_conversion): Warn if the
+ address of a non-weak function is used as a truth value.
+
2003-10-12 Kazu Hirata <kazu@cs.umass.edu>
* config/h8300/h8300.c (WORD_REG_USED): Use SP_REG instead of
diff --git a/gcc/c-common.c b/gcc/c-common.c
index b58eda1..e8ed13b 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -2602,6 +2602,9 @@ c_common_truthvalue_conversion (tree expr)
if (TREE_CODE (expr) == ERROR_MARK)
return expr;
+ if (TREE_CODE (expr) == FUNCTION_DECL)
+ expr = build_unary_op (ADDR_EXPR, expr, 0);
+
#if 0 /* This appears to be wrong for C++. */
/* These really should return error_mark_node after 2.4 is stable.
But not all callers handle ERROR_MARK properly. */
@@ -2647,17 +2650,29 @@ c_common_truthvalue_conversion (tree expr)
return real_zerop (expr) ? truthvalue_false_node : truthvalue_true_node;
case ADDR_EXPR:
- /* If we are taking the address of an external decl, it might be zero
- if it is weak, so we cannot optimize. */
- if (DECL_P (TREE_OPERAND (expr, 0))
- && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
- break;
+ {
+ if (TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL
+ && ! DECL_WEAK (TREE_OPERAND (expr, 0)))
+ {
+ /* Common Ada/Pascal programmer's mistake. We always warn
+ about this since it is so bad. */
+ warning ("the address of `%D', will always evaluate as `true'",
+ TREE_OPERAND (expr, 0));
+ return truthvalue_true_node;
+ }
- if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
- return build (COMPOUND_EXPR, truthvalue_type_node,
- TREE_OPERAND (expr, 0), truthvalue_true_node);
- else
- return truthvalue_true_node;
+ /* If we are taking the address of an external decl, it might be
+ zero if it is weak, so we cannot optimize. */
+ if (DECL_P (TREE_OPERAND (expr, 0))
+ && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
+ break;
+
+ if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
+ return build (COMPOUND_EXPR, truthvalue_type_node,
+ TREE_OPERAND (expr, 0), truthvalue_true_node);
+ else
+ return truthvalue_true_node;
+ }
case COMPLEX_EXPR:
return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index da318cf..9a0735b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2003-10-12 Steven Bosscher <steven@gcc.gnu.org>
+
+ * cvt.c (ocp_convert): Move warning to C common code.
+
2003-10-09 Jason Merrill <jason@redhat.com>
PR c++/6392
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 32d0d79..1479fbd 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -694,20 +694,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags)
return error_mark_node;
}
if (code == BOOLEAN_TYPE)
- {
- tree fn = NULL_TREE;
-
- /* Common Ada/Pascal programmer's mistake. We always warn
- about this since it is so bad. */
- if (TREE_CODE (expr) == FUNCTION_DECL)
- fn = expr;
- else if (TREE_CODE (expr) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL)
- fn = TREE_OPERAND (expr, 0);
- if (fn && !DECL_WEAK (fn))
- warning ("the address of `%D', will always be `true'", fn);
- return cp_truthvalue_conversion (e);
- }
+ return cp_truthvalue_conversion (e);
+
return fold (convert_to_integer (type, e));
}
if (POINTER_TYPE_P (type) || TYPE_PTR_TO_MEMBER_P (type))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 14e13ef..84f7c92 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2003-10-12 Steven Bosscher <steven@gcc.gnu.org>
+
+ * gcc.dg/weak/weak-3.c: Fix for new warning.
+
2003-10-12 Kelley Cook <kcook@gcc.gnu.org>
PR optimization/8750
diff --git a/gcc/testsuite/gcc.dg/weak/weak-3.c b/gcc/testsuite/gcc.dg/weak/weak-3.c
index 338d9ad..da4367a 100644
--- a/gcc/testsuite/gcc.dg/weak/weak-3.c
+++ b/gcc/testsuite/gcc.dg/weak/weak-3.c
@@ -54,7 +54,7 @@ extern void * ffoo1f (void);
extern void * ffoox1f (void);
void * foo1f (void)
{
- if (ffoo1f)
+ if (ffoo1f) /* { dg-warning "" } */
ffoo1f ();
return 0;
}