]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
8 months agoRISC-V: Tie MUL and DIV masks to the M extension
Dimitar Dimitrov [Thu, 7 Nov 2024 18:13:02 +0000 (20:13 +0200)] 
RISC-V: Tie MUL and DIV masks to the M extension

When configuring GCC for RV32EC with:
  ./configure                                     \
      --target=riscv32-none-elf                   \
      --with-multilib-generator="rv32ec-ilp32e--" \
      --with-abi=ilp32e                           \
      --with-arch=rv32ec

Then the build fails because division is erroneously left enabled:
   cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension
   -fself-test: 8412281 pass(es) in 0.647173 seconds

Fix by disabling MASK_DIV if multiplication is not available and -mdiv
option has not been explicitly passed.

Tested the above RV32EC-only toolchain using the GNU simulator:
                 === gcc Summary ===

 # of expected passes            211635
 # of unexpected failures        3004
 # of expected failures          1061
 # of unresolved testcases       5651
 # of unsupported tests          18958

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_override_options_internal):
Set division option's default to disabled if multiplication
is not available.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
8 months agotestsuite: robustify gcc.target/m68k/20100512-1.c
Andreas Schwab [Tue, 19 Nov 2024 16:35:14 +0000 (17:35 +0100)] 
testsuite: robustify gcc.target/m68k/20100512-1.c

This has been failing since r5-2883-g8cb65b3725f0c3 which caused the
memset to be optimized out.  Add an unoptimizable reference to the local
variable to keep it.

* gcc.target/m68k/20100512-1.c (doTest1, doTest2): Add asm that
references foo.

8 months agofortran: Inline MINLOC/MAXLOC with DIM and scalar MASK [PR90608]
Mikael Morin [Tue, 19 Nov 2024 16:31:25 +0000 (17:31 +0100)] 
fortran: Inline MINLOC/MAXLOC with DIM and scalar MASK [PR90608]

Enable the generation of inline code for MINLOC/MAXLOC when argument
ARRAY is of integral type and has rank > 1, DIM is a constant, and MASK is
scalar (only absent MASK or rank 1 ARRAY were inlined before).

Scalar masks are implemented with a wrapping condition around the code
one would generate if MASK wasn't present, so they are easy to support
once inline code without MASK is working.

With this change, there are both expressions evaluated inside the nested
loop (ARRAY, and in the future MASK if non-scalar) and expressions evaluated
outside of it (MASK if scalar).  For both one has to advance the
scalarization chain passed as argument SE to gfc_conv_intrinsic_minmaxloc as
they are evaluated, but for expressions evaluated from within the nested
loop one has to advance additionally the nested scalarization chain of the
reduction loop.  This is normally handled transparently through the
inheritance that is defined when initializing gfc_se structs, but there has
to be some variable to inherit from, and there is a single one, SE.  This
variable is kept as base for out of nested loop expressions only (i.e. for
scalar MASK), and this change introduces a new variable to hold the current
advance of the nested loop scalarization chain and serve as inheritance base
to evaluate nested loop expressions (just ARRAY for now, additionally
non-scalar MASK later).

PR fortran/90608

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_inline_intrinsic_function_p): Return TRUE
if MASK is scalar.
(walk_inline_intrinsic_minmaxloc): Append to the scalarization chain
a scalar element for MASK if it's present.
(gfc_conv_intrinsic_minmaxloc): Use a local gfc_se struct to serve
as base for all the expressions evaluated in the nested loop.  To
evaluate MASK when there is a nested loop, enable usage of the
scalarizer and set the original passed in SE argument as current
scalarization chain element to use.  And use the nested loop from
the scalarizer instead of the local loop in that case.

gcc/testsuite/ChangeLog:

* gfortran.dg/maxloc_bounds_8.f90: Accept the error message
generated by the scalarizer in case the MAXLOC intrinsic call is
implemented through inline code.
* gfortran.dg/minmaxloc_20.f90: New test.

8 months agolibstdc++: remove JSON comment.
Jason Merrill [Mon, 18 Nov 2024 13:32:28 +0000 (14:32 +0100)] 
libstdc++: remove JSON comment.

Standard JSON doesn't have comments, and it seems this file needs to be
conforming, not the common JSON-with-comments dialect.

libstdc++-v3/ChangeLog:

* src/c++23/libstdc++.modules.json.in: Remove C++ comment.

8 months agoc++: reduce redundant deprecated warnings
Jason Merrill [Mon, 18 Nov 2024 14:00:32 +0000 (15:00 +0100)] 
c++: reduce redundant deprecated warnings

If a template uses a deprecated function, we should warn there and not also
whenever the template is instantiated.  I implement this by suppressing
the warning at the location; then to make this also work with modules, I
need to make sure to set TREE_NO_WARNING so that the warning spec for this
location gets recorded.

And then I noticed that has_warning_spec was broken such that if it
returned true than get_nowarn_spec would always return null.

gcc/cp/ChangeLog:

* decl2.cc (cp_handle_deprecated_or_unavailable): Avoid redundant
warning.
* call.cc (build_over_call): Set TREE_NO_WARNING for calls
to deprecated functions.
* semantics.cc (finish_call_expr): Propagate TREE_NO_WARNING.

gcc/ChangeLog:

* warning-control.cc (has_warning_spec): Fix handling of
get_no_warning_bit.

gcc/testsuite/ChangeLog:

* g++.dg/warn/deprecated-21.C: New test.
* g++.dg/modules/warn-spec-2_a.C: New test.
* g++.dg/modules/warn-spec-2_b.C: New test.

8 months agoAVR: ad target/84211 - Fix a build failure on some hosts.
Georg-Johann Lay [Tue, 19 Nov 2024 13:53:10 +0000 (14:53 +0100)] 
AVR: ad target/84211 - Fix a build failure on some hosts.

This fixes a build failure on hosts where HARD_REG_SET is not a scalar.
The issue was introduced with the patch for PR84211 in r15-5415.
PR target/84211
gcc/
* config/avr/avr-passes.cc (memento_t::apply_insn1): Don't
use operator &= on memento_t.known but on memento_t itself.

8 months agoamdgcn: Fix build failure (PR117657)
Andrew Stubbs [Tue, 19 Nov 2024 12:01:22 +0000 (12:01 +0000)] 
amdgcn: Fix build failure (PR117657)

The last patch did the right thing to the wrong parameter, which caused a build
failure in Newlib.  This patch fixes it.

gcc/ChangeLog:

PR target/117657
* config/gcn/gcn-valu.md (mask_gather_load<mode><vnsi>): Fix bug in
maskload else patch.

8 months agoaarch64: Bypass hidden attribute warnings in MinGW
Evgeny Karpov [Fri, 1 Nov 2024 16:47:15 +0000 (17:47 +0100)] 
aarch64: Bypass hidden attribute warnings in MinGW

The patch bypasses hidden attribute warnings in MinGW until it is
implemented.

libgcc/ChangeLog:

* config.host: Update.
* config/aarch64/t-mingw: New.

8 months agoAdd LTO support
Evgeny Karpov [Thu, 11 Jul 2024 13:27:35 +0000 (15:27 +0200)] 
Add LTO support

The patch reuses the configuration for LTO from ix86 and adds the
aarch64 architecture to the list of supported COFF headers.

gcc/ChangeLog:

* config/aarch64/cygming.h (TARGET_ASM_LTO_START): New.
(TARGET_ASM_LTO_END): Likewise.
* config/i386/cygming.h (TARGET_ASM_LTO_START): Update.
(TARGET_ASM_LTO_END): Likewise.
* config/i386/i386-protos.h (i386_pe_asm_lto_start): Delete.
(i386_pe_asm_lto_end): Likewise.
* config/mingw/winnt.cc (i386_pe_asm_lto_start): Rename
into ...
(mingw_pe_asm_lto_start): ... this.
(i386_pe_asm_lto_end): Rename into ...
(mingw_pe_asm_lto_end): ... this.
* config/mingw/winnt.h (mingw_pe_asm_lto_start): New.
(mingw_pe_asm_lto_end): Likewise.

libiberty/ChangeLog:

* simple-object-coff.c: Add aarch64.

8 months agoaarch64: Extend the offset limit in "symbol + offset" from 1MB to 16MB
Evgeny Karpov [Thu, 12 Sep 2024 11:19:32 +0000 (13:19 +0200)] 
aarch64: Extend the offset limit in "symbol + offset" from 1MB to 16MB

This patch allows using an offset of up to 16MB in "symbol + offset",
instead of 1MB limit that was used previously.

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_load_symref_appropriately):
Update.

8 months agoaarch64: Multiple adjustments to support the SMALL code model correctly
Evgeny Karpov [Wed, 14 Aug 2024 14:43:41 +0000 (16:43 +0200)] 
aarch64: Multiple adjustments to support the SMALL code model correctly

LOCAL_LABEL_PREFIX has been changed to help the assembly
compiler recognize local labels. Emitting locals has been
replaced with the .lcomm directive to declare uninitialized
data without defining an exact section. Functions and objects
were missing declarations. Binutils was not able to distinguish
static from external, or an object from a function.
mingw_pe_declare_object_type has been added to have type
information for relocation on AArch64, which is not the case
for ix86.

This fix relies on changes in binutils.
aarch64: Relocation fixes and LTO
https://sourceware.org/pipermail/binutils/2024-August/136481.html

gcc/ChangeLog:

* config/aarch64/aarch64-coff.h (LOCAL_LABEL_PREFIX):
Use "." as the local label prefix.
(ASM_OUTPUT_ALIGNED_LOCAL): Remove.
(ASM_OUTPUT_LOCAL): New.
* config/aarch64/cygming.h (ASM_OUTPUT_EXTERNAL_LIBCALL):
Update.
(ASM_DECLARE_OBJECT_NAME): New.
(ASM_DECLARE_FUNCTION_NAME): New.
* config/i386/cygming.h (ASM_DECLARE_COLD_FUNCTION_NAME):
Update.
(ASM_OUTPUT_EXTERNAL_LIBCALL): Update.
* config/mingw/winnt.cc (mingw_pe_declare_function_type):
Rename into ...
(mingw_pe_declare_type): ... this.
(i386_pe_start_function): Update.
* config/mingw/winnt.h (mingw_pe_declare_function_type):
Rename into ...
(mingw_pe_declare_type): ... this.

8 months agoaarch64: Exclude symbols using GOT from code models
Evgeny Karpov [Thu, 8 Aug 2024 17:54:13 +0000 (19:54 +0200)] 
aarch64: Exclude symbols using GOT from code models

Symbols using GOT are not supported by the aarch64-w64-mingw32
target and should be excluded from the code models.

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_classify_symbol):
Disable GOT for PECOFF target.

8 months agoaarch64: Add minimal C++ support
Evgeny Karpov [Wed, 14 Aug 2024 06:34:30 +0000 (08:34 +0200)] 
aarch64: Add minimal C++ support

The patch resolves compilation issues for the C++ language. Previous
patch series contributed to C++ as well, however, C++ could not be
tested until we got a C++ compiler and could build at least a "Hello
World" C++ program, and in reality, more than that.

Another issue has been fixed in the libstdc++ patch.
https://gcc.gnu.org/pipermail/libstdc++/2024-September/059472.html

gcc/ChangeLog:

* config.gcc: Add missing dependencies.

8 months agoaarch64: Add debugging information
Evgeny Karpov [Fri, 7 Jun 2024 14:55:23 +0000 (16:55 +0200)] 
aarch64: Add debugging information

This patch enables DWARF and allows compilation with debugging
information by using "gcc -g". The unwind info is disabled for
the moment and will be revisited after SEH implementation for
the target.

gcc/ChangeLog:

* config/aarch64/aarch64.cc (TARGET_ASM_UNALIGNED_HI_OP):
Enable DWARF.
(TARGET_ASM_UNALIGNED_SI_OP): Likewise.
(TARGET_ASM_UNALIGNED_DI_OP): Likewise.
* config/aarch64/cygming.h (DWARF2_DEBUGGING_INFO): Likewise.
(PREFERRED_DEBUGGING_TYPE): Likewise.
(DWARF2_UNWIND_INFO): Likewise.
(ASM_OUTPUT_DWARF_OFFSET): Likewise.

8 months agoSupport weak references
Evgeny Karpov [Wed, 14 Aug 2024 15:56:38 +0000 (17:56 +0200)] 
Support weak references

The patch adds support for weak references. The original MinGW
implementation targets ix86, which handles weak symbols differently
compared to AArch64. In AArch64, the weak symbols are replaced by
other symbols which reference the original weak symbols, and the
compiler does not track the original symbol names.
This patch resolves this and declares the original symbols.

Here is an explanation of why this change is needed and what the
difference is between x86_64-w64-mingw32 and aarch64-w64-mingw32.

The way x86_64 calls a weak function:
call  weak_fn2

GCC emits the call and creates the required definitions at the end
of the assembly:

.weak weak_fn2
.def  weak_fn2;   .scl  2;    .type 32;   .endef

This is different from aarch64:

weak_fn2 will be legitimized and replaced by .refptr.weak_fn2,
and there will be no other references to weak_fn2 in the code.

adrp  x0, .refptr.weak_fn2
add   x0, x0, :lo12:.refptr.weak_fn2
ldr   x0, [x0]
blr   x0

GCC does not emit the required definitions at the end of the assembly,
and weak_fn2 is tracked only by the mingw stub sybmol.

Without the change, the stub definition will emit:

    .section      .rdata$.refptr.weak_fn2, "dr"
    .globl  .refptr.weak_fn2
    .linkonce     discard
.refptr.weak_fn2:
    .quad   weak_fn2

which is not enough. This fix will emit the required definitions:

    .weak   weak_fn2
    .def    weak_fn2;   .scl  2;    .type 32;   .endef
    .section      .rdata$.refptr.weak_fn2, "dr"
    .globl  .refptr.weak_fn2
    .linkonce     discard
.refptr.weak_fn2:
    .quad   weak_fn2

This is the first commit in the third patch series with SMALL code
model fixes, optimization fixes, LTO, and minimal C++ enablement.

