[PATCH] combine: Fix various shortcomings in make_more_copies (PR87701, PR87780)

2018-10-29 Thread Segher Boessenkool
This rewrites most of make_more_copies, in the process fixing a few PRs
and some other bugs, and working around a few target problems.  Certain
notes turn out to actually change the meaning of the RTL, so we cannot
drop them; and i386 takes subregs of hard regs.

Committing.


Segher


2018-10-29  Segher Boessenkool  

PR rtl-optimization/87701
PR rtl-optimization/87780
* combine.c (make_more_copies): Rewrite.

---
 gcc/combine.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/gcc/combine.c b/gcc/combine.c
index bd593bdc..dfb0b44 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -14990,25 +14990,20 @@ make_more_copies (void)
  rtx set = single_set (insn);
  if (!set)
continue;
- rtx src = SET_SRC (set);
  rtx dest = SET_DEST (set);
  if (dest == pc_rtx)
continue;
- if (GET_CODE (src) == SUBREG)
-   src = SUBREG_REG (src);
+ rtx src = SET_SRC (set);
  if (!(REG_P (src) && HARD_REGISTER_P (src)))
continue;
  if (TEST_HARD_REG_BIT (fixed_reg_set, REGNO (src)))
continue;
 
  rtx new_reg = gen_reg_rtx (GET_MODE (dest));
- rtx_insn *insn1 = gen_move_insn (new_reg, src);
- rtx_insn *insn2 = gen_move_insn (dest, new_reg);
- emit_insn_after (insn1, insn);
- emit_insn_after (insn2, insn1);
- delete_insn (insn);
-
- insn = insn2;
+ rtx_insn *new_insn = gen_move_insn (new_reg, src);
+ SET_SRC (set) = new_reg;
+ emit_insn_before (new_insn, insn);
+ df_insn_rescan (insn);
}
 }
 }
-- 
1.8.3.1



Re: [PATCH] combine: Fix various shortcomings in make_more_copies (PR87701, PR87780)

2018-10-29 Thread Andrew Pinski
On Mon, Oct 29, 2018 at 12:29 AM Segher Boessenkool
 wrote:
>
> This rewrites most of make_more_copies, in the process fixing a few PRs
> and some other bugs, and working around a few target problems.  Certain
> notes turn out to actually change the meaning of the RTL, so we cannot
> drop them; and i386 takes subregs of hard regs.
>
> Committing.
Only one comment about the changelog.

>
>
> Segher
>
>
> 2018-10-29  Segher Boessenkool  
>
> PR rtl-optimization/87701
> PR rtl-optimization/87780
> * combine.c (make_more_copies): Rewrite.

I think a better changelog would be :):
* combine.c (make_more_copies): Rewrite to be simplier.

Thanks,
Andrew

>
> ---
>  gcc/combine.c | 15 +--
>  1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/combine.c b/gcc/combine.c
> index bd593bdc..dfb0b44 100644
> --- a/gcc/combine.c
> +++ b/gcc/combine.c
> @@ -14990,25 +14990,20 @@ make_more_copies (void)
>   rtx set = single_set (insn);
>   if (!set)
> continue;
> - rtx src = SET_SRC (set);
>   rtx dest = SET_DEST (set);
>   if (dest == pc_rtx)
> continue;
> - if (GET_CODE (src) == SUBREG)
> -   src = SUBREG_REG (src);
> + rtx src = SET_SRC (set);
>   if (!(REG_P (src) && HARD_REGISTER_P (src)))
> continue;
>   if (TEST_HARD_REG_BIT (fixed_reg_set, REGNO (src)))
> continue;
>
>   rtx new_reg = gen_reg_rtx (GET_MODE (dest));
> - rtx_insn *insn1 = gen_move_insn (new_reg, src);
> - rtx_insn *insn2 = gen_move_insn (dest, new_reg);
> - emit_insn_after (insn1, insn);
> - emit_insn_after (insn2, insn1);
> - delete_insn (insn);
> -
> - insn = insn2;
> + rtx_insn *new_insn = gen_move_insn (new_reg, src);
> + SET_SRC (set) = new_reg;
> + emit_insn_before (new_insn, insn);
> + df_insn_rescan (insn);
> }
>  }
>  }
> --
> 1.8.3.1
>


Re: [PATCH] combine: Fix various shortcomings in make_more_copies (PR87701, PR87780)

2018-10-29 Thread Segher Boessenkool
On Mon, Oct 29, 2018 at 12:31:28AM -0700, Andrew Pinski wrote:
> > PR rtl-optimization/87701
> > PR rtl-optimization/87780
> > * combine.c (make_more_copies): Rewrite.
> 
> I think a better changelog would be :):
> * combine.c (make_more_copies): Rewrite to be simplier.

But it is not simpler at all now: *not* removing old notes while changing
RTL instructions is a very bad idea often; and modifying instructions
while not being very careful upsets DF.  It may *look* simple now ;-)


Segher


Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-29 Thread Christophe Lyon
On Fri, 26 Oct 2018 at 17:42, Richard Earnshaw (lists)
 wrote:
