aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2025-05-15OpenMP/Fortran: 'target update' with strides + DT componentsTobias Burnus1-2/+7
OpenMP 5.0 permits to use arrays with strides and derived type components for the list items to the 'from'/'to' clauses of the 'target update' directive. Partially committed to mainline as: 6629444170f85 OpenMP/Fortran: 'target update' with DT components This patch contains the differences to the mainline version. gcc/fortran/ChangeLog: * openmp.cc (resolve_omp_clauses): Apply to OpenMP target update. libgomp/ChangeLog: * testsuite/libgomp.fortran/target-13.f90: Update test.
2025-05-15vect: WORKAROUND vectorizer bugAndrew Stubbs1-1/+15
This patch disables vectorization of memory accesses to non-default address spaces where the pointer size is different to the usual pointer size. This condition typically occurs in OpenACC programs on amdgcn, where LDS memory is used for broadcasting gang-private variables between threads. In particular, see libgomp.oacc-c-c++-common/private-variables.c The problem is that the address space information is dropped from the various types in the middle-end and eventually it triggers an ICE trying to do an address conversion. That ICE can be avoided by defining POINTERS_EXTEND_UNSIGNED, but that just produces wrong RTL code later on. A correct solution would ensure that all the vectypes have the correct address spaces, but I don't have time for that right now. gcc/ChangeLog: * tree-vect-data-refs.cc (vect_analyze_data_refs): Workaround an address-space bug.
2025-05-15OpenMP: Add uses_allocators supportTobias Burnus22-20/+1063
This adds middle end support for uses_allocators, wires Fortran to use it and add C/C++ parsing support. gcc/ChangeLog: * builtin-types.def (BT_FN_VOID_PTRMODE): Add. (BT_FN_PTRMODE_PTRMODE_INT_PTR): Add. * gimplify.cc (gimplify_bind_expr): Diagnose missing uses_allocators clause. (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_workshare): Handle uses_allocators. * omp-builtins.def (BUILT_IN_OMP_INIT_ALLOCATOR, BUILT_IN_OMP_DESTROY_ALLOCATOR): Add. * omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_USES_ALLOCATORS and OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR clauses. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_USES_ALLOCATORS. * tree.cc (omp_clause_num_ops, omp_clause_code_name): Likewise. * tree-pretty-print.cc (dump_omp_clause): Handle it. * tree.h (OMP_CLAUSE_USES_ALLOCATORS_ALLOCATOR, OMP_CLAUSE_USES_ALLOCATORS_MEMSPACE, OMP_CLAUSE_USES_ALLOCATORS_TRAITS): New. gcc/c-family/ChangeLog: * c-omp.cc (c_omp_split_clauses): Hande uses_allocators. * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_USES_ALLOCATORS. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_uses_allocators): New. (c_parser_omp_clause_name, c_parser_omp_all_clauses, OMP_TARGET_CLAUSE_MASK): Handle uses_allocators. * c-typeck.cc (c_finish_omp_clauses): Likewise. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_clause_uses_allocators): New. (cp_parser_omp_clause_name, cp_parser_omp_all_clauses, OMP_TARGET_CLAUSE_MASK): Handle uses_allocators. * semantics.cc (finish_omp_clauses): Likewise. gcc/fortran/ChangeLog: * trans-array.cc (gfc_conv_array_initializer): Set PURPOSE when building constructor for get_initialized_tmp_var. * trans-openmp.cc (gfc_trans_omp_clauses): Handle uses_allocators. * types.def (BT_FN_VOID_PTRMODE, BT_FN_PTRMODE_PTRMODE_INT_PTR): Add. libgomp/ChangeLog: * testsuite/libgomp.c++/c++.exp (check_effective_target_c, check_effective_target_c++): Add. * testsuite/libgomp.c/c.exp (check_effective_target_c, check_effective_target_c++): Add. * testsuite/libgomp.fortran/uses_allocators_2.f90: Remove 'sorry'. * testsuite/libgomp.c-c++-common/uses_allocators-1.c: New test. * testsuite/libgomp.c-c++-common/uses_allocators-2.c: New test. * testsuite/libgomp.c-c++-common/uses_allocators-3.c: New test. * testsuite/libgomp.c-c++-common/uses_allocators-4.c: New test. * testsuite/libgomp.fortran/uses_allocators_3.f90: New test. * testsuite/libgomp.fortran/uses_allocators_4.f90: New test. * testsuite/libgomp.fortran/uses_allocators_5.f90: New test. * testsuite/libgomp.fortran/uses_allocators_6.f90: New test. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-1.f90: Add uses_allocators. * gfortran.dg/gomp/scope-6.f90: Update dg-scan-tree-dump. * c-c++-common/gomp/uses_allocators-1.c: New test. * c-c++-common/gomp/uses_allocators-2.c: New test. * gfortran.dg/gomp/uses_allocators-1.f90: New test.
2025-05-15omp-oacc-kernels-decompose.cc: fix -fcompare-debug with GIMPLE_DEBUGTobias Burnus7-28/+29
GIMPLE_DEBUG were put in a parallel region of its own, which is not only pointless but also breaks -fcompare-debug. With this commit, they are handled like simple assignments: those placed are places into the same body as the loop such that only one parallel region remains as without debugging. This fixes the existing testcase libgomp.oacc-c-c++-common/kernels-loop-g.c. Note: GIMPLE_DEBUG are only accepted with -fcompare-debug; if they appear otherwise, decompose_kernels_region_body rejects them with a sorry (unchanged). Also note that there are still many xfailed tests in the c-c++-common/goacc/kernels-decompose-pr* testcases that were added in mainline commit c14ea6a72fb1ae66e3d32ac8329558497c6e4403. gcc/ChangeLog * omp-oacc-kernels-decompose.cc (top_level_omp_for_in_stmt, decompose_kernels_region_body): Handle GIMPLE_DEBUG like simple assignment. gcc/testsuite/ChangeLog * c-c++-common/goacc/kernels-decompose-pr103836-1-2.c: Adjust xfails. * c-c++-common/goacc/kernels-decompose-pr103836-1-3.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr103836-1-4.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104061-1-2.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104061-1-3.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104061-1-4.c: Likewise. Co-Authored-By: Sandra Loosemore <sloosemore@baylibre.com>
2025-05-15openmp: -foffload-memory=pinnedAndrew Stubbs2-0/+69
https://patchwork.sourceware.org/project/gcc/list/?series=35022 Implement the -foffload-memory=pinned option such that libgomp is instructed to enable fully-pinned memory at start-up. The option is intended to provide a performance boost to certain offload programs without modifying the code. This feature only works on Linux, at present, and simply calls mlockall to enable always-on memory pinning. It requires that the ulimit feature is set high enough to accommodate all the program's memory usage. In this mode the ompx_gnu_pinned_memory_alloc feature is disabled as it is not needed and may conflict. gcc/ChangeLog: * omp-builtins.def (BUILT_IN_GOMP_ENABLE_PINNED_MODE): New. * omp-low.cc (omp_enable_pinned_mode): New function. (execute_lower_omp): Call omp_enable_pinned_mode. libgomp/ChangeLog: * config/linux/allocator.c (always_pinned_mode): New variable. (GOMP_enable_pinned_mode): New function. (linux_memspace_alloc): Disable pinning when always_pinned_mode set. (linux_memspace_calloc): Likewise. (linux_memspace_free): Likewise. (linux_memspace_realloc): Likewise. * libgomp.map: Add GOMP_enable_pinned_mode. * testsuite/libgomp.c/alloc-pinned-7.c: New test. * testsuite/libgomp.c-c++-common/alloc-pinned-1.c: New test.
2025-05-15openmp: Add -foffload-memoryAndrew Stubbs3-0/+38
https://patchwork.sourceware.org/project/gcc/list/?series=35022 Add a new option. It's inactive until I add some follow-up patches. gcc/ChangeLog: * common.opt: Add -foffload-memory and its enum values. * coretypes.h (enum offload_memory): New. * doc/invoke.texi: Document -foffload-memory.
2025-05-15openmp: Scale type precision of collapsed iterator variableKwok Cheung Yeung2-13/+31
This sets the type precision of the collapsed iterator variable to the sum of the precision of the collapsed loop variables, up to a maximum of sizeof(long long) (i.e. 64-bits). gcc/ChangeLog * omp-expand.cc (expand_oacc_for): Convert .tile variable to diff_type before multiplying. * omp-general.cc (omp_extract_for_data): Use accumulated precision of all collapsed for-loops as precision of iteration variable, up to the precision of a long long. libgomp/ChangeLog * testsuite/libgomp.c-c++-common/collapse-4.c: New. * testsuite/libgomp.fortran/collapse5.f90: New.
2025-05-15OpenMP 5.0: Allow multiple clauses mapping same variableChung-Lin Tang5-34/+65
This is a merge of: https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562081.html This patch now allows multiple clauses on the same construct to map the same variable, which was not valid in OpenMP 4.5, but now allowed in 5.0. This may possibly reverted/updated when a final patch is approved for mainline. gcc/c/ChangeLog * c-typeck.cc (c_finish_omp_clauses): Adjust to allow duplicate mapped variables for OpenMP. gcc/cp/ChangeLog * semantics.cc (finish_omp_clauses): Adjust to allow duplicate mapped variables for OpenMP. gcc/ChangeLog * omp-low.cc (install_var_field): Add new 'tree key_expr = NULL_TREE' default parameter. Set splay-tree lookup key to key_expr instead of var if key_expr is non-NULL. Adjust call to install_parm_decl. Update comments. (scan_sharing_clauses): Use clause tree expression as splay-tree key for map/to/from and OpenACC firstprivate cases when installing the variable field into the send/receive record type. (maybe_lookup_field_in_outer_ctx): Add code to search through construct clauses instead of entirely based on splay-tree lookup. (lower_oacc_reductions): Adjust to find map-clause of reduction variable, then create receiver-ref. (lower_omp_target): Adjust to lookup var field using clause expression. gcc/testsuite/ChangeLog * c-c++-common/gomp/clauses-2.c: Adjust testcase. * c-c++-common/gomp/map-6.c: Adjust testcase. Co-Authored-By: Paul-Antoine Arras <parras@baylibre.com>
2025-05-15DWARF address space for variablesAndrew Stubbs1-0/+9
Add DWARF address class attributes for variables that exist outside the generic address space. In particular, this is the case for gang-private variables in OpenACC offload kernels. gcc/ChangeLog: * dwarf2out.cc (add_location_or_const_value_attribute): Set DW_AT_address_class, if appropriate.
2025-05-15DWARF: late code range fixupAndrew Stubbs1-2/+59
Ensure that the parent DWARF subprograms of offload kernel functions have a code range, and are therefore not discarded by GDB. This is only necessary when the parent function does not actually exist in the final binary, which is commonly the case within the offload device's binary. gcc/ * dwarf2out.cc (notional_parents_list): New file variable. (gen_subprogram_die): Record offload kernel functions in notional_parents_list. (fixup_notional_parents): New function. (dwarf2out_finish): Call fixup_notional_parents. (dwarf2out_c_finalize): Reset notional_parents_list.
2025-05-15openacc: Adjust loop lowering for AMD GCNJulian Brown1-35/+124
This patch adjusts OpenACC loop lowering in the AMD GCN target compiler in such a way that the autovectorizer can vectorize the "vector" dimension of those loops in more cases. Rather than generating "SIMT" code that executes a scalar instruction stream for each lane of a vector in lockstep, for GCN we model the GPU like a typical CPU, with separate instructions to operate on scalar and vector data. That means that unlike other offload targets, we rely on the autovectorizer to handle the innermost OpenACC parallelism level, which is "vector". Because of this, the OpenACC builtin functions to return the current vector lane and the vector width return 0 and 1 respectively, despite the native vector width being 64 elements wide. This allows generated code to work with our chosen compilation model, but the way loops are lowered in omp-offload.c:oacc_xform_loop does not understand the discrepancy between logical (OpenACC) and physical vector sizes correctly. That means that if a loop is partitioned over e.g. the worker AND vector dimensions, we actually lower with unit vector size -- meaning that if we then autovectorize, we end up trying to vectorize over the "worker" dimension rather than the vector one! Then, because the number of workers is not fixed at compile time, that means the autovectorizer has a hard time analysing the loop and thus vectorization often fails entirely. We can fix this by deducing the true vector width in oacc_xform_loop, and using that when we are on a "non-SIMT" offload target. We can then rearrange how loops are lowered in that function so that the loop form fed to the autovectorizer is more amenable to vectorization -- namely, the innermost step is set to process each loop iteration sequentially. For some benchmarks, allowing vectorization to succeed leads to quite impressive performance improvements -- I've observed between 2.5x and 40x on one machine/GPU combination. The low-level builtins available to user code (__builtin_goacc_parlevel_id and __builtin_goacc_parlevel_size) continue to return 0/1 respectively for the vector dimension for AMD GCN, even if their containing loop is vectorized -- that's a quirk that we might possibly want to address at some later date. Only non-"chunking" loops are handled at present. "Chunking" loops are still lowered as before. gcc/ChangeLog * omp-offload.cc (oacc_thread_numbers): Add VF_BY_VECTORIZER parameter. Add overloaded wrapper for previous arguments & behaviour. (oacc_xform_loop): Lower vector loops to iterate a multiple of omp_max_vf times over contiguous steps on non-SIMT targets. libgomp/ChangeLog * testsuite/libgomp.oacc-c-c++-common/loop-gwv-1.c: Adjust for loop lowering changes. * testsuite/libgomp.oacc-c-c++-common/loop-wv-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/loop-red-gwv-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/loop-red-wv-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/routine-gwv-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/routine-wv-1.c: Likewise.
2025-05-15Fortran "declare create"/allocate support for OpenACCCesar Philippidis11-29/+183
This patch incorporates these commits from OG14 branch: 65be1389eeda9b3b97f6587721215c3f31bd7f98 9d43e819d88f97c7ade7f8c95c35ea3464ea7771 f2cf2b994c4d8c871fad5502ffb9aaee9ea4f4e0 2770ce41615557e595065ce0c5db71e9f3d82b0a a29e58f4b314862a72730119f85e9125879abf0b ffd990543f805ed448aaa355d190f37103f8f1f0 gcc/ChangeLog * gimplify.cc (omp_group_base): Handle GOMP_MAP_DECLARE_ALLOCATE and GOMP_MAP_DECLARE_DEALLOCATE. (gimplify_adjust_omp_clauses): Likewise. * omp-low.cc (scan_sharing_clauses): Update handling of OpenACC declare create, declare copyin and declare deviceptr to have local lifetimes. (convert_to_firstprivate_int): Handle pointer types. (convert_from_firstprivate_int): Likewise. Create local storage for the values being pointed to. Add new orig_type argument. Use VIEW_CONVERT also for vectors. (lower_omp_target): Handle GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}. Add orig_type argument to convert_from_firstprivate_int call. Allow pointer types with GOMP_MAP_FIRSTPRIVATE_INT. Don't privatize firstprivate VLAs. * tree-pretty-print.cc (dump_omp_clause): Handle GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE}. gcc/fortran/ChangeLog * gfortran.h (enum gfc_omp_map_op): Add OMP_MAP_DECLARE_ALLOCATE, OMP_MAP_DECLARE_DEALLOCATE. (gfc_omp_clauses): Add update_allocatable. * trans-array.cc (gfc_array_allocate): Call gfc_trans_oacc_declare_allocate for decls that have oacc_declare_create attribute set. * trans-decl.cc (find_module_oacc_declare_clauses): Relax oacc_declare_create to OMP_MAP_ALLOC, and oacc_declare_copyin to OMP_MAP_TO, in order to match OpenACC 2.5 semantics. * trans-openmp.cc (gfc_omp_check_optional_argument): Handle non-decl case. (gfc_trans_omp_clauses): Use GOMP_MAP_ALWAYS_POINTER (for update directive) or GOMP_MAP_FIRSTPRIVATE_POINTER (otherwise) for allocatable scalar decls. Handle OMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE} clauses. (gfc_trans_oacc_executable_directive): Use GOMP_MAP_ALWAYS_POINTER for allocatable scalar data clauses inside acc update directives. (gfc_trans_oacc_declare_allocate): New function. * trans-stmt.cc (gfc_trans_allocate): Call gfc_trans_oacc_declare_allocate for decls with oacc_declare_create attribute set. (gfc_trans_deallocate): Likewise. * trans.h (gfc_trans_oacc_declare_allocate): Declare. gcc/testsuite/ChangeLog * gfortran.dg/goacc/declare-allocatable-1.f90: New test. * gfortran.dg/goacc/declare-3.f95: Adjust expected dump output. include/ChangeLog * gomp-constants.h (enum gomp_map_kind): Define GOMP_MAP_DECLARE_{ALLOCATE,DEALLOCATE} and GOMP_MAP_FLAG_SPECIAL_4. libgomp/ChangeLog * libgomp.h (gomp_acc_declare_allocate): Remove prototype. * oacc-mem.c (gomp_acc_declare_allocate): New function. (find_group_last): Handle GOMP_MAP_DECLARE_ALLOCATE and GOMP_MAP_DECLARE_DEALLOCATE groupings. (goacc_enter_data_internal): Fix kind check for GOMP_MAP_DECLARE_ALLOCATE. Pass new pointer argument to gomp_acc_declare_allocate. Unlock mutex before calling gomp_acc_declare_allocate and relock it afterwards. (goacc_exit_data_internal): Unlock device mutex around gomp_acc_declare_allocate call. Pass new pointer argument. Handle group pointer mapping for deallocate. * testsuite/libgomp.oacc-fortran/allocatable-scalar.f90: New test. * testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90: Adjust. * testsuite/libgomp.oacc-fortran/declare-allocatable-1-runtime.f90: Likewise. * testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90: Likewise. * testsuite/libgomp.oacc-fortran/declare-allocatable-2.f90: New test. * testsuite/libgomp.oacc-fortran/declare-allocatable-3.f90: New test. * testsuite/libgomp.oacc-fortran/declare-allocatable-4.f90: New test. * testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-directive.f90: Adjust. * testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime.f90: Likewise. * testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1.f90: New test. Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com> Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Paul-Antoine Arras <parras@baylibre.com>
2025-05-15Handle references in OpenACC "private" clausesJulian Brown3-10/+24
Combination of OG14 commits 141a592bf147c91c28de7864fa12259687e827e3 8d7562192cc814c6d0d48b424d7751762871a37b + new testsuite fixes to add xfails for tests that already failed on OG14. gcc/ChangeLog * gimplify.cc (localize_reductions): Rewrite references for OMP_CLAUSE_PRIVATE also. Do not create local variable for privatized arrays as the size is not directly known by the type. gcc/testsuite/ChangeLog * gfortran.dg/goacc/privatization-1-compute-loop.f90: Add xfails. * gfortran.dg/goacc/privatization-1-compute.f90: Likewise. libgomp/ChangeLog * testsuite/libgomp.oacc-c++/privatized-ref-3.C: Add xfails. * testsuite/libgomp.oacc-fortran/optional-private.f90: Likewise. * testsuite/libgomp.oacc-fortran/privatized-ref-1.f95: Likewise. Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> Co-Authored-By: Sandra Loosemore <sandra@baylibre.com>
2025-05-15Reference reduction localizationCesar Philippidis6-37/+121
gcc/ChangeLog * gimplify.cc (privatize_reduction): New struct. (localize_reductions_r, localize_reductions): New functions. (gimplify_omp_for): Call localize_reductions. (gimplify_omp_workshare): Likewise. * omp-low.cc (lower_oacc_reductions): Handle localized reductions. Create fewer temp vars. * tree-core.h (omp_clause_code): Add OMP_CLAUSE_REDUCTION_PRIVATE_DECL documentation. * tree.cc (omp_clause_num_ops): Bump number of ops for OMP_CLAUSE_REDUCTION to 6. (walk_tree_1): Adjust accordingly. * tree.h (OMP_CLAUSE_REDUCTION_PRIVATE_DECL): Add macro. gcc/testsuite/ChangeLog * gfortran.dg/goacc/modules.f95: Remove xfail on bogus warnings. libgomp/ChangeLog * testsuite/libgomp.oacc-fortran/optional-reduction.f90: Remove xfail on bogus warnings. * testsuite/libgomp.oacc-fortran/parallel-reduction.f90: Likewise. * testsuite/libgomp.oacc-fortran/pr70643.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-5.f90: Likewise. * testsuite/libgomp.oacc-fortran/reduction-7.f90: Likewise. * testsuite/libgomp.oacc-fortran/reference-reductions.f90: Likewise. Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: Sandra Loosemore <sloosemore@baylibre.com>
2025-05-15Enable firstprivate OpenACC reductionsCesar Philippidis2-7/+105
gcc/ChangeLog * gimplify.cc (omp_add_variable): Enable firstprivate reduction variables. gcc/testsuite/ChangeLog * c-c++-common/goacc/reduction-10.c: New test. libgomp/ChangeLog * testsuite/libgomp.oacc-c-c++-common/privatize-reduction-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/privatize-reduction-2.c: New test. Co-Authored-By: Chung-Lin Tang <cltang@codesourcery.com>
2025-05-15Don't mark OpenACC auto loops as independent inside acc parallel regionsCesar Philippidis6-30/+198
gcc/ChangeLog * omp-low.cc (lower_oacc_head_mark): Don't mark OpenACC auto loops as independent inside acc parallel regions. gcc/testsuite/ChangeLog * c-c++-common/goacc/loop-auto-1.c: Adjust test case to conform to the new behavior of the auto clause in OpenACC 2.5. * c-c++-common/goacc/loop-auto-2.c: Likewise. * gcc.dg/goacc/loop-processing-1.c: Likewise. * c-c++-common/goacc/loop-auto-3.c: New test. * gfortran.dg/goacc/loop-auto-1.f90: New test. libgomp/ChangeLog * testsuite/libgomp.oacc-c-c++-common/loop-auto-1.c: Adjust test case to conform to the new behavior of the auto clause in OpenACC 2.5.
2025-05-15Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACCCesar Philippidis1-12/+135
Incorporates these commits from OG14 branch: a743b0947593f38fd93fa1bc5f8dd3c50ba5c498 6f759e76f00d70bf1d44a25767c73ec2de855452 61d66e2e494655a34cca7289ae584d2644f1a65f gcc/ChangeLog * omp-low.cc (maybe_lookup_field_in_outer_ctx): New function. (convert_to_firstprivate_int): New function. (convert_from_firstprivate_int): New function. (lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in OpenACC. Remove unused variable. libgomp/ChangeLog * testsuite/libgomp.oacc-c++/firstprivate-int.C: New test. * testsuite/libgomp.oacc-c-c++-common/firstprivate-int.c: New test. * testsuite/libgomp.oacc-c-c++-common/data-firstprivate-1.c: XFAIL execution test. * testsuite/libgomp.oacc-fortran/firstprivate-int.f90: New test. Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
2025-05-15Default compute dimensions (compile time)Nathan Sidwell2-10/+21
This patch was previously combined with an unrelated change and testcases that was upstreamed separately ("Add '-Wopenacc-parallelism'", 22cff118f7526bec195ed6e41452980820fdf3a8). gcc/ChangeLog * doc/invoke.texi (fopenacc-dim): Document syntax for using runtime value from environment variable. * omp-offload.cc (oacc_parse_default_dims): Implement it. libgomp/ChangeLog * testsuite/libgomp.oacc-c-c++-common/loop-default-compile.c: New. Co-Authored-By: Tom de Vries <tdevries@suse.de> Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Julian Brown <julian@codesourcery.com>
2025-05-15Adjustments and additions to testcasesCesar Philippidis3-0/+136
gcc/testsuite/ChangeLog * g++.dg/goacc/loop-1.c: New test. * g++.dg/goacc/loop-2.c: New test. * g++.dg/goacc/loop-3.c: New test. libgomp/ChangeLog * testsuite/libgomp.oacc-fortran/data-3.f90: Update parallel regions to denote variables copyied in via acc enter data as present. * testsuite/libgomp.oacc-c-c++-common/subr.h: Reimplement. * testsuite/libgomp.oacc-c-c++-common/subr.ptx: Regenerated PTX. * testsuite/libgomp.oacc-c-c++-common/timer.h: Removed. * testsuite/libgomp.oacc-c-c++-common/lib-69.c: Change async checks. * testsuite/libgomp.oacc-c-c++-common/lib-70.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-72.c: Rework kernel i/f and change async checks. * testsuite/libgomp.oacc-c-c++-common/lib-73.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-74.c: Rework kernel i/f and timing checks. * testsuite/libgomp.oacc-c-c++-common/lib-75.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-76.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-78.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-79.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-81.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-82.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/lib-93.c: New test. Co-Authored-By: James Norris <jnorris@codesourcery.com> Co-Authored-By: Tom de Vries <tom@codesourcery.com> Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: Tobias Burnus <tburnus@baylibre.com>
2025-05-15Various OpenACC reduction enhancements - test casesJulian Brown3-1/+660
gcc/testsuite/ChangeLog * c-c++-common/goacc/reduction-9.c: New. * g++.dg/goacc/reductions-1.C: New. * gcc.dg/goacc/loop-processing-1.c: Update. libgomp/ChangeLog * testsuite/libgomp.oacc-c-c++-common/par-reduction-3.c: New. * testsuite/libgomp.oacc-c-c++-common/reduction-cplx-flt-2.c: New. * testsuite/libgomp.oacc-fortran/reduction-9.f90: New. Co-Authored-By: Cesar Philippidis <cesar@codesourcery.com> Co-Authored-By: Nathan Sidwell <nathan@acm.org>
2025-05-15Various OpenACC reduction enhancements - ME and nvptx changesJulian Brown5-29/+257
gcc/ChangeLog * config/nvptx/nvptx.cc (nvptx_propagate_unified): New. (nvptx_split_blocks): Call it for cond_uni insn. (nvptx_expand_cond_uni): New. (enum nvptx_builtins): Add NVPTX_BUILTIN_COND_UNI. (nvptx_init_builtins): Initialize it. (nvptx_expand_builtin): Handle NVPTX_BUILTIN_COND_UNI. (nvptx_generate_vector_shuffle): Change integral SHIFT operand to tree BITS operand. (nvptx_vector_reduction): New. (nvptx_adjust_reduction_type): New. (nvptx_goacc_reduction_setup): Use it to adjust the type of ref_to_res. (nvptx_goacc_reduction_init): Don't update LHS if it doesn't exist. (nvptx_goacc_reduction_fini): Call nvptx_vector_reduction for vector. Use it to adjust the type of ref_to_res. (nvptx_goacc_reduction_teardown): Call nvptx_adjust_reduction_type. * config/nvptx/nvptx.md (cond_uni): New pattern. * gimplify.cc (gimplify_adjust_omp_clauses): Add DECL_P check for OMP_CLAUSE_TASK_REDUCTION. * omp-low.cc (lower_oacc_reductions): Handle GOMP_MAP_FIRSTPRIVATE_POINTER. * omp-offload.cc (default_goacc_reduction): Likewise. Co-Authored-By: Cesar Philippidis <cesar@codesourcery.com>
2025-05-15Various OpenACC reduction enhancements - FE changesJulian Brown5-41/+57
gcc/c/ChangeLog * c-parser.cc (c_parser_omp_variable_list): New c_omp_region_type argument. Use it to specialize handling of OMP_CLAUSE_REDUCTION for OpenACC. (c_parser_omp_var_list_parens): Add region-type argument to call. (c_parser_oacc_data_clause): Likewise. (c_parser_oacc_data_clause_deviceptr): Likewise. (c_parser_omp_clause_reduction): Change is_omp boolean parameter to c_omp_region_type. Update call to c_parser_omp_variable_list. (c_parser_omp_clause_map): Update call to c_parser_omp_variable_list. (c_parser_omp_clause_from_to): Likewise. (c_parser_omp_clause_init): Likewise. (c_parser_oacc_all_clauses): Update calls to c_parser_omp_clause_reduction. (c_parser_omp_all_clauses): Likewise. (c_parser_oacc_cache): Update call to c_parser_omp_variable_list. * c-typeck.cc (c_finish_omp_clauses): Emit an error on orphan OpenACC gang reductions. Suppress user-defined reduction error for OpenACC. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_var_list_no_open): New c_omp_region_type argument. Use it to specialize handling of OMP_CLAUSE_REDUCTION for OpenACC. (cp_parser_omp_var_list): Add c_omp_region_type argument. Update call to cp_parser_omp_var_list_no_open. (cp_parser_oacc_data_clause): Update call to cp_parser_omp_var_list_no_open. (cp_parser_omp_clause_reduction): Change is_omp boolean parameter to c_omp_region_type. Update call to cp_parser_omp_var_list_no_open. (cp_parser_omp_clause_from_to): Update call to cp_parser_omp_clause_var_list_no_open. (cp_parser_omp_clause_map): Likewise. (cp_parser_omp_clause_init): Likewise. (cp_parser_oacc_all_clauses): Update call to cp_parser_omp_clause_reduction. (cp_parser_omp_all_clauses): Likewise. * semantics.cc (finish_omp_reduction_clause): Add c_omp_region_type argument. Suppress user-defined reduction error for OpenACC. (finish_omp_clauses): Update call to finish_omp_reduction_clause. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_omp_clause_copy_ctor): Permit reductions. Co-Authored-By: Cesar Philippidis <cesar@codesourcery.com> Co-Authored-By: Nathan Sidwell <nathan@acm.org> Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
2025-05-15Add OpenACC Fortran support for deviceptr and variable in common blocksCesar Philippidis12-48/+66
This is a merge of these OG14 commits: 987bb4c25b4076eb54f043644bdf9988378be90d 9e8395708c0027ad1de871bae870c4b0185a74fd 2adb0ec35cd47b34d47c961f6ae46089e3e02cbc 4d29174a9602e6ea783ba0e9a7b1e38fb6913db5 gcc/fortran/ChangeLog * openmp.cc (gfc_match_omp_map_clause): Re-write handling of the deviceptr clause. Add new common_blocks argument. Propagate it to gfc_match_omp_variable_list. (gfc_match_omp_clauses): Update calls to gfc_match_omp_map_clauses. (resolve_positive_int_expr): Promote the warning to an error. (check_array_not_assumed): Remove pointer check. (resolve_oacc_nested_loops): Error on do concurrent loops. * trans-openmp.cc (gfc_omp_finish_clause): Don't create pointer data mappings for deviceptr clauses. (gfc_trans_omp_clauses): Likewise. gcc/ChangeLog * gimplify.cc (enum gimplify_omp_var_data): Add GOVD_DEVICETPR. (oacc_default_clause): Privatize fortran common blocks. (omp_notice_variable): Add GOVD_DEVICEPTR attribute when appropriate. Defer the expansion of DECL_VALUE_EXPR for common block decls. (gimplify_scan_omp_clauses): Add GOVD_DEVICEPTR attribute when appropriate. (gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for implicit deviceptr mappings. gcc/testsuite/ChangeLog * c-c++-common/goacc/deviceptr-4.c: Update. * gfortran.dg/goacc/loop-2-kernels-tile.f95: Update. * gfortran.dg/goacc/loop-2-parallel-tile.f95: Update. * gfortran.dg/goacc/loop-2-serial-tile.f95: Update. * gfortran.dg/goacc/sie.f95: Update. * gfortran.dg/goacc/tile-1.f90: Update. * gfortran.dg/gomp/num-teams-2.f90: Update. * gfortran.dg/gomp/pr67500.f90: Update. * gfortran.dg/gomp/pr77516.f90: Update. libgomp/ChangeLog * oacc-parallel.c (GOACC_parallel_keyed): Handle Fortran deviceptr clause. (GOACC_data_start): Likewise. * testsuite/libgomp.oacc-fortran/deviceptr-1.f90: New test. Co-Authored-By: James Norris <jnorris@codesourcery.com> Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> Co-Authored-By: Thomas Schwinge <tschwinge@baylibre.com>
2025-05-15Non-contiguous array support patches [PR76739]Chung-Lin Tang13-16/+460
This is based on OG14 commit b143c1c447945ce05903ff1360ead97774dfce4b, which was based from v4, posted upstream here: https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543437.html It also incorporates a number of follow-up bug and bit-rot fixes, OG14 commits e11726d3467543de45448097dde27ba34bf04bfe 87ea4de1c4a360d5d62357491a41811213f4528c 151fc161d0ed640048444ca18f9325e3d2e03e99 628a000bdbf63252c2ede13ccab8e99a19769866 11263c048d39ab1d6a11067b18674bf8307bbbf5 8c1068bbe3e52529bede5466a43af8d98f38dac2 gcc/c/ChangeLog PR other/76739 * c-typeck.cc (handle_omp_array_sections_1): Add 'bool &non_contiguous' parameter, adjust recursive call site, add cases for allowing pointer based multi-dimensional arrays for OpenACC. Reject non-DECL base-pointer cases as unsupported. (handle_omp_array_sections): Adjust handle_omp_array_sections_1 call, handle non-contiguous case to create dynamic array map. gcc/cp/ChangeLog PR other/76739 * semantics.cc (handle_omp_array_sections_1): Add 'bool &non_contiguous' parameter, adjust recursive call site, add cases for allowing pointer based multi-dimensional arrays for OpenACC. Reject non-DECL base-pointer cases as unsupported. (handle_omp_array_sections): Adjust handle_omp_array_sections_1 call, handle non-contiguous case to create dynamic array map. gcc/fortran/ChangeLog PR other/76739 * f95-lang.cc (DEF_FUNCTION_TYPE_VAR_5): New symbol. * types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type. gcc/ChangeLog PR other/76739 * builtin-types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR): New type. * gimplify.cc (omp_group_base): Handle GOMP_MAP_NONCONTIG_ARRAY_*. (gimplify_scan_omp_clauses): Handle OMP_TARGET_UPDATE. (gimplify_adjust_omp_clauses): Skip gimplification of OMP_CLAUSE_SIZE of non-contiguous array maps (which is a TREE_LIST). * omp-builtins.def (BUILT_IN_GOACC_DATA_START): Adjust function type to new BT_FN_VOID_INT_SIZE_PTR_PTR_PTR_VAR. * omp-expand.cc (expand_omp_target): Add non-contiguous array descriptor pointers to variadic arguments. * omp-low.cc (append_field_to_record_type): New function. (create_noncontig_array_descr_type): Likewise. (create_noncontig_array_descr_init_code): Likewise. (scan_sharing_clauses): For non-contiguous array map kinds, check for supported dimension structure, and install non-contiguous array variable into current omp_context. (reorder_noncontig_array_clauses): New function. (scan_omp_target): Call reorder_noncontig_array_clauses to place non-contiguous array map clauses at beginning of clause sequence. (lower_omp_target): Add handling for non-contiguous array map kinds, add all created non-contiguous array descriptors to gimple_omp_target_data_arg. * tree-pretty-print.cc (dump_omp_clause): Handle GOMP_MAP_NONCONTIG_ARRAY_*. gcc/testsuite/ChangeLog PR other/76739 * c-c++-common/goacc/data-clause-1.c (foo): Remove expected message. * c-c++-common/goacc/noncontig_array-1.c: New test. * g++.dg/goacc/data-clause-1.C (foo): Remove expected message. include/ChangeLog PR other/76739 * gomp-constants.h (GOMP_MAP_FLAG_SPECIAL_3): Define. (enum gomp_map_kind): Add GOMP_MAP_NONCONTIG_ARRAY, GOMP_MAP_NONCONTIG_ARRAY_TO, GOMP_MAP_NONCONTIG_ARRAY_FROM, GOMP_MAP_NONCONTIG_ARRAY_TOFROM, GOMP_MAP_NONCONTIG_ARRAY_FORCE_TO, GOMP_MAP_NONCONTIG_ARRAY_FORCE_FROM, GOMP_MAP_NONCONTIG_ARRAY_FORCE_TOFROM, GOMP_MAP_NONCONTIG_ARRAY_ALLOC, GOMP_MAP_NONCONTIG_ARRAY_FORCE_ALLOC, GOMP_MAP_NONCONTIG_ARRAY_FORCE_PRESENT. (GOMP_MAP_NONCONTIG_ARRAY_P): Define. libgomp/ChangeLog PR other/76739 * libgomp.h (gomp_map_vars_openacc): New function declaration. * libgomp_g.h (GOACC_data_start): Add variadic '...' to declaration. * oacc-int.h (struct goacc_ncarray_dim): New struct declaration. (struct goacc_ncarray_descr_type): Likewise. (struct goacc_ncarray): Likewise. (struct goacc_ncarray_info): Likewise. (goacc_noncontig_array_create_ptrblock): New function declaration. * oacc-parallel.c (goacc_noncontig_array_count_rows): New function. (goacc_noncontig_array_compute_sizes): Likewise. (goacc_noncontig_array_fill_rows_1): Likewise. (goacc_noncontig_array_fill_rows): Likewise. (goacc_process_noncontiguous_arrays): Likewise. (goacc_noncontig_array_create_ptrblock): Likewise. (GOACC_parallel_keyed): Use goacc_process_noncontiguous_arrays to handle non-contiguous array descriptors at end of varargs, adjust to use gomp_map_vars_openacc. (GOACC_data_start): Likewise. Adjust function type to accept varargs. * target.c (gomp_map_vars_internal): Add struct goacc_ncarray_info * nca_info parameter, add handling code for non-contiguous arrays. (gomp_map_vars_openacc): Add new function for specialization of gomp_map_vars_internal for OpenACC structured region usage. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-3.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-4.c: New test. * testsuite/libgomp.oacc-c-c++-common/noncontig_array-utils.h: Support header for new tests. Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com> Co-Authored-By: Paul-Antoine Arras <parras@baylibre.com>
2025-05-15Identify OMP development branch in output of 'gcc --version'Sandra Loosemore1-1/+1
gcc/ChangeLog * Makefile.in (REVISION_s): Change default message.
2025-05-15Update gcc zh_CN.poJoseph Myers1-196/+145
* zh_CN.po: Update.
2025-05-15Fix explicit arrays with non-constant size for -fc-prototypes.Thomas Koenig1-0/+2
gcc/fortran/ChangeLog: PR fortran/120139 * dump-parse-tree.cc (get_c_type_name): If no constant size of an array exists, output an asterisk. (cherry picked from commit 4f9c7b5258f2af89bba8e954c277981d2e2ee1ef)
2025-05-15Do not dump non-interoperable types with -fc-prototypes.Thomas Koenig1-2/+3
gcc/fortran/ChangeLog: PR fortran/120107 * dump-parse-tree.cc (write_type): Do not dump non-interoperable types. (cherry picked from commit fa0dff8e99e81bc7a3db1dc57d4fc340e0525b1d)
2025-05-15Daily bump.GCC Administrator5-1/+49
2025-05-14Update gcc sv.poJoseph Myers1-13/+11
* sv.po: Update.
2025-05-14dwarf2out: Propagate dtprel into the .debug_addr table in resolve_addr_in_exprKyle Huey1-1/+2
For a debugger to display statically-allocated[0] TLS variables the compiler must communicate information[1] that can be used in conjunction with knowledge of the runtime enviroment[2] to calculate a location for the variable for each thread. That need gives rise to dw_loc_dtprel in dwarf2out, a flag tracking whether the location description is dtprel, or relative to the "dynamic thread pointer". Location descriptions in the .debug_info section for TLS variables need to be relocated by the static linker accordingly, and dw_loc_dtprel controls emission of the needed relocations. This is further complicated by -gsplit-dwarf. -gsplit-dwarf is designed to allow as much debugging information as possible to bypass the static linker to improve linking performance. One of the ways that is done is by introducing a layer of indirection for relocatable values[3]. That gives rise to addr_index_table which ultimately results in the .debug_addr section. While the code handling addr_index_table clearly contemplates the existence of dtprel entries[4] resolve_addr_in_expr does not, and the result is that when using -gsplit-dwarf the DWARF for TLS variables contains an address[5] rather than an offset, and debuggers can't work with that. This is visible on a trivial example. Compile ``` static __thread int tls_var; int main(void) { tls_var = 42; return 0; } ``` with -g and -g -gsplit-dwarf. Run the program under gdb. When examining the value of tls_var before and after the assignment, -g behaves as one would expect but -g -gsplit-dwarf does not. If the user is lucky and the miscalculated address is not mapped, gdb will print "Cannot access memory at address ...". If the user is unlucky and the miscalculated address is mapped, gdb will simply give the wrong value. You can further confirm that the issue is the address calculation by asking gdb for the address of tls_var and comparing that to what one would expect.[6] Thankfully this is trivial to fix by modifying resolve_addr_in_expr to propagate the dtprel character of the location where necessary. gdb begins working as expected and the diff in the generated assembly is clear. ``` .section .debug_addr,"",@progbits .long 0x14 .value 0x5 .byte 0x8 .byte 0 .Ldebug_addr0: - .quad tls_var + .long tls_var@dtpoff, 0 .quad .LFB0 ``` [0] Referring to e.g. __thread as statically-allocated vs. e.g. a dynamically-allocated pthread_key_create() call. [1] Generally an offset in a TLS block. [2] With glibc, provided by libthread_db.so. [3] Relocatable values are moved to a table in the .debug_addr section, those values in .debug_info are replaced with special values that look up indexes in that table, and then the static linker elsewhere assigns a single per-CU starting index in the .debug_addr section, allowing those special values to remain permanently fixed and the resulting data to be ignored by the linker. [4] ate_kind_rtx_dtprel exists, after all, and new_addr_loc_descr does produce it where appropriate. [5] e.g. an address in the .tbss/.tdata section. [6] e.g. on x86-64 by examining %fsbase and the offset in the assembly 2025-05-01 Kyle Huey <me@kylehuey.com> * dwarf2out.cc (resolve_addr_in_expr): Propagate dtprel into the address table when appropriate.
2025-05-14c++/modules: Fix handling of -fdeclone-ctor-dtor with explicit ↵Nathaniel Shead4-3/+31
instantiations [PR120125] The attached testcase ICEs in maybe_thunk_body because we haven't created a node in the cgraph for an imported explicit instantiation yet. We in fact really shouldn't be emitting calls at all, since an imported explicit instantiation always exists in the TU we imported it from. So this patch adjusts DECL_NOT_REALLY_EXTERN handling to account for this. PR c++/120125 gcc/cp/ChangeLog: * module.cc (trees_out::write_function_def): Only set DECL_NOT_REALLY_EXTERN if the importer might need to emit it. * optimize.cc (maybe_thunk_body): Don't assume 'fn' has a cgraph node created. gcc/testsuite/ChangeLog: * g++.dg/modules/clone-4_a.C: New test. * g++.dg/modules/clone-4_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit d787bc4fd372298e9ed5b11cb3050fd3707070f6)
2025-05-14c++: Fix OpenMP support with C++20 modules [PR119864]Nathaniel Shead2-7/+16
In r15-2799-gf1bfba3a9b3f31, a new kind of global constructor was added. Unfortunately this broke C++20 modules, as both the host and target constructors were given the same mangled name. This patch ensures that only the host constructor gets the module name mangling for now, and stops forcing the creation of the target constructor even when no such initialization is required. PR c++/119864 gcc/cp/ChangeLog: * decl2.cc (start_objects): Only use module initialized for host. (c_parse_final_cleanups): Don't always create an OMP offload init function in modules. gcc/testsuite/ChangeLog: * g++.dg/modules/openmp-1.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com> (cherry picked from commit 79b7e37ea3fbbc43958190f69f6da3be3d809c9c)
2025-05-14Daily bump.GCC Administrator5-1/+175
2025-05-13Do not generate formal arglist from actual if we have already resolved it.Thomas Koenig3-3/+34
This bug was another case of generating a formal arglist from an actual one where we should not have done so. The fix is straightforward: If we have resolved the formal arglist, we should not generare a new one. OK for trunk and backport? gcc/fortran/ChangeLog: PR fortran/120163 * gfortran.h: Add formal_resolved to gfc_symbol. * resolve.cc (gfc_resolve_formal_arglist): Set it. (resolve_function): Do not call gfc_get_formal_from_actual_arglist if we already resolved a formal arglist. (resolve_call): Likewise. gcc/testsuite/ChangeLog: PR fortran/120163 * gfortran.dg/interface_61.f90: New test.
2025-05-13[PATCH] PR modula2/120117: ICE when attempting to obtain the MAX of an ↵Gaius Mulley5-9/+34
aliased set type The ICE occurred because of a bug in M2GenGCC.mod:FoldBecomes which attempted to remove the same quadruple twice. Thereafter cc1gm2 generated an erroneous error type error as PCSymBuild did not skip an aliased set type. The type of the const was set incorrectly (as a set type) rather than the type of the set element. gcc/m2/ChangeLog: PR modula2/120117 * gm2-compiler/M2GenGCC.mod (FoldBecomes): Remove the call to RemoveQuad since this is performed by TypeCheckBecomes. * gm2-compiler/PCSymBuild.mod (buildConstFunction): Rewrite header comment. Check for a set or a type aliased set and appropriately skip type equivalences and obtain the element type. * gm2-compiler/SymbolTable.mod (PutConst): Add call to CheckBreak. gcc/testsuite/ChangeLog: PR modula2/120117 * gm2/pim/pass/highbit.mod: New test. * gm2/pim/pass/highbit2.mod: New test. (cherry picked from commit bb83283e5c5c55eab7493a58c5e415aa56f5940c) Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-05-13[PATCH] PR modula2/119915: Sprintf1 repeats the entire format string if it ↵Gaius Mulley2-2/+65
starts with a directive This bugfix is for FormatStrings to ensure that in the case of %x, %u the procedure function PerformFormatString uses Copy rather than Slice to avoid the case on an upper bound of zero in Slice. Oddly the %d case had the correct code. gcc/m2/ChangeLog: PR modula2/119915 * gm2-libs/FormatStrings.mod (PerformFormatString): Handle the %u and %x format specifiers in a similar way to the %d specifier. Avoid using Slice and use Copy instead. gcc/testsuite/ChangeLog: PR modula2/119915 * gm2/pimlib/run/pass/format2.mod: New test. (cherry picked from commit 7a4f7a92770db4e739e76a06175454ba38d60b22) Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-05-13[PATCH] PR modula2/119914 No error message generated when passing a Ztype to ↵Gaius Mulley6-20/+217
an unbounded array This patch detects constants ZType, RType, CType being passed to unbounded arrays and generates an error message highlighting the formal and actual parameters in error. gcc/m2/ChangeLog: PR modula2/119914 * gm2-compiler/M2Check.mod (checkConstMeta): Add check for Ztype, Rtype and Ctype and unbounded arrays. (IsZRCType): New procedure function. (isZRC): Add comment. * gm2-compiler/M2Quads.mod: * gm2-compiler/M2Range.mod (gdbinit): New procedure. (BreakWhenRangeCreated): Ditto. (CheckBreak): Ditto. (InitRange): Call CheckBreak. (Init): Add gdbhook and initialize interactive watch point. * gm2-compiler/SymbolTable.def (GetNthParamAnyClosest): New procedure function. * gm2-compiler/SymbolTable.mod (BreakSym): Remove constant. (BreakSym): Add Variable. (stop): Remove. (gdbhook): New procedure. (BreakWhenSymCreated): Ditto. (CheckBreak): Ditto. (NewSym): Call CheckBreak. (Init): Add gdbhook and initialize interactive watch point. (MakeProcedure): Replace guarded call to stop with CheckBreak. (GetNthParamChoice): New procedure function. (GetNthParamOrdered): Ditto. (GetNthParamAnyClosest): Ditto. (GetOuterModuleScope): Ditto. gcc/testsuite/ChangeLog: PR modula2/119914 * gm2/pim/fail/constintarraybyte.mod: New test. (cherry picked from commit e9a81addd5b7d018e173fa8d59aafc2f84e41d8b) Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-05-13[PATCH] PR modula2/120188: Use existing test for pluginGaius Mulley1-1/+1
This is a cleanup patch which to use the existing plugin test rather than check the configure build options. gcc/testsuite/ChangeLog: PR modula2/120188 * gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp: Remove call to gm2-dg-frontend-configure-check and replace with tests for whether plugin variables exist. (cherry picked from commit f1f94e79dbcfa4b33267db27780870ea7810cd21) Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-05-13[PATCH] PR modula2/120188: documented example does not work assignvalue m2pluginGaius Mulley4-2/+87
This patch corrects the gm2 command line used in the documentation to invoke the m2-plugin. The patch also includes the documentation example in dejagnu test code with an expect script to check whether plugins were enabled. gcc/ChangeLog: PR modula2/120188 * doc/gm2.texi (Semantic checking): Add -fm2-plugin command line option. gcc/testsuite/ChangeLog: PR modula2/120188 * lib/gm2-dg.exp (gm2-dg-frontend-configure-check): New function. (gm2-dg-runtest): Add -O2 to the option_list. * gm2.dg/doc/examples/plugin/fail/assignvalue.mod: New test. * gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp: New test. (cherry picked from commit 9ce4c801e8275fcf0336ae2fb548f6ebb3ca068b) Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-05-13libfortran: Fix up _gfortran_{,m,s}findloc2_s{1,4} [PR120196]Jakub Jelinek1-0/+26
As mentioned in the PR, _gfortran_{,m,s}findloc2_s{1,4} iterate too many times in the back case if nothing is found. For !back, the loops are for (i = 1; i <= extent; i++) so i is in the body [1, extent] if nothing is found, but for back it is for (i = extent; i >= 0; i--) so i is in the body [0, extent] and compares one element before the start of the array. Note, findloc1_s{1,4} uses for (n = len; n > 0; n--, src -= delta * len_array) for the back loop and for (n = 1; n <= len; n++, src += delta * len_array) for !back. This patch fixes that. The testcase fails under valgrind without the libgfortran changes and succeeds with those. 2025-05-13 Jakub Jelinek <jakub@redhat.com> PR libfortran/120196 * m4/ifindloc2.m4 (header1, header2): For back use i > 0 rather than i >= 0 as for condition. * generated/findloc2_s1.c: Regenerate. * generated/findloc2_s4.c: Regenerate. * gfortran.dg/pr120196.f90: New test. (cherry picked from commit 748a7bc4624e7b000f6fdb93a8cf7da73ff193bb)
2025-05-13libfortran: Fix up _gfortran_s{max,min}loc1_{4,8,16}_s{1,4} [PR120191]Jakub Jelinek1-0/+23
There is a bug in _gfortran_s{max,min}loc1_{4,8,16}_s{1,4} which the following testcase shows. The functions return but then crash in the caller. Seems that is because buffer overflows, I believe those functions for if (mask == NULL || *mask) condition being false are supposed to fill in the result array with all zeros (or allocate it and fill it with zeros). My understanding is the result array in that case is integer(kind={4,8,16}) and should have the extents the character input array has. The problem is that it uses * string_len in the extent multiplication: extent[n] = GFC_DESCRIPTOR_EXTENT(array,n) * string_len; and extent[n] = GFC_DESCRIPTOR_EXTENT(array,n + 1) * string_len; which is I guess fine and desirable for the extents of the character array, but not for the extents of the destination array. Yet the code uses that extent array for that purpose (and no other purposes). Here it uses it to set the dimensions for the case where it needs to allocate (as well as size): for (n = 0; n < rank; n++) { if (n == 0) str = 1; else str = GFC_DESCRIPTOR_STRIDE(retarray,n-1) * extent[n-1]; GFC_DIMENSION_SET(retarray->dim[n], 0, extent[n] - 1, str); } Here it uses it for bounds checking of the destination: if (unlikely (compile_options.bounds_check)) { for (n=0; n < rank; n++) { index_type ret_extent; ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,n); if (extent[n] != ret_extent) runtime_error ("Incorrect extent in return value of" " MAXLOC intrinsic in dimension %ld:" " is %ld, should be %ld", (long int) n + 1, (long int) ret_extent, (long int) extent[n]); } } and here to find out how many retarray elements to actually fill in each dimension: while(1) { *dest = 0; count[0]++; dest += dstride[0]; n = 0; while (count[n] == extent[n]) { /* When we get to the end of a dimension, reset it and increment the next dimension. */ count[n] = 0; /* We could precalculate these products, but this is a less frequently used path so probably not worth it. */ dest -= dstride[n] * extent[n]; Seems maxloc1s.m4 and minloc1s.m4 are the only users of ifunction-s.m4, so we can change SCALAR_ARRAY_FUNCTION in there without breaking anything else. 2025-05-13 Jakub Jelinek <jakub@redhat.com> PR fortran/120191 * m4/ifunction-s.m4 (SCALAR_ARRAY_FUNCTION): Don't multiply GFC_DESCRIPTOR_EXTENT(array,) by string_len. * generated/maxloc1_4_s1.c: Regenerate. * generated/maxloc1_4_s4.c: Regenerate. * generated/maxloc1_8_s1.c: Regenerate. * generated/maxloc1_8_s4.c: Regenerate. * generated/maxloc1_16_s1.c: Regenerate. * generated/maxloc1_16_s4.c: Regenerate. * generated/minloc1_4_s1.c: Regenerate. * generated/minloc1_4_s4.c: Regenerate. * generated/minloc1_8_s1.c: Regenerate. * generated/minloc1_8_s4.c: Regenerate. * generated/minloc1_16_s1.c: Regenerate. * generated/minloc1_16_s4.c: Regenerate. * gfortran.dg/pr120191_3.f90: New test. (cherry picked from commit 781cfc454b8dc24952fe7f4c5c409296dca505e1)
2025-05-13libfortran: Fix up _gfortran_s{max,min}loc2_{4,8,16}_s{1,4} [PR120191]Jakub Jelinek1-0/+84
I've tried to write a testcase for the BT_CHARACTER maxloc/minloc with named or unnamed arguments and indeed the just posted patch fixed the arguments in there in multiple cases to match what the library expects. But the testcase still fails, due to library problems. One dealt with in this patch are _gfortran_s{max,min}loc2_{4,8,16}_s{1,4} functions. Those are trivial wrappers around _gfortrani_{max,min}loc2_{4,8,16}_s{1,4} which should call those functions if the scalar mask is true and just return 0 otherwise. The two bugs I see there is that the back, len arguments are swapped, which means that it always acts as back=.true. and for len will use character length of 1 or 0 instead of the desired one. The _gfortrani_{max,min}loc2_{4,8,16}_s{1,4} functions have prototypes like GFC_INTEGER_4 maxloc2_4_s1 (gfc_array_s1 * const restrict array, GFC_LOGICAL_4 back, gfc_charlen_type len) so back comes before len, ditto for the GFC_INTEGER_4 smaxloc2_4_s1 (gfc_array_s1 * const restrict array, GFC_LOGICAL_4 *mask, GFC_LOGICAL_4 back, gfc_charlen_type len) The other problem is that it was just testing if (mask). In my limited Fortran understanding that means that the optional argument mask was supplied but nothing about its actual value. Other scalar mask generated routines use if (mask == NULL || *mask) as the condition when to call the non-masked function, i.e. when mask is not supplied (then it should act like .true. mask) or when it is supplied and evaluates to .true.). 2025-05-13 Jakub Jelinek <jakub@redhat.com> PR fortran/120191 * m4/maxloc2s.m4: For smaxloc2 call maxloc2 if mask is NULL or *mask. Swap back and len arguments. * m4/minloc2s.m4: Likewise. * generated/maxloc2_4_s1.c: Regenerate. * generated/maxloc2_4_s4.c: Regenerate. * generated/maxloc2_8_s1.c: Regenerate. * generated/maxloc2_8_s4.c: Regenerate. * generated/maxloc2_16_s1.c: Regenerate. * generated/maxloc2_16_s4.c: Regenerate. * generated/minloc2_4_s1.c: Regenerate. * generated/minloc2_4_s4.c: Regenerate. * generated/minloc2_8_s1.c: Regenerate. * generated/minloc2_8_s4.c: Regenerate. * generated/minloc2_16_s1.c: Regenerate. * generated/minloc2_16_s4.c: Regenerate. * gfortran.dg/pr120191_2.f90: New test. (cherry picked from commit 482f2192d4ef6af55acae2dc3e0df00b8487cc7d)
2025-05-13fortran: Fix up minloc/maxloc lowering [PR120191]Jakub Jelinek2-36/+629
We need to drop the kind argument from what is passed to the library, but need to do it not only when one uses the argument name for it (so kind=4 etc.) but also when one passes all the arguments to the intrinsics. The following patch uses what gfc_conv_intrinsic_findloc uses, which looks more efficient and cleaner, we already set automatic vars to point to the kind and back actual arguments, so we can just free/clear expr on the former and set name to "%VAL" on the latter. And similarly clears dim argument for the BT_CHARACTER case when using maxloc2/minloc2, again regardless of whether it was named or not. 2025-05-13 Jakub Jelinek <jakub@redhat.com> Daniil Kochergin <daniil2472s@gmail.com> Tobias Burnus <tburnus@baylibre.com> PR fortran/120191 * trans-intrinsic.cc (strip_kind_from_actual): Remove. (gfc_conv_intrinsic_minmaxloc): Don't call strip_kind_from_actual. Free and clear kind_arg->expr if non-NULL. Set back_arg->name to "%VAL" instead of a loop looking for last argument. Remove actual variable, use array_arg instead. Free and clear dim_arg->expr if non-NULL for BT_CHARACTER cases instead of using a loop. * gfortran.dg/pr120191_1.f90: New test. (cherry picked from commit ec249be3c287c6f1dfb328712ac9c39e6fa95eca)
2025-05-13Daily bump.GCC Administrator4-1/+21
2025-05-12c+: -Wabi false positive [PR120012]Jason Merrill2-2/+16
The warning compares the position of a field depending on whether or not the previous base/field is considered a POD for layout, but failed to consider whether the previous base/field is empty; layout of an empty base doesn't consider PODness. PR c++/120012 gcc/cp/ChangeLog: * class.cc (check_non_pod_aggregate): Check is_empty_class. gcc/testsuite/ChangeLog: * g++.dg/abi/base-defaulted2.C: New test. (cherry picked from commit b4b4dfbd22e06877052bd4cc4b191d9d138155cf)
2025-05-12Update gcc sv.poJoseph Myers1-1573/+274
* sv.po: Update.
2025-05-12Daily bump.GCC Administrator4-1/+102
2025-05-11tree-optimization/120211 - constrain LOOP_VINFO_EARLY_BREAKS_LIVE_IVS moreRichard Biener3-0/+33
The PR120089 fix added more PHIs to LOOP_VINFO_EARLY_BREAKS_LIVE_IVS but not checking that we only add PHIs with a latch argument. The following adds this missing check. PR tree-optimization/120211 * tree-vect-stmts.cc (vect_stmt_relevant_p): Only add PHIs from the loop header to LOOP_VINFO_EARLY_BREAKS_LIVE_IVS. * gcc.dg/vect/vect-early-break_135-pr120211.c: New testcase. * gcc.dg/torture/pr120211-1.c: Likewise.
2025-05-11ipa/120146 - deal with vanished varpool nodes in IPA PTARichard Biener2-2/+14
I don't understand why they vanish when still refered to, but lets deal with that in a conservative way. PR ipa/120146 * tree-ssa-structalias.cc (create_variable_info_for): If the symtab cannot tell us whether all refs to a variable are explicit assume they are not. * g++.dg/ipa/pr120146.C: New testcase. (cherry picked from commit b38e3a7196d25bc8bcb1fe55da7663745cea9470)