public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40019]  New: LEADZ and TRAILZ give wrong results
@ 2009-05-04 19:36 fxcoudert at gcc dot gnu dot org
  2009-05-19 22:24 ` [Bug fortran/40019] " fxcoudert at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-05-04 19:36 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-06-03 19:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-04 19:36 [Bug fortran/40019] New: LEADZ and TRAILZ give wrong results fxcoudert at gcc dot gnu dot org
2009-05-19 22:24 ` [Bug fortran/40019] " fxcoudert at gcc dot gnu dot org
2009-05-27  7:45 ` burnus at gcc dot gnu dot org
2009-05-27 10:28 ` fxcoudert at gcc dot gnu dot org
2009-05-29 21:28 ` burnus at gcc dot gnu dot org
2009-05-29 21:34 ` burnus at gcc dot gnu dot org
2009-06-03 19:39 ` [Bug fortran/40019] [4.4 only] " burnus at gcc dot gnu dot org
2009-06-03 19:40 ` [Bug fortran/40019] " burnus at gcc dot gnu dot org
2009-06-03 19:56 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).