Re: subobject init override

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2024-06-05 at 11:06 +0530, Amol Surati via Gcc-help wrote:
> Does this warrant a bug with gcc?

There's already a bug report: https://gcc.gnu.org/PR63944.


> On Fri, 17 May 2024 at 20:32, Amol Surati <suratiamol@xxxxxxxxx>
> wrote:
> > 
> > Hello,
> > 
> > [1] says
> > 
> > "Although any non-initialized subobjects are initialized implicitly,
> > implicit
> > initialization of a subobject never overrides explicit
> > initialization of the
> > same subobject if it appeared earlier in the initializer list
> > (choose clang
> > to observe the correct output)".
> > 
> > There's a sample program attached on the website at [1] around the
> > statement, and the behaviour clearly differs between gcc and clang.
> > 
> > -----------
> > This difference is affecting Mesa builds with gcc, because Mesa
> > utilizes
> > such subobject-init-override patterns. One such instance is within
> > the
> > function blorp_params_get_clear_kernel_fs listed at [2].
> > 
> > The relevant parts were extracted and built into a small test
> > program,
> > available at [3] (for gcc) and [4] (for clang)
> > 
> > gcc prints: "" ''
> > clang prints: "blorp" 'b'
> > clang does spit out warnings about -Winitializer-overrides before
> > allowing the compilation to succeed.
> > 
> > According to the cppref website, Mesa's usage is correct, and it is
> > gcc
> > that's ignoring the fact that the subobject was previously
> > *explicitly*
> > initialized.
> > 
> > The C spec says:
> > "The initialization shall occur in initializer list order, each
> > initializer
> > provided for a particular subobject overriding any previously listed
> > initializer for the same subobject;170) all subobjects that are not
> > initialized explicitly are subject to default initialization."
> > 
> > Is there a way to force gcc to behave as clang does?
> > If not, could you please help determine who exactly is at fault here
> > and must receive a change/bug request, if needed?
> > 
> > Thank you,
> > Amol
> > -----------------------------
> > [1] https://en.cppreference.com/w/c/language/struct_initialization
> > [2]
> > https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/intel/blorp/blorp_clear.c?ref_type=heads
> > [3] https://godbolt.org/z/env53Wq9M
> > [4] https://godbolt.org/z/8TMfbb5Ef

-- 
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux