Mailinglist Archive: opensuse-bugs (7184 mails)

< Previous Next >
[Bug 355532] New: gcc produce incorrect code for "abs"
  • From: bugzilla_noreply@xxxxxxxxxx
  • Date: Wed, 23 Jan 2008 00:44:27 -0700 (MST)
  • Message-id: <bug-355532-21960@xxxxxxxxxxxxxxxxxxxxxxxxx/>
https://bugzilla.novell.com/show_bug.cgi?id=355532

User Ralf.Klingebiel@xxxxxxxxxx added comment
https://bugzilla.novell.com/show_bug.cgi?id=355532#c1

Summary: gcc produce incorrect code for "abs"
Product: openSUSE 10.3
Version: Final
Platform: i586
OS/Version: openSUSE 10.3
Status: NEW
Severity: Major
Priority: P5 - None
Component: Development
AssignedTo: pth@xxxxxxxxxx
ReportedBy: Ralf.Klingebiel@xxxxxxxxxx
QAContact: qa@xxxxxxx
Found By: Customer


When compiling this:

extern int abs (int __x) __attribute__ ((__nothrow__)) __attribute__
((__const__)) ;
extern int printf (__const char *__restrict __format, ...);


char buffer[] = "_ohne_Funktion";

static int dia_msc_hashcode (const char *text) {
int hashcode = 0;
const char *p = text;

while (*p){
hashcode = hashcode*37 + (int) (*p & 0x7f);
p++;
}

printf("hashcode=%d\n",hashcode);

return hashcode;

}


int main( void ) {
int i;
i = abs(dia_msc_hashcode(buffer) % 1009);
printf( "%d\n", i ); /* cc -O3 => -97 !!
cc -O2 => 97 */
return 0;
}


with this command:
cc -O3

this happens:

prints -97

with this system:Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1
--enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2
--enable-version-specific-runtime-libs --without-system-libunwind
--with-cpu=generic --host=i586-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)

Linux 2.6.22.5-31-default #1 SMP 2007/09/21 22:29:00 UTC i686 i686 i386
GNU/Linux


I instead expect this to happen:

prints 97


--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

< Previous Next >