]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
13 months agomap packed field type to unpacked for debug info
Alexandre Oliva [Wed, 12 Jun 2024 03:16:22 +0000 (00:16 -0300)] 
map packed field type to unpacked for debug info

We create a distinct type for each field in a packed record with a
gnu_size, but there is no distinct debug information for them.  Use
the same unpacked type for debug information.

for  gcc/ada/ChangeLog

* gcc-interface/decl.cc (gnat_to_gnu_field): Use unpacked type
as the debug type for packed fields.

for  gcc/testsuite/ChangeLog

* gnat.dg/bias1.adb: Count occurrences of -7.*DW_AT_GNU_bias.

13 months ago[libstdc++] drop workaround for clang<=7
Alexandre Oliva [Wed, 12 Jun 2024 03:16:20 +0000 (00:16 -0300)] 
[libstdc++] drop workaround for clang<=7

In response to a request in the review of the patch that introduced
_GLIBCXX_CLANG, this patch removes from std/variant an obsolete
workaround for clang 7-.

for  libstdc++-v3/ChangeLog

* include/std/variant: Drop obsolete workaround.

13 months agoDaily bump.
GCC Administrator [Wed, 12 Jun 2024 00:18:21 +0000 (00:18 +0000)] 
Daily bump.

13 months agoFix ICE in rtl check due to CONST_WIDE_INT in CONST_VECTOR_DUPLICATE_P
liuhongt [Tue, 11 Jun 2024 02:23:27 +0000 (10:23 +0800)] 
Fix ICE in rtl check due to CONST_WIDE_INT in CONST_VECTOR_DUPLICATE_P

The patch add extra check to make sure the component of CONST_VECTOR
is CONST_INT_P.

gcc/ChangeLog:

PR target/115384
* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
Only do the simplification of (AND (ASHIFTRT A imm) mask)
to (LSHIFTRT A imm) when the component of const_vector is
CONST_INT_P.

gcc/testsuite/ChangeLog:

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

13 months agoc: Add -std=c2y, -std=gnu2y, -Wc23-c2y-compat, C2Y _Generic with type operand
Joseph Myers [Tue, 11 Jun 2024 23:00:04 +0000 (23:00 +0000)] 
c: Add -std=c2y, -std=gnu2y, -Wc23-c2y-compat, C2Y _Generic with type operand

The first new C2Y feature, _Generic where the controlling operand is a
type name rather than an expression (as defined in N3260), was voted
into C2Y today.  (In particular, this form of _Generic allows
distinguishing qualified and unqualified versions of a type.)  This
feature also includes allowing the generic associations to specify
incomplete and function types.

Add this feature to GCC, along with the -std=c2y, -std=gnu2y and
-Wc23-c2y-compat options to control when and how it is diagnosed.  As
usual, the feature is allowed by default in older standards modes,
subject to diagnosis with -pedantic, -pedantic-errors or
-Wc23-c2y-compat.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc/
* doc/cpp.texi (__STDC_VERSION__): Document C2Y handling.
* doc/invoke.texi (-Wc23-c2y-compat, -std=c2y, -std=gnu2y):
Document options.
(-std=gnu23): Update documentation.
* doc/standards.texi (C Language): Document C2Y.  Update C23
description.
* config/rl78/rl78.cc (rl78_option_override): Handle "GNU C2Y"
language name.
* dwarf2out.cc (highest_c_language, gen_compile_unit_die):
Likewise.

gcc/c-family/
* c-common.cc (flag_isoc2y): New.
(flag_isoc99, flag_isoc11, flag_isoc23): Update comments.
* c-common.h (flag_isoc2y): New.
(clk_c, flag_isoc23): Update comments.
* c-opts.cc (set_std_c2y): New.
(c_common_handle_option): Handle OPT_std_c2y and OPT_std_gnu2y.
(set_std_c89, set_std_c99, set_std_c11, set_std_c17, set_std_c23):
Set flag_isoc2y.
(set_std_c23): Update comment.
* c.opt (Wc23-c2y-compat, std=c2y, std=gnu2y): New.
* c.opt.urls: Regenerate.

gcc/c/
* c-errors.cc (pedwarn_c23): New.
* c-parser.cc (disable_extension_diagnostics)
(restore_extension_diagnostics): Save and restore
warn_c23_c2y_compat.
(c_parser_generic_selection): Handle type name as controlling
operand.  Allow incomplete and function types subject to
pedwarn_c23 calls.
* c-tree.h (pedwarn_c23): New.

gcc/testsuite/
* gcc.dg/c23-generic-1.c, gcc.dg/c23-generic-2.c,
gcc.dg/c23-generic-3.c, gcc.dg/c23-generic-4.c,
gcc.dg/c2y-generic-1.c, gcc.dg/c2y-generic-2.c,
gcc.dg/c2y-generic-3.c, gcc.dg/gnu2y-generic-1.c: New tests.
* gcc.dg/c23-tag-6.c: Use -pedantic-errors.

libcpp/
* include/cpplib.h (CLK_GNUC2Y, CLK_STDC2Y): New.
* init.cc (lang_defaults): Add GNUC2Y and STDC2Y entries.
(cpp_init_builtins): Define __STDC_VERSION__ to 202500L for GNUC2Y
and STDC2Y.

13 months agodoc: Remove redundant introduction of x86-64
Gerald Pfeifer [Tue, 11 Jun 2024 22:04:09 +0000 (00:04 +0200)] 
doc: Remove redundant introduction of x86-64

The same sentence as in the x86_64-*-solaris2* section is in the
x86_64-*-* section directly above.

gcc:
PR target/69374
* doc/install.texi (Specific) <x86_64-*-solaris2*>: Remove
redundant introduction of x86-64.

13 months agoFix building JIT with musl libc [PR115442]
Andrew Pinski [Tue, 11 Jun 2024 19:30:01 +0000 (12:30 -0700)] 
Fix building JIT with musl libc [PR115442]

Just like r13-6662-g0e6f87835ccabf but this time for jit/jit-recording.cc.

Pushed as obvious after a quick build to make sure jit still builds.

gcc/jit/ChangeLog:

PR jit/115442
* jit-recording.cc: Define INCLUDE_SSTREAM before including
system.h and don't directly incldue sstream.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
13 months agovect: Merge loop mask and cond_op mask in fold-left reduction [PR115382].
Robin Dapp [Fri, 7 Jun 2024 12:36:41 +0000 (14:36 +0200)] 
vect: Merge loop mask and cond_op mask in fold-left reduction [PR115382].

Currently we discard the cond-op mask when the loop is fully masked
which causes wrong code in
gcc.dg/vect/vect-cond-reduc-in-order-2-signed-zero.c
when compiled with
-O3 -march=cascadelake --param vect-partial-vector-usage=2.

This patch ANDs both masks.

gcc/ChangeLog:

PR tree-optimization/115382

* tree-vect-loop.cc (vectorize_fold_left_reduction): Use
prepare_vec_mask.
* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
Remove static of prepare_vec_mask.
* tree-vectorizer.h (prepare_vec_mask): Export.

13 months agoRISC-V: Add Zalrsc amo-op patterns
Patrick O'Neill [Thu, 8 Feb 2024 00:30:30 +0000 (16:30 -0800)] 
RISC-V: Add Zalrsc amo-op patterns

All amo<op> patterns can be represented with lrsc sequences.
Add these patterns as a fallback when Zaamo is not enabled.

gcc/ChangeLog:

* config/riscv/sync.md (atomic_<atomic_optab><mode>): New expand pattern.
(amo_atomic_<atomic_optab><mode>): Rename amo pattern.
(atomic_fetch_<atomic_optab><mode>): New lrsc sequence pattern.
(lrsc_atomic_<atomic_optab><mode>): New expand pattern.
(amo_atomic_fetch_<atomic_optab><mode>): Rename amo pattern.
(lrsc_atomic_fetch_<atomic_optab><mode>): New lrsc sequence pattern.
(atomic_exchange<mode>): New expand pattern.
(amo_atomic_exchange<mode>): Rename amo pattern.
(lrsc_atomic_exchange<mode>): New lrsc sequence pattern.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/amo-zaamo-preferred-over-zalrsc.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-1.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-2.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-3.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-4.c: New test.
* gcc.target/riscv/amo-zalrsc-amo-add-5.c: New test.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
13 months agoRISC-V: Add Zalrsc and Zaamo testsuite support
Patrick O'Neill [Mon, 10 Jun 2024 21:12:40 +0000 (14:12 -0700)] 
RISC-V: Add Zalrsc and Zaamo testsuite support

Convert testsuite infrastructure to use Zalrsc and Zaamo rather than A.

gcc/ChangeLog:

* doc/sourcebuild.texi: Add docs for atomic extension testsuite infra.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/amo-table-a-6-amo-add-1.c: Use Zaamo rather than A.
* gcc.target/riscv/amo-table-a-6-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-a-6-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-a-6-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-a-6-amo-add-5.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-1.c: Use Zalrsc rather
than A.
* gcc.target/riscv/amo-table-a-6-compare-exchange-2.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-3.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-4.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-5.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-6.c: Ditto.
* gcc.target/riscv/amo-table-a-6-compare-exchange-7.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-1.c: Use Zaamo rather
than A.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-a-6-subword-amo-add-5.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-1.c: Add Zaamo option.
* gcc.target/riscv/amo-table-ztso-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-ztso-amo-add-5.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-1.c: Use Zalrsc rather
than A.
* gcc.target/riscv/amo-table-ztso-compare-exchange-2.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-3.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-4.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-5.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-6.c: Ditto.
* gcc.target/riscv/amo-table-ztso-compare-exchange-7.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-1.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-2.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-3.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-4.c: Ditto.
* gcc.target/riscv/amo-table-ztso-subword-amo-add-5.c: Ditto.
* lib/target-supports.exp: Add testsuite infrastructure support for
Zaamo and Zalrsc.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
13 months agoRISC-V: Add basic Zaamo and Zalrsc support
Edwin Lu [Thu, 8 Feb 2024 00:30:28 +0000 (16:30 -0800)] 
RISC-V: Add basic Zaamo and Zalrsc support

There is a proposal to split the A extension into two parts: Zaamo and Zalrsc.
This patch adds basic support by making the A extension imply Zaamo and
Zalrsc.

Proposal: https://github.com/riscv/riscv-zaamo-zalrsc/tags

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: Add Zaamo and Zalrsc.
* config/riscv/arch-canonicalize: Make A imply Zaamo and Zalrsc.
* config/riscv/riscv.opt: Add Zaamo and Zalrsc
* config/riscv/sync.md: Convert TARGET_ATOMIC to TARGET_ZAAMO and
TARGET_ZALRSC.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/attribute-15.c: Adjust expected arch string.
* gcc.target/riscv/attribute-16.c: Ditto.
* gcc.target/riscv/attribute-17.c: Ditto.
* gcc.target/riscv/attribute-18.c: Ditto.
* gcc.target/riscv/pr110696.c: Ditto.
* gcc.target/riscv/rvv/base/pr114352-1.c: Ditto.
* gcc.target/riscv/rvv/base/pr114352-3.c: Ditto.

Signed-off-by: Edwin Lu <ewlu@rivosinc.com>
Co-authored-by: Patrick O'Neill <patrick@rivosinc.com>
13 months agoi386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600]
Uros Bizjak [Tue, 11 Jun 2024 14:00:31 +0000 (16:00 +0200)] 
i386: Use CMOV in .SAT_{ADD|SUB} expansion for TARGET_CMOV [PR112600]

For TARGET_CMOV targets emit insn sequence involving conditonal move.

.SAT_ADD:

        addl    %esi, %edi
        movl    $-1, %eax
        cmovnc  %edi, %eax
        ret

.SAT_SUB:

        subl    %esi, %edi
        movl    $0, %eax
        cmovnc  %edi, %eax
ret

PR target/112600

gcc/ChangeLog:

* config/i386/i386.md (usadd<mode>3): Emit insn sequence
involving conditional move for TARGET_CMOVE targets.
(ussub<mode>3): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112600-a.c: Also scan for cmov.
* gcc.target/i386/pr112600-b.c: Ditto.

13 months agoaarch64: Add vector floating point trunc pattern
Pengxuan Zheng [Sat, 8 Jun 2024 02:52:00 +0000 (19:52 -0700)] 
aarch64: Add vector floating point trunc pattern

This patch is a follow-up of r15-1079-g230d62a2cdd16c to add vector floating
point trunc pattern for V2DF->V2SF and V4SF->V4HF conversions by renaming the
existing aarch64_float_truncate_lo_<mode><vczle><vczbe> pattern to the standard
optab one, i.e., trunc<Vwide><mode>2<vczle><vczbe>. This allows the vectorizer
to vectorize certain floating point narrowing operations for the aarch64 target.

gcc/ChangeLog:

* config/aarch64/aarch64-builtins.cc (VAR1): Remap float_truncate_lo_
builtin codes to standard optab ones.
* config/aarch64/aarch64-simd.md (aarch64_float_truncate_lo_<mode><vczle><vczbe>):
Rename to...
(trunc<Vwide><mode>2<vczle><vczbe>): ... This.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/trunc-vec.c: New test.

