/EHa problem

/EHa problem

imagem de Vitaly Trushanin

Hi,

The following code occasionally fails with bad allocation exception or unknow exception when I compile it with /EHa flag in Release configuration. It does not fail when I build it in Debug configuration and in all configurations with MS Visual C++ Compiler. 

#include <vector>
#include <iostream>

using namespace std;

int main()
{
    try
    {
      vector<wchar_t> v;
      v.push_back( L'0' );

      cout << "Ok" << endl;
    }
    catch( std::exception& e )
    {
        cout << "Failed with " << e.what() << endl;
    }
}

I have run sample 20 times and 14 of them have fallen.

Intel(R) C++ Compiler XE, Version 12.1.3.300 Build 20120130 

OS: Windows 7 Professinal with SP1 x64

Compiler options: /c /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /Gy /fp:fast /Fo"Release/" /Fd"Release/vc90.pdb" /W3 /nologo /Zi

What am I doing wrong? Could you help me please?

The sample project is attached.

AnexoTamanho
Download sample.7z1.51 KB
30 posts / 0 new
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de Sergey Kostrov

Here is a question: Did you try the test case with Update 7 for the Intel C++ compiler version 12?

Intel(R) C++ Compiler XE, Version 12.1.7.371 Build 20120928

imagem de Sergey Kostrov

And one more comment. I would try to change:
...
vector< wchar_t > v;
v.push_back( L'0' );
...
to
...
vector< TCHAR > v;
v.push_back( _T('0') );
...
Please let us know results of your tests.

imagem de Vitaly Trushanin

I have compiled code with Intel(R) C++ Compiler XE 13.1.2.190 [IA-32] and the same results have been repeated.

I have tried to use char instead wchar_t and the same results have been repeated again. But the issue is not reproduced when I use short and int types.

imagem de Sergey Kostrov

I confirm the problem with version 12 and the test application always throws exception:

C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception
C:\WuTemp>Test.exe
Failed with Unknown exception

The test application executed 22 times.

imagem de Sergey Kostrov

Here is a modified test case:

// icl.exe /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Test.cpp

#include "vector"
#include "iostream"

#include "tchar.h"

using namespace std;

int main( void )
{
try
{
// Sub-test 1
// vector< wchar_t > v;
// v.push_back( L'0' );

// Sub-test 2
// vector< TCHAR > v;
// v.push_back( _T('0') );

// Sub-test 3
vector< TCHAR > v;
TCHAR chV = _T('0');
v.push_back( chV );

cout << "Ok" << endl;
}
catch( std::exception& e )
{
cout << "Failed with " << e.what() << endl;
}

return ( int )0;
}

Note: The Sub-test 3 is your workaround and it works.

imagem de Sergey Kostrov

[ Compilation of Sub-test 2 ]

C:\WuTemp>icl.exe /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Test.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Test.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Test.cpp(20): remark #383: value copied to temporary, reference to temporary used
v.push_back( _T('0') );
^

Test.cpp(26): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^
warning #13000: could not open message catalog file: diagscUI.dll

ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\DOCUME~1\Admin\LOCALS~1\Temp\ipo_1420.obj

[ Output of Sub-test 2 ]

C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Failed with bad allocation
C:\WuTemp>Test.exe
Failed with bad allocation
C:\WuTemp>Test.exe
Failed with bad allocation
C:\WuTemp>Test.exe
Failed with bad allocation
C:\WuTemp>Test.exe
Failed with bad allocation
C:\WuTemp>Test.exe
Failed with bad allocation
C:\WuTemp>Test.exe
Failed with bad allocation

imagem de Sergey Kostrov

[ Compilation of Sub-test 3 ]

C:\WuTemp>icl.exe /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi
Test.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Test.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Test.cpp(31): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^

warning #13000: could not open message catalog file: diagscUI.dll
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\DOCUME~1\Admin\LOCALS~1\Temp\ipo_1120.
obj

[ Output of Sub-test 3 ]

C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok

Note: As you can see it works when an additional variable of type TCHAR is used ( see the modified test case ).

imagem de Sergey Kostrov

A couple of more comments:

- Don't pay attention for [ warning #13000: could not open message catalog file: diagscUI.dll ] warning since this is an issue in my development environment on Windows XP

- I would recommend to use Intel C++ compiler options /W5 and /check as much as possible since they help to identify lots of issues in source codes

- All tests on Windows XP were done with Intel(R) C++ Compiler XE for applications running on IA-32, Version 12.1.7.371 Build 20120928

- Please verify the modified test case with version 13 of Inte C++ compiler

imagem de Sergey Kostrov

I also completed additional verification with Borland C++ compiler v5.5.1 and I confirm that there is a problem with Intel C++ compiler. Here is a modofied ( again ) test case:

// bcc32.exe /O2 /D "_MBCS" Test.cpp

#include "vector"
#include "iostream"

#include "tchar.h"

using namespace std;

int main( void )
{
try
{
// Sub-test 1
// vector< wchar_t > v;
// v.push_back( L'0' );

// Sub-test 2
// vector< _TCHAR > v;
// v.push_back( _T('0') );

// Sub-test 3
vector< _TCHAR > v;
_TCHAR chV = _T('0');
v.push_back( chV );

cout << "Ok" << endl;
}
catch( std::exception& e )
{
cout << "Failed with " << e.what() << endl;
}

return ( int )0;
}

imagem de Sergey Kostrov

[ Output of Sub-test 1 with BCC v5.5.1 ]

C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok

[ Output of Sub-test 2 with BCC v5.5.1 ]

C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok

[ Output of Sub-test 3 with BCC v5.5.1 ]

C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok
C:\WuTemp>Test.exe
Ok

Note: As you can see there are No any issues, or problems, or exceptions.

imagem de Vitaly Trushanin

Unfortunately workaround fails.

D:\temporary\sample\sample>icl
Intel(R) C++ Compiler XE for applications running on IA-32, Version 12.1.3.300 B
uild 20120130
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.

icl: command line error: no files specified; for help type "icl /help"

D:\temporary\sample\sample>icl.exe /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp(19): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^

warning #13000: could not open message catalog file: diagscUI.dll
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\Users\VTRUSH~1\AppData\Local\Temp\
ipo_91080.obj

D:\temporary\sample\sample>Sample.exe
Failed with bad allocation

Workaround fails with both Unicode Character Set and Multi-Byte Character Set compiler options.

imagem de Sergey Kostrov

>>Unfortunately workaround fails.
>>
>>D:\temporary\sample\sample>icl
>>Intel(R) C++ Compiler XE for applications running on IA-32, Version 12.1.3.300 Build 20120130

You need to consider installation of the most latest update for the version 12 of Intel C++ compiler.

imagem de Vitaly Trushanin

Unfortunately, I don't know how to get the latest 12.x version but I've tried 13.1.2.190 version and sample fails with both Unicode Character Set and Multi-Byte Character Set compiler options.

D:\temporary\sample\sample>icl

Intel(R) C++ Compiler XE for applications running on IA-32, Version 13.1.2.190 Build 20130514
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.

icl: command line error: no files specified; for help type "icl /help"

D:\temporary\sample\sample>icl.exe /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Sample.cpp
Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp(19): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^

warning #13000: could not open message catalog file: diagscUI.dll
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\Users\VTRUSH~1\AppData\Local\Temp\
ipo_92080.obj

D:\temporary\sample\sample>sample
Failed with bad allocation

D:\temporary\sample\sample>sample
Failed with bad allocation

D:\temporary\sample\sample>sample
Failed with bad allocation

D:\temporary\sample\sample>icl.exe /O2 /Oi /Qipo /D "_UNICODE" /D "UNICODE" /EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Sample.cpp
Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp(19): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^

warning #13000: could not open message catalog file: diagscUI.dll
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\Users\VTRUSH~1\AppData\Local\Temp\
ipo_91168.obj

D:\temporary\sample\sample>sample
Failed with Unknown exception

D:\temporary\sample\sample>sample
Failed with Unknown exception

D:\temporary\sample\sample>sample
Failed with Unknown exception

If tests with the latest 12.x version are important, could you give me a link to that build please?

imagem de Sergey Kostrov

>>...If tests with the latest 12.x version are important, could you give me a link to that build please?

You could get any updates for Intel software at:

Intel Software Registration Center
Web-link: registrationcenter.intel.com/regcenter/register.aspx

