[PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-01-17 Thread Geng Qi via Gcc-patches
From: gengqi 

Think about this case:
  ./multilib-generator rv32imc-ilp32-rv32imac,rv32imacxthead-f
Here are 2 problems:
  1. A unexpected 'xtheadf' extension was made.
  2. The arch 'rv32imac' was not be created.
This modification fix these two, and also sorts 'multi-letter'.

gcc/ChangeLog:
* config/riscv/arch-canonicalize
(longext_sort): New function for sorting 'multi-letter'.
* config/riscv/multilib-generator: Adjusting the loop of 'alt' in
'alts'. The 'arch' may not be the first of 'alts'.
(_expand_combination): Add underline for the 'ext' without '*'.
This is because, a single-letter extension can always be treated well
with a '_' prefix, but it cannot be separated out if it is appended
to a multi-letter.
---
 gcc/config/riscv/arch-canonicalize  | 14 +-
 gcc/config/riscv/multilib-generator | 12 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/arch-canonicalize 
b/gcc/config/riscv/arch-canonicalize
index 2b4289e..a1e4570 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -74,8 +74,20 @@ def arch_canonicalize(arch):
   # becasue we just append extensions list to the arch string.
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
+  def longext_sort (exts):
+if not exts.startswith("zxm") and exts.startswith("z"):
+  # If "Z" extensions are named, they should be ordered first by CANONICAL.
+  if exts[1] not in CANONICAL_ORDER:
+raise Exception("Unsupported extension `%s`" % exts)
+  canonical_sort = CANONICAL_ORDER.index(exts[1])
+else:
+  canonical_sort = -1
+return (exts.startswith("x"), exts.startswith("zxm"),
+LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+
   # Multi-letter extension must be in lexicographic order.
-  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
+  key=longext_sort))
 
   # Put extensions in canonical order.
   for ext in CANONICAL_ORDER:
diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index 64ff15f..7b22537 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -68,15 +68,15 @@ def arch_canonicalize(arch):
 def _expand_combination(ext):
   exts = list(ext.split("*"))
 
-  # No need to expand if there is no `*`.
-  if len(exts) == 1:
-return [(exts[0],)]
-
   # Add underline to every extension.
   # e.g.
   #  _b * zvamo => _b * _zvamo
   exts = list(map(lambda x: '_' + x, exts))
 
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
   # Generate combination!
   ext_combs = []
   for comb_len in range(1, len(exts)+1):
@@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
   # Drop duplicated entry.
   alts = unique(alts)
 
-  for alt in alts[1:]:
+  for alt in alts:
+if alt == arch:
+  continue
 arches[alt] = 1
 reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
   required.append('march=%s/mabi=%s' % (arch, abi))
-- 
2.7.4



Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Jakub Jelinek via Gcc-patches
On Mon, Jan 18, 2021 at 07:10:07AM +0100, Sebastian Huber wrote:
> Hello Jakub,
> 
> On 17/01/2021 17:04, Jakub Jelinek via Gcc-patches wrote:
> 
> > On Sun, Jan 17, 2021 at 04:25:24PM +0100, Andreas Schwab wrote:
> > > On Jan 17 2021, Jakub Jelinek via Gcc-patches wrote:
> > > 
> > > > Kwok, I guess you can reproduce it even on Linux with 
> > > > --disable-linux-futex
> > > And all targets that are not explicitly configured in
> > > libcomp/configure.tgt, where --enable-linux-futex is a no-op.
> > Completely untested patch (except for the linux futex version; and RTEMS
> > stuff is missing; I think it doesn't have a function for it but has a
> > counter in the struct, so perhaps fetch it manually from there), it is
> > Sunday, don't want to do more tonight:
> 
> here is the RTEMS part:

Ok for trunk with ChangeLog entry, thanks.

I have now committed this after bootstrapping/regtesting on x86_64-linux and
i686-linux and additionally building on x86_64-linux with
--disable-linux-futex and testing libgomp there.

2021-01-18  Jakub Jelinek  

* config/linux/sem.h (gomp_sem_getcount): New function.
* config/posix/sem.h (gomp_sem_getcount): New function.
* config/posix/sem.c (gomp_sem_getcount): New function.
* config/accel/sem.h (gomp_sem_getcount): New function.
* task.c (task_fulfilled_p): Use gomp_sem_getcount.
(omp_fulfill_event): Likewise.

--- libgomp/config/linux/sem.h.jj   2021-01-04 10:25:56.160037625 +0100
+++ libgomp/config/linux/sem.h  2021-01-17 16:49:39.900750416 +0100
@@ -85,4 +85,13 @@ gomp_sem_post (gomp_sem_t *sem)
   if (__builtin_expect (count & SEM_WAIT, 0))
 gomp_sem_post_slow (sem);
 }
+
+static inline int
+gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int count = __atomic_load_n (sem, MEMMODEL_RELAXED);
+  if ((count & SEM_WAIT) != 0)
+return -1;
+  return count / SEM_INC;
+}
 #endif /* GOMP_SEM_H */
--- libgomp/config/posix/sem.h.jj   2021-01-04 10:25:56.166037557 +0100
+++ libgomp/config/posix/sem.h  2021-01-17 16:49:53.605593659 +0100
@@ -64,6 +64,8 @@ extern void gomp_sem_post (gomp_sem_t *s
 
 extern void gomp_sem_destroy (gomp_sem_t *sem);
 
+extern int gomp_sem_getcount (gomp_sem_t *sem);
+
 #else /* HAVE_BROKEN_POSIX_SEMAPHORES  */
 
 typedef sem_t gomp_sem_t;
@@ -84,5 +86,13 @@ static inline void gomp_sem_destroy (gom
 {
   sem_destroy (sem);
 }
+
+static inline int gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int val;
+  if (sem_getvalue (sem, ) < 0)
+return -1;
+  return val;  
+}
 #endif /* doesn't HAVE_BROKEN_POSIX_SEMAPHORES  */
 #endif /* GOMP_SEM_H  */
--- libgomp/config/posix/sem.c.jj   2021-01-04 10:25:56.184037354 +0100
+++ libgomp/config/posix/sem.c  2021-01-17 16:52:00.207145847 +0100
@@ -112,6 +112,26 @@ void gomp_sem_destroy (gomp_sem_t *sem)
 
   return;
 }
+
+int gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int ret, count;
+
+  ret = pthread_mutex_lock (>mutex);
+  if (ret)
+return -1;
+
+  count = sem->value;
+
+  ret = pthread_mutex_unlock (>mutex);
+  if (ret)
+return -1;
+
+  if (count < 0)
+return -1;
+
+  return count;
+}
 #else /* HAVE_BROKEN_POSIX_SEMAPHORES  */
 void
 gomp_sem_wait (gomp_sem_t *sem)
--- libgomp/config/accel/sem.h.jj   2021-01-04 10:25:56.261036482 +0100
+++ libgomp/config/accel/sem.h  2021-01-17 16:53:13.381309036 +0100
@@ -62,4 +62,13 @@ gomp_sem_post (gomp_sem_t *sem)
 {
   (void) __atomic_add_fetch (sem, 1, MEMMODEL_RELEASE);
 }
+
+static inline int
+gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int count = __atomic_load_n (sem, MEMMODEL_RELAXED);
+  if (count < 0)
+return -1;
+  return count;
+}
 #endif /* GOMP_SEM_H */
--- libgomp/task.c.jj   2021-01-16 22:52:33.749412323 +0100
+++ libgomp/task.c  2021-01-17 16:54:54.315154777 +0100
@@ -330,7 +330,7 @@ gomp_task_handle_depend (struct gomp_tas
 static bool
 task_fulfilled_p (struct gomp_task *task)
 {
-  return __atomic_load_n (>completion_sem, __ATOMIC_RELAXED);
+  return gomp_sem_getcount (>completion_sem) > 0;
 }
 
 /* Called when encountering an explicit task directive.  If IF_CLAUSE is
@@ -2406,7 +2406,7 @@ omp_fulfill_event (omp_event_handle_t ev
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr ? thr->ts.team : NULL;
 
-  if (__atomic_load_n (sem, __ATOMIC_RELAXED))
+  if (gomp_sem_getcount (sem) > 0)
 gomp_fatal ("omp_fulfill_event: %p event already fulfilled!\n", sem);
 
   gomp_debug (0, "omp_fulfill_event: %p\n", sem);


Jakub



Re: [PATCH] [wwwdocs] Add nios2 changes for GCC 11

2021-01-17 Thread Sandra Loosemore

On 1/17/21 12:08 PM, Sebastian Huber wrote:

---
  htdocs/gcc-11/changes.html | 14 +-
  1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/htdocs/gcc-11/changes.html b/htdocs/gcc-11/changes.html
index 3527428f..dac3a03f 100644
--- a/htdocs/gcc-11/changes.html
+++ b/htdocs/gcc-11/changes.html
@@ -409,7 +409,19 @@ a work-in-progress.
  
  
  
-

+Nios II
+
+  The options -mcustom-insn=N no longer produce compiler
+  warnings if the custom instruction is not generated due to missing
+  optimization options such as -fno-math-errno,
+  -ffinite-math-only, or
+  -funsafe-math-optimizations.


I think it would be good to add a sentence of rationale here, like

These warnings were not consistently emitted for all custom instructions.


+  
+  The -mcustom-fpu-cfg=fph2 has been added to enable the
+  custom instructions supported by the Nios II Floating Point Hardware
+  2 Component.
+  
+


s/has been added/option has been added/

OK with those changes.  Thanks for remembering to update the docs!  :-)

-Sandra


Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Sebastian Huber

Hello Jakub,

On 17/01/2021 17:04, Jakub Jelinek via Gcc-patches wrote:


On Sun, Jan 17, 2021 at 04:25:24PM +0100, Andreas Schwab wrote:

On Jan 17 2021, Jakub Jelinek via Gcc-patches wrote:


Kwok, I guess you can reproduce it even on Linux with --disable-linux-futex

And all targets that are not explicitly configured in
libcomp/configure.tgt, where --enable-linux-futex is a no-op.

Completely untested patch (except for the linux futex version; and RTEMS
stuff is missing; I think it doesn't have a function for it but has a
counter in the struct, so perhaps fetch it manually from there), it is
Sunday, don't want to do more tonight:


here is the RTEMS part:

diff --git a/libgomp/config/rtems/sem.h b/libgomp/config/rtems/sem.h
index 50b650ab807..0cd74153b05 100644
--- a/libgomp/config/rtems/sem.h
+++ b/libgomp/config/rtems/sem.h
@@ -47,6 +47,11 @@ static inline void gomp_sem_post (gomp_sem_t *sem)
   _Semaphore_Post (sem);
 }

+static inline int gomp_sem_getcount (gomp_sem_t *sem)
+{
+  return (int) __atomic_load_n (>_count, MEMMODEL_RELAXED);
+}
+
 static inline void gomp_sem_destroy (gomp_sem_t *sem)
 {
   _Semaphore_Destroy (sem);

--
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/



[PATCH] RISC-V: The 'multilib-generator' enhancement.

2021-01-17 Thread Geng Qi via Gcc-patches
From: gengqi 

gcc/ChangeLog:
* config/riscv/arch-canonicalize
(longext_sort): New function for sorting 'multi-letter'.
* config/riscv/multilib-generator: Adjusting the loop of 'alt' in
'alts'. The 'arch' may not be the first of 'alts'.
(_expand_combination): Add underline for the 'ext' without '*'.
This is because, a single-letter extension can always be treated well
with a '_' prefix, but it cannot be separated out if it is appended
to a multi-letter.
---
 gcc/config/riscv/arch-canonicalize  | 14 +-
 gcc/config/riscv/multilib-generator | 12 +++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/gcc/config/riscv/arch-canonicalize 
b/gcc/config/riscv/arch-canonicalize
index 2b4289e..a1e4570 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -74,8 +74,20 @@ def arch_canonicalize(arch):
   # becasue we just append extensions list to the arch string.
   std_exts += list(filter(lambda x:len(x) == 1, long_exts))
 
+  def longext_sort (exts):
+if not exts.startswith("zxm") and exts.startswith("z"):
+  # If "Z" extensions are named, they should be ordered first by CANONICAL.
+  if exts[1] not in CANONICAL_ORDER:
+raise Exception("Unsupported extension `%s`" % exts)
+  canonical_sort = CANONICAL_ORDER.index(exts[1])
+else:
+  canonical_sort = -1
+return (exts.startswith("x"), exts.startswith("zxm"),
+LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+
   # Multi-letter extension must be in lexicographic order.
-  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts)))
+  long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
+  key=longext_sort))
 
   # Put extensions in canonical order.
   for ext in CANONICAL_ORDER:
diff --git a/gcc/config/riscv/multilib-generator 
b/gcc/config/riscv/multilib-generator
index 64ff15f..7b22537 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -68,15 +68,15 @@ def arch_canonicalize(arch):
 def _expand_combination(ext):
   exts = list(ext.split("*"))
 
-  # No need to expand if there is no `*`.
-  if len(exts) == 1:
-return [(exts[0],)]
-
   # Add underline to every extension.
   # e.g.
   #  _b * zvamo => _b * _zvamo
   exts = list(map(lambda x: '_' + x, exts))
 
+  # No need to expand if there is no `*`.
+  if len(exts) == 1:
+return [(exts[0],)]
+
   # Generate combination!
   ext_combs = []
   for comb_len in range(1, len(exts)+1):
@@ -147,7 +147,9 @@ for cfg in sys.argv[1:]:
   # Drop duplicated entry.
   alts = unique(alts)
 
-  for alt in alts[1:]:
+  for alt in alts:
+if alt == arch:
+  continue
 arches[alt] = 1
 reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
   required.append('march=%s/mabi=%s' % (arch, abi))
-- 
2.7.4



[PATCH] c++: Defer access checking when processing bases [PR82613]

2021-01-17 Thread Patrick Palka via Gcc-patches
When parsing the base-clause of a class declaration, we need to defer
access checking until the entire base-clause has been seen, so that
access can be properly checked relative to the scope of the class with
all its bases attached.  This allows us to accept the declaration of
struct D from Example 2 of [class.access.general] (access12.C below).

Similarly when substituting into the base-clause of a class template,
which is the subject of PR82613.

Bootstrapped and regtested on x86_64-pc-linxu-gnu, does this look OK for
trunk?

gcc/cp/ChangeLog:

PR c++/82613
* parser.c (cp_parser_class_head): Defer access checking when
parsing the base-clause until all bases are seen and attached
to the class type.
* pt.c (instantiate_class_template): Likewise when substituting
into dependent bases.

gcc/testsuite/ChangeLog:

PR c++/82613
* g++.dg/parse/access12.C: New test.
* g++.dg/template/access35.C: New test.
---
 gcc/cp/parser.c  | 30 ++--
 gcc/cp/pt.c  | 16 ++---
 gcc/testsuite/g++.dg/parse/access12.C| 24 +++
 gcc/testsuite/g++.dg/template/access35.C | 26 
 4 files changed, 75 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/access12.C
 create mode 100644 gcc/testsuite/g++.dg/template/access35.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 88c6e2648cb..57843cd65c6 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -25578,19 +25578,11 @@ cp_parser_class_head (cp_parser* parser,
 
  is valid.  */
 
-  /* Get the list of base-classes, if there is one.  */
+  /* Get the list of base-classes, if there is one.  Defer access checking
+ until the entire list has been seen, as per [class.access.general].  */
+  push_deferring_access_checks (dk_deferred);
   if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
-{
-  /* PR59482: enter the class scope so that base-specifiers are looked
-up correctly.  */
-  if (type)
-   pushclass (type);
-  bases = cp_parser_base_clause (parser);
-  /* PR59482: get out of the previously pushed class scope so that the
-subsequent pops pop the right thing.  */
-  if (type)
-   popclass ();
-}
+bases = cp_parser_base_clause (parser);
   else
 bases = NULL_TREE;
 
@@ -25599,6 +25591,20 @@ cp_parser_class_head (cp_parser* parser,
   if (type && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
 xref_basetypes (type, bases);
 
+  /* Now that all bases have been seen and attached to the class, check
+ accessibility of the types named in the base-clause.  This must be
+ done relative to the class scope, so that we accept e.g.
+
+   class A { protected: struct B {}; };
+   struct C : A::B, A {}; // OK: A::B is accessible from C
+
+ as per [class.access.general].  */
+  if (type)
+pushclass (type);
+  pop_to_parent_deferring_access_checks ();
+  if (type)
+popclass ();
+
  done:
   /* Leave the scope given by the nested-name-specifier.  We will
  enter the class scope itself while processing the members.  */
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a82324d23be..d5d3d2fd040 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11825,17 +11825,14 @@ instantiate_class_template_1 (tree type)
  || COMPLETE_OR_OPEN_TYPE_P (TYPE_CONTEXT (type)));
 
   base_list = NULL_TREE;
+  /* Defer access checking while we substitute into the types named in
+ the base-clause.  */
+  push_deferring_access_checks (dk_deferred);
   if (BINFO_N_BASE_BINFOS (pbinfo))
 {
   tree pbase_binfo;
-  tree pushed_scope;
   int i;
 
-  /* We must enter the scope containing the type, as that is where
-the accessibility of types named in dependent bases are
-looked up from.  */
-  pushed_scope = push_scope (CP_TYPE_CONTEXT (type));
-
   /* Substitute into each of the bases to determine the actual
 basetypes.  */
   for (i = 0; BINFO_BASE_ITERATE (pbinfo, i, pbase_binfo); i++)
@@ -11877,9 +11874,6 @@ instantiate_class_template_1 (tree type)
 
   /* The list is now in reverse order; correct that.  */
   base_list = nreverse (base_list);
-
-  if (pushed_scope)
-   pop_scope (pushed_scope);
 }
   /* Now call xref_basetypes to set up all the base-class
  information.  */
@@ -11897,6 +11891,10 @@ instantiate_class_template_1 (tree type)
  class, except we also need to push the enclosing classes.  */
   push_nested_class (type);
 
+  /* Now check accessibility of the types named in its base-clause,
+ relative to the scope of the class.  */
+  pop_to_parent_deferring_access_checks ();
+
   /* Now members are processed in the order of declaration.  */
   for (member = CLASSTYPE_DECL_LIST (pattern);
member; member = TREE_CHAIN (member))
diff --git a/gcc/testsuite/g++.dg/parse/access12.C 

[PATCH] c++: Fix excessive instantiation inside decltype [PR71879]

2021-01-17 Thread Patrick Palka via Gcc-patches
Here after resolving the address of a template-id inside decltype, we
end up instantiating the chosen specialization from the call to
mark_used in resolve_nondeduced_context, even though only its type is
needed.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look for
trunk?

gcc/cp/ChangeLog:

PR c++/71879
* semantics.c (finish_decltype_type): Temporarily increment
cp_unevaluated_operand during call to resolve_nondeduced_context.

gcc/testsuite/ChangeLog:

PR c++/71879
* g++.dg/cpp0x/decltype-71879.C: New test.
---
 gcc/cp/semantics.c  | 2 ++
 gcc/testsuite/g++.dg/cpp0x/decltype-71879.C | 5 +
 2 files changed, 7 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype-71879.C

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index c8a6283b120..cad55665ce8 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -10098,7 +10098,9 @@ finish_decltype_type (tree expr, bool 
id_expression_or_member_access_p,
 
   /* The type denoted by decltype(e) is defined as follows:  */
 
+  ++cp_unevaluated_operand;
   expr = resolve_nondeduced_context (expr, complain);
+  --cp_unevaluated_operand;
 
   if (invalid_nonstatic_memfn_p (input_location, expr, complain))
 return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-71879.C 
b/gcc/testsuite/g++.dg/cpp0x/decltype-71879.C
new file mode 100644
index 000..9da4d40ca70
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype-71879.C
@@ -0,0 +1,5 @@
+// PR c++/71879
+// { dg-do compile { target c++11 } }
+
+template  void f(T x) { x.fail(); }
+using R = decltype();
-- 
2.30.0.155.g66e871b664



[PATCH] analyzer: use "malloc" attribute

2021-01-17 Thread David Malcolm via Gcc-patches
This is an updated version of this patch from October:

  'RFC: add "deallocated_by" attribute for use by analyzer'
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/44.html

reworking it to build on top of Martin's work as noted below, reusing
the existing attribute rather than adding a new one.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Also tested by hand with valgrind.

Apart from a trivial change to attrib.h and to builtins.c, this
is confined to the analyzer code and docs.  The original patch was
posted in stage 1.  Is this OK for master?  (I'm hoping for
release manager permission to commit this code now; it's not
clear to me whether the end of stage 3 was on the 16th or is
today on the 17th).

Thanks
Dave

In dce6c58db87ebf7f4477bd3126228e73e497 msebor extended the
"malloc" attribute to support user-defined allocator/deallocator
pairs.

This patch extends the "malloc" checker within -fanalyzer to use
these attributes.  It is based on an earlier patch:
  'RFC: add "deallocated_by" attribute for use by analyzer'
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/44.html
which added a different attribute.  I mistakenly thought that it would
be easy to merge our patches; the patch turned out to need a lot of
reworking, to support multiple deallocators per allocator.

My hope was that this would provide a minimal level of markup that would
support library-checking without requiring lots of further markup.
I attempted to use this to detect a memory leak within a Linux
driver (CVE-2019-19078), by adding the attribute to mark these fns:
extern struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags);
extern void usb_free_urb(struct urb *urb);
where there is a leak of a "urb" on an error-handling path.
Unfortunately I ran into the problem that there are various other fns
that take "struct urb *" and the analyzer conservatively assumes that a
urb passed to them might or might not be freed and thus stops tracking
state for them.

Hence this will only detect issues for the simplest cases (without
adding another attribute).

gcc/analyzer/ChangeLog:
* analyzer.h (is_std_named_call_p): New decl.
* diagnostic-manager.cc (path_builder::get_sm): New.
(state_change_event_creator::state_change_event_creator): Add "pb"
param.
(state_change_event_creator::on_global_state_change): Don't consider
state changes affecting other state_machines.
(state_change_event_creator::on_state_change): Likewise.
(state_change_event_creator::m_pb): New field.
(diagnostic_manager::add_events_for_eedge): Pass pb to visitor
ctor.
* region-model-impl-calls.cc
(region_model::impl_deallocation_call): New.
* region-model.cc: Include "attribs.h".
(region_model::on_call_post): Handle fndecls referenced by
__attribute__((deallocated_by(FOO))).
* region-model.h (region_model::impl_deallocation_call): New decl.
* sm-malloc.cc: Include "stringpool.h" and "attribs.h".  Add
leading comment.
(class api): Delete.
(enum resource_state): Update comment for change from api to
deallocator and deallocator_set.
(allocation_state::allocation_state): Drop api param.  Add
"deallocators" and "deallocator".
(allocation_state::m_api): Drop field in favor of...
(allocation_state::m_deallocators): New field.
(allocation_state::m_deallocator): New field.
(enum wording): Add WORDING_DEALLOCATED.
(struct deallocator): New.
(struct standard_deallocator): New.
(struct custom_deallocator): New.
(struct deallocator_set): New.
(struct custom_deallocator_set): New.
(struct standard_deallocator_set): New.
(struct deallocator_set_map_traits): New.
(malloc_state_machine::m_malloc): Drop field
(malloc_state_machine::m_scalar_new): Likewise.
(malloc_state_machine::m_vector_new): Likewise.
(malloc_state_machine::m_free): New field
(malloc_state_machine::m_scalar_delete): Likewise.
(malloc_state_machine::m_vector_delete): Likewise.
(malloc_state_machine::deallocator_map_t): New typedef.
(malloc_state_machine::m_deallocator_map): New field.
(malloc_state_machine::deallocator_set_cache_t): New typedef.
(malloc_state_machine::m_custom_deallocator_set_cache): New field.
(malloc_state_machine::custom_deallocator_set_map_t): New typedef.
(malloc_state_machine::m_custom_deallocator_set_map): New field.
(malloc_state_machine::m_dynamic_sets): New field.
(malloc_state_machine::m_dynamic_deallocators): New field.
(api::api): Delete.
(deallocator::deallocator): New ctor.
(deallocator::hash): New.
(deallocator::dump_to_pp): New.
(deallocator::cmp): New.
(deallocator::cmp_ptr_ptr): New.

[PATCH] Modula-2 into the GCC tree on master

2021-01-17 Thread Gaius Mulley via Gcc-patches


Hello,

here is a patch which merges the gm2 front end into the GCC tree.  The
patches have been boostrapped under x86_64 GNU/Linux Debian Stretch
built using make -j 24 and also under x86_64 GNU/Linux Debian Buster
using make -j 4.

Tested on Debian Stretch x86_64
===

built GCC bootstrap 3 times:

1.  built vanilla GCC (enabling bootstrap) enabling front ends:
brig,c,c++,go,d,fortran and ran the regression tests.

2.  the patches below were applied and associated tarball untarred.
The same front ends brig,c,c++,go,d,fortran (again building from
bootstrap) were enabled (no m2) and ran the regression tests.
There were no changes to the regression test results between 1 and
2.

3.  Then it was rebuilt (from bootstrap) enabling the front ends
brig,c,c++,go,d,fortran,m2 and ran the
regression tests and again no extra failures were seen.

[should I also be testing ada?]

Built on Debian Buster x86_64
=

Built a patched tree enabling bootstrap make -j 4 for front ends c,c++,m2
all compiled and bootstrapped.

How to merge


1.  apply patches below to the master GCC tree.

2.  cd gcc-git-top
wget 
http://floppsie.comp.glam.ac.uk/download/c/gm2-front-end-20210116-tar.gz
tar zxf gm2-front-end-20210116-tar.gz
rm gm2-front-end-20210116-tar.gz
# new directories libgm2 and gcc/m2 are created and populated

3.  cd gcc-git-top
autogen Makefile.def
autoconf
cd libgm2
/bin/sh ./autogen.sh

when built this implements iso, pim2, pim3 and pim4 editions of Modula-2
with access to GCC features (gcc/m2/gm2.texi).

hope this is useful - enjoy,

regards,
Gaius



2021-01-18  Gaius Mulley   

* configure.ac (GM2_FOR_TARGET): Added.
Request build driver program gm2.
(libgm2) option added.
(compare_exclusions) includes SYSTEM and M2Version.
* Makefile.def (GM2_FOR_TARGET): Added.
(GM2FLAGS_FOR_TARGET): Added.  Assign GM2,
GM2_FOR_BUILD, GM2_FOR_TARGET and GM2FLAGS.
Pass variables to make.  Add new language Modula-2
(m2).  (target_modules) includes libgm2.  (flags_to_pass)
includes GM2_FOR_TARGET and GM2FLAGS_FOR_TARGET.
* Makefile.tpl (GM2FLAGS): Added.  (GM2) Added.
(GM2_FOR_BUILD) Added.

gcc/

* gcc/brig/brigspec.c (lang_register_spec_functions): Added.
* gcc/c-family/cppspec.c (lang_register_spec_functions): Added.
* gcc/c/gccspec.c (lang_register_spec_functions): Added.
* gcc/cp/g++spec.c (lang_register_spec_functions): Added.
* gcc/d/d-spec.cc (lang_register_spec_functions): Added.
* gcc/fortran/gfortranspec.c(lang_register_spec_functions): Added.
* gcc/gcc.c (allow_linker): Global variable to disable
linker by the front end.  (xputenv) available externally.
(xgetenv) New function.  (save_switch) available externally.
(fe_add_linker_option) New function.  (handle_OPT_B) New function.
(fe_add_infile) New function.  (fe_mark_compiled) New function.
(driver_handle_option) call handle_OPT_B.  (print_option) New
function.  (print_options) New function.  (dbg_options) New function.
(fe_add_spec_function) New function.  (lookup_spec_function)
checks front end registered functions.
(driver::set_up_specs):  call lang_register_spec_functions.
(maybe_run_linker): Check allow_linker before running the linker.
* gcc/gcc.h (fe_save_switch): Prototype.
(handle_OPT_B) Prototype.  (fe_add_infile) Prototype.
(fe_add_linker_option) Prototype.  (fe_add_spec_function) Prototype.
(xputenv) Prototype.  (xgetenv) Prototype.  (print_options) Prototype.
(print_option) Prototype.  (dbg_options) Prototype.
(lang_register_spec_functions) Prototype.
(allow_linker): Extern.
* gcc/go/gospec.c (lang_register_spec_functions): Added.

Patches
===

diff --git a/Makefile.def b/Makefile.def
index 3e38f61193f..ef428b98f40 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -180,6 +180,7 @@ target_modules = { module= libffi; no_install=true; };
 target_modules = { module= zlib; };
 target_modules = { module= rda; };
 target_modules = { module= libada; };
+target_modules = { module= libgm2; lib_path=.libs; };
 target_modules = { module= libgomp; bootstrap= true; lib_path=.libs; };
 target_modules = { module= libitm; lib_path=.libs; };
 target_modules = { module= libatomic; lib_path=.libs; };
@@ -298,6 +299,8 @@ flags_to_pass = { flag= GOC_FOR_TARGET ; };
 flags_to_pass = { flag= GOCFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= GDC_FOR_TARGET ; };
 flags_to_pass = { flag= GDCFLAGS_FOR_TARGET ; };
+flags_to_pass = { flag= GM2_FOR_TARGET ; };
+flags_to_pass = { flag= GM2FLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= LD_FOR_TARGET ; };
 flags_to_pass = { flag= LIPO_FOR_TARGET ; };
 flags_to_pass = { flag= LDFLAGS_FOR_TARGET ; };
@@ -652,6 +655,7 @@ languages = { language=obj-c++; 
gcc-check-target=check-obj-c++; };
 languages = { language=go; gcc-check-target=check-go;
lib-check-target=check-target-libgo;
lib-check-target=check-gotools; };
+languages = { language=m2; 

[PATCH] aix: Default to DWARF 4

2021-01-17 Thread David Edelsohn via Gcc-patches
GCC now defaults to DWARF 5.  AIX only supports DWARF 4 (3.5).

This patch overrides the default DWARF version to 4 unless explicitly
stated.

gcc/ChangeLog:

* config/rs6000/aix71.h (SUBTARGET_OVERRIDE_OPTIONS): Override
dwarf_version to 4.
* config/rs6000/aix72.h (SUBTARGET_OVERRIDE_OPTIONS): Same.

diff --git a/gcc/config/rs6000/aix71.h b/gcc/config/rs6000/aix71.h
index cb250e9871c..3612ed2593b 100644
--- a/gcc/config/rs6000/aix71.h
+++ b/gcc/config/rs6000/aix71.h
@@ -62,6 +62,9 @@ do {
\
   /* aix/ppc doesn't support -mvsx and -maltivec with Go */
\
   rs6000_isa_flags &= ~(OPTION_MASK_VSX | OPTION_MASK_ALTIVEC);\
 }  \
+  if (!global_options_set.x_dwarf_version) \
+/* AIX only supports DWARF 4.  */  \
+dwarf_version = 4; \
 } while (0)

 #define ASM_SPEC32 "-a32"

diff --git a/gcc/config/rs6000/aix72.h b/gcc/config/rs6000/aix72.h
index 8bcaca47a7b..d34909283cc 100644
--- a/gcc/config/rs6000/aix72.h
+++ b/gcc/config/rs6000/aix72.h
@@ -62,6 +62,9 @@ do {
\
   /* aix/ppc doesn't support -mvsx and -maltivec with Go */
\
   rs6000_isa_flags &= ~(OPTION_MASK_VSX | OPTION_MASK_ALTIVEC);\
 }  \
+  if (!global_options_set.x_dwarf_version) \
+/* AIX only supports DWARF 4.  */  \
+dwarf_version = 4; \
 } while (0)

 #define ASM_SPEC32 "-a32"


Re: [PATCH] alias: Fix offset checks involving section anchors [PR92294]

2021-01-17 Thread Jan Hubicka
> This is a repost of:
> 
>   https://gcc.gnu.org/pipermail/gcc-patches/2020-February/539763.html
> 
> which was initially posted during stage 4.  (And yeah, I only just
> missed stage 4 again.)
> 
> IMO it would be better to fix the bug directly (as the patch tries
> to do) instead of wait for a more thorough redesign of this area.
> See the end of:
> 
>   https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540002.html
> 
> for some stats.
> 
> Honza: Richard said he'd like your opinion on the patch.
> 
> 
> memrefs_conflict_p has a slightly odd structure.  It first checks
> whether two addresses based on SYMBOL_REFs refer to the same object,
> with a tristate result:
> 
>   int cmp = compare_base_symbol_refs (x,y);
> 
> If the addresses do refer to the same object, we can use offset-based checks:
> 
>   /* If both decls are the same, decide by offsets.  */
>   if (cmp == 1)
> return offset_overlap_p (c, xsize, ysize);
> 
> But then, apart from the special case of forced address alignment,
> we use an offset-based check even if we don't know whether the
> addresses refer to the same object:
> 
>   /* Assume a potential overlap for symbolic addresses that went
>through alignment adjustments (i.e., that have negative
>sizes), because we can't know how far they are from each
>other.  */
>   if (maybe_lt (xsize, 0) || maybe_lt (ysize, 0))
>   return -1;
>   /* If decls are different or we know by offsets that there is no 
> overlap,
>we win.  */
>   if (!cmp || !offset_overlap_p (c, xsize, ysize))
>   return 0;
> 
> This somewhat contradicts:
> 
>   /* In general we assume that memory locations pointed to by different labels
>  may overlap in undefined ways.  */

I suppose it is becuase the code above check for SYMBOL_REF and not
label (that is probably about jumptables and constpool injected into
text segment).

I assume this is also bit result of GCC not being very systematic about
aliases.  Sometimes it assumes that two different symbols do not point
to same object while in other cases it is worried about aliases.

I see that anchors are special since they point to "same object" with
different offests.
> 
> at the end of compare_base_symbol_refs.  In other words, we're taking -1
> to mean that either (a) the symbols are equal (via aliasing) or (b) the
> references access non-overlapping objects.

I for symbol refs yes, I think so.
> 
> But even assuming that's true for normal symbols, it doesn't cope
> correctly with section anchors.  If a symbol X at ANCHOR+OFFSET is
> preemptible, either (a) X = ANCHOR+OFFSET (rather than the X = ANCHOR
> assumed above) or (b) X and ANCHOR reference non-overlapping objects.
> 
> And an offset-based comparison makes no sense for an anchor symbol
> vs. a bare symbol with no decl.  If the bare symbol is allowed to
> alias other symbols then it can surely alias any symbol in the
> anchor's block, so there are multiple anchor offsets that might
> induce an alias.
> 
> This patch therefore replaces the current tristate:
> 
>   - known equal
>   - known independent (two accesses can't alias)
>   - equal or independent
> 
> with:
> 
>   - known distance apart
>   - known independent (two accesses can't alias)
>   - known distance apart or independent
>   - don't know
> 
> For safety, the patch puts all bare symbols in the "don't know"
> category.  If that turns out to be too conservative, we at least
> need that behaviour for combinations involving a bare symbol
> and a section anchor.  However, bare symbols should be relatively
> rare these days.

Well, in tree-ssa code we do assume these to be either disjoint objects
or equal (in decl_refs_may_alias_p that continues in case
compare_base_decls is -1).  I am not sure if we win much by threating
them differently on RTL level. I would preffer staying consistent here.

Otheriwse the patch looks good to me.

Honza
> 
> Retested on aarch64-linux-gnu, aarch64_be-elf and x86_64-linux-gnu.
> OK to install?
> 
> Richard
> 
> 
> gcc/
>   PR rtl-optimization/92294
>   * alias.c (compare_base_symbol_refs): Take an extra parameter
>   and add the distance between two symbols to it.  Enshrine in
>   comments that -1 means "either 0 or 1, but we can't tell
>   which at compile time".  Return -2 for symbols whose
>   relationship is unknown.
>   (memrefs_conflict_p): Update call accordingly.
>   (rtx_equal_for_memref_p): Likewise.  Punt for a return value of -2,
>   without even checking the offset.  Take the distance between symbols
>   into account.
> ---
>  gcc/alias.c | 53 ++---
>  1 file changed, 38 insertions(+), 15 deletions(-)
> 
> diff --git a/gcc/alias.c b/gcc/alias.c
> index 8d3575e4e27..e22863a929a 100644
> --- a/gcc/alias.c
> +++ b/gcc/alias.c
> @@ -159,7 +159,8 @@ static tree decl_for_component_ref (tree);
>  static int write_dependence_p (const_rtx,
>  

[committed] avoid assuming SSA_NAME_IDENTIFIER is nonnull

2021-01-17 Thread Martin Sebor via Gcc-patches

More exhaustively testing the MEM_REF formatting change by
pretty-printing every MEM_REF the tree-ssa-uninit pass encounters
triggered another ICE, this one due to assuming SSA_NAME_IDENTIFIER
is non- null.  I have committed as "obvious" the attached patch to
remove the assumption after testing it on x86_64-linux.

Martin

commit 192105b6a2a1f24f974de98c933f372b06c1e06d (HEAD -> master)
Author: Martin Sebor 
Date:   Sun Jan 17 15:27:08 2021 -0700

Avoid assuming SSA_NAME_IDENTIFIER is nonnull.

gcc/c-family/ChangeLog:

* c-pretty-print.c (c_pretty_printer::primary_expression): Don't
assume SSA_NAME_IDENTIFIER evaluates to nonzero.

diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 5a51c05fd75..2095d4badf7 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -1340,18 +1340,23 @@ c_pretty_printer::primary_expression (tree e)
   if (SSA_NAME_VAR (e))
{
  tree var = SSA_NAME_VAR (e);
- const char *name = IDENTIFIER_POINTER (SSA_NAME_IDENTIFIER (e));
- const char *dot;
- if (DECL_ARTIFICIAL (var) && (dot = strchr (name, '.')))
+ if (tree id = SSA_NAME_IDENTIFIER (e))
{
- /* Print the name without the . suffix (such as in VLAs).
-Use pp_c_identifier so that it can be converted into
-the appropriate encoding.  */
- size_t size = dot - name;
- char *ident = XALLOCAVEC (char, size + 1);
- memcpy (ident, name, size);
- ident[size] = '\0';
- pp_c_identifier (this, ident);
+ const char *name = IDENTIFIER_POINTER (id);
+ const char *dot;
+ if (DECL_ARTIFICIAL (var) && (dot = strchr (name, '.')))
+   {
+ /* Print the name without the . suffix (such as in VLAs).
+Use pp_c_identifier so that it can be converted into
+the appropriate encoding.  */
+ size_t size = dot - name;
+ char *ident = XALLOCAVEC (char, size + 1);
+ memcpy (ident, name, size);
+ ident[size] = '\0';
+ pp_c_identifier (this, ident);
+   }
+ else
+   primary_expression (var);
}
  else
primary_expression (var);


[PATCH] ipa: Adjust cgraph verifier to materialization on demand (PR 98222)

2021-01-17 Thread Martin Jambor
Hi,

after switching to materialization of clones on demand, the verifier
can happen to see edges leading to a clone of a materialized clone.
This means its clone_of is NULL and former_clone_of needs to be
checked in order to verify that the callee is a clone of the original
decl, which it did not do and reported edges to pointing to a wrong
place.

Fixed with the following patch, which has been pre-approved by Honza.
Bootstrapped and tested on x86_64-linux, pushed to master.

Martin

gcc/ChangeLog:

2021-01-15  Martin Jambor  

PR ipa/98222
* cgraph.c (clone_of_p): Check also former_clone_of as we climb
the clone tree.

gcc/testsuite/ChangeLog:

2021-01-15  Martin Jambor  

PR ipa/98222
* gcc.dg/ipa/pr98222.c: New test.
---
 gcc/cgraph.c   |  4 +++-
 gcc/testsuite/gcc.dg/ipa/pr98222.c | 19 +++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr98222.c

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index d0d785b3438..db038306e19 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -3081,7 +3081,9 @@ clone_of_p (cgraph_node *node, cgraph_node *node2)
 
   if (!node->thunk && !node->former_thunk_p ())
 {
-  while (node2 && node->decl != node2->decl)
+  while (node2
+&& node->decl != node2->decl
+&& node->decl != node2->former_clone_of)
node2 = node2->clone_of;
   return node2 != NULL;
 }
diff --git a/gcc/testsuite/gcc.dg/ipa/pr98222.c 
b/gcc/testsuite/gcc.dg/ipa/pr98222.c
new file mode 100644
index 000..92e857c2048
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr98222.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O3"  } */
+
+int a, b, *c;
+
+int f (int j, int k) {
+  b = k / j;
+  if (a)
+f(0, 0);
+  *c = f(b & a, 0);
+  return 0;
+}
+
+int main() {
+  if (a)
+while (1)
+  f(0, 0);
+  return 0;
+}
-- 
2.29.2



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

2021-01-17 Thread Uecker, Martin
Am Freitag, den 01.01.2021, 00:01 + schrieb Joseph Myers:
> 
> 
> I'd expect c2x-* tests to use -std=c2x not -std=gnu2x.  Tests needing 
> -std=gnu2x can be gnu2x-* tests, but you should be able to test the types 
> using _Generic without needing any gnu2x features.  c2x-* tests should 
> also use -pedantic or -pedantic-errors unless they are specifically 
> testing something that doesn't work with those options.
> 
> There should also be tests for cases where code is valid before C2x but 
> invalid in C2x (assignment storing a pointer-to-qualified-array in void *, 
> for example).
> 
> All the tests should have both c2x-* and c11-* variants so the testsuite 
> verifies that the code is properly handled in C11 mode (warnings with 
> -pedantic, errors with -pedantic-errors, in the cases that are invalid for 
> C11 but valid for C2x).  There should also be -Wc11-c2x-compat tests with 
> -std=c2x where appropriate.


Here is a revised version which adds some missing warnings 
and also fixed some error regarding which warnings got emitted.

I added tests for C2X that test with std=c2x and -pedantic-errors
with and without -Wc11-c2x-compat. In the conditional operator
I directly test for the type using _Generic and _Static_assert.
This test also exists for c11 testing for the old behavior.

I did not add tests for c11 for warnings because we already
had warnings before and the tests for these exist. (I removed 
-Wdiscarded-array-qualifiers from the old tests as this flag
is not needed.) Or should there be additional warnings
with -Wc11-c2x-compat for c11? But warning twice about
the same issue does not seem ideal...

More comments?

Best,
Martin


diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 67c0080a5ef..243790e7abf 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,39 @@ 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
-   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
-   "pointer to array loses qualifier "
-   "in conditional expression");
-
-     if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
+  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 ((TREE_CODE (t2) == ARRAY_TYPE)
+     && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
+   {
+     if (!flag_isoc2x)
+   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
+   "pointer to array loses qualifier "
+   "in conditional expression");
+     else if (warn_c11_c2x_compat > 0)
+   warning_at (colon_loc, OPT_Wc11_c2x_compat,
+   "pointer to array does not lose qualifier in C2X "
+   "in conditional expression");
+   }
+     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 (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,
- 

[r11-6755 Regression] FAIL: libstdc++-prettyprinters/libfundts.cc print os on Linux/x86_64

2021-01-17 Thread sunil.k.pandey via Gcc-patches
On Linux/x86_64,

3804e937b0e252a7e42632fe6d9f898f1851a49c is the first bad commit
commit 3804e937b0e252a7e42632fe6d9f898f1851a49c
Author: Mark Wielaard 
Date:   Tue Sep 29 15:52:44 2020 +0200

Default to DWARF5

caused


with GCC configured with



To reproduce:

$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_big_alignment.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_big_alignment.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_big_alignment.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_big_alignment.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_detect_custom_size.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_detect_custom_size.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_detect_custom_size.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_detect_custom_size.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_partial.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_partial.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_partial.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_partial.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_right.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_right.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_right.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_overflow_right.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_underflow_left.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_underflow_left.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_underflow_left.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/alloca_underflow_left.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/global-overflow-1.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/global-overflow-1.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/global-overflow-1.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/global-overflow-1.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/heap-overflow-1.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/heap-overflow-1.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/heap-overflow-1.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/heap-overflow-1.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/null-deref-1.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/null-deref-1.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/null-deref-1.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/null-deref-1.c 
--target_board='unix{-m64\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/sanity-check-pure-c-1.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="asan.exp=c-c++-common/asan/sanity-check-pure-c-1.c 
--target_board='unix{-m32\ 

[patch, coarray_native, committed] Increase initial size on Darwin

2021-01-17 Thread Thomas Koenig via Gcc-patches

Hello world,

the patch (committed after Nicolas' OK) should make it possible
to go one step further in testing with Darwin.

So, it might now be possible to do another round of testing,
to see if there are any other walls to hit :-)

Best regards

Thomas

Use an initial shared memory size of 256 GB on Apple.

This implements an idea that Nicolas had to overcome the Darwin
problem that it is not possible to extend a shared memory segment
on that system.

The remedy is simple: Use a memory segment that is larger than
what can reasonably be used. This should only waste a few page
table entries, while providing the functionality, at least for
further testing.

libgfortran/ChangeLog:

* caf_shared/shared_memory.c (shared_memory_init): On Apple,
use an initial size of 256 GB.
diff --git a/libgfortran/caf_shared/shared_memory.c 
b/libgfortran/caf_shared/shared_memory.c
index b64e40a3ded..0c0b36c663d 100644
--- a/libgfortran/caf_shared/shared_memory.c
+++ b/libgfortran/caf_shared/shared_memory.c
@@ -190,7 +190,16 @@ shared_memory_init (shared_memory_act **pmem)
 {
   shared_memory_act *mem;
   int fd;
+
+  /* Darwin does not appear to be able to grow shared memory segments.  Choose
+ 256 GB; that will likely be enough.  If not, the ftruncate will fail
+ noisily.  */
+
+#ifdef __APPLE__
+  size_t initial_size = ((size_t) 1) << 38;
+#else
   size_t initial_size = round_to_pagesize (sizeof (global_shared_memory_meta));
+#endif
 
   mem = malloc (get_shared_memory_act_size (1));
   fd = get_shmem_fd ();


[PATCH] [wwwdocs] Add nios2 changes for GCC 11

2021-01-17 Thread Sebastian Huber
---
 htdocs/gcc-11/changes.html | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/htdocs/gcc-11/changes.html b/htdocs/gcc-11/changes.html
index 3527428f..dac3a03f 100644
--- a/htdocs/gcc-11/changes.html
+++ b/htdocs/gcc-11/changes.html
@@ -409,7 +409,19 @@ a work-in-progress.
 
 
 
-
+Nios II
+
+  The options -mcustom-insn=N no longer produce compiler
+  warnings if the custom instruction is not generated due to missing
+  optimization options such as -fno-math-errno,
+  -ffinite-math-only, or
+  -funsafe-math-optimizations.
+  
+  The -mcustom-fpu-cfg=fph2 has been added to enable the
+  custom instructions supported by the Nios II Floating Point Hardware
+  2 Component.
+  
+
 
 NVPTX
 
-- 
2.26.2



Re: [COMMITTED] testsuite: i386: Require ifunc support in gcc.target/i386/pr98100.c

2021-01-17 Thread Eric Botcazou
> The new gcc.target/i386/pr98100.c test FAILs on Solaris/x86:
> 
> FAIL: gcc.target/i386/pr98100.c (test for excess errors)
> 
> Excess errors:
> /vol/gcc/src/hg/master/local/gcc/testsuite/gcc.target/i386/pr98100.c:6:1:
> error: the call requires 'ifunc', which is not supported by this target
> 
> Fixed as follows.
> 
> Tested on i386-pc-solaris2.11 and x86_64-pc-linux-gnu.  Installed on
> master.

Backported into 10 branch as obvious.

-- 
Eric Botcazou




Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 17, 2021 at 04:25:24PM +0100, Andreas Schwab wrote:
> On Jan 17 2021, Jakub Jelinek via Gcc-patches wrote:
> 
> > Kwok, I guess you can reproduce it even on Linux with --disable-linux-futex
> 
> And all targets that are not explicitly configured in
> libcomp/configure.tgt, where --enable-linux-futex is a no-op.

Completely untested patch (except for the linux futex version; and RTEMS
stuff is missing; I think it doesn't have a function for it but has a
counter in the struct, so perhaps fetch it manually from there), it is
Sunday, don't want to do more tonight:

--- libgomp/config/linux/sem.h.jj   2021-01-04 10:25:56.160037625 +0100
+++ libgomp/config/linux/sem.h  2021-01-17 16:49:39.900750416 +0100
@@ -85,4 +85,13 @@ gomp_sem_post (gomp_sem_t *sem)
   if (__builtin_expect (count & SEM_WAIT, 0))
 gomp_sem_post_slow (sem);
 }
+
+static inline int
+gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int count = __atomic_load_n (sem, MEMMODEL_RELAXED);
+  if ((count & SEM_WAIT) != 0)
+return -1;
+  return count / SEM_INC;
+}
 #endif /* GOMP_SEM_H */
--- libgomp/config/posix/sem.h.jj   2021-01-04 10:25:56.166037557 +0100
+++ libgomp/config/posix/sem.h  2021-01-17 16:49:53.605593659 +0100
@@ -64,6 +64,8 @@ extern void gomp_sem_post (gomp_sem_t *s
 
 extern void gomp_sem_destroy (gomp_sem_t *sem);
 
+extern int gomp_sem_getcount (gomp_sem_t *sem);
+
 #else /* HAVE_BROKEN_POSIX_SEMAPHORES  */
 
 typedef sem_t gomp_sem_t;
@@ -84,5 +86,13 @@ static inline void gomp_sem_destroy (gom
 {
   sem_destroy (sem);
 }
+
+static inline int gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int val;
+  if (sem_getvalue (sem, ) < 0)
+return -1;
+  return val;  
+}
 #endif /* doesn't HAVE_BROKEN_POSIX_SEMAPHORES  */
 #endif /* GOMP_SEM_H  */
--- libgomp/config/posix/sem.c.jj   2021-01-04 10:25:56.184037354 +0100
+++ libgomp/config/posix/sem.c  2021-01-17 16:52:00.207145847 +0100
@@ -112,6 +112,26 @@ void gomp_sem_destroy (gomp_sem_t *sem)
 
   return;
 }
+
+int gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int ret, count;
+
+  ret = pthread_mutex_lock (>mutex);
+  if (ret)
+return -1;
+
+  count = sem->value;
+
+  ret = pthread_mutex_unlock (>mutex);
+  if (ret)
+return -1;
+
+  if (count < 0)
+return -1;
+
+  return count;
+}
 #else /* HAVE_BROKEN_POSIX_SEMAPHORES  */
 void
 gomp_sem_wait (gomp_sem_t *sem)
--- libgomp/config/accel/sem.h.jj   2021-01-04 10:25:56.261036482 +0100
+++ libgomp/config/accel/sem.h  2021-01-17 16:53:13.381309036 +0100
@@ -62,4 +62,13 @@ gomp_sem_post (gomp_sem_t *sem)
 {
   (void) __atomic_add_fetch (sem, 1, MEMMODEL_RELEASE);
 }
+
+static inline int
+gomp_sem_getcount (gomp_sem_t *sem)
+{
+  int count = __atomic_load_n (sem, MEMMODEL_RELAXED);
+  if (count < 0)
+return -1;
+  return count;
+}
 #endif /* GOMP_SEM_H */
--- libgomp/task.c.jj   2021-01-16 22:52:33.749412323 +0100
+++ libgomp/task.c  2021-01-17 16:54:54.315154777 +0100
@@ -330,7 +330,7 @@ gomp_task_handle_depend (struct gomp_tas
 static bool
 task_fulfilled_p (struct gomp_task *task)
 {
-  return __atomic_load_n (>completion_sem, __ATOMIC_RELAXED);
+  return gomp_sem_getcount (>completion_sem) > 0;
 }
 
 /* Called when encountering an explicit task directive.  If IF_CLAUSE is
@@ -2406,7 +2406,7 @@ omp_fulfill_event (omp_event_handle_t ev
   struct gomp_thread *thr = gomp_thread ();
   struct gomp_team *team = thr ? thr->ts.team : NULL;
 
-  if (__atomic_load_n (sem, __ATOMIC_RELAXED))
+  if (gomp_sem_getcount (sem) > 0)
 gomp_fatal ("omp_fulfill_event: %p event already fulfilled!\n", sem);
 
   gomp_debug (0, "omp_fulfill_event: %p\n", sem);


Jakub



Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Andreas Schwab
On Jan 17 2021, Jakub Jelinek via Gcc-patches wrote:

> Kwok, I guess you can reproduce it even on Linux with --disable-linux-futex

And all targets that are not explicitly configured in
libcomp/configure.tgt, where --enable-linux-futex is a no-op.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Rainer Orth
Hi Jakub,

> On Sun, Jan 17, 2021 at 12:26:26PM +0100, Rainer Orth wrote:
>> >> I have applied your other suggestions, and have retested the gomp.exp and
>> >> libgomp tests. The full testrun started yesterday showed no regressions. 
>> >> If
>> >> you have no further issues then I will commit this later tonight ahead of
>> >> stage4.
>> >
>> > LGTM, thanks.
>> 
>> this patch broke Solaris bootstrap, but probably all non-Linux targets:
>> 
>> /vol/gcc/src/hg/master/local/libgomp/task.c: In function 'task_fulfilled_p':
>> /vol/gcc/src/hg/master/local/libgomp/task.c:334:1: error: control reaches 
>> end of non-void function [-Werror=return-type]
>>   334 | }
>>   | ^
>> 
>> task_fulfilled_p is
>> 
>>   return __atomic_load_n (>completion_sem, __ATOMIC_RELAXED);
>> 
>> but in config/posix/sem.h gomp_sem_t is (for
>> !HAVE_BROKEN_POSIX_SEMAPHORES):
>> 
>>   typedef sem_t gomp_sem_t;
>> 
>> and sem_t being a struct in Solaris .
>
> Oops.
> I guess we want to add to sem.h some API to query current value of the
> semaphore, which could be atomic load for the config/{linux,accel}/sem.h,
> sem_getvalue for config/posix/sem.h (does Solaris implement that?)

it does: this was already in POSIX.1-2001 and even Solaris 11.3 supports XPG6.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 17, 2021 at 12:26:26PM +0100, Rainer Orth wrote:
> >> I have applied your other suggestions, and have retested the gomp.exp and
> >> libgomp tests. The full testrun started yesterday showed no regressions. If
> >> you have no further issues then I will commit this later tonight ahead of
> >> stage4.
> >
> > LGTM, thanks.
> 
> this patch broke Solaris bootstrap, but probably all non-Linux targets:
> 
> /vol/gcc/src/hg/master/local/libgomp/task.c: In function 'task_fulfilled_p':
> /vol/gcc/src/hg/master/local/libgomp/task.c:334:1: error: control reaches end 
> of non-void function [-Werror=return-type]
>   334 | }
>   | ^
> 
> task_fulfilled_p is
> 
>   return __atomic_load_n (>completion_sem, __ATOMIC_RELAXED);
> 
> but in config/posix/sem.h gomp_sem_t is (for
> !HAVE_BROKEN_POSIX_SEMAPHORES):
> 
>   typedef sem_t gomp_sem_t;
> 
> and sem_t being a struct in Solaris .

Oops.
I guess we want to add to sem.h some API to query current value of the
semaphore, which could be atomic load for the config/{linux,accel}/sem.h,
sem_getvalue for config/posix/sem.h (does Solaris implement that?)
and dunno what for config/rtems/sem.h.

Kwok, I guess you can reproduce it even on Linux with --disable-linux-futex

Jakub



Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2021-01-17 Thread Rainer Orth
Hi Jakub,

>> I have applied your other suggestions, and have retested the gomp.exp and
>> libgomp tests. The full testrun started yesterday showed no regressions. If
>> you have no further issues then I will commit this later tonight ahead of
>> stage4.
>
> LGTM, thanks.

this patch broke Solaris bootstrap, but probably all non-Linux targets:

/vol/gcc/src/hg/master/local/libgomp/task.c: In function 'task_fulfilled_p':
/vol/gcc/src/hg/master/local/libgomp/task.c:334:1: error: control reaches end 
of non-void function [-Werror=return-type]
  334 | }
  | ^

task_fulfilled_p is

  return __atomic_load_n (>completion_sem, __ATOMIC_RELAXED);

but in config/posix/sem.h gomp_sem_t is (for
!HAVE_BROKEN_POSIX_SEMAPHORES):

  typedef sem_t gomp_sem_t;

and sem_t being a struct in Solaris .

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University