Prepared, refactored and validated by
Radek Barton <radek.barton@microsoft.com> and
Evgeny Karpov <evgeny.karpov@microsoft.com>

Contributor: Zac Walker <zacwalker@microsoft.com>

gcc/ChangeLog:

* config/aarch64/cygming.h (SUB_TARGET_RECORD_STUB): Request
declaration for weak symbols.
(PE_COFF_LEGITIMIZE_EXTERN_DECL): Legitimize external
declaration for weak symbols.
* config/i386/cygming.h (SUB_TARGET_RECORD_STUB): Update
declarations in ix86 with the same functionality.
(PE_COFF_LEGITIMIZE_EXTERN_DECL): Likewise.
* config/mingw/winnt-dll.cc (legitimize_pe_coff_symbol):
Support declaration for weak symbols if requested.
* config/mingw/winnt.cc (struct stub_list): Likewise.
(mingw_pe_record_stub): Likewise.
(mingw_pe_file_end): Likewise.
* config/mingw/winnt.h (mingw_pe_record_stub): Likewise.

8 months agoada: Rename Within_Case_Or_If_Expression predicate
Eric Botcazou [Sun, 10 Nov 2024 09:46:54 +0000 (10:46 +0100)] 
ada: Rename Within_Case_Or_If_Expression predicate

The case and if expressions are exactly the conditional expressions.

gcc/ada/ChangeLog:

* exp_util.ads (Within_Case_Or_If_Expression): Rename into...
(Within_Conditional_Expression): ...this.
* exp_util.adb (Within_Case_Or_If_Expression): Rename into...
(Within_Conditional_Expression): ...this.
* checks.adb (Install_Null_Excluding_Check): Adjust for renaming.

8 months agoada: Small fix in expansion of array aggregates handled by the back end
Eric Botcazou [Mon, 11 Nov 2024 13:36:59 +0000 (14:36 +0100)] 
ada: Small fix in expansion of array aggregates handled by the back end

The (minimal) expansion is now done by Build_Array_Aggr_Code in all cases,
which means that it must prevent the aggregate from being re-analyzed as
the RHS of the assignment, which may trigger a bogus warning and lead to
another useless rewriting.

The change also inlines Build_Assignment_With_Temporary that is now called
only once by Build_Array_Aggr_Code for this processing.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Assignment_With_Temporary): Inline into...
(Build_Array_Aggr_Code): ...this.  Set the Analyzed flag on the
relocated aggregate if it is to be handled by the back-end.

8 months agoada: Cleanup in expansion of aggregates in object declarations with aspects
Eric Botcazou [Fri, 8 Nov 2024 19:50:52 +0000 (20:50 +0100)] 
ada: Cleanup in expansion of aggregates in object declarations with aspects

The strategy to expand aggregates present as initialization expressions in
object declarations, originally with a subsequent address clause given for
the object and later with aspects whose resolution needs to be delayed up
to the freeze point, has been to block their resolution, so as to block
their expansion, during the processing of the declarations, lest they be
nonstatic and expanded in place and therefore generate assignments to the
object before its freeze point, which is forbidden.  Instead a temporary
is created at the declaration point and the aggregates are assigned to it,
and finally the temporary is copied into the object at the freeze point.

Of course this general strategy cannot be applied to limited types because
the copy operation is forbidden for them, so instead aggregates of limited
types are resolved but have their expansion delayed, before being eventually
expanded through Convert_Aggr_In_Object_Decl, which uses the mechanism based
on Initialization_Statements to insert them at the freeze point.

After the series of cleanups, all the aggregates that are initialization
expressions in object declarations and get expanded in place, go through the
Convert_Aggr_In_Object_Decl mechanism, exactly like those of limited type
with address clause/aspects have done historically.  This means that we no
longer need to block the resolution of those of nonlimited type with address
clause/aspects.

gcc/ada/ChangeLog:

* exp_ch3.adb: Remove clauses for Expander.
(Expand_N_Object_Declaration): Remove special processing for delayed
aggregates of limited types as initialization expressions.
* freeze.adb (Warn_Overlay): Bail out if No_Initialization is set on
the declaration node of the entity.
* sem_ch3.adb (Delayed_Aspect_Present): Delete.
(Expand_N_Object_Declaration): Do not block the resolution of the
initialization expression that is an aggregate when the object has
an address clause or delayed aspects.

8 months agofortran: Inline unmasked integral MINLOC/MAXLOC with DIM [PR90608]
Mikael Morin [Fri, 17 Nov 2023 18:04:19 +0000 (19:04 +0100)] 
fortran: Inline unmasked integral MINLOC/MAXLOC with DIM [PR90608]

Enable generation of inline code for the MINLOC and MAXLOC intrinsics,
if the ARRAY argument is of integral type and of rank > 1 (only the rank 1
case was previously inlined), the DIM argument is a constant value and there
is no MASK argument.

The restriction to integral ARRAY and absent MASK limits the scope of
the change to the cases where we generate single loop inline code.

This change uses the existing scalarizer suport for reductions, that is
arrays used in scalarization loops, where each element uses a nested
scalarization loop to calculate its value.  The nested loop (and
respectively the nested scalarization chain) is created while walking the
MINLOC/MAXLOC expression, it's set up automatically at the time the outer
loop is set up, and gfc_conv_intrinsic_minmaxloc is changed to use it as a
replacement for the local loop variable (respectively ARRAY scalarization
chain) used in the non-reduction case (i.e. when DIM is absent).

PR fortran/90608

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_inline_intrinsic_function_p): Return true
if DIM is constant, ARRAY is integral and MASK is absent.
(walk_inline_intrinsic_minmaxloc): If DIM is present, walk ARRAY and
move the dimension corresponding to DIM to a nested chain, keeping
the rest of the dimensions as the returned scalarization chain.
(gfc_conv_intrinsic_minmaxloc): When inside the scalarization loops,
proceed with inline code generation If DIM is present.  If DIM is
present, skip result array creation and final initialization from
individual result local variables.  If DIM is present and ARRAY has
rank greater than 1, use the nested loop initialized by the
scalarizer instead of the local one, use 1 as scalarization
dimension, and evaluate ARRAY using the inherited scalarization
chain instead of creating a local one by walking the expression.

gcc/testsuite/ChangeLog:

* gfortran.dg/maxloc_bounds_1.f90: Also accept the error message
generated by the scalarizer in case the function call is implemented
through inline code.
* gfortran.dg/maxloc_bounds_2.f90: Likewise.
* gfortran.dg/maxloc_bounds_3.f90: Likewise.
* gfortran.dg/minmaxloc_19.f90: New test.

8 months agofortran: Add tests covering inline MINLOC/MAXLOC with DIM [PR90608]
Mikael Morin [Thu, 16 Nov 2023 09:00:26 +0000 (10:00 +0100)] 
fortran: Add tests covering inline MINLOC/MAXLOC with DIM [PR90608]

Add the tests covering the cases for which the following patches will
implement inline expansion of MINLOC and MAXLOC.  Those are cases where the
DIM argument is a constant value, and the ARRAY argument has rank greater
than 1.

PR fortran/90608

gcc/testsuite/ChangeLog:

* gfortran.dg/ieee/maxloc_nan_2.f90: New test.
* gfortran.dg/ieee/minloc_nan_2.f90: New test.
* gfortran.dg/maxloc_with_dim_1.f90: New test.
* gfortran.dg/maxloc_with_dim_and_mask_1.f90: New test.
* gfortran.dg/minloc_with_dim_1.f90: New test.
* gfortran.dg/minloc_with_dim_and_mask_1.f90: New test.

8 months agoRemove Debian from SECURITY.txt
Florian Weimer [Tue, 19 Nov 2024 11:26:22 +0000 (12:26 +0100)] 
Remove Debian from SECURITY.txt

As requested by the Debian security team.

* SECURITY.txt: Remove Debian.

8 months agoRISC-V: Load VLS perm indices directly from memory.
Robin Dapp [Thu, 26 Sep 2024 09:56:08 +0000 (11:56 +0200)] 
RISC-V: Load VLS perm indices directly from memory.

Instead of loading the permutation indices and using vmslt in order to
determine which elements belong to which source vector we can compute
the proper mask at compile time.  That way we can emit vlm instead of
vle + vmslt.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (shuffle_merge_patterns): Load VLS
indices directly.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls/merge-1.c: Check for vlm and
no vmsleu etc.
* gcc.target/riscv/rvv/autovec/vls/merge-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/merge-3.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/merge-4.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/merge-5.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/merge-6.c: Ditto.

8 months agoAvoid repeated calls to temporarily_undo_changes [PR117297]
Richard Sandiford [Tue, 19 Nov 2024 10:19:24 +0000 (10:19 +0000)] 
Avoid repeated calls to temporarily_undo_changes [PR117297]

In an attempt to reduce compile time, rtl-ssa computes the cost
of existing instructions lazily rather than eagerly.  However,
this means that it might need to calculate the cost of an existing
instruction while a change group is already in progress for the
instruction.  rtl_ssa::insn_info::calculate_cost therefore temporarily
undoes any in-progress changes in order to get back the original pattern
and insn code.

rtl-ssa's main use of insn costs is in rtl_ssa::changes_are_worthwhile,
which calculates the cost of a change involving an arbitrary number
of instructions.  Summing up the original cost of N instructions
while those N instructions have in-progress changes could lead to
O(N*N) rtl changes, since each lazy calculation might have to
temporarily undo the changes to all N instructions.

We can avoid that by converting the current temporarily_undo_changes/
redo_changes pair into an RAII class and extending it to allow
nested uses.  rtl_ssa::changes_are_worthwhile can then undo the
in-progress changes once, before computing the original cost of all
the instructions.

gcc/
PR rtl-optimization/117297
* recog.h (temporarily_undo_changes, redo_changes): Delete in
favor of...
(undo_recog_changes): ...this new RAII class.
* fwprop.cc (should_replace_address): Update accordingly.
(fwprop_propagation::check_mem): Likewise.
(try_fwprop_subst_note): Likewise.
(try_fwprop_subst_pattern): Likewise.
* rtl-ssa/insns.cc (insn_info::calculate_cost): Likewise.
* rtl-ssa/changes.cc (rtl_ssa::changes_are_worthwhile): Temporarily
undo all in-progress changes while computing the cost of the original
sequence.
* recog.cc (temporarily_undone_changes): Replace with...
(undo_recog_changes::s_num_changes): ...this static member variable.
(validate_change_1): Update check accordingly.
(confirm_change_group): Likewise.
(num_validated_changes): Likewise.
(temporarily_undo_changes): Replace with...
(undo_recog_changes::undo_recog_changes): ...this constructor.
(redo_changes): Replace with...
(undo_recog_changes::~undo_recog_changes): ...this destructor.

8 months agoexpand: Fix up ICE on VCE from _Complex types to _BitInt [PR117458]
Jakub Jelinek [Tue, 19 Nov 2024 09:26:44 +0000 (10:26 +0100)] 
expand: Fix up ICE on VCE from _Complex types to _BitInt [PR117458]

extract_bit_field can't handle extraction of non-mode precision
from complex mode operands which don't live in memory, e.g. gen_lowpart
crashes on those.
The following patch in that case defers the extract_bit_field call
until op0 is forced into memory.

2024-11-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/117458
* expr.cc (expand_expr_real_1) <case VIEW_CONVERT_EXPR>: Don't
call extract_bit_field if op0 has complex mode and isn't a MEM,
instead first force op0 into memory and then call extract_bit_field.

* gcc.dg/bitint-116.c: New test.

8 months agobitintlower: Handle PAREN_EXPR [PR117459]
Jakub Jelinek [Tue, 19 Nov 2024 09:25:57 +0000 (10:25 +0100)] 
bitintlower: Handle PAREN_EXPR [PR117459]

The following patch handles PAREN_EXPR in bitint lowering, and handles it
as an optimization barrier, so that temporary arithmetics from PAREN_EXPR
isn't mixed with temporary arithmetics from outside of the PAREN_EXPR.

2024-11-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/117459
* gimple-lower-bitint.cc (bitint_large_huge::handle_stmt,
bitint_large_huge::lower_stmt): Handle PAREN_EXPR.

* gcc.dg/torture/bitint-74.c: New test.

8 months agobitintlower: Handle EXACT_DIV_EXPR like TRUNC_DIV_EXPR in bitint lowering [PR117571]
Jakub Jelinek [Tue, 19 Nov 2024 09:25:04 +0000 (10:25 +0100)] 
bitintlower: Handle EXACT_DIV_EXPR like TRUNC_DIV_EXPR in bitint lowering [PR117571]

r15-4601 added match.pd simplification of some TRUNC_DIV_EXPR expressions
into EXACT_DIV_EXPR, so bitintlower can now encounter even those.
From bitint lowering POV the fact that the division will be exact
doesn't matter, we still need to call at runtime the __divmodbitint4
API and it wouldn't simplify there anything to know it is exact if
we duplicated that, so the following patch lowers EXACT_DIV_EXPR exactly
as TRUNC_DIV_EXPR.

I think we don't need to backport this unless something introduces
EXACT_DIV_EXPR on BITINT_TYPEd expressions on the 14 branch as well.

2024-11-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/117571
* gimple-lower-bitint.cc (bitint_large_huge::lower_muldiv_stmt,
bitint_large_huge::lower_stmt, stmt_needs_operand_addr,
build_bitint_stmt_ssa_conflicts, gimple_lower_bitint): Handle
EXACT_DIV_EXPR like TRUNC_DIV_EXPR.

* gcc.dg/bitint-114.c: New test.

8 months agotestsuite: m68k: Fix tests for C23
Andreas Schwab [Tue, 19 Nov 2024 08:47:54 +0000 (09:47 +0100)] 
testsuite: m68k: Fix tests for C23

* gcc.target/m68k/crash1.c (seq_printf): Add prototype.
* gcc.target/m68k/pr63347.c (oof): Add missing parameter.

8 months ago[PATCH] testsuite: Require C99 for pow-to-ldexp.c
Soumya AR [Tue, 19 Nov 2024 08:53:47 +0000 (14:23 +0530)] 
[PATCH] testsuite: Require C99 for pow-to-ldexp.c

