Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JumpTable::PatchCallSites has dead code that seems intended to do something? #75

Open
danluu opened this issue Mar 23, 2017 · 0 comments

Comments

@danluu
Copy link
Contributor

danluu commented Mar 23, 2017

    void JumpTable::PatchCallSites()
    {
        for (size_t i=0; i < m_callSites.size(); ++i)
        {
            const CallSite& site = m_callSites[i];
            const uint8_t* labelAddress = AddressOfLabel(site.GetLabel());
            uint8_t* siteAddress = site.Site();
            ptrdiff_t delta = labelAddress - siteAddress - site.Size();

            // TODO: Evaluate whether special cases for size == 2 and size == 4 actually improve performance.
            size_t size = site.Size();
            if (size == 2)
            {
                LogThrowAssert(delta <= std::numeric_limits<int16_t>::max() &&
                               delta >= std::numeric_limits<int16_t>::min(),
                               "Overflow/underflow in cast to int16_t.");
                *(reinterpret_cast<int16_t*>(siteAddress)) = static_cast<int16_t>(delta);
                siteAddress += size;  // <----------- CODE DOES NOTHING
            }
            else if (size == 4)
            {
                LogThrowAssert(delta <= std::numeric_limits<int32_t>::max() &&
                               delta >= std::numeric_limits<int32_t>::min(),
                               "Overflow/underflow in cast to int32_t.");
                *(reinterpret_cast<int32_t*>(siteAddress)) = static_cast<int32_t>(delta);
                siteAddress += size;  // <----------- CODE DOES NOTHING
            }
            else
            {
                while (size > 0)
                {
                    *siteAddress++ = static_cast<uint8_t>(delta);
                    delta = delta >> 8;
                    size--;
                }
            }
        }
    }

siteAddress += size doesn't do anything. I haven't looked at this to figure out what the intent is. It's possible it would be fine to just delete these useless lines, but it's also possible that we have a bug here and something else was intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant