Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> The important difference is for strn{,case}cmp folding, we pass that s2
> value as the last argument to the host functions comparing the c_getstr
> results.  If s2 fits into size_t, then my patch makes no difference,
> but if it is larger, we know the 2 c_getstr objects need to fit into the
> host address space, so larger s2 should just act essentially as strcmp
> or strcasecmp; as none of those objects can occupy 100% of the address
> space, using MIN (SIZE_MAX, s2) achieves that.

But SIZE_MAX is a host value, isn't it?  As a matter of fact, it breaks the 
build with somewhat ancient glibcs:

In file included from ../../src/gcc/fold-const-call.c:21:

../../src/gcc/fold-const-call.c: In function 'tree_node* 
fold_const_call(combined_fn, tree, tree, tree, tree)':

../../src/gcc/fold-const-call.c:1777:56: error: 'SIZE_MAX' was not declared in 
this scope

 1777 |  return build_int_cst (type, strncmp (p0, p1, MIN (s2, SIZE_MAX)));

because /usr/include/stdint.h has:

/* The ISO C99 standard specifies that in C++ implementations these
   macros should only be defined if explicitly requested.  */
#if !defined __cplusplus || defined __STDC_LIMIT_MACROS

-- 
Eric Botcazou




Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 31, 2021 at 01:49:29PM +0100, Eric Botcazou wrote:
> > The important difference is for strn{,case}cmp folding, we pass that s2
> > value as the last argument to the host functions comparing the c_getstr
> > results.  If s2 fits into size_t, then my patch makes no difference,
> > but if it is larger, we know the 2 c_getstr objects need to fit into the
> > host address space, so larger s2 should just act essentially as strcmp
> > or strcasecmp; as none of those objects can occupy 100% of the address
> > space, using MIN (SIZE_MAX, s2) achieves that.
> 
> But SIZE_MAX is a host value, isn't it?  As a matter of fact, it breaks the 

Sure.

> build with somewhat ancient glibcs:
> 
> In file included from ../../src/gcc/fold-const-call.c:21:
> 
> ../../src/gcc/fold-const-call.c: In function 'tree_node* 
> fold_const_call(combined_fn, tree, tree, tree, tree)':
> 
> ../../src/gcc/fold-const-call.c:1777:56: error: 'SIZE_MAX' was not declared 
> in 
> this scope
> 
>  1777 |  return build_int_cst (type, strncmp (p0, p1, MIN (s2, SIZE_MAX)));
> 
> because /usr/include/stdint.h has:
> 
> /* The ISO C99 standard specifies that in C++ implementations these
>macros should only be defined if explicitly requested.  */
> #if !defined __cplusplus || defined __STDC_LIMIT_MACROS

Ugh.  Anyway, we don't really need the SIZE_MAX macro, we can use
INTTYPE_MAXIMUM (size_t) or (~(size_t) 0) too instead of it.

Jakub



[pushed] testsuite, Darwin : Skip ELF-specific tests.

2021-01-31 Thread Iain Sandoe
Hi,

A number of ELF-specific tests were introduced in r11-6140, one
of which fails on all Mach-O/Darwin platforms.

On examination, the tests have no meaningful parallel for Mach-O
which dead strips at the symbol level, and does not make use of
function sections (the fact that a used and an unused symbol are
placed in the same section will not affect dead stripping).

Given that the tests do not demonstrate anything useful on Darwin,
skip them.

tested on x86_64-darwin16 and x86_64-linux,
pushed to master,
thanks
Iain

--

gcc/testsuite/ChangeLog:

* c-c++-common/attr-used-5.c: Skip for Darwin.
* c-c++-common/attr-used-6.c: Likewise.
* c-c++-common/attr-used-7.c: Likewise.
* c-c++-common/attr-used-8.c: Likewise.
* c-c++-common/attr-used-9.c: Likewise.
---
 gcc/testsuite/c-c++-common/attr-used-5.c | 1 +
 gcc/testsuite/c-c++-common/attr-used-6.c | 1 +
 gcc/testsuite/c-c++-common/attr-used-7.c | 1 +
 gcc/testsuite/c-c++-common/attr-used-8.c | 1 +
 gcc/testsuite/c-c++-common/attr-used-9.c | 1 +
 5 files changed, 5 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/attr-used-5.c 
