https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91160
--- Comment #4 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Mon, Jul 15, 2019 at 09:49:31AM +0000, dominiq at lps dot ens.fr wrote: > > --- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- > > Fortran allows the arguments of merge_bits() to be BOZ literal constants. > > merge_bits is broken for said arguments. > > AFAIU the current implementation of BOZ literal constants, they are > INTEGER(16) That's going away soon. F2008 and newer state a BOZ is a string of bits. The string is either truncated or padded as needed when conversion is done. The immediate conversion of a BOZ to INTEGER(8) (or INTEGER(16) depending on the target) was a convenient mistake to get F95 conformance for a BOZ in a DATA statement (ie., the only place a BOZ is allowed in a F95). This mistake has ugly consequences in that a BOZ can appear anywhere an INTEGER can appear. For example, % cat a.f90 program foo print *, abs(z'1234') end program foo % gfortran8 -o z a.f90 && ./z 4660 % gfcx -c a.f90 a.f90:2:16: 2 | print *, abs(z'1234') | 1 Error: 'a' argument of 'abs' intrinsic at (1) must have a numeric type F2008 and F2018 state that a BOZ is typeless and does not have a kind type parameter. Kind of unusual to have ABS(), a generic intrinsic function, choose a specific function. > (INTEGER(8) with -m32) and the error should be expected. The following changes > > ! { dg-do run } > program foo > integer(16) m, n, k > m = merge_bits(b'010101', 1234_16, 42_16); if (m /= 1232) stop 1 > n = merge_bits(1234_16, z'3456', 42_16); if (n /= 13398) stop 2 > k = merge_bits(1234_16, 3456_16, o'12334'); if (k /= 3536) stop 3 > end program foo > > allow the code to compile and run (for -m64). > > Note that the errors "Error: 'j' argument ..." disappeared between revisions > r267284 and r267553 (r267415?). The correct fix would be to re-arrange gfc_check_merge_bits in check.c to check for a BOZ before other checks, but as this function is part of the BOZ rewrite I'm inclined to not fix this on the branches.