[gcc r14-11665] d: Fix forward referenced enums missing type names in debug info [PR118309]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:aec3b99d3dee8a35adabb23c7835dfbd41e45520

commit r14-11665-gaec3b99d3dee8a35adabb23c7835dfbd41e45520
Author: Iain Buclaw 
Date:   Wed Apr 9 20:02:02 2025 +0200

d: Fix forward referenced enums missing type names in debug info [PR118309]

Calling `rest_of_type_compilation' as the D types were built meant that
debug info was being emitted before all forward references were
resolved, resulting in DW_AT_name's to be missing.

Instead, defer outputting type debug information until all modules have
been parsed and generated in `d_finish_compilation'.

PR d/118309

gcc/d/ChangeLog:

* modules.cc: Include debug.h
(d_finish_compilation): Call debug_hooks->type_decl on all 
TYPE_DECLs.
* types.cc: Remove toplev.h include.
(finish_aggregate_type): Don't call rest_of_type_compilation or
rest_of_decl_compilation on type.
(TypeVisitor::visit (TypeEnum *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/dwarf2/pr118309.d: New test.

(cherry picked from commit cee353c2653d274768a67677c8ea37fd23422b3c)

Diff:
---
 gcc/d/modules.cc |  9 +++
 gcc/d/types.cc   | 15 ++--
 gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d | 36 
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index b111ee90cea0..17d91d2ead9c 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "cgraph.h"
 #include "stor-layout.h"
+#include "debug.h"
 #include "toplev.h"
 #include "target.h"
 #include "common/common-target.h"
@@ -927,6 +928,14 @@ d_finish_compilation (tree *vec, int len)
   /* Complete all generated thunks.  */
   symtab->process_same_body_aliases ();
 
+  /* Output debug information for all type declarations in this unit.  */
+  for (int i = 0; i < len; i++)
+{
+  tree decl = vec[i];
+  if (TREE_CODE (decl) == TYPE_DECL)
+   debug_hooks->type_decl (decl, false);
+}
+
   /* Process all file scopes in this compilation, and the external_scope,
  through wrapup_global_declarations.  */
   for (int i = 0; i < len; i++)
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 6b045bde0a44..d1340bcd6aea 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "tm.h"
 #include "function.h"
-#include "toplev.h"
 #include "target.h"
 #include "stringpool.h"
 #include "stor-layout.h"
@@ -709,13 +708,8 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
 
-  /* Finish debugging output for this type.  */
-  rest_of_type_compilation (type, TYPE_FILE_SCOPE_P (type));
+  /* Complete any other forward-referenced fields of this aggregate type.  */
   finish_incomplete_fields (type);
-
-  /* Finish processing of TYPE_DECL.  */
-  rest_of_decl_compilation (TYPE_NAME (type),
-   DECL_FILE_SCOPE_P (TYPE_NAME (type)), 0);
 }
 
 /* Returns true if the class or struct type TYPE has already been layed out by
@@ -1185,13 +1179,8 @@ public:
 
layout_type (t->ctype);
 
-   /* Finish debugging output for this type.  */
-   rest_of_type_compilation (t->ctype, TYPE_FILE_SCOPE_P (t->ctype));
+   /* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
-
-   /* Finish processing of TYPE_DECL.  */
-   rest_of_decl_compilation (TYPE_NAME (t->ctype),
- DECL_FILE_SCOPE_P (TYPE_NAME (t->ctype)), 0);
   }
   }
 
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d 
b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
new file mode 100644
index ..50e42164eef1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-fno-druntime -gdwarf-4 -dA -fno-merge-debug-strings" }
+// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 1 
} }
+// { dg-final { scan-assembler-times " DW_AT_enum_class" 1 } }
+// { dg-final { scan-assembler-times "\"E..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"E1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C2..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C3..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C4..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"S1..\"\[^\n\]*DW_AT_name" 1 } }
+
+module expression;
+extern (C++):
+class C1
+{
+bool bfn() { return true; }
+}
+class C2 : C1
+{
+C4 cfn() { return null; }
+}

[gcc r14-11667] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:88b3c896602036b61005501981b6f4a4deca59b0

commit r14-11667-g88b3c896602036b61005501981b6f4a4deca59b0
Author: Iain Buclaw 
Date:   Wed Apr 16 01:28:53 2025 +0200

d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

Forward referenced enum types were never fixed up after the main
ENUMERAL_TYPE was finished.  All flags set are now propagated to all
variants after its mode, size, and alignment has been calculated.

PR d/119826

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeEnum *)): Propagate flags of 
main
enum types to all forward-referenced variants.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/pr119826b.d: New test.
* gdc.dg/debug/pr119826.d: New test.

(cherry picked from commit c5ffab99a5a962aa955310e74ca0a4be5c1acf30)

Diff:
---
 gcc/d/types.cc | 20 
 gcc/testsuite/gdc.dg/debug/imports/pr119826b.d | 14 ++
 gcc/testsuite/gdc.dg/debug/pr119826.d  |  8 
 3 files changed, 42 insertions(+)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index d1340bcd6aea..e9257c9c3776 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1179,6 +1179,26 @@ public:
 
layout_type (t->ctype);
 
