public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-4758] c: Don't warn about converting NULL to different sso endian [PR104822]
Date: Thu, 19 Oct 2023 16:50:20 +0000 (GMT)	[thread overview]
Message-ID: <20231019165020.F26623858D1E@sourceware.org> (raw)

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.

Diff:
---
 gcc/c/c-typeck.cc             |  1 +
 gcc/testsuite/gcc.dg/sso-18.c | 16 ++++++++++++++++
 gcc/testsuite/gcc.dg/sso-19.c | 17 +++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 6e044b4afbc9..f39dc71d5932 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -7449,6 +7449,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)))
 	{
diff --git a/gcc/testsuite/gcc.dg/sso-18.c b/gcc/testsuite/gcc.dg/sso-18.c
new file mode 100644
index 000000000000..799a0c858f20
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sso-18.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* PR c/104822 */
+
+#include <stddef.h>
+
+struct Sb {
+  int i;
+} __attribute__((scalar_storage_order("big-endian")));
+struct Sl {
+  int i;
+} __attribute__((scalar_storage_order("little-endian")));
+
+/* Neither of these should warn about incompatible scalar storage order
+   as NULL pointers are compatiable with both endian. */
+struct Sb *pb = NULL; /* { dg-bogus "" } */
+struct Sl *pl = NULL; /* { dg-bogus "" } */
diff --git a/gcc/testsuite/gcc.dg/sso-19.c b/gcc/testsuite/gcc.dg/sso-19.c
new file mode 100644
index 000000000000..50f7b40c6086
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sso-19.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+/* PR c/104822 */
+
+#include <stddef.h>
+
+struct Sb {
+  int i;
+} __attribute__((scalar_storage_order("big-endian")));
+struct Sl {
+  int i;
+} __attribute__((scalar_storage_order("little-endian")));
+
+/* Neither of these should warn about incompatible scalar storage order
+   as NULL pointers are compatiable with both endian. */
+struct Sb *pb = nullptr; /* { dg-bogus "" } */
+struct Sl *pl = nullptr; /* { dg-bogus "" } */

                 reply	other threads:[~2023-10-19 16:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231019165020.F26623858D1E@sourceware.org \
    --to=pinskia@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).