Use checking forms of DECL_FUNCTION_CODE (PR 91421)

Programming / Compilers / GCC - rsandifo [138bc75d-0d04-0410-961f-82ee72b054a4] - 13 August 2019 21:35 EDT

We were shoe-horning all built-in enumerations (including frontend and target-specific ones) into a field of type built_in_function. This was accessed as either an lvalue or an rvalue using DECL_FUNCTION_CODE.

The obvious danger with this (as was noted by several ??? comments) is that the ranges have nothing to do with each other, and targets can easily have more built-in functions than generic code. But my patch to make the field bigger was the straw that finally made the problem visible.

This patch therefore:

- replaces the field with a plain unsigned int

- turns DECL_FUNCTION_CODE into an rvalue-only accessor that checks that the function really is BUILT_IN_NORMAL

- adds corresponding DECL_MD_FUNCTION_CODE and DECL_FE_FUNCTION_CODE accessors for BUILT_IN_MD and BUILT_IN_FRONTEND respectively

- adds DECL_UNCHECKED_FUNCTION_CODE for places that need to access the underlying field (should be low-level code only)

- adds new helpers for setting the built-in class and function code

- makes DECL_BUILT_IN_CLASS an rvalue-only accessor too, since all assignments should go through the new helpers

2019-08-13 Richard Sandiford

gcc/ PR middle-end/91421
- tree-core.h (function_decl::function_code): Change type to unsigned int.
- tree.h (DECL_FUNCTION_CODE): Rename old definition to... (DECL_UNCHECKED_FUNCTION_CODE): ...this. (DECL_BUILT_IN_CLASS): Make an rvalue macro only. (DECL_FUNCTION_CODE): New function. Assert that the built-in class is BUILT_IN_NORMAL. (DECL_MD_FUNCTION_CODE, DECL_FE_FUNCTION_CODE): New functions. (set_decl_built_in_function, copy_decl_built_in_function): Likewise. (fndecl_built_in_p): Change the type of the "name" argument to unsigned int.
- builtins.c (expand_builtin): Move DECL_FUNCTION_CODE use after check for DECL_BUILT_IN_CLASS.
- cgraphclones.c (build_function_decl_skip_args): Use set_decl_built_in_function.
- ipa-param-manipulation.c (ipa_modify_formal_parameters): Likewise.
- ipa-split.c (split_function): Likewise.
- langhooks.c (add_builtin_function_common): Likewise.
- omp-simd-clone.c (simd_clone_create): Likewise.
- tree-streamer-in.c (unpack_ts_function_decl_value_fields): Likewise.
- config/darwin.c (darwin_init_cfstring_builtins): Likewise. (darwin_fold_builtin): Use DECL_MD_FUNCTION_CODE instead of DECL_FUNCTION_CODE.
- fold-const.c (operand_equal_p): Compare DECL_UNCHECKED_FUNCTION_CODE instead of DECL_FUNCTION_CODE.
- lto-streamer-out.c (hash_tree): Use DECL_UNCHECKED_FUNCTION_CODE instead of DECL_FUNCTION_CODE.
- tree-streamer-out.c (pack_ts_function_decl_value_fields): Likewise.
- print-tree.c (print_node): Use DECL_MD_FUNCTION_CODE when printing DECL_BUILT_IN_MD. Handle DECL_BUILT_IN_FRONTEND.
- config/aarch64/aarch64-builtins.c (aarch64_expand_builtin) (aarch64_fold_builtin, aarch64_gimple_fold_builtin): Use DECL_MD_FUNCTION_CODE instead of DECL_FUNCTION_CODE.
- config/aarch64/aarch64.c (aarch64_builtin_reciprocal): Likewise.
- config/alpha/alpha.c (alpha_expand_builtin, alpha_fold_builtin): (alpha_gimple_fold_builtin): Likewise.
- config/arc/arc.c (arc_expand_builtin): Likewise.
- config/arm/arm-builtins.c (arm_expand_builtin): Likewise.
- config/avr/avr-c.c (avr_resolve_overloaded_builtin): Likewise.
- config/avr/avr.c (avr_expand_builtin, avr_fold_builtin): Likewise.
- config/bfin/bfin.c (bfin_expand_builtin): Likewise.
- config/c6x/c6x.c (c6x_expand_builtin): Likewise.
- config/frv/frv.c (frv_expand_builtin): Likewise.
- config/gcn/gcn.c (gcn_expand_builtin_1): Likewise. (gcn_expand_builtin): Likewise.
- config/i386/i386-builtins.c (ix86_builtin_reciprocal): Likewise. (fold_builtin_cpu): Likewise.
- config/i386/i386-expand.c (ix86_expand_builtin): Likewise.
- config/i386/i386.c (ix86_fold_builtin): Likewise. (ix86_gimple_fold_builtin): Likewise.
- config/ia64/ia64.c (ia64_fold_builtin): Likewise. (ia64_expand_builtin): Likewise.
- config/iq2000/iq2000.c (iq2000_expand_builtin): Likewise.
- config/mips/mips.c (mips_expand_builtin): Likewise.
- config/msp430/msp430.c (msp430_expand_builtin): Likewise.
- config/nds32/nds32-intrinsic.c (nds32_expand_builtin_impl): Likewise.
- config/nios2/nios2.c (nios2_expand_builtin): Likewise.
- config/nvptx/nvptx.c (nvptx_expand_builtin): Likewise.
- config/pa/pa.c (pa_expand_builtin): Likewise.
- config/pru/pru.c (pru_expand_builtin): Likewise.
- config/riscv/riscv-builtins.c (riscv_expand_builtin): Likewise.
- config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin): Likewise.
- config/rs6000/rs6000-call.c (htm_expand_builtin): Likewise. (altivec_expand_dst_builtin, altivec_expand_builtin): Likewise. (rs6000_gimple_fold_builtin, rs6000_expand_builtin): Likewise.
- config/rs6000/rs6000.c (rs6000_builtin_md_vectorized_function) (rs6000_builtin_reciprocal): Likewise.
- config/rx/rx.c (rx_expand_builtin): Likewise.
- config/s390/s390-c.c (s390_resolve_overloaded_builtin): Likewise.
- config/s390/s390.c (s390_expand_builtin): Likewise.
- config/sh/sh.c (sh_expand_builtin): Likewise.
- config/sparc/sparc.c (sparc_expand_builtin): Likewise. (sparc_fold_builtin): Likewise.
- config/spu/spu-c.c (spu_resolve_overloaded_builtin): Likewise.
- config/spu/spu.c (spu_expand_builtin): Likewise.
- config/stormy16/stormy16.c (xstormy16_expand_builtin): Likewise.
- config/tilegx/tilegx.c (tilegx_expand_builtin): Likewise.
- config/tilepro/tilepro.c (tilepro_expand_builtin): Likewise.
- config/xtensa/xtensa.c (xtensa_fold_builtin): Likewise. (xtensa_expand_builtin): Likewise.

gcc/ada/ PR middle-end/91421
- gcc-interface/trans.c (gigi): Call set_decl_buillt_in_function. (Call_to_gnu): Use DECL_FE_FUNCTION_CODE instead of DECL_FUNCTION_CODE.

gcc/c/ PR middle-end/91421
- c-decl.c (merge_decls): Use copy_decl_built_in_function.

gcc/c-family/ PR middle-end/91421
- c-common.c (resolve_overloaded_builtin): Use copy_decl_built_in_function.

gcc/cp/ PR middle-end/91421
- decl.c (duplicate_decls): Use copy_decl_built_in_function.
- pt.c (declare_integer_pack): Use set_decl_built_in_function.

gcc/d/ PR middle-end/91421
- intrinsics.cc (maybe_set_intrinsic): Use set_decl_built_in_function.

gcc/jit/ PR middle-end/91421
- jit-playback.c (new_function): Use set_decl_built_in_function.

gcc/lto/ PR middle-end/91421
- lto-common.c (compare_tree_sccs_1): Use DECL_UNCHECKED_FUNCTION_CODE instead of DECL_FUNCTION_CODE.
- lto-symtab.c (lto_symtab_merge_p): Likewise.

d1170f8ddaa Use checking forms of DECL_FUNCTION_CODE (PR 91421)
gcc/ChangeLog | 85 +++++++++++++++++++++++++++++++++++
gcc/ada/ChangeLog | 6 +++
gcc/ada/gcc-interface/trans.c | 9 ++--
gcc/builtins.c | 2 +-
gcc/c-family/ChangeLog | 6 +++
gcc/c-family/c-common.c | 3 +-
gcc/c/ChangeLog | 5 +++
gcc/c/c-decl.c | 3 +-
gcc/cgraphclones.c | 5 +--
gcc/config/aarch64/aarch64-builtins.c | 6 +--
gcc/config/aarch64/aarch64.c | 2 +-
gcc/config/alpha/alpha.c | 6 +--
gcc/config/arc/arc.c | 2 +-
gcc/config/arm/arm-builtins.c | 2 +-
gcc/config/avr/avr-c.c | 2 +-
gcc/config/avr/avr.c | 4 +-
gcc/config/bfin/bfin.c | 2 +-
gcc/config/c6x/c6x.c | 2 +-
gcc/config/darwin.c | 5 +--
gcc/config/frv/frv.c | 2 +-
gcc/config/gcn/gcn.c | 4 +-
gcc/config/i386/i386-builtins.c | 6 +--
gcc/config/i386/i386-expand.c | 4 +-
gcc/config/i386/i386.c | 7 +--
gcc/config/ia64/ia64.c | 6 +--
gcc/config/iq2000/iq2000.c | 2 +-
gcc/config/mips/mips.c | 2 +-
gcc/config/msp430/msp430.c | 2 +-
gcc/config/nds32/nds32-intrinsic.c | 2 +-
gcc/config/nios2/nios2.c | 2 +-
gcc/config/nvptx/nvptx.c | 2 +-
gcc/config/pa/pa.c | 2 +-
gcc/config/pru/pru.c | 2 +-
gcc/config/riscv/riscv-builtins.c | 2 +-
gcc/config/rs6000/rs6000-c.c | 2 +-
gcc/config/rs6000/rs6000-call.c | 12 ++---
gcc/config/rs6000/rs6000.c | 4 +-
gcc/config/rx/rx.c | 2 +-
gcc/config/s390/s390-c.c | 2 +-
gcc/config/s390/s390.c | 2 +-
gcc/config/sh/sh.c | 2 +-
gcc/config/sparc/sparc.c | 6 ++-
gcc/config/spu/spu-c.c | 2 +-
gcc/config/spu/spu.c | 2 +-
gcc/config/stormy16/stormy16.c | 2 +-
gcc/config/tilegx/tilegx.c | 2 +-
gcc/config/tilepro/tilepro.c | 2 +-
gcc/config/xtensa/xtensa.c | 4 +-
gcc/cp/ChangeLog | 6 +++
gcc/cp/decl.c | 3 +-
gcc/cp/pt.c | 5 +--
gcc/d/ChangeLog | 5 +++
gcc/d/intrinsics.cc | 5 +--
gcc/fold-const.c | 3 +-
gcc/ipa-param-manipulation.c | 5 +--
gcc/ipa-split.c | 5 +--
gcc/jit/ChangeLog | 5 +++
gcc/jit/jit-playback.c | 5 +--
gcc/langhooks.c | 6 +--
gcc/lto-streamer-out.c | 2 +-
gcc/lto/ChangeLog | 7 +++
gcc/lto/lto-common.c | 2 +-
gcc/lto/lto-symtab.c | 3 +-
gcc/omp-simd-clone.c | 3 +-
gcc/print-tree.c | 6 ++-
gcc/tree-core.h | 5 +--
gcc/tree-streamer-in.c | 17 ++++---
gcc/tree-streamer-out.c | 2 +-
gcc/tree.h | 71 +++++++++++++++++++++++++----
69 files changed, 293 insertions(+), 128 deletions(-)

Upstream: gcc.gnu.org


  • Share