[PING][PATCH] add more detail to -Wconversion and -Woverflow (PR 80731)

2017-05-22 Thread Martin Sebor

Ping:
  https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01428.html

On 05/17/2017 06:04 PM, Martin Sebor wrote:

While working on a new warning for unsafe conversion I noticed
that the existing warnings that diagnose these kinds of problems
are missing some useful detail. For example, given declarations
of an integer Type and an integer Constant defined in some header,
a C programmer who writes this declaration:

  Type x = Constant;

might see the following:

  warning: overflow in implicit constant conversion [-Woverflow]

To help the programmer better understand the problem and its impact
it would be helpful to mention the types of the operands, and if
available, also the values of the expressions.  For instance, like
so:

  warning: overflow in conversion from ‘int’ to ‘T {aka signed char}’
changes value from ‘123456789’ to ‘21’ [-Woverflow]

The attached simple patch does just that.  In making the changes
I tried to make the text of all the warnings follow the same
consistent wording pattern without losing any essential information
(e.g., I dropped "implicit" or "constant" because the implicit part
is evident from the code (no cast) and explicit conversions aren't
diagnosed, and because constant is apparent from the rest of the
diagnostic that includes its value.

Besides adding more detail and tweaking the wording the patch
makes no functional changes (i.e., doesn't add new or remove
existing warnings).

Martin

PS While adjusting the tests (a painstaking process) it occurred
to me that these kinds of changes would be a whole lot easier if
dg-warning directives simply checked for "-Woption-name" rather
than some (often arbitrary) part of the warning text.  It might
even be more accurate if the pattern happens to match the text
of two or more warnings controlled by different options.

It's of course important to also exercise the full text of
the warnings, especially where additional detail is included
(like in this patch), but that can be done in a small subset
of tests.  All the others that just verify the presence of
a warning controlled by a given option could use the simpler
approach.




[PING #2] [PATCH] handle enumerated types in -Wformat-overflow (PR 80397)

2017-05-22 Thread Martin Sebor

Ping:

  https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00547.html

On 05/15/2017 09:01 PM, Martin Sebor wrote:

Ping: Jeff, is this patch approved?
  https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00547.html

On 05/08/2017 08:38 PM, Martin Sebor wrote:

On 04/28/2017 12:35 PM, Jeff Law wrote:

On 04/26/2017 11:05 AM, Martin Sebor wrote:

On 04/24/2017 03:35 PM, Jeff Law wrote:

On 04/11/2017 12:57 PM, Martin Sebor wrote:

In a review of my fix for bug 80364 Jakub pointed out that to
determine whether an argument to an integer directive is of
an integer type the gimple-ssa-sprintf pass tests the type code
for equality to INTEGER_TYPE when it should instead be using
INTEGRAL_TYPE_P().  This has the effect of the pass being unable
to use the available range of arguments of enumerated types,
resulting in both false positives and false negatives, and in
some cases, in emitting suboptimal code.

The attached patch replaces those tests with INTEGRAL_TYPE_P().

Since this is not a regression I submit it for GCC 8.

You might consider using POINTER_TYPE_P as well.


You mean rather than (TREE_CODE (type) == POINTER_TYPE)?  Those
I believe are vestiges of the %p handling that was removed sometime
last year, and (unless you are recommending I remove them as part
of this patch) should probably be removed during the next cleanup.Yes,
that can be a follow-up cleanup.


For the future, if you find yourself writing something like
TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE, you're usually going to be
better off using POINTER_TYPE_P (TREE_TYPE (x)).  That allows the code
to work with C++ references as well as C pointers.


I'll keep it in mind, thanks.  Should I take this as approval
of the patch as is or are there some changes you'd like me to
make?

Martin






Re: [RFC 1/5] gcc: xtensa: allow XCHAL_* macros to be non-constant

2017-05-22 Thread Max Filippov
On Mon, May 22, 2017 at 2:30 PM, augustine.sterl...@gmail.com
 wrote:
> On Mon, May 22, 2017 at 2:09 PM, Max Filippov  wrote:
>> XCHAL_* macros from the xtensa-config.h are used in a number of places
>> that require them to be preprocessor constants. Rewrite these places so
>> that non-constant XCHAL_* definitions could be used there.
>
> This whole series of patches is going to take quite a bit of time to
> sort through, so sit tight if you would.

Sure, there's no rush. Thank you for doing it.

-- Max


Re: [RFC 1/5] gcc: xtensa: allow XCHAL_* macros to be non-constant

2017-05-22 Thread augustine.sterl...@gmail.com
On Mon, May 22, 2017 at 2:09 PM, Max Filippov  wrote:
> XCHAL_* macros from the xtensa-config.h are used in a number of places
> that require them to be preprocessor constants. Rewrite these places so
> that non-constant XCHAL_* definitions could be used there.

This whole series of patches is going to take quite a bit of time to
sort through, so sit tight if you would.


[RFC 5/5] libgcc: xtensa: use built-in configuration

2017-05-22 Thread Max Filippov
Now that gcc provides __XCHAL_* definitions use them instead of XCHAL_*
definitions from the include/xtensa-config.h. That makes libgcc
dynamically configurable for the target xtensa core.

2017-05-22  Max Filippov  
include/
* xtensa-config-builtin.h: New File.

libgcc/
* config/xtensa/crti.S (xtensa-config.h): Replace #inlcude with
xtensa-config-builtin.h.
* config/xtensa/crtn.S: Likewise.
* config/xtensa/lib1funcs.S: Likewise.
* config/xtensa/lib2funcs.S: Likewise.
---
 include/xtensa-config-builtin.h  | 191 +++
 libgcc/config/xtensa/crti.S  |   2 +-
 libgcc/config/xtensa/crtn.S  |   2 +-
 libgcc/config/xtensa/lib1funcs.S |   2 +-
 libgcc/config/xtensa/lib2funcs.S |   2 +-
 5 files changed, 195 insertions(+), 4 deletions(-)
 create mode 100644 include/xtensa-config-builtin.h

diff --git a/include/xtensa-config-builtin.h b/include/xtensa-config-builtin.h
new file mode 100644
index 000..785d62c
--- /dev/null
+++ b/include/xtensa-config-builtin.h
@@ -0,0 +1,191 @@
+/* Xtensa configuration settings.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program 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 2, or (at your option)
+   any later version.
+
+   This program 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 program; if not, write to the Free Software
+   Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  
*/
+
+#ifndef XTENSA_CONFIG_BUILTIN_H
+#define XTENSA_CONFIG_BUILTIN_H
+
+/* The macros defined here match those with the same names in the Xtensa
+   compile-time HAL (Hardware Abstraction Layer).  Please refer to the
+   Xtensa System Software Reference Manual for documentation of these
+   macros.  */
+
+#undef XCHAL_HAVE_BE
+#define XCHAL_HAVE_BE  __XCHAL_HAVE_BE
+
+#undef XCHAL_HAVE_DENSITY
+#define XCHAL_HAVE_DENSITY __XCHAL_HAVE_DENSITY
+
+#undef XCHAL_HAVE_CONST16
+#define XCHAL_HAVE_CONST16 __XCHAL_HAVE_CONST16
+
+#undef XCHAL_HAVE_ABS
+#define XCHAL_HAVE_ABS __XCHAL_HAVE_ABS
+
+#undef XCHAL_HAVE_ADDX
+#define XCHAL_HAVE_ADDX__XCHAL_HAVE_ADDX
+
+#undef XCHAL_HAVE_L32R
+#define XCHAL_HAVE_L32R__XCHAL_HAVE_L32R
+
+#undef XSHAL_USE_ABSOLUTE_LITERALS
+#define XSHAL_USE_ABSOLUTE_LITERALS__XSHAL_USE_ABSOLUTE_LITERALS
+
+#undef XSHAL_HAVE_TEXT_SECTION_LITERALS
+#define XSHAL_HAVE_TEXT_SECTION_LITERALS __XSHAL_HAVE_TEXT_SECTION_LITERALS
+
+#undef XCHAL_HAVE_MAC16
+#define XCHAL_HAVE_MAC16   __XCHAL_HAVE_MAC16
+
+#undef XCHAL_HAVE_MUL16
+#define XCHAL_HAVE_MUL16   __XCHAL_HAVE_MUL16
+
+#undef XCHAL_HAVE_MUL32
+#define XCHAL_HAVE_MUL32   __XCHAL_HAVE_MUL32
+
+#undef XCHAL_HAVE_MUL32_HIGH
+#define XCHAL_HAVE_MUL32_HIGH  __XCHAL_HAVE_MUL32_HIGH
+
+#undef XCHAL_HAVE_DIV32
+#define XCHAL_HAVE_DIV32   __XCHAL_HAVE_DIV32
+
+#undef XCHAL_HAVE_NSA
+#define XCHAL_HAVE_NSA __XCHAL_HAVE_NSA
+
+#undef XCHAL_HAVE_MINMAX
+#define XCHAL_HAVE_MINMAX  __XCHAL_HAVE_MINMAX
+
+#undef XCHAL_HAVE_SEXT
+#define XCHAL_HAVE_SEXT__XCHAL_HAVE_SEXT
+
+#undef XCHAL_HAVE_LOOPS
+#define XCHAL_HAVE_LOOPS   __XCHAL_HAVE_LOOPS
+
+#undef XCHAL_HAVE_THREADPTR
+#define XCHAL_HAVE_THREADPTR   __XCHAL_HAVE_THREADPTR
+
+#undef XCHAL_HAVE_RELEASE_SYNC
+#define XCHAL_HAVE_RELEASE_SYNC__XCHAL_HAVE_RELEASE_SYNC
+
+#undef XCHAL_HAVE_S32C1I
+#define XCHAL_HAVE_S32C1I  __XCHAL_HAVE_S32C1I
+
+#undef XCHAL_HAVE_BOOLEANS
+#define XCHAL_HAVE_BOOLEANS__XCHAL_HAVE_BOOLEANS
+
+#undef XCHAL_HAVE_FP
+#define XCHAL_HAVE_FP  __XCHAL_HAVE_FP
+
+#undef XCHAL_HAVE_FP_DIV
+#define XCHAL_HAVE_FP_DIV  __XCHAL_HAVE_FP_DIV
+
+#undef XCHAL_HAVE_FP_RECIP
+#define XCHAL_HAVE_FP_RECIP__XCHAL_HAVE_FP_RECIP
+
+#undef XCHAL_HAVE_FP_SQRT
+#define XCHAL_HAVE_FP_SQRT __XCHAL_HAVE_FP_SQRT
+
+#undef XCHAL_HAVE_FP_RSQRT
+#define XCHAL_HAVE_FP_RSQRT__XCHAL_HAVE_FP_RSQRT
+
+#undef XCHAL_HAVE_FP_POSTINC
+#define XCHAL_HAVE_FP_POSTINC  __XCHAL_HAVE_FP_POSTINC
+
+#undef XCHAL_HAVE_DFP
+#define XCHAL_HAVE_DFP __XCHAL_HAVE_DFP
+
+#undef XCHAL_HAVE_DFP_DIV
+#define XCHAL_HAVE_DFP_DIV __XCHAL_HAVE_DFP_DIV
+
+#undef XCHAL_HAVE_DFP_RECIP
+#define XCHAL_HAVE_DFP_RECIP   __XCHAL_HAVE_DFP_RECIP
+
+#undef XCHAL_HAVE_DFP_SQRT
+#define XCHAL_HAVE_DFP_SQRT

[RFC 4/5] gcc: xtensa: add __XCHAL_* builtins

2017-05-22 Thread Max Filippov
Provide essential XCHAL_* configuration parameters as __XCHAL_* built-in
macros. This way it will be possible to use them in libgcc and libc
without need to patch libgcc or libc source for the specific xtensa core
configuration.

2017-05-22  Max Filippov  
gcc/
* config/xtensa/xtensa-config.c (_STRINGIFY, STRINGIFY,
XTENSA_CONFIG_ENTRY): New definitions.
(xtensa_config_strings): New array with default __XCHAL_*
macros.
(xtensa_get_config_strings): New function.
* config/xtensa/xtensa-protos.h (xtensa_get_config_strings): New
declaration.
* gcc/config/xtensa/xtensa.h (TARGET_CPU_CPP_BUILTINS): Add new
'builtin' variable and loop through string array returned by the
xtensa_get_config_strings function call.
---
 gcc/config/xtensa/xtensa-config.c | 22 ++
 gcc/config/xtensa/xtensa-protos.h |  1 +
 gcc/config/xtensa/xtensa.h|  3 +++
 3 files changed, 26 insertions(+)

diff --git a/gcc/config/xtensa/xtensa-config.c 
b/gcc/config/xtensa/xtensa-config.c
index 3259867..3d242d1 100644
--- a/gcc/config/xtensa/xtensa-config.c
+++ b/gcc/config/xtensa/xtensa-config.c
@@ -13,6 +13,17 @@
 
 static struct xtensa_config xtensa_defconfig = XTENSA_CONFIG_INITIALIZER;
 
+#define _STRINGIFY(a) #a
+#define STRINGIFY(a) _STRINGIFY(a)
+
+#undef XTENSA_CONFIG_ENTRY
+#define XTENSA_CONFIG_ENTRY(a) "__" #a "=" STRINGIFY(a)
+
+static const char *xtensa_config_strings[] = {
+XTENSA_CONFIG_ENTRY_LIST,
+NULL,
+};
+
 #if !defined (HAVE_DLFCN_H) && defined (_WIN32)
 
 #define RTLD_LAZY 0  /* Dummy value.  */
@@ -115,3 +126,14 @@ struct xtensa_config *xtensa_get_config (void)
 }
   return config;
 }
+
+const char **xtensa_get_config_strings (void)
+{
+  static const char **config_strings;
+
+  if (!config_strings)
+config_strings = (const char **) xtensa_load_config 
("xtensa_config_strings",
+
_config_strings);
+
+  return config_strings;
+}
diff --git a/gcc/config/xtensa/xtensa-protos.h 
b/gcc/config/xtensa/xtensa-protos.h
index 38901b7..d8eba73 100644
--- a/gcc/config/xtensa/xtensa-protos.h
+++ b/gcc/config/xtensa/xtensa-protos.h
@@ -73,5 +73,6 @@ extern void xtensa_expand_prologue (void);
 extern void xtensa_expand_epilogue (void);
 extern void order_regs_for_local_alloc (void);
 extern enum reg_class xtensa_regno_to_class (int regno);
+extern const char **xtensa_get_config_strings (void);
 
 #endif /* !__XTENSA_PROTOS_H__ */
diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 7852f44..e1d2e74 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS()  \
   do { \
+const char **builtin;  \
 builtin_assert ("cpu=xtensa"); \
 builtin_assert ("machine=xtensa"); \
 builtin_define ("__xtensa__"); \
@@ -72,6 +73,8 @@ along with GCC; see the file COPYING3.  If not see
 builtin_define (TARGET_BIG_ENDIAN ? "__XTENSA_EB__" : "__XTENSA_EL__"); \
 if (!TARGET_HARD_FLOAT)\
   builtin_define ("__XTENSA_SOFT_FLOAT__");
\
+for (builtin = xtensa_get_config_strings (); *builtin; ++builtin)  \
+  builtin_define (*builtin);   \
   } while (0)
 
 #define CPP_SPEC " %(subtarget_cpp_spec) "
-- 
2.1.4



[RFC 2/5] gcc: xtensa: make configuration dynamic

2017-05-22 Thread Max Filippov
Now that XCHAL_* macros don't have to be preprocessor constants add
include/xtensa-dynconfig.h that defines them as fields of a structure
returned from the xtensa_get_config function.
Define that structure and fill it with default parameter values
specified in the include/xtensa-config.h.
Define reusable function xtensa_load_config that tries to load
configuration and return an address of an exported object from it.
Define the function xtensa_get_config that uses xtensa_load_config to
get structure xtensa_config, either dynamically configured or the
default.

2017-05-22  Max Filippov  
gcc/
* Makefile.in (PLUGIN_HEADERS): Add include/xtensa-dynconfig.h.
* config.gcc (xtensa*-*-*): Add xtensa-config.o to extra_objs.
* gcc/config/xtensa/t-xtensa (xtensa-config.o): New rule.
* gcc/config/xtensa/xtensa-config.c: New file.
* gcc/config/xtensa/xtensa.h (xtensa-config.h): Replace #include
with xtensa-dynconfig.h
(XCHAL_HAVE_MUL32_HIGH, XCHAL_HAVE_RELEASE_SYNC,
 XCHAL_HAVE_S32C1I, XCHAL_HAVE_THREADPTR,
 XCHAL_HAVE_FP_POSTINC): Drop definitions.

include/
* xtensa-dynconfig.h: New file.
---
 gcc/Makefile.in   |   2 +-
 gcc/config.gcc|   1 +
 gcc/config/xtensa/t-xtensa|   5 +
 gcc/config/xtensa/xtensa-config.c |  79 
 gcc/config/xtensa/xtensa.h|  17 +-
 include/xtensa-dynconfig.h| 373 ++
 6 files changed, 460 insertions(+), 17 deletions(-)
 create mode 100644 gcc/config/xtensa/xtensa-config.c
 create mode 100644 include/xtensa-dynconfig.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 2411671..f59a29f 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -3433,7 +3433,7 @@ PLUGIN_HEADERS = $(TREE_H) $(CONFIG_H) $(SYSTEM_H) 
coretypes.h $(TM_H) \
   tree-ssa-threadupdate.h inchash.h wide-int.h signop.h hash-map.h \
   hash-set.h dominance.h cfg.h cfgrtl.h cfganal.h cfgbuild.h cfgcleanup.h \
   lcm.h cfgloopmanip.h builtins.def chkp-builtins.def pass-instances.def \
-  params.list
+  params.list $(srcdir)/../include/xtensa-dynconfig.h
 
 # generate the 'build fragment' b-header-vars
 s-header-vars: Makefile
diff --git a/gcc/config.gcc b/gcc/config.gcc
index b8bb4d6..f65bb2e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -489,6 +489,7 @@ tic6x-*-*)
;;
 xtensa*-*-*)
extra_options="${extra_options} fused-madd.opt"
+   extra_objs="xtensa-config.o"
;;
 tilegx*-*-*)
cpu_type=tilegx
diff --git a/gcc/config/xtensa/t-xtensa b/gcc/config/xtensa/t-xtensa
index f762873..28d3756 100644
--- a/gcc/config/xtensa/t-xtensa
+++ b/gcc/config/xtensa/t-xtensa
@@ -17,3 +17,8 @@
 # .
 
 $(out_object_file): gt-xtensa.h
