[gcc r15-6545] Fortran: Cray pointer comparison wrongly optimized away [PR106692]

2025-01-03 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:c7754a2fb2e60987524947fe189f3ffac035ea1d

commit r15-6545-gc7754a2fb2e60987524947fe189f3ffac035ea1d
Author: Harald Anlauf 
Date:   Thu Jan 2 20:22:23 2025 +0100

Fortran: Cray pointer comparison wrongly optimized away [PR106692]

PR fortran/106692

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_expr_op): Inhibit excessive optimization
of Cray pointers by treating them as volatile in comparisons.

gcc/testsuite/ChangeLog:

* gfortran.dg/cray_pointers_13.f90: New test.

Diff:
---
 gcc/fortran/trans-expr.cc  | 13 +++
 gcc/testsuite/gfortran.dg/cray_pointers_13.f90 | 51 ++
 2 files changed, 64 insertions(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f73e04bfd1d4..bc24105ce329 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -4150,6 +4150,19 @@ gfc_conv_expr_op (gfc_se * se, gfc_expr * expr)
 
   if (lop)
 {
+  // Inhibit overeager optimization of Cray pointer comparisons (PR106692).
+  if (expr->value.op.op1->expr_type == EXPR_VARIABLE
+ && expr->value.op.op1->ts.type == BT_INTEGER
+ && expr->value.op.op1->symtree
+ && expr->value.op.op1->symtree->n.sym->attr.cray_pointer)
+   TREE_THIS_VOLATILE (lse.expr) = 1;
+
+  if (expr->value.op.op2->expr_type == EXPR_VARIABLE
+ && expr->value.op.op2->ts.type == BT_INTEGER
+ && expr->value.op.op2->symtree
+ && expr->value.op.op2->symtree->n.sym->attr.cray_pointer)
+   TREE_THIS_VOLATILE (rse.expr) = 1;
+
   /* The result of logical ops is always logical_type_node.  */
   tmp = fold_build2_loc (input_location, code, logical_type_node,
 lse.expr, rse.expr);
diff --git a/gcc/testsuite/gfortran.dg/cray_pointers_13.f90 
b/gcc/testsuite/gfortran.dg/cray_pointers_13.f90
new file mode 100644
index ..766d24546ab2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/cray_pointers_13.f90
@@ -0,0 +1,51 @@
+! { dg-do run }
+! { dg-additional-options "-fcray-pointer" }
+!
+! PR fortran/106692 - Cray pointer comparison wrongly optimized away
+!
+! Contributed by Marek Polacek
+
+program test
+  call test_cray()
+  call test_cray2()
+end
+
+subroutine test_cray()
+  pointer(ptrzz1 , zz1)
+  ptrzz1=0
+  if (ptrzz1 .ne. 0) then
+print *, "test_cray: ptrzz1=", ptrzz1
+stop 1
+  else
+call shape_cray(zz1)
+  end if
+end
+
+subroutine shape_cray(zz1)
+  pointer(ptrzz , zz)
+  ptrzz=loc(zz1)
+  if (ptrzz .ne. 0) then
+print *, "shape_cray: ptrzz=", ptrzz
+stop 3
+  end if
+end
+
+subroutine test_cray2()
+  pointer(ptrzz1 , zz1)
+  ptrzz1=0
+  if (0 == ptrzz1) then
+call shape_cray2(zz1)
+  else
+print *, "test_cray2: ptrzz1=", ptrzz1
+stop 2
+  end if
+end
+
+subroutine shape_cray2(zz1)
+  pointer(ptrzz , zz)
+  ptrzz=loc(zz1)
+  if (.not. (0 == ptrzz)) then
+print *, "shape_cray2: ptrzz=", ptrzz
+stop 4
+  end if
+end


[gcc r15-6546] testsuite: torture: add LLVM testcase for DSE vs. -ftrivial-auto-var-init=

2025-01-03 Thread Sam James via Gcc-cvs
https://gcc.gnu.org/g:26ca00eeedb01f9d5102586b76ae2a6e787111af

commit r15-6546-g26ca00eeedb01f9d5102586b76ae2a6e787111af
Author: Sam James 
Date:   Fri Dec 13 04:42:29 2024 +

testsuite: torture: add LLVM testcase for DSE vs. -ftrivial-auto-var-init=

This testcase came up in a recent LLVM bug report [0] for DSE vs
-ftrivial-auto-var-init=. Add it to our testsuite given that area
could do with better coverage.

[0] https://github.com/llvm/llvm-project/issues/119646

gcc/testsuite/ChangeLog:

* gcc.dg/torture/dse-trivial-auto-var-init.c: New test.

Co-authored-by: Andrew Pinski 

Diff:
---
 .../gcc.dg/torture/dse-trivial-auto-var-init.c  | 17 +
 1 file changed, 17 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c 
b/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
new file mode 100644
index ..5a3d4c4e3ecb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/dse-trivial-auto-var-init.c
@@ -0,0 +1,17 @@
+/* Testcase for LLVM bug: https://github.com/llvm/llvm-project/issues/119646 */
+/* { dg-do run } */
+/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
+
+int b = 208;
+[[gnu::noinline]]
+void f(int *e, int a) {
+  *e = !!b;
+  if (a)
+__builtin_trap();
+}
+int main(void) {
+  b = 0;
+  f(&b, 0);
+  if (b != 0)
+__builtin_trap();
+}


[gcc r15-6554] MMIX: Replace format for private symbol output by output-time adjustment

2025-01-03 Thread Hans-Peter Nilsson via Gcc-cvs
https://gcc.gnu.org/g:8395cf72b49f1418deccc92c50accd2464177a45

commit r15-6554-g8395cf72b49f1418deccc92c50accd2464177a45
Author: Hans-Peter Nilsson 
Date:   Fri Jan 3 18:25:36 2025 +0100

MMIX: Replace format for private symbol output by output-time adjustment

All this started with belated MMIX regression patrol in observance of
the holidays, looking at gcc.dg/Wstringop-overflow-27.c as a
regression for target mmix.  That's because of a single message not
matched, where there is "note: destination object 'vla::22'" instead
of the expected "note: destination object 'vla'" due to
r11-5523-geafe8ee7af13c3 in which the message format and the match
changed.

That ::22 is because some identifiers that are SSA_NAME-versions and
other clones are "privatized" by ASM_FORMAT_PRIVATE_NAME and its
companion macro by default, ASM_PN_FORMAT; see the patch.  I found
that these "private names" were "unprivatized" for the purpose of
warnings and error messages *in code that only handles the default
format*, "%s.%lu".

I went ahead and wrote and tested a patch-set to hookize that
unprivatizing code, but found that it would only affect errors and
warnings; dumps still had the "target format".  While having bad
thoughts about being hit by yet another structural testism because of
the choice of outputting yet another target-specific format instead of
a canonical "versioned" format, I realized it *already was handling a
canonical format*: only the default "%s.%lu" is properly handled.

To wit, targets are better off with the default "%s.%lu" and adjusting
it (if needed, including not allowing "." or "$"), *at time of
assembly code output*.  IOW, outputs, both references and definitions,
pass a single label-output target code point: ASM_OUTPUT_LABELREF,
which is that time of output.  Some older testsuite adjustments need
to be unadjusted, but is another rabbit-hole, so I've kept that change
separate.  Other tests checking dumps, now started to pass for the
first time, some 20+.

* config/mmix/mmix.cc (mmix_asm_output_labelref): Replace '.'
with '::'.
* config/mmix/mmix.h (ASM_PN_FORMAT): Define to actual default.

Diff:
---
 gcc/config/mmix/mmix.cc | 29 +
 gcc/config/mmix/mmix.h  | 10 +-
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/gcc/config/mmix/mmix.cc b/gcc/config/mmix/mmix.cc
index 13b6c39c7678..e167ffcb6609 100644
--- a/gcc/config/mmix/mmix.cc
+++ b/gcc/config/mmix/mmix.cc
@@ -1586,6 +1586,35 @@ mmix_asm_output_labelref (FILE *stream, const char *name)
 if (*name == '@')
   is_extern = 0;
 
+  size_t ndots = 0;
+  for (const char *s = name; *s != 0; s++)
+if (*s == '.')
+  ndots++;
+
+  /* Replace all '.' with '::'.  We don't want a '.' as part of an identifier
+ as that'd be incompatible with mmixal.  We also don't want to do things
+ like overriding the default "%s.%lu" by '#define ASM_PN_FORMAT "%s::%lu"'
+ as that format will show up in warnings and error messages.  The default
+ won't show up in warnings and errors, as there are mechanisms in place to
+ strip that (but that only handles the default format).  FIXME: Make sure
+ no ":" is seen in the object file; we don't really want that mmixal
+ feature visible there.  */
+  if (ndots > 0)
+{
+  char *colonized_name = XALLOCAVEC (char, strlen (name) + 1 + ndots);
+
+  char *cs = colonized_name;
+  const char *s = name;
+  for (; *s != 0; s++)
+   {
+ if (*s == '.')
+   *cs++ = ':';
+ *cs++ = *s;
+   }
+  *cs = 0;
+  name = colonized_name;
+}
+
   asm_fprintf (stream, "%s%U%s",
   is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
   name);
diff --git a/gcc/config/mmix/mmix.h b/gcc/config/mmix/mmix.h
index 47db27594d7a..44669e195b4a 100644
--- a/gcc/config/mmix/mmix.h
+++ b/gcc/config/mmix/mmix.h
@@ -656,11 +656,11 @@ typedef struct { int regs; int lib; } CUMULATIVE_ARGS;
 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
  sprintf (LABEL, "*%s:%ld", PREFIX, (long)(NUM))
 
-/* Insert "::"; these are rarer than internal labels.  FIXME: Make sure no
-   ":" is seen in the object file; we don't really want that mmixal
-   feature visible there.  We don't want the default, which uses a dot;
-   that'd be incompatible with mmixal.  */
-#define ASM_PN_FORMAT "%s::%lu"
+/* Override the default, which looks at NO_DOT_IN_LABEL and NO_DOLLAR_IN_LABEL.
+   We want the real default "%s.%lu" in dumps and compiler messages, but the
+   actual assembly code format is adjusted to the effect of "%s::%lu".  See
+   mmix_asm_output_labelref.  */
+#define ASM_PN_FORMAT "%s.%lu"
 
 #define ASM_OUTPUT_DEF(STREAM, NAME, VALUE) \
  mmix_asm_output_def (STREAM, NAME, VALUE)


[gcc r15-6555] testsuite: Replace MMIX-specific adjustments with TARGET_CALLEE_COPIES-adjustments

2025-01-03 Thread Hans-Peter Nilsson via Gcc-cvs
https://gcc.gnu.org/g:ea228f22be816023def6cdb48e9f10a60f370833

commit r15-6555-gea228f22be816023def6cdb48e9f10a60f370833
Author: Hans-Peter Nilsson 
Date:   Fri Jan 3 18:34:14 2025 +0100

testsuite: Replace MMIX-specific adjustments with 
TARGET_CALLEE_COPIES-adjustments

With the dump now emitting "privatized symbols" in the default
"%s.%lu" format also for MMIX, there's still a difference for MMIX.
This time it's because numbers have changed (copies introduced before
this point) because it has TARGET_CALLEE_COPIES yielding true.
Redundant copies may have been elided at this point, but the change
in name remains.

Since that's true for other targets too, an obvious change is to
generalize the tested patterns to include TARGET_CALLEE_COPIES-true
targets, as a brief inspection of the history of these tests shows
that the point of these tests lie not in whether copies have been done
but in the part of the pattern that match a constant.

Also fixed up a "." where there should have been a "\\.".

* gcc.dg/tree-ssa/vector-4.c: Replace MMIX adjustments with
TARGET_CALLEE_COPIES-agnostic adjustments.
* gcc.dg/tree-ssa/forwprop-36.c: Ditto.  Correct pattern to match a
literal ".".

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c | 3 +--
 gcc/testsuite/gcc.dg/tree-ssa/vector-4.c| 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c 
b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
index f3871bf45e86..d00b957a7d67 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-36.c
@@ -21,5 +21,4 @@ main ()
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "if \\(b.0_\[0-9\]+ != 0\\)" "cddce1" { target 
{ ! mmix-knuth-mmixware } } } } */
-/* { dg-final { scan-tree-dump "if \\(b::1_\[0-9\]+ != 0\\)" "cddce1" { target 
{ mmix-knuth-mmixware } } } } */
+/* { dg-final { scan-tree-dump "if \\(b\\.\[01\]_\[0-9\]+ != 0\\)" "cddce1" } 
} */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c 
b/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c
index 982a2a47d6a0..03d70fde55a8 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vector-4.c
@@ -10,6 +10,5 @@ v4si vs (v4si a, v4si b)
 }
 
 /* The compound literal should be placed directly in the vec_perm.  */
-/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 
"gimple" { target { ! mmix-knuth-mmixware } } } } */
-/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 "gimple" { target mmix-knuth-mmixware } } } */
+/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 "gimple" } } */


[gcc(refs/users/meissner/heads/work190-sha)] Revert changes

2025-01-03 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:b974f902103a7c61c0c700bc2ff75100d8fc20a5

commit b974f902103a7c61c0c700bc2ff75100d8fc20a5
Author: Michael Meissner 
Date:   Fri Jan 3 03:23:54 2025 -0500

Revert changes

Diff:
---
 gcc/config/rs6000/altivec.md   | 35 +++---
 gcc/config/rs6000/predicates.md| 26 
 gcc/config/rs6000/rs6000.h |  3 --
 gcc/config/rs6000/rs6000.md|  6 +---
 .../gcc.target/powerpc/vector-rotate-left.c| 34 -
 5 files changed, 5 insertions(+), 99 deletions(-)

diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index 013960438b04..7edc288a6565 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -1982,39 +1982,12 @@
 }
   [(set_attr "type" "vecperm")])
 
-;; -mcpu=future adds a vector rotate left word variant.  There is no vector
-;; byte/half-word/double-word/quad-word rotate left.  This insn occurs before
-;; altivec_vrl and will match for -mcpu=future, while other cpus will
-;; match the generic insn.
-;; However for testing, allow other xvrl variants.  In particular, XVRLD for
-;; the sha3 tests for multibuf/singlebuf.
 (define_insn "altivec_vrl"
-  [(set (match_operand:VI2 0 "register_operand" "=v,wa")
-(rotate:VI2 (match_operand:VI2 1 "register_operand" "v,wa")
-   (match_operand:VI2 2 "register_operand" "v,wa")))]
+  [(set (match_operand:VI2 0 "register_operand" "=v")
+(rotate:VI2 (match_operand:VI2 1 "register_operand" "v")
+   (match_operand:VI2 2 "register_operand" "v")))]
   ""
-  "@
-   vrl %0,%1,%2
-   xvrl %x0,%x1,%x2"
-  [(set_attr "type" "vecsimple")
-   (set_attr "isa" "*,xvrlw")])
-
-(define_insn "*altivec_vrl_immediate"
-  [(set (match_operand:VI2 0 "register_operand" "=wa,wa,wa,wa")
-   (rotate:VI2 (match_operand:VI2 1 "register_operand" "wa,wa,wa,wa")
-   (match_operand:VI2 2 "vector_shift_immediate" 
"j,wM,wE,wS")))]
-  "TARGET_XVRLW && "
-{
-  rtx op2 = operands[2];
-  int value = 256;
-  int num_insns = -1;
-
-  if (!xxspltib_constant_p (op2, mode, &num_insns, &value))
-gcc_unreachable ();
-
-  operands[3] = GEN_INT (value & 0xff);
-  return "xvrli %x0,%x1,%3";
-}
+  "vrl %0,%1,%2"
   [(set_attr "type" "vecsimple")])
 
 (define_insn "altivec_vrlq"
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 276812573977..6485ee3eeecc 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -728,32 +728,6 @@
   return num_insns == 1;
 })
 
-;; Return 1 if the operand is a CONST_VECTOR whose elements are all the
-;; same and the elements can be an immediate shift or rotate factor
-(define_predicate "vector_shift_immediate"
-  (match_code "const_vector,vec_duplicate,const_int")
-{
-  int value = 256;
-  int num_insns = -1;
-
-  if (zero_constant (op, mode) || all_ones_constant (op, mode))
-return true;
-
-  if (!xxspltib_constant_p (op, mode, &num_insns, &value))
-return false;
-
-  switch (mode)
-{
-case V16QImode: return IN_RANGE (value, 0, 7);
-case V8HImode:  return IN_RANGE (value, 0, 15);
-case V4SImode:  return IN_RANGE (value, 0, 31);
-case V2DImode:  return IN_RANGE (value, 0, 63);
-default:break;
-}
-
-  return false;
-})
-  
 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
 ;; vector register without using memory.
 (define_predicate "easy_vector_constant"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 00f6ff2be636..ec08c96d0f67 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -575,9 +575,6 @@ extern int rs6000_vector_align[];
below.  */
 #define RS6000_FN_TARGET_INFO_HTM 1
 
-/* Whether we have XVRLW support.  */
-#define TARGET_XVRLW   TARGET_FUTURE
-
 /* Whether the various reciprocal divide/square root estimate instructions
exist, and whether we should automatically generate code for the instruction
by default.  */
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index e7927b88eaf8..3b876462ec32 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -369,7 +369,7 @@
   (const (symbol_ref "(enum attr_cpu) rs6000_tune")))
 
 ;; The ISA we implement.
-(define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10,xxeval,xvrlw"
+(define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10,xxeval"
   (const_string "any"))
 
 ;; Is this alternative enabled for the current CPU/ISA/etc.?
@@ -426,10 +426,6 @@
  (match_test "TARGET_PREFIXED && TARGET_XXEVAL"))
  (const_int 1)
 
- (and (eq_attr "isa" "xvrlw")
- (match_test "TARGET_XVRLW"))
- (const_int 1)
-
 ] (const_int 0)))
 
 ;; If this instruction is microcoded on the CELL processor
diff --git a/gcc/testsuite/gcc.target/powerpc/vector-rotate-left.c 
b/gcc/testsuite/gcc.target/powerpc/v

[gcc(refs/users/meissner/heads/work190-sha)] Add potential p-future XVRLD and XVRLDI instructions.

