http://llvm.org/bugs/show_bug.cgi?id=15512

            Bug ID: 15512
           Summary: Clang generates invalid code when lambdas call
                    lambdas.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Created attachment 10179
  --> http://llvm.org/bugs/attachment.cgi?id=10179&action=edit
template workaround to avoid nested lambda bags.

I have created a simple program that crashes when running the resulting code
generated by Clang.

    int main( int argc, char *argv[])
    {
        auto first = [&]() { return argc; };
        auto second = [&]() { return first(); };
        return second();
    }

I have investigated a little, and what I have found is that Clang mistakenly
thinks that 'first' and 'second' should have the same implementation, only
generates code for one of them, yet calls it for both.

If I change the resulting type of 'first' to differ from 'second', it works:

    int main( int argc, char *argv[])
    {
        auto first = [&]() -> unsigned int { return argc; };
        auto second = [&]() -> int { return first(); };
        return second();
    }

As an ugly workaround, forcing a different return type using a templated
wrapper works (see attachment)

LLVM 3.3 @ SVN 176884
clang++.exe -Xclang -cxx-abi -Xclang microsoft -S -emit-llvm lambdafail.cpp -o
lambdafail.cpp.bc
lli.exe lambdafail.cpp.bc x y

expected result: 3


Reply from Richard Smith <[email protected]> on the mailing list:

The implementation of the Microsoft ABI is incomplete. It's quite likely that
it does not correctly mangle lambdas yet.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to