[llvm] [IR][CodeGen] Specify llvm.gcroot contents are an opaque zero-initialized blob (PR #222333)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 21:54:50 PDT 2026
================
@@ -166,19 +169,35 @@ static bool InsertRootInitializers(Function &F, ArrayRef<AllocaInst *> Roots) {
// Search for initializers in the initial BB.
SmallPtrSet<AllocaInst *, 16> InitedRoots;
- for (; !CouldBecomeSafePoint(&*IP); ++IP)
+ for (; !CouldBecomeSafePoint(&*IP); ++IP) {
+ Value *Dest = nullptr;
if (StoreInst *SI = dyn_cast<StoreInst>(IP))
- if (AllocaInst *AI =
- dyn_cast<AllocaInst>(SI->getOperand(1)->stripPointerCasts()))
+ Dest = SI->getOperand(1);
+ else if (MemSetInst *MSI = dyn_cast<MemSetInst>(IP))
+ Dest = MSI->getDest();
+ if (Dest)
+ if (AllocaInst *AI = dyn_cast<AllocaInst>(Dest->stripPointerCasts()))
InitedRoots.insert(AI);
+ }
- // Add root initializers.
+ // Add root initializers. The contents of a root are an opaque blob which
+ // only the collector understands, so all we can do is fill it with zeros;
+ // note that this is a zero bit pattern rather than a null value of the
+ // allocated type, which need not be the same thing.
+ const DataLayout &DL = F.getDataLayout();
bool MadeChange = false;
for (AllocaInst *Root : Roots)
if (!InitedRoots.count(Root)) {
- new StoreInst(Constant::getNullValue(Root->getAllocatedType()), Root,
- std::next(Root->getIterator()));
+ std::optional<TypeSize> RootSize = Root->getAllocationSize(DL);
+ if (!RootSize)
+ reportFatalUsageError(
+ "Intrinsic::gcroot requires a fixed size stack object");
----------------
isuckatcs wrote:
Doesn't the current implementation allow this? Why couldn't, for example, a VLA be marked as a root with the appropriate metadata? I think we should still allow any kind of allocas.
https://github.com/llvm/llvm-project/pull/222333
More information about the llvm-commits
mailing list