platform/upstream/gcc.git
23 months agoada: Spurious error on Lock_Free protected type with discriminants
Justin Squirek [Wed, 23 Nov 2022 07:56:45 +0000 (07:56 +0000)]
ada: Spurious error on Lock_Free protected type with discriminants

This patch corrects an issue in the compiler whereby unprefixed discriminants
appearing in protected subprograms were unable to be properly resolved -
leading to spurious resolution errors.

gcc/ada/

* sem_ch8.adb
(Find_Direct_Name): Remove bypass to reanalyze incorrectly
analyzed discriminals.
(Set_Entity_Or_Discriminal): Avoid resetting the entity field of a
discriminant reference to be the internally generated renaming
when we are in strict preanalysis mode.

23 months agoc: Propagate erroneous types to declaration specifiers [PR107805]
Florian Weimer [Thu, 24 Nov 2022 10:00:54 +0000 (11:00 +0100)]
c: Propagate erroneous types to declaration specifiers [PR107805]

Without this change, finish_declspecs cannot tell that whether there
was an erroneous type specified, or no type at all.  This may result
in additional diagnostics for implicit ints, or missing diagnostics
for multiple types.

PR c/107805

gcc/c/
* c-decl.cc (declspecs_add_type): Propagate error_mark_bode
from type to specs.

gcc/testsuite/
* gcc.dg/pr107805-1.c: New test.
* gcc.dg/pr107805-2.c: Likewise.

23 months agolibstdc++: Another merge from fast_float upstream [PR107468]
Jakub Jelinek [Thu, 24 Nov 2022 09:38:42 +0000 (10:38 +0100)]
libstdc++: Another merge from fast_float upstream [PR107468]

Upstream fast_float came up with a cheaper test for
fegetround () == FE_TONEAREST using one float addition, one subtraction
and one comparison.  If we know we are rounding to nearest, we can use
fast path in more cases as before.
The following patch merges those changes into libstdc++.

2022-11-24  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/107468
* src/c++17/fast_float/MERGE: Adjust for merge from upstream.
* src/c++17/fast_float/fast_float.h: Merge from fast_float
2ef9abbcf6a11958b6fa685a89d0150022e82e78 commit.

23 months agolibstdc++: Workaround buggy printf on Solaris in to_chars/float128_c++23.cc test...
Jakub Jelinek [Thu, 24 Nov 2022 09:37:50 +0000 (10:37 +0100)]
libstdc++: Workaround buggy printf on Solaris in to_chars/float128_c++23.cc test [PR107815]

As mentioned in the PR, Solaris apparently can handle right
printf ("%.0Lf\n", 1e+202L * __DBL_MAX__);
which prints 511 chars long number, but can't handle
printf ("%.0Lf\n", 1e+203L * __DBL_MAX__);
nor
printf ("%.0Lf\n", __LDBL_MAX__);
properly, instead of printing 512 chars long number for the former and
4933 chars long number for the second, it handles them as
if user asked for "%.0Le\n" in those cases.

The following patch disables the single problematic value that fails
in the test, and also fixes commented out debugging printouts.

2022-11-24  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/107815
* testsuite/20_util/to_chars/float128_c++23.cc (test): Disable
__FLT128_MAX__ test on Solaris.  Fix up commented out debugging
printouts.

23 months agotestsuite: Fix up broken testcase [PR107127]
Jakub Jelinek [Thu, 24 Nov 2022 09:33:00 +0000 (10:33 +0100)]
testsuite: Fix up broken testcase [PR107127]

I've added { dg-options "" } line manually in the patch but
forgot to adjust the number of added lines.

2022-11-24  Jakub Jelinek  <jakub@redhat.com>

PR c/107127
* gcc.dg/pr107127.c (foo): Add missing closing }.

23 months agoanalyzer: fix Clang warnings
Martin Liska [Thu, 24 Nov 2022 07:40:10 +0000 (08:40 +0100)]
analyzer: fix Clang warnings

Fixes the following warnings:
gcc/analyzer/varargs.cc:655:8: warning: 'matches_call_types_p' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
gcc/analyzer/varargs.cc:707:50: warning: unused parameter 'cd' [-Wunused-parameter]
gcc/analyzer/varargs.cc:707:8: warning: 'matches_call_types_p' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]

gcc/analyzer/ChangeLog:

* varargs.cc: Fix Clang warnings.

23 months agoRemove use_equiv_p in vr-values.cc
Aldy Hernandez [Tue, 22 Nov 2022 09:44:18 +0000 (10:44 +0100)]
Remove use_equiv_p in vr-values.cc

With no equivalences, the use_equiv_p argument in various methods in
simplify_using_ranges is always false.  This means we can remove all
calls to compare_names, along with the function.

gcc/ChangeLog:

* vr-values.cc (simplify_using_ranges::compare_names): Remove.
(vrp_evaluate_conditional_warnv_with_ops): Remove call to
compare_names.
(simplify_using_ranges::vrp_visit_cond_stmt): Remove use_equiv_p
argument to vrp_evaluate_conditional_warnv_with_ops.
* vr-values.h (class simplify_using_ranges): Remove
compare_names.
Remove use_equiv_p to vrp_evaluate_conditional_warnv_with_ops.

23 months agoRemove follow_assert_exprs from overflow_comparison.
Aldy Hernandez [Tue, 22 Nov 2022 09:40:39 +0000 (10:40 +0100)]
Remove follow_assert_exprs from overflow_comparison.

gcc/ChangeLog:

* tree-vrp.cc (overflow_comparison_p_1): Remove follow_assert_exprs.
(overflow_comparison_p): Remove use_equiv_p.
* tree-vrp.h (overflow_comparison_p): Same.
* vr-values.cc (vrp_evaluate_conditional_warnv_with_ops): Remove
use_equiv_p argument to overflow_comparison_p.

23 months agoRemove ASSERT_EXPR.
Aldy Hernandez [Tue, 22 Nov 2022 09:24:06 +0000 (10:24 +0100)]
Remove ASSERT_EXPR.

This removes all uses of ASSERT_EXPR except the internal one in ipa-*.

gcc/ChangeLog:

* doc/gimple.texi: Remove ASSERT_EXPR references.
* fold-const.cc (tree_expr_nonzero_warnv_p): Same.
(fold_binary_loc): Same.
(tree_expr_nonnegative_warnv_p): Same.
* gimple-array-bounds.cc (get_base_decl): Same.
* gimple-pretty-print.cc (dump_unary_rhs): Same.
* gimple.cc (get_gimple_rhs_num_ops): Same.
* pointer-query.cc (handle_ssa_name): Same.
* tree-cfg.cc (verify_gimple_assign_single): Same.
* tree-pretty-print.cc (dump_generic_node): Same.
* tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr):Same.
(interpret_rhs_expr): Same.
* tree-ssa-operands.cc (operands_scanner::get_expr_operands): Same.
* tree-ssa-propagate.cc
(substitute_and_fold_dom_walker::before_dom_children): Same.
* tree-ssa-threadedge.cc: Same.
* tree-vrp.cc (overflow_comparison_p): Same.
* tree.def (ASSERT_EXPR): Add note.
* tree.h (ASSERT_EXPR_VAR): Remove.
(ASSERT_EXPR_COND): Remove.
* vr-values.cc (simplify_using_ranges::vrp_visit_cond_stmt):
Remove comment.

23 months agoRemove value_range_equiv.
Aldy Hernandez [Sat, 19 Nov 2022 16:44:02 +0000 (17:44 +0100)]
Remove value_range_equiv.

With legacy VRP gone, value_range_equiv serves no purpose and any uses
of it can just be replaced with value_range.

gcc/ChangeLog:

* Makefile.in: Remove value-range-equiv.o
* gimple-array-bounds.cc
(array_bounds_checker::array_bounds_checker): Remove comment.
* tree-vrp.cc (supported_types_p): Remove use of value_range_equiv.
* value-query.cc (class equiv_allocator): Same.
(range_query::allocate_value_range_equiv): Remove.
(range_query::free_value_range_equiv): Remove.
(range_query::get_value_range): Remove.
* value-query.h (class range_query): Remove get_value_range.
Remove allocate_value_range_equiv.
Remove free_value_range_equiv.
* vr-values.cc (compare_ranges): Replace value_range_equiv with
value_range.
(simplify_using_ranges::get_vr_for_comparison): Same.
(simplify_using_ranges::compare_names): Same.
* vr-values.h: Remove value_range_equiv references.
* value-range-equiv.cc: Removed.
* value-range-equiv.h: Removed.

23 months agoRemove unused legacy VRP code.
Aldy Hernandez [Sat, 19 Nov 2022 10:11:25 +0000 (11:11 +0100)]
Remove unused legacy VRP code.

Removes unused legacy VRP code.  The legacy mode in value_range's is
still around, as it can't be trivially deleted.

With this patch vr-values.cc melts away to simplify_using_ranges, but
I have avoided any renaming of actual files, since we have plans for
consolidation of other folding with ranges for the next release.

gcc/ChangeLog:

* doc/invoke.texi: Remove docs for max-vrp-switch-assertions,
vrp1-mode, and vrp2-mode.
* params.opt: Same.
* range-op.cc (masked_increment): Move from tree-vrp.cc.
* tree-vrp.cc (class live_names): Remove.
(live_names::init_bitmap_if_needed): Remove.
(live_names::block_has_live_names_p): Remove.
(live_names::clear_block): Remove.
(live_names::merge): Remove.
(live_names::set): Remove.
(live_names::clear): Remove.
(live_names::live_names): Remove.
(live_names::~live_names): Remove.
(live_names::live_on_block_p): Remove.
(live_names::live_on_edge_p): Remove.
(get_single_symbol): Make static.
(build_symbolic_expr): Remove.
(adjust_symbolic_bound): Remove.
(combine_bound): Remove.
(set_value_range_with_overflow): Remove.
(extract_range_from_pointer_plus_expr): Remove.
(extract_range_from_plus_minus_expr): Remove.
(drop_undefines_to_varying): Remove.
(range_fold_binary_symbolics_p): Remove.
(range_fold_unary_symbolics_p): Remove.
(range_fold_binary_expr): Remove.
(infer_value_range): Remove.
(dump_assert_info): Remove.
(dump_asserts_info): Remove.
(add_assert_info): Remove.
(extract_code_and_val_from_cond_with_ops): Remove.
(masked_increment): Move to range-op.cc.
(register_edge_assert_for_2): Remove.
(find_case_label_index): Remove.
(find_case_label_range): Remove.
(register_edge_assert_for_1): Remove.
(is_masked_range_test): Remove.
(register_edge_assert_for): Remove.
(stmt_interesting_for_vrp): Remove.
(struct case_info): Remove.
(struct assert_locus): Remove.
(class vrp_asserts): Remove.
(vrp_asserts::build_assert_expr_for): Remove.
(vrp_asserts::dump): Remove.
(vrp_asserts::register_new_assert_for): Remove.
(vrp_asserts::finish_register_edge_assert_for): Remove.
(vrp_asserts::find_conditional_asserts): Remove.
(vrp_asserts::compare_case_labels): Remove.
(vrp_asserts::find_switch_asserts): Remove.
(vrp_asserts::find_assert_locations_in_bb): Remove.
(vrp_asserts::find_assert_locations): Remove.
(vrp_asserts::process_assert_insertions_for): Remove.
(vrp_asserts::compare_assert_loc): Remove.
(vrp_asserts::process_assert_insertions): Remove.
(vrp_asserts::insert_range_assertions): Remove.
(vrp_asserts::all_imm_uses_in_stmt_or_feed_cond): Remove.
(vrp_asserts::remove_range_assertions): Remove.
(class vrp_prop): Remove.
(vrp_prop::initialize): Remove.
(enum ssa_prop_result): Remove.
(vrp_prop::visit_stmt): Remove.
(vrp_prop::visit_phi): Remove.
(vrp_prop::finalize): Remove.
(class vrp_folder): Remove.
(vrp_folder::fold_predicate_in): Remove.
(vrp_folder::fold_stmt): Remove.
(vrp_folder::simplify_casted_conds): Remove.
(execute_vrp): Remove.
* tree-vrp.h (struct assert_info): Remove.
(register_edge_assert_for): Remove.
(stmt_interesting_for_vrp): Remove.
(infer_value_range): Remove.
(get_single_symbol): Remove.
(masked_increment): Remove.
(execute_ranger_vrp): Remove.
* vr-values.cc (set_value_range_to_nonnegative): Remove.
(set_value_range_to_truthvalue): Remove.
(vr_values::get_lattice_entry): Remove.
(vr_values::get_value_range): Remove.
(vr_values::range_of_expr): Remove.
(vr_values::value_of_expr): Remove.
(vr_values::value_on_edge): Remove.
(vr_values::value_of_stmt): Remove.
(vr_values::set_def_to_varying): Remove.
(vr_values::set_defs_to_varying): Remove.
(vr_values::update_value_range): Remove.
(symbolic_range_based_on_p): Remove.
(gimple_assign_nonzero_p): Remove.
(gimple_stmt_nonzero_p): Remove.
(vr_values::vrp_stmt_computes_nonzero): Remove.
(vr_values::op_with_constant_singleton_value_range): Remove.
(vr_values::extract_range_for_var_from_comparison_expr): Remove.
(vr_values::extract_range_from_assert): Remove.
(vr_values::extract_range_from_ssa_name): Remove.
(vr_values::extract_range_from_binary_expr): Remove.
(vr_values::extract_range_from_unary_expr): Remove.
(vr_values::extract_range_from_cond_expr): Remove.
(vr_values::extract_range_from_comparison): Remove.
(vr_values::extract_range_from_ubsan_builtin): Remove.
(vr_values::extract_range_basic): Remove.
(vr_values::extract_range_from_assignment): Remove.
(vr_values::adjust_range_with_scev): Remove.
(vr_values::dump): Remove.
(vr_values::vr_values): Remove.
(vr_values::~vr_values): Remove.
(vrp_valueize): Remove.
(vrp_valueize_1): Remove.
(get_output_for_vrp): Remove.
(vr_values::vrp_visit_assignment_or_call): Remove.
(simplify_using_ranges::vrp_evaluate_conditional): Remove.
(vr_values::vrp_visit_switch_stmt): Remove.
(vr_values::extract_range_from_stmt): Remove.
(vr_values::extract_range_from_phi_node): Remove.
(simplify_using_ranges::fold_cond): Add FIXME note.
(vr_values::set_vr_value): Remove.
(vr_values::swap_vr_value): Remove.
* vr-values.h (class vr_values): Remove.
(get_output_for_vrp): Remove.

