[llvm-dev] SourceMgr lifespan

Russell Wallace via llvm-dev llvm-dev at lists.llvm.org
Sun Sep 27 23:07:21 PDT 2015


I've tried using SourceMgr in a parser to get the nice error reporting with
automatic line/column tracking, and it works well.

I'm thinking about extending that to try to get the nice error reporting in
subsequent type checking, and that leads to a question.

As I understand it, SourceMgr owns the memory buffers (be they allocated
chunks of memory, or memory mapped files) containing the source, the idea
being that when you finish parsing and return, the SourceMgr destructor
automatically frees the memory buffers, which makes sense. It doesn't seem
to have anything like a .clear function, presumably because the whole idea
is you are supposed to let the destructor automatically do it?

But that would seem to indicate that the memory buffers are not going to be
available once parsing is finished and you've moved on to things like type
checking; the SourceMgr object will be out of scope and destructed. What's
the intended way to deal with this? I suppose you could allocate SourceMgr
on the heap and manually destruct it once type checking is finished, but
that doesn't seem to be how the example code I've looked at does things?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150928/ea5e5a15/attachment.html>


More information about the llvm-dev mailing list