Commit Graph

210715 Commits (master)

Author SHA1 Message Date
Palmer Dabbelt a6114c2a69 RISC-V: Implement -m{,no}fence-tso
Some processors from T-Head don't implement the `fence.tso` instruction
natively and instead trap to firmware.  This breaks some users who
haven't yet updated the firmware and one could imagine it breaking users
who are trying to build firmware if they're using the C memory model.

So just add an option to disable emitting it, in a similar fashion to
how we allow users to forbid other instructions.

Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1070959
---
I've just smoke tested this one, but

    void func(void) { __atomic_thread_fence(__ATOMIC_ACQ_REL); }

generates `fence.tso` without the argument and `fence rw,rw` with
`-mno-fence-tso`, so it seems to be at least mostly there.  I figured
I'd just send it up for comments before putting together the DG bits:
it's kind of a pain to carry around these workarounds for unimplemented
instructions, but it's in HW so there's not much we can do about that.

gcc/ChangeLog:

	* config/riscv/riscv.opt: Add -mno-fence-tso.
	* config/riscv/sync-rvwmo.md (mem_thread_fence_rvwmo): Respect
	-mno-fence-tso.
	* doc/invoke.texi (RISC-V): Document -mno-fence-tso.
2024-05-18 15:16:45 -06:00
Jeff Law 3c9c52a1c0 [to-be-committed,RISC-V] Improve some shift-add sequences
So this is a minor fix/improvement for shift-add sequences.  This was
supposed to help xz in a minor way IIRC.

Combine may present us with (x + C2') << C1 which was canonicalized from
(x << C1) + C2.

Depending on the precise values of C2 and C2' one form may be better
than the other.  We can (somewhat awkwardly) use riscv_const_insns to
test for which sequence would be preferred.

Tested on Ventana's CI system as well as my own.  Waiting on CI results
from Rivos's tester before moving forward.

Jeff
gcc/
	* config/riscv/riscv.md: Add new patterns to allow selection
	between (x << C1) + C2 vs (x + C2') << C1 depending on the
	cost C2 vs C2'.

gcc/testsuite

	* gcc.target/riscv/shift-add-1.c: New test.
2024-05-18 15:08:07 -06:00
Wolfgang Hospital 988838da72 AVR: target/115065 - Tweak __clzhi2.
The libgcc implementation of __clzhi2 can be tweaked by
one cycle in some situations by re-arranging the instructions.
It also reduces the WCET by 1 cycle.

libgcc/
	PR target/115065
	* config/avr/lib1funcs.S (__clzhi2): Tweak.
2024-05-18 15:12:10 +02:00
Xiao Zeng 7422e050f3 RISC-V: Fix "Nan-box the result of movbf on soft-bf16"
1 According to unpriv-isa spec:
<https://github.com/riscv/riscv-isa-manual/releases/download/riscv-isa-release-221bd85-2024-05-14/unpriv-isa-asciidoc.pdf>
  1.1 "FMV.H.X moves the half-precision value encoded in IEEE 754-2008
  standard encoding from the lower 16 bits of integer register rs1
  to the floating-point register rd, NaN-boxing the result."
  1.2 "FMV.W.X moves the single-precision value encoded in IEEE 754-2008
  standard encoding from the lower 32 bits of integer register rs1
  to the floating-point register rd. The bits are not modified in the
  transfer, and in particular, the payloads of non-canonical NaNs are preserved."

2 When (!TARGET_ZFHMIN == true && TARGET_HARD_FLOAT == true), instruction needs
to be added to complete the Nan-box, as done in
"RISC-V: Nan-box the result of movhf on soft-fp16":
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=057dc349021660c40699fb5c98fd9cac8e168653>

3 Consider the "RISC-V: Nan-box the result of movbf on soft-bf16" in:
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ce51e6727c9d69bbab0e766c449e60fd41f5f2f9>
It ignores that both hf16 and bf16 are 16bits floating-point.

4 zfbfmin -> zfhmin in:
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=35224ead63732a3550ba4b1332c06e9dc7999c31>

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_legitimize_move): Optimize movbf
	with Nan-boxing value.
	* config/riscv/riscv.md (*movhf_softfloat_boxing): Expand movbf
	with Nan-boxing value.
	(*mov<HFBF:mode>_softfloat_boxing): Ditto.
	with Nan-boxing value.
	(*movbf_softfloat_boxing): Delete abandon pattern.
2024-05-18 11:18:16 +08:00
Xiao Zeng 6da1d6efde RISC-V: Modify _Bfloat16 to __bf16
According to the description in:
<https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/367>,
the type representation symbol of BF16 has been corrected.

Kito Cheng pointed out relevant information in the email:
<https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651850.html>

gcc/ChangeLog:

	* config/riscv/riscv-builtins.cc (riscv_init_builtin_types):
	Modify _Bfloat16 to __bf16.
	* config/riscv/riscv.cc (riscv_mangle_type): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/_Bfloat16-nanboxing.c: Move to...
	* gcc.target/riscv/__bf16-nanboxing.c: ...here.
	* gcc.target/riscv/bf16_arithmetic.c: Modify _Bfloat16 to __bf16.
	* gcc.target/riscv/bf16_call.c: Ditto.
	* gcc.target/riscv/bf16_comparison.c: Ditto.
	* gcc.target/riscv/bf16_float_libcall_convert.c: Ditto.
	* gcc.target/riscv/bf16_integer_libcall_convert.c: Ditto.
2024-05-18 11:05:42 +08:00
Pan Li 34ed2b4593 RISC-V: Implement IFN SAT_ADD for both the scalar and vector
The patch implement the SAT_ADD in the riscv backend as the
sample for both the scalar and vector.  Given below vector
as example:

void vec_sat_add_u64 (uint64_t *out, uint64_t *x, uint64_t *y, unsigned n)
{
  unsigned i;

  for (i = 0; i < n; i++)
    out[i] = (x[i] + y[i]) | (- (uint64_t)((uint64_t)(x[i] + y[i]) < x[i]));
}

Before this patch:
vec_sat_add_u64:
  ...
  vsetvli a5,a3,e64,m1,ta,ma
  vle64.v v0,0(a1)
  vle64.v v1,0(a2)
  slli    a4,a5,3
  sub     a3,a3,a5
  add     a1,a1,a4
  add     a2,a2,a4
  vadd.vv v1,v0,v1
  vmsgtu.vv       v0,v0,v1
  vmerge.vim      v1,v1,-1,v0
  vse64.v v1,0(a0)
  ...

After this patch:
vec_sat_add_u64:
  ...
  vsetvli a5,a3,e64,m1,ta,ma
  vle64.v v1,0(a1)
  vle64.v v2,0(a2)
  slli    a4,a5,3
  sub     a3,a3,a5
  add     a1,a1,a4
  add     a2,a2,a4
  vsaddu.vv       v1,v1,v2  <=  Vector Single-Width Saturating Add
  vse64.v v1,0(a0)
  ...

The below test suites are passed for this patch.
* The riscv fully regression tests.
* The aarch64 fully regression tests.
* The x86 bootstrap tests.
* The x86 fully regression tests.

	PR target/51492
	PR target/112600

gcc/ChangeLog:

	* config/riscv/autovec.md (usadd<mode>3): New pattern expand for
	the unsigned SAT_ADD in vector mode.
	* config/riscv/riscv-protos.h (riscv_expand_usadd): New func decl
	to expand usadd<mode>3 pattern.
	(expand_vec_usadd): Ditto but for vector.
	* config/riscv/riscv-v.cc (emit_vec_saddu): New func impl to emit
	the vsadd insn.
	(expand_vec_usadd): New func impl to expand usadd<mode>3 for vector.
	* config/riscv/riscv.cc (riscv_expand_usadd): New func impl to
	expand usadd<mode>3 for scalar.
	* config/riscv/riscv.md (usadd<mode>3): New pattern expand for
	the unsigned SAT_ADD in scalar mode.
	* config/riscv/vector.md: Allow VLS mode for vsaddu.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/binop/vec_sat_binary.h: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-1.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-2.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-3.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-4.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-run-1.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-run-2.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-run-3.c: New test.
	* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add-run-4.c: New test.
	* gcc.target/riscv/sat_arith.h: New test.
	* gcc.target/riscv/sat_u_add-1.c: New test.
	* gcc.target/riscv/sat_u_add-2.c: New test.
	* gcc.target/riscv/sat_u_add-3.c: New test.
	* gcc.target/riscv/sat_u_add-4.c: New test.
	* gcc.target/riscv/sat_u_add-run-1.c: New test.
	* gcc.target/riscv/sat_u_add-run-2.c: New test.
	* gcc.target/riscv/sat_u_add-run-3.c: New test.
	* gcc.target/riscv/sat_u_add-run-4.c: New test.
	* gcc.target/riscv/scalar_sat_binary.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2024-05-18 10:16:09 +08:00
Eric Botcazou 5812e1bbb1 Fix Ada runtime library breakage on Solaris
The recent changes made to the runtime library broke its build on Solaris
because it uses Solaris threads instead of POSIX threads on this platform.

gcc/ada/
	PR ada/115133
	* libgnarl/s-osinte__solaris.ads (mutex_t): Fix typo.
	* libgnarl/s-taprop__solaris.adb (Record_Lock): Add conversion.
	(Check_Sleep): Likewise.
	(Record_Wakeup): Likewise.
	(Check_Unlock): Likewise.
	* libgnarl/s-tasini.adb (Initialize_RTS_Lock): Add pragma Import
	on the overlaid variable.
	(Finalize_RTS_Lock): Likewise.
	(Acquire_RTS_Lock): Likewise.
	(Release_RTS_Lock): Likewise.
	* libgnarl/s-taspri__solaris.ads (To_RTS_Lock_Ptr): New instance
	of Ada.Unchecked_Conversion.
	* libgnat/s-oslock__solaris.ads: Add with clause for
	Ada.Unchecked_Conversion.
	(array_type_9): Add missing name qualification.
	(record_type_3): Likewise.
	(mutex_t): Fix formatting.
2024-05-18 00:24:46 +02:00
David Malcolm 4e3bb431bb Regenerate common.opt.urls
I forgot to do this for r15-636-g770657d02c986c.

gcc/ChangeLog:
	* common.opt.urls: Regenerate to add
	fdiagnostics-show-event-links.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-17 17:56:56 -04:00
Robin Dapp e0b9c8ad70 RISC-V: Add initial cost handling for segment loads/stores.
This patch makes segment loads and stores more expensive.  It adds
segment_permute_2 as well as 3 to 8 cost fields to the common vector
costs and adds handling to adjust_stmt_cost.

gcc/ChangeLog:

	* config/riscv/riscv-protos.h (struct common_vector_cost): Add
	segment_permute cost.
	* config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost):
	Handle segment loads/stores.
	* config/riscv/riscv.cc: Initialize segment_permute_[2-8] to 1.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/costmodel/riscv/rvv/pr113112-4.c: Adjust test.
