[Patch] Fortran: Fix assumed-size to assumed-rank passing [PR94070]
This patch requires the previously mentioned simple-loop-gen patch, which also still needs to be reviewed: https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579576.html For the xfailed part of the new testcase, the updated array descriptor is needed, but I think leaving it as xfailed for now - and reviewing this patch first makes more sense. size(a,dim=i) of an array is simply: a.dim[i].ubound - a.dim[i].lbound + 1 except that the result is always >= 0, i.e. a(5:-10) has size 0. Assumed-size arrays like as(5, -3:*) can be passed to assumed-rank arrays – but, obviously, the upper bound is unknown. Without BIND(C), the standard is quiet how those get transported but: ubound(as,dim=2) == size(as,dim=2) == -1 However, for ..., allocatable :: c(:,:) allocate (c(5,-4:-1)) the size(c,dim=2) is surely 4 and not -1. Thus, when passing it to a subroutine foo(x) ..., allocatable :: x(..) it should also come out as size(x, dim=2) == 4. To make the distinction, the allocatable/pointer attribute of the dummy can be used – as an assumed-size array cannot be allocatable. That's what is used in trans-intrinsic.c/trans-array.c – and the main reason I started to generate inline code for the array size. (Given that it permits optimizations and is a trivial code, I also think that it makes sense in general.) But even when doing so, it still did not work properly as when calling call foo(d) the bounds where not always reset such that the caller could still receive ubound(d,dim=last_dim) == -1 - in the case it just happened to be -1, be it for a zero-sized array or because the lbounds just happend to be -1 or smaller. That's taken care of in trans-expr.c. OK for mainline? Tobias - Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran: Fix assumed-size to assumed-rank passing [PR94070] This code inlines the size0 and size1 libgfortran calls, the former is still used by libgfortan itself (and by old code). Besides permitting more optimizations, it also permits to handle assumed-rank dummies better: If the dummy argument is a nonpointer/nonallocatable, an assumed-size actual arg is repesented by having ubound == -1 for the last dimension. However, for allocatable/pointers, this value can also exist. Hence, the dummy arg attr has to be honored. For that reason, when calling an assumed-rank procedure with nonpointer, nonallocatable dummy arguments, the bounds have to be updated to avoid the case ubound == -1 for the last dimension. PR fortran/94070 gcc/fortran/ChangeLog: * trans-array.c (gfc_tree_array_size): New function to find size inline (whole array or one dimension). (array_parameter_size): Use it, take stmt_block as arg. (gfc_conv_array_parameter): Update call. * trans-array.h (gfc_tree_array_size): Add prototype. * trans-expr.c (gfc_conv_procedure_call): Update bounds of pointer/allocatable actual args to nonallocatable/nonpointer dummies to be one based. * trans-intrinsic.c (gfc_conv_intrinsic_shape): Fix case for assumed rank with allocatable/pointer dummy. (gfc_conv_intrinsic_size): Update to use inline function. libgfortran/ChangeLog: * intrinsics/size.c (size0, size1): Comment that now not used by newer compiler code. libgomp/ChangeLog: * testsuite/libgomp.oacc-fortran/privatized-ref-2.f90: Update expected dg-note output. gcc/testsuite/ChangeLog: * gfortran.dg/c-interop/cf-out-descriptor-6.f90: Remove xfail. * gfortran.dg/c-interop/size.f90: Remove xfail. * gfortran.dg/intrinsic_size_3.f90: * gfortran.dg/transpose_optimization_2.f90: * gfortran.dg/assumed_rank_22.f90: New test. * gfortran.dg/assumed_rank_22_aux.c: New test. gcc/fortran/trans-array.c | 165 gcc/fortran/trans-array.h | 2 + gcc/fortran/trans-expr.c | 43 +- gcc/fortran/trans-intrinsic.c | 119 ++- gcc/testsuite/gfortran.dg/assumed_rank_22.f90 | 167 + gcc/testsuite/gfortran.dg/assumed_rank_22_aux.c| 68 + .../gfortran.dg/c-interop/cf-out-descriptor-6.f90 | 2 +- gcc/testsuite/gfortran.dg/c-interop/size.f90 | 2 +- gcc/testsuite/gfortran.dg/intrinsic_size_3.f90 | 2 +- .../gfortran.dg/transpose_optimization_2.f90 | 2 +- libgfortran/intrinsics/size.c | 4 + .../libgomp.oacc-fortran/privatized-ref-2.f90 | 13 +- 12 files changed, 476 insertions(+), 113 deletions(-) diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 0d013defdbb..b8061f37772 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -7901,31 +7901,143 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr) gfc_cleanup_loop (&loop); } + +/* Cal
Re: [Patch] Fortran: Add gfc_simple_for_loop aux function
Hi Tobias, This patch adds a useful auxiliary function to generate a loop. Looks good to me (and there are probably quite a few places where this could be useful). Best regards Thomas
[Patch] Fortran: Improve -Wmissing-include-dirs warnings [PR55534]
While the previous patch fixed -Wno-missing-include-dirs and sorted out some inconsistencies with libcpp warnings, it had two issues: * Some superfluous warnings were printed, e.g. for gfortran nonexisting/file.f90 there was a warning about include path "nonexisting" not existing and twice the error that the "nonexisting/file.f90" could not be read. * At least as invoked when build GCC or when running the GCC testsuite, the passed -B -isystem etc. arguments lead to proper but pointless diagnostic about 'finclude' or other directories not being found, causing excess-error FAILS and -Werror build fails. While the latter could be fixed by adding -Wno-missing-include-dirs, it still felt like the wrong approach. While the testsuite does run for me, others reported that they do see missing-include-dirs warnings. Instead of adding a bunch of -Wno-missing-include-dirs to the test config, I now only warn for -I and -J by default (similar to previous state) and only do a full warnings when the user requested passes the -Wmissing-include-dirs explicitly. The Fortran behavior is now also properly documented in the manual. In order to handle the silencing of the diagnostic and to avoid double output via the Fortran code and libcpp (or rather: gcc/incpath.c), I had to add some not that clean and obvious diagnostic flags. I hope they still make sense and are somewhat readable. OK? Comments? Tobias PS: There is also some inconsistency whether fprintf stderr and gfc_error is used. All calls in load_file could be fatal errors as all exist with an error - and similar issues get different error messages for no good reason. I have not tried to solve this issue – but can if deemed reasonable as follow-up patch. - Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran: Improve -Wmissing-include-dirs warnings [PR55534] It turned out that enabling the -Wmissing-include-dirs for libcpp did output too many warnings – at least as run with -B and similar options during the GCC build and warning for internal include dirs like finclude, unlikely of relevance to for a real-world user. This patch now only warns for -I and -J by default but permits to get the full warnings including libcpp ones with -Wmissing-include-dirs. It additionally documents this in the manual. With that change, the -Wno-missing-include-dirs could be removed from libgfortran's configure and libgomp's testsuite always cflags. This reverts those bits of the previous commit r12-3722-g417ea5c02cef7f000e66d1af22b066c2c1cda047 Additionally, it turned out that all call to load_file called exit explicitly - except for the main file via gfc_init -> gfc_new_file. The latter also output a file not existing fatal error, such that two errors where printed. Now exit is called in line with the other users of load_file. Finally, when compileing with "nonexisting/file.f90", first a warning that "nonexisting" does not exist as include path was printed before the file not found error was printed. Now the directory in which the physical file is located is added silently, relying on the file-not-found diagnostic for those. PR fortran/55534 gcc/ChangeLog: * doc/invoke.texi (-Wno-missing-include-dirs.): Document Fortran behavior. gcc/fortran/ChangeLog: * cpp.c (gfc_cpp_register_include_paths, gfc_cpp_post_options): Add new bool verbose_missing_dir_warn argument. * cpp.h (gfc_cpp_post_options): Update prototype. * f95-lang.c (gfc_init): Remove duplicated file-not found diag. * gfortran.h (gfc_check_include_dirs): Takes bool verbose_missing_dir_warn arg. (gfc_new_file): Returns now void. * options.c (gfc_post_options): Update to warn for -I and -J, only, by default but for all when user requested. * scanner.c (gfc_do_check_include_dir): (gfc_do_check_include_dirs, gfc_check_include_dirs): Take bool verbose warn arg and update to avoid printing the same message twice or never. (load_file): Fix indent. (gfc_new_file): Return void and exit when load_file failed as all other load_file users do. libgfortran/ChangeLog: * configure.ac (AM_FCFLAGS): Revert r12-3722 by removing -Wno-missing-include-dirs. * configure: Regenerate. libgomp/ChangeLog: * testsuite/libgomp.fortran/fortran.exp (ALWAYS_CFLAGS): Revert r12-3722 by removing -Wno-missing-include-dirs. * testsuite/libgomp.oacc-fortran/fortran.exp (ALWAYS_CFLAGS): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/include_14.f90: Add -J testcase and update dg-output. * gfortran.dg/include_15.f90: Likewise. * gfortran.dg/include_16.f90: Likewise. * gfortran.dg/include_17.f90: Likewise. * gfortran.dg/include_18.f90: Likewise. * gfortran.dg/include_19.f90: Likewise. gcc/doc/invoke.texi| 6 +++-- gcc/fortran/cpp.c