Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROOT-9147 #1

Closed
wants to merge 3 commits into from
Closed

ROOT-9147 #1

wants to merge 3 commits into from

Conversation

pcanal
Copy link
Owner

@pcanal pcanal commented Feb 2, 2018

No description provided.

couet and others added 3 commits February 2, 2018 17:14
In the example below, thread #11 is waiting on the ‘AppKit lock’ while thread #1 is waiting on the ROOT read lock and thread #12 is waiting on the ROOT write lock.

In thread #11, the ROOT write lock is taken/held by frame #9, TCanvas::Update, to ‘serialize’ the update to the windowing system.

In thread #1, the ‘AppKit lock’ is likely taken/held by a frame in the #16 to #40 range.

This commit remove the dead lock by removing the unnecessary use of code needing the ROOT lock within code run under the AppKit lock so that in they case thread #1 no longer need to wait for the ROOT (read) lock.

In addition it should be investigated whether the ROOT (write) lock should be taken in thread #1, frame 1 (TMacOSXSystem::ProcessPendingEvents) for the same reason it is taken in TCanvas::Update.

  thread #11
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fff93394e34 AppKit`-[NSViewHierarchyLock lockForReadingWithExceptionHandler:] + 287
    frame #3: 0x00007fff934948ae AppKit`-[NSWindow _copyAcquiredViewHierarchyLock] + 126
    frame #4: 0x00007fff9349442c AppKit`-[NSView lockFocusIfCanDraw] + 159
    frame #5: 0x000000011c09063d libGCocoa.so`ROOT::MacOSX::X11::CommandBuffer::Flush(this=0x0000000100dbb080, impl=0x0000000100dbb000) at X11Buffer.mm:550
    frame #6: 0x000000011c04e9c4 libGCocoa.so`TGCocoa::Update(this=0x0000000100ad1bc0, mode=1) at TGCocoa.mm:536
    frame #7: 0x000000011c04ff3e libGCocoa.so`TGCocoa::UpdateWindow(this=0x0000000100ad1bc0, (null)=1) at TGCocoa.mm:776
    frame #8: 0x000000011ad70827 libGpad.so`TCanvas::Flush(this=0x000000012274e740) at TCanvas.cxx:1096
    frame #9: 0x000000011ad7830f libGpad.so`TCanvas::Update(this=0x000000012274e740) at TCanvas.cxx:2287
    frame #10: 0x0000000100fe4e86 threadsh2_C.so`handle2((null)=0x0000000000000001) at threadsh2.C:105
    frame #11: 0x0000000100f55680 libThread.so`TThread::Function(ptr=0x0000000122753b00) at TThread.cxx:821
    frame #12: 0x00007fffab1f493b libsystem_pthread.dylib`_pthread_body + 180
    frame #13: 0x00007fffab1f4887 libsystem_pthread.dylib`_pthread_start + 286
    frame #14: 0x00007fffab1f408d libsystem_pthread.dylib`thread_start + 13

  thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fffa9b734cd libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
    frame #3: 0x0000000100f76b6f libThread.so`void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex> >(this=0x0000000122753a28, __lock=0x00007fff5fbf5cf8) at condition_variable:202
    frame #4: 0x0000000100f6887e libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock() [inlined] void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex>, ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock()::'lambda'()>(this=0x0000000122753a28, __lock=0x00007fff5fbf5cf8, __pred=(anonymous class) @ 0x00007fff5fbf5e08)::'lambda'()) at condition_variable:211
    frame #5: 0x0000000100f68857 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock(this=0x00000001227539d8) at TReentrantRWLock.cxx:95
    frame #6: 0x0000000100f5c719 libThread.so`ROOT::TRWMutexImp<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock(this=0x00000001227539d0) at TRWMutexImp.cxx:33
    frame #7: 0x00000001000f52d1 libCore.so`ROOT::TReadLockGuard::TReadLockGuard(this=0x00007fff5fbf5f48, mutex=0x00000001227539d0) at TVirtualRWMutex.h:89
    frame #8: 0x00000001000f275d libCore.so`ROOT::TReadLockGuard::TReadLockGuard(this=0x00007fff5fbf5f48, mutex=0x00000001227539d0) at TVirtualRWMutex.h:88
    frame #9: 0x00000001002fcebf libCore.so`THashTable::FindObject(this=0x0000000100b0e120, name="TGTextView") const at THashTable.cxx:242
    frame #10: 0x00000001003a67fd libCore.so`TClass::GetClass(name="TGTextView", load=true, silent=true) at TClass.cxx:2900
    frame #11: 0x00000001003c9e16 libCore.so`TClass::InheritsFrom(this=0x0000000118fe1250, classname="TGTextView") const at TClass.cxx:4683
    frame #12: 0x000000010024cb6e libCore.so`TObject::InheritsFrom(this=0x0000000126908de0, classname="TGTextView") const at TObject.cxx:445
    frame #13: 0x000000011c03e47f libGCocoa.so`ROOT::MacOSX::X11::ViewIsTextView(viewID=116) at QuartzWindow.mm:899
    frame #14: 0x000000011c03e518 libGCocoa.so`ROOT::MacOSX::X11::ViewIsTextView(view=0x0000000126908ee0) at QuartzWindow.mm:907
    frame #15: 0x000000011c04706c libGCocoa.so`::-[QuartzView drawRect:](self=0x0000000126908ee0, _cmd="drawRect:", dirtyRect=(origin = (x = 0, y = 0), size = (width = 29, height = 21))) at QuartzWindow.mm:2728
    frame #16: 0x00007fff934a4f99 AppKit`-[NSView _drawRect:clip:] + 2276
    frame #17: 0x00007fff934f4f2f AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1753
    frame #18: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #19: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #20: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #21: 0x00007fff934a2ad2 AppKit`-[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 837
    frame #22: 0x00007fff934a22af AppKit`-[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 334
    frame #23: 0x00007fff934a06d8 AppKit`-[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2452
    frame #24: 0x00007fff9349bfca AppKit`-[NSView displayIfNeeded] + 1748
    frame #25: 0x00007fff9349b8db AppKit`-[NSWindow displayIfNeeded] + 230
    frame #26: 0x00007fff93bfbcb4 AppKit`___NSWindowGetDisplayCycleObserver_block_invoke.6228 + 277
    frame #27: 0x00007fff9349b3b9 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 454
    frame #28: 0x00007fff9b384cc6 QuartzCore`CA::Transaction::run_commit_handlers(CATransactionPhase) + 46
    frame #29: 0x00007fff9b48e8ac QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 160
    frame #30: 0x00007fff9b3837a1 QuartzCore`CA::Transaction::commit() + 475
    frame #31: 0x00007fff9377e8b1 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke.31 + 323
    frame #32: 0x00007fff95874d37 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    frame #33: 0x00007fff95874ca7 CoreFoundation`__CFRunLoopDoObservers + 391
    frame #34: 0x00007fff958556d9 CoreFoundation`__CFRunLoopRun + 873
    frame #35: 0x00007fff95855114 CoreFoundation`CFRunLoopRunSpecific + 420
    frame #36: 0x00007fff94db5ebc HIToolbox`RunCurrentEventLoopInMode + 240
    frame #37: 0x00007fff94db5bf9 HIToolbox`ReceiveNextEventCommon + 184
    frame #38: 0x00007fff94db5b26 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame #39: 0x00007fff9334ca54 AppKit`_DPSNextEvent + 1120
    frame #40: 0x00007fff93ac87ee AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
    frame #41: 0x0000000100491031 libCore.so`TMacOSXSystem::ProcessPendingEvents(this=0x0000000100c06d60) at TMacOSXSystem.mm:473
    frame #42: 0x000000010049097d libCore.so`TMacOSXSystem::DispatchOneEvent(this=0x0000000100c06d60, pendingOnly=true) at TMacOSXSystem.mm:365
    frame #43: 0x0000000100294f4b libCore.so`TSystem::ProcessEvents(this=0x0000000100c06d60) at TSystem.cxx:429
    frame #44: 0x0000000100fe5844 threadsh2_C.so`threadsh2() at threadsh2.C:196
    frame #45: 0x0000000100fec06a
    frame #46: 0x0000000103d7dc2f libCling.so`cling::IncrementalExecutor::executeWrapper(this=0x0000000100a1d410, function=(Data = "_Z15__cling_Un1Qu30Pv", Length = 21), returnValue=0x00007fff5fbfbde0) at IncrementalExecutor.h:196
    frame #47: 0x0000000103d7db1f libCling.so`cling::Interpreter::RunFunction(this=0x0000000100a0e3b0, FD=0x000000011780f6b0, res=0x00007fff5fbfbde0) at Interpreter.cpp:980
    frame #48: 0x0000000103d7a92a libCling.so`cling::Interpreter::EvaluateInternal(this=0x0000000100a0e3b0, input="threadsh2()", CO=CompilationOptions @ 0x00007fff5fbfaae8, V=0x00007fff5fbfbde0, T=0x0000000000000000, wrapPoint=44) at Interpreter.cpp:1232
    frame #49: 0x0000000103d79e27 libCling.so`cling::Interpreter::process(this=0x0000000100a0e3b0, input="threadsh2()", V=0x00007fff5fbfbde0, T=0x0000000000000000, disableValuePrinting=false) at Interpreter.cpp:684
    frame #50: 0x0000000103e552a5 libCling.so`cling::MetaProcessor::process(this=0x0000000100b65aa0, input_line=(Data = "threadsh2()", Length = 11), compRes=0x00007fff5fbfb540, result=0x00007fff5fbfbde0, disableValuePrinting=false) at MetaProcessor.cpp:341
    frame #51: 0x000000010397bd63 libCling.so`HandleInterpreterException(metaProcessor=0x0000000100b65aa0, input_line="threadsh2()", compRes=0x00007fff5fbfb540, result=0x00007fff5fbfbde0) at TCling.cxx:2053
    frame #52: 0x000000010397a16e libCling.so`TCling::ProcessLine(this=0x0000000100a0de40, line=".X  /opt/build/root_builds/master.debug/tutorials/thread/./threadsh2.C+", error=0x00007fff5fbfd694) at TCling.cxx:2170
    frame #53: 0x0000000103984436 libCling.so`TCling::ProcessLineSynch(this=0x0000000100a0de40, line=".X  /opt/build/root_builds/master.debug/tutorials/thread/./threadsh2.C+", error=0x00007fff5fbfd694) at TCling.cxx:3044
    frame #54: 0x00000001001f3133 libCore.so`TApplication::ExecuteFile(file="threadsh2.C+", error=0x00007fff5fbfd694, keep=false) at TApplication.cxx:1143
    frame #55: 0x00000001001f19e0 libCore.so`TApplication::ProcessFile(this=0x0000000100b113e0, file="threadsh2.C+", error=0x00007fff5fbfd694, keep=false) at TApplication.cxx:1015
    frame #56: 0x00000001001f138f libCore.so`TApplication::ProcessLine(this=0x0000000100b113e0, line=".x threadsh2.C+", sync=false, err=0x00007fff5fbfd694) at TApplication.cxx:988
    frame #57: 0x000000010009878d libRint.so`TRint::ProcessLineNr(this=0x0000000100b113e0, filestem="ROOT_cli_", line=".x threadsh2.C+", error=0x00007fff5fbfd694) at TRint.cxx:756
    frame #58: 0x0000000100097daf libRint.so`TRint::Run(this=0x0000000100b113e0, retrn=false) at TRint.cxx:416
    frame #59: 0x00000001000027a4 root.exe`main(argc=1, argv=0x00007fff5fbff780) at rmain.cxx:30
    frame #60: 0x00007fffaafdb235 libdyld.dylib`start + 1

  thread #12
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fffa9b734cd libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
    frame #3: 0x0000000100f76b6f libThread.so`void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex> >(this=0x0000000122753a28, __lock=0x0000700009f18898) at condition_variable:202
    frame #4: 0x0000000100f697b4 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock() [inlined] void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex>, ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock()::'lambda'()>(this=0x0000000122753a28, __lock=0x0000700009f18898, __pred=(anonymous class) @ 0x0000700009f18a28)::'lambda'()) at condition_variable:211
    frame #5: 0x0000000100f69790 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock(this=0x00000001227539d8) at TReentrantRWLock.cxx:175
    frame #6: 0x0000000100f5c779 libThread.so`ROOT::TRWMutexImp<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock(this=0x00000001227539d0) at TRWMutexImp.cxx:42
    frame #7: 0x0000000100f57df6 libThread.so`ROOT::TVirtualRWMutex::Lock(this=0x00000001227539d0) at TVirtualRWMutex.h:52
    frame #8: 0x00000001039b2dd9 libCling.so`TLockGuard::TLockGuard(this=0x0000700009f18b48, mutex=0x00000001227539d0) at TVirtualMutex.h:85
    frame #9: 0x000000010397ba8d libCling.so`TLockGuard::TLockGuard(this=0x0000700009f18b48, mutex=0x00000001227539d0) at TVirtualMutex.h:85
    frame #10: 0x00000001039aa152 libCling.so`TCling::ClassInfo_Factory(this=0x0000000100a0de40, all=true) const at TCling.cxx:7216
    frame #11: 0x00000001004150ba libCore.so`TMethodCall::Init(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="", objectIsConst=false) at TMethodCall.cxx:259
    frame #12: 0x0000000100414ff3 libCore.so`TMethodCall::TMethodCall(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="") at TMethodCall.cxx:62
    frame #13: 0x000000010041519d libCore.so`TMethodCall::TMethodCall(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="") at TMethodCall.cxx:61
    frame #14: 0x0000000100fe471a threadsh2_C.so`handle1((null)=0x0000000000000000) at threadsh2.C:48
    frame #15: 0x0000000100f55680 libThread.so`TThread::Function(ptr=0x0000000122754790) at TThread.cxx:821
    frame #16: 0x00007fffab1f493b libsystem_pthread.dylib`_pthread_body + 180
    frame #17: 0x00007fffab1f4887 libsystem_pthread.dylib`_pthread_start + 286
    frame #18: 0x00007fffab1f408d libsystem_pthread.dylib`thread_start + 13