+   /* Fix up all forward-referenced variants of this enum type.  */
+   for (tree v = TYPE_MAIN_VARIANT (t->ctype); v;
+v = TYPE_NEXT_VARIANT (v))
+ {
+   if (v == t->ctype)
+ continue;
+
+   TYPE_VALUES (v) = TYPE_VALUES (t->ctype);
+   TYPE_LANG_SPECIFIC (v) = TYPE_LANG_SPECIFIC (t->ctype);
+   TYPE_MIN_VALUE (v) = TYPE_MIN_VALUE (t->ctype);
+   TYPE_MAX_VALUE (v) = TYPE_MAX_VALUE (t->ctype);
+   TYPE_UNSIGNED (v) = TYPE_UNSIGNED (t->ctype);
+   TYPE_SIZE (v) = TYPE_SIZE (t->ctype);
+   TYPE_SIZE_UNIT (v) = TYPE_SIZE_UNIT (t->ctype);
+   SET_TYPE_MODE (v, TYPE_MODE (t->ctype));
+   TYPE_PRECISION (v) = TYPE_PRECISION (t->ctype);
+   SET_TYPE_ALIGN (v, TYPE_ALIGN (t->ctype));
+   TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t->ctype);
+ }
+
/* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
   }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d 
b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
new file mode 100644
index ..3c5a6acbb877
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
@@ -0,0 +1,14 @@
+module imports.pr119826b;
+
+import pr119826 : t119826;
+
+class C119826
+{
+enum E119826 { Evalue }
+const E119826 em = void;
+}
+
+void f119826(C119826 c)
+{
+t119826(c.em);
+}
diff --git a/gcc/testsuite/gdc.dg/debug/pr119826.d 
b/gcc/testsuite/gdc.dg/debug/pr119826.d
new file mode 100644
index ..2fb98c7ba9df
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119826.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr119826b.d" }
+module pr119826;
+
+int t119826(A)(A args)
+{
+assert(false);
+}


[gcc r14-11666] d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 [PR119817]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:d1b7ee4879aca90c9828b6b9f4937ed15513adfa

commit r14-11666-gd1b7ee4879aca90c9828b6b9f4937ed15513adfa
Author: Iain Buclaw 
Date:   Tue Apr 15 14:49:34 2025 +0200

d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 
[PR119817]

The ImportVisitor method for handling the importing of overload sets was
pushing NULL_TREE to the array of import decls, which in turn got passed
to `debug_hooks->imported_module_or_decl', triggering the observed
internal compiler error.

NULL_TREE is returned from `build_import_decl' when the symbol was
ignored for being non-trivial to represent in debug, for example,
template or tuple declarations.  So similarly "skip" adding the symbol
when this is the case for overload sets too.

PR d/119817

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Don't push
NULL_TREE to vector of import symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/m119817/a.d: New test.
* gdc.dg/debug/imports/m119817/b.d: New test.
* gdc.dg/debug/imports/m119817/package.d: New test.
* gdc.dg/debug/pr119817.d: New test.

(cherry picked from commit f5ed7d19c965de9ccb158d77e929b17459bf65b5)

Diff:
---
 gcc/d/imports.cc | 6 +-
 gcc/testsuite/gdc.dg/debug/imports/m119817/a.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/b.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/package.d | 4 
 gcc/testsuite/gdc.dg/debug/pr119817.d| 4 
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 074d9e65333e..00b09c8c87f8 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -182,7 +182,11 @@ public:
 vec_alloc (tset, d->a.length);
 
 for (size_t i = 0; i < d->a.length; i++)
-  vec_safe_push (tset, build_import_decl (d->a[i]));
+  {
+   tree overload = build_import_decl (d->a[i]);
+   if (overload != NULL_TREE)
+ vec_safe_push (tset, overload);
+  }
 
 this->result_ = build_tree_list_vec (tset);
 tset->truncate (0);
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
new file mode 100644
index ..a13747240c43
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
@@ -0,0 +1,2 @@
+module imports.m119817.a;
+void f119817()() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
new file mode 100644
index ..aef0e373ca6e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
@@ -0,0 +1,2 @@
+module imports.m119817.b;
+void f119817() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
new file mode 100644
index ..188827e669f5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
@@ -0,0 +1,4 @@
+module imports.m119817;
+public import
+imports.m119817.a,
+imports.m119817.b;
diff --git a/gcc/testsuite/gdc.dg/debug/pr119817.d 
b/gcc/testsuite/gdc.dg/debug/pr119817.d
new file mode 100644
index ..91e2be0eaa67
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119817.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/m119817/package.d imports/m119817/a.d 
imports/m119817/b.d" }
+module pr119817;
+import imports.m119817 : f119817;


[gcc r13-9553] d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 [PR119817]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:3c91f94bbb09c5380c3cc07c4c8fabab332eb962

commit r13-9553-g3c91f94bbb09c5380c3cc07c4c8fabab332eb962
Author: Iain Buclaw 
Date:   Tue Apr 15 14:49:34 2025 +0200

d: Fix ICE in dwarf2out_imported_module_or_decl, at dwarf2out.cc:27676 
[PR119817]

The ImportVisitor method for handling the importing of overload sets was
pushing NULL_TREE to the array of import decls, which in turn got passed
to `debug_hooks->imported_module_or_decl', triggering the observed
internal compiler error.

NULL_TREE is returned from `build_import_decl' when the symbol was
ignored for being non-trivial to represent in debug, for example,
template or tuple declarations.  So similarly "skip" adding the symbol
when this is the case for overload sets too.

PR d/119817

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (OverloadSet *)): Don't push
NULL_TREE to vector of import symbols.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/m119817/a.d: New test.
* gdc.dg/debug/imports/m119817/b.d: New test.
* gdc.dg/debug/imports/m119817/package.d: New test.
* gdc.dg/debug/pr119817.d: New test.

(cherry picked from commit f5ed7d19c965de9ccb158d77e929b17459bf65b5)

Diff:
---
 gcc/d/imports.cc | 6 +-
 gcc/testsuite/gdc.dg/debug/imports/m119817/a.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/b.d   | 2 ++
 gcc/testsuite/gdc.dg/debug/imports/m119817/package.d | 4 
 gcc/testsuite/gdc.dg/debug/pr119817.d| 4 
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 3172b799cb04..6133672638a6 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -182,7 +182,11 @@ public:
 vec_alloc (tset, d->a.length);
 
 for (size_t i = 0; i < d->a.length; i++)
-  vec_safe_push (tset, build_import_decl (d->a[i]));
+  {
+   tree overload = build_import_decl (d->a[i]);
+   if (overload != NULL_TREE)
+ vec_safe_push (tset, overload);
+  }
 
 this->result_ = build_tree_list_vec (tset);
 tset->truncate (0);
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
new file mode 100644
index ..a13747240c43
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/a.d
@@ -0,0 +1,2 @@
+module imports.m119817.a;
+void f119817()() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
new file mode 100644
index ..aef0e373ca6e
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/b.d
@@ -0,0 +1,2 @@
+module imports.m119817.b;
+void f119817() { }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d 
b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
new file mode 100644
index ..188827e669f5
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/m119817/package.d
@@ -0,0 +1,4 @@
+module imports.m119817;
+public import
+imports.m119817.a,
+imports.m119817.b;
diff --git a/gcc/testsuite/gdc.dg/debug/pr119817.d 
b/gcc/testsuite/gdc.dg/debug/pr119817.d
new file mode 100644
index ..91e2be0eaa67
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119817.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/m119817/package.d imports/m119817/a.d 
imports/m119817/b.d" }
+module pr119817;
+import imports.m119817 : f119817;


[gcc r13-9554] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:9f12448fcbc25c0459b477cb6c1cef7012849346

commit r13-9554-g9f12448fcbc25c0459b477cb6c1cef7012849346
Author: Iain Buclaw 
Date:   Wed Apr 16 01:28:53 2025 +0200

d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

Forward referenced enum types were never fixed up after the main
ENUMERAL_TYPE was finished.  All flags set are now propagated to all
variants after its mode, size, and alignment has been calculated.

PR d/119826

gcc/d/ChangeLog:

* types.cc (TypeVisitor::visit (TypeEnum *)): Propagate flags of 
main
enum types to all forward-referenced variants.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/imports/pr119826b.d: New test.
* gdc.dg/debug/pr119826.d: New test.

(cherry picked from commit c5ffab99a5a962aa955310e74ca0a4be5c1acf30)

Diff:
---
 gcc/d/types.cc | 20 
 gcc/testsuite/gdc.dg/debug/imports/pr119826b.d | 14 ++
 gcc/testsuite/gdc.dg/debug/pr119826.d  |  8 
 3 files changed, 42 insertions(+)

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 954686f2317f..9088cf4b8431 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1179,6 +1179,26 @@ public:
 
layout_type (t->ctype);
 
+   /* Fix up all forward-referenced variants of this enum type.  */
+   for (tree v = TYPE_MAIN_VARIANT (t->ctype); v;
+v = TYPE_NEXT_VARIANT (v))
+ {
+   if (v == t->ctype)
+ continue;
+
+   TYPE_VALUES (v) = TYPE_VALUES (t->ctype);
+   TYPE_LANG_SPECIFIC (v) = TYPE_LANG_SPECIFIC (t->ctype);
+   TYPE_MIN_VALUE (v) = TYPE_MIN_VALUE (t->ctype);
+   TYPE_MAX_VALUE (v) = TYPE_MAX_VALUE (t->ctype);
+   TYPE_UNSIGNED (v) = TYPE_UNSIGNED (t->ctype);
+   TYPE_SIZE (v) = TYPE_SIZE (t->ctype);
+   TYPE_SIZE_UNIT (v) = TYPE_SIZE_UNIT (t->ctype);
+   SET_TYPE_MODE (v, TYPE_MODE (t->ctype));
+   TYPE_PRECISION (v) = TYPE_PRECISION (t->ctype);
+   SET_TYPE_ALIGN (v, TYPE_ALIGN (t->ctype));
+   TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t->ctype);
+ }
+
/* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
   }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d 
b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
new file mode 100644
index ..3c5a6acbb877
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
@@ -0,0 +1,14 @@
+module imports.pr119826b;
+
+import pr119826 : t119826;
+
+class C119826
+{
+enum E119826 { Evalue }
+const E119826 em = void;
+}
+
+void f119826(C119826 c)
+{
+t119826(c.em);
+}
diff --git a/gcc/testsuite/gdc.dg/debug/pr119826.d 
b/gcc/testsuite/gdc.dg/debug/pr119826.d
new file mode 100644
index ..2fb98c7ba9df
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119826.d
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-additional-sources "imports/pr119826b.d" }
+module pr119826;
+
+int t119826(A)(A args)
+{
+assert(false);
+}


[gcc r13-9552] d: Fix forward referenced enums missing type names in debug info [PR118309]

2025-04-19 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:849dcb45c5a79fa29c3cf706c987157deea4ac9d

commit r13-9552-g849dcb45c5a79fa29c3cf706c987157deea4ac9d
Author: Iain Buclaw 
Date:   Wed Apr 9 20:02:02 2025 +0200

d: Fix forward referenced enums missing type names in debug info [PR118309]

Calling `rest_of_type_compilation' as the D types were built meant that
debug info was being emitted before all forward references were
resolved, resulting in DW_AT_name's to be missing.

Instead, defer outputting type debug information until all modules have
been parsed and generated in `d_finish_compilation'.

PR d/118309

gcc/d/ChangeLog:

* modules.cc: Include debug.h
(d_finish_compilation): Call debug_hooks->type_decl on all 
TYPE_DECLs.
* types.cc: Remove toplev.h include.
(finish_aggregate_type): Don't call rest_of_type_compilation or
rest_of_decl_compilation on type.
(TypeVisitor::visit (TypeEnum *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/debug/dwarf2/pr118309.d: New test.

(cherry picked from commit cee353c2653d274768a67677c8ea37fd23422b3c)

Diff:
---
 gcc/d/modules.cc |  9 +++
 gcc/d/types.cc   | 15 ++--
 gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d | 36 
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index be93d8af093a..3d43d82623f6 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "function.h"
 #include "cgraph.h"
 #include "stor-layout.h"
+#include "debug.h"
 #include "toplev.h"
 #include "target.h"
 #include "common/common-target.h"
@@ -908,6 +909,14 @@ d_finish_compilation (tree *vec, int len)
   /* Complete all generated thunks.  */
   symtab->process_same_body_aliases ();
 
+  /* Output debug information for all type declarations in this unit.  */
+  for (int i = 0; i < len; i++)
+{
+  tree decl = vec[i];
+  if (TREE_CODE (decl) == TYPE_DECL)
+   debug_hooks->type_decl (decl, false);
+}
+
   /* Process all file scopes in this compilation, and the external_scope,
  through wrapup_global_declarations.  */
   for (int i = 0; i < len; i++)
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 0a8679756b0a..954686f2317f 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -33,7 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "langhooks.h"
 #include "tm.h"
 #include "function.h"
-#include "toplev.h"
 #include "target.h"
 #include "stringpool.h"
 #include "stor-layout.h"
@@ -709,13 +708,8 @@ finish_aggregate_type (unsigned structsize, unsigned 
alignsize, tree type)
   TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
 }
 
-  /* Finish debugging output for this type.  */
-  rest_of_type_compilation (type, TYPE_FILE_SCOPE_P (type));
+  /* Complete any other forward-referenced fields of this aggregate type.  */
   finish_incomplete_fields (type);
-
-  /* Finish processing of TYPE_DECL.  */
-  rest_of_decl_compilation (TYPE_NAME (type),
-   DECL_FILE_SCOPE_P (TYPE_NAME (type)), 0);
 }
 
 /* Returns true if the class or struct type TYPE has already been layed out by
@@ -1185,13 +1179,8 @@ public:
 
layout_type (t->ctype);
 
-   /* Finish debugging output for this type.  */
-   rest_of_type_compilation (t->ctype, TYPE_FILE_SCOPE_P (t->ctype));
+   /* Complete forward-referenced fields of this enum type.  */
finish_incomplete_fields (t->ctype);
-
-   /* Finish processing of TYPE_DECL.  */
-   rest_of_decl_compilation (TYPE_NAME (t->ctype),
- DECL_FILE_SCOPE_P (TYPE_NAME (t->ctype)), 0);
   }
   }
 
diff --git a/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d 
b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
new file mode 100644
index ..50e42164eef1
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/dwarf2/pr118309.d
@@ -0,0 +1,36 @@
+// { dg-do compile }
+// { dg-options "-fno-druntime -gdwarf-4 -dA -fno-merge-debug-strings" }
+// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 1 
} }
+// { dg-final { scan-assembler-times " DW_AT_enum_class" 1 } }
+// { dg-final { scan-assembler-times "\"E..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"E1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C1..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C2..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C3..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"C4..\"\[^\n\]*DW_AT_name" 1 } }
+// { dg-final { scan-assembler-times "\"S1..\"\[^\n\]*DW_AT_name" 1 } }
+
+module expression;
+extern (C++):
+class C1
+{
+bool bfn() { return true; }
+}
+class C2 : C1
+{
+C4 cfn() { return null; }
+}
+

[gcc r16-36] [PATCH v2] sh: libgcc: Implement fenv rouding and exceptions for soft-fp [PR118257]

2025-04-19 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:05c4e3ecb54d22836ba2ae0ec1efedf8b78d7522

commit r16-36-g05c4e3ecb54d22836ba2ae0ec1efedf8b78d7522
Author: Jiaxun Yang 
Date:   Sat Apr 19 08:12:07 2025 -0600

[PATCH v2] sh: libgcc: Implement fenv rouding and exceptions for soft-fp 
[PR118257]

Implement fenv rouding and exceptions for soft-fp, as per SuperH
arch specification.

No new tests required, as it's already covered by many torture tests
with fenv_exceptions.

PR target/118257

libgcc/ChangeLog:

* config/sh/sfp-machine.h (_FPU_GETCW): Implement with builtin.
(_FPU_SETCW): Likewise.
(FP_EX_ENABLE_SHIFT): Derive from arch spec.
(FP_EX_CAUSE_SHIFT): Likewise.
(FP_RND_MASK): Likewise.
(FP_EX_INVALID): Likewise.
(FP_EX_DIVZERO): Likewise.
(FP_EX_ALL): Likewise.
(FP_EX_OVERFLOW): Likewise.
(FP_EX_UNDERFLOW): Likewise.
(FP_EX_INEXACT): Likewise.
(_FP_DECL_EX): Declear default FCSR value.
(FP_RND_NEAREST): Derive from arch spec.
(FP_RND_ZERO): Likewise.
(FP_INIT_ROUNDMODE): Likewise.
(FP_ROUNDMODE): Likewise.
(FP_TRAPPING_EXCEPTIONS): Likewise.
(FP_HANDLE_EXCEPTIONS): Implement with _FPU_SETCW.

Diff:
---
 libgcc/config/sh/sfp-machine.h | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/libgcc/config/sh/sfp-machine.h b/libgcc/config/sh/sfp-machine.h
index 67bc41516a38..8030c802154e 100644
--- a/libgcc/config/sh/sfp-machine.h
+++ b/libgcc/config/sh/sfp-machine.h
@@ -76,6 +76,52 @@ typedef int __gcc_CMPtype __attribute__ ((mode 
(__libgcc_cmp_return__)));
 R##_c = FP_CLS_NAN;\
   } while (0)
 
