https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #1 from saitofuyuki at jamstec dot go.jp --- Sorry, I missed to attach the test program. program test_bits implicit none integer,parameter :: KT = 4 integer,parameter :: lbits = bit_size(0_KT) integer(kind=KT) x, y0, y1 integer(kind=KT) p, l x = -1 p = 0 l = lbits 100 format('IBITS(', I0, ',', I0, ',', I0, ')') 101 format(A, 1x, I0, 1x, B32.32) y0 = ibits(x, p, l) y1 = ibits_1(x, p, l) write(*, 100) x, p, l write(*, 101) 'intrinsic', y0, y0 write(*, 101) 'expected', y1, y1 stop contains elemental integer(kind=KT) function ibits_1(I, POS, LEN) result(n) !! IBITS(I, POS, LEN) = (I >> POS) & ~((~0) << LEN) implicit none integer(kind=KT),intent(in) :: I integer, intent(in) :: POS, LEN n = IAND(ISHFT(I, - POS), NOT(ISHFT(-1_KT, LEN))) end function ibits_1 end program test_bits