[Mesa-dev] [PATCH] st/nir: fix illegal designated initializer in st_glsl_to_nir.cpp

Brian Paul brianp at vmware.com
Thu Sep 12 13:00:12 UTC 2019


On 09/11/2019 03:06 PM, Ian Romanick wrote:
> On 9/10/19 10:53 PM, Brian Paul wrote:
>> IIRC, designated initializers are not legal C++.
>> Fixes the MSVC build.
>>
>> Fixes: 83fd1e58 ("glsl/nir: Add and use a gl_nir_link() function")
>> ---
>>   src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
>> index 280a778..d6a0264 100644
>> --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
>> +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
>> @@ -688,7 +688,7 @@ st_link_nir(struct gl_context *ctx,
>>       */
>>      if (shader_program->data->spirv) {
>>         static const gl_nir_linker_options opts = {
>> -         .fill_parameters = true,
>> +         true /*fill_parameters */
> 
> Could we get a comment in the definition of gl_nir_linker_options to
> remind people to either add options only to the end or double check all
> of the places that initialize the structures?  If someone adds 'bool
> do_foo_instead_of_bar' option at the beginning of that struct, it will
> cause problems.
> 
>>         };
>>         if (!gl_nir_link(ctx, shader_program, &opts))
>>            return GL_FALSE;
>>
> 

How about something simple like this instead:


diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp 
b/src/mesa/state_tracker
index d6a0264..4f5acfd 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -687,9 +687,14 @@ st_link_nir(struct gl_context *ctx,
      * st_nir_preprocess.
      */
     if (shader_program->data->spirv) {
-      static const gl_nir_linker_options opts = {
-         true /*fill_parameters */
-      };
+      /* Note: this object could be static const but designated
+       * initializers are not part of the C++ standard (allowed by GCC
+       * but not MSVC.)
+       */
+      gl_nir_linker_options opts = { 0 };
+
+      opts.fill_parameters = true;
+
        if (!gl_nir_link(ctx, shader_program, &opts))
           return GL_FALSE;


-Brian


More information about the mesa-dev mailing list