class.c (build_base_path): Use build_address directly.
authorRichard Henderson <rth@redhat.com>
Mon, 30 Aug 2004 18:59:18 +0000 (11:59 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Mon, 30 Aug 2004 18:59:18 +0000 (11:59 -0700)
        * class.c (build_base_path): Use build_address directly.
        * typeck.c (build_unary_op): Don't lower &a.b to pointer
        arithmetic directly.
        * typeck2.c (store_init_value): Don't assume !TREE_CONSTANT
        means !initializer_constant_valid_p.

        * g++.dg/other/offsetof1.C: Use __builtin_offsetof.

From-SVN: r86795

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/typeck.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/offsetof1.C

index 83e38c94df143f87747f38186c9f563723417e80..97296e940a560aaa49012acfd4d00e7e0c5f66dd 100644 (file)
@@ -1,3 +1,11 @@
+2004-08-30  Richard Henderson  <rth@redhat.com>
+
+       * class.c (build_base_path): Use build_address directly.
+       * typeck.c (build_unary_op): Don't lower &a.b to pointer
+       arithmetic directly.
+       * typeck2.c (store_init_value): Don't assume !TREE_CONSTANT
+       means !initializer_constant_valid_p.
+
 2004-08-30  Richard Henderson  <rth@redhat.com>
 
        * class.c (fixed_type_or_null): Use get_base_address before
index 9ef15dcca9808efb5e1496a2c57a79cb8cd43705..272c4d6a0ff11f98a395c9db995b1471e307a607 100644 (file)
@@ -319,7 +319,7 @@ build_base_path (enum tree_code code,
       expr = build_indirect_ref (expr, NULL);
       expr = build_simple_base_path (expr, binfo);
       if (want_pointer)
-       expr = build_unary_op (ADDR_EXPR, expr, 0);
+       expr = build_address (expr);
       target_type = TREE_TYPE (expr);
       goto out;
     }
index 3ec1e427582b9711ee2f42711d375e6ddf6369b3..e62db90e0d08a9d960fa9ceff6c205b880649f58 100644 (file)
@@ -3963,19 +3963,6 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert)
          return arg;
        }
 
-      /* For &x[y], return x+y.  But, in a template, ARG may be an
-        ARRAY_REF representing a non-dependent expression.  In that
-        case, there may be an overloaded "operator []" that will be
-        chosen at instantiation time; we must not try to optimize
-        here.  */
-      if (TREE_CODE (arg) == ARRAY_REF && !processing_template_decl)
-       {
-         if (!cxx_mark_addressable (TREE_OPERAND (arg, 0)))
-           return error_mark_node;
-         return cp_build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
-                                    TREE_OPERAND (arg, 1));
-       }
-
       /* Uninstantiated types are all functions.  Taking the
         address of a function is a no-op, so just return the
         argument.  */
@@ -4099,9 +4086,6 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert)
          }
        else
          {
-           /* Unfortunately we cannot just build an address
-              expression here, because we would not handle
-              address-constant-expressions or offsetof correctly.  */
            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)),
@@ -4109,10 +4093,9 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert)
                                      ba_check, NULL);
            
            rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
-           rval = build_nop (argtype, rval);
-           addr = fold (build2 (PLUS_EXPR, argtype, rval,
-                                cp_convert (argtype,
-                                            byte_position (field))));
+
+           TREE_OPERAND (arg, 0) = build_indirect_ref (rval, NULL);
+           addr = build_address (arg);
          }
 
        if (TREE_CODE (argtype) == POINTER_TYPE
index 8d776915e84a17c6b46512b827ad0c885bf74833..0a8ac753e6c80284605663f9730286f551a68050 100644 (file)
@@ -609,7 +609,7 @@ store_init_value (tree decl, tree init)
   else if (TYPE_NEEDS_CONSTRUCTING (type))
     return build2 (INIT_EXPR, type, decl, value);
   else if (TREE_STATIC (decl)
-          && (! TREE_CONSTANT (value)
+          && (TREE_SIDE_EFFECTS (value)
               || ! initializer_constant_valid_p (value, TREE_TYPE (value))))
     return split_nonconstant_init (decl, value);
   
index 175c078f02462e8e710725e92a5821600f6f3a06..a5f1a49adf200a074b200fab8ab9d5e34b047674 100644 (file)
@@ -1,3 +1,7 @@
+2004-08-30  Richard Henderson  <rth@redhat.com>
+
+       * g++.dg/other/offsetof1.C: Use __builtin_offsetof.
+
 2004-08-30  Richard Henderson  <rth@redhat.com>
 
        * lib/fortran-torture.exp (fortran-torture-execute): Honor
index 6d4ebf93c14ad74e0ff2e5949eecba4510c9ca92..39bb7836cee2ea90abe8026e4a5fb12d7a5baee4 100644 (file)
@@ -11,4 +11,4 @@ struct F
   char j;
 };
 
-static int ary[((__SIZE_TYPE__)&((struct F *)0)->j)];
+static int ary[__builtin_offsetof(F, j)];