Commit Graph

1341 Commits

Author SHA1 Message Date
Aaron Sawdey
1e2d8575ac Additional small changes to support opaque modes
After building some larger codes using opaque types and some c++ codes
using opaque types it became clear I needed to go through and look for
places where opaque types and modes needed to be handled. A whole pile
of one-liners.

gcc/
	* typeclass.h: Add opaque_type_class.
	* builtins.c (type_to_class): Identify opaque type class.
	* dwarf2out.c (is_base_type): Handle opaque types.
	(gen_type_die_with_usage): Handle opaque types.
	* expr.c (count_type_elements): Opaque types should
	never have initializers.
	* ipa-devirt.c (odr_types_equivalent_p): No type-specific handling
	for opaque types is needed as it eventually checks the underlying
	mode which is what is important.
	* tree-streamer.c (record_common_node): Handle opaque types.
	* tree.c (type_contains_placeholder_1): Handle opaque types.
	(type_cache_hasher::equal): No additional comparison needed for
	opaque types.
gcc/c-family
	* c-pretty-print.c (c_pretty_printer::simple_type_specifier):
	Treat opaque types like other types.
	(c_pretty_printer::direct_abstract_declarator): Opaque types are
	supported types.
gcc/c
	* c-aux-info.c (gen_type): Support opaque types.
gcc/cp
	* error.c (dump_type): Handle opaque types.
	(dump_type_prefix): Handle opaque types.
	(dump_type_suffix): Handle opaque types.
	(dump_expr): Handle opaque types.
	* pt.c (tsubst): Allow opaque types in templates.
	(unify): Allow opaque types in templates.
	* typeck.c (structural_comptypes): Handle comparison
	of opaque types.
2020-11-21 07:37:06 -06:00
Roger Sayle
1be4878116 Fix middle-end/85811: Introduce tree_expr_maybe_non_p et al.
The motivation for this patch is PR middle-end/85811, a wrong-code
regression entitled "Invalid optimization with fmax, fabs and nan".
The optimization involves assuming max(x,y) is non-negative if (say)
y is non-negative, i.e. max(x,2.0).  Unfortunately, this is an invalid
assumption in the presence of NaNs.  Hence max(x,+qNaN), with IEEE fmax
semantics will always return x even though the qNaN is non-negative.
Worse, max(x,2.0) may return a negative value if x is -sNaN.

I'll quote Joseph Myers (many thanks) who describes things clearly as:
> (a) When both arguments are NaNs, the return value should be a qNaN,
> but sometimes it is an sNaN if at least one argument is an sNaN.
> (b) Under TS 18661-1 semantics, if either argument is an sNaN then the
> result should be a qNaN (whereas if one argument is a qNaN and the
> other is not a NaN, the result should be the non-NaN argument).
> Various implementations treat sNaNs like qNaNs here.

Under this logic, the tree_expr_nonnegative_p for IEEE fmax should be:

    CASE_CFN_FMAX:
    CASE_CFN_FMAX_FN:
      /* Usually RECURSE (arg0) || RECURSE (arg1) but NaNs complicate
         things.  In the presence of sNaNs, we're only guaranteed to be
         non-negative if both operands are non-negative.  In the presence
         of qNaNs, we're non-negative if either operand is non-negative
         and can't be a qNaN, or if both operands are non-negative.  */
      if (tree_expr_maybe_signaling_nan_p (arg0) ||
          tree_expr_maybe_signaling_nan_p (arg1))
        return RECURSE (arg0) && RECURSE (arg1);
      return RECURSE (arg0) ? (!tree_expr_maybe_nan_p (arg0)
                              || RECURSE (arg1))
                            : (RECURSE (arg1)
                              && !tree_expr_maybe_nan_p (arg1));

Which indeed resolves the wrong code in the PR.  The infrastructure that
makes this possible are the two new functions tree_expr_maybe_nan_p and
tree_expr_maybe_signaling_nan_p which test whether a value may potentially
be a NaN or a signaling NaN respectively.  In fact, this patch adds seven
new predicates to the middle-end:

bool tree_expr_finite_p (const_tree);
bool tree_expr_infinite_p (const_tree);
bool tree_expr_maybe_infinite_p (const_tree);
bool tree_expr_signaling_nan_p (const_tree);
bool tree_expr_maybe_signaling_nan_p (const_tree);
bool tree_expr_nan_p (const_tree);
bool tree_expr_maybe_nan_p (const_tree);

These functions correspond to the "must" and "may" operators in modal logic,
and allow us to triage expressions in the middle-end; definitely a NaN,
definitely not a NaN, and unknown at compile-time, etc.  A prime example of
the utility of these functions is that a IEEE floating point value promoted
from an integer type can't be a NaN or infinite.  Hence (double)i+0.0 where
i is an integer can be simplified to (double)i even with -fsignaling-nans.
Currently in GCC optimizations are enabled/disabled based on whether the
expression's type supports NaNs or sNaNs; with these new predicates they
can be controlled by whether the actual operands may or may not be NaNs.

