The defaulted default constructor defined as deleted when one of variant member has a default member initializer

2020-12-21 Thread jim x via Gcc-patches
struct A{
A(){}
};
union C{
   A a;
   int b = 0;
};
int main(){
C c;
}

GCC reports the default constructor for union `C` is defined as
deleted.  However, the relevant rule in the current c++ standard says
that:
> A defaulted default constructor for class X is defined as deleted if:
>> X is a union that has a variant member with a non-trivial default 
>> constructor and no variant member of X has a default member initializer,
>> X is a non-union class that has a variant member M with a non-trivial 
>> default constructor and no variant member of the anonymous union containing 
>> M has a default member initializer

In simple, as long as one of these variant members has a default
member initializer, then the default constructor for the containing
class will not be defined as deleted.  In this example, the variant
member `b` has a default member initializer, hence `C::C()` should be
defined rather than deleted. Is it a bug?

GCC only agrees this code is supported:
struct A{
A(){}
};
union C{
   A a{};
   int b;
};
int main(){
C c;
}

If it is the right behavior, then the relevant rule should be described as:
> X is a union that has a variant member with a non-trivial default constructor 
> and no default member initializer is supplied for the variant member.

However, the rule does not say this.


[PATCH] bootstrap: include string/vector before abort redefinition

2020-12-21 Thread Nikhil Benesch via Gcc-patches

Similar to 1467a5c and PR 98412. Bootstrapping on FreeBSD 12.2 with the
default compiler (Clang 10.0.1) fails if the  and 
headers are included after abort is redefined to fancy_abort.

Appears to be missing defines in the new C++ module code. The following
patch is sufficient.

gcc/cp/ChangeLog:

* module.cc: INCLUDE_STRING, INCLUDE_VECTOR.

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 7e38293545f..ed3dbe244a3 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -207,6 +207,8 @@ Classes used:
 
 #define _DEFAULT_SOURCE 1 /* To get TZ field of struct tm, if available.  */

 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
 #include "cp-tree.h"


[pushed] c++: Add some asserts in mangle.c

2020-12-21 Thread Jason Merrill via Gcc-patches
The added asserts are places I noticed that we aren't adding the "on" to
distinguish an operator name from an expression involving the operator.
Hopefully that's because operator names never get there; if not, crash bug
reports will let us fix the issue.

Tested x86_64-pc-linux-gnu, applying to trunk.
---
 gcc/cp/mangle.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index c1d9c737a16..7c32e2217aa 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2877,7 +2877,10 @@ write_member_name (tree member)
   write_unqualified_id (member);
 }
   else if (DECL_P (member))
-write_unqualified_name (member);
+{
+  gcc_assert (!DECL_OVERLOADED_OPERATOR_P (member));
+  write_unqualified_name (member);
+}
   else if (TREE_CODE (member) == TEMPLATE_ID_EXPR)
 {
   tree name = TREE_OPERAND (member, 0);
@@ -3162,6 +3165,7 @@ write_expression (tree expr)
write_expression (member);
   else
{
+ gcc_assert (code != BASELINK || BASELINK_QUALIFIED_P (expr));
  write_string ("sr");
  write_type (scope);
  write_member_name (member);
@@ -3344,7 +3348,9 @@ write_expression (tree expr)
 }
   else if (dependent_name (expr))
 {
-  write_unqualified_id (dependent_name (expr));
+  tree name = dependent_name (expr);
+  gcc_assert (!IDENTIFIER_ANY_OP_P (name));
+  write_unqualified_id (name);
 }
   else
 {

base-commit: 93ac0c05ffc84acba8e73ed5238fc325044378e0
prerequisite-patch-id: cb37d2a772bb004cc23bcfe8ecf2a657efdb15c0
-- 
2.27.0



[pushed] c++: Fix demangling of

2020-12-21 Thread Jason Merrill via Gcc-patches
The ABI for unresolved scoped names on the RHS of . and -> used to be

  sr  

That changed years ago to something more complex, but G++ was never updated.
This change was particularly incompatible for simple qualified-ids like
A::x, which were previously mangled as sr1A1x, and now sr1AE1x.

This obviously makes life hard for demanglers, which can't know whether to
consume that E or not.  To work around this, we now try demangling with the
newer ABI, and if that fails and we saw an "sr", try again with the older
ABI.

The compiler side will be adjusted later, as there's an open ABI issue in this
area.

libiberty/ChangeLog:

PR c++/67343
* cp-demangle.h (struct d_info): Add unresolved_name_state.
* cp-demangle.c (d_prefix): Add subst parm.
(d_nested_name): Pass it.
(d_unresolved_name): Split out from...
(d_expression_1): ...here.
(d_demangle_callback): Maybe retry with old sr mangling.
* testsuite/demangle-expected: Add test.
---
 libiberty/cp-demangle.h   |  4 ++
 libiberty/cp-demangle.c   | 87 ---
 libiberty/testsuite/demangle-expected |  3 +
 3 files changed, 72 insertions(+), 22 deletions(-)

diff --git a/libiberty/cp-demangle.h b/libiberty/cp-demangle.h
index 943a3ef478e..27014cde258 100644
--- a/libiberty/cp-demangle.h
+++ b/libiberty/cp-demangle.h
@@ -122,6 +122,10 @@ struct d_info
   /* Non-zero if we are parsing the type operand of a conversion
  operator, but not when in an expression.  */
   int is_conversion;
+  /*  1: using new unresolved-name grammar.
+ -1: using new unresolved-name grammar and saw an unresolved-name.
+  0: using old unresolved-name grammar.  */
+  int unresolved_name_state;
   /* If DMGL_NO_RECURSE_LIMIT is not active then this is set to
  the current recursion level.  */
   unsigned int recursion_level;
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 98ab47a3460..52427275f44 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -429,7 +429,7 @@ static struct demangle_component *d_name (struct d_info *);
 
 static struct demangle_component *d_nested_name (struct d_info *);
 
-static struct demangle_component *d_prefix (struct d_info *);
+static struct demangle_component *d_prefix (struct d_info *, int);
 
 static struct demangle_component *d_unqualified_name (struct d_info *);
 
@@ -1510,7 +1510,7 @@ d_nested_name (struct d_info *di)
  once we have something to attach it to.  */
   rqual = d_ref_qualifier (di, NULL);
 
-  *pret = d_prefix (di);
+  *pret = d_prefix (di, 1);
   if (*pret == NULL)
 return NULL;
 
@@ -1536,10 +1536,12 @@ d_nested_name (struct d_info *di)
 ::=  <(template) unqualified-name>
  ::= 
  ::= 
-*/
+
+   SUBST is true if we should add substitutions (as normal), false
+   if not (in an unresolved-name).  */
 
 static struct demangle_component *
-d_prefix (struct d_info *di)
+d_prefix (struct d_info *di, int subst)
 {
   struct demangle_component *ret = NULL;
 
@@ -1605,7 +1607,7 @@ d_prefix (struct d_info *di)
   else
ret = d_make_comp (di, comb_type, ret, dc);
 
-  if (peek != 'S' && d_peek_char (di) != 'E')
+  if (peek != 'S' && d_peek_char (di) != 'E' && subst)
{
  if (! d_add_substitution (di, ret))
return NULL;
@@ -3291,14 +3293,58 @@ op_is_new_cast (struct demangle_component *op)
  || code[0] == 'c' || code[0] == 'r'));
 }
 
+/*::= [gs]  # x or (with "gs") ::x
+   ::= sr   # T::x / decltype(p)::x
+   # T::N::x /decltype(p)::N::x
+   ::= srN  + E 

+   # A::x, N::y, A::z; "gs" means leading "::"
+   ::= [gs] sr + E 
+
+ "gs" is handled elsewhere, as a unary operator.  */
+
+static struct demangle_component *
+d_unresolved_name (struct d_info *di)
+{
+  struct demangle_component *type;
+  struct demangle_component *name;
+  char peek;
+
+  /* Consume the "sr".  */
+  d_advance (di, 2);
+
+  peek = d_peek_char (di);
+  if (di->unresolved_name_state
+  && (IS_DIGIT (peek)
+ || IS_LOWER (peek)
+ || peek == 'C'
+ || peek == 'U'
+ || peek == 'L'))
+{
+  /* The third production is ambiguous with the old unresolved-name syntax
+of  ; in the old mangling, A::x was mangled
+as sr1A1x, now sr1AE1x.  So we first try to demangle using the new
+mangling, then with the old if that fails.  */
+  di->unresolved_name_state = -1;
+  type = d_prefix (di, 0);
+  if (d_peek_char (di) == 'E')
+   d_advance (di, 1);
+}
+  else
+type = cplus_demangle_type (di);
+  name = d_unqualified_name (di);
+  if (d_peek_char (di) == 'I')
+name = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
+   d_template_args (di));
+  return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name);
+}
+
 /*  ::= <(unary) operator-name> 
 ::= <(binary) 

godump patch committed: DECL_ORIGINAL_TYPE is sometimes NULL

2020-12-21 Thread Ian Lance Taylor via Gcc-patches
This patch to -fdump-go-spec code handles the case where
DECL_ORIGINAL_TYPE of a decl is NULL.  I saw this case while building
on aarch64-unknown-linux-gnu for the type pthread_attr_t.  I don't
know whether this is supposed to be possible or not, but this patch
does enable the build to continue working.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu, and bootstrapped on
aarch64-unknown-linux-gnu.  Committed to mainline.

Ian

* godump.c (go_output_typedef): If DECL_ORIGINAL_TYPE is NULL, use
TREE_TYPE.
diff --git a/gcc/godump.c b/gcc/godump.c
index ff3a4a9c52c..a59f9a02b5f 100644
--- a/gcc/godump.c
+++ b/gcc/godump.c
@@ -1159,6 +1159,8 @@ go_output_typedef (class godump_container *container, 
tree decl)
 
   type = IDENTIFIER_POINTER (DECL_NAME (decl));
   original_type = DECL_ORIGINAL_TYPE (decl);
+  if (original_type == NULL_TREE)
+   original_type = TREE_TYPE (decl);
 
   /* Suppress typedefs where the type name matches the underlying
 struct/union/enum tag. This way we'll emit the struct definition


Go patch committed: Force MPFR exponent range to be large enough

2020-12-21 Thread Ian Lance Taylor via Gcc-patches
The Go frontend recently started checking whether an exponent was out
of range when parsing a string into a floating point number.  It turns
out that in GCC the mpfr exponent range is target dependent, due to PR
88074.  That breaks some Go programs that use large exponents in
untyped constants on processors with limited floating point exponent
range, like ARM (those Go programs were always compiled incorrectly,
but now we at least report an error when that happens).  This patch
changes the Go frontend to force the mpfr exponent range to be large
enough for Go code, although in some cases that may cause the
middle-end to compile code slowly.  This should fix PR 98402.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

PR go/98402
* go-lang.c (go_langhook_init): Force MPFR exponent range to be
large enough to support Go constants.
diff --git a/gcc/go/go-lang.c b/gcc/go/go-lang.c
index 08c1f38a2c1..9c0e7af7b84 100644
--- a/gcc/go/go-lang.c
+++ b/gcc/go/go-lang.c
@@ -131,6 +131,16 @@ go_langhook_init (void)
  eventually be controllable by a command line option.  */
   mpfr_set_default_prec (256);
 
+  /* If necessary, override GCC's choice of minimum and maximum
+ exponents.  This should only affect GCC middle-end
+ compilation-time, not correctness.  */
+  mpfr_exp_t exp = mpfr_get_emax ();
+  if (exp < (1 << 16) - 1)
+mpfr_set_emax ((1 << 16) - 1);
+  exp = mpfr_get_emin ();
+  if (exp > - ((1 << 16) - 1))
+mpfr_set_emin (- ((1 << 16) - 1));
+
   /* Go uses exceptions.  */
   using_eh_for_cleanups ();
 


[PATCH] c++: Fix up floating point complex handling in build_zero_init_1 [PR98353]

2020-12-21 Thread Jakub Jelinek via Gcc-patches
Hi!

While the gimplifier patch I've just committed fixed an ICE, in some cases
like on the committed testcase cp folding doesn't happen after
build_zero_init_1 because it is called already during gimplification.

Not exactly sure why we just don't call build_zero_cst (type); for the
scalar types, but if we want to use convert, the problem with complex floats
is that it returns a COMPLEX_EXPR with FLOAT_EXPR arguments which have
INTEGER_CST 0 as argument.  As fold isn't recursive, it doesn't do anything
in that case, we need to first fold those FLOAT_EXPRs to REAL_CST 0.0 and
only afterwards the COMPLEX_EXPR can be folded into COMPLEX_CST with 0.0
arguments.

The following patch calls cp_fold_rvalue in that case which does the
recursive folding.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-12-21  Jakub Jelinek  

PR c++/98353
* init.c (build_zero_init_1): Use cp_fold_rvalue instead of fold
for SCALAR_TYPE_P zero initializers.

--- gcc/cp/init.c.jj2020-12-09 09:03:38.270054654 +0100
+++ gcc/cp/init.c   2020-12-21 13:51:57.353332652 +0100
@@ -187,7 +187,7 @@ build_zero_init_1 (tree type, tree nelts
   else if (NULLPTR_TYPE_P (type))
 init = build_int_cst (type, 0);
   else if (SCALAR_TYPE_P (type))
-init = fold (convert (type, integer_zero_node));
+init = cp_fold_rvalue (convert (type, integer_zero_node));
   else if (RECORD_OR_UNION_CODE_P (TREE_CODE (type)))
 {
   tree field;

Jakub



Re: [PATCH 3/4] libstdc++: Add floating-point std::to_chars implementation

2020-12-21 Thread Maciej W. Rozycki
On Mon, 21 Dec 2020, Patrick Palka wrote:

> >  This breaks with the `vax-netbsdelf' target in GCC compilation:
> > 
> > .../libstdc++-v3/src/c++17/floating_to_chars.cc:126:38: error: static 
> > assertion failed
> >   126 |   static_assert(__DBL_MANT_DIG__ == 53);
> >   |  ^
> > make[5]: *** [Makefile:577: floating_to_chars.lo] Error 1
> > 
> > So what's the fallback/alternative for non-IEEE-754 FP targets?  Shouldn't 
> > we call into libc (possibly with a warning attribute) for the formats we 
> > don't have explicit handcoded support for?
> 
> Sorry about this bootstrap breakage.  For now, we should probably just
> disable the entire file/implementation on such targets until a proper
> fallback could be implemented.  I posted a patch to that effect here
> https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562379.html
> which is pending review/approval.  Until then, manually stubbing out all of
> floating_to_chars.cc should probably suffice to restore bootstrap on
> this target.

 No worries, breakage happens, especially with the more obscure areas we 
support.  Thanks for the quick fix!

  Maciej


[committed] gimplify: Gimplify value in gimplify_init_ctor_eval_range [PR98353]

2020-12-21 Thread Jakub Jelinek via Gcc-patches
Hi!

gimplify_init_ctor_eval_range wasn't gimplifying value, so if it wasn't
a gimple val, verification at the end of gimplification would ICE (or with
release checking some random pass later on would ICE or misbehave).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk (so far).

2020-12-21  Jakub Jelinek  

PR c++/98353
* gimplify.c (gimplify_init_ctor_eval_range): Gimplify value before
storing it into cref.

* g++.dg/opt/pr98353.C: New test.

--- gcc/gimplify.c.jj   2020-12-21 08:58:55.710524701 +0100
+++ gcc/gimplify.c  2020-12-21 13:39:20.870168004 +0100
@@ -4607,7 +4607,11 @@ gimplify_init_ctor_eval_range (tree obje
 gimplify_init_ctor_eval (cref, CONSTRUCTOR_ELTS (value),
 pre_p, cleared);
   else
-gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value));
+{
+  if (gimplify_expr (, pre_p, NULL, is_gimple_val, fb_rvalue)
+ != GS_ERROR)
+   gimplify_seq_add_stmt (pre_p, gimple_build_assign (cref, value));
+}
 
   /* We exit the loop when the index var is equal to the upper bound.  */
   gimplify_seq_add_stmt (pre_p,
--- gcc/testsuite/g++.dg/opt/pr98353.C.jj   2020-12-21 13:49:51.541802067 
+0100
+++ gcc/testsuite/g++.dg/opt/pr98353.C  2020-12-21 13:49:25.127110571 +0100
@@ -0,0 +1,17 @@
+// PR c++/98353
+// { dg-do compile { target c++11 } }
+
+template  struct A {};
+template 
+struct B
+{
+  static const int n = 1;
+  template  A ::n> foo ();
+  _Complex double c[2], d = 1.0;
+};
+
+void
+bar ()
+{
+  B().foo ();
+}

Jakub



Re: [PATCH] libstdc++: Gracefully disable floating-point to_chars on unsupported targets

2020-12-21 Thread Maciej W. Rozycki
On Mon, 21 Dec 2020, Patrick Palka via Gcc-patches wrote:

> This patch conditionally disables the floating-point std::to_chars
> implementation on targets whose float and double aren't IEEE binary32
> and binary64, until a proper fallback can be added for such targets.
> This fixes a bootstrap failure on non-IEEE-754 FP targets such as
> vax-netbsdelf.

 And I have actually verified this change as posted makes `vax-netbsdelf' 
GCC build again.  I haven't run any regression testing though.

 Thanks for the fix and the short RTT!

  Maciej


Re: [PATCH,rs6000] Combine patterns for p10 load-cmpi fusion

2020-12-21 Thread Segher Boessenkool
On Mon, Dec 21, 2020 at 12:11:44PM -0600, Pat Haugen wrote:
> On 12/4/20 1:19 PM, acsawdey--- via Gcc-patches wrote:
> > + print "  [(set_attr \"type\" \"load\")\n";
> 
> We need to tag these with a new instruction type, such as 'fused-load-cmp', 
> so the scheduler can distinguish them from normal loads.

Yeah...  and the insn_cost function can use that to give better costs
for such fused instructions, as well (it will right now do 12 for
load+cmp, not all that bad -- for combine that always counts as better
that separate load (8) and cmp (4) insns, since it is "just one insn"...
but we can do better than that, make it a bit cheaper).


Segher


[pushed] c++: Fix demangling of qualified-id after '.'

2020-12-21 Thread Jason Merrill via Gcc-patches
The demangler was assuming that only an unqualified-id could appear after
. or ->.

libiberty/ChangeLog:

* cp-demangle.c (d_expression_1): Recognize qualified-id
on RHS of dt/pt.
* testsuite/demangle-expected: Add test.
---
 libiberty/cp-demangle.c   | 20 
 libiberty/testsuite/demangle-expected |  3 +++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 96f43b65ad6..98ab47a3460 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3476,10 +3476,22 @@ d_expression_1 (struct d_info *di)
  right = d_exprlist (di, 'E');
else if (!strcmp (code, "dt") || !strcmp (code, "pt"))
  {
-   right = d_unqualified_name (di);
-   if (d_peek_char (di) == 'I')
- right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
-  right, d_template_args (di));
+   peek = d_peek_char (di);
+   /* These codes start a qualified name.  */
+   if ((peek == 'g' && d_peek_next_char (di) == 's')
+   || (peek == 's' && d_peek_next_char (di) == 'r'))
+ right = d_expression_1 (di);
+   else
+ {
+   /* Otherwise it's an unqualified name.  We use
+  d_unqualified_name rather than d_expression_1 here for
+  old mangled names that didn't add 'on' before operator
+  names.  */
+   right = d_unqualified_name (di);
+   if (d_peek_char (di) == 'I')
+ right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
+  right, d_template_args (di));
+ }
  }
else
  right = d_expression_1 (di);
diff --git a/libiberty/testsuite/demangle-expected 
b/libiberty/testsuite/demangle-expected
index 6e3e6716def..6789d0d1d9d 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -1482,3 +1482,6 @@ void g(S<::operator int>)
 
 _Z1jI1AEDTcldtfp_oncvPT_EES1_
 decltype (({parm#1}.(operator A*))()) j(A)
+
+_Z1fI1AEDtdtfp_srT_1xES1_
+decltype ({parm#1}.A::x) f(A)

base-commit: 71690493322238d0fb9be776d9fceed0a7bf727e
-- 
2.27.0



[pushed] c++: Fix demangling of x.operator type

2020-12-21 Thread Jason Merrill via Gcc-patches
d_operator_name decides whether "cv" indicates a cast or a conversion
operator based on is_expression.  "on" specifies that we want the conversion
operator.

libiberty/ChangeLog:

* cp-demangle.c (d_unqualified_name): Clear is_expression.
* testsuite/demangle-expected: Add tests.
---
 libiberty/cp-demangle.c   | 8 +++-
 libiberty/testsuite/demangle-expected | 6 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index a9f8e759ff5..96f43b65ad6 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -1632,9 +1632,15 @@ d_unqualified_name (struct d_info *di)
 ret = d_source_name (di);
   else if (IS_LOWER (peek))
 {
+  int was_expr = di->is_expression;
   if (peek == 'o' && d_peek_next_char (di) == 'n')
-   d_advance (di, 2);
+   {
+ d_advance (di, 2);
+ /* Treat cv as naming a conversion operator.  */
+ di->is_expression = 0;
+   }
   ret = d_operator_name (di);
+  di->is_expression = was_expr;
   if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
{
  di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
diff --git a/libiberty/testsuite/demangle-expected 
b/libiberty/testsuite/demangle-expected
index 4ad9da82f2c..6e3e6716def 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -1476,3 +1476,9 @@ void f(decltype (__alignof__(int)))
 
 _Z1fIiEvDTv111__alignof__tlT_EE
 void f(decltype (__alignof__(int{})))
+
+_Z1gI1AEv1SIXadsrT_oncviEE
+void g(S<::operator int>)
+
+_Z1jI1AEDTcldtfp_oncvPT_EES1_
+decltype (({parm#1}.(operator A*))()) j(A)

base-commit: 1b021bbd85a79c9d16c1359cbc23b608685dfd9f
-- 
2.27.0



[pushed] Darwin : Update the kernel version to macOS version mapping.

2020-12-21 Thread Iain Sandoe
Hi

We are currently computing the wrong macOS version information for
Darwin kernel editions >= 20.1 (because the computation rules have
changed).  This fixes the computation as far as it’s currently defined.

The patch is an addendum to “Darwin20 is macOS 11” and is needed
on the open [and closed!] branches to support those on Darwin20.



tested on x86_64-darwin20.2, x86_64-darwin16 and i686-darwin9.8.
pushed to master,
thanks
Iain

—— commit log

With the change to macOS 11 and Darwin20, the algorithm for mapping
kernel version to macOS version has changed.

We now have darwin 20.X.Y => macOS 11.(X > 0 ? X - 1 : 0).??.
It currently unclear if the Y will be mapped to macOS patch version
and, if so, whether it will be one-based or 0-based.
Likewise, it's unknown if Darwin 21 will map to macOS 12, so these
entries are unchanged for the present.

gcc/ChangeLog:

* config/darwin-driver.c (darwin_find_version_from_kernel):
Compute the minor OS version from the minor kernel version.
---
 gcc/config/darwin-driver.c | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 8ae300057fd..4a9426ef273 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -149,9 +149,22 @@ darwin_find_version_from_kernel (void)
   if (*version_p++ != '.')
 goto parse_failed;
 
-  /* Darwin20 sees a transition to macOS 11.  */
+  /* Darwin20 sees a transition to macOS 11.  In this, it seems that the
+ mapping to macOS minor version is now shifted to the kernel minor
+ version - 1 (at least for the initial releases).  At this stage, we
+ don't know what macOS version will correspond to Darwin21.  */
   if (major_vers >= 20)
-asprintf (_flag, "11.%02d.00", major_vers - 20);
+{
+  int minor_vers = *version_p++ - '0';
+  if (ISDIGIT (*version_p))
+   minor_vers = minor_vers * 10 + (*version_p++ - '0');
+  if (*version_p++ != '.')
+   goto parse_failed;
+  if (minor_vers > 0)
+   minor_vers -= 1; /* Kernel 20.3 => macOS 11.2.  */
+  /* It's not yet clear whether patch level will be considered.  */
+  asprintf (_flag, "11.%02d.00", minor_vers);
+}
   else if (major_vers - 4 <= 4)
 /* On 10.4 and earlier, the old linker is used which does not
support three-component system versions.
-- 
2.24.1



Re: [PATCH] libstdc++: Gracefully disable floating-point to_chars on unsupported targets

2020-12-21 Thread Patrick Palka via Gcc-patches
On Mon, 21 Dec 2020, Jonathan Wakely wrote:

> On 21/12/20 11:58 -0500, Patrick Palka via Libstdc++ wrote:
> > This patch conditionally disables the floating-point std::to_chars
> > implementation on targets whose float/double are not IEEE binary32 and
> > binary64 respectively, until a proper fallback can be added for such
> > targets.  This fixes a bootstrap failure on non-IEEE-754 FP targets such
> > as vax-netbsdelf.
> > 
> > The preprocessor conditions that define the new internal libstdc++
> > macros for detecting the binary32 and binary64 formats were copied from
> > the test gcc/testsuite/gcc.dg/float-exact-1.c.
> > 
> > Tested on x86_64-pc-linux-gnu, with and without -m32, and also when
> > artifically undefining the below new macros.  Does this look OK for
> > trunk?
> > 
> > libstdc++-v3/ChangeLog:
> > 
> > * include/bits/c++config (_GLIBCXX_FLOAT_IS_IEEE_BINARY_32):
> > Define this macro.
> > (_GLIBCXX_DOUBLE_IS_IEEE_BINARY_64): Likewise.
> > * include/std/charconv (to_chars): Use the macros to
> > conditionally hide the overloads for floating-point types.
> > * src/c++17/floating_to_chars.cc: Use the macros to
> > conditionally disable this file.
> > (floating_type_traits): Remove redundant static assert.
> > (floating_type_traits): Likewise.
> > * testsuite/20_util/to_chars/double.cc: Use the macros to
> > conditionally disable this test.
> > * testsuite/20_util/to_chars/float.cc: Likewise.
> > * testsuite/20_util/to_chars/long_double.cc: Likewise.  Adjust
> > dg-do directives so that we don't execute this test on targets
> > with a large long double type and without int128.
> > ---
> > libstdc++-v3/include/bits/c++config | 14 ++
> > libstdc++-v3/include/std/charconv   |  2 ++
> > libstdc++-v3/src/c++17/floating_to_chars.cc |  9 +
> > .../testsuite/20_util/to_chars/double.cc|  2 ++
> > .../testsuite/20_util/to_chars/float.cc |  2 ++
> > .../testsuite/20_util/to_chars/long_double.cc   | 17 +
> > 6 files changed, 38 insertions(+), 8 deletions(-)
> > 
> > diff --git a/libstdc++-v3/include/bits/c++config
> > b/libstdc++-v3/include/bits/c++config
> > index 8cce88aa87b..f54074a2c04 100644
> > --- a/libstdc++-v3/include/bits/c++config
> > +++ b/libstdc++-v3/include/bits/c++config
> > @@ -688,6 +688,20 @@ namespace std
> > # endif
> > #endif
> > 
> > +// Define if float has the IEEE binary32 format.
> > +#if __FLT_MANT_DIG__ == 24 \
> > +  && __FLT_MIN_EXP__ == -125 \
> > +  && __FLT_MAX_EXP == 128
> > +# define _GLIBCXX_FLOAT_IS_IEEE_BINARY32 1
> > +#endif
> > +
> > +// Define if double has the IEEE binary64 format.
> > +#if __DBL_MANT_DIG__ == 53 \
> > +  && __DBL_MIN_EXP__ == -1021 \
> > +  && __DBL_MAX_EXP__ == 1024
> > +# define _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 1
> > +#endif
> > +
> > #ifdef __has_builtin
> > # ifdef __is_identifier
> > // Intel and older Clang require !__is_identifier for some built-ins:
> > diff --git a/libstdc++-v3/include/std/charconv
> > b/libstdc++-v3/include/std/charconv
> > index b57b0a16db2..1f005be47b1 100644
> > --- a/libstdc++-v3/include/std/charconv
> > +++ b/libstdc++-v3/include/std/charconv
> > @@ -704,6 +704,7 @@ namespace __detail
> > 
> >   // Floating-point std::to_chars
> > 
> > +#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
> >   // Overloads for float.
> >   to_chars_result to_chars(char* __first, char* __last, float __value)
> > noexcept;
> >   to_chars_result to_chars(char* __first, char* __last, float __value,
> > @@ -725,6 +726,7 @@ namespace __detail
> >chars_format __fmt) noexcept;
> >   to_chars_result to_chars(char* __first, char* __last, long double __value,
> >chars_format __fmt, int __precision) noexcept;
> > +#endif
> > 
> > _GLIBCXX_END_NAMESPACE_VERSION
> > } // namespace std
> > diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc
> > b/libstdc++-v3/src/c++17/floating_to_chars.cc
> > index b7c31c746cc..6d94d46cc0a 100644
> > --- a/libstdc++-v3/src/c++17/floating_to_chars.cc
> > +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
> > @@ -22,6 +22,10 @@
> > // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
> > // .
> > 
> > +// This implementation crucially assumes float/double have the
> > +// IEEE binary32/binary64 formats.
> > +#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
> > +
> > // Activate __glibcxx_assert within this file to shake out any bugs.
> > #define _GLIBCXX_ASSERTIONS 1
> > 
> > @@ -109,8 +113,6 @@ namespace
> >   template<>
> > struct floating_type_traits
> > {
> > -  // We (and Ryu) assume float has the IEEE binary32 format.
> > -  static_assert(__FLT_MANT_DIG__ == 24);
> >   static constexpr int mantissa_bits = 23;
> >   static constexpr int exponent_bits = 8;
> >   static constexpr bool 

Re: [PATCH v2] C-family : Add attribute 'unavailable'.

2020-12-21 Thread Iain Sandoe

Hi Joseph,

Nathan has approved this from the C++ perspective (and Martin said that his
comments were  "not necessarily to object to the idea behind the attribute  
but

to draw attention to the fact that it's not suitable for standard APIs.”)

So, I wonder, do you have more comments on the revised patch, or is this
now OK for master?

(reiterating, that we are not inventing something new here - but rather  
trying

 to achieve compatibility with implementations that already have the 
attrinbute).

thanks
Iain

Iain Sandoe  wrote:



Martin Sebor  wrote:


On 11/29/20 6:56 PM, Iain Sandoe wrote:



Martin Sebor via Gcc-patches  wrote:

On 11/10/20 12:38 PM, Iain Sandoe wrote:

—— commit message.
If an interface is marked 'deprecated' then, presumably, at some  
point it

will be withdrawn and no longer available.  The 'unavailable' attribute
makes it possible to mark up interfaces to indicate this status.

Making an interface unavailable isn't the intent of deprecation in
standards like C, C++, or POSIX.  Rather, the intended next stage
after deprecation is to make the interface available for other uses,
either by the standards themselves, or by implementations, or by
programs (if its name is not in the reserved namespace).  So unless
you have other kinds of deprecation in mind this doesn't seem like
a fitting use case.

coming at things from the standards perspective .. perhaps.
.. however, in the first set of cases above, one never needs to indicate
 unavailability  since the entity never becomes unavailable, it changes
 meaning.
In practice, we don’t have markup of keywords etc. to indicate this (such
deprecation has been handled specifically in the FEs).
The practical (and actual) use of these attributes is in describing the  
lifecycle

of system APIs.
In that context, one could see it being used to describe APIs withdrawn  
in, say,
a Posix standard (as implemented by a given system or according to  
specific

compile-time flags).


Just for the sake of clarity, to make sure we are both talking about
the same thing, the term POSIX uses for "withdrawn" when referring
to APIs is removed.  Withdrawn is a term that ISO tends to apply to
whole standards.  For example, ISO 9945:2003 AKA SUSv3 is a withdrawn
revision of POSIX (likewise, C99 and C11 are withdrawn revisions of
C).

With that, the APIs that have been removed in recent POSIX versions
would not be appropriately described by the attribute, either on
paper, in the POSIX spec (if the hypothetical case when the attribute
was specified the C standard), or in implementations.  The APIs simply
don't exist and so are open to use by programs (unless they are in
the reserved namespace), or by implementations as extensions.
The latter typically means that the APIs are defined (i.e., can
continue to be linked to by legacy applications) but not declared
in the system's header so they can be defined by programs.  Declaring
removed APIs with the unavailable attribute would prevent that and so
would not be conforming.

An example from C (not yet POSIX) is the gets() function that was
removed in C11 (it's still SUSv4).  It's only declared in 
when targeting older versions of C and C++.  Because in more recent
versions of the standards gets is not a reserved name it's valid
for programs to declare symbols named gets (of any kind).  So
declaring gets in  with attribute unavailable would be
nonconforming.

My point here is not necessarily to object to the idea behind
the attribute but to draw attention to the fact that it's not
suitable for standard APIs.


I understand (and have no disagreement with) that this is not a facility
that could be used as an enforcement of standard’s compliance.



However, imagine that you are a system integrator, and you have a
system which supports the API of SUSv3 and some of the additions of
later systems; let’s say you want to help your users avoid use of APIs
which would be unavailable on a SUSv3 system

You could mark up your implementation’s headers such that when presented
with some compile flags, it made the toolchain emit an error if the user
attempted to use APIs that are not present in SUSv3.

This is not actually a completely inane goal - despite that SUSv3 is  
retired -

in reality (AFAICS) there is only one system that’s qualified to UNIX7.


It is used
quite extensively in some codebases where a single set of headers can  
be used

to permit code generation for multiple system versions.


This sounds like a different use case than the next stage after
deprecation.  I haven't come across it but I imagine its purpose
is to foster portability between variants or flavors (rather
than versions) of APSs?  Say one set of APIs for a feature-rich
desktop variant of an OS versus a subset of the same APIs for
an embedded, more limited variant of the same OS.
In the case of Darwin, the compilers are capable of targeting multiple  
versions
of the system (one doesn’t need a separate GCC or clang to target each  
version,

Re: Add libcody

2020-12-21 Thread Nathan Sidwell

On 12/21/20 1:23 PM, Sebastian Huber wrote:

Hello Nathan,




../../gnu-mirror-gcc-cf22f78/gcc/../libcody/cody.hh:24:
In file included from /usr/include/c++/v1/memory:654:
/usr/include/c++/v1/typeinfo:231:5: error: no member named 'fancy_abort' 
in namespace 'std::__1'; did you mean simply 'fancy_abort'?

     _VSTD::abort();
     ^~~
/usr/include/c++/v1/__config:816:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
   ^
../../gnu-mirror-gcc-cf22f78/gcc/system.h:769:13: note: 'fancy_abort' 
declared here

extern void fancy_abort (const char *, int, const char *)


can you try with Gerald Pfeifer's patch setting INCLUDE_$X?  Some ot 
that's committed but not all.


nathan

--
Nathan Sidwell


Re: [PATCH] libstdc++: Gracefully disable floating-point to_chars on unsupported targets

2020-12-21 Thread Jonathan Wakely via Gcc-patches

On 21/12/20 11:58 -0500, Patrick Palka via Libstdc++ wrote:

This patch conditionally disables the floating-point std::to_chars
implementation on targets whose float/double are not IEEE binary32 and
binary64 respectively, until a proper fallback can be added for such
targets.  This fixes a bootstrap failure on non-IEEE-754 FP targets such
as vax-netbsdelf.

The preprocessor conditions that define the new internal libstdc++
macros for detecting the binary32 and binary64 formats were copied from
the test gcc/testsuite/gcc.dg/float-exact-1.c.

Tested on x86_64-pc-linux-gnu, with and without -m32, and also when
artifically undefining the below new macros.  Does this look OK for
trunk?

libstdc++-v3/ChangeLog:

* include/bits/c++config (_GLIBCXX_FLOAT_IS_IEEE_BINARY_32):
Define this macro.
(_GLIBCXX_DOUBLE_IS_IEEE_BINARY_64): Likewise.
* include/std/charconv (to_chars): Use the macros to
conditionally hide the overloads for floating-point types.
* src/c++17/floating_to_chars.cc: Use the macros to
conditionally disable this file.
(floating_type_traits): Remove redundant static assert.
(floating_type_traits): Likewise.
* testsuite/20_util/to_chars/double.cc: Use the macros to
conditionally disable this test.
* testsuite/20_util/to_chars/float.cc: Likewise.
* testsuite/20_util/to_chars/long_double.cc: Likewise.  Adjust
dg-do directives so that we don't execute this test on targets
with a large long double type and without int128.
---
libstdc++-v3/include/bits/c++config | 14 ++
libstdc++-v3/include/std/charconv   |  2 ++
libstdc++-v3/src/c++17/floating_to_chars.cc |  9 +
.../testsuite/20_util/to_chars/double.cc|  2 ++
.../testsuite/20_util/to_chars/float.cc |  2 ++
.../testsuite/20_util/to_chars/long_double.cc   | 17 +
6 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 8cce88aa87b..f54074a2c04 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -688,6 +688,20 @@ namespace std
# endif
#endif

+// Define if float has the IEEE binary32 format.
+#if __FLT_MANT_DIG__ == 24 \
+  && __FLT_MIN_EXP__ == -125 \
+  && __FLT_MAX_EXP == 128
+# define _GLIBCXX_FLOAT_IS_IEEE_BINARY32 1
+#endif
+
+// Define if double has the IEEE binary64 format.
+#if __DBL_MANT_DIG__ == 53 \
+  && __DBL_MIN_EXP__ == -1021 \
+  && __DBL_MAX_EXP__ == 1024
+# define _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 1
+#endif
+
#ifdef __has_builtin
# ifdef __is_identifier
// Intel and older Clang require !__is_identifier for some built-ins:
diff --git a/libstdc++-v3/include/std/charconv 
b/libstdc++-v3/include/std/charconv
index b57b0a16db2..1f005be47b1 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -704,6 +704,7 @@ namespace __detail

  // Floating-point std::to_chars

+#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
  // Overloads for float.
  to_chars_result to_chars(char* __first, char* __last, float __value) noexcept;
  to_chars_result to_chars(char* __first, char* __last, float __value,
@@ -725,6 +726,7 @@ namespace __detail
   chars_format __fmt) noexcept;
  to_chars_result to_chars(char* __first, char* __last, long double __value,
   chars_format __fmt, int __precision) noexcept;
+#endif

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc 
b/libstdc++-v3/src/c++17/floating_to_chars.cc
index b7c31c746cc..6d94d46cc0a 100644
--- a/libstdc++-v3/src/c++17/floating_to_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
@@ -22,6 +22,10 @@
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// .

+// This implementation crucially assumes float/double have the
+// IEEE binary32/binary64 formats.
+#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
+
// Activate __glibcxx_assert within this file to shake out any bugs.
#define _GLIBCXX_ASSERTIONS 1

@@ -109,8 +113,6 @@ namespace
  template<>
struct floating_type_traits
{
-  // We (and Ryu) assume float has the IEEE binary32 format.
-  static_assert(__FLT_MANT_DIG__ == 24);
  static constexpr int mantissa_bits = 23;
  static constexpr int exponent_bits = 8;
  static constexpr bool has_implicit_leading_bit = true;
@@ -124,8 +126,6 @@ namespace
  template<>
struct floating_type_traits
{
-  // We (and Ryu) assume double has the IEEE binary64 format.
-  static_assert(__DBL_MANT_DIG__ == 53);
  static constexpr int mantissa_bits = 52;
  static constexpr int exponent_bits = 11;
  static constexpr bool has_implicit_leading_bit = true;
@@ -1565,3 +1565,4 @@ _ZSt8to_charsPcS_eSt12chars_formati(char* 

Re: Add libcody

2020-12-21 Thread Sebastian Huber

Hello Nathan,

there is network related build errors are now fixed on FreeBSD 12. 
However, I got another build error:


/usr/bin/c++ -O2 -pipe -fbracket-depth=1024 
-I/usr/home/user/rtems-source-builder/rtems/build/tmp/sb-1001/7/rtems-aarch64/usr/local/rtems/6/include 
-fno-PIE -c  -DIN_GCC_FRONTEND  -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE  
-fno-strict-aliasing -fno-exceptions -fno-rtti -fas
ynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings 
-Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute 
-Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros 
-Wno-overlength-strings   -DHAVE_CONFIG_H -I. -Icp 
-I../../gnu-mirror-gcc-cf2
2f78/gcc -I../../gnu-mirror-gcc-cf22f78/gcc/cp 
-I../../gnu-mirror-gcc-cf22f78/gcc/../include 
-I../../gnu-mirror-gcc-cf22f78/gcc/../libcpp/include 
-I../../gnu-mirror-gcc-cf22f78/gcc/../libcody 
-I/usr/home/user/rtems-source-builder/rtems/build/aarch64-rtems7-gcc-cf22f78-ne
wlib-415fdd4-x86_64-freebsd12.1-1/build/./gmp 
-I/usr/home/user/rtems-source-builder/rtems/build/aarch64-rtems7-gcc-cf22f78-newlib-415fdd4-x86_64-freebsd12.1-1/gnu-mirror-gcc-cf22f78/gmp 
-I/usr/home/user/rtems-source-builder/rtems/build/aarch64-rtems7-gcc-cf22f78-newlib-4
15fdd4-x86_64-freebsd12.1-1/build/./mpfr/src 
-I/usr/home/user/rtems-source-builder/rtems/build/aarch64-rtems7-gcc-cf22f78-newlib-415fdd4-x86_64-freebsd12.1-1/gnu-mirror-gcc-cf22f78/mpfr/src 
-I/usr/home/user/rtems-source-builder/rtems/build/aarch64-rtems7-gcc-cf22f78-newl
ib-415fdd4-x86_64-freebsd12.1-1/gnu-mirror-gcc-cf22f78/mpc/src 
-I../../gnu-mirror-gcc-cf22f78/gcc/../libdecnumber 
-I../../gnu-mirror-gcc-cf22f78/gcc/../libdecnumber/dpd -I../libdecnumber 
-I../../gnu-mirror-gcc-cf22f78/gcc/../libbacktrace 
-I/usr/home/user/rtems-source-bu
ilder/rtems/build/aarch64-rtems7-gcc-cf22f78-newlib-415fdd4-x86_64-freebsd12.1-1/build/./isl/include 
-I/usr/home/user/rtems-source-builder/rtems/build/aarch64-rtems7-gcc-cf22f78-newlib-415fdd4-x86_64-freebsd12.1-1/gnu-mirror-gcc-cf22f78/isl/include 
-o cp/mapper-resolver
.o -MT cp/mapper-resolver.o -MMD -MP -MF cp/.deps/mapper-resolver.TPo 
../../gnu-mirror-gcc-cf22f78/gcc/cp/mapper-resolver.cc
warning: unknown warning option '-Werror=format-diag' 
[-Wunknown-warning-option]
In file included from 
../../gnu-mirror-gcc-cf22f78/gcc/cp/mapper-client.cc:31:
In file included from 
../../gnu-mirror-gcc-cf22f78/gcc/cp/mapper-client.h:26:
In file included from 
../../gnu-mirror-gcc-cf22f78/gcc/../libcody/cody.hh:24:

In file included from /usr/include/c++/v1/memory:654:
/usr/include/c++/v1/typeinfo:231:5: error: no member named 'fancy_abort' 
in namespace 'std::__1'; did you mean simply 'fancy_abort'?

    _VSTD::abort();
    ^~~
/usr/include/c++/v1/__config:816:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
  ^
../../gnu-mirror-gcc-cf22f78/gcc/system.h:769:13: note: 'fancy_abort' 
declared here

extern void fancy_abort (const char *, int, const char *)

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/



Re: [PATCH,rs6000] Fusion patterns for logical-logical

2020-12-21 Thread Pat Haugen via Gcc-patches
On 12/10/20 8:41 PM, acsawdey--- via Gcc-patches wrote:
> +  [(set_attr "type" "logical")

Similar to load-cmp fusion pairs, we need a new insn type here.

-Pat


Re: [PATCH,rs6000] Combine patterns for p10 load-cmpi fusion

2020-12-21 Thread Pat Haugen via Gcc-patches
On 12/4/20 1:19 PM, acsawdey--- via Gcc-patches wrote:
> +   print "  [(set_attr \"type\" \"load\")\n";

We need to tag these with a new instruction type, such as 'fused-load-cmp', so 
the scheduler can distinguish them from normal loads.

-Pat


c++: Windows rename [PR 98412]

2020-12-21 Thread Nathan Sidwell



Some system's rename(2) fails if the target already exists, so delete it
first.

gcc/cp/
* module.cc (create_dirs): Add logging.
(finish_module_processing): Unlink before rename.

--
Nathan Sidwell
diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc
index fc918d296a2..7e38293545f 100644
--- i/gcc/cp/module.cc
+++ w/gcc/cp/module.cc
@@ -4693,6 +4693,7 @@ create_dirs (char *path)
 	char sep = *base;
 	*base = 0;
 	int failed = mkdir (path, S_IRWXU | S_IRWXG | S_IRWXO);
+	dump () && dump ("Mkdir ('%s') errno:=%u", path, failed ? errno : 0);
 	*base = sep;
 	if (failed
 	/* Maybe racing with another creator (of a *different*
@@ -19744,8 +19745,17 @@ finish_module_processing (cpp_reader *reader)
 	  input_location = loc;
 	}
 	  if (to.end ())
-	if (rename (tmp_name, path))
-	  to.set_error (errno);
+	{
+	  /* Some OS's do not replace NEWNAME if it already
+		 exists.  This'll have a race condition in erroneous
+		 concurrent builds.  */
+	  unlink (path);
+	  if (rename (tmp_name, path))
+		{
+		  dump () && dump ("Rename ('%s','%s') errno=%u", errno);
+		  to.set_error (errno);
+		}
+	}
 
 	  if (to.get_error ())
 	{


Re: C++ 20 modules

2020-12-21 Thread Nathan Sidwell

On 12/21/20 12:38 PM, Gerald Pfeifer wrote:

O Mon, 21 Dec 2020, Nathan Sidwell wrote:

/scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.cc:31:
In file included from
/scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.h:26:
In file included from
/scratch/tmp/gerald/GCC-HEAD/gcc/../libcody/cody.hh:24:
In file included from /usr/include/c++/v1/memory:653:
/usr/include/c++/v1/typeinfo:346:5: error: no member named 'fancy_abort'
in namespace 'std::__1'; did you mean simply 'fancy_abort'?
  _VSTD::abort();
  ^~~
/usr/include/c++/v1/__config:782:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE

Care to try this?


Thank you, Nathan!

This made a difference, though it appears a similar change is needed
for gcc/cp/module.cc as well, which also includes mapper-client.h.

Please find an extended patch attached.

(Bootstrap is still running, but has progressed farther than
without your patch or your original patch alone, and already
is in libstdc++ now.)


Yes, this is good.  I already managed to commit some of this with the 
98412 patch.


nathan


--
Nathan Sidwell


Re: C++ 20 modules

2020-12-21 Thread Gerald Pfeifer
O Mon, 21 Dec 2020, Nathan Sidwell wrote:
>> /scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.cc:31:
>> In file included from
>> /scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.h:26:
>> In file included from
>> /scratch/tmp/gerald/GCC-HEAD/gcc/../libcody/cody.hh:24:
>> In file included from /usr/include/c++/v1/memory:653:
>> /usr/include/c++/v1/typeinfo:346:5: error: no member named 'fancy_abort'
>> in namespace 'std::__1'; did you mean simply 'fancy_abort'?
>>  _VSTD::abort();
>>  ^~~
>> /usr/include/c++/v1/__config:782:15: note: expanded from macro '_VSTD'
>> #define _VSTD std::_LIBCPP_ABI_NAMESPACE
> Care to try this?

Thank you, Nathan!

This made a difference, though it appears a similar change is needed 
for gcc/cp/module.cc as well, which also includes mapper-client.h. 

Please find an extended patch attached.

(Bootstrap is still running, but has progressed farther than 
without your patch or your original patch alone, and already 
is in libstdc++ now.)

Gerald
diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc
index 2ad770b3d78..40e9283a794 100644
--- a/gcc/cp/mapper-client.cc
+++ b/gcc/cp/mapper-client.cc
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3.  If not see
 // will include it later under the above check
 #include 
 #endif
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 
 #include "line-map.h"
diff --git a/gcc/cp/mapper-resolver.cc b/gcc/cp/mapper-resolver.cc
index 53c482441b4..e348757d99c 100644
--- a/gcc/cp/mapper-resolver.cc
+++ b/gcc/cp/mapper-resolver.cc
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 /* Forward to the resolver in c++tools.  */
 
 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #define INCLUDE_ALGORITHM
 #include "system.h"
 
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index fc918d296a2..7db312d3c44 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -207,6 +207,8 @@ Classes used:
 
 #define _DEFAULT_SOURCE 1 /* To get TZ field of struct tm, if available.  */
 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
 #include "cp-tree.h"


bootstrap: std:stoul non-portable [PR 98412]

2020-12-21 Thread Nathan Sidwell

Fix some more system-specific issues.  Not everyone's C++11 is the same :(

PR bootstrap/98412
libcody/
* client.cc: Include cstdlib.
* server.cc: Include cstdlib.
gcc/cp/
* mapper-client.cc: INCLUDE_STRING, INCLUDE_VECTOR.
(module_client::open_module_client): Avoid std::stoul.
* mapper-resolver.cc: INCLUDE_STRING, INCLUDE_VECTOR.

Thanks for checking it Eric!

nathan

--
Nathan Sidwell
diff --git i/gcc/cp/mapper-client.cc w/gcc/cp/mapper-client.cc
index 2ad770b3d78..df821bab7e1 100644
--- i/gcc/cp/mapper-client.cc
+++ w/gcc/cp/mapper-client.cc
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3.  If not see
 // will include it later under the above check
 #include 
 #endif
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 
 #include "line-map.h"
@@ -171,14 +173,18 @@ module_client::open_module_client (location_t loc, const char *o,
 		  }
 		else
 		  {
+		char *ptr;
 		if (!from.empty ())
 		  {
-			fd_from = std::stoul (from, , 10);
-			if (pos != from.size ())
+			/* Sadly str::stoul is not portable.  */
+			const char *cstr = from.c_str ();
+			fd_from = strtoul (cstr, , 10);
+			if (*ptr)
 			  {
+			/* Not a number -- a named pipe.  */
 			int dir = to.empty ()
 			  ? O_RDWR | O_CLOEXEC : O_RDONLY | O_CLOEXEC;
-			fd_from = open (from.c_str (), dir);
+			fd_from = open (cstr, dir);
 			  }
 			if (to.empty ())
 			  fd_to = fd_from;
@@ -190,12 +196,14 @@ module_client::open_module_client (location_t loc, const char *o,
 		  ;
 		else
 		  {
-			fd_to = std::stoul (to, , 10);
-			if (pos != to.size ())
+			const char *cstr = to.c_str ();
+			fd_to = strtoul (cstr, , 10);
+			if (*ptr)
 			  {
+			/* Not a number, a named pipe.  */
 			int dir = from.empty ()
 			  ? O_RDWR | O_CLOEXEC : O_WRONLY | O_CLOEXEC;
-			fd_to = open (to.c_str (), dir);
+			fd_to = open (cstr, dir);
 			if (fd_to < 0)
 			  close (fd_from);
 			  }
diff --git i/gcc/cp/mapper-resolver.cc w/gcc/cp/mapper-resolver.cc
index 53c482441b4..e348757d99c 100644
--- i/gcc/cp/mapper-resolver.cc
+++ w/gcc/cp/mapper-resolver.cc
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 /* Forward to the resolver in c++tools.  */
 
 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #define INCLUDE_ALGORITHM
 #include "system.h"
 
diff --git i/libcody/client.cc w/libcody/client.cc
index 54111b851d0..edfe44d34b2 100644
--- i/libcody/client.cc
+++ w/libcody/client.cc
@@ -6,6 +6,7 @@
 #include "internal.hh"
 // C
 #include 
+#include 
 #include 
 
 // Client code
diff --git i/libcody/server.cc w/libcody/server.cc
index b9ceec48a68..e2fa069bb93 100644
--- i/libcody/server.cc
+++ w/libcody/server.cc
@@ -8,6 +8,7 @@
 #include 
 // C
 #include 
+#include 
 #include 
 
 // Server code


Re: [PATCH 3/4] libstdc++: Add floating-point std::to_chars implementation

2020-12-21 Thread Patrick Palka via Gcc-patches
On Sun, 20 Dec 2020, Maciej W. Rozycki wrote:

> On Thu, 17 Dec 2020, Patrick Palka via Gcc-patches wrote:
> 
> > > >libstdc++-v3/ChangeLog:
> > > >
> > > >   * config/abi/pre/gnu.ver: Add new exports.
> > > >   * include/std/charconv (to_chars): Declare the floating-point
> > > >   overloads for float, double and long double.
> > > >   * src/c++17/Makefile.am (sources): Add floating_to_chars.cc.
> > > >   * src/c++17/Makefile.in: Regenerate.
> > > >   * src/c++17/floating_to_chars.cc: New file.
> > > >   (to_chars): Define for float, double and long double.
> > > >   * testsuite/20_util/to_chars/long_double.cc: New test.
> > >
> > > Sorry it took so long to review, this is OK for trunk.
> > >
> > > The patch needs some minor changes to rebase it on the current trunk:
> > > The linker script has additions since you send this patch, so the
> > > context in the patch is wrong and it doesn't apply, and in 
> > > the first line of context in the patch needs to have 'noexcept' added.
> > > That rebase should be easy though.
> > >
> > > I'll look at adding __float128 support for powerpc64le.
> > 
> > Thanks a lot.  I committed the patch series just now, after rebasing
> > and retesting on x86_64, aarch64 and ppc64le.
> 
>  This breaks with the `vax-netbsdelf' target in GCC compilation:
> 
> .../libstdc++-v3/src/c++17/floating_to_chars.cc:126:38: error: static 
> assertion failed
>   126 |   static_assert(__DBL_MANT_DIG__ == 53);
>   |  ^
> make[5]: *** [Makefile:577: floating_to_chars.lo] Error 1
> 
> So what's the fallback/alternative for non-IEEE-754 FP targets?  Shouldn't 
> we call into libc (possibly with a warning attribute) for the formats we 
> don't have explicit handcoded support for?

Sorry about this bootstrap breakage.  For now, we should probably just
disable the entire file/implementation on such targets until a proper
fallback could be implemented.  I posted a patch to that effect here
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562379.html
which is pending review/approval.  Until then, manually stubbing out all of
floating_to_chars.cc should probably suffice to restore bootstrap on
this target.



[PATCH] libstdc++: Gracefully disable floating-point to_chars on unsupported targets

2020-12-21 Thread Patrick Palka via Gcc-patches
This patch conditionally disables the floating-point std::to_chars
implementation on targets whose float/double are not IEEE binary32 and
binary64 respectively, until a proper fallback can be added for such
targets.  This fixes a bootstrap failure on non-IEEE-754 FP targets such
as vax-netbsdelf.

The preprocessor conditions that define the new internal libstdc++
macros for detecting the binary32 and binary64 formats were copied from
the test gcc/testsuite/gcc.dg/float-exact-1.c.

Tested on x86_64-pc-linux-gnu, with and without -m32, and also when
artifically undefining the below new macros.  Does this look OK for
trunk?

libstdc++-v3/ChangeLog:

* include/bits/c++config (_GLIBCXX_FLOAT_IS_IEEE_BINARY_32):
Define this macro.
(_GLIBCXX_DOUBLE_IS_IEEE_BINARY_64): Likewise.
* include/std/charconv (to_chars): Use the macros to
conditionally hide the overloads for floating-point types.
* src/c++17/floating_to_chars.cc: Use the macros to
conditionally disable this file.
(floating_type_traits): Remove redundant static assert.
(floating_type_traits): Likewise.
* testsuite/20_util/to_chars/double.cc: Use the macros to
conditionally disable this test.
* testsuite/20_util/to_chars/float.cc: Likewise.
* testsuite/20_util/to_chars/long_double.cc: Likewise.  Adjust
dg-do directives so that we don't execute this test on targets
with a large long double type and without int128.
---
 libstdc++-v3/include/bits/c++config | 14 ++
 libstdc++-v3/include/std/charconv   |  2 ++
 libstdc++-v3/src/c++17/floating_to_chars.cc |  9 +
 .../testsuite/20_util/to_chars/double.cc|  2 ++
 .../testsuite/20_util/to_chars/float.cc |  2 ++
 .../testsuite/20_util/to_chars/long_double.cc   | 17 +
 6 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 8cce88aa87b..f54074a2c04 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -688,6 +688,20 @@ namespace std
 # endif
 #endif
 
+// Define if float has the IEEE binary32 format.
+#if __FLT_MANT_DIG__ == 24 \
+  && __FLT_MIN_EXP__ == -125 \
+  && __FLT_MAX_EXP == 128
+# define _GLIBCXX_FLOAT_IS_IEEE_BINARY32 1
+#endif
+
+// Define if double has the IEEE binary64 format.
+#if __DBL_MANT_DIG__ == 53 \
+  && __DBL_MIN_EXP__ == -1021 \
+  && __DBL_MAX_EXP__ == 1024
+# define _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 1
+#endif
+
 #ifdef __has_builtin
 # ifdef __is_identifier
 // Intel and older Clang require !__is_identifier for some built-ins:
diff --git a/libstdc++-v3/include/std/charconv 
b/libstdc++-v3/include/std/charconv
index b57b0a16db2..1f005be47b1 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -704,6 +704,7 @@ namespace __detail
 
   // Floating-point std::to_chars
 
+#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
   // Overloads for float.
   to_chars_result to_chars(char* __first, char* __last, float __value) 
noexcept;
   to_chars_result to_chars(char* __first, char* __last, float __value,
@@ -725,6 +726,7 @@ namespace __detail
   chars_format __fmt) noexcept;
   to_chars_result to_chars(char* __first, char* __last, long double __value,
   chars_format __fmt, int __precision) noexcept;
+#endif
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc 
b/libstdc++-v3/src/c++17/floating_to_chars.cc
index b7c31c746cc..6d94d46cc0a 100644
--- a/libstdc++-v3/src/c++17/floating_to_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
@@ -22,6 +22,10 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 
+// This implementation crucially assumes float/double have the
+// IEEE binary32/binary64 formats.
+#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
+
 // Activate __glibcxx_assert within this file to shake out any bugs.
 #define _GLIBCXX_ASSERTIONS 1
 
@@ -109,8 +113,6 @@ namespace
   template<>
 struct floating_type_traits
 {
-  // We (and Ryu) assume float has the IEEE binary32 format.
-  static_assert(__FLT_MANT_DIG__ == 24);
   static constexpr int mantissa_bits = 23;
   static constexpr int exponent_bits = 8;
   static constexpr bool has_implicit_leading_bit = true;
@@ -124,8 +126,6 @@ namespace
   template<>
 struct floating_type_traits
 {
-  // We (and Ryu) assume double has the IEEE binary64 format.
-  static_assert(__DBL_MANT_DIG__ == 53);
   static constexpr int mantissa_bits = 52;
   static constexpr int exponent_bits = 11;
   static constexpr bool has_implicit_leading_bit = true;
@@ -1565,3 +1565,4 @@ _ZSt8to_charsPcS_eSt12chars_formati(char* first, char* 
last, 

Re: [PATCH, fix bootstrap] libcody: Include as needed

2020-12-21 Thread Nathan Sidwell

On 12/21/20 11:19 AM, Gerald Pfeifer wrote:


 We explicitly need to inlude netinet.h, (despite what happened on my test 
systems)
 
 libcody/

 * netclient.cc: Add netinet.h.

Note, though, that my patch also fixed libcody/netserver.cc, which still
failed. Seeing that your commit essentially matches my proposed patch, I
went ahead and committed the remaining part.

With that libcody now builds (and I'll look into the follow-up patch
you shared).


thanks, I didn't realize you had a patch already.

nathan

--
Nathan Sidwell


[PATCH] rtl-ssa: Fix updates to call clobbers [PR98403]

2020-12-21 Thread Richard Sandiford via Gcc-patches
In the PR, fwprop was changing a call instruction and tripped
an assert when trying to update a list of call clobbers.
There are two ways we could handle this: remove the call clobber
and then add it back, or assume that the clobber will stay in its
current place.

At the moment we don't have enough information to safely move
calls around, so the second approach seems simpler and more
efficient.

Tested on x86_64-linux-gnu and aarch64-linux-gnu.  OK to install?

Richard


gcc/
PR rtl-optimization/98403
* rtl-ssa/changes.cc (function_info::finalize_new_accesses): Explain
why we don't remove call clobbers.
(function_info::apply_changes_to_insn): Don't attempt to add
call clobbers here.

gcc/testsuite/
PR rtl-optimization/98403
* g++.dg/opt/pr98403.C: New test.
---
 gcc/rtl-ssa/changes.cc |   9 +-
 gcc/testsuite/g++.dg/opt/pr98403.C | 195 +
 2 files changed, 200 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/opt/pr98403.C

diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc
index 1885a80e2e9..aac64a00d07 100644
--- a/gcc/rtl-ssa/changes.cc
+++ b/gcc/rtl-ssa/changes.cc
@@ -423,7 +423,8 @@ function_info::finalize_new_accesses (insn_change )
   }
 
   // Also keep any explicitly-recorded call clobbers, which are deliberately
-  // excluded from the vec_rtx_properties.
+  // excluded from the vec_rtx_properties.  Calls shouldn't move, so we can
+  // keep the definitions in their current position.
   for (def_info *def : change.new_defs)
 if (def->m_has_been_superceded && def->is_call_clobber ())
   {
@@ -533,10 +534,10 @@ function_info::apply_changes_to_insn (insn_change )
   // Copy the cost.
   insn->set_cost (change.new_cost);
 
-  // Add all clobbers.  Sets never moved relative to other definitions,
-  // so are OK as-is.
+  // Add all clobbers.  Sets and call clobbers never move relative to
+  // other definitions, so are OK as-is.
   for (def_info *def : change.new_defs)
-if (is_a (def))
+if (is_a (def) && !def->is_call_clobber ())
   add_def (def);
 
   // Add all uses, now that their position is final.
diff --git a/gcc/testsuite/g++.dg/opt/pr98403.C 
b/gcc/testsuite/g++.dg/opt/pr98403.C
new file mode 100644
index 000..25522958112
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr98403.C
@@ -0,0 +1,195 @@
+// { dg-options "-Og -fcse-follow-jumps -fipa-ra" }
+// { dg-require-effective-target c++11 }
+// { dg-additional-options "-march=goldmont -fPIC -mforce-indirect-call" { 
target { { i?86-*-* x86_64-*-* } && fpic } } }
+
+enum WindowClass { WC_NONE, WC_AI_SETTINGS, WC_AI_LIST };
+enum { AWV_DECREASE, AWV_INCREASE };
+enum WidgetType {
+  WWT_PANEL,
+  WWT_TEXT,
+  WWT_MATRIX,
+  WWT_FRAME,
+  WWT_CAPTION,
+  WWT_DEFSIZEBOX,
+  WWT_RESIZEBOX,
+  WWT_CLOSEBOX,
+  NWID_HORIZONTAL,
+  NWID_VERTICAL,
+  NWID_SPACER,
+  NWID_VSCROLLBAR,
+  WWT_PUSHTXTBTN,
+  WWT_PUSHARROWBTN
+};
+enum NWidContainerFlags { NC_NONE };
+struct NWidgetPartPIP {
+  char prepost;
+};
+struct NWidgetPart {
+  NWidgetPartPIP pip;
+} __trans_tmp_1;
+static NWidgetPart SetResize(short, short) {
+  NWidgetPart part;
+  return part;
+}
+NWidgetPart SetMinimalSize(short, short);
+static NWidgetPart SetFill(int, int) {
+  NWidgetPart part;
+  return part;
+}
+static NWidgetPart EndContainer() {
+  NWidgetPart part;
+  return part;
+}
+static NWidgetPart SetDataTip(int, int) {
+  NWidgetPart part;
+  return part;
+}
+static NWidgetPart SetMatrixDataTip(char, char, int) { return __trans_tmp_1; }
+NWidgetPart SetPadding();
+NWidgetPart SetScrollbar(int);
+NWidgetPart NWidget(WidgetType, NWidContainerFlags = NC_NONE);
+struct WindowDesc {
+  WindowDesc(const char *, short, short, WindowClass, WindowClass, int,
+ const NWidgetPart *, short, int * = nullptr);
+  ~WindowDesc();
+};
+class CommandCost {
+public:
+  CommandCost(int);
+} const CMD_ERROR(5);
+enum { WID_AIC_SCROLLBAR };
+const NWidgetPart _nested_ai_list_widgets[]{NWidget(NWID_HORIZONTAL),
+NWidget(WWT_CLOSEBOX),
+NWidget(WWT_CAPTION),
+SetDataTip(8, 4),
+NWidget(WWT_DEFSIZEBOX),
+NWidget(NWID_HORIZONTAL),
+NWidget(WWT_MATRIX),
+SetMinimalSize(8, 2),
+SetFill(1, 1),
+SetResize(1, 1),
+SetMatrixDataTip(1, 0, 1),
+EndContainer(),
+NWidget(WWT_PANEL),
+EndContainer(),
+NWidget(NWID_HORIZONTAL),
+ 

Re: [PATCH, fix bootstrap] libcody: Include as needed

2020-12-21 Thread Gerald Pfeifer
On Mon, 21 Dec 2020, Nathan Sidwell wrote:
> On 12/20/20 6:28 PM, Gerald Pfeifer wrote:
>> libcody as originally added to GCC fails to build on *-unknown-freebsd11.4
>> and presumably others:
>> 
>>c++ -std=c++11 -g -include config.h -I ... -MMD -MP -MF netclient.d -c
>>  -o netclient.o
>>.../libcody/netclient.cc:114:3: error: unknown type sockaddr_in6 addr;
>>^~~~
> That should be fixed now

libcody/netclient.cc is indeed fixed, after 

  commit 31705b068fa5d6cbd04aa4ac5f5275bad37d
  Author: Nathan Sidwell 
  Date:   Mon Dec 21 05:36:32 2020 -0800

libcody: Add netinet.h

We explicitly need to inlude netinet.h, (despite what happened on my test 
systems)

libcody/
* netclient.cc: Add netinet.h.

Note, though, that my patch also fixed libcody/netserver.cc, which still 
failed. Seeing that your commit essentially matches my proposed patch, I 
went ahead and committed the remaining part.

With that libcody now builds (and I'll look into the follow-up patch
you shared).

Thanks,
Gerald


[PATCHv2] hurd: libgcc unwinding over signal trampolines with SIGINFO

2020-12-21 Thread Samuel Thibault via Gcc-patches
When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

libgcc/
* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the posix
siginfo case to struct handler_args. Detect between legacy and siginfo from
the second parameter, which is a small sigcode in the legacy case, and a
pointer in the siginfo case.

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..f83411e3de4 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
 int signo;
-int sigcode;
-struct sigcontext *scp;
+union
+  {
+   struct
+ {
+   long int sigcode;
+   struct sigcontext *scp;
+ } legacy;
+   struct
+ {
+   siginfo_t *siginfop;
+   ucontext_t *uctxp;
+ } posix;
+  };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
 return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode >= -16 && sigcode < 4096)
+{
+  /* This cannot be a SIGINFO pointer, assume legacy.  */
+  struct sigcontext *scp = handler_args->legacy.scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.reg[0].loc.offset = (unsigned long)>sc_eax - usp;
+  fs->regs.reg[1].loc.offset = (unsigned long)>sc_ecx - usp;
+  fs->regs.reg[2].loc.offset = (unsigned long)>sc_edx - usp;
+  fs->regs.reg[3].loc.offset = (unsigned long)>sc_ebx - usp;
+  fs->regs.reg[5].loc.offset = (unsigned long)>sc_ebp - usp;
+  fs->regs.reg[6].loc.offset = (unsigned long)>sc_esi - usp;
+  fs->regs.reg[7].loc.offset = (unsigned long)>sc_edi - usp;
+  fs->regs.reg[8].loc.offset = (unsigned long)>sc_eip - usp;
+}
+  else
+{
+  /* This is not a valid sigcode, assume SIGINFO.  */
+  ucontext_t *uctxp = handler_args->posix.uctxp;
+  gregset_t *gregset = >uc_mcontext.gregs;
+  usp = (*gregset)[REG_UESP];
+
+  fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+  fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+  fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+  fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+  fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+  fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+  fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+  fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+}
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)>sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)>sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)>sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)>sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)>sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)>sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)>sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)>sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 


libcody: Add ranlib

2020-12-21 Thread Nathan Sidwell

Add RANLIB.

libcody/
* Makefile.in (RANLIB): New var.
* Makesub.in (libcody.a): Apply RANLIB.
* configure.in: Call AC_PROG_RANLIB.
* configure: Rebuilt.


--
Nathan Sidwell
diff --git c/libcody/Makefile.in w/libcody/Makefile.in
index 28ed3a22299..a0722f9a385 100644
--- c/libcody/Makefile.in
+++ w/libcody/Makefile.in
@@ -48,6 +48,7 @@ SHELL := $(shell which zsh 2>/dev/null >/dev/null && echo zsh \
 # We have to place the -I paths last, so that building will see -I paths to us
 CXX := $(filter-out -I%,@CXX@)
 AR := @AR@
+RANLIB := @RANLIB@
 INSTALL := $(srcdir)/build-aux/install-sh
 
 # C++ compiler options
diff --git c/libcody/Makesub.in w/libcody/Makesub.in
index 0bfe6f6c1b3..6ae49d6c793 100644
--- c/libcody/Makesub.in
+++ w/libcody/Makesub.in
@@ -19,6 +19,7 @@ all:: libcody.a
 
 libcody.a: $(LIBCODY.O)
 	$(AR) -cr $@ $^
+	$(RANLIB) $@
 
 clean::
 	rm -f $(LIBCODY.O) $(LIBCODY.O:.o=.d)
diff --git c/libcody/configure w/libcody/configure
index b9967a1cd8d..af3a3074a35 100755
--- c/libcody/configure
+++ w/libcody/configure
@@ -590,6 +590,7 @@ LIBOBJS
 ALOY
 DOXYGEN
 AR
+RANLIB
 EXCEPTIONS
 PICFLAG
 CONFIG_FILES
@@ -2791,6 +2792,98 @@ fi
 
 ac_config_headers="$ac_config_headers config.h"
 
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ac_cv_prog_ac_ct_RANLIB="ranlib"
+$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+RANLIB=":"
+  else
+case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
 if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
 set dummy ${ac_tool_prefix}ar; ac_word=$2
diff --git c/libcody/configure.ac w/libcody/configure.ac
index 511fe261b45..598e585a91b 100644
--- c/libcody/configure.ac
+++ w/libcody/configure.ac
@@ -76,6 +76,7 @@ AC_SUBST(PICFLAG)
 NMS_ENABLE_EXCEPTIONS
 
 AC_CONFIG_HEADERS([config.h])
+AC_PROG_RANLIB
 AC_CHECK_TOOL([AR],[ar])
 AC_CHECK_PROG([DOXYGEN],[doxygen],[doxygen],[: NOTdoxygen])
 AC_CHECK_PROG([ALOY],[aloy],[aloy],[: Joust testsuite missing])


Re: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

2020-12-21 Thread Samuel Thibault via Gcc-patches
Jessica Clarke, le lun. 21 déc. 2020 14:21:39 +, a ecrit:
> On 21 Dec 2020, at 14:09, Samuel Thibault  wrote:
> > @@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
> > return _URC_END_OF_STACK;
> > 
> >   handler_args = context->cfa;
> > -  scp = handler_args->scp;
> > -  usp = scp->sc_uesp;
> > +  sigcode = handler_args->legacy.sigcode;
> > +  if (sigcode < 4096)
> 
> Do you not need >= 0 to handle the 3/1 split correctly?

Ah, right, that's an signed integer, I'll add that.

Thanks,
Samuel


Re: [PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

2020-12-21 Thread Jessica Clarke
On 21 Dec 2020, at 14:09, Samuel Thibault  wrote:
> @@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
> return _URC_END_OF_STACK;
> 
>   handler_args = context->cfa;
> -  scp = handler_args->scp;
> -  usp = scp->sc_uesp;
> +  sigcode = handler_args->legacy.sigcode;
> +  if (sigcode < 4096)

Do you not need >= 0 to handle the 3/1 split correctly?

Jess



[PATCH] hurd: libgcc unwinding over signal trampolines with SIGINFO

2020-12-21 Thread Samuel Thibault via Gcc-patches
When the application sets SA_SIGINFO, the signal trampoline parameters
are different to follow POSIX.

libgcc/
* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Add the posix
siginfo case to struct handler_args. Detect between legacy and siginfo from
the second parameter, which is a small sigcode in the legacy case, and a
pointer in the siginfo case.

diff --git a/libgcc/config/i386/gnu-unwind.h b/libgcc/config/i386/gnu-unwind.h
index db47f0ac1d4..3eefe7de7e5 100644
--- a/libgcc/config/i386/gnu-unwind.h
+++ b/libgcc/config/i386/gnu-unwind.h
@@ -38,10 +38,21 @@ x86_gnu_fallback_frame_state
 {
   struct handler_args {
 int signo;
-int sigcode;
-struct sigcontext *scp;
+union
+  {
+   struct
+ {
+   long int sigcode;
+   struct sigcontext *scp;
+ } legacy;
+   struct
+ {
+   siginfo_t *siginfop;
+   ucontext_t *uctxp;
+ } posix;
+  };
   } *handler_args;
-  struct sigcontext *scp;
+  long int sigcode;
   unsigned long usp;
 
 /*
@@ -75,29 +86,52 @@ x86_gnu_fallback_frame_state
 return _URC_END_OF_STACK;
 
   handler_args = context->cfa;
-  scp = handler_args->scp;
-  usp = scp->sc_uesp;
+  sigcode = handler_args->legacy.sigcode;
+  if (sigcode < 4096)
+{
+  /* This cannot be a SIGINFO pointer, assume legacy.  */
+  struct sigcontext *scp = handler_args->legacy.scp;
+  usp = scp->sc_uesp;
+
+  fs->regs.reg[0].loc.offset = (unsigned long)>sc_eax - usp;
+  fs->regs.reg[1].loc.offset = (unsigned long)>sc_ecx - usp;
+  fs->regs.reg[2].loc.offset = (unsigned long)>sc_edx - usp;
+  fs->regs.reg[3].loc.offset = (unsigned long)>sc_ebx - usp;
+  fs->regs.reg[5].loc.offset = (unsigned long)>sc_ebp - usp;
+  fs->regs.reg[6].loc.offset = (unsigned long)>sc_esi - usp;
+  fs->regs.reg[7].loc.offset = (unsigned long)>sc_edi - usp;
+  fs->regs.reg[8].loc.offset = (unsigned long)>sc_eip - usp;
+}
+  else
+{
+  /* This is not a valid sigcode, assume SIGINFO.  */
+  ucontext_t *uctxp = handler_args->posix.uctxp;
+  gregset_t *gregset = >uc_mcontext.gregs;
+  usp = (*gregset)[REG_UESP];
+
+  fs->regs.reg[0].loc.offset = (unsigned long)&(*gregset)[REG_EAX] - usp;
+  fs->regs.reg[1].loc.offset = (unsigned long)&(*gregset)[REG_ECX] - usp;
+  fs->regs.reg[2].loc.offset = (unsigned long)&(*gregset)[REG_EDX] - usp;
+  fs->regs.reg[3].loc.offset = (unsigned long)&(*gregset)[REG_EBX] - usp;
+  fs->regs.reg[5].loc.offset = (unsigned long)&(*gregset)[REG_EBP] - usp;
+  fs->regs.reg[6].loc.offset = (unsigned long)&(*gregset)[REG_ESI] - usp;
+  fs->regs.reg[7].loc.offset = (unsigned long)&(*gregset)[REG_EDI] - usp;
+  fs->regs.reg[8].loc.offset = (unsigned long)&(*gregset)[REG_EIP] - usp;
+}
 
   fs->regs.cfa_how = CFA_REG_OFFSET;
   fs->regs.cfa_reg = 4;
   fs->regs.cfa_offset = usp - (unsigned long) context->cfa;
 
   fs->regs.reg[0].how = REG_SAVED_OFFSET;
-  fs->regs.reg[0].loc.offset = (unsigned long)>sc_eax - usp;
   fs->regs.reg[1].how = REG_SAVED_OFFSET;
-  fs->regs.reg[1].loc.offset = (unsigned long)>sc_ecx - usp;
   fs->regs.reg[2].how = REG_SAVED_OFFSET;
-  fs->regs.reg[2].loc.offset = (unsigned long)>sc_edx - usp;
   fs->regs.reg[3].how = REG_SAVED_OFFSET;
-  fs->regs.reg[3].loc.offset = (unsigned long)>sc_ebx - usp;
   fs->regs.reg[5].how = REG_SAVED_OFFSET;
-  fs->regs.reg[5].loc.offset = (unsigned long)>sc_ebp - usp;
   fs->regs.reg[6].how = REG_SAVED_OFFSET;
-  fs->regs.reg[6].loc.offset = (unsigned long)>sc_esi - usp;
   fs->regs.reg[7].how = REG_SAVED_OFFSET;
-  fs->regs.reg[7].loc.offset = (unsigned long)>sc_edi - usp;
   fs->regs.reg[8].how = REG_SAVED_OFFSET;
-  fs->regs.reg[8].loc.offset = (unsigned long)>sc_eip - usp;
+
   fs->retaddr_column = 8;
   fs->signal_frame = 1;
 


Re: C++ 20 modules

2020-12-21 Thread Nathan Sidwell

On 12/20/20 6:57 PM, Gerald Pfeifer wrote:

On Thu, 17 Dec 2020, Nathan Sidwell wrote:

As yesterday, several issues fixed:


Here is a new one, *-unknown-freebsd11.4; with my previous patch



/scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.cc
In file included from /scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.cc:31:
In file included from /scratch/tmp/gerald/GCC-HEAD/gcc/cp/mapper-client.h:26:
In file included from /scratch/tmp/gerald/GCC-HEAD/gcc/../libcody/cody.hh:24:
In file included from /usr/include/c++/v1/memory:653:
/usr/include/c++/v1/typeinfo:346:5: error: no member named 'fancy_abort' in 
namespace 'std::__1'; did you mean simply 'fancy_abort'?
 _VSTD::abort();
 ^~~
/usr/include/c++/v1/__config:782:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
   ^


Care to try this?


--
Nathan Sidwell
diff --git i/gcc/cp/mapper-client.cc w/gcc/cp/mapper-client.cc
index 2ad770b3d78..40e9283a794 100644
--- i/gcc/cp/mapper-client.cc
+++ w/gcc/cp/mapper-client.cc
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3.  If not see
 // will include it later under the above check
 #include 
 #endif
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 
 #include "line-map.h"
diff --git i/gcc/cp/mapper-resolver.cc w/gcc/cp/mapper-resolver.cc
index 53c482441b4..e348757d99c 100644
--- i/gcc/cp/mapper-resolver.cc
+++ w/gcc/cp/mapper-resolver.cc
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 /* Forward to the resolver in c++tools.  */
 
 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #define INCLUDE_ALGORITHM
 #include "system.h"
 


Re: [PATCH, fix bootstrap] libcody: Include as needed

2020-12-21 Thread Nathan Sidwell

On 12/20/20 6:28 PM, Gerald Pfeifer wrote:

libcody as originally added to GCC fails to build on *-unknown-freebsd11.4
and presumably others:

   c++ -std=c++11 -g -include config.h -I ... -MMD -MP -MF netclient.d -c
 -o netclient.o
   .../libcody/netclient.cc:114:3: error: unknown type sockaddr_in6 addr;
   ^~~~



That should be fixed now


--
Nathan Sidwell


libcody: Add netinet.h

2020-12-21 Thread Nathan Sidwell
We explicitly need to inlude netinet.h, (despite what happened on my 
test systems)


libcody/
* netclient.cc: Add netinet.h.

--
Nathan Sidwell
diff --git c/libcody/netclient.cc w/libcody/netclient.cc
index 8cccface71c..7f81dd91810 100644
--- c/libcody/netclient.cc
+++ w/libcody/netclient.cc
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef AI_NUMERICSERV


libcody: to_string is not always available [PR 98412]

2020-12-21 Thread Nathan Sidwell

to_string is not always available, so don't use it.

libcody/
* buffer.cc (MessageBuffer::AppendInteger): Workaround
to_string's non-ubiquity.

--
Nathan Sidwell
diff --git i/libcody/buffer.cc w/libcody/buffer.cc
index 3256c37399b..85c066fef71 100644
--- i/libcody/buffer.cc
+++ w/libcody/buffer.cc
@@ -146,7 +146,13 @@ void MessageBuffer::Append (char c)
 
 void MessageBuffer::AppendInteger (unsigned u)
 {
-  std::string v (std::to_string (u));
+  // Sigh, even though std::to_string is C++11, we support building on
+  // gcc 4.8, which is a C++11 compiler lacking std::to_string.  so
+  // have something horrible.
+  std::string v (20, 0);
+  size_t len = snprintf (const_cast (v.data ()), v.size (), "%u", u);
+  v.erase (len);
+
   AppendWord (v);
 }
 


libcody: Fix exe suffix [PR 98409]

2020-12-21 Thread Nathan Sidwell

I had a thinko about variable case, and, coupled with Make's behaviour
of just consing up variables out of nothing, and linux not having an
executable extension, didn't notice.

PR other/98409
libcody/
* Makefile.in: Fix exeext variable case.

--
Nathan Sidwell
diff --git i/c++tools/Makefile.in w/c++tools/Makefile.in
index 87f9236c203..7dc67ad9e06 100644
--- i/c++tools/Makefile.in
+++ w/c++tools/Makefile.in
@@ -29,7 +29,7 @@ AUTOHEADER := @AUTOHEADER@
 CXX := @CXX@
 CXXFLAGS := @CXXFLAGS@
 CXXOPTS := $(CXXFLAGS) -fno-exceptions -fno-rtti
-EXEEXT := @EXEEXT@
+exeext := @EXEEXT@
 LIBIBERTY := ../libiberty/libiberty.a
 VERSION.O := ../gcc/version.o
 


Re: [PATCH][X86] Fix Typo

2020-12-21 Thread Uros Bizjak via Gcc-patches
On Mon, Dec 21, 2020 at 12:01 PM Hongtao Liu  wrote:
>
>   When i'm working on PR98348, i notice there's Typo in define_insn
> "*one_cmpl2_1", There are 2 alternatives, so the index couldn't
> be 2.
>   Bootstrap and regress test is ok on x86_64-unknown-linux.
>
> gcc/ChangeLog
>
> * config/i386/i386.md (*one_cmpl2_1): Fix typo, change
> alternative from 2 to 1 in attr isa.

OK.

Thanks,
Uros.

>
> 1 file changed, 1 insertion(+), 1 deletion(-)
> gcc/config/i386/i386.md | 2 +-
>
> modified   gcc/config/i386/i386.md
> @@ -10561,7 +10561,7 @@ (define_insn "*one_cmpl2_1"
> not{}\t%0
> #"
>[(set (attr "isa")
> - (cond [(eq_attr "alternative" "2")
> + (cond [(eq_attr "alternative" "1")
>   (if_then_else (eq_attr "mode" "SI,DI")
>  (const_string "avx512bw")
>
> --
> BR,
> Hongtao


Re: [PATCH, fix bootstrap] libcody: Include as needed

2020-12-21 Thread Sebastian Huber

On 21/12/2020 00:28, Gerald Pfeifer wrote:


libcody as originally added to GCC fails to build on *-unknown-freebsd11.4
and presumably others:

I experienced the same issue with FreeBSD 12 building a cross-compiler.

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/



[PING] [PATCH] Fix -save-temp leaking lto files in /tmp

2020-12-21 Thread Bernd Edlinger
Hi,

I'd like to ping for this patch below:
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/561811.html

Thanks
Bernd.

On 12/14/20 4:31 PM, Bernd Edlinger wrote:
> Hi,
> 
> On 2/21/20 8:35 AM, Richard Biener wrote:
>>
>> IIRC this definitely clashes with Alex work to overhaul
>> -auxdir/-dumpdir queued for GCC 11 where some of the above
>> is improved.
>>
>> So whatever we do we should do it for GCC 11 after Alex patches
>> land.
>>
>> Richard.
>>
> 
> Okay, I think this patch was applied in the mean time.
> Just some 20-30 temp files are left from a full run of the testsuite.
> 
> So I rewrote my patch, and found this time it looks
> feasible to avoid all remaining temp files with unpredictable
> random names, so that is an improvement over the state earlier
> this year.
> 
> 
> Attached is my new patch, to clean up the rest of the -save-temps
> files.  That consist just of a couple of @file parameters.
> 
> I added a few test cases, and the testsuite runs without any
> temp files leaking.
> 
> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
> Is it OK for trunk?
> 
> 
> Thanks
> Bernd.
> 


Re: [patch] libstdc++/testsuite: Tweak dg-prune-output regex for out-of-tree contexts

2020-12-21 Thread Jonathan Wakely via Gcc-patches

On 21/12/20 11:57 +0100, Olivier Hainque wrote:

Thanks for your prompt feedback on this Jonathan.


On 18 Dec 2020, at 23:24, Jonathan Wakely  wrote:


Is this ok to commit ?


Yes, OK, although I wonder if this would be better:

{ dg-prune-output "/(functional|bits/invoke.h):" }


Probably more robust, I agree. This still works
both with build tree (tested on mainline) and install
tree (tested on our gcc-10 branch).

Same ChangeLog.


OK to commit like that then, thanks.



From fe8db9fe481fe705400b1366a8709f7048418c7f Mon Sep 17 00:00:00 2001
From: Olivier Hainque 
Date: Fri, 18 Dec 2020 18:09:21 +
Subject: [PATCH] Tweak dg-prune-output regex for out-of-tree contexts

libstdc++-v3/

* testsuite/20_util/bind/ref_neg.cc: Tweak the
dg-prune-output regex for out-of-build-tree contexts.
---
libstdc++-v3/testsuite/20_util/bind/ref_neg.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc 
b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
index d77ad90cc253..cc392b63a466 100644
--- a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
@@ -49,7 +49,8 @@ void test02()
}

// Ignore the reasons for deduction/substitution failure in the headers.
-// { dg-prune-output "/include/(functional|bits/invoke.h):" }
+// Arrange for the match to work on installed trees as well as build trees.
+// { dg-prune-output "/(functional|bits/invoke.h):" }

int main()
{
--
2.17.1












[PATCH][X86] Fix Typo

2020-12-21 Thread Hongtao Liu via Gcc-patches
  When i'm working on PR98348, i notice there's Typo in define_insn
"*one_cmpl2_1", There are 2 alternatives, so the index couldn't
be 2.
  Bootstrap and regress test is ok on x86_64-unknown-linux.

gcc/ChangeLog

* config/i386/i386.md (*one_cmpl2_1): Fix typo, change
alternative from 2 to 1 in attr isa.

1 file changed, 1 insertion(+), 1 deletion(-)
gcc/config/i386/i386.md | 2 +-

modified   gcc/config/i386/i386.md
@@ -10561,7 +10561,7 @@ (define_insn "*one_cmpl2_1"
not{}\t%0
#"
   [(set (attr "isa")
- (cond [(eq_attr "alternative" "2")
+ (cond [(eq_attr "alternative" "1")
  (if_then_else (eq_attr "mode" "SI,DI")
 (const_string "avx512bw")

-- 
BR,
Hongtao


Re: [patch] libstdc++/testsuite: Tweak dg-prune-output regex for out-of-tree contexts

2020-12-21 Thread Olivier Hainque
Thanks for your prompt feedback on this Jonathan.

> On 18 Dec 2020, at 23:24, Jonathan Wakely  wrote:
> 
>> Is this ok to commit ?
> 
> Yes, OK, although I wonder if this would be better:
> 
> { dg-prune-output "/(functional|bits/invoke.h):" }

Probably more robust, I agree. This still works
both with build tree (tested on mainline) and install
tree (tested on our gcc-10 branch).

Same ChangeLog.

Olivier

From fe8db9fe481fe705400b1366a8709f7048418c7f Mon Sep 17 00:00:00 2001
From: Olivier Hainque 
Date: Fri, 18 Dec 2020 18:09:21 +
Subject: [PATCH] Tweak dg-prune-output regex for out-of-tree contexts

libstdc++-v3/

* testsuite/20_util/bind/ref_neg.cc: Tweak the
dg-prune-output regex for out-of-build-tree contexts.
---
 libstdc++-v3/testsuite/20_util/bind/ref_neg.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc 
b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
index d77ad90cc253..cc392b63a466 100644
--- a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
@@ -49,7 +49,8 @@ void test02()
 }
 
 // Ignore the reasons for deduction/substitution failure in the headers.
-// { dg-prune-output "/include/(functional|bits/invoke.h):" }
+// Arrange for the match to work on installed trees as well as build trees.
+// { dg-prune-output "/(functional|bits/invoke.h):" }
 
 int main()
 {
-- 
2.17.1







[C PATCH] qualifiers of pointers to arrays in C2X [PR 98397]

2020-12-21 Thread Uecker, Martin

Here is a patch that adds the minor corrections needed for
qualifiers of pointers to arrays in C23.

-- Martin


C: Correct qualifiers for pointers to arrays according to C2X [PR98397]

2020-12-12  Martin Uecker  

gcc/c/
 PR c/98397
 * c-typeck.c (comp_target_types): Change pedwarn to pedwarn_c11
 for pointers to arrays with qualifiers.  
 (build_conditional_expr): For C23 don't lose qualifiers for pointers
 to arrays when the other pointer is a void pointer.
 (convert_for_assignment): For C23 don't pedwarn when converting from
 void* with qualifiers to a pointer to array with the same qualifiers.

gcc/testsuite/
 PR c/98397
 * gcc.dg/c2x-qual-1.c: New test.   
 * gcc.dg/c2x-qual-2.c: New test.


diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index f68cb01529b..46a66e96db5 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -1318,8 +1318,8 @@ comp_target_types (location_t location, tree ttl, tree 
ttr)
   val = comptypes_check_enum_int (mvl, mvr, _and_int_p);
 
   if (val == 1 && val_ped != 1)
-pedwarn (location, OPT_Wpedantic, "pointers to arrays with different 
qualifiers "
-  "are incompatible in ISO C");
+pedwarn_c11 (location, OPT_Wpedantic, "pointers to arrays with different 
qualifiers "
+     "are incompatible in ISO C before 
C2X");
 
   if (val == 2)
 pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
@@ -5331,39 +5331,32 @@ build_conditional_expr (location_t colon_loc, tree 
ifexp, bool ifexp_bcp,
    "used in conditional expression");
      return error_mark_node;
    }
-  else if (VOID_TYPE_P (TREE_TYPE (type1))
-      && !TYPE_ATOMIC (TREE_TYPE (type1)))
-   {
-     if ((TREE_CODE (TREE_TYPE (type2)) == ARRAY_TYPE)
-     && (TYPE_QUALS (strip_array_types (TREE_TYPE (type2)))
-     & ~TYPE_QUALS (TREE_TYPE (type1
+  else if ((VOID_TYPE_P (TREE_TYPE (type1))
+   && !TYPE_ATOMIC (TREE_TYPE (type1)))
+      || (VOID_TYPE_P (TREE_TYPE (type2))
+      && !TYPE_ATOMIC (TREE_TYPE (type2
+   {
+     tree t1 = TREE_TYPE (type1);
+     tree t2 = TREE_TYPE (type2);
+     if (!VOID_TYPE_P (t1))
+      {
+    /* roles are swapped */
+    t1 = t2;
+    t2 = TREE_TYPE (type1);
+      }
+     tree t2_stripped = strip_array_types (t2);
+     if (flag_isoc2x)
+   t2 = t2_stripped;
+     else if ((TREE_CODE (t2) == ARRAY_TYPE)
+      && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
    warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
    "pointer to array loses qualifier "
    "in conditional expression");
-
-     if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
-   pedwarn (colon_loc, OPT_Wpedantic,
-    "ISO C forbids conditional expr between "
-    "% and function pointer");
-     result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
-     TREE_TYPE (type2)));
-   }
-  else if (VOID_TYPE_P (TREE_TYPE (type2))
-      && !TYPE_ATOMIC (TREE_TYPE (type2)))
-   {
-     if ((TREE_CODE (TREE_TYPE (type1)) == ARRAY_TYPE)
-     && (TYPE_QUALS (strip_array_types (TREE_TYPE (type1)))
-     & ~TYPE_QUALS (TREE_TYPE (type2
-   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
-   "pointer to array loses qualifier "
-   "in conditional expression");
-
-     if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
+     if (TREE_CODE (t2) == FUNCTION_TYPE)
    pedwarn (colon_loc, OPT_Wpedantic,
     "ISO C forbids conditional expr between "
     "% and function pointer");
-     result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
-     TREE_TYPE (type1)));
+     result_type = build_pointer_type (qualify_type (t1, t2));
    }
   /* Objective-C pointer comparisons are a bit more lenient.  */
   else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
@@ -7319,7 +7312,7 @@ convert_for_assignment (location_t location, location_t 
expr_loc, tree type,
      /* Don't warn about loss of qualifier for conversions from
     qualified void* to pointers to arrays with corresponding
     qualifier on the element type. */
-     if (!pedantic)
+     if (flag_isoc2x || !pedantic)
    ttl = strip_array_types (ttl);
 
      /* Assignments between atomic and non-atomic objects are OK.  */
diff --git a/gcc/testsuite/gcc.dg/c2x-qual-1.c 
b/gcc/testsuite/gcc.dg/c2x-qual-1.c
new file mode 100644
index 000..058a840e04c
--- 

Re: [PATCH] Make switchconv smarter.

2020-12-21 Thread Martin Liška

On 12/18/20 2:19 PM, Martin Liška wrote:

The patch covers 2 cases mentioned in the PR.


I've got a discussion with Jakub on IRC about the patch and he sees
2 more optimizations:

1) using VRP information (from ranger) - I'm leaving that to him, or I can 
return
to it in the next stage 1

2) considering 'return;' (in non-void function) for other cases that default
and __builtin_unreachable for other case than the default one

Let's consider:

unsigned
f1(unsigned x) {
  switch (x) {
case 0:
  return 10;
case 1:
  __builtin_unreachable ();
case 2:
  return;
case 4:
  return;
case 10:
  return 23;
case 13:
  return;
  }

  return ;
}

2a) that can be possible, but to be honest I don't see many cases where it can 
help:
- one can see the warning that is quite obvious:

/home/marxin/Programming/testcases/s.c:9:7: warning: ‘return’ with no value, in 
function returning non-void
9 |   return;
  |   ^~
/home/marxin/Programming/testcases/s.c:2:1: note: declared here
2 | f1(unsigned x) {
  | ^~

- we can leverage the information and return any value; there's so work 
that needs to be done
  in contains_linear_function_p where we need to skip the "random" values 
and the CFG checking
  code must be adjusted to ignore such cases

2b) the __builtin_unreachable in 'case 1' is removed by unreachable block 
removal and we can't see it:

  switch (x_2(D))  [INV], case 0:  [INV], case 2:  [INV], case 4:  
[INV], case 10:  [INV], case 13:  [INV]>

Overall, I tend to leave to the next stage1. The pass needs some bigger 
refactoring and I don't feel
familiar enough to modify it now.

Thanks for understanding,
Martin


Re: Patch RFA: Support non-ASCII file names in git-changelog

2020-12-21 Thread Martin Liška

On 12/21/20 10:48 AM, Jakub Jelinek wrote:

I have no idea who that is (if it is a single user at all,
if it isn't any user with git write permissions).


CCing Joel, he should help us how to set a git config
that will be used by the server hooks.

Martin


Re: Patch RFA: Support non-ASCII file names in git-changelog

2020-12-21 Thread Jakub Jelinek via Gcc-patches
On Mon, Dec 21, 2020 at 10:39:31AM +0100, Martin Liška wrote:
> On 12/18/20 7:30 PM, Ian Lance Taylor wrote:
> > I don't know the tradeoffs here.  This approach sounds fine to me.
> 
> Trade off is that we need to setup server (that's fine).
> And people have to locally do the same, otherwise they'll newly see:
> 
> $ git gcc-verify  -p
> Checking 6c439cadf0362cc0f8f2b894c1b596bbf822849b: FAILED
> ERR: Quoted UTF8 filename, please set: "git config --global core.quotepath 
> false":""kon\303\255\304\215ek.txt""
> 
> @Jakub: Can you please update the server hook (git_commit.py) file and set:
> 
> git config --global core.quotepath false
> 
> for the user that runs the server hooks?

I have no idea who that is (if it is a single user at all,
if it isn't any user with git write permissions).

Jakub



Re: Patch RFA: Support non-ASCII file names in git-changelog

2020-12-21 Thread Martin Liška

On 12/18/20 7:30 PM, Ian Lance Taylor wrote:

I don't know the tradeoffs here.  This approach sounds fine to me.


Trade off is that we need to setup server (that's fine).
And people have to locally do the same, otherwise they'll newly see:

$ git gcc-verify  -p
Checking 6c439cadf0362cc0f8f2b894c1b596bbf822849b: FAILED
ERR: Quoted UTF8 filename, please set: "git config --global core.quotepath 
false":""kon\303\255\304\215ek.txt""

@Jakub: Can you please update the server hook (git_commit.py) file and set:

git config --global core.quotepath false

for the user that runs the server hooks?

Thanks,
Martin


[PATCH][pushed] gcc-changelog: new error for quoted utf8 filenames

2020-12-21 Thread Martin Liška

The patch adds new error for situation where filenames
are quoted.

Pushed to master.
Martin

contrib/ChangeLog:

* gcc-changelog/git_commit.py: Add new error for quoted
filenames.
* gcc-changelog/test_email.py: Test it.
* gcc-changelog/test_patches.txt: Test it.
---
 contrib/gcc-changelog/git_commit.py|  8 
 contrib/gcc-changelog/test_email.py|  4 
 contrib/gcc-changelog/test_patches.txt | 27 ++
 3 files changed, 39 insertions(+)

diff --git a/contrib/gcc-changelog/git_commit.py 
b/contrib/gcc-changelog/git_commit.py
index 01f49874652..f9cb8cbf030 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -299,6 +299,14 @@ class GitCommit:
  'separately from normal commits'))
 return
 
+# check for an encoded utf-8 filename

+hint = 'git config --global core.quotepath false'
+for modified, _ in self.info.modified_files:
+if modified.startswith('"') or modified.endswith('"'):
+self.errors.append(Error('Quoted UTF8 filename, please set: '
+ f'"{hint}"', modified))
+return
+
 all_are_ignored = (len(project_files) + len(ignored_files)
== len(self.info.modified_files))
 self.parse_lines(all_are_ignored)
diff --git a/contrib/gcc-changelog/test_email.py 
b/contrib/gcc-changelog/test_email.py
index 7ba2fcf757e..2053531452c 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -399,3 +399,7 @@ class TestGccChangelog(unittest.TestCase):
 def test_unicode_chars_in_filename(self):
 email = self.from_patch_glob('0001-Add-horse.patch')
 assert not email.errors
+
+def test_bad_unicode_chars_in_filename(self):
+email = self.from_patch_glob('0001-Add-horse2.patch')
+assert email.errors[0].message.startswith('Quoted UTF8 filename')
diff --git a/contrib/gcc-changelog/test_patches.txt 
b/contrib/gcc-changelog/test_patches.txt
index bc93cce1fa7..ffd13682d5c 100644
--- a/contrib/gcc-changelog/test_patches.txt
+++ b/contrib/gcc-changelog/test_patches.txt
@@ -3371,4 +3371,31 @@ index 000..56c67f58752
 +I'm a horse.
 --
 2.29.2
+=== 0001-Add-horse2.patch ===
+From 2884248d07e4e2c922e137365253e2e521c425b0 Mon Sep 17 00:00:00 2001
+From: Martin Liska 
+Date: Mon, 21 Dec 2020 10:14:46 +0100
+Subject: [PATCH] Add horse.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+ChangeLog:
+
+   * koní�ek.txt: New file.
+---
+ "kon\303\255\304\215ek.txt" | 1 +
+ 1 file changed, 1 insertion(+)
+ create mode 100644 "kon\303\255\304\215ek.txt"
+
+diff --git "a/kon\303\255\304\215ek.txt" "b/kon\303\255\304\215ek.txt"
+new file mode 100644
+index 000..56c67f58752
+--- /dev/null
 "b/kon\303\255\304\215ek.txt"
+@@ -0,0 +1 @@
++I'm a horse.
+--
+2.29.2
+
 
--

2.29.2



[committed] fold-const: Fix up a buffer overflow in native_encode_initializer [PR98407]

2020-12-21 Thread Jakub Jelinek via Gcc-patches
Hi!

For flexible array members we need to incrementally clear just from
ptr + total_bytes up to new ptr + total_bytes, but memset has been called
with the length from ptr, so was missing - total_bytes.  Additionally,
in this code off is guaranteed to be -1 and thus o 0, so don't bother pretending
we could handle anything else, it would be more complicated than that.

Sorry for this brown paper bug, tested on x86_64-linux, committed to trunk
as obvious.

2020-12-21  Jakub Jelinek  

PR tree-optimization/98407
* fold-const.c (native_encode_initializer): When handling flexible
array members, fix up computation of length for memset.  Also remove
" - o" as o is always guaranteed to be 0 in this code path.

* gcc.c-torture/compile/pr98407.c: New test.

--- gcc/fold-const.c.jj 2020-12-19 22:24:03.945714395 +0100
+++ gcc/fold-const.c2020-12-21 09:59:59.715313469 +0100
@@ -8280,9 +8280,9 @@ native_encode_initializer (tree init, un
return 0;
  if (pos + fieldsize > total_bytes)
{
- if (ptr != NULL && total_bytes - o < len)
-   memset (ptr + (total_bytes - o),
-   '\0', MIN (pos + fieldsize - o, len));
+ if (ptr != NULL && total_bytes < len)
+   memset (ptr + total_bytes, '\0',
+   MIN (pos + fieldsize, len) - total_bytes);
  total_bytes = pos + fieldsize;
}
}
--- gcc/testsuite/gcc.c-torture/compile/pr98407.c.jj2020-12-21 
10:05:11.824717082 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr98407.c   2020-12-21 
10:04:54.267919387 +0100
@@ -0,0 +1,10 @@
+/* PR tree-optimization/98407 */
+
+struct S { int a; int b[]; };
+const struct S c = { 0, { 0 } }, d = { 0, { 0 } };
+
+int
+foo (void)
+{
+  return __builtin_memcmp (, , sizeof d);
+}

Jakub



[RFC] Run pass_sink_code once more after ivopts/fre

2020-12-21 Thread Xiong Hu Luo via Gcc-patches
Here comes another case that requires run a pass once more, as this is
not the common suggested direction to solve problems, not quite sure
whether it is still a reasonble fix here.  Source code is something like:

ref = ip + *hslot;
while (ip < in_end - 2) {
  unsigned int len = 2;
  len++;
for ()   {
  do len++;
  while (len < maxlen && ref[len] == ip[len]); //sink code here.
  break;
}
  len -= 2;
  ip++;
  ip += len + 1;
  if (ip >= in_end - 2)
break;
}

Before ivopts, the gimple for inner while loop is xxx.c.172t.slp1:

   [local count: 75120046]:
  # len_160 = PHI 
  len_189 = len_160 + 1;
  _423 = (sizetype) len_189;
  _424 = ip_229 + _423;
  if (maxlen_186 > len_189)
goto ; [94.50%]
  else
goto ; [5.50%]

   [local count: 70988443]:
  _84 = *_424;
  _86 = ref_182 + _423;
  _87 = *_86;
  if (_84 == _87)
goto ; [94.50%]
  else
goto ; [5.50%]

   [local count: 67084079]:
  goto ; [100.00%]

   [local count: 14847855]:
  # len_263 = PHI 
  # _262 = PHI <_423(32), _423(31)>
  # _264 = PHI <_424(32), _424(31)>
  len_190 = len_263 + 4294967295;
  if (len_190 <= 6)
goto ; [0.00%]
  else
goto ; [100.00%]

Then in ivopts, instructions are updated to xxx.c.174t.ivopts:

   [local count: 75120046]:
  # ivtmp.30_29 = PHI 
  _34 = (unsigned int) ivtmp.30_29;
  len_160 = _34 + 4294967295;
  _423 = ivtmp.30_29;
  _35 = (unsigned long) ip_229;
  _420 = ivtmp.30_29 + _35;
  _419 = (uint8_t *) _420;
  _424 = _419;
  len_418 = (unsigned int) ivtmp.30_29;
  if (maxlen_186 > len_418)
goto ; [94.50%]
  else
goto ; [5.50%]

   [local count: 70988443]:
  _84 = MEM[(uint8_t *)ip_229 + ivtmp.30_29 * 1];
  ivtmp.30_31 = ivtmp.30_29 + 1;
  _417 = ref_182 + 18446744073709551615;
  _87 = MEM[(uint8_t *)_417 + ivtmp.30_31 * 1];
  if (_84 == _87)
goto ; [94.50%]
  else
goto ; [5.50%]

   [local count: 67084079]:
  goto ; [100.00%]

   [local count: 14847855]:
  # len_263 = PHI 
  # _262 = PHI <_423(32), _423(31)>
  # _264 = PHI <_424(32), _424(31)>
  len_190 = len_263 + 4294967295;
  if (len_190 <= 6)
goto ; [0.00%]
  else
goto ; [100.00%]

Some instructions in BB 31 are not used in the loop and could be sinked
out of loop to reduce the computation, but they are not sinked
throughout all passes later.  Run the sink_code pass once more at least
after fre5 could improve this typical case performance 23% due to few
instructions exausted in loop.
xxx.c.209t.sink2:

Sinking _419 = (uint8_t *) _420;
 from bb 31 to bb 89
Sinking _420 = ivtmp.30_29 + _35;
 from bb 31 to bb 89
Sinking _35 = (unsigned long) ip_229;
 from bb 31 to bb 89
Sinking len_160 = _34 + 4294967295;
 from bb 31 to bb 33

I also tested the SPEC2017 performance on P8LE, 544.nab_r is improved
by 2.43%, but no big changes to other cases, GEOMEAN is improved quite
small with 0.25%.

The reason why it should be run after fre5 is fre would do some phi
optimization to expose the optimization.  The patch put it after
pass_modref is due to my guess that some gimple optimizations like
thread_jumps, dse, dce etc. could provide more opportunities for
sinking code.  Not sure it is the correct place to put.  I also
verified this issue exists in both X86 and ARM64.
Any comments?  Thanks.
---
 gcc/passes.def  | 1 +
 gcc/tree-ssa-sink.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/passes.def b/gcc/passes.def
index 21b2e2af0f7..69106615729 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -355,6 +355,7 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_uncprop);
   NEXT_PASS (pass_local_pure_const);
   NEXT_PASS (pass_modref);
+  NEXT_PASS (pass_sink_code);
   POP_INSERT_PASSES ()
   NEXT_PASS (pass_all_optimizations_g);
   PUSH_INSERT_PASSES_WITHIN (pass_all_optimizations_g)
diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c
index b0abf4147d6..824659f3919 100644
--- a/gcc/tree-ssa-sink.c
+++ b/gcc/tree-ssa-sink.c
@@ -819,6 +819,7 @@ public:
   /* opt_pass methods: */
   virtual bool gate (function *) { return flag_tree_sink != 0; }
   virtual unsigned int execute (function *);
+  opt_pass *clone (void) { return new pass_sink_code (m_ctxt); }
 
 }; // class pass_sink_code
 
-- 
2.27.0.90.geebb51ba8c



RE: Add libcody

2020-12-21 Thread Hao Liu OS via Gcc-patches
Hi Nathan,

This patch causes a build failure on CentOS.

More information: https://gcc.gnu.org/bugzilla//show_bug.cgi?id=98318#c3 

Thanks,
-Hao

> -Original Message-
> From: Gcc-patches  On Behalf Of Nathan
> Sidwell
> Sent: Tuesday, December 15, 2020 11:46 PM
> To: GCC Patches 
> Subject: Add libcody
> 
> In order to separate compiler from build system, C++ Modules, as
> implemented in GCC introduces a communication channel between those
> two entities.  This is implemented by libcody.  It is anticipated that other
> implementations will also implement this protocol, or use libcody to provide
> it.
> 
>  * Makefile.def: Add libcody.
>  * Makefile.in: Regenerated.
>  * configure: Regenerated.
>  gcc/
>  * Makefile.in (CODYINC, CODYLIB, CODYLIB_H): New. Use them.
>  libcody/
>  * CMakeLists.txt: New.
>  * CMakeLists.txt: New.
>  * CODING.md: New.
>  * CONTRIB.md: New.
>  * LICENSE: New.
>  * LICENSE.gcc: New.
>  * Makefile.in: New.
>  * Makesub.in: New.
>  * README.md: New.
>  * buffer.cc: New.
>  * build-aux/config.guess: New.
>  * build-aux/config.sub: New.
>  * build-aux/install-sh: New.
>  * client.cc: New.
>  * cmake/libcody-config-ix.cmake: New.
>  * cody.hh: New.
>  * config.h.in: New.
>  * config.m4: New.
>  * configure: New.
>  * configure.ac: New.
>  * dox.cfg.in: New.
>  * fatal.cc: New.
>  * gdbinit.in: New.
>  * internal.hh: New.
>  * netclient.cc: New.
>  * netserver.cc: New.
>  * packet.cc: New.
>  * resolver.cc: New.
>  * server.cc: New.
>  * tests/01-serialize/connect.cc: New.
>  * tests/01-serialize/decoder.cc: New.
>  * tests/01-serialize/encoder.cc: New.
>  * tests/02-comms/client-1.cc: New.
>  * tests/02-comms/pivot-1.cc: New.
>  * tests/02-comms/server-1.cc: New.
>  * tests/Makesub.in: New.
>  * tests/jouster: New.
> 
> pushing to trunk
> --
> Nathan Sidwell


[PATCH] c++: Handle array members in build_comparison_op [PR93480]

2020-12-21 Thread Jakub Jelinek via Gcc-patches
Hi!

http://eel.is/c++draft/class.compare.default#6 says for the
expanded list of subobjects:
"In that list, any subobject of array type is recursively expanded
to the sequence of its elements, in the order of increasing subscript."
but build_comparison_op just tried to compare the whole arrays, which
failed and therefore the defaulted comparison was deleted.

The following patch instead compares the array elements, and
if info.defining, adds runtime loops around it so that it iterates
over increasing subscripts.

For flexible array members it punts, we don't know how large those will be,
for zero sized arrays it doesn't even try to compare the elements,
because if there are no elements, there is nothing to compare, and
for [1] arrays it will not emit a loop because it is enough to use
[0] array ref to cover everything.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-12-21  Jakub Jelinek  

PR c++/93480
* method.c (common_comparison_type): If comps[i] is a TREE_LIST,
use its TREE_VALUE instead.
(build_comparison_op): Handle array members.

* g++.dg/cpp2a/spaceship-synth10.C: New test.
* g++.dg/cpp2a/spaceship-synth-neg5.C: New test.

--- gcc/cp/method.c.jj  2020-12-09 00:00:27.047344706 +0100
+++ gcc/cp/method.c 2020-12-20 15:14:03.048393226 +0100
@@ -1230,6 +1230,8 @@ common_comparison_type (vec 
   for (unsigned i = 0; i < comps.length(); ++i)
 {
   tree comp = comps[i];
+  if (TREE_CODE (comp) == TREE_LIST)
+   comp = TREE_VALUE (comp);
   tree ctype = TREE_TYPE (comp);
   comp_cat_tag tag = cat_tag_for (ctype);
   /* build_comparison_op already checked this.  */
@@ -1419,10 +1421,47 @@ build_comparison_op (tree fndecl, tsubst
  continue;
}
 
- tree lhs_mem = build3 (COMPONENT_REF, expr_type, lhs, field,
-NULL_TREE);
- tree rhs_mem = build3 (COMPONENT_REF, expr_type, rhs, field,
-NULL_TREE);
+ tree lhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, lhs,
+field, NULL_TREE);
+ tree rhs_mem = build3_loc (field_loc, COMPONENT_REF, expr_type, rhs,
+field, NULL_TREE);
+ tree loop_indexes = NULL_TREE;
+ while (TREE_CODE (expr_type) == ARRAY_TYPE)
+   {
+ /* Flexible array member.  */
+ if (TYPE_DOMAIN (expr_type) == NULL_TREE
+ || TYPE_MAX_VALUE (TYPE_DOMAIN (expr_type)) == NULL_TREE)
+   {
+ if (complain & tf_error)
+   inform (field_loc, "cannot default compare "
+  "flexible array member");
+ bad = true;
+ break;
+   }
+ tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (expr_type));
+ /* [0] array.  No subobjects to compare, just skip it.  */
+ if (integer_all_onesp (maxval))
+   break;
+ tree idx;
+ /* [1] array, no loop needed, just add [0] ARRAY_REF.
+Similarly if !info.defining.  */
+ if (integer_zerop (maxval) || !info.defining)
+   idx = size_zero_node;
+ /* Some other array, will need runtime loop.  */
+ else
+   {
+ idx = force_target_expr (sizetype, maxval, complain);
+ loop_indexes = tree_cons (idx, NULL_TREE, loop_indexes);
+   }
+ expr_type = TREE_TYPE (expr_type);
+ lhs_mem = build4_loc (field_loc, ARRAY_REF, expr_type, lhs_mem,
+   idx, NULL_TREE, NULL_TREE);
+ rhs_mem = build4_loc (field_loc, ARRAY_REF, expr_type, rhs_mem,
+   idx, NULL_TREE, NULL_TREE);
+   }
+ if (TREE_CODE (expr_type) == ARRAY_TYPE)
+   continue;
+
  tree overload = NULL_TREE;
  tree comp = build_new_op (field_loc, code, flags, lhs_mem, rhs_mem,
NULL_TREE, ,
@@ -1486,6 +1525,11 @@ build_comparison_op (tree fndecl, tsubst
  bad = true;
  continue;
}
+ if (loop_indexes)
+   {
+ TREE_VALUE (loop_indexes) = comp;
+ comp = loop_indexes;
+   }
  comps.safe_push (comp);
}
   if (code == SPACESHIP_EXPR && is_auto (rettype))
@@ -1502,8 +1546,35 @@ build_comparison_op (tree fndecl, tsubst
{
  tree comp = comps[i];
  tree eq, retval = NULL_TREE, if_ = NULL_TREE;
+ tree loop_indexes = NULL_TREE;
  if (info.defining)
-   if_ = begin_if_stmt ();
+   {
+ if (TREE_CODE (comp) == TREE_LIST)
+   {
+ loop_indexes = comp;
+ comp = TREE_VALUE (comp);
+ loop_indexes = 

[committed] openmp: Fix up handling of addressable temporaries in simd lb, b and incr expressions [PR98383]

2020-12-21 Thread Jakub Jelinek via Gcc-patches
Hi!

For simd, we have code to artificially add locally defined variables into
private clauses if they are addressable, so that omplower turns them into
"omp simd array" variables.  As the testcase shows, this is undesirable if
those temporaries only show in the lb, b or incr expressions and nowhere else,
if it is just used there, we really want normal scalar temporaries.

This patch implements that by making sure we don't set for those GOVD_LOCAL-ish
temporaries turned into GOVD_PRIVATE the GOVD_SEEN flag during gimplification
of the lb, b and incr expressions, which means that the private clause isn't
added for those.

Bootstrapped/regtested on x86_64-linux and i686-linux so far.

2020-12-21  Jakub Jelinek  

PR c++/98383
* gimplify.c (struct gimplify_omp_ctx): Add in_for_exprs flag.
(gimple_add_tmp_var): For addressable temporaries appearing in
simd lb, b or incr expressions, don't add a private clause unless
it is seen also outside of those expressions in the simd body.
(omp_notice_variable): Likewise.
(gimplify_omp_for): Set and reset in_for_exprs around gimplification
of lb, b or incr expressions.

* g++.dg/gomp/pr98383.C: New test.

--- gcc/gimplify.c.jj   2020-12-18 21:43:02.308626945 +0100
+++ gcc/gimplify.c  2020-12-20 19:26:11.620475648 +0100
@@ -232,6 +232,7 @@ struct gimplify_omp_ctx
   bool add_safelen1;
   bool order_concurrent;
   bool has_depend;
+  bool in_for_exprs;
   int defaultmap[4];
 };
 
@@ -781,7 +782,7 @@ gimple_add_tmp_var (tree tmp)
   if (gimplify_omp_ctxp)
{
  struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
- int flag = GOVD_LOCAL;
+ int flag = GOVD_LOCAL | GOVD_SEEN;
  while (ctx
 && (ctx->region_type == ORT_WORKSHARE
 || ctx->region_type == ORT_TASKGROUP
@@ -794,14 +795,16 @@ gimple_add_tmp_var (tree tmp)
{
  if (TREE_CODE (DECL_SIZE_UNIT (tmp)) != INTEGER_CST)
ctx->add_safelen1 = true;
- else
+ else if (ctx->in_for_exprs)
flag = GOVD_PRIVATE;
+ else
+   flag = GOVD_PRIVATE | GOVD_SEEN;
  break;
}
  ctx = ctx->outer_context;
}
  if (ctx)
-   omp_add_variable (ctx, tmp, flag | GOVD_SEEN);
+   omp_add_variable (ctx, tmp, flag);
}
 }
   else if (cfun)
@@ -7617,6 +7620,14 @@ omp_notice_variable (struct gimplify_omp
   goto do_outer;
 }
 
+  /* Don't mark as GOVD_SEEN addressable temporaries seen only in simd
+ lb, b or incr expressions, those shouldn't be turned into simd arrays.  */
+  if (ctx->region_type == ORT_SIMD
+  && ctx->in_for_exprs
+  && ((n->value & (GOVD_PRIVATE | GOVD_SEEN | GOVD_EXPLICIT))
+ == GOVD_PRIVATE))
+flags &= ~GOVD_SEEN;
+
   if ((n->value & (GOVD_SEEN | GOVD_LOCAL)) == 0
   && (flags & (GOVD_SEEN | GOVD_LOCAL)) == GOVD_SEEN
   && DECL_SIZE (decl))
@@ -12080,6 +12091,7 @@ gimplify_omp_for (tree *expr_p, gimple_s
   else
var = decl;
 
+  gimplify_omp_ctxp->in_for_exprs = true;
   if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
{
  tree lb = TREE_OPERAND (t, 1);
@@ -12092,6 +12104,7 @@ gimplify_omp_for (tree *expr_p, gimple_s
   else
tret = gimplify_expr (_OPERAND (t, 1), _pre_body, NULL,
  is_gimple_val, fb_rvalue, false);
+  gimplify_omp_ctxp->in_for_exprs = false;
   ret = MIN (ret, tret);
   if (ret == GS_ERROR)
return ret;
@@ -12101,6 +12114,7 @@ gimplify_omp_for (tree *expr_p, gimple_s
   gcc_assert (COMPARISON_CLASS_P (t));
   gcc_assert (TREE_OPERAND (t, 0) == decl);
 
+  gimplify_omp_ctxp->in_for_exprs = true;
   if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
{
  tree ub = TREE_OPERAND (t, 1);
@@ -12113,6 +12127,7 @@ gimplify_omp_for (tree *expr_p, gimple_s
   else
tret = gimplify_expr (_OPERAND (t, 1), _pre_body, NULL,
  is_gimple_val, fb_rvalue, false);
+  gimplify_omp_ctxp->in_for_exprs = false;
   ret = MIN (ret, tret);
 
   /* Handle OMP_FOR_INCR.  */
@@ -12178,6 +12193,7 @@ gimplify_omp_for (tree *expr_p, gimple_s
  gcc_unreachable ();
}
 
+ gimplify_omp_ctxp->in_for_exprs = true;
  tret = gimplify_expr (_OPERAND (t, 1), _pre_body, NULL,
is_gimple_val, fb_rvalue, false);
  ret = MIN (ret, tret);
@@ -12199,6 +12215,7 @@ gimplify_omp_for (tree *expr_p, gimple_s
  ret = MIN (ret, tret);
}
}
+ gimplify_omp_ctxp->in_for_exprs = false;
  break;
 
default:
--- gcc/testsuite/g++.dg/gomp/pr98383.C.jj  2020-12-20 19:27:57.540277373 
+0100
+++ gcc/testsuite/g++.dg/gomp/pr98383.C 2020-12-20