[gcc/devel/omp/gcc-14] nvptx: Delay 'sorry, unimplemented: dynamic stack allocation not supported' from expansion time to c

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:709c2303bce51117f6135e8f1c799cab9c7408bb

commit 709c2303bce51117f6135e8f1c799cab9c7408bb
Author: Thomas Schwinge 
Date:   Mon Feb 24 10:09:11 2025 +0100

nvptx: Delay 'sorry, unimplemented: dynamic stack allocation not supported' 
from expansion time to code generation

This gives the back end a chance to clean out a few more unnecessary 
instances
of dynamic stack allocation.  This progresses:

PASS: gcc.dg/pr78902.c  (test for warnings, line 7)
PASS: gcc.dg/pr78902.c  (test for warnings, line 8)
PASS: gcc.dg/pr78902.c  (test for warnings, line 9)
PASS: gcc.dg/pr78902.c  (test for warnings, line 10)
PASS: gcc.dg/pr78902.c  (test for warnings, line 11)
PASS: gcc.dg/pr78902.c  (test for warnings, line 12)
PASS: gcc.dg/pr78902.c  (test for warnings, line 13)
PASS: gcc.dg/pr78902.c strndup excessive bound at line 14 (test for 
warnings, line 13)
[-UNSUPPORTED: gcc.dg/pr78902.c: dynamic stack allocation not 
supported-]
{+PASS: gcc.dg/pr78902.c (test for excess errors)+}

UNSUPPORTED: gcc.dg/torture/pr71901.c   -O0 : dynamic stack allocation 
not supported
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr71901.c   -O1  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}
UNSUPPORTED: gcc.dg/torture/pr71901.c   -O2 : dynamic stack allocation 
not supported
UNSUPPORTED: gcc.dg/torture/pr71901.c   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions : dynamic stack 
allocation not supported
UNSUPPORTED: gcc.dg/torture/pr71901.c   -O3 -g : dynamic stack 
allocation not supported
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr71901.c   -Os  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}

UNSUPPORTED: gcc.dg/torture/pr78742.c   -O0 : dynamic stack allocation 
not supported
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O1  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O2  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O3 
-fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  
[-: dynamic stack allocation not supported-]{+(test for excess errors)+}
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O3 -g  [-: 
dynamic stack allocation not supported-]{+(test for excess errors)+}
UNSUPPORTED: gcc.dg/torture/pr78742.c   -Os : dynamic stack allocation 
not supported

[-UNSUPPORTED:-]{+PASS:+} gfortran.dg/pr101267.f90   -O  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}

[-UNSUPPORTED:-]{+PASS:+} gfortran.dg/pr112404.f90   -O  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}

gcc/
* config/nvptx/nvptx.md (define_expand "allocate_stack")
[!TARGET_SOFT_STACK]: Move
'sorry ("dynamic stack allocation not supported");'...
(define_insn "@nvptx_alloca_"): ... here.
gcc/testsuite/
* gcc.target/nvptx/alloca-1-unused-O0-sm_30.c: Adjust.

(cherry picked from commit 22e76700aea63eb8c298403bb2e717a6a4fc9c1e)

Diff:
---
 gcc/ChangeLog.omp  | 10 ++
 gcc/config/nvptx/nvptx.md  | 42 +++---
 gcc/testsuite/ChangeLog.omp|  5 +++
 .../gcc.target/nvptx/alloca-1-unused-O0-sm_30.c| 12 +--
 4 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index f46a06d4e1ed..e578ad89f743 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,13 @@
+2025-02-28  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-02-27  Thomas Schwinge  
+
+   * config/nvptx/nvptx.md (define_expand "allocate_stack")
+   [!TARGET_SOFT_STACK]: Move
+   'sorry ("dynamic stack allocation not supported");'...
+   (define_insn "@nvptx_alloca_"): ... here.
+
 2025-02-27  Thomas Schwinge  
 
