[PATCH] Fix non-conforming expander [PR target/95211, PR target/95256]

2020-05-23 Thread Hongtao Liu via Gcc-patches
Hi:
  This patch fix non-conforming expander for
floatv2div2sf2,floatunsv2div2sf2,fix_truncv2sfv2di,fixuns_truncv2sfv2di,
refer to PR95211, PR95256.
  bootstrap ok, regression test on i386/x86-64 backend is ok.

gcc/ChangeLog:
PR target/95211 PR target/95256
* config/i386/sse.md v2div2sf2): New expander.
(fix_truncv2sfv2di2): Ditto.
(floatv2div2sf2_internal): Renaming from
floatv2div2sf2.
(fix_truncv2sfv2di2_internal):
Renaming from fix_truncv2sfv2di2.
(vec_pack_float_): Adjust icode name.
(vec_unpack_fix_trunc_lo_): Ditto.
* config/i386/i386-builtin.def: Ditto.


-- 
BR,
Hongtao


0001-Fix-non-comforming-expander-for.patch
Description: Binary data


[committed 0/3] libstdc++: Refactor filesystem::path string conversions

2020-05-23 Thread Jonathan Wakely via Gcc-patches

This is a series of three patches to simplify the logic used to
construct a std::filesystem::path from strings/ranges of arbitrary
characters, and fix one bug.

The simpler logic also avoids some unnecessary string constructions
when a string view could be used instead. Previously a string view was
only used for strings and pairs of pointers. Now contiguous iterators
will be detected (using the concept in C++20, or by handling the
__normal_iterator wrapper in C++17).

The bug fix should be backported, the rest would be safe but doesn't
need to be.



[committed 1/3] libstdc++: Simplify filesystem::path SFINAE constraints

2020-05-23 Thread Jonathan Wakely via Gcc-patches

This replaces the filesystem::__detail::_Path SFINAE helper with two
separate helpers, _Path and _Path2. This avoids having one helper which
tries to check two different sets of requirements.

The _Path helper now uses variable templates instead of a set of
overloaded functions to detect specializations of basic_string or
basic_string_view.

The __not_> check is not necessary in
C++20 because iterator_traits is now empty. For C++17 replace
that check with a __safe_iterator_traits helper with partial
specializations for void pointers.

Finally, the __is_encoded_char check no longer uses remove_const_t,
which means that iterators with a const value_type will no longer be
accepted as arguments for path creation. Such iterators resulted in
undefined behaviour anyway, so it's still conforming to reject them in
the constraint checks.

* include/bits/fs_path.h (filesystem::__detail::__is_encoded_char):
Replace alias template with variable template. Don't remove const.
(filesystem::__detail::__is_path_src): Replace overloaded function
template with variable template and specializations.
(filesystem::__detail::__is_path_iter_src): Replace alias template
with class template.
(filesystem::__detail::_Path): Use __is_path_src. Remove support for
iterator pairs.
(filesystem::__detail::_Path2): New alias template for checking
InputIterator requirements.
(filesystem::__detail::__constructible_from): Remove.
(filesystem::path): Replace _Path with _Path2.
* testsuite/27_io/filesystem/path/construct/80762.cc: Check with two
constructor arguments of void and void* types.

Tested powerpc64le-linux, committed to master.

commit 988b853f9c829742907ae22ac66de56facfc7bc5
Author: Jonathan Wakely 
Date:   Sat May 23 07:28:40 2020 +0100

libstdc++: Simplify filesystem::path SFINAE constraints

This replaces the filesystem::__detail::_Path SFINAE helper with two
separate helpers, _Path and _Path2. This avoids having one helper which
tries to check two different sets of requirements.

The _Path helper now uses variable templates instead of a set of
overloaded functions to detect specializations of basic_string or
basic_string_view.

The __not_> check is not necessary in
C++20 because iterator_traits is now empty. For C++17 replace
that check with a __safe_iterator_traits helper with partial
specializations for void pointers.

Finally, the __is_encoded_char check no longer uses remove_const_t,
which means that iterators with a const value_type will no longer be
accepted as arguments for path creation. Such iterators resulted in
undefined behaviour anyway, so it's still conforming to reject them in
the constraint checks.

* include/bits/fs_path.h (filesystem::__detail::__is_encoded_char):
Replace alias template with variable template. Don't remove const.
(filesystem::__detail::__is_path_src): Replace overloaded function
template with variable template and specializations.
(filesystem::__detail::__is_path_iter_src): Replace alias template
with class template.
(filesystem::__detail::_Path): Use __is_path_src. Remove support for
iterator pairs.
(filesystem::__detail::_Path2): New alias template for checking
InputIterator requirements.
(filesystem::__detail::__constructible_from): Remove.
(filesystem::path): Replace _Path with _Path2.
* testsuite/27_io/filesystem/path/construct/80762.cc: Check with two
constructor arguments of void and void* types.

diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index ee6ab15cc4c..5a998284a99 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -73,58 +73,87 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 namespace __detail
 {
   template
-using __is_encoded_char = __is_one_of,
-	  char,
+inline constexpr bool __is_encoded_char = false;
+  template<>
+inline constexpr bool __is_encoded_char = true;
 #ifdef _GLIBCXX_USE_CHAR8_T
-	  char8_t,
+  template<>
+inline constexpr bool __is_encoded_char = true;
 #endif
 #if _GLIBCXX_USE_WCHAR_T
-	  wchar_t,
+  template<>
+inline constexpr bool __is_encoded_char = true;
 #endif
-	  char16_t, char32_t>;
-
-  template>
-using __is_path_iter_src
-  = __and_<__is_encoded_char,
-	   std::is_base_of>;
+  template<>
+inline constexpr bool __is_encoded_char = true;
+  template<>
+inline constexpr bool __is_encoded_char = true;
 
+#if __cpp_concepts >= 201907L
   template
-static __is_path_iter_src<_Iter>
-__is_path_src(_Iter, int);
-
-  template
-static __is_encoded_char<_CharT>
-__is_path_src(const basic_string<_CharT, _Traits, _Alloc>&, int);
-
-  template
-static __is_encoded_char<_CharT>
-

[committed 2/3] libstdc++: Remove incorrect static specifiers

2020-05-23 Thread Jonathan Wakely via Gcc-patches

These functions were originally static members of the path class, but
the 'static' specifiers were not removed when they were moved to
namespace scope. This causes ODR violations when the functions are
called from functions defined in the header, which is incompatible with
Nathan's modules branch.  Change them to 'inline' instead.

* include/bits/fs_path.h (__detail::_S_range_begin)
(__detail::_S_range_end): Remove unintentional static specifiers.
* include/experimental/bits/fs_path.h (__detail::_S_range_begin)
(__detail::_S_range_end): Likewise.

Tested powerpc64le-linux, committed to master.


commit 00c8f2a5e3a21d93a03182cacbae4badc02a37f1
Author: Jonathan Wakely 
Date:   Sat May 23 09:00:16 2020 +0100

libstdc++: Remove incorrect static specifiers

These functions were originally static members of the path class, but
the 'static' specifiers were not removed when they were moved to
namespace scope. This causes ODR violations when the functions are
called from functions defined in the header, which is incompatible with
Nathan's modules branch.  Change them to 'inline' instead.

* include/bits/fs_path.h (__detail::_S_range_begin)
(__detail::_S_range_end): Remove unintentional static specifiers.
* include/experimental/bits/fs_path.h (__detail::_S_range_begin)
(__detail::_S_range_end): Likewise.

diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index 5a998284a99..818b5918927 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -156,32 +156,32 @@ namespace __detail
 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>::value, path>;
 
   template
-static _Source
+_Source
 _S_range_begin(_Source __begin) { return __begin; }
 
   struct __null_terminated { };
 
   template
-static __null_terminated
+__null_terminated
 _S_range_end(_Source) { return {}; }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_begin(const basic_string<_CharT, _Traits, _Alloc>& __str)
 { return __str.data(); }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_end(const basic_string<_CharT, _Traits, _Alloc>& __str)
 { return __str.data() + __str.size(); }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_begin(const basic_string_view<_CharT, _Traits>& __str)
 { return __str.data(); }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_end(const basic_string_view<_CharT, _Traits>& __str)
 { return __str.data() + __str.size(); }
 
diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h
index d7234c08a00..69b823a3466 100644
--- a/libstdc++-v3/include/experimental/bits/fs_path.h
+++ b/libstdc++-v3/include/experimental/bits/fs_path.h
@@ -137,33 +137,33 @@ namespace __detail
 		 path>::type;
 
   template
-static _Source
+inline _Source
 _S_range_begin(_Source __begin) { return __begin; }
 
   struct __null_terminated { };
 
   template
-static __null_terminated
+inline __null_terminated
 _S_range_end(_Source) { return {}; }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_begin(const basic_string<_CharT, _Traits, _Alloc>& __str)
 { return __str.data(); }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_end(const basic_string<_CharT, _Traits, _Alloc>& __str)
 { return __str.data() + __str.size(); }
 
 #if __cplusplus >= 201402L
   template
-static const _CharT*
+inline const _CharT*
 _S_range_begin(const basic_string_view<_CharT, _Traits>& __str)
 { return __str.data(); }
 
   template
-static const _CharT*
+inline const _CharT*
 _S_range_end(const basic_string_view<_CharT, _Traits>& __str)
 { return __str.data() + __str.size(); }
 #endif


[committed 3/3] libstdc++: Refactor filesystem::path string conversions

2020-05-23 Thread Jonathan Wakely via Gcc-patches

This simplifies the logic of converting Source arguments and pairs of
InputIterator arguments into the native string format. For any input
that is a contiguous range of path::value_type (or char8_t for POSIX)
a string view can be created and the conversion can be done directly,
with no intermediate allocation. Previously some cases created a
basic_string unnecessarily, for example construction from a pair of
path::string_type::iterators, or a pair of non-const value_type*
pointers.

* include/bits/fs_path.h (__detail::_S_range_begin)
(__detail::_S_range_end, path::_S_string_from_iter): Replace with
overloaded function template __detail::__effective_range.
(__detail::__effective_range): New overloaded function template to
create a basic_string or basic_string_view for an effective range.
(__detail::__value_type_is_char): Use __detail::__effective_range.
Do not use remove_const on value type.
(__detail::__value_type_is_char_or_char8_t): Likewise.
(path::path(const Source&, format))
(path::path(const Source&, const locale&))
(path::operator/=(const Source&), path::append(const Source&))
(path::concat(const Source&)): Use __detail::__effective_range.
(path::_S_to_string(InputIterator, InputIterator)): New function
template to create a string view if possible, or string otherwise.
(path::_S_convert): Add overloads that convert a string returned
by __detail::__effective_range. Use if-constexpr to inline conversion
logic from all overloads of _Cvt::_S_convert.
(path::_S_convert_loc): Add overload that converts a string. Use
_S_to_string to avoid allocation when possible.
(path::_Cvt): Remove.
(path::operator+=(CharT)): Remove indirection through path::concat.
* include/experimental/bits/fs_path.h (path::_S_convert_loc): Add
overload for non-const pointers, to avoid constructing a std::string.
* src/c++17/fs_path.cc (path::_S_convert_loc): Replace conditional
compilation with call to _S_convert.


Tested powerpc64le-linux, committed to master.


commit 584d52b088f9fcf78704b504c3f1f07e17c1cded
Author: Jonathan Wakely 
Date:   Sat May 23 09:00:32 2020 +0100

libstdc++: Refactor filesystem::path string conversions

This simplifies the logic of converting Source arguments and pairs of
InputIterator arguments into the native string format. For any input
that is a contiguous range of path::value_type (or char8_t for POSIX)
a string view can be created and the conversion can be done directly,
with no intermediate allocation. Previously some cases created a
basic_string unnecessarily, for example construction from a pair of
path::string_type::iterators, or a pair of non-const value_type*
pointers.

* include/bits/fs_path.h (__detail::_S_range_begin)
(__detail::_S_range_end, path::_S_string_from_iter): Replace with
overloaded function template __detail::__effective_range.
(__detail::__effective_range): New overloaded function template to
create a basic_string or basic_string_view for an effective range.
(__detail::__value_type_is_char): Use __detail::__effective_range.
Do not use remove_const on value type.
(__detail::__value_type_is_char_or_char8_t): Likewise.
(path::path(const Source&, format))
(path::path(const Source&, const locale&))
(path::operator/=(const Source&), path::append(const Source&))
(path::concat(const Source&)): Use __detail::__effective_range.
(path::_S_to_string(InputIterator, InputIterator)): New function
template to create a string view if possible, or string otherwise.
(path::_S_convert): Add overloads that convert a string returned
by __detail::__effective_range. Use if-constexpr to inline conversion
logic from all overloads of _Cvt::_S_convert.
(path::_S_convert_loc): Add overload that converts a string. Use
_S_to_string to avoid allocation when possible.
(path::_Cvt): Remove.
(path::operator+=(CharT)): Remove indirection through path::concat.
* include/experimental/bits/fs_path.h (path::_S_convert_loc): Add
overload for non-const pointers, to avoid constructing a std::string.
* src/c++17/fs_path.cc (path::_S_convert_loc): Replace conditional
compilation with call to _S_convert.

diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index 818b5918927..2d2766ec62e 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -155,56 +155,61 @@ namespace __detail
   template>
 using _Path2 = enable_if_t<__is_path_iter_src<_Tr>::value, path>;
 
-  template
-_Source
-_S_range_begin(_Source _

Re: [PATCH] Fix non-conforming expander [PR target/95211, PR target/95256]

2020-05-23 Thread Uros Bizjak via Gcc-patches
On Sat, May 23, 2020 at 9:25 AM Hongtao Liu  wrote:
>
> Hi:
>   This patch fix non-conforming expander for
> floatv2div2sf2,floatunsv2div2sf2,fix_truncv2sfv2di,fixuns_truncv2sfv2di,
> refer to PR95211, PR95256.
>   bootstrap ok, regression test on i386/x86-64 backend is ok.
>
> gcc/ChangeLog:
> PR target/95211 PR target/95256

Please put every PR reference in a separate line.

> * config/i386/sse.md v2div2sf2): New expander.
> (fix_truncv2sfv2di2): Ditto.
> (floatv2div2sf2_internal): Renaming from
> floatv2div2sf2.
> (fix_truncv2sfv2di2_internal):

The convention throughout sse,md is to prefix a standard pattern that
is used through builtins with avx512_ instead of suffixing
the pattern name with _internal.

> Renaming from fix_truncv2sfv2di2.
> (vec_pack_float_): Adjust icode name.
> (vec_unpack_fix_trunc_lo_): Ditto.
> * config/i386/i386-builtin.def: Ditto.

Uros.


Re: [PATCH] Extend std::copy/std::copy_n char* overload to deque iterator

2020-05-23 Thread François Dumont via Gcc-patches

On 22/05/20 10:57 pm, François Dumont wrote:

On 21/05/20 2:17 pm, Jonathan Wakely wrote:


Why is the optimization not done for C++03 mode?

I did it this way because the new std::copy overload rely on 
std::copy_n implementation details which is a C++11 algo.




It looks like the uses of 'auto' can be reaplced easily, and
__enable_if_t<> can be replaced with __gnu_cxx::__enable_if<>::__type.


But yes, we can indeed provide those implementation details in pre-C++11.

This is what I've done in this new version.



Note that I expose all __copy_n_a overloads in stl_algobase.h and not 
only the overload needed for the std::copy. Let me know if you prefer to 
limit it.





Tested under Linux x86_64 in default c++ mode.

I tried to use CXXFLAGS=-std=c++03 but it doesn't seem to work even if 
I do see the option in build logs. I remember you adivised a different 
approach, can you tell me again ?


François

I forgot to mention that "doesn't seem to work" above means that all 
C++11 or higher tests are reported as FAIL in this case. I was expecting 
an UNSUPPORTED.





Re: [PATCH][PPC64] [PR88877]

2020-05-23 Thread Segher Boessenkool
Hi!

On Mon, Mar 23, 2020 at 08:16:51PM +0530, kamlesh kumar wrote:
> * rtl.h : Defined Tuple for bundling rtx, mode and
> unsignedness default as 0

This line is too long (and your mailer wrapped it).  No space before
colon.  Full stop at the end of a line.

Write changelogs in the imperative.

> Added Extra argument (unsignedp) in emit_library_call and
> emit_library_call_value.

Use "bool" for boolean arguments (just like anywhere else), not "int".

Boolean arguments are problematic usually: there is no way someone can
tell from a call site what that argument is, usually.  Written as "0" it
is even worse than "false".

And it doesn't even mean "not unsigned" here, in most cases!  It just
means "we don't care", or "we don't know", or "whatever".

> * testsuite/gcc.target/powerpc/pr88877.c : Newtest

That should be in a separate changelog (and be "New." or "New test." or
similar).


Please split this into a bunch of patches: the first few only change the
interface (so add the extra "bool" arguments), but in such a way that no
behaviour changes at all.  One patch for every function that is used a
lot it easiest to review (and to write, and to write the changelog for,
this is not extra work for you either, quite the opposite).

Followed by a patch that actually changes things.  I could not find
anywhere where you do not pass "false" for that new bool argument, btw.,
which illustrates my point here.

Do we really want function calls that are indented fifty characters, and
then have nine(!) arguments?  At some point adding stuff on top makes
things topple over, and it is better to restructure things first.  Of
course that isn't fair to demand of you here, but maybe you see some
opportunity to improve things?


Segher


Re: [PATCH PR94026] combine missed opportunity to simplify comparisons with zero

2020-05-23 Thread Segher Boessenkool
Hi!

Sorry this is taking so long.

On Wed, May 06, 2020 at 08:57:52AM +, Yangfei (Felix) wrote:
> > On Tue, Mar 24, 2020 at 06:30:12AM +, Yangfei (Felix) wrote:
> > > I modified combine emitting a simple AND operation instead of making one
> > zero_extract for this scenario.
> > > Attached please find the new patch.  Hope this solves both of our 
> > > concerns.
> > 
> > This looks promising.  I'll try it out, see what it does on other targets.  
> > (It will
> > have to wait for GCC 11 stage 1, of course).

It creates better code on all targets :-)  A quite small improvement, but
not entirely trivial.

