https://bugs.llvm.org/show_bug.cgi?id=44368
Bug ID: 44368
Summary: Miscompilation: clang generates a weak symbol for a
generic lambda that depends on a lambda in a static
function
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangb...@nondot.org
Reporter: blastr...@free.fr
CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
neeil...@live.com, richard-l...@metafoo.co.uk
Created attachment 22961
--> https://bugs.llvm.org/attachment.cgi?id=22961&action=edit
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs