Hi , are you getting the bug with latest trunk on this code. If you can tell me , i'll forward it to debian/ubuntu mainters.
On Sat, Aug 23, 2008 at 4:07 AM, Niklaus <[EMAIL PROTECTED]> wrote:
> hi,
> -O0 gives me correct output
> but -O1 or -O2 gives me wrong output. i've attached .s files.
> Can it be a distro (ubuntu ) problem ?
>
> i tried with gcc-3.4 on ubuntu , 4.1,4.2 on ubuntu.
>
> Can some body tell me which file in gcc handles the overflow ?
> Files to look at in gcc or distro gcc-source ?
>
>
> On Sat, Aug 23, 2008 at 3:55 AM, Niklaus <[EMAIL PROTECTED]> wrote:
>> hi andrew,
>> this is C code. I don't use the functions ispow2 etc.
>>
>> see the code below .
>>
>>
>> [EMAIL PROTECTED]:/home/junk/prog/tju# gcc bug_short.c -lm -O2
>> [EMAIL PROTECTED]:/home/junk/prog/tju# ./a.out
>> 2383,1
>> 31727,1
>> 132265613,1
>> 3145439247023686464
>> [EMAIL PROTECTED]:/home/junk/prog/tju# gcc bug_short.c -lm
>> [EMAIL PROTECTED]:/home/junk/prog/tju# ./a.out
>> 2383,1
>> 31727,1
>> 132265613,1
>> 10004511787964928
>> [EMAIL PROTECTED]:/home/junk/prog/tju# cat bug_short.c
>> #include<stdio.h>
>> #include<math.h>
>> typedef unsigned long long ull;
>> ull
>> gcd (ull a, ull b)
>> {
>> if (b == 0)
>> return a;
>> return gcd (b, a % b);
>> }
>> int
>> main ()
>> {
>> ull numprod, denprod, gg;
>> ull arr[] = { 2383, 31727, 132265613 };
>> ull acnt[] = {1,1,1};
>> int cntm = sizeof (arr) / sizeof (arr[0]), i;
>> numprod = denprod = 1;
>> for (i = 0; i <cntm; i++)
>> {
>> ull a = arr[i], b = acnt[i];
>> printf ("%llu,%llu\n", a, b);
>> ull num = (ull) (pow ((double) a, (double) b + 1) - 1);
>> ull den = a - 1;
>> gg = gcd (num, den);
>> num /= gg;
>> den /= gg;
>> numprod *= num;
>> denprod *= den;
>> gg = gcd (numprod, denprod);
>> numprod /= gg;
>> denprod /= gg;
>> }
>> gg = gcd (numprod, denprod);
>> numprod /= gg;
>> denprod /= gg;
>> printf ("%llu\n", numprod);
>> return 0;
>> }
>> [EMAIL PROTECTED]:/home/junk/prog/tju#
>>
>>
>> [EMAIL PROTECTED]:~/prog/tju$ gcc bug_short.c -Wall -Wstrict-overflow=2 -lm
>> [EMAIL PROTECTED]:~/prog/tju$ gcc bug_short.c -Wall -Wstrict-overflow=2 -lm
>> -O2
>> [EMAIL PROTECTED]:~/prog/tju$ gcc -v
>> 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-objc-gc
>> --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.3 (Ubuntu 4.2.3-2ubuntu7)
>> [EMAIL PROTECTED]:~/prog/tju$
>>
>>
>> Do you want the asm files or other files ? tell me how to give to
>> you. you want me to do gcc -S and send you the output ?
>>
>> On Sat, Aug 23, 2008 at 3:48 AM, Andrew Pinski <[EMAIL PROTECTED]> wrote:
>>> On Fri, Aug 22, 2008 at 3:14 PM, Andrew Pinski <[EMAIL PROTECTED]> wrote:
>>>> On Fri, Aug 22, 2008 at 2:47 PM, Niklaus <[EMAIL PROTECTED]> wrote:
>>>>> Hi,
>>>>>
>>>>>
>>>>> When i run with the options g++ prog.c -o prog and run the exectuable
>>>>> it gives me the correct output
>>>>> but when i do g++ prog.c -o prog -O2 i get the wrong output
>>>>>
>>>
>>> Note by the way I think your ispow2 is incorrect. It is doing a "a ==
>>> 1 & a != 0" and not ((a-1)&a) == 0. We do warn about this too:
>>> t.c:189: warning: suggest parentheses around comparison in operand of &
>>>
>>>
>>> -- Pinski
>>>
>>
>
bug_short.c
Description: Binary data