@pcanal pcanal closed this Feb 2, 2018
pcanal added a commit that referenced this pull request Feb 5, 2018
In the example below, thread #11 is waiting on the ‘AppKit lock’ while thread #1 is waiting on the ROOT read lock and thread #12 is waiting on the ROOT write lock.

In thread #11, the ROOT write lock is taken/held by frame #9, TCanvas::Update, to ‘serialize’ the update to the windowing system.

In thread #1, the ‘AppKit lock’ is likely taken/held by a frame in the #16 to root-project#40 range.

This commit remove the dead lock by removing the unnecessary use of code needing the ROOT lock within code run under the AppKit lock so that in they case thread #1 no longer need to wait for the ROOT (read) lock.

In addition it should be investigated whether the ROOT (write) lock should be taken in thread #1, frame 1 (TMacOSXSystem::ProcessPendingEvents) for the same reason it is taken in TCanvas::Update.

  thread #11
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fff93394e34 AppKit`-[NSViewHierarchyLock lockForReadingWithExceptionHandler:] + 287
    frame #3: 0x00007fff934948ae AppKit`-[NSWindow _copyAcquiredViewHierarchyLock] + 126
    frame #4: 0x00007fff9349442c AppKit`-[NSView lockFocusIfCanDraw] + 159
    frame #5: 0x000000011c09063d libGCocoa.so`ROOT::MacOSX::X11::CommandBuffer::Flush(this=0x0000000100dbb080, impl=0x0000000100dbb000) at X11Buffer.mm:550
    frame #6: 0x000000011c04e9c4 libGCocoa.so`TGCocoa::Update(this=0x0000000100ad1bc0, mode=1) at TGCocoa.mm:536
    frame #7: 0x000000011c04ff3e libGCocoa.so`TGCocoa::UpdateWindow(this=0x0000000100ad1bc0, (null)=1) at TGCocoa.mm:776
    frame #8: 0x000000011ad70827 libGpad.so`TCanvas::Flush(this=0x000000012274e740) at TCanvas.cxx:1096
    frame #9: 0x000000011ad7830f libGpad.so`TCanvas::Update(this=0x000000012274e740) at TCanvas.cxx:2287
    frame #10: 0x0000000100fe4e86 threadsh2_C.so`handle2((null)=0x0000000000000001) at threadsh2.C:105
    frame #11: 0x0000000100f55680 libThread.so`TThread::Function(ptr=0x0000000122753b00) at TThread.cxx:821
    frame #12: 0x00007fffab1f493b libsystem_pthread.dylib`_pthread_body + 180
    frame #13: 0x00007fffab1f4887 libsystem_pthread.dylib`_pthread_start + 286
    frame #14: 0x00007fffab1f408d libsystem_pthread.dylib`thread_start + 13

  thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fffa9b734cd libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
    frame #3: 0x0000000100f76b6f libThread.so`void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex> >(this=0x0000000122753a28, __lock=0x00007fff5fbf5cf8) at condition_variable:202
    frame #4: 0x0000000100f6887e libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock() [inlined] void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex>, ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock()::'lambda'()>(this=0x0000000122753a28, __lock=0x00007fff5fbf5cf8, __pred=(anonymous class) @ 0x00007fff5fbf5e08)::'lambda'()) at condition_variable:211
    frame #5: 0x0000000100f68857 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock(this=0x00000001227539d8) at TReentrantRWLock.cxx:95
    frame #6: 0x0000000100f5c719 libThread.so`ROOT::TRWMutexImp<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock(this=0x00000001227539d0) at TRWMutexImp.cxx:33
    frame #7: 0x00000001000f52d1 libCore.so`ROOT::TReadLockGuard::TReadLockGuard(this=0x00007fff5fbf5f48, mutex=0x00000001227539d0) at TVirtualRWMutex.h:89
    frame #8: 0x00000001000f275d libCore.so`ROOT::TReadLockGuard::TReadLockGuard(this=0x00007fff5fbf5f48, mutex=0x00000001227539d0) at TVirtualRWMutex.h:88
    frame #9: 0x00000001002fcebf libCore.so`THashTable::FindObject(this=0x0000000100b0e120, name="TGTextView") const at THashTable.cxx:242
    frame #10: 0x00000001003a67fd libCore.so`TClass::GetClass(name="TGTextView", load=true, silent=true) at TClass.cxx:2900
    frame #11: 0x00000001003c9e16 libCore.so`TClass::InheritsFrom(this=0x0000000118fe1250, classname="TGTextView") const at TClass.cxx:4683
    frame #12: 0x000000010024cb6e libCore.so`TObject::InheritsFrom(this=0x0000000126908de0, classname="TGTextView") const at TObject.cxx:445
    frame #13: 0x000000011c03e47f libGCocoa.so`ROOT::MacOSX::X11::ViewIsTextView(viewID=116) at QuartzWindow.mm:899
    frame #14: 0x000000011c03e518 libGCocoa.so`ROOT::MacOSX::X11::ViewIsTextView(view=0x0000000126908ee0) at QuartzWindow.mm:907
    frame #15: 0x000000011c04706c libGCocoa.so`::-[QuartzView drawRect:](self=0x0000000126908ee0, _cmd="drawRect:", dirtyRect=(origin = (x = 0, y = 0), size = (width = 29, height = 21))) at QuartzWindow.mm:2728
    frame #16: 0x00007fff934a4f99 AppKit`-[NSView _drawRect:clip:] + 2276
    frame #17: 0x00007fff934f4f2f AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1753
    frame #18: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #19: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #20: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #21: 0x00007fff934a2ad2 AppKit`-[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 837
    frame #22: 0x00007fff934a22af AppKit`-[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 334
    frame root-project#23: 0x00007fff934a06d8 AppKit`-[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2452
    frame root-project#24: 0x00007fff9349bfca AppKit`-[NSView displayIfNeeded] + 1748
    frame root-project#25: 0x00007fff9349b8db AppKit`-[NSWindow displayIfNeeded] + 230
    frame root-project#26: 0x00007fff93bfbcb4 AppKit`___NSWindowGetDisplayCycleObserver_block_invoke.6228 + 277
    frame root-project#27: 0x00007fff9349b3b9 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 454
    frame root-project#28: 0x00007fff9b384cc6 QuartzCore`CA::Transaction::run_commit_handlers(CATransactionPhase) + 46
    frame root-project#29: 0x00007fff9b48e8ac QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 160
    frame root-project#30: 0x00007fff9b3837a1 QuartzCore`CA::Transaction::commit() + 475
    frame root-project#31: 0x00007fff9377e8b1 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke.31 + 323
    frame root-project#32: 0x00007fff95874d37 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    frame root-project#33: 0x00007fff95874ca7 CoreFoundation`__CFRunLoopDoObservers + 391
    frame root-project#34: 0x00007fff958556d9 CoreFoundation`__CFRunLoopRun + 873
    frame root-project#35: 0x00007fff95855114 CoreFoundation`CFRunLoopRunSpecific + 420
    frame root-project#36: 0x00007fff94db5ebc HIToolbox`RunCurrentEventLoopInMode + 240
    frame root-project#37: 0x00007fff94db5bf9 HIToolbox`ReceiveNextEventCommon + 184
    frame root-project#38: 0x00007fff94db5b26 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame root-project#39: 0x00007fff9334ca54 AppKit`_DPSNextEvent + 1120
    frame root-project#40: 0x00007fff93ac87ee AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
    frame root-project#41: 0x0000000100491031 libCore.so`TMacOSXSystem::ProcessPendingEvents(this=0x0000000100c06d60) at TMacOSXSystem.mm:473
    frame root-project#42: 0x000000010049097d libCore.so`TMacOSXSystem::DispatchOneEvent(this=0x0000000100c06d60, pendingOnly=true) at TMacOSXSystem.mm:365
    frame root-project#43: 0x0000000100294f4b libCore.so`TSystem::ProcessEvents(this=0x0000000100c06d60) at TSystem.cxx:429
    frame root-project#44: 0x0000000100fe5844 threadsh2_C.so`threadsh2() at threadsh2.C:196
    frame root-project#45: 0x0000000100fec06a
    frame root-project#46: 0x0000000103d7dc2f libCling.so`cling::IncrementalExecutor::executeWrapper(this=0x0000000100a1d410, function=(Data = "_Z15__cling_Un1Qu30Pv", Length = 21), returnValue=0x00007fff5fbfbde0) at IncrementalExecutor.h:196
    frame root-project#47: 0x0000000103d7db1f libCling.so`cling::Interpreter::RunFunction(this=0x0000000100a0e3b0, FD=0x000000011780f6b0, res=0x00007fff5fbfbde0) at Interpreter.cpp:980
    frame root-project#48: 0x0000000103d7a92a libCling.so`cling::Interpreter::EvaluateInternal(this=0x0000000100a0e3b0, input="threadsh2()", CO=CompilationOptions @ 0x00007fff5fbfaae8, V=0x00007fff5fbfbde0, T=0x0000000000000000, wrapPoint=44) at Interpreter.cpp:1232
    frame root-project#49: 0x0000000103d79e27 libCling.so`cling::Interpreter::process(this=0x0000000100a0e3b0, input="threadsh2()", V=0x00007fff5fbfbde0, T=0x0000000000000000, disableValuePrinting=false) at Interpreter.cpp:684
    frame root-project#50: 0x0000000103e552a5 libCling.so`cling::MetaProcessor::process(this=0x0000000100b65aa0, input_line=(Data = "threadsh2()", Length = 11), compRes=0x00007fff5fbfb540, result=0x00007fff5fbfbde0, disableValuePrinting=false) at MetaProcessor.cpp:341
    frame root-project#51: 0x000000010397bd63 libCling.so`HandleInterpreterException(metaProcessor=0x0000000100b65aa0, input_line="threadsh2()", compRes=0x00007fff5fbfb540, result=0x00007fff5fbfbde0) at TCling.cxx:2053
    frame root-project#52: 0x000000010397a16e libCling.so`TCling::ProcessLine(this=0x0000000100a0de40, line=".X  /opt/build/root_builds/master.debug/tutorials/thread/./threadsh2.C+", error=0x00007fff5fbfd694) at TCling.cxx:2170
    frame root-project#53: 0x0000000103984436 libCling.so`TCling::ProcessLineSynch(this=0x0000000100a0de40, line=".X  /opt/build/root_builds/master.debug/tutorials/thread/./threadsh2.C+", error=0x00007fff5fbfd694) at TCling.cxx:3044
    frame root-project#54: 0x00000001001f3133 libCore.so`TApplication::ExecuteFile(file="threadsh2.C+", error=0x00007fff5fbfd694, keep=false) at TApplication.cxx:1143
    frame root-project#55: 0x00000001001f19e0 libCore.so`TApplication::ProcessFile(this=0x0000000100b113e0, file="threadsh2.C+", error=0x00007fff5fbfd694, keep=false) at TApplication.cxx:1015
    frame root-project#56: 0x00000001001f138f libCore.so`TApplication::ProcessLine(this=0x0000000100b113e0, line=".x threadsh2.C+", sync=false, err=0x00007fff5fbfd694) at TApplication.cxx:988
    frame root-project#57: 0x000000010009878d libRint.so`TRint::ProcessLineNr(this=0x0000000100b113e0, filestem="ROOT_cli_", line=".x threadsh2.C+", error=0x00007fff5fbfd694) at TRint.cxx:756
    frame root-project#58: 0x0000000100097daf libRint.so`TRint::Run(this=0x0000000100b113e0, retrn=false) at TRint.cxx:416
    frame root-project#59: 0x00000001000027a4 root.exe`main(argc=1, argv=0x00007fff5fbff780) at rmain.cxx:30
    frame root-project#60: 0x00007fffaafdb235 libdyld.dylib`start + 1

  thread #12
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fffa9b734cd libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
    frame #3: 0x0000000100f76b6f libThread.so`void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex> >(this=0x0000000122753a28, __lock=0x0000700009f18898) at condition_variable:202
    frame #4: 0x0000000100f697b4 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock() [inlined] void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex>, ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock()::'lambda'()>(this=0x0000000122753a28, __lock=0x0000700009f18898, __pred=(anonymous class) @ 0x0000700009f18a28)::'lambda'()) at condition_variable:211
    frame #5: 0x0000000100f69790 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock(this=0x00000001227539d8) at TReentrantRWLock.cxx:175
    frame #6: 0x0000000100f5c779 libThread.so`ROOT::TRWMutexImp<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock(this=0x00000001227539d0) at TRWMutexImp.cxx:42
    frame #7: 0x0000000100f57df6 libThread.so`ROOT::TVirtualRWMutex::Lock(this=0x00000001227539d0) at TVirtualRWMutex.h:52
    frame #8: 0x00000001039b2dd9 libCling.so`TLockGuard::TLockGuard(this=0x0000700009f18b48, mutex=0x00000001227539d0) at TVirtualMutex.h:85
    frame #9: 0x000000010397ba8d libCling.so`TLockGuard::TLockGuard(this=0x0000700009f18b48, mutex=0x00000001227539d0) at TVirtualMutex.h:85
    frame #10: 0x00000001039aa152 libCling.so`TCling::ClassInfo_Factory(this=0x0000000100a0de40, all=true) const at TCling.cxx:7216
    frame #11: 0x00000001004150ba libCore.so`TMethodCall::Init(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="", objectIsConst=false) at TMethodCall.cxx:259
    frame #12: 0x0000000100414ff3 libCore.so`TMethodCall::TMethodCall(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="") at TMethodCall.cxx:62
    frame #13: 0x000000010041519d libCore.so`TMethodCall::TMethodCall(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="") at TMethodCall.cxx:61
    frame #14: 0x0000000100fe471a threadsh2_C.so`handle1((null)=0x0000000000000000) at threadsh2.C:48
    frame #15: 0x0000000100f55680 libThread.so`TThread::Function(ptr=0x0000000122754790) at TThread.cxx:821
    frame #16: 0x00007fffab1f493b libsystem_pthread.dylib`_pthread_body + 180
    frame #17: 0x00007fffab1f4887 libsystem_pthread.dylib`_pthread_start + 286
    frame #18: 0x00007fffab1f408d libsystem_pthread.dylib`thread_start + 13
pcanal added a commit that referenced this pull request Mar 30, 2018
In the example below, thread #11 is waiting on the ‘AppKit lock’ while thread #1 is waiting on the ROOT read lock and thread #12 is waiting on the ROOT write lock.

In thread #11, the ROOT write lock is taken/held by frame #9, TCanvas::Update, to ‘serialize’ the update to the windowing system.

In thread #1, the ‘AppKit lock’ is likely taken/held by a frame in the #16 to root-project#40 range.

This commit remove the dead lock by removing the unnecessary use of code needing the ROOT lock within code run under the AppKit lock so that in they case thread #1 no longer need to wait for the ROOT (read) lock.

In addition it should be investigated whether the ROOT (write) lock should be taken in thread #1, frame 1 (TMacOSXSystem::ProcessPendingEvents) for the same reason it is taken in TCanvas::Update.

  thread #11
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fff93394e34 AppKit`-[NSViewHierarchyLock lockForReadingWithExceptionHandler:] + 287
    frame #3: 0x00007fff934948ae AppKit`-[NSWindow _copyAcquiredViewHierarchyLock] + 126
    frame #4: 0x00007fff9349442c AppKit`-[NSView lockFocusIfCanDraw] + 159
    frame #5: 0x000000011c09063d libGCocoa.so`ROOT::MacOSX::X11::CommandBuffer::Flush(this=0x0000000100dbb080, impl=0x0000000100dbb000) at X11Buffer.mm:550
    frame #6: 0x000000011c04e9c4 libGCocoa.so`TGCocoa::Update(this=0x0000000100ad1bc0, mode=1) at TGCocoa.mm:536
    frame #7: 0x000000011c04ff3e libGCocoa.so`TGCocoa::UpdateWindow(this=0x0000000100ad1bc0, (null)=1) at TGCocoa.mm:776
    frame #8: 0x000000011ad70827 libGpad.so`TCanvas::Flush(this=0x000000012274e740) at TCanvas.cxx:1096
    frame #9: 0x000000011ad7830f libGpad.so`TCanvas::Update(this=0x000000012274e740) at TCanvas.cxx:2287
    frame #10: 0x0000000100fe4e86 threadsh2_C.so`handle2((null)=0x0000000000000001) at threadsh2.C:105
    frame #11: 0x0000000100f55680 libThread.so`TThread::Function(ptr=0x0000000122753b00) at TThread.cxx:821
    frame #12: 0x00007fffab1f493b libsystem_pthread.dylib`_pthread_body + 180
    frame #13: 0x00007fffab1f4887 libsystem_pthread.dylib`_pthread_start + 286
    frame #14: 0x00007fffab1f408d libsystem_pthread.dylib`thread_start + 13

  thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fffa9b734cd libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
    frame #3: 0x0000000100f76b6f libThread.so`void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex> >(this=0x0000000122753a28, __lock=0x00007fff5fbf5cf8) at condition_variable:202
    frame #4: 0x0000000100f6887e libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock() [inlined] void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex>, ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock()::'lambda'()>(this=0x0000000122753a28, __lock=0x00007fff5fbf5cf8, __pred=(anonymous class) @ 0x00007fff5fbf5e08)::'lambda'()) at condition_variable:211
    frame #5: 0x0000000100f68857 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock(this=0x00000001227539d8) at TReentrantRWLock.cxx:95
    frame #6: 0x0000000100f5c719 libThread.so`ROOT::TRWMutexImp<std::__1::mutex, ROOT::Internal::RecurseCounts>::ReadLock(this=0x00000001227539d0) at TRWMutexImp.cxx:33
    frame #7: 0x00000001000f52d1 libCore.so`ROOT::TReadLockGuard::TReadLockGuard(this=0x00007fff5fbf5f48, mutex=0x00000001227539d0) at TVirtualRWMutex.h:89
    frame #8: 0x00000001000f275d libCore.so`ROOT::TReadLockGuard::TReadLockGuard(this=0x00007fff5fbf5f48, mutex=0x00000001227539d0) at TVirtualRWMutex.h:88
    frame #9: 0x00000001002fcebf libCore.so`THashTable::FindObject(this=0x0000000100b0e120, name="TGTextView") const at THashTable.cxx:242
    frame #10: 0x00000001003a67fd libCore.so`TClass::GetClass(name="TGTextView", load=true, silent=true) at TClass.cxx:2900
    frame #11: 0x00000001003c9e16 libCore.so`TClass::InheritsFrom(this=0x0000000118fe1250, classname="TGTextView") const at TClass.cxx:4683
    frame #12: 0x000000010024cb6e libCore.so`TObject::InheritsFrom(this=0x0000000126908de0, classname="TGTextView") const at TObject.cxx:445
    frame #13: 0x000000011c03e47f libGCocoa.so`ROOT::MacOSX::X11::ViewIsTextView(viewID=116) at QuartzWindow.mm:899
    frame #14: 0x000000011c03e518 libGCocoa.so`ROOT::MacOSX::X11::ViewIsTextView(view=0x0000000126908ee0) at QuartzWindow.mm:907
    frame #15: 0x000000011c04706c libGCocoa.so`::-[QuartzView drawRect:](self=0x0000000126908ee0, _cmd="drawRect:", dirtyRect=(origin = (x = 0, y = 0), size = (width = 29, height = 21))) at QuartzWindow.mm:2728
    frame #16: 0x00007fff934a4f99 AppKit`-[NSView _drawRect:clip:] + 2276
    frame #17: 0x00007fff934f4f2f AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1753
    frame #18: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #19: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #20: 0x00007fff934f539a AppKit`-[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2884
    frame #21: 0x00007fff934a2ad2 AppKit`-[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 837
    frame #22: 0x00007fff934a22af AppKit`-[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 334
    frame root-project#23: 0x00007fff934a06d8 AppKit`-[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2452
    frame root-project#24: 0x00007fff9349bfca AppKit`-[NSView displayIfNeeded] + 1748
    frame root-project#25: 0x00007fff9349b8db AppKit`-[NSWindow displayIfNeeded] + 230
    frame root-project#26: 0x00007fff93bfbcb4 AppKit`___NSWindowGetDisplayCycleObserver_block_invoke.6228 + 277
    frame root-project#27: 0x00007fff9349b3b9 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 454
    frame root-project#28: 0x00007fff9b384cc6 QuartzCore`CA::Transaction::run_commit_handlers(CATransactionPhase) + 46
    frame root-project#29: 0x00007fff9b48e8ac QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 160
    frame root-project#30: 0x00007fff9b3837a1 QuartzCore`CA::Transaction::commit() + 475
    frame root-project#31: 0x00007fff9377e8b1 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke.31 + 323
    frame root-project#32: 0x00007fff95874d37 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    frame root-project#33: 0x00007fff95874ca7 CoreFoundation`__CFRunLoopDoObservers + 391
    frame root-project#34: 0x00007fff958556d9 CoreFoundation`__CFRunLoopRun + 873
    frame root-project#35: 0x00007fff95855114 CoreFoundation`CFRunLoopRunSpecific + 420
    frame root-project#36: 0x00007fff94db5ebc HIToolbox`RunCurrentEventLoopInMode + 240
    frame root-project#37: 0x00007fff94db5bf9 HIToolbox`ReceiveNextEventCommon + 184
    frame root-project#38: 0x00007fff94db5b26 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
    frame root-project#39: 0x00007fff9334ca54 AppKit`_DPSNextEvent + 1120
    frame root-project#40: 0x00007fff93ac87ee AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
    frame root-project#41: 0x0000000100491031 libCore.so`TMacOSXSystem::ProcessPendingEvents(this=0x0000000100c06d60) at TMacOSXSystem.mm:473
    frame root-project#42: 0x000000010049097d libCore.so`TMacOSXSystem::DispatchOneEvent(this=0x0000000100c06d60, pendingOnly=true) at TMacOSXSystem.mm:365
    frame root-project#43: 0x0000000100294f4b libCore.so`TSystem::ProcessEvents(this=0x0000000100c06d60) at TSystem.cxx:429
    frame root-project#44: 0x0000000100fe5844 threadsh2_C.so`threadsh2() at threadsh2.C:196
    frame root-project#45: 0x0000000100fec06a
    frame root-project#46: 0x0000000103d7dc2f libCling.so`cling::IncrementalExecutor::executeWrapper(this=0x0000000100a1d410, function=(Data = "_Z15__cling_Un1Qu30Pv", Length = 21), returnValue=0x00007fff5fbfbde0) at IncrementalExecutor.h:196
    frame root-project#47: 0x0000000103d7db1f libCling.so`cling::Interpreter::RunFunction(this=0x0000000100a0e3b0, FD=0x000000011780f6b0, res=0x00007fff5fbfbde0) at Interpreter.cpp:980
    frame root-project#48: 0x0000000103d7a92a libCling.so`cling::Interpreter::EvaluateInternal(this=0x0000000100a0e3b0, input="threadsh2()", CO=CompilationOptions @ 0x00007fff5fbfaae8, V=0x00007fff5fbfbde0, T=0x0000000000000000, wrapPoint=44) at Interpreter.cpp:1232
    frame root-project#49: 0x0000000103d79e27 libCling.so`cling::Interpreter::process(this=0x0000000100a0e3b0, input="threadsh2()", V=0x00007fff5fbfbde0, T=0x0000000000000000, disableValuePrinting=false) at Interpreter.cpp:684
    frame root-project#50: 0x0000000103e552a5 libCling.so`cling::MetaProcessor::process(this=0x0000000100b65aa0, input_line=(Data = "threadsh2()", Length = 11), compRes=0x00007fff5fbfb540, result=0x00007fff5fbfbde0, disableValuePrinting=false) at MetaProcessor.cpp:341
    frame root-project#51: 0x000000010397bd63 libCling.so`HandleInterpreterException(metaProcessor=0x0000000100b65aa0, input_line="threadsh2()", compRes=0x00007fff5fbfb540, result=0x00007fff5fbfbde0) at TCling.cxx:2053
    frame root-project#52: 0x000000010397a16e libCling.so`TCling::ProcessLine(this=0x0000000100a0de40, line=".X  /opt/build/root_builds/master.debug/tutorials/thread/./threadsh2.C+", error=0x00007fff5fbfd694) at TCling.cxx:2170
    frame root-project#53: 0x0000000103984436 libCling.so`TCling::ProcessLineSynch(this=0x0000000100a0de40, line=".X  /opt/build/root_builds/master.debug/tutorials/thread/./threadsh2.C+", error=0x00007fff5fbfd694) at TCling.cxx:3044
    frame root-project#54: 0x00000001001f3133 libCore.so`TApplication::ExecuteFile(file="threadsh2.C+", error=0x00007fff5fbfd694, keep=false) at TApplication.cxx:1143
    frame root-project#55: 0x00000001001f19e0 libCore.so`TApplication::ProcessFile(this=0x0000000100b113e0, file="threadsh2.C+", error=0x00007fff5fbfd694, keep=false) at TApplication.cxx:1015
    frame root-project#56: 0x00000001001f138f libCore.so`TApplication::ProcessLine(this=0x0000000100b113e0, line=".x threadsh2.C+", sync=false, err=0x00007fff5fbfd694) at TApplication.cxx:988
    frame root-project#57: 0x000000010009878d libRint.so`TRint::ProcessLineNr(this=0x0000000100b113e0, filestem="ROOT_cli_", line=".x threadsh2.C+", error=0x00007fff5fbfd694) at TRint.cxx:756
    frame root-project#58: 0x0000000100097daf libRint.so`TRint::Run(this=0x0000000100b113e0, retrn=false) at TRint.cxx:416
    frame root-project#59: 0x00000001000027a4 root.exe`main(argc=1, argv=0x00007fff5fbff780) at rmain.cxx:30
    frame root-project#60: 0x00007fffaafdb235 libdyld.dylib`start + 1

  thread #12
    frame #0: 0x00007fffab109bf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x00007fffab1f57fa libsystem_pthread.dylib`_pthread_cond_wait + 712
    frame #2: 0x00007fffa9b734cd libc++.1.dylib`std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 47
    frame #3: 0x0000000100f76b6f libThread.so`void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex> >(this=0x0000000122753a28, __lock=0x0000700009f18898) at condition_variable:202
    frame #4: 0x0000000100f697b4 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock() [inlined] void std::__1::condition_variable_any::wait<std::__1::unique_lock<std::__1::mutex>, ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock()::'lambda'()>(this=0x0000000122753a28, __lock=0x0000700009f18898, __pred=(anonymous class) @ 0x0000700009f18a28)::'lambda'()) at condition_variable:211
    frame #5: 0x0000000100f69790 libThread.so`ROOT::TReentrantRWLock<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock(this=0x00000001227539d8) at TReentrantRWLock.cxx:175
    frame #6: 0x0000000100f5c779 libThread.so`ROOT::TRWMutexImp<std::__1::mutex, ROOT::Internal::RecurseCounts>::WriteLock(this=0x00000001227539d0) at TRWMutexImp.cxx:42
    frame #7: 0x0000000100f57df6 libThread.so`ROOT::TVirtualRWMutex::Lock(this=0x00000001227539d0) at TVirtualRWMutex.h:52
    frame #8: 0x00000001039b2dd9 libCling.so`TLockGuard::TLockGuard(this=0x0000700009f18b48, mutex=0x00000001227539d0) at TVirtualMutex.h:85
    frame #9: 0x000000010397ba8d libCling.so`TLockGuard::TLockGuard(this=0x0000700009f18b48, mutex=0x00000001227539d0) at TVirtualMutex.h:85
    frame #10: 0x00000001039aa152 libCling.so`TCling::ClassInfo_Factory(this=0x0000000100a0de40, all=true) const at TCling.cxx:7216
    frame #11: 0x00000001004150ba libCore.so`TMethodCall::Init(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="", objectIsConst=false) at TMethodCall.cxx:259
    frame #12: 0x0000000100414ff3 libCore.so`TMethodCall::TMethodCall(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="") at TMethodCall.cxx:62
    frame #13: 0x000000010041519d libCore.so`TMethodCall::TMethodCall(this=0x0000700009f18d80, cl=0x0000000100af0470, method="Print", params="") at TMethodCall.cxx:61
    frame #14: 0x0000000100fe471a threadsh2_C.so`handle1((null)=0x0000000000000000) at threadsh2.C:48
    frame #15: 0x0000000100f55680 libThread.so`TThread::Function(ptr=0x0000000122754790) at TThread.cxx:821
    frame #16: 0x00007fffab1f493b libsystem_pthread.dylib`_pthread_body + 180
    frame #17: 0x00007fffab1f4887 libsystem_pthread.dylib`_pthread_start + 286
    frame #18: 0x00007fffab1f408d libsystem_pthread.dylib`thread_start + 13
