[Patch, fortran] PR91729 - ICE in gfc_match_select_rank, at fortran/match.c:6586

2019-09-23 Thread Paul Richard Thomas
Fixed as obvious in revision: 276051.

The patch is largely due to Steve, for which thanks.

Paul

2019-09-23  Paul Thomas  

PR fortran/91729
* match.c (gfc_match_select_rank): Initialise 'as' to NULL.
Check for a symtree in the selector expression before trying to
assign a value to 'as'. Revert to gfc_error and go to cleanup
after setting a MATCH_ERROR.

2019-09-23  Paul Thomas  

PR fortran/91729
* gfortran.dg/select_rank_2.f90 : Add two more errors in foo2.
* gfortran.dg/select_rank_3.f90 : New test.


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


[PATCH], V4.1, patch #2: Add prefixed insn attribute (revised)

2019-09-23 Thread Michael Meissner
This patch revises patch #2, fixing an issue that shows up in compiling large
code like the Spec 2017 benchmark suite.  The issue was when a vector register
uses TImode, it needs to assume the non-prefixed instruction uses the DQ
encoding.

I also changed the spelling of PC-relative to be consitant.

The patch is also adjusted due to the changes made in the revised patch #1.

Assuming the revised patch #1 is checked in, can I check in this revised patch
into the trunk?  I did a bootstrap and make check with the patch and there were
no regressions.  I applied the remaining patches, and they also have no
regressions, and they can build the Spec 2017 test suite.

2019-09-23  Michael Meissner  

* config/rs6000/rs6000-protos.h (prefixed_load_p): New
declaration.
(prefixed_store_p): New declaration.
(prefixed_paddi_p): New declaration.
(rs6000_asm_output_opcode): New declaration.
(rs6000_final_prescan_insn): Move declaration and update calling
signature.
(address_is_prefixed): New helper inline function.
* config/rs6000/rs6000.c (rs6000_emit_move): Support loading
PC-relative addresses.
(reg_to_non_prefixed): New function to identify what the
non-prefixed memory instruction format is for a register.
(prefixed_load_p): New function to identify prefixed loads.
(prefixed_store_p): New function to identify prefixed stores.
(prefixed_paddi_p): New function to identify prefixed load
immediates.
(next_insn_prefixed_p): New static state variable.
(rs6000_final_prescan_insn): New function to determine if an insn
uses a prefixed instruction.
(rs6000_asm_output_opcode): New function to emit 'p' in front of a
prefixed instruction.
* config/rs6000/rs6000.h (FINAL_PRESCAN_INSN): New target hook.
(ASM_OUTPUT_OPCODE): New target hook.
* config/rs6000/rs6000.md (prefixed): New insn attribute for
prefixed instructions.
(prefixed_length): New insn attribute for the size of prefixed
instructions.
(non_prefixed_length): New insn attribute for the size of
non-prefixed instructions.
(pcrel_local_addr): New insn to load up a local PC-relative
address.
(pcrel_extern_addr): New insn to load up an external PC-relative
address.

