[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:51 PDT 2026
================
@@ -14433,17 +14433,26 @@ the code generator, and allows some metadata to be associated with it.
##### Arguments:
-The first argument specifies the address of a stack object that contains
-the root pointer. The second pointer (which must be either a constant or
-a global value address) contains the meta-data to be associated with the
-root.
-
-##### Semantics:
-
-At runtime, a call to this intrinsic stores a null pointer into the
-"ptrloc" location. At compile-time, the code generator generates
-information to allow the runtime to find the pointer at GC safe points.
-The '`llvm.gcroot`' intrinsic may only be used in a function which
+The first argument specifies the address of a stack object holding the
+root, which must be a static `alloca`. LLVM attaches no meaning to the
+contents of that object: it is an opaque blob of arbitrary type which
+the runtime garbage collector may interpret in any way it likes. In
+particular it need not be, or contain, a pointer. The second pointer
+(which must be either a constant or a global value address) contains the
+meta-data to be associated with the root.
+
+##### Semantics:
+
+The frontend is responsible for initializing the "ptrloc" object before
+the first GC safe point is reached, since the collector may inspect it
+there. What it stores is up to the collector's conventions and need not
----------------
isuckatcs wrote:
Did you just write this with claude?
> The frontend is responsible for initializing the "ptrloc" object
In the previous phrasing LLVM guaranteed that it initializes it. I suggest keeping that phrasing, as there are examples where due to optimization the initialization gets lost, and the GC lowering pass inserts it again.
In that case, if the user initializes it to some non-zero value, it will be zeroed out regardless.
https://github.com/llvm/llvm-project/pull/222333
More information about the llvm-commits
mailing list