> > p.s.  Please use a correct mime type?  application/octet-stream isn't
> > something I can reply to.  Just text/plain is fine :-)
> 
> I have using plain text now, hope that works for you.  :-)

Nope:

[-- Attachment #2: pr94026-v2.diff --]
[-- Type: application/octet-stream, Encoding: base64, Size: 5.9K --]


Segher


Re: [PATCH] x86: Handle -mavx512vpopcntdq for -march=native

2020-05-23 Thread H.J. Lu via Gcc-patches
On Fri, May 22, 2020 at 12:42 AM Uros Bizjak  wrote:
>
> On Thu, May 21, 2020 at 2:54 PM H.J. Lu  wrote:
> >
> > Add -mavx512vpopcntdq for -march=native if AVX512VPOPCNTDQ is available.
> >
> > PR target/95258
> > * config/i386/driver-i386.c (host_detect_local_cpu): Detect
> > AVX512VPOPCNTDQ.
>
> OK.
>

OK for backports?

Thanks.

>
> > ---
> >  gcc/config/i386/driver-i386.c | 9 ++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c
> > index 7612ddfb846..3a816400729 100644
> > --- a/gcc/config/i386/driver-i386.c
> > +++ b/gcc/config/i386/driver-i386.c
> > @@ -420,6 +420,7 @@ const char *host_detect_local_cpu (int argc, const char 
> > **argv)
> >unsigned int has_avx5124fmaps = 0, has_avx5124vnniw = 0;
> >unsigned int has_gfni = 0, has_avx512vbmi2 = 0;
> >unsigned int has_avx512bitalg = 0;
> > +  unsigned int has_avx512vpopcntdq = 0;
> >unsigned int has_shstk = 0;
> >unsigned int has_avx512vnni = 0, has_vaes = 0;
> >unsigned int has_vpclmulqdq = 0;
> > @@ -528,6 +529,7 @@ const char *host_detect_local_cpu (int argc, const char 
> > **argv)
> >has_vaes = ecx & bit_VAES;
> >has_vpclmulqdq = ecx & bit_VPCLMULQDQ;
> >has_avx512bitalg = ecx & bit_AVX512BITALG;
> > +  has_avx512vpopcntdq = ecx & bit_AVX512VPOPCNTDQ;
> >has_movdiri = ecx & bit_MOVDIRI;
> >has_movdir64b = ecx & bit_MOVDIR64B;
> >has_enqcmd = ecx & bit_ENQCMD;
> > @@ -1189,6 +1191,7 @@ const char *host_detect_local_cpu (int argc, const 
> > char **argv)
> >const char *avx512vp2intersect = has_avx512vp2intersect ? " 
> > -mavx512vp2intersect" : " -mno-avx512vp2intersect";
> >const char *tsxldtrk = has_tsxldtrk ? " -mtsxldtrk " : " 
> > -mno-tsxldtrk";
> >const char *avx512bitalg = has_avx512bitalg ? " -mavx512bitalg" : " 
> > -mno-avx512bitalg";
> > +  const char *avx512vpopcntdq = has_avx512vpopcntdq ? " 
> > -mavx512vpopcntdq" : " -mno-avx512vpopcntdq";
> >const char *movdiri = has_movdiri ? " -mmovdiri" : " -mno-movdiri";
> >const char *movdir64b = has_movdir64b ? " -mmovdir64b" : " 
> > -mno-movdir64b";
> >const char *enqcmd = has_enqcmd ? " -menqcmd" : " -mno-enqcmd";
> > @@ -1210,9 +1213,9 @@ const char *host_detect_local_cpu (int argc, const 
> > char **argv)
> > avx512ifma, avx512vbmi, avx5124fmaps, avx5124vnniw,
> > clwb, mwaitx, clzero, pku, rdpid, gfni, shstk,
> > avx512vbmi2, avx512vnni, vaes, vpclmulqdq,
> > -   avx512bitalg, movdiri, movdir64b, waitpkg, cldemote,
> > -   ptwrite, avx512bf16, enqcmd, avx512vp2intersect,
> > -   serialize, tsxldtrk, NULL);
> > +   avx512bitalg, avx512vpopcntdq, movdiri, movdir64b,
> > +   waitpkg, cldemote, ptwrite, avx512bf16, enqcmd,
> > +   avx512vp2intersect, serialize, tsxldtrk, NULL);
> >  }
> >
> >  done:
> > --
> > 2.26.2
> >



