From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18757 invoked by alias); 4 May 2009 19:36:41 -0000 Received: (qmail 18673 invoked by uid 48); 4 May 2009 19:36:25 -0000 Date: Mon, 04 May 2009 19:36:00 -0000 Subject: [Bug fortran/40019] New: LEADZ and TRAILZ give wrong results X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "fxcoudert at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-05/txt/msg00250.txt.bz2 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