public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless
@ 2022-03-07 15:05 redi at gcc dot gnu.org
  2022-03-24 10:47 ` [Bug c/104822] " ebotcazou at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-07 15:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

            Bug ID: 104822
           Summary: -Wscalar-storage-order warning for initialization from
                    NULL seems useless
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <stddef.h>

struct S {
  int i;
} __attribute__((scalar_storage_order("big-endian")));

struct S *p = NULL;


This warns on x86:



sso.c:7:15: warning: initialization of ‘struct S *’ from pointer type ‘void *’
with incompatible scalar storage order [-Wscalar-storage-order]
    7 | struct S *p = NULL;
      |               ^~~~


This doesn't seem useful. A null pointer cannot be derferenced, so there is no
chance of undefined behaviour caused by type punning struct T { int i; } as
struct S or vice versa.

Could the warning be suppressed static init of a pointer using NULL?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
@ 2022-03-24 10:47 ` ebotcazou at gcc dot gnu.org
  2022-12-07  4:24 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2022-03-24 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2022-03-24
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Indeed, it looks like the warning could be less stupid here.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
  2022-03-24 10:47 ` [Bug c/104822] " ebotcazou at gcc dot gnu.org
@ 2022-12-07  4:24 ` pinskia at gcc dot gnu.org
  2022-12-07  4:25 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07  4:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine, I think this patch will fix the issue:
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index f1a1752782a..43b9793e339 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -7480,6 +7480,7 @@ convert_for_assignment (location_t location, location_t
expr_loc, tree type,

       /* See if the pointers point to incompatible scalar storage orders.  */
       if (warn_scalar_storage_order
+         && !null_pointer_constant_p (rhs)
          && (AGGREGATE_TYPE_P (ttl) && TYPE_REVERSE_STORAGE_ORDER (ttl))
             != (AGGREGATE_TYPE_P (ttr) && TYPE_REVERSE_STORAGE_ORDER (ttr)))
        {

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
  2022-03-24 10:47 ` [Bug c/104822] " ebotcazou at gcc dot gnu.org
  2022-12-07  4:24 ` pinskia at gcc dot gnu.org
@ 2022-12-07  4:25 ` pinskia at gcc dot gnu.org
  2023-10-19  3:53 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07  4:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Mine, I think this patch will fix the issue:
Which is similar to the check above dealing with named address spaces.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-12-07  4:25 ` pinskia at gcc dot gnu.org
@ 2023-10-19  3:53 ` pinskia at gcc dot gnu.org
  2023-10-19 15:38 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-19  3:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 56147
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56147&action=edit
Patch which I am testing

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-10-19  3:53 ` pinskia at gcc dot gnu.org
@ 2023-10-19 15:38 ` pinskia at gcc dot gnu.org
  2023-10-19 16:50 ` cvs-commit at gcc dot gnu.org
  2023-10-19 16:52 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-19 15:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2023-October
                   |                            |/633609.html

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633609.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-10-19 15:38 ` pinskia at gcc dot gnu.org
@ 2023-10-19 16:50 ` cvs-commit at gcc dot gnu.org
  2023-10-19 16:52 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-19 16:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:9f33e4c50ee92a2053f52e5eb8f205afa54d4cb0

commit r14-4758-g9f33e4c50ee92a2053f52e5eb8f205afa54d4cb0
Author: Andrew Pinski <pinskia@gmail.com>
Date:   Wed Oct 18 20:49:05 2023 -0700

    c: Don't warn about converting NULL to different sso endian [PR104822]

    In a similar way we don't warn about NULL pointer constant conversion to
    a different named address we should not warn to a different sso endian
    either.
    This adds the simple check.

    Bootstrapped and tested on x86_64-linux-gnu with no regressions.

            PR c/104822

    gcc/c/ChangeLog:

            * c-typeck.cc (convert_for_assignment): Check for null pointer
            before warning about an incompatible scalar storage order.

    gcc/testsuite/ChangeLog:

            * gcc.dg/sso-18.c: New test.
            * gcc.dg/sso-19.c: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/104822] -Wscalar-storage-order warning for initialization from NULL seems useless
  2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-10-19 16:50 ` cvs-commit at gcc dot gnu.org
@ 2023-10-19 16:52 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-19 16:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104822

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-19 16:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 15:05 [Bug c/104822] New: -Wscalar-storage-order warning for initialization from NULL seems useless redi at gcc dot gnu.org
2022-03-24 10:47 ` [Bug c/104822] " ebotcazou at gcc dot gnu.org
2022-12-07  4:24 ` pinskia at gcc dot gnu.org
2022-12-07  4:25 ` pinskia at gcc dot gnu.org
2023-10-19  3:53 ` pinskia at gcc dot gnu.org
2023-10-19 15:38 ` pinskia at gcc dot gnu.org
2023-10-19 16:50 ` cvs-commit at gcc dot gnu.org
2023-10-19 16:52 ` pinskia at gcc dot gnu.org

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).