[ROOT-6650] TF1 constructor crashes using undefined lambda function Created: 05/Sep/14  Updated: 16/Dec/14  Resolved: 16/Dec/14

Status: Closed
Project: ROOT
Component/s: Cling, Core Libraries
Affects Version/s: 6.00.02
Fix Version/s: 6.04.00, 6.02/03

Type: Bug Priority: Medium
Reporter: Jan Andre Stillings Assignee: Axel Naumann
Resolution: Fixed Votes: 0
Labels: None
Environment:

SL6.5


Development:

 Description   

During the tutorial with Axel we found the following problem and he asked me to report it. The second line contains a call with an undefined lambda function.

root [0] auto myErf0Lambda = [](double* x, double* p)

{ return TMath::Erf(x[0]); }

;
root [1] TF1* myErf0 = new TF1("myErf0", myErfLambda, -10, 10);

      • Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x000000327b4ac5de in waitpid () from /lib64/libc.so.6
#1 0x000000327b43e619 in do_system () from /lib64/libc.so.6
#2 0x00007f48ca6ec90f in TUnixSystem::StackTrace() () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#3 0x00007f48ca6eefdc in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#4 <signal handler called>
#5 0x00007f48c8b9f451 in clang::QualType::getSplitDesugaredType(clang::QualType) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#6 0x00007f48c8a67bc8 in clang::ASTContext::getBaseElementType(clang::QualType) const () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#7 0x00007f48c859d114 in clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#8 0x00007f48c85a1918 in StoreAnyExprIntoOneUnit(clang::CodeGen::CodeGenFunction&, clang::Expr const*, clang::QualType, llvm::Value*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#9 0x00007f48c85aadc2 in clang::CodeGen::CodeGenFunction::EmitCXXNewExpr(clang::CXXNewExpr const*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#10 0x00007f48c85bd5b8 in clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#11 0x00007f48c85bee3d in clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#12 0x00007f48c857653f in clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#13 0x00007f48c857fb38 in clang::CodeGen::CodeGenFunction::EmitCXXGlobalVarDeclInit(clang::VarDecl const&, llvm::Constant*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#14 0x00007f48c857fccc in clang::CodeGen::CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function*, clang::VarDecl const*, llvm::GlobalVariable*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#15 0x00007f48c8580327 in clang::CodeGen::CodeGenModule::EmitCXXGlobalVarDeclInitFunc(clang::VarDecl const*, llvm::GlobalVariable*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#16 0x00007f48c8501913 in clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#17 0x00007f48c8501c2e in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#18 0x00007f48c8503fa5 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#19 0x00007f48c8504423 in clang::CodeGen::CodeGenModule::EmitTopLevelDecl () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#20 0x00007f48c84a3e43 in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#21 0x00007f48c82b6580 in cling::IncrementalParser::codeGenTransaction(cling::Transaction*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#22 0x00007f48c82b642c in cling::IncrementalParser::commitTransaction(cling::Transaction*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#23 0x00007f48c82b70f4 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#24 0x00007f48c82be12e in cling::Interpreter::EvaluateInternal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions const&, cling::Value*, cling::Transaction**) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#25 0x00007f48c82be3ad in cling::Interpreter::process(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#26 0x00007f48c82f2a2b in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#27 0x00007f48c81f9089 in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#28 0x00007f48ca620ab5 in TApplication::ProcessLine(char const*, bool, int*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#29 0x00007f48ca269dff in TRint::ProcessLineNr(char const*, char const*, int*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libRint.so
#30 0x00007f48ca26a0f1 in TRint::HandleTermInput() () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libRint.so
#31 0x00007f48ca6ee7e5 in TUnixSystem::CheckDescriptors() () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#32 0x00007f48ca6ef2da in TUnixSystem::DispatchOneEvent(bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#33 0x00007f48ca6779f6 in TSystem::InnerLoop() () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#34 0x00007f48ca6785a0 in TSystem::Run() () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#35 0x00007f48ca61f1af in TApplication::Run(bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCore.so
#36 0x00007f48ca26b5a7 in TRint::Run(bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libRint.so
#37 0x000000000040128c in main ()
===========================================================

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x00007f48c8b9f451 in clang::QualType::getSplitDesugaredType(clang::QualType) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#6 0x00007f48c8a67bc8 in clang::ASTContext::getBaseElementType(clang::QualType) const () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#7 0x00007f48c859d114 in clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#8 0x00007f48c85a1918 in StoreAnyExprIntoOneUnit(clang::CodeGen::CodeGenFunction&, clang::Expr const*, clang::QualType, llvm::Value*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#9 0x00007f48c85aadc2 in clang::CodeGen::CodeGenFunction::EmitCXXNewExpr(clang::CXXNewExpr const*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#10 0x00007f48c85bd5b8 in clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#11 0x00007f48c85bee3d in clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#12 0x00007f48c857653f in clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#13 0x00007f48c857fb38 in clang::CodeGen::CodeGenFunction::EmitCXXGlobalVarDeclInit(clang::VarDecl const&, llvm::Constant*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#14 0x00007f48c857fccc in clang::CodeGen::CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function*, clang::VarDecl const*, llvm::GlobalVariable*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#15 0x00007f48c8580327 in clang::CodeGen::CodeGenModule::EmitCXXGlobalVarDeclInitFunc(clang::VarDecl const*, llvm::GlobalVariable*, bool) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#16 0x00007f48c8501913 in clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#17 0x00007f48c8501c2e in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#18 0x00007f48c8503fa5 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#19 0x00007f48c8504423 in clang::CodeGen::CodeGenModule::EmitTopLevelDecl () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#20 0x00007f48c84a3e43 in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#21 0x00007f48c82b6580 in cling::IncrementalParser::codeGenTransaction(cling::Transaction*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#22 0x00007f48c82b642c in cling::IncrementalParser::commitTransaction(cling::Transaction*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#23 0x00007f48c82b70f4 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#24 0x00007f48c82be12e in cling::Interpreter::EvaluateInternal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions const&, cling::Value*, cling::Transaction**) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#25 0x00007f48c82be3ad in cling::Interpreter::process(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
#26 0x00007f48c82f2a2b in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/6.00.02-x86_64-slc6-gcc48-opt/lib/libCling.so
===========================================================



 Comments   
