Bug 46682 - __sync_bool_compare_and_swap generates wrong code
Summary: __sync_bool_compare_and_swap generates wrong code
Status: RESOLVED DUPLICATE of bug 45292
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-11-27 05:36 UTC by Udo Steinberg
Modified: 2010-11-27 17:28 UTC (History)
1 user (show)

See Also:
Host:
Target: i?86-*-*, x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase (362 bytes, application/octet-stream)
2010-11-27 05:36 UTC, Udo Steinberg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Udo Steinberg 2010-11-27 05:36:02 UTC
Created attachment 22544 [details]
Testcase

Compile testcase with:

gcc-4.5.1  -MP -MMD -pipe -m32 -Os -march=i686 -mpreferred-stack-boundary=2 -mregparm=3 -fdata-sections -ffunction-sections -fomit-frame-pointer -freg-struct-return -freorder-blocks -funit-at-a-time -fno-exceptions -fno-rtti -fno-stack-protector -fvisibility-inlines-hidden -Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdisabled-optimization -Wformat=2 -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wshadow -Wwrite-strings -Wabi -Wctor-dtor-privacy -Wno-non-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wsign-promo -Wframe-larger-than=64 -Wlogical-op -Wstrict-null-sentinel -Wstrict-overflow=5 -Wvolatile-register-var -c testcase.cc -o testcase.o

This results in:

00000000 <Ec::generate_wrong_code()>:
   0:   53                      push   %ebx
   1:   b8 01 00 00 00          mov    $0x1,%eax
   6:   e8 fc ff ff ff          call   7 <Ec::generate_wrong_code()+0x7>
   b:   31 d2                   xor    %edx,%edx
   d:   31 c9                   xor    %ecx,%ecx
   f:   6a 00                   push   $0x0
  11:   6a 00                   push   $0x0
  13:   6a 00                   push   $0x0
  15:   89 c3                   mov    %eax,%ebx
  17:   e8 fc ff ff ff          call   18 <Ec::generate_wrong_code()+0x18>
  1c:   8b 15 00 00 00 00       mov    0x0,%edx
  22:   31 c0                   xor    %eax,%eax
  24:   f0 0f b1 1a             lock cmpxchg %ebx,(%edx)
  28:   83 c4 0c                add    $0xc,%esp
  2b:   74 07                   je     34 <Ec::generate_wrong_code()+0x34>
  2d:   b8 01 00 00 00          mov    $0x1,%eax
  32:   eb 02                   jmp    36 <Ec::generate_wrong_code()+0x36>
  34:   31 c0                   xor    %eax,%eax
  36:   e8 fc ff ff ff          call   37 <Ec::generate_wrong_code()+0x37>

The "add" at offset 28 is messing up the flags for the "je" at offset 2b.
Comment 1 Jakub Jelinek 2010-11-27 17:28:19 UTC
Fixed for a long time already.

*** This bug has been marked as a duplicate of bug 45292 ***