* [PATCH] c: [PR104822] Don't warn about converting NULL to different sso endian
@ 2023-10-19 15:37 Andrew Pinski
2023-10-19 15:44 ` Marek Polacek
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Pinski @ 2023-10-19 15:37 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
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/c/c-typeck.cc | 1 +
gcc/testsuite/gcc.dg/sso-18.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/sso-18.c
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 6e044b4afbc..f39dc71d593 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 00000000000..799a0c858f2
--- /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 "" } */
--
2.39.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c: [PR104822] Don't warn about converting NULL to different sso endian
2023-10-19 15:37 [PATCH] c: [PR104822] Don't warn about converting NULL to different sso endian Andrew Pinski
@ 2023-10-19 15:44 ` Marek Polacek
0 siblings, 0 replies; 2+ messages in thread
From: Marek Polacek @ 2023-10-19 15:44 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches
On Thu, Oct 19, 2023 at 08:37:31AM -0700, Andrew Pinski wrote:
> 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.
Looks good, but please put "[PR104822]" at the end of the subject line.
> 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/c/c-typeck.cc | 1 +
> gcc/testsuite/gcc.dg/sso-18.c | 16 ++++++++++++++++
> 2 files changed, 17 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/sso-18.c
>
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index 6e044b4afbc..f39dc71d593 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 00000000000..799a0c858f2
> --- /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 "" } */
Maybe test nullptr as well?
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-19 15:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 15:37 [PATCH] c: [PR104822] Don't warn about converting NULL to different sso endian Andrew Pinski
2023-10-19 15:44 ` Marek Polacek
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).