Search

Wrong "this" pointer when using templates in C++ and targeting x64 Platform by Vladislav Malicevic

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 661294
Opened: 4/14/2011 7:14:17 AM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug
Compiler producing different result (result with offset) depending on target platform and build:
Release|Win32:
&range==this
Debug|Win32:
this==&range

Release|x64:
&range==this+0x10
Debug|x64:
this==&range+0xa0

Thread about this issue started in MSDN forums on Friday, March 04, 2011 1:16 PM under:

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/d2248dd0-b68d-45cd-b716-7513634b951c/
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010 SP1

What category (if any) best represents this feedback?

Reliability

Steps to reproduce

Simplified testcase located under(see README for details):

https://palo.svn.sourceforge.net/svnroot/palo/molap/client/3.X/libraries/PaloXLL/Test/offset_simplified

Product Language

English

Operating System

Windows 7

Operating System Language

German

Actual results

Release|x64:
&range==this+0x10
Debug|x64:
this==&range+0xa0

Expected results

Release|x64:
&range==this
Debug|x64:
this==&range
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 6/27/2011 at 11:24 AM
Hi Vladislav:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 6/14/2011 at 8:54 AM
Hi Vladislav,
    Thanks for reporting the issue.

    Here is the smaller repro:

#include <stdio.h>

template<class T>
class C {
public:
    struct S {
        int rw[10];
    };

    static S f()
    {
        return ((C *)0)->g();
    }

    S g()
    {
        printf("this ptr: \t '%p'\n", this);

        S cid = {};
        return cid;
    }
};

typedef C<int> type;

int main()
{
    type::f();
}

    The issue happens when you have two member functions (one is static, one is not static) and they have the same signature (it only reproes under x64 due to the fact that __thiscall and __cdecl are the same calling convention under x64) and both return a structure.

    So one possible workaround is,

    Add a dummy parameter with default argument to ‘f’ or ‘g’.
Posted by Vladislav Malicevic on 5/3/2011 at 1:16 PM
Any progress on this?
Posted by Microsoft on 4/15/2011 at 4:14 PM
Thanks for reporting this issue. I am able to reproduce the error and furthermore i was able to reduce it down to a single file repro case (~50 lines). The issue seems to involve x64 calling conventions, netsed types, retrun types, and templates. I've routed the bug to the appropriate team for further investigation. This thread will be kept up to date with our progress.

thansk,
VC++ Code Generation and Optimization Team
Posted by Vladislav Malicevic on 4/15/2011 at 8:44 AM
REG: 111041556623777
Posted by Vladislav Malicevic on 4/15/2011 at 8:41 AM
Escalated to support.
Posted by Microsoft on 4/15/2011 at 1:11 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 4/14/2011 at 8:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Vladislav Malicevic on 6/15/2011 at 5:14 AM
Thank for the feedback. With the workaround you mentioned (additional argument) it works.