[Patch] Fortran: Async I/O - avoid unlocked unlocking [PR100352]

2021-05-01 Thread Tobias Burnus

As this patch is rather obvious, I intent to commit it tomorrow
as obvious, unless there is an OK earlier or other comments :-)
(And backport to GCC 11 in a couple of days.)

Before PR100352 (r11-7647),
st_write_done did:
  st_write_done_worker (dtd)
  unlock_unit (dtp->u.p.current_unit);

but st_write_done_worker did:
   LOCK (&unit_lock);
   newunit_free (dtp->common.unit);
   UNLOCK (&unit_lock);

And this locking could lead to a deadlock.

Hence, 'unlock_unit' has been moved to st_write_done_worker
before the LOCK (&unit_lock).

That solved the issue, but async I/O does not use this lock
but, in async.c's  async_io():
  LOCK (&au->lock);
  st_write_done_worker (au->pdt);
  UNLOCK (&au->io_lock);

Which worked before the previous patch fine, but now
there is a bogus  unlock_unit() alias UNLOCK (&u->lock);
although the unit is not locked.

Solution: Guard the unlock_unit.

Tobias

PS: The thread sanitizer still complains about a potential
cross-thread deadlock, see new PR100371.

-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
Fortran: Async I/O - avoid unlocked unlocking [PR100352]

Follow up to PR100352, which moved unit unlocking to st_*_done_worker to
avoid lock order reversal; however, as async_io uses a different lock,
the (unlocked locked) unit lock shall not be unlocked there.

libgfortran/ChangeLog:

	PR libgomp/100352
	* io/transfer.c (st_read_done_worker, st_write_done_worker): Add new
	arg whether to unlock unit.
	(st_read_done, st_write_done): Call it with true.
	* io/async.c (async_io): Call it with false.
	* io/io.h (st_write_done_worker, st_read_done_worker): Update prototype.

 libgfortran/io/async.c|  4 ++--
 libgfortran/io/io.h   |  4 ++--
 libgfortran/io/transfer.c | 14 --
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libgfortran/io/async.c b/libgfortran/io/async.c
index d216ace1947..247008ca801 100644
--- a/libgfortran/io/async.c
+++ b/libgfortran/io/async.c
@@ -117,13 +117,13 @@ async_io (void *arg)
 		{
 		case AIO_WRITE_DONE:
 		  NOTE ("Finalizing write");
-		  st_write_done_worker (au->pdt);
+		  st_write_done_worker (au->pdt, false);
 		  UNLOCK (&au->io_lock);
 		  break;
 
 		case AIO_READ_DONE:
 		  NOTE ("Finalizing read");
-		  st_read_done_worker (au->pdt);
+		  st_read_done_worker (au->pdt, false);
 		  UNLOCK (&au->io_lock);
 		  break;
 
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index e0007c6bfe5..3355bc2fd8d 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -1083,11 +1083,11 @@ default_precision_for_float (int kind)
 #endif
 
 extern void
-st_write_done_worker (st_parameter_dt *);
+st_write_done_worker (st_parameter_dt *, bool);
 internal_proto (st_write_done_worker);
 
 extern void
-st_read_done_worker (st_parameter_dt *);
+st_read_done_worker (st_parameter_dt *, bool);
 internal_proto (st_read_done_worker);
 
 extern void
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 71a935652e3..36e35b48cd3 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -4337,7 +4337,7 @@ extern void st_read_done (st_parameter_dt *);
 export_proto(st_read_done);
 
 void
-st_read_done_worker (st_parameter_dt *dtp)
+st_read_done_worker (st_parameter_dt *dtp, bool unlock)
 {
   bool free_newunit = false;
   finalize_transfer (dtp);
@@ -4367,7 +4367,8 @@ st_read_done_worker (st_parameter_dt *dtp)
 	  free_format (dtp);
 	}
 }
-   unlock_unit (dtp->u.p.current_unit);
+   if (unlock)
+ unlock_unit (dtp->u.p.current_unit);
if (free_newunit)
  {
/* Avoid inverse lock issues by placing after unlock_unit.  */
@@ -4394,7 +4395,7 @@ st_read_done (st_parameter_dt *dtp)
 	  unlock_unit (dtp->u.p.current_unit);
 	}
   else
-	st_read_done_worker (dtp);  /* Calls unlock_unit.  */
+	st_read_done_worker (dtp, true);  /* Calls unlock_unit.  */
 }
 
   library_end ();
@@ -4412,7 +4413,7 @@ st_write (st_parameter_dt *dtp)
 
 
 void
-st_write_done_worker (st_parameter_dt *dtp)
+st_write_done_worker (st_parameter_dt *dtp, bool unlock)
 {
   bool free_newunit = false;
   finalize_transfer (dtp);
@@ -4463,7 +4464,8 @@ st_write_done_worker (st_parameter_dt *dtp)
 	  free_format (dtp);
 	}
 }
-   unlock_unit (dtp->u.p.current_unit);
+   if (unlock)
+ unlock_unit (dtp->u.p.current_unit);
if (free_newunit)
  {
/* Avoid inverse lock issues by placing after unlock_unit.  */
@@ -4496,7 +4498,7 @@ st_write_done (st_parameter_dt *dtp)
 	  unlock_unit (dtp->u.p.current_unit);
 	}
   else
-	st_write_done_worker (dtp);  /* Calls unlock_unit.  */
+	st_write_done_worker (dtp, true);  /* Calls unlock_unit.  */
 }
 
   library_end ();


Re: [Patch] Fortran: Async I/O - avoid unlocked unlocking [PR100352]

2021-05-01 Thread Bernhard Reutner-Fischer via Gcc-patches
On Sat, 1 May 2021 14:59:01 +0200
Tobias Burnus  wrote:

> As this patch is rather obvious, I intent to commit it tomorrow
> as obvious, unless there is an OK earlier or other comments :-)
> (And backport to GCC 11 in a couple of days.)
> 
> Before PR100352 (r11-7647),
> st_write_done did:
>st_write_done_worker (dtd)
>unlock_unit (dtp->u.p.current_unit);
> 
> but st_write_done_worker did:
> LOCK (&unit_lock);
> newunit_free (dtp->common.unit);
> UNLOCK (&unit_lock);
> 
> And this locking could lead to a deadlock.
> 
> Hence, 'unlock_unit' has been moved to st_write_done_worker
> before the LOCK (&unit_lock).
> 
> That solved the issue, but async I/O does not use this lock
> but, in async.c's  async_io():
>LOCK (&au->lock);
>st_write_done_worker (au->pdt);
>UNLOCK (&au->io_lock);
> 
> Which worked before the previous patch fine, but now
> there is a bogus  unlock_unit() alias UNLOCK (&u->lock);
> although the unit is not locked.
> 
> Solution: Guard the unlock_unit.

Doesn't look all that pretty TBH.
Doesn't it suggest that the worker's callers should eventually take
care of the locking (and newunit_free()ing) ?
I.e. have the workers return a bool whether to free the newunit or not.

But then, neither did i look closely nor do i volunteer to provide a
fix..
HTH,


[pushed] c++: C++11 range-for and ovl/lkp_iterator

2021-05-01 Thread Jason Merrill via Gcc-patches
We can't use C++11 range-based 'for' over a tree directly, because we don't
know what kind of range we want to use it as.  I suppose in some cases we
could guess, but it seems better to tersely make it explicit.  This patch
adds range adaptors ovl_range and lkp_range for use as the range of a
range-for, e.g.

  for (tree fn : lkp_range (fns)) { ... }

This patch also removes the private copy ops from ovl_iterator; it's
necessary for range-for, and these are effectively C++ forward_iterators,
which allow copying, so I don't see a reason to prevent it.  A bit more
would need to be done to make them actually conform as C++11 forward
iterators, but I don't think we particularly want to #include 
yet.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

* cp-tree.h (class ovl_iterator): Allow copying.  Add op==.
(class ovl_range, class lkp_range): New.
* call.c (build_op_call_1, add_candidates): Use them.
(build_op_delete_call, has_trivial_copy_assign_p): Likewise.
(has_trivial_copy_p): Likewise.
* class.c (handle_using_decl, get_basefndecls): Likewise.
(maybe_warn_about_overly_private_class): Likewise.
(warn_hidden, add_implicitly_declared_members): Likewise.
(check_methods, clone_constructors_and_destructors): Likewise.
(type_has_user_nondefault_constructor): Likewise.
---
 gcc/cp/cp-tree.h | 34 +-
 gcc/cp/call.c| 23 ++-
 gcc/cp/class.c   | 45 -
 3 files changed, 55 insertions(+), 47 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 368d9f5adf7..a08867aea62 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -817,11 +817,6 @@ class ovl_iterator {
   {
   }
 
- private:
-  /* Do not duplicate.  */
-  ovl_iterator &operator= (const ovl_iterator &);
-  ovl_iterator (const ovl_iterator &);
-
  public:
   operator bool () const
   {
@@ -841,6 +836,10 @@ class ovl_iterator {
 
 return fn;
   }
+  bool operator== (const ovl_iterator &o) const
+  {
+return ovl == o.ovl;
+  }
   tree get_using () const
   {
 gcc_checking_assert (using_p ());
@@ -903,6 +902,19 @@ class ovl_iterator {
   static tree reveal_node (tree ovl, tree node);
 };
 
+/* Treat a tree as a range of ovl_iterator, e.g.
+   for (tree f : ovl_range (fns)) { ... }  */
+
+class ovl_range
+{
+  tree t;
+  bool allow;
+public:
+  explicit ovl_range (tree t, bool allow = false): t(t), allow(allow) { }
+  ovl_iterator begin() { return ovl_iterator (t, allow); }
+  ovl_iterator end() { return ovl_iterator (NULL_TREE, allow); }
+};
+
 /* Iterator over a (potentially) 2 dimensional overload, which is
produced by name lookup.  */
 
@@ -935,6 +947,18 @@ class lkp_iterator : public ovl_iterator {
   }
 };
 
+/* Treat a tree as a range of lkp_iterator, e.g.
+   for (tree f : lkp_range (fns)) { ... }  */
+
+class lkp_range
+{
+  tree t;
+public:
+  lkp_range (tree t): t(t) { }
+  lkp_iterator begin() { return lkp_iterator (t); }
+  lkp_iterator end() { return lkp_iterator (NULL_TREE); }
+};
+
 /* hash traits for declarations.  Hashes potential overload sets via
DECL_NAME.  */
 
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 678e120a165..57bac05fe70 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4914,10 +4914,8 @@ build_op_call_1 (tree obj, vec **args, 
tsubst_flags_t complain)
  || TYPE_REFFN_P (totype)
  || (TYPE_REF_P (totype)
  && TYPE_PTRFN_P (TREE_TYPE (totype
-   for (ovl_iterator iter (TREE_VALUE (convs)); iter; ++iter)
+   for (tree fn : ovl_range (TREE_VALUE (convs)))
  {
-   tree fn = *iter;
-
if (DECL_NONCONVERTING_P (fn))
  continue;
 
@@ -5981,10 +5979,8 @@ add_candidates (tree fns, tree first_arg, const 
vec *args,
 which = non_templates;
 
  again:
-  for (lkp_iterator iter (fns); iter; ++iter)
+  for (tree fn : lkp_range (fns))
 {
-  fn = *iter;
-
   if (check_converting && DECL_NONCONVERTING_P (fn))
continue;
   if (check_list_ctor && !is_list_ctor (fn))
@@ -7016,10 +7012,8 @@ build_op_delete_call (enum tree_code code, tree addr, 
tree size,
 the usual deallocation function, so we shouldn't complain
 about using the operator delete (void *, size_t).  */
  if (DECL_CLASS_SCOPE_P (fn))
-   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns));
-iter; ++iter)
+   for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
  {
-   tree elt = *iter;
if (usual_deallocation_fn_p (elt)
&& FUNCTION_ARG_CHAIN (elt) == void_list_node)
  goto ok;
@@ -7062,9 +7056,8 @@ build_op_delete_call (enum tree_code code, tree addr, 
tree size,
allocation function. If the lookup finds a single matching
deallocation function, that function will be called; otherwise, no

[PATCH RFA] tree-iterator: C++11 range-for and tree_stmt_iterator

2021-05-01 Thread Jason Merrill via Gcc-patches
Like my recent patch to add ovl_range and lkp_range in the C++ front end,
this patch adds the tsi_range adaptor for using C++11 range-based 'for' with
a STATEMENT_LIST, e.g.

  for (tree stmt : tsi_range (stmt_list)) { ... }

This also involves adding some operators to tree_stmt_iterator that are
needed for range-for iterators, and should also be useful in code that uses
the iterators directly.

The patch updates the suitable loops in the C++ front end, but does not
touch any loops elsewhere in the compiler.

gcc/ChangeLog:

* tree-iterator.h (struct tree_stmt_iterator): Add operator++,
operator--, operator*, operator==, and operator!=.
(class tsi_range): New.

gcc/cp/ChangeLog:

* constexpr.c (build_data_member_initialization): Use tsi_range.
(build_constexpr_constructor_member_initializers): Likewise.
(constexpr_fn_retval, cxx_eval_statement_list): Likewise.
(potential_constant_expression_1): Likewise.
* coroutines.cc (await_statement_expander): Likewise.
(await_statement_walker): Likewise.
* module.cc (trees_out::core_vals): Likewise.
* pt.c (tsubst_expr): Likewise.
* semantics.c (set_cleanup_locs): Likewise.
---
 gcc/tree-iterator.h  | 28 +++-
 gcc/cp/constexpr.c   | 42 ++
 gcc/cp/coroutines.cc | 10 --
 gcc/cp/module.cc |  5 ++---
 gcc/cp/pt.c  |  5 ++---
 gcc/cp/semantics.c   |  5 ++---
 6 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/gcc/tree-iterator.h b/gcc/tree-iterator.h
index 076fff8644c..f57456bb473 100644
--- a/gcc/tree-iterator.h
+++ b/gcc/tree-iterator.h
@@ -1,4 +1,4 @@
-/* Iterator routines for manipulating GENERIC tree statement list.
+/* Iterator routines for manipulating GENERIC tree statement list. -*- C++ -*-
Copyright (C) 2003-2021 Free Software Foundation, Inc.
Contributed by Andrew MacLeod  
 
@@ -32,6 +32,13 @@ along with GCC; see the file COPYING3.  If not see
 struct tree_stmt_iterator {
   struct tree_statement_list_node *ptr;
   tree container;
+
+  bool operator== (tree_stmt_iterator b) const
+{ return b.ptr == ptr && b.container == container; }
+  bool operator!= (tree_stmt_iterator b) const { return !(*this == b); }
+  tree_stmt_iterator &operator++ () { ptr = ptr->next; return *this; }
+  tree_stmt_iterator &operator-- () { ptr = ptr->prev; return *this; }
+  tree &operator* () { return ptr->stmt; }
 };
 
 static inline tree_stmt_iterator
@@ -71,27 +78,38 @@ tsi_one_before_end_p (tree_stmt_iterator i)
 static inline void
 tsi_next (tree_stmt_iterator *i)
 {
-  i->ptr = i->ptr->next;
+  ++(*i);
 }
 
 static inline void
 tsi_prev (tree_stmt_iterator *i)
 {
-  i->ptr = i->ptr->prev;
+  --(*i);
 }
 
 static inline tree *
 tsi_stmt_ptr (tree_stmt_iterator i)
 {
-  return &i.ptr->stmt;
+  return &(*i);
 }
 
 static inline tree
 tsi_stmt (tree_stmt_iterator i)
 {
-  return i.ptr->stmt;
+  return *i;
 }
 
+/* Make tree_stmt_iterator work as a C++ range, e.g.
+   for (tree stmt : tsi_range (stmt_list)) { ... }  */
+class tsi_range
+{
+  tree t;
+ public:
+  tsi_range (tree t): t(t) { }
+  tree_stmt_iterator begin() { return tsi_start (t); }
+  tree_stmt_iterator end() { return { nullptr, t }; }
+};
+
 enum tsi_iterator_update
 {
   TSI_NEW_STMT,/* Only valid when single statement is added, 
move
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 9481a5bfd3c..260b0122f59 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -330,12 +330,9 @@ build_data_member_initialization (tree t, 
vec **vec)
 return false;
   if (TREE_CODE (t) == STATEMENT_LIST)
 {
-  tree_stmt_iterator i;
-  for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
-   {
- if (! build_data_member_initialization (tsi_stmt (i), vec))
-   return false;
-   }
+  for (tree stmt : tsi_range (t))
+   if (! build_data_member_initialization (stmt, vec))
+ return false;
   return true;
 }
   if (TREE_CODE (t) == CLEANUP_STMT)
@@ -577,10 +574,9 @@ build_constexpr_constructor_member_initializers (tree 
type, tree body)
break;
 
   case STATEMENT_LIST:
-   for (tree_stmt_iterator i = tsi_start (body);
-!tsi_end_p (i); tsi_next (&i))
+   for (tree stmt : tsi_range (body))
  {
-   body = tsi_stmt (i);
+   body = stmt;
if (TREE_CODE (body) == BIND_EXPR)
  break;
  }
@@ -617,10 +613,9 @@ build_constexpr_constructor_member_initializers (tree 
type, tree body)
 }
   else if (TREE_CODE (body) == STATEMENT_LIST)
 {
-  tree_stmt_iterator i;
-  for (i = tsi_start (body); !tsi_end_p (i); tsi_next (&i))
+  for (tree stmt : tsi_range (body))
{
- ok = build_data_member_initialization (tsi_stmt (i), &vec);
+ ok = build_data_member_initialization (stmt, &vec);
  if (!ok)
break;
}
@@ -675,11

Re: [PATCH 0/3] VAX backend preparatory updates for switching to LRA

2021-05-01 Thread Maciej W. Rozycki
On Wed, 28 Apr 2021, Richard Biener wrote:

> >  FAOD, as noted above will it be OK if I backport 3/3 to GCC 11 now, for
> > inclusion with 11.2?
> >
> >  While not a regression fix the change is contained in the VAX backend,
> > not a mainstream one, and now it is possibly the final opportunity to have
> > old reload improved for the VAX target as it's quite likely we'll switch
> > to LRA and dump old reload with GCC 12, and we may not be able to get LRA
> > on a par with old reload for VAX for a while yet.  Conversely, with the
> > improvement in place downstream users (NetBSD) may be able to pick it
> > easily enough to make a good use of it now.
> >
> >  WDYT?
> 
> Works for me.

 Backport committed now then, thanks for your review.

  Maciej


[committed] wwwdocs: Update the ntua.gr mirror from FTP to https

2021-05-01 Thread Gerald Pfeifer
ftp...@ntua.gr, can you please advise whether there's a better way
to link to (or you prefer a different address of yours)?

For now I pushed this change live on gcc.gnu.org.

Gerald


On the way change the reference from ftp.ntua.gr to the more generic
ntua.gr.
---
 htdocs/mirrors.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/mirrors.html b/htdocs/mirrors.html
index 3ed8a9c7..3e121e87 100644
--- a/htdocs/mirrors.html
+++ b/htdocs/mirrors.html
@@ -24,7 +24,7 @@ mirrors.  The following sites mirror the gcc.gnu.org 
download site
 Germany: ftp://ftp.gwdg.de/pub/misc/gcc/";>ftp.gwdg.de, thanks 
to emoe...@gwdg.de
 Germany: https://ftp.mpi-inf.mpg.de/mirrors/gnu/mirror/gcc.gnu.org/pub/gcc/";>mpi-sb.mpg.de,
 thanks to ftpad...@mpi-sb.mpg.de
 Germany: http://gcc.cybermirror.org";>http://gcc.cybermirror.org, thanks to 
Sascha Schwarz (c...@cybermirror.org)
-Greece: ftp://ftp.ntua.gr/pub/gnu/gcc/";>ftp.ntua.gr, thanks 
to ftp...@ntua.gr
+Greece: http://ftp.ntua.gr/mirror/gnu/gcc/";>ntua.gr, thanks 
to ftp...@ntua.gr
 Hungary, Budapest: http://robotlab.itk.ppke.hu/gcc/";>robotlab.itk.ppke.hu, thanks to 
Adam Rak (neur...@gmail.com)
 Japan: http://ftp.tsukuba.wide.ad.jp/software/gcc/";>ftp.tsukuba.wide.ad.jp, 
thanks to Kohei Takahashi (tsukuba-ftp-serv...@tsukuba.wide.ad.jp)
 Morocco:
-- 
2.31.1


[committed] wwwdocs: Remove final references to www.cilkplus.org

2021-05-01 Thread Gerald Pfeifer
As I described in commit 7a3bc40387dde4fd827c8a6d233757f1f6137d59
on Wed Mar 31 19:01:29 2021 +0200:

cilkplus.org is gone

At first cilkplus.org was broken for weeks, it not months. Now it
redirects to a generic intel.com page. So remove it.

Pushed.
Gerald

---
 htdocs/gcc-5/changes.html | 2 +-
 htdocs/news.html  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/htdocs/gcc-5/changes.html b/htdocs/gcc-5/changes.html
index efa322b1..a346c7f6 100644
--- a/htdocs/gcc-5/changes.html
+++ b/htdocs/gcc-5/changes.html
@@ -248,7 +248,7 @@
for the C and C++ compilers, which warns about boolean expressions
compared with an integer value different from
true/false.
-Full support for https://www.cilkplus.org/";>Cilk Plus
+Full support for Cilk Plus
has been added to the GCC compiler. Cilk Plus is an extension to
the C and C++ languages to support data and task parallelism.
 A new attribute no_reorder prevents reordering of
diff --git a/htdocs/news.html b/htdocs/news.html
index 0dd6b265..a4acd823 100644
--- a/htdocs/news.html
+++ b/htdocs/news.html
@@ -194,7 +194,7 @@
 
 Cilk Plus support in GCC
 [2014-09-02] wwwdocs:
-Complete support for https://www.cilkplus.org";>Cilk Plus 
features was added to GCC.
+Complete support for Cilk Plus features was added to GCC.
 Contributed by Jakub Jelinek, Aldy Hernandez, Balaji V. Iyer and Igor 
Zamyatin.
 
 New GCC version numbering scheme announced
-- 
2.31.1


[patch] Generate debug info for local dynamic record types

2021-05-01 Thread Eric Botcazou
Hi,

in Ada you can embed VLAs in local record types and thus end up with dynamic
offsets in record types, which are currently not well described in DWARF
because 1) the temporaries generated for them by the gimplifier are naturally
DECL_IGNORED_P and 2) when the types are referenced in nested subprograms,
the DWARF back-end does not correctly handle the rewritten references.

The attached patch fixes 1) by reusing the trick already used for VLAs and
2) by deferring the resolution of these references to the late DWARF pass.

Tested on x86-64/Linux, both GCC and GDB, OK for the mainline?


2021-05-01  Eric Botcazou  

* dwarf2out.c (loc_list_from_tree_1) : During early DWARF, do not
expand the VALUE_EXPR of variables put in the non-local frame.
* gimplify.c (gimplify_type_sizes) : If the type is not to
be ignored for debug info, ensure its variable offsets are not either.

-- 
Eric Botcazoudiff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index c36fd5a7f6a..5b819ab1a92 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -18658,8 +18658,20 @@ loc_list_from_tree_1 (tree loc, int want_address,
 
 case RESULT_DECL:
   if (DECL_HAS_VALUE_EXPR_P (loc))
-	return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc),
- want_address, context);
+	{
+	  tree value_expr = DECL_VALUE_EXPR (loc);
+
+	  /* Non-local frame structures are DECL_IGNORED_P variables so we need
+	 to wait until they get an RTX in order to reference them.  */
+	  if (early_dwarf
+	  && TREE_CODE (value_expr) == COMPONENT_REF
+	  && VAR_P (TREE_OPERAND (value_expr, 0))
+	  && DECL_NONLOCAL_FRAME (TREE_OPERAND (value_expr, 0)))
+	;
+	  else
+	return loc_list_from_tree_1 (value_expr, want_address, context);
+	}
+
   /* FALLTHRU */
 
 case FUNCTION_DECL:
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index b65106b1459..e790f08b23f 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -15141,11 +15141,15 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 void
 gimplify_type_sizes (tree type, gimple_seq *list_p)
 {
-  tree field, t;
-
   if (type == NULL || type == error_mark_node)
 return;
 
+  const bool ignored_p
+= TYPE_NAME (type)
+  && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
+  && DECL_IGNORED_P (TYPE_NAME (type));
+  tree t;
+
   /* We first do the main variant, then copy into any other variants.  */
   type = TYPE_MAIN_VARIANT (type);
 
@@ -15179,9 +15183,7 @@ gimplify_type_sizes (tree type, gimple_seq *list_p)
   /* Ensure VLA bounds aren't removed, for -O0 they should be variables
 	 with assigned stack slots, for -O1+ -g they should be tracked
 	 by VTA.  */
-  if (!(TYPE_NAME (type)
-	&& TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
-	&& DECL_IGNORED_P (TYPE_NAME (type)))
+  if (!ignored_p
 	  && TYPE_DOMAIN (type)
 	  && INTEGRAL_TYPE_P (TYPE_DOMAIN (type)))
 	{
@@ -15197,10 +15199,16 @@ gimplify_type_sizes (tree type, gimple_seq *list_p)
 case RECORD_TYPE:
 case UNION_TYPE:
 case QUAL_UNION_TYPE:
-  for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
+  for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
 	if (TREE_CODE (field) == FIELD_DECL)
 	  {
 	gimplify_one_sizepos (&DECL_FIELD_OFFSET (field), list_p);
+	/* Likewise, ensure variable offsets aren't removed.  */
+	if (!ignored_p
+		&& (t = DECL_FIELD_OFFSET (field))
+		&& VAR_P (t)
+		&& DECL_ARTIFICIAL (t))
+	  DECL_IGNORED_P (t) = 0;
 	gimplify_one_sizepos (&DECL_SIZE (field), list_p);
 	gimplify_one_sizepos (&DECL_SIZE_UNIT (field), list_p);
 	gimplify_type_sizes (TREE_TYPE (field), list_p);


Re: [committed] wwwdocs: Remove final references to www.cilkplus.org

2021-05-01 Thread Jeff Law via Gcc-patches



On 5/1/2021 11:41 AM, Gerald Pfeifer wrote:

As I described in commit 7a3bc40387dde4fd827c8a6d233757f1f6137d59
on Wed Mar 31 19:01:29 2021 +0200:

 cilkplus.org is gone

 At first cilkplus.org was broken for weeks, it not months. Now it
 redirects to a generic intel.com page. So remove it.


Too bad as it had some useful concepts, but the continual turnover and 
eventual de-emphasizing at Intel killed it.    John Carr (yes, the one 
from the EGCS days) is over at MIT working on OpenCilk, but they're more 
aligned with LLVM these days.



Jeff



[PATCH] i386: Fix up plugin header install on x86 [PR100336]

2021-05-01 Thread Jakub Jelinek via Gcc-patches
Hi!

The recent addition of i386-isa.def which is included from i386.h results
in failures to build gcc plugins, the i386.h header is installed, but
i386-isa.def is not.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux and
tested with make install, ok for trunk?

2021-05-01  Jakub Jelinek  

PR target/100336
* config/i386/t-i386 (TM_H): Add $(srcdir)/config/i386/i386-isa.def.

--- gcc/config/i386/t-i386.jj   2021-01-04 10:25:45.428159147 +0100
+++ gcc/config/i386/t-i386  2021-04-30 11:06:30.176266111 +0200
@@ -18,7 +18,8 @@
 
 OPTIONS_H_EXTRA += $(srcdir)/config/i386/stringop.def
 TM_H += $(srcdir)/config/i386/x86-tune.def \
-   $(srcdir)/common/config/i386/i386-cpuinfo.h
+   $(srcdir)/common/config/i386/i386-cpuinfo.h \
+   $(srcdir)/config/i386/i386-isa.def
 PASSES_EXTRA += $(srcdir)/config/i386/i386-passes.def
 
 i386-c.o: $(srcdir)/config/i386/i386-c.c

Jakub



[PATCH v2 0/2] OpenRISC support for cmodel=large

2021-05-01 Thread Stafford Horne via Gcc-patches
Changes from v1:
 - Added patch to enabled cmodle=large on crtstuff

This series fixes some bugs found when linking large binaries, both in buildroot
and glibc testing.

Stafford Horne (2):
  or1k: Add mcmodel option to handle large GOTs
  or1k: Use cmodel=large when building crtstuff

 gcc/config/or1k/or1k-opts.h   | 30 ++
 gcc/config/or1k/or1k.c| 11 +--
 gcc/config/or1k/or1k.h|  7 +++
 gcc/config/or1k/or1k.opt  | 19 +++
 gcc/doc/invoke.texi   | 12 +++-
 libgcc/config.host|  4 ++--
 libgcc/config/or1k/t-crtstuff |  2 ++
 7 files changed, 80 insertions(+), 5 deletions(-)
 create mode 100644 gcc/config/or1k/or1k-opts.h
 create mode 100644 libgcc/config/or1k/t-crtstuff

-- 
2.26.2



[PATCH v2 1/2] or1k: Add mcmodel option to handle large GOTs

2021-05-01 Thread Stafford Horne via Gcc-patches
When building libgeos we get an error with:

linux-uclibc/9.3.0/crtbeginS.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x118): relocation truncated to fit: R_OR1K_GOT16 against 
symbol `__cxa_finalize' defined in .text section in

/home/shorne/work/openrisc/3eb9f9d0f6d8274b2d19753c006bd83f7d536e3c/output/host/or1k-buildroot-linux-uclibc/sysroot/lib/libc.so.

This is caused by GOT code having a limit of 64k.  In OpenRISC this
looks to be the only relocation code pattern to be limited to 64k.

This patch allows specifying a new option -mcmodel=large which can be
used to generate 2 more instructions to construct 32-bit addresses for
up to 4G GOTs.

gcc/ChangeLog:

PR 99783
* config/or1k/or1k-opts.h: New file.
* config/or1k/or1k.c (or1k_legitimize_address_1, print_reloc):
Support generating gotha relocations if -mcmodel=large is
specified.
* config/or1k/or1k.h (TARGET_CMODEL_SMALL, TARGET_CMODEL_LARGE):
New macros.
* config/or1k/or1k.opt (mcmodel=): New option.
* doc/invoke.text (OpenRISC Options): Document mcmodel.
---
 gcc/config/or1k/or1k-opts.h | 30 ++
 gcc/config/or1k/or1k.c  | 11 +--
 gcc/config/or1k/or1k.h  |  7 +++
 gcc/config/or1k/or1k.opt| 19 +++
 gcc/doc/invoke.texi | 12 +++-
 5 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 gcc/config/or1k/or1k-opts.h

diff --git a/gcc/config/or1k/or1k-opts.h b/gcc/config/or1k/or1k-opts.h
new file mode 100644
index 000..f791b894fdd
--- /dev/null
+++ b/gcc/config/or1k/or1k-opts.h
@@ -0,0 +1,30 @@
+/* Definitions for option handling for OpenRISC.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   Contributed by Stafford Horne.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   .  */
+
+#ifndef GCC_OR1K_OPTS_H
+#define GCC_OR1K_OPTS_H
+
+/* The OpenRISC code generation models available.  */
+enum or1k_cmodel_type {
+  CMODEL_SMALL,
+  CMODEL_LARGE
+};
+
+#endif /* GCC_OR1K_OPTS_H */
diff --git a/gcc/config/or1k/or1k.c b/gcc/config/or1k/or1k.c
index e772a7addea..27d3fa17995 100644
--- a/gcc/config/or1k/or1k.c
+++ b/gcc/config/or1k/or1k.c
@@ -750,7 +750,14 @@ or1k_legitimize_address_1 (rtx x, rtx scratch)
{
  base = gen_sym_unspec (base, UNSPEC_GOT);
  crtl->uses_pic_offset_table = 1;
- t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
+ if (TARGET_CMODEL_LARGE)
+   {
+ emit_insn (gen_rtx_SET (t1, gen_rtx_HIGH (Pmode, base)));
+ emit_insn (gen_add3_insn (t1, t1, pic_offset_table_rtx));
+ t2 = gen_rtx_LO_SUM (Pmode, t1, base);
+   }
+ else
+   t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
  t2 = gen_const_mem (Pmode, t2);
  emit_insn (gen_rtx_SET (t1, t2));
  base = t1;
@@ -1089,7 +1096,7 @@ print_reloc (FILE *stream, rtx x, HOST_WIDE_INT add, 
reloc_kind kind)
  no special markup.  */
   static const char * const relocs[RKIND_MAX][RTYPE_MAX] = {
 { "lo", "got", "gotofflo", "tpofflo", "gottpofflo", "tlsgdlo" },
-{ "ha", NULL,  "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
+{ "ha", "gotha", "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
   };
   reloc_type type = RTYPE_DIRECT;
 
diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index fe01ab81ead..669907e7e74 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -21,6 +21,8 @@
 #ifndef GCC_OR1K_H
 #define GCC_OR1K_H
 
+#include "config/or1k/or1k-opts.h"
+
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_CPU_CPP_BUILTINS()  \
   do   \
@@ -37,6 +39,11 @@
 }  \
   while (0)
 
+#define TARGET_CMODEL_SMALL \
+  (or1k_code_model == CMODEL_SMALL)
+#define TARGET_CMODEL_LARGE \
+  (or1k_code_model == CMODEL_LARGE)
+
 /* Storage layout.  */
 
 #define DEFAULT_SIGNED_CHAR 1
diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
index 6bd0f3eee6d..cc23e3b8856 100644
--- a/gcc/config/or1k/or1k.opt
+++ b/gcc/config/or1k/or1k.opt
@@ -21,6 +21,9 @@
 ; See the GCC internals manual (options.texi) for a description of
 ; thi

[PATCH v2 2/2] or1k: Use cmodel=large when building crtstuff

2021-05-01 Thread Stafford Horne via Gcc-patches
When linking gcc runtime objects into large binaries the link may fail
with the below errors.  This will happen even if we are building with
-mcmodel=large.


/home/shorne/work/openrisc/output/host/lib/gcc/or1k-buildroot-linux-uclibc/10.3.0/crtbeginS.o:
 in function `deregister_tm_clones':
crtstuff.c:(.text+0x3c): relocation truncated to fit: R_OR1K_GOT16 against 
undefined symbol `_ITM_deregisterTMCloneTable'

/home/shorne/work/openrisc/output/host/lib/gcc/or1k-buildroot-linux-uclibc/10.3.0/crtbeginS.o:
 in function `register_tm_clones':
crtstuff.c:(.text+0xc0): relocation truncated to fit: R_OR1K_GOT16 against 
undefined symbol `_ITM_registerTMCloneTable'

This patch builds the gcc crtstuff binaries always with the
-mcmodel=large option to ensure they can be linked into large binaries.

libgcc/ChangeLog:

PR 99783
* config.host (or1k-*, tmake_file): Add or1k/t-crtstuff.
* config/or1k/t-crtstuff: New file.
---
 libgcc/config.host| 4 ++--
 libgcc/config/or1k/t-crtstuff | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
 create mode 100644 libgcc/config/or1k/t-crtstuff

diff --git a/libgcc/config.host b/libgcc/config.host
index f808b61be70..9e40d4560a3 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1119,12 +1119,12 @@ nios2-*-*)
extra_parts="$extra_parts crti.o crtn.o"
;;
 or1k-*-linux*)
-   tmake_file="$tmake_file or1k/t-or1k"
+   tmake_file="$tmake_file or1k/t-or1k or1k/t-crtstuff"
tmake_file="$tmake_file t-softfp-sfdf t-softfp"
md_unwind_header=or1k/linux-unwind.h
;;
 or1k-*-*)
-   tmake_file="$tmake_file or1k/t-or1k"
+   tmake_file="$tmake_file or1k/t-or1k or1k/t-crtstuff"
tmake_file="$tmake_file t-softfp-sfdf t-softfp"
;;
 pdp11-*-*)
diff --git a/libgcc/config/or1k/t-crtstuff b/libgcc/config/or1k/t-crtstuff
new file mode 100644
index 000..dcae7f3498e
--- /dev/null
+++ b/libgcc/config/or1k/t-crtstuff
@@ -0,0 +1,2 @@
+# Compile crtbeginS.o and crtendS.o with -mcmodel=large
+CRTSTUFF_T_CFLAGS_S += -mcmodel=large
-- 
2.26.2



Re: [PATCH] [RISCV] Add Pattern for builtin overflow

2021-05-01 Thread Andrew Waterman
On Thu, Apr 29, 2021 at 3:02 PM Jim Wilson  wrote:
>
> On Wed, Apr 28, 2021 at 4:04 PM Andrew Waterman  wrote:
>>
>> > This is a good suggestion, but in the interests of making forward progress 
>> > here, I'd like to accept the patch and then file these as bugzillas as 
>> > ways to further improve the patch.
>>
>> Agreed, these potential improvements are definitely not blockers.
>
>
> Turns out Levy had time to work on the patch after all, and submitted a 
> fourth version with your improvements.

Cool.  Thank you, Levy!

>
> Jim