pow-to-ldexp.c checks for calls to __builtin_ldexpf and __builtin_ldexpl, which
will only be performed when the compiler knows the target has a C99 libm
available.

Modified the test to add a C99 runtime requirement.

This fixes the failure on arm-eabi targets for this test case.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pow-to-ldexp.c: Require c99_runtime.

8 months agoRegenerate config/avr/avr.opt.urls
David Malcolm [Tue, 19 Nov 2024 01:44:09 +0000 (20:44 -0500)] 
Regenerate config/avr/avr.opt.urls

gcc/ChangeLog:
* config/avr/avr.opt.urls: Regenerate for
r15-5415-gc3db52bb47913a.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoRISC-V: Remove unnecessary option for scalar SAT_TRUNC testcase
Pan Li [Sat, 16 Nov 2024 02:43:37 +0000 (10:43 +0800)] 
RISC-V: Remove unnecessary option for scalar SAT_TRUNC testcase

After we create a isolated folder to hold all SAT scalar test,
we have fully control of what optimization options passing to
the testcase.  Thus, it is better to remove the unnecessary
work around for flto option, as well as the -O3 option for
each cases.  The riscv.exp will pass sorts of different optimization
options for each case.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat/sat_u_trunc-1-u16.c: Remove flto
dg-skip workaround and -O3 option.
* gcc.target/riscv/sat/sat_u_trunc-1-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-1-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-1-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-2-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-3-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-4-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-5-u8.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u16.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u32.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u64.c: Ditto.
* gcc.target/riscv/sat/sat_u_trunc-6-u8.c: Ditto.
* gcc.target/riscv/sat/scalar_sat_unary.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
8 months agoRISC-V: Rearrange the test files for scalar SAT_TRUNC [NFC]
Pan Li [Sat, 16 Nov 2024 02:40:27 +0000 (10:40 +0800)] 
RISC-V: Rearrange the test files for scalar SAT_TRUNC [NFC]

The test files of scalar SAT_TRUNC only has numbers as the suffix.
Rearrange the file name to -{form number}-{target-type}.  For example,
test form 3 for uint32_t SAT_TRUNC will have -3-u32.c for asm check and
-run-3-u32.c for the run test.

Meanwhile, all related test files moved to riscv/sat/.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_u_trunc-2.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-1-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-3.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-1-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-4.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-1-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-1.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-1-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-6.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-2-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-7.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-2-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-8.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-2-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-5.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-2-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-10.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-3-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-11.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-3-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-12.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-3-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-9.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-3-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-14.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-4-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-15.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-4-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-16.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-4-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-13.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-4-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-18.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-5-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-19.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-5-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-20.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-5-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-17.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-5-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-22.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-6-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-23.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-6-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-24.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-6-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-21.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-6-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-2.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-1-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-3.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-1-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-4.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-1-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-1.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-1-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-6.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-2-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-7.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-2-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-8.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-2-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-5.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-2-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-10.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-3-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-11.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-3-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-12.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-3-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-9.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-3-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-14.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-4-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-15.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-4-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-16.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-4-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-13.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-4-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-18.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-5-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-19.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-5-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-20.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-5-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-17.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-5-u8.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-22.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-6-u16.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-23.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-6-u32.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-24.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-6-u64.c: ...here.
* gcc.target/riscv/sat_u_trunc-run-21.c: Move to...
* gcc.target/riscv/sat/sat_u_trunc-run-6-u8.c: ...here.

Signed-off-by: Pan Li <pan2.li@intel.com>
8 months agoFlatten anonymous structs in CodeView types
Mark Harmstone [Sun, 10 Nov 2024 00:23:49 +0000 (00:23 +0000)] 
Flatten anonymous structs in CodeView types

If a CodeView struct, class, or union has as a member an anonymous
struct, class, or union, this gets flattened. The sub-struct's members
will appear as if they were part of their parent.

For this, we move part of get_type_num_struct into a new function
add_to_fieldlist, which also handles creating an LF_INDEX overflow item
if an LF_FIELDLIST grows too large. This is because add_struct_member
now calls itself recursively, and so needs to handle overflows itself.

gcc/
* dwarf2codeview.cc (add_to_fieldlist): New function.
(add_struct_member): Call recursively to flatten structs, and call
add_to_fieldlist.
(add_struct_static_member): Call add_to_fieldlist.
(add_struct_function): Call add_to_fieldlist.
(add_struct_inheritance): Call add_to_fieldlist.
(add_struct_nested_type): Call add_to_fieldlist.
(get_type_num_struct): Move code to add_to_fieldlist, and move
responsibility for this to subfunctions.

8 months agoProduce CodeView info about nested types
Mark Harmstone [Tue, 19 Nov 2024 00:46:45 +0000 (00:46 +0000)] 
Produce CodeView info about nested types

If the DIE for a struct, class, or union contains a nested type, add a
LF_NESTTYPE entry to its field list recording this.

Plus if we use a nested type, make sure that its parent also gets
defined. This may entail adding a forward definition and creating a
deferred type, so we need to call flush_deferred_types in
codeview_debug_finish as well.

gcc/
* dwarf2codeview.cc (enum cv_leaf_type): Add LF_NESTTYPE.
(struct codeview_subtype): Add lf_nesttype to union.
(flush_deferred_types): Add declaration.
(write_lf_fieldlist): Handle LF_NESTTYPE.
(codeview_debug_finish): Call flush_deferred_types.
(add_struct_nested_type): New function.
(get_type_num_struct): Call add_struct_nested_type, and if nested make
that parent is added.

8 months agoDaily bump.
GCC Administrator [Tue, 19 Nov 2024 00:19:52 +0000 (00:19 +0000)] 
Daily bump.

8 months agoc: Allow bool and enum null pointer constants [PR112556]
Joseph Myers [Mon, 18 Nov 2024 22:24:48 +0000 (22:24 +0000)] 
c: Allow bool and enum null pointer constants [PR112556]

As reported in bug 112556, GCC wrongly rejects conversion of null
pointer constants with bool or enum type to pointers in
convert_for_assignment (assignment, initialization, argument passing,
return).  Fix the code there to allow BOOLEAN_TYPE and ENUMERAL_TYPE;
it already allowed INTEGER_TYPE and BITINT_TYPE.

This bug (together with -std=gnu23 meaning false has type bool rather
than int) has in turn resulted in people thinking they need to fix
code using false as a null pointer constant for C23 compatibility.
While such a usage is certainly questionable, it has nothing to do
with C23 compatibility and the right place for warnings about such
usage is -Wzero-as-null-pointer-constant.  I think it would be
appropriate to extend -Wzero-as-null-pointer-constant to cover
BOOLEAN_TYPE, ENUMERAL_TYPE and BITINT_TYPE (in all the various
contexts in which that option generates warnings), though this patch
doesn't do anything about that option.

Bootstrapped with no regressions for x86-64-pc-linux-gnu.

PR c/112556

gcc/c/
* c-typeck.cc (convert_for_assignment): Allow conversion of
ENUMERAL_TYPE and BOOLEAN_TYPE null pointer constants to pointers.

gcc/testsuite/
* gcc.dg/c11-null-pointer-constant-1.c,
gcc.dg/c23-null-pointer-constant-1.c: New tests.

8 months agolibdiagnostics: add a "sarif-replay" command-line tool [PR96032]
David Malcolm [Mon, 18 Nov 2024 22:08:37 +0000 (17:08 -0500)] 
libdiagnostics: add a "sarif-replay" command-line tool [PR96032]

This patch adds a new "sarif-replay" command-line tool for
viewing .sarif files.  It uses libdiagnostics to "replay"
any diagnostics found in the .sarif files in text form as if
they were GCC diagnostics.

contrib/ChangeLog:
PR other/96032
* regenerate-sarif-spec-index.py: New file.

gcc/ChangeLog:
PR other/96032
* Makefile.in (lang_checks): If libdiagnostics is enabled, add
check-sarif-replay.
(SARIF_REPLAY_OBJS): New.
(ALL_HOST_OBJS): If libdiagnostics is enabled, add
$(SARIF_REPLAY_OBJS).
(sarif-replay): New.
(install-libdiagnostics): Add sarif-replay to deps, and install
it.
* configure: Regenerate.
* configure.ac (check_languages): If libdiagnostics is enabled,
add check-sarif-replay.
(LIBDIAGNOSTICS): If libdiagnostics is enabled, add sarif-replay.
* doc/install.texi (--enable-libdiagnostics): Note that it also
enables sarif-replay.
* libsarifreplay.cc: New file.
* libsarifreplay.h: New file.
* sarif-replay.cc: New file.
* sarif-spec-urls.def: New file.

gcc/testsuite/ChangeLog:
PR other/96032
* lib/gcc-dg.exp (gcc-dg-test-1): Add "replay-sarif".
* lib/sarif-replay-dg.exp: New file.
* lib/sarif-replay.exp: New file.
* sarif-replay.dg/2.1.0-invalid/3.1-not-an-object.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.11.11-malformed-placeholder.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.11.11-missing-arguments-for-placeholders.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.11.11-not-enough-arguments-for-placeholders.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.13.2-no-version.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.13.2-version-not-a-string.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.13.4-bad-runs.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.13.4-no-runs.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.13.4-non-object-in-runs.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.27.10-bad-level.sarif: New test.
* sarif-replay.dg/2.1.0-unhandled/3.27.10-none-level.sarif: New test.
* sarif-replay.dg/2.1.0-valid/error-with-note.sarif: New test.
* sarif-replay.dg/2.1.0-valid/escaped-braces.sarif: New test.
* sarif-replay.dg/2.1.0-valid/null-runs.sarif: New test.
* sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-1.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-2.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-3.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-4.sarif: New test.
* sarif-replay.dg/2.1.0-valid/tutorial-example.sarif: New test.
* sarif-replay.dg/dg.exp: New script.
* sarif-replay.dg/malformed-json/array-missing-comma.sarif: New test.
* sarif-replay.dg/malformed-json/array-with-trailing-comma.sarif:
New test.
* sarif-replay.dg/malformed-json/bad-token.sarif: New test.
* sarif-replay.dg/malformed-json/object-missing-comma.sarif: New test.
* sarif-replay.dg/malformed-json/object-with-trailing-comma.sarif:
New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agojson: add json parsing support
David Malcolm [Mon, 18 Nov 2024 22:08:36 +0000 (17:08 -0500)] 
json: add json parsing support

This patch implements JSON parsing support.

It's based on the parsing parts of the patch I posted here:
https://gcc.gnu.org/legacy-ml/gcc-patches/2017-08/msg00417.html
with the parsing moved to a separate source file and header, heavily
rewritten to capture source location information for JSON values, and
to capture errors via a result template.

I also added optional support for C and C++ style comments, which is
extremely useful in DejaGnu tests.

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add json-parsing.o.
* json-parsing.cc: New file.
* json-parsing.h: New file.
* json.cc (selftest::assert_print_eq): Remove "static".
* json.h (json::array::begin): New.
(json::array::end): New.
(json::array::length): New.
(json::array::get): New.
(is_a_helper <json::value *>::test): New.
(is_a_helper <const json::value *>::test): New.
(is_a_helper <json::object *>::test): New.
(is_a_helper <const json::object *>::test): New.
(is_a_helper <json::array *>::test): New.
(is_a_helper <const json::array *>::test): New.
(is_a_helper <json::float_number *>::test): New.
(is_a_helper <const json::float_number *>::test): New.
(is_a_helper <json::integer_number *>::test): New.
(is_a_helper <const json::integer_number *>::test): New.
(is_a_helper <json::string *>::test): New.
(is_a_helper <const json::string *>::test): New.
(selftest::assert_print_eq): New decl.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::json_parser_cc_tests.
* selftest.h (selftest::json_parser_cc_tests): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoAdd libdiagnostics (v4)
David Malcolm [Mon, 18 Nov 2024 22:08:36 +0000 (17:08 -0500)] 
Add libdiagnostics (v4)

This patch adds a new libdiagnostics shared library available as
part of the GCC build via --enable-libdiagnostics when
configuring GCC.

It combines the following patches from:
  https://gcc.gnu.org/pipermail/gcc-patches/2024-November/668632.html
    [PATCH 1/8] libdiagnostics v4: header
    [PATCH 2/8] libdiagnostics v4: implementation
    [PATCH 3/8] libdiagnostics: add API docs
    [PATCH 4/8] libdiagnostics v4: add C++ wrapper API
    [PATCH 6/8] libdiagnostics v4: test suite

ChangeLog:
* configure.ac (--enable-libdiagnostics): New.
* configure: Regenerate.

gcc/ChangeLog:
* configure.ac (check_languages): Add check-libdiagnostics.
(--enable-libdiagnostics): New.
* configure: Regenerate.
* Makefile.in (enable_libdiagnostics): New.
(lang_checks): If libdiagnostics is enabled, add
check-libdiagnostics.
(ALL_HOST_OBJS): If libdiagnostics is enabled, add
$(libdiagnostics_OBJS).
(start.encap): Add LIBDIAGNOSTICS.
(libdiagnostics_OBJS): New.
(LIBDIAGNOSTICS_VERSION_NUM): New, adapted from code in
jit/Make-lang.in.
(LIBDIAGNOSTICS_MINOR_NUM): Likewise.
(LIBDIAGNOSTICS_RELEASE_NUM): Likewise.
(LIBDIAGNOSTICS_FILENAME): Likewise.
(LIBDIAGNOSTICS_IMPORT_LIB): Likewise.
(libdiagnostics): Likewise.
(LIBDIAGNOSTICS_AGE): Likewise.
(LIBDIAGNOSTICS_BASENAME): Likewise.
(LIBDIAGNOSTICS_SONAME): Likewise.
(LIBDIAGNOSTICS_LINKER_NAME): Likewise.
(LIBDIAGNOSTICS_COMMA): Likewise.
(LIBDIAGNOSTICS_VERSION_SCRIPT_OPTION): Likewise.
(LIBDIAGNOSTICS_SONAME_OPTION): Likewise.
(LIBDIAGNOSTICS_SONAME_SYMLINK): Likewise.
(LIBDIAGNOSTICS_LINKER_NAME_SYMLINK): Likewise.
(LIBDIAGNOSTICS_FILENAME): Likewise.
(libdiagnostics.serial): Likewise.
(LIBDIAGNOSTICS_EXTRA_OPTS): Likewise.
(install): If libdiagnostics is enabled, add
install-libdiagnostics.
(libdiagnostics.install-headers): New.
(libdiagnostics.install-common): New, adapted from code in
jit/Make-lang.in.
(install-libdiagnostics): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::get_location_text): Make public.
* doc/install.texi (--enable-libdiagnostics): New.
* doc/libdiagnostics/Makefile: New file.
* doc/libdiagnostics/conf.py: New file.
* doc/libdiagnostics/index.rst: New file.
* doc/libdiagnostics/make.bat: New file.
* doc/libdiagnostics/topics/diagnostic-manager.rst: New file.
* doc/libdiagnostics/topics/diagnostics.rst: New file.
* doc/libdiagnostics/topics/execution-paths.rst: New file.
* doc/libdiagnostics/topics/fix-it-hints.rst: New file.
* doc/libdiagnostics/topics/index.rst: New file.
* doc/libdiagnostics/topics/logical-locations.rst: New file.
* doc/libdiagnostics/topics/message-formatting.rst: New file.
* doc/libdiagnostics/topics/metadata.rst: New file.
* doc/libdiagnostics/topics/physical-locations.rst: New file.
* doc/libdiagnostics/topics/retrofitting.rst: New file.
* doc/libdiagnostics/topics/sarif.rst: New file.
* doc/libdiagnostics/topics/text-output.rst: New file.
* doc/libdiagnostics/topics/ux.rst: New file.
* doc/libdiagnostics/tutorial/01-hello-world.rst: New file.
* doc/libdiagnostics/tutorial/02-physical-locations.rst: New file.
* doc/libdiagnostics/tutorial/03-logical-locations.rst: New file.
* doc/libdiagnostics/tutorial/04-notes.rst: New file.
* doc/libdiagnostics/tutorial/05-warnings.rst: New file.
* doc/libdiagnostics/tutorial/06-fix-it-hints.rst: New file.
* doc/libdiagnostics/tutorial/07-execution-paths.rst: New file.
* doc/libdiagnostics/tutorial/index.rst: New file.
* libdiagnostics++.h: New file.
* libdiagnostics.cc: New file.
* libdiagnostics.h: New file.
* libdiagnostics.map: New file.

gcc/testsuite/ChangeLog:
* libdiagnostics.dg/libdiagnostics.exp: New, adapted from jit.exp.
* libdiagnostics.dg/sarif.py: New.
* libdiagnostics.dg/test-dump.c: New test.
* libdiagnostics.dg/test-error-c.py: New test.
* libdiagnostics.dg/test-error-with-note-c.py: New test.
* libdiagnostics.dg/test-error-with-note.c: New test.
* libdiagnostics.dg/test-error-with-note.cc: New test.
* libdiagnostics.dg/test-error.c: New test.
* libdiagnostics.dg/test-error.cc: New test.
* libdiagnostics.dg/test-example-1.c: New test.
* libdiagnostics.dg/test-fix-it-hint-c.py: New test.
* libdiagnostics.dg/test-fix-it-hint.c: New test.
* libdiagnostics.dg/test-fix-it-hint.cc: New test.
* libdiagnostics.dg/test-helpers++.h: New test.
* libdiagnostics.dg/test-helpers.h: New test.
* libdiagnostics.dg/test-labelled-ranges.c: New test.
* libdiagnostics.dg/test-labelled-ranges.cc: New test.
* libdiagnostics.dg/test-labelled-ranges.py: New test.
* libdiagnostics.dg/test-logical-location-c.py: New test.
* libdiagnostics.dg/test-logical-location.c: New test.
* libdiagnostics.dg/test-metadata-c.py: New test.
* libdiagnostics.dg/test-metadata.c: New test.
* libdiagnostics.dg/test-multiple-lines-c.py: New test.
* libdiagnostics.dg/test-multiple-lines.c: New test.
* libdiagnostics.dg/test-no-column-c.py: New test.
* libdiagnostics.dg/test-no-column.c: New test.
* libdiagnostics.dg/test-no-diagnostics-c.py: New test.
* libdiagnostics.dg/test-no-diagnostics.c: New test.
* libdiagnostics.dg/test-note-with-fix-it-hint-c.py: New test.
* libdiagnostics.dg/test-note-with-fix-it-hint.c: New test.
* libdiagnostics.dg/test-text-sink-options.c: New test.
* libdiagnostics.dg/test-warning-c.py: New test.
* libdiagnostics.dg/test-warning-with-path-c.py: New test.
* libdiagnostics.dg/test-warning-with-path.c: New test.
* libdiagnostics.dg/test-warning.c: New test.
* libdiagnostics.dg/test-write-sarif-to-file-c.py: New test.
* libdiagnostics.dg/test-write-sarif-to-file.c: New test.
* libdiagnostics.dg/test-write-text-to-file.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agotestsuite: move dg-test cleanup code from gcc-dg.exp to its own file
David Malcolm [Mon, 18 Nov 2024 21:49:04 +0000 (16:49 -0500)] 
testsuite: move dg-test cleanup code from gcc-dg.exp to its own file

I need to use this cleanup logic for the testsuite for libdiagnostics
where it's too awkward to directly use gcc-dg.exp itself.

No functional change intended.

gcc/testsuite/ChangeLog:
* lib/dg-test-cleanup.exp: New file, from material moved from
lib/gcc-dg.exp.
* lib/gcc-dg.exp: Add load_lib of dg-test-cleanup.exp.
(cleanup-after-saved-dg-test): Move to lib/dg-test-cleanup.exp.
(dg-test): Likewise for override.
(initialize_prune_notes): Likewise.

libatomic/ChangeLog:
* testsuite/lib/libatomic.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libgomp/ChangeLog:
* testsuite/lib/libgomp.exp: Add
"load_gcc_lib dg-test-cleanup.exp".
libitm/ChangeLog:
* testsuite/lib/libitm.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libphobos/ChangeLog:
* testsuite/lib/libphobos-dg.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libstdc++-v3/ChangeLog:
* testsuite/lib/libstdc++.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

libvtv/ChangeLog:
* testsuite/lib/libvtv.exp: Add
"load_gcc_lib dg-test-cleanup.exp".

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoi386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]
Uros Bizjak [Mon, 18 Nov 2024 21:38:46 +0000 (22:38 +0100)] 
i386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]

__builtin_ia32_rsqrtsf2 expander generates UNSPEC_RSQRT insn pattern
also when TARGET_SSE_MATH is not set.  Enable *rsqrtsf2_sse without
TARGET_SSE_MATH to avoid ICE with unrecognizable insn.

PR target/117357

gcc/ChangeLog:

* config/i386/i386.md (*rsqrtsf2_sse):
Also enable for !TARGET_SSE_MATH.

gcc/testsuite/ChangeLog:

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

8 months agoFix test failures for enum-alias-{1,2,3} on arm-eabi [PR117419]
Martin Uecker [Tue, 12 Nov 2024 17:08:17 +0000 (18:08 +0100)] 
Fix test failures for enum-alias-{1,2,3} on arm-eabi [PR117419]

The tests added for PR115157 fail on arm-eabi.  Add __INT_MAX__
to enum to make sure they have size int.

PR testsuite/117419

gcc/testsuite/ChangeLog:
* gcc.dg/enum-alias-1.c: Add __INT_MAX__.
* gcc.dg/enum-alias-2.c: Likewise.
* gcc.dg/enum-alias-3.c: Likewise.

Tested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
8 months agoAdd a timevar for late combine
Richard Sandiford [Mon, 18 Nov 2024 19:33:58 +0000 (19:33 +0000)] 
Add a timevar for late combine

When adding late-combine.cc, I forgot to add a timevar for it.

gcc/
* timevar.def (TV_LATE_COMBINE): New timevar.
* late-combine.cc (pass_data_late_combine): Use it.

8 months agoaarch64: Improve early-ra handling of reductions
Richard Sandiford [Mon, 18 Nov 2024 19:32:51 +0000 (19:32 +0000)] 
aarch64: Improve early-ra handling of reductions

At the moment, early-ra ducks out of allocating any region
that contains a register with both a strong FPR affinity and
a strong GPR affinity.  The proper allocators are much better
at handling that situation.

But this means that early-ra tends not to allocate a region
of vector code that ends in a reduction to a scalar integer
if any later arithmetic is done on the scalar integer result.

Currently, if a block acts as an isolated allocation region, the pass
will try to split the block into subregions *between* instructions if
there are no live FPRs or FPR allocnos.  In the reduction case described
above, it's convenient to try the same thing *within* instructions.
If a block of vector code ends in a reduction, all FPRs and FPR
allocnos will be dead between the "use phase" and the "def phase"
of the reduction: the vector input will then have died, but the
scalar result will not yet have been born.

If we split the block that way, the problematic reduction result
will be part of the second region, which we can skip allocating,
but the vector work will be part of a separate region, which we
might be able to allocate.

This avoids a MOV in the testcase and also helps a small amount
with x264.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::IGNORE_REG): New flag.
(early_ra::fpr_preference): Handle it.
(early_ra::record_constraints): Fail the allocation if an
IGNORE_REG output operand is not independent of the inputs.
(defines_multi_def_pseudo): New function.
(early_ra::could_split_region_here): New member function, split
out from...
(early_ra::process_block): ...here.  Try splitting a block into
multiple regions between the definition and use phases of an
instruction.  Set IGNORE_REG on the output registers if we do so.

gcc/testsuite/
* gcc.target/aarch64/early_ra_1.c: New test.

8 months agoaarch64: Extend early-ra splitting of single-block regions
Richard Sandiford [Mon, 18 Nov 2024 19:32:50 +0000 (19:32 +0000)] 
aarch64: Extend early-ra splitting of single-block regions

When early-ra treats a block as an isolated allocation region,
it opportunistically splits the block into smaller regions
at points where no FPRs or FPR allocnos are live.  Previously
it only did this if m_allocation_successful, since the contrary
included cases in which the live range information wasn't trustworthy.

After earlier patches, we should now be able to trust the live range
information whenever m_accurate_live_ranges is true.  This means that
we can split the block into regions even if allocation failed for the
current (sub)region.

This is just something I noticed by inspection.  I don't have
a particular test case for it.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::process_block): Check m_accurate_live_ranges
rather than m_allocation_successful when deciding whether
to split a block into multiple regions.  Skip over subregions
that we decide not to allocate.

8 months agoaarch64: Relax early_ra treatment of modes_tieable_p
Richard Sandiford [Mon, 18 Nov 2024 19:32:50 +0000 (19:32 +0000)] 
aarch64: Relax early_ra treatment of modes_tieable_p

At least on aarch64, modes_tieable_p is a stricter condition than
can_change_mode_class.  can_change_mode_class tells us whether the
subreg rules produce a sensible result for a particular mode change.
modes_tieable_p in addition tells us whether a mode change is
reasonable for optimisation purposes.

A false return from either hook should (and does) prevent early_ra
from attempting an allocation.  But only a false return from
can_change_mode_class should invalidate the liveness tracking;
we can still analyse subregs for which can_change_mode_class is
true and modes_tieable_p is false.

This doesn't make a difference on its own, but it helps later
patches.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::get_allocno_subgroup): Split can_change_mode_class test
out from modes_tieable_p test and only invalidate the live range
information for the former.

8 months agoaarch64: Improve early_ra dump information
Richard Sandiford [Mon, 18 Nov 2024 19:32:49 +0000 (19:32 +0000)] 
aarch64: Improve early_ra dump information

The early-ra pass often didn't print a dump message when aborting the
allocation.  This patch uses a similar helper to the previous patch.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_allocation_failure): New member function.
(early_ra::get_allocno_subgroup): Use it instead of setting
m_allocation_successful directly.
(early_ra::record_constraints): Likewise.
(early_ra::allocate_colors): Likewise.

8 months agoaarch64: Add early_ra::record_live_range_failure
Richard Sandiford [Mon, 18 Nov 2024 19:32:49 +0000 (19:32 +0000)] 
aarch64: Add early_ra::record_live_range_failure

So far, early_ra has used a single m_allocation_successful bool
to record whether the current region is still being allocated.
But there are (at least) two reasons why we might pull out of
attempting an allocation:

(1) We can't track the liveness of individual FP allocnos,
    due to some awkward subregs.

(2) We're afraid of doing a worse job than the proper allocator.

A later patch needs to distinguish (1) from other reasons, since
(1) means that the liveness information is not trustworthy.
(Currently we assume it is not trustworthy whenever
m_allocation_successful is false, but that's too conservative.)

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_live_range_failure): New member function.
(early_ra::m_accurate_live_ranges): New member variable.
(early_ra::start_new_region): Set m_accurate_live_ranges to true.
(early_ra::get_allocno_subgroup): Use record_live_range_failure
to abort the allocation on invalid subregs.

8 months agoaarch64: Split early_ra::record_insn_refs
Richard Sandiford [Mon, 18 Nov 2024 19:32:48 +0000 (19:32 +0000)] 
aarch64: Split early_ra::record_insn_refs

record_insn_refs has three distinct phases: model the definitions,
model any call, and model the uses.  This patch splits each phase
out into its own function.

This isn't beneficial on its own, but it helps with later patches.

gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_insn_refs): Split into...
(early_ra::record_insn_defs, early_ra::record_insn_call)
(early_ra::record_insn_uses): ...this new functions.
(early_ra::process_block): Update accordingly.

8 months agodiagnostics: add support for nested diagnostics [PR116253]
David Malcolm [Mon, 18 Nov 2024 19:20:17 +0000 (14:20 -0500)] 
diagnostics: add support for nested diagnostics [PR116253]

