public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954]
@ 2024-05-06  6:32 Nathaniel Shead
  2024-05-06 16:39 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Nathaniel Shead @ 2024-05-06  6:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

In some circumstances, unions can also have an __as_base type; we need
to make sure that IS_FAKE_BASE_TYPE correctly recognises this.

	PR c++/114954

gcc/cp/ChangeLog:

	* cp-tree.h (IS_FAKE_BASE_TYPE): Also apply to unions.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/pr114954.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/cp-tree.h                        |  2 +-
 gcc/testsuite/g++.dg/modules/pr114954.C | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/pr114954.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 933504b4821..fa24217eb2b 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2616,7 +2616,7 @@ struct GTY(()) lang_type {
 
 /* True iff NODE is the CLASSTYPE_AS_BASE version of some type.  */
 #define IS_FAKE_BASE_TYPE(NODE)					\
-  (TREE_CODE (NODE) == RECORD_TYPE				\
+  (RECORD_OR_UNION_TYPE_P (NODE)				\
    && TYPE_CONTEXT (NODE) && CLASS_TYPE_P (TYPE_CONTEXT (NODE))	\
    && CLASSTYPE_AS_BASE (TYPE_CONTEXT (NODE)) == (NODE))
 
diff --git a/gcc/testsuite/g++.dg/modules/pr114954.C b/gcc/testsuite/g++.dg/modules/pr114954.C
new file mode 100644
index 00000000000..a9787140808
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr114954.C
@@ -0,0 +1,14 @@
+// PR c++/114954
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi main }
+
+export module main;
+
+template <int N>
+union U {
+private:
+  char a[N + 1];
+  int b;
+};
+
+U<4> p;
-- 
2.43.2


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

* Re: [PATCH] c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954]
  2024-05-06  6:32 [PATCH] c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954] Nathaniel Shead
@ 2024-05-06 16:39 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-05-06 16:39 UTC (permalink / raw)
  To: Nathaniel Shead, gcc-patches

On 5/6/24 02:32, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
> 
> -- >8 --
> 
> In some circumstances, unions can also have an __as_base type;

Hmm, even though unions can't be bases I guess that is needed for 
something like

union U {
   int i;
private:
   char c[5];
};

struct A {
   [[no_unique_address]] U u;
   char d;
};

static_assert (sizeof (A) == sizeof (U));

The patch is OK.

> we need to make sure that IS_FAKE_BASE_TYPE correctly recognises this.
> 
> 	PR c++/114954
> 
> gcc/cp/ChangeLog:
> 
> 	* cp-tree.h (IS_FAKE_BASE_TYPE): Also apply to unions.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/modules/pr114954.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>   gcc/cp/cp-tree.h                        |  2 +-
>   gcc/testsuite/g++.dg/modules/pr114954.C | 14 ++++++++++++++
>   2 files changed, 15 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/modules/pr114954.C
> 
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 933504b4821..fa24217eb2b 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -2616,7 +2616,7 @@ struct GTY(()) lang_type {
>   
>   /* True iff NODE is the CLASSTYPE_AS_BASE version of some type.  */
>   #define IS_FAKE_BASE_TYPE(NODE)					\
> -  (TREE_CODE (NODE) == RECORD_TYPE				\
> +  (RECORD_OR_UNION_TYPE_P (NODE)				\
>      && TYPE_CONTEXT (NODE) && CLASS_TYPE_P (TYPE_CONTEXT (NODE))	\
>      && CLASSTYPE_AS_BASE (TYPE_CONTEXT (NODE)) == (NODE))
>   
> diff --git a/gcc/testsuite/g++.dg/modules/pr114954.C b/gcc/testsuite/g++.dg/modules/pr114954.C
> new file mode 100644
> index 00000000000..a9787140808
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/pr114954.C
> @@ -0,0 +1,14 @@
> +// PR c++/114954
> +// { dg-additional-options "-fmodules-ts" }
> +// { dg-module-cmi main }
> +
> +export module main;
> +
> +template <int N>
> +union U {
> +private:
> +  char a[N + 1];
> +  int b;
> +};
> +
> +U<4> p;


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

end of thread, other threads:[~2024-05-06 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06  6:32 [PATCH] c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954] Nathaniel Shead
2024-05-06 16:39 ` Jason Merrill

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