summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/uninitialized-globals.slang
blob: 5108d7fc5a20911cf5eba05dac2747bf41827104 (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
//TEST:SIMPLE(filecheck=CHK): -allow-glsl -target spirv -entry computeMain

// Using groupshared variables
groupshared float4 gsUninitialized;

float use_undefined_gs()
{
    //CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'gsUninitialized'
    return gsUninitialized.x;
}

// Using static variables
static const float cexprInitialized = 1.0f;
static float writtenNever;
static float writtenLater;

// OK
float use_initialized_static()
{
    return cexprInitialized;
}

// Should detect this and treat it as a store
void write_to_later()
{
    writtenLater = 1.0f;
}

float use_never_written()
{
    //CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'writtenNever'
    return writtenNever;
}

// OK because of prior store
float use_later_writte()
{
    return writtenLater;
}

// Varying inputs never warn
layout(location = 0) in vec4 data;

vec4 glsl_layout_in_ok()
{
    return data;
}

// Layout outputs should still be written to at some point
layout(location = 1) out vec4 x;

vec4 glsl_layout_out_undefined()
{
    //CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'x'
    return x;
}

layout(location = 2) out vec4 y;

void glsl_layout_out_store(vec4 data)
{
    // Written to here...
    y = data;
}

vec4 glsl_layout_out_ok()
{
    // ...so read here is treated as OK
    return y;
}

//CHK-NOT: warning 41017

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