Christian Schafmeister
2015-Jan-24 06:31 UTC
[LLVMdev] "Expected to drop a reference" assertion thrown
Hello, A few days ago I upgraded to the LLVM/clang ToT (on Jan 19th or so) and I just encountered this assertion. “Expected to drop a reference” which is defined in llvm/lib/IR/Metadata.cpp line 136. I create DebugLoc objects using DebugLog:get(unsigned line, unsigned Col, MDNode *Scope, MDNode *InlinedAt=nullptr) The DebugLoc objects are wrapped in one of my classes and when instances get destructed the assertion is thrown. Would anyone have an idea what I’m doing wrong that causes this? Best, Christian Schafmeister Professor Chemistry Department Temple University
Duncan P. N. Exon Smith
2015-Jan-26 01:55 UTC
[LLVMdev] "Expected to drop a reference" assertion thrown
> On 2015 Jan 23, at 22:31, Christian Schafmeister <chris.schaf at verizon.net> wrote: > > > Hello, > > A few days ago I upgraded to the LLVM/clang ToT (on Jan 19th or so) and I just encountered this assertion. > > “Expected to drop a reference” which is defined in llvm/lib/IR/Metadata.cpp line 136. > > > I create DebugLoc objects using DebugLog:get(unsigned line, unsigned Col, MDNode *Scope, MDNode *InlinedAt=nullptr) > > The DebugLoc objects are wrapped in one of my classes and when instances get destructed the assertion is thrown. > > Would anyone have an idea what I’m doing wrong that causes this?The first thing I'd try is recompiling with ASan support. All the cases I've seen of this assertion firing are use-after-frees. Likely your `LLVMContext` has been destroyed already by the time this `DebugLoc` is deleted. Since `LLVMContext` teardown assumes that there aren't any live tracking references to metadata, you need to `reset()` or destroy the `DebugLoc`s before destroying the context.
Christian Schafmeister
2015-Jan-26 18:56 UTC
[LLVMdev] "Expected to drop a reference" assertion thrown
Thank you - I’ll give ASan a try - it may alert/protect me from other problems that come up down the road. This is almost certainly a memory management problem on my end. I was managing the DebugLoc’s lifetime using my copying garbage collector. I implemented a work around where I don’t expose the DebugLoc to my garbage collector and the problem went away. On Jan 25, 2015, at 8:55 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:> >> On 2015 Jan 23, at 22:31, Christian Schafmeister <chris.schaf at verizon.net> wrote: >> >> >> Hello, >> >> A few days ago I upgraded to the LLVM/clang ToT (on Jan 19th or so) and I just encountered this assertion. >> >> “Expected to drop a reference” which is defined in llvm/lib/IR/Metadata.cpp line 136. >> >> >> I create DebugLoc objects using DebugLog:get(unsigned line, unsigned Col, MDNode *Scope, MDNode *InlinedAt=nullptr) >> >> The DebugLoc objects are wrapped in one of my classes and when instances get destructed the assertion is thrown. >> >> Would anyone have an idea what I’m doing wrong that causes this? > > The first thing I'd try is recompiling with ASan support. All the cases > I've seen of this assertion firing are use-after-frees. > > Likely your `LLVMContext` has been destroyed already by the time this > `DebugLoc` is deleted. Since `LLVMContext` teardown assumes that there > aren't any live tracking references to metadata, you need to `reset()` or > destroy the `DebugLoc`s before destroying the context.
Maybe Matching Threads
- [LLVMdev] Assertion: replaceAllUses of value with new value of different type! being thrown all of a sudden
- [LLVMdev] Assertion: replaceAllUses of value with new value of different type! being thrown all of a sudden
- [LLVMdev] Assertion: replaceAllUses of value with new value of different type! being thrown all of a sudden
- [LLVMdev] More DIFactory questions
- [LLVMdev] [RFC] Less memory and greater maintainability for debug info IR