[gcc r14-11282] libgcc: On FreeBSD use GCC's crt objects for static linking

2025-02-09 Thread Gerald Pfeifer via Gcc-cvs
https://gcc.gnu.org/g:796849274c155d6f3430d94500cfa3c11fb59a1d

commit r14-11282-g796849274c155d6f3430d94500cfa3c11fb59a1d
Author: Dimitry Andric 
Date:   Tue Jan 28 18:36:16 2025 +0100

libgcc: On FreeBSD use GCC's crt objects for static linking

Add crtbeginT.o to extra_parts on FreeBSD. This ensures we use GCC's
crt objects for static linking. Otherwise it could mix crtbeginT.o
from the base system with libgcc's crtend.o, possibly leading to
segfaults.

libgcc:
PR target/118685
* config.host (*-*-freebsd*): Add crtbeginT.o to extra_parts.

Signed-off-by: Dimitry Andric 

Diff:
---
 libgcc/config.host | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/config.host b/libgcc/config.host
index 733290370442..8ad2f4047867 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -289,7 +289,7 @@ case ${host} in
   # machine-specific sections may refine and add to this
   # configuration.
   tmake_file="$tmake_file t-freebsd t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip 
t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
-  extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o"
+  extra_parts="crtbegin.o crtend.o crtbeginS.o crtbeginT.o crtendS.o"
   case ${target_thread_file} in
 posix)
   tmake_file="${tmake_file} t-freebsd-thread"


[gcc r15-7449] Test procedure dummy arguments against global symbols, if available.

2025-02-09 Thread Thomas Kテカnig via Gcc-cvs
https://gcc.gnu.org/g:a8d0a2dd6565ea15ce79d8af90f2671cbf9359c7

commit r15-7449-ga8d0a2dd6565ea15ce79d8af90f2671cbf9359c7
Author: Thomas Koenig 
Date:   Sat Feb 8 15:18:21 2025 +0100

Test procedure dummy arguments against global symbols, if available.

this fixes a rather old PR from 2005, where a subroutine
could be passed and called as a function.  This patch checks
for that, also for the reverse, and for wrong types of functions.

I expect that this will find a few bugs in dusty deck code...

gcc/fortran/ChangeLog:

PR fortran/24878
* interface.cc (compare_parameter): Check global subroutines
passed as actual arguments for subroutine / function and
function type.

gcc/testsuite/ChangeLog:

PR fortran/24878
* gfortran.dg/interface_51.f90: New test.

Diff:
---
 gcc/fortran/interface.cc   | 47 ++-
 gcc/testsuite/gfortran.dg/interface_51.f90 | 51 ++
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 145f710563a5..49677f15f13c 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -2423,6 +2423,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
   gfc_component *ppc;
   bool codimension = false;
   gfc_array_spec *formal_as;
