root icon indicating copy to clipboard operation
root copied to clipboard

*** Break *** segmentation violation in case of compilation errors in unnamed macros

Open sakib1278 opened this issue 4 years ago • 7 comments

*** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007ff62fe1bdba in __GI___wait4 (pid=227643, stat_loc=stat_loc
entry=0x7ffe314e7e68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1  0x00007ff62fe1bd7b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffe314e7e68, options=options
entry=0) at waitpid.c:38
#2  0x00007ff62fd8b0e7 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3  0x00007ff630445bfe in TUnixSystem::StackTrace() () from /home/sakib/root/lib/libCore.so.6.24
#4  0x00007ff630442a85 in TUnixSystem::DispatchSignals(ESignals) () from /home/sakib/root/lib/libCore.so.6.24
#5  <signal handler called>
#6  0x00007ff62be79d78 in (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, (anonymous namespace)::ScalarExprEmitter::ScalarConversionOpts) () from /home/sakib/root/lib/libCling.so
#7  0x00007ff62be7c77b in clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) () from /home/sakib/root/lib/libCling.so
#8  0x00007ff62be2dfcf in clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) () from /home/sakib/root/lib/libCling.so
#9  0x00007ff62bc077f5 in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/sakib/root/lib/libCling.so
#10 0x00007ff62bc05848 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /home/sakib/root/lib/libCling.so
#11 0x00007ff62bc05979 in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/sakib/root/lib/libCling.so
#12 0x00007ff62bc4c93e in clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) () from /home/sakib/root/lib/libCling.so
#13 0x00007ff62bc55fde in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/sakib/root/lib/libCling.so
#14 0x00007ff62bc9ec3a in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/sakib/root/lib/libCling.so
#15 0x00007ff62bc9c685 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/sakib/root/lib/libCling.so
#16 0x00007ff62bc9cb73 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/sakib/root/lib/libCling.so
#17 0x00007ff62bca1c07 in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) [clone .part.0] () from /home/sakib/root/lib/libCling.so
#18 0x00007ff62bba7b11 in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/sakib/root/lib/libCling.so
#19 0x00007ff62c02d764 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/sakib/root/lib/libCling.so
#20 0x00007ff62bb0d6be in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/sakib/root/lib/libCling.so
#21 0x00007ff62bacb731 in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/sakib/root/lib/libCling.so
#22 0x00007ff62bacc451 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/sakib/root/lib/libCling.so
#23 0x00007ff62ba2eaef in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/sakib/root/lib/libCling.so
#24 0x00007ff62ba2ef4a in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/sakib/root/lib/libCling.so
#25 0x00007ff62bb1c06c in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/sakib/root/lib/libCling.so
#26 0x00007ff62b940b4e in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/sakib/root/lib/libCling.so
#27 0x00007ff62b9417da in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/sakib/root/lib/libCling.so
#28 0x00007ff6302ed70a in TApplication::ExecuteFile(char const*, int*, bool) () from /home/sakib/root/lib/libCore.so.6.24
#29 0x00007ff6302ee443 in TApplication::ProcessLine(char const*, bool, int*) () from /home/sakib/root/lib/libCore.so.6.24
#30 0x00007ff630666166 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/sakib/root/lib/libRint.so.6.24
#31 0x00007ff63066656a in TRint::HandleTermInput() () from /home/sakib/root/lib/libRint.so.6.24
#32 0x00007ff630441b62 in TUnixSystem::CheckDescriptors() () from /home/sakib/root/lib/libCore.so.6.24
#33 0x00007ff630443828 in TUnixSystem::DispatchOneEvent(bool) () from /home/sakib/root/lib/libCore.so.6.24
#34 0x00007ff630353669 in TSystem::Run() () from /home/sakib/root/lib/libCore.so.6.24
#35 0x00007ff6302eb443 in TApplication::Run(bool) () from /home/sakib/root/lib/libCore.so.6.24
#36 0x00007ff630667c0e in TRint::Run(bool) () from /home/sakib/root/lib/libRint.so.6.24
#37 0x000055b5825ea180 in main ()
===========================================================

Describe the bug

tried to execute a code, crashes

Expected behavior

To Reproduce

Steps to reproduce the behavior: 1.