23 months agoanalyzer: revamp of heap-allocated regions [PR106473]
David Malcolm [Thu, 24 Nov 2022 01:43:33 +0000 (20:43 -0500)]
analyzer: revamp of heap-allocated regions [PR106473]

PR analyzer/106473 reports a false positive from -Wanalyzer-malloc-leak
on:

  void foo(char **args[], int *argc) {
      *argc = 1;
      (*args)[0] = __builtin_malloc(42);
  }

The issue is that at the write to *argc we don't know if argc could
point within *args, and so we conservatiely set *args to be unknown.
At the write "(*args)[0] = __builtin_malloc(42)" we have the result of
the allocation written through an unknown pointer, so we mark the
heap_allocated_region as having escaped.
Unfortunately, within store::canonicalize we overzealously purge the
heap allocated region, losing the information that it has escaped, and
thus errnoeously report a leak.

The first part of the fix is to update store::canonicalize so that it
doesn't purge heap_allocated_regions that are marked as escaping.

Doing so fixes the leak false positive, but leads to various state
explosions relating to anywhere we have a malloc/free pair in a loop,
where the analysis of the iteration appears to only have been reaching
a fixed state due to a bug in the state merger code that was erroneously
merging state about the region allocated in one iteration with that
of another.  On touching that, the analyzer fails to reach a fixed state
on any loops containing a malloc/free pair, since each analysis of a
malloc was creating a new heap_allocated_region instance.

Hence the second part of the fix is to revamp how heap_allocated_regions
are managed within the analyzer.  Rather than create a new one at each
analysis of a malloc call, instead we reuse them across the analysis,
only creating a new one if the current path's state is referencing all
of the existing ones.  Hence the heap_allocated_region instances get
used in a fixed order along every analysis path, so e.g. at:

  if (flag)
    p = malloc (4096);
  else
    p = malloc (1024);

both paths now use the same heap_allocated_region for their malloc
calls - but we still end up with two enodes after the CFG merger, by
rejecting merger of states with non-equal dynamic extents.

gcc/analyzer/ChangeLog:
PR analyzer/106473
* call-summary.cc
(call_summary_replay::convert_region_from_summary_1): Update for
change to creation of heap-allocated regions.
* program-state.cc (test_program_state_1): Likewise.
(test_program_state_merging): Likewise.
* region-model-impl-calls.cc (kf_calloc::impl_call_pre): Likewise.
(kf_malloc::impl_call_pre): Likewise.
(kf_operator_new::impl_call_pre): Likewise.
(kf_realloc::impl_call_postsuccess_with_move::update_model): Likewise.
* region-model-manager.cc
(region_model_manager::create_region_for_heap_alloc): Convert
to...
(region_model_manager::get_or_create_region_for_heap_alloc):
...this, reusing an existing region if it's unreferenced in the
client state.
* region-model-manager.h (region_model_manager::get_num_regions): New.
 (region_model_manager::create_region_for_heap_alloc): Convert to...
 (region_model_manager::get_or_create_region_for_heap_alloc): ...this.
* region-model.cc (region_to_value_map::can_merge_with_p): Reject
merger when the values are different.
(region_model::create_region_for_heap_alloc): Convert to...
(region_model::get_or_create_region_for_heap_alloc): ...this.
(region_model::get_referenced_base_regions): New.
(selftest::test_state_merging):  Update for change to creation of
heap-allocated regions.
(selftest::test_malloc_constraints): Likewise.
(selftest::test_malloc): Likewise.
* region-model.h: Include "sbitmap.h".
(region_model::create_region_for_heap_alloc): Convert to...
(region_model::get_or_create_region_for_heap_alloc): ...this.
(region_model::get_referenced_base_regions): New decl.
* store.cc (store::canonicalize): Don't purge a heap-allocated region
that's been marked as escaping.

gcc/testsuite/ChangeLog:
PR analyzer/106473
* gcc.dg/analyzer/aliasing-pr106473.c: New test.
* gcc.dg/analyzer/allocation-size-2.c: Add
-fanalyzer-fine-grained".
* gcc.dg/analyzer/allocation-size-3.c: Likewise.
* gcc.dg/analyzer/explode-1.c: Mark leak with XFAIL.
* gcc.dg/analyzer/explode-3.c: New test.
* gcc.dg/analyzer/malloc-reuse.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: fix nondeterminism in logs
David Malcolm [Thu, 24 Nov 2022 01:43:32 +0000 (20:43 -0500)]
analyzer: fix nondeterminism in logs

gcc/analyzer/ChangeLog:
* checker-path.cc (checker_path::inject_any_inlined_call_events):
Don't dump the address of the block when -fdump-noaddr.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: eliminate region_model::on_ fns for sockets
David Malcolm [Thu, 24 Nov 2022 01:43:32 +0000 (20:43 -0500)]
analyzer: eliminate region_model::on_ fns for sockets

This mostly mechanical patch eliminates a confusing extra layer of
redundant calls in the handling of socket-related functions.

gcc/analyzer/ChangeLog:
* region-model.h (region_model::on_socket): Delete decl.
(region_model::on_bind): Likewise.
(region_model::on_listen): Likewise.
(region_model::on_accept): Likewise.
(region_model::on_connect): Likewise.
* sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
of region_model::on_socket into here, ...
(region_model::on_socket): ...eliminating this function.
(kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
(region_model::on_bind): ...eliminating this function.
(kf_listen::outcome_of_listen::update_model): Likewise fo
on_listen...
(region_model::on_listen): ...eliminating this function.
(kf_accept::outcome_of_accept::update_model): Likewise fo
on_accept...
(region_model::on_accept): ...eliminating this function.
(kf_connect::outcome_of_connect::update_model): Likewise fo
on_connect...
(region_model::on_connect): ...eliminating this function.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: move known funs for fds to sm-fd.cc
David Malcolm [Thu, 24 Nov 2022 01:43:32 +0000 (20:43 -0500)]
analyzer: move known funs for fds to sm-fd.cc

This mostly mechanical change enables a simplification in the
followup patch.  No functional change intended.

gcc/analyzer/ChangeLog:
* analyzer.h (register_known_fd_functions): New decl.
* region-model-impl-calls.cc (class kf_accept): Move to sm-fd.cc.
(class kf_bind): Likewise.
(class kf_connect): Likewise.
(class kf_listen): Likewise.
(class kf_pipe): Likewise.
(class kf_socket): Likewise.
(register_known_functions): Remove registration of the above
functions, instead calling register_known_fd_functions.
* sm-fd.cc: Include "analyzer/call-info.h".
(class kf_socket): Move here from region-model-impl-calls.cc.
(class kf_bind): Likewise.
(class kf_listen): Likewise.
(class kf_accept): Likewise.
(class kf_connect): Likewise.
(class kf_pipe): Likewise.
(register_known_fd_functions): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoi386: Only enable small loop unrolling in backend [PR 107692]
Hongyu Wang [Sat, 19 Nov 2022 01:38:00 +0000 (09:38 +0800)]
i386: Only enable small loop unrolling in backend [PR 107692]

Followed by the discussion in pr107692, -munroll-only-small-loops
Does not turns on/off -funroll-loops, and current check in
pass_rtl_unroll_loops::gate would cause -fno-unroll-loops do not take
effect. Revert the change about targetm.loop_unroll_adjust and apply
the backend option change to strictly follow the rule that
-funroll-loops takes full control of loop unrolling, and
munroll-only-small-loops just change its behavior to unroll small size
loops.

gcc/ChangeLog:

PR target/107692
* common/config/i386/i386-common.cc (ix86_optimization_table):
Enable loop unroll O2, disable -fweb and -frename-registers
by default.
* config/i386/i386-options.cc
(ix86_override_options_after_change):
Disable small loop unroll when funroll-loops enabled, reset
cunroll_grow_size when it is not explicitly enabled.
(ix86_option_override_internal): Call
ix86_override_options_after_change instead of calling
ix86_recompute_optlev_based_flags and ix86_default_align
separately.
* config/i386/i386.cc (ix86_loop_unroll_adjust): Adjust unroll
factor if -munroll-only-small-loops enabled.
* loop-init.cc (pass_rtl_unroll_loops::gate): Do not enable
loop unrolling for -O2-speed.
(pass_rtl_unroll_loops::execute): Rmove
targetm.loop_unroll_adjust check.

gcc/testsuite/ChangeLog:

PR target/107692
* gcc.dg/guality/loop-1.c: Remove additional option for ia32.
* gcc.target/i386/pr86270.c: Add -fno-unroll-loops.
* gcc.target/i386/pr93002.c: Likewise.

23 months agoDaily bump.
GCC Administrator [Thu, 24 Nov 2022 00:17:47 +0000 (00:17 +0000)]
Daily bump.

23 months agoanalyzer: Use __builtin_alloca in gcc.dg/analyzer/call-summaries-2.c
Rainer Orth [Wed, 23 Nov 2022 20:54:26 +0000 (21:54 +0100)]
analyzer: Use __builtin_alloca in gcc.dg/analyzer/call-summaries-2.c

gcc.dg/analyzer/call-summaries-2.c currently FAILs on Solaris:

FAIL: gcc.dg/analyzer/call-summaries-2.c (test for excess errors)

Excess errors:
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c:468:12:
warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c:468:12:
warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]

alloca is only declared in <alloca.h>, which isn't included indirectly
anywhere.  To avoid this, I switched the test to use __builtin_alloca
instead, following the vast majority of analyzer tests that use alloca.

Tested no i386-pc-solaris2.11, sparc-sun-solaris2.11, and
x86_64-pc-linux-gnu.

2022-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* gcc.dg/analyzer/call-summaries-2.c (uses_alloca): Use
__builtin_alloca instead of alloca.

