------- Comment #4 from kargl at gcc dot gnu dot org 2008-02-17 06:38 ------- (In reply to comment #3) > Subject: Re: IBITS gives compiler error > ------- Comment #2 from kargl at gcc dot gnu dot org 2008-02-17 01:08 > > ------- > > (In reply to comment #0) > >> hades [TEST] cat bug-ibits.f90 > >> program main > >> write (*, *) ibits (-1, 0, bit_size (0)) > >> end program main > >> > > > > (snip) > > > > What result do you expect? > > > In this case I expect a running program to print "-1". > > > > > >> Compiling with g95 works fine though. > > > > Appears g95 may have a bug. See Sec. 13.3, 13.4, and most importantly > > 13.7 in the 'Final Committee Draft J3/03-007R2' of the Fortran 2003 > > standard. > > In that case a lot of compilers have the same bug. :-) > Appears more likely gfortran has a bug. > Pasting from the f90-standard: > > "13.13.42 IBITS (I, POS, LEN) Description.
I know what 13.13.42 says. I also know what 13.5.7 in the F95 standard says about the model numbers that are used by IBITS: Effectively, this model defines an integer object to consist of z bits in sequence numbered from right to left from 0 to z - 1 . This model is valid only in the context of the use of such an object as the argument or result of one of the bit manipulation procedures. In all other contexts, the model defined for an integer in 13.7.1 applies. and 13.14 from the Fortran 95 standard says This section contains detailed specifications of the generic intrinsic procedures in alphabetical order. The types and type parameters of intrinsic procedure arguments and function results are determined by these specifications. A program is prohibited from invoking an intrinsic procedure under circumstances where a value to be returned in a subroutine argument or function result is outside the range of values representable by objects of the specified type and type parameters. Read that last sentence carefully. You, as the programmer, are prohibited from calling an intrinsic procedure if it will return a value outside the representable range. Now, go read about the model numbers for the bit intrinsics and for integers. The bit intrinsic model numbers do not have a sign bit, and you're asking IBITS to return 2**32, which is outside of the range for gfortran's default integer kind. Also note, that a compiler is not required to detect the programming error. It can in fact do anything including what you expect as well as report an error. > > To conclude, the error message is incorrect. > You conclusion is wrong. Jerry already told you how to disable the error with -fno-range-check option. But, you should probably think about fixing your program. -- kargl at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |sgk at troutmask dot apl dot | |washington dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35223