Backported from trunk:
diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index c231c7ea0067..097b1751402a 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -1692,15 +1692,8 @@
(match_operand 1 "nvptx_register_operand")]
   ""
 {
-  if (!TARGET_SOFT_STACK
-  && TARGET_PTX_7_3
-  && TARGET_SM52)
+  if (!TARGET_SOFT_STACK)
 emit_insn (gen_nvptx_alloca (Pmode, operands[0], operands[1]));
-  else if (!TARGET_SOFT_STACK)
-{
-  sorry ("dynamic stack allocation not supported");
-  emit_insn (gen_nop ());
-}
   else if (TARGET_SOFT_STACK)
 {
   emit_move_insn (stack_pointer_rtx,
@@ -1717,19 +1710,28 @@
   [(set (match_operand:P 0 "nvptx_register_operand" "=R")
 (unspec

[gcc/devel/omp/gcc-14] nvptx: Support '-mfake-ptx-alloca'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5c438e57d7ebef246b1c61be06983d507bf23a40

commit 5c438e57d7ebef246b1c61be06983d507bf23a40
Author: Thomas Schwinge 
Date:   Mon Feb 24 16:13:11 2025 +0100

nvptx: Support '-mfake-ptx-alloca'

With '-mfake-ptx-alloca' enabled, the user-visible behavior changes only
for configurations where PTX 'alloca' is not available.  Rather than a
compile-time 'sorry, unimplemented: dynamic stack allocation not supported'
in presence of dynamic stack allocation, compilation and assembly then
succeeds.  However, attempting to link in such '*.o' files then fails due
to unresolved symbol '__GCC_nvptx__PTX_alloca_not_supported'.

This is meant to be used in scenarios where large volumes of code are
compiled, a small fraction of which runs into dynamic stack allocation, but
these parts are not important for specific use cases, and we'd thus like the
build to succeed, and error out just upon actual, very rare use of the
offending '*.o' files.

gcc/
* config/nvptx/nvptx.opt (-mfake-ptx-alloca): New.
* config/nvptx/nvptx-protos.h (nvptx_output_fake_ptx_alloca):
Declare.
* config/nvptx/nvptx.cc (nvptx_output_fake_ptx_alloca): New.
* config/nvptx/nvptx.md (define_insn "@nvptx_alloca_")
[!(TARGET_PTX_7_3 && TARGET_SM52)]: Use it for
'-mfake-ptx-alloca'.
gcc/testsuite/
* gcc.target/nvptx/alloca-1-O0_-mfake-ptx-alloca.c: New.
* gcc.target/nvptx/alloca-2-O0_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/alloca-4-O3_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/vla-1-O0_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/alloca-4-O3.c:
'dg-additional-options -mfake-ptx-alloca'.

(cherry picked from commit 1146410c0feb0e82c689b1333fdf530a2b34dc2b)

Diff:
---
 gcc/ChangeLog.omp  | 11 +
 gcc/config/nvptx/nvptx-protos.h|  1 +
 gcc/config/nvptx/nvptx.cc  | 21 ++
 gcc/config/nvptx/nvptx.md  |  4 ++
 gcc/config/nvptx/nvptx.opt | 15 +++
 gcc/testsuite/ChangeLog.omp| 10 +
 .../nvptx/alloca-1-O0_-mfake-ptx-alloca.c  | 49 ++
 .../nvptx/alloca-2-O0_-mfake-ptx-alloca.c  | 18 
 gcc/testsuite/gcc.target/nvptx/alloca-4-O3.c   |  2 +
 .../nvptx/alloca-4-O3_-mfake-ptx-alloca.c  | 48 +
 .../gcc.target/nvptx/vla-1-O0_-mfake-ptx-alloca.c  | 29 +
 11 files changed, 208 insertions(+)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index e578ad89f743..b7743c80926f 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -3,6 +3,17 @@
Backported from trunk:
2025-02-27  Thomas Schwinge  
 
+   * config/nvptx/nvptx.opt (-mfake-ptx-alloca): New.
+   * config/nvptx/nvptx-protos.h (nvptx_output_fake_ptx_alloca):
+   Declare.
+   * config/nvptx/nvptx.cc (nvptx_output_fake_ptx_alloca): New.
+   * config/nvptx/nvptx.md (define_insn "@nvptx_alloca_")
+   [!(TARGET_PTX_7_3 && TARGET_SM52)]: Use it for
+   '-mfake-ptx-alloca'.
+
+   Backported from trunk:
+   2025-02-27  Thomas Schwinge  
+
* config/nvptx/nvptx.md (define_expand "allocate_stack")
[!TARGET_SOFT_STACK]: Move
'sorry ("dynamic stack allocation not supported");'...
diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h
index ed2ec0e3282a..540497507275 100644
--- a/gcc/config/nvptx/nvptx-protos.h
+++ b/gcc/config/nvptx/nvptx-protos.h
@@ -56,6 +56,7 @@ extern rtx nvptx_expand_compare (rtx);
 extern const char *nvptx_ptx_type_from_mode (machine_mode, bool);
 extern const char *nvptx_output_mov_insn (rtx, rtx);
 extern const char *nvptx_output_call_insn (rtx_insn *, rtx, rtx);
+extern const char *nvptx_output_fake_ptx_alloca (void);
 extern const char *nvptx_output_return (void);
 extern const char *nvptx_output_set_softstack (unsigned);
 extern const char *nvptx_output_simt_enter (rtx, rtx, rtx);
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 14766b8d769f..6dd358bf3d58 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -1813,6 +1813,27 @@ nvptx_output_set_softstack (unsigned src_regno)
 }
   return "";
 }
+
+/* Output a fake PTX 'alloca'.  */
+
+const char *
+nvptx_output_fake_ptx_alloca (void)
+{
+#define FAKE_PTX_ALLOCA_NAME "__GCC_nvptx__PTX_alloca_not_supported"
+  static tree decl;
+  if (!decl)
+{
+  tree alloca_type = TREE_TYPE (builtin_decl_explicit (BUILT_IN_ALLOCA));
+  decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
+get_identifier (FAKE_PTX_ALLOCA_NAME), alloca_type);
+  DECL_EXTERNAL (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  nvptx_record_needed_fndecl (decl);
+}
+  ret

[gcc/devel/omp/gcc-14] nvptx: '#define MAX_FIXED_MODE_SIZE 128'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:6bd78a5908c9f9e2a3801c09363f7cac6dfc190e

commit 6bd78a5908c9f9e2a3801c09363f7cac6dfc190e
Author: Thomas Schwinge 
Date:   Wed Feb 26 15:39:37 2025 +0100

nvptx: '#define MAX_FIXED_MODE_SIZE 128'

... instead of 64 via 'gcc/defaults.h':

MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)

This fixes ICEs:

[-FAIL: c-c++-common/pr111309-1.c  -Wc++-compat  (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -Wc++-compat  (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -Wc++-compat  
[-compilation failed to produce executable-]{+execution test+}

[-FAIL: c-c++-common/pr111309-1.c  -std=gnu++17 (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++17 (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++17 
[-compilation failed to produce executable-]{+execution test+}
[-FAIL: c-c++-common/pr111309-1.c  -std=gnu++26 (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++26 (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++26 
[-compilation failed to produce executable-]{+execution test+}
[-FAIL: c-c++-common/pr111309-1.c  -std=gnu++98 (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++98 (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++98 
[-compilation failed to produce executable-]{+execution test+}

[-FAIL: gcc.dg/torture/pr116480-1.c   -O0  (internal compiler error: in 
expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} gcc.dg/torture/pr116480-1.c   -O0  (test for excess 
errors)
[-FAIL: gcc.dg/torture/pr116480-1.c   -O1  (internal compiler error: in 
expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} gcc.dg/torture/pr116480-1.c   -O1  (test for excess 
errors)
PASS: gcc.dg/torture/pr116480-1.c   -O2  (test for excess errors)
PASS: gcc.dg/torture/pr116480-1.c   -O3 -g  (test for excess errors)
PASS: gcc.dg/torture/pr116480-1.c   -Os  (test for excess errors)

..., where we ran into 'gcc_assert (icode != CODE_FOR_nothing);' in
'gcc/internal-fn.cc:expand_fn_using_insn' for '__int128' '__builtin_clzg' 
etc.:

during RTL pass: expand
[...]/c-c++-common/pr111309-1.c: In function 'clzI':
[...]/c-c++-common/pr111309-1.c:69:10: internal compiler error: in 
expand_fn_using_insn, at internal-fn.cc:268
0x120ec2cf internal_error(char const*, ...)
[...]/gcc/diagnostic-global-context.cc:517
0x102c7c5b fancy_abort(char const*, int, char const*)
[...]/gcc/diagnostic.cc:1722
0x109708eb expand_fn_using_insn
[...]/gcc/internal-fn.cc:268
0x1098114f expand_internal_call(internal_fn, gcall*)
[...]/gcc/internal-fn.cc:5273
0x1098114f expand_internal_call(gcall*)
[...]/gcc/internal-fn.cc:5281
0x10594fc7 expand_call_stmt
[...]/gcc/cfgexpand.cc:3049
[...]

Likewise, as of commit e8ad697a75b0870a833366daf687668a57cabb6e
"libstdc++: Use new type-generic built-ins in  [PR118855]",
the libstdc++ target library build ICEd in the same way.

Additionally, this change fixes:

[-FAIL:-]{+PASS:+} gcc.dg/pr105094.c (test for excess errors)

..., which was:

[...]/gcc.dg/pr105094.c: In function 'foo':
[...]/gcc.dg/pr105094.c:11:12: error: size of variable 's' is too large

And, finally, regarding 'gcc.target/nvptx/stack_frame-1.c'.  Before, in
'gcc/cfgexpand.cc': 'expand_used_vars' -> 'expand_used_vars_for_block' ->
'expand_one_var' for 'ww' -> 'gcc/function.cc:use_register_for_decl' due to
'DECL_MODE (decl) == BLKmode' did 'return false;', thus -> 'add_stack_var'
(even if 'ww' wasn't then actually living on the stack).  Now, 'ww' has
'TImode' and 'use_register_for_decl' does 'return true;', thus ->
'expand_one_register_var', and therefore no unused stack frame emitted.

gcc/
* config/nvptx/nvptx.h (MAX_FIXED_MODE_SIZE): '#define'.
gcc/testsuite/
* gcc.target/nvptx/stack_frame-1.c: Adjust.

(cherry picked from commit e333ad4ed82cdfb1b660e9666895641ef3ffaddb)

Diff:
---
 gcc/ChangeLog.omp  | 5 +
 gcc/config/nvptx/nvptx.h   | 2 ++
 gcc/testsuite/ChangeLog.omp| 5 +
 gcc/testsuite/gcc.target/nvptx/stack_frame-1.c | 7 ++-
 4 files changed, 14 insert

[gcc/devel/omp/gcc-14] Add 'gcc.target/nvptx/stack_frame-1.c'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:82985d2d2e6ad2512e84054148439ea2337bb870

commit 82985d2d2e6ad2512e84054148439ea2337bb870
Author: Thomas Schwinge 
Date:   Wed Feb 26 17:17:44 2025 +0100

Add 'gcc.target/nvptx/stack_frame-1.c'

gcc/testsuite/
* gcc.target/nvptx/stack_frame-1.c: New.

(cherry picked from commit 39e1ec22dbaad6cf8e3dc16fd4a576d03215201e)

Diff:
---
 gcc/testsuite/ChangeLog.omp|  5 
 gcc/testsuite/gcc.target/nvptx/stack_frame-1.c | 34 ++
 2 files changed, 39 insertions(+)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 514874cf01be..8f994a73a901 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -3,6 +3,11 @@
Backported from trunk:
2025-02-27  Thomas Schwinge  
 
+   * gcc.target/nvptx/stack_frame-1.c: New.
+
+   Backported from trunk:
+   2025-02-27  Thomas Schwinge  
+
* gcc.target/nvptx/alloca-1-O0_-mfake-ptx-alloca.c: New.
* gcc.target/nvptx/alloca-2-O0_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/alloca-4-O3_-mfake-ptx-alloca.c: Likewise.
diff --git a/gcc/testsuite/gcc.target/nvptx/stack_frame-1.c 
b/gcc/testsuite/gcc.target/nvptx/stack_frame-1.c
new file mode 100644
index ..476d0ac93ed0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/stack_frame-1.c
@@ -0,0 +1,34 @@
+/* GCC emits an unused stack frame.  */
+
+/* { dg-do assemble } */
+/* { dg-options {-O2 -mno-soft-stack} } */
+/* { dg-additional-options -save-temps } */
+/* { dg-final { check-function-bodies {** } {} } } */
+
+/* Greatly reduced from libgcc code, where this issue is visible for
+   '_divdi3.o:__divti3', '_divmoddi4.o:__divmodti4', '_moddi3.o:__modti3',
+   '_udivdi3.o:__udivti3', '_udivmoddi4.o:__udivmodti4',
+   '_umoddi3.o:__umodti3'.  */
+
+int f (int n)
+{
+  const union {
+struct { long low, high; };
+__int128 ll;
+  } ww = {{.low = n, .high = 0}};
+  return (int) ww.ll;
+}
+/*
+** f:
+** \.visible \.func \(\.param\.u32 %value_out\) f \(\.param\.u32 %in_ar0\)
+** {
+** \.reg\.u32 %value;
+** \.reg\.u32 %ar0;
+** ld\.param\.u32 %ar0, \[%in_ar0\];
+** \.local \.align 16 \.b8 %frame_ar\[16\];
+** \.reg\.u64 %frame;
+** cvta\.local\.u64 %frame, %frame_ar;
+** mov\.u32%value, %ar0;
+** st\.param\.u32  \[%value_out\], %value;
+** ret;
+*/


[gcc r15-7732] GCC: Documentation of -x option

2025-02-27 Thread Jerry DeLisle via Gcc-cvs
https://gcc.gnu.org/g:cfc9f42122f41668b986126ba7e65e3dd8bf1e9e

commit r15-7732-gcfc9f42122f41668b986126ba7e65e3dd8bf1e9e
Author: Jerry DeLisle 
Date:   Wed Feb 26 17:26:26 2025 -0800

GCC: Documentation of -x option

This change updates information about the -x option to clarify
that it does not ensure standards compliance. Sparked by
discussions in the following PR.

PR fortran/108369

gcc/ChangeLog:

* doc/invoke.texi: Add a note to clarify. Adjust some wording.

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

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index bad49a017cc1..6f8bf3923863 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1700,9 +1700,13 @@ f77  f77-cpp-input f95  f95-cpp-input
 go
 @end smallexample
 
+Note that @option{-x} does not imply a particular language standard.
+For example @option{-x f77} may also require @option{-std=legacy} for some 
older
+source codes.
+
 @item -x none
 Turn off any specification of a language, so that subsequent files are
-handled according to their file name suffixes (as they are if @option{-x}
+handled according to their file name suffixes (as if @option{-x}
 has not been used at all).
 @end table


[gcc r14-11347] c++: init-list opt and lvalue initializers [PR118673]

2025-02-27 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:b4f66a79e0c9b65d78aed6c982bdcff48ed098d5

commit r14-11347-gb4f66a79e0c9b65d78aed6c982bdcff48ed098d5
Author: Jason Merrill 
Date:   Mon Jan 27 18:30:18 2025 -0500

c++: init-list opt and lvalue initializers [PR118673]

When fn returns {extension}, the ArrayRef in the initializer_list is
constructed to point to 'extension', the variable with static storage
duration.  The optimization was copying extension's value into a temporary
array and constructing the ArrayRef to point to that temporary copy instead,
resulting in a dangling pointer.  So suppress this optimization if the
element constructor takes a reference and the initializer is a non-mergeable
lvalue.

PR c++/118673

gcc/cp/ChangeLog:

* call.cc (maybe_init_list_as_array): Check for lvalue
initializers.
* cp-tree.h (enum cp_lvalue_kind_flags): Add clk_mergeable.
* tree.cc (lvalue_kind): Return it.
(non_mergeable_glvalue_p): New.
(test_lvalue_kind): Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-opt6.C: New test.

Diff:
---
 gcc/cp/cp-tree.h   |  4 +++-
 gcc/cp/call.cc |  9 +
 gcc/cp/tree.cc | 21 +++--
 gcc/testsuite/g++.dg/cpp0x/initlist-opt6.C | 26 ++
 4 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index a9a4a7abc40d..a9a14d6267c8 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5582,7 +5582,8 @@ enum cp_lvalue_kind_flags {
   clk_class = 4,/* A prvalue of class or array type.  */
   clk_bitfield = 8, /* An lvalue for a bit-field.  */
   clk_packed = 16,  /* An lvalue for a packed field.  */
-  clk_implicit_rval = 1<<5 /* An lvalue being treated as an xvalue.  */
+  clk_implicit_rval = 1<<5, /* An lvalue being treated as an xvalue.  */
+  clk_mergeable = 1<<6
 };
 
 /* This type is used for parameters and variables which hold
@@ -8035,6 +8036,7 @@ extern bool glvalue_p 
(const_tree);
 extern bool obvalue_p  (const_tree);
 extern bool xvalue_p   (const_tree);
 extern bool bitfield_p (const_tree);
+extern bool non_mergeable_glvalue_p(const_tree);
 extern tree cp_stabilize_reference (tree);
 extern bool builtin_valid_in_constant_expr_p(const_tree);
 extern tree build_min  (enum tree_code, tree, ...);
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 1609a64c3fa6..bb376d9cb136 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4331,6 +4331,15 @@ maybe_init_list_as_array (tree elttype, tree init)
 /* Let the normal code give the error.  */
 return NULL_TREE;
 
+  /* A glvalue initializer might be significant to a reference constructor
+ or conversion operator.  */
+  if (!DECL_CONSTRUCTOR_P (c->cand->fn)
+  || (TYPE_REF_P (TREE_VALUE
+ (FUNCTION_FIRST_USER_PARMTYPE (c->cand->fn)
+for (auto &ce : CONSTRUCTOR_ELTS (init))
+  if (non_mergeable_glvalue_p (ce.value))
+   return NULL_TREE;
+
   tree first = CONSTRUCTOR_ELT (init, 0)->value;
   conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 01e6c1cb892c..b37d4605e06c 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -191,6 +191,8 @@ lvalue_kind (const_tree ref)
   return op1_lvalue_kind;
 
 case STRING_CST:
+  return clk_ordinary | clk_mergeable;
+
 case COMPOUND_LITERAL_EXPR:
   return clk_ordinary;
 
@@ -210,6 +212,10 @@ lvalue_kind (const_tree ref)
  && DECL_LANG_SPECIFIC (ref)
  && DECL_IN_AGGR_P (ref))
return clk_none;
+
+  if (DECL_MERGEABLE (ref))
+   return clk_ordinary | clk_mergeable;
+
   /* FALLTHRU */
 case INDIRECT_REF:
 case ARROW_EXPR:
@@ -407,6 +413,17 @@ bitfield_p (const_tree ref)
   return (lvalue_kind (ref) & clk_bitfield);
 }
 
+/* True if REF is a glvalue with a unique address, excluding mergeable glvalues
+   such as string constants.  */
+
+bool
+non_mergeable_glvalue_p (const_tree ref)
+{
+  auto kind = lvalue_kind (ref);
+  return (kind != clk_none
+ && !(kind & (clk_class|clk_mergeable)));
+}
+
 /* C++-specific version of stabilize_reference.  */
 
 tree
@@ -6353,11 +6370,11 @@ test_lvalue_kind ()
   tree string_lit = build_string (4, "foo");
   TREE_TYPE (string_lit) = char_array_type_node;
   string_lit = fix_string_type (string_lit);
-  ASSERT_EQ (clk_ordinary, lvalue_kind (string_lit));
+  ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
 
   tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
   ASSERT_TRUE (location_wrapper_p (wrapped_

[gcc r14-11349] c++: disable initializer_list transformation

2025-02-27 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:a72e782528749bf553158039783ce79fa760e3a4

commit r14-11349-ga72e782528749bf553158039783ce79fa760e3a4
Author: Jason Merrill 
Date:   Tue Jan 28 17:39:41 2025 -0500

c++: disable initializer_list transformation

PRs 118673 and 118285 are wrong-code bugs with the transformation to build
an initializer_list backing array from a static array of the initializer
expressions; let's disable that transformation on the GCC 14 branch.

PR c++/118673
PR c++/118285

gcc/cp/ChangeLog:

* call.cc (convert_like_internal) [ck_list]: Stop using
maybe_init_list_as_array for GCC 14.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/initlist-opt5.C: Add xfail.

Diff:
---
 gcc/cp/call.cc| 11 +--
 gcc/testsuite/g++.dg/tree-ssa/initlist-opt5.C |  2 +-
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index bb376d9cb136..f580c3f5442f 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -8690,16 +8690,7 @@ convert_like_internal (conversion *convs, tree expr, 
tree fn, int argnum,
unsigned len = CONSTRUCTOR_NELTS (expr);
tree array;
 
-   if (tree init = maybe_init_list_as_array (elttype, expr))
- {
-   elttype = cp_build_qualified_type
- (elttype, cp_type_quals (elttype) | TYPE_QUAL_CONST);
-   array = build_array_of_n_type (elttype, len);
-   array = build_vec_init_expr (array, init, complain);
-   array = get_target_expr (array);
-   array = cp_build_addr_expr (array, complain);
- }
-   else if (len)
+   if (len)
  {
tree val; unsigned ix;
 
diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt5.C 
b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt5.C
index fc928bb54050..fea59b440b64 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt5.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt5.C
@@ -3,7 +3,7 @@
 // { dg-do compile { target c++11 } }
 
 // Check that we call the basic_string constructor once (and define it once).
-// { dg-final { scan-tree-dump-times {>::basic_string} 2 "gimple" } }
+// { dg-final { scan-tree-dump-times {>::basic_string} 2 "gimple" { xfail 
*-*-* } } }
 
 #include 


[gcc r14-11351] testsuite: limit concepts-pr67774.C to C++20

2025-02-27 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:59b09468243d07f6ac7ab38cd0b7fedd00a47385

commit r14-11351-g59b09468243d07f6ac7ab38cd0b7fedd00a47385
Author: Jason Merrill 
Date:   Sun Feb 16 00:17:30 2025 +0100

testsuite: limit concepts-pr67774.C to C++20

This test breaks with -std=c++23 -fconcepts-ts, but works at the default
-std=c++20 -fconcepts-ts.  Since we're removing -fconcepts-ts in GCC 15,
it's not worth trying to fix this conflict.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-pr67774.C: Change target to c++20_only.

Diff:
---
 gcc/testsuite/g++.dg/cpp2a/concepts-pr67774.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67774.C 
b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67774.C
index 5ee5c2dac8f3..d24384364ccd 100644
--- a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67774.C
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67774.C
@@ -1,4 +1,4 @@
-// { dg-do compile { target c++20 } }
+// { dg-do compile { target c++20_only } }
 // { dg-additional-options "-fconcepts-ts" }
 
 #include 


[gcc r14-11348] c++: Update const_decl handling after r15-7259 [PR118673].

2025-02-27 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:19bf2732ae4ad0c37c2493e82cc500724de746a8

commit r14-11348-g19bf2732ae4ad0c37c2493e82cc500724de746a8
Author: Iain Sandoe 
Date:   Thu Jan 30 08:19:21 2025 +

c++: Update const_decl handling after r15-7259 [PR118673].

Objective-C++ uses CONST_DECLs to hold constant string objects
these should also be treated as mergable lvalues.

PR c++/118673

gcc/cp/ChangeLog:

* tree.cc (lvalue_kind): Mark CONST_DECLs as mergable
when they are also TREE_STATIC.

Signed-off-by: Iain Sandoe 

Diff:
---
 gcc/cp/tree.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index b37d4605e06c..abed2ce859c7 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -213,7 +213,7 @@ lvalue_kind (const_tree ref)
  && DECL_IN_AGGR_P (ref))
return clk_none;
 
-  if (DECL_MERGEABLE (ref))
+  if (TREE_CODE (ref) == CONST_DECL || DECL_MERGEABLE (ref))
return clk_ordinary | clk_mergeable;
 
   /* FALLTHRU */


[gcc r14-11346] c++: constexpr VEC_INIT_EXPR [PR118285]

2025-02-27 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:3003d404b436c2dbd5a3a282c25b797d887237d9

commit r14-11346-g3003d404b436c2dbd5a3a282c25b797d887237d9
Author: Jason Merrill 
Date:   Tue Jan 28 13:11:50 2025 -0500

c++: constexpr VEC_INIT_EXPR [PR118285]

cxx_eval_vec_init_1 was doing the wrong thing for an array of
self-referential class type; just evaluating the TARGET_EXPR initializer
creates a new object that refers to the TARGET_EXPR_SLOT, if we want it to
refer properly to the initialization target we need to provide it.

PR c++/118285

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_vec_init_1): Build INIT_EXPR for
initializing a class.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-opt7.C: New test.

Diff:
---
 gcc/cp/constexpr.cc|  9 ++-
 gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C | 41 ++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 83a9175b265d..4b10763950d2 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -5522,7 +5522,11 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree 
atype, tree init,
  if (init == void_node)
/* Trivial default-init, don't do anything to the CONSTRUCTOR.  */
return ctx->ctor;
- eltinit = cxx_eval_constant_expression (&new_ctx, init, lval,
+ eltinit = init;
+ if (CLASS_TYPE_P (elttype) && new_ctx.object)
+   /* Clarify what object is being initialized (118285).  */
+   eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit);
+ eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
  non_constant_p, overflow_p);
  reuse = i == 0;
}
@@ -5535,6 +5539,9 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree 
atype, tree init,
  eltinit = (perform_implicit_conversion_flags
 (elttype, eltinit, complain,
  LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING));
+ if (CLASS_TYPE_P (elttype) && new_ctx.object)
+   /* Clarify what object is being initialized (118285).  */
+   eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit);
  eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
  non_constant_p, overflow_p);
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C
new file mode 100644
index ..f55ef5b77c5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-opt7.C
@@ -0,0 +1,41 @@
+// PR c++/118285
+// { dg-do compile { target c++20 } }
+
+#include 
+
+struct A {
+  char *a;
+  union { char b[8]; long c; };
+  constexpr A (const char *x) : a(b)
+  {
+for (int i = 0; i < 8; ++i)
+  b[i] = 0;
+  }
+  constexpr ~A ()
+  {
+if (!foo ())
+  bar (c);
+  }
+  constexpr bool foo ()
+  {
+char *x = a;
+if (x == b)
+  return true;
+return false;
+  }
+  constexpr void bar (long) {}
+};
+
+constexpr void
+baz (std::initializer_list)
+{
+}
+
+constexpr bool
+qux ()
+{
+  baz ({""});
+  return true;
+}
+
+static_assert (qux (), "");


[gcc r15-7745] x86: Move TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P to i386.cc

2025-02-27 Thread H.J. Lu via Gcc-cvs
https://gcc.gnu.org/g:075611b646e5554ae02b2622061ea1614bf16ead

commit r15-7745-g075611b646e5554ae02b2622061ea1614bf16ead
Author: H.J. Lu 
Date:   Wed Feb 26 05:57:13 2025 +0800

x86: Move TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P to i386.cc

Move the TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P target hook from
i386.h to i386.cc.

* config/i386/i386.h (TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P):
Moved to ...
* config/i386/i386.cc (TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P):
Here.

Signed-off-by: H.J. Lu 

Diff:
---
 gcc/config/i386/i386.cc | 6 ++
 gcc/config/i386/i386.h  | 6 --
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 3128973ba79c..fb93a6fdd0a0 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -27084,6 +27084,12 @@ ix86_libgcc_floating_mode_supported_p
 #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
+/* When this hook returns true for MODE, the compiler allows
+   registers explicitly used in the rtl to be used as spill registers
+   but prevents the compiler from extending the lifetime of these
+   registers.  */
+#undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P
+#define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true
 #undef TARGET_CLASS_LIKELY_SPILLED_P
 #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
 #undef TARGET_IRA_CALLEE_SAVED_REGISTER_COST_SCALE
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 40b1aa4e6dfe..56ef11a58bbc 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1467,12 +1467,6 @@ enum reg_class
 
 #define REGNO_REG_CLASS(REGNO) (regclass_map[(REGNO)])
 
-/* When this hook returns true for MODE, the compiler allows
-   registers explicitly used in the rtl to be used as spill registers
-   but prevents the compiler from extending the lifetime of these
-   registers.  */
-#define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P hook_bool_mode_true
-
 #define QI_REG_P(X) (REG_P (X) && QI_REGNO_P (REGNO (X)))
 #define QI_REGNO_P(N) IN_RANGE ((N), FIRST_QI_REG, LAST_QI_REG)


[gcc r15-7746] MAINTAINERS: add myself to write after approval and DCO

2025-02-27 Thread Giuseppe D'Angelo via Gcc-cvs
https://gcc.gnu.org/g:a3f77f2528b9383c70f0361e0f3863cee58e9648

commit r15-7746-ga3f77f2528b9383c70f0361e0f3863cee58e9648
Author: Giuseppe D'Angelo 
Date:   Fri Feb 28 08:37:25 2025 +0100

MAINTAINERS: add myself to write after approval and DCO

ChangeLog:

* MAINTAINERS: Added myself as write after approval and DCO.

Diff:
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index c423dd6e7874..193cd802a078 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -428,6 +428,7 @@ Ludovic Courtès ludo

 Cary Coutant-   
 Lawrence Crowl  crowl   
 Lili Cui-   
+Giuseppe D'Angelo   peppe   
 Palmer Dabbelt  palmer  
 Ian Dalliandall 
 David Daney daney   

@@ -929,6 +930,7 @@ information.
 
 Soumya AR   
 Juergen Christ  
+Giuseppe D'Angelo   
 Robin Dapp  
 Robin Dapp  
 Aldy Hernandez  


[gcc/devel/omp/gcc-14] nvptx: Add test cases for dead/unused 'alloca'/VLA

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:64cc4d283c6d4304d2bac61ffda545c96ba45503

commit 64cc4d283c6d4304d2bac61ffda545c96ba45503
Author: Thomas Schwinge 
Date:   Mon Feb 24 22:03:47 2025 +0100

nvptx: Add test cases for dead/unused 'alloca'/VLA

gcc/testsuite/
* gcc.target/nvptx/alloca-1-dead-O0-sm_30.c: New.
* gcc.target/nvptx/alloca-1-dead-O0.c: Likewise.
* gcc.target/nvptx/alloca-1-dead-O1-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-1-dead-O1.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O0-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O0.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O1-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O1.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O0-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O0.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O1-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O1.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O0-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O0.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O1-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O1.c: Likewise.

(cherry picked from commit 5c9ef3bdab0c4377c8ba90c234ce891b80ae6338)

Diff:
---
 gcc/testsuite/ChangeLog.omp| 22 ++
 .../gcc.target/nvptx/alloca-1-dead-O0-sm_30.c  | 10 +
 gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c  | 48 ++
 .../gcc.target/nvptx/alloca-1-dead-O1-sm_30.c  | 17 
 gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O1.c  | 17 
 .../gcc.target/nvptx/alloca-1-unused-O0-sm_30.c|  9 
 .../gcc.target/nvptx/alloca-1-unused-O0.c  | 16 
 .../gcc.target/nvptx/alloca-1-unused-O1-sm_30.c| 16 
 .../gcc.target/nvptx/alloca-1-unused-O1.c  | 16 
 .../gcc.target/nvptx/vla-1-dead-O0-sm_30.c | 10 +
 gcc/testsuite/gcc.target/nvptx/vla-1-dead-O0.c | 27 
 .../gcc.target/nvptx/vla-1-dead-O1-sm_30.c | 19 +
 gcc/testsuite/gcc.target/nvptx/vla-1-dead-O1.c | 19 +
 .../gcc.target/nvptx/vla-1-unused-O0-sm_30.c   |  9 
 gcc/testsuite/gcc.target/nvptx/vla-1-unused-O0.c   | 26 
 .../gcc.target/nvptx/vla-1-unused-O1-sm_30.c   | 18 
 gcc/testsuite/gcc.target/nvptx/vla-1-unused-O1.c   | 18 
 17 files changed, 317 insertions(+)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index e9a41526c033..5ceb66c18935 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,25 @@
+2025-02-28  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-02-27  Thomas Schwinge  
+
+   * gcc.target/nvptx/alloca-1-dead-O0-sm_30.c: New.
+   * gcc.target/nvptx/alloca-1-dead-O0.c: Likewise.
+   * gcc.target/nvptx/alloca-1-dead-O1-sm_30.c: Likewise.
+   * gcc.target/nvptx/alloca-1-dead-O1.c: Likewise.
+   * gcc.target/nvptx/alloca-1-unused-O0-sm_30.c: Likewise.
+   * gcc.target/nvptx/alloca-1-unused-O0.c: Likewise.
+   * gcc.target/nvptx/alloca-1-unused-O1-sm_30.c: Likewise.
+   * gcc.target/nvptx/alloca-1-unused-O1.c: Likewise.
+   * gcc.target/nvptx/vla-1-dead-O0-sm_30.c: Likewise.
+   * gcc.target/nvptx/vla-1-dead-O0.c: Likewise.
+   * gcc.target/nvptx/vla-1-dead-O1-sm_30.c: Likewise.
+   * gcc.target/nvptx/vla-1-dead-O1.c: Likewise.
+   * gcc.target/nvptx/vla-1-unused-O0-sm_30.c: Likewise.
+   * gcc.target/nvptx/vla-1-unused-O0.c: Likewise.
+   * gcc.target/nvptx/vla-1-unused-O1-sm_30.c: Likewise.
+   * gcc.target/nvptx/vla-1-unused-O1.c: Likewise.
+
 2025-02-27  Thomas Schwinge  
 
Backported from trunk:
diff --git a/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0-sm_30.c 
b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0-sm_30.c
new file mode 100644
index ..2d002b57579c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0-sm_30.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options {-O0 -mno-soft-stack} } */
+/* { dg-additional-options -march=sm_30 } */
+
+void f(void)
+{
+  char *a = __builtin_alloca(123);
+  /* { dg-message {sorry, unimplemented: dynamic stack allocation not 
supported} {} { target *-*-* } .-1 } */
+  a[0] = 0;
+}
diff --git a/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c 
b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c
new file mode 100644
index ..ecc47e04e727
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c
@@ -0,0 +1,48 @@
+/* { dg-do assemble } */
+/* { dg-options {-O0 -mno-soft-stack} } */
+/* { dg-add-options nvptx_alloca_ptx } */
+/* { dg-additional-options -save-temps } */
+/* { dg-final { check-function-bodies {** } {} } } */
+
+void f(void)
+{
+  char *a = __builtin_alloca(123);
+  a[0] = 0;
+}
+/*
+** f:
+** \.visible \.func f
+*

[gcc r15-7739] input: Fix up ICEs with --param=file-cache-files=N for N > 16 [PR118860]

2025-02-27 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:518def14ef1a8e6e307079f205ff98ad619ccd7b

commit r15-7739-g518def14ef1a8e6e307079f205ff98ad619ccd7b
Author: Jakub Jelinek 
Date:   Thu Feb 27 22:10:46 2025 +0100

input: Fix up ICEs with --param=file-cache-files=N for N > 16 [PR118860]

The following testcase ICEs, because we first construct file_cache object
inside of *global_dc, then process options and then call file_cache::tune.
The earlier construction allocates the m_file_slots array (using new)
based on the static data member file_cache::num_file_slots, but then tune
changes it, without actually reallocating all m_file_slots arrays in already
constructed file_cache objects.

I think it is just weird to have the count be a static data member and
the pointer be non-static data member, that is just asking for issues like
this.

So, this patch changes num_file_slots into m_num_file_slots and turns tune
into a non-static member function and changes toplev.cc to call it on the
global_gc->get_file_cache () object.  And let's the tune just delete the
array and allocate it freshly if there is a change in the number of slots
or lines.

Note, file_cache_slot has similar problem, but because there are many, I
haven't moved the count into those objects; I just hope that when tune
is called there is exactly one file_cache constructed and all the
file_cache_slot objects constructed are pointed by its m_file_slots member,
so also on lines change it just deletes it and allocates again.  I think
it should be unlikely that the cache actually has any used slots by the time
it is called.

2025-02-27  Jakub Jelinek  

PR middle-end/118860
* input.h (file_cache::tune): No longer static.  Rename argument
from num_file_slots_ to num_file_slots.  Formatting fix.
(file_cache::num_file_slots): Renamed to ...
(file_cache::m_num_file_slots): ... this.  No longer static.
* input.cc (file_cache_slot::tune): Change return type from void to
size_t, return previous file_cache_slot::line_record_size value.
Formatting fixes.
(file_cache::tune): Rename argument from num_file_slots_ to
num_file_slots.  Set m_num_file_slots rather than num_file_slots.
If m_num_file_slots or file_cache_slot::line_record_size changes,
delete[] m_file_slots and new it again.
(file_cache::num_file_slots): Remove definition.
(file_cache::lookup_file): Use m_num_file_slots rather than
num_file_slots.
(file_cache::evicted_cache_tab_entry): Likewise.
(file_cache::file_cache): Likewise.  Initialize m_num_file_slots
to 16.
(file_cache::dump): Use m_num_file_slots rather than num_file_slots.
(file_cache_slot::get_next_line): Formatting fixes.
(file_cache_slot::read_line_num): Likewise.
(get_source_text_between): Likewise.
* toplev.cc (toplev::main): Call global_dc->get_file_cache ().tune
rather than file_cache::tune.

* gcc.dg/pr118860.c: New test.

Diff:
---
 gcc/input.cc| 71 +++--
 gcc/input.h |  4 +--
 gcc/testsuite/gcc.dg/pr118860.c |  5 +++
 gcc/toplev.cc   |  3 +-
 4 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/gcc/input.cc b/gcc/input.cc
index 44017589a3d1..797cc9925c19 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -79,8 +79,11 @@ public:
   void evict ();
   void set_content (const char *buf, size_t sz);
 
-  static void tune(size_t line_record_size_) {
-  line_record_size = line_record_size_;
+  static size_t tune (size_t line_record_size_)
+  {
+size_t ret = line_record_size;
+line_record_size = line_record_size_;
+return ret;
   }
 
  private:
@@ -200,14 +203,17 @@ size_t file_cache_slot::recent_cached_lines_shift = 8;
 
 /* Tune file_cache.  */
 void
-file_cache::tune (size_t num_file_slots_, size_t lines)
+file_cache::tune (size_t num_file_slots, size_t lines)
 {
-  num_file_slots = num_file_slots_;
-  file_cache_slot::tune (lines);
+  if (file_cache_slot::tune (lines) != lines
+  || m_num_file_slots != num_file_slots)
+{
+  delete[] m_file_slots;
+  m_file_slots = new file_cache_slot[num_file_slots];
+}
+  m_num_file_slots = num_file_slots;
 }
 
-size_t file_cache::num_file_slots = 16;
-
 static const char *
 find_end_of_line (const char *s, size_t len);
 
@@ -325,7 +331,7 @@ file_cache::lookup_file (const char *file_path)
 
   /* This will contain the found cached file.  */
   file_cache_slot *r = NULL;
-  for (unsigned i = 0; i < num_file_slots; ++i)
+  for (unsigned i = 0; i < m_num_file_slots; ++i)
 {
   file_cache_slot *c = &m_file_slots[i];
   if (c->get_file_path () && !strcmp (c->get_file_path (), file_p

[gcc r15-7730] [PR118940][LRA]: Add a test

2025-02-27 Thread Vladimir Makarov via Gcc-cvs
https://gcc.gnu.org/g:3071eb2848a2e748cfd67e8c897890ce06c69d06

commit r15-7730-g3071eb2848a2e748cfd67e8c897890ce06c69d06
Author: Vladimir N. Makarov 
Date:   Thu Feb 27 13:39:04 2025 -0500

[PR118940][LRA]: Add a test

PR115458 also solves given PR.  So the patch adds only a
test case which can be used for testing LRA work aspects different from
PR115458 test case.

gcc/testsuite/ChangeLog:

PR target/118940
* gcc.target/i386/pr118940.c: New test.

Diff:
---
 gcc/testsuite/gcc.target/i386/pr118940.c | 127 +++
 1 file changed, 127 insertions(+)

diff --git a/gcc/testsuite/gcc.target/i386/pr118940.c 
b/gcc/testsuite/gcc.target/i386/pr118940.c
new file mode 100644
index ..be094310173c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr118940.c
@@ -0,0 +1,127 @@
+/* { dg-do compile } */
+/* { dg-options "-w -g -Os -march=i386 -mregparm=3 -m32 -fno-PIE" } */
+
+typedef unsigned char uint8_t;
+typedef unsigned int uint32_t;
+typedef unsigned int size_t;
+typedef uint32_t bigint_element_t;
+
+/**
+ * Define a big-integer type
+ *
+ * @v size Number of elements
+ * @ret bigint_t   Big integer type
+ */
+ #define bigint_t( size )  \
+ struct {  \
+  bigint_element_t element[ (size) ];  \
+ }
+
+/**
+* Determine number of elements required for a big-integer type
+*
+* @v len   Maximum length of big integer, in bytes
+* @ret sizeNumber of elements
+*/
+#define bigint_required_size( len )\
+ ( ( (len) + sizeof ( bigint_element_t ) - 1 ) /   \
+   sizeof ( bigint_element_t ) )
+
+/**
+ * Determine number of elements in big-integer type
+ *
+ * @v bigint   Big integer
+ * @ret size   Number of elements
+ */
+ #define bigint_size( bigint ) \
+ ( sizeof ( *(bigint) ) / sizeof ( (bigint)->element[0] ) )
+
+ /**
+ * Initialise big integer
+ *
+ * @v valueBig integer to initialise
+ * @v data Raw data
+ * @v len  Length of raw data
+ */
+#define bigint_init( value, data, len ) do {   \
+   unsigned int size = bigint_size (value);\
+   bigint_init_raw ( (value)->element, size, (data), (len) );  \
+   } while ( 0 )
+
+
+/**
+ * Calculate temporary working space required for moduluar exponentiation
+ *
+ * @v modulus  Big integer modulus
+ * @ret lenLength of temporary working space
+ */
+ #define bigint_mod_exp_tmp_len( modulus ) ( { \
+   unsigned int size = bigint_size (modulus);  \
+   sizeof ( struct {   \
+   bigint_t ( size ) temp[4];  \
+   } ); } )
+
+
+/**
+ * Initialise big integer
+ *
+ * @v value0   Element 0 of big integer to initialise
+ * @v size Number of elements
+ * @v data Raw data
+ * @v len  Length of raw data
+ */
+ static inline __attribute__ (( always_inline )) void
+ bigint_init_raw ( uint32_t *value0, unsigned int size,
+ const void *data, size_t len ) {
+  bigint_t ( size ) __attribute__ (( may_alias )) *value =
+   ( ( void * ) value0 );
+  long pad_len = ( sizeof ( *value ) - len );
+  void *discard_D;
+  long discard_c;
+
+  /* Copy raw data in reverse order, padding with zeros */
+  __asm__ __volatile__ ( "\n1:\n\t"
+   "movb -1(%3,%1), %%al\n\t"
+   "stosb\n\t"
+   "loop 1b\n\t"
+   "xorl %%eax, %%eax\n\t"
+   "mov %4, %1\n\t"
+   "rep stosb\n\t"
+   : "=&D" ( discard_D ), "=&c" ( discard_c ),
+  "+m" ( *value )
+   : "r" ( data ), "g" ( pad_len ), "0" ( value0 ),
+  "1" ( len )
+   : "eax" );
+ }
+
+extern void touch (void *, ...);
+extern void touch3 (void *, void *, void *);
+extern void touch2 (void *, void *);
+
+/**
+ * Perform big integer self-tests
+ *
+ */
+void bigint_test_exec ( void ) {
+do{
+   static const uint8_t base_raw[3] = {0};
+   static const uint8_t modulus_raw[3] = {0};
+   static const uint8_t exponent_raw[25] = {0};
+   unsigned int size =
+   bigint_required_size ( sizeof ( base_raw ) );
+   unsigned int exponent_size =
+   bigint_required_size ( sizeof ( exponent_raw ) );
+   bigint_t ( size ) base_temp;
+   bigint_t ( size ) modulus_temp;
+   bigint_t ( exponent_size ) exponent_temp;
+   size_t tmp_len = bigint_mod_exp_tmp_len ( &modulus_temp );
+
+
+   touch ( &base_temp );
+ 

[gcc r15-7734] nvptx: Delay 'sorry, unimplemented: dynamic stack allocation not supported' from expansion time to c

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:22e76700aea63eb8c298403bb2e717a6a4fc9c1e

commit r15-7734-g22e76700aea63eb8c298403bb2e717a6a4fc9c1e
Author: Thomas Schwinge 
Date:   Mon Feb 24 10:09:11 2025 +0100

nvptx: Delay 'sorry, unimplemented: dynamic stack allocation not supported' 
from expansion time to code generation

This gives the back end a chance to clean out a few more unnecessary 
instances
of dynamic stack allocation.  This progresses:

PASS: gcc.dg/pr78902.c  (test for warnings, line 7)
PASS: gcc.dg/pr78902.c  (test for warnings, line 8)
PASS: gcc.dg/pr78902.c  (test for warnings, line 9)
PASS: gcc.dg/pr78902.c  (test for warnings, line 10)
PASS: gcc.dg/pr78902.c  (test for warnings, line 11)
PASS: gcc.dg/pr78902.c  (test for warnings, line 12)
PASS: gcc.dg/pr78902.c  (test for warnings, line 13)
PASS: gcc.dg/pr78902.c strndup excessive bound at line 14 (test for 
warnings, line 13)
[-UNSUPPORTED: gcc.dg/pr78902.c: dynamic stack allocation not 
supported-]
{+PASS: gcc.dg/pr78902.c (test for excess errors)+}

UNSUPPORTED: gcc.dg/torture/pr71901.c   -O0 : dynamic stack allocation 
not supported
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr71901.c   -O1  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}
UNSUPPORTED: gcc.dg/torture/pr71901.c   -O2 : dynamic stack allocation 
not supported
UNSUPPORTED: gcc.dg/torture/pr71901.c   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions : dynamic stack 
allocation not supported
UNSUPPORTED: gcc.dg/torture/pr71901.c   -O3 -g : dynamic stack 
allocation not supported
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr71901.c   -Os  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}

UNSUPPORTED: gcc.dg/torture/pr78742.c   -O0 : dynamic stack allocation 
not supported
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O1  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O2  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O3 
-fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  
[-: dynamic stack allocation not supported-]{+(test for excess errors)+}
[-UNSUPPORTED:-]{+PASS:+} gcc.dg/torture/pr78742.c   -O3 -g  [-: 
dynamic stack allocation not supported-]{+(test for excess errors)+}
UNSUPPORTED: gcc.dg/torture/pr78742.c   -Os : dynamic stack allocation 
not supported

[-UNSUPPORTED:-]{+PASS:+} gfortran.dg/pr101267.f90   -O  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}

[-UNSUPPORTED:-]{+PASS:+} gfortran.dg/pr112404.f90   -O  [-: dynamic 
stack allocation not supported-]{+(test for excess errors)+}

gcc/
* config/nvptx/nvptx.md (define_expand "allocate_stack")
[!TARGET_SOFT_STACK]: Move
'sorry ("dynamic stack allocation not supported");'...
(define_insn "@nvptx_alloca_"): ... here.
gcc/testsuite/
* gcc.target/nvptx/alloca-1-unused-O0-sm_30.c: Adjust.

Diff:
---
 gcc/config/nvptx/nvptx.md  | 42 +++---
 .../gcc.target/nvptx/alloca-1-unused-O0-sm_30.c| 12 +--
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index e7d3630d4c4b..d08afd4378bf 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -1671,15 +1671,8 @@
(match_operand 1 "nvptx_register_operand")]
   ""
 {
-  if (!TARGET_SOFT_STACK
-  && TARGET_PTX_7_3
-  && TARGET_SM52)
+  if (!TARGET_SOFT_STACK)
 emit_insn (gen_nvptx_alloca (Pmode, operands[0], operands[1]));
-  else if (!TARGET_SOFT_STACK)
-{
-  sorry ("dynamic stack allocation not supported");
-  emit_insn (gen_nop ());
-}
   else if (TARGET_SOFT_STACK)
 {
   emit_move_insn (stack_pointer_rtx,
@@ -1696,19 +1689,28 @@
   [(set (match_operand:P 0 "nvptx_register_operand" "=R")
 (unspec:P [(match_operand:P 1 "nvptx_nonmemory_operand" "Ri")]
  UNSPEC_ALLOCA))]
-  "TARGET_PTX_7_3
-   && TARGET_SM52"
+  ""
   {
-/* Convert the address from '.local' state space to generic.  That way,
-   we don't have to use 'st.local', 'ld.local', and can easily pass the
-   address to other "generic functions".
-   TODO 'gcc.target/nvptx/alloca-5.c' */
-output_asm_insn ("{", NULL);
-output_asm_insn ("\\t.reg%t0\\t%0_local;", operands);
-output_asm_insn ("\\talloca%u0\\t%0_local, %1;", operands);
-output_asm_insn ("\\tcvta.local%u0\\t%0, %0_local;", operands);
-output_asm_insn ("}", NULL);
-return "";
+if (TARGET_PTX_7_3
+   && TARGET_SM52)
+  {
+   /* 

[gcc r15-7743] RISC-V: Fix bug for expand_const_vector interleave [PR118931]

2025-02-27 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:e7287cbbb208b676991096dd9081ff8a61c49781

commit r15-7743-ge7287cbbb208b676991096dd9081ff8a61c49781
Author: Pan Li 
Date:   Sat Feb 22 19:34:52 2025 +0800

RISC-V: Fix bug for expand_const_vector interleave [PR118931]

This patch would like to fix one bug when expanding const vector for the
interleave case.  For example, we have:

base1 = 151
step = 121

For vec_series, we will generate vector in format of v[i] = base + i * step.
Then the vec_series will have below result for HImode, and we can find
that the result overflow to the highest 8 bits of HImode.

v1.b = {151, 255, 7,  0, 119,  0, 231,  0, 87,  1, 199,  1, 55,   2, 167,   
2}

Aka we expect v1.b should be:

v1.b = {151, 0, 7,  0, 119,  0, 231,  0, 87,  0, 199,  0, 55,   0, 167,   0}

After that it will perform the IOR with v2 for the base2(aka another 
series).

v2.b =  {0,  17, 0, 33,   0, 49,   0, 65,  0, 81,   0, 97,  0, 113,   0, 
129}

Unfortunately, the base1 + i * step1 in HImode may overflow to the high
8 bits, and the high 8 bits will pollute the v2 and result in incorrect
value in const_vector.

This patch would like to perform the overflow to smode check before the
optimized interleave code generation.  If overflow or VLA, it will fall
back to the default merge approach.

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

PR target/118931

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_const_vector): Add overflow to
smode check and clean up highest bits if overflow.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr118931-run-1.c: New test.

Signed-off-by: Pan Li 

Diff:
---
 gcc/config/riscv/riscv-v.cc| 36 +-
 .../gcc.target/riscv/rvv/base/pr118931-run-1.c | 19 
 2 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 7cc15f3d53c1..287eb3e54cf7 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1489,22 +1489,44 @@ expand_const_vector (rtx target, rtx src)
 
  EEW = 32, { 2, 4, ... }.
 
-This only works as long as the larger type does not overflow
-as we can't guarantee a zero value for each second element
-of the sequence with smaller EEW.
-??? For now we assume that no overflow happens with positive
-steps and forbid negative steps altogether.  */
+Both the series1 and series2 may overflow before taking the IOR
+to generate the final result.  However, only series1 matters
+because the series2 will shift before IOR, thus the overflow
+bits will never pollute the final result.
+
+For now we forbid the negative steps and overflow, and they
+will fall back to the default merge way to generate the
+const_vector.  */
+
  unsigned int new_smode_bitsize = builder.inner_bits_size () * 2;
  scalar_int_mode new_smode;
  machine_mode new_mode;
  poly_uint64 new_nunits
= exact_div (GET_MODE_NUNITS (builder.mode ()), 2);
+
+ poly_int64 base1_poly = rtx_to_poly_int64 (base1);
+ bool overflow_smode_p = false;
+
+ if (!step1.is_constant ())
+   overflow_smode_p = true;
+ else
+   {
+ int elem_count = XVECLEN (src, 0);
+ uint64_t step1_val = step1.to_constant ();
+ uint64_t base1_val = base1_poly.to_constant ();
+ uint64_t elem_val = base1_val + (elem_count - 1) * step1_val;
+
+ if ((elem_val >> builder.inner_bits_size ()) != 0)
+   overflow_smode_p = true;
+   }
+
  if (known_ge (step1, 0) && known_ge (step2, 0)
  && int_mode_for_size (new_smode_bitsize, 0).exists (&new_smode)
- && get_vector_mode (new_smode, new_nunits).exists (&new_mode))
+ && get_vector_mode (new_smode, new_nunits).exists (&new_mode)
+ && !overflow_smode_p)
{
  rtx tmp1 = gen_reg_rtx (new_mode);
- base1 = gen_int_mode (rtx_to_poly_int64 (base1), new_smode);
+ base1 = gen_int_mode (base1_poly, new_smode);
  expand_vec_series (tmp1, base1, gen_int_mode (step1, new_smode));
 
  if (rtx_equal_p (base2, const0_rtx) && known_eq (step2, 0))
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr118931-run-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/pr118931-run-1.c
new file mode 100644
index ..84c63b5040e4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr118931-run-1.c
@@ -0,0 +1,19 @@
+/* { dg-do run { target { riscv_v } } } */
+/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d 

[gcc r15-7736] nvptx: Build libgfortran with '-mfake-ptx-alloca' [PR107635]

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:bac2d8a246892334e24dfa7d62be0cd0648c5606

commit r15-7736-gbac2d8a246892334e24dfa7d62be0cd0648c5606
Author: Thomas Schwinge 
Date:   Tue Feb 25 22:31:25 2025 +0100

nvptx: Build libgfortran with '-mfake-ptx-alloca' [PR107635]

As of recent commit 8bf0ee8d62b8a08e808344d31354ab713157e15d
"Fortran: Add transfer_between_remotes [PR107635]", we've got 'alloca' usage
in 'libgfortran/caf/single.c:_gfortran_caf_transfer_between_remotes', and
the libgfortran target library fails to build for legacy configurations 
where
PTX 'alloca' is not available:

../../../../source-gcc/libgfortran/caf/single.c: In function 
‘_gfortran_caf_transfer_between_remotes’:
../../../../source-gcc/libgfortran/caf/single.c:675:23: sorry, 
unimplemented: dynamic stack allocation not supported
  675 |   transfer_desc = __builtin_alloca (desc_size);
  |   ^~~~
../../../../source-gcc/libgfortran/caf/single.c:680:20: sorry, 
unimplemented: dynamic stack allocation not supported
  680 | transfer_ptr = __builtin_alloca (*opt_dst_charlen * 
src_size);
  |
^~
make[6]: *** [Makefile:4675: caf/single.lo] Error 1

With '-mfake-ptx-alloca', libgfortran again succeeds to build, and compared
to before, we've got only a small number of regressions due to nvptx 'ld'
complaining about 'unresolved symbol __GCC_nvptx__PTX_alloca_not_supported':

[-PASS:-]{+FAIL:+} gfortran.dg/coarray/codimension_2.f90 -fcoarray=lib  
-O2  -lcaf_single (test for excess errors)

[-PASS:-]{+FAIL:+} gfortran.dg/coarray/event_4.f08 -fcoarray=lib  -O2  
-lcaf_single (test for excess errors)
[-PASS:-]{+UNRESOLVED:+} gfortran.dg/coarray/event_4.f08 -fcoarray=lib  
-O2  -lcaf_single [-execution test-]{+compilation failed to produce executable+}

[-PASS:-]{+FAIL:+} gfortran.dg/coarray/fail_image_2.f08 -fcoarray=lib  
-O2  -lcaf_single (test for excess errors)
[-PASS:-]{+UNRESOLVED:+} gfortran.dg/coarray/fail_image_2.f08 
-fcoarray=lib  -O2  -lcaf_single [-execution test-]{+compilation failed to 
produce executable+}

[-PASS:-]{+FAIL:+} gfortran.dg/coarray/proc_pointer_assign_1.f90 
-fcoarray=lib  -O2  -lcaf_single (test for excess errors)
[-PASS:-]{+UNRESOLVED:+} gfortran.dg/coarray/proc_pointer_assign_1.f90 
-fcoarray=lib  -O2  -lcaf_single [-execution test-]{+compilation failed to 
produce executable+}

[-PASS:-]{+FAIL:+} gfortran.dg/coarray_43.f90   -O  (test for excess 
errors)

That's acceptable for such legacy PTX configurations.

PR target/107635
libgfortran/
* config/t-nvptx: New.
* configure.host [nvptx] (tmake_file): Add it.

Diff:
---
 libgfortran/config/t-nvptx | 2 ++
 libgfortran/configure.host | 4 
 2 files changed, 6 insertions(+)

diff --git a/libgfortran/config/t-nvptx b/libgfortran/config/t-nvptx
new file mode 100644
index ..88bd6eee9826
--- /dev/null
+++ b/libgfortran/config/t-nvptx
@@ -0,0 +1,2 @@
+# Re 'alloca' usage in '../caf/single.c':
+AM_CFLAGS += -mfake-ptx-alloca
diff --git a/libgfortran/configure.host b/libgfortran/configure.host
index 291188d19c29..9abd40f511ae 100644
--- a/libgfortran/configure.host
+++ b/libgfortran/configure.host
@@ -91,6 +91,10 @@ case "${target}" in
tmake_file="t-aix"
;;
 
+  nvptx-*-none)
+   tmake_file="$tmake_file t-nvptx"
+   ;;
+
   *)
;;


[gcc r15-7735] nvptx: Support '-mfake-ptx-alloca'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:1146410c0feb0e82c689b1333fdf530a2b34dc2b

commit r15-7735-g1146410c0feb0e82c689b1333fdf530a2b34dc2b
Author: Thomas Schwinge 
Date:   Mon Feb 24 16:13:11 2025 +0100

nvptx: Support '-mfake-ptx-alloca'

With '-mfake-ptx-alloca' enabled, the user-visible behavior changes only
for configurations where PTX 'alloca' is not available.  Rather than a
compile-time 'sorry, unimplemented: dynamic stack allocation not supported'
in presence of dynamic stack allocation, compilation and assembly then
succeeds.  However, attempting to link in such '*.o' files then fails due
to unresolved symbol '__GCC_nvptx__PTX_alloca_not_supported'.

This is meant to be used in scenarios where large volumes of code are
compiled, a small fraction of which runs into dynamic stack allocation, but
these parts are not important for specific use cases, and we'd thus like the
build to succeed, and error out just upon actual, very rare use of the
offending '*.o' files.

gcc/
* config/nvptx/nvptx.opt (-mfake-ptx-alloca): New.
* config/nvptx/nvptx-protos.h (nvptx_output_fake_ptx_alloca):
Declare.
* config/nvptx/nvptx.cc (nvptx_output_fake_ptx_alloca): New.
* config/nvptx/nvptx.md (define_insn "@nvptx_alloca_")
[!(TARGET_PTX_7_3 && TARGET_SM52)]: Use it for
'-mfake-ptx-alloca'.
gcc/testsuite/
* gcc.target/nvptx/alloca-1-O0_-mfake-ptx-alloca.c: New.
* gcc.target/nvptx/alloca-2-O0_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/alloca-4-O3_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/vla-1-O0_-mfake-ptx-alloca.c: Likewise.
* gcc.target/nvptx/alloca-4-O3.c:
'dg-additional-options -mfake-ptx-alloca'.

Diff:
---
 gcc/config/nvptx/nvptx-protos.h|  1 +
 gcc/config/nvptx/nvptx.cc  | 21 ++
 gcc/config/nvptx/nvptx.md  |  4 ++
 gcc/config/nvptx/nvptx.opt | 15 +++
 .../nvptx/alloca-1-O0_-mfake-ptx-alloca.c  | 49 ++
 .../nvptx/alloca-2-O0_-mfake-ptx-alloca.c  | 18 
 gcc/testsuite/gcc.target/nvptx/alloca-4-O3.c   |  2 +
 .../nvptx/alloca-4-O3_-mfake-ptx-alloca.c  | 48 +
 .../gcc.target/nvptx/vla-1-O0_-mfake-ptx-alloca.c  | 29 +
 9 files changed, 187 insertions(+)

diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h
index e85e758322d7..ca1fed6d9920 100644
--- a/gcc/config/nvptx/nvptx-protos.h
+++ b/gcc/config/nvptx/nvptx-protos.h
@@ -55,6 +55,7 @@ extern rtx nvptx_expand_compare (rtx);
 extern const char *nvptx_ptx_type_from_mode (machine_mode, bool);
 extern const char *nvptx_output_mov_insn (rtx, rtx);
 extern const char *nvptx_output_call_insn (rtx_insn *, rtx, rtx);
+extern const char *nvptx_output_fake_ptx_alloca (void);
 extern const char *nvptx_output_return (void);
 extern const char *nvptx_output_set_softstack (unsigned);
 extern const char *nvptx_output_simt_enter (rtx, rtx, rtx);
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index 64de2b1cc9be..d1648d52f2fa 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -1758,6 +1758,27 @@ nvptx_output_set_softstack (unsigned src_regno)
 }
   return "";
 }
+
+/* Output a fake PTX 'alloca'.  */
+
+const char *
+nvptx_output_fake_ptx_alloca (void)
+{
+#define FAKE_PTX_ALLOCA_NAME "__GCC_nvptx__PTX_alloca_not_supported"
+  static tree decl;
+  if (!decl)
+{
+  tree alloca_type = TREE_TYPE (builtin_decl_explicit (BUILT_IN_ALLOCA));
+  decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
+get_identifier (FAKE_PTX_ALLOCA_NAME), alloca_type);
+  DECL_EXTERNAL (decl) = 1;
+  TREE_PUBLIC (decl) = 1;
+  nvptx_record_needed_fndecl (decl);
+}
+  return "\tcall\t(%0), " FAKE_PTX_ALLOCA_NAME ", (%1);";
+#undef FAKE_PTX_ALLOCA_NAME
+}
+
 /* Output a return instruction.  Also copy the return value to its outgoing
location.  */
 
diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index d08afd4378bf..3201247c5fb1 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -1705,6 +1705,8 @@
output_asm_insn ("}", NULL);
return "";
   }
+else if (nvptx_fake_ptx_alloca)
+  return nvptx_output_fake_ptx_alloca ();
 else
   {
sorry_at (INSN_LOCATION (insn),
@@ -1733,6 +1735,7 @@
   gcc_checking_assert (REG_P (operands[0]));
   emit_insn (gen_nvptx_stacksave (Pmode, operands[0], operands[1]));
 }
+  /* We don't bother to special-case '-mfake-ptx-alloca' here.  */
   else
 {
   /* The concept of a '%stack' pointer doesn't apply like this.
@@ -1765,6 +1768,7 @@
   operands[1] = force_reg (Pmode, operands[1]);
   emit_insn (gen_nvptx_stackrestore (Pmode, operan

[gcc r15-7733] nvptx: Add test cases for dead/unused 'alloca'/VLA

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:5c9ef3bdab0c4377c8ba90c234ce891b80ae6338

commit r15-7733-g5c9ef3bdab0c4377c8ba90c234ce891b80ae6338
Author: Thomas Schwinge 
Date:   Mon Feb 24 22:03:47 2025 +0100

nvptx: Add test cases for dead/unused 'alloca'/VLA

gcc/testsuite/
* gcc.target/nvptx/alloca-1-dead-O0-sm_30.c: New.
* gcc.target/nvptx/alloca-1-dead-O0.c: Likewise.
* gcc.target/nvptx/alloca-1-dead-O1-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-1-dead-O1.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O0-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O0.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O1-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-1-unused-O1.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O0-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O0.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O1-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-dead-O1.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O0-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O0.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O1-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-unused-O1.c: Likewise.

Diff:
---
 .../gcc.target/nvptx/alloca-1-dead-O0-sm_30.c  | 10 +
 gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c  | 48 ++
 .../gcc.target/nvptx/alloca-1-dead-O1-sm_30.c  | 17 
 gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O1.c  | 17 
 .../gcc.target/nvptx/alloca-1-unused-O0-sm_30.c|  9 
 .../gcc.target/nvptx/alloca-1-unused-O0.c  | 16 
 .../gcc.target/nvptx/alloca-1-unused-O1-sm_30.c| 16 
 .../gcc.target/nvptx/alloca-1-unused-O1.c  | 16 
 .../gcc.target/nvptx/vla-1-dead-O0-sm_30.c | 10 +
 gcc/testsuite/gcc.target/nvptx/vla-1-dead-O0.c | 27 
 .../gcc.target/nvptx/vla-1-dead-O1-sm_30.c | 19 +
 gcc/testsuite/gcc.target/nvptx/vla-1-dead-O1.c | 19 +
 .../gcc.target/nvptx/vla-1-unused-O0-sm_30.c   |  9 
 gcc/testsuite/gcc.target/nvptx/vla-1-unused-O0.c   | 26 
 .../gcc.target/nvptx/vla-1-unused-O1-sm_30.c   | 18 
 gcc/testsuite/gcc.target/nvptx/vla-1-unused-O1.c   | 18 
 16 files changed, 295 insertions(+)

diff --git a/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0-sm_30.c 
b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0-sm_30.c
new file mode 100644
index ..2d002b57579c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0-sm_30.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options {-O0 -mno-soft-stack} } */
+/* { dg-additional-options -march=sm_30 } */
+
+void f(void)
+{
+  char *a = __builtin_alloca(123);
+  /* { dg-message {sorry, unimplemented: dynamic stack allocation not 
supported} {} { target *-*-* } .-1 } */
+  a[0] = 0;
+}
diff --git a/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c 
b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c
new file mode 100644
index ..ecc47e04e727
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O0.c
@@ -0,0 +1,48 @@
+/* { dg-do assemble } */
+/* { dg-options {-O0 -mno-soft-stack} } */
+/* { dg-add-options nvptx_alloca_ptx } */
+/* { dg-additional-options -save-temps } */
+/* { dg-final { check-function-bodies {** } {} } } */
+
+void f(void)
+{
+  char *a = __builtin_alloca(123);
+  a[0] = 0;
+}
+/*
+** f:
+** \.visible \.func f
+** {
+** \.local \.align 16 \.b8 %frame_ar\[16\];
+** \.reg\.u64 %frame;
+** cvta\.local\.u64 %frame, %frame_ar;
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** \.reg\.u32 (%r[0-9]+);
+** \.reg\.u64 (%r[0-9]+);
+** mov\.u64\11, 16;
+** add\.u64\1, \11, -1;
+** add\.u64\2, \1, 123;
+** div\.u64\3, \2, 16;
+** mul\.lo\.u64\4, \3, 16;
+** {
+** \.reg\.u64  \5_local;
+** alloca\.u64 \5_local, \4;
+** cvta\.local\.u64\5, \5_local;
+** }
+** add\.u64\6, \5, 15;
+** shr\.u64\7, \6, 4;
+** shl\.b64\8, \7, 4;
+** st\.u64 \[%frame\], \8;
+** ld\.u64 \9, \[%frame\];
+** mov\.u32\10, 0;
+** st\.u8  \[\9\], \10;
+** ret;
+*/
diff --git a/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O1-sm_30.c 
b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O1-sm_30.c
new file mode 100644
index ..e296c049a73b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/alloca-1-dead-O1-sm_30.c
@@ -0,0 +1,17 @@
+/* { dg-do assemble } *

[gcc r15-7738] nvptx: '#define MAX_FIXED_MODE_SIZE 128'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:e333ad4ed82cdfb1b660e9666895641ef3ffaddb

commit r15-7738-ge333ad4ed82cdfb1b660e9666895641ef3ffaddb
Author: Thomas Schwinge 
Date:   Wed Feb 26 15:39:37 2025 +0100

nvptx: '#define MAX_FIXED_MODE_SIZE 128'

... instead of 64 via 'gcc/defaults.h':

MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (DImode)

This fixes ICEs:

[-FAIL: c-c++-common/pr111309-1.c  -Wc++-compat  (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -Wc++-compat  (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -Wc++-compat  
[-compilation failed to produce executable-]{+execution test+}

[-FAIL: c-c++-common/pr111309-1.c  -std=gnu++17 (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++17 (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++17 
[-compilation failed to produce executable-]{+execution test+}
[-FAIL: c-c++-common/pr111309-1.c  -std=gnu++26 (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++26 (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++26 
[-compilation failed to produce executable-]{+execution test+}
[-FAIL: c-c++-common/pr111309-1.c  -std=gnu++98 (internal compiler 
error: in expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++98 (test for 
excess errors)
[-UNRESOLVED:-]{+PASS:+} c-c++-common/pr111309-1.c  -std=gnu++98 
[-compilation failed to produce executable-]{+execution test+}

[-FAIL: gcc.dg/torture/pr116480-1.c   -O0  (internal compiler error: in 
expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} gcc.dg/torture/pr116480-1.c   -O0  (test for excess 
errors)
[-FAIL: gcc.dg/torture/pr116480-1.c   -O1  (internal compiler error: in 
expand_fn_using_insn, at internal-fn.cc:268)-]
[-FAIL:-]{+PASS:+} gcc.dg/torture/pr116480-1.c   -O1  (test for excess 
errors)
PASS: gcc.dg/torture/pr116480-1.c   -O2  (test for excess errors)
PASS: gcc.dg/torture/pr116480-1.c   -O3 -g  (test for excess errors)
PASS: gcc.dg/torture/pr116480-1.c   -Os  (test for excess errors)

..., where we ran into 'gcc_assert (icode != CODE_FOR_nothing);' in
'gcc/internal-fn.cc:expand_fn_using_insn' for '__int128' '__builtin_clzg' 
etc.:

during RTL pass: expand
[...]/c-c++-common/pr111309-1.c: In function 'clzI':
[...]/c-c++-common/pr111309-1.c:69:10: internal compiler error: in 
expand_fn_using_insn, at internal-fn.cc:268
0x120ec2cf internal_error(char const*, ...)
[...]/gcc/diagnostic-global-context.cc:517
0x102c7c5b fancy_abort(char const*, int, char const*)
[...]/gcc/diagnostic.cc:1722
0x109708eb expand_fn_using_insn
[...]/gcc/internal-fn.cc:268
0x1098114f expand_internal_call(internal_fn, gcall*)
[...]/gcc/internal-fn.cc:5273
0x1098114f expand_internal_call(gcall*)
[...]/gcc/internal-fn.cc:5281
0x10594fc7 expand_call_stmt
[...]/gcc/cfgexpand.cc:3049
[...]

Likewise, as of commit e8ad697a75b0870a833366daf687668a57cabb6e
"libstdc++: Use new type-generic built-ins in  [PR118855]",
the libstdc++ target library build ICEd in the same way.

Additionally, this change fixes:

[-FAIL:-]{+PASS:+} gcc.dg/pr105094.c (test for excess errors)

..., which was:

[...]/gcc.dg/pr105094.c: In function 'foo':
[...]/gcc.dg/pr105094.c:11:12: error: size of variable 's' is too large

And, finally, regarding 'gcc.target/nvptx/stack_frame-1.c'.  Before, in
'gcc/cfgexpand.cc': 'expand_used_vars' -> 'expand_used_vars_for_block' ->
'expand_one_var' for 'ww' -> 'gcc/function.cc:use_register_for_decl' due to
'DECL_MODE (decl) == BLKmode' did 'return false;', thus -> 'add_stack_var'
(even if 'ww' wasn't then actually living on the stack).  Now, 'ww' has
'TImode' and 'use_register_for_decl' does 'return true;', thus ->
'expand_one_register_var', and therefore no unused stack frame emitted.

gcc/
* config/nvptx/nvptx.h (MAX_FIXED_MODE_SIZE): '#define'.
gcc/testsuite/
* gcc.target/nvptx/stack_frame-1.c: Adjust.

Diff:
---
 gcc/config/nvptx/nvptx.h   | 2 ++
 gcc/testsuite/gcc.target/nvptx/stack_frame-1.c | 7 ++-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.h b/gcc/config/nvptx/nvptx.h
index c21e7cb960d3..1ec5f60fea7e 100644
--- a/gcc/config/nvptx/nvptx.h
+++ b/gcc/config/nvptx/n

[gcc r15-7737] Add 'gcc.target/nvptx/stack_frame-1.c'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:39e1ec22dbaad6cf8e3dc16fd4a576d03215201e

commit r15-7737-g39e1ec22dbaad6cf8e3dc16fd4a576d03215201e
Author: Thomas Schwinge 
Date:   Wed Feb 26 17:17:44 2025 +0100

Add 'gcc.target/nvptx/stack_frame-1.c'

gcc/testsuite/
* gcc.target/nvptx/stack_frame-1.c: New.

Diff:
---
 gcc/testsuite/gcc.target/nvptx/stack_frame-1.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/gcc/testsuite/gcc.target/nvptx/stack_frame-1.c 
b/gcc/testsuite/gcc.target/nvptx/stack_frame-1.c
new file mode 100644
index ..476d0ac93ed0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/nvptx/stack_frame-1.c
@@ -0,0 +1,34 @@
+/* GCC emits an unused stack frame.  */
+
+/* { dg-do assemble } */
+/* { dg-options {-O2 -mno-soft-stack} } */
+/* { dg-additional-options -save-temps } */
+/* { dg-final { check-function-bodies {** } {} } } */
+
+/* Greatly reduced from libgcc code, where this issue is visible for
+   '_divdi3.o:__divti3', '_divmoddi4.o:__divmodti4', '_moddi3.o:__modti3',
+   '_udivdi3.o:__udivti3', '_udivmoddi4.o:__udivmodti4',
+   '_umoddi3.o:__umodti3'.  */
+
+int f (int n)
+{
+  const union {
+struct { long low, high; };
+__int128 ll;
+  } ww = {{.low = n, .high = 0}};
+  return (int) ww.ll;
+}
+/*
+** f:
+** \.visible \.func \(\.param\.u32 %value_out\) f \(\.param\.u32 %in_ar0\)
+** {
+** \.reg\.u32 %value;
+** \.reg\.u32 %ar0;
+** ld\.param\.u32 %ar0, \[%in_ar0\];
+** \.local \.align 16 \.b8 %frame_ar\[16\];
+** \.reg\.u64 %frame;
+** cvta\.local\.u64 %frame, %frame_ar;
+** mov\.u32%value, %ar0;
+** st\.param\.u32  \[%value_out\], %value;
+** ret;
+*/


[gcc r15-7731] c++: ICE with GOTO_EXPR [PR118928]

2025-02-27 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:9792126ac769f2962c0f305991818c64f9e51221

commit r15-7731-g9792126ac769f2962c0f305991818c64f9e51221
Author: Marek Polacek 
Date:   Wed Feb 19 14:06:33 2025 -0500

c++: ICE with GOTO_EXPR [PR118928]

In this PR we crash in cxx_eval_constant_expression/GOTO_EXPR on:

  gcc_assert (cxx_dialect >= cxx23);

The code obviously doesn't expect to see a goto pre-C++23.  But we can
get here with the new prvalue optimization.  In this test we found
ourselves in synthesize_method for X::X().  This function calls:

 a) finish_function, which does cp_genericize -> ... -> genericize_c_loops,
which creates the GOTO_EXPR;
 b) expand_or_defer_fn -> maybe_clone_body -> ... -> cp_fold_function
where we reach the new maybe_constant_init call and crash on the
goto.

Since we can validly get to that assert, I think we should just remove
it.  I don't see other similar asserts like this one.

PR c++/118928

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression) : 
Remove
an assert.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-prvalue5.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/cp/constexpr.cc |  1 -
 gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C | 24 
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 59dd0668af3f..c68666cc5ddc 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -8691,7 +8691,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
*jump_target = TREE_OPERAND (t, 0);
   else
{
- gcc_assert (cxx_dialect >= cxx23);
  if (!ctx->quiet)
error_at (loc, "% is not a constant expression");
  *non_constant_p = true;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C
new file mode 100644
index ..1f847bbe183e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-prvalue5.C
@@ -0,0 +1,24 @@
+// PR c++/118928
+// { dg-do compile { target c++11 } }
+// { dg-options "-O" }
+
+using size_t = decltype(sizeof(0));
+
+namespace std {
+template  struct initializer_list {
+  const T *_M_array;
+  size_t _M_len;
+};
+struct S {
+  constexpr S(const char *); // { dg-warning "used but never defined" }
+};
+struct vector {
+  constexpr vector(initializer_list) {}
+};
+}
+struct Y {
+std::vector v;
+};
+struct X {
+  Y y{{""}};
+} x;


[gcc r14-11350] c++: NRVO, constexpr, lambda [PR118053]

2025-02-27 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:7e7a1b612654479e821214f7ef7658de8a132714

commit r14-11350-g7e7a1b612654479e821214f7ef7658de8a132714
Author: Jason Merrill 
Date:   Sat Feb 15 10:48:17 2025 +0100

c++: NRVO, constexpr, lambda [PR118053]

Here during constant evaluation we encounter a VAR_DECL with DECL_VALUE_EXPR
of the RESULT_DECL, where the latter has been adjusted for
pass-by-invisible-reference.  We already had the code to deal with this, we
just need to use it in the non-capture case of DECL_VALUE_EXPR as well.

PR c++/118053

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression): Generalize
DECL_VALUE_EXPR invisiref handling.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-lambda1.C: New test.

(cherry picked from commit de66529f2e7bb24fb2b61b82e6a953f3f6c12902)

Diff:
---
 gcc/cp/constexpr.cc| 19 ++-
 gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C | 21 +
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 4b10763950d2..a5c6227b8dd6 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -7460,18 +7460,19 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
 definition, so don't try to look at the closure.  But if the
 captured variable is constant, try to evaluate it directly. */
  r = DECL_CAPTURED_VARIABLE (t);
- tree type = TREE_TYPE (t);
- if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
-   {
- /* Adjust r to match the reference-ness of t.  */
- if (TYPE_REF_P (type))
-   r = build_address (r);
- else
-   r = convert_from_reference (r);
-   }
}
  else
r = DECL_VALUE_EXPR (t);
+
+ tree type = TREE_TYPE (t);
+ if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
+   {
+ /* Adjust r to match the reference-ness of t.  */
+ if (TYPE_REF_P (type))
+   r = build_address (r);
+ else
+   r = convert_from_reference (r);
+   }
  return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
   overflow_p);
}
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C 
b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
new file mode 100644
index ..dca3920ddc0c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda1.C
@@ -0,0 +1,21 @@
+// PR c++/118053
+// { dg-do compile { target c++14 } }
+// { dg-additional-options -O }
+
+template  struct vector {
+  _Tp * _M_finish;
+  vector(_Tp);
+  vector(const vector &);
+  constexpr auto back() { return *_M_finish; }
+};
+template  void
+run(Funct funct) { funct(1); }
+
+vector
+runner() try {
+  vector vec{1};
+  run([&](auto) { vec.back(); });
+  return vec;
+} catch (...) {
+  return 1;
+}


[gcc r15-7729] [PR116336][LRA]: Add a test

2025-02-27 Thread Vladimir Makarov via Gcc-cvs
https://gcc.gnu.org/g:e59dd301aea9c8d5a5d04e808c87d591a26e85bb

commit r15-7729-ge59dd301aea9c8d5a5d04e808c87d591a26e85bb
Author: Vladimir N. Makarov 
Date:   Thu Feb 27 13:05:44 2025 -0500

[PR116336][LRA]: Add a test

  Patch for PR116234 solves given PR116366.  So the patch adds only the test
case which is very different from PR116234 one.

gcc/testsuite/ChangeLog:

PR rtl-optimization/116336
* gcc.dg/pr116336.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/pr116336.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/pr116336.c b/gcc/testsuite/gcc.dg/pr116336.c
new file mode 100644
index ..3e4f3d329c10
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116336.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -gno-statement-frontiers -fcompare-debug" } */
+
+double duk_js_execute_bytecode_duk__tv_0_0;
+double duk_double_div();
+void duk_handle_call_unprotected();
+void duk_js_execute_bytecode() {
+  double du_0;
+  long opcode_shifted;
+  switch (opcode_shifted)
+  case 2:
+du_0 = duk_double_div();
+  duk_js_execute_bytecode_duk__tv_0_0 = du_0;
+  duk_handle_call_unprotected();
+  duk_js_execute_bytecode();
+}


[gcc r15-7741] libstdc++: Fix outdated comment in

2025-02-27 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:e8302282cdb53ae1d347c12d7a50c4209fbab4f7

commit r15-7741-ge8302282cdb53ae1d347c12d7a50c4209fbab4f7
Author: Jonathan Wakely 
Date:   Thu Feb 27 21:58:09 2025 +

libstdc++: Fix outdated comment in 

My r15-998-g2a83084ce55363 change replaced the use of nothrow
operator new with a call to __get_temporary_buffer, so update the
comment to match.

libstdc++-v3/ChangeLog:

* include/std/stacktrace (_Impl::_M_allocate): Fix outdated
comment.

Diff:
---
 libstdc++-v3/include/std/stacktrace | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index f94a424e4cff..491122293c5f 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -559,7 +559,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  if constexpr (is_same_v>)
{
- // For std::allocator we use nothrow-new directly so we
+ // Use non-throwing __get_temporary_buffer, so that we
  // don't need to handle exceptions from __alloc.allocate(n).
  auto __p = __detail::__get_temporary_buffer(__n);
  if (__p == nullptr) [[unlikely]]


[gcc r15-7742] libphobos: Run unittest tests with dg-runtest.

2025-02-27 Thread Iain Buclaw via Gcc-cvs
https://gcc.gnu.org/g:955de3733a9ef301e2d95009cd59a1eb4ee5273c

commit r15-7742-g955de3733a9ef301e2d95009cd59a1eb4ee5273c
Author: Iain Buclaw 
Date:   Thu Feb 27 23:37:21 2025 +0100

libphobos: Run unittest tests with dg-runtest.

Use `dg-runtest' test driver rather than `dg-test' to run the libphobos
unittest testsuite, same as all other libphobos tests.  This prevents
the tests from being ran multiple times when parallelized.

Set `libphobos_test_name' as well so that all tests get a unique name.

libphobos/ChangeLog:

* testsuite/libphobos.unittest/unittest.exp: Use `dg-runtest' rather
than `dg-test'.  Set `libphobos_test_name'.

Diff:
---
 libphobos/testsuite/libphobos.unittest/unittest.exp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libphobos/testsuite/libphobos.unittest/unittest.exp 
b/libphobos/testsuite/libphobos.unittest/unittest.exp
index 3e2d3b84cdce..0b0e3e3ce09d 100644
--- a/libphobos/testsuite/libphobos.unittest/unittest.exp
+++ b/libphobos/testsuite/libphobos.unittest/unittest.exp
@@ -42,8 +42,10 @@ foreach unit_test $unit_test_list {
 set expected_fail [lindex $unit_test 1]
 
 foreach test $tests {
+set libphobos_test_name "[dg-trim-dirname $srcdir $test] $test_flags"
 set shouldfail $expected_fail
-dg-test $test "" $test_flags
+dg-runtest $test "" $test_flags
+set libphobos_test_name ""
 }
 
 set shouldfail 0


[gcc r15-7740] gimple-fold: Fix a pasto in fold_truth_andor_for_ifcombine [PR119030]

2025-02-27 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:8371e7f240c1130a3827be1afb94f73c26df81a6

commit r15-7740-g8371e7f240c1130a3827be1afb94f73c26df81a6
Author: Jakub Jelinek 
Date:   Thu Feb 27 22:11:51 2025 +0100

gimple-fold: Fix a pasto in fold_truth_andor_for_ifcombine [PR119030]

The following testcase is miscompiled since r15-7597.
The left comparison is unsigned (x & 0x8000U) != 0) while the
right one is signed (x >> 16) >= 0 and is actually a signbit test,
so rsignbit is 64.
After debugging this and reading the r15-7597 change, I believe there
is just a pasto, the if (lsignbit) and if (rsignbit) blocks are pretty
much identical with just the first l on all variables starting with l
replaced with r (the only difference is that if (lsignbit) has a comment
explaining the sign <<= 1; stuff, while it isn't repeated in the second one.
Except the second one was using ll_unsignedp instead of rl_unsignedp
in one spot.  I think it should use the latter, the signedness of the left
comparison doesn't affect the other one, they are basically independent
with the exception that we check that after transformations they are both
EQ or both NE and later on we try to merge them together.

2025-02-27  Jakub Jelinek  

PR tree-optimization/119030
* gimple-fold.cc (fold_truth_andor_for_ifcombine): Fix a pasto,
ll_unsignedp -> rl_unsignedp.

* gcc.c-torture/execute/pr119030.c: New test.

Diff:
---
 gcc/gimple-fold.cc |  2 +-
 gcc/testsuite/gcc.c-torture/execute/pr119030.c | 26 ++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 0380c7af4c21..b64561396874 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8313,7 +8313,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   if (rsignbit)
 {
   wide_int sign = wi::mask (rl_bitsize - 1, true, rl_bitsize);
-  if (rsignbit > rl_bitsize && ll_unsignedp)
+  if (rsignbit > rl_bitsize && rl_unsignedp)
sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr119030.c 
b/gcc/testsuite/gcc.c-torture/execute/pr119030.c
new file mode 100644
index ..8964bac617bc
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr119030.c
@@ -0,0 +1,26 @@
+/* PR tree-optimization/119030 */
+
+static inline unsigned
+foo (long long x)
+{
+  return x & 0x8000;
+}
+
+static inline long long
+bar (long long x)
+{
+  if (foo (x))
+return -1000L;
+  else
+return x >> 16;
+}
+
+long long x = -0x2LL;
+
+int
+main ()
+{
+  if (bar (x) >= 0)
+__builtin_abort ();
+  return 0;
+}


[gcc r15-7726] Fortran: Fix ICE on associate of pointer [PR118789]

2025-02-27 Thread Andre Vehreschild via Gcc-cvs
https://gcc.gnu.org/g:0fc1abcc46ecc34e8d2d7ec7167656ede2cd5690

commit r15-7726-g0fc1abcc46ecc34e8d2d7ec7167656ede2cd5690
Author: Andre Vehreschild 
Date:   Tue Feb 25 17:15:47 2025 +0100

Fortran: Fix ICE on associate of pointer [PR118789]

Fix ICE when associating a pointer to void (c_ptr) by looking at the
compatibility of the type hierarchy.

PR fortran/118789

gcc/fortran/ChangeLog:

* trans-stmt.cc (trans_associate_var): Compare pointed to types when
expr to associate is already a pointer.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/fortran/trans-stmt.cc  |  7 ++-
 gcc/testsuite/gfortran.dg/associate_73.f90 | 21 +
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index e7da8fea3b24..f16e1e3b46e3 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -2287,7 +2287,12 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block 
*block)
  tmp = se.expr;
}
}
- if (!POINTER_TYPE_P (TREE_TYPE (se.expr)))
+ /* For non-pointer types in se.expr, the first condition holds.
+For pointer or reference types in se.expr, a double TREE_TYPE ()
+is possible and an associate variable always is a pointer.  */
+ if (!POINTER_TYPE_P (TREE_TYPE (se.expr))
+ || TREE_TYPE (TREE_TYPE (se.expr))
+  != TREE_TYPE (TREE_TYPE (sym->backend_decl)))
tmp = gfc_build_addr_expr (tmp, se.expr);
}
 
diff --git a/gcc/testsuite/gfortran.dg/associate_73.f90 
b/gcc/testsuite/gfortran.dg/associate_73.f90
new file mode 100644
index ..a5c3ca79b9cf
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associate_73.f90
@@ -0,0 +1,21 @@
+!{ dg-do compile }
+
+! Check associate to a "void *" does not ICE.
+! Contributed by Matthias Klose  
+! and Steve Kargl  
+
+module pr118789
+
+   implicit none
+
+   CONTAINS
+
+   subroutine fckit_c_nodelete(cptr) bind(c)
+  use, intrinsic :: iso_c_binding
+  type(c_ptr), value :: cptr
+  associate( unused_ => cptr )
+  end associate
+   end subroutine
+
+end module
+


[gcc/devel/omp/gcc-14] Refactor duplicated code into 'gcc/testsuite/lib/gcc-dg.exp:find-dg-do-what'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:2bc0b96cc1c36fe8f99402fe91f80bfeac02ff71

commit 2bc0b96cc1c36fe8f99402fe91f80bfeac02ff71
Author: Thomas Schwinge 
Date:   Fri Feb 21 19:42:28 2025 +0100

Refactor duplicated code into 'gcc/testsuite/lib/gcc-dg.exp:find-dg-do-what'

No change in behavior intended.

gcc/testsuite/
* lib/gcc-dg.exp (proc find-dg-do-what): New.
* lib/target-supports.exp (check_effective_target_stack_size)
(check_effective_target_alloca): Use it.

(cherry picked from commit f553b1aaa2b1b925c918e5dcf966290b045321c2)

Diff:
---
 gcc/testsuite/ChangeLog.omp   |  7 +++
 gcc/testsuite/lib/gcc-dg.exp  | 16 
 gcc/testsuite/lib/target-supports.exp | 20 ++--
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 230ec62f80ee..d416d476a6d3 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -3,6 +3,13 @@
Backported from trunk:
2025-02-22  Thomas Schwinge  
 
+   * lib/gcc-dg.exp (proc find-dg-do-what): New.
+   * lib/target-supports.exp (check_effective_target_stack_size)
+   (check_effective_target_alloca): Use it.
+
+   Backported from trunk:
+   2025-02-22  Thomas Schwinge  
+
* gcc.target/bpf/diag-alloca-1.c: Adjust 'dg-message'.
* gcc.target/bpf/diag-alloca-2.c: Likewise.
* gcc.target/nvptx/alloca-1-O0-sm_30.c: Likewise.
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 42c2013d4216..ffb596d80b88 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -1451,3 +1451,19 @@ proc gcc-transform-out-of-tree { args } {
 
 set additional_prunes ""
 set dg_runtest_extra_prunes ""
+
+# Find the 'dg-do-what' variable living inside DejaGnu's 'dg-test' procedure,
+# as a local variable.  We start looking at the second-outer frame: this way,
+# the caller of 'find-dg-do-what' may maintain a local 'dg-do-what' variable
+# without interfering with this search.
+proc find-dg-do-what { } {
+set lookup_level 2
+while true {
+   upvar $lookup_level dg-do-what dg-do-what
+   if { [info exists dg-do-what] } {
+   verbose "find-dg-do-what: found 'dg-do-what' at level 
$lookup_level: ${dg-do-what}" 2
+   return ${dg-do-what}
+   }
+   incr lookup_level
+}
+}
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 21a9861e392e..803a26b334cf 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -651,15 +651,7 @@ proc check_effective_target_trampolines { } {
 proc check_effective_target_stack_size { } {
 # For nvptx target, stack size limits are relevant for execution only.
 if { [istarget nvptx-*-*] } {
-   # Find 'dg-do-what' in an outer frame.
-   set level 1
-   while true {
-   upvar $level dg-do-what dg-do-what
-   if [info exists dg-do-what] then break
-   incr level
-   }
-   verbose "check_effective_target_stack_size: found dg-do-what at level 
$level" 2
-
+   set dg-do-what [find-dg-do-what]
if { ![string equal [lindex ${dg-do-what} 0] run] } {
return 0
}
@@ -1006,15 +998,7 @@ proc check_effective_target_alloca {} {
return 0
}
 
-   # Find 'dg-do-what' in an outer frame.
-   set level 1
-   while true {
-   upvar $level dg-do-what dg-do-what
-   if [info exists dg-do-what] then break
-   incr level
-   }
-   verbose "check_effective_target_alloca: found dg-do-what at level 
$level" 2
-
+   set dg-do-what [find-dg-do-what]
if { [string equal [lindex ${dg-do-what} 0] run] } {
# For 'dg-do run', it additionally depends on runtime support.
# (If not supported, we don't try to demote 'run' to 'link',


[gcc/devel/omp/gcc-14] Merge commit 'f2ab2de88082d8c52bded3725aa78610085e072c'; commit 'a01aafa5002c57e5897d006a6bba72c5b31

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:0a8d393eafd0c8b04a96ca2b631f48353fa7154c

commit 0a8d393eafd0c8b04a96ca2b631f48353fa7154c
Merge: 947fe06c30a1 f2ab2de88082 a01aafa5002c
Author: Thomas Schwinge 
Date:   Thu Feb 27 11:13:15 2025 +0100

Merge commit 'f2ab2de88082d8c52bded3725aa78610085e072c'; commit 
'a01aafa5002c57e5897d006a6bba72c5b313e422' into HEAD

Diff:

 gcc/c/c-parser.cc  |  23 +-
 gcc/c/c-typeck.cc  |  81 ++-
 gcc/config/gcn/gcn-tree.cc | 623 +++--
 gcc/config/nvptx/nvptx.cc  | 423 --
 gcc/cp/parser.cc   |  13 +-
 gcc/cp/semantics.cc|  77 +++
 gcc/fortran/openmp.cc  | 200 +--
 gcc/fortran/trans-openmp.cc| 171 +-
 gcc/gimplify.cc|  44 +-
 gcc/match.pd   |  60 +-
 gcc/omp-low.cc | 446 +--
 gcc/omp-oacc-neuter-broadcast.cc   | 124 +++-
 gcc/omp-offload.cc | 173 +-
 gcc/omp-offload.h  |  10 +
 gcc/testsuite/c-c++-common/goacc/readonly-2.c  |   4 +-
 gcc/testsuite/c-c++-common/goacc/reduction-11.c|  81 +++
 gcc/testsuite/c-c++-common/goacc/reduction-12.c|  60 ++
 gcc/testsuite/c-c++-common/goacc/reduction-13.c|  60 ++
 gcc/testsuite/c-c++-common/goacc/reduction-14.c|  46 ++
 gcc/testsuite/c-c++-common/goacc/reduction-15.c|  51 ++
 gcc/testsuite/c-c++-common/goacc/reduction-16.c|  30 +
 gcc/testsuite/c-c++-common/goacc/reduction-9.c |  18 +-
 gcc/testsuite/g++.dg/goacc/reductions-1.C  | 108 ++--
 gcc/testsuite/gcc.dg/tree-ssa/pr114760-1.c |  69 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr114760-2.c |  20 +
 .../gfortran.dg/goacc/array-reduction.f90  |  47 +-
 .../gfortran.dg/goacc/enter-exit-data-2.f90|   8 +-
 gcc/testsuite/gfortran.dg/goacc/finalize-1.f   |   4 +-
 .../gfortran.dg/goacc/kernels-decompose-1.f95  |  10 +-
 gcc/testsuite/gfortran.dg/goacc/pr70828.f90|   2 +-
 gcc/testsuite/gfortran.dg/goacc/reduction.f95  | 176 +++---
 .../gfortran.dg/gomp/target-enter-exit-data.f90|   8 +-
 gcc/tree-loop-distribution.cc  |  20 +
 gcc/tree-ssa-loop-ivopts.cc|   2 +
 gcc/tree-ssa-loop-niter.cc |  56 +-
 gcc/tree.h |  13 +
 .../libgomp.oacc-c-c++-common/reduction-arrays-1.c |  69 +++
 .../libgomp.oacc-c-c++-common/reduction-arrays-2.c |  91 +++
 .../libgomp.oacc-c-c++-common/reduction-arrays-3.c |  90 +++
 .../libgomp.oacc-c-c++-common/reduction-arrays-4.c |  91 +++
 .../libgomp.oacc-c-c++-common/reduction-arrays-5.c |  89 +++
 .../reduction-structs-1.c  | 121 
 .../libgomp.oacc-c-c++-common/reduction.h  |  52 ++
 .../libgomp.oacc-fortran/reduction-10.f90  | 598 
 .../libgomp.oacc-fortran/reduction-11.f90  | 424 ++
 .../libgomp.oacc-fortran/reduction-12.f90  | 424 ++
 .../libgomp.oacc-fortran/reduction-13.f90  | 134 +
 .../libgomp.oacc-fortran/reduction-14.f90  |  68 +++
 .../libgomp.oacc-fortran/reduction-15.f90  |  98 
 .../libgomp.oacc-fortran/reduction-16.f90  |  99 
 50 files changed, 5317 insertions(+), 492 deletions(-)


[gcc/devel/omp/gcc-14] BPF, nvptx: Standardize on 'sorry, unimplemented: dynamic stack allocation not supported'

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:145de77274fb23a70d0cf400eb0b3ff4e41c5fd9

commit 145de77274fb23a70d0cf400eb0b3ff4e41c5fd9
Author: Thomas Schwinge 
Date:   Fri Feb 21 11:21:08 2025 +0100

BPF, nvptx: Standardize on 'sorry, unimplemented: dynamic stack allocation 
not supported'

... instead of BPF: 'error: BPF does not support dynamic stack allocation', 
and
nvptx: 'sorry, unimplemented: target cannot support alloca'.

gcc/
* config/bpf/bpf.md (define_expand "allocate_stack"): Emit
'sorry, unimplemented: dynamic stack allocation not supported'.
* config/nvptx/nvptx.md (define_expand "allocate_stack")
[!TARGET_SOFT_STACK && !(TARGET_PTX_7_3 && TARGET_SM52)]: Likewise.
gcc/testsuite/
* gcc.target/bpf/diag-alloca-1.c: Adjust 'dg-message'.
* gcc.target/bpf/diag-alloca-2.c: Likewise.
* gcc.target/nvptx/alloca-1-O0-sm_30.c: Likewise.
* gcc.target/nvptx/alloca-2-O1-sm_30.c: Likewise.
* gcc.target/nvptx/vla-1-O0-sm_30.c: Likewise.
* lib/target-supports.exp (proc check_effective_target_alloca):
Adjust comment.

(cherry picked from commit 2abc942fd486be217de1ba0282a3dc8e21d599aa)

Diff:
---
 gcc/ChangeLog.omp  | 10 ++
 gcc/config/bpf/bpf.md  |  5 ++---
 gcc/config/nvptx/nvptx.md  |  2 +-
 gcc/testsuite/ChangeLog.omp| 13 +
 gcc/testsuite/gcc.target/bpf/diag-alloca-1.c   |  3 ++-
 gcc/testsuite/gcc.target/bpf/diag-alloca-2.c   |  4 +++-
 gcc/testsuite/gcc.target/nvptx/alloca-1-O0-sm_30.c |  2 +-
 gcc/testsuite/gcc.target/nvptx/alloca-2-O1-sm_30.c |  2 +-
 gcc/testsuite/gcc.target/nvptx/vla-1-O0-sm_30.c|  2 +-
 gcc/testsuite/lib/target-supports.exp  |  2 +-
 10 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index e551fa81a6dc..f46a06d4e1ed 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,13 @@
+2025-02-27  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-02-22  Thomas Schwinge  
+
+   * config/bpf/bpf.md (define_expand "allocate_stack"): Emit
+   'sorry, unimplemented: dynamic stack allocation not supported'.
+   * config/nvptx/nvptx.md (define_expand "allocate_stack")
+   [!TARGET_SOFT_STACK && !(TARGET_PTX_7_3 && TARGET_SM52)]: Likewise.
+
 2025-02-18  Thomas Schwinge  
 
Backported from trunk:
diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md
index 95859328d254..57101261c2b2 100644
--- a/gcc/config/bpf/bpf.md
+++ b/gcc/config/bpf/bpf.md
@@ -121,12 +121,11 @@
   [(match_operand:DI 0 "general_operand" "")
(match_operand:DI 1 "general_operand" "")]
   ""
-  "
 {
-  error (\"BPF does not support dynamic stack allocation\");
+  sorry ("dynamic stack allocation not supported");
   emit_insn (gen_nop ());
   DONE;
-}")
+})
 
  Arithmetic/Logical
 
diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index a9c7a6d6924e..c231c7ea0067 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -1698,7 +1698,7 @@
 emit_insn (gen_nvptx_alloca (Pmode, operands[0], operands[1]));
   else if (!TARGET_SOFT_STACK)
 {
-  sorry ("target cannot support alloca");
+  sorry ("dynamic stack allocation not supported");
   emit_insn (gen_nop ());
 }
   else if (TARGET_SOFT_STACK)
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 3fea26738e9e..230ec62f80ee 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,16 @@
+2025-02-27  Thomas Schwinge  
+
+   Backported from trunk:
+   2025-02-22  Thomas Schwinge  
+
+   * gcc.target/bpf/diag-alloca-1.c: Adjust 'dg-message'.
+   * gcc.target/bpf/diag-alloca-2.c: Likewise.
+   * gcc.target/nvptx/alloca-1-O0-sm_30.c: Likewise.
+   * gcc.target/nvptx/alloca-2-O1-sm_30.c: Likewise.
+   * gcc.target/nvptx/vla-1-O0-sm_30.c: Likewise.
+   * lib/target-supports.exp (proc check_effective_target_alloca):
+   Adjust comment.
+
 2025-02-18  Thomas Schwinge  
 
Backported from trunk:
diff --git a/gcc/testsuite/gcc.target/bpf/diag-alloca-1.c 
b/gcc/testsuite/gcc.target/bpf/diag-alloca-1.c
index 0406f2c35958..e549cab84caf 100644
--- a/gcc/testsuite/gcc.target/bpf/diag-alloca-1.c
+++ b/gcc/testsuite/gcc.target/bpf/diag-alloca-1.c
@@ -3,7 +3,8 @@
 int
 foo (int x)
 {
-  int *p = __builtin_alloca (x); /* { dg-error "support" } */
+  int *p = __builtin_alloca (x);
+  /* { dg-message {sorry, unimplemented: dynamic stack allocation not 
supported} {} { target *-*-* } .-1 } */
 
   return p[2];
 }
diff --git a/gcc/testsuite/gcc.target/bpf/diag-alloca-2.c 
b/gcc/testsuite/gcc.target/bpf/diag-alloca-2.c
index ef7170b2c3d3..b1084bf57268 100644
--- a/gcc/testsuite/gcc.target/bpf/diag-alloca-2.c
+++ b/gcc/testsuite/gcc.target/bpf/d

[gcc/devel/omp/gcc-14] Gracefully handle the case that 'gcc/testsuite/lib/gcc-dg.exp:find-dg-do-what' has not been called (

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:eb9cbd22f917aaa522bdb1d825ad6119e0ab196d

commit eb9cbd22f917aaa522bdb1d825ad6119e0ab196d
Author: Thomas Schwinge 
Date:   Fri Feb 21 21:54:59 2025 +0100

Gracefully handle the case that 
'gcc/testsuite/lib/gcc-dg.exp:find-dg-do-what' has not been called (indirectly) 
from 'dg-test'

No change in behavior intended.

gcc/testsuite/
* lib/gcc-dg.exp (find-dg-do-what): Gracefully handle the case
that we've not be called (indirectly) from 'dg-test'.
* lib/target-supports.exp (check_effective_target_stack_size)
(check_effective_target_alloca): Catch this.

(cherry picked from commit e8e228acffe382f003a7f2ca37c068a5e0c74df4)

Diff:
---
 gcc/testsuite/ChangeLog.omp   | 8 
 gcc/testsuite/lib/gcc-dg.exp  | 6 +-
 gcc/testsuite/lib/target-supports.exp | 6 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index d416d476a6d3..1316b67196ad 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -3,6 +3,14 @@
Backported from trunk:
2025-02-22  Thomas Schwinge  
 
+   * lib/gcc-dg.exp (find-dg-do-what): Gracefully handle the case
+   that we've not be called (indirectly) from 'dg-test'.
+   * lib/target-supports.exp (check_effective_target_stack_size)
+   (check_effective_target_alloca): Catch this.
+
+   Backported from trunk:
+   2025-02-22  Thomas Schwinge  
+
* lib/gcc-dg.exp (proc find-dg-do-what): New.
* lib/target-supports.exp (check_effective_target_stack_size)
(check_effective_target_alloca): Use it.
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index ffb596d80b88..87c263900ce5 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -1457,8 +1457,9 @@ set dg_runtest_extra_prunes ""
 # the caller of 'find-dg-do-what' may maintain a local 'dg-do-what' variable
 # without interfering with this search.
 proc find-dg-do-what { } {
+set level [info level]
 set lookup_level 2
-while true {
+while { $lookup_level <= $level } {
upvar $lookup_level dg-do-what dg-do-what
if { [info exists dg-do-what] } {
verbose "find-dg-do-what: found 'dg-do-what' at level 
$lookup_level: ${dg-do-what}" 2
@@ -1466,4 +1467,7 @@ proc find-dg-do-what { } {
}
incr lookup_level
 }
+# We've not be called (indirectly) from 'dg-test'.
+verbose "find-dg-do-what: have not found 'dg-do-what'" 2
+return [list]
 }
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 803a26b334cf..8518909e5167 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -652,6 +652,9 @@ proc check_effective_target_stack_size { } {
 # For nvptx target, stack size limits are relevant for execution only.
 if { [istarget nvptx-*-*] } {
set dg-do-what [find-dg-do-what]
+   if { ![llength ${dg-do-what}] } {
+   error "unexpected call stack"
+   }
if { ![string equal [lindex ${dg-do-what} 0] run] } {
return 0
}
@@ -999,6 +1002,9 @@ proc check_effective_target_alloca {} {
}
 
set dg-do-what [find-dg-do-what]
+   if { ![llength ${dg-do-what}] } {
+   error "unexpected call stack"
+   }
if { [string equal [lindex ${dg-do-what} 0] run] } {
# For 'dg-do run', it additionally depends on runtime support.
# (If not supported, we don't try to demote 'run' to 'link',


[gcc/devel/omp/gcc-14] OpenMP/Fortran: extend 'adjust_args' clause, fixes for it and declare variant [PR115271]: avoid 'err

2025-02-27 Thread Thomas Schwinge via Gcc-cvs
https://gcc.gnu.org/g:f2ab2de88082d8c52bded3725aa78610085e072c

commit f2ab2de88082d8c52bded3725aa78610085e072c
Author: Thomas Schwinge 
Date:   Sun Feb 23 10:34:39 2025 +0100

OpenMP/Fortran: extend 'adjust_args' clause, fixes for it and declare 
variant [PR115271]: avoid 'error: variable ‘saved_loc2’ set but not used 
[-Werror=unused-but-set-variable]'

[...]/source-gcc/gcc/fortran/openmp.cc: In function ‘match 
gfc_match_omp_declare_variant()’:
[...]/source-gcc/gcc/fortran/openmp.cc:7127:25: error: variable 
‘saved_loc2’ set but not used [-Werror=unused-but-set-variable]
 7127 |   locus saved_loc2 = gfc_current_locus;
  | ^~

Fix-up for OG14 commit e0246616020e95e74afa9d504c8848e6e905fab4
"OpenMP/Fortran: extend 'adjust_args' clause, fixes for it and declare 
variant [PR115271]".

PR fortran/115271
gcc/fortran/
* openmp.cc (gfc_match_omp_declare_variant): Remove
'locus saved_loc2'.

Diff:
---
 gcc/fortran/openmp.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 16b255ec1062..421e5276d339 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7124,7 +7124,6 @@ gfc_match_omp_declare_variant (void)
  else
need_range = false;
 
- locus saved_loc2 = gfc_current_locus;
  gfc_gobble_whitespace ();
  char c = gfc_peek_ascii_char ();
  if (c == '+' || c == '-')


[gcc r15-7727] testsuite: arm: Avoid incremental link warnings in pr61123-enum-size

2025-02-27 Thread Richard Earnshaw via Gcc-cvs
https://gcc.gnu.org/g:767a7a06915651da173b6751959a47487351ed3a

commit r15-7727-g767a7a06915651da173b6751959a47487351ed3a
Author: Richard Earnshaw 
Date:   Thu Feb 27 15:11:47 2025 +

testsuite: arm: Avoid incremental link warnings in pr61123-enum-size

This test uses incremental linking, but that can generate warnings if
the LTO step contains a mix of LTO and non-LTO object files (this can
happen when there's a testglue file that is normally included during
linking).

We don't care about the testglue, though, so just tell the LTO
optimizer to generate nolto-rel output, which is what it is falling
back to anyway.

gcc/testsuite:
* gcc.target/arm/lto/pr61123-enum-size_0.c: (dg-lto-options) Move
linker related options to ...
(dg-extra-ld-options): ... here.  Add -flinker-output=nolto-rel.

Diff:
---
 gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c 
b/gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
index c23f9d857605..4ccbeb39f43f 100644
--- a/gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
+++ b/gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
@@ -1,5 +1,6 @@
 /* { dg-lto-do link } */
-/* { dg-lto-options { { -fno-short-enums -Wl,-Ur,--no-enum-size-warning -Os 
-nostdlib -flto } } } */
+/* { dg-lto-options { { -fno-short-enums -Os -flto } } } */
+/* { dg-extra-ld-options "-flinker-output=nolto-rel 
-Wl,-Ur,--no-enum-size-warning -nostdlib" } */
 
 #include 


[gcc r15-7728] c++: too many errors with sneaky template [PR118516]

2025-02-27 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:3605e057040ead00c072c20bfbb8f26636f8295e

commit r15-7728-g3605e057040ead00c072c20bfbb8f26636f8295e
Author: Marek Polacek 
Date:   Thu Feb 20 14:35:25 2025 -0500

c++: too many errors with sneaky template [PR118516]

Since C++20 P0846, a name followed by a < can be treated as a template-name
even though name lookup did not find a template-name.  That happens
in this test with "i < foo ()":

  for (int id = 0; i < foo(); ++id);

and results in a raft of errors about non-constant foo().  The problem
is that the require_potential_constant_expression call in
cp_parser_template_argument emits errors even when we're parsing
tentatively.  So we repeat the error when we're trying to parse
as a nested-name-specifier, type-name, etc.

Guarding the call with !cp_parser_uncommitted_to_tentative_parse_p would
mean that require_potential_constant_expression never gets called.  But
we don't need the call at all as far as I can tell.  Stuff like

  template struct S { };
  int foo () { return 4; }
  void
  g ()
  {
S s;
  }

gets diagnosed in convert_nontype_argument.  In fact, with this patch,
we only emit "call to non-constexpr function" once.  (That is, in C++17
only; C++14 uses a different path.)

PR c++/118516

gcc/cp/ChangeLog:

* parser.cc (cp_parser_template_argument): Don't call
require_potential_constant_expression.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/fn-template11.C:
* g++.dg/template/fn-template1.C: New test.
* g++.dg/template/fn-template2.C: New test.

Diff:
---
 gcc/cp/parser.cc |  1 -
 gcc/testsuite/g++.dg/cpp2a/fn-template11.C   |  2 +-
 gcc/testsuite/g++.dg/template/fn-template1.C | 12 
 gcc/testsuite/g++.dg/template/fn-template2.C |  9 +
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9f619b111673..69c27aa7b6e3 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -20315,7 +20315,6 @@ cp_parser_template_argument (cp_parser* parser)
   /* With C++17 generalized non-type template arguments we need to handle
 lvalue constant expressions, too.  */
   argument = cp_parser_assignment_expression (parser);
-  require_potential_constant_expression (argument);
 }
 
   if (!maybe_type_id)
diff --git a/gcc/testsuite/g++.dg/cpp2a/fn-template11.C 
b/gcc/testsuite/g++.dg/cpp2a/fn-template11.C
index 1a6b68829002..ca25403f39b6 100644
--- a/gcc/testsuite/g++.dg/cpp2a/fn-template11.C
+++ b/gcc/testsuite/g++.dg/cpp2a/fn-template11.C
@@ -7,5 +7,5 @@ int nonconst ();
 int foo ()
 {
   return blah < // { dg-error "not declared" }
-nonconst (), nonconst (); // { dg-error "call to non-.constexpr. function" 
}
+nonconst (), nonconst ();
 }
diff --git a/gcc/testsuite/g++.dg/template/fn-template1.C 
b/gcc/testsuite/g++.dg/template/fn-template1.C
new file mode 100644
index ..14b98836880a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/fn-template1.C
@@ -0,0 +1,12 @@
+// PR c++/118516
+// { dg-do compile }
+// Like cpp2a/fn-template11.C but with blah declared.
+
+int nonconst ();
+
+int foo ()
+{
+  int blah = 20;
+  return blah <
+nonconst (), nonconst ();
+}
diff --git a/gcc/testsuite/g++.dg/template/fn-template2.C 
b/gcc/testsuite/g++.dg/template/fn-template2.C
new file mode 100644
index ..c7c31dd9b302
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/fn-template2.C
@@ -0,0 +1,9 @@
+// PR c++/118516
+// { dg-do compile }
+
+int foo();
+int main()
+{
+for (int id = 0; i <   // { dg-error "not declared in this 
scope" }
+foo(); ++id); // { dg-bogus "call to non-.constexpr." }
+}


[gcc r15-7723] Makefile: Link in {simple, lazy}-diagnostic-path.o [PR116143]

2025-02-27 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:fb684f1654bdc831e17a5e538bdfee63ec0a5e4b

commit r15-7723-gfb684f1654bdc831e17a5e538bdfee63ec0a5e4b
Author: Jakub Jelinek 
Date:   Thu Feb 27 08:50:47 2025 +0100

Makefile: Link in {simple,lazy}-diagnostic-path.o [PR116143]

Some of the plugin.exp tests FAIL in --enable-checking=release builds while
they succeed in --enable-checking=yes builds.
Initially I've changed some small simple out of line methods into inline 
ones
in the header, but the tests kept failing, just with different symbols.

The _ZN22simple_diagnostic_path9add_eventEmP9tree_nodeiPKcz symbol (and the
others too) are normally emitted in simple-diagnostic-path.o, it isn't some
fancy C++ optimization of classes with final method or LTO optimization.

The problem is that simple-diagnostic-path.o is like most objects added into
libbackend.a and we then link libbackend.a without -Wl,--whole-archive ...
-Wl,--no-whole-archive around it (and can't easily, not all system compilers
and linkers will support that).
With --enable-checking=yes simple-diagnostic-path.o is pulled in, because
selftest-run-tests.o calls simple_diagnostic_path_cc_tests and so
simple-diagnostic-path.o is linked in.
With --enable-checking=release self-tests aren't done and nothing links in
simple-diagnostic-path.o, because nothing in the compiler proper needs
anything from it, only the plugin tests.

Using -Wl,-M on cc1 linking, I see that in --enable-checking=release
build
analyzer/analyzer-selftests.o
digraph.o
dwarf2codeview.o
fibonacci_heap.o
function-tests.o
hash-map-tests.o
hash-set-tests.o
hw-doloop.o
insn-peep.o
lazy-diagnostic-path.o
options-urls.o
ordered-hash-map-tests.o
pair-fusion.o
print-rtl-function.o
resource.o
rtl-tests.o
selftest-rtl.o
selftest-run-tests.o
simple-diagnostic-path.o
splay-tree-utils.o
typed-splay-tree.o
vmsdbgout.o
aren't linked into cc1 (the *test* for obvious reasons of not doing
selftests, pair-fusion.o because it is aarch64 specific, hw-doloop.o because
x86 doesn't have doloop opts, vmsdbgout.o because not on VMS).

So, the question is if and what from digraph.o, fibinacci_heap.o,
hw-doloop.o, insn-peep.o, lazy-diagnostic-path.o, options-urls.o,
pair-fusion.o, print-rtl-function.o, resource.o, simple-diagnostic-path.o,
splay-tree-utils.o, typed-splay-tree.o are supposed to be part of the
plugin API if anything and how we arrange for those to be linked in when
plugins are enabled.

The following patch just adds unconditionally the
{simple,lazy}-diagnostic-path.o objects to the link lines before 
libbackend.a
so that their content is available to plugin users.

2025-02-27  Jakub Jelinek  

PR testsuite/116143
* Makefile.in (EXTRA_BACKEND_OBJS): New variable.
(BACKEND): Use it before libbackend.a.

Diff:
---
 gcc/Makefile.in | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index c159825e62c8..10a42cb1dd7d 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1904,8 +1904,12 @@ ifeq (@enable_libgdiagnostics@,yes)
 ALL_HOST_OBJS += $(libgdiagnostics_OBJS) $(SARIF_REPLAY_OBJS)
 endif
 
-BACKEND = libbackend.a main.o libcommon-target.a libcommon.a \
-   $(CPPLIB) $(LIBDECNUMBER)
+# libbackend.a objs that might not be in some cases linked into the compiler,
+# yet they are supposed to be part of the plugin ABI.  See PR116143.
+EXTRA_BACKEND_OBJS = simple-diagnostic-path.o lazy-diagnostic-path.o
+
+BACKEND = $(EXTRA_BACKEND_OBJS) libbackend.a main.o libcommon-target.a \
+   libcommon.a $(CPPLIB) $(LIBDECNUMBER)
 
 # This is defined to "yes" if Tree checking is enabled, which roughly means
 # front-end checking.


[gcc r15-7725] i386: Treat Granite Rapids/Granite Rapids-D/Diamond Rapids similar as Sapphire Rapids in x86-tune.de

2025-02-27 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:44c4a72061e86259d3defd3d1c7911f453043e3c

commit r15-7725-g44c4a72061e86259d3defd3d1c7911f453043e3c
Author: Haochen Jiang 
Date:   Wed Feb 26 11:28:45 2025 +0800

i386: Treat Granite Rapids/Granite Rapids-D/Diamond Rapids similar as 
Sapphire Rapids in x86-tune.def

Since GNR, GNR-D, DMR are both P-core based, we should treat them
just like SPR for now.

gcc/ChangeLog:

* config/i386/x86-tune.def
(X86_TUNE_DEST_FALSE_DEP_FOR_GLC): Add GNR, GNR-D, DMR.
(X86_TUNE_AVOID_256FMA_CHAINS): Ditto.
(X86_TUNE_AVX512_MOVE_BY_PIECES): Ditto.
(X86_TUNE_AVX512_STORE_BY_PIECES): Ditto.

Diff:
---
 gcc/config/i386/x86-tune.def | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/x86-tune.def b/gcc/config/i386/x86-tune.def
index df7b4ed22bc8..0bdad7234a6a 100644
--- a/gcc/config/i386/x86-tune.def
+++ b/gcc/config/i386/x86-tune.def
@@ -87,7 +87,8 @@ DEF_TUNE (X86_TUNE_SSE_PARTIAL_REG_CONVERTS_DEPENDENCY,
several insns to break false dependency on the dest register for GLC
micro-architecture.  */
 DEF_TUNE (X86_TUNE_DEST_FALSE_DEP_FOR_GLC,
- "dest_false_dep_for_glc", m_SAPPHIRERAPIDS | m_CORE_HYBRID
+ "dest_false_dep_for_glc", m_SAPPHIRERAPIDS | m_GRANITERAPIDS
+ | m_GRANITERAPIDS_D | m_DIAMONDRAPIDS | m_CORE_HYBRID
  | m_CORE_ATOM)
 
 /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
@@ -527,7 +528,8 @@ DEF_TUNE (X86_TUNE_AVOID_128FMA_CHAINS, "avoid_fma_chains", 
m_ZNVER
smaller FMA chain.  */
 DEF_TUNE (X86_TUNE_AVOID_256FMA_CHAINS, "avoid_fma256_chains",
  m_ZNVER2 | m_ZNVER3 | m_ZNVER4 | m_ZNVER5 | m_CORE_HYBRID
- | m_SAPPHIRERAPIDS | m_CORE_ATOM | m_GENERIC)
+ | m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_DIAMONDRAPIDS | m_CORE_ATOM | m_GENERIC)
 
 /* X86_TUNE_AVOID_512FMA_CHAINS: Avoid creating loops with tight 512bit or
smaller FMA chain.  */
@@ -594,12 +596,14 @@ DEF_TUNE (X86_TUNE_AVX256_STORE_BY_PIECES, 
"avx256_store_by_pieces",
 /* X86_TUNE_AVX512_MOVE_BY_PIECES: Optimize move_by_pieces with 512-bit
AVX instructions.  */
 DEF_TUNE (X86_TUNE_AVX512_MOVE_BY_PIECES, "avx512_move_by_pieces",
- m_SAPPHIRERAPIDS | m_ZNVER4 | m_ZNVER5)
+ m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_DIAMONDRAPIDS | m_ZNVER4 | m_ZNVER5)
 
 /* X86_TUNE_AVX512_STORE_BY_PIECES: Optimize store_by_pieces with 512-bit
AVX instructions.  */
 DEF_TUNE (X86_TUNE_AVX512_STORE_BY_PIECES, "avx512_store_by_pieces",
- m_SAPPHIRERAPIDS | m_ZNVER4 | m_ZNVER5)
+ m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_DIAMONDRAPIDS | m_ZNVER4 | m_ZNVER5)
 
 /* X86_TUNE_AVX512_TWO_EPILOGUES: Use two vector epilogues for 512-bit
vectorized loops.  */


[gcc r14-11345] i386: Treat Granite Rapids/Granite Rapids-D similar as Sapphire Rapids in x86-tune.def

2025-02-27 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:ba488a332ad171eff17c1f135c111c5730f4ce25

commit r14-11345-gba488a332ad171eff17c1f135c111c5730f4ce25
Author: Haochen Jiang 
Date:   Wed Feb 26 11:28:45 2025 +0800

i386: Treat Granite Rapids/Granite Rapids-D similar as Sapphire Rapids in 
x86-tune.def

Since GNR, GNR-D are both P-core based, we should treat them
just like SPR for now.

gcc/ChangeLog:

* config/i386/x86-tune.def
(X86_TUNE_DEST_FALSE_DEP_FOR_GLC): Add GNR, GNR-D.
(X86_TUNE_AVOID_256FMA_CHAINS): Ditto.
(X86_TUNE_AVX512_MOVE_BY_PIECES): Ditto.
(X86_TUNE_AVX512_STORE_BY_PIECES): Ditto.

Diff:
---
 gcc/config/i386/x86-tune.def | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/config/i386/x86-tune.def b/gcc/config/i386/x86-tune.def
index ec8de3144a8c..39431e07e69c 100644
--- a/gcc/config/i386/x86-tune.def
+++ b/gcc/config/i386/x86-tune.def
@@ -87,8 +87,8 @@ DEF_TUNE (X86_TUNE_SSE_PARTIAL_REG_CONVERTS_DEPENDENCY,
several insns to break false dependency on the dest register for GLC
micro-architecture.  */
 DEF_TUNE (X86_TUNE_DEST_FALSE_DEP_FOR_GLC,
- "dest_false_dep_for_glc", m_SAPPHIRERAPIDS | m_CORE_HYBRID
- | m_CORE_ATOM)
+ "dest_false_dep_for_glc", m_SAPPHIRERAPIDS | m_GRANITERAPIDS
+ | m_GRANITERAPIDS_D | m_CORE_HYBRID | m_CORE_ATOM)
 
 /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
are resolved on SSE register parts instead of whole registers, so we may
@@ -529,7 +529,8 @@ DEF_TUNE (X86_TUNE_AVOID_128FMA_CHAINS, "avoid_fma_chains", 
m_ZNVER
smaller FMA chain.  */
 DEF_TUNE (X86_TUNE_AVOID_256FMA_CHAINS, "avoid_fma256_chains",
  m_ZNVER2 | m_ZNVER3 | m_ZNVER4 | m_ZNVER5 | m_CORE_HYBRID
- | m_SAPPHIRERAPIDS | m_CORE_ATOM | m_GENERIC)
+ | m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_CORE_ATOM | m_GENERIC)
 
 /* X86_TUNE_AVOID_512FMA_CHAINS: Avoid creating loops with tight 512bit or
smaller FMA chain.  */
@@ -596,12 +597,14 @@ DEF_TUNE (X86_TUNE_AVX256_STORE_BY_PIECES, 
"avx256_store_by_pieces",
 /* X86_TUNE_AVX512_MOVE_BY_PIECES: Optimize move_by_pieces with 512-bit
AVX instructions.  */
 DEF_TUNE (X86_TUNE_AVX512_MOVE_BY_PIECES, "avx512_move_by_pieces",
- m_SAPPHIRERAPIDS | m_ZNVER4 | m_ZNVER5)
+ m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_ZNVER4 | m_ZNVER5)
 
 /* X86_TUNE_AVX512_STORE_BY_PIECES: Optimize store_by_pieces with 512-bit
AVX instructions.  */
 DEF_TUNE (X86_TUNE_AVX512_STORE_BY_PIECES, "avx512_store_by_pieces",
- m_SAPPHIRERAPIDS | m_ZNVER4 | m_ZNVER5)
+ m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_ZNVER4 | m_ZNVER5)
 
 /*/
 /*/


[gcc r13-9401] i386: Treat Granite Rapids/Granite Rapids-D similar as Sapphire Rapids in x86-tune.def

2025-02-27 Thread Haochen Jiang via Gcc-cvs
https://gcc.gnu.org/g:bc3fd553305933e5dd504790781aace3b0d0bf6f

commit r13-9401-gbc3fd553305933e5dd504790781aace3b0d0bf6f
Author: Haochen Jiang 
Date:   Wed Feb 26 11:28:45 2025 +0800

i386: Treat Granite Rapids/Granite Rapids-D similar as Sapphire Rapids in 
x86-tune.def

Since GNR, GNR-D are both P-core based, we should treat them
just like SPR for now.

gcc/ChangeLog:

* config/i386/x86-tune.def
(X86_TUNE_DEST_FALSE_DEP_FOR_GLC): Add GNR, GNR-D.
(X86_TUNE_AVOID_256FMA_CHAINS): Ditto.
(X86_TUNE_AVX512_MOVE_BY_PIECES): Ditto.
(X86_TUNE_AVX512_STORE_BY_PIECES): Ditto.

Diff:
---
 gcc/config/i386/x86-tune.def | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/gcc/config/i386/x86-tune.def b/gcc/config/i386/x86-tune.def
index d5fcf5ce971d..cc6e1d51e943 100644
--- a/gcc/config/i386/x86-tune.def
+++ b/gcc/config/i386/x86-tune.def
@@ -87,8 +87,8 @@ DEF_TUNE (X86_TUNE_SSE_PARTIAL_REG_CONVERTS_DEPENDENCY,
several insns to break false dependency on the dest register for GLC
micro-architecture.  */
 DEF_TUNE (X86_TUNE_DEST_FALSE_DEP_FOR_GLC,
- "dest_false_dep_for_glc", m_SAPPHIRERAPIDS | m_ALDERLAKE
- | m_CORE_ATOM)
+ "dest_false_dep_for_glc", m_SAPPHIRERAPIDS | m_GRANITERAPIDS
+ | m_GRANITERAPIDS_D | m_ALDERLAKE | m_CORE_ATOM)
 
 /* X86_TUNE_SSE_SPLIT_REGS: Set for machines where the type and dependencies
are resolved on SSE register parts instead of whole registers, so we may
@@ -521,8 +521,10 @@ DEF_TUNE (X86_TUNE_AVOID_128FMA_CHAINS, 
"avoid_fma_chains", m_ZNVER)
 
 /* X86_TUNE_AVOID_256FMA_CHAINS: Avoid creating loops with tight 256bit or
smaller FMA chain.  */
-DEF_TUNE (X86_TUNE_AVOID_256FMA_CHAINS, "avoid_fma256_chains", m_ZNVER2 | 
m_ZNVER3
- | m_ALDERLAKE | m_SAPPHIRERAPIDS | m_CORE_ATOM | m_GENERIC | m_ZNVER4 
| m_ZNVER5)
+DEF_TUNE (X86_TUNE_AVOID_256FMA_CHAINS, "avoid_fma256_chains",
+ m_ZNVER2 | m_ZNVER3 | m_ALDERLAKE | m_SAPPHIRERAPIDS
+ | m_GRANITERAPIDS | m_GRANITERAPIDS_D | m_CORE_ATOM | m_GENERIC
+ | m_ZNVER4 | m_ZNVER5)
 
 /* X86_TUNE_AVOID_512FMA_CHAINS: Avoid creating loops with tight 512bit or
smaller FMA chain.  */
@@ -589,12 +591,14 @@ DEF_TUNE (X86_TUNE_AVX256_STORE_BY_PIECES, 
"avx256_store_by_pieces",
 /* X86_TUNE_AVX512_MOVE_BY_PIECES: Optimize move_by_pieces with 512-bit
AVX instructions.  */
 DEF_TUNE (X86_TUNE_AVX512_MOVE_BY_PIECES, "avx512_move_by_pieces",
- m_SAPPHIRERAPIDS | m_ZNVER4 | m_ZNVER5)
+ m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_ZNVER4 | m_ZNVER5)
 
 /* X86_TUNE_AVX512_STORE_BY_PIECES: Optimize store_by_pieces with 512-bit
AVX instructions.  */
 DEF_TUNE (X86_TUNE_AVX512_STORE_BY_PIECES, "avx512_store_by_pieces",
- m_SAPPHIRERAPIDS | m_ZNVER4 | m_ZNVER5)
+ m_SAPPHIRERAPIDS | m_GRANITERAPIDS | m_GRANITERAPIDS_D
+ | m_ZNVER4 | m_ZNVER5)
 
 /*/
 /*/