[gcc r15-7499] s390: Fix s390_valid_shift_count() for TI mode [PR118835]

2025-02-13 Thread Stefan Schulze Frielinghaus via Gcc-cvs
https://gcc.gnu.org/g:ac9806dae30d07ab082ac341fe5646987753adcb

commit r15-7499-gac9806dae30d07ab082ac341fe5646987753adcb
Author: Stefan Schulze Frielinghaus 
Date:   Thu Feb 13 09:13:06 2025 +0100

s390: Fix s390_valid_shift_count() for TI mode [PR118835]

During combine we may end up with

(set (reg:DI 66 [ _6 ])
 (ashift:DI (reg:DI 72 [ x ])
(subreg:QI (and:TI (reg:TI 67 [ _1 ])
   (const_wide_int 0x0aabf))
   15)))

where the shift count operand does not trivially fit the scheme of
address operands.  Reject those operands, especially since
strip_address_mutations() expects expressions of the form
(and ... (const_int ...)) and fails for (and ... (const_wide_int ...)).

Thus, be more strict here and accept only CONST_INT operands.  Done by
replacing immediate_operand() with const_int_operand() which is enough
since the former only additionally checks for LEGITIMATE_PIC_OPERAND_P
and targetm.legitimate_constant_p which are always true for CONST_INT
operands.

While on it, fix indentation of the if block.

gcc/ChangeLog:

PR target/118835
* config/s390/s390.cc (s390_valid_shift_count): Reject shift
count operands which do not trivially fit the scheme of
address operands.

gcc/testsuite/ChangeLog:

* gcc.target/s390/pr118835.c: New test.

Diff:
---
 gcc/config/s390/s390.cc  | 35 ++--
 gcc/testsuite/gcc.target/s390/pr118835.c | 21 +++
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 1d96df49feac..29aef501fdd2 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -3510,26 +3510,31 @@ s390_valid_shift_count (rtx op, HOST_WIDE_INT 
implicit_mask)
 
   /* Check for an and with proper constant.  */
   if (GET_CODE (op) == AND)
-  {
-rtx op1 = XEXP (op, 0);
-rtx imm = XEXP (op, 1);
+{
+  rtx op1 = XEXP (op, 0);
+  rtx imm = XEXP (op, 1);
 
-if (GET_CODE (op1) == SUBREG && subreg_lowpart_p (op1))
-  op1 = XEXP (op1, 0);
+  if (GET_CODE (op1) == SUBREG && subreg_lowpart_p (op1))
+   op1 = XEXP (op1, 0);
 
-if (!(register_operand (op1, GET_MODE (op1)) || GET_CODE (op1) == PLUS))
-  return false;
+  if (!(register_operand (op1, GET_MODE (op1)) || GET_CODE (op1) == PLUS))
+   return false;
 
-if (!immediate_operand (imm, GET_MODE (imm)))
-  return false;
+  /* Accept only CONST_INT as immediates, i.e., reject shift count operands
+which do not trivially fit the scheme of address operands.  Especially
+since strip_address_mutations() expects expressions of the form
+(and ... (const_int ...)) and fails for
+(and ... (const_wide_int ...)).  */
+  if (!const_int_operand (imm, GET_MODE (imm)))
+   return false;
 
-HOST_WIDE_INT val = INTVAL (imm);
-if (implicit_mask > 0
-   && (val & implicit_mask) != implicit_mask)
-  return false;
+  HOST_WIDE_INT val = INTVAL (imm);
+  if (implicit_mask > 0
+ && (val & implicit_mask) != implicit_mask)
+   return false;
 
-op = op1;
-  }
+  op = op1;
+}
 
   /* Check the rest.  */
   return s390_decompose_addrstyle_without_index (op, NULL, NULL);
diff --git a/gcc/testsuite/gcc.target/s390/pr118835.c 
b/gcc/testsuite/gcc.target/s390/pr118835.c
new file mode 100644
index ..1ca6cd95543b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr118835.c
@@ -0,0 +1,21 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2" } */
+
+/* During combine we may end up with patterns of the form
+
+   (set (reg:DI 66 [ _6 ])
+(ashift:DI (reg:DI 72 [ x ])
+   (subreg:QI (and:TI (reg:TI 67 [ _1 ])
+  (const_wide_int 0x0aabf))
+  15)))
+
+   which should be rejected since the shift count does not trivially fit the
+   scheme of address operands.  */
+
+long
+test (long x, int y)
+{
+  __int128 z = 0xAABF;
+  z &= y;
+  return x << z;
+}


[gcc r15-7518] c++: Fix mangling of lambas in static member template initializers [PR107741]

2025-02-13 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:12feb78be517472ca941953dce47d6e78e5a17f8

commit r15-7518-g12feb78be517472ca941953dce47d6e78e5a17f8
Author: Nathaniel Shead 
Date:   Fri Jan 31 21:19:45 2025 +1100

c++: Fix mangling of lambas in static member template initializers 
[PR107741]

My fix for this issue in r15-7147 turns out to not be quite sufficient;
static member templates apparently go down a different code path and
need their own handling.

PR c++/107741

gcc/cp/ChangeLog:

* cp-tree.h (is_static_data_member_initialized_in_class):
Declare new predicate.
* decl2.cc (start_initialized_static_member): Push the
TEMPLATE_DECL when appropriate.
(is_static_data_member_initialized_in_class): New predicate.
(finish_initialized_static_member): Use it.
* lambda.cc (record_lambda_scope): Likewise.
* parser.cc (cp_parser_init_declarator): Start the member decl
early for static members so that lambda scope is set.
(cp_parser_template_declaration_after_parameters): Don't
register in-class initialized static members here.

gcc/testsuite/ChangeLog:

* g++.dg/abi/lambda-ctx2-19.C: Add tests for template members.
* g++.dg/abi/lambda-ctx2-19vs20.C: Likewise.
* g++.dg/abi/lambda-ctx2-20.C: Likewise.
* g++.dg/abi/lambda-ctx2.h: Likewise.
* g++.dg/cpp0x/static-member-init-1.C: Likewise.

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

Diff:
---
 gcc/cp/cp-tree.h  |  1 +
 gcc/cp/decl2.cc   | 33 ++--
 gcc/cp/lambda.cc  |  5 +--
 gcc/cp/parser.cc  | 46 +--
 gcc/testsuite/g++.dg/abi/lambda-ctx2-19.C |  3 ++
 gcc/testsuite/g++.dg/abi/lambda-ctx2-19vs20.C |  3 ++
 gcc/testsuite/g++.dg/abi/lambda-ctx2-20.C |  3 ++
 gcc/testsuite/g++.dg/abi/lambda-ctx2.h| 16 
 gcc/testsuite/g++.dg/cpp0x/static-member-init-1.C |  5 +++
 9 files changed, 96 insertions(+), 19 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ec976928f5fb..b7749eb2b327 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7250,6 +7250,7 @@ extern tree grokbitfield (const cp_declarator *, 
cp_decl_specifier_seq *,
  tree, tree, tree);
 extern tree start_initialized_static_member(const cp_declarator *,
 cp_decl_specifier_seq *, tree);
