summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/uninitialized-use-functions.slang
blob: 5a1c8ad8425dc3e78861ab7a5e2f1935254d6dcc (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//TEST:SIMPLE(filecheck=CHK): -target spirv -entry computeMain

// Both out and inout parameters
// should have this treated as writes
void out_test(int tmp, out int x)
{
    x = tmp;
}

// Permuting arguments to ensure that
// the correct argument is checked
void inout_test(inout int x, int tmp)
{
    x = tmp;
}

// __ref parameters should also be fine
void ref_test(__ref int x, int tmp)
{
    x = tmp;
}

void undefined_function_use()
{
    int x;
    int tmp = 1;

    //CHK-DAG: warning 41016: use of uninitialized variable 'x'
    out_test(x, tmp);
    
    //CHK-DAG: warning 41016: use of uninitialized variable 'x'
    inout_test(tmp, x);
}

void out_function_use()
{
    int x;
    int tmp = 1;

    // Acts as a write
    out_test(tmp, x);

    // Rest are fine now
    out_test(x, tmp);
    inout_test(tmp, x);
}

void inout_function_use()
{
    int x;
    int tmp = 1;

    // Acts as a write
    inout_test(x, tmp);

    // Rest are fine now
    out_test(x, tmp);
    inout_test(tmp, x);
}

void ref_function_use()
{
    int x;
    int tmp = 1;

    // Acts as a write
    ref_test(x, tmp);

    // Rest are fine now
    out_test(x, tmp);
    inout_test(tmp, x);
}

// Likewise for generic functions
static int ord_gen_result;

__generic<T>
void ordinary_generic(T x)
{
    ord_gen_result = __slang_noop_cast<int, T>(x);
}

__generic<T>
void unordinary_generic(out T x)
{
    x = __slang_noop_cast<T, int>(1);
}

void undefined_generic_use()
{
    int x;

    //CHK-DAG: warning 41016: use of uninitialized variable 'x'
    ordinary_generic(x);
}

void ok_generic_use()
{
    int x;
    unordinary_generic(x);
    ordinary_generic(x);
}

// Check proper handling of aliases passed
void f()
{
    int3 dim;

    // Should have no warnings
    out_test(1, dim.x);
}

//CHK-NOT: warning 41016

[Shader("compute")]
[NumThreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
}