* [Bug libfortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
@ 2023-02-27 1:44 ` saitofuyuki at jamstec dot go.jp
2023-02-27 2:26 ` kargl at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: saitofuyuki at jamstec dot go.jp @ 2023-02-27 1:44 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libfortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
2023-02-27 1:44 ` [Bug libfortran/108937] " saitofuyuki at jamstec dot go.jp
@ 2023-02-27 2:26 ` kargl at gcc dot gnu.org
2023-02-27 3:01 ` saitofuyuki at jamstec dot go.jp
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-02-27 2:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #2 from kargl at gcc dot gnu.org ---
Not sure it's a bug.
16.3.1
...
The interpretation of a negative integer as a sequence of bits
is processor dependent.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libfortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
2023-02-27 1:44 ` [Bug libfortran/108937] " saitofuyuki at jamstec dot go.jp
2023-02-27 2:26 ` kargl at gcc dot gnu.org
@ 2023-02-27 3:01 ` saitofuyuki at jamstec dot go.jp
2023-02-27 18:14 ` kargl at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: saitofuyuki at jamstec dot go.jp @ 2023-02-27 3:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #3 from saitofuyuki at jamstec dot go.jp ---
Thanks a lot.
> Not sure it's a bug.
I see. I do agree it's not a bug and the answer of the particular case is
undefined.
But (for 32-bit integer case), since implemented ISHFT(I,32) returns 0 for any
representation of I, I suppose it may be better to return I as it is by
IBITS(I,0,32) (again, I agree it is not defined by standard).
Anyway, thanks a lot for your comment.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libfortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (2 preceding siblings ...)
2023-02-27 3:01 ` saitofuyuki at jamstec dot go.jp
@ 2023-02-27 18:14 ` kargl at gcc dot gnu.org
2023-02-27 19:32 ` anlauf at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-02-27 18:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #4 from kargl at gcc dot gnu.org ---
(In reply to saitofuyuki from comment #3)
> Thanks a lot.
>
> > Not sure it's a bug.
>
> I see. I do agree it's not a bug and the answer of the particular case is
> undefined.
>
> But (for 32-bit integer case), since implemented ISHFT(I,32) returns 0 for
> any representation of I, I suppose it may be better to return I as it is by
> IBITS(I,0,32) (again, I agree it is not defined by standard).
>
> Anyway, thanks a lot for your comment.
In the end, gfortran should probably do something that a user
might expect, and that would likely be two-complements wrap-around
unsigned integer arithmetic.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libfortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (3 preceding siblings ...)
2023-02-27 18:14 ` kargl at gcc dot gnu.org
@ 2023-02-27 19:32 ` anlauf at gcc dot gnu.org
2023-02-27 20:21 ` [Bug fortran/108937] " anlauf at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-02-27 19:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gcc dot gnu.org
--- Comment #5 from anlauf at gcc dot gnu.org ---
Interestingly, we simplify IBITS(-1,0,32) to -1, and also the code generated
for ibits(x, p, lbits) produces the result expected by the reporter,
and which is also generated by Intel and NAG.
For ISHFT we have
/* ISHFT (I, SHIFT) = (abs (shift) >= BIT_SIZE (i))
? 0
: ((shift >= 0) ? i << shift : i >> -shift)
where all shifts are logical shifts. */
so we might as well consider doing what the reporter suggests.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (4 preceding siblings ...)
2023-02-27 19:32 ` anlauf at gcc dot gnu.org
@ 2023-02-27 20:21 ` anlauf at gcc dot gnu.org
2023-02-27 20:55 ` anlauf at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-02-27 20:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|libfortran |fortran
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-02-27
Ever confirmed|0 |1
--- Comment #6 from anlauf at gcc dot gnu.org ---
Adjusting component as the issue is in the frontend generating the code.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (5 preceding siblings ...)
2023-02-27 20:21 ` [Bug fortran/108937] " anlauf at gcc dot gnu.org
@ 2023-02-27 20:55 ` anlauf at gcc dot gnu.org
2023-02-27 21:30 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-02-27 20:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #7 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2023-February/058984.html
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (6 preceding siblings ...)
2023-02-27 20:55 ` anlauf at gcc dot gnu.org
@ 2023-02-27 21:30 ` cvs-commit at gcc dot gnu.org
2023-02-27 23:07 ` saitofuyuki at jamstec dot go.jp
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-27 21:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:6cce953ebec274f1468d5d3a0697cf05bb43b8f6
commit r13-6362-g6cce953ebec274f1468d5d3a0697cf05bb43b8f6
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Feb 27 21:37:11 2023 +0100
Fortran: fix corner case of IBITS intrinsic [PR108937]
gcc/fortran/ChangeLog:
PR fortran/108937
* trans-intrinsic.cc (gfc_conv_intrinsic_ibits): Handle corner case
LEN argument of IBITS equal to BITSIZE(I).
gcc/testsuite/ChangeLog:
PR fortran/108937
* gfortran.dg/ibits_2.f90: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (7 preceding siblings ...)
2023-02-27 21:30 ` cvs-commit at gcc dot gnu.org
@ 2023-02-27 23:07 ` saitofuyuki at jamstec dot go.jp
2023-03-04 19:51 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: saitofuyuki at jamstec dot go.jp @ 2023-02-27 23:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #9 from saitofuyuki at jamstec dot go.jp ---
Thanks a lot for your effort. I am very happy I can contribute.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (8 preceding siblings ...)
2023-02-27 23:07 ` saitofuyuki at jamstec dot go.jp
@ 2023-03-04 19:51 ` cvs-commit at gcc dot gnu.org
2023-03-05 19:35 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-04 19:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:bb68c20e1f3c673ed00e0e1abd468d8f19cd2072
commit r12-9222-gbb68c20e1f3c673ed00e0e1abd468d8f19cd2072
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Feb 27 21:37:11 2023 +0100
Fortran: fix corner case of IBITS intrinsic [PR108937]
gcc/fortran/ChangeLog:
PR fortran/108937
* trans-intrinsic.cc (gfc_conv_intrinsic_ibits): Handle corner case
LEN argument of IBITS equal to BITSIZE(I).
gcc/testsuite/ChangeLog:
PR fortran/108937
* gfortran.dg/ibits_2.f90: New test.
(cherry picked from commit 6cce953ebec274f1468d5d3a0697cf05bb43b8f6)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (9 preceding siblings ...)
2023-03-04 19:51 ` cvs-commit at gcc dot gnu.org
@ 2023-03-05 19:35 ` cvs-commit at gcc dot gnu.org
2023-03-05 19:36 ` cvs-commit at gcc dot gnu.org
2023-03-05 19:40 ` anlauf at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-05 19:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:adc4c8eb79a75bd0f38a461c299b37c643a1153c
commit r11-10560-gadc4c8eb79a75bd0f38a461c299b37c643a1153c
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Feb 27 21:37:11 2023 +0100
Fortran: fix corner case of IBITS intrinsic [PR108937]
gcc/fortran/ChangeLog:
PR fortran/108937
* trans-intrinsic.c (gfc_conv_intrinsic_ibits): Handle corner case
LEN argument of IBITS equal to BITSIZE(I).
gcc/testsuite/ChangeLog:
PR fortran/108937
* gfortran.dg/ibits_2.f90: New test.
(cherry picked from commit 6cce953ebec274f1468d5d3a0697cf05bb43b8f6)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (10 preceding siblings ...)
2023-03-05 19:35 ` cvs-commit at gcc dot gnu.org
@ 2023-03-05 19:36 ` cvs-commit at gcc dot gnu.org
2023-03-05 19:40 ` anlauf at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-05 19:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:570828e84f751730743093e5f060eeaf98c08cac
commit r10-11241-g570828e84f751730743093e5f060eeaf98c08cac
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Feb 27 21:37:11 2023 +0100
Fortran: fix corner case of IBITS intrinsic [PR108937]
gcc/fortran/ChangeLog:
PR fortran/108937
* trans-intrinsic.c (gfc_conv_intrinsic_ibits): Handle corner case
LEN argument of IBITS equal to BITSIZE(I).
gcc/testsuite/ChangeLog:
PR fortran/108937
* gfortran.dg/ibits_2.f90: New test.
(cherry picked from commit 6cce953ebec274f1468d5d3a0697cf05bb43b8f6)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug fortran/108937] Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I).
2023-02-27 1:43 [Bug libfortran/108937] New: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to BIT_SIZE(I) saitofuyuki at jamstec dot go.jp
` (11 preceding siblings ...)
2023-03-05 19:36 ` cvs-commit at gcc dot gnu.org
@ 2023-03-05 19:40 ` anlauf at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-03-05 19:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |10.5
--- Comment #13 from anlauf at gcc dot gnu.org ---
Fixed on all open branches. Closing.
Thanks for the report!
^ permalink raw reply [flat|nested] 14+ messages in thread