2025-01-03 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:d3e57d343996d8a2af96b032ba64364fd2f5af22

commit d3e57d343996d8a2af96b032ba64364fd2f5af22
Author: Michael Meissner 
Date:   Fri Jan 3 03:27:56 2025 -0500

Add potential p-future XVRLD and XVRLDI instructions.

2025-01-03  Michael Meissner  

gcc/

* config/rs6000/altivec.md (altivec_vrl): Add support for a
possible XVRLD instruction in the future.
(altivec_vrl_immediate): New insns.
* config/rs6000/predicates.md (vector_shift_immediate): New 
predicate.
* config/rs6000/rs6000.h (TARGET_XVRLW): New macro.
* config/rs6000/rs6000.md (isa attribute): Add xvrlw.
(enabled attribute): Add support for xvrlw.

gcc/testsuite/

* gcc.target/powerpc/vector-rotate-left.c: New test.
* lib/target-supports.exp 
(check_effective_target_powerpc_future_ok):
Add support to test -mcpu=future.

Diff:
---
 gcc/config/rs6000/altivec.md   | 35 +++---
 gcc/config/rs6000/predicates.md| 26 
 gcc/config/rs6000/rs6000.h |  3 ++
 gcc/config/rs6000/rs6000.md|  6 +++-
 .../gcc.target/powerpc/vector-rotate-left.c| 34 +
 gcc/testsuite/lib/target-supports.exp  | 12 
 6 files changed, 111 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index 7edc288a6565..013960438b04 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -1982,12 +1982,39 @@
 }
   [(set_attr "type" "vecperm")])
 
+;; -mcpu=future adds a vector rotate left word variant.  There is no vector
+;; byte/half-word/double-word/quad-word rotate left.  This insn occurs before
+;; altivec_vrl and will match for -mcpu=future, while other cpus will
+;; match the generic insn.
+;; However for testing, allow other xvrl variants.  In particular, XVRLD for
+;; the sha3 tests for multibuf/singlebuf.
 (define_insn "altivec_vrl"
-  [(set (match_operand:VI2 0 "register_operand" "=v")
-(rotate:VI2 (match_operand:VI2 1 "register_operand" "v")
-   (match_operand:VI2 2 "register_operand" "v")))]
+  [(set (match_operand:VI2 0 "register_operand" "=v,wa")
+(rotate:VI2 (match_operand:VI2 1 "register_operand" "v,wa")
+   (match_operand:VI2 2 "register_operand" "v,wa")))]
   ""
-  "vrl %0,%1,%2"
+  "@
+   vrl %0,%1,%2
+   xvrl %x0,%x1,%x2"
+  [(set_attr "type" "vecsimple")
+   (set_attr "isa" "*,xvrlw")])
+
+(define_insn "*altivec_vrl_immediate"
+  [(set (match_operand:VI2 0 "register_operand" "=wa,wa,wa,wa")
+   (rotate:VI2 (match_operand:VI2 1 "register_operand" "wa,wa,wa,wa")
+   (match_operand:VI2 2 "vector_shift_immediate" 
"j,wM,wE,wS")))]
+  "TARGET_XVRLW && "
+{
+  rtx op2 = operands[2];
+  int value = 256;
+  int num_insns = -1;
+
+  if (!xxspltib_constant_p (op2, mode, &num_insns, &value))
+gcc_unreachable ();
+
+  operands[3] = GEN_INT (value & 0xff);
+  return "xvrli %x0,%x1,%3";
+}
   [(set_attr "type" "vecsimple")])
 
 (define_insn "altivec_vrlq"
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 6485ee3eeecc..276812573977 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -728,6 +728,32 @@
   return num_insns == 1;
 })
 
+;; Return 1 if the operand is a CONST_VECTOR whose elements are all the
+;; same and the elements can be an immediate shift or rotate factor
+(define_predicate "vector_shift_immediate"
+  (match_code "const_vector,vec_duplicate,const_int")
+{
+  int value = 256;
+  int num_insns = -1;
+
+  if (zero_constant (op, mode) || all_ones_constant (op, mode))
+return true;
+
+  if (!xxspltib_constant_p (op, mode, &num_insns, &value))
+return false;
+
+  switch (mode)
+{
+case V16QImode: return IN_RANGE (value, 0, 7);
+case V8HImode:  return IN_RANGE (value, 0, 15);
+case V4SImode:  return IN_RANGE (value, 0, 31);
+case V2DImode:  return IN_RANGE (value, 0, 63);
+default:break;
+}
+
+  return false;
+})
+  
 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
 ;; vector register without using memory.
 (define_predicate "easy_vector_constant"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index ec08c96d0f67..00f6ff2be636 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -575,6 +575,9 @@ extern int rs6000_vector_align[];
below.  */
 #define RS6000_FN_TARGET_INFO_HTM 1
 
+/* Whether we have XVRLW support.  */
+#define TARGET_XVRLW   TARGET_FUTURE
+
 /* Whether the various reciprocal divide/square root estimate instructions
exist, and whether we should automatically generate code for the instruction
by default.  */
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 3b8

[gcc(refs/users/meissner/heads/work190-sha)] Update ChangeLog.*

2025-01-03 Thread Michael Meissner via Gcc-cvs
https://gcc.gnu.org/g:e10ae2e4458ec01f05d70abc5a619252512f5a4f

commit e10ae2e4458ec01f05d70abc5a619252512f5a4f
Author: Michael Meissner 
Date:   Fri Jan 3 03:29:10 2025 -0500

Update ChangeLog.*

Diff:
---
 gcc/ChangeLog.sha | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog.sha b/gcc/ChangeLog.sha
index 5ce183bf7c3b..c83a911f4cbc 100644
--- a/gcc/ChangeLog.sha
+++ b/gcc/ChangeLog.sha
@@ -2,7 +2,7 @@
 
 Add potential p-future XVRLD and XVRLDI instructions.
 
-2025-01-02  Michael Meissner  
+2025-01-03  Michael Meissner  
 
 gcc/
 
@@ -17,6 +17,8 @@ gcc/
 gcc/testsuite/
 
* gcc.target/powerpc/vector-rotate-left.c: New test.
+   * lib/target-supports.exp (check_effective_target_powerpc_future_ok):
+   Add support to test -mcpu=future.
 
  Branch work190-sha, patch #400 


[gcc r15-6512] OpenMP/C++: Store location in cp_parser_omp_var_list for kind=0

2025-01-03 Thread Tobias Burnus via Gcc-cvs
https://gcc.gnu.org/g:cf94ba812ca49608decbd1e28296f1b618c9c7d9

commit r15-6512-gcf94ba812ca49608decbd1e28296f1b618c9c7d9
Author: Tobias Burnus 
Date:   Fri Jan 3 10:12:32 2025 +0100

OpenMP/C++: Store location in cp_parser_omp_var_list for kind=0

cp_parser_omp_var_list and cp_parser_omp_var_list_no_open have a special
modus: kind = 0 alias kind = OMP_CLAUSE_ERROR, which returns a simple tree
list; however, for a decl, no location is associated with that variable,
yielding to confusing error locations. With this patch, also for kind=0,
a reasonable error location is stored, albeit with creating a tree node
(build_empty_stmt), which is otherwise not used.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_var_list_no_open,
cp_parser_omp_var_list): For kind=0 (= OMP_CLAUSE_ERROR),
store also the expression location in the tree list.
(cp_parser_oacc_data_clause_deviceptr,
cp_finish_omp_declare_variant): Use that location instead or
input_location/the before-parsing location.
* semantics.cc (finish_omp_threadprivate): Likewise.

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

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index cd1d9b5f7151..f548dc31c2b8 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -38698,8 +38698,9 @@ check_no_duplicate_clause (tree clauses, enum 
omp_clause_code code,
If KIND is nonzero, create the appropriate node and install the decl
in OMP_CLAUSE_DECL and add the node to the head of the list.
 
-   If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
-   return the list created.
+   If KIND is zero (= OMP_CLAUSE_ERROR), create a TREE_LIST with the decl
+   in TREE_PURPOSE and the location in TREE_VALUE (accessible using
+   EXPR_LOCATION); return the list created.
 
COLON can be NULL if only closing parenthesis should end the list,
or pointer to bool which will receive false if the list is terminated
@@ -38836,7 +38837,7 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum 
omp_clause_code kind,
  goto build_clause;
}
   token = cp_lexer_peek_token (parser->lexer);
-  if (kind != 0
+  if (kind != 0  /* kind != OMP_CLAUSE_ERROR */
  && cp_parser_is_keyword (token, RID_THIS))
{
  decl = finish_this_expr ();
@@ -38894,7 +38895,7 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum 
omp_clause_code kind,
decl = process_outer_var_ref (decl, tf_warning_or_error);
   if (decl == error_mark_node)
;
-  else if (kind != 0)
+  else if (kind != 0)  /* kind != OMP_CLAUSE_ERROR */
{
  switch (kind)
{
@@ -39040,8 +39041,8 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum 
omp_clause_code kind,
  OMP_CLAUSE_CHAIN (u) = list;
  list = u;
}
-  else
-   list = tree_cons (decl, NULL_TREE, list);
+  else  /* kind == 0 alias kind == OMP_CLAUSE_ERROR */
+   list = tree_cons (decl, build_empty_stmt (token->location), list);
 
 get_comma:
   if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
@@ -39088,17 +39089,17 @@ cp_parser_omp_var_list (cp_parser *parser, enum 
omp_clause_code kind, tree list,
 {
   if (parser->lexer->in_omp_decl_attribute)
 {
+  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
   if (kind)
{
- location_t loc = cp_lexer_peek_token (parser->lexer)->location;
  tree u = build_omp_clause (loc, kind);
  OMP_CLAUSE_DECL (u) = parser->lexer->in_omp_decl_attribute;
  OMP_CLAUSE_CHAIN (u) = list;
  return u;
}
-  else
-   return tree_cons (parser->lexer->in_omp_decl_attribute, NULL_TREE,
- list);
+  else  /* kind == OMP_CLAUSE_ERROR  */
+   return tree_cons (parser->lexer->in_omp_decl_attribute,
+ build_empty_stmt (loc), list);
 }
 
   if (cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
@@ -39213,7 +39214,6 @@ cp_parser_oacc_data_clause (cp_parser *parser, 
pragma_omp_clause c_kind,
 static tree
 cp_parser_oacc_data_clause_deviceptr (cp_parser *parser, tree list)
 {
-  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
   tree vars, t;
 
   /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
@@ -39223,6 +39223,7 @@ cp_parser_oacc_data_clause_deviceptr (cp_parser 
*parser, tree list)
   for (t = vars; t; t = TREE_CHAIN (t))
 {
   tree v = TREE_PURPOSE (t);
+  location_t loc = EXPR_LOCATION (TREE_VALUE (t));
   tree u = build_omp_clause (loc, OMP_CLAUSE_MAP);
   OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR);
   OMP_CLAUSE_DECL (u) = v;
@@ -50229,8 +50230,6 @@ cp_finish_omp_declare_variant (cp_parser *parser, 
cp_token *pragma_tok,

[gcc r14-11125] c++/modules: Fallback to ftruncate if posix_fallocate fails [PR115008]

2025-01-03 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:1c3dee768a9f7aa384150e4e4a584d6aa1db5e97

commit r14-11125-g1c3dee768a9f7aa384150e4e4a584d6aa1db5e97
Author: Nathaniel Shead 
Date:   Sat Dec 21 23:42:28 2024 +1100

c++/modules: Fallback to ftruncate if posix_fallocate fails [PR115008]

Depending on the libc and filesystem, in cases where posix_fallocate
cannot do an efficient preallocation it may return EINVAL.  In such a
case we should fall back to ftruncate instead.

Apparently, depending on the system the use of posix_fallocate can have
a noticeable speedup over ftruncate in general (depending on the system)
so it probably isn't worth it to use ftruncate in all cases.

PR c++/100358
PR c++/115008

gcc/cp/ChangeLog:

* module.cc (elf_out::create_mapping): Fallback to ftruncate if
posix_fallocate fails.

Signed-off-by: Nathaniel Shead 
(cherry picked from commit 84aa7065deec49bab9fb0b085cd0a0dcc42cc479)

Diff:
---
 gcc/cp/module.cc | 19 ++-
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index fb10537d3e34..60638aabee28 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -1883,13 +1883,23 @@ elf_in::begin (location_t loc)
 void
 elf_out::create_mapping (unsigned ext, bool extending)
 {
-#ifndef HAVE_POSIX_FALLOCATE
-#define posix_fallocate(fd,off,len) ftruncate (fd, off + len)
+  /* A wrapper around posix_fallocate, falling back to ftruncate
+ if the underlying filesystem does not support the operation.  */
+  auto allocate = [](int fd, off_t offset, off_t length)
+{
+#ifdef HAVE_POSIX_FALLOCATE
+  int result = posix_fallocate (fd, offset, length);
+  if (result != EINVAL)
+   return result == 0;
+  /* Not supported by the underlying filesystem, fallback to ftruncate.  */
 #endif
+  return ftruncate (fd, offset + length) == 0;
+};
+
   void *mapping = MAP_FAILED;
   if (extending && ext < 1024 * 1024)
 {
-  if (!posix_fallocate (fd, offset, ext * 2))
+  if (allocate (fd, offset, ext * 2))
mapping = mmap (NULL, ext * 2, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, offset);
   if (mapping != MAP_FAILED)
@@ -1897,7 +1907,7 @@ elf_out::create_mapping (unsigned ext, bool extending)
 }
   if (mapping == MAP_FAILED)
 {
-  if (!extending || !posix_fallocate (fd, offset, ext))
+  if (!extending || allocate (fd, offset, ext))
mapping = mmap (NULL, ext, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, offset);
   if (mapping == MAP_FAILED)
@@ -1907,7 +1917,6 @@ elf_out::create_mapping (unsigned ext, bool extending)
  ext = 0;
}
 }
-#undef posix_fallocate
   hdr.buffer = (char *)mapping;
   extent = ext;
 }


[gcc r15-6551] rtlanal: Treat writes to sp as also writing to memory [PR117938]

2025-01-03 Thread Richard Sandiford via Gcc-cvs
https://gcc.gnu.org/g:355475e332f264107ef07555f7c379be7b85942f

commit r15-6551-g355475e332f264107ef07555f7c379be7b85942f
Author: Richard Sandiford 
Date:   Fri Jan 3 18:12:07 2025 +

rtlanal: Treat writes to sp as also writing to memory [PR117938]

This PR was about a case in which late-combine moved a stack
deallocation across an earlier stack access.  This was possible
because the deallocation was missing the RTL-SSA equivalent of
a vop, which in turn was because rtl_properties didn't treat
the deallocation as writing to memory.  I think the bug was
ultimately there.

gcc/
PR rtl-optimization/117938
* rtlanal.cc (rtx_properties::try_to_add_dest): Treat writes
to the stack pointer as also writing to memory.

gcc/testsuite/
PR rtl-optimization/117938
* gcc.dg/torture/pr117938.c: New test.

Diff:
---
 gcc/rtlanal.cc  | 14 ++---
 gcc/testsuite/gcc.dg/torture/pr117938.c | 36 +
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index e7efb48c3986..8caffafdaa44 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -2163,10 +2163,18 @@ rtx_properties::try_to_add_dest (const_rtx x, unsigned 
int flags)
 
   if (LIKELY (REG_P (x)))
 {
-  /* We want to keep sp alive everywhere -  by making all
-writes to sp also use sp. */
   if (REGNO (x) == STACK_POINTER_REGNUM)
-   flags |= rtx_obj_flags::IS_READ;
+   {
+ /* Stack accesses are dependent on previous allocations and
+anti-dependent on later deallocations, so both types of
+stack operation are akin to a memory write.  */
+ if (ref_iter != ref_end)
+   *ref_iter++ = rtx_obj_reference (MEM_REGNO, flags, BLKmode);
+
+ /* We want to keep sp alive everywhere - by making all
+writes to sp also use sp.  */
+ flags |= rtx_obj_flags::IS_READ;
+   }
   try_to_add_reg (x, flags);
   return;
 }
diff --git a/gcc/testsuite/gcc.dg/torture/pr117938.c 
b/gcc/testsuite/gcc.dg/torture/pr117938.c
new file mode 100644
index ..5a3b6d2156c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117938.c
@@ -0,0 +1,36 @@
+/* { dg-do run { target { int32 && int128 } } } */
+/* { dg-additional-options "-Wno-psabi --param=max-cse-insns=1" } */
+
+typedef unsigned V __attribute__((__vector_size__(64)));
+typedef unsigned __int128 W __attribute__((__vector_size__(64)));
+unsigned a;
+W b;
+V c;
+W d;
+
+__attribute__((__noinline__))
+W
+bar (unsigned u, V z, W w)
+{
+  u *= z[5];
+  return u + w;
+}
+
+W
+foo (V v)
+{
+  unsigned g = a ? 1 : -1;
+  v ^= 0 <= v;
+  v <<= ((V){ bar (0, c, b)[0] } & 1);
+  v >>= ((V){ g, bar (1, c, b)[0] } & 1);
+  return a + b + (W) v + d;
+}
+
+int
+main ()
+{
+  V x = (V) foo ((V) { });
+  for (unsigned i = 0; i < sizeof(x)/sizeof(x[0]); i++)
+if (x[i] != (i ? 0x : 0x7fff))
+  __builtin_abort();
+}


[gcc r15-6552] OpenMP: Robustify C front end handling of attribute-syntax pragmas

2025-01-03 Thread Sandra Loosemore via Gcc-cvs
https://gcc.gnu.org/g:c97692d5403cce37a9882ab118a24dca7b202f6c

commit r15-6552-gc97692d5403cce37a9882ab118a24dca7b202f6c
Author: Sandra Loosemore 
Date:   Fri Jan 3 17:35:03 2025 +

OpenMP: Robustify C front end handling of attribute-syntax pragmas

Presently, the code to handle OpenMP attribute-syntax pragmas in the C
front end assumes nothing else is messing with redirecting
parser->tokens, and makes no provision for restoring it from anything
other than parser->tokens_buf when the buffer allocated for the pragma
is exhausted.  Adding support for metadirectives will change that,
since it also needs to buffer tokens for the metadirective
alternatives, and an attribute-syntax directive can appear inside a
metadirective.

This patch adds a more general save/restore mechanism attached to the
parser via a pointer to a new struct omp_attribute_pragma_state.

gcc/c/ChangeLog

* c-parser.cc (struct c_parser): Change in_omp_attribute_pragma
field to be of type struct omp_attribute_pragma_state.
(struct omp_attribute_pragma_state): New.
(c_parser_skip_until_found): Use the new way to restore state
on EOF.
(c_parser_skip_to_pragma_eol): Likewise.
(c_parser_handle_statement_omp_attributes): Create an
omp_attribute_pragma_state to hold the restore state.  Do not
store state in tok.flags.
(omp_maybe_parse_omp_decl): Likewise.

Diff:
---
 gcc/c/c-parser.cc | 46 --
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index f72b0f0e39fd..c46aac5f0a2b 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -262,15 +262,25 @@ struct GTY(()) c_parser {
   struct omp_for_parse_data * GTY((skip)) omp_for_parse_state;
 
   /* If we're in the context of OpenMP directives written as C23
- attributes turned into pragma, vector of tokens created from that,
- otherwise NULL.  */
-  vec *in_omp_attribute_pragma;
+ attributes turned into pragma, the tokens field is temporarily
+ redirected.  This holds data needed to restore state afterwards.
+ It's NULL otherwise.  */
+  struct omp_attribute_pragma_state *in_omp_attribute_pragma;
 
   /* Set for omp::decl attribute parsing to the decl to which it
  appertains.  */
   tree in_omp_decl_attribute;
 };
 
+/* Holds data needed to restore the token stream to its previous state
+   after parsing an OpenMP attribute-syntax pragma.  */
+struct GTY(()) omp_attribute_pragma_state
+{
+  vec *token_vec;
+  c_token * GTY((skip)) save_tokens;
+  unsigned int save_tokens_avail;
+};
+
 /* Return a pointer to the Nth token in PARSERs tokens_buf.  */
 
 c_token *
@@ -1312,8 +1322,9 @@ c_parser_skip_until_found (c_parser *parser,
  c_token *token = c_parser_peek_token (parser);
  if (token->type == CPP_EOF)
{
- parser->tokens = &parser->tokens_buf[0];
- parser->tokens_avail = token->flags;
+ parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
+ parser->tokens_avail
+   = parser->in_omp_attribute_pragma->save_tokens_avail;
  parser->in_omp_attribute_pragma = NULL;
}
}
@@ -1335,8 +1346,9 @@ c_parser_skip_until_found (c_parser *parser,
  c_token *token = c_parser_peek_token (parser);
  if (token->type == CPP_EOF)
{
- parser->tokens = &parser->tokens_buf[0];
- parser->tokens_avail = token->flags;
+ parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
+ parser->tokens_avail
+   = parser->in_omp_attribute_pragma->save_tokens_avail;
  parser->in_omp_attribute_pragma = NULL;
}
}
@@ -1429,8 +1441,9 @@ c_parser_skip_to_pragma_eol (c_parser *parser, bool 
error_if_not_eol = true)
   c_token *token = c_parser_peek_token (parser);
   if (token->type == CPP_EOF)
{
- parser->tokens = &parser->tokens_buf[0];
- parser->tokens_avail = token->flags;
+ parser->tokens = parser->in_omp_attribute_pragma->save_tokens;
+ parser->tokens_avail
+   = parser->in_omp_attribute_pragma->save_tokens_avail;
  parser->in_omp_attribute_pragma = NULL;
}
 }
@@ -7184,7 +7197,6 @@ c_parser_handle_statement_omp_attributes (c_parser 
*parser, tree &attrs,
 return false;
 
   unsigned int tokens_avail = parser->tokens_avail;
-  gcc_assert (parser->tokens == &parser->tokens_buf[0]);
 
   tokens++;
   vec *toks = NULL;
@@ -7216,12 +7228,15 @@ c_parser_handle_statement_omp_attributes (c_parser 
*parser, tree &attrs,
   tok.type = CPP_EOF;
   tok.keyword = RID_MAX;
   tok.location = toks->last ().location;
-  tok.flags = tokens_avail;
   toks->quick_push (tok);
 
+  g

[gcc r15-6547] forwprop: Use tree_fits_shwi_p in check_ctz_array

2025-01-03 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:514577c66b39fc321bec1c957130fbcd66207822

commit r15-6547-g514577c66b39fc321bec1c957130fbcd66207822
Author: Jakub Jelinek 
Date:   Fri Jan 3 17:55:04 2025 +0100

forwprop: Use tree_fits_shwi_p in check_ctz_array

When touching the function yesterday, I was surprised to see just
TREE_CODE (something) != INTEGER_CST checks followed by tree_to_shwi.
That would ICE if the INTEGER_CST doesn't fit.

I have actually not been able to reproduce an ICE for the elt case
as the caller gives up if the precision of the array type is larger than 32
bits (but I think it is still cleaner to use it), the idx case can actually
ICE e.g. on
static const unsigned long long magic = 0x03f08c5392f756cdULL;
static const char table[] = {
 0, [0x8000ULL] = 1, 12,  2, 13, 22, 17,  3, 14, 33, 23, 
36, 18, 58, 28,  4,
62, 15, 34, 26, 24, 48, 50, 37, 19, 55, 59, 52, 29, 44, 39,  5,
63, 11, 21, 16, 32, 35, 57, 27, 61, 25, 47, 49, 54, 51, 43, 38,
10, 20, 31, 56, 60, 46, 53, 42, 9, 30, 45, 41,  8, 40,  7,  6,
};

int ctz (unsigned long x)
{
  unsigned long lsb = x & -x;
  return table[(lsb * magic) >> 58];
}
~/src/gcc/obj20/gcc/cc1 -quiet /tmp/1.c -O2 -mbmi
/tmp/1.c:2:19: warning: size of ‘table’ 9223372036854775871 bytes exceeds 
maximum object size 9223372036854775807 [-Wlarger-than=]
2 | static const char table[] = {
  |   ^
during GIMPLE pass: forwprop
/tmp/1.c: In function ‘ctz’:
/tmp/1.c:13:1: internal compiler error: in tree_to_shwi, at tree.cc:6518
   13 | }
  | ^
0x2efa51f internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:517
0xf3c617 fancy_abort(char const*, int, char const*)
../../gcc/diagnostic.cc:1722
0x949a36 tree_to_shwi(tree_node const*)
../../gcc/tree.cc:6518
0x949a36 tree_to_shwi(tree_node const*)
../../gcc/tree.cc:6516
0x18472d5 check_ctz_array
../../gcc/tree-ssa-forwprop.cc:2286
but given the 9223372036854775871 bytes long array
I'm not sure it is appropriate for the testsuite.

2025-01-03  Jakub Jelinek  

* tree-ssa-forwprop.cc (check_ctz_array): Use tree_fits_shwi_p 
instead
of just TREE_CODE tests for INTEGER_CST.

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

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index b35f845a42a0..2e09027db56f 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2278,9 +2278,9 @@ check_ctz_array (tree ctor, unsigned HOST_WIDE_INT mulc,
 
   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, elt)
 {
-  if (TREE_CODE (idx) != INTEGER_CST)
+  if (!tree_fits_shwi_p (idx))
return false;
-  if (TREE_CODE (elt) != INTEGER_CST && TREE_CODE (elt) != RAW_DATA_CST)
+  if (!tree_fits_shwi_p (elt) && TREE_CODE (elt) != RAW_DATA_CST)
return false;
 
   unsigned HOST_WIDE_INT index = tree_to_shwi (idx);


[gcc r15-6548] varasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again [PR118275]

2025-01-03 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:6f444e45d3fd6c45fc34a79ac66bf46c20fd95b1

commit r15-6548-g6f444e45d3fd6c45fc34a79ac66bf46c20fd95b1
Author: Jakub Jelinek 
Date:   Fri Jan 3 17:59:57 2025 +0100

varasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again 
[PR118275]

As the following testcases show (the latter only if I revert the
temporary reversion of the C++ large array speedup), the FEs aren't
really consistent in the type of array CONSTRUCTOR_ELTS indexes,
it can be bitsizetype, but can be sizetype as well.
Given that everything else is able to cope with it just fine,
I'm using build_int_cst which also doesn't care what type it is,
instead of bitsize_int, which I've used in PR117190 fix (previously
it was size_int).

2025-01-03  Jakub Jelinek  

PR c++/118275
* varasm.cc (array_size_for_constructor): Use build_int_cst
with TREE_TYPE (index) as first argument, instead of bitsize_int.

* g++.dg/cpp/embed-18.C: New test.
* g++.dg/ext/flexary41.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/cpp/embed-18.C  | 15 +++
 gcc/testsuite/g++.dg/ext/flexary41.C | 24 
 gcc/varasm.cc|  3 ++-
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/cpp/embed-18.C 
b/gcc/testsuite/g++.dg/cpp/embed-18.C
new file mode 100644
index ..c7ab8dc5757a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/embed-18.C
@@ -0,0 +1,15 @@
+// PR c++/118275
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int a; char b[]; };
+void bar (A *);
+
+void
+foo ()
+{
+  static struct A a = { .a = 1, .b = {
+#embed __FILE__
+} };
+  bar (&a);
+}
diff --git a/gcc/testsuite/g++.dg/ext/flexary41.C 
b/gcc/testsuite/g++.dg/ext/flexary41.C
new file mode 100644
index ..da80ba391b0f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/flexary41.C
@@ -0,0 +1,24 @@
+// PR c++/118275
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int a; char b[]; };
+void bar (A *);
+
+void
+foo ()
+{
+  static struct A a = { .a = 1, .b = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+} };
+  bar (&a);
+}
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 3538e2971fc5..6d93fe97d7bf 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -5648,7 +5648,8 @@ array_size_for_constructor (tree val)
index = TREE_OPERAND (index, 1);
   if (value && TREE_CODE (value) == RAW_DATA_CST)
index = size_binop (PLUS_EXPR, index,
-   bitsize_int (RAW_DATA_LENGTH (value) - 1));
+   build_int_cst (TREE_TYPE (index),
+  RAW_DATA_LENGTH (value) - 1));
   if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
max_index = index;
 }


[gcc r15-6550] Mention generating C prototypes in the C interop documentation.

2025-01-03 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:92ad6d4ebfe5454b9299f295926517bd453bc4a2

commit r15-6550-g92ad6d4ebfe5454b9299f295926517bd453bc4a2
Author: Thomas Koenig 
Date:   Fri Jan 3 18:31:07 2025 +0100

Mention generating C prototypes in the C interop documentation.

gcc/fortran/ChangeLog:

* gfortran.texi: New subsection "Generating C prototypes from
Fortran".

Diff:
---
 gcc/fortran/gfortran.texi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 430ede45ea1b..116667245932 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -2918,6 +2918,7 @@ C or some other language instead of Fortran, see
 * Interoperable Subroutines and Functions::
 * Working with C Pointers::
 * Further Interoperability of Fortran with C::
+* Generating C prototypes from Fortran::
 @end menu
 
 Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
@@ -3322,6 +3323,20 @@ are converted to the specified form.  If you need to 
access GNU Fortran's
 internal array descriptor, you can use the Chasm Language Interoperability
 Tools, @url{http://chasm-interop.sourceforge.net/}.
 
+@node Generating C prototypes from Fortran
+@subsection Generating C prototypes from Fortran
+@cindex prototypes
+@cindex C prototypes
+The options @option{-fc-prototypes} can be used to write out C
+declatations and function prototypes for @code{BIND(C)} entities.
+The same can be done for writing out prototypes for external
+procedures using @option{-fc-prototypes-external},
+@pxref{Interoperability Options}.
+
+Standard Fortran does not specify an interoperable type for C's
+@code{unsigned} integer types.  For interoperability with unsigned
+types, GNU Fortran provides unsigned integers, @pxref{Unsigned integers}.
+
 @node GNU Fortran Compiler Directives
 @section GNU Fortran Compiler Directives
 @cindex GNU Fortran Compiler Directives


[gcc r15-6549] libgomp: Regenerate configure after copyright year bump

2025-01-03 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:b11d85f2531be779c5f8ad82a6a139d5110b3cd5

commit r15-6549-gb11d85f2531be779c5f8ad82a6a139d5110b3cd5
Author: Jakub Jelinek 
Date:   Fri Jan 3 18:06:19 2025 +0100

libgomp: Regenerate configure after copyright year bump

2025-01-03  Jakub Jelinek  

* configure: Regenerate.

Diff:
---
 libgomp/configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgomp/configure b/libgomp/configure
index ad245b47dff1..df1fc8df30e6 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -15159,7 +15159,7 @@ _ACEOF
 
 # Plugins for offload execution, configure.ac fragment.  -*- mode: autoconf -*-
 #
-# Copyright (C) 2014-2024 Free Software Foundation, Inc.
+# Copyright (C) 2014-2025 Free Software Foundation, Inc.
 #
 # Contributed by Mentor Embedded.
 #


[gcc r15-6514] bpf: install a wrapping stdint.h for bpf-none-unknown targets

2025-01-03 Thread Jose E. Marchesi via Gcc-cvs
https://gcc.gnu.org/g:995d1c2b7cca9bec23a60f9cbcebccd9f307c53f

commit r15-6514-g995d1c2b7cca9bec23a60f9cbcebccd9f307c53f
Author: Jose E. Marchesi 
Date:   Fri Jan 3 13:42:26 2025 +0100

bpf: install a wrapping stdint.h for bpf-none-unknown targets

This patch makes GCC to wrap the host's stdint.h header when operating
in the default hosted/non-freestanding mode.  It is thus up to the
user to provide a suitable standard header unless -ffreestanding gets
explicitly passed in the compilation line.

A few tests that use stdint.h are adapted to explicitly pass
-ffreestanding.

Tested in a x86_64-linux-gnu host with target bpf-unknown-none.

gcc/ChangeLog:

* config.gcc: install a wrapping stdint.h in bpf targets.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/diag-funargs-2.c: Use -ffreestanding.
* gcc.target/bpf/helper-skb-ancestor-cgroup-id.c: Likewise.
* gcc.target/bpf/helper-bind.c: Likewise.
* gcc.target/bpf/diag-funargs-3.c: Likewise.

Diff:
---
 gcc/config.gcc   | 2 +-
 gcc/testsuite/gcc.target/bpf/diag-funargs-2.c| 2 +-
 gcc/testsuite/gcc.target/bpf/diag-funargs-3.c| 2 +-
 gcc/testsuite/gcc.target/bpf/helper-bind.c   | 2 +-
 gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c01473550872..55e37146ee03 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1690,7 +1690,7 @@ bpf-*-*)
 tm_file="elfos.h ${tm_file}"
 tmake_file="${tmake_file} bpf/t-bpf"
 use_collect2=no
-use_gcc_stdint=provide
+use_gcc_stdint=wrap
 extra_objs="btfext-out.o core-builtins.o"
 target_gtfiles="$target_gtfiles \$(srcdir)/config/bpf/btfext-out.cc 
\$(srcdir)/config/bpf/core-builtins.cc"
 ;;
diff --git a/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c 
b/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c
index 116f1bc849db..c4c89b6dad3c 100644
--- a/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c
+++ b/gcc/testsuite/gcc.target/bpf/diag-funargs-2.c
@@ -1,7 +1,7 @@
 /* Verify proper errors are generated for functions taking too many
arguments, with aggregates and 128-bit arguments.  */
 /* { dg-do compile } */
-/* { dg-options "-O0" } */
+/* { dg-options "-O0 -ffreestanding" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c 
b/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c
index 598a9dbeb4b1..9106d4f6edd0 100644
--- a/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c
+++ b/gcc/testsuite/gcc.target/bpf/diag-funargs-3.c
@@ -1,7 +1,7 @@
 /* Verify proper errors are generated for functions taking too many
arguments, with aggregates and 128-bit arguments.  */
 /* { dg-do compile } */
-/* { dg-options "-O0" } */
+/* { dg-options "-O0 -ffreestanding" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/bpf/helper-bind.c 
b/gcc/testsuite/gcc.target/bpf/helper-bind.c
index 53514ba32333..3b20edc2b6af 100644
--- a/gcc/testsuite/gcc.target/bpf/helper-bind.c
+++ b/gcc/testsuite/gcc.target/bpf/helper-bind.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-std=gnu99" } */
+/* { dg-options "-std=gnu99 -ffreestanding" } */
 
 #include 
 
diff --git a/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c 
b/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c
index 075dbe6f852d..a6505d458402 100644
--- a/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c
+++ b/gcc/testsuite/gcc.target/bpf/helper-skb-ancestor-cgroup-id.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-std=gnu99 -O2" } */
+/* { dg-options "-std=gnu99 -O2 -ffreestanding" } */
 
 #include 


[gcc r15-6534] ada: Fix latent issue exposed by latest change

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0a6736ef366af6bcd7e25567919202fd6c40b7c9

commit r15-6534-g0a6736ef366af6bcd7e25567919202fd6c40b7c9
Author: Eric Botcazou 
Date:   Thu Dec 5 11:15:10 2024 +0100

ada: Fix latent issue exposed by latest change

The finalization machinery needs to precisely locate the point where the
initialization of objects is complete in order to generate the attachment
to the finalization master.  For objects initialized with a built-in-place
function call, this is achieved by means of the BIP_Initialization_Call
field present in their entity node, but this field is only set in the case
where the enclosing scope is transient, which is not guaranteed.

gcc/ada/ChangeLog:

* einfo.ads (BIP_Initialization_Call): Adjust description.
* exp_ch4.adb (Expand_N_Case_Expression): Adjust commentary.
(Expand_N_If_Expression): Likewise.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration):
Set BIP_Initialization_Call unconditionally in the definite case.

Diff:
---
 gcc/ada/einfo.ads   |  7 +++
 gcc/ada/exp_ch4.adb | 21 -
 gcc/ada/exp_ch6.adb | 20 +---
 3 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 025465265f3c..d283358c0c0e 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -526,12 +526,11 @@ package Einfo is
 --   references on this list are illegal due to the visible refinement.
 
 --BIP_Initialization_Call
---   Defined in constants and variables whose corresponding declaration
---   is wrapped in a transient block and the inital value is provided by
+--   Defined in constants and variables whose initial value is provided by
 --   a build-in-place function call. Contains the relocated build-in-place
 --   call after the expansion has decoupled the call from the object. This
---   attribute is used by the finalization machinery to insert cleanup code
---   for all additional transient objects found in the transient block.
+--   attribute is used by the finalization machinery to insert the call to
+--   the routine that attaches the object to the finalization master.
 
 --C_Pass_By_Copy [implementation base type only]
 --   Defined in record types. Set if a pragma Convention for the record
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index f44f21d654bb..81b2b734bbf0 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -5104,7 +5104,8 @@ package body Exp_Ch4 is
   --  If the expression is in the context of a simple return statement,
   --  possibly through intermediate conditional expressions, we delay
   --  expansion until the (immediate) parent is rewritten as a return
-  --  statement (or is already the return statement).
+  --  statement (or is already the return statement). Likewise if it is
+  --  in the context of an object declaration that can be optimized.
 
   if not Expansion_Delayed (N) then
  declare
@@ -5119,9 +5120,9 @@ package body Exp_Ch4 is
   end if;
 
   --  If the expansion of the expression has been delayed, we wait for the
-  --  rewriting of its parent as an assignment or return statement; when
-  --  that's done, we optimize the assignment or the return statement (the
-  --  very purpose of the manipulation).
+  --  rewriting of its parent as an assignment statement, or as as return
+  --  statement or as an object declaration; when that's done, we optimize
+  --  the assignment, return or declaration (the purpose of the delaying).
 
   if Expansion_Delayed (N) then
  if Nkind (Par) = N_Assignment_Statement then
@@ -5721,8 +5722,10 @@ package body Exp_Ch4 is
   --  If the expression is in the context of a simple return statement,
   --  possibly through intermediate conditional expressions, we delay
   --  expansion until the (immediate) parent is rewritten as a return
-  --  statement (or is already the return statement). Note that this
-  --  deals with the case of the elsif part of the if expression.
+  --  statement (or is already the return statement). Likewise if it is
+  --  in the context of an object declaration that can be optimized.
+  --  Note that this deals with the case of the elsif part of the if
+  --  expression, if it exists.
 
   if not Expansion_Delayed (N) then
  declare
@@ -5737,9 +5740,9 @@ package body Exp_Ch4 is
   end if;
 
   --  If the expansion of the expression has been delayed, we wait for the
-  --  rewriting of its parent as an assignment or return statement; when
-  --  that's done, we optimize the assignment or the return statement (the
-  --  very purpose of the manipulation).
+  --  rewriting of its parent as an assignment statement, or as as return
+  --  statement or as an object declaration; when that's

[gcc r15-6538] ada: Remove guards against empty lists

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:bfa8e6f2137ba80dcd1ca7106be2cfe967810426

commit r15-6538-gbfa8e6f2137ba80dcd1ca7106be2cfe967810426
Author: Piotr Trojanek 
Date:   Thu Dec 5 15:14:58 2024 +0100

ada: Remove guards against empty lists

There is no need to guard against calling First on a No_List, in which case
the call intentionally returns Empty. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* contracts.adb (Create_Generic_Contract): Remove calls to Present.
* sem_util.adb (Normalize_Actuals): Likewise.

Diff:
---
 gcc/ada/contracts.adb | 16 
 gcc/ada/sem_util.adb  |  9 ++---
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 7e66a54b6752..7eb41f7f1073 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -2122,9 +2122,7 @@ package body Contracts is
   if Nkind (Templ) = N_Generic_Package_Declaration then
  Mutate_Ekind (Templ_Id, E_Generic_Package);
 
- if Present (Visible_Declarations (Specification (Templ))) then
-Decl := First (Visible_Declarations (Specification (Templ)));
- end if;
+ Decl := First (Visible_Declarations (Specification (Templ)));
 
   --  A generic package body carries contract-related source pragmas in its
   --  declarations.
@@ -2132,9 +2130,7 @@ package body Contracts is
   elsif Nkind (Templ) = N_Package_Body then
  Mutate_Ekind (Templ_Id, E_Package_Body);
 
- if Present (Declarations (Templ)) then
-Decl := First (Declarations (Templ));
- end if;
+ Decl := First (Declarations (Templ));
 
   --  Generic subprogram declaration
 
@@ -2149,9 +2145,7 @@ package body Contracts is
  --  the Pragmas_After list for contract-related source pragmas.
 
  if Nkind (Context) = N_Compilation_Unit then
-if Present (Aux_Decls_Node (Context))
-  and then Present (Pragmas_After (Aux_Decls_Node (Context)))
-then
+if Present (Aux_Decls_Node (Context)) then
Decl := First (Pragmas_After (Aux_Decls_Node (Context)));
 end if;
 
@@ -2168,9 +2162,7 @@ package body Contracts is
   elsif Nkind (Templ) = N_Subprogram_Body then
  Mutate_Ekind (Templ_Id, E_Subprogram_Body);
 
- if Present (Declarations (Templ)) then
-Decl := First (Declarations (Templ));
- end if;
+ Decl := First (Declarations (Templ));
   end if;
 
   --  Inspect the relevant declarations looking for contract-related source
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 44a87298c6ea..6bc50c44291d 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -25119,9 +25119,7 @@ package body Sem_Util is
   --  Find if there is a named association, and verify that no positional
   --  associations appear after named ones.
 
-  if Present (Actuals) then
- Actual := First (Actuals);
-  end if;
+  Actual := First (Actuals);
 
   while Present (Actual)
 and then Nkind (Actual) /= N_Parameter_Association
@@ -25169,10 +25167,7 @@ package body Sem_Util is
  Next (Actual);
   end loop;
 
-  if Present (Actuals) then
- Actual := First (Actuals);
-  end if;
-
+  Actual := First (Actuals);
   Formal := First_Formal (S);
   while Present (Formal) loop


[gcc r15-6540] ada: Remove extra checks for raising a constraint error

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d9a51b704fe521fecb2e77931226c8e8798a9910

commit r15-6540-gd9a51b704fe521fecb2e77931226c8e8798a9910
Author: Piotr Trojanek 
Date:   Thu Dec 5 16:59:36 2024 +0100

ada: Remove extra checks for raising a constraint error

Routine Is_OK_Static_Expression itself calls Raises_Constraint_Error, so 
there
is no need to call both of these routines in a row. Code cleanup; semantics 
is
unaffected.

gcc/ada/ChangeLog:

* sem_attr.adb (Check_Array_Type): Remove extra call.
* sem_util.adb (Static_Boolean): Likewise.

Diff:
---
 gcc/ada/sem_attr.adb |  4 +---
 gcc/ada/sem_util.adb | 12 ++--
 2 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 6eb04b2e2582..7295784704fd 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1994,9 +1994,7 @@ package body Sem_Attr is
 Resolve (E1, Any_Integer);
 Set_Etype (E1, Standard_Integer);
 
-if not Is_OK_Static_Expression (E1)
-  or else Raises_Constraint_Error (E1)
-then
+if not Is_OK_Static_Expression (E1) then
Flag_Non_Static_Expr
  ("expression for dimension must be static!", E1);
Error_Attr;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index bd798d74885c..c1af2281a22b 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -28232,11 +28232,7 @@ package body Sem_Util is
   end if;
 
   if Is_OK_Static_Expression (N) then
- if not Raises_Constraint_Error (N) then
-return Expr_Value (N);
- else
-return No_Uint;
- end if;
+ return Expr_Value (N);
 
   elsif Etype (N) = Any_Type then
  return No_Uint;
@@ -28264,11 +28260,7 @@ package body Sem_Util is
   end if;
 
   if Is_OK_Static_Expression (N) then
- if not Raises_Constraint_Error (N) then
-return Expr_Value (N);
- else
-return No_Uint;
- end if;
+ return Expr_Value (N);
 
   elsif Etype (N) = Any_Type then
  return No_Uint;


[gcc r15-6521] ada: Fix double free at run time for class-wide allocation

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0f7b8a89c325babc2e4abf0097c9f26cb2569114

commit r15-6521-g0f7b8a89c325babc2e4abf0097c9f26cb2569114
Author: Eric Botcazou 
Date:   Tue Dec 3 22:36:15 2024 +0100

ada: Fix double free at run time for class-wide allocation

The previous change was too aggressive and overlooked a specific case.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_Allocator_Expression): Put back the call to
Remove_Side_Effects in the case of a function call, a class-wide
designated type and a regular storage pool.

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

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 8db729f0ce92..2fc891a4e390 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -996,6 +996,22 @@ package body Exp_Ch4 is
 (Loc, TagR, Underlying_Type (TagT)));
  end if;
 
+ --  If the designated type is class-wide, then the alignment and the
+ --  controlled nature of the expression are computed dynamically by
+ --  the code generated by Build_Allocate_Deallocate_Proc, which will
+ --  thus need to remove side effects from Exp first. But the below
+ --  test on Exp needs to have its final form to decide whether or not
+ --  to generate an Adjust call, so we preventively remove them here.
+
+ if Nkind (Exp) = N_Function_Call
+   and then Is_Class_Wide_Type (DesigT)
+   and then Present (Storage_Pool (N))
+   and then not Is_RTE (Storage_Pool (N), RE_RS_Pool)
+   and then not Is_RTE (Storage_Pool (N), RE_SS_Pool)
+ then
+Remove_Side_Effects (Exp);
+ end if;
+
  --  Generate an Adjust call if the object will be moved. In Ada 2005,
  --  the object may be inherently limited, in which case there is no
  --  Adjust procedure, and the object is built in place. In Ada 95, the


[gcc r15-6537] ada: Enclosing_Entity of specless subprogram bodies

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:586fa60bdb385a94d0c11cca2940b8377df7a185

commit r15-6537-g586fa60bdb385a94d0c11cca2940b8377df7a185
Author: Bob Duff 
Date:   Wed Dec 4 18:30:03 2024 -0500

ada: Enclosing_Entity of specless subprogram bodies

Correct Enclosing_Entity of specless subprogram bodies;
these are marked as Comes_From_Source = False,
so the simple name was missing.

gcc/ada/ChangeLog:

* sem_util.adb (Append_Entity_Name): Do not skip the
simple name for a compilation unit (which includes
the case of specless subprogram bodies).

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

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 4a26d9623033..44a87298c6ea 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -649,18 +649,21 @@ package body Sem_Util is
   --  recursively print A.B.C, then print D.
begin
   --  If E is not a source entity, then skip the simple name and just
-  --  recursively print its scope. However, subprogram instances have
-  --  Comes_From_Source = False, but we do want to print the simple name
-  --  of the instance.
+  --  recursively print its scope. However, certain entities have
+  --  Comes_From_Source = False, even though we DO want to print the
+  --  simple name; this happens for specless child subprogram bodies
+  --  and for subprogram instances.
 
   if not Comes_From_Source (E) then
- if Is_Generic_Instance (E)
+ if Is_Compilation_Unit (E) then
+null;
+ elsif Is_Generic_Instance (E)
and then Ekind (E) in E_Function | E_Procedure
  then
 null;
  else
 Append_Entity_Name (Buf, Scope (E));
-return;
+return; -- skip the simple name
  end if;
   end if;


[gcc r15-6544] ada: Rely on default parameter when making non-null nodes

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:75da7a6bdc83d99b994c16764960ba0a7d18e135

commit r15-6544-g75da7a6bdc83d99b994c16764960ba0a7d18e135
Author: Piotr Trojanek 
Date:   Thu Dec 5 18:03:26 2024 +0100

ada: Rely on default parameter when making non-null nodes

When calling Make_Access_To_Object_Definition and 
Make_Parameter_Specification
we can rely on the default value of parameter Null_Exclusion_Present being
False. This makes code cleaner and consistent with relying on the default 
value
of other parameters of this routine.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_ch4.adb, exp_disp.adb, inline.adb: Remove 
explicit
actual parameter Null_Exclusion_Present equal False.

Diff:
---
 gcc/ada/exp_ch3.adb  | 5 ++---
 gcc/ada/exp_ch4.adb  | 7 +++
 gcc/ada/exp_disp.adb | 5 ++---
 gcc/ada/inline.adb   | 9 -
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index ad292ee404ee..9419d5d2fac3 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2960,9 +2960,8 @@ package body Exp_Ch3 is
 Defining_Identifier => Acc_Type,
 Type_Definition =>
   Make_Access_To_Object_Definition (Loc,
-All_Present=> True,
-Null_Exclusion_Present => False,
-Subtype_Indication =>
+All_Present=> True,
+Subtype_Indication =>
   New_Occurrence_Of (Rec_Type, Loc);
 
 Set_Handled_Statement_Sequence (Body_Node,
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 81b2b734bbf0..18656ea24fdb 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -909,11 +909,10 @@ package body Exp_Ch4 is
Defining_Identifier => Def_Id,
Type_Definition =>
  Make_Access_To_Object_Definition (Loc,
-   All_Present=> True,
-   Null_Exclusion_Present => False,
-   Constant_Present   =>
+   All_Present=> True,
+   Constant_Present   =>
  Is_Access_Constant (PtrT),
-   Subtype_Indication =>
+   Subtype_Indication =>
  New_Occurrence_Of (Etype (Exp), Loc;
 
--  Inherit the allocation-related attributes from the original
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index 906ddc4175c2..f45c32356a90 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -1525,9 +1525,8 @@ package body Exp_Disp is
 Defining_Identifier => Make_Temporary (Loc, 'T'),
 Type_Definition =>
   Make_Access_To_Object_Definition (Loc,
-All_Present=> True,
-Null_Exclusion_Present => False,
-Subtype_Indication =>
+All_Present=> True,
+Subtype_Indication =>
   New_Occurrence_Of (Desig_Typ, Loc)));
 
 Stats := New_List (
diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index a24b0704c916..30d3b1bbf4d3 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -2431,12 +2431,11 @@ package body Inline is
 
  Append_To (Formals,
Make_Parameter_Specification (Loc,
- Defining_Identifier=>
+ Defining_Identifier =>
Make_Defining_Identifier (Loc, Chars (Obj_Id)),
- In_Present => False,
- Out_Present=> not Constant_Present (Obj_Decl),
- Null_Exclusion_Present => False,
- Parameter_Type => Typ_Def));
+ In_Present  => False,
+ Out_Present => not Constant_Present (Obj_Decl),
+ Parameter_Type  => Typ_Def));
   end Build_Return_Object_Formal;
 
   --


[gcc r15-6542] ada: Rely on default parameter when making component definition nodes

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:5a843616379b1c02d6702ac6121c576bd05f4209

commit r15-6542-g5a843616379b1c02d6702ac6121c576bd05f4209
Author: Piotr Trojanek 
Date:   Thu Dec 5 17:38:43 2024 +0100

ada: Rely on default parameter when making component definition nodes

When calling Make_Component_Definition we can rely on the default value of
parameter Aliased_Present being False. This makes code cleaner and 
consistent
with relying on the default value of other parameters of this routine, e.g.
Null_Exclusion_Present.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_ch9.adb, exp_dist.adb, exp_imgv.adb, 
exp_util.adb,
sem_dist.adb: Remove explicit actual parameter Aliased_Present equal
False; tune comments and whitespace.

Diff:
---
 gcc/ada/exp_ch3.adb  |  3 ---
 gcc/ada/exp_ch9.adb  | 29 ++---
 gcc/ada/exp_dist.adb |  4 
 gcc/ada/exp_imgv.adb |  1 -
 gcc/ada/exp_util.adb |  3 ---
 gcc/ada/sem_dist.adb |  3 +--
 6 files changed, 7 insertions(+), 36 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index a68b4f12ca63..b69da39da36e 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -5687,7 +5687,6 @@ package body Exp_Ch3 is
 
  Component_Definition =>
Make_Component_Definition (Loc,
- Aliased_Present => False,
  Subtype_Indication => New_Occurrence_Of (Typ, Loc))),
 
  Expression =>
@@ -9318,7 +9317,6 @@ package body Exp_Ch3 is
   Defining_Identifier => Parent_N,
   Component_Definition =>
 Make_Component_Definition (Loc,
-  Aliased_Present => False,
   Subtype_Indication => New_Occurrence_Of (Par_Subtype, Loc)));
 
   if Null_Present (Rec_Ext_Part) then