Previously the diagnostic subsystem supported a one-deep
hierarchy via auto_diagnostic_group, for associating
notes with the warning/error they annotate; this only
affects SARIF output, not text output.

This patch adds support to the diagnostics subsystem for
capturing arbitrarily deep nesting structure within
diagnostic messages.

This patch:
* adds the ability to express nesting internally when
  building diagnostics
* captures the nesting in SARIF output in the form documented
  in SG15's P3358R0 ("SARIF for Structured Diagnostics") via
  a "nestingLevel" property
* adds a new experimental mode to text output to see the
  hierarchy, via:
  -fdiagnostics-set-output=text:experimental-nesting=yes
* adds test coverage via a plugin, which with the above
  option emits:
  • note: child 0
    • note: grandchild 0 0
    • note: grandchild 0 1
    • note: grandchild 0 2
  • note: child 1
    • note: grandchild 1 0
    • note: grandchild 1 1
    • note: grandchild 1 2
  • note: child 2
    • note: grandchild 2 0
    • note: grandchild 2 1
    • note: grandchild 2 2
  using '*' rather than '•' if the text_art::theme is ascii-only.

My hope is to eventually:
(a) use this to improve C++'s template diagnostics
(b) remove the "experimental" caveat from the the text output mode

but this patch doesn't touch the C++ frontend, leaving both of these
to followup work.

gcc/c-family/ChangeLog:
PR other/116253
* c-opts.cc (c_diagnostic_text_finalizer): Use
text_output.build_indent_prefix for prefix to
diagnostic_show_locus.

gcc/ChangeLog:
PR other/116253
* diagnostic-core.h (class auto_diagnostic_nesting_level): New.
* diagnostic-format-sarif.cc (class sarif_builder): Update leading
comment re nesting of diagnostics.
(sarif_result::on_nested_diagnostic): Add nestingLevel property.
* diagnostic-format-text.cc (on_report_diagnostic): If we're
showing nested diagnostics, then print changes of location on a
new line, indented, and update m_last_location.
(diagnostic_text_output_format::build_prefix): If m_show_nesting,
then potentially add indentation and a bullet point.
(get_bullet_point_unichar): New.
(use_unicode_p): New.
(diagnostic_text_output_format::build_indent_prefix): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_show_nesting and m_show_nesting_levels.
(diagnostic_text_output_format::build_indent_prefix): New decl.
(diagnostic_text_output_format::show_nesting_p): New accessor
(diagnostic_text_output_format::show_locations_in_nesting_p):
Likewise.
(diagnostic_text_output_format::set_show_nesting): New.
(diagnostic_text_output_format::set_show_locations_in_nesting):
New.
(diagnostic_text_output_format::set_show_nesting_levels): New.
(diagnostic_text_output_format::m_show_nesting): New field.
(diagnostic_text_output_format::m_show_locations_in_nesting): New
field.
(diagnostic_text_output_format::m_show_nesting_levels): New field.
* diagnostic-global-context.cc
(auto_diagnostic_nesting_level::auto_diagnostic_nesting_level):
New.
(auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level):
New.
* diagnostic-show-locus.cc (layout_printer::print): Temporarily
set DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE.
* diagnostic.cc (diagnostic_context::initialize): Update for
renaming of m_nesting_depth to m_group_nesting_depth and
initialize m_diagnostic_nesting_level.
(diagnostic_context::finish): Update for renaming of
m_nesting_depth to m_group_nesting_depth.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_context::begin_group): Likewise.
(diagnostic_context::end_group): Likewise.
(diagnostic_context::push_nesting_level): New.
(diagnostic_context::pop_nesting_level): New.
(diagnostic_context::set_diagnostic_buffer): Update for renaming
of m_nesting_depth to m_group_nesting_depth.  Assert that we don't
have nested diagnostics.
* diagnostic.h (diagnostic_context::push_nesting_level): New decl.
(diagnostic_context::pop_nesting_level): New decl.
(diagnostic_context::get_diagnostic_nesting_level): New accessor.
(diagnostic_context::build_indent_prefix): New decl.
(diagnostic_context::m_diagnostic_groups): Rename m_nesting_depth
to m_group_nesting_depth and add field m_diagnostic_nesting_level.
* doc/invoke.texi (fdiagnostics-add-output): Add note about
"experimental" schemes, keys, and values.  Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels" to text scheme.
* opts-diagnostic.cc (text_scheme_handler::make_sink): Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels".

gcc/testsuite/ChangeLog:
PR other/116253
* gcc.dg/plugin/diagnostic-test-nesting-sarif.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-sarif.py: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-plain.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: New test plugin.
* gcc.dg/plugin/plugin.exp: Add the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoPR modula2/117555: libgm2 build failure after r15-5081-g95960cd473297c
Gaius Mulley [Mon, 18 Nov 2024 18:35:28 +0000 (18:35 +0000)] 
PR modula2/117555: libgm2 build failure after r15-5081-g95960cd473297c

This patch adds missing return statements to library procedure
functions.  These missing statements occur after a call to RAISE.

gcc/m2/ChangeLog:

PR modula2/117555
* gm2-libs-iso/M2EXCEPTION.mod (M2Exception): Add missing
return statement.
* gm2-libs-iso/RealConv.mod (ValueReal): Ditto.
* gm2-libs-iso/RndFile.mod (StartPos): Ditto.
(EndPos): Ditto.
(NewPos): Ditto.
* gm2-libs-iso/ShortConv.mod (ValueReal): Ditto.
* gm2-libs-iso/WholeConv.mod (ValueInt): Ditto.
(ValueCard): Ditto.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
8 months agoAVR: target/84211 - Add a post reload register optimization pass.
Georg-Johann Lay [Sun, 17 Nov 2024 17:19:42 +0000 (18:19 +0100)] 
AVR: target/84211 - Add a post reload register optimization pass.

This introduces a new post reload pass that tracks known values held
in registers and performs optimizations based on that knowledge.

It runs between the two instances of the RTL peephole pass.

The optimizations are activated by new option -mfuse-move=<0,23>
which provides a 3:2:2:2 mixed radix value:

Digit 0: Activates try_fuse:
    Tries to use a MOVW instead of two LDIs.

Digit 1: Activates try_bin_arg1:
    Simplify the 2nd operand of a binary operation, for example
    X xor Y  can be simplified to  X  when  Y = 0.  When  Y  is an
    expensive constant that's already held in some register R, then
    the expression can be replaced by  X xor R.

Digit 2: Activates try_split_any:
    Split multi-byte operations like shifts into 8-bit instructions.

Digit 3: Activates try_split_ldi:
    Decompose LDI-like insns into a sequence of instructions with better
    performance.  For example, R2[4] = 0x1ff may be performed as:
       CLR  R5
       CLR  R4
       MOVW R2, R4
       INC  R3
       DEC  R2
    Digit 3 can have a value of 0, 1 or 2, where value=2 may come up
    with code that performs better than with value=1 at the expense of
    reduced traceability of the generated assembly code.

Here are some examples:

   Without optimization              |   With optimization
   ====================              |   =================

   long long fn_zero (void)
   {
      return 0;
   }

   ldi r18, 0     ;  movqi_insn      |   ldi r18, 0     ;  movqi_insn
   ldi r19, 0     ;  movqi_insn      |   ldi r19, 0     ;  movqi_insn
   ldi r20, 0     ;  movqi_insn      |   movw r20, r18  ;  *movhi
   ldi r21, 0     ;  movqi_insn      |
   ldi r22, 0     ;  movqi_insn      |   movw r22, r18  ;  *movhi
   ldi r23, 0     ;  movqi_insn      |
   ldi r24, 0     ;  movqi_insn      |   movw r24, r18  ;  *movhi
   ldi r25, 0     ;  movqi_insn      |
   ret                               |   ret

   int fn_eq0 (char c)
   {
       return c == 0;
   }

   mov r18, r24    ;  movqi_insn     |   mov r18, r24   ;  movqi_insn
   ldi r24, 1      ;  *movhi         |   ldi r24, 1     ;  *movhi
   ldi r25, 0                        |   ldi r25, 0
   cp  r18, ZERO   ;  cmpqi3         |   cpse r18, ZERO ;  peephole
   breq .+4        ;  branch         |
   ldi r24, 0      ;  *movhi         |   ldi r24, 0     ;  movqi_insn
   ldi r25, 0                        |
   ret                               |   ret

   unsigned fn_crc (unsigned x, unsigned y)
   {
       for (char i = 8; i--; x <<= 1)
           y ^= (x ^ y) & 0x80 ? 79u : 0u;
       return y;
   }

   movw r18, r24   ;  *movhi         |  movw r18, r24    ;  *movhi
   movw r24, r22   ;  *movhi         |  movw r24, r22    ;  *movhi
   ldi  r22, 8     ;  movqi_insn     |  ldi  r22, 8      ;  movqi_insn
  .L13:                              | .L13:
   movw r30, r18   ;  *movhi         |  movw r30, r18    ;  *movhi
   eor  r30, r24   ;  *xorqi3        |  eor  r30, r24    ;  *xorqi3
   eor  r31, r25   ;  *xorqi3        |  eor  r31, r25    ;  *xorqi3
   mov  r20, r30   ;  *andhi3        |  mov  r20, r30    ;  *andqi3
   andi r20, 1<<7                    |  andi r20, 1<<7
   clr  r21                          |
   sbrs r30, 7     ;  *sbrx_branchhi |  sbrc r30, 7      ;  *sbrx_branchhi
   rjmp .+4                          |
   ldi  r20, 79    ;  movqi_insn     |  ldi  r20, 79     ;  movqi_insn
   ldi  r21, 0     ;  movqi_insn     |
   eor  r24, r20   ;  *xorqi3        |  eor r24, r20     ;  *xorqi3
   eor  r25, r21   ;  *xorqi3        |
   lsl  r18        ;  *ashlhi3_const |  lsl  r18         ;  *ashlhi3_const
   rol  r19                          |  rol  r19
   subi r22, 1     ;  *op8.for.cczn.p|  subi r22, 1      ;  *op8.for.cczn.plus
   brne .L13       ;  branch_ZN      |  brne .L13        ;  branch_ZN
   ret                               |  ret

   #define SPDR (*(uint8_t volatile*) 0x2c)

   void fn_PR49807 (long big)
   {
       SPDR = big >> 24;
       SPDR = big >> 16;
       SPDR = big >> 8;
       SPDR = big;
   }

   movw r20, r22   ;  *movhi         |  movw r20, r22    ;  *movhi
   movw r22, r24   ;  *movhi         |  movw r22, r24    ;  *movhi
   mov  r24, r23   ;  *ashrsi3_const |
   clr  r27                          |
   sbrc r24,7                        |
   com  r27                          |
   mov  r25, r27                     |
   mov  r26, r27                     |
   out  0xc, r24   ;  movqi_insn     |  out 0xc, r23     ;  movqi_insn
   movw r24, r22   ;  *ashrsi3_const |
   clr  r27                          |
   sbrc r25, 7                       |
   com  r27                          |
   mov  r26, r27                     |
   out  0xc, r24   ;  movqi_insn     |  out 0xc, r24     ;  movqi_insn
   clr  r27        ;  *ashrsi3_const |
   sbrc r23, 7                       |
   dec  r27                          |
   mov  r26, r23                     |
   mov  r25, r22                     |
   mov  r24, r21                     |
   out  0xc, r24   ;  movqi_insn     |  out 0xc, r21     ;  movqi_insn
   out  0xc, r20   ;  movqi_insn     |  out 0xc, r20     ;  movqi_insn
   ret                               |  ret

PR target/84211
gcc/
* doc/invoke.texi (AVR Options) [-mfuse-move]: Document new option.
* common/config/avr/avr-common.cc (avr_option_optimization_table):
Set -mfuse-move= depending on optimization level.
* config/avr/avr.opt (-mfuse-move, -mfuse-move=): New options.
* config/avr/t-avr (avr-passes.o): Depend on avr-passes-fuse-move.h.
* config/avr/avr-passes-fuse-move.h: New file, used by avr-passes.cc.
* config/avr/avr-passes.def (avr_pass_fuse_move): Insert new pass.
* config/avr/avr-passes.cc (INCLUDE_ARRAY): Define it.
(insn-attr.h): Include it.
(avr_pass_data_fuse_move): New const pass_data.
(avr_pass_fuse_move): New public rtl_opt_pass class.
(make_avr_pass_fuse_move): New function.
(gprmask_t): New typedef.
(next_nondebug_insn_bb, prev_nondebug_insn_bb)
(single_set_with_scratch, size_to_mask, size_to_mode)
(emit_valid_insn, emit_valid_move_clobbercc)
(gpr_regno_p, regmask, has_bits_in)
(find_arith, find_arith2, any_shift_p): New local functions.
(AVRasm): New namespace.
(FUSE_MOVE_MAX_MODESIZE): New define.
(avr-passes-fuse-move.h): New include.
(memento_t, absint_t, absins_byte_t, absint_val_t)
(optimize_data_t, insn_optimizedata_t, find_plies_data_t)
(insninfo_t, bbinfo_t, ply_t, plies_t): New structs / classes.
* config/avr/avr-protos.h (avr_chunk, avr_byte, avr_word, avr_int8)
(avr_uint8, avr_int16, avr_uint16)
(avr_out_set_some, avr_set_some_operation)
(output_reload_in_const, make_avr_pass_fuse_move): New protos.
(avr_dump): Depend macro definition on GCC_DUMPFILE_H.
* config/avr/avr.cc (avr_option_override): Insert after
pass "avr-fuse-move" instead of after "peephole2".
(avr_chunk, avr_byte, avr_word, avr_int8, avr_uint8, avr_int16)
(avr_uint16, output_reload_in_const): Functions are no more static.
(avr_out_set_some, avr_set_some_operation): New functions.
(ashrqi3_out, ashlqi3_out) [offset=7]: Handle "r,r,C07" alternative.
(avr_out_insert_notbit): Comment also allows QImode.
(avr_adjust_insn_length) [ADJUST_LEN_SET_SOME]: Handle case.
* config/avr/avr.md (adjust_len) <set_some>: New attribute value.
(set_some): New insn.
(andqi3, *andqi3): Add "r,r,Cb1" alternative.
(ashrqi3, *ashrqi3 ashlqi3, *ashlqi3): Add a "r,r,C07" alternative.
(gen_move_clobbercc_scratch): New emit helper.
* config/avr/constraints.md (Cb1): New constraint.
* config/avr/predicates.md (dreg_or_0_operand, set_some_operation): New.
* config/avr/avr-log.cc (avr_forward_to_printf): New static func.
(avr_log_vadump): Use it to recognize more formats.
gcc/testsuite/
* gcc.target/avr/torture/test-gprs.h: New file.
* gcc.target/avr/torture/pr84211-fuse-move-1.c: New test.
* gcc.target/avr/torture/pr84211-fuse-move-2.c: New test.

