Created attachment 22961
complete project that shows the bug
Here is a code snippet that shows the bug:
template <typename T> auto async() {
return [](auto func) {
[func] { func(); }();
};
}
static void f() {
async<int>()([] { });
}
void f1() { f(); }
Compile with:
clang++ -c ll.cpp
Run objdump -t ll.o -C, and you'll see the following symbol:
0000000000000000 w F .text._ZZZ5asyncIiEDavENKUlT_E_clIZL1fvE3$_0EEDaS0_ENKUlvE_clEv 000000000000001b async<int>()::{lambda(auto:1)#1}::operator()<f()::$_0>(f()::$_0) const::{lambda()#1}::operator()() const
This is the call operator of the inner lambda on line 3 and this symbol is
*weak*, even though it depends on the func argument, which is a lambda from a
static function. I think this symbol should be *local* as a *weak* symbol might
be overridden by another translation unit.
The consequence is that if there are two static functions that have the same
name in two different translation units and that they both define a lambda,
calling async with that lambda will generate only one symbol in the final
binary and that usually leads to a crash in a more complex example.
I am attaching a more complete project which shows the miscompilation issue.
The program should print 1 and 2, but it prints 1 and 1 for the reason
described above. Renaming the static function in one of the translation units
fixes the issue.
GCC 9 compiles the program correctly, produces *local* symbols for that call
operator and the program prints 1 and 2.
proj.tar.gz
(495 bytes, application/gzip)