On Tue, Aug 18, 2015 at 5:36 PM, Ian Romanick <i...@freedesktop.org> wrote: > On 08/18/2015 10:08 AM, Connor Abbott wrote: >> On Tue, Aug 18, 2015 at 9:56 AM, Kenneth Graunke <kenn...@whitecape.org> >> wrote: >>> Hey, >>> >>> I was thinking about using an anonymous union. Specifically, something >>> like: >>> >>> struct shader { >>> ... >>> union { >>> struct geometry_shader_info gs; >>> struct tess_eval_shader_info tes; >>> ... >>> }; >>> }; >>> >>> Are those acceptable in Mesa? I don't think we've traditionally used >>> them, but I'm not sure why. Apparently they're part of C11, though not >>> part of C99. However, GCC allows them, presumably Clang, and it looks >>> like MSVC 2005 supports them in C: >>> >>> https://msdn.microsoft.com/en-us/library/y9zewe0d%28v=vs.80%29.aspx >>> >>> We might be able to use these to avoid some of our fun >>> thing->base.Base.base.program.Base.base shenanigans... >>> >>> --Ken >>> >>> _______________________________________________ >>> mesa-dev mailing list >>> mesa-dev@lists.freedesktop.org >>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev >>> >> >> Well, we already use anonymous unions in various places in NIR (for >> example, the definition of nir_dest and nir_src), so they should be ok >> for core Mesa. IIRC there was a problem with combining anonymous >> unions and C99-style initializers, but it doesn't sound like you'll be >> too worried about that. > > Hm... is that why I get thousands of uninitialized field warnings? Or > are NIR_SRC_INIT and NIR_DEST_INIT just missing some things?
That depends on how you look at it. You could say that they are missing things. However, the correct initialization for either a nir_src or a nir_dest is effectively a memset to 0. Since C (and C++) guarantee that missing fields in a structure initializer (or compound literal) are initialized to 0 as long as one of them is, we get what we want without having to have the entire struct layout full of zeros. Also, since there is a union or two in there, it makes everything easier. > ../../../../../src/glsl/nir/nir.h: In function 'nir_src > nir_src_for_ssa(nir_ssa_def*)': > ../../../../../src/glsl/nir/nir.h:552:41: warning: missing initializer > for member 'nir_src::use_link' [-Wmissing-field-initializers] > nir_src src = NIR_SRC_INIT; > ^ > ../../../../../src/glsl/nir/nir.h:552:41: warning: missing initializer > for member 'nir_src::<anonymous>' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h:552:41: warning: missing initializer > for member 'nir_src::is_ssa' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h: In function 'nir_src > nir_src_for_reg(nir_register*)': > ../../../../../src/glsl/nir/nir.h:563:41: warning: missing initializer > for member 'nir_src::use_link' [-Wmissing-field-initializers] > nir_src src = NIR_SRC_INIT; > ^ > ../../../../../src/glsl/nir/nir.h:563:41: warning: missing initializer > for member 'nir_src::<anonymous>' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h:563:41: warning: missing initializer > for member 'nir_src::is_ssa' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h: In function 'nir_dest > nir_dest_for_reg(nir_register*)': > ../../../../../src/glsl/nir/nir.h:576:48: warning: missing initializer > for member 'nir_reg_dest::def_link' [-Wmissing-field-initializers] > nir_dest dest = NIR_DEST_INIT; > ^ > ../../../../../src/glsl/nir/nir.h:576:48: warning: missing initializer > for member 'nir_reg_dest::reg' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h:576:48: warning: missing initializer > for member 'nir_reg_dest::indirect' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h:576:48: warning: missing initializer > for member 'nir_reg_dest::base_offset' [-Wmissing-field-initializers] > ../../../../../src/glsl/nir/nir.h:576:48: warning: missing initializer > for member 'nir_dest::is_ssa' [-Wmissing-field-initializers] > >> _______________________________________________ >> mesa-dev mailing list >> mesa-dev@lists.freedesktop.org >> http://lists.freedesktop.org/mailman/listinfo/mesa-dev >> > > _______________________________________________ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/mesa-dev _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev