diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
index edfab74..0466437 100644
--- a/gcc/lto/lto-lang.c
+++ b/gcc/lto/lto-lang.c
@@ -1061,11 +1061,11 @@ lto_getdecls (void)
 static void
 lto_write_globals (void)
 {
-  tree *vec = VEC_address (tree, lto_global_var_decls);
-  int len = VEC_length (tree, lto_global_var_decls);
+  tree *vec = lto_global_var_decls->address ();
+  int len = lto_global_var_decls->length ();
   wrapup_global_declarations (vec, len);
   emit_debug_global_declarations (vec, len);
-  VEC_free (tree, gc, lto_global_var_decls);
+  vec_free (lto_global_var_decls);
 }
 
 static tree
@@ -1235,7 +1235,7 @@ lto_init (void)
     lto_register_canonical_types (global_trees[i]);
 
   /* Initialize LTO-specific data structures.  */
-  lto_global_var_decls = VEC_alloc (tree, gc, 256);
+  vec_alloc (lto_global_var_decls, 256);
   in_lto_p = true;
 
   return true;
diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
index a642a6c..363d2ff 100644
--- a/gcc/lto/lto-partition.c
+++ b/gcc/lto/lto-partition.c
@@ -44,7 +44,7 @@ enum symbol_class
    SYMBOL_DUPLICATE
 };
 
-VEC(ltrans_partition, heap) *ltrans_partitions;
+vec<ltrans_partition> ltrans_partitions;
 
 static void add_symbol_to_partition (ltrans_partition part, symtab_node node);
 
@@ -102,7 +102,7 @@ new_partition (const char *name)
   part->encoder = lto_symtab_encoder_new (false);
   part->name = name;
   part->insns = 0;
-  VEC_safe_push (ltrans_partition, heap, ltrans_partitions, part);
+  ltrans_partitions.safe_push (part);
   return part;
 }
 
@@ -113,14 +113,14 @@ free_ltrans_partitions (void)
 {
   unsigned int idx;
   ltrans_partition part;
-  for (idx = 0; VEC_iterate (ltrans_partition, ltrans_partitions, idx, part); idx++)
+  for (idx = 0; ltrans_partitions.iterate (idx, &part); idx++)
     {
       if (part->initializers_visited)
 	pointer_set_destroy (part->initializers_visited);
       /* Symtab encoder is freed after streaming.  */
       free (part);
     }
-  VEC_free (ltrans_partition, heap, ltrans_partitions);
+  ltrans_partitions.release ();
 }
 
 /* Return true if symbol is already in some partition.  */
@@ -344,9 +344,8 @@ lto_1_to_1_map (void)
 	      npartitions++;
 	    }
 	}
-      else if (!file_data
-	       && VEC_length (ltrans_partition, ltrans_partitions))
-	partition = VEC_index (ltrans_partition, ltrans_partitions, 0);
+      else if (!file_data && ltrans_partitions.length ())
+	partition = ltrans_partitions[0];
       else
 	{
 	  partition = new_partition ("");
@@ -790,11 +789,11 @@ lto_promote_cross_file_statics (void)
   gcc_assert (flag_wpa);
 
   /* First compute boundaries.  */
-  n_sets = VEC_length (ltrans_partition, ltrans_partitions);
+  n_sets = ltrans_partitions.length ();
   for (i = 0; i < n_sets; i++)
     {
       ltrans_partition part
-	= VEC_index (ltrans_partition, ltrans_partitions, i);
+	= ltrans_partitions[i];
       part->encoder = compute_ltrans_boundary (part->encoder);
     }
 
@@ -804,7 +803,7 @@ lto_promote_cross_file_statics (void)
       lto_symtab_encoder_iterator lsei;
       lto_symtab_encoder_t encoder;
       ltrans_partition part
-	= VEC_index (ltrans_partition, ltrans_partitions, i);
+	= ltrans_partitions[i];
 
       encoder = part->encoder;
       for (lsei = lsei_start (encoder); !lsei_end_p (lsei);
diff --git a/gcc/lto/lto-partition.h b/gcc/lto/lto-partition.h
index 5bf4055..86b21a0 100644
--- a/gcc/lto/lto-partition.h
+++ b/gcc/lto/lto-partition.h
@@ -29,10 +29,8 @@ struct ltrans_partition_def
 };
 
 typedef struct ltrans_partition_def *ltrans_partition;
-DEF_VEC_P(ltrans_partition);
-DEF_VEC_ALLOC_P(ltrans_partition,heap);
 
-extern VEC(ltrans_partition, heap) *ltrans_partitions;
+extern vec<ltrans_partition> ltrans_partitions;
 
 void lto_1_to_1_map (void);
 void lto_max_map (void);
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 857e8f6..da55b7e 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -305,8 +305,6 @@ struct type_pair_d
   signed char same_p;
 };
 typedef struct type_pair_d *type_pair_t;