+  const char *actual_name;
 
   /* If the formal arg has type BT_VOID, it's to one of the iso_c_binding
  procs c_f_pointer or c_f_procpointer, and we need to accept most
@@ -2487,6 +2488,51 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
  return false;
}
 
+  /* The actual symbol may disagree with a global symbol.  If so, issue an
+error, but only if no previous error has been reported on the formal
+argument.  */
+  actual_name = act_sym->name;
+  if (!formal->error && actual_name)
+   {
+ gfc_gsymbol *gsym;
+ gsym = gfc_find_gsymbol (gfc_gsym_root, actual_name);
+ if (gsym != NULL)
+   {
+ if (gsym->type == GSYM_SUBROUTINE && formal->attr.function)
+   {
+ gfc_error ("Passing global subroutine %qs declared at %L "
+"as function at %L", actual_name, &gsym->where,
+&actual->where);
+ return false;
+   }
+ if (gsym->type == GSYM_FUNCTION && formal->attr.subroutine)
+   {
+ gfc_error ("Passing global function %qs declared at %L "
+"as subroutine at %L", actual_name, &gsym->where,
+&actual->where);
+ return false;
+   }
+ if (gsym->type == GSYM_FUNCTION)
+   {
+ gfc_symbol *global_asym;
+ gfc_find_symbol (actual_name, gsym->ns, 0, &global_asym);
+ if (global_asym != NULL)
+   {
+ gcc_assert (formal->attr.function);
+ if (!gfc_compare_types (&global_asym->ts, &formal->ts))
+   {
+ gfc_error ("Type mismatch passing global function %qs 
"
+"declared at %L at %L (%s/%s)",
+actual_name, &gsym->where, &actual->where,
+gfc_typename (&global_asym->ts),
+gfc_dummy_typename (&formal->ts));
+ return false;
+   }
+   }
+   }
+   }
+   }
+
   if (formal->attr.function && !act_sym->attr.function)
{
  gfc_add_function (&act_sym->attr, act_sym->name,
@@ -2501,7 +2547,6 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
 
   return true;
 }
-
   ppc = gfc_get_proc_ptr_comp (actual);
   if (ppc && ppc->ts.interface)
 {
diff --git a/gcc/testsuite/gfortran.dg/interface_51.f90 
b/gcc/testsuite/gfortran.dg/interface_51.f90
new file mode 100644
index ..c8371e81ec90
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/interface_51.f90
@@ -0,0 +1,51 @@
+! { dg-do compile }
+
+! PR 24878 - passing a global subroutine as a function, or vice versa,
+! was not caught, nor were type mismatches.  Original test case by
+! Uttam Pawar.
+
+program memain
+  implicit none
+  integer subr
+  external subr
+  external i4
+  external r4
+  integer r4
+  
+  call foo(subr) ! { dg-error "Passing global subroutine" }
+  call bar(i4)   ! { dg-error "Passing global function" }
+  call baz(r4)   ! { dg-error "Type mismatch passing global function" }
+end program memain
+
+subroutine foo(ifun)
+  integer(kind=4) ifun
+  external ifun
+  integer y
+!---FNC is not a Function subprogram so calling it
+!   as a function is an error.
+  Y=ifun(32)
+end subroutine foo
+
+subro

[gcc r15-7450] [PR middle-end/117263] Avoid unused-but-set warning in genautomata

2025-02-09 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:b81bb3ed216213fdaba82addae9fc34619ad6ec7

commit r15-7450-gb81bb3ed216213fdaba82addae9fc34619ad6ec7
Author: Dario Gjorgjevski 
Date:   Sun Feb 9 09:16:31 2025 -0700

[PR middle-end/117263] Avoid unused-but-set warning in genautomata

This is a trivial bug where a user wanted to define NDEBUG when building
genautomata, presumably trying to debug its behavior.  This resulted in a
unused-but-set warning which caused the build to fail.

Dario included the trivial fixes in the PR which I put through the usual
bootstrap & regression test as well as compiling genautomata with NDEBUG.

Pushing to the trunk.

PR middle-end/117263
gcc/
* genautomata.cc (output_statistics): Avoid set but unnused warnings
when compiling with NDEBUG.

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

diff --git a/gcc/genautomata.cc b/gcc/genautomata.cc
index 69f856d141cd..4059a229f961 100644
--- a/gcc/genautomata.cc
+++ b/gcc/genautomata.cc
@@ -9088,8 +9088,8 @@ static void
 output_statistics (FILE *f)
 {
   automaton_t automaton;
-  int states_num;
 #ifndef NDEBUG
+  int states_num;
   int transition_comb_vect_els = 0;
   int transition_full_vect_els = 0;
   int min_issue_delay_vect_els = 0;
@@ -9106,13 +9106,17 @@ output_statistics (FILE *f)
   automaton->NDFA_states_num, automaton->NDFA_arcs_num);
   fprintf (f, "%5d DFA states,   %5d DFA arcs\n",
   automaton->DFA_states_num, automaton->DFA_arcs_num);
+#ifndef NDEBUG
   states_num = automaton->DFA_states_num;
+#endif
   if (!no_minimization_flag)
{
  fprintf (f, "%5d minimal DFA states,   %5d minimal DFA arcs\n",
   automaton->minimal_DFA_states_num,
   automaton->minimal_DFA_arcs_num);
+#ifndef NDEBUG
  states_num = automaton->minimal_DFA_states_num;
+#endif
}
   fprintf (f, "%5d all insns  %5d insn equivalence classes\n",
   description->insns_num, automaton->insn_equiv_classes_num);


[gcc r15-7451] [PR target/115123] Fix testsuite fallout from sinking heuristic change

2025-02-09 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:22e30d60b971eed9a4754ea920d05b1b7e89090a

commit r15-7451-g22e30d60b971eed9a4754ea920d05b1b7e89090a
Author: Jeff Law 
Date:   Sun Feb 9 09:55:56 2025 -0700

[PR target/115123] Fix testsuite fallout from sinking heuristic change

Code sinking is just semantic preserving code motions, so it's a lot like
scheduling in that code motions can change the vector configuration needed 
at
various program points.  That in turn can also change the number of vsetvls 
as
we may or may not be able to merge them after the code motions.

The sinking heuristics were twiddled several months ago resulting in a 
handful
of scan-asm failures.  This patch adjusts the tests appropriately fixing
pr115123 (P3 regression).

PR target/115123
gcc/testsuite
* gcc.target/riscv/rvv/base/pr114352-3.c: Adjust expected output.
* gcc.target/riscv/rvv/vsetvl/avl_multiple-7.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_multiple-8.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-66.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-82.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-83.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-86.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-88.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-90.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-91.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-92.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/base/pr114352-3.c   | 2 ++
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-7.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-8.c | 2 +-
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-66.c  | 1 -
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-82.c  | 4 ++--
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-83.c  | 4 ++--
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-86.c  | 1 -
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-88.c  | 1 -
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-90.c  | 1 -
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-91.c  | 4 ++--
 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_single-92.c  | 2 +-
 11 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr114352-3.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114352-3.c
index a764afbbbc19..9bfa39c52680 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/base/pr114352-3.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr114352-3.c
@@ -4,6 +4,7 @@
 
 /*
 ** test_1:
+** ...
 ** sext\.w\s+[atx][0-9]+,\s*[atx][0-9]+
 ** ...
 */
@@ -56,6 +57,7 @@ test_3 (int *a, int *b, int *out, unsigned count)
 
 /*
 ** test_4:
+** ...
 ** sext\.w\s+[atx][0-9]+,\s*[atx][0-9]+
 ** ...
 */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-7.c 
b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-7.c
index 21bc0729cf68..cdb1a4ee921f 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-7.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-7.c
@@ -37,4 +37,4 @@ void f (void * restrict in, void * restrict out, int l, int 
n, int m, int cond)
   }
 }
 
