public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/40019]  New: LEADZ and TRAILZ give wrong results
Date: Mon, 04 May 2009 19:36:00 -0000	[thread overview]
Message-ID: <bug-40019-10259@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2009-05-04 19:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-04 19:36 fxcoudert at gcc dot gnu dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-40019-10259@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).