+#ifdef __SH_FPU_ANY__
+#define _FPU_GETCW(fpscr) fpscr = __builtin_sh_get_fpscr ()
+#define _FPU_SETCW(fpscr) __builtin_sh_set_fpscr (fpscr)
+#define FP_EX_ENABLE_SHIFT 5
+#define FP_EX_CAUSE_SHIFT  10
+
+#defineFP_EX_INVALID   0x0040
+#defineFP_EX_DIVZERO   0x0020
+#if defined (__SH2E__)
+#defineFP_EX_ALL   (FP_EX_DIVZERO | FP_EX_INVALID)
+#else
+#defineFP_EX_OVERFLOW  0x0010
+#defineFP_EX_UNDERFLOW 0x0008
+#defineFP_EX_INEXACT   0x0004
+#defineFP_EX_ALL   (FP_EX_DIVZERO | FP_EX_INEXACT | \
+FP_EX_INVALID | FP_EX_OVERFLOW | FP_EX_UNDERFLOW)
+#endif
+#define _FP_DECL_EX \
+  unsigned int _fcsr __attribute__ ((unused)) = FP_RND_NEAREST
+/* Rounding modes.  */
+#defineFP_RND_NEAREST  0x0
+#defineFP_RND_ZERO 0x1
+/* Placeholder, hardware does not have PINF/MINF modes.  */
+#define FP_RND_PINF 0x2
+#define FP_RND_MINF 0x3
+#define FP_RND_MASK 3
+
+#define FP_INIT_ROUNDMODE _FPU_GETCW (_fcsr)
+#define FP_ROUNDMODE (_fcsr & FP_RND_MASK)
+#define FP_TRAPPING_EXCEPTIONS ((_fcsr >> FP_EX_ENABLE_SHIFT) & FP_EX_ALL)
+#define FP_HANDLE_EXCEPTIONS   \
+  do { \
+_fcsr &= ~(FP_EX_ALL << FP_EX_CAUSE_SHIFT);\
+_fcsr |= _fex | (_fex << FP_EX_CAUSE_SHIFT);   \
+_FPU_SETCW (_fcsr);\
+  } while (0)
+#else
+#define FP_EX_INVALID (1 << 4)
+#define FP_EX_DIVZERO (1 << 3)
+#if !defined (__SH2E__)
+#define FP_EX_OVERFLOW (1 << 2)
+#define FP_EX_UNDERFLOW (1 << 1)
+#define FP_EX_INEXACT (1 << 0)
+#endif
+#endif
+
 #define _FP_TININESS_AFTER_ROUNDING 1
 
 #define __LITTLE_ENDIAN 1234


[gcc r16-39] Add tables for SSE fp conversion costs

2025-04-19 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:f6859fb621179ec9bf5631eb8902619ab8d4467b

commit r16-39-gf6859fb621179ec9bf5631eb8902619ab8d4467b
Author: Jan Hubicka 
Date:   Sat Apr 19 18:51:27 2025 +0200

Add tables for SSE fp conversion costs

as disucssed, I will proceed adding costs for common SSE operations which 
are
currently globbed into addss cost, so we do not need to set it incorrectly 
for
znver5.  Looking through the stats, there are quite few missing cases, so I 
am
starting with those that I think are more common. I plan to do it in smaller
steps so individual changes gets benchmarked by LNT and also can be bisected
to.

This patch adds costs for various SSE and AVX FP->FP conversions 
(extensions and
truncations). Looking through Agner Fog's tables, these are bit assymetric 
so I
added cost for CVTSS2SD which is also used for CVTSD2SS, CVTPS2PD and 
CVTPD2PS,
cost for 256bit VCVTPS2PS (also used for oposite direction) and cost for 
512bit
one.

I plan to add int->int conversions next and then int->fp & fp->int which are
more tricky since they may bundle inter-unit move.

I also noticed that size tables are wrong for all SSE instructions so I 
updated
them.  With some love I think vectorization can work as size optimization, 
too,
but we need more work on that.

Those values I can find in Agner Fog tables are taken from there, other are 
guesses
(especially for yongfeng_cost and shijidadao_cost).

gcc/ChangeLog:

* config/i386/i386.cc (vec_fp_conversion_cost): New function.
(ix86_rtx_costs): Use it for SSE/AVX FP conversoins.
(ix86_builtin_vectorization_cost): Fix indentation;
and use vec_fp_conversion_cost in vec_promote_demote.
(fp_conversion_stmt_cost): New function.
(ix86_vector_costs::add_stmt_cost): Use it to cost NOP_EXPR
and vec_promote_demote.
* config/i386/i386.h (struct processor_costs):
* config/i386/x86-tune-costs.h (struct processor_costs):

Diff:
---
 gcc/config/i386/i386.cc  |  64 -
 gcc/config/i386/i386.h   |   6 ++
 gcc/config/i386/x86-tune-costs.h | 121 +++
 3 files changed, 178 insertions(+), 13 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 38df84f7db24..28603c2943ee 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -100,6 +100,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "i386-features.h"
 #include "function-abi.h"
 #include "rtl-error.h"
+#include "gimple-pretty-print.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -21816,6 +21817,25 @@ ix86_insn_cost (rtx_insn *insn, bool speed)
   return insn_cost + pattern_cost (PATTERN (insn), speed);
 }
 
