[Bug c++/35585] New: Miscompiled inline assembly

2008-03-14 Thread nicos at maunakeatech dot com
The project I work on uses an inline assembly part to compute floor and ceil
functions of floating point numbers and its seems that in some cases, with
gcc-4.2 and optimizations turned on, the computed values are not correct. I
attached the smallest testcase that I could come up with to reproduce the error
and the preprocessed input. Changing the testcase a little suffices to make the
miscompilation disappear.
Since I am not an expert on inline assembly in gcc, I am not sure that the
iCeil/iFloor functions are completely correct and perhaps this is not a bug...

I was unable to reproduce the error with gcc-4.1 and gcc-4.3. The error is
still present with gcc-4.2.3. The error only appears with -O2/-O3.

Compilation command:
g++-4.2 -v -save-temps testcase.cpp -o testcase -O3
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr
--enable-targets=all --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.1 (Ubuntu 4.2.1-5ubuntu4)
 /usr/lib/gcc/i486-linux-gnu/4.2.1/cc1plus -E -quiet -v -D_GNU_SOURCE
testcase.cpp -mtune=generic -O3 -fpch-preprocess -o testcase.ii
ignoring nonexistent directory /usr/local/include/i486-linux-gnu
ignoring nonexistent directory
/usr/lib/gcc/i486-linux-gnu/4.2.1/../../../../i486-linux-gnu/include
ignoring nonexistent directory /usr/include/i486-linux-gnu
#include ... search starts here:
#include ... search starts here:
 /usr/include/c++/4.2
 /usr/include/c++/4.2/i486-linux-gnu
 /usr/include/c++/4.2/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.2.1/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.2.1/cc1plus -fpreprocessed testcase.ii -quiet
-dumpbase testcase.cpp -mtune=generic -auxbase testcase -O3 -version
-fstack-protector -fstack-protector -o testcase.s
GNU C++ version 4.2.1 (Ubuntu 4.2.1-5ubuntu4) (i486-linux-gnu)
compiled by GNU C version 4.2.1 (Ubuntu 4.2.1-5ubuntu4).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 44e55ae5d2724830dee11801424b84d8
 as --traditional-format -V -Qy -o testcase.o testcase.s
GNU assembler version 2.18 (i486-linux-gnu) using BFD version (GNU Binutils for
Ubuntu) 2.18
 /usr/lib/gcc/i486-linux-gnu/4.2.1/collect2 --eh-frame-hdr -m elf_i386
--hash-style=both -dynamic-linker /lib/ld-linux.so.2 -o testcase
/usr/lib/gcc/i486-linux-gnu/4.2.1/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.2.1/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.2.1/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.2.1 -L/usr/lib/gcc/i486-linux-gnu/4.2.1
-L/usr/lib/gcc/i486-linux-gnu/4.2.1/../../../../lib -L/lib/../lib
-L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.2.1/../../.. testcase.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/i486-linux-gnu/4.2.1/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.2.1/../../../../lib/crtn.o


-- 
   Summary: Miscompiled inline assembly
   Product: gcc
   Version: 4.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nicos at maunakeatech dot com
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35585



[Bug c++/35585] Miscompiled inline assembly

2008-03-14 Thread nicos at maunakeatech dot com


--- Comment #1 from nicos at maunakeatech dot com  2008-03-14 16:26 ---
Created an attachment (id=15317)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15317action=view)
Testcase to reproduce the bug


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35585



[Bug c++/35585] Miscompiled inline assembly

2008-03-14 Thread nicos at maunakeatech dot com


--- Comment #2 from nicos at maunakeatech dot com  2008-03-14 16:29 ---
Created an attachment (id=15318)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15318action=view)
Preprocessed testcase


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35585



[Bug c++/35585] Miscompiled inline assembly

2008-03-14 Thread nicos at maunakeatech dot com


--- Comment #4 from nicos at maunakeatech dot com  2008-03-15 01:07 ---
I think I need some help here, I looked to bug 323 and I can't see how it is
related to this issue.
The assertion at the end of the test case compares integers, and the iFloor
function is only applied to 0 in the test. My problem is that the result in
sp.bbox[0] seems total garbage.
I looked at the assembly code generated by gcc (-S flag), the portion
corresponding to:

sp.bbox[0] = std::min(sp.bbox[0], iFloor(txcum) );

is:

