This is an archive of the discontinued LLVM Phabricator instance.

[orc] Change LLJIT's dtor to a virtual dtor
ClosedPublic

Authored by lxsameer on Feb 5 2022, 3:01 PM.

Details

Summary

Since LLLazyJIT inherits from LLJIT, the following is valid:

    
class A {
  std::unique_ptr<LLJIT> jit;
};
    
auto lazyJit = createLLLazyJIT(..);
A example(lazyJit);

But whet jit gets destroyed only the dtor of LLJIT will be called and
it will cause memory leaks on the members of LLLazyJIT.

With a virtual dtor for LLJIT, LLLazyJIT dtor will be called first.

Diff Detail

Event Timeline

lxsameer requested review of this revision.Feb 5 2022, 3:01 PM
lxsameer created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2022, 3:01 PM
lxsameer updated this revision to Diff 406215.Feb 5 2022, 3:06 PM

here is an example of the memory leak:

=================================================================
==1915907==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 216 byte(s) in 1 object(s) allocated from:
    #0 0x7fb2d52da42d in operator new(unsigned long) /llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
    #1 0x7fb2d2c4cbd1 in llvm::orc::LLLazyJIT::LLLazyJIT(llvm::orc::LLLazyJITBuilderState&, llvm::Error&) (/build/src/libserene/libserene.so.0+0x1a00bd1)

Indirect leak of 176 byte(s) in 1 object(s) allocated from:
    #0 0x7fb2d52da42d in operator new(unsigned long) /llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
    #1 0x7fb2d2c414b4 in llvm::orc::createLocalLazyCallThroughManager(llvm::Triple const&, llvm::orc::ExecutionSession&, unsigned long) (/build/src/libserene/libserene.so.0+0x19f54b4)

Indirect leak of 152 byte(s) in 1 object(s) allocated from:
    #0 0x7fb2d52da42d in operator new(unsigned long) /llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
    #1 0x7fb2d2c32d93 in llvm::orc::LocalTrampolinePool<llvm::orc::OrcX86_64_SysV>::Create(llvm::unique_function<void (unsigned long, llvm::unique_function<void (unsigned long) const>) const>) IndirectionUtils.cpp

SUMMARY: AddressSanitizer: 544 byte(s) leaked in 3 allocation(s).
lhames accepted this revision.Feb 7 2022, 4:20 PM

Looks good to me.

This revision is now accepted and ready to land.Feb 7 2022, 4:20 PM
This revision was landed with ongoing or failed builds.Feb 9 2022, 3:23 PM
This revision was automatically updated to reflect the committed changes.