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

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 661294 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/14/2011 7:14:17 AM
Access Restriction Public

Description

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/
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)