-DEF_VEC_P(type_pair_t);
-DEF_VEC_ALLOC_P(type_pair_t,heap);
 
 #define GIMPLE_TYPE_PAIR_SIZE 16381
 struct type_pair_d *type_pair_cache;
@@ -432,7 +430,7 @@ compare_type_names_p (tree t1, tree t2)
 
 static bool
 gimple_types_compatible_p_1 (tree, tree, type_pair_t,
-			     VEC(type_pair_t, heap) **,
+			     vec<type_pair_t> *,
 			     struct pointer_map_t *, struct obstack *);
 
 /* DFS visit the edge from the callers type pair with state *STATE to
@@ -444,7 +442,7 @@ gimple_types_compatible_p_1 (tree, tree, type_pair_t,
 static bool
 gtc_visit (tree t1, tree t2,
 	   struct sccs *state,
-	   VEC(type_pair_t, heap) **sccstack,
+	   vec<type_pair_t> *sccstack,
 	   struct pointer_map_t *sccstate,
 	   struct obstack *sccstate_obstack)
 {
@@ -558,7 +556,7 @@ gtc_visit (tree t1, tree t2,
 
 static bool
 gimple_types_compatible_p_1 (tree t1, tree t2, type_pair_t p,
-			     VEC(type_pair_t, heap) **sccstack,
+			     vec<type_pair_t> *sccstack,
 			     struct pointer_map_t *sccstate,
 			     struct obstack *sccstate_obstack)
 {
@@ -569,7 +567,7 @@ gimple_types_compatible_p_1 (tree t1, tree t2, type_pair_t p,
   state = XOBNEW (sccstate_obstack, struct sccs);
   *pointer_map_insert (sccstate, p) = state;
 
-  VEC_safe_push (type_pair_t, heap, *sccstack, p);
+  sccstack->safe_push (p);
   state->dfsnum = gtc_next_dfs_num++;
   state->low = state->dfsnum;
   state->on_sccstack = true;
@@ -857,7 +855,7 @@ pop:
       do
 	{
 	  struct sccs *cstate;
-	  x = VEC_pop (type_pair_t, *sccstack);
+	  x = sccstack->pop ();
 	  cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
 	  cstate->on_sccstack = false;
 	  x->same_p = state->u.same_p;
@@ -875,7 +873,7 @@ pop:
 static bool
 gimple_types_compatible_p (tree t1, tree t2)
 {
-  VEC(type_pair_t, heap) *sccstack = NULL;
+  vec<type_pair_t> sccstack = vec<type_pair_t>();
   struct pointer_map_t *sccstate;
   struct obstack sccstate_obstack;
   type_pair_t p = NULL;
@@ -970,7 +968,7 @@ gimple_types_compatible_p (tree t1, tree t2)
   gcc_obstack_init (&sccstate_obstack);
   res = gimple_types_compatible_p_1 (t1, t2, p,
 				     &sccstack, sccstate, &sccstate_obstack);
-  VEC_free (type_pair_t, heap, sccstack);
+  sccstack.release ();
   pointer_map_destroy (sccstate);
   obstack_free (&sccstate_obstack, NULL);
 
@@ -978,7 +976,7 @@ gimple_types_compatible_p (tree t1, tree t2)
 }
 
 static hashval_t
-iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **,
+iterative_hash_gimple_type (tree, hashval_t, vec<tree> *,
 			    struct pointer_map_t *, struct obstack *);
 
 /* DFS visit the edge from the callers type with state *STATE to T.
@@ -988,7 +986,7 @@ iterative_hash_gimple_type (tree, hashval_t, VEC(tree, heap) **,
 
 static hashval_t
 visit (tree t, struct sccs *state, hashval_t v,
-       VEC (tree, heap) **sccstack,
+       vec<tree> *sccstack,
        struct pointer_map_t *sccstate,
        struct obstack *sccstate_obstack)
 {
@@ -1081,7 +1079,7 @@ type_hash_pair_compare (const void *p1_, const void *p2_)
 
 static hashval_t
 iterative_hash_gimple_type (tree type, hashval_t val,
-			    VEC(tree, heap) **sccstack,
+			    vec<tree> *sccstack,
 			    struct pointer_map_t *sccstate,
 			    struct obstack *sccstate_obstack)
 {
@@ -1094,7 +1092,7 @@ iterative_hash_gimple_type (tree type, hashval_t val,
   state = XOBNEW (sccstate_obstack, struct sccs);
   *pointer_map_insert (sccstate, type) = state;
 
-  VEC_safe_push (tree, heap, *sccstack, type);
+  sccstack->safe_push (type);
   state->dfsnum = next_dfs_num++;
   state->low = state->dfsnum;
   state->on_sccstack = true;
@@ -1216,7 +1214,7 @@ iterative_hash_gimple_type (tree type, hashval_t val,
       struct tree_int_map *m;
 
       /* Pop off the SCC and set its hash values.  */
-      x = VEC_pop (tree, *sccstack);
+      x = sccstack->pop ();
       /* Optimize SCC size one.  */
       if (x == type)
 	{
@@ -1234,10 +1232,10 @@ iterative_hash_gimple_type (tree type, hashval_t val,
 	  unsigned first, i, size, j;
 	  struct type_hash_pair *pairs;
 	  /* Pop off the SCC and build an array of type, hash pairs.  */
-	  first = VEC_length (tree, *sccstack) - 1;
-	  while (VEC_index (tree, *sccstack, first) != type)
+	  first = sccstack->length () - 1;
+	  while ((*sccstack)[first] != type)
 	    --first;
-	  size = VEC_length (tree, *sccstack) - first + 1;
+	  size = sccstack->length () - first + 1;
 	  pairs = XALLOCAVEC (struct type_hash_pair, size);
 	  i = 0;
 	  cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
@@ -1246,7 +1244,7 @@ iterative_hash_gimple_type (tree type, hashval_t val,
 	  pairs[i].hash = cstate->u.hash;
 	  do
 	    {
-	      x = VEC_pop (tree, *sccstack);
+	      x = sccstack->pop ();
 	      cstate = (struct sccs *)*pointer_map_contains (sccstate, x);
 	      cstate->on_sccstack = false;
 	      ++i;
@@ -1300,7 +1298,7 @@ static hashval_t
 gimple_type_hash (const void *p)
 {
   const_tree t = (const_tree) p;
-  VEC(tree, heap) *sccstack = NULL;
+  vec<tree> sccstack = vec<tree>();
   struct pointer_map_t *sccstate;
   struct obstack sccstate_obstack;
   hashval_t val;
@@ -1318,7 +1316,7 @@ gimple_type_hash (const void *p)
   gcc_obstack_init (&sccstate_obstack);
   val = iterative_hash_gimple_type (CONST_CAST_TREE (t), 0,
 				    &sccstack, sccstate, &sccstate_obstack);
-  VEC_free (tree, heap, sccstack);
+  sccstack.release ();
   pointer_map_destroy (sccstate);
   obstack_free (&sccstate_obstack, NULL);
 
@@ -1581,13 +1579,13 @@ lto_ft_binfo (tree t)
   LTO_FIXUP_TREE (BINFO_OFFSET (t));
   LTO_FIXUP_TREE (BINFO_VIRTUALS (t));
   LTO_FIXUP_TREE (BINFO_VPTR_FIELD (t));
-  n = VEC_length (tree, BINFO_BASE_ACCESSES (t));
+  n = vec_safe_length (BINFO_BASE_ACCESSES (t));
   for (i = 0; i < n; i++)
     {
       saved_base = base = BINFO_BASE_ACCESS (t, i);
       LTO_FIXUP_TREE (base);
       if (base != saved_base)
-	VEC_replace (tree, BINFO_BASE_ACCESSES (t), i, base);
+	(*BINFO_BASE_ACCESSES (t))[i] = base;
     }
   LTO_FIXUP_TREE (BINFO_INHERITANCE_CHAIN (t));
   LTO_FIXUP_TREE (BINFO_SUBVTT_INDEX (t));
@@ -1598,7 +1596,7 @@ lto_ft_binfo (tree t)
       saved_base = base = BINFO_BASE_BINFO (t, i);
       LTO_FIXUP_TREE (base);
       if (base != saved_base)
-	VEC_replace (tree, BINFO_BASE_BINFOS (t), i, base);
+	(*BINFO_BASE_BINFOS (t))[i] = base;
     }
 }
 
@@ -1612,9 +1610,7 @@ lto_ft_constructor (tree t)
 
   lto_ft_typed (t);
 
-  for (idx = 0;
-       VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (t), idx, ce);
-       idx++)
+  for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (t), idx, &ce); idx++)
     {
       LTO_FIXUP_TREE (ce->index);
       LTO_FIXUP_TREE (ce->value);
@@ -1713,18 +1709,15 @@ lto_fixup_types (tree t)
 static enum ld_plugin_symbol_resolution
 get_resolution (struct data_in *data_in, unsigned index)
 {
-  if (data_in->globals_resolution)
+  if (data_in->globals_resolution.exists ())
     {
       ld_plugin_symbol_resolution_t ret;
       /* We can have references to not emitted functions in
 	 DECL_FUNCTION_PERSONALITY at least.  So we can and have
 	 to indeed return LDPR_UNKNOWN in some cases.   */
-      if (VEC_length (ld_plugin_symbol_resolution_t,
-		      data_in->globals_resolution) <= index)
+      if (data_in->globals_resolution.length () <= index)
 	return LDPR_UNKNOWN;
-      ret = VEC_index (ld_plugin_symbol_resolution_t,
-		       data_in->globals_resolution,
-		       index);
+      ret = data_in->globals_resolution[index];
       return ret;
     }
   else
@@ -1773,7 +1766,7 @@ lto_register_var_decl_in_symtab (struct data_in *data_in, tree decl)
       ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
       SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
       rest_of_decl_compilation (decl, 1, 0);
-      VEC_safe_push (tree, gc, lto_global_var_decls, decl);
+      vec_safe_push (lto_global_var_decls, decl);
     }
 
   /* If this variable has already been declared, queue the
@@ -1855,7 +1848,7 @@ static void
 uniquify_nodes (struct data_in *data_in, unsigned from)
 {
   struct streamer_tree_cache_d *cache = data_in->reader_cache;
-  unsigned len = VEC_length (tree, cache->nodes);
+  unsigned len = cache->nodes.length ();
   unsigned i;
 
   /* Go backwards because children streamed for the first time come
@@ -1866,7 +1859,7 @@ uniquify_nodes (struct data_in *data_in, unsigned from)
      them and computing hashes.  */
   for (i = len; i-- > from;)
     {
-      tree t = VEC_index (tree, cache->nodes, i);
+      tree t = cache->nodes[i];
       if (t && TYPE_P (t))
 	{
 	  tree newt = gimple_register_type (t);
@@ -1881,7 +1874,7 @@ uniquify_nodes (struct data_in *data_in, unsigned from)
   /* Second fixup all trees in the new cache entries.  */
   for (i = len; i-- > from;)
     {
-      tree t = VEC_index (tree, cache->nodes, i);
+      tree t = cache->nodes[i];
       tree oldt = t;
       if (!t)
 	continue;
@@ -2042,7 +2035,7 @@ uniquify_nodes (struct data_in *data_in, unsigned from)
      make sure it is done last.  */
   for (i = len; i-- > from;)
     {
-      tree t = VEC_index (tree, cache->nodes, i);
+      tree t = cache->nodes[i];
       if (t == NULL_TREE)
 	continue;
 
@@ -2065,7 +2058,7 @@ uniquify_nodes (struct data_in *data_in, unsigned from)
 
 static void
 lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
-		VEC(ld_plugin_symbol_resolution_t,heap) *resolutions)
+		vec<ld_plugin_symbol_resolution_t> resolutions)
 {
   const struct lto_decl_header *header = (const struct lto_decl_header *) data;
   const int decl_offset = sizeof (struct lto_decl_header);
@@ -2090,7 +2083,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
   while (ib_main.p < ib_main.len)
     {
       tree t;
-      unsigned from = VEC_length (tree, data_in->reader_cache->nodes);
+      unsigned from = data_in->reader_cache->nodes.length ();
       t = stream_read_tree (&ib_main, data_in);
       gcc_assert (t && ib_main.p <= ib_main.len);
       uniquify_nodes (data_in, from);
@@ -2242,7 +2235,7 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
          format that is only unpacked later when the subfile is processed. */
       rp.res = r;
       rp.index = index;
-      VEC_safe_push (res_pair, heap, file_data->respairs, rp);
+      file_data->respairs.safe_push (rp);
       if (file_data->max_index < index)
         file_data->max_index = index;
     }
@@ -2324,18 +2317,17 @@ lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
 {
   const char *data;
   size_t len;
-  VEC(ld_plugin_symbol_resolution_t,heap) *resolutions = NULL;
+  vec<ld_plugin_symbol_resolution_t>
+	resolutions = vec<ld_plugin_symbol_resolution_t>();
   int i;
   res_pair *rp;
 
   /* Create vector for fast access of resolution. We do this lazily
      to save memory. */ 
-  VEC_safe_grow_cleared (ld_plugin_symbol_resolution_t, heap, 
-                            resolutions,
-                            file_data->max_index + 1);
-  for (i = 0; VEC_iterate (res_pair, file_data->respairs, i, rp); i++)
-    VEC_replace (ld_plugin_symbol_resolution_t, resolutions, rp->index, rp->res);
-  VEC_free (res_pair, heap, file_data->respairs);
+  resolutions.safe_grow_cleared (file_data->max_index + 1);
+  for (i = 0; file_data->respairs.iterate (i, &rp); i++)
+    resolutions[rp->index] = rp->res;
+  file_data->respairs.release ();
 
   file_data->renaming_hash_table = lto_create_renaming_table ();
   file_data->file_name = file->filename;
@@ -2353,7 +2345,7 @@ lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
 /* Finalize FILE_DATA in FILE and increase COUNT. */
 
 static int 
-lto_create_files_from_ids (lto_file *file, struct lto_file_decl_data *file_data, 
+lto_create_files_from_ids (lto_file *file, struct lto_file_decl_data *file_data,
 			   int *count)
 {
   lto_file_finalize (file_data, file);
@@ -2608,7 +2600,7 @@ lto_wpa_write_files (void)
 
   timevar_push (TV_WHOPR_WPA);
 
-  FOR_EACH_VEC_ELT (ltrans_partition, ltrans_partitions, i, part)
+  FOR_EACH_VEC_ELT (ltrans_partitions, i, part)
     lto_stats.num_output_symtab_nodes += lto_symtab_encoder_size (part->encoder);
 
   /* Find out statics that need to be promoted
@@ -2630,17 +2622,18 @@ lto_wpa_write_files (void)
     temp_filename[blen - sizeof (".out") + 1] = '\0';
   blen = strlen (temp_filename);
 
-  n_sets = VEC_length (ltrans_partition, ltrans_partitions);
+  n_sets = ltrans_partitions.length ();
 
   /* Sort partitions by size so small ones are compiled last.
      FIXME: Even when not reordering we may want to output one list for parallel make
      and other for final link command.  */
-  VEC_qsort (ltrans_partition, ltrans_partitions,
-	    flag_toplevel_reorder ? cmp_partitions_size : cmp_partitions_order);
+  ltrans_partitions.qsort (flag_toplevel_reorder
+			   ? cmp_partitions_size
+			   : cmp_partitions_order);
   for (i = 0; i < n_sets; i++)
     {
       size_t len;
-      ltrans_partition part = VEC_index (ltrans_partition, ltrans_partitions, i);
+      ltrans_partition part = ltrans_partitions[i];
 
       /* Write all the nodes in SET.  */
       sprintf (temp_filename + blen, "%u.o", i);
@@ -3091,9 +3084,7 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames)
      this field into ltrans compilation.  */
   if (flag_ltrans)
     FOR_EACH_DEFINED_FUNCTION (node)
-      VEC_safe_push (ipa_opt_pass, heap,
-		     node->ipa_transforms_to_apply,
-		     (ipa_opt_pass)&pass_ipa_inline);
+      node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass)&pass_ipa_inline);
 
   timevar_pop (TV_IPA_LTO_CGRAPH_MERGE);
 
@@ -3148,7 +3139,7 @@ materialize_cgraph (void)
   set_cfun (NULL);
 
   /* Inform the middle end about the global variables we have seen.  */
-  FOR_EACH_VEC_ELT (tree, lto_global_var_decls, i, decl)
+  FOR_EACH_VEC_ELT (*lto_global_var_decls, i, decl)
     rest_of_decl_compilation (decl, 1, 0);
 
   if (!quiet_flag)
@@ -3253,8 +3244,7 @@ do_whole_program_analysis (void)
   FOR_EACH_SYMBOL (node)
     node->symbol.aux = NULL;
 
-  lto_stats.num_cgraph_partitions += VEC_length (ltrans_partition, 
-						 ltrans_partitions);
+  lto_stats.num_cgraph_partitions += ltrans_partitions.length ();
   timevar_pop (TV_WHOPR_PARTITIONING);
 
   timevar_stop (TV_PHASE_OPT_GEN);
