OSDN Git Service

1999-11-25 Mark Mitchell <mark@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / cp / init.c
index d1af4d7..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);
@@ -2072,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;
@@ -2081,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;
 }
@@ -2193,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-
@@ -2369,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.  */
@@ -2384,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
@@ -2398,11 +2384,9 @@ 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);
 
@@ -2449,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;
@@ -2487,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,
@@ -2496,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);
 
@@ -2924,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);
     }
@@ -3029,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
     {
@@ -3224,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.
 
@@ -3236,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;
@@ -3281,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);
 }