public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mawenqi108 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/55131] Segmentation fault happened in resulting code (inline-asm) after upgraded g++ from 3.4.6 to 4.7.0
Date: Tue, 30 Oct 2012 06:22:00 -0000	[thread overview]
Message-ID: <bug-55131-4-tI2quNZyzE@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-55131-4@http.gcc.gnu.org/bugzilla/>


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

mawenqi <mawenqi108 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
          Component|inline-asm                  |c++
            Version|4.7.0                       |unknown
         Resolution|INVALID                     |
           Severity|normal                      |blocker

--- Comment #2 from mawenqi <mawenqi108 at gmail dot com> 2012-10-30 06:22:07 UTC ---
(In reply to comment #1)
> This is not a bug.
> The produced assembly looks like:
>        movl        8(%ebp), %edi # %1
>        movl        12(%ebp), %esi# %2
>        movl        0(%esi), %eax
>        movl        4(%esi), %edx
>        movl        (%ecx), %ebx# %3
>        movl        (%eax), %ecx# %4
> 
> By the time the last statement happens, eax has already been clobbered.  You
> never said you are clobber eax in the inline-asm so it chose the 4th operand as
> being eax.  You were getting lucky in 3.4.6 with the inline-asm really,
> 
> 
> I don't see why you don't use the __sync_* (or even better the __atomic_*)
> builtins for doing the compare and swap?

Thanks a lot for your help!
This is the old legacy code. After replaced original implementation with
buildin function __atomic_compare_exchange_n, now everything is fine!
static inline bool MyAtomic_CAS64(volatile unsigned long long* tgt, 
                                    unsigned long long* old,
                                    unsigned long long rep)
{
        return __atomic_compare_exchange_n(tgt, old, rep, 
                false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}

Thanks again!


  parent reply	other threads:[~2012-10-30  6:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30  2:17 [Bug c++/55131] New: Segmentation fault happened " mawenqi108 at gmail dot com
2012-10-30  2:21 ` [Bug c++/55131] Segmentation fault happened in resulting code (inline-asm) " pinskia at gcc dot gnu.org
2012-10-30  2:28 ` [Bug inline-asm/55131] " pinskia at gcc dot gnu.org
2012-10-30  6:22 ` mawenqi108 at gmail dot com [this message]
2012-10-30  6:25 ` [Bug c++/55131] " mawenqi108 at gmail dot com
2012-10-30  9:28 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-55131-4-tI2quNZyzE@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).