23 months agoFortran: error recovery on associate with bad selector [PR107577]
Steve Kargl [Tue, 22 Nov 2022 21:31:51 +0000 (22:31 +0100)]
Fortran: error recovery on associate with bad selector [PR107577]

gcc/fortran/ChangeLog:

PR fortran/107577
* resolve.cc (find_array_spec): Choose appropriate locus either of
bad array reference or of non-array entity in error message.

gcc/testsuite/ChangeLog:

PR fortran/107577
* gfortran.dg/pr107577.f90: New test.

23 months agoc: Fix compile time hog in c_genericize [PR107127]
Jakub Jelinek [Wed, 23 Nov 2022 18:09:31 +0000 (19:09 +0100)]
c: Fix compile time hog in c_genericize [PR107127]

The complex multiplications result in deeply nested set of many SAVE_EXPRs,
which takes even on fast machines over 5 minutes to walk.
This patch fixes that by using walk_tree_without_duplicates where it is
instant.

2022-11-23  Andrew Pinski  <apinski@marvell.com>
    Jakub Jelinek  <jakub@redhat.com>

PR c/107127
* c-gimplify.cc (c_genericize): Use walk_tree_without_duplicates
instead of walk_tree for c_genericize_control_r.

* gcc.dg/pr107127.c: New test.

23 months ago[Patch Arm] Add neon_fcadd and neon_fcmla to is_neon_type.
Ramana Radhakrishnan [Wed, 23 Nov 2022 16:33:39 +0000 (16:33 +0000)]
[Patch Arm] Add neon_fcadd and neon_fcmla to is_neon_type.

Appears to have been an oversight.

gcc/
* config/arm/types.md: Update comment.
(is_neon_type): Add neon_fcmla, neon_fcadd.

Signed-off-by: Ramana Radhakrishnan <ramana.gcc@gmail.com>
23 months agodoc: -Wdelete-non-virtual-dtor supersedes -Wnon-virtual-dtor
Jonathan Wakely [Wed, 23 Nov 2022 10:01:06 +0000 (10:01 +0000)]
doc: -Wdelete-non-virtual-dtor supersedes -Wnon-virtual-dtor

The newer -Wdelete-non-virtual-dtor has no false positives and fewer
bugs. There is very little reason to use -Wnon-virtual-dtor instead.

gcc/ChangeLog:

* doc/invoke.texi (C++ Dialect Options): Recommend using
-Wdelete-non-virtual-dtor instead of -Wnon-virtual-dtor.

23 months agodiagnostics: Fix selftest ICE in certain locales [PR107722]
Jakub Jelinek [Wed, 23 Nov 2022 13:43:48 +0000 (14:43 +0100)]
diagnostics: Fix selftest ICE in certain locales [PR107722]

As reported in the PR, since special_fname_builtin () call has been
introduced, the diagnostics code compares filename against _("<built-in>")
rather than "<built-in>", which means that if self tests are performed
with the string being translated, one self-test fails.
The following patch fixes that.

2022-11-23  Jakub Jelinek  <jakub@redhat.com>

PR bootstrap/107722
* diagnostic.cc (test_diagnostic_get_location_text): Test
special_fname_builtin () rather than "<built-in>" and expect
special_fname_builtin () concatenated with ":" for it.

23 months agod: respect --enable-link-mutex configure option
Martin Liska [Tue, 22 Nov 2022 09:39:50 +0000 (10:39 +0100)]
d: respect --enable-link-mutex configure option

I noticed the option is ignored because @DO_LINK_MUTEX@
is not defined in d/Make-lang.in.

gcc/ChangeLog:

* Makefile.in: Set DO_LINK_MUTEX.

gcc/d/ChangeLog:

* Make-lang.in: Use it as $DO_LINK_MUTEX.

23 months agolibstdc++: Fix libstdc++ build on some targets [PR107811]
Jakub Jelinek [Wed, 23 Nov 2022 10:53:54 +0000 (11:53 +0100)]
libstdc++: Fix libstdc++ build on some targets [PR107811]

fast_float library relies on size_t being 32-bit or larger and float/double
being IEEE single/double.  Otherwise we only use strtod/strtof.
In 3 spots I've used fast_float namespace stuff unconditionally in one
function, which breaks the build if fast_float is disabled.

2022-11-23  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/107811
* src/c++17/floating_from_chars.cc (__floating_from_chars_hex): Guard
fast_float uses with #if USE_LIB_FAST_FLOAT and for mantissa_bits and
exponent_bits provide a fallback.

23 months agolibstdc++: Fix unsafe use of dirent::d_name [PR107814]
Jonathan Wakely [Tue, 22 Nov 2022 19:15:53 +0000 (19:15 +0000)]
libstdc++: Fix unsafe use of dirent::d_name [PR107814]

Copy the fix for PR 104731 to the equivalent experimental::filesystem
test.

libstdc++-v3/ChangeLog:

PR libstdc++/107814
* testsuite/experimental/filesystem/iterators/error_reporting.cc:
Use a static buffer with space after it.

23 months agomaintainer-scripts/gcc_release: compress xz in parallel
Sam James [Tue, 8 Nov 2022 07:14:38 +0000 (07:14 +0000)]
maintainer-scripts/gcc_release: compress xz in parallel

1. This should speed up decompression for folks, as parallel xz
   creates a different archive which can be decompressed in parallel.

   Note that this different method is enabled by default in a new
   xz release coming shortly anyway (>= 5.3.3_alpha1).

   I build GCC regularly from the weekly snapshots
   and so the decompression time adds up.

2. It should speed up compression on the webserver a bit.

   Note that -T0 won't be the default in the new xz release,
   only the parallel compression mode (which enables parallel
   decompression).

   -T0 detects the number of cores available.

   So, if a different number of threads is preferred, it's fine
   to set e.g. -T2, etc.

Signed-off-by: Sam James <sam@gentoo.org>
* gcc_release (XZ): Add -T0.

23 months agoc++: Fix up -fcontract* options
Jakub Jelinek [Wed, 23 Nov 2022 08:29:04 +0000 (09:29 +0100)]
c++: Fix up -fcontract* options

I've noticed
+FAIL: compiler driver --help=c++ option(s): "^ +-.*[^:.]\$" absent from output: "  -fcontract-build-level=[off|default|audit] Specify max contract level to generate runtime checks for"
error, this is due to missing dot at the end of the description.

The second part of the first hunk should fix that, but while at it,
I find it weird that some options don't have RejectNegative, yet
for options that accept an argument a negative option looks weird
and isn't really handled.

Though, shall we have those [on|off] options at all?
Those are inconsistent with all other boolean options gcc has.
Every other boolean option is -fwhatever for it being on
and -fno-whatever for it being off, shouldn't the options be
without arguments and accept negatives (-fcontract-assumption-mode
vs. -fno-contract-assumption-mode etc.)?

2022-11-23  Jakub Jelinek  <jakub@redhat.com>

* c.opt (fcontract-assumption-mode=, fcontract-continuation-mode=,
fcontract-role=, fcontract-semantic=): Add RejectNegative.
(fcontract-build-level=): Terminate description with dot.

23 months agoLoongArch: Add prefetch instructions.
Lulu Cheng [Wed, 16 Nov 2022 01:25:14 +0000 (09:25 +0800)]
LoongArch: Add prefetch instructions.

Enable sw prefetching at -O3 and higher.

Co-Authored-By: xujiahao <xujiahao@loongson.cn>
gcc/ChangeLog:

* config/loongarch/constraints.md (ZD): New constraint.
* config/loongarch/loongarch-def.c: Initial number of parallel prefetch.
* config/loongarch/loongarch-tune.h (struct loongarch_cache):
Define number of parallel prefetch.
* config/loongarch/loongarch.cc (loongarch_option_override_internal):
Set up parameters to be used in prefetching algorithm.
* config/loongarch/loongarch.md (prefetch): New template.

23 months agoRevert "configure: Implement --enable-host-pie"
Marek Polacek [Wed, 23 Nov 2022 02:10:31 +0000 (21:10 -0500)]
Revert "configure: Implement --enable-host-pie"

This reverts commit 251c72a68af3a8b0638705b73ef120ffdf0053eb.

23 months agoRevert "configure: Implement --enable-host-bind-now"
Marek Polacek [Wed, 23 Nov 2022 02:10:19 +0000 (21:10 -0500)]
Revert "configure: Implement --enable-host-bind-now"

This reverts commit 258d7149f92f19380c9f7763618d62408c064e60.

23 months agoconfigure: Implement --enable-host-bind-now
Marek Polacek [Wed, 23 Nov 2022 01:46:46 +0000 (20:46 -0500)]
configure: Implement --enable-host-bind-now

As promised in the --enable-host-pie patch, this patch adds another
configure option, --enable-host-bind-now, which adds -z now when linking
the compiler executables in order to extend hardening.  BIND_NOW with RELRO
allows the GOT to be marked RO; this prevents GOT modification attacks.

This option does not affect linking of target libraries; you can use
LDFLAGS_FOR_TARGET=-Wl,-z,relro,-z,now to enable RELRO/BIND_NOW.

c++tools/ChangeLog:

* configure.ac (--enable-host-bind-now): New check.
* configure: Regenerate.

gcc/ChangeLog:

* configure.ac (--enable-host-bind-now): New check.  Add
-Wl,-z,now to LD_PICFLAG if --enable-host-bind-now.
* configure: Regenerate.
* doc/install.texi: Document --enable-host-bind-now.

lto-plugin/ChangeLog:

* configure.ac (--enable-host-bind-now): New check.  Link with
-z,now.
* configure: Regenerate.

23 months agoconfigure: Implement --enable-host-pie
Marek Polacek [Thu, 10 Nov 2022 21:33:03 +0000 (16:33 -0500)]
configure: Implement --enable-host-pie

This patch implements the --enable-host-pie configure option which
makes the compiler executables PIE.  This can be used to enhance
protection against ROP attacks, and can be viewed as part of a wider
trend to harden binaries.

It is similar to the option --enable-host-shared, except that --e-h-s
won't add -shared to the linker flags whereas --e-h-p will add -pie.
It is different from --enable-default-pie because that option just
adds an implicit -fPIE/-pie when the compiler is invoked, but the
compiler itself isn't PIE.

Since r12-5768-gfe7c3ecf, PCH works well with PIE, so there are no PCH
regressions.

When building the compiler, the build process may use various in-tree
libraries; these need to be built with -fPIE so that it's possible to
use them when building a PIE.  For instance, when --with-included-gettext
is in effect, intl object files must be compiled with -fPIE.  Similarly,
when building in-tree gmp, isl, mpfr and mpc, they must be compiled with
-fPIE.

I plan to add an option to link with -Wl,-z,now.

ChangeLog:

* Makefile.def: Pass $(PICFLAG) to AM_CFLAGS for gmp, mpfr, mpc, and
isl.
* Makefile.in: Regenerate.
* Makefile.tpl: Set PICFLAG.
* configure.ac (--enable-host-pie): New check.  Set PICFLAG after this
check.
* configure: Regenerate.

c++tools/ChangeLog:

* Makefile.in: Rename PIEFLAG to PICFLAG.  Set LD_PICFLAG.  Use it.
Use pic/libiberty.a if PICFLAG is set.
* configure.ac (--enable-default-pie): Set PICFLAG instead of PIEFLAG.
(--enable-host-pie): New check.
* configure: Regenerate.

fixincludes/ChangeLog:

* Makefile.in: Set and use PICFLAG and LD_PICFLAG.  Use the "pic"
build of libiberty if PICFLAG is set.
* configure.ac:
* configure: Regenerate.

gcc/ChangeLog:

