[Bug c/14005] New: gcc rounds up when it should round down
lduncan at pillardata dot com
gcc-bugzilla@gcc.gnu.org
Tue Feb 3 18:48:00 GMT 2004
when trying to round and address down, the compiler rounds up if the sign bit is set on the
address (and it is marked as signed).
dot-i file that fails:
main ( )
{
void * pg_ptr1 , * pg_ptr2 ;
const void * addr1 = ( void * ) 0xfedcba98 ;
const void * addr2 = ( void * ) 0x1edcba98 ;
pg_ptr1 = ( void * ) ( ( ( long ) ( addr1 ) / 4096 ) * 4096 ) ;
pg_ptr2 = ( void * ) ( ( unsigned int ) ( addr1 ) & ~ ( 4096 - 1 ) ) ;
( void ) printf ( "orig=0x%x, rounding down using val=0x%x\n" , addr1 , 4096 ) ;
( void ) printf ( "result: pg_ptr1=0x%p and pg_ptr2=0x%p => %sequal\n" ,
pg_ptr1 , pg_ptr2 , ( pg_ptr1 == pg_ptr2 ) ? "" : "NOT " ) ;
pg_ptr1 = ( void * ) ( ( ( long ) ( addr2 ) / 4096 ) * 4096 ) ;
pg_ptr2 = ( void * ) ( ( unsigned int ) ( addr2 ) & ~ ( 4096 - 1 ) ) ;
( void ) printf ( "orig=0x%x, rounding down using val=0x%x\n" , addr2 , 4096 ) ;
( void ) printf ( "result: pg_ptr1=0x%p and pg_ptr2=0x%p => %sequal\n" ,
pg_ptr1 , pg_ptr2 , ( pg_ptr1 == pg_ptr2 ) ? "" : "NOT " ) ;
}
compiled with "gcc test_prog.c" (i.e. no options)
output from "gcc -v":
Reading specs from /usr/libexec/gcc/darwin/ppc/3.1/specs
Thread model: posix
Apple Computer, Inc. GCC version 1151, based on gcc version 3.1 20020420 (prerelease)
Also found same problem on versions 3.2 (SPARC) and 2.95.3 (QNX cross compiler from SPARC to
PowerPC)
--
Summary: gcc rounds up when it should round down
Product: gcc
Version: 3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: lduncan at pillardata dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: PowerPC/Apple Darwin (OS X)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14005
More information about the Gcc-bugs
mailing list