Search

Incorrect code generation for __restrict keyword with full optimization by Ilya Grebnov

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 739798
Opened: 4/29/2012 8:57:07 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
Please compile and test attached C++ application for Debug and Release targets. Note, this sample app is simplified version my actual application. Application is cross platform and work well with GCC, Clang and Intel C++, but crashes when compiled with Visual Studio 2010.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

#include <stdio.h>
#include <stdlib.h>

void init(int * p) { *p = 10; }

int main(int argc, char** argv)
{
    int var;

    init(&var);

     for (int i = 0; i < 1; i++)
    {
        int * __restrict ptr = &var;

        printf("%d", *ptr);
    };

    return 0;
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

1. In debug mode actual result is 10 which is expected.
2. In release mode actual result is 1820149524 which is garbage.

Investigation in asm output is showing that "init(&var);" statement is not compiled, so this is cause to app to produce incorrect result in Release mode.

Expected results

Expected 10 for both cases.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/4/2012 at 8:02 AM
Hi, thanks for the bug report. The C++ compiler optimizer has struggled when a __restrict pointer is pointing to a local or global variable. I have fixed this for the VS11 release.

For what it's worth, __restrict gives the best performance benefits when you mark paramters to a function as being restrict (and to some extent, return values of functions). Setting, for example, int * __restrict p = &g; is a little weird. Regardless, I have fixed the bug in the optimizer -- we should not be generating bad code here.

You probably know this already, but if you need a workaround try removing __restrict.

Eric
Microsoft Visual C++
Posted by MS-Moderator07 [Feedback Moderator] on 4/30/2012 at 1:49 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 MS-Moderator01 on 4/29/2012 at 9:43 PM
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.