Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
告知
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 ディスカッション

Odd checks for pos argument to bit intrinsics

Harald1
新規コントリビューター II
735件の閲覧回数

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 件の賞賛
1 返信
andrew_4619
名誉コントリビューター III
698件の閲覧回数

 

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

 

返信