[llvm] [IR][CodeGen] Specify llvm.gcroot contents are an opaque zero-initialized blob (PR #222333)

Jameson Nash via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 07:55:22 PDT 2026


================
@@ -86,3 +86,31 @@ entry:
 
   ret void
 }
+
+; The root is an opaque blob, so a root that is neither a pointer nor of
+; pointer size is zero-initialized in full.
+define void @fat_and_array_roots() gc "shadow-stack" {
+; CHECK-LABEL: define void @fat_and_array_roots() gc "shadow-stack" {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    %A = alloca { ptr, i1 }, align 8
+; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr align 8 %A, i8 0, i64 16, i1 false)
+; CHECK-NEXT:    %B = alloca [4 x ptr], align 8
+; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr align 8 %B, i8 0, i64 32, i1 false)
+; CHECK-NEXT:    %C = alloca ptr, i32 7, align 8
+; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr align 8 %C, i8 0, i64 56, i1 false)
+; CHECK-NEXT:    call void @llvm.gcroot(ptr %A, ptr null)
+; CHECK-NEXT:    call void @llvm.gcroot(ptr %B, ptr null)
+; CHECK-NEXT:    call void @llvm.gcroot(ptr %C, ptr null)
+; CHECK-NEXT:    ret void
+; CHECK-NEXT:  }
+entry:
+  %A = alloca { ptr, i1 }
+  %B = alloca [4 x ptr]
+  %C = alloca ptr, i32 7
+
+  call void @llvm.gcroot(ptr %A, ptr null)
+  call void @llvm.gcroot(ptr %B, ptr null)
+  call void @llvm.gcroot(ptr %C, ptr null)
----------------
vtjnash wrote:

Hypothetically speaking? A frontend could insert the metadata as the first argument in the root, and from that recover how far to jump to the next root. Or it could define that it ends with a sentinel pattern. Or they could be a fixed width which isn't a pointer size (e.g. packed 32 bit, or fat 128 bit pointers). I'm not here to tell front-ends /GCs what experiments they're allowed to run on their root designs.

https://github.com/llvm/llvm-project/pull/222333


More information about the llvm-commits mailing list