diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-10-31 12:33:05 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-10-31 12:33:05 +0000 |
commit | 28fa8094b7fe3acda4232611bb99738e2d3b0c37 (patch) | |
tree | 2035bbc1a2f604178b758bb8ac8aec2c7229d814 /gcc/fold-const.c | |
parent | 8cafc742678385cb7aab9b598e2828f3a17b975f (diff) | |
download | gcc-28fa8094b7fe3acda4232611bb99738e2d3b0c37.tar.gz |
2007-10-31 Richard Guenther <rguenther@suse.de>
PR middle-end/33779
* fold-const.c (extract_muldiv_1): Make sure to not introduce
new undefined integer overflow.
(fold_binary): Avoid useless conversion.
* gcc.c-torture/execute/pr33779-1.c: New testcase.
* gcc.c-torture/execute/pr33779-2.c: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129796 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2598ec1e18f..a7d2756116b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6060,7 +6060,12 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, then we cannot pass through this conversion. */ || (code != MULT_EXPR && (TYPE_UNSIGNED (ctype) - != TYPE_UNSIGNED (TREE_TYPE (op0)))))) + != TYPE_UNSIGNED (TREE_TYPE (op0)))) + /* ... or has undefined overflow while the converted to + type has not, we cannot do the operation in the inner type + as that would introduce undefined overflow. */ + || (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0)) + && !TYPE_OVERFLOW_UNDEFINED (type)))) break; /* Pass the constant down and see if we can make a simplification. If @@ -10266,9 +10271,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) strict_overflow_p = false; if (TREE_CODE (arg1) == INTEGER_CST - && 0 != (tem = extract_muldiv (op0, - fold_convert (type, arg1), - code, NULL_TREE, + && 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE, &strict_overflow_p))) { if (strict_overflow_p) |