pcanal added a commit that referenced this pull request Oct 9, 2018
…railing transactions.

With the current code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

The work-around is to avoid the need for the transaction by marking the class
TGlobal has been guaranteed to have a proper Hash vs RecursiveRemove setup
thus avoid the need to check it at run-time (by JIT code)

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 9, 2018
…railing transactions.

With the current code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

The work-around is to avoid the need for the transaction by marking the class
TGlobal has been guaranteed to have a proper Hash vs RecursiveRemove setup
thus avoid the need to check it at run-time (by JIT code)

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 9, 2018
…railing transactions.

This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672

With the current code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

The work-around is to avoid the need for the transaction by marking the class
TGlobal has been guaranteed to have a proper Hash vs RecursiveRemove setup
thus avoid the need to check it at run-time (by JIT code)

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 9, 2018
…railing transactions.

This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672

With the current code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

The work-around is to avoid the need for the transaction by marking the class
TGlobal has been guaranteed to have a proper Hash vs RecursiveRemove setup
thus avoid the need to check it at run-time (by JIT code)

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 10, 2018
…transactions.

This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672 by having
cling::Interpreter::DeclareCFunction return the transaction containing the
compiled code.

With the previous code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 10, 2018
…transactions.

This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672 by having
cling::Interpreter::DeclareCFunction return the transaction containing the
compiled code.

