aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2005-07-13 16:31:23 +0000
committerJeff Law <law@redhat.com>2005-07-13 16:31:23 +0000
commitfa3ed441dd6e680233fcc8666ce93c6b1a38580c (patch)
tree74485a550b11de6d6b4c0f96a5a04ad88b50adb4 /gcc/fold-const.c
parentee6de66b01fb2cbc42c36e135b71debef0b6190a (diff)
* fold-const.c (fold_binary): When comparing two simple ADDR_EXPR
expressions, test their _DECL operands for pointer equality rather than using operand_equal_p. * gcc.dg/tree-ssa/pr22321.c: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@101974 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index beee337487b..3bc27eb5d3b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8757,9 +8757,23 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& ! lookup_attribute ("alias",
DECL_ATTRIBUTES (TREE_OPERAND (arg1, 0)))
&& ! DECL_EXTERNAL (TREE_OPERAND (arg1, 0)))
- return constant_boolean_node (operand_equal_p (arg0, arg1, 0)
- ? code == EQ_EXPR : code != EQ_EXPR,
- type);
+ {
+ /* We know that we're looking at the address of two
+ non-weak, unaliased, static _DECL nodes.
+
+ It is both wasteful and incorrect to call operand_equal_p
+ to compare the two ADDR_EXPR nodes. It is wasteful in that
+ all we need to do is test pointer equality for the arguments
+ to the two ADDR_EXPR nodes. It is incorrect to use
+ operand_equal_p as that function is NOT equivalent to a
+ C equality test. It can in fact return false for two
+ objects which would test as equal using the C equality
+ operator. */
+ bool equal = TREE_OPERAND (arg0, 0) == TREE_OPERAND (arg1, 0);
+ return constant_boolean_node (equal
+ ? code == EQ_EXPR : code != EQ_EXPR,
+ type);
+ }
/* If this is a comparison of two exprs that look like an
ARRAY_REF of the same object, then we can fold this to a