This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/40019] New: LEADZ and TRAILZ give wrong results
- From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 May 2009 19:36:25 -0000
- Subject: [Bug fortran/40019] New: LEADZ and TRAILZ give wrong results
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
LEADZ and TRAILZ can give wrong results for kinds other than 4 and 8. For
example, the following code:
integer(kind=1) :: i1
integer(kind=2) :: i2
integer(kind=4) :: i4
integer(kind=8) :: i8
integer(kind=16) :: i16
i1 = -1
i2 = -1
i4 = -1
i8 = -1
i16 = -1
print *, leadz(i1), leadz(i2), leadz(i4), leadz(i8), leadz(i16)
gives " -24 -16 0 0 64" as results,
while it should only yield zeros!
There are a few reasons:
- for kinds 1 and 2, we should not cast directly to (unsigned int), but do a
double cast: (unsigned int)(unsigned char) for kind=1, for example; otherwise,
negative values are screwed.
- trans-intrinsic.c uses a correspondance, kinds == 1, 2 and 4 use
BUILT_IN_CLZ, kind 8 uses BUILT_IN_CLZL and kind 16 uses BUILT_IN_CLZLL; in
reality, there is no such correspondance, as kind==16 is larger than long long!
This, of course, makes it harder, because there is no function ready for use in
kind==16.
--
Summary: LEADZ and TRAILZ give wrong results
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fxcoudert at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40019