[llvm-bugs] [Bug 44368] New: Miscompilation: clang generates a weak symbol for a generic lambda that depends on a lambda in a static function

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 23 06:13:07 PST 2019


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: unassignedclangbugs at nondot.org
          Reporter: blastrock at free.fr
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191223/81570ca6/attachment.html>


More information about the llvm-bugs mailing list