LLVMTargetMachineEmitToFile and custom data layouts

LLVMTargetMachineEmitToFile and LLVMTargetMachineEmitToMemoryBuffer will always override the module’s data layout with a default one of the target machine, which means setting a custom data layout with LLVMSetModuleDataLayout has no effect, and that layout gets lost afterwards. In my use case I am trying to replicate LLVM 18’s i128:128 behavior for x86 targets in previous LLVM versions.

Is this intended behavior? Will my LLVM IR work correctly nonetheless as long as it had i128:128 set while being generated? Or will this actually need a new C function?

The answer I got on Discord was:

It’s not going to crash, but it will obviously interpret things with the new data layout, which will likely lead to miscompiles