diff options
author | Diego Novillo <dnovillo@google.com> | 2012-11-17 21:54:30 -0500 |
---|---|---|
committer | Diego Novillo <dnovillo@gcc.gnu.org> | 2012-11-17 21:54:30 -0500 |
commit | 9771b26396c39dfaecd5a76dd359fb65d3be4cb6 (patch) | |
tree | 1b9f930d315fa3e0a5ed7fa6e27ec5bd0a3436a4 /gcc/c-family/c-common.c | |
parent | 0f4119158064e271e48a14ce3f88a67e7baf14e0 (diff) | |
download | gcc-9771b26396c39dfaecd5a76dd359fb65d3be4cb6.zip gcc-9771b26396c39dfaecd5a76dd359fb65d3be4cb6.tar.gz gcc-9771b26396c39dfaecd5a76dd359fb65d3be4cb6.tar.bz2 |
This patch rewrites the old VEC macro-based interface into a new one based on the template class 'vec'.
This patch rewrites the old VEC macro-based interface into a new one
based on the template class 'vec'. The user-visible changes are
described in http://gcc.gnu.org/wiki/cxx-conversion/cxx-vec.
I have tested the patch pretty extensively:
- Regular bootstraps on x86_64, ppc, ia64, sparc and hppa.
- Bootstraps with --enable-checking=release
- Bootstraps with --enable-checking=gc,gcac
- Basic builds on all targets (using contrib/config-list.mk).
We no longer access the vectors via VEC_* macros. The pattern is
"VEC_operation (T, A, V, args)" becomes "V.operation (args)".
The only thing I could not do is create proper ctors and dtors for the
vec class. Since these vectors are stored in unions, we
have to keep them as PODs (C++03 does not allow non-PODs in unions).
This means that creation and destruction must be explicit. There is a
new method vec<type, allocation, layout>::create() and another vec<type,
allocation, layout>::destroy() to allocate the internal vector.
For vectors that must be pointers, there is a family of free functions
that implement the operations that need to tolerate NULL vectors.
These functions all start with the prefix 'vec_safe_'. See the wiki
page for details.
The gengtype change removes the special handling for VEC() that used
to exist in gengtype. Additionally, it allows gengtype to recognize
templates of more than one argument and introduces the concept of an
undefined type (useful for template arguments that may or may not be
types).
When a TYPE_UNDEFINED is reached, gengtype will ignore it if it
happens inside a type marked with GTY((user)). Otherwise, it will
emit an error.
Finally, gengtype rejects root types marked GTY((user)) that are not
first class pointers.
2012-11-16 Diego Novillo <dnovillo@google.com>
VEC API overhaul (http://gcc.gnu.org/wiki/cxx-conversion/cxx-vec)
* vec.c (register_overhead): Convert it into
member function of vec_prefix.
(release_overhead): Likewise.
(calculate_allocation): Likewise.
(vec_heap_free): Remove.
(vec_gc_o_reserve_1): Remove.
(vec_heap_o_reserve_1): Remove.
(vec_stack_o_reserve_1): Remove.
(vec_stack_o_reserve_exact): Remove.
(register_stack_vec): New.
(stack_vec_register_index): New.
(unregister_stack_vec): New.
(vec_assert_fail): Remove.
* vec.h: Conditionally include ggc.h. Document conditional
hackery.
Update top-level documentation.
(ALONE_VEC_CHECK_INFO): Remove.
(VEC_CHECK_INFO): Remove.
(ALONE_VEC_CHECK_DECL): Remove.
(VEC_CHECK_DECL): Remove.
(ALONE_VEC_CHECK_PASS): Remove.
(VEC_CHECK_PASS): Remove.
(VEC_ASSERT): Remove.
(vec_prefix): Add friends va_gc, va_gc_atomic, va_heap and
va_stack.
Mark fields alloc_ and num_ as protected.
(struct vec_t): Remove. Remove all function members.
(struct vl_embed): Declare.
(struct vl_ptr): Declare.
(free): Remove.
(reserve_exact): Remove.
(reserve): Remove.
(safe_splice): Remove.
(safe_push): Remove.
(safe_grow): Remove.
(safe_grow_cleared): Remove.
(safe_insert): Remove.
(DEF_VEC_I): Remove.
(DEF_VEC_ALLOC_I): Remove.
(DEF_VEC_P): Remove.
(DEF_VEC_ALLOC_P): Remove.
(DEF_VEC_O): Remove.
(DEF_VEC_ALLOC_O): Remove.
(DEF_VEC_ALLOC_P_STACK): Remove.
(DEF_VEC_ALLOC_O_STACK): Remove.
(DEF_VEC_ALLOC_I_STACK): Remove.
(DEF_VEC_A): Remove.
(DEF_VEC_ALLOC_A): Remove.
(vec_stack_p_reserve_exact_1): Remove.
(vec_stack_o_reserve): Remove.
(vec_stack_o_reserve_exact): Remove.
(VEC_length): Remove.
(VEC_empty): Remove.
(VEC_address): Remove.
(vec_address): Remove.
(VEC_last): Remove.
(VEC_index): Remove.
(VEC_iterate): Remove.
(VEC_embedded_size): Remove.
(VEC_embedded_init): Remove.
(VEC_free): Remove.
(VEC_copy): Remove.
(VEC_space): Remove.
(VEC_reserve): Remove.
(VEC_reserve_exact): Remove.
(VEC_splice): Remove.
(VEC_safe_splice): Remove.
(VEC_quick_push): Remove.
(VEC_safe_push): Remove.
(VEC_pop): Remove.
(VEC_truncate): Remove.
(VEC_safe_grow): Remove.
(VEC_replace): Remove.
(VEC_quick_insert): Remove.
(VEC_safe_insert): Remove.
(VEC_ordered_remove): Remove.
(VEC_unordered_remove): Remove.
(VEC_block_remove): Remove.
(VEC_lower_bound): Remove.
(VEC_alloc): Remove.
(VEC_qsort): Remove.
(va_heap): Declare.
(va_heap::default_layout): New typedef to vl_ptr.
(va_heap::reserve): New.
(va_heap::release): New.
(va_gc): Declare.
(va_gc::default_layout): New typedef to vl_embed.
(va_gc::reserve): New.
(va_gc::release): New.
(va_gc_atomic): Declare. Inherit from va_gc.
(va_stack): Declare.
(va_stack::default_layout): New typedef to vl_ptr.
(va_stack::alloc): New.
(va_stack::reserve): New.
(va_stack::release): New.
(register_stack_vec): Declare.
(stack_vec_register_index): Declare.
(unregister_stack_vec): Declare.
(vec<T, A = va_heap, L = typename A::default_layout>): Declare
empty vec template.
(vec<T, A, vl_embed>): Partial specialization for embedded
layout.
(vec<T, A, vl_embed>::allocated): New.
(vec<T, A, vl_embed>::length): New.
(vec<T, A, vl_embed>::is_empty): New.
(vec<T, A, vl_embed>::address): New.
(vec<T, A, vl_embed>::operator[]): New.
(vec<T, A, vl_embed>::last New.
(vec<T, A, vl_embed>::space): New.
(vec<T, A, vl_embed>::iterate): New.
(vec<T, A, vl_embed>::iterate): New.
(vec<T, A, vl_embed>::copy): New.
(vec<T, A, vl_embed>::splice): New.
(vec<T, A, vl_embed>::quick_push New.
(vec<T, A, vl_embed>::pop New.
(vec<T, A, vl_embed>::truncate): New.
(vec<T, A, vl_embed>::quick_insert): New.
(vec<T, A, vl_embed>::ordered_remove): New.
(vec<T, A, vl_embed>::unordered_remove): New.
(vec<T, A, vl_embed>::block_remove): New.
(vec<T, A, vl_embed>::qsort): New.
(vec<T, A, vl_embed>::lower_bound): New.
(vec<T, A, vl_embed>::embedded_size): New.
(vec<T, A, vl_embed>::embedded_init): New.
(vec<T, A, vl_embed>::quick_grow): New.
(vec<T, A, vl_embed>::quick_grow_cleared): New.
(vec_safe_space): New.
(vec_safe_length): New.
(vec_safe_address): New.
(vec_safe_is_empty): New.
(vec_safe_reserve): New.
(vec_safe_reserve_exact): New.
(vec_alloc): New.
(vec_free): New.
(vec_safe_grow): New.
(vec_safe_grow_cleared): New.
(vec_safe_iterate): New.
(vec_safe_push): New.
(vec_safe_insert): New.
(vec_safe_truncate): New.
(vec_safe_copy): New.
(vec_safe_splice): New.
(vec<T, A, vl_ptr>): New partial specialization for the space
efficient layout.
(vec<T, A, vl_ptr>::exists): New.
(vec<T, A, vl_ptr>::is_empty): New.
(vec<T, A, vl_ptr>::length): New.
(vec<T, A, vl_ptr>::address): New.
(vec<T, A, vl_ptr>::operator[]): New.
(vec<T, A, vl_ptr>::operator!=): New.
(vec<T, A, vl_ptr>::operator==): New.
(vec<T, A, vl_ptr>::last): New.
(vec<T, A, vl_ptr>::space): New.
(vec<T, A, vl_ptr>::iterate): New.
(vec<T, A, vl_ptr>::copy): New.
(vec<T, A, vl_ptr>::reserve): New.
(vec<T, A, vl_ptr>::reserve_exact): New.
(vec<T, A, vl_ptr>::splice): New.
(vec<T, A, vl_ptr>::safe_splice): New.
(vec<T, A, vl_ptr>::quick_push): New.
(vec<T, A, vl_ptr>::safe_push): New.
(vec<T, A, vl_ptr>::pop): New.
(vec<T, A, vl_ptr>::truncate): New.
(vec<T, A, vl_ptr>::safe_grow): New.
(vec<T, A, vl_ptr>::safe_grow_cleared): New.
(vec<T, A, vl_ptr>::quick_grow): New.
(vec<T, A, vl_ptr>::quick_grow_cleared): New.
(vec<T, A, vl_ptr>::quick_insert): New.
(vec<T, A, vl_ptr>::safe_insert): New.
(vec<T, A, vl_ptr>::ordered_remove): New.
(vec<T, A, vl_ptr>::unordered_remove): New.
(vec<T, A, vl_ptr>::block_remove): New.
(vec<T, A, vl_ptr>::qsort): New.
(vec<T, A, vl_ptr>::lower_bound): New.
(vec_stack_alloc): Define.
(FOR_EACH_VEC_SAFE_ELT): Define.
* vecir.h: Remove. Update all users.
* vecprim.h: Remove. Update all users.
Move uchar to coretypes.h.
* Makefile.in (VEC_H): Add $(GGC_H).
Remove vecir.h and vecprim.h dependencies everywhere.
2012-11-16 Diego Novillo <dnovillo@google.com>
* gengtype-lex.l (VEC): Remove.
Add characters in the set [\!\>\.-].
* gengtype-parse.c (token_names): Remove "VEC".
(require_template_declaration): Remove handling of VEC_TOKEN.
(type): Likewise.
Call create_user_defined_type when parsing GTY((user)).
* gengtype-state.c (type_lineloc): handle TYPE_UNDEFINED.
(write_state_undefined_type): New.
(write_state_type): Call write_state_undefined_type for
TYPE_UNDEFINED.
(read_state_type): Call read_state_undefined_type for
TYPE_UNDEFINED.
* gengtype.c (dbgprint_count_type_at): Handle TYPE_UNDEFINED.
(create_user_defined_type): Make extern.
(type_for_name): Factor out of resolve_typedef.
(create_undefined_type): New
(resolve_typedef): Call it when we cannot find a previous
typedef and the type is not a template.
(find_structure): Accept TYPE_UNDEFINED.
(set_gc_used_type): Add argument ALLOWED_UNDEFINED_TYPES,
default to false.
Emit an error for TYPE_UNDEFINED unless LEVEL is GC_UNUSED or
ALLOWED_UNDEFINED_TYPES is set.
Set ALLOWED_UNDEFINED_TYPES to true for TYPE_USER_STRUCT.
(filter_type_name): Accept templates with more than one
argument.
(output_mangled_typename): Handle TYPE_UNDEFINED
(walk_type): Likewise.
(write_types_process_field): Likewise.
(write_func_for_structure): If CHAIN_NEXT is set, ORIG_S
should not be a user-defined type.
(write_types_local_user_process_field): Handle TYPE_ARRAY,
TYPE_NONE and TYPE_UNDEFINED.
(write_types_local_process_field): Likewise.
(contains_scalar_p): Return 0 for TYPE_USER_STRUCT.
(write_root): Reject user-defined types that are not pointers.
Handle TYPE_NONE, TYPE_UNDEFINED, TYPE_UNION, TYPE_LANG_STRUCT
and TYPE_PARAM_STRUCT.
(output_typename): Handle TYPE_NONE, TYPE_UNDEFINED, and
TYPE_ARRAY.
(dump_typekind): Handle TYPE_UNDEFINED.
* gengtype.h (enum typekind): Add TYPE_UNDEFINED.
(create_user_defined_type): Declare.
(enum gty_token): Remove VEC_TOKEN.
2012-11-16 Diego Novillo <dnovillo@google.com>
Adjust for new vec API (http://gcc.gnu.org/wiki/cxx-conversion/cxx-vec)
* coretypes.h (uchar): Define.
* alias.c: Use new vec API in vec.h.
* asan.c: Likewise.
* attribs.c: Likewise.
* basic-block.h: Likewise.
* bb-reorder.c: Likewise.
* builtins.c: Likewise.
* calls.c: Likewise.
* cfg.c: Likewise.
* cfganal.c: Likewise.
* cfgcleanup.c: Likewise.
* cfgexpand.c: Likewise.
* cfghooks.c: Likewise.
* cfghooks.h: Likewise.
* cfgloop.c: Likewise.
* cfgloop.h: Likewise.
* cfgloopanal.c: Likewise.
* cfgloopmanip.c: Likewise.
* cfgrtl.c: Likewise.
* cgraph.c: Likewise.
* cgraph.h: Likewise.
* cgraphclones.c: Likewise.
* cgraphunit.c: Likewise.
* combine.c: Likewise.
* compare-elim.c: Likewise.
* coverage.c: Likewise.
* cprop.c: Likewise.
* data-streamer.h: Likewise.
* dbxout.c: Likewise.
* dce.c: Likewise.
* df-core.c: Likewise.
* df-problems.c: Likewise.
* df-scan.c: Likewise.
* dominance.c: Likewise.
* domwalk.c: Likewise.
* domwalk.h: Likewise.
* dse.c: Likewise.
* dwarf2cfi.c: Likewise.
* dwarf2out.c: Likewise.
* dwarf2out.h: Likewise.
* emit-rtl.c: Likewise.
* except.c: Likewise.
* except.h: Likewise.
* expr.c: Likewise.
* expr.h: Likewise.
* final.c: Likewise.
* fold-const.c: Likewise.
* function.c: Likewise.
* function.h: Likewise.
* fwprop.c: Likewise.
* gcc.c: Likewise.
* gcse.c: Likewise.
* genattr.c: Likewise.
* genattrtab.c: Likewise.
* genautomata.c: Likewise.
* genextract.c: Likewise.
* genopinit.c: Likewise
* ggc-common.c: Likewise.
* ggc.h: Likewise.
* gimple-low.c: Likewise.
* gimple-ssa-strength-reduction.c: Likewise.
* gimple-streamer-in.c: Likewise.
* gimple.c: Likewise.
* gimple.h: Likewise.
* gimplify.c: Likewise.
* graph.c: Likewise.
* graphds.c: Likewise.
* graphds.h: Likewise.
* graphite-blocking.c: Likewise.
* graphite-clast-to-gimple.c: Likewise.
* graphite-dependences.c: Likewise.
* graphite-interchange.c: Likewise.
* graphite-optimize-isl.c: Likewise.
* graphite-poly.c: Likewise.
* graphite-poly.h: Likewise.
* graphite-scop-detection.c: Likewise.
* graphite-scop-detection.h: Likewise.
* graphite-sese-to-poly.c: Likewise.
* graphite.c: Likewise.
* godump.c: Likewise.
* haifa-sched.c: Likewise.
* hw-doloop.c: Likewise.
* hw-doloop.h: Likewise.
* ifcvt.c: Likewise.
* insn-addr.h: Likewise.
* ipa-cp.c: Likewise.
* ipa-inline-analysis.c: Likewise.
* ipa-inline-transform.c: Likewise.
* ipa-inline.c: Likewise.
* ipa-inline.h: Likewise.
* ipa-prop.c: Likewise.
* ipa-prop.h: Likewise.
* ipa-pure-const.c: Likewise.
* ipa-ref-inline.h: Likewise.
* ipa-ref.c: Likewise.
* ipa-ref.h: Likewise.
* ipa-reference.c: Likewise.
* ipa-split.c: Likewise.
* ipa-utils.c: Likewise.
* ipa-utils.h: Likewise.
* ipa.c: Likewise.
* ira-build.c: Likewise.
* ira-color.c: Likewise.
* ira-emit.c: Likewise.
* ira-int.h: Likewise.
* ira.c: Likewise.
* loop-invariant.c: Likewise.
* loop-unroll.c: Likewise.
* lower-subreg.c: Likewise.
* lra-lives.c: Likewise.
* lra.c: Likewise.
* lto-cgraph.c: Likewise.
* lto-section-out.c: Likewise.
* lto-streamer-in.c: Likewise.
* lto-streamer-out.c: Likewise.
* lto-streamer.h: Likewise.
* lto-symtab.c: Likewise.
* mcf.c: Likewise.
* modulo-sched.c: Likewise.
* omp-low.c: Likewise.
* opts-common.c: Likewise.
* opts-global.c: Likewise.
* opts.c: Likewise.
* opts.h: Likewise.
* passes.c: Likewise.
* predict.c: Likewise.
* print-tree.c: Likewise.
* profile.c: Likewise.
* profile.h: Likewise.
* read-rtl.c: Likewise.
* ree.c: Likewise.
* reg-stack.c: Likewise.
* regrename.c: Likewise.
* regrename.h: Likewise.
* reload.c: Likewise.
* reload.h: Likewise.
* reload1.c: Likewise.
* rtl.h: Likewise.
* sched-deps.c: Likewise.
* sched-int.h: Likewise.
* sdbout.c: Likewise.
* sel-sched-dump.c: Likewise.
* sel-sched-ir.c: Likewise.
* sel-sched-ir.h: Likewise.
* sel-sched.c: Likewise.
* sese.c: Likewise.
* sese.h: Likewise.
* statistics.h: Likewise.
* stmt.c: Likewise.
* stor-layout.c: Likewise.
* store-motion.c: Likewise.
* tlink.c: Likewise.
* toplev.c: Likewise.
* trans-mem.c: Likewise.
* tree-browser.c: Likewise.
* tree-call-cdce.c: Likewise.
* tree-cfg.c: Likewise.
* tree-cfgcleanup.c: Likewise.
* tree-chrec.c: Likewise.
* tree-chrec.h: Likewise.
* tree-complex.c: Likewise.
* tree-data-ref.c: Likewise.
* tree-data-ref.h: Likewise.
* tree-dfa.c: Likewise.
* tree-diagnostic.c: Likewise.
* tree-dump.c: Likewise.
* tree-eh.c: Likewise.
* tree-emutls.c: Likewise.
* tree-flow.h: Likewise.
* tree-if-conv.c: Likewise.
* tree-inline.c: Likewise.
* tree-inline.h: Likewise.
* tree-into-ssa.c: Likewise.
* tree-iterator.c: Likewise.
* tree-loop-distribution.c: Likewise.
* tree-mudflap.c: Likewise.
* tree-optimize.c: Likewise.
* tree-outof-ssa.c: Likewise.
* tree-parloops.c: Likewise.
* tree-phinodes.c: Likewise.
* tree-predcom.c: Likewise.
* tree-pretty-print.c: Likewise.
* tree-scalar-evolution.c: Likewise.
* tree-sra.c: Likewise.
* tree-ssa-address.c: Likewise.
* tree-ssa-alias.c: Likewise.
* tree-ssa-ccp.c: Likewise.
* tree-ssa-coalesce.c: Likewise.
* tree-ssa-dce.c: Likewise.
* tree-ssa-dom.c: Likewise.
* tree-ssa-forwprop.c: Likewise.
* tree-ssa-live.c: Likewise.
* tree-ssa-live.h: Likewise.
* tree-ssa-loop-im.c: Likewise.
* tree-ssa-loop-ivcanon.c: Likewise.
* tree-ssa-loop-ivopts.c: Likewise.
* tree-ssa-loop-manip.c: Likewise.
* tree-ssa-loop-niter.c: Likewise.
* tree-ssa-loop-prefetch.c: Likewise.
* tree-ssa-math-opts.c: Likewise.
* tree-ssa-operands.c: Likewise.
* tree-ssa-phiopt.c: Likewise.
* tree-ssa-phiprop.c: Likewise.
* tree-ssa-pre.c: Likewise.
* tree-ssa-propagate.c: Likewise.
* tree-ssa-reassoc.c: Likewise.
* tree-ssa-sccvn.c: Likewise.
* tree-ssa-sccvn.h: Likewise.
* tree-ssa-strlen.c: Likewise.
* tree-ssa-structalias.c: Likewise.
* tree-ssa-tail-merge.c: Likewise.
* tree-ssa-threadedge.c: Likewise.
* tree-ssa-threadupdate.c: Likewise.
* tree-ssa-uncprop.c: Likewise.
* tree-ssa-uninit.c: Likewise.
* tree-ssa.c: Likewise.
* tree-ssanames.c: Likewise.
* tree-stdarg.c: Likewise.
* tree-streamer-in.c: Likewise.
* tree-streamer-out.c: Likewise.
* tree-streamer.c: Likewise.
* tree-streamer.h: Likewise.
* tree-switch-conversion.c: Likewise.
* tree-vect-data-refs.c: Likewise.
* tree-vect-generic.c: Likewise.
* tree-vect-loop-manip.c: Likewise.
* tree-vect-loop.c: Likewise.
* tree-vect-patterns.c: Likewise.
* tree-vect-slp.c: Likewise.
* tree-vect-stmts.c: Likewise.
* tree-vectorizer.c: Likewise.
* tree-vectorizer.h: Likewise.
* tree-vrp.c: Likewise.
* tree.c: Likewise.
* tree.h: Likewise.
* value-prof.c: Likewise.
* value-prof.h: Likewise.
* var-tracking.c: Likewise.
* varasm.c: Likewise.
* varpool.c: Likewise.
* vmsdbgout.c: Likewise.
* config/bfin/bfin.c: Likewise.
* config/c6x/c6x.c: Likewise.
* config/darwin.c: Likewise.
* config/i386/i386.c: Likewise.
* config/ia64/ia64.c: Likewise.
* config/mep/mep.c: Likewise.
* config/mips/mips.c: Likewise.
* config/pa/pa.c: Likewise.
* config/rs6000/rs6000-c.c: Likewise.
* config/rs6000/rs6000.c: Likewise.
* config/rx/rx.c: Likewise.
* config/spu/spu-c.c: Likewise.
* config/vms/vms.c: Likewise.
* config/vxworks.c: Likewise.
* config/epiphany/resolve-sw-modes.c: Likewise.
From-SVN: r193595
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r-- | gcc/c-family/c-common.c | 245 |
1 files changed, 119 insertions, 126 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 7828d21..fac7190 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1839,7 +1839,7 @@ strict_aliasing_warning (tree otype, tree type, tree expr) void sizeof_pointer_memaccess_warning (location_t *sizeof_arg_loc, tree callee, - VEC(tree, gc) *params, tree *sizeof_arg, + vec<tree, va_gc> *params, tree *sizeof_arg, bool (*comp_types) (tree, tree)) { tree type, dest = NULL_TREE, src = NULL_TREE, tem; @@ -1849,7 +1849,7 @@ sizeof_pointer_memaccess_warning (location_t *sizeof_arg_loc, tree callee, if (TREE_CODE (callee) != FUNCTION_DECL || DECL_BUILT_IN_CLASS (callee) != BUILT_IN_NORMAL - || VEC_length (tree, params) <= 1) + || vec_safe_length (params) <= 1) return; switch (DECL_FUNCTION_CODE (callee)) @@ -1870,55 +1870,55 @@ sizeof_pointer_memaccess_warning (location_t *sizeof_arg_loc, tree callee, case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMMOVE: case BUILT_IN_MEMMOVE_CHK: - if (VEC_length (tree, params) < 3) + if (params->length () < 3) return; - src = VEC_index (tree, params, 1); - dest = VEC_index (tree, params, 0); + src = (*params)[1]; + dest = (*params)[0]; idx = 2; break; case BUILT_IN_BCOPY: - if (VEC_length (tree, params) < 3) + if (params->length () < 3) return; - src = VEC_index (tree, params, 0); - dest = VEC_index (tree, params, 1); + src = (*params)[0]; + dest = (*params)[1]; idx = 2; break; case BUILT_IN_MEMCMP: case BUILT_IN_BCMP: - if (VEC_length (tree, params) < 3) + if (params->length () < 3) return; - src = VEC_index (tree, params, 1); - dest = VEC_index (tree, params, 0); + src = (*params)[1]; + dest = (*params)[0]; idx = 2; cmp = true; break; case BUILT_IN_MEMSET: case BUILT_IN_MEMSET_CHK: - if (VEC_length (tree, params) < 3) + if (params->length () < 3) return; - dest = VEC_index (tree, params, 0); + dest = (*params)[0]; idx = 2; break; case BUILT_IN_BZERO: - dest = VEC_index (tree, params, 0); + dest = (*params)[0]; idx = 1; break; case BUILT_IN_STRNDUP: - src = VEC_index (tree, params, 0); + src = (*params)[0]; strop = true; idx = 1; break; case BUILT_IN_MEMCHR: - if (VEC_length (tree, params) < 3) + if (params->length () < 3) return; - src = VEC_index (tree, params, 0); + src = (*params)[0]; idx = 2; break; case BUILT_IN_SNPRINTF: case BUILT_IN_SNPRINTF_CHK: case BUILT_IN_VSNPRINTF: case BUILT_IN_VSNPRINTF_CHK: - dest = VEC_index (tree, params, 0); + dest = (*params)[0]; idx = 1; strop = true; break; @@ -8729,9 +8729,7 @@ handle_target_attribute (tree *node, tree name, tree args, int flags, /* Arguments being collected for optimization. */ typedef const char *const_char_p; /* For DEF_VEC_P. */ -DEF_VEC_P(const_char_p); -DEF_VEC_ALLOC_P(const_char_p, gc); -static GTY(()) VEC(const_char_p, gc) *optimize_args; +static GTY(()) vec<const_char_p, va_gc> *optimize_args; /* Inner function to convert a TREE_LIST to argv string to parse the optimize @@ -8752,8 +8750,8 @@ parse_optimize_options (tree args, bool attr_p) /* Build up argv vector. Just in case the string is stored away, use garbage collected strings. */ - VEC_truncate (const_char_p, optimize_args, 0); - VEC_safe_push (const_char_p, gc, optimize_args, NULL); + vec_safe_truncate (optimize_args, 0); + vec_safe_push (optimize_args, (const char *) NULL); for (ap = args; ap != NULL_TREE; ap = TREE_CHAIN (ap)) { @@ -8763,7 +8761,7 @@ parse_optimize_options (tree args, bool attr_p) { char buffer[20]; sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value)); - VEC_safe_push (const_char_p, gc, optimize_args, ggc_strdup (buffer)); + vec_safe_push (optimize_args, ggc_strdup (buffer)); } else if (TREE_CODE (value) == STRING_CST) @@ -8825,17 +8823,17 @@ parse_optimize_options (tree args, bool attr_p) memcpy (r, p, len2); r[len2] = '\0'; - VEC_safe_push (const_char_p, gc, optimize_args, q); + vec_safe_push (optimize_args, (const char *) q); } } } - opt_argc = VEC_length (const_char_p, optimize_args); + opt_argc = optimize_args->length (); opt_argv = (const char **) alloca (sizeof (char *) * (opt_argc + 1)); for (i = 1; i < opt_argc; i++) - opt_argv[i] = VEC_index (const_char_p, optimize_args, i); + opt_argv[i] = (*optimize_args)[i]; saved_flag_strict_aliasing = flag_strict_aliasing; @@ -8852,7 +8850,7 @@ parse_optimize_options (tree args, bool attr_p) /* Don't allow changing -fstrict-aliasing. */ flag_strict_aliasing = saved_flag_strict_aliasing; - VEC_truncate (const_char_p, optimize_args, 0); + optimize_args->truncate (0); return ret; } @@ -9736,9 +9734,9 @@ complete_array_type (tree *ptype, tree initial_value, bool do_default) } else if (TREE_CODE (initial_value) == CONSTRUCTOR) { - VEC(constructor_elt,gc) *v = CONSTRUCTOR_ELTS (initial_value); + vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value); - if (VEC_empty (constructor_elt, v)) + if (vec_safe_is_empty (v)) { if (pedantic) failure = 3; @@ -9751,15 +9749,12 @@ complete_array_type (tree *ptype, tree initial_value, bool do_default) constructor_elt *ce; bool fold_p = false; - if (VEC_index (constructor_elt, v, 0).index) + if ((*v)[0].index) maxindex = fold_convert_loc (input_location, sizetype, - VEC_index (constructor_elt, - v, 0).index); + (*v)[0].index); curindex = maxindex; - for (cnt = 1; - VEC_iterate (constructor_elt, v, cnt, ce); - cnt++) + for (cnt = 1; vec_safe_iterate (v, cnt, &ce); cnt++) { bool curfold_p = false; if (ce->index) @@ -9879,18 +9874,18 @@ builtin_type_for_size (int size, bool unsignedp) Returns 0 if an error is encountered. */ static int -sync_resolve_size (tree function, VEC(tree,gc) *params) +sync_resolve_size (tree function, vec<tree, va_gc> *params) { tree type; int size; - if (VEC_empty (tree, params)) + if (!params) { error ("too few arguments to function %qE", function); return 0; } - type = TREE_TYPE (VEC_index (tree, params, 0)); + type = TREE_TYPE ((*params)[0]); if (TREE_CODE (type) != POINTER_TYPE) goto incompatible; @@ -9914,7 +9909,7 @@ sync_resolve_size (tree function, VEC(tree,gc) *params) static bool sync_resolve_params (location_t loc, tree orig_function, tree function, - VEC(tree, gc) *params, bool orig_format) + vec<tree, va_gc> *params, bool orig_format) { function_args_iterator iter; tree ptype; @@ -9925,7 +9920,7 @@ sync_resolve_params (location_t loc, tree orig_function, tree function, as the pointer parameter, so we shouldn't get any complaints from the call to check_function_arguments what ever type the user used. */ function_args_iter_next (&iter); - ptype = TREE_TYPE (TREE_TYPE (VEC_index (tree, params, 0))); + ptype = TREE_TYPE (TREE_TYPE ((*params)[0])); /* For the rest of the values, we need to cast these to FTYPE, so that we don't get warnings for passing pointer types, etc. */ @@ -9940,7 +9935,7 @@ sync_resolve_params (location_t loc, tree orig_function, tree function, break; ++parmnum; - if (VEC_length (tree, params) <= parmnum) + if (params->length () <= parmnum) { error_at (loc, "too few arguments to function %qE", orig_function); return false; @@ -9956,17 +9951,17 @@ sync_resolve_params (location_t loc, tree orig_function, tree function, /* Ideally for the first conversion we'd use convert_for_assignment so that we get warnings for anything that doesn't match the pointer type. This isn't portable across the C and C++ front ends atm. */ - val = VEC_index (tree, params, parmnum); + val = (*params)[parmnum]; val = convert (ptype, val); val = convert (arg_type, val); - VEC_replace (tree, params, parmnum, val); + (*params)[parmnum] = val; } function_args_iter_next (&iter); } /* __atomic routines are not variadic. */ - if (!orig_format && VEC_length (tree, params) != parmnum + 1) + if (!orig_format && params->length () != parmnum + 1) { error_at (loc, "too many arguments to function %qE", orig_function); return false; @@ -9976,7 +9971,7 @@ sync_resolve_params (location_t loc, tree orig_function, tree function, being "an optional list of variables protected by the memory barrier". No clue what that's supposed to mean, precisely, but we consider all call-clobbered variables to be protected so we're safe. */ - VEC_truncate (tree, params, parmnum + 1); + params->truncate (parmnum + 1); return true; } @@ -10004,7 +9999,8 @@ sync_resolve_return (tree first_param, tree result, bool orig_format) 0 is returned if the parameters are invalid. */ static int -get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params) +get_atomic_generic_size (location_t loc, tree function, + vec<tree, va_gc> *params) { unsigned int n_param; unsigned int n_model; @@ -10032,14 +10028,14 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params) gcc_unreachable (); } - if (VEC_length (tree, params) != n_param) + if (vec_safe_length (params) != n_param) { error_at (loc, "incorrect number of arguments to function %qE", function); return 0; } /* Get type of first parameter, and determine its size. */ - type_0 = TREE_TYPE (VEC_index (tree, params, 0)); + type_0 = TREE_TYPE ((*params)[0]); if (TREE_CODE (type_0) != POINTER_TYPE || VOID_TYPE_P (TREE_TYPE (type_0))) { error_at (loc, "argument 1 of %qE must be a non-void pointer type", @@ -10071,7 +10067,7 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params) for (x = 0; x < n_param - n_model; x++) { int size; - tree type = TREE_TYPE (VEC_index (tree, params, x)); + tree type = TREE_TYPE ((*params)[x]); /* __atomic_compare_exchange has a bool in the 4th postion, skip it. */ if (n_param == 6 && x == 3) continue; @@ -10093,7 +10089,7 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params) /* Check memory model parameters for validity. */ for (x = n_param - n_model ; x < n_param; x++) { - tree p = VEC_index (tree, params, x); + tree p = (*params)[x]; if (TREE_CODE (p) == INTEGER_CST) { int i = tree_low_cst (p, 1); @@ -10126,30 +10122,30 @@ get_atomic_generic_size (location_t loc, tree function, VEC(tree,gc) *params) static tree add_atomic_size_parameter (unsigned n, location_t loc, tree function, - VEC(tree,gc) *params) + vec<tree, va_gc> *params) { tree size_node; /* Insert a SIZE_T parameter as the first param. If there isn't enough space, allocate a new vector and recursively re-build with that. */ - if (!VEC_space (tree, params, 1)) + if (!params->space (1)) { unsigned int z, len; - VEC(tree,gc) *vec; + vec<tree, va_gc> *v; tree f; - len = VEC_length (tree, params); - vec = VEC_alloc (tree, gc, len + 1); + len = params->length (); + vec_alloc (v, len + 1); for (z = 0; z < len; z++) - VEC_quick_push (tree, vec, VEC_index (tree, params, z)); - f = build_function_call_vec (loc, function, vec, NULL); - VEC_free (tree, gc, vec); + v->quick_push ((*params)[z]); + f = build_function_call_vec (loc, function, v, NULL); + vec_free (v); return f; } /* Add the size parameter and leave as a function call for processing. */ size_node = build_int_cst (size_type_node, n); - VEC_quick_insert (tree, params, 0, size_node); + params->quick_insert (0, size_node); return NULL_TREE; } @@ -10165,7 +10161,7 @@ add_atomic_size_parameter (unsigned n, location_t loc, tree function, NEW_RETURN is set to the the return value the result is copied into. */ static bool resolve_overloaded_atomic_exchange (location_t loc, tree function, - VEC(tree,gc) *params, tree *new_return) + vec<tree, va_gc> *params, tree *new_return) { tree p0, p1, p2, p3; tree I_type, I_type_ptr; @@ -10190,10 +10186,10 @@ resolve_overloaded_atomic_exchange (location_t loc, tree function, into *return = (T) (fn (In* mem, (In) *desired, model)) */ - p0 = VEC_index (tree, params, 0); - p1 = VEC_index (tree, params, 1); - p2 = VEC_index (tree, params, 2); - p3 = VEC_index (tree, params, 3); + p0 = (*params)[0]; + p1 = (*params)[1]; + p2 = (*params)[2]; + p3 = (*params)[3]; /* Create pointer to appropriate size. */ I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); @@ -10201,15 +10197,15 @@ resolve_overloaded_atomic_exchange (location_t loc, tree function, /* Convert object pointer to required type. */ p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); - VEC_replace (tree, params, 0, p0); + (*params)[0] = p0; /* Convert new value to required type, and dereference it. */ p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR); p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1); - VEC_replace (tree, params, 1, p1); + (*params)[1] = p1; /* Move memory model to the 3rd position, and end param list. */ - VEC_replace (tree, params, 2, p3); - VEC_truncate (tree, params, 3); + (*params)[2] = p3; + params->truncate (3); /* Convert return pointer and dereference it for later assignment. */ *new_return = build_indirect_ref (loc, p2, RO_UNARY_STAR); @@ -10229,7 +10225,7 @@ resolve_overloaded_atomic_exchange (location_t loc, tree function, static bool resolve_overloaded_atomic_compare_exchange (location_t loc, tree function, - VEC(tree,gc) *params, + vec<tree, va_gc> *params, tree *new_return) { tree p0, p1, p2; @@ -10253,9 +10249,9 @@ resolve_overloaded_atomic_compare_exchange (location_t loc, tree function, there is no danger this will be done twice. */ if (n > 0) { - VEC_replace (tree, params, 3, VEC_index (tree, params, 4)); - VEC_replace (tree, params, 4, VEC_index (tree, params, 5)); - VEC_truncate (tree, params, 5); + (*params)[3] = (*params)[4]; + (*params)[4] = (*params)[5]; + params->truncate (5); } *new_return = add_atomic_size_parameter (n, loc, function, params); return true; @@ -10266,9 +10262,9 @@ resolve_overloaded_atomic_compare_exchange (location_t loc, tree function, into bool fn ((In *)mem, (In *)expected, (In) *desired, weak, succ, fail) */ - p0 = VEC_index (tree, params, 0); - p1 = VEC_index (tree, params, 1); - p2 = VEC_index (tree, params, 2); + p0 = (*params)[0]; + p1 = (*params)[1]; + p2 = (*params)[2]; /* Create pointer to appropriate size. */ I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); @@ -10276,16 +10272,16 @@ resolve_overloaded_atomic_compare_exchange (location_t loc, tree function, /* Convert object pointer to required type. */ p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); - VEC_replace (tree, params, 0, p0); + (*params)[0] = p0; /* Convert expected pointer to required type. */ p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1); - VEC_replace (tree, params, 1, p1); + (*params)[1] = p1; /* Convert desired value to required type, and dereference it. */ p2 = build_indirect_ref (loc, p2, RO_UNARY_STAR); p2 = build1 (VIEW_CONVERT_EXPR, I_type, p2); - VEC_replace (tree, params, 2, p2); + (*params)[2] = p2; /* The rest of the parameters are fine. NULL means no special return value processing.*/ @@ -10306,7 +10302,7 @@ resolve_overloaded_atomic_compare_exchange (location_t loc, tree function, static bool resolve_overloaded_atomic_load (location_t loc, tree function, - VEC(tree,gc) *params, tree *new_return) + vec<tree, va_gc> *params, tree *new_return) { tree p0, p1, p2; tree I_type, I_type_ptr; @@ -10331,9 +10327,9 @@ resolve_overloaded_atomic_load (location_t loc, tree function, into *return = (T) (fn ((In *) mem, model)) */ - p0 = VEC_index (tree, params, 0); - p1 = VEC_index (tree, params, 1); - p2 = VEC_index (tree, params, 2); + p0 = (*params)[0]; + p1 = (*params)[1]; + p2 = (*params)[2]; /* Create pointer to appropriate size. */ I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); @@ -10341,11 +10337,11 @@ resolve_overloaded_atomic_load (location_t loc, tree function, /* Convert object pointer to required type. */ p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); - VEC_replace (tree, params, 0, p0); + (*params)[0] = p0; /* Move memory model to the 2nd position, and end param list. */ - VEC_replace (tree, params, 1, p2); - VEC_truncate (tree, params, 2); + (*params)[1] = p2; + params->truncate (2); /* Convert return pointer and dereference it for later assignment. */ *new_return = build_indirect_ref (loc, p1, RO_UNARY_STAR); @@ -10366,7 +10362,7 @@ resolve_overloaded_atomic_load (location_t loc, tree function, static bool resolve_overloaded_atomic_store (location_t loc, tree function, - VEC(tree,gc) *params, tree *new_return) + vec<tree, va_gc> *params, tree *new_return) { tree p0, p1; tree I_type, I_type_ptr; @@ -10391,8 +10387,8 @@ resolve_overloaded_atomic_store (location_t loc, tree function, into fn ((In *) mem, (In) *value, model) */ - p0 = VEC_index (tree, params, 0); - p1 = VEC_index (tree, params, 1); + p0 = (*params)[0]; + p1 = (*params)[1]; /* Create pointer to appropriate size. */ I_type = builtin_type_for_size (BITS_PER_UNIT * n, 1); @@ -10400,12 +10396,12 @@ resolve_overloaded_atomic_store (location_t loc, tree function, /* Convert object pointer to required type. */ p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); - VEC_replace (tree, params, 0, p0); + (*params)[0] = p0; /* Convert new value to required type, and dereference it. */ p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR); p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1); - VEC_replace (tree, params, 1, p1); + (*params)[1] = p1; /* The memory model is in the right spot already. Return is void. */ *new_return = NULL_TREE; @@ -10426,7 +10422,8 @@ resolve_overloaded_atomic_store (location_t loc, tree function, continue. */ tree -resolve_overloaded_builtin (location_t loc, tree function, VEC(tree,gc) *params) +resolve_overloaded_builtin (location_t loc, tree function, + vec<tree, va_gc> *params) { enum built_in_function orig_code = DECL_FUNCTION_CODE (function); bool orig_format = true; @@ -10550,7 +10547,7 @@ resolve_overloaded_builtin (location_t loc, tree function, VEC(tree,gc) *params) orig_format)) return error_mark_node; - first_param = VEC_index (tree, params, 0); + first_param = (*params)[0]; result = build_function_call_vec (loc, new_function, params, NULL); if (result == error_mark_node) return result; @@ -11097,9 +11094,9 @@ record_types_used_by_current_var_decl (tree decl) { gcc_assert (decl && DECL_P (decl) && TREE_STATIC (decl)); - while (!VEC_empty (tree, types_used_by_cur_var_decl)) + while (types_used_by_cur_var_decl && !types_used_by_cur_var_decl->is_empty ()) { - tree type = VEC_pop (tree, types_used_by_cur_var_decl); + tree type = types_used_by_cur_var_decl->pop (); types_used_by_var_decl_insert (type, decl); } } @@ -11121,7 +11118,7 @@ record_locally_defined_typedef (tree decl) return; l = (struct c_language_function *) cfun->language; - VEC_safe_push (tree, gc, l->local_typedefs, decl); + vec_safe_push (l->local_typedefs, decl); } /* If T is a TYPE_DECL declared locally, mark it as used. */ @@ -11159,7 +11156,7 @@ maybe_warn_unused_local_typedefs (void) if (warn_unused_local_typedefs && errorcount == unused_local_typedefs_warn_count) { - FOR_EACH_VEC_ELT (tree, l->local_typedefs, i, decl) + FOR_EACH_VEC_SAFE_ELT (l->local_typedefs, i, decl) if (!TREE_USED (decl)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_local_typedefs, @@ -11167,86 +11164,82 @@ maybe_warn_unused_local_typedefs (void) unused_local_typedefs_warn_count = errorcount; } - if (l->local_typedefs) - { - VEC_free (tree, gc, l->local_typedefs); - l->local_typedefs = NULL; - } + vec_free (l->local_typedefs); } /* The C and C++ parsers both use vectors to hold function arguments. For efficiency, we keep a cache of unused vectors. This is the cache. */ -typedef VEC(tree,gc)* tree_gc_vec; -DEF_VEC_P(tree_gc_vec); -DEF_VEC_ALLOC_P(tree_gc_vec,gc); -static GTY((deletable)) VEC(tree_gc_vec,gc) *tree_vector_cache; +typedef vec<tree, va_gc> *tree_gc_vec; +static GTY((deletable)) vec<tree_gc_vec, va_gc> *tree_vector_cache; /* Return a new vector from the cache. If the cache is empty, allocate a new vector. These vectors are GC'ed, so it is OK if the pointer is not released.. */ -VEC(tree,gc) * +vec<tree, va_gc> * make_tree_vector (void) { - if (!VEC_empty (tree_gc_vec, tree_vector_cache)) - return VEC_pop (tree_gc_vec, tree_vector_cache); + if (tree_vector_cache && !tree_vector_cache->is_empty ()) + return tree_vector_cache->pop (); else { - /* Passing 0 to VEC_alloc returns NULL, and our callers require + /* Passing 0 to vec::alloc returns NULL, and our callers require that we always return a non-NULL value. The vector code uses 4 when growing a NULL vector, so we do too. */ - return VEC_alloc (tree, gc, 4); + vec<tree, va_gc> *v; + vec_alloc (v, 4); + return v; } } /* Release a vector of trees back to the cache. */ void -release_tree_vector (VEC(tree,gc) *vec) +release_tree_vector (vec<tree, va_gc> *vec) { if (vec != NULL) { - VEC_truncate (tree, vec, 0); - VEC_safe_push (tree_gc_vec, gc, tree_vector_cache, vec); + vec->truncate (0); + vec_safe_push (tree_vector_cache, vec); } } /* Get a new tree vector holding a single tree. */ -VEC(tree,gc) * +vec<tree, va_gc> * make_tree_vector_single (tree t) { - VEC(tree,gc) *ret = make_tree_vector (); - VEC_quick_push (tree, ret, t); + vec<tree, va_gc> *ret = make_tree_vector (); + ret->quick_push (t); return ret; } /* Get a new tree vector of the TREE_VALUEs of a TREE_LIST chain. */ -VEC(tree,gc) * +vec<tree, va_gc> * make_tree_vector_from_list (tree list) { - VEC(tree,gc) *ret = make_tree_vector (); + vec<tree, va_gc> *ret = make_tree_vector (); for (; list; list = TREE_CHAIN (list)) - VEC_safe_push (tree, gc, ret, TREE_VALUE (list)); + vec_safe_push (ret, TREE_VALUE (list)); return ret; } /* Get a new tree vector which is a copy of an existing one. */ -VEC(tree,gc) * -make_tree_vector_copy (const VEC(tree,gc) *orig) +vec<tree, va_gc> * +make_tree_vector_copy (const vec<tree, va_gc> *orig) { - VEC(tree,gc) *ret; + vec<tree, va_gc> *ret; unsigned int ix; tree t; ret = make_tree_vector (); - VEC_reserve (tree, gc, ret, VEC_length (tree, orig)); - FOR_EACH_VEC_ELT (tree, orig, ix, t) - VEC_quick_push (tree, ret, t); + vec_safe_reserve (ret, vec_safe_length (orig)); + FOR_EACH_VEC_SAFE_ELT (orig, ix, t) + ret->quick_push (t); return ret; } |