>
> On 26/10/2018 16:25, Christophe Lyon wrote:
> > On Tue, 23 Oct 2018 at 16:07, Richard Earnshaw (lists)
> >  wrote:
> >>
> >> On 19/10/2018 14:40, Christophe Lyon wrote:
> >>> On 12/10/2018 12:45, Richard Earnshaw (lists) wrote:
>  On 11/10/18 14:34, Christophe Lyon wrote:
> > The FDPIC register is hard-coded to r9, as defined in the ABI.
> >
> > We have to disable tailcall optimizations if we don't know if the
> > target function is in the same module. If not, we have to set r9 to
> > the value associated with the target module.
> >
> > When generating a symbol address, we have to take into account whether
> > it is a pointer to data or to a function, because different
> > relocations are needed.
> >
> > 2018-XX-XX  Christophe Lyon  
> > Mickaël Guêné 
> >
> > * config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
> > in FDPIC mode.
> > * config/arm/arm-protos.h (arm_load_function_descriptor): Declare
> > new function.
> > * config/arm/arm.c (arm_option_override): Define pic register to
> > FDPIC_REGNUM.
> > (arm_function_ok_for_sibcall) Disable sibcall optimization if we
> 
>  Missing colon.
> 
> > have no decl or go through PLT.
> > (arm_load_pic_register): Handle TARGET_FDPIC.
> > (arm_is_segment_info_known): New function.
> > (arm_pic_static_addr): Add support for FDPIC.
> > (arm_load_function_descriptor): New function.
> > (arm_assemble_integer): Add support for FDPIC.
> > * config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
> > Define. (FDPIC_REGNUM): New define.
> > * config/arm/arm.md (call): Add support for FDPIC.
> > (call_value): Likewise.
> > (*restore_pic_register_after_call): New pattern.
> > (untyped_call): Disable if FDPIC.
> > (untyped_return): Likewise.
> > * config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.
> >
> 
>  Other comments inline.
> 
> > diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
> > index 4471f79..90733cc 100644
> > --- a/gcc/config/arm/arm-c.c
> > +++ b/gcc/config/arm/arm-c.c
> > @@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
> > builtin_define ("__ARM_EABI__");
> >   }
> >   +  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
> > +
> > def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
> > def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
> >   diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
> > index 0dfb3ac..28cafa8 100644
> > --- a/gcc/config/arm/arm-protos.h
> > +++ b/gcc/config/arm/arm-protos.h
> > @@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
> >   extern int arm_const_double_inline_cost (rtx);
> >   extern bool arm_const_double_by_parts (rtx);
> >   extern bool arm_const_double_by_immediates (rtx);
> > +extern rtx arm_load_function_descriptor (rtx funcdesc);
> >   extern void arm_emit_call_insn (rtx, rtx, bool);
> >   bool detect_cmse_nonsecure_call (tree);
> >   extern const char *output_call (rtx *);
> > diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> > index 8810df5..92ae24b 100644
> > --- a/gcc/config/arm/arm.c
> > +++ b/gcc/config/arm/arm.c
> > @@ -3470,6 +3470,14 @@ arm_option_override (void)
> > if (flag_pic && TARGET_VXWORKS_RTP)
> >   arm_pic_register = 9;
> >   +  /* If in FDPIC mode then force arm_pic_register to be r9.  */
> > +  if (TARGET_FDPIC)
> > +{
> > +  arm_pic_register = FDPIC_REGNUM;
> > +  if (TARGET_ARM_ARCH < 7)
> > +error ("FDPIC mode is not supported on architectures older than
> > Armv7");
> 
>  What properties of FDPIC impose this requirement?  Does it also apply to
>  Armv8-m.baseline?
> 
> >>> In fact, there was miscommunication on my side, resulting in a
> >>> misunderstanding between Kyrill and myself, which I badly translated
> >>> into this condition.
> >>>
> >>> My initial plan was to submit a patch series tested on v7, and send the
> >>> patches needed to support older architectures as a follow-up. The proper
> >>> restriction is actually "CPUs that do not support ARM or Thumb2". As you
> >>> may have noticed during the iterations of this patch series, I had
> >>> failed to remove partial Thumb1 support hunks.
> >>>
> >>> So really this should be rephrased, and rewritten as "FDPIC mode is
> >>> supported on architecture versions that support ARM or Thumb-2", if that
> >>> suits you. And the condition should thus be:
> >>> if (! TARGET_ARM && ! TARGET_THUMB2)
> >>>   error ("...")
> >>>
> >>> This would also exclude Armv8-m.baseline, since it doesn't support Thumb2.
> >>
>

Re: [PATCH v4] Avoid unnecessarily numbering cloned symbols.

2018-10-29 Thread Martin Liška
On 10/27/18 6:15 PM, Michael Ploujnikov wrote:
> Hi,
> 
> On 2018-10-26 10:25 a.m., Jan Hubicka wrote:
>>> From aea94273e7a477a03d1ee10a5d9043d6d13b8e8d Mon Sep 17 00:00:00 2001
>>> From: Michael Ploujnikov 
>>> Date: Thu, 25 Oct 2018 13:16:36 -0400
>>> Subject: [PATCH] Avoid unnecessarily numbering cloned symbols.
>>>
>>> gcc/ChangeLog:
>>>
>>> 2018-10-26  Michael Ploujnikov  
>>>
>>> * cgraph.h (clone_function_name_1): Replaced by new
>>>   clone_function_name_numbered that takes name as string; for
>>>   privatize_symbol_name_1 use only.
>>>   (clone_function_name): Renamed to
>>>   clone_function_name_numbered to be explicit about numbering.
>>>   (clone_function_name): New two-argument function that does
>>>   not number its output.
>>>   (clone_function_name): New three-argument function that
>>>   takes a number to append to its output.
>>> * cgraphclones.c (duplicate_thunk_for_node):
>>>   (clone_function_name_1): Renamed.
>>>   (clone_function_name_numbered): Two new functions.
>>>   (clone_function_name): Improved documentation.
>>>   (cgraph_node::create_virtual_clone): Use clone_function_name_numbered.
>>> * config/rs6000/rs6000.c (make_resolver_func): Ditto.
>>> * final.c (final_scan_insn_1): Use the new clone_function_name
>>>   without numbering.
>>> * multiple_target.c (create_dispatcher_calls): Ditto.
>>>   (create_target_clone): Ditto.
>>> * omp-expand.c (grid_expand_target_grid_body): Ditto.
>>> * omp-low.c (create_omp_child_function_name): Ditto.
>>> * omp-simd-clone.c (simd_clone_create): Ditto.
>>> * symtab.c (simd_symtab_node::noninterposable_alias): Use the
>>>   new clone_function_name without numbering.
>>>
>>> gcc/lto/ChangeLog:
>>>
>>> 2018-10-26  Michael Ploujnikov  
>>>
>>> * lto-partition.c (privatize_symbol_name_1): Use
>>>   clone_function_name_numbered.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 2018-10-26  Michael Ploujnikov  
>>>
>>> * gcc.dg/tree-prof/cold_partition_label.c: Update for cold
>>>   section names without numbers.
>>> * gcc.dg/tree-prof/section-attr-1.c: Ditto.
>>> * gcc.dg/tree-prof/section-attr-2.c: Ditto.
>>> * gcc.dg/tree-prof/section-attr-3.c: Ditto.
>>
>> OK,
>> thanks!
>> Honza
>>
> 
> Thanks again for the review. This is my first patch and I don't have
> commit access. What should I do?

I'm going to install the patch on your behalf. For write access you should
follow these intructions: 
https://www.gnu.org/software/gcc/svnwrite.html#policies

Martin

> 
> 
> - Michael
> 



Undef CLEAR_INSN_CACHE before #define in vxworks.h

2018-10-29 Thread Olivier Hainque
Hello,

This fixes a build failure observed during aarch64 port development
effort, corresponds to the intent on this target (we still want to use
the vxworks specific definition), and I checked that I could still
build a function powerpc-vxworks toolchain after the patch.

Olivier

2018-10-29  Olivier Hainque  

* config/vxworks.h (CLEAR_INSN_CACHE): #undef before #define.

From b3eb3ee44716e1c5336b7b86a4f03746d04d4493 Mon Sep 17 00:00:00 2001
From: Olivier Hainque 
Date: Fri, 26 Oct 2018 18:44:52 +0200
Subject: [PATCH 2/4] Undef CLEAR_INSN_CACHE before #define in vxworks.h

---
 gcc/config/vxworks.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index 3e5506e..2e2ab6c 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -209,6 +209,7 @@ extern void vxworks_asm_out_destructor (rtx symbol, int 
priority);
 
 /* We provide our own version of __clear_cache in libgcc, using a separate C
file to facilitate #inclusion of VxWorks header files.  */
+#undef CLEAR_INSN_CACHE
 #define CLEAR_INSN_CACHE 1
 
 /* Default dwarf control values, for non-gdb debuggers that come with
-- 
1.7.10.4



Re: Turn complete to incomplete types in free_lang_data

2018-10-29 Thread Jan Hubicka
Hi,
this is cleaner version of the patch.  During weekend I did some tests with
firefox, libreoffice and gcc builds and it seems to work well. For firefox
it reaches almost linear scalability of the ltrans files (they are 1.9GB,
after increasing number of partitions to 128 they grow to 2GB that looks
quite acceptable. Resulting .s and libxul binary are actually bigger than
that when debug info is enabled).

So if that works in other cases, I will increas lto-partitions and probably
declare it good enough for this stage1 and will try to move to other things.

Concerning two things we have discussed, I am keeping recursion to
free_lang_data_in_type for now as reordering seems just temporary solution
until we do more freeing from both types and decl (eventually I want to free
subtypes of function types that also brings a lot of context. On Firefox that
acount another 5% of stream data volume).

One option would be to change the walking order for this stage1 and worry
about it next stage1.  Other option would be to simply push the newly created
types to the fld queues.

I also did not share fld_type_variant_equal_p with check_base_type since
that one checks also context that we do not want to do. Probably could be
cleaned up incrementally - I wonder why Objective-C needs it.

I looked into enabling free_lang_data by default.  My main problem there is
what to do with late langhooks, say one for variably_modified_type_p.
I suppose we could just declare middle-end self contained wrt analyzing
IL and try to disable them one by one after free lang data was run?

What we however want to do about late warnings? Do we have some idea how
many are those and what kind of % modifiers needs to be printed correctly?
Say late warning wants to print a type, how we are going to do that?

Boostrapped/regtested x86_64-linux.

Honza
* tree.c (free_lang_data_in_type): Forward declare.
(fld_type_variant_equal_p): New function.
(fld_type_variant): New function
(fld_incomplete_types): New hash.
(fld_incomplete_type_of): New function
(fld_simplfied-type): New function.
(free_lang_data_in_decl): New.
Index: tree.c
===
--- tree.c  (revision 265573)
+++ tree.c  (working copy)
@@ -265,6 +265,8 @@
 static void print_debug_expr_statistics (void);
 static void print_value_expr_statistics (void);
 
+static void free_lang_data_in_type (tree type);
+
 tree global_trees[TI_MAX];
 tree integer_types[itk_none];
 
@@ -5038,6 +5041,115 @@
 SET_EXPR_LOCATION (t, loc);
 }
 
+/* Do same comparsion as check_qualified_type skipping lang part of type
+   and be more permissive about type names: we only care that names are
+   same (for diagnostics) and that ODR names are the same.  */
+
+static bool
+fld_type_variant_equal_p (tree t, tree v)
+{
+  if (TYPE_QUALS (t) != TYPE_QUALS (v)
+  || TYPE_NAME (t) != TYPE_NAME (v)
+  || TYPE_ALIGN (t) != TYPE_ALIGN (v)
+  || !attribute_list_equal (TYPE_ATTRIBUTES (t),
+   TYPE_ATTRIBUTES (v)))
+return false;
+
+  return true;
+}
+
+/* Find variant of FIRST that match T and create new one if necessary.  */
+
+static tree
+fld_type_variant (tree first, tree t)
+{
+  if (first == TYPE_MAIN_VARIANT (t))
+return t;
+  for (tree v = first; v; v = TYPE_NEXT_VARIANT (v))
+if (fld_type_variant_equal_p (t, v))
+  return v;
+  tree v = build_variant_type_copy (first);
+  TYPE_READONLY (v) = TYPE_READONLY (t);
+  TYPE_VOLATILE (v) = TYPE_VOLATILE (t);
+  TYPE_ATOMIC (v) = TYPE_ATOMIC (t);
+  TYPE_RESTRICT (v) = TYPE_RESTRICT (t);
+  TYPE_ADDR_SPACE (v) = TYPE_ADDR_SPACE (t);
+  TYPE_NAME (v) = TYPE_NAME (t);
+  TYPE_ATTRIBUTES (v) = TYPE_ATTRIBUTES (t);
+  return v;
+}
+
+/* Map complete types to incomplete types.  */
+
+static hash_map *fld_incomplete_types;
+
+/* For T being aggregate type try to turn it into a incomplete variant.
+   Return T if no simplification is possible.  */
+
+static tree
+fld_incomplete_type_of (tree t)
+{
+  if (!t)
+return NULL;
+  if (POINTER_TYPE_P (t))
+{
+  tree t2 = fld_incomplete_type_of (TREE_TYPE (t));
+  if (t2 != TREE_TYPE (t))
+   {
+ tree first;
+ if (TREE_CODE (t) == POINTER_TYPE)
+   first = build_pointer_type_for_mode (t2, TYPE_MODE (t),
+   TYPE_REF_CAN_ALIAS_ALL (t));
+ else
+   first = build_reference_type_for_mode (t2, TYPE_MODE (t),
+   TYPE_REF_CAN_ALIAS_ALL (t));
+ return fld_type_variant (first, t);
+   }
+  return t;
+}
+  if (!RECORD_OR_UNION_TYPE_P (t) || !COMPLETE_TYPE_P (t))
+return t;
+  if (TYPE_MAIN_VARIANT (t) == t)
+{
+  bool existed;
+  tree ©
+= fld_incomplete_types->get_or_insert (t, &existed);
+
+  if (!existed)
+   {
+ copy = build_distinct_type_copy (t);
+
+ /* It

[PATCH] S/390: Allow LARL of literal pool entries

2018-10-29 Thread Ilya Leoshkevich
Bootstrapped and regtested on s390x-redhat-linux.

r265490 allowed the compiler to choose in a more flexible way whether to
use load or load-address-relative-long (LARL) instruction.  When it
chose LARL for literal pool references, the latter ones were rewritten
by pass_s390_early_mach to use UNSPEC_LTREF, which assumes base register
usage, which in turn is not compatible with LARL.  The end result was an
ICE because of unrecognizable insn.

UNSPEC_LTREF and friends are necessary in order to communicate the
dependency on the base register to pass_sched2.  When LARL is used, no
base register is necessary, so in such cases the rewrite must be
avoided.

gcc/ChangeLog:

2018-10-26  Ilya Leoshkevich  

PR target/87762
* config/s390/predicates.md (larl_operand): Use
s390_symbol_larl_p () to reduce code duplication.
* config/s390/s390-protos.h (s390_symbol_larl_p): New function.
* config/s390/s390.c (s390_symbol_larl_p): New function.
(s390_larl_pattern_p): New function.
(annotate_constant_pool_refs): Do nothing for LARL, do not strip
CONST.
(annotate_constant_pool_refs_1): New helper function.
(find_constant_pool_ref): Handle non-annotated literal pool
references, which are usable with LARL.
(replace_constant_pool_ref): Do nothing for LARL.
(replace_constant_pool_ref_1): New helper function.
---
 gcc/config/s390/predicates.md |  9 +
 gcc/config/s390/s390-protos.h |  1 +
 gcc/config/s390/s390.c| 76 +--
 3 files changed, 66 insertions(+), 20 deletions(-)

diff --git a/gcc/config/s390/predicates.md b/gcc/config/s390/predicates.md
index 98a824e77b7..0e431302479 100644
--- a/gcc/config/s390/predicates.md
+++ b/gcc/config/s390/predicates.md
@@ -151,9 +151,7 @@
   if (GET_CODE (op) == LABEL_REF)
 return true;
   if (SYMBOL_REF_P (op))
-return (!SYMBOL_FLAG_NOTALIGN2_P (op)
-   && SYMBOL_REF_TLS_MODEL (op) == 0
-   && s390_rel_address_ok_p (op));
+return s390_symbol_larl_p (op);
 
   /* Everything else must have a CONST, so strip it.  */
   if (GET_CODE (op) != CONST)
@@ -176,10 +174,7 @@
   if (GET_CODE (op) == LABEL_REF)
 return true;
   if (SYMBOL_REF_P (op))
-return (!SYMBOL_FLAG_NOTALIGN2_P (op)
-   && SYMBOL_REF_TLS_MODEL (op) == 0
-   && s390_rel_address_ok_p (op));
-
+return s390_symbol_larl_p (op);
 
   /* Now we must have a @GOTENT offset or @PLT stub
  or an @INDNTPOFF TLS offset.  */
diff --git a/gcc/config/s390/s390-protos.h b/gcc/config/s390/s390-protos.h
index 45fce6ce865..6c36428b1c2 100644
--- a/gcc/config/s390/s390-protos.h
+++ b/gcc/config/s390/s390-protos.h
@@ -157,6 +157,7 @@ extern void s390_indirect_branch_via_thunk (unsigned int 
regno,
rtx comparison_operator,
enum s390_indirect_branch_type 
type);
 extern void s390_indirect_branch_via_inline_thunk (rtx execute_target);
+extern bool s390_symbol_larl_p (rtx);
 #endif /* RTX_CODE */
 
 /* s390-c.c routines */
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 29a829f48ea..e7a6a1d9775 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -2816,6 +2816,25 @@ s390_decompose_constant_pool_ref (rtx *ref, rtx *disp, 
bool *is_ptr,
   return true;
 }
 
+/* Return true iff SYMBOL_REF X can be used with a LARL instruction. */
+
+bool
+s390_symbol_larl_p (rtx x)
+{
+  return (!SYMBOL_FLAG_NOTALIGN2_P (x)
+ && SYMBOL_REF_TLS_MODEL (x) == 0
+ && s390_rel_address_ok_p (x));
+}
+
+/* Return true iff X is a pattern describing a LARL instruction.  */
+
+static bool
+s390_larl_pattern_p (rtx x)
+{
+  return (GET_CODE (x) == SET
+ && larl_operand (SET_SRC (x), VOIDmode));
+}
+
 /* Decompose a RTL expression ADDR for a memory address into
its components, returned in OUT.
 
@@ -8111,11 +8130,8 @@ s390_first_cycle_multipass_dfa_lookahead (void)
   return 4;
 }
 
-/* Annotate every literal pool reference in X by an UNSPEC_LTREF expression.
-   Fix up MEMs as required.  */
-
 static void
-annotate_constant_pool_refs (rtx *x)
+annotate_constant_pool_refs_1 (rtx *x)
 {
   int i, j;
   const char *fmt;
@@ -8184,7 +8200,8 @@ annotate_constant_pool_refs (rtx *x)
  rtx addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, sym, base),
 UNSPEC_LTREF);
 
- SET_SRC (*x) = plus_constant (Pmode, addr, off);
+ SET_SRC (*x) = gen_rtx_CONST (Pmode,
+   plus_constant (Pmode, addr, off));
  return;
}
 }
@@ -8194,16 +8211,28 @@ annotate_constant_pool_refs (rtx *x)
 {
   if (fmt[i] == 'e')
{
- annotate_constant_pool_refs (&XEXP (*x, i));
+ annotate_constant_pool_refs_1 (&XEXP (*x, i));
}
   else if (fmt[i] == 'E')
{
  for (j = 0; j < XVECLEN (*x, i); j++)
-   annotate_co

[C++ Patch] Improve create_array_type_for_decl locations

2018-10-29 Thread Paolo Carlini

Hi,

while working on something else I noticed that by adding a location_t 
parameter we can improve the locations of those error messages. Tested 
x86_64-linux.


Thanks, Paolo.

/

/cp
2018-10-29  Paolo Carlini  

* decl.c (create_array_type_for_decl): Add location_t parameter
and use it.
(grokdeclarator): Adjust call.

/testsuite
2018-10-29  Paolo Carlini  

* g++.dg/cpp0x/auto24.C: Test location too.
* g++.dg/cpp0x/auto3.C: Likewise.
* g++.dg/cpp0x/auto42.C: Likewise.
* g++.dg/cpp0x/initlist57.C: Likewise.
* g++.dg/cpp0x/initlist75.C: Likewise.
* g++.dg/cpp0x/initlist80.C: Likewise.
* g++.dg/cpp0x/lambda/lambda-ice13.C: Likewise.
* g++.old-deja/g++.brendan/array-refs.C: Likewise.
* g++.old-deja/g++.bugs/900322_01.C: Likewise.
* g++.old-deja/g++.bugs/900519_07.C: Likewise.
* g++.old-deja/g++.other/typeck1.C: Likewise.
Index: cp/decl.c
===
--- cp/decl.c   (revision 265582)
+++ cp/decl.c   (working copy)
@@ -88,7 +88,7 @@ static void finish_constructor_body (void);
 static void begin_destructor_body (void);
 static void finish_destructor_body (void);
 static void record_key_method_defined (tree);
-static tree create_array_type_for_decl (tree, tree, tree);
+static tree create_array_type_for_decl (tree, tree, tree, location_t);
 static tree get_atexit_node (void);
 static tree get_dso_handle_node (void);
 static tree start_cleanup_fn (void);
@@ -9835,7 +9837,7 @@ get_scope_of_declarator (const cp_declarator *decl
with this type.  */
 
 static tree
-create_array_type_for_decl (tree name, tree type, tree size)
+create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
 {
   tree itype = NULL_TREE;
 
@@ -9848,9 +9850,9 @@ static tree
   if (type_uses_auto (type))
 {
   if (name)
-   error ("%qD declared as array of %qT", name, type);
+   error_at (loc, "%qD declared as array of %qT", name, type);
   else
-   error ("creating array of %qT", type);
+   error ("creating array of %qT", type);
   return error_mark_node;
 }
 
@@ -9860,7 +9862,7 @@ static tree
 {
 case VOID_TYPE:
   if (name)
-error ("declaration of %qD as array of void", name);
+   error_at (loc, "declaration of %qD as array of void", name);
   else
 error ("creating array of void");
   return error_mark_node;
@@ -9867,7 +9869,7 @@ static tree
 
 case FUNCTION_TYPE:
   if (name)
-error ("declaration of %qD as array of functions", name);
+   error_at (loc, "declaration of %qD as array of functions", name);
   else
 error ("creating array of functions");
   return error_mark_node;
@@ -9874,7 +9876,7 @@ static tree
 
 case REFERENCE_TYPE:
   if (name)
-error ("declaration of %qD as array of references", name);
+   error_at (loc, "declaration of %qD as array of references", name);
   else
 error ("creating array of references");
   return error_mark_node;
@@ -9881,7 +9883,8 @@ static tree
 
 case METHOD_TYPE:
   if (name)
-error ("declaration of %qD as array of function members", name);
+   error_at (loc, "declaration of %qD as array of function members",
+ name);
   else
 error ("creating array of function members");
   return error_mark_node;
@@ -9897,9 +9900,9 @@ static tree
   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
 {
   if (name)
-   error ("declaration of %qD as multidimensional array must "
-  "have bounds for all dimensions except the first",
-  name);
+   error_at (loc, "declaration of %qD as multidimensional array must "
+ "have bounds for all dimensions except the first",
+ name);
   else
error ("multidimensional array must have bounds for all "
   "dimensions except the first");
@@ -11164,7 +11167,8 @@ grokdeclarator (const cp_declarator *declarator,
{
case cdk_array:
  type = create_array_type_for_decl (dname, type,
-declarator->u.array.bounds);
+declarator->u.array.bounds,
+declarator->id_loc);
  if (!valid_array_size_p (input_location, type, dname))
type = error_mark_node;
 
Index: testsuite/g++.dg/cpp0x/auto24.C
===
--- testsuite/g++.dg/cpp0x/auto24.C (revision 265510)
+++ testsuite/g++.dg/cpp0x/auto24.C (working copy)
@@ -2,4 +2,4 @@
 // { dg-do compile { target c++11 } }
 
 int v[1];
-auto (*p)[1] = &v; // { dg-error "array of .auto" }
+auto (*p)[1] = &v; // { dg-error "8:.p. declared as array of 
.auto" }
Index: testsuite/g++.dg/cpp0x/auto3.C
===

[PATCH. Committed] Fix PR85669.

2018-10-29 Thread Iain Sandoe
Hi,

With Segher’s approval on the PR thread I’ve committed the following to trunk 
and 8 branch.
A slightly different patch is needed for 7 branch (under test).

thanks
Iain

gcc/
2018-10-28  Iain Sandoe  

PR target/85669
* config/rs6000/darwin.h (STACK_BOUNDARY): New.
(RS6000_STARTING_FRAME_OFFSET): Adjust to preserve 16byte alignment.
(STACK_DYNAMIC_OFFSET): Likewise.


diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h
index 6b0f18e118..2b5628cac5 100644
--- a/gcc/config/rs6000/darwin.h
+++ b/gcc/config/rs6000/darwin.h
@@ -159,17 +159,45 @@ extern int darwin_emit_branch_islands;
#undef  RS6000_PIC_OFFSET_TABLE_REGNUM
#define RS6000_PIC_OFFSET_TABLE_REGNUM 31

-/* Pad the outgoing args area to 16 bytes instead of the usual 8.  */
+/* Darwin's stack must remain 16-byte aligned for both 32 and 64 bit
+   ABIs.  */
+
+#undef  STACK_BOUNDARY
+#define STACK_BOUNDARY 128
+
+/* Offset within stack frame to start allocating local variables at.
+   For supported Darwin versions, FRAME_GROWS_DOWNWARD is true, therefore
+   this value is the offset to the END of the first local allocated.
+
+   On the RS/6000, the frame pointer is the same as the stack pointer,
+   except for dynamic allocations.  So we start after the fixed area and
+   outgoing parameter area.
+
+   If the function uses dynamic stack space (CALLS_ALLOCA is set), that
+   space needs to be aligned to STACK_BOUNDARY, i.e. the sum of the
+   sizes of the fixed area and the parameter area must be a multiple of
+   STACK_BOUNDARY.  */

#undef RS6000_STARTING_FRAME_OFFSET
#define RS6000_STARTING_FRAME_OFFSET\
-  (RS6000_ALIGN (crtl->outgoing_args_size, 16) \
-   + RS6000_SAVE_AREA)
+  (cfun->calls_alloca  \
+   ? RS6000_ALIGN (crtl->outgoing_args_size + RS6000_SAVE_AREA, 16)\
+   : (RS6000_ALIGN (crtl->outgoing_args_size, 16) + RS6000_SAVE_AREA))
+
+/* Offset from the stack pointer register to an item dynamically
+   allocated on the stack, e.g., by `alloca'.
+
+   The default value for this macro is `STACK_POINTER_OFFSET' plus the
+   length of the outgoing arguments.  The default is correct for most
+   machines.  See `function.c' for details.
+
+   This value must be a multiple of STACK_BOUNDARY (hard coded in
+   `emit-rtl.c').  */

#undef STACK_DYNAMIC_OFFSET
#define STACK_DYNAMIC_OFFSET(FUNDECL)   \
-  (RS6000_ALIGN (crtl->outgoing_args_size.to_constant (), 16)  \
-   + (STACK_POINTER_OFFSET))
+  RS6000_ALIGN (crtl->outgoing_args_size.to_constant() \
+   + STACK_POINTER_OFFSET, 16)

/* Darwin uses a function call if everything needs to be saved/restored.  */

-- 
2.17.1




Re: [GCC][PATCH][Aarch64] Replace umov with cheaper fmov in popcount expansion

2018-10-29 Thread Sam Tebbs
On 10/23/2018 02:50 PM, Richard Earnshaw (lists) wrote:

> On 22/10/2018 10:02, Sam Tebbs wrote:
>> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
>> index 
>> d7473418a8eb62b2757017cd1675493f86e41ef4..77e6f75cc15f06733df7b47906ee00580bea8d29
>>  100644
>> --- a/gcc/config/aarch64/aarch64.md
>> +++ b/gcc/config/aarch64/aarch64.md
>> @@ -4489,7 +4489,7 @@
>> emit_move_insn (v, gen_lowpart (V8QImode, in));
>> emit_insn (gen_popcountv8qi2 (v1, v));
>> emit_insn (gen_reduc_plus_scal_v8qi (r, v1));
>> -  emit_insn (gen_zero_extendqi2 (out, r));
>> +  emit_move_insn (out, gen_lowpart_SUBREG (GET_MODE (out), r));
> I don't think this is right.  You're effectively creating a paradoxical
> subreg here and relying on an unstated side effect of an earlier
> instruction for correct behaviour.
>
> What you really need is a pattern that generates the zero-extend in
> combination with the reduction operation.  So something like
>
> (set (reg:DI)
>   (zero_extend:DI (unspec:VecMode [(reg:VecMode)] UNSPEC_ADDV)))

Hi Richard,

Thanks for the feedback. What assembly would you expect such a pattern 
to produce?

I'm a bit unclear on what you mean by the "the reduction operation", but 
I'm assuming you're referring to the fmov in this case.

>
> now you can copy all, or part, or that register directly across to the
> integer side and the RTL remains mathematically accurate.
>
> R.



Re: [PATCH v4] Avoid unnecessarily numbering cloned symbols.

2018-10-29 Thread Martin Liška
On 10/29/18 9:40 AM, Martin Liška wrote:
> On 10/27/18 6:15 PM, Michael Ploujnikov wrote:
>> Hi,
>>
>> On 2018-10-26 10:25 a.m., Jan Hubicka wrote:
 From aea94273e7a477a03d1ee10a5d9043d6d13b8e8d Mon Sep 17 00:00:00 2001
 From: Michael Ploujnikov 
 Date: Thu, 25 Oct 2018 13:16:36 -0400
 Subject: [PATCH] Avoid unnecessarily numbering cloned symbols.

 gcc/ChangeLog:

 2018-10-26  Michael Ploujnikov  

* cgraph.h (clone_function_name_1): Replaced by new
  clone_function_name_numbered that takes name as string; for
  privatize_symbol_name_1 use only.
  (clone_function_name): Renamed to
  clone_function_name_numbered to be explicit about numbering.
  (clone_function_name): New two-argument function that does
  not number its output.
  (clone_function_name): New three-argument function that
  takes a number to append to its output.
* cgraphclones.c (duplicate_thunk_for_node):
  (clone_function_name_1): Renamed.
  (clone_function_name_numbered): Two new functions.
  (clone_function_name): Improved documentation.
  (cgraph_node::create_virtual_clone): Use clone_function_name_numbered.
* config/rs6000/rs6000.c (make_resolver_func): Ditto.
* final.c (final_scan_insn_1): Use the new clone_function_name
  without numbering.
* multiple_target.c (create_dispatcher_calls): Ditto.
  (create_target_clone): Ditto.
* omp-expand.c (grid_expand_target_grid_body): Ditto.
* omp-low.c (create_omp_child_function_name): Ditto.
* omp-simd-clone.c (simd_clone_create): Ditto.
* symtab.c (simd_symtab_node::noninterposable_alias): Use the
  new clone_function_name without numbering.

 gcc/lto/ChangeLog:

 2018-10-26  Michael Ploujnikov  

* lto-partition.c (privatize_symbol_name_1): Use
  clone_function_name_numbered.

 gcc/testsuite/ChangeLog:

 2018-10-26  Michael Ploujnikov  

* gcc.dg/tree-prof/cold_partition_label.c: Update for cold
  section names without numbers.
* gcc.dg/tree-prof/section-attr-1.c: Ditto.
* gcc.dg/tree-prof/section-attr-2.c: Ditto.
* gcc.dg/tree-prof/section-attr-3.c: Ditto.
>>>
>>> OK,
>>> thanks!
>>> Honza
>>>
>>
>> Thanks again for the review. This is my first patch and I don't have
>> commit access. What should I do?
> 
> I'm going to install the patch on your behalf. For write access you should
> follow these intructions: 
> https://www.gnu.org/software/gcc/svnwrite.html#policies
> 
> Martin
> 
>>
>>
>> - Michael
>>
> 

But first I see some failures when I tried to apply the patch:

$ patch -p0 --dry-run < 
~/Downloads/0001-Avoid-unnecessarily-numbering-cloned-symbols.patch
checking file gcc/cgraph.h
Hunk #1 succeeded at 2382 with fuzz 1 (offset 14 lines).
checking file gcc/cgraphclones.c
Hunk #1 succeeded at 317 (offset 1 line).
checking file gcc/config/rs6000/rs6000.c
Hunk #1 succeeded at 36997 (offset 485 lines).
checking file gcc/lto/lto-partition.c
checking file gcc/multiple_target.c
checking file gcc/omp-expand.c
checking file gcc/omp-low.c
checking file gcc/omp-simd-clone.c
checking file gcc/testsuite/gcc.dg/tree-prof/cold_partition_label.c
checking file gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c
Hunk #1 FAILED at 42.
1 out of 1 hunk FAILED
checking file gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c
Hunk #1 FAILED at 41.
1 out of 1 hunk FAILED
checking file gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c
Hunk #1 FAILED at 42.
1 out of 1 hunk FAILED

Can you please rebase that on top of current trunk?
Thanks,
Martin


[PATCH][RFC] Sanitize equals and hash functions in hash-tables.

2018-10-29 Thread Martin Liška
Hi.

As slightly discussed here: 
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01674.html I fixed
a situation where an equal operator of a hash table returns true, while 
corresponding hash
value of a pair of elements is different. That's inconsistent and can probably 
cause issues
in different areas of compiler.

I wrote a simple patch that verifies for a newly added element into a hash 
table that there's
no other equal element with a different hash. That's O(n) for each insert, so 
that it's only
enabled with -fchecking=3. Apart from that the way how it's enable is a bit 
cumbersome, but
that's caused by usage of hash-table also in generated files.

Anyway, there are first places where I see violation of the sanity check:

1) cselib_lookup_1:

$ cat ice.c
a() { b(); }

$ /dev/shm/objdir/gcc/xgcc -B/dev/shm/objdir/gcc/ ice.c -g -c -fchecking=3 -O
hash table checking failed: equal operator returns true for a pair of values 
with a different hash valueduring RTL pass: vartrack
ice.c:1:1: internal compiler error: in find_slot_with_hash, at hash-table.h:905
1 | a() { b(); }
  | ^
0x9680b5 hash_table::find_slot_with_hash(cselib_hasher::key* const&, unsigned int, 
insert_option)
/home/marxin/Programming/gcc/gcc/hash-table.h:905
0x962518 cselib_find_slot
/home/marxin/Programming/gcc/gcc/cselib.c:584
0x9625d4 cselib_lookup_1
/home/marxin/Programming/gcc/gcc/cselib.c:2097
0x9625d4 cselib_lookup(rtx_def*, machine_mode, int, machine_mode)
/home/marxin/Programming/gcc/gcc/cselib.c:2141
0x965ee7 cselib_record_sets
/home/marxin/Programming/gcc/gcc/cselib.c:2593
0x9670a9 cselib_process_insn(rtx_insn*)
/home/marxin/Programming/gcc/gcc/cselib.c:2790
0x1036b73 vt_initialize
/home/marxin/Programming/gcc/gcc/var-tracking.c:10231
0x103b98a variable_tracking_main_1
/home/marxin/Programming/gcc/gcc/var-tracking.c:10460
0x103b98a variable_tracking_main()
/home/marxin/Programming/gcc/gcc/var-tracking.c:10513

2) gfc_find_module

$ ./xgcc -B. 
/home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/coarray/alloc_comp_2.f90 
-fcoarray=single -fchecking=3
hash table checking failed: equal operator returns true for a pair of values 
with a different hash valuef951: internal compiler error: in 
find_slot_with_hash, at hash-table.h:905
0x8e5e86 hash_table::find_slot_with_hash(char 
const* const&, unsigned int, insert_option)
/home/marxin/Programming/gcc/gcc/hash-table.h:905
0x8e2c2c gfc_find_module(char const*)
/home/marxin/Programming/gcc/gcc/fortran/trans-decl.c:4865
0x8e4f42 gfc_generate_module_vars(gfc_namespace*)
/home/marxin/Programming/gcc/gcc/fortran/trans-decl.c:5475
0x8b8d7e gfc_generate_module_code(gfc_namespace*)
/home/marxin/Programming/gcc/gcc/fortran/trans.c:2190
0x868427 translate_all_program_units
/home/marxin/Programming/gcc/gcc/fortran/parse.c:6112
0x868427 gfc_parse_file()
/home/marxin/Programming/gcc/gcc/fortran/parse.c:6328
0x8b19cb gfc_be_parse_file
/home/marxin/Programming/gcc/gcc/fortran/f95-lang.c:204

3) lookup_template_class_1

$ ./xg++ -B. /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/template/ttp23.C 
-c -fchecking=3
hash table checking failed: equal operator returns true for a pair of values 
with a different hash 
value/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/template/ttp23.C: In 
instantiation of ‘struct B’:
/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/template/ttp23.C:15:8:   
required from here
/home/marxin/Programming/gcc/gcc/testsuite/g++.dg/template/ttp23.C:8:17: 
internal compiler error: in find_slot_with_hash, at hash-table.h:905
8 | friend bool foo (const B& a);
  | ^~~
0xa265a4 hash_table::find_slot_with_hash(spec_entry* 
const&, unsigned int, insert_option)
/home/marxin/Programming/gcc/gcc/hash-table.h:905
0xa042ce lookup_template_class_1
/home/marxin/Programming/gcc/gcc/cp/pt.c:9629
0xa042ce lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*, 
int, int)
/home/marxin/Programming/gcc/gcc/cp/pt.c:9674
0xa03670 tsubst_aggr_type
/home/marxin/Programming/gcc/gcc/cp/pt.c:12679
0x9fefcd tsubst(tree_node*, tree_node*, int, tree_node*)
/home/marxin/Programming/gcc/gcc/cp/pt.c:14294
0x9fe1a9 tsubst(tree_node*, tree_node*, int, tree_node*)
/home/marxin/Programming/gcc/gcc/cp/pt.c:14285
0xa0d8bd tsubst_arg_types
/home/marxin/Programming/gcc/gcc/cp/pt.c:13891
0xa0dc24 tsubst_function_type
/home/marxin/Programming/gcc/gcc/cp/pt.c:14032
0x9fe790 tsubst(tree_node*, tree_node*, int, tree_node*)
/home/marxin/Programming/gcc/gcc/cp/pt.c:14769
0x9f2c7c tsubst_function_decl
/home/marxin/Programming/gcc/gcc/cp/pt.c:12921
0xa02d27 tsubst_template_decl
/home/marxin/Programming/gcc/gcc/cp/pt.c:13214
0x9f4416 tsubst_decl
/home/marxin/Programming/gcc/gcc/cp/pt.c:13316
0x9ff0ca tsubst(tree_node*, tree_node*, int, tree_node*)

Re: [PATCH] Folding and check_function_arguments

2018-10-29 Thread Alexander Monakov
On Thu, 25 Oct 2018, Jason Merrill wrote:
> > > 
> > > Maybe we should remove that in favor of fold_for_warn in
> > > check_function_arguments.

David, I think your patch also fixes PR 86567.

David, Jason, could you comment on doing something similar (using fold_for_warn
instead of maybe_constant_value) to solve other issues where generation of new
tree uids under maybe_constant_value called in warning context changes code
generation, in particular PR 86586?

Thanks.
Alexander


Re: [PATCH 0/7] libsanitizer: merge from trunk

2018-10-29 Thread Martin Liška
On 10/26/18 4:52 PM, Jakub Jelinek wrote:
> On Fri, Oct 26, 2018 at 09:48:54AM -0500, Bill Seurer wrote:
>> On 10/26/18 03:57, Jakub Jelinek wrote:
>>> On Thu, Oct 25, 2018 at 12:49:42PM +0200, Jakub Jelinek wrote:
 On Thu, Oct 25, 2018 at 12:15:46PM +0200, marxin wrote:
> I've just finished my first merge from libsanitizer mainline. Overall it
> looks fine, apparently ABI hasn't changed and so that SONAME bump is not
> needed.

 Given the 6/7 patch, I think you need to bump libasan soname (it would be
 weird to bump it on powerpc64* only).
>>>
>>> BTW, how can shadow offset be 1UL<<44 on powerpc64?  That seems like they
>>> don't want to support anything but very recent kernels.
>>> E.g. looking at Linux 3.4 arch/powerpc/include/asm/processor.h
>>> I see
>>> /* 64-bit user address space is 44-bits (16TB user VM) */
>>> #define TASK_SIZE_USER64 (0x1000UL)
>>> so, the new choice must be incompatible with lots of kernels out there.
>>> Move recent kernels have:
>>> #define TASK_SIZE_64TB  (0x4000UL)
>>> #define TASK_SIZE_128TB (0x8000UL)
>>> #define TASK_SIZE_512TB (0x0002UL)
>>> #define TASK_SIZE_1PB   (0x0004UL)
>>> #define TASK_SIZE_2PB   (0x0008UL)
>>> #define TASK_SIZE_4PB   (0x0010UL)
>>> but 4.15 still tops at 512TB, 4.10 has just 64TB as the only choice, 3.8 as
>>> well.
>>>
>>> CCing Bill as he made this change.
>>>
>>> Jakub
>>>
>>
>> At the time for llvm the concern was to get it to work on newer kernels and
>> not worry (much) about the older ones.  I did spend some time trying to get
>> it to work for both.
> 
> Which exact task size doesn't work if shadow offset is 2TB and why?
> 
>   Jakub
> 

Just for the record: am I right that any system using 44 bit of VMA will fail 
because
anything + (1 << 44) will be out of process address space?

And I noticed that documentation in sanitizer_linux.cc is misleading:

...
uptr GetMaxVirtualAddress() {
#if (SANITIZER_NETBSD || SANITIZER_OPENBSD) && defined(__x86_64__)
  return 0x7f7ff000ULL;  // (0x7f80 - PAGE_SIZE)
#elif SANITIZER_WORDSIZE == 64
# if defined(__powerpc64__) || defined(__aarch64__)
  // On PowerPC64 we have two different address space layouts: 44- and 46-bit.
  // We somehow need to figure out which one we are using now and choose
  // one of 0x0fffUL and 0x3fffUL.
...

That should be adjusted.

Thanks,
Martin


Re: [PATCH 0/7] libsanitizer: merge from trunk

2018-10-29 Thread Jakub Jelinek
On Mon, Oct 29, 2018 at 12:13:04PM +0100, Martin Liška wrote:
> Just for the record: am I right that any system using 44 bit of VMA will fail 
> because
> anything + (1 << 44) will be out of process address space?

Yes.

> And I noticed that documentation in sanitizer_linux.cc is misleading:
> 
> ...
> uptr GetMaxVirtualAddress() {
> #if (SANITIZER_NETBSD || SANITIZER_OPENBSD) && defined(__x86_64__)
>   return 0x7f7ff000ULL;  // (0x7f80 - PAGE_SIZE)
> #elif SANITIZER_WORDSIZE == 64
> # if defined(__powerpc64__) || defined(__aarch64__)
>   // On PowerPC64 we have two different address space layouts: 44- and 46-bit.
>   // We somehow need to figure out which one we are using now and choose
>   // one of 0x0fffUL and 0x3fffUL.
> ...
> 
> That should be adjusted.

Apparently for ppc64 there are many different layouts now, 44, 46, 47, 49, 52
at least depending on which kernel and page size you choose.
So, ideally we want some choice that works with all of them.  Shadow offset
1ULL<<44 is not that choice.

Jakub


Re: [patch, doc, fortran] Document FINDLOC

2018-10-29 Thread Bernhard Reutner-Fischer
Hi!

On Sun, 28 Oct 2018 15:13:49 +0100
Thomas König  wrote:

One question and some nits below.

> ===
> --- intrinsic.texi(Revision 265569)
> +++ intrinsic.texi(Arbeitskopie)

> @@ -6021,8 +6022,68 @@ END PROGRAM
>  @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
>  @end table
>  
> +@node FINDLOC
> +@section @code{FINDLOC} --- Search an array for a value

I think one should not put spaces around triple-dashes.

> +@fnindex FINDLOC
> +@cindex findloc
>  
> +@table @asis
> +@item @emph{Description}:
> +Determines the location of the element in the array with the value
> +given in the @var{VALUE} argument, or, if the @var{DIM} argument is
> +supplied, determines the locations of the maximum element along each
> +row of the array in the @var{DIM} direction. If @var{MASK} is present,

dot-space-space at end of sentence: direction.  If

> +only the elements for which @var{MASK} is @code{.TRUE.} are
> +considered.  If more than one element in the array has the value
> +@var{VALUE}, the location returned is that of the first such element
> +in array element order if the @var{BACK} is not present, or if it

missing "is": ...not present or if it is @code{.FALSE.}.

> +false; otherwise, the location returned is that of the first such
> +element. If the array has zero size, or all of the elements of

I think this should mention BACK=.TRUE. for clarity; and it should
refer to the _last_ such element, not the first, doesn't it?

Like:

If @var{BACK} is @code{.TRUE.} the location returned is that of the
last such element.

> +@var{MASK} are @code{.FALSE.}, then the result is an array of zeroes.
> +Similarly, if @var{DIM} is supplied and all of the elements of
> +@var{MASK} along a given row are zero, the result value for that row
> +is zero.
>  
> +@item @emph{Standard}:
> +Fortran 2008 and later.
> +
> +@item @emph{Class}:
> +Transformational function
> +
> +@item @emph{Syntax}:
> +@multitable @columnfractions .80
> +@item @code{RESULT = FINDLOC(ARRAY, VALUE, DIM [, MASK] [,KIND] [,BACK])}
> +@item @code{RESULT = FINDLOC(ARRAY, VALUE, [, MASK] [,KIND] [,BACK])}
> +@end multitable
> +
> +@item @emph{Arguments}:
> +@multitable @columnfractions .15 .70
> +@item @var{ARRAY} @tab Shall be an array of intrinsic type.
> +@item @var{VALUE} @tab A scalar of intrinsic type which is in type
> +conformance with @var{ARRAY}.
> +@item @var{DIM}   @tab (Optional) Shall be a scalar of type

Excess spaces between @var{DIM} and @tab?

> +@code{INTEGER}, with a value between one and the rank of @var{ARRAY},
> +inclusive.  It may not be an optional dummy argument.
> +@item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
> +expression indicating the kind parameter of the result.
> +@item @var{BACK} @tab (Optional) A scalar of type @code{LOGICAL}.
> +@end multitable
> +
> +@item @emph{Return value}:
> +If @var{DIM} is absent, the result is a rank-one array with a length
> +equal to the rank of @var{ARRAY}.  If @var{DIM} is present, the result
> +is an array with a rank one less than the rank of @var{ARRAY}, and a
> +size corresponding to the size of @var{ARRAY} with the @var{DIM}
> +dimension removed.  If @var{DIM} is present and @var{ARRAY} has a rank
> +of one, the result is a scalar.   If the optional argument @var{KIND}

Excess third space at the start of the sentence: dot-space-space

thanks,

> +is present, the result is an integer of kind @var{KIND}, otherwise it
> +is of default kind.


Fix build of the D frontend on the Hurd and KFreeBSD

2018-10-29 Thread Matthias Klose
Fix build of the D frontend on the Hurd and KFreeBSD.  Where should these
changes go, when they are not yet applied upstream?

Ok to commit?

Matthias

# DP: Fix build of the D frontend on the Hurd and KFreeBSD.

Index: b/src/gcc/d/dfrontend/object.h
===
--- a/src/gcc/d/dmd/root/object.h
+++ b/src/gcc/d/dmd/root/object.h
@@ -10,7 +10,7 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
-#define POSIX (__linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun)
+#define POSIX (__linux__ || __GLIBC__ || __gnu_hurd__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun)
 
 #if __DMC__
 #pragma once


Re: [PATCH] GCOV: introduce --json-format.

2018-10-29 Thread Martin Liška
On 10/10/18 1:46 PM, Martin Liška wrote:
> Hi.
> 
> I'm sending updated version of the patch. I made a research and it looks that
> actually any significant consumer of GCOV does not use intermediate format:
> 
> https://github.com/gcovr/gcovr/issues/282
> https://github.com/linux-test-project/lcov/issues/43
> https://github.com/mozilla/grcov/issues/55
> 
> That said I made following changes:
> - I removed current int. format and replaced that with JSON format
> - documentation for the format is enhanced
> - JSON files are generated by default gzipped
> 
> Patch survives gcov.exp tests.
> 
> Martin
> 

I've just installed the patch as r265587.

Martin


Re: [GCC][PATCH][Aarch64] Replace umov with cheaper fmov in popcount expansion

2018-10-29 Thread Richard Henderson
On 10/29/18 10:31 AM, Sam Tebbs wrote:
> On 10/23/2018 02:50 PM, Richard Earnshaw (lists) wrote:
> 
>> On 22/10/2018 10:02, Sam Tebbs wrote:
>>> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
>>> index 
>>> d7473418a8eb62b2757017cd1675493f86e41ef4..77e6f75cc15f06733df7b47906ee00580bea8d29
>>>  100644
>>> --- a/gcc/config/aarch64/aarch64.md
>>> +++ b/gcc/config/aarch64/aarch64.md
>>> @@ -4489,7 +4489,7 @@
>>> emit_move_insn (v, gen_lowpart (V8QImode, in));
>>> emit_insn (gen_popcountv8qi2 (v1, v));
>>> emit_insn (gen_reduc_plus_scal_v8qi (r, v1));
>>> -  emit_insn (gen_zero_extendqi2 (out, r));
>>> +  emit_move_insn (out, gen_lowpart_SUBREG (GET_MODE (out), r));
>> I don't think this is right.  You're effectively creating a paradoxical
>> subreg here and relying on an unstated side effect of an earlier
>> instruction for correct behaviour.
>>
>> What you really need is a pattern that generates the zero-extend in
>> combination with the reduction operation.  So something like
>>
>> (set (reg:DI)
>>   (zero_extend:DI (unspec:VecMode [(reg:VecMode)] UNSPEC_ADDV)))
> 
> Hi Richard,
> 
> Thanks for the feedback. What assembly would you expect such a pattern 
> to produce?

The same assembly as you had.  It's just that the rtl that you were using to
represent it was incorrect.

> I'm a bit unclear on what you mean by the "the reduction operation", but 
> I'm assuming you're referring to the fmov in this case.

The reduction operation in this case is the addv.

r~


[PATCH] Fix PR87785

2018-10-29 Thread Richard Biener


The following fixes gone missing load nodes with the SLP tree build
now eventually caching them but not having them in the SLP tree.

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

Richard.

2018-10-29  Richard Biener  

PR tree-optimization/87785
* tree-vect-slp.c (vect_build_slp_tree_2): Remove loads argument
and processing.
(vect_build_slp_tree): Likewise.
(vect_gather_slp_loads): New function.
(vect_analyze_slp_instance): Gather loads separately from the
SLP tree build.

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 5b925be80f4..7bb0d3aa0e0 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -1032,7 +1032,6 @@ static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo,
   vec stmts, unsigned int group_size,
   poly_uint64 *max_nunits,
-  vec *loads,
   bool *matches, unsigned *npermutes, unsigned *tree_size,
   unsigned max_tree_size,
   scalar_stmts_to_slp_tree_map_t *bst_map);
@@ -1040,7 +1039,7 @@ vect_build_slp_tree_2 (vec_info *vinfo,
 static slp_tree
 vect_build_slp_tree (vec_info *vinfo,
 vec stmts, unsigned int group_size,
-poly_uint64 *max_nunits, vec *loads,
+poly_uint64 *max_nunits,
 bool *matches, unsigned *npermutes, unsigned *tree_size,
 unsigned max_tree_size,
 scalar_stmts_to_slp_tree_map_t *bst_map)
@@ -1055,7 +1054,7 @@ vect_build_slp_tree (vec_info *vinfo,
   return *leader;
 }
   slp_tree res = vect_build_slp_tree_2 (vinfo, stmts, group_size, max_nunits,
-   loads, matches, npermutes, tree_size,
+   matches, npermutes, tree_size,
max_tree_size, bst_map);
   /* Keep a reference for the bst_map use.  */
   if (res)
@@ -1075,7 +1074,6 @@ static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo,
   vec stmts, unsigned int group_size,
   poly_uint64 *max_nunits,
-  vec *loads,
   bool *matches, unsigned *npermutes, unsigned *tree_size,
   unsigned max_tree_size,
   scalar_stmts_to_slp_tree_map_t *bst_map)
@@ -1149,7 +1147,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
 {
   *max_nunits = this_max_nunits;
   node = vect_create_new_slp_node (stmts);
-  loads->safe_push (node);
   return node;
 }
 
@@ -1173,7 +1170,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
   }
 
   auto_vec children;
-  auto_vec this_loads;
 
   stmt_info = stmts[0];
 
@@ -1184,7 +1180,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
   FOR_EACH_VEC_ELT (oprnds_info, i, oprnd_info)
 {
   slp_tree child;
-  unsigned old_nloads = this_loads.length ();
   unsigned old_tree_size = this_tree_size;
   unsigned int j;
 
@@ -1207,7 +1202,7 @@ vect_build_slp_tree_2 (vec_info *vinfo,
 
   if ((child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
group_size, &this_max_nunits,
-   &this_loads, matches, npermutes,
+   matches, npermutes,
&this_tree_size,
max_tree_size, bst_map)) != NULL)
{
@@ -1227,7 +1222,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
  if (!grandchild)
{
  /* Roll back.  */
- this_loads.truncate (old_nloads);
  this_tree_size = old_tree_size;
  FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child), j, grandchild)
vect_free_slp_tree (grandchild, false);
@@ -1350,7 +1344,7 @@ vect_build_slp_tree_2 (vec_info *vinfo,
  bool *tem = XALLOCAVEC (bool, group_size);
  if ((child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
group_size, &this_max_nunits,
-   &this_loads, tem, npermutes,
+   tem, npermutes,
&this_tree_size,
max_tree_size, bst_map)) != NULL)
{
@@ -1396,7 +1390,6 @@ vect_build_slp_tree_2 (vec_info *vinfo,
  if (!grandchild)
{
  /* Roll back.  */
- this_loads.truncate (old_nloads);
  this_tree_size = old_tree_size;
  FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (child), j, 
grandchild)
vect_free_slp_tree (grandchild, false);
@@ -1433,7 +1426,6 @@ fail:
   if (tree_size)
 *tree_size += this_tree_size;
   *max_nunits = t

[PATCH] libgcc: properly destroy mutexes on VxWorks

2018-10-29 Thread Rasmus Villemoes
Just as one needs run-time initialization of mutexes, one needs to
destroy them properly to allow the OS to release resources associated
with the semaphore.

==changelog==

libgcc/

* config/gthr-vxworks.h (__gthread_mutex_destroy): Call semDelete.
---
 libgcc/config/gthr-vxworks.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libgcc/config/gthr-vxworks.h b/libgcc/config/gthr-vxworks.h
index e43253b01c7..e974aa79368 100644
--- a/libgcc/config/gthr-vxworks.h
+++ b/libgcc/config/gthr-vxworks.h
@@ -63,8 +63,9 @@ __gthread_mutex_init_function (__gthread_mutex_t *mutex)
 }
 
 static inline int
-__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+__gthread_mutex_destroy (__gthread_mutex_t *mutex)
 {
+  semDelete(*mutex);
   return 0;
 }
 
-- 
2.19.1.6.gbde171bbf5



Re: [PATCH v3 3/3] or1k: gcc: initial support for openrisc

2018-10-29 Thread Stafford Horne
On Sun, Oct 28, 2018 at 11:16:13PM +, Richard Henderson wrote:
> On 10/28/18 2:57 AM, Segher Boessenkool wrote:
> >> +(define_insn "xorsi3"
> >> +  [(set (match_operand:SI 0 "register_operand" "=r,r")
> >> +(xor:SI
> >> + (match_operand:SI 1 "register_operand"   "%r,r")
> >> + (match_operand:SI 2 "reg_or_s16_operand" " r,I")))]
> >> +  ""
> >> +  "@
> >> +  l.xor\t%0, %1, %2
> >> +  l.xori\t%0, %1, %2")
> > 
> > Is this correct?  Should this be unsigned (u16 and K)?
> 
> No, l.xori is signed.

Right, sorry, I didn't have enough time to look at this at all this morning.  It
is correct.

It looks like the documentation for this page [1] is generated from the cgen cpu
descriptions that were removed from binutils-gdb back in 2014.  Ccing cgen who
seem to maintain this web page.  How can we go about getting it regenerated?

cpu/or1korbis.cpu

(alu-insn-uimm and)
(alu-insn-uimm or)
(alu-insn-simm xor)

(define-pmacro (alu-carry-insn-simm mnemonic)
  (begin
(dni (.sym l- mnemonic "i")
 (.str "l." mnemonic "i reg/reg/simm16")
 ((MACH ORBIS-MACHS))
 (.str "l." mnemonic "i $rD,$rA,$simm16")
 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA simm16)

[1] https://sourceware.org/cgen/gen-doc/openrisc-insn.html#insns

-Stafford


Re: [PATCH] Make __PRETTY_FUNCTION__-like functions mergeable string csts (PR c++/64266).

2018-10-29 Thread Jason Merrill
On Fri, Oct 26, 2018 at 3:14 AM Martin Liška  wrote:
> On 10/24/18 7:24 PM, Jason Merrill wrote:
> > On Tue, Oct 23, 2018 at 4:59 AM Martin Liška  wrote:
> >> However, I still see some minor ICEs, it's probably related to 
> >> decay_conversion in cp_fname_init:
> >>
> >> 1) ./xg++ -B. 
> >> /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__2.C
> >>
> >> /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-__func__2.C:6:17:
> >>  internal compiler error: Segmentation fault
> >> 6 | [] { return __func__; }();
> >>   | ^~~~
> >> 0x1344568 crash_signal
> >> /home/marxin/Programming/gcc/gcc/toplev.c:325
> >> 0x76bc310f ???
> >> 
> >> /usr/src/debug/glibc-2.27-6.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
> >> 0x9db134 is_capture_proxy(tree_node*)
>
> Hi.
>
> >
> > The problem in both tests is that is_capture_proxy thinks your
> > __func__ VAR_DECL with DECL_VALUE_EXPR is a capture proxy, since it is
> > neither an anonymous union proxy nor a structured binding.
>
> I see, however I'm a rookie in area of C++ FE. Would it be solvable this 
> problem
> with lambdas?
>
> >
> > The standard says,
> >
> > The function-local predefined variable __func__ is defined as if a
> > definition of the form
> >static const char __func__[] = "function-name ";
> > had been provided, where function-name is an implementation-defined
> > string. It is unspecified whether such a variable has an address
> > distinct from that of any other object in the program.
> >
> > So changing the type of __func__ (from array to pointer) still breaks
> > conformance.  And we need to keep the type checks from pretty4.C, even
> > though the checks for strings being distinct need to go.
>
> I added following patch which puts back type to const char[] (instead of char 
> *)
> and I made the variable static. Now I see pretty4.C testcase passing again.
> To be honest I'm not convinced about the FE changes, so a help would
> be appreciated.

OK, I'll poke at it.

Jason


Re: [PATCH v3 1/3] or1k: libgcc: initial support for openrisc

2018-10-29 Thread Stafford Horne
On Sun, Oct 28, 2018 at 01:25:54AM +, Richard Henderson wrote:
> On 10/27/18 5:37 AM, Stafford Horne wrote:
> > +/* Here _init and _fini are empty because .init_array/.fini_array are used
> > +   exclusively.  However, the functions are still needed as required when
> > +   linking.  */
> > +   .align 4
> > +   .global _init
> > +   .type   _init,@function
> > +_init:
> > +   .global _fini
> > +   .type   _fini,@function
> > +_fini:
> > +   l.jrr9
> > +l.nop
> 
> Where are they referenced from?  Perhaps just a binutils bug, in that the
> linker script needs adjustment?

I was getting the issue with newlib.  Here:

 
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/misc/init.c
 
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/misc/fini.c

The HAVE_INIT_FINI was not there when I last checked. Now, thanks to risc-v, we
can turn off the need for _init/_fini see:

 
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=commit;f=newlib/libc/misc/fini.c;h=6158b30e3e9b1b582ae60b15d64e775fa1705483

I guess thats what you were referring to before though, I just missed it.

> > +   /* Given R = X * Y ... */
> > +1: l.sfeq  r4, r0  /* while (y != 0) */
> > +   l.bf2f
> > +l.andi r5, r4, 1   /* if (y & 1) ... */
> > +   l.add   r12, r11, r3
> > +   l.sfne  r5, r0
> > +#if defined(__or1k_cmov__)
> > +   l.cmov  r11, r12, r11   /* ... r += x. */
> > +   l.srli  r4, r4, 1   /* y >>= 1 */
> > +#else
> > +   l.bnf   3f
> > +l.srli r4, r4, 1   /* y >>= 1 */
> > +   l.ori   r11, r12, 0
> 
> This move could be the add to save 1 cycle in the !cmov case.
> 
> > +   /* Shift Y back to the right again, subtracting from X.  */
> > +2: l.add   r7, r11, r6 /* tmp1 = quot + mask */
> > +3: l.srli  r6, r6, 1   /* mask >>= 1 */
> > +   l.sub   r8, r12, r4 /* tmp2 = x - y */
> > +   l.sfleu r4, r12 /* y <= x */
> > +   l.srli  r4, r4, 1   /* y >>= 1 */
> > +#if defined(__or1k_cmov__)
> > +   l.cmov  r11, r7, r11/* if (y <= x) quot = tmp1 */
> > +   l.cmov  r12, r8, r12/* if (y <= x) x = tmp2 */
> > +#else
> > +   l.bnf   4f
> > +l.nop
> > +   l.ori   r11, r7, 0
> > +   l.ori   r12, r8, 0
> 
> Simiarly.
> 
> Although both mul nor div are correct as-is, and need not be fixed 
> immediately.
>  I'm only concerned about _init and _fini.

Sure, let me look into them.

-Stafford


[PATCH] Fix PR87790

2018-10-29 Thread Richard Biener


When fixing compile-time issues with the SLP graph processing I failed
to recognize that vect_detect_hybrid_slp_stmts needs to union info
over graph edges and thus a simple visited flag doesn't do the trick.
The following instead makes sure we propagate to children only after
we have visited all incoming edges.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Richard.

2018-10-29  Richard Biener  

PR tree-optimization/87790
* tree-vect-slp.c (vect_mark_slp_stmts): Simplify.
(vect_make_slp_decision): Adjust.
(vect_slp_analyze_bb_1): Likewise.
(vect_detect_hybrid_slp_stmts): Properly union SLP type over
edges.

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 5b925be80f4..a1db0dfde86 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -1477,14 +1469,10 @@ vect_print_slp_tree (dump_flags_t dump_kind, 
dump_location_t loc,
   vect_print_slp_tree (dump_kind, loc, node, visited);
 }
 
-/* Mark the tree rooted at NODE with MARK (PURE_SLP or HYBRID).
-   If MARK is HYBRID, it refers to a specific stmt in NODE (the stmt at index
-   J).  Otherwise, MARK is PURE_SLP and J is -1, which indicates that all the
-   stmts in NODE are to be marked.  */
+/* Mark the tree rooted at NODE with PURE_SLP.  */
 
 static void
-vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j,
-hash_set &visited)
+vect_mark_slp_stmts (slp_tree node, hash_set &visited)
 {
   int i;
   stmt_vec_info stmt_info;
@@ -1497,18 +1485,17 @@ vect_mark_slp_stmts (slp_tree node, enum slp_vect_type 
mark, int j,
 return;
 
   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
-if (j < 0 || i == j)
-  STMT_SLP_TYPE (stmt_info) = mark;
+STMT_SLP_TYPE (stmt_info) = pure_slp;
 
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
-vect_mark_slp_stmts (child, mark, j, visited);
+vect_mark_slp_stmts (child, visited);
 }
 
 static void
-vect_mark_slp_stmts (slp_tree node, enum slp_vect_type mark, int j)
+vect_mark_slp_stmts (slp_tree node)
 {
   hash_set visited;
-  vect_mark_slp_stmts (node, mark, j, visited);
+  vect_mark_slp_stmts (node, visited);
 }
 
 /* Mark the statements of the tree rooted at NODE as relevant (vect_used).  */
@@ -2197,7 +2211,7 @@ vect_make_slp_decision (loop_vec_info loop_vinfo)
   /* Mark all the stmts that belong to INSTANCE as PURE_SLP stmts.  Later 
we
 call vect_detect_hybrid_slp () to find stmts that need hybrid SLP and
 loop-based vectorization.  Such stmts will be marked as HYBRID.  */
-  vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance), pure_slp, -1);
+  vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance));
   decided_to_slp++;
 }
 
@@ -2221,7 +2235,7 @@ vect_make_slp_decision (loop_vec_info loop_vinfo)
 
 static void
 vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype,
- hash_set &visited)
+ hash_map &visited)
 {
   stmt_vec_info stmt_vinfo = SLP_TREE_SCALAR_STMTS (node)[i];
   imm_use_iterator imm_iter;
@@ -2231,15 +2245,16 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned 
i, slp_vect_type stype,
   loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo);
   int j;
 
-  if (visited.add (node))
-return;
+  /* We need to union stype over the incoming graph edges but we still
+ want to limit recursion to stay O(N+E).  */
+  bool only_edge = (++visited.get_or_insert (node) < node->refcnt);
 
   /* Propagate hybrid down the SLP tree.  */
   if (stype == hybrid)
 ;
   else if (HYBRID_SLP_STMT (stmt_vinfo))
 stype = hybrid;
-  else
+  else if (!only_edge)
 {
   /* Check if a pure SLP stmt has uses in non-SLP stmts.  */
   gcc_checking_assert (PURE_SLP_STMT (stmt_vinfo));
@@ -2281,15 +2296,16 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned 
i, slp_vect_type stype,
   STMT_SLP_TYPE (stmt_vinfo) = hybrid;
 }
 
-  FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child)
-if (SLP_TREE_DEF_TYPE (child) != vect_external_def)
-  vect_detect_hybrid_slp_stmts (child, i, stype, visited);
+  if (!only_edge)
+FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child)
+  if (SLP_TREE_DEF_TYPE (child) != vect_external_def)
+   vect_detect_hybrid_slp_stmts (child, i, stype, visited);
 }
 
 static void
 vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype)
 {
-  hash_set visited;
+  hash_map visited;
   vect_detect_hybrid_slp_stmts (node, i, stype, visited);
 }
 
