[llvm-dev] [IR] [CloneModule] Cloned module retains some pointers to original module's objects

Itay Bookstein via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 23 07:11:11 PST 2020


Hey all,

While refactoring code to use LLVMCloneModule instead of repeatedly
deserializing it from a buffer I began encountering bewildering bugs
and misbehaviors. We have some unusual (but apparently legal/mostly-
supported) use of BlockAddresses as initializers of GlobalVariables.
After investigating for a while we discovered that the aforementioned
BlockAddress constants used as initializers in the cloned module
contain pointers to the BasicBlocks of the old module rather than the
new one. As far as I can tell, in ValueMapper.cpp, Mapper::flush()
attempts to RAUW the temporary basic block it created when attempting
to map the BlockAddress constant which it encountered as the initializer
of a GlobalVariable, and it passes the OldBB when failing to find a target.
To my limited understanding, it sounds risky/incorrect to fall-back to the
OldBB there. The BasicBlocks themselves are of course properly
mapped/cloned into the new module in CloneFunction.cpp, in function
llvm::CloneFunctionInto, but a comment there seems to talk exactly
about it not being legal to clone a function that has an external BlockAddress
referencing it. I'm not 100% sure how to proceed yet, and haven't filed
a bug report, but it sounds like an actual bug/deficiency right?
Any advice?

Thanks,
~Itay


More information about the llvm-dev mailing list