aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
AgeCommit message (Collapse)AuthorFilesLines
2025-08-07c++, c: Introduce -Wkeyword-macro warning/pedwarn - part of C++26 P2843R3 ↵Jakub Jelinek1-0/+9
[PR120778] The following patch introduces a -Wkeyword-macro warning that clang has since 2014 to implement part of C++26 P2843R3 Preprocessing is never undefined paper. The relevant change in the paper is moving [macro.names]/2 paragraph to https://eel.is/c++draft/cpp.replace.general#9 : "A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 4, or to the attribute-tokens described in [dcl.attr], except that the names likely and unlikely may be defined as function-like macros." Now, my understanding of the paper is that in [macro.names] and surrounding sections the word shall bears different meaning from [cpp.replace.general], where only the latter location implies ill-formed, diagnostic required. The warning in clang when introduced diagnosed all #define/#undef directives on keywords, but shortly after introduction has been changed not to diagnose #undef at all (with "#undef a keyword is generally harmless but used often in configuration scripts" message) and later on even the #define part tweaked - not warn about say #define inline (or const, extern, static), or #define keyword keyword or #define keyword __keyword or #define keyword __keyword__ Later on the warning has been moved to be only pedantic diagnostic unless requested by users. Clearly some code in the wild does e.g. #define private public and similar games, or e.g. Linux kernel (sure, C) does #define inline __inline__ __attribute__((__always_inline__)) etc. Now, I believe at least with the current C++26 wording such exceptions aren't allowed (unless it is changed to IFNDR). But given that this is just pedantic stuff, the following patch makes the warning off by default for C and C++ before C++26 and even for C++26 it enables it by default only if -pedantic/-pedantic-errors (in that case it pedwarns, otherwise it warns). And it diagnoses both #define and #undef without exceptions. From what I can see, all the current NODE_WARN cases are macros starting with __ with one exception (_Pragma). As the NODE_* flags seem to be a limited resource, I chose to just use NODE_WARN as well and differentiate on the node names (if they don't start with __ or _P, they are considered to be -Wkeyword-macro registered ones, otherwise old NODE_WARN cases, typically builtin macros or __STDC* macros). 2025-08-07 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 gcc/ * doc/invoke.texi (Wkeyword-macro): Document. gcc/c-family/ * c.opt (Wkeyword-macro): New option. * c.opt.urls: Regenerate. * c-common.h (cxx_dialect): Comment formatting fix. * c-opts.cc (c_common_post_options): Default to -Wkeyword-macro for C++26 if pedantic. gcc/c/ * c-decl.cc (c_init_decl_processing): Mark cpp nodes corresponding to keywords as NODE_WARN if warn_keyword_macro. gcc/cp/ * lex.cc (cxx_init): Mark cpp nodes corresponding to keywords, identifiers with special meaning and standard attribute identifiers as NODE_WARN if warn_keyword_macro. gcc/testsuite/ * gcc.dg/Wkeyword-macro-1.c: New test. * gcc.dg/Wkeyword-macro-2.c: New test. * gcc.dg/Wkeyword-macro-3.c: New test. * gcc.dg/Wkeyword-macro-4.c: New test. * gcc.dg/Wkeyword-macro-5.c: New test. * gcc.dg/Wkeyword-macro-6.c: New test. * gcc.dg/Wkeyword-macro-7.c: New test. * gcc.dg/Wkeyword-macro-8.c: New test. * gcc.dg/Wkeyword-macro-9.c: New test. * g++.dg/warn/Wkeyword-macro-1.C: New test. * g++.dg/warn/Wkeyword-macro-2.C: New test. * g++.dg/warn/Wkeyword-macro-3.C: New test. * g++.dg/warn/Wkeyword-macro-4.C: New test. * g++.dg/warn/Wkeyword-macro-5.C: New test. * g++.dg/warn/Wkeyword-macro-6.C: New test. * g++.dg/warn/Wkeyword-macro-7.C: New test. * g++.dg/warn/Wkeyword-macro-8.C: New test. * g++.dg/warn/Wkeyword-macro-9.C: New test. * g++.dg/warn/Wkeyword-macro-10.C: New test. * g++.dg/opt/pr82577.C: Don't #define register to nothing for C++17 and later. Instead define reg macro to nothing for C++17 and later or to register and use it instead of register. * g++.dg/modules/atom-preamble-3.C: Add -Wno-keyword-macro to dg-additional-options. * g++.dg/template/sfinae17.C (static_assert): Rename macro to ... (my_static_assert): ... this. (main): Use my_static_assert instead of static_assert. libcpp/ * include/cpplib.h (struct cpp_options): Add cpp_warn_keyword_macro. (enum cpp_warning_reason): Add CPP_W_KEYWORD_MACRO enumerator. (cpp_keyword_p): New inline function. * directives.cc (do_undef): Support -Wkeyword-macro diagnostics. * macro.cc (warn_of_redefinition): Ignore NODE_WARN flag on nodes registered for -Wkeyword-macro. (_cpp_create_definition): Support -Wkeyword-macro diagnostics. Formatting fixes.
2025-08-06install: Replace bzip2 by xzGerald Pfeifer1-1/+1
In addition to gzip format our snapshots and releases have been using xz instead of bzip2 for a while. gcc: PR target/69374 * doc/install.texi (Prerequisites): Replace bzip2 by xz.
2025-08-06c++: mangling cNTTP object w/ implicit non-trailing zeros [PR121231]Patrick Palka1-2/+3
Here the results of A::make(0, 0, 1), (0, 1, 0) and (1, 0, 0) are each represented as a single-element CONSTRUCTOR with CONSTRUCTOR_NO_CLEARING cleared, and when used as as a class NTTP argument we end up mangling them all as A{1}, i.e. eliding both the implicit initial and trailing zeros. Mangling them all the same seems clearly wrong since they're logically different values. It turns out the mangling also omits intermediate zeros, e.g. A::make(1, 0, 1) is mangled as A{1, 1}, the same as A::make(1, 1, 0). It seems we can't omit both trailing and non-trailing implicit zeros without introducing mangling ambiguities. This patch makes us include non-trailing zeros in these manglings (while continuing to omit trailing zeros). This also manifests as a wrong-code bug where the specializations table would conflate different specializations that are in terms of different class NTTP arguments, since the identity of such arguments is tied to their mangling. PR c++/121231 PR c++/119688 PR c++/94511 gcc/ChangeLog: * common.opt: Document additional ABI version 21 change. * doc/invoke.texi: Likewise. gcc/cp/ChangeLog: * mangle.cc (write_expression): Write out implicit non-trailing zeroes of a CONSTRUCTOR when the ABI version is at least 21. gcc/testsuite/ChangeLog: * g++.dg/abi/mangle82.C: New test. * g++.dg/cpp2a/nontype-class73.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-06RISC-V: Support -march=unsetKito Cheng1-1/+7
This patch introduces a new `-march=unset` option for RISC-V GCC that allows users to explicitly ignore previous `-march` options and derive the architecture string from the `-mcpu` option instead. This feature is particularly useful for build systems and toolchain configurations where you want to ensure the architecture is always derived from the CPU specification rather than relying on potentially conflicting `-march` options. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_expand_arch): Ignore `unset`. * config/riscv/riscv.h (OPTION_DEFAULT_SPECS): Handle `-march=unset`. (ARCH_UNSET_CLEANUP_SPECS): New. (DRIVER_SELF_SPECS): Handle -march=unset. * doc/invoke.texi (RISC-V Options): Update documentation for `-march=unset`. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-unset-1.c: New test. * gcc.target/riscv/arch-unset-2.c: New test. * gcc.target/riscv/arch-unset-3.c: New test. * gcc.target/riscv/arch-unset-4.c: New test. * gcc.target/riscv/arch-unset-5.c: New test.
2025-08-05doc: Mark up function name in installation docsGerald Pfeifer1-2/+2
gcc: PR target/69374 * doc/install.texi (Configuration): Mark up atexit as code.
2025-08-04defaults.h: Default MAX_FIXED_MODE_SIZE to MAX (BITS_PER_WORD * 2, 64)Hans-Peter Nilsson2-8/+8
The old GET_MODE_SIZE (DImode) (i.e. 64) made sense before 64-bitters. Now the default is just a trap: when using the default 64, things like TImode (128 bits) still mostly works, but general corner cases related to computing large-size objects numbers, like (1 << 64)/8 break, as exposed by gcc.dg/pr105094.c. So, keep the floor at 64 for 32-bitters and smaller targets, but for larger targets, make it 2 * BITS_PER_WORD. Also, express it more directly with focus on BITS_PER_WORD, not the size of a mode. Add "by GCC internally" in an attempt to tell that this is when gcc cooks something up, not when plain input uses a type with such a mode. * defaults.h (MAX_FIXED_MODE_SIZE): Default to 2 * BITS_PER_WORD for larger-than-32-bitters. * doc/tm.texi.in (MAX_FIXED_MODE_SIZE): Adjust accordingly. Tweak wording. * doc/tm.texi: Regenerate.
2025-08-04diagnostics: improve support for nesting levels [PR116253]David Malcolm2-0/+25
This patch adds support to sarif-replay for "nestingLevel" from "P3358R0 SARIF for Structured Diagnostics" https://wg21.link/P3358R0 Doing so revealed a bug where libgdiagnostics was always creating new location_t values (and thus also diagnostic_physical_location instances), rather than reusing existing location_t values, leading to excess source printing. The patch also fixes this bug, adding a new flag to libgdiagnostics for debugging physical locations, and exposing this in sarif-replay via a new "-fdebug-physical-locations" maintainer option. Finally, the patch adds test coverage for the HTML sink's output of nested diagnostics (both from a GCC plugin, and from sarif-replay). gcc/ChangeLog: PR diagnostics/116253 * diagnostics/context.cc (context::set_nesting_level): New. * diagnostics/context.h (context::set_nesting_level): New decl. * doc/libgdiagnostics/topics/compatibility.rst (LIBGDIAGNOSTICS_ABI_5): New. * doc/libgdiagnostics/topics/physical-locations.rst (diagnostic_manager_set_debug_physical_locations): New. * libgdiagnostics++.h (manager::set_debug_physical_locations): New. * libgdiagnostics-private.h (private_diagnostic_set_nesting_level): New decl. * libgdiagnostics.cc (diagnostic_manager::diagnostic_manager): Initialize m_debug_physical_locations. (diagnostic_manager::new_location_from_file_and_line): Add debug printing. (diagnostic_manager::new_location_from_file_line_column): Likewise. (diagnostic_manager::new_location_from_range): Likewise. (diagnostic_manager::set_debug_physical_locations): New. (diagnostic_manager::ensure_linemap_for_file_and_line): Avoid redundant calls to linemap_add. (diagnostic_manager::new_location): Add debug printing. (diagnostic_manager::m_debug_physical_locations): New field. (diagnostic::diagnostic): Initialize m_nesting_level. (diagnostic::get_nesting_level): New accessor. (diagnostic::set_nesting_level): New. (diagnostic::m_nesting_level): New field. (diagnostic_manager::emit_va): Set and reset the nesting level of the context from that of the diagnostic. (diagnostic_manager_set_debug_physical_locations): New. (private_diagnostic_set_nesting_level): New. * libgdiagnostics.h (diagnostic_manager_set_debug_physical_locations): New decl. * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_5): New. * libsarifreplay.cc (sarif_replayer::handle_result_obj): Support the "nestingLevel" property. * libsarifreplay.h (replay_options::m_debug_physical_locations): New field. * sarif-replay.cc: Add -fdebug-physical-locations. gcc/testsuite/ChangeLog: PR diagnostics/116253 * gcc.dg/plugin/diagnostic-test-nesting-html.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-html.py: New test script. * gcc.dg/plugin/plugin.exp: Add it. * libgdiagnostics.dg/test-multiple-lines.c: Update expected output to show fix-it hint. * sarif-replay.dg/2.1.0-valid/nested-diagnostics-1.sarif: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04invoke.texi: Update docs of -fdump-{rtl,tree}-<pass>-<options>Filip Kastl1-7/+10
This patch changes two things. Firstly, we document -fdump-rtl-<whatever>-graph and other such options under -fdump-tree. At least write a remark about this under -fdump-rtl. Secondly, the documentation incorrectly says that -fdump-tree-<whatever>-graph is not implemented. Change that. gcc/ChangeLog: * doc/invoke.texi: Add remark about -options being documented under -fdump-tree. Remove remark about -graph working only for RTL. Signed-off-by: Filip Kastl <fkastl@suse.cz>
2025-08-03doc: Drop note on 16-bit Windows supportGerald Pfeifer1-7/+0
gcc: PR target/69374 * doc/install.texi (Specific) <windows>: Drop note on 16-bit Windows support. Streamline note on 32-bit support.
2025-08-01doc: mdocml.bsd.lv is now mandoc.bsd.lvGerald Pfeifer1-1/+1
On the way switch from http to https. gcc: * doc/install.texi (Prerequisites): mdocml.bsd.lv is now mandoc.bsd.lv.
2025-07-31AVR: rtl-optimization/121340 - New mini-pass to undo superfluous moves from ↵Georg-Johann Lay1-1/+5
insn combine. Insn combine may come up with superfluous reg-reg moves, where the combine people say that these are no problem since reg-alloc is supposed to optimize them. The issue is that the lower-subreg pass sitting between combine and reg-alloc may split such moves, coming up with a zoo of subregs which are only handled poorly by the register allocator. This patch adds a new avr mini-pass that handles such cases. As an example, take int f_ffssi (long x) { return __builtin_ffsl (x); } where the two functions have the same interface, i.e. there are no extra moves required for the argument or for the return value. However, $ avr-gcc -S -Os -dp -mno-fuse-move ... f_ffssi: mov r20,r22 ; 29 [c=4 l=1] movqi_insn/0 mov r21,r23 ; 30 [c=4 l=1] movqi_insn/0 mov r22,r24 ; 31 [c=4 l=1] movqi_insn/0 mov r23,r25 ; 32 [c=4 l=1] movqi_insn/0 mov r25,r23 ; 33 [c=4 l=4] *movsi/0 mov r24,r22 mov r23,r21 mov r22,r20 rcall __ffssi2 ; 34 [c=16 l=1] *ffssihi2.libgcc ret ; 37 [c=0 l=1] return where all the moves add up to a no-op. The -mno-fuse-move option stops any attempts by the avr backend to clean up that mess. PR rtl-optimization/121340 gcc/ * config/avr/avr.opt (-mfuse-move2): New option. * config/avr/avr-passes.def (avr_pass_2moves): Insert after combine. * config/avr/avr-passes.cc (make_avr_pass_2moves): New function. (pass_data avr_pass_data_2moves): New static variable. (avr_pass_2moves): New rtl_opt_pass. * config/avr/avr-protos.h (make_avr_pass_2moves): New proto. * common/config/avr/avr-common.cc (default_options avr_option_optimization_table) <-mfuse-move2>: Set for -O1 and higher. * doc/invoke.texi (AVR Options) <-mfuse-move2>: Document.
2025-07-30vect: Add target hook to prefer gather/scatter instructionsAndrew Stubbs2-0/+11
For AMD GCN, the instructions available for loading/storing vectors are always scatter/gather operations (i.e. there are separate addresses for each vector lane), so the current heuristic to avoid gather/scatter operations with too many elements in get_group_load_store_type is counterproductive. Avoiding such operations in that function can subsequently lead to a missed vectorization opportunity whereby later analyses in the vectorizer try to use a very wide array type which is not available on this target, and thus it bails out. This patch adds a target hook to override the "single_element_p" heuristic in the function as a target hook, and activates it for GCN. This allows much better code to be generated for affected loops. Co-authored-by: Julian Brown <julian@codesourcery.com> gcc/ * doc/tm.texi.in (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Add documentation hook. * doc/tm.texi: Regenerate. * target.def (prefer_gather_scatter): Add target hook under vectorizer. * hooks.cc (hook_bool_mode_int_unsigned_false): New function. * hooks.h (hook_bool_mode_int_unsigned_false): New prototype. * tree-vect-stmts.cc (vect_use_strided_gather_scatters_p): Add parameters group_size and single_element_p, and rework to use targetm.vectorize.prefer_gather_scatter. (get_group_load_store_type): Move some of the condition into vect_use_strided_gather_scatters_p. * config/gcn/gcn.cc (gcn_prefer_gather_scatter): New function. (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Define hook.
2025-07-29RISC-V: Generate -mcpu and -mtune options from riscv-cores.def.Dongyan Chen3-20/+131
Automatically generate -mcpu and -mtune options in invoke.texi from the unified riscv-cores.def metadata, ensuring documentation stays in sync with definitions and reducing manual maintenance. gcc/ChangeLog: * Makefile.in: Add riscv-mcpu.texi and riscv-mtune.texi to the list of files to be processed by the Texinfo generator. * config/riscv/t-riscv: Add rule for generating riscv-mcpu.texi and riscv-mtune.texi. * doc/invoke.texi: Replace hand‑written extension table with `@include riscv-mcpu.texi` and `@include riscv-mtune.texi` to pull in auto‑generated entries. * config/riscv/gen-riscv-mcpu-texi.cc: New file. * config/riscv/gen-riscv-mtune-texi.cc: New file. * doc/riscv-mcpu.texi: New file. * doc/riscv-mtune.texi: New file.
2025-07-25diagnostics: introduce namespace diagnostics::pathsDavid Malcolm1-2/+2
Move more diagnostic-specific code from gcc/ to gcc/diagnostics/ No functional change intended. contrib/ChangeLog: * filter-clang-warnings.py: Update for move of diagnostic-path-output.cc to diagnostics/paths-output.cc. gcc/ChangeLog: * Makefile.in (OBJS): Replace lazy-diagnostic-path.o with diagnostics/lazy-paths.o. (OBJS-libcommon): Replace diagnostic-path.o with diagnostics/paths.o, diagnostic-path-output.o with diagnostics/paths-output.o, and selftest-diagnostic-path.o with diagnostics/selftest-paths.o. (EXTRA_BACKEND_OBJS): Replace lazy-diagnostic-path.o with diagnostics/lazy-paths.o. * diagnostic-format-html.cc: Update #include for "diagnostic-path.h" moving to "diagnostics/paths.h", diagnostic_thread_id_t to diagnostics::paths::thread_id_t, diagnostic_event_id_t to diagnostics::paths::event_id_t, diagnostic_path to diagnostics::paths::path, and diagnostic_thread to diagnostics::paths::thread, and diagnostic_event to diagnostics::paths::event. * diagnostic-format-html.h: Likewise. * diagnostic-format-sarif.cc: Likewise. Update PROPERTY_PREFIX for threadFlowLocations from "gcc/diagnostic_event/" to "gcc/diagnostics/paths/event/". * diagnostic-format-text.cc: Likewise. * diagnostic-format-text.h: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-event-id.h: Move to... * diagnostics/event-id.h: ...here, updating header guard. (diagnostics:paths:event_id_t): New typedef. (diagnostic_thread_id_t): Replace with... (diagnostics:paths:thread_id_t): New typedef. * lazy-diagnostic-path.cc: Move to... * diagnostics/lazy-paths.cc: ...here. Update for above changes, lazy_diagnostic_path becomes diagnostics::paths::lazy_path. (lazy_diagnostic_path_cc_tests): Rename to... (diagnostics_lazy_paths_cc_tests): ...this. * lazy-diagnostic-path.h: Move to... * diagnostics/lazy-paths.h: ...here, updating header guard. Update for above changes. * diagnostic-path-output.cc: Move to... * diagnostics/paths-output.cc: ...here. Update for above changes. (diagnostic_path_output_cc_tests): Rename to... (diagnostics_paths_output_cc_tests): ...this. * diagnostic-path.cc: Move to... * diagnostics/paths.cc: ...here. Update for above changes. * diagnostic-path.h: Move to... * diagnostics/paths.h: ...here, updating header guard. Update #include for moving "diagnostic-event-id.h" to "diagnostics/event-id.h". (class diagnostic_event): Convert to... (class diagnostics::paths::event): ...this. (class diagnostic_thread): Convert to... (class diagnostics::paths::thread): ...this. (class diagnostic_path): Convert to... (class diagnostics::paths::path): ...this. * diagnostic-show-locus.cc: Update for above changes. * doc/analyzer.texi: Likewise. * selftest-diagnostic-path.cc: Move to... * diagnostics/selftest-paths.cc: ...here. Update for above changes, and for "selftest-diagnostic-path.h" moving to "diagnostics/selftest-paths.h". * selftest-diagnostic-path.h: Move to... * diagnostics/selftest-paths.h: ...here, updating header guard. Update for above changes. * libgdiagnostics.cc: Update for above changes. * libsarifreplay.cc: Update property prefix for threadFlowLocations from "gcc/diagnostic_event/" to "gcc/diagnostics/paths/event/". * pretty-print-format-impl.h: Update for above changes. * pretty-print.cc: Likewise. * selftest-run-tests.cc (selftest::run_tests): Update for renaming of lazy_diagnostic_path_cc_tests to diagnostics_lazy_paths_cc_tests, and of diagnostic_path_output_cc_tests to diagnostics_paths_output_cc_tests. * selftest.h (lazy_diagnostic_path_cc_tests): Replace decl with... (diagnostics_lazy_paths_cc_tests): ...this. (diagnostic_path_output_cc_tests): Replace decl with... (diagnostics_paths_output_cc_tests): ...this. * simple-diagnostic-path.cc: Clarify that this relates to "tree" and thus shouldn't be in "diagnostics". Update for above changes. * simple-diagnostic-path.h: Likewise. gcc/analyzer/ChangeLog: * access-diagram.cc: Update for changes to diagnostic paths: "diagnostic-path.h" moving to "diagnostics/paths.h", "diagnostic-event-id.h" moving to "diagnostics/event-id.h", diagnostic_event_id_t to diagnostics::paths::event_id_t, diagnostic_path to diagnostics::paths::path, and diagnostic_event to diagnostics::paths::event. * access-diagram.h: Likewise. * analyzer.cc: Likewise. * bounds-checking.cc: Likewise. * call-info.cc: Likewise. * checker-event.cc: Likewise. * checker-event.h: Likewise. * checker-path.cc: Likewise. * checker-path.h: Likewise. * common.h: Likewise. * diagnostic-manager.cc: Likewise. * pending-diagnostic.cc: Likewise. * pending-diagnostic.h: Likewise. * program-point.cc: Likewise. * program-state.cc: Likewise. * region-model.cc: Likewise. * sm-fd.cc: Likewise. * sm-file.cc: Likewise. * sm-malloc.cc: Likewise. * sm-pattern-test.cc: Likewise. * sm-sensitive.cc: Likewise. * sm-signal.cc: Likewise. * sm-taint.cc: Likewise. * varargs.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_gil_plugin.cc: Update #include for "diagnostic-path.h" moving to "diagnostics/paths.h", diagnostic_thread_id_t to diagnostics::paths::thread_id_t, diagnostic_event_id_t to diagnostics::paths::event_id_t, diagnostic_path to diagnostics::paths::path, and diagnostic_thread to diagnostics::paths::thread, and diagnostic_event to diagnostics::paths::event. * gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Likewise. * lib/sarif.py (get_state_graph): Update property prefix for threadFlowLocations from "gcc/diagnostic_event/" to "gcc/diagnostics/paths/event/". * gcc.dg/sarif-output/include-chain-2.h: Update comment. libcpp/ChangeLog: * include/rich-location.h: Replace diagnostic_path with diagnostics::paths::path. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25RISC-V: Remove user-level interruptsChristoph Müllner1-2/+2
There was once a RISC-V extension draft ("N"), which introduced user-level interrupts. However, it was never ratified and the specification draft has been removed from the RISC-V ISA manual in commit `b6cade07034` with the comment "it'll likely need to be redesigned". Support for a N extension never made it to GCC, but we support fuction attributes for user-level interrupt handlers that use the URET instruction. The "user" interrupt attribute was documented in the RISC-V C API, but has been removed in PR #106 in May 2025 (driven by LLVM devs/ maintainers and ack'ed by at least one GCC maintainer). Let's drop URET support from GCC as well. gcc/ChangeLog: * config/riscv/riscv.cc (enum riscv_privilege_levels): Remove USER_MODE. (riscv_handle_type_attribute): Remove "user" interrupts. (riscv_expand_epilogue): Likewise. (riscv_get_interrupt_type): Likewise. * config/riscv/riscv.md (riscv_uret): Remove URET pattern. * doc/extend.texi: Remove documentation of user interrupts. gcc/testsuite/ChangeLog: * gcc.target/riscv/interrupt-conflict-mode.c: Remove "user" interrupts. * gcc.target/riscv/xtheadint-push-pop.c: Likewise. * gcc.target/riscv/interrupt-umode.c: Removed. Reported-by: Sam Elliott <quic_aelliott@quicinc.com> Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2025-07-25RISC-V: Add support for resumable non-maskable interrupt (RNMI) handlersChristoph Müllner1-2/+2
The Smrnmi extension introduces the nmret instruction to return from RNMI handlers. We already have basic Smrnmi support. This patch introduces support for the nmret instruction and the ability to set the function attribute `__attribute__ ((interrupt ("rnmi")))` to let the compiler generate RNMI handlers. The attribute name is proposed in a PR for the RISC C API and approved by LLVM maintainers: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/116 gcc/ChangeLog: * config/riscv/riscv.cc (enum riscv_privilege_levels): Add RNMI_MODE. (riscv_handle_type_attribute): Handle 'rnmi' interrupt attribute. (riscv_expand_epilogue): Generate nmret for RNMI handlers. (riscv_get_interrupt_type): Handle 'rnmi' interrupt attribute. * config/riscv/riscv.md (riscv_rnmi): Add nmret INSN. * doc/extend.texi: Add documentation for 'rnmi' interrupt attribute. gcc/testsuite/ChangeLog: * gcc.target/riscv/interrupt-rnmi.c: New test. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2025-07-24Fix minor typo in #ifdef docuementationAndrew Pinski1-1/+1
As reported in https://gcc.gnu.org/pipermail/gcc/2025-July/246417.html, This fixes the minor typo under the #ifdef documentation about adding MACRO after the #endif and the MACRO matching of the #ifdef. It had `#ifndef` in it, rather than `#ifdef`. Pushed as obvious. gcc/ChangeLog: * doc/cpp.texi (#ifdef): Correct typo. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-24vect: Add is_gather_scatter argument to misalignment hook.Robin Dapp1-3/+5
This patch adds an is_gather_scatter argument to the support_vector_misalignment hook. All targets but riscv do not care about alignment for gather/scatter so return true for is_gather_scatter. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_builtin_support_vector_misalignment): Return true for gather/scatter. * config/arm/arm.cc (arm_builtin_support_vector_misalignment): Ditto. * config/epiphany/epiphany.cc (epiphany_support_vector_misalignment): Ditto. * config/gcn/gcn.cc (gcn_vectorize_support_vector_misalignment): Ditto. * config/loongarch/loongarch.cc (loongarch_builtin_support_vector_misalignment): Ditto. * config/riscv/riscv.cc (riscv_support_vector_misalignment): Add gather/scatter argument. * config/rs6000/rs6000.cc (rs6000_builtin_support_vector_misalignment): Return true for gather/scatter. * config/s390/s390.cc (s390_support_vector_misalignment): Ditto. * doc/tm.texi: Add argument. * target.def: Ditto. * targhooks.cc (default_builtin_support_vector_misalignment): Ditto. * targhooks.h (default_builtin_support_vector_misalignment): Ditto. * tree-vect-data-refs.cc (vect_supportable_dr_alignment): Ditto.
2025-07-21Hard register constraintsStefan Schulze Frielinghaus2-0/+168
Implement hard register constraints of the form {regname} where regname must be a valid register name for the target. Such constraints may be used in asm statements as a replacement for register asm and in machine descriptions. A more verbose description is given in extend.texi. It is expected and desired that optimizations coalesce multiple pseudos into one whenever possible. However, in case of hard register constraints we may have to undo this and introduce copies since otherwise we would constraint a single pseudo to multiple hard registers. This is done prior RA during asmcons in match_asm_constraints_2(). While IRA tries to reduce live ranges, it also replaces some register-register moves. That in turn might undo those copies of a pseudo which we just introduced during asmcons. Thus, check in decrease_live_ranges_number() via valid_replacement_for_asm_input_p() whether it is valid to perform a replacement. The reminder of the patch mostly deals with parsing and decoding hard register constraints. The actual work is done by LRA in process_alt_operands() where a register filter, according to the constraint, is installed. For the sake of "reviewability" and in order to show the beauty of LRA, error handling (which gets pretty involved) is spread out into a subsequent patch. Limitation ---------- Currently, a fixed register cannot be used as hard register constraint. For example, loading the stack pointer on x86_64 via void * foo (void) { void *y; __asm__ ("" : "={rsp}" (y)); return y; } leads to an error. Asm Adjust Hook --------------- The following targets implement TARGET_MD_ASM_ADJUST: - aarch64 - arm - avr - cris - i386 - mn10300 - nds32 - pdp11 - rs6000 - s390 - vax Most of them only add the CC register to the list of clobbered register. However, cris, i386, and s390 need some minor adjustment. gcc/ChangeLog: * config/cris/cris.cc (cris_md_asm_adjust): Deal with hard register constraint. * config/i386/i386.cc (map_egpr_constraints): Ditto. * config/s390/s390.cc (f_constraint_p): Ditto. * doc/extend.texi: Document hard register constraints. * doc/md.texi: Ditto. * function.cc (match_asm_constraints_2): Have a unique pseudo for each operand with a hard register constraint. (pass_match_asm_constraints::execute): Calling into new helper match_asm_constraints_2(). * genoutput.cc (mdep_constraint_len): Return the length of a hard register constraint. * genpreds.cc (write_insn_constraint_len): Support hard register constraints for insn_constraint_len(). * ira.cc (valid_replacement_for_asm_input_p_1): New helper. (valid_replacement_for_asm_input_p): New helper. (decrease_live_ranges_number): Similar to match_asm_constraints_2() ensure that each operand has a unique pseudo if constrained by a hard register. * lra-constraints.cc (process_alt_operands): Install hard register filter according to constraint. * recog.cc (asm_operand_ok): Accept register type for hard register constrained asm operands. (constrain_operands): Validate hard register constraints. * stmt.cc (decode_hard_reg_constraint): Parse a hard register constraint into the corresponding register number or bail out. (parse_output_constraint): Parse hard register constraint and set *ALLOWS_REG. (parse_input_constraint): Ditto. * stmt.h (decode_hard_reg_constraint): Declaration of new function. gcc/testsuite/ChangeLog: * gcc.dg/asm-hard-reg-1.c: New test. * gcc.dg/asm-hard-reg-2.c: New test. * gcc.dg/asm-hard-reg-3.c: New test. * gcc.dg/asm-hard-reg-4.c: New test. * gcc.dg/asm-hard-reg-5.c: New test. * gcc.dg/asm-hard-reg-6.c: New test. * gcc.dg/asm-hard-reg-7.c: New test. * gcc.dg/asm-hard-reg-8.c: New test. * gcc.target/aarch64/asm-hard-reg-1.c: New test. * gcc.target/i386/asm-hard-reg-1.c: New test. * gcc.target/i386/asm-hard-reg-2.c: New test. * gcc.target/s390/asm-hard-reg-1.c: New test. * gcc.target/s390/asm-hard-reg-2.c: New test. * gcc.target/s390/asm-hard-reg-3.c: New test. * gcc.target/s390/asm-hard-reg-4.c: New test. * gcc.target/s390/asm-hard-reg-5.c: New test. * gcc.target/s390/asm-hard-reg-6.c: New test. * gcc.target/s390/asm-hard-reg-longdouble.h: New test.
2025-07-17aarch64: Adapt unwinder to linux's SME signal behaviourRichard Sandiford1-0/+3
SME uses a lazy save system to manage ZA. The idea is that, if a function with ZA state wants to call a "normal" function, it can leave its state in ZA and instead set up a lazy save buffer. If, unexpectedly, that normal function contains a nested use of ZA, that nested use of ZA must commit the lazy save first. This lazy save system uses a special system register called TPIDR2_EL0. See: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#66the-za-lazy-saving-scheme for details. The ABI specifies that, on entry to an exception handler, the following things must be true: * PSTATE.SM must be 0 (the processor must be in non-streaming mode) * PSTATE.ZA must be 0 (ZA must be off) * TPIDR2_EL0 must be 0 (there must be no uncommitted lazy save) This is normally done by making _Unwind_RaiseException & friends commit any lazy save before they unwind. This also has the side effect of ensuring that TPIDR2_EL0 is never left pointing to a lazy save buffer that has been unwound. However, things get more complicated with signals. If: (a) a signal is raised while ZA is dormant (that is, while there is an uncommitted lazy save); (b) the signal handler throws an exception; and (c) that exception is caught outside the signal handler something must ensure that the lazy save from (a) is committed. This would be simple if the signal handler was entered with ZA and TPIDR2_EL0 intact. However, for various good reasons that are out of scope here, this is not done. Instead, Linux now clears both TPIDR2_EL0 and PSTATE.ZA before entering a signal handler, see: https://lore.kernel.org/all/20250417190113.3778111-1-mark.rutland@arm.com/ for details. Therefore, it is the unwinder that must simulate a commit of the lazy save from (a). It can do this by reading the previous values of TPIDR2_EL0 and ZA from the sigcontext. The SME-related sigcontext structures were only added to linux's asm/sigcontext.h relatively recently and we can't rely on GCC being built against such recent kernel header files. The patch therefore uses defines relevant macros if they are not defined and provide types that comply with ABI layout of the corresponding linux types. The patch includes some ugly casting in an attempt to support big-endian ILP32, even though SME on big-endian ILP32 linux should never be a thing. We can remove it if we also remove ILP32 support from GCC. Co-authored-by: Yury Khrustalev <yury.khrustalev@arm.com> Reviewed-by: Tamar Christina <tamar.christina@arm.com> gcc/ * doc/sourcebuild.texi (aarch64_sme_hw): Document. gcc/testsuite/ * lib/target-supports.exp (add_options_for_aarch64_sme) (check_effective_target_aarch64_sme_hw): New procedures. * g++.target/aarch64/sme/sme_throw_1.C: New test. * g++.target/aarch64/sme/sme_throw_2.C: Likewise. libgcc/ * config/aarch64/linux-unwind.h (aarch64_fallback_frame_state): If a signal was raised while there was an uncommitted lazy save, commit the save as part of the unwind process.
2025-07-15libgdiagnostics: add diagnostic_message_buffer [PR120792]David Malcolm10-5/+498
This patch extends libgdiagnostics to provide a way to capture the pp tokens making up a message string, so that SARIF and HTML sinks can retain information such as event IDs and URLs. As well as richer output, this improves the round-tripping of such information through sarif-replay. This also allows diagnostic messages to be built up in pieces, with a drop-in replacement for fprintf, which I've found useful when attempting to port "ld" to use libgdiagnostics. gcc/ChangeLog: PR sarif-replay/120792 * auto-obstack.h: New file, based on material taken from pretty-print.cc. * diagnostic-digraphs.h (diagnostics::digraphs::digraph::set_description): New. (diagnostics::digraphs::node::set_label): New. * doc/libgdiagnostics/topics/compatibility.rst: Add LIBGDIAGNOSTICS_ABI_4. * doc/libgdiagnostics/topics/diagnostics.rst (diagnostic_finish_via_msg_buf): Document new entrypoint. * doc/libgdiagnostics/topics/execution-paths.rst (diagnostic_execution_path_add_event_via_msg_buf): Document new entrypoint. * doc/libgdiagnostics/topics/index.rst: Add message-buffers.rst. * doc/libgdiagnostics/topics/message-buffers.rst: New file. * doc/libgdiagnostics/topics/message-formatting.rst: Add note about message buffers. * doc/libgdiagnostics/topics/physical-locations.rst (diagnostic_add_location_with_label_via_msg_buf): Add. * doc/libgdiagnostics/tutorial/07-execution-paths.rst: Link to next section. * doc/libgdiagnostics/tutorial/08-message-buffers.rst: New file. * doc/libgdiagnostics/tutorial/index.rst: Add 08-message-buffers.rst. * libgdiagnostics++.h (libgdiagnostics::message_buffer): New class. (libgdiagnostics::execution_path::add_event_via_msg_buf): New. (libgdiagnostics::diagnostic::add_location_with_label): New. (libgdiagnostics::diagnostic::finish_via_msg_buf): New. (libgdiagnostics::graph::set_description): New overload. (libgdiagnostics::graph::add_edge): New overload. (libgdiagnostics::node::set_label): New overload. * libgdiagnostics-private.h (private_diagnostic_execution_path_add_event_2): Drop decl. (private_diagnostic_execution_path_add_event_3): New decl. * libgdiagnostics.cc: Include "pretty-print-format-impl.h", "pretty-print-markup.h", and "auto-obstack.h". (class copying_token_printer): New. (struct diagnostic_message_buffer): New. (class pp_element_message_buffer): New. (libgdiagnostics_path_event::libgdiagnostics_path_event): Replace params "gmsgid" and "args" with "msg_buf". (libgdiagnostics_path_event::print_desc): Reimplement using pp_element_message_buffer to replay m_msg_buf into "pp". (libgdiagnostics_path_event::m_desc_uncolored): Drop field. (libgdiagnostics_path_event::m_desc_colored): Drop field. (libgdiagnostics_path_event::msg_buf): New field. (diagnostic_execution_path::add_event_va): Reimplement. (diagnostic_execution_path::add_event_via_msg_buf): New. (diagnostic::add_location_with_label): New overload, using msg_buf. (diagnostic_manager::emit): Reimplement with... (diagnostic_manager::emit_va): ...this. (diagnostic_manager::emit_msg_buf): New. (FAIL_IF_NULL): Rename "p" to "ptr_arg". (diagnostic_finish_va): Update to use diagnostic_manager::emit_va. (diagnostic_graph::add_node_with_id): Rename "id" to "node_id". (diagnostic_graph_add_node): Likewise. (diagnostic_graph_add_edge): Rename "id" to "edge_id". (diagnostic_graph_get_node_by_id): Rename "id" to "node_id". (diagnostic_graph_get_edge_by_id): Rename "id" to "edge_id". (private_diagnostic_execution_path_add_event_2): Delete. (diagnostic_message_buffer_new): New public entrypoint. (diagnostic_message_buffer_release): Likewise. (diagnostic_message_buffer_append_str): Likewise. (diagnostic_message_buffer_append_text): Likewise. (diagnostic_message_buffer_append_byte): Likewise. (diagnostic_message_buffer_append_printf): Likewise. (diagnostic_message_buffer_append_event_id): Likewise. (diagnostic_message_buffer_begin_url): Likewise. (diagnostic_message_buffer_end_url): Likewise. (diagnostic_message_buffer_begin_quote): Likewise. (diagnostic_message_buffer_end_quote): Likewise. (diagnostic_message_buffer_begin_color): Likewise. (diagnostic_message_buffer_end_color): Likewise. (diagnostic_message_buffer_dump): Likewise. (diagnostic_finish_via_msg_buf): Likewise. (diagnostic_add_location_with_label_via_msg_buf): Likewise. (diagnostic_execution_path_add_event_via_msg_buf): Likewise. (diagnostic_graph_set_description_via_msg_buf): Likewise. (diagnostic_graph_add_edge_via_msg_buf): Likewise. (diagnostic_node_set_label_via_msg_buf): Likewise. (private_diagnostic_execution_path_add_event_3): New private entrypoint. * libgdiagnostics.h (LIBGDIAGNOSTICS_PARAM_FORMAT_STRING): New macro. (LIBGDIAGNOSTICS_PARAM_PRINTF_FORMAT_STRING): New macro. (diagnostic_message_buffer): New typedef. (LIBDIAGNOSTICS_HAVE_diagnostic_message_buffer): New define. (diagnostic_message_buffer_new): New decl. (diagnostic_message_buffer_release): New decl. (diagnostic_message_buffer_append_str): New decl. (diagnostic_message_buffer_append_text): New decl. (diagnostic_message_buffer_append_byte): New decl. (diagnostic_message_buffer_append_printf): New decl. (diagnostic_message_buffer_append_event_id): New decl. (diagnostic_message_buffer_begin_url): New decl. (diagnostic_message_buffer_end_url): New decl. (diagnostic_message_buffer_begin_quote): New decl. (diagnostic_message_buffer_end_quote): New decl. (diagnostic_message_buffer_begin_color): New decl. (diagnostic_message_buffer_end_color): New decl. (diagnostic_message_buffer_dump): New decl. (diagnostic_finish_via_msg_buf): New decl. (diagnostic_add_location_with_label_via_msg_buf): New decl. (diagnostic_execution_path_add_event_via_msg_buf): New decl. (diagnostic_graph_set_description_via_msg_buf): New decl. (diagnostic_graph_add_edge_via_msg_buf): New decl. (diagnostic_node_set_label_via_msg_buf): New decl. * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_3): Drop private_diagnostic_execution_path_add_event_2. (LIBGDIAGNOSTICS_ABI_4): New. * libsarifreplay.cc (class annotation): Use libgdiagnostics::message_buffer rather than label_text. (add_any_annotations): Likewise. (sarif_replayer::handle_result_obj): Likewise. (make_plain_text_within_result_message): Likewise. (handle_thread_flow_location_object): Likewise. (handle_location_object): Likewise. (sarif_replayer::handle_graph_object): Likewise. (sarif_replayer::handle_node_object): Likewise. (sarif_replayer::handle_edge_object): Likewise. * pretty-print-format-impl.h (pp_token_list::push_back_byte): New decl. * pretty-print-markup.h (pp_markup::context::begin_url): New decl. (pp_markup::context::end_url): New decl. (pp_markup::context::add_event_id): New decl. * pretty-print.cc: Include "auto-obstack.h". (pp_token_list::push_back_byte): New. (struct auto_obstack): Move to auto-obstack.h. (default_token_printer): Make non-static. (pp_markup::context::begin_url): New. (pp_markup::context::end_url): New. (pp_markup::context::add_event_id): New. gcc/testsuite/ChangeLog: PR sarif-replay/120792 * libgdiagnostics.dg/sarif.py: Delete duplicate script. * libgdiagnostics.dg/test-message-buffer-c.py: New test script. * libgdiagnostics.dg/test-message-buffer.c: New test. * libgdiagnostics.dg/test-warning-with-path-c.py: Update expected output to reflect that SARIF for event messages now contains JSON pointers when referring to other events by ID. * sarif-replay.dg/2.1.0-valid/3.11.6-embedded-links.sarif: Add HTML and SARIF output, and call out to Python scripts to verify the output. Add example of a result with a link in its message. * sarif-replay.dg/2.1.0-valid/embedded-links-check-html.py: New test script. * sarif-replay.dg/2.1.0-valid/embedded-links-check-sarif-roundtrip.py: New test script. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-15[PATCH v5] RISC-V: Mips P8700 Conditional Move Support.Umesh Kalappa1-0/+4
Updated the test for rv32 accordingly and no regress found for runs like "runtest --tool gcc --target_board='riscv-sim/-march=rv32gc_zba_zbb_zbc_zbs/-mabi=ilp32d/-mcmodel=medlow' riscv.exp" and "runtest --tool gcc --target_board='riscv-sim/-march=rv64gc_zba_zbb_zbc_zbs/-mabi=lp64d/-mcmodel=medlow' riscv.exp" lint warnings can be ignored for riscv-cores.def and riscv-ext-mips.def gcc/ChangeLog: * config/riscv/riscv-cores.def (RISCV_CORE): Updated the supported march. * config/riscv/riscv-ext-mips.def (DEFINE_RISCV_EXT): New file added for mips conditional mov extension. * config/riscv/riscv-ext.def: Likewise. * config/riscv/t-riscv: Generates riscv-ext.opt * config/riscv/riscv-ext.opt: Generated file. * config/riscv/riscv.cc (riscv_expand_conditional_move): Updated for mips cmov and outlined some code that handle arch cond move. * config/riscv/riscv.md (mov<mode>cc): updated expand for MIPS CCMOV. * config/riscv/mips-insn.md: New file for mips-p8700 ccmov insn. * doc/riscv-ext.texi: Updated for mips cmov. gcc/testsuite/ChangeLog: * gcc.target/riscv/mipscondmov.c: Test file for mips.ccmov insn.
2025-07-15c, c++: Extend -Wunused-but-set-* warnings [PR44677]Jakub Jelinek1-6/+69
The -Wunused-but-set-* warnings work by using 2 bits on VAR_DECLs & PARM_DECLs, TREE_USED and DECL_READ_P. If neither is set, we typically emit -Wunused-variable or -Wunused-parameter warning, that is for variables which are just declared (including initializer) and completely unused. If TREE_USED is set and DECL_READ_P is unset, -Wunused-but-set-* warnings are emitted, i.e. for variables which can appear on the lhs of an assignment expression but aren't actually used elsewhere. The DECL_READ_P marking is done through mark_exp_read called from lots of places (e.g. lvalue to rvalue conversions etc.). LLVM has an extension on top of that in that it doesn't count pre/post inc/decrements as use (i.e. DECL_READ_P for GCC). The following patch does that too, though because we had the current behavior for 11+ years already and lot of people is -Wunused-but-set-* warning free in the current GCC behavior and not in the clang one (including GCC sources), it allows users to choose. Furthermore, it implements another level, where also var @= expr uses of var (except when it is also used in expr) aren't counted as DECL_READ_P. I think it would be nice to also handle var = var @ expr or var = expr @ var but unfortunately mark_exp_read is then done in both FEs during parsing of var @ expr or expr @ var and the code doesn't know it is rhs of an assignment with var as lhs. The patch works mostly by checking if DECL_READ_P is clear at some point and then clearing it again after some operation which might have set it. -Wunused or -Wall or -Wunused -Wextra or -Wall -Wextra turn on the 3 level of the new warning (i.e. the one which ignores also var++, ++var etc. as well as var @= expr), so does -Wunused-but-set-{variable,parameter}, but users can use explicit -Wunused-but-set-{variable,parameter}={1,2} to select a different level. 2025-07-15 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR c/44677 gcc/ * common.opt (Wunused-but-set-parameter=, Wunused-but-set-variable=): New options. (Wunused-but-set-parameter, Wunused-but-set-variable): Turn into aliases. * common.opt.urls: Regenerate. * diagnostic-spec.cc (nowarn_spec_t::nowarn_spec_t): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable and OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * gimple-ssa-store-merging.cc (find_bswap_or_nop_1): Remove unused but set variable tmp. * ipa-strub.cc (pass_ipa_strub::execute): Cast named_args to (void) if ATTR_FNSPEC_DECONST_WATERMARK is not defined. * doc/invoke.texi (Wunused-but-set-parameter=, Wunused-but-set-variable=): Document new options. (Wunused-but-set-parameter, Wunused-but-set-variable): Adjust documentation now that they are just aliases. gcc/c-family/ * c-opts.cc (c_common_post_options): Change warn_unused_but_set_parameter and warn_unused_but_set_variable from 1 to 3 if they were set only implicitly. * c-attribs.cc (build_attr_access_from_parms): Remove unused but set variable nelts. gcc/c/ * c-parser.cc (c_parser_unary_expression): Clear DECL_READ_P after default_function_array_read_conversion for -Wunused-but-set-{parameter,variable}={2,3} on PRE{IN,DE}CREMENT_EXPR argument. (c_parser_postfix_expression_after_primary): Similarly for POST{IN,DE}CREMENT_EXPR. * c-decl.cc (pop_scope): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable. (finish_function): Use OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * c-typeck.cc (mark_exp_read): Handle {PRE,POST}{IN,DE}CREMENT_EXPR and don't handle it when cast to void. (build_modify_expr): Clear DECL_READ_P after build_binary_op for -Wunused-but-set-{parameter,variable}=3. gcc/cp/ * cp-gimplify.cc (cp_fold): Clear DECL_READ_P on lhs of MODIFY_EXPR after cp_fold_rvalue if it wasn't set before. * decl.cc (poplevel): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable. (finish_function): Use OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * expr.cc (mark_use): Clear read_p for {PRE,POST}{IN,DE}CREMENT_EXPR cast to void on {VAR,PARM}_DECL for -Wunused-but-set-{parameter,variable}={2,3}. (mark_exp_read): Handle {PRE,POST}{IN,DE}CREMENT_EXPR and don't handle it when cast to void. * module.cc (trees_in::fn_parms_fini): Remove unused but set variable ix. * semantics.cc (finish_unary_op_expr): Return early for PRE{IN,DE}CREMENT_EXPR. * typeck.cc (cp_build_unary_op): Clear DECL_READ_P after mark_lvalue_use for -Wunused-but-set-{parameter,variable}={2,3} on PRE{IN,DE}CREMENT_EXPR argument. (cp_build_modify_expr): Clear DECL_READ_P after cp_build_binary_op for -Wunused-but-set-{parameter,variable}=3. gcc/go/ * gofrontend/gogo.cc (Function::export_func_with_type): Remove unused but set variable i. gcc/cobol/ * gcobolspec.cc (lang_specific_driver): Remove unused but set variable n_cobol_files. gcc/testsuite/ * c-c++-common/Wunused-parm-1.c: New test. * c-c++-common/Wunused-parm-2.c: New test. * c-c++-common/Wunused-parm-3.c: New test. * c-c++-common/Wunused-parm-4.c: New test. * c-c++-common/Wunused-parm-5.c: New test. * c-c++-common/Wunused-parm-6.c: New test. * c-c++-common/Wunused-var-7.c (bar, baz): Expect warning on a. * c-c++-common/Wunused-var-19.c: New test. * c-c++-common/Wunused-var-20.c: New test. * c-c++-common/Wunused-var-21.c: New test. * c-c++-common/Wunused-var-22.c: New test. * c-c++-common/Wunused-var-23.c: New test. * c-c++-common/Wunused-var-24.c: New test. * g++.dg/cpp26/name-independent-decl1.C (foo): Expect one set but not used warning. * g++.dg/warn/Wunused-parm-12.C: New test. * g++.dg/warn/Wunused-parm-13.C: New test. * g++.dg/warn/Wunused-var-2.C (f2): Expect set but not used warning on parameter x and variable a. * g++.dg/warn/Wunused-var-40.C: New test. * g++.dg/warn/Wunused-var-41.C: New test. * gcc.dg/memchr-3.c (test_find): Change return type from void to int, and add return n; statement. * gcc.dg/unused-9.c (g): Move dg-bogus to the correct line and expect a warning on i.
2025-07-14x86-64: Add --enable-x86-64-mfentryH.J. Lu1-0/+11
When profiling is enabled with shrink wrapping, the mcount call may not be placed at the function entry after pushq %rbp movq %rsp,%rbp As the result, the profile data may be skewed which makes PGO less effective. Add --enable-x86-64-mfentry to enable -mfentry by default to use __fentry__, added to glibc in 2010 by: commit d22e4cc9397ed41534c9422d0b0ffef8c77bfa53 Author: Andi Kleen <ak@linux.intel.com> Date: Sat Aug 7 21:24:05 2010 -0700 x86: Add support for frame pointer less mcount instead of mcount, which is placed before the prologue so that -pg can be used with -fshrink-wrap-separate enabled at -O1. This option is 64-bit only because __fentry__ doesn't support PIC in 32-bit mode. The default it to enable -mfentry when targeting glibc. Also warn -pg without -mfentry with shrink wrapping enabled. The warning is disable for PIC in 32-bit mode. gcc/ PR target/120881 * config.in: Regenerated. * configure: Likewise. * configure.ac: Add --enable-x86-64-mfentry. * config/i386/i386-options.cc (ix86_option_override_internal): Enable __fentry__ in 64-bit mode if ENABLE_X86_64_MFENTRY is set to 1. Warn -pg without -mfentry with shrink wrapping enabled. * doc/install.texi: Document --enable-x86-64-mfentry. gcc/testsuite/ PR target/120881 * gcc.dg/20021014-1.c: Add additional -mfentry -fno-pic options for x86. * gcc.dg/aru-2.c: Likewise. * gcc.dg/nest.c: Likewise. * gcc.dg/pr32450.c: Likewise. * gcc.dg/pr43643.c: Likewise. * gcc.target/i386/pr104447.c: Likewise. * gcc.target/i386/pr113122-3.c: Likewise. * gcc.target/i386/pr119386-1.c: Add additional -mfentry if not ia32. * gcc.target/i386/pr119386-2.c: Likewise. * gcc.target/i386/pr120881-1a.c: New test. * gcc.target/i386/pr120881-1b.c: Likewise. * gcc.target/i386/pr120881-1c.c: Likewise. * gcc.target/i386/pr120881-1d.c: Likewise. * gcc.target/i386/pr120881-2a.c: Likewise. * gcc.target/i386/pr120881-2b.c: Likewise. * gcc.target/i386/pr82699-1.c: Add additional -mfentry. * lib/target-supports.exp (check_effective_target_fentry): New. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-07-14i386: Remove KEYLOCKER related feature since Panther Lake and Clearwater ForestHaochen Jiang1-6/+6
According to July 2025 SDM, Key locker will no longer be supported on hardware 2025 onwards. This means for Panther Lake and Clearwater Forest, the feature will not be enabled. Remove them from those two platforms. gcc/ChangeLog: * config/i386/i386.h (PTA_PANTHERLAKE): Revmoe KL and WIDEKL. (PTA_CLEARWATERFOREST): Ditto. * doc/invoke.texi: Revise documentation.
2025-07-11diagnostics: add support for directed graphs; use them for state graphsDavid Malcolm5-12/+241
In r16-1631-g2334d30cd8feac I added support for capturing state information from -fanalyzer in XML form, and adding a way to visualize these states in HTML output. The data was optionally captured in SARIF output (with "xml-state=yes"), stashing the XML in string form in a property bag. This worked, but there was no way to round-trip the stored data back from SARIF without adding an XML parser to GCC, which I don't want to do. SARIF supports capturing directed graphs, so this patch: (a) adds a new namespace diagnostics::digraphs, with classes digraph, node, and edge, representing directed graphs in a form similar to what SARIF can serialize (b) adds support to GCC's diagnostic subsystem for reporting graphs, either "globally" or as part of a diagnostic. An example in a testsuite plugin emits an error that has a couple of dummy graphs associated with it, and captures the optimization passes as a digraph "globally". Graphs are ignored by text sinks, but are captured by sarif sinks, and the "experimental-html" sink gains SVG-based rendering of any graphs using dot. This HTML output is rather crude; an example can be seen here: https://dmalcolm.fedorapeople.org/gcc/2025-07-10/diagnostic-test-graphs-html.c.html (c) adds support to libgdiagnostics for the above (d) adds support to sarif-replay for the above (round-tripping any graph information) (e) replaces the XML representation of state with a representation based on the above directed graphs, using property bags to stash additional information (e.g. "this is an on-stack buffer") (f) implements round-tripping of this information in sarif-replay To summarize: - previously we could generate HTML diagrams for debugging -fanalyzer directly from gcc, but not from stored .sarif output. - with this patch, we can generate such HTML diagrams both directly *and* from stored .sarif output (provided the SARIF sink was created with "state-graphs=yes") Examples of HTML output can be seen here: https://dmalcolm.fedorapeople.org/gcc/2025-07-10/ where as before j/k can be used to cycle through the events. which is almost identical to the output from the old XML-based implementation seen at: https://dmalcolm.fedorapeople.org/gcc/2025-06-23/ gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add diagnostic-digraphs.o and diagnostic-state-graphs.o. gcc/ChangeLog: * diagnostic-format-html.cc: Include "diagnostic-format-sarif.h", Replace include of "diagnostic-state.h" with includes of "diagnostic-digraphs.h" and "diagnostic-state-graphs.h". (html_generation_options::html_generation_options): Update for field renaming. (html_builder::m_body_element): New field. (html_builder::html_builder): Initialize m_body_element. (html_builder::maybe_make_state_diagram): Port from XML implementation to state graph implementation. (html_builder::make_element_for_diagnostic): Add any per-diagnostic graphs. (html_builder::add_graph): New. (html_builder::emit_global_graph): New. (html_output_format::report_global_digraph): New. * diagnostic-format-html.h (html_generation_options::m_show_state_diagram_xml): Replace with... (html_generation_options::m_show_state_diagrams_sarif): ...this. (html_generation_options::m_show_state_diagram_dot_src): Rename to... (html_generation_options::m_show_state_diagrams_dot_src): ...this. * diagnostic-format-sarif.cc: Include "diagnostic-digraphs.h" and "diagnostic-state-graphs.h". (sarif_builder::m_run_graphs): New field. (sarif_result::on_nested_diagnostic): Update call to make_location_object to pass arg by pointer. (sarif_builder::sarif_builder): Initialize m_run_graphs. (sarif_builder::report_global_digraph): New. (sarif_builder::make_result_object): Add any graphs to the result object. (sarif_builder::make_locations_arr): Update call to make_location_object to pass arg by pointer. (sarif_builder::make_location_object): Pass param "loc_mgr" by pointer rather than by reference so that it can be null, and handle this case. (copy_any_property_bag): New. (make_sarif_graph): New. (make_sarif_node): New. (make_sarif_edge): New. (sarif_property_bag::set_graph): New. (populate_thread_flow_location_object): Port from XML implementation to state graph implementation. (make_run_object): Store any graphs. (sarif_output_format::report_global_digraph): New. (sarif_generation_options::sarif_generation_options): Rename m_xml_state to m_state_graph. (selftest::test_make_location_object): Update for change to make_location_object. * diagnostic-format-sarif.h: (sarif_generation_options::m_xml_state): Replace with... (sarif_generation_options::m_state_graph): ...this. (class sarif_location_manager): Add forward decl. (diagnostics::digraphs::digraph): New forward decl. (diagnostics::digraphs::node): New forward decl. (diagnostics::digraphs::edge): New forward decl. (sarif_property_bag::set_graph): New decl. (class sarif_graph): New. (class sarif_node): New. (class sarif_edge): New. (make_sarif_graph): New decl. (make_sarif_node): New decl. (make_sarif_edge): New decl. * diagnostic-format-text.h (diagnostic_text_output_format::report_global_digraph): New. * diagnostic-format.h (diagnostic_output_format::report_global_digraph): New vfunc. * diagnostic-digraphs.cc: New file. * diagnostic-digraphs.h: New file. * diagnostic-metadata.h (diagnostics::digraphs::lazy_digraphs): New forward decl. (diagnostic_metadata::diagnostic_metadata): Initialize m_lazy_digraphs. (diagnostic_metadata::set_lazy_digraphs): New. (diagnostic_metadata::get_lazy_digraphs): New. (diagnostic_metadata::m_lazy_digraphs): New field. * diagnostic-output-spec.cc (sarif_scheme_handler::make_sink): Update for XML to state graph changes. (sarif_scheme_handler::make_sarif_gen_opts): Likewise. (html_scheme_handler::make_sink): Rename "show-state-diagram-xml" to "show-state-diagrams-sarif" and use pluralization consistently. * diagnostic-path.cc: Replace include of "xml.h" with "diagnostic-state-graphs.h". (diagnostic_event::maybe_make_xml_state): Replace with... (diagnostic_event::maybe_make_diagnostic_state_graph): ...this. * diagnostic-path.h (diagnostics::digraphs::digraph): New forward decl. (diagnostic_event::maybe_make_xml_state): Replace with... (diagnostic_event::maybe_make_diagnostic_state_graph): ...this. * diagnostic-state-graphs.cc: New file. * diagnostic-state-graphs.h: New file. * diagnostic-state-to-dot.cc: Port implementation from XML to state graphs. * diagnostic-state.h: Deleted file. * diagnostic.cc (diagnostic_context::report_global_digraph): New. * diagnostic.h (diagnostics::digraphs::lazy_digraph): New forward decl. (diagnostic_context::report_global_digraph): New decl. * doc/analyzer.texi (Debugging the Analyzer): Update to reflect change from XML to state graphs. * doc/invoke.texi ("sarif" diagnostics sink): Replace "xml-state" with "state-graphs". ("experimental-html" diagnostics sink): Replace "show-state-diagrams-xml" with "show-state-diagrams-sarif" * doc/libgdiagnostics/topics/compatibility.rst (LIBGDIAGNOSTICS_ABI_3): New. * doc/libgdiagnostics/topics/graphs.rst: New file. * doc/libgdiagnostics/topics/index.rst: Add graphs.rst. * graphviz.h (node_id::operator=): New. * json.h (json::value::dyn_cast_string): New. (json::object::get_num_keys): New accessor. (json::object::get_key): New accessor. (json::string::dyn_cast_string): New. * libgdiagnostics++.h (class libgdiagnostics::graph): New. (class libgdiagnostics::node): New. (class libgdiagnostics::edge): New. (class libgdiagnostics::diagnostic::take_graph): New. (class libgdiagnostics::manager::take_global_graph): New. (class libgdiagnostics::graph::set_description): New. (class libgdiagnostics::graph::get_node_by_id): New. (class libgdiagnostics::graph::get_edge_by_id): New. (class libgdiagnostics::graph::add_edge): New. (class libgdiagnostics::node::set_label): New. (class libgdiagnostics::node::set_location): New. (class libgdiagnostics::node::set_logical_location): New. * libgdiagnostics-private.h: New file. * libgdiagnostics.cc: Define INCLUDE_STRING. Include "diagnostic-digraphs.h", "diagnostic-state-graphs.h", and "libgdiagnostics-private.h". (struct diagnostic_graph): New. (struct diagnostic_node): New. (struct diagnostic_edge): New. (libgdiagnostics_path_event::libgdiagnostics_path_event): Add state_graph param. (libgdiagnostics_path_event::maybe_make_diagnostic_state_graph): New. (libgdiagnostics_path_event::m_state_graph): New field. (diagnostic_execution_path::add_event_va): Add state_graph param. (class prebuilt_digraphs): New. (diagnostic::diagnostic): Use m_graphs in m_metadata. (diagnostic::take_graph): New. (diagnostic::get_graphs): New accessor. (diagnostic::m_graphs): New field. (diagnostic_manager::take_global_graph): New. (diagnostic_execution_path_add_event): Update for new param to add_event_va. (diagnostic_execution_path_add_event_va): Likewise. (diagnostic_graph::add_node_with_id): New public entrypoint. (diagnostic_graph::add_edge_with_label): New public entrypoint. (diagnostic_manager_new_graph): New public entrypoint. (diagnostic_manager_take_global_graph): New public entrypoint. (diagnostic_take_graph): New public entrypoint. (diagnostic_graph_release): New public entrypoint. (diagnostic_graph_set_description): New public entrypoint. (diagnostic_graph_add_node): New public entrypoint. (diagnostic_graph_add_edge): New public entrypoint. (diagnostic_graph_get_node_by_id): New public entrypoint. (diagnostic_graph_get_edge_by_id): New public entrypoint. (diagnostic_node_set_location): New public entrypoint. (diagnostic_node_set_label): New public entrypoint. (diagnostic_node_set_logical_location): New public entrypoint. (private_diagnostic_execution_path_add_event_2): New private entrypoint. (private_diagnostic_graph_set_property_bag): New private entrypoint. (private_diagnostic_node_set_property_bag): New private entrypoint. (private_diagnostic_edge_set_property_bag): New private entrypoint. * libgdiagnostics.h (diagnostic_graph): New typedef. (diagnostic_node): New typedef. (diagnostic_edge): New typedef. (diagnostic_manager_new_graph): New decl. (diagnostic_manager_take_global_graph): New decl. (diagnostic_take_graph): New decl. (diagnostic_graph_release): New decl. (diagnostic_graph_set_description): New decl. (diagnostic_graph_add_node): New decl. (diagnostic_graph_add_edge): New decl. (diagnostic_graph_get_node_by_id): New decl. (diagnostic_graph_get_edge_by_id): New decl. (diagnostic_node_set_label): New decl. (diagnostic_node_set_location): New decl. (diagnostic_node_set_logical_location): New decl. * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_3): New. * libsarifreplay.cc: Include "libgdiagnostics-private.h". (id_map): New "using". (sarif_replayer::report_invalid_sarif): Update for change to report_problem params. (sarif_replayer::report_unhandled_sarif): Likewise. (sarif_replayer::report_note): New. (sarif_replayer::report_problem): Pass param "ref" by pointer rather than reference and handle it being null. (sarif_replayer::maybe_get_property_bag): New. (sarif_replayer::maybe_get_property_bag_value): New. (sarif_replayer::handle_run_obj): Handle run-level "graphs" as per §3.14.20. (sarif_replayer::handle_result_obj): Handle result-level "graphs" as per §3.27.19. (handle_thread_flow_location_object): Optionally handle graphs stored in property "gcc/diagnostic_event/state_graph" as state graphs. (sarif_replayer::handle_graph_object): New. (sarif_replayer::handle_node_object): New. (sarif_replayer::handle_edge_object): New. (sarif_replayer::get_graph_node_by_id_property): New. * selftest-run-tests.cc (selftest::run_tests): Call selftest::diagnostic_graph_cc_tests and selftest::diagnostic_state_graph_cc_tests. * selftest.h (selftest::diagnostic_graph_cc_tests): New decl. (selftest::diagnostic_state_graph_cc_tests): New decl. gcc/analyzer/ChangeLog: * ana-state-to-diagnostic-state.cc: Reimplement, replacing XML-based implementation with one based on state graphs. * ana-state-to-diagnostic-state.h: Likewise. * checker-event.cc: Replace include of "xml.h" with include of "diagnostic-state-graphs.h". (checker_event::maybe_make_xml_state): Replace with... (checker_event::maybe_make_diagnostic_state_graph): ...this. * checker-event.h: Add include of "diagnostic-digraphs.h". (checker_event::maybe_make_xml_state): Replace decl with... (checker_event::maybe_make_diagnostic_state_graph): ...this. * engine.cc (exploded_node::on_stmt_pre): Replace "_analyzer_dump_xml" with "__analyzer_dump_sarif". * program-state.cc: Replace include of "diagnostic-state.h" with "diagnostic-state-graphs.h". (program_state::dump_dot): Port from XML to state graphs. * program-state.h: Drop reduntant forward decl of xml::document. (program_state::make_xml): Replace decl with... (program_state::make_diagnostic_state_graph): ...this. (program_state::dump_xml_to_pp): Drop decl. (program_state::dump_xml_to_file): Drop decl. (program_state::dump_xml): Drop decl. (program_state::dump_dump_sarif): New decl. * sm-malloc.cc (get_dynalloc_state_for_state): New. (malloc_state_machine::add_state_to_xml): Replace with... (malloc_state_machine::add_state_to_state_graph): ...this. * sm.cc (state_machine::add_state_to_xml): Replace with... (state_machine::add_state_to_state_graph): ...this. (state_machine::add_global_state_to_xml): Replace with... (state_machine::add_global_state_to_state_graph): ...this. * sm.h (class xml_state): Drop forward decl. (class analyzer_state_graph): New forward decl. (state_machine::add_state_to_xml): Replace decl with... (state_machine::add_state_to_state_graph): ...this. (state_machine::add_global_state_to_xml): Replace decl with... (state_machine::add_global_state_to_state_graph): ...this. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/state-diagram-1-sarif.py (test_xml_state): Rename to... (test_state_graph): ...this. Port from XML to SARIF graphs. * gcc.dg/analyzer/state-diagram-1.c: Update sink option from "sarif:xml-state=yes" to "sarif:state-graphs=yes". * gcc.dg/analyzer/state-diagram-5-sarif.c: Likewise. * gcc.dg/analyzer/state-diagram-5-sarif.py: Drop import of ET. (test_nested_types_in_xml_state): Rename to... (test_nested_types_in_state_graph): ...this. Port from XML to SARIF graphs. * gcc.dg/plugin/diagnostic-test-graphs-html.c: New test. * gcc.dg/plugin/diagnostic-test-graphs-html.py: New test script. * gcc.dg/plugin/diagnostic-test-graphs-sarif.c: New test. * gcc.dg/plugin/diagnostic-test-graphs-sarif.py: New test script. * gcc.dg/plugin/diagnostic-test-graphs.c: New test. * gcc.dg/plugin/diagnostic_plugin_test_graphs.cc: New test plugin. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above. * lib/sarif.py (get_xml_state): Delete. (get_state_graph): New. (def get_state_node_attr): New. (get_state_node_kind): New. (get_state_node_name): New. (get_state_node_type): New. (get_state_node_value): New. * sarif-replay.dg/2.1.0-invalid/3.40.2-duplicate-node-id.sarif: New test. * sarif-replay.dg/2.1.0-invalid/3.41.4-unrecognized-node-id.sarif: New test. * sarif-replay.dg/2.1.0-valid/graphs-check-html.py: New test script. * sarif-replay.dg/2.1.0-valid/graphs-check-sarif-roundtrip.py: New test script. * sarif-replay.dg/2.1.0-valid/graphs.sarif: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-11libgdiagnostics: doc fixesDavid Malcolm4-21/+25
gcc/ChangeLog: * doc/libgdiagnostics/topics/compatibility.rst (_LIBGDIAGNOSTICS_ABI_2): Add missing anchor. * doc/libgdiagnostics/topics/diagnostic-manager.rst (diagnostic_manager_add_sink_from_spec): Add links to GCC's documentation of "-fdiagnostics-add-output=". Fix parameter markup. (diagnostic_manager_set_analysis_target): Fix parameter markup. Add link to SARIF spec. * doc/libgdiagnostics/topics/logical-locations.rst: Markup fix. * doc/libgdiagnostics/tutorial/02-physical-locations.rst: Clarify wording of what "the source file" means, and that a range can't have multiple files. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-11c++: Implement C++26 P2786R13 - Trivial Relocatability [PR119064]Jakub Jelinek1-1/+7
The following patch implements the compiler side of the C++26 paper. Based on the https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119064#c3 feedback, the patch enables the new conditional keywords trivially_relocatable_if_eligible and replaceable_if_eligible only for C++26, for older versions those conditional keywords yield -Wc++26-compat warning and are treated as normal identifiers. Plus __trivially_relocatable_if_eligible and __replaceable_if_eligible are handled as conditional keywords always without diagnostics (similarly to __final in C++98). The patch uses __builtin_ prefix on the new traits (but unlike clang which for some weird reason chose to name one __builtin_is_replaceable and another __builtin_is_cpp_trivially_relocatable this one uses __builtin_is_replaceable and __builtin_is_trivially_relocatable. I'll try to convince clang to change, they've only implemented it recently. The patch computes these properties on demand, only when something needs them (at the expense of eating 2 more bits per lang_type, but I've recently saved 64 bits and a patch to save another 64 bits is pending; and even 4 bits wouldn't fit). The patch doesn't add __builtin_trivially_relocate builtin that clang has, std::trivially_relocate is not constexpr and I think we don't need it for now at least until we implement some kind of vtable pointer signing __builtin_memmove should do the job. Especially if libstdc++ will for clang compatibility use the builtin if available and __builtin_memmove otherwise, we can switch any time. I've cross-tested all testcases also against the clang++ trunk implementation, and both compilers agreed in everything except for https://github.com/llvm/llvm-project/issues/143599 where clang++ was changed already and https://github.com/llvm/llvm-project/issues/144232 where I believe clang++ got it wrong too. The first testcase comes from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2786r13.html#simple-worked-examples just tweaked so that the classes are named differently each time and that it compiles. There are 3 differences from the paper vs. the g++ as well as clang++ implementation, I've added comments into trivially-relocatable1.C but I think either that part of the paper wasn't updated through the later changes or it got it wrong. 2025-07-11 Jakub Jelinek <jakub@redhat.com> PR c++/119064 gcc/ * doc/invoke.texi (Wc++26-compat): Document. gcc/c-family/ * c.opt (Wc++26-compat): New option. * c.opt.urls: Regenerate. * c-opts.cc (c_common_post_options): Clear warn_cxx26_compat for C++26 or later. * c-cppbuiltin.cc (c_cpp_builtins): For C++26 predefine __cpp_trivial_relocatability=202502L. gcc/cp/ * cp-tree.h: Implement C++26 P2786R13 - Trivial Relocatability. (struct lang_type): Add trivially_relocatable, trivially_relocatable_computed, replaceable and replaceable_computed bitfields. Change width of dummy from 2 to 30. (CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT, CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED, CLASSTYPE_REPLACEABLE_BIT, CLASSTYPE_REPLACEABLE_COMPUTED): Define. (enum virt_specifier): Add VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE and VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE enumerators. (trivially_relocatable_type_p, replaceable_type_p): Declare. * cp-trait.def (IS_NOTHROW_RELOCATABLE, IS_REPLACEABLE, IS_TRIVIALLY_RELOCATABLE): New traits. * parser.cc (cp_parser_class_property_specifier_seq_opt): Handle trivially_relocatable_if_eligible, __trivially_relocatable_if_eligible, replaceable_if_eligible and __replaceable_if_eligible. (cp_parser_class_head): Set CLASSTYPE_REPLACEABLE_BIT and/or CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT if corresponding conditional keywords were parsed and assert corresponding *_COMPUTED macro is false. * pt.cc (instantiate_class_template): Copy over also CLASSTYPE_TRIVIALLY_RELOCATABLE_{BIT,COMPUTED} and CLASSTYPE_REPLACEABLE_{BIT,COMPUTED} bits. * semantics.cc (referenceable_type_p): Move definition earlier. (trait_expr_value): Handle CPTK_IS_NOTHROW_RELOCATABLE, CPTK_IS_REPLACEABLE and CPTK_IS_TRIVIALLY_RELOCATABLE. (finish_trait_expr): Likewise. * tree.cc (default_movable_type_p): New function. (union_with_no_declared_special_member_fns): Likewise. (trivially_relocatable_type_p): Likewise. (replaceable_type_p): Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_NOTHROW_RELOCATABLE, CPTK_IS_REPLACEABLE and CPTK_IS_TRIVIALLY_RELOCATABLE. gcc/testsuite/ * g++.dg/cpp26/feat-cxx26.C: Add test for __cpp_trivial_relocatability. * g++.dg/cpp26/trivially-relocatable1.C: New test. * g++.dg/cpp26/trivially-relocatable2.C: New test. * g++.dg/cpp26/trivially-relocatable3.C: New test. * g++.dg/cpp26/trivially-relocatable4.C: New test. * g++.dg/cpp26/trivially-relocatable5.C: New test. * g++.dg/cpp26/trivially-relocatable6.C: New test. * g++.dg/cpp26/trivially-relocatable7.C: New test. * g++.dg/cpp26/trivially-relocatable8.C: New test. * g++.dg/cpp26/trivially-relocatable9.C: New test. * g++.dg/cpp26/trivially-relocatable10.C: New test. * g++.dg/cpp26/trivially-relocatable11.C: New test.
2025-07-10aarch64: Extend HVLA permutations to big-endianRichard Sandiford1-0/+6
TARGET_VECTORIZE_VEC_PERM_CONST has code to match the SVE2.1 "hybrid VLA" DUPQ, EXTQ, UZPQ{1,2}, and ZIPQ{1,2} instructions. This matching was conditional on !BYTES_BIG_ENDIAN. The ACLE code also lowered the associated SVE2.1 intrinsics into suitable VEC_PERM_EXPRs. This lowering was not conditional on !BYTES_BIG_ENDIAN. The mismatch led to lots of ICEs in the ACLE tests on big-endian targets: we lowered to VEC_PERM_EXPRs that are not supported. I think the !BYTES_BIG_ENDIAN restriction was unnecessary. SVE maps the first memory element to the least significant end of the register for both endiannesses, so no endian correction or lane number adjustment is necessary. This is in some ways a bit counterintuitive. ZIPQ1 is conceptually "apply Advanced SIMD ZIP1 to each 128-bit block" and endianness does matter when choosing between Advanced SIMD ZIP1 and ZIP2. For example, the V4SI permute selector { 0, 4, 1, 5 } corresponds to ZIP1 for little- endian and ZIP2 for big-endian. But the difference between the hybrid VLA and Advanced SIMD permute selectors is a consequence of the difference between the SVE and Advanced SIMD element orders. The same thing applies to ACLE intrinsics. The current lowering of svzipq1 etc. is correct for both endiannesses. If ACLE code does: 2x svld1_s32 + svzipq1_s32 + svst1_s32 then the byte-for-byte result is the same for both endiannesses. On big-endian targets, this is different from using the Advanced SIMD sequence below for each 128-bit block: 2x LDR + ZIP1 + STR In contrast, the byte-for-byte result of: 2x svld1q_gather_s32 + svzipq1_s32 + svst11_scatter_s32 depends on endianness, since the quadword gathers and scatters use Advanced SIMD byte ordering for each 128-bit block. This gather/scatter sequence behaves in the same way as the Advanced SIMD LDR+ZIP1+STR sequence for both endiannesses. Programmers writing ACLE code have to be aware of this difference if they want to support both endiannesses. The patch includes some new execution tests to verify the expansion of the VEC_PERM_EXPRs. gcc/ * doc/sourcebuild.texi (aarch64_sve2_hw, aarch64_sve2p1_hw): Document. * config/aarch64/aarch64.cc (aarch64_evpc_hvla): Extend to BYTES_BIG_ENDIAN. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_aarch64_sve2p1_hw): New proc. * gcc.target/aarch64/sve2/dupq_1.c: Extend to big-endian. Add noipa attributes. * gcc.target/aarch64/sve2/extq_1.c: Likewise. * gcc.target/aarch64/sve2/uzpq_1.c: Likewise. * gcc.target/aarch64/sve2/zipq_1.c: Likewise. * gcc.target/aarch64/sve2/dupq_1_run.c: New test. * gcc.target/aarch64/sve2/extq_1_run.c: Likewise. * gcc.target/aarch64/sve2/uzpq_1_run.c: Likewise. * gcc.target/aarch64/sve2/zipq_1_run.c: Likewise.
2025-07-07Revert "Extend "counted_by" attribute to pointer fields of structures. ↵Qing Zhao1-36/+5
Convert a pointer reference with counted_by attribute to .ACCESS_WITH_SIZE." due to PR120929. This reverts commit 687727375769dd41971bad369f3553f1163b3e7a.
2025-07-07c++: -Wno-abbreviated-auto-in-template-arg [PR120917]Jason Merrill1-0/+18
In r14-1659 I added a missing error for a Concepts TS feature that we were failing to diagnose, but this PR requests a way to disable that error for code written thinking it was valid. Which seems reasonable, since it doesn't require any work beyond that and is a plausible extension by itself. While looking at this, I also noticed we were still not giving the diagnostic in a few cases, and fixing that affected a few of our old concepts testcases. PR c++/120917 gcc/ChangeLog: * doc/invoke.texi: Add -Wno-abbreviated-auto-in-template-arg. gcc/c-family/ChangeLog: * c.opt: Add -Wno-abbreviated-auto-in-template-arg. * c.opt.urls: Regenerate. gcc/cp/ChangeLog: * parser.cc (cp_parser_simple_type_specifier): Attach auto in targ in parameter to -Wabbreviated-auto-in-template-arg. (cp_parser_placeholder_type_specifier): Diagnose constrained auto in template arg. gcc/testsuite/ChangeLog: * g++.dg/concepts/auto7a.C: Add diagnostic. * g++.dg/concepts/auto7b.C: New test. * g++.dg/concepts/auto7c.C: New test. * g++.dg/cpp1y/pr85076.C: Expect 'auto' error. * g++.dg/concepts/pr67249.C: Likewise. * g++.dg/cpp1y/lambda-generic-variadic.C: Likewise. * g++.dg/cpp2a/concepts-pr67210.C: Likewise. * g++.dg/concepts/pr67249a.C: New test. * g++.dg/cpp1y/lambda-generic-variadic-a.C: New test. * g++.dg/cpp2a/concepts-pr67210a.C: New test.
2025-07-06crc: Error out on non-constant poly arguments for the crc builtins [PR120709]Andrew Pinski1-2/+2
These builtins requires a constant integer for the third argument but currently there is assert rather than error. This fixes that and updates the documentation too. Uses the same terms as was being used for the __builtin_prefetch arguments. Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/120709 gcc/ChangeLog: * builtins.cc (expand_builtin_crc_table_based): Error out instead of asserting the 3rd argument is an integer constant. * internal-fn.cc (expand_crc_optab_fn): Likewise. * doc/extend.texi (crc): Document requirement of the poly argument being a constant. gcc/testsuite/ChangeLog: * gcc.dg/crc-non-cst-poly-1.c: New test. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-06AVR: Fix a typo in avr-mcus.def.Georg-Johann Lay1-3/+3
gcc/ * config/avr/avr-mcus.def: -mmcu= takes lower case MCU names. * doc/avr-mmcu.texi: Rebuild.
2025-07-06AVR: Add support for AVR32DAxxS, AVR64DAxxS, AVR128DAxxS devices.Georg-Johann Lay1-3/+3
gcc/ * config/avr/avr-mcus.def (avr32da28S, avr32da32S, avr32da48S) (avr64da28S, avr64da32S, avr64da48S avr64da64S) (avr128da28S, avr128da32S, avr128da48S, avr128da64S): Add devices. * doc/avr-mmcu.texi: Rebuild.
2025-07-03AArch64: recognize `+cmpbr` optionKarl Meakin1-0/+3
Add the `+cmpbr` option to enable the FEAT_CMPBR architectural extension. gcc/ChangeLog: * config/aarch64/aarch64-option-extensions.def (cmpbr): New option. * config/aarch64/aarch64.h (TARGET_CMPBR): New macro. * doc/invoke.texi (cmpbr): New option.
2025-07-03Add -Wauto-profile warningJan Hubicka1-1/+6
this patch adds new warning -Wauto-profile which warns about mismatches between profile data and function bodies. This is implemented during the offline pass where every function instance is compared with actual gimple body (if available) and we verify that the statement locations in the profile data can be matched with statements in the function. Currently it is mostly useful to find bugs, but eventually I hope it will be useful for users to verify that auto-profile works as expected or to evaulate how much of an old auto-profile data can still be applied to current sources. There will probably be always some side cases we can not handle with auto-profile format (such as function with bodies in mutlple files) that can be patched in compiled program. I also added logic to fix up missing discriminators in the function callsites. I am not sure how those happens (but seem to go away with -fno-crossjumping) and will dig into it. Ohter problem is that without -flto at the train run inlined functions have dwarf names rather than symbol names. LLVM solves this by -gdebug-for-autoprofile flag that we could also have. With this flag we could output assembler names as well as multiplicities of statemnets. Building SPECint there are approx 7k profile mismatches. Bootstrapped/regtested x86_64-linux. Plan to commit it after some extra testing. gcc/ChangeLog: * auto-profile.cc (get_combined_location): Handle negative offsets; output better diagnostics. (get_relative_location_for_locus): Reutrn -1 for unknown location. (function_instance::get_cgraph_node): New member function. (match_with_target): New function. (dump_stmt): New function. (function_instance::lookup_count): New function. (mark_expr_locations): New function. (function_instance::match): New function. (autofdo_source_profile::offline_external_functions): Do not repeat renaming; manage two worklists and do matching. (autofdo_source_profile::offline_unrealized_inlines): Simplify. (afdo_set_bb_count): do not look for lost discriminators. (auto_profile): Do not ICE when profile reading failed. * common.opt (Wauto-profile): New warning flag * doc/invoke.texi (-Wauto-profile): Document.
2025-07-03doc: Clarify mode of else operand for vec_mask_load_lanesmnAlex Coplan1-2/+2
This extends the documentation of the vec_mask_load_lanes<m><n> optab to explicitly state that the mode of the else operand is n, i.e. the mode of a single subvector. gcc/ChangeLog: * doc/md.texi (Standard Names): Clarify mode of else operand for vec_mask_load_lanesmn optab.
2025-07-01Extend "counted_by" attribute to pointer fields of structures. Convert a ↵Qing Zhao1-5/+36
pointer reference with counted_by attribute to .ACCESS_WITH_SIZE. 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. 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-typeck.cc (build_counted_by_ref): Handle pointers with counted_by. Add one more argument, issue error when the pointee type is a structure or union including a flexible array member. (build_access_with_size_for_counted_by): Handle pointers with counted_by. (handle_counted_by_for_component_ref): Call build_counted_by_ref with the new prototype. 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.c: New test.
2025-06-30diagnostics: remove "json" output formatDavid Malcolm2-19/+6
The "json" output format for diagnostics was deprecated in GCC 15, with advice to users seeking machine-readable diagnostics from GCC to use SARIF instead. This patch eliminates it from GCC 16, simplifying the diagnostics subsystem somewhat. Note that the Ada frontend seems to have its own implementation of this in errout.adb (Output_JSON_Message), and documented in gnat_ugn.texi. This patch does not touch Ada. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Drop diagnostic-format-json.o. * common.opt (fdiagnostics-format=): Drop "json|json-stderr|json-file". (diagnostics_output_format): Drop values "json", "json-stderr", and "json-file". * diagnostic-format-json.cc: Delete file. * diagnostic-format.h (diagnostic_output_format_init_json_stderr): Delete. (diagnostic_output_format_init_json_file): Delete. * diagnostic.cc (diagnostic_output_format_init): Delete cases for DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR and DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE. * diagnostic.h (DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR): Delete. (DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE): Delete. * doc/invoke.texi: Remove references to json output format. * doc/ux.texi: Likewise. * selftest-run-tests.cc (selftest::run_tests): Drop call to deleted selftest::diagnostic_format_json_cc_tests. * selftest.h (selftest::diagnostic_format_json_cc_tests): Delete. gcc/testsuite/ChangeLog: * c-c++-common/analyzer/out-of-bounds-diagram-1-json.c: Deleted test. * c-c++-common/diagnostic-format-json-1.c: Deleted test. * c-c++-common/diagnostic-format-json-2.c: Deleted test. * c-c++-common/diagnostic-format-json-3.c: Deleted test. * c-c++-common/diagnostic-format-json-4.c: Deleted test. * c-c++-common/diagnostic-format-json-5.c: Deleted test. * c-c++-common/diagnostic-format-json-file-1.c: Deleted test. * c-c++-common/diagnostic-format-json-stderr-1.c: Deleted test. * c-c++-common/pr106133.c: Deleted test. * g++.dg/pr90462.C: Deleted test. * gcc.dg/plugin/diagnostic-test-paths-3.c: Deleted test. * gcc.dg/plugin/plugin.exp (plugin_test_list): Remove deleted test. * gfortran.dg/diagnostic-format-json-1.F90: Deleted test. * gfortran.dg/diagnostic-format-json-2.F90: Deleted test. * gfortran.dg/diagnostic-format-json-3.F90: Deleted test. * gfortran.dg/diagnostic-format-json-pr105916.F90: Deleted test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-06-30aarch64: Add support for NVIDIA GB10Kyrylo Tkachov1-1/+1
This adds support for -mcpu=gb10. This is a big.LITTLE configuration involving Cortex-X925 and Cortex-A725 cores. The appropriate MIDR numbers are added to detect them in -mcpu=native. We did not add an -mcpu=cortex-x925.cortex-a725 option because GB10 does include the crypto instructions which we want on by default, and the current convention is to not enable such extensions for Arm Cortex cores in -mcpu where they are optional in the IP. Bootstrapped and tested on aarch64-none-linux-gnu. Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com> gcc/ * config/aarch64/aarch64-cores.def (gb10): New entry. * config/aarch64/aarch64-tune.md: Regenerate. * doc/invoke.texi (AArch64 Options): Document the above.
2025-06-30Extend nonnull_if_nonzero attribute [PR120520]Jakub Jelinek1-4/+18
C2Y voted in the https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3466.pdf paper, which clarifies some of the conditional nonnull cases. For strncat/__strncat_chk no changes are necessary, we already use __attribute__((nonnull (1), nonnull_if_nonzero (2, 3))) attributes on the builtin and glibc can do the same too, meaning that first argument must be nonnull always and second must be nonnull if the third one is nonzero. The problem is with the fread/fwrite changes, where the paper adds: If size or nmemb is zero, +ptr may be a null pointer, fread returns zero and the contents of the array and the state of the stream remain unchanged. and ditto for fwrite, so the two argument nonnull_if_nonzero attribute isn't usable to express that, because whether the pointer can be null depends on 2 integral arguments rather than one. The following patch extends the nonnull_if_nonzero attribute, so that instead of requiring 2 arguments it allows 2 or 3, the first one is still the pointer argument index which sometimes must not be null and the other one or two are integral arguments, if there are 2, the invalid case is only if pointer is null and both the integral arguments are nonzero. 2025-06-30 Jakub Jelinek <jakub@redhat.com> PR c/120520 PR c/117023 gcc/ * builtin-attrs.def (DEF_LIST_INT_INT_INT): Define it and use for 1,2,3. (ATTR_NONNULL_IF123_LIST): New DEF_ATTR_TREE_LIST. (ATTR_NONNULL_4_IF123_LIST): Likewise. * builtins.def (BUILT_IN_FWRITE): Use ATTR_NONNULL_4_IF123_LIST instead of ATTR_NONNULL_LIST. (BUILT_IN_FWRITE_UNLOCKED): Likewise. * gimple.h (infer_nonnull_range_by_attribute): Add another optional tree * argument defaulted to NULL. * gimple.cc (infer_nonnull_range_by_attribute): Add OP3 argument, handle 3 argument nonnull_if_nonzero attribute. * builtins.cc (validate_arglist): Handle 3 argument nonnull_if_nonzero attribute. * tree-ssa-ccp.cc (pass_post_ipa_warn::execute): Likewise. * ubsan.cc (instrument_nonnull_arg): Adjust infer_nonnull_range_by_attribute caller, handle 3 argument nonnull_if_nonzero attribute. * gimple-range-infer.cc (gimple_infer_range::gimple_infer_range): Handle 3 argument nonnull_if_nonzero attribute. * doc/extend.texi (nonnull_if_nonzero): Document 3 argument version of the attribute. gcc/c-family/ * c-attribs.cc (c_common_gnu_attributes): Allow 2 or 3 arguments for nonnull_if_nonzero attribute instead of only 2. (handle_nonnull_if_nonzero_attribute): Handle 3 argument nonnull_if_nonzero. * c-common.cc (struct nonnull_arg_ctx): Rename other member to other1, add other2 member. (check_function_nonnull): Clear a if nonnull attribute has an argument. Adjust for nonnull_arg_ctx changes. Handle 3 argument nonnull_if_nonzero attribute. (check_nonnull_arg): Adjust for nonnull_arg_ctx changes, emit different diagnostics for 3 argument nonnull_if_nonzero attributes. (check_function_arguments): Adjust ctx var initialization. gcc/analyzer/ * sm-malloc.cc (malloc_state_machine::on_stmt): Handle 3 argument nonnull_if_nonzero attribute. gcc/testsuite/ * gcc.dg/nonnull-9.c: Tweak for 3 argument nonnull_if_nonzero attribute support, add further tests. * gcc.dg/nonnull-12.c: New test. * gcc.dg/nonnull-13.c: New test. * gcc.dg/nonnull-14.c: New test. * c-c++-common/ubsan/nonnull-8.c: New test. * c-c++-common/ubsan/nonnull-9.c: New test.
2025-06-30x86: Preserve frame pointer for no_callee_saved_registers attributeH.J. Lu1-4/+5
Update functions with no_callee_saved_registers/preserve_none attribute to preserve frame pointer since caller may use it to save the current stack: pushq %rbp movq %rsp, %rbp ... call function ... leave ret If callee changes frame pointer without restoring it, caller will fail to restore its stack after callee returns as LEAVE does mov %rbp, %rsp pop %rbp The corrupted frame pointer will corrupt stack pointer in caller. There are no regressions on Linux/x86-64. Also tested with https://github.com/python/cpython configured with "./configure --with-tail-call-interp". gcc/ PR target/120840 * config/i386/i386-expand.cc (ix86_expand_call): Don't mark hard frame pointer as clobber. * config/i386/i386-options.cc (ix86_set_func_type): Use TYPE_NO_CALLEE_SAVED_REGISTERS instead of TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP. * config/i386/i386.cc (ix86_function_ok_for_sibcall): Remove the TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP check. (ix86_save_reg): Merge TYPE_NO_CALLEE_SAVED_REGISTERS and TYPE_PRESERVE_NONE with TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP. * config/i386/i386.h (call_saved_registers_type): Remove TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP. * doc/extend.texi: Update no_callee_saved_registers documentation. gcc/testsuite/ PR target/120840 * gcc.target/i386/no-callee-saved-1.c: Updated. * gcc.target/i386/no-callee-saved-2.c: Likewise. * gcc.target/i386/no-callee-saved-7.c: Likewise. * gcc.target/i386/no-callee-saved-8.c: Likewise. * gcc.target/i386/no-callee-saved-9.c: Likewise. * gcc.target/i386/no-callee-saved-10.c: Likewise. * gcc.target/i386/no-callee-saved-18.c: Likewise. * gcc.target/i386/no-callee-saved-19a.c: Likewise. * gcc.target/i386/no-callee-saved-19c.c: Likewise. * gcc.target/i386/no-callee-saved-19d.c: Likewise. * gcc.target/i386/pr119784a.c: Likewise. * gcc.target/i386/preserve-none-6.c: Likewise. * gcc.target/i386/preserve-none-7.c: Likewise. * gcc.target/i386/preserve-none-12.c: Likewise. * gcc.target/i386/preserve-none-13.c: Likewise. * gcc.target/i386/preserve-none-14.c: Likewise. * gcc.target/i386/preserve-none-15.c: Likewise. * gcc.target/i386/preserve-none-23.c: Likewise. * gcc.target/i386/pr120840-1a.c: New test. * gcc.target/i386/pr120840-1b.c: Likewise. * gcc.target/i386/pr120840-1c.c: Likewise. * gcc.target/i386/pr120840-1d.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-06-27docs: fix a typo in used attribute documentationTamar Christina1-1/+1
This fixes a small typo in the Label attributes docs. gcc/ChangeLog: * doc/extend.texi: Fix typo in unsed attribute docs.
2025-06-26x86: Add preserve_none and update no_caller_saved_registers attributesH.J. Lu1-3/+11
Add preserve_none attribute which is similar to no_callee_saved_registers attribute, except on x86-64, r12, r13, r14, r15, rdi and rsi registers are used for integer parameter passing. This can be used in an interpreter to avoid saving/restoring the registers in functions which process byte codes. It improved the pystones benchmark by 6-7%: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119628#c15 Remove -mgeneral-regs-only restriction on no_caller_saved_registers attribute. Only SSE is allowed since SSE XMM register load preserves the upper bits in YMM/ZMM register while YMM register load zeros the upper 256 bits of ZMM register, and preserving 32 ZMM registers can be quite expensive. gcc/ PR target/119628 * config/i386/i386-expand.cc (ix86_expand_call): Call ix86_type_no_callee_saved_registers_p instead of looking up no_callee_saved_registers attribute. * config/i386/i386-options.cc (ix86_set_func_type): Look up preserve_none attribute. Check preserve_none attribute for interrupt attribute. Don't check no_caller_saved_registers nor no_callee_saved_registers conflicts here. (ix86_set_func_type): Check no_callee_saved_registers before checking no_caller_saved_registers attribute. (ix86_set_current_function): Allow SSE with no_caller_saved_registers attribute. (ix86_handle_call_saved_registers_attribute): Check preserve_none, no_callee_saved_registers and no_caller_saved_registers conflicts. (ix86_gnu_attributes): Add preserve_none attribute. * config/i386/i386-protos.h (ix86_type_no_callee_saved_registers_p): New. * config/i386/i386.cc (x86_64_preserve_none_int_parameter_registers): New. (ix86_using_red_zone): Don't use red-zone when there are no caller-saved registers with SSE. (ix86_type_no_callee_saved_registers_p): New. (ix86_function_ok_for_sibcall): Also check TYPE_PRESERVE_NONE and call ix86_type_no_callee_saved_registers_p instead of looking up no_callee_saved_registers attribute. (ix86_comp_type_attributes): Call ix86_type_no_callee_saved_registers_p instead of looking up no_callee_saved_registers attribute. Return 0 if preserve_none attribute doesn't match in 64-bit mode. (ix86_function_arg_regno_p): For cfun with TYPE_PRESERVE_NONE, use x86_64_preserve_none_int_parameter_registers. (init_cumulative_args): Set preserve_none_abi. (function_arg_64): Use x86_64_preserve_none_int_parameter_registers with preserve_none attribute. (setup_incoming_varargs_64): Use x86_64_preserve_none_int_parameter_registers with preserve_none attribute. (ix86_save_reg): Treat TYPE_PRESERVE_NONE like TYPE_NO_CALLEE_SAVED_REGISTERS. (ix86_nsaved_sseregs): Allow saving XMM registers for no_caller_saved_registers attribute. (ix86_compute_frame_layout): Likewise. (x86_this_parameter): Use x86_64_preserve_none_int_parameter_registers with preserve_none attribute. * config/i386/i386.h (ix86_args): Add preserve_none_abi. (call_saved_registers_type): Add TYPE_PRESERVE_NONE. (machine_function): Change call_saved_registers to 3 bits. * doc/extend.texi: Add preserve_none attribute. Update no_caller_saved_registers attribute to remove -mgeneral-regs-only restriction. gcc/testsuite/ PR target/119628 * gcc.target/i386/no-callee-saved-3.c: Adjust error location. * gcc.target/i386/no-callee-saved-19a.c: New test. * 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/preserve-none-1.c: Likewise. * gcc.target/i386/preserve-none-2.c: Likewise. * gcc.target/i386/preserve-none-3.c: Likewise. * gcc.target/i386/preserve-none-4.c: Likewise. * gcc.target/i386/preserve-none-5.c: Likewise. * gcc.target/i386/preserve-none-6.c: Likewise. * gcc.target/i386/preserve-none-7.c: Likewise. * gcc.target/i386/preserve-none-8.c: Likewise. * gcc.target/i386/preserve-none-9.c: Likewise. * gcc.target/i386/preserve-none-10.c: Likewise. * gcc.target/i386/preserve-none-11.c: Likewise. * gcc.target/i386/preserve-none-12.c: Likewise. * gcc.target/i386/preserve-none-13.c: Likewise. * gcc.target/i386/preserve-none-14.c: Likewise. * gcc.target/i386/preserve-none-15.c: Likewise. * gcc.target/i386/preserve-none-16.c: Likewise. * gcc.target/i386/preserve-none-17.c: Likewise. * gcc.target/i386/preserve-none-18.c: Likewise. * gcc.target/i386/preserve-none-19.c: Likewise. * gcc.target/i386/preserve-none-20.c: Likewise. * gcc.target/i386/preserve-none-21.c: Likewise. * gcc.target/i386/preserve-none-22.c: Likewise. * gcc.target/i386/preserve-none-23.c: Likewise. * gcc.target/i386/preserve-none-24.c: Likewise. * gcc.target/i386/preserve-none-25.c: Likewise. * gcc.target/i386/preserve-none-26.c: Likewise. * gcc.target/i386/preserve-none-27.c: Likewise. * gcc.target/i386/preserve-none-28.c: Likewise. * gcc.target/i386/preserve-none-29.c: Likewise. * gcc.target/i386/preserve-none-30a.c: Likewise. * gcc.target/i386/preserve-none-30b.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-06-25x86: Update -mtune=intel for Diamond Rapids/Clearwater ForestH.J. Lu1-2/+2
-mtune=intel is used to generate a single binary to run well on both big core and small core, similar to hybrid CPUs. Update -mtune=intel to tune for Diamond Rapids and Clearwater Forest, instead of Silvermont. PR target/120815 * common/config/i386/i386-common.cc (processor_alias_table): Replace CPU_SLM/PTA_NEHALEM with CPU_HASWELL/PTA_HASWELL for PROCESSOR_INTEL. * config/i386/i386-options.cc (processor_cost_table): Replace intel_cost with alderlake_cost. * config/i386/x86-tune-costs.h (intel_cost): Removed. * config/i386/x86-tune-sched.cc (ix86_issue_rate): Treat PROCESSOR_INTEL like PROCESSOR_ALDERLAKE. (ix86_adjust_cost): Likewise. * doc/invoke.texi: Update -mtune=intel for Diamond Rapids and Clearwater Forest. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-06-25i386: Remove CLDEMOTE for clientsHaochen Jiang1-15/+14
CLDEMOTE is not enabled on clients according to SDM. SDM only mentioned it will be enabled on Xeon and Atom servers, not clients. Remove them since Alder Lake (where it is introduced). gcc/ChangeLog: * config/i386/i386.h (PTA_ALDERLAKE): Use PTA_GOLDMONT_PLUS as base to remove PTA_CLDEMOTE. (PTA_SIERRAFOREST): Add PTA_CLDEMOTE since PTA_ALDERLAKE does not include that anymore. * doc/invoke.texi: Update texi file.
2025-06-25Add -fauto-profile-inliningJan Hubicka1-1/+7
this patch adds -fauto-profile-inlining which can be used to control the auto-profile directed inlning. gcc/ChangeLog: * common.opt: (fauto-profile-inlining): New * doc/invoke.texi (-fauto-profile-inlining): Document. * ipa-inline.cc (inline_functions_by_afdo): Check flag_auto_profile. (early_inliner): Also do inline_functions_by_afdo with !flag_early_inlining.
2025-06-24AArch64: promote aarch64-autovec-peference to mautovec-preferenceTamar Christina1-14/+24
As requested in my patch for -mmax-vectorization this promotes the parameter --param aarch64-autovec-preference to a first class top target flag. If both the parameter and the flag is specified the parameter takes precedence with the reasoning that it may already be embedded in build systems. gcc/ChangeLog: * config/aarch64/aarch64.cc (aarch64_override_options_internal): Set value of parameter based on option. * config/aarch64/aarch64.opt (autovec-preference): New. * doc/invoke.texi (autovec-preference): Document it. gcc/testsuite/ChangeLog: * gcc.target/aarch64/autovec_param_asimd-only_2.c: New test. * gcc.target/aarch64/autovec_param_default_2.c: New test. * gcc.target/aarch64/autovec_param_prefer-asimd_2.c: New test. * gcc.target/aarch64/autovec_param_prefer-sve_2.c: New test. * gcc.target/aarch64/autovec_param_sve-only_2.c: New test.
2025-06-24AArch64: propose -mmax-vectorization as an option to override vector costingTamar Christina2-0/+19
With the middle-end providing a way to make vectorization more profitable by scaling vect-scalar-cost-multiplier this makes a more user friendly option to make it easier to use. I propose making it an actual -m option that we document and retain vs using the parameter name. In the future I would like to extend this option to modify additional costing in the AArch64 backend itself. This can be used together with --param aarch64-autovec-preference to get the vectorizer to say, always vectorize with SVE. I did consider making this an additional enum to --param aarch64-autovec-preference but I also think this is a useful thing to be able to set with pragmas and attributes, but am open to suggestions. Note that as a follow up I plan on extending -fdump-tree-vect to support -stats which is then intended to be usable with this flag. gcc/ChangeLog: * config/aarch64/aarch64.opt (max-vectorization): New. * config/aarch64/aarch64.cc (aarch64_override_options_internal): Save and restore option. Implement it through vect-scalar-cost-multiplier. (aarch64_attributes): Default to off. * common/config/aarch64/aarch64-common.cc (aarch64_handle_option): Initialize option. * doc/extend.texi (max-vectorization): Document attribute. * doc/invoke.texi (max-vectorization): Document flag. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/cost_model_17.c: New test. * gcc.target/aarch64/sve/cost_model_18.c: New test.
2025-06-24middle-end: Apply loop->unroll directly in vectorizerTamar Christina1-0/+5
Consider the loop void f1 (int *restrict a, int n) { #pragma GCC unroll 4 requested for (int i = 0; i < n; i++) a[i] *= 2; } Which today is vectorized and then unrolled 3x by the RTL unroller due to the use of the pragma. This is unfortunate because the pragma was intended for the scalar loop but we end up with an unrolled vector loop and a longer path to the entry which has a low enough VF requirement to enter. This patch instead seeds the suggested_unroll_factor with the value the user requested and instead uses it to maintain the total VF that the user wanted the scalar loop to maintain. In effect it applies the unrolling inside the vector loop itself. This has the benefits for things like reductions, as it allows us to split the accumulator and so the unrolled loop is more efficient. For early-break it allows the cbranch call to be shared between the unrolled elements, giving you more effective unrolling because it doesn't need the repeated cbranch which can be expensive. The target can then choose to create multiple epilogues to deal with the "rest". The example above now generates: .L4: ldr q31, [x2] add v31.4s, v31.4s, v31.4s str q31, [x2], 16 cmp x2, x3 bne .L4 as V4SI maintains the requested VF, but e.g. pragma unroll 8 generates: .L4: ldp q30, q31, [x2] add v30.4s, v30.4s, v30.4s add v31.4s, v31.4s, v31.4s stp q30, q31, [x2], 32 cmp x3, x2 bne .L4 gcc/ChangeLog: * doc/extend.texi: Document pragma unroll interaction with vectorizer. * tree-vectorizer.h (LOOP_VINFO_USER_UNROLL): New. (class _loop_vec_info): Add user_unroll. * tree-vect-loop.cc (vect_analyze_loop_1): Set suggested_unroll_factor and retry. (_loop_vec_info::_loop_vec_info): Initialize user_unroll. (vect_transform_loop): Clear the loop->unroll value if the pragma was used. gcc/testsuite/ChangeLog: * gcc.target/aarch64/unroll-vect.c: New test.