-- 
H.J.


Re: [PATCH] Extend std::copy/std::copy_n char* overload to deque iterator

2020-05-23 Thread Jonathan Wakely via Gcc-patches

On 22/05/20 22:57 +0200, François Dumont via Libstdc++ wrote:

On 21/05/20 2:17 pm, Jonathan Wakely wrote:


Why is the optimization not done for C++03 mode?

I did it this way because the new std::copy overload rely on 
std::copy_n implementation details which is a C++11 algo.




It looks like the uses of 'auto' can be reaplced easily, and
__enable_if_t<> can be replaced with __gnu_cxx::__enable_if<>::__type.


But yes, we can indeed provide those implementation details in pre-C++11.

This is what I've done in this new version.

Tested under Linux x86_64 in default c++ mode.

I tried to use CXXFLAGS=-std=c++03 but it doesn't seem to work even if 
I do see the option in build logs. I remember you adivised a different 
approach, can you tell me again ?


See the documentation:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/test.html#test.run.permutations




[patch, fortran, committed] Fix PR 95191, hang on invalid ID for WAIT

2020-05-23 Thread Thomas Koenig via Gcc-patches

Hello world,

I have just committed as obvious and simple the attached patch -
adding an early error return.

This is a 9/10/11 Regression, so I will commit to the other
branches in a few days.

Regards

Thhomas

Fixes a hang on an invalid ID in a WAIT statement.

gcc/fortran/ChangeLog:

2020-05-23  Thomas Koenig  

PR libfortran/95191
* libgfortran.h (libgfortran_error_codes): Add
LIBERROR_BAD_WAIT_ID.

libgfortran/ChangeLog:

2020-05-23  Thomas Koenig  

PR libfortran/95191
* io/async.c (async_wait_id): Generate error if ID is higher
than the highest current ID.
* runtime/error.c (translate_error): Handle LIBERROR_BAD_WAIT_ID.

libgomp/ChangeLog:

2020-05-23  Thomas Koenig  

PR libfortran/95191
* testsuite/libgomp.fortran/async_io_9.f90: New test.

diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h
index d097caa4a96..6a9139c98fc 100644
--- a/gcc/fortran/libgfortran.h
+++ b/gcc/fortran/libgfortran.h
@@ -124,6 +124,7 @@ typedef enum
   LIBERROR_SHORT_RECORD,
   LIBERROR_CORRUPT_FILE,
   LIBERROR_INQUIRE_INTERNAL_UNIT, /* Must be different from STAT_STOPPED_IMAGE.  */
+  LIBERROR_BAD_WAIT_ID,
   LIBERROR_LAST			/* Not a real error, the last error # + 1.  */
 }
 libgfortran_error_codes;
diff --git a/libgfortran/io/async.c b/libgfortran/io/async.c
index 63b9158c0ba..1bf38e9c0ff 100644
--- a/libgfortran/io/async.c
+++ b/libgfortran/io/async.c
@@ -424,6 +424,13 @@ async_wait_id (st_parameter_common *cmp, async_unit *au, int i)
 }
 
   LOCK (&au->lock);
+  if (i > au->id.high)
+{
+  generate_error_common (cmp, LIBERROR_BAD_WAIT_ID, NULL);
+  UNLOCK (&au->lock);
+  return true;
+}
+
   NOTE ("Waiting for id %d", i);
   if (au->id.waiting < i)
 au->id.waiting = i;
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index 9ed5d566eb6..ff6b852a07c 100644
--- a/libgfortran/runtime/error.c
+++ b/libgfortran/runtime/error.c
@@ -660,6 +660,10 @@ translate_error (int code)
   p = "Inquire statement identifies an internal file";
   break;
 
+case LIBERROR_BAD_WAIT_ID:
+  p = "Bad ID in WAIT statement";
+  break;
+
 default:
   p = "Unknown error code";
   break;
diff --git a/libgomp/testsuite/libgomp.fortran/async_io_9.f90 b/libgomp/testsuite/libgomp.fortran/async_io_9.f90
new file mode 100644
index 000..2dc111c3967
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/async_io_9.f90
@@ -0,0 +1,20 @@
+! { dg-do run }
+! PR 95191 - this used to hang.
+! Original test case by Bill Long.
+program test
+  real a(1)
+  integer my_id
+  integer bad_id
+  integer :: iostat
+  character (len=100) :: iomsg
+  data my_id /1/
+  data bad_id /2/
+  a = 1.
+  open (unit=10, file='test.dat', form='unformatted', &
+   &asynchronous='yes')
+  write (unit=10, asynchronous='yes', id=my_id) a
+  iomsg = ""
+  wait (unit=10, id=bad_id, iostat=iostat, iomsg=iomsg)
+  if (iostat == 0 .or. iomsg /= "Bad ID in WAIT statement") stop 1
+  close (unit=10, status='delete')
+end program test


[committed] libstdc++: Fix function that can't be constexpr in C++11 (PR 95289)

2020-05-23 Thread Jonathan Wakely via Gcc-patches
The body of this function isn't just a return statement, so it can't be
constexpr until C++14.

PR libstdc++/95289
* include/debug/helper_functions.h (__get_distance): Only declare
as a constexpr function for C++14 and up.
* testsuite/25_algorithms/copy/debug/95289.cc: New test.

Tested powerpc64le-linux, committed to master.

I'll backport to gcc-10 too.

commit 3cb0c7cc160a50f830bfa9aa5a3264b773a28bf8
Author: Jonathan Wakely 
Date:   Sat May 23 18:27:35 2020 +0100

