public inbox for
 help / color / mirror / Atom feed
* [PATCH] Update array address space in c_build_qualified_type
@ 2023-06-21  5:57 SenthilKumar.Selvaraj
  2023-06-21  8:15 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: SenthilKumar.Selvaraj @ 2023-06-21  5:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.guenther


  When builds an array type
  from its element type, it does not copy the address space of
  the element type to the array type itself. This is unlike, which explicitly does


  This causes the ICE described in

struct S {
  char y[2];

extern const __memx  struct S *s;

extern void bar(const __memx void*);

void foo(void) {

  build_component_ref calls c_build_qualified_type, passing in the
  array type and quals including the address space (ADDR_SPACE_MEMX
  in this case). Because of this missing address space copy, the
  returned array type remains in the generic address space.  Later
  down the line, expand_expr_addr_expr detects the mismatch in
  address space/mode and tries to convert, and that leads to the
  ICE described in the bug.

  This patch sets the address space of the array type to that of the
  element type.

  Regression tests for avr look ok. Ok for trunk?


	PR 86869


	* (c_build_qualified_type): Set


	* New test.

diff --git a/gcc/c/ b/gcc/c/
index 22e240a3c2a..d4ab1d1bd46 100644
--- a/gcc/c/
+++ b/gcc/c/
@@ -16284,6 +16284,7 @@ c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
 	  t = build_variant_type_copy (type);
 	  TREE_TYPE (t) = element_type;
+	  TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
           if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
               || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
diff --git a/gcc/testsuite/ b/gcc/testsuite/
new file mode 100644
index 00000000000..54cd984276e
--- /dev/null
+++ b/gcc/testsuite/
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+extern void bar(const __memx void* p);
+struct S {
+  char y[2];
+extern const __memx struct S *s;
+void foo(void) {
+  bar(&s->y);

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

end of thread, other threads:[~2023-06-22  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21  5:57 [PATCH] Update array address space in c_build_qualified_type SenthilKumar.Selvaraj
2023-06-21  8:15 ` Richard Biener
2023-06-21 18:37   ` Joseph Myers
2023-06-22  9:55     ` SenthilKumar.Selvaraj

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