aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.h
AgeCommit message (Collapse)AuthorFilesLines
2022-03-11PR tree-optimization/98335: Improvements to DSE's compute_trims.Roger Sayle1-0/+2
This patch is the main middle-end piece of a fix for PR tree-opt/98335, which is a code-quality regression affecting mainline. The issue occurs in DSE's (dead store elimination's) compute_trims function that determines where a store to memory can be trimmed. In the testcase given in the PR, this function notices that the first byte of a DImode store is dead, and replaces the 8-byte store at (aligned) offset zero, with a 7-byte store at (unaligned) offset one. Most architectures can store a power-of-two bytes (up to a maximum) in single instruction, so writing 7 bytes requires more instructions than writing 8 bytes. This patch follows Jakub Jelinek's suggestion in comment 5, that compute_trims needs improved heuristics. On x86_64-pc-linux-gnu with -O2 the new test case in the PR goes from: movl $0, -24(%rsp) movabsq $72057594037927935, %rdx movl $0, -21(%rsp) andq -24(%rsp), %rdx movq %rdx, %rax salq $8, %rax movb c(%rip), %al ret to xorl %eax, %eax movb c(%rip), %al ret 2022-03-11 Roger Sayle <roger@nextmovesoftware.com> Richard Biener <rguenther@suse.de> gcc/ChangeLog PR tree-optimization/98335 * builtins.cc (get_object_alignment_2): Export. * builtins.h (get_object_alignment_2): Likewise. * tree-ssa-alias.cc (ao_ref_alignment): New. * tree-ssa-alias.h (ao_ref_alignment): Declare. * tree-ssa-dse.cc (compute_trims): Improve logic deciding whether to align head/tail, writing more bytes but using fewer store insns. gcc/testsuite/ChangeLog PR tree-optimization/98335 * g++.dg/pr98335.C: New test case. * gcc.dg/pr86010.c: New test case. * gcc.dg/pr86010-2.c: New test case.
2022-01-03i386, fab: Optimize __atomic_{add,sub,and,or,xor}_fetch (x, y, z) ↵Jakub Jelinek1-0/+1
{==,!=,<,<=,>,>=} 0 [PR98737] On Wed, Jan 27, 2021 at 12:27:13PM +0100, Ulrich Drepper via Gcc-patches wrote: > On 1/27/21 11:37 AM, Jakub Jelinek wrote: > > Would equality comparison against 0 handle the most common cases. > > > > The user can write it as > > __atomic_sub_fetch (x, y, z) == 0 > > or > > __atomic_fetch_sub (x, y, z) - y == 0 > > thouch, so the expansion code would need to be able to cope with both. > > Please also keep !=0, <0, <=0, >0, and >=0 in mind. They all can be > useful and can be handled with the flags. <= 0 and > 0 don't really work well with lock {add,sub,inc,dec}, x86 doesn't have comparisons that would look solely at both SF and ZF and not at other flags (and emitting two separate conditional jumps or two setcc insns and oring them together looks awful). But the rest can work. Here is a patch that adds internal functions and optabs for these, recognizes them at the same spot as e.g. .ATOMIC_BIT_TEST_AND* internal functions (fold all builtins pass) and expands them appropriately (or for the <= 0 and > 0 cases of +/- FAILs and let's middle-end fall back). So far I have handled just the op_fetch builtins, IMHO instead of handling also __atomic_fetch_sub (x, y, z) - y == 0 etc. we should canonicalize __atomic_fetch_sub (x, y, z) - y to __atomic_sub_fetch (x, y, z) (and vice versa). 2022-01-03 Jakub Jelinek <jakub@redhat.com> PR target/98737 * internal-fn.def (ATOMIC_ADD_FETCH_CMP_0, ATOMIC_SUB_FETCH_CMP_0, ATOMIC_AND_FETCH_CMP_0, ATOMIC_OR_FETCH_CMP_0, ATOMIC_XOR_FETCH_CMP_0): New internal fns. * internal-fn.h (ATOMIC_OP_FETCH_CMP_0_EQ, ATOMIC_OP_FETCH_CMP_0_NE, ATOMIC_OP_FETCH_CMP_0_LT, ATOMIC_OP_FETCH_CMP_0_LE, ATOMIC_OP_FETCH_CMP_0_GT, ATOMIC_OP_FETCH_CMP_0_GE): New enumerators. * internal-fn.c (expand_ATOMIC_ADD_FETCH_CMP_0, expand_ATOMIC_SUB_FETCH_CMP_0, expand_ATOMIC_AND_FETCH_CMP_0, expand_ATOMIC_OR_FETCH_CMP_0, expand_ATOMIC_XOR_FETCH_CMP_0): New functions. * optabs.def (atomic_add_fetch_cmp_0_optab, atomic_sub_fetch_cmp_0_optab, atomic_and_fetch_cmp_0_optab, atomic_or_fetch_cmp_0_optab, atomic_xor_fetch_cmp_0_optab): New direct optabs. * builtins.h (expand_ifn_atomic_op_fetch_cmp_0): Declare. * builtins.c (expand_ifn_atomic_op_fetch_cmp_0): New function. * tree-ssa-ccp.c: Include internal-fn.h. (optimize_atomic_bit_test_and): Add . before internal fn call in function comment. Change return type from void to bool and return true only if successfully replaced. (optimize_atomic_op_fetch_cmp_0): New function. (pass_fold_builtins::execute): Use optimize_atomic_op_fetch_cmp_0 for BUILT_IN_ATOMIC_{ADD,SUB,AND,OR,XOR}_FETCH_{1,2,4,8,16} and BUILT_IN_SYNC_{ADD,SUB,AND,OR,XOR}_AND_FETCH_{1,2,4,8,16}, for *XOR* ones only if optimize_atomic_bit_test_and failed. * config/i386/sync.md (atomic_<plusminus_mnemonic>_fetch_cmp_0<mode>, atomic_<logic>_fetch_cmp_0<mode>): New define_expand patterns. (atomic_add_fetch_cmp_0<mode>_1, atomic_sub_fetch_cmp_0<mode>_1, atomic_<logic>_fetch_cmp_0<mode>_1): New define_insn patterns. * doc/md.texi (atomic_add_fetch_cmp_0<mode>, atomic_sub_fetch_cmp_0<mode>, atomic_and_fetch_cmp_0<mode>, atomic_or_fetch_cmp_0<mode>, atomic_xor_fetch_cmp_0<mode>): Document new named patterns. * gcc.target/i386/pr98737-1.c: New test. * gcc.target/i386/pr98737-2.c: New test. * gcc.target/i386/pr98737-3.c: New test. * gcc.target/i386/pr98737-4.c: New test. * gcc.target/i386/pr98737-5.c: New test. * gcc.target/i386/pr98737-6.c: New test. * gcc.target/i386/pr98737-7.c: New test.
2022-01-03Update copyright years.Jakub Jelinek1-1/+1
2021-11-30vect: Make reduction code handle callsRichard Sandiford1-0/+1
This patch extends the reduction code to handle calls. So far it's a structural change only; a later patch adds support for specific function reductions. Most of the patch consists of using code_helper and gimple_match_op to describe the reduction operations. The other main change is that vectorizable_call now needs to handle fully-predicated reductions. There are some new functions that are provided for ABI completeness and aren't currently used: first_commutative_argument commutative_ternary_op_p 1- and 3-argument forms of gimple_build gcc/ * builtins.h (associated_internal_fn): Declare overload that takes a (combined_cfn, return type) pair. * builtins.c (associated_internal_fn): Split new overload out of original fndecl version. Also provide an overload that takes a (combined_cfn, return type) pair. * internal-fn.h (commutative_binary_fn_p): Declare. (commutative_ternary_fn_p): Likewise. (associative_binary_fn_p): Likewise. * internal-fn.c (commutative_binary_fn_p, commutative_ternary_fn_p): New functions, split out from... (first_commutative_argument): ...here. (associative_binary_fn_p): New function. * gimple-match.h (code_helper): Add a constructor that takes internal functions. (commutative_binary_op_p): Declare. (commutative_ternary_op_p): Likewise. (first_commutative_argument): Likewise. (associative_binary_op_p): Likewise. (canonicalize_code): Likewise. (directly_supported_p): Likewise. (get_conditional_internal_fn): Likewise. (gimple_build): New overloads that takes a code_helper. * gimple-fold.c (gimple_build): Likewise. * gimple-match-head.c (commutative_binary_op_p): New function. (commutative_ternary_op_p): Likewise. (first_commutative_argument): Likewise. (associative_binary_op_p): Likewise. (canonicalize_code): Likewise. (directly_supported_p): Likewise. (get_conditional_internal_fn): Likewise. * tree-vectorizer.h: Include gimple-match.h. (neutral_op_for_reduction): Take a code_helper instead of a tree_code. (needs_fold_left_reduction_p): Likewise. (reduction_fn_for_scalar_code): Likewise. (vect_can_vectorize_without_simd_p): Declare a nNew overload that takes a code_helper. * tree-vect-loop.c: Include case-cfn-macros.h. (fold_left_reduction_fn): Take a code_helper instead of a tree_code. (reduction_fn_for_scalar_code): Likewise. (neutral_op_for_reduction): Likewise. (needs_fold_left_reduction_p): Likewise. (use_mask_by_cond_expr_p): Likewise. (build_vect_cond_expr): Likewise. (vect_create_partial_epilog): Likewise. Use gimple_build rather than gimple_build_assign. (check_reduction_path): Handle calls and operate on code_helpers rather than tree_codes. (vect_is_simple_reduction): Likewise. (vect_model_reduction_cost): Likewise. (vect_find_reusable_accumulator): Likewise. (vect_create_epilog_for_reduction): Likewise. (vect_transform_cycle_phi): Likewise. (vectorizable_reduction): Likewise. Make more use of lane_reduc_code_p. (vect_transform_reduction): Use gimple_extract_op but expect a tree_code for now. (vect_can_vectorize_without_simd_p): New overload that takes a code_helper. * tree-vect-stmts.c (vectorizable_call): Handle reductions in fully-masked loops. * tree-vect-patterns.c (vect_mark_pattern_stmts): Use gimple_extract_op when updating STMT_VINFO_REDUC_IDX.
2021-10-11ldist: Recognize strlen and rawmemchr like loopsStefan Schulze Frielinghaus1-0/+1
This patch adds support for recognizing loops which mimic the behaviour of functions strlen and rawmemchr, and replaces those with internal function calls in case a target provides them. In contrast to the standard strlen and rawmemchr functions, this patch also supports different instances where the memory pointed to is interpreted as 8, 16, and 32-bit sized, respectively. gcc/ChangeLog: * builtins.c (get_memory_rtx): Change to external linkage. * builtins.h (get_memory_rtx): Add function prototype. * doc/md.texi (rawmemchr<mode>): Document. * internal-fn.c (expand_RAWMEMCHR): Define. * internal-fn.def (RAWMEMCHR): Add. * optabs.def (rawmemchr_optab): Add. * tree-loop-distribution.c (find_single_drs): Change return code behaviour by also returning true if no single store was found but a single load. (loop_distribution::classify_partition): Respect the new return code behaviour of function find_single_drs. (loop_distribution::execute): Call new function transform_reduction_loop in order to replace rawmemchr or strlen like loops by calls into builtins. (generate_reduction_builtin_1): New function. (generate_rawmemchr_builtin): New function. (generate_strlen_builtin_1): New function. (generate_strlen_builtin): New function. (generate_strlen_builtin_using_rawmemchr): New function. (reduction_var_overflows_first): New function. (determine_reduction_stmt_1): New function. (determine_reduction_stmt): New function. (loop_distribution::transform_reduction_loop): New function. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ldist-rawmemchr-1.c: New test. * gcc.dg/tree-ssa/ldist-rawmemchr-2.c: New test. * gcc.dg/tree-ssa/ldist-strlen-1.c: New test. * gcc.dg/tree-ssa/ldist-strlen-2.c: New test. * gcc.dg/tree-ssa/ldist-strlen-3.c: New test.
2021-09-09Add -ftrivial-auto-var-init option and uninitialized variable attribute.qing zhao1-0/+1
Initialize automatic variables with either a pattern or with zeroes to increase the security and predictability of a program by preventing uninitialized memory disclosure and use. GCC still considers an automatic variable that doesn't have an explicit initializer as uninitialized, -Wuninitialized will still report warning messages on such automatic variables. With this option, GCC will also initialize any padding of automatic variables that have structure or union types to zeroes. You can control this behavior for a specific variable by using the variable attribute "uninitialized" to control runtime overhead. gcc/ChangeLog: 2021-09-09 qing zhao <qing.zhao@oracle.com> * builtins.c (expand_builtin_memset): Make external visible. * builtins.h (expand_builtin_memset): Declare extern. * common.opt (ftrivial-auto-var-init=): New option. * doc/extend.texi: Document the uninitialized attribute. * doc/invoke.texi: Document -ftrivial-auto-var-init. * flag-types.h (enum auto_init_type): New enumerated type auto_init_type. * gimple-fold.c (clear_padding_type): Add one new parameter. (clear_padding_union): Likewise. (clear_padding_emit_loop): Likewise. (clear_type_padding_in_mask): Likewise. (gimple_fold_builtin_clear_padding): Handle this new parameter. * gimplify.c (gimple_add_init_for_auto_var): New function. (gimple_add_padding_init_for_auto_var): New function. (is_var_need_auto_init): New function. (gimplify_decl_expr): Add initialization to automatic variables per users' requests. (gimplify_call_expr): Add one new parameter for call to __builtin_clear_padding. (gimplify_init_constructor): Add padding initialization in the end. * internal-fn.c (INIT_PATTERN_VALUE): New macro. (expand_DEFERRED_INIT): New function. * internal-fn.def (DEFERRED_INIT): New internal function. * tree-cfg.c (verify_gimple_call): Verify calls to .DEFERRED_INIT. * tree-sra.c (generate_subtree_deferred_init): New function. (scan_function): Avoid setting cannot_scalarize_away_bitmap for calls to .DEFERRED_INIT. (sra_modify_deferred_init): New function. (sra_modify_function_body): Handle calls to DEFERRED_INIT specially. * tree-ssa-structalias.c (find_func_aliases_for_call): Likewise. * tree-ssa-uninit.c (warn_uninit): Handle calls to DEFERRED_INIT specially. (check_defs): Likewise. (warn_uninitialized_vars): Likewise. * tree-ssa.c (ssa_undefined_value_p): Likewise. * tree.c (build_common_builtin_nodes): Build tree node for BUILT_IN_CLEAR_PADDING when needed. gcc/c-family/ChangeLog: 2021-09-09 qing zhao <qing.zhao@oracle.com> * c-attribs.c (handle_uninitialized_attribute): New function. (c_common_attribute_table): Add "uninitialized" attribute. gcc/testsuite/ChangeLog: 2021-09-09 qing zhao <qing.zhao@oracle.com> * c-c++-common/auto-init-1.c: New test. * c-c++-common/auto-init-10.c: New test. * c-c++-common/auto-init-11.c: New test. * c-c++-common/auto-init-12.c: New test. * c-c++-common/auto-init-13.c: New test. * c-c++-common/auto-init-14.c: New test. * c-c++-common/auto-init-15.c: New test. * c-c++-common/auto-init-16.c: New test. * c-c++-common/auto-init-2.c: New test. * c-c++-common/auto-init-3.c: New test. * c-c++-common/auto-init-4.c: New test. * c-c++-common/auto-init-5.c: New test. * c-c++-common/auto-init-6.c: New test. * c-c++-common/auto-init-7.c: New test. * c-c++-common/auto-init-8.c: New test. * c-c++-common/auto-init-9.c: New test. * c-c++-common/auto-init-esra.c: New test. * c-c++-common/auto-init-padding-1.c: New test. * c-c++-common/auto-init-padding-2.c: New test. * c-c++-common/auto-init-padding-3.c: New test. * g++.dg/auto-init-uninit-pred-1_a.C: New test. * g++.dg/auto-init-uninit-pred-2_a.C: New test. * g++.dg/auto-init-uninit-pred-3_a.C: New test. * g++.dg/auto-init-uninit-pred-4.C: New test. * gcc.dg/auto-init-sra-1.c: New test. * gcc.dg/auto-init-sra-2.c: New test. * gcc.dg/auto-init-uninit-1.c: New test. * gcc.dg/auto-init-uninit-12.c: New test. * gcc.dg/auto-init-uninit-13.c: New test. * gcc.dg/auto-init-uninit-14.c: New test. * gcc.dg/auto-init-uninit-15.c: New test. * gcc.dg/auto-init-uninit-16.c: New test. * gcc.dg/auto-init-uninit-17.c: New test. * gcc.dg/auto-init-uninit-18.c: New test. * gcc.dg/auto-init-uninit-19.c: New test. * gcc.dg/auto-init-uninit-2.c: New test. * gcc.dg/auto-init-uninit-20.c: New test. * gcc.dg/auto-init-uninit-21.c: New test. * gcc.dg/auto-init-uninit-22.c: New test. * gcc.dg/auto-init-uninit-23.c: New test. * gcc.dg/auto-init-uninit-24.c: New test. * gcc.dg/auto-init-uninit-25.c: New test. * gcc.dg/auto-init-uninit-26.c: New test. * gcc.dg/auto-init-uninit-3.c: New test. * gcc.dg/auto-init-uninit-34.c: New test. * gcc.dg/auto-init-uninit-36.c: New test. * gcc.dg/auto-init-uninit-37.c: New test. * gcc.dg/auto-init-uninit-4.c: New test. * gcc.dg/auto-init-uninit-5.c: New test. * gcc.dg/auto-init-uninit-6.c: New test. * gcc.dg/auto-init-uninit-8.c: New test. * gcc.dg/auto-init-uninit-9.c: New test. * gcc.dg/auto-init-uninit-A.c: New test. * gcc.dg/auto-init-uninit-B.c: New test. * gcc.dg/auto-init-uninit-C.c: New test. * gcc.dg/auto-init-uninit-H.c: New test. * gcc.dg/auto-init-uninit-I.c: New test. * gcc.target/aarch64/auto-init-1.c: New test. * gcc.target/aarch64/auto-init-2.c: New test. * gcc.target/aarch64/auto-init-3.c: New test. * gcc.target/aarch64/auto-init-4.c: New test. * gcc.target/aarch64/auto-init-5.c: New test. * gcc.target/aarch64/auto-init-6.c: New test. * gcc.target/aarch64/auto-init-7.c: New test. * gcc.target/aarch64/auto-init-8.c: New test. * gcc.target/aarch64/auto-init-padding-1.c: New test. * gcc.target/aarch64/auto-init-padding-10.c: New test. * gcc.target/aarch64/auto-init-padding-11.c: New test. * gcc.target/aarch64/auto-init-padding-12.c: New test. * gcc.target/aarch64/auto-init-padding-2.c: New test. * gcc.target/aarch64/auto-init-padding-3.c: New test. * gcc.target/aarch64/auto-init-padding-4.c: New test. * gcc.target/aarch64/auto-init-padding-5.c: New test. * gcc.target/aarch64/auto-init-padding-6.c: New test. * gcc.target/aarch64/auto-init-padding-7.c: New test. * gcc.target/aarch64/auto-init-padding-8.c: New test. * gcc.target/aarch64/auto-init-padding-9.c: New test. * gcc.target/i386/auto-init-1.c: New test. * gcc.target/i386/auto-init-2.c: New test. * gcc.target/i386/auto-init-21.c: New test. * gcc.target/i386/auto-init-22.c: New test. * gcc.target/i386/auto-init-23.c: New test. * gcc.target/i386/auto-init-24.c: New test. * gcc.target/i386/auto-init-3.c: New test. * gcc.target/i386/auto-init-4.c: New test. * gcc.target/i386/auto-init-5.c: New test. * gcc.target/i386/auto-init-6.c: New test. * gcc.target/i386/auto-init-7.c: New test. * gcc.target/i386/auto-init-8.c: New test. * gcc.target/i386/auto-init-padding-1.c: New test. * gcc.target/i386/auto-init-padding-10.c: New test. * gcc.target/i386/auto-init-padding-11.c: New test. * gcc.target/i386/auto-init-padding-12.c: New test. * gcc.target/i386/auto-init-padding-2.c: New test. * gcc.target/i386/auto-init-padding-3.c: New test. * gcc.target/i386/auto-init-padding-4.c: New test. * gcc.target/i386/auto-init-padding-5.c: New test. * gcc.target/i386/auto-init-padding-6.c: New test. * gcc.target/i386/auto-init-padding-7.c: New test. * gcc.target/i386/auto-init-padding-8.c: New test. * gcc.target/i386/auto-init-padding-9.c: New test.
2021-08-06Move more code to new gimple-ssa-warn-access pass.Martin Sebor1-4/+0
gcc/ChangeLog: * builtins.c (expand_builtin_memchr): Move to gimple-ssa-warn-access.cc. (expand_builtin_strcat): Same. (expand_builtin_stpncpy): Same. (expand_builtin_strncat): Same. (check_read_access): Same. (check_memop_access): Same. (expand_builtin_strlen): Move checks to gimple-ssa-warn-access.cc. (expand_builtin_strnlen): Same. (expand_builtin_memcpy): Same. (expand_builtin_memmove): Same. (expand_builtin_mempcpy): Same. (expand_builtin_strcpy): Same. (expand_builtin_strcpy_args): Same. (expand_builtin_stpcpy_1): Same. (expand_builtin_strncpy): Same. (expand_builtin_memset): Same. (expand_builtin_bzero): Same. (expand_builtin_strcmp): Same. (expand_builtin_strncmp): Same. (expand_builtin): Remove handlers. (fold_builtin_strlen): Add a comment. * builtins.h (check_access): Move to gimple-ssa-warn-access.cc. * calls.c (maybe_warn_nonstring_arg): Same. * diagnostic-spec.c (nowarn_spec_t::nowarn_spec_t): Add warning option. * gimple-fold.c (gimple_fold_builtin_strcpy): Pass argument to callee. (gimple_fold_builtin_stpcpy): Same. * gimple-ssa-warn-access.cc (has_location): New function. (get_location): Same. (get_callee_fndecl): Same. (call_nargs): Same. (call_arg): Same. (warn_string_no_nul): Define. (unterminated_array): Same. (check_nul_terminated_array): Same. (maybe_warn_nonstring_arg): Same. (maybe_warn_for_bound): Same. (warn_for_access): Same. (check_access): Same. (check_memop_access): Same. (check_read_access): Same. (warn_dealloc_offset): Use helper functions. (maybe_emit_free_warning): Same. (class pass_waccess): Add members. (check_strcat): New function. (check_strncat): New function. (check_stxcpy): New function. (check_stxncpy): New function. (check_strncmp): New function. (pass_waccess::check_builtin): New function. (pass_waccess::check): Call it. * gimple-ssa-warn-access.h (warn_string_no_nul): Move here from builtins.h. (maybe_warn_for_bound): Same. (check_access): Same. (check_memop_access): Same. (check_read_access): Same. * pointer-query.h (struct access_data): Define a ctor overload. gcc/testsuite/ChangeLog: * c-c++-common/Wsizeof-pointer-memaccess1.c: Also disable -Wstringop-overread. * c-c++-common/attr-nonstring-3.c: Adjust pattern of expected message. * gcc.dg/Warray-bounds-39.c: Add an xfail due to a known bug. * gcc.dg/Wstring-compare-3.c: Also disable -Wstringop-overread. * gcc.dg/attr-nonstring-2.c: Adjust pattern of expected message. * gcc.dg/attr-nonstring-4.c: Same. * gcc.dg/Wstringop-overread-6.c: New test. * gcc.dg/sso-14.c: Fix typos to avoid buffer overflow.
2021-07-30Add QI vector mode support to by-pieces for memsetH.J. Lu1-2/+2
1. Replace scalar_int_mode with fixed_size_mode in the by-pieces infrastructure to allow non-integer mode. 2. Rename widest_int_mode_for_size to widest_fixed_size_mode_for_size to return QI vector mode for memset. 3. Add op_by_pieces_d::smallest_fixed_size_mode_for_size to return the smallest integer or QI vector mode. 4. Remove clear_by_pieces_1 and use builtin_memset_read_str in clear_by_pieces to support vector mode broadcast. 5. Add lowpart_subreg_regno, a wrapper around simplify_subreg_regno that uses subreg_lowpart_offset (mode, prev_mode) as the offset. 6. Add TARGET_GEN_MEMSET_SCRATCH_RTX to allow the backend to use a hard scratch register to avoid stack realignment when expanding memset. gcc/ PR middle-end/90773 * builtins.c (builtin_memcpy_read_str): Change the mode argument from scalar_int_mode to fixed_size_mode. (builtin_strncpy_read_str): Likewise. (gen_memset_value_from_prev): New function. (builtin_memset_read_str): Change the mode argument from scalar_int_mode to fixed_size_mode. Use gen_memset_value_from_prev and support CONST_VECTOR. (builtin_memset_gen_str): Likewise. (try_store_by_multiple_pieces): Use by_pieces_constfn to declare constfun. * builtins.h (builtin_strncpy_read_str): Replace scalar_int_mode with fixed_size_mode. (builtin_memset_read_str): Likewise. * expr.c (widest_int_mode_for_size): Renamed to ... (widest_fixed_size_mode_for_size): Add a bool argument to indicate if QI vector mode can be used. (by_pieces_ninsns): Call widest_fixed_size_mode_for_size instead of widest_int_mode_for_size. (pieces_addr::adjust): Change the mode argument from scalar_int_mode to fixed_size_mode. (op_by_pieces_d): Make m_len read-only. Add a bool member, m_qi_vector_mode, to indicate that QI vector mode can be used. (op_by_pieces_d::op_by_pieces_d): Add a bool argument to initialize m_qi_vector_mode. Call widest_fixed_size_mode_for_size instead of widest_int_mode_for_size. (op_by_pieces_d::get_usable_mode): Change the mode argument from scalar_int_mode to fixed_size_mode. Call widest_fixed_size_mode_for_size instead of widest_int_mode_for_size. (op_by_pieces_d::smallest_fixed_size_mode_for_size): New member function to return the smallest integer or QI vector mode. (op_by_pieces_d::run): Call widest_fixed_size_mode_for_size instead of widest_int_mode_for_size. Call smallest_fixed_size_mode_for_size instead of smallest_int_mode_for_size. (store_by_pieces_d::store_by_pieces_d): Add a bool argument to indicate that QI vector mode can be used and pass it to op_by_pieces_d::op_by_pieces_d. (can_store_by_pieces): Call widest_fixed_size_mode_for_size instead of widest_int_mode_for_size. Pass memsetp to widest_fixed_size_mode_for_size to support QI vector mode. Allow all CONST_VECTORs for memset if vec_duplicate is supported. (store_by_pieces): Pass memsetp to store_by_pieces_d::store_by_pieces_d. (clear_by_pieces_1): Removed. (clear_by_pieces): Replace clear_by_pieces_1 with builtin_memset_read_str and pass true to store_by_pieces_d to support vector mode broadcast. (string_cst_read_str): Change the mode argument from scalar_int_mode to fixed_size_mode. * expr.h (by_pieces_constfn): Change scalar_int_mode to fixed_size_mode. (by_pieces_prev): Likewise. * rtl.h (lowpart_subreg_regno): New. * rtlanal.c (lowpart_subreg_regno): New. A wrapper around simplify_subreg_regno. * target.def (gen_memset_scratch_rtx): New hook. * doc/tm.texi.in: Add TARGET_GEN_MEMSET_SCRATCH_RTX. * doc/tm.texi: Regenerated. gcc/testsuite/ * gcc.target/i386/pr100865-3.c: Expect vmovdqu8 instead of vmovdqu. * gcc.target/i386/pr100865-4b.c: Likewise.
2021-07-28Add new gimple-ssa-warn-access pass.Martin Sebor1-214/+1
gcc/ChangeLog: * Makefile.in (OBJS): Add gimple-ssa-warn-access.o and pointer-query.o. * attribs.h (fndecl_dealloc_argno): Move fndecl_dealloc_argno to tree.h. * builtins.c (compute_objsize_r): Move to pointer-query.cc. (access_ref::access_ref): Same. (access_ref::phi): Same. (access_ref::get_ref): Same. (access_ref::size_remaining): Same. (access_ref::offset_in_range): Same. (access_ref::add_offset): Same. (access_ref::inform_access): Same. (ssa_name_limit_t::visit_phi): Same. (ssa_name_limit_t::leave_phi): Same. (ssa_name_limit_t::next): Same. (ssa_name_limit_t::next_phi): Same. (ssa_name_limit_t::~ssa_name_limit_t): Same. (pointer_query::pointer_query): Same. (pointer_query::get_ref): Same. (pointer_query::put_ref): Same. (pointer_query::flush_cache): Same. (warn_string_no_nul): Move to gimple-ssa-warn-access.cc. (check_nul_terminated_array): Same. (unterminated_array): Same. (maybe_warn_for_bound): Same. (check_read_access): Same. (warn_for_access): Same. (get_size_range): Same. (check_access): Same. (gimple_call_alloc_size): Move to tree.c. (gimple_parm_array_size): Move to pointer-query.cc. (get_offset_range): Same. (gimple_call_return_array): Same. (handle_min_max_size): Same. (handle_array_ref): Same. (handle_mem_ref): Same. (compute_objsize): Same. (gimple_call_alloc_p): Move to gimple-ssa-warn-access.cc. (call_dealloc_argno): Same. (fndecl_dealloc_argno): Same. (new_delete_mismatch_p): Same. (matching_alloc_calls_p): Same. (warn_dealloc_offset): Same. (maybe_emit_free_warning): Same. * builtins.h (check_nul_terminated_array): Move to gimple-ssa-warn-access.h. (check_nul_terminated_array): Same. (warn_string_no_nul): Same. (unterminated_array): Same. (class ssa_name_limit_t): Same. (class pointer_query): Same. (struct access_ref): Same. (class range_query): Same. (struct access_data): Same. (gimple_call_alloc_size): Same. (gimple_parm_array_size): Same. (compute_objsize): Same. (class access_data): Same. (maybe_emit_free_warning): Same. * calls.c (initialize_argument_information): Remove call to maybe_emit_free_warning. * gimple-array-bounds.cc: Include new header.. * gimple-fold.c: Same. * gimple-ssa-sprintf.c: Same. * gimple-ssa-warn-restrict.c: Same. * passes.def: Add pass_warn_access. * tree-pass.h (make_pass_warn_access): Declare. * tree-ssa-strlen.c: Include new headers. * tree.c (fndecl_dealloc_argno): Move here from builtins.c. * tree.h (fndecl_dealloc_argno): Move here from attribs.h. * gimple-ssa-warn-access.cc: New file. * gimple-ssa-warn-access.h: New file. * pointer-query.cc: New file. * pointer-query.h: New file. gcc/cp/ChangeLog: * init.c: Include new header.
2021-07-07Correct handling of variable offset minus constant in -Warray-bounds [PR100137]Martin Sebor1-0/+5
Resolves: PR tree-optimization/100137 - -Warray-bounds false positive on varying offset plus negative PR tree-optimization/99121 - ICE in -Warray-bounds on a multidimensional PR tree-optimization/97027 - missing warning on buffer overflow storing a larger scalar into a smaller array gcc/ChangeLog: PR tree-optimization/100137 PR tree-optimization/99121 PR tree-optimization/97027 * builtins.c (access_ref::access_ref): Also set offmax. (access_ref::offset_in_range): Define new function. (access_ref::add_offset): Set offmax. (access_ref::inform_access): Handle access_none. (handle_mem_ref): Clear ostype. (compute_objsize_r): Handle ASSERT_EXPR. * builtins.h (struct access_ref): Add offmax member. * gimple-array-bounds.cc (array_bounds_checker::check_mem_ref): Use compute_objsize() and simplify. gcc/testsuite/ChangeLog: PR tree-optimization/100137 PR tree-optimization/99121 PR tree-optimization/97027 * c-c++-common/Warray-bounds-3.c: Remove xfail * c-c++-common/Warray-bounds-4.c: Add an expected warning. * c-c++-common/Warray-bounds-9.c: New test. * c-c++-common/Warray-bounds-10.c: New test. * g++.dg/asan/asan_test.C: Suppress expected warnings. * g++.dg/pr95768.C: Same. * g++.dg/warn/Warray-bounds-10.C: Adjust text of expected messages. * g++.dg/warn/Warray-bounds-11.C: Same. * g++.dg/warn/Warray-bounds-12.C: Same. * g++.dg/warn/Warray-bounds-13.C: Same. * g++.dg/warn/Warray-bounds-17.C: Same. * g++.dg/warn/Warray-bounds-20.C: Same. * gcc.dg/Warray-bounds-29.c: Same. * gcc.dg/Warray-bounds-30.c: Add xfail. * gcc.dg/Warray-bounds-31.c: Adjust text of expected messages. * gcc.dg/Warray-bounds-32.c: Same. * gcc.dg/Warray-bounds-52.c: Same. * gcc.dg/Warray-bounds-53.c: Same. * gcc.dg/Warray-bounds-58.c: Remove xfail. * gcc.dg/Warray-bounds-63.c: Adjust text of expected messages. * gcc.dg/Warray-bounds-66.c: Same. * gcc.dg/Warray-bounds-69.c: Same. * gcc.dg/Wstringop-overflow-34.c: Same. * gcc.dg/Wstringop-overflow-47.c: Same. * gcc.dg/Wstringop-overflow-61.c: Same. * gcc.dg/Warray-bounds-77.c: New test. * gcc.dg/Warray-bounds-78.c: New test. * gcc.dg/Warray-bounds-79.c: New test.
2021-04-29Generate offset adjusted operation for op_by_pieces operationsH.J. Lu1-2/+4
Add an overlap_op_by_pieces_p target hook for op_by_pieces operations between two areas of memory to generate one offset adjusted operation in the smallest integer mode for the remaining bytes on the last piece operation of a memory region to avoid doing more than one smaller operations. Pass the RTL information from the previous iteration to m_constfn in op_by_pieces operation so that builtin_memset_[read|gen]_str can generate the new RTL from the previous RTL. Tested on Linux/x86-64. gcc/ PR middle-end/90773 * builtins.c (builtin_memcpy_read_str): Add a dummy argument. (builtin_strncpy_read_str): Likewise. (builtin_memset_read_str): Add an argument for the previous RTL information and generate the new RTL from the previous RTL info. (builtin_memset_gen_str): Likewise. * builtins.h (builtin_strncpy_read_str): Update the prototype. (builtin_memset_read_str): Likewise. * expr.c (by_pieces_ninsns): If targetm.overlap_op_by_pieces_p() returns true, round up size and alignment to the widest integer mode for maximum size. (pieces_addr::adjust): Add a pointer to by_pieces_prev argument and pass it to m_constfn. (op_by_pieces_d): Add m_push and m_overlap_op_by_pieces. (op_by_pieces_d::op_by_pieces_d): Add a bool argument to initialize m_push. Initialize m_overlap_op_by_pieces with targetm.overlap_op_by_pieces_p (). (op_by_pieces_d::run): Pass the previous RTL information to pieces_addr::adjust and generate overlapping operations if m_overlap_op_by_pieces is true. (PUSHG_P): New. (move_by_pieces_d::move_by_pieces_d): Updated for op_by_pieces_d change. (store_by_pieces_d::store_by_pieces_d): Updated for op_by_pieces_d change. (can_store_by_pieces): Use by_pieces_constfn on constfun. (store_by_pieces): Use by_pieces_constfn on constfun. Updated for op_by_pieces_d change. (clear_by_pieces_1): Add a dummy argument. (clear_by_pieces): Updated for op_by_pieces_d change. (compare_by_pieces_d::compare_by_pieces_d): Likewise. (string_cst_read_str): Add a dummy argument. * expr.h (by_pieces_constfn): Add a dummy argument. (by_pieces_prev): New. * target.def (overlap_op_by_pieces_p): New target hook. * config/i386/i386.c (TARGET_OVERLAP_OP_BY_PIECES_P): New. * doc/tm.texi.in: Add TARGET_OVERLAP_OP_BY_PIECES_P. * doc/tm.texi: Regenerated. gcc/testsuite/ PR middle-end/90773 * g++.dg/pr90773-1.h: New test. * g++.dg/pr90773-1a.C: Likewise. * g++.dg/pr90773-1b.C: Likewise. * g++.dg/pr90773-1c.C: Likewise. * g++.dg/pr90773-1d.C: Likewise. * gcc.target/i386/pr90773-1.c: Likewise. * gcc.target/i386/pr90773-2.c: Likewise. * gcc.target/i386/pr90773-3.c: Likewise. * gcc.target/i386/pr90773-4.c: Likewise. * gcc.target/i386/pr90773-5.c: Likewise. * gcc.target/i386/pr90773-6.c: Likewise. * gcc.target/i386/pr90773-7.c: Likewise. * gcc.target/i386/pr90773-8.c: Likewise. * gcc.target/i386/pr90773-9.c: Likewise. * gcc.target/i386/pr90773-10.c: Likewise. * gcc.target/i386/pr90773-11.c: Likewise. * gcc.target/i386/pr90773-12.c: Likewise. * gcc.target/i386/pr90773-13.c: Likewise. * gcc.target/i386/pr90773-14.c: Likewise.
2021-01-04Update copyright years.Jakub Jelinek1-1/+1
2020-12-03Add support for detecting mismatched allocation/deallocation calls.Martin Sebor1-0/+10
PR c++/90629 - Support for -Wmismatched-new-delete PR middle-end/94527 - Add an __attribute__ that marks a function as freeing an object gcc/ChangeLog: PR c++/90629 PR middle-end/94527 * builtins.c (access_ref::access_ref): Initialize new member. (compute_objsize): Use access_ref::deref. Handle simple pointer assignment. (expand_builtin): Remove handling of the free built-in. (call_dealloc_argno): Same. (find_assignment_location): New function. (fndecl_alloc_p): Same. (gimple_call_alloc_p): Same. (call_dealloc_p): Same. (matching_alloc_calls_p): Same. (warn_dealloc_offset): Same. (maybe_emit_free_warning): Same. * builtins.h (struct access_ref): Declare new member. (maybe_emit_free_warning): Make extern. Make use of access_ref. Handle -Wmismatched-new-delete. * calls.c (initialize_argument_information): Call maybe_emit_free_warning. * doc/extend.texi (attribute malloc): Update. * doc/invoke.texi (-Wfree-nonheap-object): Expand documentation. (-Wmismatched-new-delete): Document new option. (-Wmismatched-dealloc): Document new option. gcc/c-family/ChangeLog: PR c++/90629 PR middle-end/94527 * c-attribs.c (handle_dealloc_attribute): New function. (handle_malloc_attribute): Handle argument forms of attribute. * c.opt (-Wmismatched-dealloc): New option. (-Wmismatched-new-delete): New option. gcc/testsuite/ChangeLog: PR c++/90629 PR middle-end/94527 * g++.dg/asan/asan_test.cc: Fix a bug. * g++.dg/warn/delete-array-1.C: Add expected warning. * g++.old-deja/g++.other/delete2.C: Add expected warning. * g++.dg/warn/Wfree-nonheap-object-2.C: New test. * g++.dg/warn/Wfree-nonheap-object.C: New test. * g++.dg/warn/Wmismatched-new-delete.C: New test. * g++.dg/warn/Wmismatched-dealloc-2.C: New test. * g++.dg/warn/Wmismatched-dealloc.C: New test. * gcc.dg/Wmismatched-dealloc.c: New test. * gcc.dg/analyzer/malloc-1.c: Prune out expected warning. * gcc.dg/attr-malloc.c: New test. * gcc.dg/free-1.c: Adjust text of expected warning. * gcc.dg/free-2.c: Same. * gcc.dg/torture/pr71816.c: Prune out expected warning. * gcc.dg/tree-ssa/pr19831-2.c: Add an expected warning. * gcc.dg/Wfree-nonheap-object-2.c: New test. * gcc.dg/Wfree-nonheap-object-3.c: New test. * gcc.dg/Wfree-nonheap-object.c: New test. libstdc++-v3/ChangeLog: * testsuite/ext/vstring/modifiers/clear/56166.cc: Suppress a false positive warning.
2020-12-02introduce overridable clear_cache emitterAlexandre Oliva1-0/+1
This patch introduces maybe_emit_call_builtin___clear_cache for the builtin expander machinery and the trampoline initializers to use to clear the instruction cache, removing a source of inconsistencies and subtle errors in low-level machinery. I've adjusted all trampoline_init implementations that used to issue explicit calls to __clear_cache or similar to use this new primitive. Specifically on vxworks targets, we needed to drop the __clear_cache symbol in libgcc, for reasons related with linking that I didn't need to understand, and we wanted to call cacheTextUpdate directly, despite the different calling conventions: the second argument is a length rather than the end address. So I introduced a target hook to enable target OS-level overriding of builtin __clear_cache call emission, retaining nearly (*) the same logic to govern the decision on whether to emit a call (or nothing, or a machine-dependent insn) but enabling a call to a target system-defined function with different calling conventions to be issued, without having to modify .md files of the various architectures supported by the target system to introduce or modify clear_cache insns. (*) I write "nearly" mainly because, when not optimizing, we'd issue a call regardless, but since the call may now be overridden, I added it to the set of builtins that are not directly turned into calls when not optimizing, following the normal expansion path instead. It wouldn't be hard to skip the emission of cache-clearing insns when not optimizing, but it didn't seem very important, especially for the new uses from trampoline init. Another difference that might be relevant is that now we expand the begin and end arguments unconditionally. This might make a difference if they have side effects. That's prettty much impossible at expand time, but I thought I'd mention it. I have NOT modified targets that did not issue cache-clearing calls in trampoline init to use the new clear_cache-calling infrastructure even if it would expand to nothing. I have considered doing so, to have __builtin___clear_cache and trampoline init call cacheTextUpdate on all vxworks targets, but decided not to, since on targets that don't do any cache clearing, cacheTextUpdate ought to be a no-op, even though rs6000 seems to use icbi and dcbf instructions in the function called to initialize a trampoline, but AFAICT not in the __clear_cache builtin. Hopefully target maintainers will have a look and take advantage of this new piece of infrastructure to remove such (apparent?) inconsistencies. Not rs6000 and other that call asm-coded trampoline setup instructions, for sure, but they might wish to introduce a CLEAR_INSN_CACHE macro or a clear_cache expander if they don't have one. for gcc/ChangeLog * builtins.c (default_emit_call_builtin___clear_cache): New. (maybe_emit_call_builtin___clear_cache): New. (expand_builtin___clear_cache): Split into the above. (expand_builtin): Do not issue clear_cache call any more. * builtins.h (maybe_emit_call_builtin___clear_cache): Declare. * config/aarch64/aarch64.c (aarch64_trampoline_init): Use maybe_emit_call_builtin___clear_cache. * config/arc/arc.c (arc_trampoline_init): Likewise. * config/arm/arm.c (arm_trampoline_init): Likewise. * config/c6x/c6x.c (c6x_initialize_trampoline): Likewise. * config/csky/csky.c (csky_trampoline_init): Likewise. * config/m68k/linux.h (FInALIZE_TRAMPOLINE): Likewise. * config/tilegx/tilegx.c (tilegx_trampoline_init): Likewise. * config/tilepro/tilepro.c (tilepro_trampoline_init): Ditto. * config/vxworks.c: Include rtl.h, memmodel.h, and optabs.h. (vxworks_emit_call_builtin___clear_cache): New. * config/vxworks.h (CLEAR_INSN_CACHE): Drop. (TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE): Define. * target.def (trampoline_init): In the documentation, refer to maybe_emit_call_builtin___clear_cache. (emit_call_builtin___clear_cache): New. * doc/tm.texi.in: Add new hook point. (CLEAR_CACHE_INSN): Remove duplicate 'both'. * doc/tm.texi: Rebuilt. * targhooks.h (default_meit_call_builtin___clear_cache): Declare. * tree.h (BUILTIN_ASM_NAME_PTR): New. for libgcc/ChangeLog * config/t-vxworks (LIB2ADD): Drop. * config/t-vxworks7 (LIB2ADD): Likewise. * config/vxcache.c: Remove.
2020-12-01PR middle-end/97373 - missing warning on sprintf into allocated destinationMartin Sebor1-2/+51
gcc/ChangeLog: PR middle-end/97373 * builtins.c (compute_objsize): Rename... (compute_objsize_r): to this. Change order and types of arguments. Use new argument. Adjust calls to self. (access_ref::get_ref): New member function. (pointer_query::pointer_query): New member function. (pointer_query::get_ref): Same. (pointer_query::put_ref): Same. (handle_min_max_size): Change order and types of arguments. (maybe_emit_free_warning): Add a test. * builtins.h (class pointer_query): New class. (compute_objsize): Declare an overload. * gimple-ssa-sprintf.c (get_destination_size): Add argument. (handle_printf_call): Change argument type. * tree-ssa-strlen.c (adjust_last_stmt): Add an argument and use it. (maybe_warn_overflow): Same. (handle_builtin_strcpy): Same. (maybe_diag_stxncpy_trunc): Same. (handle_builtin_memcpy): Change argument type. Adjust calls. (handle_builtin_strcat): Same. (handle_builtin_memset): Same. (handle_store): Same. (strlen_check_and_optimize_call): Same. (check_and_optimize_stmt): Same. (strlen_dom_walker): Add new data members. (strlen_dom_walker::before_dom_children): Use new member. (printf_strlen_execute): Dump cache performance counters. Remove objsize pass cleanup. * tree-ssa-strlen.h (maybe_diag_stxncpy_trunc): Add argument. (handle_printf_call): Change argument type. gcc/testsuite/ChangeLog: PR middle-end/97373 * gcc.dg/tree-ssa/builtin-sprintf-warn-25.c: New test.
2020-11-29Handle PHIs in compute_objsize.Martin Sebor1-12/+61
PR middle-end/92936 - missing warning on a past-the-end store to a PHI PR middle-end/92940 - incorrect offset and size in -Wstringop-overflow for out-of-bounds store into VLA and two offset ranges PR middle-end/89428 - missing -Wstringop-overflow on a PHI with variable offset gcc/ChangeLog: PR middle-end/92936 PR middle-end/92940 PR middle-end/89428 * builtins.c (access_ref::access_ref): Initialize member. (access_ref::phi): New function. (access_ref::get_ref): New function. (access_ref::add_offset): Remove duplicate assignment. (maybe_warn_for_bound): Add "maybe" kind of warning messages. (warn_for_access): Same. (inform_access): Rename... (access_ref::inform_access): ...to this. Print PHI arguments. Format offset the same as size and simplify. Improve printing of allocation functions and VLAs. (check_access): Adjust to the above. (gimple_parm_array_size): Change argument. (handle_min_max_size): New function. * builtins.h (class ssa_name_limit_t): Move class here from tree-ssa-strlen.c. (struct access_ref): Declare new members. (gimple_parm_array_size): Change argument. * tree-ssa-strlen.c (maybe_warn_overflow): Use access_ref and simplify. (handle_builtin_memcpy): Correct argument passed to maybe_warn_overflow. (handle_builtin_memset): Same. (class ssa_name_limit_t): Move class to builtins.{h,c}. gcc/testsuite/ChangeLog: PR middle-end/92936 PR middle-end/92940 PR middle-end/89428 * c-c++-common/Wstringop-overflow-2.c: Adjust text of expected informational notes. * g++.dg/warn/Wstringop-overflow-3.C: Same. * g++.dg/warn/Wplacement-new-size.C: Remove a test for a no longer issued warning. * gcc.dg/Warray-bounds-43.c: Removed unused declarations. * gcc.dg/Wstringop-overflow-11.c: Remove xfails. * gcc.dg/Wstringop-overflow-12.c: Same. * gcc.dg/Wstringop-overflow-17.c: Adjust text of expected messages. * gcc.dg/Wstringop-overflow-27.c: Same. Remove xfails. * gcc.dg/Wstringop-overflow-28.c: Adjust text of expected messages. * gcc.dg/Wstringop-overflow-29.c: Same. * gcc.dg/Wstringop-overflow-37.c: Same. * gcc.dg/Wstringop-overflow-46.c: Same. * gcc.dg/Wstringop-overflow-47.c: Same. * gcc.dg/Wstringop-overflow-54.c: Same. * gcc.dg/warn-strnlen-no-nul.c: Add expected warning. * gcc.dg/Wstringop-overflow-7.c: New test. * gcc.dg/Wstringop-overflow-58.c: New test. * gcc.dg/Wstringop-overflow-59.c: New test. * gcc.dg/Wstringop-overflow-60.c: New test. * gcc.dg/Wstringop-overflow-61.c: New test. * gcc.dg/Wstringop-overflow-62.c: New test. * gcc.dg/Wstringop-overflow-63.c: New test. * gcc.dg/Wstringop-overflow-64.c: New test.
2020-10-12Generalize compute_objsize to return maximum size/offset instead of failing ↵Martin Sebor1-6/+35
(PR middle-end/97023). Also resolves: PR middle-end/97342 - bogus -Wstringop-overflow with nonzero signed and unsigned offsets PR middle-end/97023 - missing warning on buffer overflow in chained mempcpy PR middle-end/96384 - bogus -Wstringop-overflow= storing into multidimensional array with index in range gcc/ChangeLog: PR middle-end/97342 PR middle-end/97023 PR middle-end/96384 * builtins.c (access_ref::access_ref): Initialize new member. Use new enum. (access_ref::size_remaining): Define new member function. (inform_access): Handle expressions referencing objects. (gimple_call_alloc_size): Call get_size_range instead of get_range. (gimple_call_return_array): New function. (get_range): Rename... (get_offset_range): ...to this. Improve detection of ranges from types of expressions. (gimple_call_return_array): Adjust calls to get_range per above. (compute_objsize): Same. Set maximum size or offset instead of failing for unknown objects and handle more kinds of expressions. (compute_objsize): Call access_ref::size_remaining. (compute_objsize): Have transitional wrapper fail for pointers into unknown objects. (expand_builtin_strncmp): Call access_ref::size_remaining and handle new cases. * builtins.h (access_ref::size_remaining): Declare new member function. (access_ref::set_max_size_range): Define new member function. (access_ref::add_ofset, access_ref::add_max_ofset): Same. (access_ref::add_base0): New data member. * calls.c (get_size_range): Change argument type. Handle new condition. * calls.h (get_size_range): Adjust signature. (enum size_range_flags): Define new type. * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Correct argument to get_size_range. * tree-ssa-strlen.c (get_range): Handle anti-ranges. (maybe_warn_overflow): Check DECL_P before assuming it's one. gcc/testsuite/ChangeLog: PR middle-end/97342 PR middle-end/97023 PR middle-end/96384 * c-c++-common/Wrestrict.c: Adjust comment. * gcc.dg/Wstringop-overflow-34.c: Remove xfail. * gcc.dg/Wstringop-overflow-43.c: Remove xfails. Adjust regex patterns. * gcc.dg/pr51683.c: Prune out expected warning. * gcc.target/i386/pr60693.c: Same. * g++.dg/warn/Wplacement-new-size-8.C: New test. * gcc.dg/Wstringop-overflow-41.c: New test. * gcc.dg/Wstringop-overflow-44.s: New test. * gcc.dg/Wstringop-overflow-45.c: New test. * gcc.dg/Wstringop-overflow-46.c: New test. * gcc.dg/Wstringop-overflow-47.c: New test. * gcc.dg/Wstringop-overflow-49.c: New test. * gcc.dg/Wstringop-overflow-50.c: New test. * gcc.dg/Wstringop-overflow-51.c: New test. * gcc.dg/Wstringop-overflow-52.c: New test. * gcc.dg/Wstringop-overflow-53.c: New test. * gcc.dg/Wstringop-overflow-54.c: New test. * gcc.dg/Wstringop-overflow-55.c: New test. * gcc.dg/Wstringop-overread-5.c: New test.
2020-10-12Correct handling of indices into arrays with elements larger than 1 (PR ↵Martin Sebor1-0/+16
c++/96511) Resolves: PR c++/96511 - Incorrect -Wplacement-new on POINTER_PLUS into an array with 4-byte elements PR middle-end/96384 - bogus -Wstringop-overflow= storing into multidimensional array with index in range gcc/ChangeLog: PR c++/96511 PR middle-end/96384 * builtins.c (get_range): Return full range of type when neither value nor its range is available. Fail for ranges inverted due to the signedness of offsets. (compute_objsize): Handle more special array members. Handle POINTER_PLUS_EXPR and VIEW_CONVERT_EXPR that come up in front end code. (access_ref::offset_bounded): Define new member function. * builtins.h (access_ref::eval): New data member. (access_ref::offset_bounded): New member function. (access_ref::offset_zero): New member function. (compute_objsize): Declare a new overload. * gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Use enum special_array_member. * tree.c (component_ref_size): Use special_array_member. * tree.h (special_array_member): Define a new type. (component_ref_size): Change signature. gcc/cp/ChangeLog: PR c++/96511 PR middle-end/96384 * init.c (warn_placement_new_too_small): Call builtin_objsize instead of duplicating what it does. gcc/testsuite/ChangeLog: PR c++/96511 PR middle-end/96384 * g++.dg/init/strlen.C: Add expected warning. * g++.dg/warn/Wplacement-new-size-1.C: Relax warnings. * g++.dg/warn/Wplacement-new-size-2.C: Same. * g++.dg/warn/Wplacement-new-size-6.C: Same. * gcc.dg/Warray-bounds-58.c: Adjust * gcc.dg/Wstringop-overflow-37.c: Same. * g++.dg/warn/Wplacement-new-size-7.C: New test.
2020-10-08take type from intrinsic in sincos passAlexandre Oliva1-0/+1
This is a first step towards enabling the sincos optimization in Ada. The issue this patch solves is that sincos takes the type to be looked up with mathfn_built_in from variables or temporaries passed as arguments to SIN and COS intrinsics. In Ada, different float types may be used but, despite their representation equivalence, their distinctness causes the optimization to be skipped, because they are not the types that mathfn_built_in expects. This patch introduces a function that maps intrinsics to the type they're associated with, and uses that type, obtained from the intrinsics used in calls to be optimized, to look up the correspoding CEXPI intrinsic. For the sake of defensive programming, when using the type obtained from the intrinsic, it now checks that, if different types are found for the used argument, or for other calls that use it, that the types are interchangeable. for gcc/ChangeLog * builtins.c (mathfn_built_in_type): New. * builtins.h (mathfn_built_in_type): Declare. * tree-ssa-math-opts.c (execute_cse_sincos_1): Use it to obtain the type expected by the intrinsic.
2020-10-01Convert sprintf/strlen passes to value query class.Aldy Hernandez1-5/+5
gcc/ChangeLog: * builtins.c (compute_objsize): Replace vr_values with range_query. (get_range): Same. (gimple_call_alloc_size): Same. * builtins.h (class vr_values): Remove. (gimple_call_alloc_size): Replace vr_values with range_query. * gimple-ssa-sprintf.c (get_int_range): Same. (struct directive): Pass gimple context to fmtfunc callback. (directive::set_width): Replace inline with out-of-line version. (directive::set_precision): Same. (format_none): New gimple argument. (format_percent): New gimple argument. (format_integer): New gimple argument. (format_floating): New gimple argument. (get_string_length): Use range_query API. (format_character): New gimple argument. (format_string): New gimple argument. (format_plain): New gimple argument. (format_directive): New gimple argument. (parse_directive): Replace vr_values with range_query. (compute_format_length): Same. (handle_printf_call): Same. Adjust for range_query API. * tree-ssa-strlen.c (get_range): Same. (compare_nonzero_chars): Same. (get_addr_stridx) Replace vr_values with range_query. (get_stridx): Same. (dump_strlen_info): Same. (get_range_strlen_dynamic): Adjust for range_query API. (set_strlen_range): Same (maybe_warn_overflow): Replace vr_values with range_query. (handle_builtin_strcpy): Same. (maybe_diag_stxncpy_trunc): Add FIXME comment. (handle_builtin_memcpy): Replace vr_values with range_query. (handle_builtin_memset): Same. (get_len_or_size): Same. (strxcmp_eqz_result): Same. (handle_builtin_string_cmp): Same. (count_nonzero_bytes_addr): Same, plus adjust for range_query API. (count_nonzero_bytes): Replace vr_values with range_query. (handle_store): Same. (strlen_check_and_optimize_call): Same. (handle_integral_assign): Same. (check_and_optimize_stmt): Same. * tree-ssa-strlen.h (class vr_values): Remove. (get_range): Replace vr_values with range_query. (get_range_strlen_dynamic): Same. (handle_printf_call): Same.
2020-09-19Extend -Wstringop-overflow to detect out-of-bounds accesses to array parameters.Martin Sebor1-9/+10
gcc/ChangeLog: PR c/50584 * builtins.c (warn_for_access): Add argument. Distinguish between reads and writes. (check_access): Add argument. Distinguish between reads and writes. (gimple_call_alloc_size): Set range even on failure. (gimple_parm_array_size): New function. (compute_objsize): Call it. (check_memop_access): Pass check_access an additional argument. (expand_builtin_memchr, expand_builtin_strcat): Same. (expand_builtin_strcpy, expand_builtin_stpcpy_1): Same. (expand_builtin_stpncpy, check_strncat_sizes): Same. (expand_builtin_strncat, expand_builtin_strncpy): Same. (expand_builtin_memcmp): Same. * builtins.h (compute_objsize): Declare a new overload. (gimple_parm_array_size): Declare. (check_access): Add argument. * calls.c (append_attrname): Simplify. (maybe_warn_rdwr_sizes): Handle internal attribute access. * tree-ssa-uninit.c (maybe_warn_pass_by_reference): Avoid adding quotes. gcc/testsuite/ChangeLog: PR c/50584 * c-c++-common/Wsizeof-pointer-memaccess1.c: Disable new expected warnings. * g++.dg/ext/attr-access.C: Update text of expected warnings. * gcc.dg/Wstringop-overflow-23.c: Same. * gcc.dg/Wstringop-overflow-24.c: Same. * gcc.dg/attr-access-none.c: Same. * gcc.dg/dfp/composite-type.c: Prune expected warnings. * gcc.dg/torture/pr57147-1.c: Add a member to an otherwise empty struct to avoid a warning. * gcc.dg/torture/pr57147-3.c: Same. * gcc.dg/Warray-bounds-30.c: Adjust. * gcc.dg/attr-access-none.c: Same. * gcc.dg/Wstringop-overflow-40.c: New test. * gcc.dg/attr-access-2.c: New test.
2020-08-28Add -Wstringop-overread for reading past the end by string functions.Martin Sebor1-13/+31
gcc/ChangeLog: * attribs.c (init_attr_rdwr_indices): Use global access_mode. * attribs.h (struct attr_access): Same. * builtins.c (fold_builtin_strlen): Add argument. (compute_objsize): Declare. (get_range): Declare. (check_read_access): New function. (access_ref::access_ref): Define ctor. (warn_string_no_nul): Add arguments. Handle -Wstrintop-overread. (check_nul_terminated_array): Handle source strings of different ranges of sizes. (expand_builtin_strlen): Remove warning code, call check_read_access instead. Declare locals closer to their initialization. (expand_builtin_strnlen): Same. (maybe_warn_for_bound): New function. (warn_for_access): Remove argument. Handle -Wstrintop-overread. (inform_access): Change argument type. (get_size_range): New function. (check_access): Remove unused arguments. Add new arguments. Handle -Wstrintop-overread. Move warning code to helpers and call them. Call check_nul_terminated_array. (check_memop_access): Remove unnecessary and provide additional arguments in calls. (expand_builtin_memchr): Call check_read_access. (expand_builtin_strcat): Remove unnecessary and provide additional arguments in calls. (expand_builtin_strcpy): Same. (expand_builtin_strcpy_args): Same. Avoid testing no-warning bit. (expand_builtin_stpcpy_1): Remove unnecessary and provide additional arguments in calls. (expand_builtin_stpncpy): Same. (check_strncat_sizes): Same. (expand_builtin_strncat): Remove unnecessary and provide additional arguments in calls. Adjust comments. (expand_builtin_strncpy): Remove unnecessary and provide additional arguments in calls. (expand_builtin_memcmp): Remove warning code. Call check_access. (expand_builtin_strcmp): Call check_access instead of check_nul_terminated_array. (expand_builtin_strncmp): Handle -Wstrintop-overread. (expand_builtin_fork_or_exec): Call check_access instead of check_nul_terminated_array. (expand_builtin): Same. (fold_builtin_1): Pass additional argument. (fold_builtin_n): Same. (fold_builtin_strpbrk): Remove calls to check_nul_terminated_array. (expand_builtin_memory_chk): Add comments. (maybe_emit_chk_warning): Remove unnecessary and provide additional arguments in calls. (maybe_emit_sprintf_chk_warning): Same. Adjust comments. * builtins.h (warn_string_no_nul): Add arguments. (struct access_ref): Add member and ctor argument. (struct access_data): Add members and ctor. (check_access): Adjust signature. * calls.c (maybe_warn_nonstring_arg): Return an indication of whether a warning was issued. Issue -Wstrintop-overread instead of -Wstringop-overflow. (append_attrname): Adjust to naming changes. (maybe_warn_rdwr_sizes): Same. Remove unnecessary and provide additional arguments in calls. * calls.h (maybe_warn_nonstring_arg): Return bool. * doc/invoke.texi (-Wstringop-overread): Document new option. * gimple-fold.c (gimple_fold_builtin_strcpy): Provide an additional argument in call. (gimple_fold_builtin_stpcpy): Same. * tree-ssa-uninit.c (maybe_warn_pass_by_reference): Adjust to naming changes. * tree.h (enum access_mode): New type. gcc/c-family/ChangeLog: * c.opt (Wstringop-overread): New option. gcc/testsuite/ChangeLog: * c-c++-common/Warray-bounds-7.c: Adjust expected warnings. * c-c++-common/Wrestrict.c: Remove xfail. * c-c++-common/attr-nonstring-3.c: Adjust text of expected warnings. * c-c++-common/attr-nonstring-6.c: Suppress -Wstringop-overread instead of -Wstringop-overflow. * c-c++-common/attr-nonstring-8.c: Adjust text of expected warnings. * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Also suppress -Wstringop-overread. * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same. * gcc.dg/Warray-bounds-39.c: Adjust expected warnings. * gcc.dg/Warray-bounds-40.c: Also suppress -Wstringop-overread. * gcc.dg/Warray-bounds-58.c: Remove xfail. Also expect -Wstringop-overread. Adjust text of expected warnings. * gcc.dg/Wsizeof-pointer-memaccess1.c: Also suppress -Wstringop-overread. * gcc.dg/Wstringop-overflow-22.c: Adjust text of expected warnings. * gcc.dg/Wstringop-overflow-33.c: Expect -Wstringop-overread. * gcc.dg/Wstringop-overflow-9.c: Expect -Wstringop-overread. * gcc.dg/attr-nonstring-2.c: Adjust text of expected warnings. * gcc.dg/attr-nonstring-3.c: Same. * gcc.dg/attr-nonstring-4.c: Same. * gcc.dg/attr-nonstring.c: Expect -Wstringop-overread. * gcc.dg/builtin-stringop-chk-5.c: Adjust comment. * gcc.dg/builtin-stringop-chk-8.c: Enable -Wstringop-overread instead of -Wstringop-overflow. * gcc.dg/pr78902.c: Also expect -Wstringop-overread. * gcc.dg/pr79214.c: Adjust text of expected warnings. * gcc.dg/strcmpopt_10.c: Suppress valid -Wno-stringop-overread. * gcc.dg/strlenopt-57.c: Also expect -Wstringop-overread. * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Also suppress valid -Wno-stringop-overread. * gcc.dg/tree-ssa/builtins-folding-gimple-ub.c: Same. * gcc.dg/uninit-33.c: Same. * gcc.dg/warn-strnlen-no-nul-2.c: Adjust text of expected warning. * gcc.dg/warn-strnlen-no-nul.c: Same. * gcc.target/i386/strcmpopt_6.c: Suppress -Wstringop-overread. * gcc.dg/Wstringop-overread-2.c: New test. * gcc.dg/Wstringop-overread.c: New test.
2020-06-10PR middle-end/95353 - spurious -Wstringop-overflow writing to a trailing ↵Martin Sebor1-3/+30
array plus offset Also resolves: PR middle-end/92939 - missing -Wstringop-overflow on negative index from the end of array gcc/ChangeLog: PR middle-end/95353 PR middle-end/92939 * builtins.c (inform_access): New function. (check_access): Call it. Add argument. (addr_decl_size): Remove. (get_range): New function. (compute_objsize): New overload. Only use compute_builtin_object_size with raw memory function. (check_memop_access): Pass new argument to compute_objsize and check_access. (expand_builtin_memchr, expand_builtin_strcat): Same. (expand_builtin_strcpy, expand_builtin_stpcpy_1): Same. (expand_builtin_stpncpy, check_strncat_sizes): Same. (expand_builtin_strncat, expand_builtin_strncpy): Same. (expand_builtin_memcmp): Same. * builtins.h (check_nul_terminated_array): Declare extern. (check_access): Add argument. (struct access_ref, struct access_data): New structs. * gimple-ssa-warn-restrict.c (clamp_offset): New helper. (builtin_access::overlap): Call it. * tree-object-size.c (decl_init_size): Declare extern. (addr_object_size): Correct offset computation. * tree-object-size.h (decl_init_size): Declare. * tree-ssa-strlen.c (handle_integral_assign): Remove a call to maybe_warn_overflow when assigning to an SSA_NAME. gcc/testsuite/ChangeLog: PR middle-end/95353 PR middle-end/92939 * c-c++-common/Wstringop-truncation.c: Remove an xfail. * gcc.dg/Warray-bounds-46.c: Remove a bogus warning. * gcc.dg/Wrestrict-9.c: Disable -Wstringop-overflow. * gcc.dg/Wstringop-overflow-12.c: Remove xfails. * gcc.dg/Wstringop-overflow-28.c: Same. * gcc.dg/builtin-stringop-chk-4.c: Same. * gcc.dg/builtin-stringop-chk-5.c: Same. * gcc.dg/builtin-stringop-chk-8.c: Same. * gcc.dg/strlenopt-74.c: Avoid buffer overflow. * gcc.dg/Wstringop-overflow-34.c: New test. * gcc.dg/Wstringop-overflow-35.c: New test. * gcc.dg/Wstringop-overflow-36.c: New test. * gcc.dg/Wstringop-overflow-37.c: New test. * gcc.dg/Wstringop-overflow-38.c: New test.
2020-06-04Implement a solution for PR middle-end/10138 and PR middle-end/95136.Martin Sebor1-1/+2
PR middle-end/10138 - warn for uninitialized arrays passed as const arguments PR middle-end/95136 - missing -Wuninitialized on an array access with a variable offset gcc/c-family/ChangeLog: PR middle-end/10138 PR middle-end/95136 * c-attribs.c (append_access_attrs): Handle attr_access::none. (handle_access_attribute): Same. gcc/ChangeLog: PR middle-end/10138 PR middle-end/95136 * attribs.c (init_attr_rdwr_indices): Move function here. * attribs.h (rdwr_access_hash, rdwr_map): Define. (attr_access): Add 'none'. (init_attr_rdwr_indices): Declared function. * builtins.c (warn_for_access)): New function. (check_access): Call it. * builtins.h (checK-access): Add an optional argument. * calls.c (rdwr_access_hash, rdwr_map): Move to attribs.h. (init_attr_rdwr_indices): Declare extern. (append_attrname): Handle attr_access::none. (maybe_warn_rdwr_sizes): Same. (initialize_argument_information): Update comments. * doc/extend.texi (attribute access): Document 'none'. * tree-ssa-uninit.c (struct wlimits): New. (maybe_warn_operand): New function. (maybe_warn_pass_by_reference): Same. (warn_uninitialized_vars): Refactor code into maybe_warn_operand. Also call for function calls. (pass_late_warn_uninitialized::execute): Adjust comments. (execute_early_warn_uninitialized): Same. gcc/testsuite/ChangeLog: PR middle-end/10138 PR middle-end/95136 * c-c++-common/Wsizeof-pointer-memaccess1.c: Prune out valid Wuninitialized. * c-c++-common/uninit-pr51010.c: Adjust expected warning format. * c-c++-common/goacc/uninit-dim-clause.c: Same. * c-c++-common/goacc/uninit-firstprivate-clause.c: Same. * c-c++-common/goacc/uninit-if-clause.c: Same. * c-c++-common/gomp/pr70550-1.c: Same. * c-c++-common/gomp/pr70550-2.c: Adjust. * g++.dg/20090107-1.C: Same. * g++.dg/20090121-1.C: Same. * g++.dg/ext/attr-access.C: Avoid -Wuninitialized. * gcc.dg/tree-ssa/forwprop-6.c: Prune out -Wuninitialized. * gcc.dg/Warray-bounds-52.c: Prune out valid -Wuninitialized. * gcc.dg/Warray-bounds-53.c: Same. * gcc.dg/Warray-bounds-54.c: Same. * gcc.dg/Wstringop-overflow-33.c: New test. * gcc.dg/attr-access-none.c: New test. * gcc.dg/attr-access-read-only.c: Adjust. * gcc.dg/attr-access-read-write.c: Same. * gcc.dg/attr-access-write-only.c: Same. * gcc.dg/pr71581.c: Adjust text of expected warning. * gcc.dg/uninit-15.c: Same. * gcc.dg/uninit-32.c: New test. * gcc.dg/uninit-33.c: New test. * gcc.dg/uninit-34.c: New test. * gcc.dg/uninit-36.c: New test. * gcc.dg/uninit-B-O0.c: Adjust text of expected warning. * gcc.dg/uninit-I-O0.c: Same. * gcc.dg/uninit-pr19430-O0.c: Same. * gcc.dg/uninit-pr19430.c: Same. * gcc.dg/uninit-pr95136.c: New test. * gfortran.dg/assignment_4.f90: Expect -Wuninitialized. * gfortran.dg/goacc/uninit-dim-clause.f95: Adjust text of expected warning. * gfortran.dg/goacc/uninit-firstprivate-clause.f95 * gfortran.dg/goacc/uninit-if-clause.f95 * gfortran.dg/pr66545_2.f90
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-12-13PR middle-end/91582 - missing heap overflow detection for strcpyMartin Sebor1-2/+6
PR middle-end/91582 - missing heap overflow detection for strcpy PR middle-end/92868 - ICE: tree check: expected integer_cst, have ssa_name gcc/ChangeLog: PR middle-end/91582 PR middle-end/92868 * builtins.c (addr_decl_size): New function. (gimple_call_alloc_size): Add arguments. (compute_objsize): Add an argument. Set *PDECL even for allocated objects. Correct checking for negative wide_int. Correct handling of negative outer offsets into unknown regions or with unknown inner offsets. Extend offsets to at most sizetype precision. Only handle constant subobject sizes. * builtins.h (gimple_call_alloc_size): Add arguments. * tree.c (component_ref_size): Always return sizetype. * tree-ssa-strlen.c (strinfo::alloc): New member. (get_addr_stridx): Add argument. (get_stridx): Use ptrdiff_t. Add argument. (new_strinfo): Set new member. (get_string_length): Handle alloca and VLA. (dump_strlen_info): Dump more state. (maybe_invalidate): Print more info. Decrease indentation. (unshare_strinfo): Set new member. (valid_builtin_call): Handle alloca and VLA. (maybe_warn_overflow): Check and set no-warning bit. Improve handling of offsets. Print allocated objects. (handle_builtin_strlen): Handle strinfo records with null lengths. (handle_builtin_strcpy): Add argument. Call maybe_warn_overflow. (is_strlen_related_p): Handle dynamically allocated objects. (get_range): Add argument. (handle_builtin_malloc): Rename... (handle_alloc): ...to this and handle all allocation functions. (handle_builtin_memset): Call maybe_warn_overflow. (count_nonzero_bytes): Handle more MEM_REF forms. (strlen_check_and_optimize_call): Call handle_alloc_call. Pass arguments to more callees. (handle_integral_assign): Add argument. Create strinfo entries for MEM_REF assignments. (check_and_optimize_stmt): Handle more MEM_REF forms. gcc/testsuite/ChangeLog: PR middle-end/91582 * c-c++-common/Wrestrict.c: Adjust expected warnings. * gcc/testsuite/c-c++-common/Wstringop-truncation-4.c: Enable more warnings. * gcc/testsuite/c-c++-common/Wstringop-truncation.c: Remove an xfail. * gcc.dg/Warray-bounds-46.c: Disable -Wstringop-overflow. * gcc.dg/Warray-bounds-47.c: Same. * gcc.dg/Warray-bounds-52.c: New test. * gcc.dg/Wstringop-overflow-27.c: New test. * gcc.dg/Wstringop-overflow-28.c: New test. * gcc.dg/Wstringop-overflow-29.c: New test. * gcc.dg/attr-alloc_size.c (test): Disable -Warray-bounds. * gcc.dg/attr-copy-2.c: Adjust expected warnings. * gcc.dg/builtin-stringop-chk-5.c: Adjust text of expected messages. * gcc.dg/strlenopt-86.c: Relax test. * gcc.target/i386/pr82002-1.c: Prune expected warnings. From-SVN: r279392
2019-12-04PR middle-end/91582 - missing heap overflow detection for strcpyMartin Sebor1-1/+2
gcc/ChangeLog: PR middle-end/91582 * builtins.c (gimple_call_alloc_size): New function. (compute_objsize): Add argument. Call gimple_call_alloc_size. Handle variable offsets and indices. * builtins.h (gimple_call_alloc_size): Declare. (compute_objsize): Add argument. * gcc/gimple-ssa-warn-restrict.c: Remove assertions. * tree-ssa-strlen.c (handle_store): Handle calls to allocated objects. gcc/testsuite/ChangeLog: PR middle-end/91582 * c-c++-common/Wstringop-truncation.c: Remove xfails. * g++.dg/warn/Wstringop-overflow-4.C: New test. * g++.dg/ext/attr-alloc_size.C: Suppress -Warray-bounds. * gcc.dg/Warray-bounds-56.c: New test. * gcc.dg/Wstringop-overflow-22.c: New test. * gcc.dg/attr-alloc_size.c: Suppress -Warray-bounds. * gcc.dg/attr-copy-2.c: Same. * gcc.dg/builtin-stringop-chk-5.c: Remove xfails. * gcc.dg/builtin-stringop-chk-8.c: Same. Correct the text of expected warnings. * gcc.target/i386/pr82002-2a.c: Prune expected warning. * gcc.target/i386/pr82002-2b.c: Same. From-SVN: r278983
2019-11-22PR middle-end/83859 - attributes to associate pointer arguments and sizesMartin Sebor1-0/+2
gcc/ChangeLog: PR middle-end/83859 * attribs.h (struct attr_access): New. * attribs.c (decl_attributes): Add an informational note. * builtins.c (check_access): Make extern. Consistently set no-warning after issuing a warning. Handle calls through function pointers. Set no-warning. * builtins.h (check_access): Declare. * calls.c (rdwr_access_hash): New type. (rdwr_map): Same. (init_attr_rdwr_indices): New function. (maybe_warn_rdwr_sizes): Same. (initialize_argument_information): Call init_attr_rdwr_indices. Call maybe_warn_rdwr_sizes. (get_size_range): Avoid null argument. * doc/extend.texi (attribute access): Document new attribute. gcc/c-family/ChangeLog: PR middle-end/83859 * c-attribs.c (handle_access_attribute): New function. (c_common_attribute_table): Add new attribute. (get_argument_type): New function. (append_access_attrs): New function. (get_nonnull_operand): Rename... (get_attribute_operand): ...to this. * c-common.c (get_nonnull_operand): Rename... (get_attribute_operand): ...to this. gcc/testsuite/ChangeLog: PR middle-end/83859 * c-c++-common/attr-nonstring-8.c: Adjust text of expected warning. * gcc.dg/Wstringop-overflow-23.c: New test. * gcc.dg/Wstringop-overflow-24.c: New test. * gcc.dg/attr-access-read-only.c: New test. * gcc.dg/attr-access-read-write.c: New test. * gcc.dg/attr-access-read-write-2.c: New test. * gcc.dg/attr-access-write-only.c: New test. From-SVN: r278624
2019-11-22PR middle-end/88226 - missing warning on fprintf, fputs, and puts with an ↵Martin Sebor1-2/+2
unterminated array gcc/ChangeLog: PR middle-end/88226 * builtins.c (check_nul_terminated_array): New function. (fold_builtin_0): Remove declaration. (fold_builtin_1): Same. (fold_builtin_2): Same. (fold_builtin_3): Same. (fold_builtin_strpbrk): Add argument. (fold_builtin_strspn): Same. (fold_builtin_strcspn): Same. (expand_builtin_strcat): Call it. Remove unused argument. (expand_builtin_stpncpy): Same. (expand_builtin_strncat): Same. (expand_builtin_strncpy): Same. Adjust indentation. (expand_builtin_strcmp): Same. (expand_builtin_strncmp): Same. (expand_builtin_fork_or_exec): Same. (expand_builtin): Handle more built-ins. (fold_builtin_2): Add argument. (fold_builtin_n): Make static. Add argument. (fold_call_expr): Pass new argument to fold_builtin_n and fold_builtin_2. (fold_builtin_call_array): Pass new argument to fold_builtin_n. (fold_builtin_strpbrk): Add argument. Call check_nul_terminated_array. (fold_call_stmt): Pass new argument to fold_builtin_n. * builtins.h: Correct a comment. * gimple-fold.c (gimple_fold_builtin_strchr): Call check_nul_terminated_array. * tree-ssa-strlen.c (handle_builtin_strlen): Call check_nul_terminated_array. (handle_builtin_strchr): Same. (handle_builtin_string_cmp): Same. gcc/testsuite/ChangeLog: PR middle-end/88226 * gcc.dg/Wstringop-overflow-22.c: New test. * gcc.dg/tree-ssa/builtin-fprintf-warn-1.c: Remove xfails. From-SVN: r278623
2019-08-28PR tree-optimization/91457 - inconsistent warning for writing past the end ↵Martin Sebor1-1/+1
of an array member gcc/ChangeLog: PR tree-optimization/91457 * builtins.c (component_size): New function. (compute_objsize): Add argument. Handle ARRAY_REF and COMPONENT_REF. * builtins.h (compute_objsize): Add argument. * tree-ssa-strlen.c (handle_store): Handle no-warning bit. * tree-vrp.c (vrp_prop::check_array_ref): Return warning result. (vrp_prop::check_mem_ref): Same. (vrp_prop::search_for_addr_array): Set no-warning bit. (check_array_bounds): Same. gcc/testsuite/ChangeLog: PR tree-optimization/91457 * c-c++-common/Wstringop-overflow-2.c: New test. * g++.dg/warn/Warray-bounds-8.C: New test. * g++.dg/warn/Wstringop-overflow-3.C: New test. * gcc.dg/Wstringop-overflow-15.c: New test. From-SVN: r274997
2019-08-14Enable math functions linking with static library for LTOXiong Hu Luo1-0/+1
In LTO mode, if static library and dynamic library contains same function and both libraries are passed as arguments, linker will link the function in dynamic library no matter the sequence. This patch will output LTO symbol node as UNDEF if BUILT_IN_NORMAL function FNDECL is a math function, then the function in static library will be linked first if its sequence is ahead of the dynamic library. gcc/ChangeLog 2019-08-14 Xiong Hu Luo <luoxhu@linux.ibm.com> PR lto/91287 * builtins.c (builtin_with_linkage_p): New function. * builtins.h (builtin_with_linkage_p): New function. * symtab.c (write_symbol): Remove redundant assert. * lto-streamer-out.c (symtab_node::output_to_lto_symbol_table_p): Remove FIXME and use builtin_with_linkage_p. From-SVN: r274411
2019-02-16re PR rtl-optimization/66152 (suboptimal load bytes to stack)Jakub Jelinek1-0/+1
PR rtl-optimization/66152 * builtins.h (c_readstr): Declare. * builtins.c (c_readstr): Remove forward declaration. Add null_terminated_p argument, if false, read all bytes from the string instead of stopping after '\0'. * expr.c (string_cst_read_str): New function. (store_expr): Use string_cst_read_str instead of builtin_strncpy_read_str. Try to store by pieces the whole exp_len first, and only if that fails, split it up into store by pieces followed by clear_storage. Formatting fix. * gcc.target/i386/pr66152.c: New test. From-SVN: r268957
2019-02-13Clean up MPX-related stuff.Martin Liska1-1/+0
2019-02-13 Martin Liska <mliska@suse.cz> * builtins.h (expand_builtin_with_bounds): Remove declaration. * calls.c (struct arg_data): Remove special_slot, pointer_arg and pointer_offset fields. (initialize_argument_information): Remove usage of dead fields. * cgraph.h (struct cgraph_thunk_info): Remove add_pointer_bounds_args. * cgraphunit.c (cgraph_node::expand_thunk): Remove usage of dead fields. (cgraph_node::assemble_thunks_and_aliases): Remove usage of dead fields. * config/i386/i386.c (ix86_function_arg_advance): Remove unrelated comment. (struct builtin_isa): Remove leaf_p and nothrow_p fields. (def_builtin): Remove usage of dead fields. (ix86_add_new_builtins): Likewise. * ipa-fnsummary.c (compute_fn_summary): Likewise. * ipa-icf.c (sem_function::equals_wpa): Likewise. (sem_function::init): Likewise. (sem_variable::merge): Likewise. * ipa-visibility.c (function_and_variable_visibility): Likewise. * ipa.c (symbol_table::remove_unreachable_nodes): Likewise. * lto-cgraph.c (lto_output_node): Likewise. (lto_output_varpool_node): Likewise. (input_node): Likewise. (input_varpool_node): Likewise. * lto-streamer-out.c (lto_output): Likewise. * tree-inline.c (expand_call_inline): Remove usage of assign_stmts. * tree-inline.h (struct copy_body_data): Likewise. * varpool.c (varpool_node::dump): Likewise. From-SVN: r268844
2019-02-11PR c++/87996 - size of array is negative error when SIZE_MAX/2 < ↵Martin Sebor1-1/+0
sizeof(array) <= SIZE_MAX gcc/ChangeLog: PR c++/87996 * builtins.c (max_object_size): Move from here... * builtins.h (max_object_size): ...and here... * tree.c (max_object_size): ...to here... * tree.h (max_object_size): ...and here. gcc/c-family/ChangeLog: PR c++/87996 * c-common.c (invalid_array_size_error): New function. (valid_array_size_p): Call it. Handle size as well as type. * c-common.h (valid_constant_size_p): New function. (enum cst_size_error): New type. gcc/cp/ChangeLog: PR c++/87996 * decl.c (compute_array_index_type_loc): Preserve signed sizes for diagnostics. Call valid_array_size_p instead of error. * init.c (build_new_1): Compute size for diagnostic. Call invalid_array_size_error (build_new): Call valid_array_size_p instead of error. gcc/testsuite/ChangeLog: PR c++/87996 * c-c++-common/array-5.c: New test. * c-c++-common/pr68107.c: Adjust text of diagnostics. * g++.dg/init/new38.C: Same. * g++.dg/init/new43.C: Same. * g++.dg/init/new44.C: Same. * g++.dg/init/new46.C: Same. * g++.dg/other/large-size-array.C: Same. * g++.dg/other/new-size-type.C: Same. * g++.dg/template/array30.C: Same. * g++.dg/template/array32.C: New test. * g++.dg/template/dependent-name3.C: Adjust. * gcc.dg/large-size-array-3.c: Same. * gcc.dg/large-size-array-5.c: Same. * gcc.dg/large-size-array.c: Same. * g++.old-deja/g++.brendan/array1.C: Same. * g++.old-deja/g++.mike/p6149.C: Same. From-SVN: r268774
2019-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r267494
2018-12-23builtins.h (c_strlen_data): Add new fields and comments.Martin Sebor1-1/+39
* builtins.h (c_strlen_data): Add new fields and comments. * builtins.c (unterminated_array): Change field reference from "len" to "minlen" in c_strlen_data instance. * gimple-fold.c (get_range_strlen): Likewise. * gimple-ssa-sprintf.c (get_string_length): Likewise. Co-Authored-By: Jeff Law <law@redhat.com> From-SVN: r267378
2018-10-02builtins.c (unterminated_array): Add new arguments.Martin Sebor1-1/+1
* builtins.c (unterminated_array): Add new arguments. If argument is not terminated, bubble up size and exact state to callers. (expand_builtin_strnlen): Detect, avoid expanding and diagnose unterminated arrays. (c_strlen): Fill in offset of start of unterminated strings. * builtins.h (unterminated_array): Update prototype. * gcc.dg/warn-strnlen-no-nul.c: New. Co-Authored-By: Jeff Law <law@redhat.com> From-SVN: r264787
2018-09-29builtins.c (unterminated_array): Pass in c_strlen_data * to c_strlen rather ↵Jeff Law1-1/+8
than just a tree *. * builtins.c (unterminated_array): Pass in c_strlen_data * to c_strlen rather than just a tree *. (c_strlen): Change NONSTR argument to a c_strlen_data pointer. Update recursive calls appropriately. If caller did not provide a suitable data pointer, create a local one. When a non-terminated string is discovered, bubble up information about the string via the c_strlen_data object. * builtins.h (c_strlen): Update prototype. (c_strlen_data): New structure. * gimple-fold.c (get_range_strlen): Update calls to c_strlen. For a type 2 call, if c_strlen indicates a non-terminated string use the length of the non-terminated string. (gimple_fold_builtin_stpcpy): Update calls to c_strlen. From-SVN: r264712
2018-09-14builtins.c (unterminated_array): Handle ARRAY_REF.Martin Sebor1-0/+1
* builtins.c (unterminated_array): Handle ARRAY_REF. (expand_builtin_stpcpy_1): Detect unterminated char arrays. * builtins.h (unterminated_array): Declare extern. * gimple-fold.c (gimple_fold_builtin_stpcpy): Detect unterminated arrays. (gimple_fold_builtin_sprintf): Propagate NO_WARNING to transformed calls. * gcc.dg/warn-stpcpy-no-nul.c: New test. From-SVN: r264328
2018-09-13builtins.h (c_srlen): Add argument.Martin Sebor1-1/+2
* builtins.h (c_srlen): Add argument. * builtins.c (warn_string_no_nul): New function. (c_strlen): Add argument and use it. Update recursive calls. Pass DECL argument to string_constant to get info on non terminated strings. Update *NONSTR as needed. (fold_builtin_strlen): Add argument to calls to c_strlen. Warn for unterminated arrays. (warn_string_no_null): Add prototype. * expr.c (string_constant): Update arguments. Update recursive calls appropriately. Detect missing NUL terminator and outermost declaration its missing in. Improve checks for arrays with nonzero lower bound or elements that are not a single byte. Simplify offset computation. Simplify checks for non-NUL terminated strings. * gimple-fold.c (get_range_strlen): Add argument to c_strlen call. * gimple-ssa-sprintf.c (get_string_length): Remove unnecessary code. * gcc.dg/warn-strlen-no-nul.c: New test. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de> Co-Authored-By: Jeff Law <law@redhat.com> From-SVN: r264302
2018-08-27Come up with fndecl_built_in_p.Martin Liska1-1/+0
2018-08-27 Martin Liska <mliska@suse.cz> * builtins.h (is_builtin_fn): Remove and fndecl_built_in_p. * builtins.c (is_builtin_fn): Likewise. * attribs.c (diag_attr_exclusions): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (builtin_mathfn_code): Likewise. (fold_builtin_expect): Likewise. (fold_call_expr): Likewise. (fold_builtin_call_array): Likewise. (fold_call_stmt): Likewise. (set_builtin_user_assembler_name): Likewise. (is_simple_builtin): Likewise. * calls.c (gimple_alloca_call_p): Likewise. (maybe_warn_nonstring_arg): Likewise. * cfgexpand.c (expand_call_stmt): Likewise. * cgraph.c (cgraph_update_edges_for_call_stmt_node): Likewise. (cgraph_edge::verify_corresponds_to_fndecl): Likewise. (cgraph_node::verify_node): Likewise. * cgraphclones.c (build_function_decl_skip_args): Likewise. (cgraph_node::create_clone): Likewise. * config/arm/arm.c (arm_insert_attributes): Likewise. * config/i386/i386.c (ix86_gimple_fold_builtin): Likewise. * dse.c (scan_insn): Likewise. * expr.c (expand_expr_real_1): Likewise. * fold-const.c (operand_equal_p): Likewise. (fold_binary_loc): Likewise. * gimple-fold.c (gimple_fold_stmt_to_constant_1): Likewise. * gimple-low.c (lower_stmt): Likewise. * gimple-pretty-print.c (dump_gimple_call): Likewise. * gimple-ssa-warn-restrict.c (wrestrict_dom_walker::check_call): Likewise. * gimple.c (gimple_build_call_from_tree): Likewise. (gimple_call_builtin_p): Likewise. (gimple_call_combined_fn): Likewise. * gimplify.c (gimplify_call_expr): Likewise. (gimple_boolify): Likewise. (gimplify_modify_expr): Likewise. (gimplify_addr_expr): Likewise. * hsa-gen.c (gen_hsa_insns_for_call): Likewise. * ipa-cp.c (determine_versionability): Likewise. * ipa-fnsummary.c (compute_fn_summary): Likewise. * ipa-param-manipulation.c (ipa_modify_formal_parameters): Likewise. * ipa-split.c (visit_bb): Likewise. (split_function): Likewise. * ipa-visibility.c (cgraph_externally_visible_p): Likewise. * lto-cgraph.c (input_node): Likewise. * lto-streamer-out.c (write_symbol): Likewise. * omp-low.c (setjmp_or_longjmp_p): Likewise. (lower_omp_1): Likewise. * predict.c (strip_predict_hints): Likewise. * print-tree.c (print_node): Likewise. * symtab.c (symtab_node::output_to_lto_symbol_table_p): Likewise. * trans-mem.c (is_tm_irrevocable): Likewise. (is_tm_load): Likewise. (is_tm_simple_load): Likewise. (is_tm_store): Likewise. (is_tm_simple_store): Likewise. (is_tm_abort): Likewise. (tm_region_init_1): Likewise. * tree-call-cdce.c (gen_shrink_wrap_conditions): Likewise. * tree-cfg.c (verify_gimple_call): Likewise. (move_stmt_r): Likewise. (stmt_can_terminate_bb_p): Likewise. * tree-eh.c (lower_eh_constructs_2): Likewise. * tree-if-conv.c (if_convertible_stmt_p): Likewise. * tree-inline.c (remap_gimple_stmt): Likewise. (copy_bb): Likewise. (estimate_num_insns): Likewise. (fold_marked_statements): Likewise. * tree-sra.c (scan_function): Likewise. * tree-ssa-ccp.c (surely_varying_stmt_p): Likewise. (optimize_stack_restore): Likewise. (pass_fold_builtins::execute): Likewise. * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Likewise. (mark_all_reaching_defs_necessary_1): Likewise. * tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Likewise. * tree-ssa-forwprop.c (simplify_builtin_call): Likewise. (pass_forwprop::execute): Likewise. * tree-ssa-loop-im.c (stmt_cost): Likewise. * tree-ssa-math-opts.c (pass_cse_reciprocals::execute): Likewise. * tree-ssa-sccvn.c (fully_constant_vn_reference_p): Likewise. * tree-ssa-strlen.c (get_string_length): Likewise. * tree-ssa-structalias.c (handle_lhs_call): Likewise. (find_func_aliases_for_call): Likewise. * tree-ssa-ter.c (find_replaceable_in_bb): Likewise. * tree-stdarg.c (optimize_va_list_gpr_fpr_size): Likewise. * tree-tailcall.c (find_tail_calls): Likewise. * tree.c (need_assembler_name_p): Likewise. (free_lang_data_in_decl): Likewise. (get_call_combined_fn): Likewise. * ubsan.c (is_ubsan_builtin_p): Likewise. * varasm.c (incorporeal_function_p): Likewise. * tree.h (DECL_BUILT_IN): Remove and replace with fndecl_built_in_p. (DECL_BUILT_IN_P): Transfort to fndecl_built_in_p. (fndecl_built_in_p): New. 2018-08-27 Martin Liska <mliska@suse.cz> * gcc-interface/decl.c (update_profile): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. * gcc-interface/gigi.h (call_is_atomic_load): Likewise. * gcc-interface/utils.c (gnat_pushdecl): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * c-common.c (check_function_restrict): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (check_builtin_function_arguments): Likewise. (reject_gcc_builtin): Likewise. * c-warn.c (sizeof_pointer_memaccess_warning): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * c-decl.c (locate_old_decl): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (diagnose_mismatched_decls): Likewise. (merge_decls): Likewise. (warn_if_shadowing): Likewise. (pushdecl): Likewise. (implicitly_declare): Likewise. * c-parser.c (c_parser_postfix_expression_after_primary): Likewise. * c-tree.h (C_DECL_ISNT_PROTOTYPE): Likewise. * c-typeck.c (build_function_call_vec): Likewise. (convert_arguments): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * call.c (build_call_a): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. (build_cxx_call): Likewise. * constexpr.c (constexpr_fn_retval): Likewise. (cxx_eval_builtin_function_call): Likewise. (cxx_eval_call_expression): Likewise. (potential_constant_expression_1): Likewise. * cp-gimplify.c (cp_gimplify_expr): Likewise. (cp_fold): Likewise. * decl.c (decls_match): Likewise. (validate_constexpr_redeclaration): Likewise. (duplicate_decls): Likewise. (make_rtl_for_nonlocal_decl): Likewise. * name-lookup.c (consider_binding_level): Likewise. (cp_emit_debug_info_for_using): Likewise. * semantics.c (finish_call_expr): Likewise. * tree.c (builtin_valid_in_constant_expr_p): Likewise. 2018-08-27 Martin Liska <mliska@suse.cz> * go-gcc.cc (Gcc_backend::call_expression): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. 2018-08-27 Martin Liska <mliska@suse.cz> * lto-lang.c (handle_const_attribute): Use new function fndecl_built_in_p and remove check for FUNCTION_DECL if possible. * lto-symtab.c (lto_symtab_merge_p): Likewise. (lto_symtab_merge_decls_1): Likewise. (lto_symtab_merge_symbols): Likewise. * lto.c (lto_maybe_register_decl): Likewise. (read_cgraph_and_symbols): Likewise. From-SVN: r263880
2018-08-16builtins.c (c_strlen): Add new parameter eltsize.Bernd Edlinger1-1/+1
* builtins.c (c_strlen): Add new parameter eltsize. Use it for determining how to count the elements. * builtins.h (c_strlen): Adjust prototype. * expr.c (string_constant): Add new parameter mem_size. Set *mem_size appropriately. * expr.h (string_constant): Adjust protoype. * gimple-fold.c (get_range_strlen): Add new parameter eltsize. * gimple-fold.h (get_range_strlen): Adjust prototype. * gimple-ssa-sprintf.c (get_string_length): Add new parameter eltsize. (format_string): Call get_string_length with eltsize. From-SVN: r263607
2018-08-10Introduce __builtin_expect_with_probability (PR target/83610).Martin Liska1-1/+1
2018-08-10 Martin Liska <mliska@suse.cz> PR target/83610 * builtin-types.def (BT_FN_LONG_LONG_LONG_DOUBLE): Add new function type. * builtins.c (expand_builtin_expect_with_probability): New function. (expand_builtin_expect_with_probability): New function. (build_builtin_expect_predicate): Add new argumnet probability for BUILT_IN_EXPECT_WITH_PROBABILITY. (fold_builtin_expect): (fold_builtin_2): (fold_builtin_3): * builtins.def (BUILT_IN_EXPECT_WITH_PROBABILITY): * builtins.h (fold_builtin_expect): Set new argument. * doc/extend.texi: Document __builtin_expect_with_probability. * doc/invoke.texi: Likewise. * gimple-fold.c (gimple_fold_call): Pass new argument. * ipa-fnsummary.c (find_foldable_builtin_expect): Handle also BUILT_IN_EXPECT_WITH_PROBABILITY. * predict.c (get_predictor_value): New function. (expr_expected_value): Add new argument probability. Assume that predictor and probability are always non-null. (expr_expected_value_1): Likewise. For __builtin_expect and __builtin_expect_with_probability set probability. Handle combination in binary expressions. (tree_predict_by_opcode): Simplify code by simply calling get_predictor_value. (pass_strip_predict_hints::execute): Add handling of BUILT_IN_EXPECT_WITH_PROBABILITY. * predict.def (PRED_BUILTIN_EXPECT_WITH_PROBABILITY): Add new predictor. * tree.h (DECL_BUILT_IN_P): New function. 2018-08-10 Martin Liska <mliska@suse.cz> PR target/83610 * gcc.dg/predict-17.c: New test. * gcc.dg/predict-18.c: New test. * gcc.dg/predict-19.c: New test. From-SVN: r263466
2018-07-24PR tree-optimization/86622 - incorrect strlen of array of array plus ↵Martin Sebor1-0/+1
variable offset PR tree-optimization/86622 - incorrect strlen of array of array plus variable offset PR tree-optimization/86532 - Wrong code due to a wrong strlen folding starting with r262522 gcc/ChangeLog: PR tree-optimization/86622 PR tree-optimization/86532 * builtins.h (string_length): Declare. * builtins.c (c_strlen): Correct handling of non-constant offsets. (check_access): Be prepared for non-constant length ranges. (string_length): Make extern. * expr.c (string_constant): Only handle the minor non-constant array index. Use string_constant to compute the length of a generic string constant. gcc/testsuite/ChangeLog: PR tree-optimization/86622 PR tree-optimization/86532 * gcc.c-torture/execute/strlen-2.c: New test. * gcc.c-torture/execute/strlen-3.c: New test. * gcc.c-torture/execute/strlen-4.c: New test. From-SVN: r262958
2018-01-03Add a fixed_size_mode_pod classRichard Sandiford1-2/+2
This patch adds a POD version of fixed_size_mode. The only current use is for storing the __builtin_apply and __builtin_result register modes, which were made fixed_size_modes by the previous patch. 2018-01-03 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> gcc/ * coretypes.h (fixed_size_mode): Declare. (fixed_size_mode_pod): New typedef. * builtins.h (target_builtins::x_apply_args_mode) (target_builtins::x_apply_result_mode): Change type to fixed_size_mode_pod. * builtins.c (apply_args_size, apply_result_size, result_vector) (expand_builtin_apply_args_1, expand_builtin_apply) (expand_builtin_return): Update accordingly. Co-Authored-By: Alan Hayward <alan.hayward@arm.com> Co-Authored-By: David Sherwood <david.sherwood@arm.com> From-SVN: r256193
2018-01-03Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r256169
2017-12-16PR tree-optimization/78918 - missing -Wrestrict on memcpy copying over selfMartin Sebor1-1/+3
gcc/c-family/ChangeLog: PR tree-optimization/78918 * c-common.c (check_function_restrict): Avoid checking built-ins. * c.opt (-Wrestrict): Include in -Wall. gcc/ChangeLog: PR tree-optimization/78918 * Makefile.in (OBJS): Add gimple-ssa-warn-restrict.o. * builtins.c (check_sizes): Rename... (check_access): ...to this. Rename function arguments for clarity. (check_memop_sizes): Adjust names. (expand_builtin_memchr, expand_builtin_memcpy): Same. (expand_builtin_memmove, expand_builtin_mempcpy): Same. (expand_builtin_strcat, expand_builtin_stpncpy): Same. (check_strncat_sizes, expand_builtin_strncat): Same. (expand_builtin_strncpy, expand_builtin_memset): Same. (expand_builtin_bzero, expand_builtin_memcmp): Same. (expand_builtin_memory_chk, maybe_emit_chk_warning): Same. (maybe_emit_sprintf_chk_warning): Same. (expand_builtin_strcpy): Adjust. (expand_builtin_stpcpy): Same. (expand_builtin_with_bounds): Detect out-of-bounds accesses in pointer-checking forms of memcpy, memmove, and mempcpy. (gcall_to_tree_minimal, max_object_size): Define new functions. * builtins.h (max_object_size): Declare. * calls.c (alloc_max_size): Call max_object_size instead of hardcoding ssizetype limit. (get_size_range): Handle new argument. * calls.h (get_size_range): Add a new argument. * cfgexpand.c (expand_call_stmt): Propagate no-warning bit. * doc/invoke.texi (-Wrestrict): Adjust, add example. * gimple-fold.c (gimple_fold_builtin_memory_op): Detect overlapping operations. (gimple_fold_builtin_memory_chk): Same. (gimple_fold_builtin_stxcpy_chk): New function. * gimple-ssa-warn-restrict.c: New source. * gimple-ssa-warn-restrict.h: New header. * gimple.c (gimple_build_call_from_tree): Propagate location. * passes.def (pass_warn_restrict): Add new pass. * tree-pass.h (make_pass_warn_restrict): Declare. * tree-ssa-strlen.c (handle_builtin_strcpy): Detect overlapping operations. (handle_builtin_strcat): Same. (strlen_optimize_stmt): Rename... (strlen_check_and_optimize_stmt): ...to this. Handle strncat, stpncpy, strncpy, and their checking forms. gcc/testsuite/ChangeLog: PR tree-optimization/78918 * c-c++-common/Warray-bounds.c: New test. * c-c++-common/Warray-bounds-2.c: New test. * c-c++-common/Warray-bounds-3.c: New test. * c-c++-common/Warray-bounds-4.c: New test. * c-c++-common/Warray-bounds-5.c: New test. * c-c++-common/Wrestrict-2.c: New test. * c-c++-common/Wrestrict.c: New test. * c-c++-common/Wrestrict.s: New test. * c-c++-common/Wsizeof-pointer-memaccess1.c: Adjust * c-c++-common/Wsizeof-pointer-memaccess2.c: Same. * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Same. * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same. * gcc.dg/range.h: New header. * gcc.dg/memcpy-6.c: New test. * gcc.dg/pr69172.c: Adjust. * gcc.dg/pr79223.c: Same. * gcc.dg/pr81345.c: Adjust. * gcc.dg/Wobjsize-1.c: Same. * gcc.dg/Wrestrict-2.c: New test. * gcc.dg/Wrestrict.c: New test. * gcc.dg/Wsizeof-pointer-memaccess1.c: Adjust. * gcc.dg/builtin-stpncpy.c: Same. * gcc.dg/builtin-stringop-chk-1.c: Same. * gcc.target/i386/chkp-stropt-17.c: New test. * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Adjust. From-SVN: r255755
2017-11-10PR c/81117 - Improve buffer overflow checking in strncpyMartin Sebor1-0/+1
gcc/ChangeLog: PR c/81117 * builtins.c (compute_objsize): Handle arrays that compute_builtin_object_size likes to fail for. Make extern. * builtins.h (compute_objsize): Declare. (check_strncpy_sizes): New function. (expand_builtin_strncpy): Call check_strncpy_sizes. * gimple-fold.c (gimple_fold_builtin_strncpy): Implement -Wstringop-truncation. (gimple_fold_builtin_strncat): Same. * gimple.c (gimple_build_call_from_tree): Set call location. * tree-ssa-strlen.c (strlen_to_stridx): New global variable. (maybe_diag_bound_equal_length, is_strlen_related_p): New functions. (handle_builtin_stxncpy, handle_builtin_strncat): Same. (handle_builtin_strlen): Use strlen_to_stridx. (strlen_optimize_stmt): Handle flavors of strncat, strncpy, and stpncpy. Use strlen_to_stridx. (pass_strlen::execute): Release strlen_to_stridx. * doc/invoke.texi (-Wsizeof-pointer-memaccess): Document enhancement. (-Wstringop-truncation): Document new option. gcc/ada/ChangeLog: PR c/81117 * ada/adadecode.c (__gnat_decode): Use memcpy instead of strncpy. * ada/argv.c (__gnat_fill_arg, __gnat_fill_env): Same. gcc/c-family/ChangeLog: PR c/81117 * c-common.c (catenate_strings): Use memcpy instead of strncpy. * c-warn.c (sizeof_pointer_memaccess_warning): Handle arrays. * c.opt (-Wstringop-truncation): New option. gcc/fortran/ChangeLog: PR c/81117 * gcc/fortran/decl.c (build_sym): Use strcpy instead of strncpy. gcc/objc/ChangeLog: PR c/81117 * objc-encoding.c (encode_type): Use memcpy instead of strncpy. gcc/testsuite/ChangeLog: PR c/81117 * c-c++-common/Wsizeof-pointer-memaccess3.c: New test. * c-c++-common/Wstringop-overflow.c: Same. * c-c++-common/Wstringop-truncation.c: Same. * c-c++-common/Wsizeof-pointer-memaccess2.c: Adjust. * c-c++-common/attr-nonstring-2.c: New test. * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Adjust. * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same. * gcc.dg/torture/pr63554.c: Same. * gcc.dg/Walloca-1.c: Disable macro tracking. From-SVN: r254630
2017-08-30[62/77] Big machine_mode to scalar_int_mode replacementRichard Sandiford1-2/+2
This patch changes the types of various things from machine_mode to scalar_int_mode, in cases where (after previous patches) simply changing the type is enough on its own. The patch does nothing other than that. 2017-08-30 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> gcc/ * builtins.h (builtin_strncpy_read_str): Take a scalar_int_mode instead of a machine_mode. (builtin_memset_read_str): Likewise. * builtins.c (c_readstr): Likewise. (builtin_memcpy_read_str): Likewise. (builtin_strncpy_read_str): Likewise. (builtin_memset_read_str): Likewise. (builtin_memset_gen_str): Likewise. (expand_builtin_signbit): Use scalar_int_mode for local variables. * cfgexpand.c (convert_debug_memory_address): Take a scalar_int_mode instead of a machine_mode. * combine.c (simplify_if_then_else): Use scalar_int_mode for local variables. (make_extraction): Likewise. (try_widen_shift_mode): Take and return scalar_int_modes instead of machine_modes. * config/aarch64/aarch64.c (aarch64_libgcc_cmp_return_mode): Return a scalar_int_mode instead of a machine_mode. * config/avr/avr.c (avr_addr_space_address_mode): Likewise. (avr_addr_space_pointer_mode): Likewise. * config/cr16/cr16.c (cr16_unwind_word_mode): Likewise. * config/msp430/msp430.c (msp430_addr_space_pointer_mode): Likewise. (msp430_unwind_word_mode): Likewise. * config/spu/spu.c (spu_unwind_word_mode): Likewise. (spu_addr_space_pointer_mode): Likewise. (spu_addr_space_address_mode): Likewise. (spu_libgcc_cmp_return_mode): Likewise. (spu_libgcc_shift_count_mode): Likewise. * config/rl78/rl78.c (rl78_addr_space_address_mode): Likewise. (rl78_addr_space_pointer_mode): Likewise. (fl78_unwind_word_mode): Likewise. (rl78_valid_pointer_mode): Take a scalar_int_mode instead of a machine_mode. * config/alpha/alpha.c (vms_valid_pointer_mode): Likewise. * config/ia64/ia64.c (ia64_vms_valid_pointer_mode): Likewise. * config/mips/mips.c (mips_mode_rep_extended): Likewise. (mips_valid_pointer_mode): Likewise. * config/tilegx/tilegx.c (tilegx_mode_rep_extended): Likewise. * config/ft32/ft32.c (ft32_valid_pointer_mode): Likewise. (ft32_addr_space_pointer_mode): Return a scalar_int_mode instead of a machine_mode. (ft32_addr_space_address_mode): Likewise. * config/m32c/m32c.c (m32c_valid_pointer_mode): Take a scalar_int_mode instead of a machine_mode. (m32c_addr_space_pointer_mode): Return a scalar_int_mode instead of a machine_mode. (m32c_addr_space_address_mode): Likewise. * config/powerpcspe/powerpcspe.c (rs6000_abi_word_mode): Likewise. (rs6000_eh_return_filter_mode): Likewise. * config/rs6000/rs6000.c (rs6000_abi_word_mode): Likewise. (rs6000_eh_return_filter_mode): Likewise. * config/s390/s390.c (s390_libgcc_cmp_return_mode): Likewise. (s390_libgcc_shift_count_mode): Likewise. (s390_unwind_word_mode): Likewise. (s390_valid_pointer_mode): Take a scalar_int_mode rather than a machine_mode. * target.def (mode_rep_extended): Likewise. (valid_pointer_mode): Likewise. (addr_space.valid_pointer_mode): Likewise. (eh_return_filter_mode): Return a scalar_int_mode rather than a machine_mode. (libgcc_cmp_return_mode): Likewise. (libgcc_shift_count_mode): Likewise. (unwind_word_mode): Likewise. (addr_space.pointer_mode): Likewise. (addr_space.address_mode): Likewise. * doc/tm.texi: Regenerate. * dojump.c (prefer_and_bit_test): Take a scalar_int_mode rather than a machine_mode. (do_jump): Use scalar_int_mode for local variables. * dwarf2cfi.c (init_return_column_size): Take a scalar_int_mode rather than a machine_mode. * dwarf2out.c (convert_descriptor_to_mode): Likewise. (scompare_loc_descriptor_wide): Likewise. (scompare_loc_descriptor_narrow): Likewise. * emit-rtl.c (adjust_address_1): Use scalar_int_mode for local variables. * except.c (sjlj_emit_dispatch_table): Likewise. (expand_builtin_eh_copy_values): Likewise. * explow.c (convert_memory_address_addr_space_1): Likewise. Take a scalar_int_mode rather than a machine_mode. (convert_memory_address_addr_space): Take a scalar_int_mode rather than a machine_mode. (memory_address_addr_space): Use scalar_int_mode for local variables. * expmed.h (expand_mult_highpart_adjust): Take a scalar_int_mode rather than a machine_mode. * expmed.c (mask_rtx): Likewise. (init_expmed_one_conv): Likewise. (expand_mult_highpart_adjust): Likewise. (extract_high_half): Likewise. (expmed_mult_highpart_optab): Likewise. (expmed_mult_highpart): Likewise. (expand_smod_pow2): Likewise. (expand_sdiv_pow2): Likewise. (emit_store_flag_int): Likewise. (adjust_bit_field_mem_for_reg): Use scalar_int_mode for local variables. (extract_low_bits): Likewise. * expr.h (by_pieces_constfn): Take a scalar_int_mode rather than a machine_mode. * expr.c (pieces_addr::adjust): Likewise. (can_store_by_pieces): Likewise. (store_by_pieces): Likewise. (clear_by_pieces_1): Likewise. (expand_expr_addr_expr_1): Likewise. (expand_expr_addr_expr): Use scalar_int_mode for local variables. (expand_expr_real_1): Likewise. (try_casesi): Likewise. * final.c (shorten_branches): Likewise. * fold-const.c (fold_convert_const_int_from_fixed): Change the type of "mode" to machine_mode. * internal-fn.c (expand_arith_overflow_result_store): Take a scalar_int_mode rather than a machine_mode. (expand_mul_overflow): Use scalar_int_mode for local variables. * loop-doloop.c (doloop_modify): Likewise. (doloop_optimize): Likewise. * optabs.c (expand_subword_shift): Take a scalar_int_mode rather than a machine_mode. (expand_doubleword_shift_condmove): Likewise. (expand_doubleword_shift): Likewise. (expand_doubleword_clz): Likewise. (expand_doubleword_popcount): Likewise. (expand_doubleword_parity): Likewise. (expand_absneg_bit): Use scalar_int_mode for local variables. (prepare_float_lib_cmp): Likewise. * rtl.h (convert_memory_address_addr_space_1): Take a scalar_int_mode rather than a machine_mode. (convert_memory_address_addr_space): Likewise. (get_mode_bounds): Likewise. (get_address_mode): Return a scalar_int_mode rather than a machine_mode. * rtlanal.c (get_address_mode): Likewise. * stor-layout.c (get_mode_bounds): Take a scalar_int_mode rather than a machine_mode. * targhooks.c (default_mode_rep_extended): Likewise. (default_valid_pointer_mode): Likewise. (default_addr_space_valid_pointer_mode): Likewise. (default_eh_return_filter_mode): Return a scalar_int_mode rather than a machine_mode. (default_libgcc_cmp_return_mode): Likewise. (default_libgcc_shift_count_mode): Likewise. (default_unwind_word_mode): Likewise. (default_addr_space_pointer_mode): Likewise. (default_addr_space_address_mode): Likewise. * targhooks.h (default_eh_return_filter_mode): Likewise. (default_libgcc_cmp_return_mode): Likewise. (default_libgcc_shift_count_mode): Likewise. (default_unwind_word_mode): Likewise. (default_addr_space_pointer_mode): Likewise. (default_addr_space_address_mode): Likewise. (default_mode_rep_extended): Take a scalar_int_mode rather than a machine_mode. (default_valid_pointer_mode): Likewise. (default_addr_space_valid_pointer_mode): Likewise. * tree-ssa-address.c (addr_for_mem_ref): Use scalar_int_mode for local variables. * tree-ssa-loop-ivopts.c (get_shiftadd_cost): Take a scalar_int_mode rather than a machine_mode. * tree-switch-conversion.c (array_value_type): Use scalar_int_mode for local variables. * tree-vrp.c (simplify_float_conversion_using_ranges): Likewise. * var-tracking.c (use_narrower_mode): Take a scalar_int_mode rather than a machine_mode. Co-Authored-By: Alan Hayward <alan.hayward@arm.com> Co-Authored-By: David Sherwood <david.sherwood@arm.com> From-SVN: r251513
2017-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r243994