// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

shader
test_varying_out_of_bounds_index_float (output color Cout = color(0,0,0))
{
   // Test array referencing with varying index
    float rarray[3] = { 0.1, 0.2, 0.3 };
    float garray[3] = { 0.2, 0.4, 0.6 };
    
    
    // out of bounds, should segfault if accessed accidentally
    int varyingIndex = 2000000000;

    if (int(P[0]*256)%2 == 0) {
        varyingIndex = int(clamp(P[0]*3, 0, 2));
    
        rarray[varyingIndex] = 0.0;
        garray[varyingIndex] = 0.0;
    }
    // We access the varyingIndex outside the conditional to force its assignment
    // to be masked causing the unmasked lanes to remain at an out of bounds
    // value, which should cause a segfault if not masked correctly during
    // the array assignment operation
    Cout = color((rarray[0] + rarray[1] + rarray[2]),
                 (garray[0] + garray[1] + garray[2]),
                 float(varyingIndex));    
}
