aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorZdenek Dvorak <dvorakz@suse.cz>2005-06-13 16:59:40 +0200
committerZdenek Dvorak <rakdver@gcc.gnu.org>2005-06-13 14:59:40 +0000
commitadacecf105b889e4d7f9b48dea7895724f850d66 (patch)
tree36256906046023419e83d36a7705ff6156e2b065 /gcc
parent75d93ef719d09edfe18b2720e5cc05b8b7ec19da (diff)
downloadgcc-adacecf105b889e4d7f9b48dea7895724f850d66.zip
gcc-adacecf105b889e4d7f9b48dea7895724f850d66.tar.gz
gcc-adacecf105b889e4d7f9b48dea7895724f850d66.tar.bz2
re PR middle-end/21985 (miscompiled or wrong code snippet?)
PR middle-end/21985 * fold-const.c (split_address_to_core_and_offset): Always return the address of the base object. * gcc.dg/tree-ssa/pr21985.c: New test. From-SVN: r100877
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr21985.c32
4 files changed, 44 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 037a205..f325778 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2005-06-13 Zdenek Dvorak <dvorakz@suse.cz>
+
+ PR middle-end/21985
+ * fold-const.c (split_address_to_core_and_offset): Always return
+ the address of the base object.
+
2005-06-13 Bernd Schmidt <bernd.schmidt@analog.com>
* doc/invoke.texi (Blackfin Options): Document -mlong-calls.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index af3f01c..2c1bd15 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11801,9 +11801,7 @@ split_address_to_core_and_offset (tree exp,
core = get_inner_reference (TREE_OPERAND (exp, 0), &bitsize, pbitpos,
poffset, &mode, &unsignedp, &volatilep,
false);
-
- if (TREE_CODE (core) == INDIRECT_REF)
- core = TREE_OPERAND (core, 0);
+ core = build_fold_addr_expr (core);
}
else
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0baaf8a..42536ea 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-06-13 Zdenek Dvorak <dvorakz@suse.cz>
+
+ PR middle-end/21985
+ * gcc.dg/tree-ssa/pr21985.c: New test.
+
2005-06-12 James A. Morrison <phython@gcc.gnu.org>
* ggcc.dg/pr14796-1.c: Add tests for (X << C) >> C.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21985.c b/gcc/testsuite/gcc.dg/tree-ssa/pr21985.c
new file mode 100644
index 0000000..e940310
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr21985.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-vars" } */
+
+struct
+{
+ struct
+ {
+ int a;
+ int b;
+ } a[100];
+} a;
+
+void foo(unsigned);
+unsigned *bar (void);
+
+int
+main (void)
+{
+ unsigned *b = bar ();
+
+ /* This should be folded. */
+ foo (&a.a[50].a - &a.a[33].b);
+ foo ((unsigned) &a.a[50].b - (unsigned) &a);
+
+ /* And this should not. */
+ foo ((unsigned) &b - (unsigned) b);
+ return 0;
+}
+
+/* Two of the calls to foo should be folded to just foo(constant). */
+
+/* { dg-final { scan-tree-dump-times "foo \\(\[0-9\]*\\)" 2 "vars" } } */