]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Don't warn about converting NULL to different sso endian [PR104822]
authorAndrew Pinski <pinskia@gmail.com>
Thu, 19 Oct 2023 03:49:05 +0000 (20:49 -0700)
committerAndrew Pinski <pinskia@gmail.com>
Thu, 19 Oct 2023 16:49:13 +0000 (09:49 -0700)
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.

gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/sso-18.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/sso-19.c [new file with mode: 0644]

index 6e044b4afbc991eaa76036f9b303146161aca75d..f39dc71d59324dd9cb196cd3f05641514972e3d7 100644 (file)
@@ -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 (file)
index 0000000..799a0c8
--- /dev/null
@@ -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 (file)
index 0000000..50f7b40
--- /dev/null
@@ -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 "" } */