https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108937
Bug ID: 108937
Summary: Intrinsic IBITS(I,POS,LEN) fails when LEN equals to
BIT_SIZE(I).
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
Assignee: unassigned at gcc dot gnu.org
Reporter: saitofuyuki at jamstec dot go.jp
Target Milestone: ---
Created attachment 54539
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54539&action=edit
A minimum patch to fix ibits().
gfc_conv_intrinsic_ishft(), e.g, in gcc/fortran/trans-intrinsic.cc
catches a special case when shift widths GE BIT_SIZE at LSHIFT_EXPR
operation, which is not performed in gfc_conv_intrinsic_ibits.
I attached a minimum patch, and also a test program.
The output of the program before/after patch are as follow:
------------------------ before patch
IBITS(-1,0,32)
intrinsic 0 00000000000000000000000000000000
expected -1 11111111111111111111111111111111
------------------------ after patch
IBITS(-1,0,32)
intrinsic -1 11111111111111111111111111111111
expected -1 11111111111111111111111111111111
As far as I checked, this is a long-standing bug. At least gfortran
10.4.0, 11.3.0, 12.2.0, and the latest one
(4341106354c6a463ce3628a4ef9c1a1d37193b59).