aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2010-05-24 22:03:09 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2010-05-24 22:03:09 +0000
commit12a149a0345a62df2a4e225db80de692104d15a4 (patch)
treeb9428ab159cf1e1bea7ddc0e1161b3ea0ac1fc41 /gcc/cp
parentfeb4c2937a1dafe76e6daf03e03ef106f60545c7 (diff)
downloadgcc-12a149a0345a62df2a4e225db80de692104d15a4.zip
gcc-12a149a0345a62df2a4e225db80de692104d15a4.tar.gz
gcc-12a149a0345a62df2a4e225db80de692104d15a4.tar.bz2
re PR middle-end/44100 (ICE compiling g++.dg/init/struct2.C on Tru64 UNIX V5.1B)
PR middle-end/44100 * typeck.c (cp_build_unary_op): Fold offsetof-like computations. From-SVN: r159800
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/typeck.c14
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 74cb213..cd86b88 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2010-05-24 Eric Botcazou <ebotcazou@adacore.com>
+
+ PR middle-end/44100
+ * typeck.c (cp_build_unary_op): Fold offsetof-like computations.
+
2010-05-24 Joseph Myers <joseph@codesourcery.com>
* error.c (cp_diagnostic_starter): Update call to
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 54ccbfe..77cf8fd 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5024,6 +5024,20 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
return arg;
}
+ /* ??? Cope with user tricks that amount to offsetof. */
+ if (TREE_CODE (argtype) != FUNCTION_TYPE
+ && TREE_CODE (argtype) != METHOD_TYPE
+ && argtype != unknown_type_node
+ && (val = get_base_address (arg))
+ && TREE_CODE (val) == INDIRECT_REF
+ && TREE_CONSTANT (TREE_OPERAND (val, 0)))
+ {
+ tree type = build_pointer_type (argtype);
+ tree op0 = fold_convert (type, TREE_OPERAND (val, 0));
+ tree op1 = fold_convert (sizetype, fold_offsetof (arg, val));
+ return fold_build2 (POINTER_PLUS_EXPR, type, op0, op1);
+ }
+
/* Uninstantiated types are all functions. Taking the
address of a function is a no-op, so just return the
argument. */