aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f728db6..3ee2bc7 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9582,11 +9582,22 @@ tree_expr_nonzero_p (tree t)
break;
case ADDR_EXPR:
- /* Weak declarations may link to NULL. */
- if (DECL_P (TREE_OPERAND (t, 0)))
- return !DECL_WEAK (TREE_OPERAND (t, 0));
- /* Constants and all other cases are never weak. */
- return true;
+ {
+ tree base = get_base_address (TREE_OPERAND (t, 0));
+
+ if (!base)
+ return false;
+
+ /* Weak declarations may link to NULL. */
+ if (DECL_P (base))
+ return !DECL_WEAK (base);
+
+ /* Constants are never weak. */
+ if (TREE_CODE_CLASS (TREE_CODE (base)) == 'c')
+ return true;
+
+ return false;
+ }
case COND_EXPR:
return (tree_expr_nonzero_p (TREE_OPERAND (t, 1))