2024-05-17 22:31:43 +02:00
Robin Dapp 7ca35f2e43 internal-fn: Do not force vcond_mask operands to reg.
In order to directly use constants this patch removes force_regs
in the vcond_mask expander.

gcc/ChangeLog:

	PR middle-end/113474

	* internal-fn.cc (expand_vec_cond_mask_optab_fn):  Remove
	force_regs.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr113474.c: New test.
2024-05-17 22:31:42 +02:00
Tom Tromey 9b6acf5357 Use DW_TAG_module for Ada
DWARF is not especially clear on the distinction between
DW_TAG_namespace and DW_TAG_module, but I think that DW_TAG_module is
more appropriate for Ada.  This patch changes the compiler to do this.
Note that the Ada compiler does not yet create NAMESPACE_DECLs.

gcc

	* dwarf2out.cc (gen_namespace_die): Use DW_TAG_module for Ada.
2024-05-17 13:08:08 -06:00
David Malcolm 770657d02c diagnostics, analyzer: add CFG edge visualization to path-printing
This patch adds some ability for links between labelled ranges when
quoting the user's source code, and uses this to add links between
events when printing diagnostic_paths, chopping them up further into
event ranges that can be printed together.
It adds links to the various "from..." - "...to" events in the
analyzer.

For example, previously we emitted this for
c-c++-common/analyzer/infinite-loop-linked-list.c's
while_loop_missing_next':

infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]
   30 |   while (n)
      |          ^
  'while_loop_missing_next': events 1-5
   30 |   while (n)
      |          ^
      |          |
      |          (1) infinite loop here
      |          (2) when 'n' is non-NULL: always following 'true' branch...
      |          (5) ...to here
   31 |     {
   32 |       sum += n->val;
      |       ~~~~~~~~~~~~~
      |           |   |
      |           |   (3) ...to here
      |           (4) looping back...

whereas with the patch we now emit:

infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]
   30 |   while (n)
      |          ^
  'while_loop_missing_next': events 1-3
   30 |   while (n)
      |          ^
      |          |
      |          (1) infinite loop here
      |          (2) when 'n' is non-NULL: always following 'true' branch... ->-+
      |                                                                         |
      |                                                                         |
      |+------------------------------------------------------------------------+
   31 ||    {
   32 ||      sum += n->val;
      ||             ~~~~~~
      ||              |
      |+------------->(3) ...to here
  'while_loop_missing_next': event 4
   32 |       sum += n->val;
      |       ~~~~^~~~~~~~~
      |           |
      |           (4) looping back... ->-+
      |                                  |
  'while_loop_missing_next': event 5
      |                                  |
      |+---------------------------------+
   30 ||  while (n)
      ||         ^
      ||         |
      |+-------->(5) ...to here

which I believe is easier to understand.

The patch also implements the use of unicode characters and colorization
for the lines (not shown in the above example).

There is a new option -fno-diagnostics-show-event-links for getting
back the old behavior (added to -fdiagnostics-plain-output).

gcc/analyzer/ChangeLog:
	* checker-event.h (checker_event::connect_to_next_event_p):
	Implement new diagnostic_event::connect_to_next_event_p vfunc.
	(start_cfg_edge_event::connect_to_next_event_p): Likewise.
	(start_consolidated_cfg_edges_event::connect_to_next_event_p):
	Likewise.
	* infinite-loop.cc (class looping_back_event): New subclass.
	(infinite_loop_diagnostic::add_final_event): Use it.

gcc/ChangeLog:
	* common.opt (fdiagnostics-show-event-links): New option.
	* diagnostic-label-effects.h: New file.
	* diagnostic-path.h (diagnostic_event::connect_to_next_event_p):
	New pure virtual function.
	(simple_diagnostic_event::connect_to_next_event_p): Implement it.
	(simple_diagnostic_event::connect_to_next_event): New.
	(simple_diagnostic_event::m_connected_to_next_event): New field.
	(simple_diagnostic_path::connect_to_next_event): New decl.
	* diagnostic-show-locus.cc: Include "text-art/theme.h" and
	"diagnostic-label-effects.h".
	(colorizer::set_cfg_edge): New.
	(layout::m_fallback_theme): New field.
	(layout::m_theme): New field.
	(layout::m_effect_info): New field.
	(layout::m_link_lhs_state): New enum and field.
	(layout::m_link_rhs_column): New field.
	(layout_range::has_in_edge): New.
	(layout_range::has_out_edge): New.
	(layout::layout): Add "effect_info" optional param.  Initialize
	m_theme, m_link_lhs_state, and m_link_rhs_column.
	(layout::maybe_add_location_range): Remove stray "FIXME" from
	leading comment.
	(layout::print_source_line): Replace space after margin with a
	call to print_leftmost_column.
	(layout::print_leftmost_column): New.
	(layout::start_annotation_line): Make non-const.  Gain
	responsibility for printing the leftmost column after the margin.
	(layout::print_annotation_line): Drop pp_space, as this is now
	added by start_annotation_line.
	(line_label::line_label): Add "has_in_edge" and "has_out_edge"
	params and initialize...
	(line_label::m_has_in_edge): New field.
	(line_label::m_has_out_edge): New field.
	(layout::print_any_labels): Pass edge information to line_label
	ctor.  Keep track of in-edges and out-edges, adding visualizations
	of these links between labels.
	(layout::print_leading_fixits):  Drop pp_character, as this is now
	added by start_annotation_line.
	(layout::print_trailing_fixits): Fix off-by-one errors in column
	calculation.
	(layout::move_to_column): Add comment about debugging.
	(layout::show_ruler): Make non-const.  Drop pp_space calls, as
	this is now added by start_annotation_line.
	(layout::print_line): Call print_any_right_to_left_edge_lines.
	(layout::print_any_right_to_left_edge_lines): New.
	(layout::update_any_effects): New.
	(gcc_rich_location::add_location_if_nearby): Initialize
	loc_range.m_label.
	(diagnostic_context::maybe_show_locus): Add "effects" param and
	pass it to diagnostic_context::show_locus.
	(diagnostic_context::show_locus): Add "effects" param, passing it
	to layout's ctor.  Call update_any_effects on the layout after
	printing the lines.
	(selftest::test_layout_x_offset_display_utf8): Update expected
	result for eliminated trailing newline.
	(selftest::test_layout_x_offset_display_utf8): Likewise.
	(selftest::test_layout_x_offset_display_tab): Likewise.
	* diagnostic.cc (diagnostic_context::initialize): Initialize
	m_source_printing.show_event_links_p.
	(simple_diagnostic_path::connect_to_next_event): New.
	(simple_diagnostic_event::simple_diagnostic_event): Initialize
	m_connected_to_next_event.
	* diagnostic.h (class diagnostic_source_effect_info): New forward
	decl.
	(diagnostic_source_printing_options::show_event_links_p): New
	field.
	(diagnostic_context::maybe_show_locus): Add optional "effect_info"
	param.
	(diagnostic_context::show_locus): Add "effect_info" param.
	(diagnostic_show_locus): Add optional "effect_info" param.
	* doc/invoke.texi: Add -fno-diagnostics-show-event-links.
	* lto-wrapper.cc (merge_and_complain): Add
	OPT_fdiagnostics_show_event_links to switch.
	(append_compiler_options): Likewise.
	(append_diag_options): Likewise.
	* opts-common.cc (decode_cmdline_options_to_array): Add
	"-fno-diagnostics-show-event-links" to -fdiagnostics-plain-output.
	* opts.cc (common_handle_option): Add case for
	OPT_fdiagnostics_show_event_links.
	* text-art/theme.cc (ascii_theme::get_cppchar): Handle
	cell_kind::CFG_*.
	(unicode_theme::get_cppchar): Likewise.
	* text-art/theme.h (theme::cell_kind): Add CFG_*.
	* toplev.cc (general_init): Initialize
	global_dc->m_source_printing.show_event_links_p.
	* tree-diagnostic-path.cc: Define INCLUDE_ALGORITHM,
	INCLUDE_MEMORY, and INCLUDE_STRING.  Include
	"diagnostic-label-effects.h".
	(path_label::path_label): Initialize m_effects.
	(path_label::get_effects): New.
	(class path_label::path_label_effects): New.
	(path_label::m_effects): New field.
	(class per_thread_summary): Add "friend struct event_range;".
	(per_thread_summary::per_thread_summary): Initialize m_last_event.
	(per_thread_summary::m_last_event): New field.
	(struct event_range::per_source_line_info): New.
	(event_range::event_range): Make "t" non-const.  Add
	"show_event_links" param and use it to initialize
	m_show_event_links.  Add info for initial event.
	(event_range::get_per_source_line_info): New.
	(event_range::maybe_add_event): Verify compatibility of the new
	label and existing labels with respect to the link-printing code.
	Update per-source-line info when an event is added.
	(event_range::print): Add"effect_info" param and pass to
	diagnostic_show_locus.
	(event_range::m_per_thread_summary): Make non-const.
	(event_range::m_source_line_info_map): New field.
	(event_range::m_show_event_links): New field.
	(path_summary::path_summary): Add "show_event_links" optional
	param, passing it to event_range ctor calls. Update
	pts.m_last_event.
	(thread_event_printer::print_swimlane_for_event_range): Add
	"effect_info" param and pass it to range->print.
	(print_path_summary_as_text): Keep track of the column for any
	out-edges at the end of printing each event_range and use as
	the leading in-edge for the next event_range.
	(default_tree_diagnostic_path_printer): Pass in show_event_links_p
	to path_summary ctor.
	(selftest::path_events_have_column_data_p): New.
	(class selftest::control_flow_test): New.
	(selftest::test_control_flow_1): New.
	(selftest::test_control_flow_2): New.
	(selftest::test_control_flow_3): New.
	(selftest::assert_cfg_edge_path_streq): New.
	(ASSERT_CFG_EDGE_PATH_STREQ): New macro.
	(selftest::test_control_flow_4): New.
	(selftest::test_control_flow_5): New.
	(selftest::test_control_flow_6): New.
	(selftest::control_flow_tests): New.
	(selftest::tree_diagnostic_path_cc_tests): Disable colorization on
	global_dc's printer.  Convert event_pp to a std::unique_ptr. Call
	control_flow_tests via for_each_line_table_case.
	(gen_command_line_string): Likewise.

gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/event-links-ascii.c: New test.
	* gcc.dg/analyzer/event-links-color.c: New test.
	* gcc.dg/analyzer/event-links-disabled.c: New test.
	* gcc.dg/analyzer/event-links-unicode.c: New test.

libcpp/ChangeLog:
	* include/rich-location.h (class label_effects): New forward decl.
	(range_label::get_effects): New vfunc.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-17 14:51:47 -04:00
Levy Hsu 6daed96154 MAINTAINERS: Add myself to write after approval
ChangeLog:

	* MAINTAINERS: Add myself.
2024-05-18 02:23:52 +08:00
Uros Bizjak b59de41132 i386: Rename sat_plusminus expanders to standard names [PR112600]
Rename <sse2_avx2>_<insn><mode>3<mask_name> expander to a standard ssadd,
usadd, sssub and ussub name to enable corresponding optab expansion.

Also add named expander for MMX modes.

	PR middle-end/112600

gcc/ChangeLog:

	* config/i386/mmx.md (<insn><mode>3): New expander.
	* config/i386/sse.md
	(<sse2_avx2>_<sat_plusminus:insn><mode>3<mask_name>):
	Rename expander to <sat_plusminus:insn><mode>3<mask_name>.
	(<umaxmin:code><mode>3): Update for rename.
	* config/i386/i386-builtin.def: Update for rename.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr112600-1a.c: New test.
	* gcc.target/i386/pr112600-1b.c: New test.
2024-05-17 16:54:57 +02:00
Paul Thomas 5f5074fe7a Fortran: Fix select type regression due to r14-9489 [PR114874]
2024-05-17  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/114874
	* gfortran.h: Add 'assoc_name_inferred' to gfc_namespace.
	* match.cc (gfc_match_select_type): Set 'assoc_name_inferred'
	in select type namespace if the selector has inferred type.
	* primary.cc (gfc_match_varspec): If a select type temporary
	is apparently scalar and a left parenthesis has been detected,
	check the current namespace has 'assoc_name_inferred' set. If
	so, set inferred_type.
	* resolve.cc (resolve_variable): If the namespace of a select
	type temporary is marked with 'assoc_name_inferred' call
	gfc_fixup_inferred_type_refs to ensure references are OK.
	(gfc_fixup_inferred_type_refs): Catch invalid array refs..

gcc/testsuite/
	PR fortran/114874
	* gfortran.dg/pr114874_1.f90: New test for valid code.
	* gfortran.dg/pr114874_2.f90: New test for invalid code.
2024-05-17 15:19:26 +01:00
Aldy Hernandez 1accf4454a [prange] Drop range to VARYING if the bitmask intersection made it so [PR115131]
If the intersection of the bitmasks made the range span the entire
domain, normalize the range to VARYING.

gcc/ChangeLog:

	PR middle-end/115131
	* value-range.cc (prange::intersect): Set VARYING if intersection
	of bitmasks made the range span the entire domain.
	(range_tests_misc): New test.
2024-05-17 16:03:17 +02:00
Björn Schäpers d4635b504c
libstdc++: detect DLLs on windows with <stacktrace>
libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_BACKTACE): Add check for
	tlhelp32.h, matching libbacktrace.
	* config.h.in: Regenerate.
	* configure: Regenerate.

Signed-off-by: Björn Schäpers <bjoern@hazardy.de>
2024-05-17 14:45:19 +01:00
Patrick Palka 5aaf47cb19 c++: aggregate CTAD w/ paren init and bases [PR115114]
During aggregate CTAD with paren init, we're accidentally overlooking
base classes since TYPE_FIELDS of a template type doesn't contain
corresponding base fields.  So we need to consider them separately.

	PR c++/115114

gcc/cp/ChangeLog:

	* pt.cc (maybe_aggr_guide): Consider bases in the paren init case.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/class-deduction-aggr15.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2024-05-17 09:02:52 -04:00
Jonathan Wakely c9e05b03c1
libstdc++: Fix typo in _Grapheme_cluster_view::_Iterator [PR115119]
libstdc++-v3/ChangeLog:

	PR libstdc++/115119
	* include/bits/unicode.h (_Iterator::operator++(int)): Fix typo
	in increment expression.
	* testsuite/ext/unicode/grapheme_view.cc: Check post-increment
	on view's iterator.
2024-05-17 13:46:48 +01:00
Alexander Monakov 4b9e68a6f3 tree-into-ssa: speed up sorting in prune_unused_phi_nodes [PR114480]
In PR 114480 we are hitting a case where tree-into-ssa scales
quadratically due to prune_unused_phi_nodes doing O(N log N)
work for N basic blocks, for each variable individually.
Sorting the 'defs' array is especially costly.

It is possible to assist gcc_qsort by laying out dfs_out entries
in the reverse order in the 'defs' array, starting from its tail.
This is not always a win (in fact it flips most of 7-element qsorts
in this testcase from 9 comparisons (best case) to 15 (worst case)),
but overall it helps on the testcase and on libstdc++ build.
On the testcase we go from 1.28e9 comparator invocations to 1.05e9,
on libstdc++ from 2.91e6 to 2.84e6.

gcc/ChangeLog:

	PR c++/114480
	* tree-into-ssa.cc (prune_unused_phi_nodes): Add dfs_out entries
	to the 'defs' array in the reverse order.
2024-05-17 15:28:45 +03:00
Aldy Hernandez bc6e336cb7 [prange] Avoid looking at type() for undefined ranges
Undefined ranges have no type.  This patch fixes the thinko.

gcc/ChangeLog:

	PR middle-end/115128
	* ipa-cp.cc (ipa_value_range_from_jfunc): Check for undefined_p
	before looking at type.
	(propagate_vr_across_jump_function): Same.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr115128.c: New test.
2024-05-17 13:12:47 +02:00
Richard Biener a5b3721c06 middle-end/115110 - Fix view_converted_memref_p
view_converted_memref_p was checking the reference type against the
pointer type of the offset operand rather than its pointed-to type
which leads to all refs being subject to view-convert treatment
in get_alias_set causing numerous testsuite fails but with its
new uses from r15-512-g9b7cad5884f21c is also a wrong-code issue.

	PR middle-end/115110
	* tree-ssa-alias.cc (view_converted_memref_p): Fix.
2024-05-17 12:03:58 +02:00
Eric Botcazou 6a0a46c579 Small fix to implementation of -fdump-ada-spec
gcc/c-family/
	* c-ada-spec.cc (bitfield_used): Move around.
	(packed_layout): Likewise.
	(dump_ada_array_type): Do not put "aliased" for a packed layout.
2024-05-17 11:45:40 +02:00
Eric Botcazou 4da8be4f46 Remove spurious line 2024-05-17 11:45:40 +02:00
Eric Botcazou f53f8a8596 Add widening expansion of MULT_HIGHPART_EXPR for integral modes
For integral modes the expansion of MULT_HIGHPART_EXPR requires the presence
of an {s,u}mul_highpart optab whereas, for vector modes, widening expansion
is supported.  This adds a widening expansion for integral modes too, which
is in fact already implemented in expmed_mult_highpart_optab.

gcc/
	* expmed.h (expmed_mult_highpart_optab): Declare.
	* expmed.cc (expmed_mult_highpart_optab): Remove static keyword.
	Do not assume that OP1 is a constant integer.  Fix pasto.
	(expmed_mult_highpart): Pass OP1 narrowed to MODE in all the calls
	to expmed_mult_highpart_optab.
	* optabs-query.cc (can_mult_highpart_p): Use 2 for integer widening
	and shift subsequent values accordingly.
	* optabs.cc (expand_mult_highpart): Call expmed_mult_highpart_optab
	when can_mult_highpart_p returns 2 and adjust to above change.
2024-05-17 11:45:40 +02:00
Richard Biener b420e0b920 Add missing check for const_pool in the escaped solutions
The ptr-vs-ptr compare folding using points-to info was missing a
check for const_pool being included in the escaped solution.  The
following fixes that, fixing the observed execute FAIL of
experimental/functional/searchers.cc

	* tree-ssa-alias.h (pt_solution_includes_const_pool): Declare.
	* tree-ssa-alias.cc (ptrs_compare_unequal): Use
	pt_solution_includes_const_pool.
	* tree-ssa-structalias.cc (pt_solution_includes_const_pool): New.

	* gcc.dg/torture/20240517-1.c: New testcase.
2024-05-17 10:54:11 +02:00
Viljar Indus 9bd0b709dd ada: Improve deriving initial sizes for container aggregates
Deriving the initial size of container aggregates is necessary
for deriving the correct capacity for bounded containers.

Add support for deriving the correct initial size
when the container aggregate is iterating over an array
object.

gcc/ada/

	* exp_aggr.adb (Expand_Container_Aggregate):
	Derive the size for iterable aggregates in the case of
	one-dimensional array objects.
2024-05-17 10:21:07 +02:00
Ronan Desplanques 167462f197 ada: Remove outdated workaround in aggregate expansion
Before this patch, the compiler refrained from rewriting aggregates
into purely positional form in some cases of one-component aggregates.
As explained in comments, this was because the back end could not
handle positional aggregates in those situations.

As the back end seems to have grown more capable, this patch removes
the workaround. It also extends the comments describing a warning that
is emitted in the same configuration with aggregates.

gcc/ada/

	* exp_aggr.adb (Aggr_Size_OK): Remove workaround and extend
	comment.
2024-05-17 10:21:07 +02:00
Eric Botcazou fc477a3f36 ada: Start the initialization of the tasking runtime earlier
This installs the tasking versions of the RTS_Lock manipulation routines
very early, before the elaboration of all the Ada units of the program,
including those of the runtime, because this elaboration may require the
initialization of RTS_Lock objects.

gcc/ada/

	* bindgen.adb (Gen_Adainit): Generate declaration and call to the
	imported procedure __gnat_tasking_runtime_initialize if need be.
	* libgnat/s-soflin.ads (Locking Soft-Links): Add commentary.
	* libgnarl/s-tasini.adb (Tasking_Runtime_Initialize): New procedure
	exported as __gnat_tasking_runtime_initialize.  Initialize RTS_Lock
	manipulation routines here instead of...
	(Init_RTS): ...here.
2024-05-17 10:21:07 +02:00
Steve Baird 15b5a95d36 ada: Improve test for unprocessed preprocessor directives
Preprocessor directives are case insensitive and may have spaces or tabs
between the '#' and the keyword. When checking for the error case of
unprocessed preprocessor directives, take these rules into account.

gcc/ada/

	* scng.adb (scan): When checking for an unprocessed preprocessor
	directive, take into account the preprocessor's rules about case
	insensitivity and about white space between the '#' and the
	keyword.
2024-05-17 10:21:06 +02:00
Eric Botcazou 22928da141 ada: Restore dependency on System.OS_Interface in System.Task_Primitives
The dependency is relied upon by the binder to drag the tasking runtime.

gcc/ada/

	* libgnarl/s-taspri__mingw.ads: Add clause for System.OS_Interface.
	(Private_Data): Change type of Thread component.
2024-05-17 10:21:06 +02:00
Eric Botcazou 9ff83f013e ada: Further adjustments coming from aliasing considerations
They are needed on 32-bit platforms because of different calling conventions
and again in the units implementing AltiVec and Streams support.

gcc/ada/

	* libgnat/g-alvevi.ads: Add pragma Universal_Aliasing for all the
	view types.
	* libgnat/s-stratt.ads: Likewise for Fat_Pointer type.
2024-05-17 10:21:06 +02:00
Eric Botcazou c8e5d90c4a ada: Replace spinlocks with fully-fledged locks in finalization collections
This replaces spinlocks with fully-fledged locks in finalization collections
because the former are deemed problematic with tasks that can be preempted.

Because of the requirement to avoid dragging the tasking runtime when it is
not necessary, the implementation goes through the usual soft links, with an
additional hurdle that space must be reserved for the lock in any case since
it is part of the ABI.  This entails the introduction of the System.OS_Locks
unit in the non-tasking runtime and the modification of the tasking runtime
to also use this unit.

This in turn requires a small adjustment: because of the presence of pre-
and post-conditions in Interfaces.C and of the limitations of the RTSfind
mechanism, the System.Finalization_Primitives unit must be preloaded, as
what is done for the Ada.Strings.Text_Buffers unit.

This effectively reverts the implementation to using the global task lock on
bare board platforms.

gcc/ada/

	* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-oslock$(objext).
	(LIBGNAT_TARGET_PAIRS): Use s-oslock__dummy.ads by default.
	Set specific s-oslock.ads source file for all the platforms.
	* exp_ch7.ads (Preload_Finalization_Collection): New procedure.
	* exp_ch7.adb (Allows_Finalization_Collection): Return False if
	System.Finalization_Primitives has not been preloaded.
	(Preload_Finalization_Collection): New procedure.
	* opt.ads (Interface_Seen): New boolean variable.
	* s-oscons-tmplt.c: Use "N" string for pragma Style_Checks.
	* scng.adb (Scan): Set Interface_Seen upon seeing "interface".
	* sem_ch10.adb: Add clause for Exp_Ch7.
	(Analyze_Compilation_Unit): Call Preload_Finalization_Collection
	after the context of the unit is analyzed.
	* libgnarl/a-rttiev.adb: Add with clause for System.OS_Locks and
	alphabetize others.
	(Event_Queue_Lock): Adjust qualified name of subtype.
	* libgnarl/s-osinte__aix.ads: Add with clause for System.OS_Locks
	and change pthread_mutex_t into a local subtype.
	* libgnarl/s-osinte__android.ads: Likewise.
	* libgnarl/s-osinte__darwin.ads: Likewise.
	* libgnarl/s-osinte__dragonfly.ads: Likewise.
	* libgnarl/s-osinte__freebsd.ads: Likewise.
	* libgnarl/s-osinte__gnu.ads: Likewise.
	* libgnarl/s-osinte__hpux-dce.ads: Likewise.
	* libgnarl/s-osinte__hpux.ads: Add Likewise.
	* libgnarl/s-osinte__kfreebsd-gnu.ads: Likewise.
	* libgnarl/s-osinte__linux.ads: Likewise.
	* libgnarl/s-osinte__lynxos178e.ads: Likewise.
	* libgnarl/s-osinte__qnx.ads: Likewise.
	* libgnarl/s-osinte__rtems.ads: Likewise.
	* libgnarl/s-osinte__mingw.ads: Add with clause for System.OS_Locks
	and change CRITICAL_SECTION into a local subtype.  Add declarations
	for imported procedures dealing with CRITICAL_SECTION.
	* libgnarl/s-osinte__solaris.ads: Add with clause for System.OS_Locks
	and change mutex_t into a local subtype.
	* libgnarl/s-osinte__vxworks.ads: Add missing blank line.
	* libgnarl/s-taprop.ads: Alphabetize clauses and package renamings.
	Use qualified name for RTS_Lock throughout.
	* libgnarl/s-taprop__dummy.adb: Add use clause for System.OS_Locks
	and alphabetize others.
	* libgnarl/s-taprop__hpux-dce.adb: Likewise.
	* libgnarl/s-taprop__linux.adb: Likewise.
	* libgnarl/s-taprop__posix.adb: Likewise.
	* libgnarl/s-taprop__qnx.adb: Likewise.
	* libgnarl/s-taprop__rtems.adb: Likewise.
	* libgnarl/s-taprop__solaris.adb: Likewise.
	* libgnarl/s-taprop__vxworks.adb: Likewise.
	* libgnarl/s-taprop__mingw.adb: Likewise.  Remove declarations for
	imported procedures dealing with CRITICAL_SECTION.
	* libgnarl/s-tarest.adb: Add with clause for System.OS_Locks and
	alphabetize others.
	(Global_Task_Lock): Adjust qualified name of subtype.
	* libgnarl/s-tasini.adb: Add clause for System.OS_Locks.
	(Initialize_RTS_Lock): New procedure.
	(Finalize_RTS_Lock): Likewise.
	(Acquire_RTS_Lock): Likewise.
	(Release_RTS_Lock): Likewise.
	(Init_RTS): Add compile-time assertions for RTS_Lock types.
	Set the soft links for the RTS lock manipulation routines.
	* libgnarl/s-taspri__dummy.ads: Add with clause for System.OS_Locks.
	(RTS_Lock): Delete and adjust throughout accordingly.
	* libgnarl/s-taspri__hpux-dce.ads: Likewise.
	* libgnarl/s-taspri__lynxos.ads: Likewise.
	* libgnarl/s-taspri__mingw.ads: Likewise.
	* libgnarl/s-taspri__posix-noaltstack.ads: Likewise.
	* libgnarl/s-taspri__posix.ads: Likewise.
	* libgnarl/s-taspri__solaris.ads: Likewise.
	* libgnarl/s-taspri__vxworks.ads: Likewise.
	* libgnat/s-finpri.ads: Add clause for System.OS_Locks.
	(Finalization_Collection): Change type of Lock.
	* libgnat/s-finpri.adb (Initialize): Call Initialize_RTS_Lock.
	(Lock_Collection): Call Acquire_RTS_Lock.
	(Unlock_Collection): Call Release_RTS_Lock.
	* libgnat/s-oslock__dummy.ads: New file.
	* libgnat/s-oslock__hpux-dce.ads: Likewise.
	* libgnat/s-oslock__mingw.ads: Likewise.
	* libgnat/s-oslock__posix.ads: Likewise.
	* libgnat/s-oslock__solaris.ads: Likewise.
	* libgnat/s-oslock__vxworks.ads: Likewise.
	* libgnat/s-soflin.ads (Null_Set_Address): New null procedure.
	(Initialize_RTS_Lock): New soft link.
	(Finalize_RTS_Lock): Likewise.
	(Acquire_RTS_Lock): Likewise.
	(Release_RTS_Lock): Likewise.
	* exp_ch4.adb (Expand_N_Allocator): In the subtype indication case,
	call Apply_Predicate_Check on the resulting access value if need be.
2024-05-17 10:21:06 +02:00
Eric Botcazou d7dbf6c7ae ada: Document secondary usage of Materialize_Entity flag
The flag is also used by the semantic analyzer.

gcc/ada/

	* einfo.ads (Materialize_Entity): Document secondary usage.
2024-05-17 10:21:05 +02:00
Steve Baird 7b5b67dc19 ada: Bug in computing local restrictions inherited from enclosing scopes.
In the function Local_Restrict.Active_Restriction, we traverse enclosing
scopes looking for a relevant Local_Restrictions aspect specification.
Fix a bug in this traversal.

gcc/ada/

	* local_restrict.adb (Active_Restriction): When traversing scopes,
	do not skip over a subprogram body.
2024-05-17 10:21:05 +02:00
Eric Botcazou 3a5c4f9266 ada: Factor out duplicated code in bodies of System.Task_Primitives.Operations
The duplication is present in some POSIX-like implementations (POSIX
and RTEMS) while it has already been eliminated in others (Linux, QNX).  The
latter implementations are also slightly modified for consistency's sake.

No functional changes.

gcc/ada/

	* libgnarl/s-taprop__dummy.adb (Initialize_Lock): Fix formatting.
	* libgnarl/s-taprop__linux.adb (RTS_Lock_Ptr): Delete.
	(Init_Mutex): Rename into...
	(Initialize_Lock): ...this.
	(Initialize_Lock [Lock]): Call above procedure.
	(Initialize_Lock [RTS_Lock]): Likewise.
	(Initialize_TCB): Likewise.
	* libgnarl/s-taprop__posix.adb (Initialize_Lock): New procedure
	factored out from the other two homonyms.
	(Initialize_Lock [Lock]): Call above procedure.
	(Initialize_Lock [RTS_Lock]): Likewise.
	* libgnarl/s-taprop__qnx.adb (RTS_Lock_Ptr): Delete.
	(Init_Mutex): Rename into...
	(Initialize_Lock): ...this.
	(Initialize_Lock [Lock]): Call above procedure.
	(Initialize_Lock [RTS_Lock]): Likewise.
	(Initialize_TCB): Likewise.
	* libgnarl/s-taprop__rtems.adb (Initialize_Lock): New procedure
	factored out from the other two homonyms.
	(Initialize_Lock [Lock]): Call above procedure.
	(Initialize_Lock [RTS_Lock]): Likewise.
2024-05-17 10:21:05 +02:00
Piotr Trojanek 75de817d88 ada: Fix for validity checking and conditional evaluation of 'Old
Detection of expression that are "known on entry" (as defined in Ada
2022 RM 6.1.1(20/5)) was confused by validity checks when used from
within expansion of attribute 'Old.

gcc/ada/

	* sem_util.adb (Is_Known_On_Entry): Handle constants introduced
	by validity checks.
2024-05-17 10:21:04 +02:00
Steve Baird 615c29a8c5 ada: Do not query the modification time of a special file.
In Ada.Directories, the function Modification_Time raises Name_Error if it is
called for a special file. So don't do that in Start_Search_Internal.

gcc/ada/

	* libgnat/a-direct.adb (Start_Search_Internal): Do not call
	Modification_Time for a special file; declare a Calendar.Time
	constant No_Time and use that instead.
2024-05-17 10:21:04 +02:00
Steve Baird 591ddf34a1 ada: Disable Equivalent_Array_Aggregate optimization if predicates involved
In most paths, the function Build_Equivalent_Record_Aggregate was already
testing Has_Predicates for a given component type and conditionally returning
an Empty result. This is also needed in the case of a scalar component type.
Without it, we can build corrupt trees that fail use-before-definition
detection checks in gigi.

gcc/ada/

	* exp_ch3.adb (Build_Equivalent_Record_Aggregate): Add
	Has_Predicates test for a scalar component to match what is
	already done for other kinds of components.
2024-05-17 10:21:04 +02:00
Ronan Desplanques d87d0f3315 ada: Clarify code for aggregate warnings
This patch improves comments in code that emits warnings about
particular situations involving aggregates. It also removes a
conjunct in a condition that's useless because always true in the
context of the test.

gcc/ada/

	* sem_aggr.adb (Resolve_Array_Aggregate): Improve comments
	and condition.
2024-05-17 10:21:04 +02:00
Ronan Desplanques 34ac60eb88 ada: Fix others error message location
Before this patch, the compiler pointed at the wrong component
association when reporting an illegal occurrence of "others" in an
aggregate. This patch fixes this by keeping track of which choice
contains the occurrence of "others" when resolving array aggregates.

gcc/ada/

	* sem_aggr.adb (Resolve_Array_Aggregate): Fix location of error
	message.
2024-05-17 10:21:03 +02:00
Piotr Trojanek d77c12eb33 ada: Expose utility routine for processing of Depends contracts in SPARK
Routine Is_Unconstrained_Or_Tagged_Item is now used both in the GNAT
frontend (for checking legality of Depends clauses) and in the GNATprove
backend (for representing implicit inputs in flow graphs).

gcc/ada/

	* sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Move to
	Sem_Util, so it can be used from GNATprove.
	* sem_util.ads (Is_Unconstrained_Or_Tagged_Item): Move from
	Sem_Prag; spec.
	* sem_util.adb (Is_Unconstrained_Or_Tagged_Item): Move from
	Sem_Prag; body.
2024-05-17 10:21:03 +02:00
Eric Botcazou 485d595d22 ada: Couple of adjustments coming from aliasing considerations
The first adjustment is to the expansion of implementation types for array
types with peculiar index types, for which the aliased property set on the
component of the original type must be copied; the implicit base type also
needs to be properly marked if the implementation type is constrained.

The second adjustment is to selected types in the runtime, which need to
be marked with pragma Universal_Aliasing because of their special usage.

gcc/ada/

	* exp_pakd.adb (Create_Packed_Array_Impl_Type): For non-bit-packed
	array types, propagate the aliased property of the component.
	(Install_PAT): Set fields on the implicit base type of an array.
	* libgnat/a-stream.ads (private part): Add pragma Universal_Aliasing
	for Stream_Element.
	* libgnat/g-alleve.ads: Add pragma Universal_Aliasing for all the
	vector types.
	* libgnat/g-alleve__hard.ads: Likewise.
2024-05-17 10:21:03 +02:00
Bob Duff d2a118197c ada: gnatbind: subprogram spec no longer exists
If a subprogram spec S is present while compiling something that
says "with S;", but the spec is absent while compiling the body
of S, then gnatbind fails to detect the mismatch.  The spec and
body of S might have different parameter and result types.
This patch fixes gnatbind to detect this case and give an error.

gcc/ada/

	* bcheck.adb (Check_Consistency_Of_Sdep): Split out new procedure.
	Add check for special case of subprogram spec that no longer
	exists.
	(Check_Consistency): Call Check_Consistency_Of_Sdep, except when
	Reified_Child_Spec is True. No need for "goto Continue" or "exit
	Sdep_Loop".
	* ali.ads (Subunit_Name, Unit_Name): Change the type to
	Unit_Name_Type. Add a comment pointing to the ALI file
	documentation, because it's in a somewhat-surprising place.
	* ali.adb (Scan_ALI): Subunit_Name and Unit_Name are now
	Unit_Name_Type. Remove comment explaining why Name_Find is used;
	Name_Find is the usual case. Do not remove the "%s" or "%b" from
	the Unit_Name. We need to be able to distinguish specs and bodies.
	This is also necessary to obey the invariant of Unit_Name_Type.
	* binde.adb (Write_Closure): Subunit_Name is now Unit_Name_Type.
	* clean.adb (Clean_Executables): Likewise.
2024-05-17 10:21:02 +02:00
Ronan Desplanques a666066298 ada: Update docs for Resolve_Null_Array_Aggregate
The documentation comments for Sem_Aggr.Resolve_Null_Array_Aggregate
suggested that this subprogram created a subtype, which it didn't.
This patch replaces those comments with ones that better match the
behavior.

gcc/ada/

	* sem_aggr.adb (Resolve_Null_Array_Aggregate): Update
	documentation comments.
2024-05-17 10:21:02 +02:00
Steve Baird ecf17346ff ada: Fix containers' Reference_Preserving_Key functions' memory leaks
Fix memory leaks in containers' Reference_Preserving_Key functions

Make the same change in each of 3 Ada.Containers child units: Ordered_Sets,
Indefinite_Ordered_Sets, and Bounded_Ordered_Sets. The function
Reference_Preserving_Key evaluates an allocator of type Key_Access whose
storage was not being reclaimed. Update the Finalize procedure for
type Reference_Control_Type to free that storage. But this change introduces
a possible erroneous double-free situation if an object is copied (because
the original and the copy will each be finalized at some point). So also
introduce an Adjust procedure which allocates a copy of the allocated object.
Another possible solution to this problem (which is not being implemented
yet) is based on implementing AI22-0082. Also include a fix for a bug in
Sem_Util.Has_Some_Controlled_Component that was discovered while working
on this.

gcc/ada/

	* sem_util.adb (Has_Some_Controlled_Component): Fix a bug which
	causes (in some cases involving a Disable_Controlled aspect
	specification) Needs_Finalization to return different answers for
	one type depending on whether the function is called before or
	after the type is frozen.
	* libgnat/a-coorse.ads: Type Control_Reference_Type gets an Adjust
	procedure.
	* libgnat/a-cborse.ads: Likewise.
	* libgnat/a-ciorse.ads: Likewise
	* libgnat/a-coorse.adb:
	(Finalize): Reclaim allocated Key_Type object.
	(Adjust): New procedure; prevent sharing of non-null Key_Access
	values by allocating a copy.
	* libgnat/a-cborse.adb: Likewise.
	* libgnat/a-ciorse.adb: Likewise.
2024-05-17 10:21:02 +02:00
Bob Duff bf935572b0 ada: correction to gnatbind-related cleanups
Correction to previous change; Asserts had been moved to
before Buf was initialized.

gcc/ada/

	* uname.adb (Get_Unit_Name_String): Move Asserts after
	Buf is initialized.
2024-05-17 10:21:02 +02:00
Bob Duff a0c87f1bb7 ada: gnatbind-related cleanups
This patch cleans up some things noticed while working on gnatbind.
No change in behavior yet.

gcc/ada/

	* ali-util.adb (Read_Withed_ALIs): Minor reformatting.
	* bindo-units.adb (Corresponding_Body): Add assert.
	(Corresponding_Spec): Likewise.
	* uname.adb: Clean up assertions, use available functions.
	Get_Spec_Name/Get_Body_Name can assert that N obeys the
	conventions for Unit_Name_Type (end in "%s" or "%b").
2024-05-17 10:21:01 +02:00
Sebastian Poeplau 14aef595f0 ada: Make raise-gcc.c compatible with Clang
The Morello variant of Clang doesn't have
__builtin_code_address_from_pointer; work around it where necessary.

gcc/ada/

	* raise-gcc.c: Work around __builtin_code_address_from_pointer
	if it is unavailable.
2024-05-17 10:21:01 +02:00
Marc Poulhiès 93035031c5 ada: Fix crash caused by missing New_Copy_tree
Since a recent refactor ("Factor common processing in expansion of
aggregates") where Initialize_Array_Component and
Initialize_Record_Component are merged, the behavior has slightly
changed. In the case of the expansion of an aggregate initialization
where the number of 'others' components is <= 3, the initialization
expression is not duplicated anymore, causing some incorrect multiple
definition when said expression is later transformed with
Expressions_With_Action that declares an object. The simple fix is to
add the now missing New_Copy_Tree where the assignments are created.

gcc/ada/

	* exp_aggr.adb (Build_Array_Aggr_Code) <Gen_Loop>: Copy the
	initialization expression when unrolling the loop.
2024-05-17 10:21:01 +02:00