Index: gcc/config/rs6000/rs6000-protos.h
===
--- gcc/config/rs6000/rs6000-protos.h   (revision 276069)
+++ gcc/config/rs6000/rs6000-protos.h   (working copy)
@@ -189,6 +189,30 @@ enum non_prefixed {
 
 extern enum insn_form address_to_insn_form (rtx, machine_mode,
enum non_prefixed);
+extern bool prefixed_load_p (rtx_insn *);
+extern bool prefixed_store_p (rtx_insn *);
+extern bool prefixed_paddi_p (rtx_insn *);
+extern void rs6000_asm_output_opcode (FILE *);
+extern void rs6000_final_prescan_insn (rtx_insn *, rtx [], int);
+
+/* Return true if the address is a prefixed instruction that can be directly
+   used in a memory instruction (i.e. using numeric offset or a PC-relative
+   reference to a local symbol).
+
+   References to external PC-relative symbols aren't allowed, because GCC has
+   to load the address into a register and then issue a separate load or
+   store.  */
+
+static inline bool
+address_is_prefixed (rtx addr,
+machine_mode mode,
+enum non_prefixed non_prefixed_insn)
+{
+  enum insn_form iform = address_to_insn_form (addr, mode,
+  non_prefixed_insn);
+  return (iform == INSN_FORM_PREFIXED_NUMERIC
+ || iform == INSN_FORM_PCREL_LOCAL);
+}
 #endif /* RTX_CODE */
 
 #ifdef TREE_CODE
@@ -268,8 +292,6 @@ extern void rs6000_d_target_versions (vo
 const char * rs6000_xcoff_strip_dollar (const char *);
 #endif
 
-void rs6000_final_prescan_insn (rtx_insn *, rtx *operand, int num_operands);
-
 extern unsigned char rs6000_class_max_nregs[][LIM_REG_CLASSES];
 extern unsigned char rs6000_hard_regno_nregs[][FIRST_PSEUDO_REGISTER];
 
Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 276069)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -9639,6 +9639,22 @@ rs6000_emit_move (rtx dest, rtx source,
  return;
}
 
+  /* Use the default pattern for loading up PC-relative addresses.  */
+  if (TARGET_PCREL && mode == Pmode
+ && (SYMBOL_REF_P (operands[1]) || LABEL_REF_P (operands[1])
+ || GET_CODE (operands[1]) == CONST))
+   {
+ enum insn_form iform = address_to_insn_form (operands[1], mode,
+  NON_PREFIXED_DEFAULT);
+
+ if (iform == INSN_FORM_PCREL_LOCAL
+ || iform == INSN_FORM_PCREL_EXTERNAL)
+   {
+ emit_insn (gen_r

[PATCH] V4.1, patch #1: Rework prefixed/pc-relative lookup (revised)

2019-09-23 Thread Michael Meissner
This patch replaces patch #1.  It tries to address most/all of the review
comments.

This patch bootstraps fine, and there are no regressions.  When I applied this
patch, the revised patch #2 that will be posted next and the other patches, it
builds Spec 2017 with -mcpu=future.  The other patches were the same other than
trying to be consistant about spelling PC-relative (and line numbers adjusted
due to patches #1/#2 being reworked).  Can I check this into trunk?

2019-09-23  Michael Meissner  

* config/rs6000/predicates.md (pcrel_address): Delete predicate.
(pcrel_local_address): Replace pcrel_address predicate, use the
new function address_to_insn_form.
(pcrel_external_address): Replace with new implementation using
address_to_insn_form..
(prefixed_mem_operand): Delete predicate which is now unused.
(pcrel_external_mem_operand): Delete predicate which is now
unused.
* config/rs6000/rs6000-protos.h (enum insn_form): New
enumeration.
(enum non_prefixed): New enumeration.
(address_to_insn_form): New declaration.
* config/rs6000/rs6000.c (print_operand_address): Check for either
PC-relative local symbols or PC-relative external symbols.
(mode_supports_prefixed_address_p): Delete, no longer used.
(rs6000_prefixed_address_mode_p): Delete, no longer used.
(address_to_insn_form): New function to decode an address format.

Index: gcc/config/rs6000/predicates.md
===
--- gcc/config/rs6000/predicates.md (revision 276068)
+++ gcc/config/rs6000/predicates.md (working copy)
@@ -1625,82 +1625,7 @@ (define_predicate "small_toc_ref"
   return GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_TOCREL;
 })
 
-;; Return true if the operand is a pc-relative address.
-(define_predicate "pcrel_address"
-  (match_code "label_ref,symbol_ref,const")
-{
-  if (!rs6000_pcrel_p (cfun))
-return false;
-
-  if (GET_CODE (op) == CONST)
-op = XEXP (op, 0);
-
-  /* Validate offset.  */
-  if (GET_CODE (op) == PLUS)
-{
-  rtx op0 = XEXP (op, 0);
-  rtx op1 = XEXP (op, 1);
-
-  if (!CONST_INT_P (op1) || !SIGNED_34BIT_OFFSET_P (INTVAL (op1)))
-   return false;
-
-  op = op0;
-}
-
-  if (LABEL_REF_P (op))
-return true;
-
-  return (SYMBOL_REF_P (op) && SYMBOL_REF_LOCAL_P (op));
-})
-
-;; Return true if the operand is an external symbol whose address can be loaded
-;; into a register using:
-;; PLD reg,label@pcrel@got
-;;
-;; The linker will either optimize this to either a PADDI if the label is
-;; defined locally in another module or a PLD of the address if the label is
-;; defined in another module.
-
-(define_predicate "pcrel_external_address"
-  (match_code "symbol_ref,const")
-{
-  if (!rs6000_pcrel_p (cfun))
-return false;
-
-  if (GET_CODE (op) == CONST)
-op = XEXP (op, 0);
-
-  /* Validate offset.  */
-  if (GET_CODE (op) == PLUS)
-{
-  rtx op0 = XEXP (op, 0);
-  rtx op1 = XEXP (op, 1);
-
-  if (!CONST_INT_P (op1) || !SIGNED_34BIT_OFFSET_P (INTVAL (op1)))
-   return false;
-
-  op = op0;
-}
-
-  return (SYMBOL_REF_P (op) && !SYMBOL_REF_LOCAL_P (op));
-})
-
-;; Return 1 if op is a prefixed memory operand.
-(define_predicate "prefixed_mem_operand"
-  (match_code "mem")
-{
-  return rs6000_prefixed_address_mode_p (XEXP (op, 0), GET_MODE (op));
-})
-
-;; Return 1 if op is a memory operand to an external variable when we
-;; support pc-relative addressing and the PCREL_OPT relocation to
-;; optimize references to it.
-(define_predicate "pcrel_external_mem_operand"
-  (match_code "mem")
-{
-  return pcrel_external_address (XEXP (op, 0), Pmode);
-})
-
+
 ;; Match the first insn (addis) in fusing the combination of addis and loads to
 ;; GPR registers on power8.
 (define_predicate "fusion_gpr_addis"
@@ -1857,3 +1782,28 @@ (define_predicate "fusion_addis_mem_comb
 
   return 0;
 })
+
+
+;; Return true if the operand is a PC-relative address to a local symbol or a
+;; label that can be used directly in a memory operation.
+(define_predicate "pcrel_local_address"
+  (match_code "label_ref,symbol_ref,const")
+{
+  enum insn_form iform = address_to_insn_form (op, mode, NON_PREFIXED_DEFAULT);
+  return iform == INSN_FORM_PCREL_LOCAL;
+})
+
+;; Return true if the operand is a PC-relative external symbol whose address
+;; can be loaded into a register.
+(define_predicate "pcrel_external_address"
+  (match_code "symbol_ref,const")
+{
+  enum insn_form iform = address_to_insn_form (op, mode, NON_PREFIXED_DEFAULT);
+  return iform == INSN_FORM_PCREL_EXTERNAL;
+})
+
+;; Return true if the address is PC-relative and the symbol is either local or
+;; external.
+(define_predicate "pcrel_local_or_external_address"
+  (ior (match_operand 0 "pcrel_local_address")
+   (match_operand 0 "pcrel_external_address")))
Index: gcc/config/rs6000/rs6000-protos.h
===

Re: [PATCH] Remove unused #include "vec.h" from hash-table.h

2019-09-23 Thread Bernhard Reutner-Fischer
On Mon, 23 Sep 2019 14:52:19 -0500
"Christian Biesinger via gcc-patches"  wrote:

> From: Christian Biesinger 
> 
> Removes an unused include as a cleanup. Requires updating
> lots of files who previously relied on this transitive include.

Note that we have a tool to help prune unused includes, somewhere.
It's usually run late in stage1, not sure when we did that last time
though..
> 
> I have only been able to test this on x86_64 because I failed
> at building a cross compiler.

contrib/config-list.mk is supposed help verify this. I suggest to read the top 
2 comment blocks.

you'll probably send up with something along the lines of
make -f ../../gcc-trunk/contrib/config-list.mk \
  GCC_SRC_DIR=your-abs-path-to-gcc \
  host_options='your stuff here'

HTH,


[PATCH] driver: Also prune joined switches with negation

2019-09-23 Thread Matt Turner
When -march=native is passed to host_detect_local_cpu to the backend,
it overrides all command lines after it.  That means

$ gcc -march=native -march=armv8-a

is treated as

$ gcc -march=armv8-a -march=native

Prune joined switches with Negative and RejectNegative to allow
-march=armv8-a to override previous -march=native on command-line.

This is the same fix as was applied for i386 in SVN revision 269164 but for
aarch64 and arm.

gcc/

PR driver/69471
* config/aarch64/aarch64.opt (march=): Add Negative(march=).
(mtune=): Add Negative(mtune=).
* config/arm/arm.opt: Likewise.
---
 gcc/config/aarch64/aarch64.opt | 5 +++--
 gcc/config/arm/arm.opt | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt
index 865b6a6d8ca..908dca23b3c 100644
--- a/gcc/config/aarch64/aarch64.opt
+++ b/gcc/config/aarch64/aarch64.opt
@@ -119,7 +119,8 @@ EnumValue
 Enum(aarch64_tls_size) String(48) Value(48)
 
 march=
-Target RejectNegative ToLower Joined Var(aarch64_arch_string)
+Target RejectNegative Negative(march=) ToLower Joined Var(aarch64_arch_string)
+
 Use features of architecture ARCH.
 
 mcpu=
@@ -127,7 +128,7 @@ Target RejectNegative ToLower Joined Var(aarch64_cpu_string)
 Use features of and optimize for CPU.
 
 mtune=
-Target RejectNegative ToLower Joined Var(aarch64_tune_string)
+Target RejectNegative Negative(mtune=) ToLower Joined Var(aarch64_tune_string)
 Optimize for CPU.
 
 mabi=
diff --git a/gcc/config/arm/arm.opt b/gcc/config/arm/arm.opt
index 452f0cf6d67..e3ead5c95d1 100644
--- a/gcc/config/arm/arm.opt
+++ b/gcc/config/arm/arm.opt
@@ -82,7 +82,7 @@ mapcs-stack-check
 Target Report Mask(APCS_STACK) Undocumented
 
 march=
-Target RejectNegative ToLower Joined Var(arm_arch_string)
+Target RejectNegative Negative(march=) ToLower Joined Var(arm_arch_string)
 Specify the name of the target architecture.
 
 ; Other arm_arch values are loaded from arm-tables.opt
@@ -232,7 +232,7 @@ Target Report Mask(TPCS_LEAF_FRAME)
 Thumb: Generate (leaf) stack frames even if not needed.
 
 mtune=
-Target RejectNegative ToLower Joined Var(arm_tune_string)
+Target RejectNegative Negative(mtune=) ToLower Joined Var(arm_tune_string)
 Tune code for the given processor.
 
 mprint-tune-info
-- 
2.21.0



Re: [patch, libgfortran] Bug 91593 - Implicit enum conversions in libgfortran/io/transfer.c

2019-09-23 Thread Jerry DeLisle

On 9/23/19 8:52 AM, Bernhard Reutner-Fischer wrote:

On 22 September 2019 22:51:46 CEST, Jerry DeLisle  wrote:

Hi all,

The attached patch eliminates several warnings by adjusting which
enumerator is
used in the subject offending code. I fixed this by adding an
enumerator at the
end of the file_mode definition.  This then triggered a warning in
several other
places for an unhandled case in the switch statements. I cleared those
by
throwing in an assert (false) since it cant happen unless something
really goes
wrong somehow.


I'm curious why you assert (false) instead of the usual gcc_unreachable ()?

Thanks,



Because I forgot all about gcc_unreachable.  I will give it a try.

Jerry


C++ PATCH for c++/91845 - ICE with invalid pointer-to-member.

2019-09-23 Thread Marek Polacek
build_m_component_ref checks if either datum/component it got are erroneous but
they can be turned into the error_mark_node by mark_use as in this case: datum
is "a" before the call to mark_lvalue_use, but that emits an error and returns
the error_mark_node, which then crashes.

We can just move the checks after calling mark_[lr]value_use; those just
return when they get the error_mark_node.  But I tweaked mark_use to also
handle the case when the type is erroneous.

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

2019-09-23  Marek Polacek  

PR c++/91845 - ICE with invalid pointer-to-member.
* expr.c (mark_use): Use error_operand_p.
* typeck2.c (build_m_component_ref): Check error_operand_p after
calling mark_[lr]value_use.

* g++.dg/cpp1y/pr91845.C: New test.

diff --git gcc/cp/expr.c gcc/cp/expr.c
index 212a7f93c5a..d488912d5db 100644
--- gcc/cp/expr.c
+++ gcc/cp/expr.c
@@ -96,7 +96,7 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
 {
 #define RECUR(t) mark_use ((t), rvalue_p, read_p, loc, reject_builtin)
 
-  if (expr == NULL_TREE || expr == error_mark_node)
+  if (expr == NULL_TREE || error_operand_p (expr))
 return expr;
 
   if (reject_builtin && reject_gcc_builtin (expr, loc))
diff --git gcc/cp/typeck2.c gcc/cp/typeck2.c
index d5098fa24bb..58fa54f40af 100644
--- gcc/cp/typeck2.c
+++ gcc/cp/typeck2.c
@@ -2068,12 +2068,12 @@ build_m_component_ref (tree datum, tree component, 
tsubst_flags_t complain)
   tree binfo;
   tree ctype;
 
-  if (error_operand_p (datum) || error_operand_p (component))
-return error_mark_node;
-
   datum = mark_lvalue_use (datum);
   component = mark_rvalue_use (component);
 
+  if (error_operand_p (datum) || error_operand_p (component))
+return error_mark_node;
+
   ptrmem_type = TREE_TYPE (component);
   if (!TYPE_PTRMEM_P (ptrmem_type))
 {
diff --git gcc/testsuite/g++.dg/cpp1y/pr91845.C 
gcc/testsuite/g++.dg/cpp1y/pr91845.C
new file mode 100644
index 000..cb80dd7a8a7
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1y/pr91845.C
@@ -0,0 +1,14 @@
+// PR c++/91845 - ICE with invalid pointer-to-member.
+// { dg-do compile { target c++14 } }
+
+void non_const_mem_ptr() {
+  struct A {
+  };
+  constexpr A a = {1, 2}; // { dg-error "too many initializers" }
+  struct B {
+int A::*p;
+constexpr int g() const {
+  return a.*p; // { dg-error "use of local variable" }
+};
+  };
+}


C++ PATCH for c++/91868 - improve -Wshadow location.

2019-09-23 Thread Marek Polacek
We can improve various -Wshadow warnings by using DECL_SOURCE_LOCATION
rather than whatever is in input_location.

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

2019-09-23  Marek Polacek  

PR c++/91868 - improve -Wshadow location.
* name-lookup.c (check_local_shadow): Use DECL_SOURCE_LOCATION
instead of input_location.

* g++.dg/warn/Wshadow-16.C: New test.

diff --git gcc/cp/name-lookup.c gcc/cp/name-lookup.c
index 8bbb92ddc9f..74f1072fa8c 100644
--- gcc/cp/name-lookup.c
+++ gcc/cp/name-lookup.c
@@ -2771,7 +2771,7 @@ check_local_shadow (tree decl)
msg = "declaration of %qD shadows a previous local";
 
   auto_diagnostic_group d;
-  if (warning_at (input_location, warning_code, msg, decl))
+  if (warning_at (DECL_SOURCE_LOCATION (decl), warning_code, msg, decl))
inform_shadowed (old);
   return;
 }
@@ -2798,7 +2798,7 @@ check_local_shadow (tree decl)
|| TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
  {
auto_diagnostic_group d;
-   if (warning_at (input_location, OPT_Wshadow,
+   if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
"declaration of %qD shadows a member of %qT",
decl, current_nonlambda_class_type ())
&& DECL_P (member))
@@ -2818,7 +2818,7 @@ check_local_shadow (tree decl)
 /* XXX shadow warnings in outer-more namespaces */
 {
   auto_diagnostic_group d;
-  if (warning_at (input_location, OPT_Wshadow,
+  if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
  "declaration of %qD shadows a global declaration",
  decl))
inform_shadowed (old);
diff --git gcc/testsuite/g++.dg/warn/Wshadow-16.C 
gcc/testsuite/g++.dg/warn/Wshadow-16.C
new file mode 100644
index 000..1ba54ec107d
--- /dev/null
+++ gcc/testsuite/g++.dg/warn/Wshadow-16.C
@@ -0,0 +1,24 @@
+// PR c++/91868 - improve -Wshadow location.
+// { dg-options "-Wshadow" }
+
+int global; // { dg-message "shadowed declaration" }
+
+struct S
+{
+  static int bar; // { dg-message "shadowed declaration" }
+  S (int i) { int bar // { dg-warning "19:declaration of .bar. shadows a 
member" }
+  (1);
+int global // { dg-warning "9:declaration of .global. shadows a global 
declaration" }
+  (42);
+  }
+};
+
+void
+foo ()
+{
+  int xx; // { dg-message "shadowed declaration" }
+  {
+S xx // { dg-warning "7:declaration of .xx. shadows a previous local" }
+(42);
+  }
+}


Re: [PING^2][PATCH 0/3] GNAT test suite fixes for build sysroot

2019-09-23 Thread Maciej W. Rozycki
On Mon, 16 Sep 2019, Arnaud Charlet wrote:

> > > In the course of setting up GCC regression testing for the RISC-V target 
> > > I have discovered that the GNAT test suite does not correctly respond to 
> > > the test environment settings passed from the test harness in my setup 
> > > and 
> > > consequently no test case works correctly.
> > 
> >  Ping for:
> > 
> > 
> > 
> 
> Assuming good Ada test results with these changes for both
> RISC-V and native linux x86_64, OK for me.

 I have completed regression-testing now and there were no changes at all 
for native x86_64/Linux and only progressions for crossed RISC-V/Linux:

$ diff -u old/gnat.sum new/gnat.sum | sed -n 
'/^\(+FAIL\|-PASS\)/p;/Summary/,${s,^.*/,,;p}'
=== gnat Summary ===
 
-# of expected passes   2137
-# of unexpected failures   710
+# of expected passes   3184
+# of unexpected failures   6
 # of expected failures 23
 # of unsupported tests 28
gnatmake version 10.0.0 20190917 (experimental)

I have therefore committed 2/3 now, however 3/3 requires a DejaGNU 
maintainer's attention.

 Thanks for your review.

  Maciej


Re: [PATCH] fold more string comparison with known result (PR 90879)

2019-09-23 Thread Martin Sebor

On 9/3/19 2:00 PM, Jeff Law wrote:

On 8/28/19 3:12 PM, Martin Sebor wrote:

On 8/22/19 3:31 PM, Jeff Law wrote:

On 8/20/19 8:10 PM, Martin Sebor wrote:

Jeff,

Please let me know if you agree/disagree and what I need to
do to advance this work:

    https://gcc.gnu.org/ml/gcc-patches/2019-08/msg00643.html

For the official record, I agree :-)


Great! :)

Any comments/suggestions on the patch?

   https://gcc.gnu.org/ml/gcc-patches/2019-08/msg00643.html

Martin

Yea, they were in an earlier message.  I'll extract the relevant
comments since some we addressed independently:


  
  
  
@@ -325,7 +333,7 @@ state_ident_by_name (const char *name, enum insert_option optins)

namlen = strlen (name);
stid =
  (struct state_ident_st *) xmalloc (sizeof (struct state_ident_st) +
-  namlen);
+  namlen + 1);
memset (stid, 0, sizeof (struct state_ident_st) + namlen);
strcpy (stid->stid_name, name);
*slot = stid;

How did you find this goof?




This was more a curiosity than anything.  Nothing we need to change here.


The code is correct as is, I just adjusted the allocated amount to
account for the change to use the zero length trailing array instead
of the [1] kind.  But neither was part of the updated patch (I had
initially posted an outdated version of my patch).




diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index fc57fb45e3a..582768090ae 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1346,6 +1346,10 @@ get_range_strlen_tree (tree arg, bitmap *visited, 
strlen_range_kind rkind,
}
  }
  
+  /* Set if VAL represents the maximum length based on array size (set

+ when exact length cannot be determined).  */
+  bool maxbound = false;
+
if (!val && rkind == SRK_LENRANGE)
  {
if (TREE_CODE (arg) == ADDR_EXPR)
@@ -1441,6 +1445,7 @@ get_range_strlen_tree (tree arg, bitmap *visited, 
strlen_range_kind rkind,
  pdata->minlen = ssize_int (0);
}
}
+  maxbound = true;
  }
  
if (!val)

@@ -1454,7 +1459,7 @@ get_range_strlen_tree (tree arg, bitmap *visited, 
strlen_range_kind rkind,
  && tree_int_cst_lt (val, pdata->minlen)))
  pdata->minlen = val;
  
-  if (pdata->maxbound)

+  if (pdata->maxbound && TREE_CODE (pdata->maxbound) == INTEGER_CST)
  {
/* Adjust the tighter (more optimistic) string length bound
 if necessary and proceed to adjust the more conservative

So inside the conditional guarded by the test you're changing above we have:

  if (TREE_CODE (val) == INTEGER_CST)
 {
   if (TREE_CODE (pdata->maxbound) == INTEGER_CST)
 {
   if (tree_int_cst_lt (pdata->maxbound, val))
 pdata->maxbound = val;
 }
   else
 pdata->maxbound = build_all_ones_cst (size_type_node);
 }

Isn't the inner test that pdata->maxbound == INTEGER_CST always true and
we should remove the test and the else clause?


Yes, it looks redundant.  I never remember which of these functions
ICE when their argument is not a constant (e.g., tree_int_cst_lt)
and which ones handle it gracefully (e.g., tree_int_cst_equal) so
I often check even when it isn't necessary.  It would be nice if
these closely related APIs had consistent preconditions.

   Does the else clause

need to be handled elsewhere (I don't see that it would be handled after
your changes).  Or perhaps it just doesn't matter...


It's handled in the else block, except differently than before.


The redundant test of TREE_CODE (pdata->maxbound) == INTEGER_CST is a
bit of nit, but we might as well clean that up.

I couldn't convince myself that losing the else clause handling was
correct or not.


MAXBOUND is only non-constant when set that way by client code to
have the function set it to the longest PHI argument, otherwise
it's either an INTEGER_CST or null.  The inner test may be dead
code, a leftover from something earlier.  Either way, MAXBOUND
is only used for diagnostics so it probably doesn't matter.


@@ -1653,8 +1661,11 @@ get_range_strlen (tree arg, bitmap *visited,
  
  /* Try to obtain the range of the lengths of the string(s) referenced

 by ARG, or the size of the largest array ARG refers to if the range
-   of lengths cannot be determined, and store all in *PDATA.  ELTSIZE
-   is the expected size of the string element in bytes: 1 for char and
+   of lengths cannot be determined, and store all in *PDATA which must
+   be zero-initialized on input except PDATA->MAXBOUND may be set to
+   a non-null tree node other than INTEGER_CST to request to have it
+   set to the length of the longest string in a PHI.  ELTSIZE is
+   the expected size of the string element in bytes: 1 for char and

Is there any reason we can't just make a clean distinction between input
and output objects in this routine?  As an API this seems awkward at best.
Any thoughts on the API quest

Re: [PATCH] Remove unused #include "vec.h" from hash-table.h

2019-09-23 Thread Jason Merrill
On Mon, Sep 23, 2019 at 3:52 PM Christian Biesinger via gcc-patches
 wrote:
>
> From: Christian Biesinger 
>
> Removes an unused include as a cleanup. Requires updating
> lots of files who previously relied on this transitive include.
>
> I have only been able to test this on x86_64 because I failed
> at building a cross compiler.
>
> gcc/ChangeLog:
>
> 2019-09-23  Christian Biesinger  
>
> * bitmap.c: Include vec.h.
> * common/common-target.h: Likewise.
> * common/common-targhooks.h: Likewise.
> * config/aarch64/aarch64-protos.h: Likewise.
> * config/aarch64/aarch64.c: Likewise.
> * config/aarch64/cortex-a57-fma-steering.c: Likewise.
> * config/arc/arc.c: Likewise.
> * config/avr/avr-c.c: Likewise.
> * config/c6x/c6x.c: Likewise.
> * config/cris/cris.c: Likewise.
> * config/darwin.c: Likewise.
> * config/epiphany/resolve-sw-modes.c: Likewise.
> * config/i386/i386-features.c: Likewise.
> * config/i386/i386.c: Likewise.
> * config/ia64/ia64.c: Likewise.
> * config/mips/mips.c: Likewise.
> * config/mn10300/mn10300.c: Likewise.
> * config/nds32/nds32-relax-opt.c: Likewise.
> * config/nds32/nds32.c: Likewise.
> * config/nvptx/nvptx.c: Likewise.
> * config/pa/pa.c: Likewise.
> * config/pdp11/pdp11.c: Likewise.
> * config/rs6000/rs6000-c.c: Likewise.
> * config/rx/rx.c: Likewise.
> * config/s390/s390-c.c: Likewise.
> * config/s390/s390.c: Likewise.
> * config/sparc/sparc.c: Likewise.
> * config/visium/visium.c: Likewise.
> * config/vms/vms.c: Likewise.
> * config/vxworks.c: Likewise.
> * dbgcnt.c: Likewise.
> * diagnostic-show-locus.c: Likewise.
> * edit-context.c: Likewise.
> * fibonacci_heap.h: Likewise.
> * function.h: Likewise.
> * genmatch.c: Likewise.
> * ggc-common.c: Likewise.
> * graphds.h: Likewise.
> * hash-table.h: Remove unused include of vec.h.
> * input.c: Include vec.h.
> * json.h: Likewise.
> * opt-suggestions.h: Likewise.
> * opts.h: Likewise.
> * rtl.h: Likewise.
> * target.h: Likewise.
> * timevar.c: Likewise.
> * tree-core.h: Likewise.
> * typed-splay-tree.c: Likewise.
> * vec.c: Likewise.
> * vector-builder.h: Likewise.
> * vtable-verify.h: Likewise.

This is a surprising list of files.  For instance, common-target.h
uses nothing from vec.h, and most of these files include tree-core.h,
so adding the include there should avoid the need in most other files.

Jason



[PATCH] Remove unused #include "vec.h" from hash-table.h

2019-09-23 Thread Christian Biesinger via gcc-patches
From: Christian Biesinger 

Removes an unused include as a cleanup. Requires updating
lots of files who previously relied on this transitive include.

I have only been able to test this on x86_64 because I failed
at building a cross compiler.

gcc/ChangeLog:

2019-09-23  Christian Biesinger  

* bitmap.c: Include vec.h.
* common/common-target.h: Likewise.
* common/common-targhooks.h: Likewise.
* config/aarch64/aarch64-protos.h: Likewise.
* config/aarch64/aarch64.c: Likewise.
* config/aarch64/cortex-a57-fma-steering.c: Likewise.
* config/arc/arc.c: Likewise.
* config/avr/avr-c.c: Likewise.
* config/c6x/c6x.c: Likewise.
* config/cris/cris.c: Likewise.
* config/darwin.c: Likewise.
* config/epiphany/resolve-sw-modes.c: Likewise.
* config/i386/i386-features.c: Likewise.
* config/i386/i386.c: Likewise.
* config/ia64/ia64.c: Likewise.
* config/mips/mips.c: Likewise.
* config/mn10300/mn10300.c: Likewise.
* config/nds32/nds32-relax-opt.c: Likewise.
* config/nds32/nds32.c: Likewise.
* config/nvptx/nvptx.c: Likewise.
* config/pa/pa.c: Likewise.
* config/pdp11/pdp11.c: Likewise.
* config/rs6000/rs6000-c.c: Likewise.
* config/rx/rx.c: Likewise.
* config/s390/s390-c.c: Likewise.
* config/s390/s390.c: Likewise.
* config/sparc/sparc.c: Likewise.
* config/visium/visium.c: Likewise.
* config/vms/vms.c: Likewise.
* config/vxworks.c: Likewise.
* dbgcnt.c: Likewise.
* diagnostic-show-locus.c: Likewise.
* edit-context.c: Likewise.
* fibonacci_heap.h: Likewise.
* function.h: Likewise.
* genmatch.c: Likewise.
* ggc-common.c: Likewise.
* graphds.h: Likewise.
* hash-table.h: Remove unused include of vec.h.
* input.c: Include vec.h.
* json.h: Likewise.
* opt-suggestions.h: Likewise.
* opts.h: Likewise.
* rtl.h: Likewise.
* target.h: Likewise.
* timevar.c: Likewise.
* tree-core.h: Likewise.
* typed-splay-tree.c: Likewise.
* vec.c: Likewise.
* vector-builder.h: Likewise.
* vtable-verify.h: Likewise.

gcc/fortran/ChangeLog:

2019-09-23  Christian Biesinger  

* gfortran.h: Include vec.h.
---
 gcc/bitmap.c | 1 +
 gcc/common/common-target.h   | 1 +
 gcc/common/common-targhooks.h| 2 ++
 gcc/config/aarch64/aarch64-protos.h  | 1 +
 gcc/config/aarch64/aarch64.c | 1 +
 gcc/config/aarch64/cortex-a57-fma-steering.c | 1 +
 gcc/config/arc/arc.c | 1 +
 gcc/config/avr/avr-c.c   | 1 +
 gcc/config/c6x/c6x.c | 1 +
 gcc/config/cris/cris.c   | 1 +
 gcc/config/darwin.c  | 1 +
 gcc/config/epiphany/resolve-sw-modes.c   | 1 +
 gcc/config/i386/i386-features.c  | 1 +
 gcc/config/i386/i386.c   | 1 +
 gcc/config/ia64/ia64.c   | 1 +
 gcc/config/mips/mips.c   | 1 +
 gcc/config/mn10300/mn10300.c | 1 +
 gcc/config/nds32/nds32-relax-opt.c   | 1 +
 gcc/config/nds32/nds32.c | 1 +
 gcc/config/nvptx/nvptx.c | 1 +
 gcc/config/pa/pa.c   | 1 +
 gcc/config/pdp11/pdp11.c | 1 +
 gcc/config/rs6000/rs6000-c.c | 1 +
 gcc/config/rx/rx.c   | 1 +
 gcc/config/s390/s390-c.c | 1 +
 gcc/config/s390/s390.c   | 1 +
 gcc/config/sparc/sparc.c | 1 +
 gcc/config/visium/visium.c   | 1 +
 gcc/config/vms/vms.c | 1 +
 gcc/config/vxworks.c | 1 +
 gcc/dbgcnt.c | 1 +
 gcc/diagnostic-show-locus.c  | 1 +
 gcc/edit-context.c   | 1 +
 gcc/fibonacci_heap.h | 2 ++
 gcc/fortran/gfortran.h   | 1 +
 gcc/function.h   | 1 +
 gcc/genmatch.c   | 1 +
 gcc/ggc-common.c | 1 +
 gcc/graphds.h| 2 ++
 gcc/hash-table.h | 1 -
 gcc/input.c  | 1 +
 gcc/json.h   | 2 ++
 gcc/opt-suggestions.h| 2 ++
 gcc/opts.h   | 1 +
 gcc/rtl.h| 1 +
 gcc/target.h | 1 +
 gcc/timevar.c| 1 +
 gcc/tree-core.h  | 1 +
 gcc/typed-splay-tree.c   | 1 +
 gcc/vec.c   

Re: [PATCH RS6000], add xxswapd support

2019-09-23 Thread Segher Boessenkool
Hi Carl,

On Mon, Sep 23, 2019 at 08:07:32AM -0700, Carl Love wrote:
>   * config/rs6000/vsx.md (xxswapd_v4si, xxswapd_v8hi, xxswapd_v16qi):
>   New define_insn.
>   (vsx_xxpermdi4_le_, vsx_xxpermdi8_le_V8HI,
>   vsx_xxpermdi16_le_V16QI): Removed define_insn.

If you use "" in a changelog, it usually is handy to say what mode
it is here.  Like in this case, (vsx_xxpermdi4_le_ for VSX_W).

> +(define_insn "xxswapd_v16qi"
> +  [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
> + (vec_select:V16QI
> +   (match_operand:V16QI 1 "vsx_register_operand" "wa")
> +   (parallel [(const_int 8) (const_int 9)
> +  (const_int 10) (const_int 11)
> +  (const_int 12) (const_int 13)
> +  (const_int 14) (const_int 15)
> +  (const_int 0) (const_int 1)
> +  (const_int 2) (const_int 3)
> +  (const_int 4) (const_int 5)
> +  (const_int 6) (const_int 7)])))]
> +   "TARGET_VSX"
> +;; AIX does not support the extended mnemonic xxswapd.  Use the basic
> +;; mnemonic xxpermdi instead.
> +   "xxpermdi %x0,%x1,%x1,2"
>    [(set_attr "type" "vecperm")])

Both of the strings ("TARGET_VSX" and "xxpermdi*") should be indented by
only two spacesC, just like the things above and below them are.

> +;; AIX does not support the extended mnemonic xxswapd.  Use the basic
> +;; mnemonic xxpermdi instead.
> +   "xxpermdi %x0,%x1,%x1,2"
> +   [(set_attr "type" "vecperm")])

For the other two, the [(set_attr... as well: only two spaces.

Okay for trunk with that fixed up.  Thanks!


Segher


Re: [PATCH] V4, patch #1: Rework prefixed/pc-relative lookup

2019-09-23 Thread Michael Meissner
On Fri, Sep 20, 2019 at 08:29:04PM -0500, Segher Boessenkool wrote:
> Hi Mike,
> 
> On Wed, Sep 18, 2019 at 07:49:18PM -0400, Michael Meissner wrote:
> > This patch reworks the prefixed and pc-relative memory matching functions.
> 
> This mostly looks fine, thanks!  A few smaller things:
> 
> 
> > (pcrel_external_address): Replace with new implementation using
> > address_to_insn_form..
> 
> (Two dots is one too many).

Yes.

> > +(define_predicate "pcrel_local_or_external_address"
> > +  (match_code "label_ref,symbol_ref,const")
> > +{
> > +  enum insn_form iform = address_to_insn_form (op, mode, 
> > NON_PREFIXED_DEFAULT);
> > +  return (iform == INSN_FORM_PCREL_EXTERNAL || iform == 
> > INSN_FORM_PCREL_LOCAL);
> > +})
> 
> (define_predicate "pcrel_local_or_external_address"
>   (ior (match_operand 0 "pcrel_local_address")
>(match_operand 0 "pcrel_external_address")))
> 
> (or similar) please.  genpreds will generate effectively the same code
> as you had automatically.

Ok.

> > +/* Different PowerPC instruction formats that are used by GCC.  There are
> > +   various other instruction formats used by the PowerPC hardware, but the
> > +   these formats are not currently used by GCC.  */
> > +
> > +enum insn_form {
> > +  INSN_FORM_BAD,   /* Bad instruction format.  */
> > +  INSN_FORM_BASE_REG,  /* Base register only.  */
> > +  INSN_FORM_D, /* Base register + 16-bit numeric 
> > offset.  */
> > +  INSN_FORM_DS,/* Base register + 14-bit offset + 00.  
> > */
> > +  INSN_FORM_DQ,/* Base register + 12-bit offset + 
> > .  */
> 
> It may be easier to describe DS-form as "D-form, with the offset aligned
> to a (single) word" and DQ-form as "D-form, with the offset aligned to a
> quad-word".  (Or what you do below; see below).

Ok.

> > +  INSN_FORM_X, /* Base register + index register.  */
> > +  INSN_FORM_UPDATE,/* Address udpates base register.  */
> 
> (typo, "updates").
> 
> > +  INSN_FORM_LO_SUM,/* Special offset instruction.  */
> 
> That's a somewhat lame description :-)  It's not really a separate form
> insn anyway, hrm.  Can you come up with a better comment?  I have no
> suggestions, so yeah maybe just keep it like you have.

None of my code uses INSN_FORM_LO_SUM, but I was adding it for completeness,
since it is a valid instruction format (as used within the compiler).

> 
> > +  INSN_FORM_PREFIXED_NUMERIC,  /* Base register + 34 bit numeric 
> > offset.  */
> > +  INSN_FORM_PCREL_LOCAL,   /* Pc-relative local symbol.  */
> > +  INSN_FORM_PCREL_EXTERNAL /* Pc-relative external symbol.  */
> > +};
> 
> Either pc or PC please.  It's an initialism.

Yep.

> 
> > +/* Instruction format for the non-prefixed version of a load or store.  
> > This is
> > +   used to determine if a 16-bit offset is valid to be used with a 
> > non-prefixed
> > +   (traditional) instruction or if the bottom bits of the offset cannot be 
> > used
> > +   with a DS or DQ instruction format, and GCC has to use a prefixed
> > +   instruction for the load or store.  */
> > +
> > +enum non_prefixed {
> > +  NON_PREFIXED_DEFAULT,/* Use the default.  */
> > +  NON_PREFIXED_D,  /* All 16-bits are valid.  */
> > +  NON_PREFIXED_DS, /* Bottom 2 bits must be 0.  */
> > +  NON_PREFIXED_DQ, /* Bottom 4 bits must be 0.  */
> > +  NON_PREFIXED_X   /* No offset memory form exists.  */
> > +};
> 
> Yeah the DS- and DQ-form descriptions here are nicer I think, thanks.
> 
> Maybe non_prefixed_form is a clearer name?  But it is longer of course.
> You decide.

That is fine.

> 
> > +  if (SYMBOL_REF_P (x) && !SYMBOL_REF_LOCAL_P (x))
> > +   fputs ("@got", file);
> > +
> >fputs ("@pcrel", file);
> 
> I'd just use fprintf btw, GCC knows since decades to optimise that to
> fputs, and it is easier to read IMO.  Not that fputs is so super bad,
> but every little we do not have to think helps (helps us think, think
> about more important matters!)

Ok.  It is just the many years of doing C code before GCC did the optimization
is ingrained on me.
 
> > +/* Given an address (ADDR), a mode (MODE), and what the format of the
> > +   non-prefixed address (NON_PREFIXED_INSN) is, return the instruction 
> > format
> > +   for the address.  */
> > +
> > +enum insn_form
> > +address_to_insn_form (rtx addr,
> > + machine_mode mode,
> > + enum non_prefixed non_prefixed_insn)
> 
> non_prefixed_form, instead?
> 
> 
> > +{
> > +  rtx op0, op1;
> 
> You can declare these at first use.  Declaring things in multiple blocks
> (so with shorter scopes) is a bit nicer.
> 
> > +  /* If we don't support offset addressing, make sure only indexed 
> > addressing
> > + is allowed.  We special case SDmode so that the register allocator 
> > does
> > + try to move SDmode through GPR registers, but instead uses the 32-bit
> > + 

Re: [PATCH] PR libstdc++/91788 improve codegen for std::variant::index()

2019-09-23 Thread Marc Glisse

On Mon, 23 Sep 2019, Jonathan Wakely wrote:


If __index_type is a smaller type than size_t, then the result of
size_t(__index_type(-1)) is not equal to size_t(-1), but to an incorrect
value such as size_t(255) or size_t(65535). The old implementation of
variant::index() uses (size_t(__index_type(_M_index + 1)) - 1)
which is always correct, but generates suboptimal code for many common
cases.

When the __index_type is size_t or valueless variants are not possible
we can just return the value directly.

When the number of alternatives is sufficiently small the result of
converting the _M_index value to the corresponding signed type will be
either non-negative or -1. In those cases converting to the signed type
and then to size_t will either produce the correct positive value or
will sign extend -1 to (size_t)-1 as desired.

For the remaining case we keep the existing arithmetic operations to
ensure the correct result.

PR libstdc++/91788 (partial)
* include/std/variant (variant::index()): Improve codegen for cases
where conversion to size_t already works correctly.

Tested x86_64-linux, committed to trunk.


Thanks.

+   if constexpr (is_same_v<__index_type, size_t>)
+ return this->_M_index;

I don't think this special case is useful, gcc has no trouble optimizing 
the other 2 versions to nothing when the types are the same. Of course it 
won't hurt either.


--
Marc Glisse


[C++ PATCH] PR c++/91809 - bit-field and ellipsis.

2019-09-23 Thread Jason Merrill
decay_conversion converts a bit-field access to its declared type, which
isn't what we want here; it even has a comment that the caller is expected
to have already used default_conversion to perform integral promotion.  This
function handles arithmetic promotion differently, but we still don't want
to call decay_conversion before that happens.

Tested x86_64-pc-linux-gnu, applying to trunk.

* call.c (convert_arg_to_ellipsis): Don't call decay_conversion for
arithmetic arguments.
---
 gcc/cp/call.c | 14 +++---
 gcc/testsuite/g++.dg/overload/ellipsis4.C | 12 
 gcc/cp/ChangeLog  |  6 ++
 3 files changed, 25 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/overload/ellipsis4.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2dad699622e..12b495d6e8d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7485,15 +7485,9 @@ convert_like_real (conversion *convs, tree expr, tree 
fn, int argnum,
 tree
 convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
 {
-  tree arg_type;
+  tree arg_type = TREE_TYPE (arg);
   location_t loc = cp_expr_loc_or_input_loc (arg);
 
-  /* [expr.call]
-
- The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
- standard conversions are performed.  */
-  arg = decay_conversion (arg, complain);
-  arg_type = TREE_TYPE (arg);
   /* [expr.call]
 
  If the argument has integral or enumeration type that is subject
@@ -7536,6 +7530,12 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t 
complain)
   else
arg = cp_perform_integral_promotions (arg, complain);
 }
+  else
+/* [expr.call]
+
+   The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
+   standard conversions are performed.  */
+arg = decay_conversion (arg, complain);
 
   arg = require_complete_type_sfinae (arg, complain);
   arg_type = TREE_TYPE (arg);
diff --git a/gcc/testsuite/g++.dg/overload/ellipsis4.C 
b/gcc/testsuite/g++.dg/overload/ellipsis4.C
new file mode 100644
index 000..9bade5af330
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/ellipsis4.C
@@ -0,0 +1,12 @@
+// { dg-additional-options "-Wformat" }
+
+extern "C" int printf (const char *, ...);
+
+struct X {
+  unsigned long long a: 1;
+} x;
+
+void foo()
+{
+  printf("%d", x.a);
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4420d8ffab7..f49d8c96ce0 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2019-09-23  Jason Merrill  
+
+   PR c++/91809 - bit-field and ellipsis.
+   * call.c (convert_arg_to_ellipsis): Don't call decay_conversion for
+   arithmetic arguments.
+
 2019-09-22  Marek Polacek  
 
PR c++/91819 - ICE with operator++ and enum.

base-commit: 6e34bdafb79ee53cde9ff9893c419f6ebcff96fc
-- 
2.21.0



Re: C++ PATCH for c++/91844 - Implement CWG 2352, Similar types and reference binding.

2019-09-23 Thread Jason Merrill

On 9/23/19 12:06 PM, Marek Polacek wrote:

On Mon, Sep 23, 2019 at 10:17:00AM -0400, Jason Merrill wrote:

On 9/22/19 3:23 PM, Marek Polacek wrote:

+  /* Informally, two types are similar if, ignoring top-level cv-qualification:
+ * they are the same type; or
+ * they are both pointers, and the pointed-to types are similar; or
+ * they are both pointers to member of the same class, and the types of
+   the pointed-to members are similar; or
+ * they are both arrays of the same size or both arrays of unknown bound,
+   and the array element types are similar.  */


Yes.


+  if ((TREE_CODE (type1) == POINTER_TYPE && TREE_CODE (type2) == POINTER_TYPE)
+  || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
+  || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
+{
+  int result = comp_cv_qual_signature (TREE_TYPE (type1),
+  TREE_TYPE (type2));


Using comp_cv_qual_signature means that we only return true if one
cv-qualification signature is a subset of the other, but the definition of
'similar' is such that we should completely ignore cv-quals.  int const **
and int *const* are similar even though neither can convert to the other.


Ah, true, what I actually want is comp_ptr_ttypes_const.  I didn't notice
because as you say, the conversion would fail with "discarding qualifiers".
But similar_type_p shouldn't give the wrong answer.

The handling of arrays will come in P0388R4.



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


OK.

Jason


[PR 91831] Copy PARM_DECLs of artificial thunks

2019-09-23 Thread Martin Jambor
Hi,

I am quite surprised I did not catch this before but the new
ipa-param-manipulation does not copy PARM_DECLs when creating artificial
thinks (I think it originally did but then I somehow removed during one
cleanups).  Fixed below by adding the capability at the natural place.
It is triggered whenever context of the PARM_DECL that is just taken
from the original function does not match the target fndecl rather than
by some constructor parameter because in such situation it is always the
correct thing to do.

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin

2019-09-23  Martin Jambor  

PR ipa/91831
* ipa-param-manipulation.c (carry_over_param): Make a method of
ipa_param_body_adjustments, remove now unnecessary argument.  Also copy
in case of a context mismatch.
(ipa_param_body_adjustments::common_initialization): Adjust call to
carry_over_param.
* ipa-param-manipulation.h (class ipa_param_body_adjustments): Add
private method carry_over_param.

testsuite/
* g++.dg/ipa/pr91831.C: New test.
---
 gcc/ipa-param-manipulation.c   | 22 ++
 gcc/ipa-param-manipulation.h   |  1 +
 gcc/testsuite/g++.dg/ipa/pr91831.C | 19 +++
 3 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr91831.C

diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 7f52e9c2506..913b96fefa4 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -906,18 +906,24 @@ ipa_param_body_adjustments::register_replacement 
(ipa_adjusted_param *apm,
   m_replacements.safe_push (psr);
 }
 
-/* Copy or not, as appropriate given ID, a pre-existing PARM_DECL T so that
-   it can be included in the parameters of the modified function.  */
+/* Copy or not, as appropriate given m_id and decl context, a pre-existing
+   PARM_DECL T so that it can be included in the parameters of the modified
+   function.  */
 
-static tree
-carry_over_param (tree t, struct copy_body_data *id)
+tree
+ipa_param_body_adjustments::carry_over_param (tree t)
 {
   tree new_parm;
-  if (id)
+  if (m_id)
 {
-  new_parm = remap_decl (t, id);
+  new_parm = remap_decl (t, m_id);
   if (TREE_CODE (new_parm) != PARM_DECL)
-   new_parm = id->copy_decl (t, id);
+   new_parm = m_id->copy_decl (t, m_id);
+}
+  else if (DECL_CONTEXT (t) != m_fndecl)
+{
+  new_parm = copy_node (t);
+  DECL_CONTEXT (new_parm) = m_fndecl;
 }
   else
 new_parm = t;
@@ -982,7 +988,7 @@ ipa_param_body_adjustments::common_initialization (tree 
old_fndecl,
  || apm->prev_clone_adjustment)
{
  kept[prev_index] = true;
- new_parm = carry_over_param (m_oparms[prev_index], m_id);
+ new_parm = carry_over_param (m_oparms[prev_index]);
  m_new_decls.quick_push (new_parm);
}
   else if (apm->op == IPA_PARAM_OP_NEW
diff --git a/gcc/ipa-param-manipulation.h b/gcc/ipa-param-manipulation.h
index 34477da51b7..8e9554563e4 100644
--- a/gcc/ipa-param-manipulation.h
+++ b/gcc/ipa-param-manipulation.h
@@ -370,6 +370,7 @@ public:
 private:
   void common_initialization (tree old_fndecl, tree *vars,
  vec *tree_map);
+  tree carry_over_param (tree t);
   unsigned get_base_index (ipa_adjusted_param *apm);
   ipa_param_body_replacement *lookup_replacement_1 (tree base,
unsigned unit_offset);
diff --git a/gcc/testsuite/g++.dg/ipa/pr91831.C 
b/gcc/testsuite/g++.dg/ipa/pr91831.C
new file mode 100644
index 000..66e4b693151
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr91831.C
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 --param uninlined-thunk-insns=1000"  } */
+
+struct A {
+  virtual void m_fn1();
+};
+struct B {
+  virtual void *m_fn2(int, int) = 0;
+};
+struct C : A, B {
+  void *m_fn2(int, int) { return this; }
+};
+void *fn1(B &p1) { return p1.m_fn2(0, 0); }
+
+int main() {
+  C c;
+  fn1(c);
+  return 0;
+}
-- 
2.23.0



[PATCH][arm] Add missing Makefile dependency on arm_acle_builtins.def

2019-09-23 Thread Kyrill Tkachov

Hi all,

arm-builtins.o is missing a Makefile dependency on arm_acle_builtins.def 
which can cause inconsistent rebuilds

when adding builtins in there.

This patch adds the right Makefile-foo to fix that.

Tested on arm-none-eabi.

Committing to trunk.

Thanks,
Kyrill

2019-09-23  Kyrylo Tkachov  

    * config/arm/t-arm (arm-builtins.o): Add dependency on
    arm_acle_builtins.def.

diff --git a/gcc/config/arm/t-arm b/gcc/config/arm/t-arm
index f49ee728dad552d393117472dafc274b9f03d1cd..af60c8fc285bb536afeb9ec5c21771a4379755fc 100644
--- a/gcc/config/arm/t-arm
+++ b/gcc/config/arm/t-arm
@@ -141,6 +141,7 @@ arm-builtins.o: $(srcdir)/config/arm/arm-builtins.c $(CONFIG_H) \
   $(RTL_H) $(TREE_H) expr.h $(TM_P_H) $(RECOG_H) langhooks.h \
   $(DIAGNOSTIC_CORE_H) $(OPTABS_H) \
   $(srcdir)/config/arm/arm-protos.h \
+  $(srcdir)/config/arm/arm_acle_builtins.def \
   $(srcdir)/config/arm/arm_neon_builtins.def \
   $(srcdir)/config/arm/arm_vfp_builtins.def \
   $(srcdir)/config/arm/arm-simd-builtin-types.def


Re: C++ PATCH for c++/91844 - Implement CWG 2352, Similar types and reference binding.

2019-09-23 Thread Marek Polacek
On Mon, Sep 23, 2019 at 10:17:00AM -0400, Jason Merrill wrote:
> On 9/22/19 3:23 PM, Marek Polacek wrote:
> > +  /* Informally, two types are similar if, ignoring top-level 
> > cv-qualification:
> > + * they are the same type; or
> > + * they are both pointers, and the pointed-to types are similar; or
> > + * they are both pointers to member of the same class, and the types of
> > +   the pointed-to members are similar; or
> > + * they are both arrays of the same size or both arrays of unknown 
> > bound,
> > +   and the array element types are similar.  */
> 
> Yes.
> 
> > +  if ((TREE_CODE (type1) == POINTER_TYPE && TREE_CODE (type2) == 
> > POINTER_TYPE)
> > +  || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
> > +  || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == 
> > ARRAY_TYPE))
> > +{
> > +  int result = comp_cv_qual_signature (TREE_TYPE (type1),
> > +  TREE_TYPE (type2));
> 
> Using comp_cv_qual_signature means that we only return true if one
> cv-qualification signature is a subset of the other, but the definition of
> 'similar' is such that we should completely ignore cv-quals.  int const **
> and int *const* are similar even though neither can convert to the other.

Ah, true, what I actually want is comp_ptr_ttypes_const.  I didn't notice
because as you say, the conversion would fail with "discarding qualifiers".
But similar_type_p shouldn't give the wrong answer.

The handling of arrays will come in P0388R4.

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

2019-09-23  Marek Polacek  

PR c++/91844 - Implement CWG 2352, Similar types and reference binding.
* call.c (reference_related_p): Use similar_type_p instead of
same_type_p.
(reference_compatible_p): Update implementation to match CWG 2352.
* cp-tree.h (similar_type_p): Declare.
* typeck.c (similar_type_p): New.

* g++.dg/cpp0x/pr33930.C: Add dg-error.
* g++.dg/cpp0x/ref-bind1.C: New test.
* g++.dg/cpp0x/ref-bind2.C: New test.
* g++.dg/cpp0x/ref-bind3.C: New test.
* g++.old-deja/g++.pt/spec35.C: Remove dg-error.

diff --git gcc/cp/call.c gcc/cp/call.c
index 2dad699622e..28b3f332b5d 100644
--- gcc/cp/call.c
+++ gcc/cp/call.c
@@ -1530,9 +1530,8 @@ reference_related_p (tree t1, tree t2)
   /* [dcl.init.ref]
 
  Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related
- to "cv2 T2" if T1 is the same type as T2, or T1 is a base class
- of T2.  */
-  return (same_type_p (t1, t2)
+ to "cv2 T2" if T1 is similar to T2, or T1 is a base class of T2.  */
+  return (similar_type_p (t1, t2)
  || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
  && DERIVED_FROM_P (t1, t2)));
 }
@@ -1545,14 +1544,15 @@ reference_compatible_p (tree t1, tree t2)
   /* [dcl.init.ref]
 
  "cv1 T1" is reference compatible with "cv2 T2" if
-   * T1 is reference-related to T2 or
-   * T2 is "noexcept function" and T1 is "function", where the
- function types are otherwise the same,
- and cv1 is the same cv-qualification as, or greater cv-qualification
- than, cv2.  */
-  return ((reference_related_p (t1, t2)
-  || fnptr_conv_p (t1, t2))
- && at_least_as_qualified_p (t1, t2));
+ a prvalue of type "pointer to cv2 T2" can be converted to the type
+ "pointer to cv1 T1" via a standard conversion sequence.  */
+  tree ptype1 = build_pointer_type (t1);
+  tree ptype2 = build_pointer_type (t2);
+  conversion *conv = standard_conversion (ptype1, ptype2, NULL_TREE,
+ /*c_cast_p=*/false, 0, tf_none);
+  if (!conv || conv->bad_p)
+return false;
+  return true;
 }
 
 /* A reference of the indicated TYPE is being bound directly to the
diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h
index 6d217fc27a2..9c0f3949c68 100644
--- gcc/cp/cp-tree.h
+++ gcc/cp/cp-tree.h
@@ -7361,6 +7361,7 @@ enum { ce_derived, ce_type, ce_normal, ce_exact };
 extern bool comp_except_specs  (const_tree, const_tree, int);
 extern bool comptypes  (tree, tree, int);
 extern bool same_type_ignoring_top_level_qualifiers_p (tree, tree);
+extern bool similar_type_p (tree, tree);
 extern bool compparms  (const_tree, const_tree);
 extern int comp_cv_qualification   (const_tree, const_tree);
 extern int comp_cv_qualification   (int, int);
diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index d85e5474df2..f427c4f4d3e 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -1530,6 +1530,33 @@ same_type_ignoring_top_level_qualifiers_p (tree type1, 
tree type2)
   return same_type_p (type1, type2);
 }
 
+/* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual].  */
+
+bool
+similar_type_p (tree type1, tree type2)
+{
+  if (type1 == error_mark_node || type2 == error_mark_node)
+return false;
+
+  /* Inform

[PATCH] PR libstdc++/91788 improve codegen for std::variant::index()

2019-09-23 Thread Jonathan Wakely

If __index_type is a smaller type than size_t, then the result of
size_t(__index_type(-1)) is not equal to size_t(-1), but to an incorrect
value such as size_t(255) or size_t(65535). The old implementation of
variant::index() uses (size_t(__index_type(_M_index + 1)) - 1)
which is always correct, but generates suboptimal code for many common
cases.

When the __index_type is size_t or valueless variants are not possible
we can just return the value directly.

When the number of alternatives is sufficiently small the result of
converting the _M_index value to the corresponding signed type will be
either non-negative or -1. In those cases converting to the signed type
and then to size_t will either produce the correct positive value or
will sign extend -1 to (size_t)-1 as desired.

For the remaining case we keep the existing arithmetic operations to
ensure the correct result.

PR libstdc++/91788 (partial)
* include/std/variant (variant::index()): Improve codegen for cases
where conversion to size_t already works correctly.

Tested x86_64-linux, committed to trunk.


commit 6ef8d9750c46e3d781c4d8cf169f66a13e0d0827
Author: Jonathan Wakely 
Date:   Mon Sep 23 16:07:54 2019 +0100

PR libstdc++/91788 improve codegen for std::variant::index()

If __index_type is a smaller type than size_t, then the result of
size_t(__index_type(-1)) is not equal to size_t(-1), but to an incorrect
value such as size_t(255) or size_t(65535). The old implementation of
variant::index() uses (size_t(__index_type(_M_index + 1)) - 1)
which is always correct, but generates suboptimal code for many common
cases.

When the __index_type is size_t or valueless variants are not possible
we can just return the value directly.

When the number of alternatives is sufficiently small the result of
converting the _M_index value to the corresponding signed type will be
either non-negative or -1. In those cases converting to the signed type
and then to size_t will either produce the correct positive value or
will sign extend -1 to (size_t)-1 as desired.

For the remaining case we keep the existing arithmetic operations to
ensure the correct result.

PR libstdc++/91788 (partial)
* include/std/variant (variant::index()): Improve codegen for cases
where conversion to size_t already works correctly.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index d93ea86ea29..c0043243ec2 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1518,7 +1518,17 @@ namespace __variant
   { return !this->_M_valid(); }
 
   constexpr size_t index() const noexcept
-  { return size_t(typename _Base::__index_type(this->_M_index + 1)) - 1; }
+  {
+   using __index_type = typename _Base::__index_type;
+   if constexpr (is_same_v<__index_type, size_t>)
+ return this->_M_index;
+   else if constexpr (__detail::__variant::__never_valueless<_Types...>())
+ return this->_M_index;
+   else if constexpr (sizeof...(_Types) <= __index_type(-1) / 2)
+ return make_signed_t<__index_type>(this->_M_index);
+   else
+ return size_t(__index_type(this->_M_index + 1)) - 1;
+  }
 
   void
   swap(variant& __rhs)


Re: [patch, libgfortran] Bug 91593 - Implicit enum conversions in libgfortran/io/transfer.c

2019-09-23 Thread Bernhard Reutner-Fischer
On 22 September 2019 22:51:46 CEST, Jerry DeLisle  wrote:
>Hi all,
>
>The attached patch eliminates several warnings by adjusting which
>enumerator is 
>used in the subject offending code. I fixed this by adding an
>enumerator at the 
>end of the file_mode definition.  This then triggered a warning in
>several other 
>places for an unhandled case in the switch statements. I cleared those
>by 
>throwing in an assert (false) since it cant happen unless something
>really goes 
>wrong somehow.
>
I'm curious why you assert (false) instead of the usual gcc_unreachable ()?

Thanks,


[PATCH RS6000], add xxswapd support

2019-09-23 Thread Carl Love
GCC maintainers:

The following patch adds define_insn support for xxswapd mnemonic.  The
xxswapd mnemonic is the more prefered name for the xxpermdi mnemonic. 
The following patch replaces the define_insn xxpermdi with define_insn
xxswapd.

The patch has been tested on:

  powerpc64le-unknown-linux-gnu (Power 8 LE)
  powerpc64le-unknown-linux-gnu (Power 9 LE)

with no regressions.

Please let me know if the patch is acceptable for trunk.

Carl Love

P.S.  Note this is a repost as I missed copying  segher and dje on the
original messag.

--

gcc/ChangeLog:

2019-09-10  Carl Love  

* config/rs6000/vsx.md (xxswapd_v4si, xxswapd_v8hi, xxswapd_v16qi):
New define_insn.
(vsx_xxpermdi4_le_, vsx_xxpermdi8_le_V8HI,
vsx_xxpermdi16_le_V16QI): Removed define_insn.
---
 gcc/config/rs6000/vsx.md | 74 ++--
 1 file changed, 40 insertions(+), 34 deletions(-)

diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md
index 7633171df..cd67131eb 100644
--- a/gcc/config/rs6000/vsx.md
+++ b/gcc/config/rs6000/vsx.md
@@ -2941,43 +2941,49 @@
   "xxpermdi %x0,%x1,%x1,2"
   [(set_attr "type" "vecperm")])
 
-(define_insn "*vsx_xxpermdi4_le_"
-  [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
-(vec_select:VSX_W
-  (match_operand:VSX_W 1 "vsx_register_operand" "wa")
-  (parallel [(const_int 2) (const_int 3)
- (const_int 0) (const_int 1)])))]
-  "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (mode)"
-  "xxpermdi %x0,%x1,%x1,2"
+(define_insn "xxswapd_v16qi"
+  [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
+   (vec_select:V16QI
+     (match_operand:V16QI 1 "vsx_register_operand" "wa")
+     (parallel [(const_int 8) (const_int 9)
+    (const_int 10) (const_int 11)
+    (const_int 12) (const_int 13)
+    (const_int 14) (const_int 15)
+    (const_int 0) (const_int 1)
+    (const_int 2) (const_int 3)
+    (const_int 4) (const_int 5)
+    (const_int 6) (const_int 7)])))]
+   "TARGET_VSX"
+;; AIX does not support the extended mnemonic xxswapd.  Use the basic
+;; mnemonic xxpermdi instead.
+   "xxpermdi %x0,%x1,%x1,2"
   [(set_attr "type" "vecperm")])
 
-(define_insn "*vsx_xxpermdi8_le_V8HI"
+(define_insn "xxswapd_v8hi"
   [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
-(vec_select:V8HI
-  (match_operand:V8HI 1 "vsx_register_operand" "wa")
-  (parallel [(const_int 4) (const_int 5)
- (const_int 6) (const_int 7)
- (const_int 0) (const_int 1)
- (const_int 2) (const_int 3)])))]
-  "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (V8HImode)"
-  "xxpermdi %x0,%x1,%x1,2"
-  [(set_attr "type" "vecperm")])
-
-(define_insn "*vsx_xxpermdi16_le_V16QI"
-  [(set (match_operand:V16QI 0 "vsx_register_operand" "=wa")
-(vec_select:V16QI
-  (match_operand:V16QI 1 "vsx_register_operand" "wa")
-  (parallel [(const_int 8) (const_int 9)
- (const_int 10) (const_int 11)
- (const_int 12) (const_int 13)
- (const_int 14) (const_int 15)
- (const_int 0) (const_int 1)
- (const_int 2) (const_int 3)
- (const_int 4) (const_int 5)
- (const_int 6) (const_int 7)])))]
-  "!BYTES_BIG_ENDIAN && VECTOR_MEM_VSX_P (V16QImode)"
-  "xxpermdi %x0,%x1,%x1,2"
-  [(set_attr "type" "vecperm")])
+   (vec_select:V8HI
+     (match_operand:V8HI 1 "vsx_register_operand" "wa")
+     (parallel [(const_int 4) (const_int 5)
+    (const_int 6) (const_int 7)
+    (const_int 0) (const_int 1)
+    (const_int 2) (const_int 3)])))]
+   "TARGET_VSX"
+;; AIX does not support the extended mnemonic xxswapd.  Use the basic
+;; mnemonic xxpermdi instead.
+   "xxpermdi %x0,%x1,%x1,2"
+   [(set_attr "type" "vecperm")])
+
+(define_insn "xxswapd_"
+  [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
+   (vec_select:VSX_W
+     (match_operand:VSX_W 1 "vsx_register_operand" "wa")
+     (parallel [(const_int 2) (const_int 3)
+    (const_int 0) (const_int 1)])))]
+   "TARGET_VSX"
+;; AIX does not support extended mnemonic xxswapd.  Use the basic
+;; mnemonic xxpermdi instead.
+   "xxpermdi %x0,%x1,%x1,2"
+   [(set_attr "type" "vecperm")])
 
 ;; lxvd2x for little endian loads.  We need several of
 ;; these since the form of the PARALLEL differs by mode.
-- 
2.17.1



Re: [C++ Patch] Use cp_expr_loc_or_input_loc in a few places in pt.c

2019-09-23 Thread Jason Merrill

On 9/23/19 7:08 AM, Paolo Carlini wrote:

Hi,

simply a few new uses, in the places where we are dealing with 
expressions: we are able to do the right thing in a pretty large number 
of additional cases - the below could even include more testcases, most 
however are rather tangled (eg, we finally get the locations completely 
right only for the c++17 errors, there are additional errors on the same 
line, a few redundant ones, etc).


OK.

Jason



[PR 91832] Do not ICE on negative offsets in ipa-sra

2019-09-23 Thread Martin Jambor
Hi,

IPA-SRA asserts that an offset obtained from get_ref_base_and_extent
is non-negative (after it verifies it is based on a parameter).  That
assumption is invalid as the testcase shows.  One could probably also write a
testcase with defined behavior, but unless I see a reasonable one
where the transformation is really desirable, I'd like to just punt on
those cases.

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin

2019-09-23  Martin Jambor  

PR ipa/91832
* ipa-sra.c (scan_expr_access): Check that offset is non-negative.

testsuite/
* gcc.dg/ipa/pr91832.c: New test.
---
 gcc/ipa-sra.c  |  7 ++-
 gcc/testsuite/gcc.dg/ipa/pr91832.c | 12 
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr91832.c

diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c
index a32defb59bd..0ccebbd4607 100644
--- a/gcc/ipa-sra.c
+++ b/gcc/ipa-sra.c
@@ -1692,7 +1692,12 @@ scan_expr_access (tree expr, gimple *stmt, 
isra_scan_context ctx,
   disqualify_split_candidate (desc, "Encountered a bit-field access.");
   return;
 }
-  gcc_assert (offset >= 0);
+  if (offset < 0)
+{
+  disqualify_split_candidate (desc, "Encountered an access at a "
+ "negative offset.");
+  return;
+}
   gcc_assert ((offset % BITS_PER_UNIT) == 0);
   gcc_assert ((size % BITS_PER_UNIT) == 0);
   if ((offset / BITS_PER_UNIT) >= (UINT_MAX - ISRA_ARG_SIZE_LIMIT)
diff --git a/gcc/testsuite/gcc.dg/ipa/pr91832.c 
b/gcc/testsuite/gcc.dg/ipa/pr91832.c
new file mode 100644
index 000..4a0d62ec1d9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr91832.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2"  } */
+
+struct A1 {
+  char a1[1];
+};
+
+void fn2(char a);
+
+void fn1(struct A1 *p1) {
+  fn2(p1->a1[-1]);
+}
-- 
2.23.0



Re: C++ PATCH for c++/91844 - Implement CWG 2352, Similar types and reference binding.

2019-09-23 Thread Jason Merrill

On 9/22/19 3:23 PM, Marek Polacek wrote:

+  /* Informally, two types are similar if, ignoring top-level cv-qualification:
+ * they are the same type; or
+ * they are both pointers, and the pointed-to types are similar; or
+ * they are both pointers to member of the same class, and the types of
+   the pointed-to members are similar; or
+ * they are both arrays of the same size or both arrays of unknown bound,
+   and the array element types are similar.  */


Yes.


+  if ((TREE_CODE (type1) == POINTER_TYPE && TREE_CODE (type2) == POINTER_TYPE)
+  || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
+  || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
+{
+  int result = comp_cv_qual_signature (TREE_TYPE (type1),
+  TREE_TYPE (type2));


Using comp_cv_qual_signature means that we only return true if one 
cv-qualification signature is a subset of the other, but the definition 
of 'similar' is such that we should completely ignore cv-quals.  int 
const ** and int *const* are similar even though neither can convert to 
the other.


Jason


Re: [PATCH] Reduction of conditional operations for vectorization

2019-09-23 Thread Richard Biener
On Fri, Sep 20, 2019 at 3:53 PM Yuliang Wang  wrote:
>
> Hi Richard,
>
> Thanks for your comments and tips. fold_binary_op_with_conditional_arg 
> performs the reverse transformation to this patch in certain situations:
>
> /* Transform `a + (b ? x : y)' into `b ? (a + x) : (a + y)'.

Yes, this is essentially the reverse transform.  It's bad to have
both, we should
decide on one here.  That means we have to align conditions appropriately,
for example by splitting out a predicate which we can test (negated) in both
places.

I agree with Marc that the condition in fold_binary_op_with_conditional_arg
is sub-optimal.

Richard.

>... */
>
> static tree
> fold_binary_op_with_conditional_arg (location_t loc,
> ...
>
> /* This transformation is only worthwhile if we don't have to wrap ARG
>in a SAVE_EXPR and the operation can be simplified without recursing
>on at least one of the branches once its pushed inside the COND_EXPR.  */
> if (!TREE_CONSTANT (arg)
> && (TREE_SIDE_EFFECTS (arg) ...)
>   return NULL_TREE;
> ...
>
> For instance, this causes infinite recursion in 
> gcc.dg/vect/fast-math-vect-call-2 because ARG is a float literal.
> Regards,
> Yuliang
>
> -Original Message-
> From: Richard Biener 
> Sent: 20 September 2019 13:02
> To: Yuliang Wang 
> Cc: gcc-patches@gcc.gnu.org; nd ; Richard Sandiford 
> 
> Subject: Re: [PATCH] Reduction of conditional operations for vectorization
>
> On Fri, Sep 20, 2019 at 10:09 AM Yuliang Wang  wrote:
> >
> > Hi,
> >
> > ifcvt transforms the following conditional operation reduction pattern:
> >
> >   if ( condition )
> > a = a OP b;
> >   else
> > a = a OP c;
> >
> > Into:
> >
> >   a_1 = a OP b;
> >   a_2 = a OP c;
> >   a = condition ? a_1 : a_2;
> >
> > Where OP is one of { plus minus mult min max and ior eor }.
> >
> > This patch further optimizes the above to:
> >
> >   a_0 = condition ? b : c;
> >   a = a OP a_0;
> >
> > Which enables vectorization on AArch64.
> > Also supported are permutations of the above operand ordering subject to 
> > commutativity of OP.
> >
> > Added new tests. Built and regression tested on aarch64-none-elf and 
> > aarch64-linux-gnu.
>
> @@ -3206,7 +3206,41 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   /* !A ? B : C -> A ? C : B.  */
>   (simplify
>(cnd (logical_inverted_value truth_valued_p@0) @1 @2)
> -  (cnd @0 @2 @1)))
> +  (cnd @0 @2 @1))
> +
> + /* !A ? B : C -> A ? C : B.  */
> + (simplify
> +  (cnd (logical_inverted_value truth_valued_p@0) @1 @2)  (cnd @0 @2
> + @1))
> +
>
> looks like you duplicate the above pattern.  Should have raised a warning in 
> the genmatch run.
>
> The patch header shows you are not working against trunk?
>
> + (for op (plus minus mult
> + min max
> + bit_and bit_ior bit_xor)
> +  (simplify
> +   (cnd @0 (op @1 @2) (op @1 @3))
> +   (op @1 (cnd @0 @2 @3)))
> +  (simplify
> +   (cnd @0 (op @1 @2) (op @3 @2))
> +   (op (cnd @0 @1 @3) @2))
> +  (if (op != MINUS_EXPR)
> +   (simplify
> +(cnd @0 (op @1 @2) (op @3 @1))
> +(op @1 (cnd @0 @2 @3)))
> +   (simplify
> +(cnd @0 (op @2 @1) (op @1 @3))
> +(op @1 (cnd @0 @2 @3)
>
> if you would have dropped minus handling this simplifies to
>
> (for op (...)
>  (simpify
>   (cnd @0 (op:c @1 @2) (op:c @1 @3))
>   (op @1 (cnd @0 @2 @3)))
>
> you can then add minus special-cases if they are important
>
>  (simplify
>   (cnd @0 (minus @1 @2) (minus @1 @3))
> ...
>  (simplify
>   (cnd @0 (minus @2 @1) (minus @3 @1))
>
> I think that's clearer.
>
> + /* Hack: generic-match causes infinite recursion
> +by reverting this transformation when
> +i) -fno-trapping-math is enabled, and
> +ii) the common operand does not need to be wrapped in a SAVE_EXPR.
> + */
>
> What's the specific transform that causes this?  Yes, there are some left in 
> fold-const.c.
>
> Thanks,
> Richard.
>
> > Best Regards,
> > Yuliang Wang
> >
> >
> > gcc/ChangeLog:
> >
> > 2019-09-19  Yuliang Wang  
> >
> > * match.pd (for cnd (cond vec_cond)): New match statements for the
> > above patterns.
> > * doc/sourcebuild.texi (vect_condred_si): Document new target 
> > selector.
> >
> > gcc/testsuite/ChangeLog:
> >
> > 2019-09-19  Yuliang Wang  
> >
> > * gcc.target/aarch64/sve2/condred_1.c: New test.
> > * gcc.dg/vect/vect-condred-1.c: As above.
> > * gcc.dg/vect/vect-condred-2.c: As above.
> > * gcc.dg/vect/vect-condred-3.c: As above.
> > * gcc.dg/vect/vect-condred-4.c: As above.
> > * gcc.dg/vect/vect-condred-5.c: As above.
> > * gcc.dg/vect/vect-condred-6.c: As above.
> > * gcc.dg/vect/vect-condred-7.c: As above.
> > * gcc.dg/vect/vect-condred-8.c: As above.
> > * lib/target-supports.exp (check_effective_target_vect_condred_si):
> > Return true for AArch64 without SVE.


Re: [PATCH, Fortran] Character type names in errors and warnings - new version for review

2019-09-23 Thread Janne Blomqvist
On Thu, Sep 19, 2019 at 3:59 PM Mark Eggleston
 wrote:
>
> Original thread: https://gcc.gnu.org/ml/fortran/2019-09/msg00024.html
>
> The original patch introduced a new field in gfc_typespec called length
> to be used only for character literals. At the time I felt that this was
> a bit of kludge.  As a results of comments from Janne Blomqvist I
> investigated whether the existing mechanism for character length in
> gfc_typespec could be used for character literals. This turn out to be
> impractical.
>
> The character length for literals is already held in the gfc_expr
> structure for character constants. I've added a new version of
> gfc_typename that accepts gfc_expr * instead of gfc_typespec. Where
> character types are possible the gfc_expr * version is now used instead
> of the gfc_typespec * version.
>
> I've implemented Janne's suggestions.
>
> I think this is a better solution.
>
> Please review.
>
> Tested on x86_64 (built with bootstrap).

Thanks, this is Ok.


-- 
Janne Blomqvist


Re: [rs6000] Fix non-canonical CONST_INTs in altivec_copysign_v4sf3 (PR91823)

2019-09-23 Thread Segher Boessenkool
On Mon, Sep 23, 2019 at 10:51:30AM +0100, Richard Sandiford wrote:
> The pattern was generating zero-extended rather than sign-extended
> CONST_INTs.
> 
> Tested by Bill Seurer (thanks!).  OK to install?

Sure!  One nit:

> gcc/
>   PR target/91823
>   * config/rs6000/altivec.md (altivec_copysign_v4sf3): Generate
>   canonical CONST_INTs.  Use gen_rtvec_v.

You actually use gen_rtvec here.

Okay for trunk (and backports if you want those).  Thanks!


Segher


[C++ Patch] Use cp_expr_loc_or_input_loc in a few places in pt.c

2019-09-23 Thread Paolo Carlini

Hi,

simply a few new uses, in the places where we are dealing with 
expressions: we are able to do the right thing in a pretty large number 
of additional cases - the below could even include more testcases, most 
however are rather tangled (eg, we finally get the locations completely 
right only for the c++17 errors, there are additional errors on the same 
line, a few redundant ones, etc).


Tested x86_64-linux, as usual.

Thanks, Paolo.



/cp
2019-09-23  Paolo Carlini  

* pt.c (check_explicit_specialization): Use cp_expr_loc_or_input_loc.
(process_partial_specialization): Likewise.
(convert_nontype_argument_function): Likewise.
(invalid_tparm_referent_p): Likewise.
(convert_template_argument): Likewise.
(check_valid_ptrmem_cst_expr): Tidy.

/testsuite
2019-09-23  Paolo Carlini  

* g++.dg/cpp0x/pr68724.C: Check location(s) too.
* g++.dg/cpp0x/variadic38.C: Likewise.
* g++.dg/cpp1z/nontype2.C: Likewise.
* g++.dg/parse/explicit1.C: Likewise.
* g++.dg/template/crash11.C: Likewise.
* g++.dg/template/non-dependent8.C: Likewise.
* g++.dg/template/nontype-array1.C: Likewise.
* g++.dg/template/nontype3.C: Likewise.
* g++.dg/template/nontype8.C: Likewise.
* g++.dg/template/partial5.C: Likewise.
* g++.dg/template/spec33.C: Likewise.
* g++.old-deja/g++.pt/memtemp64.C: Likewise.
* g++.old-deja/g++.pt/spec20.C: Likewise.
* g++.old-deja/g++.pt/spec21.C: Likewise.
* g++.old-deja/g++.robertl/eb103.C: Likewise.
Index: cp/pt.c
===
--- cp/pt.c (revision 276015)
+++ cp/pt.c (working copy)
@@ -2808,8 +2808,9 @@ check_explicit_specialization (tree declarator,
  /* This case handles bogus declarations like template <>
 template  void f(); */
 
- error ("template-id %qD in declaration of primary template",
-declarator);
+ error_at (cp_expr_loc_or_input_loc (declarator),
+   "template-id %qE in declaration of primary template",
+   declarator);
  return decl;
}
}
@@ -2867,8 +2868,9 @@ check_explicit_specialization (tree declarator,
 template  void f(); */
 
  if (!uses_template_parms (TREE_OPERAND (declarator, 1)))
-   error ("template-id %qD in declaration of primary template",
-  declarator);
+   error_at (cp_expr_loc_or_input_loc (declarator),
+ "template-id %qE in declaration of primary template",
+ declarator);
  else if (variable_template_p (TREE_OPERAND (declarator, 0)))
{
  /* Partial specialization of variable template.  */
@@ -2877,11 +2879,13 @@ check_explicit_specialization (tree declarator,
  goto ok;
}
  else if (cxx_dialect < cxx14)
-   error ("non-type partial specialization %qD "
-  "is not allowed", declarator);
+   error_at (cp_expr_loc_or_input_loc (declarator),
+ "non-type partial specialization %qE "
+ "is not allowed", declarator);
  else
-   error ("non-class, non-variable partial specialization %qD "
-  "is not allowed", declarator);
+   error_at (cp_expr_loc_or_input_loc (declarator),
+ "non-class, non-variable partial specialization %qE "
+ "is not allowed", declarator);
  return decl;
ok:;
}
@@ -4958,8 +4962,9 @@ process_partial_specialization (tree decl)
 {
   if ((!packed_args && tpd.arg_uses_template_parms[i])
   || (packed_args && uses_template_parms (arg)))
-error ("template argument %qE involves template parameter(s)",
-   arg);
+   error_at (cp_expr_loc_or_input_loc (arg),
+ "template argument %qE involves template "
+ "parameter(s)", arg);
   else 
 {
   /* Look at the corresponding template parameter,
@@ -6258,13 +6263,14 @@ convert_nontype_argument_function (tree type, tree
 {
   if (complain & tf_error)
{
- error ("%qE is not a valid template argument for type %qT",
-expr, type);
+ location_t loc = cp_expr_loc_or_input_loc (expr);
+ error_at (loc, "%qE is not a valid template argument for type %qT",
+   expr, type);
  if (TYPE_PTR_P (type))
-   inform (input_location, "it must be the address of a function "
+   inform (loc, "it must be the address of a function "
"with external linkage");
  else
-   inform (input_location, "it must be the name of a funct

[testsuite] Skip gcc.dg/ucnid-5-utf8.c unless ucn is supported

2019-09-23 Thread Rainer Orth
The new gcc.dg/ucnid-5-utf8.c test FAILs on Solaris with the native
assembler:

+FAIL: gcc.dg/ucnid-5-utf8.c (test for excess errors)
+UNRESOLVED: gcc.dg/ucnid-5-utf8.c compilation failed to produce executable

Excess errors:
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 22: error: invalid character 
(0x9f)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 22: error: invalid character 
(0x98)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 22: error: invalid character 
(0x80)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 23: error: invalid character 
(0x9f)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 23: error: invalid character 
(0x98)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 23: error: invalid character 
(0x80)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 25: error: unknown opcode "a$b"
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 25: error: invalid character 
(0x9f)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 25: error: invalid character 
(0x98)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 25: error: invalid character 
(0x80)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 25: error: statement syntax
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: error: invalid character 
(0x9f)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: error: invalid character 
(0x98)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: error: invalid character 
(0x80)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: error: invalid character 
(0x9f)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: error: invalid character 
(0x98)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: error: invalid character 
(0x80)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 60: error: invalid character 
(0x9f)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 60: error: invalid character 
(0x98)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 60: error: invalid character 
(0x80)
/usr/ccs/bin/as: "/var/tmp//cc8LEnCb.s", line 37: warning: size of "a$b" 
redefined

The test uses a UCN identifier (as can only be seen with cat -v), but
fails to declare that requirement.  Fixed as follows as has been done in
the other affected ucnid-*.c tests.  Now the test is UNSUPPORTED on
i386-pc-solaris2.11 with as and PASSes with gas.

Installed on mainline.

Rainer

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


2019-09-20  Rainer Orth  

* gcc.dg/ucnid-5-utf8.c: Skip unless ucn is supported.

# HG changeset patch
# Parent  071c1aca10b4c058ee33055f2346209812c9aa52
Skip gcc.dg/ucnid-5-utf8.c unless ucn is supported

diff --git a/gcc/testsuite/gcc.dg/ucnid-5-utf8.c b/gcc/testsuite/gcc.dg/ucnid-5-utf8.c
--- a/gcc/testsuite/gcc.dg/ucnid-5-utf8.c
+++ b/gcc/testsuite/gcc.dg/ucnid-5-utf8.c
@@ -1,5 +1,6 @@
 /* { dg-do run } */
 /* { dg-skip-if "No dollar in identfiers" { avr-*-* powerpc-ibm-aix* } } */
+/* { dg-skip-if "" { ! ucn } } */
 /* { dg-options "-std=c99 -fdollars-in-identifiers -g" } */
 void abort (void);
 


Re: [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32

2019-09-23 Thread Rainer Orth
Hi Arnaud,

>> I'd keep the target list alphabetical.  Can do so when the Solaris patch
>> goes in.
>> 
>> Here's what I've successfully tested last night on both
>> i386-pc-solaris2.11 and sparc-sun-solaris2.11, shamelessly stolen from
>> the Linux counterparts.  If it is acceptable, I'd add *-*-solaris2.* to
>> the target list when merging.
>
> The change is OK.
>
>> 2019-09-19  Rainer Orth  
>> 
>>  * libgnarl/s-osinte__solaris.ads (sysconf): Declare.
>>  (SC_NPROCESSORS_ONLN): Define.
>>  * libgnarl/s-tasinf__solaris.ads (Number_Of_Processors): Declare.
>>  * libgnarl/s-tasinf__solaris.adb (N_CPU): New variable.
>>  (Number_Of_Processors): New function.

Thanks.  Here's what I've installed.

Rainer

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


2019-09-19  Rainer Orth  

gcc/ada:
* libgnarl/s-osinte__solaris.ads (sysconf): Declare.
(SC_NPROCESSORS_ONLN): Define.
* libgnarl/s-tasinf__solaris.ads (Number_Of_Processors): Declare.
* libgnarl/s-tasinf__solaris.adb (N_CPU): New variable.
(Number_Of_Processors): New function.

gcc/testsuite:
* gnat.dg/system_info1.adb: Sort dg-do target list.
Add *-*-solaris2.*.

# HG changeset patch
# Parent  0d13bfaa0b34084a84b2b12d906b7252383366d4
Provide Task_Info.Number_Of_Processors on Solaris

diff --git a/gcc/ada/libgnarl/s-osinte__solaris.ads b/gcc/ada/libgnarl/s-osinte__solaris.ads
--- a/gcc/ada/libgnarl/s-osinte__solaris.ads
+++ b/gcc/ada/libgnarl/s-osinte__solaris.ads
@@ -259,6 +259,11 @@ package System.OS_Interface is
function To_Timespec (D : Duration) return timespec;
pragma Inline (To_Timespec);
 
+   function sysconf (name : int) return long;
+   pragma Import (C, sysconf);
+
+   SC_NPROCESSORS_ONLN : constant := 15;
+
-
-- Process --
-
diff --git a/gcc/ada/libgnarl/s-tasinf__solaris.adb b/gcc/ada/libgnarl/s-tasinf__solaris.adb
--- a/gcc/ada/libgnarl/s-tasinf__solaris.adb
+++ b/gcc/ada/libgnarl/s-tasinf__solaris.adb
@@ -84,4 +84,23 @@ package body System.Task_Info is
   return (False, False);
end Unbound_Thread_Attributes;
 
+   N_CPU : Natural := 0;
+   pragma Atomic (N_CPU);
+   --  Cache CPU number. Use pragma Atomic to avoid a race condition when
+   --  setting N_CPU in Number_Of_Processors below.
+
+   --
+   -- Number_Of_Processors --
+   --
+
+   function Number_Of_Processors return Positive is
+   begin
+  if N_CPU = 0 then
+ N_CPU := Natural
+   (OS_Interface.sysconf (OS_Interface.SC_NPROCESSORS_ONLN));
+  end if;
+
+  return N_CPU;
+   end Number_Of_Processors;
+
 end System.Task_Info;
diff --git a/gcc/ada/libgnarl/s-tasinf__solaris.ads b/gcc/ada/libgnarl/s-tasinf__solaris.ads
--- a/gcc/ada/libgnarl/s-tasinf__solaris.ads
+++ b/gcc/ada/libgnarl/s-tasinf__solaris.ads
@@ -139,4 +139,7 @@ package System.Task_Info is
 
Unspecified_Task_Info : constant Task_Info_Type := null;
 
+   function Number_Of_Processors return Positive;
+   --  Returns the number of processors on the running host
+
 end System.Task_Info;
diff --git a/gcc/testsuite/gnat.dg/system_info1.adb b/gcc/testsuite/gnat.dg/system_info1.adb
--- a/gcc/testsuite/gnat.dg/system_info1.adb
+++ b/gcc/testsuite/gnat.dg/system_info1.adb
@@ -3,7 +3,7 @@
 --  both 32bit and 64bit Windows. Additional configurations where the
 --  feature was verified to work can opt-in.
 
---  { dg-do run { target *-*-mingw* *-*-linux* } }
+--  { dg-do run { target *-*-linux* *-*-mingw* *-*-solaris2.* } }
 
 with System.Multiprocessors;
 with System.Task_Info;


Use underscore in IPA-SRA LTO section name (PR ipa/91835)

2019-09-23 Thread Rainer Orth
The recent IPA-SRA patch completely broke LTO on Solaris/x86 with the
native assembler:

FAIL: gcc.c-torture/compile/2105-1.c   -O2 -flto -flto-partition=none  
(test for excess errors)
Excess errors:
Assembler: 2105-1.c
"/var/tmp//ccaW7VHa.s", line 35 : Syntax error
Near line: ".section
.gnu.lto_.ipa-sra.e03463101918c5a8,#exclude"

This happens because tokens (including section names) can only consist
of letters, digits, '_' and '.'.

Fixed by using '_' instead of '-' as all other LTO section names do.
Tested on i386-pc-solaris2.11 and i686-pc-linux-gnu, installed on
mainline as pre-approved by Richard in the PR.

Rainer

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


2019-09-22  Rainer Orth  

PR ipa/91835
* lto-section-in.c (lto_section_name): Use "ipa_sra" instead of
"ipa-sra".

# HG changeset patch
# Parent  8c01a327e7dfcb4f3b75e96bd58996729bcfd5c8
Use underscore in IPA-SRA LTO section name (PR ipa/91835)

diff --git a/gcc/lto-section-in.c b/gcc/lto-section-in.c
--- a/gcc/lto-section-in.c
+++ b/gcc/lto-section-in.c
@@ -54,7 +54,7 @@ const char *lto_section_name[LTO_N_SECTI
   "mode_table",
   "hsa",
   "lto",
-  "ipa-sra"
+  "ipa_sra"
 };
 
 /* Hooks so that the ipa passes can call into the lto front end to get


[rs6000] Fix non-canonical CONST_INTs in altivec_copysign_v4sf3 (PR91823)

2019-09-23 Thread Richard Sandiford
The pattern was generating zero-extended rather than sign-extended
CONST_INTs.

Tested by Bill Seurer (thanks!).  OK to install?

Richard


2019-09-23  Richard Sandiford  

gcc/
PR target/91823
* config/rs6000/altivec.md (altivec_copysign_v4sf3): Generate
canonical CONST_INTs.  Use gen_rtvec_v.

Index: gcc/config/rs6000/altivec.md
===
--- gcc/config/rs6000/altivec.md2019-08-25 19:10:35.582156848 +0100
+++ gcc/config/rs6000/altivec.md2019-09-23 10:48:21.998225836 +0100
@@ -2198,13 +2198,8 @@ (define_expand "altivec_copysign_v4sf3"
   "VECTOR_UNIT_ALTIVEC_P (V4SFmode)"
 {
   rtx mask = gen_reg_rtx (V4SImode);
-  rtvec v = rtvec_alloc (4);
-  unsigned HOST_WIDE_INT mask_val = ((unsigned HOST_WIDE_INT)1) << 31;
-
-  RTVEC_ELT (v, 0) = GEN_INT (mask_val);
-  RTVEC_ELT (v, 1) = GEN_INT (mask_val);
-  RTVEC_ELT (v, 2) = GEN_INT (mask_val);
-  RTVEC_ELT (v, 3) = GEN_INT (mask_val);
+  rtx mask_val = gen_int_mode (HOST_WIDE_INT_1U << 31, SImode);
+  rtvec v = gen_rtvec (4, mask_val, mask_val, mask_val, mask_val);
 
   emit_insn (gen_vec_initv4sisi (mask, gen_rtx_PARALLEL (V4SImode, v)));
   emit_insn (gen_vector_select_v4sf (operands[0], operands[1], operands[2],


[AArch64] Fix cost of (plus ... (const_int -C))

2019-09-23 Thread Richard Sandiford
The PLUS handling in aarch64_rtx_costs only checked for nonnegative
constants, meaning that simple immediate subtractions like:

  (set (reg R1) (plus (reg R2) (const_int -8)))

had a cost of two instructions.

Tested on aarch64-linux-gnu (with and without SVE).  OK to install?

Richard


2019-09-23  Richard Sandiford  

gcc/
* config/aarch64/aarch64.c (aarch64_rtx_costs): Use
aarch64_plus_immediate rather than aarch64_uimm12_shift
to test for valid PLUS immediates.

Index: gcc/config/aarch64/aarch64.c
===
--- gcc/config/aarch64/aarch64.c2019-09-23 10:22:47.0 +0100
+++ gcc/config/aarch64/aarch64.c2019-09-23 10:43:41.652295538 +0100
@@ -10753,7 +10753,7 @@ aarch64_rtx_costs (rtx x, machine_mode m
  }
 
if (GET_MODE_CLASS (mode) == MODE_INT
-   && ((CONST_INT_P (op1) && aarch64_uimm12_shift (INTVAL (op1)))
+   && (aarch64_plus_immediate (op1, mode)
|| aarch64_sve_addvl_addpl_immediate (op1, mode)))
  {
*cost += rtx_cost (op0, mode, PLUS, 0, speed);


[committed][AArch64] Fix memmodel index in aarch64_store_exclusive_pair

2019-09-23 Thread Richard Sandiford
Found via an rtl checking failure.  Tested on aarch64-linux-gnu
and applied as obvious (r276052).

Richard


2019-09-23  Richard Sandiford  

gcc/
* config/aarch64/atomics.md (aarch64_store_exclusive_pair): Fix
memmodel index.

Index: gcc/config/aarch64/atomics.md
===
--- gcc/config/aarch64/atomics.md   2019-09-21 13:56:09.071933423 +0100
+++ gcc/config/aarch64/atomics.md   2019-09-23 10:22:47.361697048 +0100
@@ -752,7 +752,7 @@ (define_insn "aarch64_store_exclusive_pa
  UNSPECV_SX))]
   ""
   {
-enum memmodel model = memmodel_from_int (INTVAL (operands[3]));
+enum memmodel model = memmodel_from_int (INTVAL (operands[4]));
 if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_acquire 
(model))
   return "stxp\t%w0, %x2, %x3, %1";
 else


Re: [patch, libgfortran] Bug 91593 - Implicit enum conversions in libgfortran/io/transfer.c

2019-09-23 Thread Tobias Burnus

Hi Jerry,

On 9/22/19 10:51 PM, Jerry DeLisle wrote:
The attached patch eliminates several warnings by adjusting which 
enumerator is used in the subject offending code. I fixed this by 
adding an enumerator at the end of the file_mode definition.  This 
then triggered a warning in several other places for an unhandled case 
in the switch statements. I cleared those by throwing in an assert 
(false) since it cant happen unless something really goes wrong somehow.


Regardless, regression tested on x86_64-pc-linux-gnu.
OK for trunk? No applicable test case.


LGTM – thanks for eliminating warnings.



PS

While I was at it, I 'touched' all files in libgfortran/io to see what 
other warnings are left,  There is another odd warning I have not 
sorted out yet.

[…]
In function ‘btoa_big’,
    inlined from ‘write_b’ at 
../../../trunk/libgfortran/io/write.c:1212:11:
../../../trunk/libgfortran/io/write.c:1051:6: warning: writing 1 byte 
into a region of size 0 [-Wstringop-overflow=]

 1051 |   *q = '\0';
  |   ~~~^~

The first of these two I understand. The second one about region of 
size 0 puzzles me.



btoa_big (const char *s, char *buffer, int len, GFC_UINTEGER_LARGEST *n)

…
  q = buffer;
…
  for (i = 0; i < len; i++)
  for (j = 0; j < 8; j++)
    {
  *q++ = (c & 128) ? '1' : '0';
…
  *q = '\0';

I think the compiler assumes that if you call "q++" (alias buffer) 
"8*len" times, that the

   *q = '\0';
will write at buffer[len] – which could be one byte beyond the buffer 
size. I don't quickly see whether that's the case or not, but I think 
you should check whether this can happen – and if not, you may need to 
add a comment, e.g. stating that the buffer is 8*len+1 bytes long or 
something along that line. And if it can happen, you need to ensure that 
in the future it cannot :-)


Now looking at the code,
  char itoa_buf[GFC_BTOA_BUF_SIZE];
with
   #define GFC_BTOA_BUF_SIZE (GFC_LARGEST_BUF * 8 + 1)
and GFC_LARGEST_BUF  is sizeof(real-16 real or integer-16) if available 
or sizeof(real-10) or is not sizeof(largest integer).


"len" comes in as parameter to write_b/write_o/write_z and looks like 
being the byte size or kind. Hence, it seems to be fine. Maybe adding a 
comment plus an assert(len < GFC_BTOA_BUF_SIZE) would make sense? With 
the assert, the warning would return with "NDEBUG" set (cf. assert man 
page) but otherwise, it should be fine.


Down side is that w/o NDEBUG, one adds one additional condition ("if" 
branch) to the code - even if it is regarded as unlikely (assert code 
moved to the end of the function) - and adds some strings + printf call 
as well (via the assert). But at the end, one probably doesn't need to 
worry about this too much.


Cheers,

Tobias



Re: [PATCH, AArch64] Fix PR target/91834

2019-09-23 Thread Kyrill Tkachov



On 9/21/19 7:11 AM, Richard Henderson wrote:

As diagnosed in the PR.

    * config/aarch64/lse.S (LDNM): Ensure STXR output does not
    overlap the inputs.



Looks good to me. Perhaps even obvious.

Thanks,

Kyrill



---
 libgcc/config/aarch64/lse.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libgcc/config/aarch64/lse.S b/libgcc/config/aarch64/lse.S
index a5f6673596c..c7979382ad7 100644
--- a/libgcc/config/aarch64/lse.S
+++ b/libgcc/config/aarch64/lse.S
@@ -227,8 +227,8 @@ STARTFN NAME(LDNM)
 8:  mov s(tmp0), s(0)
 0:  LDXR    s(0), [x1]
 OP  s(tmp1), s(0), s(tmp0)
-   STXR    w(tmp1), s(tmp1), [x1]
-   cbnz    w(tmp1), 0b
+   STXR    w(tmp2), s(tmp1), [x1]
+   cbnz    w(tmp2), 0b
 ret

 ENDFN   NAME(LDNM)
--
2.17.1



Re: [PATCH, AArch64] PR target/91833

2019-09-23 Thread Kyrill Tkachov



On 9/21/19 7:11 AM, Richard Henderson wrote:

Tested on aarch64-linux (glibc) and aarch64-elf (installed newlib).

The existing configure claims to be generated by 2.69, but there
are changes wrt the autoconf distributed with Ubuntu 18. Nothing
that seems untoward though.



The aarch64 parts LGTM FWIW.

Don't know what's the process for the configure parts though.

Are we strict about which version they're generated with?

Kyrill




r~


    * config/aarch64/lse-init.c: Include auto-target.h. Disable
    initialization if !HAVE_SYS_AUXV_H.
    * configure.ac (AC_CHECK_HEADERS): Add sys/auxv.h.
    * config.in, configure: Rebuild.
---
 libgcc/config/aarch64/lse-init.c |  4 +++-
 libgcc/config.in |  8 
 libgcc/configure | 26 +++---
 libgcc/configure.ac  |  2 +-
 4 files changed, 31 insertions(+), 9 deletions(-)
 mode change 100644 => 100755 libgcc/configure

diff --git a/libgcc/config/aarch64/lse-init.c 
b/libgcc/config/aarch64/lse-init.c

index 33d29147479..1a8f4c55213 100644
--- a/libgcc/config/aarch64/lse-init.c
+++ b/libgcc/config/aarch64/lse-init.c
@@ -23,12 +23,14 @@ a copy of the GCC Runtime Library Exception along 
with this program;

 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
 . */

+#include "auto-target.h"
+
 /* Define the symbol gating the LSE implementations.  */
 _Bool __aarch64_have_lse_atomics
   __attribute__((visibility("hidden"), nocommon));

 /* Disable initialization of __aarch64_have_lse_atomics during 
bootstrap.  */

-#ifndef inhibit_libc
+#if !defined(inhibit_libc) && defined(HAVE_SYS_AUXV_H)
 # include 

 /* Disable initialization if the system headers are too old.  */
diff --git a/libgcc/config.in b/libgcc/config.in
index d634af9d949..59a3d8daf52 100644
--- a/libgcc/config.in
+++ b/libgcc/config.in
@@ -43,6 +43,9 @@
 /* Define to 1 if you have the  header file. */
 #undef HAVE_STRING_H

+/* Define to 1 if you have the  header file. */
+#undef HAVE_SYS_AUXV_H
+
 /* Define to 1 if you have the  header file. */
 #undef HAVE_SYS_STAT_H

@@ -82,6 +85,11 @@
 /* Define to 1 if the target use emutls for thread-local storage. */
 #undef USE_EMUTLS

+/* Enable large inode numbers on Mac OS X 10.5.  */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS

diff --git a/libgcc/configure b/libgcc/configure
old mode 100644
new mode 100755
index 29f647319b4..28c7394b3f9
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -675,6 +675,7 @@ infodir
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -765,6 +766,7 @@ datadir='${datarootdir}'
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1017,6 +1019,15 @@ do
   | -silent | --silent | --silen | --sile | --sil)
 silent=yes ;;

+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
 ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1154,7 +1165,7 @@ fi
 for ac_var in   exec_prefix prefix bindir sbindir libexecdir 
datarootdir \
 datadir sysconfdir sharedstatedir localstatedir 
includedir \
 oldincludedir docdir infodir htmldir dvidir pdfdir 
psdir \

-   libdir localedir mandir
+   libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1307,6 +1318,7 @@ Fine tuning of the installation directories:
   --sysconfdir=DIR    read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data 
[PREFIX/com]

   --localstatedir=DIR modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR   modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR    object code libraries [EPREFIX/lib]
   --includedir=DIR    C header files [PREFIX/include]
   --oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -4173,7 +4185,7 @@ else
 We can't simply define LARGE_OFF_T to be 9223372036854775807,
 since some C++ compilers masquerading as C compilers
 incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 
31) << 31))


Update riscv64 baseline symbols

2019-09-23 Thread Andreas Schwab
Tested on riscv64-suse-linux and installed as obvious.

* config/abi/post/riscv64-linux-gnu/baseline_symbols.txt: Update.

diff --git 
a/libstdc++-v3/config/abi/post/riscv64-linux-gnu/baseline_symbols.txt 
b/libstdc++-v3/config/abi/post/riscv64-linux-gnu/baseline_symbols.txt
index 042fb3ce458..4ef2758e7df 100644
--- a/libstdc++-v3/config/abi/post/riscv64-linux-gnu/baseline_symbols.txt
+++ b/libstdc++-v3/config/abi/post/riscv64-linux-gnu/baseline_symbols.txt
@@ -1829,6 +1829,7 @@ 
FUNC:_ZNSt10filesystem28recursive_directory_iteratorC2ERKNS_4pathENS_17directory
 FUNC:_ZNSt10filesystem28recursive_directory_iteratorD1Ev@@GLIBCXX_3.4.26
 FUNC:_ZNSt10filesystem28recursive_directory_iteratorD2Ev@@GLIBCXX_3.4.26
 FUNC:_ZNSt10filesystem28recursive_directory_iteratoraSEOS0_@@GLIBCXX_3.4.26
+FUNC:_ZNSt10filesystem28recursive_directory_iteratoraSERKS0_@@GLIBCXX_3.4.27
 FUNC:_ZNSt10filesystem28recursive_directory_iteratorppEv@@GLIBCXX_3.4.26
 FUNC:_ZNSt10filesystem4copyERKNS_4pathES2_NS_12copy_optionsE@@GLIBCXX_3.4.26
 
FUNC:_ZNSt10filesystem4copyERKNS_4pathES2_NS_12copy_optionsERSt10error_code@@GLIBCXX_3.4.26
@@ -1885,6 +1886,7 @@ 
FUNC:_ZNSt10filesystem7__cxx1128recursive_directory_iteratorC2ERKNS0_4pathENS_17
 
FUNC:_ZNSt10filesystem7__cxx1128recursive_directory_iteratorD1Ev@@GLIBCXX_3.4.26
 
FUNC:_ZNSt10filesystem7__cxx1128recursive_directory_iteratorD2Ev@@GLIBCXX_3.4.26
 
FUNC:_ZNSt10filesystem7__cxx1128recursive_directory_iteratoraSEOS1_@@GLIBCXX_3.4.26
+FUNC:_ZNSt10filesystem7__cxx1128recursive_directory_iteratoraSERKS1_@@GLIBCXX_3.4.27
 
FUNC:_ZNSt10filesystem7__cxx1128recursive_directory_iteratorppEv@@GLIBCXX_3.4.26
 FUNC:_ZNSt10filesystem7__cxx114path14_M_split_cmptsEv@@GLIBCXX_3.4.26
 
FUNC:_ZNSt10filesystem7__cxx114path14_S_convert_locEPKcS3_RKSt6locale@@GLIBCXX_3.4.26
@@ -2060,13 +2062,21 @@ FUNC:_ZNSt12__basic_fileIcED1Ev@@GLIBCXX_3.4
 FUNC:_ZNSt12__basic_fileIcED2Ev@@GLIBCXX_3.4
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem28recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC1EOS5_@@GLIBCXX_3.4.26
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem28recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC1Ev@@GLIBCXX_3.4.26
+FUNC:_ZNSt12__shared_ptrINSt10filesystem28recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC2EOS5_@@GLIBCXX_3.4.28
+FUNC:_ZNSt12__shared_ptrINSt10filesystem28recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC2Ev@@GLIBCXX_3.4.27
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem4_DirELN9__gnu_cxx12_Lock_policyE1EEC1EOS4_@@GLIBCXX_3.4.26
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem4_DirELN9__gnu_cxx12_Lock_policyE1EEC1Ev@@GLIBCXX_3.4.26
+FUNC:_ZNSt12__shared_ptrINSt10filesystem4_DirELN9__gnu_cxx12_Lock_policyE1EEC2EOS4_@@GLIBCXX_3.4.28
+FUNC:_ZNSt12__shared_ptrINSt10filesystem4_DirELN9__gnu_cxx12_Lock_policyE1EEC2Ev@@GLIBCXX_3.4.27
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem4_DirELN9__gnu_cxx12_Lock_policyE1EEaSEOS4_@@GLIBCXX_3.4.26
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx1128recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC1EOS6_@@GLIBCXX_3.4.26
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx1128recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC1Ev@@GLIBCXX_3.4.26
+FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx1128recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC2EOS6_@@GLIBCXX_3.4.28
+FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx1128recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE1EEC2Ev@@GLIBCXX_3.4.27
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE1EEC1EOS5_@@GLIBCXX_3.4.26
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE1EEC1Ev@@GLIBCXX_3.4.26
+FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE1EEC2EOS5_@@GLIBCXX_3.4.28
+FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE1EEC2Ev@@GLIBCXX_3.4.27
 
FUNC:_ZNSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE1EEaSEOS5_@@GLIBCXX_3.4.26
 FUNC:_ZNSt12bad_weak_ptrD0Ev@@GLIBCXX_3.4.15
 FUNC:_ZNSt12bad_weak_ptrD1Ev@@GLIBCXX_3.4.15
@@ -4401,6 +4411,8 @@ OBJECT:0:GLIBCXX_3.4.23
 OBJECT:0:GLIBCXX_3.4.24
 OBJECT:0:GLIBCXX_3.4.25
 OBJECT:0:GLIBCXX_3.4.26
+OBJECT:0:GLIBCXX_3.4.27
+OBJECT:0:GLIBCXX_3.4.28
 OBJECT:0:GLIBCXX_3.4.3
 OBJECT:0:GLIBCXX_3.4.4
 OBJECT:0:GLIBCXX_3.4.5
-- 
2.23.0


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[Ada] Disable selected optimizations done in gigi at -Og

2019-09-23 Thread Eric Botcazou
This disables 3 optimizations done in gigi when the -Og switch is passed: the 
rotation of loops, the NRV optimization (Named Return Value) and the inlining 
of local finalizers.

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


2019-09-23  Eric Botcazou  

* gcc-interface/trans.c (Regular_Loop_to_gnu): Do not rotate the loop
if -Og is enabled.
(build_return_expr): Do not perform NRV if -Og is enabled.
(Subprogram_Body_to_gnu): Likewise.
(gnat_to_gnu) : Likewise.
(Handled_Sequence_Of_Statements_to_gnu): Do not inline finalizers if
-Og is enabled.
* gcc-interface/utils.c (convert_to_index_type): Return early if -Og
is enabled.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 276045)
+++ gcc-interface/trans.c	(working copy)
@@ -3653,7 +3653,7 @@ Regular_Loop_to_gnu (Node_Id gnat_node,
 
 	 which works in all cases.  */
 
-  if (optimize)
+  if (optimize && !optimize_debug)
 	{
 	  /* We can use the do-while form directly if GNU_FIRST-1 doesn't
 	 overflow.  */
@@ -4436,6 +4436,7 @@ build_return_expr (tree ret_obj, tree re
 	 a candidate for Named Return Value.  If so, record it.  Otherwise,
 	 if this is an expression of some kind, record it elsewhere.  */
   if (optimize
+	  && !optimize_debug
 	  && AGGREGATE_TYPE_P (operation_type)
 	  && !TYPE_IS_FAT_POINTER_P (operation_type)
 	  && TYPE_MODE (operation_type) == BLKmode
@@ -4773,7 +4774,7 @@ Subprogram_Body_to_gnu (Node_Id gnat_nod
 
   /* If the function returns an aggregate type and we have candidates for
  a Named Return Value, finalize the optimization.  */
-  if (optimize && gnu_subprog_language->named_ret_val)
+  if (optimize && !optimize_debug && gnu_subprog_language->named_ret_val)
 {
   finalize_nrv (gnu_subprog_decl,
 		gnu_subprog_language->named_ret_val,
@@ -5893,7 +5894,7 @@ Handled_Sequence_Of_Statements_to_gnu (N
 
   /* When not optimizing, disable inlining of finalizers as this can
 	 create a more complex CFG in the parent function.  */
-  if (!optimize)
+  if (!optimize || optimize_debug)
 	DECL_DECLARED_INLINE_P (proc_decl) = 0;
 
   /* If there is no end label attached, we use the location of the At_End
@@ -8050,7 +8051,9 @@ gnat_to_gnu (Node_Id gnat_node)
 
 		/* And find out whether this is a candidate for Named Return
 		   Value.  If so, record it.  */
-		if (!TYPE_CI_CO_LIST (gnu_subprog_type) && optimize)
+		if (optimize
+		&& !optimize_debug
+		&& !TYPE_CI_CO_LIST (gnu_subprog_type))
 		  {
 		tree ret_val = gnu_ret_val;
 
Index: gcc-interface/utils.c
===
--- gcc-interface/utils.c	(revision 275988)
+++ gcc-interface/utils.c	(working copy)
@@ -5023,7 +5023,7 @@ convert_to_index_type (tree expr)
 
   /* If the type is unsigned, overflow is allowed so we cannot be sure that
  EXPR doesn't overflow.  Keep it simple if optimization is disabled.  */
-  if (TYPE_UNSIGNED (type) || !optimize)
+  if (TYPE_UNSIGNED (type) || !optimize || optimize_debug)
 return convert (sizetype, expr);
 
   switch (code)


[Ada] Process argument of pragma Compile_Time_{Error|Warning} in gigi

2019-09-23 Thread Eric Botcazou
As demonstrated by the testcase, gigi needs to process the (first) argument of 
pragma Compile_Time_{Error|Warning} to catch the case of a type otherwise not 
referenced in the main unit.

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


2019-09-23  Eric Botcazou  

* gcc-interface/trans.c (gnat_compile_time_expr_list): New variable.
(Pragma_to_gnu): Rename local variable.  Save the (first) expression
of pragma Compile_Time_{Error|Warning} for later processing.
(Compilation_Unit_to_gnu): Process the expressions saved above.


2019-09-23  Eric Botcazou  

* gnat.dg/specs/compile_time1.ads: New test.
* gnat.dg/specs/compile_time1_pkg.ads! New helper.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 276041)
+++ gcc-interface/trans.c	(working copy)
@@ -95,6 +95,9 @@ bool type_annotate_only;
 /* List of N_Validate_Unchecked_Conversion nodes in the unit.  */
 static vec gnat_validate_uc_list;
 
+/* List of expressions of pragma Compile_Time_{Error|Warning} in the unit.  */
+static vec gnat_compile_time_expr_list;
+
 /* When not optimizing, we cache the 'First, 'Last and 'Length attributes
of unconstrained array IN parameters to avoid emitting a great deal of
redundant instructions to recompute them each time.  */
@@ -1508,17 +1511,28 @@ static tree
 Pragma_to_gnu (Node_Id gnat_node)
 {
   tree gnu_result = alloc_stmt_list ();
-  unsigned char pragma_id;
   Node_Id gnat_temp;
 
-  /* Do nothing if we are just annotating types and check for (and ignore)
- unrecognized pragmas.  */
-  if (type_annotate_only
-  || !Is_Pragma_Name (Chars (Pragma_Identifier (gnat_node
+  /* Check for (and ignore) unrecognized pragmas.  */
+  if (!Is_Pragma_Name (Chars (Pragma_Identifier (gnat_node
 return gnu_result;
 
-  pragma_id = Get_Pragma_Id (Chars (Pragma_Identifier (gnat_node)));
-  switch (pragma_id)
+  const unsigned char id
+= Get_Pragma_Id (Chars (Pragma_Identifier (gnat_node)));
+
+  /* Save the expression of pragma Compile_Time_{Error|Warning} for later.  */
+  if (id == Pragma_Compile_Time_Error || id == Pragma_Compile_Time_Warning)
+{
+  gnat_temp = First (Pragma_Argument_Associations (gnat_node));
+  gnat_compile_time_expr_list.safe_push (Expression (gnat_temp));
+  return gnu_result;
+}
+
+  /* Stop there if we are just annotating types.  */
+  if (type_annotate_only)
+return gnu_result;
+
+  switch (id)
 {
 case Pragma_Inspection_Point:
   /* Do nothing at top level: all such variables are already viewable.  */
@@ -1670,11 +1684,11 @@ Pragma_to_gnu (Node_Id gnat_node)
 	  break;
 
 	tree gnu_clauses = gnu_loop_stack->last ()->omp_construct_clauses;
-	if (pragma_id == Pragma_Acc_Data)
+	if (id == Pragma_Acc_Data)
 	  gnu_loop_stack->last ()->omp_code = OACC_DATA;
-	else if (pragma_id == Pragma_Acc_Kernels)
+	else if (id == Pragma_Acc_Kernels)
 	  gnu_loop_stack->last ()->omp_code = OACC_KERNELS;
-	else if (pragma_id == Pragma_Acc_Parallel)
+	else if (id == Pragma_Acc_Parallel)
 	  gnu_loop_stack->last ()->omp_code = OACC_PARALLEL;
 	else
 	  gcc_unreachable ();
@@ -1914,7 +1928,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 	/* This is the String form: pragma Warning{s|_As_Error}(String).  */
 	if (Nkind (Expression (gnat_temp)) == N_String_Literal)
 	  {
-	switch (pragma_id)
+	switch (id)
 	  {
 	  case Pragma_Warning_As_Error:
 		kind = DK_ERROR;
@@ -6319,7 +6333,7 @@ Compilation_Unit_to_gnu (Node_Id gnat_no
 		   || Nkind (gnat_unit) == N_Subprogram_Body);
   const Entity_Id gnat_unit_entity = Defining_Entity (gnat_unit);
   Entity_Id gnat_entity;
-  Node_Id gnat_pragma;
+  Node_Id gnat_pragma, gnat_iter;
   /* Make the decl for the elaboration procedure.  Emit debug info for it, so
  that users can break into their elaboration code in debuggers.  Kludge:
  don't consider it as a definition so that we have a line map for its
@@ -6415,6 +6429,12 @@ Compilation_Unit_to_gnu (Node_Id gnat_no
   add_stmt_list (Actions (Aux_Decls_Node (gnat_node)));
   finalize_from_limited_with ();
 
+  /* Then process the expressions of pragma Compile_Time_{Error|Warning} to
+ annotate types referenced therein if they have not been annotated.  */
+  for (int i = 0; gnat_compile_time_expr_list.iterate (i, &gnat_iter); i++)
+(void) gnat_to_gnu_external (gnat_iter);
+  gnat_compile_time_expr_list.release ();
+
   /* Save away what we've made so far and finish it up.  */
   set_current_block_context (gnu_elab_proc_decl);
   gnat_poplevel ();
-- { dg-do compile }

with Compile_Time1_Pkg; use Compile_Time1_Pkg;

package Compile_Time1 is

  pragma Compile_Time_Error (Rec'Size /= Integer'Size, "wrong record size");

end Compile_Time1;
package Compile_Time1_Pkg is

  type Rec is record
I : Integer;
  end record;

end Compile_Time1_Pkg;


Re: [patch, testsuite, arm] Fix ICE in gcc.dg/gimplefe-28.c

2019-09-23 Thread Kyrill Tkachov



On 9/23/19 4:11 AM, Sandra Loosemore wrote:

On 9/20/19 2:18 AM, Kyrill Tkachov wrote:


Yeah, an add_options_for_arm_vfp is what we ideally need here.


How about this version of the patch?  The two test cases I also 
tweaked to use it are the only ones that use the corresponding 
arm_vfp_ok effective target.



That looks good.

Ok.

Thanks,

Kyrill




-Sandra


[Ada] Fix run-time segfault with private access-to-subprogram type

2019-09-23 Thread Eric Botcazou
This fixes a segfault at run time in a very peculiar case where an access-to-
subprogram type is declared as private and used to pass the address of a local 
subprogram and dereference it using different views of the type.

Tested on x86_64-suse-linux, applied on all active branches.


2019-09-23  Eric Botcazou  

* gcc-interface/trans.c (Attribute_to_gnu): Test Can_Use_Internal_Rep
on the underlying type of the node.
(Call_to_gnu): Likewise with the type of the prefix.

-- 
Eric BotcazouIndex: gcc-interface/trans.c
===
--- gcc-interface/trans.c	(revision 275988)
+++ gcc-interface/trans.c	(working copy)
@@ -2254,32 +2254,29 @@ Attribute_to_gnu (Node_Id gnat_node, tre
   /* For other address attributes applied to a nested function,
 	 find an inner ADDR_EXPR and annotate it so that we can issue
 	 a useful warning with -Wtrampolines.  */
-  else if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (gnu_prefix)))
-	{
-	  gnu_expr = remove_conversions (gnu_result, false);
-
-	  if (TREE_CODE (gnu_expr) == ADDR_EXPR
-	  && decl_function_context (TREE_OPERAND (gnu_expr, 0)))
-	{
-	  set_expr_location_from_node (gnu_expr, gnat_node);
-
-	  /* Also check the inlining status.  */
-	  check_inlining_for_nested_subprog (TREE_OPERAND (gnu_expr, 0));
-
-	  /* Moreover, for 'Access or 'Unrestricted_Access with non-
-		 foreign-compatible representation, mark the ADDR_EXPR so
-		 that we can build a descriptor instead of a trampoline.  */
-	  if ((attribute == Attr_Access
-		   || attribute == Attr_Unrestricted_Access)
-		  && targetm.calls.custom_function_descriptors > 0
-		  && Can_Use_Internal_Rep (Etype (gnat_node)))
-		FUNC_ADDR_BY_DESCRIPTOR (gnu_expr) = 1;
-
-	  /* Otherwise, we need to check that we are not violating the
-		 No_Implicit_Dynamic_Code restriction.  */
-	  else if (targetm.calls.custom_function_descriptors != 0)
-	Check_Implicit_Dynamic_Code_Allowed (gnat_node);
-	}
+  else if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (gnu_prefix))
+	   && (gnu_expr = remove_conversions (gnu_result, false))
+	   && TREE_CODE (gnu_expr) == ADDR_EXPR
+	   && decl_function_context (TREE_OPERAND (gnu_expr, 0)))
+	{
+	  set_expr_location_from_node (gnu_expr, gnat_node);
+
+	  /* Also check the inlining status.  */
+	  check_inlining_for_nested_subprog (TREE_OPERAND (gnu_expr, 0));
+
+	  /* Moreover, for 'Access or 'Unrestricted_Access with non-
+	 foreign-compatible representation, mark the ADDR_EXPR so
+	 that we can build a descriptor instead of a trampoline.  */
+	  if ((attribute == Attr_Access
+	   || attribute == Attr_Unrestricted_Access)
+	  && targetm.calls.custom_function_descriptors > 0
+	  && Can_Use_Internal_Rep (Underlying_Type (Etype (gnat_node
+	FUNC_ADDR_BY_DESCRIPTOR (gnu_expr) = 1;
+
+	  /* Otherwise, we need to check that we are not violating the
+	 No_Implicit_Dynamic_Code restriction.  */
+	  else if (targetm.calls.custom_function_descriptors != 0)
+	Check_Implicit_Dynamic_Code_Allowed (gnat_node);
 	}
   break;
 
@@ -5111,7 +5108,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gn
   /* If the access type doesn't require foreign-compatible representation,
 	 be prepared for descriptors.  */
   if (targetm.calls.custom_function_descriptors > 0
-	  && Can_Use_Internal_Rep (Etype (Prefix (Name (gnat_node)
+	  && Can_Use_Internal_Rep
+	 (Underlying_Type (Etype (Prefix (Name (gnat_node))
 	by_descriptor = true;
 }
   else if (Nkind (Name (gnat_node)) == N_Attribute_Reference)


Re: [Patch 0/X] [WIP][RFC][libsanitizer] Introduce HWASAN to GCC

2019-09-23 Thread Martin Liška
Hi.

As mentioned in the next email thread, there are main objectives
that will help me to make a proper patch review:

1) Make first libsanitizer merge from trunk, it will remove the need
   of the backports that you made. Plus I will be able to apply the
   patchset on the current master.
2) I would exclude the setjmp/longjmp - these should be upstreamed first
   in libsanitizer.
3) I would like to see a two HWASAN options that will clearly separate the
   2 supported modes: TBI without MTE and MTE. Here I would appreciate to have
   a compiler farm machine with TBI which we can use for testing.
4) About the BUILTIN expansion: you provided a patch for couple of them. My 
question
   is whether the list is complete?
5) I would appreciate the patch set to be split into less logical parts, e.g.
   libsanitizer changes; option introduction; stack variable handling 
(colour/uncolour/alignment);
   hwasan pass and other GIMPLE-related changes; RTL hooks, new RTL 
instructions and expansion changes.

Thank you,
Martin
   


Re: [PATCH] xtensa: fix PR target/90922

2019-09-23 Thread Max Filippov
On Tue, Jun 18, 2019 at 3:23 PM Max Filippov  wrote:
>
> On Tue, Jun 18, 2019 at 3:09 PM augustine.sterl...@gmail.com
>  wrote:
> >
> > On Tue, Jun 18, 2019 at 2:27 PM Max Filippov  wrote:
> > >
> > > Stack pointer adjustment code in prologue missed a case of no
> > > callee-saved registers and a stack frame size bigger than 128 bytes.
> > > Handle that case.
> > >
> > > This fixes the following gcc tests with call0 ABI:
> > >   gcc.c-torture/execute/stdarg-2.c
> > >   gcc.dg/torture/pr55882.c
> > >   gcc.dg/torture/pr57569.c
> >
> > Approved, please apply.
>
> Thanks. Applied to trunk.
> I'll backport it later to gcc-7..9 branches.

I've committed the backported versions to gcc-7..9 branches.

-- 
Thanks.
-- Max


Re: Question on direction of GCC support for HWASAN.

2019-09-23 Thread Martin Liška
On 9/20/19 7:11 PM, Matthew Malcomson wrote:
> Hello,

Hi.

Next time, please send the email to the HWASAN email thread.

> 
> I'm nearing the point where I think the hardware-asan patch series could
> go in and would appreciate some feedback on what features need to be
> implemented before it could be put into trunk.

I'll reply to the original cover letter email about what will help me to
do a proper patch review easier.

> (The RFC can be found at
> https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00387.html, the only
> change to the general approach I've made since then is to use backend
> hooks to determine the RTL to emit instead of introducing a new RTX
> called `ADDTAG`)
> 
> ---
> Note that hwasan will not have support for architectures other than
> AArch64 to start with, and any support that could be added later for
> architectures without TBI would be difficult.
> 
> As a comparison; LLVM has support for hwasan on x86_64 "but it's not
> really practical because any library built without instrumentation is a
> big source of false positives"
> https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00773.html.

Yes, I agree with you that we should aim only on aarch64 in 2 modes:
TBI and MTE.

> 
> 
> ---
> We would really like to enable using HWASAN for the kernel (in KHWASAN
> -- https://lwn.net/Articles/748455/) when compiling with GCC, while also
> allowing use of hwasan for testing/debugging of userland processes
> (i.e. not to be run in production).
> A secondary benefit is that the hwasan instrumentation should provide a
> framework for adding stack-tagging MTE support to the compiler.
> 
> The implementation is unlikely to be production-quality since
> development on libhwasan is only on its `platform` ABI.  This libhwasan
> ABI requires changes to the system libc so that it calls into libhwasan
> on interesting events.
> I haven't looked into adding these changes to glibc, but expect that
> most people running a Linux distribution would not want to install a
> special glibc to use this sanitizer.

Can you please provide a link about what special one needs in glibc
to support HWASAN?

> 
> The alternate libhwasan ABI is called the `interceptor` ABI.  This
> intercepts certain functions in the system libc so that libhwasan can
> run its own code.  The method of intercepting events has some known
> difficulties.  Also, as one of the LLVM hwasan developers mentioned,
> this ABI is not being developed any more
> https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00773.html.
> 
> 
> ---
> If this aim is acceptable, then the biggest question I have is whether
> HWASAN could be accepted as a first stage without having the option for
> inline instrumentation.

Yes, that is really not needed now and can be added incrementally.

> As it stands I've just implemented the
> function-call instrumentation for checking tags and tagging memory, with
> the idea that inline instrumentation could be added later.
> 
> Similarly I'm not planning on implementing global instrumentation for 
> this first stage and hoping that's OK with the community.

Which is also fine for me.

Martin

> 
> Cheers,
> Matthew
> 



[Ada] Fix size increase for packed record with aliased component

2019-09-23 Thread Eric Botcazou
This fixes a fallout of the reordering of components in record types that was 
enabled some time ago: the size of a packed record with an aliased component 
may be larger than the size that would have been given by a textual layout of 
the record type.

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


2019-09-23  Eric Botcazou  

* gcc-interface/decl.c (components_to_record): Do not reorder fields
in packed record types if they contain fixed-size fields that cannot
be laid out in a packed manner.

-- 
Eric BotcazouIndex: gcc-interface/decl.c
===
--- gcc-interface/decl.c	(revision 275988)
+++ gcc-interface/decl.c	(working copy)
@@ -7521,6 +7521,7 @@ components_to_record (Node_Id gnat_compo
   bool all_rep_and_size = all_rep && TYPE_SIZE (gnu_record_type);
   bool variants_have_rep = all_rep;
   bool layout_with_rep = false;
+  bool has_non_packed_fixed_size_field = false;
   bool has_self_field = false;
   bool has_aliased_after_self_field = false;
   Entity_Id gnat_component_decl, gnat_variant_part;
@@ -7577,6 +7578,10 @@ components_to_record (Node_Id gnat_compo
 		  has_self_field = true;
 		else if (has_self_field && DECL_ALIASED_P (gnu_field))
 		  has_aliased_after_self_field = true;
+		else if (!DECL_FIELD_OFFSET (gnu_field)
+			 && !DECL_PACKED (gnu_field)
+			 && !field_has_variable_size (gnu_field))
+		  has_non_packed_fixed_size_field = true;
 	  }
 	  }
 
@@ -7868,8 +7873,9 @@ components_to_record (Node_Id gnat_compo
  self-referential/variable offset or misaligned.  Note, in the latter
  case, that this can only happen in packed record types so the alignment
  is effectively capped to the byte for the whole record.  But we don't
- do it for non-packed record types if pragma Optimize_Alignment (Space)
- is specified because this can prevent alignment gaps from being filled.
+ do it for packed record types if not all fixed-size fiels can be packed
+ and for non-packed record types if pragma Optimize_Alignment (Space) is
+ specified, because this can prevent alignment gaps from being filled.
 
  Optionally, if the layout warning is enabled, keep track of the above 4
  different kinds of fields and issue a warning if some of them would be
@@ -7880,8 +7886,9 @@ components_to_record (Node_Id gnat_compo
   const bool do_reorder
 = (Convention (gnat_record_type) == Convention_Ada
&& !No_Reordering (gnat_record_type)
-   && (!Optimize_Alignment_Space (gnat_record_type)
-	   || Is_Packed (gnat_record_type))
+   && !(Is_Packed (gnat_record_type)
+	? has_non_packed_fixed_size_field
+	: Optimize_Alignment_Space (gnat_record_type))
&& !debug__debug_flag_dot_r);
   const bool w_reorder
 = (Convention (gnat_record_type) == Convention_Ada