-/* { dg-final { scan-assembler 
{add\s+\s*[a-x0-9]+,\s*[a-x0-9]+,\s*[a-x0-9]+\s+ble\s+[a-x0-9]+,\s*zero,\.L[0-9]+\s+vsetvli\s+zero,\s*[a-x0-9]+,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts 
"-g" no-opts "-funroll-loops" } } } } */
+/* { dg-final { scan-assembler 
{add\s+\s*[a-x0-9]+,\s*[a-x0-9]+,\s*[a-x0-9]+\s+ble\s+[a-x0-9]+,\s*zero,\.L[0-9]+\s+.L[0-9]+:\s+vsetvli\s+zero,\s*[a-x0-9]+,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts 
"-g" no-opts "-funroll-loops" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-8.c 
b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-8.c
index 5539486b5060..c7c9e1f91ffe 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-8.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/avl_multiple-8.c
@@ -36,4 +36,4 @@ void f (void * restrict in, void * restrict out, int l, int 
n, int m, int cond)
   }
 }
 
-/* { dg-final { scan-assembler 
{add\s+\s*[a-x0-9]+,\s*[a-x0-9]+,\s*[a-x0-9]+\s+ble\s+[a-x0-9]+,\s*zero,\.L[0-9]+\s+vsetvli\s+zero,\s*[a-x0-9]+,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts 
"-g" no-opts "-funroll-loops" } } } } */
+/* { dg-final { scan-assembler 
{add\s+\s*[a-x0-9]+,\s*[a-x0-9]+,\s*[a-x0-9]+\s+ble\s+[a-x0-9]+,\s*zero,\.L[0-9]+\s+.L[0-9]+:\s+vsetvli\s+zero,\s*[a-x0-9]+,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts 
"-g" no-opts "-funroll-loops" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetv