aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2025-08-17[PR target/121213] Avoid unnecessary constant load in amoswapAustin Law2-4/+21
PR 121213 shows an unnecessary "li target,0" in an atomic exchange loop on RISC-V. The source operand for an amoswap instruction should allow (const_int 0) in addition to GPRs. So the operand's predicate is changed to "reg_or_0_operand". The corresponding constraint is also changed to allow a reg or the constant 0. With the source operand no longer tied to the destination operand we do not need the earlyclobber for the destination, so the destination operand's constraint is adjusted accordingly. This patch does not address the unnecessary sign extension reported in the PR. Tested with no regressions on riscv32-elf and riscv64-elf. PR target/121213 gcc/ * config/riscv/sync.md (amo_atomic_exchange<mode>): Allow (const_int 0) as input operand. Do not tie input to output. No longer earlyclobber the output. gcc/testsuite * gcc.target/riscv/amo/pr121213.c: New test.
2025-08-17Add test for spill failuredragan.mladjenovic1-0/+10
Adding the float-agnostic reproducer as test-case. gcc/testsuite/ * gcc.target/mips/tls-1.c: New file.
2025-08-17Testsuite: Use HAS_LDC instead of a specific ISAMatthew Fortune1-1/+1
The call-clobbered-1.c test has both reasons to be above a certain ISA and below a certain ISA level. The option based ISA min/max code only triggers if there is no isa level request. gcc/testsuite/ * gcc.target/mips/call-clobbered-1.c: Use HAS_LDC ghost option instead of isa>=2.
2025-08-17Testsuite: Fix tests properly for compact-branchesAndrew Bennett4-20/+20
Compact-branches use the balc opcode, this patch adjusts the testsuite to handle that correctly. gcc/testsuite * gcc.target/mips/near-far-1.c: Fix tests properly for compact-branches (jals and balc). * gcc.target/mips/near-far-2.c: Likewise. * gcc.target/mips/near-far-3.c: Likewise. * gcc.target/mips/near-far-4.c: Likewise.
2025-08-17Testsuite: Adjust tests to cope with -mips16Jeff Law10-182/+183
Various tests are missing NOMIPS16 markers or can be safely skipped via -mno-mips16. Adjust them appropriately. gcc/testsuite/ * gcc.target/mips/call-clobbered-2.c: Add a NOMIPS16 attribute. * gcc.target/mips/call-clobbered-3.c: Likewise. * gcc.target/mips/call-clobbered-5.c: Likewise. * gcc.target/mips/ds-schedule-2.c: Add an -mno-mips16 option. * gcc.target/mips/interrupt_handler-bug-1.c: Same as call-clobbered-*.c tests. * gcc.target/mips/movdf-1.c: Likewise. * gcc.target/mips/movdf-2.c: Likewise. * gcc.target/mips/movdf-3.c: Likewise. * gcc.target/mips/msa-builtins.c: Same as ds-schedule-2.c. Remove a NOMIPS16 attribute from builtins. * gcc.target/mips/msa.c: Likewise.
2025-08-17Testsuite: Fix insn-*.c tests from trunkMatthew Fortune2-6/+6
Ensure micromips test does not get confused about library support. Ensure insn-casesi.c and insn-tablejump.c can be executed. Move the micromips/mips16 selection into the file as per function attributes so that there is no requirement on having a full micromips or mips16 runtime to execute the test. gcc/testsuite/ * gcc.target/mips/insn-casesi.c: Require mips16 support but not the command line option. * gcc.target/mips/insn-tablejump.c: Force o32 ABI as we do not really support n32/n64 microMIPS. Require micromips support but not the command line option.
2025-08-17regrename: treat writes as reads for fused instruction pairsArtemiy Volkov1-1/+9
Consider the following (RISC-V) instruction pair: mul s6,a1,a2 add s6,a4,s6 Without this patch, while handling the second instruction, (a) the existing chain for s6 will first be closed (upon the terminate_write action for the input operand), then (b) a new one will be opened (upon the mark_write action for the output operand). This will likely lead to the two output operands being different physical registers, breaking the single-output property required for some macro-op fusion pairs. This patch, using the single_output_fused_pair_p () predicate introduced earlier, changes the regrename behavior for such pairs to append the input and the output operands to the existing chain (as if both actions were mark_read), instead of breaking the current renaming chain and starting a new one. This ensures that the output operands of both fused instructions are kept in the same hard register, and that the single-output property of the insn pair is preserved. gcc/ChangeLog: * regrename.cc (scan_rtx_reg): Handle fused insn pairs.
2025-08-17[PR target/109324] H8/300: Fix genrecog warnings about operands missing modes.Jan Dubiec3-20/+20
This patch fixes genrecog warnings about operands missing modes. This is done by explicitly specifying modes of operations. PR target/109324 gcc/ChangeLog: * config/h8300/addsub.md: Explicitly specify mode for plus operation. * config/h8300/jumpcall.md: Explicitly specify modes for eq and match_operand operations. * config/h8300/testcompare.md: Explicitly specify modes for eq, ltu and compare operations.
2025-08-16ira: tie output allocnos for fused instruction pairsArtemiy Volkov3-2/+31
Some of the instruction pairs recognized as fusible by a preceding invocation of the dep_fusion pass require that both components of a pair have the same hard register output for the fusion to work in hardware. (An example of this would be a multiply-add operation, or a zero-extract operation composed of two shifts.) For all such pairs, the following conditions will hold: (a) Both insns are single_sets (b) Both insns have a register destination (c) The pair has been marked as fusible by setting the second insn's SCHED_GROUP flag (d) Additionally, post-RA, both instructions' destination regnos are equal (All of these conditions are encapsulated in the newly created single_output_fused_pair_p () predicate.) During IRA, if conditions (a)-(c) above hold, we need to tie the two instructions' destination allocnos together so that they are allocated to the same hard register. We do this in add_insn_allocno_copies () by adding a constraint conflict to the output operands of the two instructions. gcc/ChangeLog: * ira-conflicts.cc (add_insn_allocno_copies): Handle fused insn pairs. * rtl.h (single_output_fused_pair_p): Declare new function. * rtlanal.cc (single_output_fused_pair_p): Define it.
2025-08-16[PATCH] RISC-V: Fix block matching in arch-canonicalize [PR121538]Dimitar Dimitrov1-2/+20
Commit r16-3028-g0c517ddf9b136c introduced parsing of conditional blocks in riscv-ext*.def. For simplicity, it used a simple regular expression to match the C++ lambda function for each condition. But the regular expression is too simple - it matches only the first scoped code block, without any trailing closing braces. The "c" dependency for the "zca" extension has two code blocks inside its conditional. One for RV32 and one for RV64. The script matches only the RV32 block, and leaves the RV64 one. Any strings left, in turn, are considered a list of non-conditional extensions. Thus the quoted strings "d" and "zcd" from that block are taken as "simple" (non-conditional) dependencies: if (subset_list->xlen () == 64) { if (subset_list->lookup ("d")) return subset_list->lookup ("zcd"); As a result, arch-canonicalize erroneously adds "d" extension: $ ./config/riscv/arch-canonicalize rv32ec rv32efdc_zicsr_zca_zcd_zcf Before r16-3028-g0c517ddf9b136c the command returned: $ ./config/riscv/arch-canonicalize rv32ec rv32ec Fix by extending the conditional block match until the number of opening and closing braces is equal. This change might seem crude, but it does save us from introducing a full C++ parser into the simple arch-canonicalize python script. With this patch the script now returns: $ ./config/riscv/arch-canonicalize rv32ec rv32ec_zca Ok for trunk? PR target/121538 gcc/ChangeLog: * config/riscv/arch-canonicalize (parse_dep_exts): Match condition block up to closing brace. (test_parse_long_condition_block): New test.
2025-08-16x86: Add target("80387") function attributeH.J. Lu9-0/+78
Add target("80387") attribute to enable and disable x87 instructions in a function. gcc/ PR target/121541 * config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p): Add target("80387") attribute. Set the mask bit in opts_set->x_target_flags if the mask bit in opts->x_target_flags is updated. * doc/extend.texi: Document target("80387") function attribute. gcc/testsuite/ PR target/121541 * gcc.target/i386/pr121541-1a.c: New test. * gcc.target/i386/pr121541-1b.c: Likewise. * gcc.target/i386/pr121541-2.c: Likewise. * gcc.target/i386/pr121541-3.c: Likewise. * gcc.target/i386/pr121541-4.c: Likewise. * gcc.target/i386/pr121541-5a.c: Likewise. * gcc.target/i386/pr121541-5b.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-17Daily bump.GCC Administrator5-1/+55
2025-08-17c++: Implement P2115R0 linkage changes for unnamed unscoped enums [PR120503]Nathaniel Shead11-14/+109
We currently list P2115R0 as implemented, but only the modules changes had been done. This patch implements the linkage changes so that unnamed unscoped enums will use the name of the first enumerator for linkage purposes. This is (strictly speaking) a breaking change, as code that previously relied on unnamed enumerations being internal linkage may have overloads using those types become exposed and clash with other functions in a different TU that have been similarly exposed. As such this feature is only implemented for C++20. No ABI flag warning is provided, partly because C++20 is still an experimental standard, but also because any affected functions could not have been part of an ABI until this change anyway. A number of testcases that are testing for behaviour of no-linkage types are adjusted to use an enumeration with no values, so that the pre-C++20 and post-C++20 behaviour is equivalently tested. In terms of implementation, I had originally considered adjusting the DECL_NAME of the enum, as with 'name_unnamed_type', but this ended up being more complicated as it had unwanted interactions with the existing modules streaming and with name lookup and diagnostic messages. This patch instead uses a new function to derive this case. The standard says that ([dcl.enum] p11) such an enum "...is denoted, for linkage purposes, by its underlying type and its first enumerator", so we need to add a new mangling production as well to handle this. PR c++/120503 PR c++/120824 gcc/cp/ChangeLog: * cp-tree.h (TYPE_UNNAMED_P): Adjust for enums with enumerators for linkage purposes. (enum_with_enumerator_for_linkage_p): Declare. * decl.cc (name_unnamed_type): Adjust assertions to handle enums with enumerators for linkage purposes. (grokdeclarator): Use a typedef name for enums with enumerators for linkage purposes. (enum_with_enumerator_for_linkage_p): New function. (finish_enum_value_list): Reset type linkage for enums with enumerators for linkage purposes. * mangle.cc (write_unnamed_enum_name): New function. (write_unqualified_name): Handle enums with enumerators for linkage purposes. * tree.cc (decl_linkage): Fixup unnamed enums. gcc/testsuite/ChangeLog: * g++.dg/abi/mangle32.C: Remove enumerator list. * g++.dg/cpp0x/linkage2.C: Likewise. * g++.dg/ext/vector26.C: Likewise. * g++.dg/other/anon3.C: Likewise. * g++.dg/abi/mangle83.C: New test. * g++.dg/modules/enum-15_a.C: New test. * g++.dg/modules/enum-15_b.C: New test. include/ChangeLog: * demangle.h (enum demangle_component_type): Add enumeration DEMANGLE_COMPONENT_UNNAMED_ENUM. libiberty/ChangeLog: * cp-demangle.c (d_unnamed_enum): New function. (d_unqualified_name): Call it. (cplus_demangle_type): Handle unscoped unnamed types (Ue, Ul, etc.) (d_count_templates_scopes): Handle unnamed enums. (d_find_pack): Likewise. (d_print_comp_inner): Print unnamed enums. * testsuite/demangle-expected: Add tests. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-17RISC-V: Update the comments of vx combine [NFC]Pan Li1-0/+20
The supported insn of vx combine is out of date, update all insn supported for now. gcc/ChangeLog: * config/riscv/autovec-opt.md: Add supported insn of vx combine. Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-17RISC-V: Add missed DONE for vx combine pattern [NFC]Pan Li1-0/+4
The previous patch missed the DONE indicator of the vx combine pattern. Thus add it back. gcc/ChangeLog: * config/riscv/autovec-opt.md: Add missed DONE for vx combine pattern. Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-16fortran: Set DECL_TLS_MODEL after processing a variableH.J. Lu3-10/+26
Call set_decl_tls_model only after a variable has been fully processed, not in the middle of processing it. gcc/fortran/ PR fortran/107421 * trans-common.cc (build_common_decl): Call set_decl_tls_model after processing a variable. * trans-decl.cc (gfc_finish_var_decl): Likewise. (get_proc_pointer_decl): Likewise. gcc/testsuite/ PR fortran/107421 * gfortran.dg/gomp/pr107421.f90: New test. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-16Daily bump.GCC Administrator7-1/+343
2025-08-15c++: Implement __builtin_structured_binding_size traitJakub Jelinek12-29/+255
clang++ apparently added a SFINAE-friendly __builtin_structured_binding_size trait to return the structured binding size (or error if not in SFINAE contexts if a type doesn't have a structured binding size). The expansion statement patch already anticipated this through adding complain argument to cp_finish_decomp. The following patch implements it. 2025-08-15 Jakub Jelinek <jakub@redhat.com> gcc/ * doc/extend.texi (Type Traits): Document __builtin_structured_binding_size. gcc/cp/ * cp-trait.def (STRUCTURED_BINDING_SIZE): New unary trait. * cp-tree.h (finish_structured_binding_size): Declare. * semantics.cc (trait_expr_value): Handle CPTK_STRUCTURED_BINDING_SIZE. (finish_structured_binding_size): New function. (finish_trait_expr): Handle CPTK_RANK and CPTK_TYPE_ORDER in the switch instead of just doing break; for those and ifs at the end to handle them. Handle CPTK_STRUCTURED_BINDING_SIZE. * pt.cc (tsubst_expr): Likewise. * constraint.cc (diagnose_trait_expr): Likewise. * decl.cc (get_tuple_size): Use mce_true for maybe_const_value. (cp_decomp_size): Diagnose incomplete types not just if processing_template_decl, and use error_at instead of pedwarn. If btype is NULL, just return 0 instead of diagnosing an error. gcc/testsuite/ * g++.dg/cpp26/expansion-stmt15.C: Expect different diagnostics for zero size destructuring expansion statement. * g++.dg/ext/builtin-structured-binding-size1.C: New test. * g++.dg/ext/builtin-structured-binding-size2.C: New test. * g++.dg/ext/builtin-structured-binding-size3.C: New test. * g++.dg/ext/builtin-structured-binding-size4.C: New test.
2025-08-15c++: Add testcases for the defarg part of P1766R1 [PR121552]Jakub Jelinek6-0/+188
The following patch adds some testcases for the default argument (function and template) part of the paper, making sure we diagnose multiple defargs in the same TU and when visible in modules and DTRT when some aren't visible and some are visible and they are equal. Not testing when they are different since that is IFNDR. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR c++/121552 * g++.dg/parse/defarg21.C: New test. * g++.dg/template/defarg24.C: New test. * g++.dg/modules/default-arg-4_a.C: New test. * g++.dg/modules/default-arg-4_b.C: New test. * g++.dg/modules/default-arg-5_a.C: New test. * g++.dg/modules/default-arg-5_b.C: New test.
2025-08-15c++: Implement C++20 P1766R1 - Mitigating minor modules maladies [PR121552]Jakub Jelinek18-4/+223
The following patch attempts to implement the C++20 P1766R1 - Mitigating minor modules maladies paper. clang++ a few years ago introduced for the diagnostics required in the paper -Wnon-c-typedef-for-linkage pedwarn and the following patch does that too. The paper was accepted as a DR, the patch enables the warning also for C++98, dunno whether it might not be better to do it only for C++11 onwards. The paper is also about differences in default arguments of functions in different TUs and in modules, I think within the same TU we diagnose it correctly (maybe I should add some testcase) and perhaps try something with modules as well. But in different TUs it is IFNDR. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR c++/121552 gcc/ * doc/invoke.texi (-Wno-non-c-typedef-for-linkage): Document. gcc/c-family/ * c.opt (Wnon-c-typedef-for-linkage): New option. * c.opt.urls: Regenerate. gcc/cp/ * decl.cc: Implement C++20 P1766R1 - Mitigating minor modules maladies. (diagnose_non_c_class_typedef_for_linkage, maybe_diagnose_non_c_class_typedef_for_linkage): New functions. (name_unnamed_type): Call maybe_diagnose_non_c_class_typedef_for_linkage. gcc/testsuite/ * g++.dg/cpp2a/typedef1.C: New test. * g++.dg/debug/dwarf2/typedef5.C: Add -Wno-non-c-typedef-for-linkage to dg-options. * g++.dg/inherit/typeinfo1.C: Add -Wno-non-c-typedef-for-linkage to dg-additional-options. * g++.dg/parse/ctor2.C: Likewise. * g++.dg/ext/anon-struct9.C: Add -Wno-non-c-typedef-for-linkage to dg-options. * g++.dg/ext/visibility/anon11.C: Add -Wno-non-c-typedef-for-linkage to dg-additional-options. * g++.dg/lto/pr69137_0.C: Add -Wno-non-c-typedef-for-linkage to dg-lto-options. * g++.dg/other/anon8.C: Add -Wno-non-c-typedef-for-linkage to dg-additional-options. * g++.dg/template/pr84973.C: Likewise. * g++.dg/template/pr84973-2.C: Likewise. * g++.dg/template/pr84973-3.C: Likewise. * g++.dg/abi/anon2.C: Likewise. * g++.dg/abi/anon3.C: Likewise. * g++.old-deja/g++.oliva/linkage1.C: Likewise.
2025-08-15c++: Fix default argument parsing in non-comma variadic methods [PR121539]Jakub Jelinek2-1/+84
While the non-comma variadic functions/methods were deprecated in C++26, they are still valid and they are valid without deprecation in C++98 to C++23. We parse default arguments followed by ...) outside of classes or for out of class definitions of methods, but I think since C++11 support in GCC 4.9 or so we consider ... to be a part of a default argument and error on it. I think a default argument can't validly contain a pack expansion that ends the expression with ..., so I think we can simply handle ...) if at depth 0 as not part of the default argument. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR c++/121539 * parser.cc (cp_parser_cache_defarg): Set done to true for CPP_ELLIPSIS followed by CPP_CLOSE_PAREN in !nsdmi at depth 0. * g++.dg/parse/defarg20.C: New test.
2025-08-15c++: Warn on #undef/#define of remaining cpp.predefined macros [PR120778]Jakub Jelinek6-42/+298
We already warn on #undef or pedwarn on #define (but not on #define after #undef) of some builtin macros mentioned in cpp.predefined. The C++26 P2843R3 paper changes it from (compile time) undefined behavior to ill-formed. The following patch arranges for warning (for #undef) and pedwarn (on #define) for the remaining cpp.predefined macros. __cpp_* feature test macros only for C++20 which added some of them to cpp.predefined, in earlier C++ versions it was just an extension and for pedantic diagnostic I think we don't need to diagnose anything, __STDCPP_* and __cplusplus macros for all C++ versions where they appeared. Like the earlier posted -Wkeyword-macro diagnostics (which is done regardless whether the identifier is defined as a macro or not, obviously most likely none of the keywords are defined as macros initially), this one also warns on #undef when a macro isn't defined or later #define after #undef. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 PR target/121520 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581. Add cpp_define_warn lambda and use it as well as cpp_warn where needed. In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add cpp_define lambda. Formatting fixes. gcc/c/ * c-decl.cc (c_init_decl_processing): Use cpp_warn instead of cpp_lookup and NODE_WARN bit setting. gcc/cp/ * lex.cc (cxx_init): Remove warn_on lambda. Use cpp_warn instead of cpp_lookup and NODE_WARN bit setting or warn_on. gcc/testsuite/ * g++.dg/DRs/dr2581-1.C: New test. * g++.dg/DRs/dr2581-2.C: New test. * c-c++-common/cpp/pr92296-2.c: Expect warnings also on defining special macros after undefining them. libcpp/ * include/cpplib.h (struct cpp_options): Add suppress_builtin_macro_warnings member. (cpp_warn): New inline functions. * init.cc (cpp_create_reader): Clear suppress_builtin_macro_warnings. (cpp_init_builtins): Call cpp_warn on __cplusplus, __STDC__, __STDC_VERSION__, __STDC_MB_MIGHT_NEQ_WC__ and __STDCPP_STRICT_POINTER_SAFETY__ when appropriate. * directives.cc (do_undef): Warn on undefining NODE_WARN macros if not cpp_keyword_p. Don't emit any NODE_WARN related diagnostics if CPP_OPTION (pfile, suppress_builtin_macro_warnings). (cpp_define, _cpp_define_builtin, cpp_undef): Temporarily set CPP_OPTION (pfile, suppress_builtin_macro_warnings) around run_directive calls. * macro.cc (_cpp_create_definition): Warn on defining NODE_WARN macros if they weren't previously defined and not cpp_keyword_p. Ignore NODE_WARN for diagnostics if CPP_OPTION (pfile, suppress_builtin_macro_warnings).
2025-08-15cobol: Eliminate a run-time structure type that is no longer used.Robert Dubner3-28/+0
gcc/cobol/ChangeLog: * genapi.h (parser_call_exception_end): Remove obsolete comment. * structs.cc (create_cbl_enabled_exception_t): Remove cbl_enabled_exception_type_node; remove create_cbl_enabled_exception_t(). (create_our_type_nodes): Likewise. * structs.h (GTY): Likewise.
2025-08-15real: Eliminate access to uninitialized memory.Robert Dubner1-0/+5
When compiling this program with gcobol: identification division. program-id. prog. data division. working-storage section. 01 val pic v9(5) value .001. procedure division. display val goback. the rounding up of .99999...9999 to 1.000...0000 causes a read of the first byte of the output buffer. Although harmless, it generates a valgrind warning. The following change clears that warning. gcc/ChangeLog: * real.cc (real_to_decimal_for_mode): Set str[0] to known value.
2025-08-15RISC-V: fix __builtin_round clobbering FP exceptions flags [PR121534]Vineet Gupta2-2/+14
__builtin_round() fails to save/restore FP exception flags around the FP compare insn which can potentially clobber the same. Worth noting that the fflags restore bracketing is slightly different than the glibc implementation. Both FLT and FCVT can potentially clobber fflags. gcc generates below where even if branch is not taken and FCVT is not executed, FLT still executed. Thus FSFLAGS is placed AFTER the label 'L3'. glibc implementation FLT can't clobber due to early NaN check, so FSFLAGS can be moved under the branch, before the label. | convert_float_to_float_round | ... | frflags a5 | fabs.s fa5,fa0 | flt.s a4,fa5,fa4 <--- can clobber fflags | beq a4,zero,.L3 | fcvt.w.s a4,fa0,rmm <--- also | fcvt.s.w fa5,a4 | fsgnj.s fa0,fa5,fa0 | .L3: | fsflags a5 <-- both code paths Fixes: f652a35877e3 ("This is almost exclusively Jivan's work....") PR target/121534 gcc/ChangeLog: * config/riscv/riscv.md (round_pattern): save/restore fflags. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls/math-nearbyint-1.c: Adjust scan pattern for additional instances of frflags/fsrflags. Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
2025-08-15Generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by attribute ↵Qing Zhao4-37/+21
only when it's read from. Currently, we generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by attribute for every component_ref that corresponds to such an object. Actually, such .ACCESS_WITH_SIZE calls are useless when they are generated for a written site or an address taken site. In this patch, we only generate a call to .ACCESS_WITH_SIZE for a FAM with counted_by attribute when it's a read. gcc/c/ChangeLog: * c-tree.h (handle_counted_by_for_component_ref): New prototype of build_component_ref and handle_counted_by_for_component_ref. * c-parser.cc (c_parser_postfix_expression): Call the new prototypes of build_component_ref and handle_counted_by_for_component_ref, update comments. * c-typeck.cc (default_function_array_read_conversion): Likewise. (convert_lvalue_to_rvalue): Likewise. (default_conversion): Likewise. (handle_counted_by_p): Update comments. (handle_counted_by_for_component_ref): Delete one argument. (build_component_ref): Delete one argument. Delete the call to handle_counted_by_for_component_ref completely. (build_array_ref): Generate call to .ACCESS_WITH_SIZE for array. gcc/testsuite/ChangeLog: * gcc.dg/flex-array-counted-by-2.c: Adjust testing case.
2025-08-15Use the counted_by attribute of pointers in array bound checker.Qing Zhao7-16/+545
Current array bound checker only instruments ARRAY_REF, and the INDEX information is the 2nd operand of the ARRAY_REF. When extending the array bound checker to pointer references with counted_by attributes, the hardest part is to get the INDEX of the corresponding array ref from the offset computation expression of the pointer ref. I.e. Given an OFFSET expression, and the ELEMENT_SIZE, get the index expression from the OFFSET. For example: OFFSET: ((long unsigned int) m * (long unsigned int) SAVE_EXPR <n>) * 4 ELEMENT_SIZE: (sizetype) SAVE_EXPR <n> * 4 get the index as (long unsigned int) m. gcc/c-family/ChangeLog: * c-gimplify.cc (is_address_with_access_with_size): New function. (ubsan_walk_array_refs_r): Instrument an INDIRECT_REF whose base address is .ACCESS_WITH_SIZE or an address computation whose base address is .ACCESS_WITH_SIZE. * c-ubsan.cc (ubsan_instrument_bounds_pointer_address): New function. (struct factor_t): New structure. (get_factors_from_mul_expr): New function. (get_index_from_offset): New function. (get_index_from_pointer_addr_expr): New function. (is_instrumentable_pointer_array_address): New function. (ubsan_array_ref_instrumented_p): Change prototype. Handle MEM_REF in addtional to ARRAY_REF. (ubsan_maybe_instrument_array_ref): Handle MEM_REF in addtional to ARRAY_REF. gcc/testsuite/ChangeLog: * gcc.dg/ubsan/pointer-counted-by-bounds-2.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-3.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-4.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-5.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds.c: New test.
2025-08-15Use the counted_by attribute of pointers in builtinin-object-size. No need ↵Qing Zhao9-0/+302
to change anything in middle-end. Add the testing case for PR120929. gcc/testsuite/ChangeLog: * gcc.dg/pointer-counted-by-4-char.c: New test. * gcc.dg/pointer-counted-by-4-float.c: New test. * gcc.dg/pointer-counted-by-4-struct.c: New test. * gcc.dg/pointer-counted-by-4-union.c: New test. * gcc.dg/pointer-counted-by-4.c: New test. * gcc.dg/pointer-counted-by-5.c: New test. * gcc.dg/pointer-counted-by-6.c: New test. * gcc.dg/pointer-counted-by-7.c: New test. * gcc.dg/pr120929.c: New test.
2025-08-15Extend "counted_by" attribute to pointer fields of structures. Convert a ↵Qing Zhao13-75/+659
pointer reference with counted_by attribute to .ACCESS_WITH_SIZE. Fix PR120929. For example: struct PP { size_t count2; char other1; char *array2 __attribute__ ((counted_by (count2))); int other2; } *pp; specifies that the "array2" is an array that is pointed by the pointer field, and its number of elements is given by the field "count2" in the same structure. In order to fix PR120929, we agreed on the following solution: for a pointer field with counted_by attribute: struct S { int n; int *p __attribute__((counted_by(n))); } *f; when generating call to .ACCESS_WITH_SIZE for f->p, instead of generating *.ACCESS_WITH_SIZE (&f->p, &f->n,...) We should generate .ACCESS_WITH_SIZE (f->p, &f->n,...) i.e., the return type and the type of the first argument of the call is the original pointer type in this version. However, this code generation might bring undefined behavior into the applicaiton if the call to .ACCESS_WITH_SIZE is generated for a pointer field reference when this refernece is written to. For example: f->p = malloc (size); ***** the IL for the above is: tmp1 = f->p; tmp2 = &f->n; tmp3 = .ACCESS_WITH_SIZE (tmp1, tmp2, ...); tmp4 = malloc (size); tmp3 = tmp4; In the above, in order to generate a call to .ACCESS_WITH_SIZE for the pointer reference f->p, the new GIMPLE tmp1 = f->p is necessary to pass the value of the pointer f->p to the call to .ACCESS_WITH_SIZE. However, this new GIMPLE is the one that brings UB into the application since the value of f->p is not initialized yet when it is assigned to "tmp1". the above IL will be expanded to the following when .ACCESS_WITH_SIZE is expanded to its first argument: tmp1 = f->p; tmp2 = &f->n; tmp3 = tmp1; tmp4 = malloc (size); tmp3 = tmp4; the final optimized IL will be: tmp3 = f->p; tmp3 = malloc (size);; As a result, the f->p will NOT be set correctly to the pointer returned by malloc (size). Due to this potential issue, We will need to selectively generate the call to .ACCESS_WITH_SIZE for f->p according to whether it's a read or a write. We will only generate call to .ACCESS_WITH_SIZE for f->p when it's a read in C FE. gcc/c-family/ChangeLog: * c-attribs.cc (handle_counted_by_attribute): Accept counted_by attribute for pointer fields. gcc/c/ChangeLog: * c-decl.cc (verify_counted_by_attribute): Change the 2nd argument to a vector of fields with counted_by attribute. Verify all fields in this vector. (finish_struct): Collect all the fields with counted_by attribute to a vector and pass this vector to verify_counted_by_attribute. * c-tree.h (handle_counted_by_for_component_ref): New prototype of handle_counted_by_form_component_ref. * c-parser.cc (c_parser_postfix_expression): Call the new prototype of handle_counted_by_for_component_ref. * c-typeck.cc (default_function_array_read_conversion): Only generate call to .ACCESS_WITH_SIZE for a pointer field when it's a read. (convert_lvalue_to_rvalue): Likewise. (default_conversion): Likewise. (handle_counted_by_p): New routine. (check_counted_by_attribute): New routine. (build_counted_by_ref): Handle pointers with counted_by. (build_access_with_size_for_counted_by): Handle pointers with counted_by. (handle_counted_by_for_component_ref): Add one more argument. (build_component_ref): Call the new prototype of handle_counted_by_for_component_ref. gcc/ChangeLog: * doc/extend.texi: Extend counted_by attribute to pointer fields in structures. Add one more requirement to pointers with counted_by attribute. gcc/testsuite/ChangeLog: * gcc.dg/flex-array-counted-by.c: Update test. * gcc.dg/pointer-counted-by-1.c: New test. * gcc.dg/pointer-counted-by-2.c: New test. * gcc.dg/pointer-counted-by-3.c: New test. * gcc.dg/pointer-counted-by-8.c: New test. * gcc.dg/pointer-counted-by-9.c: New test. * gcc.dg/pointer-counted-by.c: New test.
2025-08-15RISC-V: MIPS prefetch extensions for MIPS RV64 P8700 and can be enabled with ↵Umesh Kalappa10-5/+131
xmipscbop. Addressed the comments and tested "runtest --tool gcc --target_board='riscv-sim/-march=rv64gc_zba_zbb_zbc_zbs/-mabi=lp64/-mcmodel=medlow' riscv.exp" and 32 bit too lint warnings can be ignored for riscv-ext.opt. gcc/ChangeLog: * config/riscv/riscv-ext-mips.def (DEFINE_RISCV_EXT): Added mips prefetch extension. * config/riscv/riscv-ext.opt: Generated file. * config/riscv/riscv.md (prefetch): Added mips prefetch address operand constraint. * config/riscv/constraints.md: Added mips specific constraint. * config/riscv/predicates.md (prefetch_operand): Updated for mips nine bits offset. * config/riscv/riscv.cc (riscv_prefetch_offset_address_p): Legitimate address with offset for prefetch check. * config/riscv/riscv-protos.h: Likewise. * config/riscv/riscv.h: Macros to support for mips cached type. * doc/riscv-ext.texi: Updated for mips prefetch. gcc/testsuite/ChangeLog: * gcc.target/riscv/mipsprefetch.c: Test file for mips.pref.
2025-08-15testsuite: Add a test for [PR119156]Richard Sandiford1-0/+15
PR119156 was fixed by g:f702b593e7268ab161053bafd097f1b09933b783. This patch adds a test for it. gcc/testsuite/ PR target/119156 * gcc.target/aarch64/sve/pr119156_1.c: New test.
2025-08-15RISC-V: Allow errors to be suppressed when parsing architecturesRichard Sandiford5-134/+170
One of Alfie's FMV patches adds a hook that, in some cases, is used to silently query a target_version (with no diagnostics expected). In the review, I'd suggested handling this using a location_t *, with null meaning "suppress diagnostics": https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692113.html This patch tries to propagate that through the RISC-V parsing code. I realise this isn't very elegant, sorry. I think riscv_compare_version_priority should also logically suppress diagnostics, since it's supposed to be a pure query function. (From that point of view, advocating for this change for Alfie's patch might have been a bit unfair.) gcc/ * config/riscv/riscv-protos.h (riscv_process_target_version_attr): Change location_t argument to location_t *. * config/riscv/riscv-subset.h (riscv_subset_list::riscv_subset_list): Change location_t argument to location_t *. (riscv_subset_list::parse): Likwise. (riscv_subset_list::set_loc): Likewise. (riscv_minimal_hwprobe_feature_bits): Likewise. (riscv_subset_list::m_loc): Change type to location_t. * common/config/riscv/riscv-common.cc (riscv_subset_list::riscv_subset_list): Change location_t argument to location_t *. (riscv_subset_list::add): Suppress diagnostics when m_loc is null. (riscv_subset_list::parsing_subset_version): Likewise. (riscv_subset_list::parse_profiles): Likewise. (riscv_subset_list::parse_base_ext): Likewise. (riscv_subset_list::parse_single_std_ext): Likewise. (riscv_subset_list::check_conflict_ext): Likewise. (riscv_subset_list::parse_single_multiletter_ext): Likewise. (riscv_subset_list::parse): Change location_t argument to location_t *. (riscv_subset_list::set_loc): Likewise. (riscv_minimal_hwprobe_feature_bits): Likewise. (riscv_parse_arch_string): Update call accordingly. * config/riscv/riscv-target-attr.cc (riscv_target_attr_parser::m_loc): Change type to location_t *. (riscv_target_attr_parser::riscv_target_attr_parser): Change location_t argument to location_t *. (riscv_process_one_target_attr): Likewise. (riscv_process_target_attr): Likewise. (riscv_process_target_version_attr): Likewise. (riscv_target_attr_parser::parse_arch): Suppress diagnostics when m_loc is null. (riscv_target_attr_parser::handle_arch): Likewise. (riscv_target_attr_parser::handle_cpu): Likewise. (riscv_target_attr_parser::handle_tune): Likewise. (riscv_target_attr_parser::handle_priority): Likewise. (riscv_option_valid_attribute_p): Update call accordingly. (riscv_option_valid_version_attribute_p): Likewise. * config/riscv/riscv.cc (parse_features_for_version): Add a location_t * argument. (dispatch_function_versions): Update call accordingly. (riscv_compare_version_priority): Likewise, suppressing diagnostics.
2025-08-15Use gimple_call_fntype rather than gimple_call_fndecl in ↵Kito Cheng1-1/+1
pass_return_slot::execute Call with funciton pointer might not able to get the fndecl, but fntype so use gimple_call_fntype instead of gimple_call_fndecl. aggregate_value_p can handle fndecl and fntype right (and even CALL_EXPR), so I think this change is safe. gcc/ChangeLog: * tree-nrv.cc (pass_return_slot::execute): Use gimple_call_fntype instead of gimple_call_fndecl.
2025-08-15LoongArch: Fix ICE caused by function add_stmt_cost[PR121542].Lulu Cheng2-0/+55
PR target/121542 gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_vector_costs::add_stmt_cost): When using vectype, first determine whether it is NULL. gcc/testsuite/ChangeLog: * gcc.target/loongarch/pr121542.c: New test.
2025-08-15Daily bump.GCC Administrator4-1/+105
2025-08-14c++: Fix up build_cplus_array_type [PR121524]Jakub Jelinek2-1/+14
The following testcase is miscompiled since my r15-3046 change to properly apply std attributes after closing ] for arrays to the array type. Array type is not a class type, so when cplus_decl_attribute is called on the ARRAY_TYPE, it doesn't do ATTR_FLAG_TYPE_IN_PLACE. Though, for alignas/gnu::aligned/deprecated/gnu::unavailable/gnu::unused attributes the handlers of those attributes for non-ATTR_FLAG_TYPE_IN_PLACE on types call build_variant_type_copy and modify some flags on the new variant type. They also usually don't clear *no_add_attrs, so the caller then checks if the attributes are present on the new type and if not, calls build_type_attribute_variant. On the following testcase, it results in the B::foo type to be properly 32 byte aligned. The problem happens later when we build_cplus_array_type for C::a. elt_type is T (typedef, or using works likewise), we get as m main variant type with unsigned int element type but because elt_type is different, build_cplus_array_type searches the TYPE_NEXT_VARIANT chain to find if there isn't already a useful ARRAY_TYPE to reuse. It checks for NULL TYPE_NAME, NULL TYPE_ATTRIBUTES and the right TREE_TYPE. Unfortunately this is not good enough, build_variant_type_copy above created a variant type on which it modified TYPE_USER_ALIGN and TYPE_ALIGN, but TYPE_ATTRIBUTES is still NULL, only the build_type_attribute_variant call later adds attributes. The problem is that the intermediate type is found in the TYPE_NEXT_VARIANT chain and reused. The following patch adds conditions to prevent problems with the affected attributes (except gnu::unused, I think whether TREE_USED is set or not shouldn't prevent sharing). In particular, if TYPE_USER_ALIGN is not set on the variant, it wasn't user realigned, if it is set, it verifies it has it set because the elt_type has been user aligned and TYPE_ALIGN is the expected one. For deprecated it punts on the flag being set and for gnu::unavailable as well. 2025-08-14 Jakub Jelinek <jakub@redhat.com> PR c++/121524 * tree.cc (build_cplus_array_type): Don't reuse variant type if it has TREE_DEPRECATED or TREE_UNAVAILABLE flags set or, unless elt_type has TYPE_USER_ALIGN set and TYPE_ALIGN is TYPE_ALIGN of elt_type, TYPE_USER_ALIGN is not set. * g++.dg/cpp0x/gen-attrs-89.C: New test.
2025-08-14[PR target/119275][RISC-V] Avoid calling gen_lowpart in cases where it would ICEJeff Law2-1/+28
So this is a minor bug in the riscv move expanders. It has a special cases for extraction from vector objects which makes assumptions that it can use gen_lowpart unconditionally. That's not always the case. We can just bypass that special code for cases where we can't use gen_lowpart and let the more generic code run. If gen_lowpart_common indicates we've got a case that can't be handled we just bypass the special extraction code. Tested on riscv64-elf and riscv32-elf. Waiting for pre-commit CI to do its thing. PR target/119275 gcc/ * config/riscv/riscv.cc (riscv_legitimize_move): Avoid calling gen_lowpart for cases where it'll fail. Just use standard expander paths for those cases. gcc/testsuite/ * gcc.target/riscv/pr119275.c: New test.
2025-08-14fix cris-elf build with binutils-2.45Mikael Pettersson1-1/+1
Since the cris port was added to gcc it has passed --em=criself to gas, as an abbreviation for --emulation=criself. Starting with binutils-2.45 that causes a hard error in gas due to ambiguity with another option. Fixed by replacing the abbreviation with the complete option. Tested by building a cross to cris-elf with binutils-2.45, which failed before but now succeeds. gcc/ PR target/121336 * config/cris/cris.h: Do not abbreviate --emulation. Signed-off-by: Mikael Pettersson <mikpelinux@gmail.com>
2025-08-14powerpc: Add missing modes to P9 if_then_elses [PR121501]Richard Sandiford1-20/+20
These patterns had one (if_then_else ...) nested within another. The outer if_then_else had SImode, which means that the "then" and "else" should also be SImode (unless they're const_ints). However, the inner if_then_else was modeless, which led to an assertion failure when trying to take a subreg of it. gcc/ PR target/121501 * config/rs6000/rs6000.md (cmprb, setb_signed, setb_unsigned) (cmprb2, cmpeqb): Add missing modes to nested if_then_elses.
2025-08-14forwprop: Limit alias walk in some cases [PR121474]Andrew Pinski2-16/+34
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692091.html pointed out: ''' Oh, as we now do alias walks in forwprop maybe we should make this conditional and do this not for all pass instances, since it makes forwprop possibly a lot slower? ''' This does patch limits the walk in a few different ways. First only allow for a full walk in the first 2 forwprop (the one before inlining and the one after inlining). The other 2 forwprop are less likely to find any extra zero prop so limit them so there is no walk. There is an exception to the rule though, allowing to skip over clobbers still since those will not take a long time for the walk and from when looking at benchmarks the only place where forwprop3/4 would cause a zero prop. The other thing is limit a full walk only if flag_expensive_optimizations is true. This limits the walk for -O1 since flag_expensive_optimizations is turned on at -O2+. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/121474 gcc/ChangeLog: * passes.def: Update forwprop1/2 to have full_walk to be true. * tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Add new argument full_walk. Take into account the full_walk and clobbers at the end of the limit can be done always. (simplify_builtin_call): Add new argument, full_walk. Update call to optimize_aggr_zeroprop. (pass_forwprop): Add m_full_walk field. (pass_forwprop::set_pass_param): Update for m_full_walk. (pass_forwprop::execute): Update call to simplify_builtin_call and optimize_aggr_zeroprop. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-14forwprop: Copy prop aggregates into argsAndrew Pinski2-55/+137
This implements the simple copy prop of aggregates into arguments of function calls. This can reduce the number of copies done. Just like removing of an extra copy in general, this can and will help out SRA; since we might not need to do a full scalarization of the aggregate now. This is the simpliest form of this copy prop of aggregates into function arguments. Changes since v1: * v2: Merge in the changes of r16-3160-g2fe432175ef135. Move the checks for assignment and call statement into optimize_agr_copyprop rather than having it in optimize_agr_copyprop_1 and optimize_agr_copyprop_arg. gcc/ChangeLog: * tree-ssa-forwprop.cc (optimize_agr_copyprop_1): New function split out of ... (optimize_agr_copyprop): Here. Also try calling optimize_agr_copyprop_arg. (optimize_agr_copyprop_arg): New function. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/copy-prop-aggregate-arg-1.c: New test. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-14s390: Fix zero extend patterns using vlgvStefan Schulze Frielinghaus4-70/+98
In commit r16-2316-gc6676092318 mistakenly patterns were introduced which actually should have been merged as alternatives to existing zero extend patterns. While on it, generalize the vec_extract patterns and also allow registers for the index. A subsequent patch will add register+immediate support. gcc/ChangeLog: * config/s390/s390.md: Merge movdi<mode>_zero_extend_A and movsi<mode>_zero_extend_A into zero_extendsidi2 and zero_extendhi<mode>2_z10 and zero_extend<HQI:mode><GPR:mode>2_extimm. * config/s390/vector.md (*movdi<mode>_zero_extend_A): Remove. (*movsi<mode>_zero_extend_A): Remove. (*movdi<mode>_zero_extend_B): Move to vec_extract patterns and rename to *vec_extract<mode>_zero_extend. (*movsi<mode>_zero_extend_B): Ditto. gcc/testsuite/ChangeLog: * gcc.target/s390/vector/vlgv-zero-extend-1.c: Require target s390_mvx. * gcc.target/s390/vector/vlgv-zero-extend-2.c: New test.
2025-08-14testsuite: Fix asm-hard-reg-error-3.c for arm [PR121511]Stefan Schulze Frielinghaus1-1/+1
This test is about register pairs. On arm a long long is accepted in thumb mode in any register 0-6 whereas in arm mode this is restricted to even register pairs. Thus, in order to trigger the error even if gcc is configured with --with-mode=thumb, add option -marm. gcc/testsuite/ChangeLog: PR target/121511 * gcc.dg/asm-hard-reg-error-3.c: Add additional option -marm for target arm.
2025-08-13x86: Disallow MMX and 80387 in no_caller_saved_registers functionH.J. Lu10-7/+27
commit 9804b23198b39f85a7258be556c5e8aed44b9efc Author: H.J. Lu <hjl.tools@gmail.com> Date: Sun Apr 13 11:38:24 2025 -0700 x86: Add preserve_none and update no_caller_saved_registers attributes allowed MMX/80387 instructions in functions with no_caller_saved_registers attribute by accident. Update ix86_set_current_function to properly check if MMX and 80387 are enabled. gcc/ PR target/121540 * config/i386/i386-options.cc (ix86_set_current_function): Properly check if MMX and 80387 are enabled. gcc/testsuite/ PR target/121540 * gcc.target/i386/no-callee-saved-19a.c (dg-options): Add "-mno-avx -mno-mmx -mno-80387" * gcc.target/i386/no-callee-saved-19b.c: Likewise. * gcc.target/i386/no-callee-saved-19c.c: Likewise. * gcc.target/i386/no-callee-saved-19d.c: Likewise. * gcc.target/i386/no-callee-saved-19e.c: Likewise. * gcc.target/i386/pr121208-1a.c: Likewise. * gcc.target/i386/pr121208-1b.c: Likewise. * gcc.target/i386/pr121540-1.c: New test. * gcc.target/i386/pr121540-2.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-14Daily bump.GCC Administrator8-1/+450
2025-08-13[RISC-V][PR target/121531] Cover missing insn types in p400 and p600 ↵Jeff Law3-0/+32
scheduler models So the usual problems, DFAs without full coverage. I took the output of Kito's checker and use that to construct a dummy reservation for the p400 and p600 sifive models. Tested on riscv32-elf and riscv64-elf with no regressions. Pushing to the trunk once pre-commit CI gives the green light. PR target/121531 gcc/ * config/riscv/sifive-p400.md (sifive_p400_unknown): New reservation. * config/riscv/sifive-p600.md (sifive_p600_unkonwn): Likewise. gcc/testsuite/ * gcc.target/riscv/pr121531.c: New test.
2025-08-13c++: P2036R3 - Change scope of lambda trailing-return-type [PR102610]Marek Polacek20-37/+750
This patch is an attempt to implement P2036R3 along with P2579R0, fixing build breakages caused by P2036R3. The simplest example is: auto counter1 = [j=0]() mutable -> decltype(j) { return j++; }; which currently doesn't compile because the 'j' in the capture isn't visible in the trailing return type. With these proposals, the 'j' will be in a lambda scope which spans the trailing return type, so this test will compile. This oughtn't be difficult but decltype and other issues made this patch much more challenging. We have to push the explicit captures before going into _lambda_declarator_opt because that is what parses the trailing return type. Yet we can't build any captures until after _lambda_body -> start_lambda_function which creates the lambda's operator(), without which we can't build a proxy, but _lambda_body happens only after parsing the declarator. This patch works around it by creating a fake operator() and adding it to the capture and then removing it when we have the real operator(). Another thing is that in "-> decltype(j)" we don't have the right current_function_decl yet. If current_lambda_expr gives us a lambda, we know this decltype appertains to a lambda. But we have to know if we are in a parameter-declaration-clause: as per [expr.prim.id.unqual]/4.4, if we are, we shouldn't be adding "const". The new LAMBDA_EXPR_CONST_QUAL_P flag tracks this. But it doesn't handle nested lambdas yet, specifically, [expr.prim.id.unqual]/14. I don't think this patch changes behavior for the tests in "capture-default with [=]" as the paper promises; clang++ behaves the same as gcc with this patch. PR c++/102610 gcc/cp/ChangeLog: * cp-tree.h (LAMBDA_EXPR_CONST_QUAL_P): Define. (maybe_add_dummy_lambda_op): Declare. (remove_dummy_lambda_op): Declare. (push_capture_proxies): Adjust. * lambda.cc (build_capture_proxy): No longer static. New early_p parameter. Use it. (add_capture): Adjust the call to build_capture_proxy. (resolvable_dummy_lambda): Check DECL_LAMBDA_FUNCTION_P. (push_capture_proxies): New. (start_lambda_function): Use it. * name-lookup.cc (check_local_shadow): Give an error for is_capture_proxy. (cp_binding_level_descriptor): Add lambda-scope. (begin_scope) <case sk_lambda>: New case. * name-lookup.h (enum scope_kind): Add sk_lambda. (struct cp_binding_level): Widen kind. * parser.cc (cp_parser_lambda_expression): Create a new (lambda) scope after the lambda-introducer. (cp_parser_lambda_declarator_opt): Set LAMBDA_EXPR_CONST_QUAL_P. Create a dummy operator() if needed. Inject the captures into the lambda scope. Remove the dummy operator(). (make_dummy_lambda_op): New. (maybe_add_dummy_lambda_op): New. (remove_dummy_lambda_op): New. * pt.cc (tsubst_lambda_expr): Begin/end a lambda scope. Push the capture proxies. Build/remove a dummy operator() if needed. Set LAMBDA_EXPR_CONST_QUAL_P. * semantics.cc (parsing_lambda_declarator): New. (outer_var_p): Also consider captures as outer variables if in a lambda declarator. (process_outer_var_ref): Reset containing_function when parsing_lambda_declarator. (finish_decltype_type): Process decls in the lambda-declarator as well. Look at LAMBDA_EXPR_CONST_QUAL_P unless we have an xobj function. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-decltype3.C: Remove xfail. * g++.dg/warn/Wshadow-19.C: Add -Wpedantic. Adjust a dg-warning. * g++.dg/warn/Wshadow-6.C: Adjust expected diagnostics. * g++.dg/cpp23/lambda-scope1.C: New test. * g++.dg/cpp23/lambda-scope2.C: New test. * g++.dg/cpp23/lambda-scope3.C: New test. * g++.dg/cpp23/lambda-scope4.C: New test. * g++.dg/cpp23/lambda-scope4b.C: New test. * g++.dg/cpp23/lambda-scope5.C: New test. * g++.dg/cpp23/lambda-scope6.C: New test. * g++.dg/cpp23/lambda-scope7.C: New test. * g++.dg/cpp23/lambda-scope8.C: New test. * g++.dg/cpp23/lambda-scope9.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-13diagnostics/output-spec.cc: simplify implementationDavid Malcolm1-40/+13
No functional change intended. gcc/ChangeLog: * diagnostics/output-spec.cc (sarif_scheme_handler::make_sink): Populate sarif_generation_options instance directly, rather than through local variables. (sarif_scheme_handler::make_sarif_gen_opts): Drop. (html_scheme_handler::make_sink): Populate html_generation_options instance directly, rather than through local variables. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-13c++: Implement C++26 P1306R5 - Expansion statements [PR120776]Jakub Jelinek37-164/+2952
The following patch implements the C++26 P1306R5 - Expansion statements paper. When expansion statements are used outside of templates, the lowering of the statement uses push_tinst_level_loc and instantiates the body multiple times, otherwise when the new TEMPLATE_FOR_STMT statement is being instantiated and !processing_template_decl, it instantiates the body several times with just local_specialization_stack around each iteration but with the original args. Because the lowering of these statements is mostly about instantiation, I've put the lowering code into pt.cc rather than semantics.cc. Only destructuring expansion statements currently use in the patch temporary lifetime extension which matches the proposed resolution of https://cplusplus.github.io/CWG/issues/3043.html I'm not sure what will CWG decide about that if there will be some temporary lifetime extension for enumerating expansion statements and if yes, under what exact rules (e.g. whether it extends all the temporaries across one iteration of the body, or only if a reference is initialized or nothing at all). And for iterating expansion statements, I think I don't understand the P2686R4 rules well yet, I think if the expansion-initializer is used in static constexpr rvalue reference, then it isn't needed, but not sure if it won't be needed if static would be dropped (whether struct S { constexpr S () : s (0) {} constexpr ~S () {} int s; }; struct T { const S &t, &u; }; void foo () { constexpr T t = { S {}, S {} }; use (t.t, t.u); } is ok under P2686R4; though without constexpr before T I see S::~S () being called after use, not at the end of the t declaration, so maybe it is fine also without static). As per https://cplusplus.github.io/CWG/issues/3044.html the patch uses build_int_cst (ptrdiff_type_node, i) to create second operand of begin + i and doesn't lookup overloaded comma operator (note, I'm actually not even creating a lambda there, just using TARGET_EXPRs). I guess my preference would be dropping those 4 static keywords from [stmt.expand] but the patch does use those for now and it won't be possible to change that until the rest of P2686R4 is implemented. As per https://cplusplus.github.io/CWG/issues/3045.html it treats sk_template_for like sk_for for the purpose of redeclaration of vars in the body but doesn't yet reject [[fallthrough]]; in the expansion stmt body (when not nested in another switch). I'm not sure if cp_perform_range_for_lookup used in the patch is exactly what we want for the https://eel.is/c++draft/stmt.expand#3.2 - it does finish_call_expr on the perform_koenig_lookup as well, shouldn't for the decision whether it is iterating or destructing (i.e. tf_none) just call perform_koenig_lookup and check if it found some FUNCTION_DECL/OVERLOAD/TEMPLATE_DECL? cp_decomp_size in the patch has tsubst_flags_t argument and attempts to be SFINAE friendly, even when it isn't needed strictly for this patch. This is with PR96185 __builtin_structured_binding_size implementation in mind (to follow clang). The new TEMPLATE_FOR_STMT statement is expected to be lowered to something that doesn't use the statement at all, I've implemented break/continue discovery in the body, so all I needed was to punt on TEMPLATE_FOR_STMT in potential_constant_expression_1 so that we don't try to constant evaluate it when it is still dependent (and cxx_eval_constant_expression rejects it without any extra code). I think only enumerating and iterating expansion statements can have zero iteration, because for destructuring ones it doesn't use a structured binding pack and so valid structured binding has to have at least one iteration. Though https://cplusplus.github.io/CWG/issues/3048.html could change that, this patch currently rejects it though. 2025-08-13 Jakub Jelinek <jakub@redhat.com> PR c++/120776 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_expansion_statements=202506L for C++26. gcc/cp/ * cp-tree.def: Implement C++26 P1306R5 - Expansion statements. (TEMPLATE_FOR_STMT): New tree code. * cp-tree.h (struct saved_scope): Add expansion_stmt. (in_expansion_stmt): Define. (TEMPLATE_FOR_DECL, TEMPLATE_FOR_EXPR, TEMPLATE_FOR_BODY, TEMPLATE_FOR_SCOPE, TEMPLATE_FOR_INIT_STMT): Define. (struct tinst_level): Adjust comment. (cp_decomp_size, finish_expansion_stmt, do_pushlevel, cp_build_range_for_decls, build_range_temp, cp_perform_range_for_lookup, begin_template_for_scope): Declare. (finish_range_for_stmt): Remove declaration. * cp-objcp-common.cc (cp_common_init_ts): Handle TEMPLATE_FOR_STMT. * name-lookup.h (enum scope_kind): Add sk_template_for enumerator. (struct cp_binding_level): Enlarge kind bitfield from 4 to 5 bits. Adjust comment with remaining space bits. * name-lookup.cc (check_local_shadow): Handle sk_template_for like sk_for. (cp_binding_level_descriptor): Add entry for sk_template_for. (begin_scope): Handle sk_template_for. * parser.h (IN_EXPANSION_STMT): Define. * parser.cc (cp_debug_parser): Print IN_EXPANSION_STMT bit. (cp_parser_lambda_expression): Temporarily clear in_expansion_stmt. (cp_parser_statement): Handle RID_TEMPLATE followed by RID_FOR for C++11. (cp_parser_label_for_labeled_statement): Complain about named labels inside of expansion stmt body. (cp_hide_range_decl): New function. (cp_parser_range_for): Use it. Adjust do_range_for_auto_deduction caller. Remove second template argument from auto_vecs bindings and names. (build_range_temp): No longer static. (do_range_for_auto_deduction): Add expansion_stmt argument. (cp_build_range_for_decls): New function. (cp_convert_range_for): Use it. Call cp_perform_range_for_lookup rather than cp_parser_perform_range_for_lookup. (cp_parser_perform_range_for_lookup): Rename to ... (cp_perform_range_for_lookup): ... this. No longer static. Add complain argument and handle it. (cp_parser_range_for_member_function): Rename to ... (cp_range_for_member_function): ... this. (cp_parser_expansion_statement): New function. (cp_parser_jump_statement): Handle IN_EXPANSION_STMT. (cp_convert_omp_range_for): Adjust do_range_for_auto_deduction caller. Call cp_perform_range_for_lookup rather than cp_parser_perform_range_for_lookup. * error.cc (print_instantiation_full_context): Handle tldcl being TEMPLATE_FOR_STMT. (print_instantiation_partial_context_line): Likewise. * constexpr.cc (potential_constant_expression_1): Handle TEMPLATE_FOR_STMT. * decl.cc (poplevel_named_label_1): Use obl instead of bl->level_chain. (finish_case_label): Diagnose case labels inside of template for. (find_decomp_class_base): Add complain argument, don't diagnose anything and just return error_mark_node if tf_none, adjust recursive call. (cp_decomp_size): New function. (cp_finish_decomp): Adjust find_decomp_class_base caller. * semantics.cc (do_pushlevel): No longer static. (begin_template_for_scope): New function. * pt.cc (push_tinst_level_loc): Handle TEMPLATE_FOR_STMT. (reopen_tinst_level): Likewise. (tsubst_stmt): Handle TEMPLATE_FOR_STMT. (struct expansion_stmt_bc): New type. (expansion_stmt_find_bc_r, finish_expansion_stmt): New functions. * decl2.cc (decl_dependent_p): Return true for current function's decl if in_expansion_stmt. * call.cc (extend_ref_init_temps): Don't extend_all_temps if TREE_STATIC (decl). * cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle TEMPLATE_FOR_STMT. gcc/testsuite/ * g++.dg/cpp1z/decomp64.C: New test. * g++.dg/cpp26/expansion-stmt1.C: New test. * g++.dg/cpp26/expansion-stmt2.C: New test. * g++.dg/cpp26/expansion-stmt3.C: New test. * g++.dg/cpp26/expansion-stmt4.C: New test. * g++.dg/cpp26/expansion-stmt5.C: New test. * g++.dg/cpp26/expansion-stmt6.C: New test. * g++.dg/cpp26/expansion-stmt7.C: New test. * g++.dg/cpp26/expansion-stmt8.C: New test. * g++.dg/cpp26/expansion-stmt9.C: New test. * g++.dg/cpp26/expansion-stmt10.C: New test. * g++.dg/cpp26/expansion-stmt11.C: New test. * g++.dg/cpp26/expansion-stmt12.C: New test. * g++.dg/cpp26/expansion-stmt13.C: New test. * g++.dg/cpp26/expansion-stmt14.C: New test. * g++.dg/cpp26/expansion-stmt15.C: New test. * g++.dg/cpp26/expansion-stmt16.C: New test. * g++.dg/cpp26/expansion-stmt17.C: New test. * g++.dg/cpp26/expansion-stmt18.C: New test. * g++.dg/cpp26/expansion-stmt19.C: New test. * g++.dg/cpp26/feat-cxx26.C: Add __cpp_expansion_statements tests.
2025-08-13Mark epiphany and rl78 as obsolete targetsAndrew Pinski1-1/+1
rl78 still uses reload rather than LRA. epiphany still uses reload and causes ICEs during reload. Both don't have a maintainer. epiphany has been without one since 2024 (2023 email) while rl78 has been without one since 2018. gcc/ChangeLog: * config.gcc: Mark epiphany*-*-* and rl78*-*-* as obsolete targets. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>