root icon indicating copy to clipboard operation
root copied to clipboard

root crashes due to typo in the macro

Open linev opened this issue 2 years ago • 4 comments

Check duplicate issues.

  • [ ] Checked for duplicates

Description

This small macro crash ROOT:

{
   for (int i = 0; i< 100; i++) {
      auto hname = TString::Format("h%d", i);
      auto h1 = new TH1I(hname, hanme, 100, -5, 5);
      delete h1;
   }
}

reproducer.C.txt

There is minimal typo in arguments: hanme instead of hname

Here is stack trace output:


===========================================================
#6  0x00007fcae9926574 in clang::QualType::getSplitDesugaredType(clang::QualType) () from /home/linev/build/webgui/lib/libCling.so
#7  0x00007fcae9589636 in clang::ASTContext::getBaseElementType(clang::QualType) const () from /home/linev/build/webgui/lib/libCling.so
#8  0x00007fcae70c9805 in clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) () from /home/linev/build/webgui/lib/libCling.so
#9  0x00007fcae70ceffa in StoreAnyExprIntoOneUnit(clang::CodeGen::CodeGenFunction&, clang::Expr const*, clang::QualType, clang::CodeGen::Address, clang::CodeGen::AggValueSlot::Overlap_t) [clone .constprop.0] () from /home/linev/build/webgui/lib/libCling.so
#10 0x00007fcae70d84a1 in clang::CodeGen::CodeGenFunction::EmitCXXNewExpr(clang::CXXNewExpr const*) () from /home/linev/build/webgui/lib/libCling.so
#11 0x00007fcae710203f in clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) () from /home/linev/build/webgui/lib/libCling.so
#12 0x00007fcae707e0ec in clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) () from /home/linev/build/webgui/lib/libCling.so
#13 0x00007fcae7087438 in clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) () from /home/linev/build/webgui/lib/libCling.so
#14 0x00007fcae70889ec in clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) () from /home/linev/build/webgui/lib/libCling.so
#15 0x00007fcae7088b4d in clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) () from /home/linev/build/webgui/lib/libCling.so
#16 0x00007fcae6da702f in clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) () from /home/linev/build/webgui/lib/libCling.so
#17 0x00007fcae6db803d in clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /home/linev/build/webgui/lib/libCling.so
#18 0x00007fcae6db2112 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /home/linev/build/webgui/lib/libCling.so
#19 0x00007fcae6db2a99 in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/linev/build/webgui/lib/libCling.so
#20 0x00007fcae6db2d7d in clang::CodeGen::CodeGenFunction::EmitCompoundStmt(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/linev/build/webgui/lib/libCling.so
#21 0x00007fcae6db80d5 in clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /home/linev/build/webgui/lib/libCling.so
#22 0x00007fcae6db2112 in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) () from /home/linev/build/webgui/lib/libCling.so
#23 0x00007fcae6db506b in clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) () from /home/linev/build/webgui/lib/libCling.so
#24 0x00007fcae6db2a99 in clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) () from /home/linev/build/webgui/lib/libCling.so
#25 0x00007fcae6e06292 in clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) () from /home/linev/build/webgui/lib/libCling.so
#26 0x00007fcae6e14fef in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) () from /home/linev/build/webgui/lib/libCling.so
#27 0x00007fcae6e51add in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/linev/build/webgui/lib/libCling.so
#28 0x00007fcae6e4ec24 in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) () from /home/linev/build/webgui/lib/libCling.so
#29 0x00007fcae6e4f233 in clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) () from /home/linev/build/webgui/lib/libCling.so
#30 0x00007fcae6e55b4a in clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) [clone .part.0] () from /home/linev/build/webgui/lib/libCling.so
#31 0x00007fcae6d5b733 in clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/linev/build/webgui/lib/libCling.so
#32 0x00007fcae72ca4a0 in clang::MultiplexConsumer::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/linev/build/webgui/lib/libCling.so
#33 0x00007fcae6c6f8cf in cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) () from /home/linev/build/webgui/lib/libCling.so
#34 0x00007fcae6c33a89 in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/linev/build/webgui/lib/libCling.so
#35 0x00007fcae6c34a1c in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) () from /home/linev/build/webgui/lib/libCling.so
#36 0x00007fcae6b974f1 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/linev/build/webgui/lib/libCling.so
#37 0x00007fcae6b9784a in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/linev/build/webgui/lib/libCling.so
#38 0x00007fcae6c852be in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/linev/build/webgui/lib/libCling.so
===========================================================

Reproducer

Provided

ROOT version

Tested master and 6.28 branch on Linux

Installation method

build from source

Operating system

OpenSUSE Linux

Additional context

No response

linev avatar Jul 14 '23 06:07 linev

More info for the llvm experts: this is due to an assertion failure, visible with dbg builds: interpreter/llvm-project/clang/include/clang/AST/Type.h:752: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.

dpiparo avatar Feb 27 '24 11:02 dpiparo

@devajithvs

dpiparo avatar Feb 27 '24 11:02 dpiparo

Minimal reproducer:

if(true) {auto h1 = new int(any_undeclared_variable_here);}

devajithvs avatar Apr 29 '24 07:04 devajithvs

The above example throws an expected error in cling:

[cling]$ auto h1 = new int(any_undeclared_variable_here);
input_line_5:2:20: error: use of undeclared identifier 'any_undeclared_variable_here'
 auto h1 = new int(any_undeclared_variable_here);
                   ^
[cling]$ if(true) {auto h1 = new int(any_undeclared_variable_here);}
input_line_4:2:30: error: use of undeclared identifier 'any_undeclared_variable_here'
 if(true) {auto h1 = new int(any_undeclared_variable_here);}
                             ^

In root, the first example gives a syntax error instead (which is already wrong). This is because ROOT tries to resolve any_undeclared_variable_here at runtime:

root [0] auto h1 = new int(any_undeclared_variable_here);
ROOT_prompt_0:1:1: error: Syntax error
auto h1 = new int(any_undeclared_variable_here);
^
FunctionDecl 0x55555714b7c8 <input_line_8:1:1, ROOT_prompt_0:3:1> input_line_8:1:6 __cling_Un1Qu30 'void (void *)'
|-ParmVarDecl 0x55555714b710 <col:22, col:28> col:28 vpClingValue 'void *'
|-CompoundStmt 0x555557161e30 <col:42, ROOT_prompt_0:3:1>
| |-DeclStmt 0x555557161e10 <line:1:1, col:48>
| | `-VarDecl 0x55555714b918 <col:1, col:47> col:6 h1 'int *':'int *' cinit
| |   `-CXXNewExpr 0x555557161ce8 <col:11, col:47> 'int *' Function 0x55555714bb40 'operator new' 'void *(std::size_t)'
| |     `-ParenListExpr 0x55555714bad0 <col:18, col:47> 'NULL TYPE'
| |       `-DeclRefExpr 0x55555714ba90 <col:19> '<dependent type>' lvalue Var 0x55555714b988 'any_undeclared_variable_here' '<dependent type>'
| `-NullStmt 0x555557161e28 <line:2:1>
`-AnnotateAttr 0x55555714b9f0 <<invalid sloc>> Implicit R"ATTRDUMP(__ResolveAtRuntime)ATTRDUMP"
<<<NULL>>>
root [1] 

And we get a segfault when added inside an if clause:

root [1] if(true) {auto h1 = new int(any_undeclared_variable_here);}
root.exe: /home/dvalapar/work/root/dev.bug-fixes/interpreter/llvm-project/clang/include/clang/AST/Type.h:752: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.

Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=140737352911424) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.

devajithvs avatar Apr 29 '24 11:04 devajithvs