Debian Codegraph @

gcc/testsuite/gfortran.dg/unsigned_write.f90

raw
1 ! { dg-do run }
2 ! This is a libgfortran (runtime library) test, need to run only once!
3 !
4 ! { dg-require-effective-target fortran_integer_16 }
5 ! { dg-additional-options "-funsigned" }
6 !
7 ! PR libfortran/118406 - printing large UNSIGNED(kind=16) crashes
8
9 program print_large_unsigned
10 unsigned(16), parameter :: u16_max = huge(0U_16)
11 unsigned(16), parameter :: u8_max = uint(huge(0U_8),16) ! UINT64_MAX
12 unsigned(16), parameter :: ten19 = uint(10_8 ** 18,16)*10U_16 ! 10**19
13 character(42) :: s
14
15 ! Reference: signed integer
16 write(s,*) huge(0_16)
17 if (adjustl (s) /= "170141183460469231731687303715884105727") stop 1
18
19 ! Same value as unsigned
20 write(s,*) uint (huge(0_16),16)
21 if (adjustl (s) /= "170141183460469231731687303715884105727") stop 2
22
23 ! Extreme and intermediate values
24 write(s,*) u16_max
25 if (adjustl (s) /= "340282366920938463463374607431768211455") stop 3
26
27 write(s,*) (u16_max - 3U_16) / 4U_16 * 3U_16
28 if (adjustl (s) /= "255211775190703847597530955573826158589") stop 4
29
30 ! Test branches of implementation in string.c::gfc_itoa
31 write(s,*) u8_max * ten19
32 if (adjustl (s) /= "184467440737095516150000000000000000000") stop 5
33
34 write(s,*) u8_max * ten19 - 1U_16
35 if (adjustl (s) /= "184467440737095516149999999999999999999") stop 6
36
37 write(s,*) u8_max * ten19 + 1U_16
38 if (adjustl (s) /= "184467440737095516150000000000000000001") stop 7
39
40 end