Signed-off-by: Pengxuan Zheng <quic_pzheng@quicinc.com>
13 months agoC++: Support constexpr strings for asm statements
Andi Kleen [Wed, 24 Jan 2024 12:27:13 +0000 (04:27 -0800)] 
C++: Support constexpr strings for asm statements

Some programing styles use a lot of inline assembler, and it is common
to use very complex preprocessor macros to generate the assembler
strings for the asm statements. In C++ there would be a typesafe alternative
using templates and constexpr to generate the assembler strings, but
unfortunately the asm statement requires plain string literals, so this
doesn't work.

This patch modifies the C++ parser to accept strings generated by
constexpr instead of just plain strings. This requires new syntax
because e.g. asm("..." : "r" (expr)) would be ambigious with a function
call. I chose () to make it unique. For example now you can write

constexpr const char *genasm() { return "insn"; }
constexpr const char *genconstraint() { return "r"; }

asm(genasm() :: (genconstraint()) (input));

The constexpr strings are allowed for the asm template, the
constraints and the clobbers (every time current asm accepts a string)

This version allows the same constexprs as C++26 static_assert,
following Jakub's suggestion.

The drawback of this scheme is that the constexpr doesn't have
full control over the input/output/clobber lists, but that can be
usually handled with a switch statement.  One could imagine
more flexible ways to handle that, for example supporting constexpr
vectors for the clobber list, or similar. But even without
that it is already useful.

Bootstrapped and full test on x86_64-linux.

gcc/c-family/ChangeLog:

* c-cppbuiltin.cc (c_cpp_builtins): Define __GXX_CONSTEXPR_ASM__

gcc/cp/ChangeLog:

* parser.cc (cp_parser_asm_string_expression): New function
to handle constexpr strings for asm.
(cp_parser_asm_definition): Use cp_parser_asm_string_expression.
(cp_parser_yield_expression): Dito.
(cp_parser_asm_specification_opt): Dito.
(cp_parser_asm_operand_list): Dito.
(cp_parser_asm_clobber_list): Dito.

gcc/ChangeLog:

* doc/extend.texi: Document constexpr asm.

gcc/testsuite/ChangeLog:

* g++.dg/ext/asm11.C: Adjust to new error message.
* g++.dg/ext/asm9.C: Dito.
* g++.dg/parse/asm1.C: Dito.
* g++.dg/parse/asm2.C: Dito.
* g++.dg/parse/asm3.C: Dito.
* g++.dg/cpp1z/constexpr-asm-1.C: New test.
* g++.dg/cpp1z/constexpr-asm-2.C: New test.
* g++.dg/cpp1z/constexpr-asm-3.C: New test.

13 months agoFactor out static_assert constexpr string extraction for reuse
Andi Kleen [Mon, 6 May 2024 05:40:20 +0000 (22:40 -0700)] 
Factor out static_assert constexpr string extraction for reuse

The only semantics changes are slightly more vague error messages
to generalize.

gcc/cp/ChangeLog:

* cp-tree.h (class cexpr_str): Add.
* semantics.cc (finish_static_assert): Convert to use cexpr_str.
(cexpr_str::type_check): Extract constexpr string code to here.
(cexpr_str::extract): ... and here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/static_assert1.C: Update to new error message.
* g++.dg/cpp0x/udlit-error1.C: Dito.

13 months agoscev query mismatch message
Andrew MacLeod [Thu, 30 May 2024 13:40:46 +0000 (09:40 -0400)] 
scev query mismatch message

Add a message to the listing if SCEV is not invoked because of a
range_query mismatch

* gimple-range-fold.cc (range_of_ssa_name_with_loop_info): Issue a
message if SCEV is not invoked due to a mismatch.

13 months agolibstdc++: Add test for chrono::leap_seconds ostream insertion
Jonathan Wakely [Mon, 10 Jun 2024 20:10:29 +0000 (21:10 +0100)] 
libstdc++: Add test for chrono::leap_seconds ostream insertion

Also add a comment to the three-way comparison oeprator for
chrono::leap_seconds, noting the deviation from the spec (which is
functionally equivalent). What we implement is the originally proposed
resolution to LWG 3383, which should compile slightly more efficiently
than the final accepted resolution.

libstdc++-v3/ChangeLog:

* include/std/chrono (leap_seconds): Add comment.
* testsuite/std/time/leap_seconds/io.cc: New test.

13 months agorust: Do not link with libdl and libpthread unconditionally
Arthur Cohen [Fri, 12 Apr 2024 11:52:18 +0000 (13:52 +0200)] 
rust: Do not link with libdl and libpthread unconditionally

ChangeLog:

* Makefile.tpl: Add CRAB1_LIBS variable.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check if -ldl and -lpthread are needed, and if so, add
them to CRAB1_LIBS.

gcc/rust/ChangeLog:

* Make-lang.in: Remove overazealous LIBS = -ldl -lpthread line, link
crab1 against CRAB1_LIBS.

13 months agoPR modula2/114529 Avoid ODR violations in bootstrap translated sources
Gaius Mulley [Tue, 11 Jun 2024 09:01:12 +0000 (10:01 +0100)] 
PR modula2/114529 Avoid ODR violations in bootstrap translated sources

This patch changes the bootstrap tool mc to avoid redefining any data
types and therefore preventing ODR violations.  All exported opaque type
usages are implemented as void *.  Local opaque type usages (static
functions containing opaque type parameters) use the full declaration.
mc casts usages between void * and full opaque type as necessary.
The --extended-opaque option in mc has been disabled, as this generated
ODR violations.  The extended-opaque option inlined all declarations in
the translated implementation module.  As this is no longer used there
is now a .h file for each .def file and a .cc file for every .mod file.
This results in more Makefile rules for the ppg tool in Make-maintainer.in.

gcc/m2/ChangeLog:

PR modula2/114529
* Make-lang.in (MC_EXTENDED_OPAQUE): Assign to nothing.
* Make-maintainer.in (mc-basetest): New rule.
(mc-devel-basetest): New rule.
(mc-clean): Remove mc.
(m2/mc-boot-gen/$(SRC_PREFIX)decl.cc): Replace --extended-opaque
with $(EXTENDED_OPAQUE).
(PG-SRC): Move define before generic rules.
(PGE-DEF): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)%.h): New rule.
(m2/gm2-ppg-boot/$(SRC_PREFIX)libc.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)mcrts.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)UnixArgs.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)Selective.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)termios.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)SysExceptions.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)ldtoa.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)wrapc.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)SYSTEM.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)errno.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)M2RTS.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)SymbolKey.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)SymbolKey.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)NameKey.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)NameKey.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)Lists.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)Lists.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)Output.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)bnflex.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)bnflex.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)RTco.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)RTentity.h): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)RTco.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)RTentity.o): Ditto.
(m2/gm2-ppg-boot/$(SRC_PREFIX)%.o): Ditto.
(m2/ppg$(exeext)): Ditto.
(m2/gm2-ppg-boot/main.o): Ditto.
(m2/gm2-auto): Ditto.
(c-family/m2pp.o): Ditto.
(BUILD-BOOT-PG-H): Correct macro definition.
(m2/gm2-pg-boot/$(SRC_PREFIX)%.h): New rule.
(m2/gm2-pg-boot/$(SRC_PREFIX)NameKey.h): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)NameKey.o): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)Lists.h): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)Lists.o): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)Output.h): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)Output.o): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)bnflex.h): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)bnflex.o): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)RTco.h): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)RTentity.h): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)RTco.o): Ditto.
(m2/gm2-pg-boot/$(SRC_PREFIX)RTentity.o): Ditto.
(BUILD-BOOT-PGE-H): Correct macro definition.
(m2/gm2-pge-boot/$(SRC_PREFIX)SymbolKey.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)SymbolKey.o): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)NameKey.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)NameKey.o): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)Lists.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)Lists.o): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)Output.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)Output.o): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)bnflex.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)bnflex.o): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)RTco.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)RTentity.h): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)RTco.o): Ditto.
(m2/gm2-pge-boot/$(SRC_PREFIX)RTentity.o): Ditto.
(mc-basetest): Ditto.
(mc-devel-basetest): Ditto.
* gm2-compiler/M2Options.def (SetM2Dump): Add BOOLEAN return.
* gm2-compiler/M2Quads.def (BuildAlignment): Add tokno parameter.
(BuildBitLength): Ditto.
* gm2-compiler/P3Build.bnf (ByteAlignment): Move tokpos assignment
to the start of the block.
* gm2-compiler/PCBuild.bnf (ConstSetOrQualidentOrFunction): Ditto.
(SetOrDesignatorOrFunction): Ditto.
* gm2-compiler/PHBuild.bnf (ConstSetOrQualidentOrFunction): Ditto.
(SetOrDesignatorOrFunction): Ditto.
(ByteAlignment): Ditto.
* gm2-libs/dtoa.def (dtoa): Change mode to INTEGER.
* gm2-libs/ldtoa.def (ldtoa): Ditto.
* mc-boot-ch/GSYSTEM.c (_M2_SYSTEM_init): Correct parameter list.
(_M2_SYSTEM_fini): Ditto.
* mc-boot-ch/Gdtoa.cc (dtoa_calcsign): Return bool.
(dtoa_dtoa): Return void * and use bool in the fifth parameter.
(_M2_dtoa_init): Correct parameter list.
(_M2_dtoa_fini): Ditto.
* mc-boot-ch/Gerrno.cc (_M2_errno_init): Ditto.
(_M2_errno_fini): Ditto.
* mc-boot-ch/Gldtoa.cc (dtoa_calcsign): Return bool.
(ldtoa_ldtoa): Return void * and use bool in the fifth parameter.
(_M2_ldtoa_init): Correct parameter list.
(_M2_ldtoa_fini): Ditto.
* mc-boot-ch/Glibc.c (tracedb_zresult): New function.
(libc_read): Return size_t and use size_t in parameter three.
(libc_write): Return size_t and use size_t in parameter three.
(libc_printf): Add const to the format specifier.
Change declaration of c to use const.
(libc_snprintf): Add const to the format specifier.
Change declaration of c to use const.
(libc_malloc): Use size_t.
(libc_memcpy): Ditto.
* mc-boot/GASCII.cc: Regenerate.
* mc-boot/GArgs.cc: Ditto.
* mc-boot/GAssertion.cc: Ditto.
* mc-boot/GBreak.cc: Ditto.
* mc-boot/GCmdArgs.cc: Ditto.
* mc-boot/GDebug.cc: Ditto.
* mc-boot/GDynamicStrings.cc: Ditto.
* mc-boot/GEnvironment.cc: Ditto.
* mc-boot/GFIO.cc: Ditto.
* mc-boot/GFormatStrings.cc: Ditto.
* mc-boot/GFpuIO.cc: Ditto.
* mc-boot/GIO.cc: Ditto.
* mc-boot/GIndexing.cc: Ditto.
* mc-boot/GM2Dependent.cc: Ditto.
* mc-boot/GM2EXCEPTION.cc: Ditto.
* mc-boot/GM2RTS.cc: Ditto.
* mc-boot/GMemUtils.cc: Ditto.
* mc-boot/GNumberIO.cc: Ditto.
* mc-boot/GPushBackInput.cc: Ditto.
* mc-boot/GRTExceptions.cc: Ditto.
* mc-boot/GRTint.cc: Ditto.
* mc-boot/GSArgs.cc: Ditto.
* mc-boot/GSFIO.cc: Ditto.
* mc-boot/GStdIO.cc: Ditto.
* mc-boot/GStorage.cc: Ditto.
* mc-boot/GStrCase.cc: Ditto.
* mc-boot/GStrIO.cc: Ditto.
* mc-boot/GStrLib.cc: Ditto.
* mc-boot/GStringConvert.cc: Ditto.
* mc-boot/GSysStorage.cc: Ditto.
* mc-boot/GTimeString.cc: Ditto.
* mc-boot/Galists.cc: Ditto.
* mc-boot/Gdecl.cc: Ditto.
* mc-boot/Gkeyc.cc: Ditto.
* mc-boot/Glists.cc: Ditto.
* mc-boot/GmcComment.cc: Ditto.
* mc-boot/GmcComp.cc: Ditto.
* mc-boot/GmcDebug.cc: Ditto.
* mc-boot/GmcError.cc: Ditto.
* mc-boot/GmcFileName.cc: Ditto.
* mc-boot/GmcLexBuf.cc: Ditto.
* mc-boot/GmcMetaError.cc: Ditto.
* mc-boot/GmcOptions.cc: Ditto.
* mc-boot/GmcPreprocess.cc: Ditto.
* mc-boot/GmcPretty.cc: Ditto.
* mc-boot/GmcPrintf.cc: Ditto.
* mc-boot/GmcQuiet.cc: Ditto.
* mc-boot/GmcReserved.cc: Ditto.
* mc-boot/GmcSearch.cc: Ditto.
* mc-boot/GmcStack.cc: Ditto.
* mc-boot/GmcStream.cc: Ditto.
* mc-boot/Gmcp1.cc: Ditto.
* mc-boot/Gmcp2.cc: Ditto.
* mc-boot/Gmcp3.cc: Ditto.
* mc-boot/Gmcp4.cc: Ditto.
* mc-boot/Gmcp5.cc: Ditto.
* mc-boot/GnameKey.cc: Ditto.
* mc-boot/GsymbolKey.cc: Ditto.
* mc-boot/Gvarargs.cc: Ditto.
* mc-boot/Gwlists.cc: Ditto.
* mc-boot/Gdecl.h: Ditto.
* mc-boot/Gldtoa.h: Ditto.
* mc-boot/Glibc.h: Ditto.
* mc/decl.def (putTypeOpaque): New procedure.
(isTypeOpaque): New procedure function.
* mc/decl.mod (debugOpaque): New constant.
(nodeT): New enumeration field opaquecast.
(node): New record field opaquecastF.
(opaqueCastState): New record.
(opaquecastT): New record.
(typeT): New field isOpaque.
(varT): New field opaqueState.
(arrayT): Ditto.
(varparamT): Ditto.
(paramT): Ditto.
(pointerT): Ditto.
(recordfieldT): Ditto.
(componentrefT): Ditto.
(pointerrefT): Ditto.
(arrayrefT): Ditto.
(procedureT): Ditto.
(proctypeT): Ditto.
(makeType): Initialize field isOpaque.
(makeTypeImp): Initialize field isOpaque.
(putVar): Call initNodeOpaqueCastState.
(putReturnType): Ditto.
(makeProcType): Ditto.
(putProcTypeReturn): Ditto.
(makeVarParameter): Ditto.
(makeNonVarParameter): Ditto.
(makeFuncCall): Ditto.
(putTypeOpaque): New procedure.
(isTypeOpaque): New procedure function.
(doMakeComponentRef): Call initNodeOpaqueCastState.
(makePointerRef): Call initNodeOpaqueCastState.
(doGetFuncType): Call initNodeOpaqueCastState.
(doBinary): Add FALSE parameter to doExprCup.
(doDeRefC): Rewrite.
(doComponentRefC): Call flushOpaque.
(doPointerRefC): Call flushOpaque.
(doArrayRefC): Add const_cast for unbounded array.
(doExprCup): Rewrite.
(doTypeAliasC): Remove.
(isDeclType): New procedure function.
(doEnumerationC): New procedure function.
(doParamTypeEmit): Ditto.
(doParamTypeNameModifier): Ditto.
(initOpaqueCastState): Ditto.
(initNodeOpaqueCastState): Ditto.
(setOpaqueCastState): Ditto.
(setNodeOpaqueVoidStar): Ditto.
(nodeUsesOpaque): Ditto.
(getNodeOpaqueVoidStar): Ditto.
(getOpaqueFlushNecessary): Ditto.
(makeOpaqueCast): Ditto.
(flushOpaque): Ditto.
(castOpaque): Ditto.
(isTypeOpaqueDefImp): Ditto.
(isParamVoidStar): Ditto.
(isRefVoidStar): Ditto.
(isReturnVoidStar): Ditto.
(isVarVoidStar): Ditto.
(initNodeOpaqueState): Ditto.
(assignNodeOpaqueCastState): Ditto.
(assignNodeOpaqueCastFalse): Ditto.
(dumpOpaqueState): Ditto.
(doProcTypeC): Rewrite.
(isDeclInImp): New procedure function.
(doTypeNameModifier): Ditto.
(doTypeC): Emit typedef if enum is declared in this module.
(doCompletePartialProcType): Rewrite.
(outputCompletePartialProcType): New procedure.
(doOpaqueModifier): Ditto.
(doVarC): Ditto.
(doProcedureHeadingC): Add opaque modifier to return type if
necessary.
(doReturnC): Cast opaque type for return if necessary.
(forceCastOpaque): New procedure.
(forceReintCastOpaque): New procedure.
(doUnConstCastUnbounded): New procedure.
(doAssignmentC): Cast opaque for both des and expr if necessary.
(doAdrExprC): Use static_cast for void * casting.
(doFuncVarParam): New procedure.
(doFuncParamC): Rewrite.
(doAdrArgC): Rewrite.
(getFunction): New procedure function.
(stop): Rename to ...
(localstop): ... this.
(dupFunccall): Call assignNodeOpaqueCastState.
(dbg): Rewrite.
(addDone): Rewrite.
(addDoneDef): Do not add opaque types to the doneQ when declared in
the definition module.
* mc/mc.flex (openSource): Return bool.
(_M2_mcflex_init): Correct parameter list.
(_M2_mcflex_fini): Ditto.
* mc/mcComment.h (stdbool.h): Include.
(mcComment_initComment): Change unsigned int to bool.
* mc/mcOptions.mod (handleOption): Disable --extended-opaque
and issue warning.
* mc/mcp1.bnf (DefTypeDeclaration): Call putTypeOpaque.

gcc/testsuite/ChangeLog:

PR modula2/114529
* gm2/base-lang/pass/SYSTEM.def: New test.
* gm2/base-lang/pass/base-lang-test.sh: New test.
* gm2/base-lang/pass/globalproctype.def: New test.
* gm2/base-lang/pass/globalproctype.mod: New test.
* gm2/base-lang/pass/globalvar.def: New test.
* gm2/base-lang/pass/globalvar.mod: New test.
* gm2/base-lang/pass/globalvarassign.def: New test.
* gm2/base-lang/pass/globalvarassign.mod: New test.
* gm2/base-lang/pass/localproctype.def: New test.
* gm2/base-lang/pass/localproctype.mod: New test.
* gm2/base-lang/pass/localvar.def: New test.
* gm2/base-lang/pass/localvar.mod: New test.
* gm2/base-lang/pass/localvarassign.def: New test.
* gm2/base-lang/pass/localvarassign.mod: New test.
* gm2/base-lang/pass/opaquefield.def: New test.
* gm2/base-lang/pass/opaquefield.mod: New test.
* gm2/base-lang/pass/opaquenew.def: New test.
* gm2/base-lang/pass/opaquenew.mod: New test.
* gm2/base-lang/pass/opaqueparam.def: New test.
* gm2/base-lang/pass/opaqueparam.mod: New test.
* gm2/base-lang/pass/opaquestr.def: New test.
* gm2/base-lang/pass/opaqueuse.def: New test.
* gm2/base-lang/pass/opaqueuse.mod: New test.
* gm2/base-lang/pass/opaqueusestr.def: New test.
* gm2/base-lang/pass/opaqueusestr.mod: New test.
* gm2/base-lang/pass/opaquevariant.def: New test.
* gm2/base-lang/pass/opaquevariant.mod: New test.
* gm2/base-lang/pass/opaquevarparam.def: New test.
* gm2/base-lang/pass/opaquevarparam.mod: New test.
* gm2/base-lang/pass/simplelist.def: New test.
* gm2/base-lang/pass/simplelist.mod: New test.
* gm2/base-lang/pass/simplelistiter.def: New test.
* gm2/base-lang/pass/simplelistiter.mod: New test.
* gm2/base-lang/pass/simpleopaque.def: New test.
* gm2/base-lang/pass/simpleopaque.mod: New test.
* gm2/base-lang/pass/straddress.def: New test.
* gm2/base-lang/pass/straddress.mod: New test.
* gm2/base-lang/pass/straddressexport.def: New test.
* gm2/base-lang/pass/straddressexport.mod: New test.
* gm2/base-lang/pass/unboundedarray.def: New test.
* gm2/base-lang/pass/unboundedarray.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
13 months agoi386: PR target/115397: AVX512 ternlog vs. -m32 -fPIC constant pool.
Roger Sayle [Tue, 11 Jun 2024 08:31:34 +0000 (09:31 +0100)] 
i386: PR target/115397: AVX512 ternlog vs. -m32 -fPIC constant pool.

This patch fixes PR target/115397, a recent regression caused by my
ternlog patch that results in an ICE (building numpy) with -m32 -fPIC.
The problem is that ix86_broadcast_from_constant, which calls
get_pool_constant, doesn't handle the UNSPEC_GOTOFF that's created by
calling validize_mem when using -fPIC on i686.  The logic here is a bit
convoluted (and my future patches will clean some of this up), but the
simplest fix is to call ix86_broadcast_from_constant between the calls
to force_const_mem and the call to validize_mem.

Perhaps a better solution might be to call targetm.delegitimize_address
from the middle-end's get_pool_constant, but ultimately the best approach
would be to not place things in the constant pool if we don't need to.
My plans to move (broadcast) constant handling from expand to split1
should simplify this.

2024-06-11  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/115397
* config/i386/i386-expand.cc (ix86_expand_ternlog): Move call to
ix86_broadcast_from_constant before call to validize_mem, but after
call to force_const_mem.

gcc/testsuite/ChangeLog
PR target/115397
* gcc.target/i386/pr115397.c: New test case.

13 months agoRISC-V: Implement .SAT_SUB for unsigned vector int
Pan Li [Tue, 11 Jun 2024 03:04:22 +0000 (11:04 +0800)] 
RISC-V: Implement .SAT_SUB for unsigned vector int

As the middle support of .SAT_SUB committed,  implement the unsigned
vector int of .SAT_SUB for the riscv backend.  Consider below example
code:

void __attribute__((noinline))                                       \
vec_sat_u_sub_##T##_fmt_1 (T *out, T *op_1, T *op_2, unsigned limit) \
{                                                                    \
  unsigned i;                                                        \
  for (i = 0; i < limit; i++)                                        \
    {                                                                \
      T x = op_1[i];                                                 \
      T y = op_2[i];                                                 \
      out[i] = (x - y) & (-(T)(x >= y));                             \
    }                                                                \
}

Before this patch:
  ...
  vsetvli a5,a3,e64,m1,ta,mu
  slli    a4,a5,3
  vle64.v v2,0(a1)
  vle64.v v1,0(a2)
  vmsgeu.vv       v0,v2,v1
  vmv1r.v v3,v4
  vsub.vv v3,v2,v1,v0.t
  vse64.v v3,0(a0)
  ...

After this patch:
  ...
  vsetvli a5,a3,e64,m1,ta,ma
  slli    a4,a5,3
  vle64.v v1,0(a1)
  vle64.v v2,0(a2)
  vssubu.vv       v1,v1,v2
  vse64.v v1,0(a0)
  ...

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

gcc/ChangeLog:

* config/riscv/autovec.md (ussub<mode>3): Add new pattern impl
for the unsigned vector modes.
* config/riscv/riscv-protos.h (expand_vec_ussub): Add new func
decl to expand .SAT_SUB for vector mode.
* config/riscv/riscv-v.cc (emit_vec_saddu): Add new func impl
to expand .SAT_SUB for vector mode.
(emit_vec_binary_alu): Add new helper func to emit binary alu.
(expand_vec_ussub): Leverage above helper func.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add helper macros for test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-1.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-2.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-3.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-4.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-1.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-2.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-3.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_sub-run-4.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
13 months agofixincludes: bypass the math_exception fix on __cplusplus
Francois-Xavier Coudert [Fri, 7 Jun 2024 09:05:39 +0000 (11:05 +0200)] 
fixincludes: bypass the math_exception fix on __cplusplus

fixincludes/ChangeLog:

* fixincl.x: Regenerate.
* inclhack.def (math_exception): Bypass on __cplusplus.
* tests/base/math.h: Regenerate.

13 months ago[committed] [RISC-V] Drop dead round_32 test
Jeff Law [Tue, 11 Jun 2024 04:39:40 +0000 (22:39 -0600)] 
[committed] [RISC-V] Drop dead round_32 test

This test is no longer useful.  It doesn't test what it was originally intended
to test and there's really no way to recover it sanely.

We agreed in the patchwork meeting last week that if we want to test Zfa that
we'll write a new test for that.  Similarly if we want to do deeper testing of
the non-Zfa sequences in this space that we'd write new tests for those as well
(execution tests in particular).

So dropping this test.

gcc/testsuite
* gcc.target/riscv/round_32.c: Delete.

13 months agoDaily bump.
GCC Administrator [Tue, 11 Jun 2024 00:18:01 +0000 (00:18 +0000)] 
Daily bump.

13 months agomodula2: Fix typos, grammar, and a link
Gerald Pfeifer [Mon, 10 Jun 2024 22:32:53 +0000 (00:32 +0200)] 
modula2: Fix typos, grammar, and a link

gcc:
* doc/gm2.texi (Documentation): Fix typos, grammar, and a link.

13 months agoMove array_bounds warnings into a separate pass.
Andrew MacLeod [Wed, 5 Jun 2024 19:12:27 +0000 (15:12 -0400)] 
Move array_bounds warnings into a separate pass.

Array bounds checking is currently tied to VRP.  This causes issues with
using laternate VRP algorithms as well as experimenting with moving
the location of the warnings later.   This moves it to its own pass
and cleans up the vrp_pass object.

* gimple-array-bounds.cc (array_bounds_checker::array_bounds_checker):
Always use current range_query.
(pass_data_array_bounds): New.
(pass_array_bounds): New.
(make_pass_array_bounds): New.
* gimple-array-bounds.h  (array_bounds_checker): Adjust prototype.
* passes.def (pass_array_bounds): New.  Add after VRP1.
* timevar.def (TV_TREE_ARRAY_BOUNDS): New timevar.
* tree-pass.h (make_pass_array_bounds): Add prototype.
* tree-vrp.cc (execute_ranger_vrp): Remove warning param and do
not invoke array bounds warning pass.
(pass_vrp::pass_vrp): Adjust params.
(pass_vrp::close): Adjust parameters.
(pass_vrp::warn_array_bounds_p): Remove.
(make_pass_vrp): Remove warning param.
(make_pass_early_vrp): Remove warning param.
(make_pass_fast_vrp): Remove warning param.