@@ -2875,7 +2891,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_iterator region_begin,
 
   /* Mark all the statements that we want to vectorize as pure SLP and
 relevant.  */
-  vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance), pure_slp, -1);
+  vect_mark_slp_stmts (SLP_INSTANCE_TREE (instance));
   vect_mark_slp_stmts_relevant (SLP_INSTANCE_TREE (instance));
 
   i++;
Index: gcc/testsuite/gcc.dg/pr87790.c
=

Re: [ARM/FDPIC v3 03/21] [ARM] FDPIC: Force FDPIC related options unless -mno-fdpic is provided

2018-10-29 Thread Christophe Lyon
On Fri, 26 Oct 2018 at 17:07, Christophe Lyon
 wrote:
>
> On Tue, 23 Oct 2018 at 17:14, Segher Boessenkool
>  wrote:
> >
> > On Tue, Oct 23, 2018 at 02:58:21PM +0100, Richard Earnshaw (lists) wrote:
> > > On 15/10/2018 11:10, Christophe Lyon wrote:
> > > > Do you mean to also make -mfdpic non-existent/rejected when GCC is not
> > > > configured
> > > > for arm-uclinuxfdpiceabi?
> > >
> > > Ideally doesn't exist, so that it doesn't show up in things like --help
> > > when it doesn't work.
> > >
> > > > How to achieve that?
> > >
> > > Good question, I'm not sure, off hand.  It might be possible to make the
> > > config machinery add additional opt files, but it's not something I've
> > > tried.  You might want to try adding an additional opt file to
> > > extra_options for fdpic targets.
> >
> > That should work yes.  You could look at how 476.opt is added for powerpc,
> > it is a comparable situation.
> >
>
> Thanks, I got it to work.
>
> Now back to Richard's original question:
> > I think this needs to be resolved.  Either -mfdpic works everywhere, or
> > the option should only be available when configured for -mfdpic.
> It's not that -mfdpic does not work everywhere, rather it is not sufficient
> to use it alone: it should be used along with fpic/fPIC/fpie/fPIE depending
> on the use case.
>
> In practice I don't know if we want to be able to use -mfdpic with a
> arm-linux-gnueabi
> toolchain, or if we are ok to have to use two different toolchains
> when we want to make
> tests/compare code generation in both cases.
>
> The 1st option means I should improve the documentation patch. For the 2nd 
> one,
> I have patches in progress (which also imply reworking the doc since the 
> option
> would not also be available)
>

Here is an updated doc proposal (that would go in patch #1, without
changing this one):
@item -mfdpic
@opindex mfdpic
Select the FDPIC ABI, which uses function descriptors to represent
pointers to functions.  When the compiler is configured for
@code{arm-*-uclinuxfdpiceabi} targets, this option is on by default
and implies @option{-fPIE} if none of the PIC/PIE-related options is
provided.  On other targets, it only enables the FDPIC-specific code
generation features, and the user should explicitly provide the
PIC/PIE-related options as needed.

The opposite @option{-mno-fdpic} option is useful (and required) to
build the Linux kernel using the same toolchain as the one used to
build the userland programs.

Is it clearer? Does it read OK?

Thanks

> Christophe
>
>
> >
> > Segher


Re: [PATCH][RFC] Sanitize equals and hash functions in hash-tables.

2018-10-29 Thread Alexander Monakov
On Mon, 29 Oct 2018, Martin Liška wrote:
> My question is whether we want to have in GCC 9 time frame or should I wait 
> with that?
> Does it worth implementing?

This is cool, thanks! A few questions/comments on the patch.

I think there are places that use libiberty C-style hashtab (htab_t), would it
make sense to have this kind of checking for them as well?  I think it's going
to be more complicated though, no need to do both in one step.

I would recommend to factor out the error reporting path into a separate
non-template function, e.g. hashtab_chk_error.  See how qsort_chk_error
has "cold" and "noreturn" attributes and invokes problematic comparators:
the idea was that a developer can 'break qsort_chk_error' in GDB and then
easily step into broken comparators.

Furthermore, it might be nice to investigate if the entire checking loop can
be factored out somehow into a non-template function to avoid having multiple
instantiations of it for different hashtable template parameters.

On my first attempt to submit qsort_chk, Richi asked how much it slows down
stage2, do you have some data on the cost of this hashtable checking?

I think it is possible to optimize this a bit: instead of checking on
insertions, check on deletions and when destroying the table (with care to do
n^2/2 rather than n^2 tests). Although, such approach would miss errors on
hashtables that are never destroyed (leaked or deliberately not deleted).

Alexander

Re: [PATCH 0/7] libsanitizer: merge from trunk

2018-10-29 Thread Bill Seurer

On 10/29/18 06:24, Jakub Jelinek wrote:

On Mon, Oct 29, 2018 at 12:13:04PM +0100, Martin Liška wrote:

Just for the record: am I right that any system using 44 bit of VMA will fail 
because
anything + (1 << 44) will be out of process address space?


Yes.


And I noticed that documentation in sanitizer_linux.cc is misleading:

