Search

Internal compiler error C1001 when compiling OpenCV 2.1/2.2 with C++/CLI 64 bit by Chee Pin

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 629931
Opened: 12/8/2010 5:19:48 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Hi,
I tried to compile a C++/CLI 64-bit .net application with OpenCV 2.1/2.2 and found out that by just doing simple stuff as below will cause internal compiler error.

Any workaround is appreciated. I need to eventually build a .net class library using OpenCV using C++/CLI. I have reconfigured OpenCV to be in 64-bit using CMake 2.8.

#include "stdafx.h"
#include <opencv/cv.h>

using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    return 0;
}

The line "#include <opencv/cv.h>" will cause the compile error

Attached is the error log

1>------ Rebuild All started: Project: netcv, Configuration: Debug x64 ------
1> AssemblyInfo.cpp
1> netcv.cpp
1> stdafx.cpp
1> Generating Code...
1>c:\opencv-2.2.0\bin\include\opencv2\core\mat.hpp(379): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\wvm\mdmiscw.c', line 2704)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

1. Download OpenCV 2.2 or 2.1 source, configure it to 64-bit using CMake GUI 2.8 and recompile using VS2010. Make sure the "INSTALL" project is included in the build when compiling.

2. Create a C++/CLI .net console application with the simple following code

#include "stdafx.h"
#include <opencv/cv.h>

using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    return 0;
}

Compile the simple hello world program. You will notice mat.hpp is causing internal compiler error.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

1>------ Rebuild All started: Project: netcv, Configuration: Debug x64 ------
1> AssemblyInfo.cpp
1> netcv.cpp
1> stdafx.cpp
1> Generating Code...
1>c:\opencv-2.2.0\bin\include\opencv2\core\mat.hpp(379): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\wvm\mdmiscw.c', line 2704)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Expected results

expected to compile fine. As it compiles ok in 32 bit environment.
File Attachments
0 attachments
Sign in to post a comment.
Posted by joatski on 3/25/2011 at 6:25 PM
Does the bug that caused this affect any other intrinsics / library calls?

We're also running into this issue compiling some other C++/cli code (not open CV), but trying to trick the compiler with the 64 bit interlocked add (or even removing all interlocked adds just to see if that would compile) results in the same compiler error on the same file.
Posted by Chee Pin on 1/6/2011 at 4:52 PM
Thanks for the update. In fact, i managed to make it work with the following approach.

#pragma managed(push, off)
#include <opencv/cv.h>
#pragma managed(pop)

And it works out okay for me.
Posted by Microsoft on 12/21/2010 at 11:47 AM
Hi -

Thanks for reporting this issue. I can confirm this is a bug in the frontend compiler, and it has been fixed. However, this fix will not be available until a future release. I do have a workaround, however.

Here's the details on the bug. The intrinsic InterlockedExchangeAdd is not being detected as requiring native codegen, and so the frontend requests a managed codegen for the function it is used in. When the backend goes to generate code, it discovers that the function does need to be compiled as native, sees that the frontend requested managed compilation, and (unfortunately) ICEs as a result.

The workaround is to trick the compiler into compiling the uses of InterlockedExchangeAdd as native. The easiest way to do that is to add an unused code branch that makes use of an intrinsic that is recognized by the compiler as needing to compile native. In your case, the problem code is coming from a macro definition within the OpenCV library. What you can do is change the macro definition in c:\OpenCV-2.1.0\include\opencv\cxoperations.hpp, line 93 to something like this:

// #define CV_XADD(addr,delta) InterlockedExchangeAdd((LONG volatile*)(addr), (delta))

#define CV_XADD(addr,delta) \

(1 ? (InterlockedExchangeAdd((LONG volatile*)(addr), (delta))) : (LONG)InterlockedExchangeAdd64((LONGLONG volatile*)0,(LONGLONG)0))


(Note that InterlockedExchangeAdd64 is never called, but it, or a similar intrinsic, is necessary in order to work around the frontend bug.) Except in /Od, this should result in very similar (or the same) codegen with no performance penalty, as the optimizer will remove the dead code. You may also need to disable warning c4793, depending on your build system setttings.

Hope this workaround helps - and thanks again for filing this issue.

Andy Rich,
Visual C++ QA
Posted by Microsoft on 12/9/2010 at 10:32 PM
Can you package up a repro for us with the specific header files you are using ?
Posted by Microsoft on 12/8/2010 at 5:23 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.