13 months ago[to-be-committed] [RISC-V] Use bext for extracting a bit into a SImode object
Raphael Zinsly [Mon, 10 Jun 2024 20:16:16 +0000 (14:16 -0600)] 
[to-be-committed] [RISC-V] Use bext for extracting a bit into a SImode object

bext is defined as (src >> n) & 1.  With that formulation, particularly the
"&1" means the result is implicitly zero extended.  So we can safely use it on
SI objects for rv64 without the need to do any explicit extension.

This patch adds the obvious pattern and a few testcases.   I think one of the
tests is derived from coremark, the other two from spec2017.

This has churned through Ventana's CI system repeatedly since it was first
written.  Assuming pre-commit CI doesn't complain, I'll commit it on Raphael's
behalf later today or Monday.

gcc/
* config/riscv/bitmanip.md (*bextdisi): New pattern.

gcc/testsuite

* gcc.target/riscv/zbs-ext.c: New test.

13 months ago[PATCH v1] Widening-Mul: Fix one ICE of gcall insertion for PHI match
Pan Li [Mon, 10 Jun 2024 20:13:38 +0000 (14:13 -0600)] 
[PATCH v1] Widening-Mul: Fix one ICE of gcall insertion for PHI match

When enabled the PHI handing for COND_EXPR,  we need to insert the gcall
to replace the PHI node.  Unfortunately,  I made a mistake that insert
the gcall to before the last stmt of the bb.  See below gimple,  the PHI
is located at no.1 but we insert the gcall (aka no.9) to the end of
the bb.  Then the use of _9 in no.2 will have no def and will trigger
ICE when verify_ssa.

  1. # _9 = PHI <_3(4), 18446744073709551615(3)> // The PHI node to be deleted.
  2. prephitmp_36 = (char *) _9;
  3. buf.write_base = string_13(D);
  4. buf.write_ptr = string_13(D);
  5. buf.write_end = prephitmp_36;
  6. buf.written = 0;
  7. buf.mode = 3;
  8. _7 = buf.write_end;
  9. _9 = .SAT_ADD (string.0_2, maxlen_15(D));   // Insert gcall to last bb by mistake

This patch would like to insert the gcall to before the start of the bb
stmt.  To ensure the possible use of PHI_result will have a def exists.
After this patch the above gimple will be:

  0. _9 = .SAT_ADD (string.0_2, maxlen_15(D));   // Insert gcall to start bb by mistake
  1. # _9 = PHI <_3(4), 18446744073709551615(3)> // The PHI node to be deleted.
  2. prephitmp_36 = (char *) _9;
  3. buf.write_base = string_13(D);
  4. buf.write_ptr = string_13(D);
  5. buf.write_end = prephitmp_36;
  6. buf.written = 0;
  7. buf.mode = 3;
  8. _7 = buf.write_end;

The below test suites are passed for this patch:
* The rv64gcv fully regression test with newlib.
* The rv64gcv build with glibc.
* The x86 regression test with newlib.
* The x86 bootstrap test with newlib.

PR target/115387

gcc/ChangeLog:

* tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children): Take
the gsi of start_bb instead of last_bb.

gcc/testsuite/ChangeLog:

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

13 months agolibstdc++: [_Hashtable] Optimize destructor
François Dumont [Thu, 25 Apr 2024 16:45:59 +0000 (18:45 +0200)] 
libstdc++: [_Hashtable] Optimize destructor

Hashtable destructor do not need to call clear() method that in addition to
destroying all nodes also reset all buckets to nullptr.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (~_Hashtable()): Replace clear call with
a _M_deallocate_nodes call.

13 months agoFix pr115388.c: plain char could be unsigned by default [PR115415]
Andrew Pinski [Mon, 10 Jun 2024 15:23:00 +0000 (08:23 -0700)] 
Fix pr115388.c: plain char could be unsigned by default [PR115415]

This is a simple fix to the testcase as plain `char` could be
unsigned by default on some targets (e.g. aarch64 and powerpc).

Committed as obvious after quick test of the testcase on both aarch64 and x86_64.

gcc/testsuite/ChangeLog:

PR testsuite/115415
PR tree-optimization/115388
* gcc.dg/torture/pr115388.c: Use `signed char` directly instead
of plain `char`.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
13 months ago[to-be-committed] [RISC-V] Use bext for extracting a bit into a SImode object
Raphael Zinsly [Mon, 10 Jun 2024 13:03:00 +0000 (07:03 -0600)] 
[to-be-committed] [RISC-V] Use bext for extracting a bit into a SImode object

bext is defined as (src >> n) & 1.  With that formulation, particularly the
"&1" means the result is implicitly zero extended.  So we can safely use it on
SI objects for rv64 without the need to do any explicit extension.

This patch adds the obvious pattern and a few testcases.   I think one of the
tests is derived from coremark, the other two from spec2017.

This has churned through Ventana's CI system repeatedly since it was first
written.  Assuming pre-commit CI doesn't complain, I'll commit it on Raphael's
behalf later today or Monday.

gcc/
* config/riscv/bitmanip.md (*bextdisi): New pattern.

gcc/testsuite

* gcc.target/riscv/bext-ext.c: New test.

13 months agotree-optimization/115388 - wrong DSE in irreductible regions
Richard Biener [Mon, 10 Jun 2024 09:29:43 +0000 (11:29 +0200)] 
tree-optimization/115388 - wrong DSE in irreductible regions

The following fixes a latent bug in DSE with regarding to variant
array accesses where the code avoiding bogus DSE in loops fails to
handle irreducible regions.  For those we need to make sure backedges
are marked and discover a header for the irreducible region to check
invariantness.

PR tree-optimization/115388
* tree-ssa-dse.cc (dse_classify_store): Handle irreducible
regions.
(pass_dse::execute): Make sure to mark backedges.

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

13 months agoAdd testcase for PR ada/114708
Eric Botcazou [Mon, 10 Jun 2024 10:12:21 +0000 (12:12 +0200)] 
Add testcase for PR ada/114708

gcc/testsuite/
PR ada/114708
* gnat.dg/incomplete8.adb: New test.

13 months agoAdd testcase for PR ada/114398
Eric Botcazou [Mon, 10 Jun 2024 09:44:24 +0000 (11:44 +0200)] 
Add testcase for PR ada/114398

gcc/testsuite/
PR ada/114398
* gnat.dg/access11.adb: New test.

13 months agotree-optimization/115395 - wrong-code with SLP reduction in epilog
Richard Biener [Mon, 10 Jun 2024 08:12:52 +0000 (10:12 +0200)] 
tree-optimization/115395 - wrong-code with SLP reduction in epilog

When we continue a non-SLP reduction from the main loop in the
epilog with a SLP reduction we currently fail to handle an
adjustment by the initial value because that's not a thing with SLP.
As long as we have the possibility to mix SLP and non-SLP we have
to handle it though.

PR tree-optimization/115395
* tree-vect-loop.cc (vect_create_epilog_for_reduction):
Handle STMT_VINFO_REDUC_EPILOGUE_ADJUSTMENT also for SLP
reductions of group_size one.

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

13 months agoada: Add support for No_Implicit_Conditionals to nonbinary modular types
Eric Botcazou [Sat, 20 Apr 2024 08:53:16 +0000 (10:53 +0200)] 
ada: Add support for No_Implicit_Conditionals to nonbinary modular types

The expansion of additive operations for nonbinary modular types implemented
in the front-end and its counterpart in code generators may create branches,
which is not allowed when restriction No_Implicit_Conditionals is in effect.

This changes it to use an explicit Mod operation when the restriction is in
effect, which is assumed not to create such branches.

gcc/ada/

* exp_ch4.adb (Expand_Nonbinary_Modular_Op): Create an explicit Mod
for additive operations if No_Implicit_Conditionals is in effect.
(Expand_Modular_Addition): Likewise.
(Expand_Modular_Subtraction): Likewise.
(Expand_Modular_Op): Always use an unsigned type obtained by calling
Small_Integer_Type_For on the required size.

13 months agoada: Storage_Error in indirect call to function returning limited type
Javier Miranda [Thu, 18 Apr 2024 09:54:22 +0000 (09:54 +0000)] 
ada: Storage_Error in indirect call to function returning limited type

At runtime the code generated by the compiler reports the
exception Storage_Error in an indirect call through an
access-to-subprogram variable that references a function
returning a limited tagged type object.

gcc/ada/

* sem_ch6.adb (Might_Need_BIP_Task_Actuals): Add support
for access-to-subprogram parameter types.
* exp_ch6.adb (Add_Task_Actuals_To_Build_In_Place_Call):
Add dummy BIP parameters to access-to-subprogram types
that may reference a function that has BIP parameters.

13 months agoada: Derived type with convention C must override convention C_Pass_By_Copy
Gary Dismukes [Wed, 17 Apr 2024 23:44:41 +0000 (23:44 +0000)] 
ada: Derived type with convention C must override convention C_Pass_By_Copy

If a type DT is derived from a record type T with convention C_Pass_By_Copy
and explicitly specifies convention C (via aspect or pragma), then type DT
should not be treated as a type with convention C_Pass_By_Copy. Any parameters
of the derived type should be passed by reference rather than by copy. The
compiler was incorrectly inheriting convention C_Pass_By_Copy, by inheriting
the flag set on the parent type, but that flag needs to be unset in the case
where the convention is overridden.

gcc/ada/

* sem_prag.adb (Set_Convention_From_Pragma): If the specified convention on
a record type is not C_Pass_By_Copy, then force the C_Pass_By_Copy flag to
False, to ensure that it's overridden.

13 months agoada: Minor code adjustment to "not Present" test
Gary Dismukes [Wed, 17 Apr 2024 21:24:21 +0000 (21:24 +0000)] 
ada: Minor code adjustment to "not Present" test

This is just changing a "not Present (...)" test to "No (...)"
to address a CB complaint from gnatcheck.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Association): Change "not Present"
to "No" in test of Add_Named_Subp.

13 months agoada: For freezing, treat an extension or delta aggregate like a regular aggregate.
Steve Baird [Tue, 16 Apr 2024 22:45:45 +0000 (15:45 -0700)] 
ada: For freezing, treat an extension or delta aggregate like a regular aggregate.

Extend existing special freezing rules for regular aggregates to also apply to
extension and delta aggregates.

gcc/ada/

* freeze.adb
(Should_Freeze_Type.Is_Dispatching_Call_Or_Aggregate): Treat an extension
aggregate or a delta aggregate like a regular aggregate.

13 months agoada: Resolve compilation issues with container aggregates in draft ACATS B tests
Gary Dismukes [Fri, 12 Apr 2024 17:40:34 +0000 (17:40 +0000)] 
ada: Resolve compilation issues with container aggregates in draft ACATS B tests

This change set addresses compilation problems encountered in the draft
versions of the following ACATS B tests for container aggregates:

B435001 (container aggregates with Assign_Indexed)
B435002 (container aggregates with Add_Unnamed)
B435003 (container aggregates with Add_Named)
B435004 (container aggregates with Assign_Indexed and Add_Unnamed)

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Association): In the case of
N_Iterated_Element_Associations that have a key expression, issue
an error if the aggregate type does not have an Add_Named
operation, and include a reference to RM22 4.3.5(24) in the error
message. In the case of an N_Component_Association with a
Defining_Identifer where the "choice" is given by a function call,
in the creation of the iterator_specification associate a copy of
Choice as its Name, and remove the call to
Analyze_Iterator_Specification, which was causing problems with
the reanalysis of function calls originally given in prefixed form
that were transformed into function calls in normal (infix) form.
The iterator_specification will be analyzed later in any case, so
that call should not be done here. Remove the with and use of
Sem_Ch5.

13 months agoada: Missing style check for extra parentheses in operators
Justin Squirek [Thu, 11 Apr 2024 19:43:44 +0000 (19:43 +0000)] 
ada: Missing style check for extra parentheses in operators

This patch fixes an issue in the compiler whereby wrapping an operand
of a boolean operator resulted in a failure to detect whether or not
they were unnecessary for the -gnatyx style checks.

gcc/ada/

* ali.adb (Get_Nat): Remove unnecessary parentheses.
* exp_ch11.adb (Expand_Local_Exception_Handlers): Remove
unnecessary parentheses.
* freeze.adb (Freeze_Entity): Remove unnecessary parentheses.
* lib-list.adb (List): Remove unnecessary parentheses.
* par-ch5.adb (P_Condition): Add extra parentheses checks on
condition operands.
* sem_ch3.adb (Add_Interface_Tag_Components): Remove unnecessary
parentheses.
(Check_Delta_Expression): Remove unnecessary parenthesis.
(Check_Digits_Expression): Remove unnecessary parentheses.
* sem_ch12.adb (Validate_Array_Type_Instance): Remove unnecessary
parentheses.

13 months agoada: Iterator filter ignored on formal loop
Justin Squirek [Thu, 11 Apr 2024 18:30:38 +0000 (18:30 +0000)] 
ada: Iterator filter ignored on formal loop

This patch fixs an issue where iterator filters for formal container and
formal container element loops got silently ignored and remained unexpanded.

gcc/ada/

* exp_ch5.adb (Expand_Formal_Container_Element_Loop): Add
expansion of filter condition.
(Expand_Formal_Container_Loop): Add expansion of filter condition.

13 months agoada: Crash checking accessibility level on private type
Justin Squirek [Thu, 11 Apr 2024 19:13:52 +0000 (19:13 +0000)] 
ada: Crash checking accessibility level on private type

This patch fixes an issue in the compiler whereby calculating a static
accessibility level on a private type with an access discriminant resulted
in a compile time crash when No_Dynamic_Accessibility_Checks is enabled.

gcc/ada/

* accessibility.adb (Accessibility_Level): Use Get_Full_View to
avoid crashes when calculating scope.

13 months agoada: Unreferenced warning on abstract subprogram
Justin Squirek [Thu, 11 Apr 2024 20:51:05 +0000 (20:51 +0000)] 
ada: Unreferenced warning on abstract subprogram

This patch modifies the unreferenced entity warning in the compiler to avoid
noisily warning about unreferenced abstract subprogram.

gcc/ada/

* sem_warn.adb (Warn_On_Unreferenced_Entity): Add a condition to
ignore warnings on unreferenced abstract subprogram.

13 months agoada: Further refine 'Super attribute
Justin Squirek [Thu, 11 Apr 2024 22:05:30 +0000 (22:05 +0000)] 
ada: Further refine 'Super attribute

This patch adds the restriction on 'Super such that it cannot apply to objects
whose parent type is an interface.

gcc/ada/

* sem_attr.adb (Analyze_Attribute): Add check for interface parent
types.

13 months agoada: Fix references to Ada RM in comments
Piotr Trojanek [Tue, 9 Apr 2024 14:49:03 +0000 (16:49 +0200)] 
ada: Fix references to Ada RM in comments

We seem to have a convention of using "RM" in the GNAT comments, not
"Ada RM". Also, the paragraph references by convention should appear
in parentheses, e.g. "8.3(12.3/2)", not "8.3 12.3/2".

gcc/ada/

* einfo.ads, exp_attr.adb, exp_ch4.adb, exp_ch7.adb,
lib-writ.adb, libgnat/a-stbuut.ads, sem_ch13.adb, sem_ch3.adb,
sem_ch7.adb: Use "RM" in comments.

13 months agoada: Tune code related to potentially unevaluated expressions
Piotr Trojanek [Wed, 3 Apr 2024 11:25:04 +0000 (13:25 +0200)] 
ada: Tune code related to potentially unevaluated expressions

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_util.adb
(Immediate_Context_Implies_Is_Potentially_Unevaluated): Use
collective subtypes in membership tests.
(Is_Known_On_Entry): Require all alternatives in a case statement
to return; this change could prevent a recently fixed glitch,
where one of the alternatives relied on the return statement
afterwards (also, the new code is shorter).
* sem_util.ads (Is_Potentially_Unevaluated): Clarify that this
routine applies to Ada 2012.

13 months agoada: Remove streaming facilities from generics for formal containers
Yannick Moy [Thu, 11 Apr 2024 10:30:32 +0000 (12:30 +0200)] 
ada: Remove streaming facilities from generics for formal containers

The dependency on Ada.Streams is problematic for light runtimes.
As these streaming facilities are in fact not used in formal containers,
remove the corresponding dead code.

gcc/ada/

* libgnat/a-chtgfo.adb (Generic_Read, Generic_Write): Remove.
* libgnat/a-chtgfo.ads: Same. Remove dependency on Ada.Streams.

13 months agoada: Fix usage of SetThreadAffinityMask
Ronan Desplanques [Mon, 15 Apr 2024 12:17:13 +0000 (14:17 +0200)] 
ada: Fix usage of SetThreadAffinityMask

This patches fixes the signature of the binding to SetThreadAffinityMask
in the run-time library. It also fixes the error checking after calls
to SetThreadAffinityMask. The previous code behaved as if
SetThreadAffinityMask returned 1 on success, but it in fact returns a
pointer value on success and 0 on failure.

gcc/ada/

* libgnarl/s-taprop__mingw.adb (Set_Task_Affinity): Fix usage of
SetThreadAffinityMask.
* libgnat/s-winext.ads (SetThreadAffinityMask): Fix binding
signature.

13 months agoada: Fix usage of SetThreadIdealProcessor
Ronan Desplanques [Mon, 15 Apr 2024 16:07:49 +0000 (18:07 +0200)] 
ada: Fix usage of SetThreadIdealProcessor

This patches fixes the way the run-time library checks the return
value of SetThreadIdealProcessor.

gcc/ada/

* libgnarl/s-taprop__mingw.adb (Set_Task_Affinity): Fix usage
of SetThreadIdealProcessor.

13 months agoada: Remove incorrect assertion in run-time
Ronan Desplanques [Fri, 12 Apr 2024 13:25:22 +0000 (15:25 +0200)] 
ada: Remove incorrect assertion in run-time

There is a special case of file paths on Windows that are absolute
but don't start with a drive letter: UNC paths. This patch removes
an assertion in System.OS_Lib.Normalize_Pathname that failed to take
this case into account. It also renames a local subprogram of
Normalize_Pathname to make its purpose clearer.

gcc/ada/

* libgnat/s-os_lib.adb (Normalize_Pathname): Remove incorrect
assert statement.
(Missed_Drive_Letter): Rename into...
(Drive_Letter_Omitted): This.

13 months agoada: Fix incorrect lower bound presumption in gnatlink
Ronan Desplanques [Fri, 12 Apr 2024 14:45:08 +0000 (16:45 +0200)] 
ada: Fix incorrect lower bound presumption in gnatlink

This patch fixes a subprogram in gnatlink that incorrectly assumed
that the strings it is passed as arguments all have a lower bound of
1.

gcc/ada/

* gnatlink.adb (Check_File_Name): Fix incorrect assumption.

13 months agoada: Cleanup repeated code in expansion of stream attributes
Piotr Trojanek [Mon, 5 Feb 2024 18:41:50 +0000 (19:41 +0100)] 
ada: Cleanup repeated code in expansion of stream attributes

In expansion of various attributes, in particular for the Input/Output
and Read/Write attributes, we can use constants that are already used
for expansion of many other attributes.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): Use constants
declared at the beginning of subprogram; tune layout.
* exp_ch3.adb (Predefined_Primitive_Bodies): Tune layout.

13 months agoada: Adjust comments and doc about the new use of restriction No_Streams
Piotr Trojanek [Wed, 3 Apr 2024 11:02:12 +0000 (13:02 +0200)] 
ada: Adjust comments and doc about the new use of restriction No_Streams

Extend code comment; move recently added documentation from pragma
No_Tagged_Streams to restriction No_Streams.

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst
(No_Tagged_Streams): Move documentation.
* doc/gnat_rm/standard_and_implementation_defined_restrictions.rst
(No_Streams): Likewise.
* exp_disp.adb (Make_DT): Extend comment.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

13 months agoada: Skip processing of NUL character for attribute Type_Key
Piotr Trojanek [Wed, 3 Apr 2024 09:51:46 +0000 (11:51 +0200)] 
ada: Skip processing of NUL character for attribute Type_Key

Code cleanup; behavior is unaffected.

gcc/ada/

* sem_attr.adb (Analyze_Attribute): Use fully qualified name
without a NUL, so that it doesn't need to be skipped afterwards.

13 months agoada: Simplify check for type without stream operations
Piotr Trojanek [Tue, 19 Mar 2024 10:22:40 +0000 (11:22 +0100)] 
ada: Simplify check for type without stream operations

Recursive routine Type_Without_Stream_Operation was checking restriction
No_Default_Stream_Attributes at every call, which was confusing and
inefficient.

This routine is only called from the places: Check_Stream_Attribute,
which already checks if this restriction is active, and
Stream_Operation_OK, where we add such a check.

Cleanup related to extending the use of No_Streams restriction.

gcc/ada/

* exp_ch3.adb (Stream_Operation_OK): Check restriction
No_Default_Stream_Attributes before call to
Type_Without_Stream_Operation.
* sem_util.adb (Type_Without_Stream_Operation): Remove static
condition from recursive routine

13 months agoada: Enable inlining for subprograms with multiple return statements
Piotr Trojanek [Fri, 5 Apr 2024 12:22:34 +0000 (14:22 +0200)] 
ada: Enable inlining for subprograms with multiple return statements

With the support for forward GOTO statements in the GNATprove backend,
we can now inline subprograms with multiple return statements in the
frontend.

Also, fix inconsistent source locations in the inlined code, which were
now triggering assertion violations in the code for GNATprove
counterexamples.

gcc/ada/

* inline.adb (Has_Single_Return_In_GNATprove_Mode): Remove.
(Process_Formals): When rewriting an occurrence of a formal
parameter, use location of the occurrence, not of the inlined
call.

13 months agoada: Add switch to disable expansion of assertions in CodePeer mode
Piotr Trojanek [Thu, 11 Apr 2024 08:04:19 +0000 (10:04 +0200)] 
ada: Add switch to disable expansion of assertions in CodePeer mode

A new debug switch -gnatd_k is added, which has only effect in CodePeer
mode. When enabled, assertion expressions are no longer expanded (which
is the default in the CodePeer mode); instead, their expansion needs to
be explicitly enabled by pragma Assertion_Policy.

gcc/ada/

* debug.adb (d_k): Use first available debug switch.
* gnat1drv.adb (Adjust_Global_Switches): If new debug switch is
active then don't expand assertion expressions by default.

13 months agoada: Refactor common code for dynamic and static class-wide preconditions
Piotr Trojanek [Fri, 1 Dec 2023 17:47:01 +0000 (18:47 +0100)] 
ada: Refactor common code for dynamic and static class-wide preconditions

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_ch6.adb (Install_Class_Preconditions_Check): Refactor
common code for checking if precondition fails, since the
difference is only in raising an exception or calling the
Raise_Assert_Failure procedure.

13 months agoada: Cleanup building of error messages for class-wide contracts
Piotr Trojanek [Fri, 1 Dec 2023 16:56:12 +0000 (17:56 +0100)] 
ada: Cleanup building of error messages for class-wide contracts

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_ch6.adb (Build_Dynamic_Check_Helper_Call): Remove unused
iteration over formal parameters.

13 months agoada: Fix handling of aspects CPU and Interrupt_Priority
Piotr Trojanek [Mon, 8 Apr 2024 14:26:02 +0000 (16:26 +0200)] 
ada: Fix handling of aspects CPU and Interrupt_Priority

When resolving aspect expression, aspects CPU and Interrupt_Priority
should be handled like the aspect Priority; in particular, all these
expressions can reference discriminants of the annotated task type.

gcc/ada/

* sem_ch13.adb (Check_Aspect_At_End_Of_Declarations): Make
discriminants visible when analyzing aspect Interrupt_Priority.
(Freeze_Entity_Checks): Likewise.
(Resolve_Aspect_Expressions): Likewise for both aspects CPU and
Interrupt_Priority.

13 months agoada: Remove unnecessary guard against empty list
Piotr Trojanek [Mon, 8 Apr 2024 16:00:49 +0000 (18:00 +0200)] 
ada: Remove unnecessary guard against empty list

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_prag.adb (Report_Extra_Clauses): Remove redundant check
for empty list, because First works also for No_List.

13 months agoada: Refactor checks for Refined_Depends in generic instances
Piotr Trojanek [Mon, 8 Apr 2024 16:00:05 +0000 (18:00 +0200)] 
ada: Refactor checks for Refined_Depends in generic instances

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_prag.adb (Check_Dependency_Clause, Check_Output_States,
Report_Extra_Clauses): Remove multiple checks for being inside
an instance.
(Analyze_Refined_Depends_In_Decl_Part): Add single check for
being inside an instance.

13 months agoada: Refactor checks for Refined_Global in generic instances
Piotr Trojanek [Mon, 8 Apr 2024 11:54:22 +0000 (13:54 +0200)] 
ada: Refactor checks for Refined_Global in generic instances

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_prag.adb (Check_In_Out_States, Check_Input_States,
Check_Output_States, Check_Proof_In_States,
Check_Refined_Global_List, Report_Extra_Constituents,
Report_Missing_Items): Remove multiple checks for being inside
an instance.
(Analyze_Refined_Global_In_Decl_Part): Add single check for
being inside an instance.

13 months agoIBM Z: Fix ICE in expand_perm_as_replicate
Andreas Krebbel [Mon, 10 Jun 2024 07:09:10 +0000 (09:09 +0200)] 
IBM Z: Fix ICE in expand_perm_as_replicate

The current implementation assumes to always be invoked with register
operands. For memory operands we even have an instruction
though (vlrep). With the patch we try this first and only if it fails
force the input into a register and continue.

vec_splats generation fails for single element 128bit types which are
allowed for vec_splat. This is something to sort out with another
patch I guess.

gcc/ChangeLog:

* config/s390/s390.cc (expand_perm_as_replicate): Handle memory
operands.
* config/s390/vx-builtins.md (vec_splats<mode>): Turn into parameterized expander.
(@vec_splats<mode>): New expander.