With the previous code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 11, 2018
…transactions.

This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672 by having
cling::Interpreter::DeclareCFunction return the transaction containing the
compiled code.

With the previous code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal added a commit that referenced this pull request Oct 11, 2018
…transactions.

This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672 by having
cling::Interpreter::DeclareCFunction return the transaction containing the
compiled code.

With the previous code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
root-project#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
root-project#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
root-project#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
root-project#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
root-project#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
root-project#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
root-project#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
root-project#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
root-project#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
root-project#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
root-project#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
root-project#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
root-project#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
root-project#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
root-project#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
root-project#38 0x0000000000400e21 in mytest() ()
root-project#39 0x0000000000400e92 in main ()
pcanal pushed a commit that referenced this pull request Nov 19, 2018
…urrently

in a nutshell, the condition was:
- Thread #1) a task ends and pushes back processing slot
- Thread #2) a task starts and overwrites thread-local TTreeReaderValues
- Thread #1) first task deletes TTreeReader

See root-project@26e8ace
pcanal pushed a commit that referenced this pull request Nov 20, 2018
…urrently

in a nutshell, the condition was:
- Thread #1) a task ends and pushes back processing slot
- Thread #2) a task starts and overwrites thread-local TTreeReaderValues
- Thread #1) first task deletes TTreeReader

See root-project@26e8ace
pcanal pushed a commit that referenced this pull request May 6, 2021
Before, MetaParser might have pointed to a StringRef whose storage
was gone, see asan failure in roottest/cling/other/runfileClose.C below.

This was caused by recursive uses of MetaParser; see stack trace below:
the inner recursion returned, but as the same MetaParser object was used
by both frames, the objects cursor now pointed to freed memory.

Instead, create a MetaParser (and MetaLexer) object per input. That way,
their lifetime corresponds to the lifetime of their input.

=================================================================
==529104==ERROR: AddressSanitizer: stack-use-after-return on address 0x7ffff3afd82a at pc 0x7fffea18df6d bp 0x7fffffff8170 sp 0x7fffffff8168
READ of size 1 at 0x7ffff3afd82a thread T0
[Detaching after fork from child process 529183]
    #0 0x7fffea18df6c in cling::MetaLexer::Lex(cling::Token&) src/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp:58:11
    #1 0x7fffea190d7c in cling::MetaParser::lookAhead(unsigned int) src/interpreter/cling/lib/MetaProcessor/MetaParser.cpp:89:15
    #2 0x7fffea190bd5 in cling::MetaParser::consumeToken() src/interpreter/cling/lib/MetaProcessor/MetaParser.cpp:49:5
    #3 0x7fffea191d4d in cling::MetaParser::isLCommand(cling::MetaSema::ActionResult&) src/interpreter/cling/lib/MetaProcessor/MetaParser.cpp:147:9
    #4 0x7fffea1914dd in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) src/interpreter/cling/lib/MetaProcessor/MetaParser.cpp:123:12
    #5 0x7fffea191216 in cling::MetaParser::isMetaCommand(cling::MetaSema::ActionResult&, cling::Value*) src/interpreter/cling/lib/MetaProcessor/MetaParser.cpp:101:33
    #6 0x7fffea14e5aa in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) src/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp:317:24
    #7 0x7fffe99b67b7 in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) src/core/metacling/src/TCling.cxx:2431:29
    #8 0x7fffe99bde30 in TCling::Load(char const*, bool) src/core/metacling/src/TCling.cxx:3454:10
    #9 0x7ffff7865f11 in TSystem::Load(char const*, char const*, bool) src/core/base/src/TSystem.cxx:1941:27
    #10 0x7ffff7b8a0e3 in TUnixSystem::Load(char const*, char const*, bool) src/core/unix/src/TUnixSystem.cxx:2789:20
    #11 0x7fffd78dd08b  (<unknown module>)
    #12 0x7fffe9f8a5d9 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const src/interpreter/cling/lib/Interpreter/IncrementalExecutor.cpp:376:3
    #13 0x7fffe9d73dc2 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) src/interpreter/cling/lib/Interpreter/Interpreter.cpp:1141:20
    #14 0x7fffe9d6e317 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) src/interpreter/cling/lib/Interpreter/Interpreter.cpp:1391:29
    #15 0x7fffe9d6c1fe in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) src/interpreter/cling/lib/Interpreter/Interpreter.cpp:819:9
    #16 0x7fffea151826 in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) src/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp:507:22
    #17 0x7fffe99b585b in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) src/core/metacling/src/TCling.cxx:2570:39
    #18 0x7fffe99bbfee in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) src/core/metacling/src/TCling.cxx:3496:17
    #19 0x7ffff77203d3 in TApplication::ExecuteFile(char const*, int*, bool) src/core/base/src/TApplication.cxx:1608:30
    #20 0x7ffff771ebdf in TApplication::ProcessFile(char const*, int*, bool) src/core/base/src/TApplication.cxx:1480:11
    #21 0x7ffff771e385 in TApplication::ProcessLine(char const*, bool, int*) src/core/base/src/TApplication.cxx:1453:14
    #22 0x7ffff7f8157a in TRint::ProcessLineNr(char const*, char const*, int*) src/core/rint/src/TRint.cxx:766:11
    root-project#23 0x7ffff7f802f0 in TRint::Run(bool) src/core/rint/src/TRint.cxx:424:22
    root-project#24 0x4ff96d in main src/main/src/rmain.cxx:30:12
    root-project#25 0x7ffff6e040b2 in __libc_start_main /build/glibc-YbNSs7/glibc-2.31/csu/../csu/libc-start.c:308:16
    root-project#26 0x41f35d in _start (asan/bin/root.exe+0x41f35d)

Address 0x7ffff3afd82a is located in stack of thread T0 at offset 42 in frame
    #0 0x7fffe99b3d8f in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) src/core/metacling/src/TCling.cxx:2456

  This frame has 21 object(s):
    [32, 56) 'sLine' (line 2462) <== Memory access at offset 42 is inside this variable
    [96, 104) 'R__guard2471' (line 2471)
    [128, 136) 'R__guard2488' (line 2488)
    [160, 176) 'interpreterFlagsRAII' (line 2491)
    [192, 240) 'result' (line 2511)
    [272, 276) 'compRes' (line 2512)
    [288, 312) 'mod_line' (line 2517)
    [352, 376) 'aclicMode' (line 2518)
    [416, 440) 'arguments' (line 2519)
    [480, 504) 'io' (line 2520)
    [544, 568) 'fname' (line 2521)
    [608, 632) 'ref.tmp' (line 2547)
    [672, 696) 'ref.tmp145' (line 2547)
    [736, 768) 'code' (line 2555)
    [800, 832) 'codeline' (line 2556)
    [864, 1384) 'in' (line 2559)
    [1520, 1552) 'ref.tmp176' (line 2562)
    [1584, 1600) 'agg.tmp'
    [1616, 1624) 'ref.tmp198' (line 2568)
    [1648, 1664) 'agg.tmp207'
    [1680, 1696) 'autoParseRaii' (line 2588)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return src/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp:58:11 in cling::MetaLexer::Lex(cling::Token&)
Shadow bytes around the buggy address:
  0x10007e757ab0: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757ac0: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757ad0: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757ae0: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757af0: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
=>0x10007e757b00: f5 f5 f5 f5 f5[f5]f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757b10: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757b20: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757b30: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757b40: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
  0x10007e757b50: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==529104==ABORTING

    at src/interpreter/cling/lib/MetaProcessor/MetaLexer.cpp:49
    at src/interpreter/cling/lib/MetaProcessor/MetaParser.cpp:41
    compRes=@0x7ffff3afd910: cling::Interpreter::kSuccess, result=0x7ffff3afd8c0, disableValuePrinting=false)
    at src/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp:314
    input_line=0x7ffff3afd829 "#define XYZ 21", compRes=@0x7ffff3afd910: cling::Interpreter::kSuccess,
    result=0x7ffff3afd8c0) at src/core/metacling/src/TCling.cxx:2431
    error=0x7fffd78cb0f4 <x>) at src/core/metacling/src/TCling.cxx:2591
    sync=false, err=0x7fffd78cb0f4 <x>) at src/core/base/src/TApplication.cxx:1472
    line=0x7fffd78c9000 "#define XYZ 21", error=0x7fffd78cb0f4 <x>)
    at src/core/base/src/TROOT.cxx:2328
   from asan/roottest/cling/other/fileClose_C.so
    filename=0x6070000f0fd0 "asan/roottest/cling/other/fileClose_C.so", flag=257)
    at /home/axel/build/llvm/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:6270
    at src/interpreter/cling/lib/Utils/PlatformPosix.cpp:118
    permanent=false, resolved=true)
    at src/interpreter/cling/lib/Interpreter/DynamicLibraryManager.cpp:184
    at src/interpreter/cling/lib/Interpreter/Interpreter.cpp:1444
    T=0x0) at src/interpreter/cling/lib/Interpreter/Interpreter.cpp:1560
    at src/interpreter/cling/lib/MetaProcessor/MetaSema.cpp:57
    actionResult=@0x7ffff39532b0: cling::MetaSema::AR_Success)
pcanal pushed a commit that referenced this pull request Sep 14, 2021
This is to avoid output that doesn't indicate any problem and only makes
the test output harder to interpret.

That's how the output of test 27 was before this commit:
```
[#1] INFO:NumericIntegration -- RooRealIntegral::init(pxyz_Int[z|R]_Norm[x,y,z]_Int[y|R]) using numeric integrator RooIntegrator1D to calculate Int(y)
Test 27 : Integration over non-rectangular regions...............OK
```
pcanal pushed a commit that referenced this pull request Dec 15, 2022
Fixes root-meta-execUnloading which shows
```==768591== Invalid read of size 8
==768591==    at 0x6EFB10E: llvm::ilist_node_base<false>::getNext() const (ilist_node_base.h:29)
==768591==    by 0x6FBF119: llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Function, false, false, void> >::getNext() (ilist_node.h:66)
==768591==    by 0x6FBED48: llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, false, false, void>, false, false>::operator++() (ilist_iterator.h:157)
==768591==    by 0x6FBEA20: llvm::simple_ilist<llvm::Function>::begin() (simple_ilist.h:117)
==768591==    by 0x6FBE40F: llvm::Module::begin() (Module.h:622)
==768591==    by 0x6FBE475: llvm::Module::functions() (Module.h:634)
==768591==    by 0x6FBE22F: cling::TransactionUnloader::unloadModule(llvm::Module*) (TransactionUnloader.cpp:175)
==768591==    by 0x6FBDF83: cling::TransactionUnloader::RevertTransaction(cling::Transaction*) (TransactionUnloader.cpp:126)
==768591==    by 0x6F90CD0: cling::Interpreter::unload(cling::Transaction&) (Interpreter.cpp:1553)
==768591==    by 0x6F90E25: cling::Interpreter::unload(unsigned int) (Interpreter.cpp:1574)
==768591==    by 0x721A9F2: cling::MetaSema::actOnUndoCommand(unsigned int) (MetaSema.cpp:186)
```
...
```
==768591==  Address 0x144b0ce0 is 32 bytes inside a block of size 800 free'd
==768591==    at 0x484399B: operator delete(void*, unsigned long) (vg_replace_malloc.c:935)
==768591==    by 0x6FBC7CA: std::default_delete<llvm::Module>::operator()(llvm::Module*) const (unique_ptr.h:95)
==768591==    by 0x6FBC82D: std::__uniq_ptr_impl<llvm::Module, std::default_delete<llvm::Module> >::reset(llvm::Module*) (unique_ptr.h:203)
==768591==    by 0x6FBC87E: std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >::reset(llvm::Module*) (unique_ptr.h:501)
==768591==    by 0x6FBC04E: std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >::operator=(decltype(nullptr)) (unique_ptr.h:434)
==768591==    by 0x70E60E7: llvm::orc::ThreadSafeModule::~ThreadSafeModule() (ThreadSafeModule.h:116)
==768591==    by 0x936EC79: llvm::orc::IRMaterializationUnit::~IRMaterializationUnit() (Layer.h:31)
==768591==    by 0x93707F5: llvm::orc::BasicIRLayerMaterializationUnit::~BasicIRLayerMaterializationUnit() (Layer.h:121)
==768591==    by 0x9370811: llvm::orc::BasicIRLayerMaterializationUnit::~BasicIRLayerMaterializationUnit() (Layer.h:121)
==768591==    by 0x6E91B45: std::default_delete<llvm::orc::MaterializationUnit>::operator()(llvm::orc::MaterializationUnit*) const (unique_ptr.h:95)
==768591==    by 0x6E8F9A3: std::unique_ptr<llvm::orc::MaterializationUnit, std::default_delete<llvm::orc::MaterializationUnit> >::~unique_ptr() (unique_ptr.h:396)
==768591==    by 0x935D3C3: llvm::orc::JITDylib::UnmaterializedInfo::~UnmaterializedInfo() (Core.h:1062)
==768591==    by 0x935D3DE: void std::_Destroy<llvm::orc::JITDylib::UnmaterializedInfo>(llvm::orc::JITDylib::UnmaterializedInfo*) (stl_construct.h:151)
==768591==    by 0x935D26B: void std::allocator_traits<std::allocator<void> >::destroy<llvm::orc::JITDylib::UnmaterializedInfo>(std::allocator<void>&, llvm::orc::JITDylib::UnmaterializedInfo*) (alloc_traits.h:648)
==768591==    by 0x935CBA0: std::_Sp_counted_ptr_inplace<llvm::orc::JITDylib::UnmaterializedInfo, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() (shared_ptr_base.h:613)
==768591==    by 0x6C39FCE: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (shared_ptr_base.h:346)
==768591==    by 0x6C3CB36: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:1071)
==768591==    by 0x6E98CED: std::__shared_ptr<llvm::orc::JITDylib::UnmaterializedInfo, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:1524)
==768591==    by 0x6E98D09: std::shared_ptr<llvm::orc::JITDylib::UnmaterializedInfo>::~shared_ptr() (shared_ptr.h:175)
==768591==    by 0x932D614: llvm::DenseMapBase<llvm::DenseMap<llvm::orc::SymbolStringPtr, std::shared_ptr<llvm::orc::JITDylib::UnmaterializedInfo>, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, std::shared_ptr<llvm::orc::JITDylib::UnmaterializedInfo> > >, llvm::orc::SymbolStringPtr, std::shared_ptr<llvm::orc::JITDylib::UnmaterializedInfo>, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, std::shared_ptr<llvm::orc::JITDylib::UnmaterializedInfo> > >::erase(llvm::orc::SymbolStringPtr const&) (DenseMap.h:307)
==768591==    by 0x931028D: llvm::orc::JITDylib::removeTracker(llvm::orc::ResourceTracker&) (Core.cpp:1510)
==768591==    by 0x9315060: llvm::orc::ExecutionSession::removeResourceTracker(llvm::orc::ResourceTracker&)::{lambda()#1}::operator()() const (Core.cpp:2155)
==768591==    by 0x93150D0: decltype(auto) llvm::orc::ExecutionSession::runSessionLocked<llvm::orc::ExecutionSession::removeResourceTracker(llvm::orc::ResourceTracker&)::{lambda()#1}>(llvm::orc::ExecutionSession::removeResourceTracker(llvm::orc::ResourceTracker&)::{lambda()#1}&&) (Core.h:1326)
==768591==    by 0x9315272: llvm::orc::ExecutionSession::removeResourceTracker(llvm::orc::ResourceTracker&) (Core.cpp:2152)
==768591==    by 0x93060FD: llvm::orc::ResourceTracker::remove() (Core.cpp:53)
==768591==    by 0x70F1D58: cling::IncrementalJIT::removeModule(cling::Transaction const&) (IncrementalJIT.cpp:151)
==768591==    by 0x6FBE6CF: cling::IncrementalExecutor::unloadModule(cling::Transaction const&) const (IncrementalExecutor.h:180)
==768591==    by 0x6FBDE5B: cling::TransactionUnloader::RevertTransaction(cling::Transaction*) (TransactionUnloader.cpp:119)
==768591==    by 0x6F90CD0: cling::Interpreter::unload(cling::Transaction&) (Interpreter.cpp:1553)
==768591==    by 0x6F90E25: cling::Interpreter::unload(unsigned int) (Interpreter.cpp:1574)
==768591==    by 0x721A9F2: cling::MetaSema::actOnUndoCommand(unsigned int) (MetaSema.cpp:186)
```
pcanal pushed a commit that referenced this pull request Dec 8, 2023
[ RUN      ] RooTruthModel.IntegrateSubrange
[#1] INFO:Eval -- RooRealVar::setRange(dt) new range named 'integral' created with bounds [2,2]
/builddir/build/BUILD/root-6.30.02/roofit/roofitcore/test/testRooTruthModel.cxx:38: Failure
Expected equality of these values:
  integ->getVal()
    Which is: -2.8822093e-17
  0.0
    Which is: 0
[  FAILED  ] RooTruthModel.IntegrateSubrange (194 ms)
pcanal pushed a commit that referenced this pull request Jan 17, 2024
[ RUN      ] RooTruthModel.IntegrateSubrange
[#1] INFO:Eval -- RooRealVar::setRange(dt) new range named 'integral' created with bounds [2,2]
/builddir/build/BUILD/root-6.30.02/roofit/roofitcore/test/testRooTruthModel.cxx:38: Failure
Expected equality of these values:
  integ->getVal()
    Which is: -2.8822093e-17
  0.0
    Which is: 0
[  FAILED  ] RooTruthModel.IntegrateSubrange (194 ms)
pcanal pushed a commit that referenced this pull request May 21, 2024
In the jitted version of the `Vary` transformation a node is allocated on the heap and its address is passed down to the function `JitVariationHelper`, which is also responsible for deleting the allocated memory. In case a mismatch in the return type of the jitted function given to the Vary call is detected, we throw an error to inform the user they should return an RVec for the Vary to properly work. This means that the call to JitVariationHelper does not happen, thus the memory of the node is not deallocated. This commit corrects that behaviour by properly deleting the pointer before throwing the exception.

Thanks to the address sanitizer:
```
Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f28c78d9e28 in operator new(unsigned long) (/lib64/libasan.so.8+0xd9e28) (BuildId: 2b657470ea196ba4342e3bd8a3cc138b1e200599)
    #1 0xb711e0 in std::shared_ptr<ROOT::Detail::RDF::RNodeBase>* ROOT::Internal::RDF::MakeSharedOnHeap<ROOT::Detail::RDF::RNodeBase>(std::shared_ptr<ROOT::Detail::RDF::RNodeBase> const&) /home/vpadulan/Programs/rootproject/rootbuild/master-a73f11dfc5-testing-asan/include/ROOT/RDF/InterfaceUtils.hxx:370
    #2 0xb843a8 in ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager, void>::JittedVaryImpl(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::basic_string_view<char, std::char_traits<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::basic_string_view<char, std::char_traits<char> >, bool) /home/vpadulan/Programs/rootproject/rootbuild/master-a73f11dfc5-testing-asan/include/ROOT/RDF/RInterface.hxx:3108
```
pcanal pushed a commit that referenced this pull request May 28, 2024
In the jitted version of the `Vary` transformation a node is allocated on the heap and its address is passed down to the function `JitVariationHelper`, which is also responsible for deleting the allocated memory. In case a mismatch in the return type of the jitted function given to the Vary call is detected, we throw an error to inform the user they should return an RVec for the Vary to properly work. This means that the call to JitVariationHelper does not happen, thus the memory of the node is not deallocated. This commit corrects that behaviour by properly deleting the pointer before throwing the exception.

Thanks to the address sanitizer:
```
Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f28c78d9e28 in operator new(unsigned long) (/lib64/libasan.so.8+0xd9e28) (BuildId: 2b657470ea196ba4342e3bd8a3cc138b1e200599)
    #1 0xb711e0 in std::shared_ptr<ROOT::Detail::RDF::RNodeBase>* ROOT::Internal::RDF::MakeSharedOnHeap<ROOT::Detail::RDF::RNodeBase>(std::shared_ptr<ROOT::Detail::RDF::RNodeBase> const&) /home/vpadulan/Programs/rootproject/rootbuild/master-a73f11dfc5-testing-asan/include/ROOT/RDF/InterfaceUtils.hxx:370
    #2 0xb843a8 in ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager, void>::JittedVaryImpl(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::basic_string_view<char, std::char_traits<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::basic_string_view<char, std::char_traits<char> >, bool) /home/vpadulan/Programs/rootproject/rootbuild/master-a73f11dfc5-testing-asan/include/ROOT/RDF/RInterface.hxx:3108
```
pcanal pushed a commit that referenced this pull request Jul 2, 2024
This fixes a race condition in which a TTreeReader and its
TTreeReaderValues could be deleted concurrently:
Thread #1) a task ends and pushes back processing slot
Thread #2) a task starts and overwrites thread-local TTreeReaderValues
Thread #1) first task deletes TTreeReader
pcanal pushed a commit that referenced this pull request Aug 7, 2024
The destructor of TTreeReader was making use of the TFile after its destruction.

```
480: ==2560128==ERROR: AddressSanitizer: heap-use-after-free on address 0x617000011648 at pc 0x7fb9d1ae089e bp 0x7ffd8e35b0a0 sp 0x7ffd8e35b098
480: READ of size 8 at 0x617000011648 thread T0
480:     #0 0x7fb9d1ae089d in TTree::GetNotify() const /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/inc/TTree.h:503
480:     #1 0x7fb9d1ae089d in void TNotifyLinkBase::RemoveLink<TTree>(TTree&) /home/vpadulan/Programs/rootproject/rootsrc/core/base/inc/TNotifyLin
k.h:104
480:     #2 0x7fb9d1ae089d in TTreeReader::~TTreeReader() /home/vpadulan/Programs/rootproject/rootsrc/tree/treeplayer/src/TTreeReader.cxx:252
480:     #3 0x433968 in BulkApiSillyStructTest_stdReadSplitBranch_Test::TestBody() /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/test/Bulk
ApiSillyStruct.cxx:104
480:     root-project#4 0x470bac in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)()
, char const*) (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApiSillyStruct+0x4
70bac) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#5 0x45a5f3 in testing::Test::Run() [clone .part.0] (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-
asan/tree/tree/test/testBulkApiSillyStruct+0x45a5f3) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#6 0x45a969 in testing::TestInfo::Run() (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tr
ee/test/testBulkApiSillyStruct+0x45a969) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#7 0x45ab10 in testing::TestSuite::Run() [clone .part.0] (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-tes
ting-asan/tree/tree/test/testBulkApiSillyStruct+0x45ab10) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#8 0x4675be in testing::internal::UnitTestImpl::RunAllTests() (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-fre
e-testing-asan/tree/tree/test/testBulkApiSillyStruct+0x4675be) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#9 0x45af6c in testing::UnitTest::Run() (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tr
ee/test/testBulkApiSillyStruct+0x45af6c) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#10 0x425456 in main (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApi
SillyStruct+0x425456) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:     root-project#11 0x7fb9cd446149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 0d710e9d9dc10c500b8119c85da75004183618e2)
480:     root-project#12 0x7fb9cd44620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 0d710e9d9dc10c500b8119c85da75004183618e2)
480:     root-project#13 0x4257b4 in _start (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkA
piSillyStruct+0x4257b4) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)

480: 0x617000011648 is located 328 bytes inside of 712-byte region [0x617000011500,0x6170000117c8)
480: freed by thread T0 here:
480:     #0 0x7fb9d1eda878 in operator delete(void*) (/lib64/libasan.so.8+0xda878) (BuildId: 2e1c50524ff1a2e7e73c4565b46f3f51892353ea)
480:     #1 0x7fb9cdfb4f25 in TCollection::GarbageCollect(TObject*) /home/vpadulan/Programs/rootproject/rootsrc/core/cont/src/TCollection.cxx:736
480:     #2 0x7fb9cdfe8a27 in TList::Delete(char const*) /home/vpadulan/Programs/rootproject/rootsrc/core/cont/src/TList.cxx:535
480:     #3 0x7fb9cdfc53d7 in THashList::Delete(char const*) /home/vpadulan/Programs/rootproject/rootsrc/core/cont/src/THashList.cxx:215
480:     root-project#4 0x7fb9ce8d285d in TDirectoryFile::Close(char const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TDirectoryFile.cxx:585
480:     root-project#5 0x7fb9ce8d285d in TDirectoryFile::Close(char const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TDirectoryFile.cxx:561
480:     root-project#6 0x7fb9ce9468e4 in TFile::Close(char const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TFile.cxx:989
480:     root-project#7 0x7fb9ce9481fd in TFile::~TFile() /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TFile.cxx:566
480:     root-project#8 0x7fb9ce948fd0 in TFile::~TFile() /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TFile.cxx:603
480:     root-project#9 0x4338cd in BulkApiSillyStructTest_stdReadSplitBranch_Test::TestBody() /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/test/Bulk
ApiSillyStruct.cxx:103
480:     root-project#10 0x470bac in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(
), char const*) (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApiSillyStruct+0x
470bac) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)

480: previously allocated by thread T0 here:
480:     #0 0x7fb9d1ed9e38 in operator new(unsigned long) (/lib64/libasan.so.8+0xd9e38) (BuildId: 2e1c50524ff1a2e7e73c4565b46f3f51892353ea)
480:     #1 0x7fb9cdebbfd0 in TStorage::ObjectAlloc(unsigned long) /home/vpadulan/Programs/rootproject/rootsrc/core/base/src/TStorage.cxx:293
480:     #2 0x7fb9d12cc209 in TObject::operator new(unsigned long) /home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-tes
ting-asan/include/TObject.h:181
480:     #3 0x7fb9d12cc209 in new_TTree /home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/G__Tree
.cxx:4363
480:     root-project#4 0x7fb9ce10a49c in TClass::NewObject(TClass::ENewType, bool) const /home/vpadulan/Programs/rootproject/rootsrc/core/meta/src/TClass.cxx
:5003
480:     root-project#5 0x7fb9ce113c7d in TClass::New(TClass::ENewType, bool) const /home/vpadulan/Programs/rootproject/rootsrc/core/meta/src/TClass.cxx:4980
480:     root-project#6 0x7fb9ce9cda38 in TKey::ReadObjectAny(TClass const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TKey.cxx:1086
480:     root-project#7 0x7fb9ce8d10a7 in TDirectoryFile::GetObjectChecked(char const*, TClass const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/T
DirectoryFile.cxx:1111
480:     root-project#8 0x7fb9d1ade1d1 in void TDirectory::GetObject<TTree>(char const*, TTree*&) /home/vpadulan/Programs/rootproject/rootsrc/core/base/inc/TD
irectory.h:214
480:     root-project#9 0x7fb9d1ade1d1 in TTreeReader::TTreeReader(char const*, TDirectory*, TEntryList*) /home/vpadulan/Programs/rootproject/rootsrc/tree/tre
eplayer/src/TTreeReader.cxx:232
480:     root-project#10 0x433332 in BulkApiSillyStructTest_stdReadSplitBranch_Test::TestBody() /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/test/Bu$
kApiSillyStruct.cxx:87
480:     root-project#11 0x470bac in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(
), char const*) (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApiSillyStruct+0x
470bac) (BuildId: 45d8d15c24ba2aae252398ec00943aba7665b034)
480:
480: SUMMARY: AddressSanitizer: heap-use-after-free /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/inc/TTree.h:503 in TTree::GetNotify() co
nst
```
pcanal pushed a commit that referenced this pull request Aug 7, 2024
Ensure proper TFile memory management and avoid TTreeReader accessing the TFile after its destruction.

```
479: ==2573107==ERROR: AddressSanitizer: heap-use-after-free on address 0x617000051b48 at pc 0x7f0fcf4e089e bp 0x7fff6e7e1fe0 sp 0x7fff6e7e1fd8
479: READ of size 8 at 0x617000051b48 thread T0
479:     #0 0x7f0fcf4e089d in TTree::GetNotify() const /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/inc/TTree.h:503
479:     #1 0x7f0fcf4e089d in void TNotifyLinkBase::RemoveLink<TTree>(TTree&) /home/vpadulan/Programs/rootproject/rootsrc/core/base/inc/TNotifyLin
k.h:104
479:     #2 0x7f0fcf4e089d in TTreeReader::~TTreeReader() /home/vpadulan/Programs/rootproject/rootsrc/tree/treeplayer/src/TTreeReader.cxx:252
479:     #3 0x4321ca in BulkApiVariableTest_stdRead_Test::TestBody() /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/test/BulkApiVarLength.c
xx:135
479:     root-project#4 0x470c8c in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)()
, char const*) (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApiVarLength+0x470
c8c) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479:     root-project#5 0x45a6d3 in testing::Test::Run() [clone .part.0] (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-
asan/tree/tree/test/testBulkApiVarLength+0x45a6d3) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479:     root-project#6 0x45aa49 in testing::TestInfo::Run() (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tr
ee/test/testBulkApiVarLength+0x45aa49) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479:     root-project#7 0x45abf0 in testing::TestSuite::Run() [clone .part.0] (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-tes
ting-asan/tree/tree/test/testBulkApiVarLength+0x45abf0) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479:     root-project#8 0x46769e in testing::internal::UnitTestImpl::RunAllTests() (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-fre
e-testing-asan/tree/tree/test/testBulkApiVarLength+0x46769e) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479:     root-project#9 0x45b04c in testing::UnitTest::Run() (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tr
ee/test/testBulkApiVarLength+0x45b04c) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479:     root-project#10 0x424606 in main (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApi
VarLength+0x424606) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
479: 0x617000051b48 is located 328 bytes inside of 712-byte region [0x617000051a00,0x617000051cc8)

479: freed by thread T0 here:
479:     #0 0x7f0fcf8da878 in operator delete(void*) (/lib64/libasan.so.8+0xda878) (BuildId: 2e1c50524ff1a2e7e73c4565b46f3f51892353ea)
479:     #1 0x7f0fcb9b4f25 in TCollection::GarbageCollect(TObject*) /home/vpadulan/Programs/rootproject/rootsrc/core/cont/src/TCollection.cxx:736
479:     #2 0x7f0fcb9e8a27 in TList::Delete(char const*) /home/vpadulan/Programs/rootproject/rootsrc/core/cont/src/TList.cxx:535
479:     #3 0x7f0fcb9c53d7 in THashList::Delete(char const*) /home/vpadulan/Programs/rootproject/rootsrc/core/cont/src/THashList.cxx:215
479:     root-project#4 0x7f0fcc2d285d in TDirectoryFile::Close(char const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TDirectoryFile.cxx:585
479:     root-project#5 0x7f0fcc2d285d in TDirectoryFile::Close(char const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TDirectoryFile.cxx:561
479:     root-project#6 0x7f0fcc3468e4 in TFile::Close(char const*) /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TFile.cxx:989
479:     root-project#7 0x7f0fcc3481fd in TFile::~TFile() /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TFile.cxx:566
479:     root-project#8 0x7f0fcc348fd0 in TFile::~TFile() /home/vpadulan/Programs/rootproject/rootsrc/io/io/src/TFile.cxx:603
479:     root-project#9 0x432ebf in BulkApiVariableTest_stdRead_Test::TestBody() /home/vpadulan/Programs/rootproject/rootsrc/tree/tree/test/BulkApiVarLength.c
xx:130
479:     root-project#10 0x470c8c in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(
), char const*) (/home/vpadulan/Programs/rootproject/rootbuild/bulksilly-heap-use-after-free-testing-asan/tree/tree/test/testBulkApiVarLength+0x47
0c8c) (BuildId: aac947b72f02e5567382f0dadfefd1e97d058a56)
```
pcanal added a commit that referenced this pull request Sep 20, 2024
On el9 with the following config (and package from uscms cvmfs for
non-builtin depedencies):

cxx17 asimage builtin_clang builtin_cling builtin_gl2ps builtin_gtest
builtin_llvm builtin_lz4 builtin_lzma builtin_nlohmannjson
builtin_openui5 builtin_xxhash builtin_zlib builtin_zstd clad dataframe
davix fitsio gdml http imt mysql opengl pyroot roofit root7 rpath
runtime_cxxmodules shared sqlite ssl tmva tmva-cpu tmva-pymva tpython
spectrum vdt x11 xml xrootd

In particular the following for compressions:

   builtin_lz4 builtin_lzma builtin_zlib builtin_zstd

cmslpc-el9-heavy01:src (master) pcanal$ uname -a
   Linux cmslpc-el9-heavy01.fnal.gov 5.14.0-427.28.1.el9_4.x86_64 #1 SMP
     PREEMPT_DYNAMIC Fri Aug 2 03:44:10 EDT 2024 x86_64 x86_64 x86_64
     GNU/Linux

The test 18 and 43 produced a PNG file that slight smaller that
expected:

Test 18: TGaxis 2.................................................. OK
         PDF output................................................ OK
         JPG output................................................ OK
         PNG output......................................... 18 FAILED
         Result    = 15655
         Reference = 16076
         Error     = 421 (was 350)
         C file result............................................. OK
Test 43: Divided pads and TLatex................................... OK
         PDF output................................................ OK
         JPG output................................................ OK
         PNG output......................................... 43 FAILED
         Result    = 24855
         Reference = 25421
         Error     = 566 (was 300)
         C file result............................................. OK

Visual inspection of the png files showed no differences.
pcanal added a commit that referenced this pull request Sep 26, 2024
On el9 with the following config (and package from uscms cvmfs for
non-builtin depedencies):

cxx17 asimage builtin_clang builtin_cling builtin_gl2ps builtin_gtest
builtin_llvm builtin_lz4 builtin_lzma builtin_nlohmannjson
builtin_openui5 builtin_xxhash builtin_zlib builtin_zstd clad dataframe
davix fitsio gdml http imt mysql opengl pyroot roofit root7 rpath
runtime_cxxmodules shared sqlite ssl tmva tmva-cpu tmva-pymva tpython
spectrum vdt x11 xml xrootd

In particular the following for compressions:

   builtin_lz4 builtin_lzma builtin_zlib builtin_zstd

cmslpc-el9-heavy01:src (master) pcanal$ uname -a
   Linux cmslpc-el9-heavy01.fnal.gov 5.14.0-427.28.1.el9_4.x86_64 #1 SMP
     PREEMPT_DYNAMIC Fri Aug 2 03:44:10 EDT 2024 x86_64 x86_64 x86_64
     GNU/Linux

The test 18 and 43 produced a PNG file that slight smaller that
expected:

Test 18: TGaxis 2.................................................. OK
         PDF output................................................ OK
         JPG output................................................ OK
         PNG output......................................... 18 FAILED
         Result    = 15655
         Reference = 16076
         Error     = 421 (was 350)
         C file result............................................. OK
Test 43: Divided pads and TLatex................................... OK
         PDF output................................................ OK
         JPG output................................................ OK
         PNG output......................................... 43 FAILED
         Result    = 24855
         Reference = 25421
         Error     = 566 (was 300)
         C file result............................................. OK

Visual inspection of the png files showed no differences.
pcanal pushed a commit that referenced this pull request Sep 26, 2024
The test was dynamically allocating the array data members of the `Data` struct, but never deallocating them. This commit polishes the `Data` struct definition and ensures proper management of the data members.

The previous way of writing data to the TTree was leading to a bad memory access in the ReadBasicPointer inlined function in TStreamerInfoReadBuffer.cxx while reading the `double*` array. In particular, the issue arises when accessing and then deallocating the array at the current index provided by the `TCompInfo` object.

```
Target 0: (repro.out) stopped.
(lldb)
Process 13498 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x00000001044cf140 libRIO.so`int TStreamerInfo::ReadBuffer<char**>(this=<unavailable>, b=<unavailable>, arr=<unavailable>, compinfo=<unavailable>, first=<unavailable>, last=<unavailable>, narr=<unavailable>, eoffset=<unavailable>, arrayMode=0) at TStreamerInfoReadBuffer.cxx:923:65 [opt]
   920 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kLong:   ReadBasicPointer(Long_t);  continue;
   921 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kLong64: ReadBasicPointer(Long64_t);  continue;
   922 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kFloat:  ReadBasicPointer(Float_t);  continue;
-> 923 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kDouble: ReadBasicPointer(Double_t);  continue;
   924 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kUChar:  ReadBasicPointer(UChar_t);  continue;
   925 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kUShort: ReadBasicPointer(UShort_t);  continue;
   926 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kUInt:   ReadBasicPointer(UInt_t);  continue;
Target 0: (repro.out) stopped.
(lldb)
Process 13498 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x00000001044cf184 libRIO.so`int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) [inlined] TBuffer::BufferSize(this=0x000060e00010ef00) const at TBuffer.h:98:41 [opt]
   95  	   TObject *GetParent()  const;
   96  	   char    *Buffer()     const { return fBuffer; }
   97  	   char    *GetCurrent() const { return fBufCur; }
-> 98  	   Int_t    BufferSize() const { return fBufSize; }
   99  	   void     DetachBuffer() { fBuffer = nullptr; }
   100 	   Int_t    Length()     const { return (Int_t)(fBufCur - fBuffer); }
   101 	   void     Expand(Int_t newsize, Bool_t copy = kTRUE);  // expand buffer to newsize
Target 0: (repro.out) stopped.
(lldb) p fBufSize
(Int_t) 32008
(lldb) s
Process 13498 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
    frame #0: 0x00000001044cf194 libRIO.so`int TStreamerInfo::ReadBuffer<char**>(this=<unavailable>, b=<unavailable>, arr=<unavailable>, compinfo=<unavailable>, first=<unavailable>, last=<unavailable>, narr=<unavailable>, eoffset=<unavailable>, arrayMode=0) at TStreamerInfoReadBuffer.cxx:923:65 [opt]
   920 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kLong:   ReadBasicPointer(Long_t);  continue;
   921 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kLong64: ReadBasicPointer(Long64_t);  continue;
   922 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kFloat:  ReadBasicPointer(Float_t);  continue;
-> 923 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kDouble: ReadBasicPointer(Double_t);  continue;
   924 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kUChar:  ReadBasicPointer(UChar_t);  continue;
   925 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kUShort: ReadBasicPointer(UShort_t);  continue;
   926 	         case TStreamerInfo::kOffsetP + TStreamerInfo::kUInt:   ReadBasicPointer(UInt_t);  continue;
Target 0: (repro.out) stopped.
(lldb) s
Process 13498 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xbebebebebebebeae)
    frame #0: 0x0000000107bac674 libclang_rt.asan_osx_dynamic.dylib`__asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) + 76
libclang_rt.asan_osx_dynamic.dylib`__asan::Allocator::Deallocate:
->  0x107bac674 <+76>: casalb w8, w9, [x22]
    0x107bac678 <+80>: cmp    w8, #0x2
    0x107bac67c <+84>: b.ne   0x107bac6f4    ; <+204>
    0x107bac680 <+88>: mov    x8, #-0x100000000 ; =-4294967296
Target 0: (repro.out) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xbebebebebebebeae)
  * frame #0: 0x0000000107bac674 libclang_rt.asan_osx_dynamic.dylib`__asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) + 76
    frame #1: 0x0000000107c0c444 libclang_rt.asan_osx_dynamic.dylib`wrap__ZdaPv + 232
    frame #2: 0x00000001044d4a60 libRIO.so`int TStreamerInfo::ReadBuffer<char**>(this=<unavailable>, b=<unavailable>, arr=<unavailable>, compinfo=<unavailable>, first=<unavailable>, last=<unavailable>, narr=<unavailable>, eoffset=<unavailable>, arrayMode=0) at TStreamerInfoReadBuffer.cxx:923:65 [opt]
    frame #3: 0x0000000103ffc888 libRIO.so`TStreamerInfoActions::GenericReadAction(buf=0x000060e00010ef00, addr=0x0000602000056bd0, config=0x0000604000149910) at TStreamerInfoActions.cxx:195:45
    frame #4: 0x0000000103caa5ec libRIO.so`TStreamerInfoActions::TConfiguredAction::operator()(this=0x00006030001693f0, buffer=0x000060e00010ef00, object=0x0000602000056bd0) const at TStreamerInfoActions.h:123:17
    frame #5: 0x0000000103ca9ef8 libRIO.so`TBufferFile::ApplySequence(this=0x000060e00010ef00, sequence=0x000060600011ac20, obj=0x0000602000056bd0) at TBufferFile.cxx:3702:10
    frame #6: 0x00000001064bc570 libTree.so`TBranchElement::ReadLeavesMemberBranchCount(this=0x0000619000566380, b=0x000060e00010ef00) at TBranchElement.cxx:4603:6
    frame #7: 0x0000000106455ce4 libTree.so`TBranch::GetEntry(this=0x0000619000566380, entry=0, getall=0) at TBranch.cxx:1753:4
    frame #8: 0x00000001064a1764 libTree.so`TBranchElement::GetEntry(this=0x0000619000566380, entry=0, getall=0) at TBranchElement.cxx:2783:27
    frame #9: 0x000000010739915c libTreePlayer.so`ROOT::Detail::TBranchProxy::Read(this=0x00006110000c9580) at TBranchProxy.h:163:42
    frame #10: 0x0000000107649ba8 libTreePlayer.so`(anonymous namespace)::TObjectArrayReader::At(this=0x0000603000169900, proxy=0x00006110000c9580, idx=1) at TTreeReaderArray.cxx:176:22
    frame #11: 0x000000010000c2e4 repro.out`ROOT::Internal::TTreeReaderArrayBase::UntypedAt(this=0x000000016fdfe740, idx=1) const at TTreeReaderArray.h:41:62
    frame #12: 0x000000010000c200 repro.out`TTreeReaderArray<double>::At(this=0x000000016fdfe740, idx=1) at TTreeReaderArray.h:205:54
    frame #13: 0x00000001000065e0 repro.out`TTreeReaderArray<double>::operator[](this=0x000000016fdfe740, idx=1) at TTreeReaderArray.h:207:44
    frame #14: 0x0000000100007b48 repro.out`simpleTest() at repro.cpp:123:26
    frame #15: 0x0000000100007e10 repro.out`main at repro.cpp:128:5
    frame #16: 0x000000018c718274 dyld`start + 2840
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants