Clang generates invalid code when lambdas call lambdas.

Hello,

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();
  }

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

Thank you,
Ian

Hello,

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();
}

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

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