+
+xtensa-config.o: $(srcdir)/config/xtensa/xtensa-config.c \
+  $(CONFIG_H) $(SYSTEM_H) $(srcdir)/../include/xtensa-dynconfig.h \
+  $(srcdir)/../include/xtensa-config.h
+   $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $<
diff --git a/gcc/config/xtensa/xtensa-config.c 
b/gcc/config/xtensa/xtensa-config.c
new file mode 100644
index 000..296caf4
--- /dev/null
+++ b/gcc/config/xtensa/xtensa-config.c
@@ -0,0 +1,79 @@
+#include 
+#include 
+#define XTENSA_CONFIG_DEFINITION
+#include "xtensa-config.h"
+#include "xtensa-dynconfig.h"
+
+static struct xtensa_config xtensa_defconfig = XTENSA_CONFIG_INITIALIZER;
+
+void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED, void *def)
+{
+  static int init;
+#ifdef ENABLE_PLUGIN
+  static void *handle;
+  void *p;
+
+  if (!init)
+{
+  char *path = getenv ("XTENSA_GNU_CONFIG");
+
+  init = 1;
+  if (!path)
+   return def;
+  handle = dlopen (path, RTLD_LAZY);
+  if (!handle)
+   {
+ fprintf (stderr,
+  "XTENSA_GNU_CONFIG is defined but could not be loaded: %s\n",
+  dlerror ());
+ abort ();
+   }
+}
+  else if (!handle)
+{
+  return def;
+}
+
+  p = dlsym (handle, name);
+  if (!p)
+{
+  fprintf (stderr,
+  "XTENSA_GNU_CONFIG is loaded but symbol \"%s\" is not found: 
%s\n",
+  name, dlerror ());
+  abort ();
+}
+  return p;
+#else
+  if (!init)
+{
+  char *path = getenv ("XTENSA_GNU_CONFIG");
+
+  init = 1;
+  if (path)
+   {
+ fprintf (stderr,
+  "XTENSA_GNU_CONFIG is defined but plugin support is 
disabled\n");
+ abort ();
+   }
+}
+  return def;
+#endif
+}
+
+struct xtensa_config *xtensa_get_config (void)
+{
+  static struct xtensa_config *config;
+
+  if (!config)
+config = (struct xtensa_config *) xtensa_load_config ("xtensa_config",
+ _defconfig);
+
+  if (config->config_size < sizeof(struct xtensa_config))
+{
+  fprintf (stderr,
+  "Old or incompatible configuration is loaded: config_size = %ld, 
expected: 

[RFC 3/5] gcc: xtensa: support dynconfig on windows

2017-05-22 Thread Max Filippov
2017-05-22  Max Filippov  
gcc/
* config/xtensa/xtensa-config.c (dlfcn.h, windows.h): New
#include'd headers.
(RTLD_LAZY): New macro definition.
(dlopen, dlsym, dlclose, dlerror): New function definitions.
---
 gcc/config/xtensa/xtensa-config.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/gcc/config/xtensa/xtensa-config.c 
b/gcc/config/xtensa/xtensa-config.c
index 296caf4..3259867 100644
--- a/gcc/config/xtensa/xtensa-config.c
+++ b/gcc/config/xtensa/xtensa-config.c
@@ -4,8 +4,46 @@
 #include "xtensa-config.h"
 #include "xtensa-dynconfig.h"
 
+#if defined (HAVE_DLFCN_H)
+#include 
+#elif defined (_WIN32)
+#include 
+#define ENABLE_PLUGIN
+#endif
+
 static struct xtensa_config xtensa_defconfig = XTENSA_CONFIG_INITIALIZER;
 
+#if !defined (HAVE_DLFCN_H) && defined (_WIN32)
+
+#define RTLD_LAZY 0  /* Dummy value.  */
+
+static void *
+dlopen (const char *file, int mode ATTRIBUTE_UNUSED)
+{
+  return LoadLibrary (file);
+}
+
+static void *
+dlsym (void *handle, const char *name)
+{
+  return (void *) GetProcAddress ((HMODULE) handle, name);
+}
+
+static int ATTRIBUTE_UNUSED
+dlclose (void *handle)
+{
+  FreeLibrary ((HMODULE) handle);
+  return 0;
+}
+
+static const char *
+dlerror (void)
+{
+  return "Unable to load DLL.";
+}
+
+#endif /* !defined (HAVE_DLFCN_H) && defined (_WIN32)  */
+
 void *xtensa_load_config (const char *name ATTRIBUTE_UNUSED, void *def)
 {
   static int init;
-- 
2.1.4



[RFC 1/5] gcc: xtensa: allow XCHAL_* macros to be non-constant

2017-05-22 Thread Max Filippov
XCHAL_* macros from the xtensa-config.h are used in a number of places
that require them to be preprocessor constants. Rewrite these places so
that non-constant XCHAL_* definitions could be used there.

2017-05-22  Max Filippov  
gcc/
* config/xtensa/xtensa.c (xtensa_option_override): Append
MASK_CONST16 to target_flags in the absence of TARGET_L32R.
(hwloop_optimize, hwloop_fail, hwloop_pattern_reg,
 xtensa_doloop_hooks): Define unconditionally.
(xtensa_reorg_loops): Only call reorg_loops in the presence of
TARGET_LOOPS.
* config/xtensa/xtensa.h (TARGET_L32R): New definition.
(TARGET_DEFAULT): Remove XCHAL_HAVE_L32R condition and account
for it in xtensa_option_override.
(HARD_FRAME_POINTER_IS_FRAME_POINTER,
 HARD_FRAME_POINTER_IS_ARG_POINTER): New definitions.
---
 gcc/config/xtensa/xtensa.c | 18 +-
 gcc/config/xtensa/xtensa.h | 11 ---
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
index 0181dde..8b20c64 100644
--- a/gcc/config/xtensa/xtensa.c
+++ b/gcc/config/xtensa/xtensa.c
@@ -2181,6 +2181,13 @@ xtensa_option_override (void)
   int regno;
   machine_mode mode;
 
+  /* Use CONST16 in the absence of L32R.
+ Set it in the TARGET_OPTION_OVERRIDE to avoid dependency on xtensa
+ configuration in the xtensa-common.c  */
+
+  if (!TARGET_L32R)
+target_flags |= MASK_CONST16;
+
   if (!TARGET_BOOLEANS && TARGET_HARD_FLOAT)
 error ("boolean registers required for the floating-point option");
 
@@ -4053,8 +4060,6 @@ xtensa_invalid_within_doloop (const rtx_insn *insn)
 
 /* Optimize LOOP.  */
 
-#if TARGET_LOOPS
-
 static bool
 hwloop_optimize (hwloop_info loop)
 {
@@ -4241,14 +4246,9 @@ static struct hw_doloop_hooks xtensa_doloop_hooks =
 static void
 xtensa_reorg_loops (void)
 {
-  reorg_loops (false, _doloop_hooks);
-}
-#else
-static inline void
-xtensa_reorg_loops (void)
-{
+  if (TARGET_LOOPS)
+reorg_loops (false, _doloop_hooks);
 }
-#endif
 
 /* Implement the TARGET_MACHINE_DEPENDENT_REORG pass.  */
 
diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index c32e8ca..59d6b00 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -66,10 +66,9 @@ along with GCC; see the file COPYING3.  If not see
 #define TARGET_LOOPS   XCHAL_HAVE_LOOPS
 #define TARGET_WINDOWED_ABI(XSHAL_ABI == XTHAL_ABI_WINDOWED)
 #define TARGET_DEBUG   XCHAL_HAVE_DEBUG
+#define TARGET_L32RXCHAL_HAVE_L32R
 
-#define TARGET_DEFAULT \
-  ((XCHAL_HAVE_L32R? 0 : MASK_CONST16) |   \
-   MASK_SERIALIZE_VOLATILE)
+#define TARGET_DEFAULT (MASK_SERIALIZE_VOLATILE)
 
 #ifndef HAVE_AS_TLS
 #define HAVE_AS_TLS 0
@@ -362,6 +361,12 @@ extern char 
xtensa_hard_regno_mode_ok[][FIRST_PSEUDO_REGISTER];
 /* Base register for access to arguments of the function.  */
 #define ARG_POINTER_REGNUM (GP_REG_FIRST + 17)
 
+/* Hard frame pointer is neither frame nor arg pointer.
+   The definitions are here because actual hard frame pointer register
+   definition is not a preprocessor constant.  */
+#define HARD_FRAME_POINTER_IS_FRAME_POINTER 0
+#define HARD_FRAME_POINTER_IS_ARG_POINTER 0
+
 /* For now we don't try to use the full set of boolean registers.  Without
software pipelining of FP operations, there's not much to gain and it's
a real pain to get them reloaded.  */
-- 
2.1.4



[RFC 0/5] xtensa: support dynamic configuration

2017-05-22 Thread Max Filippov
Hi Sterling,

this is an RFC series that makes xtensa gcc dynamically configurable,
i.e. on a platform with shared library support single toolchain binary
becomes capable of building code for arbitrary xtensa configuration.
At the same time it fully preserves the traditional way of configuring
using xtensa configuration overlay.

Currently xtensa toolchain needs to be patched and rebuilt for every
new xtensa processor configuration. This has a number of downsides:
- toolchain builders need to change the toolchain source code, and
  because xtensa configuration overlay is not a patch, this change is
  special, embedding it into the toolchain build process gets
  backpressure.
- toolchain built for one configuration is usually not usable for any
  other configuration. It's not possible for a distribution to provide
  reusable prebuilt xtensa toolchain.

This series allows building the toolchain (including target libraries)
without its source code modification. Built toolchain takes configuration
parameters from the shared object specified in the environment variable.
That shared object may be built by the following project:

  https://github.com/jcmvbkbc/xtensa-dynconfig

The same shared object is used for gcc, all binutils and for gdb.
Xtensa core specific information needed to build that shared object is
taken from the configuration overlay.

Both gcc and binutils-gdb get new shared header file
include/xtensa-dynconfig.h that provides definition of configuration
data structure, initialization macros, redefines XCHAL_* macros to
access this structure and declares function for loading configuration
dynamically.

Max Filippov (5):
  gcc: xtensa: allow XCHAL_* macros to be non-constant
  gcc: xtensa: make configuration dynamic
  gcc: xtensa: support dynconfig on windows
  gcc: xtensa: add __XCHAL_* builtins
  libgcc: xtensa: use built-in configuration

 gcc/Makefile.in   |   2 +-
 gcc/config.gcc|   1 +
 gcc/config/xtensa/t-xtensa|   5 +
 gcc/config/xtensa/xtensa-config.c | 139 ++
 gcc/config/xtensa/xtensa-protos.h |   1 +
 gcc/config/xtensa/xtensa.c|  18 +-
 gcc/config/xtensa/xtensa.h|  31 ++--
 include/xtensa-config-builtin.h   | 191 +++
 include/xtensa-dynconfig.h| 373 ++
 libgcc/config/xtensa/crti.S   |   2 +-
 libgcc/config/xtensa/crtn.S   |   2 +-
 libgcc/config/xtensa/lib1funcs.S  |   2 +-
 libgcc/config/xtensa/lib2funcs.S  |   2 +-
 13 files changed, 736 insertions(+), 33 deletions(-)
 create mode 100644 gcc/config/xtensa/xtensa-config.c
 create mode 100644 include/xtensa-config-builtin.h
 create mode 100644 include/xtensa-dynconfig.h

-- 
2.1.4



Re: [PATCH], PR target/80718, Improve PowerPC splat double word

2017-05-22 Thread Segher Boessenkool
On Mon, May 22, 2017 at 02:32:44PM -0400, Michael Meissner wrote:
> The register allocator did not use the load with splat instruction (LXVDSX)
> because all of the loads were register+offset.  For the scalar values that it
> could load into the FPR registers, it used the normal register+offset load
> (d-form).  For the other scalar values that would wind up in the traditional
> Altivec registers, the register allocator decided to load up the value into a
> GPR register and do a direct move.

> The patch splits the splat into a register splat and a memory splat.  This
> forces the register allocator to convert the load to the indexed form which 
> the
> LXVDSX instruction uses.

> Can I apply this patch to the trunk, and later apply it to the GCC 7 and 6
> branches?

Please add a comment near the new instruction patterns saying why reg and
mem are separate.  Okay for trunk and backports with that.  Thanks!


Segher


> [gcc]
> 2017-05-22  Michael Meissner  
> 
>   PR target/80718
>   * config/rs6000/vsx.md (vsx_splat_, VSX_D iterator): Split
>   V2DF/V2DI splat into two separate patterns, one that handles
>   registers, and the other that only handles memory.  Drop support
>   for splatting from a GPR on ISA 2.07 and then splitting the
>   splat into direct move and splat.
>   (vsx_splat__reg): Likewise.
>   (vsx_splat__mem): Likewise.
> 
> [gcc/testsuite]
> 2017-05-22  Michael Meissner  
> 
>   PR target/80718
>   * gcc.target/powerpc/pr80718.c: New test.


Re: [PATCH, rs6000, committed] Fix gcc.target/powerpc/p8-vec-xl-xst.c target selector

2017-05-22 Thread Segher Boessenkool
On Mon, May 22, 2017 at 08:14:13PM +, Joseph Myers wrote:
> > The subject test requires little endian, but the target selector doesn't
> > specify this.  This patch fixes that.  Tested on BE/LE P8 systems,
> > committed as obvious.
> 
> It's not obvious; it's wrong.  You can configure for a BE default while 
> supporting LE, using appropriate --enable-targets options.  That's what 
> config/rs6000/t-linux64bele is for, for example.  In such cases, this test 
> should be enabled when testing LE multilibs.  Likewise, you can configure 
> for LE default while supporting BE, and then the test should be disabled 
> when testing BE multilibs.
> 
> For any target property that can depend on the multilib, you have to use a 
> general target pattern such as powerpc*-*-*, then test effective-target 
> keywords for any per-multilib properties that are relevant (such as 
> endianness in this case).  Testing for BE/LE, or for 32-bit/64-bit, via 
> target triplet patterns, is always wrong in powerpc tests, just as it's 
> always wrong for x86 tests to support one of x86_64 and i?86 but not the 
> other (those should similarly use effective-targets as needed).

Yes, all this is true.  But the patch is an obvious improvement, and in
line with the many other tests where we have this test for powerpc64le-*-*.

As far as I know no one tests LE on a BE system, and the other way around.
But yes you are right, it should be supported, just like powerpc64 on a
non-powerpc64 system (and importantly, the other way around), for which
we currently use lp64 (which isn't exactly right), except of course the
tests that do it completely wrong :-/


Segher


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-22 Thread Jason Merrill
On Mon, May 22, 2017 at 2:22 PM, Jason Merrill  wrote:
> On Mon, May 22, 2017 at 12:28 PM, Martin Sebor  wrote:
>> On 05/19/2017 11:26 AM, Bernd Edlinger wrote:
>>>
>>> On 05/19/17 19:05, Dominique d'Humières wrote:

 Hi Bernd,

 Your patches are causing troubles when I try to do "incremental updates
 »:

 After revision r248290 it fails with

 ../../work/gcc/cp/init.c:4916:10: fatal error: gt-cp-init.h: No such file
 or directory
   #include "gt-cp-init.h »

 and after r248242 with

 ../../work/gcc/c-family/c-format.c:4215:10: fatal error:
 gt-c-family-c-format.h: No such file or directory
   #include "gt-c-family-c-format.h »

 Note that after r248242 a full bootstrap succeeded (don’t know yet for
 r248290).

 Is there a way to fix that?

>>>
>>> No, unfortunately it looks like incremental does not work in this case.
>>>
>>> You can try to remove gcc/s-gtyp-input, maybe it un-breaks your
>>> build.  However, I gave up at that point and did a full bootstrap
>>> instead.
>>
>> I also keep running into this error.  Removing my build directory
>> and starting from scratch usually fixes it, but it seems that almost
>> every time git pull or svn update brings in new changes it comes back.
>
> I've found that the key is ./config.status --recheck so that the
> GTFILES variable gets updated from config-lang.in.  I'm not sure if
> plain ./config.status is also needed, and/or removing the gtype stuff
> from the build directory.

Nope, just

 ./config.status --recheck

Jason


Re: [Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-22 Thread Tim Song
On Mon, May 22, 2017 at 4:14 PM, Tim Song  wrote:
> assuming core issue 1227's resolution

Actually, 1227 doesn't touch default template arguments :( OTOH, the
paragraph dealing with default template arguments seems to be full of
issues - it says "invalid type" rather than "invalid type or
expression", and "above" when the description is actually "below".

Anyway, that should be easily fixable by moving the SFINAE into the
type of a non-type parameter, I think.


Re: [Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-22 Thread Tim Song
On Mon, May 22, 2017 at 9:21 AM, Jonathan Wakely  wrote:
> On 19/05/17 22:40 -0700, Tim Shen via libstdc++ wrote:
>>
>> diff --git a/libstdc++-v3/include/std/variant
>> b/libstdc++-v3/include/std/variant
>> index 0e04a820d69..b9824a5182c 100644
>> --- a/libstdc++-v3/include/std/variant
>> +++ b/libstdc++-v3/include/std/variant
>> @@ -936,9 +936,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   noexcept((is_nothrow_move_constructible_v<_Types> && ...)) =
>> default;
>>
>>   template> +  typename = enable_if_t, variant>>,
>>typename =
>> enable_if_t<__exactly_once<__accepted_type<_Tp&&>>
>> - && is_constructible_v<__accepted_type<_Tp&&>,
>> _Tp&&>
>> - && !is_same_v, variant>>>
>> + && is_constructible_v<__accepted_type<_Tp&&>,
>> _Tp&&>>>
>
>
> Does this definitely short-circuit? I seem to recall a similar case
> where either Clang or GCC (I think it was Clang) was evaluating the
> second default template argument even though the first had produce a
> substition failure.
>
> If we need to guarantee it short-circuits then we'd want:
>
>  templatetypename = enable_if_t<__and_<
>  __not_, variant>>,
>  __bool_constant<
>__exactly_once<__accepted_type<_Tp&&>>
>&& 
> is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>>>
>
> i.e. use __and_< is-this-type, everything-else> where
> "everything-else" still uses && to avoid making the instantiations too
> deep.
>
> Also, this is another place where we could use an __is_samey
> trait that does is_same.
>

The thing that needs to be short-circuited out is the evaluation of
__accepted_type<_Tp&&>, which starts the tower of turtles.

The original patch does that (assuming core issue 1227's resolution),
but the __and_ version doesn't; __and_ only short circuits the
immediate parameter, not things used in forming it.


Re: [PATCH, rs6000, committed] Fix gcc.target/powerpc/p8-vec-xl-xst.c target selector

2017-05-22 Thread Joseph Myers
On Mon, 22 May 2017, Bill Schmidt wrote:

> Hi,
> 
> The subject test requires little endian, but the target selector doesn't
> specify this.  This patch fixes that.  Tested on BE/LE P8 systems,
> committed as obvious.

It's not obvious; it's wrong.  You can configure for a BE default while 
supporting LE, using appropriate --enable-targets options.  That's what 
config/rs6000/t-linux64bele is for, for example.  In such cases, this test 
should be enabled when testing LE multilibs.  Likewise, you can configure 
for LE default while supporting BE, and then the test should be disabled 
when testing BE multilibs.

For any target property that can depend on the multilib, you have to use a 
general target pattern such as powerpc*-*-*, then test effective-target 
keywords for any per-multilib properties that are relevant (such as 
endianness in this case).  Testing for BE/LE, or for 32-bit/64-bit, via 
target triplet patterns, is always wrong in powerpc tests, just as it's 
always wrong for x86 tests to support one of x86_64 and i?86 but not the 
other (those should similarly use effective-targets as needed).

-- 
Joseph S. Myers
jos...@codesourcery.com


[PATCH, rs6000, committed] Fix gcc.target/powerpc/p8-vec-xl-xst.c target selector

2017-05-22 Thread Bill Schmidt
Hi,

The subject test requires little endian, but the target selector doesn't
specify this.  This patch fixes that.  Tested on BE/LE P8 systems,
committed as obvious.

Thanks,
Bill


2017-05-22  Bill Schmidt  

* gcc.target/powerpc/p8-vec-xl-xst.c: Fix target string to
LE-only.


Index: gcc/testsuite/gcc.target/powerpc/p8-vec-xl-xst.c
===
--- gcc/testsuite/gcc.target/powerpc/p8-vec-xl-xst.c(revision 248347)
+++ gcc/testsuite/gcc.target/powerpc/p8-vec-xl-xst.c(working copy)
@@ -1,4 +1,4 @@
-/* { dg-do compile { target { powerpc*-*-* } } } */
+/* { dg-do compile { target { powerpc64le-*-* } } } */
 /* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
 /* { dg-require-effective-target powerpc_p8vector_ok } */
 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power8" } } */



Re: MinGW compilation warnings in libiberty's waitpid.c

2017-05-22 Thread DJ Delorie

Eli Zaretskii  writes:
> Hmm... no, this doesn't solve the problem.  The expansion of AC_LIBOBJ
> for waitpid is gone from the configure script, but the value of
> LIBOBJS in libiberty/Makefile still includes waitpid.o.  What else is
> related to this?

After re-reading the sources a bit, I come to the following
conclusions...

* $funcs is a list of functions libiberty should provide if the host
  doesn't have them.

* We can override what the host *has* but not what it *shouldn't* have.

Since (or "if") nobody will (should) use waitpid() on mingw anyway, and
since libiberty really wants to include waitpid.o, how difficult would
it be to use some #ifdefs to have waitpid() just return an error on
mingw?  That at least gets past the mingw build problem.

> One caveat: I needed to hack config/override.m4 to allow me to run
> autoconf 2.69 I have installed, because otherwise it insists on
> autoconf 2.64 which I don't have.  I hope this isn't the reason for
> the incomplete solution.

I have many versions of autoconf installed, each in their own
directories, and add the right one to my $PATH on a per-project basis.
Autoconf works just fine that way, and there have been plenty of cases
of autoconf output changing in, er, "unexpected" ways across autoconf
releases.  If you regen configure and an "svn diff" (or git diff) shows
unexpected changes, check your autoconf :-)

Same for automake and autogen.


[committed] Re: C PATCH to kill c_save_expr or towards delayed folding for the C FE

2017-05-22 Thread Jakub Jelinek
Hi!

On Fri, May 12, 2017 at 09:48:28PM +0200, Jakub Jelinek wrote:
> On Fri, May 12, 2017 at 09:37:27PM +0200, Marek Polacek wrote:
> > @@ -565,6 +564,25 @@ c_fully_fold_internal (tree expr, bool in_init, bool 
> > *maybe_const_operands,
> >  appropriate in any particular case.  */
> >gcc_unreachable ();
> >  
> > +case SAVE_EXPR:
> > +  /* Make sure to fold the contents of a SAVE_EXPR exactly once.  */
> > +  if (!SAVE_EXPR_FOLDED_P (expr))
> > +   {
> > + op0 = TREE_OPERAND (expr, 0);
> > + op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
> > +  maybe_const_itself, for_int_const);
> > + /* Don't wrap the folded tree in a SAVE_EXPR if we don't
> > +have to.  */
> > + if (tree_invariant_p (op0))
> > +   ret = op0;
> > + else
> > +   {
> > + TREE_OPERAND (expr, 0) = op0;
> > + SAVE_EXPR_FOLDED_P (expr) = true;
> > +   }
> > +   }
> 
> Wouldn't it be better to guard with if (!SAVE_EXPR_FOLDED_P (expr))
> only c_fully_fold_internal recursion on the operand
> and then use if (tree_invariant_p (op0)) unconditionally?

After discussions on IRC with Marek, we concluded the above is bad, because
if there is a huge SAVE_EXPR operand that c_fully_fold_internal folds into
an invariant (worse if it contains many other SAVE_EXPRs with such
properties), the current trunk code will fold it over and over again.

Fixed thusly, acked by Marek on IRC, bootstrapped/regtested on x86_64-linux
and i686-linux, committed to trunk.

2017-05-22  Jakub Jelinek  

* c-fold.c (c_fully_fold_internal): Save the c_fully_fold_internal
result for SAVE_EXPR operand and set SAVE_EXPR_FOLDED_P even if
it returned invariant.  Call tree_invariant_p unconditionally
afterwards to decide whether to return expr or op0.

--- gcc/c/c-fold.c  2017-05-22 10:49:38.669161353 +0200
+++ gcc/c/c-fold.c  2017-05-22 18:09:49.358107221 +0200
@@ -566,21 +566,17 @@ c_fully_fold_internal (tree expr, bool i
 
 case SAVE_EXPR:
   /* Make sure to fold the contents of a SAVE_EXPR exactly once.  */
+  op0 = TREE_OPERAND (expr, 0);
   if (!SAVE_EXPR_FOLDED_P (expr))
{
- op0 = TREE_OPERAND (expr, 0);
  op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
   maybe_const_itself, for_int_const);
- /* Don't wrap the folded tree in a SAVE_EXPR if we don't
-have to.  */
- if (tree_invariant_p (op0))
-   ret = op0;
- else
-   {
- TREE_OPERAND (expr, 0) = op0;
- SAVE_EXPR_FOLDED_P (expr) = true;
-   }
+ TREE_OPERAND (expr, 0) = op0;
+ SAVE_EXPR_FOLDED_P (expr) = true;
}
+  /* Return the SAVE_EXPR operand if it is invariant.  */
+  if (tree_invariant_p (op0))
+   ret = op0;
   goto out;
 
 default:


Jakub


[committed] Fix OpenMP VLA firstprivatization on task (PR middle-end/80809)

2017-05-22 Thread Jakub Jelinek
Hi!

This PR shows another bug, the computation of the size argument
for GOMP_task call could include uninitialized variable uses.

The problem is that the task arg_size needs to be finalized only
after mwe return from omp_low_1 of the task construct, thus it
is hard to gimplify it somewhere, but it can include references
to temporaries that need to be remapped if in nested constructs.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk, queued for release branches.

2017-05-22  Jakub Jelinek  

PR middle-end/80809
* omp-low.c (finish_taskreg_remap): New function.
(finish_taskreg_scan): If unit size of ctx->record_type
is non-constant, unshare the size expression and replace
decls in it with possible outer var refs.

* testsuite/libgomp.c/pr80809-2.c: New test.
* testsuite/libgomp.c/pr80809-3.c: New test.

--- gcc/omp-low.c.jj2017-05-22 11:34:51.0 +0200
+++ gcc/omp-low.c   2017-05-22 18:31:30.045010460 +0200
@@ -1913,6 +1913,29 @@ scan_omp_task (gimple_stmt_iterator *gsi
 }
 }
 
+/* Helper function for finish_taskreg_scan, called through walk_tree.
+   If maybe_lookup_decl_in_outer_context returns non-NULL for some
+   tree, replace it in the expression.  */
+
+static tree
+finish_taskreg_remap (tree *tp, int *walk_subtrees, void *data)
+{
+  if (VAR_P (*tp))
+{
+  omp_context *ctx = (omp_context *) data;
+  tree t = maybe_lookup_decl_in_outer_ctx (*tp, ctx);
+  if (t != *tp)
+   {
+ if (DECL_HAS_VALUE_EXPR_P (t))
+   t = unshare_expr (DECL_VALUE_EXPR (t));
+ *tp = t;
+   }
+  *walk_subtrees = 0;
+}
+  else if (IS_TYPE_OR_DECL_P (*tp))
+*walk_subtrees = 0;
+  return NULL_TREE;
+}
 
 /* If any decls have been made addressable during scan_omp,
adjust their fields if needed, and layout record types
@@ -2033,6 +2056,11 @@ finish_taskreg_scan (omp_context *ctx)
layout_type (ctx->srecord_type);
   tree t = fold_convert_loc (loc, long_integer_type_node,
 TYPE_SIZE_UNIT (ctx->record_type));
+  if (TREE_CODE (t) != INTEGER_CST)
+   {
+ t = unshare_expr (t);
+ walk_tree (, finish_taskreg_remap, ctx, NULL);
+   }
   gimple_omp_task_set_arg_size (ctx->stmt, t);
   t = build_int_cst (long_integer_type_node,
 TYPE_ALIGN_UNIT (ctx->record_type));
--- libgomp/testsuite/libgomp.c/pr80809-2.c.jj  2017-05-22 18:36:28.950298209 
+0200
+++ libgomp/testsuite/libgomp.c/pr80809-2.c 2017-05-22 14:28:40.0 
+0200
@@ -0,0 +1,35 @@
+/* PR middle-end/80809 */
+/* { dg-do run } */
+
+__attribute__((noinline, noclone)) void
+foo (int x)
+{
+  int i, v[x], w[16];
+  for (i = 0; i < x; i++)
+v[i] = i;
+  for (i = 0; i < 16; i++)
+w[i] = 0;
+#pragma omp parallel
+#pragma omp single
+  for (i = 0; i < 16; i++)
+#pragma omp task firstprivate (v)
+{
+  int j;
+  for (j = 0; j < x; j++)
+   v[j] += i;
+  for (j = 0; j < x; j++)
+   w[i] += v[j];
+}
+  for (i = 0; i < 16; i++)
+if (w[i] != (x - 1) * x / 2 + x * i)
+  __builtin_abort ();
+}
+
+int
+main ()
+{
+  foo (4);
+  foo (27);
+  foo (196);
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/pr80809-3.c.jj  2017-05-22 18:36:32.252257201 
+0200
+++ libgomp/testsuite/libgomp.c/pr80809-3.c 2017-05-22 18:34:46.0 
+0200
@@ -0,0 +1,42 @@
+/* PR middle-end/80809 */
+/* { dg-do run } */
+
+__attribute__((noinline, noclone)) void
+foo (int x)
+{
+  int i, v[x], w[16];
+  for (i = 0; i < x; i++)
+v[i] = i;
+  for (i = 0; i < 16; i++)
+w[i] = 0;
+#pragma omp parallel
+#pragma omp single
+  {
+int z[x];
+for (i = 0; i < x; i++)
+  z[0] = 0;
+for (i = 0; i < 16; i++)
+#pragma omp task firstprivate (z) firstprivate (v)
+  {
+   int j;
+   for (j = 0; j < x; j++)
+ z[j] = i;
+   for (j = 0; j < x; j++)
+ v[j] += z[j];
+   for (j = 0; j < x; j++)
+ w[i] += v[j];
+  }
+  }
+  for (i = 0; i < 16; i++)
+if (w[i] != (x - 1) * x / 2 + x * i)
+  __builtin_abort ();
+}
+
+int
+main ()
+{
+  foo (4);
+  foo (27);
+  foo (196);
+  return 0;
+}

Jakub


[committed] Fix OpenMP VLA implicit determination in task (PR middle-end/80809)

2017-05-22 Thread Jakub Jelinek
Hi!

If a VLA is shared e.g. on parallel or task construct, we firstprivatize
a pointer pointing to it, and add a private VLA variable that will have a
DECL_VALUE_EXPR for debug info purposes.  But, standardwise, the VLA is
still shared on the parallel/task, it is just implementation detail what we
are doing with it.  So, for the purpose of implicit data sharing
determination we want to treat it still as shared and only when emitting or
changing the clause we want to emit private with OMP_CLAUSE_PRIVATE_DEBUG.

The following patch does that, bootstrapped/regtested on x86_64-linux and
i686-linux, committed to trunk, queued for release branches.

2017-05-22  Jakub Jelinek  

PR middle-end/80809
* gimplify.c (omp_add_variable): For GOVD_DEBUG_PRIVATE use
GOVD_SHARED rather than GOVD_PRIVATE with it.
(gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses): Expect
GOVD_SHARED rather than GOVD_PRIVATE with GOVD_DEBUG_PRIVATE.

* testsuite/libgomp.c/pr80809-1.c: New test.

--- gcc/gimplify.c.jj   2017-05-22 10:50:07.0 +0200
+++ gcc/gimplify.c  2017-05-22 13:07:00.520162436 +0200
@@ -6693,7 +6693,7 @@ omp_add_variable (struct gimplify_omp_ct
 of PRIVATE.  The sharing would take place via the pointer variable
 which we remapped above.  */
   if (flags & GOVD_SHARED)
-   flags = GOVD_PRIVATE | GOVD_DEBUG_PRIVATE
+   flags = GOVD_SHARED | GOVD_DEBUG_PRIVATE
| (flags & (GOVD_SEEN | GOVD_EXPLICIT));
 
   /* We're going to make use of the TYPE_SIZE_UNIT at least in the
@@ -8616,7 +8616,7 @@ gimplify_adjust_omp_clauses_1 (splay_tre
 return 0;
   if (flags & GOVD_DEBUG_PRIVATE)
 {
-  gcc_assert ((flags & GOVD_DATA_SHARE_CLASS) == GOVD_PRIVATE);
+  gcc_assert ((flags & GOVD_DATA_SHARE_CLASS) == GOVD_SHARED);
   private_debug = true;
 }
   else if (flags & GOVD_MAP)
@@ -8878,7 +8878,7 @@ gimplify_adjust_omp_clauses (gimple_seq
{
  gcc_assert ((n->value & GOVD_DEBUG_PRIVATE) == 0
  || ((n->value & GOVD_DATA_SHARE_CLASS)
- == GOVD_PRIVATE));
+ == GOVD_SHARED));
  OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_PRIVATE);
  OMP_CLAUSE_PRIVATE_DEBUG (c) = 1;
}
--- libgomp/testsuite/libgomp.c/pr80809-1.c.jj  2017-05-22 12:52:11.445135718 
+0200
+++ libgomp/testsuite/libgomp.c/pr80809-1.c 2017-05-22 12:51:10.0 
+0200
@@ -0,0 +1,29 @@
+/* PR middle-end/80809 */
+/* { dg-do run } */
+
+__attribute__((noinline, noclone)) void
+foo (int x)
+{
+  int i, j, v[x], *w[16];
+  for (i = 0; i < x; i++)
+v[i] = i;
+#pragma omp parallel
+#pragma omp single
+  for (i = 0; i < 16; i++)
+  /* Make sure v is implicitly determined shared in task, because it
+ is shared on the parallel.  */
+#pragma omp task private (j)
+w[i] = v;
+  for (i = 0; i < 16; i++)
+if (w[i] != v)
+  __builtin_abort ();
+}
+
+int
+main ()
+{
+  foo (4);
+  foo (27);
+  foo (196);
+  return 0;
+}

Jakub


[committed] Fix OpenMP array reduction handling in orphaned workshare (PR middle-end/80853)

2017-05-22 Thread Jakub Jelinek
Hi!

For pointer based array sections, we are not requiring the pointer to be
shared in outer context and it might be not shared (e.g. function argument
or just a private pointer initialized to point to something shared etc.),
which is right, but we shouldn't require it during lowering either.

This patch fixes ICE on it.  Bootstrapped/regtested on x86_64-linux and
i686-linux, committed to trunk, queued for release branches.

2017-05-22  Jakub Jelinek  

PR middle-end/80853
* omp-low.c (lower_reduction_clauses): Pass OMP_CLAUSE_PRIVATE
as last argument to build_outer_var_ref for pointer bases of array
section reductions.

* testsuite/libgomp.c/pr80853.c: New test.

--- gcc/omp-low.c.jj2017-04-21 08:14:29.436790613 +0200
+++ gcc/omp-low.c   2017-05-22 11:34:51.085746641 +0200
@@ -5140,15 +5140,25 @@ lower_reduction_clauses (tree clauses, g
   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
continue;
 
+  enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION;
   orig_var = var = OMP_CLAUSE_DECL (c);
   if (TREE_CODE (var) == MEM_REF)
{
  var = TREE_OPERAND (var, 0);
  if (TREE_CODE (var) == POINTER_PLUS_EXPR)
var = TREE_OPERAND (var, 0);
- if (TREE_CODE (var) == INDIRECT_REF
- || TREE_CODE (var) == ADDR_EXPR)
+ if (TREE_CODE (var) == ADDR_EXPR)
var = TREE_OPERAND (var, 0);
+ else
+   {
+ /* If this is a pointer or referenced based array
+section, the var could be private in the outer
+context e.g. on orphaned loop construct.  Pretend this
+is private variable's outer reference.  */
+ ccode = OMP_CLAUSE_PRIVATE;
+ if (TREE_CODE (var) == INDIRECT_REF)
+   var = TREE_OPERAND (var, 0);
+   }
  orig_var = var;
  if (is_variable_sized (var))
{
@@ -5162,7 +5172,7 @@ lower_reduction_clauses (tree clauses, g
   new_var = lookup_decl (var, ctx);
   if (var == OMP_CLAUSE_DECL (c) && omp_is_reference (var))
new_var = build_simple_mem_ref_loc (clause_loc, new_var);
-  ref = build_outer_var_ref (var, ctx);
+  ref = build_outer_var_ref (var, ctx, ccode);
   code = OMP_CLAUSE_REDUCTION_CODE (c);
 
   /* reduction(-:var) sums up the partial results, so it acts
--- libgomp/testsuite/libgomp.c/pr80853.c.jj2017-05-22 11:28:50.060287195 
+0200
+++ libgomp/testsuite/libgomp.c/pr80853.c   2017-05-22 11:28:29.0 
+0200
@@ -0,0 +1,29 @@
+/* PR middle-end/80853 */
+/* { dg-do run } */
+
+__attribute__((noinline, noclone)) void
+foo (int *p)
+{
+  #pragma omp for reduction(+:p[:4])
+  for (int i = 0; i < 64; i++)
+{
+  p[0] += i;
+  p[1] += i / 2;
+  p[2] += 2 * i;
+  p[3] += 3 * i;
+}
+}
+
+int
+main ()
+{
+  int p[4] = { 0, 0, 0, 0 };
+  #pragma omp parallel
+  foo (p);
+  if (p[0] != 63 * 64 / 2
+  || p[1] != 31 * 32
+  || p[2] != 63 * 64
+  || p[3] != 3 * 63 * 64 / 2)
+__builtin_abort ();
+  return 0;
+}

Jakub


[PATCH], PR target/80718, Improve PowerPC splat double word

2017-05-22 Thread Michael Meissner
When I was comparing spec 2006 numbers between GCC 6.3 and 7.1, there was one
benchmark that was noticeably slower (milc).  In looking at the code generated,
the #1 hot function (mult_adj_su3_mat_vec) had some cases where automatic
vectorization generated splat of double from memory.

The register allocator did not use the load with splat instruction (LXVDSX)
because all of the loads were register+offset.  For the scalar values that it
could load into the FPR registers, it used the normal register+offset load
(d-form).  For the other scalar values that would wind up in the traditional
Altivec registers, the register allocator decided to load up the value into a
GPR register and do a direct move.

Now, it turns out that while the above code is inefficient, it is not a cause
for slow down of the milc benchmark.  However there might be other places where
using a load, direct move, and double word permute are causing a performance
problem, so I made this patch.

The patch splits the splat into a register splat and a memory splat.  This
forces the register allocator to convert the load to the indexed form which the
LXVDSX instruction uses.  I did a spec 2006 run with these changes, and there
were no significant performance differences with this patch.

In the mult_adj_su3_mat_vec function, there were previously 5 GPR loads, direct
move, and permute sequences along with one LXVDSK.  With this patch, those GPR
loads have been replaced with LXVDSKs.

Can I apply this patch to the trunk, and later apply it to the GCC 7 and 6
branches?

[gcc]
2017-05-22  Michael Meissner  

PR target/80718
* config/rs6000/vsx.md (vsx_splat_, VSX_D iterator): Split
V2DF/V2DI splat into two separate patterns, one that handles
registers, and the other that only handles memory.  Drop support
for splatting from a GPR on ISA 2.07 and then splitting the
splat into direct move and splat.
(vsx_splat__reg): Likewise.
(vsx_splat__mem): Likewise.

[gcc/testsuite]
2017-05-22  Michael Meissner  

PR target/80718
* gcc.target/powerpc/pr80718.c: New test.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797
Index: gcc/config/rs6000/vsx.md
===
--- gcc/config/rs6000/vsx.md(revision 248266)
+++ gcc/config/rs6000/vsx.md(working copy)
@@ -3066,29 +3066,36 @@ (define_expand "vsx_mergeh_"
 })
 
 ;; V2DF/V2DI splat
-(define_insn_and_split "vsx_splat_"
-  [(set (match_operand:VSX_D 0 "vsx_register_operand"
-   "=,,we,")
+(define_expand "vsx_splat_"
+  [(set (match_operand:VSX_D 0 "vsx_register_operand")
(vec_duplicate:VSX_D
-(match_operand: 1 "splat_input_operand"
-   ",Z,b, wA")))]
+(match_operand: 1 "input_operand")))]
+  "VECTOR_MEM_VSX_P (mode)"
+{
+  rtx op1 = operands[1];
+  if (MEM_P (op1))
+operands[1] = rs6000_address_for_fpconvert (op1);
+  else if (!REG_P (op1))
+op1 = force_reg (mode, op1);
+})
+
+(define_insn "vsx_splat__reg"
+  [(set (match_operand:VSX_D 0 "vsx_register_operand" "=,?we")
+   (vec_duplicate:VSX_D
+(match_operand: 1 "gpc_reg_operand" ",b")))]
   "VECTOR_MEM_VSX_P (mode)"
   "@
xxpermdi %x0,%x1,%x1,0
-   lxvdsx %x0,%y1
-   mtvsrdd %x0,%1,%1
-   #"
-  "&& reload_completed && TARGET_POWERPC64 && !TARGET_P9_VECTOR
-   && int_reg_operand (operands[1], mode)"
-  [(set (match_dup 2)
-   (match_dup 1))
-   (set (match_dup 0)
-   (vec_duplicate:VSX_D (match_dup 2)))]
-{
-  operands[2] = gen_rtx_REG (mode, reg_or_subregno (operands[0]));
-}
-  [(set_attr "type" "vecperm,vecload,vecperm,vecperm")
-   (set_attr "length" "4,4,4,8")])
+   mtvsrdd %x0,%1,%1"
+  [(set_attr "type" "vecperm")])
+
+(define_insn "vsx_splat__mem"
+  [(set (match_operand:VSX_D 0 "vsx_register_operand" "=")
+   (vec_duplicate:VSX_D
+(match_operand: 1 "memory_operand" "Z")))]
+  "VECTOR_MEM_VSX_P (mode)"
+  "lxvdsx %x0,%y1"
+  [(set_attr "type" "vecload")])
 
 ;; V4SI splat support
 (define_insn "vsx_splat_v4si"
Index: gcc/testsuite/gcc.target/powerpc/pr80718.c
===
--- gcc/testsuite/gcc.target/powerpc/pr80718.c  (revision 0)
+++ gcc/testsuite/gcc.target/powerpc/pr80718.c  (revision 0)
@@ -0,0 +1,298 @@
+/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_p8vector_ok } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power8" } } */
+/* { dg-options "-mcpu=power8 -O3 -ffast-math" } */
+
+/* Taken from the Spec 2006 milc brenchmark.  Ultimately, GCC wants to generate
+   a DF splat from offsettable memory.  The 

Re: [PATCH] [i386] Recompute the frame layout less often

2017-05-22 Thread Bernd Edlinger
On 05/19/17 05:17, Daniel Santos wrote:
> On 05/18/2017 08:37 AM, Bernd Edlinger wrote:
>> On 05/17/17 04:01, Daniel Santos wrote:
 -  if (ignore_outlined && cfun->machine->call_ms2sysv
 -  && in_hard_reg_set_p (stub_managed_regs, DImode, regno))
 -return false;
 +  if (ignore_outlined && cfun->machine->call_ms2sysv)
 +{
 +  /* Registers who's save & restore will be managed by stubs
 called from
 + pro/epilogue.  */
 +  HARD_REG_SET stub_managed_regs;
 +  xlogue_layout::compute_stub_managed_regs (stub_managed_regs);

 +  if (in_hard_reg_set_p (stub_managed_regs, DImode, regno))
 +return false;
 +}
 +
 if (crtl->drap_reg
 && regno == REGNO (crtl->drap_reg)
 && !cfun->machine->no_drap_save_restore)
>>> This makes no sense.  The entire purpose of stub_managed_regs is to
>>> cache the result of xlogue_layout::compute_stub_managed_regs() and this
>>> would unnecessarily repeat that calculation for each time
>>> ix86_save_reg() is called.  Since
>>> xlogue_layout::compute_stub_managed_regs() calls ix86_save_reg many
>>> times, this makes it even worse.Which registers are being saved
>>> out-of-line and inline MUST be known at the time the stack layout is
>>> determined.  So stub_managed_regsshould either be left a TU static or
>>> just moved to struct machine_function.
>>>
>>> As an aside, I've noticed that xlogue_layout::compute_stub_managed_regs
>>> is calling ix86_save_reg (which isn't trivial) more often than it really
>>> has to, so I've refactored it.
>>>
>> Well, meanwhile I think the stub_managed_regs contain zero information
>> and need not be saved at all, because it can easily be reconstructed
>> from  m->call_ms2sysv_extra_regs.
>>
>> See the attached new version.  Daniel does it work for you?
> 
> No, I'm not at all comfortable with you making so many seemingly 
> unnecessary changes to this code.  (Although I wish I got this much 
> feedback during my RFCs! :)  I can accept the changes to 
> is/count_stub_managed_reg (with some caveats), but I do not at all see 
> the rationale for changing m_stub_names to a static and adding another 
> dimension for the object instance -- from an OO standpoint, that's just 
> bad design.  Can you please share your rationale for that?
> 

Hmm, sorry about that ...
I just thought it would be nice to avoid the const-cast here.

This moved the m_stub_names from all 4 instances to one static
array s_stub_names.  But looking at it again, I think the extra
dimension is not even necessary, because all instances share the
same data, so removing that extra dimension again will be fine.

> Incidentally, half of the space in that array is wasted and can be 
> trimmed since a given instance of xlogue_layout either supports hard 
> frame pointers or doesn't, I just never got around to splitting that 
> apart.  (The first three enum xlogue_stub values are for without HFP and 
> the last three for with.)  Also, if we wanted to further reduce the 
> memory footprint of xlogue_layout objects, the offset field of struct 
> reginfo could be changed to int, and if we really wanted to go nuts then 
> 16 bits would work for both of its fields.
> 
> So for is/count_stub_managed_reg(s), you are obviously much more 
> familiar with gcc, its passes and the i386 backend, but my knowledge 
> level makes me very uncomfortable having the result of 
> xlogue_layout::is_stub_managed_reg() determined in a way that has the 
> (apparent) potential to differ from from the state at the time the last 
> call to ix86_compute_frame_layout() was made; I just don't understand 

I fund it technically difficult to add a HARD_REG_SET to
struct machine_function, and tried to avoid the extra overhead of
calling ix86_save_reg so often, which you also felt uncomfortable with.

So, if you look at compute_stub_managed_regs I first saw that the
first loop can never terminate thru the "return 0", because the
registers in x86_64_ms_sysv_extra_clobbered_registers are guaranteed
to be clobbered.  Then I saw that the bits in stub_managed_regs
are always added in the same sequence, thus the result depends only
on the number call_ms2sysv_extra_regs and hfp so everything is already
available in struct machine_function.


Thanks
Bernd.


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-22 Thread Jason Merrill
On Mon, May 22, 2017 at 12:28 PM, Martin Sebor  wrote:
> On 05/19/2017 11:26 AM, Bernd Edlinger wrote:
>>
>> On 05/19/17 19:05, Dominique d'Humières wrote:
>>>
>>> Hi Bernd,
>>>
>>> Your patches are causing troubles when I try to do "incremental updates
>>> »:
>>>
>>> After revision r248290 it fails with
>>>
>>> ../../work/gcc/cp/init.c:4916:10: fatal error: gt-cp-init.h: No such file
>>> or directory
>>>   #include "gt-cp-init.h »
>>>
>>> and after r248242 with
>>>
>>> ../../work/gcc/c-family/c-format.c:4215:10: fatal error:
>>> gt-c-family-c-format.h: No such file or directory
>>>   #include "gt-c-family-c-format.h »
>>>
>>> Note that after r248242 a full bootstrap succeeded (don’t know yet for
>>> r248290).
>>>
>>> Is there a way to fix that?
>>>
>>
>> No, unfortunately it looks like incremental does not work in this case.
>>
>> You can try to remove gcc/s-gtyp-input, maybe it un-breaks your
>> build.  However, I gave up at that point and did a full bootstrap
>> instead.
>
> I also keep running into this error.  Removing my build directory
> and starting from scratch usually fixes it, but it seems that almost
> every time git pull or svn update brings in new changes it comes back.

I've found that the key is ./config.status --recheck so that the
GTFILES variable gets updated from config-lang.in.  I'm not sure if
plain ./config.status is also needed, and/or removing the gtype stuff
from the build directory.

Jason


Re: [Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-22 Thread Tim Shen via gcc-patches
On Mon, May 22, 2017 at 11:05 AM, Tim Shen  wrote:
> On Mon, May 22, 2017 at 6:21 AM, Jonathan Wakely  wrote:
> I suggest to cc a front-end person (Jason?) to take a look, as I
> suggested in the bug, and the example: https://godbolt.org/g/AxUv16.

See more discussion in pr80737. Basically in the godbolt example,
turning on and off -DBUG results in different behaviors, but it
shouldn't.


-- 
Regards,
Tim Shen


Re: [Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-22 Thread Tim Shen via gcc-patches
On Mon, May 22, 2017 at 6:21 AM, Jonathan Wakely  wrote:
> On 19/05/17 22:40 -0700, Tim Shen via libstdc++ wrote:
>>
>> diff --git a/libstdc++-v3/include/std/variant
>> b/libstdc++-v3/include/std/variant
>> index 0e04a820d69..b9824a5182c 100644
>> --- a/libstdc++-v3/include/std/variant
>> +++ b/libstdc++-v3/include/std/variant
>> @@ -936,9 +936,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   noexcept((is_nothrow_move_constructible_v<_Types> && ...)) =
>> default;
>>
>>   template> +  typename = enable_if_t, variant>>,
>>typename =
>> enable_if_t<__exactly_once<__accepted_type<_Tp&&>>
>> - && is_constructible_v<__accepted_type<_Tp&&>,
>> _Tp&&>
>> - && !is_same_v, variant>>>
>> + && is_constructible_v<__accepted_type<_Tp&&>,
>> _Tp&&>>>
>
>
> Does this definitely short-circuit? I seem to recall a similar case
> where either Clang or GCC (I think it was Clang) was evaluating the
> second default template argument even though the first had produce a
> substition failure.
>
> If we need to guarantee it short-circuits then we'd want:
>
>  templatetypename = enable_if_t<__and_<
>  __not_, variant>>,
>  __bool_constant<
>
> __exactly_once<__accepted_type<_Tp&&>>
>&&
> is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>>>
>
> i.e. use __and_< is-this-type, everything-else> where
> "everything-else" still uses && to avoid making the instantiations too
> deep.

Good observation. I changed to use __and_ and __not_:

-  typename = enable_if_t<__exactly_once<__accepted_type<_Tp&&>>
- && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>
- && !is_same_v, variant>>>
+  typename = enable_if_t<__and_<
+ __not_, variant>>,
+ std::integral_constant>>,
+ is_constructible<__accepted_type<_Tp&&>,
_Tp&&>>::value>>

(I didn't use && at all, just to verify the correctness)

but the compile still fails with the similar error messages. If __and_
and __not_ are expected to work, then the root cause is unlikely "not
short-circuit" only.

I suggest to cc a front-end person (Jason?) to take a look, as I
suggested in the bug, and the example: https://godbolt.org/g/AxUv16.

>
> Also, this is another place where we could use an __is_samey
> trait that does is_same.
>

I never know that "samey" is a word. :)


-- 
Regards,
Tim Shen


Re: MinGW compilation warnings in libiberty's include/environ.h

2017-05-22 Thread Pedro Alves
On 05/20/2017 02:27 AM, DJ Delorie wrote:
> 
> Pedro Alves  writes:
>> That sounds to me like the root issue that should be fixed,
>> so that these fallback definitions don't come into into play at all.
>> I.e., why isn't HAVE_ENVIRON_DECL defined on mingw when
>> setenv.o is built?  Sounds like a decl check is missing
>> in configure.ac.
> 
> environ is tricky because it's typically messy on platforms, unlike a
> standard C function.  You can't use a generic check if the macro expands
> to something that interferes with the check.

gnulib has a check, which I assume to be solid:

 http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=m4/environ.m4

we could import just that bit, I suppose, though every client
of libiberty's environ.h would need to gain the same check.
That's be quite doable with the shared libiberty.m4 idea (we'd just
put the check there), but a nuisance if you have to copy the check all
over the place.  At this point it may be more worth it to
invest in finishing the previous use-gnulib-in-gcc effort instead.

Thanks,
Pedro Alves



OpenACC 1.0 compatibility: acc_async_wait, acc_async_wait_all

2017-05-22 Thread Thomas Schwinge
Hi!

For OpenACC 1.0 compatibility, we need to provide the aliases
acc_async_wait, and acc_async_wait_all for acc_wait, and acc_wait_all,
respectively.  OK for trunk?

commit 0f8302913db6d2c23804a3463c51a47e623e76b2
Author: Thomas Schwinge 
Date:   Mon May 22 19:22:24 2017 +0200

OpenACC 1.0 compatibility: acc_async_wait, acc_async_wait_all

libgomp/
* openacc.h (acc_async_wait, acc_async_wait_all): New prototypes.
* libgomp.map (OACC_2.0): Add these.
* oacc-async.c (acc_async_wait, acc_async_wait_all): New aliases
for "acc_wait", and "acc_wait_all", respectively.
* openacc.f90 (acc_async_wait, acc_async_wait_all): New interfaces
for "acc_wait", and "acc_wait_all", respectively.
* openacc_lib.h (acc_async_wait, acc_async_wait_all): Likewise.
* libgomp.texi (acc_wait, acc_wait_all): Update.
* testsuite/libgomp.oacc-c-c++-common/par-reduction-2.c: Update.
* testsuite/libgomp.oacc-fortran/par-reduction-2-1.f: New file.
* testsuite/libgomp.oacc-fortran/par-reduction-2-2.f: Likewise.
---
 libgomp/libgomp.map|  2 +
 libgomp/libgomp.texi   |  7 ++-
 libgomp/oacc-async.c   | 22 +
 libgomp/openacc.f90| 16 +-
 libgomp/openacc.h  |  2 +
 libgomp/openacc_lib.h  | 11 +
 .../libgomp.oacc-c-c++-common/par-reduction-2.c|  9 ++--
 .../libgomp.oacc-fortran/par-reduction-2-1.f   | 57 ++
 .../libgomp.oacc-fortran/par-reduction-2-2.f   | 57 ++
 9 files changed, 176 insertions(+), 7 deletions(-)

diff --git libgomp/libgomp.map libgomp/libgomp.map
index c7bf245..141424b 100644
--- libgomp/libgomp.map
+++ libgomp/libgomp.map
@@ -315,10 +315,12 @@ OACC_2.0 {
acc_async_test_all;
acc_async_test_all_h_;
acc_wait;
+   acc_async_wait;
acc_wait_h_;
acc_wait_async;
acc_wait_async_h_;
acc_wait_all;
+   acc_async_wait_all;
acc_wait_all_h_;
acc_wait_all_async;
acc_wait_all_async_h_;
diff --git libgomp/libgomp.texi libgomp/libgomp.texi
index cc5ee1c..230720f 100644
--- libgomp/libgomp.texi
+++ libgomp/libgomp.texi
@@ -2095,12 +2095,15 @@ specified in @var{arg}.
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
+@item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab 
@code{acc_async_wait(arg);}
 @end multitable
 
 @item @emph{Fortran}:
 @multitable @columnfractions .20 .80
 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
 @item   @tab @code{integer(acc_handle_kind) arg}
+@item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine 
acc_async_wait(arg)}
+@item   @tab 
@code{integer(acc_handle_kind) arg}
 @end multitable
 
 @item @emph{Reference}:
@@ -2119,11 +2122,13 @@ This function waits for the completion of all 
asynchronous operations.
 @item @emph{C/C++}:
 @multitable @columnfractions .20 .80
 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
+@item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab 
@code{acc_async_wait_all(void);}
 @end multitable
 
 @item @emph{Fortran}:
 @multitable @columnfractions .20 .80
-@item @emph{Interface}: @tab @code{subroutine acc_wait_async()}
+@item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
+@item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine 
acc_async_wait_all()}
 @end multitable
 
 @item @emph{Reference}:
diff --git libgomp/oacc-async.c libgomp/oacc-async.c
index b68c84d..1334f99 100644
--- libgomp/oacc-async.c
+++ libgomp/oacc-async.c
@@ -70,6 +70,17 @@ acc_wait (int async)
   thr->dev->openacc.async_wait_func (async);
 }
 
+/* acc_async_wait is an OpenACC 1.0 compatibility name for acc_wait.  */
+#ifdef HAVE_ATTRIBUTE_ALIAS
+strong_alias (acc_wait, acc_async_wait)
+#else
+void
+acc_async_wait (int async)
+{
+  acc_wait (async);
+}
+#endif
+
 void
 acc_wait_async (int async1, int async2)
 {
@@ -92,6 +103,17 @@ acc_wait_all (void)
   thr->dev->openacc.async_wait_all_func ();
 }
 
+/* acc_async_wait_all is an OpenACC 1.0 compatibility name for acc_wait_all.  
*/
+#ifdef HAVE_ATTRIBUTE_ALIAS
+strong_alias (acc_wait_all, acc_async_wait_all)
+#else
+void
+acc_async_wait_all (void)
+{
+  acc_wait_all ();
+}
+#endif
+
 void
 acc_wait_all_async (int async)
 {
diff --git libgomp/openacc.f90 libgomp/openacc.f90
index a4422d4..0eb34ff 100644
--- libgomp/openacc.f90
+++ libgomp/openacc.f90
@@ -470,8 +470,10 @@ module openacc
 
   public :: acc_get_num_devices, acc_set_device_type, acc_get_device_type
   public :: acc_set_device_num, acc_get_device_num, acc_async_test
-  public :: acc_async_test_all, acc_wait, 

Re: [PATCH GCC8][31/33]Set range information for niter bound of vectorized loop

2017-05-22 Thread Bin.Cheng
On Fri, May 19, 2017 at 1:51 PM, Richard Biener
 wrote:
> On Mon, May 15, 2017 at 5:58 PM, Bin.Cheng  wrote:
>> On Thu, May 11, 2017 at 12:02 PM, Richard Biener
>>  wrote:
>>> On Tue, Apr 18, 2017 at 12:54 PM, Bin Cheng  wrote
 Hi,
 Based on vect_peeling algorithm, we know for sure that vectorized loop 
 must iterates at least once.
 This patch sets range information for niter bounds of vectorized loop.  
 This helps niter analysis,
 so iv elimination too.
 Is it OK?
>>>
>>>niters_vector = force_gimple_operand (niters_vector, , true, 
>>> var);
>>>gsi_insert_seq_on_edge_immediate (pe, stmts);
>>> +  /* Peeling algorithm guarantees that vector loop bound is at least 
>>> ONE,
>>> +we set range information to make niters analyzer's life easier.  */
>>> +  if (TREE_CODE (niters_vector) == SSA_NAME)
>>> +   set_range_info (niters_vector, VR_RANGE, build_int_cst (type, 1),
>>> +   fold_build2 (RSHIFT_EXPR, type,
>>> +TYPE_MAX_VALUE (type), log_vf));
>>>
>>> if all of niters_vector folds to an original SSA name then
>>> niters_vector after gimplification
>>> is not a new SSA name and thus you can't set range-info on it.
>>>
>>> Likewise for the other case where LOOP_VINFO_NITERS is just an SSA name.
>> Hi,
>> This is updated patch.  It checks whether the result ssa name is newly
>> created tmp and only sets range information if so.
>>
>> Is it OK?
>
> A better way to check whether the SSA name is new is to see if 'stmts'
> filled by force_gimple_operand is non-empty.
Hi,
Here is updated patch checking empty gimple_seq.  Is it OK?

Thanks,
bin
>
> Richard.
>
>> Thanks,
>> bin
>>
>> 2017-04-11  Bin Cheng  
>>
>> * tree-vectorizer.h (vect_build_loop_niters): New parameter.
>> * tree-vect-loop-manip.c (vect_build_loop_niters): New parameter.
>> Set true to new parameter if new ssa variable is defined.
>> (vect_gen_vector_loop_niters): Refactor.  Set range information
>> for the new vector loop bound variable.
>> (vect_do_peeling): Ditto.
>>
>>>
>>> Richard.
>>>
 Thanks,
 bin
 2017-04-11  Bin Cheng  

 * tree-vect-loop-manip.c (vect_gen_vector_loop_niters): Refactor.
 Set range information for vector loop bound variable.
 (vect_do_peeling): Ditto.
diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index f48336b..93c1542 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -1095,10 +1095,11 @@ vect_update_inits_of_drs (loop_vec_info loop_vinfo, tree niters)
 
 
 /* This function builds ni_name = number of iterations.  Statements
-   are emitted on the loop preheader edge.  */
+   are emitted on the loop preheader edge.  If NEW_VAR_P is not NULL, set
+   it to TRUE if new ssa_var is generated.  */
 
 tree
-vect_build_loop_niters (loop_vec_info loop_vinfo)
+vect_build_loop_niters (loop_vec_info loop_vinfo, bool *new_var_p)
 {
   tree ni = unshare_expr (LOOP_VINFO_NITERS (loop_vinfo));
   if (TREE_CODE (ni) == INTEGER_CST)
@@ -1112,7 +1113,11 @@ vect_build_loop_niters (loop_vec_info loop_vinfo)
   var = create_tmp_var (TREE_TYPE (ni), "niters");
   ni_name = force_gimple_operand (ni, , false, var);
   if (stmts)
-	gsi_insert_seq_on_edge_immediate (pe, stmts);
+	{
+	  gsi_insert_seq_on_edge_immediate (pe, stmts);
+	  if (new_var_p != NULL)
+	*new_var_p = true;
+	}
 
   return ni_name;
 }
@@ -1177,22 +1182,21 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, tree niters,
 			 tree *niters_vector_ptr, bool niters_no_overflow)
 {
   tree ni_minus_gap, var;
-  tree niters_vector;
+  tree niters_vector, type = TREE_TYPE (niters);
   int vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
   edge pe = loop_preheader_edge (LOOP_VINFO_LOOP (loop_vinfo));
-  tree log_vf = build_int_cst (TREE_TYPE (niters), exact_log2 (vf));
+  tree log_vf = build_int_cst (type, exact_log2 (vf));
 
   /* If epilogue loop is required because of data accesses with gaps, we
  subtract one iteration from the total number of iterations here for
  correct calculation of RATIO.  */
   if (LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo))
 {
-  ni_minus_gap = fold_build2 (MINUS_EXPR, TREE_TYPE (niters),
-  niters,
-  build_one_cst (TREE_TYPE (niters)));
+  ni_minus_gap = fold_build2 (MINUS_EXPR, type, niters,
+  build_one_cst (type));
   if (!is_gimple_val (ni_minus_gap))
 	{
-	  var = create_tmp_var (TREE_TYPE (niters), "ni_gap");
+	  var = create_tmp_var (type, "ni_gap");
 	  gimple *stmts = NULL;
 	  ni_minus_gap = force_gimple_operand (ni_minus_gap, ,
 	   true, var);
@@ -1208,25 +1212,28 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, tree niters,
  (niters - vf) >> log2(vf) + 1 by using the fact that we know 

Re: [Patch, Fortran, OOP] PR 80766: [7/8 Regression] ICE with type-bound procedure returning an array

2017-05-22 Thread Janus Weil
2017-05-21 23:56 GMT+02:00 Jerry DeLisle :
> On 05/21/2017 09:14 AM, Janus Weil wrote:
>>
>> Hi all,
>>
>> the attached patch fixes an ICE-on-valid regression by making sure
>> that the relevant vtype symbol is resolved properly (for further
>> discussion see the PR).
>>
>> The patch regtests cleanly on x86_64-linux-gnu. Ok for trunk and 7-branch?
>>
>> Cheers,
>> Janus
>>
>>
>> 2017-05-21  Janus Weil  
>>
>>  PR fortran/80766
>>  * resolve.c (resolve_fl_derived): Make sure that vtype symbols are
>>  properly resolved.
>>
>> 2017-05-21  Janus Weil  
>>
>>  PR fortran/80766
>>  * gfortran.dg/typebound_call_28.f90: New test.
>>
>
> OK to commit. I have been unable to commit another patch today. Server down
> or internet connection gone.  I will try later. Hope its OK from your side
> of the pond.

Thanks, Jerry. Just committed as r248341 (without any problems). Will
backport to the 7-branch in about a week or so.

Cheers,
Janus


Re: [RFC, testsuite] Add dg-save-linenr

2017-05-22 Thread Tom de Vries

On 05/16/2017 03:12 PM, Rainer Orth wrote:

Hi Tom,

sorry for chiming in so very late: I've been on vacation and sick in
between...



thanks for review anyway.


On 04/24/2017 05:20 PM, David Malcolm wrote:

On Sat, 2017-04-22 at 19:49 +0200, Tom de Vries wrote:

Hi,

there are currently two types of line number supported in
dg-{error,warning,message,bogus} directives: absolute and relative.
With an absolute line number, it's immediately clear what line number
is
meant, but when a line is added at the start of the file, the line
number needs to be updated.  With a relative line number, that
problem
is solved, but when relative line numbers become large, it becomes
less
clear what line it refers to, and when adding a line inbetween the
directive using the relative line number and the line it refers to,
the
relative line number still needs to be updated.

This patch adds a directive dg-save-linenr with argument varname,
that
saves the line number of the directive in a variable varname, which
can
be used as line number in dg directives.

Testing status:
- tested updated test-case objc.dg/try-catch-12.m
- ran tree-ssa.exp

RFC:
- good idea?


Excellent idea; thanks!  There are various places where I'd find this
useful.


- naming of directive dg-save-linenr (dg-linenr, dg-save-line-nr,
dg-save-lineno, dg-save-line-number, etc)


How about just "dg-line"?  (if it's not already taken)


Done.


I'd have preferred dg-linenum: it clarifiers that it's a number and we
have precedent in DejaGnu's dg-linenum-format and dg-format-linenum...



I see. I'll leave it dg-line for now, but I'll mention the dg-linenum 
variant upstream.



- error message formulation


Nit: the new function should have a leading comment, explaining the
usage.



Done.


Not only that, but the new proc needs documenting in sourcebuild.texi.


Attached patch adds the missing documentation.

It looks like this in gccint.info:
...
'{ dg-line LINENUMVAR }'
 This DejaGnu directive sets the variable LINENUMVAR to the line
 number of the source line.  The variable LINENUMVAR can then be
 used in subsequent 'dg-error', 'dg-warning', 'dg-message' and
 'dg-bogus' directives.  For example:

  int a;   /* { dg-line first_def_a } */
  float a; /* { dg-error "conflicting types of" } */
  /* { dg-message "previous declaration of" "" { target *-*-* } 
first_def_a } */

...

Note: AFAIK, dg-line does not work in the gnat testsuite. This is 
similar to PR80219 for relative line numbers. I'm not sure if we should 
mention this here, or how.


OK for trunk like this?


(It's already way too hard for testsuite writers to find their way with
the documentation; if parts are missing, it gets next to impossible.)



Ack. I think the relative line numbers are also not documented.


Besides, it may be worthwhile contributing/suggesting this upstream.


Will do.

Thanks,
- Tom
Document dg-line directive

2017-05-22  Tom de Vries  

	* doc/sourcebuild.texi: Document dg-line directive.

---
 gcc/doc/sourcebuild.texi | 12 
 1 file changed, 12 insertions(+)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 84d9a22..a887337 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1180,6 +1180,18 @@ associated with the bogus message.  It is usually used with @samp{xfail}
 to indicate that the message is a known problem for a particular set of
 targets.
 
+@item @{ dg-line @var{linenumvar} @}
+This DejaGnu directive sets the variable @var{linenumvar} to the line number of
+the source line.  The variable @var{linenumvar} can then be used in subsequent
+@code{dg-error}, @code{dg-warning}, @code{dg-message} and @code{dg-bogus}
+directives.  For example:
+
+@smallexample
+int a;   /* @{ dg-line first_def_a @} */
+float a; /* @{ dg-error "conflicting types of" @} */
+/* @{ dg-message "previous declaration of" "" @{ target *-*-* @} first_def_a @} */
+@end smallexample
+
 @item @{ dg-excess-errors @var{comment} [@{ target/xfail @var{selector} @}] @}
 This DejaGnu directive indicates that the test is expected to fail due
 to compiler messages that are not handled by @samp{dg-error},


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-22 Thread Martin Sebor

On 05/19/2017 11:26 AM, Bernd Edlinger wrote:

On 05/19/17 19:05, Dominique d'Humières wrote:

Hi Bernd,

Your patches are causing troubles when I try to do "incremental updates »:

After revision r248290 it fails with

../../work/gcc/cp/init.c:4916:10: fatal error: gt-cp-init.h: No such file or 
directory
  #include "gt-cp-init.h »

and after r248242 with

../../work/gcc/c-family/c-format.c:4215:10: fatal error: 
gt-c-family-c-format.h: No such file or directory
  #include "gt-c-family-c-format.h »

Note that after r248242 a full bootstrap succeeded (don’t know yet for r248290).

Is there a way to fix that?



No, unfortunately it looks like incremental does not work in this case.

You can try to remove gcc/s-gtyp-input, maybe it un-breaks your
build.  However, I gave up at that point and did a full bootstrap
instead.


I also keep running into this error.  Removing my build directory
and starting from scratch usually fixes it, but it seems that almost
every time git pull or svn update brings in new changes it comes back.

Martin


Re: MinGW compilation warnings in libiberty's xstrndup.c

2017-05-22 Thread Pedro Alves
On 05/20/2017 01:38 AM, DJ Delorie wrote:
> 
> Pedro Alves  writes:
>> Ah, yeah.  AFAICS, all the declaration checks in libiberty.h are 
>> HAVE_DECL checks.  This suggests to me that this declaration guard 
>> should be HAVE_DECL too [1].
> 
> Except the ones in the $funcs list, which includes strnlen.  I think in
> the old days, we didn't put in declarations at all... until "char *"
> became a different size than "int" and we started needing them.

Running:

$ grep HAVE_ libiberty/config.h | sed 's/DECL_//g'| sort | uniq -c | sort -n

on the build I have handy shows:
...
  2 #define HAVE_ASPRINTF 1
  2 #define HAVE_BASENAME 1
  2 #define HAVE_CALLOC 1
  2 #define HAVE_FFS 1
  2 #define HAVE_SBRK 1
  2 #define HAVE_SNPRINTF 1
  2 #define HAVE_STRTOL 1
  2 #define HAVE_STRTOLL 1
  2 #define HAVE_STRTOUL 1
  2 #define HAVE_STRTOULL 1
  2 #define HAVE_STRVERSCMP 1
  2 #define HAVE_VASPRINTF 1

"2" means above means each FOO symbol above has both HAVE_FOO
and HAVE_DECL_FOO defines:

 $ grep "HAVE.*_SNPRINTF" config.h
 #define HAVE_DECL_SNPRINTF 1
 #define HAVE_SNPRINTF 1

> 
> So some functions in libiberty are HAVE_DECL and others are still HAVE.

But I don't see any HAVE check in libiberty.h (for function symbols),
only HAVE_DECL ones:

$ grep HAVE libiberty.h 
/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
#if !HAVE_DECL_BASENAME
 || defined (__DragonFly__) || defined (HAVE_DECL_BASENAME) 
   autoconf which would result in HAVE_DECL_BASENAME being set.  */
#if defined (HAVE_DECL_FFS) && !HAVE_DECL_FFS
#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
#if !HAVE_DECL_VASPRINTF
#if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF
#if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF
#if defined (HAVE_DECL_STRNLEN) && !HAVE_DECL_STRNLEN
#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP
#if defined(HAVE_DECL_STRTOL) && !HAVE_DECL_STRTOL
#if defined(HAVE_DECL_STRTOUL) && !HAVE_DECL_STRTOUL
#if defined(HAVE_LONG_LONG) && defined(HAVE_DECL_STRTOLL) && !HAVE_DECL_STRTOLL
#if defined(HAVE_LONG_LONG) && defined(HAVE_DECL_STRTOULL) && 
!HAVE_DECL_STRTOULL
#if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP

Nor in other headers under include/, while at it.
Are you looking elsewhere perhaps?  Based on the above, it looks to
me like the non-HAVE_DECL HAVE symbols are implementation detail
to libiberty, side effect of the checks used to determine whether
a replacement is necessary.

> 
> Ah, found it, this commit is incomplete:
> 
> https://gcc.gnu.org/ml/gcc-patches/2014-06/msg00784.html
> 
> It changes gcc's configure but nobody else's (and now we have an answer
> to the three-year-old question "why don't we have a more liberal commit
> policy?" ;) which breaks both libiberty and libgfortran.

Yeah, that exactly the sort of thing that gets fixed by design by having
a centralized libiberty.m4 file.

> 
>> BTW, I once proposed a new libiberty.m4 file that all libiberty
>> clients would source so that these checks are all centralized.
> 
> I have no philosophical problem with that type of change, but I have the
> usual fear of touching anything in libiberty that's been around this
> long ;-)
> 
> (this bug being a prime example of how subtle an incorrect change can be)
> 
> (and honestly, my upstream attention is elsewhere these days)
> 

Thanks,
Pedro Alves



[PING] [MSP430] Trunk patches required for gcc-6-branch to build for msp430

2017-05-22 Thread Jozef Lawrynowicz
Ping, original post: 
https://gcc.gnu.org/ml/gcc-patches/2017-03/msg01560.html

---

For the msp430-elf target, the gcc-6-branch fails to build when 
configured to enable C++ support.


The gcc-5-branch successfully builds with C++ support.

Backporting r244727 and r243310 to the gcc-6-branch fixes the two
build issues, so the build completes successfully.

I don't have write access to the GCC repository, so would appreciate
if someone could backport these patches to gcc-6-branch if that is 
acceptable.


[C++ PATCH] Using directives

2017-05-22 Thread Nathan Sidwell
This is the first half of using directive cleanup.  I split the current 
interface in two, one for namespace-level directives and one for local 
directives.  That avoids the need for a load if 'if (namespace_level_p 
())' tests in the bodies of the worker functions.  I also merged and 
renamed do_using_directive & parse_using_directive, as we're not 
actually parsing at this point, so a finish_FOO name seemed more 
appropriate.


The second part of the patch removes the recursiveness of 
add_using_namespace_1 and will wait until the namespace using 
representation has been simplified.


Jason killed strong using directives earlier this year.  I'd already 
written the fragment suggesting an inline namespace, so included it here.


You may notice that push_namespace has two calls to add_using_directive, 
which look like they could be combined.  That's only because the 
representation if inline namespaces hasn't yet been changed.


Applied to trunk.

nathan
--
Nathan Sidwell
2017-05-22  Nathan Sidwell  

	cp/
	* name-lookup.h (parse_using_directive): Replace with ...
	(finish_namespace_using_directive): ... this and ...
	(finish_local_using_directive): ... this.
	* name-lookup.c (add_using_namespace_1): Move later.
	(add_using_namespace): Move later, add namespace_p arg, remove
	indirect arg.
	(push_using_directive_1): Directly recurse.
	(do_using_directive, parse_using_directive): Delete, split into ...
	(finish_namespace_using_directive): ... this and ...
	(finish_local_using_directive): ... this.
	(push_namespace): Use add_using_namespace.
	* parser.c (cp_parser_using_directive): Call
	finish_namespace_using_directive or finish_local_using_directive.
	* pt.c (tsubst_expr): Call finish_local_using_directive.

	testsuite/
	* g++.dg/lookup/strong-using.C: New.

Index: cp/name-lookup.c
===
--- cp/name-lookup.c	(revision 248327)
+++ cp/name-lookup.c	(working copy)
@@ -4337,60 +4337,6 @@ pushdecl_namespace_level (tree x, bool i
   return t;
 }
 
-/* Insert USED into the using list of USER. Set INDIRECT_flag if this
-   directive is not directly from the source. Also find the common
-   ancestor and let our users know about the new namespace */
-
-static void
-add_using_namespace_1 (tree user, tree used, bool indirect)
-{
-  tree t;
-  /* Using oneself is a no-op.  */
-  if (user == used)
-return;
-  gcc_assert (TREE_CODE (user) == NAMESPACE_DECL);
-  gcc_assert (TREE_CODE (used) == NAMESPACE_DECL);
-  /* Check if we already have this.  */
-  t = purpose_member (used, DECL_NAMESPACE_USING (user));
-  if (t != NULL_TREE)
-{
-  if (!indirect)
-	/* Promote to direct usage.  */
-	TREE_INDIRECT_USING (t) = 0;
-  return;
-}
-
-  /* Add used to the user's using list.  */
-  DECL_NAMESPACE_USING (user)
-= tree_cons (used, namespace_ancestor (user, used),
-		 DECL_NAMESPACE_USING (user));
-
-  TREE_INDIRECT_USING (DECL_NAMESPACE_USING (user)) = indirect;
-
-  /* Add user to the used's users list.  */
-  DECL_NAMESPACE_USERS (used)
-= tree_cons (user, 0, DECL_NAMESPACE_USERS (used));
-
-  /* Recursively add all namespaces used.  */
-  for (t = DECL_NAMESPACE_USING (used); t; t = TREE_CHAIN (t))
-/* indirect usage */
-add_using_namespace_1 (user, TREE_PURPOSE (t), 1);
-
-  /* Tell everyone using us about the new used namespaces.  */
-  for (t = DECL_NAMESPACE_USERS (user); t; t = TREE_CHAIN (t))
-add_using_namespace_1 (TREE_PURPOSE (t), used, 1);
-}
-
-/* Wrapper for add_using_namespace_1.  */
-
-static void
-add_using_namespace (tree user, tree used, bool indirect)
-{
-  bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  add_using_namespace_1 (user, used, indirect);
-  timevar_cond_stop (TV_NAME_LOOKUP, subtime);
-}
-
 /* Process a using-declaration not appearing in class or local scope.  */
 
 void
@@ -4422,75 +4368,6 @@ do_toplevel_using_decl (tree decl, tree
 binding->type = newtype;
 }
 
-/* Process a using-directive.  */
-
-void
-do_using_directive (tree name_space)
-{
-  tree context = NULL_TREE;
-
-  if (name_space == error_mark_node)
-return;
-
-  gcc_assert (TREE_CODE (name_space) == NAMESPACE_DECL);
-
-  if (building_stmt_list_p ())
-add_stmt (build_stmt (input_location, USING_STMT, name_space));
-  name_space = ORIGINAL_NAMESPACE (name_space);
-
-  if (!toplevel_bindings_p ())
-{
-  push_using_directive (name_space);
-}
-  else
-{
-  /* direct usage */
-  add_using_namespace (current_namespace, name_space, 0);
-  if (current_namespace != global_namespace)
-	context = current_namespace;
-
-  /* Emit debugging info.  */
-  if (!processing_template_decl)
-	(*debug_hooks->imported_module_or_decl) (name_space, NULL_TREE,
-		 context, false);
-}
-}
-
-/* Deal with a using-directive seen by the parser.  Currently we only
-   handle attributes here, since they cannot appear inside a template.  */
-
-void
-parse_using_directive (tree 

Re: [testsuite, committed, PR65941] Add and use effective target rdrand

2017-05-22 Thread Tom de Vries

On 05/11/2017 04:44 PM, Rainer Orth wrote:

Hi Tom,


2017-05-01  Tom de Vries  

PR testsuite/65941
* lib/target-supports.exp (check_effective_target_rdrand): New proc.


the new effective-target keyword needs documenting in sourcebuild.texi.


Attached patch adds the missing documentation.

It looks like this in gccint.info:
...
7.2.3.10 Other hardware attributes
..

'avx'
 Target supports compiling 'avx' instructions.



'divmod_simode'
 Target supporting hardware divmod insn or divmod libcall for
 SImode.

'rdrand'
 Target supports i386/x86-64 insn rdrand.
...

OK?

Thanks,
- Tom
Document rdrand effective target

2017-05-22  Tom de Vries  

	* doc/sourcebuild.texi: Document rdrand effective target.

---
 gcc/doc/sourcebuild.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 84d9a22..dec9227 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1883,6 +1883,9 @@ Target supporting hardware divmod insn or divmod libcall.
 @item divmod_simode
 Target supporting hardware divmod insn or divmod libcall for SImode.
 
+@item rdrand
+Target supports i386/x86-64 insn rdrand.
+
 @end table
 
 @subsubsection Environment attributes


Re: [PATCH] [MSP430] PR78838: Do not add section name prefixes when section name is .lowtext

2017-05-22 Thread Jozef Lawrynowicz

On 19/05/2017 04:13, Martin Sebor wrote:

On 05/18/2017 10:14 AM, Jozef Lawrynowicz wrote:

A patch for this bug was originally posted here:
https://gcc.gnu.org/ml/gcc-patches/2017-02/msg01054.html
There were some issues with that patch which I've now fixed.

The MSP430 target supports the automatic placement of functions and
data in different memory regions when passing the
"-mdata-region=either" and "-mcode-region=either" options.
MSP430x devices support the large memory model, "-mlarge", which
enables 20 bit pointers, however the vector table across all MSP430
targets only accepts 16-bit pointers. To prevent the use of 20-bit
pointers in the vector table when the large memory model is used, the
MSP430 backend currently places functions specified with the interrupt
attribute in a section called ".lowtext". This section is placed at
the beginning of .text in the MSP430 linker scripts.

PR target/78838 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78838)
reports that a function with the interrupt attribute is placed in a
non-existent section ".either.lowtext" when "-mlarge",
"-mcode-region=either" and "-ffunction-sections" are passed. The
backend has correctly decided to place the function in .lowtext, but
has applied the .either prefix which is undesirable.

No additional .lower/.upper/.either prefixes should be applied to the
section name once it has been placed in .lowtext, the attached patch
implements this, and adds a test.

The patch passed regression testing with "-mcpu=msp430x/-mlarge" for
msp430-elf on the gcc-6-branch (r247086). Trunk doesn't build with C++
support for msp430-elf which is why gcc-6-branch was used.

I don't have write access to the GCC SVN repository, so if this patch
is satisfactory, I would appreciate if someone could commit it for me.
Thanks.


I don't normally review back end patches so forgive me for picking
on two of yours the same day but it seems to me that the first
argument to has_section_name() needs to be const-qualified:

+static bool
+has_section_name (char * name, tree decl = current_function_decl)
...

if the following is to compile without error in C++ where string
literals are const char[]:

+  if (has_section_name (".lowtext", decl))

Martin


No problem. The updated patch is attached.

Thanks,
Jozef
From bc4bda371df3b8bb54614ade700b2c970ef3611a Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz 
Date: Thu, 18 May 2017 12:51:12 +
Subject: [PATCH] MSP430: Do not add code region prefixes when the section name
 is .lowtext (PR 78838)

2017-05-XX  Jozef Lawrynowicz  

gcc/
PR target/78838
* config/msp430/msp430.c (gen_prefix): Return NULL when section name is
.lowtext.
(has_section_name): New function.

gcc/testsuite
PR target/78838
* gcc.target/msp430/interrupt_fn_placement.c: New test.
---
 gcc/config/msp430/msp430.c   | 15 +++
 gcc/testsuite/gcc.target/msp430/interrupt_fn_placement.c | 13 +
 2 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/msp430/interrupt_fn_placement.c

diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 6f63116..067f99f 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -1808,6 +1808,15 @@ is_critical_func (tree decl = current_function_decl)
   return has_attr (ATTR_CRIT, decl);
 }
 
+static bool
+has_section_name (const char * name, tree decl = current_function_decl)
+{
+  if (decl == NULL_TREE)
+return false;
+  return (DECL_SECTION_NAME (decl)
+&& (strcmp (name, DECL_SECTION_NAME (decl)) == 0));
+}
+
 #undef  TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS   
msp430_allocate_stack_slots_for_args
 
@@ -2146,6 +2155,12 @@ gen_prefix (tree decl)
   if (has_attr ("section", decl))
 return NULL;
 
+  /* If the function has been put in the .lowtext section because it is an
+   * interrupt handler, and the large memory model is used, then do not add any
+   * prefixes.  */
+  if (has_section_name (".lowtext", decl))
+return NULL;
+
   /* If the object has __attribute__((lower)) then use the ".lower." prefix.  
*/
   if (has_attr (ATTR_LOWER, decl))
 return lower_prefix;
diff --git a/gcc/testsuite/gcc.target/msp430/interrupt_fn_placement.c 
b/gcc/testsuite/gcc.target/msp430/interrupt_fn_placement.c
new file mode 100644
index 000..c88bfc3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/interrupt_fn_placement.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-mlarge -mcode-region=either -ffunction-sections" } */
+/* { dg-final { scan-assembler-not "\\.either\\.lowtext" } } */
+
+void __attribute__ ((interrupt (2))) ir_1 (void)
+{
+  while (1);
+}
+
+int main (void)
+{
+  while (1);
+}
-- 
1.8.3.1



Re: Implementing OpenACC's Fortran module

2017-05-22 Thread Thomas Schwinge
Hi!

On Thu, 13 Apr 2017 19:45:05 +0200, I wrote:
> On Fri, 10 Oct 2014 12:42:06 +0200, I wrote:
> > In the OpenACC Runtime Library, acc_pcopyin and acc_pcreate are to be
> > aliases for acc_present_or_copyin and acc_present_or_create,
> > respectively.
> > 
> > This is implemented in openacc.f90 as follows: [...]

> The following patch seems to do the right thing (that is, "divert" calls
> of "acc_pcopyin" to the existing "acc_present_or_copyin_*_h", and
> likewise for "acc_pcreate").  Is that the correct way of doing this?

Building on ,
OK to commit the following to trunk?

commit e5f5715556a30a0fff71243ad136d6ec29556f92
Author: Thomas Schwinge 
Date:   Wed Apr 19 21:12:33 2017 +0200

Fortran OpenACC "openacc_lib.h": acc_pcopyin, acc_pcreate

libgomp/
* openacc_lib.h (acc_pcopyin, acc_pcreate): Route to
acc_present_or_copyin and acc_present_or_create procedures,
respectively.
* testsuite/libgomp.oacc-fortran/lib-32-1.f: Exercise these, and
generally different variants of OpenACC Runtime Library functions.
* testsuite/libgomp.oacc-fortran/lib-32-2.f: Likewise.
---
 libgomp/openacc_lib.h | 42 ---
 libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f | 36 ---
 libgomp/testsuite/libgomp.oacc-fortran/lib-32-2.f | 26 +++---
 3 files changed, 35 insertions(+), 69 deletions(-)

diff --git libgomp/openacc_lib.h libgomp/openacc_lib.h
index 65f47a8..7818bd7 100644
--- libgomp/openacc_lib.h
+++ libgomp/openacc_lib.h
@@ -191,23 +191,9 @@
   end interface
 
   interface acc_pcopyin
-subroutine acc_pcopyin_32_h (a, len)
-  use iso_c_binding, only: c_int32_t
-  !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-  type (*), dimension (*) :: a
-  integer (c_int32_t) len
-end subroutine
-
-subroutine acc_pcopyin_64_h (a, len)
-  use iso_c_binding, only: c_int64_t
-  !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-  type (*), dimension (*) :: a
-  integer (c_int64_t) len
-end subroutine
-
-subroutine acc_pcopyin_array_h (a)
-  type (*), dimension (..), contiguous :: a
-  end subroutine
+procedure :: acc_present_or_copyin_32_h
+procedure :: acc_present_or_copyin_64_h
+procedure :: acc_present_or_copyin_array_h
   end interface
 
   interface acc_create
@@ -251,23 +237,9 @@
   end interface
 
   interface acc_pcreate
-subroutine acc_pcreate_32_h (a, len)
-  use iso_c_binding, only: c_int32_t
-  !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-  type (*), dimension (*) :: a
-  integer (c_int32_t) len
-end subroutine
-
-subroutine acc_pcreate_64_h (a, len)
-  use iso_c_binding, only: c_int64_t
-  !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-  type (*), dimension (*) :: a
-  integer (c_int64_t) len
-end subroutine
-
-subroutine acc_pcreate_array_h (a)
-  type (*), dimension (..), contiguous :: a
-  end subroutine
+procedure :: acc_present_or_create_32_h
+procedure :: acc_present_or_create_64_h
+procedure :: acc_present_or_create_array_h
   end interface
 
   interface acc_copyout
@@ -353,7 +325,7 @@
   ! acc_map_data: Only available in C/C++
   ! acc_unmap_data: Only available in C/C++
   ! acc_deviceptr: Only available in C/C++
-  ! acc_ostptr: Only available in C/C++
+  ! acc_hostptr: Only available in C/C++
 
   interface acc_is_present
 function acc_is_present_32_h (a, len)
diff --git libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f 
libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f
index 4606d77..177e4fb 100644
--- libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f
+++ libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f
@@ -20,8 +20,8 @@
 
   SHARED_MEM = ACC_IS_PRESENT (H)
 
-  CALL ACC_PRESENT_OR_CREATE (H)
-  IF (.NOT. ACC_IS_PRESENT (H)) CALL ABORT
+  CALL ACC_PRESENT_OR_CREATE (H, INT (SIZEOF (H), 4))
+  IF (.NOT. ACC_IS_PRESENT (H, INT (SIZEOF (H), 8))) CALL ABORT
 
 !$ACC PARALLEL LOOP DEFAULT (PRESENT)
   DO I = 1, N
@@ -48,8 +48,7 @@
  H(I) = I + 4
   END DO
 
-!  CALL ACC_PCREATE (H)
-  CALL ACC_PRESENT_OR_CREATE (H)
+  CALL ACC_PCREATE (H, INT (SIZEOF (H), 4))
 
 !$ACC PARALLEL LOOP DEFAULT (PRESENT)
   DO I = 1, N
@@ -63,7 +62,7 @@
  H(I) = I + 6
   END DO
 
-  CALL ACC_PRESENT_OR_COPYIN (H)
+  CALL ACC_PRESENT_OR_COPYIN (H, INT (SIZEOF (H), 8))
 
 !$ACC PARALLEL LOOP DEFAULT (PRESENT)
   DO I = 1, N
@@ -77,8 +76,7 @@
  H(I) = I + 8
   END DO
 
-!  CALL ACC_PCOPYIN (H)
-  CALL ACC_PRESENT_OR_COPYIN (H)
+  CALL ACC_PCOPYIN (H, INT (SIZEOF (H), 4))
 
 !$ACC PARALLEL LOOP DEFAULT 

Translate libgomp.oacc-c-c++-common/lib-32.c into Fortran (was: C/C++ OpenACC: acc_pcopyin, acc_pcreate)

2017-05-22 Thread Thomas Schwinge
Hi!

On Mon, 22 May 2017 16:26:48 +0200, I wrote:
> C/C++ OpenACC: acc_pcopyin, acc_pcreate

> libgomp/
> [...]
> * testsuite/libgomp.oacc-c-c++-common/lib-38.c: Remove, merging
> its content into...
> * testsuite/libgomp.oacc-c-c++-common/lib-32.c: ... this file.
> Extend testing.

... which I then translated into two Fortran variants; OK for trunk?

commit 04ee44504e6256ee95ae3c6ba91a5960265b3261
Author: Thomas Schwinge 
Date:   Wed Apr 19 15:38:51 2017 +0200

Translate libgomp.oacc-c-c++-common/lib-32.c into Fortran

libgomp/
* testsuite/libgomp.oacc-fortran/lib-32-1.f: New file.
* testsuite/libgomp.oacc-fortran/lib-32-2.f: Likewise.
---
 .../testsuite/libgomp.oacc-c-c++-common/lib-32.c   |   1 +
 libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f  | 179 +
 libgomp/testsuite/libgomp.oacc-fortran/lib-32-2.f  | 173 
 3 files changed, 353 insertions(+)

diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/lib-32.c 
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-32.c
index 6a9e995..1696fb6 100644
--- libgomp/testsuite/libgomp.oacc-c-c++-common/lib-32.c
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/lib-32.c
@@ -1,4 +1,5 @@
 /* acc_present_or_create, acc_present_or_copyin, etc.  */
+/* See also Fortran variants in "../libgomp.oacc-fortran/lib-32*".  */
 
 #include 
 #include 
diff --git libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f 
libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f
new file mode 100644
index 000..4606d77
--- /dev/null
+++ libgomp/testsuite/libgomp.oacc-fortran/lib-32-1.f
@@ -0,0 +1,179 @@
+! ACC_PRESENT_OR_CREATE, ACC_PRESENT_OR_COPYIN, etc.
+! Variant of "../libgomp.oacc-c-c++-common/lib-32.c".
+! Variant using "openacc_lib.h".
+
+! { dg-do run }
+
+  PROGRAM MAIN
+  IMPLICIT NONE
+  INCLUDE "openacc_lib.h"
+
+  INTEGER, PARAMETER :: N = 1
+  INTEGER, ALLOCATABLE :: H(:)
+  INTEGER :: I
+  LOGICAL :: SHARED_MEM
+
+  ALLOCATE (H(N))
+  DO I = 1, N
+ H(I) = I + 0
+  END DO
+
+  SHARED_MEM = ACC_IS_PRESENT (H)
+
+  CALL ACC_PRESENT_OR_CREATE (H)
+  IF (.NOT. ACC_IS_PRESENT (H)) CALL ABORT
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ H(I) = I + 1
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (1, 0, SHARED_MEM)) CALL ABORT
+ H(I) = I + 2
+  END DO
+
+  CALL ACC_PRESENT_OR_CREATE (H)
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (2, 1, SHARED_MEM)) CALL ABORT
+ H(I) = I + 3
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (3, 2, SHARED_MEM)) CALL ABORT
+ H(I) = I + 4
+  END DO
+
+!  CALL ACC_PCREATE (H)
+  CALL ACC_PRESENT_OR_CREATE (H)
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (4, 3, SHARED_MEM)) CALL ABORT
+ H(I) = I + 5
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (5, 4, SHARED_MEM)) CALL ABORT
+ H(I) = I + 6
+  END DO
+
+  CALL ACC_PRESENT_OR_COPYIN (H)
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (6, 5, SHARED_MEM)) CALL ABORT
+ H(I) = I + 7
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (7, 6, SHARED_MEM)) CALL ABORT
+ H(I) = I + 8
+  END DO
+
+!  CALL ACC_PCOPYIN (H)
+  CALL ACC_PRESENT_OR_COPYIN (H)
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (8, 7, SHARED_MEM)) CALL ABORT
+ H(I) = I + 9
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (9, 8, SHARED_MEM)) CALL ABORT
+ H(I) = I + 10
+  END DO
+
+  CALL ACC_COPYOUT (H)
+  IF (.NOT. SHARED_MEM) THEN
+ IF (ACC_IS_PRESENT (H)) CALL ABORT
+  ENDIF
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (10, 9, SHARED_MEM)) CALL ABORT
+  END DO
+
+!  CALL ACC_PCOPYIN (H)
+  CALL ACC_PRESENT_OR_COPYIN (H)
+  IF (.NOT. ACC_IS_PRESENT (H)) CALL ABORT
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (10, 9, SHARED_MEM)) CALL ABORT
+ H(I) = I + 11
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (11, 9, SHARED_MEM)) CALL ABORT
+ H(I) = I + 12
+  END DO
+
+!  CALL ACC_PCOPYIN (H)
+  CALL ACC_PRESENT_OR_COPYIN (H)
+
+!$ACC PARALLEL LOOP DEFAULT (PRESENT)
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (12, 11, SHARED_MEM)) CALL ABORT
+ H(I) = I + 13
+  END DO
+!$ACC END PARALLEL LOOP
+
+  DO I = 1, N
+ IF (H(I) .NE. I + MERGE (13, 12, 

[PATCH v2] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)

2017-05-22 Thread Xi Ruoyao
On 2017-05-22Mon的 14:50 +0100, Jonathan Wakely wrote:
> On 22/05/17 21:41 +0800, Xi Ruoyao wrote:
> > On 2017-05-22 14:00 +0100, Jonathan Wakely wrote:
> > > On 18/05/17 19:27 +0800, Xi Ruoyao wrote:
> > > > This patch use ioctl to get entropy of std::random_device using
> > > > /dev/random and /dev/urandom.
> > > 
> > > This is a nice addition, thanks.
> > > 
> > > N.B. I couldn't apply your patch, several lines had U+00A0 (i.e.
> > > NO-BREAK SPACE) characters where normal spaces should be. I don't know
> > > if this is something your mail client did, but maybe attaching the
> > > patch as a multipart message rather than including it inline in the
> > > body will prevent it in future.
> > 
> > Oh no...  Seems my email client destroyed my patch. I'll attach the
> > patch next time.  Please wait for PATCH v2.
> 
> OK, will do. I missed part of the required changes when adding a new
> symbol version, see the attached patch.

The new patch is attached.  Just merged the patches you sent and fixed
the ChangeLog of gnu.ver and testsuite_abi.cc.

(For fun:  I had mistakenly attached the Vim .swp file of the patch
and almost sent it. :-p)
-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University
From dd343500100a32cca46fce8c698d34161ca25958 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao 
Date: Mon, 22 May 2017 22:19:18 +0800
Subject: [PATCH] PR libstdc++/67578 Implement non-trivial
 std::random_device::entropy

2017-05-22  Xi Ruoyao  
	Jonathan Wakely  

	PR libstdc++/67578
	* acinclude.m4: Bump libtool_VERSION.
	* config/abi/pre/gnu.ver: Create GLIBCXX_3.4.24 with new symbol.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Add test for .
	* doc/xml/manual/abi.xml: Document new library version.
	* include/bits/random.h (random_device::entropy)
	[_GLIBCXX_USE_RANDOM_TR1]: Add call to new _M_getentropy member.
	(random_device::_M_getentropy): Declare.
	* src/c++11/random.cc (random_device::_M_getentropy): Define.
	* testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.24 to known
	versions, and make it the latest version.
---
 libstdc++-v3/acinclude.m4|  2 +-
 libstdc++-v3/config/abi/pre/gnu.ver  |  7 ++
 libstdc++-v3/configure.ac|  2 +-
 libstdc++-v3/doc/xml/manual/abi.xml  |  2 ++
 libstdc++-v3/include/bits/random.h   |  9 ++-
 libstdc++-v3/src/c++11/random.cc | 35 
 libstdc++-v3/testsuite/util/testsuite_abi.cc |  3 ++-
 7 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 61c8cb2..baeea67 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -3750,7 +3750,7 @@ changequote([,])dnl
 fi
 
 # For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=6:23:0
+libtool_VERSION=6:24:0
 
 # Everything parsed; figure out what files and settings to use.
 case $enable_symvers in
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 268fb94..48e2ec8 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1967,6 +1967,13 @@ GLIBCXX_3.4.23 {
 
 } GLIBCXX_3.4.22;
 
+GLIBCXX_3.4.24 {
+
+# std::random_device::_M_getentropy() const
+_ZNKSt13random_device13_M_getentropyEv;
+
+} GLIBCXX_3.4.23;
+
 # Symbols in the support library (libsupc++) have their own tag.
 CXXABI_1.3 {
 
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index 8e97350..270dcba 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -237,7 +237,7 @@ AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \
 locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \
 strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \
 sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \
-wchar.h wctype.h])
+wchar.h wctype.h linux/random.h])
 
 # Only do link tests if native. Else, hardcode.
 if $GLIBCXX_IS_NATIVE; then
diff --git a/libstdc++-v3/doc/xml/manual/abi.xml b/libstdc++-v3/doc/xml/manual/abi.xml
index d086d9e..de8e66c 100644
--- a/libstdc++-v3/doc/xml/manual/abi.xml
+++ b/libstdc++-v3/doc/xml/manual/abi.xml
@@ -266,6 +266,7 @@ compatible.
 GCC 5.1.0: libstdc++.so.6.0.21
 GCC 6.1.0: libstdc++.so.6.0.22
 GCC 7.1.0: libstdc++.so.6.0.23
