summaryrefslogtreecommitdiff
path: root/tests/diagnostics/uninitialized-out.slang
blob: d0d87449fbeaf7578c71f7ce7dfdf12feb76b7fe (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
//DIAGNOSTIC_TEST:SIMPLE:

float foo(out float3 v)
{
    // This should error as we haven't set v before we read from it
    float r = v.x + 1.0;
    // This should warn as we haven't set v before we return
    return r;
}

// This should warn as we return without x being initialized
float bar(out float x)
{
    return 0;
}

// This should also warn pointing at the implicit return
void baz(out float x) {}

void twoReturns(bool b, out float y)
{
    if(b)
    {
        // Should warn
        return;
    }
    y = 0;
    // Shouldn't warn
    return;
}

void twoOkReturns(bool b, out float y)
{
    if(b)
    {
        // Shouldn't warn
        unused(y);
        return;
    }
    y = 0;
    // Shouldn't warn
    return;
}

// TODO: This should warn that n is potentially uninitialized
int ok(bool b, out int n)
{
    if(b)
        n = 0;
    return n;
}

// TODO: This should warn that arr isn't fully initialized
void partial(out float arr[2])
{
    arr[0] = 1;
}