+/* Return cost of SSE/AVX FP->FP conversion (extensions and truncates).  */
+
+static int
+vec_fp_conversion_cost (const struct processor_costs *cost, int size)
+{
+  if (size < 128)
+return cost->cvtss2sd;
+  else if (size < 256)
+{
+  if (TARGET_SSE_SPLIT_REGS)
+   return cost->cvtss2sd * size / 64;
+  return cost->cvtss2sd;
+}
+  if (size < 512)
+return cost->vcvtps2pd256;
+  else
+return cost->vcvtps2pd512;
+}
+
 /* Compute a (partial) cost for rtx X.  Return true if the complete
cost has been computed, and false if subexpressions should be
scanned.  In either case, *TOTAL contains the cost result.  */
@@ -22479,17 +22499,18 @@ ix86_rtx_costs (rtx x, machine_mode mode, int 
outer_code_i, int opno,
   return false;
 
 case FLOAT_EXTEND:
+  /* x87 represents all values extended to 80bit.  */
   if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
*total = 0;
   else
-*total = ix86_vec_cost (mode, cost->addss);
+   *total = vec_fp_conversion_cost (cost, GET_MODE_BITSIZE (mode));
   return false;
 
 case FLOAT_TRUNCATE:
   if (!SSE_FLOAT_MODE_SSEMATH_OR_HFBF_P (mode))
*total = cost->fadd;
   else
-*total = ix86_vec_cost (mode, cost->addss);
+   *total = vec_fp_conversion_cost (cost, GET_MODE_BITSIZE (mode));
   return false;
 
 case ABS:
@@ -24683,7 +24704,7 @@ ix86_builtin_vectorization_cost (enum 
vect_cost_for_stmt type_of_cost,
   switch (type_of_cost)
 {
   case scalar_stmt:
-return fp ? ix86_cost->addss : COSTS_N_INSNS (1);
+   return fp ? ix86_cost->addss : COSTS_N_INSNS (1);
 
   case scalar_load:
/* load/store costs are relative to register move which is 2. Recompute
@@ -24754,7 +24775,11 @@ ix86_builtin_vectorization_cost (enum 
vect_cost_for_stmt type_of_cost,
 return ix86_cost->cond_not_taken_branch_cost;
 
   case vec_perm:
+   return ix86_vec_cost (mode, ix86_cost->sse_op);
+
   case vec_promote_demote:
+   if (fp)
+ return vec_fp_conversion_cost (ix86_tune_cost, mode);
  

[gcc r16-34] c++: minor EXPR_STMT cleanup

2025-04-19 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:6beb0a14aacd84ec49646237fc0f69c6765f956e

commit r16-34-g6beb0a14aacd84ec49646237fc0f69c6765f956e
Author: Jason Merrill 
Date:   Mon Feb 3 10:35:33 2025 -0500

c++: minor EXPR_STMT cleanup

I think it was around PR118574 that I noticed a few cases where we were
unnecessarily wrapping a statement tree in a further EXPR_STMT.  Let's avoid
that and also use finish_expr_stmt in a few places in the coroutines code
that were building EXPR_STMT directly.

gcc/cp/ChangeLog:

* coroutines.cc (coro_build_expr_stmt)
(coro_build_cvt_void_expr_stmt): Remove.
(build_actor_fn): Use finish_expr_stmt.
* semantics.cc (finish_expr_stmt): Avoid wrapping statement in
EXPR_STMT.
(finish_stmt_expr_expr): Add comment.

Diff:
---
 gcc/cp/coroutines.cc | 21 ++---
 gcc/cp/semantics.cc  |  8 ++--
 2 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index b92d09fa4ead..743da068e352 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1852,21 +1852,6 @@ coro_build_frame_access_expr (tree coro_ref, tree 
member_id, bool preserve_ref,
   return expr;
 }
 
-/* Helpers to build EXPR_STMT and void-cast EXPR_STMT, common ops.  */
-
-static tree
-coro_build_expr_stmt (tree expr, location_t loc)
-{
-  return maybe_cleanup_point_expr_void (build_stmt (loc, EXPR_STMT, expr));
-}
-
-static tree
-coro_build_cvt_void_expr_stmt (tree expr, location_t loc)
-{
-  tree t = build1 (CONVERT_EXPR, void_type_node, expr);
-  return coro_build_expr_stmt (t, loc);
-}
-
 /* Helpers to build an artificial var, with location LOC, NAME and TYPE, in
CTX, and with initializer INIT.  */
 
@@ -2582,8 +2567,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, 
tree actor, tree fnbody,
   tree hfa = build_new_method_call (ash, hfa_m, &args, NULL_TREE, 
LOOKUP_NORMAL,
NULL, tf_warning_or_error);
   r = cp_build_init_expr (ash, hfa);
-  r = coro_build_cvt_void_expr_stmt (r, loc);
-  add_stmt (r);
+  finish_expr_stmt (r);
   release_tree_vector (args);
 
   /* Now we know the real promise, and enough about the frame layout to
@@ -2678,8 +2662,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, 
tree actor, tree fnbody,
  we must tail call them.  However, some targets do not support indirect
  tail calls to arbitrary callees.  See PR94359.  */
   CALL_EXPR_TAILCALL (resume) = true;
-  resume = coro_build_cvt_void_expr_stmt (resume, loc);
-  add_stmt (resume);
+  finish_expr_stmt (resume);
 
   r = build_stmt (loc, RETURN_EXPR, NULL);
   gcc_checking_assert (maybe_cleanup_point_expr_void (r) == r);
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 7f23efd4a11e..1aa35d3861ea 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -1180,10 +1180,13 @@ finish_expr_stmt (tree expr)
 expr = error_mark_node;
 
   /* Simplification of inner statement expressions, compound exprs,
-etc can result in us already having an EXPR_STMT.  */
+etc can result in us already having an EXPR_STMT or other statement
+tree.  Don't wrap them in EXPR_STMT.  */
   if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
{
- if (TREE_CODE (expr) != EXPR_STMT)
+ if (TREE_CODE (expr) != EXPR_STMT
+ && !STATEMENT_CLASS_P (expr)
+ && TREE_CODE (expr) != STATEMENT_LIST)
expr = build_stmt (loc, EXPR_STMT, expr);
  expr = maybe_cleanup_point_expr_void (expr);
}
@@ -3082,6 +3085,7 @@ finish_stmt_expr_expr (tree expr, tree stmt_expr)
}
   else if (processing_template_decl)
{
+ /* Not finish_expr_stmt because we don't want convert_to_void.  */
  expr = build_stmt (input_location, EXPR_STMT, expr);
  expr = add_stmt (expr);
  /* Mark the last statement so that we can recognize it as such at


[gcc r16-35] [PATCH v2] sh: Correct NaN signalling bit and propagation rules [PR111814]

2025-04-19 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:2a643f55f5acc05dcc7cee133647bf3193d5b563

commit r16-35-g2a643f55f5acc05dcc7cee133647bf3193d5b563
Author: Jiaxun Yang 
Date:   Sat Apr 19 08:07:58 2025 -0600

[PATCH v2] sh: Correct NaN signalling bit and propagation rules [PR111814]

As per architecture, SuperH has a reversed NaN signalling bit
vs IEEE754-2008, it also has a NaN propgation rule similar to
MIPS style.

Use mips style float format and mode for all float types, and
correct sfp-machine header accordingly.

PR target/111814

gcc/ChangeLog:

* config/sh/sh-modes.def (RESET_FLOAT_FORMAT): Use mips format.
(FLOAT_MODE): Use mips mode.

libgcc/ChangeLog:

* config/sh/sfp-machine.h (_FP_NANFRAC_B): Reverse signaling bit.
(_FP_NANFRAC_H): Likewise.
(_FP_NANFRAC_S): Likewise.
(_FP_NANFRAC_D): Likewise.
(_FP_NANFRAC_Q): Likewise.
(_FP_KEEPNANFRACP): Enable for target.
(_FP_QNANNEGATEDP): Enable for target.
(_FP_CHOOSENAN): Port from MIPS.

gcc/testsuite/ChangeLog:

* gcc.target/sh/pr111814.c: New test.

Diff:
---
 gcc/config/sh/sh-modes.def |  6 ++
 gcc/testsuite/gcc.target/sh/pr111814.c |  7 +++
 libgcc/config/sh/sfp-machine.h | 36 ++
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/gcc/config/sh/sh-modes.def b/gcc/config/sh/sh-modes.def
index 80650b429e4c..e31ae694a48d 100644
--- a/gcc/config/sh/sh-modes.def
+++ b/gcc/config/sh/sh-modes.def
@@ -17,6 +17,12 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+/* SH has the same reversed quiet bit as MIPS.  */
+RESET_FLOAT_FORMAT (SF, mips_single_format);
+RESET_FLOAT_FORMAT (DF, mips_double_format);
+/* TFmode: IEEE quad floating point (software).  */
+FLOAT_MODE (TF, 16, mips_quad_format);
+
 /* Vector modes.  */
 VECTOR_MODE  (INT, QI, 2);/* V2QI */
 VECTOR_MODES (INT, 4);/*V4QI V2HI */
diff --git a/gcc/testsuite/gcc.target/sh/pr111814.c 
b/gcc/testsuite/gcc.target/sh/pr111814.c
new file mode 100644
index ..a88e5d786ba0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/sh/pr111814.c
@@ -0,0 +1,7 @@
+/* Verify that __builtin_nan("") produces a constant matches
+   architecture specification. */
+/* { dg-do compile } */
+
+double d = __builtin_nan ("");
+
+/* { dg-final { scan-assembler "\t.long\t-1\n\t.long\t2146959359\n" } } */
diff --git a/libgcc/config/sh/sfp-machine.h b/libgcc/config/sh/sfp-machine.h
index 66984d45755f..67bc41516a38 100644
--- a/libgcc/config/sh/sfp-machine.h
+++ b/libgcc/config/sh/sfp-machine.h
@@ -39,11 +39,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 #define _FP_DIV_MEAT_D(R,X,Y)  _FP_DIV_MEAT_2_udiv(D,R,X,Y)
 #define _FP_DIV_MEAT_Q(R,X,Y)  _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
 
-#define _FP_NANFRAC_B  _FP_QNANBIT_B
-#define _FP_NANFRAC_H  _FP_QNANBIT_H
-#define _FP_NANFRAC_S  _FP_QNANBIT_S
-#define _FP_NANFRAC_D  _FP_QNANBIT_D, 0
-#define _FP_NANFRAC_Q  _FP_QNANBIT_Q, 0, 0, 0
+#define _FP_NANFRAC_B  (_FP_QNANBIT_B - 1)
+#define _FP_NANFRAC_H  (_FP_QNANBIT_H - 1)
+#define _FP_NANFRAC_S  (_FP_QNANBIT_S - 1)
+#define _FP_NANFRAC_D  (_FP_QNANBIT_D - 1), -1
+#define _FP_NANFRAC_Q  (_FP_QNANBIT_Q - 1), -1, -1, -1
 
 /* The type of the result of a floating point comparison.  This must
match __libgcc_cmp_return__ in GCC for the target.  */
@@ -56,14 +56,24 @@ typedef int __gcc_CMPtype __attribute__ ((mode 
(__libgcc_cmp_return__)));
 #define _FP_NANSIGN_D  0
 #define _FP_NANSIGN_Q  0
 
-#define _FP_KEEPNANFRACP 0
-#define _FP_QNANNEGATEDP 0
-
-#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP)  \
-  do {  \
-R##_s = _FP_NANSIGN_##fs;   \
-_FP_FRAC_SET_##wc(R,_FP_NANFRAC_##fs);  \
-R##_c = FP_CLS_NAN; \
+#define _FP_KEEPNANFRACP 1
+#define _FP_QNANNEGATEDP 1
+
+/* X is chosen unless one of the NaNs is sNaN.  */
+# define _FP_CHOOSENAN(fs, wc, R, X, Y, OP)\
+  do { \
+if ((_FP_FRAC_HIGH_RAW_##fs(X) |   \
+_FP_FRAC_HIGH_RAW_##fs(Y)) & _FP_QNANBIT_##fs) \
+  {\
+   R##_s = _FP_NANSIGN_##fs;   \
+   _FP_FRAC_SET_##wc(R,_FP_NANFRAC_##fs);  \
+  }\
+else   \
+  {\
+   R##_s = X##_s;  \
+   _FP_FRAC_COPY_##wc(R,X);\
+  }   

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression dependency_60.f90

2025-04-19 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:4cf0bfc9ea46cdcd4372780dd4f11b630c10f2dc

commit 4cf0bfc9ea46cdcd4372780dd4f11b630c10f2dc
Author: Mikael Morin 
Date:   Sat Apr 19 14:53:51 2025 +0200

Correction régression dependency_60.f90

Diff:
---
 gcc/fortran/trans-array.cc  |  4 +++-
 gcc/fortran/trans-descriptor.cc | 25 +
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index d0a205fef90b..75802c9a0b02 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -2836,7 +2836,9 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, 
bool subscript,
  trans_array_constructor (ss, where);
  {
gcc_assert (info->shape != nullptr || ss->dimen == 1);
-   tree type = gfc_typenode_for_spec (&ss_info->expr->ts);
+   tree type = gfc_typenode_for_spec (ss_info->expr->ts.type == 
BT_CLASS
+  ? &CLASS_DATA (ss_info->expr)->ts
+  : &ss_info->expr->ts);
if (ss_info->expr->ts.type == BT_CHARACTER
&& ss_info->expr->ts.u.cl->length
&& ss_info->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT)
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 3ae5a2a2dea3..cb2dd86f6522 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -3879,12 +3879,37 @@ gfc_grow_array (stmtblock_t * pblock, tree desc, tree 
extra)
 
   /* Calculate the new array size.  */
   size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc)));
+  gcc_assert (integer_zerop (GFC_TYPE_ARRAY_LBOUND (TREE_TYPE (desc), 0)));
   tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
 ubound, gfc_index_one_node);
   arg1 = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
  fold_convert (size_type_node, tmp),
  fold_convert (size_type_node, size));
 
+  /* Reset array type upper bound if known.  */
+  tree dataptr_type = GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc));
+  gcc_assert (TREE_CODE (dataptr_type) == POINTER_TYPE);
+  tree array_type = TREE_TYPE (dataptr_type);
+  gcc_assert (TREE_CODE (array_type) == ARRAY_TYPE);
+  tree index_type = TYPE_DOMAIN (array_type);
+  if (index_type != NULL_TREE
+  && (TYPE_MAX_VALUE (index_type) != NULL_TREE
+ || TYPE_SIZE (array_type) != NULL_TREE
+ || TYPE_SIZE_UNIT (array_type) != NULL_TREE))
+{
+  tree fixed_index_type = build_distinct_type_copy (index_type);
+  TYPE_MAX_VALUE (fixed_index_type) = NULL_TREE;
+
+  tree fixed_array_type = build_distinct_type_copy (array_type);
+  TYPE_DOMAIN (fixed_array_type) = fixed_index_type;
+  TYPE_SIZE (fixed_array_type) = NULL_TREE;
+  TYPE_SIZE_UNIT (fixed_array_type) = NULL_TREE;
+  layout_type (fixed_array_type);
+
+  tree fixed_ptr_type = build_pointer_type (fixed_array_type);
+  GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc)) = fixed_ptr_type;
+}
+
   /* Call the realloc() function.  */
   tmp = gfc_call_realloc (pblock, arg0, arg1);
   gfc_conv_descriptor_data_set (pblock, desc, tmp);


[gcc r16-40] [RISC-V][PR target/118410] Improve code generation for some logical ops

2025-04-19 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:874f4c164749f1ed5b60ddf1d4533c8f4ba627a1

commit r16-40-g874f4c164749f1ed5b60ddf1d4533c8f4ba627a1
Author: Jeff Law 
Date:   Sat Apr 19 12:30:42 2025 -0600

[RISC-V][PR target/118410] Improve code generation for some logical ops

I'm posting this on behalf of Shreya Munnangi who is working as an intern 
with
me.  I've got her digging into prerequisites for removing mvconst_internal 
and
would prefer she focus on that rather than our patch process at this time.

--

We can use the orn, xnor, andn instructions on RISC-V to improve the code
generated logical operations when one operand is a constant C where
synthesizing ~C is cheaper than synthesizing C.

This is going to be an N -> N - 1 splitter rather than a 
define_insn_and_split.
A define_insn_and_split can obviously work, but has multiple undesirable
effects in general.

As a result of implementing as a simple define_split we're not supporting 
AND
at this time.  We need to clean up the mvconst_internal situation first 
after
which supporting AND is trivial.

This has been tested in Ventana's CI system as well as my tester. Obviously
we'll wait for the pre-commit tester to run before moving forward.

PR target/118410
gcc/
* config/riscv/bitmanip.md (logical with constant argument): New
splitter for cases where synthesizing ~C is cheaper than 
synthesizing
the original constant C.

gcc/testsuite/
* gcc.target/riscv/pr118410-1.c: New test.
* gcc.target/riscv/pr118410-2.c: Likewise.

Co-authored-by: Jeff Law  

Diff:
---
 gcc/config/riscv/bitmanip.md| 38 +
 gcc/testsuite/gcc.target/riscv/pr118410-1.c |  9 +++
 gcc/testsuite/gcc.target/riscv/pr118410-2.c |  9 +++
 3 files changed, 56 insertions(+)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 2a3884cfde01..d0919ece31f7 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -1263,3 +1263,41 @@
   expand_crc_using_clmul (mode, mode, operands);
   DONE;
 })
