OSDN Git Service

1999-11-25 Mark Mitchell <mark@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / cp / init.c
index e6a1c5f..1361b96 100644 (file)
@@ -37,8 +37,7 @@ static void expand_aggr_vbase_init_1 PROTO((tree, tree, tree, tree));
 static void construct_virtual_bases PROTO((tree, tree, tree, tree, tree));
 static void expand_aggr_init_1 PROTO((tree, tree, tree, tree, int));
 static void expand_default_init PROTO((tree, tree, tree, tree, int));
-static tree build_vec_delete_1 PROTO((tree, tree, tree, tree, tree,
-                                     int));
+static tree build_vec_delete_1 PROTO((tree, tree, tree, tree, int));
 static void perform_member_init PROTO((tree, tree, tree, int));
 static void sort_base_init PROTO((tree, tree *, tree *));
 static tree build_builtin_delete_call PROTO((tree));
@@ -66,8 +65,12 @@ void init_init_processing ()
   BI_header_type = make_lang_type (RECORD_TYPE);
   nelts_identifier = get_identifier ("nelts");
   fields[0] = build_lang_decl (FIELD_DECL, nelts_identifier, sizetype);
+
+  /* Use the biggest alignment supported by the target to prevent operator
+     new from returning misaligned pointers. */
+  TYPE_ALIGN (BI_header_type) = BIGGEST_ALIGNMENT;
   finish_builtin_type (BI_header_type, "__new_cookie", fields,
-                      0, double_type_node);
+                      0, BI_header_type);
   BI_header_size = size_in_bytes (BI_header_type);
 
   ggc_add_tree_root (&BI_header_type, 1);
@@ -105,7 +108,6 @@ expand_direct_vtbls_init (real_binfo, binfo, init_self, can_elide, addr)
   tree binfos = BINFO_BASETYPES (binfo);
   int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0;
 
-  push_momentary ();
   for (i = 0; i < n_baselinks; i++)
     {
       tree real_base_binfo = TREE_VEC_ELT (real_binfos, i);
@@ -127,7 +129,6 @@ expand_direct_vtbls_init (real_binfo, binfo, init_self, can_elide, addr)
       tree base_ptr = convert_pointer_to_real (binfo, addr);
       expand_virtual_init (real_binfo, base_ptr);
     }
-  pop_momentary ();
 }
 \f
 /* 348 - 351 */
@@ -149,7 +150,6 @@ perform_member_init (member, name, init, explicit)
   if (ANON_AGGR_TYPE_P (type))
     {
       init = build (INIT_EXPR, type, decl, TREE_VALUE (init));
-      TREE_SIDE_EFFECTS (init) = 1;
       finish_expr_stmt (init);
     }
   else if (TYPE_NEEDS_CONSTRUCTING (type)
@@ -660,9 +660,9 @@ expand_virtual_init (binfo, decl)
   /* This code is crusty.  Should be simple, like:
      vtbl = BINFO_VTABLE (binfo);
      */
-  vtype = DECL_CONTEXT (CLASSTYPE_VFIELD (type));
+  vtype = DECL_CONTEXT (TYPE_VFIELD (type));
   vtype_binfo = get_binfo (vtype, TREE_TYPE (TREE_TYPE (decl)), 0);
-  vtbl = BINFO_VTABLE (binfo_value (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (type)), binfo));
+  vtbl = BINFO_VTABLE (binfo_value (DECL_FIELD_CONTEXT (TYPE_VFIELD (type)), binfo));
   assemble_external (vtbl);
   TREE_USED (vtbl) = 1;
   vtbl = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (vtbl)), vtbl);
@@ -976,7 +976,6 @@ begin_init_stmts (stmt_expr_p, compound_stmt_p)
      tree *stmt_expr_p;
      tree *compound_stmt_p;
 {
-  push_momentary ();
   *stmt_expr_p = begin_stmt_expr ();
   *compound_stmt_p = begin_compound_stmt (/*has_no_scope=*/1);
 }