+GCC 8.0.0: libstdc++.so.6.0.24
 
 
   Note 1: Error should be libstdc++.so.3.0.3.
@@ -334,6 +335,7 @@ compatible.
 GCC 5.1.0: GLIBCXX_3.4.21, CXXABI_1.3.9
 GCC 6.1.0: GLIBCXX_3.4.22, CXXABI_1.3.10
 GCC 7.1.0: GLIBCXX_3.4.23, CXXABI_1.3.11
+GCC 8.0.0: GLIBCXX_3.4.24, CXXABI_1.3.10
 
 
 
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index d39cc3e..bb761ec 100644
--- 

C/C++ OpenACC: acc_pcopyin, acc_pcreate

2017-05-22 Thread Thomas Schwinge
Hi!

In , we currently describe acc_pcopyin, acc_pcreate as "old
names", but they're not "old" but really "alternative names", with the
intention to provide them at symbol level, not via "#define"s.  OK for
trunk?

commit 89c6599cc343a2f3b087caf9cb47c2c42bb02074
Author: Thomas Schwinge 
Date:   Wed Apr 19 15:37:11 2017 +0200

C/C++ OpenACC: acc_pcopyin, acc_pcreate

libgomp/
* openacc.h (acc_pcopyin, acc_pcreate): Provide prototypes instead
of preprocessor definitions.
* libgomp.h (strong_alias): Guard by "#ifdef
HAVE_ATTRIBUTE_ALIAS".
* oacc-mem.c: Provide "acc_pcreate" as alias for
"acc_present_or_create", and "acc_pcopyin" as alias for
"acc_present_or_copyin".
* libgomp.map (OACC_2.0): Add "acc_pcopyin", and "acc_pcreate".
* testsuite/libgomp.oacc-c-c++-common/lib-38.c: Remove, merging
its content into...
* testsuite/libgomp.oacc-c-c++-common/lib-32.c: ... this file.
Extend testing.
---
 libgomp/libgomp.h  |   5 +-
 libgomp/libgomp.map|   2 +
 libgomp/oacc-mem.c |  22 ++
 libgomp/openacc.h  |   7 +-
 .../testsuite/libgomp.oacc-c-c++-common/lib-32.c   | 241 +++--
 .../testsuite/libgomp.oacc-c-c++-common/lib-38.c   |  64 --
 6 files changed, 254 insertions(+), 87 deletions(-)

diff --git libgomp/libgomp.h libgomp/libgomp.h
index 1769a48..940b5b8 100644
--- libgomp/libgomp.h
+++ libgomp/libgomp.h
@@ -1060,8 +1060,6 @@ extern void gomp_set_nest_lock_25 (omp_nest_lock_25_t *) 
__GOMP_NOTHROW;
 extern void gomp_unset_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
 extern int gomp_test_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
 