8 months agoFortran: add bounds-checking for ALLOCATE of CHARACTER with type-spec [PR53357]
Harald Anlauf [Sun, 17 Nov 2024 22:04:58 +0000 (23:04 +0100)] 
Fortran: add bounds-checking for ALLOCATE of CHARACTER with type-spec [PR53357]

Fix a rejects-(potentially)-valid code for ALLOCATE of CHARACTER with
type-spec, and implement a string-length check for -fcheck=bounds.
Implement more detailed errors or warnings when character function
declarations and references do not match.

PR fortran/53357

gcc/fortran/ChangeLog:

* dependency.cc (gfc_dep_compare_expr): Return correct result if
relationship of expressions could not be determined.
* interface.cc (gfc_check_result_characteristics): Implement error
messages if character function declations and references do not
agree, else emit warning in cases where a mismatch is suspected.
* trans-stmt.cc (gfc_trans_allocate): Implement a string length
check for -fcheck=bounds.

gcc/testsuite/ChangeLog:

* gfortran.dg/auto_char_len_4.f90: Adjust patterns.
* gfortran.dg/typebound_override_1.f90: Likewise.
* gfortran.dg/bounds_check_strlen_10.f90: New test.

8 months agotree-optimization/117594 - fix live op vectorization for length masked case
Richard Biener [Mon, 18 Nov 2024 12:46:52 +0000 (13:46 +0100)] 
tree-optimization/117594 - fix live op vectorization for length masked case

The code was passing factor == 0 to vect_get_loop_len which always
returns an unmodified length, even if the number of scalar elements
doesn't agree.  It also failed to insert the eventually generated
code.

PR tree-optimization/117594
* tree-vect-loop.cc (vectorizable_live_operation_1): Pass
factor == 1 to vect_get_loop_len, insert generated stmts.

* gcc.dg/vect/pr117594.c: New testcase.

8 months ago[committed][RISC-V][PR target/117595] Fix bogus use of simplify_gen_subreg
Jeff Law [Mon, 18 Nov 2024 17:55:09 +0000 (10:55 -0700)] 
[committed][RISC-V][PR target/117595] Fix bogus use of simplify_gen_subreg

And stage3 begins...

Zdenek's fuzzer caught this one.  Essentially using simplify_gen_subreg
directly with an offset of 0 when we just needed a lowpart.

The offset of 0 works for little endian, but for big endian it's simply wrong.
simplify_gen_subreg will return NULL_RTX because the case isn't representable.
We then embed that NULL_RTX into an insn that's later scanned during
mark_jump_label.

Scanning the port I see a couple more instances of this incorrect idiom.   One
is pretty obvious to fix.  The others look a bit goofy and I'll probably need
to sync with Patrick on them.

Anyway tested on riscv64-elf and riscv32-elf with no regressions.  Pushing to
the trunk.

PR target/117595
gcc/
* config/riscv/sync.md (atomic_compare_and_swap<mode>): Use gen_lowpart
rather than simplify_gen_subreg.
* config/riscv/riscv.cc (riscv_legitimize_move): Similarly.

gcc/testsuite/
* gcc.target/riscv/pr117595.c: New test.

8 months agoPR modula2/117660: Errors referring to variables of type array could display full...
Gaius Mulley [Mon, 18 Nov 2024 17:51:37 +0000 (17:51 +0000)] 
PR modula2/117660: Errors referring to variables of type array could display full declaration

This patch ensures that the tokens defining the full declaration of an
ARRAY type is stored in the symbol table and used during production of
error messages.

gcc/m2/ChangeLog:

PR modula2/117660
* gm2-compiler/P2Build.bnf (ArrayType): Update tok with the
composite token produced during array type declaration.
* gm2-compiler/P2SymBuild.mod (EndBuildArray): Create the
combinedtok and store it into the symbol table.
Also ensure combinedtok is pushed to the quad stack.
(BuildFieldArray): Preserve typetok.
* gm2-compiler/SymbolTable.def (PutArray): Rename parameters.
* gm2-compiler/SymbolTable.mod (PutArray): Rename parameters.

gcc/testsuite/ChangeLog:

PR modula2/117660
* gm2/iso/fail/arraymismatch.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
8 months agoAVR: target/117659 - Fix wrong code for u24 << 16.
Georg-Johann Lay [Mon, 18 Nov 2024 17:12:38 +0000 (18:12 +0100)] 
AVR: target/117659 - Fix wrong code for u24 << 16.

gcc/
PR target/117659
* config/avr/avr.cc (avr_out_ashlpsi3) [case 16]: Use %A1 as
input (instead of bogus %A0).

8 months agoFix more c23 bool fallout
Jeff Law [Mon, 18 Nov 2024 17:11:01 +0000 (10:11 -0700)] 
Fix more c23 bool fallout

While these haven't shown up in my tester (not configs I test) and I think
we're likely going to be deprecating the nds32 target. we might as well go
ahead and fix them.

I'm going to include this under the pr117628 umbrella.

PR target/117628

libgcc/
* config/arm/freebsd-atomic.c (bool): Remove unnecessary typedef.
* config/arm/linux-atomic-64bit.c: Likewise.
* config/arm/linux-atomic.c: Likewise.
* config/nds32/linux-atomic.c: Likewise.
* config/nios2/linux-atomic.c: Likewise.

8 months ago[RFA] Fix csky and c6x build failures
Jeff Law [Mon, 18 Nov 2024 16:59:54 +0000 (09:59 -0700)] 
[RFA] Fix csky and c6x build failures

csky fails to build libgcc after the c23 changes because it has a typedef for
bool.  AFAICT it's internal to the file, so removing the typedef isn't an ABI
change.

Similiarly for c6x which includes unwind-arm-common.inc.  I suspect most, if
not all of the arm-v7 and older targets are failing to build right now.

I've built and regression tested both csky-linux-gnu and c6x-elf with this
change.  OK for the trunk?

PR target/117628
libgcc/
* config/csky/linux-atomic.c (bool): Remove unnecessary typedef.
* unwind-arm-common.inc (bool): Similarly.

8 months agoPR modula2/117371: Add check for zero step in for loop
Gaius Mulley [Mon, 18 Nov 2024 16:34:42 +0000 (16:34 +0000)] 
PR modula2/117371: Add check for zero step in for loop

This patch is a follow on from PR modula2/117371 which could include
a check to enforce the ISO restriction on a zero for loop step.

gcc/m2/ChangeLog:

PR modula2/117371
* gm2-compiler/M2GenGCC.mod (PerformLastForIterator):
Add check for zero step value and issue an error message.

gcc/testsuite/ChangeLog:

PR modula2/117371
* gm2/iso/fail/forloopbyzero.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
8 months agoada: Fix interaction of aspect Predicate and static case expressions
Eric Botcazou [Sun, 10 Nov 2024 18:20:13 +0000 (19:20 +0100)] 
ada: Fix interaction of aspect Predicate and static case expressions

The semantics of the GNAT-specific Predicate aspect should be equivalent
to those of the Static_Predicate aspect when the predicate expression is
static, but that is not correctly implemented for static case expressions.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_N_Case_Expression): Remove the test on
enclosing predicate function for the return optimization.
Rewrite it in the general case to catch all nondynamic predicates.
(Expand_N_If_Expression): Remove the test on enclosing predicate
function for the return optimization.

8 months agoada: Atomic_Synchronization is not a user-visible check
Bob Duff [Sun, 10 Nov 2024 11:39:57 +0000 (06:39 -0500)] 
ada: Atomic_Synchronization is not a user-visible check

Remove all user-level documentation of the check name
"Atomic_Synchronization". The documentation was confusing because
this check should never be used in source code, and because it
raises the question of whether All_Checks applies to it (it does
not).

Change the name Atomic_Synchronization to be _Atomic_Synchronization
(with a leading underscore) so that it cannot be used in source code.

This "check" is not really a check at all; it is used only internally in
the implementation of Disable/Enable_Atomic_Synchronization, because the
placement and scope of these pragmas match pragma Suppress.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_characteristics.rst:
Remove Atomic_Synchronization.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Likewise.
* doc/gnat_rm/implementation_defined_pragmas.rst: DRY.
Consolidate documentation of Disable/Enable_Atomic_Synchronization.
* checks.adb: Comment fix.
* exp_util.ads: Likewise.
* targparm.ads: Likewise.
* types.ads: Likewise.
* gnat1drv.adb: Likewise. DRY.
* sem_prag.adb (Process_Disable_Enable_Atomic_Sync):
Change name of Atomic_Synchronization to start with
underscore.
(Process_Suppress_Unsuppress): No need to check Comes_From_Source for
Atomic_Synchronization anymore; _Atomic_Synchronization can never
come from source. (Anyway, it shouldn't be ignored; it should be
an error.)
* snames.ads-tmpl (Atomic_Synchronization):
Change name to start with underscore.
* switch-c.adb (Scan_Front_End_Switches):
Minor cleanup: Use 'in'.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

8 months agoada: Fix small oversight in removal of N_Unchecked_Expression node
Eric Botcazou [Fri, 8 Nov 2024 14:35:27 +0000 (15:35 +0100)] 
ada: Fix small oversight in removal of N_Unchecked_Expression node

In addition to Resolve_Indexed_Component, Eval_Indexed_Component can also
set the Do_Range_Check flag on the expressions of an N_Indexed_Component
node through the call on Check_Non_Static_Context, so this also needs to
be blocked by the Kill_Range_Check flag.

gcc/ada/ChangeLog:

* sem_eval.adb (Eval_Indexed_Component): Clear Do_Range_Check on
the expressions if Kill_Range_Check is set on the node.

8 months agoada: Fix another minor fallout of previous changes to aggregate expansion
Eric Botcazou [Fri, 8 Nov 2024 10:01:11 +0000 (11:01 +0100)] 
ada: Fix another minor fallout of previous changes to aggregate expansion

This is another glitch associated with Initialization_Statements.

gcc/ada/ChangeLog:

* exp_util.adb (Remove_Init_Call): Rewrite a compound statement in
the Initialization_Statements of the variable as a null statement
instead of removing it.
* freeze.adb (Explode_Initialization_Compound_Statement): Small
comment tweaks.

8 months agoada: Fix another minor fallout of previous changes to aggregate expansion
Eric Botcazou [Thu, 7 Nov 2024 18:23:39 +0000 (19:23 +0100)] 
ada: Fix another minor fallout of previous changes to aggregate expansion

The processing of static array aggregates in Exp_Aggr requires that their
bounds be representable as Int(eger) values for practical purposes, and
the previous changes have exposed another path where this is not checked.

This introduces a UI_Are_In_Int_Range local predicate for convenience.

gcc/ada/ChangeLog:

* exp_aggr.adb (UI_Are_In_Int_Range): New predicate.
(Aggr_Size_OK): Use it.
(Flatten): Likewise.
(Packed_Array_Aggregate_Handled): Likewise.
(Static_Array_Aggregate): Likewise.

8 months agoada: Fix minor fallout of previous changes to aggregate expansion
Eric Botcazou [Thu, 7 Nov 2024 17:50:49 +0000 (18:50 +0100)] 
ada: Fix minor fallout of previous changes to aggregate expansion

The problem occurs for an anonymous array object declared with an aspect and
when pragma {Initialize,Normalize}_Scalars is in effect: in this case, the
synthesized aggregate is attached to the Initialization_Statements field by
Convert_Aggr_In_Object_Decl, but Explode_Initialization_Compound_Statement
puts it back at the point of declaration instead of the freeze point, thus
voiding the effects of the mechanism.

This was previously hidden because of a bypass in Freeze_Entity which drops
the freeze node on the floor in this case, so the change fixes the issue and
removes the bypass in the process.

gcc/ada/ChangeLog:

* freeze.ads (Explode_Initialization_Compound_Statement): Adjust the
description.
* freeze.adb (Explode_Initialization_Compound_Statement): If the
entity has its freezing delayed, append the initialization actions
to its freeze actions.
(Freeze_Object_Declaration): Remove commented out code.
(Freeze_Entity): Remove bypass for object of anonymous array type.

8 months agoada: Small cleanup and refactoring in expansion of asynchronous select
Eric Botcazou [Thu, 31 Oct 2024 10:21:56 +0000 (11:21 +0100)] 
ada: Small cleanup and refactoring in expansion of asynchronous select

The exception handler that catches Abort_Signal does nothing nowadays.
This refactors the code to use Build_Abort_Block more consistently and
also makes it simpler by dropping the identifier on the abort block.

No functional changes.

gcc/ada/ChangeLog:

* exp_sel.ads (Build_Abort_Block): Remove second parameter and
rename the third.
(Build_Abort_Block_Handler): Fix description.
* exp_sel.adb (Build_Abort_Block): Remove second parameter, rename
the third and adjust accordingly.
* exp_ch9.adb (Expand_N_Asynchronous_Select): Fix the description
of the exception handler throughout.  Remove Abort_Block_Ent and
Hdle local variables.  Call Build_Abort_Block consistently to build
the abort block and adjust existing calls.

8 months agoada: Array aggregate with large static bounds causes compiler crash
Steve Baird [Wed, 30 Oct 2024 22:34:50 +0000 (15:34 -0700)] 
ada: Array aggregate with large static bounds causes compiler crash

In some cases an array aggregate with statically known bounds and at least
one bound outside of the range of a 32-bit signed integer causes
a bugbox.