b/gcc/testsuite/c-c++-common/attr-used-5.c
index ba59326e452..5b4924160fd 100644
--- a/gcc/testsuite/c-c++-common/attr-used-5.c
+++ b/gcc/testsuite/c-c++-common/attr-used-5.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-skip-if "non-ELF target" { *-*-darwin* } } */
 /* { dg-options "-Wall -O2" } */
 
 struct dtv_slotinfo_list
diff --git a/gcc/testsuite/c-c++-common/attr-used-6.c 
b/gcc/testsuite/c-c++-common/attr-used-6.c
index 5d20f875bf0..3cf288dd28f 100644
--- a/gcc/testsuite/c-c++-common/attr-used-6.c
+++ b/gcc/testsuite/c-c++-common/attr-used-6.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-skip-if "non-ELF target" { *-*-darwin* } } */
 /* { dg-options "-Wall -O2" } */
 
 struct dtv_slotinfo_list
diff --git a/gcc/testsuite/c-c++-common/attr-used-7.c 
b/gcc/testsuite/c-c++-common/attr-used-7.c
index 75576bcabe5..1721a8afc4e 100644
--- a/gcc/testsuite/c-c++-common/attr-used-7.c
+++ b/gcc/testsuite/c-c++-common/attr-used-7.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-skip-if "non-ELF target" { *-*-darwin* } } */
 /* { dg-options "-Wall -O2" } */
 
 int __attribute__((used,section(".data.foo"))) foo2 = 2;
diff --git a/gcc/testsuite/c-c++-common/attr-used-8.c 
b/gcc/testsuite/c-c++-common/attr-used-8.c
index e4982db1044..20662cadf70 100644
--- a/gcc/testsuite/c-c++-common/attr-used-8.c
+++ b/gcc/testsuite/c-c++-common/attr-used-8.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-skip-if "non-ELF target" { *-*-darwin* } } */
 /* { dg-options "-Wall -O2" } */
 
 int __attribute__((section(".data.foo"))) foo1 = 1;
diff --git a/gcc/testsuite/c-c++-common/attr-used-9.c 
b/gcc/testsuite/c-c++-common/attr-used-9.c
index cf3bde67622..5847b0550ce 100644
--- a/gcc/testsuite/c-c++-common/attr-used-9.c
+++ b/gcc/testsuite/c-c++-common/attr-used-9.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-skip-if "non-ELF target" { *-*-darwin* } } */
 /* { dg-options "-Wall -O2" } */
 
 struct dtv_slotinfo_list
-- 
2.24.1




[PATCH][Bug libstdc++/70303] Value-initialized debug iterators

2021-01-31 Thread François Dumont via Gcc-patches
After the debug issue has been fixed in PR 98466 the problem was not in 
the debug iterator implementation itself but in the deque iterator 
operator- implementation.


    libstdc++: Make deque iterator operator- usable with value-init 
iterators


    N3644 implies that operator- can be used on value-init iterators. 
We now return
    0 if both iterators are value initialized. If only one is value 
initialized we
    keep the UB by returning the result of a normal computation which 
is an unexpected

    value.

    libstdc++/ChangeLog:

    PR libstdc++/70303
    * include/bits/stl_deque.h 
(std::deque<>::operator-(iterator, iterator)):

    Return 0 if both iterators are value-initialized.
    * testsuite/23_containers/deque/70303.cc: New test.
    * testsuite/23_containers/vector/70303.cc: New test.

Tested under Linux x86_64, ok to commit ?

François

diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h
index d41c27717a3..04b70b77621 100644
--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -352,9 +352,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   friend difference_type
   operator-(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
   {
-	return difference_type(_S_buffer_size())
-	  * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
-	  + (__y._M_last - __y._M_cur);
+	if (__builtin_expect(__x._M_node || __y._M_node, true))
+	  return difference_type(_S_buffer_size())
+	* (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
+	+ (__y._M_last - __y._M_cur);
+
+	return 0;
   }
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -366,9 +369,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 	operator-(const _Self& __x,
 		  const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
 	{
-	  return difference_type(_S_buffer_size())
-	* (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
-	+ (__y._M_last - __y._M_cur);
+	  if (__builtin_expect(__x._M_node || __y._M_node, true))
+	return difference_type(_S_buffer_size())
+	  * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
+	  + (__y._M_last - __y._M_cur);
+
+	  return 0;
 	}
 
   friend _Self
diff --git a/libstdc++-v3/testsuite/23_containers/deque/70303.cc b/libstdc++-v3/testsuite/23_containers/deque/70303.cc
new file mode 100644
index 000..e0e63694170
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/70303.cc
@@ -0,0 +1,67 @@
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library 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 this library; see the file COPYING3.  If not see
+// .
+
+// { dg-do run }
+
+#include 
+#include 
+
+// PR libstdc++/70303
+
+void test01()
+{
+  typedef typename std::deque::iterator It;
+  It it = It();
+  VERIFY(it == it);
+  VERIFY(!(it != it));
+  VERIFY(it - it == 0);
+  VERIFY(!(it < it));
+  VERIFY(!(it > it));
+  VERIFY(it <= it);
+  VERIFY(it >= it);
+
+  typedef typename std::deque::const_iterator CIt;
+  CIt cit = CIt();
+  VERIFY(cit == cit);
+  VERIFY(!(cit != cit));
+  VERIFY(cit - cit == 0);
+  VERIFY(!(cit < cit));
+  VERIFY(!(cit > cit));
+  VERIFY(cit <= cit);
+  VERIFY(cit >= cit);
+
+  VERIFY(it == cit);
+  VERIFY(!(it != cit));
+  VERIFY(cit == it);
+  VERIFY(!(cit != it));
+  VERIFY(it - cit == 0);
+  VERIFY(cit - it == 0);
+  VERIFY(!(it < cit));
+  VERIFY(!(it > cit));
+  VERIFY(it <= cit);
+  VERIFY(it >= cit);
+  VERIFY(!(cit < it));
+  VERIFY(!(cit > it));
+  VERIFY(cit <= it);
+  VERIFY(cit >= it);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/vector/70303.cc b/libstdc++-v3/testsuite/23_containers/vector/70303.cc
new file mode 100644
index 000..af18a0503d8
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/70303.cc
@@ -0,0 +1,67 @@
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library 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.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty o

Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 31, 2021 at 02:12:46PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Sun, Jan 31, 2021 at 01:49:29PM +0100, Eric Botcazou wrote:
> > > The important difference is for strn{,case}cmp folding, we pass that s2
> > > value as the last argument to the host functions comparing the c_getstr
> > > results.  If s2 fits into size_t, then my patch makes no difference,
> > > but if it is larger, we know the 2 c_getstr objects need to fit into the
> > > host address space, so larger s2 should just act essentially as strcmp
> > > or strcasecmp; as none of those objects can occupy 100% of the address
> > > space, using MIN (SIZE_MAX, s2) achieves that.
> > 
> > But SIZE_MAX is a host value, isn't it?  As a matter of fact, it breaks the 
> 
> Sure.
> 
> > build with somewhat ancient glibcs:
> > 
> > In file included from ../../src/gcc/fold-const-call.c:21:
> > 
> > ../../src/gcc/fold-const-call.c: In function 'tree_node* 
> > fold_const_call(combined_fn, tree, tree, tree, tree)':
> > 
> > ../../src/gcc/fold-const-call.c:1777:56: error: 'SIZE_MAX' was not declared 
> > in 
> > this scope
> > 
> >  1777 |  return build_int_cst (type, strncmp (p0, p1, MIN (s2, SIZE_MAX)));
> > 
> > because /usr/include/stdint.h has:
> > 
> > /* The ISO C99 standard specifies that in C++ implementations these
> >macros should only be defined if explicitly requested.  */
> > #if !defined __cplusplus || defined __STDC_LIMIT_MACROS
> 
> Ugh.  Anyway, we don't really need the SIZE_MAX macro, we can use
> INTTYPE_MAXIMUM (size_t) or (~(size_t) 0) too instead of it.

In patch form now (for ~ we'd need to use (size_t) ~(size_t) 0 to be
fully portable, I think nothing in the standard requires that size_t isn't
e.g. unsigned char or unsigned short that would then promote to int.

Ok for trunk?

2021-01-31  Jakub Jelinek  

* fold-const-call.c (fold_const_call): Use INTTYPE_MAXIMUM (size_t)
instead of SIZE_MAX.

--- gcc/fold-const-call.c.jj2021-01-25 10:03:30.855413068 +0100
+++ gcc/fold-const-call.c   2021-01-31 18:37:04.022539076 +0100
@@ -1777,7 +1777,9 @@ fold_const_call (combined_fn fn, tree ty
  && !TREE_SIDE_EFFECTS (arg1))
return build_int_cst (type, 0);
   else if ((p0 = c_getstr (arg0)) && (p1 = c_getstr (arg1)))
-   return build_int_cst (type, strncmp (p0, p1, MIN (s2, SIZE_MAX)));
+   return build_int_cst (type,
+ strncmp (p0, p1,
+  MIN (s2, INTTYPE_MAXIMUM (size_t;
   return NULL_TREE;
 
 case CFN_BUILT_IN_STRNCASECMP:
@@ -1789,7 +1791,7 @@ fold_const_call (combined_fn fn, tree ty
return build_int_cst (type, 0);
   else if ((p0 = c_getstr (arg0))
   && (p1 = c_getstr (arg1))
-  && strncmp (p0, p1, MIN (s2, SIZE_MAX)) == 0)
+  && strncmp (p0, p1, MIN (s2, INTTYPE_MAXIMUM (size_t))) == 0)
return build_int_cst (type, 0);
   return NULL_TREE;
 


Jakub



Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> In patch form now (for ~ we'd need to use (size_t) ~(size_t) 0 to be
> fully portable, I think nothing in the standard requires that size_t isn't
> e.g. unsigned char or unsigned short that would then promote to int.
> 
> Ok for trunk?
> 
> 2021-01-31  Jakub Jelinek  
> 
>   * fold-const-call.c (fold_const_call): Use INTTYPE_MAXIMUM (size_t)
>   instead of SIZE_MAX.

Why not just:

#ifndef SIZE_MAX
# define SIZE_MAX INTTYPE_MAXIMUM (size_t)
#endif

just below UCHAR_MAX in system.h?

-- 
Eric Botcazou




Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> Why not just:
> 
> #ifndef SIZE_MAX
> # define SIZE_MAX INTTYPE_MAXIMUM (size_t)
> #endif
> 
> just below UCHAR_MAX in system.h?

Or rather just below

#ifdef HAVE_STDINT_H
#include 
#endif

#ifdef HAVE_INTTYPES_H
#include 
#endif

-- 
Eric Botcazou




Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 31, 2021 at 07:07:32PM +0100, Eric Botcazou wrote:
> > Why not just:
> > 
> > #ifndef SIZE_MAX
> > # define SIZE_MAX INTTYPE_MAXIMUM (size_t)
> > #endif
> > 
> > just below UCHAR_MAX in system.h?
> 
> Or rather just below
> 
> #ifdef HAVE_STDINT_H
> #include 
> #endif
> 
> #ifdef HAVE_INTTYPES_H
> #include 
> #endif

If it doesn't break anything (note, there can be system headers included
even after this spot), why not.

Note, it now affects GCC 10 branch too.

Jakub



Re: [PATCH] RISC-V: Fix -march option parsing when `p` extension exists.

2021-01-31 Thread Andreas Schwab
FAIL: gcc.target/riscv/attribute-18.c scan-assembler .attribute arch, 
"rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_p"

$ grep -c 'attribute arch' attribute-18.s 
0

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] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> If it doesn't break anything (note, there can be system headers included
> even after this spot), why not.

OK, then maybe move them to the end.  Or define

#define __STDC_LIMIT_MACROS

just before the two aforementioned includes, so that this doesn't happen again 
with another macro.

> Note, it now affects GCC 10 branch too.

Yep, that's where it breaks things for us. :-)

-- 
Eric Botcazou




Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 31, 2021 at 07:07:32PM +0100, Eric Botcazou wrote:
> > Why not just:
> > 
> > #ifndef SIZE_MAX
> > # define SIZE_MAX INTTYPE_MAXIMUM (size_t)
> > #endif
> > 
> > just below UCHAR_MAX in system.h?
> 
> Or rather just below
> 
> #ifdef HAVE_STDINT_H
> #include 
> #endif
> 
> #ifdef HAVE_INTTYPES_H
> #include 
> #endif

Whatever works, I can't test such patches except on Linux, so can you just
create a patch and test it on Solaris where it failed before?

Jakub



Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> Whatever works, I can't test such patches except on Linux, so can you just
> create a patch and test it on Solaris where it failed before?

It fails on old Linux distros, e.g. RHES 5, not on Solaris as far as I know.

-- 
Eric Botcazou




Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> Whatever works, I can't test such patches except on Linux, so can you just
> create a patch and test it on Solaris where it failed before?

Maybe a safer fix is the attached one.  Tested on old RedHat and SuSE distros.


* fold-const-call.c: Define __STDC_LIMIT_MACROS at the top.

-- 
Eric Botcazoudiff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c
index da01759d9c8..c5f5566fa06 100644
--- a/gcc/fold-const-call.c
+++ b/gcc/fold-const-call.c
@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#define __STDC_LIMIT_MACROS /* For SIZE_MAX in C++.  */
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"


Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 31, 2021 at 09:19:07PM +0100, Eric Botcazou wrote:
> > Whatever works, I can't test such patches except on Linux, so can you just
> > create a patch and test it on Solaris where it failed before?
> 
> Maybe a safer fix is the attached one.  Tested on old RedHat and SuSE distros.
> 
> 
>   * fold-const-call.c: Define __STDC_LIMIT_MACROS at the top.

But next time we use SIZE_MAX somewhere it is going to break again this way.
If we just define SIZE_MAX if not defined after all includes in system.h, I
think it is better than this.

> diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c
> index da01759d9c8..c5f5566fa06 100644
> --- a/gcc/fold-const-call.c
> +++ b/gcc/fold-const-call.c
> @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public 
> License
>  along with GCC; see the file COPYING3.  If not see
>  .  */
>  
> +#define __STDC_LIMIT_MACROS /* For SIZE_MAX in C++.  */
> +
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"


Jakub



Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Eric Botcazou
> But next time we use SIZE_MAX somewhere it is going to break again this way.
> If we just define SIZE_MAX if not defined after all includes in system.h, I
> think it is better than this.

The existing practice seems to define the missing constants right after the 
corresponding include, e.g. MAP_FAILED, so I have successfully tested this.


* system.h (SIZE_MAX): Define if not already defined.

-- 
Eric Botcazoudiff --git a/gcc/system.h b/gcc/system.h
index d04f8fd3360..a2218834b43 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -528,6 +528,10 @@ extern void *realloc (void *, size_t);
 #include 
 #endif
 
+#ifndef SIZE_MAX
+# define SIZE_MAX INTTYPE_MAXIMUM (size_t)
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif


Re: [PATCH] fold: Fix up strn{case,}cmp folding [PR98771]

2021-01-31 Thread Jakub Jelinek via Gcc-patches
On Sun, Jan 31, 2021 at 10:48:53PM +0100, Eric Botcazou wrote:
> > But next time we use SIZE_MAX somewhere it is going to break again this way.
> > If we just define SIZE_MAX if not defined after all includes in system.h, I
> > think it is better than this.
> 
> The existing practice seems to define the missing constants right after the 
> corresponding include, e.g. MAP_FAILED, so I have successfully tested this.
> 
> 
>   * system.h (SIZE_MAX): Define if not already defined.
> 
> -- 
> Eric Botcazou

> diff --git a/gcc/system.h b/gcc/system.h
> index d04f8fd3360..a2218834b43 100644
> --- a/gcc/system.h
> +++ b/gcc/system.h
> @@ -528,6 +528,10 @@ extern void *realloc (void *, size_t);
>  #include 
>  #endif
>  
> +#ifndef SIZE_MAX
> +# define SIZE_MAX INTTYPE_MAXIMUM (size_t)
> +#endif
> +
>  #ifdef __cplusplus
>  extern "C" {
>  #endif

Ok, thanks.


Jakub



[PATCH] run -Wnonnull later (PR 87489)

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

The initial -Wnonnull implementation in the middle end took place
too late in the pipeline (just before expansion), and as a result
was prone to false positives (bug 78817).  In an attempt to avoid
the worst of those, the warning was moved to the ccp2 pass in
r243874.  However, as the test case in PR 87489 shows, this is
in turn too early and causes other false positives as a result.

A few experiments with running the warning later suggest that
just before the mergephi2 pass is a good point to avoid this class
of false positives without causing any regressions or introducing
any new warnings either in Glibc or in Binutils/GDB.

Since PR 87489 is a GCC 8-11 regression I propose to make this
change on the trunk as well as on the release branches.

Martin
PR middle-end/87489 - Spurious -Wnonnull warning on bitwise arithmetic and inlining

gcc/ChangeLog:

	PR middle-end/87489
	* passes.def (pass_post_ipa_warn): Move later.

gcc/testsuite/ChangeLog:

	PR middle-end/87489
	* gcc.dg/Wnonnull-6.c: New test.
	* gcc.dg/Wnonnull-7.c: New test.

diff --git a/gcc/passes.def b/gcc/passes.def
index e9ed3c7bc57..5e5a012943a 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -194,7 +194,6 @@ along with GCC; see the file COPYING3.  If not see
 	 They ensure memory accesses are not indirect wherever possible.  */
   NEXT_PASS (pass_strip_predict_hints, false /* early_p */);
   NEXT_PASS (pass_ccp, true /* nonzero_p */);
-  NEXT_PASS (pass_post_ipa_warn);
   /* After CCP we rewrite no longer addressed locals into SSA
 	 form if possible.  */
   NEXT_PASS (pass_complete_unrolli);
@@ -207,6 +206,7 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_build_alias);
   NEXT_PASS (pass_return_slot);
   NEXT_PASS (pass_fre, true /* may_iterate */);
+  NEXT_PASS (pass_post_ipa_warn);
   NEXT_PASS (pass_merge_phi);
   NEXT_PASS (pass_thread_jumps);
   NEXT_PASS (pass_vrp, true /* warn_array_bounds_p */);
@@ -368,7 +368,6 @@ along with GCC; see the file COPYING3.  If not see
   NEXT_PASS (pass_lower_switch);
   /* Perform simple scalar cleanup which is constant/copy propagation.  */
   NEXT_PASS (pass_ccp, true /* nonzero_p */);
-  NEXT_PASS (pass_post_ipa_warn);
   NEXT_PASS (pass_object_sizes);
   /* Fold remaining builtins.  */
   NEXT_PASS (pass_fold_builtins);
@@ -377,6 +376,7 @@ along with GCC; see the file COPYING3.  If not see
  to forward object-size and builtin folding results properly.  */
   NEXT_PASS (pass_copy_prop);
   NEXT_PASS (pass_dce);
+  NEXT_PASS (pass_post_ipa_warn);
   NEXT_PASS (pass_sancov);
   NEXT_PASS (pass_asan);
   NEXT_PASS (pass_tsan);
diff --git a/gcc/testsuite/gcc.dg/Wnonnull-6.c b/gcc/testsuite/gcc.dg/Wnonnull-6.c
new file mode 100644
index 000..507e7979cd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wnonnull-6.c
@@ -0,0 +1,25 @@
+/* PR middle-end/87489 - Spurious -Wnonnull warning on bitwise arithmetic
+   and inlining
+   { dg-do compile }
+   { dg-options "-O1 -Wall" } */
+
+extern void f (const void*, int);
+
+static void g (int i, const char *s)
+{
+  int j = 0;
+
+  if (i)
+j |= 1;
+
+  if (j)
+f (&j, 0);
+
+  if (j & 1)
+f (s, __builtin_strlen (s));// { dg-bogus "\\\[-Wnonnull" }
+}
+
+void h (void)
+{
+  g (0, 0);
+}
diff --git a/gcc/testsuite/gcc.dg/Wnonnull-7.c b/gcc/testsuite/gcc.dg/Wnonnull-7.c
new file mode 100644
index 000..d801ca2329d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wnonnull-7.c
@@ -0,0 +1,6 @@
+/* PR middle-end/87489 - Spurious -Wnonnull warning on bitwise arithmetic
+   and inlining
+   { dg-do compile }
+   { dg-options "-Og -Wall" } */
+
+#include "Wnonnull-6.c"


Re: [PATCH] adjust "partly out of bounds" warning (PR 98503)

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

On 1/30/21 12:36 AM, Eric Gallager wrote:

On Thu, Jan 28, 2021 at 6:04 PM Martin Sebor via Gcc-patches
 wrote:


The GCC 11 -Warray-bounds enhancement to diagnose accesses whose
leading offset is in bounds but whose trailing offset is not has
been causing some confusion.  When the warning is issued for
an access to an in-bounds member via a pointer to a struct that's
larger than the pointed-to object, phrasing this strictly invalid
access in terms of array subscripts can be misleading, especially
when the source code doesn't involve any arrays or indexing.

Since the problem boils down to an aliasing violation much more
so than an actual out-of-bounds access, the attached patch adjusts
the code to issue a -Wstrict-aliasing warning in these cases instead
of -Warray-bounds.  In addition, since the aliasing assumptions in
GCC can be disabled by -fno-strict-aliasing, the patch also makes
these instances of the warning conditional on -fstrict-aliasing
being in effect.

Martin


-Wstrict-aliasing is a warning with numerical levels; can you clarify
which of them this is active at?


It runs at the default level 3.


(also I have always found it confusing how -Wstrict-aliasing's
numerical levels are in reverse order from most other warnings with
numerical levels; i.e., how higher numbers supposedly mean fewer
warnings for it (according to documentation) rather than more, as is
the case with most other warnings with numerical levels)



The description does seem a little counter-intuitive.  The warning
runs in the front ends and the analysis functions it calls at level
3 have the same complexity as at level 1 so I'm not sure I understand
the point of the levels.  I'd be surprised if anyone used anything
but the default.

Martin


Re: [PATCH] RISC-V: Fix -march option parsing when `p` extension exists.

2021-01-31 Thread Xing GUO via Gcc-patches
Hi Andreas and Kito,

I haven't reproduced this failure, but it looks that I forget to
append `-mriscv-attribute` to dg-options in attribute-18.c. I'll reply
to this thread ASAP.

Thanks,
Xing

On 2/1/21, Andreas Schwab  wrote:
> FAIL: gcc.target/riscv/attribute-18.c scan-assembler .attribute arch,
> "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_p"
>
> $ grep -c 'attribute arch' attribute-18.s
> 0
>
> 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."
>


-- 
Cheers,
Xing


Re: [PATCH 3/8] [RS6000] rs6000_rtx_costs tidy AND

2021-01-31 Thread Alan Modra via Gcc-patches
On Mon, Jan 25, 2021 at 04:37:21PM -0600, Segher Boessenkool wrote:
> I still do not see what this improves, I only see possible obvious
> regressions :-(

You asked me to break the patch series into small pieces, for ease of
review and to separate tidies from functional changes.  Well OK, fair
enough.  This is one of the tidies.  The idea being to make
rs6000_rtx_costs a little more self-consistent, to not have someone
look at this code in the future and wonder why AND was treated
differently to other operations.

The only part of this patch that I can imagine you see as a possible
regression is the "Don't avoid recursion on const_int shift count"
part.  That is there only because you wanted it that way in new code.
I think you said something about premature optimisation when I made
the new code special case const_int and reg to stop recursion, like
AND.  So for consistency I made the change in old code too.

-- 
Alan Modra
Australia Development Lab, IBM


Re: [PATCH 5/8] [RS6000] rs6000_rtx_costs cost IOR

2021-01-31 Thread Alan Modra via Gcc-patches
On Mon, Jan 25, 2021 at 04:51:43PM -0600, Segher Boessenkool wrote:
> Hi!
> 
> On Thu, Oct 08, 2020 at 09:27:57AM +1030, Alan Modra wrote:
> > * config/rs6000/rs6000.c (rotate_insert_cost): New function.
> > (rs6000_rtx_costs): Cost IOR.
> > 
> > diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> > index 383d2901c9f..15a806fe307 100644
> > --- a/gcc/config/rs6000/rs6000.c
> > +++ b/gcc/config/rs6000/rs6000.c
> > @@ -21206,6 +21206,91 @@ rs6000_cannot_copy_insn_p (rtx_insn *insn)
> >  && get_attr_cannot_copy (insn);
> >  }
> >  
> > +/* Handle rtx_costs for scalar integer rotate and insert insns.  */
> 
> You need to document here what the return value means, and what the
> preconditions for "left" (and "right") are.

Done, and I moved the preconditions on "left" into the new function.

> > +static bool
> > +rotate_insert_cost (rtx left, rtx right, machine_mode mode, bool speed,
> > +   int *total)
> > +{
> > +  if (GET_CODE (right) == AND
> 
> ... because you never check the CODE of "left".
> 
> > +  && CONST_INT_P (XEXP (right, 1))
> > +  && UINTVAL (XEXP (left, 1)) + UINTVAL (XEXP (right, 1)) + 1 == 0)
> 
> HOST_WIDE_INT is always exactly 64 bits now, so you could do "== -1".

Yes, but this is exactly the way the expression occurs in rotl*_insert*
instruction patterns.  I think it's better to keep them the same.

> > +{
> > +  rtx leftop = XEXP (left, 0);
> > +  rtx rightop = XEXP (right, 0);
> > +
> > +  /* rotlsi3_insert_5.  */
> > +  if (REG_P (leftop)
> > + && REG_P (rightop)
> > + && mode == SImode
> > + && UINTVAL (XEXP (left, 1)) != 0
> > + && UINTVAL (XEXP (right, 1)) != 0
> > + && rs6000_is_valid_mask (XEXP (left, 1), NULL, NULL, mode))
> > +   return true;
> 
> Empty line after return please.

Done, here and elsewhere.

> > +  /* rotldi3_insert_6.  */
> > +  if (REG_P (leftop)
> > + && REG_P (rightop)
> > + && mode == DImode
> > + && exact_log2 (-UINTVAL (XEXP (left, 1))) > 0)
> > +   return true;
> > +  /* rotldi3_insert_7.  */
> > +  if (REG_P (leftop)
> > + && REG_P (rightop)
> > + && mode == DImode
> > + && exact_log2 (-UINTVAL (XEXP (right, 1))) > 0)
> > +   return true;
> 
> Those could just use rs6000_is_valid_mask as well?

This is taken straight from rotldi3_insert_7, so it really ought to
stay that way.

> 
> Please wait this until stage 1.  Sorry.

OK, I'll leave all the rs6000_rtx_costs changes until then.

-- 
Alan Modra
Australia Development Lab, IBM


[PATCH] testsuite: Update pr79251 ilp32 store regex.

2021-01-31 Thread Xionghu Luo via Gcc-patches
BE ilp32 Linux generates extra stack stwu instructions which shouldn't
be counted in, \m … \M is needed around each instruction, not just the
beginning and end of the entire pattern. Pre-approved, committing.

gcc/testsuite/ChangeLog:

2021-02-01  Xionghu Luo  

* gcc.target/powerpc/pr79251.p8.c: Update regex.
* gcc.target/powerpc/pr79251.p9.c: Likewise.
---
 gcc/testsuite/gcc.target/powerpc/pr79251.p8.c | 2 +-
 gcc/testsuite/gcc.target/powerpc/pr79251.p9.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/powerpc/pr79251.p8.c 
b/gcc/testsuite/gcc.target/powerpc/pr79251.p8.c
index b0e7732a38b..178e02fc866 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr79251.p8.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr79251.p8.c
@@ -16,7 +16,7 @@
 /* { dg-final { scan-assembler-times {\mrlwinm\M} 10 { target ilp32 } } } */
 /* { dg-final { scan-assembler-times {\mstxvw4x\M} 6 { target ilp32 } } } */
 /* { dg-final { scan-assembler-times {\mstxvd2x\M} 4 { target ilp32 } } } */
-/* { dg-final { scan-assembler-times {\mstb|sth|stw|stfs|stfd\M} 12 { target 
ilp32 } } } */
+/* { dg-final { scan-assembler-times 
{\mstb\M|\msth\M|\mstw\M|\mstfs\M|\mstfd\M} 12 { target ilp32 } } } */
 /* { dg-final { scan-assembler-times {\mlxvw4x\M} 6 { target ilp32 } } } */
 /* { dg-final { scan-assembler-times {\mlxvd2x\M} 4 { target ilp32 } } } */
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr79251.p9.c 
b/gcc/testsuite/gcc.target/powerpc/pr79251.p9.c
index cedb0bf7da8..2ae2da8c72e 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr79251.p9.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr79251.p9.c
@@ -17,6 +17,6 @@
 
 /* { dg-final { scan-assembler-times {\mrlwinm\M} 10 { target ilp32 } } } */
 /* { dg-final { scan-assembler-times {\mstxv\M} 10 { target ilp32 } } } */
-/* { dg-final { scan-assembler-times {\mstb|sth|stw|stfs|stfd\M} 12 { target 
ilp32 } } } */
+/* { dg-final { scan-assembler-times 
{\mstb\M|\msth\M|\mstw\M|\mstfs\M|\mstfd\M} 12 { target ilp32 } } } */
 /* { dg-final { scan-assembler-times {\mlxv\M} 10 { target ilp32 } } } */
 
-- 
2.25.1