[llvm-bugs] [Bug 44554] New: Explicit instantiation of static member initialized with lamda causes crashe (C++11) or error about mangled name (C++14)

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 15 05:52:08 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44554

            Bug ID: 44554
           Summary: Explicit instantiation of static member initialized
                    with lamda causes crashe (C++11) or error about
                    mangled name (C++14)
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ogoffart at kde.org
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

The following testcase crashes with -std=c++11,  or report error with
-std=c++17

```
template<typename T> struct Test {
    static int x;
    static int y;
};

template<typename T> int Test<T>::x = []() { return 0; }();
template<typename T> int Test<T>::y = []() { return 0; }();

template struct Test<bool>;
```

C++11 crash:

Stack dump:

0.      Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o
./output.s -mllvm --x86-asm-syntax=intel -S
--gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics
-fno-crash-diagnostics -std=c++11 -O3 <source> 
1.      <source>:20:27: current parser token ';'
2.      <source>:17:40: instantiating function definition
'Test<bool>::(anonymous class)::operator()'
3.      <source>:17:40: LLVM IR generation of declaration
'Test<bool>::(anonymous class)::operator()'
4.      <source>:17:40: Generating code for declaration 'Test<bool>::(anonymous
class)::operator()'
<snip>
 #4 0x0000558691b98784 CrashRecoverySignalHandler(int)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x28cc784)
 #5 0x00007f428c165890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #6 0x0000558691f4e19a
clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c8219a)
 #7 0x0000558691f4f34f
clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c8334f)
 #8 0x0000558691f4ea50
clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c82a50)
 #9 0x0000558692070a88
clang::CodeGen::CodeGenTypes::arrangeLLVMFunctionInfo(clang::CanQual<clang::Type>,
bool, bool, llvm::ArrayRef<clang::CanQual<clang::Type> >,
clang::FunctionType::ExtInfo,
llvm::ArrayRef<clang::FunctionType::ExtParameterInfo>,
clang::CodeGen::RequiredArgs)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2da4a88)
#10 0x0000558692072504
clang::CodeGen::CodeGenTypes::arrangeCXXMethodType(clang::CXXRecordDecl const*,
clang::FunctionProtoType const*, clang::CXXMethodDecl const*)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2da6504)
#11 0x00005586920730c8
clang::CodeGen::CodeGenTypes::arrangeCXXMethodDeclaration(clang::CXXMethodDecl
const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2da70c8)
#12 0x00005586920733fb
clang::CodeGen::CodeGenTypes::arrangeFunctionDeclaration(clang::FunctionDecl
const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2da73fb)
#13 0x0000558691f1d381
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c51381)
#14 0x0000558691f1af34
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c4ef34)
#15 0x0000558691f1b5e3
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c4f5e3)
#16 0x0000558691f20c37
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.4701)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x2c54c37)
#17 0x000055869291bd91 (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x364fd91)
#18 0x000055869290f2d6
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x36432d6)
#19 0x00005586939f922d
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x472d22d)
#20 0x00005586939d2a40
clang::Sema::InstantiateClassMembers(clang::SourceLocation,
clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&,
clang::TemplateSpecializationKind)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x4706a40)
#21 0x00005586939d258d
clang::Sema::InstantiateClassMembers(clang::SourceLocation,
clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&,
clang::TemplateSpecializationKind)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x470658d)
#22 0x00005586939d2c16
clang::Sema::InstantiateClassTemplateSpecializationMembers(clang::SourceLocation,
clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x4706c16)
#23 0x00005586938fc96b clang::Sema::ActOnExplicitInstantiation(clang::Scope*,
clang::SourceLocation, clang::SourceLocation, unsigned int,
clang::SourceLocation, clang::CXXScopeSpec const&,
clang::OpaquePtr<clang::TemplateName>, clang::SourceLocation,
clang::SourceLocation, llvm::MutableArrayRef<clang::ParsedTemplateArgument>,
clang::SourceLocation, clang::ParsedAttributesView const&)
(/opt/compiler-explorer/clang-trunk/bin/clang+++0x463096b)
<snip>



Or the following error with -std=c++14 and -std=c++17

 error: definition with same mangled name '_ZNK4TestIbEUt_clEv' as another
definition
 template<typename T> int Test<T>::y = []() { return 0; }();
                                       ^
 note: previous definition is here
 template<typename T> int Test<T>::x = []() { return 0; }();
                                       ^

When disambiguating the mangled name by adding a dummy parameter to the lambda,
one can see that these lambda functions are exported by the explicit
instentiation, they should probably not.


The same problem also happens in this C++17 testcase:


```
template<typename T> struct Test {
    static constexpr int x = []()constexpr { return 0; }() 
        + []() constexpr { return 1; }();
};
template struct Test<bool>;
```

The function are also exported when disambiguating despite they really
shouldn't

-- 
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/20200115/f71049ce/attachment.html>


More information about the llvm-bugs mailing list