https://llvm.org/bugs/show_bug.cgi?id=27797
Bug ID: 27797 Summary: Clang crashes on capturing this when template instantiation creates nested lambdas Product: clang Version: trunk Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: C++11 Assignee: unassignedclangb...@nondot.org Reporter: t...@fb.com CC: dgre...@apple.com, llvm-bugs@lists.llvm.org Classification: Unclassified Compiler crashes with assertion failure in line 908 of lib/Sema/SemaExprCXX.cpp (revision 269789). getCurLambda call in line 907 returns nullptr because "CurLSI->Lambda->Encloses(CurContext)" returns false in line 1196 of lib/Sema/Sema.cpp. It seems that the fundamental problem is passing "S.getCurrentThisType()" to "LSI->addThisCapture" in line 11112 of lib/Sema/SemaDecl.cpp. At this point, what is needed is "this" type for nesting lambda. However, inside Sema::getCurrentThisType function, what computed from line 876-881 of Sema/SemaExprCXX.cpp is "this" type for nested lambda. Below is the stack dump: #0 0x00000000013a6205 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x13a6205) #1 0x00000000013a4236 llvm::sys::RunSignalHandlers() (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x13a4236) #2 0x00000000013a4435 SignalHandler(int) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x13a4435) #3 0x00007f24efaff7e0 __restore_rt (/lib64/libpthread.so.0+0xf7e0) #4 0x0000000002089741 clang::Sema::getCurrentThisType() (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x2089741) #5 0x0000000001f797c2 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Decl*, clang::Sema::SkipBodyInfo*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x1f797c2) #6 0x000000000228c597 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228c597) #7 0x000000000222486a clang::Sema::DeduceReturnType(clang::FunctionDecl*, clang::SourceLocation, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x222486a) #8 0x0000000002051841 clang::Sema::DiagnoseUseOfDecl(clang::NamedDecl*, clang::SourceLocation, clang::ObjCInterfaceDecl const*, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x2051841) #9 0x0000000002176e60 CreateFunctionRefExpr(clang::Sema&, clang::FunctionDecl*, clang::NamedDecl*, bool, clang::SourceLocation, clang::DeclarationNameLoc const&) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x2176e60) #10 0x000000000219f648 clang::Sema::BuildCallToObjectOfClassType(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x219f648) #11 0x0000000002067933 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x2067933) #12 0x000000000225ff54 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225ff54) #13 0x000000000225bf9a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225bf9a) #14 0x000000000226c72c clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformIfStmt(clang::IfStmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226c72c) #15 0x000000000226b095 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226b095) #16 0x000000000226be83 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226be83) #17 0x000000000226bf9b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226bf9b) #18 0x000000000226b125 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226b125) #19 0x000000000225a897 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225a897) #20 0x000000000225b99c clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225b99c) #21 0x000000000225cdfa clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225cdfa) #22 0x000000000225c80f clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExprs(clang::Expr* const*, unsigned int, bool, llvm::SmallVectorImpl<clang::Expr*>&, bool*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225c80f) #23 0x000000000225fefc clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225fefc) #24 0x000000000225bf9a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x225bf9a) #25 0x000000000226b0c5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226b0c5) #26 0x000000000226be83 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226be83) #27 0x000000000226bf9b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226bf9b) #28 0x000000000226b125 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226b125) #29 0x000000000226e8ef clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x226e8ef) #30 0x000000000228c618 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228c618) #31 0x000000000228c8c9 clang::Sema::PerformPendingInstantiations(bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228c8c9) #32 0x000000000228bf07 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228bf07) #33 0x000000000228c8c9 clang::Sema::PerformPendingInstantiations(bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228c8c9) #34 0x000000000228bf07 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228bf07) #35 0x000000000228c8c9 clang::Sema::PerformPendingInstantiations(bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228c8c9) #36 0x000000000228bf07 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228bf07) #37 0x000000000228c8c9 clang::Sema::PerformPendingInstantiations(bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x228c8c9) #38 0x0000000001ebbc9f clang::Sema::ActOnEndOfTranslationUnit() (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x1ebbc9f) #39 0x0000000001d07d51 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x1d07d51) #40 0x0000000001d00b03 clang::ParseAST(clang::Sema&, bool, bool) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x1d00b03) #41 0x000000000177bc8e clang::FrontendAction::Execute() (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x177bc8e) #42 0x000000000175a495 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x175a495) #43 0x00000000017f70dc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x17f70dc) #44 0x00000000008845d0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x8845d0) #45 0x0000000000846fb2 main (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x846fb2) #46 0x00007f24eedc4d5d __libc_start_main (/lib64/libc.so.6+0x1ed5d) #47 0x0000000000880c91 _start (/data/users/twoh/llvms/latest/build-release/bin/clang-3.9+0x880c91) Stack dump: 0. Program arguments: /data/users/twoh/llvms/latest/build-release/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-file /home/twoh/local/clang_debug/admarket_t11200264/test.bc -resource-dir /data/users/twoh/llvms/latest/build-release/bin/../lib/clang/3.9.0 -I /home/twoh/fbsource/fbcode -I /home/twoh/fbsource/fbcode/third-party-buck/build/boost/include -I /home/twoh/fbsource/fbcode/third-party-buck/build/glog/include -I /home/twoh/fbsource/fbcode/third-party-buck/build/gflags/include -I /home/twoh/fbsource/fbcode/third-party-buck/build/double_conversion/include -internal-isystem /opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2 -internal-isystem /opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/x86_64-redhat-linux -internal-isystem /opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/backward -internal-isystem /usr/local/include -internal-isystem /data/users/twoh/llvms/latest/build-release/bin/../lib/clang/3.9.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++1y -fdeprecated-macro -fdebug-compilation-dir /home/twoh/local/clang_debug/admarket_t11200264 -ferror-limit 19 -fmessage-length 362 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o test.bc -x c++ test.cpp 1. <eof> parser at end of file 2. /home/twoh/fbsource/fbcode/folly/gen/Core-inl.h:290:6: instantiating function definition 'operator|' 3. /home/twoh/fbsource/fbcode/folly/gen/Base-inl.h:2078:14: instantiating function definition 'compose' 4. /home/twoh/fbsource/fbcode/folly/gen/Core-inl.h:255:1: instantiating function definition 'operator|' 5. /home/twoh/fbsource/fbcode/folly/gen/Base-inl.h:560:10: instantiating function definition 'foreach' clang-3.9: error: unable to execute command: Segmentation fault clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.9.0 (trunk 269789) (llvm/trunk 269788) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/twoh/local/llvms/latest/build-release/bin clang-3.9: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-3.9: note: diagnostic msg: -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs