platform/upstream/gcc.git
2 years agomatch.pd: Optimize __builtin_mul_overflow_p (x, cst, (stype)0) [PR105777]
Jakub Jelinek [Fri, 3 Jun 2022 09:41:21 +0000 (11:41 +0200)]
match.pd: Optimize __builtin_mul_overflow_p (x, cst, (stype)0) [PR105777]

The following patch is an incremental change to the PR30314 enhancement,
this one handles signed types.
For signed types (but still, the same for 1st and result element type
and non-zero constant that fits into that type), we actually need to
watch for overflow in direction to positive and negative infinity
and it also depends on whether the cst operand is positive or negative.
For __builtin_mul_overflow_p (x, cst, (stype) 0):
For cst > 0, we can simplify it to:
x > INT_MAX / cst || x < INT_MIN / cst
aka:
x + (unsigned) (INT_MIN / cst) > (unsigned) (INT_MAX / cst) - (unsigned) (INT_MIN / cst)
and for cst < 0 to:
x < INT_MAX / cst || x > INT_MIN / cst
aka:
x + (unsigned) (INT_MAX / cst) > (unsigned) (INT_MIN / cst) - (unsigned) (INT_MAX / cst)

Additionally, I've added executable testcases, so we don't just check for
the optimization to be performed, but also that it is correct (done that
even for the other PR's testcase).

2022-06-03  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/30314
PR middle-end/105777
* match.pd (__builtin_mul_overflow_p (x, cst, (stype) 0) ->
x > stype_max / cst || x < stype_min / cst): New simplification.

* gcc.dg/tree-ssa/pr30314.c: Add noipa attribute to all functions.
* gcc.dg/tree-ssa/pr105777.c: New test.
* gcc.c-torture/execute/pr30314.c: New test.
* gcc.c-torture/execute/pr105777.c: New test.

2 years agoMisc range temporary fixes.
Aldy Hernandez [Thu, 2 Jun 2022 17:52:41 +0000 (19:52 +0200)]
Misc range temporary fixes.

This fixes a couples places that were using int_range_max, but needed
a generic temporary.  Found while merging the frange work.

Also, copying between range temporaries is actually useful :).

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-cache.cc (ranger_cache::range_from_dom): Use
Value_Range.
* gimple-range.cc (gimple_ranger::register_inferred_ranges): Same.
* value-range.h (Value_Range::Value_Range): Implement copy
constructor for Value_Range.

2 years agoRemove unneeded vrange_traits.
Aldy Hernandez [Wed, 1 Jun 2022 15:41:10 +0000 (17:41 +0200)]
Remove unneeded vrange_traits.

The traits struct is no longer needed.

Tested on x86-64 Linux.

gcc/ChangeLog:

* value-range.h (struct vrange_traits): Remove.
(is_a): Rewrite without vrange_traits.
(as_a): Same.

2 years agoFlesh out unsupported_range.
Aldy Hernandez [Wed, 1 Jun 2022 14:58:36 +0000 (16:58 +0200)]
Flesh out unsupported_range.

It's cleaner to have the unsupported_range fully fleshed out, instead
of trapping on every operation.  It can also serve as the basis for
the default vrange methods that frange and prange will inherit.

This patch implements most methods, including union and intersect, to
handle an UNDEFINED and a VARYING range.

Since this can serve as the basis for other classes, I have moved
everything into the vrange class, making the unsupported_range
trivial.

Note that vrange is still an abstract class, as I have purposely left
the dump() method abstract.

Also, I have made the unsupported range in the temporary class
(Value_Range) a method field, instead of a static member.  This way
the temporary can set UNDEFINED and VARYING as needed.

Tested on x86-64 Linux.

gcc/ChangeLog:

* value-range.cc (vrange::contains_p): Implement.
(vrange::type): Return void.
(vrange::supports_type_p): Implement.
(irange::fits_p): Same.
(vrange::set_undefined): Same.
(irange::set_nonnegative): Same.
(vrange::set_varying): Same.
(vrange::union_): Same.
(unsupported_range::set): Move to vrange.
(unsupported_range::type): Move to vrange.
(vrange::intersect): Implement for varying and undefined.
(vrange::zero_p): Implement.
(unsupported_range::supports_type_p): Move to vrange.
(vrange::nonzero_p): Implement.
(unsupported_range::set_undefined): Move to vrange.
(unsupported_range::set_varying): Same.
(unsupported_range::dump): Same.
(unsupported_range::union_): Same.  Implement for varying and
undefined.
(unsupported_range::intersect): Move to vrange.
(unsupported_range::zero_p): Same.
(unsupported_range::nonzero_p): Same.
(unsupported_range::set_nonzero): Same.
(unsupported_range::set_zero): Same.
(unsupported_range::set_nonnegative): Same.
(unsupported_range::fits_p): Same.
* value-range.h (class vrange): Remove abstract markers for most
methods.
(class unsupported_range): Remove most methods as they will now be
inherited from vrange.

2 years agoImplement vrange::supports_type_p.
Aldy Hernandez [Tue, 31 May 2022 12:04:51 +0000 (14:04 +0200)]
Implement vrange::supports_type_p.