...
uptr GetMaxVirtualAddress() {
#if (SANITIZER_NETBSD || SANITIZER_OPENBSD) && defined(__x86_64__)
   return 0x7f7ff000ULL;  // (0x7f80 - PAGE_SIZE)
#elif SANITIZER_WORDSIZE == 64
# if defined(__powerpc64__) || defined(__aarch64__)
   // On PowerPC64 we have two different address space layouts: 44- and 46-bit.
   // We somehow need to figure out which one we are using now and choose
   // one of 0x0fffUL and 0x3fffUL.
...

That should be adjusted.


Apparently for ppc64 there are many different layouts now, 44, 46, 47, 49, 52
at least depending on which kernel and page size you choose.
So, ideally we want some choice that works with all of them.  Shadow offset
1ULL<<44 is not that choice.


We (llvm team) tried to get it to work on all the different kernels but 
didn't find anything that worked.  Finally we just went with a value 
that worked on the newer kernels as the 44 bit one was not a target of 
concern.


--

-Bill Seurer



Re: [PR87469] ICE in record_estimate, at tree-ssa-loop-niter.c

2018-10-29 Thread Richard Biener
On Sun, Oct 28, 2018 at 1:11 AM Kugan Vivekanandarajah
 wrote:
>
> Hi,
>
> In the testcase provided in the bug report, max value for niter
> estimation is off by one when it is INTEGER_CST. As a results it
> asserts at the place where it is checked for equality.
> Attached patch fixes this. Bootstrapped and regression tested on
> x86_64-linux-gnu with no new regression. Is this OK?

OK.

> Thanks,
> Kugan
>
> gcc/testsuite/ChangeLog:
>
> 2018-10-26  Kugan Vivekanandarajah  
>
> PR middle-end/87469
> * g++.dg/pr87469.C: New test.
>
> gcc/ChangeLog:
>
> 2018-10-26  Kugan Vivekanandarajah  
>
> PR middle-end/87469
> * tree-ssa-loop-niter.c (number_of_iterations_popcount): Fix niter
> max value.


ping x2 [PATCH 0/3] [MSP430] Add methods to extract MCU data from file

2018-10-29 Thread Jozef Lawrynowicz

The same as previous pings except I removed the patch which updates the
hard-coded device data - I'll commit that later as "obvious".

Ok for trunk?



The following series of patches extends MCU device data handling for the msp430
target, allowing an external file to be read which describes the CPU ISA and
hardware multiply supported for different MCUs.
The current hard-coded solution means that new MCUs can only be supported by
updating the GCC itself.

The first patch keeps the hard-coded data as the only way of reading MCU data,
but consolidates it in a single file. Extensions to the spec handling in
msp430.h mean that the hard-coded data is no longer needed in 't-msp430' for
multilib selection, or in the assembler. This is achieved by the driver which
places the corresponding mcpu value for the MCU on its command line.

Some extensions to msp430.exp were necessary to ensure that full test coverage
is achieved when the testsuite is run using "make check".
As the tests for different MCUs result in different ISAs/memory
models being used, the hard-coded libgloss multilib directories on the command
line needed to be fixed up to allow the non-default "430" and "large" multilibs
to be tested.
The tests could be downgraded from link tests to assemble tests, (the mips
testsuite does this), but then we would lose coverage that the spec strings
and multilib selection work as expected.

The second patch adds functionality to search the include paths specified with
-I for "devices.csv". If the file is found, and a device name has been passed
to the -mmcu option, then devices.csv is parsed, and the MCU data for the given
device is extracted.

The third patch adds functionality to search for devices.csv in both
the path specified by the environment variable "MSP430_GCC_INCLUDE_DIR", and
the directory "msp430-elf/include/devices" from the toolchain root. These
locations are searched if devices.csv is not found on an include path.
If devices.csv is found using one of these methods, the directory containing
devices.csv is also registered as an include path and linker library path.



Re: [RFC][PR87528][PR86677] Disable builtin popcount detection when back-end does not define it

2018-10-29 Thread Richard Biener
On Mon, Oct 29, 2018 at 2:06 AM Kugan Vivekanandarajah
 wrote:
>
> Hi Richard and Jeff,
>
> Thanks for your comments.
>
> On Fri, 26 Oct 2018 at 19:40, Richard Biener  
> wrote:
> >
> > On Fri, Oct 26, 2018 at 4:55 AM Jeff Law  wrote:
> > >
> > > On 10/25/18 4:33 PM, Kugan Vivekanandarajah wrote:
> > > > Hi,
> > > >
> > > > PR87528 showed a case where libgcc generated popcount is causing
> > > > regression for Skylake.
> > > > We also have PR86677 where kernel build is failing because the kernel
> > > > does not use the libgcc (when backend is not defining popcount
> > > > pattern).  While I agree that the kernel should implement its own
> > > > functionality when it is not using the libgcc, I am afraid that the
> > > > implementation can have the same performance issues reported for
> > > > Skylake in PR87528.
> > > >
> > > > Therefore, I would like to propose that we disable popcount detection
> > > > when we don't have a pattern for that. The attached patch (based on
> > > > previous discussions) does this.
> > > >
> > > > Bootstrapped and regression tested on x86_64-linux-gnu with no new
> > > > regressions. We need to disable the popcount* testcases. I will have
> > > > to define a effective_target_with_popcount in
> > > > gcc/testsuite/lib/target-supports.exp if this patch is OK?
> > > > Thanks,
> > > > Kugan
> > > >
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > > 2018-10-25  Kugan Vivekanandarajah  
> > > >
> > > > * tree-scalar-evolution.c (expression_expensive_p): Make BUILTIN 
> > > > POPCOUNT
> > > > as expensive when backend does not define it.
> > > >
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > 2018-10-25  Kugan Vivekanandarajah  
> > > >
> > > > * gcc.target/aarch64/popcount4.c: New test.
> > > >
> > > FWIW, I've been disabling by checking direct_optab_handler elsewhere
> > > (number_of_iterations_popcount) in my tester.  It may in fact be an old
> > > patch from you.
> > >
> > > Richi argued that it's the kernel team's responsibility to provide a
> > > popcount since they don't link with libgcc.  And I'm generally in
> > > agreement with that position, though it does tend to generate some
> > > friction with the kernel developers.  We also run the real risk of GCC 9
> > > not being able to build the kernel which, IMHO, would be a disaster from
> > > a PR standpoint.
> > >
> > > I'd like to hear from others here.  I fully realize we're beyond the
> > > realm of what is strictly technically correct here from a review 
> > > standpoint.
> >
> > As said final value replacement to a library call is probably not wanted
> > for optimization purpose, so adjusting expression_expensive_p is OK with
> > me.  It might not fully solve the (non-)issue in case another optimization 
> > pass
> > chooses to materialize niter computation result.
> >
> > Few comments on the patch:
> >
> > +  tree fndecl = get_callee_fndecl (expr);
> > +
> > +  if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
> > +   {
> > + combined_fn cfn = as_combined_fn (DECL_FUNCTION_CODE (fndecl));
> >
> >   combined_fn cfn = gimple_call_combined_fn (expr);
> >   switch (cfn)
> > {
>
> Did you mean:
> combined_fn cfn = get_call_combined_fn (expr);

Yes.

> > ...
> >
> > cfn will be CFN_LAST for a non-builtin/internal call.  I know Richard is 
> > mostly
> > offline but eventually he knows whether there is a better way to query
> >
> > +   CASE_CFN_POPCOUNT:
> > + /* Check if opcode for popcount is available.  */
> > + if (optab_handler (popcount_optab,
> > +TYPE_MODE (TREE_TYPE (CALL_EXPR_ARG
> > (expr, 0
> > + == CODE_FOR_nothing)
> > +   return true;
> >
> > note that we currently generate builtin calls rather than IFN calls
> > (when a direct
> > optab is supported).
> >
> > Another comment on the patch is that you probably have to adjust existing
> > popcount testcases to add architecture specific flags enabling suport for
> > the instructions, otherwise you won't see loop replacement.
> Indeed.
> In lib/target-supports.exp, I will try to add support for
> check_effective_target_popcount_long.
> When I grep for the popcount pattern in md files, I see it is defined for:
>
> tilegx
> tilepro
> alpha
> aarch64  when TARGET_SIMD
> ia64
> rs6000
> i386  when TARGET_POPCOUNT
> popwerpcspce  when TARGET_POPCNTB || TARGET_POPCNTD
> s390  when TARGET_Z916 && TARGET_64BIT
> sparc when TARGET_POPC
> arm when TARGET_NEON
> mips when ISA_HAS_POP
> spu
> avr
>
> I can check these targets with the condition.
> Another possibility is to check with a sample code and see if we are
> getting a libcall in the asm. Not sure if that is straightforward. Are
> there any example for such.

You could try linking w/o libgcc ...

> We could also move these test to a primary target that is tested often
> tested which also defines popcount pattern. I dont think these tests
> change for targets and if we can t

ping x2 [PATCH 1/3] [MSP430] Consolidate hard-coded MCU data

2018-10-29 Thread Jozef Lawrynowicz

This patch keeps the hard-coded data as the only way of reading MCU data,
but consolidates it in a single file. Extensions to the spec handling in
msp430.h mean that the hard-coded data is no longer needed in 't-msp430' for
multilib selection, or in the assembler. This is achieved by the driver which
places the corresponding mcpu value for the MCU on its command line.

>From 58709e127d3bf13da6da58fca416946718c4c17c Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz 
Date: Mon, 29 Oct 2018 13:48:06 +
Subject: [PATCH 1/3] MSP430 - Devices 1 - Handle device tasks in separate file

2018-10-29  Jozef Lawrynowicz  

gcc/
	* config.gcc (msp430*-*-*): Add msp430-devices.o to extra_objs and
	extra_gcc_objs.

gcc/config/msp430/

	* msp430-devices.c: New.
	* msp430-devices.h: New.
	* driver-msp430.c (msp430_select_cpu): New spec function to return
	-mcpu value for given mcu.
	(msp430_select_hwmult_lib): Call msp430_extract_mcu_data to get MCU
	data.
	(msp430_mcu_data): Remove.
	* msp430.c (msp430_mcu_data): Remove.
	(msp430_mcu_name): Call msp430_extract_mcu_data to get MCU data.
	(msp430_option_override): Likewise.
	(msp430_use_f5_series_hwmult): Likewise.
	(use_32bit_hwmult): Likewise.
	(msp430_no_hwmult): Likewise.
	* msp430.h (EXTRA_SPEC_FUNCTIONS): Add msp430_select_cpu.
	(DRIVER_SELF_SPECS): Define.
	(ASM_SPEC): Don't pass mmcu option to assembler.
	* t-msp430: Add makefile rule for msp430-devices.o.
	Remove MULTILIB_MATCHES containing MCU names.

gcc/testsuite/gcc.target/msp430/

	* devices-main.c: New generic test source file.
	* msp430.exp (msp430_set_old_board_info_ldflags): New.
	(msp430_reset_board_info_ldflags): New.
	(msp430_get_multidir): New.
	(check_effective_target_430_selected): New.
	(check_effective_target_msp430_hwmul_not_none): New.
	(check_effective_target_msp430_hwmul_not_16bit): New.
	(check_effective_target_msp430_hwmul_not_32bit): New.
	(check_effective_target_msp430_hwmul_not_f5): New.
	(msp430_get_supported_opts): New.
	(msp430_device_permutations_runtest): New.
	(dg-msp-options): New dg-directive for MSP430.
	* devices/README: New.
	* devices/hard_cc430f5123.c: New test.
	* devices/hard_foo.c: New test.
	* devices/hard_msp430afe253.c: New test.
	* devices/hard_msp430cg4616.c: New test.
	* devices/hard_msp430f4783.c: New test.
	* devices/hard_rf430frl154h_rom.c: New test.
---
 gcc/config.gcc |   3 +-
 gcc/config/msp430/driver-msp430.c  | 667 +--
 gcc/config/msp430/msp430-devices.c | 673 +++
 gcc/config/msp430/msp430-devices.h |  11 +
 gcc/config/msp430/msp430.c | 732 ++---
 gcc/config/msp430/msp430.h |  14 +-
 gcc/config/msp430/t-msp430 | 237 +--
 gcc/testsuite/gcc.target/msp430/devices-main.c |   5 +
 gcc/testsuite/gcc.target/msp430/devices/README |  15 +
 .../gcc.target/msp430/devices/hard_cc430f5123.c|   7 +
 gcc/testsuite/gcc.target/msp430/devices/hard_foo.c |   5 +
 .../gcc.target/msp430/devices/hard_msp430afe253.c  |   7 +
 .../gcc.target/msp430/devices/hard_msp430cg4616.c  |   7 +
 .../gcc.target/msp430/devices/hard_msp430f4783.c   |   7 +
 .../msp430/devices/hard_rf430frl154h_rom.c |   7 +
 gcc/testsuite/gcc.target/msp430/msp430.exp | 207 +-
 16 files changed, 1057 insertions(+), 1547 deletions(-)
 create mode 100644 gcc/config/msp430/msp430-devices.c
 create mode 100644 gcc/config/msp430/msp430-devices.h
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices-main.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/README
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/hard_cc430f5123.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/hard_foo.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/hard_msp430afe253.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/hard_msp430cg4616.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/hard_msp430f4783.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/hard_rf430frl154h_rom.c

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 93dc297..e093ae9 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2429,7 +2429,8 @@ msp430*-*-*)
 	c_target_objs="msp430-c.o"
 	cxx_target_objs="msp430-c.o"
 	tmake_file="${tmake_file} msp430/t-msp430"
-	extra_gcc_objs="driver-msp430.o"
+	extra_objs="${extra_objs} msp430-devices.o"
+	extra_gcc_objs="driver-msp430.o msp430-devices.o"
 	;;
 nds32*-*-*)
 	target_cpu_default="0"
diff --git a/gcc/config/msp430/driver-msp430.c b/gcc/config/msp430/driver-msp430.c
index 09b4b9c..e83c20f 100644
--- a/gcc/config/msp430/driver-msp430.c
+++ b/gcc/config/msp430/driver-msp430.c
@@ -25,627 +25,30 @@
 #include "coretypes.h"
 #include "diagnostic.h"
 #include "tm.h"
+#include "msp430-devices.h"
 
-/* This is a copy of the same data structure found in gas/config/tc-msp430.c
-   Also another (sort-of) copy can

Re: [PATCH v3 3/3] or1k: gcc: initial support for openrisc

2018-10-29 Thread Szabolcs Nagy
On 27/10/18 05:37, Stafford Horne wrote:
> +++ b/gcc/config/or1k/linux.h
> @@ -0,0 +1,44 @@
> +/* Linux Definitions for OpenRISC.
> +   Copyright (C) 2018 Free Software Foundation, Inc.
> +   Contributed by Stafford Horne.
> +
> +   This file is part of GCC.
> +
> +   GCC is free software; you can redistribute it and/or modify it
> +   under the terms of the GNU General Public License as published
> +   by the Free Software Foundation; either version 3, or (at your
> +   option) any later version.
> +
> +   GCC is distributed in the hope that it will be useful, but WITHOUT
> +   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
> +   License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with GCC; see the file COPYING3.  If not see
> +   .  */
> +
> +#ifndef GCC_OR1K_LINUX_H
> +#define GCC_OR1K_LINUX_H
> +
> +/* elfos.h should have already been included.  Now just override
> +   any conflicting definitions and add any extras.  */
> +
> +#define TARGET_OS_CPP_BUILTINS() \
> +  GNU_USER_TARGET_OS_CPP_BUILTINS ()
> +
> +#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-or1k.so.1"
> +
> +#undef MUSL_DYNAMIC_LINKER
> +#define MUSL_DYNAMIC_LINKER  "/lib/ld-musl-or1k.so.1"
> +
> +#undef LINK_SPEC
> +#define LINK_SPEC "%{h*} \
> +   %{static:-Bstatic}\
> +   %{shared:-shared} \
> +   %{symbolic:-Bsymbolic}\
> +   %{!static:\
> + %{rdynamic:-export-dynamic} \
> + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
> +
> +#endif /* GCC_OR1K_LINUX_H */

note that because of the -static-pie mess each
target needs a more complicated LINK_SPEC now.

i think there could be a generic LINK_SPEC in
config/linux.h or config/gnu-user.h that works
for simple targets (the start file spec is
already there) so this complex logic is not
repeated everywhere.

or even do the -no-dynamic-linker logic in
LINK_PIE_SPEC in gcc.c for all targets, not
just linux, so backends don't need to do
anything to get static-pie to work.


Introduce VXWORKS_PERSONALITY

2018-10-29 Thread Olivier Hainque
Hello,

This patch simply makes explicit the notion of VxWorks
"personality" on which a given port relies, which controls
conditional parts exposed by the system headers, depending
on the kind of system compiler used to build the VxWorks
kernel on which we expect programs will run.

This defaults to "gnu" as the vast majority of VxWorks
environments we target come which GNU toolchains and this
is our natural interface.

I checked that I could build functional toolchains based on
gcc-8, passing Ada ACATS in two modes for two targets: powerpc
which uses a gnu personality, and aarch64 (port to be
contributed shortly) which comes with only an llvm system compiler
at this stage.

This exercises quite a bit of the Ada runtime system, several
parts of which interface with OS services through a C layer.

Testing exposed that the _VX_TOOL/_VX_TOOL_FAMILY pair is
more typically inferred from the TOOL/TOOL_FAMILY pair within the
system headers, not always vice-versa, so this patch arranges to
#define the latter instead of the former.

Olivier

2018-10-29  Olivier Hainque  

* config/vxworks.h (VXWORKS_PERSONALITY): New VxWorks
ports configuration macro, defaults to "gnu".
(VXWORKS_OS_CPP_BUILTINS): Use it. Feed TOOL and
TOOL_FAMILY instead of _VX_TOOL/_VXTOOL_FAMILY.

From c70c245919209a4ae6dd1278fd87a5a652960d7d Mon Sep 17 00:00:00 2001
From: Olivier Hainque 
Date: Fri, 19 Oct 2018 18:47:19 +0200
Subject: [PATCH 1/4] Introduce VXWORKS_PERSONALITY

---
 gcc/config/vxworks.h |   11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index 656ced5..3e5506e 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -169,6 +169,13 @@ extern void vxworks_asm_out_destructor (rtx symbol, int 
priority);
 #define TARGET_POSIX_IO
 
 /* A VxWorks implementation of TARGET_OS_CPP_BUILTINS.  */
+
+/* The VxWorks personality we rely on, controlling which sections of system
+   headers files we trigger.  This might be redefined on targets where the
+   base VxWorks environment doesn't come with a GNU toolchain.  */
+
+#define VXWORKS_PERSONALITY "gnu"
+
 #define VXWORKS_OS_CPP_BUILTINS()  \
   do   \
 {  \
@@ -179,8 +186,8 @@ extern void vxworks_asm_out_destructor (rtx symbol, int 
priority);
builtin_define ("__RTP__"); \
   else \
builtin_define ("_WRS_KERNEL"); \
-  builtin_define ("_VX_TOOL_FAMILY=gnu");  \
-  builtin_define ("_VX_TOOL=gnu"); \
+  builtin_define ("TOOL_FAMILY=" VXWORKS_PERSONALITY); \
+  builtin_define ("TOOL=" VXWORKS_PERSONALITY);\
   if (TARGET_VXWORKS7) \
 {  \
builtin_define ("_VSB_CONFIG_FILE=");   \
-- 
1.7.10.4










ping x2 [PATCH 2/3] [MSP430] Search for MCU data file on include paths

2018-10-29 Thread Jozef Lawrynowicz

This patch adds functionality to search the include paths specified with
-I for "devices.csv". If the file is found, and a device name has been passed
to the -mmcu option, then devices.csv is parsed, and the MCU data for the given
device is extracted.

>From e85964a398a35a69513da07e4fcdaeed215ae79a Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz 
Date: Mon, 29 Oct 2018 13:51:24 +
Subject: [PATCH 2/3] MSP430 - Devices 2 - Add functionality to read device
 data from CSV file

2018-10-29  Jozef Lawrynowicz  

gcc/config/msp430/

	* msp430-devices.c (msp430_check_path_for_devices): New.
	(devices_csv_warning): New.
	(parse_devices_csv_1): New.
	(parse_devices_csv): New.
	(msp430_extract_mcu_data): Add argument to choose if devices.csv
	warnings should be surpressed.
	* msp430.c (msp430_mcu_name): Update invocation of msp430_extract_mcu_data.
	(msp430_option_override): Likewise.
	(msp430_use_f5_series_hwmult): Likewise.
	(use_32bit_hwmult): Likewise.
	(msp430_no_hwmult): Likewise.
	* msp430-devices.h (msp430_extract_mcu_data): Add argument to choose
	if devices.csv warnings should be surpressed.
	* msp430.h (EXTRA_SPEC_FUNCTIONS): Add msp430_check_path_for_devices.
	(DRIVER_SELF_SPECS): Likewise.
	* msp430.opt: Add -mdevices-csv-loc= and -mdisable-device-warnings
	options.
	* driver-msp430.c (msp430_select_cpu): Update invocation of
	msp430_extract_mcu_data.
	(msp430_select_hwmult_lib): Likewise.

gcc/doc/

	* invoke.texi: Document that MCU data for the -mmcu option value can be
	loaded from an external file.
	Document -mdisable-device-warnings.

gcc/testsuite/gcc.target/msp430/

	* devices/csv_msp430_{0,1,2}{0,1,2,4,8}.c: New.
	* devices/csv_msp430f5529.c: New.
	* devices/csv_msp430fr5969.c: New.
	* devices/devices.csv: New.
	* devices/msp430.h: New.
	* msp430.exp (msp430_get_multidir): Extend so MCU data is loaded from
	devices.csv for csv_* tests.
	(dg-msp-options): Update invocation to msp430_get_multidir.
	(msp430_get_supported_opts): Likewise.
	(msp430_device_permutations_runtest): Extend to handle csv_* tests.
---
 gcc/config/msp430/driver-msp430.c  |   5 +-
 gcc/config/msp430/msp430-devices.c | 203 -
 gcc/config/msp430/msp430-devices.h |   2 +-
 gcc/config/msp430/msp430.c |  10 +-
 gcc/config/msp430/msp430.h |   7 +-
 gcc/config/msp430/msp430.opt   |   9 +
 gcc/doc/invoke.texi|  10 +-
 .../gcc.target/msp430/devices/csv_msp430_00.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_01.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_02.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_04.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_08.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_10.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_11.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_12.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_14.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_18.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_20.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_21.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_22.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_24.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430_28.c  |   6 +
 .../gcc.target/msp430/devices/csv_msp430f5529.c|   8 +
 .../gcc.target/msp430/devices/csv_msp430fr5969.c   |  10 +
 .../gcc.target/msp430/devices/devices.csv  |  17 ++
 gcc/testsuite/gcc.target/msp430/devices/msp430.h   |   3 +
 gcc/testsuite/gcc.target/msp430/msp430.exp |  35 +++-
 27 files changed, 386 insertions(+), 23 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_00.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_01.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_02.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_04.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_08.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_10.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_11.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_12.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_14.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_18.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_20.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_21.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_22.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_24.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430_28.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_msp430f5529.c
 create mode 100644 

Extract VXWORKS_NET_LIBS_RTP from VXWORKS_LIBS_RTP

2018-10-29 Thread Olivier Hainque
Hello,

This patch extracts the network part of the VXWORKS_LIBS_RTP
LIB_SPEC component, so it can be redefined by OS specific configuration
files.

I used this in the course of the aarch64 port development and
verified that I could still build a functional powerpc-vxworks port
after the patch.

Olivier

2018-10-29  Olivier Hainque  

* VXWORKS_NET_LIBS_RTP: New macro, network part of VXWORKS_LIBS_RTP.

From 45a7b0a2254740306ede125c633bdcb55ae1bdca Mon Sep 17 00:00:00 2001
From: Olivier Hainque 
Date: Fri, 19 Oct 2018 21:20:31 +0200
Subject: [PATCH 3/4] Extract VXWORKS_NET_LIBS_RTP from VXWORKS_LIBS_RTP

---
 gcc/config/vxworks.h |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index 2e2ab6c..b00b597 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -69,13 +69,19 @@ along with GCC; see the file COPYING3.  If not see
libgcc.a that we need to use e.g. to satisfy references to __init and
__fini.  We still want our libgcc to prevail for symbols it would provide
(e.g. register save entry points), so re-place it here between libraries
-   that might reference it and libc_internal.  Also, some versions of VxWorks
-   rely on explicit extra libraries for system calls.  */
+   that might reference it and libc_internal.
+
+   In addition, some versions of VxWorks rely on explicit extra libraries for
+   system calls and the set of base network libraries of common use varies
+   across architectures.  The default settings defined here might be redefined
+   by target specific port configuration files.  */
 
 #define VXWORKS_SYSCALL_LIBS_RTP
 
+#define VXWORKS_NET_LIBS_RTP "-lnet -ldsi"
+
 #define VXWORKS_LIBS_RTP \
-  VXWORKS_SYSCALL_LIBS_RTP " -lnet -ldsi -lc -lgcc -lc_internal"
+  VXWORKS_SYSCALL_LIBS_RTP " " VXWORKS_NET_LIBS_RTP " -lc -lgcc -lc_internal"
 
 /* On Vx6 and previous, the libraries to pick up depends on the architecture,
so cannot be defined for all archs at once.  On Vx7, a VSB is always needed
-- 
1.7.10.4





ping x2 [PATCH 3/3] [MSP430] Search for MCU data file using environment variable and in a toolchain subdirectory

2018-10-29 Thread Jozef Lawrynowicz

This patch adds functionality to search for devices.csv in both
the path specified by the environment variable "MSP430_GCC_INCLUDE_DIR", and
the directory "msp430-elf/include/devices" from the toolchain root. These
locations are searched if devices.csv is not found on an include path.
If devices.csv is found using one of these methods, the directory containing
devices.csv is also registered as an include path and linker library path.

>From cc4dbcb83be19fd55e6dae28ea37a714109bec26 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz 
Date: Mon, 29 Oct 2018 13:52:39 +
Subject: [PATCH 3/3] MSP430 - Devices 3 - Add functionality to read device
 data from environment variable

2018-10-29  Jozef Lawrynowicz  

gcc/config/msp430/

	* driver-msp430.c (msp430_select_hwmult_lib): Fix formatting.
	(msp430_get_linker_devices_include_path): New.
	* msp430-devices.c (msp430_dirname): New.
	(canonicalize_path_dirsep): New.
	(process_collect_gcc_into_devices_dir): New.
	(msp430_check_env_var_for_devices): New.
	(parse_devices_csv): Call msp430_check_env_var_for_devices after trying
	other methods.
	* msp430-devices.h (msp430_check_env_var_for_devices): New.
	(msp430_dirname): New.
	* msp430.c (msp430_register_pre_includes): New.
	* msp430.h (EXTRA_SPEC_FUNCTIONS): Add
	msp430_get_linker_devices_include_path.
	(LINK_SPEC): Likewise.
	Define TARGET_EXTRA_PRE_INCLUDES to msp430_register_pre_includes.

gcc/doc/

	* invoke.texi: Document that devices.csv is searched for using an
	environment variable and in a subdirectory of the toolchain
	installation.

gcc/testsuite/gcc.target/msp430/

	* devices/csv_using_env_var.c: New.
	* devices/csv_using_installed.c: New.
	* devices/csv_using_option.c: New.
	* msp430.exp (msp430_device_permutations_runtest): Prepare for
	csv_using_* tests as appropriate.
	(get_installed_device_data_path): New.
	(msp430_hide_installed_devices_data): New.
	(msp430_restore_installed_devices_data): New.
	(msp430_test_installed_device_data): New.
---
 gcc/config/msp430/driver-msp430.c  | 13 +++-
 gcc/config/msp430/msp430-devices.c | 88 +-
 gcc/config/msp430/msp430-devices.h |  2 +
 gcc/config/msp430/msp430.c | 16 
 gcc/config/msp430/msp430.h | 12 ++-
 gcc/doc/invoke.texi| 28 ++-
 .../gcc.target/msp430/devices/csv_using_env_var.c  | 10 +++
 .../msp430/devices/csv_using_installed.c   | 11 +++
 .../gcc.target/msp430/devices/csv_using_option.c   | 12 +++
 gcc/testsuite/gcc.target/msp430/msp430.exp | 70 -
 10 files changed, 255 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_using_env_var.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_using_installed.c
 create mode 100644 gcc/testsuite/gcc.target/msp430/devices/csv_using_option.c

diff --git a/gcc/config/msp430/driver-msp430.c b/gcc/config/msp430/driver-msp430.c
index 4242274..3facdc2 100644
--- a/gcc/config/msp430/driver-msp430.c
+++ b/gcc/config/msp430/driver-msp430.c
@@ -52,7 +52,8 @@ msp430_select_cpu (int argc, const char ** argv)
 /* Implement spec function `msp430_hwmult_lib´.  */
 
 const char *
-msp430_select_hwmult_lib (int argc ATTRIBUTE_UNUSED, const char ** argv ATTRIBUTE_UNUSED)
+msp430_select_hwmult_lib (int argc ATTRIBUTE_UNUSED,
+			  const char ** argv ATTRIBUTE_UNUSED)
 {
   int i;
 
@@ -116,3 +117,13 @@ msp430_select_hwmult_lib (int argc ATTRIBUTE_UNUSED, const char ** argv ATTRIBUT
   
   return "-lmul_none";
 }
+
+const char *
+msp430_get_linker_devices_include_path (int argc ATTRIBUTE_UNUSED,
+	const char **argv ATTRIBUTE_UNUSED)
+{
+  char *devices_csv_path;
+  if (msp430_check_env_var_for_devices (&devices_csv_path))
+return NULL;
+  return concat ("-L", msp430_dirname (devices_csv_path), NULL);
+}
diff --git a/gcc/config/msp430/msp430-devices.c b/gcc/config/msp430/msp430-devices.c
index 2f44861..c37f8dc 100644
--- a/gcc/config/msp430/msp430-devices.c
+++ b/gcc/config/msp430/msp430-devices.c
@@ -23,6 +23,88 @@ char * derived_devices_csv_loc = NULL;
 /* Set to true by msp430_extract_mcu_data if called from the driver.  */
 bool surpress_devices_warn = false;
 
+/* This modifies the string pointed to by path.  */
+char *
+msp430_dirname (char *path)
+{
+  int last_elem = strlen (path) - 1;
+  int i = last_elem - (IS_DIR_SEPARATOR (path[last_elem]) ? 1 : 0);
+  for (; i >= 0; i--)
+{
+  if (IS_DIR_SEPARATOR (path[i]))
+	{
+	  path[i] = '\0';
+	  return path;
+	}
+}
+  return path;
+}
+
+/* This is to canonicalize the path.  On Windows we can have a mix of forward
+   and backslashes which leads to issues following paths.  */
+static void
+canonicalize_path_dirsep (char **path)
+{
+  char *t_path = *path;
+  unsigned int i;
+  for (i = 0; i < strlen (t_path); i++)
+if (IS_DIR_SEPARATOR (t_path[i]))
+  t_path[i] = DIR_SEPARATOR;
+}
+
+static void
+process_collect_g

Re: [PATCH][rs6000] use index form addresses more often for ldbrx/stdbrx

2018-10-29 Thread Aaron Sawdey
On 10/27/18 12:52 PM, Segher Boessenkool wrote:
> Hi Aaron,
> 
> On Sat, Oct 27, 2018 at 11:20:01AM -0500, Aaron Sawdey wrote:
>> --- gcc/config/rs6000/rs6000.md  (revision 265393)
>> +++ gcc/config/rs6000/rs6000.md  (working copy)
>> @@ -2512,9 +2512,27 @@
>>if (TARGET_POWERPC64 && TARGET_LDBRX)
>>  {
>>if (MEM_P (src))
>> -emit_insn (gen_bswapdi2_load (dest, src));
>> +{
>> +  rtx addr = XEXP (src, 0);
>> +  if (!legitimate_indirect_address_p (addr, reload_completed)
>> +  && !legitimate_indexed_address_p (addr, reload_completed))
> 
> Should you use indexed_or_indirect operand instead here?
> 
>> +{
>> +  addr = force_reg (Pmode, addr);
>> +  src = replace_equiv_address_nv (src, addr);
>> +}
>> +  emit_insn (gen_bswapdi2_load (dest, src));
>> +}
> 
> You could maybe make this a utility routine as well (in rs6000.c)...
> Something like force_indexed_or_indirect_mem.  So this code will be just
> 
>   if (MEM_P (src))
>   force_indexed_or_indirect_mem (src);
> 
> then.
> 
> Could you try those things please?
> 
> 
> Segher
> 

Segher,
  Here's a patch restructured in that way.
OK for trunk if bootstrap/regtest passes?

Thanks!
   Aaron

2018-10-29  Aaron Sawdey  

* config/rs6000/rs6000.md (bswapdi2): Force address into register
if not in one already.
(bswapdi2_load): Change predicate to indexed_or_indirect_operand.
(bswapdi2_store): Ditto.
* config/rs6000/rs6000.c (rs6000_force_indexed_or_indirect_mem): New
helper function.
* config/rs6000/rs6000-protos.h (rs6000_force_indexed_or_indirect_mem):
Prototype for helper function.



Index: gcc/config/rs6000/rs6000-protos.h
===
--- gcc/config/rs6000/rs6000-protos.h   (revision 265588)
+++ gcc/config/rs6000/rs6000-protos.h   (working copy)
@@ -47,6 +47,7 @@
 extern bool legitimate_indirect_address_p (rtx, int);
 extern bool legitimate_indexed_address_p (rtx, int);
 extern bool avoiding_indexed_address_p (machine_mode);
+extern void rs6000_force_indexed_or_indirect_mem (rtx x);

 extern rtx rs6000_got_register (rtx);
 extern rtx find_addr_reg (rtx);
Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 265588)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -8423,7 +8423,22 @@
   return false;
 }

+/* Helper function for making sure we will make full
+   use of indexed addressing.  */

+void
+rs6000_force_indexed_or_indirect_mem (rtx x)
+{
+  rtx addr = XEXP (x, 0);
+  machine_mode m = GET_MODE (x);
+  if (!indexed_or_indirect_operand (x, m))
+{
+  addr = force_reg (Pmode, addr);
+  x = replace_equiv_address_nv (x, addr);
+}
+}
+
+
 /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook.  */

 static bool
Index: gcc/config/rs6000/rs6000.md
===
--- gcc/config/rs6000/rs6000.md (revision 265588)
+++ gcc/config/rs6000/rs6000.md (working copy)
@@ -2512,9 +2512,15 @@
   if (TARGET_POWERPC64 && TARGET_LDBRX)
 {
   if (MEM_P (src))
-   emit_insn (gen_bswapdi2_load (dest, src));
+{
+ rs6000_force_indexed_or_indirect_mem (src);
+ emit_insn (gen_bswapdi2_load (dest, src));
+}
   else if (MEM_P (dest))
-   emit_insn (gen_bswapdi2_store (dest, src));
+{
+ rs6000_force_indexed_or_indirect_mem (dest);
+ emit_insn (gen_bswapdi2_store (dest, src));
+}
   else if (TARGET_P9_VECTOR)
emit_insn (gen_bswapdi2_xxbrd (dest, src));
   else
@@ -2535,13 +2541,13 @@
 ;; Power7/cell has ldbrx/stdbrx, so use it directly
 (define_insn "bswapdi2_load"
   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
-   (bswap:DI (match_operand:DI 1 "memory_operand" "Z")))]
+   (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "Z")))]
   "TARGET_POWERPC64 && TARGET_LDBRX"
   "ldbrx %0,%y1"
   [(set_attr "type" "load")])

 (define_insn "bswapdi2_store"
-  [(set (match_operand:DI 0 "memory_operand" "=Z")
+  [(set (match_operand:DI 0 "indexed_or_indirect_operand" "=Z")
(bswap:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
   "TARGET_POWERPC64 && TARGET_LDBRX"
   "stdbrx %1,%y0"



-- 
Aaron Sawdey, Ph.D.  acsaw...@linux.vnet.ibm.com
050-2/C113  (507) 253-7520 home: 507/263-0782
IBM Linux Technology Center - PPC Toolchain



Re: [PATCH] Fix PR87785

2018-10-29 Thread Richard Biener
On Mon, 29 Oct 2018, Richard Biener wrote:

> 
> The following fixes gone missing load nodes with the SLP tree build
> now eventually caching them but not having them in the SLP tree.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

SPEC testing reveals a thinko...

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Richard.

2018-10-29  Richard Biener  

* tree-vect-slp.c (vect_gather_slp_loads): Only gather
internal defs.

    * gcc.dg/torture/20181029-1.c: New testcase.

Index: gcc/tree-vect-slp.c
===
--- gcc/tree-vect-slp.c (revision 265593)
+++ gcc/tree-vect-slp.c (working copy)
@@ -1645,7 +1645,8 @@ vect_gather_slp_loads (slp_instance inst
   if (SLP_TREE_CHILDREN (node).length () == 0)
 {
   stmt_vec_info stmt_info = SLP_TREE_SCALAR_STMTS (node)[0];
-  if (STMT_VINFO_GROUPED_ACCESS (stmt_info)
+  if (SLP_TREE_DEF_TYPE (node) == vect_internal_def
+ && STMT_VINFO_GROUPED_ACCESS (stmt_info)
  && DR_IS_READ (STMT_VINFO_DATA_REF (stmt_info)))
SLP_INSTANCE_LOADS (inst).safe_push (node);
 }
Index: gcc/testsuite/gcc.dg/torture/20181029-1.c
===
--- gcc/testsuite/gcc.dg/torture/20181029-1.c   (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/20181029-1.c   (working copy)
@@ -0,0 +1,81 @@
+/* { dg-do compile } */
+
+typedef __SIZE_TYPE__ size_t;
+typedef unsigned long UV;
+typedef size_t STRLEN;
+typedef struct sv SV;
+typedef struct magic MAGIC;
+typedef struct xpv XPV;
+typedef unsigned char U8;
+typedef int I32;
+typedef unsigned int U32;
+struct sv {
+void* sv_any;
+U32 sv_flags;
+};
+struct xpv {
+char * xpv_pv;
+STRLEN xpv_cur;
+};
+struct magic {
+char* mg_ptr;
+};
+extern const unsigned char PL_utf8skip[];
+char *Perl_sv_2pv_flags (STRLEN *);
+void Perl_utf8n_to_uvuni (U8 *);
+void Perl_sv_magic (SV *);
+void Perl_sv_pos_b2u( register SV* sv, I32* offsetp, MAGIC *mg)
+{
+  U8* s;
+  STRLEN len;
+  s = (U8*)(((sv)->sv_flags & (0x0004)) == 0x0004
+   ? ((len = ((XPV*) (sv)->sv_any)->xpv_cur), ((XPV*) 
(sv)->sv_any)->xpv_pv)
+   : Perl_sv_2pv_flags(&len));
+  if ((I32)len < *offsetp)
+;
+  else
+{
+  STRLEN *cache = ((void *)0);
+  if (((sv)->sv_flags & (0x2000|0x4000|0x8000))
+ && !((sv)->sv_flags & 0x0080))
+   {
+ if (mg && mg->mg_ptr)
+   {
+ cache = (STRLEN *) mg->mg_ptr;
+ STRLEN forw = *offsetp;
+ STRLEN backw = cache[1] - *offsetp;
+ if (!(forw < 2 * backw))
+   {
+ U8 *p = s + cache[1];
+ STRLEN ubackw = 0;
+ cache[1] -= backw;
+ while (backw--)
+   {
+ p--;
+ while U8)*p) >= 0x80 && (((U8)*p) <= 0xbf)))
+   {
+ p--;
+ backw--;
+   }
+ ubackw++;
+   }
+ cache[0] -= ubackw;
+ *offsetp = cache[0];
+ cache[2] = 0;
+ cache[3] = 0;
+ return;
+   }
+   }
+ if (!(((UV)(*s)) < 0x80))
+   Perl_utf8n_to_uvuni(s);
+   }
+  if (!((sv)->sv_flags & 0x0080))
+   {
+ if (!mg)
+   Perl_sv_magic(sv);
+ cache[0] = len;
+ cache[1] = *offsetp;
+   }
+  *offsetp = len;
+}
+}


Re: [PATCH][RFC] Sanitize equals and hash functions in hash-tables.

2018-10-29 Thread Martin Liška
On 10/29/18 2:53 PM, Alexander Monakov wrote:
> On Mon, 29 Oct 2018, Martin Liška wrote:
>> My question is whether we want to have in GCC 9 time frame or should I wait 
>> with that?
>> Does it worth implementing?
> 
> This is cool, thanks! A few questions/comments on the patch.

Hi.

Thanks for support.

> 
> I think there are places that use libiberty C-style hashtab (htab_t), would it
> make sense to have this kind of checking for them as well?  I think it's going
> to be more complicated though, no need to do both in one step.

Sure, that can be also added in the future!

> 
> I would recommend to factor out the error reporting path into a separate
> non-template function, e.g. hashtab_chk_error.  See how qsort_chk_error
> has "cold" and "noreturn" attributes and invokes problematic comparators:
> the idea was that a developer can 'break qsort_chk_error' in GDB and then
> easily step into broken comparators.

I did so.

> 
> Furthermore, it might be nice to investigate if the entire checking loop can
> be factored out somehow into a non-template function to avoid having multiple
> instantiations of it for different hashtable template parameters.

Note that Jakub is preferring to enable the checking only in non-release builds.
Thus I've guarded the checking with #if ENABLE_EXTRA_CHECKING. That said I won't
care much about saving a binary size.

The checking function is dependent on template arguments, so the avoidance is 
probably
not possible.

> 
> On my first attempt to submit qsort_chk, Richi asked how much it slows down
> stage2, do you have some data on the cost of this hashtable checking?

It does not survive bootstrap right now (too many cselib_find_slot failures).

> 
> I think it is possible to optimize this a bit: instead of checking on
> insertions, check on deletions and when destroying the table (with care to do
> n^2/2 rather than n^2 tests). Although, such approach would miss errors on
> hashtables that are never destroyed (leaked or deliberately not deleted).

Interesting idea. Benefit of the current approach is that the ICE is triggered
as soon as first bad element is inserted into a hast table. Which means it's 
easier
to debug. One problem with the destruction is that one equals function is 
defined on:
Descriptor::equal (Descriptor::value_type, Descriptor::compare_type). One can 
have
a table where these are not equal and so that equals can't be called.

Martin

> 
> Alexander
> 

>From 9afc42d324820cc0fc8a8a8b2d9cccd218734d10 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 29 Oct 2018 09:38:21 +0100
Subject: [PATCH] Sanitize equals and hash functions in hash-tables.

---
 gcc/hash-table.h | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index bd83345c7b8..43adfac2dc0 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -503,6 +503,7 @@ private:
 
   value_type *alloc_entries (size_t n CXX_MEM_STAT_INFO) const;
   value_type *find_empty_slot_for_expand (hashval_t);
+  void verify (const compare_type &comparable, hashval_t hash);
   bool too_empty_p (unsigned int);
   void expand ();
   static bool is_deleted (value_type &v)
@@ -882,8 +883,12 @@ hash_table
   if (insert == INSERT && m_size * 3 <= m_n_elements * 4)
 expand ();
 
-  m_searches++;
+#if ENABLE_EXTRA_CHECKING
+if (insert == INSERT)
+  verify (comparable, hash);
+#endif
 
+  m_searches++;
   value_type *first_deleted_slot = NULL;
   hashval_t index = hash_table_mod1 (hash, m_size_prime_index);
   hashval_t hash2 = hash_table_mod2 (hash, m_size_prime_index);
@@ -930,6 +935,39 @@ hash_table
   return &m_entries[index];
 }
 
+#if ENABLE_EXTRA_CHECKING
+
+/* Report a hash table checking error.  */
+
+ATTRIBUTE_NORETURN ATTRIBUTE_COLD
+static void
+hashtab_chk_error ()
+{
+  fprintf (stderr, "hash table checking failed: "
+	   "equal operator returns true for a pair "
+	   "of values with a different hash value");
+  gcc_unreachable ();
+}
+
+/* Verify that all existing elements in th hash table which are
+   equal to COMPARABLE have an equal HASH value provided as argument.  */
+
+template class Allocator>
+void
+hash_table
+::verify (const compare_type &comparable, hashval_t hash)
+{
+  for (size_t i = 0; i < m_size; i++)
+{
+  value_type *entry = &m_entries[i];
+  if (!is_empty (*entry) && !is_deleted (*entry)
+	  && Descriptor::equal (*entry, comparable)
+	  && hash != Descriptor::hash (*entry))
+	hashtab_chk_error ();
+}
+}
+#endif
+
 /* This function deletes an element with the given COMPARABLE value
from hash table starting with the given HASH.  If there is no
matching element in the hash table, this function does nothing. */
-- 
2.19.0



Re: [PATCH] libgcc: properly destroy mutexes on VxWorks

2018-10-29 Thread Olivier Hainque
Hi Rasmus,

> On 29 Oct 2018, at 14:32, Rasmus Villemoes  wrote:
> 
> Just as one needs run-time initialization of mutexes, one needs to
> destroy them properly to allow the OS to release resources associated
> with the semaphore.
> 
> ==changelog==
> 
> libgcc/
> 
>   * config/gthr-vxworks.h (__gthread_mutex_destroy): Call semDelete.

Looks good at first sight. Let me give it a try
on an ongoing port.





Re: [PATCH] Fix PR87785

2018-10-29 Thread Martin Liška
On 10/29/18 4:02 PM, Richard Biener wrote:
> On Mon, 29 Oct 2018, Richard Biener wrote:
> 
>>
>> The following fixes gone missing load nodes with the SLP tree build
>> now eventually caching them but not having them in the SLP tree.
>>
>> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
> 
> SPEC testing reveals a thinko...

If you mean following ICE:

during GIMPLE pass: slp
i.c: In function ‘f’:
i.c:5:6: internal compiler error: in vect_get_place_in_interleaving_chain, at 
tree-vect-slp.c:212
5 | void f() {
  |  ^
0x1579899 vect_get_place_in_interleaving_chain(_stmt_vec_info*, _stmt_vec_info*)
/home/marxin/Programming/gcc/gcc/tree-vect-slp.c:212
0x157fe0a vect_analyze_slp_instance
/home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2020
0x1580680 vect_analyze_slp(vec_info*, unsigned int)
/home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2158
0x15829df vect_slp_analyze_bb_1
/home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2861
0x1583236 vect_slp_bb(basic_block_def*)
/home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2995
0x1590031 execute
/home/marxin/Programming/gcc/gcc/tree-vectorizer.c:1291

then the test-case can be simplified into:

$ cat i.c
int a, b;
unsigned long c;
unsigned long *d;
void e();
void f() {
  if (c) {
if (a) {
  e();
  d[0] = c;
  d[1] = b;
}
b = c;
  }
}

Martin

> 
> Bootstrap & regtest running on x86_64-unknown-linux-gnu.
> 
> Richard.
> 
> 2018-10-29  Richard Biener  
> 
> * tree-vect-slp.c (vect_gather_slp_loads): Only gather
> internal defs.
> 
> * gcc.dg/torture/20181029-1.c: New testcase.
> 
> Index: gcc/tree-vect-slp.c
> ===
> --- gcc/tree-vect-slp.c   (revision 265593)
> +++ gcc/tree-vect-slp.c   (working copy)
> @@ -1645,7 +1645,8 @@ vect_gather_slp_loads (slp_instance inst
>if (SLP_TREE_CHILDREN (node).length () == 0)
>  {
>stmt_vec_info stmt_info = SLP_TREE_SCALAR_STMTS (node)[0];
> -  if (STMT_VINFO_GROUPED_ACCESS (stmt_info)
> +  if (SLP_TREE_DEF_TYPE (node) == vect_internal_def
> +   && STMT_VINFO_GROUPED_ACCESS (stmt_info)
> && DR_IS_READ (STMT_VINFO_DATA_REF (stmt_info)))
>   SLP_INSTANCE_LOADS (inst).safe_push (node);
>  }
> Index: gcc/testsuite/gcc.dg/torture/20181029-1.c
> ===
> --- gcc/testsuite/gcc.dg/torture/20181029-1.c (nonexistent)
> +++ gcc/testsuite/gcc.dg/torture/20181029-1.c (working copy)
> @@ -0,0 +1,81 @@
> +/* { dg-do compile } */
> +
> +typedef __SIZE_TYPE__ size_t;
> +typedef unsigned long UV;
> +typedef size_t STRLEN;
> +typedef struct sv SV;
> +typedef struct magic MAGIC;
> +typedef struct xpv XPV;
> +typedef unsigned char U8;
> +typedef int I32;
> +typedef unsigned int U32;
> +struct sv {
> +void* sv_any;
> +U32 sv_flags;
> +};
> +struct xpv {
> +char * xpv_pv;
> +STRLEN xpv_cur;
> +};
> +struct magic {
> +char* mg_ptr;
> +};
> +extern const unsigned char PL_utf8skip[];
> +char *Perl_sv_2pv_flags (STRLEN *);
> +void Perl_utf8n_to_uvuni (U8 *);
> +void Perl_sv_magic (SV *);
> +void Perl_sv_pos_b2u( register SV* sv, I32* offsetp, MAGIC *mg)
> +{
> +  U8* s;
> +  STRLEN len;
> +  s = (U8*)(((sv)->sv_flags & (0x0004)) == 0x0004
> + ? ((len = ((XPV*) (sv)->sv_any)->xpv_cur), ((XPV*) 
> (sv)->sv_any)->xpv_pv)
> + : Perl_sv_2pv_flags(&len));
> +  if ((I32)len < *offsetp)
> +;
> +  else
> +{
> +  STRLEN *cache = ((void *)0);
> +  if (((sv)->sv_flags & (0x2000|0x4000|0x8000))
> +   && !((sv)->sv_flags & 0x0080))
> + {
> +   if (mg && mg->mg_ptr)
> + {
> +   cache = (STRLEN *) mg->mg_ptr;
> +   STRLEN forw = *offsetp;
> +   STRLEN backw = cache[1] - *offsetp;
> +   if (!(forw < 2 * backw))
> + {
> +   U8 *p = s + cache[1];
> +   STRLEN ubackw = 0;
> +   cache[1] -= backw;
> +   while (backw--)
> + {
> +   p--;
> +   while U8)*p) >= 0x80 && (((U8)*p) <= 0xbf)))
> + {
> +   p--;
> +   backw--;
> + }
> +   ubackw++;
> + }
> +   cache[0] -= ubackw;
> +   *offsetp = cache[0];
> +   cache[2] = 0;
> +   cache[3] = 0;
> +   return;
> + }
> + }
> +   if (!(((UV)(*s)) < 0x80))
> + Perl_utf8n_to_uvuni(s);
> + }
> +  if (!((sv)->sv_flags & 0x0080))
> + {
> +   if (!mg)
> + Perl_sv_magic(sv);
> +   cache[0] = len;
> +   cache[1] = *offsetp;
> + }
> +  *offsetp = len;
> +}
> +}
> 



Re: [PATCH 0/7] libsanitizer: merge from trunk

2018-10-29 Thread Michael Matz
Hi,

On Mon, 29 Oct 2018, Bill Seurer wrote:

> >> Just for the record: am I right that any system using 44 bit of VMA will
> >> fail because
> >> anything + (1 << 44) will be out of process address space?
> > 
> > Yes.
> > 
> >> And I noticed that documentation in sanitizer_linux.cc is misleading:
> >>
> >> ...
> >> uptr GetMaxVirtualAddress() {
> >> #if (SANITIZER_NETBSD || SANITIZER_OPENBSD) && defined(__x86_64__)
> >>return 0x7f7ff000ULL;  // (0x7f80 - PAGE_SIZE)
> >> #elif SANITIZER_WORDSIZE == 64
> >> # if defined(__powerpc64__) || defined(__aarch64__)
> >>// On PowerPC64 we have two different address space layouts: 44- and
> >>46-bit.
> >>// We somehow need to figure out which one we are using now and choose
> >>// one of 0x0fffUL and 0x3fffUL.
> >> ...
> >>
> >> That should be adjusted.
> > 
> > Apparently for ppc64 there are many different layouts now, 44, 46, 47, 49,
> > 52
> > at least depending on which kernel and page size you choose.
> > So, ideally we want some choice that works with all of them.  Shadow offset
> > 1ULL<<44 is not that choice.
> 
> We (llvm team) tried to get it to work on all the different kernels but didn't
> find anything that worked.  Finally we just went with a value that worked on
> the newer kernels as the 44 bit one was not a target of concern.

I'm still wondering what didn't work with 41 bits?  AFAICS, due to 
highshadow=highmem-offset and lowshadow=low+offset, and the existence of a 
non-empty shadow-gap, offset must be minimum(vbits)-3 (vbits being one of 
the above numbers).  Why would 41 not work for the other vbit setting?  
It would lead to a large shadow gap, but so?  If a shadow-gap isn't 
necessary then minimum(vbits)-2 would also work.


Ciao,
Michael.


Re: [PATCH] Fix PR87785

2018-10-29 Thread Richard Biener
On Mon, 29 Oct 2018, Martin Liška wrote:

> On 10/29/18 4:02 PM, Richard Biener wrote:
> > On Mon, 29 Oct 2018, Richard Biener wrote:
> > 
> >>
> >> The following fixes gone missing load nodes with the SLP tree build
> >> now eventually caching them but not having them in the SLP tree.
> >>
> >> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
> > 
> > SPEC testing reveals a thinko...
> 
> If you mean following ICE:
> 
> during GIMPLE pass: slp
> i.c: In function ‘f’:
> i.c:5:6: internal compiler error: in vect_get_place_in_interleaving_chain, at 
> tree-vect-slp.c:212
> 5 | void f() {
>   |  ^
> 0x1579899 vect_get_place_in_interleaving_chain(_stmt_vec_info*, 
> _stmt_vec_info*)
>   /home/marxin/Programming/gcc/gcc/tree-vect-slp.c:212
> 0x157fe0a vect_analyze_slp_instance
>   /home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2020
> 0x1580680 vect_analyze_slp(vec_info*, unsigned int)
>   /home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2158
> 0x15829df vect_slp_analyze_bb_1
>   /home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2861
> 0x1583236 vect_slp_bb(basic_block_def*)
>   /home/marxin/Programming/gcc/gcc/tree-vect-slp.c:2995
> 0x1590031 execute
>   /home/marxin/Programming/gcc/gcc/tree-vectorizer.c:1291
> 
> then the test-case can be simplified into:

Yes.

> $ cat i.c
> int a, b;
> unsigned long c;
> unsigned long *d;
> void e();
> void f() {
>   if (c) {
> if (a) {
>   e();
>   d[0] = c;
>   d[1] = b;
> }
> b = c;
>   }
> }

Thanks,
Richard.

> Martin
> 
> > 
> > Bootstrap & regtest running on x86_64-unknown-linux-gnu.
> > 
> > Richard.
> > 
> > 2018-10-29  Richard Biener  
> > 
> > * tree-vect-slp.c (vect_gather_slp_loads): Only gather
> > internal defs.
> > 
> > * gcc.dg/torture/20181029-1.c: New testcase.
> > 
> > Index: gcc/tree-vect-slp.c
> > ===
> > --- gcc/tree-vect-slp.c (revision 265593)
> > +++ gcc/tree-vect-slp.c (working copy)
> > @@ -1645,7 +1645,8 @@ vect_gather_slp_loads (slp_instance inst
> >if (SLP_TREE_CHILDREN (node).length () == 0)
> >  {
> >stmt_vec_info stmt_info = SLP_TREE_SCALAR_STMTS (node)[0];
> > -  if (STMT_VINFO_GROUPED_ACCESS (stmt_info)
> > +  if (SLP_TREE_DEF_TYPE (node) == vect_internal_def
> > + && STMT_VINFO_GROUPED_ACCESS (stmt_info)
> >   && DR_IS_READ (STMT_VINFO_DATA_REF (stmt_info)))
> > SLP_INSTANCE_LOADS (inst).safe_push (node);
> >  }
> > Index: gcc/testsuite/gcc.dg/torture/20181029-1.c
> > ===
> > --- gcc/testsuite/gcc.dg/torture/20181029-1.c   (nonexistent)
> > +++ gcc/testsuite/gcc.dg/torture/20181029-1.c   (working copy)
> > @@ -0,0 +1,81 @@
> > +/* { dg-do compile } */
> > +
> > +typedef __SIZE_TYPE__ size_t;
> > +typedef unsigned long UV;
> > +typedef size_t STRLEN;
> > +typedef struct sv SV;
> > +typedef struct magic MAGIC;
> > +typedef struct xpv XPV;
> > +typedef unsigned char U8;
> > +typedef int I32;
> > +typedef unsigned int U32;
> > +struct sv {
> > +void* sv_any;
> > +U32 sv_flags;
> > +};
> > +struct xpv {
> > +char * xpv_pv;
> > +STRLEN xpv_cur;
> > +};
> > +struct magic {
> > +char* mg_ptr;
> > +};
> > +extern const unsigned char PL_utf8skip[];
> > +char *Perl_sv_2pv_flags (STRLEN *);
> > +void Perl_utf8n_to_uvuni (U8 *);
> > +void Perl_sv_magic (SV *);
> > +void Perl_sv_pos_b2u( register SV* sv, I32* offsetp, MAGIC *mg)
> > +{
> > +  U8* s;
> > +  STRLEN len;
> > +  s = (U8*)(((sv)->sv_flags & (0x0004)) == 0x0004
> > +   ? ((len = ((XPV*) (sv)->sv_any)->xpv_cur), ((XPV*) 
> > (sv)->sv_any)->xpv_pv)
> > +   : Perl_sv_2pv_flags(&len));
> > +  if ((I32)len < *offsetp)
> > +;
> > +  else
> > +{
> > +  STRLEN *cache = ((void *)0);
> > +  if (((sv)->sv_flags & (0x2000|0x4000|0x8000))
> > + && !((sv)->sv_flags & 0x0080))
> > +   {
> > + if (mg && mg->mg_ptr)
> > +   {
> > + cache = (STRLEN *) mg->mg_ptr;
> > + STRLEN forw = *offsetp;
> > + STRLEN backw = cache[1] - *offsetp;
> > + if (!(forw < 2 * backw))
> 

Re: [PATCH 0/7] libsanitizer: merge from trunk

2018-10-29 Thread Bill Seurer

On 10/29/18 10:26, Michael Matz wrote:

Hi,

On Mon, 29 Oct 2018, Bill Seurer wrote:


Just for the record: am I right that any system using 44 bit of VMA will
fail because
anything + (1 << 44) will be out of process address space?


Yes.


And I noticed that documentation in sanitizer_linux.cc is misleading:

...
uptr GetMaxVirtualAddress() {
#if (SANITIZER_NETBSD || SANITIZER_OPENBSD) && defined(__x86_64__)
return 0x7f7ff000ULL;  // (0x7f80 - PAGE_SIZE)
#elif SANITIZER_WORDSIZE == 64
# if defined(__powerpc64__) || defined(__aarch64__)
// On PowerPC64 we have two different address space layouts: 44- and
46-bit.
// We somehow need to figure out which one we are using now and choose
// one of 0x0fffUL and 0x3fffUL.
...

That should be adjusted.


Apparently for ppc64 there are many different layouts now, 44, 46, 47, 49,
52
at least depending on which kernel and page size you choose.
So, ideally we want some choice that works with all of them.  Shadow offset
1ULL<<44 is not that choice.


We (llvm team) tried to get it to work on all the different kernels but didn't
find anything that worked.  Finally we just went with a value that worked on
the newer kernels as the 44 bit one was not a target of concern.


I'm still wondering what didn't work with 41 bits?  AFAICS, due to
highshadow=highmem-offset and lowshadow=low+offset, and the existence of a
non-empty shadow-gap, offset must be minimum(vbits)-3 (vbits being one of
the above numbers).  Why would 41 not work for the other vbit setting?
It would lead to a large shadow gap, but so?  If a shadow-gap isn't
necessary then minimum(vbits)-2 would also work.


41 was what the value previously was and it did not work (IIRC with 47 
bit VMA kernels which were "new" at the time) thus the change.


If someone comes up with something that they think will work I am 
willing to test it with both llvm and gcc.

--

-Bill Seurer



Re: [PATCH] combine: Fix various shortcomings in make_more_copies (PR87701, PR87780)

2018-10-29 Thread Jeff Law
On 10/29/18 1:49 AM, Segher Boessenkool wrote:
> On Mon, Oct 29, 2018 at 12:31:28AM -0700, Andrew Pinski wrote:
>>> PR rtl-optimization/87701
>>> PR rtl-optimization/87780
>>> * combine.c (make_more_copies): Rewrite.
>>
>> I think a better changelog would be :):
>> * combine.c (make_more_copies): Rewrite to be simplier.
> 
> But it is not simpler at all now: *not* removing old notes while changing
> RTL instructions is a very bad idea often; and modifying instructions
> while not being very careful upsets DF.  It may *look* simple now ;-)
FWIW, it looks like cr16 ran to completion this morning :-)

Jeff


Re: [PATCH 0/7] libsanitizer: merge from trunk

2018-10-29 Thread Jakub Jelinek
On Mon, Oct 29, 2018 at 10:38:11AM -0500, Bill Seurer wrote:
> > I'm still wondering what didn't work with 41 bits?  AFAICS, due to
> > highshadow=highmem-offset and lowshadow=low+offset, and the existence of a
> > non-empty shadow-gap, offset must be minimum(vbits)-3 (vbits being one of
> > the above numbers).  Why would 41 not work for the other vbit setting?
> > It would lead to a large shadow gap, but so?  If a shadow-gap isn't
> > necessary then minimum(vbits)-2 would also work.
> 
> 41 was what the value previously was and it did not work (IIRC with 47 bit
> VMA kernels which were "new" at the time) thus the change.

What we'd like to see is details or URL with those why it didn't work with
47 bit.  E.g. x86_64 uses much lower shadow offset (0x7fff8000), asan has
support for multiple shadow areas, gaps and normal areas.
I think ppc64 binaries are usually using 0x1000 base, so that isn't a
problem, so is there a conflict with the default dynamic linker placement or
default placement of shared libraries when using the 47-bit VMA?
What do you get with the 41-bit shadow offset and ASAN_OPTIONS=verbosity=1
on 47-bit VMA that e.g. kMidMemBeg/kMidMemEnd couldn't solve?

Jakub


Re: [

2018-10-29 Thread graham stott via gcc-patches
Looks like it fixed an GO Libs failure as well I was having

 Original message 
From: Jeff Law  
Date: 29/10/2018  15:56  (GMT+00:00) 
To: Segher Boessenkool , Andrew Pinski 
 
Cc: GCC Patches  
Subject: Re: [ 

On 10/29/18 1:49 AM, Segher Boessenkool wrote:
> On Mon, Oct 29, 2018 at 12:31:28AM -0700, Andrew Pinski wrote:
>>> PR rtl-optimization/87701
>>> PR rtl-optimization/87780
>>> * combine.c (make_more_copies): Rewrite.
>>
>> I think a better changelog would be :):
>> * combine.c (make_more_copies): Rewrite to be simplier.
> 
> But it is not simpler at all now: *not* removing old notes while changing
> RTL instructions is a very bad idea often; and modifying instructions
> while not being very careful upsets DF.  It may *look* simple now ;-)
FWIW, it looks like cr16 ran to completion this morning :-)

Jeff


Re: [PATCH v3 3/3] or1k: gcc: initial support for openrisc

2018-10-29 Thread Segher Boessenkool
On Mon, Oct 29, 2018 at 10:34:25PM +0900, Stafford Horne wrote:
> On Sun, Oct 28, 2018 at 11:16:13PM +, Richard Henderson wrote:
> > On 10/28/18 2:57 AM, Segher Boessenkool wrote:
> > > Is this correct?  Should this be unsigned (u16 and K)?
> > 
> > No, l.xori is signed.
> 
> Right, sorry, I didn't have enough time to look at this at all this morning.  
> It
> is correct.
> 
> It looks like the documentation for this page [1] is generated from the cgen 
> cpu
> descriptions that were removed from binutils-gdb back in 2014.  Ccing cgen who
> seem to maintain this web page.  How can we go about getting it regenerated?

Is there some better documentation available?  This is what google found
for me.  I would have like better docs (more compact, etc.)  Links to
such would be great to have in readings.html :-)


Segher


Re: [PATCH v3 3/3] or1k: gcc: initial support for openrisc

2018-10-29 Thread Richard Henderson
On 10/29/18 4:34 PM, Segher Boessenkool wrote:
> Is there some better documentation available?  This is what google found
> for me.  I would have like better docs (more compact, etc.)  Links to
> such would be great to have in readings.html :-)

https://openrisc.io/architecture

and especially the v1.2 pdf linked from there

https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.2-rev0.pdf


r~


Re: [PATCH v4] Avoid unnecessarily numbering cloned symbols.

2018-10-29 Thread Michael Ploujnikov

On 2018-10-29 6:49 a.m., Martin Liška wrote:
> On 10/29/18 9:40 AM, Martin Liška wrote:
>> On 10/27/18 6:15 PM, Michael Ploujnikov wrote:
>>> Hi,
>>>
>>> On 2018-10-26 10:25 a.m., Jan Hubicka wrote:
> From aea94273e7a477a03d1ee10a5d9043d6d13b8e8d Mon Sep 17 00:00:00 2001
> From: Michael Ploujnikov 
> Date: Thu, 25 Oct 2018 13:16:36 -0400
> Subject: [PATCH] Avoid unnecessarily numbering cloned symbols.
>
> gcc/ChangeLog:
>
> 2018-10-26  Michael Ploujnikov  
>
>   * cgraph.h (clone_function_name_1): Replaced by new
> clone_function_name_numbered that takes name as string; for
> privatize_symbol_name_1 use only.
> (clone_function_name): Renamed to
> clone_function_name_numbered to be explicit about numbering.
> (clone_function_name): New two-argument function that does
> not number its output.
> (clone_function_name): New three-argument function that
> takes a number to append to its output.
>   * cgraphclones.c (duplicate_thunk_for_node):
> (clone_function_name_1): Renamed.
> (clone_function_name_numbered): Two new functions.
> (clone_function_name): Improved documentation.
> (cgraph_node::create_virtual_clone): Use clone_function_name_numbered.
>   * config/rs6000/rs6000.c (make_resolver_func): Ditto.
>   * final.c (final_scan_insn_1): Use the new clone_function_name
> without numbering.
>   * multiple_target.c (create_dispatcher_calls): Ditto.
> (create_target_clone): Ditto.
>   * omp-expand.c (grid_expand_target_grid_body): Ditto.
>   * omp-low.c (create_omp_child_function_name): Ditto.
>   * omp-simd-clone.c (simd_clone_create): Ditto.
>   * symtab.c (simd_symtab_node::noninterposable_alias): Use the
> new clone_function_name without numbering.
>
> gcc/lto/ChangeLog:
>
> 2018-10-26  Michael Ploujnikov  
>
>   * lto-partition.c (privatize_symbol_name_1): Use
> clone_function_name_numbered.
>
> gcc/testsuite/ChangeLog:
>
> 2018-10-26  Michael Ploujnikov  
>
>   * gcc.dg/tree-prof/cold_partition_label.c: Update for cold
> section names without numbers.
>   * gcc.dg/tree-prof/section-attr-1.c: Ditto.
>   * gcc.dg/tree-prof/section-attr-2.c: Ditto.
>   * gcc.dg/tree-prof/section-attr-3.c: Ditto.

 OK,
 thanks!
 Honza

>>>
>>> Thanks again for the review. This is my first patch and I don't have
>>> commit access. What should I do?
>>
>> I'm going to install the patch on your behalf. For write access you should
>> follow these intructions: 
>> https://www.gnu.org/software/gcc/svnwrite.html#policies
>>
>> Martin
>>
>>>
>>>
>>> - Michael
>>>
>>
> 
> But first I see some failures when I tried to apply the patch:
> 
> $ patch -p0 --dry-run < 
> ~/Downloads/0001-Avoid-unnecessarily-numbering-cloned-symbols.patch
> checking file gcc/cgraph.h
> Hunk #1 succeeded at 2382 with fuzz 1 (offset 14 lines).
> checking file gcc/cgraphclones.c
> Hunk #1 succeeded at 317 (offset 1 line).
> checking file gcc/config/rs6000/rs6000.c
> Hunk #1 succeeded at 36997 (offset 485 lines).
> checking file gcc/lto/lto-partition.c
> checking file gcc/multiple_target.c
> checking file gcc/omp-expand.c
> checking file gcc/omp-low.c
> checking file gcc/omp-simd-clone.c
> checking file gcc/testsuite/gcc.dg/tree-prof/cold_partition_label.c
> checking file gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c
> Hunk #1 FAILED at 42.
> 1 out of 1 hunk FAILED
> checking file gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c
> Hunk #1 FAILED at 41.
> 1 out of 1 hunk FAILED
> checking file gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c
> Hunk #1 FAILED at 42.
> 1 out of 1 hunk FAILED
> 
> Can you please rebase that on top of current trunk?
> Thanks,
> Martin
> 

Sorry about that. Attached is the fixed patch. Note that I'm currently unable 
to run
those particular section-attr tests to verify the correctness of the new 
scan-assembler
expressions.


Thanks for installing the patch while I figure out the SVN access.
- Michael
From 13d6c5446f807d8691ad2c554eda6fef26dc12b0 Mon Sep 17 00:00:00 2001
From: Michael Ploujnikov 
Date: Thu, 25 Oct 2018 13:16:36 -0400
Subject: [PATCH] Avoid unnecessarily numbering cloned symbols.

gcc/ChangeLog:

2018-10-26  Michael Ploujnikov  

	* cgraph.h (clone_function_name_1): Replaced by new
	  clone_function_name_numbered that takes name as string; for
	  privatize_symbol_name_1 use only.
	  (clone_function_name): Renamed to
	  clone_function_name_numbered to be explicit about numbering.
	  (clone_function_name): New two-argument function that does
	  not number its output.
	  (clone_function_name): New three-argument function that
	  takes a number to append to its output.
	* cgraphclones.c (duplicate_thunk_for_node):
	  (clone_function_name_1): Renamed.
	  (clone_function_name_numbered): Two new functions.
	  (clone_function_name): Improved do

Re: [PATCH] libgcc: properly destroy mutexes on VxWorks

2018-10-29 Thread Olivier Hainque



> On 29 Oct 2018, at 16:16, Olivier Hainque  wrote:
> 
> Hi Rasmus,
>> libgcc/
>> 
>>  * config/gthr-vxworks.h (__gthread_mutex_destroy): Call semDelete.
> 
> Looks good at first sight. Let me give it a try
> on an ongoing port.

Ok, thanks!



Re: [PATCH] Folding and check_function_arguments

2018-10-29 Thread Jason Merrill
On Mon, Oct 29, 2018 at 7:07 AM Alexander Monakov  wrote:
> On Thu, 25 Oct 2018, Jason Merrill wrote:
> > > >
> > > > Maybe we should remove that in favor of fold_for_warn in
> > > > check_function_arguments.
>
> David, I think your patch also fixes PR 86567.
>
> David, Jason, could you comment on doing something similar (using 
> fold_for_warn
> instead of maybe_constant_value) to solve other issues where generation of new
> tree uids under maybe_constant_value called in warning context changes code
> generation, in particular PR 86586?

I don't see how it would help; this change does the same folding, just
a bit later.

Jason


Jason


Re: [Patch, fortran] PR40196 - [F03] [F08] Type parameter inquiry (str%len, a%kind) and Complex parts (z%re, z%im)

2018-10-29 Thread Paul Richard Thomas
Hi Thomas,

Thanks for finding the assignment a%len = 2 that escapes the check for
lvalues. I am back home tomorrow night and will investigate why this
one evades the trap. I think that an error test is needed in
expr.c(gfc_check_assign).

Cheers

Paul

On Sun, 28 Oct 2018 at 13:38, Thomas Koenig  wrote:
>
> Hi Paul,
>
>
> >> inq would be easier to understand and unambiguous imho.
> >
> > Why? inquiry_type seems fine to me.
>
> I think Bernhard means the name of the member, i.
>
> I think it makes sense to leave as it is - gfc_ref is a
> struct that occurs a lot in complicated expressions, and the other
> members are one and two letters, too.
>
> > snip
> >> Is the switch really worth it? I'd have used a plain chain of strcmp,
> >> fwiw.
> >
> > I have done it. However, I might revert in order to combine the switch
> > block where I set the typespec for the primary expression.
>
> Whatever suits you best.
>
> > I haven't added testcases for errors. Does anybody think that this is 
> > necessary?
>
> Might not be a bad idea to run through at least each new error message
> again.
>
> There is one illwfL test case which ICEs:
>
> $ cat b.f90
> program main
>character(len=:), allocatable :: a
>allocate(a,source="abc")
>a%len = 2
>print *,a
> end
> $ gfortran b.f90
> gimplification failed:
> (integer(kind=4)) .a   type   size 
>  unit-size 
>  align:32 warn_if_not_align:0 symtab:0 alias-set -1
> canonical-type 0x7f138acd15e8 precision:32 min  0x7f138acbcd68 -2147483648> max 
>  pointer_to_this >
>
>  arg:0   type   size 
>  unit-size 
>  align:64 warn_if_not_align:0 symtab:0 alias-set -1
> canonical-type 0x7f138acd1738 precision:64 min  0x7f138acbcdf8 -9223372036854775808> max  9223372036854775807>
>  pointer_to_this >
>  used DI b.f90:1:0 size 
> unit-size 
>  align:64 warn_if_not_align:0 context  0x7f138ae83200 MAIN__>
>  chain 
>  used unsigned DI b.f90:2:0 size  64> unit-size 
>  align:64 warn_if_not_align:0 context  0x7f138ae83200 MAIN__
> b.f90:4:0:
>
>  4 |   a%len = 2
>|
> internal compiler error: gimplification failed
> 0xb45602 gimplify_expr(tree_node**, gimple**, gimple**, bool
> (*)(tree_node*), int)
>  ../../trunk/gcc/gimplify.c:12568
>
> Regards
>
> Thomas



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein


Re: C++ PATCH for c++/87594, constexpr rejects-valid with range-based for

2018-10-29 Thread Marek Polacek
On Wed, Oct 24, 2018 at 05:16:33PM -0400, Jason Merrill wrote:
> On 10/11/18 8:56 PM, Marek Polacek wrote:
> > Here potential_constant_expression_1 rejects the testcase because the body 
> > of
> > the for loop calls a non-constexpr function.  But the range is empty so the
> > function would never get called.
> > The trick with evaluating the for-condition doesn't work here, because we're
> > dealing with a converted range-based for and can't evaluate
> > 
> >__for_begin != __for_end
> > 
> > because the constexpr cache doesn't have the values of these two VAR_DECLs.
> 
> 
> > So either we can use this ugly hack (more specialized), or just not check 
> > the
> > body of the loop (more general), similarly to what we do (don't do) with
> > switch.
> > 
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > 
> > 2018-10-11  Marek Polacek  
> > 
> > PR c++/87594 - constexpr rejects-valid with range-based for.
> > * constexpr.c (potential_constant_expression_1) : Return
> > true for a converted ange-based for-statement.
> > 
> > * g++.dg/cpp1y/constexpr-loop8.C: New test.
> > 
> > diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
> > index 4fa8c965a9d..685ca743859 100644
> > --- gcc/cp/constexpr.c
> > +++ gcc/cp/constexpr.c
> > @@ -5827,6 +5827,17 @@ potential_constant_expression_1 (tree t, bool 
> > want_rval, bool strict, bool now,
> > tmp = cxx_eval_outermost_constant_expr (tmp, true);
> >   if (integer_zerop (tmp))
> > return true;
> > + /* See if this is
> > +__for_begin != __for_end
> > +cp_convert_range_for created for us.  If so, this is a converted
> > +range-based for-statement, and we're not able to evaluate this
> > +condition, so we might end up skipping the body entirely.  */
> > + else if (TREE_CODE (tmp) == NE_EXPR
> > +  && VAR_P (TREE_OPERAND (tmp, 0))
> > +  && DECL_NAME (TREE_OPERAND (tmp, 0)) == for_begin_identifier
> > +  && VAR_P (TREE_OPERAND (tmp, 1))
> > +  && DECL_NAME (TREE_OPERAND (tmp, 1)) == for_end_identifier)
> > +   return true;
> 
> This seems over-specific; any other condition we can't immediately evaluate
> also might not ever be true.  So I think we want to return here unless the
> condition is always true.  Likewise for WHILE_STMT.

Yeah, that makes a lot of sense.  Thus:

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-10-29  Marek Polacek  

PR c++/87594 - constexpr rejects-valid with range-based for.
* constexpr.c (potential_constant_expression_1): If the condition
can't be evaluated, return true.

* g++.dg/cpp1y/constexpr-loop8.C: New test.

diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 4fa8c965a9d..7692b1727da 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -5825,7 +5825,9 @@ potential_constant_expression_1 (tree t, bool want_rval, 
bool strict, bool now,
{
  if (!processing_template_decl)
tmp = cxx_eval_outermost_constant_expr (tmp, true);
- if (integer_zerop (tmp))
+ /* If we couldn't evaluate the condition, it might not ever be
+true.  */
+ if (!integer_onep (tmp))
return true;
}
   if (!RECUR (FOR_EXPR (t), any))
@@ -5853,7 +5855,8 @@ potential_constant_expression_1 (tree t, bool want_rval, 
bool strict, bool now,
return false;
   if (!processing_template_decl)
tmp = cxx_eval_outermost_constant_expr (tmp, true);
-  if (integer_zerop (tmp))
+  /* If we couldn't evaluate the condition, it might not ever be true.  */
+  if (!integer_onep (tmp))
return true;
   if (!RECUR (WHILE_BODY (t), any))
return false;
diff --git gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C 
gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C
index e69de29bb2d..bf132f2484e 100644
--- gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-loop8.C
@@ -0,0 +1,44 @@
+// PR c++/87594
+// { dg-do compile { target c++14 } }
+
+constexpr bool always_false() { return false; }
+int f() { return 1; }
+
+constexpr int
+fn1()
+{
+  struct empty_range {
+constexpr int* begin() { return 0; }
+constexpr int* end() { return 0; }
+  } e;
+  for (auto x : e)
+f();
+  return 0;
+}
+
+constexpr int
+fn2 ()
+{
+  int a[] = { 1, 2, 3 };
+  for (auto x : a)
+f(); // { dg-error "call to non-.constexpr. function" }
+  return 0;
+}
+
+constexpr int
+fn3 ()
+{
+  __extension__ int a[] = { };
+  for (auto x : a)
+f();
+  return 0;
+}
+
+
+void
+bar ()
+{
+  constexpr int i1 = fn1 ();
+  constexpr int i2 = fn2 (); // { dg-message "in .constexpr. expansion of " }
+  constexpr int i3 = fn3 ();
+}


Go patch committed: Add location_file method to Linemap

2018-10-29 Thread Ian Lance Taylor
This patch to the Go frontend adds a location_file method to Linemap,
adding support for getting the file name from a Location value.  This
will be used by later work.  This requires a patch to the interface
between the Go frontend and the rest of GCC.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

2018-10-29  Ian Lance Taylor  

* go-linemap.cc (Gcc_linemap::location_file): New method.
Index: gcc/go/go-linemap.cc
===
--- gcc/go/go-linemap.cc(revision 265460)
+++ gcc/go/go-linemap.cc(working copy)
@@ -34,6 +34,9 @@ class Gcc_linemap : public Linemap
   std::string
   to_string(Location);
 
+  std::string
+  location_file(Location);
+
   int
   location_line(Location);
 
@@ -93,7 +96,16 @@ Gcc_linemap::to_string(Location location
   return ss.str();
 }
 
-// Return the line number for a given location (for debugging dumps)
+// Return the file name for a given location.
+
+std::string
+Gcc_linemap::location_file(Location loc)
+{
+  return LOCATION_FILE(loc.gcc_location());
+}
+
+// Return the line number for a given location.
+
 int
 Gcc_linemap::location_line(Location loc)
 {
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 265541)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-8902fb43c569e4d3ec5bd143bfa8cb6bf2836780
+e4a421a01ad1fcc4315e530e79272604f3683051
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/go-linemap.h
===
--- gcc/go/gofrontend/go-linemap.h  (revision 265460)
+++ gcc/go/gofrontend/go-linemap.h  (working copy)
@@ -63,7 +63,11 @@ class Linemap
   virtual std::string
   to_string(Location) = 0;
 
-  // Return the line number for a given location (for debugging dumps)
+  // Return the file name for a given location.
+  virtual std::string
+  location_file(Location) = 0;
+
+  // Return the line number for a given location.
   virtual int
   location_line(Location) = 0;
 
@@ -140,7 +144,15 @@ class Linemap
 return Linemap::instance_->to_string(loc);
   }
 
-  // Return line number for location
+  // Return the file name of a location.
+  static std::string
+  location_to_file(Location loc)
+  {
+go_assert(Linemap::instance_ != NULL);
+return Linemap::instance_->location_file(loc);
+  }
+
+  // Return line number of a location.
   static int
   location_to_line(Location loc)
   {


Re: [PATCH] Folding and check_function_arguments

2018-10-29 Thread Alexander Monakov
On Mon, 29 Oct 2018, Jason Merrill wrote:

> On Mon, Oct 29, 2018 at 7:07 AM Alexander Monakov  wrote:
> > On Thu, 25 Oct 2018, Jason Merrill wrote:
> > > > >
> > > > > Maybe we should remove that in favor of fold_for_warn in
> > > > > check_function_arguments.
> >
> > David, I think your patch also fixes PR 86567.
> >
> > David, Jason, could you comment on doing something similar (using 
> > fold_for_warn
> > instead of maybe_constant_value) to solve other issues where generation of 
> > new
> > tree uids under maybe_constant_value called in warning context changes code
> > generation, in particular PR 86586?
> 
> I don't see how it would help; this change does the same folding, just
> a bit later.

If David's patch causes GCC to perform that folding only after main compilation
flow has already instantiated templates, that should help: folding for warning
wouldn't try to instantiate anything not already instantiated, and thus wouldn't
cause allocation of new uids, I think?

(I did check that it helps on the std::vector testcase given in the PR)

I see that my question about fold_for_warn doesn't make sense though.

Thanks.
Alexander


Re: [PATCH] S/390: Allow LARL of literal pool entries

2018-10-29 Thread Ulrich Weigand
Ilya Leoshkevich wrote:

> r265490 allowed the compiler to choose in a more flexible way whether to
> use load or load-address-relative-long (LARL) instruction.  When it
> chose LARL for literal pool references, the latter ones were rewritten
> by pass_s390_early_mach to use UNSPEC_LTREF, which assumes base register
> usage, which in turn is not compatible with LARL.  The end result was an
> ICE because of unrecognizable insn.
> 
> UNSPEC_LTREF and friends are necessary in order to communicate the
> dependency on the base register to pass_sched2.  When LARL is used, no
> base register is necessary, so in such cases the rewrite must be
> avoided.

This is true.  But something else must still be going on here.  Note that
many other instruction patterns might contain constant pool addresses,
since they are accepted e.g. by the 'b' constraint.  In all of those
cases, we shouldn't add the UNSPEC_LTREF.  So just checking for the
specific LARL instruction pattern in annotate_constant_pool_refs does
not feel like a correct fix here.

In fact, before r265490, the pattern for movdi_larl could also contain a
constant pool address, so why didn't the problem occur then?  What's the
difference whether this is part of movdi_larl or just movdi?

> @@ -8184,7 +8200,8 @@ annotate_constant_pool_refs (rtx *x)
> rtx addr = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, sym, base),
>UNSPEC_LTREF);
>  
> -   SET_SRC (*x) = plus_constant (Pmode, addr, off);
> +   SET_SRC (*x) = gen_rtx_CONST (Pmode,
> + plus_constant (Pmode, addr, off));

This looks like an unrelated change ... it seems incorrect to me, given
the UNSPEC_LTREF actually contains a register reference, so it shouldn't
really be CONST.  (And if it were, why make the change just here and not
everywhere a UNSPEC_LTREF is generated?)

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  ulrich.weig...@de.ibm.com



Go patch committed: Pass a single flags argument to Backend::function

2018-10-29 Thread Ian Lance Taylor
This patch changes the Go frontend to pass a single flags argument to
Backend::function, rather than a sequence of boolean variables.  This
requires a change to the interface between the Go frontend and the
rest of GCC.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

2018-10-29  Ian Lance Taylor  

* go-gcc.cc (Gcc_backend::function): Change to use a single flags
parameter.
Index: gcc/go/go-gcc.cc
===
--- gcc/go/go-gcc.cc(revision 265460)
+++ gcc/go/go-gcc.cc(working copy)
@@ -482,9 +482,7 @@ class Gcc_backend : public Backend
 
   Bfunction*
   function(Btype* fntype, const std::string& name, const std::string& asm_name,
-   bool is_visible, bool is_declaration, bool is_inlinable,
-   bool disable_split_stack, bool does_not_return,
-  bool in_unique_section, Location);
+  unsigned int flags, Location);
 
   Bstatement*
   function_defer_statement(Bfunction* function, Bexpression* undefer,
@@ -3047,10 +3045,8 @@ Gcc_backend::label_address(Blabel* label
 
 Bfunction*
 Gcc_backend::function(Btype* fntype, const std::string& name,
-  const std::string& asm_name, bool is_visible,
-  bool is_declaration, bool is_inlinable,
-  bool disable_split_stack, bool does_not_return,
- bool in_unique_section, Location location)
+  const std::string& asm_name, unsigned int flags,
+ Location location)
 {
   tree functype = fntype->get_tree();
   if (functype != error_mark_node)
@@ -3065,9 +3061,9 @@ Gcc_backend::function(Btype* fntype, con
   tree decl = build_decl(location.gcc_location(), FUNCTION_DECL, id, functype);
   if (! asm_name.empty())
 SET_DECL_ASSEMBLER_NAME(decl, get_identifier_from_string(asm_name));
-  if (is_visible)
+  if ((flags & function_is_visible) != 0)
 TREE_PUBLIC(decl) = 1;
-  if (is_declaration)
+  if ((flags & function_is_declaration) != 0)
 DECL_EXTERNAL(decl) = 1;
   else
 {
@@ -3079,16 +3075,16 @@ Gcc_backend::function(Btype* fntype, con
   DECL_CONTEXT(resdecl) = decl;
   DECL_RESULT(decl) = resdecl;
 }
-  if (!is_inlinable)
+  if ((flags & function_is_inlinable) == 0)
 DECL_UNINLINABLE(decl) = 1;
-  if (disable_split_stack)
+  if ((flags & function_no_split_stack) != 0)
 {
   tree attr = get_identifier ("no_split_stack");
   DECL_ATTRIBUTES(decl) = tree_cons(attr, NULL_TREE, NULL_TREE);
 }
-  if (does_not_return)
+  if ((flags & function_does_not_return) != 0)
 TREE_THIS_VOLATILE(decl) = 1;
-  if (in_unique_section)
+  if ((flags & function_in_unique_section) != 0)
 resolve_unique_section(decl, 0, 1);
 
   go_preserve_from_gc(decl);
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 265598)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-e4a421a01ad1fcc4315e530e79272604f3683051
+8dae05f57f3c8249319e3360b10f07dcc2cd57a7
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/backend.h
===
--- gcc/go/gofrontend/backend.h (revision 265460)
+++ gcc/go/gofrontend/backend.h (working copy)
@@ -699,26 +699,41 @@ class Backend
   virtual Bfunction*
   error_function() = 0;
 
+  // Bit flags to pass to the function method.
+
+  // Set if the function should be visible outside of the current
+  // compilation unit.
+  static const unsigned int function_is_visible = 1 << 0;
+
+  // Set if this is a function declaration rather than a definition;
+  // the definition will be in another compilation unit.
+  static const unsigned int function_is_declaration = 1 << 1;
+
+  // Set if the function can be inlined.  This is normally set, but is
+  // false for functions that may not be inlined because they call
+  // recover and must be visible for correct panic recovery.
+  static const unsigned int function_is_inlinable = 1 << 2;
+
+  // Set if the function may not split the stack.  This is set for the
+  // implementation of recover itself, among other things.
+  static const unsigned int function_no_split_stack = 1 << 3;
+
+  // Set if the function does not return.  This is set for the
+  // implementation of panic.
+  static const unsigned int function_does_not_return = 1 << 4;
+
+  // Set if the function should be put in a unique section if
+  // possible.  This is used for field tracking.
+  static const unsigned int function_in_unique_section = 1 << 5;
+
   // Declare or define a function of FNTYPE.
-  // NAME is the Go name of the function. ASM_NAME, if not the empty string, is
-  // the name that should be used in the symbol table; this will be non-empty 
if
-  // a magic extern comment is used.
-  // IS_VISIBLE is true if this function 

Re: [nvptx] vector length patch series

2018-10-29 Thread Cesar Philippidis
On 10/5/18 23:22, Tom de Vries wrote:
> On 9/18/18 10:04 PM, Cesar Philippidis wrote:
>> 591973d3c3a [nvptx] use user-defined vectors when possible
> 
> If I drop this patch, I get the same test results. Can you find a
> testcase for which this patch has an effect?

I just revisited the vector length patch series, and that patch in
specific is bogus and can be safely dropped.

>From what I can remember, the intent behind that patch is to allow the
user to override the default vector length using GOMP_OPENACC_DIM. E.g.,

  #pragma acc parallel loop vector
  for (...)

Here, the nvptx BE defaults to vector length = 32. But I had originally
wanted to allow something like

  GOMP_OPENACC_DIM="1:1:128" ./a.out

to use a vector length of 128 in that parallel region. After looking the
rest of the patch series, that's not possible because the nvptx BE
hard-codes the vector length to 128 at compile time. This was done
because large, multi-warp vector reductions are slow (O(n) vs O(ln n)).

Is this patch series OK without that patch? And if so, because that
patch series depends on other patches, can the following patches be
committed independently?

91e5c13b462 [nvptx] Generalize state propagation and synchronization
cb4b27a93e0 [nvptx] Use MAX, MIN, ROUND_UP macros
0af782ae93c [nvptx] Use TARGET_SET_CURRENT_FUNCTION
87cfb384dbe [nvptx] Add axis_dim
d1783939d98 [nvptx] Add thread count parm to bar.sync
47e80fa77a5 [nvptx] only use one bar.sync barriers in OpenACC offloaded
code
dafc9957ee7 [nvptx] Fix whitespace in nvptx_single and nvptx_neuter_pars
a4857b94879 [nvptx] make nvptx state propagation function names more
generic
b4b85f6e0b5 [nvptx] consolidate offloaded function attributes into
struct offload_attrs
bcdb1e8afac [nvptx] Rename worker_bcast variables oacc_bcast.
34958a0904d [nvptx] update openacc dim macros

These patches just refactor code in the nvptx BE.

Thanks,
Cesar


nvptx-vl.tar.gz
Description: application/gzip


Re: C++ PATCH for c++/87594, constexpr rejects-valid with range-based for

2018-10-29 Thread Jason Merrill

On 10/29/18 2:07 PM, Marek Polacek wrote:

On Wed, Oct 24, 2018 at 05:16:33PM -0400, Jason Merrill wrote:

On 10/11/18 8:56 PM, Marek Polacek wrote:

Here potential_constant_expression_1 rejects the testcase because the body of
the for loop calls a non-constexpr function.  But the range is empty so the
function would never get called.
The trick with evaluating the for-condition doesn't work here, because we're
dealing with a converted range-based for and can't evaluate

__for_begin != __for_end

because the constexpr cache doesn't have the values of these two VAR_DECLs.




So either we can use this ugly hack (more specialized), or just not check the
body of the loop (more general), similarly to what we do (don't do) with
switch.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-10-11  Marek Polacek  

PR c++/87594 - constexpr rejects-valid with range-based for.
* constexpr.c (potential_constant_expression_1) : Return
true for a converted ange-based for-statement.

* g++.dg/cpp1y/constexpr-loop8.C: New test.

diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 4fa8c965a9d..685ca743859 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -5827,6 +5827,17 @@ potential_constant_expression_1 (tree t, bool want_rval, 
bool strict, bool now,
tmp = cxx_eval_outermost_constant_expr (tmp, true);
  if (integer_zerop (tmp))
return true;
+ /* See if this is
+__for_begin != __for_end
+cp_convert_range_for created for us.  If so, this is a converted
+range-based for-statement, and we're not able to evaluate this
+condition, so we might end up skipping the body entirely.  */
+ else if (TREE_CODE (tmp) == NE_EXPR
+  && VAR_P (TREE_OPERAND (tmp, 0))
+  && DECL_NAME (TREE_OPERAND (tmp, 0)) == for_begin_identifier
+  && VAR_P (TREE_OPERAND (tmp, 1))
+  && DECL_NAME (TREE_OPERAND (tmp, 1)) == for_end_identifier)
+   return true;


This seems over-specific; any other condition we can't immediately evaluate
also might not ever be true.  So I think we want to return here unless the
condition is always true.  Likewise for WHILE_STMT.


Yeah, that makes a lot of sense.  Thus:

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-10-29  Marek Polacek  

PR c++/87594 - constexpr rejects-valid with range-based for.
* constexpr.c (potential_constant_expression_1): If the condition
can't be evaluated, return true.


OK.

Jason



Re: [C++ Patch] Improve create_array_type_for_decl locations

2018-10-29 Thread Jason Merrill

On 10/29/18 6:12 AM, Paolo Carlini wrote:

Hi,

while working on something else I noticed that by adding a location_t 
parameter we can improve the locations of those error messages. Tested 
x86_64-linux.


OK.

Jason



[PATCH, rs6000] Consistently use '__vector' instead of 'vector'

2018-10-29 Thread Paul Clarke
Revision r265535 committed changes that used 'vector' instead of the
preferred '__vector'.  There is a reason that '__vector' is preferred,
because it ensures no conflicts with C++ namespace.  Indeed,
gcc/config/rs6000/xmmintrin.h undefines it, leading to errors:

  gcc/include/xmmintrin.h:999:20: error: 'vector' undeclared (first use in this 
function); did you mean 'vec_or'?
  gcc/include/xmmintrin.h:999:20: note: each undeclared identifier is reported 
only once for each function it appears in
  gcc/include/xmmintrin.h:999:26: error: expected ')' before 'long'
  gcc/include/xmmintrin.h:999:37: error: expected ')' before 'result'

Also fixed a few whitespace issues.

(Committing as obvious.)

[gcc]

2018-10-29  Paul A. Clarke  

* gcc/config/rs6000/mmintrin.h (_mm_packs_pi16, _mm_packs_pi32,
_mm_packs_pu16, _mm_unpackhi_pi8, _mm_unpacklo_pi8, _mm_add_pi8,
_mm_add_pi16, _mm_add_pi32, _mm_sub_pi8, _mm_sub_pi16, _mm_sub_pi32,
_mm_cmpgt_pi8, _mm_cmpeq_pi16, _mm_cmpgt_pi16, _mm_cmpeq_pi32,
_mm_cmpgt_pi32, _mm_adds_pi8, _mm_adds_pi16, _mm_adds_pu8,
_mm_adds_pu16, _mm_subs_pi8, _mm_subs_pi16, _mm_subs_pu8,
_mm_subs_pu16, _mm_madd_pi16, _mm_mulhi_pi16, _mm_mullo_pi16,
_mm_sll_pi16, _mm_sra_pi16, _mm_srl_pi16, _mm_set1_pi16, _mm_set1_pi8):
Change 'vector' to '__vector'.
* gcc/config/rs6000/xmmintrin.h (_mm_cvtps_pi32, _mm_cvttps_pi32,
_mm_cvtps_pi16, _mm_cvtps_pi8, _mm_max_pi16, _mm_max_pu8, _mm_min_pi16,
_mm_min_pu8, _mm_mulhi_pu16, _mm_shuffle_pi16, _mm_avg_pu8,
_mm_avg_pu16): Likewise.  And, whitespace corrections.

Index: gcc/config/rs6000/mmintrin.h
===
diff --git a/trunk/gcc/config/rs6000/mmintrin.h 
b/trunk/gcc/config/rs6000/mmintrin.h
--- a/trunk/gcc/config/rs6000/mmintrin.h(revision 265559)
+++ b/trunk/gcc/config/rs6000/mmintrin.h(working copy)
@@ -174,7 +174,7 @@
 
   vm1 = (__vector signed short) (__vector unsigned long long) { __m2, __m1 };
   vresult = vec_vpkshss (vm1, vm1);
-  return (__m64) ((vector long long) vresult)[0];
+  return (__m64) ((__vector long long) vresult)[0];
 }
 
 extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, 
__artificial__))
@@ -194,7 +194,7 @@
 
   vm1 = (__vector signed int) (__vector unsigned long long) { __m2, __m1 };
   vresult = vec_vpkswss (vm1, vm1);
-  return (__m64) ((vector long long) vresult)[0];
+  return (__m64) ((__vector long long) vresult)[0];
 }
 
 extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, 
__artificial__))
@@ -214,7 +214,7 @@
 
   vm1 = (__vector signed short) (__vector unsigned long long) { __m2, __m1 };
   vresult = vec_vpkshus (vm1, vm1);
-  return (__m64) ((vector long long) vresult)[0];
+  return (__m64) ((__vector long long) vresult)[0];
 }
 
 extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, 
__artificial__))
@@ -235,7 +235,7 @@
   a = (__vector unsigned char)vec_splats (__m1);
   b = (__vector unsigned char)vec_splats (__m2);
   c = vec_mergel (a, b);
-  return (__m64) ((vector long long) c)[0];
+  return (__m64) ((__vector long long) c)[0];
 #else
   __m64_union m1, m2, res;
 
@@ -316,7 +316,7 @@
   a = (__vector unsigned char)vec_splats (__m1);
   b = (__vector unsigned char)vec_splats (__m2);
   c = vec_mergel (a, b);
-  return (__m64) ((vector long long) c)[1];
+  return (__m64) ((__vector long long) c)[1];
 #else
   __m64_union m1, m2, res;
 
@@ -397,7 +397,7 @@
   a = (__vector signed char)vec_splats (__m1);
   b = (__vector signed char)vec_splats (__m2);
   c = vec_add (a, b);
-  return (__m64) ((vector long long) c)[0];
+  return (__m64) ((__vector long long) c)[0];
 #else
   __m64_union m1, m2, res;
 
@@ -433,7 +433,7 @@
   a = (__vector signed short)vec_splats (__m1);
   b = (__vector signed short)vec_splats (__m2);
   c = vec_add (a, b);
-  return (__m64) ((vector long long) c)[0];
+  return (__m64) ((__vector long long) c)[0];
 #else
   __m64_union m1, m2, res;
 
@@ -465,7 +465,7 @@
   a = (__vector signed int)vec_splats (__m1);
   b = (__vector signed int)vec_splats (__m2);
   c = vec_add (a, b);
-  return (__m64) ((vector long long) c)[0];
+  return (__m64) ((__vector long long) c)[0];
 #else
   __m64_union m1, m2, res;
 
@@ -495,7 +495,7 @@
   a = (__vector signed char)vec_splats (__m1);
   b = (__vector signed char)vec_splats (__m2);
   c = vec_sub (a, b);
-  return (__m64) ((vector long long) c)[0];
+  return (__m64) ((__vector long long) c)[0];
 #else
   __m64_union m1, m2, res;
 
@@ -531,7 +531,7 @@
   a = (__vector signed short)vec_splats (__m1);
   b = (__vector signed short)vec_splats (__m2);
   c = vec_sub (a, b);
-  return (__m64) ((vector long long) c)[0];
+  return (__m64) ((__vector long long) c)[0];
 #else
   __m64_union m1, m2, res;
 
@@ -563,7 +563,7 @@
   a = (__vector signed int)vec_splats (__m1);
   b = (__vector signed int)vec_splats (__m2);
   c = vec_sub (a, b

Re: [PATCH][rs6000] use index form addresses more often for ldbrx/stdbrx

2018-10-29 Thread Segher Boessenkool
Hi again,

On Mon, Oct 29, 2018 at 09:39:59AM -0500, Aaron Sawdey wrote:
>   * config/rs6000/rs6000.md (bswapdi2): Force address into register
>   if not in one already.

This isn't very correct, could you rephrase?

> +void
> +rs6000_force_indexed_or_indirect_mem (rtx x)
> +{
> +  rtx addr = XEXP (x, 0);

You can move this line down a block.

> +  machine_mode m = GET_MODE (x);
> +  if (!indexed_or_indirect_operand (x, m))
> +{

(to here)

> +  addr = force_reg (Pmode, addr);
> +  x = replace_equiv_address_nv (x, addr);
> +}
> +}


Okay for trunk (if it works ;-) )  Thanks!


Segher


[PATCH, testsuite, c-compat] Handle another c/l option not recognised by older GCC or clang.

2018-10-29 Thread Iain Sandoe
Hi

When using ALT_CC/CXX_UNDER_TEST in the compat/struct-layout-1 tests, the c/l 
options provided to the “alt” compiler need to avoid latest and greatest GCC 
capability.  The patch tests to see if the ‘alt’ compiler can handle 
-fno-diagnostics-show-line-numbers.

OK for trunk?
thanks
Iain

gcc/testsuite/

* lib/c-compat.exp (compat-use-alt-compiler): handle 
-fno-diagnostics-show-line-numbers.
(compat_setup_dfp): Likewise.

diff --git a/gcc/testsuite/lib/c-compat.exp b/gcc/testsuite/lib/c-compat.exp
index f021890..45aa80a 100644
--- a/gcc/testsuite/lib/c-compat.exp
+++ b/gcc/testsuite/lib/c-compat.exp
@@ -35,7 +35,7 @@ load_lib target-libpath.exp
 # 
 proc compat-use-alt-compiler { } {
 global GCC_UNDER_TEST ALT_CC_UNDER_TEST
-global compat_same_alt compat_alt_caret compat_alt_color
+global compat_same_alt compat_alt_caret compat_alt_color compat_no_line_no
 global TEST_ALWAYS_FLAGS
 
 # We don't need to do this if the alternate compiler is actually
@@ -48,6 +48,9 @@ proc compat-use-alt-compiler { } {
if { $compat_alt_color == 0 } then {
regsub -- "-fdiagnostics-color=never" $TEST_ALWAYS_FLAGS "" 
TEST_ALWAYS_FLAGS
}
+   if { $compat_no_line_no == 0 } then {
+   regsub -- "-fno-diagnostics-show-line-numbers" $TEST_ALWAYS_FLAGS 
"" TEST_ALWAYS_FLAGS
+   }
restore_gcc_exec_prefix_env_var
 }
 }
@@ -77,10 +80,12 @@ proc compat_setup_dfp { } {
 global compat_have_dfp
 global compat_alt_caret
 global compat_alt_color
+global compat_no_line_no
 global TEST_ALWAYS_FLAGS compat_save_TEST_ALWAYS_FLAGS
 
 set compat_alt_caret 0
 set compat_alt_color 0
+set compat_no_line_no 0
 set compat_save_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
 
 verbose "compat_setup_dfp: $compat_use_alt $compat_same_alt" 2
@@ -100,6 +105,11 @@ proc compat_setup_dfp { } {
int dummy; } "-fdiagnostics-color=never"] != 0 } {
set compat_alt_color 1
}
+   if { [check_no_compiler_messages_nocache compat_alt_has_no_line_no 
object {
+   int dummy; } "-fno-diagnostics-show-line-numbers"] != 0 } {
+   set compat_no_line_no 1
+   }
+   
compat-use-tst-compiler
 }
 



[PATCH, doc] Fix CONST_WIDE_INT_ELT

2018-10-29 Thread Paul Koning
The description of CONST_WIDE_INT_ELT gave the macro's name as 
CONST_WIDE_INT_NUNITS instead.

Committed as obvious.

paul

ChangeLog:

2018-10-29  Paul Koning  

* doc/rtl.texi (CONST_WIDE_INT_ELT): Give correct macro name.

Index: doc/rtl.texi
===
--- doc/rtl.texi(revision 265601)
+++ doc/rtl.texi(working copy)
@@ -1732,7 +1732,7 @@ Note that this generally is smaller than the numbe
 @code{HOST_WIDE_INT}s implied by the mode size.
 
 @findex CONST_WIDE_INT_ELT
-@item CONST_WIDE_INT_NUNITS (@var{code},@var{i})
+@item CONST_WIDE_INT_ELT (@var{code},@var{i})
 Returns the @code{i}th element of the array.   Element 0 is contains
 the low order bits of the constant.
 



Re: [PATCH] Change vectorizer SLP tree to be a graph

2018-10-29 Thread H.J. Lu
On Wed, Oct 24, 2018 at 7:19 AM Richard Biener  wrote:
>
>
> This does the last step (I've already changed costing, analysis and
> code generation to process nodes as if it were) in making the SLP
> tree a graph.  This means adjusting SLP analysis to lookup already
> identified SLP nodes for a set of scalar stmts and refering to a
> slp_tree from multiple parents.
>
> This avoids blowing up during analysis and lets us vectorize
> the testcase from PR87105 as well as clang does.
>
> I'm still fighting with the necessary refcounting, but maybe this
> version did the trick.
>
> Re-bootstrap & regtest running on x86_64-unknown-linux-gnu, SPEC
> CPU 2006 build is also on the way (though it looks like sth else
> broke stuff there as well).
>
> Most changes are moving and re-indenting misindented stuff (looks like the
> moving part isn't necessary so I'll edit it out).
>
> Note while costing and code generation share things cross SLP
> instance the analysis part does not try to do that (I just thought
> that might not be a good idea without re-vamping the whole
> data structure to get rid of the idea of "separate" instances)
>
> Richard.
>
> From c0e980edec39850e4f9730b02df49cdd31ced8c0 Mon Sep 17 00:00:00 2001
> From: Richard Guenther 
> Date: Wed, 24 Oct 2018 16:09:28 +0200
> Subject: [PATCH] make-slp-tree-a-graph
>
> PR tree-optimization/87105
> * tree-vectorizer.h (_slp_tree::refcnt): New member.
> * tree-vect-slp.c (vect_free_slp_tree): Decrement and honor
> refcnt.
> (vect_create_new_slp_node): Initialize refcnt to one.
> (bst_traits): Move.
> (scalar_stmts_set_t, bst_fail): Remove.
> (vect_build_slp_tree_2): Add bst_map argument and adjust calls.
> (vect_build_slp_tree): Add bst_map argument and lookup
> already created SLP nodes.
> (vect_print_slp_tree): Handle a SLP graph.
> (vect_analyze_slp_instance): Adjust.
> (vect_schedule_slp_instance): Add short-cut.
>

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87801

H.J.


[PATCH, rs6000, committed] Remove inaccurate comment in ssse3-check.h

2018-10-29 Thread Paul Clarke
In gcc.target/powerpc/ssse3-check.h, "DEBUG" doesn't actually
"replace abort with printf on error", it just enables debugging output.

Remove the comment.

Suggested-by: Bill Schmidt 

(Committing as trivial.)

[gcc/testsuite]

2018-10-29  Paul A. Clarke  

* gcc.target/powerpc/ssse3-check.h: Remove inaccurate comment.

Index: gcc/testsuite/gcc.target/powerpc/ssse3-check.h
===
diff --git a/trunk/gcc/testsuite/gcc.target/powerpc/ssse3-check.h 
b/trunk/gcc/testsuite/gcc.target/powerpc/ssse3-check.h
--- a/trunk/gcc/testsuite/gcc.target/powerpc/ssse3-check.h  (revision 
265599)
+++ b/trunk/gcc/testsuite/gcc.target/powerpc/ssse3-check.h  (working copy)
@@ -3,7 +3,6 @@
 
 #include "m128-check.h"
 
-/* define DEBUG replace abort with printf on error.  */
 //#define DEBUG 1
 
 #define TEST ssse3_test



Re: [PATCH] BB vectorization with intermediate aliasing stores

2018-10-29 Thread H.J. Lu
On Wed, Oct 24, 2018 at 3:03 AM Richard Biener  wrote:
>
>
> The following fixes data ref analysis giving up forming group accesses
> when it encounters duplicates.  This most happens during BB vectorization
> when inside a single BB two store groups are separated by a stmt that
> prevents DSE (or CSE for loads) of duplicates.  This is what we for
> example see in PR87105 though there are more issues in that PR.
>
> I've not found a PR that mentions this specific limitation or
> would be fixed with the bug - if you know one please let me know.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Richard.
>
> From b6b2cd3399872818befcc95fdd0bc0a12f0bff25 Mon Sep 17 00:00:00 2001
> From: Richard Guenther 
> Date: Wed, 24 Oct 2018 11:51:16 +0200
> Subject: [PATCH] bb-slp-dups
>
> 2018-10-24  Richard Biener  
>
> * tree-vect-data-refs.c (vect_analyze_group_access_1): Adjust
> dump classification.
> (vect_analyze_data_ref_accesses): Handle duplicate loads and
> stores by splitting the affected group after the fact.
> * tree-vect-slp.c (vect_build_slp_tree_2): Dump when we
> fail the SLP build because of size constraints.
>

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87800

-- 
H.J.


Re: [PATCH] i386: Use scalar operand in SF/DF/SI/DI vec_dup patterns

2018-10-29 Thread Uros Bizjak
On Sat, Oct 27, 2018 at 8:03 AM H.J. Lu  wrote:
>
> Use scalar operand in SF/DF/SI/DI vec_dup patterns which enables combiner
> to generate
>
> (set (reg:V8SF 84)
>  (vec_duplicate:V8SF (mem/c:SF (symbol_ref:DI ("y")
>
> const_vector_duplicate_operand is added for constant vector broadcast.
> We split
>
> (set (reg:V16SF 86)
>  (const_vector:V16SF
>[(const_double:SF 2.0e+0 [0x0.8p+2]) repeated x16])
>
> to
>
> (set (reg:V16SF 86)
>  (vec_duplicate:V16SF (mem/u/c:SF (symbol_ref/u:DI ("*.LC1")

Why not at the expand time? Rewrite vector constant as vec_duplicate
from memory and combine will do the stuff for you. We do have _bcst
instruction patterns.

BTW: We have similar stuff at compress_float_constant.

> before IRA so tha IRA can turn
>
> (set (reg:V16SF 86)
>  (vec_duplicate:V16SF (mem/u/c:SF (symbol_ref/u:DI ("*.LC1")
> (set (reg:V16SF 90)
>  (plus:V16SF (reg/v:V16SF 85 [ x ])
>  (reg:V16SF 86)))
>
> into
>
> (set (reg:V16SF 90)
>  (plus:V16SF
>(vec_duplicate:V16SF (mem/u/c:SF (symbol_ref/u:DI ("*.LC1"
>(reg/v:V16SF 85 [ x ])))
>
> For AVX512 broadcast instructions from integer register operand, we only
> need to broadcast integer to integer vectors.
>
> pic_reg_initialized is added to machine_function to indicate that IRA
> has started since *_const_vec_dup is valid only before
> IRA.

I stopped reading the patch here.

Uros.

> gcc/
>
> PR target/87537
> PR target/87767
> * config/i386/i386-builtin-types.def: Replace
> CODE_FOR_avx2_vec_dupv4sf, CODE_FOR_avx2_vec_dupv8sf and
> CODE_FOR_avx2_vec_dupv4df with CODE_FOR_vec_dupv4sf,
> CODE_FOR_vec_dupv8sf and CODE_FOR_vec_dupv4df, respectively.
> * config/i386/i386.c (ix86_init_pic_reg): Set pic_reg_initialized.
> (expand_vec_perm_1): Replace gen_avx512f_vec_dupv16sf_1,
> gen_avx2_vec_dupv8sf_1 and gen_avx512f_vec_dupv8df_1 with
> gen_avx512f_vec_dupv16sf, gen_vec_dupv8sf and
> gen_avx512f_vec_dupv8df, respectively.  Duplicate them from
> scalar operand.
> * config/i386/i386.h (machine_function): Add pic_reg_initialized.
> * config/i386/i386.md (SF to DF splitter): Replace
> gen_avx512f_vec_dupv16sf_1 with gen_avx512f_vec_dupv16sf.
> * config/i386/predicates.md (const_vector_duplicate_operand): New.
> * config/i386/sse.md (VF48_AVX512VL): New.
> (avx2_vec_dup): Removed.
> (avx2_vec_dupv8sf_1): Likewise.
> (avx512f_vec_dup_1): Likewise.
> (avx2_vec_dupv4df): Likewise.
> (_vec_dup:V48_AVX512VL): Likewise.
> (_vec_dup:VF48_AVX512VL): New.
> (*_const_vec_dup): Likewise.
> (_vec_dup:VI48_AVX512VL): Likewise.
> (_vec_dup_gpr): Replace
> V48_AVX512VL with VI48_AVX512VL.
> (*avx_vperm_broadcast_): Replace gen_avx2_vec_dupv8sf with
> gen_vec_dupv8sf.
>
> gcc/testsuite/
>
> PR target/87537
> PR target/87767
> * gcc.target/i386/avx2-vbroadcastss_ps256-1.c: Updated.
> * gcc.target/i386/avx512vl-vbroadcast-3.c: Likewise.
> * gcc.target/i386/avx512-binop-7.h: New file.
> * gcc.target/i386/avx512f-add-sf-zmm-7.c: Likewise.
> * gcc.target/i386/avx512f-add-si-zmm-7.c: Likewise.
> * gcc.target/i386/avx512vl-add-di-xmm-7.c: Likewise.
> * gcc.target/i386/avx512vl-add-sf-xmm-7.c: Likewise.
> * gcc.target/i386/avx512vl-add-sf-ymm-7.c: Likewise.
> * gcc.target/i386/avx512vl-add-si-xmm-7.c: Likewise.
> * gcc.target/i386/avx512vl-add-si-ymm-7.c: Likewise.
> * gcc.target/i386/pr87537-2.c: Likewise.
> * gcc.target/i386/pr87537-3.c: Likewise.
> * gcc.target/i386/pr87537-4.c: Likewise.
> * gcc.target/i386/pr87537-5.c: Likewise.
> * gcc.target/i386/pr87537-6.c: Likewise.
> * gcc.target/i386/pr87537-7.c: Likewise.
> * gcc.target/i386/pr87537-8.c: Likewise.
> * gcc.target/i386/pr87537-9.c: Likewise.
> ---
>  gcc/config/i386/i386-builtin.def  |  6 +-
>  gcc/config/i386/i386.c| 30 +-
>  gcc/config/i386/i386.h|  3 +
>  gcc/config/i386/i386.md   |  2 +-
>  gcc/config/i386/predicates.md | 13 +++
>  gcc/config/i386/sse.md| 98 ---
>  .../i386/avx2-vbroadcastss_ps256-1.c  |  3 +-
>  .../gcc.target/i386/avx512-binop-7.h  | 12 +++
>  .../gcc.target/i386/avx512f-add-sf-zmm-7.c| 14 +++
>  .../gcc.target/i386/avx512f-add-si-zmm-7.c| 12 +++
>  .../gcc.target/i386/avx512vl-add-di-xmm-7.c   | 13 +++
>  .../gcc.target/i386/avx512vl-add-sf-xmm-7.c   | 13 +++
>  .../gcc.target/i386/avx512vl-add-sf-ymm-7.c   | 13 +++
>  .../gcc.target/i386/avx512vl-add-si-xmm-7.c   | 13 +++
>  .../gcc.target/i386/avx512vl-add-si-ymm-7.c   | 13 +++
>  .../gcc.target/i386/avx512vl-vbroadcast-3.c   | 

Re: [patch, doc, fortran] Document FINDLOC

2018-10-29 Thread Thomas König

Am 29.10.18 um 12:31 schrieb Bernhard Reutner-Fischer:

Hi!

On Sun, 28 Oct 2018 15:13:49 +0100
Thomas König  wrote:

One question and some nits below.


===
--- intrinsic.texi  (Revision 265569)
+++ intrinsic.texi  (Arbeitskopie)



@@ -6021,8 +6022,68 @@ END PROGRAM
  @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
  @end table
  
+@node FINDLOC

+@section @code{FINDLOC} --- Search an array for a value


I think one should not put spaces around triple-dashes.


We have it everywhere else.  Should we change this in general?
If so, that would probably make sense as a followup patch.

DIM} direction. If @var{MASK} is present,


dot-space-space at end of sentence: direction.  If


Done.


+only the elements for which @var{MASK} is @code{.TRUE.} are
+considered.  If more than one element in the array has the value
+@var{VALUE}, the location returned is that of the first such element
+in array element order if the @var{BACK} is not present, or if it


missing "is": ...not present or if it is @code{.FALSE.}.


+false; otherwise, the location returned is that of the first such
+element. If the array has zero size, or all of the elements of


I think this should mention BACK=.TRUE. for clarity; and it should
refer to the _last_ such element, not the first, doesn't it?


Reordered, to make it more sensible.


Excess spaces between @var{DIM} and @tab?


Removed.


Excess third space at the start of the sentence: dot-space-space


Removed.

Unless there are other comments, I'll commit in a couple of days.

Regards

Thomas
Index: gfortran.texi
===
--- gfortran.texi	(Revision 265569)
+++ gfortran.texi	(Arbeitskopie)
@@ -1479,7 +1479,7 @@ contains a negative number, then there is a preced
 
 In the most simple case, with only one subrecord per logical record,
 both record markers contain the number of bytes of user data in the
-record,
+record.
 
 The format for unformatted sequential data can be duplicated using
 unformatted stream, as shown in the example program for an unformatted
Index: intrinsic.texi
===
--- intrinsic.texi	(Revision 265569)
+++ intrinsic.texi	(Arbeitskopie)
@@ -148,6 +148,7 @@ Some basic guidelines for editing this document:
 * @code{FDATE}: FDATE, Subroutine (or function) to get the current time as a string
 * @code{FGET}:  FGET,  Read a single character in stream mode from stdin
 * @code{FGETC}: FGETC, Read a single character in stream mode
+* @code{FINDLOC}:   FINDLOC,   Search an array for a value
 * @code{FLOOR}: FLOOR, Integer floor function
 * @code{FLUSH}: FLUSH, Flush I/O unit(s)
 * @code{FNUM}:  FNUM,  File number function
@@ -6021,8 +6022,68 @@ END PROGRAM
 @ref{FGET}, @ref{FPUT}, @ref{FPUTC}
 @end table
 
+@node FINDLOC
+@section @code{FINDLOC} --- Search an array for a value
+@fnindex FINDLOC
+@cindex findloc
 
+@table @asis
+@item @emph{Description}:
+Determines the location of the element in the array with the value
+given in the @var{VALUE} argument, or, if the @var{DIM} argument is
+supplied, determines the locations of the maximum element along each
+row of the array in the @var{DIM} direction.  If @var{MASK} is
+present, only the elements for which @var{MASK} is @code{.TRUE.} are
+considered.  If more than one element in the array has the value
+@var{VALUE}, the location returned is that of the first such element
+in array element order if the @var{BACK} is not present or if it is
+@code{.FALSE.}. If @var{BACK} is true, the location returned is that
+of the last such element. If the array has zero size, or all of the
+elements of @var{MASK} are @code{.FALSE.}, then the result is an array
+of zeroes.  Similarly, if @var{DIM} is supplied and all of the
+elements of @var{MASK} along a given row are zero, the result value
+for that row is zero.
 
+@item @emph{Standard}:
+Fortran 2008 and later.
+
+@item @emph{Class}:
+Transformational function
+
+@item @emph{Syntax}:
+@multitable @columnfractions .80
+@item @code{RESULT = FINDLOC(ARRAY, VALUE, DIM [, MASK] [,KIND] [,BACK])}
+@item @code{RESULT = FINDLOC(ARRAY, VALUE, [, MASK] [,KIND] [,BACK])}
+@end multitable
+
+@item @emph{Arguments}:
+@multitable @columnfractions .15 .70
+@item @var{ARRAY} @tab Shall be an array of intrinsic type.
+@item @var{VALUE} @tab A scalar of intrinsic type which is in type
+conformance with @var{ARRAY}.
+@item @var{DIM} @tab (Optional) Shall be a scalar of type
+@code{INTEGER}, with a value between one and the rank of @var{ARRAY},
+inclusive.  It may not be an optional dummy argument.
+@item @var{KIND} @tab (Optional) An @code{INTEGER} initialization
+expression indicating the kind parameter of the result.
+@item @var{BACK} @tab (Optional) A scalar of type @code{LOGICAL}.
+@end multitable
+
+@item @emph{Return value}:
+If @var{DIM} is ab

Re: [ARM/FDPIC v3 03/21] [ARM] FDPIC: Force FDPIC related options unless -mno-fdpic is provided

2018-10-29 Thread Segher Boessenkool
On Mon, Oct 29, 2018 at 02:45:20PM +0100, Christophe Lyon wrote:
> Here is an updated doc proposal (that would go in patch #1, without
> changing this one):
> @item -mfdpic
> @opindex mfdpic
> Select the FDPIC ABI, which uses function descriptors to represent
> pointers to functions.  When the compiler is configured for
> @code{arm-*-uclinuxfdpiceabi} targets, this option is on by default
> and implies @option{-fPIE} if none of the PIC/PIE-related options is
> provided.  On other targets, it only enables the FDPIC-specific code
> generation features, and the user should explicitly provide the
> PIC/PIE-related options as needed.

Most other things seem to put -mno-fdpic in an @itemx and mno-fdpic in
an @opindex as well, in similar cases.

> The opposite @option{-mno-fdpic} option is useful (and required) to
> build the Linux kernel using the same toolchain as the one used to
> build the userland programs.
> 
> Is it clearer? Does it read OK?

It reads fine I think.


Segher


Re: C++ PATCH to Implement P0846R0, ADL and function templates

2018-10-29 Thread Jason Merrill

On 10/28/18 3:56 PM, Marek Polacek wrote:

This patch implements P0846R0: ADL and Function Templates that are not Visible

whereby a name for which a normal lookup produces either no result or finds one
or more functions and that is followed by a "<" would be treated as if a 
function
template name had been found and would cause ADL to be performed.  Thus e.g.

namespace N {
   struct S { };
   template void f(S);
}

void
bar (N::S s)
{
   f<3>(s);
}

will now compile; ADL will find N::f.  The gist of the approach I took is in
cp_parser_template_name and setting TEMPLATE_ID_TRY_ADL_P.


Why do you need that flag?  Can't you tell from the first operand of the 
TEMPLATE_ID_EXPR whether it's suitable?



One of the side effects is that a function name followed by a < means that the 
< is
always taken as the delimiter of a template-argument-list, rendering e.g. this

   fun-ptr < a;

ill-formed.

There's something I'm not clear on; the proposal talks about an
unqualified-id followed by a <, which is also the case for

   a.foo < 1;

which is "postfix-expression . unqualified-id <", but treating "foo" as a
template name would break valid programs.  I don't think this proposal should
be in effect for class member accesses, so I've disabled it by using scoped_p
below.  See fn-template8.C for a complete testcase for this scenario.


Agreed; ADL doesn't apply to class member access, so it shouldn't apply 
here.  Sent mail to the core reflector.



Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-10-28  Marek Polacek  

Implement P0846R0, ADL and function templates.
* cp-tree.h (TEMPLATE_ID_TRY_ADL_P): New macro.
* decl.c (grokfndecl): Allow FUNCTION_DECL in assert.
* parser.c (cp_parser_postfix_expression): Also perform ADL for
template-id that is TEMPLATE_ID_TRY_ADL_P.
(cp_parser_template_id): Adjust a call to cp_parser_template_name.
Allow FUNCTION_DECL in assert.  Return error node if parsing the
template argument list didn't go well.  Set TEMPLATE_ID_TRY_ADL_P
on the template-id.
(cp_parser_template_name): Add a new parameter.  Consider a name to
refer to a template if it is an unqualified-id followed by <.
(cp_parser_constructor_declarator_p): Adjust a call to
cp_parser_template_name.

* g++.dg/addr_builtin-1.C: Adjust dg-error.
* g++.dg/cpp2a/fn-template1.C: New test.
* g++.dg/cpp2a/fn-template10.C: New test.
* g++.dg/cpp2a/fn-template11.C: New test.
* g++.dg/cpp2a/fn-template12.C: New test.
* g++.dg/cpp2a/fn-template13.C: New test.
* g++.dg/cpp2a/fn-template2.C: New test.
* g++.dg/cpp2a/fn-template3.C: New test.
* g++.dg/cpp2a/fn-template4.C: New test.
* g++.dg/cpp2a/fn-template5.C: New test.
* g++.dg/cpp2a/fn-template6.C: New test.
* g++.dg/cpp2a/fn-template7.C: New test.
* g++.dg/cpp2a/fn-template8.C: New test.
* g++.dg/cpp2a/fn-template9.C: New test.
* g++.dg/parse/fn-template1.C: New test.
* g++.dg/parse/fn-template2.C: New test.
* g++.dg/template/pr61745.C: Add target to dg-error.

diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h
index 26ded3a9214..aa7ddb0830c 100644
--- gcc/cp/cp-tree.h
+++ gcc/cp/cp-tree.h
@@ -409,6 +409,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
SWITCH_STMT_ALL_CASES_P (in SWITCH_STMT)
REINTERPRET_CAST_P (in NOP_EXPR)
ALIGNOF_EXPR_STD_P (in ALIGNOF_EXPR)
+  TEMPLATE_ID_TRY_ADL_P (in TEMPLATE_ID_EXPR)
 1: IDENTIFIER_KIND_BIT_1 (in IDENTIFIER_NODE)
TI_PENDING_TEMPLATE_FLAG.
TEMPLATE_PARMS_FOR_INLINE.
@@ -4987,6 +4988,11 @@ more_aggr_init_expr_args_p (const 
aggr_init_expr_arg_iterator *iter)
  #define ALIGNOF_EXPR_STD_P(NODE) \
TREE_LANG_FLAG_0 (ALIGNOF_EXPR_CHECK (NODE))
  
+/* True iff this template-id uses an unqualified-id that should

+   be considered to refer to a template-name, as per P0846R0.  */
+#define TEMPLATE_ID_TRY_ADL_P(NODE) \
+  (TREE_LANG_FLAG_0 (TEMPLATE_ID_EXPR_CHECK (NODE)))
+
  /* An enumeration of the kind of tags that C++ accepts.  */
  enum tag_types {
none_type = 0, /* Not a tag type.  */
diff --git gcc/cp/decl.c gcc/cp/decl.c
index 5ebfaaf85e6..e63743f8a6f 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -8827,7 +8827,9 @@ grokfndecl (tree ctype,
 the information in the TEMPLATE_ID_EXPR.  */
  SET_DECL_IMPLICIT_INSTANTIATION (decl);
  
-	  gcc_assert (identifier_p (fns) || TREE_CODE (fns) == OVERLOAD);

+ gcc_assert (identifier_p (fns)
+ || TREE_CODE (fns) == OVERLOAD
+ || TREE_CODE (fns) == FUNCTION_DECL);
  DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
  
  	  for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))

diff --git gcc/cp/parser.c gcc/cp/parser.c
index ebe326eb923..a99bde

[PATCH] avoid -Wnonnull for printf format in dead code (PR 87041)

2018-10-29 Thread Martin Sebor

PR 87041 - -Wformat "reading through null pointer" on unreachable
code is a complaint about -Wformat false positives due to null
arguments to %s directives in unreachable printf calls.  The warning
is issued by the front end, too early to know whether or not the call
is ever made.

The -Wformat-overflow has had the ability to detect null pointers
in %s and similar directives to sprintf calls since GCC 7 without
these false positives, but the warning doesn't consider stream or
file I/O functions like printf/fprintf.  To resolve the bug report
I have enhanced -Wformat-overflow to consider all printf-like
functions, including user-defined ones declared attribute format
(printf).

Besides null pointers the enhancement also makes it possible to
detect other problems (like out-of-range arguments and output in
excess of INT_MAX bytes).  It also lays the groundwork for
checking user-defined printf-like functions for buffer overflow
(once a suitable attribute is added to indicate which arguments
are the destination buffer pointer and the buffer size).

With that, I have removed the null checking from -Wformat (again,
only for printf-like functions).

Martin
PR middle-end/87041 - -Wformat reading through null pointer on unreachable code

gcc/ChangeLog:

	PR middle-end/87041
	* gimple-ssa-sprintf.c (format_directive): Use %G to include
	inlining context.
	(sprintf_dom_walker::compute_format_length):
	Avoid setting POSUNDER4K here.
	(get_destination_size): Handle null argument values.
	(get_user_idx_format): New function.
	(sprintf_dom_walker::handle_gimple_call): Handle all printf-like
	functions, including user-defined with attribute format printf.
	Use %G to include inlining context.
	Set POSUNDER4K here.

gcc/c-family/ChangeLog:

	PR middle-end/87041
	* c-format.c (check_format_types): Avoid diagnosing null pointer
	arguments to printf-family of functions.

gcc/testsuite/ChangeLog:

	PR middle-end/87041
	* gcc.c-torture/execute/fprintf-2.c: New test.
	* gcc.c-torture/execute/printf-2.c: Same.
	* gcc.c-torture/execute/user-printf.c: Same.
	* gcc.dg/tree-ssa/builtin-fprintf-warn-1.c: Same.
	* gcc.dg/tree-ssa/builtin-printf-2.c: Same.
	* gcc.dg/tree-ssa/builtin-printf-warn-1.c: Same.
	* gcc.dg/tree-ssa/user-printf-warn-1.c: Same.

Index: gcc/c-family/c-format.c
===
--- gcc/c-family/c-format.c	(revision 265496)
+++ gcc/c-family/c-format.c	(working copy)
@@ -3123,8 +3123,11 @@ check_format_types (const substring_loc &fmt_loc,
 		warning (OPT_Wformat_, "writing through null pointer "
 			 "(argument %d)", arg_num);
 
-	  /* Check for reading through a NULL pointer.  */
-	  if (types->reading_from_flag
+	  /* Check for reading through a NULL pointer.  Ignore
+		 printf-family of functions as they are checked for
+		 null arguments by the middle-end.  */
+	  if (fki->conversion_specs != print_char_table
+		  && types->reading_from_flag
 		  && i == 0
 		  && cur_param != 0
 		  && integer_zerop (cur_param))
Index: gcc/gimple-ssa-sprintf.c
===
--- gcc/gimple-ssa-sprintf.c	(revision 265496)
+++ gcc/gimple-ssa-sprintf.c	(working copy)
@@ -68,6 +68,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "langhooks.h"
 
+#include "attribs.h"
 #include "builtins.h"
 #include "stor-layout.h"
 
@@ -2796,8 +2797,9 @@ format_directive (const sprintf_dom_walker::call_i
   if (fmtres.nullp)
 {
   fmtwarn (dirloc, argloc, NULL, info.warnopt (),
-	   "%<%.*s%> directive argument is null",
-	   dirlen, target_to_host (hostdir, sizeof hostdir, dir.beg));
+	   "%G%<%.*s%> directive argument is null",
+	   info.callstmt, dirlen,
+	   target_to_host (hostdir, sizeof hostdir, dir.beg));
 
   /* Don't bother processing the rest of the format string.  */
   res->warned = true;
@@ -3475,7 +3477,6 @@ sprintf_dom_walker::compute_format_length (call_in
  by the known range [0, 0] (with no conversion resulting in a failure
  or producing more than 4K bytes) until determined otherwise.  */
   res->knownrange = true;
-  res->posunder4k = true;
   res->floating = false;
   res->warned = false;
 
@@ -3518,6 +3519,10 @@ sprintf_dom_walker::compute_format_length (call_in
 static unsigned HOST_WIDE_INT
 get_destination_size (tree dest)
 {
+  /* When there is no destination return -1.  */
+  if (!dest)
+return HOST_WIDE_INT_M1U;
+
   /* Initialize object size info before trying to compute it.  */
   init_object_sizes ();
 
@@ -3738,6 +3743,37 @@ try_simplify_call (gimple_stmt_iterator *gsi,
   return false;
 }
 
+/* Return the zero-based index of the format string argument of a printf
+   like function and set *IDX_ARGS to the first format argument.  When
+   no such index exists return UINT_MAX.  */
+
+static unsigned
+get_user_idx_format (tree fndecl, unsigned *idx_args)
+{
+  tree attrs = lookup_attribute ("format", DECL_ATTRIBUTES (fn

[PATCH] xstormy: Set tm_d_file in config.gcc

2018-10-29 Thread Iain Buclaw
The default value of tm_d_file is "${cpu_type}/${cpu_type}.h", however
this header doesn't exist for the xstormy back-end, so need to
explicitly override it to stormy16/stormy16.h

Also including elfos.h, otherwise there's a warning about a
redefinition of PREFERRED_DEBUGGING_TYPE when building with
--enable-languages=d.  There is no library support, but the compiler
works well enough.

OK for trunk?
-- 
Iain

---
gcc/ChangeLog:

2018-10-29  Iain Buclaw  

* config.gcc (xstormy16-*-elf): Set tm_d_file.

---
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 93dc2978603..b108697cfc7 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3161,6 +3161,7 @@ xstormy16-*-elf)
 	# For historical reasons, the target files omit the 'x'.
 	tm_file="dbxelf.h elfos.h newlib-stdint.h stormy16/stormy16.h"
 	tm_p_file=stormy16/stormy16-protos.h
+	tm_d_file="elfos.h stormy16/stormy16.h"
 	md_file=stormy16/stormy16.md
 	out_file=stormy16/stormy16.c
 	extra_options=stormy16/stormy16.opt


Re: [PATCH] xstormy: Set tm_d_file in config.gcc

2018-10-29 Thread Jeff Law
On 10/29/18 4:10 PM, Iain Buclaw wrote:
> The default value of tm_d_file is "${cpu_type}/${cpu_type}.h", however
> this header doesn't exist for the xstormy back-end, so need to
> explicitly override it to stormy16/stormy16.h
> 
> Also including elfos.h, otherwise there's a warning about a
> redefinition of PREFERRED_DEBUGGING_TYPE when building with
> --enable-languages=d.  There is no library support, but the compiler
> works well enough.
> 
> OK for trunk?
> 
OK
jeff


Re: C++ PATCH to implement C++20 P0892R2 - explicit(bool) [v4]

2018-10-29 Thread Marek Polacek
On Wed, Oct 24, 2018 at 02:55:14PM -0400, Jason Merrill wrote:
> On 10/12/18 12:32 PM, Marek Polacek wrote:
> > +   EXPLICIT_SPECIFIER is used in case the explicit-specifier, if any, has
> > +   value-dependent expression.  */
> >  static void
> >  cp_parser_decl_specifier_seq (cp_parser* parser,
> >   cp_parser_flags flags,
> >   cp_decl_specifier_seq *decl_specs,
> > - int* declares_class_or_enum)
> > + int* declares_class_or_enum,
> > + tree* explicit_specifier)
> 
> Why not add the explicit-specifier to cp_decl_specifier_seq?  They don't
> live very long, so making them bigger isn't a concern.  Then other of the
> handling could move into grokdeclarator along with the other explicit
> handling.

Great -- that simplifies things.

> > @@ -12822,6 +12844,17 @@ tsubst_function_decl (tree t, tree args, 
> > tsubst_flags_t complain,
> >if (!uses_template_parms (DECL_TI_ARGS (t)))
> > return t;
> > +  /* Handle explicit(dependent-expr).  */
> > +  if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t))
> > +   {
> > + tree spec = lookup_explicit_specifier (t);
> > + spec = tsubst_copy_and_build (spec, args, complain, in_decl,
> > +   /*function_p=*/false,
> > +   /*i_c_e_p=*/true);
> > + spec = build_explicit_specifier (spec, complain);
> > + DECL_NONCONVERTING_P (t) = (spec == boolean_true_node);
> > +   }
> 
> This is setting DECL_NONCONVERTING_P on the template, rather than the
> instantiation r, which hasn't been created yet at this point; this handling
> needs to move further down in the function.

Hmm, interesting that that worked, too.  Anyway, fixed.  Thanks!

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-10-29  Marek Polacek  

Implement P0892R2, explicit(bool).
* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_explicit_bool.

* call.c (add_template_candidate_real): Return if the declaration is
explicit and we're only looking for non-converting constructor.
* cp-tree.h (lang_decl_fn): Add has_dependent_explicit_spec_p bit.
(DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P): New macro.
(cp_decl_specifier_seq): Add explicit_specifier field.
(build_explicit_specifier, store_explicit_specifier): Declare.
* decl.c (grokdeclarator): Call store_explicit_specifier.
(build_explicit_specifier): New function.
* parser.c (cp_parser_function_specifier_opt) :
Parse C++20 explicit(bool).
* pt.c (store_explicit_specifier, lookup_explicit_specifier): New.
(tsubst_function_decl): Handle explicit(dependent-expr).

* g++.dg/cpp2a/explicit1.C: New test.
* g++.dg/cpp2a/explicit10.C: New test.
* g++.dg/cpp2a/explicit11.C: New test.
* g++.dg/cpp2a/explicit12.C: New test.
* g++.dg/cpp2a/explicit13.C: New test.
* g++.dg/cpp2a/explicit2.C: New test.
* g++.dg/cpp2a/explicit3.C: New test.
* g++.dg/cpp2a/explicit4.C: New test.
* g++.dg/cpp2a/explicit5.C: New test.
* g++.dg/cpp2a/explicit6.C: New test.
* g++.dg/cpp2a/explicit7.C: New test.
* g++.dg/cpp2a/explicit8.C: New test.
* g++.dg/cpp2a/explicit9.C: New test.

* testsuite/20_util/any/cons/explicit.cc: Adjust dg-error.
* testsuite/20_util/pair/cons/explicit_construct.cc: Likewise.
* testsuite/20_util/tuple/cons/explicit_construct.cc: Likewise.

diff --git gcc/gcc/c-family/c-cppbuiltin.c gcc/gcc/c-family/c-cppbuiltin.c
index 96a6b4dfd2b..b085cf9201f 100644
--- gcc/gcc/c-family/c-cppbuiltin.c
+++ gcc/gcc/c-family/c-cppbuiltin.c
@@ -955,7 +955,7 @@ c_cpp_builtins (cpp_reader *pfile)
}
   if (cxx_dialect > cxx14)
{
- /* Set feature test macros for C++1z.  */
+ /* Set feature test macros for C++17.  */
  cpp_define (pfile, "__cpp_unicode_characters=201411");
  cpp_define (pfile, "__cpp_static_assert=201411");
  cpp_define (pfile, "__cpp_namespace_attributes=201411");
@@ -975,6 +975,11 @@ c_cpp_builtins (cpp_reader *pfile)
  cpp_define (pfile, "__cpp_structured_bindings=201606");
  cpp_define (pfile, "__cpp_variadic_using=201611");
}
+  if (cxx_dialect > cxx17)
+   {
+ /* Set feature test macros for C++2a.  */
+ cpp_define (pfile, "__cpp_explicit_bool=201806");
+   }
   if (flag_concepts)
cpp_define (pfile, "__cpp_concepts=201507");
   if (flag_tm)
diff --git gcc/gcc/cp/call.c gcc/gcc/cp/call.c
index cd0c0f60ced..e3453aca96e 100644
--- gcc/gcc/cp/call.c
+++ gcc/gcc/cp/call.c
@@ -3251,6 +3251,12 @@ add_template_candidate_real (struct z_candidate 
**candidates, tree tmpl,
   goto fail;
 }
 
+  /* Now the explicit specifier might have been deduced; check if this
+ declaration is explicit.  If it is and we're ig

Re: Fix build of the D frontend on the Hurd and KFreeBSD

2018-10-29 Thread Iain Buclaw
On Mon, 29 Oct 2018 at 12:51, Matthias Klose  wrote:
>
> Fix build of the D frontend on the Hurd and KFreeBSD.  Where should these
> changes go, when they are not yet applied upstream?
>
> Ok to commit?
>
> Matthias
>

Thanks,

I can send a patch to the github repository upstream.

I'll do a sync of the repo sometime tomorrow.

-- 
Iain


[PATCHv2] Add sinh(atanh(x)) and cosh(atanh(x)) optimizations

2018-10-29 Thread Giuliano Augusto Faulin Belinassi
Improves the numerical precision, as suggested on the previous iteration.

Before, the code used 1 - x*x, which can be problematic when x is near
1. Wilco Dijkstra suggested to replace it with 2*(1-fabs(x)) -
(1-fabs(x))*(1-fabs(x)) when fabs(x) > 0.5 to greatly improve
precision, however after some experiments i found that just
factorizing 1 - x*x to (1+x)*(1-x) was just as precise as his
suggestion, and works very well for both cases when fabs(x) > 0.5 and
fabs(x) <= 0.5, therefore it is faster and the code is simpler because
no check is needed.

The largest ULP error I could find with this formula when comparing it
with the correctly rounded result was 2.

gcc/ChangeLog
2018-10-29  Giuliano Belinassi  

* match.pd (sinh (atanh (x))): New simplification rules.
(cosh (atanh (x))): Likewise.

gcc/testsuite/ChangeLog
2018-10-29  Giuliano Belinassi  

* gcc.dg/sinhatanh-1.c: New test.
* gcc.dg/sinhatanh-2.c: New test.

There are no tests in trunk that seems to be breaking because of this patch.
Index: gcc/match.pd
===
--- gcc/match.pd	(revision 265608)
+++ gcc/match.pd	(working copy)
@@ -4310,6 +4310,24 @@
   (rdiv { t_one; } (sqrts (plus (mult @0 @0) { t_one; })))
   (copysigns { t_zero; } @0))
 
+ /* Simplify sinh(atanh(x)) -> x / sqrt((1 - x)*(1 + x)). */
+ (for sinhs (SINH)
+  atanhs (ATANH)
+  sqrts (SQRT)
+  (simplify
+   (sinhs (atanhs:s @0))
+   (with { tree t_one = build_one_cst (type); }
+   (rdiv @0 (sqrts (mult (minus { t_one; } @0) (plus { t_one; } @0)))
+
+ /* Simplify cosh(atanh(x)) -> 1 / sqrt((1 - x)*(1 + x)) */
+ (for coshs (COSH)
+  atanhs (ATANH)
+  sqrts (SQRT)
+  (simplify
+   (coshs (atanhs:s @0))
+   (with { tree t_one = build_real (type, dconst1); }
+   (rdiv { t_one; } (sqrts (mult (minus { t_one; } @0) (plus { t_one; } @0)))
+
 /* cabs(x+0i) or cabs(0+xi) -> abs(x).  */
 (simplify
  (CABS (complex:C @0 real_zerop@1))
Index: gcc/testsuite/gcc.dg/sinhatanh-1.c
===
--- gcc/testsuite/gcc.dg/sinhatanh-1.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/sinhatanh-1.c	(working copy)
@@ -0,0 +1,62 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-optimized" } */
+
+extern float sinhf (float);
+extern float coshf (float);
+extern float atanhf (float);
+extern float sqrtf (float);
+extern double sinh (double);
+extern double cosh (double);
+extern double atanh (double);
+extern double sqrt (double);
+extern long double sinhl (long double);
+extern long double coshl (long double);
+extern long double atanhl (long double);
+extern long double sqrtl (long double);
+
+double __attribute__ ((noinline))
+sinhatanh_ (double x)
+{
+return sinh (atanh (x));
+}
+
+double __attribute__ ((noinline))
+coshatanh_ (double x)
+{
+return cosh (atanh (x));
+}
+
+float __attribute__ ((noinline))
+sinhatanhf_(float x)
+{
+return sinhf (atanhf (x));
+}
+
+float __attribute__ ((noinline))
+coshatanhf_(float x)
+{
+return coshf (atanhf (x));
+}
+
+long double __attribute__ ((noinline))
+sinhatanhl_ (long double x)
+{
+return sinhl (atanhl (x));
+}
+
+long double __attribute__ ((noinline))
+coshatanhl_ (long double x)
+{
+return coshl (atanhl (x));
+}
+
+/* There must be no calls to sinh, cosh, or atanh */
+/* {dg-final { scan-tree-dump-not "sinh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "cosh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "atanh " "optimized" }} */
+/* {dg-final { scan-tree-dump-not "sinfh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "cosfh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "atanfh " "optimized" }} */
+/* {dg-final { scan-tree-dump-not "sinlh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "coslh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "atanlh " "optimized" }} */
Index: gcc/testsuite/gcc.dg/sinhatanh-2.c
===
--- gcc/testsuite/gcc.dg/sinhatanh-2.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/sinhatanh-2.c	(working copy)
@@ -0,0 +1,68 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-optimized" } */
+
+extern float sinhf (float);
+extern float coshf (float);
+extern float atanhf (float);
+extern float sqrtf (float);
+extern double sinh (double);
+extern double cosh (double);
+extern double atanh (double);
+extern double sqrt (double);
+extern long double sinhl (long double);
+extern long double coshl (long double);
+extern long double atanhl (long double);
+extern long double sqrtl (long double);
+
+float __attribute__ ((noinline)) 
+coshatanhf_(float x)
+{
+float atg = atanhf(x);
+return coshf(atg) + atg;
+}
+
+double __attribute__ ((noinline)) 
+cosatan_(double x)
+{
+double atg = atanh(x);
+return cosh(atg) + atg;
+}
+
+long double __attribute__ ((noinline)) 
+cosatanl_(long double x)
+{
+long double atg = atanhl(x);
+  

[PATCH] detect missing nuls in address of const char (PR 87756)

2018-10-29 Thread Martin Sebor

The missing nul detection fails when the argument of the %s or
similar sprintf directive is the address of a non-nul character
constant such as in:

  const char c = 'a';
  int f (void)
  {
return snprintf (0, 0, "%s", &c);
  }

This is because the string_constant function only succeeds for
arguments that refer to STRRING_CSTs, not to individual characters.

For the same reason, calls to memchr() such as the one below aren't
folded into constants:

  const char d = '\0';
  void* g (void)
  {
return memchr (&d, 0, 1);
  }

To detect and diagnose the missing nul in the first example and
to fold the second, the attached patch modifies string_constant
to return a synthesized STRING_CST object for such references
(while also indicating whether such an object is properly
nul-terminated).

Tested on x86_64-linux.

Martin
PR tree-optimization/87756 - missing unterminated argument warning using address of a constant character

gcc/ChangeLog:

	PR tree-optimization/87756
	* expr.c (string_constant): Synthesize a string literal from
	the address of a constant character.
	* tree.c (build_string_literal): Add an argument.
	* tree.h (build_string_literal): Same.

gcc/testsuite/ChangeLog:

	PR tree-optimization/87756
	* gcc.dg/builtin-memchr-2.c: New test.
	* gcc.dg/builtin-memchr-3.c: Same.
	* gcc.dg/warn-sprintf-no-nul-2.c: Same.

Index: gcc/expr.c
===
--- gcc/expr.c	(revision 265496)
+++ gcc/expr.c	(working copy)
@@ -11484,18 +11484,40 @@ string_constant (tree arg, tree *ptr_offset, tree
 	offset = off;
 }
 
-  if (!init || TREE_CODE (init) != STRING_CST)
+  if (!init)
 return NULL_TREE;
 
+  *ptr_offset = offset;
+
+  tree eltype = TREE_TYPE (init);
+  tree initsize = TYPE_SIZE_UNIT (eltype);
   if (mem_size)
-*mem_size = TYPE_SIZE_UNIT (TREE_TYPE (init));
+*mem_size = initsize;
+
   if (decl)
 *decl = array;
 
-  gcc_checking_assert (tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (init)))
-		   >= TREE_STRING_LENGTH (init));
+  if (TREE_CODE (init) == INTEGER_CST)
+{
+  /* For a reference to (address of) a single constant character,
+	 store the native representation of the character in CHARBUF.   */
+  unsigned char charbuf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
+  int len = native_encode_expr (init, charbuf, sizeof charbuf, 0);
+  if (len > 0)
+	{
+	  /* Construct a string literal with elements of ELTYPE and
+	 the representation above.  Then strip
+	 the ADDR_EXPR (ARRAY_REF (...)) around the STRING_CST.  */
+	  init = build_string_literal (len, (char *)charbuf, eltype);
+	  init = TREE_OPERAND (TREE_OPERAND (init, 0), 0);
+	}
+}
 
-  *ptr_offset = offset;
+  if (TREE_CODE (init) != STRING_CST)
+return NULL_TREE;
+
+  gcc_checking_assert (tree_to_shwi (initsize) >= TREE_STRING_LENGTH (init));
+
   return init;
 }
 
Index: gcc/tree.c
===
--- gcc/tree.c	(revision 265496)
+++ gcc/tree.c	(working copy)
@@ -11141,25 +11141,28 @@ build_alloca_call_expr (tree size, unsigned int al
 }
 }
 
-/* Create a new constant string literal and return a char* pointer to it.
-   The STRING_CST value is the LEN characters at STR.  */
+/* Create a new constant string literal consisting of elements of type
+   ELTYPE and return a tree node representing char* pointer to it as
+   an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)).  The STRING_CST value is
+   the LEN bytes at STR (the representation of the string, which may
+   be wide).  */
+
 tree
-build_string_literal (int len, const char *str)
+build_string_literal (int len, const char *str,
+		  tree eltype /* = char_type_node */)
 {
-  tree t, elem, index, type;
-
-  t = build_string (len, str);
-  elem = build_type_variant (char_type_node, 1, 0);
-  index = build_index_type (size_int (len - 1));
-  type = build_array_type (elem, index);
+  tree t = build_string (len, str);
+  tree index = build_index_type (size_int (len - 1));
+  eltype = build_type_variant (eltype, 1, 0);
+  tree type = build_array_type (eltype, index);
   TREE_TYPE (t) = type;
   TREE_CONSTANT (t) = 1;
   TREE_READONLY (t) = 1;
   TREE_STATIC (t) = 1;
 
-  type = build_pointer_type (elem);
+  type = build_pointer_type (eltype);
   t = build1 (ADDR_EXPR, type,
-	  build4 (ARRAY_REF, elem,
+	  build4 (ARRAY_REF, eltype,
 		  t, integer_zero_node, NULL_TREE, NULL_TREE));
   return t;
 }
Index: gcc/tree.h
===
--- gcc/tree.h	(revision 265496)
+++ gcc/tree.h	(working copy)
@@ -4194,7 +4194,7 @@ extern tree build_call_expr_internal_loc_array (lo
 extern tree maybe_build_call_expr_loc (location_t, combined_fn, tree,
    int, ...);
 extern tree build_alloca_call_expr (tree, unsigned int, HOST_WIDE_INT);
-extern tree build_string_literal (int, const char *);
+extern tree build_string_literal (int, const char *, tree = char_type_node);
 
 /* Construct

[committed] Fix ICE in get_substring_ranges_for_loc on __FILE__ (PR c++/87721)

2018-10-29 Thread David Malcolm
PR c++/87721 reports a crash in get_substring_ranges_for_loc introduced
by r265271, my fix for PR 87562.

The new issue occurs when attempting to get a location with a string
literal inside a macro in which the first token is __FILE__ (formed via
concatenation).  Attempting to get the spelling location of __FILE__
fails, leading to NULL for start_ord_map and final_ord_map, and thus
a NULL pointer dereference.

Given that our "on-demand" substring locations approach reparses the
string literals, there isn't a good way to access the locations inside
such string literals: attempting to reparse __FILE__ fails with a
"missing open quote".

This patch applies the easy fix by gracefully rejecting the case where
the spelling locations for the start or finish give us NULL maps.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

Committed to trunk as r265611.

gcc/ChangeLog:
PR c++/87721
* input.c (get_substring_ranges_for_loc): Detect if
linemap_resolve_location gives us a NULL map, and reject
this case.

gcc/testsuite/ChangeLog:
PR c++/87721
* c-c++-common/substring-location-PR-87721.c: New test.
* gcc.dg/plugin/diagnostic-test-string-literals-1.c: Add test for
PR 87721.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c
(test_string_literals): Fold the index arguments before checking
for INTEGER_CST.
---
 gcc/input.c|  2 ++
 .../c-c++-common/substring-location-PR-87721.c | 11 
 .../plugin/diagnostic-test-string-literals-1.c | 30 ++
 .../diagnostic_plugin_test_string_literals.c   |  6 ++---
 4 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/substring-location-PR-87721.c

diff --git a/gcc/input.c b/gcc/input.c
index 57a1a3c..a94a010 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -1463,6 +1463,8 @@ get_substring_ranges_for_loc (cpp_reader *pfile,
   const line_map_ordinary *final_ord_map;
   linemap_resolve_location (line_table, src_range.m_finish,
LRK_SPELLING_LOCATION, &final_ord_map);
+  if (start_ord_map == NULL || final_ord_map == NULL)
+   return "failed to get ordinary maps";
   /* Bulletproofing.  We ought to only have different ordinary maps
 for start vs finish due to line-length jumps.  */
   if (start_ord_map != final_ord_map
diff --git a/gcc/testsuite/c-c++-common/substring-location-PR-87721.c 
b/gcc/testsuite/c-c++-common/substring-location-PR-87721.c
new file mode 100644
index 000..ba99f1b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/substring-location-PR-87721.c
@@ -0,0 +1,11 @@
+# define DBG_ERROR(dbg_logger, format, args...) if (1){\
+  char dbg_buffer[256]; \
+  __builtin_snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
+  __FILE__":%5d: " format  , __LINE__ , ## args); \
+};
+
+void testPasswordStore1(int argc, char **argv) {
+  const char *pw1="Secret1";
+  char pw[256];
+  DBG_ERROR(0, "Bad password, expected [%s], got [%s].", pw1, pw);
+}
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c 
b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
index b735095..36324fd 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
@@ -319,3 +319,33 @@ pr87652 (const char *stem, int counter)
^~
  { dg-end-multiline-output "" } */
 }
+
+/* Reproducer for PR 87721.  */
+
+# define OFFSET __builtin_strlen (__FILE__) + __builtin_strlen(":%5d: ")
+
+# define DBG_ERROR(format, caret_idx, start_idx, end_idx)  \
+  do { \
+__emit_string_literal_range(__FILE__":%5d: " format,   \
+   OFFSET + caret_idx, \
+   OFFSET + start_idx, \
+   OFFSET + end_idx);  \
+  } while (0)
+
+/* { dg-error "unable to read substring location: failed to get ordinary maps" 
"" { target *-*-* } 329 } */
+/* { dg-begin-multiline-output "" }
+ __emit_string_literal_range(__FILE__":%5d: " format, \
+ ^~~~
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ __emit_string_literal_range(__FILE__":%5d: " format, \
+ ^
+ { dg-end-multiline-output "" { target c++ } } */
+
+void pr87721 (void) {
+  DBG_ERROR("Bad password, expected [%s], got [%s].", 24, 24, 25); /* { 
dg-message "in expansion of macro 'DBG_ERROR'" } */
+  /* { dg-begin-multiline-output "" }
+   DBG_ERROR("Bad password, expected [%s], got [%s].", 24, 24, 25);
+   ^
+ { dg-end-multiline-output "" } */
+}
diff --git 
a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c 
b/gcc/testsuite/gc

[PATCH] Fix bug 86293

2018-10-29 Thread Nicholas Krause
This fixes the bug on the gcc bugzilla with id, 86293. Basically
a variable is undefined in certain build configuration scentarios
and must be enabled with the attribute marco and the flag, unused 
for it to avoid this build error. Build and regtested on x86_64_gnu,
ok for trunk?

Signed-off-by: Nicholas Krause 
---
 libitm/method-serial.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libitm/method-serial.cc b/libitm/method-serial.cc
index e4804946a34..ab23d0b5660 100644
--- a/libitm/method-serial.cc
+++ b/libitm/method-serial.cc
@@ -306,7 +306,7 @@ GTM::gtm_thread::serialirr_mode ()
   // We're already serial, so we don't need to ensure privatization safety
   // for other transactions here.
   gtm_word priv_time = 0;
-  bool ok = disp->trycommit (priv_time);
+  bool ok __attribute__((unused)) = disp->trycommit (priv_time);
   // Given that we're already serial, the trycommit better work.
   assert (ok);
 }
-- 
2.17.1



std::vector fix & enhancements

2018-10-29 Thread François Dumont
Following Marc Glisse change to ignore _M_start offset I wanted to go a 
little step further and just remove it in _GLIBCXX_INLINE_VERSION mode.


I also fix a regression we already fixed on mainstream std::vector 
regarding noexcept qualification of move constructor with allocator.


And I implemented the same optimizations than in std::vector for 
allocators always comparing equals and for the std::swap operation.


I also avoid re-implementing in vector::operator[] the same code already 
implemented in iterator::operator[] but this one should perhaps go in a 
different commit.



    * include/bits/stl_bvector.h
    [_GLIBCXX_INLINE_VERSION](_Bvector_impl_data::_M_start): Define as
    _Bit_type*.
    (_Bvector_impl_data(const _Bvector_impl_data&)): New.
    (_Bvector_impl_data(_Bvector_impl_data&&)): Delegate to latter.
    (_Bvector_impl_data::operator=(const _Bvector_impl_data&)): New.
(_Bvector_impl_data::_M_move_data(_Bvector_impl_data&&)): Use latter.
    (_Bvector_impl_data::_M_reset()): Likewise.
    (_Bvector_impl_data::_M_begin()): New.
    (_Bvector_impl_data::_M_cbegin()): New.
    (_Bvector_impl_data::_M_start_p()): New.
    (_Bvector_impl_data::_M_set_start(_Bit_type*)): New.
    (_Bvector_impl_data::_M_swap_data): New.
    (_Bvector_impl::_Bvector_impl(_Bvector_impl&&)): Implement explicitely.
    (_Bvector_impl::_Bvector_impl(_Bit_alloc_type&&, _Bvector_impl&&)): 
New.

    (_Bvector_base::_Bvector_base(_Bvector_base&&, const allocator_type&)):
    New.
    (_Bvector_base::_M_deallocate()): Adapt.
    (vector::vector(const vector&, const allocator_type&)): Adapt.
    (vector::vector(vector&&, const allocator_type&, true_type)): New.
    (vector::vector(vector&&, const allocator_type&, false_type)): New.
    (vector::vector(vector&&, const allocator_type&)): Use latters.
    (vector::vector(const vector&, const allocator_type&)): Adapt.
    (vector::begin()): Adapt.
    (vector::cbegin()): Adapt.
    (vector::operator[](size_type)): Use iterator operator[].
    (vector::swap(vector&)): Adapt.
    (vector::flip()): Adapt.
    (vector::_M_initialize(size_type)): Adapt.
    (vector::_M_initialize_value(bool)): Adapt.
    * include/bits/vector.tcc:
    (vector::_M_reallocate(size_type)): Adapt.
    (vector::_M_fill_insert(iterator, size_type, bool)): Adapt.
    (vector::_M_insert_range<_FwdIter>(iterator, _FwdIter, _FwdIter
    std::forward_iterator_tag)): Adapt.
    (vector::_M_insert_aux(iterator, bool)): Adapt.
    (std::hash>::operator()): Adapt.
    * testsuite/23_containers/vector/bool/cons/noexcept_move_construct.cc:
    Add check.

Tested under Linux x86_64.

Ok to commit ?

François

diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h
index 8fbef7a1a3a..81b4a75236d 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -437,7 +437,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   struct _Bvector_impl_data
   {
+#if !_GLIBCXX_INLINE_VERSION
 	_Bit_iterator	_M_start;
+#else
+	_Bit_type*	_M_start;
+#endif
 	_Bit_iterator	_M_finish;
 	_Bit_pointer	_M_end_of_storage;
 
@@ -447,32 +451,74 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
 #if __cplusplus >= 201103L
 	_Bvector_impl_data(_Bvector_impl_data&& __x) noexcept
-	: _M_start(__x._M_start), _M_finish(__x._M_finish)
-	, _M_end_of_storage(__x._M_end_of_storage)
+	: _Bvector_impl_data(__x)
 	{ __x._M_reset(); }
 
+	_Bvector_impl_data(const _Bvector_impl_data&) = default;
+	_Bvector_impl_data&
+	operator=(const _Bvector_impl_data&) = default;
+
 	void
 	_M_move_data(_Bvector_impl_data&& __x) noexcept
 	{
-	  this->_M_start = __x._M_start;
-	  this->_M_finish = __x._M_finish;
-	  this->_M_end_of_storage = __x._M_end_of_storage;
+	  *this = __x;
 	  __x._M_reset();
 	}
+#else
+	_Bvector_impl_data(const _Bvector_impl_data& __x)
+	  : _M_start(__x._M_start), _M_finish(__x._M_finish)
+	  , _M_end_of_storage(__x._M_end_of_storage)
+	{ }
+
+	_Bvector_impl_data&
+	operator=(const _Bvector_impl_data& __x)
+	{
+	  _M_start = __x._M_start;
+	  _M_finish = __x._M_finish;
+	  _M_end_of_storage = __x._M_end_of_storage;
+	}
+#endif
+
+	_Bit_iterator
+	_M_begin() const _GLIBCXX_NOEXCEPT
+	{ return _Bit_iterator(_M_start_p(), 0); }
+
+	_Bit_const_iterator
+	_M_cbegin() const _GLIBCXX_NOEXCEPT
+	{ return _Bit_const_iterator(_M_start_p(), 0); }
+
+	_Bit_type*
+	_M_start_p() const _GLIBCXX_NOEXCEPT
+#if !_GLIBCXX_INLINE_VERSION
+	{ return _M_start._M_p; }
+#else
+	{ return _M_start; }
+#endif
+
+	void
+	_M_set_start(_Bit_type* __p) _GLIBCXX_NOEXCEPT
+#if !_GLIBCXX_INLINE_VERSION
+	{ _M_start._M_p = __p; }
+#else
+	{ _M_start = __p; }
 #endif
 
 	void
 	_M_reset() _GLIBCXX_NOEXCEPT
+	{ *this = _Bvector_impl_data(); }
+
+	void
+	_M_swap_data(_Bvector_impl_data& __x) _GLIBCXX_NOEXCEPT
 	{
-	  _M_start = _M_finish = _Bit_iterator();
-	  _M_end_of_storage = _Bit_pointer();
+	  // Do not use std::swap(_M_start, __x._M_start), etc as it loses
+	  // information used by TBAA.
+	  s