{
  g = new TGraph();
  
  for(i=0; i<12; i++) {
    g->SetPoint(i, i, i*i + 4*i + 7);
  }
  
  g->SetMarkerStyle(49);
  
  g->Draw("ALP");
}
  1. .x graph2.C

Setup

  1. ROOT version 6.24.00
  2. Operating system ubuntu 20.04
  3. How you obtained ROOT-> binary download

Additional context

sakib1278 avatar Jun 08 '21 03:06 sakib1278

Hi, the segmentation fault is terrible ( ping @Axel-Naumann ) but the code is not valid C++: you need for(int i=0; i<12; i++) instead of for(i=0; i<12; i++). Does that fix the crash?

eguiraud avatar Jun 08 '21 16:06 eguiraud

Hi, That solves the problem. Thank you very much.

Best, Sakib

On Tue, Jun 8, 2021 at 12:47 PM Enrico Guiraud @.***> wrote:

Hi, the segmentation fault is terrible ( ping @Axel-Naumann https://github.com/Axel-Naumann ) but the code is not valid C++: you need for(int i=0; i<12; i++) instead of for(i=0; i<12; i++). Does that fix the crash?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/root-project/root/issues/8367#issuecomment-856929174, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUMS4Q3F6PHG63CCZNBXWKTTRZCTBANCNFSM46I5PYFQ .

sakib1278 avatar Jun 08 '21 17:06 sakib1278

The segfault itself seems to be a problem in how the interpreter handles unnamed macros:

// foo.C
{
  for(i=0; i < 0;); // the second usage of `i` is necessary to get a segfault
}

yields:

/tmp root -l foo.C
root [0]
Processing foo.C...

 *** Break *** segmentation violation



===========================================================
There was a crash (kSigSegmentationViolation).
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fb037c9b9ea in wait4 () from /usr/lib/libc.so.6
#1  0x00007fb037c19a2b in do_system () from /usr/lib/libc.so.6
#2  0x00007fb0385bb6f2 in TUnixSystem::Exec (this=0x564b032cc800, shellcmd=0x564b0483e650 "/home/blue/ROOT/master/_build/etc/gdb-backtrace.sh 62718 1>&2") at ../core/unix/src/TUnixSystem.cxx:2120
#3  0x00007fb0385bbfe4 in TUnixSystem::StackTrace (this=0x564b032cc800) at ../core/unix/src/TUnixSystem.cxx:2411
#4  0x00007fb0385bfd1a in TUnixSystem::DispatchSignals (this=0x564b032cc800, sig=kSigSegmentationViolation) at ../core/unix/src/TUnixSystem.cxx:3649
#5  0x00007fb0385b7340 in SigHandler (sig=kSigSegmentationViolation) at ../core/unix/src/TUnixSystem.cxx:407
#6  0x00007fb0385bfc1e in sighandler (sig=11) at ../core/unix/src/TUnixSystem.cxx:3620
#7  0x00007fb0385b02ae in textinput::TerminalConfigUnix::HandleSignal (this=0x7fb038799120 <textinput::TerminalConfigUnix::Get()::s>, signum=11) at ../core/textinput/src/textinput/TerminalConfigUnix.cpp:99
#8  0x00007fb0385affb4 in (anonymous namespace)::TerminalConfigUnix__handleSignal (signum=11) at ../core/textinput/src/textinput/TerminalConfigUnix.cpp:36
#9  <signal handler called>
#10 0x00007fb0330cb818 in (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, (anonymous namespace)::ScalarExprEmitter::ScalarConversionOpts) () from /home/blue/ROOT/master/_build/lib/libCling.so
#11 0x00007fb0330cddd4 in clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) () from /home/blue/ROOT/master/_build/lib/libCling.so
#12 0x00007fb032e4a010 in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/blue/ROOT/master/_build/lib/libCling.so
#13 0x00007fb032e48014 in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/blue/ROOT/master/_build/lib/libCling.so
#14 0x00007fb032e907d9 in clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) () from /home/blue/ROOT/master/_build/lib/libCling.so
#15 0x00007fb032ea0e0c in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/blue/ROOT/master/_build/lib/libCling.so
#16 0x00007fb032ee86ca in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/blue/ROOT/master/_build/lib/libCling.so
#17 0x00007fb032ee4e33 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/blue/ROOT/master/_build/lib/libCling.so
#18 0x00007fb032ee5533 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/blue/ROOT/master/_build/lib/libCling.so
#19 0x00007fb032eec6b0 in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) [clone .part.0] () from /home/blue/ROOT/master/_build/lib/libCling.so
#20 0x00007fb032de0c29 in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/blue/ROOT/master/_build/lib/libCling.so
#21 0x00007fb03327d4d4 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/blue/ROOT/master/_build/lib/libCling.so
#22 0x00007fb032d2ca9a in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/blue/ROOT/master/_build/lib/libCling.so
#23 0x00007fb032cfd991 in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/blue/ROOT/master/_build/lib/libCling.so
#24 0x00007fb032cfe69d in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/blue/ROOT/master/_build/lib/libCling.so
#25 0x00007fb032c735bb in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/blue/ROOT/master/_build/lib/libCling.so
#26 0x00007fb032c73add in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/blue/ROOT/master/_build/lib/libCling.so
#27 0x00007fb032d3c0bc in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/blue/ROOT/master/_build/lib/libCling.so
#28 0x00007fb032a9843c in TCling::ProcessLine (this=0x564b0333c7e0, line=0x564b04468b80 ".x /tmp/./foo.C", error=0x7ffe65ffc940) at ../core/metacling/src/TCling.cxx:2568
#29 0x00007fb032a9beec in TCling::ProcessLineSynch (this=0x564b0333c7e0, line=0x564b04468b80 ".x /tmp/./foo.C", error=0x7ffe65ffc940) at ../core/metacling/src/TCling.cxx:3494
#30 0x00007fb038421dc5 in TApplication::ExecuteFile (file=0x7ffe65ffc9a3 "foo.C", error=0x7ffe65ffc940, keep=false) at ../core/base/src/TApplication.cxx:1608
#31 0x00007fb0384214e4 in TApplication::ProcessFile (this=0x564b03325550, file=0x7ffe65ffc9a3 "foo.C", error=0x7ffe65ffc940, keep=false) at ../core/base/src/TApplication.cxx:1480
#32 0x00007fb0384212f9 in TApplication::ProcessLine (this=0x564b03325550, line=0x7ffe65ffc9a0 ".x foo.C", sync=false, err=0x7ffe65ffc940) at ../core/base/src/TApplication.cxx:1453
#33 0x00007fb0387d6e2b in TRint::ProcessLineNr (this=0x564b03325550, filestem=0x7fb0387e6742 "ROOT_cli_", line=0x7ffe65ffc9a0 ".x foo.C", error=0x7ffe65ffc940) at ../core/rint/src/TRint.cxx:766
#34 0x00007fb0387d564c in TRint::Run (this=0x564b03325550, retrn=false) at ../core/rint/src/TRint.cxx:424
#35 0x0000564b028ef1f0 in main (argc=1, argv=0x7ffe65ffeb28) at ../main/src/rmain.cxx:30
===========================================================

while

// foo.C
void foo() {
  for(i=0; i < 0;);
}

yields the expected compilation errors:

/tmp root -l foo.C
root [0]
Processing foo.C...
In file included from input_line_8:1:
/tmp/foo.C:2:7: error: use of undeclared identifier 'i'
  for(i=0; i < 0;);
      ^
/tmp/foo.C:2:12: error: use of undeclared identifier 'i'
  for(i=0; i < 0;);
           ^

eguiraud avatar Jun 10 '21 09:06 eguiraud

Side note, it crashes with current ROOT master, but does not crash with current cling standalone master (debug mode).

for(i=0; i < 0;);
input_line_3:2:6: error: use of undeclared identifier 'i'
for(auto i=0; i < 0;)

ferdymercury avatar Apr 14 '24 18:04 ferdymercury

@devajithvs do you happen to understand why?

dpiparo avatar Apr 25 '24 08:04 dpiparo

Same thing observed here: https://its.cern.ch/jira/browse/ROOT-10309

ferdymercury avatar Apr 27 '24 09:04 ferdymercury

It only happens for this specific case for(i=0; i<0;);, for(i=0;;); works completely fine. It happens because TClingCallbacks.cxx tries to add multiple addDecls for the same variable i for runtime resolution.

devajithvs avatar Apr 29 '24 09:04 devajithvs