Instantiating an LLVMContext might be uneasy task.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/AsmParser/Parser.cpp | ||
---|---|---|
36 | Instead of duplicating the call, maybe you can do something like std::optional<LLVMContext> OptContext; return LLParser(F.getBuffer(), SM, Err, M, Index, M ? M->getContext() : OptContext.emplace(), Slots) |
Can you reupload the patch with full context?
So this is recycling an existing, already used context? I keep running into bugs caused by doing that
The local change itself looks now good to me, but @arsenm may have general concerns with the approach here, so please address his comment first.
Done
Can you elaborate? What bugs do you see? I'm currently investigating a crash during deletion of modules and functions after parsing, but my case does not use that local LLVMContext. So I just saw this extra instantiation and proposed to get rid of it.
The deleted copy constructor LLVMContext(LLVMContext &) got its
parameter changed to const to allow the latest clang compiler to
instantiatiate template std::optional<LLVMContext>.
@jsilvanus , @arsenm, please take a look.
@jsilvanus, do you mind if I land the patch? I believe @arsenm just misunderstood the change. The given context is not recycled. The local context is recycled as it used to be. The only change is that the new local context is created only if it is really needed.
LGTM.
This should be a strict improvement over the existing state, as we avoid unnecessary creations of contexts in some cases.
Instead of duplicating the call, maybe you can do something like