libstdc++: Fix function that can't be constexpr in C++11 (PR 95289)

The body of this function isn't just a return statement, so it can't be
constexpr until C++14.

PR libstdc++/95289
* include/debug/helper_functions.h (__get_distance): Only declare
as a constexpr function for C++14 and up.
* testsuite/25_algorithms/copy/debug/95289.cc: New test.

diff --git a/libstdc++-v3/include/debug/helper_functions.h 
b/libstdc++-v3/include/debug/helper_functions.h
index 251582d5922..62d5309257f 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -96,7 +96,7 @@ namespace __gnu_debug
 { return std::make_pair(__rhs - __lhs, __dp_exact); }
 
   template
-_GLIBCXX_CONSTEXPR
+_GLIBCXX14_CONSTEXPR
 inline typename _Distance_traits<_Iterator>::__type
 __get_distance(_Iterator __lhs, _Iterator __rhs,
   std::input_iterator_tag)
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/debug/95289.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/debug/95289.cc
new file mode 100644
index 000..bcdab19761f
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/debug/95289.cc
@@ -0,0 +1,31 @@
+// Copyright (C) 2020 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-options "-std=gnu++11 -D_GLIBCXX_DEBUG" }
+// { dg-do compile { target c++11_only } }
+
+#include 
+#include 
+#include 
+
+// PR libstdc++/95289
+
+void
+test01(std::istream_iterator i, char* out)
+{
+  std::copy(i, decltype(i){}, out);
+}


Re: [PATCH] Check and substitute AR in libcpp and libdecnumber

2020-05-23 Thread Richard Biener via Gcc-patches
On May 23, 2020 2:15:45 AM GMT+02:00, David Edelsohn via Gcc-patches 
 wrote:
>TL;DR: This patch updates configure.ac and Makefile.in in libcpp and
>libdecnumber to substitute AR archiver.
>
>AIX supports "FAT" libraries containing 32 bit and 64 bit objects
>(similar to Darwin), but commands for manipulating libraries do not
>default to accept both 32 bit and 64 bit object files.  While updating
>the AIX configuration to support building and running GCC as a 64 bit
>application, I have encountered some build libraries that hard code
>AR=ar instead of testing the environment.
>
>This patch adds AR_CHECK_TOOL(AR, ar) to configure.ac for the two
>libraries and updates Makefile.in to accept the substitution.
>
>Bootstrapped on powerpc64le-ibm-linux-gnu.
>
>Okay?

OK. 

Richard. 
>
>Thanks, David
>
>libcpp/
>* Makefile.in (AR): Substitute @AR@.
>* configure.ac (CHECK_PROG AR): New.
>* configure: Regenerate.
>
>libdecnumber/
>* Makefile.in (AR): Substitute @AR@.
>* configure.ac (CHECK_PROG AR): New.
>* configure: Regenerate.
>
>diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
>index ebbca07..5fbba9b 100644
>--- a/libcpp/Makefile.in
>+++ b/libcpp/Makefile.in
>@@ -25,7 +25,7 @@ srcdir = @srcdir@
> top_builddir = .
> VPATH = @srcdir@
> INSTALL = @INSTALL@
>-AR = ar
>+AR = @AR@
> ARFLAGS = cru
> ACLOCAL = @ACLOCAL@
> AUTOCONF = @AUTOCONF@
>diff --git a/libcpp/configure.ac b/libcpp/configure.ac
>index 540efeb..1efa96f 100644
>--- a/libcpp/configure.ac
>+++ b/libcpp/configure.ac
>@@ -12,6 +12,7 @@ AC_PROG_INSTALL
> AC_PROG_CC
> AC_PROG_CXX
> AC_PROG_RANLIB
>+AC_CHECK_TOOL(AR, ar)
>
> AC_USE_SYSTEM_EXTENSIONS
> AC_SYS_LARGEFILE
>diff --git a/libdecnumber/Makefile.in b/libdecnumber/Makefile.in
>index 9260b48..9da028d 100644
>--- a/libdecnumber/Makefile.in
>+++ b/libdecnumber/Makefile.in
>@@ -25,7 +25,7 @@ srcdir = @srcdir@
> top_builddir = .
> VPATH = @srcdir@
> INSTALL = @INSTALL@
>-AR = ar
>+AR = @AR@
> ARFLAGS = cru
> ACLOCAL = @ACLOCAL@
> AUTOCONF = @AUTOCONF@
>diff --git a/libdecnumber/configure.ac b/libdecnumber/configure.ac
>index de7e008..ae475a0 100644
>--- a/libdecnumber/configure.ac
>+++ b/libdecnumber/configure.ac
>@@ -28,6 +28,7 @@ AC_CONFIG_AUX_DIR(..)
> AC_PROG_MAKE_SET
> AC_PROG_CC
> AC_PROG_RANLIB
>+AC_CHECK_TOOL(AR, ar)
>
> MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
> AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])



Re: [PATCH] c++: template instantiation during fold_for_warn [PR94038]

2020-05-23 Thread Patrick Palka via Gcc-patches
On Fri, 22 May 2020, Jason Merrill wrote:
> On 5/22/20 9:18 PM, Patrick Palka wrote:
> > On Fri, 22 May 2020, Jason Merrill wrote:
> > > On 5/20/20 10:08 PM, Patrick Palka wrote:
> > > > On Wed, 20 May 2020, Patrick Palka wrote:
> > > > > On Tue, 19 May 2020, Jason Merrill wrote:
> > > > > 
> > > > > > On 5/8/20 11:42 AM, Patrick Palka wrote:
> > > > > > > On Wed, 6 May 2020, Patrick Palka wrote:
> > > > > > > 
> > > > > > > > On Wed, 6 May 2020, Patrick Palka wrote:
> > > > > > > > 
> > > > > > > > > On Tue, 5 May 2020, Patrick Palka wrote:
> > > > > > > > > 
> > > > > > > > > > On Tue, 5 May 2020, Patrick Palka wrote:
> > > > > > > > > > 
> > > > > > > > > > > Unfortunately, the previous fix to PR94038 is fragile.
> > > > > > > > > > > When
> > > > > > > > > > > the
> > > > > > > > > > > argument to fold_for_warn is a bare CALL_EXPR, then all is
> > > > > > > > > > > well: the
> > > > > > > > > > > result of maybe_constant_value from fold_for_warn (with
> > > > > > > > > > > uid_sensitive=true) is reused via the cv_cache in the
> > > > > > > > > > > subsequent
> > > > > > > > > > > call to
> > > > > > > > > > > maybe_constant_value from cp_fold (with
> > > > > > > > > > > uid_sensitive=false),
> > > > > > > > > > > so we
> > > > > > > > > > > avoid instantiating bar.
> > > > > > > > > > > 
> > > > > > > > > > > But when the argument to fold_for_warn is more complex,
> > > > > > > > > > > e.g.
> > > > > > > > > > > an
> > > > > > > > > > > INDIRECT_REF of a CALL_EXPR, as in the testcase below (due
> > > > > > > > > > > to
> > > > > > > > > > > bar()
> > > > > > > > > > > returning const int& which we need to decay to int) then
> > > > > > > > > > > from
> > > > > > > > > > > fold_for_warn we call maybe_constant_value on the
> > > > > > > > > > > INDIRECT_REF, and
> > > > > > > > > > > from
> > > > > > > > > > > cp_fold we call it on the CALL_EXPR, so there is no reuse
> > > > > > > > > > > via
> > > > > > > > > > > the
> > > > > > > > > > > cv_cache and we therefore end up instantiating bar.
> > > > > > > > > > > 
> > > > > > > > > > > So for a more robust solution to this general issue of
> > > > > > > > > > > warning
> > > > > > > > > > > flags
> > > > > > > > > > > affecting code generation, it seems that we need a way to
> > > > > > > > > > > globally
> > > > > > > > > > > avoid
> > > > > > > > > > > template instantiation during constexpr evaluation
> > > > > > > > > > > whenever
> > > > > > > > > > > we're
> > > > > > > > > > > performing warning-dependent folding.
> > > > > > > > > > > 
> > > > > > > > > > > To that end, this patch replaces the flag
> > > > > > > > > > > constexpr_ctx::uid_sensitive
> > > > > > > > > > > with a global flag uid_sensitive_constexpr_evaluation_p,
> > > > > > > > > > > and
> > > > > > > > > > > enables
> > > > > > > > > > > it
> > > > > > > > > > > during fold_for_warn using an RAII helper.
> > > > > > > > > > > 
> > > > > > > > > > > The patch also adds a counter that keeps track of the
> > > > > > > > > > > number
> > > > > > > > > > > of
> > > > > > > > > > > times
> > > > > > > > > > > uid_sensitive_constexpr_evaluation_p is called, and we use
> > > > > > > > > > > this to
> > > > > > > > > > > determine whether the result of constexpr evaluation
> > > > > > > > > > > depended
> > > > > > > > > > > on the
> > > > > > > > > > > flag's value.  This lets us safely update the cv_cache and
> > > > > > > > > > > fold_cache
> > > > > > > > > > > from fold_for_warn in the most common case where the
> > > > > > > > > > > flag's
> > > > > > > > > > > value
> > > > > > > > > > > was
> > > > > > > > > > > irrelevant during constexpr evaluation.
> > > > > > > 
> > > > > > > Here's some statistics about about the fold cache and cv cache
> > > > > > > that
> > > > > > > were
> > > > > > > collected when building the testsuite of range-v3 (with the
> > > > > > > default
> > > > > > > build flags which include -O -Wall -Wextra, so warning-dependent
> > > > > > > folding
> > > > > > > applies).
> > > > > > > 
> > > > > > > The "naive solution" below refers to the one in which we would
> > > > > > > refrain
> > > > > > > from updating the caches at the end of
> > > > > > > cp_fold/maybe_constant_value
> > > > > > > whenever we're in uid-sensitive constexpr evaluation mode (i.e.
> > > > > > > whenever
> > > > > > > we're called from fold_for_warn), regardless of whether constexpr
> > > > > > > evaluation was actually restricted.
> > > > > > > 
> > > > > > > 
> > > > > > > FOLD CACHE  | cache hit | cache miss| cache miss|
> > > > > > >|   | cache updated | cache not updated |
> > > > > > > +---+---+---+
> > > > > > > naive sol'n |   5060779 |  11374667 |  12887790 |
> > > > > > > +
> > > > > > > this patch  |   6665242 |  19688975 |199137 |
> > > > > > > +---+---+---+
>

[committed] libstdc++: Compile PR93978 testcase with -Wall

2020-05-23 Thread Patrick Palka via Gcc-patches
Now that the frontend issue PR c++/94038 is thoroughly fixed, the
testcase for PR93978 no longer fails to compile with -O -Wall, so add
-Wall to the testcase's compile flags to help ensure we don't regress
here.

Committed as obvious after testing on x86_64-pc-linux-gnu.

libstdc++-v3/ChangeLog:

PR libstdc++/93978
* testsuite/std/ranges/adaptors/93978.cc: Add -Wall to
dg-additional-options.  Avoid unused-but-set-variable warning.
---
 libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc 
b/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc
index a0152ec0532..82b82b0a5be 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/93978.cc
@@ -16,7 +16,7 @@
 // .
 
 // { dg-options "-std=gnu++2a" }
-// { dg-additional-options "-O" }
+// { dg-additional-options "-O -Wall" }
 // { dg-do compile { target c++2a } }
 
 #include 
@@ -25,11 +25,12 @@
 namespace ranges = std::ranges;
 namespace views = std::views;
 
-void
+auto
 test()
 {
   std::vector x = {""};
   auto i = std::counted_iterator(x.begin(), 1);
   auto r = ranges::subrange{i, std::default_sentinel};
   auto v = r | views::join;
+  return v;
 }
-- 
2.27.0.rc1.5.gae92ac8ae3



Bountysource campaign for converting the VAX backend

2020-05-23 Thread John Paul Adrian Glaubitz
Hi!

The NetBSD VAX porters have shown interest in a Bountysource campaign
for their GCC backend [1], so I created one [2].

The backend can be tested with the help of the SimH emulator, see [3, 4].

Adrian

> [1] http://mail-index.netbsd.org/port-vax/2020/04/16/msg003460.html
> [2] 
> https://www.bountysource.com/issues/91495157-vax-convert-the-backend-to-mode_cc-so-it-can-be-kept-in-future-releases
> [3] http://mail-index.netbsd.org/port-vax/2020/04/18/msg003481.html
> [4] http://www.netbsd.org/ports/vax/emulator-howto.html

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaub...@debian.org
`. `'   Freie Universitaet Berlin - glaub...@physik.fu-berlin.de
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


[PATCH RFC] gcc-git: Add prepare-commit-msg hook.

2020-05-23 Thread Jason Merrill via Gcc-patches
This patch introduces a prepare-commit-msg hook that appends a ChangeLog
skeleton to a commit message that doesn't already have one, and a 'git
amend-mklog' command to amend and append a new ChangeLog skeleton (to be
edited together with existing entries by hand).

Thoughts?

contrib/ChangeLog:

* prepare-commit-msg: New file.
* gcc-git-customization.sh: Install it.  Add amend-mklog alias.
---
 contrib/gcc-git-customization.sh |  5 
 contrib/prepare-commit-msg   | 39 
 2 files changed, 44 insertions(+)
 create mode 100644 contrib/prepare-commit-msg

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index 7a950ae5f38..a36403f0b2c 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -30,6 +30,11 @@ git config alias.gcc-backport '!f() { rev=$1; git 
cherry-pick -x $@; } ; f'
 
 git config alias.gcc-mklog '!f() { "`git rev-parse 
