From 3f12964b24f8829a4548f634463492f02b7de913 Mon Sep 17 00:00:00 2001 From: jarcherNV Date: Mon, 4 Aug 2025 12:26:30 -0700 Subject: Add support for pointer literals in metal (#8040) Add support for kIROp_PtrLit types in metal and add a test for null pointer values, which is the only valid value. --- tests/metal/pointer-literals.slang | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/metal/pointer-literals.slang (limited to 'tests') diff --git a/tests/metal/pointer-literals.slang b/tests/metal/pointer-literals.slang new file mode 100644 index 000000000..327d488d2 --- /dev/null +++ b/tests/metal/pointer-literals.slang @@ -0,0 +1,30 @@ +//TEST:SIMPLE(filecheck=METAL): -target metal -stage compute -entry computeMain +//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage compute -entry computeMain + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +//METAL: {{\[\[}}kernel{{\]\]}} void computeMain +//METALLIB: define void @computeMain + +// Test that pointer literals are handled correctly in Metal. + +[numthreads(1,1,1)] +void computeMain() +{ + // Test pointer literals in some contexts that might generate kIROp_PtrLit. + + // Test 1: Basic pointer literal assignment + void* ptr1 = nullptr; + outputBuffer[0] = (ptr1 == nullptr) ? 1 : 0; + + // Test 2: Pointer literal in struct + struct TestStruct + { + void* ptr; + int value; + }; + + TestStruct test = { nullptr, 42 }; + outputBuffer[1] = (test.ptr == nullptr) ? 1 : 0; +} \ No newline at end of file -- cgit v1.2.3