gcc/ada/ChangeLog:

* exp_aggr.adb (Convert_To_Positional.Flatten): Avoid raising
Constraint_Error in UI_To_Int by testing UI_Is_In_Int_Range first.

8 months agoada: Cleanup in expansion of array aggregates in object declarations
Eric Botcazou [Wed, 6 Nov 2024 15:09:28 +0000 (16:09 +0100)] 
ada: Cleanup in expansion of array aggregates in object declarations

This mainly decouples the handling of the declaration case from that of the
assignment case in Expand_Array_Aggregate, as well as moves the expansion
in the case of an aggregate that can be processed by the back end to the
Build_Array_Aggr_Code routine.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Array_Aggr_Code): Build the simple assignment
for the case of an aggregate that can be handled by the back end.
(Expand_Array_Aggregate): Adjust description of the processing.
Move handling of declaration case to STEP 4 and remove handling of
the case of an aggregate that can be processed by the back end.
(Late_Expansion): Likewise for the second part.
* exp_ch3.adb (Expand_N_Object_Declaration): Deal with a delayed
aggregate synthesized for the default initialization, if any.
* sem_eval.adb (Eval_Indexed_Component): Bail out for the name of
an assignment statement.

8 months agoada: Further cleanup in expansion of array aggregates in allocators
Eric Botcazou [Tue, 5 Nov 2024 14:46:45 +0000 (15:46 +0100)] 
ada: Further cleanup in expansion of array aggregates in allocators

This mainly decouples the handling of the allocator case from that of the
assignment case in Expand_Array_Aggregate and also makes Must_Slide a bit
more forgiving.

gcc/ada/ChangeLog:

* exp_aggr.adb (In_Place_Assign_OK): Remove handling of allocators
and call Must_Slide instead of implementing the check manually.
(Convert_To_Assignments): Adjust outdated comment.
(Expand_Array_Aggregate): Move handling of allocator case to STEP 3
and call Must_Slide directly for it.
(Must_Slide): Replace tests based on Is_OK_Static_Expression with
tests based on Compile_Time_Known_Value.

8 months agoada: Small cleanup in expansion of array aggregates in allocators
Eric Botcazou [Tue, 5 Nov 2024 10:24:06 +0000 (11:24 +0100)] 
ada: Small cleanup in expansion of array aggregates in allocators

Convert_Array_Aggr_In_Allocator does nothing that Late_Expansion cannot do,
so this deletes the former and moves its support code for Storage_Model to
the latter.  No functional changes.

gcc/ada/ChangeLog:

* exp_aggr.adb (Convert_Array_Aggr_In_Allocator): Delete.
(Convert_Aggr_In_Allocator): Do not call above procedure.
(Late_Expansion): Deal with a target that is the dereference of a
prefix with a Storage_Model.  Remove an useless actual parameter
in the call to Build_Array_Aggr_Code.

8 months agoada: Constraint error not raised in ACATS test c413007
Javier Miranda [Sun, 20 Oct 2024 12:13:03 +0000 (12:13 +0000)] 
ada: Constraint error not raised in ACATS test c413007

Reverse the meaning of switch -gnatd_P; that is, enable by default
the generating of a runtime check when the prefix of the call is
an access-to-subprogram type with a null value.

gcc/ada/ChangeLog:

* sem_res.adb (Resolve_Actuals): Add by default a null-exclusion
check on the prefix of the call when it is an access-type; it can
be disabled using -gnatd_P.
* debug.adb (gnatd_P): Update documentation.

8 months agoada: Crash on 'Access for Stream_Element_Array object
squirek [Thu, 24 Oct 2024 17:02:53 +0000 (17:02 +0000)] 
ada: Crash on 'Access for Stream_Element_Array object

This patch fixes a crash in the compiler when the actual for an anonymous
access type formal is an 'Access of a Sream_Element_Array object during
the calculation of said actual's accessibility level.

gcc/ada/ChangeLog:

* accessibility.adb (Accessibility_Level): Handle the Input attribute
case

8 months agoada: Tweak test for predefined main unit
Ronan Desplanques [Mon, 4 Nov 2024 16:57:15 +0000 (17:57 +0100)] 
ada: Tweak test for predefined main unit

This change is part of an effort to reduce usage of
Is_Predefined_Filename.

gcc/ada/ChangeLog:

* frontend.adb (Frontend): tweak test for predefined main unit.

8 months agolibgomp/plugin/plugin-gcn.c: async-queue init - fix function-return type and fail...
Tobias Burnus [Mon, 18 Nov 2024 13:58:21 +0000 (14:58 +0100)] 
libgomp/plugin/plugin-gcn.c: async-queue init - fix function-return type and fail fatally

libgomp/ChangeLog:

* plugin/plugin-gcn.c (GOMP_OFFLOAD_openacc_async_construct): In
case of an error, call GOMP_PLUGIN_fatal not ..._error; use NULL
not false in return.

8 months agotestsuite: Move test pr117093.c into gcc.target/aarch64.
Jennifer Schmitz [Mon, 18 Nov 2024 09:02:42 +0000 (01:02 -0800)] 
testsuite: Move test pr117093.c into gcc.target/aarch64.

The test file pr117093.c failed on platforms other than aarch64, because
it uses arm_neon.h. We moved it into gcc.target/aarch64.

The patch was bootstrapped and tested on aarch64-linux-gnu and
x86_64-linux-gnu, no regression.
Committed as obvious.

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>
gcc/testsuite/
PR tree-optimization/117093
* gcc.dg/tree-ssa/pr117093.c: Move to gcc.target/aarch64.
* gcc.target/aarch64/pr117093.c: New test.

8 months agoRISC-V: Add VLS modes to strided loads.
Robin Dapp [Mon, 4 Nov 2024 14:34:50 +0000 (15:34 +0100)] 
RISC-V: Add VLS modes to strided loads.

This patch adds VLS modes to the strided load expanders.

gcc/ChangeLog:

* config/riscv/autovec.md: Add VLS modes.
* config/riscv/vector-iterators.md: Ditto.
* config/riscv/vector.md: Ditto.

8 months agoRISC-V: Add else operand to masked loads [PR115336].
Robin Dapp [Thu, 8 Aug 2024 08:31:22 +0000 (10:31 +0200)] 
RISC-V: Add else operand to masked loads [PR115336].

This patch adds else operands to masked loads.  Currently the default
else operand predicate just accepts "undefined" (i.e. SCRATCH) values.

PR middle-end/115336
PR middle-end/116059

gcc/ChangeLog:

* config/riscv/autovec.md: Add else operand.
* config/riscv/predicates.md (maskload_else_operand): New
predicate.
* config/riscv/riscv-v.cc (get_else_operand): Remove static.
(expand_load_store): Use get_else_operand and adjust index.
(expand_gather_scatter): Ditto.
(expand_lanes_load_store): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr115336.c: New test.
* gcc.target/riscv/rvv/autovec/pr116059.c: New test.

8 months agoi386: Add zero maskload else operand.
Robin Dapp [Tue, 5 Nov 2024 13:47:07 +0000 (14:47 +0100)] 
i386: Add zero maskload else operand.

gcc/ChangeLog:

* config/i386/sse.md (maskload<mode><sseintvecmodelower>):
Call maskload<mode>..._1.
(maskload<mode><sseintvecmodelower>_1): Rename.

8 months agogcn: Add else operand to masked loads.
Robin Dapp [Thu, 8 Aug 2024 08:31:05 +0000 (10:31 +0200)] 
gcn: Add else operand to masked loads.

This patch adds an undefined else operand to the masked loads.

gcc/ChangeLog:

* config/gcn/predicates.md (maskload_else_operand): New
predicate.
* config/gcn/gcn-valu.md: Use new predicate.

8 months agoaarch64: Add masked-load else operands.
Robin Dapp [Thu, 8 Aug 2024 08:30:58 +0000 (10:30 +0200)] 
aarch64: Add masked-load else operands.

This adds zero else operands to masked loads and their intrinsics.
I needed to adjust more than initially thought because we rely on
combine for several instructions and a change in a "base" pattern
needs to propagate to all those.

gcc/ChangeLog:

* config/aarch64/aarch64-sve-builtins-base.cc: Add else
handling.
* config/aarch64/aarch64-sve-builtins.cc (function_expander::use_contiguous_load_insn):
Ditto.
* config/aarch64/aarch64-sve-builtins.h: Add else operand to
contiguous load.
* config/aarch64/aarch64-sve.md (@aarch64_load<SVE_PRED_LOAD:pred_load>
_<ANY_EXTEND:optab><SVE_HSDI:mode><SVE_PARTIAL_I:mode>):
Split and add else operand.
(@aarch64_load_<ANY_EXTEND:optab><SVE_HSDI:mode><SVE_PARTIAL_I:mode>):
Ditto.
(*aarch64_load_<ANY_EXTEND:optab>_mov<SVE_HSDI:mode><SVE_PARTIAL_I:mode>):
Ditto.
* config/aarch64/aarch64-sve2.md: Ditto.
* config/aarch64/iterators.md: Remove unused iterators.
* config/aarch64/predicates.md (aarch64_maskload_else_operand):
Add zero else operand.

8 months agovect: Add maskload else value support.
Robin Dapp [Thu, 8 Aug 2024 12:29:05 +0000 (14:29 +0200)] 
vect: Add maskload else value support.

This patch adds an else operand to vectorized masked load calls.
The current implementation adds else-value arguments to the respective
target-querying functions that is used to supply the vectorizer with the
proper else value.

We query the target for its supported else operand and uses that for the
maskload call.  If necessary, i.e. if the mode has padding bits and if
the else operand is nonzero, a VEC_COND enforcing a zero else value is
emitted.

gcc/ChangeLog:

* optabs-query.cc (supports_vec_convert_optab_p): Return icode.
(get_supported_else_val): Return supported else value for
optab's operand at index.
(supports_vec_gather_load_p): Add else argument.
(supports_vec_scatter_store_p): Ditto.
* optabs-query.h (supports_vec_gather_load_p): Ditto.
(get_supported_else_val): Ditto.
* optabs-tree.cc (target_supports_mask_load_store_p): Ditto.
(can_vec_mask_load_store_p): Ditto.
(target_supports_len_load_store_p): Ditto.
(get_len_load_store_mode): Ditto.
* optabs-tree.h (target_supports_mask_load_store_p): Ditto.
(can_vec_mask_load_store_p): Ditto.
* tree-vect-data-refs.cc (vect_lanes_optab_supported_p): Ditto.
(vect_gather_scatter_fn_p): Ditto.
(vect_check_gather_scatter): Ditto.
(vect_load_lanes_supported): Ditto.
* tree-vect-patterns.cc (vect_recog_gather_scatter_pattern):
Ditto.
* tree-vect-slp.cc (vect_get_operand_map): Adjust indices for
else operand.
(vect_slp_analyze_node_operations): Skip undefined else operand.
* tree-vect-stmts.cc (exist_non_indexing_operands_for_use_p):
Add else operand handling.
(vect_get_vec_defs_for_operand): Handle undefined else operand.
(check_load_store_for_partial_vectors): Add else argument.
(vect_truncate_gather_scatter_offset): Ditto.
(vect_use_strided_gather_scatters_p): Ditto.
(get_group_load_store_type): Ditto.
(get_load_store_type): Ditto.
(vect_get_mask_load_else): Ditto.
(vect_get_else_val_from_tree): Ditto.
(vect_build_one_gather_load_call): Add zero else operand.
(vectorizable_load): Use else operand.
* tree-vectorizer.h (vect_gather_scatter_fn_p): Add else
argument.
(vect_load_lanes_supported): Ditto.
(vect_get_mask_load_else): Ditto.
(vect_get_else_val_from_tree): Ditto.

8 months agotree-ifcvt: Add zero maskload else value.
Robin Dapp [Thu, 8 Aug 2024 10:54:36 +0000 (12:54 +0200)] 
tree-ifcvt: Add zero maskload else value.

When predicating a load we implicitly assume that the else value is
zero.  This matters in case the loaded value is padded (like e.g.
a Bool) and we must ensure that the padding bytes are zero on targets
that don't implicitly zero inactive elements.

A former version of this patch still had this handling in ifcvt but
the latest version defers it to the vectorizer.

gcc/ChangeLog:

* tree-if-conv.cc (predicate_load_or_store): Add zero else
operand and comment.

8 months agoifn: Add else-operand handling.
Robin Dapp [Thu, 8 Aug 2024 08:54:35 +0000 (10:54 +0200)] 
ifn: Add else-operand handling.

This patch adds else-operand handling to the internal functions.

gcc/ChangeLog:

* internal-fn.cc (add_mask_and_len_args): Rename...
(add_mask_else_and_len_args): ...to this and add else handling.
(expand_partial_load_optab_fn): Use adjusted function.
(expand_partial_store_optab_fn): Ditto.
(expand_scatter_store_optab_fn): Ditto.
(expand_gather_load_optab_fn): Ditto.
(internal_fn_len_index): Add else handling.
(internal_fn_else_index): Ditto.
(internal_fn_mask_index): Ditto.
(get_supported_else_vals): New function.
(supported_else_val_p): New function.
(internal_gather_scatter_fn_supported_p): Add else operand.
* internal-fn.h (internal_gather_scatter_fn_supported_p): Define
else constants.
(MASK_LOAD_ELSE_ZERO): Ditto.
(MASK_LOAD_ELSE_M1): Ditto.
(MASK_LOAD_ELSE_UNDEFINED): Ditto.
(get_supported_else_vals): Declare.
(supported_else_val_p): Ditto.

8 months agodocs: Document maskload else operand and behavior.
Robin Dapp [Thu, 8 Aug 2024 08:32:25 +0000 (10:32 +0200)] 
docs: Document maskload else operand and behavior.

This patch amends the documentation for masked loads (maskload,
vec_mask_load_lanes, and mask_gather_load as well as their len
counterparts) with an else operand.

gcc/ChangeLog:

* doc/md.texi: Document masked load else operand.

