Commit Graph

224691 Commits

Author SHA1 Message Date
GCC Administrator
29ea6d141e Daily bump. 2025-11-07 00:20:18 +00:00
Sandra Loosemore
eb88c84cf7 AArch64, ARM: Clean up documentation of -mbranch-protection.
While working on other things, I noticed that the documentation for
the -mbranch-protection= option was pretty garbled on both aarch64 and
arm targets, with incorrect markup, too much syntax crammed into the
option summary, and confusion about what the values "+leaf" modifier
can apply to.  I rewrote it to list all the valid option values
explicitly in the option description, checking this against the
implementation.

gcc/ChangeLog
	* doc/invoke.texi (AArch64 Options): Clean up description of
	-mbranch-protection= argument.
	(ARM Options): Likewise.
2025-11-06 22:30:44 +00:00
Alejandro Colomar
e5b5a1322d doc: Move _Countof under 'Other Extensions to C Syntax'
gcc/ChangeLog:

	* doc/extend.texi: Move _Countof under 'Syntax Extensions'.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-06 21:23:03 +00:00
Jerry DeLisle
9636d90e43 fortran: [PR121628]
This patch fixes PR121628 by implementing proper deep copy semantics for
derived types containing recursive allocatable array components, in
compliance with Fortran 2018+ standards.

The original implementation would generate infinitely recursive code at
compile time when encountering self-referential derived types with
allocatable components (e.g., type(t) containing allocatable type(t)
arrays). This patch solves the problem by generating a runtime helper
function that performs element-wise deep copying, avoiding compile-time
recursion while maintaining correct assignment semantics.

The trans-intrinsic.cc change enhances handling of constant values in
coarray atomic operations to ensure temporary variables are created when
needed, avoiding invalid address-of-constant expressions.

gcc/fortran/ChangeLog:

	PR fortran/121628
	* trans-array.cc (get_copy_helper_function_type): New function to
	create function type for element copy helpers.
	(get_copy_helper_pointer_type): New function to create pointer type
	for element copy helpers.
	(generate_element_copy_wrapper): New function to generate runtime
	helper for element-wise deep copying of recursive types.
	(structure_alloc_comps): Detect recursive allocatable array
	components and use runtime helper instead of inline recursion.
	Add includes for cgraph.h and function.h.
	* trans-decl.cc (gfor_fndecl_cfi_deep_copy_array): New declaration
	for runtime deep copy helper.
	(gfc_build_builtin_function_decls): Initialize the runtime helper
	declaration.
	* trans-intrinsic.cc (conv_intrinsic_atomic_op): Enhance handling of
	constant values in coarray atomic operations by detecting and
	materializing address-of-constant expressions.
	* trans.h (gfor_fndecl_cfi_deep_copy_array): Add external declaration.

libgfortran/ChangeLog:

	PR fortran/121628
	* Makefile.am: Add runtime/deep_copy.c to source files.
	* Makefile.in: Regenerate.
	* gfortran.map: Export _gfortran_cfi_deep_copy_array symbol.
	* libgfortran.h: Add prototype for internal_deep_copy_array.
	* runtime/deep_copy.c: New file implementing runtime deep copy
	helper for recursive allocatable array components.

gcc/testsuite/ChangeLog:

	PR fortran/121628
	* gfortran.dg/alloc_comp_deep_copy_5.f90: New test for recursive
	allocatable array deep copy.
	* gfortran.dg/alloc_comp_deep_copy_6.f90: New test for multi-level
	recursive allocatable deep copy.
	* gfortran.dg/array_memcpy_2.f90: Fix test with proper allocation.

	Signed-off-by: Christopher Albert <albert@tugraz.at>
2025-11-06 12:58:45 -08:00
Eric Botcazou
3dbca5ff67 Ada: Fix function call in object notation incorrectly rejected
This happens in the name of a procedure call, again when there
is an implicit dereference in this name, and the fix to apply to
Find_Selected_Component is again straightforward:

--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -8524,9 +8524,7 @@ package body Sem_Ch8 is
          --  Error if the prefix is procedure or entry, as is P.X

          if Ekind (P_Name) /= E_Function
-           and then
-             (not Is_Overloaded (P)
-               or else Nkind (Parent (N)) = N_Procedure_Call_Statement)
+           and then not Is_Overloaded (P)
          then
             --  Prefix may mention a package that is hidden by a local
             --  declaration: let the user know. Scan the full homonym

But this also changes the diagnostics in illegal cases because they are not
uniform in the procedure, so the change also factors them out so as to make
them uniform, which slightly improves them in the end.

gcc/ada/
	PR ada/113352
	* sem_ch4.adb (Diagnose_Call): Tweak error message.
	* sem_ch8.adb (Find_Selected_Component): Remove bypass for calls
	to procedures in the overloaded overloadable case.  Factor out
	the diagnostics code and invoke it uniformly in this case.

gcc/testsuite/
	* gnat.dg/prefix3.adb: New test.
	* gnat.dg/prefix3_pkg.ads: New helper.
	* gnat.dg/prefix3_pkg.adb: Likewise.
2025-11-06 20:47:18 +01:00
Ian Lance Taylor
1ae7073586 libbacktrace: use correct names in #undef of ELF macros
Patch from Joseph Koshy.

	* elf.c (ELFMAGn): In #undef rename from ELF_MAGn.
2025-11-06 11:30:12 -08:00
Georg-Johann Lay
d5ede6fff1 AVR: target/122516: Make attribute "retain" work.
Due to some quirks in crtstuff.c, attribute "retain" requires
some features that avr doesn't implement -- even though it
doesnt't even use crtstuff.  This patch works around that.

	PR target/122516
gcc/
	* config/avr/elf.h (SUPPORTS_SHF_GNU_RETAIN): Define if
	HAVE_GAS_SHF_GNU_RETAIN.
2025-11-06 20:26:50 +01:00
Jeff Law
d277d4e374 [RISC-V] Ignore useless zero-initialization in conditional move sequence costing
Let's consider this code fragment (from xalan):

bool isValidAncestorType(int type) {
    if (type == 0 || type == 6 || type == 4) {
            return true;
    }
    return false;
}

Right now it generates something like this for RISC-V with Zicond enabled:

>         li      a5,6
>         bgtu    a0,a5,.L3
>         li      a5,81
>         bext    a0,a5,a0
>         ret
> .L3:
>         li      a0,0
>         ret

But there's a clearly better sequence.  LLVM for example generates:

>         addi    a1, a0, -6
>         seqz    a1, a1
>         andi    a0, a0, -5
>         seqz    a0, a0
>         or      a0, a1, a0

And with a little work GCC can generate this (which is probably better than
LLVM's codegen ever-so-slightly):

>         li      a4,6            # 8     [c=4 l=4]  *movdi_64bit/1
>         li      a5,81           # 33    [c=4 l=4]  *movdi_64bit/1
>         bext    a5,a5,a0        # 36    [c=4 l=4]  *bextdi
>         sgtu    a0,a0,a4        # 38    [c=4 l=4]  *sgtu_didi
>         czero.nez       a0,a5,a0        # 39    [c=4 l=4]  *czero.nez.didi

There's multiple ways Daniel B. and I looked at to resolve this.  At the core
the failure to if-convert is a cost model problem.

We could try to generate more efficient code out of cmove_arith.  What we're
currently getting out of that routine is horribly bad:

```
> (insn 10 3 34 2 (set (reg:DI 138)
>         (const_int 6 [0x6])) 277 {*movdi_64bit}
>      (nil))
> (insn 34 10 35 2 (set (reg:DI 145)
>         (const_int 0 [0])) 277 {*movdi_64bit}
>      (nil)) (insn 35 34 36 2 (set (reg:DI 141)
>         (const_int 81 [0x51])) 277 {*movdi_64bit}
>      (nil))
> (insn 36 35 37 2 (set (reg:DI 140 [ _3 ])
>         (lshiftrt:DI (reg:DI 141)                    (subreg:QI (reg/v:DI 137 [ type ]) 0))) 301 {lshrdi3}
>      (nil))
> (insn 37 36 38 2 (set (reg:DI 143)
>         (and:DI (reg:DI 140 [ _3 ])
>             (const_int 1 [0x1]))) 106 {*anddi3}
>      (nil))
> (insn 38 37 40 2 (set (reg:DI 146)
>         (zero_extend:DI (subreg:QI (reg:DI 143) 0))) 126 {*zero_extendqidi2_internal}
>      (nil)) (insn 40 38 41 2 (set (reg:DI 147)
>         (gtu:DI (reg/v:DI 137 [ type ])
>             (reg:DI 138))) 428 {*sgtu_didi}
>      (nil))
> (insn 41 40 42 2 (set (reg:DI 149)         (if_then_else:DI (ne:DI (reg:DI 147)
>                 (const_int 0 [0]))
>             (const_int 0 [0])
>             (reg:DI 146))) 40369 {*czero.nez.didi}
>      (nil))
> (insn 42 41 43 2 (set (reg:DI 148)
>         (if_then_else:DI (eq:DI (reg:DI 147)
>                 (const_int 0 [0]))             (const_int 0 [0])
>             (reg:DI 145))) 40368 {*czero.eqz.didi}
>      (nil))
> (insn 43 42 25 2 (set (reg:DI 136 [ <retval> ])
>         (plus:DI (reg:DI 148)
>             (reg:DI 149))) 5 {*adddi3}

```

In particular note insn 34, 42 and 43.  Those are useless.  Insns 36, 37, 38
are just a single bit extraction from a variable location (from one of the
if-converted blocks).  I couldn't see a good way to fix the problem with insn
34/insn 42.  The desire to make the then/else blocks independent is cmove_arith
is good, what's unclear is whether or not that code really cares about the
*destination* of the then/else blocks. But I set that aside.

We then thought that cleaning up the variable bit extraction would be the way
to go.  So a pattern was constructed to match that form of variable bit extract
and the cost model was twiddled to return that it was a single fast
instruction.  But even with those changes fwprop1 refused to make the
substitution.  Sigh.  At least combine recognizes the idiom later and cleans it
up.

Then we realized we really should just ignore the (set (reg) (const_int 0)) in
the if-converted sequence.  We're going to be able to propagate that away in
nearly every case since we have a hard-wired zero register.  Sure enough,
ignoring that insn was enough to tip the balance on this case and we get the
desired code.

Tested on riscv32-elf and riscv64-elf.  Pioneer bootstrap is in flight, though
it won't really exercise this problem.  The BPI's build hasn't started yet, so
it'll be at least 27hours before it's done.

Waiting on pre-commit CI before moving forward.

gcc/

	* config/riscv/riscv.cc (riscv_noce_conversion_profitable_p): Ignore
	assignments of (const_int 0) to a register.  They will get propagated
	away.

gcc/testsuite
	* gcc.target/riscv/czero-bext.c: New test.
2025-11-06 12:19:40 -07:00
Eric Botcazou
9cc7722674 Ada: Fix incorrect renaming of primitive subprogram in object notation
It is possible to declare a subprogram renaming whose name is a primitive
subprogram in object notation; in this case, the name is unconditionally
evaluated in the front-end (unlike for objects) so that, if an ad-hoc body
needs to be built for the renaming later, the name is not reevaluated for
every call to it.

This evaluation is skipped if the name contains an implicit dereference,
as reported in the first PR, and the fix is to make the dereference explicit
at the end of the processing done in Analyze_Renamed_Primitive_Operation,
as is done in the sibling procedure Analyze_Renamed_Entry.  The patch also
makes a few consistency tweaks to them and also replaces a manual evaluation
of the name in Expand_N_Subprogram_Renaming_Declaration by a simple call to
Evaluate_Name, which is the procedure used for object renamings.

Analyze_Renamed_Primitive_Operation performs the resolution of the name
based on the declared profile, but it does not do that correctly in all
cases, as reported in the second PR; the fix is again straightforward.

gcc/ada/
	PR ada/113350
	PR ada/113551
	* exp_ch2.adb (Expand_Renaming): Fix reference to Evaluate_Name.
	* exp_ch8.adb (Expand_N_Subprogram_Renaming_Declaration): Call
	Evaluate_Name to evaluate the name.
	* sem_ch8.adb (Analyze_Renamed_Entry): Minor tweaks.
	(Analyze_Renamed_Family_Member): Likewise.
	(Analyze_Renamed_Primitive_Operation): Likewise.
	Fix thinko in the function checking profile conformance, save the
	result of the resolution and make implicit dereferences explicit.

gcc/testsuite
	* gnat.dg/renaming19.adb: New test.
	* gnat.dg/renaming19_pkg.ads: New helper.
	* gnat.dg/renaming19_pkg.adb: Likewise.
2025-11-06 20:16:46 +01:00
Georg-Johann Lay
d79d12d3fa AVR: AVR-SD: Put a valid opcode prior to gs() table in .subsection 1.
On functional safety devices (AVR-SD), each executed instruction must
be followed by a valid opcode.  This is because instruction fetch and
decode for the next instruction runs while the 2-stage pipeline is
executing the current instruction.

There is only one case where avr-gcc generates code interspersed with
data, which is when a switch/case table is generated for a function
with a "section" attribute and AVR_HAVE_JMP_CALL.  In that case, the
table with the gs() code label addresses is put in .subsection 1 so
that it belongs to the section as specified by the "section" attribute.

gcc/
	* config/avr/avr.cc (avr_output_addr_vec): Output
	a valid opcode prior to the first gs() label provided:
	- The code is compiled for an arch that has AVR-SD mcus, and
	- the function has a "section" attribute, and
	- the function has a gs() label addresses switch/case table.
2025-11-06 20:06:11 +01:00
Your Name
5e93ab0da7 [RISC-V][PR 121136] Improve various tests which only need to examine upper bits in a GPR
So pre-commit CI flagged an issue with the initial version of this patch.  In
particular the cmp-mem-const-{1,2} tests are failing.

I didn't see that in my internal testing, but that well could be an artifact of
having multiple patches touching in the same broad space that the tester is
evaluating.  If I apply just this patch I can trigger the cmp-mem-const{1,2}
failures.

The code we're getting now is actually better than we were getting before, but
the new patterns avoid the path through combine that emits the message about
narrowing the load down to a byte load, hence the failure.

Given we're getting better code now than before, I'm just skipping this test on
risc-v.    That's the only non-whitespace change since the original version of
this patch.

--

This addresses the first level issues seen in generating better performing code
for testcases derived from pr121136.  It likely regresses code size in some
cases as in many cases it selects code sequences that should be better
performing, though larger to encode.

Improving -Os code generation should remain the primary focus of pr121136.  Any
improvements in code size with this change are a nice side effect, but not the
primary goal.

--

Let's take this test (derived from the PR):

_Bool func1_0x1U (unsigned int x) { return x <= 0x1U; }

_Bool func2_0x1U (unsigned int x) { return ((x >> __builtin_ctz (0x1U + 1U)) == 0); }

_Bool func3_0x1U (unsigned int x) { return ((x / (0x1U + 1U)) == 0); }

Those should produce the same output.  We currently get these fragments for the
3 cases.  In particular note how the second variant is a two instruction
sequence.

        sltiu   a0,a0,2

        srliw   a0,a0,1
        seqz    a0,a0

        sltiu   a0,a0,2

This patch will adjust that second sequence to match the first and third and is
optimal.

Let's take another case.  This is interesting as it's right at the simm12
border:

_Bool func1_0x7ffU (unsigned long x) { return x <= 0x7ffU; }

_Bool func2_0x7ffU (unsigned long x) { return ((x >> __builtin_ctzl (0x7ffU + 1UL)) == 0); }

_Bool func3_0x7ffU (unsigned long x) { return ((x / (0x7ffU + 1UL)) == 0); }

We get:

        li      a5,2047
        sltu    a0,a5,a0
        seqz    a0,a0

        srli    a0,a0,11
        seqz    a0,a0

        li      a5,2047
        sltu    a0,a5,a0
        seqz    a0,a0

In this case the second sequence is pretty good.  Not perfect, but clearly
better than the other two.  This patch will fix the code for case #1 and case

So anyway, that's the basic motivation here.  So to be 100% clear, while the
bug is focused on code size, I'm focused on the performance of the resulting
code.

This has been tested on riscv32-elf and riscv64-elf.  It's also bootstrapped
and regression tested on the Pioneer.  The BPI won't have results for this
patch until late tomorrow.

--

	PR rtl-optimization/121136
gcc/
	* config/riscv/riscv.md: Add define_insn to test the
	upper bits of a register against zero using sltiu when
	the bits are extracted via zero_extract or logial right shift.
	Add 3->2 define_splits for gtu/leu cases testing upper bits
	against zero.

gcc/testsuite
	* gcc.target/riscv/pr121136.c: New test.
	* gcc.dg/cmp-mem-const-1.c: Skip for risc-v.
	* gcc.dg/cmp-mem-const-2.c: Likewise.
2025-11-06 09:50:22 -07:00
Richard Biener
6c56609915 Add GTY skip to active_iterated_stmt
The following should fix a disable-checking build which seems to
confuse gengtype.

	* tree-core.h (tree_ssa_name::active_iterated_stmt): Mark
	GTY((skip(""))).
2025-11-06 15:57:24 +01:00
Robert Dubner
1139d69306 cobol: Mainly extends compilation and execution in finternal-ebcdic.
We expanded our extended testing regime to execute many testcases in
EBCDIC mode as well as in ASCII. This exposed hundreds of problems in
both compilation (where conversions must be made between the ASCII
source code and the EBCDIC execution environment) and in run-time
functionality, where results from calls to system routines and internal
calculations that must be done in ASCII have to be converted to EBCDIC.

These changes also switch to using FIXED_WIDE_INT(128) instead of
REAL_VALUE_TYPE when initializing fixed-point COBOL variable types.
This provides for accurate initialization up to 37 digits, instead of
losing accuracy after 33 digits.

These changes also support the implementation of the COBOL DELETE FILE
(Format 2) statement.

These changes also introduce expanded support for specifying character
encodings, including support for locales.

co-authored-by: Robert Dubner <rdubner@symas.com>
co-authored-by: James K. Lowden <jklowden@cobolworx.com>

gcc/cobol/ChangeLog:

	* Make-lang.in: Repair documentation generation.
	* cdf.y: Changes to tokens.
	* cobol1.cc (cobol_langhook_handle_option): Add comment.
	* genapi.cc (function_pointer_from_name): Use data.original() for
	function name.
	(parser_initialize_programs): Likewise.
	(cobol_compare): Make sure encodings of comparands are the same.
	(move_tree): Change name of DEFAULT_SOURCE_ENCODING macro.
	(parser_enter_program): Typo.
	(psa_FldLiteralN): Break out dirty_to_binary() support routine.
	(dirty_to_binary): Likewise.
	(parser_alphabet): Rename 'alphabet' to 'collation_sequence'.
	(parser_allocate): Change wsclear() to be uint32_t instead of char.
	(parser_label_label): Formatting.
	(parser_label_goto): Likewise.
	(get_the_filename): Breakout get_the_filename(), which handles
	encoding.
	(parser_file_open): Likewise.
	(set_up_delete_file_label): Implement DELETE FILE (Format 2).
	(parser_file_delete_file): Likewise.
	(parser_file_delete_on_exception): Likewise.
	(parser_file_delete_not_exception): Likewise.
	(parser_file_delete_end): Likewise.
	(parser_call): Use data.original().
	(parser_entry): Use data.original().
	(mh_source_is_literalN): Convert from
	sourceref.field->codeset.encoding.
	(binary_initial_from_float128): Change to "binary_initial".
	(binary_initial): Calculate in FIXED_WIDE_INT(128) instead of
	REAL_VALUE_TYPE.
	(digits_from_int128): New routine uses binary_initial.
	(digits_from_float128): Removed.  Kept as comment for reference.
	(initial_from_initial): Use binary_initial.
	(actually_create_the_static_field): Use correct encoding.
	(parser_symbol_add): Likewise.
	* genapi.h (parser_file_delete_file): Implement FILE DELETE.
	(parser_file_delete_on_exception): Implement FILE DELETE.
	(parser_file_delete_not_exception): Implement FILE DELETE.
	(parser_file_delete_end): Implement FILE DELETE.
	* genmath.cc: Include charmaps.h.
	* genutil.cc (get_literal_string):  Change name of
	DEFAULT_SOURCE_ENCODING macro.
	* parse.y: Token changes; numerous changes in support of encoding;
	support for DELETE FILE.
	* parse_ante.h (name_of): Use data.original().
	(class prog_descr_t): Support of locales.
	(current_options): Formatting.
	(current_encoding):  Formatting.
	(current_program_index): Formatting.
	(current_section): Formatting.
	(current_paragraph): Formatting.
	(is_integer_literal): Use correct encoding.
	(value_encoding_check): Handle encoding changes.
	(alphabet_add): Likewise.
	(data_division_ready): Likewise.
	* scan.l: Use data.original().
	* show_parse.h: Use correct encoding.
	* symbols.cc (elementize): Likewise.
	(symbol_elem_cmp): Handle locale.
	(struct symbol_elem_t): Likewise.
	(symbol_locale): Likewise.
	(field_str): Change DEFAULT_SOURCE_ENCODING macro name.
	(symbols_alphabet_set): Formatting.
	(symbols_update): Modify consistency checks.
	(symbol_locale_add): Locale support.
	(cbl_locale_t::cbl_locale_t): Locale support.
	(cbl_alphabet_t::cbl_alphabet_t): New structure.
	(cbl_alphabet_t::reencode): Formatting.
	(cbl_alphabet_t::assign): Change name of collation_sequence.
	(cbl_alphabet_t::also): Likewise.
	(new_literal_add): Anticipate the need for four-byte characters.
	(guess_encoding): Eliminate.
	(cbl_field_t::internalize): Refine conversion of data.initial to
	specified encoding.
	* symbols.h (enum symbol_type_t): Add SymLocale.
	(struct cbl_field_data_t): Incorporate data.orig.
	(struct cbl_field_t): Likewise.
	(struct cbl_delete_file_t): New structure.
	(struct cbl_label_t): Incorporate cbl_delete_file_t.
	(struct cbl_locale_t): Support for locale.
	(hex_decode): Comment.
	(struct cbl_alphabet_t): Incorporate locale; change variable name
	to collation_sequence.
	(struct symbol_elem_t): Incorporate locale.
	(cbl_locale_of): Likewise.
	(cbl_alphabet_of): Likewise.
	(symbol_locale_add): Likewise.
	(wsclear): Type is now uint32_t instead of char.
	* util.cc (symbol_type_str):  Incorporate locale.
	(cbl_field_t::report_invalid_initial_value): Change test so that
	pure PIC A() variables are limited to [a-zA-Z] and space.
	(valid_move): Use DEFAULT_SOURCE_ENCODING macro.
	(cobol_filename): Formatting.

libgcobol/ChangeLog:

	* charmaps.cc (__gg__encoding_iconv_type): Eliminate trailing
	'/' characters from encoding names.
	(__gg__get_charmap): Switch to DEFAULT_SOURCE_ENCODING macro name.
	* charmaps.h (DEFAULT_CHARMAP_SOURCE): Likewise.
	(DEFAULT_SOURCE_ENCODING): Likewise.
	(class charmap_t): Enhance constructor.
	* encodings.h (valid_encoding): New routine.
	* gcobolio.h (enum cblc_file_prior_op_t): Support DELETE FILE.
	* gfileio.cc (get_filename): Likewise.
	(__io__file_remove): Likewise.
	(__gg__file_reopen): Likewise.
	(__io__file_open): Likewise.
	(gcobol_fileops): Likewise.
	(__gg__file_delete): Likewise.
	(__gg__file_remove): Likewise.
	* intrinsic.cc (get_all_time):  Switch to DEFAULT_SOURCE_ENCODING
	macro name.
	(ftime_replace): Support ASCII/EBCDIC encoding.
	(__gg__current_date): Likewise.
	(__gg__max): Likewise.
	(__gg__lower_case): Likewise.
	(numval): Likewise.
	(numval_c): Likewise.
	(__gg__upper_case): Likewise.
	(__gg__when_compiled): Likewise.
	(gets_int): Likewise.
	(gets_nanoseconds): Likewise.
	(fill_cobol_tm): Likewise.
	(floating_format_tester): Likewise.
	(__gg__numval_f): Likewise.
	(__gg__test_numval_f): Likewise.
	(iscasematch): Likewise.
	(strcasestr): Likewise.
	(strcaselaststr): Likewise.
	(__gg__substitute): Likewise.
	(__gg__locale_compare): Support for locale.
	(__gg__locale_date): Likewise.
	(__gg__locale_time): Likewise.
	(__gg__locale_time_from_seconds): Likewise.
	* libgcobol.cc (class ec_status_t): Support for encoding.
	(int128_to_field): Likewise.
	(__gg__dirty_to_float): Likewise.
	(format_for_display_internal): Likewise.
	(get_float128): Likewise.
	(compare_field_class): Likewise.
	(__gg__compare_2): Likewise.
	(init_var_both): Likewise.
	(__gg__move): Likewise.
	(display_both): Likewise.
	(is_numeric_display_numeric): Likewise.
	(accept_envar): Likewise.
	(__gg__get_argv): Likewise.
	(__gg__unstring): Likewise.
	(__gg__check_fatal_exception): Likewise.
	(__gg__adjust_encoding): Likewise.
	(__gg__func_exception_location): Likewise.
	(__gg__func_exception_statement): Likewise.
	(__gg__func_exception_status): Likewise.
	(__gg__func_exception_file): Likewise.
	(__gg__just_mangle_name): Likewise.
	(__gg__function_handle_from_name): Likewise.
	(get_the_byte): Likewise.
	(__gg__module_name): Likewise.
	(__gg__accept_arg_value): Likewise.
	* xmlparse.cc (fatalError): Formatting.
	(setDocumentLocator): Formatting.
	(xmlchar_of): Formatting.
	(xmlParserErrors_str): Formatting.
2025-11-06 08:57:54 -05:00
Richard Biener
e82a29a9a7 SSA immediate use iterator checking
The following implements additional checking around
SSA immediate use iteration.  Specifically this prevents

 - any nesting of FOR_EACH_IMM_USE_STMT inside another iteration
   via FOR_EACH_IMM_USE_STMT or FOR_EACH_IMM_USE_FAST when iterating
   on the same SSA name

 - modification (for now unlinking of immediate uses) of a SSA
   immediate use list when a fast iteration of the immediate uses
   of the SSA name is active

 - modification (for now unlinking of immediate uses) of the immediate
   use list outside of the block of uses for the currently active stmt
   of an ongoing FOR_EACH_IMM_USE_STMT of the SSA name

To implement this additional bookkeeping members are put into the
SSA name structure when ENABLE_GIMPLE_CHECKING is active.  I have
kept the existing consistency checking of the fast iterator.

	* ssa-iterators.h (imm_use_iterator::name): Add.
	(delink_imm_use): When in a FOR_EACH_IMM_USE_STMT iteration
	enforce we only remove uses from the current stmt.
	(end_imm_use_stmt_traverse): Reset current stmt.
	(first_imm_use_stmt): Assert no FOR_EACH_IMM_USE_STMT on
	var is in progress.  Set the current stmt.
	(next_imm_use_stmt): Set the current stmt.
	(auto_end_imm_use_fast_traverse): New, lower iteration
	depth upon destruction.
	(first_readonly_imm_use): Bump the iteration depth.
	* tree-core.h (tree_ssa_name::active_iterated_stmt,
	tree_ssa_name::fast_iteration_depth): New members when
	ENABLE_GIMPLE_CHECKING.
	* tree-ssanames.cc (make_ssa_name_fn): Initialize
	immediate use verifier bookkeeping members.
2025-11-06 14:56:13 +01:00
Richard Biener
9ded9b80c1 Make FOR_EACH_IMM_USE_STMT work w/o fake imm use node
This is an attempt to fix PR122502 by making a FOR_EACH_IMM_USE_FAST
with in an FOR_EACH_IMM_USE_STMT on _the same_ VAR work without
the former running into the FOR_EACH_IMM_USE_STMT inserted marker
use operand.  It does this by getting rid of the marker.

The downside is that this in principle restricts the set of operations
that can be done on the immediate use list of VAR.  Where previously
almost anything was OK (but technically not well-defined what happens
to the iteration) after this patch you may only remove immediate
uses of VAR on the current stmt from the FOR_EACH_IMM_USE_STMT
iteration.  In particular things will break if you happen to remove
the one immediate use of VAR on the stmt immediately following
the set of immediate uses on the currrent stmt.

Additional checking to combat such cases is implemented in a
followup.

	PR tree-optimization/122502
	* ssa-iterators.h (imm_use_iterator::iter_node): Remove.
	(imm_use_iterator::next_stmt_use): New.
	(next_readonly_imm_use): Adjust checking code.
	(end_imm_use_stmt_traverse): Simplify.
	(link_use_stmts_after): Likewise.  Return the last use
	with the same stmt.
	(first_imm_use_stmt): Simplify.  Set next_stmt_use.
	(next_imm_use_stmt): Likewise.
	(end_imm_use_on_stmt_p): Adjust.

	* gcc.dg/torture/pr122502-2.c: New testcase.
2025-11-06 14:55:27 +01:00
Richard Biener
36c44c2d66 Update immediate use iterator documentation
This clarifies the constraints of the immediate use iterators,
documenting how exactly stmts and their immediate uses might be
altered during it.

	* doc/tree-ssa.texi: Update immediate use iterator
	documentation.
	* ssa-iterators.h: Likewise.
2025-11-06 14:55:27 +01:00
Andrew MacLeod
a137663b93 New XOR fold routine.
XOR goes to VARYING frequently with complex ranges. The other bitwise
operations are improved, so implement XOR using them as well.

	PR tree-optimization/113632
	gcc/
	* range-op-mixed.h (operator_bitwise_xor): Relocate and adjust.
	(operator_bitwise_xor::m_and, m_or, m_not): New.
	* range-op.cc (operator_bitwise_xor::fold_range): New.

	gcc/testsuite/
	* gcc.dg/pr113632.c: New.
2025-11-06 08:54:17 -05:00
Christophe Lyon
c35bab0819 testsuite: arm: fix arm_v8_vfp_ok effective-target
This effective-target does not need to check for arm32, but needs to
force -march=armv8-a, otherwise -mfpu=fp-armv8 has no useful meaning.

While fixing that, introduce
check_effective_target_arm_v8_vfp_ok_nocache, so that arm_v8_vfp_ok
behaves like arm_v8_neon_ok and many other effective-targets.

Without this patch, gcc.target/arm/attr-neon.c fails with a toolchain
configured with --with-mode=thumb --with-cpu=cortex-m0
--with-float=soft because arm_v8_vfp returns "" because arm32 is
false.  As a result, the testcase is compiled with the options needed
for arm_neon_ok, which generates an extra ".fpu neon" directive
compared to what is expected.

The patch removes -march=armv8-a from dg-options in lceil-vcvt_1.c,
lfloor-vcvt_1.c lround-vcvt_1.c and vrinta-ce.c, because this could
override what arm_v8_vfp_ok detected (and lead to 'error: selected
architecture lacks an FPU').

With this patch, the test passes, and several others are enabled:
gcc.target/arm/lceil-vcvt_1.c
gcc.target/arm/lfloor-vcvt_1.c
gcc.target/arm/lround-vcvt_1.c
gcc.target/arm/pr69135_1.c
gcc.target/arm/vmaxnmdf.c
gcc.target/arm/vmaxnmsf.c
gcc.target/arm/vminnmdf.c
gcc.target/arm/vminnmsf.c
gcc.target/arm/vrinta-ce.c
gcc.target/arm/vrintaf32.c
gcc.target/arm/vrintaf64.c
gcc.target/arm/vrintmf32.c
gcc.target/arm/vrintmf64.c
gcc.target/arm/vrintpf32.c
gcc.target/arm/vrintpf64.c
gcc.target/arm/vrintrf32.c
gcc.target/arm/vrintrf64.c
gcc.target/arm/vrintxf32.c
gcc.target/arm/vrintxf64.c
gcc.target/arm/vrintzf32.c
gcc.target/arm/vrintzf64.c
gcc.target/arm/vseleqdf.c
gcc.target/arm/vseleqsf.c
gcc.target/arm/vselgedf.c
gcc.target/arm/vselgesf.c
gcc.target/arm/vselgtdf.c
gcc.target/arm/vselgtsf.c
gcc.target/arm/vselledf.c
gcc.target/arm/vsellesf.c
gcc.target/arm/vselltdf.c
gcc.target/arm/vselltsf.c
gcc.target/arm/vselnedf.c
gcc.target/arm/vselnesf.c
gcc.target/arm/vselvcdf.c
gcc.target/arm/vselvcsf.c
gcc.target/arm/vselvsdf.c
gcc.target/arm/vselvssf.c

gcc/testsuite/ChangeLog:
	* lib/target-supports.exp
	(check_effective_target_arm_v8_vfp_ok_nocache): New.
	(check_effective_target_arm_v8_vfp_ok): Call the above helper, and
	use global flags.
	(add_options_for_arm_v8_vfp): Use et_arm_v8_vfp_flags.
	* gcc.target/arm/lceil-vcvt_1.c: Remove -march=armv8-a.
	* gcc.target/arm/lfloor-vcvt_1.c: Likewise.
	* gcc.target/arm/lround-vcvt_1.c: Likewise.
	* gcc.target/arm/vrinta-ce.c: Likewise.
2025-11-06 13:14:03 +00:00
Peter Damianov
f401c2b735 libiberty: Add BigObj COFF support for LTO on Windows targets [PR122472]
This patch adds support for the BigObj COFF object file format to libiberty's
simple-object-coff.c. BigObj extends regular COFF to support a 32-bit section
count.

BigObj differs from COFF in a few ways:

* A different header structure
* 32-bit section counts instead of 16-bit
* 32-bit symbol section numbers instead of 16-bit
* 20-byte symbols instead of 18-byte symbols
  (due to the extended section numbers)

For a more detailed summary, read my blog post on this subject:
https://peter0x44.github.io/posts/bigobj_format_explained/

libiberty/ChangeLog:

	PR target/122472
	* simple-object-coff.c (struct external_filehdr_bigobj): New
	structure for BigObj file header.
	(bigobj_magic): New constant for BigObj magic bytes.
	(struct external_syment_bigobj): New structure for BigObj
	20-byte symbol table entries.
	(union external_auxent_bigobj): New union for BigObj 20-byte
	auxiliary symbol entries.
	(struct simple_object_coff_read): Add is_bigobj flag and make
	nscns 32-bit to support both formats.
	(struct simple_object_coff_attributes): Add is_bigobj flag.
	(simple_object_coff_match): Add BigObj format detection.
	(simple_object_coff_read_strtab): Use format-specific symbol
	size when calculating string table offset.
	(simple_object_coff_attributes_merge): Check is_bigobj flag.
	(simple_object_coff_write_filehdr_bigobj): New function.
	(simple_object_coff_write_to_file): Add logic for writing
	BigObj vs regular COFF format with appropriate symbol
	and auxiliary entry structures.

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
2025-11-06 11:02:13 +00:00
Xi Ruoyao
cc3ade6da5 LoongArch: Switch the default code model to medium
It has turned out the normal code model isn't enough for some large
LoongArch link units in practice.  Quoting WANG Rui's comment [1]:

We’ve actually been considering pushing for a change to the default
code model for LoongArch compilers (including GCC) for a while now.
In fact, this was one of the topics discussed in yesterday’s internal
compiler tool-chain meeting. The reason we haven’t moved forward with
it yet is that the medium code model generates a R_LARCH_CALL36
relocation, which had some issues with earlier versions of the linker.
We need to assess the impact on users before proceeding with the change.

In GCC we have build-time probe for linker call36 support and if the
linker does not support it, we fall back to pcalau12i + jirl or
la.{local,global} + jirl for the medium code model.  I also had some
concern about a potential performance regression caused by the
conservative nature of the relaxation process, but when I tested this
patch it turned out the relaxation is powerful enough to eliminate all
the pcaddu18i instructions in cc1plus and libstdc++.so.

The Loong Arch Linux project has been using -mcmodel=medium in their
{C,CXX}FLAGS building packages for a while [2] and they've not reported
any issues with that.

The Linux kernel developers has already anticipated the change and
explicitly specified -mcmodel=normal for a while [3].

Thus to me it's safe to make GCC 16 the first release with the medium
code model as the default now.  If someone must keep the normal code
model as the default for any reason, it's possible to configure GCC
using --with-cmodel=normal.

[1]: https://discourse.llvm.org/t/rfc-changing-the-default-code-model-for-loongarch/85317/3
[2]: https://github.com/lcpu-club/loongarch-packages/pull/340
[3]: https://git.kernel.org/torvalds/c/e67e0eb6a98b

gcc/

	* config.gcc: Support --with-cmodel={medium,normal} and make
	medium the default for LoongArch, define TARGET_DEFAULT_CMODEL
	as the selected value.
	* config/loongarch/loongarch-opts.cc: Use TARGET_DEFAULT_CMODEL
	instead of hard coding CMODEL_NORMAL.
	* doc/install.texi: Document that --with-cmodel= is supported
	for LoongArch.
	* doc/invoke.texi: Update the document about default code model
	on LoongArch.

gcc/testsuite/

	* gcc.target/loongarch/vect-frint-no-inexact.c (dg-options): Add
	-mcmodel=normal.
	* gcc.target/loongarch/vect-frint-scalar-no-inexact.c: Likewise.
	* gcc.target/loongarch/vect-frint-scalar.c: Likewise.
	* gcc.target/loongarch/vect-frint.c: Likewise.
	* gcc.target/loongarch/vect-ftint-no-inexact.c: Likewise.
	* gcc.target/loongarch/vect-ftint.c: Likewise.
2025-11-06 17:02:43 +08:00
GCC Administrator
20ddfc95a1 Daily bump. 2025-11-06 00:22:22 +00:00
Nathaniel Shead
f5db79b06e c++/modules: Complain on imported GMF TU-local entities in instantiation [PR121574]
An unfortunate side effect of the previous patch is that even with
-pedantic-errors, unless the user specifies -Wtemplate-names-tu-local
when building the module interface there will be no diagnostic at all
from instantiating a template that exposes global TU-local entities,
either when building the module or its importer.

This patch solves this by recognising imported TU-local dependencies,
even if they weren't streamed as TU_LOCAL_ENTITY nodes.  The warnings
here are deliberately conservative for when we can be sure this was
actually an imported TU-local entity; in particular, we bail on any
TU-local entity that originated from a header module, without attempting
to determine if the entity came via a named module first.

	PR c++/121574

gcc/cp/ChangeLog:

	* cp-tree.h (instantiating_tu_local_entity): Declare.
	* module.cc (is_tu_local_entity): Extract from depset::hash.
	(is_tu_local_value): Likewise.
	(has_tu_local_tmpl_arg): Likewise.
	(depset::hash::is_tu_local_entity): Remove.
	(depset::hash::has_tu_local_tmpl_arg): Remove.
	(depset::hash::is_tu_local_value): Remove.
	(instantiating_tu_local_entity): New function.
	(depset::hash::add_binding_entity): No longer go through
	depset::hash to check is_tu_local_entity.
	* pt.cc (complain_about_tu_local_entity): Remove.
	(tsubst): Use instantiating_tu_local_entity.
	(tsubst_expr): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/internal-17_b.C: Check for diagnostics when
	instantiating imported TU-local entities.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-11-06 10:19:37 +11:00
Nathaniel Shead
99c2ed7407 c++/modules: Allow ignoring some TU-local exposure errors in GMF [PR121574]
A frequent issue with migrating to C++20 modules has been dealing with
third-party libraries with internal functions or data.  This causes GCC
to currently refuse to build the module if any references to these
internal-linkage declarations escape into the module CMI.

This can seem needlessly hostile, however, especially since we have the
capabilities to support this (to a degree) from header units, albeit
with the inherent ODR issues associated with their use.  In aid of this,
this patch demotes the error to a pedwarn in various scenarios, by
treating some declarations as not being TU-local even if they otherwise
would have been.

Effort has been made to not alter semantics of valid programs, and to
continue to diagnose cases that the standard says we must.  In
particular, any code in the module purview is still a hard error, due to
the inherent issues with exposing TU-local entities, and the lack of any
migration requirements.

Because this patch is just to assist migration, we only deal with the
simplest (yet most common) cases: namespace scope functions and
variables.  Types are hard to handle neatly as we risk getting thousands
of unhelpful warnings as we continue to walk the type body and find new
TU-local entities to complain about.  Templates are also tricky because
it's hard to tell if an instantiation that occurred in the module
purview only refers to global module entities or if it's inadvertantly
exposing a purview entity as well.  Neither of these are likely to occur
frequently in third-party code; if need be, this can be relaxed later as
well.

Similarly, even in the GMF a constexpr variable with a TU-local value
will not be usable in constant expressions in the importer, and since we
cannot easily warn about this from the importer we continue to make this
an error in the module interface.

	PR c++/121574

gcc/c-family/ChangeLog:

	* c.opt: New warning '-Wexpose-global-module-tu-local'.
	* c.opt.urls: Regenerate.

gcc/ChangeLog:

	* doc/invoke.texi: Document '-Wexpose-global-module-tu-local'.

gcc/cp/ChangeLog:

	* module.cc (depset::disc_bits): Replace 'DB_REFS_TU_LOCAL_BIT'
	and 'DB_EXPOSURE_BIT' with new four flags
	'DB_{REF,EXPOSE}_{GLOBAL,PURVIEW}_BIT'.
	(depset::is_tu_local): Support checking either for only purview
	TU-local entities or any entity described TU-local by standard.
	(depset::refs_tu_local): Likewise.
	(depset::is_exposure): Likewise.
	(depset::hash::make_dependency): A constant initialized to a
	TU-local variable is always considered a purview exposure.
	(is_exposure_of_member_type): Adjust sanity checks to handle if
	we ever relax requirements for TU-local types.
	(depset::hash::add_dependency): Differentiate referencing
	purview or GMF TU-local entities.
	(depset::hash::diagnose_bad_internal_ref): New function.
	(depset::hash::diagnose_template_names_tu_local): New function.
	(depset::hash::finalize_dependencies): Handle new warnings that
	might be needed for GMF TU-local entities.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/internal-17_a.C: New test.
	* g++.dg/modules/internal-17_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-11-06 10:19:17 +11:00
Eric Botcazou
35e029530f Ada: Fix qualified name of discriminant incorrectly accepted in constraint
The RM 3.8(12/3) subclause says that a discriminant mentioned in a
constraint must appear alone as a direct name.  The last part is not
consistently checked and, while the first part is, it generates a
slightly different error message depending on the form of the input.

This fixes the last part and changes the first to use a single message.

gcc/ada/
	PR ada/35793
	* sem_res.adb (Check_Discriminant_Use): In a constraint context,
	check that the discriminant appears alone as a direct name in all
	cases and give a consistent error message when it does not.

gcc/testsuite/
	* gnat.dg/specs/discr8.ads: New test.
2025-11-05 21:20:46 +01:00
Tobias Burnus
90f2ab4b6e libgomp.c++/target-std__multimap-concurrent.C: Fix USM memory freeing
Fix the unified-shared memory test,
   libgomp.c++/target-std__multimap-concurrent-usm.C
added in commit r16-1010-g83ca283853f195
   libgomp: Add testcases for concurrent access to standard C++ containers
   on offload targets, a number of USM variants
This tests includes the actual code of target-std__multimap-concurrent.C.

The issue is that multimap.insert allocates memory – which is freed by
the destructor. However, if the memory is allocated on a device
('insert'), it also needs to be freed there ('clear') as in general
freeing device-allocated memory is not possible on the host.

libgomp/ChangeLog:

	* testsuite/libgomp.c++/target-std__multimap-concurrent.C: Fix memory
	freeing of device allocated memory with USM.
2025-11-05 16:25:54 +01:00
Paul Thomas
4983e9745e Fortran: Add non-PDT type extension to PDTs [PR122566]
2025-11-05  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/122566
	* decl.cc (gfc_get_pdt_instance): Add non-PDT type exstention.

gcc/testsuite/
	PR fortran/122566
	* gfortran.dg/pdt_68.f03: New test.
2025-11-05 12:17:10 +00:00
Paul Thomas
071942e587 Fortran: Fix PDT constructors in associate [PR122501, PR122524]
2025-11-05  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/122501
	PR fortran/122524
	* primary.cc (gfc_convert_to_structure_constructor): Correct
	whitespace issue.
	(gfc_match_rvalue): Remove the attempt to match specific procs
	before filling out PDT constructor. Instead, defer this until
	resolution with the condition that there not be a following
	arglist and more than one procedure in the generic interface.

gcc/testsuite/
	PR fortran/122501
	* gfortran.dg/pdt_66.f03: New test.

	PR fortran/122524
	* gfortran.dg/pdt_67.f03: New test.
2025-11-05 12:11:00 +00:00
Tobias Burnus
dd62c97f12 OpenMP/Fortran: Fix skipping unmatchable metadirectives [PR122570]
Fix a bug in the removal code of always false variants in metadirectives.

	PR fortran/122570

gcc/fortran/ChangeLog:

	* openmp.cc (resolve_omp_metadirective): Fix 'skip' of
	never matchable metadirective variants.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/pr122570.f: New test.
2025-11-05 12:51:37 +01:00
Artemiy Volkov
470411f44f forwprop: allow subvectors in simplify_vector_constructor ()
This is an attempt to fix
https://gcc.gnu.org/pipermail/gcc-patches/2025-October/697879.html in the
middle-end; the motivation in that patch was to teach gcc to compile:

int16x8_t foo (int16x8_t x)
{
  return vcombine_s16 (vget_high_s16 (x), vget_low_s16 (x));
}

into one instruction:

foo:
        ext     v0.16b, v0.16b, v0.16b, #8
        ret

rather than the two we are generating now:

foo:
        dup     d31, v0.d[1]
        uzp1    v0.2d, v31.2d, v0.2d
        ret

Instead of adding a define_insn in the backend, this patch relaxes the
precondition of tree-ssa-forwprop.cc:simplify_vector_constructor () to
accept subvectors as constructor elements.  During initial argument
processing (ll. 3817-3916), subvectors are decomposed into individual
elements before populating the ELTS array; this allows the rest of the
function to remain unchanged.  Special handling is also implemented for
constant and splat subvector elements of a constructor (the latter with
the use of ssa_uniform_vector_p () from tree-vect-generic.cc, which this
patch moves to tree.cc).

Add GIMPLE tests to gcc.dg/tree-ssa demonstrating the intended behavior
with various combinations of subvectors as constructor arguments,
including constant and splat subvectors; also add some aarch64-specific
tests to show that the change leads to us picking the "ext" instruction
for the resulting VEC_PERM_EXPR.

Bootstrapped and regtested on aarch64 and x86_64, regtested on aarch64_be.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_vector_constructor): Support
	vector constructor elements.
	* tree-vect-generic.cc (ssa_uniform_vector_p): Make non-static and
	move ...
	* tree.cc (ssa_uniform_vector_p): ... here.
	* tree.h (ssa_uniform_vector_p): Declare it.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/forwprop-43.c: New test.
	* gcc.target/aarch64/simd/combine_ext.c: New test.
2025-11-05 10:38:51 +00:00
Richard Biener
7c4f8ae20c Use gather_imm_use_stmts instead of FOR_EACH_IMM_USE_STMT in forwprop
The following fixes forwprop using FOR_EACH_IMM_USE_STMT to iterate
over stmts and then eventually removing the active stmt, releasing
its defs.  This can cause debug stmt insertion with a RHS referencing
the SSA name we iterate over, adding to its immediate use list
but also adjusting all other debug stmts refering to the released
SSA name, updating those.  And those can refer to the original
iterated over variable.

In the end the destructive behavior of update_stmt is a problem
here, which unlinks all uses of a stmt and then links in the
newly computed ones instead of leaving those in place that are.

The solution is to not rely on FOR_EACH_IMM_USE_STMT to iterate
over stmt uses without duplicates.

	* tree-ssa-forwprop.cc (forward_propagate_addr_expr):
	Use gather_imm_use_stmts instead of FOR_EACH_IMM_USE_STMT.
2025-11-05 09:34:09 +01:00
Richard Biener
07a2b1a40c Add gather_imm_use_stmts helper
The following adds a helper function to gather SSA use stmts without
duplicates.  It steals the only padding bit in gimple to be a
"infrastructure local flag" which should be used only temporarily
and kept cleared.  I did not add accessor functions for the flag
to not encourage (ab-)uses.

I have used an auto_vec<gimple *, 2> in the API to avoid heap
allocations for most cases (without doing statistics).  I have
verified GCC 7 performs NRV optimization on the copy but I'll
note while auto_vec<gimple *> has copy and assign deleted,
auto_vec<gimple *, N> does not.  Adding them breaks pair-fusion.cc
compile.  Without using 'auto' or range-for the API use is a bit
awkward as that exposes the number of auto-allocated elements.

The helper can be used in a range-for, see the followup for an
example.

	* gimple.h (gimple::pad): Rename to ...
	(gimple::ilf): ... this.
	* ssa-iterators.h (gather_imm_use_stmts): Declare.
	* tree-ssa-operands.cc (gather_imm_use_stmts): New function.
2025-11-05 09:34:09 +01:00
Richard Biener
b9457ed89c Fix unsafe stmt modifications in FOR_EACH_IMM_USE_STMT
The following fixes path isolation changing the immediate use list of
an SSA name that is currently iterated over via FOR_EACH_IMM_USE_STMT.
This happens when it duplicates a BB within this and creates/modifies
stmts that contain SSA uses of the name and calls update_stmt which
re-builds SSA operands, including removal of SSA uses and re-inserting
them.  This is not safe as that might cause missed iterated uses but
more importantly could cause the 'next' use to be removed.

For the case in question the fix is to collect interesting uses in
a vec and do the processing outside of the FOR_EACH_IMM_USE_STMT
iteration.

	* gimple-ssa-isolate-paths.cc (check_loadstore): Set
	the volatile flag on the stmt manually.
	(find_implicit_erroneous_behavior): Move code transform
	outside of FOR_EACH_IMM_USE_STMT iteration.
2025-11-05 09:32:51 +01:00
Richard Biener
e5b355e45d Add debug function for affine_iv
* tree-ssa-loop-niter.cc (dump_affine_iv): Use file, not
	dump_file when printing.
	(debug): New overload for affine_iv.
2025-11-05 09:22:44 +01:00
Guo Jie
5bb3bc9e4b LoongArch: testsuite: Adapt widen-mul-rtx-cost-signed.c for r16-4949
Commit r16-4949 optimize mulw.d.w + srli.d to mulh.w,
so remove the check rule for mulw.d.w.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/widen-mul-rtx-cost-signed.c: Update.
2025-11-05 10:53:30 +08:00
Xi Ruoyao
d7434f3bab LoongArch: Avoid unnecessary zero-initialization using LSX for scalar popcount
Now for __builtin_popcountl we are getting things like

	vrepli.b	$vr0,0
	vinsgr2vr.d	$vr0,$r4,0
	vpcnt.d	$vr0,$vr0
	vpickve2gr.du	$r4,$vr0,0
	slli.w	$r4,$r4,0
	jr  $r1

The "vrepli.b" instruction is introduced by the init-regs pass (see
PR61810 and all the issues it references).  To work it around, we can
use post-reload instead of define_expand: the "f" constraint will make
the compiler automatically move the scalar between GPR and FPR, and
reload is much later than init-regs so init-regs won't get in our way.

Now the code looks like:

	movgr2fr.d	$f0,$r4
	vpcnt.d	$vr0,$vr0
	movfr2gr.d	$r4,$f0
	jr  $r1

gcc/ChangeLog:

	* config/loongarch/loongarch.md (cntmap): Change to uppercase.
	(popcount<GPR:mode>2): Modify to a post reload split.
2025-11-05 09:52:18 +08:00
GCC Administrator
84974b9e66 Daily bump. 2025-11-05 00:19:42 +00:00
Eric Botcazou
c0132281f6 Ada: Fix explicit raise on subtype of lock-free protected type
The issue is that the Uses_Lock_Free flag is not propagated to the subtype.

gcc/ada/
	* sem_ch3.adb (Analyze_Subtype_Declaration) <Concurrent_Kind>:
	Propagate the Uses_Lock_Free flag for protected types.

gcc/testsuite/
	* gnat.dg/protected_subtype1.adb: New test.
2025-11-04 20:08:48 +01:00
Eric Botcazou
8836210fb6 Ada: Fix incorrect legality check in instantiation of child generic unit
The problem arises when the generic unit has a formal access type parameter,
because the manual resolution implemented in Find_Actual_Type does not pick
the correct entity for the designated type.  The fix replaces it with a bona
fide resolution and cleans up the associated code in the callers.

gcc/ada/
	PR ada/18453
	* sem_ch12.adb (Find_Actual_Type): Add Typ_Ref parameter and
	perform a standard resolution on it in the fallback case.
	Call Get_Instance_Of if the type is declared in a formal of
	the child unit.
	(Instantiate_Type.Validate_Access_Type_Instance): Adjust call
	to Find_Actual_Type.
	(Instantiate_Type.Validate_Array_Type_Instance): Likewise and
	streamline the check for matching component subtypes.

gcc/testsuite/
	* gnat.dg/specs/generic_inst9.ads: New test.
	* gnat.dg/specs/generic_inst9_pkg1.ads: New helper.
	* gnat.dg/specs/generic_inst9_pkg2.ads: Likewise.
	* gnat.dg/specs/generic_inst9_pkg2-g.ads: Likewise.
2025-11-04 20:08:48 +01:00
Harald Anlauf
4cad566793 Fortran: fix frontend memleak with DO CONCURRENT [PR122564]
PR fortran/122564

gcc/fortran/ChangeLog:

	* resolve.cc (resolve_locality_spec): Delete temporary hash_set.
2025-11-04 20:04:55 +01:00
Alejandro Colomar
a01a30020c Fix typos in comment
gcc/c-family/ChangeLog:

	* c-warn.cc (warn_parms_array_mismatch): Fix typos in comment.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-04 18:05:00 +00:00
Alejandro Colomar
c106443b44 gcc/: Rename warn_parm_array_mismatch() => warn_parms_array_mismatch()
This function acts on entire parameter declaration lists, and iterates
over them.  Use plural in the name, to clarify that it acts on
parameters, not just on a single parameter.

gcc/c-family/ChangeLog:

	* c-common.h (warn_parm_array_mismatch):
	Rename warn_parm_array_mismatch => warn_parms_array_mismatch.
	* c-warn.cc (warn_parm_array_mismatch):
	Rename warn_parm_array_mismatch => warn_parms_array_mismatch.

gcc/c/ChangeLog:

	* c-decl.cc (start_function):
	Rename warn_parm_array_mismatch => warn_parms_array_mismatch.
	* c-parser.cc (c_parser_declaration_or_fndef):
	Rename warn_parm_array_mismatch => warn_parms_array_mismatch.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-04 18:03:57 +00:00
Uros Bizjak
0983945b7c i386: TEST insn should be merged with ADC/SBB insn [PR122390]
The attached testcase is currently compiled to:

f1:
        cmpl    %esi, %edi
        adcl    %esi, %edi
        testl   %edi, %edi
        js      .L4
	...

TEST insn should be merged with ADC/SBB insn.  The patch provides missing
combined insn patterns.

	PR target/122390

gcc/ChangeLog:

	* config/i386/i386.md (*add<mode>3_carry_2): New insn pattern.
	(*add<mode>3_carry_0_cc): Ditto.
	(*add<mode>3_carry_0r_cc): Ditto.
	(*sub<mode>3_carry_2): Ditto.
	(*sub<mode>3_carry_0_cc): Ditto.
	(*sub<mode>3_carry_0r_cc): Ditt.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr122390.c: New test.
	* gcc.target/i386/pr122390-1.c: New test.
2025-11-04 17:22:25 +01:00
Kees Cook
7e7091bfa8 arc: Add const attribute support for mathematical ARC builtins
The ARC builtin functions __builtin_arc_ffs and __builtin_arc_fls
perform pure mathematical operations equivalent to the standard
GCC __builtin_ffs function, which is marked with the const attribute.
However, the ARC target-specific versions were not marked as const,
preventing compiler optimizations like common subexpression elimination.

Extend the ARC builtin infrastructure to support function attributes
and mark the appropriate mathematical builtins as const:

- __builtin_arc_ffs: Find first set bit (const)
- __builtin_arc_fls: Find last set bit (const)
- __builtin_arc_norm: Count leading zeros (const)
- __builtin_arc_normw: Count leading zeros for 16-bit (const)
- __builtin_arc_swap: Endian swap (const)

gcc/ChangeLog:

	* config/arc/builtins.def: Add ATTRS parameter to DEF_BUILTIN
	macro calls.  Mark mathematical builtins (FFS, FLS, NORM, NORMW,
	SWAP) with attr_const, leave others as NULL_TREE.
	* config/arc/arc.cc: Add support for builtin function attributes.
	Create attr_const using tree_cons.  Update DEF_BUILTIN macro to
	pass ATTRS parameter to add_builtin_function.

gcc/testsuite/ChangeLog:

	* gcc.target/arc/builtin_fls_const.c: New test.  Verify that
	const attribute enables CSE optimization for mathematical ARC
	builtins by checking that duplicate calls are eliminated and
	results are optimized to shift operations.

Signed-off-by: Kees Cook <kees@kernel.org>
2025-11-04 17:27:58 +02:00
Paul-Antoine Arras
7fa8420170 OpenMP/Fortran: Revamp handling of labels in metadirectives [PR122369,PR122508]
When a label is matched in the first statement after the end of a metadirective
body, it is bound to the associated region. However this prevents it from being
referenced elsewhere.
This patch fixes it by rebinding such labels to the outer region. It also
ensures that labels defined in an outer region can be referenced in a
metadirective body.

	PR fortran/122369
	PR fortran/122508

gcc/fortran/ChangeLog:
	* gfortran.h (gfc_rebind_label): Declare new function.
	* parse.cc (parse_omp_metadirective_body): Rebind labels to the outer
	region. Maintain a vector of metadirective regions.
	(gfc_parse_file): Initialise it.
	* parse.h (GFC_PARSE_H): Declare it.
	* symbol.cc (gfc_get_st_label): Look for existing labels in outer
	metadirective regions.
	(gfc_rebind_label): Define new function.
	(gfc_define_st_label): Accept duplicate labels in metadirective body.
	(gfc_reference_st_label): Accept shared DO termination labels in
	metadirective body.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/pr122369-1.f90: New test.
	* gfortran.dg/gomp/pr122369-2.f90: New test.
	* gfortran.dg/gomp/pr122369-3.f90: New test.
	* gfortran.dg/gomp/pr122369-4.f90: New test.
	* gfortran.dg/gomp/pr122508-1.f90: New test.
	* gfortran.dg/gomp/pr122508-2.f90: New test.
2025-11-04 16:14:01 +01:00
Pan Li
0834dc3a80 Match: Refactor min based unsigned SAT_MUL pattern by widen mul helper [NFC]
There are 3 kinds of widen_mul during the unsigned SAT_MUL pattern, aka
* widen_mul directly, like _3 w* _4
* convert and the widen_mul, like (uint64_t)_3 *w (uint64_t)_4
* convert and then mul, like (uint64_t)_3 * (uint64_t)_4

All of them will be referenced during different forms of unsigned
SAT_MUL pattern match, but actually we can wrap them into a helper
which present the "widening_mul" sematics.  With this helper, some
unnecessary pattern and duplicated code could be eliminated.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

gcc/ChangeLog:

	* match.pd: Add usmul_widen_mult helper and referenced by
	min based unsigned SAT_MUL pattern.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-11-04 23:06:02 +08:00
Siddhesh Poyarekar
0013501e46 lto/122515: Fix archive offset types for i686
On i686, offsets into object archives could be 64-bit, but they're
inconsistently treated across the lto, which may sometimes result in
truncation of those offsets for large archives.

Use int64_t/off_t consistently across all uses of archive offsets to
make sure that they're always read and mapped correctly.

gcc/lto/ChangeLog

	PR lto/122515
	* lto.h (lto_section_slot): Set type of START to off_t.
	* lto-common.cc (lto_read_section_data): Adjust.
	* lto-object.cc (lto_obj_file_open): Set type of OFFSET to
	int64_t.

gcc/ChangeLog

	PR lto/122515
	* lto-wrapper.cc (debug_objcopy): Set type of INOFF to int64_t.
	(run_gcc): Set type of FILE_OFFSET to int64_t.

gcc/testsuite/ChangeLog

	PR lto/122515
	* lib/lto.exp (lto-build-archive): New procedure.
	(lto-execute-1): Use it.
	(lto-link-and-maybe-run, lto-get-options-main): Handle ar-link.
	* gcc.dg/lto/pr122515_0.c: New test case.
	* gcc.dg/lto/pr122515_1.c: New file.
	* gcc.dg/lto/pr122515_2.c: Likewise.
	* gcc.dg/lto/pr122515_3.c: Likewise.
	* gcc.dg/lto/pr122515_4.c: Likewise.
	* gcc.dg/lto/pr122515_5.c: Likewise.
	* gcc.dg/lto/pr122515_6.c: Likewise.
	* gcc.dg/lto/pr122515_7.c: Likewise.
	* gcc.dg/lto/pr122515_8.c: Likewise.
	* gcc.dg/lto/pr122515_9.c: Likewise.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
2025-11-04 05:13:30 -06:00
Nathaniel Shead
f062a6b798 c++: Don't constrain template visibility using no-linkage variables [PR122253]
When finding the minimal visibility of a template, any reference to a
dependent automatic variable will cause the instantiation to be marked
as internal linkage.  However, when processing the template decl we
don't yet know whether that should actually be the case, as a given
instantiation may not require referencing the local decl in its
mangling.

This patch fixes the issue by checking for no-linkage decls first, in
which case we just constrain using the type of the entity.  We can't use
a check for lk_external/lk_internal in the other cases, as
instantiations referring to internal types can still have external
linkage as determined by the language, but should still constrain the
visibility of any declarations that refer to them.

	PR c++/122253

gcc/cp/ChangeLog:

	* decl2.cc (min_vis_expr_r): Don't mark no-linkage declarations
	as VISIBILITY_ANON.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/internal-16.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-11-04 21:27:02 +11:00
Tobias Burnus
95cabf531c gfortran.dg/pr122513-2.f90: New test [PR122513]
This test is from PR122513; even though the actual error message was
already added in GCC 15, there was no testcase for the diagnostic type
  Index variable 'i' at (1) cannot be specified in a locality-spec

Thus, this commit adds one.

gcc/testsuite/ChangeLog:

	PR fortran/122513
	* gfortran.dg/pr122513-2.f90: New test.
2025-11-04 10:23:31 +01:00
Kishan Parmar
a50b4406e5 simplify-rtx: Canonicalize SUBREG and LSHIFTRT order for AND operations
For a given rtx expression (and (lshiftrt (subreg X) shift) mask)
combine pass tries to simplify the RTL form to

   (and (subreg (lshiftrt X shift)) mask)

where the SUBREG wraps the result of the shift.  This leaves the AND
and the shift in different modes, which complicates recognition.

   (and (lshiftrt (subreg X) shift) mask)

where the SUBREG is inside the shift and both operations share the same
mode.  This form is easier to recognize across targets and enables
cleaner pattern matching.

This patch checks in simplify-rtx to perform this transformation when
safe: the SUBREG must be a lowpart, the shift amount must be valid, and
the precision of the operation must be preserved.

Tested on powerpc64le-linux-gnu, powerpc64-linux-gnu, and
x86_64-pc-linux-gnu with no regressions.  On rs6000, the change reduces
insn counts due to improved matching.

2025-11-04  Kishan Parmar  <kishan@linux.ibm.com>

gcc/ChangeLog:

	PR rtl-optimization/93738
	* simplify-rtx.cc (simplify_binary_operation_1): Canonicalize
	SUBREG(LSHIFTRT) into LSHIFTRT(SUBREG) when valid.

gcc/testsuite/ChangeLog:

	PR rtl-optimization/93738
	* gcc.target/powerpc/rlwimi-2.c: Update expected rldicl count.
2025-11-04 12:43:13 +05:30
David Malcolm
0a2c4b6dd2 analyzer: add event kinds for special control flow [PR122544]
The SARIF 3.38.8 "kinds" property has some verbs for expressing
control flow, but is missing some of the awkward special cases.

The spec says "If none of these values are appropriate, a SARIF
producer MAY use any value."

This patch adds the following new values:

* "throw" for throwing an exception
* "catch" for catching an exception
* "unwind" for unwinding stack frame(s) during exception-handling
* "setjmp" for calls to setjmp
* "longjmp" for calls to longjmp that rewind the program counter/stack
to the location of a previous setjmp call

gcc/analyzer/ChangeLog:
	PR analyzer/122544
	* checker-event.cc (catch_cfg_edge_event::get_meaning): New.
	(setjmp_event::get_meaning): New.
	(rewind_event::get_meaning): New.
	(throw_event::get_meaning): New.
	(unwind_event::get_meaning): New.
	* checker-event.h (catch_cfg_edge_event::get_meaning): New decl.
	(setjmp_event::get_meaning): New decl.
	(rewind_event::get_meaning): New decl.
	(throw_event::get_meaning): New decl.
	(unwind_event::get_meaning): New decl.

gcc/ChangeLog:
	PR analyzer/122544
	* diagnostics/paths.cc (event::meaning::maybe_get_verb_str):
	Handle the new verbs.
	* diagnostics/paths.h (event::meaning::verb): Add new values
	for special control flow operations.
	(event::meaning::meaning): Add ctor taking just a verb.

gcc/testsuite/ChangeLog:
	PR analyzer/122544
	* g++.dg/analyzer/exception-path-1-sarif.py: New test script.
	* g++.dg/analyzer/exception-path-1.C: Add SARIF output, and use
	the above to check it.
	* g++.dg/analyzer/exception-path-unwind-multiple-2-sarif.py: New
	test script.
	* g++.dg/analyzer/exception-path-unwind-multiple-2.C: Add SARIF
	output, and use the above to check it.
	* gcc.dg/analyzer/setjmp-3-sarif.py: New test script.
	* gcc.dg/analyzer/setjmp-3.c: Add SARIF output, and use
	the above to check it.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-11-03 21:42:59 -05:00