imagem de Vitaly Trushanin

The issue is reproducible with the latest 12.x version.

D:\temporary\sample\sample>icl
Intel(R) C++ Compiler XE for applications running on IA-32, Version 12.1.7.371 B
uild 20120928
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.

icl: command line error: no files specified; for help type "icl /help"

D:\temporary\sample\sample>icl.exe /O2 /Oi /Qipo /D "_MBCS" /EHa /MD /GS /G
y /fp:fast /W5 /nologo /Zi Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp(19): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^

warning #13000: could not open message catalog file: diagscUI.dll
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\Users\VTRUSH~1\AppData\Local\Temp\
ipo_95904.obj

D:\temporary\sample\sample>sample
Failed with bad allocation

D:\temporary\sample\sample>sample
Failed with bad allocation

D:\temporary\sample\sample>sample
Failed with bad allocation

D:\temporary\sample\sample>icl.exe /O2 /Oi /Qipo /D "_UNICODE" /D "UNICODE"
/EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp
warning #13000: could not open message catalog file: diagscUI.dll
Sample.cpp(19): remark #981: operands are evaluated in unspecified order
cout << "Failed with " << e.what() << endl;
^

warning #13000: could not open message catalog file: diagscUI.dll
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file C:\Users\VTRUSH~1\AppData\Local\Temp\
ipo_95036.obj

D:\temporary\sample\sample>sample
Failed with Unknown exception

D:\temporary\sample\sample>sample
Failed with Unknown exception

D:\temporary\sample\sample>sample
Failed with Unknown exception

imagem de Sergey Kostrov

>>The issue is reproducible with the latest 12.x version.
>>
>>D:\temporary\sample\sample>icl
>>Intel(R) C++ Compiler XE for applications running on IA-32, Version 12.1.7.371 Build 20120928

I see that you're compiling from the command line. My question is did you use:

'IA-32 Visual Studio 2005 mode'
or
'IA-32 Visual Studio 2008 mode'
or
'IA-32 Visual Studio 2010 mode'

command prompt?

I used 'IA-32 Visual Studio 2005 mode'. On that computer I have Windows XP 32-bit with Visual Studios 2005 Professional Edition, 2008 Express Edition and 2010 Express Edition.

imagem de Vitaly Trushanin

I have used "IA-32 Visual Studio 2008 mode". On that computer I have Windows 7 64-bit with Visual Studio Team System 2008.

imagem de Sergey Kostrov

>>I have used "IA-32 Visual Studio 2008 mode". On that computer I have Windows 7 64-bit
>>with Visual Studio Team System 2008.

The highest versions of VSs I have are Professional Editions.

So, even if we have the same versions of Intel C++ compiler ( 12.1.7.371 ) our Visual Studios are different and, it is possible and still Not proven, that STLs are different as well. If Intel C++ compiler is integrated with Visual Studio Team System 2008 try to create a complete Visual Studio project with these simple codes ( don't forget to use the same compiler options ) and try to Debug it. That is, step into
...
v.push_back( L'0' );
...
statement.

Let me know if you need a help with a complete Visual Studio project.

imagem de Vitaly Trushanin

The sample crashed in the following method of STL std::vector class:

template<class _Ty, class _Ax> class vector : public _Vector_val<_Ty, _Ax> {

   ...

   void _Insert_n(const_iterator _Where, size_type _Count, const _Ty& _Val) {

      ...

      pointer _Newvec = this->_Alval.allocate(_Capacity);

      ...

   }

}

Crash line screen and build log are attached.

Anexos: 

AnexoTamanho
Download crash-line-screen.png128.46 KB
Download build-log.txt905 bytes
imagem de Sergey Kostrov

I reviewed some of my old codes and I've noticed that I never used a variable of type vector before calling a reserve( NumOfElements ) method. A modified test case is as follows:

// icl.exe /O2 /EHa Test13.cpp
// icl.exe /O3 /EHa Test13.cpp
// bcc32.exe /O2 Test13.cpp

#include "vector"
#include "iostream"

#undef _MBCS
#define _MBCS

#include "tchar.h"

using namespace std;

int main( void )
{
try
{
// Sub-test 1
vector< wchar_t > v;
v.reserve( 4096 );
v.push_back( L'0' );

// Sub-test 2
// vector< _TCHAR > v;
// v.reserve( 4096 );
// v.push_back( _T('0') );

// Sub-test 3
// vector< _TCHAR > v;
// v.reserve( 4096 );
// _TCHAR chV = _T('0');
// v.push_back( chV );

cout << "Ok" << endl;
}
catch( std::exception &e )
{
cout << "Failed with " << e.what() << endl;
}

return ( int )0;
}

imagem de Vitaly Trushanin

Sorry for a delay with the answer.

1. std::vector automatically increases internal memory size if it is full, so reserve() method call is not necessary.

2. But I've tried suggested workaround but it didn't lead to expected result and sample failed with the same exception again.

imagem de Sergey Kostrov

>>...But I've tried suggested workaround but it didn't lead to expected result and sample failed with the same exception...

Any comments from Intel software engineers? Thanks in advance.

imagem de Vitaly Trushanin

How can I contact them?

imagem de Sergey Kostrov

All IDZ Forums are monitored by Intel software engineers and managers.

If you have a valid license of Intel C++ compiler than I would suggest you to contact Intel Premier Support. I also recommend you to try the test case with Visual Studios 2008 and 2010 Express Editions ( available for free ).

I will do another set of tests with these Visual Studios and Intel C++ compiler version 12 ( command line integrations ) and attached test case. I won't be able to spend too much time ( just a couple of minutes ) and if everything will be right I'll let you know.

Anexos: 

AnexoTamanho
Download test13.cpp718 bytes
imagem de Sergey Kostrov

I didn't have any problems during my latest verification. Take a look at a zip archive and it has 6 executables compiled with Intel C++ compiler using:

- VS 2005 PE ( 2 executables compiled with /O2 and /O3 )
- VS 2008 EE ( 2 executables compiled with /O2 and /O3 )
- VS 2010 EE ( 2 executables compiled with /O2 and /O3 )

Anexos: 

AnexoTamanho
Download tests.zip320.75 KB
imagem de Sergey Kostrov

>>...But I've tried suggested workaround but it didn't lead to expected result and sample failed with the same exception...

Could you try -fno-exceptions command line option?

imagem de Sergey Kostrov

>>...
>>D:\temporary\sample\sample>icl.exe /O2 /Oi /Qipo /D "_UNICODE" /D "UNICODE"
>>/EHa /MD /GS /Gy /fp:fast /W5 /nologo /Zi Sample.cpp
>>warning #13000: could not open message catalog file: diagscUI.dll
>>Sample.cpp
>>warning #13000: could not open message catalog file: diagscUI.dll
>>Sample.cpp(19): remark #981: operands are evaluated in unspecified order
>>cout << "Failed with " << e.what() << endl;
>>^
>>
>>warning #13000: could not open message catalog file: diagscUI.dll
>>ipo: remark #11001: performing single-file optimizations
>>ipo: remark #11006: generating object file C:\Users\VTRUSH~1\AppData\Local\Temp\
>>ipo_95036.obj
>>
>>D:\temporary\sample\sample>sample
>>Failed with Unknown exception
>>...

I did a review of all our posts and I wonder if you could try to use /Qfp-trap:none option?

imagem de Sergey Kostrov

Here is another follow up and let me call it as some kind of Conclusion:

- I don't consider that Microsoft Visual Studio STL header files are responsible for that error

- Something is wrong with processing ( due to some issues with codes generation ) when /Qipo and /EHa options are used at the same time

- There are No any exceptions ( at least I coudn't reproduce it ) when /Qip and /EHa ( or /EHs ) options are used at the same time

- Since that problem is related to IPO there is a chance to workaround it by Not using /Qipo option for some source files ( in case of a production software system ) or /Qip needs to be used instead

- Since it happens with Intel C++ compiler version 12 there is No way it could be fixed ( consider Intel C++ compiler upgrade )

imagem de Sergey Kostrov

>>...- Since it happens with Intel C++ compiler version 12 there is No way it could be fixed ( consider Intel C++ compiler upgrade )

A note for Intel software engineers:

Please verify latest releases of 32-bit and 64-bit Intel C++ compilers. A test case is attached. Thanks.

Anexos: 

AnexoTamanho
Download test13.cpp796 bytes

Faça login para deixar um comentário.