aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2002-08-15 10:34:05 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2002-08-15 10:34:05 +0000
commiteac5ce6c93ebae62a03b741975086d5b09151334 (patch)
treeff4dfd9cbdf604cfab662616f1959f6830478c26 /gcc
parent61f02ff548608d1fe98c35f724575cb87865946b (diff)
downloadgcc-eac5ce6c93ebae62a03b741975086d5b09151334.zip
gcc-eac5ce6c93ebae62a03b741975086d5b09151334.tar.gz
gcc-eac5ce6c93ebae62a03b741975086d5b09151334.tar.bz2
re PR c++/7598 (offsetof broken)
cp: PR c++/7598 * typeck.c (build_unary_op): Fold offsetof idiom. Fixes regression caused by my 2002-08-08 patch. testsuite: * g++.dg/other/offsetof1.C: New test From-SVN: r56346
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c18
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/other/offsetof1.C14
4 files changed, 42 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0ab00f6..27e5bc7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2002-08-15 Nathan Sidwell <nathan@codesourcery.com>
+
+ PR c++/7598
+ * typeck.c (build_unary_op): Fold offsetof idiom. Fixes
+ regression caused by my 2002-08-08 patch.
+
2002-08-13 Mark Mitchell <mark@codesourcery.com>
* decl.c (pushdecl_class_level): Honor requests to bind names to
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index f8bc378..de3c059 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4256,6 +4256,24 @@ build_unary_op (code, xarg, noconvert)
TREE_OPERAND (arg, 1));
return error_mark_node;
}
+ else if (TREE_CODE (arg) == COMPONENT_REF
+ && TREE_CODE (TREE_OPERAND (arg, 0)) == INDIRECT_REF
+ && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg, 0), 0))
+ == INTEGER_CST))
+ {
+ /* offsetof idiom, fold it. */
+ tree field = TREE_OPERAND (arg, 1);
+ tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
+ tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)),
+ decl_type_context (field),
+ ba_check, NULL);
+
+ rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
+ rval = build1 (NOP_EXPR, argtype, rval);
+ TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
+ addr = fold (build (PLUS_EXPR, argtype, rval,
+ cp_convert (argtype, byte_position (field))));
+ }
else
addr = build1 (ADDR_EXPR, argtype, arg);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 69a99ff..d0694f3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2002-08-15 Nathan Sidwell <nathan@codesourcery.com>
+
+ * g++.dg/other/offsetof1.C: New test.
+
2002-08-14 Richard Henderson <rth@redhat.com>
* gcc.dg/tls/diag-3.c: Fix expected message strings.
diff --git a/gcc/testsuite/g++.dg/other/offsetof1.C b/gcc/testsuite/g++.dg/other/offsetof1.C
new file mode 100644
index 0000000..1051cd2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/offsetof1.C
@@ -0,0 +1,14 @@
+// { dg-do compile }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 14 Aug 2002 <nathan@codesourcery.com>
+
+// PR c++ 7598, offsetof broke
+
+struct F
+{
+ char i;
+ char j;
+};
+
+static int ary[((unsigned) &((struct F *)0)->j)];