[I have conservatively assumed that both the loop-ch and loop-unswitch
passes, which also use the ranger, only support integers and pointers.
If the goal is to handle other types as well, irange::supports_p()
should be Value_Range::supports_type_p(), and any uses of
int_range_max should be converted to Value_Range.  I can help in the
conversion if you'd like.]

As discussed, this patch disambiguates the use of supports_type_p
throughout, as what ranger supports is a totally different question
than what a given range variant (irange, frange, etc) supports.

Unfortunately we need both a static method and a virtual method, and
they can't be named the same.  The uses are documented in the vrange
class:

+// To query what types ranger and the entire ecosystem can support,
+// use Value_Range::supports_type_p(tree type).  This is a static
+// method available independently of any vrange object.
+//
+// To query what a given vrange variant can support, use:
+//    irange::supports_p ()
+//    frange::supports_p ()
+//    etc
+//
+// To query what a range object can support, use:
+//    void foo (vrange &v, irange &i, frange &f)
+//    {
+//     if (v.supports_type_p (type)) ...
+//     if (i.supports_type_p (type)) ...
+//     if (f.supports_type_p (type)) ...
+//    }

The value_range_equiv::supports_p() method can be use to determine
what legacy VRP supports, as irange::supports_p() will no longer be
applicable in the evrp analyzer code base once irange and prange are
split.

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Adjust for
an object level supports_type_p for irange and a static
Value_Range::supports_type_p.
* gimple-range-fold.cc (fold_using_range::range_of_range_op): Same.
(fold_using_range::range_of_address): Same.
(fold_using_range::range_of_builtin_call): Same.
* gimple-range-fold.h (gimple_range_type): Same.
(gimple_range_ssa_p): Same.
* gimple-range-path.cc (path_range_query::internal_range_of_expr):
Same.
(path_range_query::range_of_stmt): Same.
(path_range_query::add_to_imports): Same.
* gimple-range.cc (gimple_ranger::range_on_edge): Same.
(gimple_ranger::export_global_ranges): Same.
* gimple-ssa-evrp-analyze.cc
(evrp_range_analyzer::record_ranges_from_phis):  Same.
* range-op.cc (range_operator::wi_fold): Same.
(range_operator::fold_range): Same.
* tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Same.
* tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Same.
(evaluate_control_stmt_using_entry_checks): Same.
* tree-ssa-threadedge.cc
(hybrid_jt_simplifier::compute_ranges_from_state): Same.
* tree-vrp.cc (supported_types_p): Same.
* value-query.cc (range_query::value_of_expr): Same.
(range_query::value_on_edge): Same.
(range_query::value_of_stmt): Same.
(range_query::get_tree_range): Same.
(get_range_global): Same.
(global_range_query::range_of_expr): Same.
* value-range-equiv.h (class value_range_equiv): Same.
* value-range.cc (irange::supports_type_p): Same.
(unsupported_range::supports_type_p): Same.
* value-range.h (enum value_range_discriminator): Same.
(Value_Range::init): Same.
(Value_Range::supports_type_p): Same.
(irange::supports_type_p): Same.
(irange::supports_p): Same.
(vrange::supports_type_p): Same.
(vrange_allocator::alloc_vrange): Same.

2 years agoconfigure: arrange to use appropriate objcopy
Jan Beulich [Fri, 3 Jun 2022 08:22:25 +0000 (10:22 +0200)]
configure: arrange to use appropriate objcopy

Using the system objcopy is wrong when other configure checks have
probed a different set of binutils (I've noticed the problem on a system
where the base objcopy can't deal with compressed debug sections).
Arrange for the matching one to be picked up, first and foremost if an
"in tree" one is available, by mirroring respective logic already
present for nm.

gcc/

* Makefile.in (ORIGINAL_OBJCOPY_FOR_TARGET): New.
* configure.ac: Check for objcopy, producing
ORIGINAL_OBJCOPY_FOR_TARGET.
* configure: Update accordingly.
* exec-tool.in (ORIGINAL_OBJCOPY_FOR_TARGET): New.
Handle objcopy.

2 years agox86: {,v}psadbw have commutative source operands
Jan Beulich [Fri, 3 Jun 2022 08:21:21 +0000 (10:21 +0200)]
x86: {,v}psadbw have commutative source operands

Like noticed for gas as well (binutils-gdb commit c8cad9d389b7), the
"absolute difference" aspect of the insns makes their source operands
commutative.

gcc/

* config/i386/mmx.md (mmx_psadbw): Convert to expander.
(*mmx_psadbw): New. Mark as commutative.
* config/i386/sse.md (<sse2_avx2>_psadbw): Convert to expander.
(*<sse2_avx2>_psadbw): New. Mark as commutative.

2 years ago[PR105665] ivopts: check defs of names in base for undefs
Alexandre Oliva [Fri, 3 Jun 2022 06:59:03 +0000 (03:59 -0300)]
[PR105665] ivopts: check defs of names in base for undefs

The patch for PR 100810 tested for undefined SSA_NAMEs appearing
directly in the base expression of the potential IV candidate, but
that's not enough.  The testcase for PR105665 shows an undefined
SSA_NAME has the same ill effect if it's referenced as an PHI_NODE arg
in the referenced SSA_NAME.  The variant of that test shows it can be
further removed from the referenced SSA_NAME.

To avoid deep recursion, precompute maybe-undefined SSA_NAMEs: start
from known-undefined nonvirtual default defs, and propagate them to
any PHI nodes reached by a maybe-undefined arg, as long as there
aren't intervening non-PHI uses, that would imply the maybe-undefined
name must be defined at that point, otherwise it would invoke
undefined behavior.  Also test for intervening non-PHI uses of DEFs in
the base expr.

The test for intervening uses implemented herein relies on dominance;
this could be further extended, regarding conditional uses in every
path leading to a point as an unconditional use dominating that point,
but I haven't implemented that.

for  gcc/ChangeLog

PR tree-optimization/105665
PR tree-optimization/100810
* tree-ssa-loop-ivopts.cc
(ssa_name_maybe_undef_p, ssa_name_set_maybe_undef): New.
(ssa_name_any_use_dominates_bb_p, mark_ssa_maybe_undefs): New.
(find_ssa_undef): Check precomputed flag and intervening uses.
(tree_ssa_iv_optimize): Call mark_ssa_maybe_undefs.

for  gcc/testsuite/ChangeLog

PR tree-optimization/105665
PR tree-optimization/100810
* gcc.dg/torture/pr105665.c: New.

2 years agolibcody: fix nonportable shell code in revision.stamp build rule
Alexandre Oliva [Fri, 3 Jun 2022 06:59:01 +0000 (03:59 -0300)]
libcody: fix nonportable shell code in revision.stamp build rule

Two non-portable shell constructs have been long present in libcody's
build rule for revision.stamp: $() instead of ``, and += to append to
a shell variable.  The former seems to work even when bash is
operating as /bin/sh, but += doesn't, and it ends up trying to run
revision+=M as a command name, and issuing an error as that command is
(hopefully) not found.

This patch replaces both constructs with more portable ones.

for  libcody/ChangeLog

* Makefile.in (revision.stamp): Replace $() and += with more
portable shell constructs.

2 years agoDaily bump.
GCC Administrator [Fri, 3 Jun 2022 00:16:40 +0000 (00:16 +0000)]
Daily bump.

2 years agoc++: new-expression is potentially constant in C++20
Marek Polacek [Thu, 2 Jun 2022 19:56:18 +0000 (15:56 -0400)]
c++: new-expression is potentially constant in C++20

... so adjust p_c_e accordingly.

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1): Treat
{,VEC_}NEW_EXPR and {,VEC_}DELETE_EXPRas potentially constant in C++20.

2 years agoc++: ICE with template NEW_EXPR [PR105803]
Marek Polacek [Wed, 1 Jun 2022 22:21:36 +0000 (18:21 -0400)]
c++: ICE with template NEW_EXPR [PR105803]

Here we ICE because value_dependent_expression_p gets a NEW_EXPR
whose operand is a type, and we go to the default case which just
calls v_d_e_p on each operand of the NEW_EXPR.  Since one of them
is a type, we crash on the new assert in t_d_e_p.

t_d_e_p has code to handle {,VEC_}NEW_EXPR, which at this point
was already performed, so I think we can handle these two codes
specifically and skip the second operand, which is always going
to be a type.

PR c++/105803

gcc/cp/ChangeLog:

* pt.cc (value_dependent_expression_p): Handle {,VEC_}NEW_EXPR
in the switch.

gcc/testsuite/ChangeLog:

* g++.dg/template/new13.C: New test.

2 years agodiagnostics: add SARIF output format
David Malcolm [Thu, 2 Jun 2022 19:40:22 +0000 (15:40 -0400)]
diagnostics: add SARIF output format

This patch adds support to gcc's diagnostic subsystem for emitting
diagnostics in SARIF, aka the Static Analysis Results Interchange Format:
  https://sarifweb.azurewebsites.net/
by extending -fdiagnostics-format= to add two new options:
  -fdiagnostics-format=sarif-stderr
and:
  -fdiagnostics-format=sarif-file

The patch targets SARIF v2.1.0

This is a JSON-based format suited for capturing the results of static
analysis tools (like GCC's -fanalyzer), but it can also be used for plain
GCC warnings and errors.

SARIF supports per-event metadata in diagnostic paths such as
["acquire", "resource"] and ["release", "lock"] (specifically, the
threadFlowLocation "kinds" property: SARIF v2.1.0 section 3.38.8), so
the patch extends GCC"s diagnostic_event subclass with a "struct meaning"
with similar purpose.  The patch implements this for -fanalyzer so that
the various state-machine-based warnings set these in the SARIF output.

The heart of the implementation is in the new file
diagnostic-format-sarif.cc.  Much of the rest of the patch is interface
classes, isolating the diagnostic subsystem (which has no knowledge of
e.g. tree or langhook) from the "client" code in the compiler proper
cc1 etc).

The patch adds a langhook for specifying the SARIF v2.1.0
"artifact.sourceLanguage" property, based on the list in
SARIF v2.1.0 Appendix J.

The patch adds automated DejaGnu tests to our testsuite via new
scan-sarif-file and scan-sarif-file-not directives (although these
merely use regexps, rather than attempting to use a proper JSON parser).

I've tested the patch by hand using the validator at:
  https://sarifweb.azurewebsites.net/Validation
and the react-based viewer at:
  https://microsoft.github.io/sarif-web-component/
which successfully shows most of the information (although not paths,
and not CWE IDs), and I've fixed all validation errors I've seen (though
bugs no doubt remain).

I've also tested the generated SARIF using the VS Code extension linked
to from the SARIF website; I'm a novice with VS Code, but it seems to be
able to handle my generated SARIF files (e.g. showing the data in the
SARIF tab, and showing squiggly underlines under issues, and when I
click on them, it visualizes the events in the path inline within the
source window).

Has anyone written an Emacs mode for SARIF files? (pretty please)

gcc/ChangeLog:
* Makefile.in (OBJS): Add tree-diagnostic-client-data-hooks.o and
tree-logical-location.o.
(OBJS-libcommon): Add diagnostic-format-sarif.o; reorder.
(CFLAGS-tree-diagnostic-client-data-hooks.o): Add TARGET_NAME.
* common.opt (fdiagnostics-format=): Add sarif-stderr and sarif-file.
(sarif-stderr, sarif-file): New enum values.
* diagnostic-client-data-hooks.h: New file.
* diagnostic-format-sarif.cc: New file.
* diagnostic-path.h (enum diagnostic_event::verb): New enum.
(enum diagnostic_event::noun): New enum.
(enum diagnostic_event::property): New enum.
(struct diagnostic_event::meaning): New struct.
(diagnostic_event::get_logical_location): New vfunc.
(diagnostic_event::get_meaning): New vfunc.
(simple_diagnostic_event::get_logical_location): New vfunc impl.
(simple_diagnostic_event::get_meaning): New vfunc impl.
* diagnostic.cc: Include "diagnostic-client-data-hooks.h".
(diagnostic_initialize): Initialize m_client_data_hooks.
(diagnostic_finish): Clean up m_client_data_hooks.
(diagnostic_event::meaning::dump_to_pp): New.
(diagnostic_event::meaning::maybe_get_verb_str): New.
(diagnostic_event::meaning::maybe_get_noun_str): New.
(diagnostic_event::meaning::maybe_get_property_str): New.
(get_cwe_url): Make non-static.
(diagnostic_output_format_init): Handle
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR and
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE.
* diagnostic.h (enum diagnostics_output_format): Add
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR and
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE.
(class diagnostic_client_data_hooks): New forward decl.
(class logical_location): New forward decl.
(diagnostic_context::m_client_data_hooks): New field.
(diagnostic_output_format_init_sarif_stderr): New decl.
(diagnostic_output_format_init_sarif_file): New decl.
(get_cwe_url): New decl.
* doc/invoke.texi (-fdiagnostics-format=): Add sarif-stderr and
sarif-file.
* doc/sourcebuild.texi (Scan a particular file): Add
scan-sarif-file and scan-sarif-file-not.
* langhooks-def.h (lhd_get_sarif_source_language): New decl.
(LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): New macro.
(LANG_HOOKS_INITIALIZER): Add
LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE.
* langhooks.cc (lhd_get_sarif_source_language): New.
* langhooks.h (lang_hooks::get_sarif_source_language): New field.
* logical-location.h: New file.
* plugin.cc (struct for_each_plugin_closure): New.
(for_each_plugin_cb): New.
(for_each_plugin): New.
* plugin.h (for_each_plugin): New decl.
* tree-diagnostic-client-data-hooks.cc: New file.
* tree-diagnostic.cc: Include "diagnostic-client-data-hooks.h".
(tree_diagnostics_defaults): Populate m_client_data_hooks.
* tree-logical-location.cc: New file.
* tree-logical-location.h: New file.

gcc/ada/ChangeLog:
* gcc-interface/misc.cc (gnat_get_sarif_source_language): New.
(LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.

gcc/analyzer/ChangeLog:
* checker-path.cc (checker_event::get_meaning): New.
(function_entry_event::get_meaning): New.
(state_change_event::get_desc): Add dump of meaning of the event
to the -fanalyzer-verbose-state-changes output.
(state_change_event::get_meaning): New.
(cfg_edge_event::get_meaning): New.
(call_event::get_meaning): New.
(return_event::get_meaning): New.
(start_consolidated_cfg_edges_event::get_meaning): New.
(warning_event::get_meaning): New.
* checker-path.h: Include "tree-logical-location.h".
(checker_event::checker_event): Construct m_logical_loc.
(checker_event::get_logical_location): New.
(checker_event::get_meaning): New decl.
(checker_event::m_logical_loc): New.
(function_entry_event::get_meaning): New decl.
(state_change_event::get_meaning): New decl.
(cfg_edge_event::get_meaning): New decl.
(call_event::get_meaning): New decl.
(return_event::get_meaning): New decl.
(start_consolidated_cfg_edges_event::get_meaning): New.
(warning_event::get_meaning): New decl.
* pending-diagnostic.h: Include "diagnostic-path.h".
(pending_diagnostic::get_meaning_for_state_change): New vfunc.
* sm-file.cc (file_diagnostic::get_meaning_for_state_change): New
vfunc impl.
* sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-sensitive.cc
(exposure_through_output_file::get_meaning_for_state_change):
Likewise.
* sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
Likewise.
* varargs.cc
(va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.

gcc/c/ChangeLog:
* c-lang.cc (LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.
(c_get_sarif_source_language): New.
* c-tree.h (c_get_sarif_source_language): New decl.

gcc/cp/ChangeLog:
* cp-lang.cc (LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.
(cp_get_sarif_source_language): New.

gcc/d/ChangeLog:
* d-lang.cc (d_get_sarif_source_language): New.
(LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.

gcc/fortran/ChangeLog:
* f95-lang.cc (gfc_get_sarif_source_language): New.
(LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.

gcc/go/ChangeLog:
* go-lang.cc (go_get_sarif_source_language): New.
(LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.

gcc/objc/ChangeLog:
* objc-act.h (objc_get_sarif_source_language): New decl.
* objc-lang.cc (LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE): Redefine.
(objc_get_sarif_source_language): New.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-1.c: New test.
* c-c++-common/diagnostic-format-sarif-file-2.c: New test.
* c-c++-common/diagnostic-format-sarif-file-3.c: New test.
* c-c++-common/diagnostic-format-sarif-file-4.c: New test.
* gcc.dg/analyzer/file-meaning-1.c: New test.
* gcc.dg/analyzer/malloc-meaning-1.c: New test.
* gcc.dg/analyzer/malloc-sarif-1.c: New test.
* gcc.dg/plugin/analyzer_gil_plugin.c
(gil_diagnostic::get_meaning_for_state_change): New vfunc impl.
* gcc.dg/plugin/diagnostic-test-paths-5.c: New test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
diagnostic-test-paths-5.c to tests for
diagnostic_plugin_test_paths.c.
* lib/gcc-dg.exp: Load scansarif.exp.
* lib/scansarif.exp: New test.

libatomic/ChangeLog:
* testsuite/lib/libatomic.exp: Add load_gcc_lib of scansarif.exp.

libgomp/ChangeLog:
* testsuite/lib/libgomp.exp: Add load_gcc_lib of scansarif.exp.

libitm/ChangeLog:
* testsuite/lib/libitm.exp: Add load_gcc_lib of scansarif.exp.

libphobos/ChangeLog:
* testsuite/lib/libphobos-dg.exp: Add load_gcc_lib of scansarif.exp.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoAdd -fdiagnostics-format={json-stderr|json-file}
David Malcolm [Thu, 2 Jun 2022 19:38:38 +0000 (15:38 -0400)]
Add -fdiagnostics-format={json-stderr|json-file}

This commit adds -fdiagnostics-format=json-file, writing to
DUMP_BASE_NAME.gcc.json, and adds -fdiagnostics-format=json-stderr,
a synonym for the existing -fdiagnostics-format=json.

gcc/ChangeLog:
* common.opt (fdiagnostics-format=): Add json-stderr and json-file
to description.
(DIAGNOSTICS_OUTPUT_FORMAT_JSON): Rename to...
(DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR): ...this.
(diagnostics_output_format): Add json-stderr and json-file.
* diagnostic-format-json.cc (json_flush_to_file): New.
(json_final_cb): Convert to...
(json_flush_to_file): ...this, ...
(json_stderr_final_cb): ...this, and...
(json_file_final_cb): ...this.
(diagnostic_output_format_init): Move to diagnostic.cc.
(json_output_base_file_name): New.
(diagnostic_output_format_init_json): New.
(diagnostic_output_format_init_json_stderr): New.
(diagnostic_output_format_init_json_file): New.
* diagnostic.cc (diagnostic_output_format_init): Move here from
diagnostic-format-json.cc; update for changes to enum.
* diagnostic.h (enum diagnostics_output_format): Rename
DIAGNOSTICS_OUTPUT_FORMAT_JSON to
DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR, and add
DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE.
(diagnostic_output_format_init): Add base_file_name param.
(diagnostic_output_format_init_json_stderr): New decl.
(diagnostic_output_format_init_json_file): New dec.
* doc/invoke.texi (-fdiagnostics-format=): Add "json-stderr" and
"json-file".  Rewrite so that the existing "json" is a synonym of
"json-stderr".
* gcc.cc (driver_handle_option): Pass dump_base_name to
diagnostic_output_format_init.
* opts.cc (common_handle_option): Likewise.

gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-json-file-1.c: New test.
* c-c++-common/diagnostic-format-json-stderr-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agojson: fix escaping of '\'
David Malcolm [Thu, 2 Jun 2022 19:36:27 +0000 (15:36 -0400)]
json: fix escaping of '\'

gcc/ChangeLog:
* json.cc (string::print): Fix escaping of '\'.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoRISC-V: bitmanip: improve constant-loading for (1ULL << 31) in DImode
Philipp Tomsich [Mon, 29 Jun 2020 13:15:10 +0000 (15:15 +0200)]
RISC-V: bitmanip: improve constant-loading for (1ULL << 31) in DImode

The SINGLE_BIT_MASK_OPERAND() is overly restrictive, triggering for
bits above 31 only (to side-step any issues with the negative SImode
value 0x80000000/(-1ull << 31)/(1 << 31)).  This moves the special
handling of this SImode value (i.e. the check for (-1ull << 31) to
riscv.cc and relaxes the SINGLE_BIT_MASK_OPERAND() test.

With this, the code-generation for loading (1ULL << 31) from:
li a0,1
slli a0,a0,31
to:
bseti a0,zero,31

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_build_integer_1): Rewrite value as
(-1 << 31) for the single-bit case, when operating on (1 << 31)
in SImode.
* config/riscv/riscv.h (SINGLE_BIT_MASK_OPERAND): Allow for
any single-bit value, moving the special case for (1 << 31) to
riscv_build_integer_1 (in riscv.c).

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2 years agoc++: more constexpr empty base [PR105795]
Jason Merrill [Wed, 1 Jun 2022 21:30:25 +0000 (17:30 -0400)]
c++: more constexpr empty base [PR105795]

Following on from the previous patch, for trunk let's consistently set
ctx->ctor to NULL_TREE for empty subobjects.

PR c++/105795

gcc/cp/ChangeLog:

* constexpr.cc (init_subob_ctx): Clear ctx->ctor for empty subob.
(cxx_eval_store_expression): Likewise.
(cxx_eval_bare_aggregate): Handle null ctx->ctor.

2 years agoc++: constexpr empty aggr [PR105795]
Jason Merrill [Wed, 1 Jun 2022 20:13:48 +0000 (16:13 -0400)]
c++: constexpr empty aggr [PR105795]

In this testcase, leaving ctx->ctor pointing to the enclosing object meant
that evaluating the initializer for the subobject clobbered previous
initializers for the enclosing object.  So do update ctx->ctor, just don't
add it to the enclosing object ctor.

PR c++/105795

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_bare_aggregate): Always call
init_subob_ctx.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-aggr-base1.C: New test.

2 years agoPR target/105791: Add V1TI to V_128_256 for xop_pcmov_v1ti on x86_64.
Roger Sayle [Thu, 2 Jun 2022 17:46:37 +0000 (18:46 +0100)]
PR target/105791: Add V1TI to V_128_256 for xop_pcmov_v1ti on x86_64.

This patch resolves PR target/105791 which is a regression that was
accidentally introduced for my workaround to PR tree-optimization/10566.
(a deeper problem in GCC's vectorizer creating VEC_COND_EXPR when it
shouldn't).  The latest issues is that by providing a vcond_mask_v1tiv1ti
pattern in sse.md, the backend now calls ix86_expand_sse_movcc with
V1TImode operands, which has a special case for TARGET_XOP to generate
a vpcmov instruction.  Unfortunately, there wasn't previously a V1TImode
variant, xop_pcmov_v1ti, so we'd ICE.

This is easily fixed by adding V1TImode (and V2TImode) to V_128_256
which is only used for defining XOP's vpcmov instruction.  This in turn
requires V1TI (and V2TI) to be supported by <avxsizesuffix> (though
the use if <avxsizesuffix> in the names xop_pcmov_<mode><avxsizesuffix>
seems unnecessary; the mode makes the name unique).

2022-06-02  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/105791
* config/i386/sse.md (V_128_256):Add V1TI and V2TI.
(define_mode_attr avxsizesuffix): Add support for V1TI and V2TI.

gcc/testsuite/ChangeLog
PR target/105791
* gcc.target/i386/pr105791.c: New test case.

2 years agotestsuite: Also test swapped arguments of __builtin_mul_overflow_p [PR30314]
Jakub Jelinek [Thu, 2 Jun 2022 09:14:09 +0000 (11:14 +0200)]
testsuite: Also test swapped arguments of __builtin_mul_overflow_p [PR30314]

To test the commutativity of __builtin_mul_overflow* arguments in the
optimization, I've added 2 further tests.

2022-06-02  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/30314
* gcc.dg/tree-ssa/pr30314.c: Add tests with swapped arguments.

2 years ago[Ada] Update copyright notices
Pierre-Marie de Rodat [Tue, 24 May 2022 09:37:29 +0000 (09:37 +0000)]
[Ada] Update copyright notices

gcc/ada/

* gcc-interface/gigi.h: Update copyright notice.
* gcc-interface/lang-specs.h: Likewise.
* gcc-interface/utils.cc: Likewise.

2 years ago[Ada] Remove left-overs of front-end SJLJ processing
Eric Botcazou [Mon, 9 May 2022 11:15:02 +0000 (13:15 +0200)]
[Ada] Remove left-overs of front-end SJLJ processing

gcc/ada/

* gcc-interface/gigi.h (enum standard_datatypes): Remove values
for the SJLJ exception mechanism.
(jmpbuf_type): Delete.
(jmpbuf_ptr_type): Likewise.
(get_jmpbuf_decl): Likewise.
(set_jmpbuf_decl): Likewise.
(get_excptr_decl): Likewise.
(not_handled_by_others_decl): Likewise.
(setjmp_decl): Likewise.
(update_setjmp_buf_decl): Likewise.
(raise_nodefer_decl): Likewise.
(set_block_jmpbuf_decl): Likewise.
(get_block_jmpbuf_decl): Likewise.
* gcc-interface/trans.cc (gigi): Delete dead code.
* gcc-interface/utils.cc (gnat_binding_level): Remove JMPBUF_DECL.
(gnat_pushlevel): Do not clear it.
(set_block_jmpbuf_decl): Delete.
(get_block_jmpbuf_decl): Likewise.

2 years ago[Ada] Fix record layout warnings not being tagged
Ghjuvan Lacambre [Tue, 26 Apr 2022 07:44:55 +0000 (09:44 +0200)]
[Ada] Fix record layout warnings not being tagged

This allows tools ingesting GNAT's output to properly classify these
messages.

gcc/ada/

* gcc-interface/decl.cc (warn_on_field_placement): Add insertion
character '.q' to warning string.

2 years ago[Ada] Disable -flto when building the shared libgnat
Arnaud Charlet [Thu, 21 Apr 2022 15:40:16 +0000 (15:40 +0000)]
[Ada] Disable -flto when building the shared libgnat

This setting isn't useful in this context.

gcc/ada/

* gcc-interface/Makefile.in (gnatlib-shared-default): Add
-fno-lto.

2 years ago[Ada] Couple of small preparatory adjustments
Eric Botcazou [Tue, 19 Apr 2022 19:53:35 +0000 (21:53 +0200)]
[Ada] Couple of small preparatory adjustments

No functional changes.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity): Do not check the
scope of anonymous access Itypes.
* gcc-interface/trans.cc (Identifier_to_gnu): Do not translate
the return type of a subprogram here.

2 years ago[Ada] Restore full generation of static dispatch tables with -gnatzr
Eric Botcazou [Sat, 21 May 2022 19:54:45 +0000 (21:54 +0200)]
[Ada] Restore full generation of static dispatch tables with -gnatzr

The -gnatzr switch triggers the creation of distribution stubs for use
by the implementation of PolyORB.  Now these stubs declare tagged types
and are generated at the very end of the analysis of compilation units,
after the static dispatch tables have been built, so these tables are
missing for the tagged types of the stubs.

Therefore this change defers the generation of static dispatch tables
for compilation units, which is the common case, until after the stubs
are (potentially) generated.  For the other cases, in particular the
generic instances that are not compilation units, nothing is changed.

gcc/ada/

* exp_ch7.adb (Expand_N_Package_Body): Build static dispatch
tables only for units that are not compilation units, unless
they are generic instances.  Do not push a scope for this.
(Expand_N_Package_Declaration): Build static dispatch tables
only for units that are both not compilation units and generic
instances.
* exp_disp.adb (Build_Static_Dispatch_Tables): Remove redundant
early return.  Push a scope for package bodies.
* sem_ch10.adb: Add with and use clauses for Exp_Disp.
(Analyze_Compilation_Unit): Build static dispatch tables here.

2 years ago[Ada] Never make symbols for thunks public
Eric Botcazou [Fri, 20 May 2022 17:06:28 +0000 (19:06 +0200)]
[Ada] Never make symbols for thunks public

Thunks are only referenced locally by dispatch tables and never inlined.

gcc/ada/

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Clear the Is_Public
flag on thunks.

2 years ago[Ada] Remove redundant checks for missing lists
Piotr Trojanek [Fri, 20 May 2022 07:41:30 +0000 (09:41 +0200)]
[Ada] Remove redundant checks for missing lists

When iterating over list elements with First/Next there is no need to
check if the list is present, because First intentionally returns Empty
if list is not present and the condition of subsequent loop will not be
satisfied.

Code cleanup; semantics is unaffected.

Occurrences of the redundant pattern were found with:

  $ grep First -B 3 | less

and examining the output for the calls to Present.

gcc/ada/

* exp_ch13.adb, exp_ch5.adb, exp_ch9.adb, exp_strm.adb,
sem_ch10.adb, sem_ch13.adb, sem_ch5.adb, sem_ch6.adb,
sem_ch8.adb, sem_elab.adb, sem_eval.adb, sem_prag.adb,
sem_util.adb: Remove checks for the missing list before
iterating with First/Next; reindent code and refill comments.

2 years ago[Ada] Get rid of secondary stack for most calls returning tagged types
Eric Botcazou [Wed, 18 May 2022 10:17:27 +0000 (12:17 +0200)]
[Ada] Get rid of secondary stack for most calls returning tagged types

This eliminates the use of the secondary stack to return specific tagged
types from functions in calls that are not dispatching on result, which
comprises returning controlled types, by introducing thunks whose only
purpose is to move the result from the primary to the secondary stack
for primitive functions that are controlling on result, and referencing
them in the dispatch table in lieu of the primitive functions.

The implementation reuses the existing machinery of interface thunks and
thus creates another kind of thunks, secondary stack thunks, which only
perform a call to the primitive function and return the result.

gcc/ada/

* einfo.ads (Has_Controlling_Result): Document new usage.
(Is_Thunk): Document secondary stack thunks.
(Returns_By_Ref): Adjust.
* exp_ch6.adb (Caller_Known_Size): Return true for tagged types.
(Expand_N_Extended_Return_Statement): Do not call Set_By_Ref.
(Expand_Simple_Function_Return): For a BIP return with an Alloc_Form
parameter, mark the node as returning on the secondary stack.
Replace call to Is_Limited_Interface with Is_Limited_View.  Deal wit
secondary stack thunks.  Do not call Set_By_Ref.  Optimize the case
of a call to a function whose type also needs finalization.
(Needs_BIP_Task_Actuals): Replace Thunk_Entity with Thunk_Target.
(Needs_BIP_Finalization_Master): Cosmetic fixes.
(Needs_BIP_Alloc_Form): Check No_Secondary_Stack restriction and
return true for tagged types.
* exp_ch7.adb (Transient Scope Management): Update description.
* exp_disp.adb (Expand_Dispatching_Call): Always set Returns_By_Ref
on designated type if the call is dispatching on result.  Tidy up.
(Expand_Interface_Thunk): Change type of Thunk_Code from Node_Id to
List_Id.  Change type of local variables from Node_Id to Entity_Id.
Propagate Aliased_Present flag to create the formals and explicitly
set Has_Controlling_Result to False.  Build a secondary stack thunk
if necessary in the function case.
(Expand_Secondary_Stack_Thunk): New function.
(Make_Secondary_DT): Build secondary stack thunks if necessary.
(Make_DT): Likewise.
(Register_Predefined_Primitive): Likewise.
(Register_Primitive): Likewise.
* exp_util.ads (Is_Secondary_Stack_Thunk): Declare.
(Thunk_Target): Likewise.
* exp_util.adb (Is_Secondary_Stack_Thunk): New function.
(Thunk_Target): Likewise.
* fe.h (Is_Secondary_Stack_Thunk): Declare.
(Thunk_Target): Likewise.
* gen_il-fields.ads (Opt_Field_Enum): Remove By_Ref.
* gen_il-gen-gen_nodes.adb (N_Simple_Return_Statement): Likewise.
(N_Extended_Return_Statement): Likewise.
* sem_ch6.adb (Analyze_Subprogram_Specification): Skip check for
abstract return type in the thunk case.
(Create_Extra_Formals): Replace Thunk_Entity with Thunk_Target.
* sem_disp.adb (Check_Controlling_Formals): Skip in the thunk case.
* sem_util.adb: Add use and with clauses for Exp_Ch6.
(Compute_Returns_By_Ref): Do not process procedures and only set
the flag for direct return by reference.
(Needs_Secondary_Stack): Do not return true for specific tagged
types and adjust comments accordingly.
* sinfo.ads (By_Ref): Delete.
(N_Simple_Return_Statement): Remove By_Ref.
(N_Extended_Return_Statement): Likewise.
* gcc-interface/ada-tree.h (TYPE_RETURN_UNCONSTRAINED_P): Delete.
* gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Do not use it.
Return by direct reference if the return type needs the secondary
stack as well as for secondary stack thunks.
* gcc-interface/gigi.h (fntype_same_flags_p): Remove parameter.
* gcc-interface/misc.cc (gnat_type_hash_eq): Adjust to above change.
* gcc-interface/trans.cc (finalize_nrv): Replace test on
TYPE_RETURN_UNCONSTRAINED_P with TYPE_RETURN_BY_DIRECT_REF_P.
(Subprogram_Body_to_gnu): Do not call maybe_make_gnu_thunk for
secondary stack thunks.
(Call_to_gnu): Do not test TYPE_RETURN_UNCONSTRAINED_P.
(gnat_to_gnu) <N_Simple_Return_Statement>: In the return by direct
reference case, test for the presence of Storage_Pool on the node
to build an allocator.
(maybe_make_gnu_thunk): Deal with Thunk_Entity and Thunk_Target.
* gcc-interface/utils.cc (fntype_same_flags_p): Remove parameter.

2 years ago[Ada] Fix references to old variables that have been refactored
Marc Poulhiès [Mon, 16 May 2022 12:52:41 +0000 (14:52 +0200)]
[Ada] Fix references to old variables that have been refactored

Local_Entity_Suppress and Global_Entity_Suppress variables referencing
tables were refactored to Local_Suppress_Stack_Top and
Global_Suppress_Stack_Top stacks back in 2007.  Fix remaining references
to these variables.

gcc/ada/

* einfo.ads: Fix reference to Global_Entity_Suppress and
Local_Entity_Suppress variable in the comments.
* sem.ads: Likewise.
* sem_prag.adb: Likewise.

2 years ago[Ada] Rename GNATprove annotate pragma for termination to Always_Return
Claire Dross [Wed, 18 May 2022 13:22:39 +0000 (15:22 +0200)]
[Ada] Rename GNATprove annotate pragma for termination to Always_Return

GNATprove changed the name of the pragma Annotate used to verify that
a subprogram always returns normally. It is now called Always_Return
instead of Terminating.

gcc/ada/

* libgnat/s-aridou.adb: Use Always_Return instead of Terminating
to annotate termination for GNATprove.
* libgnat/s-arit32.adb: Idem.
* libgnat/s-spcuop.ads: Idem.

2 years ago[Ada] Make the functional Maps and Sets unbounded
Julien Bortolussi [Tue, 26 Apr 2022 10:02:59 +0000 (12:02 +0200)]
[Ada] Make the functional Maps and Sets unbounded

Before this patch, the Functional Sets ans Maps were bounded both from
the user and the implementation points of view.  To make them closer to
mathematical Sets ans Maps, this patch removes the bounds from the
contracts. Note that, in practice, they are still bounded by
Count_Type'Last, even if the user is not aware of it anymore.

This patch removed constraints on length of sets and maps from the
preconditions of functions. The function Length and Num_Overlaps now
return a Big_Natural.

gcc/ada/

* libgnat/a-cofuse.ads, libgnat/a-cofuse.adb,
libgnat/a-cofuma.ads, libgnat/a-cofuma.adb: Make Length and
Num_Overlaps return Big_Natural.
* libgnat/a-cforse.ads, libgnat/a-cforse.adb,
libgnat/a-cforma.adb, libgnat/a-cfhase.ads,
libgnat/a-cfhase.adb, libgnat/a-cfhama.adb,
libgnat/a-cfdlli.adb: Adapt code to handle Big_Integers instead
of Count_Type.

2 years ago[Ada] Fix spurious use of trampolines with interface types
Eric Botcazou [Wed, 18 May 2022 09:05:33 +0000 (11:05 +0200)]
[Ada] Fix spurious use of trampolines with interface types

Function pointers must always be built with '[Unrestricted_]Access.

gcc/ada/

* exp_ch3.adb (Init_Secondary_Tags.Initialize_Tag): Initialize the
Offset_Func component by means of 'Unrestricted_Access.

2 years ago[Ada] Add precise subprogram identification to -fdiagnostics-format=json
Ghjuvan Lacambre [Tue, 17 May 2022 18:03:44 +0000 (20:03 +0200)]
[Ada] Add precise subprogram identification to -fdiagnostics-format=json

This commit adds information allowing identification of the subprogram
surrounding the message emitted by gnat when using -gnatdJ along with
-fdiagnostics-format=json.

gcc/ada/

* errout.adb (Write_JSON_Span): Add subprogram name to emitted
JSON.

2 years ago[Ada] Refine previous changes on making symbols public/private
Arnaud Charlet [Tue, 17 May 2022 12:22:20 +0000 (12:22 +0000)]
[Ada] Refine previous changes on making symbols public/private

Inline_Always procedures should be kept public for proper inter unit
inlining.

gcc/ada/

* sem_ch7.adb (Set_Referencer_Of_Non_Subprograms): New local
procedure, used for code refactoring. Also take into account
Inline_Always pragma when deciding to make a symbol public for
C generation.

2 years ago[Ada] Fix spurious errors on ghost code in generics
Yannick Moy [Mon, 16 May 2022 07:58:18 +0000 (09:58 +0200)]
[Ada] Fix spurious errors on ghost code in generics

After the recent fix for detecting illegal use of ghost entities in
code, spurious errors could be raised on generic code with ghost, due to
wrong setting of the ghost flags on copied entities from the generic to
the instantiation.

gcc/ada/

* atree.adb (New_Copy): Reset flags related to ghost entities
before marking the new node.

2 years ago[Ada] Move registering code for predefined primitives to Exp_Disp
Eric Botcazou [Tue, 17 May 2022 06:27:11 +0000 (08:27 +0200)]
[Ada] Move registering code for predefined primitives to Exp_Disp

This avoids making Expand_Interface_Thunk visible from the outside.

No functional changes.

gcc/ada/

* exp_ch6.adb (Freeze_Subprogram.Register_Predefined_DT_Entry): Move
procedure to...
* exp_disp.ads (Expand_Interface_Thunk): Move declaration to...
(Register_Predefined_Primitive): Declare.
* exp_disp.adb (Expand_Interface_Thunk): ...here.
(Register_Predefined_Primitive): ...here and change into a function
returning List_Id.

2 years ago[Ada] Build static dispatch tables always at the end of declarative part
Eric Botcazou [Mon, 16 May 2022 14:14:46 +0000 (16:14 +0200)]
[Ada] Build static dispatch tables always at the end of declarative part

The static dispatch tables of library-level tagged types are either built
on the first object declaration or at the end of the declarative part of
the package spec or body. There is no real need for the former case, and
the tables are not built for other constructs that freeze (tagged) types.

Therefore this change removes the former case, thus causing the tables to
be always built at the end of the declarative part; that's orthogonal to
freezing and the tagged types are still frozen at the appropriate place.

Moreover, it wraps the code in the Actions list of a freeze node (like
for the nonstatic case) so that it is considered elaboration code by the
processing done in Sem_Elab and does not disturb it.

No functional changes.

gcc/ada/

* exp_ch3.adb (Expand_Freeze_Record_Type): Adjust comment.
(Expand_N_Object_Declaration): Do not build static dispatch tables.
* exp_disp.adb (Make_And_Insert_Dispatch_Table): New procedure.
(Build_Static_Dispatch_Tables): Call it to build the dispatch tables
and wrap them in the Actions list of a freeze node.

2 years ago[Ada] vx7r2-arm/aarch64 - Support Atomic Primitives True
Doug Rupp [Mon, 16 May 2022 18:57:13 +0000 (11:57 -0700)]
[Ada] vx7r2-arm/aarch64 - Support Atomic Primitives True

This feature is an architecture feature, not an OS feature, so enable
on vx7r2 for arm and aarch64 to coincide with what is done on similarly
capable targets.

gcc/ada/

* libgnat/system-vxworks7-arm.ads (Support_Atomic_Primitives):
Set True.
* libgnat/system-vxworks7-arm-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-aarch64.ads: Likewise.
* libgnat/system-vxworks7-aarch64-rtp-smp.ads: Likewise:

2 years ago[Ada] Update documentation of GNAT.Dynamic_Tables
Javier Miranda [Fri, 13 May 2022 16:56:00 +0000 (16:56 +0000)]
[Ada] Update documentation of GNAT.Dynamic_Tables

Document that dynamic tables are defined aliased for backward
compatibility.

gcc/ada/

* libgnat/g-dyntab.ads (Table_Type): Update documentation.

2 years ago[Ada] Fix detection of deferred constants for freezing error
Eric Botcazou [Thu, 12 May 2022 15:44:59 +0000 (17:44 +0200)]
[Ada] Fix detection of deferred constants for freezing error

Testing Is_Frozen is not robust enough, so instead test that the full view
has been seen and that the Has_Completion flag is set on it.

gcc/ada/

* freeze.adb (Check_Expression_Function.Find_Constant): Make test
for deferred constants more robust.

2 years ago[Ada] Fix preconditions of Interfaces.C.Strings
Joffrey Huguet [Thu, 12 May 2022 09:53:54 +0000 (11:53 +0200)]
[Ada] Fix preconditions of Interfaces.C.Strings

Preconditions of Update procedures were always true when Offset was 0.
The changes enable to protect from Update_Error when Offset is 0.

gcc/ada/

* libgnat/i-cstrin.ads (Update): Update precondition.

2 years ago[Ada] Issue errors on wrong context for ghost entities
Yannick Moy [Mon, 2 May 2022 15:38:41 +0000 (17:38 +0200)]
[Ada] Issue errors on wrong context for ghost entities

References to ghost entities should only occur in ghost context.  This
was not checked systematically on all references.

gcc/ada/

* sem_ch2.adb (Analyze_Identifier): Add checking for ghost
context.
* sem_ch5.adb (Analyze_Implicit_Label_Declaration): Treat
implicit labels like other entities by setting their ghost
status according to context.
* ghost.adb (Check_Ghost_Context): Adapt checking.

2 years ago[Ada] Complete contracts of Interfaces.C.Strings subprograms
Joffrey Huguet [Wed, 11 May 2022 15:16:05 +0000 (17:16 +0200)]
[Ada] Complete contracts of Interfaces.C.Strings subprograms

This patch adds preconditions to Update procedures, to protect from
Update_Error propagations.

gcc/ada/

* libgnat/i-cstrin.ads (Update): Add precondition.

2 years ago[Ada] Removal of dead code Analyze_Label_Entity
Yannick Moy [Tue, 10 May 2022 16:52:59 +0000 (18:52 +0200)]
[Ada] Removal of dead code Analyze_Label_Entity

gcc/ada/

* sem_ch5.adb (Analyze_Label_Entity): Remove body.
* sem_ch5.ads (Analyze_Label_Entity): Remove spec.

2 years ago[Ada] Propagate Has_Inherit{able,ed}_Invariants to base types
Eric Botcazou [Wed, 11 May 2022 08:10:52 +0000 (10:10 +0200)]
[Ada] Propagate Has_Inherit{able,ed}_Invariants to base types

The two flags apply to base types only like Has_Own_Invariants.

gcc/ada/

* sem_util.adb (Propagate_DIC_Attributes): Add ??? comment.
(Propagate_Invariant_Attributes): Likewise.  Propagate the
Has_Inheritable_Invariants and Has_Inherited_Invariants to
the base type of the target type.

2 years ago[Ada] Combine system.ads files - arm and aarch64 linux
Doug Rupp [Tue, 10 May 2022 22:03:58 +0000 (15:03 -0700)]
[Ada] Combine system.ads files - arm and aarch64 linux

Systemitize Word_Size and Memory_Size declarations rather than hard code
with numerical values or OS specific Long_Integer size.

gcc/ada/

* libgnat/system-linux-arm.ads (Memory_Size): Compute based on
Word_Size.

2 years ago[Ada] Combine system.ads file - vxworks7 rtp constants
Doug Rupp [Tue, 10 May 2022 21:53:59 +0000 (14:53 -0700)]
[Ada] Combine system.ads file - vxworks7 rtp constants

Systemitize Word_Size and Memory_Size declarations rather than hard code
with numerical values or OS specific Long_Integer size.

gcc/ada/

* libgnat/system-vxworks7-aarch64-rtp-smp.ads (Word_Size):
Compute based on Standard'Word_Size. (Memory_Size): Compute
based on Word_Size.
* libgnat/system-vxworks7-arm-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-e500-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-e500-rtp.ads: Likewise.
* libgnat/system-vxworks7-ppc-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-ppc-rtp.ads: Likewise.
* libgnat/system-vxworks7-ppc64-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-x86-rtp-smp.ads: Likewise.
* libgnat/system-vxworks7-x86-rtp.ads: Likewise.

2 years ago[Ada] Gnatbind crash during checksum calculation
Justin Squirek [Tue, 10 May 2022 18:19:10 +0000 (18:19 +0000)]
[Ada] Gnatbind crash during checksum calculation

This patch corrects an error in the compiler whereby gnatbind may crash
during calculation of file checksums in certain corner cases due to
uninitialized lookup tables.

gcc/ada/

* gnatbind.adb (Gnatbind): Add initialize call for Uintp
* gnatls.adb (Gnatls): Likewise.
* gprep.adb (Gnatprep): Likewise.
* make.adb (Initialize): Likewise.

2 years ago[Ada] Fix iteration on formal vectors
Claire Dross [Mon, 9 May 2022 13:44:22 +0000 (15:44 +0200)]
[Ada] Fix iteration on formal vectors

We need to use Extended_Index for the Position parameter of the Element
function in formal vectors so it is compatible with other primitives of
the Iterable aspect.

gcc/ada/

* libgnat/a-cfinve.ads (Element): Change the type of the
Position parameter to Extended_Index.
* libgnat/a-cfinve.adb (Element): Idem.
* libgnat/a-cofove.ads (Element): Idem.
* libgnat/a-cofove.adb (Element): Idem.

2 years ago[Ada] Add contracts to System.Address_To_Access_Conversions
Joffrey Huguet [Mon, 9 May 2022 13:25:30 +0000 (15:25 +0200)]
[Ada] Add contracts to System.Address_To_Access_Conversions

This patch adds SPARK annotations to subprograms from
System.Address_To_Access_Conversions. To_Pointer is considered to have
no global items, if the returned value has no aliases. To_Address is
forbidden in SPARK because addresses are not handled.

gcc/ada/

* libgnat/s-atacco.ads (To_Pointer): Add Global => null.
(To_Address): Add SPARK_Mode => Off.

2 years ago[Ada] Add contracts to Interfaces.C.Strings
Joffrey Huguet [Tue, 3 May 2022 12:46:35 +0000 (14:46 +0200)]
[Ada] Add contracts to Interfaces.C.Strings

This patch adds Global contracts and preconditions to subprograms of
Interfaces.C.Strings. Effects on allocated memory are modelled
through an abstract state, C_Memory. The preconditions protect against
Dereference_Error, but not Storage_Error (which is not handled by
SPARK). This patch also disables the use of To_Chars_Ptr, which
creates an alias between an ownership pointer and the abstract state,
and the use of Free, in SPARK code. Thus, memory leaks will happen
if the user creates the Chars_Ptr using New_Char_Array and New_String.

gcc/ada/

* libgnat/i-cstrin.ads (To_Chars_Ptr): Add SPARK_Mode => Off.
(Free): Likewise.
(New_Char_Array): Add global contracts and Volatile attribute.
(New_String): Likewise.
(Value, Strlen, Update): Add global contracts and preconditions.
* libgnat/i-cstrin.adb: Add SPARK_Mode => Off to the package
body.

2 years agoi386: Optimize away shift count masking of shifts/rotates some more [PR105778]
Jakub Jelinek [Thu, 2 Jun 2022 08:40:12 +0000 (10:40 +0200)]
i386: Optimize away shift count masking of shifts/rotates some more [PR105778]

As the following testcase shows, our x86 backend support for optimizing
out useless masking of shift/rotate counts when using instructions
that naturally modulo the count themselves is insufficient.
The *_mask define_insn_and_split patterns use
(subreg:QI (and:SI (match_operand:SI) (match_operand "const_int_operand")))
for the masking, but that can catch only the case where the masking
is done in SImode, so typically in SImode in the source.
We then have another set of patterns, *_mask_1, which use
(and:QI (match_operand:QI) (match_operand "const_int_operand"))
If the masking is done in DImode or in theory in HImode, we don't match
it.
The following patch does 4 different things to improve this:
1) drops the mode from AND and MATCH_OPERAND inside of the subreg:QI
   and replaces that by checking that the register shift count has
   SWI48 mode - I think doing it this way is cheaper than adding
   another mode iterator to patterns which use already another mode
   iterator and sometimes a code iterator as well
2) the doubleword shift patterns were only handling the case where
   the shift count is masked with a constant that has the most significant
   bit clear, i.e. where we know the shift count is less than half the
   number of bits in double-word.  If the mask is equal to half the
   number of bits in double-word minus 1, the masking was optimized
   away, otherwise the AND was kept.
   But if the most significant bit isn't clear, e use a word-sized shift
   and SHRD instruction, where the former does the modulo and the latter
   modulo with 64 / 32 depending on what mode the CPU is in (so 64 for
   128-bit doubleword and 32 or 64-bit doubleword).  So we can also
   optimize away the masking when the mask has all the relevant bits set,
   masking with the most significant bit will remain for the cmove
   test.
3) as requested, this patch adds a bunch of force_reg calls before
   gen_lowpart
4) 1-3 above unfortunately regressed
   +FAIL: gcc.target/i386/bt-mask-2.c scan-assembler-not and[lq][ \\t]
   +FAIL: gcc.target/i386/pr57819.c scan-assembler-not and[lq][ \\t]
   where we during combine match the new pattern we didn't match
   before and in the end don't match the pattern we were testing for.
   These 2 tests are fixed by the *jcc_bt<mode>_mask_1 pattern
   addition and small tweak to target rtx_costs, because even with
   the pattern around we'd refuse to match it because it appeared to
   have higher instruction cost

2022-06-02  Jakub Jelinek  <jakub@redhat.com>

PR target/105778
* config/i386/i386.md (*ashl<dwi>3_doubleword_mask): Remove :SI
from AND and its operands and just verify operands[2] has HImode,
SImode or for TARGET_64BIT DImode.  Allow operands[3] to be a mask
with all low 6 (64-bit) or 5 (32-bit) bits set and in that case
just throw away the masking.  Use force_reg before calling
gen_lowpart.
(*ashl<dwi>3_doubleword_mask_1): Allow operands[3] to be a mask
with all low 6 (64-bit) or 5 (32-bit) bits set and in that case
just throw away the masking.
(*ashl<mode>3_doubleword): Rename to ...
(ashl<mode>3_doubleword): ... this.
(*ashl<mode>3_mask): Remove :SI from AND and its operands and just
verify operands[2] has HImode, SImode or for TARGET_64BIT DImode.
Use force_reg before calling gen_lowpart.
(*<insn><mode>3_mask): Likewise.
(*<insn><dwi>3_doubleword_mask): Likewise.  Allow operands[3] to be
a mask with all low 6 (64-bit) or 5 (32-bit) bits set and in that
case just throw away the masking.  Use force_reg before calling
gen_lowpart.
(*<insn><dwi>3_doubleword_mask_1): Allow operands[3] to be a mask
with all low 6 (64-bit) or 5 (32-bit) bits set and in that case just
throw away the masking.
(*<insn><mode>3_doubleword): Rename to ...
(<insn><mode>3_doubleword): ... this.
(*<insn><mode>3_mask): Remove :SI from AND and its operands and just
verify operands[2] has HImode, SImode or for TARGET_64BIT DImode.
Use force_reg before calling gen_lowpart.
(splitter after it): Remove :SI from AND and its operands and just
verify operands[2] has HImode, SImode or for TARGET_64BIT DImode.
(*<btsc><mode>_mask, *<btsc><mode>_mask): Remove :SI from AND and its
operands and just verify operands[1] has HImode, SImode or for
TARGET_64BIT DImode.  Use force_reg before calling gen_lowpart.
(*jcc_bt<mode>_mask_1): New define_insn_and_split pattern.
* config/i386/i386.cc (ix86_rtx_costs): For ZERO_EXTRACT with
ZERO_EXTEND QI->SI in last operand ignore the cost of the ZERO_EXTEND.

* gcc.target/i386/pr105778.c: New test.

2 years agotree-optimization/101668 - relax SLP of existing vectors
Richard Biener [Tue, 31 May 2022 07:37:05 +0000 (09:37 +0200)]
tree-optimization/101668 - relax SLP of existing vectors

This relaxes the conditions on SLPing extracts from existing vectors
leveraging the relaxed VEC_PERM conditions on the input vs output
vector type compatibility.  It also handles lowpart extracts
and concats without VEC_PERMs now.

2022-05-25  Richard Biener  <rguenther@suse.de>

PR tree-optimization/101668
* tree-vect-slp.cc (vect_build_slp_tree_1): Allow BIT_FIELD_REFs
for vector types with compatible lane types.
(vect_build_slp_tree_2): Deal with this.
(vect_add_slp_permutation): Adjust.  Emit lowpart/concat
special cases without VEC_PERM.
(vectorizable_slp_permutation): Select the operand vector
type and relax requirements.  Handle identity permutes
with mismatching operand types.
* optabs-query.cc (can_vec_perm_const_p): Only allow variable
permutes for op_mode == mode.

* gcc.target/i386/pr101668.c: New testcase.
* gcc.dg/vect/bb-slp-pr101668.c: Likewise.

2 years agotree-optimization/105802 - another unswitching type issue
Richard Biener [Wed, 1 Jun 2022 13:42:06 +0000 (15:42 +0200)]
tree-optimization/105802 - another unswitching type issue

This also fixes the type of the irange used for unswitching of
switch statements.

PR tree-optimization/105802
* tree-ssa-loop-unswitch.cc (find_unswitching_predicates_for_bb):
Make sure to also compute the range in the type of the switch index.

* g++.dg/opt/pr105802.C: New testcase.

2 years agoDaily bump.
GCC Administrator [Thu, 2 Jun 2022 00:16:32 +0000 (00:16 +0000)]
Daily bump.

2 years agolibgcc: Align __EH_FRAME_BEGIN__ to pointer size
H.J. Lu [Tue, 18 Jan 2022 00:18:56 +0000 (16:18 -0800)]
libgcc: Align __EH_FRAME_BEGIN__ to pointer size

Aligne __EH_FRAME_BEGIN__ to pointer size since gcc/unwind-dw2-fde.h has

/* The first few fields of a CIE.  The CIE_id field is 0 for a CIE,
   to distinguish it from a valid FDE.  FDEs are aligned to an addressing
   unit boundary, but the fields within are unaligned.  */
struct dwarf_cie
{
  uword length;
  sword CIE_id;
  ubyte version;
  unsigned char augmentation[];
} __attribute__ ((packed, aligned (__alignof__ (void *))));

/* The first few fields of an FDE.  */
struct dwarf_fde
{
  uword length;
  sword CIE_delta;
  unsigned char pc_begin[];
} __attribute__ ((packed, aligned (__alignof__ (void *))));

which indicates that CIE/FDE should be aligned at the pointer size.

PR libgcc/27576
* crtstuff.c (__EH_FRAME_BEGIN__): Aligned to pointer size.

2 years ago[PATCH] configure: use OBJDUMP determined by libtool [PR95648]
David Seifert [Wed, 1 Jun 2022 21:21:44 +0000 (17:21 -0400)]
[PATCH] configure: use OBJDUMP determined by libtool [PR95648]

$ac_cv_prog_OBJDUMP contains the --host OBJDUMP that
libtool has inferred. Current config/gcc-plugin.m4 does
not respect the user's choice for OBJDUMP.

PR plugins/95648
config/

* gcc-plugin.m4: Use libtool's $ac_cv_prog_OBJDUMP.

gcc/

* configure: Regenerate.

libcc1/

* configure: Regenerate.

2 years agoDSE: Use the constant store source if possible
H.J. Lu [Wed, 18 May 2022 20:00:47 +0000 (13:00 -0700)]
DSE: Use the constant store source if possible

RTL DSE tracks redundant constant stores within a basic block.  When RTL
loop invariant motion hoists a constant initialization out of the loop
into a separate basic block, the constant store value becomes unknown
within the original basic block.  When recording store for RTL DSE, check
if the source register is set only once to a constant by a non-partial
unconditional load.  If yes, record the constant as the constant store
source.  It eliminates unrolled zero stores after memset 0 in a loop
where a vector register is used as the zero store source.

gcc/

PR rtl-optimization/105638
* df-core.cc (df_find_single_def_src): Moved and renamed from
find_single_def_src in loop-iv.cc.  Change the argument to rtx
and use rtx_equal_p.  Return null for partial or conditional
defs.
* df.h (df_find_single_def_src): New prototype.
* dse.cc (record_store): Use the constant source if the source
register is set only once.
* loop-iv.cc (find_single_def_src): Moved to df-core.cc.
(replace_single_def_regs): Replace find_single_def_src with
df_find_single_def_src.

gcc/testsuite/

PR rtl-optimization/105638
* g++.target/i386/pr105638.C: New test.

2 years agoc++: auto and dependent member name [PR105734]
Jason Merrill [Tue, 31 May 2022 20:31:35 +0000 (16:31 -0400)]
c++: auto and dependent member name [PR105734]

In r12-3643 I improved our handling of type names after . or -> when
unqualified lookup doesn't find anything, but it needs to handle auto
specially.

PR c++/105734

gcc/cp/ChangeLog:

* parser.cc (cp_parser_postfix_dot_deref_expression): Use typeof
if the expression has auto type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/auto57.C: New test.

2 years agoc++: auto function as function argument [PR105779]
Jason Merrill [Tue, 31 May 2022 20:17:58 +0000 (16:17 -0400)]
c++: auto function as function argument [PR105779]

This testcase demonstrates that the issue in PR105623 is not limited to
templates, so we should do the marking in a less template-specific place.

PR c++/105779

gcc/cp/ChangeLog:

* call.cc (resolve_args): Call mark_single_function here.
* pt.cc (unify_one_argument): Not here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/auto-fn63.C: New test.

2 years agoAArch64: Cleanup option processing code
Wilco Dijkstra [Wed, 1 Jun 2022 15:46:36 +0000 (16:46 +0100)]
AArch64: Cleanup option processing code

Further cleanup option processing. Remove the duplication of global
variables for CPU and tune settings so that CPU option processing is
simplified even further. Move global variables that need save and
restore due to target option processing into aarch64.opt. This removes
the need for explicit saving/restoring and unnecessary reparsing of
options.

gcc/
* config/aarch64/aarch64.opt (explicit_tune_core): Rename to
selected_tune.
(explicit_arch): Rename to selected_arch.
(x_aarch64_override_tune_string): Remove.
(aarch64_ra_sign_key): Add as TargetVariable so it gets saved/restored.
(aarch64_override_tune_string): Add Save so it gets saved/restored.
* config/aarch64/aarch64.h (aarch64_architecture_version): Remove.
* config/aarch64/aarch64.cc (aarch64_architecture_version): Remove.
(processor): Remove archtecture_version field.
(selected_arch): Remove global.
(selected_cpu): Remove global.
(selected_tune): Remove global.
(aarch64_ra_sign_key): Move global to aarch64.opt so it is saved.
(aarch64_override_options_internal): Use aarch64_get_tune_cpu.
(aarch64_override_options): Further simplify code to only set
selected_arch and selected_tune globals.
(aarch64_option_save): Remove now that target options are saved.
(aarch64_option_restore): Remove redundant target option restores.
* config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Use
AARCH64_ISA_V9.
* config/aarch64/aarch64-opts.h (aarch64_key_type): Add, moved from...
* config/aarch64/aarch64-protos.h (aarch64_key_type): Remove.
(aarch64_ra_sign_key): Remove.

2 years agomatch.pd: Optimize __builtin_mul_overflow_p (x, cst, (utype)0) to x > ~(utype)0 ...
Jakub Jelinek [Wed, 1 Jun 2022 15:54:39 +0000 (17:54 +0200)]
match.pd: Optimize __builtin_mul_overflow_p (x, cst, (utype)0) to x > ~(utype)0 / cst [PR30314]

A comparison with a constant is most likely always faster than
.MUL_OVERFLOW from which we only check whether it overflowed and not the
multiplication result, and even if not, it is simpler operation on GIMPLE
and even if a target exists where such multiplications with overflow checking
are cheaper than comparisons, because comparisons are so much more common
than overflow checking multiplications, it would be nice if it simply
arranged for comparisons to be emitted like those multiplications on its
own...

2022-06-01  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/30314
* match.pd (__builtin_mul_overflow_p (x, cst, (utype) 0) ->
x > ~(utype)0 / cst): New simplification.

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

2 years agoc++: Static init guard generation
Nathan Sidwell [Wed, 1 Jun 2022 11:52:21 +0000 (04:52 -0700)]
c++: Static init guard generation

The guard generation for a static var init was overly verbose.  We can
use a bit of RAII and avoid some rechecking.  Also in the !cxa_atexit
case, the only difference is whether can become whether to use
post-inc or pre-dec.

gcc/cp/
* decl2.cc (fix_temporary_vars_context_r): Use data argument
for new context.
(one_static_initialization_or_destruction): Adjust tree walk
call.  Refactor guard generation.

2 years agoc++: Cleanup static init generation
Nathan Sidwell [Tue, 31 May 2022 20:22:06 +0000 (13:22 -0700)]
c++: Cleanup static init generation

The static init/fini generation is showing some bitrot.  This cleans
up several places to use C++, and also take advantage of already
having checked a variable for non-nullness.

gcc/cp/
* decl2.cc (ssdf_decl): Delete global.
(start_static_storage_duration_function): Use some RAII.
(do_static_initialization_or_destruction): Likewise.
(c_parse_final_cleanups): Likewise.  Avoid rechecking 'vars'.

2 years agoc++: Make static init generation more consistent
Nathan Sidwell [Tue, 31 May 2022 14:56:53 +0000 (07:56 -0700)]
c++: Make static init generation more consistent

The end-of-compilation static init code generation functions are:

* Inconsistent in argument ordering (swapping 'is-init' and 'priority',
  wrt each other and other arguments).

* Inconsistent in naming. mostly calling the is-init argument 'initp',
  but sometimes calling it 'constructor_p' and in the worst case using
  a transcoded 'methody_type' character, and naming the priority
  argument 'initp'.

* Inconsistent in typing.  Sometimes the priority is unsigned,
  sometimes signed.  And the initp argument can of course be a bool.

* Several of the function comments have bit-rotted.

This addresses those oddities.  Name is-init 'initp', name priority
'priority'.  Place initp first, make priority unsigned.

gcc/cp/
* decl2.cc (start_objects): Replace 'method_type' parameter
with 'initp' boolean, rename and retype 'priority' parameter.
(finish_objects): Likewise.  Do not expand here.
(one_static_initialization_or_destruction): Move 'initp'
parameter first.
(do_static_initialization_or_destruction): Likewise.
(generate_ctor_or_dtor_function): Rename 'initp' parameter.
Adjust start_objects/finish_obects calls and expand here.
(generate_ctor_and_dtor_functions_for_priority): Adjust calls.
(c_parse_final_cleanups): Likewise.
(vtv_start_verification_constructor_init): Adjust.
(vtv_finish_verification_constructor_init): Use finish_objects.

2 years agotree-optimization/105786 - avoid strlen replacement for pointers
Richard Biener [Wed, 1 Jun 2022 12:13:01 +0000 (14:13 +0200)]
tree-optimization/105786 - avoid strlen replacement for pointers

This avoids matching strlen to a pointer result, avoiding ICEing
because of an integer adjustment using PLUS_EXPR on pointers.

2022-06-01  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105786
* tree-loop-distribution.cc
(loop_distribution::transform_reduction_loop): Only do strlen
replacement for integer type reductions.

* gcc.dg/torture/pr105786.c: New testcase.

2 years agounswitch: Fold case label lo/hi values to index type [PR105770]
Jakub Jelinek [Wed, 1 Jun 2022 12:00:49 +0000 (14:00 +0200)]
unswitch: Fold case label lo/hi values to index type [PR105770]

The following testcase ICEs because we use different types in comparison,
idx has int type, while CASE_LOW has char type.

While I believe all CASE_{LOW,HIGH} in the same switch have to use the same
or compatible type, the index expression can have a promoted type as happens
in this testcase.  Other spots that handle switches do such foldings too.

2022-06-01  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/105770
* tree-ssa-loop-unswitch.cc (find_unswitching_predicates_for_bb): Cast
CASE_LOW and CASE_HIGH to TREE_TYPE (idx) before comparisons with idx.

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

2 years agoConvert ranger and clients to vrange.
Aldy Hernandez [Sun, 22 May 2022 18:17:40 +0000 (20:17 +0200)]
Convert ranger and clients to vrange.

Finally, the meat of the work.  Convert ranger and associated clients
to vrange.

Everything's relatively mechanical given the previous patches.  I did
include a minor cleanup in the edge code.  There's no need to check
that the type of the switch is an integer as non-integer switches are
invalid.  I verified this with an appropriately coded assert.

Tested on x86-64 & ppc64le Linux.

gcc/ChangeLog:

* gimple-range-cache.cc (ssa_block_ranges::dump): Convert to vrange.
(sbr_vector::sbr_vector): Same.
(sbr_vector::grow): Same.
(sbr_vector::set_bb_range): Same.
(sbr_vector::get_bb_range): Same.
(sbr_sparse_bitmap::sbr_sparse_bitmap): Same.
(sbr_sparse_bitmap::set_bb_range): Same.
(sbr_sparse_bitmap::get_bb_range): Same.
(block_range_cache::set_bb_range): Same.
(block_range_cache::get_bb_range): Same.
(block_range_cache::dump): Same.
(ssa_global_cache::get_global_range): Same.
(ssa_global_cache::set_global_range): Same.
(ssa_global_cache::clear): Same.
(ssa_global_cache::dump): Same.
(ranger_cache::get_global_range): Same.
(ranger_cache::set_global_range): Same.
(ranger_cache::range_of_def): Same.
(ranger_cache::entry_range): Same.
(ranger_cache::exit_range): Same.
(ranger_cache::edge_range): Same.
(ranger_cache::range_of_expr): Same.
(ranger_cache::range_on_edge): Same.
(ranger_cache::block_range): Same.
(ranger_cache::propagate_cache): Same.
(ranger_cache::fill_block_cache): Same.
(ranger_cache::range_from_dom): Same.
* gimple-range-cache.h: Same.
* gimple-range-edge.cc (gimple_outgoing_range::get_edge_range):
Same.
(gimple_outgoing_range::switch_edge_range): Same.
(gimple_outgoing_range::edge_range_p): Same.
* gimple-range-edge.h: Same.
* gimple-range-fold.cc (fur_source::get_operand): Same.
(fur_source::get_phi_operand): Same.
(fur_edge::get_operand): Same.
(fur_edge::get_phi_operand): Same.
(fur_stmt::get_operand): Same.
(fur_stmt::get_phi_operand): Same.
(fur_list::fur_list): Same.
(fur_list::get_operand): Same.
(fur_list::get_phi_operand): Same.
(fold_range): Same.
(adjust_imagpart_expr): Same.
(adjust_realpart_expr): Same.
(gimple_range_adjustment): Same.
(fold_using_range::fold_stmt): Same.
(fold_using_range::range_of_range_op): Same.
(fold_using_range::range_of_address): Same.
(fold_using_range::range_of_phi): Same.
(fold_using_range::range_of_call): Same.
(fold_using_range::range_of_builtin_call): Same.
(fold_using_range::range_of_builtin_int_call): Same.
(fold_using_range::range_of_cond_expr): Same.
(fur_source::register_outgoing_edges): Same.
* gimple-range-fold.h (fold_range): Same.
(gimple_range_type): Same.
(gimple_range_ssa_p): Same.
* gimple-range-gori.cc (gimple_range_calc_op1): Same.
(gimple_range_calc_op2): Same.
(gori_compute::compute_operand_range_switch): Same.
(gori_compute::compute_operand_range): Same.
(gori_compute::logical_combine): Same.
(gori_compute::compute_logical_operands): Same.
(gori_compute::compute_operand1_range): Same.
(gori_compute::compute_operand2_range): Same.
(gori_compute::compute_operand1_and_operand2_range): Same.
(gori_compute::outgoing_edge_range_p): Same.
(gori_compute::condexpr_adjust): Same.
* gimple-range-gori.h (gimple_range_calc_op1): Same.
(gimple_range_calc_op2): Same.
* gimple-range-path.cc (path_range_query::get_cache): Same.
(path_range_query::set_cache): Same.
(path_range_query::range_on_path_entry): Same.
(path_range_query::internal_range_of_expr): Same.
(path_range_query::range_of_expr): Same.
(path_range_query::ssa_range_in_phi): Same.
(path_range_query::range_defined_in_block): Same.
(path_range_query::compute_ranges_in_phis): Same.
(path_range_query::compute_ranges_in_block): Same.
(path_range_query::add_to_imports): Same.
(path_range_query::range_of_stmt): Same.
* gimple-range-path.h: Same.
* gimple-range-infer.cc (gimple_infer_range::add_range): Same.
(gimple_infer_range::~side_effect_manager): Same.
(gimple_infer_range::get_nonzero): Same.
(gimple_infer_range::maybe_adjust_range): Same.
(gimple_infer_range::add_range): Same.
* gimple-range-infer.h: Same.
* gimple-range-tests.cc: Same.
* gimple-range-trace.cc (range_tracer::trailer): Same.
(debug_seed_ranger): Same.
* gimple-range-trace.h: Same.
* gimple-range.cc (gimple_ranger::range_of_expr): Same.
(gimple_ranger::range_on_entry): Same.
(gimple_ranger::range_on_exit): Same.
(gimple_ranger::range_on_edge): Same.
(gimple_ranger::fold_range_internal): Same.
(gimple_ranger::range_of_stmt): Same.
(gimple_ranger::prefill_name): Same.
(gimple_ranger::prefill_stmt_dependencies): Same.
(gimple_ranger::export_global_ranges): Same.
(gimple_ranger::dump_bb): Same.
* gimple-range.h: Same.
* gimple-ssa-warn-access.cc (check_nul_terminated_array): Same.
(memmodel_to_uhwi): Same.
* tree-ssa-loop-niter.cc (refine_value_range_using_guard): Same.
(determine_value_range): Same.
(record_nonwrapping_iv): Same.
(infer_loop_bounds_from_signedness): Same.
(scev_var_range_cant_overflow): Same.
* tree-ssa-threadedge.cc (hybrid_jt_simplifier::simplify): Same.
* value-query.cc (range_query::range_on_edge): Same.
(range_query::range_of_stmt): Same.
(range_query::value_of_expr): Same.
(range_query::value_on_edge): Same.
(range_query::value_of_stmt): Same.
(range_query::get_tree_range): Same.
(update_global_range): Same.
(get_range_global): Same.
(gimple_range_global): Same.
(global_range_query::range_of_expr): Same.
(range_query::query_relation): Same.
* value-query.h (gimple_range_global): Same.
(update_global_range): Same.
* vr-values.cc (vr_values::range_of_expr): Same.
(bounds_of_var_in_loop): Same.
(simplify_using_ranges::vrp_visit_cond_stmt): Same.
* vr-values.h (class vr_values): Same.
* tree-ssa-loop-unswitch.cc (unswitch_predicate): Same.

2 years agoRevamp irange_allocator to handle vranges.
Aldy Hernandez [Sun, 22 May 2022 18:17:39 +0000 (20:17 +0200)]
Revamp irange_allocator to handle vranges.

This patch revamps the range allocator to handle generic vrange's.
I've cleaned it up somehow to make it obvious the various things you
can allocate with it.  I've also moved away from overloads into
distinct names when appropriate.

The various entry points are now:

  // Allocate a range of TYPE.
  vrange *alloc_vrange (tree type);
  // Allocate a memory block of BYTES.
  void *alloc (unsigned bytes);
  // Return a clone of SRC.
  template <typename T> T *clone (const T &src);

It is now possible to allocate a clone of an irange, or any future
range types:

      irange *i = allocator.clone <irange> (some_irange);
      frange *f = allocator.clone <frange> (some_frange);

You can actually do so without the <>, but I find it clearer to
specify the vrange type.

So with it you can allocate a specific range type, or vrange, or a
block of memory.

I have rewritten the C style casts to C++ casts, since casts tend to
be hints of problematic designs.  With the C++ casts you can at least
grep for them easier.  Speak of which, the next patch, which converts
ranger to vrange, will further clean this space by removing some
unnecessary casts.

Tested on x86-64 Linux and ppc64le Linux.

* gimple-range-cache.cc (sbr_vector::sbr_vector): Adjust for
vrange allocator.
(sbr_vector::grow): Same.
(sbr_vector::set_bb_range): Same.
(sbr_sparse_bitmap::sbr_sparse_bitmap): Same.
(sbr_sparse_bitmap::set_bb_range): Same.
(block_range_cache::~block_range_cache): Same.
(block_range_cache::set_bb_range): Same.
(ssa_global_cache::ssa_global_cache): Same.
(ssa_global_cache::~ssa_global_cache): Same.
(ssa_global_cache::set_global_range): Same.
* gimple-range-cache.h (block_range_cache): Same.
(ssa_global_cache): Same.
* gimple-range-edge.cc
(gimple_outgoing_range::calc_switch_ranges): Same.
* gimple-range-edge.h (gimple_outgoing_range): Same.
* gimple-range-infer.cc (infer_range_manager::get_nonzero):
Same.
(infer_range_manager::add_range): Same.
* gimple-range-infer.h (class infer_range_manager): Same.
* value-range.h (class irange_allocator): Rename to...
(class vrange_allocator): ...this.
(irange_allocator::irange_allocator): New.
(vrange_allocator::vrange_allocator): New.
(irange_allocator::~irange_allocator): New.
(vrange_allocator::~vrange_allocator): New.
(irange_allocator::get_memory): Rename to...
(vrange_allocator::alloc): ...this.
(vrange_allocator::alloc_vrange): Rename from...
(irange_allocator::allocate): ...this.
(vrange_allocator::alloc_irange): New.

2 years agoConvert range-op.* to vrange.
Aldy Hernandez [Mon, 14 Mar 2022 12:31:18 +0000 (13:31 +0100)]
Convert range-op.* to vrange.

This patch provides the infrastructure to make range-ops type agnostic.

First, the range_op_handler function has been replaced with an object
of the same name.  It's coded in such a way to minimize changes to the
code base, and to encapsulate the dispatch code.

Instead of:

range_operator *op = range_op_handler (code, type);
if (op)
  op->fold_range (...);

We now do:
range_op_handler op (code, type);
if (op)
  op->fold_range (...);

I've folded gimple_range_handler into the range_op_handler class,
since it's also a query into the range operators.

Instead of:

range_operator *handler = gimple_range_handler (stmt);

We now do:

range_op_handler handler (stmt);

This all has the added benefit of moving all the dispatch code into an
independent class and avoid polluting range_operator (which we'll
further split later when frange and prange come live).

There's this annoying "using" keyword that's been added to each
operator due to hiding rules in C++.  The issue is that we will have
different virtual versions of fold_range() for each combination of
operands.  For example:

// Traditional binary op on irange's.
fold_range (irange &lhs, const irange &op1, const irange &op2);
// For POINTER_DIFF_EXPR:
fold_range (irange &lhs, const prange &op1, const prange &op2);
// Cast from irange to prange.
fold_range (prange &lhs, const irange &op1, const irange &op2);

Overloading virtuals when there are multiple same named methods causes
hidden virtuals warnings from -Woverloaded-virtual, thus the using
keyword.  An alternative would be to have different names:
fold_range_III, fold_range_IPP, fold_range_PII, but that's uglier
still.

Tested on x86-64 & ppc64le Linux.

gcc/ChangeLog:

* gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Adjust for
vrange and convert range_op_handler function calls to use the
identically named object.
* gimple-range-fold.cc (gimple_range_operand1): Same.
(gimple_range_operand2): Same.
(fold_using_range::fold_stmt): Same.
(fold_using_range::range_of_range_op): Same.
(fold_using_range::range_of_builtin_ubsan_call): Same.
(fold_using_range::relation_fold_and_or): Same.
(fur_source::register_outgoing_edges): Same.
* gimple-range-fold.h (gimple_range_handler): Remove.
* gimple-range-gori.cc (gimple_range_calc_op1): Adjust for vrange.
(gimple_range_calc_op2): Same.
(range_def_chain::get_def_chain): Same.
(gori_compute::compute_operand_range): Same.
(gori_compute::condexpr_adjust): Same.
* gimple-range.cc (gimple_ranger::prefill_name): Same.
(gimple_ranger::prefill_stmt_dependencies): Same.
* range-op.cc (get_bool_state): Same.
(class operator_equal): Add using clause.
(class operator_not_equal): Same.
(class operator_lt): Same.
(class operator_le): Same.
(class operator_gt): Same.
(class operator_ge): Same.
(class operator_plus): Same.
(class operator_minus): Same.
(class operator_mult): Same.
(class operator_exact_divide): Same.
(class operator_lshift): Same.
(class operator_rshift): Same.
(class operator_cast): Same.
(class operator_logical_and): Same.
(class operator_bitwise_and): Same.
(class operator_logical_or): Same.
(class operator_bitwise_or): Same.
(class operator_bitwise_xor): Same.
(class operator_trunc_mod): Same.
(class operator_logical_not): Same.
(class operator_bitwise_not): Same.
(class operator_cst): Same.
(class operator_identity): Same.
(class operator_unknown): Same.
(class operator_abs): Same.
(class operator_negate): Same.
(class operator_addr_expr): Same.
(class pointer_or_operator): Same.
(operator_plus::op1_range): Adjust for vrange.
(operator_minus::op1_range): Same.
(operator_mult::op1_range): Same.
(operator_cast::op1_range): Same.
(operator_bitwise_not::fold_range): Same.
(operator_negate::fold_range): Same.
(range_op_handler): Rename to...
(get_handler): ...this.
(range_op_handler::range_op_handler): New.
(range_op_handler::fold_range): New.
(range_op_handler::op1_range): New.
(range_op_handler::op2_range): New.
(range_op_handler::lhs_op1_relation): New.
(range_op_handler::lhs_op2_relation): New.
(range_op_handler::op1_op2_relation): New.
(range_cast): Adjust for vrange.
* range-op.h (range_op_handler): Remove function.
(range_cast): Adjust for vrange.
(class range_op_handler): New.
(get_bool_state): Adjust for vrange.
(empty_range_varying): Same.
(relop_early_resolve): Same.
* tree-data-ref.cc (compute_distributive_range): Same.
* tree-vrp.cc (get_range_op_handler): Remove.
(range_fold_binary_symbolics_p): Use range_op_handler class
instead of get_range_op_handler.
(range_fold_unary_symbolics_p): Same.
(range_fold_binary_expr): Same.
(range_fold_unary_expr): Same.
* value-query.cc (range_query::get_tree_range): Adjust for vrange.

2 years agoImplement generic range temporaries.
Aldy Hernandez [Mon, 14 Mar 2022 12:27:36 +0000 (13:27 +0100)]
Implement generic range temporaries.

Now that we have generic ranges, we need a way to define generic local
temporaries on the stack for intermediate calculations in the ranger
and elsewhere.  We need temporaries analogous to int_range_max, but
for any of the supported types (currently just integers, but soon
integers, pointers, and floats).

The Value_Range object is such a temporary.  It is designed to be
transparently used as a vrange.  It shares vrange's abstract API, and
implicitly casts itself to a vrange when passed around.

The ultimate name will be value_range, but we need to remove legacy
first for that to happen.  Until then, Value_Range will do.

Sample usage is as follows.  Instead of:

extern void foo (vrange &);

int_range_max t;
t.set_nonzero (type);
foo (t);

one does:

Value_Range t (type);
t.set_nonzero (type);
foo (t);

You can also delay initialization, for use in loops for example:

Value_Range t;
...
t.set_type (type);
t.set_varying (type);

Creating an supported range type, will result in an unsupported_range
object being created, which will trap if anything but set_undefined()
and undefined_p() are called on it.  There's no size penalty for the
unsupported_range, since its immutable and can be shared across
instances.

Since supports_type_p() is called at construction time for each
temporary, I've removed the non-zero check from this function, which
was mostly unneeded.  I fixed the handful of callers that were
passing null types, and in the process sped things up a bit.

As more range types come about, the Value_Range class will be augmented
to support them by adding the relevant bits in the initialization
code, etc.

Tested on x86-64 & ppc64le Linux.

gcc/ChangeLog:

* gimple-range-fold.h (gimple_range_type): Check type before
calling supports_type_p.
* gimple-range-path.cc (path_range_query::range_of_stmt): Same.
* value-query.cc (range_query::get_tree_range): Same.
* value-range.cc (Value_Range::lower_bound): New.
(Value_Range::upper_bound): New.
(Value_Range::dump): New.
* value-range.h (class Value_Range): New.
(irange::supports_type_p): Do not check if type is non-zero.

2 years agoImplement abstract vrange class.
Aldy Hernandez [Mon, 14 Mar 2022 13:04:56 +0000 (14:04 +0100)]
Implement abstract vrange class.

This is a series of patches making ranger type agnostic in preparation
for contributing support for other types of ranges (pointers and
floats initially).

The first step in this process is to implement vrange, an abstract
class that will be exclusively used by ranger, and from which all
ranges will inherit.  Vrange provides the minimum operations for
ranger to work.  The current virtual methods are what we've used to
implement frange (floats) and prange (pointers), but we may restrict
the virtual methods further as other ranges come about
(i.e. set_nonnegative() has no meaning for a future string range).

This patchset also provides a mechanism for declaring local type
agnostic ranges that can transparently hold an irange, frange,
prange's, etc, and a dispatch mechanism for range-ops to work with
various range types.  More details in the relevant patches.

FUTURE PLAN
===========

The plan after this is to contribute a bare bones implementation for
floats (frange) that will provide relationals, followed by a
separation of integers and pointers (irange and prange).  Once this is
in place, we can further enhance both floats and pointers.  For
example, pointer tracking, pointer plus optimizations, and keeping
track of NaN's, etc.

Once frange and prange come live, all ranger clients will immediately
benefit from these enhancements.  For instance, in our local branch,
the threader is already float aware with regards to relationals.

We expect to wait a few weeks before starting to contribute further
enhancements to give the tree a time to stabilize, and Andrew time to
rebase his upcoming patches  :-P.

NOTES
=====

In discussions with Andrew, it has become clear that with vrange
coming about, supports_type_p() is somewhat ambiguous.  Prior to
vrange it has been used to (a) determine if a type is supported by
ranger, (b) as a short-cut for checking if a type is pointer or integer,
as well as (c) to see if a given range can hold a type.  These things
have had the same meaning in irange, but are slightly different with
vrange.  I will address this in a follow-up patch.

Speaking of supported types, we now provide an unsupported_range
for passing around ranges for unsupported types. We've been silently
doing this for a while, in both vr-values by creating VARYING for
unsupported types with error_mark_node end points, and in ranger when
we pass an unsupported range before we realize in range_of_expr that
it's unsupported.  This class just formalizes what we've already been
doing in an irange, but making it explicit that you can't do anything
with these ranges except pass them.  Any other operation traps.

There is no GTY support for vrange yet, as we don't store it long
term.  When we contribute support for global ranges (think
SSA_NAME_RANGE_INFO but for generic ranges), we will include it.  There
was just no need to pollute this patchset with it.

TESTING
=======

The patchset has been tested on x86-64 Linux as well as ppc64 Linux.
I have also verified that we fold the same number of conditionals in
evrp as well as thread the same number of paths.  There should be no
user visible changes.

We have also benchmarked the work, with the final numbers being an
*improvement* of 1.92% for evrp, and 0.82% for VRP.  Overall
compilation has a miniscule improvement.  This is despite the extra
indirection level.

The improvements are mostly because of small cleanups required for the
generalization of ranges.  As a sanity check, I stuck kcachegrind on a
few sample .ii files to see where the time was being gained.  Most of
the gain came from gimple_range_global() being 19% faster.  This
function is called a lot, and it was constructing a legacy
value_range, then returning it by value, which the caller then had to
convert to an irange.  This is in line with other pending work:
anytime we get rid of legacy, we gain time.

I will wait a few days before committing to welcome any comments.

gcc/ChangeLog:

* value-range-equiv.cc (value_range_equiv::set): New.
* value-range-equiv.h (class value_range_equiv): Make set method
virtual.
Remove default bitmap argument from set method.
* value-range.cc (vrange::contains_p): New.
(vrange::singleton_p): New.
(vrange::operator=): New.
(vrange::operator==): New.
(irange::fits_p): Move to .cc file.
(irange::set_nonnegative): New.
(unsupported_range::unsupported_range): New.
(unsupported_range::set): New.
(unsupported_range::type): New.
(unsupported_range::set_undefined): New.
(unsupported_range::set_varying): New.
(unsupported_range::dump): New.
(unsupported_range::union_): New.
(unsupported_range::intersect): New.
(unsupported_range::zero_p): New.
(unsupported_range::nonzero_p): New.
(unsupported_range::set_nonzero): New.
(unsupported_range::set_zero): New.
(unsupported_range::set_nonnegative): New.
(unsupported_range::fits_p): New.
(irange::set): Call irange::set_undefined.
(irange::verify_range): Check discriminator field.
(irange::dump): Dump [irange] marker.
(irange::debug): Move to...
(vrange::debug): ...here.
(dump_value_range): Accept vrange.
(debug): Same.
* value-range.h (enum value_range_discriminator): New.
(class vrange): New.
(class unsupported_range): New.
(struct vrange_traits): New.
(is_a): New.
(as_a): New.
(class irange): Inherit from vrange.
(dump_value_range): Adjust for vrange.
(irange::kind): Rename to...
(vrange::kind): ...this.
(irange::varying_p): Rename to...
(vrange::varying_p): ...this.
(irange::undefined_p): Rename to...
(vrange::undefined_p): ...this.
(irange::irange): Set discriminator.
(irange::union_): Convert to irange before passing to irange
method.
(irange::intersect): Same.
(vrange::supports_type_p): New.
* vr-values.cc (vr_values::extract_range_from_binary_expr): Pass
NULL bitmap argument to value_range_equiv::set.
(vr_values::extract_range_basic): Same.

2 years ago[Ada] Allow confirming volatile properties on No_Caching variables
Yannick Moy [Mon, 9 May 2022 13:26:22 +0000 (15:26 +0200)]
[Ada] Allow confirming volatile properties on No_Caching variables

Volatile variables marked with the No_Caching aspect can now have
confirming aspects for other volatile properties, with a value of
False.

gcc/ada/

* contracts.adb (Check_Type_Or_Object_External_Properties): Check
the validity of combinations only when No_Caching is not used.
* sem_prag.adb (Analyze_External_Property_In_Decl_Part): Check
valid combinations with No_Caching.

2 years ago[Ada] Combine system.ads file - vxworks7 kernel constants.
Doug Rupp [Mon, 9 May 2022 19:19:50 +0000 (12:19 -0700)]
[Ada] Combine system.ads file - vxworks7 kernel constants.

Systemitize Word_Size and Memory_Size declarations rather than hard code
with numerical values or OS specific Long_Integer size.

gcc/ada/

* libgnat/system-vxworks7-aarch64.ads (Word_Size): Compute
based on Standard'Word_Size. (Memory_Size): Compute based
on Word_Size.
* libgnat/system-vxworks7-arm.ads: Likewise.
* libgnat/system-vxworks7-e500-kernel.ads: Likewise.
* libgnat/system-vxworks7-ppc-kernel.ads: Likewise.
* libgnat/system-vxworks7-ppc64-kernel.ads: Likewise.
* libgnat/system-vxworks7-x86-kernel.ads: Likewise.
* libgnat/system-vxworks7-x86_64-kernel.ads: Likewise.

2 years ago[Ada] Combine system.ads files - arm and aarch64 qnx
Doug Rupp [Mon, 9 May 2022 18:37:17 +0000 (11:37 -0700)]
[Ada] Combine system.ads files - arm and aarch64 qnx

Systemitize Word_Size and Memory_Size declarations rather than hard code
with numerical values or OS specific Long_Integer size.

gcc/ada/

* libgnat/system-qnx-arm.ads (Memory_Size): Compute based on
Word_Size.

2 years ago[Ada] Fix missing space in error message
Piotr Trojanek [Tue, 3 May 2022 12:13:13 +0000 (14:13 +0200)]
[Ada] Fix missing space in error message

On illegal code like:

   type T is new Positive in range 1..5;

the compiler was emitting message:

  error: extra "in"ignored
                  ^^

which lacked a space character.

A tiny diagnostic improvement; spotted while mistakenly typing an
illegal test.

gcc/ada/

* par-util.adb (Ignore): Add missing space to message string.

2 years ago[Ada] Fix classification of Subprogram_Variant as assertion pragma
Yannick Moy [Mon, 9 May 2022 10:49:41 +0000 (12:49 +0200)]
[Ada] Fix classification of Subprogram_Variant as assertion pragma

This pragma was wrongly not recognized as an assertion pragma.  Now
fixed.

gcc/ada/

* sem_prag.ads (Assertion_Expression_Pragmas): Fix value for
pragma Subprogram_Variant.

2 years ago[Ada] Rename Returns_On_Secondary_Stack into Needs_Secondary_Stack
Eric Botcazou [Mon, 9 May 2022 08:17:09 +0000 (10:17 +0200)]
[Ada] Rename Returns_On_Secondary_Stack into Needs_Secondary_Stack

The Returns_On_Secondary_Stack predicate is a misnomer because it must be
invoked on a type and types do not return; as a matter of fact, the other
Returns_XXX predicates apply to functions.

gcc/ada/

* exp_ch6.adb (Caller_Known_Size): Invoke Needs_Secondary_Stack in
lieu of Returns_On_Secondary_Stack.
(Expand_Call_Helper): Likewise.
(Expand_Simple_Function_Return): Likewise.
(Needs_BIP_Alloc_Form): Likewise.
* exp_ch7.adb (Wrap_Transient_Declaration): Likewise.
* sem_res.adb (Resolve_Call): Likewise.
(Resolve_Entry_Call): Likewise.
* sem_util.ads (Returns_On_Secondary_Stack): Rename into...
(Needs_Secondary_Stack): ...this.
* sem_util.adb (Returns_On_Secondary_Stack): Rename into...
(Needs_Secondary_Stack): ...this.
* fe.h (Returns_On_Secondary_Stack): Delete.
(Needs_Secondary_Stack): New function.
* gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Replace call
to Returns_On_Secondary_Stack with Needs_Secondary_Stack.

2 years ago[Ada] Do not freeze subprogram body without spec too early
Eric Botcazou [Mon, 9 May 2022 06:56:27 +0000 (08:56 +0200)]
[Ada] Do not freeze subprogram body without spec too early

This fixes a small oddity whereby a subprogram body declared without a spec
would be frozen before its entity is fully processed as an overloaded name.
Now the latter step computes useful information, for example whether the
body is a (late) primitive of a tagged type, which can be required during
the freezing process.  The change also adjusts Check_Dispatching_Operation
accordingly.  No functional changes.

gcc/ada/

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): For the case where
there is no previous declaration, freeze the body entity only after
it has been processed as a new overloaded name.
Use Was_Expression_Function to recognize expression functions.
* sem_disp.adb (Check_Dispatching_Operation): Do not require a body
which is the last primitive to be frozen here.

2 years ago[Ada] Bug fix in "=" function of formal doubly linked list
Julien Bortolussi [Fri, 6 May 2022 14:48:31 +0000 (16:48 +0200)]
[Ada] Bug fix in "=" function of formal doubly linked list

Correction of a typo regarding indexes.

gcc/ada/

* libgnat/a-cfdlli.adb ("="): Make the function properly loop
over the right list.

2 years ago[Ada] Fix predicate check on object declaration
Marc Poulhiès [Fri, 22 Apr 2022 15:52:49 +0000 (17:52 +0200)]
[Ada] Fix predicate check on object declaration

When subtype predicate checks are added for object declarations, it
could lead to a compiler crash or to an incorrect check.

When the subtype for the object being declared is built later by
Analyze_Object_Declaration, the predicate check can't be applied on the
object instead of a copy as the call will be incorrect after the subtype
has been built.

When subtypes for LHS and RHS do not statically match, only checking the
predicate on the object after it has been initialized may miss a failing
predicate on the RHS.

In both cases, skip the optimization and check the predicate on a copy.

Rename Should_Build_Subtype into Build_Default_Subtype_OK and move it
out of sem_ch3 to make it available to other part of the compiler (in
particular to checks.adb).

gcc/ada/

* checks.adb (Apply_Predicate_Check): Refine condition for
applying optimization.
* sem_ch3.adb (Analyze_Component_Declaration): Adjust calls to
Should_Build_Subtype.
(Analyze_Object_Declaration): Likewise.
(Should_Build_Subtype): Rename/move to ...
* sem_util.ads (Build_Default_Subtype_OK): ... this.
* sem_util.adb (Build_Default_Subtype_OK): Moved from
sem_ch3.adb.

2 years ago[Ada] arm-qnx-7.1: unwind goes wrong after regs restore
Doug Rupp [Fri, 6 May 2022 22:28:49 +0000 (15:28 -0700)]
[Ada] arm-qnx-7.1: unwind goes wrong after regs restore

Bump the pc +3 total for Thumb mode, the same calculation that as is
done for arm-linux.

gcc/ada/

* init.c (__gnat_adjust_context_for_raise) [QNX][__thumb2__]: Bump
the pc an extra byte.

2 years ago[Ada] Enable using absolute paths in -fdiagnostics-format=json output
Ghjuvan Lacambre [Fri, 6 May 2022 16:53:57 +0000 (18:53 +0200)]
[Ada] Enable using absolute paths in -fdiagnostics-format=json output

This commit makes GNAT use absolute paths in -fdiagnostics-format=json's
output when -gnatef is present on the command line. This makes life
easier for tools that ingest GNAT's output.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Document new behavior.
* errout.adb (Write_JSON_Location): Output absolute paths when
needed.
* switch-c.adb (Scan_Front_End_Switches): Update -gnatef
comment.
* usage.adb (Usage): Update description of -gnatef.
* gnat_ugn.texi: Regenerate.

2 years ago[Ada] Fix bad interaction between Inline_Always and -gnateV + -gnata
Eric Botcazou [Fri, 6 May 2022 20:48:04 +0000 (22:48 +0200)]
[Ada] Fix bad interaction between Inline_Always and -gnateV + -gnata

The combination of pragma/aspect Inline_Always and -gnateV -gnata runs
afoul of the handling of inlining across units by gigi, which does not
inline a subprogram that calls nested subprograms if these subprograms
are not themselves inlined.

This condition does not apply to internally generated subprograms but
the special _postconditions procedure has Debug_Info_Needed set so it
is not considered as such and, as a consequence, triggers an error if
the enclosing subprogram requires inlining by means of Inline_Always.

The _postconditions procedure is already marked inlined when generating
C code so it makes sense to mark it inlined in the general case as well.

gcc/ada/

* contracts.adb (Build_Postconditions_Procedure): Set Is_Inlined
unconditionnally on the procedure entity.

2 years ago[Ada] Propagate null-exclusion to anonymous access types
Piotr Trojanek [Fri, 6 May 2022 15:23:25 +0000 (17:23 +0200)]
[Ada] Propagate null-exclusion to anonymous access types

When analyzing an array or record type declaration whose component has a
constrained access type, e.g.:

   type Buffer_Acc is not null access all String;

   type Buffer_Rec is record
      Data : Buffer_Acc (1 .. 10);
   end record;

   type Buffer_Arr is array (Boolean) of Buffer_Acc (1 .. 10);

we propagated various properties of the unconstrained access type (e.g.
the designated type, access-to-constant flag), but forgot to propagate
the null-exclusion.

For GNAT it didn't make a big difference, because the (anonymous)
component type was never subject to legality checks. The "value
tracking" optimisation machinery, which also deals with null values,
only works for entire objects and doesn't care about components.
However, GNATprove uses this flag when an access-to-component object is
dereferenced.

gcc/ada/

* sem_ch3.adb (Constrain_Access): Propagate null-exclusion flag
from parent type.

2 years ago[Ada] Add a comment about a finalization issue
Eric Botcazou [Fri, 6 May 2022 14:56:41 +0000 (16:56 +0200)]
[Ada] Add a comment about a finalization issue

gcc/ada/

* sem_ch5.adb (Analyze_Loop_Statement): Add a comment about
a finalization issue.

2 years ago[Ada] Get rid of secondary stack for controlled components of limited types
Eric Botcazou [Thu, 5 May 2022 16:08:50 +0000 (18:08 +0200)]
[Ada] Get rid of secondary stack for controlled components of limited types

The initial work didn't change anything for limited types because they use
a specific return mechanism for functions called build-in-place where there
is no anonymous return object, so the secondary stack was used only for the
sake of consistency with the nonlimited case.

This change aligns the limited case with the nonlimited case, i.e. either
they both use the primary stack or they both use the secondary stack.

gcc/ada/

* exp_ch6.adb (Caller_Known_Size): Call Returns_On_Secondary_Stack
instead of Requires_Transient_Scope and tidy up.
(Needs_BIP_Alloc_Form): Likewise.
* exp_util.adb (Initialized_By_Aliased_BIP_Func_Call): Also return
true if the build-in-place function call has no BIPalloc parameter.
(Is_Finalizable_Transient): Remove redundant test.

2 years ago[Ada] Note that hardening features are experimental
Alexandre Oliva [Thu, 5 May 2022 03:45:38 +0000 (00:45 -0300)]
[Ada] Note that hardening features are experimental

Some features haven't got customer feedback or made upstream yet.

gcc/ada/

* doc/gnat_rm/security_hardening_features.rst: Note that hardening
features are experimental.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] Another case where freezing incorrectly suppresses checks
Steve Baird [Wed, 4 May 2022 23:23:40 +0000 (16:23 -0700)]
[Ada] Another case where freezing incorrectly suppresses checks

Avoid improperly suppressing checks for the wrapper subprogram that is
built when a null type extension inherits (and does not override) a
function with a controlling result. This is a follow-up to other changes
already made on this ticket.

gcc/ada/

* exp_ch3.adb (Make_Controlling_Function_Wrappers): Set the
Corresponding_Spec field of a wrapper subprogram body before
analyzing the subprogram body; the field will be set (again)
during analysis, but we need it to be set earlier.
* exp_ch13.adb (Expand_N_Freeze_Entity): Add wrapper subprogram
bodies to the list of declarations for which we do not want to
suppress checks.

2 years ago[Ada] Adjust reference in comment
Eric Botcazou [Thu, 5 May 2022 09:02:07 +0000 (11:02 +0200)]
[Ada] Adjust reference in comment

This is needed after the creation of Returns_On_Secondary_Stack from the
original Requires_Transient_Scope.

gcc/ada/

* sem_util.adb (Indirect_Temp_Needed): Adjust reference in comment.

2 years ago[Ada] QNX shared libraries - arm-qnx build gnatlib .so's
Doug Rupp [Fri, 29 Apr 2022 21:15:17 +0000 (14:15 -0700)]
[Ada] QNX shared libraries - arm-qnx build gnatlib .so's

Shared libraries now fully supported on arm-qnx.

gcc/ada/

* Makefile.rtl (GNATLIB_SHARED): Revert disablement for arm-qnx.

2 years ago[Ada] Fix composability of return on the secondary stack
Eric Botcazou [Wed, 4 May 2022 10:31:14 +0000 (12:31 +0200)]
[Ada] Fix composability of return on the secondary stack

Having components that need to be returned on the secondary stack would
not always force a record type to be returned on the secondary stack
itself.

gcc/ada/

* sem_util.adb
(Returns_On_Secondary_Stack.Caller_Known_Size_Record): Directly
check the dependence on discriminants for the variant part, if
any, instead of calling the Is_Definite_Subtype predicate.

2 years ago[Ada] Fix "formal parameter & is not referenced" not being properly tagged
Ghjuvan Lacambre [Wed, 4 May 2022 11:31:07 +0000 (13:31 +0200)]
[Ada] Fix "formal parameter & is not referenced" not being properly tagged

gcc/ada/

* sem_warn.adb (Warn_On_Unreferenced_Entity): Fix warning tag.

2 years ago[Ada] Adjust warning switches
Ghjuvan Lacambre [Tue, 3 May 2022 14:00:46 +0000 (16:00 +0200)]
[Ada] Adjust warning switches

This makes tagging more accurate.

gcc/ada/

* sem_warn.adb (Check_References): Adjust conditions under which
warning messages should be emitted and their tags as well.

2 years ago[Ada] Minor tweaks to dispatching support code
Eric Botcazou [Mon, 2 May 2022 08:07:38 +0000 (10:07 +0200)]
[Ada] Minor tweaks to dispatching support code

No functional changes.

gcc/ada/

* exp_disp.ads (Expand_Interface_Thunk): Change type of Prim.
* exp_disp.adb (Expand_Interface_Thunk): Declare Is_Predef_Op
earlier, do not initialize Iface_Formal, use No idiom and tweaks
comments.
(Register_Primitive): Declare L earlier and tweak comments.
* sem_disp.adb (Check_Dispatching_Operation): Move tests out of
loop.

2 years ago[Ada] Missing discriminant checks when accessing variant field
Steve Baird [Fri, 29 Apr 2022 21:55:38 +0000 (14:55 -0700)]
[Ada] Missing discriminant checks when accessing variant field

In some cases, the compiler would incorrectly fail to generate
discriminant checks when accessing fields declared in a variant part.
Correct some such cases; detect the remaining cases and flag them as
unsupported. The formerly-problematic cases that are now handled
correctly involve component references occurring in a predicate
expression (e.g., the expression of a Dynamic_Predicate aspect
specification) for a type declaration (not for a subtype declaration).
The cases which are now flagged as unsupported involve expression
functions declared before the discriminated type in question has been
frozen.

gcc/ada/

* exp_ch3.ads: Replace visible Build_Discr_Checking_Funcs (which
did not need to be visible - it was not referenced outside this
package) with Build_Or_Copy_Discr_Checking_Funcs.
* exp_ch3.adb: Refactor existing code into 3 procedures -
Build_Discr_Checking_Funcs, Copy_Discr_Checking_Funcs, and
Build_Or_Copy_Discr_Checking_Funcs. This refactoring is intended
to be semantics-preserving.
* exp_ch4.adb (Expand_N_Selected_Component): Detect case where a
call should be generated to the Discriminant_Checking_Func for
the component in question, but that subprogram does not yet
exist.
* sem_ch13.adb (Freeze_Entity_Checks): Immediately before
calling Build_Predicate_Function, add a call to
Exp_Ch3.Build_Or_Copy_Discr_Checking_Funcs in order to ensure
that Discriminant_Checking_Func attributes are already set when
Build_Predicate_Function is called.
* sem_ch6.adb (Analyze_Expression_Function): If the expression
of a static expression function has been transformed into an
N_Raise_xxx_Error node, then we need to copy the original
expression in order to check the requirement that the expression
must be a potentially static expression. We also want to set
aside a copy the untransformed expression for later use in
checking calls to the expression function via
Inline_Static_Function_Call.  So introduce a new function,
Make_Expr_Copy, for use in these situations.
* sem_res.adb (Preanalyze_And_Resolve): When analyzing certain
expressions (e.g., a default parameter expression in a
subprogram declaration) we want to suppress checks. However, we
do not want to suppress checks for the expression of an
expression function.

2 years ago[Ada] Fix search for "for ... of" loop subprograms
Bob Duff [Mon, 2 May 2022 18:11:03 +0000 (14:11 -0400)]
[Ada] Fix search for "for ... of" loop subprograms

This patch makes the search for Get_Element_Access, Step (Next/Prev),
Reference_Control_Type, and Pseudo_Reference (for optimized "for ... of"
loops) more robust.  In particular, we have a new Next procedure in Ada
2022, and we need to pick the right one.

We have not yet added the new Next and other subprograms.

gcc/ada/

* exp_ch5.adb (Expand_Iterator_Loop_Over_Container): For each
subprogram found, assert that the variable is Empty, so we can
detect bugs where we find two or more things with the same name.
Without this patch, that bug would happen when we add the new
Next procedure.  For Step, make sure we pick the right one, by
checking name and number of parameters.  For Get_Element_Access,
check that we're picking a function.  That's not really
necessary, because there is no procedure with that name, but it
seems cleaner this way.
* rtsfind.ads: Minor comment improvement. It seems kind of odd
to say "under no circumstances", and then immediately contradict
that with "The one exception is...".

2 years ago[Ada] arm-qnx-7.1: unwind goes wrong after regs restore
Doug Rupp [Thu, 14 Apr 2022 17:59:37 +0000 (10:59 -0700)]
[Ada] arm-qnx-7.1: unwind goes wrong after regs restore

The usual increment of the pc to pc+2 for ARM is needed.

gcc/ada/

* init.c (QNX): __gnat_adjust_context_for_raise: New
implementation for arm-qnx.

2 years ago[Ada] Add reference counting in functional containers
Julien Bortolussi [Thu, 21 Apr 2022 09:11:26 +0000 (11:11 +0200)]
[Ada] Add reference counting in functional containers

This patch adds reference counting to dynamically allocated pointers
on arrays and elements used by the functional container. This is done
by making both the arrays and the elements controlled.

gcc/ada/

* libgnat/a-cofuba.ads, libgnat/a-cofuba.adb: Add reference
counting.