-# define strong_alias(fn, al) \
-  extern __typeof (fn) al __attribute__ ((alias (#fn)));
 # define omp_lock_symver(fn) \
   __asm (".symver g" #fn "_30, " #fn "@@OMP_3.0"); \
   __asm (".symver g" #fn "_25, " #fn "@OMP_1.0");
@@ -1085,6 +1083,9 @@ extern int gomp_test_nest_lock_25 (omp_nest_lock_25_t *) 
__GOMP_NOTHROW;
 #endif
 
 #ifdef HAVE_ATTRIBUTE_ALIAS
+# define strong_alias(fn, al) \
+  extern __typeof (fn) al __attribute__ ((alias (#fn)));
+
 # define ialias_ulpialias_str1(__USER_LABEL_PREFIX__)
 # define ialias_str1(x)ialias_str2(x)
 # define ialias_str2(x)#x
diff --git libgomp/libgomp.map libgomp/libgomp.map
index 4d42c42..c7bf245 100644
--- libgomp/libgomp.map
+++ libgomp/libgomp.map
@@ -335,6 +335,7 @@ OACC_2.0 {
acc_copyin_64_h_;
acc_copyin_array_h_;
acc_present_or_copyin;
+   acc_pcopyin;
acc_present_or_copyin_32_h_;
acc_present_or_copyin_64_h_;
acc_present_or_copyin_array_h_;
@@ -343,6 +344,7 @@ OACC_2.0 {
acc_create_64_h_;
acc_create_array_h_;
acc_present_or_create;
+   acc_pcreate;
acc_present_or_create_32_h_;
acc_present_or_create_64_h_;
acc_present_or_create_array_h_;
diff --git libgomp/oacc-mem.c libgomp/oacc-mem.c
index 2df2202..ff3ed49 100644
--- libgomp/oacc-mem.c
+++ libgomp/oacc-mem.c
@@ -514,12 +514,34 @@ acc_present_or_create (void *h, size_t s)
   return present_create_copy (FLAG_PRESENT | FLAG_CREATE, h, s);
 }
 
+/* acc_pcreate is acc_present_or_create by a different name.  */
+#ifdef HAVE_ATTRIBUTE_ALIAS
+strong_alias (acc_present_or_create, acc_pcreate)
+#else
+void *
+acc_pcreate (void *h, size_t s)
+{
+  return acc_present_or_create (h, s);
+}
+#endif
+
 void *
 acc_present_or_copyin (void *h, size_t s)
 {
   return present_create_copy (FLAG_PRESENT | FLAG_CREATE | FLAG_COPY, h, s);
 }
 
+/* acc_pcopyin is acc_present_or_copyin by a different name.  */
+#ifdef HAVE_ATTRIBUTE_ALIAS
+strong_alias (acc_present_or_copyin, acc_pcopyin)
+#else
+void *
+acc_pcopyin (void *h, size_t s)
+{
+  return acc_present_or_copyin (h, s);
+}
+#endif
+
 #define FLAG_COPYOUT (1 << 0)
 
 static void
diff --git libgomp/openacc.h libgomp/openacc.h
index 53d0c39..ebccb18 100644
--- libgomp/openacc.h
+++ libgomp/openacc.h
@@ -91,8 +91,10 @@ void acc_free (void *) __GOACC_NOTHROW;
the standard specifies otherwise.  */
 void *acc_copyin (void *, size_t) __GOACC_NOTHROW;
 void *acc_present_or_copyin (void *, size_t) __GOACC_NOTHROW;
+void *acc_pcopyin (void *, size_t) __GOACC_NOTHROW;
 void *acc_create (void *, size_t) __GOACC_NOTHROW;
 void *acc_present_or_create (void *, size_t) __GOACC_NOTHROW;
+void *acc_pcreate (void *, size_t) __GOACC_NOTHROW;
 void acc_copyout (void *, size_t) __GOACC_NOTHROW;
 void acc_delete (void *, size_t) __GOACC_NOTHROW;
 void acc_update_device (void *, size_t) __GOACC_NOTHROW;
@@ -105,11 +107,6 @@ int acc_is_present (void *, size_t) __GOACC_NOTHROW;
 void acc_memcpy_to_device (void *, void *, size_t) __GOACC_NOTHROW;
 void acc_memcpy_from_device (void *, void *, size_t) 

[PATCH] Dump function on internal errors

2017-05-22 Thread Andi Kleen
From: Andi Kleen 

When a verification check fails it is useful to dump the current
function to the dump file, so it's easier to figure out what
actually went wrong.

v2: Updated version now using a hook in internal_error, and
also prints the pass name and the dump file name.

gcc/:

2017-05-21  Andi Kleen  

* diagnostic.c (internal_error): Call hook.
(set_internal_error_hook): New function.
* diagnostic.h: Add set_internal_error_hook.
* passes.c: (pass_ice_hook): Add class to set
internal_error_hook to dump functions.
---
 gcc/diagnostic.c | 18 ++
 gcc/diagnostic.h |  1 +
 gcc/passes.c | 21 +
 3 files changed, 40 insertions(+)

diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 158519606f8..8d9caade60b 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -33,6 +33,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-color.h"
 #include "edit-context.h"
 #include "selftest.h"
+#include "tree.h"
+#include "tree-pass.h"
+#include "tree-cfg.h"
 
 #ifdef HAVE_TERMIOS_H
 # include 
@@ -1396,6 +1399,10 @@ fatal_error (location_t loc, const char *gmsgid, ...)
   gcc_unreachable ();
 }
 
+/* Hook to call on internal errors.  */
+
+static void (*internal_error_hook)();
+
 /* An internal consistency check has failed.  We make no attempt to
continue.  Note that unless there is debugging value to be had from
a more specific message, or some other good reason, you should use
@@ -1403,6 +1410,9 @@ fatal_error (location_t loc, const char *gmsgid, ...)
 void
 internal_error (const char *gmsgid, ...)
 {
+  if (internal_error_hook)
+internal_error_hook ();
+
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
@@ -1412,6 +1422,14 @@ internal_error (const char *gmsgid, ...)
   gcc_unreachable ();
 }
 
+/* Call HOOK on internal errors.  */
+
+void
+set_internal_error_hook (void (*hook)())
+{
+  internal_error_hook = hook;
+}
+
 /* Like internal_error, but no backtrace will be printed.  Used when
the internal error does not happen at the current location, but happened
somewhere else.  */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index dbd1703e0ef..3d26a84ab44 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -369,5 +369,6 @@ extern char *file_name_as_prefix (diagnostic_context *, 
const char *);
 
 extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
 
+extern void set_internal_error_hook (void (*)());
 
 #endif /* ! GCC_DIAGNOSTIC_H */
diff --git a/gcc/passes.c b/gcc/passes.c
index e7c5d194010..1bd92c8140a 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -3040,4 +3040,25 @@ function_called_by_processed_nodes_p (void)
   return e != NULL;
 }
 
+class pass_ice_hook {
+
+  /* Print function to dump file on internal errors.  */
+
+  static void ice_hook() {
+if (dump_file)
+  {
+   fprintf (stderr, "Dumping function to dump file %s for pass %s\n",
+dump_file_name, current_pass->name);
+   dump_function_to_file (current_function_decl, dump_file, dump_flags);
+  }
+  }
+
+ public:
+  pass_ice_hook() {
+set_internal_error_hook (ice_hook);
+  }
+};
+
+static pass_ice_hook pass_ice_hook;
+
 #include "gt-passes.h"
-- 
2.12.2



Re: [PATCH] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)

2017-05-22 Thread Xi Ruoyao
On 2017-05-22 14:50 +0100, Jonathan Wakely wrote:
> On 22/05/17 21:41 +0800, Xi Ruoyao wrote:
> > On 2017-05-22 14:00 +0100, Jonathan Wakely wrote:
> > > On 18/05/17 19:27 +0800, Xi Ruoyao wrote:
> > > > This patch use ioctl to get entropy of std::random_device using
> > > > /dev/random and /dev/urandom.
> > > 
> > > This is a nice addition, thanks.
> > > 
> > > N.B. I couldn't apply your patch, several lines had U+00A0 (i.e.
> > > NO-BREAK SPACE) characters where normal spaces should be. I don't know
> > > if this is something your mail client did, but maybe attaching the
> > > patch as a multipart message rather than including it inline in the
> > > body will prevent it in future.
> > 
> > Oh no...  Seems my email client destroyed my patch. I'll attach the
> > patch next time.  Please wait for PATCH v2.
> 
> OK, will do. I missed part of the required changes when adding a new
> symbol version, see the attached patch.
> 

In very old Linux kernel (1.3.x) there is random.h but not RNDGETENTCNT.
The random.h without RNDGETENTCNT was only used in the kernel internally.
But at that time Linux Makefile didn't have "headers_install" target
so user may copy all headers (including the internal ones) to /usr/include.
It seems we should check RNDGETENTCNT explicitly if we want to support
1.3.x.
-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University



Re: [PATCH] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)

2017-05-22 Thread Jonathan Wakely

On 22/05/17 21:41 +0800, Xi Ruoyao wrote:

On 2017-05-22 14:00 +0100, Jonathan Wakely wrote:

On 18/05/17 19:27 +0800, Xi Ruoyao wrote:
> This patch use ioctl to get entropy of std::random_device using
> /dev/random and /dev/urandom.

This is a nice addition, thanks.

N.B. I couldn't apply your patch, several lines had U+00A0 (i.e.
NO-BREAK SPACE) characters where normal spaces should be. I don't know
if this is something your mail client did, but maybe attaching the
patch as a multipart message rather than including it inline in the
body will prevent it in future.


Oh no...  Seems my email client destroyed my patch. I'll attach the
patch next time.  Please wait for PATCH v2.


OK, will do. I missed part of the required changes when adding a new
symbol version, see the attached patch.


diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc
index 953c907..ee7572e 100644
--- a/libstdc++-v3/testsuite/util/testsuite_abi.cc
+++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc
@@ -235,7 +235,7 @@ check_version(symbol& test, bool added)
 	test.version_status = symbol::incompatible;
 
   // Check that added symbols are added in the latest pre-release version.
-  bool latestp = (test.version_name == "GLIBCXX_3.4.23"
+  bool latestp = (test.version_name == "GLIBCXX_3.4.24"
 		 || test.version_name == "CXXABI_1.3.11"
 		 || test.version_name == "CXXABI_FLOAT128"
 		 || test.version_name == "CXXABI_TM_1");


Re: [PATCH] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)

2017-05-22 Thread Xi Ruoyao
On 2017-05-22 14:00 +0100, Jonathan Wakely wrote:
> On 18/05/17 19:27 +0800, Xi Ruoyao wrote:
> > This patch use ioctl to get entropy of std::random_device using
> > /dev/random and /dev/urandom.
> 
> This is a nice addition, thanks.
> 
> N.B. I couldn't apply your patch, several lines had U+00A0 (i.e.
> NO-BREAK SPACE) characters where normal spaces should be. I don't know
> if this is something your mail client did, but maybe attaching the
> patch as a multipart message rather than including it inline in the
> body will prevent it in future.

Oh no...  Seems my email client destroyed my patch. I'll attach the
patch next time.  Please wait for PATCH v2.

> > diff --git a/libstdc++-v3/config/abi/pre/gnu.ver 
> > b/libstdc++-v3/config/abi/pre/gnu.ver
> > index 3e6e70b..39ad330 100644
> > --- a/libstdc++-v3/config/abi/pre/gnu.ver
> > +++ b/libstdc++-v3/config/abi/pre/gnu.ver
> > @@ -1963,6 +1963,9 @@ GLIBCXX_3.4.23 {
> >  _ZNSt13__future_base13_State_baseV211_Make_ready6_M_setEv;
> >  #endif
> >  
> > +# std::random_device::_M_getentropy() const
> > +_ZNKSt13random_device13_M_getentropyEv;
> > +
> >  } GLIBCXX_3.4.22;
> 
> The 3.4.23 version is now "closed" because it was used for the GCC 7.1
> release, and so we can't add new symbols to it. That means we need to
> bump the library version and create a new GLIBCXX_3.4.24 version node.
> The required steps are documented in doc/xml/manual/build_hacking.xml
> (and done by the attached patch which I'm testing).

I'll do it.  Glad to add the first symbol in 3.4.24.

> > @@ -161,6 +169,34 @@ namespace std _GLIBCXX_VISIBILITY(default)
> >  return _M_mt();
> >    }
> >  
> > +  double
> > +  random_device::_M_getentropy() const noexcept
> > +  {
> > +#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && \
> > +defined _GLIBCXX_HAVE_LINUX_RANDOM_H
> 
> Is RNDGETENTCNT guaranteed to be defined by all versions of
> ?
> 
> Would it be better to check for it explicitly? i.e.
> 
> #if defined _GLIBCXX_HAVE_SYS_IOCTL_H && defined RNDGETENTCNT

It has been there since the git repo of Linux kernel was created.
I have to check the ancient history of kernel code to know.

> 
> It would also be nice to have a test for this functionality, but since
> the available entropy might be zero sometimes we can't guarantee that
> a test for a non-zero value will always pass.

I've thought about it, but I couldn't find out how to do the test.
-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University



Re: [Patch] SFINAE on is_same first in variant's _Tp&& constructor

2017-05-22 Thread Jonathan Wakely

On 19/05/17 22:40 -0700, Tim Shen via libstdc++ wrote:

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 0e04a820d69..b9824a5182c 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -936,9 +936,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  noexcept((is_nothrow_move_constructible_v<_Types> && ...)) = default;

  template, variant>>,
   typename = enable_if_t<__exactly_once<__accepted_type<_Tp&&>>
- && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>
- && !is_same_v, variant>>>
+ && is_constructible_v<__accepted_type<_Tp&&>, _Tp&&>>>


Does this definitely short-circuit? I seem to recall a similar case
where either Clang or GCC (I think it was Clang) was evaluating the
second default template argument even though the first had produce a
substition failure.

If we need to guarantee it short-circuits then we'd want:

 template, variant>>,
 __bool_constant<
   __exactly_once<__accepted_type<_Tp&&>>
   && is_constructible_v<__accepted_type<_Tp&&>, 
_Tp&&>>>

i.e. use __and_< is-this-type, everything-else> where
"everything-else" still uses && to avoid making the instantiations too
deep.

Also, this is another place where we could use an __is_samey
trait that does is_same.



Re: [PATCH] Implement non-trivial std::random_device::entropy (PR libstdc++/67578)

2017-05-22 Thread Jonathan Wakely

On 18/05/17 19:27 +0800, Xi Ruoyao wrote:

This patch use ioctl to get entropy of std::random_device using
/dev/random and /dev/urandom.


This is a nice addition, thanks.

N.B. I couldn't apply your patch, several lines had U+00A0 (i.e.
NO-BREAK SPACE) characters where normal spaces should be. I don't know
if this is something your mail client did, but maybe attaching the
patch as a multipart message rather than including it inline in the
body will prevent it in future.


diff --git a/libstdc++-v3/config/abi/pre/gnu.ver 
b/libstdc++-v3/config/abi/pre/gnu.ver
index 3e6e70b..39ad330 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1963,6 +1963,9 @@ GLIBCXX_3.4.23 {
 _ZNSt13__future_base13_State_baseV211_Make_ready6_M_setEv;
 #endif
 
+# std::random_device::_M_getentropy() const
+_ZNKSt13random_device13_M_getentropyEv;
+
 } GLIBCXX_3.4.22;


The 3.4.23 version is now "closed" because it was used for the GCC 7.1
release, and so we can't add new symbols to it. That means we need to
bump the library version and create a new GLIBCXX_3.4.24 version node.
The required steps are documented in doc/xml/manual/build_hacking.xml
(and done by the attached patch which I'm testing).


@@ -161,6 +169,34 @@ namespace std _GLIBCXX_VISIBILITY(default)
 return _M_mt();
   }
 
+  double
+  random_device::_M_getentropy() const noexcept
+  {
+#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && \
+defined _GLIBCXX_HAVE_LINUX_RANDOM_H


Is RNDGETENTCNT guaranteed to be defined by all versions of
?

Would it be better to check for it explicitly? i.e.

#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && defined RNDGETENTCNT


It would also be nice to have a test for this functionality, but since
the available entropy might be zero sometimes we can't guarantee that
a test for a non-zero value will always pass.

commit 2e6f7939b6ab2ac0e25af6fc57085bcef8381d04
Author: Jonathan Wakely 
Date:   Mon May 22 13:36:53 2017 +0100

PR libstdc++/67578 Implement non-trivial std::random_device::entropy

2017-05-22  Xi Ruoyao  
	Jonathan Wakely  

	PR libstdc++/67578
	* acinclude.m4: Bump libtool_VERSION.
	* config/abi/pre/gnu.ver: Add GLIBCXX_3.4.23 with new symbol.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Add test for .
	* doc/xml/manual/abi.xml: Document new library version.
	* include/bits/random.h (random_device::entropy)
	[_GLIBCXX_USE_RANDOM_TR1]: Add call to new _M_getentropy member.
	(random_device::_M_getentropy): Declare.
	* src/c++11/random.cc (random_device::_M_getentropy): Define.
	* testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.24 to known
	versions.

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 61c8cb2..baeea67 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -3750,7 +3750,7 @@ changequote([,])dnl
 fi
 
 # For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=6:23:0
+libtool_VERSION=6:24:0
 
 # Everything parsed; figure out what files and settings to use.
 case $enable_symvers in
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 268fb94..48e2ec8 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1967,6 +1967,13 @@ GLIBCXX_3.4.23 {
 
 } GLIBCXX_3.4.22;
 
+GLIBCXX_3.4.24 {
+
+# std::random_device::_M_getentropy() const
+_ZNKSt13random_device13_M_getentropyEv;
+
+} GLIBCXX_3.4.23;
+
 # Symbols in the support library (libsupc++) have their own tag.
 CXXABI_1.3 {
 
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index 8e97350..270dcba 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -237,7 +237,7 @@ AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \
 locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \
 strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \
 sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \
-wchar.h wctype.h])
+wchar.h wctype.h linux/random.h])
 
 # Only do link tests if native. Else, hardcode.
 if $GLIBCXX_IS_NATIVE; then
diff --git a/libstdc++-v3/doc/xml/manual/abi.xml b/libstdc++-v3/doc/xml/manual/abi.xml
index d086d9e..de8e66c 100644
--- a/libstdc++-v3/doc/xml/manual/abi.xml
+++ b/libstdc++-v3/doc/xml/manual/abi.xml
@@ -266,6 +266,7 @@ compatible.
 GCC 5.1.0: libstdc++.so.6.0.21
 GCC 6.1.0: libstdc++.so.6.0.22
 GCC 7.1.0: libstdc++.so.6.0.23
+GCC 8.0.0: libstdc++.so.6.0.24
 
 
   Note 1: Error should be libstdc++.so.3.0.3.
@@ -334,6 +335,7 @@ compatible.
 GCC 5.1.0: GLIBCXX_3.4.21, CXXABI_1.3.9
 GCC 6.1.0: GLIBCXX_3.4.22, CXXABI_1.3.10
 GCC 7.1.0: GLIBCXX_3.4.23, CXXABI_1.3.11
+GCC 8.0.0: GLIBCXX_3.4.24, CXXABI_1.3.10
 
 
 
diff --git 

libgomp nvptx plugin: Debugging output for cuInit failure

2017-05-22 Thread Thomas Schwinge
Hi!

OK for trunk?

commit 7b2f06b7d2fd23b20d81fda8be6ec7453e8b3fe3
Author: Thomas Schwinge 
Date:   Thu Dec 22 08:30:04 2016 +0100

libgomp nvptx plugin: Debugging output for cuInit failure

libgomp/
* plugin/plugin-nvptx.c (nvptx_get_num_devices): Debugging output
for cuInit failure.
---
 libgomp/plugin/plugin-nvptx.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git libgomp/plugin/plugin-nvptx.c libgomp/plugin/plugin-nvptx.c
index 3ef48dd..0e1b3e2 100644
--- libgomp/plugin/plugin-nvptx.c
+++ libgomp/plugin/plugin-nvptx.c
@@ -838,7 +838,11 @@ nvptx_get_num_devices (void)
   /* PR libgomp/65099: Currently, we only support offloading in 64-bit
  configurations.  */
   if (sizeof (void *) != 8)
-return 0;
+{
+  GOMP_PLUGIN_debug (0, "Disabling nvptx offloading;"
+" only 64-bit configurations are supported\n");
+  return 0;
+}
 
   /* This function will be called before the plugin has been initialized in
  order to enumerate available devices, but CUDA API routines can't be used
@@ -852,7 +856,11 @@ nvptx_get_num_devices (void)
   /* This is not an error: e.g. we may have CUDA libraries installed but
  no devices available.  */
   if (r != CUDA_SUCCESS)
-return 0;
+   {
+ GOMP_PLUGIN_debug (0, "Disabling nvptx offloading; cuInit: %s\n",
+cuda_error (r));
+ return 0;
+   }
 }
 
   CUDA_CALL_ERET (-1, cuDeviceGetCount, );


Grüße
 Thomas


[DUMP PATCH]: Move fdump-translation-unit to C++ FE only

2017-05-22 Thread Nathan Sidwell
This patch moves the -fdump-translation-unit into the new langhook for 
registering dumps.  On the way the option gets renamed to -fdump-lang-raw.


Committed as obvious.

nathan
--
Nathan Sidwell
2017-05-22  Nathan Sidwell  

	gcc/
	* doc/invoke.texi (fdump-translation-unit): Delete documentation.
	(fdump-lang): Document 'raw' option.
	* dumpfile.h (TDI_tu): Delete.
	* dumpfile.c (dump_files): Remove translation-unit.
	(FIRST_AUTO_NUMBERED_DUMP): Decrement.
	gcc/cp/
	* cp-objcp-common.c (cp_register_dumps): Register raw dumper.
	* cp-tree.h (raw_dump_id): Declare.
	* decl2.c (raw_dump_id): Define.
	(dump_tu): Use raw_dump_id.
	gcc/c/
	* c-decl.c (c_parse_final_cleanups): Drop TDI_tu handling.

Index: c/c-decl.c
===
--- c/c-decl.c	(revision 248332)
+++ c/c-decl.c	(working copy)
@@ -11214,18 +11214,6 @@ c_parse_final_cleanups (void)
   dump_ada_specs (collect_all_refs, NULL);
 }
 
-  if (ext_block)
-{
-  tree tmp = BLOCK_VARS (ext_block);
-  dump_flags_t flags;
-  FILE * stream = dump_begin (TDI_tu, );
-  if (stream && tmp)
-	{
-	  dump_node (tmp, flags & ~TDF_SLIM, stream);
-	  dump_end (TDI_tu, stream);
-	}
-}
-
   /* Process all file scopes in this compilation, and the external_scope,
  through wrapup_global_declarations.  */
   FOR_EACH_VEC_ELT (*all_translation_units, i, t)
