re PR c/17396 (ICE in tree-int-cst at -O0)
authorRichard Henderson <rth@redhat.com>
Sat, 11 Sep 2004 17:02:58 +0000 (10:02 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Sat, 11 Sep 2004 17:02:58 +0000 (10:02 -0700)
        PR c/17396
        * c-typeck.c (build_unary_op): Add legacy offsetof hack.

From-SVN: r87351

gcc/ChangeLog
gcc/c-typeck.c

index 48e06ce9e6099df3f1b7824d40f4b4dfb9a3ad47..2e4b04a750e6cd6fbae388eb1b39a2fdacb68865 100644 (file)
@@ -1,3 +1,8 @@
+2004-09-11  Richard Henderson  <rth@redhat.com>
+
+       PR c/17396
+       * c-typeck.c (build_unary_op): Add legacy offsetof hack.
+
 2004-09-11  Kazu Hirata  <kazu@cs.umass.edu>
 
        * doc/cfg.texi, doc/hostconfig.texi, doc/install.texi,
index b06085d8c2c60a841e778fb8455fc3257f265387..85ba9ce58e2a53035b0b9019f035a7f1a0f1ac04 100644 (file)
@@ -2619,6 +2619,14 @@ build_unary_op (enum tree_code code, tree xarg, int flag)
        }
 
       argtype = build_pointer_type (argtype);
+
+      /* ??? Cope with user tricks that amount to offsetof.  Delete this
+        when we have proper support for integer constant expressions.  */
+      val = get_base_address (arg);
+      if (val && TREE_CODE (val) == INDIRECT_REF
+         && integer_zerop (TREE_OPERAND (val, 0)))
+       return fold_convert (argtype, fold_offsetof (arg));
+
       val = build1 (ADDR_EXPR, argtype, arg);
 
       if (TREE_CODE (arg) == COMPOUND_LITERAL_EXPR)