aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
AgeCommit message (Collapse)AuthorFilesLines
19 hoursFortran: Fix ICE in ASSOCIATE with user defined operator [PR121060]Paul Thomas1-0/+7
2025-07-16 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/121060 * interface.cc (matching_typebound_op): Defer determination of specific procedure until resolution by returning NULL. gcc/testsuite/ PR fortran/121060 * gfortran.dg/associate_75.f90: New test.
19 hoursFortran: Fix ICE in F2018 IMPORT statements.Paul Thomas1-3/+6
2025-07-16 Steve Kargl <sgk@troutmask.apl.washington.edu> gcc/fortran * decl.cc (gfc_match_import): Correct minor whitespace snafu and fix NULL pointer dereferences in two places. gcc/testsuite/ * gfortran.dg/import13.f90: New test.
24 hoursDaily bump.GCC Administrator1-0/+49
34 hoursopenmp, fortran: Fix ICE when the procedure name cannot be found in declare ↵Kwok Cheung Yeung1-2/+3
variant directives [PR104428] The result of searching for the procedure name symbol should be checked in case the symbol cannot be found to avoid a null dereference. gcc/fortran/ PR fortran/104428 * trans-openmp.cc (gfc_trans_omp_declare_variant): Check that proc_st is non-NULL before dereferencing. Add line number to error message. gcc/testsuite/ PR fortran/104428 * gfortran.dg/gomp/pr104428.f90: New.
40 hoursfortran: Amend descriptor bounds init if unallocatedMikael Morin2-47/+49
Always generate the conditional initialization of unallocated variables regardless of the basic variable allocation tracking done in the frontend and with an additional always false condition. The scalarizer used to always evaluate array bounds, including in the case of unallocated arrays on the left hand side of an assignment. This was (correctly) causing uninitialized warnings, even if the uninitialized values were in the end discarded. Since the fix for PR fortran/108889, an initialization of the descriptor bounds is added to silent the uninitialized warnings, conditional on the array being unallocated. This initialization is not useful in the execution of the program, and it is removed if the compiler can prove that the variable is unallocated (in the case of a local variable for example). Unfortunately, the compiler is not always able to prove it and the useless initialization may remain in the final code. Moreover, the generated code that was causing the evaluation of uninitialized variables has ben changed to avoid them, so we can try to remove or revisit that unallocated variable bounds initialization tweak. Unfortunately, just removing the extra initialization restores the warnings at -O0, as there is no dead code removal at that optimization level. Instead, this change keeps the initialization and modifies its guarding condition with an extra always false variable, so that if optimizations are enabled the whole initialization block is removed, and if they are disabled it remains and is sufficient to prevent the warning. The new variable requires the code generation to be done earlier in the function so that the variable declaration and usage are in the same scope. As the modified condition guarantees the removal of the block with optimizations, we can emit it more broadly and remove the basic allocation tracking that was done in the frontend to limit its emission. gcc/fortran/ChangeLog: * gfortran.h (gfc_symbol): Remove field allocated_in_scope. * trans-array.cc (gfc_array_allocate): Don't set it. (gfc_alloc_allocatable_for_assignment): Likewise. Generate the unallocated descriptor bounds initialisation before the opening of the reallocation code block. Create a variable and use it as additional condition to the unallocated descriptor bounds initialisation.
40 hoursfortran: Delay evaluation of array bounds after reallocationMikael Morin2-47/+104
Delay the evaluation of bounds, offset, etc after the reallocation, for the scalarization of allocatable arrays on the left hand side of assignments. Before this change, the code preceding the scalarization loop is like: D.4757 = ref2.offset; D.4759 = ref2.dim[0].ubound; D.4762 = ref2.dim[0].lbound; { if (ref2.data == 0B) goto realloc; if (ref2.dim[0].lbound + 4 != ref2.dim[0].ubound) goto realloc; goto L.10; realloc: ... change offset and bounds ... D.4757 = ref2.offset; D.4762 = NON_LVALUE_EXPR <ref2.dim[0].lbound>; ... reallocation ... L.10:; } while (1) { ... scalarized code ... so the bounds etc are evaluated first to variables, and the reallocation code takes care to update the variables during the reallocation. This is problematic because the variables' initialization references the array bounds, which for unallocated arrays are uninitialized at the evaluation point. This used to (correctly) cause uninitialized warnings (see PR fortran/108889), and a workaround for variables was found, that initializes the bounds of arrays variables to some value beforehand if they are unallocated. For allocatable components, there is no warning but the problem remains, some uninitialized values are used, even if discarded later. After this change the code becomes: { if (ref2.data == 0B) goto realloc; if (ref2.dim[0].lbound + 4 != ref2.dim[0].ubound) goto realloc; goto L.10; realloc:; ... change offset and bounds ... ... reallocation ... L.10:; } D.4762 = ref2.offset; D.4763 = ref2.dim[0].lbound; D.4764 = ref2.dim[0].ubound; while (1) { ... scalarized code so the scalarizer avoids storing the values to variables at the time it evaluates them, if the array is reallocatable on assignment. Instead, it keeps expressions with references to the array descriptor fields, expressions that remain valid through reallocation. After the reallocation code has been generated, the expressions stored by the scalarizer are evaluated in place to variables. The decision to delay evaluation is based on the existing field is_alloc_lhs, which requires a few tweaks to be alway correct wrt to what its name suggests. Namely it should be set even if the assignment right hand side is an intrinsic function, and it should not be set if the right hand side is a scalar and neither if the -fno-realloc-lhs flag is passed to the compiler. gcc/fortran/ChangeLog: * trans-array.cc (gfc_conv_ss_descriptor): Don't evaluate offset and data to a variable if is_alloc_lhs is set. Move the existing evaluation decision condition for data... (save_descriptor_data): ... here as a new predicate. (evaluate_bound): Add argument save_value. Omit the evaluation of the value to a variable if that argument isn't set. (gfc_conv_expr_descriptor): Update caller. (gfc_conv_section_startstride): Update caller. Set save_value if is_alloc_lhs is not set. Omit the evaluation of stride to a variable if save_value isn't set. (gfc_set_delta): Omit the evaluation of delta to a variable if is_alloc_lhs is set. (gfc_is_reallocatable_lhs): Return false if flag_realloc_lhs isn't set. (gfc_alloc_allocatable_for_assignment): Don't update the variables that may be stored in saved_offset, delta, and data. Call instead... (update_reallocated_descriptor): ... this new procedure. * trans-expr.cc (gfc_trans_assignment_1): Don't omit setting the is_alloc_lhs flag if the right hand side is an intrinsic function. Clear the flag if the right hand side is scalar.
40 hoursfortran: Generate array reallocation out of loopsMikael Morin1-9/+12
Generate the array reallocation on assignment code before entering the scalarization loops. This doesn't move the generated code itself, which was already put before the outermost loop, but only changes the current scope at the time the code is generated. This is a prerequisite for a followup patch that makes the reallocation code create new variables. Without this change the new variables would be declared in the innermost loop body and couldn't be used outside of it. gcc/fortran/ChangeLog: * trans-expr.cc (gfc_trans_assignment_1): Generate array reallocation code before entering the scalarisation loops.
41 hoursfortran: Fix indentationFilip Kastl1-10/+10
Move a block of code two spaces to the left. Commiting as obvious. gcc/fortran/ChangeLog: * resolve.cc (resolve_select_type): Fix indentation. Signed-off-by: Filip Kastl <fkastl@suse.cz>
4 daysDaily bump.GCC Administrator1-0/+9
5 daysFortran/OpenACC: Permit PARAMETER as 'var' in clauses (+ ignore)Tobias Burnus3-9/+38
It turned out that other compilers permit (require?) named constants to appear in clauses - and programs actually use this. OpenACC 3.4 added therefore the following: In this spec, a _var_ (in italics) is one of the following: ... * a named constant in Fortran. plus If during an optimization phase _var_ is removed by the compiler, appearances of var in data clauses are ignored. Thus, all errors related to PARAMETER are now downgraded, most to a -Wsurprising warning, but for 'acc declare device_resident' (which kind of makes sense), no warning is printed. In trans-openmp.cc, those are ignored, unless I missed some code path. (If so, I hope the middle end removes them; but before removing them for the covered cases, the program just compiled & linked fine.) Note that 'ignore PARAMETER inside clauses' in trans-openmp.cc would in principle also apply to expressions ('if (var)') but those should be evaluated during 'resolve.cc' + 'openmp.cc' to their (numeric, logical, string) value such that there should be no issue. gcc/fortran/ChangeLog: * invoke.texi (-Wsurprising): Note about OpenACC warning related to PARAMATER. * openmp.cc (resolve_omp_clauses, gfc_resolve_oacc_declare): Accept PARAMETER for OpenACC but add surprising warning. * trans-openmp.cc (gfc_trans_omp_variable_list, gfc_trans_omp_clauses): Ignore PARAMETER inside clauses. gcc/testsuite/ChangeLog: * gfortran.dg/goacc/parameter.f95: Add -Wsurprising flag and update expected diagnostic. * gfortran.dg/goacc/parameter-3.f90: New test. * gfortran.dg/goacc/parameter-4.f90: New test.
5 daysDaily bump.GCC Administrator1-0/+27
6 daysFortran: Implement F2018 IMPORT statements [PR106135]Paul Thomas4-16/+369
2025-09-09 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/106135 * decl.cc (build_sym): Emit an error if a symbol associated by an IMPORT, ONLY or IMPORT, all statement is being redeclared. (gfc_match_import): Parse and check the F2018 versions of the IMPORT statement. For scopes other than and interface body, if the symbol cannot be found in the host scope, generate it and set it up such that gfc_fixup_sibling_symbols can transfer its 'imported attribute' if it turnes out to be a not yet parsed procedure. Test for violations of C897-8100. * gfortran.h : Add 'import_only' to the gfc_symtree structure. Add the enum, 'importstate', which is used for values the new field 'import_state' in gfc_namespace. * parse.cc (gfc_fixup_sibling_symbols): Transfer the attribute 'imported' to the new symbol. * resolve.cc (check_sym_import_status, check_import_status): New functions to test symbols and expressions for violations of F2018:C8102. (resolve_call): Test the 'resolved_sym' against C8102 by a call to 'check_sym_import_status'. (gfc_resolve_expr): If the expression is OK and an IMPORT statement has been registered in the current scope, test C102 by calling 'check_import_status'. (resolve_select_type): Test the declared derived type in TYPE IS and CLASS IS statements. gcc/testsuite/ PR fortran/106135 * gfortran.dg/import3.f90: Use -std=f2008 and comment on change in error message texts with f2018. * gfortran.dg/import12.f90: New test.
8 daysDaily bump.GCC Administrator1-0/+6
9 daysFortran: Ensure finalizers are created correctly [PR120637]Andre Vehreschild1-10/+14
Finalize_component freeed an expression that it used to remember which components in which context it had finalized already. While it makes sense to free the copy of the expression, if it is unused, it causes issues, when comparing to a non existent expression. This is now detected by returning true, when the expression has been used. PR fortran/120637 gcc/fortran/ChangeLog: * class.cc (finalize_component): Return true, when a finalizable component was detect and do not free it. gcc/testsuite/ChangeLog: * gfortran.dg/asan/finalize_1.f90: New test.
9 daysDaily bump.GCC Administrator1-0/+5
10 daysfortran: Add the preliminary code of MOVE_ALLOC argumentsMikael Morin1-0/+5
Add the preliminary code produced for the evaluation of the FROM and TO arguments of the MOVE_ALLOC intrinsic before using their values. Before this change, the preliminary code was ignored and dropped, limiting the validity of the implementation of MOVE_ALLOC to simple cases without preliminary code. This change also adds the cleanup code of the same arguments. It doesn't make any difference on the testcase though. Because of the limited set of arguments that are allowed (variables or components without subreference), it is possible that the cleanup code is actually guaranteed to be empty. At least adding the cleanup code makes the array case consistent with the scalar case. gcc/fortran/ChangeLog: * trans-intrinsic.cc (conv_intrinsic_move_alloc): Add pre and post code for the FROM and TO arguments. gcc/testsuite/ChangeLog: * gfortran.dg/move_alloc_20.f03: New test.
12 daysDaily bump.GCC Administrator1-0/+5
12 daysFortran: Silence a clang warning (suggesting a brace) in io.ccMartin Jambor1-1/+1
When GCC is built with clang, it suggests that we add a brace to the initialization of format_asterisk: gcc/fortran/io.cc:32:16: warning: suggest braces around initialization of subobject [-Wmissing-braces] So this patch does that to silence it. gcc/fortran/ChangeLog: 2025-06-24 Martin Jambor <mjambor@suse.cz> * io.cc (format_asterisk): Add a brace around static initialization location part of the field locus.
13 daysDaily bump.GCC Administrator1-0/+6
14 daysFortran: Remove corank conformability checks [PR120843]Andre Vehreschild1-29/+0
Remove the checks on coranks conformability in expressions, because there is nothing in the standard about it. When a coarray has no coindexes it it treated like a non-coarray, when it has a full-corank coindex its result is a regular array. So nothing to check for corank conformability. PR fortran/120843 gcc/fortran/ChangeLog: * resolve.cc (resolve_operator): Remove conformability check, because it is not in the standard. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/coindexed_6.f90: Enhance test to have coarray components covered.
2025-07-02Daily bump.GCC Administrator1-0/+22
2025-07-01Fortran: fix minor issues with coarraysHarald Anlauf2-3/+6
gcc/fortran/ChangeLog: * coarray.cc (check_add_new_component): Treat pure and elemental intrinsic functions the same as non-intrinsic ones. (create_caf_add_data_parameter_type): Fix front-end memleaks. * trans-intrinsic.cc (conv_caf_func_index): Likewise.
2025-07-01Fortran: Ensure arguments in coarray call get unique components in add_data ↵Andre Vehreschild1-2/+2
[PR120847] PR fortran/120847 gcc/fortran/ChangeLog: * coarray.cc (check_add_new_comp_handle_array): Make the count of components static to be able to create more than one. Create an array component only for array expressions. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/coindexed_7.f90: New test.
2025-07-01Fortran: Fix non-conformable corank on this_image ref [PR120843]Andre Vehreschild1-3/+4
PR fortran/120843 gcc/fortran/ChangeLog: * resolve.cc (resolve_operator): Report inconsistent coranks only when not referencing this_image. (gfc_op_rank_conformable): Treat coranks as inconformable only when a coindex other then implicit this_image is used. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/coindexed_6.f90: New test.
2025-06-28Daily bump.GCC Administrator1-0/+27
2025-06-27Fortran: follow-up fix to checking of renamed-on-use interface name [PR120784]Harald Anlauf1-1/+3
Commit r16-1633 introduced a regression for imported interfaces that were not renamed-on-use, since the related logic did not take into account that the absence of renaming could be represented by an empty string. PR fortran/120784 gcc/fortran/ChangeLog: * interface.cc (gfc_match_end_interface): Detect empty local_name. gcc/testsuite/ChangeLog: * gfortran.dg/interface_63.f90: Extend testcase.
2025-06-26fortran: Avoid freeing uninitialized valueMartin Jambor1-1/+1
When compiling fortran/match.cc, clang emits a warning fortran/match.cc:5301:7: warning: variable 'p' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] which looks accurate, so this patch adds an initialization of p to avoid the use. gcc/fortran/ChangeLog: 2025-06-23 Martin Jambor <mjambor@suse.cz> * match.cc (gfc_match_nullify): Initialize p to NULL;
2025-06-26Fortran: Prevent creation of unused tree.Andre Vehreschild1-4/+7
gcc/fortran/ChangeLog: * trans.cc (gfc_allocate_using_malloc): Prevent possible memory leak when allocation was already done.
2025-06-26Fortran: Fix wasting memory in coarray single mode.Andre Vehreschild2-3/+3
gcc/fortran/ChangeLog: * resolve.cc (resolve_fl_derived0): Do not create the token component when not in coarray lib mode. * trans-types.cc: Do not access the token when not in coarray lib mode.
2025-06-26Fortran: Fix out of bounds access in structure constructor's clean up [PR120711]Andre Vehreschild1-4/+6
A structure constructor's generated clean up code was using an offset variable, which was manipulated before the clean up was run leading to an out of bounds access. PR fortran/120711 gcc/fortran/ChangeLog: * trans-array.cc (gfc_trans_array_ctor_element): Store the value of the offset for reuse. gcc/testsuite/ChangeLog: * gfortran.dg/asan/array_constructor_1.f90: New test.
2025-06-25Daily bump.GCC Administrator1-0/+28
2025-06-24Fortran/OpenACC: Add Fortran support for acc_attach/acc_detachTobias Burnus1-2/+72
While C/++ support the routines acc_attach{,_async} and acc_detach{,_finalize}{,_async} routines since a long time, the Fortran API routines where only added in OpenACC 3.3. Unfortunately, they cannot directly be implemented in the library as GCC will introduce a temporary array descriptor in some cases, which causes the attempted attachment to the this temporary variable instead of to the original one. Therefore, those API routines are handled in a special way in the compiler. gcc/fortran/ChangeLog: * trans-stmt.cc (gfc_trans_call_acc_attach_detach): New. (gfc_trans_call): Call it. libgomp/ChangeLog: * libgomp.texi (acc_attach, acc_detach): Update for Fortran version. * openacc.f90 (acc_attach{,_async}, acc_detach{,_finalize}{,_async}): Add. * openacc_lib.h: Likewise. * testsuite/libgomp.oacc-fortran/acc-attach-detach-1.f90: New test. * testsuite/libgomp.oacc-fortran/acc-attach-detach-2.f90: New test.
2025-06-24Fortran: fix ICE in verify_gimple_in_seq with substrings [PR120743]Harald Anlauf1-2/+3
PR fortran/120743 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_substring): Substring indices are of type gfc_charlen_type_node. Convert to size_type_node for pointer arithmetic only after offset adjustments have been made. gcc/testsuite/ChangeLog: * gfortran.dg/pr120743.f90: New test. Co-authored-by: Jerry DeLisle <jvdelisle@gcc.gnu.org> Co-authored-by: Mikael Morin <mikael@gcc.gnu.org>
2025-06-24fortran: Mention user variable in SELECT TYPE temporary variable namesMikael Morin4-17/+51
The temporary variables that are generated to implement SELECT TYPE and TYPE IS statements have (before this change) a name depending only on the type. This can produce confusing dumps with code having multiple SELECT TYPE statements, as it isn't obvious which SELECT TYPE construct the variable relates to. This is especially the case with nested SELECT TYPE statements and with SELECT TYPE variables having identical types (and thus identical names). This change adds one additional user-provided discriminating string in the variable names, using the value from the SELECT TYPE variable name or last component reference name. The additional string may be truncated to fit in the temporary buffer. This requires all buffers to have matching sizes to get the same resulting name everywhere. gcc/fortran/ChangeLog: * misc.cc (gfc_var_name_for_select_type_temp): New function. * gfortran.h (gfc_var_name_for_select_type_temp): Declare it. * resolve.cc (resolve_select_type): Pick a discriminating name from the SELECT TYPE variable reference and use it in the name of the temporary variable that is generated. Truncate name to the buffer size. * match.cc (select_type_set_tmp): Likewise. Pass the discriminating name... (select_intrinsic_set_tmp): ... to this function. Use the discriminating name likewise. Augment the buffer size to match that of select_type_set_tmp and resolve_select_type. gcc/testsuite/ChangeLog: * gfortran.dg/select_type_51.f90: New test.
2025-06-24Daily bump.GCC Administrator1-0/+11
2025-06-23OpenACC: Add 'if' clause to 'acc wait' directiveTobias Burnus2-1/+5
OpenACC 3.0 added the 'if' clause to four directives; this patch only adds it to 'acc wait'. gcc/c-family/ChangeLog: * c-omp.cc (c_finish_oacc_wait): Handle if clause. gcc/c/ChangeLog: * c-parser.cc (OACC_WAIT_CLAUSE_MASK): Add if clause. gcc/cp/ChangeLog: * parser.cc (OACC_WAIT_CLAUSE_MASK): Ass if clause. gcc/fortran/ChangeLog: * openmp.cc (OACC_WAIT_CLAUSES): Add if clause. * trans-openmp.cc (gfc_trans_oacc_wait_directive): Handle it. gcc/testsuite/ChangeLog: * c-c++-common/goacc/acc-wait-1.c: New test. * gfortran.dg/goacc/acc-wait-1.f90: New test.
2025-06-23Fortran: fix checking of renamed-on-use interface name [PR120784]Harald Anlauf1-3/+10
PR fortran/120784 gcc/fortran/ChangeLog: * interface.cc (gfc_match_end_interface): If a use-associated symbol is renamed, use the local_name for checking. gcc/testsuite/ChangeLog: * gfortran.dg/interface_63.f90: New test.
2025-06-20Daily bump.GCC Administrator1-0/+6
2025-06-19fortran: Statically initialize length of SAVEd character arraysMikael Morin1-2/+10
PR fortran/120713 gcc/fortran/ChangeLog: * trans-array.cc (gfc_trans_deferred_array): Statically initialize deferred length variable for SAVEd character arrays. gcc/testsuite/ChangeLog: * gfortran.dg/save_alloc_character_1.f90: New test.
2025-06-19Daily bump.GCC Administrator1-0/+9
2025-06-18Fortran: various fixes for STAT/LSTAT/FSTAT intrinsics [PR82480]Harald Anlauf2-39/+46
The GNU intrinsics STAT/LSTAT/FSTAT were inherited from g77, but changed the names of some keywords: FILE became NAME, and SARRAY became VALUES, which are the keywords documented in the gfortran manual. Adjust code and libgfortran error messages to reflect this change. Furthermore, add compile-time checking that INTENT(OUT) arguments are definable, and that array VALUES has at least size 13. Document that integer arguments are of default kind, and that overflows in conversion to integer return -1 in VALUES. PR fortran/82480 gcc/fortran/ChangeLog: * check.cc (gfc_check_fstat): Extend checks to INTENT(OUT) arguments. (gfc_check_fstat_sub): Likewise. (gfc_check_stat): Likewise. (gfc_check_stat_sub): Likewise. * intrinsic.texi: Adjust documentation. libgfortran/ChangeLog: * intrinsics/stat.c (stat_i4_sub_0): Fix argument names. Rename SARRAY to VALUES also in error message. When array VALUES is KIND=4, get only stat components that do not overflow INT32_MAX, otherwise set the corresponding VALUES elements to -1. (stat_i4_sub): Fix argument names. (lstat_i4_sub): Likewise. (stat_i8_sub_0): Likewise. (stat_i8_sub): Likewise. (lstat_i8_sub): Likewise. (stat_i4): Likewise. (stat_i8): Likewise. (lstat_i4): Likewise. (lstat_i8): Likewise. (fstat_i4_sub): Likewise. (fstat_i8_sub): Likewise. (fstat_i4): Likewise. (fstat_i8): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/stat_3.f90: New test.
2025-06-17Daily bump.GCC Administrator1-0/+6
2025-06-16Fortran: fix checking of MOLD= in ALLOCATE statements [PR51961]Harald Anlauf1-0/+17
In ALLOCATE statements where the MOLD= argument is present and is not scalar, and the allocate-object has an explicit-shape-spec, the standard does not require the ranks to agree. In that case we skip the rank check, but emit a warning if -Wsurprising is given. PR fortran/51961 gcc/fortran/ChangeLog: * resolve.cc (conformable_arrays): Use modified rank check when MOLD= expression is given. gcc/testsuite/ChangeLog: * gfortran.dg/allocate_with_mold_5.f90: New test.
2025-06-12Daily bump.GCC Administrator1-0/+7
2025-06-12fortran: add intrinsic doc for trig functions with half revolutionsYuao Ma1-68/+458
This patch is a follow-up to commit r16-938-ge8fdd55ec90749. In this patch, we add intrinsic documentation for the newly added trig functions with half revolutions. We also reorder the documentation for `atand` to place it in correct alphabetical order. PR fortran/113152 gcc/fortran/ChangeLog: * intrinsic.texi: Document new half-revolution trigonometric functions. Reorder doc for atand. Signed-off-by: Yuao Ma <c8ef@outlook.com> Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
2025-06-07Daily bump.GCC Administrator1-0/+10
2025-06-06OpenMP: Add omp_get_initial_device/omp_get_num_devices builtinsTobias Burnus4-3/+20
By adding omp_get_initial_device and omp_get_num_devices builtins for C, C++, and Fortran, the following can be achieved: * By making them pure, multiple calls can be avoiding in some cases. * Some comparisons can be optimized at compile time. omp_get_initial_device will be converted to omp_get_num_devices for consistency; note that OpenMP 6 also permits omp_initial_device (== -1) as value. If GCC has not been configure for offloading, either intrinsic will leads to 0 - and on the offload side, -1 (= omp_initial_device) is returned for omp_initial_device. gcc/fortran/ChangeLog: * f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define. * trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices and omp_get_intrinsic_device. * gfortran.h (gfc_option_t): Add disable_omp_... for them. * options.cc (gfc_handle_option): Handle them with -fno-builtin-. gcc/ChangeLog: * gimple-fold.cc (gimple_fold_builtin_omp_get_initial_device, gimple_fold_builtin_omp_get_num_devices): New. (gimple_fold_builtin): Call them. * omp-builtins.def (BUILT_IN_OMP_GET_INITIAL_DEVICE): Add (BUILT_IN_OMP_GET_NUM_DEVICES): Make uservisible + pure. libgomp/ChangeLog: * libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device): Document builtin handling. gcc/testsuite/ChangeLog: * c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New test. * c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test. * gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New test. * gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test. Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
2025-06-05Daily bump.GCC Administrator1-0/+6
2025-06-04Fortran: Fix missing substring ref for allocatable saved vars [PR120483]Andre Vehreschild1-3/+13
Compute a substring ref on an allocatable static character array using pointer arithmetic. Using an array type corrupts type layouting and crashes omp generation. PR fortran/120483 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_substring): Use pointer arithmetic on static allocatable char arrays. gcc/testsuite/ChangeLog: * gfortran.dg/save_8.f90: New test.
2025-06-04Daily bump.GCC Administrator1-0/+6