* Makefile.in: Set LD_PICFLAG.  Use it.  Set enable_host_pie.
Remove NO_PIE_CFLAGS and NO_PIE_FLAG.  Pass LD_PICFLAG to
ALL_LINKERFLAGS.  Use the "pic" build of libiberty if --enable-host-pie.
* configure.ac (--enable-host-shared): Don't set PICFLAG here.
(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
check.
* configure: Regenerate.
* doc/install.texi: Document --enable-host-pie.

gcc/d/ChangeLog:

* Make-lang.in: Remove NO_PIE_CFLAGS.

intl/ChangeLog:

* Makefile.in: Use @PICFLAG@ in COMPILE as well.
* configure.ac (--enable-host-shared): Don't set PICFLAG here.
(--enable-host-pie): New check.  Set PICFLAG after this check.
* configure: Regenerate.

libcody/ChangeLog:

* Makefile.in: Pass LD_PICFLAG to LDFLAGS.
* configure.ac (--enable-host-shared): Don't set PICFLAG here.
(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
check.
* configure: Regenerate.

libcpp/ChangeLog:

* configure.ac (--enable-host-shared): Don't set PICFLAG here.
(--enable-host-pie): New check.  Set PICFLAG after this check.
* configure: Regenerate.

libdecnumber/ChangeLog:

* configure.ac (--enable-host-shared): Don't set PICFLAG here.
(--enable-host-pie): New check.  Set PICFLAG after this check.
* configure: Regenerate.

libiberty/ChangeLog:

* configure.ac: Also set shared when enable_host_pie.
* configure: Regenerate.

zlib/ChangeLog:

* configure.ac (--enable-host-shared): Don't set PICFLAG here.
(--enable-host-pie): New check.  Set PICFLAG after this check.
* configure: Regenerate.

23 months agoDaily bump.
GCC Administrator [Wed, 23 Nov 2022 00:17:30 +0000 (00:17 +0000)]
Daily bump.

23 months agoFix thinko in last patch
Jeff Law [Tue, 22 Nov 2022 23:30:38 +0000 (16:30 -0700)]
Fix thinko in last patch

gcc/
* tree-ssa-dom.cc (record_edge_info): Fix thinko in last commit.

23 months agoFix comment typos noticed by Bernhard
Jeff Law [Tue, 22 Nov 2022 23:22:18 +0000 (16:22 -0700)]
Fix comment typos noticed by Bernhard

gcc/
* tree-ssa-dom.cc (record_edge_info): Fix comment typos.

23 months agoFix recent rvv/base/spill testcase failures
Jeff Law [Tue, 22 Nov 2022 23:12:45 +0000 (18:12 -0500)]
Fix recent rvv/base/spill testcase failures

he core issue is we're expecting the frame to have a constant size, but it
doesn't.  So when using the to_constant method we abort.

The safest thing to do is to set no shrink-wrapping components when the
frame size is not fixed.  We might be able to do better later -- iff we
know the offset to the GPRs/FPRs is fixed and fits into the appropriate
number of bits.

Bootstrapped and regression tested (C-only) on riscv64-linux-gnu.  As
expected, it fixes a bucketload of failures in rvv/base/spill-*.c.

gcc/
* config/riscv/riscv.cc (riscv_get_separate_components): Do not
do shrink-wrapping for a frame with a variable size.

23 months agotree-object-size: Support strndup and strdup
Siddhesh Poyarekar [Fri, 4 Nov 2022 12:42:57 +0000 (08:42 -0400)]
tree-object-size: Support strndup and strdup

Use string length of input to strdup to determine the usable size of the
resulting object.  Avoid doing the same for strndup since there's a
chance that the input may be too large, resulting in an unnecessary
overhead or worse, the input may not be NULL terminated, resulting in a
crash where there would otherwise have been none.

gcc/ChangeLog:

* tree-object-size.cc (todo): New variable.
(object_sizes_execute): Use it.
(strdup_object_size): New function.
(call_object_size): Use it.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c (test_strdup,
test_strndup, test_strdup_min, test_strndup_min): New tests.
(main): Call them.
* gcc.dg/builtin-dynamic-object-size-1.c: Silence overread
warnings.
* gcc.dg/builtin-dynamic-object-size-2.c: Likewise.
* gcc.dg/builtin-dynamic-object-size-3.c: Likewise.
* gcc.dg/builtin-dynamic-object-size-4.c: Likewise.
* gcc.dg/builtin-object-size-1.c: Silence overread warnings.
Declare free, strdup and strndup.
(test11): New test.
(main): Call it.
* gcc.dg/builtin-object-size-2.c: Silence overread warnings.
Declare free, strdup and strndup.
(test9): New test.
(main): Call it.
* gcc.dg/builtin-object-size-3.c: Silence overread warnings.
Declare free, strdup and strndup.
(test11): New test.
(main): Call it.
* gcc.dg/builtin-object-size-4.c: Silence overread warnings.
Declare free, strdup and strndup.
(test9): New test.
(main): Call it.

23 months agoanalyzer: only look for named functions in root ns [PR107788]
David Malcolm [Tue, 22 Nov 2022 22:29:21 +0000 (17:29 -0500)]
analyzer: only look for named functions in root ns [PR107788]

gcc/analyzer/ChangeLog:
PR analyzer/107788
* known-function-manager.cc (known_function_manager::get_match):
Don't look up fndecls by name when they're not in the root
namespace.

gcc/testsuite/ChangeLog:
PR analyzer/107788
* g++.dg/analyzer/named-functions.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: fix ICE on 'bind(INT_CST, ...)' [PR107783]
David Malcolm [Tue, 22 Nov 2022 22:29:21 +0000 (17:29 -0500)]
analyzer: fix ICE on 'bind(INT_CST, ...)' [PR107783]

This was crashing inside fd_phase_mismatch's ctor with assertion
failure when the state was "fd-constant".

Fix the ICE by not complaining about constants passed to these APIs.

gcc/analyzer/ChangeLog:
PR analyzer/107783
* sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
complain when old state is "fd-constant".
(fd_state_machine::on_listen): Likewise.
(fd_state_machine::on_accept): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/107783
* gcc.dg/analyzer/fd-accept.c (test_accept_on_constant): New.
* gcc.dg/analyzer/fd-bind.c (test_bind_on_constant): New.
* gcc.dg/analyzer/fd-connect.c (test_connect_on_constant): New.
* gcc.dg/analyzer/fd-listen.c (test_listen_on_connected_socket):
Fix typo.
(test_listen_on_constant): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: fix 'errno' on Solaris and OS X [PR107807]
David Malcolm [Tue, 22 Nov 2022 22:29:21 +0000 (17:29 -0500)]
analyzer: fix 'errno' on Solaris and OS X [PR107807]

gcc/analyzer/ChangeLog:
PR analyzer/107807
* region-model-impl-calls.cc (register_known_functions): Register
"___errno" and "__error" as synonyms  for "__errno_location".

gcc/testsuite/ChangeLog:
PR analyzer/107807
* gcc.dg/analyzer/errno-___errno.c: New test.
* gcc.dg/analyzer/errno-__error.c: New test.
* gcc.dg/analyzer/errno-global-var.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: eliminate region_model::impl_call_* special cases
David Malcolm [Tue, 22 Nov 2022 22:29:21 +0000 (17:29 -0500)]
analyzer: eliminate region_model::impl_call_* special cases

Eliminate all of the remaining special cases in class region_model that
handle various specific functions, replacing them with uses of
known_function subclasses.

Add various type-checks that ought to prevent ICEs for cases where
functions match the name of a standard C library or POSIX function, but
have incompatible arguments.

gcc/analyzer/ChangeLog:
* analyzer.h (class internal_known_function): New.
(register_varargs_builtins): New decl.
* engine.cc (exploded_node::on_stmt_pre): Remove
"out_terminate_path" param from call to region_model::on_stmt_pre.
(feasibility_state::maybe_update_for_edge): Likewise.
* known-function-manager.cc: Include "basic-block.h", "gimple.h",
and "analyzer/region-model.h".
(known_function_manager::known_function_manager): Initialize
m_combined_fns_arr.
(known_function_manager::~known_function_manager): Clean up
m_combined_fns_arr.
(known_function_manager::get_by_identifier): Make const.
(known_function_manager::add): New overloaded definitions for
enum built_in_function and enum internal_fn.
(known_function_manager::get_by_fndecl): Delete.
(known_function_manager::get_match): New.
(known_function_manager::get_internal_fn): New.
(known_function_manager::get_normal_builtin): New.
* known-function-manager.h
(known_function_manager::get_by_identifier): Make private and
add const qualifier.
(known_function_manager::get_by_fndecl): Delete.
(known_function_manager::add): Add overloaded decls for
enum built_in_function name and enum internal_fn.
(known_function_manager::get_match): New decl.
(known_function_manager::get_internal_fn): New decl.
(known_function_manager::get_normal_builtin): New decl.
(known_function_manager::m_combined_fns_arr): New field.
* region-model-impl-calls.cc (call_details::arg_is_size_p): New.
(class kf_alloca): New.
(region_model::impl_call_alloca): Convert to...
(kf_alloca::impl_call_pre): ...this.
(kf_analyzer_dump_capacity::matches_call_types_p): Rewrite check
to use call_details::arg_is_pointer_p.
(region_model::impl_call_builtin_expect): Convert to...
(class kf_expect): ...this.
(class kf_calloc): New, adding check that both arguments are
size_t.
(region_model::impl_call_calloc): Convert to...
(kf_calloc::impl_call_pre): ...this.
(kf_connect::matches_call_types_p): Rewrite check to use
call_details::arg_is_pointer_p.
(region_model::impl_call_error): Convert to...
(class kf_error): ...this, and...
(kf_error::impl_call_pre): ...this.
(class kf_fgets): New, adding checks that args 0 and 2 are
pointers.
(region_model::impl_call_fgets): Convert to...
(kf_fgets::impl_call_pre): ...this.
(class kf_fread): New, adding checks on the argument types.
(region_model::impl_call_fread): Convert to...
(kf_fread::impl_call_pre): ...this.
(class kf_free): New, adding check that the argument is a pointer.
(region_model::impl_call_free): Convert to...
(kf_free::impl_call_post): ...this.
(class kf_getchar): New.
(class kf_malloc): New, adding check that the argument is a
size_t.
(region_model::impl_call_malloc): Convert to...
(kf_malloc::impl_call_pre): ...this.
(class kf_memcpy): New, adding checks on arguments.
(region_model::impl_call_memcpy): Convert to...
(kf_memcpy::impl_call_pre): ...this.
(class kf_memset): New.
(region_model::impl_call_memset): Convert to...
(kf_memset::impl_call_pre): ...this.
(kf_pipe::matches_call_types_p): Rewrite check to use
call_details::arg_is_pointer_p.
(kf_putenv::matches_call_types_p): Likewise.
(class kf_realloc): New, adding checks on the argument types.
(region_model::impl_call_realloc): Convert to...
(kf_realloc::impl_call_post): ...this.
(class kf_strchr): New.
(region_model::impl_call_strchr): Convert to...
(kf_strchr::impl_call_post): ...this.
(class kf_stack_restore): New.
(class kf_stack_save): New.
(class kf_stdio_output_fn): New.
(class kf_strcpy): New,
(region_model::impl_call_strcpy): Convert to...
(kf_strcpy::impl_call_pre): ...this.
(class kf_strlen): New.
(region_model::impl_call_strlen): Convert to...
(kf_strlen::impl_call_pre): ...this.
(class kf_ubsan_bounds): New.
(region_model::impl_deallocation_call): Reimplement to avoid call
to impl_call_free.
(register_known_functions): Add handlers for IFN_BUILTIN_EXPECT
and IFN_UBSAN_BOUNDS.  Add handlers for BUILT_IN_ALLOCA,
BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FPRINTF,
BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
BUILT_IN_FREE, BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED,
BUILT_IN_MALLOC, BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK,
BUILT_IN_MEMSET, BUILT_IN_MEMSET_CHK, BUILT_IN_PRINTF,
BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
BUILT_IN_PUTS_UNLOCKED, BUILT_IN_REALLOC, BUILT_IN_STACK_RESTORE,
BUILT_IN_STACK_SAVE, BUILT_IN_STRCHR, BUILT_IN_STRCPY,
BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN, BUILT_IN_VFPRINTF, and
BUILT_IN_VPRINTF. Call register_varargs_builtins.  Add handlers
for "getchar", "memset", "fgets", "fgets_unlocked", "fread",
"error", and "error_at_line".
* region-model.cc (region_model::on_stmt_pre): Drop
"out_terminate_path" param.
(region_model::get_known_function): Reimplement by calling
known_function_manager::get_match, passing new "cd" param.
Add overload taking enum internal_fn.
(region_model::on_call_pre): Drop "out_terminate_path" param.
Remove special-case handling of internal fns IFN_BUILTIN_EXPECT,
IFN_UBSAN_BOUNDS, and IFN_VA_ARG, of built-in fns BUILT_IN_ALLOCA,
BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FREE, BUILT_IN_MALLOC,
BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMSET,
BUILT_IN_MEMSET_CHK, BUILT_IN_REALLOC, BUILT_IN_STRCHR,
BUILT_IN_STRCPY, BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN,
BUILT_IN_STACK_SAVE, BUILT_IN_STACK_RESTORE, BUILT_IN_FPRINTF,
BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED,
BUILT_IN_FPUTC, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS,
BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE,
BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF, BUILT_IN_VA_START, and
BUILT_IN_VA_COPY, and of named functions "malloc", "calloc",
"alloca", "realloc", "error", "error_at_line", "fgets",
"fgets_unlocked", "fread", "getchar", "memset", "strchr", and
"strlen".  Replace all this special-casing with calls to
get_known_function for internal fns and for fn decls.
(region_model::on_call_post): Remove special-casing handling for
"free" and "strchr", and for BUILT_IN_REALLOC, BUILT_IN_STRCHR,
and BUILT_IN_VA_END.  Replace by consolidating on usage of
get_known_function.
* region-model.h (call_details::arg_is_size_p): New.
(region_model::on_stmt_pre): Drop "out_terminate_path" param.
(region_model::on_call_pre): Likewise.
(region_model::impl_call_alloca): Delete.
(region_model::impl_call_builtin_expect): Delete.
(region_model::impl_call_calloc): Delete.
(region_model::impl_call_error): Delete.
(region_model::impl_call_fgets): Delete.
(region_model::impl_call_fread): Delete.
(region_model::impl_call_free): Delete.
(region_model::impl_call_malloc): Delete.
(region_model::impl_call_memcpy): Delete.
(region_model::impl_call_memset): Delete.
(region_model::impl_call_realloc): Delete.
(region_model::impl_call_strchr): Delete.
(region_model::impl_call_strcpy): Delete.
(region_model::impl_call_strlen): Delete.
(region_model::impl_call_va_start): Delete.
(region_model::impl_call_va_copy): Delete.
(region_model::impl_call_va_arg): Delete.
(region_model::impl_call_va_end): Delete.
(region_model::check_region_for_write): Public.
(region_model::get_known_function): Add "cd" param.  Add
overloaded decl taking enum internal_fn.
* sm-malloc.cc: Update comments.
* varargs.cc (class kf_va_start): New.
(region_model::impl_call_va_start): Convert to...
(kf_va_start::impl_call_pre): ...this.
(class kf_va_copy): New.
(region_model::impl_call_va_copy): Convert to...
(kf_va_copy::impl_call_pre): ...this.
(class kf_va_arg): New.
(region_model::impl_call_va_arg): Convert to...
(kf_va_arg::impl_call_pre): ...this.
(class kf_va_end): New.
(region_model::impl_call_va_end): Delete.
(register_varargs_builtins): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agotestsuite: Fix missing EFFECTIVE_TARGETS variable errors
Maciej W. Rozycki [Tue, 22 Nov 2022 18:22:16 +0000 (18:22 +0000)]
testsuite: Fix missing EFFECTIVE_TARGETS variable errors

Permit running vector tests outside `check_vect_support_and_set_flags'
environment, removing errors such as:

ERROR: gcc.dg/analyzer/torture/pr93350.c   -O0 : can't read "EFFECTIVE_TARGETS": no such variable for " dg-require-effective-target 1 vect_int "

or:

ERROR: gcc.dg/bic-bitmask-13.c: error executing dg-final: can't read "EFFECTIVE_TARGETS": no such variable

with `mips-linux-gnu' target testing.

The EFFECTIVE_TARGETS variable has originated from commit 9b7937cf8a06
("Add support to run auto-vectorization tests for multiple effective
targets."), where arrangements have been made to run vector tests run
within `check_vect_support_and_set_flags' environment iteratively over
all the vector unit variants available in the architecture using extra
compilation flags regardless of whether the target environment arranged
for a particular testsuite run has vector support enabled by default.
So far this has been used for the MIPS target only.

Vector tests have since been added though that run outside environment
set up by `check_vect_support_and_set_flags' just using the current
compilation environment with no extra flags added.  This works for most
targets, however causes problems with the MIPS target, because outside
`check_vect_support_and_set_flags' environment the EFFECTIVE_TARGETS
variable will not have been correctly set up even if it was added to
the particular script invoking the test in question.

Fix this by using just the current compilation environment whenever a
vector feature is requested by `et-is-effective-target' in the absence
of the EFFECTIVE_TARGETS variable.  This required some modification to
individual vector feature tests, which always added the compilation
flags required for the determination of whether the given vector unit
variant can be verified with the current testsuite run (except for the
Loongson MMI variant).  Now explicit flags are only passed in setting up
EFFECTIVE_TARGETS and otherwise the current compilation environment will
determine whether such a vector test is applicable.

This changes how Loongson MMI is handled in that the `-mloongson-mmi'
flag is explicitly passed for the determination of whether this vector
unit variant can be verified, which I gather is how it was supposed to
be arranged anyway because the flag is then added for testing the
Loongson MMI variant.

gcc/testsuite/
* lib/target-supports.exp
(check_effective_target_mpaired_single): Add `args' argument and
pass it to `check_no_compiler_messages' replacing
`-mpaired-single'.
(add_options_for_mips_loongson_mmi): Add `args' argument and
pass it to `check_no_compiler_messages'.
(check_effective_target_mips_msa): Add `args' argument and pass
it to `check_no_compiler_messages' replacing `-mmsa'.
(check_effective_target_mpaired_single_runtime)
(add_options_for_mpaired_single): Pass `-mpaired-single' to
`check_effective_target_mpaired_single'.
(check_effective_target_mips_loongson_mmi_runtime)
(add_options_for_mips_loongson_mmi): Pass `-mloongson-mmi' to
`check_effective_target_mips_loongson_mmi'.
(check_effective_target_mips_msa_runtime)
(add_options_for_mips_msa): Pass `-mmsa' to
`check_effective_target_mips_msa'.
(et-is-effective-target): Verify that EFFECTIVE_TARGETS exists
and if not, just check if the current compilation environment
supports the target feature requested.
(check_vect_support_and_set_flags): Pass `-mpaired-single',
`-mloongson-mmi', and `-mmsa' to the respective target feature
checks.

23 months agoFix wrong array type conversion with different storage orde
Eric Botcazou [Tue, 22 Nov 2022 18:03:49 +0000 (19:03 +0100)]
Fix wrong array type conversion with different storage orde

When two arrays of scalars have a different storage order in Ada, the
front-end makes sure that the conversion is performed component-wise
so that each component can be reversed.  So it's a little bit counter
productive that the ldist pass performs the opposite transformation
and synthesizes a memcpy/memmove in this case.

gcc/
* tree-loop-distribution.cc (loop_distribution::classify_builtin_ldst):
Bail out if source and destination do not have the same storage order.

gcc/testsuite/
* gnat.dg/sso18.adb: New test.

23 months agolibstdc++: Replace std::isdigit and std::isxdigit in <format> [PR107817]
Jonathan Wakely [Tue, 22 Nov 2022 17:39:43 +0000 (17:39 +0000)]
libstdc++: Replace std::isdigit and std::isxdigit in <format> [PR107817]

These functions aren't usable in constant expressions. Provide our own
implementations, based on __from_chars_alnum_to_val from <charconv>.

libstdc++-v3/ChangeLog:

PR libstdc++/107817
* include/std/charconv (__from_chars_alnum_to_val): Add
constexpr for C++20.
* include/std/format (__is_digit, __is_xdigit): New functions.
(_Spec::_S_parse_width_or_precision): Use __is_digit.
(__formatter_fp::parse): Use __is_xdigit.

23 months agolibstdc++: Add testcase for fs::path constraint recursion [PR106201]
Jonathan Wakely [Tue, 22 Nov 2022 12:17:27 +0000 (12:17 +0000)]
libstdc++: Add testcase for fs::path constraint recursion [PR106201]

libstdc++-v3/ChangeLog:

PR libstdc++/106201
* testsuite/27_io/filesystem/iterators/106201.cc: New test.

23 months agoipa-sra: Dump edge summaries also for non-candidates
Martin Jambor [Tue, 22 Nov 2022 17:22:03 +0000 (18:22 +0100)]
ipa-sra: Dump edge summaries also for non-candidates

This should have been part of r12-578-g717d278af93a4a.  Call edge
summaries provide information required for IPA-SRA transformations in
the callees but are generated when analyzing callers and thus also
callers which are not IPA-SRA candidates themselves.  Therefore we
analyze them but don't dump them, which makes the dumops quite
incomplete. This patch fixes that.

gcc/ChangeLog:

2021-12-14  Martin Jambor  <mjambor@suse.cz>

* ipa-sra.cc (ipa_sra_dump_all_summaries): Dump edge summaries even
for non-candidates.

23 months agoipa-cp: Do not consider useless aggregate constants
Martin Jambor [Tue, 22 Nov 2022 17:22:03 +0000 (18:22 +0100)]
ipa-cp: Do not consider useless aggregate constants

When building vectors of known aggregate values, there is no point in
including those for parameters which are not used in any way
whatsoever.  This patch avoids that together with also other kinds of
constants.

gcc/ChangeLog:

2022-11-13  Martin Jambor  <mjambor@suse.cz>

* ipa-cp.cc (push_agg_values_from_edge): Do not consider constants
in unused aggregate parameters.

23 months agoipa: IPA-SRA split detection simplification
Martin Jambor [Tue, 22 Nov 2022 17:22:03 +0000 (18:22 +0100)]
ipa: IPA-SRA split detection simplification

I have noticed that the flag m_split_modifications_p of
ipa_param_body_adjustments is not really necessary as it has to
correspond to whether m_replacements is non-empty so this patches
removes it.  This also simplifies a bit some patches I work on.

gcc/ChangeLog:

2022-11-10  Martin Jambor  <mjambor@suse.cz>

* ipa-param-manipulation.h (ipa_param_body_adjustments): Removed
member m_split_modifications_p.
* ipa-param-manipulation.cc
(ipa_param_body_adjustments::common_initialization): Do not set
m_split_modifications_p.
(ipa_param_body_adjustments::ipa_param_body_adjustments): Remove
initializations of m_split_modifications_p.
(ipa_param_body_adjustments::modify_call_stmt): Check that
m_replacements is empty instead of m_split_modifications_p.

23 months agoipa-cp: Do not be too optimistic about self-recursive edges (PR 107661)
Martin Jambor [Tue, 22 Nov 2022 17:22:03 +0000 (18:22 +0100)]
ipa-cp: Do not be too optimistic about self-recursive edges (PR 107661)

PR 107661 shows that function push_agg_values_for_index_from_edge
should not attempt to optimize self-recursive call graph edges when
called from cgraph_edge_brings_all_agg_vals_for_node.  Unlike when
being called from find_aggregate_values_for_callers_subset, we cannot
expect that any cloning for constants would lead to the edge leading
from a new clone to the same new clone, in this case it would only be
redirected to a new callee.

Fixed by adding a parameter to push_agg_values_from_edge whether being
optimistic about self-recursive edges is possible.

gcc/ChangeLog:

2022-11-22  Martin Jambor  <mjambor@suse.cz>

PR ipa/107661
* ipa-cp.cc (push_agg_values_from_edge): New parameter
optimize_self_recursion, use it to decide whether to pass interim to
the helper function.
(find_aggregate_values_for_callers_subset): Pass true in the new
parameter of push_agg_values_from_edge.
(cgraph_edge_brings_all_agg_vals_for_node): Pass false in the new
parameter of push_agg_values_from_edge.

gcc/testsuite/ChangeLog:

2022-11-22  Martin Jambor  <mjambor@suse.cz>

PR ipa/107661
* g++.dg/ipa/pr107661.C: New test.

23 months agogcn: Add __builtin_gcn_{get_stack_limit,first_call_this_thread_p}
Tobias Burnus [Tue, 22 Nov 2022 16:54:34 +0000 (17:54 +0100)]
gcn: Add __builtin_gcn_{get_stack_limit,first_call_this_thread_p}

The new builtins have been added for newlib to reduce dependency on
compiler-internal implementation choices of GCC in newlibs' getreent.c.

gcc/ChangeLog:

* config/gcn/gcn-builtins.def (FIRST_CALL_THIS_THREAD_P,
GET_STACK_LIMIT): Add new builtins.
* config/gcn/gcn.cc (gcn_expand_builtin_1): Expand them.
* config/gcn/gcn.md (prologue_use): Add "register_operand" as
arg to match_operand.
(prologue_use_di): New; DI insn_and_split variant of the former.

Co-Authored-By: Andrew Stubbs <ams@codesourcery.com>
23 months agoc++: don't use strchrnul [PR107781]
Jason Merrill [Mon, 21 Nov 2022 22:42:14 +0000 (17:42 -0500)]
c++: don't use strchrnul [PR107781]

The contracts implementation was using strchrnul, which is a glibc
extension, so bootstrap broke on non-glibc targets.  Use C89 strcspn
instead.

PR c++/107781

gcc/cp/ChangeLog:

* contracts.cc (role_name_equal): Use strcspn instead
of strchrnul.

23 months agoaarch64: Fix test_dfp_17.c for big-endian [PR 107604]
Christophe Lyon [Tue, 22 Nov 2022 08:33:06 +0000 (08:33 +0000)]
aarch64: Fix test_dfp_17.c for big-endian [PR 107604]

gcc.target/aarch64/aapcs64/test_dfp_17.c has been failing on
big-endian, because the _Decimal32 on-stack argument is not padded in
the same direction depending on endianness.

This patch fixes the testcase so that it expects the argument in the
right stack location, similarly to what other tests do in the same
directory.

gcc/testsuite/ChangeLog:

PR target/107604
* gcc.target/aarch64/aapcs64/test_dfp_17.c: Fix for big-endian.

23 months agoada: Accept aspects Global and Depends on abstract subprograms
Piotr Trojanek [Mon, 21 Nov 2022 10:31:29 +0000 (11:31 +0100)]
ada: Accept aspects Global and Depends on abstract subprograms

Aspects Global and Depends are now allowed on abstract subprograms
(as substitutes for Global'Class and Depends'Class).

This patch implements the recently modified rules SPARK RM 6.1.2(2-3).
The behavior for Contract_Cases and aspects on null subprograms stays
as it was.

gcc/ada/

* sem_prag.adb (Analyze_Depends_Global): Accept aspects on
abstract subprograms.

23 months agoada: Disable checking of Elab_Spec procedures in CodePeer_Mode
Ghjuvan Lacambre [Fri, 18 Nov 2022 15:05:12 +0000 (16:05 +0100)]
ada: Disable checking of Elab_Spec procedures in CodePeer_Mode

This commit re-enables the Validate_Subprogram_Calls check that had been
disabled in a previous commit and has said check skip over Elab_Spec
procedures in CodePeer_Mode.

gcc/ada/

* frontend.adb (Frontend): Re-enable Validate_Subprogram_Calls.
* exp_ch6.adb (Check_BIP_Actuals): When in CodePeer mode, do not
attempt to validate procedures coming from an
Elab_Spec/Elab_Body/Elab_Subp_Body procedure.

23 months agoada: Adjust number of errors when removing warning in dead code
Piotr Trojanek [Mon, 7 Nov 2022 14:17:40 +0000 (15:17 +0100)]
ada: Adjust number of errors when removing warning in dead code

When a warning about a runtime exception is emitted for a code in
generic instance, we add continuation warnings "in instantiation ..."
and only the original message increase the total number of errors.

When removing these messages, e.g. after detecting that the code inside
generic instance is dead, we must decrease the total number of errors,
as otherwise the compiler exit status might stop gnatmake or gprbuild.

gcc/ada/

* errout.adb (To_Be_Removed): Decrease total number of errors when
removing a warning that has been escalated into error.
* erroutc.adb (dmsg): Print Warn_Runtime_Raise flag.

23 months agoada: Fix formatting glitches in Make_Tag_Assignment
Eric Botcazou [Sat, 19 Nov 2022 19:43:40 +0000 (20:43 +0100)]
ada: Fix formatting glitches in Make_Tag_Assignment

gcc/ada/

* exp_ch3.adb (Make_Tag_Assignment): Fix formatting glitches.

23 months agoada: Fix recent assertion failure on GPR2
Eric Botcazou [Sat, 19 Nov 2022 17:01:21 +0000 (18:01 +0100)]
ada: Fix recent assertion failure on GPR2

It's the compiler trying to load the nonexistent body of a generic package
when trying to inline a call to an expression function of this package that
has a pre or post-condition (hence the need for -gnata to trigger the ICE).

gcc/ada/

* contracts.adb (Build_Subprogram_Contract_Wrapper): Do not fiddle
with the Was_Expression_Function flag. Move a few lines around.

23 months agotree-optimization/107803 - abnormal cleanup from the SSA propagator
Richard Biener [Tue, 22 Nov 2022 09:16:14 +0000 (10:16 +0100)]
tree-optimization/107803 - abnormal cleanup from the SSA propagator

The SSA propagator is missing abnormal cleanup which shows in a
sanity check in the uninit engine (and missed CFG verification).
The following adds that.

PR tree-optimization/107803
* tree-ssa-propagate.cc (substitute_and_fold_dom_walker): Add
need_ab_cleanup member.
(substitute_and_fold_dom_walker::before_dom_children): When
a stmt can no longer transfer control flow abnormally set
need_ab_cleanup.
(substitute_and_fold_engine::substitute_and_fold): Cleanup
abnormal control flow.

* g++.dg/pr107803.C: New testcase.

23 months agolibstdc++: Fix pool resource build errors for H8 [PR107801]
Jonathan Wakely [Tue, 22 Nov 2022 09:53:36 +0000 (09:53 +0000)]
libstdc++: Fix pool resource build errors for H8 [PR107801]

The array of pool sizes was previously adjusted to work for msp430-elf
which has 16-bit int and either 16-bit size_t or 20-bit size_t. The
largest pool sizes were disabled unless size_t has more than 20 bits.

The H8 family has 16-bit int but 32-bit size_t, which means that the
largest sizes are enabled, but 1<<15 produces a negative number that
then cannot be narrowed to size_t.

Replace the test for 32-bit size_t with a test for 32-bit int, which
means we won't use the 4kiB to 4MiB pools for targets with 16-bit int
even if they have a wider size_t.

libstdc++-v3/ChangeLog:

PR libstdc++/107801
* src/c++17/memory_resource.cc (pool_sizes): Disable large pools
for targets with 16-bit int.

23 months agotree-optimization/107672 - avoid vector mode type_for_mode call
Richard Biener [Tue, 22 Nov 2022 08:03:53 +0000 (09:03 +0100)]
tree-optimization/107672 - avoid vector mode type_for_mode call

The following avoids using type_for_mode on vector modes which might
not work for all frontends.  Instead we look for the inner mode
type and use build_vector_type_for_mode instead.

PR tree-optimization/107672
* tree-vect-stmts.cc (supportable_widening_operation): Avoid
type_for_mode on vector modes.

23 months agotree-optimization/107766 - ICE with recent -ffp-contract=off fix
Richard Biener [Mon, 21 Nov 2022 06:56:06 +0000 (07:56 +0100)]
tree-optimization/107766 - ICE with recent -ffp-contract=off fix

The following uses *node to check for FP types rather than the
child nodes which could be constant leafs and thus without a
vector type.

PR tree-optimization/107766
* tree-vect-slp-patterns.cc (complex_mul_pattern::matches):
Use *node to check for FP vector types.

* g++.dg/vect/pr107766.cc: New testcase.

23 months agoGuard 64/32-bit vector move patterns with ix86_hard_reg_move_ok.
liuhongt [Mon, 21 Nov 2022 08:09:13 +0000 (16:09 +0800)]
Guard 64/32-bit vector move patterns with ix86_hard_reg_move_ok.

gcc/ChangeLog:

* config/i386/mmx.md (*mov<mode>_internal): Add
ix86_hard_reg_move_ok to condition.

23 months agoSome tidy up for RA related hooks.
liuhongt [Fri, 18 Nov 2022 08:08:08 +0000 (16:08 +0800)]
Some tidy up for RA related hooks.

1. We also need to guard size of TO to be
less than TARGET_SSE2 ? 2 : 4 in ix86_can_change_mode_class.
2. Merge VALID_AVX512FP16_SCALAR_MODE plus BFmode
into VALID_AVX512F_SCALAR_MODE since we've support 16-bit data move
above SSE2, so no need for the condition of AVX512FP16 for those evex
sse registers.
3. Allocate DI/HImode to sse register for SSE2 above just like
SImode since we've supported 16-bit data move between sse and gpr
above SSE2, this will help RA to handle cases like (subreg:HI (reg:V8HI)
0) or else RA will spill it. This enable optimization for
pices-memset-{3,37,39}.c

gcc/ChangeLog:

* config/i386/i386.cc (ix86_can_change_mode_class): Also guard
size of TO.
(ix86_hard_regno_mode_ok): Remove VALID_AVX512FP16_SCALAR_MODE
* config/i386/i386.h (VALID_AVX512FP16_SCALAR_MODE): Merged to
..
(VALID_AVX512F_SCALAR_MODE): .. this, also add HImode.
(VALID_SSE_REG_MODE): Add DI/HImode.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pieces-memset-3.c: Remove xfail.
* gcc.target/i386/pieces-memset-37.c: Remove xfail.
* gcc.target/i386/pieces-memset-39.c: Remove xfail.

23 months agoc++: contracts fixes
Jason Merrill [Mon, 21 Nov 2022 22:58:07 +0000 (17:58 -0500)]
c++: contracts fixes

Fixing -Wunused-parm warnings and link errors depending on where -fcontracts
appears on the command line.

gcc/cp/ChangeLog:

* contracts.cc (build_contract_condition_function):
Set DECL_ARTIFICIAL on return value parm.
* g++spec.cc (lang_specific_driver): Add -lstdc++exp
just before -lstdc++.

23 months agoDaily bump.
GCC Administrator [Tue, 22 Nov 2022 00:17:49 +0000 (00:17 +0000)]
Daily bump.

23 months agoanalyzer: fix ICE on 'bind' that returns a struct [PR107788]
David Malcolm [Tue, 22 Nov 2022 00:08:18 +0000 (19:08 -0500)]
analyzer: fix ICE on 'bind' that returns a struct [PR107788]

gcc/analyzer/ChangeLog:
PR analyzer/107788
* region-model.cc (region_model::update_for_int_cst_return):
Require that the return type be an integer type.
(region_model::update_for_nonzero_return): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/107788
* g++.dg/analyzer/fd-bind-pr107783.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: fix ICE on 'bind' with non-pointer arg [P107783]
David Malcolm [Tue, 22 Nov 2022 00:08:17 +0000 (19:08 -0500)]
analyzer: fix ICE on 'bind' with non-pointer arg [P107783]

gcc/analyzer/ChangeLog:
PR analyzer/107783
* region-model-impl-calls.cc (kf_accept::matches_call_types_p):
Require that args 1 and 2 be pointers.
(kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
* region-model.h (call_details::arg_is_pointer_p): New

gcc/testsuite/ChangeLog:
PR analyzer/107783
* gcc.dg/analyzer/fd-bind-pr107783.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: fix ICE on writes to errno [PR107777]
David Malcolm [Tue, 22 Nov 2022 00:08:17 +0000 (19:08 -0500)]
analyzer: fix ICE on writes to errno [PR107777]

gcc/analyzer/ChangeLog:
PR analyzer/107777
* call-summary.cc
(call_summary_replay::convert_region_from_summary_1): Handle
RK_THREAD_LOCAL and RK_ERRNO in switch.
* region-model.cc (region_model::get_representative_path_var_1):
Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/107777
* gcc.dg/analyzer/call-summaries-errno.c: New test.
* gcc.dg/analyzer/errno-pr107777.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer, testsuite: add more examples taken from CWE
David Malcolm [Tue, 22 Nov 2022 00:08:17 +0000 (19:08 -0500)]
analyzer, testsuite: add more examples taken from CWE

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/CWE-131-examples.c: New test.
* gcc.dg/analyzer/file-CWE-1341-example.c: New test.
* gcc.dg/analyzer/malloc-CWE-401-example.c: New test.
* gcc.dg/analyzer/malloc-CWE-415-examples.c: New test.
* gcc.dg/analyzer/malloc-CWE-416-examples.c: New test.
* gcc.dg/analyzer/malloc-CWE-590-examples.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agolibcpp: Fix paste error with unknown pragma after macro expansion
Lewis Hyatt [Wed, 2 Nov 2022 20:04:36 +0000 (16:04 -0400)]
libcpp: Fix paste error with unknown pragma after macro expansion

In directives.cc, do_pragma() contains logic to handle a case such as the new
testcase pragma-omp-unknown.c, where an unknown pragma was the result of macro
expansion (for pragma namespaces that permit expansion). This no longer works
correctly as shown by the testcase, fixed by adding PREV_WHITE to the flags on
the second token to prevent an unwanted paste.  Also fixed the memory leak,
since the temporary tokens are pushed on their own context, nothing prevents
freeing of the buffer that holds them when the context is eventually popped.

libcpp/ChangeLog:

* directives.cc (do_pragma): Fix memory leak in token buffer.  Fix
unwanted paste between two tokens.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/pragma-omp-unknown.c: New test.

23 months agoRTEMS: Use local-exec TLS model by default
Sebastian Huber [Fri, 22 Jul 2022 12:11:10 +0000 (14:11 +0200)]
RTEMS: Use local-exec TLS model by default

gcc/ChangeLog:

* config/rtems.h (SUBTARGET_CC1_SPEC): Undef and define.

23 months agoAllow subtarget customization of CC1_SPEC
Sebastian Huber [Mon, 21 Nov 2022 06:49:15 +0000 (07:49 +0100)]
Allow subtarget customization of CC1_SPEC

gcc/ChangeLog:

* gcc.cc (SUBTARGET_CC1_SPEC): Define if not defined.
(cc1_spec): Append SUBTARGET_CC1_SPEC.

23 months agolibstdc++: Reduce size of std::bind_front(F) result
Jonathan Wakely [Mon, 21 Nov 2022 11:30:55 +0000 (11:30 +0000)]
libstdc++: Reduce size of std::bind_front(F) result

When there are no bound arguments to a std::bind_front call we don't
need the overhead of compiling, initializing, and accessing an empty
tuple.

libstdc++-v3/ChangeLog:

* include/std/functional (_Bind_front0): New class template.
(_Bind_front_t): Use _Bind_front0 when there are no bound
arguments.
* testsuite/20_util/function_objects/bind_front/107784.cc:
New test.

23 months agolibstdc++: Check static assertions earlier in chrono::duration
Jonathan Wakely [Mon, 21 Nov 2022 11:52:34 +0000 (11:52 +0000)]
libstdc++: Check static assertions earlier in chrono::duration

This ensures that we fail a static assertion before giving any other
errors. Instantiating chrono::duration<int, chrono::seconds> will now
print this before the other errors caused by it:

error: static assertion failed: period must be a specialization of ratio

libstdc++-v3/ChangeLog:

* include/bits/chrono.h (duration): Check preconditions on
template arguments before using them.

23 months agolibstdc++: Improve Doxygen comments in <tuple>
Jonathan Wakely [Mon, 21 Nov 2022 14:12:52 +0000 (14:12 +0000)]
libstdc++: Improve Doxygen comments in <tuple>

libstdc++-v3/ChangeLog:

* include/std/tuple: Add better Doxygen comments.

23 months agotestsuite: Add filter for target socket support
Dimitar Dimitrov [Fri, 18 Nov 2022 19:59:42 +0000 (21:59 +0200)]
testsuite: Add filter for target socket support

The new analyzer tests for sockets are failing on embedded targets.
The newlib and avr-libc C libraries do not support sockets.

Testing done:
  - No changes in gcc.sum for x86_64-pc-linux-gnu, with or without this
    patch.
  - Filtered cases are now UNSUPPORTED instead of failing on AVR and PRU
    backends.

gcc/ChangeLog:

* doc/sourcebuild.texi (sockets): Document new check.

gcc/testsuite/ChangeLog:

* gcc.dg/analyzer/fd-accept.c: Require sockets.
* gcc.dg/analyzer/fd-bind.c: Ditto.
* gcc.dg/analyzer/fd-connect.c: Ditto.
* gcc.dg/analyzer/fd-datagram-socket.c: Ditto.
* gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c:
Ditto.
* gcc.dg/analyzer/fd-glibc-byte-stream-socket.c: Ditto.
* gcc.dg/analyzer/fd-glibc-datagram-client.c: Ditto.
* gcc.dg/analyzer/fd-glibc-datagram-socket.c: Ditto.
* gcc.dg/analyzer/fd-listen.c: Ditto.
* gcc.dg/analyzer/fd-manpage-getaddrinfo-client.c: Ditto.
* gcc.dg/analyzer/fd-mappage-getaddrinfo-server.c: Ditto.
* gcc.dg/analyzer/fd-socket-meaning.c: Ditto.
* gcc.dg/analyzer/fd-socket-misuse.c: Ditto.
* gcc.dg/analyzer/fd-stream-socket-active-open.c: Ditto.
* gcc.dg/analyzer/fd-stream-socket-passive-open.c: Ditto.
* gcc.dg/analyzer/fd-stream-socket.c: Ditto.
* gcc.dg/analyzer/fd-symbolic-socket.c: Ditto.
* lib/target-supports.exp (check_effective_target_sockets): New
check.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
23 months agoExpand comment for tree_niter_desc.max
Andrew Carlotti [Wed, 9 Nov 2022 15:59:21 +0000 (15:59 +0000)]
Expand comment for tree_niter_desc.max

This requirement is enforced by a gcc_checking_assert in
record_estimate.

gcc/ChangeLog:

* tree-ssa-loop.h (tree_niter_desc): Update comment.

23 months agoModify test, to prevent the next patch breaking it
Andrew Carlotti [Mon, 7 Nov 2022 14:35:08 +0000 (14:35 +0000)]
Modify test, to prevent the next patch breaking it

The upcoming c[lt]z idiom recognition patch eliminates the need for a
brute force computation of the iteration count of these loops. The test
is intended to verify that ivcanon can determine the loop count when the
condition is given by a chain of constant computations.

We replace the constant operations with a more complicated chain that should
resist future idiom recognition.

gcc/testsuite/ChangeLog:

* gcc.dg/pr77975.c: Make tests more robust.

23 months agoRefactor number_of_iterations_popcount
Andrew Carlotti [Tue, 4 Oct 2022 17:21:57 +0000 (18:21 +0100)]
Refactor number_of_iterations_popcount

This includes various changes to improve clarity, and to enable the code
to be more similar to the clz and ctz idiom recognition added in
subsequent patches.

We create new number_of_iterations_bitcount function, which will be used
to call the other bit-counting recognition functions added in subsequent
patches, as well as a generic comment describing the loop structures
that are common to each idiom. Some of the variables in
number_of_iterations_popcount are given more descriptive names, and the
popcount expression builder is extracted into a separate function.

As part of the refactoring, we also fix a bug where the max loop count
for modes shorter than an integer would be incorrectly computed as if
the input mode were actually an integer.

We also ensure that niter->max takes into account the final value for
niter->niter (after any folding and simplifying), since if the latter is a
constant, then record_estimate mandates that the two values are equivalent.

gcc/ChangeLog:

* tree-ssa-loop-niter.cc
(number_of_iterations_exit_assumptions): Modify to call...
(number_of_iterations_bitcount): ...this new function.
(number_of_iterations_popcount): Now called by the above.
Refactor, and extract popcount expression builder to...
(build_popcount_expr): this new function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/popcount-max.c: New test.

23 months agoRemove prototype for number_of_iterations_popcount
Andrew Carlotti [Tue, 4 Oct 2022 17:15:12 +0000 (18:15 +0100)]
Remove prototype for number_of_iterations_popcount

gcc/ChangeLog:

* tree-ssa-loop-niter.cc (ssa_defined_by_minus_one_stmt_p): Move
(number_of_iterations_popcount): Move, and remove separate prototype.

23 months agoEnsure at_stmt is defined before an early exit
Andrew Carlotti [Thu, 6 Oct 2022 14:59:15 +0000 (15:59 +0100)]
Ensure at_stmt is defined before an early exit

This prevents a null dereference error when outputing debug information
following an early exit from number_of_iterations_exit_assumptions.

gcc/ChangeLog:

* tree-ssa-loop-niter.cc (number_of_iterations_exit_assumptions):
Move at_stmt assignment.

23 months agotestsuite: Windows paths use \ and not /
Torbjörn SVENSSON [Tue, 25 Oct 2022 15:04:07 +0000 (17:04 +0200)]
testsuite: Windows paths use \ and not /

Without this patch, the following error is reported on Windows:

In file included from t:\build\arm-none-eabi\include\c++\11.3.1\string:54,
                  from t:\build\arm-none-eabi\include\c++\11.3.1\bits\locale_classes.h:40,
                  from t:\build\arm-none-eabi\include\c++\11.3.1\bits\ios_base.h:41,
                  from t:\build\arm-none-eabi\include\c++\11.3.1\ios:42,
                  from t:\build\arm-none-eabi\include\c++\11.3.1\ostream:38,
                  from t:\build\arm-none-eabi\include\c++\11.3.1\iostream:39:
t:\build\arm-none-eabi\include\c++\11.3.1\bits\range_access.h:36:10: note: include 't:\build\arm-none-eabi\include\c++\11.3.1\initializer_list' translated to import
arm-none-eabi-g++.exe: warning: .../gcc/testsuite/g++.dg/modules/pr99023_b.X: linker input file unused because linking not done
FAIL: g++.dg/modules/pr99023_b.X -std=c++2a  dg-regexp 6 not found: "[^\n]*: note: include '[^\n]*/initializer_list' translated to import\n"

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99023_b.X: Match Windows paths too.

Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
23 months agolibgomp/gcn: fix/improve struct output
Tobias Burnus [Mon, 21 Nov 2022 14:22:35 +0000 (15:22 +0100)]
libgomp/gcn: fix/improve struct output

output.printf_data.(value union) contains text[128], which has the size
of 128 bytes, sufficient for 16 uint64_t variables; hence value_u64[2]
could be extended to value_u64[6] - sufficient for all required arguments
to gomp_target_rev.  Additionally, next_output.printf_data.(msg union)
contained msg_u64 which then is no longer needed and also caused 32bit
vs 64bit alignment issues.

libgomp/
* config/gcn/libgomp-gcn.h (struct output):
Remove 'msg_u64' from the union, change
value_u64[2] to value_u64[6].
* config/gcn/target.c (GOMP_target_ext): Update accordingly.
* plugin/plugin-gcn.c (process_reverse_offload, console_output):
Likewise.

23 months agolibcpp/remap: Only override if string matched
Torbjörn SVENSSON [Thu, 20 Oct 2022 20:38:57 +0000 (22:38 +0200)]
libcpp/remap: Only override if string matched

For systems with HAVE_DOS_BASED_FILE_SYSTEM set, only override the
pointer if the backslash pattern matches.

Output without this patch:
.../gcc/testsuite/gcc.dg/cpp/pr71681-2.c:5:10: fatal error: a/t2.h: No such file or directory

With patch applied, no output and the test case succeeds.

libcpp/ChangeLog

* files.cc: Ensure pattern matches before use.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
23 months agogenmultilib: Fix sanity check
Christophe Lyon [Mon, 21 Nov 2022 11:12:14 +0000 (12:12 +0100)]
genmultilib: Fix sanity check

My previous patch to add a sanity check to genmultilib actually
checked the number of dirnames with the number of "sets of options"
rather than the number of options, thus breaking the build on some
targets.

To avoid duplicating once more the loop that constructs the sed
patterns, this patch checks that the current dirname/osdirname is not
empty in the existing loops.

Are there targets where:
if [ "$1" != "${opt}" ]; then
is "legally" executed with an empty $1? (and thus where this patch
would incorrectly trigger an error?)

Sorry for the breakage. Tested on aarch64 by adding an option to
t-aarch64 and no corresponding dirname, and on x86_64.

gcc/ChangeLog:

* genmultilib: Fix options and dirnames/osdirnames sanity check.

23 months agoRISC-V: Fix ICE in branch<ANYI:mode>_shiftedarith_equals_zero
Philipp Tomsich [Mon, 21 Nov 2022 11:44:23 +0000 (12:44 +0100)]
RISC-V: Fix ICE in branch<ANYI:mode>_shiftedarith_equals_zero

With the recent improvements to the splitting of special cases of
branch patterns on RISC-V, a dependency on an unmerged/in-discussion
change for branch-equals-zero slipped in: this allowed a non-X mode to
be presented to branch-equals-zero (where only X mode is permissible).

This addresses the issue by wrapping the ANYI operand in a paradoxical
SUBREG:X (the high bits can be safely ignored, as we we perform an
and-immediate before the branch in the pattern).

Tested against the GCC testsuite and committed as obvious.

gcc/ChangeLog:

PR target/107786
* config/riscv/riscv.md
(*branch<ANYI:mode>_shiftedarith_equals_zero): Wrap ANYI
in a subreg, as our branch instructions only supports X.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr107786-2.c: New test.
* gcc.target/riscv/pr107786.c: New test.

23 months agoada: Adjust recent change for returns involving function calls
Eric Botcazou [Wed, 16 Nov 2022 02:58:17 +0000 (03:58 +0100)]
ada: Adjust recent change for returns involving function calls

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Constant>: Revert
latest change.
* gcc-interface/trans.cc (gnat_to_gnu) <N_Object_Declaration>:
Tweak latest change.

23 months agoada: Do not share Packed Array Type if sizes of types differ
Marc Poulhiès [Tue, 15 Nov 2022 15:47:59 +0000 (16:47 +0100)]
ada: Do not share Packed Array Type if sizes of types differ

If a subtype has a Size attribute value different than the size of its
ancestor, then the Packed Array Type can't be shared and a new one must
be created.

gcc/ada/

* exp_pakd.adb (Create_Packed_Array_Impl_Type): Do not share PAT
if sizes of types differ.

23 months agoada: Order pragmas alphabetically in reference manual
Ronan Desplanques [Thu, 17 Nov 2022 13:37:12 +0000 (14:37 +0100)]
ada: Order pragmas alphabetically in reference manual

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst: Restore
alphabetical ordering.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

23 months agoada: Minor tweak in assertion
Eric Botcazou [Thu, 17 Nov 2022 12:31:33 +0000 (13:31 +0100)]
ada: Minor tweak in assertion

For an array subtype, being definite is the same as being constrained.

gcc/ada/

* sem_util.adb (Needs_Secondary_Stack): Test Is_Constrained
directly instead of Is_Definite_Subtype for an array subtype.

23 months agoada: Internal compiler error for Sequential Partition_Elaboration_Policy
Steve Baird [Wed, 16 Nov 2022 17:28:22 +0000 (09:28 -0800)]
ada: Internal compiler error for Sequential Partition_Elaboration_Policy

In some cases, compilation of a function with a limited class-wide result
type could fail with an internal error if a Sequential
Partition_Elaboration_Policy is specified. To prevent this, we want specifying
a Sequential Partition_Elaboration_Policy to have the side effect of
imposing a No_Task_Hierarchy restriction. But doing that in a straightforward
way leads to problems with incorrectly accepting violations of H.6(6). So
a new restriction, No_Task_Hierarchy_Implicit, is introduced.

gcc/ada/

* libgnat/s-rident.ads: Define a new restriction,
No_Task_Hierarchy_Implicit. This is like the No_Task_Hierarchy
restriction, but with the difference that setting this restriction
does not mean the H.6(6) post-compilation check is satisified.
* exp_ch6.adb (Add_Task_Actuals_To_Build_In_Place_Call): If it is
known that the function result cannot have tasks, then pass in a
null literal for the activation chain actual parameter. This
avoids generating a reference to an entity that
Build_Activation_Chain_Entity may have chosen not to generate a
declaration for.
* gnatbind.adb (List_Applicable_Restrictions): Do not list the
No_Task_Hierarchy_Implicit restriction.
* restrict.adb: Special treatment for the
No_Task_Hierarchy_Implicit restriction in functions
Get_Restriction_Id and Restriction_Active. The former is needed to
disallow the (unlikely) case that a user tries to explicitly
reference the No_Task_Hierarchy_Implicit restriction.
* sem_prag.adb (Analyze_Pragma): If a Sequential
Partition_Elaboration_Policy is specified (and the
No_Task_Hierarchy restriction is not already enabled), then enable
the No_Task_Hierarchy_Implicit restriction.

23 months agoada: Small cleanup in Expand_N_Object_Declaration
Eric Botcazou [Tue, 15 Nov 2022 07:53:46 +0000 (08:53 +0100)]
ada: Small cleanup in Expand_N_Object_Declaration

This reuses a local constant more consistently, removes a duplicate of this
local constant, renames local variables, alphabetizes declarations, makes a
few consistency tweaks and adjusts a couple of comments.

No functional changes.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Use Typ local
constant throughout, remove Ret_Obj_Typ local constant, rename
Ref_Type into Acc_Typ in a couple of places, remove a useless call
to Set_Etype, use a consistent checks suppression scheme, adjust
comments for the sake of consistencty and alphabetize some local
declarations.
* exp_ch6.adb (Expand_Simple_Function_Return): Remove a couple of
redundant local constants.

23 months agoada: Ada 2022 Image attribute bugs
Steve Baird [Fri, 11 Nov 2022 01:15:33 +0000 (17:15 -0800)]
ada: Ada 2022 Image attribute bugs

Two issues. First, the two procedures
Ada.Strings.Text_Buffers.Output_Mapping.[Wide_]Wide_Put each correctly
call Encode, but that call was missing from the corresponding Put procedure.
Second, if a record type contains an array-valued Data component as well as
both a Max_Length and Current_Length component, then the slice
Data (Current_Length + 1 .. Max_Length) should usually be treated like
uninitialized data. It should not participate in things like equality
comparisons. In particular, it should not participate in 'Image results.
To accomplish this, such a type usually ought to have a Put_Image aspect
specification. This Put_Image aspect specification was missing for the
three Super_String types declared in the
Ada.Strings.[Wide_[Wide_]]Superbounded packages.

gcc/ada/
* libgnat/a-sttebu.adb (Put): Add missing call to Encode.
* libgnat/a-strsup.ads: Declare new Put_Image procedure and add
Put_Image aspect specification for type Super_String.
* libgnat/a-strsup.adb (Put_Image): New procedure.
* libgnat/a-stwisu.ads: Declare new Put_Image procedure and add
Put_Image aspect specification for type Super_String.
* libgnat/a-stwisu.adb (Put_Image): New procedure.
* libgnat/a-stzsup.ads: Declare new Put_Image procedure and add
Put_Image aspect specification for type Super_String.
* libgnat/a-stzsup.adb (Put_Image): New procedure.

23 months agoada: Disable subprogram call validation in CodePeer mode
Ghjuvan Lacambre [Wed, 16 Nov 2022 14:53:17 +0000 (15:53 +0100)]
ada: Disable subprogram call validation in CodePeer mode

CodePeer builds with assertions enabled started failing when this
validation was introduced. We temporarily disable this validation for
CodePeer in order to buy time before fixing the underlying issue.

gcc/ada/

* frontend.adb (Frontend): Disable subprogram call validation.

23 months agoada: Move warnings switches
Bob Duff [Tue, 15 Nov 2022 18:57:49 +0000 (13:57 -0500)]
ada: Move warnings switches

This patch moves warning switches from Opt into Warnsw, fixes some minor
discrepancies, and cleans up the code.

No change in behavior.

gcc/ada/

* warnsw.ads, warnsw.adb: Move warning flags here from package
Opt. Rename Warning_Record to be Warnings_State. Use an array
instead of a record; this simplifies the code. Add renamings of
all the array components for easy reference outside this package.
Pass the "Family" to Set_Warning_Switch. Use more table-driven
code. Misc cleanup and comment fixes.
* opt.ads: Move warning switches to Warnsw.
* gnat1drv.adb
(Adjust_Global_Switches): Expanded names needed.
* inline.ads: Rename Warning_Record to be Warnings_State.
* sem_ch12.adb: Likewise.
* sem_prag.adb: Use new Set_Warning_Switch.
* contracts.adb, errout.adb, exp_aggr.adb, exp_ch11.adb: Adjust
imports for move to Warnsw.
* exp_ch5.adb, exp_prag.adb, exp_util.adb, frontend.adb: Likewise.
* layout.adb, lib-xref.adb, restrict.adb, scn.adb, sem_aggr.adb:
Likewise.
* sem_attr.adb, sem_case.adb, sem_ch10.adb, sem_ch11.adb:
Likewise.
* sem_ch13.adb, sem_ch3.adb, sem_ch4.adb, sem_ch5.adb: Likewise.
* sem_ch6.adb, sem_ch7.adb, sem_ch8.adb, sem_elab.adb: Likewise.
* sem_eval.adb, sem_res.adb, sem_util.adb, sem_warn.adb: Likewise.
* switch-c.adb: Likewise.

23 months agoada: Improve documentation for -gnatw.h warnings
Steve Baird [Wed, 9 Nov 2022 23:53:49 +0000 (15:53 -0800)]
ada: Improve documentation for -gnatw.h warnings

The -gnatw.h option enables warnings about "gaps" in record layout
specifications. In the case of a "partial" layout specification, where the
locations of some components are left unspecified, the resulting warnings
may be incomplete or incorrect. Document this implementation limitation.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Improve
the description of how the -gnatw.h switch interacts with
"partial" record layout specifications (i.e., specifications where
the locations of some components are left unspecified).
* gnat_ugn.texi: Regenerate.

23 months agoada: Reject nonconfirming Size attribute value for aliased object
Marc Poulhiès [Mon, 7 Nov 2022 13:34:54 +0000 (14:34 +0100)]
ada: Reject nonconfirming Size attribute value for aliased object

Only confirming Size must be supported for aliased object of elementary
type (see RM 13.1 in the "Implementation Advice").

   -- size is 1-byte
   type Y is range 0 .. 20;
   type Ay is access all Y;

   -- Var size is 8-bytes
   Var : aliased Y := 5 with Size => 64;

   --  JP.all is a 1-byte reference to an 8-bytes objects.
   JP : Ay := Var'Access;

The above JP.all references the first byte of the 8-byte Var object,
which is, for example, not correct on little-endian systems.

This change rejects nonconfirming Size attribute on such objects
instead of miscompiling it.

gcc/ada/

* sem_ch13.adb (Check_One_Attr): produce error when Size attribute
used on aliased object of elementary types with nonconfirming
value.

23 months agoada: Fix gnatmake's parsing of adc files
Ronan Desplanques [Fri, 4 Nov 2022 15:54:35 +0000 (16:54 +0100)]
ada: Fix gnatmake's parsing of adc files

Before this patch, gnatmake's parser for adc files failed to ignore
semicolons located inside comments. This patch fixes that behavior.

gcc/ada/

* sfn_scan.adb (Scan_SFN_Pragmas): Improve handling of comments.

23 months agoada: Tweak error messages on misplaced with keywords
Ronan Desplanques [Wed, 9 Nov 2022 12:32:05 +0000 (13:32 +0100)]
ada: Tweak error messages on misplaced with keywords

Before this patch, with clauses placed in declarative sections were
interpreted by the compiler as incorrect aspect specifications, which
led to confusing error messages.

This patch makes it so more syntax errors involving the with keyword
are diagnosed as intended with clauses instead of aspect
specifications.

gcc/ada/

* par-ch3.adb (P_Declarative_Item): Tweak handling of with keyword.