Wrap the function's return type within an optional to differentiate
between a null pointer and a missing value.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_hir_struct_field): Change
call site to accomodate new return type.
(Mappings::lookup_hir_struct_field): Change the function's return
type.
* util/rust-hir-map.h: Update the function's prototype.
Wrap the function's return type within an optional in order to
differentiate null pointers from missing value.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_hir_self_param): Adapt call
site to new return type.
(Mappings::lookup_hir_self_param): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change lookup_hir_smt's return type with optional
Wrap the function's return type within an optional in order to
differentiate missing values from null pointers.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_hir_stmt): Change call site
to accomodate new return type.
(Mappings::lookup_hir_stmt): Change the function's return type.
(Mappings::resolve_nodeid_to_stmt): Adapt call site to new return type.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change lookup_hir_type return type with an optional
Wrap the function's return type with an optional in order to tell
appart a null pointer from a missing value.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_hir_type): Change call site
to accomodate the new return type.
(Mappings::lookup_hir_type): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change lookup_hir_generic_param return type
Wrap the function's return type with an optional.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_hir_generic_param): Change
call site to accomodate the new return type.
(Mappings::lookup_hir_generic_param): Wrap the function's return type
with an optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change lookup_hir_path_expr_seg return type
Make the function's return type optional in order to differentiate
between null pointers and missing value.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_hir_path_expr_seg): Change
call site to accomodate the new return type.
(Mappings::lookup_hir_path_expr_seg): Wrap the function's return type
with an optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change lookup_hir_expr return type to optional
Wrap the function's return type with an optional in order to
differentiate missing values from null pointers.
gcc/rust/ChangeLog:
* backend/rust-mangle-v0.cc (v0_path): Adapt call site to new returned
type.
* util/rust-hir-map.cc (Mappings::lookup_hir_expr): Change the
function's return type.
* util/rust-hir-map.h: Update the function's prototype.
* checks/errors/privacy/rust-visibility-resolver.cc: Update function
call to match the new return type.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Likewise.
* util/rust-hir-map.cc (Mappings::insert_module): Likewise.
(Mappings::lookup_module): Change the function's return type.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change lookup_local_defid return type to optional
Make the API more convenient by changing the function's return type. We
can now differentiate between a stored null pointer and a missing value.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Adapt call
to new return type.
(Mappings::insert_local_defid_mapping): Likewise.
(Mappings::lookup_local_defid): Change return type to wrap it with an
optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change crate name retrieval function return types
Change their return type to a const reference in order to avoid copies
when possible. Also wrap this new return type into an optional.
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
Adapt the code to the new return types.
* resolve/rust-ast-resolve.cc (NameResolution::go): Likewise.
* util/rust-hir-map.cc (Mappings::get_crate_name): Change return type
to const string reference optional.
(Mappings::get_current_crate_name): Likewise.
* util/rust-hir-map.h: Update function prototypes.
* resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new
return type.
* rust-session-manager.cc (Session::load_extern_crate): Likewise.
* util/rust-hir-map.cc (Mappings::crate_num_to_nodeid): Change the
return type.
* util/rust-hir-map.h: Update the function's prototype.
Change the function's return type to use an optional.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new
return type.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Likewise.
* rust-session-manager.cc (Session::load_extern_crate): Likewise.
* util/rust-hir-map.cc (Mappings::lookup_crate_name): Change the return
type to an optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change return type of lookup_impl_block_type
Change the return type to an optional.
gcc/rust/ChangeLog:
* typecheck/rust-type-util.cc (query_type): Adapt code to accomodate
the new return type.
* util/rust-hir-map.cc (Mappings::lookup_impl_block_type): Change
the function's return type and remove the out pointer argument.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change return type for lookup_hir_impl_block
Change the return type to an optiona. This allows to differentiate
between missing hir impl block and null pointers.
gcc/rust/ChangeLog:
* typecheck/rust-type-util.cc (query_type): Change call to the function
in order to accomodate the new return type.
* util/rust-hir-map.cc (Mappings::lookup_hir_impl_block): Change the
function's return type to an optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change return type of lookup_hir_extern_block
Change the return type to an optional in order to easily differentiate
between a null pointer and an missing value.
gcc/rust/ChangeLog:
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_function_call):
Adapt function call to new return type.
* typecheck/rust-type-util.cc (query_type): Likewise.
* util/rust-hir-map.cc (Mappings::insert_hir_extern_block): Likewise.
(Mappings::lookup_hir_extern_block): Change return type to an optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change return type of lookup_hir_trait_item
Change the return type to an optional instead of returning a null
pointer. This allows easier tracking of rogue null pointers in the
map. This commit also fixes a bug in trait associated function mangling,
the function was using an already invalidated pointer.
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
Adapt return type to new optional.
* backend/rust-mangle-v0.cc (v0_function_path): Change prototype to use
the generic arguments vector instead of the whole HIR function.
(v0_path): Fix a bug with a null pointer being used to create the
trait function mangling.
* util/rust-hir-map.cc (Mappings::insert_hir_trait_item): Adapt code
to new return type.
(Mappings::lookup_hir_trait_item): Change the return type of the
function to an optional.
* util/rust-hir-map.h: Update the function's prototype.
gccrs: Change return type of resolve_nodeid_to_stmt
Change the return type to an optional.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::resolve_nodeid_to_stmt): Change the
return type and remove pointer out argument.
* util/rust-hir-map.h: Update function prototype.
gccrs: Change lookup_hir_to_node return type to optional
Optional are more convenient to use and avoid uninitialized data.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
Adapt code for new optional return type.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
Likewise.
* util/rust-hir-map.cc (Mappings::lookup_hir_to_node): Change return
type to an optional.
* util/rust-hir-map.h: Adapt function prototype with the new return
type.
Jakub Dupak [Wed, 24 Apr 2024 11:47:20 +0000 (13:47 +0200)]
gccrs: borrowck: Testsuite
gcc/testsuite/ChangeLog:
* rust/borrowck/borrowck.exp: New test.
* rust/borrowck/position_dependant_outlives.rs: New test.
* rust/borrowck/reference.rs: New test.
* rust/borrowck/return_ref_to_local.rs: New test.
* rust/borrowck/subset.rs: New test.
* rust/borrowck/test_move.rs: New test.
* rust/borrowck/test_move_behind_reference.rs: New test.
* rust/borrowck/test_move_conditional.rs: New test.
* rust/borrowck/tmp.rs: New test.
* rust/borrowck/use_while_mut.rs: New test.
* rust/borrowck/use_while_mut_fr.rs: New test.
* rust/borrowck/well_formed_function_inputs.rs: New test.
Tobias Burnus [Mon, 17 Mar 2025 09:12:44 +0000 (10:12 +0100)]
Move gfortran.dg/gomp/declare-variant-mod-1*.f90 to libgomp.fortran/ [PR115271]
The test is a supposed to be a compile-only test but as dg-additional-sources
does not work with dg-compile (due to compiling with '-o'), dg-link had to
be used; as the code actually compiles (no diagnostic error), the linker
is actually invoked, which fails unless the system compiler by chance
provides the required files. Solution: move the test to libgomp.
PR fortran/115271
gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/declare-variant-mod-1-use.f90: Move to
libgomp/testsuite/libgomp.fortran/.
* gfortran.dg/gomp/declare-variant-mod-1.f90: Likewise.
libgomp/ChangeLog:
* testsuite/libgomp.fortran/declare-variant-mod-1-use.f90: Moved
from gcc/testsuite/gfortran.dg/gomp/.
* testsuite/libgomp.fortran/declare-variant-mod-1.f90: Likewise.
Robin Dapp [Tue, 11 Mar 2025 13:30:48 +0000 (14:30 +0100)]
RISC-V: Mask values before initializing bitmask vector [PR119114].
In the somewhat convoluted vector code of PR119114 we extract a
<signed-boolean:1> mask value from a vector mask. After some middle-end
simplifications we end up with a value of -2. Its lowest bit is
correctly unset representing "false". When initializing a bitmak vector
from values we compare the full value/register against zero instead of
just the last bit. This causes erroneous mask values.
This patch masks the values by & 0x1 before comparing against 0.
PR target/119114
gcc/ChangeLog:
* config/riscv/autovec.md: Apply & 0x1 mask when initializing
bitmask vector.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr119114.c: New test.
Ayan Shafqat [Mon, 17 Mar 2025 08:28:27 +0000 (09:28 +0100)]
Aarch64: Add FMA and FMAF intrinsic and corresponding tests
This patch introduces inline definitions for the __fma and __fmaf
functions in arm_acle.h for Aarch64 targets. These definitions rely on
__builtin_fma and __builtin_fmaf to ensure proper inlining and to meet
the ACLE requirements [1].
The patch has been tested locally using a crosstool-NG sysroot for
Aarch64, confirming that the generated code uses the expected fused
multiply-accumulate instructions (fmadd).
Richard Biener [Thu, 13 Mar 2025 13:29:06 +0000 (14:29 +0100)]
Add -[DU]_FORTIFY_SOURCE[=n] to DW_AT_producer
The following makes sure to record -D_FORTIFY_SOURCE=n and
-U_FORTIFY_SOURCE in the DW_AT_producer debuginfo attribute when
present on the compiler command line.
* opts.cc (gen_producer_string): Record -D and -U
with _FORTIFY_SOURCE prefix.
Jeff Law [Sun, 16 Mar 2025 23:43:48 +0000 (17:43 -0600)]
[RISC-V][PR target/116256][V4] Fix minor code quality regression in reassociated arithmetic
Arggh. This time add arguments for rv32. Hand edited the testcase part of the
patch, but I think I got it right.
One. More. Time.
-pedantic-errors this time ;( Adding an explicit -std=gnu23 to shut that up.
Part of me wants to know why that's getting added by the pre-commit, but not
enough to chase it down.
--
This failed pre-commit CI the first time through. The only change is in the
return type in the test bool -> _Bool.
The patch for target/116256 significantly simplified the condition and, I guess
not too surprisingly, exposed a minor code quality regression.
Specifically the split part of the define_insn_and_split only splits after
reload (because we use a match_scratch). So there's nothing to combine the
load-immediate with the subsequent add into an addi when the immediate fits
into a simm12 field.
This patch adjusts the split code to handle that scenario directly and generate
the more efficient code. We can squeeze out the slli in this test with a bit
more work, but that's out of scope right now since that isn't a regression.
Tested in my tester. Waiting on pre-commit testing to render a verdict.
PR target/116256
gcc
* config/riscv/riscv.md (reassociation splitters): Do not load the
adjusted addend into a register if it fits in a simm12.
gcc/testsuite
* gcc.target/riscv/pr116256-1.c: New test.
Harald Anlauf [Sat, 15 Mar 2025 14:11:22 +0000 (15:11 +0100)]
Fortran: fix bogus dependency check in ALLOCATE statement [PR60560]
Restrict dependency check of ALLOCATE object to variables in the same
statement, but exclude check of length type parameter that might be
set in the declaration and could lead to a bogus cyclic dependency.
PR fortran/60560
gcc/fortran/ChangeLog:
* expr.cc (gfc_traverse_expr): Do not descend into length type
parameter for negative values of auxiliary parameter f.
* resolve.cc (gfc_find_var_in_expr): New helper function to check
dependence of an expression on given variable.
(resolve_allocate_expr): Use it to determine if array bounds in an
ALLOCATE statement depend explicitly on a variable.
Andrew Pinski [Sat, 15 Mar 2025 23:37:41 +0000 (16:37 -0700)]
discriminators: Fix assigning discriminators on edge [PR113546]
The problem here is there was a compare debug since the discriminators
would still take into account debug statements. For the edge we would look
at the first statement after the labels and that might have been a debug statement.
So we need to skip over debug statements otherwise we could get different
discriminators # with and without -g.
Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR middle-end/113546
gcc/ChangeLog:
* tree-cfg.cc (first_non_label_stmt): Rename to ...
(first_non_label_nondebug_stmt): This and use gsi_start_nondebug_after_labels_bb.
(assign_discriminators): Update call to first_non_label_nondebug_stmt.
gcc/testsuite/ChangeLog:
* c-c++-common/torture/pr113546-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Gaius Mulley [Sun, 16 Mar 2025 15:56:48 +0000 (15:56 +0000)]
PR modula2/115111 Incorrect line debugging locations at the end of the WHILE loop
This fix corrects the END token position used during the GotoOp at the
bottom of the WHILE loop. The fix is to pass the relative token position
down to M2Quads. This method should be replicated for the other loops
END or UNTIL keywords and possibly the END statements for
conditional statements.
gcc/m2/ChangeLog:
PR modula2/115111
* gm2-compiler/M2GenGCC.mod (CodeStatementNote): Add debugging.
* gm2-compiler/M2Quads.def (BuildEndWhile): New parameter reltokpos.
* gm2-compiler/M2Quads.mod (BuildEndWhile): Reimplement using new parameter.
* gm2-compiler/P3Build.bnf (WhileStatement): Call BuildEndWhile
with -1 relative position.
* gm2-gcc/m2block.cc (do_add_stmt): Tidy comment.
(GetGlobals): Ditto.
(flush_pending_note): Remove #if 0 code.
* gm2-gcc/m2pp.cc (m2pp_nop_expr): New function.
(m2pp_statement): New case clause call m2pp_nop_expr.
gcc/testsuite/ChangeLog:
PR modula2/115111
* gm2/pim/pass/whilestep.mod: New test.
Iain Sandoe [Sun, 9 Mar 2025 09:24:34 +0000 (09:24 +0000)]
Darwin: Pass -macos_version_min to the linker [PR119172].
For binaries to be notarised, the SDK version must be available.
Since we do not, at present, parse this information we have been
passing "0.0" to ld64. This now results in a warning and a fail
to notarise. As a quick-fix, we can fall back to letting ld64
figure out the SDK version (which it does for -macos_version_min).
TODO: Parse the SDKSetting.plist at some point.
PR target/119172
gcc/ChangeLog:
* config.in: Regenerate.
* config/darwin.h (DARWIN_PLATFORM_ID): Add the option to
use -macos_version_min where available.
* configure: Regenerate.
* configure.ac: Check for ld64 support of -macos_version_min.
Tobias Burnus [Sat, 15 Mar 2025 07:53:18 +0000 (08:53 +0100)]
contrib/gcc-changelog: Fix Git.AutoInterrupt - sys.meta_path is None exception
I think the following message is new with Python 3.13, at least I starting
seeing the following exception, which could be fixed by a simple call
to 'repo.close()'.
Seemingly the issue was that the lifetime of the destructor exceeded the
object lifetime.
Exception ignored in: <function Git.AutoInterrupt.__del__ at 0x7ff995aa4f40>
Traceback (most recent call last):
File "/usr/lib/python3.13/site-packages/git/cmd.py", line 790, in __del__
File "/usr/lib/python3.13/site-packages/git/cmd.py", line 781, in _terminate
File "/usr/lib64/python3.13/subprocess.py", line 2227, in terminate
ImportError: sys.meta_path is None, Python is likely shutting down
contrib/ChangeLog:
* gcc-changelog/git_repository.py (parse_git_revisions): Destroy the
Repo object by calling repo.close() at the end of the function.
Tobias Burnus [Sat, 15 Mar 2025 07:28:11 +0000 (08:28 +0100)]
Fortran: Store OpenMP's 'declare variant' in module file [PR115271]
Write the 'omp declare variant' data into the .mod file: Base function,
variant function(s), supporting the clauses match, append_args, and
adjust_args.
PR fortran/115271
gcc/fortran/ChangeLog:
* module.cc (mio_omp_declare_simd_clauses): New, moved from ...
(mio_omp_declare_simd): ... here. Update call, write empty '( )'
if there is no declare simd but a declare variant.
(mio_omp_declare_variant): New.
(mio_symbol): Call it.
* openmp.cc (gfc_match_omp_context_selector): Add comment about
module.cc to TODO note.
* trans-stmt.h (gfc_trans_omp_declare_variant): Take additional
parent_ns argument.
* trans-decl.cc (create_function_arglist,
gfc_create_function_decl): Update call.
* trans-openmp.cc (gfc_trans_omp_declare_variant): Take new
argument, add some special case handling for attr.use_assoc.
gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/declare-variant-mod-1-use.f90: New test.
* gfortran.dg/gomp/declare-variant-mod-1.f90: New test.
* gfortran.dg/gomp/declare-variant-mod-2-use.f90: New test.
* gfortran.dg/gomp/declare-variant-mod-2.f90: New test.
Pan Li [Wed, 12 Mar 2025 03:26:52 +0000 (11:26 +0800)]
RISC-V: Refine the testcases for cond_widen_complicate-3
Rearrange the test cases of cond_widen_complicate-3 by different types
into different files, instead of put all types together. Then we can
easily reduce the range when asm check fails.
The below test suites are passed locally, let's wait online CI says.
* The rv64gcv fully regression test.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3.c: Removed.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-f16.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-f32.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-i16.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-i32.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-i8.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-u16.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-u32.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3-u8.c: New test.
* gcc.target/riscv/rvv/autovec/cond/cond_widen_complicate-3.h: New test.
Patrick Palka [Fri, 14 Mar 2025 20:10:35 +0000 (16:10 -0400)]
libstdc++: Missing 'constexpr' in vector's from_range ctor [PR119282]
A missing 'constexpr' in the non-forward (and non-sized) branch of our
recently implemented vector from_range ctor was causing this valid example
to be rejected with a cryptic error.
PR libstdc++/119282
libstdc++-v3/ChangeLog:
* include/bits/stl_vector.h (vector::vector(from_range_t)): Add
missing 'constexpr' to local class _Clear.
* testsuite/std/ranges/conv/1.cc (test_pr119282): New test.
Jakub Jelinek [Fri, 14 Mar 2025 19:32:43 +0000 (20:32 +0100)]
cobol: Don't run cobol tests with -m32 or -mx32 [PR119290]
The following patch adds cobol effective target and uses it to guard main
loop in cobol.dg/dg.exp, so that we don't run the tests on unsupported
multilibs.
Tested on x86_64-linux with
make check-cobol RUNTESTFLAGS='--target_board=unix\{-m32,-m64\} dg.exp'
which previously had all FAILs in the -m32 case and now doesn't report
any PASSes/FAILs/XFAILs/XPASSes etc, while for -m64 the testsuite is run
normally.
2025-03-14 Jakub Jelinek <jakub@redhat.com>
PR cobol/119290
* lib/target-supports.exp (check_compile): Use *.cob extension for
"*> COBOL" comment.
* lib/cobol-dg.exp (check_effective_target_cobol): New procedure.
* cobol.dg/dg.exp: Guard main loop with [check_effective_target_cobol]
test.
Martin Jambor [Fri, 14 Mar 2025 15:07:01 +0000 (16:07 +0100)]
ipa: Do not modify cgraph edges from thunk clones during inlining (PR116572)
In PR 116572 we hit an assert that a thunk which does not have a body
looks like it has one. It does not, but the call_stmt of its outgoing
edge points to a statement, which should not. In fact it has several
outgoing call graph edges, which cannot be. The problem is that the
code updating the edges to reflect inlining into the master clone (an
ex-thunk, unlike the clone, which is still an unexpanded thunk) is
being updated during inling into the master clone. This patch simply
makes the code to skip unexpanded thunk clones.
gcc/ChangeLog:
2025-03-13 Martin Jambor <mjambor@suse.cz>
PR ipa/116572
* cgraph.cc (cgraph_update_edges_for_call_stmt): Do not update
edges of clones that are unexpanded thunk. Assert that the node
passed as the parameter is not an unexpanded thunk.
Jakub Jelinek [Fri, 14 Mar 2025 14:34:32 +0000 (15:34 +0100)]
match.pd: Fix up r15-8025 simplification [PR119287]
The following testcase ICEs since r15-8025.
tree_nop_conversion_p doesn't imply TREE_TYPE (@0) is uselessly convertible
to type, e.g. they could be INTEGER_TYPEs with the same precision but
different TYPE_SIGN.
The following patch just adds a convert so that it creates a valid IL
even in those cases.
2025-03-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/119287
* match.pd (((X >> C1) & C2) * (1 << C1) to X & (C2 << C1)): Use
(convert @0) instead of @0 in the substitution.
Jakub Jelinek [Fri, 14 Mar 2025 14:31:47 +0000 (15:31 +0100)]
c, c++: Set DECL_NOT_GIMPLE_REG_P on *PART_EXPR operand on lhs of MODIFY_EXPR [PR119120]
The PR119190 patch I've posted regresses the PR119120 testcase (not adding
to testsuite, as it is fairly hard to scan for that problem).
The issue is that for the partial setting of _Complex floating vars
through __real__ on it first and __imag__ later (or vice versa) and since
we forced all complex vars into SSA form we often have undefined (D)
arguments of those COMPLEX_EXPRs. When we don't DCE them (for -O0 debug
info reasons), their expansion will copy both the real and imag parts
using the floating mode and on some targets like 387 that copying alone can
unfortunately trigger exceptions on sNaNs or other problematic bit patterns
and for uninitialized memory it can be triggered randomly based on whatever
is on the stack before.
The following patch sets DECL_NOT_GIMPLE_REG_P flag in the FEs during
genericization.
I think Fortran doesn't have a way to modify just real or just complex
part separately.
The patch is for code like
_ComplexT __t;
__real__ __t = __z.real();
__imag__ __t = __z.imag();
_M_value *= __t;
return *this;
at -O0 which used to appear widely even in libstdc++ before GCC 9
and happens in real-world code. At -O0 for debug info reasons (see
PR119190) we don't want to aggressively DCE statements and when we
since r0-100845 try to rewrite vars with COMPLEX_TYPE into SSA form
aggressively, the above results in copying of uninitialized data
when expanding COMPLEX_EXPRs added so that the vars can be in SSA form.
The patch detects during genericization the partial initialization and
doesn't rewrite such vars to SSA at -O0. This has to be done before
gimplification starts, otherwise e.g. the attached testcase ICEs.
2025-03-14 Jakub Jelinek <jakub@redhat.com>
PR target/119120
* c-gimplify.cc (c_genericize_control_r): Set DECL_NOT_GIMPLE_REG_P
on {REAL,IMAG}PART_EXPR is_gimple_reg operand at -O0 if it is lhs
of a MODIFY_EXPR.
* cp-gimplify.cc (cp_genericize_r): Set DECL_NOT_GIMPLE_REG_P
on {REAL,IMAG}PART_EXPR is_gimple_reg operand at -O0 if it is lhs
of a MODIFY_EXPR.
Jakub Jelinek [Fri, 14 Mar 2025 14:30:43 +0000 (15:30 +0100)]
analyzer: Fix ICE in cmp_csts_same_type on RAW_DATA_CST [PR119278]
The following testcase ICEs in cmp_csts_same_type because RAW_DATA_CST
isn't handled there. As TREE_TYPE (cst1) in that case is INTEGER_TYPE,
e.g. char/signed char/unsigned char, the type itself doesn't imply
the size, so the length is compared first, followed by comparing the
data.
While at it, I've noticed STRING_CST handling is wrong, because STRING_CST
can represent even string literals with embedded nul characters.
We shouldn't stop at those, hence memcmp.
While for STRING_CST TREE_TYPE should likely already imply the length
and so same type should imply same TREE_STRING_LENGTH, I've repeated
the comparisons in there just in case.
2025-03-14 Jakub Jelinek <jakub@redhat.com>
PR analyzer/119278
* svalue.cc (cmp_csts_same_type): For STRING_CST, compare
TREE_STRING_LENGTH first just in case and use memcmp rather
than strcmp. Handle RAW_DATA_CST.
Tomasz Kamiński [Fri, 7 Mar 2025 10:54:38 +0000 (11:54 +0100)]
libstdc++: Fix views::zip_transform constraints for empty range pack [PR111138]
Add missing move_constructible && regular_invocable constrains on functor type,
and is_object on functor result type for invocations of views::zip_transform
without range arguments.
PR libstdc++/111138
libstdc++-v3/ChangeLog:
* include/std/ranges (_ZipTransform::operator()):
Create separate overload for calls with empty range pack,
and add move_constructible, regular_invocable and
is_object_v<invoke_result_t<...>>> constraints.
* testsuite/std/ranges/zip_transform/1.cc: New tests
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Robert Dubner [Fri, 14 Mar 2025 01:03:46 +0000 (21:03 -0400)]
Prevent use of ASM_EXPR for optimized COBOL compilations [PR119214]
The creation of assembler labels using ASM_EXPR causes name collisions in the
assembly language because some optimizations repeat code, and those labels
can get repeated. Use of "if( !optimize )" prevents (at least) that problem when
it cropped up with "-O -ftrace"
gcc/cobol:
PR cobol/119214
* gengen.cc: applies if( !optimize ) test
Richard Biener [Fri, 14 Mar 2025 12:09:31 +0000 (13:09 +0100)]
cobol/119281 - make sure $(gcc_version) is set for libgcobol install
When using --enable-version-specific-runtime-libs at least it's
required that $(gcc_version) is set to be able to expand
toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
The following fixes this by adjusting configure.ac to call GCC_BASE_VER
and Makefile.am to include a definition for gcc_version.
Thomas Schwinge [Mon, 11 Jul 2022 20:36:39 +0000 (22:36 +0200)]
GCN, nvptx: Don't default-disable libstdc++ build
In addition to making libstdc++ itself available, this, via enabling
'build-gcc/*/libstdc++-v3/scripts/testsuite_flags', in particular also makes
the standard C++ headers available to 'make check-gcc-c++'. With that, there
are a lot of FAIL/UNRESOLVED -> PASS progressions, where we previously ran
into, for example:
FAIL: g++.dg/coroutines/co-await-syntax-00-needs-expr.C (test for errors, line 6)
FAIL: g++.dg/coroutines/co-await-syntax-00-needs-expr.C (test for excess errors)
Excess errors:
[...]/gcc/testsuite/g++.dg/coroutines/coro.h:132:10: fatal error: cstdlib: No such file or directory
Similarly, there are a lot of FAIL/UNRESOLVED -> UNSUPPORTED "progressions" due
to 'sorry, unimplemented: exception handling not supported'.
The 'make check-target-libstdc++-v3' results don't look too bad, either.
With libstdc++ now available, libgrust gets enabled, which we in turn again
have to disable, for 'sorry, unimplemented: exception handling not supported'
reasons.
The following improves how VN performs its dominance queries to
determine availability, exploiting edges considered unreachable.
The function already contains code to handle the leader block
forking the CFG, but that looks like a situation that won't
help the dominance query ever. The following adds handling
of the more useful case where this block forwards to a CFG
merge with the forwarder being the only executable entry.
This helps optimizing the code so the spurious array diagnostic
does no longer appear.
PR tree-optimization/119274
* tree-ssa-sccvn.cc (dominated_by_p_w_unex): Handle the
top block being the only executable forwarder to a CFG
merge.
vect_slp_prefer_store_lanes_p allows an SLP tree to be split even
if the tree could use store-lanes, provided that one of the new
groups would operate on full vectors for each scalar iteration.
That heuristic is no longer firing for gcc.target/aarch64/pr99873_2.c.
The test contains:
void __attribute ((noipa))
foo (uint64_t *__restrict x, uint64_t *__restrict y, int n)
{
for (int i = 0; i < n; i += 4)
{
x[i] += y[i];
x[i + 1] += y[i + 1];
x[i + 2] |= y[i + 2];
x[i + 3] |= y[i + 3];
}
}
and wants us to use V2DI for the first two elements and V2DI for
the second two elements, rather than LD4s and ST4s. This gives:
The first loop only handles half the amount of data per iteration,
but it requires far fewer internal permutations.
One reason the heuristic no longer fired looks like a typo: the call
to vect_slp_prefer_store_lanes_p was passing "1" as the new group size,
instead of "i".
However, even with that fixed, vect_analyze_slp later falls back on
single-lane SLP with load/store lanes. I think that heuristic too
should use vect_slp_prefer_store_lanes_p (but it otherwise looks good).
The question is whether every load should pass
vect_slp_prefer_store_lanes_p or whether just one is enough.
I don't have an example that would make the call either way,
so I went for the latter, given that it's the smaller change
from the status quo.
This also appears to improve fotonik3d and roms from SPEC2017
(cross-checked against two different systems).
gcc/
* tree-vect-slp.cc (vect_build_slp_instance): Pass the new group
size (i) rather than 1 to vect_slp_prefer_store_lanes_p.
(vect_analyze_slp): Only force the use of load-lanes and
store-lanes if that is preferred for at least one load/store pair.
libstdc++: fix compile error when converting std::weak_ptr<T[]>
A std::weak_ptr<T[]> can be converted to a compatible
std::weak_ptr<U[]>. This is implemented by having suitable converting
constructors to std::weak_ptr which dispatch to the __weak_ptr base
class (implementation detail).
In __weak_ptr<T[]>, lock() is supposed to return a __shared_ptr<T[]>,
not a __shared_ptr<element_type> (that is, __shared_ptr<T>).
Unfortunately the return type of lock() and the type of the returned
__shared_ptr were mismatching and that was causing a compile error: when
converting a __weak_ptr<T[]> to a __weak_ptr<U[]> through __weak_ptr's
converting constructor, the code calls lock(), and that simply fails to
build.
Fix it by removing the usage of element_type inside lock(), and using
_Tp instead.
Note that std::weak_ptr::lock() itself was already correct; the one in
__weak_ptr was faulty (and that is the one called by __weak_ptr's
converting constructors).
libstdc++-v3/ChangeLog:
* include/bits/shared_ptr_base.h (lock): Fixed a compile error
when calling lock() on a weak_ptr<T[]>, by removing an
erroneous usage of element_type from within lock().
* testsuite/20_util/shared_ptr/requirements/explicit_instantiation/1.cc:
Add more tests for array types.
* testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc:
Likewise.
* testsuite/20_util/shared_ptr/requirements/1.cc: New test.
* testsuite/20_util/weak_ptr/requirements/1.cc: New test.
Richard Biener [Fri, 7 Mar 2025 11:57:42 +0000 (12:57 +0100)]
tree-optimization/119155 - wrong aligned access for vectorized packed access
When doing strided SLP vectorization we use the wrong alignment for
the possibly piecewise access of the vector elements for loads and
stores. While we are carefully using element aligned loads and
stores that isn't enough for the case the original scalar accesses
are packed. The following instead honors larger alignment when
present but correctly falls back to the original scalar alignment
used.
PR tree-optimization/119155
* tree-vect-stmts.cc (vectorizable_store): Do not always
use vector element alignment for VMAT_STRIDED_SLP but
a more correct alignment towards both ends.
(vectorizable_load): Likewise.
Sandra Loosemore [Wed, 12 Mar 2025 23:36:17 +0000 (23:36 +0000)]
Doc: Remove redundant info from documentation of -ansi.
The -ansi option has essentially been superseded by the more general
-std= option, and all the additional information about its effects is
already covered elsewhere in the manual. I also cleaned up some
confusing text about alternate keywords that I noticed while
confirming this.
gcc/ChangeLog
* doc/extend.texi (Alternate Keywords): Clean up text and remove
discussion of "restrict", which is not a GNU extension at all.
* doc/invoke.texi (C Dialect Options): Remove detailed discussion.
Patrick Palka [Thu, 13 Mar 2025 23:55:00 +0000 (19:55 -0400)]
libstdc++: Work around C++20 tuple<tuple<any>> constraint recursion [PR116440]
The type tuple<tuple<any>> is clearly copy/move constructible, but for
reasons that are not yet completely understood checking this triggers
constraint recursion with our C++20 tuple implementation (but not the
C++17 implementation).
It turns out this recursion stems from considering the non-template
tuple(const _Elements&) constructor during the copy/move constructibility
check. Considering this constructor is ultimately redundant, since the
defaulted copy/move constructors are better matches.
GCC has a non-standard "perfect candidate" optimization[1] that causes
overload resolution to shortcut considering template candidates if we
find a (non-template) perfect candidate. So to work around this issue
(and as a general compile-time optimization) this patch turns the
problematic constructor into a template so that GCC doesn't consider it
when checking for copy/move constructibility of this tuple type.
Changing the template-ness of a constructor can affect overload
resolution (since template-ness is a tiebreaker) so there's a risk this
change could e.g. introduce overload resolution ambiguities. But the
original C++17 implementation has long defined this constructor as a
template (in order to constrain it etc), so doing the same thing in the
C++20 mode should naturally be quite safe.
The testcase still fails with Clang (in C++20 mode) since it doesn't
implement said optimization.
Jan Hubicka [Thu, 13 Mar 2025 19:11:02 +0000 (20:11 +0100)]
Fix speculation_useful_p
This patch fixes issue with speculation and x264. With profile feedback
we first introduce speculative calls to mc_chroma which is called indirectly.
Then we propagate constants acorss these calls (which is useful transform) but
then speculation_useful_p decides that these speculations are not useful and
we end up calling unspecialized version.
This patch updates speculation_useful_p to consider edges redirected earlier
to clones as useful, since we can expect that ipa-cp knows what it is doing
(originally it only looked for inlined calls). I also noticed that we want
to keep edges even if they are not hot.
Finally I noticed a typo in computing target in code which intends to keep
devirtualized calls to functions where we propagated pureness/constness. Newly
we also track ipa-modref summaries as they also may be useful.
gcc/ChangeLog:
PR ipa/119147
* ipa-inline.cc: Include ipa-modref-tree.h and
ipa-modref.h.
(speculation_useful_p): If target is a clone, speculation is usef;
fix mixup of caller and callee; speculate also calls not considered
hot; consider modref summary also possibly useful for optimization.
* ipa-profile.cc (ipa_profile): Keep non-hot speculations.
Harald Anlauf [Thu, 13 Mar 2025 17:46:54 +0000 (18:46 +0100)]
Fortran: improve checking of substring bounds [PR119118]
Commit r15-7873 copy-pasted erroneous code containing a non-terminating
loop that did not progress its control variable, and a switch statement
with an unhandled case leading to a gcc_unreachable () with suitable input.
PR fortran/119118
gcc/fortran/ChangeLog:
* dependency.cc (contains_forall_index_p): Let loop over elements
of a constructor update its control variable. Handle REF_INQUIRY
in switch statement.
(gfc_contains_implied_index_p): Likewise.
Iain Sandoe [Mon, 10 Mar 2025 08:44:41 +0000 (08:44 +0000)]
testsuite, gm2: Use -B option for libstdc++ where required.
We need to add testsuite options to locate gm2 libs and libstdc++.
Usually '-L' options are added to point to the relevant directories for
the uninstalled libraries.
In cases where libraries are available as both shared and convenience some
additional checks are made.
For some targets -static-xxxx options are handled by specs substitution and
need a '-B' option rather than '-L'. For Darwin, when embedded runpaths are
in use (the default for all versions after macOS 10.11), '-B' is also needed
to provide the runpath.
When '-B' is used, this results in a '-L' for each path that exists (so that
appending a '-L' as well is a needless duplicate). There are also cases
where tools warn for duplicates, leading to spurious fails.
Therefore the objective of the code here is to add just one '-L' or '-B' for
each of the libraries.
Currently, we are forcing the full paths to each of the gm2 convenience libs
onto the link line and therefore the B/L logic is not needed there. It would
need to be added if/when gm2 is tested with shared libraries
gcc/testsuite/ChangeLog:
* lib/gm2.exp: Arrange for a '-B' option to be added for the
libstdc++ paths on targets that need it.
Among other things, this testcase tests an addition of the four
values (n*4+[0:3])*9//2 for each n in [0:99]. The addition is
done in multiple integer and floating-point types and the test
is compiled with -ffast-math.
One of the floating-point types is _Float16, and as Andrew says
in the PR, _Float16's limited precision means that the order of the
additions begins to matter for higher n. Specifically, some orders
begin to give different results from others at n=38, and at many
higher n as well.
This patch uses 5/3 rather than 9/2. I tested locally that
all addition orders give the same result over the test range.
gcc/testsuite/
PR testsuite/113965
* gcc.target/aarch64/sve/mask_struct_load_3_run.c: Use an
input range that is suitable for _Float16.
Jonathan Wakely [Thu, 13 Mar 2025 14:10:00 +0000 (14:10 +0000)]
libstdc++: Implement <stdckdint.h> for C++26 (P3370R1)
This is the second part of the P3370R1 proposal just approved by the
committee in Wrocław. This adds C++ equivalents of the functions added
to C23 by WG14 N2683.
These functions are in the global namespace, but to avoid collisions
with the same functions defined by other standard library
implementations, this change defines them in namespace __gnu_cxx and
then adds them to the global namespace.
libstdc++-v3/ChangeLog:
* include/Makefile.am: Add stdckdint.h.
* include/Makefile.in: Regenerate.
* src/c++23/std.compat.cc.in: Export <stdckdint.h> functions.
* include/c_compatibility/stdckdint.h: New file.
* testsuite/26_numerics/stdckdint/1.cc: New test.
* testsuite/26_numerics/stdckdint/2_neg.cc: New test.
Jonathan Wakely [Thu, 13 Mar 2025 13:34:55 +0000 (13:34 +0000)]
libstdc++: Implement <stdbit.h> for C++26 (P3370R1)
This is the first part of the P3370R1 proposal just approved by the
committee in Wrocław. This adds C++ equivalents of the functions added
to C23 by WG14 N3022.
These functions are in the global namespace, but to avoid collisions
with the same functions defined by other standard library
implementations, this change defines them in namespace __gnu_cxx and
then adds them to the global namespace.
libstdc++-v3/ChangeLog:
* include/Makefile.am: Add stdbit.h.
* include/Makefile.in: Regenerate.
* src/c++23/std.compat.cc.in: Export <stdbit.h> functions.
* include/c_compatibility/stdbit.h: New file.
* testsuite/20_util/stdbit/1.cc: New test.
* testsuite/20_util/stdbit/2_neg.cc: New test.