--show-toplevel`/contrib/mklog.py" $@; } ; f'
 
+hookdir=`git rev-parse --git-path hooks`
+install "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
+
+git config alias.amend-mklog '!f() { GCC_PREPARE_COMMIT_FORCE_APPEND=1 git 
commit --amend "$@"; }; f'
+
 # Make diff on MD files use "(define" as a function marker.
 # Use this in conjunction with a .gitattributes file containing
 # *.mddiff=md
diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
new file mode 100644
index 000..61bc051268f
--- /dev/null
+++ b/contrib/prepare-commit-msg
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+#COMMIT_MSG_FILE=$1
+#COMMIT_SOURCE=$2
+#SHA1=$3
+
+#echo "# $*" > $HOME/prepare-commit-msg-args
+
+# Can't do anything if $1 isn't a file.
+if ! [ -f "$1" ]; then exit 0; fi
+
+# Don't mess with existing entries unless requested to.
+if [ -z "$GCC_PREPARE_COMMIT_FORCE_APPEND" ] &&
+   grep -qsF 'ChangeLog:' "$1"
+then exit 0; fi
+
+if [ -z "$2" ] || [ $2 == template ]; then
+# No source or "template" means new commit.
+cmd="diff --cached"
+elif [ $2 == message ]; then
+# "message" means -m, but could be either a new commit or --amend.
+# Guess which based on whether there are any changes staged.
+if git diff --cached --quiet; then
+   cmd="show"
+else
+   cmd="diff --cached"
+fi
+
+# Add a blank line before the ChangeLog entries.
+echo >> "$1"
+elif [ $2 == commit ]; then
+# The message of an existing commit.
+cmd="show $3"
+else
+# Do nothing for merge or squash.
+exit 0
+fi
+
+git $cmd | git gcc-mklog >> "$1"

base-commit: 584d52b088f9fcf78704b504c3f1f07e17c1cded
-- 
2.18.1



[PATCH] Add support for C++20 barriers

2020-05-23 Thread Thomas Rodgers
This patch requires the patch for atomic::wait/notify to be applied first.

This implementation is based on the libc++ implementation, but excludes the 
alternative “central barrier” implementation for now as there is no standard 
way to switch between the two.

* include/Makefile.am (std_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/std/barrier: New file.
* testsuite/30_thread/barrier/1.cc: New test.
* testsuite/30_thread/barrier/2.cc: Likewise.
* testsuite/30_thread/barrier/arrive_and_drop.cc: Likewise.
* testsuite/30_thread/barrier/arrive_and_wait.cc: Likewise.
* testsuite/30_thread/barrier/arrive.cc: Likewise.
* testsuite/30_thread/barrier/completion.cc: Likewise.
* testsuite/30_thread/barrier/max.cc: Likewise.



Re: [PATCH] Provide diagnostic hints for missing inttypes.h string constants.

2020-05-23 Thread Mark Wielaard
On Sat, May 23, 2020 at 05:01:21AM +0200, Mark Wielaard wrote:
> Yes, that is actually better. And much easier to read. And the code
> can still be shared between get_c_stdlib_header_for_string_macro_name
> and get_stdlib_header_for_name. Changed in the attached patch.
>
> I also extended the testcase so it covers both identifiers and string
> concatenation cases. The identifier hints also work for C++, but I
> haven't yet added the string token concatenation detection to the
> cp_parser. It looks like it can be done similar as done for the
> c_parser, but the parsers are different enough that it seems
> better/simpler to do that in a followup patch once we have this patch
> in the the c_parser.

The cp_parser keeps a stack of tokens, so it was actually easier to
add the same functionality. I kept the patch separate to make review
easier. The c_parser patch is almost the same as what I posted earlier,
it just uses get_c_stdlib_header_for_string_macro_name explicitly. The
cp_parser patch adds get_cpp_stdlib_header_for_string_macro_name and
uses that. The testcase for the C++ case is extended like the c_parser
one.

[PATCH 1/2] Provide diagnostic hints for missing C inttypes.h string
[PATCH 2/2] Provide diagnostic hints for missing C++ cinttypes string

Cheers,

Mark


[PATCH 2/2] Provide diagnostic hints for missing C++ cinttypes string constants.

2020-05-23 Thread Mark Wielaard
When reporting an error in cp_parser and we notice a string literal
followed by an unknown name check whether there is a known standard
header containing a string macro with the same name, then add a hint
to the error message to include that header.

gcc/c-family/ChangeLog:

* known-headers.cc (get_cp_stdlib_header_for_string_macro_name):
New function.
* known-headers.h (get_c_stdlib_header_for_string_macro_name):
New function definition.

gcc/cp/ChangeLog:

* parser.c (cp_lexer_safe_previous_token): New function.
(cp_parser_error_1): Add name_hint if the previous token is
a string literal and next token is a CPP_NAME and we have a
missing header suggestion for the name.

gcc/testsuite/ChangeLog:

* g++.dg/spellcheck-inttypes.C: Add string-literal testcases.
---
 gcc/c-family/known-headers.cc  |  8 +
 gcc/c-family/known-headers.h   |  1 +
 gcc/cp/parser.c| 36 
 gcc/testsuite/g++.dg/spellcheck-inttypes.C | 39 ++
 4 files changed, 84 insertions(+)

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index c07cfd1db815..977230a586db 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -268,6 +268,14 @@ get_c_stdlib_header_for_string_macro_name (const char 
*name)
   return get_string_macro_hint (name, STDLIB_C);
 }
 
+/* Given non-NULL NAME, return the header name defining a string macro
+   within the C++ standard library (with '<' and '>'), or NULL.  */
+const char *
+get_cp_stdlib_header_for_string_macro_name (const char *name)
+{
+  return get_string_macro_hint (name, STDLIB_CPLUSPLUS);
+}
+
 /* Implementation of class suggest_missing_header.  */
 
 /* suggest_missing_header's ctor.  */
diff --git a/gcc/c-family/known-headers.h b/gcc/c-family/known-headers.h
index a69bbbf28e76..f0c89dc9019d 100644
--- a/gcc/c-family/known-headers.h
+++ b/gcc/c-family/known-headers.h
@@ -24,6 +24,7 @@ extern const char *get_c_stdlib_header_for_name (const char 
*name);
 extern const char *get_cp_stdlib_header_for_name (const char *name);
 
 extern const char *get_c_stdlib_header_for_string_macro_name (const char *n);
+extern const char *get_cp_stdlib_header_for_string_macro_name (const char *n);
 
 /* Subclass of deferred_diagnostic for suggesting to the user
that they have missed a #include.  */
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 54ca875ce54c..95b8c635fc65 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-iterator.h"
 #include "cp-name-hint.h"
 #include "memmodel.h"
+#include "c-family/known-headers.h"
 
 
 /* The lexer.  */
@@ -776,6 +777,20 @@ cp_lexer_previous_token (cp_lexer *lexer)
   return cp_lexer_token_at (lexer, tp);
 }
 
+/* Same as above, but return NULL when the lexer doesn't own the token
+   buffer or if the next_token is at the start of the token
+   vector.  */
+
+static cp_token *
+cp_lexer_safe_previous_token (cp_lexer *lexer)
+{
+  if (lexer->buffer)
+if (lexer->next_token != lexer->buffer->address ())
+  return cp_lexer_previous_token (lexer);
+
+  return NULL;
+}
+
 /* Overload for make_location, taking the lexer to mean the location of the
previous token.  */
 
@@ -2919,6 +2934,7 @@ cp_parser_error_1 (cp_parser* parser, const char* gmsgid,
}
 }
 
+  auto_diagnostic_group d;
   gcc_rich_location richloc (input_location);
 
   bool added_matching_location = false;
@@ -2941,6 +2957,26 @@ cp_parser_error_1 (cp_parser* parser, const char* gmsgid,
  = richloc.add_location_if_nearby (matching_location);
 }
 
+  /* If we were parsing a string-literal and there is an unknown name
+ token right after, then check to see if that could also have been
+ a literal string by checking the name against a list of known
+ standard string literal constants defined in header files. If
+ there is one, then add that as an hint to the error message. */
+  name_hint h;
+  cp_token *prev_token = cp_lexer_safe_previous_token (parser->lexer);
+  if (prev_token && cp_parser_is_string_literal (prev_token)
+  && token->type == CPP_NAME)
+{
+  tree name = token->u.value;
+  const char *token_name = IDENTIFIER_POINTER (name);
+  const char *header_hint
+   = get_cp_stdlib_header_for_string_macro_name (token_name);
+  if (header_hint != NULL)
+   h = name_hint (NULL, new suggest_missing_header (token->location,
+token_name,
+header_hint));
+}
+
   /* Actually emit the error.  */
   c_parse_error (gmsgid,
 /* Because c_parser_error does not understand
diff --git a/gcc/testsuite/g++.dg/spellcheck-inttypes.C 
b/gcc/testsuite/g++.dg/spellcheck-inttypes.C
index c5861127ca6d..84bfc125513c 100644
--- a/gcc

[PATCH 1/2] Provide diagnostic hints for missing C inttypes.h string constants.

2020-05-23 Thread Mark Wielaard
This adds a flag to c_parser so we know when we were trying to
construct a string literal. If there is a parse error and we were
constructing a string literal, and the next token is an unknown
identifier name, and we know there is a standard header that defines
that name as a string literal, then add a missing header hint to
the error messsage.

The list of macro names are also used when providing a hint for
missing identifiers.

gcc/c-family/ChangeLog:

* known-headers.cc (get_string_macro_hint): New function.
(get_stdlib_header_for_name): Use get_string_macro_hint.
(get_c_stdlib_header_for_string_macro_name): New function.
* known-headers.h (get_c_stdlib_header_for_string_macro_name):
New function definition.

gcc/c/ChangeLog:

* c-parser.c (struct c_parser): Add seen_string_literal
bitfield.
(c_parser_consume_token): Reset seen_string_literal.
(c_parser_error_richloc): Add name_hint if seen_string_literal
and next token is a CPP_NAME and we have a missing header
suggestion for the name.
(c_parser_string_literal): Set seen_string_literal.

gcc/testsuite/ChangeLog:

* gcc.dg/spellcheck-inttypes.c: New test.
* g++.dg/spellcheck-inttypes.C: Likewise.
---
 gcc/c-family/known-headers.cc  | 53 ++-
 gcc/c-family/known-headers.h   |  2 +
 gcc/c/c-parser.c   | 29 
 gcc/testsuite/g++.dg/spellcheck-inttypes.C | 41 
 gcc/testsuite/gcc.dg/spellcheck-inttypes.c | 78 ++
 5 files changed, 202 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/spellcheck-inttypes.C
 create mode 100644 gcc/testsuite/gcc.dg/spellcheck-inttypes.c

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 1e2bf49c439a..c07cfd1db815 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -46,6 +46,49 @@ struct stdlib_hint
   const char *header[NUM_STDLIBS];
 };
 
+/* Given non-NULL NAME, return the header name defining it (as literal
+   string) within either the standard library (with '<' and '>'), or
+   NULL.
+
+   Only handle string macros, so that this can be used for
+   get_stdlib_header_for_name and
+   get_c_stdlib_header_for_string_macro_name.  */
+
+static const char *
+get_string_macro_hint (const char *name, enum stdlib lib)
+{
+  /*  and .  */
+  static const char *c99_cxx11_macros[] =
+{ "PRId8", "PRId16", "PRId32", "PRId64",
+  "PRIi8", "PRIi16", "PRIi32", "PRIi64",
+  "PRIo8", "PRIo16", "PRIo32", "PRIo64",
+  "PRIu8", "PRIu16", "PRIu32", "PRIu64",
+  "PRIx8", "PRIx16", "PRIx32", "PRIx64",
+  "PRIX8", "PRIX16", "PRIX32", "PRIX64",
+
+  "PRIdPTR", "PRIiPTR", "PRIoPTR", "PRIuPTR", "PRIxPTR", "PRIXPTR",
+
+  "SCNd8", "SCNd16", "SCNd32", "SCNd64",
+  "SCNi8", "SCNi16", "SCNi32", "SCNi64",
+  "SCNo8", "SCNo16", "SCNo32", "SCNo64",
+  "SCNu8", "SCNu16", "SCNu32", "SCNu64",
+  "SCNx8", "SCNx16", "SCNx32", "SCNx64",
+
+  "SCNdPTR", "SCNiPTR", "SCNoPTR", "SCNuPTR", "SCNxPTR" };
+
+  if ((lib == STDLIB_C && flag_isoc99)
+  || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
+{
+  const size_t num_c99_cxx11_macros
+   = sizeof (c99_cxx11_macros) / sizeof (c99_cxx11_macros[0]);
+  for (size_t i = 0; i < num_c99_cxx11_macros; i++)
+   if (strcmp (name, c99_cxx11_macros[i]) == 0)
+ return lib == STDLIB_C ? "" : "";
+}
+
+  return NULL;
+}
+
 /* Given non-NULL NAME, return the header name defining it within either
the standard library (with '<' and '>'), or NULL.
Only handles a subset of the most common names within the stdlibs.  */
@@ -196,7 +239,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib 
lib)
   if (strcmp (name, c99_cxx11_hints[i].name) == 0)
return c99_cxx11_hints[i].header[lib];
 
-  return NULL;
+  return get_string_macro_hint (name, lib);
 }
 
 /* Given non-NULL NAME, return the header name defining it within the C
@@ -217,6 +260,14 @@ get_cp_stdlib_header_for_name (const char *name)
   return get_stdlib_header_for_name (name, STDLIB_CPLUSPLUS);
 }
 
+/* Given non-NULL NAME, return the header name defining a string macro
+   within the C standard library (with '<' and '>'), or NULL.  */
+const char *
+get_c_stdlib_header_for_string_macro_name (const char *name)
+{
+  return get_string_macro_hint (name, STDLIB_C);
+}
+
 /* Implementation of class suggest_missing_header.  */
 
 /* suggest_missing_header's ctor.  */
diff --git a/gcc/c-family/known-headers.h b/gcc/c-family/known-headers.h
index 4ec4e23fc88d..a69bbbf28e76 100644
--- a/gcc/c-family/known-headers.h
+++ b/gcc/c-family/known-headers.h
@@ -23,6 +23,8 @@ along with GCC; see the file COPYING3.  If not see
 extern const char *get_c_stdlib_header_for_name (const char *name);
 extern const char *get_cp_stdlib_header_for_name (const char *name);
 
+extern const char *get_c_stdlib