summaryrefslogtreecommitdiff
path: root/tests/metal/pointer-literals.slang
blob: 327d488d2905c50d12681035857ee6f228ff843e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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<uint> 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;
}