Launchpad has imported 4 comments from the remote bug at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42553.

If you reply to an imported comment from within Launchpad, your comment
will be sent to the remote bug automatically. Read more about
Launchpad's inter-bugtracker facilities at
https://documentation.ubuntu.com/launchpad/user/reference/bugs/multi-project-bugs/about-multi-project-bugs/#bugs-in-external-trackers.

------------------------------------------------------------------------
On 2009-12-30T12:56:51+00:00 Debian GCC maintainers wrote:

current trunk/branches on x86_64-linux-gnu. return values with different
compilers and different optimizations:

         -O0  -O1  -O2  -O3
gcc-4.1   0    2    2    2
gcc-4.3   0    2    2    2
gcc-4.4   2    0    0    0
gcc-4.5   0    1    0    0

  Matthias

#include <stdbool.h>
#include <stdio.h>

static bool atomic_test_and_reset_bit(unsigned long *v,unsigned long bit) {
  bool res;

  __asm__ __volatile__( "btr %2,%1\n"
                        "adc $0,%0\n"
                        :"=r"(res), "=m"(*v)
                        :"r"(bit), "r"(0)) ;
  return res ? 1 : 0;
}

int main(void)
{
  unsigned long flags = 0;
  int j;

  j = atomic_test_and_reset_bit(&flags, 2);

  printf("%d\n", j);

  return 0;
}

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/434527/comments/2

------------------------------------------------------------------------
On 2009-12-30T13:14:52+00:00 Pinskia-gmail wrote:

Subject: Re:   New: wrong code with -O1


Sent from my iPhone

On Dec 30, 2009, at 7:56 AM, "debian-gcc at lists dot debian dot org" 
<[email protected] 
 > wrote:

> current trunk/branches on x86_64-linux-gnu. return values with  
> different
> compilers and different optimizations:
>
>         -O0  -O1  -O2  -O3
> gcc-4.1   0    2    2    2
> gcc-4.3   0    2    2    2
> gcc-4.4   2    0    0    0
> gcc-4.5   0    1    0    0
>
>  Matthias
>
> #include <stdbool.h>
> #include <stdio.h>
>
> static bool atomic_test_and_reset_bit(unsigned long *v,unsigned long  
> bit) {
>  bool res;
>
>  __asm__ __volatile__( "btr %2,%1\n"
>                        "adc $0,%0\n"
>                        :"=r"(res), "=m"(*v)
>                        :"r"(bit), "r"(0)) ;
>  return res ? 1 : 0;

This inline-asm looks wrong. Because it says *v is always overriden.  
So if that function is inlined, flags down below does not have to be  
set before it.

> }
>
> int main(void)
> {
>  unsigned long flags = 0;
>  int j;
>
>  j = atomic_test_and_reset_bit(&flags, 2);
>
>  printf("%d\n", j);
>
>  return 0;
> }
>
>
> -- 
>           Summary: wrong code with -O1
>           Product: gcc
>           Version: 4.4.3
>            Status: UNCONFIRMED
>          Severity: normal
>          Priority: P3
>         Component: target
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: debian-gcc at lists dot debian dot org
> GCC target triplet: x86_64-linux-gnu
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42553
>


Reply at: 
https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/434527/comments/4

------------------------------------------------------------------------
On 2009-12-30T14:33:01+00:00 Pinskia wrote:

The inline-asm is totally incorrect here is the corrected version of the 
function (note res should be set):
static bool atomic_test_and_reset_bit(unsigned long *v,unsigned long bit) {
  bool res = 0;

  __asm__ __volatile__( "btr %2,%1\n"
                        "adc $0,%0\n"
                        :"+r"(res): "m"(*v)
                        ,"r"(bit), "r"(0): "flags") ;
  return res ? 1 : 0;
}

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/434527/comments/5

------------------------------------------------------------------------
On 2010-01-04T16:07:49+00:00 Ubizjak wrote:

(In reply to comment #2)
> The inline-asm is totally incorrect here ...

Actually, the asm is correct, it is just a couple of volatiles that are
missing. Please see arch/x86/include/asm/bitops.h from linux-2.6 for
correct implementation.


Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/434527/comments/7

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/434527

Title:
  [PR42553] Compiled program misbehaves

To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/434527/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to