Repository navigation
Conversation
…by typing the fields that close the cycle as opaque pointers, and reported structures holding arrays of themselves as unsupported. Co-Authored-By: Claude <noreply@anthropic.com>
…ts and comparisons and of conversions between pointers and integers by computing them on the integer values of native integers. Co-Authored-By: Claude <noreply@anthropic.com>
… to a pointer instead of failing with an internal compiler error. Co-Authored-By: Claude <noreply@anthropic.com>
…offsets of pointers to structures of any size and joins of pointers with null, which were miscompiled or raised internal compiler errors. Co-Authored-By: Claude <noreply@anthropic.com>
…nter and long fields are padded to their alignment and for structures that point to their own types. Co-Authored-By: Claude <noreply@anthropic.com>
… casts of vectorized CPU kernels, and kept the views and indices of element addresses alive until the loads and stores through them. Co-Authored-By: Claude <noreply@anthropic.com>
m4rs-mt
force-pushed
the
frontend_pointer_fixes
branch
from
October 30, 2026 09:11
7031789 to
a766554
Compare
This was referenced Oct 31, 2026
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #1687. Structures that point to their own types compile, native integers and pointer/integer conversions
compute on integer values,
Unsafe.AsPointeryields element addresses, and pointer arithmetic subtracts offsets,addresses elements of any size and joins pointers with null.
A note on authorship
This PR was done with AI-assistant pair programming (Claude via Claude Code). The commits carry a
Co-Authored-By: Claudetrailer.What's in this PR
1. Structures pointing to themselves (
Src/ILGPUC/IR/TypeInformationManager.cs,Src/ILGPUC/IR/ModuleValues/Construction/ModuleBuilder.cs,Src/ILGPUC/Frontend/CodeGenerator/Fields.cs)other structures, is an opaque pointer field in the structure type. Loads from such fields convert their values
back to the pointer type, and stores convert them to the field type.
2. Native integers and pointer/integer conversions (
Src/ILGPUC/Frontend/CodeGenerator/{Convert,Arithmetic,Compare}.cs,Src/ILGPUC/Frontend/DisassemblerDriver.cs,Src/ILGPUC/IR/PureValues/Construction/{Cast,Compare}.cs)conv.uzero-extends unsignedintegers.
nint/nuintcompute on integer values. Signed comparisons andcomparisons with integers compare integer values. Address strides keep their element addressing.
compares integers cast to pointers as integers.
3.
Unsafe.AsPointer(Src/ILGPUC/Static/Intrinsics/CompilerServices.xml,Src/ILGPUC/Frontend/Intrinsic/CompilerServices.cs)Unsafe.AsPointer(ref x)converts the reference to a pointer to the same element.4. Pointer arithmetic and null pointers (
Src/ILGPUC/Frontend/CodeGenerator/Arithmetic.cs,Src/ILGPUC/IR/PureValues/Construction/Cast.cs,Src/ILGPUC/IR/Transformations/SSABuilder.cs)differs from the stride.
pointer type. Pointers compare with null pointers as pointers.
5. CPU kernels (
Src/ILGPUC/Backends/CPU/CPUMethodEmitter.cs,Src/ILGPUC/Backends/CPU/VectorBufferAllocator.cs)field. Ordinary padded structures, such as ones mixing ints and longs, previously read wrong values on the CPU, as
did structures holding a pointer and an int.
addresses are passed to helpers or used in pointer differences.
6. Tests (
Src/ILGPUC.Tests/)NonKernelTests/SelfReferentialPointerTests.cs: structures pointing to their own types, directly, through a structvalue or through another struct, generate source on all backends; their self-pointing fields are opaque pointers in
the IR type; structures holding arrays of themselves report ILGPU1200 at the local's location. On Metal and OpenCL
the kernels that store a local's address in a local struct (
ListKernel,SelfKernel,MutualKernel) report thelocated "does not support generic pointers" diagnostic.
ConvertExecutionTests.NativeInt_ProducesCorrectOutput(TestPrograms/ConvertInt/NativeInt.cs):nint/nuintlocals and helper parameters with arithmetic, shifts, comparisons with 0, signed and unsigned comparisons, negation,
complement and zero extension, at O0, O1 and O2.
ConvertExecutionTests.PointerInt_ProducesCorrectOutput(TestPrograms/ConvertInt/PointerInt.cs):(long)&x,(nint)&x,(int*)address,(int*)native, an address stored to memory and converted back to a pointer, andpointer differences, on CPU, Metal, CUDA, ROCm and OpenCL.
ArrayViewExecutionTests.AsPointer_ProducesCorrectOutput(TestPrograms/ArrayView/AsPointer.cs):Unsafe.AsPointerof a view element and of a local.
AddressSpaceExecutionTests.PointerArithmetic_ProducesCorrectOutput(TestPrograms/AddressSpace/PointerArithmetic.cs):constant and variable offsets added to and subtracted from int, long and 12-byte structure pointers, at O0, O1, O2
and from Debug IL.
AddressSpaceExecutionTests.PointerSelect_ProducesCorrectOutput(TestPrograms/AddressSpace/PointerSelect.cs): apointer joining an element address with null on CPU, Metal, CUDA, ROCm and OpenCL.
StructureExecutionTests.PointerFieldPadding_ProducesCorrectOutput(TestPrograms/Structure/PointerFieldPadding.cs):the second of two padded structures in a local struct — holding a pointer and an int, or ints and longs — read
through a pointer to the first one, in a helper and in the kernel, at O0, O1 and O2.
ArrayViewExecutionTests.ElementRefStore_ProducesCorrectOutput(TestPrograms/ArrayView/ElementRefStore.cs): areference to a view element stored through and passed to a helper after other elements were stored, at O0, O1 and
O2.
StructureExecutionTests.SelfReferentialPointer_ProducesCorrectOutput(TestPrograms/Structure/SelfReferentialPointer.cs):a linked list of locals, a node read by value and indexed, a struct whose only field points to itself, and two
structs pointing to each other, on the backends with a generic address space (CPU, CUDA, ROCm), at O0, O1, O2 and
from Debug IL.
Depends on
#1687 (based on its head; the base is retargeted once it merges).
Testing
nvcc, NVIDIA GB10TreatWarningsAsErrors🤖 Generated with Claude Code