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.
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,
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.
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?
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,
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.