Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.

Calling wrong lambda

MarcusGustafsson
Beginner
1,476 Views

Seems like a bug to me: https://godbolt.org/z/rxY7Wh8x7

Attaching files as well.

Adding static to the functions called hidden avoids the problem.

 

To elaborate a bit:

 

A function foo taking a lambda or a std::function.

In file1: A function called hidden in a anonymous namespace calling foo. 

Also in file 1: A function called apa::run_file1 that calls hidden();

 

In file2: A function called hidden in a anonymous namespace calling foo. 

Also in file 2: A function called apa::run_file2 that calls hidden();

 

Main function calls:

apa::run_file1() and apa::run_file2().

 

When building and running with ICC the lambda used in file1.cpp:hidden is also used when calling apa::run_file2. Seems like nameless lambdas in unnamed namespaces can get the same symbol name when defined in functions with identical signatures.

 

Best Regards

Marcus

Labels (1)
0 Kudos
1 Solution
MWind2
New Contributor III
1,246 Views

When I build and run on Linux(Mint 22.04) and Windows, both 64 bit, I get correct result 2021.4.0

View solution in original post

7 Replies
NoorjahanSk_Intel
Moderator
1,430 Views

Hi,


Thanks for reaching out to us.

Could you please try compiling your code with the Intel icpx compiler? It compiled successfully from our end with icpx compiler.

Please do let us know if you face any issues.


Thanks & Regards,

Noorjahan.


MarcusGustafsson
Beginner
1,417 Views

Noorjahan,

 

I work in a locked down environment so I'll see what I can do regarding testing icpx. That is also why I supplied the Compiler Explorer link.

Also you state that you compile successfully, what about the runtime result? Is the correct lambda called? Please also test the latest version of the classic C++ compiler and let me know the result.

 

Best regards

Marcus

 

MarcusGustafsson
Beginner
1,388 Views

Hi all,

 

here is an update:

 

I've downloaded the intel/oneapi-hpckit Docker image and tested:

[icc-bug]$ icc --version
icc (ICC) 2021.4.0 20210910
Copyright (C) 1985-2021 Intel Corporation.  All rights reserved.

[icc-bug]$ icpx --version
Intel(R) oneAPI DPC++/C++ Compiler 2021.4.0 (2021.4.0.20210924)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/intel/oneapi/compiler/2021.4.0/linux/bin

And the results:

Output from ICC:
./icc-test
This is the hidden function in file1.cpp saying Hello!
This is the hidden function in file1.cpp saying Hello!
---------------------------------------------------------------------
Output from ICPX:
./icpx-test
This is the hidden function in file1.cpp saying Hello!
This is the hidden function in file2.cpp saying Hello!

I.e. newest ICC shows the bug and newest ICPX works correctly. Can one expect ICC to be patched?

 

Br

Marcus

NoorjahanSk_Intel
Moderator
1,291 Views

Hi,

 

Thank you very much for reporting the issue.

 

>> what about the runtime result? Is the correct lambda called?

 

Apologies for the incomplete information.

 

We are also able to see the incorrect result with the latest ICC version, Whereas with the latest icpx we are getting the correct result i.e. correct lambda is called as you have mentioned in the previous post.

 

Please find the attached screenshots for more details.

 

>>Can one expect ICC to be patched?

 

We have reported this issue to the development team, they are looking into this issue

 

 

Thanks & Regards,

Noorjahan.

 

Viet_H_Intel
Moderator
1,264 Views

Hi Marcus,


Since this issue is only seen with icpc and there is a workaround by having void hidden() in file2.cpp as static.

At some point in the future, the classic C/C++ compilers will enter “Legacy Product Support” mode signaling the end of regular updates to the classic compiler base, and they will no longer appear in oneAPI toolkits.

Please see this article for more details. https://www.intel.com/content/www/us/en/developer/articles/technical/adoption-of-llvm-complete-icx.h....


I reported this issue to our Developer but unsure if it will be fixed in icpc as the article mentioned. Hence, my recommendation is to migrate your code to icpx.


Thanks,




MWind2
New Contributor III
1,247 Views

When I build and run on Linux(Mint 22.04) and Windows, both 64 bit, I get correct result 2021.4.0

Devorah_H_Intel
Moderator
572 Views

Fix is coming in the next 2022.3 oneAPI Toolkits release.

Reply