[LLVMbugs] [Bug 12917] New: Incorrect mangling of lambdas in default arguments in templates

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue May 22 22:22:21 PDT 2012


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

             Bug #: 12917
           Summary: Incorrect mangling of lambdas in default arguments in
                    templates
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: richard-llvm at metafoo.co.uk
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Related to, but different from, PR12057, Clang (correctly) accepts this:

template<typename...T>
struct S {
  S(T ...t = []{static int n = 0; return ++n;}());
};
S<int, char> s1, s2;

... but it generates incorrect code. The two instantiated lambdas are given the
same mangled name, and we only produce a single static variable rather than
two.

This ultimately seems to be caused by us copying the mangling information from
the lambda in the template to the instantiation, rather than regenerating it in
the instantiation. This also seems to give us wrong manglings in non-variadic
cases. From test/CodeGenCXX/mangle-lambdas.cpp:

template<typename T>
struct ST {
  void f(T = []{return T() + 1;}()
           + []{return T() + 2;}(),
         T = []{return T(3);}());
};

// CHECK: define void @_Z7test_ST2STIdE
void test_ST(ST<double> st) {
  // CHECK: call double @_ZZN2ST1fET_S0_Ed0_NKUlvE_clEv
  // CHECK-NEXT: call double @_ZZN2ST1fET_S0_Ed0_NKUlvE0_clEv
  // CHECK-NEXT: fadd double
  // CHECK-NEXT: call double @_ZZN2ST1fET_S0_Ed_NKUlvE_clEv
  // CHECK-NEXT: call void @_ZN2STIdE1fEdd
  st.f();

  // CHECK-NEXT: ret void
}

These mangled names contain no reference to the value of the template argument:
N2ST1fET_S0_ is a mangling of the member function within the template itself! I
think these should be:

_ZZN2STIdE1fEddEd0_NKUlvE_clEv
_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
_ZZN2STIdE1fEddEd_NKUlvE_clEv

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list