[gcc r16-1205] libstdc++: Support wide characters output for sys_info and local_info [PR120565]

2025-06-06 Thread Tomasz Kaminski via Gcc-cvs
https://gcc.gnu.org/g:6dcba678030181527c6010551387917b8d734904

commit r16-1205-g6dcba678030181527c6010551387917b8d734904
Author: Tomasz Kamiński 
Date:   Fri Jun 6 09:07:49 2025 +0200

libstdc++: Support wide characters output for sys_info and local_info 
[PR120565]

Formatting sys_info as wchar_t require widening of the abbrev (zone) member.
To support that we reuse the existing code in support for '%Z' specifier, 
for
local_time_format, and produce output using singe format call with
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]" format string. As noted in 
the
comment, produced output is locale independed, as it does not contain 
decimal
separtors.

For sys_info, the outputed literals are widended using _GLIBCXX_WIDEN, 
except
opening and closing brackets, that are fetched from __format::_Separators.

PR libstdc++/120565

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h
(operator<<(basic_ostream<_CharT, _Traits>&, const sys_info&))
(operator<<(basic_ostream<_CharT, _Traits>&, const local_info&)):
Support wchar_t as _CharT.
* testsuite/std/time/format/empty_spec.cc: Instantiated test_infos 
for
wchar_t and increase timeout.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h  | 23 +-
 .../testsuite/std/time/format/empty_spec.cc|  8 
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index 9711a83cebed..c5c5e4bae53d 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -2944,9 +2944,14 @@ namespace __detail
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_info& __i)
 {
-  __os << '[' << __i.begin << ',' << __i.end
-  << ',' << hh_mm_ss(__i.offset) << ',' << __i.save
-  << ',' << __i.abbrev << ']';
+  // n.b. only decimal separator is locale dependent for specifiers
+  // used below, as sys_info uses seconds and minutes duration, the
+  // output is locale-independent.
+  constexpr auto* __fs 
+   = _GLIBCXX_WIDEN("[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]");
+  local_seconds __lb(__i.begin.time_since_epoch());
+  __os << std::format(__fs, local_time_format(__lb, &__i.abbrev),
+ __i.end, __i.offset, __i.save);
   return __os;
 }
 
@@ -2955,19 +2960,19 @@ namespace __detail
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __li)
 {
-  __os << '[';
+  __os << __format::_Separators<_CharT>::_S_squares()[0];
   if (__li.result == local_info::unique)
__os << __li.first;
   else
{
  if (__li.result == local_info::nonexistent)
-   __os << "nonexistent";
+   __os << _GLIBCXX_WIDEN("nonexistent");
  else
-   __os << "ambiguous";
- __os << " local time between " << __li.first;
- __os << " and " << __li.second;
+   __os << _GLIBCXX_WIDEN("ambiguous");
+ __os << _GLIBCXX_WIDEN(" local time between ") << __li.first;
+ __os << _GLIBCXX_WIDEN(" and ") << __li.second;
}
-  __os << ']';
+  __os << __format::_Separators<_CharT>::_S_squares()[1];
   return __os;
 }
 
diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc 
b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
index 661712f1238b..99cbd740d5f5 100644
--- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
+++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
@@ -1,6 +1,6 @@
 // { dg-do run { target c++20 } }
 // { dg-require-effective-target hosted }
-// { dg-timeout-factor 4 }
+// { dg-timeout-factor 5 }
 
 #include 
 #include 
@@ -842,14 +842,14 @@ test_all()
   test_durations();
   test_calendar();
   test_time_points();
+#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
+  test_infos();
+#endif
 }
 
 int main()
 {
   test_all();
-#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
-  test_infos();
-#endif
 
 #ifdef _GLIBCXX_USE_WCHAR_T
   test_all();


[gcc r16-1233] ada: Constant_Indexing used when context requires a variable

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:84fc53174e6b21de0aadc8f776a4f1e4a1e4f361

commit r16-1233-g84fc53174e6b21de0aadc8f776a4f1e4a1e4f361
Author: Javier Miranda 
Date:   Fri Jan 31 20:21:09 2025 +

ada: Constant_Indexing used when context requires a variable

In the case of an assignment where the type of its left hand side
is an indexable container that has indexable container components
(for example a container vector of container vectors), and both
indexable containers have Constant_Indexing and Variable_Indexing
aspects, the left hand side of the assignment is erroneously
interpreted as constant indexing. The error results in spurious
compile-time error messages saying that the left hand side of
the assignment must be a variable.

gcc/ada/ChangeLog:

* sem_ch4.adb (Constant_Indexing_OK): Add missing support for
RM 4.1.6(13/3), and improve performance to avoid climbing more
than needed. Add documentation.
(Try_Indexing_Function): New subprogram.
(Expr_Matches_In_Formal): Added new formals.
(Handle_Selected_Component): New subprogram.
(Has_IN_Mode): New subprogram.
(Try_Container_Indexing): Add documentation, code reorganization
and extend its functionality to improve its support for prefixed
notation calls.

Diff:
---
 gcc/ada/sem_ch4.adb | 886 +++-
 1 file changed, 667 insertions(+), 219 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index f04ee84adc1e..9a1784fc492c 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -308,8 +308,12 @@ package body Sem_Ch4 is
  (N  : Node_Id;
   Prefix : Node_Id;
   Exprs  : List_Id) return Boolean;
-   --  AI05-0139: Generalized indexing to support iterators over containers
-   --  ??? Need to provide a more detailed spec of what this function does
+   --  AI05-0139: Generalized indexing to support iterators over containers.
+   --  Given the N_Indexed_Component node N, with the given prefix and
+   --  expressions list, check if the generalized indexing is applicable;
+   --  if applicable then build its indexing function, link it to N through
+   --  attribute Generalized_Indexing, and return True; otherwise return
+   --  False.
 
function Try_Indexed_Call
  (N  : Node_Id;
@@ -8513,21 +8517,29 @@ package body Sem_Ch4 is
   Prefix : Node_Id;
   Exprs  : List_Id) return Boolean
is
-  Pref_Typ : Entity_Id := Etype (Prefix);
+  Heuristic : Boolean   := False;
+  Pref_Typ  : Entity_Id := Etype (Prefix);
 
   function Constant_Indexing_OK return Boolean;
-  --  Constant_Indexing is legal if there is no Variable_Indexing defined
-  --  for the type, or else node not a target of assignment, or an actual
-  --  for an IN OUT or OUT formal (RM 4.1.6 (11)).
-
-  function Expr_Matches_In_Formal
-(Subp : Entity_Id;
- Par  : Node_Id) return Boolean;
-  --  Find formal corresponding to given indexed component that is an
-  --  actual in a call. Note that the enclosing subprogram call has not
-  --  been analyzed yet, and the parameter list is not normalized, so
-  --  that if the argument is a parameter association we must match it
-  --  by name and not by position.
+  --  Determines whether the Constant_Indexing aspect has been specified
+  --  for the type of the prefix and can be interpreted as constant
+  --  indexing; that is, there is no Variable_Indexing defined for the
+  --  type, or else the node is not a target of an assignment, or an
+  --  actual for an IN OUT or OUT formal, or the name in an object
+  --  renaming (RM 4.1.6 (12/3..15/3)).
+  --
+  --  Given that prefix notation calls have not yet been resolved, if the
+  --  type of the prefix has both aspects present (Constant_Indexing and
+  --  Variable_Indexing), and context analysis performed by this routine
+  --  identifies a potential prefix notation call (i.e., an N_Selected_
+  --  Component node), this function may rely on heuristics to decide
+  --  between constant or variable indexing. In such cases, if the
+  --  decision is later found to be incorrect, Try_Container_Indexing
+  --  will retry using the alternative indexing aspect.
+
+  --  When heuristics are used to compute the result of this function
+  --  the behavior of Try_Container_Indexing might not be strictly
+  --  following the rules of the RM.
 
   function Indexing_Interpretations
 (T   : Entity_Id;
@@ -8535,59 +8547,429 @@ package body Sem_Ch4 is
   --  Return a set of interpretations reflecting all of the functions
   --  associated with an indexing aspect of type T of the given kind.
 
+  function Try_Indexing_Function
+(Func_Name : Node_Id;
+ Assoc : List_Id) return

[gcc r16-1224] ada: Tweak condition for name resolution failure

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:8727813200bf75c0f1ad22edd49c271a92831882

commit r16-1224-g8727813200bf75c0f1ad22edd49c271a92831882
Author: Ronan Desplanques 
Date:   Fri Feb 21 17:32:35 2025 +0100

ada: Tweak condition for name resolution failure

It is sometimes used as a convention across GNAT's code to set the Etype
field of a node to Any_Type to signal a name resolution error. This has
the potential to be confusing, which is why this patch replaces one such
use of the convention by a less convoluted check.

This only affects error recovery paths, and possibly doesn't change the
behavior of the compiler at all.

gcc/ada/ChangeLog:

* sem_ch4.adb (Analyze_Selected_Component): Tweak condition.

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

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 50b3eee0dbe5..d910d770ad3a 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -6040,9 +6040,10 @@ package body Sem_Ch4 is
  Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
   end if;
 
-  --  If N still has no type, the component is not defined in the prefix
+  --  If the selector is not labelled with an entity at this point, the
+  --  component is not defined in the prefix.
 
-  if Etype (N) = Any_Type then
+  if No (Entity (Sel)) then
 
  if Is_Single_Concurrent_Object then
 Error_Msg_Node_2 := Entity (Pref);


[gcc r16-1247] libstdc++: Optimize std::counting_semaphore for futex path

2025-06-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:bdae7824cd9a9d27665bf1b82f60a761a9745a6a

commit r16-1247-gbdae7824cd9a9d27665bf1b82f60a761a9745a6a
Author: Jonathan Wakely 
Date:   Wed Jun 4 15:53:20 2025 +0100

libstdc++: Optimize std::counting_semaphore for futex path

Rename __semaphore_base to __semaphore_impl, because it's not used as a
base class. Replace the three identical lambda expressions with a named
class, __semaphore_impl::_Available, which stores the most recent
value of the counter as a data member, and provides call operators that
test whether the value is decrementable (i.e. whether the semaphore can
be acquired).

Add a new __platform_semaphore_impl class template to be used when
__platform_wait is available, which uses __platform_wait_t for the
counter and uses more efficient atomic waits for the acquire functions.
For a binary semaphore some members are further optimized because we
know the counter can only be zero or one.

Also add a bare wait flag to __atomic_wait_address_v, for consistency
with __atomic_wait_address_until_v and __atomic_wait_address_for_v and
to allow semaphores to use it without the redundant overhead of tracking
waiters.

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h (__atomic_wait_address_v): Add bare
wait flag.
* include/bits/semaphore_base.h (__semaphore_base): Rename to
__semaphore_impl. Replace local variable and predicate lambdas
with _Available struct.
(__platform_semaphore_impl): New class template.
(__semaphore_impl): Remove alias template.
(_Select_semaphore_impl): New alias template.
* include/std/semaphore (counting_semaphore): Use
_Select_semaphore_impl.

Diff:
---
 libstdc++-v3/include/bits/atomic_wait.h|   5 +-
 libstdc++-v3/include/bits/semaphore_base.h | 230 ++---
 libstdc++-v3/include/std/semaphore |   5 +-
 3 files changed, 183 insertions(+), 57 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h 
b/libstdc++-v3/include/bits/atomic_wait.h
index 815726c16ccb..9ae11191d9ab 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -249,12 +249,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // C++26 will return __val
 }
 
+  // Wait on __addr while *__addr == __old is true.
   inline void
   __atomic_wait_address_v(const __detail::__platform_wait_t* __addr,
  __detail::__platform_wait_t __old,
- int __order)
+ int __order, bool __bare_wait = false)
   {
-__detail::__wait_args __args{ __addr, __old, __order };
+__detail::__wait_args __args{ __addr, __old, __order, __bare_wait };
 // C++26 will not ignore the return value here
 __detail::__wait_impl(__addr, __args);
   }
diff --git a/libstdc++-v3/include/bits/semaphore_base.h 
b/libstdc++-v3/include/bits/semaphore_base.h
index 3f7a33ccd51a..ebbc9a80b91a 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -46,23 +46,20 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  template
-  struct __semaphore_base
+  struct __semaphore_impl
   {
-using __count_type = __conditional_t<_Platform_wait,
-__detail::__platform_wait_t,
-ptrdiff_t>;
+using __count_type = ptrdiff_t;
 
 static constexpr ptrdiff_t _S_max
   = __gnu_cxx::__int_traits<__count_type>::__max;
 
 constexpr explicit
-__semaphore_base(__count_type __count) noexcept
+__semaphore_impl(__count_type __count) noexcept
 : _M_counter(__count)
 { }
 
-__semaphore_base(const __semaphore_base&) = delete;
-__semaphore_base& operator=(const __semaphore_base&) = delete;
+__semaphore_impl(const __semaphore_impl&) = delete;
+__semaphore_impl& operator=(const __semaphore_impl&) = delete;
 
 // Load the current counter value.
 _GLIBCXX_ALWAYS_INLINE __count_type
@@ -71,8 +68,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 // Try to acquire the semaphore (i.e. decrement the counter).
 // Returns false if the current counter is zero, or if another thread
-// decrements the value first. In the latter case, __cur is set to the
-// new value.
+// changes the value first. In the latter case, __cur is set to the new
+// value.
 _GLIBCXX_ALWAYS_INLINE bool
 _M_do_try_acquire(__count_type& __cur) noexcept
 {
@@ -85,24 +82,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
memory_order::relaxed);
 }
 
+// Keep trying to acquire the semaphore in a loop until it succeeds.
 void
 _M_acquire() noexcept
 {
-  auto const __vfn = [this]{ return _M_get_current(); };
-  auto __val = __vfn();

[gcc r15-9782] tree-optimization/119960 - failed external SLP promotion

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:8fb3d9066266ea30de62c395239bda4e992297a3

commit r15-9782-g8fb3d9066266ea30de62c395239bda4e992297a3
Author: Richard Biener 
Date:   Tue Apr 29 13:23:41 2025 +0200

tree-optimization/119960 - failed external SLP promotion

The following addresses a too conservative sanity check of SLP nodes
we want to promote external.  The issue lies in code generation
for such external which relies on get_later_stmt to figure an
insert location.  But get_later_stmt relies on the ability to
totally order stmts, specifically implementation-wise that they
are all from the same BB, which is what is verified at the moment.

The patch changes this to require stmts to be orderable by
dominance queries.  For simplicity and seemingly enough for the
testcase in PR119960, this handles the case of two distinct BBs.

PR tree-optimization/119960
* tree-vect-slp.cc (vect_slp_can_convert_to_external):
Handle cases where defs from multiple BBs are ordered
by their dominance relation.

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

(cherry picked from commit cc74e2f2b39b6debbef1787a087abad2108e95dd)

Diff:
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr119960-1.c | 15 +++
 gcc/tree-vect-slp.cc  | 63 ---
 2 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr119960-1.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-pr119960-1.c
new file mode 100644
index ..955fc7e32208
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr119960-1.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_double } */
+
+double foo (double *dst, double *src, int b)
+{
+  double y = src[1];
+  if (b)
+{
+  dst[0] = src[0];
+  dst[1] = y;
+}
+  return y;
+}
+
+/* { dg-final { scan-tree-dump "optimized: basic block part vectorized" "slp2" 
{ target vect_double } } } */
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index b5addd6d76bb..f5286e6b819e 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -7842,21 +7842,70 @@ vect_slp_analyze_node_operations_1 (vec_info *vinfo, 
slp_tree node,
node, node_instance, cost_vec);
 }
 
+static int
+sort_ints (const void *a_, const void *b_)
+{
+  int a = *(const int *)a_;
+  int b = *(const int *)b_;
+  return a - b;
+}
+
 /* Verify if we can externalize a set of internal defs.  */
 
 static bool
 vect_slp_can_convert_to_external (const vec &stmts)
 {
+  /* Constant generation uses get_later_stmt which can only handle
+ defs from the same BB or a set of defs that can be ordered
+ with a dominance query.  */
   basic_block bb = NULL;
+  bool all_same = true;
+  auto_vec bbs;
+  bbs.reserve_exact (stmts.length ());
   for (stmt_vec_info stmt : stmts)
-if (!stmt)
-  return false;
-/* Constant generation uses get_later_stmt which can only handle
-   defs from the same BB.  */
-else if (!bb)
-  bb = gimple_bb (stmt->stmt);
-else if (gimple_bb (stmt->stmt) != bb)
+{
+  if (!stmt)
+   return false;
+  else if (!bb)
+   bb = gimple_bb (stmt->stmt);
+  else if (gimple_bb (stmt->stmt) != bb)
+   all_same = false;
+  bbs.quick_push (gimple_bb (stmt->stmt)->index);
+}
+  if (all_same)
+return true;
+
+  /* Produce a vector of unique BB indexes for the defs.  */
+  bbs.qsort (sort_ints);
+  unsigned i, j;
+  for (i = 1, j = 1; i < bbs.length (); ++i)
+if (bbs[i] != bbs[j-1])
+  bbs[j++] = bbs[i];
+  gcc_assert (j >= 2);
+  bbs.truncate (j);
+
+  if (bbs.length () == 2)
+return (dominated_by_p (CDI_DOMINATORS,
+   BASIC_BLOCK_FOR_FN (cfun, bbs[0]),
+   BASIC_BLOCK_FOR_FN (cfun, bbs[1]))
+   || dominated_by_p (CDI_DOMINATORS,
+  BASIC_BLOCK_FOR_FN (cfun, bbs[1]),
+  BASIC_BLOCK_FOR_FN (cfun, bbs[0])));
+
+  /* ???  For more than two BBs we can sort the vector and verify the
+ result is a total order.  But we can't use vec::qsort with a
+ compare function using a dominance query since there's no way to
+ signal failure and any fallback for an unordered pair would
+ fail qsort_chk later.
+ For now simply hope that ordering after BB index provides the
+ best candidate total order.  If required we can implement our
+ own mergesort or export an entry without checking.  */
+  for (unsigned i = 1; i < bbs.length (); ++i)
+if (!dominated_by_p (CDI_DOMINATORS,
+BASIC_BLOCK_FOR_FN (cfun, bbs[i]),
+BASIC_BLOCK_FOR_FN (cfun, bbs[i-1])))
   return false;
+
   return true;
 }


[gcc r15-9783] tree-optimization/120003 - missed jump threading

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:4d375ebd56c54dc8c242bed988f29094b7e3e94e

commit r15-9783-g4d375ebd56c54dc8c242bed988f29094b7e3e94e
Author: Richard Biener 
Date:   Wed Apr 30 11:52:17 2025 +0200

tree-optimization/120003 - missed jump threading

The following allows the entry and exit block of a jump thread path
to be equal, which can easily happen when there isn't a forwarder
on the interesting edge for an FSM thread conditional.  We just
don't want to enlarge the path from such a block.

PR tree-optimization/120003
* tree-ssa-threadbackward.cc (back_threader::find_paths_to_names):
Allow block re-use but do not enlarge the path beyond such a
re-use.

* gcc.dg/tree-ssa/ssa-thread-23.c: New testcase.
* gcc.dg/tree-ssa/ssa-dom-thread-7.c: Adjust.

(cherry picked from commit 1a13684dfc7286139064f7d7341462c9995cbd1c)

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c |  4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-23.c| 19 +++
 gcc/tree-ssa-threadbackward.cc   |  8 +++-
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
index d84aceebc5d0..8be9878e0cfb 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
@@ -11,8 +11,8 @@
to change decisions in switch expansion which in turn can expose new
jump threading opportunities.  Skip the later tests on aarch64.  */
 /* { dg-final { scan-tree-dump-not "Jumps threaded"  "dom3" { target { ! 
aarch64*-*-* } } } } */
-/* { dg-final { scan-tree-dump "Jumps threaded: 9"  "thread2" { target { ! 
aarch64*-*-* } } } } */
-/* { dg-final { scan-tree-dump "Jumps threaded: 17"  "thread2" { target { 
aarch64*-*-* } } } } */
+/* { dg-final { scan-tree-dump "Jumps threaded: 10"  "thread2" { target { ! 
aarch64*-*-* } } } } */
+/* { dg-final { scan-tree-dump "Jumps threaded: 14"  "thread2" { target { 
aarch64*-*-* } } } } */
 
 enum STATE {
   S0=0,
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-23.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-23.c
new file mode 100644
index ..930360a33b57
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-23.c
@@ -0,0 +1,19 @@
+/* PR120003 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce3-details" } */
+
+extern _Bool g(int);
+
+_Bool f()
+{
+  _Bool retval = 0;
+  for(int i=0; i<100; ++i)
+retval = retval || g(i);
+  return retval;
+}
+
+/* Jump threading after loop optimization should get the counting loop
+   separated from the loop until retval is true and CD-DCE elide it.
+   It's difficult to check for the fact that a true retval terminates
+   the loop so check CD-DCE eliminates one loop instead.  */
+/* { dg-final { scan-tree-dump "fix_loop_structure: removing loop" "cddce3" } 
} */
diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc
index d0b74b2531df..3adb83e97126 100644
--- a/gcc/tree-ssa-threadbackward.cc
+++ b/gcc/tree-ssa-threadbackward.cc
@@ -349,9 +349,6 @@ back_threader::find_paths_to_names (basic_block bb, bitmap 
interesting,
unsigned overall_paths,
back_threader_profitability &profit)
 {
-  if (m_visited_bbs.add (bb))
-return;
-
   m_path.safe_push (bb);
 
   // Try to resolve the path without looking back.  Avoid resolving paths
@@ -377,7 +374,8 @@ back_threader::find_paths_to_names (basic_block bb, bitmap 
interesting,
   // Continue looking for ways to extend the path but limit the
   // search space along a branch
   else if ((overall_paths = overall_paths * EDGE_COUNT (bb->preds))
-  <= (unsigned)param_max_jump_thread_paths)
+  <= (unsigned)param_max_jump_thread_paths
+  && !m_visited_bbs.add (bb))
 {
   // For further greedy searching we want to remove interesting
   // names defined in BB but add ones on the PHI edges for the
@@ -489,6 +487,7 @@ back_threader::find_paths_to_names (basic_block bb, bitmap 
interesting,
 backtracking we have to restore it.  */
   for (int j : new_imports)
bitmap_clear_bit (m_imports, j);
+  m_visited_bbs.remove (bb);
 }
   else if (dump_file && (dump_flags & TDF_DETAILS))
 fprintf (dump_file, "  FAIL: Search space limit %d reached.\n",
@@ -496,7 +495,6 @@ back_threader::find_paths_to_names (basic_block bb, bitmap 
interesting,
 
   // Reset things to their original state.
   m_path.pop ();
-  m_visited_bbs.remove (bb);
 }
 
 // Search backwards from BB looking for paths where the final


[gcc r16-1251] PR modula2/120542: Return statement in the main procedure crashes the compiler

2025-06-06 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:16ab791531ec16fd4596a25efbe6b42e6c16171f

commit r16-1251-g16ab791531ec16fd4596a25efbe6b42e6c16171f
Author: Gaius Mulley 
Date:   Fri Jun 6 10:46:48 2025 +0100

PR modula2/120542: Return statement in the main procedure crashes the 
compiler

The patch checks whether a return statement is allowed.  It also checks
to see that a return expression is allowed.

gcc/m2/ChangeLog:

PR modula2/120542
* gm2-compiler/M2Quads.mod (BuildReturnLower): New procedure.
(BuildReturn): Allow return without an expression from
module initialization blocks.  Generate an error if an
expression is provided.  Call BuildReturnLower if no error
was seen.

gcc/testsuite/ChangeLog:

PR modula2/120542
* gm2/iso/fail/badreturn.mod: New test.
* gm2/iso/fail/badreturn2.mod: New test.
* gm2/iso/pass/modulereturn.mod: New test.
* gm2/iso/pass/modulereturn2.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod  | 60 ++--
 gcc/testsuite/gm2/iso/fail/badreturn.mod |  5 +++
 gcc/testsuite/gm2/iso/fail/badreturn2.mod| 12 ++
 gcc/testsuite/gm2/iso/pass/modulereturn.mod  |  5 +++
 gcc/testsuite/gm2/iso/pass/modulereturn2.mod | 10 +
 5 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 3c29fdd3b2ba..b5455d09c66f 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -11298,6 +11298,35 @@ BEGIN
 END CheckReturnType ;
 
 
+(*
+   BuildReturnLower - check the return type and value to ensure type
+  compatibility and no range overflow will occur.
+*)
+
+PROCEDURE BuildReturnLower (tokcombined, tokexpr: CARDINAL; e1, t1: CARDINAL) ;
+VAR
+   e2, t2: CARDINAL ;
+BEGIN
+   (* This will check that the type returned is compatible with
+  the formal return type of the procedure.  *)
+   CheckReturnType (tokcombined, CurrentProc, e1, t1) ;
+   (* Dereference LeftValue if necessary.  *)
+   IF GetMode (e1) = LeftValue
+   THEN
+  t2 := GetSType (CurrentProc) ;
+  e2 := MakeTemporary (tokexpr, RightValue) ;
+  PutVar(e2, t2) ;
+  CheckPointerThroughNil (tokexpr, e1) ;
+  doIndrX (tokexpr, e2, e1) ;
+  e1 := e2
+   END ;
+   (* Here we check the data contents to ensure no overflow.  *)
+   BuildRange (InitReturnRangeCheck (tokcombined, CurrentProc, e1)) ;
+   GenQuadOtok (tokcombined, ReturnValueOp, e1, NulSym, CurrentProc, FALSE,
+tokcombined, UnknownTokenNo, GetDeclaredMod (CurrentProc))
+END BuildReturnLower ;
+
+
 (*
BuildReturn - Builds the Return part of the procedure.
  tokreturn is the location of the RETURN keyword.
@@ -11317,7 +11346,6 @@ PROCEDURE BuildReturn (tokreturn: CARDINAL) ;
 VAR
tokcombined,
tokexpr: CARDINAL ;
-   e2, t2,
e1, t1,
t, f,
Des: CARDINAL ;
@@ -11337,26 +11365,18 @@ BEGIN
tokcombined := MakeVirtualTok (tokreturn, tokreturn, tokexpr) ;
IF e1 # NulSym
THEN
-  (* this will check that the type returned is compatible with
- the formal return type of the procedure.  *)
-  CheckReturnType (tokcombined, CurrentProc, e1, t1) ;
-  (* dereference LeftValue if necessary *)
-  IF GetMode (e1) = LeftValue
-  THEN
- t2 := GetSType (CurrentProc) ;
- e2 := MakeTemporary (tokexpr, RightValue) ;
- PutVar(e2, t2) ;
- CheckPointerThroughNil (tokexpr, e1) ;
- doIndrX (tokexpr, e2, e1) ;
-(* here we check the data contents to ensure no overflow.  *)
- BuildRange (InitReturnRangeCheck (tokcombined, CurrentProc, e2)) ;
- GenQuadOtok (tokcombined, ReturnValueOp, e2, NulSym, CurrentProc, 
FALSE,
-  tokcombined, UnknownTokenNo, GetDeclaredMod 
(CurrentProc))
+  (* Check we are in a procedure scope and that the procedure has a return 
type.  *)
+  IF CurrentProc = NulSym
+  THEN
+ MetaErrorT0 (tokcombined,
+  '{%1E} attempting to return a value when not in a 
procedure scope')
+  ELSIF GetSType (CurrentProc) = NulSym
+  THEN
+ MetaErrorT1 (tokcombined,
+  'attempting to return a value from procedure {%1Ea} 
which does not have a return type',
+ CurrentProc)
   ELSE
-(* here we check the data contents to ensure no overflow.  *)
- BuildRange (InitReturnRangeCheck (tokcombined, CurrentProc, e1)) ;
- GenQuadOtok (tokcombined, ReturnValueOp, e1, NulSym, CurrentProc, 
FALSE,
-  tokcombined, UnknownTokenNo, GetDeclaredMod 
(CurrentProc))
+ BuildReturnLower (tokcombined, tokexpr, e1, t1)
   END
END ;
GenQuadO (tokcombined, GotoOp, NulSym, NulSym, PopWord (ReturnStack), 
FAL

[gcc r15-9787] tree-optimization/120357 - ICE with early break vectorization

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:8cb0127dfd3d01d4549f3139b087d1a5966844ee

commit r15-9787-g8cb0127dfd3d01d4549f3139b087d1a5966844ee
Author: Richard Biener 
Date:   Fri May 30 14:11:47 2025 +0200

tree-optimization/120357 - ICE with early break vectorization

When doing early break vectorization of a loop with a conditional
reduction the epilog creation code is confused as to before which exit
to insert the conditional reduction induction IV update.  The
following make sure this is done before the main IV exit.

PR tree-optimization/120357
* tree-vect-loop.cc (vect_create_epilog_for_reduction): Create
the conditional reduction induction IV increment before the
main IV exit.

* gcc.dg/vect/vect-early-break_136-pr120357.c: New testcase.

(cherry picked from commit dce4da51ab66c3abb84448326910cd42f6fe2499)

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-early-break_136-pr120357.c | 13 +
 gcc/tree-vect-loop.cc |  3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_136-pr120357.c 
b/gcc/testsuite/gcc.dg/vect/vect-early-break_136-pr120357.c
new file mode 100644
index ..8a51cfc46a5d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_136-pr120357.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-additional-options "-O3" } */
+
+char a;
+unsigned long long t[2][22];
+int u[22];
+void f(void)
+{
+  for (int v = 0; v < 22; v++)
+for (_Bool w = 0; w < (u[v] < 0) + 1; w = 1)
+  a *= 0 != t[w][v];
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 2d35fa128864..c824b5abaaff 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6189,7 +6189,8 @@ vect_create_epilog_for_reduction (loop_vec_info 
loop_vinfo,
   /* Create an induction variable.  */
   gimple_stmt_iterator incr_gsi;
   bool insert_after;
-  vect_iv_increment_position (loop_exit, &incr_gsi, &insert_after);
+  vect_iv_increment_position (LOOP_VINFO_IV_EXIT (loop_vinfo),
+ &incr_gsi, &insert_after);
   create_iv (series_vect, PLUS_EXPR, vec_step, NULL_TREE, loop, &incr_gsi,
 insert_after, &indx_before_incr, &indx_after_incr);


[gcc r15-9785] rtl-optimization/120182 - wrong-code with RTL DSE and constant addresses

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:44792a6c4253f9a5b322797ef73b9c347c223545

commit r15-9785-g44792a6c4253f9a5b322797ef73b9c347c223545
Author: Richard Biener 
Date:   Fri May 9 08:38:45 2025 +0200

rtl-optimization/120182 - wrong-code with RTL DSE and constant addresses

RTL DSE forms store groups from unique invariant bases but that is
confused when presented with constant addresses where it assigns
one store group per unique address.  That causes it to not consider
0x101:QI to alias 0x100:SI.  Constant accesses can really alias
to every object, in practice they appear for I/O and for access
to objects fixed via linker scripts for example.  So simply avoid
registering a store group for them.

PR rtl-optimization/120182
* dse.cc (canon_address): Constant addresses have no
separate store group.

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

(cherry picked from commit b9434c3db900d5d037fdf2f64149b82800ceadf8)

Diff:
---
 gcc/dse.cc  |  5 +++-
 gcc/testsuite/gcc.dg/torture/pr120182.c | 42 +
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/gcc/dse.cc b/gcc/dse.cc
index ffc86ffabe5e..14f82c364c06 100644
--- a/gcc/dse.cc
+++ b/gcc/dse.cc
@@ -1190,7 +1190,10 @@ canon_address (rtx mem,
   address = strip_offset_and_add (address, offset);
 
   if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (mem))
- && const_or_frame_p (address))
+ && const_or_frame_p (address)
+ /* Literal addresses can alias any base, avoid creating a
+group for them.  */
+ && ! CONST_SCALAR_INT_P (address))
{
  group_info *group = get_group_info (address);
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr120182.c 
b/gcc/testsuite/gcc.dg/torture/pr120182.c
new file mode 100644
index ..5e2d171ef985
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr120182.c
@@ -0,0 +1,42 @@
+/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
+
+#include 
+#include 
+#include 
+
+struct S
+{
+  struct S *next;
+};
+
+static void __attribute__((noipa))
+allocate(void *addr, unsigned long long size)
+{
+  void *ptr = mmap((void *)addr, size,
+  PROT_READ | PROT_WRITE,
+  MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
+  -1, 0);
+  if(ptr != addr)
+exit(0);
+}
+
+int main (void)
+{
+  int size = 0x8000;
+  char *ptr = (char *)0x288000ull;
+  allocate((void *)ptr, size);
+
+  struct S *s1 = (struct S *)ptr;
+  struct S *s2 = (struct S *)256;
+  for (int i = 0; i < 3; i++)
+{
+  for(char *addr = (char *)s1; addr < (char *)s1 + sizeof(*s1); ++addr)
+   *addr = 0;
+
+  if(s1->next)
+   s1->next = s1->next->next = s2;
+  else
+   s1->next = s2;
+}
+  return 0;
+}


[gcc r16-1246] More of autofdo 0 issues

2025-06-06 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:22f1f765db056527076a3b7e785b068f3ea28cf0

commit r16-1246-g22f1f765db056527076a3b7e785b068f3ea28cf0
Author: Jan Hubicka 
Date:   Fri Jun 6 10:43:38 2025 +0200

More of autofdo 0 issues

This patch fixes ICE seen when building spec2k17 with autofdo and enable
checking compiler.  Bause we special case 0 of autofdo to be kind of 1 in 
IPA
scalling, we can now end up with function heving global0 profile but 
producing
inline clone with nonzero profile.

I think correct way is to extend auto-profile generation to merge static 
profile
with afdo in places afdo profile is missing and drop the autofdo 0 hacks, 
but
I think we need to run benchmarks first before making broader changes here.

* profile-count.cc (profile_count::to_sreal_scale): Special case 0 
of autofdo.
(profile_count::combine_with_ipa_count): If outer function has 
GLOBAL0 profile
but innter counter has non-zero profile, force it to be 0.

Diff:
---
 gcc/profile-count.cc | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc
index 2d9c778b3758..22c109ab528c 100644
--- a/gcc/profile-count.cc
+++ b/gcc/profile-count.cc
@@ -344,6 +344,10 @@ profile_count::to_sreal_scale (profile_count in, bool 
*known) const
 return 1;
   if (!in.m_val)
 return m_val * 4;
+  /* Auto-FDO 0 really just means that we have no samples.
+ Treat it as small non-zero frequency.  */
+  if (!m_val && quality () == AFDO)
+return (sreal)1 / (sreal)in.m_val;
   return (sreal)m_val / (sreal)in.m_val;
 }
 
@@ -398,7 +402,7 @@ profile_count::combine_with_ipa_count (profile_count ipa)
   return this->global0adjusted ();
 }
 
-/* Sae as profile_count::combine_with_ipa_count but within function with count
+/* Same as profile_count::combine_with_ipa_count but within function with count
IPA2.  */
 profile_count
 profile_count::combine_with_ipa_count_within (profile_count ipa,
@@ -410,7 +414,16 @@ profile_count::combine_with_ipa_count_within 
(profile_count ipa,
   if (ipa2.ipa () == ipa2 && ipa.initialized_p ())
 ret = ipa;
   else
-ret = combine_with_ipa_count (ipa);
+{
+  /* For inconsistent profiles we may end up having ipa2 of GLOBAL0
+while ipa is non-zero (i.e. non-zero IPA counters within function
+executed 0 times).  Be sure we produce GLOBAL0 as well
+so counters remain compatible.  */
+  if (ipa.nonzero_p ()
+ && ipa2.ipa ().initialized_p ())
+   ipa = ipa2.ipa ();
+  ret = combine_with_ipa_count (ipa);
+}
   gcc_checking_assert (ret.compatible_p (ipa2));
   return ret;
 }


[gcc r15-9784] Fix gcc.dg/tree-ssa/ssa-dom-thread-7.c for aarch64

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:ca8032d6177668ca7f2a6a2e612e126a97ba8c53

commit r15-9784-gca8032d6177668ca7f2a6a2e612e126a97ba8c53
Author: Richard Biener 
Date:   Thu May 1 13:56:25 2025 +0200

Fix gcc.dg/tree-ssa/ssa-dom-thread-7.c for aarch64

So on another machine with a cross I see 17 jumps threaded, so adjusted
like that.

PR tree-optimization/120003
* gcc.dg/tree-ssa/ssa-dom-thread-7.c: Adjust aarch64 expected
thread2 number of threads.

(cherry picked from commit aa6f1df4ec46a20d2292291b192d3331e51b59f8)

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
index 8be9878e0cfb..59891f29132c 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c
@@ -12,7 +12,7 @@
jump threading opportunities.  Skip the later tests on aarch64.  */
 /* { dg-final { scan-tree-dump-not "Jumps threaded"  "dom3" { target { ! 
aarch64*-*-* } } } } */
 /* { dg-final { scan-tree-dump "Jumps threaded: 10"  "thread2" { target { ! 
aarch64*-*-* } } } } */
-/* { dg-final { scan-tree-dump "Jumps threaded: 14"  "thread2" { target { 
aarch64*-*-* } } } } */
+/* { dg-final { scan-tree-dump "Jumps threaded: 17"  "thread2" { target { 
aarch64*-*-* } } } } */
 
 enum STATE {
   S0=0,


[gcc r15-9781] tree-optimization/116352 - amend previous fix

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:7da2b6ddf3a8371b585595231cddcb1ad0942ea4

commit r15-9781-g7da2b6ddf3a8371b585595231cddcb1ad0942ea4
Author: Richard Biener 
Date:   Thu May 8 10:56:16 2025 +0200

tree-optimization/116352 - amend previous fix

The previous fix restricted external vector builds to defs from
the same basic-block.  That turns out too restrictive so we have
to mitigate the original issue in a different way which is
restricting it to the original case where all defs are in the
same basic-block.

PR tree-optimization/116352
* tree-vect-slp.cc (vect_build_slp_tree_2): When compressing
operands from a two-operator node make sure the resulting
operation does not mix defs from different basic-blocks.

(cherry picked from commit 1e8bd720b1a618a39e2a41eec05e935c32d295f3)

Diff:
---
 gcc/tree-vect-slp.cc | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index ed432a95d33f..b5addd6d76bb 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -2616,13 +2616,14 @@ out:
   if (oprnds_info[0]->def_stmts[0]
  && is_a (oprnds_info[0]->def_stmts[0]->stmt))
code = gimple_assign_rhs_code (oprnds_info[0]->def_stmts[0]->stmt);
+  basic_block bb = nullptr;
 
   for (unsigned j = 0; j < group_size; ++j)
{
  FOR_EACH_VEC_ELT (oprnds_info, i, oprnd_info)
{
  stmt_vec_info stmt_info = oprnd_info->def_stmts[j];
- if (!stmt_info || !stmt_info->stmt
+ if (!stmt_info
  || !is_a (stmt_info->stmt)
  || gimple_assign_rhs_code (stmt_info->stmt) != code
  || skip_args[i])
@@ -2630,6 +2631,14 @@ out:
  success = false;
  break;
}
+ /* Avoid mixing lanes with defs in different basic-blocks.  */
+ if (!bb)
+   bb = gimple_bb (vect_orig_stmt (stmt_info)->stmt);
+ else if (gimple_bb (vect_orig_stmt (stmt_info)->stmt) != bb)
+   {
+ success = false;
+ break;
+   }
 
  bool exists;
  unsigned &stmt_idx


[gcc r16-1250] Fix assertion failure on small array constructor

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:61b014f614be523174f6a9df6e1fbac11de11abd

commit r16-1250-g61b014f614be523174f6a9df6e1fbac11de11abd
Author: Eric Botcazou 
Date:   Fri Jun 6 11:32:51 2025 +0200

Fix assertion failure on small array constructor

The Ada testcase triggers an assertion failure in size_binop_loc:

+===GNAT BUG DETECTED==+
| 16.0.0 20250605 (experimental) (x86_64-suse-linux) GCC error:|
| in size_binop_loc, at fold-const.cc:2091 |
| Error detected around aggr7.ads:9:36

  gcc_assert (int_binop_types_match_p (code, TREE_TYPE (arg0),
   TREE_TYPE (arg1)));

because the very old code for ARRAY_TYPE in store_constructor is confused in
the case where it cannot perform static host-based arithmetics on offsets.

But the root cause is that it performs all the calculations in signed
sizetype while TYPE_DOMAIN is supposed to be a subtype of (unsigned)
sizetype, even for signed index types in Ada like in the testcase,
so the code takes the dynamic path instead of the static one for
negative indices.

gcc/
* expr.cc (store_constructor) : Perform the arithmetics
on offsets in (unsigned) sizetype.

gcc/testsuite/
* gnat.dg/specs/aggr7.ads: New test.

Diff:
---
 gcc/expr.cc   | 100 --
 gcc/testsuite/gnat.dg/specs/aggr7.ads |  11 
 2 files changed, 58 insertions(+), 53 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 1eeefa1cadc0..b3b46a266268 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -7631,8 +7631,8 @@ store_constructor (tree exp, rtx target, int cleared, 
poly_int64 size,
tree domain;
tree elttype = TREE_TYPE (type);
bool const_bounds_p;
-   HOST_WIDE_INT minelt = 0;
-   HOST_WIDE_INT maxelt = 0;
+   unsigned HOST_WIDE_INT minelt = 0;
+   unsigned HOST_WIDE_INT maxelt = 0;
 
/* The storage order is specified for every aggregate type.  */
reverse = TYPE_REVERSE_STORAGE_ORDER (type);
@@ -7640,14 +7640,14 @@ store_constructor (tree exp, rtx target, int cleared, 
poly_int64 size,
domain = TYPE_DOMAIN (type);
const_bounds_p = (TYPE_MIN_VALUE (domain)
  && TYPE_MAX_VALUE (domain)
- && tree_fits_shwi_p (TYPE_MIN_VALUE (domain))
- && tree_fits_shwi_p (TYPE_MAX_VALUE (domain)));
+ && tree_fits_uhwi_p (TYPE_MIN_VALUE (domain))
+ && tree_fits_uhwi_p (TYPE_MAX_VALUE (domain)));
 
/* If we have constant bounds for the range of the type, get them.  */
if (const_bounds_p)
  {
-   minelt = tree_to_shwi (TYPE_MIN_VALUE (domain));
-   maxelt = tree_to_shwi (TYPE_MAX_VALUE (domain));
+   minelt = tree_to_uhwi (TYPE_MIN_VALUE (domain));
+   maxelt = tree_to_uhwi (TYPE_MAX_VALUE (domain));
  }
 
/* If the constructor has fewer elements than the array, clear
@@ -7660,7 +7660,7 @@ store_constructor (tree exp, rtx target, int cleared, 
poly_int64 size,
else
  {
unsigned HOST_WIDE_INT idx;
-   HOST_WIDE_INT count = 0, zero_count = 0;
+   unsigned HOST_WIDE_INT count = 0, zero_count = 0;
need_to_clear = ! const_bounds_p;
 
/* This loop is a more accurate version of the loop in
@@ -7668,7 +7668,7 @@ store_constructor (tree exp, rtx target, int cleared, 
poly_int64 size,
   is also needed to check for missing elements.  */
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
  {
-   HOST_WIDE_INT this_node_count;
+   unsigned HOST_WIDE_INT this_node_count;
 
if (need_to_clear)
  break;
@@ -7742,16 +7742,16 @@ store_constructor (tree exp, rtx target, int cleared, 
poly_int64 size,
  {
tree lo_index = TREE_OPERAND (index, 0);
tree hi_index = TREE_OPERAND (index, 1);
-   rtx index_r, pos_rtx;
-   HOST_WIDE_INT lo, hi, count;
-   tree position;
+   rtx index_r;
+   unsigned HOST_WIDE_INT lo, hi, count;
+   tree offset;
 
/* If the range is constant and "small", unroll the loop.  */
if (const_bounds_p
-   && tree_fits_shwi_p (lo_index)
-   && tree_fits_shwi_p (hi_index)
-   && (lo = tree_to_shwi (lo_index),
-   hi = tree_to_shwi (hi_index),
+   && tree_fits_uhwi_p (lo_index)
+   && tree_fits_uhwi_p (hi_index)
+   && (lo = tree_to_uhwi (lo_index),
+   hi = tree_to_uhwi (hi_index),
count 

[gcc r16-1235] ada: Deconstruct C header for the SCOs unit

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:82ece409b8be75a7d57c43efbeb28c166d981747

commit r16-1235-g82ece409b8be75a7d57c43efbeb28c166d981747
Author: Piotr Trojanek 
Date:   Wed Feb 26 18:00:57 2025 +0100

ada: Deconstruct C header for the SCOs unit

The C version of SCOs unit provided a gigi interface to source code 
obligations
that at some point were generated by the frontend. This functionality has 
been
deconstructed long ago.

gcc/ada/ChangeLog:

* libgnat/g-dyntab.ads (Instance): Update and extend comment.
* scos.ads: Remove comment about the corresponding C header.
* scos.h: Remove.

Diff:
---
 gcc/ada/libgnat/g-dyntab.ads |  5 ++-
 gcc/ada/scos.ads |  3 --
 gcc/ada/scos.h   | 89 
 3 files changed, 3 insertions(+), 94 deletions(-)

diff --git a/gcc/ada/libgnat/g-dyntab.ads b/gcc/ada/libgnat/g-dyntab.ads
index 7e2e3b22be4a..78109867ec26 100644
--- a/gcc/ada/libgnat/g-dyntab.ads
+++ b/gcc/ada/libgnat/g-dyntab.ads
@@ -168,8 +168,9 @@ package GNAT.Dynamic_Tables is
   --
   -- Tab : Table_Type renames X.Table (First .. X.Last);
   --
-  --  Note: The Table component must come first. See declarations of
-  --  SCO_Unit_Table and SCO_Table in scos.h.
+  --  Note: The Table component must come first to simplify interfacing
+  --  with C, similar to how we do it for the Table unit; see declarations
+  --  of Names_Ptr and Names_Char_Ptr in namet.h.
 
   Locked : Boolean := False;
   --  Table reallocation is permitted only if this is False. A client may
diff --git a/gcc/ada/scos.ads b/gcc/ada/scos.ads
index a2ade8a0907a..b5f39c9632e3 100644
--- a/gcc/ada/scos.ads
+++ b/gcc/ada/scos.ads
@@ -28,9 +28,6 @@
 --  the ALI file, and by Get_SCO/Put_SCO to read and write the text form that
 --  is used in the ALI file.
 
---  WARNING: There is a C version of this package. Any changes to this
---  source file must be properly reflected in the C header file scos.h
-
 with Namet; use Namet;
 with Table;
 with Types; use Types;
diff --git a/gcc/ada/scos.h b/gcc/ada/scos.h
deleted file mode 100644
index 3d800bf12b15..
--- a/gcc/ada/scos.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/
- *  *
- * GNAT COMPILER COMPONENTS *
- *  *
- * S C O S  *
- *  *
- *  C Header File   *
- *  *
- *   Copyright (C) 2014-2025, Free Software Foundation, Inc.*
- *  *
- * GNAT is free software;  you can  redistribute it  and/or modify it under *
- * terms of the  GNU General Public License as published  by the Free Soft- *
- * ware  Foundation;  either version 3,  or (at your option) any later ver- *
- * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
- * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License *
- * for  more details.  You should have  received  a copy of the GNU General *
- * Public License  distributed with GNAT; see file COPYING3.  If not, go to *
- * http://www.gnu.org/licenses for a complete copy of the license.  *
- *  *
- * GNAT was originally developed  by the GNAT team at  New York University. *
- * Extensive contributions were provided by Ada Core Technologies Inc.  *
- *  *
- /
-
-/* This is the C header that corresponds to the Ada package specification for
-   Scos.  It was created manually from scos.ads and must be kept synchronized
-   with changes in this file.  */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Unit table:  */
-
-typedef Int SCO_Unit_Index;
-
-struct SCO_Unit_Table_Entry
-  {
-String_Pointer File_Name;
-Int File_Index;
-Nat Dep_Num;
-Nat From, To;
-  };
-
-typedef struct SCO_Unit_Table_Entry *SCO_Unit_Table_Type;
-
-extern SCO_Unit_Table_Type scos__sco_unit_table__table;
-#define SCO_Unit_Table scos__sco_unit_table__table
-
-extern Int scos__sco_unit_table__min;
-#define SCO_Unit_Table_Min scos__sco_unit_table__min
-
-extern Int scos__sco_unit_table__last_val;
-#define SCO_Unit_Table_Last_Val scos__sco_unit_table__last_val
-
-
-/* SCOs table:  */
-
-struct So

[gcc r16-1241] ada: Add null exclusion to registration of floating-point types

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:9e349587dec0eed4f0183c7ddc7b7392612e5547

commit r16-1241-g9e349587dec0eed4f0183c7ddc7b7392612e5547
Author: Piotr Trojanek 
Date:   Tue Feb 18 14:38:24 2025 +0100

ada: Add null exclusion to registration of floating-point types

Null exclusion both clarifies the intention of the code and allows GNAT to
eliminate runtime checks where possible (or make them fail where violated), 
at
least in developer builds. Code cleanup.

gcc/ada/ChangeLog:

* get_targ.ads (Register_Proc_Type): Add null exclusion.

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

diff --git a/gcc/ada/get_targ.ads b/gcc/ada/get_targ.ads
index 35cf00d73a1a..4b658f10884f 100644
--- a/gcc/ada/get_targ.ads
+++ b/gcc/ada/get_targ.ads
@@ -113,7 +113,7 @@ package Get_Targ is
type C_String is array (0 .. 255) of aliased Character;
pragma Convention (C, C_String);
 
-   type Register_Type_Proc is access procedure
+   type Register_Type_Proc is not null access procedure
  (C_Name: C_String;   -- Nul-terminated string with name of type
   Digs  : Natural;-- Digits for floating point, 0 otherwise
   Complex   : Boolean;-- True iff type has real and imaginary parts


[gcc r15-9779] tree-optimization/119960 - fix and guard get_later_stmt

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:6bb316973249d460f4dae2c33a0aa5bc2928ef30

commit r15-9779-g6bb316973249d460f4dae2c33a0aa5bc2928ef30
Author: Richard Biener 
Date:   Tue Apr 29 14:52:27 2025 +0200

tree-optimization/119960 - fix and guard get_later_stmt

The following makes get_later_stmt handle stmts from different
basic-blocks in the case they are orderd and otherwise asserts.

* tree-vectorizer.h (get_later_stmt): Robustify against
stmts in different BBs, assert when they are unordered.

(cherry picked from commit a6cfde60d8c744b31b147022e797bbcc371ae092)

Diff:
---
 gcc/tree-vectorizer.h | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 01d19c776561..94cbfde6c9a7 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1870,11 +1870,25 @@ vect_orig_stmt (stmt_vec_info stmt_info)
 inline stmt_vec_info
 get_later_stmt (stmt_vec_info stmt1_info, stmt_vec_info stmt2_info)
 {
-  if (gimple_uid (vect_orig_stmt (stmt1_info)->stmt)
-  > gimple_uid (vect_orig_stmt (stmt2_info)->stmt))
+  gimple *stmt1 = vect_orig_stmt (stmt1_info)->stmt;
+  gimple *stmt2 = vect_orig_stmt (stmt2_info)->stmt;
+  if (gimple_bb (stmt1) == gimple_bb (stmt2))
+{
+  if (gimple_uid (stmt1) > gimple_uid (stmt2))
+   return stmt1_info;
+  else
+   return stmt2_info;
+}
+  /* ???  We should be really calling this function only with stmts
+ in the same BB but we can recover if there's a domination
+ relationship between them.  */
+  else if (dominated_by_p (CDI_DOMINATORS,
+  gimple_bb (stmt1), gimple_bb (stmt2)))
 return stmt1_info;
-  else
+  else if (dominated_by_p (CDI_DOMINATORS,
+  gimple_bb (stmt2), gimple_bb (stmt1)))
 return stmt2_info;
+  gcc_unreachable ();
 }
 
 /* If STMT_INFO has been replaced by a pattern statement, return the


[gcc r15-9786] tree-optimization/120341 - stores into STRING_CSTs can trap

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:09884fa0f90da67915245622254cdfb947b87d37

commit r15-9786-g09884fa0f90da67915245622254cdfb947b87d37
Author: Richard Biener 
Date:   Fri May 30 13:47:55 2025 +0200

tree-optimization/120341 - stores into STRING_CSTs can trap

The following fixes conditional store elimination and store motion
so they consider stores to STRING_CSTs as trapping.

PR tree-optimization/120341
* tree-ssa-loop-im.cc (can_sm_ref_p): STRING_CSTs are readonly.
* tree-ssa-phiopt.cc (cond_store_replacement): Likewise.

* gcc.dg/torture/pr120341-1.c: New testcase.
* gcc.dg/torture/pr120341-2.c: Likewise.

(cherry picked from commit 02c58bc4b0885f5b6f50033da35768ebe6c4a030)

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr120341-1.c | 11 +++
 gcc/testsuite/gcc.dg/torture/pr120341-2.c | 13 +
 gcc/tree-ssa-loop-im.cc   |  3 ++-
 gcc/tree-ssa-phiopt.cc|  5 +++--
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr120341-1.c 
b/gcc/testsuite/gcc.dg/torture/pr120341-1.c
new file mode 100644
index ..e23185b62b07
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr120341-1.c
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fallow-store-data-races" } */
+
+char a, *b;
+int main()
+{
+  b = "0";
+  if (a)
+b[0]++;
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr120341-2.c 
b/gcc/testsuite/gcc.dg/torture/pr120341-2.c
new file mode 100644
index ..7bcc96f63ddc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr120341-2.c
@@ -0,0 +1,13 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fallow-store-data-races" } */
+
+char a, *b;
+int main()
+{
+  while (a)
+{
+  b = "0";
+  b[0]++;
+}
+  return 0;
+}
diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc
index 225964c62156..71a46f7e03f9 100644
--- a/gcc/tree-ssa-loop-im.cc
+++ b/gcc/tree-ssa-loop-im.cc
@@ -3293,7 +3293,8 @@ can_sm_ref_p (class loop *loop, im_mem_ref *ref)
  explicitly.  */
   base = get_base_address (ref->mem.ref);
   if ((tree_could_trap_p (ref->mem.ref)
-   || (DECL_P (base) && TREE_READONLY (base)))
+   || (DECL_P (base) && TREE_READONLY (base))
+   || TREE_CODE (base) == STRING_CST)
   /* ???  We can at least use false here, allowing loads?  We
 are forcing conditional stores if the ref is not always
 stored to later anyway.  So this would only guard
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 7f3390be31e5..aaebae6b38c0 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3565,8 +3565,9 @@ cond_store_replacement (basic_block middle_bb, 
basic_block join_bb,
  /* tree_could_trap_p is a predicate for rvalues, so check
 for readonly memory explicitly.  */
  || ((base = get_base_address (lhs))
- && DECL_P (base)
- && TREE_READONLY (base)))
+ && ((DECL_P (base)
+  && TREE_READONLY (base))
+ || TREE_CODE (base) == STRING_CST)))
return false;
 }


[gcc r13-9745] libstdc++: fix a dangling reference crash in ranges::is_permutation [PR118160]

2025-06-06 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:63be00fe4cad2552edcda863087adcce0b2aa236

commit r13-9745-g63be00fe4cad2552edcda863087adcce0b2aa236
Author: Giuseppe D'Angelo 
Date:   Thu Feb 6 14:24:17 2025 +

libstdc++: fix a dangling reference crash in ranges::is_permutation 
[PR118160]

The code was caching the result of `invoke(proj, *it)` in a local
`auto &&` variable. The problem is that this may create dangling
references, for instance in case `proj` is `std::identity` (the common
case) and `*it` produces a prvalue: lifetime extension does not
apply here due to the expressions involved.

Instead, store (and lifetime-extend) the result of `*it` in a separate
variable, then project that variable. While at it, also forward the
result of the projection to the predicate, so that the predicate can
act on the proper value category.

libstdc++-v3/ChangeLog:

PR libstdc++/118160
PR libstdc++/100249
* include/bits/ranges_algo.h (__is_permutation_fn): Avoid a
dangling reference by storing the result of the iterator
dereference and the result of the projection in two distinct
variables, in order to lifetime-extend each one.
Forward the projected value to the predicate.
* testsuite/25_algorithms/is_permutation/constrained.cc: Add a
test with a range returning prvalues. Test it in a constexpr
context, in order to rely on the compiler to catch UB.

Signed-off-by: Giuseppe D'Angelo 
(cherry picked from commit 2a2bd96d0d2109384a0eedde843ba811d2e18738)

Diff:
---
 libstdc++-v3/include/bits/ranges_algo.h |  7 +--
 .../testsuite/25_algorithms/is_permutation/constrained.cc   | 13 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_algo.h 
b/libstdc++-v3/include/bits/ranges_algo.h
index 48efe9f81655..4060a507d6fe 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -561,9 +561,12 @@ namespace ranges
 
for (auto __scan = __first1; __scan != __last1; ++__scan)
  {
-   auto&& __proj_scan = std::__invoke(__proj1, *__scan);
+   auto&& __scan_deref = *__scan;
+   auto&& __proj_scan =
+ std::__invoke(__proj1, 
std::forward(__scan_deref));
auto __comp_scan = [&]  (_Tp&& __arg) -> bool {
- return std::__invoke(__pred, __proj_scan,
+ return std::__invoke(__pred,
+  
std::forward(__proj_scan),
   std::forward<_Tp>(__arg));
};
if (__scan != ranges::find_if(__first1, __scan,
diff --git a/libstdc++-v3/testsuite/25_algorithms/is_permutation/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/is_permutation/constrained.cc
index e503247d44af..5ffe3ce3da33 100644
--- a/libstdc++-v3/testsuite/25_algorithms/is_permutation/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/is_permutation/constrained.cc
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -77,10 +78,22 @@ test03()
   while (std::next_permutation(std::begin(cx), std::end(cx)));
 }
 
+constexpr
+bool
+test04() // PR118160, do not create dangling references
+{
+  int x[] = { 4, 3, 2, 1 };
+  auto y = std::views::iota(1, 5);
+  return ranges::is_permutation(x, y) && ranges::is_permutation(y, x);
+}
+
+static_assert(test04());
+
 int
 main()
 {
   test01();
   test02();
   test03();
+  VERIFY( test04() );
 }


[gcc r16-1209] ada: Move standard subtype declarations generation

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:903c0128c6442446df37038341747eacf02a64dc

commit r16-1209-g903c0128c6442446df37038341747eacf02a64dc
Author: Ronan Desplanques 
Date:   Wed Feb 12 10:37:30 2025 +0100

ada: Move standard subtype declarations generation

Before this patch, the subtype declarations for Standard.Natural and
Standard.Positive were created before the entity for Standard.Integer
was complete. In preparation of a future change that will make it
impossible to call Etype on an incomplete node, this patch delays the
creation of these subtype declarations. It doesn't affect the behavior
of the compiler.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Delay declaration generation for
Natural and Positive.

Diff:
---
 gcc/ada/cstand.adb | 35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/cstand.adb b/gcc/ada/cstand.adb
index 41b0fec157fc..14c7496fa619 100644
--- a/gcc/ada/cstand.adb
+++ b/gcc/ada/cstand.adb
@@ -612,25 +612,14 @@ package body CStand is
   Set_Is_Pure (Standard_Standard);
   Set_Is_Compilation_Unit (Standard_Standard);
 
-  --  Create type/subtype declaration nodes for standard types
+  --  Create type declaration nodes for standard types
 
   for S in S_Types loop
-
- --  Subtype declaration case
-
- if S = S_Natural or else S = S_Positive then
-Decl := New_Node (N_Subtype_Declaration, Stloc);
-Set_Subtype_Indication (Decl,
-  New_Occurrence_Of (Standard_Integer, Stloc));
-
- --  Full type declaration case
-
- else
+ if S not in S_Natural | S_Positive then
 Decl := New_Node (N_Full_Type_Declaration, Stloc);
+Set_Defining_Identifier (Decl, Standard_Entity (S));
+Append (Decl, Decl_S);
  end if;
-
- Set_Defining_Identifier (Decl, Standard_Entity (S));
- Append (Decl, Decl_S);
   end loop;
 
   Create_Back_End_Float_Types;
@@ -1021,6 +1010,14 @@ package body CStand is
 Hb  => Intval (High_Bound (Scalar_Range (Standard_Integer;
   Set_Is_Constrained (Standard_Natural);
 
+  Append_To
+(Decl_S,
+ Make_Subtype_Declaration
+   (Stloc,
+Standard_Natural,
+Subtype_Indication =>
+  New_Occurrence_Of (Standard_Integer, Stloc)));
+
   --  Setup entity for Positive
 
   Mutate_Ekind (Standard_Positive, E_Signed_Integer_Subtype);
@@ -1038,6 +1035,14 @@ package body CStand is
  Hb  => Intval (High_Bound (Scalar_Range (Standard_Integer;
   Set_Is_Constrained   (Standard_Positive);
 
+  Append_To
+(Decl_S,
+ Make_Subtype_Declaration
+   (Stloc,
+Standard_Positive,
+Subtype_Indication =>
+  New_Occurrence_Of (Standard_Integer, Stloc)));
+
   --  Create declaration for package ASCII
 
   Decl := New_Node (N_Package_Declaration, Stloc);


[gcc r16-1213] ada: Remove Size_Check_Code field from entities

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:3d8a56ced13c48f8ee156b1a6af6ba078401429d

commit r16-1213-g3d8a56ced13c48f8ee156b1a6af6ba078401429d
Author: Eric Botcazou 
Date:   Thu Feb 13 12:07:37 2025 +0100

ada: Remove Size_Check_Code field from entities

It has been unused for a very long time.

gcc/ada/ChangeLog:

* einfo.ads (Size_Check_Code): Delete.
* gen_il-fields.ads (Opt_Field_Enum): Remove Size_Check_Code.
* gen_il-gen-gen_entities.adb (Constant_Or_Variable_Kind): Likewise.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Remove call
to Kill_Size_Check_Code.
* sem_prag.adb (Analyze_Pragma): Likewise.
* sem_util.ads (Kill_Size_Check_Code): Delete.
* sem_util.adb (Kill_Size_Check_Code): Likewise.

Diff:
---
 gcc/ada/einfo.ads   |  7 ---
 gcc/ada/gen_il-fields.ads   |  1 -
 gcc/ada/gen_il-gen-gen_entities.adb |  1 -
 gcc/ada/sem_ch13.adb|  5 -
 gcc/ada/sem_prag.adb|  3 ---
 gcc/ada/sem_util.adb| 14 --
 gcc/ada/sem_util.ads|  6 --
 7 files changed, 37 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 1fce2f98b8f9..7a7765d1272d 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -4388,11 +4388,6 @@ package Einfo is
 --   set, in which case this is the entity for the associated instance of
 --   System.Shared_Storage.Shared_Var_Procs. See Exp_Smem for full details.
 
---Size_Check_Code
---   Defined in constants and variables. Normally Empty. Set if code is
---   generated to check the size of the object. This field is used to
---   suppress this code if a subsequent address clause is encountered.
-
 --Size_Clause (synthesized)
 --   Applies to all entities. If a size or value size clause is present in
 --   the rep item chain for an entity then that attribute definition clause
@@ -5316,7 +5311,6 @@ package Einfo is
--Actual_Subtype
--Renamed_Object
--Renamed_Entity $$$
-   --Size_Check_Code   (constants only)
--Prival_Link   (privals only)
--Interface_Name(constants only)
--Related_Type  (constants only)
@@ -6202,7 +6196,6 @@ package Einfo is
--Renamed_Object
--Renamed_Entity $$$
--Discriminal_Link $$$
-   --Size_Check_Code
--Prival_Link
--Interface_Name
--Shared_Var_Procs_Instance
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index fe6d3387cfa9..f957f7f64327 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -893,7 +893,6 @@ package Gen_IL.Fields is
   Scope_Depth_Value,
   Sec_Stack_Needed_For_Return,
   Shared_Var_Procs_Instance,
-  Size_Check_Code,
   Size_Depends_On_Discriminant,
   Size_Known_At_Compile_Time,
   Small_Value,
diff --git a/gcc/ada/gen_il-gen-gen_entities.adb 
b/gcc/ada/gen_il-gen-gen_entities.adb
index 530af9085303..85ab62a0af73 100644
--- a/gcc/ada/gen_il-gen-gen_entities.adb
+++ b/gcc/ada/gen_il-gen-gen_entities.adb
@@ -357,7 +357,6 @@ begin -- Gen_IL.Gen.Gen_Entities
 Sm (Prival_Link, Node_Id),
 Sm (Related_Type, Node_Id),
 Sm (Return_Statement, Node_Id),
-Sm (Size_Check_Code, Node_Id),
 Sm (SPARK_Pragma, Node_Id),
 Sm (SPARK_Pragma_Inherited, Flag)));
 
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 69e18b049b99..de5716e6fd08 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -6278,11 +6278,6 @@ package body Sem_Ch13 is
   then
  Set_Check_Address_Alignment (N);
   end if;
-
-  --  Kill the size check code, since we are not allocating
-  --  the variable, it is somewhere else.
-
-  Kill_Size_Check_Code (U_Ent);
end;
 
 --  Not a valid entity for an address clause
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index fafd27454d9e..b37a9ad06a54 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -10029,7 +10029,6 @@ package body Sem_Prag is
 end if;
 
 Def_Id := Entity (Def_Id);
-Kill_Size_Check_Code (Def_Id);
 if Ekind (Def_Id) /= E_Constant then
Note_Possible_Modification
  (Get_Pragma_Arg (Arg1), Sure => False);
@@ -10042,7 +10041,6 @@ package body Sem_Prag is
 --  purposes of legality checks and removal of ignored Ghost code.
 
 Mark_Ghost_Pragma (N, Def_Id);
-Kill_Size_Check_Code (Def_Id);
 if Ekind (Def_Id) /= E_Constant then
Note_Possible_Modification
  (Get_Pragma_Arg (Arg2), Sure => False);
@@ -19946,7 +19944,6 @@ package body Sem_Prag is
 --  o

[gcc r16-1207] ada: Fix internal error on allocator involving interface type

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:d575c1bc78f0a3b094cdf41542b8db5c7e364e08

commit r16-1207-gd575c1bc78f0a3b094cdf41542b8db5c7e364e08
Author: Eric Botcazou 
Date:   Tue Feb 11 12:47:36 2025 +0100

ada: Fix internal error on allocator involving interface type

The problem is that an itype duplicated through Duplicate_Subexpr_No_Checks
ends up in a different scope than its source.  It is fixed by adding a new
formal parameter New_Scope to the function and forwarding it in the call to
the New_Copy_Tree function.

gcc/ada/ChangeLog:

* exp_aggr.adb (Expand_Record_Aggregate): Use the named form for the
second actual parameter in the call to Duplicate_Subexpr.
* exp_attr.adb (Expand_Size_Attribute): Likewise.
* exp_ch5.adb (Expand_Assign_Array): Likewise.
(Expand_Assign_Array_Bitfield): Likewise.
(Expand_Assign_Array_Bitfield_Fast): Likewise.
* exp_util.ads (Duplicate_Subexpr): Add New_Scope formal parameter.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Pass Proc_Id as the
actual for New_Scope in the calls to Duplicate_Subexpr_No_Checks.
(Duplicate_Subexpr): Add New_Scope formal parameter and forward it
in the call to New_Copy_Tree.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.

Diff:
---
 gcc/ada/exp_aggr.adb |  3 ++-
 gcc/ada/exp_attr.adb |  4 ++--
 gcc/ada/exp_ch5.adb  | 24 +---
 gcc/ada/exp_util.adb | 35 ++-
 gcc/ada/exp_util.ads | 18 --
 5 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index f2e7ad76e98f..8f1869cc7091 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -8077,7 +8077,8 @@ package body Exp_Aggr is
Make_Selected_Component (Loc,
  Prefix=>
Unchecked_Convert_To (Typ,
- Duplicate_Subexpr (Parent_Expr, True)),
+ Duplicate_Subexpr
+   (Parent_Expr, Name_Req => True)),
  Selector_Name => New_Occurrence_Of (Comp, Loc));
 
  Append_To (Comps,
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 4e0052e9ee41..455cc226bbfb 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -8602,10 +8602,10 @@ package body Exp_Attr is
 Rewrite (N,
   Make_Op_Multiply (Loc,
 Make_Attribute_Reference (Loc,
-  Prefix => Duplicate_Subexpr (Pref, True),
+  Prefix => Duplicate_Subexpr (Pref, Name_Req => True),
   Attribute_Name => Name_Length),
 Make_Attribute_Reference (Loc,
-  Prefix => Duplicate_Subexpr (Pref, True),
+  Prefix => Duplicate_Subexpr (Pref, Name_Req => True),
   Attribute_Name => Name_Component_Size)));
 Analyze_And_Resolve (N, Typ);
  end if;
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 06616eaf87d3..3d8a542c24e0 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -1039,7 +1039,8 @@ package body Exp_Ch5 is
  Prefix =>
Make_Indexed_Component (Loc,
  Prefix =>
-   Duplicate_Subexpr_Move_Checks (Larray, True),
+   Duplicate_Subexpr_Move_Checks
+ (Larray, Name_Req => True),
  Expressions => New_List (
Make_Attribute_Reference (Loc,
  Prefix =>
@@ -1054,7 +1055,8 @@ package body Exp_Ch5 is
  Prefix =>
Make_Indexed_Component (Loc,
  Prefix =>
-   Duplicate_Subexpr_Move_Checks (Rarray, True),
+   Duplicate_Subexpr_Move_Checks
+ (Rarray, Name_Req => True),
  Expressions => New_List (
Make_Attribute_Reference (Loc,
  Prefix =>
@@ -1396,7 +1398,7 @@ package body Exp_Ch5 is
   Prefix =>
 Make_Indexed_Component (Loc,
   Prefix =>
-Duplicate_Subexpr (Larray, True),
+Duplicate_Subexpr (Larray, Name_Req => True),
   Expressions => New_List (New_Copy_Tree (Left_Lo))),
   Attribute_Name => Name_Address);
 
@@ -1405,7 +1407,7 @@ package body Exp_Ch5 is
   Prefix =>
 Make_Indexed_Component (Loc,
  

[gcc r16-1208] ada: Remove useless calls

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:d5b0410adf21e24177150ac3a209770f46299494

commit r16-1208-gd5b0410adf21e24177150ac3a209770f46299494
Author: Ronan Desplanques 
Date:   Wed Feb 12 10:34:06 2025 +0100

ada: Remove useless calls

The subprogram calls this patch removes were useless because they were
already made in New_Standard_Entity.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Remove useless calls.

Diff:
---
 gcc/ada/cstand.adb | 2 --
 1 file changed, 2 deletions(-)

diff --git a/gcc/ada/cstand.adb b/gcc/ada/cstand.adb
index 5ba88b9ae1c9..41b0fec157fc 100644
--- a/gcc/ada/cstand.adb
+++ b/gcc/ada/cstand.adb
@@ -629,8 +629,6 @@ package body CStand is
 Decl := New_Node (N_Full_Type_Declaration, Stloc);
  end if;
 
- Set_Is_Frozen (Standard_Entity (S));
- Set_Is_Public (Standard_Entity (S));
  Set_Defining_Identifier (Decl, Standard_Entity (S));
  Append (Decl, Decl_S);
   end loop;


[gcc r16-1214] ada: Remove dead code

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:fd87cba805163b6bf9936fbc22deb7995e2dc2c0

commit r16-1214-gfd87cba805163b6bf9936fbc22deb7995e2dc2c0
Author: Ronan Desplanques 
Date:   Thu Feb 13 14:19:58 2025 +0100

ada: Remove dead code

The code this patch removes is never executed on any of the available
test suites. The patch that introduced it mentions that it fixes a test
in particular, but that test passes anyway today.

gcc/ada/ChangeLog:

* sem_ch8.adb (Premature_Usage): Remove dead code.

Diff:
---
 gcc/ada/sem_ch8.adb | 20 
 1 file changed, 20 deletions(-)

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 65d30967ae02..fe9328833df4 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -9922,28 +9922,8 @@ package body Sem_Ch8 is
 
procedure Premature_Usage (N : Node_Id) is
   Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
-  E: Entity_Id := Entity (N);
 
begin
-  --  Within an instance, the analysis of the actual for a formal object
-  --  does not see the name of the object itself. This is significant only
-  --  if the object is an aggregate, where its analysis does not do any
-  --  name resolution on component associations. (see 4717-008). In such a
-  --  case, look for the visible homonym on the chain.
-
-  if In_Instance and then Present (Homonym (E)) then
- E := Homonym (E);
- while Present (E) and then not In_Open_Scopes (Scope (E)) loop
-E := Homonym (E);
- end loop;
-
- if Present (E) then
-Set_Entity (N, E);
-Set_Etype (N, Etype (E));
-return;
- end if;
-  end if;
-
   case Kind is
  when N_Component_Declaration =>
 Error_Msg_N


[gcc r16-1211] ada: Improve large unconstrained-but-definite warning

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:537453af7c83432f5bde527f035f9dbb43921fd3

commit r16-1211-g537453af7c83432f5bde527f035f9dbb43921fd3
Author: Ronan Desplanques 
Date:   Wed Feb 12 19:09:18 2025 +0100

ada: Improve large unconstrained-but-definite warning

Before this patch, Check_Discriminant_Use called Is_Limited type on
entities before they were fully analyzed. That caused Is_Limited_Type
to incorrectly return False for records that are limited because they
have a limited component.

This patch pushes back the emissions of the Check_Discriminant_Use
warning after analysis of record declarations. A new field to
E_Record_Type entity is added to take relevant discriminant uses into
account.

gcc/ada/ChangeLog:

* gen_il-fields.ads: New field.
* gen_il-gen-gen_entities.adb: New field.
* einfo.ads: Document new field.
* sem_res.adb (Check_Discriminant_Use): Record relevant uses in new
field. Move warning emission to...
* sem_ch3.adb (Analyze_Full_Type_Declaration): ... Here.

Diff:
---
 gcc/ada/einfo.ads   |  5 +
 gcc/ada/gen_il-fields.ads   |  1 +
 gcc/ada/gen_il-gen-gen_entities.adb |  3 ++-
 gcc/ada/sem_ch3.adb |  7 +++
 gcc/ada/sem_res.adb | 16 +++-
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index f154e7f0d763..1fce2f98b8f9 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2967,6 +2967,11 @@ package Einfo is
 --   fully constructed, since it simply indicates the last state.
 --   Thus this flag has no meaning to the backend.
 
+--Is_Large_Unconstrained_Definite
+--   Defined in record types. Used to detect types with default
+--   discriminant values that have exaggerated sizes and emit warnings
+--   about them.
+
 --Is_Limited_Composite
 --   Defined in all entities. Set for composite types that have a limited
 --   component. Used to enforce the rule that operations on the composite
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index c293e0fa63fb..fe6d3387cfa9 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -744,6 +744,7 @@ package Gen_IL.Fields is
   Is_Known_Non_Null,
   Is_Known_Null,
   Is_Known_Valid,
+  Is_Large_Unconstrained_Definite,
   Is_Limited_Composite,
   Is_Limited_Interface,
   Is_Limited_Record,
diff --git a/gcc/ada/gen_il-gen-gen_entities.adb 
b/gcc/ada/gen_il-gen-gen_entities.adb
index 37ddd851d7c3..530af9085303 100644
--- a/gcc/ada/gen_il-gen-gen_entities.adb
+++ b/gcc/ada/gen_il-gen-gen_entities.adb
@@ -781,7 +781,8 @@ begin -- Gen_IL.Gen.Gen_Entities
 Sm (No_Reordering, Flag, Impl_Base_Type_Only),
 Sm (Parent_Subtype, Node_Id, Base_Type_Only),
 Sm (Reverse_Bit_Order, Flag, Base_Type_Only),
-Sm (Underlying_Record_View, Node_Id)));
+Sm (Underlying_Record_View, Node_Id),
+Sm (Is_Large_Unconstrained_Definite, Flag, Impl_Base_Type_Only)));
 
Cc (E_Record_Subtype, Aggregate_Kind,
--  A record subtype, created by a record subtype declaration
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 47e7ede83e19..80359e5b68ee 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -3553,6 +3553,13 @@ package body Sem_Ch3 is
 end;
  end if;
   end if;
+
+  if Ekind (T) = E_Record_Type
+and then Is_Large_Unconstrained_Definite (T)
+and then not Is_Limited_Type (T)
+  then
+ Error_Msg_N ("??creation of & object may raise Storage_Error!", T);
+  end if;
end Analyze_Full_Type_Declaration;
 
--
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 865f967a5b93..1ae72fab6629 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -757,14 +757,6 @@ package body Sem_Res is
   goto No_Danger;
end if;
 
-   --  If the enclosing type is limited, we allocate only the
-   --  default value, not the maximum, and there is no need for
-   --  a warning.
-
-   if Is_Limited_Type (Scope (Disc)) then
-  goto No_Danger;
-   end if;
-
--  Check that it is the high bound
 
if N /= High_Bound (PN)
@@ -811,11 +803,9 @@ package body Sem_Res is
   goto No_Danger;
end if;
 
-   --  Warn about the danger
-
-   Error_Msg_N
- ("??creation of & object may raise Storage_Error!",
-  Scope (Disc));
+   if Ekind (Scope (Disc)) = E_Record_Type then
+  Set_Is_Large_Unconstrained_Definite (Scope (Disc));
+   end if;
 
<>
   null;


[gcc r16-1219] ada: Implement use implies with experimental extension

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:994705cbe8658dc939160504e086409bd7a00a10

commit r16-1219-g994705cbe8658dc939160504e086409bd7a00a10
Author: squirek 
Date:   Tue Feb 18 10:54:01 2025 +

ada: Implement use implies with experimental extension

The patch implements the experimental feature to allow use package
clauses within the context area to imply with.

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Add documentation.
* gnat_rm.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/gnat_language_extensions.rst |  16 +++
 gcc/ada/gnat_rm.texi | 133 +--
 2 files changed, 92 insertions(+), 57 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst 
b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
index ee2df668eb1d..1713f56be3b8 100644
--- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
+++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
@@ -657,6 +657,22 @@ An exception message can also be added:
 when Imported_C_Func /= 0;
end;
 
+Implicit With
+-
+
+This feature allows a standalone ``use`` clause in the context clause of a
+compilation unit to imply an implicit ``with`` of the same library unit where
+an equivalent ``with`` clause would be allowed.
+
+.. code-block:: ada
+
+   use Ada.Text_IO;
+   procedure Main is
+   begin
+  Put_Line ("Hello");
+   end;
+
+
 Storage Model
 -
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 5719d0d3e62d..5ec090f2669a 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -916,6 +916,7 @@ Deep delta Aggregates
 Experimental Language Extensions
 
 * Conditional when constructs:: 
+* Implicit With:: 
 * Storage Model:: 
 * Attribute Super:: 
 * Simpler Accessibility Model:: 
@@ -29896,6 +29897,7 @@ Features activated via @code{-gnatX0} or
 
 @menu
 * Conditional when constructs:: 
+* Implicit With:: 
 * Storage Model:: 
 * Attribute Super:: 
 * Simpler Accessibility Model:: 
@@ -29909,7 +29911,7 @@ Features activated via @code{-gnatX0} or
 
 @end menu
 
-@node Conditional when constructs,Storage Model,,Experimental Language 
Extensions
+@node Conditional when constructs,Implicit With,,Experimental Language 
Extensions
 @anchor{gnat_rm/gnat_language_extensions 
conditional-when-constructs}@anchor{455}
 @subsection Conditional when constructs
 
@@ -29978,8 +29980,25 @@ begin
 end;
 @end example
 
-@node Storage Model,Attribute Super,Conditional when constructs,Experimental 
Language Extensions
-@anchor{gnat_rm/gnat_language_extensions storage-model}@anchor{456}
+@node Implicit With,Storage Model,Conditional when constructs,Experimental 
Language Extensions
+@anchor{gnat_rm/gnat_language_extensions implicit-with}@anchor{456}
+@subsection Implicit With
+
+
+This feature allows a standalone @code{use} clause in the context clause of a
+compilation unit to imply an implicit @code{with} of the same library unit 
where
+an equivalent @code{with} clause would be allowed.
+
+@example
+use Ada.Text_IO;
+procedure Main is
+begin
+   Put_Line ("Hello");
+end;
+@end example
+
+@node Storage Model,Attribute Super,Implicit With,Experimental Language 
Extensions
+@anchor{gnat_rm/gnat_language_extensions storage-model}@anchor{457}
 @subsection Storage Model
 
 
@@ -29996,7 +30015,7 @@ memory models, in particular to support interactions 
with GPU.
 @end menu
 
 @node Aspect Storage_Model_Type,Aspect Designated_Storage_Model,,Storage Model
-@anchor{gnat_rm/gnat_language_extensions aspect-storage-model-type}@anchor{457}
+@anchor{gnat_rm/gnat_language_extensions aspect-storage-model-type}@anchor{458}
 @subsubsection Aspect Storage_Model_Type
 
 
@@ -30130,7 +30149,7 @@ end CUDA_Memory;
 @end example
 
 @node Aspect Designated_Storage_Model,Legacy Storage Pools,Aspect 
Storage_Model_Type,Storage Model
-@anchor{gnat_rm/gnat_language_extensions 
aspect-designated-storage-model}@anchor{458}
+@anchor{gnat_rm/gnat_language_extensions 
aspect-designated-storage-model}@anchor{459}
 @subsubsection Aspect Designated_Storage_Model
 
 
@@ -30208,7 +30227,7 @@ begin
 @end example
 
 @node Legacy Storage Pools,,Aspect Designated_Storage_Model,Storage Model
-@anchor{gnat_rm/gnat_language_extensions legacy-storage-pools}@anchor{459}
+@anchor{gnat_rm/gnat_language_extensions legacy-storage-pools}@anchor{45a}
 @subsubsection Legacy Storage Pools
 
 
@@ -30259,7 +30278,7 @@ type Acc is access Integer_Array with Storage_Pool => 
My_Pool;
 can still be accepted as a shortcut for the new syntax.
 
 @node Attribute Super,Simpler Accessibility Model,Storage Model,Experimental 
Language Extensions
-@anchor{gnat_rm/gnat_language_extensions attribute-super}@anchor{45a}
+@anchor{gnat_rm/gnat_language_extensions attribute-super}@anchor{45b}
 @subsection Attribute Super
 
 
@@ -30294,7 +30313,7 @@ end;
 @end example
 
 @node Simpler Accessibility Model,Case pattern matching,Attribute 
Super,Experimental Language Extensions
-@anc

[gcc r16-1220] ada: Initial prototype of constructors

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:ac2d8941f51d1280e1bf88274b1b4cf0c56e653b

commit r16-1220-gac2d8941f51d1280e1bf88274b1b4cf0c56e653b
Author: squirek 
Date:   Thu Feb 20 13:12:58 2025 +

ada: Initial prototype of constructors

The patch implements the experimental constructors RFC. Currently a WIP.

gcc/ada/ChangeLog:

* aspects.ads: Add support for constructors.
* exp_aggr.adb: Likewise.
* exp_attr.adb: Likewise.
* exp_ch3.adb: Likewise.
* exp_ch4.adb: Likewise.
* exp_util.adb: Likewise.
* gen_il-fields.ads: Likewise.
* gen_il-gen-gen_entities.adb: Likewise.
* gen_il-gen-gen_nodes.adb: Likewise.
* par-ch4.adb: Likewise.
* sem_aggr.adb: Likewise.
* sem_attr.adb, sem_attr.ads: Likewise.
* sem_ch13.adb: Likewise.
* sem_ch3.adb: Likewise.
* sem_ch5.adb: Likewise.
* sem_ch6.adb: Likewise.
* sem_res.adb: Likewise.
* sem_util.adb, sem_util.ads: Likewise.
* snames.ads-tmpl: Likewise.

Diff:
---
 gcc/ada/aspects.ads |  10 ++
 gcc/ada/exp_aggr.adb|   9 +-
 gcc/ada/exp_attr.adb| 311 
 gcc/ada/exp_ch3.adb |  39 -
 gcc/ada/exp_ch4.adb |   9 ++
 gcc/ada/exp_util.adb|  11 +-
 gcc/ada/gen_il-fields.ads   |   4 +
 gcc/ada/gen_il-gen-gen_entities.adb |   3 +
 gcc/ada/gen_il-gen-gen_nodes.adb|   1 +
 gcc/ada/par-ch4.adb |  42 -
 gcc/ada/sem_aggr.adb|  24 +++
 gcc/ada/sem_attr.adb| 134 +++-
 gcc/ada/sem_attr.ads|   6 +
 gcc/ada/sem_ch13.adb|  98 +++-
 gcc/ada/sem_ch3.adb |   8 +
 gcc/ada/sem_ch5.adb |   6 +-
 gcc/ada/sem_ch6.adb |  83 ++
 gcc/ada/sem_res.adb |   2 +
 gcc/ada/sem_util.adb|  44 +
 gcc/ada/sem_util.ads|   7 +
 gcc/ada/snames.ads-tmpl |   3 +
 21 files changed, 805 insertions(+), 49 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
index 70ea12023abb..9d44ed4dec34 100644
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -81,6 +81,7 @@ package Aspects is
   Aspect_Bit_Order,
   Aspect_Component_Size,
   Aspect_Constant_Indexing,
+  Aspect_Constructor,   -- GNAT
   Aspect_Contract_Cases,-- GNAT
   Aspect_Convention,
   Aspect_CPU,
@@ -106,6 +107,7 @@ package Aspects is
   Aspect_GNAT_Annotate, -- GNAT
   Aspect_Implicit_Dereference,
   Aspect_Initial_Condition, -- GNAT
+  Aspect_Initialize,-- GNAT
   Aspect_Initializes,   -- GNAT
   Aspect_Input,
   Aspect_Integer_Literal,
@@ -428,6 +430,7 @@ package Aspects is
   Aspect_Bit_Order  => Expression,
   Aspect_Component_Size => Expression,
   Aspect_Constant_Indexing  => Name,
+  Aspect_Constructor=> Name,
   Aspect_Contract_Cases => Expression,
   Aspect_Convention => Name,
   Aspect_CPU=> Expression,
@@ -453,6 +456,7 @@ package Aspects is
   Aspect_GNAT_Annotate  => Expression,
   Aspect_Implicit_Dereference   => Name,
   Aspect_Initial_Condition  => Expression,
+  Aspect_Initialize => Expression,
   Aspect_Initializes=> Expression,
   Aspect_Input  => Name,
   Aspect_Integer_Literal=> Name,
@@ -529,6 +533,7 @@ package Aspects is
   Aspect_Component_Size   => True,
   Aspect_Constant_Indexing=> False,
   Aspect_Contract_Cases   => False,
+  Aspect_Constructor  => False,
   Aspect_Convention   => True,
   Aspect_CPU  => False,
   Aspect_Default_Component_Value  => True,
@@ -556,6 +561,7 @@ package Aspects is
   Aspect_GNAT_Annotate=> False,
   Aspect_Implicit_Dereference => False,
   Aspect_Initial_Condition=> False,
+  Aspect_Initialize   => False,
   Aspect_Initializes  => False,
   Aspect_Input=> False,
   Aspect_Integer_Literal  => False,
@@ -698,6 +704,7 @@ package Aspects is
   Aspect_Constant_After_Elaboration   => Name_Constant_After_Elaboration,
   Aspect_Constant_Indexing=> Name_Constant_Indexing,
   Aspect_Contract_Cases   => Name_Contract_Cases,
+  Aspect_Constructor  => Name_Constructor,
   Aspect_Convention 

[gcc r16-1218] ada: Tweak definition of Modulus field of entities

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:df310aab0e1f56da10382a68ddd46d3fa0aa89a4

commit r16-1218-gdf310aab0e1f56da10382a68ddd46d3fa0aa89a4
Author: Eric Botcazou 
Date:   Tue Feb 18 11:24:15 2025 +0100

ada: Tweak definition of Modulus field of entities

The compiler may build modular integer subtypes whose base type is private
in the context of instantiations, but we want to be able to get the Modulus.

gcc/ada/ChangeLog:

* einfo.ads (Modulus): Change to implementation base type only.
* gen_il-gen-gen_entities.adb (Modular_Integer_Kind): Change type
of Modulus field to Impl_Base_Type_Only.

Diff:
---
 gcc/ada/einfo.ads   | 2 +-
 gcc/ada/gen_il-gen-gen_entities.adb | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index c07de681045a..05ce8beca764 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -3626,7 +3626,7 @@ package Einfo is
 --   subprogram or the formal's Extra_Accessibility - whichever one is
 --   lesser. The Minimum_Accessibility field then points to this object.
 
---Modulus [base type only]
+--Modulus [implementation base type only]
 --   Defined in modular types. Contains the modulus. For the binary case,
 --   this will be a power of 2, but if Non_Binary_Modulus is set, then it
 --   will not be a power of 2.
diff --git a/gcc/ada/gen_il-gen-gen_entities.adb 
b/gcc/ada/gen_il-gen-gen_entities.adb
index 4548789383e2..2dc255c78c8a 100644
--- a/gcc/ada/gen_il-gen-gen_entities.adb
+++ b/gcc/ada/gen_il-gen-gen_entities.adb
@@ -572,7 +572,7 @@ begin -- Gen_IL.Gen.Gen_Entities
--  created for the base type, and this is the first named subtype).
 
Ab (Modular_Integer_Kind, Integer_Kind,
-   (Sm (Modulus, Uint, Base_Type_Only),
+   (Sm (Modulus, Uint, Impl_Base_Type_Only),
 Sm (Original_Array_Type, Node_Id)));
 
Cc (E_Modular_Integer_Type, Modular_Integer_Kind);


[gcc r16-1217] ada: Restore Original_Access_Type field in E_Access_Subprogram_Type entities

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:573b0389e6fe46a328964c4cc705dfff63dcb611

commit r16-1217-g573b0389e6fe46a328964c4cc705dfff63dcb611
Author: Eric Botcazou 
Date:   Mon Feb 17 10:29:48 2025 +0100

ada: Restore Original_Access_Type field in E_Access_Subprogram_Type entities

It is used by CodePeer to recognize the special access pattern.

gcc/ada/ChangeLog:

* einfo.ads (Original_Access_Type): Restore.
* gen_il-fields.ads (Opt_Field_Enum): Restore Original_Access_Type.
* gen_il-gen-gen_entities.adb: Adjust accordingly.
* exp_ch9.adb (Expand_Access_Protected_Subprogram_Type): Restore the
call to Set_Original_Access_Type.

Diff:
---
 gcc/ada/einfo.ads   | 7 +++
 gcc/ada/exp_ch9.adb | 6 ++
 gcc/ada/gen_il-fields.ads   | 1 +
 gcc/ada/gen_il-gen-gen_entities.adb | 3 ++-
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 152a8b296a0f..c07de681045a 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -3883,6 +3883,12 @@ package Einfo is
 --   Optimize_Alignment (Off) mode applies to the type/object, then neither
 --   of the flags Optimize_Alignment_Space/Optimize_Alignment_Time is set.
 
+--Original_Access_Type
+--   Defined in E_Access_Subprogram_Type entities. Set only if the access
+--   type was generated by the expander as part of processing an access-
+--   to-protected-subprogram type. Points to the access-to-protected-
+--   subprogram type. Read by CodePeer.
+
 --Original_Array_Type
 --   Defined in modular types and array types and subtypes. Set only if
 --   the Is_Packed_Array_Impl_Type flag is set, indicating that the type
@@ -5122,6 +5128,7 @@ package Einfo is
--  E_Access_Subprogram_Type
--Equivalent_Type   (remote types only)
--Directly_Designated_Type
+   --Original_Access_Type
--Needs_No_Actuals
--Can_Use_Internal_Rep
--Associated_Storage_Pool $$$
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index 39ad2b10846b..ff5668e08c4c 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -5746,6 +5746,12 @@ package body Exp_Ch9 is
 
   Insert_Before_And_Analyze (N, Decl1);
 
+  --  Associate the access to subprogram with its original access to
+  --  protected subprogram type. Needed by CodePeer to know that this
+  --  type corresponds with an access to protected subprogram type.
+
+  Set_Original_Access_Type (D_T2, T);
+
   --  Create Equivalent_Type, a record with two components for an access to
   --  object and an access to subprogram.
 
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index 0092a5728c66..f664449ed966 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -839,6 +839,7 @@ package Gen_IL.Fields is
   OK_To_Rename,
   Optimize_Alignment_Space,
   Optimize_Alignment_Time,
+  Original_Access_Type,
   Original_Array_Type,
   Original_Protected_Subprogram,
   Original_Record_Component,
diff --git a/gcc/ada/gen_il-gen-gen_entities.adb 
b/gcc/ada/gen_il-gen-gen_entities.adb
index 86e3f39f6d38..4548789383e2 100644
--- a/gcc/ada/gen_il-gen-gen_entities.adb
+++ b/gcc/ada/gen_il-gen-gen_entities.adb
@@ -677,7 +677,8 @@ begin -- Gen_IL.Gen.Gen_Entities
Cc (E_Access_Subprogram_Type, Access_Subprogram_Kind,
--  An access-to-subprogram type, created by an access-to-subprogram
--  declaration.
-   (Sm (Equivalent_Type, Node_Id)));
+   (Sm (Equivalent_Type, Node_Id),
+Sm (Original_Access_Type, Node_Id)));
 
Ab (Access_Protected_Kind, Access_Subprogram_Kind,
(Sm (Equivalent_Type, Node_Id)));


[gcc r16-1216] ada: Remove more unused fields from entities

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:64bb8c8b59f98ff0faa1b61f54ffbd18dd8304c5

commit r16-1216-g64bb8c8b59f98ff0faa1b61f54ffbd18dd8304c5
Author: Eric Botcazou 
Date:   Fri Feb 14 12:31:33 2025 +0100

ada: Remove more unused fields from entities

This removes 5 more unused fields from entities, as well as 1 flag.

gcc/ada/ChangeLog:

* einfo.ads (Default_Expr_Function): Delete.
(Dependent_Instances): Likewise.
(Handler_Records): Likewise.
(Needs_Activation_Record): Likewise.
(Original_Access_Type): Likewise.
(Register_Exception_Call): Likewise.
* sinfo.ads (Accept_Handler_Records): Likewise.
* gen_il-fields.ads (Opt_Field_Enum): Remove Accept_Handler_Records,
Default_Expr_Function, Dependent_Instances, Handler_Records,
Needs_Activation_Record, Original_Access_Type and
Register_Exception_Call.
* gen_il-gen-gen_entities.adb: Adjust accordingly.
* gen_il-gen-gen_nodes.adb: Likewise.
* exp_ch9.adb (Expand_Access_Protected_Subprogram_Type): Remove call
to Set_Original_Access_Type.
(Expand_N_Selective_Accept): Remove call to Set_Handler_Records.
* exp_ch11.adb (Expand_N_Exception_Declaration): Remove call to
Set_Register_Exception_Call.
* sem_ch3.adb (Access_Subprogram_Declaration): Remove call to
Set_Needs_Activation_Record.
* sem_ch12.adb (Instantiate_Package_Body): Remove call to
Set_Handler_Records.

Diff:
---
 gcc/ada/einfo.ads   | 47 -
 gcc/ada/exp_ch11.adb|  2 --
 gcc/ada/exp_ch9.adb | 14 ---
 gcc/ada/gen_il-fields.ads   |  7 --
 gcc/ada/gen_il-gen-gen_entities.adb | 13 +-
 gcc/ada/gen_il-gen-gen_nodes.adb|  3 +--
 gcc/ada/sem_ch12.adb|  4 
 gcc/ada/sem_ch3.adb |  8 ---
 gcc/ada/sinfo.ads   |  9 ---
 9 files changed, 2 insertions(+), 105 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 7a7765d1272d..152a8b296a0f 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -832,12 +832,6 @@ package Einfo is
 --   Default_Value aspect specification for the type, or inherited
 --   on derivation.
 
---Default_Expr_Function
---   Defined in parameters. It holds the entity of the parameterless
---   function that is built to evaluate the default expression if it is
---   more complex than a simple identifier or literal. For the latter
---   simple cases or if there is no default value, this field is Empty.
-
 --Default_Expressions_Processed
 --   A flag in subprograms (functions, operators, procedures) and in
 --   entries and entry families used to indicate that default expressions
@@ -864,12 +858,6 @@ package Einfo is
 --   that holds value of delta for the type, as given in the declaration
 --   or as inherited by a subtype or derived type.
 
---Dependent_Instances
---   Defined in packages that are instances. Holds list of instances
---   of inner generics. Used to place freeze nodes for those instances
---   after that of the current one, i.e. after the corresponding generic
---   bodies.
-
 --Depends_On_Private
 --   Defined in all type entities. Set if the type is private or if it
 --   depends on a private type.
@@ -1462,11 +1450,6 @@ package Einfo is
 --   associates generic parameters with the corresponding instances, in
 --   those cases where the instance is an entity.
 
---Handler_Records
---   Defined in subprogram and package entities. Points to a list of
---   identifiers referencing the handler record entities for the
---   corresponding unit.
-
 --Has_Aliased_Components [implementation base type only]
 --   Defined in array type entities. Indicates that the component type
 --   of the array is aliased. Should this also be set for records to
@@ -3663,11 +3646,6 @@ package Einfo is
 --   preelaborable initialization at freeze time (this has to be deferred
 --   to the freeze point because of the rule about overriding Initialize).
 
---Needs_Activation_Record
---   Defined on generated subprogram types. Indicates that a call through
---   a named or anonymous access to subprogram requires an activation
---   record when compiling with unnesting for C or LLVM.
-
 --Needs_Debug_Info
 --   Defined in all entities. Set if the entity requires normal debugging
 --   information to be generated. This is true of all entities that have
@@ -3905,12 +3883,6 @@ package Einfo is
 --   Optimize_Alignment (Off) mode applies to the type/object, then neither
 --   of the flags Optimize_Alignment_Space/Optimize_Alignment_Time is set.
 
---Original_Access_Type
---   Defined in E_Access_Subpr

[gcc r16-1212] ada: Allow IN OUT parameters for first parameter of traversal functions

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:8abecb35be8fd6790e9b7ec7c28cfee075d9c9e5

commit r16-1212-g8abecb35be8fd6790e9b7ec7c28cfee075d9c9e5
Author: Claire Dross 
Date:   Wed Feb 12 12:10:20 2025 +0100

ada: Allow IN OUT parameters for first parameter of traversal functions

In general, functions in SPARK cannot have parameters of mode IN OUT
unless they are annotated with the Side_Effects aspect. Borrowing
traversal functions are special functions which can return a part
of their first parameter as an access-to-variable type. This might not
be allowed in Ada if the parameter is a constant. Allow the first
parameter of borrowing traversal functions to have mode IN OUT.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_SPARK_Subprogram_Specification):
Allow the first parameter of functions whose return type is
an anonymous access-to-variable type to have mode IN OUT.

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

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index d4e6d1693263..dcbcc608f839 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -2275,6 +2275,23 @@ package body Sem_Ch6 is
   end if;
 
   Formal := First_Formal (Spec_Id);
+
+  --  The first parameter of a borrowing traversal function might be an IN
+  --  or an IN OUT parameter.
+
+  if Present (Formal)
+and then Ekind (Etype (Spec_Id)) = E_Anonymous_Access_Type
+and then not Is_Access_Constant (Etype (Spec_Id))
+  then
+ if Ekind (Formal) = E_Out_Parameter then
+Error_Msg_Code := GEC_Out_Parameter_In_Function;
+Error_Msg_N
+  ("first parameter of traversal function cannot have mode `OUT` "
+   & "in SPARK '[[]']", Formal);
+ end if;
+ Next_Formal (Formal);
+  end if;
+
   while Present (Formal) loop
  if Ekind (Spec_Id) in E_Function | E_Generic_Function
and then not Is_Function_With_Side_Effects (Spec_Id)


[gcc r16-1221] ada: Move Incomplete_View from node to entity field

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:a90094505584cae5d3c813bf955b194d60785e87

commit r16-1221-ga90094505584cae5d3c813bf955b194d60785e87
Author: Piotr Trojanek 
Date:   Wed Feb 19 16:32:43 2025 +0100

ada: Move Incomplete_View from node to entity field

The Incomplete_View property of a type was attached to its full type
declaration as a semantic field, but retrieving it from there required
low-level tree navigation and caused code duplication. In one case we
relied on internal class-wide type being attached to the corresponding
full type declaration, which is an undocumented assumption.

It seems better to attach this field to entities, just like we do with
Full_View and many other type properties. Ideally, this field should be
present just in type entities, but currently we set it before setting
the proper entity kind.

Behavior is unaffected. This is rather a code cleanup, originating from the
need to use Incomplete_View in GNATprove.

gcc/ada/ChangeLog:

* einfo.ads (Incomplete_View): Move from Sinfo; adapt wording.
* exp_ch3.adb (Build_Record_Init_Proc): Adapt retrieval of
Incomplete_View.
* gen_il-fields.ads (Opt_Field_Enum): Move Incomplete_View from node
to entity field.
* gen_il-gen-gen_entities.adb (Gen_Entities): Add field.
* gen_il-gen-gen_nodes.adb (Gen_Nodes): Remove field.
* sem_ch3.adb (Analyze_Full_Type_Declaration,
Check_Anonymous_Access_Component): Adapt setting of Incomplete_View.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Adapt retrieval of
Incomplete_View for class-wide types; no longer rely on class-wide
type being attached to non-classwide type declaration.
* sem_util.adb (Collect_Primitive_Operations): Adapt retrieval of
Incomplete_View.
* sinfo.ads (Incomplete_View): Move to Einfo.

Diff:
---
 gcc/ada/einfo.ads   | 5 +
 gcc/ada/exp_ch3.adb | 6 ++
 gcc/ada/gen_il-fields.ads   | 2 +-
 gcc/ada/gen_il-gen-gen_entities.adb | 1 +
 gcc/ada/gen_il-gen-gen_nodes.adb| 3 +--
 gcc/ada/sem_ch3.adb | 4 ++--
 gcc/ada/sem_ch6.adb | 6 ++
 gcc/ada/sem_util.adb| 6 ++
 gcc/ada/sinfo.ads   | 5 -
 9 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 05ce8beca764..545c15de24a2 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2245,6 +2245,11 @@ package Einfo is
 --   is relocated to the corresponding package body, which must have a
 --   corresponding nonlimited with_clause.
 
+--Incomplete_View
+--   Defined in all entities. Present in those that are completions of
+--   incomplete types. Denotes the corresponding incomplete view declared
+--   by the incomplete declaration.
+
 --Indirect_Call_Wrapper
 --   Defined on subprogram entities. Set if the subprogram has class-wide
 --   preconditions. Denotes the internal wrapper that checks preconditions
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index c11e74b9fd87..d884e755d66b 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2652,11 +2652,9 @@ package body Exp_Ch3 is
--  may have an incomplete type. In that case, it must also be
--  replaced by the formal of the Init_Proc.
 
-   if Nkind (Parent (Rec_Type)) = N_Full_Type_Declaration
- and then Present (Incomplete_View (Parent (Rec_Type)))
-   then
+   if Present (Incomplete_View (Rec_Type)) then
   Append_Elmt (
-N  => Incomplete_View (Parent (Rec_Type)),
+N  => Incomplete_View (Rec_Type),
 To => Map);
   Append_Elmt (
 N  => Defining_Identifier
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index 2780dc7acc14..9871035416d1 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -229,7 +229,6 @@ package Gen_IL.Fields is
   Import_Interface_Present,
   In_Present,
   Includes_Infinities,
-  Incomplete_View,
   Inherited_Discriminant,
   Instance_Spec,
   Intval,
@@ -658,6 +657,7 @@ package Gen_IL.Fields is
   Ignore_SPARK_Mode_Pragmas,
   Import_Pragma,
   Incomplete_Actuals,
+  Incomplete_View,
   Indirect_Call_Wrapper,
   In_Package_Body,
   In_Private_Part,
diff --git a/gcc/ada/gen_il-gen-gen_entities.adb 
b/gcc/ada/gen_il-gen-gen_entities.adb
index d653107a6996..bfa634f8a692 100644
--- a/gcc/ada/gen_il-gen-gen_entities.adb
+++ b/gcc/ada/gen_il-gen-gen_entities.adb
@@ -114,6 +114,7 @@ begin -- Gen_IL.Gen.Gen_Entities
 Sm (Has_Xref_Entry, Flag),
 Sm (Has_Yield_Aspect, Flag),
 Sm (Homonym, Node_Id),
+S

[gcc r16-1215] ada: Incorrect unresolved operator name in an instantiation

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:5f3113d79d55820f041fc7d1d6ce38598c6c3a35

commit r16-1215-g5f3113d79d55820f041fc7d1d6ce38598c6c3a35
Author: Steve Baird 
Date:   Fri Feb 7 12:29:46 2025 -0800

ada: Incorrect unresolved operator name in an instantiation

In some cases, a generic containing a use of a unary operator successfully
compiles but the compiler incorrectly rejects the corresponding use in
an instantiation.

gcc/ada/ChangeLog:

* sem_ch4.adb
(Find_Unary_Types): Because we reanalyze names in an instance,
we sometimes have to take steps to filter out extraneous name
resolution candidates that happen to be visible at the point of the
instance declaration. Remove some code that appears to have been
written with this in mind. This is done for two reasons. First, the
code sometimes doesn't work (possibly because the In_Instance test
is not specific enough - it probably should be testing to see 
whether
we are in an instance of the particular generic in which the result
of calling Corresponding_Generic_Type was declared) and causes 
correct
code to be rejected. Second, the code seems to no longer be 
necessary
(possibly because of subsequent fixes in this area which are not
specific to unary operators).

Diff:
---
 gcc/ada/sem_ch4.adb | 25 ++---
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 406983995f3d..50b3eee0dbe5 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -7642,35 +7642,14 @@ package body Sem_Ch4 is
begin
   if not Is_Overloaded (R) then
  if Is_Numeric_Type (Etype (R)) then
-
---  In an instance a generic actual may be a numeric type even if
---  the formal in the generic unit was not. In that case, the
---  predefined operator was not a possible interpretation in the
---  generic, and cannot be one in the instance, unless the operator
---  is an actual of an instance.
-
-if In_Instance
-  and then
-not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
-then
-   null;
-else
-   Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
-end if;
+Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
  end if;
 
   else
  Get_First_Interp (R, Index, It);
  while Present (It.Typ) loop
 if Is_Numeric_Type (It.Typ) then
-   if In_Instance
- and then
-   not Is_Numeric_Type
- (Corresponding_Generic_Type (Etype (It.Typ)))
-   then
-  null;
-
-   elsif Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
+   if Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
then
   Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
end if;


[gcc r16-1222] ada: Convert floating-point zero to machine representation

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:032e2209fff5573ee018fb78ed4c238c5fac4226

commit r16-1222-g032e2209fff5573ee018fb78ed4c238c5fac4226
Author: Piotr Trojanek 
Date:   Thu Feb 20 19:25:02 2025 +0100

ada: Convert floating-point zero to machine representation

When statically evaluating floating-point expressions we convert the final
result to machine number. However, we skipped this conversion if the result 
was
zero.

This inconsistency was introduced when adding a warning for compile-time
evaluation that gives different result from a run-time evaluation, but left
when this warning was deconstructed. It causes a crash in GNATprove, which
expects all floating-point numbers in the GNAT AST to be in a machine
representation form.

gcc/ada/ChangeLog:

* sem_eval.adb (Check_Non_Static_Context): Remove special handling 
of
floating-point zero.

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

diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index 5d1506364956..f5cd0449d617 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -574,13 +574,11 @@ package body Sem_Eval is
 
  Rewrite (N, New_Copy (N));
 
- if not Is_Floating_Point_Type (T) then
-Set_Realval
-  (N, Corresponding_Integer_Value (N) * Small_Value (T));
-
- elsif not UR_Is_Zero (Realval (N)) then
+ if Is_Floating_Point_Type (T) then
 Set_Realval (N, Machine_Number (Base_Type (T), Realval (N), N));
 Set_Is_Machine_Number (N);
+ else
+Set_Realval (N, Corresponding_Integer_Value (N) * Small_Value (T));
  end if;
 
   end if;


[gcc r16-1228] ada: Document representation clauses previously required by ASIS

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:da377160f648ff09f8df1a5200d14106bf62b2d1

commit r16-1228-gda377160f648ff09f8df1a5200d14106bf62b2d1
Author: Piotr Trojanek 
Date:   Tue Feb 25 12:48:32 2025 +0100

ada: Document representation clauses previously required by ASIS

A record type used for name identifiers had representation clause to make 
sure
that table with identifiers is written to an ASIS file without holes. Now 
ASIS
mode has been deconstructed, but we still want this representation clause to
ensure efficient implementation.

Comment update; behavior is unaffected.

gcc/ada/ChangeLog:

* namet.ads (Name_Entry): Update comments to explain the current 
needs.

Diff:
---
 gcc/ada/namet.ads | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/namet.ads b/gcc/ada/namet.ads
index daa87d91caa6..7182fb87e7ec 100644
--- a/gcc/ada/namet.ads
+++ b/gcc/ada/namet.ads
@@ -609,6 +609,7 @@ private
   --  Int Value associated with this name
 
end record;
+   --  The aliased non-boolean components are required to match the C structure
 
for Name_Entry use record
   Name_Chars_Index  at  0 range 0 .. 31;
@@ -622,9 +623,10 @@ private
   Hash_Link at  8 range 0 .. 31;
   Int_Info  at 12 range 0 .. 31;
end record;
+   --  This ensures a matching layout between Ada and C
 
for Name_Entry'Size use 16 * 8;
-   --  This ensures that we did not leave out any fields
+   --  This ensures that record is reasonably small
 
--  This is the table that is referenced by Valid_Name_Id entries.
--  It contains one entry for each unique name in the table.


[gcc r16-1223] ada: Fix wrong initialization of library-level object by conditional expression

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:f6d20900a2f358b007cfd47636bfb696aeab0d4c

commit r16-1223-gf6d20900a2f358b007cfd47636bfb696aeab0d4c
Author: Eric Botcazou 
Date:   Fri Feb 21 10:03:22 2025 +0100

ada: Fix wrong initialization of library-level object by conditional 
expression

At library level the object must be allocated statically and with its bounds
when its nominal subtype is an unconstrained array type.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Make sure the
object is allocated properly by the code generator at library level.

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

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 88e5f360bbfa..01be3dff89bc 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -13301,10 +13301,12 @@ package body Exp_Ch4 is
   Obj_Decl : constant Node_Id :=
 Make_Object_Declaration (Loc,
   Defining_Identifier => Obj_Id,
-  Aliased_Present => Aliased_Present (Decl),
+  Aliased_Present => True,
   Constant_Present=> Constant_Present (Decl),
   Object_Definition   => New_Copy_Tree (Object_Definition (Decl)),
   Expression  => Relocate_Node (Expr));
+  --  We make the object unconditionally aliased to avoid dangling bound
+  --  issues when its nominal subtype is an unconstrained array type.
 
   Master_Node_Decl : Node_Id;
   Master_Node_Id   : Entity_Id;
@@ -13319,6 +13321,11 @@ package body Exp_Ch4 is
 
   Insert_Action (Expr, Obj_Decl);
 
+  --  The object can never be local to an elaboration routine at library
+  --  level since we will take 'Unrestricted_Access of it.
+
+  Set_Is_Statically_Allocated (Obj_Id, Is_Library_Level_Entity (Obj_Id));
+
   --  If the object needs finalization, we need to insert its Master_Node
   --  manually because 1) the machinery in Exp_Ch7 will not pick it since
   --  it will be declared in the arm of a conditional statement and 2) we


[gcc r16-1204] libstdc++: Test for formatting with empty spec for local_info and sys_info.

2025-06-06 Thread Tomasz Kaminski via Gcc-cvs
https://gcc.gnu.org/g:66e65eb50d16affca66f29927478d109533f71bb

commit r16-1204-g66e65eb50d16affca66f29927478d109533f71bb
Author: Tomasz Kamiński 
Date:   Thu Jun 5 16:27:41 2025 +0200

libstdc++: Test for formatting with empty spec for local_info and sys_info.

We do not test with wchar_t currently, as operator<< (and format) are
ill-formed in such case, because we do not widen abbrev member of 
local_info.

Adding a tests for behavior of the ostream operator and the formatting
with empty chrono-spec for the chrono types. The coverage is now
complete:
 * sys_info, local_info in this commit,
 * time point, zoned_time and local_time_format in r16-1107-g3cfa53aa95a19c,
 * duration and hh_mm_ss in r16-1099-gac0a04b7a254fb,
 * calendar types in r16-1016-g28a17985dd34b7.

Finally, the timeout for the test was increased again and preprocessor 
checks
for zoned_time where changed to _GLIBCXX_USE_CXX11_ABI || 
!_GLIBCXX_USE_DUAL_ABI
to match ones from bits/chrono_io.h file.

libstdc++-v3/ChangeLog:

* testsuite/std/time/format/empty_spec.cc: New tests and increased
timeout.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 

Diff:
---
 .../testsuite/std/time/format/empty_spec.cc| 111 -
 1 file changed, 108 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc 
b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
index 48f61ee13e43..661712f1238b 100644
--- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
+++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
@@ -1,6 +1,6 @@
 // { dg-do run { target c++20 } }
 // { dg-require-effective-target hosted }
-// { dg-timeout-factor 2 }
+// { dg-timeout-factor 4 }
 
 #include 
 #include 
@@ -643,7 +643,7 @@ test_leap_second()
  WIDEN("2012-06-30 23:59:60") );
 }
 
-#if _GLIBCXX_USE_CXX11_ABI
+#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
 template
 auto
 make_zoned(const sys_time& st, const time_zone* tz)
@@ -723,7 +723,7 @@ test_time_points()
   test_time_point(true);
   test_time_point(true);
   test_leap_second();
-#if _GLIBCXX_USE_CXX11_ABI
+#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
   test_zoned_time();
 #endif
   test_local_time_format();
@@ -732,6 +732,108 @@ test_time_points()
   test_no_empty_spec>>();
 }
 
+#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
+template
+void
+test_sys_info()
+{
+  const sys_info si
+  {
+sys_days(2024y/March/22) + 2h,
+sys_days(2025y/April/11) + 23h + 15min + 10s,
+2h + 13min + 4s,
+15min,
+"Zone"
+  };
+  const std::basic_string_view<_CharT> txt
+= WIDEN("[2024-03-22 02:00:00,2025-04-11 23:15:10,02:13:04,15min,Zone]");
+
+  verify( si, txt );
+
+  std::basic_string<_CharT> res;
+  std::basic_string_view<_CharT> sv;
+
+  sv = res = std::format(WIDEN("{:65}"), si);
+  VERIFY( sv.ends_with(WIDEN("")) );
+  sv.remove_suffix(4);
+  VERIFY( sv == txt );
+
+  sv = res = std::format(WIDEN("{:=^67}"), si);
+  VERIFY( sv.starts_with(WIDEN("===")) );
+  VERIFY( sv.ends_with(WIDEN("===")) );
+  sv.remove_prefix(3);
+  sv.remove_suffix(3);
+  VERIFY( sv == txt );
+}
+
+template
+void test_local_info()
+{
+  using String = std::basic_string<_CharT>;
+  using StringView = std::basic_string_view<_CharT>;
+
+  const sys_info s1
+  {
+sys_days(2015y/September/11) + 2h,
+sys_days(2016y/March/13) + 2h,
+-5h,
+0h,
+"EET"
+  };
+  const sys_info s2
+  {
+sys_days(2016y/March/13) + 2h,
+sys_days(2015y/September/15) + 2h,
+-4h,
+1h,
+"EDT"
+  };
+
+  const StringView single
+= WIDEN("[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]");
+  const StringView both
+= WIDEN(" local time between "
+   "[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]"
+   " and "
+   "[2016-03-13 02:00:00,2015-09-15 02:00:00,-04:00:00,60min,EDT]");
+
+  const local_info l1{local_info::nonexistent, s1, s2};
+  auto exp = WIDEN("[nonexistent") + String(both) + WIDEN("]");
+  verify( l1, StringView(exp) );
+
+  const local_info l2{local_info::ambiguous, s1, s2};
+  exp = WIDEN("[ambiguous") + String(both) + WIDEN("]");
+  verify( l2, StringView(exp) );
+
+  const local_info l3{local_info::unique, s1, s1};
+  exp = WIDEN("[") + String(single) + WIDEN("]");
+  verify( l3, StringView(exp) );
+
+  String res;
+  StringView sv;
+
+  sv = res = std::format(WIDEN("{:65}"), l3);
+  VERIFY( sv.ends_with(WIDEN("   ")) );
+  sv.remove_suffix(3);
+  VERIFY( sv == exp );
+
+  sv = res = std::format(WIDEN("{:=^67}"), l3);
+  VERIFY( sv.starts_with(WIDEN("==")) );
+  VERIFY( sv.ends_with(WIDEN("===")) );
+  sv.remove_prefix(2);
+  sv.remove_suffix(3);
+  VERIFY( sv == exp );
+}
+
+template
+void
+test_infos()
+{
+  test_sys_info();
+  test_local_info();
+}
+#endif
+
 template
 void
 test_all()
@@ -745,6 +847,9 @@ test_all()
 int main()
 {
   te

[gcc r16-1225] ada: Fix libgpr2 build failure with compiler built with assertions

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:c29774a1f35eb46c969b84af31a362bbd5d8855d

commit r16-1225-gc29774a1f35eb46c969b84af31a362bbd5d8855d
Author: Eric Botcazou 
Date:   Mon Feb 24 22:27:21 2025 +0100

ada: Fix libgpr2 build failure with compiler built with assertions

The problem is that the Entity field is accessed for a node without one.

gcc/ada/ChangeLog:

* sem_ch10.adb (Install_Siblings.In_Context): Add missing guard.

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

diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index 9af96fc41b6b..25bba9b60759 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -4924,6 +4924,8 @@ package body Sem_Ch10 is
if Entity (Name (Clause)) = Id
  or else
(Nkind (Name (Clause)) = N_Expanded_Name
+ and then
+   Is_Entity_Name (Prefix (Name (Clause)))
  and then Entity (Prefix (Name (Clause))) = Id)
then
   return True;


[gcc r16-1210] ada: Do not generate warning about missing overriding indicator

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:939d23d1c8966c453a03e216135cb968e9db1761

commit r16-1210-g939d23d1c8966c453a03e216135cb968e9db1761
Author: Steve Baird 
Date:   Wed Feb 5 17:35:16 2025 -0800

ada: Do not generate warning about missing overriding indicator

We were previously generating a warning about a missing overriding
indicator in some cases when a dispatching subprogram is declared.
In at least some (and perhaps all) cases where this warning was generated,
it was incorrect. It was also generated very infrequently. The simple
solution is to stop generating the warning.

gcc/ada/ChangeLog:

* sem_disp.adb
(Check_Dispatching_Operation): Delete code to generate
"missing overriding indicator" warning. Update comments.

Diff:
---
 gcc/ada/sem_disp.adb | 20 +---
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb
index 4881d6f2f8b3..d13367659ac2 100644
--- a/gcc/ada/sem_disp.adb
+++ b/gcc/ada/sem_disp.adb
@@ -80,7 +80,7 @@ package body Sem_Disp is
--  parameter); otherwise returns empty.
 
function Find_Hidden_Overridden_Primitive (S : Entity_Id) return Entity_Id;
-   --  [Ada 2012:AI-0125] Find an inherited hidden primitive of the dispatching
+   --  [AI05-0125] Find an inherited hidden primitive of the dispatching
--  type of S that has the same name of S, a type-conformant profile, an
--  original corresponding operation O that is a primitive of a visible
--  ancestor of the dispatching type of S and O is visible at the point of
@@ -91,7 +91,8 @@ package body Sem_Disp is
--  This routine does not search for non-hidden primitives since they are
--  covered by the normal Ada 2005 rules. Its name was motivated by an
--  intermediate version of AI05-0125 where this term was proposed to
-   --  name these entities in the RM.
+   --  name these entities in the RM. FWIW, note that AI05-0125 was
+   --  not approved; it was voted "No Action".
 
function Is_Inherited_Public_Operation (Op : Entity_Id) return Boolean;
--  Check whether a primitive operation is inherited from an operation
@@ -1710,9 +1711,8 @@ package body Sem_Disp is
 
   Ovr_Subp := Old_Subp;
 
-  --  [Ada 2012:AI-0125]: Search for inherited hidden primitive that may be
-  --  overridden by Subp. This only applies to source subprograms, and
-  --  their declaration must carry an explicit overriding indicator.
+  --  Search for inherited hidden primitive that may be
+  --  overridden by Subp. This only applies to source subprograms.
 
   if No (Ovr_Subp)
 and then Ada_Version >= Ada_2012
@@ -1721,16 +1721,6 @@ package body Sem_Disp is
   Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
   then
  Ovr_Subp := Find_Hidden_Overridden_Primitive (Subp);
-
- --  Warn if the proper overriding indicator has not been supplied.
-
- if Present (Ovr_Subp)
-   and then
- not Must_Override (Specification (Unit_Declaration_Node (Subp)))
-   and then not In_Instance
- then
-Error_Msg_NE ("missing overriding indicator for&??", Subp, Subp);
- end if;
   end if;
 
   --  Now it should be a correct primitive operation, put it in the list


[gcc r16-1226] ada: Fix typo in documentation about convention and representation

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:daa245bc566835d162c0bcf323ead2effa9e2ecb

commit r16-1226-gdaa245bc566835d162c0bcf323ead2effa9e2ecb
Author: Piotr Trojanek 
Date:   Tue Feb 25 13:02:38 2025 +0100

ada: Fix typo in documentation about convention and representation

Currently there are only three exceptions to the general rule; the fourth
exception applied to OpenVMS, whose support has been deconstructed.

gcc/ada/ChangeLog:

* doc/gnat_rm/representation_clauses_and_pragmas.rst
(Effect of Convention on Representation): Fix number of list items.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst | 2 +-
 gcc/ada/gnat_rm.texi   | 2 +-
 gcc/ada/gnat_ugn.texi  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst 
b/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
index b0e131fe4abb..7250f6586ee1 100644
--- a/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/representation_clauses_and_pragmas.rst
@@ -1872,7 +1872,7 @@ conventions, and for example records are laid out in a 
manner that is
 consistent with C.  This means that specifying convention C (for example)
 has no effect.
 
-There are four exceptions to this general rule:
+There are three exceptions to this general rule:
 
 * *Convention Fortran and array subtypes*.
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 5ec090f2669a..5b2a9157c059 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -20717,7 +20717,7 @@ conventions, and for example records are laid out in a 
manner that is
 consistent with C.  This means that specifying convention C (for example)
 has no effect.
 
-There are four exceptions to this general rule:
+There are three exceptions to this general rule:
 
 
 @itemize *
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 5331a318c0d8..ca1d7bcc1abf 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29833,8 +29833,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{d2}@w{  }
 @anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
+@anchor{d2}@w{  }
 
 @c %**end of body
 @bye


[gcc r16-1227] ada: Deconstruct representation clauses required by ASIS

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:957a41f6daae59c3d0cbe1a76349416fae980ffa

commit r16-1227-g957a41f6daae59c3d0cbe1a76349416fae980ffa
Author: Piotr Trojanek 
Date:   Mon Feb 24 14:19:46 2025 +0100

ada: Deconstruct representation clauses required by ASIS

When GNAT was operating in ASIS mode, it was writing internal tables to 
files,
so we annotated record types for elements stored in these tables with
representation clauses to avoid holes with potentially uninitialized data.

Since ASIS mode has been now deconstructed and we no longer write internal
tables to files, we can remove explicit representation clauses and rely on 
the
data layout chosen by the compiler.

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* lib.ads (Unit_Record): Remove representation clauses and filler
components
* lib-load.adb, lib-writ.adb: Remove initialization of data fillers.
* nlists.adb (Allocate_List_Tables): Remove explicit initialization.
* repinfo.adb (Exp_Node): Remove representation clauses.
* sinput.ads (Source_File_Record): Likewise.
* urealp.adb (Ureal_Entry): Likewise.

Diff:
---
 gcc/ada/lib-load.adb |  6 --
 gcc/ada/lib-writ.adb |  4 
 gcc/ada/lib.ads  | 41 -
 gcc/ada/nlists.adb   | 11 +--
 gcc/ada/repinfo.adb  | 14 --
 gcc/ada/sinput.ads   | 50 ++
 gcc/ada/urealp.adb   | 14 --
 7 files changed, 3 insertions(+), 137 deletions(-)

diff --git a/gcc/ada/lib-load.adb b/gcc/ada/lib-load.adb
index 46de947c..bdeea1c8a75d 100644
--- a/gcc/ada/lib-load.adb
+++ b/gcc/ada/lib-load.adb
@@ -226,13 +226,11 @@ package body Lib.Load is
  Fatal_Error=> Error_Detected,
  Generate_Code  => False,
  Has_RACW   => False,
- Filler => False,
  Ident_String   => Empty,
 
  Is_Predefined_Renaming => Ren_Name,
  Is_Predefined_Unit => Pre_Name or Ren_Name,
  Is_Internal_Unit   => Pre_Name or Ren_Name or GNAT_Name,
- Filler2=> False,
 
  Loading=> False,
  Main_Priority  => Default_Main_Priority,
@@ -374,13 +372,11 @@ package body Lib.Load is
 Fatal_Error=> None,
 Generate_Code  => True,
 Has_RACW   => False,
-Filler => False,
 Ident_String   => Empty,
 
 Is_Predefined_Renaming => Ren_Name,
 Is_Predefined_Unit => Pre_Name or Ren_Name,
 Is_Internal_Unit   => Pre_Name or Ren_Name or GNAT_Name,
-Filler2=> False,
 
 Loading=> True,
 Main_Priority  => Default_Main_Priority,
@@ -760,13 +756,11 @@ package body Lib.Load is
Fatal_Error=> None,
Generate_Code  => False,
Has_RACW   => False,
-   Filler => False,
Ident_String   => Empty,
 
Is_Predefined_Renaming => Ren_Name,
Is_Predefined_Unit => Pre_Name or Ren_Name,
Is_Internal_Unit   => Pre_Name or Ren_Name or GNAT_Name,
-   Filler2=> False,
 
Loading=> True,
Main_Priority  => Default_Main_Priority,
diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb
index ccb0bd2a175a..b7a7f129de95 100644
--- a/gcc/ada/lib-writ.adb
+++ b/gcc/ada/lib-writ.adb
@@ -116,12 +116,10 @@ package body Lib.Writ is
  Fatal_Error=> None,
  Generate_Code  => False,
  Has_RACW   => False,
- Filler => False,
  Ident_String   => Empty,
  Is_Predefined_Renaming => False,
  Is_Internal_Unit   => False,
  Is_Predefined_Unit => False,
- Filler2=> False,
  Loading=> False,
  Main_Priority  => -1,
  Main_CPU   => -1,
@@ -175,12 +173,10 @@ package body Lib.Writ is
  Fatal_Error=> None,
  Generate_Code  => False,
  Has_RACW   => False,
- Filler => False,
  Ident_String   => Empty,
  Is_Predefined_Renaming => False,
  Is_Internal_Unit   => True,
  Is_Predefined_Unit => True,
- Filler2=> False,
  Loading=> False,
  Main_Priority  => -1,
  Main_CPU   => -1,
diff --git a/gcc/ada/lib.ads b/gcc/ada/lib.ads
index c902ca217a66..c22db30219e5 100644
--- a/gcc/ada/lib.ads
+

[gcc r16-1231] ada: Set Ekind early for entities created in expansion

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:5a8191d7fd64479756cce7063602b1dd34436d52

commit r16-1231-g5a8191d7fd64479756cce7063602b1dd34436d52
Author: Ronan Desplanques 
Date:   Wed Feb 26 11:22:45 2025 +0100

ada: Set Ekind early for entities created in expansion

This patch adds early Ekind assignments to entities created for the
expansion of a few constructs. The only effect is to enable more dynamic
checks for the uses of those entities that used to happen before the
Ekind had been set.

gcc/ada/ChangeLog:

* contracts.adb (Add_Invariant_And_Predicate_Checks): Assign Ekind.
* inline.adb (Expand_Inlined_Call): Likewise.
* exp_ch9.adb (Build_Simple_Entry_Call): Likewise.
* exp_dist.adb (Append_Array_Traversal): Likewise.
* exp_fixd.adb (Build_Double_Divide_Code, Build_Scaled_Divide_Code):
Likewise.

Diff:
---
 gcc/ada/contracts.adb |  1 +
 gcc/ada/exp_ch9.adb   |  1 +
 gcc/ada/exp_dist.adb  |  2 ++
 gcc/ada/exp_fixd.adb  | 14 ++
 gcc/ada/inline.adb|  1 +
 5 files changed, 19 insertions(+)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index c0a57e6d0bae..fc48d7f97da6 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -2422,6 +2422,7 @@ package body Contracts is
 --  verify the return value.
 
 Result := Make_Defining_Identifier (Loc, Name_uResult);
+Mutate_Ekind (Result, E_Constant);
 Set_Etype (Result, Typ);
 
 --  Add an invariant check when the return type has invariants and
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index ff5668e08c4c..9cfc6b536e92 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -4273,6 +4273,7 @@ package body Exp_Ch9 is
Defining_Identifier => Obj,
Object_Definition   => New_Occurrence_Of (Conctyp, Loc),
Expression  => ExpR);
+   Mutate_Ekind (Obj, E_Variable);
Set_Etype (Obj, Conctyp);
Decls := New_List (Decl);
Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
diff --git a/gcc/ada/exp_dist.adb b/gcc/ada/exp_dist.adb
index 694fbe47daba..a351b9b8a8fb 100644
--- a/gcc/ada/exp_dist.adb
+++ b/gcc/ada/exp_dist.adb
@@ -10980,6 +10980,7 @@ package body Exp_Dist is
 if not Constrained or else Depth > 1 then
Inner_Any := Make_Defining_Identifier (Loc,
   New_External_Name ('A', Depth));
+   Mutate_Ekind (Inner_Any, E_Variable);
Set_Etype (Inner_Any, RTE (RE_Any));
 else
Inner_Any := Empty;
@@ -10988,6 +10989,7 @@ package body Exp_Dist is
 if Present (Counter) then
Inner_Counter := Make_Defining_Identifier (Loc,
   New_External_Name ('J', Depth));
+   Mutate_Ekind (Inner_Counter, E_Variable);
 else
Inner_Counter := Empty;
 end if;
diff --git a/gcc/ada/exp_fixd.adb b/gcc/ada/exp_fixd.adb
index 03c7ca849158..8759099c193e 100644
--- a/gcc/ada/exp_fixd.adb
+++ b/gcc/ada/exp_fixd.adb
@@ -570,12 +570,16 @@ package body Exp_Fixd is
   --  Case where we can compute the denominator in Max_Integer_Size bits
 
   if QR_Id = RE_Null then
+ Mutate_Ekind (Qnn, E_Constant);
+ Mutate_Ekind (Rnn, E_Constant);
 
  --  Create temporaries for numerator and denominator and set Etypes,
  --  so that New_Occurrence_Of picks them up for Build_xxx calls.
 
  Nnn := Make_Temporary (Loc, 'N');
+ Mutate_Ekind (Nnn, E_Constant);
  Dnn := Make_Temporary (Loc, 'D');
+ Mutate_Ekind (Dnn, E_Constant);
 
  Set_Etype (Nnn, QR_Typ);
  Set_Etype (Dnn, QR_Typ);
@@ -621,6 +625,8 @@ package body Exp_Fixd is
   --  to call the runtime routine to compute the quotient and remainder.
 
   else
+ Mutate_Ekind (Qnn, E_Variable);
+ Mutate_Ekind (Rnn, E_Variable);
  Rnd := Boolean_Literals (Rounded_Result_Set (N));
 
  Code := New_List (
@@ -935,8 +941,13 @@ package body Exp_Fixd is
   --  Case where we can compute the numerator in Max_Integer_Size bits
 
   if QR_Id = RE_Null then
+ Mutate_Ekind (Qnn, E_Constant);
+ Mutate_Ekind (Rnn, E_Constant);
+
  Nnn := Make_Temporary (Loc, 'N');
+ Mutate_Ekind (Nnn, E_Constant);
  Dnn := Make_Temporary (Loc, 'D');
+ Mutate_Ekind (Dnn, E_Constant);
 
  --  Set Etypes, so that they can be picked up by New_Occurrence_Of
 
@@ -982,6 +993,9 @@ package body Exp_Fixd is
   --  to call the runtime routine to compute the quotient and remainder.
 
   else
+ Mutate_Ekind (Qnn, E_Variable);
+ Mutate_Ekind (Rnn, E_Variable);
+
  Rnd := Boolean_Literals (Rounded_Result_Set (N));
 
  Code := New_List (
diff --git a/gcc/ada/inline.

[gcc r16-1230] ada: Rework Android struct sigaction bindings

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:bdec2b7ce2109cc3aad94cad3ab478db7ae2

commit r16-1230-gbdec2b7ce2109cc3aad94cad3ab478db7ae2
Author: Olivier Hainque 
Date:   Fri Feb 21 08:18:38 2025 +

ada: Rework Android struct sigaction bindings

A previous change arranged for the common definition of
struct_sigaction in s-osinte__android.ads to work both for
ARM and aarch64 by way of representation clauses with
field offsets taken from specialized versions of s-linux
(one for ARM, one for aarch64).

The aarch64 variant had the offsets wrong, placing the
sa_handler pointer at offset 4, following the sa_flags int
at offset 0. The pointer is 8 bytes wide so should be
placed at an offset multiple of 8. This caused a discrepancy
between the Ada runtime actions and the expectations of the
underlying libc functions called.

This change refactors the struct_sigaction definition
to instanciate an entire type provided by s-linux instead,
parametrized by sigset_t which needs to remain provided
by the common System.OS_Interface spec.

gcc/ada/ChangeLog:

* libgnarl/s-linux__android-aarch64.ads: Provide an
Android_Sigaction generic package to expose an aarch64
version of struct_sigation, using a provided sigset_t
for sa_flags.
* libgnarl/s-linux__android-arm.ads: Likewise, for ARM
rather than aarch64.
* libgnarl/s-osinte__android.ads: Move sigset_t definition
to the visible part and use it to instantiate the Android_Sigation
generic provided by System.Linux, which is specialized for ARM vs
aarch64. Define struct_sigaction out of the Android_Sigaction
instance, remove the local representation clauses.

Diff:
---
 gcc/ada/libgnarl/s-linux__android-aarch64.ads | 20 +-
 gcc/ada/libgnarl/s-linux__android-arm.ads | 18 
 gcc/ada/libgnarl/s-osinte__android.ads| 40 ++-
 3 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/gcc/ada/libgnarl/s-linux__android-aarch64.ads 
b/gcc/ada/libgnarl/s-linux__android-aarch64.ads
index 4f9e81ddf656..537c46b5d3cc 100644
--- a/gcc/ada/libgnarl/s-linux__android-aarch64.ads
+++ b/gcc/ada/libgnarl/s-linux__android-aarch64.ads
@@ -118,13 +118,19 @@ package System.Linux is
SIG33  : constant := 33; --  glibc internal signal
SIG34  : constant := 34; --  glibc internal signal
 
-   --  struct_sigaction offsets
-
-   --  sa_flags come first on aarch64-android (sa_flags, sa_handler, sa_mask)
-
-   sa_flags_pos   : constant := 0;
-   sa_handler_pos : constant := sa_flags_pos + Interfaces.C.int'Size / 8;
-   sa_mask_pos: constant := sa_handler_pos + Standard'Address_Size / 8;
+   --  struct_sigaction
+
+   generic
+  type sigset_t is private;
+   package Android_Sigaction is
+  type struct_sigaction is record
+ sa_flags: Interfaces.C.int;
+ sa_handler  : System.Address;
+ sa_mask : sigset_t;
+ sa_restorer : System.Address;
+  end record;
+  pragma Convention (C, struct_sigaction);
+   end Android_Sigaction;
 
SA_SIGINFO  : constant := 16#0004#;
SA_ONSTACK  : constant := 16#0800#;
diff --git a/gcc/ada/libgnarl/s-linux__android-arm.ads 
b/gcc/ada/libgnarl/s-linux__android-arm.ads
index 3e0325e1902d..07bca55f6c47 100644
--- a/gcc/ada/libgnarl/s-linux__android-arm.ads
+++ b/gcc/ada/libgnarl/s-linux__android-arm.ads
@@ -118,11 +118,19 @@ package System.Linux is
SIG33  : constant := 33; --  glibc internal signal
SIG34  : constant := 34; --  glibc internal signal
 
-   --  struct_sigaction offsets
-
-   sa_handler_pos : constant := 0;
-   sa_mask_pos: constant := Standard'Address_Size / 8;
-   sa_flags_pos   : constant := 4 + sa_mask_pos;
+   --  struct_sigaction
+
+   generic
+  type sigset_t is private;
+   package Android_Sigaction is
+  type struct_sigaction is record
+ sa_handler  : System.Address;
+ sa_mask : sigset_t;
+ sa_flags: Interfaces.C.int;
+ sa_restorer : System.Address;
+  end record;
+  pragma Convention (C, struct_sigaction);
+   end Android_Sigaction;
 
SA_SIGINFO  : constant := 16#0004#;
SA_ONSTACK  : constant := 16#0800#;
diff --git a/gcc/ada/libgnarl/s-osinte__android.ads 
b/gcc/ada/libgnarl/s-osinte__android.ads
index d74589047e75..4383860ed2b1 100644
--- a/gcc/ada/libgnarl/s-osinte__android.ads
+++ b/gcc/ada/libgnarl/s-osinte__android.ads
@@ -147,7 +147,20 @@ package System.OS_Interface is
--  Not clear why these two signals are reserved. Perhaps they are not
--  supported by this version of GNU/Linux ???
 
-   type sigset_t is private;
+   --  struct sigaction fields are of different sizes and come in different
+   --  order on ARM vs aarch64.  As this source is shared by the two
+   --  configurations, fetch the type definit

[gcc r16-1243] ada: Simplify tests for positive rational numbers

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:45a305c3c7b431c5be761dd7e05cc99384b32b32

commit r16-1243-g45a305c3c7b431c5be761dd7e05cc99384b32b32
Author: Piotr Trojanek 
Date:   Mon Feb 24 10:40:16 2025 +0100

ada: Simplify tests for positive rational numbers

Checking a rational number for being positive takes a shorter code path than
a general comparison with zero. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Tune code for
attribute Small.
* sem_prag.adb (Analyze_Attribute): Tune code for pragma Time_Slice.

Diff:
---
 gcc/ada/sem_ch13.adb | 2 +-
 gcc/ada/sem_prag.adb | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 5e7cba8bef91..76a8c0ba7331 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -7250,7 +7250,7 @@ package body Sem_Ch13 is
 else
Small := Expr_Value_R (Expr);
 
-   if Small <= Ureal_0 then
+   if not UR_Is_Positive (Small) then
   Error_Msg_N ("small value must be greater than zero", Expr);
   return;
end if;
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index b94606eabc71..4090d0c71175 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -26953,7 +26953,7 @@ package body Sem_Prag is
Opt.Time_Slice_Set := True;
Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
 
-   if Val <= Ureal_0 then
+   if not UR_Is_Positive (Val) then
   Opt.Time_Slice_Value := 0;
 
elsif Val > UR_From_Uint (UI_From_Int (1000)) then


[gcc r16-1245] ada: Avoid repeated range checks when negating a rational number

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:73763e312fb3fc483ab0d159d35998b5d927a333

commit r16-1245-g73763e312fb3fc483ab0d159d35998b5d927a333
Author: Piotr Trojanek 
Date:   Thu Feb 27 11:44:54 2025 +0100

ada: Avoid repeated range checks when negating a rational number

Use local constant to avoid repeated range checks (at least in the debug
builds), but also to make the code easier to read and consistent in style
with similar routines in the same package.

gcc/ada/ChangeLog:

* urealp.adb (UR_Negate): Capture array element in a local constant.

Diff:
---
 gcc/ada/urealp.adb | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/urealp.adb b/gcc/ada/urealp.adb
index 3a9fddea60b5..d5fb4f55be7d 100644
--- a/gcc/ada/urealp.adb
+++ b/gcc/ada/urealp.adb
@@ -1237,12 +1237,13 @@ package body Urealp is
---
 
function UR_Negate (Real : Ureal) return Ureal is
+  Val : constant Ureal_Entry := Ureals.Table (Real);
begin
   return Store_Ureal
-   ((Num  => Ureals.Table (Real).Num,
- Den  => Ureals.Table (Real).Den,
- Rbase=> Ureals.Table (Real).Rbase,
- Negative => not Ureals.Table (Real).Negative));
+   ((Num  => Val.Num,
+ Den  => Val.Den,
+ Rbase=> Val.Rbase,
+ Negative => not Val.Negative));
end UR_Negate;
 



[gcc r16-1273] cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]

2025-06-06 Thread Robert Dubner via Gcc-cvs
https://gcc.gnu.org/g:37f5fdd008399c239e0689f2e864519505c78c7e

commit r16-1273-g37f5fdd008399c239e0689f2e864519505c78c7e
Author: Robert Dubner 
Date:   Fri Jun 6 16:32:22 2025 -0400

cobol: Diagnostic messages, Flex build, and some cppcheck reports. 
[PR120328, PR119695]

Remove %0x and similar from diagnostic framework messages.  Remove %zu
from printf messages because it is not supported on some
platforms. Corrections in response to cppcheck.  Sundry small fixes.

gcc/cobol/ChangeLog:

PR cobol/120328
* Make-lang.in: Success with non-English locale.
PR cobol/119695
* cbldiag.h (cbl_unimplemented_at): Comment:
* cdf-copy.cc (copybook_elem_t::open_file): Indentation.
* cdf.y: YYABORT on certain errors.
* cdfval.h (cdf_value): Const parameter.
* copybook.h (class copybook_elem_t): Initialization.
(class uppername_t): Explicit constructor.
* except.cc (ec_type_descr): Remove %04s.
(cbl_enabled_exceptions_t::dump): Remove %zu.
* exceptg.h (class exception_turn_t): Explicit constructor.
* genapi.cc (parser_perform_conditional): Remove %zu.
(set_exception_environment): Formatting.
(parser_statement_begin): Exception overhead.
(parser_perform_conditional): Formatting:
(parser_perform_conditional_end): Eliminate size_t.
(parser_check_fatal_exception): Exception overhead.
(parser_perform_conditional_end): Remove %zu.
* inspect.h (struct cbx_inspect_match_t): Const reference.
(struct cbx_inspect_t): Const parameter.
* lexio.cc (cdftext::process_file): Remove %zu.
* lexio.h (struct YYLTYPE): Remove unneeded struct.
(YYLTYPE_IS_DECLARED): Likewise.
(YYLTYPE_IS_TRIVIAL): Likewise.
* parse.y: Comment; change DOT.
* scan.l: Scan function names without swallowing whitespace.
* scan_ante.h (scanner_parsing): Remove %zu.
(scanner_parsing_pop): Remove %zu.
(binary_integer_usage): Remove %zu.
* scan_post.h (prelex): Correct post-CDF resumption.
(yylex): Clearer message.
* symbols.cc (symbol_table_extend): Explicit constructor.
(elementize): Const parameter.
(is_variable_length): Correct always-false.
(symbols_update): Remove unnecessary shadow variable.
(struct symbol_elem_t): Const parameter.
(symbol_alphabet_add): Const parameter.
(new_literal_add): Initialization.
* symbols.h (class cbl_domain_elem_t): Correct assignment.
(struct cbl_span_t): Improve constructor.
(struct cbl_refer_t): Initialization.
(struct cbl_alphabet_t): Rename shadow variable.
(struct cbl_file_key_t): Remove unused constructor.
(struct symbol_elem_t): Initialization.
(struct cbl_until_addresses_t): Use unsigned int, for messages.
(struct cbl_prog_hier_t): Initialization.
(struct cbl_perform_tgt_t): Repair constructor.
(struct cbl_label_t): Const parameter.
(symbol_typedef_add): Const parameter.
(symbol_field_add): Explicit constructor.
(symbol_label_add): Explicit constructor.
(symbol_program_add): Remove C-style "struct" use.
(symbol_special_add): Remove C-style "struct" use.
(symbol_alphabet_add): Const parameter.
(symbol_file_add): Remove C-style "struct" use.
(symbol_section_add): Remove C-style "struct" use.
* symfind.cc: Const parameter.
* util.cc (gb4): New function.
* util.h (gb4): New function.
* TODO: New file.

libgcobol/ChangeLog:

* common-defs.h (enum cbl_file_mode_t): Whitespace.
(enum file_stmt_t): Likewise.
(ec_cmp): Likewise.
(struct cbl_declarative_t): Add "explicit" keyword.
(class cbl_enabled_exceptions_t): Whitespace.
* gfileio.cc: Remove cppcheck comment.
* libgcobol.cc (class ec_status_t): Add "explicit" keyword.
(match_declarative): Remove %zu.
(default_exception_handler): Likwise.
(__gg__check_fatal_exception): Exception overhead.
(__gg__exception_push): Remove %zu.
(__gg__exception_pop): Likewise.
(cbl_enabled_exception_t::dump): Likewise.
(__gg__match_exception): Exception overhead; remove %zu.
(cbl_enabled_exceptions_t::dump): Remove %zu.
(__gg__set_exception_environment): Likewise.

Co-authored-by: James K. Lowden 
Co-authored-by: Robert Dubner 

Diff:
---
 gcc/cobol/Make-lang.in  |   3 +-
 gcc/cobol/TODO  |  33 +++
 gcc/cobol/cbldiag.h |   6 

[gcc r16-1275] Fix index of some warnings [PR120572]

2025-06-06 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:50ca15baa73a5687ff0d0207dc9313b3ae1d6e5c

commit r16-1275-g50ca15baa73a5687ff0d0207dc9313b3ae1d6e5c
Author: Andrew Pinski 
Date:   Fri Jun 6 21:50:27 2025 -0700

Fix index of some warnings [PR120572]

The problem here is opindex should not include the `-` part of the option.
But Wmusttail-local-addr and Wno-maybe-musttail-local-addr currently do.
This deletes them.

Pushed as obvious after building the html.

PR tree-optimization/120572
gcc/ChangeLog:

* doc/invoke.texi (Wmusttail-local-addr,
Wno-maybe-musttail-local-addr): Fix opindex.
* common.opt.urls: Regenerate.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/common.opt.urls | 2 +-
 gcc/doc/invoke.texi | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/common.opt.urls b/gcc/common.opt.urls
index c10856087357..c7f234bce413 100644
--- a/gcc/common.opt.urls
+++ b/gcc/common.opt.urls
@@ -159,7 +159,7 @@ Wmissing-noreturn
 UrlSuffix(gcc/Warning-Options.html#index-Wmissing-noreturn)
 
 Wmusttail-local-addr
-UrlSuffix(gcc/Warning-Options.html#index-Wno-musttail-local-addr)
+UrlSuffix(gcc/Warning-Options.html#index-Wmusttail-local-addr)
 
 Wmaybe-musttail-local-addr
 UrlSuffix(gcc/Warning-Options.html#index-Wmaybe-musttail-local-addr)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d7f51b4f6d93..189a52b9b959 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7060,14 +7060,14 @@ which is enabled by optimizations in most targets.  The 
precision of
 the warnings depends on the optimization options used.
 
 @opindex Wno-musttail-local-addr
-@opindex -Wmusttail-local-addr
+@opindex Wmusttail-local-addr
 @item -Wno-musttail-local-addr
 Do not warn about passing a pointer (or in C++, a reference) to a
 local variable or label to argument of a @code{musttail} call.  Those
 variables go out of scope before the tail call instruction.
 
 @opindex Wmaybe-musttail-local-addr
-@opindex -Wno-maybe-musttail-local-addr
+@opindex Wno-maybe-musttail-local-addr
 @item -Wmaybe-musttail-local-addr
 Warn when address of a local variable can escape to a @code{musttail}
 call, unless it goes out of scope already before the @code{musttail}


[gcc r16-1264] libstdc++: Adjust effective-target requirements for and

2025-06-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:29b2cb40ee848928385a48c4fdeb9b7a2ae0aecd

commit r16-1264-g29b2cb40ee848928385a48c4fdeb9b7a2ae0aecd
Author: Jonathan Wakely 
Date:   Wed Jun 4 20:09:21 2025 +0100

libstdc++: Adjust effective-target requirements for  and 


These features depend on __cpp_lib_atomic_wait which is not available
for freestanding, and is available when either gthreads is supported, or
the target is linux (for futex support).

libstdc++-v3/ChangeLog:

* testsuite/30_threads/barrier/1.cc: Require hosted. Only
require gthreads for non-linux targets.
* testsuite/30_threads/barrier/2.cc: Likewise.
* testsuite/30_threads/semaphore/1.cc: Likewise.
* testsuite/30_threads/semaphore/2.cc: Likewise.
* testsuite/30_threads/semaphore/cons.cc: Likewise.
* testsuite/30_threads/semaphore/least_max_value_neg.cc:
Likewise.
* testsuite/30_threads/semaphore/try_acquire.cc: Likewise.

Reviewed-by: Tomasz Kamiński 

Diff:
---
 libstdc++-v3/testsuite/30_threads/barrier/1.cc | 3 ++-
 libstdc++-v3/testsuite/30_threads/barrier/2.cc | 2 +-
 libstdc++-v3/testsuite/30_threads/semaphore/1.cc   | 2 ++
 libstdc++-v3/testsuite/30_threads/semaphore/2.cc   | 1 +
 libstdc++-v3/testsuite/30_threads/semaphore/cons.cc| 2 ++
 libstdc++-v3/testsuite/30_threads/semaphore/least_max_value_neg.cc | 4 ++--
 libstdc++-v3/testsuite/30_threads/semaphore/try_acquire.cc | 3 ++-
 7 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/30_threads/barrier/1.cc 
b/libstdc++-v3/testsuite/30_threads/barrier/1.cc
index eff8ef3a174b..01c55d96cd20 100644
--- a/libstdc++-v3/testsuite/30_threads/barrier/1.cc
+++ b/libstdc++-v3/testsuite/30_threads/barrier/1.cc
@@ -16,7 +16,8 @@
 // .
 
 // { dg-do compile { target c++20 } }
-// { dg-require-effective-target gthreads }
+// { dg-require-effective-target gthreads { target { ! *-*-linux* } } }
+// { dg-require-effective-target hosted }
 // { dg-add-options no_pch }
 
 #include 
diff --git a/libstdc++-v3/testsuite/30_threads/barrier/2.cc 
b/libstdc++-v3/testsuite/30_threads/barrier/2.cc
index e0188b3fd8ea..728030babbd1 100644
--- a/libstdc++-v3/testsuite/30_threads/barrier/2.cc
+++ b/libstdc++-v3/testsuite/30_threads/barrier/2.cc
@@ -16,7 +16,7 @@
 // .
 
 // { dg-do compile { target c++20 } }
-// { dg-require-effective-target gthreads }
+// { dg-require-effective-target gthreads { target { ! *-*-linux* } } }
 // { dg-require-effective-target hosted }
 // { dg-add-options no_pch }
 
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/1.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/1.cc
index ac9f97b816fe..cc6befcc1a50 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/1.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/1.cc
@@ -16,6 +16,8 @@
 // .
 
 // { dg-do compile { target c++20 } }
+// { dg-require-effective-target gthreads { target { ! *-*-linux* } } }
+// { dg-require-effective-target hosted }
 // { dg-add-options no_pch }
 
 #include 
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/2.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/2.cc
index 251e96adae68..bff747c0aa33 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/2.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/2.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-do compile { target c++20 } }
+// { dg-require-effective-target gthreads { target { ! *-*-linux* } } }
 // { dg-require-effective-target hosted }
 // { dg-add-options no_pch }
 
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/cons.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/cons.cc
index 920f7423332b..790ff2eab557 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/cons.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/cons.cc
@@ -1,4 +1,6 @@
 // { dg-do compile { target c++20 } }
+// { dg-require-effective-target gthreads { target { ! *-*-linux* } } }
+// { dg-require-effective-target hosted }
 
 #include 
 
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/least_max_value_neg.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/least_max_value_neg.cc
index 1498d38cb93a..e2680b12e5ae 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/least_max_value_neg.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/least_max_value_neg.cc
@@ -16,8 +16,8 @@
 // .
 
 // { dg-do compile { target c++20 } }
-// { dg-require-effective-target pthread }
-// { dg-require-gthreads "" }
+// { dg-require-effective-target gthreads { target { ! *-*-linux* } } }
+// { dg-require-effective-target hosted }
 
 #include 
 
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquir

[gcc r16-1265] cselim: Update the vop manually for cond_if_else_store replacement

2025-06-06 Thread Andrew Pinski via Gcc-cvs
https://gcc.gnu.org/g:3655b4c4ae2dd6c841777f6479472a75a15ba746

commit r16-1265-g3655b4c4ae2dd6c841777f6479472a75a15ba746
Author: Andrew Pinski 
Date:   Thu Jun 5 15:03:27 2025 -0700

cselim: Update the vop manually for cond_if_else_store replacement

To speed up things slightly, we can do the update of the vop for the
newly inserted store manually.
This will also allow a simplified part of cselim to be used inside
phi-opt to move the store out earlier and independent of the full cselim.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (cond_if_else_store_replacement_1): Add vphi 
argument.
Manually update the vphi and new_stmt vdef/lhs.
(cond_if_else_store_replacement): Update call to 
cond_if_else_store_replacement_1.

Signed-off-by: Andrew Pinski 

Diff:
---
 gcc/tree-ssa-phiopt.cc | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index bf493e129878..2e4f9dad3270 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3605,7 +3605,8 @@ cond_store_replacement (basic_block middle_bb, 
basic_block join_bb,
 static bool
 cond_if_else_store_replacement_1 (basic_block then_bb, basic_block else_bb,
  basic_block join_bb, gimple *then_assign,
- gimple *else_assign)
+ gimple *else_assign,
+ gphi *vphi)
 {
   tree lhs_base, lhs, then_rhs, else_rhs, name;
   location_t then_locus, else_locus;
@@ -3672,6 +3673,14 @@ cond_if_else_store_replacement_1 (basic_block then_bb, 
basic_block else_bb,
   add_phi_arg (newphi, else_rhs, EDGE_SUCC (else_bb, 0), else_locus);
 
   new_stmt = gimple_build_assign (lhs, gimple_phi_result (newphi));
+  /* Update the vdef for the new store statement. */
+  tree newvphilhs = make_ssa_name (gimple_vop (cfun));
+  tree vdef = gimple_phi_result (vphi);
+  gimple_set_vuse (new_stmt, newvphilhs);
+  gimple_set_vdef (new_stmt, vdef);
+  gimple_phi_set_result (vphi, newvphilhs);
+  SSA_NAME_DEF_STMT (vdef) = new_stmt;
+  update_stmt (vphi);
   if (dump_file && (dump_flags & TDF_DETAILS))
 {
   fprintf(dump_file, "to use phi:\n");
@@ -3782,7 +3791,7 @@ cond_if_else_store_replacement (basic_block then_bb, 
basic_block else_bb,
   gimple *else_assign = single_trailing_store_in_bb (else_bb, else_vdef);
   if (else_assign)
return cond_if_else_store_replacement_1 (then_bb, else_bb, join_bb,
-then_assign, else_assign);
+then_assign, else_assign, 
vphi);
 }
 
   /* If either vectorization or if-conversion is disabled then do
@@ -3921,7 +3930,7 @@ cond_if_else_store_replacement (basic_block then_bb, 
basic_block else_bb,
   then_store = store_pair.first;
   else_store = store_pair.second;
   res = cond_if_else_store_replacement_1 (then_bb, else_bb, join_bb,
-  then_store, else_store);
+ then_store, else_store, vphi);
   ok = ok || res;
 }


[gcc/devel/omp/gcc-15] builtins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:c8963f01ac813346f543ae118e702df8c28cd884

commit c8963f01ac813346f543ae118e702df8c28cd884
Author: Tobias Burnus 
Date:   Fri Jun 6 15:57:50 2025 +0200

builtins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins

The flags -std=c.. and -std=c++.. imply -fno-nonansi-builtins, which 
disabled
the OpenMP/OpenACC intrinsics - but -fopenmp/-fopenacc builtin use should be
rather othogonal to the user's choice between -std=c... and -std=gnuc...

gcc/ChangeLog:

* builtins.def (DEF_GOACC_BUILTIN_COMPILER, 
DEF_GOMP_BUILTIN_COMPILER):
Set NONANSI_P = false to enable those also with 
-fno-nonansi-builtins.

(cherry picked from commit 214b5d66c54613463a96aa2c7202bc32f628dad6)

Diff:
---
 gcc/builtins.def | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/builtins.def b/gcc/builtins.def
index ff470051e54e..6794109f5fb1 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -217,6 +217,8 @@ along with GCC; see the file COPYING3.  If not see
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
   false, true, true, ATTRS, false, \
   flag_openacc)
+/* Set NONANSI_P = false to enable the builtins also with 
-fno-nonansi-builtins,
+   esp. as -std=c++../c.. imply that flag and -fopenacc should be othogonal.  
*/
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
@@ -232,10 +234,12 @@ along with GCC; see the file COPYING3.  If not see
   (flag_openacc \
|| flag_openmp \
|| flag_tree_parallelize_loops > 1))
+/* Set NONANSI_P = false to enable the builtins also with 
-fno-nonansi-builtins,
+   esp. as -std=c++../c.. imply that flag and -fopenmp should be othogonal.  */
 #undef DEF_GOMP_BUILTIN_COMPILER
 #define DEF_GOMP_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
-   flag_openmp, true, true, ATTRS, false, flag_openmp)
+   flag_openmp, true, false, ATTRS, false, flag_openmp)
 
 /* Builtin used by the implementation of GNU TM.  These
functions are mapped to the actual implementation of the STM library. */


[gcc r16-1268] diagnostics: move xml defs to a new xml.cc

2025-06-06 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:1233d79c1935f19104e76ba7aa842dc7ee6c2279

commit r16-1268-g1233d79c1935f19104e76ba7aa842dc7ee6c2279
Author: David Malcolm 
Date:   Fri Jun 6 13:41:27 2025 -0400

diagnostics: move xml defs to a new xml.cc

While prototyping new features I'm finding it helpful to use XML
beyond the "experimental-html" diagnostics sink.  Move the
implementation of the xml classes to their own file.

No functional change intended.

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add xml.o.
* diagnostic-format-html.cc (namespace xml): Move implementation
to xml.cc
(selftest::test_printer): Likewise.
(selftest::test_attribute_ordering): Likewise.
(selftest::diagnostic_format_html_cc_tests): Don't call the moved
tests here; they will be called from xml_cc_tests in xml.cc.
* selftest-run-tests.cc (selftest::run_tests): Call xml_cc_tests.
* selftest.h (selftest::xml_cc_tests): New decl.
* xml.cc: New file, based on material from
diagnostic-format-html.cc.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/Makefile.in   |   1 +
 gcc/diagnostic-format-html.cc | 313 
 gcc/selftest-run-tests.cc |   1 +
 gcc/selftest.h|   1 +
 gcc/xml.cc| 358 ++
 5 files changed, 361 insertions(+), 313 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 49869531bc8a..fe20b655477f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1862,6 +1862,7 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o 
diagnostic-color.o \
edit-context.o \
pretty-print.o intl.o \
json.o json-parsing.o \
+   xml.o \
sbitmap.o \
vec.o input.o hash-table.o ggc-none.o memory-block.o \
selftest.o selftest-diagnostic.o sort.o \
diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc
index 05d4273c2c61..076790bfff7a 100644
--- a/gcc/diagnostic-format-html.cc
+++ b/gcc/diagnostic-format-html.cc
@@ -49,256 +49,6 @@ html_generation_options::html_generation_options ()
 {
 }
 
-namespace xml {
-
-/* Disable warnings about quoting issues in the pp_xxx calls below
-   that (intentionally) don't follow GCC diagnostic conventions.  */
-#if __GNUC__ >= 10
-#  pragma GCC diagnostic push
-#  pragma GCC diagnostic ignored "-Wformat-diag"
-#endif
-
-
-/* Implementation.  */
-
-static void
-write_escaped_text (pretty_printer *pp, const char *text)
-{
-  gcc_assert (text);
-
-  for (const char *p = text; *p; ++p)
-{
-  char ch = *p;
-  switch (ch)
-   {
-   default:
- pp_character (pp, ch);
- break;
-   case '\'':
- pp_string (pp, "'");
- break;
-   case '"':
- pp_string (pp, """);
- break;
-   case '&':
- pp_string (pp, "&");
- break;
-   case '<':
- pp_string (pp, "<");
- break;
-   case '>':
- pp_string (pp, ">");
- break;
-   }
-}
-}
-
-/* struct node.  */
-
-void
-node::dump (FILE *out) const
-{
-  pretty_printer pp;
-  pp.set_output_stream (out);
-  write_as_xml (&pp, 0, true);
-  pp_flush (&pp);
-}
-
-/* struct text : public node.  */
-
-void
-text::write_as_xml (pretty_printer *pp, int depth, bool indent) const
-{
-  if (indent)
-{
-  for (int i = 0; i < depth; ++i)
-   pp_string (pp, "  ");
-}
-  write_escaped_text (pp, m_str.c_str ());
-  if (indent)
-pp_newline (pp);
-}
-
-/* struct node_with_children : public node.  */
-
-void
-node_with_children::add_child (std::unique_ptr node)
-{
-  gcc_assert (node.get ());
-  m_children.push_back (std::move (node));
-}
-
-void
-node_with_children::add_text (std::string str)
-{
-  // Consolidate runs of text
-  if (!m_children.empty ())
-if (text *t = m_children.back ()->dyn_cast_text ())
-  {
-   t->m_str += std::move (str);
-   return;
-  }
-  add_child (std::make_unique  (std::move (str)));
-}
-
-
-/* struct document : public node_with_children.  */
-
-void
-document::write_as_xml (pretty_printer *pp, int depth, bool indent) const
-{
-  pp_string (pp, "\n");
-  pp_string (pp, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>");
-  if (indent)
-pp_newline (pp);
-  for (auto &iter : m_children)
-iter->write_as_xml (pp, depth, indent);
-}
-
-/* struct element : public node_with_children.  */
-
-void
-element::write_as_xml (pretty_printer *pp, int depth, bool indent) const
-{
-  if (indent)
-{
-  for (int i = 0; i < depth; ++i)
-   pp_string (pp, "  ");
-}
-
-  pp_printf (pp, "<%s", m_kind.c_str ());
-  for (auto &key : m_key_insertion_order)
-{
-  auto iter = m_attributes.find (key);
-  if (iter != m_attributes.end ())
-   {
- pp_printf (pp, " %s=\"", key.c_str ());
- write_escaped_text (pp, iter->second.c

[gcc r16-1267] selftest.h: fix sort order of decls

2025-06-06 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:0401957b86fa29b25acf3e960e430e6a7c9196eb

commit r16-1267-g0401957b86fa29b25acf3e960e430e6a7c9196eb
Author: David Malcolm 
Date:   Fri Jun 6 13:41:27 2025 -0400

selftest.h: fix sort order of decls

No functional change intended.

gcc/ChangeLog:
* selftest.h: Fix the sorting of the various *_cc_tests decls.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/selftest.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/selftest.h b/gcc/selftest.h
index cd85840b83e0..c5ea6de30137 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -220,6 +220,7 @@ extern void attribs_cc_tests ();
 extern void bitmap_cc_tests ();
 extern void cgraph_cc_tests ();
 extern void convert_cc_tests ();
+extern void dbgcnt_cc_tests ();
 extern void diagnostic_color_cc_tests ();
 extern void diagnostic_format_html_cc_tests ();
 extern void diagnostic_format_json_cc_tests ();
@@ -237,12 +238,15 @@ extern void gcc_attribute_urlifier_cc_tests ();
 extern void gcc_urlifier_cc_tests ();
 extern void ggc_tests_cc_tests ();
 extern void gimple_cc_tests ();
+extern void gimple_range_tests ();
 extern void hash_map_tests_cc_tests ();
 extern void hash_set_tests_cc_tests ();
 extern void input_cc_tests ();
+extern void ipa_modref_tree_cc_tests ();
 extern void json_cc_tests ();
-extern void lazy_diagnostic_path_cc_tests ();
 extern void json_parser_cc_tests ();
+extern void lazy_diagnostic_path_cc_tests ();
+extern void opt_suggestions_cc_tests ();
 extern void optinfo_emit_json_cc_tests ();
 extern void opts_cc_tests ();
 extern void opts_diagnostic_cc_tests ();
@@ -250,11 +254,10 @@ extern void ordered_hash_map_tests_cc_tests ();
 extern void path_coverage_cc_tests ();
 extern void predict_cc_tests ();
 extern void pretty_print_cc_tests ();
-extern void range_tests ();
 extern void range_op_tests ();
-extern void relation_tests ();
-extern void gimple_range_tests ();
+extern void range_tests ();
 extern void read_rtl_function_cc_tests ();
+extern void relation_tests ();
 extern void rtl_tests_cc_tests ();
 extern void sbitmap_cc_tests ();
 extern void selftest_cc_tests ();
@@ -273,9 +276,6 @@ extern void typed_splay_tree_cc_tests ();
 extern void vec_cc_tests ();
 extern void vec_perm_indices_cc_tests ();
 extern void wide_int_cc_tests ();
-extern void opt_suggestions_cc_tests ();
-extern void dbgcnt_cc_tests ();
-extern void ipa_modref_tree_cc_tests ();
 
 extern int num_passes;


[gcc r16-1266] text-art: allow wrapper_widget to have no child

2025-06-06 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:cda7145fa9e97f9f710a09339ea001fccb2662a2

commit r16-1266-gcda7145fa9e97f9f710a09339ea001fccb2662a2
Author: David Malcolm 
Date:   Fri Jun 6 13:41:27 2025 -0400

text-art: allow wrapper_widget to have no child

During prototyping a feature I found it useful for
text_art::wrapper_widget to be able to not have a child.

gcc/ChangeLog:
* text-art/widget.cc (selftest::test_empty_wrapper_widget): New.
(selftest::text_art_widget_cc_tests): Call it.
* text-art/widget.h (text_art::wrapper_widget::calc_req_size):
Gracefully handle m_child being null.
(text_art::wrapper_widget::update_child_alloc_rects): Likewise.
(text_art::wrapper_widget::paint_to_canvas): Likewise.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/text-art/widget.cc | 10 ++
 gcc/text-art/widget.h  | 11 ---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/text-art/widget.cc b/gcc/text-art/widget.cc
index 3c68018c3b54..5d3e5178484c 100644
--- a/gcc/text-art/widget.cc
+++ b/gcc/text-art/widget.cc
@@ -199,6 +199,15 @@ test_wrapper_widget ()
   "BBB\n"));
 }
 
+static void
+test_empty_wrapper_widget ()
+{
+  style_manager sm;
+  wrapper_widget w (nullptr);
+  canvas c (w.to_canvas (sm));
+  ASSERT_CANVAS_STREQ (c, false, "");
+}
+
 static void
 test_vbox_1 ()
 {
@@ -263,6 +272,7 @@ text_art_widget_cc_tests ()
   test_test_widget ();
   test_text_widget ();
   test_wrapper_widget ();
+  test_empty_wrapper_widget ();
   test_vbox_1 ();
   test_vbox_2 ();
   test_canvas_widget ();
diff --git a/gcc/text-art/widget.h b/gcc/text-art/widget.h
index 55655ebfd62a..ab7b1d3c4ecc 100644
--- a/gcc/text-art/widget.h
+++ b/gcc/text-art/widget.h
@@ -146,15 +146,20 @@ class wrapper_widget : public widget
   }
   canvas::size_t calc_req_size () override
   {
-return m_child->get_req_size ();
+if (m_child)
+  return m_child->get_req_size ();
+else
+  return canvas::size_t (0,0);
   }
   void update_child_alloc_rects () override
   {
-m_child->set_alloc_rect (get_alloc_rect ());
+if (m_child)
+  m_child->set_alloc_rect (get_alloc_rect ());
   }
   void paint_to_canvas (canvas &canvas) override
   {
-m_child->paint_to_canvas (canvas);
+if (m_child)
+  m_child->paint_to_canvas (canvas);
   }
  private:
   std::unique_ptr m_child;


[gcc r16-1269] diagnostics: introduce xml::doctypedecl to avoid hardcoding html

2025-06-06 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:d5050287acd28cbe23df527605449f514a659bba

commit r16-1269-gd5050287acd28cbe23df527605449f514a659bba
Author: David Malcolm 
Date:   Fri Jun 6 13:41:28 2025 -0400

diagnostics: introduce xml::doctypedecl to avoid hardcoding html

As further generalization of XML support during prototyping of new
features, don't hardcode the HTML DTD.

gcc/ChangeLog:
* diagnostic-format-html.cc (struct html_doctypedecl): New.
(html_builder::html_builder): Use it to populate the document's
m_doctypedecl.
* xml.cc (xml::document::write_as_xml): Replace hardcoded HTML DTD
with use of m_doctypedecl field.
(selftest::test_no_dtd): New.
(selftest::xml_cc_tests): New.
* xml.h (struct doctypedecl): New decl.

Signed-off-by: David Malcolm 

Diff:
---
 gcc/diagnostic-format-html.cc | 19 +++
 gcc/xml.cc| 19 ++-
 gcc/xml.h |  8 
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc
index 076790bfff7a..ea2dbbba9293 100644
--- a/gcc/diagnostic-format-html.cc
+++ b/gcc/diagnostic-format-html.cc
@@ -319,6 +319,24 @@ const char * const HTML_SCRIPT
  "  });\n"
  "  highlight_current_focus_idx ();\n");
 
+struct html_doctypedecl : public xml::doctypedecl
+{
+  void write_as_xml (pretty_printer *pp,
+int depth, bool indent) const final override
+  {
+if (indent)
+  {
+   for (int i = 0; i < depth; ++i)
+ pp_string (pp, "  ");
+  }
+pp_string (pp, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>");
+if (indent)
+  pp_newline (pp);
+  }
+};
+
 /* html_builder's ctor.  */
 
 html_builder::html_builder (diagnostic_context &context,
@@ -336,6 +354,7 @@ html_builder::html_builder (diagnostic_context &context,
   gcc_assert (m_line_maps);
 
   m_document = std::make_unique ();
+  m_document->m_doctypedecl = std::make_unique ();
   {
 auto html_element = std::make_unique ("html", false);
 html_element->set_attr ("xmlns",
diff --git a/gcc/xml.cc b/gcc/xml.cc
index e75884066f30..6c95288607de 100644
--- a/gcc/xml.cc
+++ b/gcc/xml.cc
@@ -128,11 +128,8 @@ void
 document::write_as_xml (pretty_printer *pp, int depth, bool indent) const
 {
   pp_string (pp, "\n");
-  pp_string (pp, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>");
-  if (indent)
-pp_newline (pp);
+  if (m_doctypedecl)
+m_doctypedecl->write_as_xml (pp, depth, indent);
   for (auto &iter : m_children)
 iter->write_as_xml (pp, depth, indent);
 }
@@ -283,6 +280,17 @@ printer::get_insertion_point () const
 
 namespace selftest {
 
+static void
+test_no_dtd ()
+{
+  xml::document doc;
+  pretty_printer pp;
+  doc.write_as_xml (&pp, 0, true);
+  ASSERT_STREQ
+(pp_formatted_text (&pp),
+ "\n");
+}
+
 static void
 test_printer ()
 {
@@ -349,6 +357,7 @@ test_attribute_ordering ()
 void
 xml_cc_tests ()
 {
+  test_no_dtd ();
   test_printer ();
   test_attribute_ordering ();
 }
diff --git a/gcc/xml.h b/gcc/xml.h
index 523a44dd146f..3c5813a22862 100644
--- a/gcc/xml.h
+++ b/gcc/xml.h
@@ -29,6 +29,7 @@ struct node;
   struct node_with_children;
 struct document;
 struct element;
+  struct doctypedecl;
 
 struct node
 {
@@ -72,6 +73,13 @@ struct document : public node_with_children
 {
   void write_as_xml (pretty_printer *pp,
 int depth, bool indent) const final override;
+
+  std::unique_ptr m_doctypedecl;
+};
+
+struct doctypedecl : public node
+{
+  // still abstract
 };
 
 struct element : public node_with_children


[gcc r16-1271] libstdc++: Add more tests for semaphores

2025-06-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:37fe7e7069c2bb999c95a9807a8f895f38b9cacf

commit r16-1271-g37fe7e7069c2bb999c95a9807a8f895f38b9cacf
Author: Jonathan Wakely 
Date:   Fri Jun 6 17:18:40 2025 +0100

libstdc++: Add more tests for semaphores

libstdc++-v3/ChangeLog:

* testsuite/30_threads/semaphore/1.cc: Check type properties and
max() values.
* testsuite/30_threads/semaphore/3.cc: New test.
* testsuite/30_threads/semaphore/cons_neg.cc: New test.

Diff:
---
 libstdc++-v3/testsuite/30_threads/semaphore/1.cc   | 22 ++
 libstdc++-v3/testsuite/30_threads/semaphore/3.cc   | 19 +++
 .../testsuite/30_threads/semaphore/cons_neg.cc | 12 
 3 files changed, 53 insertions(+)

diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/1.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/1.cc
index cc6befcc1a50..9472def4cba1 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/1.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/1.cc
@@ -27,3 +27,25 @@
 #elif __cpp_lib_semaphore != 201907L
 # error "Feature-test macro for semaphore has wrong value in "
 #endif
+
+static_assert(std::is_same_v,
+std::binary_semaphore>);
+
+static_assert(! std::is_same_v,
+  std::binary_semaphore>);
+
+static_assert(! std::is_same_v,
+  std::binary_semaphore>);
+
+// The standard permits max() to be greater than the template argument,
+// but for the current libstdc++ implementation it's always equal to it.
+static_assert(std::binary_semaphore::max() == 1);
+static_assert(std::counting_semaphore<0>::max() == 0);
+static_assert(std::counting_semaphore<2>::max() == 2);
+
+#include 
+
+static_assert(std::counting_semaphore::max() == INT_MAX);
+static_assert(std::counting_semaphore::max() == INT_MAX-1);
+static_assert(std::counting_semaphore::max() == PTRDIFF_MAX);
+static_assert(std::counting_semaphore::max() == PTRDIFF_MAX-3);
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/3.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/3.cc
new file mode 100644
index ..51b9fbb0e4bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/3.cc
@@ -0,0 +1,19 @@
+// { dg-do compile { target *-*-*linux* } }
+// { dg-require-effective-target c++20 }
+// { dg-require-effective-target hosted }
+
+#include 
+#include 
+
+// on Linux these specializations all use a futex:
+static_assert(sizeof(std::counting_semaphore<0>) == sizeof(int));
+static_assert(sizeof(std::counting_semaphore<1>) == sizeof(int));
+static_assert(sizeof(std::counting_semaphore) == sizeof(int));
+static_assert(sizeof(std::counting_semaphore<>) == sizeof(int));
+
+// This will use a futex iff ptrdiff_t has 32 bits:
+static_assert(sizeof(std::counting_semaphore) == 
sizeof(std::ptrdiff_t));
+
+#if PTRDIFF_MAX > INT_MAX
+static_assert(sizeof(std::counting_semaphore) == 
sizeof(std::ptrdiff_t));
+#endif
diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/cons_neg.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/cons_neg.cc
new file mode 100644
index ..56e27d7ddc4c
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/cons_neg.cc
@@ -0,0 +1,12 @@
+// { dg-options "-D_GLIBCXX_ASSERTIONS" }
+// { dg-do run { target c++20 xfail *-*-* } }
+// { dg-require-effective-target hosted }
+// { dg-add-options libatomic }
+
+#include 
+
+int main()
+{
+  // Preconditions: desired >= 0 is true, and desired <= max() is true.
+  std::binary_semaphore b(2);
+}


[gcc r16-1270] libstdc++: Use std::conditional_t instead of lambda to select semaphore implementation

2025-06-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:7407891a3d7c177212c6027c1dee08bed09b

commit r16-1270-g7407891a3d7c177212c6027c1dee08bed09b
Author: Jonathan Wakely 
Date:   Fri Jun 6 14:16:15 2025 +0100

libstdc++: Use std::conditional_t instead of lambda to select semaphore 
implementation

The lambda expression causes testsuite failures such as:
FAIL g++.dg/modules/xtreme-header-2_b.C -std=c++26 (test for excess errors)

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h (_Select_semaphore_impl): Rename
to _Semaphore_impl and use std::conditional_t instead of an
immediately invoked lambda expression.
* include/std/semaphore (counting_semaphore): Adjust to use new
name.

Diff:
---
 libstdc++-v3/include/bits/semaphore_base.h | 22 ++
 libstdc++-v3/include/std/semaphore |  4 ++--
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/include/bits/semaphore_base.h 
b/libstdc++-v3/include/bits/semaphore_base.h
index ebbc9a80b91a..82871ce3518b 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -289,22 +289,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 alignas(__detail::__platform_wait_alignment) __count_type _M_counter;
   };
 
-  template
-using _Select_semaphore_impl = typename decltype([]
-{
-  using namespace __detail;
-  if constexpr (__platform_wait_uses_type<__platform_wait_t>)
-   {
- if constexpr (_Max <= 1)
-   return type_identity<__platform_semaphore_impl>{};
- else if constexpr (_Max <= __platform_semaphore_impl::_S_max)
-   return type_identity<__platform_semaphore_impl>{};
- else
-   return type_identity<__semaphore_impl>{};
-   }
-  else
-   return type_identity<__semaphore_impl>{};
-}())::type;
+  template
+using _Semaphore_impl
+  = __conditional_t<__platform_wait_uses_type<_Tp>
+ && _Max <= __gnu_cxx::__int_traits<_Tp>::__max,
+   __platform_semaphore_impl<(_Max <= 1)>,
+   __semaphore_impl>;
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
diff --git a/libstdc++-v3/include/std/semaphore 
b/libstdc++-v3/include/std/semaphore
index 8f49188563e8..18d04075776c 100644
--- a/libstdc++-v3/include/std/semaphore
+++ b/libstdc++-v3/include/std/semaphore
@@ -45,12 +45,12 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  template::_S_max>
+  template::_S_max>
 class counting_semaphore
 {
   static_assert(__least_max_value >= 0);
 
-  _Select_semaphore_impl<__least_max_value> _M_sem;
+  _Semaphore_impl<__least_max_value> _M_sem;
 
 public:
   constexpr explicit


[gcc r16-1272] c++: recursive template with deduced return [PR120555]

2025-06-06 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:8d204f2a536f7253e4251aca7bc12af524800b4c

commit r16-1272-g8d204f2a536f7253e4251aca7bc12af524800b4c
Author: Jason Merrill 
Date:   Fri Jun 6 10:26:28 2025 -0400

c++: recursive template with deduced return [PR120555]

Here since r15-4120 we were prematurely complaining about the use of func
within its own definiton, which is fine at instantiation time.  So don't
require this for function templates that are currently being defined.

But keep the error for instantiations of templates that are not currently
being defined, which we similarly did not diagnose before r15-4120 but other
implementations do.

Both of these follow the general principle from [temp.res.general]/6 that we
only error in a template body if no instatiation could be well-formed.

Also remove a redundant call to require_deduced_type.

PR c++/120555

gcc/cp/ChangeLog:

* decl2.cc (fn_being_defined, fn_template_being_defined): New.
(mark_used): Check fn_template_being_defined.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-if39.C: New test.

Diff:
---
 gcc/cp/decl2.cc | 33 ++---
 gcc/testsuite/g++.dg/cpp1z/constexpr-if39.C | 30 ++
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index e3fbc4093929..2bbc6180b0b9 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -6269,6 +6269,33 @@ mark_single_function (tree expr, tsubst_flags_t complain)
   return true;
 }
 
+/* True iff we have started, but not finished, defining FUNCTION_DECL DECL.  */
+
+bool
+fn_being_defined (tree decl)
+{
+  /* DECL_INITIAL is set to error_mark_node in grokfndecl for a definition, and
+ changed to BLOCK by poplevel at the end of the function.  */
+  return (TREE_CODE (decl) == FUNCTION_DECL
+ && DECL_INITIAL (decl) == error_mark_node);
+}
+
+/* True if DECL is an instantiation of a function template currently being
+   defined.  */
+
+bool
+fn_template_being_defined (tree decl)
+{
+  if (TREE_CODE (decl) != FUNCTION_DECL
+  || !DECL_LANG_SPECIFIC (decl)
+  || !DECL_TEMPLOID_INSTANTIATION (decl)
+  || DECL_TEMPLATE_INSTANTIATED (decl))
+return false;
+  tree tinfo = DECL_TEMPLATE_INFO (decl);
+  tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
+  return fn_being_defined (pattern);
+}
+
 /* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
If DECL is a specialization or implicitly declared class member,
generate the actual definition.  Return false if something goes
@@ -6422,6 +6449,9 @@ mark_used (tree decl, tsubst_flags_t complain /* = 
tf_warning_or_error */)
 maybe_instantiate_decl (decl);
 
   if (!decl_dependent_p (decl)
+  /* Don't require this yet for an instantiation of a function template
+we're currently defining (c++/120555).  */
+  && !fn_template_being_defined (decl)
   && !require_deduced_type (decl, complain))
 return false;
 
@@ -6436,9 +6466,6 @@ mark_used (tree decl, tsubst_flags_t complain /* = 
tf_warning_or_error */)
   && uses_template_parms (DECL_TI_ARGS (decl)))
 return true;
 
-  if (!require_deduced_type (decl, complain))
-return false;
-
   if (builtin_pack_fn_p (decl))
 {
   error ("use of built-in parameter pack %qD outside of a template",
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if39.C 
b/gcc/testsuite/g++.dg/cpp1z/constexpr-if39.C
new file mode 100644
index ..38ae7a0c0e10
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if39.C
@@ -0,0 +1,30 @@
+// PR c++/120555
+// { dg-do compile { target c++17 } }
+
+struct A { int m; };
+
+template
+constexpr auto f() {
+  if constexpr (sizeof(T) == sizeof(int))
+return 1;
+  else
+return A{f()};
+}
+
+static_assert(f().m == 1);
+static_assert(f() == 1);
+
+template  constexpr auto g();
+
+template
+constexpr auto f2() {
+  if constexpr (sizeof(T) == sizeof(int))
+return 1;
+  else
+return A{g()};// { dg-error "auto" }
+}
+
+template  constexpr auto g() { return A{1}; }
+
+static_assert(f2().m == 1);
+static_assert(f2() == 1);


[gcc r16-1201] tree-optimization/120032 - matching of table based CLZ

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:c6eb92973ea308e248ce23927a9ac58ef81ee7a2

commit r16-1201-gc6eb92973ea308e248ce23927a9ac58ef81ee7a2
Author: Richard Biener 
Date:   Wed May 28 15:09:19 2025 +0200

tree-optimization/120032 - matching of table based CLZ

The following adds the ability to match a table based CLZ implementation
similar as to how we can do for CTZ.  I'm re-using the workers for
matching up array and string tables by using a lambda and templates
and kept the transform step for CLZ/CTZ inter-mangled.

PR tree-optimization/120032
* match.pd (clz_table_index): New match.
* tree-ssa-forwprop.cc (check_table_array): Rename from
check_ctz_array.  Split out actual verification to a functor.
(check_table_string): Rename from check_ctz_string and likewise.
(check_table): Rename from check_ctz_table and adjust.
(gimple_clz_table_index): Declare.
(simplify_count_zeroes): Rename from simplify_count_trailing_zeroes.
Extend to cover CLZ.
(pass_forwprop::execute): Adjust.

* gcc.target/i386/pr120032-1.c: New testcase.
* gcc.target/i386/pr120032-2.c: Likewise.

Diff:
---
 gcc/match.pd   |  48 +++-
 gcc/testsuite/gcc.target/i386/pr120032-1.c |  22 ++
 gcc/testsuite/gcc.target/i386/pr120032-2.c |  22 ++
 gcc/tree-ssa-forwprop.cc   | 121 +
 4 files changed, 181 insertions(+), 32 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 656572423aa7..0f53c162fce3 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -11339,7 +11339,7 @@ and,
  (vec_perm @2 @5 { op0; })))
 
 
-/* Match count trailing zeroes for simplify_count_trailing_zeroes in fwprop.
+/* Match count trailing zeroes for simplify_count_zeroes in forwprop.
The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic
constant which when multiplied by a power of 2 contains a unique value
in the top 5 or 6 bits.  This is then indexed into a table which maps it
@@ -11347,6 +11347,52 @@ and,
 (match (ctz_table_index @1 @2 @3)
   (rshift (mult (bit_and:c (negate @1) @1) INTEGER_CST@2) INTEGER_CST@3))
 
+/* Match count leading zeros for simplify_count_zeroes in forwprop.
+   One canonical form is 31 - array[idx] where IDX is computed from X
+   by first setting all bits from the topmost set bits down via a
+   series of shifts and ors to X' and then computing (X' * C) >> SHIFT.  */
+(match (clz_table_index @1 @2 @3)
+  (rshift (mult
+   (bit_ior (rshift
+ (bit_ior@d (rshift
+   (bit_ior@c (rshift
+ (bit_ior@b (rshift
+  (bit_ior@a (rshift @1 INTEGER_CST@c1) @1)
+  INTEGER_CST@c2) @a)
+INTEGER_CST@c4) @b)
+   INTEGER_CST@c8) @c)
+ INTEGER_CST@c16) @d) INTEGER_CST@2) INTEGER_CST@3)
+  (if (INTEGRAL_TYPE_P (type)
+   && TYPE_UNSIGNED (type)
+   && TYPE_PRECISION (type) == 32
+   && compare_tree_int (@c1, 1) == 0
+   && compare_tree_int (@c2, 2) == 0
+   && compare_tree_int (@c4, 4) == 0
+   && compare_tree_int (@c8, 8) == 0
+   && compare_tree_int (@c16, 16) == 0)))
+(match (clz_table_index @1 @2 @3)
+  (rshift (mult
+   (bit_ior (rshift
+ (bit_ior@e (rshift
+   (bit_ior@d (rshift
+ (bit_ior@c (rshift
+   (bit_ior@b (rshift
+(bit_ior@a (rshift @1 INTEGER_CST@c1) @1)
+INTEGER_CST@c2) @a)
+  INTEGER_CST@c4) @b)
+ INTEGER_CST@c8) @c)
+   INTEGER_CST@c16) @d)
+ INTEGER_CST@c32) @e) INTEGER_CST@2) INTEGER_CST@3)
+  (if (INTEGRAL_TYPE_P (type)
+   && TYPE_UNSIGNED (type)
+   && TYPE_PRECISION (type) == 64
+   && compare_tree_int (@c1, 1) == 0
+   && compare_tree_int (@c2, 2) == 0
+   && compare_tree_int (@c4, 4) == 0
+   && compare_tree_int (@c8, 8) == 0
+   && compare_tree_int (@c16, 16) == 0
+   && compare_tree_int (@c32, 32) == 0)))
+
 /* Floatint point/integer comparison and integer->integer
or floating point -> float point conversion.  */
 (match (cond_expr_convert_p @0 @2 @3 @6)
diff --git a/gcc/testsuite/gcc.target/i386/pr120032-1.c 
b/gcc/testsuite/gcc.target/i386/pr120032-1.c
new file mode 100644
index ..c51512492b6f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr120032-1.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlzcnt" } */
+
+unsigned int
+ZSTD_countLeadingZeros32_fallback(unsigned int val)
+{
+  static const unsigned int DeBruijnClz[32]
+= { 0, 9, 1, 10, 13, 21, 2, 29,
+   11, 14, 16, 18, 22, 25, 3, 30,
+   8, 12, 20, 28, 15, 17, 24, 7,
+   19, 27, 23, 6, 26, 5, 4, 31};
+  if (val == 0)
+__builtin_abort ();
+  val |= val >> 1;
+  val |= val >> 2;
+  val |= val >> 4;
+  val |= val >> 8;
+  val |= val >> 16;
+  return 31 - DeBruijnClz[(val * 0x07C4ACDDU) >> 27];
+}
+
+/* { dg-final { scan-assembler "lzcnt" } } */
diff --git a/gcc/

[gcc r16-1200] Use ranger for table based CTZ detection

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:10adbc54a5e1fd89eb69ce1bced4c74b7047fd24

commit r16-1200-g10adbc54a5e1fd89eb69ce1bced4c74b7047fd24
Author: Richard Biener 
Date:   Wed May 28 15:26:48 2025 +0200

Use ranger for table based CTZ detection

The following uses context sensitive ranger for determining whether
the input to the table based CTZ is ever zero.

* tree-ssa-forwprop.cc (simplify_count_trailing_zeroes):
Use ranger instead of tree_expr_nonzero_p.

Diff:
---
 gcc/tree-ssa-forwprop.cc | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 4ef75ba98bd1..a60862a4b1a9 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2667,7 +2667,12 @@ simplify_count_trailing_zeroes (gimple_stmt_iterator 
*gsi)
   int nargs = 2;
 
   /* If the input value can't be zero, don't special case ctz (0).  */
-  if (tree_expr_nonzero_p (res_ops[0]))
+  range_query *q = get_range_query (cfun);
+  if (q == get_global_range_query ())
+q = enable_ranger (cfun);
+  int_range_max vr;
+  if (q->range_of_expr (vr, res_ops[0], stmt)
+  && !range_includes_zero_p (vr))
 {
   zero_ok = true;
   zero_val = 0;


[gcc r16-1202] tree-optimization/120032 - CLZ matching, fallback for missing range-info

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:4a80eaefd93c2f1f7c9b71dbc1b97783214b7b2f

commit r16-1202-g4a80eaefd93c2f1f7c9b71dbc1b97783214b7b2f
Author: Richard Biener 
Date:   Thu Jun 5 14:23:06 2025 +0200

tree-optimization/120032 - CLZ matching, fallback for missing range-info

The following allows us to emit a conditional move when the value
of the table based CLZ/CLZ implementation at zero differs from what
the target implementation guarantees or we cannot easily fixup
otherwise.  In that case emit a val == 0 ? table-based-zero-result : ...

PR tree-optimization/120032
* tree-ssa-forwprop.cc (simplify_count_zeroes): When we cannot use
the IFN to determine the result at zero use a conditional move
to reproduce the correct result from the table-based
algorithm.

* gcc.target/i386/pr120032-3.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.target/i386/pr120032-3.c | 20 
 gcc/tree-ssa-forwprop.cc   | 27 +++
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/gcc/testsuite/gcc.target/i386/pr120032-3.c 
b/gcc/testsuite/gcc.target/i386/pr120032-3.c
new file mode 100644
index ..9523bbb0f5b5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr120032-3.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlzcnt" } */
+
+unsigned int
+ZSTD_countLeadingZeros32_fallback(unsigned int val)
+{
+  static const unsigned int DeBruijnClz[32]
+= { 0, 9, 1, 10, 13, 21, 2, 29,
+   11, 14, 16, 18, 22, 25, 3, 30,
+   8, 12, 20, 28, 15, 17, 24, 7,
+   19, 27, 23, 6, 26, 5, 4, 31};
+  val |= val >> 1;
+  val |= val >> 2;
+  val |= val >> 4;
+  val |= val >> 8;
+  val |= val >> 16;
+  return 31 - DeBruijnClz[(val * 0x07C4ACDDU) >> 27];
+}
+
+/* { dg-final { scan-assembler "lzcnt" } } */
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 0c2b10e92aa4..43b1c9d696fd 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2728,13 +2728,6 @@ simplify_count_zeroes (gimple_stmt_iterator *gsi)
   nargs = 1;
 }
 
-  /* Skip if there is no value defined at zero, or if we can't easily
- return the correct value for zero.  */
-  if (!zero_ok)
-return false;
-  if (zero_val != ctz_val && !(zero_val == 0 && ctz_val == input_bits))
-return false;
-
   gimple_seq seq = NULL;
   gimple *g;
   gcall *call = gimple_build_call_internal (fn, nargs, res_ops[0],
@@ -2758,8 +2751,10 @@ simplify_count_zeroes (gimple_stmt_iterator *gsi)
   prev_lhs = gimple_assign_lhs (g);
 }
 
+  if (zero_ok && zero_val == ctz_val)
+;
   /* Emit ctz (x) & 31 if ctz (0) is 32 but we need to return 0.  */
-  if (zero_val == 0 && ctz_val == input_bits)
+  else if (zero_ok && zero_val == 0 && ctz_val == input_bits)
 {
   g = gimple_build_assign (make_ssa_name (integer_type_node),
   BIT_AND_EXPR, prev_lhs,
@@ -2769,6 +2764,22 @@ simplify_count_zeroes (gimple_stmt_iterator *gsi)
   gimple_seq_add_stmt (&seq, g);
   prev_lhs = gimple_assign_lhs (g);
 }
+  /* As fallback emit a conditional move.  */
+  else
+{
+  g = gimple_build_assign (make_ssa_name (boolean_type_node), EQ_EXPR,
+  res_ops[0], build_zero_cst (input_type));
+  gimple_set_location (g, gimple_location (stmt));
+  gimple_seq_add_stmt (&seq, g);
+  tree cond = gimple_assign_lhs (g);
+  g = gimple_build_assign (make_ssa_name (integer_type_node),
+  COND_EXPR, cond,
+  build_int_cst (integer_type_node, zero_val),
+  prev_lhs);
+  gimple_set_location (g, gimple_location (stmt));
+  gimple_seq_add_stmt (&seq, g);
+  prev_lhs = gimple_assign_lhs (g);
+}
 
   g = gimple_build_assign (gimple_assign_lhs (stmt), NOP_EXPR, prev_lhs);
   gimple_seq_add_stmt (&seq, g);


[gcc r16-1203] RISC-V: Support -mcpu for XiangShan Kunminghu cpu.

2025-06-06 Thread Jiawei Chen via Gcc-cvs
https://gcc.gnu.org/g:f0cd40f71ba424bde94dcddbf1df67bb100b82ef

commit r16-1203-gf0cd40f71ba424bde94dcddbf1df67bb100b82ef
Author: Jiawei 
Date:   Wed Jun 4 17:56:49 2025 +0800

RISC-V: Support -mcpu for XiangShan Kunminghu cpu.

This patch adds support for the XiangShan Kunminghu CPU in GCC, allowing
the use of the `-mcpu=xiangshan-kunminghu` option.

XiangShan-KunMingHu is the third-generation open-source high-performance
RISC-V processor.[1] You can find the corresponding ISA extension from the
XiangShan Github repository.[2] The latest news of KunMingHu can be found
in the XiangShan Biweekly.[3]

[1] https://github.com/OpenXiangShan/XiangShan-User-Guide/releases.
[2] 
https://github.com/OpenXiangShan/XiangShan/blob/master/src/main/scala/xiangshan/Parameters.scala
[3] https://docs.xiangshan.cc/zh-cn/latest/blog

A dedicated scheduling model for KunMingHu's hybrid pipeline will be
proposed in a subsequent PR.

gcc/ChangeLog:

* config/riscv/riscv-cores.def (RISCV_TUNE): New cpu tune.
(RISCV_CORE): New cpu.
* doc/invoke.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/mcpu-xiangshan-kunminghu.c: New test.

Co-Authored-By: Jiawei Chen 
Co-Authored-By: Yangyu Chen 
Co-Authored-By: Tang Haojin 

Diff:
---
 gcc/config/riscv/riscv-cores.def   | 14 
 gcc/doc/invoke.texi|  4 +-
 .../gcc.target/riscv/mcpu-xiangshan-kunminghu.c| 95 ++
 3 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv-cores.def b/gcc/config/riscv/riscv-cores.def
index 118fef23cad4..cff7c77a0bd7 100644
--- a/gcc/config/riscv/riscv-cores.def
+++ b/gcc/config/riscv/riscv-cores.def
@@ -48,6 +48,7 @@ RISCV_TUNE("xt-c910v2", generic, generic_ooo_tune_info)
 RISCV_TUNE("xt-c920", generic, generic_ooo_tune_info)
 RISCV_TUNE("xt-c920v2", generic, generic_ooo_tune_info)
 RISCV_TUNE("xiangshan-nanhu", xiangshan, xiangshan_nanhu_tune_info)
+RISCV_TUNE("xiangshan-kunminghu", xiangshan, generic_ooo_tune_info)
 RISCV_TUNE("generic-ooo", generic_ooo, generic_ooo_tune_info)
 RISCV_TUNE("size", generic, optimize_size_tune_info)
 RISCV_TUNE("mips-p8700", mips_p8700, mips_p8700_tune_info)
@@ -154,6 +155,19 @@ RISCV_CORE("xiangshan-nanhu",  
"rv64imafdc_zba_zbb_zbc_zbs_"
  "svinval_zicbom_zicboz",
  "xiangshan-nanhu")
 
+RISCV_CORE("xiangshan-kunminghu",   "rv64imafdcbvh_sdtrig_sha_shcounterenw_"
+ 
"shgatpa_shlcofideleg_shtvala_shvsatpa_shvstvala_shvstvecd_"
+ 
"smaia_smcsrind_smdbltrp_smmpm_smnpm_smrnmi_smstateen_"
+ 
"ssaia_ssccptr_sscofpmf_sscounterenw_sscsrind_ssdbltrp_"
+ 
"ssnpm_sspm_ssstateen_ssstrict_sstc_sstvala_sstvecd_"
+ 
"ssu64xl_supm_svade_svbare_svinval_svnapot_svpbmt_za64rs_"
+ 
"zacas_zawrs_zba_zbb_zbc_zbkb_zbkc_zbkx_zbs_zcb_zcmop_"
+ 
"zfa_zfh_zfhmin_zic64b_zicbom_zicbop_zicboz_ziccif_"
+ 
"zicclsm_ziccrse_zicntr_zicond_zicsr_zifencei_zihintpause_"
+ 
"zihpm_zimop_zkn_zknd_zkne_zknh_zksed_zksh_zkt_zvbb_zvfh_"
+ "zvfhmin_zvkt_zvl128b_zvl32b_zvl64b",
+ "xiangshan-kunminghu")
+
 RISCV_CORE("mips-p8700",   "rv64imafd_zicsr_zmmul_"
  "zaamo_zalrsc_zba_zbb",
  "mips-p8700")
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index f943d3a70aa7..d7f51b4f6d93 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -31200,8 +31200,8 @@ Permissible values for this option are: 
@samp{mips-p8700}, @samp{sifive-e20},
 @samp{sifive-e76}, @samp{sifive-s21}, @samp{sifive-s51}, @samp{sifive-s54},
 @samp{sifive-s76}, @samp{sifive-u54}, @samp{sifive-u74}, @samp{sifive-x280},
 @samp{sifive-xp450}, @samp{sifive-x670}, @samp{thead-c906}, 
@samp{tt-ascalon-d8},
-@samp{xiangshan-nanhu}, @samp{xt-c908}, @samp{xt-c908v}, @samp{xt-c910}, 
@samp{xt-c910v2},
-@samp{xt-c920}, @samp{xt-c920v2}.
+@samp{xiangshan-nanhu}, @samp{xiangshan-kunminghu}, @samp{xt-c908}, 
@samp{xt-c908v},
+@samp{xt-c910}, @samp{xt-c910v2}, @samp{xt-c920}, @samp{xt-c920v2}.
 
 Note that @option{-mcpu} does not override @option{-march} or @option{-mtune}.
 
diff --git a/gcc/testsuite/gcc.target/riscv/mcpu-xiangshan-kunminghu.c 
b/gcc/testsuite/gcc.target/riscv/mcpu-xiangshan-kunminghu.c
new file mode 100644
index ..e3ae65c46444
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/mcpu-xiangshan-kunminghu.c
@@ -0,0 +1,95 @@
+/* { dg-do compile { target { rv64 } } } */
+/* { dg-skip-if "-march given" { *-*-* } { "-march=*" } } */
+/* { dg-options "-mcpu=xiangshan-kunminghu" } */
+/* XiangShan Kunmingh

[gcc r16-1199] Refactor CTZ detection in forwprop

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:63a8128218cc421b4294f9b8b139197a985ce375

commit r16-1199-g63a8128218cc421b4294f9b8b139197a985ce375
Author: Richard Biener 
Date:   Wed May 28 14:13:00 2025 +0200

Refactor CTZ detection in forwprop

The following refactors the CTZ detection code to be more easily
extensible to also handle CLZ.

* tree-ssa-forwprop.cc (optimize_count_trailing_zeroes):
Inline into ...
(simplify_count_trailing_zeroes): ... this function.
Split out ...
(check_ctz_table): ... a wrapper for CONSTRUCTOR vs. STRING_CST
handling.

Diff:
---
 gcc/tree-ssa-forwprop.cc | 161 ++-
 1 file changed, 74 insertions(+), 87 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 27197bbc0769..4ef75ba98bd1 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2592,6 +2592,22 @@ check_ctz_string (tree string, unsigned HOST_WIDE_INT 
mulc,
   return matched == bits;
 }
 
+/* Check whether CTOR contains a valid ctz table.  */
+static bool
+check_ctz_table (tree ctor, tree type, unsigned HOST_WIDE_INT mulc,
+HOST_WIDE_INT &zero_val, unsigned shift, unsigned bits)
+{
+  if (TREE_CODE (ctor) == CONSTRUCTOR)
+return check_ctz_array (ctor, mulc, zero_val, shift, bits);
+  else if (TREE_CODE (ctor) == STRING_CST
+  && TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
+return check_ctz_string (ctor, mulc, zero_val, shift, bits);
+  return false;
+}
+
+/* Match.pd function to match the ctz expression.  */
+extern bool gimple_ctz_table_index (tree, tree *, tree (*)(tree));
+
 /* Recognize count trailing zeroes idiom.
The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic
constant which when multiplied by a power of 2 creates a unique value
@@ -2599,17 +2615,23 @@ check_ctz_string (tree string, unsigned HOST_WIDE_INT 
mulc,
to the number of trailing zeroes.  Array[0] is returned so the caller can
emit an appropriate sequence depending on whether ctz (0) is defined on
the target.  */
+
 static bool
-optimize_count_trailing_zeroes (tree array_ref, tree x, tree mulc,
-   tree tshift, HOST_WIDE_INT &zero_val)
+simplify_count_trailing_zeroes (gimple_stmt_iterator *gsi)
 {
-  tree type = TREE_TYPE (array_ref);
-  tree array = TREE_OPERAND (array_ref, 0);
+  gimple *stmt = gsi_stmt (*gsi);
+  tree array_ref = gimple_assign_rhs1 (stmt);
+  tree res_ops[3];
+
+  gcc_checking_assert (TREE_CODE (array_ref) == ARRAY_REF);
 
-  gcc_assert (TREE_CODE (mulc) == INTEGER_CST);
-  gcc_assert (TREE_CODE (tshift) == INTEGER_CST);
+  if (!gimple_ctz_table_index (TREE_OPERAND (array_ref, 1), &res_ops[0], NULL))
+return false;
 
-  tree input_type = TREE_TYPE (x);
+  HOST_WIDE_INT zero_val;
+  tree type = TREE_TYPE (array_ref);
+  tree array = TREE_OPERAND (array_ref, 0);
+  tree input_type = TREE_TYPE (res_ops[0]);
   unsigned input_bits = tree_to_shwi (TYPE_SIZE (input_type));
 
   /* Check the array element type is not wider than 32 bits and the input is
@@ -2627,102 +2649,67 @@ optimize_count_trailing_zeroes (tree array_ref, tree 
x, tree mulc,
   if (!low || !integer_zerop (low))
 return false;
 
-  unsigned shiftval = tree_to_shwi (tshift);
-
   /* Check the shift extracts the top 5..7 bits.  */
+  unsigned shiftval = tree_to_shwi (res_ops[2]);
   if (shiftval < input_bits - 7 || shiftval > input_bits - 5)
 return false;
 
   tree ctor = ctor_for_folding (array);
   if (!ctor)
 return false;
+  unsigned HOST_WIDE_INT val = tree_to_uhwi (res_ops[1]);
+  if (!check_ctz_table (ctor, type, val, zero_val, shiftval, input_bits))
+return false;
 
-  unsigned HOST_WIDE_INT val = tree_to_uhwi (mulc);
-
-  if (TREE_CODE (ctor) == CONSTRUCTOR)
-return check_ctz_array (ctor, val, zero_val, shiftval, input_bits);
-
-  if (TREE_CODE (ctor) == STRING_CST
-  && TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
-return check_ctz_string (ctor, val, zero_val, shiftval, input_bits);
-
-  return false;
-}
-
-/* Match.pd function to match the ctz expression.  */
-extern bool gimple_ctz_table_index (tree, tree *, tree (*)(tree));
+  HOST_WIDE_INT ctz_val = 0;
+  bool zero_ok = CTZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (input_type),
+   ctz_val) == 2;
+  int nargs = 2;
 
-static bool
-simplify_count_trailing_zeroes (gimple_stmt_iterator *gsi)
-{
-  gimple *stmt = gsi_stmt (*gsi);
-  tree array_ref = gimple_assign_rhs1 (stmt);
-  tree res_ops[3];
-  HOST_WIDE_INT zero_val;
-
-  gcc_checking_assert (TREE_CODE (array_ref) == ARRAY_REF);
+  /* If the input value can't be zero, don't special case ctz (0).  */
+  if (tree_expr_nonzero_p (res_ops[0]))
+{
+  zero_ok = true;
+  zero_val = 0;
+  ctz_val = 0;
+  nargs = 1;
+}
 
-  if (!gimple_ctz_table_index (TREE_OPERAND (array_ref, 1), &res_ops[0], NULL))
+  /* Skip if there

[gcc r16-1249] Avoid useless reading of profile data in LTO

2025-06-06 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:572dd0dd8db4bec69883c0b3e53013a7842e886e

commit r16-1249-g572dd0dd8db4bec69883c0b3e53013a7842e886e
Author: Jan Hubicka 
Date:   Fri Jun 6 10:56:51 2025 +0200

Avoid useless reading of profile data in LTO

New auto-profile merging dumps made me notice that we read the afdo
data when we are in LTO.  This is not necessary since profile is read
at compile time and streamed to LTO bytecode.

gcc/ChangeLog:

* coverage.cc (coverage_init): Return early when in LTO

Diff:
---
 gcc/coverage.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/coverage.cc b/gcc/coverage.cc
index 7181e7573594..c0ae76a40ef1 100644
--- a/gcc/coverage.cc
+++ b/gcc/coverage.cc
@@ -1253,6 +1253,9 @@ coverage_obj_finish (vec *ctor,
 void
 coverage_init (const char *filename)
 {
+  /* If we are in LTO, the profile will be read from object files.  */
+  if (in_lto_p)
+return;
   const char *original_filename = filename;
   int original_len = strlen (original_filename);
 #if HAVE_DOS_BASED_FILE_SYSTEM


[gcc r16-1239] ada: Check references to subprogram outputs with Program_Exit expression

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:9eb8ae16868418855ac81d86f6584057bc852aec

commit r16-1239-g9eb8ae16868418855ac81d86f6584057bc852aec
Author: Piotr Trojanek 
Date:   Wed Feb 26 14:02:15 2025 +0100

ada: Check references to subprogram outputs with Program_Exit expression

Add check for references to subprogram outputs occurring within the
Program_Exit expression. This check is necessarily partial, as it misses
objects referenced by subprograms called from the Program_Exit expression,
but this is consistent with other checks.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Add dependency of Program_Exit on
Global and Depends contracts.
(Analyze_Program_Exit_In_Decl_Part): Check references to subprogram
outputs.

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

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 706812313296..b94606eabc71 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -23717,6 +23717,8 @@ package body Sem_Prag is
 
Analyze_If_Present (Pragma_SPARK_Mode);
Analyze_If_Present (Pragma_Volatile_Function);
+   Analyze_If_Present (Pragma_Global);
+   Analyze_If_Present (Pragma_Depends);
Analyze_Program_Exit_In_Decl_Part (N);
 end if;
  end Program_Exit;
@@ -28425,6 +28427,46 @@ package body Sem_Prag is
 
   Errors: Nat;
   Restore_Scope : Boolean := False;
+  Unused: Boolean;
+
+  Subp_Inputs, Subp_Outputs : Elist_Id := No_Elist;
+  --  Inputs and outputs of the subprogram
+
+  function Check_Reference (N : Node_Id) return Traverse_Result;
+  --  Check references to objects within the Program_Exit expression
+
+  -
+  -- Check_Reference --
+  -
+
+  function Check_Reference (N : Node_Id) return Traverse_Result is
+  begin
+  --  If an output of a subprogram with side effects is mentioned
+  --  in the boolean expression of its aspect Program_Exit, then it
+  --  shall either occur inside the prefix of a reference to the Old
+  --  attribute or be a stand-alone object.
+
+ if Is_Attribute_Old (N) then
+return Skip;
+ end if;
+
+ if Is_Entity_Name (N) then
+declare
+   E : constant Entity_Id := Entity (N);
+begin
+   if Appears_In (Subp_Outputs, E)
+ and then Ekind (E) not in E_Constant | E_Variable
+   then
+  Error_Msg_NE
+("reference to subprogram output & in Program_Exit", N, E);
+   end if;
+end;
+ end if;
+
+ return OK;
+  end Check_Reference;
+
+  procedure Check_Exit_References is new Traverse_Proc (Check_Reference);
 
--  Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
 
@@ -28475,6 +28517,15 @@ package body Sem_Prag is
  Preanalyze_And_Resolve_Assert_Expression
(Expression (Arg1), Any_Boolean);
 
+ Collect_Subprogram_Inputs_Outputs
+   (Spec_Id,
+Synthesize   => True,
+Subp_Inputs  => Subp_Inputs,
+Subp_Outputs => Subp_Outputs,
+Global_Seen  => Unused);
+
+ Check_Exit_References (Expression (Arg1));
+
  --  Emit a clarification message when the expression contains at least
  --  one undefined reference, possibly due to contract freezing.


[gcc r16-1238] ada: Add case for Program_Exit in Exit_Cases

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:028dd931876d2bf7d9d38e3ca93f018d0b51ce6d

commit r16-1238-g028dd931876d2bf7d9d38e3ca93f018d0b51ce6d
Author: Claire Dross 
Date:   Fri Jan 17 14:29:47 2025 +0100

ada: Add case for Program_Exit in Exit_Cases

Extend the syntax for Exit_Cases to support exiting the program.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Exit_Cases): Update the documentation for Exit_Cases.
* sem_prag.adb
(Anlayze_Pragma): Accept Program_Exit as an exit kind.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst | 3 ++-
 gcc/ada/gnat_rm.texi   | 1 +
 gcc/ada/gnat_ugn.texi  | 2 +-
 gcc/ada/sem_prag.adb   | 7 +--
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst 
b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
index 685bdde48a5d..cae8c168562b 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -1940,7 +1940,8 @@ Syntax:
   EXIT_CASE  ::= GUARD => EXIT_KIND
   EXIT_KIND  ::= Normal_Return
| Exception_Raised
-  | (Exception_Raised => exception_name)
+   | (Exception_Raised => exception_name)
+   | Program_Exit
   GUARD  ::= Boolean_expression
 
 For the semantics of this aspect, see the SPARK 2014 Reference Manual, section
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index c67c198b8c4b..4d984713e020 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -3474,6 +3474,7 @@ EXIT_CASE  ::= GUARD => EXIT_KIND
 EXIT_KIND  ::= Normal_Return
  | Exception_Raised
  | (Exception_Raised => exception_name)
+ | Program_Exit
 GUARD  ::= Boolean_expression
 @end example
 
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 5331a318c0d8..ca1d7bcc1abf 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29833,8 +29833,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{d2}@w{  }
 @anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
+@anchor{d2}@w{  }
 
 @c %**end of body
 @bye
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 9964f70ce201..706812313296 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -2642,14 +2642,16 @@ package body Sem_Prag is
 end if;
 
 --  Check the exit kind. It shall be either an exception or the
---  identifiers Normal_Return or Any_Exception.
+--  identifiers Normal_Return, Exception_Raised, or Program_Exit.
 
 if Nkind (Exit_Kind) = N_Identifier then
if Chars (Exit_Kind) not in Name_Normal_Return
  | Name_Exception_Raised
+ | Name_Program_Exit
then
   Error_Msg_N
-("exit kind should be Normal_Return or Exception_Raised",
+("exit kind should be Normal_Return, Exception_Raised, " &
+   "or Program_Exit",
  Exit_Kind);
end if;
 
@@ -17438,6 +17440,7 @@ package body Sem_Prag is
  --
  --EXIT_KIND ::=
  --  Normal_Return
+ --| Program_Exit
  --| Exception_Raised
  --| (Exception_Raised => exception_name)
  --


[gcc r16-1248] libstdc++: Add assertions to atomic waiting functions that need platform wait

2025-06-06 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ba1ad0ec6fe6b8ee3e6682f266f7a336a15f7965

commit r16-1248-gba1ad0ec6fe6b8ee3e6682f266f7a336a15f7965
Author: Jonathan Wakely 
Date:   Wed Jun 4 16:58:45 2025 +0100

libstdc++: Add assertions to atomic waiting functions that need platform 
wait

These overloads should never be used for proxy waits, so add assertions
to ensure that they aren't used accidentally.

The reason they can't be used is that they don't call
__args._M_setup_wait to obtain a __wait_state pointer. Even if that was
changed, they would wait on a proxy wait which is potentially used by
many other threads waiting on other addresses, meaning spurious wake ups
are likely. In order to make the functions correct they would need to
perform additional loads and comparisons of the atomic variable before
calling __wait_impl or __wait_until_impl, which would make these
functions no faster than the general purpose overloads that take an
accessor function and predicate. That would be possible, and I think
they would then work for proxy waits, but doesn't seem necessary at this
time.

In order to preseve the property that these functions are more
lightweight and efficient than the general ones, they should not be used
for proxy waits.

libstdc++-v3/ChangeLog:

* include/bits/atomic_timed_wait.h (__atomic_wait_address_until_v):
Add assertion to prevent use with proxy waits.
(__atomic_wait_address_for_v): Likewise.
* include/bits/atomic_wait.h (__atomic_wait_address_v):
Likewise.

Diff:
---
 libstdc++-v3/include/bits/atomic_timed_wait.h | 6 ++
 libstdc++-v3/include/bits/atomic_wait.h   | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/libstdc++-v3/include/bits/atomic_timed_wait.h 
b/libstdc++-v3/include/bits/atomic_timed_wait.h
index bd2e6bf61ecf..30f7ff616840 100644
--- a/libstdc++-v3/include/bits/atomic_timed_wait.h
+++ b/libstdc++-v3/include/bits/atomic_timed_wait.h
@@ -156,6 +156,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  const chrono::time_point<_Clock, _Dur>& 
__atime,
  bool __bare_wait = false) noexcept
 {
+#ifndef _GLIBCXX_HAVE_PLATFORM_TIMED_WAIT
+  __glibcxx_assert(false); // This function can't be used for proxy wait.
+#endif
   __detail::__wait_args __args{ __addr, __old, __order, __bare_wait };
   auto __res = __detail::__wait_until(__addr, __args, __atime);
   return !__res._M_timeout; // C++26 will also return last observed __val
@@ -205,6 +208,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const chrono::duration<_Rep, _Period>& __rtime,
bool __bare_wait = false) noexcept
 {
+#ifndef _GLIBCXX_HAVE_PLATFORM_TIMED_WAIT
+  __glibcxx_assert(false); // This function can't be used for proxy wait.
+#endif
   __detail::__wait_args __args{ __addr, __old, __order, __bare_wait };
   auto __res = __detail::__wait_for(__addr, __args, __rtime);
   return !__res._M_timeout; // C++26 will also return last observed __val
diff --git a/libstdc++-v3/include/bits/atomic_wait.h 
b/libstdc++-v3/include/bits/atomic_wait.h
index 9ae11191d9ab..95151479c120 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -255,6 +255,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  __detail::__platform_wait_t __old,
  int __order, bool __bare_wait = false)
   {
+#ifndef _GLIBCXX_HAVE_PLATFORM_WAIT
+__glibcxx_assert(false); // This function can't be used for proxy wait.
+#endif
 __detail::__wait_args __args{ __addr, __old, __order, __bare_wait };
 // C++26 will not ignore the return value here
 __detail::__wait_impl(__addr, __args);


[gcc r15-9780] tree-optimization/119960 - add validity checking to SLP scheduling

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

commit r15-9780-g05ef04d644c1a460b3af266a7766001c93fe1a6a
Author: Richard Biener 
Date:   Tue Apr 29 15:08:52 2025 +0200

tree-optimization/119960 - add validity checking to SLP scheduling

The following adds checks that when we search for a vector stmt
insert location we arrive at one where all required operand defs
are dominating the insert location.  At the moment any such
failure only blows up during SSA verification.

There's the long-standing issue that we do not verify there
exists a valid schedule of the SLP graph from BB vectorization
into the existing CFG.  We do not have the ability to insert
vector stmts on the dominance frontier "end", nor to insert
LC PHIs that would be eventually required.

This should be done all differently, computing the schedule
during analysis and failing if we can't schedule.

PR tree-optimization/119960
* tree-vect-slp.cc (vect_schedule_slp_node): Sanity
check dominance check on operand defs.

(cherry picked from commit 5f44fcdfe18e72f2900d2757375843e88d32c535)

Diff:
---
 gcc/tree-vect-slp.cc | 36 
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 958f000e7d6d..ed432a95d33f 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -11162,9 +11162,14 @@ vect_schedule_slp_node (vec_info *vinfo,
== cycle_phi_info_type);
gphi *phi = as_a 
  (vect_find_last_scalar_stmt_in_slp (child)->stmt);
-   if (!last_stmt
-   || vect_stmt_dominates_stmt_p (last_stmt, phi))
+   if (!last_stmt)
  last_stmt = phi;
+   else if (vect_stmt_dominates_stmt_p (last_stmt, phi))
+ last_stmt = phi;
+   else if (vect_stmt_dominates_stmt_p (phi, last_stmt))
+ ;
+   else
+ gcc_unreachable ();
  }
/* We are emitting all vectorized stmts in the same place and
   the last one is the last.
@@ -11175,9 +11180,14 @@ vect_schedule_slp_node (vec_info *vinfo,
FOR_EACH_VEC_ELT (SLP_TREE_VEC_DEFS (child), j, vdef)
  {
gimple *vstmt = SSA_NAME_DEF_STMT (vdef);
-   if (!last_stmt
-   || vect_stmt_dominates_stmt_p (last_stmt, vstmt))
+   if (!last_stmt)
+ last_stmt = vstmt;
+   else if (vect_stmt_dominates_stmt_p (last_stmt, vstmt))
  last_stmt = vstmt;
+   else if (vect_stmt_dominates_stmt_p (vstmt, last_stmt))
+ ;
+   else
+ gcc_unreachable ();
  }
  }
else if (!SLP_TREE_VECTYPE (child))
@@ -11190,9 +11200,14 @@ vect_schedule_slp_node (vec_info *vinfo,
  && !SSA_NAME_IS_DEFAULT_DEF (def))
{
  gimple *stmt = SSA_NAME_DEF_STMT (def);
- if (!last_stmt
- || vect_stmt_dominates_stmt_p (last_stmt, stmt))
+ if (!last_stmt)
+   last_stmt = stmt;
+ else if (vect_stmt_dominates_stmt_p (last_stmt, stmt))
last_stmt = stmt;
+ else if (vect_stmt_dominates_stmt_p (stmt, last_stmt))
+   ;
+ else
+   gcc_unreachable ();
}
  }
else
@@ -11213,9 +11228,14 @@ vect_schedule_slp_node (vec_info *vinfo,
  && !SSA_NAME_IS_DEFAULT_DEF (vdef))
{
  gimple *vstmt = SSA_NAME_DEF_STMT (vdef);
- if (!last_stmt
- || vect_stmt_dominates_stmt_p (last_stmt, vstmt))
+ if (!last_stmt)
+   last_stmt = vstmt;
+ else if (vect_stmt_dominates_stmt_p (last_stmt, vstmt))
last_stmt = vstmt;
+ else if (vect_stmt_dominates_stmt_p (vstmt, last_stmt))
+   ;
+ else
+   gcc_unreachable ();
}
  }
  }


[gcc r16-1252] Remove create_tmp_reg_or_ssa_name

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:3e00d7dcc5b9a30d3f356369828e8ceb03de91b9

commit r16-1252-g3e00d7dcc5b9a30d3f356369828e8ceb03de91b9
Author: Richard Biener 
Date:   Fri Jun 6 11:44:18 2025 +0200

Remove create_tmp_reg_or_ssa_name

Now that create_tmp_reg_or_ssa_name just calls make_ssa_name replace
all of its uses.

* gimple-fold.h (create_tmp_reg_or_ssa_name): Remove.
* gimple-fold.cc (create_tmp_reg_or_ssa_name): Likewise.
(gimple_fold_builtin_memory_op): Use make_ssa_name.
(gimple_fold_builtin_strchr): Likewise.
(gimple_fold_builtin_strcat): Likewise.
(gimple_load_first_char): Likewise.
(gimple_fold_builtin_string_compare): Likewise.
(gimple_build): Likewise.
* tree-inline.cc (copy_bb): Likewise.
* config/rs6000/rs6000-builtin.cc (fold_build_vec_cmp): Likewise.
(rs6000_gimple_fold_mma_builtin): Likewise.
(rs6000_gimple_fold_builtin): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc | 24 ++---
 gcc/gimple-fold.cc  | 42 +
 gcc/gimple-fold.h   |  1 -
 gcc/tree-inline.cc  |  2 +-
 4 files changed, 28 insertions(+), 41 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc 
b/gcc/config/rs6000/rs6000-builtin.cc
index 111802381acb..bc1580f051b0 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -915,7 +915,7 @@ fold_build_vec_cmp (tree_code code, tree type, tree arg0, 
tree arg1,
   tree cmp_type = truth_type_for (type);
   tree zero_vec = build_zero_cst (type);
   tree minus_one_vec = build_minus_one_cst (type);
-  tree temp = create_tmp_reg_or_ssa_name (cmp_type);
+  tree temp = make_ssa_name (cmp_type);
   gimple *g = gimple_build_assign (temp, code, arg0, arg1);
   gsi_insert_before (gsi, g, GSI_SAME_STMT);
   return fold_build3 (VEC_COND_EXPR, type, temp, minus_one_vec, zero_vec);
@@ -1106,7 +1106,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi,
   if (TREE_TYPE (src_ptr) != src_type)
src_ptr = build1 (NOP_EXPR, src_type, src_ptr);
 
-  tree src = create_tmp_reg_or_ssa_name (TREE_TYPE (src_type));
+  tree src = make_ssa_name (TREE_TYPE (src_type));
   gimplify_assign (src, build_simple_mem_ref (src_ptr), &new_seq);
 
   /* If we are not disassembling an accumulator/pair or our destination is
@@ -1130,7 +1130,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi,
{
  new_decl = rs6000_builtin_decls[RS6000_BIF_XXMFACC_INTERNAL];
  new_call = gimple_build_call (new_decl, 1, src);
- src = create_tmp_reg_or_ssa_name (vector_quad_type_node);
+ src = make_ssa_name (vector_quad_type_node);
  gimple_call_set_lhs (new_call, src);
  gimple_seq_add_stmt (&new_seq, new_call);
}
@@ -1146,7 +1146,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi,
  unsigned index = WORDS_BIG_ENDIAN ? i : nvec - 1 - i;
  tree dst = build2 (MEM_REF, unsigned_V16QI_type_node, dst_base,
 build_int_cst (dst_type, index * 16));
- tree dstssa = create_tmp_reg_or_ssa_name (unsigned_V16QI_type_node);
+ tree dstssa = make_ssa_name (unsigned_V16QI_type_node);
  new_call = gimple_build_call (new_decl, 2, src,
build_int_cstu (uint16_type_node, i));
  gimple_call_set_lhs (new_call, dstssa);
@@ -1204,7 +1204,7 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi,
 {
   /* This built-in has a pass-by-reference accumulator input, so load it
 into a temporary accumulator for use as a pass-by-value input.  */
-  op[0] = create_tmp_reg_or_ssa_name (vector_quad_type_node);
+  op[0] = make_ssa_name (vector_quad_type_node);
   for (unsigned i = 1; i < nopnds; i++)
op[i] = gimple_call_arg (stmt, i);
   gimplify_assign (op[0], build_simple_mem_ref (acc), &new_seq);
@@ -1252,9 +1252,9 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi,
 }
 
   if (fncode == RS6000_BIF_BUILD_PAIR || fncode == RS6000_BIF_ASSEMBLE_PAIR_V)
-lhs = create_tmp_reg_or_ssa_name (vector_pair_type_node);
+lhs = make_ssa_name (vector_pair_type_node);
   else
-lhs = create_tmp_reg_or_ssa_name (vector_quad_type_node);
+lhs = make_ssa_name (vector_quad_type_node);
   gimple_call_set_lhs (new_call, lhs);
   gimple_seq_add_stmt (&new_seq, new_call);
   gimplify_assign (build_simple_mem_ref (acc), lhs, &new_seq);
@@ -1450,7 +1450,7 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
   arg0 = gimple_call_arg (stmt, 0);
   arg1 = gimple_call_arg (stmt, 1);
   lhs = gimple_call_lhs (stmt);
-  temp = create_tmp_reg_or_ssa_name (TREE_TYPE (arg1));
+  temp = make_ssa_name (TREE_TYPE (arg1));
   g = gimple_build_assign (temp, BIT_NOT_EXPR, arg1);
 

[gcc r16-1259] libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]

2025-06-06 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:91ed3248ce26aaaee4d7471aa4edbc07b3f1a90e

commit r16-1259-g91ed3248ce26aaaee4d7471aa4edbc07b3f1a90e
Author: Patrick Palka 
Date:   Fri Jun 6 09:34:17 2025 -0400

libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]

The const lvalue operator[] overload wasn't properly forwarding the key
type to the generic overload, causing a hard error for const keys.

Rather than correcting the forwarded type this patch just makes the
non-template overloads call try_emplace directly instead.  That way we
can remove the non-standard same_as constraint on the generic overload
and match the spec more closely.

PR libstdc++/120432

libstdc++-v3/ChangeLog:

* include/std/flat_map (flat_map::operator[]): Make the
non-template overloads call try_emplace directly.  Remove
non-standard same_as constraint on the template overload.
* testsuite/23_containers/flat_map/1.cc (test08): New test.

Reviewed-by: Tomasz Kamiński 
Reviewed-by: Jonathan Wakely 

Diff:
---
 libstdc++-v3/include/std/flat_map  |  6 +++---
 libstdc++-v3/testsuite/23_containers/flat_map/1.cc | 10 ++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/flat_map 
b/libstdc++-v3/include/std/flat_map
index 4bd4963c2ad7..de006ad1c533 100644
--- a/libstdc++-v3/include/std/flat_map
+++ b/libstdc++-v3/include/std/flat_map
@@ -1148,14 +1148,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // element access
   mapped_type&
   operator[](const key_type& __x)
-  { return operator[](__x); }
+  { return try_emplace(__x).first->second; }
 
   mapped_type&
   operator[](key_type&& __x)
-  { return operator[](std::move(__x)); }
+  { return try_emplace(std::move(__x)).first->second; }
 
   template
-   requires same_as, _Key> || 
__transparent_comparator<_Compare>
+   requires __transparent_comparator<_Compare>
mapped_type&
operator[](_Key2&& __x)
{ return try_emplace(std::forward<_Key2>(__x)).first->second; }
diff --git a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc 
b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
index 1b593135f225..01278d7dc33c 100644
--- a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
@@ -254,6 +254,15 @@ test07()
   VERIFY( std::ranges::equal(m, (std::pair[]){{3,4}}) );
 }
 
+void
+test08()
+{
+  // PR libstdc++/120432 - flat_map operator[] is broken for const lvalue keys
+  std::flat_map m;
+  const int k = 42;
+  m[k] = 0;
+}
+
 int
 main()
 {
@@ -267,4 +276,5 @@ main()
   test05();
   test06();
   test07();
+  test08();
 }


[gcc r16-1258] RISC-V: Reconcile the existing test for vdivu.vx combine

2025-06-06 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:08a0b6dabd76c8ca4366a59c2fdcd1ef8f8b1cb9

commit r16-1258-g08a0b6dabd76c8ca4366a59c2fdcd1ef8f8b1cb9
Author: Pan Li 
Date:   Fri Jun 6 10:03:50 2025 +0800

RISC-V: Reconcile the existing test for vdivu.vx combine

Some existing vdiv related test need some adjust for the
asm check due to cost model.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c: Adjust
the asm check for vdivu.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c: Ditto.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c: Ditto.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c: Ditto.

Signed-off-by: Pan Li 

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c | 4 ++--
 gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c  | 4 ++--
 gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c | 4 ++--
 gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c
index 4685ed22a784..a8be5edcc70c 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c
@@ -5,8 +5,8 @@
 
 /* { dg-final { scan-assembler-times {\tvdiv\.vv} 8 } } */
 /* { dg-final { scan-assembler-not {\tvdiv\.vx} } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vv} 5 } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vx} 3 } } */
+/* { dg-final { scan-assembler-times {\tvdivu\.vv} 8 } } */
+/* { dg-final { scan-assembler-not {\tvdivu\.vx} } } */
 
 /* { dg-final { scan-assembler-times {\tvfdiv\.vv} 6 } } */
 /* { dg-final { scan-assembler-not {\tvfdiv\.vf} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c
index 59c48d2d9bae..7feee0ec154a 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c
@@ -5,8 +5,8 @@
 
 /* { dg-final { scan-assembler-times {\tvdiv\.vv} 8 } } */
 /* { dg-final { scan-assembler-not {\tvdiv\.vx} } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vv} 5 } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vx} 3 } } */
+/* { dg-final { scan-assembler-times {\tvdivu\.vv} 8 } } */
+/* { dg-final { scan-assembler-not {\tvdivu\.vx} } } */
 
 /* Division by constant is done by calculating a reciprocal and
then multiplying.  Hence we do not expect 6 vfdivs.  */
diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c
index b574dc42182c..766b17fc37da 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c
@@ -5,8 +5,8 @@
 
 /* { dg-final { scan-assembler-times {\tvdiv\.vv} 8 } } */
 /* { dg-final { scan-assembler-not {\tvdiv\.vx} } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vv} 4 } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vx} 4 } } */
+/* { dg-final { scan-assembler-times {\tvdivu\.vv} 8 } } */
+/* { dg-final { scan-assembler-not {\tvdivu\.vx} } } */
 
 /* { dg-final { scan-assembler-times {\tvfdiv\.vv} 6 } } */
 /* { dg-final { scan-assembler-not {\tvfdiv\.vf} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c
index 9b46c6be0efb..c59c66439f89 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c
@@ -5,8 +5,8 @@
 
 /* { dg-final { scan-assembler-times {\tvdiv\.vv} 8 } } */
 /* { dg-final { scan-assembler-not {\tvdiv\.vx} } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vv} 4 } } */
-/* { dg-final { scan-assembler-times {\tvdivu\.vx} 4 } } */
+/* { dg-final { scan-assembler-times {\tvdivu\.vv} 8 } } */
+/* { dg-final { scan-assembler-not {\tvdivu\.vx} } } */
 
 /* Division by constant is done by calculating a reciprocal and
then multiplying.  Hence we do not expect 6 vfdivs.  */


[gcc r16-1262] OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:387209938d2c476a67966c6ddbdbf817626f24a2

commit r16-1262-g387209938d2c476a67966c6ddbdbf817626f24a2
Author: Tobias Burnus 
Date:   Fri Jun 6 16:22:06 2025 +0200

OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins

By adding omp_get_initial_device and omp_get_num_devices builtins for
C, C++, and Fortran, the following can be achieved:
* By making them pure, multiple calls can be avoiding in some cases.
* Some comparisons can be optimized at compile time.

omp_get_initial_device will be converted to omp_get_num_devices for
consistency; note that OpenMP 6 also permits omp_initial_device (== -1)
as value.

If GCC has not been configure for offloading, either intrinsic will
leads to 0 - and on the offload side, -1 (= omp_initial_device) is
returned for omp_initial_device.

gcc/fortran/ChangeLog:

* f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define.
* trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices
and omp_get_intrinsic_device.
* gfortran.h (gfc_option_t): Add disable_omp_... for them.
* options.cc (gfc_handle_option): Handle them with
-fno-builtin-.

gcc/ChangeLog:

* gimple-fold.cc (gimple_fold_builtin_omp_get_initial_device,
gimple_fold_builtin_omp_get_num_devices): New.
(gimple_fold_builtin): Call them.
* omp-builtins.def (BUILT_IN_OMP_GET_INITIAL_DEVICE): Add
(BUILT_IN_OMP_GET_NUM_DEVICES): Make uservisible + pure.

libgomp/ChangeLog:

* libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device):
Document builtin handling.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New 
test.
* c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New 
test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test.

Co-authored-by: Sandra Loosemore 

Diff:
---
 gcc/fortran/f95-lang.cc|  3 +-
 gcc/fortran/gfortran.h |  6 ++--
 gcc/fortran/options.cc |  4 +++
 gcc/fortran/trans-expr.cc  | 10 ++
 gcc/gimple-fold.cc | 40 ++
 gcc/omp-builtins.def   |  9 +++--
 .../gomp/omp_get_num_devices_initial_device-2.c| 29 
 .../gomp/omp_get_num_devices_initial_device.c  | 32 +
 .../gomp/omp_get_num_devices_initial_device-2.f90  | 21 
 .../gomp/omp_get_num_devices_initial_device.f90| 24 +
 libgomp/libgomp.texi   | 14 
 11 files changed, 186 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/f95-lang.cc b/gcc/fortran/f95-lang.cc
index 1f09553142d6..bb4ce6d82882 100644
--- a/gcc/fortran/f95-lang.cc
+++ b/gcc/fortran/f95-lang.cc
@@ -564,7 +564,7 @@ gfc_builtin_function (tree decl)
   return decl;
 }
 
-/* So far we need just these 10 attribute types.  */
+/* So far we need just these 12 attribute types.  */
 #define ATTR_NULL  0
 #define ATTR_LEAF_LIST (ECF_LEAF)
 #define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
@@ -580,6 +580,7 @@ gfc_builtin_function (tree decl)
 #define ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST \
(ECF_COLD | ECF_NORETURN | \
 ECF_NOTHROW | ECF_LEAF)
+#define ATTR_PURE_NOTHROW_LIST (ECF_PURE | ECF_NOTHROW)
 
 static void
 gfc_define_builtin (const char *name, tree type, enum built_in_function code,
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index e461aa68470d..f73b5f9c23f4 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3302,8 +3302,10 @@ typedef struct
   int flag_init_logical;
   int flag_init_character;
   char flag_init_character_value;
-  bool disable_omp_is_initial_device;
-  bool disable_acc_on_device;
+  bool disable_omp_is_initial_device:1;
+  bool disable_omp_get_initial_device:1;
+  bool disable_omp_get_num_devices:1;
+  bool disable_acc_on_device:1;
 
   int fpe;
   int fpe_summary;
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index c1c2833f..d3c9066630b7 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -883,6 +883,10 @@ gfc_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
return false;  /* Not supported. */
   if (!strcmp ("omp_is_initial_device", arg))
gfc_option.disable_omp_is_initial_device = true;
+  else if (!strcmp ("omp_get_initial_device", arg))
+   gfc_option.disable_omp_get_initial_device = true;
+  else if (!strcmp ("omp_get_num_devices", arg))
+   gfc_option.disable_omp_get

[gcc r16-1261] builtins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:214b5d66c54613463a96aa2c7202bc32f628dad6

commit r16-1261-g214b5d66c54613463a96aa2c7202bc32f628dad6
Author: Tobias Burnus 
Date:   Fri Jun 6 15:57:50 2025 +0200

builtins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins

The flags -std=c.. and -std=c++.. imply -fno-nonansi-builtins, which 
disabled
the OpenMP/OpenACC intrinsics - but -fopenmp/-fopenacc builtin use should be
rather othogonal to the user's choice between -std=c... and -std=gnuc...

gcc/ChangeLog:

* builtins.def (DEF_GOACC_BUILTIN_COMPILER, 
DEF_GOMP_BUILTIN_COMPILER):
Set NONANSI_P = false to enable those also with 
-fno-nonansi-builtins.

Diff:
---
 gcc/builtins.def | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/builtins.def b/gcc/builtins.def
index fdcad54a5d75..59a43a10058a 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -217,6 +217,8 @@ along with GCC; see the file COPYING3.  If not see
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
   false, true, true, ATTRS, false, \
   flag_openacc)
+/* Set NONANSI_P = false to enable the builtins also with 
-fno-nonansi-builtins,
+   esp. as -std=c++../c.. imply that flag and -fopenacc should be othogonal.  
*/
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
@@ -232,10 +234,12 @@ along with GCC; see the file COPYING3.  If not see
   (flag_openacc \
|| flag_openmp \
|| flag_tree_parallelize_loops > 1))
+/* Set NONANSI_P = false to enable the builtins also with 
-fno-nonansi-builtins,
+   esp. as -std=c++../c.. imply that flag and -fopenmp should be othogonal.  */
 #undef DEF_GOMP_BUILTIN_COMPILER
 #define DEF_GOMP_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,\
-   flag_openmp, true, true, ATTRS, false, flag_openmp)
+   flag_openmp, true, false, ATTRS, false, flag_openmp)
 
 /* Builtin used by the implementation of GNU TM.  These
functions are mapped to the actual implementation of the STM library. */


[gcc r16-1260] Remove non-SLP path from get_[group_]load_store_type

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:a4ff2cc3ad4f46f531a2af4596790609d622aa10

commit r16-1260-ga4ff2cc3ad4f46f531a2af4596790609d622aa10
Author: Richard Biener 
Date:   Fri Jun 6 13:32:49 2025 +0200

Remove non-SLP path from get_[group_]load_store_type

The following removes the non-SLP path from get_group_load_store_type
and get_load_store_type.

* tree-vect-stmts.cc (get_group_load_store_type): Remove
non-SLP path.
(get_load_store_type): Likewise.

Diff:
---
 gcc/tree-vect-stmts.cc | 551 -
 1 file changed, 223 insertions(+), 328 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index c92dfdc52884..f699d808e688 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -2097,310 +2097,246 @@ get_group_load_store_type (vec_info *vinfo, 
stmt_vec_info stmt_info,
  known at compile time.  */
   gcc_assert (!STMT_VINFO_STRIDED_P (first_stmt_info) || gap == 0);
 
-  /* Stores can't yet have gaps.  */
-  gcc_assert (slp_node || vls_type == VLS_LOAD || gap == 0);
-
-  if (slp_node)
+  /* For SLP vectorization we directly vectorize a subchain
+ without permutation.  */
+  if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
+first_dr_info = STMT_VINFO_DR_INFO (SLP_TREE_SCALAR_STMTS (slp_node)[0]);
+  if (STMT_VINFO_STRIDED_P (first_stmt_info))
+/* Try to use consecutive accesses of as many elements as possible,
+   separated by the stride, until we have a complete vector.
+   Fall back to scalar accesses if that isn't possible.  */
+*memory_access_type = VMAT_STRIDED_SLP;
+  else
 {
-  /* For SLP vectorization we directly vectorize a subchain
-without permutation.  */
-  if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
-   first_dr_info
- = STMT_VINFO_DR_INFO (SLP_TREE_SCALAR_STMTS (slp_node)[0]);
-  if (STMT_VINFO_STRIDED_P (first_stmt_info))
-   /* Try to use consecutive accesses of as many elements as possible,
-  separated by the stride, until we have a complete vector.
-  Fall back to scalar accesses if that isn't possible.  */
-   *memory_access_type = VMAT_STRIDED_SLP;
-  else
+  int cmp = compare_step_with_zero (vinfo, stmt_info);
+  if (cmp < 0)
{
- int cmp = compare_step_with_zero (vinfo, stmt_info);
- if (cmp < 0)
+ if (single_element_p)
+   /* ???  The VMAT_CONTIGUOUS_REVERSE code generation is
+  only correct for single element "interleaving" SLP.  */
+   *memory_access_type = get_negative_load_store_type
+   (vinfo, stmt_info, vectype, vls_type, 1,
+&neg_ldst_offset);
+ else
{
- if (single_element_p)
-   /* ???  The VMAT_CONTIGUOUS_REVERSE code generation is
-  only correct for single element "interleaving" SLP.  */
-   *memory_access_type = get_negative_load_store_type
-(vinfo, stmt_info, vectype, vls_type, 1,
- &neg_ldst_offset);
+ /* Try to use consecutive accesses of DR_GROUP_SIZE elements,
+separated by the stride, until we have a complete vector.
+Fall back to scalar accesses if that isn't possible.  */
+ if (multiple_p (nunits, group_size))
+   *memory_access_type = VMAT_STRIDED_SLP;
  else
-   {
- /* Try to use consecutive accesses of DR_GROUP_SIZE elements,
-separated by the stride, until we have a complete vector.
-Fall back to scalar accesses if that isn't possible.  */
- if (multiple_p (nunits, group_size))
-   *memory_access_type = VMAT_STRIDED_SLP;
- else
-   *memory_access_type = VMAT_ELEMENTWISE;
-   }
+   *memory_access_type = VMAT_ELEMENTWISE;
}
- else if (cmp == 0 && loop_vinfo)
-   {
- gcc_assert (vls_type == VLS_LOAD);
- *memory_access_type = VMAT_INVARIANT;
-   }
- /* Try using LOAD/STORE_LANES.  */
- else if (slp_node->ldst_lanes
-  && (*lanes_ifn
-= (vls_type == VLS_LOAD
-   ? vect_load_lanes_supported (vectype, group_size,
-masked_p, elsvals)
-   : vect_store_lanes_supported (vectype, group_size,
- masked_p))) != 
IFN_LAST)
-   *memory_access_type = VMAT_LOAD_STORE_LANES;
- else if (!loop_vinfo && slp_node->avoid_stlf_fail)
+   }
+  else if (cmp == 0 && loop_vinfo)
+   {
+ gcc_assert (vls_type == VLS_LOAD);
+ *memory_access_type = VMAT_INVARIANT;
+   }
+  /* Try using LOAD/STORE_LANES.

[gcc r15-9791] ada: Fix for validity checking of limited scalar types

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:649bde867ae0a808b21e837744211339476c8099

commit r15-9791-g649bde867ae0a808b21e837744211339476c8099
Author: Piotr Trojanek 
Date:   Tue Jan 28 12:12:23 2025 +0100

ada: Fix for validity checking of limited scalar types

With a recent change we are now validity checking objects of private scalar
types, but need to handle private scalar types whose public view is limited.

gcc/ada/ChangeLog:

* checks.adb (Insert_Valid_Check): Set flag Assignment_OK in the 
object
declaration inserted for the validity checks.

Diff:
---
 gcc/ada/checks.adb | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index dcfcaa33bcc4..6a98292d1cc1 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -8163,6 +8163,7 @@ package body Checks is
   end if;
 
   declare
+ Decl   : Node_Id;
  CE : Node_Id;
  PV : Node_Id;
  Var_Id : Entity_Id;
@@ -8215,12 +8216,20 @@ package body Checks is
 Mutate_Ekind (Var_Id, E_Variable);
 Set_Etype (Var_Id, Typ);
 
-Insert_Action (Exp,
+Decl :=
   Make_Object_Declaration (Loc,
 Defining_Identifier => Var_Id,
 Object_Definition   => New_Occurrence_Of (Typ, Loc),
-Expression  => New_Copy_Tree (Exp)),
-  Suppress => Validity_Check);
+Expression  => New_Copy_Tree (Exp));
+
+--  We might be validity-checking object whose type is declared as
+--  limited but completion is a scalar type. We need to explicitly
+--  flag its assignment as OK, as otherwise it would be rejected by
+--  the language rules.
+
+Set_Assignment_OK (Decl);
+
+Insert_Action (Exp, Decl, Suppress => Validity_Check);
 
 Set_Validated_Object (Var_Id, New_Copy_Tree (Exp));


[gcc r15-9792] ada: Fix internal error on allocator involving interface type

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:855fe3625493e3888df5da12aba945c243ec6650

commit r15-9792-g855fe3625493e3888df5da12aba945c243ec6650
Author: Eric Botcazou 
Date:   Tue Feb 11 12:47:36 2025 +0100

ada: Fix internal error on allocator involving interface type

The problem is that an itype duplicated through Duplicate_Subexpr_No_Checks
ends up in a different scope than its source.  It is fixed by adding a new
formal parameter New_Scope to the function and forwarding it in the call to
the New_Copy_Tree function.

gcc/ada/ChangeLog:

* exp_aggr.adb (Expand_Record_Aggregate): Use the named form for the
second actual parameter in the call to Duplicate_Subexpr.
* exp_attr.adb (Expand_Size_Attribute): Likewise.
* exp_ch5.adb (Expand_Assign_Array): Likewise.
(Expand_Assign_Array_Bitfield): Likewise.
(Expand_Assign_Array_Bitfield_Fast): Likewise.
* exp_util.ads (Duplicate_Subexpr): Add New_Scope formal parameter.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Pass Proc_Id as the
actual for New_Scope in the calls to Duplicate_Subexpr_No_Checks.
(Duplicate_Subexpr): Add New_Scope formal parameter and forward it
in the call to New_Copy_Tree.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.

Diff:
---
 gcc/ada/exp_aggr.adb |  3 ++-
 gcc/ada/exp_attr.adb |  4 ++--
 gcc/ada/exp_ch5.adb  | 24 +---
 gcc/ada/exp_util.adb | 35 ++-
 gcc/ada/exp_util.ads | 18 --
 5 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index f2e7ad76e98f..8f1869cc7091 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -8077,7 +8077,8 @@ package body Exp_Aggr is
Make_Selected_Component (Loc,
  Prefix=>
Unchecked_Convert_To (Typ,
- Duplicate_Subexpr (Parent_Expr, True)),
+ Duplicate_Subexpr
+   (Parent_Expr, Name_Req => True)),
  Selector_Name => New_Occurrence_Of (Comp, Loc));
 
  Append_To (Comps,
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 4e0052e9ee41..455cc226bbfb 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -8602,10 +8602,10 @@ package body Exp_Attr is
 Rewrite (N,
   Make_Op_Multiply (Loc,
 Make_Attribute_Reference (Loc,
-  Prefix => Duplicate_Subexpr (Pref, True),
+  Prefix => Duplicate_Subexpr (Pref, Name_Req => True),
   Attribute_Name => Name_Length),
 Make_Attribute_Reference (Loc,
-  Prefix => Duplicate_Subexpr (Pref, True),
+  Prefix => Duplicate_Subexpr (Pref, Name_Req => True),
   Attribute_Name => Name_Component_Size)));
 Analyze_And_Resolve (N, Typ);
  end if;
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 06616eaf87d3..3d8a542c24e0 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -1039,7 +1039,8 @@ package body Exp_Ch5 is
  Prefix =>
Make_Indexed_Component (Loc,
  Prefix =>
-   Duplicate_Subexpr_Move_Checks (Larray, True),
+   Duplicate_Subexpr_Move_Checks
+ (Larray, Name_Req => True),
  Expressions => New_List (
Make_Attribute_Reference (Loc,
  Prefix =>
@@ -1054,7 +1055,8 @@ package body Exp_Ch5 is
  Prefix =>
Make_Indexed_Component (Loc,
  Prefix =>
-   Duplicate_Subexpr_Move_Checks (Rarray, True),
+   Duplicate_Subexpr_Move_Checks
+ (Rarray, Name_Req => True),
  Expressions => New_List (
Make_Attribute_Reference (Loc,
  Prefix =>
@@ -1396,7 +1398,7 @@ package body Exp_Ch5 is
   Prefix =>
 Make_Indexed_Component (Loc,
   Prefix =>
-Duplicate_Subexpr (Larray, True),
+Duplicate_Subexpr (Larray, Name_Req => True),
   Expressions => New_List (New_Copy_Tree (Left_Lo))),
   Attribute_Name => Name_Address);
 
@@ -1405,7 +1407,7 @@ package body Exp_Ch5 is
   Prefix =>
 Make_Indexed_Component (Loc,
  

[gcc r16-1263] [committed] Fix compromised ARC test

2025-06-06 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:e37eb8578c5c9a62d4f804908ad57fc38c71a3a2

commit r16-1263-ge37eb8578c5c9a62d4f804908ad57fc38c71a3a2
Author: Jeff Law 
Date:   Fri Jun 6 08:45:53 2025 -0600

[committed] Fix compromised ARC test

Jakub's recent changes for pr120231 compromised this arc port specific test.
Essentially we collapse the entire FMA sequence down to a constant and thus
never emit the FMA instruction the test wants to see.

If we make "a" an extern so that we don't know its value the optimizers 
can't
collapse the calculation away completely and we can verify that we get an 
FMA
operation.

Pushing to the trunk.

gcc/testsuite
* gcc.target/arc/fma-1.c: Make "a" extern so the optimizers can
see any value and optimize away the key computation.

Diff:
---
 gcc/testsuite/gcc.target/arc/fma-1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/arc/fma-1.c 
b/gcc/testsuite/gcc.target/arc/fma-1.c
index c195ad98127c..b32989fced1b 100644
--- a/gcc/testsuite/gcc.target/arc/fma-1.c
+++ b/gcc/testsuite/gcc.target/arc/fma-1.c
@@ -2,7 +2,8 @@
 /* { dg-skip-if "FPU not available" { arc700 || arc6xx } } */
 /* { dg-options "-s -std=gnu11  -O2 -frounding-math -mfpu=fpus_all" } */
 
-const float a, b = 7.8539818525e01;
+const float b = 7.8539818525e01;
+extern const float a;
 
 /* Check if the fma operation is generated correctly.  */


[gcc r15-9796] ada: Constant_Indexing used when context requires a variable

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:f59d33ad52cbc9c3096862a7e286021463a05998

commit r15-9796-gf59d33ad52cbc9c3096862a7e286021463a05998
Author: Javier Miranda 
Date:   Fri Jan 31 20:21:09 2025 +

ada: Constant_Indexing used when context requires a variable

In the case of an assignment where the type of its left hand side
is an indexable container that has indexable container components
(for example a container vector of container vectors), and both
indexable containers have Constant_Indexing and Variable_Indexing
aspects, the left hand side of the assignment is erroneously
interpreted as constant indexing. The error results in spurious
compile-time error messages saying that the left hand side of
the assignment must be a variable.

gcc/ada/ChangeLog:

* sem_ch4.adb (Constant_Indexing_OK): Add missing support for
RM 4.1.6(13/3), and improve performance to avoid climbing more
than needed. Add documentation.
(Try_Indexing_Function): New subprogram.
(Expr_Matches_In_Formal): Added new formals.
(Handle_Selected_Component): New subprogram.
(Has_IN_Mode): New subprogram.
(Try_Container_Indexing): Add documentation, code reorganization
and extend its functionality to improve its support for prefixed
notation calls.

Diff:
---
 gcc/ada/sem_ch4.adb | 886 +++-
 1 file changed, 667 insertions(+), 219 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 50b3eee0dbe5..8be9647e5c02 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -308,8 +308,12 @@ package body Sem_Ch4 is
  (N  : Node_Id;
   Prefix : Node_Id;
   Exprs  : List_Id) return Boolean;
-   --  AI05-0139: Generalized indexing to support iterators over containers
-   --  ??? Need to provide a more detailed spec of what this function does
+   --  AI05-0139: Generalized indexing to support iterators over containers.
+   --  Given the N_Indexed_Component node N, with the given prefix and
+   --  expressions list, check if the generalized indexing is applicable;
+   --  if applicable then build its indexing function, link it to N through
+   --  attribute Generalized_Indexing, and return True; otherwise return
+   --  False.
 
function Try_Indexed_Call
  (N  : Node_Id;
@@ -8512,21 +8516,29 @@ package body Sem_Ch4 is
   Prefix : Node_Id;
   Exprs  : List_Id) return Boolean
is
-  Pref_Typ : Entity_Id := Etype (Prefix);
+  Heuristic : Boolean   := False;
+  Pref_Typ  : Entity_Id := Etype (Prefix);
 
   function Constant_Indexing_OK return Boolean;
-  --  Constant_Indexing is legal if there is no Variable_Indexing defined
-  --  for the type, or else node not a target of assignment, or an actual
-  --  for an IN OUT or OUT formal (RM 4.1.6 (11)).
-
-  function Expr_Matches_In_Formal
-(Subp : Entity_Id;
- Par  : Node_Id) return Boolean;
-  --  Find formal corresponding to given indexed component that is an
-  --  actual in a call. Note that the enclosing subprogram call has not
-  --  been analyzed yet, and the parameter list is not normalized, so
-  --  that if the argument is a parameter association we must match it
-  --  by name and not by position.
+  --  Determines whether the Constant_Indexing aspect has been specified
+  --  for the type of the prefix and can be interpreted as constant
+  --  indexing; that is, there is no Variable_Indexing defined for the
+  --  type, or else the node is not a target of an assignment, or an
+  --  actual for an IN OUT or OUT formal, or the name in an object
+  --  renaming (RM 4.1.6 (12/3..15/3)).
+  --
+  --  Given that prefix notation calls have not yet been resolved, if the
+  --  type of the prefix has both aspects present (Constant_Indexing and
+  --  Variable_Indexing), and context analysis performed by this routine
+  --  identifies a potential prefix notation call (i.e., an N_Selected_
+  --  Component node), this function may rely on heuristics to decide
+  --  between constant or variable indexing. In such cases, if the
+  --  decision is later found to be incorrect, Try_Container_Indexing
+  --  will retry using the alternative indexing aspect.
+
+  --  When heuristics are used to compute the result of this function
+  --  the behavior of Try_Container_Indexing might not be strictly
+  --  following the rules of the RM.
 
   function Indexing_Interpretations
 (T   : Entity_Id;
@@ -8534,59 +8546,429 @@ package body Sem_Ch4 is
   --  Return a set of interpretations reflecting all of the functions
   --  associated with an indexing aspect of type T of the given kind.
 
+  function Try_Indexing_Function
+(Func_Name : Node_Id;
+ Assoc : List_Id) return

[gcc r15-9795] ada: Fix libgpr2 build failure with compiler built with assertions

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:e0777e78bede3108d41a506d8877c03997bed2c5

commit r15-9795-ge0777e78bede3108d41a506d8877c03997bed2c5
Author: Eric Botcazou 
Date:   Mon Feb 24 22:27:21 2025 +0100

ada: Fix libgpr2 build failure with compiler built with assertions

The problem is that the Entity field is accessed for a node without one.

gcc/ada/ChangeLog:

* sem_ch10.adb (Install_Siblings.In_Context): Add missing guard.

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

diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb
index de5a8c846ba7..e3d9925ab581 100644
--- a/gcc/ada/sem_ch10.adb
+++ b/gcc/ada/sem_ch10.adb
@@ -4932,6 +4932,8 @@ package body Sem_Ch10 is
if Entity (Name (Clause)) = Id
  or else
(Nkind (Name (Clause)) = N_Expanded_Name
+ and then
+   Is_Entity_Name (Prefix (Name (Clause)))
  and then Entity (Prefix (Name (Clause))) = Id)
then
   return True;


[gcc r15-9794] ada: Fix wrong initialization of library-level object by conditional expression

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:cb3e76508b1af7ff5ba6e43592d7d67bbb96fac6

commit r15-9794-gcb3e76508b1af7ff5ba6e43592d7d67bbb96fac6
Author: Eric Botcazou 
Date:   Fri Feb 21 10:03:22 2025 +0100

ada: Fix wrong initialization of library-level object by conditional 
expression

At library level the object must be allocated statically and with its bounds
when its nominal subtype is an unconstrained array type.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Make sure the
object is allocated properly by the code generator at library level.

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

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index eb9fb6bba569..793e468a0a3c 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -13292,10 +13292,12 @@ package body Exp_Ch4 is
   Obj_Decl : constant Node_Id :=
 Make_Object_Declaration (Loc,
   Defining_Identifier => Obj_Id,
-  Aliased_Present => Aliased_Present (Decl),
+  Aliased_Present => True,
   Constant_Present=> Constant_Present (Decl),
   Object_Definition   => New_Copy_Tree (Object_Definition (Decl)),
   Expression  => Relocate_Node (Expr));
+  --  We make the object unconditionally aliased to avoid dangling bound
+  --  issues when its nominal subtype is an unconstrained array type.
 
   Master_Node_Decl : Node_Id;
   Master_Node_Id   : Entity_Id;
@@ -13310,6 +13312,11 @@ package body Exp_Ch4 is
 
   Insert_Action (Expr, Obj_Decl);
 
+  --  The object can never be local to an elaboration routine at library
+  --  level since we will take 'Unrestricted_Access of it.
+
+  Set_Is_Statically_Allocated (Obj_Id, Is_Library_Level_Entity (Obj_Id));
+
   --  If the object needs finalization, we need to insert its Master_Node
   --  manually because 1) the machinery in Exp_Ch7 will not pick it since
   --  it will be declared in the arm of a conditional statement and 2) we


[gcc r15-9793] ada: Incorrect unresolved operator name in an instantiation

2025-06-06 Thread Eric Botcazou via Gcc-cvs
https://gcc.gnu.org/g:1189522245be51d435fcc6d205e690f086f12e46

commit r15-9793-g1189522245be51d435fcc6d205e690f086f12e46
Author: Steve Baird 
Date:   Fri Feb 7 12:29:46 2025 -0800

ada: Incorrect unresolved operator name in an instantiation

In some cases, a generic containing a use of a unary operator successfully
compiles but the compiler incorrectly rejects the corresponding use in
an instantiation.

gcc/ada/ChangeLog:

* sem_ch4.adb
(Find_Unary_Types): Because we reanalyze names in an instance,
we sometimes have to take steps to filter out extraneous name
resolution candidates that happen to be visible at the point of the
instance declaration. Remove some code that appears to have been
written with this in mind. This is done for two reasons. First, the
code sometimes doesn't work (possibly because the In_Instance test
is not specific enough - it probably should be testing to see 
whether
we are in an instance of the particular generic in which the result
of calling Corresponding_Generic_Type was declared) and causes 
correct
code to be rejected. Second, the code seems to no longer be 
necessary
(possibly because of subsequent fixes in this area which are not
specific to unary operators).

Diff:
---
 gcc/ada/sem_ch4.adb | 25 ++---
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 406983995f3d..50b3eee0dbe5 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -7642,35 +7642,14 @@ package body Sem_Ch4 is
begin
   if not Is_Overloaded (R) then
  if Is_Numeric_Type (Etype (R)) then
-
---  In an instance a generic actual may be a numeric type even if
---  the formal in the generic unit was not. In that case, the
---  predefined operator was not a possible interpretation in the
---  generic, and cannot be one in the instance, unless the operator
---  is an actual of an instance.
-
-if In_Instance
-  and then
-not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
-then
-   null;
-else
-   Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
-end if;
+Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
  end if;
 
   else
  Get_First_Interp (R, Index, It);
  while Present (It.Typ) loop
 if Is_Numeric_Type (It.Typ) then
-   if In_Instance
- and then
-   not Is_Numeric_Type
- (Corresponding_Generic_Type (Etype (It.Typ)))
-   then
-  null;
-
-   elsif Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
+   if Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
then
   Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
end if;


[gcc r16-1206] ada: Fix for validity checking of limited scalar types

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:b449898970a502d31f30334cf0dd630f93d12bd8

commit r16-1206-gb449898970a502d31f30334cf0dd630f93d12bd8
Author: Piotr Trojanek 
Date:   Tue Jan 28 12:12:23 2025 +0100

ada: Fix for validity checking of limited scalar types

With a recent change we are now validity checking objects of private scalar
types, but need to handle private scalar types whose public view is limited.

gcc/ada/ChangeLog:

* checks.adb (Insert_Valid_Check): Set flag Assignment_OK in the 
object
declaration inserted for the validity checks.

Diff:
---
 gcc/ada/checks.adb | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index dcfcaa33bcc4..6a98292d1cc1 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -8163,6 +8163,7 @@ package body Checks is
   end if;
 
   declare
+ Decl   : Node_Id;
  CE : Node_Id;
  PV : Node_Id;
  Var_Id : Entity_Id;
@@ -8215,12 +8216,20 @@ package body Checks is
 Mutate_Ekind (Var_Id, E_Variable);
 Set_Etype (Var_Id, Typ);
 
-Insert_Action (Exp,
+Decl :=
   Make_Object_Declaration (Loc,
 Defining_Identifier => Var_Id,
 Object_Definition   => New_Occurrence_Of (Typ, Loc),
-Expression  => New_Copy_Tree (Exp)),
-  Suppress => Validity_Check);
+Expression  => New_Copy_Tree (Exp));
+
+--  We might be validity-checking object whose type is declared as
+--  limited but completion is a scalar type. We need to explicitly
+--  flag its assignment as OK, as otherwise it would be rejected by
+--  the language rules.
+
+Set_Assignment_OK (Decl);
+
+Insert_Action (Exp, Decl, Suppress => Validity_Check);
 
 Set_Validated_Object (Var_Id, New_Copy_Tree (Exp));


[gcc r16-1234] ada: Child unit subprograms are not primitive subprograms

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:5f0163fcc82e1862adef82d66ab876127751f8e3

commit r16-1234-g5f0163fcc82e1862adef82d66ab876127751f8e3
Author: Steve Baird 
Date:   Tue Feb 25 13:51:40 2025 -0800

ada: Child unit subprograms are not primitive subprograms

If a package declares a type and a child unit of that package is a 
subprogram
with a parameter (or function result) of that type, then that subprogram is
not a primitive subprogram of that type. Previously this was handled
incorrectly in some cases, leading to incorrect analysis of overriding
indicators.

gcc/ada/ChangeLog:

* sem_util.adb (Collect_Primitive_Operations): When collecting
primitive operations, do not include child unit subprograms.

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

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 42f852e336bd..fefb65c6733c 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -5717,6 +5717,7 @@ package body Sem_Util is
  or else Is_Primitive (Id))
   and then Parent_Kind (Parent (Id))
 not in N_Formal_Subprogram_Declaration
+  and then not Is_Child_Unit (Id)
 then
Is_Prim := False;


[gcc r16-1229] ada: Adjust the Android RTS config to match linux

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:c11a019108ceb6b45f707618a26b2846036bbec2

commit r16-1229-gc11a019108ceb6b45f707618a26b2846036bbec2
Author: Olivier Hainque 
Date:   Wed Feb 12 17:15:00 2025 +

ada: Adjust the Android RTS config to match linux

Android has many traits of Linux, reflected
by the gcc port triplets composition (-android-linux).

The Android Ada RTS was so far configured as a mostly "posix"
port, which happens to be very little tested, if at all.

This change reworks the Android Ada RTS to map a lot more closely
to that of a regular Linux target, a natural fit and much more toroughly
exercized.

This expects support of pthread rwlocks in the bionic libc,
which is there in the not-so-old-but-not-so-recent versions we
tested (Android 11 at least).

gcc/ada/ChangeLog:

* Makefile.rtl: Rework the Android pairs to match those of a
regular Linux port rather than a generic posix one.
* libgnarl/s-osinte__android.ads: Import pcrtl and add bindings
for the pthread_rwlock entry points, used by the Linux units now
in the libgnat target pairs.
* sysdep.c (__gnat_has_cap_sys_nice): Define for Android,
conservative return 0.
* adaint.c (__gnat_cpu_alloc): Define for Android as for Linux.

Diff:
---
 gcc/ada/Makefile.rtl   | 18 +++---
 gcc/ada/adaint.c   |  2 +-
 gcc/ada/libgnarl/s-osinte__android.ads | 64 +++---
 gcc/ada/sysdep.c   |  7 +++-
 4 files changed, 79 insertions(+), 12 deletions(-)

diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
index a26a725b3db1..bd36c31a1080 100644
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -1407,24 +1407,32 @@ ifeq ($(SELECTED_PAIRS),PAIRS_NONE)
 ifeq ($(strip $(filter-out arm% aarch64 linux-android%,$(target_cpu) 
$(target_os))),)
 
   LIBGNAT_TARGET_PAIRS = \
+  a-exetim.adb
 
 /* glibc versions earlier than 2.7 do not define the routines to handle
diff --git a/gcc/ada/libgnarl/s-osinte__android.ads 
b/gcc/ada/libgnarl/s-osinte__android.ads
index cd7e148933d9..d74589047e75 100644
--- a/gcc/ada/libgnarl/s-osinte__android.ads
+++ b/gcc/ada/libgnarl/s-osinte__android.ads
@@ -258,6 +258,14 @@ package System.OS_Interface is
function getpid return pid_t;
pragma Import (C, getpid, "getpid");
 
+   PR_SET_NAME : constant := 15;
+   PR_GET_NAME : constant := 16;
+
+   function prctl
+ (option : int;
+  arg: unsigned_long) return int;
+   pragma Import (C_Variadic_1, prctl, "prctl");
+
-
-- Threads --
-
@@ -276,9 +284,11 @@ package System.OS_Interface is
  new Ada.Unchecked_Conversion (unsigned_long, pthread_t);
 
subtype pthread_mutex_t   is System.OS_Locks.pthread_mutex_t;
+   type pthread_rwlock_t is limited private;
type pthread_cond_t   is limited private;
type pthread_attr_t   is limited private;
type pthread_mutexattr_t  is limited private;
+   type pthread_rwlockattr_t is limited private;
type pthread_condattr_t   is limited private;
type pthread_key_tis private;
 
@@ -287,11 +297,6 @@ package System.OS_Interface is
PTHREAD_SCOPE_PROCESS : constant := 1;
PTHREAD_SCOPE_SYSTEM  : constant := 0;
 
-   --  Read/Write lock not supported on Android.
-
-   subtype pthread_rwlock_t is pthread_mutex_t;
-   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
-
---
-- Stack --
---
@@ -389,6 +394,43 @@ package System.OS_Interface is
function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
 
+   function pthread_rwlockattr_init
+ (attr : access pthread_rwlockattr_t) return int;
+   pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init");
+
+   function pthread_rwlockattr_destroy
+ (attr : access pthread_rwlockattr_t) return int;
+   pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy");
+
+   PTHREAD_RWLOCK_PREFER_READER_NP  : constant := 0;
+   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 1;
+
+   --  No PTHREAD_RWLOCK_PREFER_WRITER_NP in Android's pthread.h API level 29
+
+   function pthread_rwlockattr_setkind_np
+ (attr : access pthread_rwlockattr_t;
+  pref : int) return int;
+   pragma Import
+ (C, pthread_rwlockattr_setkind_np, "pthread_rwlockattr_setkind_np");
+
+   function pthread_rwlock_init
+ (mutex : access pthread_rwlock_t;
+  attr  : access pthread_rwlockattr_t) return int;
+   pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init");
+
+   function pthread_rwlock_destroy
+ (mutex : access pthread_rwlock_t) return int;
+   pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy");
+
+   function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int;
+   p

[gcc r16-1240] ada: Refine subtypes in routines for building floating-point numbers

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:8013b4085527f9242f98ef1f47f7427efb7a20ea

commit r16-1240-g8013b4085527f9242f98ef1f47f7427efb7a20ea
Author: Piotr Trojanek 
Date:   Tue Feb 18 14:37:19 2025 +0100

ada: Refine subtypes in routines for building floating-point numbers

Propagate strict subtypes from callees to the caller; code cleanup.

gcc/ada/ChangeLog:

* cstand.adb (Build_Float_Type, Register_Float_Type): Refine
parameter subtypes.
* set_targ.ads (FPT_Mode_Entry): Refine component subtype.

Diff:
---
 gcc/ada/cstand.adb   | 10 +-
 gcc/ada/set_targ.ads |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/cstand.adb b/gcc/ada/cstand.adb
index 14c7496fa619..28c32690b48e 100644
--- a/gcc/ada/cstand.adb
+++ b/gcc/ada/cstand.adb
@@ -67,10 +67,10 @@ package body CStand is
 
procedure Build_Float_Type
  (E : Entity_Id;
-  Digs  : Int;
+  Digs  : Pos;
   Rep   : Float_Rep_Kind;
   Siz   : Int;
-  Align : Int);
+  Align : Nat);
--  Procedure to build standard predefined float base type. The first
--  parameter is the entity for the type. The second parameter is the
--  digits value. The third parameter indicates the representation to
@@ -192,10 +192,10 @@ package body CStand is
 
procedure Build_Float_Type
  (E : Entity_Id;
-  Digs  : Int;
+  Digs  : Pos;
   Rep   : Float_Rep_Kind;
   Siz   : Int;
-  Align : Int)
+  Align : Nat)
is
begin
   Set_Type_Definition (Parent (E),
@@ -2086,7 +2086,7 @@ package body CStand is
   Set_Defining_Identifier (New_Node (N_Full_Type_Declaration, Stloc), Ent);
   Set_Scope (Ent, Standard_Standard);
   Build_Float_Type
-(Ent, Pos (Digs), Float_Rep, Int (Size), Int (Alignment / 8));
+(Ent, Pos (Digs), Float_Rep, Int (Size), Nat (Alignment / 8));
 
   Append_New_Elmt (Ent, Back_End_Float_Types);
end Register_Float_Type;
diff --git a/gcc/ada/set_targ.ads b/gcc/ada/set_targ.ads
index b2e598fbb96b..e465c3ff5a15 100644
--- a/gcc/ada/set_targ.ads
+++ b/gcc/ada/set_targ.ads
@@ -93,7 +93,7 @@ package Set_Targ is
 
type FPT_Mode_Entry is record
   NAME  : String_Ptr; -- Name of mode (no null character at end)
-  DIGS  : Natural;-- Digits for floating-point type
+  DIGS  : Positive;   -- Digits for floating-point type
   FLOAT_REP : Float_Rep_Kind; -- Float representation
   PRECISION : Natural;-- Precision in bits
   SIZE  : Natural;-- Size in bits


[gcc r16-1242] ada: Tune style in code for floating-point numbers

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:268258b222502feddf365600ccd20967c4216209

commit r16-1242-g268258b222502feddf365600ccd20967c4216209
Author: Piotr Trojanek 
Date:   Tue Feb 18 14:36:53 2025 +0100

ada: Tune style in code for floating-point numbers

Cleanup whitespace and comments.

gcc/ada/ChangeLog:

* ada_get_targ.adb, cstand.ads, cstand.adb, sem_eval.adb, 
sem_eval.ads,
urealp.adb, urealp.ads: Tune style.

Diff:
---
 gcc/ada/ada_get_targ.adb |  9 ++--
 gcc/ada/cstand.adb   |  2 +-
 gcc/ada/cstand.ads   |  2 +-
 gcc/ada/sem_eval.adb |  2 +-
 gcc/ada/sem_eval.ads | 56 
 gcc/ada/urealp.adb   |  2 +-
 gcc/ada/urealp.ads   |  4 ++--
 7 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/gcc/ada/ada_get_targ.adb b/gcc/ada/ada_get_targ.adb
index 72e54520b28b..853197ad0024 100644
--- a/gcc/ada/ada_get_targ.adb
+++ b/gcc/ada/ada_get_targ.adb
@@ -219,9 +219,14 @@ package body Get_Targ is
begin
   Float_Str (Float_Str'First .. Float_Str'First + 4) := "float";
   Call_Back
-(C_Name => Float_Str, Digs => 6, Complex => False, Count  => 0,
+(C_Name=> Float_Str,
+ Digs  => 6,
+ Complex   => False,
+ Count => 0,
  Float_Rep => IEEE_Binary,
- Precision => 32, Size => 32, Alignment => 32);
+ Precision => 32,
+ Size  => 32,
+ Alignment => 32);
 
   Double_Str (Double_Str'First .. Double_Str'First + 5) := "double";
   Call_Back
diff --git a/gcc/ada/cstand.adb b/gcc/ada/cstand.adb
index 28c32690b48e..1dc06986e74d 100644
--- a/gcc/ada/cstand.adb
+++ b/gcc/ada/cstand.adb
@@ -2095,7 +2095,7 @@ package body CStand is
-- Set_Float_Bounds --
--
 
-   procedure Set_Float_Bounds (Id  : Entity_Id) is
+   procedure Set_Float_Bounds (Id : Entity_Id) is
   L : Node_Id;
   H : Node_Id;
   --  Low and high bounds of literal value
diff --git a/gcc/ada/cstand.ads b/gcc/ada/cstand.ads
index 62644fe546c0..bfd30526e114 100644
--- a/gcc/ada/cstand.ads
+++ b/gcc/ada/cstand.ads
@@ -42,7 +42,7 @@ package CStand is
--  The semantics info is in the format given by Entity_Info. The global
--  variables Last_Standard_Node_Id and Last_Standard_List_Id are also set.
 
-   procedure Set_Float_Bounds (Id  : Entity_Id);
+   procedure Set_Float_Bounds (Id : Entity_Id);
--  Procedure to set bounds for float type or subtype. Id is the entity
--  whose bounds and type are to be set (a floating-point type).
 
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index f5cd0449d617..fcab3e79d332 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -144,7 +144,7 @@ package body Sem_Eval is
Checking_For_Potentially_Static_Expression : Boolean := False;
--  Global flag that is set True during Analyze_Static_Expression_Function
--  in order to verify that the result expression of a static expression
-   --  function is a potentially static function (see RM2022 6.8(5.3)).
+   --  function is a potentially static function (see RM 2022 6.8(5.3)).
 
---
-- Local Subprograms --
diff --git a/gcc/ada/sem_eval.ads b/gcc/ada/sem_eval.ads
index 7df1c4c25e91..b6f44ef68332 100644
--- a/gcc/ada/sem_eval.ads
+++ b/gcc/ada/sem_eval.ads
@@ -301,34 +301,34 @@ package Sem_Eval is
--  is static or its value is known at compile time. This version is used
--  for string types and returns the corresponding N_String_Literal node.
 
-   procedure Eval_Actual (N : Node_Id);
-   procedure Eval_Allocator  (N : Node_Id);
-   procedure Eval_Arithmetic_Op  (N : Node_Id);
-   procedure Eval_Call   (N : Node_Id);
-   procedure Eval_Case_Expression(N : Node_Id);
-   procedure Eval_Character_Literal  (N : Node_Id);
-   procedure Eval_Concatenation  (N : Node_Id);
-   procedure Eval_Entity_Name(N : Node_Id);
-   procedure Eval_If_Expression  (N : Node_Id);
-   procedure Eval_Indexed_Component  (N : Node_Id);
-   procedure Eval_Integer_Literal(N : Node_Id);
-   procedure Eval_Logical_Op (N : Node_Id);
-   procedure Eval_Membership_Op  (N : Node_Id);
-   procedure Eval_Named_Integer  (N : Node_Id);
-   procedure Eval_Named_Real (N : Node_Id);
-   procedure Eval_Op_Expon   (N : Node_Id);
-   procedure Eval_Op_Not (N : Node_Id);
-   procedure Eval_Real_Literal   (N : Node_Id);
-   procedure Eval_Relational_Op  (N : Node_Id);
-   procedure Eval_Selected_Component (N : Node_Id);
-   procedure Eval_Shift  (N : Node_Id);
-   procedure Eval_Short_Circuit  (N : Node_Id);
-   procedure Eval_Slice  (N : Node_Id);
-   procedure Eval_String_Literal (N : Node_Id);
-   procedure Eval_Qualified_Expression   (N : Node_Id);
-   proc

[gcc r16-1244] ada: Remove repeated call in exponentiation of rational numbers

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:782d1cec98f0116797aecc80325f5c351c707d97

commit r16-1244-g782d1cec98f0116797aecc80325f5c351c707d97
Author: Piotr Trojanek 
Date:   Thu Feb 27 11:32:05 2025 +0100

ada: Remove repeated call in exponentiation of rational numbers

Code cleanup.

gcc/ada/ChangeLog:

* urealp.adb (UR_Exponentiate): Use local variable.

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

diff --git a/gcc/ada/urealp.adb b/gcc/ada/urealp.adb
index 446a65664f98..3a9fddea60b5 100644
--- a/gcc/ada/urealp.adb
+++ b/gcc/ada/urealp.adb
@@ -818,7 +818,7 @@ package body Urealp is
  return Store_Ureal
   ((Num  => Uint_1,
 Den  => -N,
-Rbase=> UI_To_Int (UR_Trunc (Bas)),
+Rbase=> UI_To_Int (IBas),
 Negative => Neg));
 
   --  If the exponent is negative then we raise the numerator and the


[gcc r16-1237] ada: Support aspect Program_Exit with no expression

2025-06-06 Thread Marc Poulhies via Gcc-cvs
https://gcc.gnu.org/g:8952d7caf9e6bd9b19dc4efb3af702c566d8e474

commit r16-1237-g8952d7caf9e6bd9b19dc4efb3af702c566d8e474
Author: Piotr Trojanek 
Date:   Thu Feb 13 16:39:43 2025 +0100

ada: Support aspect Program_Exit with no expression

New aspect Program_Exit for SPARK was originally designed to require an
expression, but now we want this expression to be optional.

gcc/ada/ChangeLog:

* aspects.ads (Aspect_Argument): Argument for Program_Exit is now
optional.
* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Program_Exit): Change documentation for pragma syntax.
* sem_prag.adb (Analyze_Pragma): Argument for Program_Exit is now
optional.
(Analyze_Program_Exit_In_Decl_Part): Likewise.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

Diff:
---
 gcc/ada/aspects.ads|  2 +-
 .../doc/gnat_rm/implementation_defined_pragmas.rst |  2 +-
 gcc/ada/gnat_rm.texi   |  2 +-
 gcc/ada/gnat_ugn.texi  |  2 +-
 gcc/ada/sem_prag.adb   | 83 --
 5 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads
index fc91ca23cbaf..5e61450748ff 100644
--- a/gcc/ada/aspects.ads
+++ b/gcc/ada/aspects.ads
@@ -482,7 +482,7 @@ package Aspects is
   Aspect_Predicate  => Expression,
   Aspect_Predicate_Failure  => Expression,
   Aspect_Priority   => Expression,
-  Aspect_Program_Exit   => Expression,
+  Aspect_Program_Exit   => Optional_Expression,
   Aspect_Put_Image  => Name,
   Aspect_Read   => Name,
   Aspect_Real_Literal   => Name,
diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst 
b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
index 50de68a4cea2..685bdde48a5d 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -5294,7 +5294,7 @@ Syntax:
 
 .. code-block:: ada
 
-  pragma Program_Exit (boolean_EXPRESSION);
+  pragma Program_Exit [ (boolean_EXPRESSION) ];
 
 For the semantics of this pragma, see the entry for aspect ``Program_Exit``
 in the SPARK 2014 Reference Manual, section 6.1.10.
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index fb7c6238856b..c67c198b8c4b 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -6942,7 +6942,7 @@ of error messages.
 Syntax:
 
 @example
-pragma Program_Exit (boolean_EXPRESSION);
+pragma Program_Exit [ (boolean_EXPRESSION) ];
 @end example
 
 For the semantics of this pragma, see the entry for aspect @code{Program_Exit}
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index ca1d7bcc1abf..5331a318c0d8 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29833,8 +29833,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
 @anchor{d2}@w{  }
+@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{   
   }
 
 @c %**end of body
 @bye
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index b35aa4aa2519..9964f70ce201 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -23640,7 +23640,7 @@ package body Sem_Prag is
  begin
 GNAT_Pragma;
 Check_No_Identifiers;
-Check_Arg_Count (1);
+Check_At_Most_N_Arguments (1);
 
 --  Ensure the proper placement of the pragma. Program_Exit must be
 --  associated with a subprogram declaration or a body that acts as
@@ -28413,8 +28413,8 @@ package body Sem_Prag is
is
   Subp_Decl : constant Node_Id   := Find_Related_Declaration_Or_Body (N);
   Spec_Id   : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
-
-  Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
+  Arg1  : constant Node_Id   :=
+First (Pragma_Argument_Associations (N));
 
   Saved_GM  : constant Ghost_Mode_Type := Ghost_Mode;
   Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
@@ -28440,56 +28440,61 @@ package body Sem_Prag is
 "for subprograms with side effects", N);
   end if;
 
-  --  Set the Ghost mode in effect from the pragma. Due to the delayed
-  --  analysis of the pragma, the Ghost mode at point of declaration and
-  --  point of analysis may not necessarily be the same. Use the mode in
-  --  effect at the point of declaration.
+  if Present (Arg1) then
 
-  Set_Ghost_Mode (N);
+ --  Set the Ghost mode in effect from the pragma. Due to the delayed
+ --  analysis of t

[gcc r15-9778] Fix regression from x86 multi-epilogue tuning

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:e93f02828faf7dc0df6a4d67b1b6b2a30bd713cb

commit r15-9778-ge93f02828faf7dc0df6a4d67b1b6b2a30bd713cb
Author: Richard Biener 
Date:   Wed May 14 16:36:29 2025 +0200

Fix regression from x86 multi-epilogue tuning

With the avx512_two_epilogues tuning enabled for zen4 and zen5
the gcc.target/i386/vect-epilogues-5.c testcase below regresses
and ends up using AVX2 sized vectors for the masked epilogue
rather than AVX512 sized vectors.  The following patch rectifies
this and adds coverage for the intended behavior.

* config/i386/i386.cc (ix86_vector_costs::finish_cost):
Do not suggest a first epilogue mode for AVX512 sized
main loops with X86_TUNE_AVX512_TWO_EPILOGUES as that
interferes with using a masked epilogue.

* gcc.target/i386/vect-epilogues-1.c: New testcase.
* gcc.target/i386/vect-epilogues-2.c: Likewise.
* gcc.target/i386/vect-epilogues-3.c: Likewise.
* gcc.target/i386/vect-epilogues-4.c: Likewise.
* gcc.target/i386/vect-epilogues-5.c: Likewise.

(cherry picked from commit 75c7f90bfe6fa8e6c1a70b784e98a3412861646d)

Diff:
---
 gcc/config/i386/i386.cc  | 10 +++---
 gcc/testsuite/gcc.target/i386/vect-epilogues-1.c | 14 ++
 gcc/testsuite/gcc.target/i386/vect-epilogues-2.c | 15 +++
 gcc/testsuite/gcc.target/i386/vect-epilogues-3.c | 15 +++
 gcc/testsuite/gcc.target/i386/vect-epilogues-4.c | 13 +
 gcc/testsuite/gcc.target/i386/vect-epilogues-5.c | 13 +
 6 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 38df84f7db24..a6f0a582c3d2 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -25545,14 +25545,10 @@ ix86_vector_costs::finish_cost (const vector_costs 
*scalar_costs)
   /* When X86_TUNE_AVX512_TWO_EPILOGUES is enabled arrange for both
  a AVX2 and a SSE epilogue for AVX512 vectorized loops.  */
   if (loop_vinfo
+  && LOOP_VINFO_EPILOGUE_P (loop_vinfo)
+  && GET_MODE_SIZE (loop_vinfo->vector_mode) == 32
   && ix86_tune_features[X86_TUNE_AVX512_TWO_EPILOGUES])
-{
-  if (GET_MODE_SIZE (loop_vinfo->vector_mode) == 64)
-   m_suggested_epilogue_mode = V32QImode;
-  else if (LOOP_VINFO_EPILOGUE_P (loop_vinfo)
-  && GET_MODE_SIZE (loop_vinfo->vector_mode) == 32)
-   m_suggested_epilogue_mode = V16QImode;
-}
+m_suggested_epilogue_mode = V16QImode;
   /* When a 128bit SSE vectorized epilogue still has a VF of 16 or larger
  enable a 64bit SSE epilogue.  */
   if (loop_vinfo
diff --git a/gcc/testsuite/gcc.target/i386/vect-epilogues-1.c 
b/gcc/testsuite/gcc.target/i386/vect-epilogues-1.c
new file mode 100644
index ..a7f5f12c71bc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vect-epilogues-1.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mavx2 -mno-avx512f -mtune=generic 
-fdump-tree-vect-optimized" } */
+
+int test (signed char *data, int n)
+{
+  int sum = 0;
+  for (int i = 0; i < n; ++i)
+sum += data[i];
+  return sum;
+}
+
+/* { dg-final { scan-tree-dump "loop vectorized using 32 byte vectors" "vect" 
} } */
+/* { dg-final { scan-tree-dump "loop vectorized using 16 byte vectors" "vect" 
} } */
+/* { dg-final { scan-tree-dump "loop vectorized using 8 byte vectors" "vect" { 
target { ! ia32 } } } } */
diff --git a/gcc/testsuite/gcc.target/i386/vect-epilogues-2.c 
b/gcc/testsuite/gcc.target/i386/vect-epilogues-2.c
new file mode 100644
index ..d6c06edcacd1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vect-epilogues-2.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mavx512bw -mtune=generic -fdump-tree-vect-optimized" } */
+
+int test (signed char *data, int n)
+{
+  int sum = 0;
+  for (int i = 0; i < n; ++i)
+sum += data[i];
+  return sum;
+}
+
+/* { dg-final { scan-tree-dump "loop vectorized using 64 byte vectors" "vect" 
} } */
+/* { dg-final { scan-tree-dump "loop vectorized using 32 byte vectors" "vect" 
} } */
+/* { dg-final { scan-tree-dump-not "loop vectorized using 16 byte vectors" 
"vect" } } */
+/* { dg-final { scan-tree-dump-not "loop vectorized using 8 byte vectors" 
"vect" } } */
diff --git a/gcc/testsuite/gcc.target/i386/vect-epilogues-3.c 
b/gcc/testsuite/gcc.target/i386/vect-epilogues-3.c
new file mode 100644
index ..0ee610f5e3ef
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/vect-epilogues-3.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mavx512bw -mtune=znver4 -fdump-tree-vect-optimized" } */
+
+int test (signed char *data, int n)
+{
+  int sum = 0;
+  for (int i = 0; i < n; ++i)
+sum += data[i];
+  return sum;
+}
+
+/* { dg-final { scan-tree-dump "loop vectorized using 64 byte vectors" "vect" 
} } */
+/* { dg-final { scan-tree-dump "loop vectorized using 32 byte vectors" "vect" 

[gcc r15-9788] libstdc++: Fix format call in formatting with empty specs for durations.

2025-06-06 Thread Tomasz Kaminski via Libstdc++-cvs
https://gcc.gnu.org/g:b2338ebf3e698589c69a521b4b4a7908dd959751

commit r15-9788-gb2338ebf3e698589c69a521b4b4a7908dd959751
Author: Tomasz Kamiński 
Date:   Wed Jun 4 11:05:11 2025 +0200

libstdc++: Fix format call in formatting with empty specs for durations.

This patches fixes an obvious error, where the output iterator argument was
missing for call to format_to, when duration with custom representation 
types
are used.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono:_M_s): Add missing
__out argument to format_to call.

Reviewed-by: Jonathan Wakely 
Signed-off-by: Tomasz Kamiński 
(cherry picked from commit ac0a04b7a254fb8e1d8d7088336bcb4375807b1e)

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index 7ab989f59a1c..32ef3533c720 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -1318,7 +1318,8 @@ namespace __format
  else
{
  auto __str = std::format(_S_empty_spec, __ss.count());
- __out = std::format_to(_GLIBCXX_WIDEN("{:0>{}s}"),
+ __out = std::format_to(std::move(__out),
+_GLIBCXX_WIDEN("{:0>{}s}"),
 __str,
 __hms.fractional_width);
}


[gcc r15-9790] gcn: Update --with-arch= for newer archs

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:a69ab79c1abaa43f827a6ce1dacdcd78cf682cc8

commit r15-9790-ga69ab79c1abaa43f827a6ce1dacdcd78cf682cc8
Author: Tobias Burnus 
Date:   Thu Jun 5 10:36:21 2025 +0200

gcn: Update --with-arch= for newer archs

Replace hard-coded list of supported devices by directly checking
config/gcn/gcn-devices.def.

gcc/ChangeLog:

* config.gcc (--with-{arch,tune}): Use .def file to validate gcn
processor names.
* doc/install.texi (amdgcn*-*-*): Update list of devices supported
by --with-arch/--with-tune.

(cherry picked from commit 61a6430cf663e3c980c2ee966f094fea7d99f8e7)

Diff:
---
 gcc/config.gcc   | 12 +---
 gcc/doc/install.texi | 10 +++---
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 40b50dc969ed..5725704e06be 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4598,15 +4598,13 @@ case "${target}" in
 
for which in arch tune; do
eval "val=\$with_$which"
-   case ${val} in
-   "" | gfx900 | gfx906 | gfx908 | gfx90a | gfx90c | 
gfx1030 | gfx1036 | gfx1100 | gfx1103)
-   # OK
-   ;;
-   *)
+   if test x"$val" != x \
+  && ! grep -q "GCN_DEVICE($val," \
+   "${srcdir}/config/gcn/gcn-devices.def";
+   then
echo "Unknown cpu used in --with-$which=$val." 
1>&2
exit 1
-   ;;
-   esac
+   fi
done
[ "x$with_arch" = x ] && with_arch=gfx900
 
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 1af0082ed772..3e9e09b4ae3e 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1342,9 +1342,13 @@ default set of libraries is selected based on the value 
of
 
 @item amdgcn*-*-*
 @var{list} is a comma separated list of ISA names (allowed values:
-@code{gfx900}, @code{gfx906}, @code{gfx908}, @code{gfx90a}, @code{gfx90c}, 
-@code{gfx1030}, @code{gfx1036}, @code{gfx1100}, @code{gfx1103}).
-It ought not include the name of the default
+@code{gfx900}, @code{gfx902}, @code{gfx904}, @code{gfx906}, @code{gfx908},
+@code{gfx909}, @code{gfx90a}, @code{gfx90c}, @code{gfx9-generic},
+@code{gfx1030}, @code{gfx1031}, @code{gfx1032}, @code{gfx1033},
+@code{gfx1034}, @code{gfx1035}, @code{gfx1036}, @code{gfx10-3-generic},
+@code{gfx1100}, @code{gfx1101}, @code{gfx1102}, @code{gfx1103},
+@code{gfx1150}, @code{gfx1151}, @code{gfx1152}, @code{gfx1153},
+@code{gfx11-generic}).  It ought not include the name of the default
 ISA, specified via @option{--with-arch}.  If @var{list} is empty, then there
 will be no multilibs and only the default run-time library will be built.  If
 @var{list} is @code{default} or @option{--with-multilib-list=} is not


[gcc r16-1254] libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:16c742e1079e838b920a1b215af17828da7c6365

commit r16-1254-g16c742e1079e838b920a1b215af17828da7c6365
Author: Tobias Burnus 
Date:   Fri Jun 6 15:15:03 2025 +0200

libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]

A mapping clause was missing, causing the code to fail with offloading
when a host pointer was not device accessible.

libgomp/ChangeLog:

PR target/120530
* testsuite/libgomp.c/target-map-zero-sized-3.c (main): Add missing
map clause; remove unused variable.

Diff:
---
 libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c 
b/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c
index f968bd377c2c..580c6ad89bf5 100644
--- a/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c
+++ b/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c
@@ -1,7 +1,7 @@
 int
 main ()
 {
-  int i, n, n2;
+  int i, n;
   int data[] = {1,2};
   struct S {
 int **ptrset;
@@ -33,16 +33,17 @@ main ()
 
   i = 1;
   n = 0;
-  n2 = 2;
+  #pragma omp target enter data map(data)
   #pragma omp target enter data map(sptr1[:1], sptr1->ptrset[:3], 
sptr1->ptrset2[:3])
   #pragma omp target enter data map(sptr1->ptrset[i][:n], 
sptr1->ptrset2[i][:n])
 
-  #pragma omp target
+  #pragma omp target map(sptr1->ptrset[i][:n], sptr1->ptrset2[i][:n])
 if (sptr1->ptrset2[1][0] != 1 || sptr1->ptrset2[1][1] != 2)
   __builtin_abort ();
 
   #pragma omp target exit data map(sptr1->ptrset[i][:n], sptr1->ptrset2[i][:n])
   #pragma omp target exit data map(sptr1[:1], sptr1->ptrset[:3], 
sptr1->ptrset2[:3])
+  #pragma omp target exit data map(data)
 
   __builtin_free (s1.ptrset);
   __builtin_free (s1.ptrset2);


[gcc r16-1253] Remove non-SLP path from vectorizable_store

2025-06-06 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:bcab27d1c5729b6d86b9008ddd8c9376b7a14623

commit r16-1253-gbcab27d1c5729b6d86b9008ddd8c9376b7a14623
Author: Richard Biener 
Date:   Fri Jun 6 12:22:36 2025 +0200

Remove non-SLP path from vectorizable_store

This prunes now unreachable paths from vectorizable_store,
eliminates the toplevel ncopies and loops that become non-loops.
And eliminates the use of STMT_VINFO_VECTYPE.

* tree-vect-stmts.cc (vectorizable_store): Remove non-SLP
paths.

Diff:
---
 gcc/tree-vect-stmts.cc | 1095 +++-
 1 file changed, 421 insertions(+), 674 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 3710694ac75d..c92dfdc52884 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -8352,12 +8352,10 @@ vectorizable_store (vec_info *vinfo,
   tree dataref_ptr = NULL_TREE;
   tree dataref_offset = NULL_TREE;
   gimple *ptr_incr = NULL;
-  int ncopies;
   int j;
   stmt_vec_info first_stmt_info;
   bool grouped_store;
   unsigned int group_size, i;
-  bool slp = (slp_node != NULL);
   unsigned int vec_num;
   bb_vec_info bb_vinfo = dyn_cast  (vinfo);
   tree aggr_type;
@@ -8403,7 +8401,7 @@ vectorizable_store (vec_info *vinfo,
return false;
 
   int mask_index = internal_fn_mask_index (ifn);
-  if (mask_index >= 0 && slp_node)
+  if (mask_index >= 0)
mask_index = vect_slp_child_index_for_operand
(call, mask_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
   if (mask_index >= 0
@@ -8415,9 +8413,9 @@ vectorizable_store (vec_info *vinfo,
 
   /* Cannot have hybrid store SLP -- that would mean storing to the
  same location twice.  */
-  gcc_assert (slp == PURE_SLP_STMT (stmt_info));
+  gcc_assert (PURE_SLP_STMT (stmt_info));
 
-  tree vectype = STMT_VINFO_VECTYPE (stmt_info), rhs_vectype = NULL_TREE;
+  tree vectype = SLP_TREE_VECTYPE (stmt_info), rhs_vectype = NULL_TREE;
   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
 
   if (loop_vinfo)
@@ -8428,20 +8426,10 @@ vectorizable_store (vec_info *vinfo,
   else
 vf = 1;
 
-  /* Multiple types in SLP are handled by creating the appropriate number of
- vectorized stmts for each SLP node.  Hence, NCOPIES is always 1 in
- case of SLP.  */
-  if (slp)
-ncopies = 1;
-  else
-ncopies = vect_get_num_copies (loop_vinfo, vectype);
-
-  gcc_assert (ncopies >= 1);
-
   /* FORNOW.  This restriction should be relaxed.  */
   if (loop
   && nested_in_vect_loop_p (loop, stmt_info)
-  && (ncopies > 1 || (slp && SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) > 1)))
+  && SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) > 1)
 {
   if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -8467,13 +8455,12 @@ vectorizable_store (vec_info *vinfo,
   poly_int64 poffset;
   internal_fn lanes_ifn;
   if (!get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask, 
vls_type,
-   ncopies, &memory_access_type, &poffset,
+   1, &memory_access_type, &poffset,
&alignment_support_scheme, &misalignment, &gs_info,
&lanes_ifn))
 return false;
 
-  if (slp_node
-  && slp_node->ldst_lanes
+  if (slp_node->ldst_lanes
   && memory_access_type != VMAT_LOAD_STORE_LANES)
 {
   if (dump_enabled_p ())
@@ -8520,8 +8507,7 @@ vectorizable_store (vec_info *vinfo,
 
   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
   grouped_store = (STMT_VINFO_GROUPED_ACCESS (stmt_info)
-  && memory_access_type != VMAT_GATHER_SCATTER
-  && (slp || memory_access_type != VMAT_CONTIGUOUS));
+  && memory_access_type != VMAT_GATHER_SCATTER);
   if (grouped_store)
 {
   first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
@@ -8546,8 +8532,7 @@ vectorizable_store (vec_info *vinfo,
   if (costing_p) /* transformation not required.  */
 {
   STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) = memory_access_type;
-  if (slp_node)
-   SLP_TREE_MEMORY_ACCESS_TYPE (slp_node) = memory_access_type;
+  SLP_TREE_MEMORY_ACCESS_TYPE (slp_node) = memory_access_type;
 
   if (loop_vinfo
  && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
@@ -8556,11 +8541,10 @@ vectorizable_store (vec_info *vinfo,
  memory_access_type, &gs_info,
  mask);
 
-  if (slp_node
- && (!vect_maybe_update_slp_op_vectype (op_node, vectype)
- || (mask
- && !vect_maybe_update_slp_op_vectype (mask_node,
-   mask_vectype
+  if (!vect_maybe_update_slp_op_vectype (op_node, vectype)
+ || (mask
+ && !vect_maybe_update_slp_op_vectype (mask_node,
+  

[gcc r16-1255] RISC-V: Combine vec_duplicate + vidvu.vv to vdivu.vx on GR2VR cost

2025-06-06 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:be205ec675ed79275e694dda90f0f97fc6ac0e7a

commit r16-1255-gbe205ec675ed79275e694dda90f0f97fc6ac0e7a
Author: Pan Li 
Date:   Fri Jun 6 09:33:21 2025 +0800

RISC-V: Combine vec_duplicate + vidvu.vv to vdivu.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vdivu.vv to the
vdivu.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

Assume we have example code like below, GR2VR cost is 0.

  #define DEF_VX_BINARY(T, OP)\
  void\
  test_vx_binary (T * restrict out, T * restrict in, T x, unsigned n) \
  {   \
for (unsigned i = 0; i < n; i++)  \
  out[i] = in[i] OP x;\
  }

  DEF_VX_BINARY(int32_t, /)

Before this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │ beq a3,zero,.L8
  12   │ vsetvli a5,zero,e32,m1,ta,ma
  13   │ vmv.v.x v2,a2
  14   │ sllia3,a3,32
  15   │ srlia3,a3,32
  16   │ .L3:
  17   │ vsetvli a5,a3,e32,m1,ta,ma
  18   │ vle32.v v1,0(a1)
  19   │ sllia4,a5,2
  20   │ sub a3,a3,a5
  21   │ add a1,a1,a4
  22   │ vdivu.vv v1,v1,v2
  23   │ vse32.v v1,0(a0)
  24   │ add a0,a0,a4
  25   │ bne a3,zero,.L3

After this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │ beq a3,zero,.L8
  12   │ sllia3,a3,32
  13   │ srlia3,a3,32
  14   │ .L3:
  15   │ vsetvli a5,a3,e32,m1,ta,ma
  16   │ vle32.v v1,0(a1)
  17   │ sllia4,a5,2
  18   │ sub a3,a3,a5
  19   │ add a1,a1,a4
  20   │ vdivu.vx v1,v1,a2
  21   │ vse32.v v1,0(a0)
  22   │ add a0,a0,a4
  23   │ bne a3,zero,.L3

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add new
case UDIV.
* config/riscv/riscv.cc (riscv_rtx_costs): Ditto.
* config/riscv/vector-iterators.md: Add new op divu.

Signed-off-by: Pan Li 

Diff:
---
 gcc/config/riscv/riscv-v.cc  | 1 +
 gcc/config/riscv/riscv.cc| 1 +
 gcc/config/riscv/vector-iterators.md | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index a41317f322f7..6a7eb7161b37 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -5568,6 +5568,7 @@ expand_vx_binary_vec_vec_dup (rtx op_0, rtx op_1, rtx 
op_2,
 case XOR:
 case MULT:
 case DIV:
+case UDIV:
   icode = code_for_pred_scalar (code, mode);
   break;
 default:
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 413eae05f4c9..99eeba64b6f9 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -3943,6 +3943,7 @@ riscv_rtx_costs (rtx x, machine_mode mode, int 
outer_code, int opno ATTRIBUTE_UN
  switch (GET_CODE (op))
{
case DIV:
+   case UDIV:
  *total = get_vector_binary_rtx_cost (op, scalar2vr_cost);
  break;
default:
diff --git a/gcc/config/riscv/vector-iterators.md 
b/gcc/config/riscv/vector-iterators.md
index 86f31f3afabb..36301b0be6e7 100644
--- a/gcc/config/riscv/vector-iterators.md
+++ b/gcc/config/riscv/vector-iterators.md
@@ -4042,7 +4042,7 @@
 ])
 
 (define_code_iterator any_int_binop_no_shift_v_vdup [
-  plus minus and ior xor mult div
+  plus minus and ior xor mult div udiv
 ])
 
 (define_code_iterator any_int_binop_no_shift_vdup_v [


[gcc r16-1256] RISC-V: Add test for vec_duplicate + vdivu.vv combine case 0 with GR2VR cost 0, 2 and 15

2025-06-06 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:2ca7622fd7b32fd538edea8fd8bd8b97ba07ef16

commit r16-1256-g2ca7622fd7b32fd538edea8fd8bd8b97ba07ef16
Author: Pan Li 
Date:   Fri Jun 6 09:49:56 2025 +0800

RISC-V: Add test for vec_duplicate + vdivu.vv combine case 0 with GR2VR 
cost 0, 2 and 15

Add asm dump check test for vec_duplicate + vdivu.vv combine to vdivu.vx,
with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
for vdivu.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add test
data for run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u8.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c   |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c   |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c  |   2 +
 .../gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c   |   2 +
 .../riscv/rvv/autovec/vx_vf/vx_binary_data.h   | 196 +
 .../riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u16.c|  15 ++
 .../riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u32.c|  15 ++
 .../riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u64.c|  15 ++
 .../riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u8.c |  15 ++
 17 files changed, 280 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c
index 7e107d30191d..92fbf227d563 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c
@@ -11,6 +11,7 @@ DEF_VX_BINARY_REVERSE_CASE_0_WRAP(T, -, rsub);
 DEF_VX_BINARY_CASE_0_WRAP(T, &, and)
 DEF_VX_BINARY_CASE_0_WRAP(T, |, or)
 DEF_VX_BINARY_CASE_0_WRAP(T, ^, xor)
+DEF_VX_BINARY_CASE_0_WRAP(T, /, div)
 
 /* { dg-final { scan-assembler-times {vadd.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vsub.vx} 1 } } */
@@ -18,3 +19,4 @@ DEF_VX_BINARY_CASE_0_WRAP(T, ^, xor)
 /* { dg-final { scan-assembler-times {vand.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vor.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vxor.vx} 1 } } */
+/* { dg-final { scan-assembler-times {vdivu.vx} 1 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c
index f8ffab78067a..f487b42820ee 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c
@@ -11,6 +11,7 @@ DEF_VX_BINARY_REVERSE_CASE_0_WRAP(T, -, rsub);
 DEF_VX_BINARY_CASE_0_WRAP(T, &, and)
 DEF_VX_BINARY_CASE_0_WRAP(T, |, or)
 DEF_VX_BINARY_CASE_0_WRAP(T, ^, xor)
+DEF_VX_BINARY_CASE_0_WRAP(T, /, div)
 
 /* { dg-final { scan-assembler-times {vadd.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vsub.vx} 1 } } */
@@ -18,3 +19,4 @@ DEF_VX_BINARY_CASE_0_WRAP(T, ^, xor)
 /* { dg-final { scan-assembler-times {vand.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vor.vx} 1 } } */
 /* { dg-final { scan-assembler-times {vxor.vx} 1 } } */
+/* { dg-final { scan-assembler-times {vdivu.vx} 1 } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c
index 31d294567e83..761d25c0833a 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c
@@ -11,

[gcc r16-1257] RISC-V: Add test for vec_duplicate + vdivu.vv combine case 1 with GR2VR cost 0, 1 and 2

2025-06-06 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:c01830fa809fa18d1d54b29a89cb65f3bb8f5676

commit r16-1257-gc01830fa809fa18d1d54b29a89cb65f3bb8f5676
Author: Pan Li 
Date:   Fri Jun 6 09:51:10 2025 +0800

RISC-V: Add test for vec_duplicate + vdivu.vv combine case 1 with GR2VR 
cost 0, 1 and 2

Add asm dump check test for vec_duplicate + vdivu.vv combine to vdivu.vx,
with the GR2VR cost is 0, 1 and 2.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c: Add asm check
for vdivu.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u8.c: Ditto.

Signed-off-by: Pan Li 

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u8.c  | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u16.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u32.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u64.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u8.c  | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u16.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u32.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u64.c | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u8.c  | 2 ++
 12 files changed, 24 insertions(+)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c
index 4bc0850f6737..58e4a1e96d6c 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c
@@ -11,6 +11,7 @@ DEF_VX_BINARY_REVERSE_CASE_1_WRAP(T, -, rsub, 
VX_BINARY_REVERSE_BODY_X16)
 DEF_VX_BINARY_CASE_1_WRAP(T, &, and, VX_BINARY_BODY_X16)
 DEF_VX_BINARY_CASE_1_WRAP(T, |, or, VX_BINARY_BODY_X16)
 DEF_VX_BINARY_CASE_1_WRAP(T, ^, xor, VX_BINARY_BODY_X16)
+DEF_VX_BINARY_CASE_1_WRAP(T, /, div, VX_BINARY_BODY_X16)
 
 /* { dg-final { scan-assembler {vadd.vx} } } */
 /* { dg-final { scan-assembler {vsub.vx} } } */
@@ -18,3 +19,4 @@ DEF_VX_BINARY_CASE_1_WRAP(T, ^, xor, VX_BINARY_BODY_X16)
 /* { dg-final { scan-assembler {vand.vx} } } */
 /* { dg-final { scan-assembler {vor.vx} } } */
 /* { dg-final { scan-assembler {vxor.vx} } } */
+/* { dg-final { scan-assembler {vdivu.vx} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c
index 255273d767f0..3d5f53568dbe 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c
@@ -11,6 +11,7 @@ DEF_VX_BINARY_REVERSE_CASE_1_WRAP(T, -, rsub, 
VX_BINARY_REVERSE_BODY_X4)
 DEF_VX_BINARY_CASE_1_WRAP(T, &, and, VX_BINARY_BODY_X4)
 DEF_VX_BINARY_CASE_1_WRAP(T, |, or, VX_BINARY_BODY_X4)
 DEF_VX_BINARY_CASE_1_WRAP(T, ^, xor, VX_BINARY_BODY_X4)
+DEF_VX_BINARY_CASE_1_WRAP(T, /, div, VX_BINARY_BODY_X4)
 
 /* { dg-final { scan-assembler {vadd.vx} } } */
 /* { dg-final { scan-assembler {vsub.vx} } } */
@@ -18,3 +19,4 @@ DEF_VX_BINARY_CASE_1_WRAP(T, ^, xor, VX_BINARY_BODY_X4)
 /* { dg-final { scan-assembler {vand.vx} } } */
 /* { dg-final { scan-assembler {vor.vx} } } */
 /* { dg-final { scan-assembler {vxor.vx} } } */
+/* { dg-final { scan-assembler {vdivu.vx} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c
index d21f61b49e73..0edb9257a7a7 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c
@@ -11,6 +11,7 @@ DEF_VX_BINARY_REVERSE_CASE_1_WRAP(T, -, rsub, 
VX_BINARY_REVERSE_BODY)
 DEF_VX_BINARY_CASE_1_WRAP(T, &, and, VX_BINARY_BODY)
 DEF_VX_BINARY_CASE_1_WRAP(T, |, or, VX_BINARY_BODY)
 DEF_VX_BINARY_CASE_1_WRAP(T, ^, xor, VX_BINARY_BODY)
+DEF_VX_BINARY_CASE_1_WRAP(T, /, div, VX_BINARY_BODY)
 
 /* { dg-final { scan-assembler {vadd.vx} } } */
 /* { dg-final { scan-assembler {vsub.vx} } } */
@@ -18,3 +19,4 @@ DEF_VX_BINARY_CASE_1_WRAP(T, ^, xor, VX_BINARY_BODY)
 /* { dg-final { scan-assembler {va

[gcc r15-9789] libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]

2025-06-06 Thread Patrick Palka via Gcc-cvs
https://gcc.gnu.org/g:e75e42f315e1e8bb4befee8ed242bd241c182091

commit r15-9789-ge75e42f315e1e8bb4befee8ed242bd241c182091
Author: Patrick Palka 
Date:   Fri Jun 6 09:34:17 2025 -0400

libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]

The const lvalue operator[] overload wasn't properly forwarding the key
type to the generic overload, causing a hard error for const keys.

Rather than correcting the forwarded type this patch just makes the
non-template overloads call try_emplace directly instead.  That way we
can remove the non-standard same_as constraint on the generic overload
and match the spec more closely.

PR libstdc++/120432

libstdc++-v3/ChangeLog:

* include/std/flat_map (flat_map::operator[]): Make the
non-template overloads call try_emplace directly.  Remove
non-standard same_as constraint on the template overload.
* testsuite/23_containers/flat_map/1.cc (test08): New test.

Reviewed-by: Tomasz Kamiński 
Reviewed-by: Jonathan Wakely 
(cherry picked from commit 91ed3248ce26aaaee4d7471aa4edbc07b3f1a90e)

Diff:
---
 libstdc++-v3/include/std/flat_map  |  6 +++---
 libstdc++-v3/testsuite/23_containers/flat_map/1.cc | 10 ++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/flat_map 
b/libstdc++-v3/include/std/flat_map
index 4bd4963c2ad7..de006ad1c533 100644
--- a/libstdc++-v3/include/std/flat_map
+++ b/libstdc++-v3/include/std/flat_map
@@ -1148,14 +1148,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // element access
   mapped_type&
   operator[](const key_type& __x)
-  { return operator[](__x); }
+  { return try_emplace(__x).first->second; }
 
   mapped_type&
   operator[](key_type&& __x)
-  { return operator[](std::move(__x)); }
+  { return try_emplace(std::move(__x)).first->second; }
 
   template
-   requires same_as, _Key> || 
__transparent_comparator<_Compare>
+   requires __transparent_comparator<_Compare>
mapped_type&
operator[](_Key2&& __x)
{ return try_emplace(std::forward<_Key2>(__x)).first->second; }
diff --git a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc 
b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
index 9d99796878e1..d7f27a05a878 100644
--- a/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
+++ b/libstdc++-v3/testsuite/23_containers/flat_map/1.cc
@@ -252,6 +252,15 @@ test07()
   VERIFY( std::ranges::equal(m, (std::pair[]){{3,4}}) );
 }
 
+void
+test08()
+{
+  // PR libstdc++/120432 - flat_map operator[] is broken for const lvalue keys
+  std::flat_map m;
+  const int k = 42;
+  m[k] = 0;
+}
+
 int
 main()
 {
@@ -265,4 +274,5 @@ main()
   test05();
   test06();
   test07();
+  test08();
 }


[gcc/devel/omp/gcc-15] Merge branch 'releases/gcc-15' into devel/omp/gcc-15

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:b9b7cf8e6a742d3528d661b0b5b299af8a666b8d

commit b9b7cf8e6a742d3528d661b0b5b299af8a666b8d
Merge: 54c4c4512085 a69ab79c1aba
Author: Tobias Burnus 
Date:   Fri Jun 6 15:47:31 2025 +0200

Merge branch 'releases/gcc-15' into devel/omp/gcc-15

Merge up to r15-9790-ga69ab79c1abaa4 (June 6, 2025)

Diff:

 gcc/ChangeLog  |   5 +
 gcc/DATESTAMP  |   2 +-
 gcc/ada/ChangeLog  |  88 
 .../gnat_rm/implementation_defined_attributes.rst  |   6 +-
 gcc/ada/exp_aggr.adb   | 498 +
 gcc/ada/exp_attr.adb   |  43 +-
 gcc/ada/exp_ch3.adb|  11 +-
 gcc/ada/exp_ch4.adb|  18 +-
 gcc/ada/exp_ch6.adb| 107 ++---
 gcc/ada/exp_ch7.adb|  15 +
 gcc/ada/gnat_rm.texi   |   6 +-
 gcc/ada/sem_attr.adb   |   5 +-
 gcc/ada/sem_ch3.adb|  11 +-
 gcc/ada/sem_res.adb|   2 +
 gcc/ada/sem_util.adb   | 140 --
 gcc/config.gcc |  12 +-
 gcc/config/i386/i386.cc|  10 +-
 gcc/cp/ChangeLog   |   6 +
 gcc/cp/lambda.cc   |   5 +-
 gcc/doc/install.texi   |  10 +-
 gcc/dse.cc |   5 +-
 gcc/fortran/ChangeLog  |  71 +++
 gcc/fortran/data.cc|   8 +-
 gcc/fortran/expr.cc| 110 -
 gcc/fortran/primary.cc |  64 ++-
 gcc/fortran/trans-types.cc |  31 +-
 gcc/testsuite/ChangeLog|  63 +++
 gcc/testsuite/g++.dg/cpp2a/concepts-lambda24.C |  13 +
 gcc/testsuite/gcc.dg/torture/pr120182.c|  42 ++
 gcc/testsuite/gcc.dg/torture/pr120341-1.c  |  11 +
 gcc/testsuite/gcc.dg/torture/pr120341-2.c  |  13 +
 gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-7.c   |   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-23.c  |  19 +
 gcc/testsuite/gcc.dg/vect/bb-slp-pr119960-1.c  |  15 +
 .../gcc.dg/vect/vect-early-break_136-pr120357.c|  13 +
 gcc/testsuite/gcc.target/i386/vect-epilogues-1.c   |  14 +
 gcc/testsuite/gcc.target/i386/vect-epilogues-2.c   |  15 +
 gcc/testsuite/gcc.target/i386/vect-epilogues-3.c   |  15 +
 gcc/testsuite/gcc.target/i386/vect-epilogues-4.c   |  13 +
 gcc/testsuite/gcc.target/i386/vect-epilogues-5.c   |  13 +
 gcc/testsuite/gfortran.dg/coarray_data_2.f90   |  14 +
 gcc/testsuite/gfortran.dg/guality/pr120193.f90 |  26 ++
 gcc/testsuite/gfortran.dg/inquiry_type_ref_7.f90   |  62 +++
 gcc/testsuite/gfortran.dg/inquiry_type_ref_8.f90   | 214 +
 gcc/testsuite/gnat.dg/specs/opt7.ads   |  15 +
 gcc/testsuite/gnat.dg/specs/opt7_pkg.adb   |  15 +
 gcc/testsuite/gnat.dg/specs/opt7_pkg.ads   |   9 +
 gcc/tree-ssa-loop-im.cc|   3 +-
 gcc/tree-ssa-phiopt.cc |   5 +-
 gcc/tree-ssa-threadbackward.cc |   8 +-
 gcc/tree-vect-data-refs.cc |   3 +-
 gcc/tree-vect-loop.cc  |   3 +-
 gcc/tree-vect-slp.cc   | 110 -
 gcc/tree-vectorizer.h  |  20 +-
 libgfortran/ChangeLog  |  11 +
 libstdc++-v3/include/bits/chrono_io.h  |   3 +-
 libstdc++-v3/include/std/flat_map  |   6 +-
 libstdc++-v3/testsuite/23_containers/flat_map/1.cc |  10 +
 58 files changed, 1647 insertions(+), 440 deletions(-)


[gcc/devel/omp/gcc-15] (40 commits) ChangeLog.omp bump

2025-06-06 Thread Tobias Burnus via Gcc-cvs
The branch 'devel/omp/gcc-15' was updated to point to:

 f34abf47bf57... ChangeLog.omp bump

It previously pointed to:

 54c4c4512085... ChangeLog.omp bump

Diff:

Summary of changes (added commits):
---

  f34abf4... ChangeLog.omp bump
  5f56185... OpenMP: Add omp_get_initial_device/omp_get_num_devices buil
  c8963f0... builtins.def: Enable OpenMP/OpenACC builtins also with -fno
  76e0b6c... libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM o
  b9b7cf8... Merge branch 'releases/gcc-15' into devel/omp/gcc-15
  a69ab79... gcn: Update --with-arch= for newer archs (*)
  e75e42f... libstdc++: Fix flat_map::operator[] for const lvalue keys [ (*)
  b2338eb... libstdc++: Fix format call in formatting with empty specs f (*)
  8cb0127... tree-optimization/120357 - ICE with early break vectorizati (*)
  09884fa... tree-optimization/120341 - stores into STRING_CSTs can trap (*)
  44792a6... rtl-optimization/120182 - wrong-code with RTL DSE and const (*)
  ca8032d... Fix gcc.dg/tree-ssa/ssa-dom-thread-7.c for aarch64 (*)
  4d375eb... tree-optimization/120003 - missed jump threading (*)
  8fb3d90... tree-optimization/119960 - failed external SLP promotion (*)
  7da2b6d... tree-optimization/116352 - amend previous fix (*)
  05ef04d... tree-optimization/119960 - add validity checking to SLP sch (*)
  6bb3169... tree-optimization/119960 - fix and guard get_later_stmt (*)
  e93f028... Fix regression from x86 multi-epilogue tuning (*)
  6346562... Daily bump. (*)
  d056ac5... ada: Spurious compilation error with repeated loop index (*)
  48a5910... ada: Exception-raising loop incorrectly eliminated (*)
  257a8dc... ada: Fix crash on access to protected return (*)
  6b1c8f4... ada: Tweak caching of streaming subprograms (*)
  b7e10f8... ada: Implement built-in-place expansion of two-pass array a (*)
  9f9476c... ada: Reject Valid_Value arguments originating from Standard (*)
  a871b23... ada: Error about assignment to limited target on aggregate  (*)
  09b0aac... ada: Fix buffer overflow for function call returning discri (*)
  5738c9b... ada: Fix compile-time failure due to duplicated attribute s (*)
  29447fb... ada: Avoid calling Resolve with Stand.Any_Fixed as the expe (*)
  a52223c... ada: Compiler crash on array aggregate association iteratin (*)
  d9fb0b4... Fix crash with constant initializer caused by IPA (*)
  ea8d197... Daily bump. (*)
  c77dd2d... Fortran: ICE due to missing locus with data statement for c (*)
  55a9203... Daily bump. (*)
  e8a36b0... Fortran: parameter inquiries of constant complex arrays [PR (*)
  819b641... Fortran: fix regression introduced by commit r16-914-g787a8 (*)
  25e4642... Fortran: fix parsing of type parameter inquiries of substri (*)
  1299fd3... Daily bump. (*)
  c096341... c++: lambda this capture and requires [PR120123] (*)
  fff23f4... fortran: Fix debug info for unsigned(kind=1) and unsigned(k (*)

(*) This commit already exists in another branch.
Because the reference `refs/heads/devel/omp/gcc-15' matches
your hooks.email-new-commits-only configuration,
no separate email is sent for this commit.


[gcc/devel/omp/gcc-15] OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:5f56185a23e4e6d417091ba21f9eac4d0b4da239

commit 5f56185a23e4e6d417091ba21f9eac4d0b4da239
Author: Tobias Burnus 
Date:   Fri Jun 6 16:22:06 2025 +0200

OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins

By adding omp_get_initial_device and omp_get_num_devices builtins for
C, C++, and Fortran, the following can be achieved:
* By making them pure, multiple calls can be avoiding in some cases.
* Some comparisons can be optimized at compile time.

omp_get_initial_device will be converted to omp_get_num_devices for
consistency; note that OpenMP 6 also permits omp_initial_device (== -1)
as value.

If GCC has not been configure for offloading, either intrinsic will
leads to 0 - and on the offload side, -1 (= omp_initial_device) is
returned for omp_initial_device.

gcc/fortran/ChangeLog:

* f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define.
* trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices
and omp_get_intrinsic_device.
* gfortran.h (gfc_option_t): Add disable_omp_... for them.
* options.cc (gfc_handle_option): Handle them with
-fno-builtin-.

gcc/ChangeLog:

* gimple-fold.cc (gimple_fold_builtin_omp_get_initial_device,
gimple_fold_builtin_omp_get_num_devices): New.
(gimple_fold_builtin): Call them.
* omp-builtins.def (BUILT_IN_OMP_GET_INITIAL_DEVICE): Add
(BUILT_IN_OMP_GET_NUM_DEVICES): Make uservisible + pure.

libgomp/ChangeLog:

* libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device):
Document builtin handling.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New 
test.
* c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New 
test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test.

Co-authored-by: Sandra Loosemore 
(cherry picked from commit 387209938d2c476a67966c6ddbdbf817626f24a2)

Diff:
---
 gcc/fortran/f95-lang.cc|  3 +-
 gcc/fortran/gfortran.h |  6 ++--
 gcc/fortran/options.cc |  4 +++
 gcc/fortran/trans-expr.cc  | 10 ++
 gcc/gimple-fold.cc | 40 ++
 gcc/omp-builtins.def   |  9 +++--
 .../gomp/omp_get_num_devices_initial_device-2.c| 29 
 .../gomp/omp_get_num_devices_initial_device.c  | 32 +
 .../gomp/omp_get_num_devices_initial_device-2.f90  | 21 
 .../gomp/omp_get_num_devices_initial_device.f90| 24 +
 libgomp/libgomp.texi   | 14 
 11 files changed, 186 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/f95-lang.cc b/gcc/fortran/f95-lang.cc
index 3808fed69c16..3b6610ec5aeb 100644
--- a/gcc/fortran/f95-lang.cc
+++ b/gcc/fortran/f95-lang.cc
@@ -571,7 +571,7 @@ gfc_builtin_function (tree decl)
   return decl;
 }
 
-/* So far we need just these 10 attribute types.  */
+/* So far we need just these 12 attribute types.  */
 #define ATTR_NULL  0
 #define ATTR_LEAF_LIST (ECF_LEAF)
 #define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
@@ -587,6 +587,7 @@ gfc_builtin_function (tree decl)
 #define ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST \
(ECF_COLD | ECF_NORETURN | \
 ECF_NOTHROW | ECF_LEAF)
+#define ATTR_PURE_NOTHROW_LIST (ECF_PURE | ECF_NOTHROW)
 
 static void
 gfc_define_builtin (const char *name, tree type, enum built_in_function code,
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 903712a2ac90..aa44571cde63 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -3338,8 +3338,10 @@ typedef struct
   int flag_init_logical;
   int flag_init_character;
   char flag_init_character_value;
-  bool disable_omp_is_initial_device;
-  bool disable_acc_on_device;
+  bool disable_omp_is_initial_device:1;
+  bool disable_omp_get_initial_device:1;
+  bool disable_omp_get_num_devices:1;
+  bool disable_acc_on_device:1;
 
   int fpe;
   int fpe_summary;
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index c1c2833f..d3c9066630b7 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -883,6 +883,10 @@ gfc_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
return false;  /* Not supported. */
   if (!strcmp ("omp_is_initial_device", arg))
gfc_option.disable_omp_is_initial_device = true;
+  else if (!strcmp ("omp_get_initial_device", arg))
+   gfc_option.disable_omp_get_initial_device = true;
+  else if (!strcmp (

[gcc/devel/omp/gcc-15] libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:76e0b6c20dc54d7a6f704a4bddd824f4c8d90c2c

commit 76e0b6c20dc54d7a6f704a4bddd824f4c8d90c2c
Author: Tobias Burnus 
Date:   Fri Jun 6 15:15:03 2025 +0200

libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]

A mapping clause was missing, causing the code to fail with offloading
when a host pointer was not device accessible.

libgomp/ChangeLog:

PR target/120530
* testsuite/libgomp.c/target-map-zero-sized-3.c (main): Add missing
map clause; remove unused variable.

(cherry picked from commit 16c742e1079e838b920a1b215af17828da7c6365)

Diff:
---
 libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c 
b/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c
index f968bd377c2c..580c6ad89bf5 100644
--- a/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c
+++ b/libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c
@@ -1,7 +1,7 @@
 int
 main ()
 {
-  int i, n, n2;
+  int i, n;
   int data[] = {1,2};
   struct S {
 int **ptrset;
@@ -33,16 +33,17 @@ main ()
 
   i = 1;
   n = 0;
-  n2 = 2;
+  #pragma omp target enter data map(data)
   #pragma omp target enter data map(sptr1[:1], sptr1->ptrset[:3], 
sptr1->ptrset2[:3])
   #pragma omp target enter data map(sptr1->ptrset[i][:n], 
sptr1->ptrset2[i][:n])
 
-  #pragma omp target
+  #pragma omp target map(sptr1->ptrset[i][:n], sptr1->ptrset2[i][:n])
 if (sptr1->ptrset2[1][0] != 1 || sptr1->ptrset2[1][1] != 2)
   __builtin_abort ();
 
   #pragma omp target exit data map(sptr1->ptrset[i][:n], sptr1->ptrset2[i][:n])
   #pragma omp target exit data map(sptr1[:1], sptr1->ptrset[:3], 
sptr1->ptrset2[:3])
+  #pragma omp target exit data map(data)
 
   __builtin_free (s1.ptrset);
   __builtin_free (s1.ptrset2);


[gcc/devel/omp/gcc-15] ChangeLog.omp bump

2025-06-06 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:f34abf47bf57179eeb6f77355ad1549c89a58733

commit f34abf47bf57179eeb6f77355ad1549c89a58733
Author: Tobias Burnus 
Date:   Fri Jun 6 16:58:25 2025 +0200

ChangeLog.omp bump

Diff:
---
 gcc/ChangeLog.omp   | 20 
 gcc/DATESTAMP.omp   |  2 +-
 gcc/fortran/ChangeLog.omp   | 13 +
 gcc/testsuite/ChangeLog.omp | 11 +++
 libgomp/ChangeLog.omp   | 18 ++
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index d5b60db31bab..6ac795bf4c33 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,23 @@
+2025-06-06  Tobias Burnus  
+
+   Backported from master:
+   2025-06-06  Tobias Burnus  
+   Sandra Loosemore  
+
+   * gimple-fold.cc (gimple_fold_builtin_omp_get_initial_device,
+   gimple_fold_builtin_omp_get_num_devices): New.
+   (gimple_fold_builtin): Call them.
+   * omp-builtins.def (BUILT_IN_OMP_GET_INITIAL_DEVICE): Add
+   (BUILT_IN_OMP_GET_NUM_DEVICES): Make uservisible + pure.
+
+2025-06-06  Tobias Burnus  
+
+   Backported from master:
+   2025-06-06  Tobias Burnus  
+
+   * builtins.def (DEF_GOACC_BUILTIN_COMPILER, DEF_GOMP_BUILTIN_COMPILER):
+   Set NONANSI_P = false to enable those also with -fno-nonansi-builtins.
+
 2025-06-05  Sandra Loosemore  
 
Backported from master:
diff --git a/gcc/DATESTAMP.omp b/gcc/DATESTAMP.omp
index 520e78d76964..c6de4e349988 100644
--- a/gcc/DATESTAMP.omp
+++ b/gcc/DATESTAMP.omp
@@ -1 +1 @@
-20250605
+20250606
diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 05c8e3f40057..7c5eee2b86e4 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,16 @@
+2025-06-06  Tobias Burnus  
+
+   Backported from master:
+   2025-06-06  Tobias Burnus  
+   Sandra Loosemore  
+
+   * f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define.
+   * trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices
+   and omp_get_intrinsic_device.
+   * gfortran.h (gfc_option_t): Add disable_omp_... for them.
+   * options.cc (gfc_handle_option): Handle them with
+   -fno-builtin-.
+
 2025-05-15  Sandra Loosemore  
Tobias Burnus  
 
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index d82620804163..1684f7a388cf 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,14 @@
+2025-06-06  Tobias Burnus  
+
+   Backported from master:
+   2025-06-06  Tobias Burnus  
+   Sandra Loosemore  
+
+   * c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New test.
+   * c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test.
+   * gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New test.
+   * gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test.
+
 2025-06-05  Sandra Loosemore  
 
Backported from master:
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 5ecab6d05e98..e25761590956 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,21 @@
+2025-06-06  Tobias Burnus  
+
+   Backported from master:
+   2025-06-06  Tobias Burnus  
+   Sandra Loosemore  
+
+   * libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device):
+   Document builtin handling.
+
+2025-06-06  Tobias Burnus  
+
+   Backported from master:
+   2025-06-06  Tobias Burnus  
+
+   PR target/120530
+   * testsuite/libgomp.c/target-map-zero-sized-3.c (main): Add missing
+   map clause; remove unused variable.
+
 2025-05-30  Thomas Schwinge  
 
* testsuite/libgomp.c++/target-flex-300.C: XFAIL.


  1   2   >