Fix strict aliasing violations in gl3cCommonBugsTests
authorNeil Roberts <nroberts@igalia.com>
Wed, 15 Nov 2017 21:45:39 +0000 (22:45 +0100)
committerNeil Roberts <nroberts@igalia.com>
Thu, 16 Nov 2017 09:32:44 +0000 (10:32 +0100)
In two places in PerVertexValidationTest::getTestIterationProperties
it first stores a value in a pointer to an enum and then later tries
to update the enum via a reference casted to an int reference. I
believe this violates the strict aliasing rules and so is undefined
behaviour. At least with gcc and -O2 the compiler seems to take
advantage of this and effectively ignores the initial assignment of
SHADER_STAGE_VERTEX for the PERVERTEX_DECLARATION_MISMATCH_TC_TE_VS
iteration. The result is that used_shader_stages gets or’d with an
unitialised value. This was causing a valgrind error and depending on
what the original value happened to be it can make the test
erroneously fail.

Modules: OpenGL

VK-GL-CTS issue: 853

Affects:
KHR-GL*.CommonBugs.CommonBug_PerVertexValidation

Change-Id: I1094de5c2114c035e339cdb524808f45cbe55782

external/openglcts/modules/gl/gl3cCommonBugsTests.cpp

index 4b1a33b..6f3a5f9 100644 (file)
@@ -2233,21 +2233,23 @@ void PerVertexValidationTest::getTestIterationProperties(glu::ContextType contex
        case TEST_ITERATION_PERVERTEX_DECLARATION_MISMATCH_TC_TE_VS:
        {
                *out_min_context_type_ptr   = glu::ContextType(4, 1, glu::PROFILE_CORE);
-               *out_used_shader_stages_ptr = SHADER_STAGE_VERTEX;
+               int used_shader_stages = SHADER_STAGE_VERTEX;
 
                if (iteration == TEST_ITERATION_PERVERTEX_DECLARATION_MISMATCH_GS_TC_TE_VS ||
                        iteration == TEST_ITERATION_PERVERTEX_DECLARATION_MISMATCH_GS_VS)
                {
-                       (int&)* out_used_shader_stages_ptr |= SHADER_STAGE_GEOMETRY;
+                       used_shader_stages |= SHADER_STAGE_GEOMETRY;
                }
 
                if (iteration == TEST_ITERATION_PERVERTEX_DECLARATION_MISMATCH_GS_TC_TE_VS ||
                        iteration == TEST_ITERATION_PERVERTEX_DECLARATION_MISMATCH_TC_TE_VS)
                {
-                       (int&)* out_used_shader_stages_ptr |=
-                               (_shader_stage)(SHADER_STAGE_TESSELLATION_CONTROL | SHADER_STAGE_TESSELLATION_EVALUATION);
+                       used_shader_stages |=
+                               SHADER_STAGE_TESSELLATION_CONTROL | SHADER_STAGE_TESSELLATION_EVALUATION;
                }
 
+               *out_used_shader_stages_ptr = (_shader_stage) used_shader_stages;
+
                /* Shader bodies are predefined in this case. */
                *out_gs_body_ptr = "#version 410\n"
                                                   "\n"
@@ -2325,19 +2327,21 @@ void PerVertexValidationTest::getTestIterationProperties(glu::ContextType contex
        case TEST_ITERATION_PERVERTEX_BLOCK_UNDEFINED:
        {
                *out_min_context_type_ptr   = glu::ContextType(4, 1, glu::PROFILE_CORE);
-               *out_used_shader_stages_ptr = SHADER_STAGE_VERTEX;
+               int used_shader_stages = SHADER_STAGE_VERTEX;
 
                if (glu::contextSupports(context_type, glu::ApiType::core(3, 2)))
                {
-                       (int&)* out_used_shader_stages_ptr |= SHADER_STAGE_GEOMETRY;
+                       used_shader_stages |= SHADER_STAGE_GEOMETRY;
                }
 
                if (glu::contextSupports(context_type, glu::ApiType::core(4, 0)))
                {
-                       (int&)* out_used_shader_stages_ptr |=
+                       used_shader_stages |=
                                SHADER_STAGE_TESSELLATION_CONTROL | SHADER_STAGE_TESSELLATION_EVALUATION;
                }
 
+               *out_used_shader_stages_ptr = (_shader_stage) used_shader_stages;
+
                *out_gs_body_ptr = "#version 410\n"
                                                   "\n"
                                                   "layout (points)                   in;\n"