Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Optimization failure with latest classic compiler

RGK
Beginner
1,078 Views

I have a bigger project which runs fine when compiled with the Visual Studio C++ compiler.

Trying to use the Intel Classic Compiler (latest version to be downloaded) works mostly fine but there are some caveats (still need to track them down one by one).

 

This is one that I have isolated by now.

It is code from a private string class that in this case converts a string to UTF8.

With optimization switched off (debug build) everything works perfectly fine.

As soon as the compiler optimizes something strange happens.

 

Input string: <b>{BC}</b><br>{volume|µl|---|f}

Output string: }b>{BC}</b><br>{volume|µl|---|f}

 

Note that the first character is wrong (should be a <). However optimization prevents me to step into the function (it looks like the function WordStrToUtf8 is completely optimized away).

 

Attached a simple demo project to reproduce the error.

0 Kudos
6 Replies
VidyalathaB_Intel
Moderator
1,036 Views

Hi Roger,


Thanks for reaching out to us.

The issue is reproducible from our end also.

We are working on it, we will get back to you soon.


Regards,

Vidya.


0 Kudos
VidyalathaB_Intel
Moderator
975 Views

Hi @RGK ,

 

Thanks for your patience.

 

>>With optimization switched off (debug build) everything works perfectly fine.

As soon as the compiler optimizes something strange happens.

 

The Intel OneAPI compiler has "Strict Aliasing" enabled by default on Windows. (In Linux this issue cannot be reproduced with optimization enabled)

 

This decision was made to follow the latest C++ standard, and compile programs (especially GPU kernels) similarly on Windows and Linux.

 

The short version is that when the optimizer does not know exactly where a pointer points, it will assume that pointers to different types, such as short* and wchar_t*, cannot point to the same data. This follows the C++ standard and enables many optimizations that are not possible otherwise.

Code such as this:

 

> Utf8Len((short*)str);

 

may cause problems for the optimizer in this way.

 

The -fno-strict-aliasing option will disable this feature and allow the code to run as intended.

 

Here is the screenshot of the output which gives the expected results when including the above-mentioned option during the compilation.

VidyalathaB_Intel_0-1674483324178.png

 

 

Please do let us know if you have any issues in doing so.

 

Regards,

Vidya.

 

0 Kudos
RGK
Beginner
945 Views

Hello Vidya

 

Thank you for this. The compiler option solves the issue on this project. So far all good.

I just find this "feature" quite dangerous (might be standard but there is so much legacy code around and this is hard to trace).

 

Thanks a lot

Roger

 

0 Kudos
VidyalathaB_Intel
Moderator
931 Views

Hi Roger,


Thanks for the feedback. we will let the concerned team know about it.

If there are no other issues, could you please confirm if we can close this thread from our end?


Regards,

Vidya.


0 Kudos
RGK
Beginner
926 Views

Hi Vidja

Yes this can be closed.

Regards

Roger

0 Kudos
VidyalathaB_Intel
Moderator
916 Views

Hi Roger,


Thanks for the confirmation.

As the issue is resolved we are closing this thread. Please post a new question if you need any additional assistance from Intel as this thread will no longer be monitored.


Have a Nice Day!


Regards,

Vidya.


0 Kudos
Reply