[gcc(refs/users/meissner/heads/work165-tar)] Fix tests if -mtar is used.

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:67b9630d3b91aa2cb3d6508a107e54f65f438998

commit 67b9630d3b91aa2cb3d6508a107e54f65f438998
Author: Michael Meissner 
Date:   Tue May 7 01:23:27 2024 -0400

Fix tests if -mtar is used.

2024-05-06  Michael Meissner  

gcc/testsuite/

* gcc.target/powerpc/ppc-switch-1.c: Add support for using the TAR
register.
* gcc.target/powerpc/pr51513.c: Likewise.
* gcc.target/powerpc/safe-indirect-jump-3.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c | 4 ++--
 gcc/testsuite/gcc.target/powerpc/pr51513.c  | 4 ++--
 gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c 
b/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
index eb379a0f67d..7c1031d1b39 100644
--- a/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
@@ -1,8 +1,8 @@
 /* { dg-do compile { target { powerpc*-*-* } } } */
 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
 /* { dg-options "-O2 --param case-values-threshold=2" } */
-/* { dg-final { scan-assembler "mtctr" } } */
-/* { dg-final { scan-assembler "bctr" } } */
+/* { dg-final { scan-assembler "mt\(ctr\|tar\)" } } */
+/* { dg-final { scan-assembler "b\(ctr\|tar\)" } } */
 
 /* Force using a dispatch table even though by default we would generate
ifs.  */
diff --git a/gcc/testsuite/gcc.target/powerpc/pr51513.c 
b/gcc/testsuite/gcc.target/powerpc/pr51513.c
index 1c72a75502a..43c06da8f32 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr51513.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr51513.c
@@ -1,8 +1,8 @@
 /* { dg-do compile { target { powerpc*-*-linux* } } } */
 /* { dg-options "-O2 -fjump-tables --param case-values-threshold=1" } */
 /* Verify we created a jump table.  */
-/* { dg-final { scan-assembler-times "mtctr "  1 } } */
-/* { dg-final { scan-assembler-times "bctr" 1 } } */
+/* { dg-final { scan-assembler-times "mt\(ctr\|tar\) "  1 } } */
+/* { dg-final { scan-assembler-times "b\(ctr\|tar\)" 1 } } */
 /* Verify we eliminated the range check.  */
 /* { dg-final { scan-assembler-not "cmpldi" } } */
 /* { dg-final { scan-assembler-not "cmplwi" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c 
b/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
index 87881fb18fc..f61a4dbfad8 100644
--- a/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
+++ b/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
@@ -47,5 +47,5 @@ int foo (int x)
 }
 
 /* { dg-final { scan-assembler "crset" } } */
-/* { dg-final { scan-assembler "beqctr-" } } */
+/* { dg-final { scan-assembler "beq\(ctr\|tar\)-" } } */
 /* { dg-final { scan-assembler {b \$} } } */


[gcc(refs/users/meissner/heads/work165-tar)] Revert previous changes

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:0934b9b1c8960ae332817767dbf650ccce122edc

commit 0934b9b1c8960ae332817767dbf650ccce122edc
Author: Michael Meissner 
Date:   Mon May 6 23:28:53 2024 -0400

Revert previous changes

Diff:
---
 gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c | 4 ++--
 gcc/testsuite/gcc.target/powerpc/pr51513.c  | 4 ++--
 gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c 
b/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
index f9145ad6345..eb379a0f67d 100644
--- a/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
@@ -1,8 +1,8 @@
 /* { dg-do compile { target { powerpc*-*-* } } } */
 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
 /* { dg-options "-O2 --param case-values-threshold=2" } */
-/* { dg-final { scan-assembler {\mmtctr\M\|\mmttar\M} } } */
-/* { dg-final { scan-assembler {\mbctr\M\|\mbtar\M} } } */
+/* { dg-final { scan-assembler "mtctr" } } */
+/* { dg-final { scan-assembler "bctr" } } */
 
 /* Force using a dispatch table even though by default we would generate
ifs.  */
diff --git a/gcc/testsuite/gcc.target/powerpc/pr51513.c 
b/gcc/testsuite/gcc.target/powerpc/pr51513.c
index 54fcc261607..1c72a75502a 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr51513.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr51513.c
@@ -1,8 +1,8 @@
 /* { dg-do compile { target { powerpc*-*-linux* } } } */
 /* { dg-options "-O2 -fjump-tables --param case-values-threshold=1" } */
 /* Verify we created a jump table.  */
-/* { dg-final { scan-assembler-times {\mmtctr\M\|\mmttar\M}  1 } } */
-/* { dg-final { scan-assembler-times {\mbctr\M\|\mbtar\M} 1 } } */
+/* { dg-final { scan-assembler-times "mtctr "  1 } } */
+/* { dg-final { scan-assembler-times "bctr" 1 } } */
 /* Verify we eliminated the range check.  */
 /* { dg-final { scan-assembler-not "cmpldi" } } */
 /* { dg-final { scan-assembler-not "cmplwi" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c 
b/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
index 5dabd2e2ba7..87881fb18fc 100644
--- a/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
+++ b/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
@@ -47,5 +47,5 @@ int foo (int x)
 }
 
 /* { dg-final { scan-assembler "crset" } } */
-/* { dg-final { scan-assembler {\mbeqctr-\M\|\mbeqtar-\M} } } */
+/* { dg-final { scan-assembler "beqctr-" } } */
 /* { dg-final { scan-assembler {b \$} } } */


[gcc(refs/users/meissner/heads/work165-tar)] Update ChangeLog.*

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:8bc4ba55725be85840e1ca20a614aa9baefc58b4

commit 8bc4ba55725be85840e1ca20a614aa9baefc58b4
Author: Michael Meissner 
Date:   Mon May 6 22:09:56 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.tar | 13 +
 1 file changed, 13 insertions(+)

diff --git a/gcc/ChangeLog.tar b/gcc/ChangeLog.tar
index 5083f34c4cf..0004ea7551f 100644
--- a/gcc/ChangeLog.tar
+++ b/gcc/ChangeLog.tar
@@ -1,3 +1,16 @@
+ Branch work165-tar, patch #201 
+
+Fix tests if -mtar is used.
+
+2024-05-06  Michael Meissner  
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/ppc-switch-1.c: Add support for using the TAR
+   register.
+   * gcc.target/powerpc/pr51513.c: Likewise.
+   * gcc.target/powerpc/safe-indirect-jump-3.c: Likewise.
+
  Branch work165-tar, patch #200 
 
 Add support for -mtar


[gcc(refs/users/meissner/heads/work165-tar)] Fix tests if -mtar is used.

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:7c3aaafbcbe1784f226ba49ac143493295c35c03

commit 7c3aaafbcbe1784f226ba49ac143493295c35c03
Author: Michael Meissner 
Date:   Mon May 6 22:09:09 2024 -0400

Fix tests if -mtar is used.

2024-05-06  Michael Meissner  

gcc/testsuite/

* gcc.target/powerpc/ppc-switch-1.c: Add support for using the TAR
register.
* gcc.target/powerpc/pr51513.c: Likewise.
* gcc.target/powerpc/safe-indirect-jump-3.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c | 4 ++--
 gcc/testsuite/gcc.target/powerpc/pr51513.c  | 4 ++--
 gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c 
b/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
index eb379a0f67d..f9145ad6345 100644
--- a/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
+++ b/gcc/testsuite/gcc.target/powerpc/ppc-switch-1.c
@@ -1,8 +1,8 @@
 /* { dg-do compile { target { powerpc*-*-* } } } */
 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
 /* { dg-options "-O2 --param case-values-threshold=2" } */
-/* { dg-final { scan-assembler "mtctr" } } */
-/* { dg-final { scan-assembler "bctr" } } */
+/* { dg-final { scan-assembler {\mmtctr\M\|\mmttar\M} } } */
+/* { dg-final { scan-assembler {\mbctr\M\|\mbtar\M} } } */
 
 /* Force using a dispatch table even though by default we would generate
ifs.  */
diff --git a/gcc/testsuite/gcc.target/powerpc/pr51513.c 
b/gcc/testsuite/gcc.target/powerpc/pr51513.c
index 1c72a75502a..54fcc261607 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr51513.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr51513.c
@@ -1,8 +1,8 @@
 /* { dg-do compile { target { powerpc*-*-linux* } } } */
 /* { dg-options "-O2 -fjump-tables --param case-values-threshold=1" } */
 /* Verify we created a jump table.  */
-/* { dg-final { scan-assembler-times "mtctr "  1 } } */
-/* { dg-final { scan-assembler-times "bctr" 1 } } */
+/* { dg-final { scan-assembler-times {\mmtctr\M\|\mmttar\M}  1 } } */
+/* { dg-final { scan-assembler-times {\mbctr\M\|\mbtar\M} 1 } } */
 /* Verify we eliminated the range check.  */
 /* { dg-final { scan-assembler-not "cmpldi" } } */
 /* { dg-final { scan-assembler-not "cmplwi" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c 
b/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
index 87881fb18fc..5dabd2e2ba7 100644
--- a/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
+++ b/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-3.c
@@ -47,5 +47,5 @@ int foo (int x)
 }
 
 /* { dg-final { scan-assembler "crset" } } */
-/* { dg-final { scan-assembler "beqctr-" } } */
+/* { dg-final { scan-assembler {\mbeqctr-\M\|\mbeqtar-\M} } } */
 /* { dg-final { scan-assembler {b \$} } } */


[gcc r15-221] c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954]

2024-05-06 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:0c43c673b0d431ca02d83bf6fae9cd60e9a3d0a8

commit r15-221-g0c43c673b0d431ca02d83bf6fae9cd60e9a3d0a8
Author: Nathaniel Shead 
Date:   Mon May 6 13:05:52 2024 +1000

c++: Allow IS_FAKE_BASE_TYPE for union types [PR114954]

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 
Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/cp-tree.h|  2 +-
 gcc/testsuite/g++.dg/modules/pr114954.C | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 4fadc9aaf48..db098c32f2d 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 000..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 
+union U {
+private:
+  char a[N + 1];
+  int b;
+};
+
+U<4> p;


[gcc r15-220] c++/modules: Fix dangling pointer with imported_temploid_friends

2024-05-06 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:ec2365e07537e8b17745d75c28a2b45bf33be119

commit r15-220-gec2365e07537e8b17745d75c28a2b45bf33be119
Author: Nathaniel Shead 
Date:   Fri May 3 19:36:17 2024 +1000

c++/modules: Fix dangling pointer with imported_temploid_friends

I got notified by Linaro CI and by checking testresults that there seems
to be some occasional failures in tpl-friend-4_b.C on some architectures
and standards modes since r15-59-gb5f6a56940e708.  I haven't been able
to reproduce but looking at the backtrace I suspect the issue is that
we're adding to the 'imported_temploid_friend' map a decl that is
ultimately discarded, which then has its address reused by a later decl
causing a failure in the assert in 'set_originating_module'.

This patch fixes the problem by ensuring 'imported_temploid_friends' is
correctly marked as a GTY root, and that 'duplicate_decls' properly
removes entries from the map for declarations that it frees.

PR c++/114275

gcc/cp/ChangeLog:

* cp-tree.h (remove_defining_module): Declare.
* decl.cc (duplicate_decls): Call remove_defining_module on
to-be-freed newdecl.
* module.cc (imported_temploid_friends): Mark as GTY root...
(init_modules): ...and allocate from ggc.
(trees_in::decl_value): Only track for declarations that won't
be discarded.
(remove_defining_module): New function.

Signed-off-by: Nathaniel Shead 
Reviewed-by: Jason Merrill 
Reviewed-by: Patrick Palka 

Diff:
---
 gcc/cp/cp-tree.h |  1 +
 gcc/cp/decl.cc   |  4 
 gcc/cp/module.cc | 19 ---
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 52d6841559c..4fadc9aaf48 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7420,6 +7420,7 @@ extern void set_instantiating_module (tree);
 extern void set_defining_module (tree);
 extern void maybe_key_decl (tree ctx, tree decl);
 extern void propagate_defining_module (tree decl, tree orig);
+extern void remove_defining_module (tree decl);
 
 extern void mangle_module (int m, bool include_partition);
 extern void mangle_module_fini ();
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 04a151c341c..b112b70659f 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -3340,6 +3340,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
hiding, bool was_hidden)
   if (flag_concepts)
 remove_constraints (newdecl);
 
+  /* And similarly for any module tracking data.  */
+  if (modules_p ())
+remove_defining_module (newdecl);
+
   ggc_free (newdecl);
 
   return olddecl;
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 44dc81eed3e..520dd710549 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2731,7 +2731,7 @@ static keyed_map_t *keyed_table;
need to be attached to the same module as the temploid.  This maps
these decls to the temploid they are instantiated them, as there is
no other easy way to get this information.  */
-static hash_map *imported_temploid_friends;
+static GTY((cache)) decl_tree_cache_map *imported_temploid_friends;
 
 //
 /* Tree streaming.   The tree streaming is very specific to the tree
@@ -8327,7 +8327,8 @@ trees_in::decl_value ()
   if (TREE_CODE (inner) == FUNCTION_DECL
   || TREE_CODE (inner) == TYPE_DECL)
 if (tree owner = tree_node ())
-  imported_temploid_friends->put (decl, owner);
+  if (is_new)
+   imported_temploid_friends->put (decl, owner);
 
   /* Regular typedefs will have a NULL TREE_TYPE at this point.  */
   unsigned tdef_flags = 0;
@@ -19336,6 +19337,18 @@ propagate_defining_module (tree decl, tree orig)
 }
 }
 
+/* DECL is being freed, clear data we don't need anymore.  */
+
+void
+remove_defining_module (tree decl)
+{
+  if (!modules_p ())
+return;
+
+  if (imported_temploid_friends)
+imported_temploid_friends->remove (decl);
+}
+
 /* Create the flat name string.  It is simplest to have it handy.  */
 
 void
@@ -20550,7 +20563,7 @@ init_modules (cpp_reader *reader)
   entity_map = new entity_map_t (EXPERIMENT (1, 400));
   vec_safe_reserve (entity_ary, EXPERIMENT (1, 400));
   imported_temploid_friends
-   = new hash_map (EXPERIMENT (1, 400));
+   = decl_tree_cache_map::create_ggc (EXPERIMENT (1, 400));
 }
 
 #if CHECKING_P


[gcc r13-8701] RISC-V: Fix vsetvli local eliminate [PR114747]

2024-05-06 Thread Kito Cheng via Gcc-cvs
https://gcc.gnu.org/g:c4c0b0be87b4e08dab0e5e62c6f38a610a7423e7

commit r13-8701-gc4c0b0be87b4e08dab0e5e62c6f38a610a7423e7
Author: Kito Cheng 
Date:   Mon May 6 23:45:22 2024 +0800

RISC-V: Fix vsetvli local eliminate [PR114747]

vsetvli local eliminate is only consider the current demand instead of
full demand, and it will use that incomplete info to remove vsetvli.

Give following example from PR114747:

vsetvli a5,a1,e8,m4,ta,mu   # 57, ratio=2, sew=8, lmul=4
vsetvli zero,a5,e16,m8,ta,ma# 58, ratio=2, sew=16, lmul=8
vle8.v  v8,0(a0)# 13, demand ratio=2
vzext.vf2   v24,v8  # 14, demand sew=16 and lmul=8

Insn #58 will removed because #57 has satisfied demand of #13, but it's
not consider #14.

It should doing more demand analyze, but this bug only present in GCC 13
branch, and we should not change too much on this release branch, so the 
best
way is make the check more conservative - remove only if the target
vsetvl_discard_result having same SEW and LMUL as the source vsetvli.

gcc/ChangeLog:

PR target/114747
* config/riscv/riscv-vsetvl.cc (local_eliminate_vsetvl_insn):
Check target vsetvl_discard_result and source vsetvli has same
SEW and LMUL.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/vsetvl/pr114747.c: New.

Diff:
---
 gcc/config/riscv/riscv-vsetvl.cc | 10 ++
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114747.c | 18 ++
 2 files changed, 28 insertions(+)

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 587c6975a70..e6606b1e4de 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -1106,6 +1106,16 @@ local_eliminate_vsetvl_insn (const vector_insn_info )
  if (!new_info.skip_avl_compatible_p (dem))
return;
 
+ /* Be more conservative here since we don't really get full
+demand info for following instructions, also that instruction
+isn't exist in RTL-SSA yet so we need parse that by low level
+API rather than vector_insn_info::parse_insn, see PR114747.  */
+ unsigned last_vsetvli_sew = ::get_sew (PREV_INSN (i->rtl ()));
+ unsigned last_vsetvli_lmul = ::get_vlmul (PREV_INSN (i->rtl ()));
+ if (new_info.get_sew() != last_vsetvli_sew ||
+ new_info.get_vlmul() != last_vsetvli_lmul)
+   return;
+
  new_info.set_avl_info (dem.get_avl_info ());
  new_info = dem.merge (new_info, LOCAL_MERGE);
  change_vsetvl_insn (insn, new_info);
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114747.c 
b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114747.c
new file mode 100644
index 000..c478405e8d6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114747.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize 
-fno-schedule-insns -fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+typedef unsigned short char16_t;
+
+size_t convert_latin1_to_utf16le(const char *src, size_t len, char16_t *dst) {
+  char16_t *beg = dst;
+  for (size_t vl; len > 0; len -= vl, src += vl, dst += vl) {
+vl = __riscv_vsetvl_e8m4(len);
+vuint8m4_t v = __riscv_vle8_v_u8m4((uint8_t*)src, vl);
+__riscv_vse16_v_u16m8((uint16_t*)dst, __riscv_vzext_vf2_u16m8(v, vl), vl);
+  }
+  return dst - beg;
+}
+
+/* { dg-final { scan-assembler 
{vsetvli\s+[a-z0-9]+,\s*[a-x0-9]+,\s*e16,\s*m8,\s*t[au],\s*m[au]} } } */


[gcc(refs/vendors/microsoft/heads/main)] Merge commit 'ffb521f157fec823907913602ed5cb73dd1c63e8' into merge-master-ffb521f157fec823907913602e

2024-05-06 Thread Eugene Rozenfeld via Gcc-cvs
https://gcc.gnu.org/g:da1eddccf7ec1836d0a00a5cc09e945d90e3de95

commit da1eddccf7ec1836d0a00a5cc09e945d90e3de95
Merge: 012850a7800 ffb521f157f
Author: MS Automation 
Date:   Sun May 5 13:29:43 2024 +

Merge commit 'ffb521f157fec823907913602ed5cb73dd1c63e8' into 
merge-master-ffb521f157fec823907913602ed5cb73dd1c63e8-2024-05-05T13-29-40

Diff:

 contrib/ChangeLog  | 5 +
 contrib/gcc-changelog/git_update_version.py| 4 +-
 gcc/BASE-VER   | 2 +-
 gcc/ChangeLog  |  1124 ++
 gcc/DATESTAMP  | 2 +-
 gcc/ada/ChangeLog  | 4 +
 gcc/ada/gnatvsn.ads| 2 +-
 gcc/analyzer/ChangeLog |31 +
 gcc/analyzer/analyzer.cc   |15 +-
 gcc/analyzer/analyzer.h| 4 +-
 gcc/analyzer/engine.cc | 2 +-
 gcc/analyzer/kf.cc |22 +
 gcc/analyzer/known-function-manager.cc |38 +-
 gcc/analyzer/known-function-manager.h  | 5 +
 gcc/analyzer/sm-file.cc| 8 +
 gcc/analyzer/sm-malloc.cc  | 1 +
 gcc/analyzer/sm-signal.cc  |11 +-
 gcc/bitmap.cc  | 5 +-
 gcc/c-family/ChangeLog |22 +
 gcc/c-family/c-attribs.cc  | 2 +-
 gcc/c-family/c-cppbuiltin.cc   | 5 +-
 gcc/c-family/c.opt | 2 +-
 gcc/c/ChangeLog| 5 +
 gcc/c/gimple-parser.cc |35 +
 gcc/cfgexpand.cc   |57 +-
 gcc/cfgrtl.cc  | 3 +-
 gcc/common.opt | 6 +
 gcc/common/config/i386/i386-common.cc  | 2 +-
 gcc/common/config/riscv/riscv-common.cc| 8 +-
 gcc/config.gcc |42 +-
 gcc/config/aarch64/aarch64-ldp-fusion.cc   | 8 -
 gcc/config/aarch64/aarch64-ldpstp.md   | 8 +-
 gcc/config/aarch64/aarch64-tuning-flags.def| 3 -
 gcc/config/aarch64/aarch64.cc  |   199 +-
 gcc/config/aarch64/tuning_models/emag.h| 2 +-
 gcc/config/aarch64/tuning_models/xgene1.h  | 2 +-
 gcc/config/arm/arm.cc  |69 +
 gcc/config/bpf/bpf-c.cc|88 +
 gcc/config/bpf/bpf.cc  |24 +-
 gcc/config/bpf/bpf.h   | 9 +-
 gcc/config/bpf/bpf.opt | 2 +-
 gcc/config/bpf/t-bpf   | 4 +
 gcc/config/darwin.opt  | 2 +-
 gcc/config/epiphany/epiphany.opt   | 2 +-
 gcc/config/gcn/gcn-hsa.h   | 2 +-
 gcc/config/gcn/gcn-opts.h  | 2 +
 gcc/config/gcn/gcn.cc  | 8 +
 gcc/config/gcn/gcn.h   | 2 +
 gcc/config/gcn/gcn.opt | 3 +
 gcc/config/gcn/mkoffload.cc| 9 +
 gcc/config/gcn/t-omp-device| 2 +-
 gcc/config/i386/i386-options.cc| 1 +
 gcc/config/i386/i386.md|25 +-
 gcc/config/loongarch/genopts/gen-evolution.awk |   230 +
 gcc/config/loongarch/genopts/genstr.sh |82 +-
 gcc/config/loongarch/genopts/isa-evolution.in  |10 +-
 gcc/config/loongarch/genopts/loongarch-strings | 5 +-
 gcc/config/loongarch/genopts/loongarch.opt.in  |43 +-
 gcc/config/loongarch/loongarch-c.cc|60 +-
 gcc/config/loongarch/loongarch-cpu.cc  |37 +-
 gcc/config/loongarch/loongarch-def.cc  |83 +-
 gcc/config/loongarch/loongarch-def.h   |37 +-
 gcc/config/loongarch/loongarch-driver.cc   | 8 +-
 gcc/config/loongarch/loongarch-evolution.cc|60 +
 ...oongarch-cpucfg-map.h => loongarch-evolution.h} |46 +-
 gcc/config/loongarch/loongarch-opts.cc |66 +-
 gcc/config/loongarch/loongarch-opts.h  |15 +-
 gcc/config/loongarch/loongarch-str.h   | 5 +-
 gcc/config/loongarch/loongarch.cc  |11 +-
 gcc/config/loongarch/loongarch.h   | 1 +
 gcc/config/loongarch/loongarch.md  |16 +-
 gcc/config/loongarch/loongarch.opt |43 +-
 gcc/config/loongarch/t-loongarch   |26 +-
 gcc/config/mips/i6400.md   | 6 +
 

[gcc/microsoft/heads/main] (249 commits) Merge commit 'ffb521f157fec823907913602ed5cb73dd1c63e8' int

2024-05-06 Thread Eugene Rozenfeld via Gcc-cvs
The branch 'microsoft/heads/main' was updated to point to:

 da1eddccf7e... Merge commit 'ffb521f157fec823907913602ed5cb73dd1c63e8' int

It previously pointed to:

 012850a7800... Merge commit 'ef2392236ec629351496d7f299d6a0956080e4d9' int

Diff:

Summary of changes (added commits):
---

  da1eddc... Merge commit 'ffb521f157fec823907913602ed5cb73dd1c63e8' int
  ffb521f... Remove m_nloops field from loop_versioning (*)
  fda7419... Daily bump. (*)
  6cec31d... Add prange entries in gimple-range-op.cc. (*)
  ff306c7... Implement operator_ge for prange (*)
  76fae40... Implement operator_gt for prange. (*)
  3a4ee6e... Implement operator_le for prange. (*)
  bfa2323... Implement operator_lt for prange. (*)
  bcb2269... Implement operator_equal for prange. (*)
  d1be4c9... Implement operator_not_equal for prange. (*)
  6b9e640... Implement operator_bitwise_or for prange. (*)
  e58f149... Implement operator_bitwise_and for prange. (*)
  f803b93... Implement operator_pointer_diff for prange. (*)
  86ff3c4... Implement pointer_plus_operator for prange. (*)
  54d3fd6... Implement operator_addr_expr for prange. (*)
  1a4f5d4... Implement operator_min and operator_max for prange. (*)
  95fce0d... Implement operator_cast for prange. (*)
  a91fd7b... Implement operator_cst for prange. (*)
  e7b6e96... Implement operator_identity for prange. (*)
  31377ee... Implement range-op dispatch for prange. (*)
  ddf039a... Add prange implementation for get_legacy_range. (*)
  7c1b136... Add hashing support for prange. (*)
  f859996... Add storage support for prange. (*)
  a7f1285... Add streaming support for prange. (*)
  64993a8... Implement basic prange class. (*)
  f589196... Minimal prange class showing inlining degradation to VRP. (*)
  3e3d115... Daily bump. (*)
  b69dac5... libbacktrace: add DLLS as they are loaded (*)
  04f24e4... Fix printing COMPOUND_EXPR in .original [PR23872] (*)
  8f3afb8... c++: initializer_list and EH [PR114935] (*)
  c943d7b... PR modula2/114929 extra for loop iteration count regression (*)
  cb5d904... c++: Implement __is_pointer built-in trait (*)
  9b51b3e... c++: Implement __is_volatile built-in trait (*)
  7dd8c90... c++: Implement __is_const built-in trait (*)
  467ca4a... RISC-V: miscll comment fixes [NFC] (*)
  301b954... docs: rtl: document GET_MODE_INNER (*)
  5219414... testsuite: fix analyzer C++ failures on Solaris [PR111475] (*)
  a2e9032... Add default bitmap obstack allocation check (*)
  c5245c8... Silence two instances of -Wcalloc-transposed-args (*)
  212d93f... libstdc++: Update powerpc-linux-gnu baseline_symbols (*)
  7a212ac... Avoid changing type in the type_hash_canon hash (*)
  fe40d52... cfgrtl: Fix MEM_EXPR update in duplicate_insn_chain [PR1149 (*)
  7117e1f... tree-inline: Add __builtin_stack_{save,restore} pair about  (*)
  87e35da... tree-optimization/114921 - _Float16 -> __bf16 isn't noop (*)
  f04dc89... c++: remove lookup_template_class's entering_scope flag (*)
  a561dc0... PR modula2/114929 for loop fails to iterate down to zero wh (*)
  f2d0116... Daily bump. (*)
  8367c99... [committed][RISC-V] Fix nearbyint failure on rv32 and forma (*)
  affd24b... libgfortran: Fix up the autoreconf warnings (*)
  9b54bea... [RFA][RISC-V] Improve constant synthesis for constants with (*)
  bd010e9... Regenerate gcc.pot (*)
  ff4dc8b... RISC-V: Add testcase for pr114734 (*)
  1e29da0... [committed] [RISC-V] Don't run new rounding tests on newlib (*)
  7317d62... c++: Clear is_unbraced_* when parsing declaration_seq_opt [ (*)
  67e66c9... modula2: Regenerate libgm2 Makefile.ins using correct inclu (*)
  bf33fe9... Improve SLP dump and graph (*)
  9b5c0be... Objective-C, NeXT, v2: Correct a regression in code-gen. (*)
  43dc430... PR modula2/113836 gm2 does not dump gimple or quadruples to (*)
  4bb21b5... fix single argument static_assert (*)
  a704554... lto-wrapper: Truncate files using -truncate driver option [ (*)
  985b5a9... Driver: Add new -truncate option (*)
  5eb25d1... libgomp: Add gfx90c, 1036 and 1103 declare variant tests (*)
  2f15787... c++: Implement C++26 P2573R2 - = delete("should have a reas (*)
  c59708f... Make graph dumps use graphviz format (*)
  5176402... Remove live-info global bitmap (*)
  66f49cc... s390: testsuite: Fix risbg-ll-2.c (*)
  02917ac... c++: Don't emit unused GMF partial specializations [PR11463 (*)
  6c4a745... s390: testsuite: Fix zero_bits_compound-1.c (*)
  bbe8359... middle-end/114579 - speed up add_scope_conflicts (*)
  ad30265... c++: Implement modules ABI for vtable emissions (*)
  fd48e67... Daily bump. (*)
  ff98aab... doc: Describe limitations re Ada, D, and Go on FreeBSD (*)
  a12cae9... c++: drop in-charge for dtors without vbases (*)
  76ca6e1... [committed] [RISC-V] Trivial pattern cleanup (*)
  fad93e7... [committed] [RISC-V] Fix detection of store pair fusion cas (*)
  1fbe1a5... libstdc++: Guard uses of is_pointer_interconvertible_v [PR1 (*)
  c3bc278... c++: const void* memchr 

[gcc r15-218] [PATCH 1/1] RISC-V: Add Zfbfmin extension to the -march= option

2024-05-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:35224ead63732a3550ba4b1332c06e9dc7999c31

commit r15-218-g35224ead63732a3550ba4b1332c06e9dc7999c31
Author: Xiao Zeng 
Date:   Mon May 6 15:57:37 2024 -0600

[PATCH 1/1] RISC-V: Add Zfbfmin extension to the -march= option

This patch would like to add new sub extension (aka Zfbfmin) to the
-march= option. It introduces a new data type BF16.

1 The Zfbfmin extension depend on 'F', and the FLH, FSH, FMV.X.H, and
FMV.H.X instructions as defined in the Zfh extension.

2 The Zfhmin extension includes the following instructions from the
Zfh extension: FLH, FSH, FMV.X.H, FMV.H.X, FCVT.S.H, and FCVT.H.S.

3 Zfhmin extension depend on 'F'.

4 Simply put, just make Zfbfmin dependent on Zfhmin.

Perhaps in the future, we could propose making the FLH, FSH, FMV.X.H, and
FMV.H.X instructions an independent extension to achieve precise dependency
relationships for the Zfbfmin.

You can locate more information about Zfbfmin from below spec doc.




gcc/
* common/config/riscv/riscv-common.cc (riscv_implied_info): zfbfmin
implies zfhmin.
(riscv_ext_version_table, riscv_ext_flag_table): Add zfbfmin.
* config/riscv/riscv.opt (ZFBFMIN): Add optoion.

gcc/testsuite/
* gcc.target/riscv/arch-35.c: New test.
* gcc.target/riscv/arch-36.c: New test.
* gcc.target/riscv/predef-34.c: New test.
* gcc.target/riscv/predef-35.c: New test.

Diff:
---
 gcc/common/config/riscv/riscv-common.cc|  3 ++
 gcc/config/riscv/riscv.opt |  2 ++
 gcc/testsuite/gcc.target/riscv/arch-35.c   |  5 
 gcc/testsuite/gcc.target/riscv/arch-36.c   |  5 
 gcc/testsuite/gcc.target/riscv/predef-34.c | 47 ++
 gcc/testsuite/gcc.target/riscv/predef-35.c | 47 ++
 6 files changed, 109 insertions(+)

diff --git a/gcc/common/config/riscv/riscv-common.cc 
b/gcc/common/config/riscv/riscv-common.cc
index 8cc0e727737..fb76017ffbc 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -155,6 +155,7 @@ static const riscv_implied_info_t riscv_implied_info[] =
   {"zvksed", "zve32x"},
   {"zvksh",  "zve32x"},
 
+  {"zfbfmin", "zfhmin"},
   {"zfh", "zfhmin"},
   {"zfhmin", "f"},
 
@@ -331,6 +332,7 @@ static const struct riscv_ext_version 
riscv_ext_version_table[] =
   {"zvl32768b", ISA_SPEC_CLASS_NONE, 1, 0},
   {"zvl65536b", ISA_SPEC_CLASS_NONE, 1, 0},
 
+  {"zfbfmin",   ISA_SPEC_CLASS_NONE, 1, 0},
   {"zfh",   ISA_SPEC_CLASS_NONE, 1, 0},
   {"zfhmin",ISA_SPEC_CLASS_NONE, 1, 0},
   {"zvfbfmin",  ISA_SPEC_CLASS_NONE, 1, 0},
@@ -1698,6 +1700,7 @@ static const riscv_ext_flag_table_t 
riscv_ext_flag_table[] =
   {"zvl32768b", _options::x_riscv_zvl_flags, MASK_ZVL32768B},
   {"zvl65536b", _options::x_riscv_zvl_flags, MASK_ZVL65536B},
 
+  {"zfbfmin",   _options::x_riscv_zf_subext, MASK_ZFBFMIN},
   {"zfhmin",_options::x_riscv_zf_subext, MASK_ZFHMIN},
   {"zfh",   _options::x_riscv_zf_subext, MASK_ZFH},
   {"zvfbfmin",  _options::x_riscv_zf_subext, MASK_ZVFBFMIN},
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index ee824756381..7cca1c4aab2 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -393,6 +393,8 @@ Mask(ZIC64B) Var(riscv_zicmo_subext)
 TargetVariable
 int riscv_zf_subext
 
+Mask(ZFBFMIN)  Var(riscv_zf_subext)
+
 Mask(ZFHMIN)  Var(riscv_zf_subext)
 
 Mask(ZFH) Var(riscv_zf_subext)
diff --git a/gcc/testsuite/gcc.target/riscv/arch-35.c 
b/gcc/testsuite/gcc.target/riscv/arch-35.c
new file mode 100644
index 000..6c783769666
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-35.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32i_zfbfmin -mabi=ilp32f" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/arch-36.c 
b/gcc/testsuite/gcc.target/riscv/arch-36.c
new file mode 100644
index 000..cbdccf12807
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/arch-36.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64i_zfbfmin -mabi=lp64f" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/riscv/predef-34.c 
b/gcc/testsuite/gcc.target/riscv/predef-34.c
new file mode 100644
index 000..0a993271f7f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/predef-34.c
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32i_zfbfmin -mabi=ilp32f -mcmodel=medlow 
-misa-spec=20191213" } */
+
+int main () {
+
+#ifndef __riscv_arch_test
+#error "__riscv_arch_test"
+#endif
+
+#if __riscv_xlen != 32
+#error "__riscv_xlen"
+#endif
+
+#if !defined(__riscv_i)
+#error "__riscv_i"
+#endif
+
+#if !defined(__riscv_f)
+#error "__riscv_f"
+#endif
+
+#if !defined(__riscv_zfhmin)

[gcc r15-217] aix: Fix building fat library for AIX

2024-05-06 Thread David Edelsohn via Gcc-cvs
https://gcc.gnu.org/g:f62e55a7d0aa03886227672272852926291c7f27

commit r15-217-gf62e55a7d0aa03886227672272852926291c7f27
Author: David Edelsohn 
Date:   Sun May 5 16:17:51 2024 -0400

aix: Fix building fat library for AIX

With the change in subdirectories, the code for libgfortran fat libraries
needs to be adjusted to explicitly reference the subdirectory.  AIX
creates fat library archives and the compiler itself can be built as
either 32 bit or 64 bit application and default code generation.  For
the two, alternate versions of the compiler to interoperate, GCC needs
to construct the fat libraries manually.

The Makefile fragment had been trying to leverage as much of the existing
targets and macros as possible.  With the subdirectory change, the
location of single.o is more obscured and cannot be determined without
libtool.  This patch references the location of the real object file
more explicitly.

Utilizing subst seems like overkill and unnecessary obscuration for a single
object file.  Either way, it's digging below the libtool abstraction layer.

This also fixes Fortran bootstrap on AIX.

Bootstrapped on powerpc-ibm-aix7.3.0.0

libgfortran/ChangeLog:

* config/t-aix (all-local, libcaf_single): Explicitly reference
caf/.libs/single.o

Signed-off-by: David Edelsohn 

Diff:
---
 libgfortran/config/t-aix | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgfortran/config/t-aix b/libgfortran/config/t-aix
index 0e50501d10e..099fc5d8b3a 100644
--- a/libgfortran/config/t-aix
+++ b/libgfortran/config/t-aix
@@ -7,6 +7,6 @@ ARX=$(shell echo $(AR) | sed -e 's/-X[^ ]*//g')
 all-local:
$(ARX) -X$(BITS) rc .libs/$(PACKAGE).a 
../ppc$(BITS)/$(PACKAGE)/.libs/$(PACKAGE).so.$(MAJOR)
$(ARX) -X$(BITS) rc ../pthread/$(PACKAGE)/.libs/$(PACKAGE).a 
../pthread/ppc$(BITS)/$(PACKAGE)/.libs/$(PACKAGE).so.$(MAJOR)
-   $(ARX) -X$(BITS) rc .libs/libcaf_single.a 
../ppc$(BITS)/$(PACKAGE)/.libs/$(libcaf_single_la_OBJECTS:.lo=.o)
-   $(ARX) -X$(BITS) rc ../pthread/$(PACKAGE)/.libs/libcaf_single.a 
../pthread/ppc$(BITS)/$(PACKAGE)/.libs/$(libcaf_single_la_OBJECTS:.lo=.o)
+   $(ARX) -X$(BITS) rc .libs/libcaf_single.a 
../ppc$(BITS)/$(PACKAGE)/caf/.libs/single.o
+   $(ARX) -X$(BITS) rc ../pthread/$(PACKAGE)/.libs/libcaf_single.a 
../pthread/ppc$(BITS)/$(PACKAGE)/caf/.libs/single.o
 endif


[gcc r15-216] RISC-V: Add testcase for PR114749.

2024-05-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:4b1f128d4c25713116c7d9fd37016f7d9a112959

commit r15-216-g4b1f128d4c25713116c7d9fd37016f7d9a112959
Author: Robin Dapp 
Date:   Mon May 6 15:51:37 2024 -0600

RISC-V: Add testcase for PR114749.

this adds a test case for PR114749.
Going to commit as obvious unless somebody complains.

Regards
 Robin

gcc/testsuite/ChangeLog:

PR tree-optimization/114749

* gcc.target/riscv/rvv/autovec/pr114749.c: New test.

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c
new file mode 100644
index 000..6733b0481a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114749.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv_zvl128b -mabi=lp64d -fwhole-program -O3 
-mrvv-vector-bits=zvl" } */
+
+extern int a[];
+extern char b[];
+int c = 24;
+_Bool d[24][24][24];
+_Bool (*e)[24][24] = d;
+int main() {
+  for (short f = 0; f < 24; f += 3)
+for (unsigned g = 0; g < (char)c; g += 2) {
+  a[f] = 0;
+  b[g] |= ({ e[f][f][f]; });
+}
+}


[gcc r15-215] [RISC-V] Add support for _Bfloat16

2024-05-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:8c7cee80eb50792e57d514be1418c453ddd1073e

commit r15-215-g8c7cee80eb50792e57d514be1418c453ddd1073e
Author: Xiao Zeng 
Date:   Mon May 6 15:39:12 2024 -0600

[RISC-V] Add support for _Bfloat16

1 At point ,
  BF16 has already been completed "post public review".

2 LLVM has also added support for RISCV BF16 in
   and
  .

3 According to the discussion 
,
  this use __bf16 and use DF16b in riscv_mangle_type like x86.

Below test are passed for this patch
* The riscv fully regression test.

gcc/ChangeLog:

* config/riscv/iterators.md: New mode iterator HFBF.
* config/riscv/riscv-builtins.cc (riscv_init_builtin_types):
Initialize data type _Bfloat16.
* config/riscv/riscv-modes.def (FLOAT_MODE): New.
(ADJUST_FLOAT_FORMAT): New.
* config/riscv/riscv.cc (riscv_mangle_type): Support for BFmode.
(riscv_scalar_mode_supported_p): Ditto.
(riscv_libgcc_floating_mode_supported_p): Ditto.
(riscv_init_libfuncs): Set the conversion method for BFmode and
HFmode.
(riscv_block_arith_comp_libfuncs_for_mode): Set the arithmetic
and comparison libfuncs for the mode.
* config/riscv/riscv.md (mode" ): Add BF.
(movhf): Support for BFmode.
(mov): Ditto.
(*movhf_softfloat): Ditto.
(*mov_softfloat): Ditto.

libgcc/ChangeLog:

* config/riscv/sfp-machine.h (_FP_NANFRAC_B): New.
(_FP_NANSIGN_B): Ditto.
* config/riscv/t-softfp32: Add support for BF16 libfuncs.
* config/riscv/t-softfp64: Ditto.
* soft-fp/floatsibf.c: For si -> bf16.
* soft-fp/floatunsibf.c: For unsi -> bf16.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/bf16_arithmetic.c: New test.
* gcc.target/riscv/bf16_call.c: New test.
* gcc.target/riscv/bf16_comparison.c: New test.
* gcc.target/riscv/bf16_float_libcall_convert.c: New test.
* gcc.target/riscv/bf16_integer_libcall_convert.c: New test.

Co-authored-by: Jin Ma 

Diff:
---
 gcc/config/riscv/iterators.md  |  2 +
 gcc/config/riscv/riscv-builtins.cc | 16 +
 gcc/config/riscv/riscv-modes.def   |  3 +
 gcc/config/riscv/riscv.cc  | 64 +++--
 gcc/config/riscv/riscv.md  | 24 +++
 gcc/testsuite/gcc.target/riscv/bf16_arithmetic.c   | 42 +++
 gcc/testsuite/gcc.target/riscv/bf16_call.c | 12 
 gcc/testsuite/gcc.target/riscv/bf16_comparison.c   | 36 ++
 .../gcc.target/riscv/bf16_float_libcall_convert.c  | 57 +++
 .../riscv/bf16_integer_libcall_convert.c   | 81 ++
 libgcc/config/riscv/sfp-machine.h  |  3 +
 libgcc/config/riscv/t-softfp32 | 10 ++-
 libgcc/config/riscv/t-softfp64 |  3 +-
 libgcc/soft-fp/floatsibf.c | 45 
 libgcc/soft-fp/floatunsibf.c   | 45 
 15 files changed, 407 insertions(+), 36 deletions(-)

diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
index 75e119e407a..32e1b140305 100644
--- a/gcc/config/riscv/iterators.md
+++ b/gcc/config/riscv/iterators.md
@@ -75,6 +75,8 @@
 ;; Iterator for floating-point modes that can be loaded into X registers.
 (define_mode_iterator SOFTF [SF (DF "TARGET_64BIT") (HF "TARGET_ZFHMIN")])
 
+;; Iterator for floating-point modes of BF16
+(define_mode_iterator HFBF [HF BF])
 
 ;; ---
 ;; Mode attributes
diff --git a/gcc/config/riscv/riscv-builtins.cc 
b/gcc/config/riscv/riscv-builtins.cc
index d457e306dd1..4c08834288a 100644
--- a/gcc/config/riscv/riscv-builtins.cc
+++ b/gcc/config/riscv/riscv-builtins.cc
@@ -230,6 +230,7 @@ static GTY(()) int riscv_builtin_decl_index[NUM_INSN_CODES];
   riscv_builtin_decls[riscv_builtin_decl_index[(CODE)]]
 
 tree riscv_float16_type_node = NULL_TREE;
+tree riscv_bfloat16_type_node = NULL_TREE;
 
 /* Return the function type associated with function prototype TYPE.  */
 
@@ -273,6 +274,21 @@ riscv_init_builtin_types (void)
   if (!maybe_get_identifier ("_Float16"))
 lang_hooks.types.register_builtin_type (riscv_float16_type_node,
"_Float16");
+
+  /* Provide the _Bfloat16 type and bfloat16_type_node if needed.  */
+  if (!bfloat16_type_node)
+{
+  riscv_bfloat16_type_node = make_node (REAL_TYPE);
+  TYPE_PRECISION (riscv_bfloat16_type_node) = 16;
+  SET_TYPE_MODE 

[gcc r15-214] RISC-V: Document -mcmodel=large

2024-05-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:6ffea3e37380860507cce08af42a997fbdb5d754

commit r15-214-g6ffea3e37380860507cce08af42a997fbdb5d754
Author: Palmer Dabbelt 
Date:   Mon May 6 15:34:26 2024 -0600

RISC-V: Document -mcmodel=large

  This slipped through the cracks.  Probably also NEWS-worthy.

gcc/ChangeLog:

* doc/invoke.texi (RISC-V): Add -mcmodel=large.

Diff:
---
 gcc/doc/invoke.texi | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9456ced468a..dc4c5a3189d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1252,7 +1252,7 @@ See RS/6000 and PowerPC Options.
 -msave-restore  -mno-save-restore
 -mshorten-memrefs  -mno-shorten-memrefs
 -mstrict-align  -mno-strict-align
--mcmodel=medlow  -mcmodel=medany
+-mcmodel=medlow  -mcmodel=medany -mcmodel=large
 -mexplicit-relocs  -mno-explicit-relocs
 -mrelax  -mno-relax
 -mriscv-attribute  -mno-riscv-attribute
@@ -31049,6 +31049,11 @@ The code generated by the medium-any code model is 
position-independent, but is
 not guaranteed to function correctly when linked into position-independent
 executables or libraries.
 
+@opindex -mcmodel=large
+@item -mcmodel=large
+Generate code for a large code model, which has no restrictions on size or
+placement of symbols.
+
 @item -mexplicit-relocs
 @itemx -mno-exlicit-relocs
 Use or do not use assembler relocation operators when dealing with symbolic


[gcc r15-213] So another constant synthesis improvement.

2024-05-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:975bb17e2f6bc90d366237ab1c5dc9b8df2dee69

commit r15-213-g975bb17e2f6bc90d366237ab1c5dc9b8df2dee69
Author: Jeff Law 
Date:   Mon May 6 15:27:43 2024 -0600

So another constant synthesis improvement.

In this patch we're looking at cases where we'd like to be able to use
lui+slli, but can't because of the sign extending nature of lui on
TARGET_64BIT.  For example: 0x800110020UL.  The trunk currently 
generates 4
instructions for that constant, when it can be done with 3 
(lui+slli.uw+addi).

When Zba is enabled, we can use lui+slli.uw as the slli.uw masks off the 
bits
32..63 before shifting, giving us the precise semantics we want.

I strongly suspect we'll want to do the same for a set of constants with
lui+add.uw, lui+shNadd.uw, so you'll see the beginnings of generalizing 
support
for lui followed by a "uw" instruction.

The new test just tests the set of cases that showed up while exploring a
particular space of the constant synthesis problem.  It's not meant to be
exhaustive (failure to use shadd when profitable).

gcc/

* config/riscv/riscv.cc (riscv_integer_op): Add field tracking if we
want to use a "uw" instruction variant.
(riscv_build_integer_1): Initialize the new field in various places.
Use lui+slli.uw for some constants.
(riscv_move_integer): Handle slli.uw.

gcc/testsuite/

* gcc.target/riscv/synthesis-2.c: New test.

Diff:
---
 gcc/config/riscv/riscv.cc|   60 +-
 gcc/testsuite/gcc.target/riscv/synthesis-2.c | 1481 ++
 2 files changed, 1539 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 44945d47fd6..6f1c67bf3f7 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -249,6 +249,7 @@ struct riscv_arg_info {
where A is an accumulator, each CODE[i] is a binary rtl operation
and each VALUE[i] is a constant integer.  CODE[0] is undefined.  */
 struct riscv_integer_op {
+  bool use_uw;
   enum rtx_code code;
   unsigned HOST_WIDE_INT value;
 };
@@ -734,6 +735,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
   /* Simply ADDI or LUI.  */
   codes[0].code = UNKNOWN;
   codes[0].value = value;
+  codes[0].use_uw = false;
   return 1;
 }
   if (TARGET_ZBS && SINGLE_BIT_MASK_OPERAND (value))
@@ -741,6 +743,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
   /* Simply BSETI.  */
   codes[0].code = UNKNOWN;
   codes[0].value = value;
+  codes[0].use_uw = false;
 
   /* RISC-V sign-extends all 32bit values that live in a 32bit
 register.  To avoid paradoxes, we thus need to use the
@@ -769,6 +772,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
{
  alt_codes[alt_cost-1].code = PLUS;
  alt_codes[alt_cost-1].value = low_part;
+ alt_codes[alt_cost-1].use_uw = false;
  memcpy (codes, alt_codes, sizeof (alt_codes));
  cost = alt_cost;
}
@@ -782,6 +786,7 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
{
  alt_codes[alt_cost-1].code = XOR;
  alt_codes[alt_cost-1].value = low_part;
+ alt_codes[alt_cost-1].use_uw = false;
  memcpy (codes, alt_codes, sizeof (alt_codes));
  cost = alt_cost;
}
@@ -792,17 +797,37 @@ riscv_build_integer_1 (struct riscv_integer_op 
codes[RISCV_MAX_INTEGER_OPS],
 {
   int shift = ctz_hwi (value);
   unsigned HOST_WIDE_INT x = value;
+  bool use_uw = false;
   x = sext_hwi (x >> shift, HOST_BITS_PER_WIDE_INT - shift);
 
   /* Don't eliminate the lower 12 bits if LUI might apply.  */
-  if (shift > IMM_BITS && !SMALL_OPERAND (x) && LUI_OPERAND (x << 
IMM_BITS))
+  if (shift > IMM_BITS
+ && !SMALL_OPERAND (x)
+ && (LUI_OPERAND (x << IMM_BITS)
+ || (TARGET_64BIT
+ && TARGET_ZBA
+ && LUI_OPERAND ((x << IMM_BITS)
+ & ~HOST_WIDE_INT_C (0x8000)
shift -= IMM_BITS, x <<= IMM_BITS;
 
+  /* Adjust X if it isn't a LUI operand in isolation, but we can use
+a subsequent "uw" instruction form to mask off the undesirable
+bits.  */
+  if (!LUI_OPERAND (x)
+ && TARGET_64BIT
+ && TARGET_ZBA
+ && LUI_OPERAND (x & ~HOST_WIDE_INT_C (0x8000UL)))
+   {
+ x = sext_hwi (x, 32);
+ use_uw = true;
+   }
+
   alt_cost = 1 + riscv_build_integer_1 (alt_codes, x, mode);
   if (alt_cost < cost)
{
  alt_codes[alt_cost-1].code = ASHIFT;
  alt_codes[alt_cost-1].value = shift;
+ alt_codes[alt_cost-1].use_uw = use_uw;
  memcpy (codes, alt_codes, sizeof 

[gcc(refs/users/meissner/heads/work165-vpair)] Update ChangeLog.*

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:9d5b33ea737d5873510454bea1b159c34cfa6a62

commit 9d5b33ea737d5873510454bea1b159c34cfa6a62
Author: Michael Meissner 
Date:   Mon May 6 15:35:03 2024 -0400

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.vpair | 127 +++-
 1 file changed, 126 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.vpair b/gcc/ChangeLog.vpair
index 01a40b0cd7f..3af41c85468 100644
--- a/gcc/ChangeLog.vpair
+++ b/gcc/ChangeLog.vpair
@@ -1,6 +1,131 @@
+ Branch work165-vpair, patch #303 
+
+Add vector pair optimizations.
+
+2024-05-06  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/vector-pair.md (vpair_add_neg_3): New
+   combiner insn to convert vector plus/neg into a minus operation.
+   (vpair_fma__merge): Optimize multiply, add/subtract, and
+   negation into fma operations if the user specifies to create fmas.
+   (vpair_fma__merge): Likewise.
+   (vpair_fma__merge2): Likewise.
+   (vpair_nfma__merge): Likewise.
+   (vpair_nfms__merge): Likewise.
+   (vpair_nfms__merge2): Likewise.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-7.c: New test.
+   * gcc.target/powerpc/vector-pair-8.c: Likewise.
+   * gcc.target/powerpc/vector-pair-9.c: Likewise.
+   * gcc.target/powerpc/vector-pair-10.c: Likewise.
+   * gcc.target/powerpc/vector-pair-11.c: Likewise.
+   * gcc.target/powerpc/vector-pair-12xs.c: Likewise.
+
+ Branch work165-vpair, patch #302 
+
+Add vector pair init and splat.
+
+2024-05-06  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-builtins.def (__builtin_vpair_zero): New
+   built-in function.
+   (__builtin_vpair_f32_splat): Likewise.
+   (__builtin_vpair_f64_splat): Likewise.
+   * config/rs6000/vector-pair.md (UNSPEC_VPAIR_ZERO): New unspec.
+   (UNSPEC_VPAIR_SPLAT): Likewise.
+   (VPAIR_SPLAT_VMODE): New mode iterator.
+   (VPAIR_SPLAT_ELEMENT_TO_VMODE): New mode attribute.
+   (vpair_splat_name): Likewise.
+   (vpair_zero): New insn.
+   (vpair_splat_): New define_expand.
+   (vpair_splat__internal): New insns.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-5.c: New test.
+   * gcc.target/powerpc/vector-pair-6.c: Likewise.
+
+ Branch work165-vpair, patch #301 
+
+Add support for vector pair fma operations.
+
+2024-05-06  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-builtins.def (__builtin_vpair_f32_fma): New
+   built-in.
+   (__builtin_vpair_f32_fms): Likewise.
+   (__builtin_vpair_f32_nfma): Likewise.
+   (__builtin_vpair_f32_nfms): Likewise.
+   (__builtin_vpair_f64_fma): Likewise.
+   (__builtin_vpair_f64_fms): Likewise.
+   (__builtin_vpair_f64_nfma): Likewise.
+   * config/rs6000/rs6000/rs6000-proto.h (enum vpair_split_fma): New
+   enumeration.
+   (vpair_split_fma): New declaration.
+   * config/rs6000/rs6000.cc (vpair_split_fma): New function to split
+   vector pair FMA operations.
+   * config/rs6000/vector-pair.md (UNSPEC_VPAIR_FMA): New unspec.
+   (vpair_stdname): Add UNSPEC_VPAIR_FMA.
+   (VPAIR_OP): Likewise.
+   (vpair_fma_4): New insns.
+   (vpair_fms_4): Likewise.
+   (vpair_nfma_4): Likewise.
+   (vpair_nfms_4): Likewise.
+   * doc/extend.texi (PowerPC Vector Pair Built-in Functions): Document new
+   vector pair fma built-in functions.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-3.c: New test.
+   * gcc.target/powerpc/vector-pair-4.c: Likewise.
+
+ Branch work165-vpair, patch #300 
+
+Add support for vector pair unary and binary operations.
+
+2024-05-06  Michael Meissner  
+
+gcc/
+
+   * config/rs6000/rs6000-builtins.def (__builtin_vpair_*): Add new
+   built-in functions for vector pair support.
+   * config/rs6000/rs6000-protos.h (enum vpair_split_unary): New
+   enumeration.
+   (vpair_split_unary): New declaration.
+   (vpair_split_binary): Likewise.
+   * config/rs6000/rs6000.cc (vpair_split_unary): New function to split
+   vector pair operations.
+   (vpair_split_binary): Likewise.
+   * config/rs6000/rs6000.md (toplevel): Include vector-pair.md.
+   * config/rs6000/t-rs6000 (MD_INCLUDES): Add vector-pair.md.
+   * config/rs6000/vector-pair.md: New file.
+   * doc/extend.texi (PowerPC Vector Pair Built-in Functions): Add
+   documentation for the new vector pair built-in functions.
+
+gcc/testsuite/
+
+   * gcc.target/powerpc/vector-pair-1.c: New test.
+   * gcc.target/powerpc/vector-pair-2.c: Likewise.
+
  Branch work165-vpair, baseline 
 
+Add ChangeLog.vpair and update REVISION.
+
+2024-05-02  Michael Meissner  
+
+gcc/
+
+   * ChangeLog.vpair: New file for branch.
+   * REVISION: 

[gcc(refs/users/meissner/heads/work165-vpair)] Add support for vector pair fma operations.

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:610b600064ea7c5d26d4a24e1f29efab1f98646e

commit 610b600064ea7c5d26d4a24e1f29efab1f98646e
Author: Michael Meissner 
Date:   Mon May 6 15:10:11 2024 -0400

Add support for vector pair fma operations.

2024-05-06  Michael Meissner  

gcc/

* config/rs6000/rs6000-builtins.def (__builtin_vpair_f32_fma): New
built-in.
(__builtin_vpair_f32_fms): Likewise.
(__builtin_vpair_f32_nfma): Likewise.
(__builtin_vpair_f32_nfms): Likewise.
(__builtin_vpair_f64_fma): Likewise.
(__builtin_vpair_f64_fms): Likewise.
(__builtin_vpair_f64_nfma): Likewise.
* config/rs6000/rs6000/rs6000-proto.h (enum vpair_split_fma): New
enumeration.
(vpair_split_fma): New declaration.
* config/rs6000/rs6000.cc (vpair_split_fma): New function to split
vector pair FMA operations.
* config/rs6000/vector-pair.md (UNSPEC_VPAIR_FMA): New unspec.
(vpair_stdname): Add UNSPEC_VPAIR_FMA.
(VPAIR_OP): Likewise.
(vpair_fma_4): New insns.
(vpair_fms_4): Likewise.
(vpair_nfma_4): Likewise.
(vpair_nfms_4): Likewise.
* doc/extend.texi (PowerPC Vector Pair Built-in Functions): 
Document new
vector pair fma built-in functions.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-3.c: New test.
* gcc.target/powerpc/vector-pair-4.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def| 24 ++
 gcc/config/rs6000/rs6000-protos.h| 13 
 gcc/config/rs6000/rs6000.cc  | 71 ++
 gcc/config/rs6000/vector-pair.md | 96 
 gcc/doc/extend.texi  | 25 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-3.c | 57 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-4.c | 57 ++
 7 files changed, 343 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 83e7206e989..4362cbb8fc7 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -4142,6 +4142,12 @@
   v256 __builtin_vpair_f32_div (v256, v256);
 VPAIR_F32_DIV vpair_div_v8sf3 {mma}
 
+  v256 __builtin_vpair_f32_fma (v256, v256, v256);
+VPAIR_F32_FMA vpair_fma_v8sf4 {mma}
+
+  v256 __builtin_vpair_f32_fms (v256, v256, v256);
+VPAIR_F32_FMS vpair_fms_v8sf4 {mma}
+
   v256 __builtin_vpair_f32_max (v256, v256);
 VPAIR_F32_MAX vpair_smax_v8sf3 {mma}
 
@@ -4157,6 +4163,12 @@
   v256 __builtin_vpair_f32_neg (v256);
 VPAIR_F32_NEG vpair_neg_v8sf2 {mma}
 
+  v256 __builtin_vpair_f32_nfma (v256, v256, v256);
+VPAIR_F32_NFMA vpair_nfma_v8sf4 {mma}
+
+  v256 __builtin_vpair_f32_nfms (v256, v256, v256);
+VPAIR_F32_NFMS vpair_nfms_v8sf4 {mma}
+
   v256 __builtin_vpair_f32_sub (v256, v256);
 VPAIR_F32_SUB vpair_sub_v8sf3 {mma}
 
@@ -4170,6 +4182,12 @@
   v256 __builtin_vpair_f64_div (v256, v256);
 VPAIR_F64_DIV vpair_div_v4df3 {mma}
 
+  v256 __builtin_vpair_f64_fma (v256, v256, v256);
+VPAIR_F64_FMA vpair_fma_v4df4 {mma}
+
+  v256 __builtin_vpair_f64_fms (v256, v256, v256);
+VPAIR_F64_FMS vpair_fms_v4df4 {mma}
+
   v256 __builtin_vpair_f64_max (v256, v256);
 VPAIR_F64_MAX vpair_smax_v4df3 {mma}
 
@@ -4185,5 +4203,11 @@
   v256 __builtin_vpair_f64_neg (v256);
 VPAIR_F64_NEG vpair_neg_v4df2 {mma}
 
+  v256 __builtin_vpair_f64_nfma (v256, v256, v256);
+VPAIR_F64_NFMA vpair_nfma_v4df4 {mma}
+
+  v256 __builtin_vpair_f64_nfms (v256, v256, v256);
+VPAIR_F64_NFMS vpair_nfms_v4df4 {mma}
+
   v256 __builtin_vpair_f64_sub (v256, v256);
 VPAIR_F64_SUB vpair_sub_v4df3 {mma}
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 4d6ecc83436..aed4081c87b 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -174,6 +174,19 @@ extern void vpair_split_unary (rtx [], machine_mode, enum 
rtx_code,
   enum vpair_split_unary);
 extern void vpair_split_binary (rtx [], machine_mode, enum rtx_code);
 
+/* When we are splitting a vector pair FMA operation into two vector 
operations, we
+   may need to modify the code generated.  This enumeration encodes the
+   different choices.  */
+
+enum vpair_split_fma {
+  VPAIR_SPLIT_FMA, /* Fused multiply-add.  */
+  VPAIR_SPLIT_FMS, /* Fused multiply-subtract.  */
+  VPAIR_SPLIT_NFMA,/* Fused negate multiply-add.  */
+  VPAIR_SPLIT_NFMS /* Fused negate multiply-subtract.  */
+};
+
+extern void vpair_split_fma (rtx [], machine_mode, enum vpair_split_fma);
+
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
formats are 

[gcc(refs/users/meissner/heads/work165-vpair)] Add vector pair optimizations.

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:0a1cb3a34efae94ec25f59f258df2aa6bc0963ed

commit 0a1cb3a34efae94ec25f59f258df2aa6bc0963ed
Author: Michael Meissner 
Date:   Mon May 6 15:32:50 2024 -0400

Add vector pair optimizations.

2024-05-06  Michael Meissner  

gcc/

* config/rs6000/vector-pair.md (vpair_add_neg_3): 
New
combiner insn to convert vector plus/neg into a minus operation.
(vpair_fma__merge): Optimize multiply, 
add/subtract, and
negation into fma operations if the user specifies to create fmas.
(vpair_fma__merge): Likewise.
(vpair_fma__merge2): Likewise.
(vpair_nfma__merge): Likewise.
(vpair_nfms__merge): Likewise.
(vpair_nfms__merge2): Likewise.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-7.c: New test.
* gcc.target/powerpc/vector-pair-8.c: Likewise.
* gcc.target/powerpc/vector-pair-9.c: Likewise.
* gcc.target/powerpc/vector-pair-10.c: Likewise.
* gcc.target/powerpc/vector-pair-11.c: Likewise.
* gcc.target/powerpc/vector-pair-12xs.c: Likewise.

Diff:
---
 gcc/config/rs6000/vector-pair.md  | 224 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-10.c |  61 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-11.c |  65 +++
 gcc/testsuite/gcc.target/powerpc/vector-pair-12.c |  65 +++
 gcc/testsuite/gcc.target/powerpc/vector-pair-7.c  |  18 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-8.c  |  18 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-9.c  |  61 ++
 7 files changed, 512 insertions(+)

diff --git a/gcc/config/rs6000/vector-pair.md b/gcc/config/rs6000/vector-pair.md
index 39b419c6814..7a81acbdc05 100644
--- a/gcc/config/rs6000/vector-pair.md
+++ b/gcc/config/rs6000/vector-pair.md
@@ -261,6 +261,31 @@
(set (attr "type") (if_then_else (match_test " == DIV")
(const_string "")
(const_string "")))])
+
+;; Optimize vector pair add of a negative value into a subtract.
+(define_insn_and_split "*vpair_add_neg_3"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa")
+   (unspec:OO
+[(match_operand:OO 1 "vsx_register_operand" "wa")
+ (unspec:OO
+  [(match_operand:OO 2 "vsx_register_operand" "wa")
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_NEG)
+ (const_int VPAIR_FP_ELEMENT)]
+VPAIR_FP_BINARY))]
+  "TARGET_MMA"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (unspec:OO
+[(match_dup 1)
+ (match_dup 2)
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_MINUS))]
+{
+}
+  [(set_attr "length" "8")
+   (set_attr "type" "")])
 
 ;; Vector pair fused-multiply (FMA) operations.  The last argument in the
 ;; UNSPEC is a CONST_INT which identifies what the scalar element is.
@@ -354,3 +379,202 @@
 }
   [(set_attr "length" "8")
(set_attr "type" "")])
+
+;; Optimize vector pair multiply and vector pair add into vector pair fma,
+;; providing the compiler would do this optimization for scalar and vectors.
+;; Unlike most of the define_insn_and_splits, this can be done before register
+;; allocation.
+(define_insn_and_split "*vpair_fma__merge"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa,wa")
+   (unspec:OO
+[(unspec:OO
+  [(match_operand:OO 1 "vsx_register_operand" "%wa,wa")
+   (match_operand:OO 2 "vsx_register_operand" "wa,0")
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_MULT)
+ (match_operand:OO 3 "vsx_register_operand" "0,wa")
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_PLUS))]
+  "TARGET_MMA && flag_fp_contract_mode == FP_CONTRACT_FAST"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (unspec:OO
+[(match_dup 1)
+ (match_dup 2)
+ (match_dup 3)
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_FMA))]
+{
+}
+  [(set_attr "length" "8")
+   (set_attr "type" "")])
+
+;; Merge multiply and subtract.
+(define_insn_and_split "*vpair_fma__merge"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa,wa")
+   (unspec:OO
+[(unspec:OO
+  [(match_operand:OO 1 "vsx_register_operand" "%wa,wa")
+   (match_operand:OO 2 "vsx_register_operand" "wa,0")
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_MULT)
+ (match_operand:OO 3 "vsx_register_operand" "0,wa")
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_MINUS))]
+  "TARGET_MMA && flag_fp_contract_mode == FP_CONTRACT_FAST"
+  "#"
+  "&& 1"
+  [(set (match_dup 0)
+   (unspec:OO
+[(match_dup 1)
+ (match_dup 2)
+ (unspec:OO
+  [(match_dup 3)
+   (const_int VPAIR_FP_ELEMENT)]
+  UNSPEC_VPAIR_NEG)
+ (const_int VPAIR_FP_ELEMENT)]
+UNSPEC_VPAIR_FMA))]
+{
+}
+  [(set_attr "length" "8")
+   (set_attr "type" 

[gcc(refs/users/meissner/heads/work165-vpair)] Add vector pair init and splat.

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:a51e8b4546f52c0c646cfcdac411bb2bebf2d5d4

commit a51e8b4546f52c0c646cfcdac411bb2bebf2d5d4
Author: Michael Meissner 
Date:   Mon May 6 15:15:06 2024 -0400

Add vector pair init and splat.

2024-05-06  Michael Meissner  

gcc/

* config/rs6000/rs6000-builtins.def (__builtin_vpair_zero): New
built-in function.
(__builtin_vpair_f32_splat): Likewise.
(__builtin_vpair_f64_splat): Likewise.
* config/rs6000/vector-pair.md (UNSPEC_VPAIR_ZERO): New unspec.
(UNSPEC_VPAIR_SPLAT): Likewise.
(VPAIR_SPLAT_VMODE): New mode iterator.
(VPAIR_SPLAT_ELEMENT_TO_VMODE): New mode attribute.
(vpair_splat_name): Likewise.
(vpair_zero): New insn.
(vpair_splat_): New define_expand.
(vpair_splat__internal): New insns.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-5.c: New test.
* gcc.target/powerpc/vector-pair-6.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def|  10 +++
 gcc/config/rs6000/vector-pair.md | 102 ++-
 gcc/doc/extend.texi  |   9 ++
 gcc/testsuite/gcc.target/powerpc/vector-pair-5.c |  56 +
 gcc/testsuite/gcc.target/powerpc/vector-pair-6.c |  56 +
 5 files changed, 232 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 4362cbb8fc7..b757a8630ff 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -4132,6 +4132,10 @@
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
 STXVP nothing {mma,pair}
 
+;; Vector pair built-in functions.
+  v256 __builtin_vpair_zero ();
+VPAIR_ZERO vpair_zero {mma}
+
 ;; Vector pair built-in functions with float elements
   v256 __builtin_vpair_f32_abs (v256);
 VPAIR_F32_ABS vpair_abs_v8sf2 {mma}
@@ -4169,6 +4173,9 @@
   v256 __builtin_vpair_f32_nfms (v256, v256, v256);
 VPAIR_F32_NFMS vpair_nfms_v8sf4 {mma}
 
+  v256 __builtin_vpair_f32_splat (float);
+VPAIR_F32_SPLAT vpair_splat_v8sf {mma}
+
   v256 __builtin_vpair_f32_sub (v256, v256);
 VPAIR_F32_SUB vpair_sub_v8sf3 {mma}
 
@@ -4209,5 +4216,8 @@
   v256 __builtin_vpair_f64_nfms (v256, v256, v256);
 VPAIR_F64_NFMS vpair_nfms_v4df4 {mma}
 
+  v256 __builtin_vpair_f64_splat (double);
+VPAIR_F64_SPLAT vpair_splat_v4df {mma}
+
   v256 __builtin_vpair_f64_sub (v256, v256);
 VPAIR_F64_SUB vpair_sub_v4df3 {mma}
diff --git a/gcc/config/rs6000/vector-pair.md b/gcc/config/rs6000/vector-pair.md
index 73ae46e6d40..39b419c6814 100644
--- a/gcc/config/rs6000/vector-pair.md
+++ b/gcc/config/rs6000/vector-pair.md
@@ -38,7 +38,9 @@
UNSPEC_VPAIR_NEG
UNSPEC_VPAIR_PLUS
UNSPEC_VPAIR_SMAX
-   UNSPEC_VPAIR_SMIN])
+   UNSPEC_VPAIR_SMIN
+   UNSPEC_VPAIR_ZERO
+   UNSPEC_VPAIR_SPLAT])
 
 ;; Vector pair element ID that defines the scaler element within the vector 
pair.
 (define_c_enum "vpair_element"
@@ -98,6 +100,104 @@
 ;; Map the scalar element ID into the appropriate insn type for divide.
 (define_int_attr vpair_divtype [(VPAIR_ELEMENT_FLOAT  "vecfdiv")
(VPAIR_ELEMENT_DOUBLE "vecdiv")])
+
+;; Mode iterator for the vector modes that we provide splat operations for.
+(define_mode_iterator VPAIR_SPLAT_VMODE [V4SF V2DF])
+
+;; Map element mode to 128-bit vector mode for splat operations
+(define_mode_attr VPAIR_SPLAT_ELEMENT_TO_VMODE [(SF "V4SF")
+   (DF "V2DF")])
+
+;; Map either element mode or vector mode into the name for the splat insn.
+(define_mode_attr vpair_splat_name [(SF   "v8sf")
+   (DF   "v4df")
+   (V4SF "v8sf")
+   (V2DF "v4df")])
+
+;; Initialize a vector pair to 0
+(define_insn_and_split "vpair_zero"
+  [(set (match_operand:OO 0 "vsx_register_operand" "=wa")
+   (unspec:OO [(const_int 0)] UNSPEC_VPAIR_ZERO))]
+  "TARGET_MMA"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 1) (match_dup 3))
+   (set (match_dup 2) (match_dup 3))]
+{
+  rtx op0 = operands[0];
+
+  operands[1] = simplify_gen_subreg (V2DFmode, op0, OOmode, 0);
+  operands[2] = simplify_gen_subreg (V2DFmode, op0, OOmode, 16);
+  operands[3] = CONST0_RTX (V2DFmode);
+}
+  [(set_attr "length" "8")
+   (set_attr "type" "vecperm")])
+
+;; Create a vector pair with a value splat'ed (duplicated) to all of the
+;; elements.
+(define_expand "vpair_splat_"
+  [(use (match_operand:OO 0 "vsx_register_operand"))
+   (use (match_operand:SFDF 1 "input_operand"))]
+  "TARGET_MMA"
+{
+  rtx op0 = operands[0];
+  rtx op1 = operands[1];
+  machine_mode element_mode = mode;
+
+  if (op1 == CONST0_RTX (element_mode))
+{
+  emit_insn (gen_vpair_zero (op0));
+  DONE;
+}
+
+  machine_mode vector_mode = mode;

[gcc(refs/users/meissner/heads/work165-vpair)] Add support for vector pair unary and binary operations.

2024-05-06 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:8d6120f017e142a940e7b9feee501b596a24bcda

commit 8d6120f017e142a940e7b9feee501b596a24bcda
Author: Michael Meissner 
Date:   Mon May 6 15:05:34 2024 -0400

Add support for vector pair unary and binary operations.

2024-05-06  Michael Meissner  

gcc/

* config/rs6000/rs6000-builtins.def (__builtin_vpair_*): Add new
built-in functions for vector pair support.
* config/rs6000/rs6000-protos.h (enum vpair_split_unary): New
enumeration.
(vpair_split_unary): New declaration.
(vpair_split_binary): Likewise.
* config/rs6000/rs6000.cc (vpair_split_unary): New function to split
vector pair operations.
(vpair_split_binary): Likewise.
* config/rs6000/rs6000.md (toplevel): Include vector-pair.md.
* config/rs6000/t-rs6000 (MD_INCLUDES): Add vector-pair.md.
* config/rs6000/vector-pair.md: New file.
* doc/extend.texi (PowerPC Vector Pair Built-in Functions): Add
documentation for the new vector pair built-in functions.

gcc/testsuite/

* gcc.target/powerpc/vector-pair-1.c: New test.
* gcc.target/powerpc/vector-pair-2.c: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtins.def|  56 
 gcc/config/rs6000/rs6000-protos.h|  12 ++
 gcc/config/rs6000/rs6000.cc  |  67 ++
 gcc/config/rs6000/rs6000.md  |   1 +
 gcc/config/rs6000/t-rs6000   |   1 +
 gcc/config/rs6000/vector-pair.md | 160 +++
 gcc/doc/extend.texi  |  51 
 gcc/testsuite/gcc.target/powerpc/vector-pair-1.c |  87 
 gcc/testsuite/gcc.target/powerpc/vector-pair-2.c |  86 
 9 files changed, 521 insertions(+)

diff --git a/gcc/config/rs6000/rs6000-builtins.def 
b/gcc/config/rs6000/rs6000-builtins.def
index 3bc7fed6956..83e7206e989 100644
--- a/gcc/config/rs6000/rs6000-builtins.def
+++ b/gcc/config/rs6000/rs6000-builtins.def
@@ -4131,3 +4131,59 @@
 
   void __builtin_vsx_stxvp (v256, unsigned long, const v256 *);
 STXVP nothing {mma,pair}
+
+;; Vector pair built-in functions with float elements
+  v256 __builtin_vpair_f32_abs (v256);
+VPAIR_F32_ABS vpair_abs_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_add (v256, v256);
+VPAIR_F32_ADD vpair_add_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_div (v256, v256);
+VPAIR_F32_DIV vpair_div_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_max (v256, v256);
+VPAIR_F32_MAX vpair_smax_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_min (v256, v256);
+VPAIR_F32_MIN vpair_smin_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_mul (v256, v256);
+VPAIR_F32_MUL vpair_mul_v8sf3 {mma}
+
+  v256 __builtin_vpair_f32_nabs (v256);
+VPAIR_F32_NABS vpair_nabs_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_neg (v256);
+VPAIR_F32_NEG vpair_neg_v8sf2 {mma}
+
+  v256 __builtin_vpair_f32_sub (v256, v256);
+VPAIR_F32_SUB vpair_sub_v8sf3 {mma}
+
+;; Vector pair built-in functions with double elements
+  v256 __builtin_vpair_f64_abs (v256);
+VPAIR_F64_ABS vpair_abs_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_add (v256, v256);
+VPAIR_F64_ADD vpair_add_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_div (v256, v256);
+VPAIR_F64_DIV vpair_div_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_max (v256, v256);
+VPAIR_F64_MAX vpair_smax_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_min (v256, v256);
+VPAIR_F64_MIN vpair_smin_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_mul (v256, v256);
+VPAIR_F64_MUL vpair_mul_v4df3 {mma}
+
+  v256 __builtin_vpair_f64_nabs (v256);
+VPAIR_F64_NABS vpair_nabs_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_neg (v256);
+VPAIR_F64_NEG vpair_neg_v4df2 {mma}
+
+  v256 __builtin_vpair_f64_sub (v256, v256);
+VPAIR_F64_SUB vpair_sub_v4df3 {mma}
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 09a57a806fa..4d6ecc83436 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -162,6 +162,18 @@ extern bool rs6000_pcrel_p (void);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
 extern void rs6000_output_addr_vec_elt (FILE *, int);
 
+/* If we are splitting a vector pair unary operator into two separate vector
+   operations, we need to generate a NEG if this is NABS.  */
+
+enum vpair_split_unary {
+  VPAIR_SPLIT_NORMAL,  /* No extra processing is needed.  */
+  VPAIR_SPLIT_NEGATE   /* Wrap operation with a NEG.  */
+};
+
+extern void vpair_split_unary (rtx [], machine_mode, enum rtx_code,
+  enum vpair_split_unary);
+extern void vpair_split_binary (rtx [], machine_mode, enum rtx_code);
+
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
formats are not currently 

[gcc r15-212] aarch64: Fix gcc.target/aarch64/sve/loop_add_6.c for LLP64 targets

2024-05-06 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:53026cbf08889d00fed34d8667796d22ef8554cf

commit r15-212-g53026cbf08889d00fed34d8667796d22ef8554cf
Author: Andrew Pinski 
Date:   Mon May 6 12:20:17 2024 -0700

aarch64: Fix gcc.target/aarch64/sve/loop_add_6.c for LLP64 targets

Even though the aarch64-mingw32 support has not been committed yet,
we should fix some of the testcases. In this case 
gcc.target/aarch64/sve/loop_add_6.c
is easy to fix. We should use __SIZETYPE__ instead of `unsigned long` for 
the variables
that will be used for pointer plus.

Committed as obvious after a quick test on aarch64-linux-gnu.

gcc/testsuite/ChangeLog:

PR testsuite/114177
* gcc.target/aarch64/sve/loop_add_6.c: Use __SIZETYPE__ instead
of `unsigned long` for index and offset variables.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/testsuite/gcc.target/aarch64/sve/loop_add_6.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/loop_add_6.c 
b/gcc/testsuite/gcc.target/aarch64/sve/loop_add_6.c
index e7416ebcded..a530998f54b 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/loop_add_6.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/loop_add_6.c
@@ -5,8 +5,8 @@ double __GIMPLE (ssa, startwith("loop"))
 neg_xi (double *x)
 {
   int i;
-  long unsigned int index;
-  long unsigned int offset;
+  __SIZETYPE__ index;
+  __SIZETYPE__ offset;
   double * xi_ptr;
   double xi;
   double neg_xi;
@@ -20,8 +20,8 @@ neg_xi (double *x)
   res_1 = __PHI (__BB5: 0.0, __BB3: res_2);
   i_4 = __PHI (__BB5: 0, __BB3: i_5);
   ivtmp_6 = __PHI (__BB5: 100U, __BB3: ivtmp_7);
-  index = (long unsigned int) i_4;
-  offset = index * 8UL;
+  index = (__SIZETYPE__ ) i_4;
+  offset = index * _Literal (__SIZETYPE__) 8;
   xi_ptr = x_8(D) + offset;
   xi = *xi_ptr;
   neg_xi = -xi;


[gcc r15-211] Update the C FE routine "add_flexible_array_elts_to_size" C++ FE routine "layout_var_decl" to handle

2024-05-06 Thread Qing Zhao via Gcc-cvs
https://gcc.gnu.org/g:6634a409124a884ff66b3756568a7daae7d3c295

commit r15-211-g6634a409124a884ff66b3756568a7daae7d3c295
Author: Qing Zhao 
Date:   Mon May 6 16:28:01 2024 +

Update the C FE routine "add_flexible_array_elts_to_size" C++ FE routine 
"layout_var_decl" to handle the cases when the DECL is union.

PR c/53548

Add testing cases to test the _bos for flexible array members in unions
or alone in structures.

gcc/c/ChangeLog:

PR c/53548
* c-decl.cc (add_flexible_array_elts_to_size): Handle the cases
when the DECL is union.

gcc/cp/ChangeLog:

PR c/53548
* decl.cc (layout_var_decl): Handle the cases when the DECL is
union with a flexible array member initializer.

gcc/testsuite/ChangeLog:

PR c/53548
* c-c++-common/fam-in-union-alone-in-struct-bos-1.c: New test.
* c-c++-common/fam-in-union-alone-in-struct-bos.c: New test.

Diff:
---
 gcc/c/c-decl.cc| 29 --
 gcc/cp/decl.cc | 32 ---
 .../fam-in-union-alone-in-struct-bos-1.c   | 66 ++
 .../fam-in-union-alone-in-struct-bos.c | 45 +++
 4 files changed, 159 insertions(+), 13 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 9ef2ab25773..b691b91b3db 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -5339,8 +5339,9 @@ zero_length_array_type_p (const_tree type)
 }
 
 /* INIT is a constructor that forms DECL's initializer.  If the final
-   element initializes a flexible array field, add the size of that
-   initializer to DECL's size.  */
+   element initializes a flexible array field, adjust the size of the
+   DECL with the initializer based on whether the DECL is a union or
+   a structure.  */
 
 static void
 add_flexible_array_elts_to_size (tree decl, tree init)
@@ -5355,10 +5356,26 @@ add_flexible_array_elts_to_size (tree decl, tree init)
   if (flexible_array_member_type_p (type))
 {
   complete_array_type (, elt, false);
-  DECL_SIZE (decl)
-   = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
-  DECL_SIZE_UNIT (decl)
-   = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type));
+  /* For a structure, add the size of the initializer to the DECL's
+size.  */
+  if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
+   {
+ DECL_SIZE (decl)
+   = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
+ DECL_SIZE_UNIT (decl)
+   = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
+ TYPE_SIZE_UNIT (type));
+   }
+  /* For a union, the DECL's size is the maximum of the current size
+and the size of the initializer.  */
+  else
+   {
+ DECL_SIZE (decl)
+   = size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
+ DECL_SIZE_UNIT (decl)
+   = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
+ TYPE_SIZE_UNIT (type));
+   }
 }
 }
 
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index e8622e22a4c..04a151c341c 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -6563,8 +6563,9 @@ layout_var_decl (tree decl)
}
 }
 
-  /* If the final element initializes a flexible array field, add the size of
- that initializer to DECL's size.  */
+  /* If the final element initializes a flexible array field, adjust
+ the size of the DECL with the initializer based on whether the
+ DECL is a union or a structure.  */
   if (type != error_mark_node
   && DECL_INITIAL (decl)
   && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
@@ -6585,11 +6586,28 @@ layout_var_decl (tree decl)
  && TREE_CODE (vtype) == ARRAY_TYPE
  && COMPLETE_TYPE_P (vtype))
{
- DECL_SIZE (decl)
-   = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (vtype));
- DECL_SIZE_UNIT (decl)
-   = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
- TYPE_SIZE_UNIT (vtype));
+ /* For a structure, add the size of the initializer to the DECL's
+size.  */
+ if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
+   {
+ DECL_SIZE (decl)
+   = size_binop (PLUS_EXPR, DECL_SIZE (decl),
+ TYPE_SIZE (vtype));
+ DECL_SIZE_UNIT (decl)
+   = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
+ TYPE_SIZE_UNIT (vtype));
+   }
+ /* For a union, the DECL's size is the maximum of the current size
+and the size of the initializer.  */
+ else
+   {
+ DECL_SIZE (decl)
+   = size_binop (MAX_EXPR, DECL_SIZE 

[gcc r15-210] Add testing cases for flexible array members in unions and alone in structures.

2024-05-06 Thread Qing Zhao via Gcc-cvs
https://gcc.gnu.org/g:93f6a47583f3fa8a1b66856ecb19ec28f26b2ba4

commit r15-210-g93f6a47583f3fa8a1b66856ecb19ec28f26b2ba4
Author: Qing Zhao 
Date:   Mon May 6 16:27:09 2024 +

Add testing cases for flexible array members in unions and alone in 
structures.

PR c/53548

gcc/testsuite/ChangeLog:

PR c/53548
* c-c++-common/fam-in-union-alone-in-struct-1.c: New testcase.
* c-c++-common/fam-in-union-alone-in-struct-2.c: New testcase.
* c-c++-common/fam-in-union-alone-in-struct-3.c: New testcase.

Diff:
---
 .../c-c++-common/fam-in-union-alone-in-struct-1.c  | 52 ++
 .../c-c++-common/fam-in-union-alone-in-struct-2.c  | 51 +
 .../c-c++-common/fam-in-union-alone-in-struct-3.c  | 36 +++
 3 files changed, 139 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c 
b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c
new file mode 100644
index 000..7d4721aa95a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c
@@ -0,0 +1,52 @@
+/* testing the correct usage of flexible array members in unions 
+   and alone in structures.  */
+/* { dg-do run} */
+/* { dg-options "-Wpedantic" } */
+
+union with_fam_1 {
+  int a;
+  int b[];  /* { dg-warning "flexible array member in union is a GCC 
extension" } */
+};
+
+union with_fam_2 {
+  char a;
+  int b[];  /* { dg-warning "flexible array member in union is a GCC 
extension" } */
+};
+
+union with_fam_3 {
+  char a[];  /* { dg-warning "flexible array member in union is a GCC 
extension" } */
+  /* { dg-warning "in an otherwise empty" "" { target c++ } .-1 } */
+  int b[];  /* { dg-warning "flexible array member in union is a GCC 
extension" } */
+};
+
+struct only_fam {
+  int b[];
+  /* { dg-warning "in a struct with no named members" "" { target c } .-1 } */
+  /* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */
+  /* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */
+};
+
+struct only_fam_2 {
+  unsigned int : 2;
+  unsigned int : 3;
+  int b[];
+  /* { dg-warning "in a struct with no named members" "" { target c } .-1 } */
+  /* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */
+  /* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */
+};
+
+int main ()
+{
+  if (sizeof (union with_fam_1) != sizeof (int))
+__builtin_abort ();
+  if (sizeof (union with_fam_2) != __alignof__ (int))
+__builtin_abort ();
+  if (sizeof (union with_fam_3) != 0)
+__builtin_abort ();
+  if (sizeof (struct only_fam) != 0)
+__builtin_abort ();
+  if (sizeof (struct only_fam_2) != sizeof (int))
+__builtin_abort ();
+  return 0;
+}
+
diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c 
b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c
new file mode 100644
index 000..3743f9e7dac
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c
@@ -0,0 +1,51 @@
+/* testing the correct usage of flexible array members in unions 
+   and alone in structures: initialization  */
+/* { dg-do run} */
+/* { dg-options "-O2" } */
+
+union with_fam_1 {
+  int a;
+  int b[]; 
+} with_fam_1_v = {.b = {1, 2, 3, 4}};
+
+union with_fam_2 {
+  int a;
+  char b[];  
+} with_fam_2_v = {.a = 0x1f2f3f4f};
+
+union with_fam_3 {
+  char a[];  
+  int b[];  
+} with_fam_3_v = {.b = {0x1f2f3f4f, 0x5f6f7f7f}};
+
+struct only_fam {
+  int b[]; 
+} only_fam_v = {{7, 11}};
+
+struct only_fam_2 {
+  unsigned int : 2;
+  unsigned int : 3;
+  int b[]; 
+} only_fam_2_v = {{7, 11}};
+
+int main ()
+{
+  if (with_fam_1_v.b[3] != 4
+  || with_fam_1_v.b[0] != 1)
+__builtin_abort ();
+  if (with_fam_2_v.b[3] != 0x1f
+  || with_fam_2_v.b[0] != 0x4f)
+__builtin_abort ();
+  if (with_fam_3_v.a[0] != 0x4f
+  || with_fam_3_v.a[7] != 0x5f)
+__builtin_abort ();
+  if (only_fam_v.b[0] != 7
+  || only_fam_v.b[1] != 11)
+__builtin_abort ();
+  if (only_fam_2_v.b[0] != 7
+  || only_fam_2_v.b[1] != 11)
+__builtin_abort ();
+
+  return 0;
+}
+
diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c 
b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c
new file mode 100644
index 000..dd36fa01306
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c
@@ -0,0 +1,36 @@
+/* testing the correct usage of flexible array members in unions 
+   and alone in structures.  */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+union with_fam_1 {
+  int a;
+  int b[];  /* { dg-error "flexible array member in union is a GCC extension" 
} */
+};
+
+union with_fam_2 {
+  char a;
+  int b[];  /* { dg-error "flexible array member in union is a GCC extension" 
} */
+};
+
+union with_fam_3 {
+  char a[];  /* { dg-error "flexible array member in union is a GCC extension" 
} */
+  /* { dg-error "in an otherwise empty" 

[gcc r15-209] C and C++ FE changes to support flexible array members in unions and alone in structures. Adjust tes

2024-05-06 Thread Qing Zhao via Gcc-cvs
https://gcc.gnu.org/g:f27fc59d9f7c735d200fda647a487850144b10eb

commit r15-209-gf27fc59d9f7c735d200fda647a487850144b10eb
Author: Qing Zhao 
Date:   Mon May 6 16:26:19 2024 +

C and C++ FE changes to support flexible array members in unions and alone 
in structures. Adjust testcases for flexible array member in union and alone in 
structure extension.

PR c/53548

gcc/c/ChangeLog:

PR c/53548
* c-decl.cc (finish_struct): Change errors to pedwarns for the cases
flexible array members in union or alone in structures.

gcc/cp/ChangeLog:

PR c/53548
* class.cc (diagnose_flexarrays): Change error to pdewarn for the 
case
flexible array members alone in structures.
* decl.cc (grokdeclarator): Change error to pdewarn for the case
flexible array members in unions.

gcc/ChangeLog:

PR c/53548
* stor-layout.cc (place_union_field): Use zero sizes for flexible 
array
member fields.

gcc/testsuite/ChangeLog:

PR c/53548
* c-c++-common/builtin-clear-padding-3.c: Adjust testcase.
* g++.dg/ext/flexary12.C: Likewise.
* g++.dg/ext/flexary19.C: Likewise.
* g++.dg/ext/flexary2.C: Likewise.
* g++.dg/ext/flexary3.C: Likewise.
* g++.dg/ext/flexary36.C: Likewise.
* g++.dg/ext/flexary4.C: Likewise.
* g++.dg/ext/flexary5.C: Likewise.
* g++.dg/ext/flexary8.C: Likewise.
* g++.dg/torture/pr64280.C: Likewise.
* gcc.dg/20050620-1.c: Likewise.
* gcc.dg/940510-1.c: Likewise.

Diff:
---
 gcc/c/c-decl.cc| 16 ++-
 gcc/cp/class.cc| 11 +++--
 gcc/cp/decl.cc |  7 ++-
 gcc/stor-layout.cc |  9 +++-
 .../c-c++-common/builtin-clear-padding-3.c | 10 ++--
 gcc/testsuite/g++.dg/ext/flexary12.C   |  6 +--
 gcc/testsuite/g++.dg/ext/flexary19.C   | 42 -
 gcc/testsuite/g++.dg/ext/flexary2.C|  2 +-
 gcc/testsuite/g++.dg/ext/flexary3.C|  2 +-
 gcc/testsuite/g++.dg/ext/flexary36.C   |  2 +-
 gcc/testsuite/g++.dg/ext/flexary4.C| 54 +++---
 gcc/testsuite/g++.dg/ext/flexary5.C|  4 +-
 gcc/testsuite/g++.dg/ext/flexary8.C|  8 ++--
 gcc/testsuite/g++.dg/torture/pr64280.C |  2 +-
 gcc/testsuite/gcc.dg/20050620-1.c  |  2 +-
 gcc/testsuite/gcc.dg/940510-1.c|  4 +-
 16 files changed, 91 insertions(+), 90 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 52af8f32998..9ef2ab25773 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -9516,11 +9516,8 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
tree attributes,
   if (flexible_array_member_type_p (TREE_TYPE (x)))
{
  if (TREE_CODE (t) == UNION_TYPE)
-   {
- error_at (DECL_SOURCE_LOCATION (x),
-   "flexible array member in union");
- TREE_TYPE (x) = error_mark_node;
-   }
+   pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
+"flexible array member in union is a GCC extension");
  else if (!is_last_field)
{
  error_at (DECL_SOURCE_LOCATION (x),
@@ -9528,12 +9525,9 @@ finish_struct (location_t loc, tree t, tree fieldlist, 
tree attributes,
  TREE_TYPE (x) = error_mark_node;
}
  else if (!saw_named_field)
-   {
- error_at (DECL_SOURCE_LOCATION (x),
-   "flexible array member in a struct with no named "
-   "members");
- TREE_TYPE (x) = error_mark_node;
-   }
+   pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic,
+"flexible array member in a struct with no named "
+"members is a GCC extension");
}
 
   if (pedantic && TREE_CODE (t) == RECORD_TYPE
diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 5ef7c71af61..0ce361eb88e 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -7624,6 +7624,7 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem)
   bool diagd = false;
 
   const char *msg = 0;
+  const char *msg_fam = 0;
 
   if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
 {
@@ -7649,15 +7650,19 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem)
   if (fmem->after[0])
msg = G_("flexible array member %qD not at end of %q#T");
   else if (!fmem->first)
-   msg = G_("flexible array member %qD in an otherwise empty %q#T");
+   msg_fam = G_("flexible array member %qD in an otherwise"
+" empty %q#T is a GCC extension");
 
-  if (msg)
+  if (msg || 

[gcc r15-208] Allow flexible array members in unions and alone in structures [PR53548]

2024-05-06 Thread Qing Zhao via Gcc-cvs
https://gcc.gnu.org/g:adb1c8a0f167c3a1f7593d75f5a10eb07a5d741a

commit r15-208-gadb1c8a0f167c3a1f7593d75f5a10eb07a5d741a
Author: Qing Zhao 
Date:   Mon May 6 16:25:04 2024 +

Allow flexible array members in unions and alone in structures [PR53548]

The request for GCC to accept that the C99 flexible array member can be
in a union or alone in a structure has been made a long time ago around 2012
for supporting several practical cases including glibc.

A GCC PR has been opened for such request at that time:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53548

However, this PR was closed as WONTFIX around 2015 due to the following 
reason:

"there is an existing extension that makes the requested functionality 
possible"
i.e GCC fully supported that the zero-length array can be in a union or 
alone
in a structure for a long time. (though I didn't see any official 
documentation
on such extension)

It's reasonable to close PR53548 at that time since zero-length array 
extension
can be used for such purpose.

However, since GCC13, in order to improve the C/C++ security, we introduced
-fstrict-flex-arrays=n to gradually eliminate the "fake flexible array"
usages from C/C++ source code. As a result, zero-length arrays eventually
will be replaced by C99 flexiable array member completely.

Therefore, GCC needs to explicitly allow such extensions directly for C99
flexible arrays, since flexable array member in unions or alone in structs
are common code patterns in active use by the Linux kernel (and other 
projects).

For example, these do not error by default with GCC:

union one {
  int a;
  int b[0];
};

union two {
  int a;
  struct {
struct { } __empty;
int b[];
  };
};

But these do:

union three {
  int a;
  int b[];
};

struct four {
  int b[];
}

Clang has supported such extensions since March, 2024
https://github.com/llvm/llvm-project/pull/84428

GCC should also support such extensions. This will allow for
a seamless transition for code bases away from zero-length arrays without
losing existing code patterns.

gcc/ChangeLog:

PR c/53548
* doc/extend.texi: Add documentation for Flexible Array Members in
Unions and Flexible Array Members alone in Structures.

Diff:
---
 gcc/doc/extend.texi | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index e290265d68d..267fccd1512 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -42,6 +42,8 @@ extensions, accepted by GCC in C90 mode and in C++.
 * Named Address Spaces::Named address spaces.
 * Zero Length:: Zero-length arrays.
 * Empty Structures::Structures with no members.
+* Flexible Array Members in Unions::  Unions with Flexible Array Members.
+* Flexible Array Members alone in Structures::  Structures with only Flexible 
Array Members.
 * Variable Length:: Arrays whose length is computed at run time.
 * Variadic Macros:: Macros with a variable number of arguments.
 * Escaped Newlines::Slightly looser rules for escaped newlines.
@@ -1873,6 +1875,38 @@ The structure has size zero.  In C++, empty structures 
are part
 of the language.  G++ treats empty structures as if they had a single
 member of type @code{char}.
 
+@node Flexible Array Members in Unions
+@section Unions with Flexible Array Members
+@cindex unions with flexible array members
+@cindex unions with FAMs
+
+GCC permits a C99 flexible array member (FAM) to be in a union:
+
+@smallexample
+union with_fam @{
+  int a;
+  int b[];
+@};
+@end smallexample
+
+If every member of a union is a flexible array member, the size of
+such a union is zero.
+
+@node Flexible Array Members alone in Structures
+@section Structures with only Flexible Array Members
+@cindex structures with only flexible array members
+@cindex structures with only FAMs
+
+GCC permits a C99 flexible array member (FAM) to be alone in a structure:
+
+@smallexample
+struct only_fam @{
+  int b[];
+@};
+@end smallexample
+
+The size of such a structure is zero.
+
 @node Variable Length
 @section Arrays of Variable Length
 @cindex variable-length arrays


[gcc r13-8699] AVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.

2024-05-06 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:287293786d541217e7bf47cab6b8fb522ae9156a

commit r13-8699-g287293786d541217e7bf47cab6b8fb522ae9156a
Author: Georg-Johann Lay 
Date:   Fri May 3 18:47:50 2024 +0200

AVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.

ipa/92606: Inter-procedural analysis optimizes data across
address-spaces and PROGMEM.  As of v14, the PROGMEM part is
still not fixed (and there is still no target hook as proposed
in PR92932).  Just disable respective bogus optimization.

PR ipa/92606
gcc/
* config/avr/avr.cc (avr_option_override): Set
flag_ipa_icf_variables = 0.
gcc/testsuite/
* gcc.target/avr/torture/pr92606.c: New test.

(cherry picked from commit 08e752e72363ae7fd5a5fcb70913a0f7b240387b)

Diff:
---
 gcc/config/avr/avr.cc  |  6 +++
 gcc/testsuite/gcc.target/avr/torture/pr92606.c | 57 ++
 2 files changed, 63 insertions(+)

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index f8c4eb327a2..a5c628134b4 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -1112,6 +1112,12 @@ avr_option_override (void)
   if (targetm.addr_space.zero_address_valid (ADDR_SPACE_GENERIC))
 flag_delete_null_pointer_checks = 0;
 
+  /* PR ipa/92606: Inter-procedural analysis optimizes data across
+ address-spaces and PROGMEM.  As of v14, the PROGMEM part is
+ still not fixed (and there is still no target hook as proposed
+ in PR92932).  Just disable respective bogus optimization.  */
+  flag_ipa_icf_variables = 0;
+
   if (flag_pic == 1)
 warning (OPT_fpic, "%<-fpic%> is not supported");
   if (flag_pic == 2)
diff --git a/gcc/testsuite/gcc.target/avr/torture/pr92606.c 
b/gcc/testsuite/gcc.target/avr/torture/pr92606.c
new file mode 100644
index 000..cc07128c73b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/torture/pr92606.c
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+
+typedef uint32_t T;
+
+#define NI __attribute__((noinline,noclone))
+
+
+#ifndef __AVR_TINY__
+#define read_u32(X) \
+(__extension__( \
+{   \
+uint16_t __addr16 = (uint16_t)(X);  \
+uint32_t __result;  \
+__asm__ __volatile__ ("lpm %A0, Z+" "\n\t"  \
+  "lpm %B0, Z+" "\n\t"  \
+  "lpm %C0, Z+" "\n\t"  \
+  "lpm %D0, Z" "\n\t"   \
+  : "=r" (__result), "+z" (__addr16));  \
+__result;   \
+}))
+#else
+NI uint32_t read_u32 (const uint32_t *p)
+{
+   return *p;
+}
+#endif
+
+static const __attribute((progmem)) T xyz_prog[] = { 123, 123, 123 };
+T xyz[] = { 123, 123, 123 };
+volatile int x = 0;
+
+NI void prf (T f)
+{
+if (f != 123)
+__builtin_abort();
+}
+
+NI void func_progmem()
+{
+prf (read_u32 (_prog[0]));
+}
+
+NI void func_ram()
+{
+prf (xyz[x]);
+}
+
+int main (void)
+{
+func_progmem();
+func_ram();
+
+   return 0;
+}


[gcc r15-207] AVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.

2024-05-06 Thread Georg-Johann Lay via Gcc-cvs
https://gcc.gnu.org/g:08e752e72363ae7fd5a5fcb70913a0f7b240387b

commit r15-207-g08e752e72363ae7fd5a5fcb70913a0f7b240387b
Author: Georg-Johann Lay 
Date:   Fri May 3 18:47:50 2024 +0200

AVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.

ipa/92606: Inter-procedural analysis optimizes data across
address-spaces and PROGMEM.  As of v14, the PROGMEM part is
still not fixed (and there is still no target hook as proposed
in PR92932).  Just disable respective bogus optimization.

PR ipa/92606
gcc/
* config/avr/avr.cc (avr_option_override): Set
flag_ipa_icf_variables = 0.
gcc/testsuite/
* gcc.target/avr/torture/pr92606.c: New test.

Diff:
---
 gcc/config/avr/avr.cc  |  6 +++
 gcc/testsuite/gcc.target/avr/torture/pr92606.c | 57 ++
 2 files changed, 63 insertions(+)

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 510e4cea19f..74924ab0565 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -1140,6 +1140,12 @@ avr_option_override (void)
   if (targetm.addr_space.zero_address_valid (ADDR_SPACE_GENERIC))
 flag_delete_null_pointer_checks = 0;
 
+  /* PR ipa/92606: Inter-procedural analysis optimizes data across
+ address-spaces and PROGMEM.  As of v14, the PROGMEM part is
+ still not fixed (and there is still no target hook as proposed
+ in PR92932).  Just disable respective bogus optimization.  */
+  flag_ipa_icf_variables = 0;
+
   if (flag_pic == 1)
 warning (OPT_fpic, "%<-fpic%> is not supported");
   if (flag_pic == 2)
diff --git a/gcc/testsuite/gcc.target/avr/torture/pr92606.c 
b/gcc/testsuite/gcc.target/avr/torture/pr92606.c
new file mode 100644
index 000..cc07128c73b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/torture/pr92606.c
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+
+typedef uint32_t T;
+
+#define NI __attribute__((noinline,noclone))
+
+
+#ifndef __AVR_TINY__
+#define read_u32(X) \
+(__extension__( \
+{   \
+uint16_t __addr16 = (uint16_t)(X);  \
+uint32_t __result;  \
+__asm__ __volatile__ ("lpm %A0, Z+" "\n\t"  \
+  "lpm %B0, Z+" "\n\t"  \
+  "lpm %C0, Z+" "\n\t"  \
+  "lpm %D0, Z" "\n\t"   \
+  : "=r" (__result), "+z" (__addr16));  \
+__result;   \
+}))
+#else
+NI uint32_t read_u32 (const uint32_t *p)
+{
+   return *p;
+}
+#endif
+
+static const __attribute((progmem)) T xyz_prog[] = { 123, 123, 123 };
+T xyz[] = { 123, 123, 123 };
+volatile int x = 0;
+
+NI void prf (T f)
+{
+if (f != 123)
+__builtin_abort();
+}
+
+NI void func_progmem()
+{
+prf (read_u32 (_prog[0]));
+}
+
+NI void func_ram()
+{
+prf (xyz[x]);
+}
+
+int main (void)
+{
+func_progmem();
+func_ram();
+
+   return 0;
+}


[gcc r15-206] contrib/gcc-changelog/git_check_commit.py: Implement --num-commits

2024-05-06 Thread Ken Matsui via Gcc-cvs
https://gcc.gnu.org/g:0e12aa6c26a9566f5b1a9b6d111a9e27507e213d

commit r15-206-g0e12aa6c26a9566f5b1a9b6d111a9e27507e213d
Author: Ken Matsui 
Date:   Wed Feb 28 13:00:23 2024 -0800

contrib/gcc-changelog/git_check_commit.py: Implement --num-commits

This patch implements a --num-commits (-n) flag for shorthand for
the range of hash~N..hash commits.

contrib/ChangeLog:

* gcc-changelog/git_check_commit.py: Implement --num-commits.

Signed-off-by: Ken Matsui 
Reviewed-by: Patrick Palka 
Reviewed-by: Jason Merrill 

Diff:
---
 contrib/gcc-changelog/git_check_commit.py | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/contrib/gcc-changelog/git_check_commit.py 
b/contrib/gcc-changelog/git_check_commit.py
index 8cca9f439a5..22e032e8b38 100755
--- a/contrib/gcc-changelog/git_check_commit.py
+++ b/contrib/gcc-changelog/git_check_commit.py
@@ -22,6 +22,12 @@ import argparse
 
 from git_repository import parse_git_revisions
 
+def nonzero_uint(value):
+ivalue = int(value)
+if ivalue <= 0:
+raise argparse.ArgumentTypeError('%s is not a non-zero positive 
integer' % value)
+return ivalue
+
 parser = argparse.ArgumentParser(description='Check git ChangeLog format '
  'of a commit')
 parser.add_argument('revisions', default='HEAD', nargs='?',
@@ -33,8 +39,17 @@ parser.add_argument('-p', '--print-changelog', 
action='store_true',
 help='Print final changelog entires')
 parser.add_argument('-v', '--verbose', action='store_true',
 help='Print verbose information')
+parser.add_argument('-n', '--num-commits', type=nonzero_uint, default=1,
+help='Number of commits to check (i.e. shorthand for '
+'hash~N..hash)')
 args = parser.parse_args()
 
+if args.num_commits > 1:
+if '..' in args.revisions:
+print('ERR: --num-commits and range of revisions are mutually 
exclusive')
+exit(1)
+args.revisions = '{0}~{1}..{0}'.format(args.revisions, args.num_commits)
+
 retval = 0
 for git_commit in parse_git_revisions(args.git_path, args.revisions):
 res = 'OK' if git_commit.success else 'FAILED'


[gcc r15-205] OpenMP: Fix for ICE in tree-nested.cc.

2024-05-06 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:80c03ac8041340b29325f86ed58ea8bd40a55b99

commit r15-205-g80c03ac8041340b29325f86ed58ea8bd40a55b99
Author: Sandra Loosemore 
Date:   Mon Apr 22 18:24:25 2024 +

OpenMP: Fix for ICE in tree-nested.cc.

Use gimple_omp_target_clauses() instead of gimple_omp_taskreg_clauses()
when stmt is GIMPLE_OMP_TARGET, to avoid an as_a<> ICE.  The code
immediately following this is already conditionalized in the same way.

gcc/ChangeLog
* tree-nested.cc (convert_tramp_reference_stmt): Use the correct
accessor for GIMPLE_OMP_TARGET clauses.

Diff:
---
 gcc/tree-nested.cc | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc
index 4e5f3be7676..fc0495d6443 100644
--- a/gcc/tree-nested.cc
+++ b/gcc/tree-nested.cc
@@ -2906,9 +2906,11 @@ convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, 
bool *handled_ops_p,
  continue;
decl = i ? get_chain_decl (info) : info->frame_decl;
/* Don't add CHAIN.* or FRAME.* twice.  */
-   for (c = gimple_omp_taskreg_clauses (stmt);
-c;
-c = OMP_CLAUSE_CHAIN (c))
+   if (gimple_code (stmt) == GIMPLE_OMP_TARGET)
+ c = gimple_omp_target_clauses (stmt);
+   else
+ c = gimple_omp_taskreg_clauses (stmt);
+   for (; c; c = OMP_CLAUSE_CHAIN (c))
  if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
  && OMP_CLAUSE_DECL (c) == decl)


[gcc r13-8698] tree-optimization/114799 - SLP and patterns

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:026ecb914d3d84c6e803cedb8b1677d3e7ddd60f

commit r13-8698-g026ecb914d3d84c6e803cedb8b1677d3e7ddd60f
Author: Richard Biener 
Date:   Tue Apr 23 08:39:03 2024 +0200

tree-optimization/114799 - SLP and patterns

The following plugs a hole with computing whether a SLP node has any
pattern stmts which is important to know when we want to replace it
by a CTOR from external defs.

PR tree-optimization/114799
* tree-vect-slp.cc (vect_get_and_check_slp_defs): Properly
update ->any_pattern when swapping operands.

* gcc.dg/vect/bb-slp-pr114799.c: New testcase.

(cherry picked from commit 18e8e55487238237f37f621668fdee316624981a)

Diff:
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr114799.c | 16 
 gcc/tree-vect-slp.cc|  6 ++
 2 files changed, 22 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr114799.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-pr114799.c
new file mode 100644
index 000..70572fe703b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr114799.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-forwprop" } */
+
+unsigned long x;
+unsigned char y;
+
+void
+foo (void)
+{
+  unsigned long tt = y;
+  tt+=255;
+  unsigned short t1 = tt;
+  t1 = 254 - t1;
+  tt += ((unsigned long)t1);
+  x = tt;
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index a72dd787a34..570edf38ca4 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -774,6 +774,12 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned 
char swap,
 (*oprnds_info)[i+1]->def_stmts[stmt_num]);
  std::swap ((*oprnds_info)[i]->ops[stmt_num],
 (*oprnds_info)[i+1]->ops[stmt_num]);
+ /* After swapping some operands we lost track whether an
+operand has any pattern defs so be conservative here.  */
+ if ((*oprnds_info)[i]->any_pattern
+ || (*oprnds_info)[i+1]->any_pattern)
+   (*oprnds_info)[i]->any_pattern
+ = (*oprnds_info)[i+1]->any_pattern = true;
  swapped = true;
  continue;
}


[gcc r13-8697] tree-optimization/114787 - more careful loop update with CFG cleanup

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:715a1df9082b40cf810283632218258ac9c86773

commit r13-8697-g715a1df9082b40cf810283632218258ac9c86773
Author: Richard Biener 
Date:   Wed Apr 24 08:42:40 2024 +0200

tree-optimization/114787 - more careful loop update with CFG cleanup

When CFG cleanup removes a backedge we have to be more careful with
loop update.  In particular we need to clear niter info and estimates
and if we remove the last backedge of a loop we have to also mark
it for removal to prevent a following basic block merging to associate
loop info with an unrelated header.

PR tree-optimization/114787
* tree-cfg.cc (remove_edge_and_dominated_blocks): When
removing a loop backedge clear niter info and when removing
the last backedge of a loop mark that loop for removal.

* gcc.dg/torture/pr114787.c: New testcase.

(cherry picked from commit cc48418cfc2e555d837ae9138cbfac23acb3cdf9)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr114787.c | 27 +++
 gcc/tree-cfg.cc | 26 +++---
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr114787.c 
b/gcc/testsuite/gcc.dg/torture/pr114787.c
new file mode 100644
index 000..1c7294bee7b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr114787.c
@@ -0,0 +1,27 @@
+/* { dg-do run } */
+
+int a, b, c, d, e = -1, f, g, h, j, k, n, o, p;
+int main() {
+  int i, l = 2, m;
+  for (b = 0; b < 1; b++)
+l = 0;
+  for (; a >= 0; a--)
+for (m = 3; m; m--) {
+  k = g;
+  i = 0;
+  for (; i < 1; i++)
+for (; f < 1; f++)
+  h = g;
+  n = 2 & ((e ^ d) | 1) * j;
+  o = ~(e & n);
+q:
+  if (c <= e)
+return 0;
+  e = o;
+}
+  p = l;
+  l = 0;
+  if (p)
+goto q;
+  return 0;
+}
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index a9fcc7fd050..98c6a0d06b8 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -8872,10 +8872,30 @@ remove_edge_and_dominated_blocks (edge e)
 
   /* If we are removing a path inside a non-root loop that may change
  loop ownership of blocks or remove loops.  Mark loops for fixup.  */
+  class loop *src_loop = e->src->loop_father;
   if (current_loops
-  && loop_outer (e->src->loop_father) != NULL
-  && e->src->loop_father == e->dest->loop_father)
-loops_state_set (LOOPS_NEED_FIXUP);
+  && loop_outer (src_loop) != NULL
+  && src_loop == e->dest->loop_father)
+{
+  loops_state_set (LOOPS_NEED_FIXUP);
+  /* If we are removing a backedge clear the number of iterations
+and estimates.  */
+  class loop *dest_loop = e->dest->loop_father;
+  if (e->dest == src_loop->header
+ || (e->dest == dest_loop->header
+ && flow_loop_nested_p (dest_loop, src_loop)))
+   {
+ free_numbers_of_iterations_estimates (dest_loop);
+ /* If we removed the last backedge mark the loop for removal.  */
+ FOR_EACH_EDGE (f, ei, dest_loop->header->preds)
+   if (f != e
+   && (f->src->loop_father == dest_loop
+   || flow_loop_nested_p (dest_loop, f->src->loop_father)))
+ break;
+ if (!f)
+   mark_loop_for_removal (dest_loop);
+   }
+}
 
   if (!dom_info_available_p (CDI_DOMINATORS))
 {


[gcc r13-8695] middle-end/114734 - wrong code with expand_call_mem_ref

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:20ebcaf826c91ddaf2aac35417ec1e5e6d31ad50

commit r13-8695-g20ebcaf826c91ddaf2aac35417ec1e5e6d31ad50
Author: Richard Biener 
Date:   Fri Apr 26 15:47:13 2024 +0200

middle-end/114734 - wrong code with expand_call_mem_ref

When expand_call_mem_ref looks at the definition of the address
argument to eventually expand a _MEM_REF argument together
with a masked load it fails to honor constraints imposed by SSA
coalescing decisions.  The following fixes this.

PR middle-end/114734
* internal-fn.cc (expand_call_mem_ref): Use
get_gimple_for_ssa_name to get at the def stmt of the address
argument to honor SSA coalescing constraints.

(cherry picked from commit 4d3a5618de5a949c61605f545f90e81bc502)

Diff:
---
 gcc/internal-fn.cc | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index c8943e6cb9e..0ff69a9dce8 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -52,6 +52,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "explow.h"
 #include "rtl-iter.h"
 #include "gimple-range.h"
+#include "tree-ssa-live.h"
+#include "tree-outof-ssa.h"
 
 /* For lang_hooks.types.type_for_mode.  */
 #include "langhooks.h"
@@ -2771,8 +2773,8 @@ expand_call_mem_ref (tree type, gcall *stmt, int index)
   tree tmp = addr;
   if (TREE_CODE (tmp) == SSA_NAME)
 {
-  gimple *def = SSA_NAME_DEF_STMT (tmp);
-  if (gimple_assign_single_p (def))
+  gimple *def = get_gimple_for_ssa_name (tmp);
+  if (def && gimple_assign_single_p (def))
tmp = gimple_assign_rhs1 (def);
 }


[gcc r13-8696] RISC-V: Add testcase for pr114734

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:4c3011ec4825bf06c9d268361a53f8239bf9564a

commit r13-8696-g4c3011ec4825bf06c9d268361a53f8239bf9564a
Author: Patrick O'Neill 
Date:   Tue Apr 30 13:26:45 2024 -0700

RISC-V: Add testcase for pr114734

gcc/testsuite/ChangeLog:

PR middle-end/114734

* gcc.target/riscv/rvv/autovec/pr114734.c: New test.

Signed-off-by: Patrick O'Neill 
(cherry picked from commit ff4dc8b10a421cdb0c56f7f8c238609de4f9fbe2)

Diff:
---
 .../gcc.target/riscv/rvv/autovec/pr114734.c| 25 ++
 1 file changed, 25 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114734.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114734.c
new file mode 100644
index 000..b605d992aa1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr114734.c
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v } */
+/* { dg-options { -march=rv64gcv_zvl256b -mabi=lp64d -fwhole-program -O3 
-mrvv-vector-bits=zvl  } } */
+
+int f[18];
+int g[18];
+int h[18][18][18];
+int a[324];
+long b[18];
+int *i = g;
+int (*j)[18][18] = h;
+int z;
+int main() {
+  for (int m = 0; m < 18; ++m)
+f[m] = 3;
+  for (int m = 0; m < 18; m += 1)
+for (int n = 0; n < 18; n += 3) {
+  a[m * 8 + n] = j[m][m][0] ? i[n] : 0;
+  b[n] = f[n] ? -i[m] : 0;
+}
+  for (long n = 0; n < 8; ++n)
+z = a[n];
+  if (b[15] != 0)
+__builtin_abort();
+}


[gcc r13-8694] tree-optimization/114246 - invalid call argument from DSE

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c4795316b2d92c9edd3d86ffa11425c82d1e379c

commit r13-8694-gc4795316b2d92c9edd3d86ffa11425c82d1e379c
Author: Richard Biener 
Date:   Wed Mar 6 09:02:31 2024 +0100

tree-optimization/114246 - invalid call argument from DSE

The following makes sure to strip type conversions added by
build_fold_addr_expr before placing the result in a call argument.

PR tree-optimization/114246
* tree-ssa-dse.cc (increment_start_addr): Strip useless
type conversions from the adjusted address.

* gcc.dg/torture/pr114246.c: New testcase.

(cherry picked from commit 0249744a9fe0775c2c895727aeebec4c59fd5f95)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr114246.c | 11 +++
 gcc/tree-ssa-dse.cc |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr114246.c 
b/gcc/testsuite/gcc.dg/torture/pr114246.c
new file mode 100644
index 000..eb20db594cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr114246.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+int a, b;
+
+void
+foo (void)
+{
+  __builtin_memcpy (, (char *) - 1, 2);
+  __builtin_memcpy (, , 1);
+}
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index e28eb88068a..779b518ff80 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -48,6 +48,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop-niter.h"
 #include "cfgloop.h"
 #include "tree-data-ref.h"
+#include "tree-ssa.h"
 
 /* This file implements dead store elimination.
 
@@ -643,6 +644,7 @@ increment_start_addr (gimple *stmt, tree *where, int 
increment)
  *where,
  build_int_cst (ptr_type_node,
 increment)));
+  STRIP_USELESS_TYPE_CONVERSION (*where);
 }
 
 /* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead


[gcc r13-8693] tree-optimization/113630 - invalid code hoisting

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:47cd06042237bf2d4f05b8355362bc038f6fa445

commit r13-8693-g47cd06042237bf2d4f05b8355362bc038f6fa445
Author: Richard Biener 
Date:   Wed Jan 31 11:28:50 2024 +0100

tree-optimization/113630 - invalid code hoisting

The following avoids code hoisting (but also PRE insertion) of
expressions that got value-numbered to another one that are not
a valid replacement (but still compute the same value).  This time
because the access path ends in a structure with different size,
meaning we consider a related access as not trapping because of the
size of the base of the access.

PR tree-optimization/113630
* tree-ssa-pre.cc (compute_avail): Avoid registering a
reference with a representation with not matching base
access size.

* gcc.dg/torture/pr113630.c: New testcase.

(cherry picked from commit 724b64304ff5c8ac08a913509afd6fde38d7b767)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr113630.c |  4 
 gcc/tree-ssa-pre.cc | 14 ++
 2 files changed, 18 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr113630.c 
b/gcc/testsuite/gcc.dg/torture/pr113630.c
new file mode 100644
index 000..72ebdefae27
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr113630.c
@@ -0,0 +1,4 @@
+/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
+/* { dg-additional-options "-fno-strict-aliasing" } */
+
+#include "pr110799.c"
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index dfcc9ec4711..9e9a2f9d26a 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -4224,6 +4224,20 @@ compute_avail (function *fun)
  = wide_int_to_tree (ptr_type_node,
  wi::to_wide (ref1->op2));
}
+ /* We also need to make sure that the access path
+ends in an access of the same size as otherwise
+we might assume an access may not trap while in
+fact it might.  That's independent of whether
+TBAA is in effect.  */
+ if (TYPE_SIZE (ref1->type) != TYPE_SIZE (ref2->type)
+ && (! TYPE_SIZE (ref1->type)
+ || ! TYPE_SIZE (ref2->type)
+ || ! operand_equal_p (TYPE_SIZE (ref1->type),
+   TYPE_SIZE (ref2->type
+   {
+ operands.release ();
+ continue;
+   }
  operands.release ();
 
  result = get_or_alloc_expr_for_reference


[gcc r15-204] tree-optimization/100923 - re-do VN with contextual PTA info fix

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:7c469a9fc785505dc350aba60311812c2bb0c1b5

commit r15-204-g7c469a9fc785505dc350aba60311812c2bb0c1b5
Author: Richard Biener 
Date:   Wed Feb 28 10:08:31 2024 +0100

tree-optimization/100923 - re-do VN with contextual PTA info fix

The following implements the gist of the PR100923 fix in a leaner
(and more complete) way by realizing that all ao_ref_init_from_vn_reference
uses need to have an SSA name in the base valueized with availability
in mind.  Instead of re-valueizing the whole chain of operands we can
simply only and always valueize the SSA name we put in the base.

This handles also two omitted places in vn_reference_lookup_3.

PR tree-optimization/100923
* tree-ssa-sccvn.cc (ao_ref_init_from_vn_reference): Valueize
base SSA_NAME.
(vn_reference_lookup_3): Adjust vn_context_bb around calls
to ao_ref_init_from_vn_reference.
(vn_reference_lookup_pieces): Revert original PR100923 fix.
(vn_reference_lookup): Likewise.

Diff:
---
 gcc/tree-ssa-sccvn.cc | 58 ++-
 1 file changed, 25 insertions(+), 33 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index fbbfa557833..726e9d88b8f 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -1201,11 +1201,17 @@ ao_ref_init_from_vn_reference (ao_ref *ref,
case STRING_CST:
  /* This can show up in ARRAY_REF bases.  */
case INTEGER_CST:
-   case SSA_NAME:
  *op0_p = op->op0;
  op0_p = NULL;
  break;
 
+   case SSA_NAME:
+ /* SSA names we have to get at one available since it contains
+flow-sensitive info.  */
+ *op0_p = vn_valueize (op->op0);
+ op0_p = NULL;
+ break;
+
/* And now the usual component-reference style ops.  */
case BIT_FIELD_REF:
  offset += wi::to_poly_offset (op->op1);
@@ -2725,7 +2731,6 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
  copy_reference_ops_from_ref (lhs, _ops);
  valueize_refs_1 (_ops, _anything, true);
}
-  vn_context_bb = saved_rpo_bb;
   ao_ref_init (_ref, lhs);
   lhs_ref_ok = true;
   if (valueized_anything
@@ -2734,9 +2739,11 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
ao_ref_base_alias_set (_ref), TREE_TYPE (lhs), lhs_ops)
  && !refs_may_alias_p_1 (ref, _ref, data->tbaa_p))
{
+ vn_context_bb = saved_rpo_bb;
  *disambiguate_only = TR_VALUEIZE_AND_DISAMBIGUATE;
  return NULL;
}
+  vn_context_bb = saved_rpo_bb;
 
   /* When the def is a CLOBBER we can optimistically disambiguate
 against it since any overlap it would be undefined behavior.
@@ -3634,13 +3641,19 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
   /* Adjust *ref from the new operands.  */
   ao_ref rhs1_ref;
   ao_ref_init (_ref, rhs1);
+  basic_block saved_rpo_bb = vn_context_bb;
+  vn_context_bb = gimple_bb (def_stmt);
   if (!ao_ref_init_from_vn_reference (,
  force_no_tbaa ? 0
  : ao_ref_alias_set (_ref),
  force_no_tbaa ? 0
  : ao_ref_base_alias_set (_ref),
  vr->type, vr->operands))
-   return (void *)-1;
+   {
+ vn_context_bb = saved_rpo_bb;
+ return (void *)-1;
+   }
+  vn_context_bb = saved_rpo_bb;
   /* This can happen with bitfields.  */
   if (maybe_ne (ref->size, r.size))
{
@@ -3839,8 +3852,14 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void 
*data_,
return data->finish (0, 0, val);
 
   /* Adjust *ref from the new operands.  */
+  basic_block saved_rpo_bb = vn_context_bb;
+  vn_context_bb = gimple_bb (def_stmt);
   if (!ao_ref_init_from_vn_reference (, 0, 0, vr->type, vr->operands))
-   return (void *)-1;
+   {
+ vn_context_bb = saved_rpo_bb;
+ return (void *)-1;
+   }
+  vn_context_bb = saved_rpo_bb;
   /* This can happen with bitfields.  */
   if (maybe_ne (ref->size, r.size))
return (void *)-1;
@@ -3928,31 +3947,13 @@ vn_reference_lookup_pieces (tree vuse, alias_set_type 
set,
   unsigned limit = param_sccvn_max_alias_queries_per_access;
   vn_walk_cb_data data (, NULL_TREE, NULL, kind, true, NULL_TREE,
false);
-  vec ops_for_ref;
-  if (!valueized_p)
-   ops_for_ref = vr1.operands;
-  else
-   {
- /* For ao_ref_from_mem we have to ensure only available SSA names
-end up in base and the only convenient way to make this work
-for PRE is to re-valueize with that in mind.  */
- ops_for_ref.create 

[gcc r15-203] Complete ao_ref_init_from_vn_reference for all refs

2024-05-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:8bdfb0c2d5a13a4fb846cde291decff06e4b753c

commit r15-203-g8bdfb0c2d5a13a4fb846cde291decff06e4b753c
Author: Richard Biener 
Date:   Tue Feb 27 13:55:15 2024 +0100

Complete ao_ref_init_from_vn_reference for all refs

This makes sure we can create ao_refs from all VN operands we create.

* tree-ssa-sccvn.cc (ao_ref_init_from_vn_reference): Add
TARGET_MEM_REF support.  Handle more bases.

Diff:
---
 gcc/tree-ssa-sccvn.cc | 51 +--
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 02c3bd5f538..fbbfa557833 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -1148,8 +1148,29 @@ ao_ref_init_from_vn_reference (ao_ref *ref,
 {
   switch (op->opcode)
{
-   /* These may be in the reference ops, but we cannot do anything
-  sensible with them here.  */
+   case CALL_EXPR:
+ return false;
+
+   /* Record the base objects.  */
+   case MEM_REF:
+ *op0_p = build2 (MEM_REF, op->type,
+  NULL_TREE, op->op0);
+ MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
+ MR_DEPENDENCE_BASE (*op0_p) = op->base;
+ op0_p = _OPERAND (*op0_p, 0);
+ break;
+
+   case TARGET_MEM_REF:
+ *op0_p = build5 (TARGET_MEM_REF, op->type,
+  NULL_TREE, op->op2, op->op0,
+  op->op1, ops[i+1].op0);
+ MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
+ MR_DEPENDENCE_BASE (*op0_p) = op->base;
+ op0_p = _OPERAND (*op0_p, 0);
+ ++i;
+ break;
+
+   /* Unwrap some of the wrapped decls.  */
case ADDR_EXPR:
  /* Apart from ADDR_EXPR arguments to MEM_REF.  */
  if (base != NULL_TREE
@@ -1170,21 +1191,16 @@ ao_ref_init_from_vn_reference (ao_ref *ref,
  break;
}
  /* Fallthru.  */
-   case CALL_EXPR:
- return false;
-
-   /* Record the base objects.  */
-   case MEM_REF:
- *op0_p = build2 (MEM_REF, op->type,
-  NULL_TREE, op->op0);
- MR_DEPENDENCE_CLIQUE (*op0_p) = op->clique;
- MR_DEPENDENCE_BASE (*op0_p) = op->base;
- op0_p = _OPERAND (*op0_p, 0);
- break;
-
-   case VAR_DECL:
case PARM_DECL:
+   case CONST_DECL:
case RESULT_DECL:
+ /* ???  We shouldn't see these, but un-canonicalize what
+copy_reference_ops_from_ref does when visiting MEM_REF.  */
+   case VAR_DECL:
+ /* ???  And for this only have DECL_HARD_REGISTER.  */
+   case STRING_CST:
+ /* This can show up in ARRAY_REF bases.  */
+   case INTEGER_CST:
case SSA_NAME:
  *op0_p = op->op0;
  op0_p = NULL;
@@ -1234,13 +1250,12 @@ ao_ref_init_from_vn_reference (ao_ref *ref,
case VIEW_CONVERT_EXPR:
  break;
 
-   case STRING_CST:
-   case INTEGER_CST:
+   case POLY_INT_CST:
case COMPLEX_CST:
case VECTOR_CST:
case REAL_CST:
+   case FIXED_CST:
case CONSTRUCTOR:
-   case CONST_DECL:
  return false;
 
default:


[gcc r12-10416] Fortran: Add error for subroutine passed to a variable dummy [PR106999]

2024-05-06 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:d72e9f90e370538b057690b16c1e65350dbbb75c

commit r12-10416-gd72e9f90e370538b057690b16c1e65350dbbb75c
Author: Paul Thomas 
Date:   Tue Apr 2 15:53:29 2024 +0100

Fortran: Add error for subroutine passed to a variable dummy [PR106999]

2024-04-02  Paul Thomas  

gcc/fortran
PR fortran/106999
* interface.cc (gfc_compare_interfaces): Add error for a
subroutine proc pointer passed to a variable formal.
(compare_parameter): If a procedure pointer is being passed to
a non-procedure formal arg, and there is an an interface, use
gfc_compare_interfaces to check and provide a more useful error
message.

gcc/testsuite/
PR fortran/106999
* gfortran.dg/pr106999.f90: New test.

(cherry picked from commit a7aa9455a8b9cb080649a7357b7360f2d99bcbf1)

Diff:
---
 gcc/fortran/interface.cc   | 20 +++-
 gcc/testsuite/gfortran.dg/pr106999.f90 | 33 +
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 874acb914f3..0c4cd385d56 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -1746,6 +1746,14 @@ gfc_compare_interfaces (gfc_symbol *s1, gfc_symbol *s2, 
const char *name2,
   return false;
 }
 
+  if (s2->attr.subroutine && s1->attr.flavor == FL_VARIABLE)
+{
+  if (errmsg != NULL)
+   snprintf (errmsg, err_len, "subroutine proc pointer '%s' passed "
+ "to dummy variable '%s'", name2, s1->name);
+  return false;
+}
+
   /* Do strict checks on all characteristics
  (for dummy procedures and procedure pointer assignments).  */
   if (!generic_flag && strict_flag)
@@ -2381,12 +2389,22 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
 {
   gfc_symbol *act_sym = actual->symtree->n.sym;
 
-  if (formal->attr.flavor != FL_PROCEDURE)
+  if (formal->attr.flavor != FL_PROCEDURE && !act_sym->ts.interface)
{
  if (where)
gfc_error ("Invalid procedure argument at %L", >where);
  return false;
}
+  else if (act_sym->ts.interface
+  && !gfc_compare_interfaces (formal, act_sym->ts.interface,
+  act_sym->name, 0, 1, err,
+  sizeof(err),NULL, NULL))
+   {
+ if (where)
+   gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
+  " %s", formal->name, >where, err);
+ return false;
+   }
 
   if (!gfc_compare_interfaces (formal, act_sym, act_sym->name, 0, 1, err,
   sizeof(err), NULL, NULL))
diff --git a/gcc/testsuite/gfortran.dg/pr106999.f90 
b/gcc/testsuite/gfortran.dg/pr106999.f90
new file mode 100644
index 000..f05a27006f6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106999.f90
@@ -0,0 +1,33 @@
+! { dg-do compile }
+! Test the fix for PR106999
+! Contributed by Gerhard Steinmetz  
+program p
+   type t
+  integer :: i
+  procedure(g), pointer :: f
+   end type
+   class(t), allocatable :: y, z
+   procedure(g), pointer :: ff
+   allocate (z)
+   z%i = 42
+   z%f => g
+   ff => g
+   call r(z%f)
+   call s(z%f) ! { dg-error "Interface mismatch in dummy procedure" }
+   call s(ff)  ! { dg-error "Interface mismatch in dummy procedure" }
+contains
+   subroutine g(x)
+  class(t) :: x
+  x%i = 84
+   end
+   subroutine r(x)
+  procedure(g) :: x
+  print *, "in r"
+  allocate (y)
+  call x(y)
+  print *, y%i
+   end
+   subroutine s(x)
+  class(*) :: x
+   end subroutine
+end


[gcc r13-8692] Fortran: Add error for subroutine passed to a variable dummy [PR106999]

2024-05-06 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:429935510202c4efee933bf907fd9dff816193f2

commit r13-8692-g429935510202c4efee933bf907fd9dff816193f2
Author: Paul Thomas 
Date:   Tue Apr 2 15:53:29 2024 +0100

Fortran: Add error for subroutine passed to a variable dummy [PR106999]

2024-04-02  Paul Thomas  

gcc/fortran
PR fortran/106999
* interface.cc (gfc_compare_interfaces): Add error for a
subroutine proc pointer passed to a variable formal.
(compare_parameter): If a procedure pointer is being passed to
a non-procedure formal arg, and there is an an interface, use
gfc_compare_interfaces to check and provide a more useful error
message.

gcc/testsuite/
PR fortran/106999
* gfortran.dg/pr106999.f90: New test.

(cherry picked from commit a7aa9455a8b9cb080649a7357b7360f2d99bcbf1)

Diff:
---
 gcc/fortran/interface.cc   | 20 +++-
 gcc/testsuite/gfortran.dg/pr106999.f90 | 33 +
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index dc384ad9323..05c92ab8f67 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -1752,6 +1752,14 @@ gfc_compare_interfaces (gfc_symbol *s1, gfc_symbol *s2, 
const char *name2,
   return false;
 }
 
+  if (s2->attr.subroutine && s1->attr.flavor == FL_VARIABLE)
+{
+  if (errmsg != NULL)
+   snprintf (errmsg, err_len, "subroutine proc pointer '%s' passed "
+ "to dummy variable '%s'", name2, s1->name);
+  return false;
+}
+
   /* Do strict checks on all characteristics
  (for dummy procedures and procedure pointer assignments).  */
   if (!generic_flag && strict_flag)
@@ -2388,12 +2396,22 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
 {
   gfc_symbol *act_sym = actual->symtree->n.sym;
 
-  if (formal->attr.flavor != FL_PROCEDURE)
+  if (formal->attr.flavor != FL_PROCEDURE && !act_sym->ts.interface)
{
  if (where)
gfc_error ("Invalid procedure argument at %L", >where);
  return false;
}
+  else if (act_sym->ts.interface
+  && !gfc_compare_interfaces (formal, act_sym->ts.interface,
+  act_sym->name, 0, 1, err,
+  sizeof(err),NULL, NULL))
+   {
+ if (where)
+   gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
+  " %s", formal->name, >where, err);
+ return false;
+   }
 
   if (!gfc_compare_interfaces (formal, act_sym, act_sym->name, 0, 1, err,
   sizeof(err), NULL, NULL))
diff --git a/gcc/testsuite/gfortran.dg/pr106999.f90 
b/gcc/testsuite/gfortran.dg/pr106999.f90
new file mode 100644
index 000..f05a27006f6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106999.f90
@@ -0,0 +1,33 @@
+! { dg-do compile }
+! Test the fix for PR106999
+! Contributed by Gerhard Steinmetz  
+program p
+   type t
+  integer :: i
+  procedure(g), pointer :: f
+   end type
+   class(t), allocatable :: y, z
+   procedure(g), pointer :: ff
+   allocate (z)
+   z%i = 42
+   z%f => g
+   ff => g
+   call r(z%f)
+   call s(z%f) ! { dg-error "Interface mismatch in dummy procedure" }
+   call s(ff)  ! { dg-error "Interface mismatch in dummy procedure" }
+contains
+   subroutine g(x)
+  class(t) :: x
+  x%i = 84
+   end
+   subroutine r(x)
+  procedure(g) :: x
+  print *, "in r"
+  allocate (y)
+  call x(y)
+  print *, y%i
+   end
+   subroutine s(x)
+  class(*) :: x
+   end subroutine
+end


[gcc r13-8691] Fortran: Fix wrong recursive errors and class initialization [PR112407]

2024-05-06 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:f598a1c8a77e678ca009b433fd849b4834594926

commit r13-8691-gf598a1c8a77e678ca009b433fd849b4834594926
Author: Paul Thomas 
Date:   Tue Apr 2 14:19:09 2024 +0100

Fortran: Fix wrong recursive errors and class initialization [PR112407]

2024-04-02  Paul Thomas  

gcc/fortran
PR fortran/112407
* resolve.cc (resolve_procedure_expression): Change the test for
for recursion in the case of hidden procedures from modules.
(resolve_typebound_static): Add warning for possible recursive
calls to typebound procedures.
* trans-expr.cc (gfc_trans_class_init_assign): Do not apply
default initializer to class dummy where component initializers
are all null.

gcc/testsuite/
PR fortran/112407
* gfortran.dg/pr112407a.f90: New test.
* gfortran.dg/pr112407b.f90: New test.

(cherry picked from commit 35408b3669fac104cd380582b32e32c64a603d8b)

Diff:
---
 gcc/fortran/resolve.cc  | 23 +--
 gcc/fortran/trans-expr.cc   | 16 
 gcc/testsuite/gfortran.dg/pr112407a.f90 | 71 +
 gcc/testsuite/gfortran.dg/pr112407b.f90 | 58 +++
 4 files changed, 164 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index e12997bc4a0..388209d2832 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -1950,12 +1950,20 @@ resolve_procedure_expression (gfc_expr* expr)
   || (sym->attr.function && sym->result == sym))
 return true;
 
-  /* A non-RECURSIVE procedure that is used as procedure expression within its
+   /* A non-RECURSIVE procedure that is used as procedure expression within its
  own body is in danger of being called recursively.  */
   if (is_illegal_recursion (sym, gfc_current_ns))
-gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
-" itself recursively.  Declare it RECURSIVE or use"
-" %<-frecursive%>", sym->name, >where);
+{
+  if (sym->attr.use_assoc && expr->symtree->name[0] == '@')
+   gfc_warning (0, "Non-RECURSIVE procedure %qs from module %qs is "
+" possibly calling itself recursively in procedure %qs. "
+" Declare it RECURSIVE or use %<-frecursive%>",
+sym->name, sym->module, gfc_current_ns->proc_name->name);
+  else
+   gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
+" itself recursively.  Declare it RECURSIVE or use"
+" %<-frecursive%>", sym->name, >where);
+}
 
   return true;
 }
@@ -6624,6 +6632,13 @@ resolve_typebound_static (gfc_expr* e, gfc_symtree** 
target,
   if (st)
*target = st;
 }
+
+  if (is_illegal_recursion ((*target)->n.sym, gfc_current_ns)
+  && !e->value.compcall.tbp->deferred)
+gfc_warning (0, "Non-RECURSIVE procedure %qs at %L is possibly calling"
+" itself recursively.  Declare it RECURSIVE or use"
+" %<-frecursive%>", (*target)->n.sym->name, >where);
+
   return true;
 }
 
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 5e4d04483ec..c7ec591e279 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1692,6 +1692,7 @@ gfc_trans_class_init_assign (gfc_code *code)
   tree tmp;
   gfc_se dst,src,memsz;
   gfc_expr *lhs, *rhs, *sz;
+  gfc_component *cmp;
 
   gfc_start_block ();
 
@@ -1708,6 +1709,21 @@ gfc_trans_class_init_assign (gfc_code *code)
   /* The _def_init is always scalar.  */
   rhs->rank = 0;
 
+  /* Check def_init for initializers.  If this is a dummy with all default
+ initializer components NULL, return NULL_TREE and use the passed value as
+ required by F2018(8.5.10).  */
+  if (!lhs->ref && lhs->symtree->n.sym->attr.dummy)
+{
+  cmp = rhs->ref->next->u.c.component->ts.u.derived->components;
+  for (; cmp; cmp = cmp->next)
+   {
+ if (cmp->initializer)
+   break;
+ else if (!cmp->next)
+   return build_empty_stmt (input_location);
+   }
+}
+
   if (code->expr1->ts.type == BT_CLASS
   && CLASS_DATA (code->expr1)->attr.dimension)
 {
diff --git a/gcc/testsuite/gfortran.dg/pr112407a.f90 
b/gcc/testsuite/gfortran.dg/pr112407a.f90
new file mode 100644
index 000..470f4191611
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr112407a.f90
@@ -0,0 +1,71 @@
+! { dg-do run }
+! Test of an issue found in the investigation of PR112407
+! Contributed by Tomas Trnka  
+!
+module m
+  private new_t
+
+  type s
+procedure(),pointer,nopass :: op
+  end type
+
+  type :: t
+integer :: i
+type (s) :: s
+  contains
+procedure :: new_t
+procedure :: bar
+procedure :: add_t
+generic :: new => new_t, bar
+generic, public :: assignment(=) => add_t
+final :: 

[gcc r13-8690] Fortran: Fix a gimplifier ICE/wrong result with finalization [PR36337]

2024-05-06 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:9f204cc695d27d0b8eb69d9a4d266261171185ae

commit r13-8690-g9f204cc695d27d0b8eb69d9a4d266261171185ae
Author: Paul Thomas 
Date:   Fri Mar 29 07:23:19 2024 +

Fortran: Fix a gimplifier ICE/wrong result with finalization [PR36337]

2024-03-29  Paul Thomas  

gcc/fortran
PR fortran/36337
PR fortran/110987
PR fortran/113885
* trans-expr.cc (gfc_trans_assignment_1): Place finalization
block before rhs post block for elemental rhs.
* trans.cc (gfc_finalize_tree_expr): Check directly if a type
has no components, rather than the zero components attribute.
Treat elemental zero component expressions in the same way as
scalars.

gcc/testsuite/
PR fortran/113885
* gfortran.dg/finalize_54.f90: New test.
* gfortran.dg/finalize_55.f90: New test.

gcc/testsuite/
PR fortran/110987
* gfortran.dg/finalize_56.f90: New test.

(cherry picked from commit 3c793f0361bc66d2a6bf0b3e1fb3234fc511e2a6)

Diff:
---
 gcc/fortran/trans-expr.cc |   9 +-
 gcc/fortran/trans.cc  |   6 +-
 gcc/testsuite/gfortran.dg/finalize_54.f90 |  47 +
 gcc/testsuite/gfortran.dg/finalize_55.f90 |  89 
 gcc/testsuite/gfortran.dg/finalize_56.f90 | 168 ++
 5 files changed, 313 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index c3f02c83b3f..5e4d04483ec 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -12182,11 +12182,14 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * 
expr2, bool init_flag,
   gfc_add_block_to_block (, );
   gfc_add_expr_to_block (, tmp);
 
-  /* Add the post blocks to the body.  */
-  if (!l_is_temp)
+  /* Add the post blocks to the body.  Scalar finalization must appear before
+ the post block in case any dellocations are done.  */
+  if (rse.finalblock.head
+  && (!l_is_temp || (expr2->expr_type == EXPR_FUNCTION
+&& gfc_expr_attr (expr2).elemental)))
 {
-  gfc_add_block_to_block (, );
   gfc_add_block_to_block (, );
+  gfc_add_block_to_block (, );
 }
   else
 gfc_add_block_to_block (, );
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index f7745add045..67ac06138e1 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1527,7 +1527,7 @@ gfc_finalize_tree_expr (gfc_se *se, gfc_symbol *derived,
 }
   else if (derived && gfc_is_finalizable (derived, NULL))
 {
-  if (derived->attr.zero_comp && !rank)
+  if (!derived->components && (!rank || attr.elemental))
{
  /* Any attempt to assign zero length entities, causes the gimplifier
 all manner of problems. Instead, a variable is created to act as
@@ -1578,7 +1578,7 @@ gfc_finalize_tree_expr (gfc_se *se, gfc_symbol *derived,
  final_fndecl);
   if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
 {
-  if (is_class)
+  if (is_class || attr.elemental)
desc = gfc_conv_scalar_to_descriptor (se, desc, attr);
   else
{
@@ -1588,7 +1588,7 @@ gfc_finalize_tree_expr (gfc_se *se, gfc_symbol *derived,
}
 }
 
-  if (derived && derived->attr.zero_comp)
+  if (derived && !derived->components)
 {
   /* All the conditions below break down for zero length derived types.  */
   tmp = build_call_expr_loc (input_location, final_fndecl, 3,
diff --git a/gcc/testsuite/gfortran.dg/finalize_54.f90 
b/gcc/testsuite/gfortran.dg/finalize_54.f90
new file mode 100644
index 000..73d32b1b333
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/finalize_54.f90
@@ -0,0 +1,47 @@
+! { dg-do compile }
+! Test the fix for PR113885, where not only was there a gimplifier ICE
+! for a derived type 't' with no components but, with a component, gfortran
+! gave wrong results.
+! Contributed by David Binderman  
+!
+module types
+  type t
+   contains
+ final :: finalize
+  end type t
+contains
+  pure subroutine finalize(x)
+type(t), intent(inout) :: x
+  end subroutine finalize
+end module types
+
+subroutine test1(x)
+  use types
+  interface
+ elemental function elem(x)
+   use types
+   type(t), intent(in) :: x
+   type(t) :: elem
+ end function elem
+  end interface
+  type(t) :: x(:)
+  x = elem(x)
+end subroutine test1
+
+subroutine test2(x)
+  use types
+  interface
+ elemental function elem(x)
+   use types
+   type(t), intent(in) :: x
+   type(t) :: elem
+ end function elem
+ elemental function elem2(x, y)
+   use types
+   type(t), intent(in) :: x, y
+   type(t) :: elem2
+ end function elem2
+  end interface
+  type(t) :: x(:)
+  x = elem2(elem(x), elem(x))
+end subroutine test2
diff --git a/gcc/testsuite/gfortran.dg/finalize_55.f90 

[gcc r15-202] ada: Allow use of writable parameters inside function with side-effects

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:ec1cdad89afed4d5fc8617c3de3c1950ca55ba7e

commit r15-202-gec1cdad89afed4d5fc8617c3de3c1950ca55ba7e
Author: Piotr Trojanek 
Date:   Thu Jan 4 17:37:06 2024 +0100

ada: Allow use of writable parameters inside function with side-effects

Writable parameters can be used as global outputs inside functions with
side-effects.

gcc/ada/

* sem_prag.adb (Collect_Global_Item): Handle functions with
side-effects.

Diff:
---
 gcc/ada/sem_prag.adb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 25a98cb414e..5764992237b 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31656,8 +31656,9 @@ package body Sem_Prag is
--  outputs when the related type is access-to-variable.
 
if Ekind (Formal) = E_In_Parameter
- and then Ekind (Spec_Id) not in E_Function
-   | E_Generic_Function
+ and then (Ekind (Spec_Id) not in E_Function
+| E_Generic_Function
+ or else Is_Function_With_Side_Effects (Spec_Id))
  and then Is_Access_Variable (Etype (Formal))
then
   Append_New_Elmt (Formal, Subp_Outputs);


[gcc r15-201] ada: Cleanup collecting of implicit outputs

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d917954922f38652eb314f096e130ecaa53e8441

commit r15-201-gd917954922f38652eb314f096e130ecaa53e8441
Author: Piotr Trojanek 
Date:   Thu Jan 4 17:10:47 2024 +0100

ada: Cleanup collecting of implicit outputs

Move handling of IN parameters to where both IN and IN OUT parameters
are handled. This makes the code marginally more efficient and
symmetrical to handling of implicit inputs.

gcc/ada/

* sem_prag.adb (Collect_Global_Item): Move code.

Diff:
---
 gcc/ada/sem_prag.adb | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index ab60a8ad1d5..25a98cb414e 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31651,6 +31651,17 @@ package body Sem_Prag is
  while Present (Formal) loop
 if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then
Append_New_Elmt (Formal, Subp_Inputs);
+
+   --  IN parameters of procedures and protected entries can act as
+   --  outputs when the related type is access-to-variable.
+
+   if Ekind (Formal) = E_In_Parameter
+ and then Ekind (Spec_Id) not in E_Function
+   | E_Generic_Function
+ and then Is_Access_Variable (Etype (Formal))
+   then
+  Append_New_Elmt (Formal, Subp_Outputs);
+   end if;
 end if;
 
 if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then
@@ -31667,17 +31678,6 @@ package body Sem_Prag is
end if;
 end if;
 
---  IN parameters of procedures and protected entries can act as
---  outputs when the related type is access-to-variable.
-
-if Ekind (Formal) = E_In_Parameter
-  and then Ekind (Spec_Id) not in E_Function
-| E_Generic_Function
-  and then Is_Access_Variable (Etype (Formal))
-then
-   Append_New_Elmt (Formal, Subp_Outputs);
-end if;
-
 Next_Formal (Formal);
  end loop;


[gcc r15-200] ada: Support writable parameters in Depends with side-effects

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0f3324fd8ba91b16905e4b03eaf1e35a728f1027

commit r15-200-g0f3324fd8ba91b16905e4b03eaf1e35a728f1027
Author: Piotr Trojanek 
Date:   Thu Jan 4 15:01:55 2024 +0100

ada: Support writable parameters in Depends with side-effects

Functions with side-effects can modify writable parameters of mode IN,
so these parameters must be allowed to appear in their Depends aspects.

gcc/ada/

* sem_prag.adb (Find_Role): Handle functions with side-effects
like procedures.

Diff:
---
 gcc/ada/sem_prag.adb | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 299e388167f..ab60a8ad1d5 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -1383,10 +1383,11 @@ package body Sem_Prag is
(Item_Is_Input  : out Boolean;
 Item_Is_Output : out Boolean)
  is
---  A constant or an IN parameter of a procedure or a protected
---  entry, if it is of an access-to-variable type, should be
---  handled like a variable, as the underlying memory pointed-to
---  can be modified. Use Adjusted_Kind to do this adjustment.
+--  A constant or an IN parameter of a protected entry, procedure,
+--  or function with side-effects, if it is of an
+--  access-to-variable type, should be handled like a variable, as
+--  the underlying memory pointed-to can be modified. Use
+--  Adjusted_Kind to do this adjustment.
 
 Adjusted_Kind : Entity_Kind := Ekind (Item_Id);
 
@@ -1394,11 +1395,15 @@ package body Sem_Prag is
 if (Ekind (Item_Id) in E_Constant | E_Generic_In_Parameter
   or else
   (Ekind (Item_Id) = E_In_Parameter
- and then Ekind (Scope (Item_Id))
-not in E_Function | E_Generic_Function))
+ and then
+   (Ekind (Scope (Item_Id)) not in E_Function
+ | E_Generic_Function
+  or else
+Is_Function_With_Side_Effects (Scope (Item_Id)
   and then Is_Access_Variable (Etype (Item_Id))
-  and then Ekind (Spec_Id) not in E_Function
-| E_Generic_Function
+  and then (Ekind (Spec_Id) not in E_Function
+ | E_Generic_Function
+  or else Is_Function_With_Side_Effects (Spec_Id))
 then
Adjusted_Kind := E_Variable;
 end if;


[gcc r15-198] ada: Give error for reference to nonvisible library unit

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9737a48553b7b489bbecb59b6dd9a96ed02bb1f8

commit r15-198-g9737a48553b7b489bbecb59b6dd9a96ed02bb1f8
Author: Bob Duff 
Date:   Wed Jan 3 16:32:51 2024 -0500

ada: Give error for reference to nonvisible library unit

This patch fixes a bug where the compiler would allow
a name X to refer to a library unit that is not visible.
In particular, this happens when the name X occurs in the
private part of a library package, and the parent of that
package contains an instantiation of a generic package, and the
spec of that generic package has "private with X;",
but there is no "private with X;" or "with X;" that applies
to the place where the name X occurs.

Also misc cleanup.

gcc/ada/

* sem_ch10.adb (Expand_With_Clause): Misc cleanup.
(Install_Private_With_Clauses): Avoid installing a private
with_clause that comes from an instantiated generic
(it is marked as Implicit_With, but doesn't come from a parent
with). Fix typo in comment, and other minor cleanups.

Diff:
---
 gcc/ada/sem_ch10.adb | 49 +
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index 43adbbc54bf..7fc623b6278 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -3425,17 +3425,15 @@ package body Sem_Ch10 is
   --  Local variables
 
   Ent   : constant Entity_Id  := Entity (Nam);
-  Withn : Node_Id;
+  Withn : constant Node_Id :=
+Make_With_Clause
+  (Loc, Name => Build_Unit_Name (Nam),
+   First_Name => True, Last_Name => True);
 
--  Start of processing for Expand_With_Clause
 
begin
-  Withn :=
-Make_With_Clause (Loc,
-  Name => Build_Unit_Name (Nam));
-
   Set_Corresponding_Spec (Withn, Ent);
-  Set_First_Name (Withn);
   Set_Implicit_With  (Withn);
   Set_Library_Unit   (Withn, Parent (Unit_Declaration_Node (Ent)));
   Set_Parent_With(Withn);
@@ -3570,7 +3568,6 @@ package body Sem_Ch10 is
   P  : constant Node_Id:= Parent_Spec (Child_Unit);
   P_Unit : Node_Id := Unit (P);
   P_Name : constant Entity_Id  := Get_Parent_Entity (P_Unit);
-  Withn  : Node_Id;
 
   function Build_Ancestor_Name (P : Node_Id) return Node_Id;
   --  Build prefix of child unit name. Recurse if needed
@@ -3655,21 +3652,25 @@ package body Sem_Ch10 is
  return;
   end if;
 
-  Withn := Make_With_Clause (Loc, Name => Build_Unit_Name);
+  declare
+ Withn : constant Node_Id :=
+   Make_With_Clause
+ (Loc, Name => Build_Unit_Name,
+  First_Name => True, Last_Name => True);
+  begin
+ Set_Corresponding_Spec (Withn, P_Name);
+ Set_Implicit_With  (Withn);
+ Set_Library_Unit   (Withn, P);
+ Set_Parent_With(Withn);
 
-  Set_Corresponding_Spec (Withn, P_Name);
-  Set_First_Name (Withn);
-  Set_Implicit_With  (Withn);
-  Set_Library_Unit   (Withn, P);
-  Set_Parent_With(Withn);
+ --  Node is placed at the beginning of the context items, so that
+ --  subsequent use clauses on the parent can be validated.
 
-  --  Node is placed at the beginning of the context items, so that
-  --  subsequent use clauses on the parent can be validated.
+ Prepend (Withn, Context_Items (N));
+ Mark_Rewrite_Insertion (Withn);
 
-  Prepend (Withn, Context_Items (N));
-  Mark_Rewrite_Insertion (Withn);
-
-  Install_With_Clause (Withn);
+ Install_With_Clause (Withn);
+  end;
 
   if Is_Child_Spec (P_Unit) then
  Implicit_With_On_Parent (P_Unit, N);
@@ -4524,13 +4525,21 @@ package body Sem_Ch10 is
   if Nkind (Parent (Decl)) = N_Compilation_Unit then
  Item := First (Context_Items (Parent (Decl)));
  while Present (Item) loop
+--  If Item is a private with clause, install it, but do not
+--  install implicit private with's that come from (for example)
+--  with's on instantiated generics. DO install implicit private
+--  with's that come from parents, which is necessary in general,
+--  but ???not quite right if the former (generic) case also
+--  applies.
+
 if Nkind (Item) = N_With_Clause
   and then Private_Present (Item)
+  and then (not Implicit_With (Item) or else Parent_With (Item))
 then
--  If the unit is an ancestor of the current one, it is the
--  case of a private limited with clause on a child unit, and
--  the compilation of one of its descendants, in that case the
-   --  limited view is errelevant.
+   --  limited view is irrelevant.
 
   

[gcc r15-199] ada: Excess finalization on return of call to dispatching constructor

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:911d921759e4a32bac81016b2dda1e26147ba5d8

commit r15-199-g911d921759e4a32bac81016b2dda1e26147ba5d8
Author: Gary Dismukes 
Date:   Thu Jan 4 00:34:33 2024 +

ada: Excess finalization on return of call to dispatching constructor

The compiler expands a too-early finalization call for the result
object of an extended return statement that returns a call to a
dispatching constructor function for a limited interface type,
resulting in premature (and extra) finalization of the result.
The temporary object that the compiler creates to hold the result
of the build-in-place call loses the fact that it comes from a
return, and the wrong BIP allocation form may be passed in the
call to the dispatching constructor, and the later code for dealing
with finalization in Exp_Ch7.Build_Finalizer incorrectly finalizes
the result object.

gcc/ada/

* exp_ch6.adb
(Make_Build_In_Place_Iface_Call_In_Object_Declaration): Set the
Is_Return_Object flag on the entity of the temp object created to
hold the BIP call result, from the flag on the passed-in object
declaration's entity. Update copyright notice to 2024.

Diff:
---
 gcc/ada/exp_ch6.adb | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index fcfd1d7f0bf..a89c9af0bb2 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -9393,6 +9393,16 @@ package body Exp_Ch6 is
   Insert_Action (Obj_Decl, Tmp_Decl);
   Expander_Mode_Restore;
 
+  --  Inherit Is_Return_Object from the parent object to the temp object,
+  --  so that Make_In_Build_Place_Call_In_Object_Declaration will handle
+  --  the temp properly in cases where there's a BIP_Alloc_Form formal of
+  --  an enclosing function that should be passed along (and which also
+  --  ensures that if the BIP call is used as a function result and it
+  --  requires finalization, then it will not be finalized prematurely
+  --  or redundantly).
+
+  Set_Is_Return_Object (Tmp_Id, Is_Return_Object (Obj_Id));
+
   Make_Build_In_Place_Call_In_Object_Declaration
 (Obj_Decl  => Tmp_Decl,
  Function_Call => Expression (Tmp_Decl));


[gcc r15-197] ada: Tweak discriminant source locations

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:615c33804f6a1d3f6dcc02308f59b24c735881dc

commit r15-197-g615c33804f6a1d3f6dcc02308f59b24c735881dc
Author: Ronan Desplanques 
Date:   Wed Jan 3 12:09:03 2024 +0100

ada: Tweak discriminant source locations

This patch changes the source location information for the default
expressions of discrimants to better represent the fact that they're
evaluated at the point of object declaration, in the cases where
a Build_Default_Subtype optimization is performed. This fixes a
regression with CodePeer diagnostics introduced by a recent change
around Build_Default_Subtype optimizations.

gcc/ada/

* sem_util.adb (Build_Default_Subtype): Tweak source location
information.

Diff:
---
 gcc/ada/sem_util.adb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index c47904f168c..18c9de05cf9 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -1780,7 +1780,8 @@ package body Sem_Util is
   begin
  while Present (Disc) loop
 Append_To (Constraints,
-  New_Copy_Tree (Discriminant_Default_Value (Disc)));
+   New_Copy_Tree
+ (Discriminant_Default_Value (Disc), New_Sloc => Loc));
 Next_Discriminant (Disc);
  end loop;


[gcc r15-193] ada: Spurious reference warning on qualified expression

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c8cf8c3fd0793e1d7ba8c6d0e906384f4fd9170c

commit r15-193-gc8cf8c3fd0793e1d7ba8c6d0e906384f4fd9170c
Author: Justin Squirek 
Date:   Thu Dec 21 18:41:15 2023 +

ada: Spurious reference warning on qualified expression

Incremental improvement/clean up.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add coverage for
Preconditions

Diff:
---
 gcc/ada/sem_warn.adb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 54d8920a943..57bdee65356 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1978,7 +1978,8 @@ package body Sem_Warn is
if Nkind (Nod) = N_Pragma
  and then
Pragma_Name_Unmapped (Nod)
-in Name_Postcondition
+in Name_Precondition
+ | Name_Postcondition
  | Name_Refined_Post
  | Name_Contract_Cases
then


[gcc r15-191] ada: Spurious reference warning on qualified expression

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:373921dc7b2ada3960b5fbb99cb4cf543ff4ffa0

commit r15-191-g373921dc7b2ada3960b5fbb99cb4cf543ff4ffa0
Author: Justin Squirek 
Date:   Thu Dec 21 18:35:22 2023 +

ada: Spurious reference warning on qualified expression

Incremental improvement/clean up.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Renamed to
Within_Contract_Or_Predicate.

Diff:
---
 gcc/ada/sem_warn.adb | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 0a54b3eda50..8317b449021 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1958,16 +1958,16 @@ package body Sem_Warn is
  SR : Entity_Id;
  SE : constant Entity_Id := Scope (E);
 
- function Within_Postcondition return Boolean;
- --  Returns True if N is within a Postcondition, a
- --  Refined_Post, an Ensures component in a Test_Case,
- --  or a Contract_Cases.
+ function Within_Contract_Or_Predicate  return Boolean;
+ --  Returns True if N is within a contract or predicate,
+ --  an Ensures component in a Test_Case, or a
+ --  Contract_Cases.
 
- --
- -- Within_Postcondition --
- --
+ --
+ -- Within_Contract_Or_Predicate --
+ --
 
- function Within_Postcondition return Boolean is
+ function Within_Contract_Or_Predicate return Boolean is
 Nod, P : Node_Id;
 
  begin
@@ -2012,7 +2012,7 @@ package body Sem_Warn is
 end loop;
 
 return False;
- end Within_Postcondition;
+ end Within_Contract_Or_Predicate;
 
   --  Start of processing for Potential_Unset_Reference
 
@@ -2136,7 +2136,7 @@ package body Sem_Warn is
  --  postcondition, since the expression occurs in a
  --  place unrelated to the actual test.
 
- if not Within_Postcondition then
+ if not Within_Contract_Or_Predicate then
 
 --  Here we definitely have a case for giving a warning
 --  for a reference to an unset value. But we don't


[gcc r15-196] ada: Do not attempt to generate finalization actions with restricted profile

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:98b26f695bdcb1e4eee2c27742fd6ab534bb7d55

commit r15-196-g98b26f695bdcb1e4eee2c27742fd6ab534bb7d55
Author: Eric Botcazou 
Date:   Fri Dec 22 12:46:29 2023 +0100

ada: Do not attempt to generate finalization actions with restricted profile

These actions are not supported with this profile, but we were nevertheless
attempting to generate them for protected objects.

gcc/ada/

* exp_ch7.adb (Build_Finalizer.Process_Declarations): Do not call
Processing_Actions for simple protected objects if the profile is
restricted.
* exp_util.adb (Requires_Cleanup_Actions): Do not return True for
simple protected objects if the profile is restricted.

Diff:
---
 gcc/ada/exp_ch7.adb  | 6 +-
 gcc/ada/exp_util.adb | 8 ++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 7a8457683c5..99142a527fa 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -2526,9 +2526,12 @@ package body Exp_Ch7 is
then
   Processing_Actions (Decl);
 
-   --  Simple protected objects which use type System.Tasking.
+   --  Simple protected objects which use the type System.Tasking.
--  Protected_Objects.Protection to manage their locks should
--  be treated as controlled since they require manual cleanup.
+   --  but not for restricted run-time libraries (Ravenscar), see
+   --  also Cleanup_Protected_Object.
+
--  The only exception is illustrated in the following example:
 
-- package Pkg is
@@ -2561,6 +2564,7 @@ package body Exp_Ch7 is
elsif Ekind (Obj_Id) = E_Variable
  and then not In_Library_Level_Package_Body (Obj_Id)
  and then Has_Simple_Protected_Object (Obj_Typ)
+ and then not Restricted_Profile
then
   Processing_Actions (Decl, Is_Protected => True);
end if;
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 732a02fc5d8..533127f26c2 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -12999,9 +12999,12 @@ package body Exp_Util is
 then
return True;
 
---  Simple protected objects which use type System.Tasking.
+--  Simple protected objects which use the type System.Tasking.
 --  Protected_Objects.Protection to manage their locks should be
---  treated as controlled since they require manual cleanup.
+--  treated as controlled since they require manual cleanup, but
+--  not for restricted run-time libraries (Ravenscar), see also
+--  Cleanup_Protected_Object in Exp_Ch7.
+
 --  The only exception is illustrated in the following example:
 
 -- package Pkg is
@@ -13034,6 +13037,7 @@ package body Exp_Util is
 elsif Ekind (Obj_Id) = E_Variable
   and then not In_Library_Level_Package_Body (Obj_Id)
   and then Has_Simple_Protected_Object (Obj_Typ)
+  and then not Restricted_Profile
 then
return True;
 end if;


[gcc r15-195] ada: Small cleanup in C/C++ front-end interface

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:22a9ce9946525b4b039841786d82631617b2ef41

commit r15-195-g22a9ce9946525b4b039841786d82631617b2ef41
Author: Eric Botcazou 
Date:   Thu Dec 21 22:56:16 2023 +0100

ada: Small cleanup in C/C++ front-end interface

The fe.h header file is supposed to contain only the declarations needed
by the code in the gcc-interface repository.

gcc/ada/

* fe.h: Remove unused declarations and add 'extern' to others.

no-issue-check

Diff:
---
 gcc/ada/fe.h | 272 +--
 1 file changed, 41 insertions(+), 231 deletions(-)

diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 397045ea583..692c29a70af 100644
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -377,305 +377,114 @@ extern Boolean Get_Warn_On_Questionable_Layout (void);
 
 // The following corresponds to Ada code in Einfo.Utils.
 
-typedef Boolean B;
-typedef Component_Alignment_Kind C;
+typedef Boolean   B;
 typedef Entity_Id E;
-typedef Mechanism_Type M;
-typedef Node_Id N;
-typedef Uint U;
-typedef Ureal R;
-typedef Elist_Id L;
-typedef List_Id S;
-
-#define Is_Access_Object_Type einfo__utils__is_access_object_type
-B Is_Access_Object_Type   (E Id);
-
-#define Is_Named_Access_Type einfo__utils__is_named_access_type
-B Is_Named_Access_Type(E Id);
+typedef Node_Id   N;
 
 #define Address_Clause einfo__utils__address_clause
-N Address_Clause  (E Id);
-
-#define Aft_Value einfo__utils__aft_value
-U Aft_Value   (E Id);
+extern N Address_Clause (E Id);
 
 #define Alignment_Clause einfo__utils__alignment_clause
-N Alignment_Clause(E Id);
+extern N Alignment_Clause (E Id);
 
 #define Base_Type einfo__utils__base_type
-E Base_Type   (E Id);
+extern E Base_Type (E Id);
 
 #define Declaration_Node einfo__utils__declaration_node
-N Declaration_Node(E Id);
+extern N Declaration_Node (E Id);
 
 #define Designated_Type einfo__utils__designated_type
-E Designated_Type (E Id);
-
-#define First_Component einfo__utils__first_component
-E First_Component (E Id);
-
-#define First_Component_Or_Discriminant 
einfo__utils__first_component_or_discriminant
-E First_Component_Or_Discriminant (E Id);
+extern E Designated_Type (E Id);
 
 #define First_Formal einfo__utils__first_formal
-E First_Formal(E Id);
+extern E First_Formal (E Id);
 
 #define First_Formal_With_Extras einfo__utils__first_formal_with_extras
-E First_Formal_With_Extras(E Id);
-
-#define Has_Attach_Handler einfo__utils__has_attach_handler
-B Has_Attach_Handler  (E Id);
-
-#define Has_Entries einfo__utils__has_entries
-B Has_Entries (E Id);
+extern E First_Formal_With_Extras (E Id);
 
 #define Has_Foreign_Convention einfo__utils__has_foreign_convention
-B Has_Foreign_Convention  (E Id);
-
-#define Has_Interrupt_Handler einfo__utils__has_interrupt_handler
-B Has_Interrupt_Handler   (E Id);
-
-#define Has_Non_Limited_View einfo__utils__has_non_limited_view
-B Has_Non_Limited_View(E Id);
-
-#define Has_Non_Null_Abstract_State einfo__utils__has_non_null_abstract_state
-B Has_Non_Null_Abstract_State (E Id);
-
-#define Has_Non_Null_Visible_Refinement 
einfo__utils__has_non_null_visible_refinement
-B Has_Non_Null_Visible_Refinement (E Id);
-
-#define Has_Null_Abstract_State einfo__utils__has_null_abstract_state
-B Has_Null_Abstract_State (E Id);
-
-#define Has_Null_Visible_Refinement einfo__utils__has_null_visible_refinement
-B Has_Null_Visible_Refinement (E Id);
+extern B Has_Foreign_Convention (E Id);
 
 #define Implementation_Base_Type einfo__utils__implementation_base_type
-E Implementation_Base_Type(E Id);
-
-#define Is_Base_Type einfo__utils__is_base_type
-B Is_Base_Type(E Id);
+extern E Implementation_Base_Type (E Id);
 
 #define Is_Boolean_Type einfo__utils__is_boolean_type
-B Is_Boolean_Type (E Id);
-
-#define Is_Constant_Object einfo__utils__is_constant_object
-B Is_Constant_Object  (E Id);
-
-#define Is_Controlled einfo__utils__is_controlled
-B Is_Controlled   (E Id);
-
-#define Is_Discriminal einfo__utils__is_discriminal
-B Is_Discriminal  (E Id);
-
-#define Is_Dynamic_Scope einfo__utils__is_dynamic_scope
-B Is_Dynamic_Scope(E Id);
-
-#define Is_Elaboration_Target einfo__utils__is_elaboration_target
-B Is_Elaboration_Target   (E Id);
-
-#define Is_External_State einfo__utils__is_external_state
-B Is_External_State   (E Id);
-
-#define Is_Finalizer einfo__utils__is_finalizer
-B Is_Finalizer(E Id);
-
-#define Is_Null_State einfo__utils__is_null_state
-B Is_Null_State   (E Id);
-

[gcc r15-190] ada: Spurious reference warning on qualified expression

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0b7c0811ced8c98b4bebd1bc89f2272216000900

commit r15-190-g0b7c0811ced8c98b4bebd1bc89f2272216000900
Author: Justin Squirek 
Date:   Thu Dec 21 18:31:27 2023 +

ada: Spurious reference warning on qualified expression

This patch fixes an error in the compiler whereby an assignment to an out
formal (whose type requires a predicate check) can lead to spurious
"value may be referenced before it has a value" warnings when the RHS is a
qualified expression.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add case to ignore
references within generated predicate function calls.

Diff:
---
 gcc/ada/sem_warn.adb | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index eaf9a257ba0..0a54b3eda50 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1982,6 +1982,16 @@ package body Sem_Warn is
then
   return True;
 
+   --  Verify we are not within a generated predicate
+   --  function call.
+
+   elsif Nkind (Nod) = N_Function_Call
+ and then Is_Entity_Name (Name (Nod))
+ and then Is_Predicate_Function
+(Entity (Name (Nod)))
+   then
+  return True;
+
elsif Present (Parent (Nod)) then
   P := Parent (Nod);


[gcc r15-194] ada: Deconstruct support for abstract states with Relaxed_Initialization

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:cc0110cbd86fab6d6cf67742aad53b97fd9eb061

commit r15-194-gcc0110cbd86fab6d6cf67742aad53b97fd9eb061
Author: Piotr Trojanek 
Date:   Thu Dec 21 17:31:51 2023 +0100

ada: Deconstruct support for abstract states with Relaxed_Initialization

GNATprove newer implemented support for abstract states with aspect
Relaxed_Initialization, so the frontend support is now deconstructed.

gcc/ada/

* einfo-utils.adb (Is_Relaxed_Initialization_State): Remove.
* einfo-utils.ads (Is_Relaxed_Initialization_State): Remove.
* einfo.ads: Remove description of removed aspect.
* fe.h (Is_Relaxed_Initialization_State): Remove.
* sem_prag.adb (Analyze_Abstract_State): Remove support for
Relaxed_Initialization.
* sem_util.adb (Has_Relaxed_Initialization): Likewise.
* sem_util.ads (Has_Relaxed_Initialization): Likewise.

Diff:
---
 gcc/ada/einfo-utils.adb | 14 --
 gcc/ada/einfo-utils.ads |  1 -
 gcc/ada/einfo.ads   |  5 -
 gcc/ada/fe.h|  3 ---
 gcc/ada/sem_prag.adb| 25 +
 gcc/ada/sem_util.adb|  5 -
 gcc/ada/sem_util.ads|  6 +++---
 7 files changed, 12 insertions(+), 47 deletions(-)

diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index 00799eb9bee..438868ac757 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -1649,20 +1649,6 @@ package body Einfo.Utils is
   and then Is_Protected_Type (Corresponding_Concurrent_Type (Id));
end Is_Protected_Record_Type;
 
-   -
-   -- Is_Relaxed_Initialization_State --
-   -
-
-   function Is_Relaxed_Initialization_State (Id : E) return B is
-   begin
-  --  To qualify, the abstract state must appear with simple option
-  --  "Relaxed_Initialization" (SPARK RM 6.10).
-
-  return
-Ekind (Id) = E_Abstract_State
-  and then Has_Option (Id, Name_Relaxed_Initialization);
-   end Is_Relaxed_Initialization_State;
-

-- Is_Standard_Character_Type --

diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads
index 701d8ce59fb..d87a3e34f49 100644
--- a/gcc/ada/einfo-utils.ads
+++ b/gcc/ada/einfo-utils.ads
@@ -201,7 +201,6 @@ package Einfo.Utils is
function Is_Protected_Component (Id : E) return B with Inline;
function Is_Protected_Interface (Id : E) return B;
function Is_Protected_Record_Type (Id : E) return B with Inline;
-   function Is_Relaxed_Initialization_State (Id : E) return B;
function Is_Standard_Character_Type (Id : E) return B;
function Is_Standard_String_Type (Id : E) return B;
function Is_String_Type (Id : E) return B with Inline;
diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 6f563d5e62c..e3bfdb3507d 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -3219,10 +3219,6 @@ package Einfo is
 --   Applies to all entities, true for record types and subtypes,
 --   includes class-wide types and subtypes (which are also records).
 
---Is_Relaxed_Initialization_State (synthesized)
---   Applies to all entities, true for abstract states that are subject to
---   option Relaxed_Initialization.
-
 --Is_Remote_Call_Interface
 --   Defined in all entities. Set in E_Package and E_Generic_Package
 --   entities to which a pragma Remote_Call_Interface is applied, and
@@ -5129,7 +5125,6 @@ package Einfo is
--Has_Null_Visible_Refinement (synth)
--Is_External_State   (synth)
--Is_Null_State   (synth)
-   --Is_Relaxed_Initialization_State (synth)
--Is_Synchronized_State   (synth)
--Partial_Refinement_Constituents (synth)
 
diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h
index 6aaa3fdc4d3..397045ea583 100644
--- a/gcc/ada/fe.h
+++ b/gcc/ada/fe.h
@@ -501,9 +501,6 @@ B Is_Protected_Interface  (E Id);
 #define Is_Protected_Record_Type einfo__utils__is_protected_record_type
 B Is_Protected_Record_Type(E Id);
 
-#define Is_Relaxed_Initialization_State 
einfo__utils__is_relaxed_initialization_state
-B Is_Relaxed_Initialization_State (E Id);
-
 #define Is_Standard_Character_Type einfo__utils__is_standard_character_type
 B Is_Standard_Character_Type  (E Id);
 
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 39005aaea05..299e388167f 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -12181,16 +12181,15 @@ package body Sem_Prag is
 is
--  Flags used to verify the consistency of options
 
-   AR_Seen : Boolean := False;
-   AW_Seen : Boolean := False;
-   ER_Seen : Boolean := False;
-   EW_Seen : Boolean 

[gcc r15-192] ada: Spurious reference warning on qualified expression

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:6bcda3e0d7559b643f3c18f28e254ea8cb89d2b4

commit r15-192-g6bcda3e0d7559b643f3c18f28e254ea8cb89d2b4
Author: Justin Squirek 
Date:   Thu Dec 21 18:38:38 2023 +

ada: Spurious reference warning on qualified expression

Incremental improvement/clean up.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add/modify comments to
document various cases.

Diff:
---
 gcc/ada/sem_warn.adb | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 8317b449021..54d8920a943 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1973,6 +1973,8 @@ package body Sem_Warn is
  begin
 Nod := Parent (N);
 while Present (Nod) loop
+   --  General contract / predicate related pragma
+
if Nkind (Nod) = N_Pragma
  and then
Pragma_Name_Unmapped (Nod)
@@ -1992,6 +1994,8 @@ package body Sem_Warn is
then
   return True;
 
+   --  Deal with special 'Ensures' Test_Case component
+
elsif Present (Parent (Nod)) then
   P := Parent (Nod);


[gcc r15-188] ada: Make a couple of comment tweaks

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:a9a32d0e2208166d4e3cd8beac6738af1a74c68e

commit r15-188-ga9a32d0e2208166d4e3cd8beac6738af1a74c68e
Author: Eric Botcazou 
Date:   Thu Dec 21 12:01:06 2023 +0100

ada: Make a couple of comment tweaks

This removes a reference to a mechanism that didn't make it into the final
implementation and completes the description of another.

gcc/ada/

* libgnat/s-finpri.ads (Finalize_Master): Remove obsolete reference
in the description.
(Finalize_Object): Document the effects of repeated calls.

Diff:
---
 gcc/ada/libgnat/s-finpri.ads | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/libgnat/s-finpri.ads b/gcc/ada/libgnat/s-finpri.ads
index de775caee91..ab79ea2c664 100644
--- a/gcc/ada/libgnat/s-finpri.ads
+++ b/gcc/ada/libgnat/s-finpri.ads
@@ -92,13 +92,12 @@ package System.Finalization_Primitives with Preelaborate is
 
procedure Finalize_Master (Master : in out Finalization_Scope_Master);
--  Finalizes each of the controlled objects associated with Master, in the
-   --  reverse of the order in which they were attached, and releases the space
-   --  that was allocated on the secondary stack if Master.SS_Mark is not null.
-   --  Calls to this procedure with a Master that has already been finalized
-   --  have no effects.
+   --  reverse of the order in which they were attached. Calls to the procedure
+   --  with a Master that has already been finalized have no effects.
 
procedure Finalize_Object (Node : in out Master_Node);
-   --  Finalizes the controlled object attached to Node
+   --  Finalizes the controlled object attached to Node. Calls to the procedure
+   --  with a Node that has already been finalized have no effects.
 
procedure Suppress_Object_Finalize_At_End (Node : in out Master_Node);
--  Changes the state of Node to effectively suppress a call to Node's


[gcc r15-189] ada: Fix RM reference in comment

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:625d5f98d74863ca580008f3566768f46da2c109

commit r15-189-g625d5f98d74863ca580008f3566768f46da2c109
Author: Ronan Desplanques 
Date:   Thu Dec 21 12:39:23 2023 +0100

ada: Fix RM reference in comment

The RM 2.2(15) that the comment mentioned before this patch doesn't
exist. It's pretty clear that the comment meant to refer to
RM 2.2(14) instead.

gcc/ada/

* hostparm.ads: Fix reference to RM clause.

Diff:
---
 gcc/ada/hostparm.ads | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/hostparm.ads b/gcc/ada/hostparm.ads
index 11eef359d30..b2d2f814b32 100644
--- a/gcc/ada/hostparm.ads
+++ b/gcc/ada/hostparm.ads
@@ -48,7 +48,7 @@ package Hostparm is
--  have a valid Column_Number equal to Max_Line_Length to represent
--  the location of a "line too long" error.
--
-   --  200 is the minimum value required (RM 2.2(15)). The value set here
+   --  200 is the minimum value required (RM 2.2(14)). The value set here
--  can be reduced by the explicit use of the -gnatyM style switch.
 
Max_Name_Length : constant := 1024;


[gcc r15-186] ada: Replace references to PO_Simple by Protected_Objects in comments

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3b2f2aac29a881c5b68bb3d42bd9729545e82448

commit r15-186-g3b2f2aac29a881c5b68bb3d42bd9729545e82448
Author: Eric Botcazou 
Date:   Wed Dec 20 16:27:09 2023 +0100

ada: Replace references to PO_Simple by Protected_Objects in comments

The child unit was renamed a while ago.

gcc/ada/

* libgnarl/s-taprob.ads (Protection): Add cross-reference to the
counterpart in System.Tasking.Protected_Objects.Entries.
* libgnarl/s-taskin.ads (Locking Rules): Replace PO_Simple by
Protected_Objects.
* libgnarl/s-tpoben.ads (Protection_Entries): Likewise.

Diff:
---
 gcc/ada/libgnarl/s-taprob.ads | 6 ++
 gcc/ada/libgnarl/s-taskin.ads | 4 ++--
 gcc/ada/libgnarl/s-tpoben.ads | 4 ++--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/libgnarl/s-taprob.ads b/gcc/ada/libgnarl/s-taprob.ads
index 34cfcc7a9ba..e94ec71e768 100644
--- a/gcc/ada/libgnarl/s-taprob.ads
+++ b/gcc/ada/libgnarl/s-taprob.ads
@@ -207,6 +207,12 @@ package System.Tasking.Protected_Objects is
--  lock and allowed to return from the Lock or Lock_Read_Only call.
 
 private
+   --  The following type contains the GNARL state of a protected object.
+   --  The application-defined portion of the state (i.e. private objects)
+   --  is maintained by the compiler-generated code. Note that there is
+   --  another version declared in System.Tasking.Protected_Objects.Entries
+   --  that handles the case with entries and is controlled.
+
type Protection is record
   L : aliased Task_Primitives.Lock;
   --  Lock used to ensure mutual exclusive access to the protected object
diff --git a/gcc/ada/libgnarl/s-taskin.ads b/gcc/ada/libgnarl/s-taskin.ads
index 949fb7e6607..1bae7e114cf 100644
--- a/gcc/ada/libgnarl/s-taskin.ads
+++ b/gcc/ada/libgnarl/s-taskin.ads
@@ -70,9 +70,9 @@ package System.Tasking is
-- Unlock (Y);
 
--  Locks with lower (smaller) level number cannot be locked
-   --  while holding a lock with a higher level number. (The level
+   --  while holding a lock with a higher level number.
 
-   --  1. System.Tasking.PO_Simple.Protection.L (any PO lock)
+   --  1. System.Tasking.Protected_Objects.Protection.L (any PO lock)
--  2. System.Tasking.Initialization.Global_Task_Lock (in body)
--  3. System.Task_Primitives.Operations.Single_RTS_Lock
--  4. System.Tasking.Ada_Task_Control_Block.LL.L (any TCB lock)
diff --git a/gcc/ada/libgnarl/s-tpoben.ads b/gcc/ada/libgnarl/s-tpoben.ads
index d1e6b8533d2..a7091184223 100644
--- a/gcc/ada/libgnarl/s-tpoben.ads
+++ b/gcc/ada/libgnarl/s-tpoben.ads
@@ -79,8 +79,8 @@ package System.Tasking.Protected_Objects.Entries is
--  The following type contains the GNARL state of a protected object.
--  The application-defined portion of the state (i.e. private objects)
--  is maintained by the compiler-generated code. Note that there is a
-   --  simplified version of this type declared in System.Tasking.PO_Simple
-   --  that handle the simple case (no entries).
+   --  simplified version declared in System.Tasking.Protected_Objects that
+   --  handles the simple case (no entries) and is not controlled.
 
type Protection_Entries (Num_Entries : Protected_Entry_Index) is new
  Ada.Finalization.Limited_Controlled


[gcc r15-187] ada: Rework processing of special objects needing finalization

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:8d613b26d3d9d388dc85f95a035d4972dc3bc1ba

commit r15-187-g8d613b26d3d9d388dc85f95a035d4972dc3bc1ba
Author: Eric Botcazou 
Date:   Wed Dec 20 17:39:10 2023 +0100

ada: Rework processing of special objects needing finalization

This reworks the processing of special objects needing finalization in the
new implementation.  These special objects, i.e. return object in extended
return statements and transient objects, cannot be automatically handled by
the post-processing phase because they have additional requirements, either
conditional finalization for the former or immediate finalization for the
latter and, therefore, a specific processing during expansion is needed for
them before the post-processing phase can complete the work.

The previous scheme used to do minimal processing during expansion, leaving
the bulk of the work to the post-processing phase. Unfortunately this scheme
turned out not to be stable for Expression_With_Actions nodes under copying
by means of New_Copy_Tree or equivalent devices. The new scheme moves a bit
more processing to the expansion, namely the generation of the attachment to
the master node, whose result can then be naturally copied by New_Copy_Tree.

A side effect is to further simplify the implementation of Build_Finalizer
in Exp_Ch7, which has one fewer special case to deal with.

gcc/ada/

* einfo.ads (Finalization_Master_Node_Or_Object): Rename into...
(Finalization_Master_Node): ...this and adjust description.
* exp_ch4.adb (Process_Transient_In_Expression): Attach the object
to its master node here.
* exp_ch7.ads (Attach_Object_To_Master_Node): New declaration.
* exp_ch7.adb (Attach_Object_To_Master_Node): New procedure.
(Build_Finalizer.Process_Declarations): Examine the type of a
variable to spot master nodes.
(Build_Finalizer.Process_Object_Declaration): Look only at the
object and deal specifically with the case of a master node.
(Build_Finalizer.Build_BIP_Cleanup_Stmts): Move to child function
of Attach_Object_To_Master_Node.
(Build_Finalizer.Make_Address_For_Finalize): Move to...
(Insert_Actions_In_Scope_Around.Process_Transient_In_Scope): Attach
the object to its master node here.
(Make_Address_For_Finalize): ...here.
(Make_Master_Node_Declaration): Adjust to above renaming and set
Finalization_Master_Node only on the object.
(Make_Suppress_Object_Finalize_Call): Adjust to above renaming and
attach the object to its master node here.
* exp_util.adb (Requires_Cleanup_Actions): Examine the type of a
variable to spot master nodes.
* gen_il-fields.ads (Opt_Field_Enum): Adjust to above renaming.
* gen_il-gen-gen_entities.adb (Allocatable_Kind): Likewise.
* rtsfind.ads (RE_Id): Add RE_Chain_Node_To_Master.
(RE_Unit_Table): Add entry for  RE_Chain_Node_To_Master.
* libgnat/s-finpri.ads (Chain_Node_To_Master): New declaration.
* libgnat/s-finpri.adb (Chain_Node_To_Master): New procedure.
(Attach_Object_To_Master): Call it.
(Finalize_Master): Do not raise Program_Error on null addresses.
(Finalize_Object): Add assertion that the address is not null.

Diff:
---
 gcc/ada/einfo.ads   |   8 +-
 gcc/ada/exp_ch4.adb |   4 +
 gcc/ada/exp_ch7.adb | 804 
 gcc/ada/exp_ch7.ads |   7 +
 gcc/ada/exp_util.adb|   7 +-
 gcc/ada/gen_il-fields.ads   |   2 +-
 gcc/ada/gen_il-gen-gen_entities.adb |   2 +-
 gcc/ada/libgnat/s-finpri.adb|  32 +-
 gcc/ada/libgnat/s-finpri.ads|  12 +-
 gcc/ada/rtsfind.ads |   2 +
 10 files changed, 500 insertions(+), 380 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 24964004c05..6f563d5e62c 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -1305,15 +1305,13 @@ package Einfo is
 --   type. Empty for access-to-subprogram types. Empty for access types
 --   whose designated type does not need finalization actions.
 
---Finalization_Master_Node_Or_Object
+--Finalization_Master_Node
 --   Defined in variables and constants that require finalization actions.
 --   The field contains the entity of an object (called a Master_Node) that
 --   contains the address of the finalizable object, along with an access
 --   value denoting the finalizable object's finalization procedure. The
 --   Master_Node may be attached to a finalization list associated with
 --   either the global scope or some dynamic scope (block or subprogram).
---   Conversely, for a Master_Node 

[gcc r15-185] ada: Fix wrong Finalization_Size for No_Heap_Finalization objects

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:3862106d3506293ad5af2fc04d2d21ef3a5e0edf

commit r15-185-g3862106d3506293ad5af2fc04d2d21ef3a5e0edf
Author: Eric Botcazou 
Date:   Sat Dec 16 11:34:48 2023 +0100

ada: Fix wrong Finalization_Size for No_Heap_Finalization objects

When an access type is subject to the No_Heap_Finalization pragma, no header
is added in front of objects allocated through it, and the value returned by
Finalization_Size is defined to be the size of this header.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference) :
Return 0 if the prefix is a dereference of an access value subject
to the No_Heap_Finalization pragma.

Diff:
---
 gcc/ada/exp_attr.adb | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 614f1fbe14d..a8e06f0005e 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -3563,6 +3563,14 @@ package body Exp_Attr is
   --  Start of processing for Finalization_Size
 
   begin
+ --  If the prefix is the dereference of an access value subject to
+ --  pragma No_Heap_Finalization, then no header has been added.
+
+ if Nkind (Pref) = N_Explicit_Dereference
+   and then No_Heap_Finalization (Etype (Prefix (Pref)))
+ then
+Rewrite (N, Make_Integer_Literal (Loc, 0));
+
  --  An object of a class-wide type first requires a runtime check to
  --  determine whether it is actually controlled or not. Depending on
  --  the outcome of this check, the Finalization_Size of the object
@@ -3578,7 +3586,7 @@ package body Exp_Attr is
  --
  --  and the attribute reference is replaced with a reference to Size.
 
- if Is_Class_Wide_Type (Ptyp) then
+ elsif Is_Class_Wide_Type (Ptyp) then
 Size := Make_Temporary (Loc, 'S');
 
 Insert_Actions (N, New_List (


[gcc r15-184] ada: Fix spurious warning emission

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0b591735952e006c00be23e5b64631809bd93d10

commit r15-184-g0b591735952e006c00be23e5b64631809bd93d10
Author: Ronan Desplanques 
Date:   Tue Dec 19 17:13:20 2023 +0100

ada: Fix spurious warning emission

This patch fixes a bug where GNAT would emit incorrect warnings
about obsolescent syntax for array aggregates with generics and
particular arrangements of Ada version pragmas.

This patch also removes a syntactic field that was introduced to
support the emission of this warning, but is no longer required.

gcc/ada/

* exp_imgv.adb (Append_Table_To): Remove reference to removed
field.
* gen_il-fields.ads: Remove Is_Enum_Array_Aggregate field.
* gen_il-gen-gen_nodes.adb: Likewise.
* sem_aggr.adb: Tweak warning emission condition.
* sinfo.ads: Remove documentation for Is_Enum_Array_Aggregate.

Diff:
---
 gcc/ada/exp_imgv.adb |  3 +--
 gcc/ada/gen_il-fields.ads|  1 -
 gcc/ada/gen_il-gen-gen_nodes.adb |  1 -
 gcc/ada/sem_aggr.adb | 13 -
 gcc/ada/sinfo.ads|  5 -
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index ec0126a7da2..6dc59f2c6f3 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -159,8 +159,7 @@ package body Exp_Imgv is
Make_Component_Definition (Loc,
  Aliased_Present=> False,
  Subtype_Indication => New_Occurrence_Of (Ctyp, Loc))),
- Expression  => Make_Aggregate (Loc, Expressions => V,
-  Is_Enum_Array_Aggregate => True)));
+ Expression  => Make_Aggregate (Loc, Expressions => V)));
   end Append_Table_To;
 
--  Start of Build_Enumeration_Image_Tables
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index cdd9b9577e2..7cf6a38faa3 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -259,7 +259,6 @@ package Gen_IL.Fields is
   Is_Generic_Contract_Pragma,
   Is_Homogeneous_Aggregate,
   Is_Parenthesis_Aggregate,
-  Is_Enum_Array_Aggregate,
   Is_Ignored,
   Is_Ignored_Ghost_Pragma,
   Is_In_Discriminant_Check,
diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
index 72280025498..d7cc39bc048 100644
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -492,7 +492,6 @@ begin -- Gen_IL.Gen.Gen_Nodes
 Sy (Null_Record_Present, Flag),
 Sy (Is_Parenthesis_Aggregate, Flag),
 Sy (Is_Homogeneous_Aggregate, Flag),
-Sy (Is_Enum_Array_Aggregate, Flag),
 Sm (Aggregate_Bounds_Or_Ancestor_Type, Node_Id),
 Sm (Entity_Or_Associated_Node, Node_Id), -- just Associated_Node
 Sm (Compile_Time_Known_Aggregate, Flag),
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index e381af101c8..508c86bc5de 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -2099,14 +2099,25 @@ package body Sem_Aggr is
 
   --  Disable the warning for GNAT Mode to allow for easier transition.
 
+  --  We don't warn about obsolescent usage of parentheses in generic
+  --  instances for two reasons:
+  --
+  --  1. An equivalent warning has been emitted in the corresponding
+  -- definition.
+  --  2. In cases where a generic definition specifies a version older than
+  -- Ada 2022 through a pragma and rightfully uses parentheses for
+  -- an array aggregate, an incorrect warning would be raised in
+  -- instances of that generic that are in Ada 2022 or later if we
+  -- didn't filter out the instance case.
+
   if Ada_Version_Explicit >= Ada_2022
 and then Warn_On_Obsolescent_Feature
 and then not GNAT_Mode
 and then not Is_Homogeneous_Aggregate (N)
-and then not Is_Enum_Array_Aggregate (N)
 and then Is_Parenthesis_Aggregate (N)
 and then Nkind (Parent (N)) /= N_Qualified_Expression
 and then Comes_From_Source (N)
+and then not In_Instance
   then
  Error_Msg_N
("?j?array aggregate using () is an" &
diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
index 803f5dfc759..4e977152cd0 100644
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -1715,10 +1715,6 @@ package Sinfo is
--nodes which emulate the barrier function of a protected entry body.
--The flag is used when checking for incorrect use of Current_Task.
 
-   --  Is_Enum_Array_Aggregate
-   --A flag set on an aggregate created internally while building the
-   --images tables for enumerations.
-
--  Is_Expanded_Build_In_Place_Call
--This flag is set in an N_Function_Call node to indicate that the extra
--actuals to support a build-in-place style of call have been added to
@@ -4091,7 

[gcc r15-183] ada: Replace redundant conditions with assertions

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:e5a71415c32db32bf2c20a597f6191990ed1a0be

commit r15-183-ge5a71415c32db32bf2c20a597f6191990ed1a0be
Author: Piotr Trojanek 
Date:   Tue Dec 19 10:23:55 2023 +0100

ada: Replace redundant conditions with assertions

Fix warnings from the CodePeer. The code structure is essentially:

  if A and B then ...
  elsif not A and not B then ...
  elsif A then ...
  elsif B then ...  --  this condition is redundant
  end if;

and it causes CodePeer to say "exception is raised in a conditional
branch", which most likely means that the condition is redundant.

gcc/ada/

* make.adb (Scan_Make_Arg): Remove redundant condition.
* switch-b.adb (Scan_Debug_Switches): Likewise.
* switch-c.adb (Scan_Front_End_Switches): Likewise.

Diff:
---
 gcc/ada/make.adb | 2 +-
 gcc/ada/switch-b.adb | 2 +-
 gcc/ada/switch-c.adb | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/make.adb b/gcc/ada/make.adb
index 01d3ccab8af..24b2d099bfe 100644
--- a/gcc/ada/make.adb
+++ b/gcc/ada/make.adb
@@ -4508,7 +4508,7 @@ package body Make is
  Make_Failed
("RTS path not valid: missing adainclude directory");
 
-  elsif Lib_Path_Name = null then
+  else pragma Assert (Lib_Path_Name = null);
  Make_Failed
("RTS path not valid: missing adalib directory");
   end if;
diff --git a/gcc/ada/switch-b.adb b/gcc/ada/switch-b.adb
index 2c4fc0c6039..8d8dc58937c 100644
--- a/gcc/ada/switch-b.adb
+++ b/gcc/ada/switch-b.adb
@@ -703,7 +703,7 @@ package body Switch.B is
  elsif Src_Path_Name = null then
 Osint.Fail
   ("RTS path not valid: missing adainclude directory");
- elsif Lib_Path_Name = null then
+ else pragma Assert (Lib_Path_Name = null);
 Osint.Fail
   ("RTS path not valid: missing adalib directory");
  end if;
diff --git a/gcc/ada/switch-c.adb b/gcc/ada/switch-c.adb
index 7668fce885a..43b69f1dde1 100644
--- a/gcc/ada/switch-c.adb
+++ b/gcc/ada/switch-c.adb
@@ -274,7 +274,7 @@ package body Switch.C is
  Osint.Fail ("RTS path not valid: missing "
  & "adainclude directory");
 
-  elsif RTS_Lib_Path_Name = null then
+  else pragma Assert (RTS_Lib_Path_Name = null);
  Osint.Fail ("RTS path not valid: missing "
  & "adalib directory");
   end if;


[gcc r15-182] ada: Fix detection of (Un)Hide_Info pragma in GNATprove mode

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:bd2462a8473b7ee7cabd4040553ae13606273723

commit r15-182-gbd2462a8473b7ee7cabd4040553ae13606273723
Author: Yannick Moy 
Date:   Tue Dec 19 10:52:38 2023 +0100

ada: Fix detection of (Un)Hide_Info pragma in GNATprove mode

Spec or body may not be in a list for subunit.

gcc/ada/

* inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Add guard.

Diff:
---
 gcc/ada/inline.adb | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index 98bed860760..b7a6cc90cd2 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -1819,6 +1819,7 @@ package body Inline is
 
   begin
  if Present (Spec_Id)
+   and then Is_List_Member (Unit_Declaration_Node (Spec_Id))
and then Has_Hide_Unhide_Pragma
  (Next (Unit_Declaration_Node (Spec_Id)))
  then
@@ -1829,7 +1830,9 @@ package body Inline is
Subp_Body : constant N_Subprogram_Body_Id :=
  Unit_Declaration_Node (Body_Id);
 begin
-   return Has_Hide_Unhide_Pragma (Next (Subp_Body))
+   return
+ (Is_List_Member (Subp_Body)
+   and then Has_Hide_Unhide_Pragma (Next (Subp_Body)))
  or else
Has_Hide_Unhide_Pragma (First (Declarations (Subp_Body)));
 end;


[gcc r15-179] ada: Fix memory leak in 'Image

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4629cd34506416d05cd9ab56879f69b44fe65d2b

commit r15-179-g4629cd34506416d05cd9ab56879f69b44fe65d2b
Author: Bob Duff 
Date:   Fri Dec 15 16:59:43 2023 -0500

ada: Fix memory leak in 'Image

Fix memory leak in 'Image by managing the secondary stack
in scopes that call the new Ada 2020 'Image, which calls 'Put_Image
and then Get, which returns on the secondary stack.

gcc/ada/

* exp_put_image.adb (Build_Image_Call): Call Set_Uses_Sec_Stack on
the current scope. We don't do this at all call sites, because
there are three; better to do it here.

Diff:
---
 gcc/ada/exp_put_image.adb | 8 
 1 file changed, 8 insertions(+)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index c298163f36f..182497fb6e8 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -1290,6 +1290,14 @@ package body Exp_Put_Image is
  Actions := New_List (Sink_Decl, Put_Im, Result_Decl);
   end if;
 
+  --  To avoid leaks, we need to manage the secondary stack, because Get is
+  --  returning a String allocated thereon. It might be cleaner to let the
+  --  normal mechanisms for functions returning on the secondary stack call
+  --  Set_Uses_Sec_Stack, but this expansion of 'Image is happening too
+  --  late for that.
+
+  Set_Uses_Sec_Stack (Current_Scope);
+
   return Make_Expression_With_Actions (Loc,
 Actions=> Actions,
 Expression => New_Occurrence_Of (Result_Entity, Loc));


[gcc r15-181] ada: Fix missing associated node for packed array itypes

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9bc49f5ac1e1140f00f488f5d05294541079fb1b

commit r15-181-g9bc49f5ac1e1140f00f488f5d05294541079fb1b
Author: Piotr Trojanek 
Date:   Mon Dec 18 14:31:52 2023 +0100

ada: Fix missing associated node for packed array itypes

After decoration, itypes should have its associated node set.

gcc/ada/

* exp_pakd.adb (Create_Packed_Array_Impl_Type): Set associated
node for the packed array itype.
* exp_util.adb (Possible_Side_Effect_In_SPARK): Remove
workaround for a missing associated node.

Diff:
---
 gcc/ada/exp_pakd.adb |  4 
 gcc/ada/exp_util.adb | 15 ++-
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
index 628a3e38a78..3f26c3527fa 100644
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -541,8 +541,12 @@ package body Exp_Pakd is
 
  if Is_Itype (Typ) then
 Set_Parent (Decl, Associated_Node_For_Itype (Typ));
+Set_Associated_Node_For_Itype
+  (PAT, Associated_Node_For_Itype (Typ));
  else
 Set_Parent (Decl, Declaration_Node (Typ));
+Set_Associated_Node_For_Itype
+  (PAT, Declaration_Node (Typ));
  end if;
 
  if Scope (Typ) /= Current_Scope then
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 25190a65ebf..e7573277b61 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -11917,7 +11917,7 @@ package body Exp_Util is
 
 --  When this routine is called while the itype
 --  is being created, the entity might not yet be
---  decorated with the associated node, but should
+--  decorated with the associated node, but will
 --  have the related expression.
 
 if Present (Associated_Node_For_Itype (Subt)) then
@@ -11925,21 +11925,10 @@ package body Exp_Util is
  Possible_Side_Effect_In_SPARK
(Associated_Node_For_Itype (Subt));
 
-elsif Present (Related_Expression (Subt)) then
+else
return
  Possible_Side_Effect_In_SPARK
(Related_Expression (Subt));
-
---  When the itype doesn't have any indication of its
---  origin (which currently only happens for packed
---  array types created by freezing that shouldn't
---  be picked by GNATprove anyway), then we can
---  conservatively assume that the expression can
---  be kept as it appears in the source code.
-
-else
-   pragma Assert (Is_Packed_Array_Impl_Type (Subt));
-   return False;
 end if;
  else
 return True;


[gcc r15-180] ada: Don't propagate convention to internal subprograms

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:dd548dc587d16ac9d272899739d384e67789e862

commit r15-180-gdd548dc587d16ac9d272899739d384e67789e862
Author: Richard Kenner 
Date:   Sun Dec 17 07:47:44 2023 -0500

ada: Don't propagate convention to internal subprograms

AI95-117 requires that all new primitives of a tagged type must
inherit the convention of the full view of the type. However, we need
not do this for primitives that are internally-generated, such as for
finalization. There are issues with GNAT LLVM when primitives have
convention C since the UC from that subprogram type to the type used
in the dispatch table will generate a warning. We're not doing
anything here about the case where the convention C is explicit or
there are user-specified primitives on a type with convention C, but
let's not make the problem worse by putting convention C on internal
subprograms.

gcc/ada/

* freeze.adb (Freeze_Entity): When changing the convention of
primitive to match that of the type, only do this for user-specified
primitives.

Diff:
---
 gcc/ada/freeze.adb | 28 +---
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index d032b75f1f2..4cb5979b016 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -7327,17 +7327,21 @@ package body Freeze is
 
  if Is_Composite_Type (E) then
 
---  AI95-117 requires that all new primitives of a tagged type must
---  inherit the convention of the full view of the type. Inherited
---  and overriding operations are defined to inherit the convention
---  of their parent or overridden subprogram (also specified in
---  AI-117), which will have occurred earlier (in Derive_Subprogram
---  and New_Overloaded_Entity). Here we set the convention of
+--  AI95-117 requires that all new primitives of a tagged type
+--  must inherit the convention of the full view of the
+--  type. Inherited and overriding operations are defined to
+--  inherit the convention of their parent or overridden
+--  subprogram (also specified in AI-117), which will have
+--  occurred earlier (in Derive_Subprogram and
+--  New_Overloaded_Entity). Here we set the convention of
 --  primitives that are still convention Ada, which will ensure
---  that any new primitives inherit the type's convention. Class-
---  wide types can have a foreign convention inherited from their
---  specific type, but are excluded from this since they don't have
---  any associated primitives.
+--  that any new primitives inherit the type's convention. We
+--  don't do this for primitives that are internal to avoid
+--  potential problems in the case of nested subprograms and
+--  convention C. In addition, class-wide types can have a
+--  foreign convention inherited from their specific type, but
+--  are excluded from this since they don't have any associated
+--  primitives.
 
 if Is_Tagged_Type (E)
   and then not Is_Class_Wide_Type (E)
@@ -7350,7 +7354,9 @@ package body Freeze is
begin
   Prim := First_Elmt (Prim_List);
   while Present (Prim) loop
- if Convention (Node (Prim)) = Convention_Ada then
+ if Convention (Node (Prim)) = Convention_Ada
+   and then Comes_From_Source (Node (Prim))
+ then
 Set_Convention (Node (Prim), Convention (E));
  end if;


[gcc r15-177] ada: Fix non-idiomatic construct

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4002a72aff546e20b6efc75147bebdf893891ea6

commit r15-177-g4002a72aff546e20b6efc75147bebdf893891ea6
Author: Eric Botcazou 
Date:   Fri Dec 15 19:07:44 2023 +0100

ada: Fix non-idiomatic construct

gcc/ada/

* exp_ch3.adb (Expand_Freeze_Class_Wide_Type): Use No instead of
not Present.

Diff:
---
 gcc/ada/exp_ch3.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 7a137dda3f7..09551b22154 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -5021,7 +5021,7 @@ package body Exp_Ch3 is
   --  Create the body of TSS primitive Finalize_Address. This automatically
   --  sets the TSS entry for the class-wide type.
 
-  if not Present (Finalize_Address (Typ)) then
+  if No (Finalize_Address (Typ)) then
  Make_Finalize_Address_Body (Typ);
   end if;
end Expand_Freeze_Class_Wide_Type;


[gcc r15-176] ada: Adjust source location for degenerate scope master

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:6cc4ac7d151e432b75da58d44d2ffb53192e04b5

commit r15-176-g6cc4ac7d151e432b75da58d44d2ffb53192e04b5
Author: Eric Botcazou 
Date:   Fri Dec 15 13:08:38 2023 +0100

ada: Adjust source location for degenerate scope master

When the finalization scope master degenerates into a simple master node,
the latter must inherit the source location that the former would have had.

gcc/ada/

* exp_ch7.adb (Build_Finalizer.Process_Object_Declaration): Adjust
the Sloc of the master node declaration in the degenerate case.

Diff:
---
 gcc/ada/exp_ch7.adb | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 75c9e223956..4382de9b6b2 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -2875,6 +2875,7 @@ package body Exp_Ch7 is
  Master_Node_Decl   : Node_Id;
  Master_Node_Id : Entity_Id;
  Master_Node_Ins: Node_Id;
+ Master_Node_Loc: Source_Ptr;
  Obj_Ref: Node_Id;
 
   --  Start of processing for Process_Object_Declaration
@@ -2936,11 +2937,20 @@ package body Exp_Ch7 is
 end if;
 
  else
+--  For one object, use the Sloc the scope master would have had
+
+if Counter_Val = 1 then
+   Master_Node_Loc := Sloc (N);
+else
+   Master_Node_Loc := Loc;
+end if;
+
 Master_Node_Id :=
-  Make_Defining_Identifier (Loc,
+  Make_Defining_Identifier (Master_Node_Loc,
 Chars => New_External_Name (Chars (Obj_Id), Suffix => "MN"));
 Master_Node_Decl :=
-  Make_Master_Node_Declaration (Loc, Master_Node_Id, Obj_Id);
+  Make_Master_Node_Declaration (Master_Node_Loc,
+Master_Node_Id, Obj_Id);
 
 Push_Scope (Scope (Obj_Id));
 if Counter_Val = 1 then


[gcc r15-175] ada: Prevent inlining in GNATprove for memory leaks

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:cdf15b4b661c5fa1a210642e0b2a508969faf197

commit r15-175-gcdf15b4b661c5fa1a210642e0b2a508969faf197
Author: Yannick Moy 
Date:   Wed Dec 13 17:40:03 2023 +0100

ada: Prevent inlining in GNATprove for memory leaks

In some cases, inlining a call in GNATprove could lead to
missing a memory leak. Recognize such cases and do not inline
such calls.

gcc/ada/

* inline.adb (Call_Can_Be_Inlined_In_GNATprove_Mode):
Add case to prevent inlining of call.
* inline.ads: Likewise.
* sem_res.adb (Resolve_Call): Update comment and message.

Diff:
---
 gcc/ada/inline.adb  | 58 +
 gcc/ada/inline.ads  |  5 +++--
 gcc/ada/sem_res.adb |  5 +++--
 3 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index 2ec92ca9dff..98bed860760 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -1460,10 +1460,47 @@ package body Inline is
 (N: Node_Id;
  Subp : Entity_Id) return Boolean
is
+  function Has_Dereference (N : Node_Id) return Boolean;
+  --  Return whether N contains an explicit dereference
+
+  -
+  -- Has_Dereference --
+  -
+
+  function Has_Dereference (N : Node_Id) return Boolean is
+
+ function Process (N : Node_Id) return Traverse_Result;
+ --  Process one node in search for dereference
+
+ -
+ -- Process --
+ -
+
+ function Process (N : Node_Id) return Traverse_Result is
+ begin
+if Nkind (N) = N_Explicit_Dereference then
+   return Abandon;
+else
+   return OK;
+end if;
+ end Process;
+
+ function Traverse is new Traverse_Func (Process);
+ --  Traverse tree to look for dereference
+
+  begin
+ return Traverse (N) = Abandon;
+  end Has_Dereference;
+
+  --  Local variables
+
   F : Entity_Id;
   A : Node_Id;
 
begin
+  --  Check if inlining may lead to missing a check on type conversion of
+  --  input parameters otherwise.
+
   F := First_Formal (Subp);
   A := First_Actual (N);
   while Present (F) loop
@@ -1480,6 +1517,27 @@ package body Inline is
  Next_Actual (A);
   end loop;
 
+  --  Check if inlining may lead to introducing temporaries of access type,
+  --  which can lead to missing checks for memory leaks. This can only
+  --  come from an (IN-)OUT parameter transformed into a renaming by SPARK
+  --  expansion, whose side-effects are removed, and a dereference in the
+  --  corresponding actual. If the formal itself is of a deep type (it has
+  --  access subcomponents), the subprogram already cannot be inlined in
+  --  GNATprove mode.
+
+  F := First_Formal (Subp);
+  A := First_Actual (N);
+  while Present (F) loop
+ if Ekind (F) /= E_In_Parameter
+   and then Has_Dereference (A)
+ then
+return False;
+ end if;
+
+ Next_Formal (F);
+ Next_Actual (A);
+  end loop;
+
   return True;
end Call_Can_Be_Inlined_In_GNATprove_Mode;
 
diff --git a/gcc/ada/inline.ads b/gcc/ada/inline.ads
index 3df0a01b65d..bc90c0ce6d8 100644
--- a/gcc/ada/inline.ads
+++ b/gcc/ada/inline.ads
@@ -146,8 +146,9 @@ package Inline is
 (N: Node_Id;
  Subp : Entity_Id) return Boolean;
--  Returns False if the call in node N to subprogram Subp cannot be inlined
-   --  in GNATprove mode, because it may lead to missing a check on type
-   --  conversion of input parameters otherwise. Returns True otherwise.
+   --  in GNATprove mode, because it may otherwise lead to missing a check
+   --  on type conversion of input parameters, or a missing memory leak on
+   --  an output parameter. Returns True otherwise.
 
function Can_Be_Inlined_In_GNATprove_Mode
  (Spec_Id : Entity_Id;
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 075c0d85ccd..67062c6b32b 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -7329,11 +7329,12 @@ package body Sem_Res is
 ("cannot inline & (in while loop condition)?", N, Nam_UA);
 
--  Do not inline calls which would possibly lead to missing a
-   --  type conversion check on an input parameter.
+   --  type conversion check on an input parameter or a memory leak
+   --  on an output parameter.
 
elsif not Call_Can_Be_Inlined_In_GNATprove_Mode (N, Nam) then
   Cannot_Inline
-("cannot inline & (possible check on input parameters)?",
+("cannot inline & (possible check on parameters)?",
  N, Nam_UA);
 
--  Otherwise, inline the call, issuing an info message when


[gcc r15-173] ada: Do not inline in GNATprove the subprograms with (Un)Hide_Info

2024-05-06 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:53c32e9d7f01ee350803c9371b8630bf3e4844b7

commit r15-173-g53c32e9d7f01ee350803c9371b8630bf3e4844b7
Author: Yannick Moy 
Date:   Wed Dec 13 15:38:59 2023 +0100

ada: Do not inline in GNATprove the subprograms with (Un)Hide_Info

The annotations Hide_Info and Unhide_Info in GNATprove are meant to
give special visibility in the corresponding scope to the precise definition
of some entities. Hence, such scopes should not be inlined in GNATprove.

gcc/ada/

* inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Adapt checking.

Diff:
---
 gcc/ada/inline.adb | 89 --
 1 file changed, 86 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index f23100dbb13..2ec92ca9dff 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -1503,6 +1503,12 @@ package body Inline is
   --  an unconstrained record type with per-object constraints on component
   --  types.
 
+  function Has_Hide_Unhide_Annotation
+(Spec_Id, Body_Id : Entity_Id)
+ return Boolean;
+  --  Returns whether the subprogram has an annotation Hide_Info or
+  --  Unhide_Info on its spec or body.
+
   function Has_Skip_Proof_Annotation (Id : Entity_Id) return Boolean;
   --  Returns True if subprogram Id has an annotation Skip_Proof or
   --  Skip_Flow_And_Proof.
@@ -1705,6 +1711,76 @@ package body Inline is
  return False;
   end Has_Formal_With_Discriminant_Dependent_Fields;
 
+  
+  -- Has_Hide_Unhide_Annotation --
+  
+
+  function Has_Hide_Unhide_Annotation
+(Spec_Id, Body_Id : Entity_Id)
+ return Boolean
+  is
+ function Has_Hide_Unhide_Pragma (Prag : Node_Id) return Boolean;
+ --  Return whether a pragma Hide/Unhide is present in the list of
+ --  pragmas starting with Prag.
+
+ 
+ -- Has_Hide_Unhide_Pragma --
+ 
+
+ function Has_Hide_Unhide_Pragma (Prag : Node_Id) return Boolean is
+Decl : Node_Id := Prag;
+ begin
+while Present (Decl)
+  and then Nkind (Decl) = N_Pragma
+loop
+   if Get_Pragma_Id (Decl) = Pragma_Annotate
+ and then List_Length (Pragma_Argument_Associations (Decl)) = 4
+   then
+  declare
+ Arg1  : constant Node_Id :=
+   First (Pragma_Argument_Associations (Decl));
+ Arg2  : constant Node_Id := Next (Arg1);
+ Arg1_Name : constant Name_Id :=
+   Chars (Get_Pragma_Arg (Arg1));
+ Arg2_Name : constant String :=
+   Get_Name_String (Chars (Get_Pragma_Arg (Arg2)));
+  begin
+ if Arg1_Name = Name_Gnatprove
+   and then Arg2_Name in "hide_info" | "unhide_info"
+ then
+return True;
+ end if;
+  end;
+   end if;
+
+   Next (Decl);
+end loop;
+
+return False;
+ end Has_Hide_Unhide_Pragma;
+
+  begin
+ if Present (Spec_Id)
+   and then Has_Hide_Unhide_Pragma
+ (Next (Unit_Declaration_Node (Spec_Id)))
+ then
+return True;
+
+ elsif Present (Body_Id) then
+declare
+   Subp_Body : constant N_Subprogram_Body_Id :=
+ Unit_Declaration_Node (Body_Id);
+begin
+   return Has_Hide_Unhide_Pragma (Next (Subp_Body))
+ or else
+   Has_Hide_Unhide_Pragma (First (Declarations (Subp_Body)));
+end;
+
+ else
+return False;
+ end if;
+  end Has_Hide_Unhide_Annotation;
+
   ---
   -- Has_Skip_Proof_Annotation --
   ---
@@ -1725,12 +1801,12 @@ package body Inline is
   Arg1  : constant Node_Id :=
 First (Pragma_Argument_Associations (Decl));
   Arg2  : constant Node_Id := Next (Arg1);
-  Arg1_Name : constant String :=
-Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
+  Arg1_Name : constant Name_Id :=
+Chars (Get_Pragma_Arg (Arg1));
   Arg2_Name : constant String :=
 Get_Name_String (Chars (Get_Pragma_Arg (Arg2)));
begin
-  if Arg1_Name = "gnatprove"
+  if Arg1_Name = Name_Gnatprove
 and then Arg2_Name in "skip_proof" | "skip_flow_and_proof"
   then
  return True;
@@ -1952,6 

[gcc r14-10170] testsuite: c++: Skip g++.dg/analyzer on Solaris [PR111475]

2024-05-06 Thread Rainer Orth via Gcc-cvs
https://gcc.gnu.org/g:c7b4305f9c0d23a9dfb2cf0855d345ff67e48732

commit r14-10170-gc7b4305f9c0d23a9dfb2cf0855d345ff67e48732
Author: Rainer Orth 
Date:   Mon May 6 10:54:27 2024 +0200

testsuite: c++: Skip g++.dg/analyzer on Solaris [PR111475]

Almost 1400 C++ analyzer tests FAIL on Solaris.  The patch is too risky
to apply so close to the GCC 14.1.0 release, so disable the tests on
Solaris instead to reduce the noise.

Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11, and
x86_64-pc-linux-gnu.

2024-05-05  Rainer Orth  

gcc/testsuite:
PR analyzer/111475
* g++.dg/analyzer/analyzer.exp: Disable on *-*-solaris2.*.

Diff:
---
 gcc/testsuite/g++.dg/analyzer/analyzer.exp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/testsuite/g++.dg/analyzer/analyzer.exp 
b/gcc/testsuite/g++.dg/analyzer/analyzer.exp
index 863c14de057..7bbafc5bdb4 100644
--- a/gcc/testsuite/g++.dg/analyzer/analyzer.exp
+++ b/gcc/testsuite/g++.dg/analyzer/analyzer.exp
@@ -24,6 +24,11 @@ if { ![check_effective_target_analyzer] } {
 return
 }
 
+# Disable on Solaris until PR analyzer/111475 is fixed.
+if { [istarget *-*-solaris2.*] } {
+return
+}
+
 if [info exists DEFAULT_CXXFLAGS] then {
   set save_default_cxxflags $DEFAULT_CXXFLAGS
 }


[gcc r12-10415] Fortran: Fix ICE and clear incorrect error messages [PR114739]

2024-05-06 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:3a5acd2583056e8cd0e5fda83e7c34be65415c62

commit r12-10415-g3a5acd2583056e8cd0e5fda83e7c34be65415c62
Author: Paul Thomas 
Date:   Mon May 6 08:21:14 2024 +0100

Fortran: Fix ICE and clear incorrect error messages [PR114739]

2024-05-06  Paul Thomas  

gcc/fortran
PR fortran/114739
* primary.cc (gfc_match_varspec): Check for default type before
checking for derived types with the right component name.

gcc/testsuite/
PR fortran/114739
* gfortran.dg/pr114739.f90: New test.
* gfortran.dg/derived_comp_array_ref_8.f90: Add 'implicit none'
for consistency with expected error message.
* gfortran.dg/nullify_4.f90: ditto
* gfortran.dg/pointer_init_6.f90: ditto
* gfortran.dg/pr107397.f90: ditto
* gfortran.dg/pr88138.f90: ditto

(cherry picked from commit 094f8a36dffea52fe6a64596203b82648a3f6121)

Diff:
---
 gcc/fortran/primary.cc |  9 +
 gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 |  1 +
 gcc/testsuite/gfortran.dg/nullify_4.f90|  1 +
 gcc/testsuite/gfortran.dg/pointer_init_6.f90   |  2 +-
 gcc/testsuite/gfortran.dg/pr107397.f90 |  1 +
 gcc/testsuite/gfortran.dg/pr114739.f90 | 11 +++
 gcc/testsuite/gfortran.dg/pr88138.f90  |  1 +
 7 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 78295c54b6c..4f8bd129ee9 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2207,6 +2207,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
   match mm;
   old_loc = gfc_current_locus;
   mm = gfc_match_name (name);
+
+  /* Check to see if this has a default type.  */
+  if (sym->ts.type == BT_UNKNOWN && tgt_expr == NULL
+ && gfc_get_default_type (sym->name, sym->ns)->type != BT_UNKNOWN)
+   {
+ gfc_set_default_type (sym, 0, sym->ns);
+ primary->ts = sym->ts;
+   }
+
   if (mm == MATCH_YES && is_inquiry_ref (name, ))
inquiry = true;
   gfc_current_locus = old_loc;
diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 
b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
index 739f4adfb78..22dfdc668a6 100644
--- a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
+++ b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
@@ -2,6 +2,7 @@
 !
 ! PR fortran/52325
 !
+implicit none
 real :: f
 cc%a = 5 ! { dg-error "Symbol 'cc' at .1. has no IMPLICIT type" }
 f%a = 5  ! { dg-error "Unexpected '%' for nonderived-type variable 'f' at" }
diff --git a/gcc/testsuite/gfortran.dg/nullify_4.f90 
b/gcc/testsuite/gfortran.dg/nullify_4.f90
index 0fd5056ee07..240110fabf8 100644
--- a/gcc/testsuite/gfortran.dg/nullify_4.f90
+++ b/gcc/testsuite/gfortran.dg/nullify_4.f90
@@ -3,6 +3,7 @@
 !
 ! Check error recovery; was crashing before.
 !
+implicit none
 real, pointer :: ptr
 nullify(ptr, mesh%coarser) ! { dg-error "Symbol 'mesh' at .1. has no IMPLICIT 
type" }
 end
diff --git a/gcc/testsuite/gfortran.dg/pointer_init_6.f90 
b/gcc/testsuite/gfortran.dg/pointer_init_6.f90
index 3abad4ae179..477626e66bb 100644
--- a/gcc/testsuite/gfortran.dg/pointer_init_6.f90
+++ b/gcc/testsuite/gfortran.dg/pointer_init_6.f90
@@ -21,7 +21,7 @@ end module m1
 
 
 module m2
-
+ implicit none
  type :: t
procedure(s), pointer, nopass :: ppc
  end type
diff --git a/gcc/testsuite/gfortran.dg/pr107397.f90 
b/gcc/testsuite/gfortran.dg/pr107397.f90
index fd59bf16007..f77b4b00d00 100644
--- a/gcc/testsuite/gfortran.dg/pr107397.f90
+++ b/gcc/testsuite/gfortran.dg/pr107397.f90
@@ -1,6 +1,7 @@
 !{ dg-do compile }
 !
 program p
+  implicit none
   type t
 real :: a = 1.0
   end type
diff --git a/gcc/testsuite/gfortran.dg/pr114739.f90 
b/gcc/testsuite/gfortran.dg/pr114739.f90
new file mode 100644
index 000..eb82cb3f65b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr114739.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! The fix here was triggered by an ICE prior to r14-9489-g3fd46d859cda10
+! Before that gfortran gave an incorrect "no implicit type" error for all
+! three statements.
+program main
+  implicit complex(z)
+  implicit character(c)
+  z2%re = 1.
+  z2%im = 2.
+  print *, z2, c%kind
+end
diff --git a/gcc/testsuite/gfortran.dg/pr88138.f90 
b/gcc/testsuite/gfortran.dg/pr88138.f90
index c4019a6ca2e..f1130cf2bab 100644
--- a/gcc/testsuite/gfortran.dg/pr88138.f90
+++ b/gcc/testsuite/gfortran.dg/pr88138.f90
@@ -1,5 +1,6 @@
 ! { dg-do compile }
 program p
+   implicit none
type t
   character :: c = 'c'
end type


[gcc r15-172] libgfortran: Fix libgfortran.so versioning on Solaris with subdirs

2024-05-06 Thread Rainer Orth via Gcc-cvs
https://gcc.gnu.org/g:8daf4eb02a2e739d5c62b94528adfddaed506a0a

commit r15-172-g8daf4eb02a2e739d5c62b94528adfddaed506a0a
Author: Rainer Orth 
Date:   Mon May 6 09:31:11 2024 +0200

libgfortran: Fix libgfortran.so versioning on Solaris with subdirs

The move of libgfortran objects to subdirectories completely broke the
creation of libgfortran.so on Solaris.  Since the gfortran.ver-sun rule
doesn't support that structure, no libtool objects are found, thus no
symbols exported from libgfortran.so, causing every link to fail.

This patch fixes this by allowing for the new structure.

Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11.

2024-05-05  Rainer Orth  

libgfortran:
* Makefile.am [LIBGFOR_USE_SYMVER_SUN] (gfortran.ver-sun): Handle
objects in subdirs.
* Makefile.in: Regenerate.

Diff:
---
 libgfortran/Makefile.am | 2 +-
 libgfortran/Makefile.in | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 8bef1729219..9e1d12f7546 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -29,7 +29,7 @@ gfortran.ver-sun : gfortran.ver \
$(libgfortran_la_OBJECTS) $(libgfortran_la_LIBADD)
perl $(top_srcdir)/../contrib/make_sunver.pl \
  gfortran.ver \
- $(libgfortran_la_OBJECTS:%.lo=.libs/%.o) \
+ $(subst /,/.libs/,$(libgfortran_la_OBJECTS:.lo=.o)) \
 `echo $(libgfortran_la_LIBADD) | \
sed 's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
 > $@ || (rm -f $@ ; exit 1)
diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in
index f4fe0ebc43e..ab10a476eae 100644
--- a/libgfortran/Makefile.in
+++ b/libgfortran/Makefile.in
@@ -4576,7 +4576,7 @@ uninstall-am: uninstall-cafexeclibLTLIBRARIES 
uninstall-gfor_cHEADERS \
 @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@ 
$(libgfortran_la_OBJECTS) $(libgfortran_la_LIBADD)
 @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@ perl 
$(top_srcdir)/../contrib/make_sunver.pl \
 @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@   gfortran.ver \
-@LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@   
$(libgfortran_la_OBJECTS:%.lo=.libs/%.o) \
+@LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@   $(subst 
/,/.libs/,$(libgfortran_la_OBJECTS:.lo=.o)) \
 @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@  `echo 
$(libgfortran_la_LIBADD) | \
 @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@ sed 
's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
 @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@  > $@ || (rm -f $@ ; 
exit 1)


[gcc r13-8689] Fortran: Fix ICE and clear incorrect error messages [PR114739]

2024-05-06 Thread Paul Thomas via Gcc-cvs
https://gcc.gnu.org/g:094f8a36dffea52fe6a64596203b82648a3f6121

commit r13-8689-g094f8a36dffea52fe6a64596203b82648a3f6121
Author: Paul Thomas 
Date:   Mon May 6 08:21:14 2024 +0100

Fortran: Fix ICE and clear incorrect error messages [PR114739]

2024-05-06  Paul Thomas  

gcc/fortran
PR fortran/114739
* primary.cc (gfc_match_varspec): Check for default type before
checking for derived types with the right component name.

gcc/testsuite/
PR fortran/114739
* gfortran.dg/pr114739.f90: New test.
* gfortran.dg/derived_comp_array_ref_8.f90: Add 'implicit none'
for consistency with expected error message.
* gfortran.dg/nullify_4.f90: ditto
* gfortran.dg/pointer_init_6.f90: ditto
* gfortran.dg/pr107397.f90: ditto
* gfortran.dg/pr88138.f90: ditto

Diff:
---
 gcc/fortran/primary.cc |  9 +
 gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 |  1 +
 gcc/testsuite/gfortran.dg/nullify_4.f90|  1 +
 gcc/testsuite/gfortran.dg/pointer_init_6.f90   |  2 +-
 gcc/testsuite/gfortran.dg/pr107397.f90 |  1 +
 gcc/testsuite/gfortran.dg/pr114739.f90 | 11 +++
 gcc/testsuite/gfortran.dg/pr88138.f90  |  1 +
 7 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index edbd162ed13..a1b6b74765a 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -2199,6 +2199,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, 
bool sub_flag,
   match mm;
   old_loc = gfc_current_locus;
   mm = gfc_match_name (name);
+
+  /* Check to see if this has a default type.  */
+  if (sym->ts.type == BT_UNKNOWN && tgt_expr == NULL
+ && gfc_get_default_type (sym->name, sym->ns)->type != BT_UNKNOWN)
+   {
+ gfc_set_default_type (sym, 0, sym->ns);
+ primary->ts = sym->ts;
+   }
+
   if (mm == MATCH_YES && is_inquiry_ref (name, ))
inquiry = true;
   gfc_current_locus = old_loc;
diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90 
b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
index 739f4adfb78..22dfdc668a6 100644
--- a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
+++ b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_8.f90
@@ -2,6 +2,7 @@
 !
 ! PR fortran/52325
 !
+implicit none
 real :: f
 cc%a = 5 ! { dg-error "Symbol 'cc' at .1. has no IMPLICIT type" }
 f%a = 5  ! { dg-error "Unexpected '%' for nonderived-type variable 'f' at" }
diff --git a/gcc/testsuite/gfortran.dg/nullify_4.f90 
b/gcc/testsuite/gfortran.dg/nullify_4.f90
index 0fd5056ee07..240110fabf8 100644
--- a/gcc/testsuite/gfortran.dg/nullify_4.f90
+++ b/gcc/testsuite/gfortran.dg/nullify_4.f90
@@ -3,6 +3,7 @@
 !
 ! Check error recovery; was crashing before.
 !
+implicit none
 real, pointer :: ptr
 nullify(ptr, mesh%coarser) ! { dg-error "Symbol 'mesh' at .1. has no IMPLICIT 
type" }
 end
diff --git a/gcc/testsuite/gfortran.dg/pointer_init_6.f90 
b/gcc/testsuite/gfortran.dg/pointer_init_6.f90
index 3abad4ae179..477626e66bb 100644
--- a/gcc/testsuite/gfortran.dg/pointer_init_6.f90
+++ b/gcc/testsuite/gfortran.dg/pointer_init_6.f90
@@ -21,7 +21,7 @@ end module m1
 
 
 module m2
-
+ implicit none
  type :: t
procedure(s), pointer, nopass :: ppc
  end type
diff --git a/gcc/testsuite/gfortran.dg/pr107397.f90 
b/gcc/testsuite/gfortran.dg/pr107397.f90
index fd59bf16007..f77b4b00d00 100644
--- a/gcc/testsuite/gfortran.dg/pr107397.f90
+++ b/gcc/testsuite/gfortran.dg/pr107397.f90
@@ -1,6 +1,7 @@
 !{ dg-do compile }
 !
 program p
+  implicit none
   type t
 real :: a = 1.0
   end type
diff --git a/gcc/testsuite/gfortran.dg/pr114739.f90 
b/gcc/testsuite/gfortran.dg/pr114739.f90
new file mode 100644
index 000..eb82cb3f65b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr114739.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! The fix here was triggered by an ICE prior to r14-9489-g3fd46d859cda10
+! Before that gfortran gave an incorrect "no implicit type" error for all
+! three statements.
+program main
+  implicit complex(z)
+  implicit character(c)
+  z2%re = 1.
+  z2%im = 2.
+  print *, z2, c%kind
+end
diff --git a/gcc/testsuite/gfortran.dg/pr88138.f90 
b/gcc/testsuite/gfortran.dg/pr88138.f90
index c4019a6ca2e..f1130cf2bab 100644
--- a/gcc/testsuite/gfortran.dg/pr88138.f90
+++ b/gcc/testsuite/gfortran.dg/pr88138.f90
@@ -1,5 +1,6 @@
 ! { dg-do compile }
 program p
+   implicit none
type t
   character :: c = 'c'
end type