@@ -9376,7 +9374,6 @@ package body Exp_Ch3 is
   Defining_Identifier => First_Tag_Component (T),
   Component_Definition =>
 Make_Component_Definition (Sloc_N,
-  Aliased_Present => False,
   Subtype_Indication => New_Occurrence_Of (RTE (RE_Tag), Sloc_N)));
 
   if Null_Present (Comp_List)
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index df51856f9c90..2e49a4a68bc0 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -1628,8 +1628,6 @@ package body Exp_Ch9 is
   Make_Defining_Identifier (Loc, Chars (Formal)),
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present =>
-  False,
 Subtype_Indication =>
   New_Occurrence_Of (Comp_Nam, Loc;
 
@@ -4808,7 +4806,7 @@ package body Exp_Ch9 is
   Identifier => New_Occurrence_Of (Blkent, Loc),
   Declarations => New_List (
 
---  _Chain : Activation_Chain;
+--  _Chain : aliased Activation_Chain;
 
 Make_Object_Declaration (Loc,
   Defining_Identifier => Chain,
@@ -4968,7 +4966,6 @@ package body Exp_Ch9 is
 
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present=> False,
 Subtype_Indication =>
   New_Occurrence_Of (Standard_Character, Loc;
 end;
@@ -4984,7 +4981,6 @@ package body Exp_Ch9 is
 
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present=> False,
 Subtype_Indication =>
   Make_Subtype_Indication (Loc,
 Subtype_Mark =>
@@ -5764,7 +5760,6 @@ package body Exp_Ch9 is
   Defining_Identifier  => Make_Temporary (Loc, 'P'),
   Component_Definition =>
 Make_Component_Definition (Loc,
-  Aliased_Present=> False,
   Subtype_Indication =>
 New_Occurrence_Of (RTE (RE_Address), Loc))),
 
@@ -5772,7 +5767,6 @@ package body Exp_Ch9 is
   Defining_Identifier  => Make_Temporary (Loc, 'S'),
   Component_Definition =>
 Make_Component_Definition (Loc,
-  Aliased_Present=> False,
   Subtype_Indication => New_Occurrence_Of (D_T2, Loc;
 
   Decl2 :=
@@ -8153,7 +8147,6 @@ package body Exp_Ch9 is
 Defining_Identifier => Component,
 Component_Definition =>
   Make_Component_Definition (Loc,
-Aliased_Present=> False,
 Subtype_Indication => New_Occurrence_Of (Ctype, Loc;
 
 Next_Formal_With_Extras (Formal);
@@ -9078,14 +9071,12 @@ package body Exp_Ch9 is
if Present (Subtype_Indication (Old_Comp)) then
   New_Comp :=
 Make_Component_Definition (Sloc (Oent),
-  

[gcc r15-6527] ada: Handle C++ exception hierarchies

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:fbe14f65eddd7f450079cff893a2ddc8fb454543

commit r15-6527-gfbe14f65eddd7f450079cff893a2ddc8fb454543
Author: Alexandre Oliva 
Date:   Wed Nov 13 19:21:56 2024 -0300

ada: Handle C++ exception hierarchies

This patch introduces support for defining exceptions in Ada with
C++'s notion of exception type compatibility, such as handling
occurrences of derived types, and obtaining class-wide access to the
thrown/raised objects.  As a bonus, it adds support for C++ dependent
(wrapped) exceptions, and introduces types and interfaces to match
C++'s std::type_info and std::exception.

Support for C++ exceptions with base-type matching, added to raise-gcc
by calling subprograms in Ada units, requires these units and their
dependencies to be linked into programs that link with raise-gcc.

gcc/ada/ChangeLog:

* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-cpp, g-cppstd,
and g-cstyin.
* doc/gnat_rm/interfacing_to_other_languages.rst (Interfacing to 
C++):
Document class-wide matching and new interfaces.
* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Add class-wide
exception matching support with 'B' as language identifier.
* libgnat/a-exexpr.adb (Setup_Current_Excep): Add Id formal.
(Set_Foreign_Occurrence): Likewise.
(Propagate_GCC_Exception): Adjust.
(Set_Exception_Parameter): Likewise.
(Unhandled_Except_Handler): Likewise.
* libgnat/g-cpp.ads: New.
* libgnat/g-cppexc.adb (Raise_Cpp_Exception): Match 'B' lang id.
(Get_Object_Address): New.
(Get_Object): Rewrite.
(Get_Access_To_Object): New.
(Get_Access_To_Tagged_Object): New.
(Get_Type_Info): New.
(Convert_Caught_Object): New.
* libgnat/g-cppexc.ads (Get_Object_Address): New.
(Get_Object): Note the Cpp Convention requirement.
(Get_Access_To_Object): New.
(Get_Access_To_Tagged_Object): New.
(Get_Type_Info): New.
* libgnat/g-cppstd.adb: New.
* libgnat/g-cppstd.ads: New.
* libgnat/g-csclex.ads: New, unused.
* libgnat/g-cstyin.adb: New.
* libgnat/g-cstyin.ads: New.
* libgnat/g-excact.adb (Exception_Language): New.
(Is_Foreign_Exception): Rewrite.
* libgnat/g-excact.ads (Exception_Languages): New.
(Exception_Language): New.
* libgnat/s-stalib.ads (Lang): Document 'B'.
* raise-gcc.c (__gnat_setup_current_excep): Add Exception_Id formal.
(CXX_DEPENDENT_EXCEPTION_CLASS): New.
(cxx_type_info): New.
(__cxa_exception): Rename exceptionType to encompass 
PrimaryException.
(_GNAT_Exception): Drop wrapper.
(EID_For): Adjust.
(exception_class_eq): Likewise.
(__gnat_exception_language_is_cplusplus): New.
(__gnat_exception_language_is_ada): New.
(__gnat_convert_caught_object): Declare.
(__gnat_get_cxx_dependent_exception): New.
(__gnat_maybe_get_cxx_dependent_exception): New.
(__gnat_get_cxx_exception_type_info): New.
(__gnat_obtain_caught_object): New.
(is_handled_by): Adjust.   [!CERT] Add eid formal, handle dependent
exceptions and base-type matches.
(get_action_description_for) [!CERT]: Add eid formal.  Adjust.
(personality_body): Adjust.
* gcc-interface/Make-lang.in (GNAT_ADA_OBJS, GNATBIND_OBJS) 
[!STAGE1]:
Add new g-cpp, g-cppstd, g-cstyin + preexisting g-cppexc
and i-cstrin.
* gnat-style.texi: Regenerate.
* gnat_rm.texi: Regenerate.

Diff:
---
 gcc/ada/Makefile.rtl   |   3 +
 .../doc/gnat_rm/interfacing_to_other_languages.rst | 163 +-
 gcc/ada/exp_prag.adb   |  57 -
 gcc/ada/gcc-interface/Make-lang.in |  10 +
 gcc/ada/gnat-style.texi|   4 +-
 gcc/ada/gnat_rm.texi   | 164 +-
 gcc/ada/libgnat/a-exexpr.adb   |  38 +++-
 gcc/ada/libgnat/g-cpp.ads  |  36 +++
 gcc/ada/libgnat/g-cppexc.adb   | 213 --
 gcc/ada/libgnat/g-cppexc.ads   |  48 +++-
 gcc/ada/libgnat/g-cppstd.adb   | 115 ++
 gcc/ada/libgnat/g-cppstd.ads   |  95 
 gcc/ada/libgnat/g-csclex.ads   |  98 
 gcc/ada/libgnat/g-cstyin.adb   | 122 ++
 gcc/ada/libgnat/g-cstyin.ads   | 141 
 gcc/ada/libgnat/g-excact.adb   |  72 +-
 gcc/ada/libgnat/g-excact.ads 

[gcc r15-6529] ada: Simplify traversal procedures into traversal functions

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c1d22d40490a5b0e2429f0c206e53c8f95948b30

commit r15-6529-gc1d22d40490a5b0e2429f0c206e53c8f95948b30
Author: Piotr Trojanek 
Date:   Wed Jan 31 13:44:19 2024 +0100

ada: Simplify traversal procedures into traversal functions

Instead of using the generic routine Traverse_Proc to set a global flag 
when a
particular node is found, we can use its underlying routine Traverse_Func 
and
check if traversal has been abandoned. We already used this pattern in a 
number
of places; this patch merely applies it the remaining uses of Traverse_Proc.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb (Search_Access_Discriminant, Search_Current_Instance,
Search_Internal_Call): Use traversal function instead of traversal
procedure and remove associated global variables.
* exp_util.adb (Search_Calls): Likewise.
* sem_prag.adb (Contains_Loop_Entry): Likewise.
* sem_util.adb (Mentions_Post_State): Likewise.

Diff:
---
 gcc/ada/exp_ch3.adb  | 67 +---
 gcc/ada/exp_util.adb | 11 ++---
 gcc/ada/sem_prag.adb |  8 ++-
 gcc/ada/sem_util.adb | 15 
 4 files changed, 35 insertions(+), 66 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index afcb0a9d328f..71bca1cdc886 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -10406,63 +10406,57 @@ package body Exp_Ch3 is
 (Decl : Node_Id;
  Rec_Type : Entity_Id) return Boolean
   is
- References_Current_Instance : Boolean := False;
- Has_Access_Discriminant : Boolean := False;
- Has_Internal_Call   : Boolean := False;
-
- function Find_Access_Discriminant
+ function Is_Access_Discriminant
(N : Node_Id) return Traverse_Result;
  --  Look for a name denoting an access discriminant
 
- function Find_Current_Instance
+ function Is_Current_Instance
(N : Node_Id) return Traverse_Result;
  --  Look for a reference to the current instance of the type
 
- function Find_Internal_Call
+ function Is_Internal_Call
(N : Node_Id) return Traverse_Result;
  --  Look for an internal protected function call
 
- --
- -- Find_Access_Discriminant --
- --
+ 
+ -- Is_Access_Discriminant --
+ 
 
- function Find_Access_Discriminant
+ function Is_Access_Discriminant
(N : Node_Id) return Traverse_Result is
  begin
 if Is_Entity_Name (N)
   and then Denotes_Discriminant (N)
   and then Is_Access_Type (Etype (N))
 then
-   Has_Access_Discriminant := True;
return Abandon;
 else
return OK;
 end if;
- end Find_Access_Discriminant;
+ end Is_Access_Discriminant;
 
- ---
- -- Find_Current_Instance --
- ---
+ -
+ -- Is_Current_Instance --
+ -
 
- function Find_Current_Instance
+ function Is_Current_Instance
(N : Node_Id) return Traverse_Result is
  begin
 if Is_Entity_Name (N)
   and then Present (Entity (N))
   and then Is_Current_Instance (N)
 then
-   References_Current_Instance := True;
return Abandon;
 else
return OK;
 end if;
- end Find_Current_Instance;
+ end Is_Current_Instance;
 
- 
- -- Find_Internal_Call --
- 
+ --
+ -- Is_Internal_Call --
+ --
 
- function Find_Internal_Call (N : Node_Id) return Traverse_Result is
+ function Is_Internal_Call (N : Node_Id) return Traverse_Result is
 
 function Call_Scope (N : Node_Id) return Entity_Id;
 --  Return the scope enclosing a given call node N
@@ -10486,21 +10480,20 @@ package body Exp_Ch3 is
   and then Call_Scope (N)
  = Corresponding_Concurrent_Type (Rec_Type)
 then
-   Has_Internal_Call := True;
return Abandon;
 else
return OK;
 end if;
- end Find_Internal_Call;
+ end Is_Internal_Call;
 
- procedure Search_Access_Discriminant is new
-   Traverse_Proc (Find_Access_Discriminant);
+ function Search_Access_Discriminant is new
+   Traverse_Func (Is_Access_Discriminant);
 
- procedure Se

[gcc r15-6543] ada: Rely on default parameter when making non-constant nodes

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:2789e3610ee17c153ab9dc851a4e1ae64afc4103

commit r15-6543-g2789e3610ee17c153ab9dc851a4e1ae64afc4103
Author: Piotr Trojanek 
Date:   Thu Dec 5 17:55:09 2024 +0100

ada: Rely on default parameter when making non-constant nodes

When calling Make_Access_To_Object_Definition and Make_Object_Declaration we
can rely on the default value of parameter Constant_Present being False. 
This
makes code cleaner and consistent with relying on the default value of other
parameters of this routine, like Null_Exclusion_Present.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_disp.adb: Remove explicit actual parameter
Constant_Present equal False; tune comments.

Diff:
---
 gcc/ada/exp_ch3.adb  | 1 -
 gcc/ada/exp_disp.adb | 8 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index b69da39da36e..ad292ee404ee 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2962,7 +2962,6 @@ package body Exp_Ch3 is
   Make_Access_To_Object_Definition (Loc,
 All_Present=> True,
 Null_Exclusion_Present => False,
-Constant_Present   => False,
 Subtype_Indication =>
   New_Occurrence_Of (Rec_Type, Loc);
 
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index 9fcc46944888..906ddc4175c2 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -1527,7 +1527,6 @@ package body Exp_Disp is
   Make_Access_To_Object_Definition (Loc,
 All_Present=> True,
 Null_Exclusion_Present => False,
-Constant_Present   => False,
 Subtype_Indication =>
   New_Occurrence_Of (Desig_Typ, Loc)));
 
@@ -1974,7 +1973,6 @@ package body Exp_Disp is
   Make_Access_To_Object_Definition (Loc,
 All_Present=> True,
 Null_Exclusion_Present => False,
-Constant_Present   => False,
 Subtype_Indication =>
   New_Occurrence_Of (Ftyp, Loc)));
 
@@ -4922,7 +4920,7 @@ package body Exp_Disp is
   if not Building_Static_DT (Typ) then
 
  --  Generate:
- --DT : No_Dispatch_Table_Wrapper;
+ --DT : aliased No_Dispatch_Table_Wrapper;
  --DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
 
  if not Has_DT (Typ) then
@@ -4930,7 +4928,6 @@ package body Exp_Disp is
   Make_Object_Declaration (Loc,
 Defining_Identifier => DT,
 Aliased_Present => True,
-Constant_Present=> False,
 Object_Definition   =>
   New_Occurrence_Of
 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
@@ -4973,7 +4970,7 @@ package body Exp_Disp is
 end if;
 
  --  Generate:
- --DT : Dispatch_Table_Wrapper (Nb_Prim);
+ --DT : aliased Dispatch_Table_Wrapper (Nb_Prim);
  --DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
 
  else
@@ -4992,7 +4989,6 @@ package body Exp_Disp is
   Make_Object_Declaration (Loc,
 Defining_Identifier => DT,
 Aliased_Present => True,
-Constant_Present=> False,
 Object_Definition   =>
   Make_Subtype_Indication (Loc,
 Subtype_Mark =>


[gcc r15-6539] ada: Reuse and simplify counting the length of various lists

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:9c73f9dcca3b7ed29dd80afea0196729630973be

commit r15-6539-g9c73f9dcca3b7ed29dd80afea0196729630973be
Author: Piotr Trojanek 
Date:   Thu Dec 5 14:12:25 2024 +0100

ada: Reuse and simplify counting the length of various lists

Use utility routines to compute number of elements in lists of nodes and 
chains
of formal parameters. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_aggr.adb (Others_Check): Reuse List_Length; tune whitespace.
* exp_ch3.adb (Constrain_Array): Remove counting of constraints.
* exp_disp.adb (Make_DT): Use Elist utility routines; tune 
whitespace.
* sem_ch12.adb (Formal_Dimensions): Reuse List_Length.
(Valid_Default_Attribute): Reuse Number_Formals.
* sem_prag.adb (Process_Convention): Likewise.
* sem_util.adb (Normalize_Actuals): Likewise.
(Check_Function_Writable_Actuals): Reuse List_Length.

Diff:
---
 gcc/ada/exp_aggr.adb | 18 +++---
 gcc/ada/exp_ch3.adb  | 15 ---
 gcc/ada/exp_disp.adb | 18 ++
 gcc/ada/sem_ch12.adb | 22 +-
 gcc/ada/sem_prag.adb | 13 +
 gcc/ada/sem_util.adb | 24 +++-
 6 files changed, 26 insertions(+), 84 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 64bb05c9b4c1..dae9d4e50095 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5352,17 +5352,10 @@ package body Exp_Aggr is
--  Count the number of discrete choices. Start with -1 because
--  the others choice does not count.
 
-   --  Is there some reason we do not use List_Length here ???
-
Nb_Choices := -1;
Assoc := First (Component_Associations (Sub_Aggr));
while Present (Assoc) loop
-  Choice := First (Choice_List (Assoc));
-  while Present (Choice) loop
- Nb_Choices := Nb_Choices + 1;
- Next (Choice);
-  end loop;
-
+  Nb_Choices := Nb_Choices + List_Length (Choice_List (Assoc));
   Next (Assoc);
end loop;
 
@@ -5379,12 +5372,7 @@ package body Exp_Aggr is
  --  choice then compute the number or positional elements.
 
  if Need_To_Check and then Present (Expressions (Sub_Aggr)) then
-Expr := First (Expressions (Sub_Aggr));
-Nb_Elements := Uint_0;
-while Present (Expr) loop
-   Nb_Elements := Nb_Elements + 1;
-   Next (Expr);
-end loop;
+Nb_Elements := UI_From_Int (List_Length (Expressions (Sub_Aggr)));
 
  --  If the aggregate contains discrete choices and an others choice
  --  compute the smallest and largest discrete choice values.
@@ -5395,7 +5383,7 @@ package body Exp_Aggr is
Table : Case_Table_Type (1 .. Nb_Choices);
--  Used to sort all the different choice values
 
-   J: Pos := 1;
+   J : Pos := 1;
 
 begin
Assoc := First (Component_Associations (Sub_Aggr));
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 71bca1cdc886..a68b4f12ca63 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4300,10 +4300,9 @@ package body Exp_Ch3 is
(SI : Node_Id;
 Check_List : List_Id)
  is
-C : constant Node_Id := Constraint (SI);
-Number_Of_Constraints : Nat := 0;
-Index : Node_Id;
-S, T  : Entity_Id;
+C : constant Node_Id := Constraint (SI);
+Index : Node_Id;
+S, T  : Entity_Id;
 
 procedure Constrain_Index
   (Index  : Node_Id;
@@ -4341,12 +4340,6 @@ package body Exp_Ch3 is
T := Designated_Type (T);
 end if;
 
-S := First (Constraints (C));
-while Present (S) loop
-   Number_Of_Constraints := Number_Of_Constraints + 1;
-   Next (S);
-end loop;
-
 --  In either case, the index constraint must provide a discrete
 --  range for each index of the array type and the type of each
 --  discrete range must be the same as that of the corresponding
@@ -4358,7 +4351,7 @@ package body Exp_Ch3 is
 
 --  Apply constraints to each index type
 
-for J in 1 .. Number_Of_Constraints loop
+while Present (S) loop
Constrain_Index (Index, S, Check_List);
Next (Index);
Next (S);
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
index f25011735164..9fcc46944888 100644
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -4650,7 +4650,6 @@ package body Exp_Disp is
   Name_ITable:

[gcc r15-6541] ada: Simplify code for obtaining function entity from a function call

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c20458a12d21a93f4ad5596f64545d6142a7d2dc

commit r15-6541-gc20458a12d21a93f4ad5596f64545d6142a7d2dc
Author: Piotr Trojanek 
Date:   Thu Dec 5 17:12:55 2024 +0100

ada: Simplify code for obtaining function entity from a function call

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* sem_ch5.adb (Check_Call): Reuse Get_Called_Entity.

Diff:
---
 gcc/ada/sem_ch5.adb | 24 ++--
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 2a5c8dcdbe52..944259a532ac 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4536,34 +4536,14 @@ package body Sem_Ch5 is
   
 
   function Check_Call (N : Node_Id) return Traverse_Result is
- Nam  : Node_Id;
  Subp : Entity_Id;
- Typ  : Entity_Id;
 
   begin
  if Nkind (N) = N_Function_Call then
-Nam := Name (N);
-
---  Obtain the subprogram being invoked
-
-loop
-   if Nkind (Nam) = N_Explicit_Dereference then
-  Nam := Prefix (Nam);
-
-   elsif Nkind (Nam) = N_Selected_Component then
-  Nam := Selector_Name (Nam);
-
-   else
-  exit;
-   end if;
-end loop;
-
-Subp := Entity (Nam);
+Subp := Get_Called_Entity (N);
 
 if Present (Subp) then
-   Typ := Etype (Subp);
-
-   if Requires_Transient_Scope (Typ) then
+   if Requires_Transient_Scope (Etype (Subp)) then
   return Abandon;
 
elsif Sec_Stack_Needed_For_Return (Subp) then


[gcc r15-6515] ada: Fix omissions of ALI P line parameters

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:5bb378b68bc58993977de344ea4f0761cdde341b

commit r15-6515-g5bb378b68bc58993977de344ea4f0761cdde341b
Author: Ronan Desplanques 
Date:   Thu Nov 28 11:08:46 2024 +0100

ada: Fix omissions of ALI P line parameters

Before this patch, the compiler would not report various tasking
settings specified in library units when these library units did not use
tasking, or when they were predefined. While this behavior was
implemented deliberately, that was a long time ago and it proved to be
a pitfall that could cause configuration pragmas to be silently ignored.

This patch makes the compiler report the aforementioned tasking settings
in ALI files unconditionally.

Also, this patch fixes an incorrect statement and a couple of typos in
the spec of Lib.Writ.

gcc/ada/ChangeLog:

* lib-writ.adb (Write_ALI): Remove condition for writing P line
parameters.
* lib-writ.ads: Fix typos. Clarify comment.

Diff:
---
 gcc/ada/lib-writ.adb | 26 --
 gcc/ada/lib-writ.ads | 15 ---
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb
index e6bfbf1bb37b..4e7ed5a380a7 100644
--- a/gcc/ada/lib-writ.adb
+++ b/gcc/ada/lib-writ.adb
@@ -1240,22 +1240,20 @@ package body Lib.Writ is
  Write_Info_Str (" DB");
   end if;
 
-  if Tasking_Used and then not Is_Predefined_Unit (Main_Unit) then
- if Locking_Policy /= ' ' then
-Write_Info_Str  (" L");
-Write_Info_Char (Locking_Policy);
- end if;
+  if Locking_Policy /= ' ' then
+ Write_Info_Str  (" L");
+ Write_Info_Char (Locking_Policy);
+  end if;
 
- if Queuing_Policy /= ' ' then
-Write_Info_Str  (" Q");
-Write_Info_Char (Queuing_Policy);
- end if;
+  if Queuing_Policy /= ' ' then
+ Write_Info_Str  (" Q");
+ Write_Info_Char (Queuing_Policy);
+  end if;
 
- if Task_Dispatching_Policy /= ' ' then
-Write_Info_Str  (" T");
-Write_Info_Char (Task_Dispatching_Policy);
-Write_Info_Char (' ');
- end if;
+  if Task_Dispatching_Policy /= ' ' then
+ Write_Info_Str  (" T");
+ Write_Info_Char (Task_Dispatching_Policy);
+ Write_Info_Char (' ');
   end if;
 
   if GNATprove_Mode then
diff --git a/gcc/ada/lib-writ.ads b/gcc/ada/lib-writ.ads
index 38206179dfc7..fc489e7f3c34 100644
--- a/gcc/ada/lib-writ.ads
+++ b/gcc/ada/lib-writ.ads
@@ -228,9 +228,9 @@ package Lib.Writ is
-- OL   Pragma Default_Scalar_Storage_Order (Low_Order_First) is
--  present in a configuration pragma file that applies.
 
-   -- Qx   A valid Queueing_Policy pragma applies to all the units
-   --  in this file, where x is the first character (upper case)
-   --  of the policy name (e.g. 'P' for Priority_Queueing).
+   -- Qx   A valid Queuing_Policy pragma applies to all the units in
+   --  this file, where x is the first character (upper case) of
+   --  the policy name (e.g. 'P' for Priority_Queuing).
 
-- SL   Indicates that the unit is an Interface to a Standalone
--  Library. Note that this indication is never given by the
@@ -253,10 +253,11 @@ package Lib.Writ is
--  generated exception tables. If ZX is not present, the
--  longjmp/setjmp exception scheme is in use.
 
-   --  Note that language defined units never output policy (Lx, Tx, Qx)
-   --  parameters. Language defined units must correctly handle all
-   --  possible cases. These values are checked for consistency by the
-   --  binder and then copied to the generated binder output file.
+   --  Note that library units from the GNAT runtime library should never
+   --  output policy (Lx, Tx, Qx) parameters. They must correctly handle
+   --  all possible cases to be usable in all contexts. These values are
+   --  checked for consistency by the binder and then copied to the
+   --  generated binder output file.
 
--Note: The P line must be present. Even in Ignore_Errors mode, Scan_ALI
--insists on finding a P line. So if changes are made to the ALI format,


[gcc r15-6516] ada: Remove useless space in ALI P lines

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:2f7ff43579e814f05389d9766b149c80eb4bfe5d

commit r15-6516-g2f7ff43579e814f05389d9766b149c80eb4bfe5d
Author: Ronan Desplanques 
Date:   Thu Nov 28 11:45:25 2024 +0100

ada: Remove useless space in ALI P lines

The generated ALI files are syntactically unchanged.

gcc/ada/ChangeLog:

* lib-writ.adb (Write_ALI): Remove useless space.

Diff:
---
 gcc/ada/lib-writ.adb | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb
index 4e7ed5a380a7..992952eed678 100644
--- a/gcc/ada/lib-writ.adb
+++ b/gcc/ada/lib-writ.adb
@@ -1253,7 +1253,6 @@ package body Lib.Writ is
   if Task_Dispatching_Policy /= ' ' then
  Write_Info_Str  (" T");
  Write_Info_Char (Task_Dispatching_Policy);
- Write_Info_Char (' ');
   end if;
 
   if GNATprove_Mode then


[gcc r15-6517] ada: Preliminary work in analysis and expansion of initialized allocators

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:d9ba2b857eb39ab52b1e2f93246af444e837dce4

commit r15-6517-gd9ba2b857eb39ab52b1e2f93246af444e837dce4
Author: Eric Botcazou 
Date:   Sun Dec 1 11:46:46 2024 +0100

ada: Preliminary work in analysis and expansion of initialized allocators

This makes the expansion of the various cases of initialized allocators more
uniform by factoring out common processing as much as possible.  This also
avoids giving the warning or error for a default-initialized allocator when
it is marked with No_Initialization.  No functional changes.

gcc/ada/ChangeLog:

* checks.adb (Apply_Predicate_Check): Preserve Comes_From_Source.
* exp_ch4.adb (Expand_Allocator_Expression): Factor out common code
for the various cases.  Also delay applying the 2nd predicate check.
In the default case, defer to Make_Build_In_Place_Call_In_Allocator
entirely in the build-in-place case.
* sem_ch4.adb (Analyze_Allocator): Do not give the warning or error
for a default-initialized allocator with No_Initialization.

Diff:
---
 gcc/ada/checks.adb  |   4 +
 gcc/ada/exp_ch4.adb | 309 ++--
 gcc/ada/sem_ch4.adb |   6 +-
 3 files changed, 160 insertions(+), 159 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index c30c99b31aa2..467661bf4186 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -2893,6 +2893,10 @@ package body Checks is
 
   if Deref then
  Expr := Make_Explicit_Dereference (Loc, Prefix => Expr);
+
+ --  Preserve Comes_From_Source for Predicate_Check_In_Scope
+
+ Preserve_Comes_From_Source (Expr, N);
   end if;
 
   --  Disable checks to prevent an infinite recursion
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 6f54b5c04b4f..7fda62216612 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -566,18 +566,25 @@ package body Exp_Ch4 is
   PtrT   : constant Entity_Id  := Etype (N);
   DesigT : constant Entity_Id  := Designated_Type (PtrT);
   Special_Return : constant Boolean:= For_Special_Return_Object (N);
+  Static_Match   : constant Boolean:=
+not Is_Constrained (DesigT)
+  or else Subtypes_Statically_Match (T, DesigT);
 
   procedure Build_Aggregate_In_Place (Temp : Entity_Id; Typ : Entity_Id);
   --  If Exp is an aggregate to build in place, build the declaration of
-  --  Temp with Typ and initializing expression an uninitialized allocator
-  --  for Etype (Exp), then perform an in-place aggregate assignment of Exp
-  --  into the allocated memory.
+  --  object Temp with Typ and initialization expression an uninitialized
+  --  allocator for Etype (Exp), then perform in-place aggregate assignment
+  --  of Exp into the newly allocated memory.
 
   procedure Build_Explicit_Assignment (Temp : Entity_Id; Typ : Entity_Id);
   --  If Exp is a conditional expression whose expansion has been delayed,
-  --  build the declaration of Temp with Typ and initializing expression an
-  --  uninitialized allocator for Etype (Exp), then perform an assignment
-  --  of Exp into the allocated memory.
+  --  build the declaration of object Temp with Typ and initialization
+  --  expression an uninitialized allocator for Etype (Exp), then perform
+  --  assignment of Exp into the newly allocated memory.
+
+  procedure Build_Simple_Allocation (Temp : Entity_Id; Typ : Entity_Id);
+  --  Build the declaration of object Temp with Typ and initialization
+  --  expression the allocator N.
 
   --
   -- Build_Aggregate_In_Place --
@@ -587,6 +594,7 @@ package body Exp_Ch4 is
  Temp_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
  Defining_Identifier => Temp,
+ Constant_Present=> True,
  Object_Definition   => New_Occurrence_Of (Typ, Loc),
  Expression  =>
Make_Allocator (Loc,
@@ -625,6 +633,7 @@ package body Exp_Ch4 is
  Temp_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
  Defining_Identifier => Temp,
+ Constant_Present=> True,
  Object_Definition   => New_Occurrence_Of (Typ, Loc),
  Expression  =>
Make_Allocator (Loc,
@@ -653,15 +662,32 @@ package body Exp_Ch4 is
  Insert_Action (N, Assign);
   end Build_Explicit_Assignment;
 
+  -
+  -- Build_Simple_Allocation --
+  -
+
+  procedure Build_Simple_Allocation (Temp : Entity_Id; Typ : Entity_Id) is
+ New_N : constant Node_Id := Relocate_Node (N);
+ Temp_Decl : constant Node_Id :=
+   Make_Object_Declaration (Loc,
+ Defining_Identifier => Temp,
+ 

[gcc r15-6518] ada: Improve expansion of conditional expressions in object declarations

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:1e3619a37aebd8005c8505aebded7957b661577c

commit r15-6518-g1e3619a37aebd8005c8505aebded7957b661577c
Author: Eric Botcazou 
Date:   Mon Dec 2 21:58:29 2024 +0100

ada: Improve expansion of conditional expressions in object declarations

This arranges for conditional expressions in objects declarations to have
their expansion delayed when they have a type that cannot be easily copied
or copied at all, including limited and controlled types.

The ultimate goal is to replace the declaration with a renaming declaration
of the dereference of an access value designating an object initialized with
the dependent expression chosen by the condition.

gcc/ada/ChangeLog:

* einfo.ads (Is_Independent): Document usage on Master_Node objects.
* exp_aggr.adb (In_Place_Assign_OK): Remove Parent_Kind variable.
(Convert_To_Assignments): Call Unconditional_Parent and remove the
restriction on the known size for the in-place expansion of the
aggregate in the context of an object declaration.
(Expand_Array_Aggregate): Remove Parent_Kind variable and call
Unconditional_Parent and Delay_Conditional_Expressions_Between
* exp_ch3.adb: Remove clauses for Exp_Dbug.
(Expand_N_Object_Declaration): Factor out the code rewriting the
declaration as a renaming in Rewrite_Object_Declaration_As_Renaming
and call the procedure.
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Declare.
(Expand_N_Case_Expression): Delay expanding the expression if it is
in the context of an optimizable object declaration.  If the parent
node is this object declaration, then replace it with a renaming of
the dereference of an access value designating an object initialized
with the dependent expression chosen by the condition.
(Expand_N_If_Expression): Likewise.
(Insert_Conditional_Object_Declaration): New procedure.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Test the unconditional
parent in the case of an object declaration too.
* exp_ch7.adb (Build_Finalizer.Process_Declarations): Pass Strict to
Processing_Actions from the Is_Independent flag on a Master_Node.
* exp_util.ads (Rewrite_Object_Declaration_As_Renaming): Declare.
* exp_util.adb: Add clauses for Exp_Dbug.
(Rewrite_Object_Declaration_As_Renaming): New procedure extracted
from Expand_N_Object_Declaration.
* sem_ch3.adb (Analyze_Object_Declaration): Also leave the analysis
if the declaration has been replaced with a renaming in the case of
an initialization expression that is a conditional expression.

Diff:
---
 gcc/ada/einfo.ads|   4 +
 gcc/ada/exp_aggr.adb | 123 +
 gcc/ada/exp_ch3.adb  |  31 +
 gcc/ada/exp_ch4.adb  | 368 +++
 gcc/ada/exp_ch6.adb  |  14 +-
 gcc/ada/exp_ch7.adb  |   3 +-
 gcc/ada/exp_util.adb |  41 ++
 gcc/ada/exp_util.ads |   3 +
 gcc/ada/sem_ch3.adb  |  15 ++-
 9 files changed, 455 insertions(+), 147 deletions(-)

diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index 1a8760c0dbb1..025465265f3c 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -2804,6 +2804,10 @@ package Einfo is
 --   case of private and incomplete types, this flag is set in both the
 --   partial view and the full view.
 
+--   This flag is also set on the Master_Node objects generated by the
+--   compiler (see Finalization_Master_Node above) to indicate that the
+--   associated finalizable object has relaxed finalization semantics.
+
 --Is_Initial_Condition_Procedure
 --   Defined in functions and procedures. Set for a generated procedure
 --   which verifies the assumption of pragma Initial_Condition at run time.
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 344e4d10c5f6..1f1f58061cee 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4119,7 +4119,6 @@ package body Exp_Aggr is
 
   --  Local variables
 
-  Parent_Kind : Node_Kind;
   Parent_Node : Node_Id;
 
--  Start of processing for In_Place_Assign_OK
@@ -4132,11 +4131,9 @@ package body Exp_Aggr is
   end if;
 
   Parent_Node := Parent (N);
-  Parent_Kind := Nkind (Parent_Node);
 
-  if Parent_Kind = N_Qualified_Expression then
+  if Nkind (Parent_Node) = N_Qualified_Expression then
  Parent_Node := Parent (Parent_Node);
- Parent_Kind := Nkind (Parent_Node);
   end if;
 
   --  On assignment, sliding can take place, so we cannot do the
@@ -4161,44 +4158,11 @@ package body Exp_Aggr is
procedure Convert_To_Assignments (N : Node_Id; Typ : Entity_Id) is
   Loc : constant Source_Ptr := Sloc (N);
 
-  function Known_Size

[gcc r15-6519] ada: Avoid failing reanalysis of aggregate bounds

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:05f211ab748c478196ece74948efa14f05f78dcb

commit r15-6519-g05f211ab748c478196ece74948efa14f05f78dcb
Author: Steve Baird 
Date:   Mon Dec 2 16:45:37 2024 -0800

ada: Avoid failing reanalysis of aggregate bounds

An expression like Some_Package."+" (Arg1, Arg2) is sometimes transformed
during expansion into an unqualified call of the form "+" (Arg1, Arg2).
This is normally ok, but it means that reanalysis of the expression is 
likely
to fail and must therefore be avoided. Remove code that was forcing such
reanalysis (the original reason for the now-removed code is unknown).

gcc/ada/ChangeLog:

* exp_aggr.adb (Check_Bounds): Remove calls that were setting the
Analyzed flag to False for two aggregate bound expressions.

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

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 1f1f58061cee..64bb05c9b4c1 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5144,8 +5144,6 @@ package body Exp_Aggr is
 
 Right_Opnd => Cond);
 
-Set_Analyzed (Left_Opnd  (Left_Opnd (Cond)), False);
-Set_Analyzed (Right_Opnd (Left_Opnd (Cond)), False);
 Insert_Action (N,
   Make_Raise_Constraint_Error (Loc,
 Condition => Cond,


[gcc r15-6528] ada: Assorted style cleanups

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:b045b3e266f9897a0e3fe15d333bdcb486ae288b

commit r15-6528-gb045b3e266f9897a0e3fe15d333bdcb486ae288b
Author: Piotr Trojanek 
Date:   Wed Dec 4 16:22:05 2024 +0100

ada: Assorted style cleanups

Whitespace and comment cleanups.

gcc/ada/ChangeLog:

* sem_attr.adb (Eval_Attribute): Fix comment for attribute Image.
* tbuild.adb (Make_SC): Remove extra whitespace.

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

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 6cee808d89ab..6eb04b2e2582 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -9448,7 +9448,7 @@ package body Sem_Attr is
   ---
 
   --  Image is a scalar attribute, but is never static, because it is
-  --  not a static function (having a non-scalar argument (RM 4.9(22))
+  --  not a static function (having a non-scalar argument (RM 4.9(22)).
   --  However, we can constant-fold the image of an enumeration literal
   --  if names are available and default Image implementation has not
   --  been overridden.
diff --git a/gcc/ada/tbuild.adb b/gcc/ada/tbuild.adb
index 31154266bcb4..598030bd5dbb 100644
--- a/gcc/ada/tbuild.adb
+++ b/gcc/ada/tbuild.adb
@@ -492,7 +492,7 @@ package body Tbuild is
-- Make_SC --
-
 
-   function  Make_SC (Pre, Sel : Node_Id) return Node_Id is
+   function Make_SC (Pre, Sel : Node_Id) return Node_Id is
begin
   return
 Make_Selected_Component (System_Location,


[gcc r15-6524] ada: Leave empty parent in an array component of an anonymous access type

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:cca7647392727038c86a9eb785cbd673896afa57

commit r15-6524-gcca7647392727038c86a9eb785cbd673896afa57
Author: Piotr Trojanek 
Date:   Wed Dec 4 13:45:24 2024 +0100

ada: Leave empty parent in an array component of an anonymous access type

An itype created for a record component with an anonymous access type has 
empty
parent. However, a similar itype created for an array component has its 
parent
copied from the parent of the array type.

The above discrepancy appears to be not needed for the frontend. Also, it is
confusing for the GNATprove backend, because it looks like the itype entity
of the array component comes from a declaration of the array itself.

gcc/ada/ChangeLog:

* sem_ch3.adb (Array_Type_Declaration): Don't copy parent for an 
itype
created by an array component declaration.

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

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index eb53d59032c6..7bedc043c8d4 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -6612,12 +6612,6 @@ package body Sem_Ch3 is
 N   => Access_Definition (Component_Def));
  Set_Is_Local_Anonymous_Access (Element_Type);
 
- --  Propagate the parent. This field is needed if we have to generate
- --  the master_id associated with an anonymous access to task type
- --  component (see Expand_N_Full_Type_Declaration.Build_Master)
-
- Copy_Parent (To => Element_Type, From => T);
-
  --  Ada 2005 (AI-230): In case of components that are anonymous access
  --  types the level of accessibility depends on the enclosing type
  --  declaration


[gcc r15-6526] ada: Improve and correct support for inheritance of nonoverriding aspects

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:758de5fed10a7c964bb06a143a3dc3c308721ddd

commit r15-6526-g758de5fed10a7c964bb06a143a3dc3c308721ddd
Author: Gary Dismukes 
Date:   Mon Nov 4 06:06:21 2024 +

ada: Improve and correct support for inheritance of nonoverriding aspects

This set of changes fixes various issues with the handling of inheritance
of nonoverridable aspects (such as for Aggregate, and the indexing and
iterator aspects, among others), plus improves some of the error reporting
related to those. The prior implementation incorrectly handled types
derived from container types with respect to such aspect inheritance,
not properly inheriting the parent type's aspects, leading to rejection
of legal constructs (such as container aggregates for the derived type).
Also, various errors were incorrect (such as stating the wrong aspect)
or unclear.

In the case of types with indexing aspects, the resolution of indexed
names for such types involved locating the eligible indexing functions
anew with the analysis of each indexed name, which was both inefficient
and wrong in some cases. That is addressed by locating the functions once,
when the aspects are resolved, rather doing the location of those in two
places, which is a maintenance hazard and could result in inconsistent
resolution.

Note that this completes work originally undertaken by Ed Schonberg
that was also worked on by Steve Baird.

gcc/ada/ChangeLog:

* diagnostics-constructors.adb 
(Make_Default_Iterator_Not_Primitive_Error):
Revise message to match message change made in sem_ch13.adb.
* freeze.adb (Freeze_Record_Type): Output appropriate aspect name in
error message, using Get_Name_String.
(Freeze_Entity): For derived types, call 
Analyze_Aspects_At_Freeze_Point
on the parent type, and call Inherit_Nonoverridable_Aspects on the 
type
(for both parent type and any progenitor types). Add with_clause for
System.Case_Util.
* gen_il-fields.ads: Add Aspect_Subprograms to type Opt_Field_Enum.
* gen_il-gen-gen_nodes.adb: Add field Aspect_Subprograms to
N_Aspect_Specification nodes.
* sem_ch4.adb (Try_Container_Indexing): Remove 
Find_Indexing_Operations
and the code calling it. Add new function Indexing_Interpretations 
for
retrieving the eligible indexing functions from the appropriate 
aspect's
Aspect_Subprograms list and call that instead of 
Find_Value_Of_Aspect.
* sem_ch7.adb (Analyze_Package_Specification): In loop over 
entities,
call Analyze_Aspects_At_Freeze_Point for types that have delayed
aspects.
* sem_ch13.ads (Analyze_Aspects_At_Freeze_Point): Add 
Nonoverridable_Only
formal to restrict processing to nonoverridable aspects.
(Check_Function_For_Indexing_Aspect): New exported procedure renamed
from Check_One_Function and moved to library level.
* sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Test new formal
Nonoverridable_Only formal to skip processing of aspects that are 
not
nonoverridable when the formal is True. Skip the processing for
Aspect_Full_Access_Only when Nonoverridable_Only is True. Call
Check_Indexing_Functions in the case of indexing aspects (procedure
moved from Analyze_Attribute_Definition_Clause to top level).
(Analyze_Aspect_Specifications): Locate closest ancestor type with 
an
explicit matching aspect to determine the aspect spec to reference 
in
the error about a nonoverridable aspect not confirming an inherited
aspect (skipping intermediate derived parents). Ensures that we 
retain
existing errors flagged on explicit ancestor aspects rather than
implicit inherited ones. Change names of variables Parent_Type and
Inherited_Aspect to Ancestor_Type and Ancestor_Aspect respectively
for clarity.
(Analyze_Attribute_Definition_Clause): Move nested subprograms
Check_Iterator_Functions and Check_Primitive_Function to top level
of package. Move Check_Indexing_Functions (and its nested 
subprograms)
from here to within Analyze_Aspects_At_Freeze_Point (adding some
formal parameters and adjusting the code appropriately, and no 
longer
call it from this procedure).
(Is_CW_Or_Access_To_CW): Add test for the parent type having the
indexing aspect for proper setting of 
Aspect_Specification_Is_Inherited.
Delete "???" comment.
(Look_Through_Anon_Access): Remove unneeded tests of 
Is_Access_Constant
and Name_Constant_Indexing, which lead to wrong messages in some 
cases.
(Check_Functi

[gcc r15-6531] ada: Simplify uses of the global name buffer

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:0c0d73490570674a311022efb31d4315008c

commit r15-6531-g0c0d73490570674a311022efb31d4315008c
Author: Piotr Trojanek 
Date:   Wed Dec 4 16:42:29 2024 +0100

ada: Simplify uses of the global name buffer

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_dist.adb (Assign_Subprogram_Identifier,
Reserve_NamingContext_Methods): Simplify.
* osint.adb (Append_Suffix_To_File_Name, Find_File, Get_Directory,
Object_File_Name, Strip_Directory): Likewise.

Diff:
---
 gcc/ada/exp_dist.adb |  8 ++--
 gcc/ada/osint.adb| 22 +-
 2 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/gcc/ada/exp_dist.adb b/gcc/ada/exp_dist.adb
index fcfeba0e1a67..e8f9b68baf35 100644
--- a/gcc/ada/exp_dist.adb
+++ b/gcc/ada/exp_dist.adb
@@ -2089,8 +2089,7 @@ package body Exp_Dist is
   --  disambiguated within their own scope.
 
   if Overload_Order > 1 then
- Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "__";
- Name_Len := Name_Len + 2;
+ Add_Str_To_Name_Buffer ("__");
  Add_Nat_To_Name_Buffer (Overload_Order);
   end if;
 
@@ -11188,11 +11187,8 @@ package body Exp_Dist is
   ---
 
   procedure Reserve_NamingContext_Methods is
- Str_Resolve : constant String := "resolve";
   begin
- Name_Buffer (1 .. Str_Resolve'Length) := Str_Resolve;
- Name_Len := Str_Resolve'Length;
- Overload_Counter_Table.Set (Name_Find, 1);
+ Overload_Counter_Table.Set (Name_Find ("resolve"), 1);
   end Reserve_NamingContext_Methods;
 
   ---
diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb
index 645cb630b13b..364c069a099f 100644
--- a/gcc/ada/osint.adb
+++ b/gcc/ada/osint.adb
@@ -658,8 +658,7 @@ package body Osint is
is
begin
   Get_Name_String (Name);
-  Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix;
-  Name_Len := Name_Len + Suffix'Length;
+  Add_Str_To_Name_Buffer (Suffix);
   return Name_Find;
end Append_Suffix_To_File_Name;
 
@@ -1225,12 +1224,8 @@ package body Osint is
   declare
  Full_Path : constant String :=
Normalize_Pathname (Get_Name_String (N));
- Full_Size : constant Natural := Full_Path'Length;
-
   begin
- Name_Buffer (1 .. Full_Size) := Full_Path;
- Name_Len := Full_Size;
- Found:= Name_Find;
+ Found := Name_Find (Full_Path);
   end;
end if;
 
@@ -1446,9 +1441,7 @@ package body Osint is
  end if;
   end loop;
 
-  Name_Len := Hostparm.Normalized_CWD'Length;
-  Name_Buffer (1 .. Name_Len) := Hostparm.Normalized_CWD;
-  return Name_Find;
+  return Name_Find (Hostparm.Normalized_CWD);
end Get_Directory;
 
--
@@ -2182,10 +2175,7 @@ package body Osint is
   Get_Name_String (N);
   Name_Len := Name_Len - ALI_Suffix'Length - 1;
 
-  for J in Target_Object_Suffix'Range loop
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := Target_Object_Suffix (J);
-  end loop;
+  Add_Str_To_Name_Buffer (Target_Object_Suffix);
 
   return Name_Enter;
end Object_File_Name;
@@ -2935,9 +2925,7 @@ package body Osint is
 
 --  Return part of Name that follows this last directory separator
 
-Name_Buffer (1 .. Name_Len - J) := Name_Buffer (J + 1 .. Name_Len);
-Name_Len := Name_Len - J;
-return Name_Find;
+return Name_Find (Name_Buffer (J + 1 .. Name_Len));
  end if;
   end loop;


[gcc r15-6523] ada: Incompatible conversion on vxworks in socket.c

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:34ace6d7b63d04d26fe7b190764ede70aaa75f32

commit r15-6523-g34ace6d7b63d04d26fe7b190764ede70aaa75f32
Author: Douglas B Rupp 
Date:   Mon Aug 5 13:17:38 2024 -0700

ada: Incompatible conversion on vxworks in socket.c

In the vxworks section, a conversion between char* and int is
attempted, which results in a warning with gcc. However with clang
with is an error. Note also on 64bit targets, there's a size
mismatch.

gcc/ada/ChangeLog:

* socket.c [__vxworks]: Change vxw_h_addr type to long from
int, and cast the conversion of char* to vxw_h_addr to avoid
warning/error.

Diff:
---
 gcc/ada/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/socket.c b/gcc/ada/socket.c
index 75b4288a129e..297d303cef7d 100644
--- a/gcc/ada/socket.c
+++ b/gcc/ada/socket.c
@@ -266,7 +266,7 @@ __gnat_getservbyport (int port, const char *proto,
 #elif defined (__vxworks)
 static char vxw_h_name[MAXHOSTNAMELEN + 1];
 static char *vxw_h_aliases[1] = { NULL };
-static int vxw_h_addr;
+static long vxw_h_addr;
 static char *vxw_h_addr_list[2] = { (char*) &vxw_h_addr, NULL };
 
 int
@@ -307,7 +307,7 @@ __gnat_gethostbyaddr (const char *addr, int len, int type,
 return -1;
   }
 
-  vxw_h_addr   = addr;
+  vxw_h_addr   = (long) addr;
 
   ret->h_name  = &vxw_h_name;
   ret->h_aliases   = &vxw_h_aliases;


[gcc r15-6522] ada: Do not search executables in current dir by default

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:fdf84665158e44c4dc0fdc63b023784a8c091f04

commit r15-6522-gfdf84665158e44c4dc0fdc63b023784a8c091f04
Author: Tonu Naks 
Date:   Tue Dec 3 12:50:45 2024 +

ada: Do not search executables in current dir by default

gcc/ada/ChangeLog:

* adaint.c: change default behaviour of __gnat_locate_exec_on_path
* adaint.h: change prototype of __gnat_locate_exec_on_path
* libgnat/s-os_lib.adb: pass optional argument in 
Locate_Exec_On_Path
* libgnat/s-os_lib.ads: change spec of Locate_Exec_On_Path
* libgnat/s-trasym__dwarf.adb: update import of 
__gnat_locate_exec_on_path

Diff:
---
 gcc/ada/adaint.c| 31 +--
 gcc/ada/adaint.h|  2 +-
 gcc/ada/libgnat/s-os_lib.adb| 11 ---
 gcc/ada/libgnat/s-os_lib.ads|  9 -
 gcc/ada/libgnat/s-trasym__dwarf.adb |  7 +--
 5 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 9ccac305dde9..0b6d4bb6b4e5 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -3079,32 +3079,35 @@ __gnat_locate_exec (char *exec_name, char *path_val)
 /* Locate an executable using the Systems default PATH.  */
 
 char *
-__gnat_locate_exec_on_path (char *exec_name)
+__gnat_locate_exec_on_path (char *exec_name, int current_dir_on_windows)
 {
   char *apath_val;
 
 #if defined (_WIN32)
   TCHAR *wpath_val = _tgetenv (_T("PATH"));
-  TCHAR *wapath_val;
-  /* In Win32 systems we expand the PATH as for XP environment
- variables are not automatically expanded. We also prepend the
- ".;" to the path to match normal NT path search semantics */
-
   #define EXPAND_BUFFER_SIZE 32767
+  apath_val = (char *) alloca (EXPAND_BUFFER_SIZE);
 
-  wapath_val = (TCHAR *) alloca (EXPAND_BUFFER_SIZE);
+  if (current_dir_on_windows) {
+TCHAR *wapath_val;
+/* In Win32 systems we expand the PATH as for XP environment
+  variables are not automatically expanded. We also prepend the
+  ".;" to the path to match normal NT path search semantics */
 
-  wapath_val [0] = '.';
-  wapath_val [1] = ';';
+wapath_val = (TCHAR *) alloca (EXPAND_BUFFER_SIZE);
 
-  DWORD res = ExpandEnvironmentStrings
-(wpath_val, &wapath_val[2], EXPAND_BUFFER_SIZE - 2);
+wapath_val [0] = '.';
+wapath_val [1] = ';';
 
-  if (!res) wapath_val [0] = _T('\0');
+DWORD res = ExpandEnvironmentStrings
+  (wpath_val, &wapath_val[2], EXPAND_BUFFER_SIZE - 2);
 
-  apath_val = (char *) alloca (EXPAND_BUFFER_SIZE);
+if (!res) wapath_val [0] = _T('\0');
 
-  WS2SC (apath_val, wapath_val, EXPAND_BUFFER_SIZE);
+WS2SC (apath_val, wapath_val, EXPAND_BUFFER_SIZE);
+  } else {
+WS2SC (apath_val, wpath_val, EXPAND_BUFFER_SIZE);
+  }
 
 #else
   const char *path_val = getenv ("PATH");
diff --git a/gcc/ada/adaint.h b/gcc/ada/adaint.h
index 0cbfd0e151d8..26184640211a 100644
--- a/gcc/ada/adaint.h
+++ b/gcc/ada/adaint.h
@@ -240,7 +240,7 @@ extern int__gnat_portable_wait (int *);
 extern int__gnat_portable_no_block_wait(int *);
 extern int__gnat_current_process_id(void);
 extern char  *__gnat_locate_exec   (char *, char *);
-extern char  *__gnat_locate_exec_on_path   (char *);
+extern char  *__gnat_locate_exec_on_path   (char *, int);
 extern char  *__gnat_locate_regular_file   (char *, char *);
 extern void   __gnat_maybe_glob_args   (int *, char ***);
 extern void   __gnat_os_exit  (int);
diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
index dd2156e1dcb5..d249663e73a4 100644
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -34,6 +34,7 @@ with Ada.Unchecked_Deallocation;
 with System.Case_Util;
 with System.CRTL;
 with System.Soft_Links;
+with Interfaces.C;
 
 package body System.OS_Lib is
 
@@ -1641,9 +1642,12 @@ package body System.OS_Lib is
-
 
function Locate_Exec_On_Path
- (Exec_Name : String) return String_Access
+ (Exec_Name : String;
+  Current_Dir_On_Win : Boolean := False) return String_Access
is
-  function Locate_Exec_On_Path (C_Exec_Name : Address) return Address;
+  function Locate_Exec_On_Path
+(C_Exec_Name: Address;
+ Current_Dir_On_Win : Interfaces.C.int) return Address;
   pragma Import (C, Locate_Exec_On_Path, "__gnat_locate_exec_on_path");
 
   C_Exec_Name  : String (1 .. Exec_Name'Length + 1);
@@ -1655,7 +1659,8 @@ package body System.OS_Lib is
   C_Exec_Name (1 .. Exec_Name'Length)   := Exec_Name;
   C_Exec_Name (C_Exec_Name'Last):= ASCII.NUL;
 
-  Path_Addr := Locate_Exec_On_Path (C_Exec_Name'Address);
+  Path_Addr := Locate_Exec_On_Path
+(C_Exec_Name'Address, (if Current_Dir_On_Win then 1 else 0));
   Path_Len  := C_String_Length (Path_Addr);
 
   if Path_Len = 

[gcc r15-6532] ada: Reuse existing utility routine to detect attribute Loop_Entry

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:6bb5439c74a029446c14a4925e52d1b67afced0a

commit r15-6532-g6bb5439c74a029446c14a4925e52d1b67afced0a
Author: Piotr Trojanek 
Date:   Wed Dec 4 19:20:31 2024 +0100

ada: Reuse existing utility routine to detect attribute Loop_Entry

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* checks.adb (Generate_Index_Checks): Reuse existing utility 
routine.
* sem_ch4.adb (Analyze_Indexed_Component_Form): Likewise.
* sem_prag.adb (Analyze_Pragma): Likewise.

Diff:
---
 gcc/ada/checks.adb   | 4 +---
 gcc/ada/sem_ch4.adb  | 4 +---
 gcc/ada/sem_prag.adb | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 467661bf4186..d445ca828ae0 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -7306,9 +7306,7 @@ package body Checks is
   --  Delay the generation of the check until 'Loop_Entry has been properly
   --  expanded. This is done in Expand_Loop_Entry_Attributes.
 
-  elsif Nkind (Prefix (N)) = N_Attribute_Reference
-and then Attribute_Name (Prefix (N)) = Name_Loop_Entry
-  then
+  elsif Is_Attribute_Loop_Entry (Prefix (N)) then
  return;
   end if;
 
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 6a3b7c6e0a98..18b3a4fc22f5 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -3053,9 +3053,7 @@ package body Sem_Ch4 is
   --  the indexed component denotes a loop name, the indexed form is turned
   --  into an attribute reference.
 
-  elsif Nkind (N) = N_Attribute_Reference
-and then Attribute_Name (N) = Name_Loop_Entry
-  then
+  elsif Is_Attribute_Loop_Entry (N) then
  return;
   end if;
 
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index b45be1747981..50ba96bbef1d 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -13646,9 +13646,7 @@ package body Sem_Prag is
 
function Process (N : Node_Id) return Traverse_Result is
begin
-  if Nkind (N) = N_Attribute_Reference
-and then Attribute_Name (N) = Name_Loop_Entry
-  then
+  if Is_Attribute_Loop_Entry (N) then
  return Abandon;
   else
  return OK;


[gcc r15-6533] ada: Refine subtype of a universal arithmetic utility routine

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:e0dfc10707dcc78e21bc239de127603ec9e1050a

commit r15-6533-ge0dfc10707dcc78e21bc239de127603ec9e1050a
Author: Piotr Trojanek 
Date:   Wed Dec 4 19:23:08 2024 +0100

ada: Refine subtype of a universal arithmetic utility routine

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* uintp.adb (N_Digits): Refine return subtype, since this routine
always returns a positive number of digits.

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

diff --git a/gcc/ada/uintp.adb b/gcc/ada/uintp.adb
index fc548e02d570..59ed5b045889 100644
--- a/gcc/ada/uintp.adb
+++ b/gcc/ada/uintp.adb
@@ -174,7 +174,7 @@ package body Uintp is
--  K is as small as possible S.T. Right_Hat < Base * Base. It is required
--  that Left >= Right for the algorithm to work.
 
-   function N_Digits (Input : Valid_Uint) return Int;
+   function N_Digits (Input : Valid_Uint) return Pos;
pragma Inline (N_Digits);
--  Returns number of "digits" in a Uint
 
@@ -603,7 +603,7 @@ package body Uintp is
-- N_Digits --
---
 
-   function N_Digits (Input : Valid_Uint) return Int is
+   function N_Digits (Input : Valid_Uint) return Pos is
begin
   if Direct (Input) then
  if Direct_Val (Input) >= Base then


[gcc r15-6520] ada: Warn on unmodified parameters of expression functions

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:2c1200d671759d7d138a15b3f891d88cc5fc48da

commit r15-6520-g2c1200d671759d7d138a15b3f891d88cc5fc48da
Author: Bob Duff 
Date:   Tue Dec 3 17:49:15 2024 -0500

ada: Warn on unmodified parameters of expression functions

If an 'out' or 'in out' parameter is not modified in a function body,
we warn. However, the warning was missing when we have an expression
function instead of a proper body. This patch enables the warning
on expression functions.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Expression_Function): Mark the implicit
spec for an expression function as Comes_From_Source.
(Analyze_Null_Procedure): Minor cleanup.
* sem_warn.adb (Source_E1): New function to compute whether
to give warnings. In particular, return True for [in] out
parameters of expression functions.

Diff:
---
 gcc/ada/sem_ch6.adb  | 16 ++--
 gcc/ada/sem_warn.adb | 44 
 2 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index a3b521ddad4b..2f09284ebdad 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -310,7 +310,7 @@ package body Sem_Ch6 is
   Typ  : Entity_Id := Empty;
 
   Def_Id : Entity_Id := Empty;
-  Prev   : Entity_Id;
+  Prev   : Entity_Id := Current_Entity_In_Scope (Defining_Entity (Spec));
   --  If the expression is a completion, Prev is the entity whose
   --  declaration is completed. Def_Id is needed to analyze the spec.
 
@@ -325,10 +325,15 @@ package body Sem_Ch6 is
   Inline_Processing_Required := True;
 
   --  Create a specification for the generated body. This must be done
-  --  prior to the analysis of the initial declaration.
+  --  prior to the analysis of the initial declaration. We mark the
+  --  generated Defining_Unit_Name as Comes_From_Source to avoid
+  --  suppressing warnings on it. We do not do that in instances,
+  --  because of arcane interactions with ghost generics.
 
   New_Spec := Copy_Subprogram_Spec (Spec);
-  Prev := Current_Entity_In_Scope (Defining_Entity (Spec));
+  if not In_Instance then
+ Set_Comes_From_Source (Defining_Unit_Name (New_Spec));
+  end if;
 
   --  Copy SPARK pragma from expression function
 
@@ -1363,11 +1368,10 @@ package body Sem_Ch6 is
   Form   : Node_Id;
   Null_Body  : Node_Id := Empty;
   Null_Stmt  : Node_Id := Null_Statement (Spec);
-  Prev   : Entity_Id;
+  Prev   : Entity_Id :=
+Current_Entity_In_Scope (Defining_Entity (Spec));
 
begin
-  Prev := Current_Entity_In_Scope (Defining_Entity (Spec));
-
   --  A null procedure is Ghost when it is stand-alone and is subject to
   --  pragma Ghost, or when the corresponding spec is Ghost. Set the mode
   --  now, to ensure that any nodes generated during analysis and expansion
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 2ffd631d6283..2eac80246a69 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -861,6 +861,13 @@ package body Sem_Warn is
   --  Return True if it is OK for an object of type T to be referenced
   --  without having been assigned a value in the source.
 
+  function Source_E1 return Boolean;
+  --  True if E1 is sufficiently "from source" to warrant a warning.
+  --  We are only interested in source entities. We also don't issue
+  --  warnings within instances, since the proper place for such
+  --  warnings is on the template when it is compiled. Expression
+  --  functions are a special case (see body).
+
   function Warnings_Off_E1 return Boolean;
   --  Return True if Warnings_Off is set for E1, or for its Etype (E1T),
   --  or for the base type of E1T.
@@ -1156,6 +1163,34 @@ package body Sem_Warn is
  end if;
   end Type_OK_For_No_Value_Assigned;
 
+  ---
+  -- Source_E1 --
+  ---
+
+  function Source_E1 return Boolean is
+  begin
+ if Instantiation_Location (Sloc (E1)) /= No_Location then
+return False;
+ end if;
+
+ if Comes_From_Source (E1) then
+return True;
+ end if;
+
+ --  In the special case of an expression function, which has been
+ --  turned into an E_Subprogram_Body, we want to warn about unmodified
+ --  [in] out parameters.
+
+ if Ekind (E) = E_Subprogram_Body
+   and then Comes_From_Source (E)
+   and then Ekind (E1) in E_In_Out_Parameter | E_Out_Parameter
+ then
+return True;
+ end if;
+
+ return False;
+  end Source_E1;
+
   -
   -- Warnings_Off_E1 --
   -
@@ -1190,14 +1225,7 @@ package body Sem_Warn is
 
   E1 := First_Entity (E);
   while Present (E1) lo

[gcc r15-6530] ada: Simplify check for No_Coextensions restriction

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:299c1045a22564ea54a2f37d01e198df8eddf0a9

commit r15-6530-g299c1045a22564ea54a2f37d01e198df8eddf0a9
Author: Piotr Trojanek 
Date:   Wed Dec 4 16:26:45 2024 +0100

ada: Simplify check for No_Coextensions restriction

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_res.adb (Resolve_Alocator): Move unrelated code out of a 
declare
block.

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

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 27309b2e0192..889cbd307b4c 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -5821,13 +5821,13 @@ package body Sem_Res is
   and then Nkind (Associated_Node_For_Itype (Typ)) =
  N_Discriminant_Specification
 then
+   Check_Restriction (No_Coextensions, N);
+
declare
   Discr : constant Entity_Id :=
 Defining_Identifier (Associated_Node_For_Itype (Typ));
 
begin
-  Check_Restriction (No_Coextensions, N);
-
   --  Ada 2012 AI05-0052: If the designated type of the
   --  allocator is limited, then the allocator shall not
   --  be used to define the value of an access discriminant


[gcc r15-6525] ada: Fix small thinko in previous change

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:4b330318626ec5907436aea8eb9c326da85f1e61

commit r15-6525-g4b330318626ec5907436aea8eb9c326da85f1e61
Author: Eric Botcazou 
Date:   Wed Dec 4 12:35:29 2024 +0100

ada: Fix small thinko in previous change

Even if the declaration of the conditional object is turned into a renaming
during expansion, the conditional object must be finalized when the original
object would have been.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Create the
Master_Node even if the declaration is turned into a renaming.

Diff:
---
 gcc/ada/exp_ch4.adb | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 2fc891a4e390..f44f21d654bb 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -13240,9 +13240,7 @@ package body Exp_Ch4 is
   --  cannot invoke Process_Transients_In_Expression on it since it is not
   --  a transient object (it has the lifetime of the original object).
 
-  if Nkind (Obj_Decl) = N_Object_Declaration
-and then Needs_Finalization (Base_Type (Etype (Obj_Id)))
-  then
+  if Needs_Finalization (Base_Type (Etype (Obj_Id))) then
  Master_Node_Id := Make_Temporary (Loc, 'N');
  Master_Node_Decl :=
Make_Master_Node_Declaration (Loc, Master_Node_Id, Obj_Id);


[gcc r15-6535] ada: Add parentheses in expressions involving combinations of and & or

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:98e37c6ca5a0b3dd2729dcf3e79df40edb020f52

commit r15-6535-g98e37c6ca5a0b3dd2729dcf3e79df40edb020f52
Author: Tucker Taft 
Date:   Wed Dec 4 16:22:10 2024 +

ada: Add parentheses in expressions involving combinations of and & or

In the Expression_Image function, we were not inserting
parentheses properly when there was a sequence of
and and or operators, even though Ada requires such
parentheses to show the correct order of association.

gcc/ada/ChangeLog:

* pprint.adb (Expression_Image): In local function Expr_Name
add a No_Parens flag and define a subtype Not_Associative
to represent the short-circuit operations and And/Or/Xor.
Insert parentheses to separate the subexpressions when
different "Not_Associative" operations occur in a
sequence.

Diff:
---
 gcc/ada/pprint.adb | 53 ++---
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb
index b5935fcb0b47..5958a6b47b29 100644
--- a/gcc/ada/pprint.adb
+++ b/gcc/ada/pprint.adb
@@ -57,12 +57,16 @@ package body Pprint is
   function Expr_Name
 (Expr: Node_Id;
  Take_Prefix : Boolean := True;
- Expand_Type : Boolean := True) return String;
+ Expand_Type : Boolean := True;
+ No_Parens   : Boolean := False) return String;
   --  Return string corresponding to Expr. If no string can be extracted,
   --  return "...". If Take_Prefix is True, go back to prefix when needed,
   --  otherwise only consider the right-hand side of an expression. If
   --  Expand_Type is True and Expr is a type, try to expand Expr (an
   --  internally generated type) into a user understandable name.
+  --  If No_Parens is True, then suppress creating parentheses
+  --  around expression.  If False, check to see whether expression
+  --  should be parenthesized.
 
   function Count_Parentheses (S : String; C : Character) return Natural
 with Pre => C in '(' | ')';
@@ -70,6 +74,8 @@ package body Pprint is
   --  to string S for getting a correctly parenthesized result. For C = '('
   --  this means prepending the character, for C = ')' this means appending
   --  the character.
+  --  In other words, count the number of missing instances of C,
+  --  but never return less than zero.
 
   function Fix_Parentheses (S : String) return String;
   --  Counts the number of required opening and closing parentheses in S to
@@ -101,6 +107,7 @@ package body Pprint is
  Elmt : Node_Id;
 
  Printed_Elmts : Natural := 0;
+ List_Len : constant Natural := Natural (List_Length (List));
 
   begin
  --  Give up if the printed list is too deep
@@ -146,7 +153,8 @@ package body Pprint is
 --  Print expression itself as "12345"
 
 else
-   Append (Buf, Expr_Name (Elmt));
+   Append (Buf, Expr_Name (Elmt, No_Parens => List_Len = 1));
+  --  Suppress parens if is the only parameter.
 end if;
 
 Next (Elmt);
@@ -178,9 +186,32 @@ package body Pprint is
   function Expr_Name
 (Expr: Node_Id;
  Take_Prefix : Boolean := True;
- Expand_Type : Boolean := True) return String
+ Expand_Type : Boolean := True;
+ No_Parens   : Boolean := False) return String
   is
+ --  Define subtype matching logical operations
+ --  and [then], or [else], and xor.
+ subtype Not_Associative is N_Subexpr
+   with Static_Predicate =>
+ Not_Associative in
+   N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor;
   begin
+ if not No_Parens
+  and then
+(Paren_Count (Expr) > 0
+  or else
+ (Nkind (Expr) in Not_Associative
+   and then
+  Nkind (Parent (Expr)) in Not_Associative
+   and then
+  Nkind (Parent (Expr)) /= Nkind (Expr)))
+ then
+--  Parentheses are needed
+return '(' &
+  Expr_Name (Expr, Take_Prefix, Expand_Type, No_Parens => True) &
+  ')';
+ end if;
+
  Num_Elements := Num_Elements + 1;
 
  if Num_Elements > Max_Expr_Elements then
@@ -589,7 +620,9 @@ package body Pprint is
return "abs " & Expr_Name (Right_Opnd (Expr));
 
 when N_Op_Not =>
-   return "not (" & Expr_Name (Right_Opnd (Expr)) & ")";
+   return "not (" &
+  Expr_Name (Right_Opnd (Expr), No_Parens => True) &
+  ")";
 
 when N_Type_Conversion =>
 
@@ -608,7 +641,9 @@ package body Pprint is
Is_Modular_Integer_Type (Etype (Expression (Expr)))
then
   ret

[gcc r15-6536] ada: Fix comments and change subtype name in response to review

2025-01-03 Thread Marc Poulhi?s via Gcc-cvs
https://gcc.gnu.org/g:c3c701a5e905aa638605f5bedc6b37dbc5bc2ecf

commit r15-6536-gc3c701a5e905aa638605f5bedc6b37dbc5bc2ecf
Author: Tucker Taft 
Date:   Thu Dec 5 14:47:37 2024 +

ada: Fix comments and change subtype name in response to review

gcc/ada/ChangeLog:

* pprint.adb (Expression_Image): Adjust and improve comments
to match style recommendations, and change name of subtype
from Not_Associative to Non_Associative, in response to
code review.

Diff:
---
 gcc/ada/pprint.adb | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb
index 5958a6b47b29..8061d3daa86c 100644
--- a/gcc/ada/pprint.adb
+++ b/gcc/ada/pprint.adb
@@ -64,9 +64,9 @@ package body Pprint is
   --  otherwise only consider the right-hand side of an expression. If
   --  Expand_Type is True and Expr is a type, try to expand Expr (an
   --  internally generated type) into a user understandable name.
-  --  If No_Parens is True, then suppress creating parentheses
-  --  around expression.  If False, check to see whether expression
-  --  should be parenthesized.
+  --  If No_Parens is True, then suppress creating parentheses around
+  --  expression. If False, check to see whether expression should be
+  --  parenthesized.
 
   function Count_Parentheses (S : String; C : Character) return Natural
 with Pre => C in '(' | ')';
@@ -153,8 +153,8 @@ package body Pprint is
 --  Print expression itself as "12345"
 
 else
+   --  Suppress parens if is the only parameter
Append (Buf, Expr_Name (Elmt, No_Parens => List_Len = 1));
-  --  Suppress parens if is the only parameter.
 end if;
 
 Next (Elmt);
@@ -189,24 +189,31 @@ package body Pprint is
  Expand_Type : Boolean := True;
  No_Parens   : Boolean := False) return String
   is
- --  Define subtype matching logical operations
+ --  Define a subtype matching logical operations
  --  and [then], or [else], and xor.
- subtype Not_Associative is N_Subexpr
+ --  In Ada, these operations are non associative -- they
+ --  all have the same precedence, so parentheses
+ --  are needed to indicate the association of
+ --  operands in a sequence of distinct operations.
+ subtype Non_Associative is N_Subexpr
with Static_Predicate =>
- Not_Associative in
+ Non_Associative in
N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor;
   begin
  if not No_Parens
   and then
 (Paren_Count (Expr) > 0
   or else
- (Nkind (Expr) in Not_Associative
+ (Nkind (Expr) in Non_Associative
and then
-  Nkind (Parent (Expr)) in Not_Associative
+  Nkind (Parent (Expr)) in Non_Associative
and then
   Nkind (Parent (Expr)) /= Nkind (Expr)))
  then
---  Parentheses are needed
+--  Parentheses are needed, either because
+--  Paren_Count is greater than zero, or because
+--  this operation and its parent are non associative,
+--  and are not the same operation.
 return '(' &
   Expr_Name (Expr, Take_Prefix, Expand_Type, No_Parens => True) &
   ')';


[gcc r15-6513] OpenMP: update documentation for dispatch and adjust_args

2025-01-03 Thread Paul-Antoine Arras via Gcc-cvs
https://gcc.gnu.org/g:d22b0e3033d991104ad48c3618981fedea1a8841

commit r15-6513-gd22b0e3033d991104ad48c3618981fedea1a8841
Author: Paul-Antoine Arras 
Date:   Mon May 27 11:48:34 2024 +0200

OpenMP: update documentation for dispatch and adjust_args

libgomp/ChangeLog:

* libgomp.texi:

Diff:
---
 libgomp/libgomp.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index c8fb08ec269a..9a42355ff5d4 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -294,8 +294,8 @@ The OpenMP 4.5 specification is fully supported.
 @item C/C++'s @code{declare variant} directive: elision support of
   preprocessed code @tab N @tab
 @item @code{declare variant}: new clauses @code{adjust_args} and
-  @code{append_args} @tab N @tab
-@item @code{dispatch} construct @tab N @tab
+  @code{append_args} @tab P @tab Only @code{adjust_args}
+@item @code{dispatch} construct @tab Y @tab
 @item device-specific ICV settings with environment variables @tab Y @tab
 @item @code{assume} and @code{assumes} directives @tab Y @tab
 @item @code{nothing} directive @tab Y @tab