Comment by Axel Naumann [ 31/Oct/14 ]

The second line is enough:

TF1* myErf0 = new TF1("myErf0", myErfLambda, -10, 10);

The problem is that this expression ends up in CodeGen with a subexpression with dependent type:

(gdb) p D->dump()
VarDecl 0x14779a0 <ROOT_prompt_0:1:1, col:53> col:6 myErf0 'class TF1 *' cinit
`-CXXNewExpr 0x1477d18 <col:15, col:53> 'class TF1 *'
  `-ParenListExpr 0x1477bf8 <col:22, col:53> 'NULL TYPE'
    |-StringLiteral 0x1477a78 <col:23> 'const char [7]' lvalue "myErf0"
    |-DeclRefExpr 0x1477b70 <col:33> '<dependent type>' lvalue Var 0x1477ab0 'myErfLambda' '<dependent type>'
    |-UnaryOperator 0x1477bb8 <col:46, col:47> 'int' prefix '-'
    | `-IntegerLiteral 0x1477b98 <col:47> 'int' 10
    `-IntegerLiteral 0x1477bd8 <col:51> 'int' 10

We probably need to check the init expr of a DeclStmt which is currently not the case.

Comment by Axel Naumann [ 16/Dec/14 ]

Fixed in master and v6-02-00-patches with a cling test. Thanks for your report!

Generated at Sun Sep 22 02:15:37 CEST 2019 using Jira 7.13.1#713001-sha1:5e06076c2d215a6f699b7e5c90ab2fae7ba5a1ce.