@@ -989,7 +988,6 @@ finish_init_stmts (stmt_expr, compound_stmt)
      tree stmt_expr;
      tree compound_stmt;
 {
-  pop_momentary ();
   finish_compound_stmt (/*has_no_scope=*/1, compound_stmt);
   stmt_expr = finish_stmt_expr (stmt_expr);
 
@@ -1247,11 +1245,7 @@ expand_aggr_init_1 (binfo, true_exp, exp, init, flags)
            expand_decl_init (exp);
        }
       else
-       {
-         tree t = build (INIT_EXPR, type, exp, init);
-         TREE_SIDE_EFFECTS (t) = 1;
-         finish_expr_stmt (t);
-       }
+       finish_expr_stmt (build (INIT_EXPR, type, exp, init));
       return;
     }
 
@@ -1900,8 +1894,6 @@ build_new (placement, decl, init, use_global_new)
   tree nelts = NULL_TREE, t;
   int has_array = 0;
 
-  tree pending_sizes = NULL_TREE;
-
   if (decl == error_mark_node)
     return error_mark_node;
 
@@ -2059,10 +2051,6 @@ build_new (placement, decl, init, use_global_new)
   rval = build1 (NOP_EXPR, TREE_TYPE (rval), rval);
   TREE_NO_UNUSED_WARNING (rval) = 1;
 
-  if (pending_sizes)
-    rval = build_compound_expr (chainon (pending_sizes,
-                                        build_expr_list (NULL_TREE, rval)));
-
   return rval;
 }
 
@@ -2087,7 +2075,6 @@ build_java_class_ref (type)
   class_decl = IDENTIFIER_GLOBAL_VALUE (name);
   if (class_decl == NULL_TREE)
     {
-      push_permanent_obstack ();
       class_decl = build_decl (VAR_DECL, name, TREE_TYPE (jclass_node));
       TREE_STATIC (class_decl) = 1;
       DECL_EXTERNAL (class_decl) = 1;
@@ -2096,7 +2083,6 @@ build_java_class_ref (type)
       DECL_IGNORED_P (class_decl) = 1;
       pushdecl_top_level (class_decl);
       make_decl_rtl (class_decl, NULL_PTR, 1);
-      pop_obstacks ();
     }
   return class_decl;
 }
@@ -2208,20 +2194,10 @@ build_new_1 (exp)
     }
   else
     {
-      int susp = 0;
-
-      if (flag_exceptions)
-       /* We will use RVAL when generating an exception handler for
-          this new-expression, so we must save it.  */
-       susp = suspend_momentary ();
-
       rval = build_op_new_call
        (code, true_type, tree_cons (NULL_TREE, size, placement),
         LOOKUP_NORMAL | (use_global_new * LOOKUP_GLOBAL));
       rval = cp_convert (build_pointer_type (true_type), rval);
-
-      if (flag_exceptions)
-       resume_momentary (susp);
     }
 
   /*        unless an allocation function is declared with an empty  excep-
@@ -2271,7 +2247,6 @@ build_new_1 (exp)
                    build_component_ref (cookie, nelts_identifier,
                                         NULL_TREE, 0),
                    nelts);
-      TREE_SIDE_EFFECTS (exp1) = 1;
       rval = cp_convert (build_pointer_type (true_type), rval);
       rval = build_compound_expr
        (tree_cons (NULL_TREE, exp1,
@@ -2385,9 +2360,6 @@ build_new_1 (exp)
          tree cleanup, fn = NULL_TREE;
          int flags = LOOKUP_NORMAL | (use_global_new * LOOKUP_GLOBAL);
 
-         /* All cleanups must last longer than normal.  */
-         int yes = suspend_momentary ();
-
          /* The Standard is unclear here, but the right thing to do
              is to use the same method for finding deallocation
              functions that we use for finding allocation functions.  */
@@ -2400,8 +2372,6 @@ build_new_1 (exp)
 
          cleanup = build_op_delete_call (dcode, alloc_node, size, flags, fn);
 
-         resume_momentary (yes);
-
          /* Ack!  First we allocate the memory.  Then we set our sentry
             variable to true, and expand a cleanup that deletes the memory
             if sentry is true.  Then we run the constructor and store the
@@ -2414,17 +2384,14 @@ build_new_1 (exp)
              begin = get_target_expr (boolean_true_node);
              sentry = TREE_OPERAND (begin, 0);
 
-             yes = suspend_momentary ();
              TREE_OPERAND (begin, 2)
                = build (COND_EXPR, void_type_node, sentry,
                         cleanup, void_zero_node);
-             resume_momentary (yes);
 
              rval = get_target_expr (rval);
 
              end = build (MODIFY_EXPR, TREE_TYPE (sentry),
                           sentry, boolean_false_node);
-             TREE_SIDE_EFFECTS (end) = 1;
 
              buf = TREE_OPERAND (rval, 0);
 
@@ -2466,10 +2433,9 @@ build_new_1 (exp)
 }
 \f
 static tree
-build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
-                   use_global_delete)
+build_vec_delete_1 (base, maxindex, type, auto_delete_vec, use_global_delete)
      tree base, maxindex, type;
-     tree auto_delete_vec, auto_delete;
+     tree auto_delete_vec;
      int use_global_delete;
 {
   tree virtual_size;
@@ -2504,7 +2470,7 @@ build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
   /* The below is short by BI_header_size */
   virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex));
 
-  tbase = build_decl (VAR_DECL, NULL_TREE, ptype);
+  tbase = create_temporary_var (ptype);
   tbase_init = build_modify_expr (tbase, NOP_EXPR,
                                  fold (build (PLUS_EXPR, ptype,
                                               base,
@@ -2513,29 +2479,10 @@ build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
   controller = build (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE);
   TREE_SIDE_EFFECTS (controller) = 1;
 
-  if (auto_delete != integer_zero_node
-      && auto_delete != integer_two_node)
-    {
-      tree base_tbd = cp_convert (ptype,
-                                 build_binary_op (MINUS_EXPR,
-                                                  cp_convert (ptr_type_node, base),
-                                                  BI_header_size));
-      /* This is the real size */
-      virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size);
-      body = build_expr_list (NULL_TREE,
-                             build_x_delete (base_tbd,
-                                             2 | use_global_delete,
-                                             virtual_size));
-      body = fold (build (COND_EXPR, void_type_node,
-                         fold (build (BIT_AND_EXPR, integer_type_node,
-                                      auto_delete, integer_one_node)),
-                         body, integer_zero_node));
-    }
-  else
-    body = NULL_TREE;
+  body = NULL_TREE;
 
   body = tree_cons (NULL_TREE,
-                   build_delete (ptype, tbase, auto_delete,
+                   build_delete (ptype, tbase, integer_two_node,
                                  LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1),
                    body);
 
@@ -2941,7 +2888,6 @@ build_vec_init (decl, base, maxindex, init, from_array)
                                               iterator),
                              type,
                              /*auto_delete_vec=*/integer_zero_node,
-                             /*auto_delete=*/integer_zero_node,
                              /*use_global_delete=*/0);
       finish_cleanup (e, try_block);
     }
@@ -3046,8 +2992,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
          return error_mark_node;
        }
       return build_vec_delete (addr, array_type_nelts (type),
-                              auto_delete, integer_zero_node,
-                              use_global_delete);
+                              auto_delete, use_global_delete);
     }
   else
     {
@@ -3241,7 +3186,6 @@ build_vbase_delete (type, decl)
    BASE is the expression that should yield the store to be deleted.
    This function expands (or synthesizes) these calls itself.
    AUTO_DELETE_VEC says whether the container (vector) should be deallocated.
-   AUTO_DELETE say whether each item in the container should be deallocated.
 
    This also calls delete for virtual baseclasses of elements of the vector.
 
@@ -3253,10 +3197,9 @@ build_vbase_delete (type, decl)
    be worth bothering.)  */
 
 tree
-build_vec_delete (base, maxindex, auto_delete_vec, auto_delete,
-                 use_global_delete)
+build_vec_delete (base, maxindex, auto_delete_vec, use_global_delete)
      tree base, maxindex;
-     tree auto_delete_vec, auto_delete;
+     tree auto_delete_vec;
      int use_global_delete;
 {
   tree type;
@@ -3298,6 +3241,6 @@ build_vec_delete (base, maxindex, auto_delete_vec, auto_delete,
       return error_mark_node;
     }
 
-  return build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete,
+  return build_vec_delete_1 (base, maxindex, type, auto_delete_vec,
                             use_global_delete);
 }