gcc/testsuite/ChangeLog:

* g++.dg/torture/vshuf-mem.C: New test.

13 months agolibgcc/aarch64: also provide AT_HWCAP2 fallback
Jan Beulich [Mon, 10 Jun 2024 06:47:58 +0000 (08:47 +0200)] 
libgcc/aarch64: also provide AT_HWCAP2 fallback

Much like AT_HWCAP is already provided in case the platform headers
don't have the value (yet).

libgcc/

* config/aarch64/cpuinfo.c: Provide AT_HWCAP2.

13 months agoMIPS/testsuite: add -mno-branch-likely to r10k-cache-barrier-13.c
YunQiang Su [Sat, 8 Jun 2024 08:05:13 +0000 (16:05 +0800)] 
MIPS/testsuite: add -mno-branch-likely to r10k-cache-barrier-13.c

In mips.cc(mips_reorg_process_insns), there is this claim:

    Also delete cache barriers if the last instruction
    was an annulled branch.  INSN will not be speculatively
    executed.

And with -O1 on mips64, we can generate binary code like this,
which fails this test.

gcc/testsuite
* gcc.target/mips/r10k-cache-barrier-13.c: Add -mno-branch-likely
option.

13 months agotree-optimization/115383 - EXTRACT_LAST_REDUCTION with multiple stmt copies
Richard Biener [Fri, 7 Jun 2024 10:15:31 +0000 (12:15 +0200)] 
tree-optimization/115383 - EXTRACT_LAST_REDUCTION with multiple stmt copies

The EXTRACT_LAST_REDUCTION code isn't ready to deal with multiple stmt
copies but SLP no longer checks for this.  The following adjusts
code generation to handle the situation.

PR tree-optimization/115383
* tree-vect-stmts.cc (vectorizable_condition): Handle
generating a chain of .FOLD_EXTRACT_LAST.

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

13 months agoDaily bump.
GCC Administrator [Mon, 10 Jun 2024 00:16:29 +0000 (00:16 +0000)] 
Daily bump.

13 months agoFreeBSD: Stop linking _p libs for -pg as of FreeBSD 14
Andreas Tobler [Sun, 9 Jun 2024 21:18:04 +0000 (23:18 +0200)] 
FreeBSD: Stop linking _p libs for -pg as of FreeBSD 14

As of FreeBSD version 14, FreeBSD no longer provides profiled system
libraries like libc_p and libpthread_p. Stop linking against them if
the FreeBSD major version is 14 or more.

gcc:
* config/freebsd-spec.h: Change fbsd-lib-spec for FreeBSD > 13,
do not link against profiled system libraries if -pg is invoked.
Add a define to note about this change.
* config/aarch64/aarch64-freebsd.h: Use the note to inform if
-pg is invoked on FreeBSD > 13.
* config/arm/freebsd.h: Likewise.
* config/i386/freebsd.h: Likewise.
* config/i386/freebsd64.h: Likewise.
* config/riscv/freebsd.h: Likewise.
* config/rs6000/freebsd64.h: Likewise.
* config/rs6000/sysv4.h: Likeise.

13 months ago[committed] [RISC-V] Fix false-positive uninitialized variable
Jeff Law [Sun, 9 Jun 2024 15:17:55 +0000 (09:17 -0600)] 
[committed] [RISC-V] Fix false-positive uninitialized variable

Andreas noted we were getting an uninit warning after the recent constant
synthesis changes.  Essentially there's no way for the uninit analysis code to
know the first entry in the CODES array is a UNKNOWN which will set X before
its first use.

So trivial initialization with NULL_RTX is the obvious fix.

Pushed to the trunk.

gcc/

* config/riscv/riscv.cc (riscv_move_integer): Initialize "x".

13 months agoi386: Implement .SAT_SUB for unsigned scalar integers [PR112600]
Uros Bizjak [Sun, 9 Jun 2024 10:09:13 +0000 (12:09 +0200)] 
i386: Implement .SAT_SUB for unsigned scalar integers [PR112600]

The following testcase:

unsigned
sub_sat (unsigned x, unsigned y)
{
  unsigned res;
  res = x - y;
  res &= -(x >= y);
  return res;
}

currently compiles (-O2) to:

sub_sat:
        movl    %edi, %edx
        xorl    %eax, %eax
        subl    %esi, %edx
        cmpl    %esi, %edi
        setnb   %al
        negl    %eax
        andl    %edx, %eax
        ret

We can expand through ussub{m}3 optab to use carry flag from the subtraction
and generate code using SBB instruction implementing:

    unsigned res = x - y;
    res &= ~(-(x < y));

sub_sat:
        subl    %esi, %edi
        sbbl    %eax, %eax
        notl    %eax
        andl    %edi, %eax
        ret

PR target/112600

gcc/ChangeLog:

* config/i386/i386.md (ussub<mode>3): New expander.
(sub<mode>_3): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112600-b.c: New test.

13 months agodoc: Remove link to www.amelek.gda.pl/avr/
Gerald Pfeifer [Sun, 9 Jun 2024 07:24:14 +0000 (09:24 +0200)] 
doc: Remove link to www.amelek.gda.pl/avr/

The entire server/site appears gone for a while.

gcc:
* doc/install.texi (avr): Remove link to www.amelek.gda.pl/avr/.

13 months ago[middle-end PATCH] Prefer PLUS over IOR in RTL expansion of multi-word shifts/rotates.
Roger Sayle [Sun, 9 Jun 2024 01:47:08 +0000 (19:47 -0600)] 
[middle-end PATCH] Prefer PLUS over IOR in RTL expansion of multi-word shifts/rotates.

This patch tweaks RTL expansion of multi-word shifts and rotates to use
PLUS rather than IOR for disjunctive operations.  During expansion of
these operations, the middle-end creates RTL like (X<<C1) | (Y>>C2)
where the constants C1 and C2 guarantee that bits don't overlap.
Hence the IOR can be performed by any any_or_plus operation, such as
IOR, XOR or PLUS; for word-size operations where carry chains aren't
an issue these should all be equally fast (single-cycle) instructions.
The benefit of this change is that targets with shift-and-add insns,
like x86's lea, can benefit from the LSHIFT-ADD form.

An example of a backend that benefits is ARC, which is demonstrated
by these two simple functions:

unsigned long long foo(unsigned long long x) { return x<<2; }

which with -O2 is currently compiled to:

foo:    lsr     r2,r0,30
        asl_s   r1,r1,2
        asl_s   r0,r0,2
        j_s.d   [blink]
        or_s    r1,r1,r2

with this patch becomes:

foo:    lsr     r2,r0,30
        add2    r1,r2,r1
        j_s.d   [blink]
        asl_s   r0,r0,2

unsigned long long bar(unsigned long long x) { return (x<<2)|(x>>62); }

which with -O2 is currently compiled to 6 insns + return:

bar:    lsr     r12,r0,30
        asl_s   r3,r1,2
        asl_s   r0,r0,2
        lsr_s   r1,r1,30
        or_s    r0,r0,r1
        j_s.d   [blink]
        or      r1,r12,r3

with this patch becomes 4 insns + return:

bar:    lsr     r3,r1,30
        lsr     r2,r0,30
        add2    r1,r2,r1
        j_s.d   [blink]
        add2    r0,r3,r0

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target_board=unix{-m32}
with no new failures.  Ok for mainline?

gcc/ChangeLog
* expmed.cc (expand_shift_1): Use add_optab instead of ior_optab
to generate PLUS instead or IOR when unioning disjoint bitfields.
* optabs.cc (expand_subword_shift): Likewise.
(expand_binop): Likewise for double-word rotate.

13 months agoDaily bump.
GCC Administrator [Sun, 9 Jun 2024 00:16:23 +0000 (00:16 +0000)] 
Daily bump.

13 months agolibstdc++: Add missing constexpr to __atomic_impl::__clear_padding
Deev Patel [Thu, 6 Jun 2024 10:53:25 +0000 (11:53 +0100)] 
libstdc++: Add missing constexpr to __atomic_impl::__clear_padding

This is called from the std::atomic<floating-point-type> constructor,
which needs to be usable in constant expressions.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (__atomic_impl::__clear_padding):
Add missing constexpr specifier.
* testsuite/29_atomics/atomic_float/constinit.cc: New test.

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
13 months agolibstdc++: Fix std::ranges::iota is not included in numeric [PR108760]
Michael Levine [Fri, 7 Jun 2024 08:54:38 +0000 (09:54 +0100)] 
libstdc++: Fix std::ranges::iota is not included in numeric [PR108760]

Before this patch, using std::ranges::iota required including
<algorithm> when it should have been sufficient to only include
<numeric>.

libstdc++-v3/ChangeLog:

PR libstdc++/108760
* include/bits/ranges_algo.h (ranges::out_value_result):
Move to <bits/ranges_algobase.h>.
(ranges::iota_result, ranges::__iota_fn, ranges::iota): Move to
<numeric>.
* include/bits/ranges_algobase.h (ranges::out_value_result):
Move to here.
* include/std/numeric (ranges::iota_result, ranges::__iota_fn)
(ranges::iota): Move to here.
* testsuite/25_algorithms/iota/1.cc: Renamed to ...
* testsuite/26_numerics/iota/2.cc: ... here.

Signed-off-by: Michael Levine <mlevine55@bloomberg.net>
13 months agolibstdc++: Define __cpp_lib_ranges in <algorithm>
Jonathan Wakely [Fri, 7 Jun 2024 16:44:29 +0000 (17:44 +0100)] 
libstdc++: Define __cpp_lib_ranges in <algorithm>

The __cpp_lib_ranges macro is missing from <algorithm>.

libstdc++-v3/ChangeLog:

* include/std/algorithm: Define __glibcxx_want_ranges.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Check
feature test macro in C++20 mode.

13 months agors6000: Update ELFv2 stack frame comment showing the correct ROP save location
Peter Bergner [Fri, 7 Jun 2024 21:03:08 +0000 (16:03 -0500)] 
rs6000: Update ELFv2 stack frame comment showing the correct ROP save location

The ELFv2 stack frame layout comment in rs6000-logue.cc shows the ROP
hash save slot in the wrong location.  Update the comment to show the
correct ROP hash save location in the frame.

2024-06-07  Peter Bergner  <bergner@linux.ibm.com>

gcc/
* config/rs6000/rs6000-logue.cc (rs6000_stack_info): Update comment.

13 months agoc++: Make *_cast<*> parsing more robust to errors [PR108438]
Simon Martin [Fri, 7 Jun 2024 09:21:07 +0000 (11:21 +0200)] 
c++: Make *_cast<*> parsing more robust to errors [PR108438]

We ICE upon the following when trying to emit a -Wlogical-not-parentheses
warning:

=== cut here ===
template <typename T> T foo (T arg, T& ref, T* ptr) {
  int a = 1;
  return static_cast<T!>(a);
}
=== cut here ===

This patch makes *_cast<*> parsing more robust by skipping to the closing '>'
upon error in the target type.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/108438

gcc/cp/ChangeLog:

* parser.cc (cp_parser_postfix_expression): Use
cp_parser_require_end_of_template_parameter_list to skip to the closing
'>' upon error parsing the target type of *_cast<*> expressions.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash75.C: New test.

13 months agoi386: Implement .SAT_ADD for unsigned scalar integers [PR112600]
Uros Bizjak [Sat, 8 Jun 2024 10:17:11 +0000 (12:17 +0200)] 
i386: Implement .SAT_ADD for unsigned scalar integers [PR112600]

The following testcase:

unsigned
add_sat(unsigned x, unsigned y)
{
    unsigned z;
    return __builtin_add_overflow(x, y, &z) ? -1u : z;
}

currently compiles (-O2) to:

add_sat:
        addl    %esi, %edi
        jc      .L3
        movl    %edi, %eax
        ret
.L3:
        orl     $-1, %eax
        ret

We can expand through usadd{m}3 optab to use carry flag from the addition
and generate branchless code using SBB instruction implementing:

    unsigned res = x + y;
    res |= -(res < x);

add_sat:
        addl    %esi, %edi
        sbbl    %eax, %eax
        orl     %edi, %eax
        ret

PR target/112600

gcc/ChangeLog:

* config/i386/i386.md (usadd<mode>3): New expander.
(x86_mov<mode>cc_0_m1_neg): Use SWI mode iterator.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112600-a.c: New test.

13 months agoRISC-V: Implement .SAT_SUB for unsigned scalar int
Pan Li [Wed, 5 Jun 2024 08:42:05 +0000 (16:42 +0800)] 
RISC-V: Implement .SAT_SUB for unsigned scalar int

As the middle support of .SAT_SUB committed,  implement the unsigned
scalar int of .SAT_SUB for the riscv backend.  Consider below example
code:

T __attribute__((noinline))        \
sat_u_sub_##T##_fmt_1 (T x, T y)   \
{                                  \
  return (x - y) & (-(T)(x >= y)); \
}

T __attribute__((noinline))       \
sat_u_sub_##T##_fmt_2 (T x, T y)  \
{                                 \
  return (x - y) & (-(T)(x > y)); \
}

DEF_SAT_U_SUB_FMT_1(uint64_t);
DEF_SAT_U_SUB_FMT_2(uint64_t);

Before this patch:
sat_u_sub_uint64_t_fmt_1:
        bltu    a0,a1,.L2
        sub     a0,a0,a1
        ret
.L2:
        li      a0,0
        ret

After this patch:
sat_u_sub_uint64_t_fmt_1:
        sltu    a5,a0,a1
        addi    a5,a5,-1
        sub     a0,a0,a1
        and     a0,a5,a0
        ret

ToDo:
Only above 2 forms of .SAT_SUB are support for now,  we will
support more forms of .SAT_SUB in the middle-end in short future.

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

gcc/ChangeLog:

* config/riscv/riscv-protos.h (riscv_expand_ussub): Add new func
decl for ussub expanding.
* config/riscv/riscv.cc (riscv_expand_ussub): Ditto but for impl.
* config/riscv/riscv.md (ussub<mode>3): Add new pattern ussub
for scalar modes.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test macros and comments.
* gcc.target/riscv/sat_u_sub-1.c: New test.
* gcc.target/riscv/sat_u_sub-2.c: New test.
* gcc.target/riscv/sat_u_sub-3.c: New test.
* gcc.target/riscv/sat_u_sub-4.c: New test.
* gcc.target/riscv/sat_u_sub-5.c: New test.
* gcc.target/riscv/sat_u_sub-6.c: New test.
* gcc.target/riscv/sat_u_sub-7.c: New test.
* gcc.target/riscv/sat_u_sub-8.c: New test.
* gcc.target/riscv/sat_u_sub-run-1.c: New test.
* gcc.target/riscv/sat_u_sub-run-2.c: New test.
* gcc.target/riscv/sat_u_sub-run-3.c: New test.
* gcc.target/riscv/sat_u_sub-run-4.c: New test.
* gcc.target/riscv/sat_u_sub-run-5.c: New test.
* gcc.target/riscv/sat_u_sub-run-6.c: New test.
* gcc.target/riscv/sat_u_sub-run-7.c: New test.
* gcc.target/riscv/sat_u_sub-run-8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
13 months agoanalyzer: Restore g++ 4.8 bootstrap; use std::move to return std::unique_ptr.
Roger Sayle [Sat, 8 Jun 2024 04:01:38 +0000 (05:01 +0100)] 
analyzer: Restore g++ 4.8 bootstrap; use std::move to return std::unique_ptr.

This patch restores bootstrap when using g++ 4.8 as a host compiler.
Returning a std::unique_ptr requires a std::move on C++ compilers
(pre-C++17) that don't guarantee copy elision/return value optimization.

2024-06-08  Roger Sayle  <roger@nextmovesoftware.com>

gcc/analyzer/ChangeLog
* constraint-manager.cc (equiv_class::make_dump_widget): Use
std::move to return a std::unique_ptr.
(bounded_ranges_constraint::make_dump_widget): Likewise.
(constraint_manager::make_dump_widget): Likewise.
* program-state.cc (sm_state_map::make_dump_widget): Likewise.
(program_state::make_dump_widget): Likewise.
* region-model.cc (region_to_value_map::make_dump_widget): Likewise.
(region_model::make_dump_widget): Likewise.
* region.cc (region::make_dump_widget): Likewise.
* store.cc (binding_cluster::make_dump_widget): Likewise.
(store::make_dump_widget): Likewise.
* svalue.cc (svalue::make_dump_widget): Likewise.

13 months agoDaily bump.
GCC Administrator [Sat, 8 Jun 2024 00:18:05 +0000 (00:18 +0000)] 
Daily bump.

13 months agoanalyzer: add logging to get_representative_path_var
David Malcolm [Fri, 7 Jun 2024 20:14:29 +0000 (16:14 -0400)] 
analyzer: add logging to get_representative_path_var

This was very helpful when debugging the cast_region::m_original_region
removal, but is probably too verbose to enable except by hand on
specific calls to get_representative_tree.

gcc/analyzer/ChangeLog:
* engine.cc (impl_region_model_context::on_state_leak): Pass nullptr
to get_representative_path_var.
* region-model.cc (region_model::get_representative_path_var_1):
Add logger param and use it in both overloads.
(region_model::get_representative_path_var): Likewise.
(region_model::get_representative_tree): Likewise.
(selftest::test_get_representative_path_var): Pass nullptr to
get_representative_path_var.
* region-model.h (region_model::get_representative_tree): Add
optional logger param to both overloads.
(region_model::get_representative_path_var): Add logger param to
both overloads.
(region_model::get_representative_path_var_1): Likewise.
* store.cc (binding_cluster::get_representative_path_vars): Add
logger param and use it.
(store::get_representative_path_vars): Likewise.
* store.h (binding_cluster::get_representative_path_vars): Add
logger param.
(store::get_representative_path_vars): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
13 months agoanalyzer: eliminate cast_region::m_original_region
David Malcolm [Fri, 7 Jun 2024 20:14:29 +0000 (16:14 -0400)] 
analyzer: eliminate cast_region::m_original_region

cast_region had its own field m_original_region, rather than
simply using region::m_parent, leading to lots of pointless
special-casing of RK_CAST.

Remove the field and simply use the parent region.

Doing so revealed a bug (seen in gcc.dg/analyzer/taint-alloc-4.c)
where region_model::get_representative_path_var_1's RK_CAST case
was always failing, due to using the "parent region" (actually
that of the original region's parent), rather than the original region;
the patch fixes the bug by removing the distinction.

gcc/analyzer/ChangeLog:
* call-summary.cc
(call_summary_replay::convert_region_from_summary_1): Update
for removal of cast_region::m_original_region.
* region-model-manager.cc
(region_model_manager::get_or_create_initial_value): Likewise.
* region-model.cc (region_model::get_store_value): Likewise.
* region.cc (region::get_base_region): Likewise.
(region::descendent_of_p): Likewise.
(region::maybe_get_frame_region): Likewise.
(region::get_memory_space): Likewise.
(region::calc_offset): Likewise.
(cast_region::accept): Delete.
(cast_region::dump_to_pp): Update for removal of
cast_region::m_original_region.
(cast_region::add_dump_widget_children): Delete.
* region.h (struct cast_region::key_t): Rename "original_region"
to "parent".
(cast_region::cast_region): Likewise.  Update for removal of
cast_region::m_original_region.
(cast_region::accept): Delete.
(cast_region::add_dump_widget_children): Delete.
(cast_region::get_original_region): Delete.
(cast_region::m_original_region): Delete.
* sm-taint.cc (region_model::check_region_for_taint): Remove
special-casing for RK_CAST.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/taint-alloc-4.c: Update expected result to
reflect change in message due to
region_model::get_representative_path_var_1 now handling RK_CAST.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
13 months agoanalyzer: new warning: -Wanalyzer-undefined-behavior-ptrdiff (PR analyzer/105892)
David Malcolm [Fri, 7 Jun 2024 20:14:28 +0000 (16:14 -0400)] 
analyzer: new warning: -Wanalyzer-undefined-behavior-ptrdiff (PR analyzer/105892)

Add a new warning to complain about pointer subtraction involving
different chunks of memory.

For example, given:

  #include <stddef.h>

  int arr[42];
  int sentinel;

  ptrdiff_t
  test_invalid_calc_of_array_size (void)
  {
    return &sentinel - arr;
  }

this emits:

demo.c: In function ‘test_invalid_calc_of_array_size’:
demo.c:9:20: warning: undefined behavior when subtracting pointers [CWE-469] [-Wanalyzer-undefined-behavior-ptrdiff]
    9 |   return &sentinel - arr;
      |                    ^
  events 1-2
    │
    │    3 | int arr[42];
    │      |     ~~~
    │      |     |
    │      |     (2) underlying object for right-hand side of subtraction created here
    │    4 | int sentinel;
    │      |     ^~~~~~~~
    │      |     |
    │      |     (1) underlying object for left-hand side of subtraction created here
    │
    └──> ‘test_invalid_calc_of_array_size’: event 3
           │
           │    9 |   return &sentinel - arr;
           │      |                    ^
           │      |                    |
           │      |                    (3) ⚠️  subtraction of pointers has undefined behavior if they do not point into the same array object
           │

gcc/analyzer/ChangeLog:
PR analyzer/105892
* analyzer.opt (Wanalyzer-undefined-behavior-ptrdiff): New option.
* analyzer.opt.urls: Regenerate.
* region-model.cc (class undefined_ptrdiff_diagnostic): New.
(check_for_invalid_ptrdiff): New.
(region_model::get_gassign_result): Call it for POINTER_DIFF_EXPR.

gcc/ChangeLog:
* doc/invoke.texi: Add -Wanalyzer-undefined-behavior-ptrdiff.

gcc/testsuite/ChangeLog:
PR analyzer/105892
* c-c++-common/analyzer/out-of-bounds-pr110387.c: Add
expected warnings about pointer subtraction.
* c-c++-common/analyzer/ptr-subtraction-1.c: New test.
* c-c++-common/analyzer/ptr-subtraction-CWE-469-example.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
13 months agolibstdc++: Add missing header to <bits/ranges_algobase.h> for std::__memcmp
Jonathan Wakely [Fri, 7 Jun 2024 08:49:06 +0000 (09:49 +0100)] 
libstdc++: Add missing header to <bits/ranges_algobase.h> for std::__memcmp

As noticed by Michael Levine.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h: Include <bits/stl_algobase.h>.

13 months agoc++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575]
Simon Martin [Tue, 4 Jun 2024 19:20:23 +0000 (21:20 +0200)] 
c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575]

We currently ICE upon the following because we don't properly handle local
functions with an error_mark_node as DECL_LOCAL_DECL_ALIAS in duplicate_decls.

=== cut here ===
void f (void) {
  virtual int f (void) const;
  virtual int f (void);
}
=== cut here ===

This patch fixes this by checking for error_mark_node.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/107575

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Check for error_mark_node
DECL_LOCAL_DECL_ALIAS.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash74.C: New test.

13 months agoc++: -include and header unit translation
Jason Merrill [Wed, 5 Jun 2024 02:27:56 +0000 (22:27 -0400)] 
c++: -include and header unit translation

 Within a source file, #include is translated to import if a suitable header
 unit is available, but this wasn't working with -include.  This turned out
 to be because we suppressed the translation before the beginning of the
 main file.  After removing that, I had to tweak libcpp file handling to
 accommodate the way it moves from an -include to the main file.

gcc/ChangeLog:

* doc/invoke.texi (C++ Modules): Mention -include.

gcc/cp/ChangeLog:

* module.cc (maybe_translate_include): Allow before the main file.

libcpp/ChangeLog:

* files.cc (_cpp_stack_file): LC_ENTER for -include header unit.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dashinclude-1_b.C: New test.
* g++.dg/modules/dashinclude-1_a.H: New test.

13 months agoc++: lambda in pack expansion [PR115378]
Patrick Palka [Fri, 7 Jun 2024 16:12:30 +0000 (12:12 -0400)] 
c++: lambda in pack expansion [PR115378]

Here find_parameter_packs_r is incorrectly treating the 'auto' return
type of a lambda as a parameter pack due to Concepts-TS specific logic
added in r6-4517, leading to confusion later when expanding the pattern.

Since we intend on removing Concepts TS support soon anyway, this patch
fixes this by restricting the problematic logic with flag_concepts_ts.
Doing so revealed that add_capture was relying on this logic to set
TEMPLATE_TYPE_PARAMETER_PACK for the 'auto' type of an pack expansion
init-capture, which we now need to do explicitly.

PR c++/115378

gcc/cp/ChangeLog:

* lambda.cc (lambda_capture_field_type): Set
TEMPLATE_TYPE_PARAMETER_PACK on the auto type of an init-capture
pack expansion.
* pt.cc (find_parameter_packs_r) <case TEMPLATE_TYPE_PARM>:
Restrict TEMPLATE_TYPE_PARAMETER_PACK promotion with
flag_concepts_ts.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/decltype-auto-103497.C: Adjust expected diagnostic.
* g++.dg/template/pr95672.C: Likewise.
* g++.dg/cpp2a/lambda-targ5.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
13 months agolto: Fix build on MacOS
Simon Martin [Fri, 7 Jun 2024 14:14:58 +0000 (16:14 +0200)] 
lto: Fix build on MacOS

The build fails on x86_64-apple-darwin19.6.0 starting with 5b6d5a886ee because
vector is included after system.h and runs into poisoned identifiers.

This patch fixes this by defining INCLUDE_VECTOR before including system.h.

Validated by doing a full build on x86_64-apple-darwin19.6.0.

gcc/lto/ChangeLog:

* lto-partition.cc: Define INCLUDE_VECTOR to avoid running into
poisoned identifiers.

13 months agoi386: PR target/115351: RTX costs for *concatditi3 and *insvti_highpart.
Roger Sayle [Fri, 7 Jun 2024 13:03:20 +0000 (14:03 +0100)] 
i386: PR target/115351: RTX costs for *concatditi3 and *insvti_highpart.

This patch addresses PR target/115351, which is a code quality regression
on x86 when passing floating point complex numbers.  The ABI considers
these arguments to have TImode, requiring interunit moves to place the
FP values (which are actually passed in SSE registers) into the upper
and lower parts of a TImode pseudo, and then similar moves back again
before they can be used.