.L201:
fld %st(1)
fadd%st(2), %st
fsubs   .LC4
#APP
fistpl -44(%ebp)
#NO_APP
movl-44(%ebp), %edi
movl-88(%ebp), %eax
sarl%edi
cmpl16(%ebx), %edi
jge .L204
leal-28(%ebp), %eax
.L204:
fld %st(0)
movl(%eax), %eax
fadd%st(1), %st
fsubs   .LC4
movl%eax, 16(%ebx)

The result of iFloor is stored in %edi but whatever the result of cmpl, the
value in %edi isn't used (instead the value at -28(%ebp), which appears to be
uninitialized, is stored into sp.bbox[0]).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35585



[Bug c++/25260] [4.0/4.1/4.2 Regression] Forward explicit intantiation declaration doesn't mix well with static integral member

2005-12-20 Thread nicos at maunakeatech dot com


--- Comment #3 from nicos at maunakeatech dot com  2005-12-20 09:20 ---
I was under the belief that out of class definitions of const static integral
members was optional for gcc and that static const N = k; was equivalent to
enum { N = k};, was I wrong ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25260



[Bug c++/25260] New: Forward explicit intantiation declaration doesn't mix well with static integral member

2005-12-05 Thread nicos at maunakeatech dot com
Compiling:
templateclass T
class A
{
public:
   static const unsigned int n = 1;

   void foo ()
   {
  int i = n;
   }
};

extern template class Aint;

int main ()
{
   Aint a;
   a.foo ();
}

fails with:
foo.cpp: In member function 'void AT::foo() [with T = int]':
foo.cpp:9:   instantiated from 'const unsigned int Aint::n'
foo.cpp:9:   instantiated from 'void AT::foo() [with T = int]'
foo.cpp:18:   instantiated from here
foo.cpp:9: error: explicit instantiation of 'Aint::n' but no definition
available
foo.cpp:9:   instantiated from 'const unsigned int Aint::n'
foo.cpp:9:   instantiated from 'void AT::foo() [with T = int]'
foo.cpp:18:   instantiated from here
foo.cpp:9: error: explicit instantiation of 'Aint::n' but no definition
available


-- 
   Summary: Forward explicit intantiation declaration doesn't mix
well with static integral member
   Product: gcc
   Version: 4.0.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nicos at maunakeatech dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25260



[Bug c/23077] New: Invalid code with O2 flag (bad alias analysis?)

2005-07-26 Thread nicos at maunakeatech dot com
Source code:
#include stdio.h

int main (int argc, char * argv[])
{
   unsigned int t[2] = {1, 1};  
   *((double *)t) = 0.0;   
   
   printf(%d\n, t[1]);   
}

This code prints 1 insted of 0 when with: gcc foo.c -o foo -O2
Output of gcc -v foo.c -o foo2 -O2:
Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: /var/tmp/portage/gcc-3.4.4/work/gcc-3.4.4/configure
--enable-version-specific-runtime-libs --prefix=/usr
--bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.4.4
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.4
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.4/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.4/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include/g++-v3
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --disable-libunwind-exceptions --disable-multilib
--disable-libgcj --enable-languages=c,c++,f77 --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8)
 /usr/libexec/gcc/i686-pc-linux-gnu/3.4.4/cc1 -quiet -v foo.c -quiet -dumpbase
foo.c -mtune=pentiumpro -auxbase foo -O2 -version -o /tmp/ccFePbg2.s
ignoring nonexistent directory /usr/local/include
ignoring nonexistent directory
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../i686-pc-linux-gnu/include
#include ... search starts here:
#include ... search starts here:
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include
 /usr/include
End of search list.
GNU C version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8) (i686-pc-linux-gnu)
compiled by GNU C version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, 
pie-8.7.8).
GGC heuristics: --param ggc-min-expand=90 --param ggc-min-heapsize=113127
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../i686-pc-linux-gnu/bin/as -V
-Qy -o /tmp/ccokr9zW.o /tmp/ccFePbg2.s
GNU assembler version 2.16.1 (i686-pc-linux-gnu) using BFD version 2.16.1
 /usr/libexec/gcc/i686-pc-linux-gnu/3.4.4/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o foo2
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../crt1.o
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../crti.o
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/crtbegin.o
-L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4 -L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4
-L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../i686-pc-linux-gnu/lib
-L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../.. /tmp/ccokr9zW.o -lgcc -lgcc_eh
-lc -lgcc -lgcc_eh /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/crtend.o
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../crtn.o

I suspect that the alias analysis use an incorrect size for double.

-- 
   Summary: Invalid code with O2 flag (bad alias analysis?)
   Product: gcc
   Version: 3.4.4
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nicos at maunakeatech dot com
CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23077