Index: cp/cp-objcp-common.c
===
--- cp/cp-objcp-common.c	(revision 248332)
+++ cp/cp-objcp-common.c	(working copy)
@@ -359,6 +359,9 @@ cp_register_dumps (gcc::dump_manager *du
 {
   class_dump_id = dumps->dump_register
 (".class", "lang-class", "lang-class", DK_lang, OPTGROUP_NONE, false);
+
+  raw_dump_id = dumps->dump_register
+(".raw", "lang-raw", "lang-raw", DK_lang, OPTGROUP_NONE, false);
 }
 
 void
Index: cp/cp-tree.h
===
--- cp/cp-tree.h	(revision 248332)
+++ cp/cp-tree.h	(working copy)
@@ -5776,6 +5776,7 @@ extern cp_parameter_declarator *no_param
 
 /* Various dump ids.  */
 extern int class_dump_id;
+extern int raw_dump_id;
 
 /* in call.c */
 extern bool check_dtor_name			(tree, tree);
Index: cp/decl2.c
===
--- cp/decl2.c	(revision 248332)
+++ cp/decl2.c	(working copy)
@@ -49,6 +49,9 @@ along with GCC; see the file COPYING3.
 #include "c-family/c-ada-spec.h"
 #include "asan.h"
 
+/* Id for dumping the raw trees.  */
+int raw_dump_id;
+ 
 extern cpp_reader *parse_in;
 
 /* This structure contains information about the initializations
@@ -4362,12 +4365,10 @@ static void
 dump_tu (void)
 {
   dump_flags_t flags;
-  FILE *stream = dump_begin (TDI_tu, );
-
-  if (stream)
+  if (FILE *stream = dump_begin (raw_dump_id, ))
 {
   dump_node (global_namespace, flags & ~TDF_SLIM, stream);
-  dump_end (TDI_tu, stream);
+  dump_end (raw_dump_id, stream);
 }
 }
 
Index: doc/invoke.texi
===
--- doc/invoke.texi	(revision 248332)
+++ doc/invoke.texi	(working copy)
@@ -550,7 +550,6 @@ Objective-C and Objective-C++ Dialects}.
 -fdump-passes @gol
 -fdump-rtl-@var{pass}  -fdump-rtl-@var{pass}=@var{filename} @gol
 -fdump-statistics @gol
--fdump-translation-unit@r{[}-@var{n}@r{]} @gol
 -fdump-tree-all @gol
 -fdump-tree-@var{switch} @gol
 -fdump-tree-@var{switch}-@var{options} @gol
@@ -12972,7 +12971,7 @@ Dump after function inlining.
 @opindex fdump-lang
 Control the dumping of language-specific information.  The @var{options}
 and @var{filename} portions behave as described in the
-`@option{-fdump-tree} option.  The following @var{switch} values are
+@option{-fdump-tree} option.  The following @var{switch} values are
 accepted:
 
 @table @samp
@@ -12984,6 +12983,9 @@ Enable all language-specific dumps.
 Dump class hierarchy information.  Virtual table information is emitted
 unless '@option{slim}' is specified.  This option is applicable to C++ only.
 
+@item raw
+Dump the raw internal tree data.  This option is applicable to C++ only.
+
 @end table
 
 @item -fdump-passes
@@ -13002,16 +13004,6 @@ whole compilation unit while @samp{-deta
 the passes generate them.  The default with no option is to sum
 counters for each function compiled.
 
-@item -fdump-translation-unit @r{(C++ only)}
-@itemx -fdump-translation-unit-@var{options} @r{(C++ only)}
-@opindex fdump-translation-unit
-Dump a representation of the tree structure for the entire translation
-unit to a file.  The file name is made by appending @file{.tu} to the
-source file name, and the file is created in the same directory as the
-output file.  If the @samp{-@var{options}} form is used, @var{options}
-controls the details of the dump as described for the
-@option{-fdump-tree} options.
-
 @item -fdump-tree-all
 @itemx -fdump-tree-@var{switch}
 @itemx -fdump-tree-@var{switch}-@var{options}

[C++ PATCH] config-lang.in

2017-05-22 Thread Nathan Sidwell
gtfiles in config-lang.in is a massive line of confusion.  While very 
rarely modified, it's completely impossible^W^Wreally hard to tell 
what's changed.


Committed this patch to break the line and sort it.  Although sh can 
cope with newlines in the middle of a string, the value gets fed to 
make, which doesn't understand.  Hence the escaped newlines.


nathan
--
Nathan Sidwell
2017-05-22  Nathan Sidwell  

	* config-lang.in (gtfiles): Sort list, break lines.

Index: config-lang.in
===
--- config-lang.in	(revision 248326)
+++ config-lang.in	(working copy)
@@ -29,4 +29,28 @@ compilers="cc1plus\$(exeext)"
 
 target_libs="target-libstdc++-v3"
 
-gtfiles="\$(srcdir)/cp/rtti.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/name-lookup.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.h \$(srcdir)/cp/call.c \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/pt.c \$(srcdir)/cp/repo.c \$(srcdir)/cp/semantics.c \$(srcdir)/cp/tree.c \$(srcdir)/cp/parser.h \$(srcdir)/cp/parser.c \$(srcdir)/cp/method.c \$(srcdir)/cp/typeck2.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c \$(srcdir)/c-family/c-format.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-objcp-common.c \$(srcdir)/cp/cp-lang.c \$(srcdir)/cp/except.c \$(srcdir)/cp/vtable-class-hierarchy.c \$(srcdir)/cp/constexpr.c \$(srcdir)/cp/cp-gimplify.c \$(srcdir)/cp/init.c \$(srcdir)/cp/friend.c \$(srcdir)/cp/lambda.c"
+# The header files must come first, but otherwise please keep this
+# list sorted.
+gtfiles="\
+\$(srcdir)/cp/name-lookup.h \$(srcdir)/cp/cp-tree.h \
+\$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \
+\$(srcdir)/c-family/c-pragma.h \$(srcdir)/cp/decl.h \
+\$(srcdir)/cp/parser.h \
+\$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-format.c \
+\$(srcdir)/c-family/c-lex.c \$(srcdir)/c-family/c-pragma.c \
+\$(srcdir)/cp/call.c \$(srcdir)/cp/class.c \$(srcdir)/cp/constexpr.c \
+\$(srcdir)/cp/cp-gimplify.c \
+\$(srcdir)/cp/cp-lang.c \$(srcdir)/cp/cp-objcp-common.c \
+\$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \
+\$(srcdir)/cp/except.c \
+\$(srcdir)/cp/friend.c \
+\$(srcdir)/cp/init.c \
+\$(srcdir)/cp/lambda.c \
+\$(srcdir)/cp/mangle.c \$(srcdir)/cp/method.c \
+\$(srcdir)/cp/name-lookup.c \
+\$(srcdir)/cp/parser.c \$(srcdir)/cp/pt.c \
+\$(srcdir)/cp/repo.c \$(srcdir)/cp/rtti.c \
+\$(srcdir)/cp/semantics.c \
+\$(srcdir)/cp/tree.c \$(srcdir)/cp/typeck2.c \
+\$(srcdir)/cp/vtable-class-hierarchy.c \
+" 


Re: [PTX] simplify movs

2017-05-22 Thread Nathan Sidwell

On 05/21/2017 03:35 AM, Tom de Vries wrote:

On 12/02/2015 04:09 PM, Nathan Sidwell wrote:

+/* Output a pattern for a move instruction.  */
+
+const char *
+nvptx_output_mov_insn (rtx dst, rtx src)
+{


src_inner uses dst_mode rather than GET_MODE (src). I'm trying to 
understand if that is intentional or not.


I have no idea.

--
Nathan Sidwell


Re: [patch,avr] Simplify genmultilib.awk

2017-05-22 Thread Denis Chertykov
2017-05-22 15:37 GMT+04:00 Georg-Johann Lay :
> This patch simplifies genmultilib.awk so that it generates
> MULTILIB_REQUIRED instead of the complement, MULTILIB_EXCEPTIONS.
>
> The current awk script dates back to the days when we mapped
> all the > 200 devices to the mmcu core and also parts of
> --help=target to list all devices were generated from avr-mmcus.
> That code rot is also cleaned up.  Moreover, the structure now allows
> for simpler addition of new multilib options which are likely to come
> in the near future.
>
> The result of -print-multi-lib is:
>
> .;
> avr25;@mmcu=avr25
> avr3;@mmcu=avr3
> avr31;@mmcu=avr31
> avr35;@mmcu=avr35
> avr4;@mmcu=avr4
> avr5;@mmcu=avr5
> avr51;@mmcu=avr51
> avr6;@mmcu=avr6
> avrxmega2;@mmcu=avrxmega2
> avrxmega4;@mmcu=avrxmega4
> avrxmega5;@mmcu=avrxmega5
> avrxmega6;@mmcu=avrxmega6
> avrxmega7;@mmcu=avrxmega7
> avrtiny;@mmcu=avrtiny
> tiny-stack;@msp8
> avr25/tiny-stack;@mmcu=avr25@msp8
>
> hence unchanged.
>
> Ok for trunk?
>
> Johann
>
>
> * config/avr/t-avr (AWK) [t-multilib]: Remove "-v FORMAT=Makefile"
> command option from $(AWK) call.
> * config/avr/genmultilib.awk: Simplify and rewrite so that it
> generates MULTILIB_REQUIRED instead of MULTILIB_EXCEPTIONS.
> [FORMAT]: Remove handling of variable.
> * config/avr/t-multilib: Regenerate.

Approved.
Please commit.


[patch,avr] Simplify genmultilib.awk

2017-05-22 Thread Georg-Johann Lay

This patch simplifies genmultilib.awk so that it generates
MULTILIB_REQUIRED instead of the complement, MULTILIB_EXCEPTIONS.

The current awk script dates back to the days when we mapped
all the > 200 devices to the mmcu core and also parts of
--help=target to list all devices were generated from avr-mmcus.
That code rot is also cleaned up.  Moreover, the structure now allows
for simpler addition of new multilib options which are likely to come
in the near future.

The result of -print-multi-lib is:

.;
avr25;@mmcu=avr25
avr3;@mmcu=avr3
avr31;@mmcu=avr31
avr35;@mmcu=avr35
avr4;@mmcu=avr4
avr5;@mmcu=avr5
avr51;@mmcu=avr51
avr6;@mmcu=avr6
avrxmega2;@mmcu=avrxmega2
avrxmega4;@mmcu=avrxmega4
avrxmega5;@mmcu=avrxmega5
avrxmega6;@mmcu=avrxmega6
avrxmega7;@mmcu=avrxmega7
avrtiny;@mmcu=avrtiny
tiny-stack;@msp8
avr25/tiny-stack;@mmcu=avr25@msp8

hence unchanged.

Ok for trunk?

Johann


* config/avr/t-avr (AWK) [t-multilib]: Remove "-v FORMAT=Makefile"
command option from $(AWK) call.
* config/avr/genmultilib.awk: Simplify and rewrite so that it
generates MULTILIB_REQUIRED instead of MULTILIB_EXCEPTIONS.
[FORMAT]: Remove handling of variable.
* config/avr/t-multilib: Regenerate.
Index: config/avr/t-avr
===
--- config/avr/t-avr	(revision 247631)
+++ config/avr/t-avr	(working copy)
@@ -89,14 +89,13 @@ install-device-specs: s-device-specs ins
 		$(INSTALL_DATA) $${file} $(DESTDIR)$(libsubdir)/$${file}; \
 	done
 
-# Map -mmcu= to the right multilib variant
+# Get multilib layout
 # MULTILIB_OPTIONS
 # MULTILIB_DIRNAMES
-# MULTILIB_EXCEPTIONS
-# MULTILIB_MATCHES
+# MULTILIB_REQUIRED
 
 s-mlib: $(srcdir)/config/avr/t-multilib
 
 $(srcdir)/config/avr/t-multilib: $(srcdir)/config/avr/genmultilib.awk \
  $(AVR_MCUS)
-	$(AWK) -f $< -v FORMAT=Makefile   $< $(AVR_MCUS) > $@
+	$(AWK) -f $< $< $(AVR_MCUS) > $@
Index: config/avr/genmultilib.awk
===
--- config/avr/genmultilib.awk	(revision 247631)
+++ config/avr/genmultilib.awk	(working copy)
@@ -22,23 +22,28 @@
 # Representation that is understood by GCC's multilib Machinery.
 #
 # The Script works as a Filter from STDIN to STDOUT.
-# 
-# FORMAT = "Makefile": Generate Makefile Snipet that sets some
-#  MULTILIB_* Variables as needed.
+# It generates a Makefile Snipet that sets some
+# MULTILIB_* Variables as needed.
 #
 ##
 
 BEGIN {
 FS ="[(, \t]+"
 option[""] = ""
-tiny_stack[""] = 1
 comment = 1
-n_mcu = 0
-n_cores = 0
 
-mtiny[0] = ""
-mtiny[1] = "tiny-stack"
-option["tiny-stack"] = "msp8"
+dir_tiny = "tiny-stack"
+opt_tiny = "msp8"
+
+#awk Variable Makefile Variable  
+#  --
+#m_options <->MULTILIB_OPTIONS
+#m_dirnames<->MULTILIB_DIRNAMES
+#m_required<->MULTILIB_REQUIRED
+m_sep = ""
+m_options= "\nMULTILIB_OPTIONS = "
+m_dirnames   = "\nMULTILIB_DIRNAMES ="
+m_required   = "\nMULTILIB_REQUIRED ="
 }
 
 ##
@@ -51,14 +56,11 @@ BEGIN {
 	next
 else if (comment == 1)
 {
-	if (FORMAT == "Makefile")
-	{
-	print "# Auto-generated Makefile Snip"
-	print "# Generated by: ./gcc/config/avr/genmultilib.awk"
-	print "# Generated from  : ./gcc/config/avr/avr-mcus.def"
-	print "# Used by : tmake_file from Makefile and genmultilib"
-	print ""
-	}
+	print "# Auto-generated Makefile Snip"
+	print "# Generated by: ./gcc/config/avr/genmultilib.awk"
+	print "# Generated from  : ./gcc/config/avr/avr-mcus.def"
+	print "# Used by : tmake_file from Makefile and genmultilib"
+	print ""
 }
 
 comment = 2;
@@ -74,12 +76,10 @@ BEGIN {
 }
 
 ##
-# Run over all AVR_MCU Lines and gather Information:
-# cores[] : Enumerates the Cores (avr2, avr25, ...)
-# mcu[]   : Enumerates the Devices
-# tiny_stack[]: Maps Core/Device to 0 (2-byte SP) or 1 (1-byte SP)
-# option[]: Maps Core/Device to the mmcu= option to get it
-# toCore[]: Maps Device to its Core
+# Run over all AVR_MCU Lines.  If we encounter a required multilib
+# variant, add according combination of options to m_required,
+# but onyl once.  Add encountered cores to m_dirnames and
+# according -mmcu= options to m_options.
 ##
 
 /^AVR_MCU/ {
@@ -94,11 +94,12 @@ BEGIN {
 	if (core == "avr1")
 	next
 
-	cores[n_cores] = core
-	n_cores++
-	tiny_stack[core] = 0
 	option[core] = "mmcu=" core
 
+	m_options  = m_options m_sep option[core]
+	m_dirnames = m_dirnames " " core
+	m_sep = "/"
+
 	next
 }
 
@@ -109,113 +110,37 @@ BEGIN {
 # split device 

[C++ PATCH] make eh fn nodes global trees

2017-05-22 Thread Nathan Sidwell
This patch neatens up the recent change in except.c to register GTY 
roots.  I've made them all global trees.


Whilst there I noticed except's declare_library_fn could be doing more 
work, rather than its callers repeat themselves.  Also renamed a couple 
of global trees to be more mnemonic and consistent with these names.


nathan
--
Nathan Sidwell
2017-05-22  Nathan Sidwell  

	* cp-tree.h (CPTI_TERMINATE, CPTI_CALL_UNEXPECTED): Rename to ...
	(CPTI_TERMINATE_FN, CPTI_CALL_UNEXPECTED_FN): ... here.
	( CPTI_GET_EXCEPTION_PTR_FN, CPTI_BEGIN_CATCH_FN, CPTI_END_CATCH_FN,
	CPTI_ALLOCATE_EXCEPTION_FN, CPTI_FREE_EXCEPTION_FN, CPTI_THROW_FN,
	CPTI_RETHROW_FN): New.
	(noexcept_deferred_spec): New.
	(terminate_node, call_unexpected_node): Rename to ...
	(terminate_fn, call_unexpected_fn): ... here.
	(get_exception_ptr_fn, begin_catch_fn, end_catch_fn,
	allocate_exception_fn, free_exception_fn, throw_fn, rethrow_fn): New.
	* except.c (fn1..fn5, throw_fn, rethrow_rn, spec): Delete.
	(init_exception_processing): Adjust.
	(declare_library_fn): Create and push the fns here.
	(do_get_exception_ptr, do_begin_catch, do_end_catch,
	do_allocate_exception_ptr, do_free_exception_ptr): Adjust
	declare_library_fn use.
	(unevaluated_noexcept_spec): Adjust.
	* cp-gimplify.c (genericize_eh_spec_block,
	gimplify_most_not_throw_expr): Adjust.

Index: cp-gimplify.c
===
--- cp-gimplify.c	(revision 248326)
+++ cp-gimplify.c	(working copy)
@@ -150,7 +150,7 @@ genericize_eh_spec_block (tree *stmt_p)
 {
   tree body = EH_SPEC_STMTS (*stmt_p);
   tree allowed = EH_SPEC_RAISES (*stmt_p);
-  tree failure = build_call_n (call_unexpected_node, 1, build_exc_ptr ());
+  tree failure = build_call_n (call_unexpected_fn, 1, build_exc_ptr ());
 
   *stmt_p = build_gimple_eh_filter_tree (body, allowed, failure);
   TREE_NO_WARNING (*stmt_p) = true;
@@ -501,7 +501,7 @@ gimplify_must_not_throw_expr (tree *expr
   gimple *mnt;
 
   gimplify_and_add (body, _);
-  mnt = gimple_build_eh_must_not_throw (terminate_node);
+  mnt = gimple_build_eh_must_not_throw (terminate_fn);
   gimple_seq_add_stmt_without_update (_, mnt);
   mnt = gimple_build_try (try_, catch_, GIMPLE_TRY_CATCH);
 
Index: cp-tree.h
===
--- cp-tree.h	(revision 248326)
+++ cp-tree.h	(working copy)
@@ -153,8 +153,17 @@ enum cp_tree_index
 CPTI_EMPTY_EXCEPT_SPEC,
 CPTI_NOEXCEPT_TRUE_SPEC,
 CPTI_NOEXCEPT_FALSE_SPEC,
-CPTI_TERMINATE,
-CPTI_CALL_UNEXPECTED,
+CPTI_NOEXCEPT_DEFERRED_SPEC,
+
+CPTI_TERMINATE_FN,
+CPTI_CALL_UNEXPECTED_FN,
+CPTI_GET_EXCEPTION_PTR_FN,
+CPTI_BEGIN_CATCH_FN,
+CPTI_END_CATCH_FN,
+CPTI_ALLOCATE_EXCEPTION_FN,
+CPTI_FREE_EXCEPTION_FN,
+CPTI_THROW_FN,
+CPTI_RETHROW_FN,
 CPTI_ATEXIT_FN_PTR_TYPE,
 CPTI_ATEXIT,
 CPTI_DSO_HANDLE,
@@ -242,17 +251,24 @@ extern GTY(()) tree cp_global_trees[CPTI
 #define lang_name_c			cp_global_trees[CPTI_LANG_NAME_C]
 #define lang_name_cplusplus		cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS]
 
-/* Exception specifiers used for throw(), noexcept(true) and
-   noexcept(false).  We rely on these being uncloned.  */
+/* Exception specifiers used for throw(), noexcept(true),
+   noexcept(false) and deferred noexcept.  We rely on these being
+   uncloned.  */
 #define empty_except_spec		cp_global_trees[CPTI_EMPTY_EXCEPT_SPEC]
 #define noexcept_true_spec		cp_global_trees[CPTI_NOEXCEPT_TRUE_SPEC]
 #define noexcept_false_spec		cp_global_trees[CPTI_NOEXCEPT_FALSE_SPEC]
+#define noexcept_deferred_spec		cp_global_trees[CPTI_NOEXCEPT_DEFERRED_SPEC]
 
-/* The declaration for `std::terminate'.  */
-#define terminate_node			cp_global_trees[CPTI_TERMINATE]
-
-/* The declaration for "__cxa_call_unexpected".  */
-#define call_unexpected_node		cp_global_trees[CPTI_CALL_UNEXPECTED]
+/* Exception handling function declarations.  */
+#define terminate_fn			cp_global_trees[CPTI_TERMINATE_FN]
+#define call_unexpected_fn		cp_global_trees[CPTI_CALL_UNEXPECTED_FN]
+#define get_exception_ptr_fn		cp_global_trees[CPTI_GET_EXCEPTION_PTR_FN]
+#define begin_catch_fn			cp_global_trees[CPTI_BEGIN_CATCH_FN]
+#define end_catch_fn			cp_global_trees[CPTI_END_CATCH_FN]
+#define allocate_exception_fn		cp_global_trees[CPTI_ALLOCATE_EXCEPTION_FN]
+#define free_exception_fn		cp_global_trees[CPTI_FREE_EXCEPTION_FN]
+#define throw_fn			cp_global_trees[CPTI_THROW_FN]
+#define rethrow_fn			cp_global_trees[CPTI_RETHROW_FN]
 
 /* The type of the function-pointer argument to "__cxa_atexit" (or
"std::atexit", if "__cxa_atexit" is not being used).  */
Index: except.c
===
--- except.c	(revision 248326)
+++ except.c	(working copy)
@@ -42,15 +42,6 @@ static int complete_ptr_ref_or_void_ptr_
 static bool is_admissible_throw_operand_or_catch_parameter (tree, bool);
 static int can_convert_eh (tree, tree);
 
-static GTY(()) tree 

[C++ PATCH] namespace pushing/popping

2017-05-22 Thread Nathan Sidwell
name-lookup.c is somewhat messy in which functions are external 
interfaces and which are internal workers.  One impact is the 
conditional timekeeping code.


In an attempt to clean that up, I'm trying to move the external 
interfaces to the end of the file and consistently name worker functions 
do_FOO.


This cleans up the namespace pushing and popping.  Here we had a popping 
worker function but no matching pushing worker.


nathan
--
Nathan Sidwell
2017-05-22  Nathan Sidwell  

	* name-lookup.c (pushdecl_top_level,
	pushdecl_top_level_and_finish): Move after namespace pushing and
	popping functions.
	(push_to_top_level): Rename to ...
	(do_push_to_top_level): ... here.  Remove timing code.
	(pop_from_top_level_1): Rename to ...
	(do_pop_from_top_level): ... here.
	(do_push_nested_namespace, do_pop_nested_namespace)
	(push_to_top_level): New wrapper for do_push_to_top_level.
	(pop_from_top_level): Adjust.
	(push_nested_namepace, pop_nested_namespace): Wrappers for workers.

Index: name-lookup.c
===
--- name-lookup.c	(revision 248326)
+++ name-lookup.c	(working copy)
@@ -4491,32 +4491,6 @@ parse_using_directive (tree name_space,
 }
 }
 
-/* Pushes X into the global namespace.  */
-
-tree
-pushdecl_top_level (tree x, bool is_friend)
-{
-  bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  push_to_top_level ();
-  x = pushdecl_namespace_level (x, is_friend);
-  pop_from_top_level ();
-  timevar_cond_stop (TV_NAME_LOOKUP, subtime);
-  return x;
-}
-
-/* Pushes X into the global namespace and Calls cp_finish_decl to
-   register the variable, initializing it with INIT.  */
-
-tree
-pushdecl_top_level_and_finish (tree x, tree init)
-{
-  push_to_top_level ();
-  x = pushdecl_namespace_level (x, false);
-  cp_finish_decl (x, init, false, NULL_TREE, 0);
-  pop_from_top_level ();
-  return x;
-}
-
 /* Combines two sets of overloaded functions into an OVERLOAD chain, removing
duplicates.  The first list becomes the tail of the result.
 
@@ -6232,8 +6206,8 @@ store_class_bindings (vec

Drop self_time from inline_summary

2017-05-22 Thread Jan Hubicka
Hi,
self_time is currently write only and there is quite good reason for it (one
should not care about running time of unoptimized body without context at all).

Bootstrapped/regtested x86_64-linux, comitted.

Honza

* ipa-inline-analysis.c (inline_summary::reset): Do not reset
self_time.
(dump_inline_summary): Do not print self_time.
(estimate_function_body_sizes): Do not set self_time.
(compute_inline_parameters): Likewise.
(inline_read_section, inline_write_summary): Do not stream self_time.
* ipa-inline.h (inline_summary): Drop self_time.
Index: ipa-inline-analysis.c
===
--- ipa-inline-analysis.c   (revision 248322)
+++ ipa-inline-analysis.c   (working copy)
@@ -560,7 +560,6 @@ inline_summary::reset (struct cgraph_nod
   struct cgraph_edge *e;
 
   self_size = 0;
-  self_time = 0;
   estimated_stack_size = 0;
   estimated_self_stack_size = 0;
   stack_frame_offset = 0;
@@ -920,8 +919,7 @@ dump_inline_summary (FILE *f, struct cgr
fprintf (f, " contains_cilk_spawn");
   if (s->fp_expressions)
fprintf (f, " fp_expression");
-  fprintf (f, "\n  self time:   %f\n", s->self_time.to_double ());
-  fprintf (f, "  global time: %f\n", s->time.to_double ());
+  fprintf (f, "\n  global time: %f\n", s->time.to_double ());
   fprintf (f, "  self size:   %i\n", s->self_size);
   fprintf (f, "  global size: %i\n", s->size);
   fprintf (f, "  min size:   %i\n", s->min_size);
@@ -2415,7 +2413,7 @@ estimate_function_body_sizes (struct cgr
  e->aux = NULL;
}
 }
-  inline_summaries->get (node)->self_time = time;
+  inline_summaries->get (node)->time = time;
   inline_summaries->get (node)->self_size = size;
   nonconstant_names.release ();
   ipa_release_body_info ();
@@ -2472,7 +2470,6 @@ compute_inline_parameters (struct cgraph
   info->account_size_time (2 * INLINE_SIZE_SCALE, 0, t, t);
   inline_update_overall_summary (node);
   info->self_size = info->size;
-  info->self_time = info->time;
   /* We can not inline instrumentation clones.  */
   if (node->thunk.add_pointer_bounds_args)
{
@@ -2539,7 +2536,6 @@ compute_inline_parameters (struct cgraph
   node->calls_comdat_local = (e != NULL);
 
   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
-  info->time = info->self_time;
   info->size = info->self_size;
   info->stack_frame_offset = 0;
   info->estimated_stack_size = info->estimated_self_stack_size;
@@ -2548,8 +2544,7 @@ compute_inline_parameters (struct cgraph
  inline_update_overall_summary but because computation happens in
  different order the roundoff errors result in slight changes.  */
   inline_update_overall_summary (node);
-  gcc_assert (!(info->time - info->self_time).to_int ()
- && info->size == info->self_size);
+  gcc_assert (info->size == info->self_size);
 }
 
 
@@ -3695,7 +3690,7 @@ inline_read_section (struct lto_file_dec
   info->estimated_stack_size
= info->estimated_self_stack_size = streamer_read_uhwi ();
   info->size = info->self_size = streamer_read_uhwi ();
-  info->time = info->self_time = sreal::stream_in ();
+  info->time = sreal::stream_in ();
 
   bp = streamer_read_bitpack ();
   info->inlinable = bp_unpack_value (, 1);
@@ -3848,7 +3843,7 @@ inline_write_summary (void)
  streamer_write_uhwi (ob, lto_symtab_encoder_encode (encoder, cnode));
  streamer_write_hwi (ob, info->estimated_self_stack_size);
  streamer_write_hwi (ob, info->self_size);
- info->self_time.stream_out (ob);
+ info->time.stream_out (ob);
  bp = bitpack_create (ob->main_stream);
  bp_pack_value (, info->inlinable, 1);
  bp_pack_value (, info->contains_cilk_spawn, 1);
Index: ipa-inline.h
===
--- ipa-inline.h(revision 248322)
+++ ipa-inline.h(working copy)
@@ -96,8 +96,6 @@ struct GTY(()) inline_summary
   HOST_WIDE_INT estimated_self_stack_size;
   /* Size of the function body.  */
   int self_size;
-  /* Time of the function body.  */
-  sreal GTY((skip)) self_time;
   /* Minimal size increase after inlining.  */
   int min_size;
 
@@ -149,7 +147,7 @@ struct GTY(()) inline_summary
   /* Keep all field empty so summary dumping works during its computation.
  This is useful for debugging.  */
   inline_summary ()
-: estimated_self_stack_size (0), self_size (0), self_time (0), min_size 
(0),
+: estimated_self_stack_size (0), self_size (0), min_size (0),
   inlinable (false), contains_cilk_spawn (false), single_caller (false),
   fp_expressions (false), estimated_stack_size (false),
   stack_frame_offset (false), time (0), size (0), conds (NULL),


Re: [PATCH] Avoid signed overflow in num_get::_M_extract_int (PR libstdc++/67214)

2017-05-22 Thread Jonathan Wakely

On 20/05/17 15:10 +0800, Xi Ruoyao wrote:

On 2017-05-19 15:38 +0100, Jonathan Wakely wrote:

On 18/05/17 19:10 +0800, Xi Ruoyao wrote:
> This UB has been hiding so long...

Indeed! Thanks for the patch.

> 2017-03-11  Xi Ruoyao  
>
>PR libstdc++/67214
>* include/bits/locale_facets.tcc (_M_extract_int):
>  Add explicit conversion to avoid signed overflow.
> ---
>  libstdc++-v3/include/bits/locale_facets.tcc | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/bits/locale_facets.tcc 
b/libstdc++-v3/include/bits/locale_facets.tcc
> index 351190c..5f85d15 100644
> --- a/libstdc++-v3/include/bits/locale_facets.tcc
> +++ b/libstdc++-v3/include/bits/locale_facets.tcc
> @@ -470,7 +470,8 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL
>    bool __testoverflow = false;
>    const __unsigned_type __max =
>      (__negative && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
> -    ? -__gnu_cxx::__numeric_traits<_ValueT>::__min
> +    ? -static_cast<__unsigned_type>(__gnu_cxx::
> +   __numeric_traits<_ValueT>::__min)

Do we need to keep the negation, or can we just cast to
__unsigned_type?


For 2's complement we can just cast to __unsigned_type.  But for
clarity and other strange architectures I think we should keep
the negation.


https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
"GCC only supports two's complement integer types"

I doubt that's ever going to change, but keeping the negation also
doesn't do any harm. I'll test and commit this, thanks.




[Ada] Fix ICE on subprogram defined with null exclusion

2017-05-22 Thread Eric Botcazou
It's a regression present on the mainline and 7 branch: the compiler aborts on 
a package containing a declaration of a subprogram taking an access parameter 
with null exclusion and a reference to the Access attribute applied to this 
subprogram.

Tested on x86_64-suse-linux, applied on the mainline and 7 branch.


2017-05-22  Eric Botcazou  

* gcc-interface/decl.c (gnat_to_gnu_entity): Skip regular processing
for Itypes that are E_Access_Subtype.
: Use the DECL of the base type directly.


2017-05-22  Pierre-Marie de Rodat  

* gnat.dg/specs/not_null1.ads: New test.

-- 
Eric Botcazou-- { dg-do compile }

package Not_Null1 is
   type T is null record;
   type T_Access is access all T;

   procedure Proc (This : in not null T_Access) is null;

   type Proc_Access is access procedure (This : in not null T_Access);
   PA : Proc_Access := Proc'Access;
end Not_Null1;
Index: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 248321)
+++ gcc-interface/decl.c	(working copy)
@@ -310,11 +310,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
   /* Contains the list of attributes directly attached to the entity.  */
   struct attrib *attr_list = NULL;
 
-  /* Since a use of an Itype is a definition, process it as such if it
- is not in a with'ed unit.  */
+  /* Since a use of an Itype is a definition, process it as such if it is in
+ the main unit, except for E_Access_Subtype because it's actually a use
+ of its base type, see below.  */
   if (!definition
   && is_type
   && Is_Itype (gnat_entity)
+  && Ekind (gnat_entity) != E_Access_Subtype
   && !present_gnu_tree (gnat_entity)
   && In_Extended_Main_Code_Unit (gnat_entity))
 {
@@ -3823,7 +3825,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 case E_Access_Subtype:
   /* We treat this as identical to its base type; any constraint is
 	 meaningful only to the front-end.  */
-  gnu_type = gnat_to_gnu_type (Etype (gnat_entity));
+  gnu_decl = gnat_to_gnu_entity (Etype (gnat_entity), NULL_TREE, false);
+  saved = true;
 
   /* The designated subtype must be elaborated as well, if it does
 	 not have its own freeze node.  But designated subtypes created
@@ -3855,8 +3858,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	gnat_to_gnu_entity (Directly_Designated_Type (gnat_entity),
 NULL_TREE, false);
 	}
-
-  maybe_present = true;
   break;
 
 /* Subprogram Entities


More of ipa-inline-analysis cleanups

2017-05-22 Thread Jan Hubicka
Hi,
this is rather boring patch to turn some of inline summary manipulatotions
into member functions.  More work is needed on this.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

* ipa-inline-analysis.c (account_size_time): Rename to ...
(inline_summary::account_size_time): ... this one.
(reset_ipa_call_summary): Turn to ...
(ipa_call_summary::reset): ... this one.
(reset_inline_summary): Turn to ...
(inline_summary::reset): ... this one.
(inline_summary_t::remove): Update.
(inline_summary_t::duplicate): Update.
(ipa_call_summary_t::remove): Update.
(dump_inline_summary): Update.
(estimate_function_body_sizes): Update.
(compute_inline_parameters): Update.
(estimate_node_size_and_time): Update.
(inline_merge_summary): Update.
(inline_update_overall_summary): Update.
(inline_read_section): Update.
(inline_write_summary): Update.
* ipa-inline.h (inline_summary): Rename entry to size_time_table;
add account_size_time and reset member functions.
(ipa_call_summary): Add reset function.
* ipa-predicate.h (predicate::operator &): Constify.
Index: ipa-inline-analysis.c
===
--- ipa-inline-analysis.c   (revision 248287)
+++ ipa-inline-analysis.c   (working copy)
@@ -158,33 +158,33 @@ dump_inline_hints (FILE *f, inline_hints
When NONCONST_PRED is false the code will evaulate to constant and
will get optimized out in specialized clones of the function.   */
 
-static void
-account_size_time (struct inline_summary *summary, int size, sreal time,
-  predicate *exec_pred,
-  predicate *nonconst_pred_ptr)
+void
+inline_summary::account_size_time (int size, sreal time,
+  const predicate _pred,
+  const predicate _pred_in)
 {
   size_time_entry *e;
   bool found = false;
   int i;
   predicate nonconst_pred;
 
-  if (*exec_pred == false)
+  if (exec_pred == false)
 return;
 
-  nonconst_pred = *nonconst_pred_ptr & *exec_pred;
+  nonconst_pred = nonconst_pred_in & exec_pred;
 
   if (nonconst_pred == false)
 return;
 
   /* We need to create initial empty unconitional clause, but otherwie
  we don't need to account empty times and sizes.  */
-  if (!size && time == 0 && summary->entry)
+  if (!size && time == 0 && size_time_table)
 return;
 
   gcc_assert (time >= 0);
 
-  for (i = 0; vec_safe_iterate (summary->entry, i, ); i++)
-if (e->exec_predicate == *exec_pred
+  for (i = 0; vec_safe_iterate (size_time_table, i, ); i++)
+if (e->exec_predicate == exec_pred
&& e->nonconst_predicate == nonconst_pred)
   {
found = true;
@@ -194,7 +194,7 @@ account_size_time (struct inline_summary
 {
   i = 0;
   found = true;
-  e = &(*summary->entry)[0];
+  e = &(*size_time_table)[0];
   if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file,
 "\t\tReached limit on number of entries, "
@@ -206,11 +206,11 @@ account_size_time (struct inline_summary
   "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:",
   ((double) size) / INLINE_SIZE_SCALE,
   (time.to_double ()), found ? "" : "new ");
-  exec_pred->dump (dump_file, summary->conds, 0);
-  if (*exec_pred != nonconst_pred)
+  exec_pred.dump (dump_file, conds, 0);
+  if (exec_pred != nonconst_pred)
{
   fprintf (dump_file, " nonconst:");
-  nonconst_pred.dump (dump_file, summary->conds);
+  nonconst_pred.dump (dump_file, conds);
}
   else
 fprintf (dump_file, "\n");
@@ -220,9 +220,9 @@ account_size_time (struct inline_summary
   struct size_time_entry new_entry;
   new_entry.size = size;
   new_entry.time = time;
-  new_entry.exec_predicate = *exec_pred;
+  new_entry.exec_predicate = exec_pred;
   new_entry.nonconst_predicate = nonconst_pred;
-  vec_safe_push (summary->entry, new_entry);
+  vec_safe_push (size_time_table, new_entry);
 }
   else
 {
@@ -541,58 +541,55 @@ inline_summary_alloc (void)
 /* We are called multiple time for given function; clear
data from previous run so they are not cumulated.  */
 
-static void
-reset_ipa_call_summary (struct cgraph_edge *e)
+void
+ipa_call_summary::reset ()
 {
-  struct ipa_call_summary *es = ipa_call_summaries->get (e);
-
-  es->call_stmt_size = es->call_stmt_time = 0;
-  if (es->predicate)
-edge_predicate_pool.remove (es->predicate);
-  es->predicate = NULL;
-  es->param.release ();
+  call_stmt_size = call_stmt_time = 0;
+  if (predicate)
+edge_predicate_pool.remove (predicate);
+  predicate = NULL;
+  param.release ();
 }
 
 /* We are called multiple time for given function; clear
data from previous run so they are not cumulated.  

[Ada] Remove restriction on inlining in related units

2017-05-22 Thread Eric Botcazou
This change makes it possible for the compiler to inline into a child package
a subprogram declared in a parent package, even if the parent package has a
with clause for the child package in the body.  It also fixes segfaults that
can occur when inlining into a package a subprogram coming from an unrelated
package containing a Taft Amendment type that closes a dependency cycle with
at least one member type declared in the first package.

The following code must compile quietly with -O -gnatn -Winline:

package Buf.Support is
  type Sup_T is new Integer;
  procedure Doit (Obj : T);
end Buf.Support;

package body Buf.Support is
  procedure Doit (Obj : T) is
  begin
if Buf.Get_Support (Obj) > 100 then
  raise Program_Error;
end if;
  end Doit;
end Buf.Support;

limited with Buf.Support;

package Buf is
  type T is limited private;
  function Get_Support (Obj : T) return Buf.Support.Sup_T with Inline;
private
  type T is new Integer;
end Buf;

with Buf.Support;

package body Buf is
  function Get_Support (Obj : T) return Buf.Support.Sup_T is
  begin
return Buf.Support.Sup_T (Obj + 1);
  end Get_Support;
end Buf;

Tested on x86_64-suse-linux, applied on the mainline.


2017-05-22  Ed Schonberg  
Eric Botcazou  

* sem_ch4.adb (Analyze_Call): In Ada2012 an incomplete type from a
limited view may appear in the profile of a function, and a call to
that function in another unit in which the full view is available must
use this full view to spurious type errors at the point of call.
* inline.adb (Analyze_Inlined_Bodies): Remove restriction on loading
of parent body with a with clause for the main unit.
* gcc-interface/decl.c (defer_limited_with_list): Document new usage.
(gnat_to_gnu_entity) : Handle completed Taft Amendment
types declared in external units like types from limited with clauses.
Adjust final processing of defer_limited_with_list accordingly.
* gcc-interface/trans.c (gnat_to_gnu) < N_Selected_Component>: Try
again to translate the prefix after the field if it is incomplete.


2017-05-22  Eric Botcazou  

* gnat.dg/limited_with5.ad[sb]: New test.
* gnat.dg/limited_with5_pkg.ad[sb]: New helper.
* gnat.dg/limited_with6.ad[sb]: New test.
* gnat.dg/limited_with6_pkg.ad[sb]: New helper.

-- 
Eric BotcazouIndex: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 248320)
+++ gcc-interface/decl.c	(working copy)
@@ -101,8 +101,8 @@ struct incomplete
 static int defer_incomplete_level = 0;
 static struct incomplete *defer_incomplete_list;
 
-/* This variable is used to delay expanding From_Limited_With types until the
-   end of the spec.  */
+/* This variable is used to delay expanding types coming from a limited with
+   clause and completed Taft Amendment types until the end of the spec.  */
 static struct incomplete *defer_limited_with_list;
 
 typedef struct subst_pair_d {
@@ -3580,6 +3580,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	const bool is_from_limited_with
 	  = (IN (Ekind (gnat_desig_equiv), Incomplete_Kind)
 	 && From_Limited_With (gnat_desig_equiv));
+	/* Whether it is a completed Taft Amendment type.  Such a type is to
+	   be treated as coming from a limited with clause if it is not in
+	   the main unit, i.e. we break potential circularities here in case
+	   the body of an external unit is loaded for inter-unit inlining.  */
+const bool is_completed_taft_type
+	  = (IN (Ekind (gnat_desig_equiv), Incomplete_Kind)
+	 && Has_Completion_In_Body (gnat_desig_equiv)
+	 && Present (Full_View (gnat_desig_equiv)));
 	/* The "full view" of the designated type.  If this is an incomplete
 	   entity from a limited with, treat its non-limited view as the full
 	   view.  Otherwise, if this is an incomplete or private type, use the
@@ -3646,13 +3654,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 
 	/* Get the type of the thing we are to point to and build a pointer to
 	   it.  If it is a reference to an incomplete or private type with a
-	   full view that is a record or an array, make a dummy type node and
-	   get the actual type later when we have verified it is safe.  */
+	   full view that is a record, an array or an access, make a dummy type
+	   and get the actual type later when we have verified it is safe.  */
 	else if ((!in_main_unit
 		  && !present_gnu_tree (gnat_desig_equiv)
 		  && Present (gnat_desig_full)
 		  && (Is_Record_Type (gnat_desig_full)
-		  || Is_Array_Type (gnat_desig_full)))
+		  || Is_Array_Type (gnat_desig_full)
+		  || Is_Access_Type (gnat_desig_full)))
 		 /* Likewise if this is a reference to a record, an array or a
 		subprogram type and we are to defer elaborating incomplete
 		types.  We do this because this access type may be the 

Re: [PATCH, GCC/testsuite/ARM] Add MOVT testing for ARMv8-M Baseline

2017-05-22 Thread Kyrill Tkachov


On 22/05/17 08:48, Thomas Preudhomme wrote:

Ping?

Best regards,

Thomas

On 11/05/17 16:13, Thomas Preudhomme wrote:

Hi,

When ARMv8-M Baseline support was introduced no testcase was added for
support of the MOVT instruction because GCC would always prefer a load
from literal pool. With the recent work to fix -mslow-flash-data by
Andre Simoes Dias Vieira and Prakhar Bahuguna it is now possible to
test that support.

This commit adds a test for MOVT based on the MOVW test by using
-mslow-flash-data to ensure that GCC does not do a literal load of the
immediate. As such, this test is restricted to Cortex-M devices (where
-mslow-flash-data is available) with MOVT instruction.

ChangeLog entry is as follows:

*** gcc/testsuite/ChangeLog ***

2017-05-2017  Thomas Preud'homme 

* gcc.target/arm/movsi_movt.c: New test.
* gcc.target/arm/movdi_movt.c: New test.

Testing: the new tests have been tested to pass for ARMv7-M and
ARMv8-M (Baseline and Mainline) on arm-none-eabi and armeb-none-eabi
targets.

Is this ok for trunk?



Ok.
Thanks,
Kyrill


Best regards,

Thomas




[Ada] Relax restrictions on volatile components

2017-05-22 Thread Eric Botcazou
GNAT has historically enforced strong restrictions on volatile components, but 
this is no basis for that in the RM.

Tested on x86_64-suse-linux, applied on the mainline.


2017-05-22  Eric Botcazou  

* gcc-interface/decl.c (gnat_to_gnu_field): Do not enforce strict
alignment for simple volatile fields and remove associated errors.


2017-05-22  Eric Botcazou  

* gnat.dg/specs/volatile1.ads: Remove obsolete errors.
* gnat.dg/specs/clause_on_volatile.ads: Likewise.

-- 
Eric BotcazouIndex: ada/gcc-interface/decl.c
===
--- ada/gcc-interface/decl.c	(revision 248140)
+++ ada/gcc-interface/decl.c	(working copy)
@@ -6783,19 +6783,24 @@ gnat_to_gnu_field (Entity_Id gnat_field,
 {
   const Entity_Id gnat_record_type = Underlying_Type (Scope (gnat_field));
   const Entity_Id gnat_field_type = Etype (gnat_field);
-  const bool is_aliased
-= Is_Aliased (gnat_field);
   const bool is_atomic
 = (Is_Atomic_Or_VFA (gnat_field) || Is_Atomic_Or_VFA (gnat_field_type));
+  const bool is_aliased = Is_Aliased (gnat_field);
   const bool is_independent
 = (Is_Independent (gnat_field) || Is_Independent (gnat_field_type));
   const bool is_volatile
 = (Treat_As_Volatile (gnat_field) || Treat_As_Volatile (gnat_field_type));
+  const bool is_strict_alignment = Strict_Alignment (gnat_field_type);
+  /* We used to consider that volatile fields also require strict alignment,
+ but that was an interpolation and would cause us to reject a pragma
+ volatile on a packed record type containing boolean components, while
+ there is no basis to do so in the RM.  In such cases, the writes will
+ involve load-modify-store sequences, but that's OK for volatile.  The
+ only constraint is the implementation advice whereby only the bits of
+ the components should be accessed if they both start and end on byte
+ boundaries, but that should be guaranteed by the GCC memory model.  */
   const bool needs_strict_alignment
-= (is_aliased
-   || is_independent
-   || is_volatile
-   || Strict_Alignment (gnat_field_type));
+= (is_atomic || is_aliased || is_independent || is_strict_alignment);
   tree gnu_field_type = gnat_to_gnu_type (gnat_field_type);
   tree gnu_field_id = get_entity_name (gnat_field);
   tree gnu_field, gnu_size, gnu_pos;
@@ -6917,9 +6922,7 @@ gnat_to_gnu_field (Entity_Id gnat_field,
 		s = "position of aliased field& must be multiple of ^ bits";
 	  else if (is_independent)
 		s = "position of independent field& must be multiple of ^ bits";
-	  else if (is_volatile)
-		s = "position of volatile field& must be multiple of ^ bits";
-	  else if (Strict_Alignment (gnat_field_type))
+	  else if (is_strict_alignment)
 		s = "position of & with aliased or tagged part must be"
 		" multiple of ^ bits";
 	  else
@@ -6947,9 +6950,7 @@ gnat_to_gnu_field (Entity_Id gnat_field,
 		s = "size of aliased field& must be ^ bits";
 		  else if (is_independent)
 		s = "size of independent field& must be at least ^ bits";
-		  else if (is_volatile)
-		s = "size of volatile field& must be at least ^ bits";
-		  else if (Strict_Alignment (gnat_field_type))
+		  else if (is_strict_alignment)
 		s = "size of & with aliased or tagged part must be"
 			" at least ^ bits";
 		  else
@@ -6969,10 +6970,7 @@ gnat_to_gnu_field (Entity_Id gnat_field,
 		  if (is_independent)
 		s = "size of independent field& must be multiple of"
 			" Storage_Unit";
-		  else if (is_volatile)
-		s = "size of volatile field& must be multiple of"
-			" Storage_Unit";
-		  else if (Strict_Alignment (gnat_field_type))
+		  else if (is_strict_alignment)
 		s = "size of & with aliased or tagged part must be"
 			" multiple of Storage_Unit";
 		  else
@@ -7079,9 +7077,9 @@ gnat_to_gnu_field (Entity_Id gnat_field,
   /* Now create the decl for the field.  */
   gnu_field
 = create_field_decl (gnu_field_id, gnu_field_type, gnu_record_type,
-			 gnu_size, gnu_pos, packed, Is_Aliased (gnat_field));
+			 gnu_size, gnu_pos, packed, is_aliased);
   Sloc_to_locus (Sloc (gnat_field), _SOURCE_LOCATION (gnu_field));
-  DECL_ALIASED_P (gnu_field) = Is_Aliased (gnat_field);
+  DECL_ALIASED_P (gnu_field) = is_aliased;
   TREE_SIDE_EFFECTS (gnu_field) = TREE_THIS_VOLATILE (gnu_field) = is_volatile;
 
   if (Ekind (gnat_field) == E_Discriminant)
Index: testsuite/gnat.dg/specs/clause_on_volatile.ads
===
--- testsuite/gnat.dg/specs/clause_on_volatile.ads	(revision 248140)
+++ testsuite/gnat.dg/specs/clause_on_volatile.ads	(working copy)
@@ -57,7 +57,7 @@ package Clause_On_Volatile is
   end record;
   For V1'Alignment use 4;
   for V1 use record
- VW at 0 range 0 .. 15; -- { dg-error "must be at least" }
+ VW at 0 range 0 .. 15;
   end record;
 
   type V2 is record
@@ -67,7 

Re: [PATCH, GCC/testsuite/ARM] Add MOVT testing for ARMv8-M Baseline

2017-05-22 Thread Thomas Preudhomme

Ping?

Best regards,

Thomas

On 11/05/17 16:13, Thomas Preudhomme wrote:

Hi,

When ARMv8-M Baseline support was introduced no testcase was added for
support of the MOVT instruction because GCC would always prefer a load
from literal pool. With the recent work to fix -mslow-flash-data by
Andre Simoes Dias Vieira and Prakhar Bahuguna it is now possible to
test that support.

This commit adds a test for MOVT based on the MOVW test by using
-mslow-flash-data to ensure that GCC does not do a literal load of the
immediate. As such, this test is restricted to Cortex-M devices (where
-mslow-flash-data is available) with MOVT instruction.

ChangeLog entry is as follows:

*** gcc/testsuite/ChangeLog ***

2017-05-2017  Thomas Preud'homme  

* gcc.target/arm/movsi_movt.c: New test.
* gcc.target/arm/movdi_movt.c: New test.

Testing: the new tests have been tested to pass for ARMv7-M and
ARMv8-M (Baseline and Mainline) on arm-none-eabi and armeb-none-eabi
targets.

Is this ok for trunk?

Best regards,

Thomas
diff --git a/gcc/testsuite/gcc.target/arm/movdi_movt.c b/gcc/testsuite/gcc.target/arm/movdi_movt.c
new file mode 100644
index ..e2a28ccbd994ed0e4d0b9ac432df32138820432c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/movdi_movt.c
@@ -0,0 +1,18 @@
+/* { dg-do compile { target { arm_cortex_m && { arm_thumb2_ok || arm_thumb1_movt_ok } } } } */
+/* { dg-options "-O2 -mslow-flash-data" } */
+
+unsigned long long
+movdi_1 (int a)
+{
+  return 0xF0F0LLU;
+}
+
+unsigned long long
+movdi_2 (int a)
+{
+  return 0xF0F0LLU;
+}
+
+/* Accept r1 because big endian targets put the low bits in the highest
+   numbered register of a pair.  */
+/* { dg-final { scan-assembler-times "movt\tr\[01\], 61680" 2 } } */
diff --git a/gcc/testsuite/gcc.target/arm/movsi_movt.c b/gcc/testsuite/gcc.target/arm/movsi_movt.c
new file mode 100644
index ..3cf46e2fd172ee1728b7b50c1cead90924962dca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/movsi_movt.c
@@ -0,0 +1,10 @@
+/* { dg-do compile { target { arm_cortex_m && { arm_thumb2_ok || arm_thumb1_movt_ok } } } } */
+/* { dg-options "-O2 -mslow-flash-data" } */
+
+unsigned
+movsi (void)
+{
+  return 0xF0F0U;
+}
+
+/* { dg-final { scan-assembler-times "movt\tr0, 61680" 1 } } */


Re: Move "(A & C) == D is false when D & ~C != 0" to match.pd

2017-05-22 Thread Richard Biener
On Sat, May 20, 2017 at 8:27 PM, Marc Glisse  wrote:
> Hello,
>
> as asked, I am adding some replacement in match.pd instead of just deleting
> this (redundant with CCP). It is not clear how general the match.pd version
> needs to be. (for instance it could handle some casts in addition to what I
> have written)
>
> The expansion results in a few non-canonical patterns (thus unreachable
> code), but avoiding them would make the code longer and less readable.
>
> I wondered about naming with_possible_nonzero_bits INTEGER_CST_or_SSA_NAME
> instead.
>
> I would like to rename get_nonzero_bits to get_possible_nonzero_bits or
> get_possibly_nonzero_bits, something more explicit, and introduce
> get_certain(ly)_nonzero_bits that would always return 0 for SSA_NAME for a
> start (but hopefully the next person who rewrites this stuff (merge CCP with
> VRP for instance?) will implement it). It would allow for more symmetry in
> the transformations and make the intent clearer.

I think get_nonzero_bits and its behavior is modeled after nonzero_bits on RTL.

> Bootstrap+testsuite on powerpc64le-unknown-linux-gnu.

Ok.

Thanks,
Richard.

> 2017-05-22  Marc Glisse  
>
> * fold-const.c (fold_binary_loc) [(A & C) == D]: Remove
> transformation.
> * match.pd (X == C): Rewrite it here.
> (with_possible_nonzero_bits, with_possible_nonzero_bits2,
> with_certain_nonzero_bits2): New predicates.
> * tree-ssanames.c (get_nonzero_bits): Handle INTEGER_CST.
>
> --
> Marc Glisse


Re: [PATCH] Try harder to fix recently introduced crashes in ggc_collect

2017-05-22 Thread Richard Biener
On Fri, May 19, 2017 at 7:41 PM, Dominique d'Humières
 wrote:
>
>> Le 19 mai 2017 à 19:26, Bernd Edlinger  a écrit :
>>
>> No, unfortunately it looks like incremental does not work in this case.
>>
>> You can try to remove gcc/s-gtyp-input, maybe it un-breaks your
>> build.  However, I gave up at that point and did a full bootstrap
>> instead.
>>
>> Bernd.
>
>
> Quite bad!-( bootstrap takes 2+ hours, incremental update for gfortran ~10 
> minutes.

in gcc/ do

./config.status --recheck



> Dominique
>
>
>
>


[Ada] Add check for sys/capability.h

2017-05-22 Thread Eric Botcazou
In preparation for an upcoming improvement.

Tested on x86_64-suse-linux, applied on the mainline.


2017-05-22  Eric Botcazou  

libada/
* configure.ac: Add check for sys/capability.h header.
(have_capability): New substitution.
* configure: Regenerate.
* Makefile.in (GNATLIBCFLAGS_FOR_C): Add @have_capability@.

-- 
Eric BotcazouIndex: Makefile.in
===
--- Makefile.in	(revision 248140)
+++ Makefile.in	(working copy)
@@ -61,7 +61,7 @@ PICFLAG = @PICFLAG@
 GNATLIBFLAGS= -W -Wall -gnatpg -nostdinc
 GNATLIBCFLAGS= -g -O2
 GNATLIBCFLAGS_FOR_C = -W -Wall $(GNATLIBCFLAGS) $(CFLAGS_FOR_TARGET) \
-	-fexceptions -DIN_RTS @have_getipinfo@
+	-fexceptions -DIN_RTS @have_getipinfo@ @have_capability@
 
 host_subdir = @host_subdir@
 GCC_DIR=$(MULTIBUILDTOP)../../$(host_subdir)/gcc
Index: configure.ac
===
--- configure.ac	(revision 248140)
+++ configure.ac	(working copy)
@@ -144,6 +144,10 @@ if test x$have_unwind_getipinfo = xyes;
 fi
 AC_SUBST(have_getipinfo)
 
+# Check for 
+AC_CHECK_HEADER([sys/capability.h], have_capability=-DHAVE_CAPABILITY, have_capability=)
+AC_SUBST(have_capability)
+
 # Determine what GCC version number to use in filesystem paths.
 GCC_BASE_VER
 


[PATCH] Speedup df_insn_refs_verify

2017-05-22 Thread Richard Biener

When not verifying we can actually short-circuit verifying the individual
chains.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2017-05-22  Richard Biener  

* df-scan.c (df_insn_refs_verify): Speedup when not verifying.

Index: gcc/df-scan.c
===
--- gcc/df-scan.c   (revision 248263)
+++ gcc/df-scan.c   (working copy)
@@ -4103,23 +4103,31 @@ df_insn_refs_verify (struct df_collectio
  rtx_insn *insn,
 bool abort_if_fail)
 {
-  bool ret1, ret2, ret3, ret4;
+  bool ret1, ret2, ret3;
   unsigned int uid = INSN_UID (insn);
   struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
 
   df_insn_refs_collect (collection_rec, bb, insn_info);
 
+  if (! df_mws_verify (_rec->mw_vec, DF_INSN_UID_MWS (uid),
+  abort_if_fail))
+return false;
+
   /* Unfortunately we cannot opt out early if one of these is not
- right because the marks will not get cleared.  */
+ right and abort_if_fail is set because the marks will not get cleared.  */
   ret1 = df_refs_verify (_rec->def_vec, DF_INSN_UID_DEFS (uid),
 abort_if_fail);
+  if (!ret1 && !abort_if_fail)
+return false;
   ret2 = df_refs_verify (_rec->use_vec, DF_INSN_UID_USES (uid),
 abort_if_fail);
+  if (!ret2 && !abort_if_fail)
+return false;
   ret3 = df_refs_verify (_rec->eq_use_vec, DF_INSN_UID_EQ_USES 
(uid),
 abort_if_fail);
-  ret4 = df_mws_verify (_rec->mw_vec, DF_INSN_UID_MWS (uid),
-  abort_if_fail);
-  return (ret1 && ret2 && ret3 && ret4);
+  if (!ret3 && !abort_if_fail)
+return false;
+  return (ret1 && ret2 && ret3);
 }
 
 


Re: [PATCH 4/4] Set function alignment for M7 to 8 bytes.

2017-05-22 Thread Eric Botcazou
> The gcc source tree is as desired, but I may have made
> 2 inadvertent process mistakes:
> * did not send a revised PATCH to gcc-patches

That's OK since only a minor correction was requested.

> * made the 4 changes with 1 commit

That's as expected.

-- 
Eric Botcazou