+extern bool is_static_data_member_initialized_in_class (tree decl);
 extern void finish_initialized_static_member   (tree, tree, tree);
 extern tree splice_template_attributes (tree *, tree);
 extern bool any_dependent_type_attributes_p(tree);
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index aa9ebca12f8f..0217a8e24740 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1295,6 +1295,8 @@ start_initialized_static_member (const cp_declarator 
*declarator,
   gcc_checking_assert (VAR_P (value));
 
   DECL_CONTEXT (value) = current_class_type;
+  DECL_INITIALIZED_IN_CLASS_P (value) = true;
+
   if (processing_template_decl)
 {
   value = push_template_decl (value);
@@ -1305,12 +1307,37 @@ start_initialized_static_member (const cp_declarator 
*declarator,
   if (attrlist)
 cplus_decl_attributes (&value, attrlist, 0);
 
-  finish_member_declaration (value);
-  DECL_INITIALIZED_IN_CLASS_P (value) = true;
+  /* When defining a template we need to register the TEMPLATE_DECL.  */
+  tree maybe_template = value;
+  if (template_parm_scope_p ())
+{
+  if (!DECL_TEMPLATE_SPECIALIZATION (value))
+   maybe_template = DECL_TI_TEMPLATE (value);
+  else
+   maybe_template = NULL_TREE;
+}
+  if (maybe_template)
+finish_member_declaration (maybe_template);
 
   return value;
 }
 
+/* Whether DECL is a static data member initialized at the point
+   of declaration within its class.  */
+
+bool
+is_static_data_member_initialized_in_class (tree decl)
+{
+  if (!decl || decl == error_mark_node)
+return false;
+
+  tree inner = STRIP_TEMPLATE (decl);
+  return (inner
+ && VAR_P (inner)
+ && DECL_CLASS_SCOPE_P (inner)
+ && DECL_INITIALIZED_IN_CLASS_P (inner));
+}
+
 /* Finish a declaration prepared with start_initialized_static_member.  */
 
 void
@@ -1318,7 +1345,7 @@ finish_initialized_static_member (tree decl, tree init, 
tree asmspec)
 {
   if (decl == error_mark_node)
 return;
-  gcc_checking_assert (VAR_P (decl));
+  gcc_checking_assert (is_static_data_member_initialized_in_class (decl));
 
   int flags;
   if (init && DIRECT_LIST_INIT_P (init))
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index 2d86e9892f99..c612f4fe1ad0 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -1555,10 +1555,7 @@ record_lambda_scope (t

[gcc r15-7519] c++: Clear lambda scope for unattached member template lambdas

2025-02-13 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:8caf67eea7e1b29a4437f07d13c300d9fdb04827

commit r15-7519-g8caf67eea7e1b29a4437f07d13c300d9fdb04827
Author: Nathaniel Shead 
Date:   Fri Jan 31 23:01:15 2025 +1100

c++: Clear lambda scope for unattached member template lambdas

In r15-7202 we made lambdas between a template parameter scope and a
class/function/initializer be considered TU-local, in lieu of working
out how to mangle them to the succeeding declaration.

I neglected to clear any existing mangling on the template declaration
however; this means that such lambdas can occasionally get a lambda
scope, and will in general inherit the lambda scope of their
instantiation context (whatever that might be).

This patch ensures that the scope is cleared on the template declaration
as well.

gcc/cp/ChangeLog:

* lambda.cc (record_lambda_scope): Clear mangling scope for
otherwise unattached lambdas in class member templates.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-uneval22.C: Add check that the primary
specialisation of the lambda is TU-local.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/lambda.cc | 11 +++
 gcc/testsuite/g++.dg/cpp2a/lambda-uneval22.C |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index c612f4fe1ad0..09898f6746ca 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -1572,6 +1572,17 @@ record_lambda_scope (tree lambda)
}
 }
 
+  /* An otherwise unattached class-scope lambda in a member template
+ should not have a mangling scope, as the mangling scope will not
+ correctly inherit on instantiation.  */
+  tree ctx = TYPE_CONTEXT (closure);
+  if (scope
+  && ctx
+  && CLASS_TYPE_P (ctx)
+  && ctx == TREE_TYPE (scope)
+  && current_template_depth > template_class_depth (ctx))
+scope = NULL_TREE;
+
   LAMBDA_EXPR_EXTRA_SCOPE (lambda) = scope;
   if (scope)
 maybe_key_decl (scope, TYPE_NAME (closure));
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval22.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval22.C
index 9c0e8128f108..1a25a0255fc1 100644
--- a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval22.C
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval22.C
@@ -5,7 +5,7 @@ struct S {
   using T = decltype([]{ return I; });
 
   template 
-  decltype([]{ return I; }) f() { return {}; }
+  decltype([]{ return I; }) f();  // { dg-error "declared using local type" }
 };
 
 void a(S::T<0>*);  // { dg-error "declared using local type" }
@@ -18,4 +18,5 @@ int main() {
   b(nullptr);
   c(nullptr);
   d(nullptr);
+  S{}.f<2>()();
 }


[gcc r15-7520] tree-optimization/90579 - avoid STLF fail by better optimizing

2025-02-13 Thread Richard Biener via Gcc-cvs
https://gcc.gnu.org/g:27653070db35216d5115cc25672fcc6a51203d26

commit r15-7520-g27653070db35216d5115cc25672fcc6a51203d26
Author: Richard Biener 
Date:   Wed Feb 12 14:18:06 2025 +0100

tree-optimization/90579 - avoid STLF fail by better optimizing

For the testcase in question which uses a fold-left vectorized
reduction of a reverse iterating loop we'd need two forwprop
invocations to first bypass the permute emitted for the reverse
iterating loop and then to decompose the vector load that only
feeds element extracts.  The following moves the first transform
to a match.pd pattern and makes sure we fold the element extracts
when the vectorizer emits them so the single forwprop pass can
then pick up the vector load decomposition, avoiding the forwarding
fail that causes.

Moving simplify_bitfield_ref also makes forwprop remove the dead
VEC_PERM_EXPR via the simple-dce it uses - this was also
previously missing.

PR tree-optimization/90579
* tree-ssa-forwprop.cc (simplify_bitfield_ref): Move to
match.pd.
(pass_forwprop::execute): Adjust.
* match.pd (bit_field_ref (vec_perm ...)): New pattern
modeled after simplify_bitfield_ref.
* tree-vect-loop.cc (vect_expand_fold_left): Fold the
element extract stmt, combining it with the vector def.

* gcc.target/i386/pr90579.c: New testcase.

Diff:
---
 gcc/match.pd|  56 +
 gcc/testsuite/gcc.target/i386/pr90579.c |  23 +++
 gcc/tree-ssa-forwprop.cc| 103 +---
 gcc/tree-vect-loop.cc   |   5 ++
 4 files changed, 85 insertions(+), 102 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 97e0bafdda4b..5c679848bdf2 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9531,6 +9531,62 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(BIT_FIELD_REF { CONSTRUCTOR_ELT (ctor, idx / const_k)->value; }
   @1 { bitsize_int ((idx % const_k) * width); })
 
+(simplify
+ (BIT_FIELD_REF (vec_perm@0 @1 @2 VECTOR_CST@3) @rsize @rpos)
+ (with
+  {
+tree elem_type = TREE_TYPE (TREE_TYPE (@0));
+poly_uint64 elem_size = tree_to_poly_uint64 (TYPE_SIZE (elem_type));
+poly_uint64 size = tree_to_poly_uint64 (TYPE_SIZE (type));
+unsigned HOST_WIDE_INT nelts, idx;
+unsigned HOST_WIDE_INT nelts_op = 0;
+  }
+  (if (constant_multiple_p (tree_to_poly_uint64 (@rpos), elem_size, &idx)
+   && VECTOR_CST_NELTS (@3).is_constant (&nelts)
+   && (known_eq (size, elem_size)
+  || (constant_multiple_p (size, elem_size, &nelts_op)
+  && pow2p_hwi (nelts_op
+   (with
+{
+  bool ok = true;
+  /* One element.  */
+  if (known_eq (size, elem_size))
+idx = TREE_INT_CST_LOW (VECTOR_CST_ELT (@3, idx)) % (2 * nelts);
+  else
+{
+ /* Clamp vec_perm_expr index.  */
+ unsigned start
+   = TREE_INT_CST_LOW (vector_cst_elt (@3, idx)) % (2 * nelts);
+ unsigned end
+   = (TREE_INT_CST_LOW (vector_cst_elt (@3, idx + nelts_op - 1))
+  % (2 * nelts));
+ /* Be in the same vector.  */
+ if ((start < nelts) != (end < nelts))
+   ok = false;
+ else
+   for (unsigned HOST_WIDE_INT i = 1; i != nelts_op; i++)
+ {
+   /* Continuous area.  */
+   if ((TREE_INT_CST_LOW (vector_cst_elt (@3, idx + i))
+% (2 * nelts) - 1)
+   != (TREE_INT_CST_LOW (vector_cst_elt (@3, idx + i - 1))
+   % (2 * nelts)))
+ {
+   ok = false;
+   break;
+ }
+ }
+ /* Alignment not worse than before.  */
+ if (start % nelts_op)
+   ok = false;
+ idx = start;
+   }
+}
+(if (ok)
+ (if (idx < nelts)
+  (BIT_FIELD_REF @1 @rsize { bitsize_int (idx * elem_size); })
+  (BIT_FIELD_REF @2 @rsize { bitsize_int ((idx - nelts) * elem_size); 
})))
+
 /* Simplify a bit extraction from a bit insertion for the cases with
the inserted element fully covering the extraction or the insertion
not touching the extraction.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr90579.c 
b/gcc/testsuite/gcc.target/i386/pr90579.c
new file mode 100644
index ..ab48a44063c3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr90579.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mavx2 -mfpmath=sse" } */
+
+extern double r[6];
+extern double a[];
+
+double
+loop (int k, double x)
+{
+  int i;
+  double t=0;
+  for (i=0;i<6;i++)
+r[i] = x * a[i + k];
+  for (i=0;i<6;i++)
+t+=r[5-i];
+  return t;
+}
+
+/* Verify we end up with scalar loads from r for the final sum.  */
+/* { dg-final { scan-assembler "vaddsd\tr\\\+40" } } */
+/* { dg-final { scan-assemb

[gcc r14-11305] c++: Constrain visibility for CNTTPs with internal types [PR118849]

2025-02-13 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:9fa962a5db797665972aaa65426b881754782cfb

commit r14-11305-g9fa962a5db797665972aaa65426b881754782cfb
Author: Nathaniel Shead 
Date:   Wed Feb 12 23:07:43 2025 +1100

c++: Constrain visibility for CNTTPs with internal types [PR118849]

While looking into PR118846 I noticed that we don't currently constrain
the linkage of functions involving CNTTPs of internal-linkage types.  It
seems to me that this would be sensible to do.

PR c++/118849

gcc/cp/ChangeLog:

* decl2.cc (min_vis_expr_r): Constrain visibility according to
the type of decl_constant_var_p decls.

gcc/testsuite/ChangeLog:

* g++.dg/template/linkage6.C: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/decl2.cc  |  4 +++-
 gcc/testsuite/g++.dg/template/linkage6.C | 13 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 5cbe4c0ceda7..bf8f566b8e37 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -2724,7 +2724,9 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void 
*data)
/* The ODR allows definitions in different TUs to refer to distinct
   constant variables with internal or no linkage, so such a reference
   shouldn't affect visibility (PR110323).  FIXME but only if the
-  lvalue-rvalue conversion is applied.  */;
+  lvalue-rvalue conversion is applied.  We still want to restrict
+  visibility according to the type of the declaration however.  */
+   tpvis = type_visibility (TREE_TYPE (t));
   else if (! TREE_PUBLIC (t))
tpvis = VISIBILITY_ANON;
   else
diff --git a/gcc/testsuite/g++.dg/template/linkage6.C 
b/gcc/testsuite/g++.dg/template/linkage6.C
new file mode 100644
index ..b86c986568f8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/linkage6.C
@@ -0,0 +1,13 @@
+// PR c++/118849
+// { dg-do compile { target c++20 } }
+// { dg-final { scan-assembler-not "(weak|glob)\[^\n\]*_Z" { xfail 
powerpc-*-aix* } } }
+
+namespace {
+  struct A {};
+}
+
+template  void f() { }
+
+int main() {
+  f();
+}


[gcc r15-7505] arm: gimple fold aes[ed] [PR114522]

2025-02-13 Thread Christophe Lyon via Gcc-cvs
https://gcc.gnu.org/g:926c989131e914e69cd73529d183ebd9d637798a

commit r15-7505-g926c989131e914e69cd73529d183ebd9d637798a
Author: Christophe Lyon 
Date:   Tue Feb 11 20:51:23 2025 +

arm: gimple fold aes[ed] [PR114522]

Almost a copy/paste from the recent aarch64 version of this patch,
this one is a bit more intrusive because it also introduces
arm_general_gimple_fold_builtin.

With this patch,
gcc.target/arm/aes_xor_combine.c scan-assembler-not veor
passes again.

gcc/ChangeLog:

PR target/114522
* config/arm/arm-builtins.cc (arm_fold_aes_op): New function.
(arm_general_gimple_fold_builtin): New function.
* config/arm/arm-builtins.h (arm_general_gimple_fold_builtin): New
prototype.
* config/arm/arm.cc (arm_gimple_fold_builtin): Call
arm_general_gimple_fold_builtin as needed.

Diff:
---
 gcc/config/arm/arm-builtins.cc | 55 ++
 gcc/config/arm/arm-builtins.h  |  1 +
 gcc/config/arm/arm.cc  |  3 +++
 3 files changed, 59 insertions(+)

diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index e860607686c6..c56ab5db985b 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -45,6 +45,9 @@
 #include "arm-builtins.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "basic-block.h"
+#include "gimple.h"
+#include "ssa.h"
 
 #define SIMD_MAX_BUILTIN_ARGS 7
 
@@ -4053,4 +4056,56 @@ arm_cde_end_args (tree fndecl)
 }
 }
 
+/* Fold a call to vaeseq_u8 and vaesdq_u8.
+   That is `vaeseq_u8 (x ^ y, 0)` gets folded
+   into `vaeseq_u8 (x, y)`.*/
+static gimple *
+arm_fold_aes_op (gcall *stmt)
+{
+  tree arg0 = gimple_call_arg (stmt, 0);
+  tree arg1 = gimple_call_arg (stmt, 1);
+  if (integer_zerop (arg0))
+arg0 = arg1;
+  else if (!integer_zerop (arg1))
+return nullptr;
+  if (TREE_CODE (arg0) != SSA_NAME)
+return nullptr;
+  if (!has_single_use (arg0))
+return nullptr;
+  auto *s = dyn_cast (SSA_NAME_DEF_STMT (arg0));
+  if (!s || gimple_assign_rhs_code (s) != BIT_XOR_EXPR)
+return nullptr;
+  gimple_call_set_arg (stmt, 0, gimple_assign_rhs1 (s));
+  gimple_call_set_arg (stmt, 1, gimple_assign_rhs2 (s));
+  return stmt;
+}
+
+/* Try to fold STMT, given that it's a call to the built-in function with
+   subcode FCODE.  Return the new statement on success and null on
+   failure.  */
+gimple *
+arm_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt)
+{
+  gimple *new_stmt = NULL;
+
+  switch (fcode)
+{
+case ARM_BUILTIN_CRYPTO_AESE:
+case ARM_BUILTIN_CRYPTO_AESD:
+  new_stmt = arm_fold_aes_op (stmt);
+  break;
+}
+
+  /* GIMPLE assign statements (unlike calls) require a non-null lhs.  If we
+ created an assign statement with a null lhs, then fix this by assigning
+ to a new (and subsequently unused) variable.  */
+  if (new_stmt && is_gimple_assign (new_stmt) && !gimple_assign_lhs (new_stmt))
+{
+  tree new_lhs = make_ssa_name (gimple_call_return_type (stmt));
+  gimple_assign_set_lhs (new_stmt, new_lhs);
+}
+
+  return new_stmt;
+}
+
 #include "gt-arm-builtins.h"
diff --git a/gcc/config/arm/arm-builtins.h b/gcc/config/arm/arm-builtins.h
index 1fa85b602d92..3a646619f446 100644
--- a/gcc/config/arm/arm-builtins.h
+++ b/gcc/config/arm/arm-builtins.h
@@ -32,6 +32,7 @@ enum resolver_ident {
 };
 enum resolver_ident arm_describe_resolver (tree);
 unsigned arm_cde_end_args (tree);
+gimple *arm_general_gimple_fold_builtin (unsigned int, gcall *);
 
 #define ENTRY(E, M, Q, S, T, G) E,
 enum arm_simd_type
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index a95ddf8201fa..00499a26bae1 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -76,6 +76,7 @@
 #include "aarch-common.h"
 #include "aarch-common-protos.h"
 #include "machmode.h"
+#include "arm-builtins.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -2859,7 +2860,9 @@ arm_gimple_fold_builtin (gimple_stmt_iterator *gsi)
   switch (code & ARM_BUILTIN_CLASS)
 {
 case ARM_BUILTIN_GENERAL:
+  new_stmt = arm_general_gimple_fold_builtin (subcode, stmt);
   break;
+
 case ARM_BUILTIN_MVE:
   new_stmt = arm_mve::gimple_fold_builtin (subcode, stmt);
 }


[gcc r15-7502] c++: Fix up regressions caused by for/while loops with declarations [PR118822]

2025-02-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:26baa2c09b39abf037afad349a318dc5734eae25

commit r15-7502-g26baa2c09b39abf037afad349a318dc5734eae25
Author: Jakub Jelinek 
Date:   Thu Feb 13 10:21:29 2025 +0100

c++: Fix up regressions caused by for/while loops with declarations 
[PR118822]

The recent PR86769 r15-7426 changes regressed the following two testcases,
the first one is more important as it is derived from real-world code.

The first problem is that the chosen
prep = do_pushlevel (sk_block);
// emit something
body = push_stmt_list ();
// emit further stuff
body = pop_stmt_list (body);
prep = do_poplevel (prep);
way of constructing the {FOR,WHILE}_COND_PREP and {FOR,WHILE}_BODY
isn't reliable.  If during parsing a label is seen in the body and then
some decl with destructors, sk_cleanup transparent scope is added, but
the correspondiong result from push_stmt_list is saved in
*current_binding_level and pop_stmt_list then pops even that statement list
but only do_poplevel actually attempts to pop the sk_cleanup scope and so we
ICE.
The reason for not doing do_pushlevel (sk_block); do_pushlevel (sk_block);
is that variables should be in the same scope (otherwise various e.g.
redeclaration*.C tests FAIL) and doing do_pushlevel (sk_block); do_pushlevel
(sk_cleanup); wouldn't work either as do_poplevel would silently unwind even
the cleanup one.

The second problem is that my assumption that the declaration in the
condition will have zero or one cleanup is just wrong, at least for
structured bindings used as condition, there can be as many cleanups as
there are names in the binding + 1.

So, the following patch changes the earlier approach.  Nothing is removed
from the {FOR,WHILE}_COND_PREP subtrees while doing adjust_loop_decl_cond,
push_stmt_list isn't called either; all it does is remember as an integer
the number of cleanups (CLEANUP_STMT at the end of the STATEMENT_LISTs)
from querying stmt_list_stack and finding the initial *body_p in there
(that integer is stored into {FOR,WHILE}_COND_CLEANUP), and temporarily
{FOR,WHILE}_BODY is set to the last statement (if any) in the innermost
STATEMENT_LIST at the adjust_loop_decl_cond time; then at
finish_{for,while}_stmt a new finish_loop_cond_prep routine takes care of
do_poplevel for the scope (which is in {FOR,WHILE}_COND_PREP) and finds
given {FOR,WHILE}_COND_CLEANUP number and {FOR,WHILE}_BODY tree the right
spot where body statements start and moves that into {FOR,WHILE}_BODY.
Finally genericize_c_loop then inserts the cond, body, continue label, expr
into the right subtree of {FOR,WHILE}_COND_PREP.
The constexpr evaluation unfortunately had to be changed as well, because
we don't want to evaluate everything in BIND_EXPR_BODY (*_COND_PREP ())
right away, we want to evaluate it with the exception of the CLEANUP_STMT
cleanups at the end (given {FOR,WHILE}_COND_CLEANUP levels), and defer
the evaluation of the cleanups until after cond, body, expr are evaluated.

2025-02-13  Jakub Jelinek  

PR c++/118822
PR c++/118833
gcc/
* tree-iterator.h (tsi_split_stmt_list): Declare.
* tree-iterator.cc (tsi_split_stmt_list): New function.
gcc/c-family/
* c-common.h (WHILE_COND_CLEANUP): Change description in comment.
(FOR_COND_CLEANUP): Likewise.
* c-gimplify.cc (genericize_c_loop): Adjust for COND_CLEANUP
being CLEANUP_STMT/TRY_FINALLY_EXPR trailing nesting depth
instead of actual cleanup.
gcc/cp/
* semantics.cc (adjust_loop_decl_cond): Allow multiple trailing
CLEANUP_STMT levels in *BODY_P.  Set *CLEANUP_P to the number
of levels rather than one particular cleanup, keep the cleanups
in *PREP_P.  Set *BODY_P to the last stmt in the cur_stmt_list
or NULL if *CLEANUP_P and the innermost cur_stmt_list is empty.
(finish_loop_cond_prep): New function.
(finish_while_stmt, finish_for_stmt): Use it.  Don't call
set_one_cleanup_loc.
* constexpr.cc (cxx_eval_loop_expr): Adjust handling of
{FOR,WHILE}_COND_{PREP,CLEANUP}.
gcc/testsuite/
* g++.dg/expr/for9.C: New test.
* g++.dg/cpp26/decomp12.C: New test.

Diff:
---
 gcc/c-family/c-common.h   |   6 +-
 gcc/c-family/c-gimplify.cc|  41 ---
 gcc/cp/constexpr.cc   |  97 --
 gcc/cp/semantics.cc   | 128 +-
 gcc/testsuite/g++.dg/cpp26/decomp12.C |  46 
 gcc/testsuite/g++.dg/expr/for9.C  |  25 +++
 gcc/tree-iterator.cc  |  22 ++
 gcc/tree-iterator.h   |   1 +
 8 files changed, 297 insertions(+), 69 deletions(-)

diff -

[gcc/aoliva/heads/testme] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 63c14ae67e08... [ifcombine] cope with signbit tests of extended values

It previously pointed to:

 f39dde7887f0... [ifcombine] cope with signbit tests of extended values

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  f39dde7... [ifcombine] cope with signbit tests of extended values


Summary of changes (added commits):
---

  63c14ae... [ifcombine] cope with signbit tests of extended values


[gcc/aoliva/heads/testme] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 5fed42b6a458... [ifcombine] cope with signbit tests of extended values

It previously pointed to:

 cf2e0f411bea... [ifcombine] cope with signbit tests of extended values

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  cf2e0f4... [ifcombine] cope with signbit tests of extended values


Summary of changes (added commits):
---

  5fed42b... [ifcombine] cope with signbit tests of extended values


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:5fed42b6a458baf896df610e690ec4593fd7a130

commit 5fed42b6a458baf896df610e690ec4593fd7a130
Author: Alexandre Oliva 
Date:   Thu Feb 13 07:36:04 2025 -0300

[ifcombine] cope with signbit tests of extended values

A compare with zero may be taken as a sign bit test by
fold_truth_andor_for_ifcombine, but the operand may be extended from a
narrower field.  If the operand was narrower, the bitsize will reflect
the narrowing conversion, but if it was wider, we'll only know whether
the field is sign- or zero-extended from unsignedp, but we won't know
whether it needed to be extended, because arg will have changed to the
narrower variable when we get to the point in which we can compute the
arg width.  If it's sign-extended, we're testing the right bit, but if
it's zero-extended, there isn't any bit we can test.

Instead of punting and leaving the foldable compare to be figured out
by another pass, arrange for the sign bit resulting from the widening
zero-extension to be taken as zero, so that the modified compare will
yield the desired result.

While at that, avoid swapping the right-hand compare operands when
we've already determined that it was a signbit test: it no use to even
try.


for  gcc/ChangeLog

PR tree-optimization/118805
* gimple-fold.cc (fold_truth_andor_for_combine): Detect and
cope with zero-extension in signbit tests.  Reject swapping
right-compare operands if rsignbit.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118805
* gcc.dg/field-merge-26.c: New.

Diff:
---
 gcc/gimple-fold.cc| 22 +-
 gcc/testsuite/gcc.dg/field-merge-26.c | 20 
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 29191685a43c..90b0ec6d79a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8090,14 +8090,16 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
 
   /* Prepare to turn compares of signed quantities with zero into sign-bit
  tests.  We need not worry about *_reversep here for these compare
- rewrites: loads will have already been reversed before compares.  */
-  bool lsignbit = false, rsignbit = false;
+ rewrites: loads will have already been reversed before compares.  Save the
+ precision, because [lr]l_arg may change and we won't be able to tell how
+ wide it was originally.  */
+  unsigned lsignbit = 0, rsignbit = 0;
   if ((lcode == LT_EXPR || lcode == GE_EXPR)
   && integer_zerop (lr_arg)
   && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (ll_arg)))
 {
-  lsignbit = true;
+  lsignbit = TYPE_PRECISION (TREE_TYPE (ll_arg));
   lcode = (lcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   /* Turn compares of unsigned quantities with powers of two into
@@ -8130,7 +8132,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   && INTEGRAL_TYPE_P (TREE_TYPE (rl_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (rl_arg)))
 {
-  rsignbit = true;
+  rsignbit = TYPE_PRECISION (TREE_TYPE (rl_arg));
   rcode = (rcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   else if ((rcode == LT_EXPR || rcode == GE_EXPR)
@@ -8204,7 +8206,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   || ! operand_equal_p (ll_inner, rl_inner, 0))
 {
   /* Try swapping the operands.  */
-  if (ll_reversep != rr_reversep
+  if (ll_reversep != rr_reversep || rsignbit
  || !operand_equal_p (ll_inner, rr_inner, 0))
return 0;
 
@@ -8284,6 +8286,14 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   if (lsignbit)
 {
   wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
+  /* If ll_arg is zero-extended and we're testing the sign bit, we know
+what the result should be.  Shifting the sign bit out of sign will get
+us to mask the entire field out, yielding zero, i.e., the sign bit of
+the zero-extended value.  We know the masked value is being compared
+with zero, so the compare will get us the result we're looking
+for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
+  if (lsignbit > ll_bitsize && ll_unsignedp)
+   sign <<= 1;
   if (!ll_and_mask.get_precision ())
ll_and_mask = sign;
   else
@@ -8303,6 +8313,8 @@ 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)
+   sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
   else
diff --git a/gcc/testsuite/gcc.dg/field-merge-26.c 
b/gcc/testsuite/gcc.dg/field-merge-26.c
new file mode 100644
index ..96d7e7

[gcc r15-7504] c++: Constrain visibility for CNTTPs with internal types [PR118849]

2025-02-13 Thread Nathaniel Shead via Gcc-cvs
https://gcc.gnu.org/g:0e485b8c85c31856b9f7c91015ac94874b100bd4

commit r15-7504-g0e485b8c85c31856b9f7c91015ac94874b100bd4
Author: Nathaniel Shead 
Date:   Wed Feb 12 23:07:43 2025 +1100

c++: Constrain visibility for CNTTPs with internal types [PR118849]

While looking into PR118846 I noticed that we don't currently constrain
the linkage of functions involving CNTTPs of internal-linkage types.  It
seems to me that this would be sensible to do.

PR c++/118849

gcc/cp/ChangeLog:

* decl2.cc (min_vis_expr_r): Constrain visibility according to
the type of decl_constant_var_p decls.

gcc/testsuite/ChangeLog:

* g++.dg/template/linkage6.C: New test.

Signed-off-by: Nathaniel Shead 

Diff:
---
 gcc/cp/decl2.cc  |  4 +++-
 gcc/testsuite/g++.dg/template/linkage6.C | 13 +
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 593dcaa4e2de..aa9ebca12f8f 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -2814,7 +2814,9 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void 
*data)
/* The ODR allows definitions in different TUs to refer to distinct
   constant variables with internal or no linkage, so such a reference
   shouldn't affect visibility (PR110323).  FIXME but only if the
-  lvalue-rvalue conversion is applied.  */;
+  lvalue-rvalue conversion is applied.  We still want to restrict
+  visibility according to the type of the declaration however.  */
+   tpvis = type_visibility (TREE_TYPE (t));
   else if (! TREE_PUBLIC (t))
tpvis = VISIBILITY_ANON;
   else
diff --git a/gcc/testsuite/g++.dg/template/linkage6.C 
b/gcc/testsuite/g++.dg/template/linkage6.C
new file mode 100644
index ..b86c986568f8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/linkage6.C
@@ -0,0 +1,13 @@
+// PR c++/118849
+// { dg-do compile { target c++20 } }
+// { dg-final { scan-assembler-not "(weak|glob)\[^\n\]*_Z" { xfail 
powerpc-*-aix* } } }
+
+namespace {
+  struct A {};
+}
+
+template  void f() { }
+
+int main() {
+  f();
+}


[gcc r15-7506] tree, gengtype: Fix up GC issue with DECL_VALUE_EXPR [PR118790]

2025-02-13 Thread Jakub Jelinek via Gcc-cvs
https://gcc.gnu.org/g:7738c6286fba7ec2112823f53cc2cefac2c8d007

commit r15-7506-g7738c6286fba7ec2112823f53cc2cefac2c8d007
Author: Jakub Jelinek 
Date:   Thu Feb 13 14:14:50 2025 +0100

tree, gengtype: Fix up GC issue with DECL_VALUE_EXPR [PR118790]

The following testcase ICEs, because we have multiple levels of
DECL_VALUE_EXPR VAR_DECLs:
  character(kind=1) id_string[1:.id_string] [value-expr: *id_string.55];
  character(kind=1)[1:.id_string] * id_string.55 [value-expr: 
FRAME.107.id_string.55];
  integer(kind=8) .id_string [value-expr: FRAME.107..id_string];
id_string is the user variable mentioned in BLOCK_VARS, it has
DECL_VALUE_EXPR because it is a VLA, id_string.55 is a temporary created by
gimplify_vla_decl as the address that points to the start of the VLA, what
is normally used in the IL to access it.  But as this artificial var is then
used inside of a nested function, tree-nested.cc adds DECL_VALUE_EXPR to it
too and moves the actual value into the FRAME.107 object's member.
Now, remove_unused_locals removes id_string.55 (and various other VAR_DECLs)
from cfun->local_decls, simply because it is not mentioned in the IL at all
(neither is id_string itself, but that is kept in BLOCK_VARS as it has
DECL_VALUE_EXPR).  So, after this point, id_string.55 tree isn't referenced 
from
anywhere but id_string's DECL_VALUE_EXPR.  Next GC collection is triggered,
and we are unlucky enough that in the value_expr_for_decl hash table
(underlying hash map for DECL_VALUE_EXPR) the id_string.55 entry comes
before the id_string entry.  id_string is ggc_marked_p because it is
referenced from BLOCK_VARS, but id_string.55 is not, as we don't mark
DECL_VALUE_EXPR anywhere but by gt_cleare_cache on value_expr_for_decl.
But gt_cleare_cache does two things, it calls clear_slots on entries
where the key is not ggc_marked_p (so the id_string.55 mapping to
FRAME.107.id_string.55 is lost and DECL_VALUE_EXPR (id_string.55) becomes
NULL) but then later we see id_string entry, which is ggc_marked_p, so mark
the whole hash table entry, which sets ggc_set_mark on id_string.55.  But
at this point its DECL_VALUE_EXPR is lost.
Later during dwarf2out.cc we want to emit DW_AT_location for id_string, see
it has DECL_VALUE_EXPR, so emit it as indirection of id_string.55 for which
we again lookup DECL_VALUE_EXPR as it has DECL_HAS_VALUE_EXPR_P, but as it
is NULL, we ICE, instead of finding it is a subobject of FRAME.107 for which
we can find its stack location.

Now, as can be seen in the PR, I've tried to tweak tree-ssa-live.cc so that
it would keep id_string.55 in cfun->local_decls; that prohibits it from
the DECL_VALUE_EXPR of it being GC until expansion, but then we shrink and
free cfun->local_decls completely and so GC at that point still can throw
it away.

The following patch adds an extension to the GTY ((cache)) option, before
calling the gt_cleare_cache on some hash table by specifying
GTY ((cache ("somefn"))) it calls somefn on that hash table as well.
And this extra hook can do any additional ggc_set_mark needed so that
gt_cleare_cache preserves everything that is actually needed and throws
away the rest.

In order to make it just 2 pass rather than up to n passes - (if we had
say
id1 -> something, id2 -> x(id1), id3 -> x(id2), id4 -> x(id3), id5 -> x(id4)
in the value_expr_for_decl hash table in that order (where idN are VAR_DECLs
with DECL_HAS_VALUE_EXPR_P, id5 is the only one mentioned from outside and
idN -> X stands for idN having DECL_VALUE_EXPR X, something for some
arbitrary tree and x(idN) for some arbitrary tree which mentions idN
variable) and in each pass just marked the to part of entries with
ggc_marked_p base.from we'd need to repeat until we don't mark anything)
the patch calls walk_tree on DECL_VALUE_EXPR of the marked trees and if it
finds yet unmarked tree, it marks it and walks its DECL_VALUE_EXPR as well
the same way.

2025-02-13  Jakub Jelinek  

PR debug/118790
* gengtype.cc (write_roots): Remove cache variable, instead break 
from
the loop on match and test o for NULL.  If the cache option has
non-empty string argument, call the specified function with v->name
as argument before calling gt_cleare_cache on it.
* tree.cc (gt_value_expr_mark_2, gt_value_expr_mark_1,
gt_value_expr_mark): New functions.
(value_expr_for_decl): Use GTY ((cache ("gt_value_expr_mark"))) 
rather
than just GTY ((cache)).
* doc/gty.texi (cache): Document optional argument of cache option.

* gfortran.dg/gomp/pr118790.f90: New test.

Diff:
---
 gcc/doc/gty.texi|   5 +
 gcc/gengtype.cc |   7 +-
 gcc

[gcc/aoliva/heads/testme] (89 commits) [testsuite] add x86 effective target

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 98a1939da569... [testsuite] add x86 effective target

It previously pointed to:

 5fed42b6a458... [ifcombine] cope with signbit tests of extended values

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  5fed42b... [ifcombine] cope with signbit tests of extended values
  2a10285... [testsuite] add x86 effective target
  7adffbc... [testsuite] adjust expectations of x86 vect-simd-clone test
  4e2f34f... [testsuite] fix check-function-bodies usage


Summary of changes (added commits):
---

  98a1939... [testsuite] add x86 effective target
  765fcf5... [ifcombine] cope with signbit tests of extended values
  80b3fa9... [testsuite] adjust expectations of x86 vect-simd-clone test
  9d91029... [testsuite] fix check-function-bodies usage
  926c989... arm: gimple fold aes[ed] [PR114522] (*)
  0e485b8... c++: Constrain visibility for CNTTPs with internal types [P (*)
  a1855a3... testsuite: Add another range for coroutines testcase [PR118 (*)
  26baa2c... c++: Fix up regressions caused by for/while loops with decl (*)
  7db9437... build: Remove HAVE_LD_EH_FRAME_CIEV3 (*)
  85b0a6e... doc: Update install.texi for GCC 15 on Solaris (*)
  ac9806d... s390: Fix s390_valid_shift_count() for TI mode [PR118835] (*)
  77d0192... tree-optimization/118817 - fix ICE with VN CTOR simplificat (*)
  2f33fa0... Daily bump. (*)
  8598a84... loop-invariant: Treat inline-asm conditional trapping [PR10 (*)
  aa972d0... ifcvt: Don't speculation move inline-asm [PR102150] (*)
  30dfcec... avr.opt.urls += -mcall-main (*)
  0fa06d7... AVR: target/118806 - Add -mno-call-main to tweak running ma (*)
  b0cf042... c++: add fixed test [PR101740] (*)
  cfdb961... vect: Set counts of early break exit blocks correctly [PR11 (*)
  3880271... RISC-V: Vector pesudoinsns with x0 operand to use imm 0 (*)
  580f571... RISC-V: unrecognizable insn ICE in xtheadvector/pr114194.c  (*)
  805329e... Doc: Fix Texinfo warning in install.texi (*)
  b9857b7... Doc: Fix some typos and other nearby sloppy-writing issues (*)
  29a5b1b... Doc: Delete obsolete interface.texi chapter from GCC intern (*)
  2605daa... RISC-V: Drop __riscv_vendor_feature_bits (*)
  1fb2146... Daily bump. (*)
  71f6540... [PR target/115478] Accept ADD, IOR or XOR when combining ob (*)
  556248d... c++: don't default -frange-for-ext-temps in -std=gnu++20 [P (*)
  0d2a5f3... c++: change implementation of -frange-for-ext-temps [PR1185 (*)
  299a8e2... aarch64: Update fp8 dependencies (*)
  00d943b... testsuite: Enable reduced parallel batch sizes (*)
  9a2116f... OpenMP: Pass a 3-way flag to omp_check_context_selector ins (*)
  84854ce... OpenMP: Bug fixes for comparing context selectors (*)
  4abac2f... lto: Add an entry for cold attribute to lto_gnu_attributes (*)
  c74e7f6... c++: Reject cdtors and conversion operators with a single * (*)
  e8c5013... sarif-replay: fix off-by-one in handling of "endColumn" (§ (*)
  0f8fd6b... Synchronize include/dwarf2.def with binutils (*)
  0a1d2ea... tree-optimization/118817 - missed folding of PRE inserted c (*)
  1bfab1d... testsuite: Fix g++.dg/modules/adl-5 (*)
  ef83fae... c++: Fix use-after-free of replaced friend instantiation [P (*)
  7317fc0... x86: Correct ASM_OUTPUT_SYMBOL_REF (*)
  0399e3e... config.gcc: Support mips*64*-linux-muslabi64 as ABI64 by de (*)
  86b9abc... MIPS: Add some floating point instructions support for MIPS (*)
  b700855... libphobos: Disable libphobos.phobos/std/concurrency.d on ma (*)
  d171f21... testsuite: LoongArch: Remove from btrunc, ceil, and floor e (*)
  30a3a55... i386: Fix AVX512BW intrin header with __OPTIMIZE__ [PR 1188 (*)
  3c5422e... PR modula2/118761: gm2 driver doesnt behave as gcc for -fhe (*)
  a7ccad4... Daily bump. (*)
  d5c72da... libbacktrace: add cast to avoid undefined shift (*)
  d2ff1b7... This improves an error message, avoiding at ... at. (*)
  118a6c3... Fortran: checking of pointer targets for structure construc (*)
  4ce8ad6... [gcn] mkoffload.cc: Print fatal error if -march has no mult (*)
  7037fdf... [gcn] install.texi: Update for new ISA targets and their re (*)
  6d07e3d... ipa-cp: Perform operations in the appropriate types (PR 118 (*)
  6ed1b40... arm: fix typo in dg-require-effective-target [PR118089] (*)
  9214201... i386: Change RTL representation of bt[lq] [PR118623] (*)
  aaf5f50... testsuite: Fix two testisms on x86 after PFA [PR118754] (*)
  38aeb60... Daily bump. (*)
  22e30d6... [PR target/115123] Fix testsuite fallout from sinking heuri (*)
  b81bb3e... [PR middle-end/117263] Avoid unused-but-set warning in gena (*)
  a8d0a2d... Test procedure dummy arguments against global symbols, if a (*)
  9576353... [RISC-V][PR target/118146] Fix ICE for unsupported modes (*)
  58856a6... Daily bump. (*)
  0c7109a... ad target/118764: Fix a typo in doc/extend.texi. (*)
  5753f45... [PATCH] OpenMP: 

[gcc/aoliva/heads/testbase] (85 commits) arm: gimple fold aes[ed] [PR114522]

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testbase' was updated to point to:

 926c989131e9... arm: gimple fold aes[ed] [PR114522]

It previously pointed to:

 d790f0137c6f... [testsuite] tolerate later success [PR108357]

Diff:

Summary of changes (added commits):
---

  926c989... arm: gimple fold aes[ed] [PR114522] (*)
  0e485b8... c++: Constrain visibility for CNTTPs with internal types [P (*)
  a1855a3... testsuite: Add another range for coroutines testcase [PR118 (*)
  26baa2c... c++: Fix up regressions caused by for/while loops with decl (*)
  7db9437... build: Remove HAVE_LD_EH_FRAME_CIEV3 (*)
  85b0a6e... doc: Update install.texi for GCC 15 on Solaris (*)
  ac9806d... s390: Fix s390_valid_shift_count() for TI mode [PR118835] (*)
  77d0192... tree-optimization/118817 - fix ICE with VN CTOR simplificat (*)
  2f33fa0... Daily bump. (*)
  8598a84... loop-invariant: Treat inline-asm conditional trapping [PR10 (*)
  aa972d0... ifcvt: Don't speculation move inline-asm [PR102150] (*)
  30dfcec... avr.opt.urls += -mcall-main (*)
  0fa06d7... AVR: target/118806 - Add -mno-call-main to tweak running ma (*)
  b0cf042... c++: add fixed test [PR101740] (*)
  cfdb961... vect: Set counts of early break exit blocks correctly [PR11 (*)
  3880271... RISC-V: Vector pesudoinsns with x0 operand to use imm 0 (*)
  580f571... RISC-V: unrecognizable insn ICE in xtheadvector/pr114194.c  (*)
  805329e... Doc: Fix Texinfo warning in install.texi (*)
  b9857b7... Doc: Fix some typos and other nearby sloppy-writing issues (*)
  29a5b1b... Doc: Delete obsolete interface.texi chapter from GCC intern (*)
  2605daa... RISC-V: Drop __riscv_vendor_feature_bits (*)
  1fb2146... Daily bump. (*)
  71f6540... [PR target/115478] Accept ADD, IOR or XOR when combining ob (*)
  556248d... c++: don't default -frange-for-ext-temps in -std=gnu++20 [P (*)
  0d2a5f3... c++: change implementation of -frange-for-ext-temps [PR1185 (*)
  299a8e2... aarch64: Update fp8 dependencies (*)
  00d943b... testsuite: Enable reduced parallel batch sizes (*)
  9a2116f... OpenMP: Pass a 3-way flag to omp_check_context_selector ins (*)
  84854ce... OpenMP: Bug fixes for comparing context selectors (*)
  4abac2f... lto: Add an entry for cold attribute to lto_gnu_attributes (*)
  c74e7f6... c++: Reject cdtors and conversion operators with a single * (*)
  e8c5013... sarif-replay: fix off-by-one in handling of "endColumn" (§ (*)
  0f8fd6b... Synchronize include/dwarf2.def with binutils (*)
  0a1d2ea... tree-optimization/118817 - missed folding of PRE inserted c (*)
  1bfab1d... testsuite: Fix g++.dg/modules/adl-5 (*)
  ef83fae... c++: Fix use-after-free of replaced friend instantiation [P (*)
  7317fc0... x86: Correct ASM_OUTPUT_SYMBOL_REF (*)
  0399e3e... config.gcc: Support mips*64*-linux-muslabi64 as ABI64 by de (*)
  86b9abc... MIPS: Add some floating point instructions support for MIPS (*)
  b700855... libphobos: Disable libphobos.phobos/std/concurrency.d on ma (*)
  d171f21... testsuite: LoongArch: Remove from btrunc, ceil, and floor e (*)
  30a3a55... i386: Fix AVX512BW intrin header with __OPTIMIZE__ [PR 1188 (*)
  3c5422e... PR modula2/118761: gm2 driver doesnt behave as gcc for -fhe (*)
  a7ccad4... Daily bump. (*)
  d5c72da... libbacktrace: add cast to avoid undefined shift (*)
  d2ff1b7... This improves an error message, avoiding at ... at. (*)
  118a6c3... Fortran: checking of pointer targets for structure construc (*)
  4ce8ad6... [gcn] mkoffload.cc: Print fatal error if -march has no mult (*)
  7037fdf... [gcn] install.texi: Update for new ISA targets and their re (*)
  6d07e3d... ipa-cp: Perform operations in the appropriate types (PR 118 (*)
  6ed1b40... arm: fix typo in dg-require-effective-target [PR118089] (*)
  9214201... i386: Change RTL representation of bt[lq] [PR118623] (*)
  aaf5f50... testsuite: Fix two testisms on x86 after PFA [PR118754] (*)
  38aeb60... Daily bump. (*)
  22e30d6... [PR target/115123] Fix testsuite fallout from sinking heuri (*)
  b81bb3e... [PR middle-end/117263] Avoid unused-but-set warning in gena (*)
  a8d0a2d... Test procedure dummy arguments against global symbols, if a (*)
  9576353... [RISC-V][PR target/118146] Fix ICE for unsupported modes (*)
  58856a6... Daily bump. (*)
  0c7109a... ad target/118764: Fix a typo in doc/extend.texi. (*)
  5753f45... [PATCH] OpenMP: Improve Fortran metadirective diagnostics [ (*)
  06e5b0b... libgcc: On FreeBSD use GCC's crt objects for static linking (*)
  6312165... GCN, nvptx: 'sorry, unimplemented: exception handling not s (*)
  7809aa1... For a few test cases, clarify dependance on effective-targe (*)
  2466b0b... nvptx doesn't actually support effective-target 'exceptions (*)
  e90276a... BPF doesn't actually support effective-target 'exceptions'  (*)
  9f4feba... Clarify that effective-targets 'exceptions' and 'exceptions (*)
  0e602b2... 'gcc.dg/pr88870.c': don't 'dg-require-effective-target nonl (*)
  64d8ea0... i386: Fix ICE with conditional QI/HI vector

[gcc(refs/users/aoliva/heads/testme)] [testsuite] add x86 effective target

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:98a1939da5695727502636624f1b8d88b3d2271e

commit 98a1939da5695727502636624f1b8d88b3d2271e
Author: Alexandre Oliva 
Date:   Thu Feb 13 10:13:37 2025 -0300

[testsuite] add x86 effective target

I got tired of repeating the conditional that recognizes ia32 or
x86_64, and introduced 'x86' as a shorthand for that, adjusting all
occurrences in target-supports.exp, to set an example.  I found some
patterns that recognized i?86* and x86_64*, but I took those as likely
cut&pastos instead of trying to preserve those weirdnesses.


for  gcc/ChangeLog

* doc/sourcebuild.texi: Add x86 effective target.

for  gcc/testsuite/ChangeLog

* lib/target-supports.exp (check_effective_target_x86): New.
Replace all uses of i?86-*-* and x86_64-*-* in this file.

Diff:
---
 gcc/doc/sourcebuild.texi  |   3 +
 gcc/testsuite/lib/target-supports.exp | 188 +-
 2 files changed, 99 insertions(+), 92 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 89abce7eec2c..966bec3cb8d0 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2801,6 +2801,9 @@ Target supports the execution of @code{user_msr} 
instructions.
 @item vect_cmdline_needed
 Target requires a command line argument to enable a SIMD instruction set.
 
+@item x86
+Target is ia32 or x86_64.
+
 @item xorsign
 Target supports the xorsign optab expansion.
 
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index ff95b88f3c40..77e5a514175f 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -740,7 +740,7 @@ proc check_profiling_available { test_what } {
 }
 
 if { $test_what == "-fauto-profile" } {
-   if { !([istarget i?86-*-linux*] || [istarget x86_64-*-linux*]) } {
+   if { !([check_effective_target_x86] && [istarget *-*-linux*]) } {
verbose "autofdo only supported on linux"
return 0
}
@@ -2616,17 +2616,23 @@ proc remove_options_for_riscv_zvbb { flags } {
 return [add_options_for_riscv_z_ext zvbb $flags]
 }
 
+# Return 1 if the target is ia32 or x86_64.
+
+proc check_effective_target_x86 { } {
+if { ([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
+   return 1
+} else {
+return 0
+}
+}
+
 # Return 1 if the target OS supports running SSE executables, 0
 # otherwise.  Cache the result.
 
 proc check_sse_os_support_available { } {
 return [check_cached_effective_target sse_os_support_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
-   expr 0
-   } else {
-   expr 1
-   }
+   expr [check_effective_target_x86]
 }]
 }
 
@@ -2636,7 +2642,7 @@ proc check_sse_os_support_available { } {
 proc check_avx_os_support_available { } {
 return [check_cached_effective_target avx_os_support_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
# Check that OS has AVX and SSE saving enabled.
@@ -2659,7 +2665,7 @@ proc check_avx_os_support_available { } {
 proc check_avx512_os_support_available { } {
 return [check_cached_effective_target avx512_os_support_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
# Check that OS has AVX512, AVX and SSE saving enabled.
@@ -2682,7 +2688,7 @@ proc check_avx512_os_support_available { } {
 proc check_sse_hw_available { } {
 return [check_cached_effective_target sse_hw_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
check_runtime_nocache sse_hw_available {
@@ -2706,7 +2712,7 @@ proc check_sse_hw_available { } {
 proc check_sse2_hw_available { } {
 return [check_cached_effective_target sse2_hw_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
check_runtime_nocache sse2_hw_available {
@@ -2730,7 +2736,7 @@ proc check_sse2_hw_available { } {
 proc check_sse4_hw_available { } {
 return [check_cached_effective_target sse4_hw_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effe

[gcc(refs/users/aoliva/heads/testme)] [testsuite] fix check-function-bodies usage

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:9d9102995b365735ddccd7a7186965bf1a763fe3

commit 9d9102995b365735ddccd7a7186965bf1a763fe3
Author: Alexandre Oliva 
Date:   Thu Feb 13 10:13:29 2025 -0300

[testsuite] fix check-function-bodies usage

The existing usage comment for check-function-bodies is presumably a
typo, as it doesn't match existing uses.  Fix it.


for  gcc/testsuite/ChangeLog

* lib/scanasm.exp (check-function-bodies): Fix usage comment.

Diff:
---
 gcc/testsuite/lib/scanasm.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index beffedd5bce4..97935cb23c3c 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -985,7 +985,7 @@ proc check_function_body { functions name body_regexp } {
 
 # Check the implementations of functions against expected output.  Used as:
 #
-# { dg-do { check-function-bodies PREFIX TERMINATOR[ OPTION[ SELECTOR 
[MATCHED]]] } }
+# { dg-final { check-function-bodies PREFIX TERMINATOR[ OPTION[ SELECTOR 
[MATCHED]]] } }
 #
 # See sourcebuild.texi for details.


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:765fcf5679c6d0db5229f8da3d08f920a4e23dae

commit 765fcf5679c6d0db5229f8da3d08f920a4e23dae
Author: Alexandre Oliva 
Date:   Thu Feb 13 10:13:34 2025 -0300

[ifcombine] cope with signbit tests of extended values

A compare with zero may be taken as a sign bit test by
fold_truth_andor_for_ifcombine, but the operand may be extended from a
narrower field.  If the operand was narrower, the bitsize will reflect
the narrowing conversion, but if it was wider, we'll only know whether
the field is sign- or zero-extended from unsignedp, but we won't know
whether it needed to be extended, because arg will have changed to the
narrower variable when we get to the point in which we can compute the
arg width.  If it's sign-extended, we're testing the right bit, but if
it's zero-extended, there isn't any bit we can test.

Instead of punting and leaving the foldable compare to be figured out
by another pass, arrange for the sign bit resulting from the widening
zero-extension to be taken as zero, so that the modified compare will
yield the desired result.

While at that, avoid swapping the right-hand compare operands when
we've already determined that it was a signbit test: it no use to even
try.


for  gcc/ChangeLog

PR tree-optimization/118805
* gimple-fold.cc (fold_truth_andor_for_combine): Detect and
cope with zero-extension in signbit tests.  Reject swapping
right-compare operands if rsignbit.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118805
* gcc.dg/field-merge-26.c: New.

Diff:
---
 gcc/gimple-fold.cc| 22 +-
 gcc/testsuite/gcc.dg/field-merge-26.c | 20 
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 29191685a43c..0380c7af4c21 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8090,14 +8090,16 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
 
   /* Prepare to turn compares of signed quantities with zero into sign-bit
  tests.  We need not worry about *_reversep here for these compare
- rewrites: loads will have already been reversed before compares.  */
-  bool lsignbit = false, rsignbit = false;
+ rewrites: loads will have already been reversed before compares.  Save the
+ precision, because [lr]l_arg may change and we won't be able to tell how
+ wide it was originally.  */
+  unsigned lsignbit = 0, rsignbit = 0;
   if ((lcode == LT_EXPR || lcode == GE_EXPR)
   && integer_zerop (lr_arg)
   && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (ll_arg)))
 {
-  lsignbit = true;
+  lsignbit = TYPE_PRECISION (TREE_TYPE (ll_arg));
   lcode = (lcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   /* Turn compares of unsigned quantities with powers of two into
@@ -8130,7 +8132,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   && INTEGRAL_TYPE_P (TREE_TYPE (rl_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (rl_arg)))
 {
-  rsignbit = true;
+  rsignbit = TYPE_PRECISION (TREE_TYPE (rl_arg));
   rcode = (rcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   else if ((rcode == LT_EXPR || rcode == GE_EXPR)
@@ -8204,7 +8206,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   || ! operand_equal_p (ll_inner, rl_inner, 0))
 {
   /* Try swapping the operands.  */
-  if (ll_reversep != rr_reversep
+  if (ll_reversep != rr_reversep || rsignbit
  || !operand_equal_p (ll_inner, rr_inner, 0))
return 0;
 
@@ -8284,6 +8286,14 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   if (lsignbit)
 {
   wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
+  /* If ll_arg is zero-extended and we're testing the sign bit, we know
+what the result should be.  Shifting the sign bit out of sign will get
+us to mask the entire field out, yielding zero, i.e., the sign bit of
+the zero-extended value.  We know the masked value is being compared
+with zero, so the compare will get us the result we're looking
+for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
+  if (lsignbit > ll_bitsize && ll_unsignedp)
+   sign <<= 1;
   if (!ll_and_mask.get_precision ())
ll_and_mask = sign;
   else
@@ -8303,6 +8313,8 @@ 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)
+   sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
   else
diff --git a/gcc/testsuite/gcc.dg/field-merge-26.c 
b/gcc/testsuite/gcc.dg/field-merge-26.c
new file mode 100644
index 

[gcc(refs/users/aoliva/heads/testme)] [testsuite] adjust expectations of x86 vect-simd-clone tests

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:80b3fa99afebf1dd32e1f8ed5e3b47ab4434055b

commit 80b3fa99afebf1dd32e1f8ed5e3b47ab4434055b
Author: Alexandre Oliva 
Date:   Thu Feb 13 10:13:31 2025 -0300

[testsuite] adjust expectations of x86 vect-simd-clone tests

Some vect-simd-clone tests fail when targeting ancient x86 variants,
because the expected transformations only take place with -msse4 or
higher.

So arrange for these tests to take an -msse4 option on x86, so that
the expected vectorization takes place, but decay to a compile test if
vect.exp would enable execution but the target doesn't have an sse4
runtime.  This requires the new dg-do-if to override the action on a
target while retaining the default action on others, instead of
disabling the test.

We can count on avx512f compile-time support for these tests, because
vect_simd_clones requires that on x86, and that implies sse4 support,
so we need not complicate the scan conditionals with tests for sse4,
except on the last test.


for  gcc/ChangeLog

* doc/sourcebuild.texi (dg-do-if): Document.

for  gcc/testsuite/ChangeLog

* lib/target-supports-dg.exp (dg-do-if): New.
* gcc.dg/vect/vect-simd-clone-16f.c: Use -msse4 on x86, and
skip in case execution is enabled but the runtime isn't.
* gcc.dg/vect/vect-simd-clone-17f.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18f.c: Likewise.
* gcc.dg/vect/vect-simd-clone-20.c: Likewise, but only skip
the scan test.

Diff:
---
 gcc/doc/sourcebuild.texi|  5 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c |  2 ++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c |  2 ++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c |  2 ++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-20.c  |  6 +++--
 gcc/testsuite/lib/target-supports-dg.exp| 29 +
 6 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 797775e90de9..89abce7eec2c 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1128,6 +1128,11 @@ by the specified floating-point factor.
 @subsubsection Skip a test for some targets
 
 @table @code
+@item @{ dg-do-if @var{action} @{ @var{selector} @} @}
+Same as dg-do if the selector matches and the test hasn't already been
+marked as unsupported.  Use it to override an action on a target while
+leaving the default action alone for other targets.
+
 @item @{ dg-skip-if @var{comment} @{ @var{selector} @} [@{ @var{include-opts} 
@} [@{ @var{exclude-opts} @}]] @}
 Arguments @var{include-opts} and @var{exclude-opts} are lists in which
 each element is a string of zero or more GCC options.
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c
index 7cd29e894d05..bb3b081b0e3d 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c
@@ -1,5 +1,7 @@
+/* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
 /* { dg-require-effective-target vect_simd_clones } */
 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
+/* { dg-additional-options "-msse4" { target sse4 } } */
 /* { dg-additional-options "-mavx" { target avx_runtime } } */
 /* { dg-additional-options "-mno-avx512f" { target { { i?86*-*-* x86_64-*-* } 
&& { ! lp64 } } } } */
 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c
index 177521dc4453..504465614c98 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c
@@ -1,5 +1,7 @@
+/* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
 /* { dg-require-effective-target vect_simd_clones } */
 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
+/* { dg-additional-options "-msse4" { target sse4 } } */
 /* { dg-additional-options "-mavx" { target avx_runtime } } */
 /* { dg-additional-options "-mno-avx512f" { target { { i?86*-*-* x86_64-*-* } 
&& { ! lp64 } } } } */
 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c
index 4dd51381d73c..0c418d432482 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c
@@ -1,5 +1,7 @@
+/* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
 /* { dg-require-effective-target vect_simd_clones } */
 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
+/* { dg-additional-options "-msse4" { target sse4 } } */
 /* { dg-additional-options "-mavx" { target avx_runtime } } */
 /* { dg-additional-options "-mno-avx512f" { target { { i?86*-*-* x86_64-*-* } 
&& { ! lp64 } } } } */
 
diff --git a/gcc/tests

[gcc r15-7507] c++: P2308, Template parameter initialization (tests) [PR113800]

2025-02-13 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:84f19ecb01958fa791b9213dbd80331474fca9f0

commit r15-7507-g84f19ecb01958fa791b9213dbd80331474fca9f0
Author: Marek Polacek 
Date:   Wed Feb 12 13:33:37 2025 -0500

c++: P2308, Template parameter initialization (tests) [PR113800]

This proposal was implemented a long time ago by my r9-5271,
but it took me this long to verify that it still works as per P2308.

This patch adds assorted tests, both from clang and from [temp.arg.nontype].
Fortunately I did not discover any issues in the compiler.

PR c++/113800
DR 2450

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing15.C: New test.
* g++.dg/cpp2a/nontype-class68.C: New test.
* g++.dg/cpp2a/nontype-class69.C: New test.
* g++.dg/cpp2a/nontype-class70.C: New test.
* g++.dg/cpp2a/nontype-class71.C: New test.
* g++.dg/cpp2a/nontype-class72.C: New test.

Reviewed-by: Jason Merrill 

Diff:
---
 gcc/testsuite/g++.dg/cpp26/pack-indexing15.C | 20 
 gcc/testsuite/g++.dg/cpp2a/nontype-class68.C | 24 ++
 gcc/testsuite/g++.dg/cpp2a/nontype-class69.C | 27 
 gcc/testsuite/g++.dg/cpp2a/nontype-class70.C | 47 
 gcc/testsuite/g++.dg/cpp2a/nontype-class71.C | 19 +++
 gcc/testsuite/g++.dg/cpp2a/nontype-class72.C | 41 
 6 files changed, 178 insertions(+)

diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing15.C 
b/gcc/testsuite/g++.dg/cpp26/pack-indexing15.C
new file mode 100644
index ..3f8382b12cd2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/pack-indexing15.C
@@ -0,0 +1,20 @@
+// PR c++/113800
+// { dg-do compile { target c++26 } }
+// From LLVM's temp_arg_nontype_cxx2c.cpp.
+
+template
+concept C = sizeof(T...[1]) == 1;
+
+struct A {};
+
+template auto = A{}> struct Set {};
+
+template
+void
+foo ()
+{
+  Set u;
+}
+
+Set sb;
+Set sf; // { dg-error "placeholder constraints not satisfied" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class68.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class68.C
new file mode 100644
index ..ade646e391b1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class68.C
@@ -0,0 +1,24 @@
+// PR c++/113800
+// { dg-do compile { target c++20 } }
+// From [temp.arg.nontype].
+
+template struct B { /* ... */ };
+B<5> b1;// OK, template parameter type is int
+B<'a'> b2;  // OK, template parameter type is char
+B<2.5> b3;  // OK, template parameter type is double
+B b4;  // { dg-error ".void. is not a valid type for 
a template non-type parameter" }
+
+template struct C { /* ... */ };
+C<{ 42 }> c1;   // OK
+
+struct J1 {
+  J1 *self = this;
+};
+B j1; // { dg-error "not a constant expression" }
+
+struct J2 {
+  J2 *self = this;
+  constexpr J2() {}
+  constexpr J2(const J2&) {}
+};
+B j2; // { dg-error "not a constant expression" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class69.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class69.C
new file mode 100644
index ..08b0a5ef73cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class69.C
@@ -0,0 +1,27 @@
+// PR c++/113800
+// { dg-do compile { target c++20 } }
+
+// DR 2450
+struct S { int a; };
+
+template
+void
+f ()
+{
+}
+
+void
+test ()
+{
+  f<{0}>();
+  f<{.a= 0}>();
+}
+
+// DR 2459
+struct A {
+  constexpr A (float) {}
+};
+
+template
+struct X {};
+X<1> x;
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class70.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class70.C
new file mode 100644
index ..0e50847e440e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class70.C
@@ -0,0 +1,47 @@
+// PR c++/113800
+// P2308R1 - Template parameter initialization
+// { dg-do compile { target c++20 } }
+
+struct S {
+  int a = 0;
+  int b = 42;
+};
+
+template 
+struct A {
+  static constexpr auto a = t.a;
+  static constexpr auto b = t.b;
+};
+
+static_assert(A<{}>::a == 0);
+static_assert(A<{}>::b == 42);
+static_assert(A<{.a = 3}>::a == 3);
+static_assert(A<{.b = 4}>::b == 4);
+
+template
+struct D1 {};
+
+template
+struct D2 {};
+
+template 
+struct D3 {};
+
+struct E {};
+
+struct I {
+  constexpr I(E) {};
+};
+
+template
+struct W {};
+
+void
+g ()
+{
+  D1<> d1;
+  D2<> d2;
+  D3<> d3;
+
+  W w;
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class71.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class71.C
new file mode 100644
index ..36ce5b16deeb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class71.C
@@ -0,0 +1,19 @@
+// PR c++/113800
+// { dg-do compile { target c++20 } }
+// From LLVM's temp_arg_nontype_cxx2c.cpp.
+
+template
+struct A {
+  T x[I];
+};
+
+template
+A(T, U...) -> A;
+
+template void foo() { }
+
+void
+bar ()
+{
+  foo<{1}>();
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class72.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class72.C
new file mode 100644
index 0

[gcc r15-7501] build: Remove HAVE_LD_EH_FRAME_CIEV3

2025-02-13 Thread Rainer Orth via Gcc-cvs
https://gcc.gnu.org/g:7db94370a74481ad1db1f0a4dc4aa45fa464a02a

commit r15-7501-g7db94370a74481ad1db1f0a4dc4aa45fa464a02a
Author: Rainer Orth 
Date:   Thu Feb 13 10:17:50 2025 +0100

build: Remove HAVE_LD_EH_FRAME_CIEV3

Old versions of Solaris ld and GNU ld didn't support CIEv3 in .eh_frame.
To avoid this breaking the build

[build] Default to DWARF 4 on Solaris if linker supports CIEv3
http://gcc.gnu.org/ml/gcc-patches/2013-03/msg00669.html

checked for the necessary linker support, defaulting to DWARF-2 if
necessary.  Solaris ld was fixed in Solaris 11.1, GNU ld in binutils
2.16, so this is long obsolete and only used in Solaris code anyway.

This patch thus removes both the configure check and
solaris_override_options.

Bootstrapped without regressions on i386-pc-solaris2.11 and
sparc-sun-solaris2.11.

2025-02-12  Rainer Orth  

gcc:
* configure.ac (gcc_cv_ld_eh_frame_ciev3): Remove.
* configure, config.in: Regenerate.
* config/sol2.cc (solaris_override_options): Remove.
* config/sol2.h (SUBTARGET_OVERRIDE_OPTIONS): Remove.
* config/sol2-protos.h (solaris_override_options): Remove.

Diff:
---
 gcc/config.in|  6 --
 gcc/config/sol2-protos.h |  1 -
 gcc/config/sol2.cc   |  9 -
 gcc/config/sol2.h|  5 -
 gcc/configure| 40 
 gcc/configure.ac | 36 
 6 files changed, 97 deletions(-)

diff --git a/gcc/config.in b/gcc/config.in
index 3b06533c4829..45ae9fb222eb 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1773,12 +1773,6 @@
 #endif
 
 
-/* Define 0/1 if your linker supports CIE v3 in .eh_frame. */
-#ifndef USED_FOR_TARGET
-#undef HAVE_LD_EH_FRAME_CIEV3
-#endif
-
-
 /* Define if your linker supports .eh_frame_hdr. */
 #undef HAVE_LD_EH_FRAME_HDR
 
diff --git a/gcc/config/sol2-protos.h b/gcc/config/sol2-protos.h
index 2462b475c7fc..70dd9583e6ce 100644
--- a/gcc/config/sol2-protos.h
+++ b/gcc/config/sol2-protos.h
@@ -24,7 +24,6 @@ extern void solaris_elf_asm_comdat_section (const char *, 
unsigned int, tree);
 extern void solaris_file_end (void);
 extern void solaris_insert_attributes (tree, tree *);
 extern void solaris_output_init_fini (FILE *, tree);
-extern void solaris_override_options (void);
 
 /* In sol2-c.cc.  */
 extern void solaris_register_pragmas (void);
diff --git a/gcc/config/sol2.cc b/gcc/config/sol2.cc
index 9bd9722dff72..f46bcfaf0023 100644
--- a/gcc/config/sol2.cc
+++ b/gcc/config/sol2.cc
@@ -291,12 +291,3 @@ solaris_file_end (void)
   solaris_comdat_htab->traverse 
 (NULL);
 }
-
-void
-solaris_override_options (void)
-{
-  /* Older versions of Solaris ld cannot handle CIE version 3 in .eh_frame.
- Don't emit DWARF3/4 unless specifically selected if so.  */
-  if (!HAVE_LD_EH_FRAME_CIEV3 && !OPTION_SET_P (dwarf_version))
-dwarf_version = 2;
-}
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
index 9618b43c6178..2405c101aee3 100644
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -119,11 +119,6 @@ along with GCC; see the file COPYING3.  If not see
 TARGET_SUB_OS_CPP_BUILTINS();  \
   } while (0)
 
-#define SUBTARGET_OVERRIDE_OPTIONS \
-  do { \
-solaris_override_options ();   \
-  } while (0)
-
 #if DEFAULT_ARCH32_P
 #define MULTILIB_DEFAULTS { "m32" }
 #else
diff --git a/gcc/configure b/gcc/configure
index e36d1d91612a..69a9cf7af5f5 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -32335,46 +32335,6 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_eh_frame_hdr" >&5
 $as_echo "$gcc_cv_ld_eh_frame_hdr" >&6; }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linker CIEv3 in .eh_frame 
support" >&5
-$as_echo_n "checking linker CIEv3 in .eh_frame support... " >&6; }
-gcc_cv_ld_eh_frame_ciev3=no
-if test $in_tree_ld = yes ; then
-  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 
16 -o "$gcc_cv_gld_major_version" -gt 2 \
- && test $in_tree_ld_is_elf = yes; then
-gcc_cv_ld_eh_frame_ciev3=yes
-  fi
-elif test x$gcc_cv_ld != x; then
-  if echo "$ld_ver" | grep GNU > /dev/null; then
-gcc_cv_ld_eh_frame_ciev3=yes
-if test 0"$ld_date" -lt 20040513; then
-  if test -n "$ld_date"; then
-   # If there was date string, but was earlier than 2004-05-13, fail
-   gcc_cv_ld_eh_frame_ciev3=no
-  elif test "$ld_vers_major" -lt 2; then
-   gcc_cv_ld_eh_frame_ciev3=no
-  elif test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -lt 16; then
-   gcc_cv_ld_eh_frame_ciev3=no
-  fi
-fi
-  else
-case "$target" in
-  *-*-solaris2*)
-# Sun ld added support for CIE v3 in .eh_frame in Solaris 11.1.
-if test "$ld_vers_major" -gt 1 || test "$ld_vers_minor" -ge 2324; then
-

[gcc r15-7500] doc: Update install.texi for GCC 15 on Solaris

2025-02-13 Thread Rainer Orth via Gcc-cvs
https://gcc.gnu.org/g:85b0a6e853aeda30acc1990c8bf13951c7e4da7d

commit r15-7500-g85b0a6e853aeda30acc1990c8bf13951c7e4da7d
Author: Rainer Orth 
Date:   Thu Feb 13 09:59:43 2025 +0100

doc: Update install.texi for GCC 15 on Solaris

Apart from minor updates, this patch is primarily an important caveat
about binutils PR ld/32580, which has broken the binutils 2.44 ld on
Solaris/x86.

Tested on i386-pc-solaris2.11.

2025-02-11  Rainer Orth  

gcc:
* doc/install.texi (Specific, *-*-solaris2*): Updates for newer
Solaris 11.4 SRUs and binutils 2.44.

Diff:
---
 gcc/doc/install.texi | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index bd7a38048eb3..08892c676e31 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4840,7 +4840,7 @@ Support for Solaris 10 has been removed in GCC 10.  
Support for Solaris
 9 has been removed in GCC 5.  Support for Solaris 8 has been removed in
 GCC 4.8.  Support for Solaris 7 has been removed in GCC 4.6.
 
-Solaris 11.4 provides one or more of GCC 5, 7, 9, 10, 11, 12, and 13.
+Solaris 11.4 provides one or more of GCC 5, 7, 9, 10, 11, 12, 13, and 14.
 
 You need to install the @code{system/header}, @code{system/linker}, and
 @code{developer/assembler} packages.
@@ -4862,7 +4862,7 @@ conjunction with the Solaris linker.
 The GNU @command{as} versions included in Solaris 11.4, from GNU
 binutils 2.30.1 or newer (in @file{/usr/bin/gas} and
 @file{/usr/gnu/bin/as}), are known to work.  The version from GNU
-binutils 2.42 is known to work as well.  Recent versions of the Solaris
+binutils 2.44 is known to work as well.  Recent versions of the Solaris
 assembler in @file{/usr/bin/as} work almost as well, though.  To use GNU
 @command{as}, configure with the options @option{--with-gnu-as
 --with-as=@//usr/@/gnu/@/bin/@/as}.
@@ -4870,9 +4870,12 @@ assembler in @file{/usr/bin/as} work almost as well, 
though.  To use GNU
 For linking, the Solaris linker is preferred.  If you want to use the
 GNU linker instead, the version in Solaris 11.4, from GNU binutils
 2.30.1 or newer (in @file{/usr/gnu/bin/ld} and @file{/usr/bin/gld}),
-works, as does the version from GNU binutils 2.42.  However, it
+works.  However, it
 generally lacks platform specific features, so better stay with Solaris
-@command{ld}.  To use the LTO linker plugin
+@command{ld}.  When using the version from GNU binutils 2.44, there's
+an important caveat: binutils @emph{must} be configured with
+@code{CONFIG_SHELL=/bin/bash}, otherwise the linker's built-in linker
+scripts get corrupted on x86.  To use the LTO linker plugin
 (@option{-fuse-linker-plugin}) with GNU @command{ld}, GNU binutils
 @emph{must} be configured with @option{--enable-largefile}.  To use
 Solaris @command{ld}, we recommend to configure with
@@ -4894,7 +4897,7 @@ will be disabled if no appropriate version is found.  
Solaris
 work.
 
 In order to build the GNU Ada compiler, GNAT, a working GNAT is needed.
-Since Solaris 11.4 SRU 39, GNAT 11, 12 or 13 is bundled in the
+Since Solaris 11.4 SRU 39, GNAT 11, 12, 13 or 14 is bundled in the
 @code{developer/gcc/gcc-gnat} package.
 
 In order to build the GNU D compiler, GDC, a working @samp{libphobos} is


[gcc(refs/users/aoliva/heads/testme)] [testsuite] fix check-function-bodies usage

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:4e2f34ff0de1794e28b98250ed9125fdf7ead58c

commit 4e2f34ff0de1794e28b98250ed9125fdf7ead58c
Author: Alexandre Oliva 
Date:   Tue Feb 11 01:59:39 2025 -0300

[testsuite] fix check-function-bodies usage

The existing usage comment for check-function-bodies is presumably a
typo, as it doesn't match existing uses.  Fix it.


for  gcc/testsuite/ChangeLog

* lib/scanasm.exp (check-function-bodies): Fix usage comment.

Diff:
---
 gcc/testsuite/lib/scanasm.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index beffedd5bce4..97935cb23c3c 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -985,7 +985,7 @@ proc check_function_body { functions name body_regexp } {
 
 # Check the implementations of functions against expected output.  Used as:
 #
-# { dg-do { check-function-bodies PREFIX TERMINATOR[ OPTION[ SELECTOR 
[MATCHED]]] } }
+# { dg-final { check-function-bodies PREFIX TERMINATOR[ OPTION[ SELECTOR 
[MATCHED]]] } }
 #
 # See sourcebuild.texi for details.


[gcc/aoliva/heads/testme] (4 commits) [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 f39dde7887f0... [ifcombine] cope with signbit tests of extended values

It previously pointed to:

 b9e7c101eafc... [testsuite] add x86 effective target

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  b9e7c10... [testsuite] add x86 effective target
  dec20eb... [testsuite] adjust expectations of x86 vect-simd-clone test
  5f3ee43... [testsuite] fix check-function-bodies usage


Summary of changes (added commits):
---

  f39dde7... [ifcombine] cope with signbit tests of extended values
  2a10285... [testsuite] add x86 effective target
  7adffbc... [testsuite] adjust expectations of x86 vect-simd-clone test
  4e2f34f... [testsuite] fix check-function-bodies usage


[gcc r15-7503] testsuite: Add another range for coroutines testcase [PR118574]

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

commit r15-7503-ga1855a3e0bcf0f94bc9fa421ccc9ebd0565c62cd
Author: Jakub Jelinek 
Date:   Thu Feb 13 11:53:04 2025 +0100

testsuite: Add another range for coroutines testcase [PR118574]

This patch adds another range for coroutine testcase, which doesn't
extend (across co_await) just the __for_range var and what it binds
to (so passes even without -frange-for-ext-temps), but also some other
temporaries and verifies they are destructed in the right order.

2025-02-13  Jakub Jelinek  

PR c++/118574
* g++.dg/coroutines/range-for2.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/coroutines/range-for2.C | 92 
 1 file changed, 92 insertions(+)

diff --git a/gcc/testsuite/g++.dg/coroutines/range-for2.C 
b/gcc/testsuite/g++.dg/coroutines/range-for2.C
new file mode 100644
index ..14372f39855a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/range-for2.C
@@ -0,0 +1,92 @@
+// PR c++/118574
+// { dg-do run }
+// { dg-additional-options "-std=c++23 -O2" }
+
+#include 
+
+[[gnu::noipa]] void
+baz (int *)
+{
+}
+
+struct D {
+  D () : d (new int (42)) {}
+  ~D () { if (*d != 42) __builtin_abort (); *d = 0; baz (d); delete d; }
+  int *d;
+};
+
+struct E {
+  E (const D &x) : e (x) {}
+  void test () const { if (*e.d != 42) __builtin_abort (); }
+  ~E () { test (); }
+  const D &e;
+};
+
+struct A {
+  const char **a = nullptr;
+  int n = 0;
+  const E *e1 = nullptr;
+  const E *e2 = nullptr;
+  void test () const { if (e1) e1->test (); if (e2) e2->test (); }
+  void push_back (const char *x) { test (); if (!a) a = new const char *[2]; 
a[n++] = x; }
+  const char **begin () const { test (); return a; }
+  const char **end () const { test (); return a + n; }
+  ~A () { test (); delete[] a; }
+};
+
+struct B {
+  long ns;
+  bool await_ready () const noexcept { return false; }
+  void await_suspend (std::coroutine_handle<> h) const noexcept {
+volatile int v = 0;
+while (v < ns)
+  v = v + 1;
+h.resume ();
+  }
+  void await_resume () const noexcept {}
+};
+
+struct C {
+  struct promise_type {
+const char *value;
+std::suspend_never initial_suspend () { return {}; }
+std::suspend_always final_suspend () noexcept { return {}; }
+void return_value (const char *v) { value = v; }
+void unhandled_exception () { __builtin_abort (); }
+C get_return_object () { return C{this}; }
+  };
+  promise_type *p;
+  explicit C (promise_type *p) : p(p) {}
+  const char *get () { return p->value; }
+};
+
+A
+foo (const E &e1, const E &e2)
+{
+  A a;
+  a.e1 = &e1;
+  a.e2 = &e2;
+  a.push_back ("foo");
+  a.push_back ("bar");
+  return a;
+}
+
+C
+bar ()
+{
+  A ret;
+  for (const auto &item : foo (E{D {}}, E{D {}}))
+{
+  co_await B{20};
+  ret.push_back (item);
+}
+  co_return "foobar";
+}
+
+int
+main ()
+{
+  auto task = bar ();
+  if (__builtin_strcmp (task.get (), "foobar"))
+__builtin_abort ();
+}


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:63c14ae67e0842aa377505ebc97d00a35ddc9513

commit 63c14ae67e0842aa377505ebc97d00a35ddc9513
Author: Alexandre Oliva 
Date:   Thu Feb 13 07:36:04 2025 -0300

[ifcombine] cope with signbit tests of extended values

A compare with zero may be taken as a sign bit test by
fold_truth_andor_for_ifcombine, but the operand may be extended from a
narrower field.  If the operand was narrower, the bitsize will reflect
the narrowing conversion, but if it was wider, we'll only know whether
the field is sign- or zero-extended from unsignedp, but we won't know
whether it needed to be extended, because arg will have changed to the
narrower variable when we get to the point in which we can compute the
arg width.  If it's sign-extended, we're testing the right bit, but if
it's zero-extended, there isn't any bit we can test.

Instead of punting and leaving the foldable compare to be figured out
by another pass, arrange for the sign bit resulting from the widening
zero-extension to be taken as zero, so that the modified compare will
yield the desired result.

While at that, avoid swapping the right-hand compare operands when
we've already determined that it was a signbit test: it no use to even
try.


for  gcc/ChangeLog

PR tree-optimization/118805
* gimple-fold.cc (fold_truth_andor_for_combine): Detect and
cope with zero-extension in signbit tests.  Reject swapping
right-compare operands if rsignbit.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118805
* gcc.dg/field-merge-26.c: New.

Diff:
---
 gcc/gimple-fold.cc| 22 +-
 gcc/testsuite/gcc.dg/field-merge-26.c | 18 ++
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 29191685a43c..90b0ec6d79a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8090,14 +8090,16 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
 
   /* Prepare to turn compares of signed quantities with zero into sign-bit
  tests.  We need not worry about *_reversep here for these compare
- rewrites: loads will have already been reversed before compares.  */
-  bool lsignbit = false, rsignbit = false;
+ rewrites: loads will have already been reversed before compares.  Save the
+ precision, because [lr]l_arg may change and we won't be able to tell how
+ wide it was originally.  */
+  unsigned lsignbit = 0, rsignbit = 0;
   if ((lcode == LT_EXPR || lcode == GE_EXPR)
   && integer_zerop (lr_arg)
   && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (ll_arg)))
 {
-  lsignbit = true;
+  lsignbit = TYPE_PRECISION (TREE_TYPE (ll_arg));
   lcode = (lcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   /* Turn compares of unsigned quantities with powers of two into
@@ -8130,7 +8132,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   && INTEGRAL_TYPE_P (TREE_TYPE (rl_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (rl_arg)))
 {
-  rsignbit = true;
+  rsignbit = TYPE_PRECISION (TREE_TYPE (rl_arg));
   rcode = (rcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   else if ((rcode == LT_EXPR || rcode == GE_EXPR)
@@ -8204,7 +8206,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   || ! operand_equal_p (ll_inner, rl_inner, 0))
 {
   /* Try swapping the operands.  */
-  if (ll_reversep != rr_reversep
+  if (ll_reversep != rr_reversep || rsignbit
  || !operand_equal_p (ll_inner, rr_inner, 0))
return 0;
 
@@ -8284,6 +8286,14 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   if (lsignbit)
 {
   wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
+  /* If ll_arg is zero-extended and we're testing the sign bit, we know
+what the result should be.  Shifting the sign bit out of sign will get
+us to mask the entire field out, yielding zero, i.e., the sign bit of
+the zero-extended value.  We know the masked value is being compared
+with zero, so the compare will get us the result we're looking
+for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
+  if (lsignbit > ll_bitsize && ll_unsignedp)
+   sign <<= 1;
   if (!ll_and_mask.get_precision ())
ll_and_mask = sign;
   else
@@ -8303,6 +8313,8 @@ 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)
+   sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
   else
diff --git a/gcc/testsuite/gcc.dg/field-merge-26.c 
b/gcc/testsuite/gcc.dg/field-merge-26.c
new file mode 100644
index ..72e24462

[gcc(refs/users/aoliva/heads/testme)] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:61d1dddfddc9cd3f89d0309c895ad60872915f09

commit 61d1dddfddc9cd3f89d0309c895ad60872915f09
Author: Alexandre Oliva 
Date:   Thu Feb 13 07:36:04 2025 -0300

[ifcombine] cope with signbit tests of extended values

A compare with zero may be taken as a sign bit test by
fold_truth_andor_for_ifcombine, but the operand may be extended from a
narrower field.  If the operand was narrower, the bitsize will reflect
the narrowing conversion, but if it was wider, we'll only know whether
the field is sign- or zero-extended from unsignedp, but we won't know
whether it needed to be extended, because arg will have changed to the
narrower variable when we get to the point in which we can compute the
arg width.  If it's sign-extended, we're testing the right bit, but if
it's zero-extended, there isn't any bit we can test.

Instead of punting and leaving the foldable compare to be figured out
by another pass, arrange for the sign bit resulting from the widening
zero-extension to be taken as zero, so that the modified compare will
yield the desired result.

While at that, avoid swapping the right-hand compare operands when
we've already determined that it was a signbit test: it no use to even
try.


for  gcc/ChangeLog

PR tree-optimization/118805
* gimple-fold.cc (fold_truth_andor_for_combine): Detect and
cope with zero-extension in signbit tests.  Reject swapping
right-compare operands if rsignbit.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118805
* gcc.dg/field-merge-26.c: New.

Diff:
---
 gcc/gimple-fold.cc| 22 +-
 gcc/testsuite/gcc.dg/field-merge-26.c | 20 
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 29191685a43c..90b0ec6d79a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8090,14 +8090,16 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
 
   /* Prepare to turn compares of signed quantities with zero into sign-bit
  tests.  We need not worry about *_reversep here for these compare
- rewrites: loads will have already been reversed before compares.  */
-  bool lsignbit = false, rsignbit = false;
+ rewrites: loads will have already been reversed before compares.  Save the
+ precision, because [lr]l_arg may change and we won't be able to tell how
+ wide it was originally.  */
+  unsigned lsignbit = 0, rsignbit = 0;
   if ((lcode == LT_EXPR || lcode == GE_EXPR)
   && integer_zerop (lr_arg)
   && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (ll_arg)))
 {
-  lsignbit = true;
+  lsignbit = TYPE_PRECISION (TREE_TYPE (ll_arg));
   lcode = (lcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   /* Turn compares of unsigned quantities with powers of two into
@@ -8130,7 +8132,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   && INTEGRAL_TYPE_P (TREE_TYPE (rl_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (rl_arg)))
 {
-  rsignbit = true;
+  rsignbit = TYPE_PRECISION (TREE_TYPE (rl_arg));
   rcode = (rcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   else if ((rcode == LT_EXPR || rcode == GE_EXPR)
@@ -8204,7 +8206,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   || ! operand_equal_p (ll_inner, rl_inner, 0))
 {
   /* Try swapping the operands.  */
-  if (ll_reversep != rr_reversep
+  if (ll_reversep != rr_reversep || rsignbit
  || !operand_equal_p (ll_inner, rr_inner, 0))
return 0;
 
@@ -8284,6 +8286,14 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   if (lsignbit)
 {
   wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
+  /* If ll_arg is zero-extended and we're testing the sign bit, we know
+what the result should be.  Shifting the sign bit out of sign will get
+us to mask the entire field out, yielding zero, i.e., the sign bit of
+the zero-extended value.  We know the masked value is being compared
+with zero, so the compare will get us the result we're looking
+for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
+  if (lsignbit > ll_bitsize && ll_unsignedp)
+   sign <<= 1;
   if (!ll_and_mask.get_precision ())
ll_and_mask = sign;
   else
@@ -8303,6 +8313,8 @@ 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)
+   sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
   else
diff --git a/gcc/testsuite/gcc.dg/field-merge-26.c 
b/gcc/testsuite/gcc.dg/field-merge-26.c
new file mode 100644
index ..6e165d

[gcc/aoliva/heads/testme] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 61d1dddfddc9... [ifcombine] cope with signbit tests of extended values

It previously pointed to:

 63c14ae67e08... [ifcombine] cope with signbit tests of extended values

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  63c14ae... [ifcombine] cope with signbit tests of extended values


Summary of changes (added commits):
---

  61d1ddd... [ifcombine] cope with signbit tests of extended values


[gcc/aoliva/heads/testme] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
The branch 'aoliva/heads/testme' was updated to point to:

 cf2e0f411bea... [ifcombine] cope with signbit tests of extended values

It previously pointed to:

 61d1dddfddc9... [ifcombine] cope with signbit tests of extended values

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  61d1ddd... [ifcombine] cope with signbit tests of extended values


Summary of changes (added commits):
---

  cf2e0f4... [ifcombine] cope with signbit tests of extended values


[gcc(refs/users/aoliva/heads/testme)] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:cf2e0f411bea79746e2f399bd5642ba0861a6d89

commit cf2e0f411bea79746e2f399bd5642ba0861a6d89
Author: Alexandre Oliva 
Date:   Thu Feb 13 07:36:04 2025 -0300

[ifcombine] cope with signbit tests of extended values

A compare with zero may be taken as a sign bit test by
fold_truth_andor_for_ifcombine, but the operand may be extended from a
narrower field.  If the operand was narrower, the bitsize will reflect
the narrowing conversion, but if it was wider, we'll only know whether
the field is sign- or zero-extended from unsignedp, but we won't know
whether it needed to be extended, because arg will have changed to the
narrower variable when we get to the point in which we can compute the
arg width.  If it's sign-extended, we're testing the right bit, but if
it's zero-extended, there isn't any bit we can test.

Instead of punting and leaving the foldable compare to be figured out
by another pass, arrange for the sign bit resulting from the widening
zero-extension to be taken as zero, so that the modified compare will
yield the desired result.

While at that, avoid swapping the right-hand compare operands when
we've already determined that it was a signbit test: it no use to even
try.


for  gcc/ChangeLog

PR tree-optimization/118805
* gimple-fold.cc (fold_truth_andor_for_combine): Detect and
cope with zero-extension in signbit tests.  Reject swapping
right-compare operands if rsignbit.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118805
* gcc.dg/field-merge-26.c: New.

Diff:
---
 gcc/gimple-fold.cc| 22 +-
 gcc/testsuite/gcc.dg/field-merge-26.c | 20 
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 29191685a43c..90b0ec6d79a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8090,14 +8090,16 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
 
   /* Prepare to turn compares of signed quantities with zero into sign-bit
  tests.  We need not worry about *_reversep here for these compare
- rewrites: loads will have already been reversed before compares.  */
-  bool lsignbit = false, rsignbit = false;
+ rewrites: loads will have already been reversed before compares.  Save the
+ precision, because [lr]l_arg may change and we won't be able to tell how
+ wide it was originally.  */
+  unsigned lsignbit = 0, rsignbit = 0;
   if ((lcode == LT_EXPR || lcode == GE_EXPR)
   && integer_zerop (lr_arg)
   && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (ll_arg)))
 {
-  lsignbit = true;
+  lsignbit = TYPE_PRECISION (TREE_TYPE (ll_arg));
   lcode = (lcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   /* Turn compares of unsigned quantities with powers of two into
@@ -8130,7 +8132,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   && INTEGRAL_TYPE_P (TREE_TYPE (rl_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (rl_arg)))
 {
-  rsignbit = true;
+  rsignbit = TYPE_PRECISION (TREE_TYPE (rl_arg));
   rcode = (rcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   else if ((rcode == LT_EXPR || rcode == GE_EXPR)
@@ -8204,7 +8206,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   || ! operand_equal_p (ll_inner, rl_inner, 0))
 {
   /* Try swapping the operands.  */
-  if (ll_reversep != rr_reversep
+  if (ll_reversep != rr_reversep || rsignbit
  || !operand_equal_p (ll_inner, rr_inner, 0))
return 0;
 
@@ -8284,6 +8286,14 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   if (lsignbit)
 {
   wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
+  /* If ll_arg is zero-extended and we're testing the sign bit, we know
+what the result should be.  Shifting the sign bit out of sign will get
+us to mask the entire field out, yielding zero, i.e., the sign bit of
+the zero-extended value.  We know the masked value is being compared
+with zero, so the compare will get us the result we're looking
+for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
+  if (lsignbit > ll_bitsize && ll_unsignedp)
+   sign <<= 1;
   if (!ll_and_mask.get_precision ())
ll_and_mask = sign;
   else
@@ -8303,6 +8313,8 @@ 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)
+   sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
   else
diff --git a/gcc/testsuite/gcc.dg/field-merge-26.c 
b/gcc/testsuite/gcc.dg/field-merge-26.c
new file mode 100644
index ..b37607

[gcc(refs/users/aoliva/heads/testme)] [testsuite] add x86 effective target

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:2a10285fd76af8507cc580b52a6c8681b857a644

commit 2a10285fd76af8507cc580b52a6c8681b857a644
Author: Alexandre Oliva 
Date:   Tue Feb 11 00:13:43 2025 -0300

[testsuite] add x86 effective target

I got tired of repeating the conditional that recognizes ia32 or
x86_64, and introduced 'x86' as a shorthand for that, adjusting all
occurrences in target-supports.exp, to set an example.  I found some
patterns that recognized i?86* and x86_64*, but I took those as likely
cut&pastos instead of trying to preserve those weirdnesses.


for  gcc/ChangeLog

* doc/sourcebuild.texi: Add x86 effective target.

for  gcc/testsuite/ChangeLog

* lib/target-supports.exp (check_effective_target_x86): New.
Replace all uses of i?86-*-* and x86_64-*-* in this file.

Diff:
---
 gcc/doc/sourcebuild.texi  |   3 +
 gcc/testsuite/lib/target-supports.exp | 188 +-
 2 files changed, 99 insertions(+), 92 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 255d1a451e44..d4e2a13dd77a 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2801,6 +2801,9 @@ Target supports the execution of @code{user_msr} 
instructions.
 @item vect_cmdline_needed
 Target requires a command line argument to enable a SIMD instruction set.
 
+@item x86
+Target is ia32 or x86_64.
+
 @item xorsign
 Target supports the xorsign optab expansion.
 
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 60e24129bd58..035f82eb86c9 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -740,7 +740,7 @@ proc check_profiling_available { test_what } {
 }
 
 if { $test_what == "-fauto-profile" } {
-   if { !([istarget i?86-*-linux*] || [istarget x86_64-*-linux*]) } {
+   if { !([check_effective_target_x86] && [istarget *-*-linux*]) } {
verbose "autofdo only supported on linux"
return 0
}
@@ -2616,17 +2616,23 @@ proc remove_options_for_riscv_zvbb { flags } {
 return [add_options_for_riscv_z_ext zvbb $flags]
 }
 
+# Return 1 if the target is ia32 or x86_64.
+
+proc check_effective_target_x86 { } {
+if { ([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
+   return 1
+} else {
+return 0
+}
+}
+
 # Return 1 if the target OS supports running SSE executables, 0
 # otherwise.  Cache the result.
 
 proc check_sse_os_support_available { } {
 return [check_cached_effective_target sse_os_support_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
-   expr 0
-   } else {
-   expr 1
-   }
+   expr [check_effective_target_x86]
 }]
 }
 
@@ -2636,7 +2642,7 @@ proc check_sse_os_support_available { } {
 proc check_avx_os_support_available { } {
 return [check_cached_effective_target avx_os_support_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
# Check that OS has AVX and SSE saving enabled.
@@ -2659,7 +2665,7 @@ proc check_avx_os_support_available { } {
 proc check_avx512_os_support_available { } {
 return [check_cached_effective_target avx512_os_support_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
# Check that OS has AVX512, AVX and SSE saving enabled.
@@ -2682,7 +2688,7 @@ proc check_avx512_os_support_available { } {
 proc check_sse_hw_available { } {
 return [check_cached_effective_target sse_hw_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
check_runtime_nocache sse_hw_available {
@@ -2706,7 +2712,7 @@ proc check_sse_hw_available { } {
 proc check_sse2_hw_available { } {
 return [check_cached_effective_target sse2_hw_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effective_target_x86]) } {
expr 0
} else {
check_runtime_nocache sse2_hw_available {
@@ -2730,7 +2736,7 @@ proc check_sse2_hw_available { } {
 proc check_sse4_hw_available { } {
 return [check_cached_effective_target sse4_hw_available {
# If this is not the right target then we can skip the test.
-   if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+   if { !([check_effe

[gcc(refs/users/aoliva/heads/testme)] [ifcombine] cope with signbit tests of extended values

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:f39dde7887f03b4799747bd0ac0d857ec60f1220

commit f39dde7887f03b4799747bd0ac0d857ec60f1220
Author: Alexandre Oliva 
Date:   Thu Feb 13 07:36:04 2025 -0300

[ifcombine] cope with signbit tests of extended values

A compare with zero may be taken as a sign bit test by
fold_truth_andor_for_ifcombine, but the operand may be extended from a
narrower field.  If the operand was narrower, the bitsize will reflect
the narrowing conversion, but if it was wider, we'll only know whether
the field is sign- or zero-extended from unsignedp, but we won't know
whether it needed to be extended, because arg will have changed to the
narrower variable when we get to the point in which we can compute the
arg width.  If it's sign-extended, we're testing the right bit, but if
it's zero-extended, there isn't any bit we can test.

Instead of punting and leaving the foldable compare to be figured out
by another pass, arrange for the sign bit resulting from the widening
zero-extension to be taken as zero, so that the modified compare will
yield the desired result.

While at that, avoid swapping the right-hand compare operands when
we've already determined that it was a signbit test: it no use to even
try.


for  gcc/ChangeLog

PR tree-optimization/118805
* gimple-fold.cc (fold_truth_andor_for_combine): Detect and
cope with zero-extension in signbit tests.  Reject swapping
right-compare operands if rsignbit.

for  gcc/testsuite/ChangeLog

PR tree-optimization/118805
* gcc.dg/field-merge-26.c: New.

Diff:
---
 gcc/gimple-fold.cc| 22 +-
 gcc/testsuite/gcc.dg/field-merge-26.c | 16 
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 29191685a43c..90b0ec6d79a3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8090,14 +8090,16 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
 
   /* Prepare to turn compares of signed quantities with zero into sign-bit
  tests.  We need not worry about *_reversep here for these compare
- rewrites: loads will have already been reversed before compares.  */
-  bool lsignbit = false, rsignbit = false;
+ rewrites: loads will have already been reversed before compares.  Save the
+ precision, because [lr]l_arg may change and we won't be able to tell how
+ wide it was originally.  */
+  unsigned lsignbit = 0, rsignbit = 0;
   if ((lcode == LT_EXPR || lcode == GE_EXPR)
   && integer_zerop (lr_arg)
   && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (ll_arg)))
 {
-  lsignbit = true;
+  lsignbit = TYPE_PRECISION (TREE_TYPE (ll_arg));
   lcode = (lcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   /* Turn compares of unsigned quantities with powers of two into
@@ -8130,7 +8132,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   && INTEGRAL_TYPE_P (TREE_TYPE (rl_arg))
   && !TYPE_UNSIGNED (TREE_TYPE (rl_arg)))
 {
-  rsignbit = true;
+  rsignbit = TYPE_PRECISION (TREE_TYPE (rl_arg));
   rcode = (rcode == LT_EXPR ? NE_EXPR : EQ_EXPR);
 }
   else if ((rcode == LT_EXPR || rcode == GE_EXPR)
@@ -8204,7 +8206,7 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree 
truth_type,
   || ! operand_equal_p (ll_inner, rl_inner, 0))
 {
   /* Try swapping the operands.  */
-  if (ll_reversep != rr_reversep
+  if (ll_reversep != rr_reversep || rsignbit
  || !operand_equal_p (ll_inner, rr_inner, 0))
return 0;
 
@@ -8284,6 +8286,14 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   if (lsignbit)
 {
   wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
+  /* If ll_arg is zero-extended and we're testing the sign bit, we know
+what the result should be.  Shifting the sign bit out of sign will get
+us to mask the entire field out, yielding zero, i.e., the sign bit of
+the zero-extended value.  We know the masked value is being compared
+with zero, so the compare will get us the result we're looking
+for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
+  if (lsignbit > ll_bitsize && ll_unsignedp)
+   sign <<= 1;
   if (!ll_and_mask.get_precision ())
ll_and_mask = sign;
   else
@@ -8303,6 +8313,8 @@ 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)
+   sign <<= 1;
   if (!rl_and_mask.get_precision ())
rl_and_mask = sign;
   else
diff --git a/gcc/testsuite/gcc.dg/field-merge-26.c 
b/gcc/testsuite/gcc.dg/field-merge-26.c
new file mode 100644
index ..3e36fa696e

[gcc(refs/users/aoliva/heads/testme)] [testsuite] adjust expectations of x86 vect-simd-clone tests

2025-02-13 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:7adffbcb3ada7046e118bb3b61588e02de5f142f

commit 7adffbcb3ada7046e118bb3b61588e02de5f142f
Author: Alexandre Oliva 
Date:   Tue Feb 11 00:13:43 2025 -0300

[testsuite] adjust expectations of x86 vect-simd-clone tests

Some vect-simd-clone tests fail when targeting ancient x86 variants,
because the expected transformations only take place with -msse4 or
higher.

So arrange for these tests to take an -msse4 option on x86, so that
the expected vectorization takes place, but decay to a compile test if
vect.exp would enable execution but the target doesn't have an sse4
runtime.  This requires the new dg-do-if to override the action on a
target while retaining the default action on others, instead of
disabling the test.

We can count on avx512f compile-time support for these tests, because
vect_simd_clones requires that on x86, and that implies sse4 support,
so we need not complicate the scan conditionals with tests for sse4,
except on the last test.


for  gcc/ChangeLog

* doc/sourcebuild.texi (dg-do-if): Document.

for  gcc/testsuite/ChangeLog

* lib/target-supports-dg.exp (dg-do-if): New.
* gcc.dg/vect/vect-simd-clone-16f.c: Use -msse4 on x86, and
skip in case execution is enabled but the runtime isn't.
* gcc.dg/vect/vect-simd-clone-17f.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18f.c: Likewise.
* gcc.dg/vect/vect-simd-clone-20.c: Likewise, but only skip
the scan test.

Diff:
---
 gcc/doc/sourcebuild.texi|  5 +
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c |  2 ++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c |  2 ++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c |  2 ++
 gcc/testsuite/gcc.dg/vect/vect-simd-clone-20.c  |  6 +++--
 gcc/testsuite/lib/target-supports-dg.exp| 29 +
 6 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 98ede70f23c0..255d1a451e44 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1128,6 +1128,11 @@ by the specified floating-point factor.
 @subsubsection Skip a test for some targets
 
 @table @code
+@item @{ dg-do-if @var{action} @{ @var{selector} @} @}
+Same as dg-do if the selector matches and the test hasn't already been
+marked as unsupported.  Use it to override an action on a target while
+leaving the default action alone for other targets.
+
 @item @{ dg-skip-if @var{comment} @{ @var{selector} @} [@{ @var{include-opts} 
@} [@{ @var{exclude-opts} @}]] @}
 Arguments @var{include-opts} and @var{exclude-opts} are lists in which
 each element is a string of zero or more GCC options.
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c
index 7cd29e894d05..bb3b081b0e3d 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16f.c
@@ -1,5 +1,7 @@
+/* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
 /* { dg-require-effective-target vect_simd_clones } */
 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
+/* { dg-additional-options "-msse4" { target sse4 } } */
 /* { dg-additional-options "-mavx" { target avx_runtime } } */
 /* { dg-additional-options "-mno-avx512f" { target { { i?86*-*-* x86_64-*-* } 
&& { ! lp64 } } } } */
 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c
index 177521dc4453..504465614c98 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17f.c
@@ -1,5 +1,7 @@
+/* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
 /* { dg-require-effective-target vect_simd_clones } */
 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
+/* { dg-additional-options "-msse4" { target sse4 } } */
 /* { dg-additional-options "-mavx" { target avx_runtime } } */
 /* { dg-additional-options "-mno-avx512f" { target { { i?86*-*-* x86_64-*-* } 
&& { ! lp64 } } } } */
 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c
index 4dd51381d73c..0c418d432482 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18f.c
@@ -1,5 +1,7 @@
+/* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
 /* { dg-require-effective-target vect_simd_clones } */
 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
+/* { dg-additional-options "-msse4" { target sse4 } } */
 /* { dg-additional-options "-mavx" { target avx_runtime } } */
 /* { dg-additional-options "-mno-avx512f" { target { { i?86*-*-* x86_64-*-* } 
&& { ! lp64 } } } } */
 
diff --git a/gcc/tests

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Factorisation set_descriptor_dimension

2025-02-13 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:305e39d4521a02d6f7327d938dd8a714951c77e0

commit 305e39d4521a02d6f7327d938dd8a714951c77e0
Author: Mikael Morin 
Date:   Thu Feb 13 20:26:47 2025 +0100

Factorisation set_descriptor_dimension

Diff:
---
 gcc/fortran/trans-array.cc | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index ba040d25241d..80307be1a212 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1904,6 +1904,9 @@ set_bounds_update_offset (stmtblock_t *block, tree desc, 
int dim,
 gfc_conv_descriptor_stride_set (block, desc,
gfc_rank_cst[dim], stride);
 
+  if (!offset && !next_stride)
+return;
+
   /* Update offset.  */
   tree tmp = fold_build2_loc (input_location, MULT_EXPR,
  gfc_array_index_type, lbound_diff, stride);
@@ -3650,13 +3653,8 @@ set_temporary_descriptor (stmtblock_t *block, tree desc, 
tree class_src,
   for (n = 0; n < rank; n++)
{
  /* Store the stride and bound components in the descriptor.  */
- gfc_conv_descriptor_stride_set (block, desc, gfc_rank_cst[n],
- stride[n]);
-
- gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[n],
- gfc_index_zero_node);
-
- gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[n], 
ubound[n]);
+ set_descriptor_dimension (block, desc, n, gfc_index_zero_node, 
ubound[n],
+   srtide[n], nullptr, nullptr);
}
 }


[gcc r15-7511] c++: use -Wprio-ctor-dtor for attribute init_priority

2025-02-13 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:4e7f74225116e76caa65c5ce2815c2714343dfbc

commit r15-7511-g4e7f74225116e76caa65c5ce2815c2714343dfbc
Author: Jason Merrill 
Date:   Wed Feb 12 23:21:25 2025 +0100

c++: use -Wprio-ctor-dtor for attribute init_priority

gcc/cp/ChangeLog:

* tree.cc (handle_init_priority_attribute): Use OPT_prio_ctor_dtor.

gcc/testsuite/ChangeLog:

* g++.dg/special/initp1.C: Test disabling -Wprio-ctor-dtor.

Diff:
---
 gcc/cp/tree.cc| 3 ++-
 gcc/testsuite/g++.dg/special/initp1.C | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 79bc74fa2b7a..bf84fb6bcec4 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -5335,7 +5335,8 @@ handle_init_priority_attribute (tree* node,
   && !in_system_header_at (input_location))
 {
   warning
-   (0, "requested % %i is reserved for internal use",
+   (OPT_Wprio_ctor_dtor,
+"requested % %i is reserved for internal use",
 pri);
 }
 
diff --git a/gcc/testsuite/g++.dg/special/initp1.C 
b/gcc/testsuite/g++.dg/special/initp1.C
index 4a539a5a4bdd..ef88ca970b88 100644
--- a/gcc/testsuite/g++.dg/special/initp1.C
+++ b/gcc/testsuite/g++.dg/special/initp1.C
@@ -30,9 +30,9 @@ Two hoo[ 3 ] = {
 Two( 15, 16 )
 };
 
-Two coo[ 3 ] __attribute__((init_priority(1000)));
-
-Two koo[ 3 ] __attribute__((init_priority(1000))) = {
+Two coo[ 3 ] __attribute__((init_priority(10))); // { dg-warning "reserved" }
+#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
+Two koo[ 3 ] __attribute__((init_priority(10))) = {
 Two( 21, 22 ),
 Two( 23, 24 ),
 Two( 25, 26 )


[gcc r15-7512] dwarf: emit DW_AT_name for DW_TAG_GNU_formal_parameter_pack [PR70536]

2025-02-13 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:53e1686e6e0c3e809384e6fcf5eed46f37bc296b

commit r15-7512-g53e1686e6e0c3e809384e6fcf5eed46f37bc296b
Author: Ed Catmur 
Date:   Sat Feb 4 17:50:33 2023 +0100

dwarf: emit DW_AT_name for DW_TAG_GNU_formal_parameter_pack [PR70536]

Per https://wiki.dwarfstd.org/C++0x_Variadic_templates.md
DW_TAG_GNU_formal_parameter_pack should have a DW_AT_name:

17$:  DW_TAG_formal_parameter_pack
  DW_AT_name("args")
18$:  DW_TAG_formal_parameter
  ! no DW_AT_name attribute
  DW_AT_type(reference to 13$)
(...)

PR c++/70536

gcc/ChangeLog:

* dwarf2out.cc (gen_formal_parameter_pack_die): Add name attr.

gcc/testsuite/ChangeLog:

* g++.dg/debug/dwarf2/template-func-params-7.C: Check for pack 
names.

Co-authored-by: Jason Merrill 

Diff:
---
 gcc/dwarf2out.cc   | 2 +-
 gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-7.C | 7 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 43884f206c07..ed7d9402200e 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -23195,7 +23195,7 @@ gen_formal_parameter_pack_die  (tree parm_pack,
  && subr_die);
 
   parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, 
parm_pack);
-  add_src_coords_attributes (parm_pack_die, parm_pack);
+  add_name_and_src_coords_attributes (parm_pack_die, parm_pack);
 
   for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
 {
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-7.C 
b/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-7.C
index 22b0e4f984da..4e95c238bcd3 100644
--- a/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-7.C
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/template-func-params-7.C
@@ -23,6 +23,9 @@
 // These 3 function template instantiations has a total of 3 template
 // parameters named T.
 // { dg-final { scan-assembler-times "\.ascii \"T.0\"\[\t 
\]+\[^\n\]*DW_AT_name" 3 } }
+// And the packs also have names.
+// { dg-final { scan-assembler-times "\.ascii \"PTs.0\"\[\t 
\]+\[^\n\]*DW_AT_name" 3 } }
+// { dg-final { scan-assembler-times "\.ascii \"args.0\"\[\t 
\]+\[^\n\]*DW_AT_name" 3 } }
 
 
 void
@@ -35,11 +38,11 @@ printf(const char* s)
   */
 }
 
-template
+template
 void
 printf(const char* s,
T value,
-   PackTypes... args)
+   PTs... args)
 {
   while (*s)
 {


[gcc r15-7513] testsuite: adjust nontype-class72 for implicit constexpr

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

commit r15-7513-ga560b5b5b508f39294989ee2559fcecdd2d8924a
Author: Jason Merrill 
Date:   Thu Feb 13 17:34:15 2025 +0100

testsuite: adjust nontype-class72 for implicit constexpr

This test added by r15-7507 doesn't get some expected diagnostics if we
implicitly make I(E) constexpr.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/nontype-class72.C: Disable -fimplicit-constexpr.

Diff:
---
 gcc/testsuite/g++.dg/cpp2a/nontype-class72.C | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class72.C 
b/gcc/testsuite/g++.dg/cpp2a/nontype-class72.C
index 1c48ff57add0..c36be7a4a80d 100644
--- a/gcc/testsuite/g++.dg/cpp2a/nontype-class72.C
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class72.C
@@ -1,6 +1,7 @@
 // PR c++/113800
 // P2308R1 - Template parameter initialization
 // { dg-do compile { target c++20 } }
+// { dg-additional-options "-fno-implicit-constexpr" }
 // Invalid cases.
 
 namespace std {


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Réduction différences

2025-02-13 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:d8e509d0ad729942dabbd64b912d6a62907de29b

commit d8e509d0ad729942dabbd64b912d6a62907de29b
Author: Mikael Morin 
Date:   Wed Feb 12 18:50:20 2025 +0100

Réduction différences

Diff:
---
 gcc/fortran/trans-array.cc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 6765034f9bd6..41c336d699b1 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3646,9 +3646,6 @@ set_temporary_descriptor (stmtblock_t *block, tree desc, 
tree class_src,
   gfc_conv_descriptor_rank_set (block, desc, rank);
 }
 
-  /* Set the span.  */
-  gfc_conv_descriptor_span_set (block, desc, elemsize);
-  
   if (!callee_allocated)
 {
   for (n = 0; n < rank; n++)
@@ -3664,6 +3661,8 @@ set_temporary_descriptor (stmtblock_t *block, tree desc, 
tree class_src,
}
 }
 
+  gfc_conv_descriptor_span_set (block, desc, elemsize);
+  
   gfc_conv_descriptor_data_set (block, desc, data_ptr);
 
   /* The offset is zero because we create temporaries with a zero


[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction régression class_transformational_2

2025-02-13 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:cf483b5ab35b5c7e1e68e60fc767b5796e2969c7

commit cf483b5ab35b5c7e1e68e60fc767b5796e2969c7
Author: Mikael Morin 
Date:   Thu Feb 13 18:22:47 2025 +0100

Correction régression class_transformational_2

Diff:
---
 gcc/fortran/trans-array.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 41c336d699b1..ba040d25241d 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3621,10 +3621,9 @@ set_temporary_descriptor (stmtblock_t *block, tree desc, 
tree class_src,
  tree stride[GFC_MAX_DIMENSIONS], int rank,
  bool callee_allocated, bool rank_changer)
 {
-  tree class_expr = NULL_TREE;
   int n;
 
-  if (!class_expr)
+  if (!class_src)
 {
   /* Fill in the array dtype.  */
   gfc_conv_descriptor_dtype_set (block, desc,


[gcc r15-7515] jit: add "final override" to diagnostic sink [PR116613]

2025-02-13 Thread David Malcolm via Gcc-cvs
https://gcc.gnu.org/g:6ac313525a1faecb9f39a0ba3240f7a9ead91dcc

commit r15-7515-g6ac313525a1faecb9f39a0ba3240f7a9ead91dcc
Author: David Malcolm 
Date:   Thu Feb 13 18:10:47 2025 -0500

jit: add "final override" to diagnostic sink [PR116613]

I added class jit_diagnostic_listener in r15-4760-g0b73e9382ab51c
but forgot to annotate one of the vfuncs with "override".

Fixed thusly.

gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc
(jit_diagnostic_listener::on_report_diagnostic): Add
"final override".

Signed-off-by: David Malcolm 

Diff:
---
 gcc/jit/dummy-frontend.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc
index 1d0080d6fecb..88784ec9e92f 100644
--- a/gcc/jit/dummy-frontend.cc
+++ b/gcc/jit/dummy-frontend.cc
@@ -1017,7 +1017,7 @@ public:
   }
 
   void on_report_diagnostic (const diagnostic_info &info,
-diagnostic_t orig_diag_kind)
+diagnostic_t orig_diag_kind) final override
   {
 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());


[gcc r14-11307] driver: -fhardened and -z lazy/-z norelro [PR117739]

2025-02-13 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:88ca0670c79f123cc84928f78cd3d5eb46b91338

commit r14-11307-g88ca0670c79f123cc84928f78cd3d5eb46b91338
Author: Marek Polacek 
Date:   Tue Nov 26 14:37:21 2024 -0500

driver: -fhardened and -z lazy/-z norelro [PR117739]

As the manual states, using "-fhardened -fstack-protector" will produce
a warning because -fhardened wants to enable -fstack-protector-strong,
but it can't since it's been overriden by the weaker -fstack-protector.

-fhardened also attempts to enable -Wl,-z,relro,-z,now.  By the same
logic as above, "-fhardened -z norelro" or "-fhardened -z lazy" should
produce the same warning.  But we don't detect this combination, so
this patch fixes it.  I also renamed a variable to better reflect its
purpose.

Also don't check warn_hardened in process_command, since it's always
true there.

Also tweak wording in the manual as Jon Wakely suggested on IRC.

PR driver/117739

gcc/ChangeLog:

* doc/invoke.texi: Tweak wording for -Whardened.
* gcc.cc (driver_handle_option): If -z lazy or -z norelro was
specified, don't enable linker hardening.
(process_command): Don't check warn_hardened.

gcc/testsuite/ChangeLog:

* c-c++-common/fhardened-16.c: New test.
* c-c++-common/fhardened-17.c: New test.
* c-c++-common/fhardened-18.c: New test.
* c-c++-common/fhardened-19.c: New test.
* c-c++-common/fhardened-20.c: New test.
* c-c++-common/fhardened-21.c: New test.

Reviewed-by: Jakub Jelinek 
(cherry picked from commit a134dcd8a010744a0097d190f73a4efc2e381531)

Diff:
---
 gcc/doc/invoke.texi   |  4 ++--
 gcc/gcc.cc| 20 ++--
 gcc/testsuite/c-c++-common/fhardened-16.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-17.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-18.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-19.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-20.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-21.c |  5 +
 8 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b575e2b96632..6a94c7b70a5f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6974,8 +6974,8 @@ This warning is enabled by @option{-Wall}.
 Warn when @option{-fhardened} did not enable an option from its set (for
 which see @option{-fhardened}).  For instance, using @option{-fhardened}
 and @option{-fstack-protector} at the same time on the command line causes
-@option{-Whardened} to warn because @option{-fstack-protector-strong} is
-not enabled by @option{-fhardened}.
+@option{-Whardened} to warn because @option{-fstack-protector-strong} will
+not be enabled by @option{-fhardened}.
 
 This warning is enabled by default and has effect only when @option{-fhardened}
 is enabled.
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 728332b81538..8690f15a8c9a 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -302,9 +302,10 @@ static size_t dumpdir_length = 0;
driver added to dumpdir after dumpbase or linker output name.  */
 static bool dumpdir_trailing_dash_added = false;
 
-/* True if -r, -shared, -pie, or -no-pie were specified on the command
-   line.  */
-static bool any_link_options_p;
+/* True if -r, -shared, -pie, -no-pie, -z lazy, or -z norelro were
+   specified on the command line, and therefore -fhardened should not
+   add -z now/relro.  */
+static bool avoid_linker_hardening_p;
 
 /* True if -static was specified on the command line.  */
 static bool static_p;
@@ -4413,10 +4414,17 @@ driver_handle_option (struct gcc_options *opts,
}
/* Record the part after the last comma.  */
add_infile (arg + prev, "*");
+   if (strcmp (arg, "-z,lazy") == 0 || strcmp (arg, "-z,norelro") == 0)
+ avoid_linker_hardening_p = true;
   }
   do_save = false;
   break;
 
+case OPT_z:
+  if (strcmp (arg, "lazy") == 0 || strcmp (arg, "norelro") == 0)
+   avoid_linker_hardening_p = true;
+  break;
+
 case OPT_Xlinker:
   add_infile (arg, "*");
   do_save = false;
@@ -4616,7 +4624,7 @@ driver_handle_option (struct gcc_options *opts,
 case OPT_r:
 case OPT_shared:
 case OPT_no_pie:
-  any_link_options_p = true;
+  avoid_linker_hardening_p = true;
   break;
 
 case OPT_static:
@@ -5000,7 +5008,7 @@ process_command (unsigned int decoded_options_count,
   /* TODO: check if -static -pie works and maybe use it.  */
   if (flag_hardened)
 {
-  if (!any_link_options_p && !static_p)
+  if (!avoid_linker_hardening_p && !static_p)
{
 #if defined HAVE_LD_PIE && defined LD_PIE_SPEC
  save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, 
/*known=*/false);
@@ -5019,7 +5027,7 @@ process_command (unsigned int decoded_options_count,
}
 

[gcc r15-7510] c++: omp declare variant tweak

2025-02-13 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:32d3e63ebb2aac4208a522fcd3477932d72eacfc

commit r15-7510-g32d3e63ebb2aac4208a522fcd3477932d72eacfc
Author: Jason Merrill 
Date:   Wed Feb 12 18:47:17 2025 +0100

c++: omp declare variant tweak

In r15-6707 I changed this function to use build_stub_object to more simply
produce the right type, but it occurs to me that forward_parm would be even
better, specifically for the diagnostic.

This changes nothing with respect to PR118791.

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): Use forward_parm.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/declare-variant-3.C: Adjust diagnostic.
* g++.dg/gomp/declare-variant-5.C: Adjust diagnostic.

Diff:
---
 gcc/cp/decl.cc| 2 +-
 gcc/testsuite/g++.dg/gomp/declare-variant-3.C | 8 
 gcc/testsuite/g++.dg/gomp/declare-variant-5.C | 8 
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 7f7f4938f2ce..df4e66798b15 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8462,7 +8462,7 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
 parm = DECL_CHAIN (parm);
   for (; parm; parm = DECL_CHAIN (parm))
-vec_safe_push (args, build_stub_object (TREE_TYPE (parm)));
+vec_safe_push (args, forward_parm (parm));
 
   unsigned nappend_args = 0;
   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-3.C 
b/gcc/testsuite/g++.dg/gomp/declare-variant-3.C
index 8c0cfd218ad4..fdf030fc4290 100644
--- a/gcc/testsuite/g++.dg/gomp/declare-variant-3.C
+++ b/gcc/testsuite/g++.dg/gomp/declare-variant-3.C
@@ -86,8 +86,8 @@ struct E { int e; };
 
 void fn19 (E, int);
 
-#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error 
{could not convert 'std::declval\(\)' from 'int' to 'E'} }
-void fn20 (int, E);
+#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error 
{could not convert 'i' from 'int' to 'E'} }
+void fn20 (int i, E e);
 
 struct F { operator int () const { return 42; } int f; };
 void fn21 (int, F);
@@ -95,8 +95,8 @@ void fn21 (int, F);
 #pragma omp declare variant ( fn21 ) match (user = { condition ( 1 - 1 ) } )   
// { dg-error "variant 'void fn21\\\(int, F\\\)' and base 'void fn22\\\(F, 
F\\\)' have incompatible types" }
 void fn22 (F, F);
 
-#pragma omp declare variant (fn19) match (user={condition(0)}) // { 
dg-error {could not convert 'std::declval\(\)' from 'F' to 'E'} }
-void fn23 (F, int);
+#pragma omp declare variant (fn19) match (user={condition(0)}) // { 
dg-error {could not convert 'f' from 'F' to 'E'} }
+void fn23 (F f, int i);
 
 void fn24 (int);
 struct U { int u; };
diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-5.C 
b/gcc/testsuite/g++.dg/gomp/declare-variant-5.C
index a4747ac030b9..f3697f66aba6 100644
--- a/gcc/testsuite/g++.dg/gomp/declare-variant-5.C
+++ b/gcc/testsuite/g++.dg/gomp/declare-variant-5.C
@@ -74,8 +74,8 @@ struct E { int e; };
 
 void fn19 (E, int) {}
 
-#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error 
{could not convert 'std::declval\(\)' from 'int' to 'E'} }
-void fn20 (int, E) {}
+#pragma omp declare variant (fn19)match(user={condition(0)})   // { dg-error 
{could not convert 'i' from 'int' to 'E'} }
+void fn20 (int i, E e) {}
 
 struct F { operator int () const { return 42; } int f; };
 void fn21 (int, F) {}
@@ -83,8 +83,8 @@ void fn21 (int, F) {}
 #pragma omp declare variant ( fn21 ) match (user = { condition ( 1 - 1 ) } )   
// { dg-error "variant 'void fn21\\\(int, F\\\)' and base 'void fn22\\\(F, 
F\\\)' have incompatible types" }
 void fn22 (F, F) {}
 
-#pragma omp declare variant (fn19) match (user={condition(0)}) // { 
dg-error {could not convert 'std::declval\(\)' from 'F' to 'E'} }
-void fn23 (F, int) {}
+#pragma omp declare variant (fn19) match (user={condition(0)}) // { 
dg-error {could not convert 'f' from 'F' to 'E'} }
+void fn23 (F f, int i) {}
 
 void fn24 (int);
 struct U { int u; };


[gcc r15-7514] driver: -fhardened and -z lazy/-z norelro [PR117739]

2025-02-13 Thread Marek Polacek via Gcc-cvs
https://gcc.gnu.org/g:a134dcd8a010744a0097d190f73a4efc2e381531

commit r15-7514-ga134dcd8a010744a0097d190f73a4efc2e381531
Author: Marek Polacek 
Date:   Tue Nov 26 14:37:21 2024 -0500

driver: -fhardened and -z lazy/-z norelro [PR117739]

As the manual states, using "-fhardened -fstack-protector" will produce
a warning because -fhardened wants to enable -fstack-protector-strong,
but it can't since it's been overriden by the weaker -fstack-protector.

-fhardened also attempts to enable -Wl,-z,relro,-z,now.  By the same
logic as above, "-fhardened -z norelro" or "-fhardened -z lazy" should
produce the same warning.  But we don't detect this combination, so
this patch fixes it.  I also renamed a variable to better reflect its
purpose.

Also don't check warn_hardened in process_command, since it's always
true there.

Also tweak wording in the manual as Jon Wakely suggested on IRC.

PR driver/117739

gcc/ChangeLog:

* doc/invoke.texi: Tweak wording for -Whardened.
* gcc.cc (driver_handle_option): If -z lazy or -z norelro was
specified, don't enable linker hardening.
(process_command): Don't check warn_hardened.

gcc/testsuite/ChangeLog:

* c-c++-common/fhardened-16.c: New test.
* c-c++-common/fhardened-17.c: New test.
* c-c++-common/fhardened-18.c: New test.
* c-c++-common/fhardened-19.c: New test.
* c-c++-common/fhardened-20.c: New test.
* c-c++-common/fhardened-21.c: New test.

Reviewed-by: Jakub Jelinek 

Diff:
---
 gcc/doc/invoke.texi   |  4 ++--
 gcc/gcc.cc| 20 ++--
 gcc/testsuite/c-c++-common/fhardened-16.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-17.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-18.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-19.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-20.c |  5 +
 gcc/testsuite/c-c++-common/fhardened-21.c |  5 +
 8 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b3ff3bbaa36d..e78810ab4b3f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7072,8 +7072,8 @@ This warning is enabled by @option{-Wall}.
 Warn when @option{-fhardened} did not enable an option from its set (for
 which see @option{-fhardened}).  For instance, using @option{-fhardened}
 and @option{-fstack-protector} at the same time on the command line causes
-@option{-Whardened} to warn because @option{-fstack-protector-strong} is
-not enabled by @option{-fhardened}.
+@option{-Whardened} to warn because @option{-fstack-protector-strong} will
+not be enabled by @option{-fhardened}.
 
 This warning is enabled by default and has effect only when @option{-fhardened}
 is enabled.
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 95b98eaa83cf..04b3736a5da1 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -305,9 +305,10 @@ static size_t dumpdir_length = 0;
driver added to dumpdir after dumpbase or linker output name.  */
 static bool dumpdir_trailing_dash_added = false;
 
-/* True if -r, -shared, -pie, or -no-pie were specified on the command
-   line.  */
-static bool any_link_options_p;
+/* True if -r, -shared, -pie, -no-pie, -z lazy, or -z norelro were
+   specified on the command line, and therefore -fhardened should not
+   add -z now/relro.  */
+static bool avoid_linker_hardening_p;
 
 /* True if -static was specified on the command line.  */
 static bool static_p;
@@ -4434,10 +4435,17 @@ driver_handle_option (struct gcc_options *opts,
}
/* Record the part after the last comma.  */
add_infile (arg + prev, "*");
+   if (strcmp (arg, "-z,lazy") == 0 || strcmp (arg, "-z,norelro") == 0)
+ avoid_linker_hardening_p = true;
   }
   do_save = false;
   break;
 
+case OPT_z:
+  if (strcmp (arg, "lazy") == 0 || strcmp (arg, "norelro") == 0)
+   avoid_linker_hardening_p = true;
+  break;
+
 case OPT_Xlinker:
   add_infile (arg, "*");
   do_save = false;
@@ -4642,7 +4650,7 @@ driver_handle_option (struct gcc_options *opts,
 case OPT_r:
 case OPT_shared:
 case OPT_no_pie:
-  any_link_options_p = true;
+  avoid_linker_hardening_p = true;
   break;
 
 case OPT_static:
@@ -5026,7 +5034,7 @@ process_command (unsigned int decoded_options_count,
   /* TODO: check if -static -pie works and maybe use it.  */
   if (flag_hardened)
 {
-  if (!any_link_options_p && !static_p)
+  if (!avoid_linker_hardening_p && !static_p)
{
 #if defined HAVE_LD_PIE && defined LD_PIE_SPEC
  save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, 
/*known=*/false);
@@ -5045,7 +5053,7 @@ process_command (unsigned int decoded_options_count,
}
}
   /* We can't use OPT_Whardened yet.  Sigh.  */
-  else 

[gcc r15-7508] c++: -frange-for-ext-temps and reused temps [PR118856]

2025-02-13 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:6f7935b3fd60968cff1b3252edf40022f25705aa

commit r15-7508-g6f7935b3fd60968cff1b3252edf40022f25705aa
Author: Jason Merrill 
Date:   Thu Feb 13 11:54:48 2025 +0100

c++: -frange-for-ext-temps and reused temps [PR118856]

Some things in the front-end use a TARGET_EXPR to create a temporary, then
refer to its TARGET_EXPR_SLOT separately later; in this testcase,
maybe_init_list_as_range does.  So we need to handle that pattern in
extend_all_temps.

PR c++/118856

gcc/cp/ChangeLog:

* call.cc (struct extend_temps_data): Add var_map.
(extend_all_temps): Adjust.
(set_up_extended_ref_temp): Make walk_data void*.
(extend_temps_r): Remap variables.  Handle pset here.
Extend all TARGET_EXPRs.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/range-for9.C: New test.

Diff:
---
 gcc/cp/call.cc  | 89 ++---
 gcc/testsuite/g++.dg/cpp23/range-for9.C | 20 
 2 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 2c77b4a4b689..38a8f7fdcda9 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -14154,18 +14154,6 @@ make_temporary_var_for_ref_to_temp (tree decl, tree 
type)
   return pushdecl (var);
 }
 
-/* Data for extend_temps_r, mostly matching the parameters of
-   extend_ref_init_temps.  */
-
-struct extend_temps_data
-{
-  tree decl;
-  tree init;
-  vec **cleanups;
-  tree* cond_guard;
-  hash_set *pset;
-};
-
 static tree extend_temps_r (tree *, int *, void *);
 
 /* EXPR is the initializer for a variable DECL of reference or
@@ -14177,7 +14165,7 @@ static tree extend_temps_r (tree *, int *, void *);
 static tree
 set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups,
  tree *initp, tree *cond_guard,
- extend_temps_data *walk_data)
+ void *walk_data)
 {
   tree init;
   tree type;
@@ -14218,7 +14206,7 @@ set_up_extended_ref_temp (tree decl, tree expr, 
vec **cleanups,
  maybe_constant_init because the extension might change its result.  */
   if (walk_data)
 cp_walk_tree (&TARGET_EXPR_INITIAL (expr), extend_temps_r,
- walk_data, walk_data->pset);
+ walk_data, nullptr);
   else
 TARGET_EXPR_INITIAL (expr)
   = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups,
@@ -14833,6 +14821,19 @@ extend_ref_init_temps_1 (tree decl, tree init, 
vec **cleanups,
   return init;
 }
 
+/* Data for extend_temps_r, mostly matching the parameters of
+   extend_ref_init_temps.  */
+
+struct extend_temps_data
+{
+  tree decl;
+  tree init;
+  vec **cleanups;
+  tree* cond_guard;
+  hash_set *pset; // For avoiding redundant walk_tree.
+  hash_map *var_map; // For remapping extended temps.
+};
+
 /* Tree walk function for extend_all_temps.  Generally parallel to
extend_ref_init_temps_1, but adapted for walk_tree.  */
 
@@ -14841,7 +14842,15 @@ extend_temps_r (tree *tp, int *walk_subtrees, void 
*data)
 {
   extend_temps_data *d = (extend_temps_data *)data;
 
-  if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR)
+  if (TREE_CODE (*tp) == VAR_DECL)
+{
+  if (tree *r = d->var_map->get (*tp))
+   *tp = *r;
+  return NULL_TREE;
+}
+
+  if (TYPE_P (*tp) || TREE_CODE (*tp) == CLEANUP_POINT_EXPR
+  || d->pset->add (*tp))
 {
   *walk_subtrees = 0;
   return NULL_TREE;
@@ -14849,13 +14858,13 @@ extend_temps_r (tree *tp, int *walk_subtrees, void 
*data)
 
   if (TREE_CODE (*tp) == COND_EXPR)
 {
-  cp_walk_tree (&TREE_OPERAND (*tp, 0), extend_temps_r, d, d->pset);
+  cp_walk_tree (&TREE_OPERAND (*tp, 0), extend_temps_r, d, nullptr);
 
   auto walk_arm = [d](tree &op)
   {
tree cur_cond_guard = NULL_TREE;
auto ov = make_temp_override (d->cond_guard, &cur_cond_guard);
-   cp_walk_tree (&op, extend_temps_r, d, d->pset);
+   cp_walk_tree (&op, extend_temps_r, d, nullptr);
if (cur_cond_guard)
  {
tree set = build2 (MODIFY_EXPR, boolean_type_node,
@@ -14870,29 +14879,25 @@ extend_temps_r (tree *tp, int *walk_subtrees, void 
*data)
   return NULL_TREE;
 }
 
-  if (TREE_CODE (*tp) == ADDR_EXPR
-  /* A discarded-value temporary.  */
-  || (TREE_CODE (*tp) == CONVERT_EXPR
- && VOID_TYPE_P (TREE_TYPE (*tp
-{
-  tree *p;
-  for (p = &TREE_OPERAND (*tp, 0);
-  TREE_CODE (*p) == COMPONENT_REF || TREE_CODE (*p) == ARRAY_REF; )
-   p = &TREE_OPERAND (*p, 0);
-  if (TREE_CODE (*p) == TARGET_EXPR)
-   {
- tree subinit = NULL_TREE;
- *p = set_up_extended_ref_temp (d->decl, *p, d->cleanups, &subinit,
-d->cond_guard, d);
- if (TREE_CODE (*tp) == ADDR_EXPR)
-   recompute_tree_invariant_for_addr_expr (*tp);
- if (s

[gcc r14-11306] [PATCH] PR modula2/115112 Incorrect line debugging information occurs during INC builtin

2025-02-13 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:3d961691e0878e1328f9cbbc1d1af5e573ee6786

commit r14-11306-g3d961691e0878e1328f9cbbc1d1af5e573ee6786
Author: Gaius Mulley 
Date:   Thu Feb 13 18:17:17 2025 +

[PATCH] PR modula2/115112 Incorrect line debugging information occurs 
during INC builtin

This patch fixes location bugs in BuildDecProcedure,
BuildIncProcedure, BuildInclProcedure, BuildExclProcedure and
BuildThrow.  All these procedure functions use the token position
passed as a parameter (rather than from the quad stack).  It also
fixes location bugs in CheckRangeIncDec to ensure that the token
position is stored on the quad stack before calling subsidiary
procedure functions.

gcc/m2/ChangeLog:

PR modula2/115112
* gm2-compiler/M2Quads.mod (BuildPseudoProcedureCall): Pass
tokno to each build procedure.
(BuildThrowProcedure): New parameter functok.
(BuildIncProcedure): New parameter proctok.
Pass proctok on the quad stack during every push.
(BuildDecProcedure): Ditto.
(BuildInclProcedure): New parameter proctok.
(BuildExclProcedure): New parameter proctok.

gcc/testsuite/ChangeLog:

PR modula2/115112
* gm2/pim/run/pass/dectest.mod: New test.
* gm2/pim/run/pass/inctest.mod: New test.

(cherry picked from commit 4d0ff917528d1c59bfad5401274c5be71b7b)

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod| 64 +-
 gcc/testsuite/gm2/pim/run/pass/dectest.mod | 10 +
 gcc/testsuite/gm2/pim/run/pass/inctest.mod | 10 +
 3 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 2c3969805dc4..21699554a658 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -7020,19 +7020,19 @@ BEGIN
   BuildDisposeProcedure (tokno)
ELSIF ProcSym = Inc
THEN
-  BuildIncProcedure
+  BuildIncProcedure (tokno)
ELSIF ProcSym = Dec
THEN
-  BuildDecProcedure
+  BuildDecProcedure (tokno)
ELSIF ProcSym = Incl
THEN
-  BuildInclProcedure
+  BuildInclProcedure (tokno)
ELSIF ProcSym = Excl
THEN
-  BuildExclProcedure
+  BuildExclProcedure (tokno)
ELSIF ProcSym = Throw
THEN
-  BuildThrowProcedure
+  BuildThrowProcedure (tokno)
ELSE
   InternalError  ('pseudo procedure not implemented yet')
END
@@ -7083,14 +7083,12 @@ END GetItemPointedTo ;
  ||
 *)
 
-PROCEDURE BuildThrowProcedure ;
+PROCEDURE BuildThrowProcedure (functok: CARDINAL) ;
 VAR
-   functok  : CARDINAL ;
op   : CARDINAL ;
NoOfParam: CARDINAL ;
 BEGIN
PopT (NoOfParam) ;
-   functok  := OperandTtok (NoOfParam + 1) ;
IF NoOfParam = 1
THEN
   op := OperandT (NoOfParam) ;
@@ -7327,19 +7325,19 @@ BEGIN
IF IsExpressionCompatible (dtype, etype)
THEN
   (* the easy case simulate a straightforward macro *)
-  PushTF (des, dtype) ;
+  PushTFtok (des, dtype, tokenpos) ;
   PushT (tok) ;
-  PushTF (expr, etype) ;
+  PushTFtok (expr, etype, tokenpos) ;
   doBuildBinaryOp (FALSE, TRUE)
ELSE
   IF (IsOrdinalType (dtype) OR (dtype = Address) OR IsPointer (dtype)) AND
  (IsOrdinalType (etype) OR (etype = Address) OR IsPointer (etype))
   THEN
- PushTF (des, dtype) ;
+ PushTFtok (des, dtype, tokenpos) ;
  PushT (tok) ;
- PushTF (Convert, NulSym) ;
- PushT (dtype) ;
- PushT (expr) ;
+ PushTFtok (Convert, NulSym, tokenpos) ;
+ PushTtok (dtype, tokenpos) ;
+ PushTtok (expr, tokenpos) ;
  PushT (2) ;  (* Two parameters *)
  BuildConvertFunction (Convert, FALSE) ;
  doBuildBinaryOp (FALSE, TRUE)
@@ -7386,9 +7384,8 @@ END CheckRangeIncDec ;
||
 *)
 
-PROCEDURE BuildIncProcedure ;
+PROCEDURE BuildIncProcedure (proctok: CARDINAL) ;
 VAR
-   proctok   : CARDINAL ;
NoOfParam,
dtype,
OperandSym,
@@ -7396,26 +7393,25 @@ VAR
TempSym   : CARDINAL ;
 BEGIN
PopT (NoOfParam) ;
-   proctok := OperandTtok (NoOfParam + 1) ;
IF (NoOfParam = 1) OR (NoOfParam = 2)
THEN
-  VarSym := OperandT (NoOfParam) ;  (* bottom/first parameter *)
+  VarSym := OperandT (NoOfParam) ;  (* Bottom/first parameter.  *)
   IF IsVar (VarSym)
   THEN
  dtype := GetDType (VarSym) ;
  IF NoOfParam = 2
  THEN
-OperandSym := DereferenceLValue (OperandTok (1), OperandT (1))
+OperandSym := DereferenceLValue (proctok, OperandT (1))
  ELSE
 PushOne (proctok, dtype,
  'the {%EkINC} will cause an overflow {%1ad}') ;
PopT (OperandSym)
  END ;
 
- PushT (VarSym) ;
-   

[gcc r15-7509] Fix LAPACK build error due to global symbol checking.

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

commit r15-7509-gcdb4d27a4c2786cf1b1b0eb1872eac6a5f931578
Author: Thomas Koenig 
Date:   Thu Feb 13 21:47:39 2025 +0100

Fix LAPACK build error due to global symbol checking.

This was an interesting regression.  It came from my recent
patch, where an assert was triggered because a procedure artificial
dummy argument generated for a global symbol did not have the
information if if was a function or a subroutine.  Fixed by
adding the information in gfc_get_formal_from_actual_arglist.

This information then uncovered some new errors, also in the
testsuite, which needed fixing.  Finally, the error is made to
look a bit nicer, so the user gets a pointer to where the
original interface comes from.

gcc/fortran/ChangeLog:

PR fortran/118845
* interface.cc (compare_parameter): If the formal attribute has been
generated from an actual argument list, also output an pointer to
there in case of an error.
(gfc_get_formal_from_actual_arglist): Set function and subroutine
attributes and (if it is a function) the typespec from the actual
argument.

gcc/testsuite/ChangeLog:

PR fortran/118845
* gfortran.dg/recursive_check_4.f03: Adjust call so types matche.
* gfortran.dg/recursive_check_6.f03: Likewise.
* gfortran.dg/specifics_2.f90: Adjust calls so types match.
* gfortran.dg/interface_52.f90: New test.
* gfortran.dg/interface_53.f90: New test.

Diff:
---
 gcc/fortran/interface.cc|  31 -
 gcc/testsuite/gfortran.dg/interface_52.f90  |  20 
 gcc/testsuite/gfortran.dg/interface_53.f90  |   8 ++
 gcc/testsuite/gfortran.dg/recursive_check_4.f03 |   2 +-
 gcc/testsuite/gfortran.dg/recursive_check_6.f03 |   2 +-
 gcc/testsuite/gfortran.dg/specifics_2.f90   | 145 
 6 files changed, 130 insertions(+), 78 deletions(-)

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index fdde84db80d0..edec907d33a3 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -2474,8 +2474,16 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
   sizeof(err),NULL, NULL))
{
  if (where)
-   gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
-  " %s", formal->name, &actual->where, err);
+   {
+ /* Artificially generated symbol names would only confuse.  */
+ if (formal->attr.artificial)
+   gfc_error_opt (0, "Interface mismatch in dummy procedure "
+  "at %L conflicts with %L: %s", &actual->where,
+  &formal->declared_at, err);
+ else
+   gfc_error_opt (0, "Interface mismatch in dummy procedure %qs "
+  "at %L: %s", formal->name, &actual->where, err);
+   }
  return false;
}
 
@@ -2483,8 +2491,16 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
   sizeof(err), NULL, NULL))
{
  if (where)
-   gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
-  " %s", formal->name, &actual->where, err);
+   {
+ if (formal->attr.artificial)
+   gfc_error_opt (0, "Interface mismatch in dummy procedure "
+  "at %L conflichts with %L: %s", &actual->where,
+  &formal->declared_at, err);
+ else
+   gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at 
"
+  "%L: %s", formal->name, &actual->where, err);
+
+   }
  return false;
}
 
@@ -5822,7 +5838,14 @@ gfc_get_formal_from_actual_arglist (gfc_symbol *sym,
  gfc_get_symbol (name, gfc_current_ns, &s);
  if (a->expr->ts.type == BT_PROCEDURE)
{
+ gfc_symbol *asym = a->expr->symtree->n.sym;
  s->attr.flavor = FL_PROCEDURE;
+ if (asym->attr.function)
+   {
+ s->attr.function = 1;
+ s->ts = asym->ts;
+   }
+ s->attr.subroutine = asym->attr.subroutine;
}
  else
{
diff --git a/gcc/testsuite/gfortran.dg/interface_52.f90 
b/gcc/testsuite/gfortran.dg/interface_52.f90
new file mode 100644
index ..4d619241c27a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/interface_52.f90
@@ -0,0 +1,20 @@
+  ! { dg-do compile }
+MODULE m
+  IMPLICIT NONE
+
+CONTAINS
+
+  SUBROUTINE test ()
+IMPLICIT NONE
+
+CALL bar (test2) ! { dg-error "Interface mismatch in dummy procedure" }
+  END SUBROUTINE test
+
+  INTEGER FUNCTION test2 () R

[gcc(refs/users/mikael/heads/refactor_descriptor_v01)] Correction typo

2025-02-13 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:2e7ed307c6cf6f5ffadbb11c16a1d2d6ce678c6d

commit 2e7ed307c6cf6f5ffadbb11c16a1d2d6ce678c6d
Author: Mikael Morin 
Date:   Thu Feb 13 20:28:23 2025 +0100

Correction typo

Diff:
---
 gcc/fortran/trans-array.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 80307be1a212..3bfe41c64013 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3654,7 +3654,7 @@ set_temporary_descriptor (stmtblock_t *block, tree desc, 
tree class_src,
{
  /* Store the stride and bound components in the descriptor.  */
  set_descriptor_dimension (block, desc, n, gfc_index_zero_node, 
ubound[n],
-   srtide[n], nullptr, nullptr);
+   stride[n], nullptr, nullptr);
}
 }


[gcc r15-7516] RISC-V: Avoid more unsplit insns in const expander [PR118832].

2025-02-13 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:28b2ad5341f875ee7e034b0c6f9e4eb725e19a8f

commit r15-7516-g28b2ad5341f875ee7e034b0c6f9e4eb725e19a8f
Author: Robin Dapp 
Date:   Thu Feb 13 16:33:24 2025 -0700

RISC-V: Avoid more unsplit insns in const expander [PR118832].

Hi,

in PR118832 we have another instance of the problem already noticed in
PR117878.  We sometimes use e.g. expand_simple_binop for vector
operations like shift or and.  While this is usually OK, it causes
problems when doing it late, e.g. during LRA.

In particular, we might rematerialize a const_vector during LRA, which
then leaves an insn laying around that cannot be split any more if it
requires a pseudo.  Therefore we should only use the split variants
in expand_const_vector.

This patch fixed the issue in the PR and also pre-emptively rewrites two
other spots that might be prone to the same issue.

Regtested on rv64gcv_zvl512b.  As the two other cases don't have a test
(so might not even trigger) I unconditionally enabled them for my testsuite
run.

Regards
 Robin

PR target/118832

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_const_vector):  Expand as
vlmax insn during lra.

gcc/testsuite/ChangeLog:

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

Diff:
---
 gcc/config/riscv/riscv-v.cc| 46 ++
 .../gcc.target/riscv/rvv/autovec/pr118832.c| 13 ++
 2 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 62456c7ef79d..7cc15f3d53c1 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -1265,7 +1265,16 @@ expand_const_vector (rtx target, rtx src)
   element. Use element width = 64 and broadcast a vector with
   all element equal to 0x0706050403020100.  */
  rtx ele = builder.get_merged_repeating_sequence ();
- rtx dup = expand_vector_broadcast (builder.new_mode (), ele);
+ rtx dup;
+ if (lra_in_progress)
+   {
+ dup = gen_reg_rtx (builder.new_mode ());
+ rtx ops[] = {dup, ele};
+ emit_vlmax_insn (code_for_pred_broadcast
+  (builder.new_mode ()), UNARY_OP, ops);
+   }
+ else
+   dup = expand_vector_broadcast (builder.new_mode (), ele);
  emit_move_insn (result, gen_lowpart (mode, dup));
}
   else
@@ -1523,10 +1532,20 @@ expand_const_vector (rtx target, rtx src)
  base2 = gen_int_mode (rtx_to_poly_int64 (base2), new_smode);
  expand_vec_series (tmp2, base2,
 gen_int_mode (step2, new_smode));
- rtx shifted_tmp2 = expand_simple_binop (
-   new_mode, ASHIFT, tmp2,
-   gen_int_mode (builder.inner_bits_size (), Pmode), NULL_RTX,
-   false, OPTAB_DIRECT);
+ rtx shifted_tmp2;
+ rtx shift = gen_int_mode (builder.inner_bits_size (), Xmode);
+ if (lra_in_progress)
+   {
+ shifted_tmp2 = gen_reg_rtx (new_mode);
+ rtx shift_ops[] = {shifted_tmp2, tmp2, shift};
+ emit_vlmax_insn (code_for_pred_scalar
+  (ASHIFT, new_mode), BINARY_OP,
+  shift_ops);
+   }
+ else
+   shifted_tmp2 = expand_simple_binop (new_mode, ASHIFT, tmp2,
+   shift, NULL_RTX, false,
+   OPTAB_DIRECT);
  rtx tmp3 = gen_reg_rtx (new_mode);
  rtx ior_ops[] = {tmp3, tmp1, shifted_tmp2};
  emit_vlmax_insn (code_for_pred (IOR, new_mode), BINARY_OP,
@@ -1539,9 +1558,20 @@ expand_const_vector (rtx target, rtx src)
  rtx vid = gen_reg_rtx (mode);
  expand_vec_series (vid, const0_rtx, const1_rtx);
  /* Transform into { 0, 0, 1, 1, 2, 2, ... }.  */
- rtx shifted_vid
-   = expand_simple_binop (mode, LSHIFTRT, vid, const1_rtx,
-  NULL_RTX, false, OPTAB_DIRECT);
+ rtx shifted_vid;
+ if (lra_in_progress)
+   {
+ shifted_vid = gen_reg_rtx (mode);
+ rtx shift = gen_int_mode (1, Xmode);
+ rtx shift_ops[] = {shifted_vid, vid, shift};
+ emit_vlmax_insn (code_for_pred_scalar
+  (ASHIFT, mode), BINARY_OP,
+  shift_ops);
+   }
+ else
+   shifted_vid = expand_simple_binop (mode, LSHIFTRT, vid,
+  

[gcc r15-7522] LoongArch: Split the function loongarch_cpu_cpp_builtins into two functions.

2025-02-13 Thread LuluCheng via Gcc-cvs
https://gcc.gnu.org/g:c1af05f3d0320b5af98f27a76abfc9263bd42bb8

commit r15-7522-gc1af05f3d0320b5af98f27a76abfc9263bd42bb8
Author: Lulu Cheng 
Date:   Tue Feb 11 20:05:13 2025 +0800

LoongArch: Split the function loongarch_cpu_cpp_builtins into two functions.

Split the implementation of the function loongarch_cpu_cpp_builtins into 
two parts:
  1. Macro definitions that do not change (only considering 64-bit 
architecture)
  2. Macro definitions that change with different compilation options.

gcc/ChangeLog:

* config/loongarch/loongarch-c.cc (builtin_undef): New macro.
(loongarch_cpu_cpp_builtins): Split to loongarch_update_cpp_builtins
and loongarch_define_unconditional_macros.
(loongarch_def_or_undef): New functions.
(loongarch_define_unconditional_macros): Likewise.
(loongarch_update_cpp_builtins): Likewise.

Diff:
---
 gcc/config/loongarch/loongarch-c.cc | 122 +++-
 1 file changed, 77 insertions(+), 45 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-c.cc 
b/gcc/config/loongarch/loongarch-c.cc
index 5d8c02e094bc..9a8de1ec3812 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -31,26 +31,22 @@ along with GCC; see the file COPYING3.  If not see
 
 #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
 #define builtin_define(TXT) cpp_define (pfile, TXT)
+#define builtin_undef(TXT) cpp_undef (pfile, TXT)
 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
 
-void
-loongarch_cpu_cpp_builtins (cpp_reader *pfile)
+static void
+loongarch_def_or_undef (bool def_p, const char *macro, cpp_reader *pfile)
 {
-  builtin_assert ("machine=loongarch");
-  builtin_assert ("cpu=loongarch");
-  builtin_define ("__loongarch__");
-
-  builtin_define_with_value ("__loongarch_arch",
-loongarch_arch_strings[la_target.cpu_arch], 1);
-
-  builtin_define_with_value ("__loongarch_tune",
-loongarch_tune_strings[la_target.cpu_tune], 1);
-
-  builtin_define_with_value ("_LOONGARCH_ARCH",
-loongarch_arch_strings[la_target.cpu_arch], 1);
+  if (def_p)
+cpp_define (pfile, macro);
+  else
+cpp_undef (pfile, macro);
+}
 
-  builtin_define_with_value ("_LOONGARCH_TUNE",
-loongarch_tune_strings[la_target.cpu_tune], 1);
+static void
+loongarch_define_unconditional_macros (cpp_reader *pfile)
+{
+  builtin_define ("__loongarch__");
 
   /* Base architecture / ABI.  */
   if (TARGET_64BIT)
@@ -66,6 +62,48 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
   builtin_define ("__loongarch_lp64");
 }
 
+  /* Add support for FLOAT128_TYPE on the LoongArch architecture.  */
+  builtin_define ("__FLOAT128_TYPE__");
+
+  /* Map the old _Float128 'q' builtins into the new 'f128' builtins.  */
+  builtin_define ("__builtin_fabsq=__builtin_fabsf128");
+  builtin_define ("__builtin_copysignq=__builtin_copysignf128");
+  builtin_define ("__builtin_nanq=__builtin_nanf128");
+  builtin_define ("__builtin_nansq=__builtin_nansf128");
+  builtin_define ("__builtin_infq=__builtin_inff128");
+  builtin_define ("__builtin_huge_valq=__builtin_huge_valf128");
+
+  /* Native Data Sizes.  */
+  builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE);
+  builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE);
+  builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE);
+  builtin_define_with_int_value ("_LOONGARCH_FPSET", 32);
+  builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);
+}
+
+static void
+loongarch_update_cpp_builtins (cpp_reader *pfile)
+{
+  /* Since the macros in this function might be redefined, it's necessary to
+ undef them first.*/
+  builtin_undef ("__loongarch_arch");
+  builtin_define_with_value ("__loongarch_arch",
+loongarch_arch_strings[la_target.cpu_arch], 1);
+
+  builtin_undef ("__loongarch_tune");
+  builtin_define_with_value ("__loongarch_tune",
+loongarch_tune_strings[la_target.cpu_tune], 1);
+
+  builtin_undef ("_LOONGARCH_ARCH");
+  builtin_define_with_value ("_LOONGARCH_ARCH",
+loongarch_arch_strings[la_target.cpu_arch], 1);
+
+  builtin_undef ("_LOONGARCH_TUNE");
+  builtin_define_with_value ("_LOONGARCH_TUNE",
+loongarch_tune_strings[la_target.cpu_tune], 1);
+
+  builtin_undef ("__loongarch_double_float");
+  builtin_undef ("__loongarch_single_float");
   /* These defines reflect the ABI in use, not whether the
  FPU is directly accessible.  */
   if (TARGET_DOUBLE_FLOAT_ABI)
@@ -73,6 +111,8 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
   else if (TARGET_SINGLE_FLOAT_ABI)
 builtin_define ("__loongarch_single_float=1");
 
+  builtin_undef ("__loongarch_soft_float");
+  builtin_undef ("__loongarch_hard_float");
   if (TARGET_DOUBLE_FLOAT_ABI ||

[gcc r15-7521] LoongArch: Move the function loongarch_register_pragmas to loongarch-c.cc.

2025-02-13 Thread LuluCheng via Gcc-cvs
https://gcc.gnu.org/g:46ce50b44e3d06f103c9136bc052a7354e07cfca

commit r15-7521-g46ce50b44e3d06f103c9136bc052a7354e07cfca
Author: Lulu Cheng 
Date:   Wed Feb 12 09:57:02 2025 +0800

LoongArch: Move the function loongarch_register_pragmas to loongarch-c.cc.

gcc/ChangeLog:

* config/loongarch/loongarch-target-attr.cc
(loongarch_pragma_target_parse): Move to ...
(loongarch_register_pragmas): Move to ...
* config/loongarch/loongarch-c.cc
(loongarch_pragma_target_parse): ... here.
(loongarch_register_pragmas): ... here.
* config/loongarch/loongarch-protos.h
(loongarch_process_target_attr): Function Declaration.

Diff:
---
 gcc/config/loongarch/loongarch-c.cc   | 51 +++
 gcc/config/loongarch/loongarch-protos.h   |  1 +
 gcc/config/loongarch/loongarch-target-attr.cc | 48 -
 3 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-c.cc 
b/gcc/config/loongarch/loongarch-c.cc
index c95c0f373be6..5d8c02e094bc 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -23,9 +23,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "target.h"
 #include "tm.h"
 #include "c-family/c-common.h"
 #include "cpplib.h"
+#include "tm_p.h"
 
 #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
 #define builtin_define(TXT) cpp_define (pfile, TXT)
@@ -145,3 +147,52 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
   builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);
 
 }
+
+/* Hook to validate the current #pragma GCC target and set the state, and
+   update the macros based on what was changed.  If ARGS is NULL, then
+   POP_TARGET is used to reset the options.  */
+
+static bool
+loongarch_pragma_target_parse (tree args, tree pop_target)
+{
+  /* If args is not NULL then process it and setup the target-specific
+ information that it specifies.  */
+  if (args)
+{
+  if (!loongarch_process_target_attr (args, NULL))
+   return false;
+
+  loongarch_option_override_internal (&la_target,
+ &global_options,
+ &global_options_set);
+}
+
+  /* args is NULL, restore to the state described in pop_target.  */
+  else
+{
+  pop_target = pop_target ? pop_target : target_option_default_node;
+  cl_target_option_restore (&global_options, &global_options_set,
+   TREE_TARGET_OPTION (pop_target));
+}
+
+  target_option_current_node
+= build_target_option_node (&global_options, &global_options_set);
+
+  loongarch_reset_previous_fndecl ();
+
+  /* If we're popping or reseting make sure to update the globals so that
+ the optab availability predicates get recomputed.  */
+  if (pop_target)
+loongarch_save_restore_target_globals (pop_target);
+
+  return true;
+}
+
+/* Implement REGISTER_TARGET_PRAGMAS.  */
+
+void
+loongarch_register_pragmas (void)
+{
+  /* Update pragma hook to allow parsing #pragma GCC target.  */
+  targetm.target_option.pragma_parse = loongarch_pragma_target_parse;
+}
diff --git a/gcc/config/loongarch/loongarch-protos.h 
b/gcc/config/loongarch/loongarch-protos.h
index b99f949a004e..e7b318143bfe 100644
--- a/gcc/config/loongarch/loongarch-protos.h
+++ b/gcc/config/loongarch/loongarch-protos.h
@@ -219,4 +219,5 @@ extern void loongarch_option_override_internal (struct 
loongarch_target *, struc
 extern void loongarch_reset_previous_fndecl (void);
 extern void loongarch_save_restore_target_globals (tree new_tree);
 extern void loongarch_register_pragmas (void);
+extern bool loongarch_process_target_attr (tree args, tree fndecl);
 #endif /* ! GCC_LOONGARCH_PROTOS_H */
diff --git a/gcc/config/loongarch/loongarch-target-attr.cc 
b/gcc/config/loongarch/loongarch-target-attr.cc
index cee7031ca1e7..cb537446dffe 100644
--- a/gcc/config/loongarch/loongarch-target-attr.cc
+++ b/gcc/config/loongarch/loongarch-target-attr.cc
@@ -422,51 +422,3 @@ loongarch_option_valid_attribute_p (tree fndecl, tree, 
tree args, int)
   return ret;
 }
 
-/* Hook to validate the current #pragma GCC target and set the state, and
-   update the macros based on what was changed.  If ARGS is NULL, then
-   POP_TARGET is used to reset the options.  */
-
-static bool
-loongarch_pragma_target_parse (tree args, tree pop_target)
-{
-  /* If args is not NULL then process it and setup the target-specific
- information that it specifies.  */
-  if (args)
-{
-  if (!loongarch_process_target_attr (args, NULL))
-   return false;
-
-  loongarch_option_override_internal (&la_target,
- &global_options,
- &global_options_set);
-}
-
-  /* args is NULL, restore to the state

[gcc r15-7523] LoongArch: After setting the compilation options, update the predefined macros.

2025-02-13 Thread LuluCheng via Gcc-cvs
https://gcc.gnu.org/g:753306bbaebb4a56ee8dde893e14dbd9e5269df6

commit r15-7523-g753306bbaebb4a56ee8dde893e14dbd9e5269df6
Author: Lulu Cheng 
Date:   Tue Feb 11 20:36:17 2025 +0800

LoongArch: After setting the compilation options, update the predefined 
macros.

PR target/118828

gcc/ChangeLog:

* config/loongarch/loongarch-c.cc (loongarch_pragma_target_parse):
Update the predefined macros.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/pr118828.c: New test.
* gcc.target/loongarch/pr118828-2.c: New test.
* gcc.target/loongarch/pr118828-3.c: New test.
* gcc.target/loongarch/pr118828-4.c: New test.

Diff:
---
 gcc/config/loongarch/loongarch-c.cc | 14 ++
 gcc/testsuite/gcc.target/loongarch/pr118828-2.c | 30 ++
 gcc/testsuite/gcc.target/loongarch/pr118828-3.c | 32 +++
 gcc/testsuite/gcc.target/loongarch/pr118828-4.c | 32 +++
 gcc/testsuite/gcc.target/loongarch/pr118828.c   | 34 +
 5 files changed, 142 insertions(+)

diff --git a/gcc/config/loongarch/loongarch-c.cc 
b/gcc/config/loongarch/loongarch-c.cc
index 9a8de1ec3812..66ae77ad665f 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm.h"
 #include "c-family/c-common.h"
 #include "cpplib.h"
+#include "c-family/c-pragma.h"
 #include "tm_p.h"
 
 #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
@@ -212,6 +213,19 @@ loongarch_pragma_target_parse (tree args, tree pop_target)
 
   loongarch_reset_previous_fndecl ();
 
+  /* For the definitions, ensure all newly defined macros are considered
+ as used for -Wunused-macros.  There is no point warning about the
+ compiler predefined macros.  */
+  cpp_options *cpp_opts = cpp_get_options (parse_in);
+  unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
+  cpp_opts->warn_unused_macros = 0;
+
+  cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
+  loongarch_update_cpp_builtins (parse_in);
+  cpp_stop_forcing_token_locations (parse_in);
+
+  cpp_opts->warn_unused_macros = saved_warn_unused_macros;
+
   /* If we're popping or reseting make sure to update the globals so that
  the optab availability predicates get recomputed.  */
   if (pop_target)
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-2.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828-2.c
new file mode 100644
index ..3d32fcc15c95
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828-2.c
@@ -0,0 +1,30 @@
+/* { dg-do preprocess } */
+/* { dg-options "-mno-lsx" } */
+
+#ifdef __loongarch_sx
+#error LSX should not be available here
+#endif
+
+#ifdef __loongarch_simd_width
+#error simd width shuold not be available here
+#endif
+
+#pragma GCC push_options
+#pragma GCC target("lsx")
+#ifndef __loongarch_sx
+#error LSX should be available here
+#endif
+#ifndef __loongarch_simd_width
+#error simd width should be available here
+#elif __loongarch_simd_width != 128
+#error simd width should be 128
+#endif
+#pragma GCC pop_options
+
+#ifdef __loongarch_sx
+#error LSX should become unavailable again
+#endif
+
+#ifdef __loongarch_simd_width
+#error simd width shuold become unavailable again
+#endif
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-3.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
new file mode 100644
index ..31ab8e59a3fc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=loongarch64" } */
+/* { dg-final { scan-assembler "t1: loongarch64" } } */
+/* { dg-final { scan-assembler "t2: la64v1.1" } } */
+/* { dg-final { scan-assembler "t3: loongarch64" } } */
+
+#ifndef __loongarch_arch
+#error __loongarch_arch should be available here
+#endif
+
+void
+t1 (void)
+{
+  asm volatile ("# t1: " __loongarch_arch);
+}
+
+#pragma GCC push_options
+#pragma GCC target("arch=la64v1.1")
+
+void
+t2 (void)
+{
+  asm volatile ("# t2: " __loongarch_arch);
+}
+
+#pragma GCC pop_options
+
+void
+t3 (void)
+{
+  asm volatile ("# t3: " __loongarch_arch);
+}
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-4.c 
b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
new file mode 100644
index ..77587ee56148
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=loongarch64 -mtune=la464" } */
+/* { dg-final { scan-assembler "t1: la464" } } */
+/* { dg-final { scan-assembler "t2: la664" } } */
+/* { dg-final { scan-assembler "t3: la464" } } */
+
+#ifndef __loongarch_tune
+#error __loongarch_tune should be available here
+#endif
+
+void
+t1 (void)
+{
+  asm volatile ("# t1: " __loongarch_tune);
+}
+
+#pragma GCC push_options
+#pragma GCC target("tune=

[gcc r15-7524] LoongArch: When -mfpu=none, '__loongarch_frecipe' shouldn't be defined [PR118843].

2025-02-13 Thread LuluCheng via Gcc-cvs
https://gcc.gnu.org/g:ee579b7c257468b9032ab4583ec455fa871d4428

commit r15-7524-gee579b7c257468b9032ab4583ec455fa871d4428
Author: Lulu Cheng 
Date:   Wed Feb 12 11:50:50 2025 +0800

LoongArch: When -mfpu=none, '__loongarch_frecipe' shouldn't be defined 
[PR118843].

PR target/118843

gcc/ChangeLog:

* config/loongarch/loongarch-c.cc
(loongarch_update_cpp_builtins): Fix macro definition issues.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/pr118843.c: New test.

Diff:
---
 gcc/config/loongarch/loongarch-c.cc   | 27 +++
 gcc/testsuite/gcc.target/loongarch/pr118843.c |  6 ++
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-c.cc 
b/gcc/config/loongarch/loongarch-c.cc
index 66ae77ad665f..effdcf0e2554 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -129,9 +129,6 @@ loongarch_update_cpp_builtins (cpp_reader *pfile)
   else
 builtin_define ("__loongarch_frlen=0");
 
-  loongarch_def_or_undef (TARGET_HARD_FLOAT && ISA_HAS_FRECIPE,
- "__loongarch_frecipe", pfile);
-
   loongarch_def_or_undef (ISA_HAS_LSX, "__loongarch_simd", pfile);
   loongarch_def_or_undef (ISA_HAS_LSX, "__loongarch_sx", pfile);
   loongarch_def_or_undef (ISA_HAS_LASX, "__loongarch_asx", pfile);
@@ -149,17 +146,23 @@ loongarch_update_cpp_builtins (cpp_reader *pfile)
   int max_v_major = 1, max_v_minor = 0;
 
   for (int i = 0; i < N_EVO_FEATURES; i++)
-if (la_target.isa.evolution & la_evo_feature_masks[i])
-  {
-   builtin_define (la_evo_macro_name[i]);
+{
+  builtin_undef (la_evo_macro_name[i]);
 
-   int major = la_evo_version_major[i],
-   minor = la_evo_version_minor[i];
+  if (la_target.isa.evolution & la_evo_feature_masks[i]
+ && (la_evo_feature_masks[i] != OPTION_MASK_ISA_FRECIPE
+ || TARGET_HARD_FLOAT))
+   {
+ builtin_define (la_evo_macro_name[i]);
 
-   max_v_major = major > max_v_major ? major : max_v_major;
-   max_v_minor = major == max_v_major
- ? (minor > max_v_minor ? minor : max_v_minor) : max_v_minor;
-  }
+ int major = la_evo_version_major[i],
+ minor = la_evo_version_minor[i];
+
+ max_v_major = major > max_v_major ? major : max_v_major;
+ max_v_minor = major == max_v_major
+   ? (minor > max_v_minor ? minor : max_v_minor) : max_v_minor;
+   }
+}
 
   /* Find the minimum ISA version required to run the target program.  */
   builtin_undef ("__loongarch_version_major");
diff --git a/gcc/testsuite/gcc.target/loongarch/pr118843.c 
b/gcc/testsuite/gcc.target/loongarch/pr118843.c
new file mode 100644
index ..30372b8ffe6a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr118843.c
@@ -0,0 +1,6 @@
+/* { dg-do preprocess } */
+/* { dg-options "-mfrecipe -mfpu=none" } */
+
+#ifdef __loongarch_frecipe
+#error __loongarch_frecipe should not be avaliable here
+#endif


[gcc r15-7525] LoongArch: Adjust the cost of ADDRESS_REG_REG.

2025-02-13 Thread LuluCheng via Gcc-cvs
https://gcc.gnu.org/g:7c50f95421b6de50e4f40773558d0072eafb2365

commit r15-7525-g7c50f95421b6de50e4f40773558d0072eafb2365
Author: Lulu Cheng 
Date:   Tue Dec 10 20:59:22 2024 +0800

LoongArch: Adjust the cost of ADDRESS_REG_REG.

After changing this cost from 1 to 3, the performance of spec2006
401 473 416 465 482 can be improved by about 2% on LA664.

Add option '-maddr-reg-reg-cost='.

gcc/ChangeLog:

* config/loongarch/genopts/loongarch.opt.in: Add
option '-maddr-reg-reg-cost='.
* config/loongarch/loongarch-def.cc
(loongarch_rtx_cost_data::loongarch_rtx_cost_data): Initialize
addr_reg_reg_cost to 3.
* config/loongarch/loongarch-opts.cc
(loongarch_target_option_override): If '-maddr-reg-reg-cost='
is not used, set it to the initial value.
* config/loongarch/loongarch-tune.h
(struct loongarch_rtx_cost_data): Add the member
addr_reg_reg_cost and its assignment function to the structure
loongarch_rtx_cost_data.
* config/loongarch/loongarch.cc (loongarch_address_insns):
Use la_addr_reg_reg_cost to set the cost of ADDRESS_REG_REG.
* config/loongarch/loongarch.opt: Regenerate.
* config/loongarch/loongarch.opt.urls: Regenerate.
* doc/invoke.texi: Add description of '-maddr-reg-reg-cost='.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/const-double-zero-stx.c: Add
'-maddr-reg-reg-cost=1'.
* gcc.target/loongarch/stack-check-alloca-1.c: Likewise.

Diff:
---
 gcc/config/loongarch/genopts/loongarch.opt.in  | 4 
 gcc/config/loongarch/loongarch-def.cc  | 1 +
 gcc/config/loongarch/loongarch-opts.cc | 3 +++
 gcc/config/loongarch/loongarch-tune.h  | 7 +++
 gcc/config/loongarch/loongarch.cc  | 2 +-
 gcc/config/loongarch/loongarch.opt | 4 
 gcc/config/loongarch/loongarch.opt.urls| 3 +++
 gcc/doc/invoke.texi| 7 ++-
 gcc/testsuite/gcc.target/loongarch/const-double-zero-stx.c | 2 +-
 gcc/testsuite/gcc.target/loongarch/stack-check-alloca-1.c  | 2 +-
 10 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in 
b/gcc/config/loongarch/genopts/loongarch.opt.in
index 8c292c8600d0..39c1545e5408 100644
--- a/gcc/config/loongarch/genopts/loongarch.opt.in
+++ b/gcc/config/loongarch/genopts/loongarch.opt.in
@@ -177,6 +177,10 @@ mbranch-cost=
 Target RejectNegative Joined UInteger Var(la_branch_cost) Save
 -mbranch-cost=COST Set the cost of branches to roughly COST instructions.
 
+maddr-reg-reg-cost=
+Target RejectNegative Joined UInteger Var(la_addr_reg_reg_cost) Save
+-maddr-reg-reg-cost=COST  Set the cost of ADDRESS_REG_REG to the value 
calculated by COST.
+
 mcheck-zero-division
 Target Mask(CHECK_ZERO_DIV) Save
 Trap on integer divide by zero.
diff --git a/gcc/config/loongarch/loongarch-def.cc 
b/gcc/config/loongarch/loongarch-def.cc
index b0271eb3b9ad..5f235a04ef2f 100644
--- a/gcc/config/loongarch/loongarch-def.cc
+++ b/gcc/config/loongarch/loongarch-def.cc
@@ -136,6 +136,7 @@ loongarch_rtx_cost_data::loongarch_rtx_cost_data ()
 movcf2gr (COSTS_N_INSNS (7)),
 movgr2cf (COSTS_N_INSNS (15)),
 branch_cost (6),
+addr_reg_reg_cost (3),
 memory_latency (4) {}
 
 /* The following properties cannot be looked up directly using "cpucfg".
diff --git a/gcc/config/loongarch/loongarch-opts.cc 
b/gcc/config/loongarch/loongarch-opts.cc
index 36342cc93731..c2a63f75fc24 100644
--- a/gcc/config/loongarch/loongarch-opts.cc
+++ b/gcc/config/loongarch/loongarch-opts.cc
@@ -1010,6 +1010,9 @@ loongarch_target_option_override (struct loongarch_target 
*target,
   if (!opts_set->x_la_branch_cost)
 opts->x_la_branch_cost = loongarch_cost->branch_cost;
 
+  if (!opts_set->x_la_addr_reg_reg_cost)
+opts->x_la_addr_reg_reg_cost = loongarch_cost->addr_reg_reg_cost;
+
   /* other stuff */
   if (ABI_LP64_P (target->abi.base))
 opts->x_flag_pcc_struct_return = 0;
diff --git a/gcc/config/loongarch/loongarch-tune.h 
b/gcc/config/loongarch/loongarch-tune.h
index e69173ebf79e..f7819fe76783 100644
--- a/gcc/config/loongarch/loongarch-tune.h
+++ b/gcc/config/loongarch/loongarch-tune.h
@@ -38,6 +38,7 @@ struct loongarch_rtx_cost_data
   unsigned short movcf2gr;
   unsigned short movgr2cf;
   unsigned short branch_cost;
+  unsigned short addr_reg_reg_cost;
   unsigned short memory_latency;
 
   /* Default RTX cost initializer, implemented in loongarch-def.cc.  */
@@ -115,6 +116,12 @@ struct loongarch_rtx_cost_data
 return *this;
   }
 
+  loongarch_rtx_cost_data addr_reg_reg_cost_ (unsigned short 
_addr_reg_reg_cost)
+  {
+addr_reg_reg_cost = _addr_reg_reg_cost;
+return *this;
+  }
+
   loongar