Incorrect code generated when returning struct by value and compiling for x86. - by Johan Lindvall

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 649953 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 3/7/2011 9:06:56 AM
Access Restriction Public

Description

Returning a declared struct by value causes the x86 compiler to generate incorrect code (debug and release).
Sign in to post a comment.
Posted by Xiang [MSFT] on 6/14/2011 at 8:51 AM
Hi Johan,
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.
    Here is a simplified repro:

a.cpp

struct A {int i;};
 
template <typename T> T f();
 
int main()
{
    f<A>();
}

b.cpp:

template <typename T> T f();
 
struct A;
 
template <> A f<A>();
 
struct A {int i;};
 
template <>
A f<A>()
{
    A q = {};
    return q;
}

cl a.cpp b.cpp

    a.exe will crash at runtime.

    The workaround is to do the explicit instantiation "template <> A f<A>();" after the definition of A.

Xiang Fan
Visual C++ Team
Posted by Ian [MSFT] on 3/9/2011 at 11:58 AM
Thanks for reporting this issue. We're still investigating the problem, but it looks like the root cause is different header inclusion order in the two .cpp files. As a work around you can change your header inclusion order in each .cpp file to be the same.

thanks,
VC++ Code Generation and Optimization Team
Posted by Microsoft on 3/7/2011 at 7:13 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 3/7/2011 at 9: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)