+
+;; If we have an XOR/IOR with a constant operand (C) and the we can
+;; synthesize ~C more efficiently than C, then synthesize ~C and use
+;; xnor/orn instead.
+;;
+;; The same can be done for AND, but mvconst_internal's issues get in
+;; the way.  That's future work.
+(define_split
+  [(set (match_operand:X 0 "register_operand")
+   (any_or:X (match_operand:X 1 "register_operand")
+ (match_operand:X 2 "const_int_operand")))
+   (clobber (match_operand:X 3 "register_operand"))]
+  "TARGET_ZBB
+   && (riscv_const_insns (operands[2], true)
+   > riscv_const_insns (GEN_INT (~INTVAL (operands[2])), true))"
+  [(const_int 0)]
+{
+  /* Get the inverted constant into the temporary register.  */
+  riscv_emit_move (operands[3], GEN_INT (~INTVAL (operands[2])));
+
+  /* For xnor, the NOT operation is in a different position.  So
+ we have to customize the split code we generate a bit.
+
+ It is expected that AND will be handled like IOR in the future.  */
+  if ( == XOR)
+{
+  rtx x = gen_rtx_XOR (mode, operands[1], operands[3]);
+  x = gen_rtx_NOT (mode, x);
+  emit_insn (gen_rtx_SET (operands[0], x));
+}
+  else
+{
+  rtx x = gen_rtx_NOT (mode, operands[3]);
+  x = gen_rtx_IOR (mode, x, operands[1]);
+  emit_insn (gen_rtx_SET (operands[0], x));
+}
+  DONE;
+})
diff --git a/gcc/testsuite/gcc.target/riscv/pr118410-1.c 
b/gcc/testsuite/gcc.target/riscv/pr118410-1.c
new file mode 100644
index ..4a8b847d4f4c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr118410-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+/* { dg-options "-march=rv64gcb -mabi=lp64d" { target { rv64} } } */
+/* { dg-options "-march=rv32gcb -mabi=ilp32" { target { rv32} } } */
+
+long orlow(long x) { return x | ((1L << 24) - 1); }
+
+/* { dg-final { scan-assembler-times "orn\t" 1 } } */
+/* { dg-final { scan-assembler-not "addi\t" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/pr118410-2.c 
b/gcc/testsuite/gcc.target/riscv/pr118410-2.c
new file mode 100644
index ..b63a1d9c4659
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr118410-2.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+/* { dg-options "-march=rv64gcb -mabi=lp64d" { target { rv64} } } */
+/* { dg-options "-march=rv32gcb -mabi=ilp32" { target { rv32} } } */
+
+long xorlow(long x) { return x ^ ((1L << 24) - 1); }
+
+/* { dg-final { scan-assembler-times "xnor\t" 1 } } */
+/* { dg-final { scan-assembler-not "addi\t" } } */


[gcc r16-41] [RISC-V][PR target/119865] Don't free ggc allocated memory

2025-04-19 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:1a64b224fa014e772fb30f6bd69ceb24da5827e6

commit r16-41-g1a64b224fa014e772fb30f6bd69ceb24da5827e6
Author: Jeff Law 
Date:   Sat Apr 19 12:35:29 2025 -0600

[RISC-V][PR target/119865] Don't free ggc allocated memory

Kaiweng's patch to stop freeing riscv_arch_string was correct, but 
incomplete
as there's another path that was freeing that node, which is just plain 
wrong
for a node allocated by the GC system.

This patch removes that call to free() which fixes the test.  I've spun it 
in
my tester and will obviously wait for the pre-commit system to render a 
verdict
before moving forward.

PR target/119865
gcc/
* config/riscv/riscv.cc (parse_features_for_version): Do not
explicitly free the architecture string.

Diff:
---
 gcc/config/riscv/riscv.cc | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index d3656a7a4307..bad59e248d08 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -13136,9 +13136,6 @@ parse_features_for_version (tree decl,
  DECL_SOURCE_LOCATION (decl));
   gcc_assert (parse_res);
 
-  if (arch_string != default_opts->x_riscv_arch_string)
-free (CONST_CAST (void *, (const void *) arch_string));
-
   cl_target_option_restore (&global_options, &global_options_set,
&cur_target);
 }


[gcc r16-33] Alpha: Fix base block alignment calculation regression

2025-04-19 Thread Maciej W. Rozycki via Gcc-cvs
https://gcc.gnu.org/g:1dd769b3d0d9251649dcb645d7ed6c4ba2202306

commit r16-33-g1dd769b3d0d9251649dcb645d7ed6c4ba2202306
Author: Maciej W. Rozycki 
Date:   Sat Apr 19 14:10:25 2025 +0100

Alpha: Fix base block alignment calculation regression

In determination of base block alignment we only examine a COMPONENT_REF
tree node at hand without ever checking if its ultimate alignment has
been reduced by the combined offset going back to the outermost object.
Consequently cases have been observed where quadword accesses have been
produced for a memory location referring a nested struct member only
aligned to the longword boundary, causing emulation to trigger.

Address this issue by recursing into COMPONENT_REF tree nodes until the
outermost one has been reached, which is supposed to be a MEM_REF one,
accumulating the offset as we go, fixing a commit e0dae4da4c45 ("Alpha:
Also use tree information to get base block alignment") regression.

Bail out and refrain from using tree information for alignment if we end
up at something different or we are unable to calculate the offset at
any point.

gcc/
* config/alpha/alpha.cc
(alpha_get_mem_rtx_alignment_and_offset): Recurse into
COMPONENT_REF nodes.

gcc/testsuite/
* gcc.target/alpha/memcpy-nested-offset-long.c: New file.
* gcc.target/alpha/memcpy-nested-offset-quad.c: New file.

Diff:
---
 gcc/config/alpha/alpha.cc  | 23 +++
 .../gcc.target/alpha/memcpy-nested-offset-long.c   | 76 ++
 .../gcc.target/alpha/memcpy-nested-offset-quad.c   | 64 ++
 3 files changed, 150 insertions(+), 13 deletions(-)

diff --git a/gcc/config/alpha/alpha.cc b/gcc/config/alpha/alpha.cc
index ba470d9e75ec..14e7da57ca6f 100644
--- a/gcc/config/alpha/alpha.cc
+++ b/gcc/config/alpha/alpha.cc
@@ -4291,14 +4291,10 @@ alpha_get_mem_rtx_alignment_and_offset (rtx expr, int 
&a, HOST_WIDE_INT &o)
 
   tree mem = MEM_EXPR (expr);
   if (mem != NULL_TREE)
-switch (TREE_CODE (mem))
-  {
-  case MEM_REF:
-   tree_offset = mem_ref_offset (mem).force_shwi ();
-   tree_align = get_object_alignment (get_base_address (mem));
-   break;
+{
+  HOST_WIDE_INT comp_offset = 0;
 
-  case COMPONENT_REF:
+  for (; TREE_CODE (mem) == COMPONENT_REF; mem = TREE_OPERAND (mem, 0))
{
  tree byte_offset = component_ref_field_offset (mem);
  tree bit_offset = DECL_FIELD_BIT_OFFSET (TREE_OPERAND (mem, 1));
@@ -4307,14 +4303,15 @@ alpha_get_mem_rtx_alignment_and_offset (rtx expr, int 
&a, HOST_WIDE_INT &o)
  || !poly_int_tree_p (byte_offset, &offset)
  || !tree_fits_shwi_p (bit_offset))
break;
- tree_offset = offset + tree_to_shwi (bit_offset) / BITS_PER_UNIT;
+ comp_offset += offset + tree_to_shwi (bit_offset) / BITS_PER_UNIT;
}
-   tree_align = get_object_alignment (get_base_address (mem));
-   break;
 
-  default:
-   break;
-  }
+  if (TREE_CODE (mem) == MEM_REF)
+   {
+ tree_offset = comp_offset + mem_ref_offset (mem).force_shwi ();
+ tree_align = get_object_alignment (get_base_address (mem));
+   }
+}
 
   if (reg_align > mem_align)
 {
diff --git a/gcc/testsuite/gcc.target/alpha/memcpy-nested-offset-long.c 
b/gcc/testsuite/gcc.target/alpha/memcpy-nested-offset-long.c
new file mode 100644
index ..631d14f3de27
--- /dev/null
+++ b/gcc/testsuite/gcc.target/alpha/memcpy-nested-offset-long.c
@@ -0,0 +1,76 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+typedef unsigned int __attribute__ ((mode (DI))) int64_t;
+typedef unsigned int __attribute__ ((mode (SI))) int32_t;
+
+typedef union
+  {
+int32_t l[8];
+  }
+val;
+
+typedef struct
+  {
+int32_t l[2];
+val v;
+  }
+tre;
+
+typedef struct
+  {
+int32_t l[3];
+tre t;
+  }
+due;
+
+typedef struct
+  {
+val v;
+int64_t q;
+int32_t l[2];
+due d;
+  }
+uno;
+
+void
+memcpy_nested_offset_long (uno *u)
+{
+  u->d.t.v = u->v;
+}
+
+/* Expect assembly such as:
+
+   ldq $4,0($16)
+   ldq $3,8($16)
+   ldq $2,16($16)
+   srl $4,32,$7
+   ldq $1,24($16)
+   srl $3,32,$6
+   stl $4,68($16)
+   srl $2,32,$5
+   stl $7,72($16)
+   srl $1,32,$4
+   stl $3,76($16)
+   stl $6,80($16)
+   stl $2,84($16)
+   stl $5,88($16)
+   stl $1,92($16)
+   stl $4,96($16)
+
+   that is with four quadword loads at offsets 0, 8, 16, 24 each and
+   eight longword stores at offsets 68, 72, 76, 80, 84, 88, 92, 96 each.  */
+
+/* { dg-final { scan-assembler-times 
"\\sldq\\s\\\$\[0-9\]+,0\\\(\\\$16\\\)\\s" 1 } } */
+/* { dg-final { scan-assembler-times 
"\\sldq\\s\\\$\[0-9\]+,8\\\(\\\$16\\\)\\s" 1 } } */
+/* { dg-final { scan-assembler-times 
"\\sldq\\s\\

[gcc r16-37] combine: Better split point for `(and (not X))` [PR111949]

2025-04-19 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:0939abea33ce9d9eb9328f80aace8109c096760c

commit r16-37-g0939abea33ce9d9eb9328f80aace8109c096760c
Author: Andrew Pinski 
Date:   Mon Jan 20 15:24:39 2025 -0800

combine: Better split point for `(and (not X))` [PR111949]

In a similar way find_split_point handles `a+b*C`, this adds
the split point for `~a & b`.  This allows for better instruction
selection when the target has this instruction (aarch64, arm and x86_64
are examples which have this).

Built and tested for aarch64-linux-gnu.

PR rtl-optimization/111949

gcc/ChangeLog:

* combine.cc (find_split_point): Add a split point
for `(and (not X) Y)` if not in the outer set already.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/bic-1.c: New test.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/combine.cc   |  6 +
 gcc/testsuite/gcc.target/aarch64/bic-1.c | 40 
 2 files changed, 46 insertions(+)

diff --git a/gcc/combine.cc b/gcc/combine.cc
index e1186087dff4..873c2bdd4698 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -5280,6 +5280,12 @@ find_split_point (rtx *loc, rtx_insn *insn, bool set_src)
  SUBST (XEXP (x, 0), XEXP (x, 1));
  SUBST (XEXP (x, 1), tem);
}
+  /* Many targets have a `(and (not X) Y)` and/or `(ior (not X) Y)` 
instructions.
+Split at that insns.  However if this is
+the SET_SRC, we likely do not have such an instruction and it's
+worthless to try this split.  */
+  if (!set_src && GET_CODE (XEXP (x, 0)) == NOT)
+   return loc;
   break;
 
 case PLUS:
diff --git a/gcc/testsuite/gcc.target/aarch64/bic-1.c 
b/gcc/testsuite/gcc.target/aarch64/bic-1.c
new file mode 100644
index ..65e1514755ff
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/bic-1.c
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/* PR rtl-optmization/111949 */
+
+/*
+**func1:
+** bic w([0-9]+), w0, w1
+** and w0, w\1, 1
+**  ret
+*/
+
+unsigned func1(unsigned a, bool b)
+{
+int c = a & b;
+return (c ^ a)&1;
+}
+
+/*
+**func2:
+** bic w([0-9]+), w1, w0
+** and w0, w\1, 255
+**  ret
+*/
+unsigned func2(bool a, bool b)
+{
+  return ~a & b;
+}
+
+/*
+**func3:
+** bic w([0-9]+), w1, w0
+** and w0, w\1, 1
+**  ret
+*/
+bool func3(bool a, unsigned char b)
+{
+  return !a & b;
+}


[gcc r16-38] Fix pr118947-1.c and pr78408-3.c on targets where 32 bytes memcpy uses a vector

2025-04-19 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:52d7676cb4b998521c88691474ed2616226eaa73

commit r16-38-g52d7676cb4b998521c88691474ed2616226eaa73
Author: Andrew Pinski 
Date:   Fri Apr 18 20:28:40 2025 -0700

Fix pr118947-1.c and pr78408-3.c on targets where 32 bytes memcpy uses a 
vector

The problem here is on targets where a 32byte memcpy will use an integral 
(vector) type
to do the copy and the code will be optimized a different way than 
expected. This changes
the testcase instead to use a size of 1025 to make sure there is no target 
that will use an
integral (vector) type for the memcpy and be optimized via the method that 
was just added.

Pushed as obvious after a test run.

gcc/testsuite/ChangeLog:

* gcc.dg/pr118947-1.c: Use 1025 as the size of the buf.
* gcc.dg/pr78408-3.c: Likewise.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/gcc.dg/pr118947-1.c | 4 ++--
 gcc/testsuite/gcc.dg/pr78408-3.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr118947-1.c 
b/gcc/testsuite/gcc.dg/pr118947-1.c
index 70b7f800065c..8733e8d7f5c2 100644
--- a/gcc/testsuite/gcc.dg/pr118947-1.c
+++ b/gcc/testsuite/gcc.dg/pr118947-1.c
@@ -6,10 +6,10 @@
 void* aaa();
 void* bbb()
 {
-char buf[32] = {};
+char buf[1025] = {};
 /*  Tha call to aaa should not matter and clobber buf. */
 void* ret = aaa();
-__builtin_memcpy(ret, buf, 32);
+__builtin_memcpy(ret, buf, sizeof(buf));
 return ret;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr78408-3.c b/gcc/testsuite/gcc.dg/pr78408-3.c
index 3de90d023923..5ea545868ad9 100644
--- a/gcc/testsuite/gcc.dg/pr78408-3.c
+++ b/gcc/testsuite/gcc.dg/pr78408-3.c
@@ -7,8 +7,8 @@ void* aaa();
 void* bbb()
 {
 void* ret = aaa();
-char buf[32] = {};
-__builtin_memcpy(ret, buf, 32);
+char buf[1025] = {};
+__builtin_memcpy(ret, buf, sizeof(buf));
 return ret;
 }


[gcc r16-42] Disable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]

2025-04-19 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:79d2c3089f480738613b7d338d86d8be710f8158

commit r16-42-g79d2c3089f480738613b7d338d86d8be710f8158
Author: Thomas Schwinge 
Date:   Sat Apr 19 15:49:34 2025 +0200

Disable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]

..., using the standard idiom.  This '*.exp' file doesn't adhere to the
parallel testing protocol as defined in 'gcc/testsuite/lib/gcc-defs.exp'.

This also restores proper behavior for '*.exp' files executing after (!) 
this
one, which erroneously caused hundreds or even thousands of individual test
cases get duplicated vs. skipped, randomly, depending on the '-jN' level.

PR testsuite/119508
gcc/testsuite/
* rust/compile/nr2/compile.exp: Disable parallel testing.

Diff:
---
 gcc/testsuite/rust/compile/nr2/compile.exp | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/gcc/testsuite/rust/compile/nr2/compile.exp 
b/gcc/testsuite/rust/compile/nr2/compile.exp
index 4d91dd004a3d..9e15cdd7253a 100644
--- a/gcc/testsuite/rust/compile/nr2/compile.exp
+++ b/gcc/testsuite/rust/compile/nr2/compile.exp
@@ -19,6 +19,15 @@
 # Load support procs.
 load_lib rust-dg.exp
 
+# These tests don't run runtest_file_p consistently if it
+# doesn't return the same values, so disable parallelization
+# of this *.exp file.  The first parallel runtest to reach
+# this will run all the tests serially.
+if ![gcc_parallel_test_run_p compile] {
+return
+}
+gcc_parallel_test_enable 0
+
 # Initialize `dg'.
 dg-init
 
@@ -136,3 +145,5 @@ namespace eval rust-nr2-ns {
 
 # All done.
 dg-finish
+
+gcc_parallel_test_enable 1