Hi Joseph,

Thanks for reviewing my patch.

On 20/05/2025 18:02, Joseph Myers wrote:
On Tue, 20 May 2025, Christopher Bazley wrote:

+       if (!cleared)
+         {
+           if (complete_p.padded_non_union
+               && warn_zero_init_padding_bits >= ZERO_INIT_PADDING_BITS_ALL)
+             {
+               warning (OPT_Wzero_init_padding_bits_,
+                            "Padding bits might not be initialized to zero; "
+                            "consider using %<-fzero-init-padding-bits=all%>");
+             }
+           else if (complete_p.padded_union
+                    && warn_zero_init_padding_bits
+                       >= ZERO_INIT_PADDING_BITS_UNIONS)
+             {
+               warning (OPT_Wzero_init_padding_bits_,
+                        "Padding bits might not be initialized to zero; "
+                        "consider using %<-fzero-init-padding-bits=unions%> "
+                        "or %<-fzero-init-padding-bits=all%>");
Diagnostics should start with a lowercase letter.

I'll change it to "padding might not be initialized to zero..." OK?

("padding" seems to be more common than "padding bits" in existing messages.)

Is there anything I need to do for initialization?

If there's a meaningful location available for the initialization, then
warning_at (passing an explicit location) is preferred to warning.

I originally intended to use warning_at, but I never found the right way of getting a source code location. It wasn't obvious to me what that location should be either, since whether or not padding bits are initialized may depend on more than one initializer (or the absence of an initializer).

Then, I found that the generated warnings seem adequate without using warning_at:

/work/gcc/gcc/testsuite/gcc.dg/gnu11-empty-init-warn-1.c:49:12: error: padding might not be initialized to zero; consider using ‘-fzero-init-padding-bits=unions’ or ‘-fzero-init-padding-bits=all’ [-Werror=zero-init-padding-bits=]    49 |   struct F t = { argc, {}, .b = {.a = 2} }; /* { dg-warning "padding might not be initialized to zero" } */
      |            ^

The opening brace is highlighted when diagnosing an issue within a compound literal:

/work/gcc/gcc/testsuite/gcc.dg/gnu11-empty-init-warn-1.c:55:16: error: padding might not be initialized to zero; consider using ‘-fzero-init-padding-bits=unions’ or ‘-fzero-init-padding-bits=all’ [-Werror=zero-init-padding-bits=]    55 |   aa((struct F){ argc, {}, .b = {.a = 2} }); /* { dg-warning "padding might not be initialized to zero" } */
      |                ^

Would you agree this is adequate? If anyone wants different source code locations to be highlighted then a future commit could change that.

--
Christopher Bazley
Staff Software Engineer, GNU Tools Team.
Arm Ltd, 110 Fulbourn Road, Cambridge, CB1 9NJ, UK.
http://www.arm.com/

Reply via email to