8 months agolibgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 wrong-return-type...
Tobias Burnus [Mon, 18 Nov 2024 10:06:58 +0000 (11:06 +0100)] 
libgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 wrong-return-type error [PR117626]

libgomp/ChangeLog:

PR libgomp/117626
* plugin/plugin-nvptx.c (nvptx_open_device): Use 'CUDA_CALL_ERET'
with 'NULL' as error return instead of 'CUDA_CALL' that returns false.

8 months agomatch: Fix the `max<a,b>==0` pattern for pointers [PR117646]
Andrew Pinski [Mon, 18 Nov 2024 04:21:58 +0000 (20:21 -0800)] 
match: Fix the `max<a,b>==0` pattern for pointers [PR117646]

For pointers I forgot that BIT_IOR_EXPR is not valid so when
I added the pattern to convert `max<a,b> != 0` (r15-5356), GCC
would start to ICEing saying pointer types were not valid for
BIT_IOR_EXPR.
This fixes the problem by casting to the unsigned type of the
inner type. There was another way of fixing this to handling it
as `a == 0 & b == 0` but both match and reassoication (for pointers)
will then convert it back into the form I am creating here so
let's just use that form instead.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/117646

gcc/ChangeLog:

* match.pd (`max<a,b>==0`): Add casts to `unsigned type`.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/minmaxneeqptr-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agolibstdc++: Fix invalid casts in unordered container merge functions
Jonathan Wakely [Thu, 14 Nov 2024 14:25:52 +0000 (14:25 +0000)] 
libstdc++: Fix invalid casts in unordered container merge functions

François pointed out that static_cast<__node_ptr>(&_M_before_begin) is
invalid, because _M_before_begin is only a node-base not a node.

Refactor the new merge overloads to only cast when we know we have a
valid node.

He also pointed out some optimizations to allow reusing hash codes that
might be cached in the node. The _M_src_hash_code function already has
the right logic to decide when a cached hash code can be reused by a
different _Hashtable object.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (_Hashtable::_M_src_hash_code):
Improve comments.
(_Hashtable::_M_merge_unique(_Hashtable&)): Use pointer_traits
to get before-begin pointer. Only use static_cast on valid
nodes, not the before-begin pointer. Reuse a hash code cached in
the node when possible.
(_Hashtable::_M_merge_multi(_Hashtable&)): Likewise.

Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
8 months agolibcpp: add .c++-header-unit target
Jason Merrill [Wed, 5 Jun 2024 01:15:02 +0000 (21:15 -0400)] 
libcpp: add .c++-header-unit target

The dependency output for header unit modules is based on the absolute
pathname of the header file, but that's not something that a makefile can
portably refer to.  This patch adds a .c++-header-unit target based on the
header name relative to an element of the include path.

libcpp/ChangeLog:

* internal.h (_cpp_get_file_dir): Declare.
* files.cc (_cpp_get_file_dir): New fn.
* mkdeps.cc (make_write): Use it.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dep-4.H: New test.

8 months agotestsuite: Fix pr101145inf*.c testcases [PR117494]
Andrew Pinski [Sun, 17 Nov 2024 21:40:22 +0000 (13:40 -0800)] 
testsuite: Fix pr101145inf*.c testcases [PR117494]

Instead of doing a dg-run with a specific target check for linux.
Use signal as the effective-target since this requires the use
of ALARM signal to do the testing.
Also use check_vect in the main and renames main to main1 to make sure
we don't use the registers.

Tested on x86_64-linux-gnu.

PR testsuite/117494
gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr101145inf.c: Remove dg-do and replace
with dg-require-effective-target of signal.
* gcc.dg/vect/pr101145inf_1.c: Likewise.
* gcc.dg/vect/pr101145inf.inc: Rename main to main1
and mark as noinline.
Include tree-vect.h. Have main call check_vect and main1.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agolibstdc++: Update reference to Angelika Langer's article
Gerald Pfeifer [Mon, 18 Nov 2024 07:33:49 +0000 (08:33 +0100)] 
libstdc++: Update reference to Angelika Langer's article

libstdc++-v3:
* doc/xml/manual/allocator.xml: Update reference to Angelika
Langer's article.
* doc/html/manual/memory.html: Regenerate.

8 months agoImprove ext-dce's ability to eliminate more extensions
Jeff Law [Sun, 17 Nov 2024 23:44:09 +0000 (16:44 -0700)] 
Improve ext-dce's ability to eliminate more extensions

I was looking at a regression in ext-dce's behavior just before Cauldron.
Essentially a bugfix in ext-dce ended up causing us to fail to eliminate some
useless extensions.

When we have a SUBREG object with SUBREG_PROMOTED_VAR* flags set, we generally
have to be more conservative in how we process bit group liveness, making bits
live that wouldn't obviously be live otherwise.

That's not always necessary though. For example, if we're storing a promoted
subreg into memory, we may not care about those extra live bits on this
instance of the subreg object (remember subregs are not shared!).  Essentially
if the mode of the memory reference is not wider than the mode of the inner
REG, then we can clear the promoted state which in turn may allow more
extension elimination.

So at the start of ext-dce we do a simple pass over the IL and remove promoted
subreg state when it's obviously safe to do so (memory stores when the modes
allow it).  That prevents extra bits from being live and ultimately allows us
to remove more useless extensions.

The testcase is in theory generic, but many targets won't have an opportunity
to optimize this case.  So rather then build out a large inclusion/exclusion
list, I've just made the test risc-v specific.

Bootstrapped and regression tested on aarch64, riscv64, s390x, etc in my tester.

gcc/
* ext-dce.cc (maybe_clear_subreg_promoted_p): New function.
(ext_dce_execute): Call it.

gcc/testsuite
* gcc.target/riscv/ext-dce-1.c: New test.

8 months agoAlpha: Remove leftover `;;' for "unaligned_store<mode>"
Maciej W. Rozycki [Mon, 18 Nov 2024 03:02:59 +0000 (03:02 +0000)] 
Alpha: Remove leftover `;;' for "unaligned_store<mode>"

Remove stray `;;' from the middle of the introductory comment for the
"unaligned_store<mode>" expander, clearly a leftover from a previous
edition.

gcc/
* config/alpha/alpha.md (unaligned_store<mode>): Remove stray
`;;'.

8 months agohppa: Update install documentation
John David Anglin [Mon, 18 Nov 2024 01:37:53 +0000 (20:37 -0500)] 
hppa: Update install documentation

2024-11-17  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

PR target/69374
* doc/install.texi (Specific) <hppa*-hp-hpux11>: Update anchor
and heading to reflect removal of 32-bit hppa support on HP-UX.
Trim 32-bit related text.

8 months agoDaily bump.
GCC Administrator [Mon, 18 Nov 2024 00:17:28 +0000 (00:17 +0000)] 
Daily bump.

8 months agoc++: regenerate opt urls
Jason Merrill [Sun, 17 Nov 2024 19:42:09 +0000 (20:42 +0100)] 
c++: regenerate opt urls

This should have been part of r15-5367.  One day I'll remember to do this
before buildbot sends me hate mail.

gcc/c-family/ChangeLog:

* c.opt.urls: Regenerate.

8 months agohppa: Remove typedef for bool type
John David Anglin [Sun, 17 Nov 2024 19:42:39 +0000 (14:42 -0500)] 
hppa: Remove typedef for bool type

In C23, bool is now a keyword.  So, doing a typedef for it is invalid.

2024-11-17  John David Anglin  <danglin@gcc.gnu.org>

libgcc/ChangeLog:

PR target/117627
* config/pa/linux-atomic.c: Remove typedef for bool type.

8 months agoc: Implement -Wdeprecated-non-prototype
Florian Weimer [Sun, 17 Nov 2024 18:42:33 +0000 (19:42 +0100)] 
c: Implement -Wdeprecated-non-prototype

This warning covers the C23 incompibilities resulting from using
() as parameter lists in function declarations.

The warning name comes from Clang.  The implementation is not
perfect because GCC treats these two declarations as equivalent:

  void f ();
  void f (not_a_type);

This is a bit confusing because they are clearly visually distinct.
However, as of GCC 14, the second form is an error by default, so
treating both the same as far as  -Wdeprecated-non-prototype does
not seem so bad from a user experience view.

gcc/c-family/

PR c/95445
* c-opts.cc (c_common_post_options): Initialize
warn_deprecated_non_prototype.
* c.opt (Wdeprecated-non-prototype): New option.
* c.opt.urls: Regenerate.

gcc/c/

PR c/95445
* c-decl.cc (start_function): Warn about parameters
after parameter-less declaration.
* c-typeck.cc (build_function_call_vec): Pass fntype
to convert_arguments.
(convert_arguments): Change argument to fntype and
compute typelist.  Warn about parameter list mismatches
on first parameter.

gcc/

PR c/95445
* doc/invoke.texi: Document -Wdeprecated-non-prototype.

gcc/testsuite/

PR c/95445
* gcc.dg/Wdeprecated-non-prototype-1.c: New test.
* gcc.dg/Wdeprecated-non-prototype-2.c: New test.
* gcc.dg/Wdeprecated-non-prototype-3.c: New test.
* gcc.dg/Wdeprecated-non-prototype-4.c: New test.

8 months agoc++: -M and modules again
Jason Merrill [Sat, 16 Nov 2024 20:25:04 +0000 (15:25 -0500)] 
c++: -M and modules again

While experimenting with testing module std I noticed that gcc -M broke on
it; it seems I need to set directives_only even sooner than I did in
r15-4219.

gcc/c-family/ChangeLog:

* c-ppoutput.cc (preprocess_file): Don't set directives_only here.

gcc/cp/ChangeLog:

* module.cc (module_preprocess_options): Set directives_only here.

8 months agoc-family: add -fsearch-include-path
Jason Merrill [Fri, 17 May 2024 01:43:20 +0000 (21:43 -0400)] 
c-family: add -fsearch-include-path

The C++ modules code has a -fmodule-header (or -x c++-{user,system}-header)
option to specify looking up headers to compile to header units on the usual
include paths.  I'd like to have the same functionality for full C++20
modules such as module std, which I proposed to live on the include path at
bits/std.cc.  But this behavior doesn't seem necessarily connected to
modules, so I'm proposing a general C/C++ option to specify the behavior of
looking in the include path for the input files specified on the command
line.

Other ideas for the name of the option are very welcome.

The libcpp change is to allow -fsearch-include-path{,=user} to find files in
the current working directory, like -include.  This can be handy for a quick
compile of both std.cc and a file that imports it, e.g.

g++ -std=c++20 -fmodules -fsearch-include-path bits/std.cc importer.cc

gcc/ChangeLog:

* doc/cppopts.texi: Document -fsearch-include-path.
* doc/invoke.texi: Mention it for modules.

gcc/c-family/ChangeLog:

* c.opt: Add -fsearch-include-path.
* c-opts.cc (c_common_post_options): Handle it.

gcc/cp/ChangeLog:

* module.cc (module_preprocess_options): Don't override it.

libcpp/ChangeLog:

* internal.h (search_path_head): Declare.
* files.cc (search_path_head): No longer static.
* init.cc (cpp_read_main_file): Use it.

8 months agolibstdc++: add module std [PR106852]
Jason Merrill [Thu, 10 Oct 2024 21:27:50 +0000 (17:27 -0400)] 
libstdc++: add module std [PR106852]

This patch introduces an installed source form of module std and std.compat.
To help a build system find them, we install a libstdc++.modules.json file
alongside libstdc++.so, which tells the build system where the files are and
any special flags it should use when compiling them (none, in this case).
The format is from a proposal in SG15.  The build system can find this file
with 'gcc -print-file-name=libstdc++.modules.json'.

It seems preferable to use a relative path from this file to the sources so
that moving the installation doesn't break the reference, but I didn't see
any obvious way to compute that without relying on coreutils, perl, or
python, so I wrote a POSIX shell script for it.  The .. canonicalization
bits aren't necessary since I discovered $(abspath), but I guess I might as
well leave them in.

Currently this installs the sources under $(gxx_include_dir)/bits/,
i.e. /usr/include/c++/15/bits.  So with my -fsearch-include-path change,
std.cc can be compiled with g++ -fsearch-include-path bits/std.cc.  Note
that if someone actually tries to #include <bits/std.cc> it will fail with
"error: module control-line cannot be in included file".

Any ideas about a more user-friendly way to express "compile module std" are
welcome.

The sources currently have the extension .cc, like other source files.

std.cc started with m.cencora's implementation in PR114600.  I've made some
adjustments, but more is probably desirable, e.g. of the <algorithm>
handling of namespace ranges, and to remove exports of templates that are
only specialized in a particular header.  I've filled in a bunch of missing
exports, and added some FIXMEs where I noticed bits that are not implemented
yet.

Since bits/stdc++.h also intends to include the whole standard library, I
include it rather than duplicate it.  But stdc++.h comments out <execution>,
due to TBB issues; I include it separately and suppress TBB usage, so module
std won't currently provide parallel execution.

It seemed most convenient for the two files to be monolithic so we don't
need to worry about include paths.  So the C library names that module
std.compat exports in both namespace std and :: are a block of code that is
appended to both files, adjusted based on whether the macro STD_COMPAT is
defined before the block.

In this implementation std.compat imports std; it would also be valid for it
to duplicate everything in std.  I see the libc++ std.compat also imports
std.

As discussed in the PR, module std is supported in C++20 mode even though it
was added in C++23.

Changes to test module std will follow in a separate patch.  In my testing
I've noticed a few compiler bugs that break various testcases, so I don't
expect to enable module std testing by default at first.

PR libstdc++/106852

libstdc++-v3/ChangeLog:

* include/bits/version.def: Add __cpp_lib_modules.
* include/bits/version.h: Regenerate.
* src/c++23/Makefile.am: Add modules std and std.compat.
* src/c++23/Makefile.in: Regenerate.
* src/c++23/std-clib.cc.in: New file.
* src/c++23/std.cc.in: New file.
* src/c++23/std.compat.cc.in: New file.
* src/c++23/libstdc++.modules.json.in: New file.

contrib/ChangeLog:

* relpath.sh: New file.