Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:36:46+00:00 2026-06-03T01:36:46+00:00

GCC 4.5.2 (on Ubuntu 11.10 x64 but compiling for 32 bit) generates invalid assembly

  • 0

GCC 4.5.2 (on Ubuntu 11.10 x64 but compiling for 32 bit) generates invalid assembly code and I’m curious if it’s possible to fix without changing code, just by applying options or something like that. Note that optimization is already -O0.

I have two functions:

inline long Class::Get()
{
    long v = *(long*)(m_p);
    m_p += 4;
    return v;
}
inline void Class::Command()
{
    m_p += Get();
}

GCC 4.5.2 generates this assembly code:

 9840       m_p += Get();
f689eff5:   mov 0x8(%ebp),%eax
f689eff8:   mov 0xd4(%eax),%eax
f689effe:   mov %eax,%esi
f689f000:   mov 0x8(%ebp),%eax
f689f003:   mov %eax,(%esp)
f689f006:   call 0xf66116a0
f689f00b:   lea (%esi,%eax,1),%edx
f689f00e:   mov 0x8(%ebp),%eax
f689f011:   mov %edx,0xd4(%eax)

As you can see it stores m_p value in %esi and later adds returned value to it using lea. BUT ::Get() does also change m_p! which GCC doesn’t seem to be aware of. Thus the bug, m_p is incorrect (4 bytes less than expected) because value in %esi is obsolete.

I can fix it using

inline void Class::Command()
{
    long v = Get();
    m_p += v;
}

But I’m just wondering if I can apply some pragma or smth like that, without changing the code, to make the bug go away. As for gcc version I’m stuck with the given one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:36:48+00:00Added an answer on June 3, 2026 at 1:36 am

    That’s not a bug. As you know, m_p += Get(); is really m_p = m_p + Get();. The compiler is free to chose the order of evaluation for the addition. So fetching m_p, then executing Get(), then doing the addition is valid, and creates the code you just posted.

    Your second example is different because you created a new sequence point. In this case Get() is always evaluated first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Ubuntu 8.10 (Intrepid Ibex) and compiling C++ files with GCC, but when
I'm using GCC 4.3.3 on Ubuntu 9.04 64-bit and was getting errors using C++-style
I'm currently switch from ubuntu 11.04 (gcc 4.5) to ubuntu 12.04 (but I have
I'm using Linux Ubuntu Intrepid Ibex and using as compiler the gcc , but
I am using Ubuntu 9.10 For a particular piece of code I require GCC
I want to install gcc-4.3 but it's not installed in Ubuntu 11.10. How can
Using gcc on Ubuntu, should there be a (speed) performance difference if compiling the
I tried to install gcc 4.5 on ubuntu 10.04 but failed. Here is a
My program is written in C++, using GCC on Ubuntu 9.10 64 bit. If
Just curious. Using gcc/gdb under Ubuntu 9.10. Reading a C book that also often

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.