summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/bitfield/msvc-sizeof.slang
blob: 9d4ccdcfcb1b308c2896891daed1eb09321b862d (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
31
32
33
34
35
36
37
38
39
40
41
42
43
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -output-using-type -compile-arg -msvc-style-bitfield-packing

// MSVC starts new backing fields when type sizes change
// CHECK:      4
// CHECK-NEXT: 12
// CHECK-NEXT: 8
// CHECK-NEXT: 16

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<uint> outputBuffer;

struct S {
    int foo : 8;
    int bar : 24;
};

// MSVC will use separate backing fields for different sized types
struct T {
    int64_t foo : 33;  // Uses int64_t backing
    int bar : 24;      // Uses separate int backing due to type size change
};

// This still takes two ints to store all the bits
struct P {
    int foo : 24;
    int bar : 24;
};

// MSVC will use separate backing fields due to type size difference
struct Q {
    int8_t foo : 1;    // Uses int8_t backing
    int64_t bar : 63;  // Uses separate int64_t backing
};

[numthreads(1, 1, 1)]
void computeMain()
{
    outputBuffer[0] = sizeof(S);
    outputBuffer[1] = sizeof(T);
    outputBuffer[2] = sizeof(P);
    outputBuffer[3] = sizeof(Q);
}