Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28445 Discussions

Odd checks for pos argument to bit intrinsics

Harald1
New Contributor II
293 Views

The following code demonstrates oddities in the checks of bit intrinsic arguments:

program p
  integer :: i
  logical, parameter :: a(*) = [(btest(8_4,i), i=-1,-1)]
  integer, parameter :: b(*) = [(ibclr(8_4,i), i=-1,-1)]
  integer, parameter :: c(*) = [(ibset(8_4,i), i=-1,-1)]
  logical, parameter :: d(*) = [(btest(8_4,i), i=32,32)]
  integer, parameter :: e(*) = [(ibclr(8_4,i), i=32,32)]
  integer, parameter :: f(*) = [(ibset(8_4,i), i=32,32)]
  integer, parameter :: g(*) = [(ibset(8_4,i), i=33,33)]
end

ifort/2021.6.0 and ifx/2022.1.0 produce:

ifort-check_bits.f90(3): error #6331: The POS argument to BTEST, IBITS, IBCLR, or IBSET must be less than BIT_SIZE.
  logical, parameter :: a(*) = [(btest(8_4,i), i=-1,-1)]
---------------------------------^
ifort-check_bits.f90(4): error #6331: The POS argument to BTEST, IBITS, IBCLR, or IBSET must be less than BIT_SIZE.
  integer, parameter :: b(*) = [(ibclr(8_4,i), i=-1,-1)]
---------------------------------^
ifort-check_bits.f90(5): error #6331: The POS argument to BTEST, IBITS, IBCLR, or IBSET must be less than BIT_SIZE.
  integer, parameter :: c(*) = [(ibset(8_4,i), i=-1,-1)]
---------------------------------^
ifort-check_bits.f90(9): error #6331: The POS argument to BTEST, IBITS, IBCLR, or IBSET must be less than BIT_SIZE.
  integer, parameter :: g(*) = [(ibset(8_4,i), i=33,33)]
---------------------------------^
compilation aborted for ifort-check_bits.f90 (code 1)

 So the first error messages are misleading, some checks are off-by one: bit_size(8_4) = 32, not 33.

 

0 Kudos
1 Reply
andrew_4619
Honored Contributor II
256 Views

 

pos(Input) Must be of type integer. It must not be negative and it must be less than BIT_SIZE(i).
The rightmost (least significant) bit of i is in position 0.
 
So all the errors are correct 0,31 only are valid, the message could be better "out of range" might be more accurate

 

0 Kudos
Reply