aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-01-19 15:09:12 +0000
committerRichard Stallman <rms@gnu.org>1993-01-19 15:09:12 +0000
commitd023bff9eb7b7ad49dfe8cd40aabcfc7eed6c8d5 (patch)
tree8e2bf4b60f4edf23b0806f1bb10917c2257ee489 /gcc/fold-const.c
parent441cedbd685af32e608ce0676fe6133768521110 (diff)
downloadgcc-d023bff9eb7b7ad49dfe8cd40aabcfc7eed6c8d5.zip
gcc-d023bff9eb7b7ad49dfe8cd40aabcfc7eed6c8d5.tar.gz
gcc-d023bff9eb7b7ad49dfe8cd40aabcfc7eed6c8d5.tar.bz2
(non_lvalue): Result must not be null ptr constant.
(omit_one_operand): Use non_lvalue. (fold, case COMPOUND_EXPR): Use non_lvalue if value is 0. From-SVN: r3276
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index ba23fd4..e3a7ca0 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -1580,7 +1580,8 @@ fold_convert (t, arg1)
return t;
}
-/* Return an expr equal to X but certainly not valid as an lvalue. */
+/* Return an expr equal to X but certainly not valid as an lvalue.
+ Also make sure it is not valid as an null pointer constant. */
tree
non_lvalue (x)
@@ -1594,7 +1595,15 @@ non_lvalue (x)
|| TREE_CODE (x) == REAL_CST
|| TREE_CODE (x) == STRING_CST
|| TREE_CODE (x) == ADDR_EXPR)
- return x;
+ {
+ if (TREE_CODE (x) == INTEGER_CST && integer_zerop (x))
+ {
+ result = build1 (NOP_EXPR, TREE_TYPE (x), x);
+ TREE_CONSTANT (result) = TREE_CONSTANT (x);
+ return result;
+ }
+ return x;
+ }
result = build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x);
TREE_CONSTANT (result) = TREE_CONSTANT (x);
@@ -1990,7 +1999,7 @@ omit_one_operand (type, result, omitted)
if (TREE_SIDE_EFFECTS (omitted))
return build (COMPOUND_EXPR, type, omitted, t);
- return t;
+ return non_lvalue (t);
}
/* Return a simplified tree node for the truth-negation of ARG. This
@@ -4339,9 +4348,12 @@ fold (expr)
return t;
case COMPOUND_EXPR:
- if (!TREE_SIDE_EFFECTS (arg0))
- return arg1;
- return t;
+ if (TREE_SIDE_EFFECTS (arg0))
+ return t;
+ /* Don't let (0, 0) be null pointer constant. */
+ if (integer_zerop (arg1))
+ return non_lvalue (arg1);
+ return arg1;
default:
return t;