The cause of the regression is that changes in how TImode initialization
is represented in RTL now prevents the RTL optimizers from eliminating
these redundant moves.  The specific cause is that the *concatditi3
pattern, (zext(hi)<<64)|zext(lo), has an inappropriately high (default)
rtx_cost, preventing fwprop1 from propagating it.  This pattern just
sets the hipart and lopart of a double-word register, typically two
instructions (less if reload can allocate things appropriately) but
the current ix86_rtx_costs actually returns INSN_COSTS(13), i.e. 52.

propagating insn 5 into insn 6, replacing:
(set (reg:TI 110)
    (ior:TI (and:TI (reg:TI 110)
            (const_wide_int 0x0ffffffffffffffff))
        (ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112 [ zD.2796+8 ]) 0))
            (const_int 64 [0x40]))))
successfully matched this instruction to *concatditi3_3:
(set (reg:TI 110)
    (ior:TI (ashift:TI (zero_extend:TI (subreg:DI (reg:DF 112 [ zD.2796+8 ]) 0))
            (const_int 64 [0x40]))
        (zero_extend:TI (subreg:DI (reg:DF 111 [ zD.2796 ]) 0))))
change not profitable (cost 50 -> cost 52)

This issue is resolved by having ix86_rtx_costs return more reasonable
values for these (place-holder) patterns.

2024-06-07  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/115351
* config/i386/i386.cc (ix86_rtx_costs): Provide estimates for
the *concatditi3 and *insvti_highpart patterns, about two insns.

gcc/testsuite/ChangeLog
PR target/115351
* g++.target/i386/pr115351.C: New test case.

13 months agoi386: Improve handling of ternlog instructions in i386/sse.md
Roger Sayle [Fri, 7 Jun 2024 12:57:23 +0000 (13:57 +0100)] 
i386: Improve handling of ternlog instructions in i386/sse.md

This patch improves the way that the x86 backend recognizes and
expands AVX512's bitwise ternary logic (vpternlog) instructions.

As a motivating example consider the following code which calculates
the carry out from a (binary) full adder:

typedef unsigned long long v4di __attribute((vector_size(32)));

v4di foo(v4di a, v4di b, v4di c)
{
    return (a & b) | ((a ^ b) & c);
}

with -O2 -march=cascadelake current mainline produces:

foo:    vpternlogq      $96, %ymm0, %ymm1, %ymm2
        vmovdqa %ymm0, %ymm3
        vmovdqa %ymm2, %ymm0
        vpternlogq      $248, %ymm3, %ymm1, %ymm0
        ret

with the patch below, we now generate a single instruction:

foo:    vpternlogq      $232, %ymm2, %ymm1, %ymm0
        ret

The AVX512 vpternlog[qd] instructions are a very cool addition to the
x86 instruction set, that can calculate any Boolean function of three
inputs in a single fast instruction.  As the truth table for any
three-input function has 8 rows, any specific function can be represented
by specifying those bits, i.e. by a 8-bit byte, an immediate integer
between 0 and 256.

Examples of ternary functions and their indices are given below:

0x01   1:  ~((b|a)|c)
0x02   2:  (~(b|a))&c
0x03   3:  ~(b|a)
0x04   4:  (~(c|a))&b
0x05   5:  ~(c|a)
0x06   6:  (c^b)&~a
0x07   7:  ~((c&b)|a)
0x08   8:  (~a&c)&b (~a&b)&c (c&b)&~a
0x09   9:  ~((c^b)|a)
0x0a  10:  ~a&c
0x0b  11:  ~((~c&b)|a) (~b|c)&~a
0x0c  12:  ~a&b
0x0d  13:  ~((~b&c)|a) (~c|b)&~a
0x0e  14:  (c|b)&~a
0x0f  15:  ~a
0x10  16:  (~(c|b))&a
0x11  17:  ~(c|b)
...
0xf4 244:  (~c&b)|a
0xf5 245:  ~c|a
0xf6 246:  (c^b)|a
0xf7 247:  (~(c&b))|a
0xf8 248:  (c&b)|a
0xf9 249:  (~(c^b))|a
0xfa 250:  c|a
0xfb 251:  (c|a)|~b (~b|a)|c (~b|c)|a
0xfc 252:  b|a
0xfd 253:  (b|a)|~c (~c|a)|b (~c|b)|a
0xfe 254:  (b|a)|c (c|a)|b (c|b)|a

A naive implementation (in many compilers) might be add define_insn
patterns for all 256 different functions.  The situation is even
worse as many of these Boolean functions don't have a "canonical form"
(as produced by simplify_rtx) and would each need multiple patterns.
See the space-separated equivalent expressions in the table above.

This need to provide instruction "templates" might explain why GCC,
LLVM and ICC all exhibit similar coverage problems in their ability
to recognize x86 ternlog ternary functions.

Perhaps a unique feature of GCC's design is that in addition to regular
define_insn templates, machine descriptions can also perform pattern
matching via a match_operator (and its corresponding predicate).
This patch introduces a ternlog_operand predicate that matches a
(possibly infinite) set of expression trees, identifying those that
have at most three unique operands.  This then allows a
define_insn_and_split to recognize suitable expressions and then
transform them into the appropriate UNSPEC_VTERNLOG as a pre-reload
splitter.  This design allows combine to smash together arbitrarily
complex Boolean expressions, then transform them into an UNSPEC
before register allocation.  As an "optimization", where possible
ix86_expand_ternlog generates a simpler binary operation, using
AND, XOR, IOR or ANDN where possible, and in a few cases attempts
to "canonicalize" the ternlog, by reordering or duplicating operands,
so that later CSE passes have a hope of spotting equivalent values.

This patch leaves the existing ternlog patterns in sse.md (for now),
many of which are made obsolete by these changes.  In theory we now
only need one define_insn for UNSPEC_VTERNLOG.  One complication from
these previous variants was that they inconsistently used decimal vs.
hexadecimal to specify the immediate constant operand in assembly
language, making the list of tweaks to the testsuite with this patch
larger than it might have been.  I propose to remove the vestigial
patterns in a follow-up patch, once this approach has baked (proven
to be stable) on mainline.

2024-06-07  Roger Sayle  <roger@nextmovesoftware.com>
    Hongtao Liu  <hongtao.liu@intel.com>

gcc/ChangeLog
* config/i386/i386-expand.cc (ix86_expand_args_builtin): Call
fixup_modeless_constant before testing predicates.  Only call
copy_to_mode_reg on memory operands (after the first one).
(ix86_gen_bcst_mem): Helper function to convert a CONST_VECTOR
into a VEC_DUPLICATE if possible.
(ix86_ternlog_idx):  Convert an RTX expression into a ternlog
index between 0 and 255, recording the operands in ARGS, if
possible or return -1 if this is not possible/valid.
(ix86_ternlog_leaf_p): Helper function to identify "leaves"
of a ternlog expression, e.g. REG_P, MEM_P, CONST_VECTOR, etc.
(ix86_ternlog_operand_p): Test whether a expression is suitable
for and prefered as an UNSPEC_TERNLOG.
(ix86_expand_ternlog_binop): Helper function to construct the
binary operation corresponding to a sufficiently simple ternlog.
(ix86_expand_ternlog_andnot): Helper function to construct a
ANDN operation corresponding to a sufficiently simple ternlog.
(ix86_expand_ternlog): Expand a 3-operand ternary logic
expression, constructing either an UNSPEC_TERNLOG or simpler
rtx expression.  Called from builtin expanders and pre-reload
splitters.
* config/i386/i386-protos.h (ix86_ternlog_idx): Prototype here.
(ix86_ternlog_operand_p): Likewise.
(ix86_expand_ternlog): Likewise.
* config/i386/predicates.md (ternlog_operand): New predicate
that calls xi86_ternlog_operand_p.
* config/i386/sse.md (<avx512>_vpternlog<mode>_0): New
define_insn_and_split that recognizes a SET_SRC of ternlog_operand
and expands it via ix86_expand_ternlog pre-reload.
(<avx512>_vternlog<mode>_mask): Convert from define_insn to
define_expand.  Use ix86_expand_ternlog if the mask operand is
~0 (or 255 or -1).
(*<avx512>_vternlog<mode>_mask): define_insn renamed from above.

gcc/testsuite/ChangeLog
* gcc.target/i386/avx512f-vpternlogd-1.c: Update test case.
* gcc.target/i386/avx512f-vpternlogq-1.c: Likewise.
* gcc.target/i386/avx512vl-vpternlogd-1.c: Likewise.
* gcc.target/i386/avx512vl-vpternlogq-1.c: Likewise.
* gcc.target/i386/pr100711-4.c: Likewise.
* gcc.target/i386/pr100711-5.c: Likewise.

* gcc.target/i386/avx512f-vpternlogd-3.c: New 128-bit test case.
* gcc.target/i386/avx512f-vpternlogd-4.c: New 256-bit test case.
* gcc.target/i386/avx512f-vpternlogd-5.c: New 512-bit test case.
* gcc.target/i386/avx512f-vpternlogq-3.c: New test case.

13 months agolto: Implement cache partitioning
Michal Jires [Fri, 17 Nov 2023 20:17:18 +0000 (21:17 +0100)] 
lto: Implement cache partitioning

This patch implements new cache partitioning. It tries to keep symbols
from single source file together to minimize propagation of divergence.

It starts with symbols already grouped by source files. If reasonably
possible it only either combines several files into one final partition,
or, if a file is large, split the file into several final partitions.

Intermediate representation is partition_set which contains set of
groups of symbols (each group corresponding to original source file) and
number of final partitions this partition_set should split into.

First partition_fixed_split splits partition_set into constant number of
partition_sets with equal number of symbols groups. If for example there
are 39 source files, the resulting partition_sets will contain 10, 10,
10, and 9 source files. This splitting intentionally ignores estimated
instruction counts to minimize propagation of divergence.

Second partition_over_target_split separates too large files and splits
them into individual symbols to be combined back into several smaller
files in next step.

Third partition_binary_split splits partition_set into two halves until
it should be split into only one final partition, at which point the
remaining symbols are joined into one final partition.

Bootstrapped/regtested on x86_64-pc-linux-gnu

gcc/ChangeLog:

* common.opt: Add cache partitioning.
* flag-types.h (enum lto_partition_model): Likewise.

gcc/lto/ChangeLog:

* lto-partition.cc (new_partition): Use new_partition_no_push.
(new_partition_no_push): New.
(free_ltrans_partition): New.
(free_ltrans_partitions): Use free_ltrans_partition.
(join_partitions): New.
(split_partition_into_nodes): New.
(is_partition_reorder): New.
(class partition_set): New.
(distribute_n_partitions): New.
(partition_over_target_split): New.
(partition_binary_split): New.
(partition_fixed_split): New.
(class partitioner_base): New.
(class partitioner_default): New.
(lto_cache_map): New.
* lto-partition.h (lto_cache_map): New.
* lto.cc (do_whole_program_analysis): Use lto_cache_map.

gcc/testsuite/ChangeLog:

* gcc.dg/completion-2.c: Add -flto-partition=cache.

13 months ago[libstdc++] drop workaround for clang<=7
Alexandre Oliva [Fri, 7 Jun 2024 10:00:11 +0000 (07:00 -0300)] 
[libstdc++] drop workaround for clang<=7

In response to a request in the review of the patch that introduced
_GLIBCXX_CLANG, this patch removes from std/variant an obsolete
workaround for clang 7-.

for  libstdc++-v3/ChangeLog

* include/std/variant: Drop obsolete workaround.

13 months agoFix fold-left reduction vectorization with multiple stmt copies
Richard Biener [Fri, 7 Jun 2024 07:41:11 +0000 (09:41 +0200)] 
Fix fold-left reduction vectorization with multiple stmt copies

There's a typo when code generating the mask operand for conditional
fold-left reductions in the case we have multiple stmt copies.  The
latter is now allowed for SLP and possibly disabled for non-SLP by
accident.

This fixes the observed run-FAIL for
gcc.dg/vect/vect-cond-reduc-in-order-2-signed-zero.c with AVX512
and 256bit sized vectors.

* tree-vect-loop.cc (vectorize_fold_left_reduction): Fix
mask vector operand indexing.

13 months agolibstdc++: Optimize std::to_address
Jonathan Wakely [Mon, 18 Mar 2024 16:58:23 +0000 (16:58 +0000)] 
libstdc++: Optimize std::to_address

We can use if-constexpr and variable templates to simplify and optimize
std::to_address. This should compile faster (and run faster for -O0)
than dispatching to the pre-C++20 std::__to_address overloads.

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (to_address): Optimize.
* testsuite/20_util/to_address/1_neg.cc: Adjust dg-error text.

13 months agofixincludes: bypass some fixes for recent darwin headers
Francois-Xavier Coudert [Sun, 2 Jun 2024 19:07:23 +0000 (21:07 +0200)] 
fixincludes: bypass some fixes for recent darwin headers

fixincludes/ChangeLog:

* fixincl.x: Regenerate.
* inclhack.def (darwin_stdint_7, darwin_dispatch_object_1,
darwin_os_trace_2, darwin_os_base_1): Include bypasses
for recent headers, fixed by Apple.