Will Sema break from replacing its CodeGen in the middle of TU ?

While compiling C++ code, I’m trying to make different function and template from the same TU go into different IR modules, in order to support sort of lazy compilation with the MCJIT.

I have tried to replace Sema CodeGen in the middle of TU. It sometimes worked but mostly crashed while running the code.

It’s clear that something is wrong but I am not sure if it’s because it breaks something in Sema-CodeGen interface assumptions or for other reason, possibly related to MCJIT dynamic linker.

Can I use Sema+CodeGen like that?

Yaron

Hard to say without trying. I don’t think Sema will break. It simply calls ASTConsumer methods implemented by CodeGen, which do all the work and don’t return anything back.

However, CodeGen will surely break without some cleverness on your part. It will assume that Sema referenced and created GlobalValues for decls encountered earlier in the TU.