Having added these extremely useful helper functions to the middle-end,
I couldn't help by use then in a few places in fold-const.c, builtins.c
and match.pd.  In the near term, these can/should be used in places
where the tree optimizers test for HONOR_NANS, HONOR_INFINITIES or
HONOR_SNANS, or explicitly test whether a REAL_CST is a NaN or Inf.
In the longer term (I'm not volunteering) these predicates could perhaps
be hooked into the middle-end's SSA chaining and/or VRP machinery,
allowing finiteness to propagated around the CFG, much like we
currently propagate value ranges.

This patch has been tested on x86_64-pc-linux-gnu with a "make bootstrap"
and "make -k check".
Ok for mainline?

2020-08-15  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	PR middle-end/85811
	* fold-const.c (tree_expr_finite_p): New function to test whether
	a tree expression must be finite, i.e. not a FP NaN or infinity.
	(tree_expr_infinite_p):  New function to test whether a tree
	expression must be infinite, i.e. a FP infinity.
	(tree_expr_maybe_infinite_p): New function to test whether a tree
	expression may be infinite, i.e. a FP infinity.
	(tree_expr_signaling_nan_p): New function to test whether a tree
	expression must evaluate to a signaling NaN (sNaN).
	(tree_expr_maybe_signaling_nan_p): New function to test whether a
	tree expression may be a signaling NaN (sNaN).
	(tree_expr_nan_p): New function to test whether a tree expression
	must evaluate to a (quiet or signaling) NaN.
	(tree_expr_maybe_nan_p): New function to test whether a tree
	expression me be a (quiet or signaling) NaN.

	(tree_binary_nonnegative_warnv_p) [MAX_EXPR]: In the presence
	of NaNs, MAX_EXPR is only guaranteed to be non-negative, if both
	operands are non-negative.
	(tree_call_nonnegative_warnv_p) [CASE_CFN_FMAX,CASE_CFN_FMAX_FN]:
	In the presence of signaling NaNs, fmax is only guaranteed to be
	non-negative if both operands are negative.  In the presence of
	quiet NaNs, fmax is non-negative if either operand is non-negative
	and not a qNaN, or both operands are non-negative.

	* fold-const.h (tree_expr_finite_p, tree_expr_infinite_p,
	tree_expr_maybe_infinite_p, tree_expr_signaling_nan_p,
	tree_expr_maybe_signaling_nan_p, tree_expr_nan_p,
	tree_expr_maybe_nan_p): Prototype new functions here.

	* builtins.c (fold_builtin_classify) [BUILT_IN_ISINF]: Fold to
	a constant if argument is known to be (or not to be) an Infinity.
	[BUILT_IN_ISFINITE]: Fold to a constant if argument is known to
	be (or not to be) finite.
	[BUILT_IN_ISNAN]: Fold to a constant if argument is known to be
	(or not to be) a NaN.
	(fold_builtin_fpclassify): Check tree_expr_maybe_infinite_p and
	tree_expr_maybe_nan_p instead of HONOR_INFINITIES and HONOR_NANS
	respectively.
	(fold_builtin_unordered_cmp): Fold UNORDERED_EXPR to a constant
	when its arguments are known to be (or not be) NaNs.  Check
	tree_expr_maybe_nan_p instead of HONOR_NANS when choosing between
	unordered and regular forms of comparison operators.

	* match.pd (ordered(x,y)->true/false): Constant fold ORDERED_EXPR
	if its operands are known to be (or not to be) NaNs.
	(unordered(x,y)->true/false): Constant fold UNORDERED_EXPR if its
	operands are known to be (or not to be) NaNs.
	(sqrt(x)*sqrt(x)->x): Check tree_expr_maybe_signaling_nan_p instead
	of HONOR_SNANS.

gcc/testsuite/ChangeLog
	PR middle-end/85811
	* gcc.dg/pr85811.c: New test.
	* gcc.dg/fold-isfinite-1.c: New test.
	* gcc.dg/fold-isfinite-2.c: New test.
	* gcc.dg/fold-isinf-1.c: New test.
	* gcc.dg/fold-isinf-2.c: New test.
	* gcc.dg/fold-isnan-1.c: New test.
	* gcc.dg/fold-isnan-2.c: New test.
2020-11-18 15:09:46 -07:00
Jakub Jelinek
6fcc3cac42 openmp: Implement allocate clause in omp lowering.
For now, task/taskloop constructs aren't handled and C/C++ array reductions
and reductions with task or inscan modifiers need further work.
Instead of calling omp_alloc/omp_free (where the former doesn't have
alignment argument and omp_aligned_alloc is 5.1 only feature), this calls
GOMP_alloc/GOMP_free, so that the library can fail if it would fall back
into NULL (exception is zero length allocations).

2020-11-12  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* builtin-types.def (BT_FN_PTR_SIZE_SIZE_PTRMODE): New function type.
	* omp-builtins.def (BUILT_IN_GOACC_DECLARE): Move earlier.
	(BUILT_IN_GOMP_ALLOC, BUILT_IN_GOMP_FREE): New builtins.
	* gimplify.c (gimplify_scan_omp_clauses): Force allocator into a
	decl if it is not NULL, INTEGER_CST or decl.
	(gimplify_adjust_omp_clauses): Clear GOVD_EXPLICIT on explicit clauses
	which are being removed.  Remove allocate clauses for variables not seen
	if they are private, firstprivate or linear too.  Call
	omp_notice_variable on the allocator otherwise.
	(gimplify_omp_for): Handle iterator vars mentioned in allocate clauses
	similarly to non-is_gimple_reg iterators.
	* omp-low.c (struct omp_context): Add allocate_map field.
	(delete_omp_context): Delete it.
	(scan_sharing_clauses): Fill it from allocate clauses.  Remove it
	if mentioned also in shared clause.
	(lower_private_allocate): New function.
	(lower_rec_input_clauses): Handle allocate clause for privatized
	variables, except for task/taskloop, C/C++ array reductions for now
	and task/inscan variables.
	(lower_send_shared_vars): Don't consider variables in allocate_map
	as shared.
	* omp-expand.c (expand_omp_for_generic, expand_omp_for_static_nochunk,
	expand_omp_for_static_chunk): Use expand_omp_build_assign instead of
	gimple_build_assign + gsi_insert_after.
	* builtins.c (builtin_fnspec): Handle BUILTIN_GOMP_ALLOC and
	BUILTIN_GOMP_FREE.
	* tree-ssa-ccp.c (evaluate_stmt): Handle BUILTIN_GOMP_ALLOC.
	* tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Handle
	BUILTIN_GOMP_ALLOC.
	(mark_all_reaching_defs_necessary_1): Handle BUILTIN_GOMP_ALLOC
	and BUILTIN_GOMP_FREE.
	(propagate_necessity): Likewise.
gcc/fortran/
	* f95-lang.c (ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST):
	Define.
	(gfc_init_builtin_functions): Add alloc_size and warn_unused_result
	attributes to __builtin_GOMP_alloc.
	* types.def (BT_PTRMODE): New primitive type.
	(BT_FN_VOID_PTR_PTRMODE, BT_FN_PTR_SIZE_SIZE_PTRMODE): New function
	types.
libgomp/
	* libgomp.map (GOMP_alloc, GOMP_free): Export at GOMP_5.0.1.
	* omp.h.in (omp_alloc): Add malloc and alloc_size attributes.
	* libgomp_g.h (GOMP_alloc, GOMP_free): Declare.
	* allocator.c (omp_aligned_alloc): New for now static function,
	add alignment argument and handle it.
	(omp_alloc): Reimplement using omp_aligned_alloc.
	(GOMP_alloc, GOMP_free): New functions.
	(omp_free): Add ialias.
	* testsuite/libgomp.c-c++-common/allocate-1.c: New test.
	* testsuite/libgomp.c++/allocate-1.C: New test.
2020-11-12 21:38:04 +01:00
Jan Hubicka
071a31a533 Add support for copy specifiers in fnspec
* attr-fnspec.h: Update topleve comment.
	(attr_fnspec::arg_direct_p): Accept 1...9.
	(attr_fnspec::arg_maybe_written_p): Reject 1...9.
	(attr_fnspec::arg_copied_to_arg_p): New member function.
	* builtins.c (builtin_fnspec): Update fnspec of block copy.
	* tree-ssa-alias.c (attr_fnspec::verify): Update.
2020-11-12 14:56:40 +01:00
Martin Sebor
bdf6524bc0 PR middle-end/97556 - ICE on excessively large index into a multidimensional array
gcc/ChangeLog:

	PR middle-end/97556
	* builtins.c (access_ref::add_offset): Cap offset lower bound
	to at most the the upper bound.

gcc/testsuite/ChangeLog:

	PR middle-end/97556
	* gcc.dg/Warray-bounds-70.c: New test.
2020-10-30 13:04:29 -06:00
Jan Hubicka
b53f709d92 Add string builtins to builtin_fnspec
* builtins.c (builtin_fnspec): Add bzero, memcmp, memcmp_eq, bcmp,
	strncmp, strncmp_eq, strncasecmp, rindex, strlen, strlnen, strcasecmp,
	strcspn, strspn, strcmp, strcmp_eq.
2020-10-27 09:01:41 +01:00
Jan Hubicka
4f8cfb4288 Extend builtin fnspecs
* attr-fnspec.h: Update toplevel comment.
	(attr_fnspec::attr_fnspec): New constructor.
	(attr_fnspec::arg_read_p,
	attr_fnspec::arg_written_p,
	attr_fnspec::arg_access_size_given_by_arg_p,
	attr_fnspec::arg_single_access_p
	attr_fnspec::loads_known_p
	attr_fnspec::stores_known_p,
	attr_fnspec::clobbers_errno_p): New member functions.
	(gimple_call_fnspec): Declare.
	(builtin_fnspec): Declare.
	* builtins.c: Include attr-fnspec.h
	(builtin_fnspec): New function.
	* builtins.def (BUILT_IN_MEMCPY): Do not specify RET1 fnspec.
	(BUILT_IN_MEMMOVE): Do not specify RET1 fnspec.
	(BUILT_IN_MEMSET): Do not specify RET1 fnspec.
	(BUILT_IN_STRCAT): Do not specify RET1 fnspec.
	(BUILT_IN_STRCPY): Do not specify RET1 fnspec.
	(BUILT_IN_STRNCAT): Do not specify RET1 fnspec.
	(BUILT_IN_STRNCPY): Do not specify RET1 fnspec.
	(BUILT_IN_MEMCPY_CHK): Do not specify RET1 fnspec.
	(BUILT_IN_MEMMOVE_CHK): Do not specify RET1 fnspec.
	(BUILT_IN_MEMSET_CHK): Do not specify RET1 fnspec.
	(BUILT_IN_STRCAT_CHK): Do not specify RET1 fnspec.
	(BUILT_IN_STRCPY_CHK): Do not specify RET1 fnspec.
	(BUILT_IN_STRNCAT_CHK): Do not specify RET1 fnspec.
	(BUILT_IN_STRNCPY_CHK): Do not specify RET1 fnspec.
	* gimple.c (gimple_call_fnspec): Return attr_fnspec.
	(gimple_call_arg_flags): Update.
	(gimple_call_return_flags): Update.
	* tree-ssa-alias.c (check_fnspec): New function.
	(ref_maybe_used_by_call_p_1): Use fnspec for builtin handling.
	(call_may_clobber_ref_p_1): Likewise.
	(attr_fnspec::verify): Update verifier.
	* calls.c (decl_fnspec): New function.
	(decl_return_flags): Use it.
2020-10-26 20:22:16 +01:00
Martin Sebor
14d83c6f58 PR middle-end/97391 - bogus -Warray-bounds accessing a multidimensional array parameter
gcc/ChangeLog:

	PR middle-end/97391
	* builtins.c (gimple_parm_array_size): Peel off one less layer
	of array types.

gcc/testsuite/ChangeLog:

	PR middle-end/97391
	* gcc.dg/Warray-bounds-68.c: New test.
2020-10-14 15:36:24 -06:00
Alexandre Oliva
455c3d2efc mathfn_built_in_type case type fix
Martin Liška reported warnings about type mismatches in the cases in
the recently-introduced mathfn_built_in_type.  This patch adjusts the
macros to use the combined_fn enumerators rather than the
(currently same-numbered) built_in_function ones.

for  gcc/ChangeLog

	* builtins.c (mathfn_built_in_type): Use CFN_ enumerators.
2020-10-12 18:55:40 -03:00
Martin Sebor
83685efd5f Generalize compute_objsize to return maximum size/offset instead of failing (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-12 09:05:55 -06:00
Martin Sebor
de05c19d5f Correct handling of indices into arrays with elements larger than 1 (PR 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-12 09:04:49 -06:00
Alexandre Oliva
a500588aa5 take type from intrinsic in sincos pass
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-08 17:12:18 -03:00
Aldy Hernandez
f529999282 Convert sprintf/strlen passes to value query class.
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-10-01 17:11:17 +02:00
Tom de Vries
bae974e637 [nvptx] Add type arg to TARGET_LIBC_HAS_FUNCTION
GCC has a target hook TARGET_LIBC_HAS_FUNCTION, which tells the compiler
which functions it can expect to be present in libc.

The default target hook does not include the sincos functions.

The nvptx port of newlib does include sincos and sincosf, but not sincosl.

The target hook TARGET_LIBC_HAS_FUNCTION does not distinguish between sincos,
sincosf and sincosl, so if we enable it for the sincos functions, then for
test.c:
...
long double x, a, b;
int main (void) {
  x = 0.5;
  a = sinl (x);
  b = cosl (x);
  printf ("a: %f\n", (double)a);
  printf ("b: %f\n", (double)b);
  return 0;
}
...
we introduce a regression:
...
$ gcc test.c -lm -O2
unresolved symbol sincosl
collect2: error: ld returned 1 exit status
...

Add a type argument to target hook TARGET_LIBC_HAS_FUNCTION_TYPE, and use it
in nvptx_libc_has_function_type to enable sincos and sincosf, but not sincosl.

Build and reg-tested on x86_64-linux.

Build and tested on nvptx.

gcc/ChangeLog:

2020-09-28  Tobias Burnus  <tobias@codesourcery.com>
	    Tom de Vries  <tdevries@suse.de>

	* builtins.c (expand_builtin_cexpi, fold_builtin_sincos): Update
	targetm.libc_has_function call.
	* builtins.def (DEF_C94_BUILTIN, DEF_C99_BUILTIN, DEF_C11_BUILTIN):
	(DEF_C2X_BUILTIN, DEF_C99_COMPL_BUILTIN, DEF_C99_C90RES_BUILTIN):
	Same.
	* config/darwin-protos.h (darwin_libc_has_function): Update prototype.
	* config/darwin.c (darwin_libc_has_function): Add arg.
	* config/linux-protos.h (linux_libc_has_function): Update prototype.
	* config/linux.c (linux_libc_has_function): Add arg.
	* config/i386/i386.c (ix86_libc_has_function): Update
	targetm.libc_has_function call.
	* config/nvptx/nvptx.c (nvptx_libc_has_function): New function.
	(TARGET_LIBC_HAS_FUNCTION): Redefine to nvptx_libc_has_function.
	* convert.c (convert_to_integer_1): Update targetm.libc_has_function
	call.
	* match.pd: Same.
	* target.def (libc_has_function): Add arg.
	* doc/tm.texi: Regenerate.
	* targhooks.c (default_libc_has_function, gnu_libc_has_function)
	(no_c99_libc_has_function): Add arg.
	* targhooks.h (default_libc_has_function, no_c99_libc_has_function)
	(gnu_libc_has_function): Update prototype.
	* tree-ssa-math-opts.c (pass_cse_sincos::execute): Update
	targetm.libc_has_function call.

gcc/fortran/ChangeLog:

2020-09-30  Tom de Vries  <tdevries@suse.de>

	* f95-lang.c (gfc_init_builtin_functions):  Update
	targetm.libc_has_function call.
2020-09-30 14:36:56 +02:00
Martin Sebor
6edc8f5bfe Handle DECLs and EXPRESSIONs consistently (PR middle-end/97175).
gcc/ChangeLog:

	PR middle-end/97175
	* builtins.c (maybe_warn_for_bound): Handle both DECLs and EXPRESSIONs
	in pad->dst.ref, same is pad->src.ref.

gcc/testsuite/ChangeLog:

	PR middle-end/97175
	* gcc.dg/Wstringop-overflow-44.c: New test.
2020-09-23 15:10:20 -06:00
Martin Sebor
baad4c48a8 Extend -Wstringop-overflow to detect out-of-bounds accesses to array parameters.
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-09-19 17:37:05 -06:00
Martin Sebor
f36a8168f0 Move/correct offset adjustment (PR middle-end/96903).
Resolves:
PR middle-end/96903 - bogus warning on memcpy at negative offset from array end

gcc/ChangeLog:

	PR middle-end/96903
	* builtins.c (compute_objsize): Remove incorrect offset adjustment.
	(compute_objsize): Adjust offset range here instead.

gcc/testsuite/ChangeLog:

	PR middle-end/96903
	* gcc.dg/Wstringop-overflow-42.c:: Add comment.
	* gcc.dg/Wstringop-overflow-43.c: New test.
2020-09-11 09:42:29 -06:00
Martin Sebor
0c344a649d Use the determined lower bound of the range of offsets in a PLUS_EXPR.
gcc/ChangeLog:

	* builtins.c (compute_objsize):  Only replace the upper bound
	of a POINTER_PLUS offset when it's less than the lower bound.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wstringop-overflow.c: Remove xfails.
	* gcc.dg/Wstringop-overflow-42.c: New test.
	* gcc.dg/Wstringop-overread-4.c: New test.
2020-09-01 16:03:25 -06:00
Martin Sebor
6ccadc4c04 Use get_size_range instead of get_range to obtain range of valid sizes.
gcc/ChangeLog:

	* builtins.c (access_ref::access_ref): Call get_size_range instead
	of get_range.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wstringop-overread-3.c: New test.
2020-08-30 15:11:48 -06:00
Martin Sebor
d14c547abd Add -Wstringop-overread for reading past the end by string functions.
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-08-28 13:18:28 -06:00
Martin Sebor
866626efd7 PR tree-optimization/78257 - missing memcmp optimization with constant arrays
gcc/ChangeLog:

	PR middle-end/78257
	* builtins.c (expand_builtin_memory_copy_args): Rename called function.
	(expand_builtin_stpcpy_1): Remove argument from call.
	(expand_builtin_memcmp): Rename called function.
	(inline_expand_builtin_bytecmp): Same.
	* expr.c (convert_to_bytes): New function.
	(constant_byte_string): New function (formerly string_constant).
	(string_constant): Call constant_byte_string.
	(byte_representation): New function.
	* expr.h (byte_representation): Declare.
	* fold-const-call.c (fold_const_call): Rename called function.
	* fold-const.c (c_getstr): Remove an argument.
	(getbyterep): Define a new function.
	* fold-const.h (c_getstr): Remove an argument.
	(getbyterep): Declare a new function.
	* gimple-fold.c (gimple_fold_builtin_memory_op): Rename callee.
	(gimple_fold_builtin_string_compare): Same.
	(gimple_fold_builtin_memchr): Same.

gcc/testsuite/ChangeLog:

	PR middle-end/78257
	* gcc.dg/memchr.c: New test.
	* gcc.dg/memcmp-2.c: New test.
	* gcc.dg/memcmp-3.c: New test.
	* gcc.dg/memcmp-4.c: New test.
2020-08-14 17:11:53 -06:00
Aldy Hernandez
f21757eb8f Remove ad-hoc range canonicalization from determine_block_size.
Anti ranges of ~[MIN,X] are automatically canonicalized to [X+1,MAX],
at creation time.  There is no need to handle them specially.

Tested by adding a gcc_unreachable and bootstrapping/testing.

gcc/ChangeLog:

	* builtins.c (determine_block_size): Remove ad-hoc range canonicalization.
2020-08-04 07:23:41 +02:00
Martin Sebor
d5803b9876 Correct handling of constant representations containing embedded nuls.
Resolves:
PR middle-end/95189 - memcmp being wrongly stripped like strcm
PR middle-end/95886 - suboptimal memcpy with embedded zero bytes

gcc/ChangeLog:

	PR middle-end/95189
	PR middle-end/95886
	* builtins.c (inline_expand_builtin_string_cmp): Rename...
	(inline_expand_builtin_bytecmp): ...to this.
	(builtin_memcpy_read_str): Don't expect data to be nul-terminated.
	(expand_builtin_memory_copy_args): Handle object representations
	with embedded nul bytes.
	(expand_builtin_memcmp): Same.
	(expand_builtin_strcmp): Adjust call to naming change.
	(expand_builtin_strncmp): Same.
	* expr.c (string_constant): Create empty strings with nonzero size.
	* fold-const.c (c_getstr): Rename locals and update comments.
	* tree.c (build_string): Accept null pointer argument.
	(build_string_literal): Same.
	* tree.h (build_string): Provide a default.
	(build_string_literal): Same.

gcc/testsuite/ChangeLog:

	PR middle-end/95189
	PR middle-end/95886
	* gcc.dg/memcmp-pr95189.c: New test.
	* gcc.dg/strncmp-3.c: New test.
	* gcc.target/i386/memcpy-pr95886.c: New test.
2020-07-20 12:08:58 -06:00
Jakub Jelinek
410675cb63 builtins: Avoid useless char/short -> int promotions before atomics [PR96176]
As mentioned in the PR, we generate a useless movzbl insn before lock cmpxchg.
The problem is that the builtin for the char/short cases has the arguments
promoted to int and combine gives up, because the instructions have
MEM_VOLATILE_P arguments and recog in that case doesn't recognize anything
when volatile_ok is false, and nothing afterwards optimizes the
(reg:SI a) = (zero_extend:SI (reg:QI a))
... (subreg:QI (reg:SI a) 0) ...

The following patch fixes it at expansion time, we already have a function
that is meant to undo the promotion, so this just adds the very common case
to that.

2020-07-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/96176
	* builtins.c: Include gimple-ssa.h, tree-ssa-live.h and
	tree-outof-ssa.h.
	(expand_expr_force_mode): If exp is a SSA_NAME with different mode
	from MODE and get_gimple_for_ssa_name is a cast from MODE, use the
	cast's rhs.

	* gcc.target/i386/pr96176.c: New test.
2020-07-15 11:26:22 +02:00
Martin Sebor
5acc654e38 Avoid warning for memset writing over multiple members.
Resolves:
PR middle-end/95667 - unintended warning for memset writing across multiple members
PR middle-end/92814 - missing -Wstringop-overflow writing into a dynamically allocated flexible array member

gcc/ChangeLog:

	PR middle-end/95667
	PR middle-end/92814
	* builtins.c (compute_objsize): Remove call to
	compute_builtin_object_size and instead compute conservative sizes
	directly here.

gcc/testsuite/ChangeLog:

	PR middle-end/95667
	PR middle-end/92814
	* gcc.dg/Wstringop-overflow-25.c: Remove xfails.
	* gcc.dg/Wstringop-overflow-39.c: New test.
2020-06-18 12:00:36 -06:00
Martin Sebor
a2c2cee92e PR middle-end/95353 - spurious -Wstringop-overflow writing to a trailing 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-10 12:02:12 -06:00
Martin Sebor
b825a22890 Implement a solution for PR middle-end/10138 and PR middle-end/95136.
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-06-04 16:08:32 -06:00
Eric Botcazou
fe7ebef7fe Add support for __builtin_bswap128
This patch introduces a new builtin named __builtin_bswap128 on targets
where TImode is supported, i.e. 64-bit targets only in practice.  The
implementation simply reuses the existing double word path in optab, so
no routine is added to libgcc (which means that you get two calls to
_bswapdi2 in the worst case).

gcc/ChangeLog:

	* builtin-types.def (BT_UINT128): New primitive type.
	(BT_FN_UINT128_UINT128): New function type.
	* builtins.def (BUILT_IN_BSWAP128): New GCC builtin.
	* doc/extend.texi (__builtin_bswap128): Document it.
	* builtins.c (expand_builtin): Deal with BUILT_IN_BSWAP128.
	(is_inexpensive_builtin): Likewise.
	* fold-const-call.c (fold_const_call_ss): Likewise.
	* fold-const.c (tree_call_nonnegative_warnv_p): Likewise.
	* tree-ssa-ccp.c (evaluate_stmt): Likewise.
	* tree-vect-stmts.c (vect_get_data_ptr_increment): Likewise.
	(vectorizable_call): Likewise.
	* optabs.c (expand_unop): Always use the double word path for it.
	* tree-core.h (enum tree_index): Add TI_UINT128_TYPE.
	* tree.h (uint128_type_node): New global type.
	* tree.c (build_common_tree_nodes): Build it if TImode is supported.

gcc/testsuite/ChangeLog:

	* gcc.dg/builtin-bswap-10.c: New test.
	* gcc.dg/builtin-bswap-11.c: Likewise.
	* gcc.dg/builtin-bswap-12.c: Likewise.
	* gcc.target/i386/builtin-bswap-5.c: Likewise.
2020-05-28 00:33:04 +02:00
Jakub Jelinek
7afa3b8291 expand: Don't depend on warning flags in code generation of strnlen [PR94189]
The following testcase FAILs with -O2 -fcompare-debug, but the reason isn't
that we'd emit different code based on -g or non-debug, but rather that
we emit different code depending on whether -w is used or not (or e.g.
-Wno-stringop-overflow or whether some other pass emitted some other warning
already on the call).

Code generation shouldn't depend on whether we emit a warning or not if at
all possible.

The following patch punts (i.e. doesn't optimize the strnlen call to a
constant value) if we would emit the warning if it was enabled.
In the PR there is an alternate patch which does optimize the strnlen call
no matter if we emit the warning or not, though I think I prefer the version
below, e.g. the strnlen call might be crossing field boundaries, which is in
strict reading undefined, but I'd be afraid people do that in the real
world programs.

2020-03-17  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/94189
	* builtins.c (expand_builtin_strnlen): Do return NULL_RTX if we would
	emit a warning if it was enabled and don't depend on TREE_NO_WARNING
	for code-generation.

	* gcc.dg/pr94189.c: New test.
2020-03-17 10:42:35 +01:00
Martin Sebor
2b5d3dc22c PR middle-end/93200 - spurious -Wstringop-overflow due to assignment vectorization to multiple members
PR middle-end/93200 - spurious -Wstringop-overflow due to assignment vectorization to multiple members
PR fortran/92956 - 'libgomp.fortran/examples-4/async_target-2.f90' fails with offloading due to bogus -Wstringop-overflow warning

gcc/testsuite/ChangeLog:

	PR middle-end/93200
	* gcc.dg/Wstringop-overflow-30.c: New test.

gcc/ChangeLog:

	PR middle-end/93200
	PR fortran/92956
	* builtins.c (compute_objsize): Avoid handling MEM_REFs of vector type.

From-SVN: r280041
2020-01-09 04:59:41 -07:00
Jakub Jelinek
8d9254fc8a Update copyright years.
From-SVN: r279813
2020-01-01 12:51:42 +01:00
Martin Sebor
126036359a PR middle-end/92952 - gfortran.dg/lto/pr87689 FAILs at -O2
gcc/ChangeLog:
	* builtins.c (compute_objsize): Adjust offset by the array low bound.

From-SVN: r279445
2019-12-16 15:24:15 -07:00
Martin Sebor
ef29b12cfb PR middle-end/91582 - missing heap overflow detection for strcpy
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-13 17:52:46 -07:00
Martin Sebor
f7d86b5ca8 builtins.c (compute_objsize): Add an argument and set it to offset into destination.
gcc/ChangeLog:

	* builtins.c (compute_objsize): Add an argument and set it to offset
	into destination.
	* builtins.h (compute_objsize): Add an argument.
	* tree-object-size.c (addr_object_size): Add an argument and set it
	to offset into destination.
	(compute_builtin_object_size): Same.
	* tree-object-size.h (compute_builtin_object_size): Add an argument.
	* tree-ssa-strlen.c (get_addr_stridx): Add an argument and set it
	to offset into destination.
	(maybe_warn_overflow): New function.
	(handle_store): Call maybe_warn_overflow to issue warnings.

gcc/testsuite/ChangeLog:

	* c-c++-common/Wstringop-overflow-2.c: Adjust text of expected messages.
	* g++.dg/warn/Wstringop-overflow-3.C: Same.
	* gcc.dg/Wstringop-overflow-17.c: Same.

From-SVN: r279248
2019-12-11 12:50:43 -07:00
Jakub Jelinek
a6ae300f9a re PR tree-optimization/92891 (ice in decompose, at wide-int.h:984)
PR tree-optimization/92891
	* builtins.c (gimple_call_alloc_size): Convert size to sizetype
	before returning it.

	* gcc.c-torture/compile/pr92891.c: New test.

From-SVN: r279205
2019-12-11 00:49:40 +01:00
Martin Sebor
268209f3a0 PR middle-end/91582 - missing heap overflow detection for strcpy
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-12-04 18:28:11 -07:00
Tobias Burnus
90ca6847bb PR 92463 - Cleanups due to minimum MPFR version bump to 3.1.0
PR middle-end/92463
        * configure.ac: Use MPFR_RNDN instead of GMP's MP_RNDN.
        * configure: Regenerate

        gcc/
        PR middle-end/92463
        * builtins.c (do_mpfr_ckconv, do_mpc_ckconv, do_mpfr_remquo,
        do_mpfr_lgamma_r, do_mpc_arg2): Use MPFR_RNDx instead of GMP_RNDx,
        mpfr_rnd_t instead of mp_rnd_t.
        * fold-const-call.c (do_mpfr_ckconv, do_mpfr_arg1, do_mpfr_sincos,
        do_mpfr_arg2, do_mpfr_arg3, do_mpc_arg1, do_mpc_arg2): Likewise.
        * gimple-ssa-sprintf.c (format_floating_max, format_floating):
        Use mpfr_exp_t instead of mp_exp_t.
        * real.c (real_from_string, dconst_e_ptr, dconst_sqrt2_ptr): Use
        MPFR_RNDx instead of GMP_RNDx.
        * realmpfr.c (real_from_mpfr, mpfr_from_real): Use mpfr_rnd_t and
        mpfr_exp_t instead mp_rnd_t and mp_exp_t, respectively.
        * realmpfr.h (real_from_mpfr, mpfr_from_real): Use mpfr_rnd_t instead
        of mp_rnd_t and remove MPFR_RNDx poisoning.
        * ubsan.c (ubsan_instrument_float_cast): MPFR_RNDx instead of GMP_RNDx.

        fortran/
        PR middle-end/92463
        * arith.c (gfc_check_real_range): Replace mp_exp_t by mpfr_exp_t.

From-SVN: r278761
2019-11-27 10:16:24 +01:00
Martin Sebor
54aa6b58fe PR middle-end/83859 - attributes to associate pointer arguments and sizes
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-22 10:14:17 -07:00
Martin Sebor
b5338fb359 PR middle-end/88226 - missing warning on fprintf, fputs, and puts with an 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-11-22 09:47:22 -07:00
Richard Biener
3e00ba47b9 re PR c/92088 (aggregates with VLAs and nested functions are broken)
2019-11-20  Richard Biener  <rguenther@suse.de>

	PR c/92088
	c/
	* c-decl.c (grokdeclarator): Prevent inlining of nested
	function with VLA arguments.

	* builtins.c (compute_objsize): Deal with VLAs.

	* gcc.dg/torture/pr92088-1.c: New testcase.
	* gcc.dg/torture/pr92088-2.c: Likewise.

From-SVN: r278477
2019-11-20 07:33:19 +00:00
Joseph Myers
00be2a5f39 Add C2x *_NORM_MAX constants to <float.h>.
C2x adds <float.h> constants FLT_NORM_MAX, DBL_NORM_MAX and
LDBL_NORM_MAX.  These are for the maximum "normalized" finite
floating-point number, where the given definition of normalized is
that all possible values with MANT_DIG significand digits (leading one
not zero) can be represented with that exponent.  The effect of that
definition is that these macros are the same as the corresponding MAX
macros for all formats except IBM long double, where the NORM_MAX
value has exponent 1 smaller than the MAX one so that all 106 digits
can be 1.

This patch adds those macros to GCC.  They are only defined for float,
double and long double; C2x does not include such macros for DFP
types, and while the integration of TS 18661-3 into C2x has not yet
occurred, the draft proposed text does not add them for the _FloatN /
_FloatNx types (where they would always be the same as the MAX
macros).

Bootstrapped with no regressions on x86_64-pc-linux-gnu.  Also tested
compilation of the new test for powerpc-linux-gnu to confirm the check
of LDBL_NORM_MAX in the IBM long double case does get properly
optimized out.

gcc:
	* ginclude/float.c [__STDC_VERSION__ > 201710L] (FLT_NORM_MAX,
	DBL_NORM_MAX, LDBL_NORM_MAX): Define.
	* real.c (get_max_float): Add norm_max argument.
	* real.h (get_max_float): Update prototype.
	* builtins.c (fold_builtin_interclass_mathfn): Update calls to
	get_max_float.

gcc/c-family:
	* c-cppbuiltin.c (builtin_define_float_constants): Also define
	NORM_MAX constants.  Update call to get_max_float.
	(LAZY_HEX_FP_VALUES_CNT): Update value to include NORM_MAX
	constants.

gcc/d:
	* d-target.cc (define_float_constants): Update call to
	get_max_float.

gcc/testsuite:
	* gcc.dg/c11-float-3.c, gcc.dg/c2x-float-1.c: New tests.

From-SVN: r278145
2019-11-13 15:25:15 +00:00
Martin Liska
0c29cac4a8 Remove gcc/params.* files.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* Makefile.in: Remove PARAMS_H and params.list
	and params.options.
	* params-enum.h: Remove.
	* params-list.h: Remove.
	* params-options.h: Remove.
	* params.c: Remove.
	* params.def: Remove.
	* params.h: Remove.
	* asan.c: Do not include params.h.
	* auto-profile.c: Likewise.
	* bb-reorder.c: Likewise.
	* builtins.c: Likewise.
	* cfgcleanup.c: Likewise.
	* cfgexpand.c: Likewise.
	* cfgloopanal.c: Likewise.
	* cgraph.c: Likewise.
	* combine.c: Likewise.
	* common/config/aarch64/aarch64-common.c: Likewise.
	* common/config/gcn/gcn-common.c: Likewise.
	* common/config/ia64/ia64-common.c: Likewise.
	* common/config/powerpcspe/powerpcspe-common.c: Likewise.
	* common/config/rs6000/rs6000-common.c: Likewise.
	* common/config/sh/sh-common.c: Likewise.
	* config/aarch64/aarch64.c: Likewise.
	* config/alpha/alpha.c: Likewise.
	* config/arm/arm.c: Likewise.
	* config/avr/avr.c: Likewise.
	* config/csky/csky.c: Likewise.
	* config/i386/i386-builtins.c: Likewise.
	* config/i386/i386-expand.c: Likewise.
	* config/i386/i386-features.c: Likewise.
	* config/i386/i386-options.c: Likewise.
	* config/i386/i386.c: Likewise.
	* config/ia64/ia64.c: Likewise.
	* config/rs6000/rs6000-logue.c: Likewise.
	* config/rs6000/rs6000.c: Likewise.
	* config/s390/s390.c: Likewise.
	* config/sparc/sparc.c: Likewise.
	* config/visium/visium.c: Likewise.
	* coverage.c: Likewise.
	* cprop.c: Likewise.
	* cse.c: Likewise.
	* cselib.c: Likewise.
	* dse.c: Likewise.
	* emit-rtl.c: Likewise.
	* explow.c: Likewise.
	* final.c: Likewise.
	* fold-const.c: Likewise.
	* gcc.c: Likewise.
	* gcse.c: Likewise.
	* ggc-common.c: Likewise.
	* ggc-page.c: Likewise.
	* gimple-loop-interchange.cc: Likewise.
	* gimple-loop-jam.c: Likewise.
	* gimple-loop-versioning.cc: Likewise.
	* gimple-ssa-split-paths.c: Likewise.
	* gimple-ssa-sprintf.c: Likewise.
	* gimple-ssa-store-merging.c: Likewise.
	* gimple-ssa-strength-reduction.c: Likewise.
	* gimple-ssa-warn-alloca.c: Likewise.
	* gimple-ssa-warn-restrict.c: Likewise.
	* graphite-isl-ast-to-gimple.c: Likewise.
	* graphite-optimize-isl.c: Likewise.
	* graphite-scop-detection.c: Likewise.
	* graphite-sese-to-poly.c: Likewise.
	* graphite.c: Likewise.
	* haifa-sched.c: Likewise.
	* hsa-gen.c: Likewise.
	* ifcvt.c: Likewise.
	* ipa-cp.c: Likewise.
	* ipa-fnsummary.c: Likewise.
	* ipa-inline-analysis.c: Likewise.
	* ipa-inline.c: Likewise.
	* ipa-polymorphic-call.c: Likewise.
	* ipa-profile.c: Likewise.
	* ipa-prop.c: Likewise.
	* ipa-split.c: Likewise.
	* ipa-sra.c: Likewise.
	* ira-build.c: Likewise.
	* ira-conflicts.c: Likewise.
	* loop-doloop.c: Likewise.
	* loop-invariant.c: Likewise.
	* loop-unroll.c: Likewise.
	* lra-assigns.c: Likewise.
	* lra-constraints.c: Likewise.
	* modulo-sched.c: Likewise.
	* opt-suggestions.c: Likewise.
	* opts.c: Likewise.
	* postreload-gcse.c: Likewise.
	* predict.c: Likewise.
	* reload.c: Likewise.
	* reorg.c: Likewise.
	* resource.c: Likewise.
	* sanopt.c: Likewise.
	* sched-deps.c: Likewise.
	* sched-ebb.c: Likewise.
	* sched-rgn.c: Likewise.
	* sel-sched-ir.c: Likewise.
	* sel-sched.c: Likewise.
	* shrink-wrap.c: Likewise.
	* stmt.c: Likewise.
	* targhooks.c: Likewise.
	* toplev.c: Likewise.
	* tracer.c: Likewise.
	* trans-mem.c: Likewise.
	* tree-chrec.c: Likewise.
	* tree-data-ref.c: Likewise.
	* tree-if-conv.c: Likewise.
	* tree-inline.c: Likewise.
	* tree-loop-distribution.c: Likewise.
	* tree-parloops.c: Likewise.
	* tree-predcom.c: Likewise.
	* tree-profile.c: Likewise.
	* tree-scalar-evolution.c: Likewise.
	* tree-sra.c: Likewise.
	* tree-ssa-ccp.c: Likewise.
	* tree-ssa-dom.c: Likewise.
	* tree-ssa-dse.c: Likewise.
	* tree-ssa-ifcombine.c: Likewise.
	* tree-ssa-loop-ch.c: Likewise.
	* tree-ssa-loop-im.c: Likewise.
	* tree-ssa-loop-ivcanon.c: Likewise.
	* tree-ssa-loop-ivopts.c: Likewise.
	* tree-ssa-loop-manip.c: Likewise.
	* tree-ssa-loop-niter.c: Likewise.
	* tree-ssa-loop-prefetch.c: Likewise.
	* tree-ssa-loop-unswitch.c: Likewise.
	* tree-ssa-math-opts.c: Likewise.
	* tree-ssa-phiopt.c: Likewise.
	* tree-ssa-pre.c: Likewise.
	* tree-ssa-reassoc.c: Likewise.
	* tree-ssa-sccvn.c: Likewise.
	* tree-ssa-scopedtables.c: Likewise.
	* tree-ssa-sink.c: Likewise.
	* tree-ssa-strlen.c: Likewise.
	* tree-ssa-structalias.c: Likewise.
	* tree-ssa-tail-merge.c: Likewise.
	* tree-ssa-threadbackward.c: Likewise.
	* tree-ssa-threadedge.c: Likewise.
	* tree-ssa-uninit.c: Likewise.
	* tree-switch-conversion.c: Likewise.
	* tree-vect-data-refs.c: Likewise.
	* tree-vect-loop.c: Likewise.
	* tree-vect-slp.c: Likewise.
	* tree-vrp.c: Likewise.
	* tree.c: Likewise.
	* value-prof.c: Likewise.
	* var-tracking.c: Likewise.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* gimple-parser.c: Do not include params.h.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* name-lookup.c: Do not include params.h.
	* typeck.c: Likewise.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* lto-common.c: Do not include params.h.
	* lto-partition.c: Likewise.
	* lto.c: Likewise.

From-SVN: r278086
2019-11-12 10:09:41 +00:00
Martin Liska
028d409252 Apply mechanical replacement (generated patch).
2019-11-12  Martin Liska  <mliska@suse.cz>

	* asan.c (asan_sanitize_stack_p): Replace old parameter syntax
	with the new one, include opts.h if needed.  Use SET_OPTION_IF_UNSET
	macro.
	(asan_sanitize_allocas_p): Likewise.
	(asan_emit_stack_protection): Likewise.
	(asan_protect_global): Likewise.
	(instrument_derefs): Likewise.
	(instrument_builtin_call): Likewise.
	(asan_expand_mark_ifn): Likewise.
	* auto-profile.c (auto_profile): Likewise.
	* bb-reorder.c (copy_bb_p): Likewise.
	(duplicate_computed_gotos): Likewise.
	* builtins.c (inline_expand_builtin_string_cmp): Likewise.
	* cfgcleanup.c (try_crossjump_to_edge): Likewise.
	(try_crossjump_bb): Likewise.
	* cfgexpand.c (defer_stack_allocation): Likewise.
	(stack_protect_classify_type): Likewise.
	(pass_expand::execute): Likewise.
	* cfgloopanal.c (expected_loop_iterations_unbounded): Likewise.
	(estimate_reg_pressure_cost): Likewise.
	* cgraph.c (cgraph_edge::maybe_hot_p): Likewise.
	* combine.c (combine_instructions): Likewise.
	(record_value_for_reg): Likewise.
	* common/config/aarch64/aarch64-common.c (aarch64_option_validate_param): Likewise.
	(aarch64_option_default_params): Likewise.
	* common/config/ia64/ia64-common.c (ia64_option_default_params): Likewise.
	* common/config/powerpcspe/powerpcspe-common.c (rs6000_option_default_params): Likewise.
	* common/config/rs6000/rs6000-common.c (rs6000_option_default_params): Likewise.
	* common/config/sh/sh-common.c (sh_option_default_params): Likewise.
	* config/aarch64/aarch64.c (aarch64_output_probe_stack_range): Likewise.
	(aarch64_allocate_and_probe_stack_space): Likewise.
	(aarch64_expand_epilogue): Likewise.
	(aarch64_override_options_internal): Likewise.
	* config/alpha/alpha.c (alpha_option_override): Likewise.
	* config/arm/arm.c (arm_option_override): Likewise.
	(arm_valid_target_attribute_p): Likewise.
	* config/i386/i386-options.c (ix86_option_override_internal): Likewise.
	* config/i386/i386.c (get_probe_interval): Likewise.
	(ix86_adjust_stack_and_probe_stack_clash): Likewise.
	(ix86_max_noce_ifcvt_seq_cost): Likewise.
	* config/ia64/ia64.c (ia64_adjust_cost): Likewise.
	* config/rs6000/rs6000-logue.c (get_stack_clash_protection_probe_interval): Likewise.
	(get_stack_clash_protection_guard_size): Likewise.
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Likewise.
	* config/s390/s390.c (allocate_stack_space): Likewise.
	(s390_emit_prologue): Likewise.
	(s390_option_override_internal): Likewise.
	* config/sparc/sparc.c (sparc_option_override): Likewise.
	* config/visium/visium.c (visium_option_override): Likewise.
	* coverage.c (get_coverage_counts): Likewise.
	(coverage_compute_profile_id): Likewise.
	(coverage_begin_function): Likewise.
	(coverage_end_function): Likewise.
	* cse.c (cse_find_path): Likewise.
	(cse_extended_basic_block): Likewise.
	(cse_main): Likewise.
	* cselib.c (cselib_invalidate_mem): Likewise.
	* dse.c (dse_step1): Likewise.
	* emit-rtl.c (set_new_first_and_last_insn): Likewise.
	(get_max_insn_count): Likewise.
	(make_debug_insn_raw): Likewise.
	(init_emit): Likewise.
	* explow.c (compute_stack_clash_protection_loop_data): Likewise.
	* final.c (compute_alignments): Likewise.
	* fold-const.c (fold_range_test): Likewise.
	(fold_truth_andor): Likewise.
	(tree_single_nonnegative_warnv_p): Likewise.
	(integer_valued_real_single_p): Likewise.
	* gcse.c (want_to_gcse_p): Likewise.
	(prune_insertions_deletions): Likewise.
	(hoist_code): Likewise.
	(gcse_or_cprop_is_too_expensive): Likewise.
	* ggc-common.c: Likewise.
	* ggc-page.c (ggc_collect): Likewise.
	* gimple-loop-interchange.cc (MAX_NUM_STMT): Likewise.
	(MAX_DATAREFS): Likewise.
	(OUTER_STRIDE_RATIO): Likewise.
	* gimple-loop-jam.c (tree_loop_unroll_and_jam): Likewise.
	* gimple-loop-versioning.cc (loop_versioning::max_insns_for_loop): Likewise.
	* gimple-ssa-split-paths.c (is_feasible_trace): Likewise.
	* gimple-ssa-store-merging.c (imm_store_chain_info::try_coalesce_bswap): Likewise.
	(imm_store_chain_info::coalesce_immediate_stores): Likewise.
	(imm_store_chain_info::output_merged_store): Likewise.
	(pass_store_merging::process_store): Likewise.
	* gimple-ssa-strength-reduction.c (find_basis_for_base_expr): Likewise.
	* graphite-isl-ast-to-gimple.c (class translate_isl_ast_to_gimple): Likewise.
	(scop_to_isl_ast): Likewise.
	* graphite-optimize-isl.c (get_schedule_for_node_st): Likewise.
	(optimize_isl): Likewise.
	* graphite-scop-detection.c (build_scops): Likewise.
	* haifa-sched.c (set_modulo_params): Likewise.
	(rank_for_schedule): Likewise.
	(model_add_to_worklist): Likewise.
	(model_promote_insn): Likewise.
	(model_choose_insn): Likewise.
	(queue_to_ready): Likewise.
	(autopref_multipass_dfa_lookahead_guard): Likewise.
	(schedule_block): Likewise.
	(sched_init): Likewise.
	* hsa-gen.c (init_prologue): Likewise.
	* ifcvt.c (bb_ok_for_noce_convert_multiple_sets): Likewise.
	(cond_move_process_if_block): Likewise.
	* ipa-cp.c (ipcp_lattice::add_value): Likewise.
	(merge_agg_lats_step): Likewise.
	(devirtualization_time_bonus): Likewise.
	(hint_time_bonus): Likewise.
	(incorporate_penalties): Likewise.
	(good_cloning_opportunity_p): Likewise.
	(ipcp_propagate_stage): Likewise.
	* ipa-fnsummary.c (decompose_param_expr): Likewise.
	(set_switch_stmt_execution_predicate): Likewise.
	(analyze_function_body): Likewise.
	(compute_fn_summary): Likewise.
	* ipa-inline-analysis.c (estimate_growth): Likewise.
	* ipa-inline.c (caller_growth_limits): Likewise.
	(inline_insns_single): Likewise.
	(inline_insns_auto): Likewise.
	(can_inline_edge_by_limits_p): Likewise.
	(want_early_inline_function_p): Likewise.
	(big_speedup_p): Likewise.
	(want_inline_small_function_p): Likewise.
	(want_inline_self_recursive_call_p): Likewise.
	(edge_badness): Likewise.
	(recursive_inlining): Likewise.
	(compute_max_insns): Likewise.
	(early_inliner): Likewise.
	* ipa-polymorphic-call.c (csftc_abort_walking_p): Likewise.
	* ipa-profile.c (ipa_profile): Likewise.
	* ipa-prop.c (determine_known_aggregate_parts): Likewise.
	(ipa_analyze_node): Likewise.
	(ipcp_transform_function): Likewise.
	* ipa-split.c (consider_split): Likewise.
	* ipa-sra.c (allocate_access): Likewise.
	(process_scan_results): Likewise.
	(ipa_sra_summarize_function): Likewise.
	(pull_accesses_from_callee): Likewise.
	* ira-build.c (loop_compare_func): Likewise.
	(mark_loops_for_removal): Likewise.
	* ira-conflicts.c (build_conflict_bit_table): Likewise.
	* loop-doloop.c (doloop_optimize): Likewise.
	* loop-invariant.c (gain_for_invariant): Likewise.
	(move_loop_invariants): Likewise.
	* loop-unroll.c (decide_unroll_constant_iterations): Likewise.
	(decide_unroll_runtime_iterations): Likewise.
	(decide_unroll_stupid): Likewise.
	(expand_var_during_unrolling): Likewise.
	* lra-assigns.c (spill_for): Likewise.
	* lra-constraints.c (EBB_PROBABILITY_CUTOFF): Likewise.
	* modulo-sched.c (sms_schedule): Likewise.
	(DFA_HISTORY): Likewise.
	* opts.c (default_options_optimization): Likewise.
	(finish_options): Likewise.
	(common_handle_option): Likewise.
	* postreload-gcse.c (eliminate_partially_redundant_load): Likewise.
	(if): Likewise.
	* predict.c (get_hot_bb_threshold): Likewise.
	(maybe_hot_count_p): Likewise.
	(probably_never_executed): Likewise.
	(predictable_edge_p): Likewise.
	(predict_loops): Likewise.
	(expr_expected_value_1): Likewise.
	(tree_predict_by_opcode): Likewise.
	(handle_missing_profiles): Likewise.
	* reload.c (find_equiv_reg): Likewise.
	* reorg.c (redundant_insn): Likewise.
	* resource.c (mark_target_live_regs): Likewise.
	(incr_ticks_for_insn): Likewise.
	* sanopt.c (pass_sanopt::execute): Likewise.
	* sched-deps.c (sched_analyze_1): Likewise.
	(sched_analyze_2): Likewise.
	(sched_analyze_insn): Likewise.
	(deps_analyze_insn): Likewise.
	* sched-ebb.c (schedule_ebbs): Likewise.
	* sched-rgn.c (find_single_block_region): Likewise.
	(too_large): Likewise.
	(haifa_find_rgns): Likewise.
	(extend_rgns): Likewise.
	(new_ready): Likewise.
	(schedule_region): Likewise.
	(sched_rgn_init): Likewise.
	* sel-sched-ir.c (make_region_from_loop): Likewise.
	* sel-sched-ir.h (MAX_WS): Likewise.
	* sel-sched.c (process_pipelined_exprs): Likewise.
	(sel_setup_region_sched_flags): Likewise.
	* shrink-wrap.c (try_shrink_wrapping): Likewise.
	* targhooks.c (default_max_noce_ifcvt_seq_cost): Likewise.
	* toplev.c (print_version): Likewise.
	(process_options): Likewise.
	* tracer.c (tail_duplicate): Likewise.
	* trans-mem.c (tm_log_add): Likewise.
	* tree-chrec.c (chrec_fold_plus_1): Likewise.
	* tree-data-ref.c (split_constant_offset): Likewise.
	(compute_all_dependences): Likewise.
	* tree-if-conv.c (MAX_PHI_ARG_NUM): Likewise.
	* tree-inline.c (remap_gimple_stmt): Likewise.
	* tree-loop-distribution.c (MAX_DATAREFS_NUM): Likewise.
	* tree-parloops.c (MIN_PER_THREAD): Likewise.
	(create_parallel_loop): Likewise.
	* tree-predcom.c (determine_unroll_factor): Likewise.
	* tree-scalar-evolution.c (instantiate_scev_r): Likewise.
	* tree-sra.c (analyze_all_variable_accesses): Likewise.
	* tree-ssa-ccp.c (fold_builtin_alloca_with_align): Likewise.
	* tree-ssa-dse.c (setup_live_bytes_from_ref): Likewise.
	(dse_optimize_redundant_stores): Likewise.
	(dse_classify_store): Likewise.
	* tree-ssa-ifcombine.c (ifcombine_ifandif): Likewise.
	* tree-ssa-loop-ch.c (ch_base::copy_headers): Likewise.
	* tree-ssa-loop-im.c (LIM_EXPENSIVE): Likewise.
	* tree-ssa-loop-ivcanon.c (try_unroll_loop_completely): Likewise.
	(try_peel_loop): Likewise.
	(tree_unroll_loops_completely): Likewise.
	* tree-ssa-loop-ivopts.c (avg_loop_niter): Likewise.
	(CONSIDER_ALL_CANDIDATES_BOUND): Likewise.
	(MAX_CONSIDERED_GROUPS): Likewise.
	(ALWAYS_PRUNE_CAND_SET_BOUND): Likewise.
	* tree-ssa-loop-manip.c (can_unroll_loop_p): Likewise.
	* tree-ssa-loop-niter.c (MAX_ITERATIONS_TO_TRACK): Likewise.
	* tree-ssa-loop-prefetch.c (PREFETCH_BLOCK): Likewise.
	(L1_CACHE_SIZE_BYTES): Likewise.
	(L2_CACHE_SIZE_BYTES): Likewise.
	(should_issue_prefetch_p): Likewise.
	(schedule_prefetches): Likewise.
	(determine_unroll_factor): Likewise.
	(volume_of_references): Likewise.
	(add_subscript_strides): Likewise.
	(self_reuse_distance): Likewise.
	(mem_ref_count_reasonable_p): Likewise.
	(insn_to_prefetch_ratio_too_small_p): Likewise.
	(loop_prefetch_arrays): Likewise.
	(tree_ssa_prefetch_arrays): Likewise.
	* tree-ssa-loop-unswitch.c (tree_unswitch_single_loop): Likewise.
	* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Likewise.
	(convert_mult_to_fma): Likewise.
	(math_opts_dom_walker::after_dom_children): Likewise.
	* tree-ssa-phiopt.c (cond_if_else_store_replacement): Likewise.
	(hoist_adjacent_loads): Likewise.
	(gate_hoist_loads): Likewise.
	* tree-ssa-pre.c (translate_vuse_through_block): Likewise.
	(compute_partial_antic_aux): Likewise.
	* tree-ssa-reassoc.c (get_reassociation_width): Likewise.
	* tree-ssa-sccvn.c (vn_reference_lookup_pieces): Likewise.
	(vn_reference_lookup): Likewise.
	(do_rpo_vn): Likewise.
	* tree-ssa-scopedtables.c (avail_exprs_stack::lookup_avail_expr): Likewise.
	* tree-ssa-sink.c (select_best_block): Likewise.
	* tree-ssa-strlen.c (new_stridx): Likewise.
	(new_addr_stridx): Likewise.
	(get_range_strlen_dynamic): Likewise.
	(class ssa_name_limit_t): Likewise.
	* tree-ssa-structalias.c (push_fields_onto_fieldstack): Likewise.
	(create_variable_info_for_1): Likewise.
	(init_alias_vars): Likewise.
	* tree-ssa-tail-merge.c (find_clusters_1): Likewise.
	(tail_merge_optimize): Likewise.
	* tree-ssa-threadbackward.c (thread_jumps::profitable_jump_thread_path): Likewise.
	(thread_jumps::fsm_find_control_statement_thread_paths): Likewise.
	(thread_jumps::find_jump_threads_backwards): Likewise.
	* tree-ssa-threadedge.c (record_temporary_equivalences_from_stmts_at_dest): Likewise.
	* tree-ssa-uninit.c (compute_control_dep_chain): Likewise.
	* tree-switch-conversion.c (switch_conversion::check_range): Likewise.
	(jump_table_cluster::can_be_handled): Likewise.
	* tree-switch-conversion.h (jump_table_cluster::case_values_threshold): Likewise.
	(SWITCH_CONVERSION_BRANCH_RATIO): Likewise.
	(param_switch_conversion_branch_ratio): Likewise.
	* tree-vect-data-refs.c (vect_mark_for_runtime_alias_test): Likewise.
	(vect_enhance_data_refs_alignment): Likewise.
	(vect_prune_runtime_alias_test_list): Likewise.
	* tree-vect-loop.c (vect_analyze_loop_costing): Likewise.
	(vect_get_datarefs_in_loop): Likewise.
	(vect_analyze_loop): Likewise.
	* tree-vect-slp.c (vect_slp_bb): Likewise.
	* tree-vectorizer.h: Likewise.
	* tree-vrp.c (find_switch_asserts): Likewise.
	(vrp_prop::check_mem_ref): Likewise.
	* tree.c (wide_int_to_tree_1): Likewise.
	(cache_integer_cst): Likewise.
	* var-tracking.c (EXPR_USE_DEPTH): Likewise.
	(reverse_op): Likewise.
	(vt_find_locations): Likewise.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* gimple-parser.c (c_parser_parse_gimple_body): Replace old parameter syntax
	with the new one, include opts.h if needed.  Use SET_OPTION_IF_UNSET
	macro.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* name-lookup.c (namespace_hints::namespace_hints): Replace old parameter syntax
	with the new one, include opts.h if needed.  Use SET_OPTION_IF_UNSET
	macro.
	* typeck.c (comptypes): Likewise.
2019-11-12  Martin Liska  <mliska@suse.cz>

	* lto-partition.c (lto_balanced_map): Replace old parameter syntax
	with the new one, include opts.h if needed.  Use SET_OPTION_IF_UNSET
	macro.
	* lto.c (do_whole_program_analysis): Likewise.

From-SVN: r278085
2019-11-12 10:08:40 +00:00
Eric Botcazou
3cf3da88be introduce -fcallgraph-info option
This was first submitted many years ago
https://gcc.gnu.org/ml/gcc-patches/2010-10/msg02468.html

The command line option -fcallgraph-info is added and makes the
compiler generate another output file (xxx.ci) for each compilation
unit (or LTO partitoin), which is a valid VCG file (you can launch
your favorite VCG viewer on it unmodified) and contains the "final"
callgraph of the unit.  "final" is a bit of a misnomer as this is
actually the callgraph at RTL expansion time, but since most
high-level optimizations are done at the Tree level and RTL doesn't
usually fiddle with calls, it's final in almost all cases.  Moreover,
the nodes can be decorated with additional info: -fcallgraph-info=su
adds stack usage info and -fcallgraph-info=da dynamic allocation info.


for  gcc/ChangeLog
From  Eric Botcazou  <ebotcazou@adacore.com>, Alexandre Oliva  <oliva@adacore.com>

	* common.opt (-fcallgraph-info[=]): New option.
	* doc/invoke.texi (Developer options): Document it.
	* opts.c (common_handle_option): Handle it.
	* builtins.c (expand_builtin_alloca): Record allocation if
	-fcallgraph-info=da.
	* calls.c (expand_call): If -fcallgraph-info, record the call.
	(emit_library_call_value_1): Likewise.
	* flag-types.h (enum callgraph_info_type): New type.
	* explow.c: Include stringpool.h.
	(set_stack_check_libfunc): Set SET_SYMBOL_REF_DECL on the symbol.
	* function.c (allocate_stack_usage_info): New.
	(allocate_struct_function): Call it for -fcallgraph-info.
	(prepare_function_start): Call it otherwise.
	(record_final_call, record_dynamic_alloc): New.
	* function.h (struct callinfo_callee): New.
	(CALLEE_FROM_CGRAPH_P): New.
	(struct callinfo_dalloc): New.
	(struct stack_usage): Add callees and dallocs.
	(record_final_call, record_dynamic_alloc): Declare.
	* gimplify.c (gimplify_decl_expr): Record dynamically-allocated
	object if -fcallgraph-info=da.
	* optabs-libfuncs.c (build_libfunc_function): Keep SYMBOL_REF_DECL.
	* print-tree.h (print_decl_identifier): Declare.
	(PRINT_DECL_ORIGIN, PRINT_DECL_NAME, PRINT_DECL_UNIQUE_NAME): New.
	* print-tree.c: Include print-tree.h.
	(print_decl_identifier): New function.
	* toplev.c: Include print-tree.h.
	(callgraph_info_file): New global variable.
	(callgraph_info_external_printed): Likewise.
	(output_stack_usage): Rename to...
	(output_stack_usage_1): ... this.  Make it static, add cf
	parameter.  If -fcallgraph-info=su, print stack usage to cf.
	If -fstack-usage, use print_decl_identifier for
	pretty-printing.
	(INDIRECT_CALL_NAME): New.
	(dump_final_node_vcg_start): New.
	(dump_final_callee_vcg, dump_final_node_vcg): New.
	(output_stack_usage): New.
	(lang_dependent_init): Open and start file if
	-fcallgraph-info.  Allocated callgraph_info_external_printed.
	(finalize): If callgraph_info_file is not null, finish it,
	close it, and release callgraph_info_external_printed.

for  gcc/ada/ChangeLog

	* gcc-interface/misc.c (callgraph_info_file): Delete.

Co-Authored-By: Alexandre Oliva <oliva@adacore.com>

From-SVN: r277876
2019-11-06 10:57:18 +00:00
Jakub Jelinek
f05b372429 re PR tree-optimization/91945 (ICE: tree check: expected integer_cst, have var_decl in get_len, at tree.h:5837 since r274997)
PR tree-optimization/91945
	* builtins.c (compute_objsize): For ARRAY_REF, only multiply off
	by tpsize if it is both non-NULL and INTEGER_CST, otherwise punt.
	Formatting fix.

	* gfortran.dg/pr91945.f90: New test.

From-SVN: r277820
2019-11-05 11:17:29 +01:00
Martin Sebor
a7160771da PR tree-optimization/90879 - fold zero-equality of strcmp between a longer string and a smaller array
gcc/c-family/ChangeLog:

	PR tree-optimization/90879
	* c.opt (-Wstring-compare): New option.

gcc/testsuite/ChangeLog:

	PR tree-optimization/90879
	* gcc.dg/Wstring-compare-2.c: New test.
	* gcc.dg/Wstring-compare.c: New test.
	* gcc.dg/strcmpopt_3.c: Scan the optmized dump instead of strlen.
	* gcc.dg/strcmpopt_6.c: New test.
	* gcc.dg/strlenopt-65.c: Remove uinnecessary declarations, add
	test cases.
	* gcc.dg/strlenopt-66.c: Run it.
	* gcc.dg/strlenopt-68.c: New test.

gcc/ChangeLog:

	PR tree-optimization/90879
	* builtins.c (check_access): Avoid using maxbound when null.
	* calls.c (maybe_warn_nonstring_arg): Adjust to get_range_strlen change.
	* doc/invoke.texi (-Wstring-compare): Document new warning option.
	* gimple-fold.c (get_range_strlen_tree): Make setting maxbound
	conditional.
	(get_range_strlen): Overwrite initial maxbound when non-null.
	* gimple-ssa-sprintf.c (get_string_length): Adjust to get_range_strlen
	changes.
	* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Same.
	(used_only_for_zero_equality): New function.
	(handle_builtin_memcmp): Call it.
	(determine_min_objsize): Return an integer instead of tree.
	(get_len_or_size, strxcmp_eqz_result): New functions.
	(maybe_warn_pointless_strcmp): New function.
	(handle_builtin_string_cmp): Call it.  Fold zero-equality of strcmp
	between a longer string and a smaller array.
	(get_range_strlen_dynamic): Overwrite initial maxbound when non-null.

From-SVN: r276773
2019-10-09 15:35:11 -06:00
Martin Sebor
28a5fa54aa builtins.c (compute_objsize): Add an argument.
gcc/ChangeLog:

	* builtins.c (compute_objsize): Add an argument.
	* tree-object-size.c (addr_object_size): Same.
	(compute_builtin_object_size): Same.
	* tree-object-size.h (compute_builtin_object): Same.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wstringop-overflow-17.c: New test.

From-SVN: r276602
2019-10-04 15:26:27 -06:00
Aaron Sawdey
03a9b90aa6 builtins.c (expand_builtin_memory_copy_args): Add might_overlap parm.
2019-10-02  Aaron Sawdey <acsawdey@linux.ibm.com>

	* builtins.c (expand_builtin_memory_copy_args): Add might_overlap parm.
	(expand_builtin_memcpy): Use might_overlap parm.
	(expand_builtin_mempcpy_args): Use might_overlap parm.
	(expand_builtin_memmove): Call expand_builtin_memory_copy_args.
	(expand_builtin_memory_copy_args): Add might_overlap parm.
	* expr.c (emit_block_move_via_cpymem): Rename to
	emit_block_move_via_pattern, add might_overlap parm, use cpymem
	or movmem optab as appropriate.
	(emit_block_move_hints): Add might_overlap parm, do the right
	thing for might_overlap==true.
	* expr.h (emit_block_move_hints): Update prototype.

From-SVN: r276461
2019-10-02 09:23:51 -05:00
Martin Sebor
6889a3acfe PR middle-end/91631 - buffer overflow into an array member of a declared object not detected
gcc/ChangeLog:

	PR middle-end/91631
	* builtins.c (component_size): Correct trailing array computation,
	rename to component_ref_size and move...
	(compute_objsize): Adjust.
	* gimple-ssa-warn-restrict.c (builtin_memref::refsize): New member.
	(builtin_access::strict): Do not consider mememmove.
	(builtin_access::write_off): New function.
	(builtin_memref::builtin_memref): Initialize refsize.
	(builtin_memref::set_base_and_offset): Adjust refoff and compute
	refsize.
	(builtin_memref::offset_out_of_bounds): Use ooboff input values.
	Handle refsize.
	(builtin_access::builtin_access): Intialize dstoff to destination
	refeence offset here instead of in maybe_diag_overlap.  Adjust
	referencess even to unrelated objects.	Adjust sizrange of bounded
	string functions to reflect bound.  For strcat, adjust destination
	sizrange by that of source.
	(builtin_access::strcat_overlap):  Adjust offsets and sizes
	to reflect the increase in destination sizrange above.
	(builtin_access::overlap): Do not set dstoff here but instead
	in builtin_access::builtin_access.
	(check_bounds_or_overlap): Use builtin_access::write_off.
	(maybe_diag_access_bounds): Add argument.  Add informational notes.
	(dump_builtin_memref, dump_builtin_access): New functions.
	* tree.c (component_ref_size): ...to here.
	* tree.h (component_ref_size): Declare.
	* tree-ssa-strlen (handle_builtin_strcat): Include the terminating
	nul in the size of the source string.

gcc/testsuite/ChangeLog:

	PR middle-end/91631
	* /c-c++-common/Warray-bounds-3.c: Correct expected offsets.
	* /c-c++-common/Warray-bounds-4.c: Same.
	* gcc.dg/Warray-bounds-39.c: Remove xfails.
	* gcc.dg/Warray-bounds-45.c: New test.
	* gcc.dg/Warray-bounds-46.c: New test.

From-SVN: r275981
2019-09-19 16:15:34 -06:00
Martin Sebor
464969eb9b PR tree-optimization/91457 - inconsistent warning for writing past the end 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-28 10:43:56 -06:00