[PUSHED] [OpenACC/Fortran testsuite] Use relative line numbers for a few DejaGnu directives
From: Thomas Schwinge For easier maintenance. gcc/testsuite/ * gfortran.dg/goacc/assumed.f95: Use relative line numbers for a few DejaGnu directives. * gfortran.dg/goacc/list.f95: Likewise. * gfortran.dg/goacc/loop-1-2.f95: Likewise. * gfortran.dg/goacc/loop-1.f95: Likewise. * gfortran.dg/goacc/reduction.f95: Likewise. --- gcc/testsuite/gfortran.dg/goacc/assumed.f95 | 5 +-- gcc/testsuite/gfortran.dg/goacc/list.f95 | 8 ++-- gcc/testsuite/gfortran.dg/goacc/loop-1-2.f95 | 2 +- gcc/testsuite/gfortran.dg/goacc/loop-1.f95| 2 +- gcc/testsuite/gfortran.dg/goacc/reduction.f95 | 45 +-- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/gcc/testsuite/gfortran.dg/goacc/assumed.f95 b/gcc/testsuite/gfortran.dg/goacc/assumed.f95 index 4efe5a2b06e..4e35c1d5960 100644 --- a/gcc/testsuite/gfortran.dg/goacc/assumed.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/assumed.f95 @@ -16,6 +16,7 @@ contains !$acc host_data use_device (a) ! { dg-error "Assumed size" } !$acc end host_data !$acc parallel loop reduction(+:a) ! { dg-error "Assumed size" } +! { dg-error "Array 'a' is not permitted in reduction" "" { target "*-*-*" } .-1 } do i = 1,5 enddo !$acc end parallel loop @@ -37,6 +38,7 @@ contains !$acc host_data use_device (a) ! { dg-error "Assumed rank" } !$acc end host_data !$acc parallel loop reduction(+:a) ! { dg-error "Assumed rank" } +! { dg-error "Array 'a' is not permitted in reduction" "" { target "*-*-*" } .-1 } do i = 1,5 enddo !$acc end parallel loop @@ -45,6 +47,3 @@ contains !$acc update self (a) ! { dg-error "Assumed rank" } end subroutine assumed_rank end module test - -! { dg-error "Array 'a' is not permitted in reduction" "" { target "*-*-*" } 18 } -! { dg-error "Array 'a' is not permitted in reduction" "" { target "*-*-*" } 39 } diff --git a/gcc/testsuite/gfortran.dg/goacc/list.f95 b/gcc/testsuite/gfortran.dg/goacc/list.f95 index d2f4c5e88be..3d4ebf88720 100644 --- a/gcc/testsuite/gfortran.dg/goacc/list.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/list.f95 @@ -100,14 +100,14 @@ program test !$acc host_data use_device(10) ! { dg-error "Syntax error" } !$acc host_data use_device(/b/, /b/) + ! { dg-error "neither a POINTER nor an array" "" { target *-*-* } .-1 } + ! { dg-error "present on multiple clauses" "" { target *-*-* } .-2 } !$acc end host_data - ! { dg-error "neither a POINTER nor an array" "" { target *-*-* } 102 } - ! { dg-error "present on multiple clauses" "" { target *-*-* } 102 } !$acc host_data use_device(i, j, i) + ! { dg-error "neither a POINTER nor an array" "" { target *-*-* } .-1 } + ! { dg-error "present on multiple clauses" "" { target *-*-* } .-2 } !$acc end host_data - ! { dg-error "neither a POINTER nor an array" "" { target *-*-* } 107 } - ! { dg-error "present on multiple clauses" "" { target *-*-* } 107 } !$acc host_data use_device(p1) !$acc end host_data diff --git a/gcc/testsuite/gfortran.dg/goacc/loop-1-2.f95 b/gcc/testsuite/gfortran.dg/goacc/loop-1-2.f95 index e048205d2c3..8846e7d2a1f 100644 --- a/gcc/testsuite/gfortran.dg/goacc/loop-1-2.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/loop-1-2.f95 @@ -148,8 +148,8 @@ subroutine test1 !$acc parallel loop collapse(2) do i = 1, 3 do r = 4, 6 + ! { dg-error "ACC LOOP iteration variable must be of type integer" "" { target *-*-* } .-1 } end do -! { dg-error "ACC LOOP iteration variable must be of type integer" "" { target *-*-* } 150 } end do !$acc loop independent seq diff --git a/gcc/testsuite/gfortran.dg/goacc/loop-1.f95 b/gcc/testsuite/gfortran.dg/goacc/loop-1.f95 index 776fa482af3..67dc97a3ecd 100644 --- a/gcc/testsuite/gfortran.dg/goacc/loop-1.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/loop-1.f95 @@ -148,8 +148,8 @@ subroutine test1 !$acc parallel loop collapse(2) do i = 1, 3 do r = 4, 6 + ! { dg-error "ACC LOOP iteration variable must be of type integer" "" { target *-*-* } .-1 } end do -! { dg-error "ACC LOOP iteration variable must be of type integer" "" { target *-*-* } 150 } end do !$acc loop independent seq diff --git a/gcc/testsuite/gfortran.dg/goacc/reduction.f95 b/gcc/testsuite/gfortran.dg/goacc/reduction.f95 index a13574b150c..aaa82980e16 100644 --- a/gcc/testsuite/gfortran.dg/goacc/reduction.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/reduction.f95 @@ -25,14 +25,19 @@ save i2 common /blk/ i1 !$acc parallel reduction (+:ia2) +! { dg-error "Array 'ia2' is not permitted in reduction" "" { target "*-*-*" } .-1 } !$acc end parallel !$acc parallel reduction (+:ra1) +! { dg-error "Array 'ra1' is not permitted in reduction" "" { target "*-*-*" } .-1 } !$acc end parallel !$acc parallel reduction (+:ca1) +! { dg-error "Array 'ca1' is not permitted in reduction" "" { target "*-*-*" } .-1 } !$acc
[Patch] Fortran/OpenMP: Fix declare_variant's 'adjust_args' mishandling with return by reference [PR118321]
For declare_variant's 'adjust_args', the arguments for need_device_ptr are referenced by argument number. This patch fixes that calculation if hidden arguments due to return-by-reference calling exist. Note: It only fixes the Fortran issue; the C++ issue still needs to be fixed. Build + regtested on x86-64-gnu-linux. And comments before I commit it? Tobias Fortran/OpenMP: Fix declare_variant's 'adjust_args' mishandling with return by reference [PR118321] declare_variant's 'adjust_args' clause references the arguments in the middle end by the argument position; this has to account for hidden arguments that are inserted before due to return by reference, as done in this commit. PR fortran/118321 gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_declare_variant): Honor hidden arguments for append_arg's need_device_ptr. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/adjust-args-12.f90: New test. gcc/fortran/trans-openmp.cc | 14 ++-- gcc/testsuite/gfortran.dg/gomp/adjust-args-12.f90 | 40 +++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 2c6192820cc..d3ebc9b4745 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -8622,7 +8622,7 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns) if (!search_ns->proc_name->attr.function && !search_ns->proc_name->attr.subroutine) gfc_error ("The base name for % must be " - "specified at %L ", &odv->where); + "specified at %L", &odv->where); else error_found = false; } @@ -8821,6 +8821,13 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns) // Handle adjust_args tree need_device_ptr_list = make_node (TREE_LIST); vec adjust_args_list = vNULL; + int arg_idx_offset = 0; + if (gfc_return_by_reference (ns->proc_name)) + { + arg_idx_offset++; + if (ns->proc_name->ts.type == BT_CHARACTER) + arg_idx_offset++; + } for (gfc_omp_namelist *arg_list = odv->adjust_args_list; arg_list != NULL; arg_list = arg_list->next) { @@ -8847,14 +8854,15 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns) if (arg->sym == arg_list->sym) break; gcc_assert (arg != NULL); + // Store 0-based argument index, + // as in gimplify_call_expr need_device_ptr_list = chainon ( need_device_ptr_list, build_tree_list ( NULL_TREE, build_int_cst ( integer_type_node, -idx))); // Store 0-based argument index, - // as in gimplify_call_expr +idx + arg_idx_offset))); } } diff --git a/gcc/testsuite/gfortran.dg/gomp/adjust-args-12.f90 b/gcc/testsuite/gfortran.dg/gomp/adjust-args-12.f90 new file mode 100644 index 000..94fdd6c7a62 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/adjust-args-12.f90 @@ -0,0 +1,40 @@ +! { dg-additional-options "-fdump-tree-gimple" } + +! PR fortran/118321 + +! Ensure that hidden arguments (return by reference) do not mess up the +! argument counting of need_device_ptr + +! Here, we want to process the 3rd argument: 'c' as dummy argument = 'y' as actual. + + +! { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 1 "gimple" } } +! { dg-final { scan-tree-dump "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(y, D\.\[0-9\]+\\);" "gimple" } } + +! { dg-final { scan-tree-dump " \\(&pstr.\[0-9\], &slen.\[0-9\], &\"abc\"\\\[1\\\]\{lb: 1 sz: 1\}, x, D\.\[0-9\]+, z, &\"cde\"\\\[1\\\]\{lb: 1 sz: 1\}, 3, 3\\);" "gimple" } } + +module m + use iso_c_binding + implicit none (type, external) +contains + character(:) function (a,b,c,d,e) +allocatable :: +character(*) :: a, e +type(c_ptr), value :: b,c,d + end + character(:) function (a,b,c,d,e) +!$omp declare variant() match(construct={dispatch}) & +!$omp& adjust_args(need_device_ptr : c) +allocatable :: +character(*) :: a, e +type(c_ptr), value :: b,c,d + end +end module m + +use m +implicit none (type, external) +type(c_ptr) :: x,y,z +character(len=:), allocatable :: str +!$omp dispatch + str = ("abc", x, y, z, "cde") +end
Re: PING **(6./7.): [patch, Fortran] -fc-prototypes fixes.
Am 16.01.25 um 01:50 schrieb Jerry D: Yes I think this is OK, a definite improvement. Committed as r15-6967. Thanks for the review! Best regards Thomas
[PATCH] libfortran: fix conversion of UNSIGNED(kind=16) to decimal in output [PR118406]
Dear all, the conversion of (unsigned) integers to decimal in output was designed to be efficient up to INTEGER(kind=16) and did not handle values larger than roughly (10^19 * 2^64). The attached obvious patch fixes this. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From f66049d52327242743e7e9ff59d8373fcb333212 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 16 Jan 2025 20:23:06 +0100 Subject: [PATCH] libfortran: fix conversion of UNSIGNED(kind=16) to decimal in output [PR118406] PR libfortran/118406 libgfortran/ChangeLog: * runtime/string.c (gfc_itoa): Handle unsigned integers larger than (10^19 * 2^64). gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_write.f90: New test. --- gcc/testsuite/gfortran.dg/unsigned_write.f90 | 40 libgfortran/runtime/string.c | 35 - 2 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/unsigned_write.f90 diff --git a/gcc/testsuite/gfortran.dg/unsigned_write.f90 b/gcc/testsuite/gfortran.dg/unsigned_write.f90 new file mode 100644 index 000..903c212ee3a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unsigned_write.f90 @@ -0,0 +1,40 @@ +! { dg-do run } +! This is a libgfortran (runtime library) test, need to run only once! +! +! { dg-require-effective-target fortran_integer_16 } +! { dg-additional-options "-funsigned" } +! +! PR libfortran/118406 - printing large UNSIGNED(kind=16) crashes + +program print_large_unsigned + unsigned(16), parameter :: u16_max = huge(0U_16) + unsigned(16), parameter :: u8_max = uint(huge(0U_8),16)! UINT64_MAX + unsigned(16), parameter :: ten19 = uint(10_8 ** 18,16)*10U_16 ! 10**19 + character(42) :: s + + ! Reference: signed integer + write(s,*) huge(0_16) + if (adjustl (s) /= "170141183460469231731687303715884105727") stop 1 + + ! Same value as unsigned + write(s,*) uint (huge(0_16),16) + if (adjustl (s) /= "170141183460469231731687303715884105727") stop 2 + + ! Extreme and intermediate values + write(s,*) u16_max + if (adjustl (s) /= "340282366920938463463374607431768211455") stop 3 + + write(s,*) (u16_max - 3U_16) / 4U_16 * 3U_16 + if (adjustl (s) /= "255211775190703847597530955573826158589") stop 4 + + ! Test branches of implementation in string.c::gfc_itoa + write(s,*) u8_max * ten19 + if (adjustl (s) /= "18446744073709551615000") stop 5 + + write(s,*) u8_max * ten19 - 1U_16 + if (adjustl (s) /= "18446744073709551614999") stop 6 + + write(s,*) u8_max * ten19 + 1U_16 + if (adjustl (s) /= "18446744073709551615001") stop 7 + +end diff --git a/libgfortran/runtime/string.c b/libgfortran/runtime/string.c index 8acc94292c4..a0e2a85e8e2 100644 --- a/libgfortran/runtime/string.c +++ b/libgfortran/runtime/string.c @@ -241,18 +241,35 @@ gfc_itoa (GFC_UINTEGER_LARGEST n, char *buffer, size_t len) the uint64_t function are not sufficient for all 128-bit unsigned integers (we would need three calls), but they do suffice for all values up to 2^127, which is the largest that Fortran can produce - (-HUGE(0_16)-1) with its signed integer types. */ + (-HUGE(0_16)-1) with its signed integer types. + With the introduction of UNSIGNED integers, we must treat the case + of unsigned ints larger than (10^19 * 2^64) by adding one step. */ _Static_assert (sizeof(GFC_UINTEGER_LARGEST) <= 2 * sizeof(uint64_t), "integer too large"); - GFC_UINTEGER_LARGEST r; - r = n % TEN19; - n = n / TEN19; - assert (r <= UINT64_MAX); - p = itoa64_pad19 (r, p); - - assert(n <= UINT64_MAX); - return itoa64 (n, p); + if (n <= TEN19 * UINT64_MAX) + { + GFC_UINTEGER_LARGEST r; + r = n % TEN19; + n = n / TEN19; + assert (r <= UINT64_MAX); + p = itoa64_pad19 (r, p); + + assert(n <= UINT64_MAX); + return itoa64 (n, p); + } + else + { + /* Here n > (10^19 * 2^64). */ + GFC_UINTEGER_LARGEST d1, r1, d2, r2; + d1 = n / (TEN19 * TEN19); + r1 = n % (TEN19 * TEN19); + d2 = r1 / TEN19; + r2 = r1 % TEN19; + p = itoa64_pad19 (r2, p); + p = itoa64_pad19 (d2, p); + return itoa64 (d1, p); + } } #else /* On targets where the largest integer is 64-bit, just use that. */ -- 2.43.0
Re: [PATCH] libfortran: fix conversion of UNSIGNED(kind=16) to decimal in output [PR118406]
Hello Harald, the conversion of (unsigned) integers to decimal in output was designed to be efficient up to INTEGER(kind=16) and did not handle values larger than roughly (10^19 * 2^64). The attached obvious patch fixes this. Regtested on x86_64-pc-linux-gnu. OK for mainline? OK. Thanks a lot for finding and fixing this! Best regards Thomas
Re: [PATCH] libfortran: fix conversion of UNSIGNED(kind=16) to decimal in output [PR118406]
Hi Thomas, Am 16.01.25 um 20:38 schrieb Thomas Koenig: Hello Harald, the conversion of (unsigned) integers to decimal in output was designed to be efficient up to INTEGER(kind=16) and did not handle values larger than roughly (10^19 * 2^64). The attached obvious patch fixes this. Regtested on x86_64-pc-linux-gnu. OK for mainline? OK. Thanks a lot for finding and fixing this! sure. Committed as r15-6971-g99bcce0d89b8a9 . The testcase would have been slightly smaller with exponentiation of unsigned being implemented already (hint, hint! :) Best regards Thomas Cheers, Harald