* subobject init override
@ 2024-05-17 15:02 Amol Surati
2024-06-05 5:36 ` Amol Surati
0 siblings, 1 reply; 3+ messages in thread
From: Amol Surati @ 2024-05-17 15:02 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: subobject init override
2024-05-17 15:02 subobject init override Amol Surati
@ 2024-06-05 5:36 ` Amol Surati
2024-06-05 6:01 ` Xi Ruoyao
0 siblings, 1 reply; 3+ messages in thread
From: Amol Surati @ 2024-06-05 5:36 UTC (permalink / raw)
To: gcc-help
Does this warrant a bug with gcc?
Thank you,
Amol
On Fri, 17 May 2024 at 20:32, Amol Surati <suratiamol@gmail.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: subobject init override
2024-06-05 5:36 ` Amol Surati
@ 2024-06-05 6:01 ` Xi Ruoyao
0 siblings, 0 replies; 3+ messages in thread
From: Xi Ruoyao @ 2024-06-05 6:01 UTC (permalink / raw)
To: Amol Surati, gcc-help
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@gmail.com>
> 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@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-05 6:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-17 15:02 subobject init override Amol Surati
2024-06-05 5:36 ` Amol Surati
2024-06-05 6:01 ` Xi Ruoyao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).