aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2025-08-19c++: constrained corresponding using from partial spec [PR121351]Patrick Palka1-0/+23
When comparing constraints during correspondence checking for a using from a partial specialization, we need to substitute the partial specialization arguments into the constraints rather than the primary template arguments. Otherwise we incorrectly reject e.g. the below testcase as ambiguous since we substitute T=int* instead of T=int into #1's constraints and don't notice the correspondence. This patch corrects the recent r16-2771-gb9f1cc4e119da9 fix by using outer_template_args instead of TI_ARGS of the DECL_CONTEXT, which should always give the correct outer arguments for substitution. PR c++/121351 gcc/cp/ChangeLog: * class.cc (add_method): Use outer_template_args when substituting outer template arguments into constraints. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-using7.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-19AArch64: Use vectype from SLP node instead of stmt_info [PR121536]Tamar Christina1-0/+14
commit g:1786be14e94bf1a7806b9dc09186f021737f0227 stops storing in STMT_VINFO_VECTYPE the vectype of the current stmt being vectorized and instead requires the use of SLP_TREE_VECTYPE for everything but data-refs. This means that STMT_VINFO_VECTYPE (stmt_info) will always be NULL and so aarch64_bool_compound_p will never properly cost predicate AND operations anymore resulting in less vectorization. This patch changes it to use SLP_TREE_VECTYPE and pass the slp_node to aarch64_bool_compound_p. gcc/ChangeLog: PR target/121536 * config/aarch64/aarch64.cc (aarch64_bool_compound_p): Use SLP_TREE_VECTYPE instead of STMT_VINFO_VECTYPE. (aarch64_adjust_stmt_cost, aarch64_vector_costs::count_ops): Pass SLP node to aarch64_bool_compound_p. gcc/testsuite/ChangeLog: PR target/121536 * g++.target/aarch64/sve/pr121536.cc: New test.
2025-08-19testsuite: Fix g++.dg/abi/mangle83.C [PR121578]Nathaniel Shead1-1/+1
This testcase (added in r16-3233-g7921bb4afcb7a3) mistakenly only required C++14, but auto template paramaters are a C++17 feature. PR c++/121578 gcc/testsuite/ChangeLog: * g++.dg/abi/mangle83.C: Requires C++17. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-19c++/modules: Fix exporting using-decls of unattached purview functions ↵Nathaniel Shead2-0/+22
[PR120195] We have logic to adjust a function decl if it gets re-declared as a using-decl with different purviewness, but we also need to do the same if it gets redeclared with different exportedness. PR c++/120195 gcc/cp/ChangeLog: * name-lookup.cc (do_nonmember_using_decl): Also handle change in exportedness of a function. gcc/testsuite/ChangeLog: * g++.dg/modules/using-32_a.C: New test. * g++.dg/modules/using-32_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-19testsuite: Fix PR108080 testcase for some targets [PR121396]Nathaniel Shead1-1/+1
I added a testcase for the (temporary) warning that we don't currently support the 'gnu::optimize' or 'gnu::target' attributes in r15-10183; however, some targets produce target nodes even when only an optimize attribute is present. This adjusts the warning. PR c++/108080 PR c++/121396 gcc/testsuite/ChangeLog: * g++.dg/modules/pr108080.H: Also allow target warnings. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-18Daily bump.GCC Administrator1-0/+56
2025-08-17[PR target/121213] Avoid unnecessary constant load in amoswapAustin Law1-0/+17
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-16x86: Add target("80387") function attributeH.J. Lu7-0/+67
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 Administrator1-0/+17
2025-08-17c++: Implement P2115R0 linkage changes for unnamed unscoped enums [PR120503]Nathaniel Shead7-7/+64
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-16fortran: Set DECL_TLS_MODEL after processing a variableH.J. Lu1-0/+15
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 Administrator1-0/+111
2025-08-15c++: Implement __builtin_structured_binding_size traitJakub Jelinek5-1/+191
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 Jelinek14-3/+108
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 Jelinek1-0/+79
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 Jelinek3-6/+218
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-15RISC-V: fix __builtin_round clobbering FP exceptions flags [PR121534]Vineet Gupta1-2/+2
__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 Zhao1-1/+1
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 Zhao5-0/+223
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 Zhao7-1/+397
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 Kalappa1-0/+31
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-15LoongArch: Fix ICE caused by function add_stmt_cost[PR121542].Lulu Cheng1-0/+54
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 Administrator1-0/+40
2025-08-14c++: Fix up build_cplus_array_type [PR121524]Jakub Jelinek1-0/+8
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 Law1-0/+26
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-14forwprop: Copy prop aggregates into argsAndrew Pinski1-0/+21
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 Frielinghaus2-1/+37
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. Lu9-7/+23
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 Administrator1-0/+112
2025-08-13[RISC-V][PR target/121531] Cover missing insn types in p400 and p600 ↵Jeff Law1-0/+5
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 Polacek13-7/+538
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-13c++: Implement C++26 P1306R5 - Expansion statements [PR120776]Jakub Jelinek21-0/+1810
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-13x86-64: Remove redundant TLS callsH.J. Lu18-0/+445
For TLS calls: 1. UNSPEC_TLS_GD: (parallel [ (set (reg:DI 0 ax) (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr"))) (const_int 0 [0]))) (unspec:DI [(symbol_ref:DI ("e") [flags 0x50]) (reg/f:DI 7 sp)] UNSPEC_TLS_GD) (clobber (reg:DI 5 di))]) 2. UNSPEC_TLS_LD_BASE: (parallel [ (set (reg:DI 0 ax) (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr"))) (const_int 0 [0]))) (unspec:DI [(reg/f:DI 7 sp)] UNSPEC_TLS_LD_BASE)]) 3. UNSPEC_TLSDESC: (parallel [ (set (reg/f:DI 104) (plus:DI (unspec:DI [ (symbol_ref:DI ("_TLS_MODULE_BASE_") [flags 0x10]) (reg:DI 114) (reg/f:DI 7 sp)] UNSPEC_TLSDESC) (const:DI (unspec:DI [ (symbol_ref:DI ("e") [flags 0x1a]) ] UNSPEC_DTPOFF)))) (clobber (reg:CC 17 flags))]) (parallel [ (set (reg:DI 101) (unspec:DI [(symbol_ref:DI ("e") [flags 0x50]) (reg:DI 112) (reg/f:DI 7 sp)] UNSPEC_TLSDESC)) (clobber (reg:CC 17 flags))]) they return the same value for the same input value. But multiple calls with the same input value may be generated for simple programs like: void a(long *); int b(void); void c(void); static __thread long e; long d(void) { a(&e); if (b()) c(); return e; } When compiled with -O2 -fPIC -mtls-dialect=gnu2, the following codes are generated: .type d, @function d: .LFB0: .cfi_startproc pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 leaq e@TLSDESC(%rip), %rbx movq %rbx, %rax call *e@TLSCALL(%rax) addq %fs:0, %rax movq %rax, %rdi call a@PLT call b@PLT testl %eax, %eax jne .L8 movq %rbx, %rax call *e@TLSCALL(%rax) popq %rbx .cfi_remember_state .cfi_def_cfa_offset 8 movq %fs:(%rax), %rax ret .p2align 4,,10 .p2align 3 .L8: .cfi_restore_state call c@PLT movq %rbx, %rax call *e@TLSCALL(%rax) popq %rbx .cfi_def_cfa_offset 8 movq %fs:(%rax), %rax ret .cfi_endproc There are 3 "call *e@TLSCALL(%rax)". They all return the same value. Rename the remove_redundant_vector pass to the x86_cse pass, for 64bit, extend it to also remove redundant TLS calls to generate: d: .LFB0: .cfi_startproc pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 leaq e@TLSDESC(%rip), %rax movq %fs:0, %rdi call *e@TLSCALL(%rax) addq %rax, %rdi movq %rax, %rbx call a@PLT call b@PLT testl %eax, %eax jne .L8 movq %fs:(%rbx), %rax popq %rbx .cfi_remember_state .cfi_def_cfa_offset 8 ret .p2align 4,,10 .p2align 3 .L8: .cfi_restore_state call c@PLT movq %fs:(%rbx), %rax popq %rbx .cfi_def_cfa_offset 8 ret .cfi_endproc with only one "call *e@TLSCALL(%rax)". This reduces the number of __tls_get_addr calls in libgcc.a by 72%: __tls_get_addr calls before after libgcc.a 868 243 gcc/ PR target/81501 * config/i386/i386-features.cc (x86_cse_kind): Add X86_CSE_TLS_GD, X86_CSE_TLS_LD_BASE and X86_CSE_TLSDESC. (redundant_load): Renamed to ... (redundant_pattern): This. (ix86_place_single_vector_set): Replace redundant_load with redundant_pattern. (replace_tls_call): New. (ix86_place_single_tls_call): Likewise. (pass_remove_redundant_vector_load): Renamed to ... (pass_x86_cse): This. Add val, def_insn, mode, scalar_mode, kind, x86_cse, candidate_gnu_tls_p, candidate_gnu2_tls_p and candidate_vector_p. (pass_x86_cse::candidate_gnu_tls_p): New. (pass_x86_cse::candidate_gnu2_tls_p): Likewise. (pass_x86_cse::candidate_vector_p): Likewise. (remove_redundant_vector_load): Renamed to ... (pass_x86_cse::x86_cse): This. Extend to remove redundant TLS calls. (make_pass_remove_redundant_vector_load): Renamed to ... (make_pass_x86_cse): This. * config/i386/i386-passes.def: Replace pass_remove_redundant_vector_load with pass_x86_cse. * config/i386/i386-protos.h (ix86_tls_get_addr): New. (make_pass_remove_redundant_vector_load): Renamed to ... (make_pass_x86_cse): This. * config/i386/i386.cc (ix86_tls_get_addr): Remove static. * config/i386/i386.h (machine_function): Add tls_descriptor_call_multiple_p. * config/i386/i386.md (tls64): New attribute. (@tls_global_dynamic_64_<mode>): Set tls_descriptor_call_multiple_p. (@tls_local_dynamic_base_64_<mode>): Likewise. (@tls_dynamic_gnu2_64_<mode>): Likewise. (*tls_global_dynamic_64_<mode>): Set tls64 attribute to gd. (*tls_local_dynamic_base_64_<mode>): Set tls64 attribute to ld_base. (*tls_dynamic_gnu2_lea_64_<mode>): Set tls64 attribute to lea. (*tls_dynamic_gnu2_call_64_<mode>): Set tls64 attribute to call. (*tls_dynamic_gnu2_combine_64_<mode>): Set tls64 attribute to combine. gcc/testsuite/ PR target/81501 * g++.target/i386/pr81501-1.C: New test. * gcc.target/i386/pr81501-1a.c: Likewise. * gcc.target/i386/pr81501-1b.c: Likewise. * gcc.target/i386/pr81501-2a.c: Likewise. * gcc.target/i386/pr81501-2b.c: Likewise. * gcc.target/i386/pr81501-3.c: Likewise. * gcc.target/i386/pr81501-4a.c: Likewise. * gcc.target/i386/pr81501-4b.c: Likewise. * gcc.target/i386/pr81501-5.c: Likewise. * gcc.target/i386/pr81501-6a.c: Likewise. * gcc.target/i386/pr81501-6b.c: Likewise. * gcc.target/i386/pr81501-7.c: Likewise. * gcc.target/i386/pr81501-8a.c: Likewise. * gcc.target/i386/pr81501-8b.c: Likewise. * gcc.target/i386/pr81501-9a.c: Likewise. * gcc.target/i386/pr81501-9b.c: Likewise. * gcc.target/i386/pr81501-10a.c: Likewise. * gcc.target/i386/pr81501-10b.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-13Darwin: Handle string constants specially when asan is enabled.Iain Sandoe2-8/+8
The Darwin ABI uses a different section for string constants when address sanitizing is enabled. This adds defintions of the asan- specific sections and switches string constants to the correct section. It also makes the string constant symbols linker-visible when asan is enabled, but not otherwise. gcc/ChangeLog: * config/darwin-sections.def (asan_string_section, asan_globals_section, asan_liveness_section): New. * config/darwin.cc (objc_method_decl): Use asan sections when asan is enabled. (darwin_encode_section_info): Alter string constant linker visibility depending on asan. (machopic_select_section): Use the asan sections when asan is enabled. gcc/testsuite/ChangeLog: * gcc.dg/torture/darwin-cfstring-3.c: Adjust for amended string labels. * g++.dg/torture/darwin-cfstring-3.C: Likewise. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-08-13[RISC-V][PR target/121160] Avoid bogus force_reg callJeff Law1-0/+60
When we canonicalize the comparison for a czero sequence we need to handle both integer and fp comparisons. Furthermore, within the integer space we want to make sure we promote any sub-word objects to a full word. All that is working fine. After promotion we then force the value into a register if it is not a register or constant already. The idea is not to have to special case subregs in subsequent code. This works fine except when we're presented with a floating point object that would be a subword. (subreg:SF (reg:SI)) on rv64 for example. So this tightens up that force_reg step. Bootstapped and regression tested on riscv64-linux-gnu and tested on riscv32-elf and riscv64-elf. Pushing to the trunk after pre-commit verifies no regressions. Jeff PR target/121160 gcc/ * config/riscv/riscv.cc (canonicalize_comparands); Tighten check for forcing value into a GPR. gcc/testsuite/ * gcc.target/riscv/pr121160.c: New test.
2025-08-13Fortran: Use associated TBP subroutine not found [PR89092]Paul Thomas1-0/+49
2025-08-13 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/89092 * resolve.cc (was_declared): Add subroutine attribute. gcc/testsuite/ PR fortran/89092 * gfortran.dg/pr89092.f90: New test.
2025-08-13LoongArch: Add support for _BitInt [PR117599]Yang Yujie3-0/+199
This patch adds support for C23's _BitInt for LoongArch. From the LoongArch psABI[1]: > _BitInt(N) objects are stored in little-endian order in memory > and are signed by default. > > For N ≤ 64, a _BitInt(N) object have the same size and alignment > of the smallest fundamental integral type that can contain it. > The unused high-order bits within this containing type are filled > with sign or zero extension of the N-bit value, depending on whether > the _BitInt(N) object is signed or unsigned. The _BitInt(N) object > propagates its signedness to the containing type and is laid out > in a register or memory as an object of this type. > > For N > 64, _BitInt(N) objects are implemented as structs of 64-bit > integer chunks. The number of chunks is the smallest even integer M > so that M * 64 ≥ N. These objects are of the same size of the struct > containing the chunks, but always have 16-byte alignment. If there > are unused bits in the highest-ordered chunk that contains used > bits, they are defined as the sign- or zero- extension of the used > bits depending on whether the _BitInt(N) object is signed or > unsigned. If an entire chunk is unused, its bits are undefined. [1] https://github.com/loongson/la-abi-specs PR target/117599 gcc/ChangeLog: * config/loongarch/loongarch.h: Define a PROMOTE_MODE case for small _BitInts. * config/loongarch/loongarch.cc (loongarch_promote_function_mode): Same. (loongarch_bitint_type_info): New function. (TARGET_C_BITINT_TYPE_INFO): Declare. libgcc/ChangeLog: * config/loongarch/t-softfp-tf: Enable _BitInt helper functions. * config/loongarch/t-loongarch: Same. * config/loongarch/libgcc-loongarch.ver: New file. gcc/testsuite/ChangeLog: * gcc.target/loongarch/bitint-alignments.c: New test. * gcc.target/loongarch/bitint-args.c: New test. * gcc.target/loongarch/bitint-sizes.c: New test.
2025-08-12[RISC-V][PR target/121113] Handle HFmode in various insn reservationsJeff Law1-0/+5
So this is a minor bug in a few DFA descriptions such as the Xiangshan and a couple of the SiFive descriptions. While Xiangshan covers every insn type, some of the reservations check the mode of the operation. Concretely the fdiv/fsqrt unit reservations vary based on the mode. They handled DF/SF, but not HF (the relevant iterators don't include BF). This patch just adds HF support with the same characteristics as SF. Those who know these designs better could perhaps improve the reservation, but this at least keeps us from aborting. I did check the other published DFAs for mode dependent reservations. That's show I found the p400/p600 issue. Tested in my tester, waiting for CI to render its verdict before pushing. PR target/121113 gcc/ * config/riscv/sifive-p400.md: Handle HFmode for fdiv/fsqrt. * config/riscv/sifive-p600.md: Likewise. * config/riscv/xiangshan.md: Likewise. gcc/testsuite/ * gcc.target/riscv/pr121113.c: New test.
2025-08-12testsuite: fix jit.dg/test-error-impossible-must-tail-call.c [PR119783]David Malcolm1-2/+4
I added this test back in r7-934-g15c671a79ca66d, but it looks like r15-2125-g81824596361cf4 changed the error message. gcc/testsuite/ChangeLog: PR testsuite/119783 jit.dg/test-error-impossible-must-tail-call.c * jit.dg/test-error-impossible-must-tail-call.c (verify_code): Check that we get a suitable-looking error message, but don't try to specify exactly what the message is. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-12x86: Convert integer constant to mode of moveH.J. Lu1-0/+18
For (set (reg/v:DI 106 [ k ]) (const_int 3000000000 [0xb2d05e00])) ... (set (reg:V4SI 115 [ _13 ]) (vec_duplicate:V4SI (subreg:SI (reg/v:DI 106 [ k ]) 0))) ... (set (reg:V2SI 118 [ _9 ]) (vec_duplicate:V2SI (subreg:SI (reg/v:DI 106 [ k ]) 0))) we should generate (set (reg:SI 125) (const_int -1294967296 [0xffffffffb2d05e00])) (set (reg:V4SI 124) (vec_duplicate:V4SI (reg:VSI 125)) ... (set (reg:V4SI 115 [ _13 ]) (reg:V4SI 124) ... (set (reg:V2SI 118 [ _9 ]) (subreg:V2SI (reg:V4SI 124)) by converting integer constant to mode of move. gcc/ PR target/121497 * config/i386/i386-features.cc (ix86_broadcast_inner): Convert integer constant to mode of move gcc/testsuite/ PR target/121497 * gcc.target/i386/pr121497.c: New test. Co-authored-by: Liu, Hongtao <hongtao.liu@intel.com> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-13Daily bump.GCC Administrator1-0/+65