Re: [PATCH 1/2] S/390: Support vector load/store alignment hints

2020-07-16 Thread Andreas Krebbel via Gcc-patches
On 15.07.20 17:53, Stefan Schulze Frielinghaus wrote:
> From: Andreas Krebbel 
> 
> The IBM z14 POP adds an optional alignment operand to the vl, vst,
> vlm, and vstm instruction (vector loads and stores). Vectors residing
> on 8 or 16 byte boundaries might get loaded or stored faster on some
> models given the instruction uses the proper hint operand.  A wrong
> hint will hurt performance though.
> 
> The attached testcase align-1 currently fails due to:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88085
> 
> gcc/ChangeLog:
> 
> 2018-11-21  Andreas Krebbel  
> 
>   * configure.ac: Add check for Binutils to determine whether vector
>   load/store alignments hints are being supported.
>   * config.in: Regenerate.
>   * configure: Regenerate.
>   * config/s390/s390.c (print_operand): Support new output
>   modifier A.
>   * config/s390/s390.md ("movti"): Append alignment hint output
>   using the new output modifier 'A'.
>   * config/s390/vector.md ("mov", "*vec_tf_to_v1tf")
>   ("*vec_ti_to_v1ti"): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 2018-11-21  Andreas Krebbel  
> 
>   * gcc.target/s390/vector/align-1.c: New test.
>   * gcc.target/s390/vector/align-2.c: New test.

Ok, thanks!

Andreas



Re: [PATCH 2/2] S/390: Emit vector alignment hints for z13 if AS accepts them

2020-07-16 Thread Andreas Krebbel via Gcc-patches
On 15.07.20 17:53, Stefan Schulze Frielinghaus wrote:
> gcc/ChangeLog:
> 
>   * config.in: Regenerate.
>   * config/s390/s390.c (print_operand): Emit vector alignment hints
>   for target z13, if AS accepts them.  For other targets the logic
>   stays the same.
>   * config/s390/s390.h (TARGET_VECTOR_LOADSTORE_ALIGNMENT_HINTS): Define
>   macro.
>   * configure: Regenerate.
>   * configure.ac: Check HAVE_AS_VECTOR_LOADSTORE_ALIGNMENT_HINTS_ON_Z13.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/s390/vector/align-1.c: Change target architecture
>   to z13.
>   * gcc.target/s390/vector/align-2.c: Change target architecture
>   to z13.

Ok. Thanks!

Andreas


Re: [PATCH] S/390: Emit vector alignment hints for z13 if AS accepts them [BACKPORT GCC9]

2020-07-16 Thread Andreas Krebbel via Gcc-patches
On 09.07.20 09:35, Stefan Schulze Frielinghaus wrote:
> Bootstrapped and regtested on s390x with and without a patched gas. Ok
> for master?
> 
> gcc/ChangeLog:
> 
>   * config.in: Regenerate.
>   * config/s390/s390.c (print_operand): Emit vector alignment hints
>   for target z13, if AS accepts them.  For other targets the logic
>   stays the same.
>   * config/s390/s390.h (TARGET_VECTOR_LOADSTORE_ALIGNMENT_HINTS): Define
>   macro.
>   * configure: Regenerate.
>   * configure.ac: Check HAVE_AS_VECTOR_LOADSTORE_ALIGNMENT_HINTS_ON_Z13.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/s390/vector/align-1.c: Change target architecture
>   to z13.
>   * gcc.target/s390/vector/align-2.c: Change target architecture
>   to z13.

Ok. Thanks!

Andreas


Re: [PATCH] S/390: Emit vector alignment hints for z13 if AS accepts them [BACKPORT GCC10]

2020-07-16 Thread Andreas Krebbel via Gcc-patches
On 09.07.20 09:29, Stefan Schulze Frielinghaus wrote:
> gcc/ChangeLog:
> 
>   * config.in: Regenerate.
>   * config/s390/s390.c (print_operand): Emit vector alignment hints
>   for target z13, if AS accepts them.  For other targets the logic
>   stays the same.
>   * config/s390/s390.h (TARGET_VECTOR_LOADSTORE_ALIGNMENT_HINTS): Define
>   macro.
>   * configure: Regenerate.
>   * configure.ac: Check HAVE_AS_VECTOR_LOADSTORE_ALIGNMENT_HINTS_ON_Z13.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.target/s390/vector/align-1.c: Change target architecture
>   to z13.
>   * gcc.target/s390/vector/align-2.c: Change target architecture
>   to z13.

Ok. Thanks!

Andreas



[wwwdocs PATCH v2] projects/tree-ssa: add a big banner to tree-browser.html

2020-07-16 Thread Hu Jiangping
Hi,

Different from Patch v1 which removed the page, I add a big banner to
say that the page is no longer up-to-date, just as Richard and Gerald
recommended. OK for push?

Regards!
Hujp

---
 htdocs/projects/tree-ssa/tree-browser.html | 5 +
 1 file changed, 5 insertions(+)

diff --git a/htdocs/projects/tree-ssa/tree-browser.html 
b/htdocs/projects/tree-ssa/tree-browser.html
index ce95a103..fe292b49 100644
--- a/htdocs/projects/tree-ssa/tree-browser.html
+++ b/htdocs/projects/tree-ssa/tree-browser.html
@@ -8,6 +8,11 @@
 
   
   
+
+
+Tree Browser has been removed from gcc,
+and this page is no longer up-to-date.
+
 Tree Browser
 
 Until recently the only way to debug trees from gdb was to call
-- 
2.17.1





Re: OpenACC 'attach'/'detach' has no business affecting user-visible reference counting

2020-07-16 Thread Thomas Schwinge
Hi Julian!

On 2020-06-18T19:21:57+0100, Julian Brown  wrote:
> On Tue, 9 Jun 2020 12:41:21 +0200
> Thomas Schwinge  wrote:
>> On 2020-06-05T21:31:08+0100, Julian Brown 
>> wrote:
>> > On Fri, 5 Jun 2020 13:17:09 +0200
>> > Thomas Schwinge  wrote:
>> >> On 2019-12-17T21:03:47-0800, Julian Brown 
>> >> wrote:
>> >> > This part contains the libgomp runtime support for the
>> >> > GOMP_MAP_ATTACH and GOMP_MAP_DETACH mapping kinds
>> >>
>> >> > --- a/libgomp/target.c
>> >> > +++ b/libgomp/target.c
>> >>
>> >> > @@ -1203,6 +1211,32 @@ gomp_map_vars_internal (struct gomp_device_descr 
>> >> > *devicep,
>> >>
>> >> > + case GOMP_MAP_ATTACH:
>> >> > +   {
>> >> > + cur_node.host_start = (uintptr_t) hostaddrs[i];
>> >> > + cur_node.host_end = cur_node.host_start + sizeof 
>> >> > (void *);
>> >> > + splay_tree_key n = splay_tree_lookup (mem_map, 
>> >> > &cur_node);
>> >> > + if (n != NULL)
>> >> > +   {
>> >> > + tgt->list[i].key = n;
>> >> > + tgt->list[i].offset = cur_node.host_start - 
>> >> > n->host_start;
>> >> > + tgt->list[i].length = n->host_end - n->host_start;
>> >> > + tgt->list[i].copy_from = false;
>> >> > + tgt->list[i].always_copy_from = false;
>> >> > + tgt->list[i].do_detach
>> >> > +   = (pragma_kind != 
>> >> > GOMP_MAP_VARS_OPENACC_ENTER_DATA);
>> >> > + n->refcount++;
>> >> > +   }
>> >> > + else
>> >> > +   {
>> >> > + gomp_mutex_unlock (&devicep->lock);
>> >> > + gomp_fatal ("outer struct not mapped for attach");
>> >> > +   }
>> >> > + gomp_attach_pointer (devicep, aq, mem_map, n,
>> >> > +  (uintptr_t) hostaddrs[i], 
>> >> > sizes[i],
>> >> > +  cbufp);
>> >> > + continue;
>> >> > +   }
>> >>
>> >> For the OpenACC runtime API 'acc_attach' etc. routines they don't,
>> >> so what's the conceptual reason that for the corresponding OpenACC
>> >> directive variants, 'GOMP_MAP_ATTACH' etc. here participate in
>> >> reference counting ('n->refcount++' above)?  I understand OpenACC
>> >> 'attach'/'detach' clauses to be simple "executable clauses", which
>> >> just update some values somewhere (say, like
>> >> 'GOMP_MAP_ALWAYS_POINTER'), but they don't alter any mapping state,
>> >> thus wouldn't appear to need reference counting?
>> >
>> > IIUC, n->refcount is not directly the "structural reference count"
>> > as seen at source level, but rather counts the number of
>> > target_var_descs in the lists appended to each target_mem_desc --
>> > and GOMP_MAP_ATTACH have variable entries in those lists.
>>
>> That may be OK if that's purely an implementation detail that isn't
>> visible to the user, however:
>>
>> > That's not the case for the API
>> > routines.
>>
>> As I had mentioned, the problem is: in contrast to 'acc_attach', an
>> OpenACC 'enter data' directive with 'attach' clause currently uses
>> this same reference-counted code path, and thus such an 'attach'
>> without corresponding 'detach' inhibits unmapping; [...]
>
> The attached patch stops attach/detach operations from affecting
> reference counts (either structured or dynamic). This isn't as invasive
> as I'd imagined: we can extend the use of the "do_detach" flag in
> target_mem_descs' variable lists to mark mappings that correspond to
> attach operations, then use that flag to avoid refcount
> increment/decrements.

Thanks, ACK.

> (The flag should possibly be renamed now.)

How about:

-  /* True if variable should be detached at end of region.  */
-  bool do_detach;
+  /* True if this is for OpenACC 'attach'.  */
+  bool is_attach;

(Changing that similarly is obvious/pre-approved.)

> Tested with offloading to NVPTX. OK?

I've adjusted the patch for current GCC sources, and did some further
changes/cleanup; see below, and attached "[OpenACC] Deep copy
attach/detach should not affect reference counts".  If you're happy with
that, that's OK for master and releases/gcc-10 (once un-frozen) branches.

> --- a/libgomp/oacc-mem.c
> +++ b/libgomp/oacc-mem.c

> @@ -1131,7 +1134,9 @@ goacc_enter_data_internal (struct gomp_device_descr 
> *acc_dev, size_t mapnum,
>   if (tgt->list[j].key == n)
> {
>   for (size_t k = 0; k < groupnum; k++)
> -   if (j + k < tgt->list_count && tgt->list[j + k].key)
> +   if (j + k < tgt->list_count
> +   && tgt->list[j + k].key
> +   && !tgt->list[j + k].do_detach)
>   {
> tgt->list[j + k].key->refcount++;
> tgt->list[j + k].key->dynamic_refcount++;
> @@ -1156,7 +1161,7 @@ goa

Re: [PATCH] libsanitizer: Fix GetPcSpBp determination of SP on 32-bit Solaris/x86

2020-07-16 Thread Rainer Orth
Hi Jakub,

>> I may still be mistaken, but all this suggests that Linux might be
>> playing games with ESP and UESP, while Solaris and NetBSD (see below)
>> keep them separate, but in the end UESP is the register to use.
>
> I think what matters more is
> kernel/signal.c and ia32/ia32_signal.c doing:
> put_user_ex(regs->sp, &sc->sp);
> ...
> put_user_ex(regs->sp, &sc->sp_at_signal);
> i.e. both ESP and UESP ought to have the same value in the end on Linux.
>
> Your patch is ok for trunk and for 10.3 after a few weeks (10.2 is frozen
> ATM anyway) so that if there are some problems (like say some headers not
> defining REG_UESP or something similar), we'll find that out on trunk first.

fair enough.  What about the gcc-9 branch by then?  I expect there will
be at least one more release from that one, too?

Thanks.
Rainer

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


[Ada] AI12-0373 Additional check on Integer_Literal function

2020-07-16 Thread Pierre-Marie de Rodat
Part (1) clarifies that we anticipated in Statically_Names_Object,
update comment accordingly.

Part 4 (4) clarifies: 4.2.1(3/5) says that the only parameter of a
user-defined Integer_Literal function is of type String. But it doesn't
specify a mode.

Since the parameter is passed a string literal, a call to a function
with a mode other than "in" would be illegal. Thus, defining the
function with an "in out" parameter would be useless. Similarly, if the
parameter was explicitly aliased, any call would be illegal as the
actual is not aliased.  So that would also be useless as well.

We were doing it right except for checking the 'explicitly aliased'
part.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch13.adb (Validate_Literal_Aspect): Ensure that the
parameter is not aliased. Minor reformatting.
* sem_util.adb (Statically_Names_Object): Update comment.diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -16016,10 +16016,12 @@ package body Sem_Ch13 is
   Match_Found : Boolean := False;
   Is_Match: Boolean;
   Match   : Interp;
+
begin
   if not Is_Type (Typ) then
  Error_Msg_N ("aspect can only be specified for a type", ASN);
  return;
+
   elsif not Is_First_Subtype (Typ) then
  Error_Msg_N ("aspect cannot be specified for a subtype", ASN);
  return;
@@ -16030,12 +16032,15 @@ package body Sem_Ch13 is
 Error_Msg_N ("aspect cannot be specified for a string type", ASN);
 return;
  end if;
+
  Param_Type := Standard_Wide_Wide_String;
+
   else
  if Is_Numeric_Type (Typ) then
 Error_Msg_N ("aspect cannot be specified for a numeric type", ASN);
 return;
  end if;
+
  Param_Type := Standard_String;
   end if;
 
@@ -16059,17 +16064,21 @@ package body Sem_Ch13 is
and then Base_Type (Etype (It.Nam)) = Typ
  then
 declare
-   Params : constant List_Id :=
+   Params : constant List_Id :=
  Parameter_Specifications (Parent (It.Nam));
Param_Spec : Node_Id;
Param_Id   : Entity_Id;
+
 begin
if List_Length (Params) = 1 then
   Param_Spec := First (Params);
+
   if not More_Ids (Param_Spec) then
  Param_Id := Defining_Identifier (Param_Spec);
+
  if Base_Type (Etype (Param_Id)) = Param_Type
-and then Ekind (Param_Id) = E_In_Parameter
+   and then Ekind (Param_Id) = E_In_Parameter
+   and then not Is_Aliased (Param_Id)
  then
 Is_Match := True;
  end if;
@@ -16083,6 +16092,7 @@ package body Sem_Ch13 is
Error_Msg_N ("aspect specification is ambiguous", ASN);
return;
 end if;
+
 Match_Found := True;
 Match := It;
  end if;


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -27054,6 +27054,7 @@ package body Sem_Util is
-
-- Statically_Names_Object --
-
+
function Statically_Names_Object (N : Node_Id) return Boolean is
begin
   if Statically_Denotes_Object (N) then
@@ -27126,28 +27127,16 @@ package body Sem_Util is
 then
return False;
 end if;
+
 declare
Comp : constant Entity_Id :=
  Original_Record_Component (Entity (Selector_Name (N)));
 begin
-  --  In not calling Has_Discriminant_Dependent_Constraint here,
-  --  we are anticipating a language definition fixup. The
-  --  current definition of "statically names" includes the
-  --  wording "the selector_name names a component that does
-  --  not depend on a discriminant", which suggests that this
-  --  call should not be commented out. But it appears likely
-  --  that this wording will be updated to only apply to a
-  --  component declared in a variant part. There is no need
-  --  to disallow something like
-  --with Post => ... and then
-  --   Some_Record.Some_Discrim_Dep_Array_Component'Old (I)
-  --  since the evaluation of the 'Old prefix cannot raise an
-  --  exception. If the language is not updated, then the call
-  --  below to H_D_C_C will need to be uncommented.
-
-   if Is_Declared_Within_Variant (Comp)
-  --  or else Has_Discriminant_Dependent_Constraint (Comp)
-   then
+  --  AI12-0373 confirms that we should not call
+

[Ada] Incorrect static accessibility error in return aggregate

2020-07-16 Thread Pierre-Marie de Rodat
This patch fixes a bug in the compiler whereby a local object of a named
access type used as an actual for an anonymous access discriminant
within a return aggregate would lead to an incorrect accessibility level
calculation and thus an incorrect compile-time accessibility error on
such an object.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* einfo.adb, einfo.ads (Is_Named_Access_Type): Created for
readability.
* sem_ch6.adb (Check_Return_Construct_Accessibility): Add
special cases for formals.
* sem_util.adb (Object_Access_Level): Add handling of access
attributes and named access types in the general case.diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb
--- a/gcc/ada/einfo.adb
+++ b/gcc/ada/einfo.adb
@@ -3797,6 +3797,12 @@ package body Einfo is
   return Ekind (Id) in Modular_Integer_Kind;
end Is_Modular_Integer_Type;
 
+   function Is_Named_Access_Type(Id : E) return B is
+   begin
+  return Ekind (Id) in E_Access_Type ..
+ E_Access_Protected_Subprogram_Type;
+   end Is_Named_Access_Type;
+
function Is_Named_Number (Id : E) return B is
begin
   return Ekind (Id) in Named_Kind;


diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -7624,6 +7624,7 @@ package Einfo is
function Is_Integer_Type (Id : E) return B;
function Is_Limited_Record   (Id : E) return B;
function Is_Modular_Integer_Type (Id : E) return B;
+   function Is_Named_Access_Type(Id : E) return B;
function Is_Named_Number (Id : E) return B;
function Is_Numeric_Type (Id : E) return B;
function Is_Object   (Id : E) return B;


diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -904,6 +904,11 @@ package body Sem_Ch6 is
   --  named access types and renamed objects within the
   --  expression.
 
+  --  Note, this loop duplicates some of the logic in
+  --  Object_Access_Level since we have to check special rules
+  --  based on the context we are in (a return aggregate)
+  --  relating to formals of the current function.
+
   Obj := Original_Node (Prefix (Expr));
   loop
  while Nkind_In (Obj, N_Explicit_Dereference,
@@ -943,15 +948,20 @@ package body Sem_Ch6 is
  end if;
   end loop;
 
-  --  Do not check aliased formals or function calls. A
-  --  run-time check may still be needed ???
+  --  Do not check aliased formals statically
 
   if Is_Formal (Entity (Obj))
-and then Is_Aliased (Entity (Obj))
+and then (Is_Aliased (Entity (Obj))
+   or else Ekind (Etype (Entity (Obj))) =
+ E_Anonymous_Access_Type)
   then
  null;
 
-  elsif Object_Access_Level (Obj) >
+  --  Otherwise, handle the expression normally, avoiding the
+  --  special logic above, and call Object_Access_Level with
+  --  the original expression.
+
+  elsif Object_Access_Level (Expr) >
   Scope_Depth (Scope (Scope_Id))
   then
  Error_Msg_N


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -24330,7 +24330,7 @@ package body Sem_Util is
  --  than the level of any visible named access type (see 3.10.2(21)).
 
  if Is_Type (E) then
-return Type_Access_Level (E) +  1;
+return Type_Access_Level (E) + 1;
 
  elsif Present (Renamed_Object (E)) then
 return Object_Access_Level (Renamed_Object (E));
@@ -24347,6 +24347,12 @@ package body Sem_Util is
  then
 return Type_Access_Level (Scope (E)) + 1;
 
+ --  An object of a named access type gets its level from its
+ --  associated type.
+
+ elsif Is_Named_Access_Type (Etype (E)) then
+return Type_Access_Level (Etype (E));
+
  else
 return Scope_Depth (Enclosing_Dynamic_Scope (E));
  end if;
@@ -24559,6 +24565,15 @@ package body Sem_Util is
   then
  return Object_Access_Level (Current_Scope);
 
+  --  Move up the attribute reference when we encounter a 'Access variation
+
+  elsif Nkind (Orig_Obj) = N_Attribute_Reference
+and then Nam_In (Attribute_Name (Orig_Obj), Name_Access,
+Name_Unchecked_Access,
+   

[Ada] Do not perform null exclusion static checks on generated entities

2020-07-16 Thread Pierre-Marie de Rodat
Performing null exclusion checks on generated entities can result in
bogus error messages.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch3.adb (Analyze_Object_Declaration): Add
Comes_From_Source call.diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4055,7 +4055,7 @@ package body Sem_Ch3 is
 then
null;
 
-else
+elsif Comes_From_Source (Id) then
declare
   Save_Typ : constant Entity_Id := Etype (Id);
begin




[Ada] Simplify detection of others choice with just one value

2020-07-16 Thread Pierre-Marie de Rodat
Trivial cleanup with equality between universal integers, which should
be much faster than subtraction. Semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_case.adb (Build_Choice): Simplify.diff --git a/gcc/ada/sem_case.adb b/gcc/ada/sem_case.adb
--- a/gcc/ada/sem_case.adb
+++ b/gcc/ada/sem_case.adb
@@ -1012,7 +1012,7 @@ package body Sem_Case is
  --  If there is only one choice value missing between Value1 and
  --  Value2, build an integer or enumeration literal to represent it.
 
- if (Value2 - Value1) = 0 then
+ if Value1 = Value2 then
 if Is_Integer_Type (Choice_Type) then
Lit_Node := Make_Integer_Literal (Loc, Value1);
Set_Etype (Lit_Node, Choice_Type);




[Ada] Ada2020: AI12-0289 Implicitly null excluding anon access

2020-07-16 Thread Pierre-Marie de Rodat
This patch implements AI12-0289. In particular, if an untagged type T is
completed with a tagged full type, and a parameter whose type is "access
T", where T denotes the partial view in the subprogram spec, an explicit
"not null" is required.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch6.adb (Null_Exclusions_Match): New function to check
that the null exclusions match, including in the case addressed
by this AI.
(Check_Conformance): Remove calls to Comes_From_Source
when calling Null_Exclusions_Match. These are not
needed, as indicated by an ancient "???" comment.diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -5605,10 +5605,11 @@ package body Sem_Ch6 is
   --  in the message, and also provides the location for posting the
   --  message in the absence of a specified Err_Loc location.
 
-  function Conventions_Match
-(Id1 : Entity_Id;
- Id2 : Entity_Id) return Boolean;
-  --  Determine whether the conventions of arbitrary entities Id1 and Id2
+  function Conventions_Match (Id1, Id2 : Entity_Id) return Boolean;
+  --  True if the conventions of entities Id1 and Id2 match.
+
+  function Null_Exclusions_Match (F1, F2 : Entity_Id) return Boolean;
+  --  True if the null exclusions of two formals of anonymous access type
   --  match.
 
   ---
@@ -5699,6 +5700,50 @@ package body Sem_Ch6 is
  end if;
   end Conventions_Match;
 
+  ---
+  -- Null_Exclusions_Match --
+  ---
+
+  function Null_Exclusions_Match (F1, F2 : Entity_Id) return Boolean is
+  begin
+ if not Is_Anonymous_Access_Type (Etype (F1))
+   or else not Is_Anonymous_Access_Type (Etype (F2))
+ then
+return True;
+ end if;
+
+ --  AI12-0289-1: Case of controlling access parameter; False if the
+ --  partial view is untagged, the full view is tagged, and no explicit
+ --  "not null". Note that at this point, we're processing the package
+ --  body, so private/full types have been swapped. The Sloc test below
+ --  is to detect the (legal) case where F1 comes after the full type
+ --  declaration. This part is disabled pre-2005, because "not null" is
+ --  not allowed on those language versions.
+
+ if Ada_Version >= Ada_2005
+   and then Is_Controlling_Formal (F1)
+   and then not Null_Exclusion_Present (Parent (F1))
+   and then not Null_Exclusion_Present (Parent (F2))
+ then
+declare
+   D : constant Entity_Id := Directly_Designated_Type (Etype (F1));
+   Partial_View_Of_Desig : constant Entity_Id :=
+ Incomplete_Or_Partial_View (D);
+begin
+   return No (Partial_View_Of_Desig)
+ or else Is_Tagged_Type (Partial_View_Of_Desig)
+ or else Sloc (D) < Sloc (F1);
+end;
+
+ --  Not a controlling parameter, or one or both views have an explicit
+ --  "not null".
+
+ else
+return Null_Exclusion_Present (Parent (F1)) =
+   Null_Exclusion_Present (Parent (F2));
+ end if;
+  end Null_Exclusions_Match;
+
   --  Local Variables
 
   Old_Type   : constant Entity_Id := Etype (Old_Id);
@@ -5868,25 +5913,14 @@ package body Sem_Ch6 is
 
 --  Null exclusion must match
 
-if Null_Exclusion_Present (Parent (Old_Formal))
- /=
-   Null_Exclusion_Present (Parent (New_Formal))
-then
-   --  Only give error if both come from source. This should be
-   --  investigated some time, since it should not be needed ???
-
-   if Comes_From_Source (Old_Formal)
-and then
-  Comes_From_Source (New_Formal)
-   then
-  Conformance_Error
-("\null exclusion for& does not match", New_Formal);
+if not Null_Exclusions_Match (Old_Formal, New_Formal) then
+   Conformance_Error
+ ("\null exclusion for& does not match", New_Formal);
 
-  --  Mark error posted on the new formal to avoid duplicated
-  --  complaint about types not matching.
+   --  Mark error posted on the new formal to avoid duplicated
+   --  complaint about types not matching.
 
-  Set_Error_Posted (New_Formal);
-   end if;
+   Set_Error_Posted (New_Formal);
 end if;
  end if;
 




[Ada] Add centralized capacity check in Generic_Bignums

2020-07-16 Thread Pierre-Marie de Rodat
This replaces the special case done in "**" so far.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-genbig.adb ("**"): Remove capacity limit check.
Improve code by using an extended return.
(Normalize): Perform capacity limit check here instead which is
the centralized place where (potentially large) big integers are
allocated.diff --git a/gcc/ada/libgnat/s-genbig.adb b/gcc/ada/libgnat/s-genbig.adb
--- a/gcc/ada/libgnat/s-genbig.adb
+++ b/gcc/ada/libgnat/s-genbig.adb
@@ -98,6 +98,7 @@ package body System.Generic_Bignums is
--  Given a digit vector and sign, allocate and construct a big integer
--  value. Note that X may have leading zeroes which must be removed, and if
--  the result is zero, the sign is forced positive.
+   --  If X is too big, Storage_Error is raised.
 
function "**" (X : Bignum; Y : SD) return Big_Integer;
--  Exponentiation routine where we know right operand is one word
@@ -274,32 +275,18 @@ package body System.Generic_Bignums is
XY2  : aliased Big_Integer := X ** (Y / 2);
XY2S : aliased Big_Integer :=
  Big_Mul (To_Bignum (XY2), To_Bignum (XY2));
-   Res  : Big_Integer;
 
 begin
Free_Big_Integer (XY2);
 
-   --  Raise storage error if intermediate value is getting too
-   --  large, which we arbitrarily define as 200 words for now.
-   --  ??? Consider putting a limit instead in a wrapper of
-   --  Allocate_Big_Integer and update all calls to
-   --  Allocate_Big_Integer to call this wrapper, to catch all such
-   --  cases.
-
-   if To_Bignum (XY2S).Len > 200 then
-  Free_Big_Integer (XY2S);
-  raise Storage_Error with
-"exponentiation result is too large";
-   end if;
-
-   --  Otherwise take care of even/odd cases
-
if (Y and 1) = 0 then
   return XY2S;
else
-  Res := Big_Mul (To_Bignum (XY2S), X);
-  Free_Big_Integer (XY2S);
-  return Res;
+  return Res : constant Big_Integer :=
+Big_Mul (To_Bignum (XY2S), X)
+  do
+ Free_Big_Integer (XY2S);
+  end return;
end if;
 end;
   end case;
@@ -1108,6 +1095,8 @@ package body System.Generic_Bignums is
-- Normalize --
---
 
+   Bignum_Limit : constant := 200;
+
function Normalize
  (X   : Digit_Vector;
   Neg : Boolean := False) return Big_Integer
@@ -1120,6 +1109,10 @@ package body System.Generic_Bignums is
  J := J + 1;
   end loop;
 
+  if X'Last - J > Bignum_Limit then
+ raise Storage_Error with "big integer limit exceeded";
+  end if;
+
   return Allocate_Big_Integer (X (J .. X'Last), J <= X'Last and then Neg);
end Normalize;
 




[Ada] Spurious accessibility error on allocator in generic instance

2020-07-16 Thread Pierre-Marie de Rodat
This patch fixes an error in the compiler whereby an allocator for a
limited type may cause spurious accessibility errors due to a
miscalculation of access levels on internally generated temporaries
within the instance.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch4.adb (Expand_N_Type_Conversion): Remove flawed test for
whether "statically deeper" accessibility rules apply to a given
target type and instead use the new routine
Statically_Deeper_Relation_Applies.
(Statically_Deeper_Relation_Applies): Created to centralize the
calculation of whether a target type within a conversion must
have static accessibility checks.
* sem_ch13.adb (Check_One_Function): Minor comment revision.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -11305,6 +11305,11 @@ package body Exp_Ch4 is
   --  True iff Present (Effective_Extra_Accessibility (Id)) successfully
   --  evaluates to True.
 
+  function Statically_Deeper_Relation_Applies (Targ_Typ : Entity_Id)
+return Boolean;
+  --  Given a target type for a conversion, determine whether the
+  --  statically deeper accessibility rules apply to it.
+
   --
   -- Discrete_Range_Check --
   --
@@ -11887,6 +11892,25 @@ package body Exp_Ch4 is
  end if;
   end Has_Extra_Accessibility;
 
+  
+  -- Statically_Deeper_Relation_Applies --
+  
+
+  function Statically_Deeper_Relation_Applies (Targ_Typ : Entity_Id)
+return Boolean
+  is
+  begin
+ --  The case where the target type is an anonymous access type is
+ --  ignored since they have different semantics and get covered by
+ --  various runtime checks depending on context.
+
+ --  Note, the current implementation of this predicate is incomplete
+ --  and doesn't fully reflect the rules given in RM 3.10.2 (19) and
+ --  (19.1) ???
+
+ return Ekind (Targ_Typ) /= E_Anonymous_Access_Type;
+  end Statically_Deeper_Relation_Applies;
+
--  Start of processing for Expand_N_Type_Conversion
 
begin
@@ -12133,21 +12157,7 @@ package body Exp_Ch4 is
  --  Note: warnings are issued by the analyzer for the instance cases
 
  elsif In_Instance_Body
-
-   --  The case where the target type is an anonymous access type of
-   --  a discriminant is excluded, because the level of such a type
-   --  depends on the context and currently the level returned for such
-   --  types is zero, resulting in warnings about check failures
-   --  in certain legal cases involving class-wide interfaces as the
-   --  designated type (some cases, such as return statements, are
-   --  checked at run time, but not clear if these are handled right
-   --  in general, see 3.10.2(12/2-12.5/3) ???).
-
-   and then
- not (Ekind (Target_Type) = E_Anonymous_Access_Type
-   and then Present (Associated_Node_For_Itype (Target_Type))
-   and then Nkind (Associated_Node_For_Itype (Target_Type)) =
-  N_Discriminant_Specification)
+   and then Statically_Deeper_Relation_Applies (Target_Type)
and then
  Type_Access_Level (Operand_Type) > Type_Access_Level (Target_Type)
  then


diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -5488,7 +5488,7 @@ package body Sem_Ch13 is
end if;
 end if;
 
---  All checks succeeded.
+--  All checks succeeded
 
 Indexing_Found := True;
  end Check_One_Function;




[Ada] Spurious redundant use clause warning

2020-07-16 Thread Pierre-Marie de Rodat
The recent change in Exp_Ch3.Freeze_Type exposes a latent issue in
Sem_Ch8.Note_Redundant_Use when Load_RTU triggers at the wrong time,
causing spurious redundant use clause warnings.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch8.adb (Note_Redundant_Use): Add missing warning tag.
Do not check for redundant use clauses in predefined units to avoid
misleading warnings that may occur as part of a rtsfind load.diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -9461,9 +9461,14 @@ package body Sem_Ch8 is
 
  Set_Redundant_Use (Clause, True);
 
+ --  Do not check for redundant use if clause is generated, or in an
+ --  instance, or in a predefined unit to avoid misleading warnings
+ --  that may occur as part of a rtsfind load.
+
  if not Comes_From_Source (Clause)
or else In_Instance
or else not Warn_On_Redundant_Constructs
+   or else Is_Predefined_Unit (Current_Sem_Unit)
  then
 return;
  end if;
@@ -9596,10 +9601,12 @@ package body Sem_Ch8 is
  Private_Declarations (Parent (Decl))
 then
declare
-  Par : constant Entity_Id := Defining_Entity (Parent (Decl));
-  Spec : constant Node_Id  :=
-   Specification (Unit (Cunit (Current_Sem_Unit)));
+  Par  : constant Entity_Id :=
+Defining_Entity (Parent (Decl));
+  Spec : constant Node_Id  :=
+Specification (Unit (Cunit (Current_Sem_Unit)));
   Cur_List : constant List_Id := List_Containing (Cur_Use);
+
begin
   if Is_Compilation_Unit (Par)
 and then Par /= Cunit_Entity (Current_Sem_Unit)
@@ -9641,7 +9648,7 @@ package body Sem_Ch8 is
 
 Error_Msg_Sloc := Sloc (Prev_Use);
 Error_Msg_NE -- CODEFIX
-  ("& is already use-visible through previous use_clause #??",
+  ("& is already use-visible through previous use_clause #?r?",
Redundant, Pack_Name);
  end if;
   end Note_Redundant_Use;




[Ada] Handle N_Others_Choice case in range-building function

2020-07-16 Thread Pierre-Marie de Rodat
GNAT crashes when building static predicate functions out of a case
expression that contain an "others" clause. This is because it attempts
to call Is_OK_Static_Expression() on the N_Others_Choice of the case
expression when trying to figure out whether the case is exhaustive or
not.

Fixing requires two changes:

- Ensuring that choice values built out of `others` clauses have their
  Is_Static_Expression flag set.

- Checking if N is an N_Others_Choice in Membership_Entry and if it is
  returning the list of ranges that it corresponds to.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_case.adb (Build_Choice): Set Is_Static_Expression flag.
(Lit_Of): Update specification to mention Is_Static_Expression
flag.
* sem_ch13.adb (Membership_Entry): Check for N_Others_Choice.diff --git a/gcc/ada/sem_case.adb b/gcc/ada/sem_case.adb
--- a/gcc/ada/sem_case.adb
+++ b/gcc/ada/sem_case.adb
@@ -998,7 +998,8 @@ package body Sem_Case is
 
   function Lit_Of (Value : Uint) return Node_Id;
   --  Returns the Node_Id for the enumeration literal corresponding to the
-  --  position given by Value within the enumeration type Choice_Type.
+  --  position given by Value within the enumeration type Choice_Type. The
+  --  returned value has its Is_Static_Expression flag set to true.
 
   --
   -- Build_Choice --
@@ -1016,6 +1017,7 @@ package body Sem_Case is
 if Is_Integer_Type (Choice_Type) then
Lit_Node := Make_Integer_Literal (Loc, Value1);
Set_Etype (Lit_Node, Choice_Type);
+   Set_Is_Static_Expression (Lit_Node);
 else
Lit_Node := Lit_Of (Value1);
 end if;
@@ -1028,8 +1030,10 @@ package body Sem_Case is
 if Is_Integer_Type (Choice_Type) then
Lo := Make_Integer_Literal (Loc, Value1);
Set_Etype (Lo, Choice_Type);
+   Set_Is_Static_Expression (Lo);
Hi := Make_Integer_Literal (Loc, Value2);
Set_Etype (Hi, Choice_Type);
+   Set_Is_Static_Expression (Hi);
Lit_Node :=
  Make_Range (Loc,
Low_Bound  => Lo,


diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -9112,6 +9112,25 @@ package body Sem_Ch13 is
return RList'(1 => REnt'(SLo, SHi));
 end if;
 
+ --  Others case
+
+ elsif Nkind (N) = N_Others_Choice then
+declare
+   Choices: constant List_Id := Others_Discrete_Choices (N);
+   Choice : Node_Id;
+   Range_List : RList (1 .. List_Length (Choices));
+
+begin
+   Choice := First (Choices);
+
+   for J in Range_List'Range loop
+  Range_List (J) := REnt'(Lo_Val (Choice), Hi_Val (Choice));
+  Next (Choice);
+   end loop;
+
+   return Range_List;
+end;
+
  --  Static expression case
 
  elsif Is_OK_Static_Expression (N) then




[Ada] Disable Initialize_Scalars on runtime files

2020-07-16 Thread Pierre-Marie de Rodat
To avoid creating circular dependencies between runtime units and to
allow compiling e.g. GNAT with Initialize_Scalars.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* frontend.adb: Disable Initialize_Scalars on runtime files.diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -382,6 +382,16 @@ begin
  Warn_On_Non_Local_Exception := True;
   end if;
 
+  --  Disable Initialize_Scalars for runtime files to avoid circular
+  --  dependencies.
+
+  if Initialize_Scalars
+and then Fname.Is_Predefined_File_Name (File_Name (Main_Source_File))
+  then
+ Initialize_Scalars   := False;
+ Init_Or_Norm_Scalars := Normalize_Scalars;
+  end if;
+
   --  Now on to the semantics. Skip if in syntax only mode
 
   if Operating_Mode /= Check_Syntax then




[Ada] Ada2020: AI12-0107 convention of By_Protected_Procedure

2020-07-16 Thread Pierre-Marie de Rodat
A prefixed view of a subprogram with aspect Synchronization being
By_Protected_Procedure has convention protected.  This new feature is
documented in AI12-0107.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_attr.adb (Has_By_Protected_Procedure_Prefixed_View): New
subprogram.
(Expand_Access_To_Protected_Op): Adding support for prefixed
class-wide view with By_Protected_Procedure convention.
* sem_attr.adb (Get_Convention): New subprogram.
(Get_Kind): Adapted to use Get_Convention.
* sem_ch4.adb (Try_By_Protected_Procedure_Prefixed_View): New
subprogram.
(Analyze_Selected_Component): Invoke
Try_By_Protected_Procedure_Prefixed_View.
* sem_util.ads (Is_By_Protected_Procedure): New subprogram.
* sem_util.adb (Is_By_Protected_Procedure): New subprogram.diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -941,7 +941,30 @@ package body Exp_Attr is
is
   --  The value of the attribute_reference is a record containing two
   --  fields: an access to the protected object, and an access to the
-  --  subprogram itself. The prefix is a selected component.
+  --  subprogram itself. The prefix is an identifier or a selected
+  --  component.
+
+  function Has_By_Protected_Procedure_Prefixed_View return Boolean;
+  --  Determine whether Pref denotes the prefixed class-wide interface
+  --  view of a procedure with synchronization kind By_Protected_Procedure.
+
+  --
+  -- Has_By_Protected_Procedure_Prefixed_View --
+  --
+
+  function Has_By_Protected_Procedure_Prefixed_View return Boolean is
+  begin
+ return Nkind (Pref) = N_Selected_Component
+   and then Nkind (Prefix (Pref)) in N_Has_Entity
+   and then Present (Entity (Prefix (Pref)))
+   and then Is_Class_Wide_Type (Etype (Entity (Prefix (Pref
+   and then (Is_Synchronized_Interface (Etype (Entity (Prefix (Pref
+   or else
+ Is_Protected_Interface (Etype (Entity (Prefix (Pref)
+   and then Is_By_Protected_Procedure (Entity (Selector_Name (Pref)));
+  end Has_By_Protected_Procedure_Prefixed_View;
+
+  --  Local variables
 
   Loc : constant Source_Ptr := Sloc (N);
   Agg : Node_Id;
@@ -1015,6 +1038,23 @@ package body Exp_Attr is
 Attribute_Name => Name_Address);
  end if;
 
+  elsif Has_By_Protected_Procedure_Prefixed_View then
+ Obj_Ref :=
+   Make_Attribute_Reference (Loc,
+ Prefix => Relocate_Node (Prefix (Pref)),
+   Attribute_Name => Name_Address);
+
+ --  Analyze the object address with expansion disabled. Required
+ --  because its expansion would displace the pointer to the object,
+ --  which is not correct at this stage since the object type is a
+ --  class-wide interface type and we are dispatching a call to a
+ --  thunk (which would erroneously displace the pointer again).
+
+ Expander_Mode_Save_And_Set (False);
+ Analyze (Obj_Ref);
+ Set_Analyzed (Obj_Ref);
+ Expander_Mode_Restore;
+
   --  Case where the prefix is not an entity name. Find the
   --  version of the protected operation to be called from
   --  outside the protected object.
@@ -1031,26 +1071,64 @@ package body Exp_Attr is
Attribute_Name => Name_Address);
   end if;
 
-  Sub_Ref :=
-Make_Attribute_Reference (Loc,
-  Prefix => Sub,
-  Attribute_Name => Name_Access);
+  if Has_By_Protected_Procedure_Prefixed_View then
+ declare
+Ctrl_Tag  : Node_Id := Duplicate_Subexpr (Prefix (Pref));
+Prim_Addr : Node_Id;
+Subp  : constant Entity_Id := Entity (Selector_Name (Pref));
+Typ   : constant Entity_Id :=
+  Etype (Etype (Entity (Prefix (Pref;
+ begin
+--  The target subprogram is a thunk; retrieve its address from
+--  its secondary dispatch table slot.
+
+Build_Get_Prim_Op_Address (Loc,
+  Typ  => Typ,
+  Tag_Node => Ctrl_Tag,
+  Position => DT_Position (Subp),
+  New_Node => Prim_Addr);
+
+--  Mark the access to the target subprogram as an access to the
+--  dispatch table and perform an unchecked type conversion to such
+--  access type. This is required to allow the backend to properly
+--  identify and handle the access to the dispatch table slot on
+--  targets where the dispatch table contains descriptors (instead
+--  of pointers).
+
+Set_Is_Dispatch_Table_Entity (Acc);
+  

[Ada] AI12-0042: Type invariant checking rules

2020-07-16 Thread Pierre-Marie de Rodat
AI12-0042 specifies a couple of new rules for type invariants. The first
is that when a type extension inherits a nonabstract subprogram that is
a private operation of an ancestor type that has a class-wide invariant
and the parent subprogram is visible at that point, the subprogram must
be overridden. The second is the addition of a requirement to perform an
invariant check on a conversion from a specific tagged expression to a
class-wide type T'Class whose root type imposes a type invariant, when
the conversion occurs within the immediate scope of T (checking the
invariant on the part of the conversion expression that is of type T).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch4.adb (Expand_N_Type_Conversion): Handle the case of
applying an invariant check for a conversion to a class-wide
type whose root type has a type invariant, when the conversion
appears within the immediate scope of the type and the
expression is of a specific tagged type.
* sem_ch3.adb (Is_Private_Primitive): New function to determine
whether a primitive subprogram is a private operation.
(Check_Abstract_Overriding): Enforce the restriction imposed by
AI12-0042 of requiring overriding of an inherited nonabstract
private operation when the ancestor has a class-wide type
invariant and the ancestor's private operation is visible.
(Derive_Subprogram): Set Requires_Overriding on a subprogram
inherited from a visible private operation of an ancestor to
which a Type_Invariant'Class expression applies.diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -11951,6 +11951,39 @@ package body Exp_Ch4 is
  Remove_Side_Effects (N);
  Insert_Action (N, Make_Invariant_Call (Duplicate_Subexpr (N)));
  goto Done;
+
+  --  AI12-0042: For a view conversion to a class-wide type occurring
+  --  within the immediate scope of T, from a specific type that is
+  --  a descendant of T (including T itself), an invariant check is
+  --  performed on the part of the object that is of type T. (We don't
+  --  need to explicitly check for the operand type being a descendant,
+  --  just that it's a specific type, because the conversion would be
+  --  illegal if it's specific and not a descendant -- downward conversion
+  --  is not allowed).
+
+  elsif Is_Class_Wide_Type (Target_Type)
+and then not Is_Class_Wide_Type (Etype (Expression (N)))
+and then Present (Invariant_Procedure (Root_Type (Target_Type)))
+and then Comes_From_Source (N)
+and then Within_Scope (Find_Enclosing_Scope (N), Scope (Target_Type))
+  then
+ Remove_Side_Effects (N);
+
+ --  Perform the invariant check on a conversion to the class-wide
+ --  type's root type.
+
+ declare
+Root_Conv : constant Node_Id :=
+  Make_Type_Conversion (Loc,
+Subtype_Mark =>
+  New_Occurrence_Of (Root_Type (Target_Type), Loc),
+Expression   => Duplicate_Subexpr (Expression (N)));
+ begin
+Set_Etype (Root_Conv, Root_Type (Target_Type));
+
+Insert_Action (N, Make_Invariant_Call (Root_Conv));
+goto Done;
+ end;
   end if;
 
   --  Here if we may need to expand conversion


diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -579,6 +579,12 @@ package body Sem_Ch3 is
--  Extensions_Visible with value False and has at least one controlling
--  parameter of mode OUT.
 
+   function Is_Private_Primitive (Prim : Entity_Id) return Boolean;
+   --  Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
+   --  When applied to a primitive subprogram Prim, returns True if Prim is
+   --  declared as a private operation within a package or generic package,
+   --  and returns False otherwise.
+
function Is_Valid_Constraint_Kind
  (T_Kind  : Type_Kind;
   Constraint_Kind : Node_Kind) return Boolean;
@@ -10754,6 +10760,32 @@ package body Sem_Ch3 is
  elsif Present (Interface_Alias (Subp)) then
 null;
 
+ --  AI12-0042: Test for rule in 7.3.2(6.1/4), that requires overriding
+ --  of a visible private primitive inherited from an ancestor with
+ --  the aspect Type_Invariant'Class, unless the inherited primitive
+ --  is abstract. (The test for the extension occurring in a different
+ --  scope than the ancestor is to avoid requiring overriding when
+ --  extending in the same scope, because the inherited primitive will
+ --  also be private in that case, which looks like an unhelpful
+ --  restriction that may break reasonable code, though the rule
+ --  appears to apply in the same-scope case as well?

[Ada] Overflow in string streaming

2020-07-16 Thread Pierre-Marie de Rodat
The routine to output strings in an optimized manner has an overflow
error in case of very large strings.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* libgnat/s-ststop.ads: Fix typo.
* libgnat/s-ststop.adb (Read, Write): Fix block number
computation to avoid overflows in case of large strings.diff --git a/gcc/ada/libgnat/s-ststop.adb b/gcc/ada/libgnat/s-ststop.adb
--- a/gcc/ada/libgnat/s-ststop.adb
+++ b/gcc/ada/libgnat/s-ststop.adb
@@ -216,21 +216,25 @@ package body System.Strings.Stream_Ops is
 declare
--  Determine the size in BITS of the block necessary to contain
--  the whole string.
+   --  Since we are dealing with strings indexed by natural, there
+   --  is no risk of overflow when using a Long_Long_Integer.
 
-   Block_Size : constant Natural :=
-  Integer (Item'Last - Item'First + 1) * ET_Size;
+   Block_Size : constant Long_Long_Integer :=
+ Item'Length * Long_Long_Integer (ET_Size);
 
--  Item can be larger than what the default block can store,
-   --  determine the number of whole reads necessary to read the
+   --  determine the number of whole writes necessary to output the
--  string.
 
-   Blocks : constant Natural := Block_Size / Default_Block_Size;
+   Blocks : constant Natural :=
+ Natural (Block_Size / Long_Long_Integer (Default_Block_Size));
 
--  The size of Item may not be a multiple of the default block
-   --  size, determine the size of the remaining chunk in BITS.
+   --  size, determine the size of the remaining chunk.
 
Rem_Size : constant Natural :=
-Block_Size mod Default_Block_Size;
+ Natural
+   (Block_Size mod Long_Long_Integer (Default_Block_Size));
 
--  String indexes
 
@@ -337,20 +341,25 @@ package body System.Strings.Stream_Ops is
 declare
--  Determine the size in BITS of the block necessary to contain
--  the whole string.
+   --  Since we are dealing with strings indexed by natural, there
+   --  is no risk of overflow when using a Long_Long_Integer.
 
-   Block_Size : constant Natural := Item'Length * ET_Size;
+   Block_Size : constant Long_Long_Integer :=
+ Item'Length * Long_Long_Integer (ET_Size);
 
--  Item can be larger than what the default block can store,
--  determine the number of whole writes necessary to output the
--  string.
 
-   Blocks : constant Natural := Block_Size / Default_Block_Size;
+   Blocks : constant Natural :=
+ Natural (Block_Size / Long_Long_Integer (Default_Block_Size));
 
--  The size of Item may not be a multiple of the default block
--  size, determine the size of the remaining chunk.
 
Rem_Size : constant Natural :=
-Block_Size mod Default_Block_Size;
+ Natural
+   (Block_Size mod Long_Long_Integer (Default_Block_Size));
 
--  String indexes
 


diff --git a/gcc/ada/libgnat/s-ststop.ads b/gcc/ada/libgnat/s-ststop.ads
--- a/gcc/ada/libgnat/s-ststop.ads
+++ b/gcc/ada/libgnat/s-ststop.ads
@@ -53,7 +53,7 @@
 --   or
 -- String_Output_Blk_IO (Some_Stream, Some_String);
 
---  String_Output form is used if pragma Restrictions (No_String_Optimziations)
+--  String_Output form is used if pragma Restrictions (No_String_Optimizations)
 --  is active, which requires element by element operations. The BLK_IO form
 --  is used if this restriction is not set, allowing block optimization.
 




[Ada] gnatbind: Fix No_Entry_Calls_In_Elaboration_Code message

2020-07-16 Thread Pierre-Marie de Rodat
This patch fixes a bug where gnatbind would suggest adding the
No_Entry_Calls_In_Elaboration_Code restriction, when that restriction is
already present.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* bindo-diagnostics.adb (Output_Invocation_Related_Suggestions):
Use Cumulative_Restrictions.Set, because Restriction_Active only
works at compile time.diff --git a/gcc/ada/bindo-diagnostics.adb b/gcc/ada/bindo-diagnostics.adb
--- a/gcc/ada/bindo-diagnostics.adb
+++ b/gcc/ada/bindo-diagnostics.adb
@@ -25,7 +25,6 @@
 
 with Binderr;  use Binderr;
 with Debug;use Debug;
-with Restrict; use Restrict;
 with Rident;   use Rident;
 with Types;use Types;
 
@@ -1144,7 +1143,7 @@ package body Bindo.Diagnostics is
   --  within the task body on a select or accept statement, eliminating
   --  subsequent invocation edges, thus breaking the cycle.
 
-  if not Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
+  if not Cumulative_Restrictions.Set (No_Entry_Calls_In_Elaboration_Code)
 and then Contains_Task_Activation (G, Cycle)
   then
  Error_Msg_Info




[Ada] Implicit dereferencing in container indexing

2020-07-16 Thread Pierre-Marie de Rodat
The compiler was disallowing an access to a container to be used as the
prefix of an indexing of the container, but implicit dereferencing is
allowed in such a context (basically because a prefix can be an
implicit_dereference, by RM 4.1(4); a Ramification note was added in RM
4.1.6(11.a/5), to clarify that this works).

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch4.adb (Try_Container_Indexing): When the prefix type is
an access type, change it to the designated type, change the
prefix to an explicit dereference, and emit a ?d? warning for
the implicit dereference. Include a ??? comment questioning
whether this is the right context in which to perform the
implicit dereferencing.diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -7979,7 +7979,7 @@ package body Sem_Ch4 is
   Prefix : Node_Id;
   Exprs  : List_Id) return Boolean
is
-  Pref_Typ : constant Entity_Id := Etype (Prefix);
+  Pref_Typ : Entity_Id := Etype (Prefix);
 
   function Constant_Indexing_OK return Boolean;
   --  Constant_Indexing is legal if there is no Variable_Indexing defined
@@ -8415,6 +8415,25 @@ package body Sem_Ch4 is
  return True;
   end if;
 
+  --  An explicit dereference needs to be created in the case of a prefix
+  --  that's an access.
+
+  --  It seems that this should be done elsewhere, but not clear where that
+  --  should happen. Normally Insert_Explicit_Dereference is called via
+  --  Resolve_Implicit_Dereference, called from Resolve_Indexed_Component,
+  --  but that won't be called in this case because we transform the
+  --  indexing to a call. Resolve_Call.Check_Prefixed_Call takes care of
+  --  implicit dereferencing and referencing on prefixed calls, but that
+  --  would be too late, even if we expanded to a prefix call, because
+  --  Process_Indexed_Component will flag an error before the resolution
+  --  happens. ???
+
+  if Is_Access_Type (Pref_Typ) then
+ Pref_Typ := Implicitly_Designated_Type (Pref_Typ);
+ Insert_Explicit_Dereference (Prefix);
+ Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
+  end if;
+
   C_Type := Pref_Typ;
 
   --  If indexing a class-wide container, obtain indexing primitive from




[Ada] Misplace of internal master renaming declaration

2020-07-16 Thread Pierre-Marie de Rodat
This patch fixes a regression introduced by the recent work done for
tagged type constructors with task components.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch3.adb (Expand_N_Full_Type_Declaration): Ensure a _master
declaration on limited types that might have tasks.
* exp_ch9.adb (Build_Master_Renaming): For private types, if we
are processing declarations in the private part, ensure that
master is inserted before its full declaration; otherwise the
master renaming may be inserted in the public part of the
package (and hence before the declaration of its _master
variable).diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -5898,7 +5898,10 @@ package body Exp_Ch3 is
Typ := Etype (Comp);
 
if Ekind (Typ) = E_Anonymous_Access_Type
- and then Has_Task (Available_View (Designated_Type (Typ)))
+ and then
+   (Has_Task (Available_View (Designated_Type (Typ)))
+  or else
+Might_Have_Tasks (Available_View (Designated_Type (Typ
  and then No (Master_Id (Typ))
then
   --  Ensure that the record or array type have a _master


diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -3576,8 +3576,40 @@ package body Exp_Ch9 is
 
   if Present (Ins_Nod) then
  Context := Ins_Nod;
+
   elsif Is_Itype (Ptr_Typ) then
  Context := Associated_Node_For_Itype (Ptr_Typ);
+
+ --  When the context references a discriminant or a component of a
+ --  private type and we are processing declarations in the private
+ --  part of the enclosing package, we must insert the master renaming
+ --  before the full declaration of the private type; otherwise the
+ --  master renaming would be inserted in the public part of the
+ --  package (and hence before the declaration of _master).
+
+ if In_Private_Part (Current_Scope) then
+declare
+   Ctx : Node_Id := Context;
+
+begin
+   if Nkind (Context) = N_Discriminant_Specification then
+  Ctx := Parent (Ctx);
+   else
+  while Nkind_In (Ctx, N_Component_Declaration,
+   N_Component_List)
+  loop
+ Ctx := Parent (Ctx);
+  end loop;
+   end if;
+
+   if Nkind_In (Ctx, N_Private_Type_Declaration,
+ N_Private_Extension_Declaration)
+   then
+  Context := Parent (Full_View (Defining_Identifier (Ctx)));
+   end if;
+end;
+ end if;
+
   else
  Context := Parent (Ptr_Typ);
   end if;




[Ada] AI12-0004 Normalization and allowed characters

2020-07-16 Thread Pierre-Marie de Rodat
This Ada AI clarifies that Ada identifiers that contain characters that
are not allowed in Normalization Form KC are illegal.

It also introduces a new function Is_NFKC.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* scng.adb (Scan): Detect wide characters not in NFKC.
* libgnat/a-chahan.adb, libgnat/a-chahan.ads,
libgnat/a-wichha.adb, libgnat/a-wichha.ads,
libgnat/a-wichun.adb, libgnat/a-wichun.ads,
libgnat/a-zchhan.adb, libgnat/a-zchhan.ads,
libgnat/a-zchuni.adb, libgnat/a-zchuni.ads (Is_NFKC): New.
* libgnat/s-utf_32.ads, libgnat/s-utf_32.adb (Is_UTF_32_NFKC):
New.

patch.diff.gz
Description: application/gzip


[Ada] Ongoing work for AI12-0212 : container aggregates

2020-07-16 Thread Pierre-Marie de Rodat
This patch adds support for indexed aggregates with both positional
components and component associations that include multiple choices and
range specifications. For indexed aggregates the expansion uses a
separate pass, as suggested in AI12-0212, to compute the size of the
resulting object and preallocate that size before expanding the
aggregate into individual indexed assignments.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_aggr.adb (Resolve_Container_Aggregate): Add semantic
checks for indexed aggregates, including component associations
and iterated component associations.
* exp_aggr.adb (Expand_Iterated_Component): New subprogram,
subsidiary of Expand_Container_Aggreggate, used for positional,
named, and indexed aggregates.
(Aggregate_Size): New subprogram to precompute the size of an
indexed aggregate prior to call to allocate it.
(Expand_Range_Component): New subprogram so generate loop for a
component association given by a range or a subtype name in an
indexed aggregate.diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -6878,8 +6878,6 @@ package body Exp_Aggr is
   New_Indexed_Subp: Node_Id := Empty;
   Assign_Indexed_Subp : Node_Id := Empty;
 
-  procedure Expand_Iterated_Component (Comp : Node_Id);
-
   Aggr_Code : constant List_Id   := New_List;
   Temp  : constant Entity_Id := Make_Temporary (Loc, 'C', N);
 
@@ -6887,6 +6885,12 @@ package body Exp_Aggr is
   Decl  : Node_Id;
   Init_Stat : Node_Id;
 
+  procedure Expand_Iterated_Component (Comp : Node_Id);
+  --  Handle iterated_component_association and iterated_Element
+  --  association by generating a loop over the specified range,
+  --  given either by a loop parameter specification or an iterator
+  --  specification.
+
   ---
   -- Expand_Iterated_Component --
   ---
@@ -6946,6 +6950,7 @@ package body Exp_Aggr is
   Iteration_Scheme => L_Iteration_Scheme,
   Statements   => Stats);
  Append (Loop_Stat, Aggr_Code);
+
   end Expand_Iterated_Component;
 
begin
@@ -6968,11 +6973,16 @@ package body Exp_Aggr is
Name => New_Occurrence_Of (Temp, Loc),
Expression => New_Occurrence_Of (Entity (Empty_Subp), Loc));
   end if;
+
   Append (Init_Stat, Aggr_Code);
 
-  --  First case: positional aggregate
+  ---
+  --  Positional aggregate --
+  ---
 
-  if Present (Add_Unnamed_Subp) then
+  if Present (Add_Unnamed_Subp)
+and then No (Assign_Indexed_Subp)
+  then
  if Present (Expressions (N)) then
 declare
Insert : constant Entity_Id := Entity (Add_Unnamed_Subp);
@@ -6993,7 +7003,7 @@ package body Exp_Aggr is
 end;
  end if;
 
- --  iterated component associations may be present.
+ --  Iterated component associations may also be present.
 
  Comp := First (Component_Associations (N));
  while Present (Comp) loop
@@ -7001,6 +7011,10 @@ package body Exp_Aggr is
 Next (Comp);
  end loop;
 
+  -
+  -- Named_Aggregate --
+  -
+
   elsif Present (Add_Named_Subp) then
  declare
 Insert : constant Entity_Id := Entity (Add_Named_Subp);
@@ -7034,6 +7048,235 @@ package body Exp_Aggr is
Next (Comp);
 end loop;
  end;
+
+  ---
+  -- Indexed_Aggregate --
+  ---
+
+  elsif Present (Assign_Indexed_Subp) then
+ declare
+Insert : constant Entity_Id := Entity (Assign_Indexed_Subp);
+Index_Type : constant Entity_Id :=
+   Etype (Next_Formal (First_Formal (Insert)));
+
+function Aggregate_Size return Int;
+--  Compute number of entries in aggregate, including choices
+--  that cover a range, as well as iterated constructs.
+
+function  Expand_Range_Component
+  (Rng  : Node_Id;
+   Expr : Node_Id) return Node_Id;
+--  Transform a component assoication with a range into an
+--  explicit loop. If the choice is a subtype name, it is
+--  rewritten as a range with the corresponding bounds, which
+--  are known to be static.
+
+Comp   : Node_Id;
+Index  : Node_Id;
+Pos: Int := 0;
+Stat   : Node_Id;
+Key: Node_Id;
+Size   : Int := 0;
+
+-
+-- Expand_Raange_Component --
+-
+
+function E

[Ada] Spurious error in instance nested in formal package

2020-07-16 Thread Pierre-Marie de Rodat
This patch removes a spurious error in a compilation of a generic body
GB that includes a formal package whose source GF includes a nested
generic package NGF, and GB includes instances of NGF and of further
generic units declared within NGF.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch12.adb (Load_Parent_Of_Generic): If an ancestor is an
instance whose source appears within a formal package of the
current unit, there is no body of the ancestor needed to
complete the current generic compilation.diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -14292,6 +14292,21 @@ package body Sem_Ch12 is
 
exit;
 
+--  If an ancestor of the generic comes from a formal package
+--  there is no source for the ancestor body. This is detected
+--  by examining the scope of the ancestor and its declaration.
+--  The body, if any is needed, will be available when the
+--  current unit (containing a formal package) is instantiated.
+
+elsif Nkind (True_Parent) = N_Package_Specification
+  and then Present (Generic_Parent (True_Parent))
+  and then Nkind
+(Original_Node (Unit_Declaration_Node
+  (Scope (Generic_Parent (True_Parent)
+ = N_Formal_Package_Declaration
+then
+   return;
+
 else
True_Parent := Parent (True_Parent);
 end if;




[Ada] AI12-0132 Freezing of renames_as_body

2020-07-16 Thread Pierre-Marie de Rodat
This AI clarifies that a renames-as-body freezes the expression of any
expression function that it renames.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* sem_ch8.adb (Analyze_Subprogram_Renaming): A renames-as-body
freezes the expression of any expression function that it
renames.diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -3160,6 +3160,22 @@ package body Sem_Ch8 is
 Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec);
  end if;
 
+ --  AI12-0132: a renames-as-body freezes the expression of any
+ --  expression function that it renames.
+
+ if Is_Entity_Name (Nam)
+   and then Is_Expression_Function (Entity (Nam))
+   and then not Inside_A_Generic
+ then
+Freeze_Expr_Types
+  (Def_Id => Entity (Nam),
+   Typ=> Etype (Entity (Nam)),
+   Expr   =>
+ Expression
+   (Original_Node (Unit_Declaration_Node (Entity (Nam,
+   N  => N);
+ end if;
+
   --  Normal subprogram renaming (not renaming as body)
 
   else




[Ada] Set missing Parent field of block entity

2020-07-16 Thread Pierre-Marie de Rodat
This sets the Parent field of the block entity created in the case of
a statement sequence by Expand_N_Accept_Statement to the newly created
block statment, as done for example in Add_Block_Identifier.  This is
needed in peculiar cases where the block contains instantiations of
packages with generic child units.

No functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_ch9.adb (Expand_N_Accept_Statement): Set Parent of the
created block entity to the created block statement.diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -6660,6 +6660,7 @@ package body Exp_Ch9 is
  --  must be properly set.
 
  Set_Parent (Block, Parent (N));
+ Set_Parent (Blkent, Block);
 
  --  Prepend call to Accept_Call to main statement sequence If the
  --  accept has exception handlers, the statement sequence is wrapped




[Ada] Ada2020: AI12-0117 Restriction No_Tasks_Unassigned_To_CPU

2020-07-16 Thread Pierre-Marie de Rodat
Implement the No_Tasks_Unassigned_To_CPU restriction.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* gnatbind.adb (Gnatbind): For No_Tasks_Unassigned_To_CPU, check
that CPU has been set on the main subprogram.
(Restriction_Could_Be_Set): Don't print
No_Tasks_Unassigned_To_CPU if it would violate the
above-mentioned rule. Up to now, all restrictions were checked
by the compiler, with the binder just checking for consistency.
But the compiler can't know which subprogram is the main, so
it's impossible to check this one at compile time.
* restrict.ads, restrict.adb: Misc refactoring. Change Warning
to Warn, for consistency, since most already use Warn.
(Set_Restriction): New convenience routine.
* sem_ch13.adb (Attribute_CPU): Check
No_Tasks_Unassigned_To_CPU.
* sem_prag.adb (Pragma_CPU): Check No_Tasks_Unassigned_To_CPU.
Misc refactoring.
* tbuild.ads, tbuild.adb (Sel_Comp): New functions for building
selected components.diff --git a/gcc/ada/gnatbind.adb b/gcc/ada/gnatbind.adb
--- a/gcc/ada/gnatbind.adb
+++ b/gcc/ada/gnatbind.adb
@@ -238,8 +238,8 @@ procedure Gnatbind is
   --
 
   function Restriction_Could_Be_Set (R : Restriction_Id) return Boolean is
- CR : Restrictions_Info renames Cumulative_Restrictions;
-
+ CR : Restrictions_Info renames Cumulative_Restrictions;
+ Result : Boolean;
   begin
  case R is
 
@@ -247,11 +247,19 @@ procedure Gnatbind is
 
 when All_Boolean_Restrictions =>
 
-   --  The condition for listing a boolean restriction as an
-   --  additional restriction that could be set is that it is
-   --  not violated by any unit, and not already set.
+   --  Print it if not violated by any unit, and not already set...
+
+   Result := not CR.Violated (R) and then not CR.Set (R);
+
+   --  ...except that for No_Tasks_Unassigned_To_CPU, we don't want
+   --  to print it if it would violate the restriction post
+   --  compilation.
 
-   return CR.Violated (R) = False and then CR.Set (R) = False;
+   if R = No_Tasks_Unassigned_To_CPU
+ and then ALIs.Table (ALIs.First).Main_CPU = No_Main_CPU
+   then
+  Result := False;
+   end if;
 
 --  Parameter restriction
 
@@ -261,18 +269,18 @@ procedure Gnatbind is
--  unknown, the restriction can definitely not be listed.
 
if CR.Violated (R) and then CR.Unknown (R) then
-  return False;
+  Result := False;
 
--  We can list the restriction if it is not set
 
elsif not CR.Set (R) then
-  return True;
+  Result := True;
 
--  We can list the restriction if is set to a greater value
--  than the maximum value known for the violation.
 
else
-  return CR.Value (R) > CR.Count (R);
+  Result := CR.Value (R) > CR.Count (R);
end if;
 
 --  No other values for R possible
@@ -280,6 +288,8 @@ procedure Gnatbind is
 when others =>
raise Program_Error;
  end case;
+
+ return Result;
   end Restriction_Could_Be_Set;
 
--  Start of processing for List_Applicable_Restrictions
@@ -881,6 +891,17 @@ begin
   --  mode where we want to be more flexible.
 
   if not CodePeer_Mode then
+ --  AI12-0117-1, "Restriction No_Tasks_Unassigned_To_CPU":
+ --  If the restriction No_Tasks_Unassigned_To_CPU applies, then
+ --  check that the main subprogram has a CPU assigned.
+
+ if Cumulative_Restrictions.Set (No_Tasks_Unassigned_To_CPU)
+   and then ALIs.Table (ALIs.First).Main_CPU = No_Main_CPU
+ then
+Error_Msg ("No_Tasks_Unassigned_To_CPU restriction requires CPU" &
+ " aspect to be specified for main procedure");
+ end if;
+
  Check_Duplicated_Subunits;
  Check_Versions;
  Check_Consistency;


diff --git a/gcc/ada/restrict.adb b/gcc/ada/restrict.adb
--- a/gcc/ada/restrict.adb
+++ b/gcc/ada/restrict.adb
@@ -1354,8 +1354,6 @@ package body Restrict is
-- Set_Restriction --
-
 
-   --  Case of Boolean restriction
-
procedure Set_Restriction
  (R : All_Boolean_Restrictions;
   N : Node_Id)
@@ -1395,8 +1393,6 @@ package body Restrict is
   end if;
end Set_Restriction;
 
-   --  Case of parameter restriction
-
procedure Set_Restriction
  (R : All_Parameter_Restrictions;
   N : Node_Id;
@@ -1446,6 +1442,29 @@ package body Restrict is
   Restriction_Profile_Name (R) := No_Profile;
end Set_Restrict

[Ada] Adjust heuristics about size of static aggregates

2020-07-16 Thread Pierre-Marie de Rodat
This patch adjusts the heuristics about the size of static aggregates,
which determine whether an aggregate should be statically allocated.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* exp_aggr.adb (Max_Aggregate_Size): Use the small size of 64
when copying is needed (for example, for the initialization of a
local variable, and for assignment statements). Use the larger
size when static allocation can be done without copying.diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -252,7 +252,7 @@ package body Exp_Aggr is
function Aggr_Assignment_OK_For_Backend (N : Node_Id) return Boolean;
--  Returns true if an aggregate assignment can be done by the back end
 
-   function Aggr_Size_OK (N : Node_Id; Typ : Entity_Id) return Boolean;
+   function Aggr_Size_OK (N : Node_Id) return Boolean;
--  Very large static aggregates present problems to the back-end, and are
--  transformed into assignments and loops. This function verifies that the
--  total number of components of an aggregate is acceptable for rewriting
@@ -328,10 +328,10 @@ package body Exp_Aggr is
--  is a two dimensional bit packed array with component size 1, 2, or 4.
 
function Max_Aggregate_Size
- (Typ  : Entity_Id;
+ (N: Node_Id;
   Default_Size : Nat := 5000) return Nat;
-   --  Return the max size for a static aggregate of the given Typ.
-   --  Return Default_Size if no other special criteria trigger.
+   --  Return the max size for a static aggregate N. Return Default_Size if no
+   --  other special criteria trigger.
 
function Packed_Array_Aggregate_Handled (N : Node_Id) return Boolean;
--  Given an array aggregate, this function handles the case of a packed
@@ -593,7 +593,8 @@ package body Exp_Aggr is
-- Aggr_Size_OK --
--
 
-   function Aggr_Size_OK (N : Node_Id; Typ : Entity_Id) return Boolean is
+   function Aggr_Size_OK (N : Node_Id) return Boolean is
+  Typ  : constant Entity_Id := Etype (N);
   Lo   : Node_Id;
   Hi   : Node_Id;
   Indx : Node_Id;
@@ -688,9 +689,9 @@ package body Exp_Aggr is
   if No (Expressions (N))
 and then No (Next (First (Component_Associations (N
   then
- Max_Aggr_Size := Max_Aggregate_Size (Typ);
+ Max_Aggr_Size := Max_Aggregate_Size (N);
   else
- Max_Aggr_Size := Max_Aggregate_Size (Typ, 500_000);
+ Max_Aggr_Size := Max_Aggregate_Size (N, 500_000);
   end if;
 
   Size := UI_From_Int (Component_Count (Component_Type (Typ)));
@@ -4955,7 +4956,7 @@ package body Exp_Aggr is
is
   Typ  : constant Entity_Id := Etype (N);
   Dims : constant Nat := Number_Dimensions (Typ);
-  Max_Others_Replicate : constant Nat := Max_Aggregate_Size (Typ);
+  Max_Others_Replicate : constant Nat := Max_Aggregate_Size (N);
 
   Static_Components : Boolean := True;
 
@@ -5475,7 +5476,7 @@ package body Exp_Aggr is
   --  compatible with the upper bound of the type, and therefore it is
   --  worth flattening such aggregates as well.
 
-  if Aggr_Size_OK (N, Typ)
+  if Aggr_Size_OK (N)
 and then
   Flatten (N, Dims, First_Index (Typ), First_Index (Base_Type (Typ)))
   then
@@ -8315,8 +8316,69 @@ package body Exp_Aggr is

 
function Max_Aggregate_Size
- (Typ  : Entity_Id;
-  Default_Size : Nat := 5000) return Nat is
+ (N: Node_Id;
+  Default_Size : Nat := 5000) return Nat
+   is
+  Typ : constant Entity_Id := Etype (N);
+
+  function Use_Small_Size (N : Node_Id) return Boolean;
+  --  True if we should return a very small size, which means large
+  --  aggregates will be implemented as a loop when possible (potentially
+  --  transformed to memset calls).
+
+  function Aggr_Context (N : Node_Id) return Node_Id;
+  --  Return the context in which the aggregate appears, not counting
+  --  qualified expressions and similar.
+
+  function Aggr_Context (N : Node_Id) return Node_Id is
+ Result : Node_Id := Parent (N);
+  begin
+ if Nkind_In (Result, N_Qualified_Expression,
+  N_Type_Conversion,
+  N_Unchecked_Type_Conversion,
+  N_If_Expression,
+  N_Case_Expression,
+  N_Component_Association,
+  N_Aggregate)
+ then
+Result := Aggr_Context (Result);
+ end if;
+
+ return Result;
+  end Aggr_Context;
+
+  function Use_Small_Size (N : Node_Id) return Boolean is
+ C : constant Node_Id := Aggr_Context (N);
+ --  The decision depends on the context in which the aggregate occurs,
+ --  and for variable declarations, whether

[Ada] Wrong execution of Tan on large argument

2020-07-16 Thread Pierre-Marie de Rodat
The custom implementation of Tan in a-numaux__x86.adb has some holes for
large values and will e.g. produce the wrong result on Tan (16367173.0 *
2.0**72).

This is fixed by replacing the use of a-numaux__x86 by
a-numaux__libc-x86.ads.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

* Makefile.rtl: replace a-numaux__x86.ads by
a-numaux__libc-x86.ads and a-numaux__x86.adb by
a-numaux__dummy.adb.
* libgnat/a-numaux__x86.ads, libgnat/a-numaux__x86.adb: Removed.
* libgnat/a-numaux__dummy.adb: New.diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl
--- a/gcc/ada/Makefile.rtl
+++ b/gcc/ada/Makefile.rtl
@@ -834,13 +834,13 @@ ATOMICS_BUILTINS_TARGET_PAIRS = \
 # Special version of units for x86 and x86-64 platforms.
 
 X86_TARGET_PAIRS = \
-  a-numaux.adshttp://www.gnu.org/licenses/>.  --
+--  --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.  --
+--  --
+--
+
+pragma No_Body;


diff --git a/gcc/ada/libgnat/a-numaux__x86.adb /dev/null
deleted file mode 100644
--- a/gcc/ada/libgnat/a-numaux__x86.adb
+++ /dev/null
@@ -1,577 +0,0 @@
---
---  --
--- GNAT RUN-TIME COMPONENTS --
---  --
--- A D A . N U M E R I C S . A U X  --
---  --
--- B o d y  --
---(Machine Version for x86) --
---  --
---  Copyright (C) 1998-2020, Free Software Foundation, Inc. --
---  --
--- GNAT is free software;  you can  redistribute it  and/or modify it under --
--- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 3,  or (at your option) any later ver- --
--- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
--- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE. --
---  --
--- As a special exception under Section 7 of GPL version 3, you are granted --
--- additional permissions described in the GCC Runtime Library Exception,   --
--- version 3.1, as published by the Free Software Foundation.   --
---  --
--- You should have received a copy of the GNU General Public License and--
--- a copy of the GCC Runtime Library Exception along with this program; --
--- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see--
--- .  --
---  --
--- GNAT was originally developed  by the GNAT team at  New York University. --
--- Extensive contributions were provided by Ada Core Technologies Inc.  --
---  --
---
-
-with System.Machine_Code; use System.Machine_Code;
-
-package body Ada.Numerics.Aux is
-
-   NL : constant String := ASCII.LF & ASCII.HT;
-
-   ---
-   -- Local subprograms --
-   ---
-
-   function Is_Nan (X : Double) return Boolean;
-   --  Return True iff X is a IEEE NaN value
-
-   function Logarithmic_Pow (X, Y : Double) return Double;
-   --  Implementation of X**Y using Exp and Log functions (binary base)
-   --  to calculate the exponentiation. This is used by Pow for values
-   --  for values of Y in the open interval (-0.25, 0.25)
-
-   procedure Reduce (X : in out Double; Q : out Natural);
-   --  Implement reduction of X by Pi/2. Q is the quadrant of the final
-   --  result in the range 0..3. The absolute value of X is at most Pi/4.
-   --  It is needed to avoid a loss of accuracy for sin near Pi and cos
-   --  near Pi/2 due to the use of an insufficiently precise value of Pi
-   --  in the range reduction.
-
-   pragma Inline (Is_Nan);
-   pragma Inline (Reduce);
-
-   ---

Re: [PATCH] libsanitizer: Fix GetPcSpBp determination of SP on 32-bit Solaris/x86

2020-07-16 Thread Jakub Jelinek via Gcc-patches
On Thu, Jul 16, 2020 at 10:44:21AM +0200, Rainer Orth wrote:
> Hi Jakub,
> 
> >> I may still be mistaken, but all this suggests that Linux might be
> >> playing games with ESP and UESP, while Solaris and NetBSD (see below)
> >> keep them separate, but in the end UESP is the register to use.
> >
> > I think what matters more is
> > kernel/signal.c and ia32/ia32_signal.c doing:
> > put_user_ex(regs->sp, &sc->sp);
> > ...
> > put_user_ex(regs->sp, &sc->sp_at_signal);
> > i.e. both ESP and UESP ought to have the same value in the end on Linux.
> >
> > Your patch is ok for trunk and for 10.3 after a few weeks (10.2 is frozen
> > ATM anyway) so that if there are some problems (like say some headers not
> > defining REG_UESP or something similar), we'll find that out on trunk first.
> 
> fair enough.  What about the gcc-9 branch by then?  I expect there will
> be at least one more release from that one, too?

Ok, but please do it in order (i.e. trunk, then 10+9+8 (if you want 8 too)).

Jakub



Re: [PATCH] libsanitizer: Fix GetPcSpBp determination of SP on 32-bit Solaris/x86

2020-07-16 Thread Rainer Orth
Hi Jakub,

>> fair enough.  What about the gcc-9 branch by then?  I expect there will
>> be at least one more release from that one, too?
>
> Ok, but please do it in order (i.e. trunk, then 10+9+8 (if you want 8 too)).

that's been the plan: I want to avoid older releases to have fixes
missing in newer ones.

I don't intend to do 8, though: trunk + two branches is all I can
handle.

Thanks.
Rainer

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


Re: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts

2020-07-16 Thread Thomas Schwinge
Hi Julian!

Ping.

On 2020-06-26T11:20:40+0200, I wrote:
> On 2019-12-17T22:03:47-0800, Julian Brown  wrote:
>> This part contains the libgomp runtime support for the GOMP_MAP_ATTACH and
>> GOMP_MAP_DETACH mapping kinds (etc.), as introduced by the front-end
>> patches following in this series.
>
>> --- a/libgomp/target.c
>> +++ b/libgomp/target.c
>
>> @@ -1534,6 +1571,18 @@ gomp_unmap_vars_internal (struct target_mem_desc 
>> *tgt, bool do_copyfrom,
>
> This is the code path at the end of a structured OpenACC 'data'
> construct.
>
>> +  /* We must perform detachments before any copies back to the host.  */
>> +  for (i = 0; i < tgt->list_count; i++)
>> +{
>> +  splay_tree_key k = tgt->list[i].key;
>> +
>> +  if (k != NULL && tgt->list[i].do_detach)
>> +gomp_detach_pointer (devicep, aq, k, tgt->list[i].key->host_start
>> + + tgt->list[i].offset,
>> + k->refcount == 1, NULL);
>> +}
>
> Can you please explain (as a source code comment) the logic for here
> using 'k->refcount == 1' for the 'bool finalize' parameter of
> 'gomp_detach_pointer'; this somehow feels "strange"?
>
> Nonwithstanding the question whether that's a valid thing to do or not,
> but doesn't the current code hide the "attach count underflow" error if
> you reach the above code with 'attach_count == 0' (user already
> explicitly 'detach'ed), but then given 'k->refcount == 1' (thus
> 'finalize' semantics), 'gomp_detach_pointer' will then re-initialize
> 'attach_count = 1', and then do another 'gomp_copy_host2dev', etc.
> instead of emitting an error.
>
> (I have not attempted to produce a libgomp test case.)
>
> Shouldn't this just always be 'finalize = false' given that there is no
> 'finalize' semantics for 'detach' on a structured OpenACC 'data'
> constructs -- at least that's what I remember right now?


Grüße
 Thomas
-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter


[PATCH] Define TARGET_TRULY_NOOP_TRUNCATION to false.

2020-07-16 Thread Roger Sayle

Many thanks to Richard Biener for approving the midde-end
patch that cleared the way for this one.  This nvptx patch
defines the target hook TARGET_TRULY_NOOP_TRUNCATION to
false, indicating that integer truncations require explicit
instructions.  nvptx.c already defines TARGET_MODES_TIEABLE_P
and TARGET_CAN_CHANGE_MODE_CLASS to false, and as (previously)
documented that may require TARGET_TRULY_NOOP_TRUNCATION to
be defined likewise.

This patch decreases the number of unexpected failures in
the testsuite by 10, and increases the number of expected
passes by 4, including these previous FAILs/ICEs:
gcc.c-torture/compile/opout.c
gcc.dg/torture/pr79125.c
gcc.dg/tree-ssa/pr92085-1.c

Unfortunately there is one testsuite failure that used to
pass gcc.target/nvptx/v2si-cvt.c, but this isn't an ICE or
incorrect code.  As explained in this test, the scan-assembler
already isn't testing what it should.  Given that there are
several (nvptx) patches pending review that affect code
generation of this example, and (perhaps) more on the way,
I propose letting this test FAIL for now until the dust
settles and it becomes clear what instruction(s) should be
generated (certainly not a cvt.u32.u32).

This patch has been tested on nvptx-none hosted on
x86_64-pc-linux-gnu with "make" and "make check" with
fewer ICEs and no wrong code regressions.
Ok for mainline?


2020-07-16  Roger Sayle  

gcc/ChangeLog
* config/nvptx/nvptx.c (nvptx_truly_noop_truncation): Implement.
(TARGET_TRULY_NOOP_TRUNCATION): Define.


Thanks in advance.
--
Roger Sayle
NextMove Software
Cambridge, UK

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index e3e84df..f5b5d8c 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -6450,6 +6450,14 @@ nvptx_can_change_mode_class (machine_mode, machine_mode, 
reg_class_t)
   return false;
 }
 
+/* Implement TARGET_TRULY_NOOP_TRUNCATION.  */
+
+static bool
+nvptx_truly_noop_truncation (poly_uint64, poly_uint64)
+{
+  return false;
+}
+
 static GTY(()) tree nvptx_previous_fndecl;
 
 static void
@@ -6599,6 +6607,9 @@ nvptx_set_current_function (tree fndecl)
 #undef TARGET_CAN_CHANGE_MODE_CLASS
 #define TARGET_CAN_CHANGE_MODE_CLASS nvptx_can_change_mode_class
 
+#undef TARGET_TRULY_NOOP_TRUNCATION
+#define TARGET_TRULY_NOOP_TRUNCATION nvptx_truly_noop_truncation
+
 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
 


RE: [PATCH] target: fix default value checking of x_str_align_functions in aarch64.c

2020-07-16 Thread Hu, Jiangping
PING.

> -Original Message-
> From: Gcc-patches  On Behalf Of Hu
> Jiangping
> Sent: Tuesday, July 14, 2020 3:55 PM
> To: gcc-patches@gcc.gnu.org
> Subject: [PATCH] target: fix default value checking of x_str_align_functions 
> in
> aarch64.c
> 
> Hi,
> 
> This patch deal with the -falign-X=0 options. According to man pages,
> if zero is specified, a machine-dependent default value should be used.
> But in fact, zero was used in internal process, it is inconsistent.
> 
> Tested on aarch64-linux cross compiler, Is that OK?
> 
> BTW, the similar problems exists in other target sources.
> I can submit them all in another patch if needed,
> but I can test on i386 target only.
> 
> Regards!
> Hujp
> 
> ---
>  gcc/config/aarch64/aarch64.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
> index 17dbe673978..697ac676f4d 100644
> --- a/gcc/config/aarch64/aarch64.c
> +++ b/gcc/config/aarch64/aarch64.c
> @@ -14221,11 +14221,14 @@ aarch64_override_options_after_change_1
> (struct gcc_options *opts)
>   alignment to what the target wants.  */
>if (!opts->x_optimize_size)
>  {
> -  if (opts->x_flag_align_loops && !opts->x_str_align_loops)
> +  if ((opts->x_flag_align_loops && !opts->x_str_align_loops)
> +|| (opts->x_str_align_loops && strcmp(opts->x_str_align_loops, "0") 
> ==
> 0))
>   opts->x_str_align_loops = aarch64_tune_params.loop_align;
> -  if (opts->x_flag_align_jumps && !opts->x_str_align_jumps)
> +  if ((opts->x_flag_align_jumps && !opts->x_str_align_jumps)
> +|| (opts->x_str_align_jumps && strcmp(opts->x_str_align_jumps, "0")
> == 0))
>   opts->x_str_align_jumps = aarch64_tune_params.jump_align;
> -  if (opts->x_flag_align_functions && !opts->x_str_align_functions)
> +  if ((opts->x_flag_align_functions && !opts->x_str_align_functions)
> +|| (opts->x_str_align_functions && 
> strcmp(opts->x_str_align_functions,
> "0") == 0))
>   opts->x_str_align_functions = aarch64_tune_params.function_align;
>  }
> 
> --
> 2.17.1
> 
> 





RE: [PATCH] x86: Provide expanders for truncdisi2 and friends.

2020-07-16 Thread Roger Sayle

Hi Richard,

Many thanks.  As promised, here's a clean-up patch that removes the last direct
call to targetm.truly_noop_truncation from the middle-end, allowing this hook 
at some point in the future to take modes instead of sizes.

middle-end: Prefer TRULY_NOOP_TRUNCATION_MODES_P over raw target hook.

This patch has been tested with "make bootstrap" and "make -k check" on
x86_64-pc-linux-gnu with no regressions.

2020-07-16  Roger Sayle  

gcc/ChangeLog
* function.c (assign_parm_setup_block): Use the macro
TRULY_NOOP_TRUNCATION_MODES_P instead of calling
targetm.truly_noop_truncation directly.

Ok for mainline?

Thanks again,
Roger
--

-Original Message-
From: Richard Biener  
Sent: 14 July 2020 15:17
To: Roger Sayle 
Cc: GCC Patches 
Subject: Re: [PATCH] x86: Provide expanders for truncdisi2 and friends.

On Mon, Jul 13, 2020 at 4:50 PM Roger Sayle  wrote:
> > It seems to be improving TARGET_TRULY_NOOP_TRUNCATION documentation might 
> > be useful here.
> This is an excellent suggestion.  How about the following/attached...
>
> > The only user (after your patch) of this hook is in function.c for the 
> > function parameter setup btw.
>
> The targetm.truly_noop_truncation in assign_parm_setup_block is the 
> last place that calls this hook directly (with sizes), but the 
> majority of uses go via TRULY_NOOP_TRUNCATION_MODES_P as defined in 
> machmode.h.
>
> I'll prepare a patch to switch function.c to use 
> TRULY_NOOP_TRUNCATION_MODE_P so that we are consistent throughout the 
> compiler.  In theory, this hook could then be changed to take modes 
> instead of (poly_unit64) sizes, but that clean-up might be tricky without 
> access to the affected platforms.
>
> Is the above documentation change Ok for mainline?
OK.

Thanks,
Richard.

> Thanks,
> Roger
> --
>
diff --git a/gcc/function.c b/gcc/function.c
index 9eee9b5..cdfcc4b 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -3013,8 +3013,8 @@ assign_parm_setup_block (struct assign_parm_data_all *all,
 to the value directly in mode MODE, otherwise we must
 start with the register in word_mode and explicitly
 convert it.  */
- if (targetm.truly_noop_truncation (size * BITS_PER_UNIT,
-BITS_PER_WORD))
+ if (mode == word_mode
+ || TRULY_NOOP_TRUNCATION_MODES_P (mode, word_mode))
reg = gen_rtx_REG (mode, REGNO (entry_parm));
  else
{


Re: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3

2020-07-16 Thread Richard Sandiford
xiezhiheng  writes:
>> -Original Message-
>> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
>> Sent: Tuesday, July 7, 2020 10:08 PM
>> To: xiezhiheng 
>> Cc: Richard Biener ; gcc-patches@gcc.gnu.org
>> Subject: Re: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions
>> emitted at -O3
>> 
>> xiezhiheng  writes:
>> >> -Original Message-
>> >> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
>> >> Sent: Monday, July 6, 2020 5:31 PM
>> >> To: xiezhiheng 
>> >> Cc: Richard Biener ;
>> gcc-patches@gcc.gnu.org
>> >> Subject: Re: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions
>> >> emitted at -O3
>> >>
>> >> No, this is unfortunately a known bug.  See:
>> >>
>> >>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95964
>> >>
>> >> (Although the PR is recent, it's been a known bug for longer.)
>> >>
>> >> As you say, the difficulty is that the correct attributes depend on what
>> >> the built-in function does.  Most integer arithmetic is “const”, but
>> things
>> >> get more complicated for floating-point arithmetic.
>> >>
>> >> The SVE intrinsics use a three stage process:
>> >>
>> >> - each function is classified into one of several groups
>> >> - each group has a set of flags that describe what functions in the
>> >>   group can do
>> >> - these flags get converted into attributes based on the current
>> >>   command-line options
>> >>
>> >> I guess we should have something similar for the arm_neon.h built-ins.
>> >>
>> >> If you're willing to help fix this, that'd be great.  I think a first
>> >> step would be to agree a design.
>> >>
>> >> Thanks,
>> >> Richard
>> >
>> > I'd like to have a try.
>> 
>> Great!
>> 
>> > I have checked the steps in SVE intrinsics.
>> > It defines a base class "function_base" and derives different classes
>> > to describe several intrinsics for each.  And each class may
>> > have its own unique flags described in virtual function "call_properties".
>> > The specific attributes will be converted from these flags in
>> > "get_attributes" later.
>> >
>> > I find that there are more than 100 classes in total and if I only
>> > need to classify them into different groups by attributes, maybe
>> > we does not need so many classes?
>> 
>> Yeah, I agree.
>> 
>> Long term, there might be value in defining arm_neon.h in a similar
>> way to arm_sve.h: i.e. have arm_neon.h defer most of the work to
>> a special compiler pragma.  But that's going to be a lot of work.
>> 
>> I think it's possible to make incremental improvements to the current
>> arm_neon.h implementation without that work being thrown away if we
>> ever
>> did switch to a pragma in future.  And the incremental approach seems
>> more practical.
>> 
>> > The difficult thing I think is how to classify neon intrinsics into
>> > different groups.  I'm going to follow up the way in SVE intrinsics
>> > first now.
>> 
>> For now I'd suggest just giving a name to each combination of flags
>> that the intrinsics need, rather than splitting instructions in a
>> more fine-grained way.  (It's not at all obvious from the final state
>> of the SVE code, but even there, the idea was to have as few groups as
>> possible.  I.e. the groups were supposedly only split where necessary.
>> As you say, there still ended up being a lot of groups in the end…)
>> 
>> It'd be easier to review if the work was split up into smaller steps.
>> E.g. maybe one way would be this, with each number being a single
>> patch:
>> 
>> (1) (a) Add a flags field to the built-in function definitions
>> that for now is always zero.
>> (b) Pick a name N to describe the most conservative set of flags.
>> (c) Make every built-in function definition use N.
>> 
>
> I have finished the first part.
>
> (a) I add a new parameter called FLAG to every built-in function macro.
>
> (b) I define some flags in aarch64-builtins.c
> FLAG_NONE for no needed flags
> FLAG_READ_FPCR for functions will read FPCR register
> FLAG_RAISE_FP_EXCEPTIONS for functions will raise fp exceptions
> FLAG_READ_MEMORY for functions will read global memory
> FLAG_PREFETCH_MEMORY for functions will prefetch data to memory
> FLAG_WRITE_MEMORY for functions will write global memory
>
> FLAG_FP is used for floating-point arithmetic
> FLAG_ALL is all flags above
>
> (c) I add a field in struct aarch64_simd_builtin_datum to record flags
> for each built-in function.  But the default flags I set for built-in 
> functions
> are FLAG_ALL because by default the built-in functions might do anything.
>
> And bootstrap and regression are tested ok on aarch64 Linux platform.

This looks great.

The patch is OK for trunk, but could you send a changelog too,
so that I can include it in the commit message?

Thanks,
Richard


[Patch][OG10, committed] libgomp.oacc-fortran/firstprivate-int.f90 fix for nonexisting kind-16 int

2020-07-16 Thread Tobias Burnus

i386 (alias x86-64 with -m32) does not support integer(kind=16);
this fix simply uses the highest available value in integer_kinds.

This patch still assumes that all offload targets
support at least those ,
but that seems to currently the case. Alternatively,
one could operate with effective-target, but as this
test copy checks data copying, the simple approach is
sufficient.

Committed to the OG10 (devel/omp/gcc-10) branch.

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
commit b729ebe99cdbb21bb5afccecd0a284d00a66182d
Author: Tobias Burnus 
Date:   Thu Jul 16 14:37:23 2020 +0200

libgomp.oacc-fortran/firstprivate-int.f90 fix for nonexisting kind-16 int

libgomp/
* testsuite/libgomp.oacc-fortran/firstprivate-int.f90: Use
highest available integer kind instead of assuming that kind=16 exists.

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index db1e396b57f..64980dbc38a 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2020-07-16  Tobias Burnus  
+
+	* testsuite/libgomp.oacc-fortran/firstprivate-int.f90: Use
+	highest available integer kind instead of assuming that kind=16 exists.
+
 2020-07-15  Julian Brown  
 
 	* testsuite/libgomp.oacc-c-c++-common/broadcast-many.c: New test.
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90 b/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90
index 3b148ce7517..abc175f37e3 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/firstprivate-int.f90
@@ -3,19 +3,22 @@
 ! { dg-do run }
 
 program test
+  use iso_fortran_env, only: integer_kinds
   implicit none
 
   integer (kind=1)  :: i1i, i1o
   integer (kind=2)  :: i2i, i2o
   integer (kind=4)  :: i4i, i4o
   integer (kind=8)  :: i8i, i8o
-  integer (kind=16) :: i16i, i16o
+! Use highest-precision integer, which might be less than '16'
+! assume integer_kinds == logical_kinds
+  integer (kind=maxval(integer_kinds)) :: i16i, i16o
 
   logical (kind=1)  :: l1i, l1o
   logical (kind=2)  :: l2i, l2o
   logical (kind=4)  :: l4i, l4o
   logical (kind=8)  :: l8i, l8o
-  logical (kind=16) :: l16i, l16o
+  logical (kind=maxval(integer_kinds)) :: l16i, l16o
 
   real (kind=4)  :: r4i, r4o
   real (kind=8)  :: r8i, r8o
@@ -108,19 +111,20 @@ subroutine subtest(i1i, i2i, i4i, i8i, i16i, i1o, i2o, i4o, i8o, i16o, &
l1i, l2i, l4i, l8i, l16i, l1o, l2o, l4o, l8o, l16o, &
r4i, r8i, r4o, r8o, c4i, c8i, c4o, c8o, &
ch1i, ch4i, ch1o, ch4o)
+  use iso_fortran_env, only: integer_kinds
   implicit none
 
   integer (kind=1)  :: i1i, i1o
   integer (kind=2)  :: i2i, i2o
   integer (kind=4)  :: i4i, i4o
   integer (kind=8)  :: i8i, i8o
-  integer (kind=16) :: i16i, i16o
+  integer (kind=maxval(integer_kinds)) :: i16i, i16o
 
   logical (kind=1)  :: l1i, l1o
   logical (kind=2)  :: l2i, l2o
   logical (kind=4)  :: l4i, l4o
   logical (kind=8)  :: l8i, l8o
-  logical (kind=16) :: l16i, l16o
+  logical (kind=maxval(integer_kinds)) :: l16i, l16o
 
   real (kind=4)  :: r4i, r4o
   real (kind=8)  :: r8i, r8o


[committed] build: Fix 'make TAGS' in gcc/

2020-07-16 Thread Andrea Corallo
Hi all,

the following simple patch fixes 'make TAGS' for gcc/

Wasn't working because still searching for params.def.

Committed as obvious fix.

Regards

  Andrea

gcc/ChangeLog:

2020-07-16  Andrea Corallo  

* Makefile.in (TAGS): Remove 'params.def'.
>From 0037265f07295c5e5b0db15c0e87105b85811e80 Mon Sep 17 00:00:00 2001
From: Andrea Corallo 
Date: Thu, 16 Jul 2020 10:20:28 +0100
Subject: [PATCH] build: Fix TAGS target in gcc/Makefile.in

gcc/ChangeLog:

2020-07-16  Andrea Corallo  

	* Makefile.in (TAGS): Remove 'params.def'.
---
 gcc/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 2ba76656dbf..4208c6285b6 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -4247,7 +4247,7 @@ TAGS: lang.tags
 	  ../include/*.h ../libiberty/*.c \
 	  ../libcpp/*.c ../libcpp/include/*.h \
 	  --language=none --regex="/\(char\|unsigned int\|int\|bool\|void\|HOST_WIDE_INT\|enum [A-Za-z_0-9]+\) [*]?\([A-Za-z_0-9]+\)/\2/" common.opt	\
-	  --language=none --regex="/\(DEF_RTL_EXPR\|DEFTREECODE\|DEFGSCODE\|DEFTIMEVAR\|DEFPARAM\|DEFPARAMENUM5\)[ ]?(\([A-Za-z_0-9]+\)/\2/" rtl.def tree.def gimple.def timevar.def params.def \
+	  --language=none --regex="/\(DEF_RTL_EXPR\|DEFTREECODE\|DEFGSCODE\|DEFTIMEVAR\|DEFPARAM\|DEFPARAMENUM5\)[ ]?(\([A-Za-z_0-9]+\)/\2/" rtl.def tree.def gimple.def timevar.def \
 		; \
 	etags --include TAGS.sub $$incs)
 
-- 
2.17.1



[pushed] coroutines: Spelling corrections in comments [NFC].

2020-07-16 Thread Iain Sandoe
Hi

Correct some typos noticed while working on another patch.
tested on x86_64-darwin,
pushed to master,
thanks
Iain

gcc/cp/ChangeLog:

* coroutines.cc: Correct some spelling errors
in comments.
---
 gcc/cp/coroutines.cc | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index bec7f2f2027..d6b584eef58 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -110,7 +110,7 @@ struct coroutine_info_hasher : ggc_ptr_hash
 
 static GTY (()) hash_table *coroutine_info_table;
 
-/* We will initialise state lazily.  */
+/* We will initialize state lazily.  */
 static bool coro_initialized = false;
 
 /* Return a hash value for the entry pointed to by INFO.
@@ -261,7 +261,7 @@ static GTY(()) tree void_coro_handle_type;
 static tree
 find_coro_traits_template_decl (location_t kw)
 {
-  /* If we are missing fundmental information, such as the traits, (or the
+  /* If we are missing fundamental information, such as the traits, (or the
  declaration found is not a type template), then don't emit an error for
  every keyword in a TU, just do it once.  */
   static bool traits_error_emitted = false;
@@ -1102,7 +1102,7 @@ finish_co_yield_expr (location_t kw, tree expr)
   return op;
 }
 
-/* Check and build a co_return statememt.
+/* Check and build a co_return statement.
First that it's valid to have a co_return keyword here.
If it is, then check and build the p.return_{void(),value(expr)}.
These are built against a proxy for the promise, which will be filled
@@ -1519,7 +1519,7 @@ struct coro_aw_data
   unsigned index;  /* This is our current resume index.  */
 };
 
-/* Lighweight search for the first await expression in tree-walk order.
+/* Lightweight search for the first await expression in tree-walk order.
returns:
  The first await expression found in STMT.
  NULL_TREE if there are none.
@@ -1538,13 +1538,13 @@ co_await_find_in_subtree (tree *stmt, int *do_subtree 
ATTRIBUTE_UNUSED, void *d)
   return NULL_TREE;
 }
 
-/* Starting with a statment:
+/* Starting with a statement:
 
stmt => some tree containing one or more await expressions.
 
We replace the statement with:
 {
-  initialise awaitable
+  initialize awaitable
   if (!ready)
{
  suspension context.
@@ -1731,7 +1731,7 @@ expand_one_await_expression (tree *stmt, tree 
*await_expr, void *d)
 
   *await_expr = resume_call; /* Replace the co_await expr with its result.  */
   append_to_statement_list_force (saved_statement, &stmt_list);
-  /* Get a pointer to the revised statment.  */
+  /* Get a pointer to the revised statement.  */
   tree *revised = tsi_stmt_ptr (tsi_last (stmt_list));
   if (needs_dtor)
 {
@@ -2161,7 +2161,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, 
tree actor, tree fnbody,
  bool existed;
  param_info &parm = param_uses->get_or_insert (arg, &existed);
  if (!parm.body_uses)
-   continue; /* Wasn't used in the orignal function body.  */
+   continue; /* Wasn't used in the original function body.  */
 
  tree fld_ref = lookup_member (coro_frame_type, parm.field_id,
/*protect=*/1, /*want_type=*/0,
@@ -3231,7 +3231,7 @@ await_statement_walker (tree *stmt, int *do_subtree, void 
*d)
   if (cond) then stmt1 else stmt2.  */
tree if_stmt = *stmt;
/* We treat the condition as if it was a stand-alone statement,
-  to see if there are any await expressions which will be analysed
+  to see if there are any await expressions which will be analyzed
   and registered.  */
if ((res = cp_walk_tree (&IF_COND (if_stmt),
analyze_expression_awaits, d, &visited)))
@@ -3885,7 +3885,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
   (void) coro_make_frame_entry (&field_list, "__self_h", handle_type, 
fn_start);
 
   /* Now add in fields for function params (if there are any).
- We do not attempt elision of copies at this stage, we do analyse the
+ We do not attempt elision of copies at this stage, we do analyze the
  uses and build worklists to replace those when the state machine is
  lowered.  */
 
@@ -4018,7 +4018,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree 
*destroyer)
   add_decl_expr (coro_fp);
 
   /* The CO_FRAME internal function is a mechanism to allow the middle end
- to adjust the allocation in response to optimisations.  We provide the
+ to adjust the allocation in response to optimizations.  We provide the
  current conservative estimate of the frame size (as per the current)
  computed layout.  */
   tree frame_size = TYPE_SIZE_UNIT (coro_frame_type);
-- 
2.24.1



Re: [PATCH] analyzer: Fix -Wanalyzer-possible-null-argument warning

2020-07-16 Thread Jonathan Wakely via Gcc-patches

On 06/07/20 11:27 +0100, Jonathan Wakely wrote:

On 05/07/20 21:48 -0400, David Malcolm wrote:

On Wed, 2020-07-01 at 18:29 +0100, Jonathan Wakely wrote:

On 30/06/20 17:43 +0100, Jonathan Wakely wrote:

gcc/testsuite/ChangeLog:

* g++.dg/analyzer/pr94028.C: Make operator new non-throwing so
that the compiler doesn't implicitly mark it as returning
non-null.

Fixes these:

FAIL: g++.dg/analyzer/pr94028.C  -std=c++98 (test for excess
errors)
FAIL: g++.dg/analyzer/pr94028.C  -std=c++14 (test for excess
errors)
FAIL: g++.dg/analyzer/pr94028.C  -std=c++17 (test for excess
errors)
FAIL: g++.dg/analyzer/pr94028.C  -std=c++2a (test for excess
errors)


Updated to add PR 96014 to the commit log.

OK for master?


Sorry for not responding to this earlier.

My knowledge of C++ exceptions is a little rusty; I found the addition
of "throw()" to mark the decl as non-throwing to be confusing.


An operator new is required to report allocation failure by throwing
an exception that can be caught by `catch (const std::bad_alloc&)`,
unless it is marked as non-throwing, in which case it reports
allocation failure by returning a null pointer.

I believe the C++ front end adds the returns_nonnull attribute to
operator new unless it is marked non-throwing.

The operator new in this test just calls calloc, which can return
null, but it isn't marked as non-throwing so has the returns_nonnull
attribute. Therefore it has undefined behaviour if calloc ever fails
and returns null. Your analyzer seems to be noticing this, and so
warning, which is nice.

The way to fix it is to either check the return value of calloc and
throw std::bad_alloc() if calloc returned null, or to simply mark the
operator new as non-throwing so that returning null is OK.



Looking in my copy of Stroustrup 4th edition (C++11) p367 it says this
is an empty exception specification, and is equivalent to "noexcept",
and Stroustrup recommends using the latter instead.  Did you use this
syntax for backwards compat with C++98, or is "noexcept" available in
the earlier C++ dialects?


noexcept is not valid in C++98/C++03. But I forgot that throw() is
deprecated in C++17 and removed in C++20, so although G++ still
accepts throw() to be futureproof we should use:

#if __cplusplus < 201103L
# define NOTHROW throw()
#else
# define NOTHROW noexcept
#endif

and then mark it NOTHROW.

Although it would take fewer lines of code to just check what calloc
returns and turn a null pointer into a std::bad_alloc exception.


It looks like I accidentally pushed this patch without approval (when
pushing my own a1a0dc4548979f8a340a7ea71624a52a20e1e0b3 change).

As discussed above, the throw() is not actually valid in C++20. Should
I push this patch to use noexcept instead for C++11 and up?


Tested x86_64-linux:

PASS: g++.dg/analyzer/pr94028.C  -std=c++14  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++14  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++14  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++14 (test for excess errors)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17 (test for excess errors)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a (test for excess errors)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98 (test for excess errors)



commit bd5fbae9d5caaa9810fb3c2a6652f39666d2a728
Author: Jonathan Wakely 
Date:   Thu Jul 16 11:44:32 2020

analyzer: Use noexcept instead of throw() for C++11 and later (PR 96014)

gcc/testsuite/ChangeLog:

PR testsuite/96014
* g++.dg/analyzer/pr94028.C: Replace dynamic exception
specification with noexcept-specifier for C++11 and later.

diff --git a/gcc/testsuite/g++.dg/analyzer/pr94028.C b/gcc/testsuite/g++.dg/analyzer/pr94028.C
index c0c35d65829..5c8e2c9b286 100644
--- a/gcc/testsuite/g++.dg/analyzer/pr94028.C
+++ b/gcc/testsuite/g++.dg/analyzer/pr94028.C
@@ -12,7 +12,12 @@ enum e {} i;
 
 struct j
 {
-  void *operator new (__SIZE_TYPE__ b) throw()
+  void *operator new (__SIZE_TYPE__ b)
+#if __cplusplus >= 201103L
+noexcept
+#else
+throw()
+#endif
   {
 return calloc (b, sizeof (int)); // { dg-warning "leak" }
   }


[PATCH] Don't write COMDAT group id to LTO output on PE/COFF

2020-07-16 Thread Markus Böck via Gcc-patches
COFF targets currently do not support COMDAT groups. On MinGW targets
GCC instead puts symbols part of a COMDAT group inside of sections
annotated with the .linkonce GAS directive. This leads to GAS
generating a section so that the COMDAT name is the same as the name
of the actual symbol.

When using LTO however we never go through any of those mechanisms and
instead output the COMDAT into the LTO IR. This patch fixes this by
basically replicating the above chain by instead writing the name into
the IR file.

This case only occurs in cases where multiple inheritance is used and
non virtual thunks are created. This problem was found while trying to
compile Qt using LTO on a MinGW target. In the patch a minimal
reproducible testcase is added which fails to link without the patch
and links successfully with the patch. No regressions were observed in
the gcc and g++ testsuite after the patch has been added.

gcc/ChangeLog:

2020-07-16  Markus Böck  

* lto-streamer-out.c (write_symol): Write symbol name instead of
COMDAT group
on PE/COFF Targets

gcc/testsuite/ChangeLog:

2020-07-16  Markus Böck  

* g++.dg/lto/virtual-thunk-comdat_0.C: New test.
* g++.dg/lto/virtual-thunk-comdat.h: New test.
* g++.dg/lto/virtual-thunk-comdat_1.C: New test.

--

Index: gcc/lto-streamer-out.c
===
--- gcc/lto-streamer-out.c (revision 932e9140d3268cf2033c1c3e93219541c53fcd29)
+++ gcc/lto-streamer-out.c (date 1594903384922)
@@ -2779,7 +2779,12 @@
 size = 0;

   if (DECL_ONE_ONLY (t))
+{
+  if (TARGET_PECOFF)
+comdat = name;
+  else
 comdat = IDENTIFIER_POINTER (decl_comdat_group_id (t));
+}
   else
 comdat = "";

Index: gcc/testsuite/g++.dg/lto/virtual-thunk-comdat_0.C
===
--- gcc/testsuite/g++.dg/lto/virtual-thunk-comdat_0.C  (date 1594903164805)
+++ gcc/testsuite/g++.dg/lto/virtual-thunk-comdat_0.C  (date 1594903164805)
@@ -0,0 +1,15 @@
+// { dg-lto-do link }
+#include "virtual-thunk-comdat.h"
+
+QAccessibleInterface::~QAccessibleInterface() {}
+
+QAccessibleActionInterface::~QAccessibleActionInterface() {}
+
+QAccessibleEditableTextInterface::~QAccessibleEditableTextInterface() {}
+
+bool QAccessibleObject::isValid() const
+{
+  return false;
+}
+
+void QAccessibleLineEdit::deleteText(const char* string) {}
Index: gcc/testsuite/g++.dg/lto/virtual-thunk-comdat.h
===
--- gcc/testsuite/g++.dg/lto/virtual-thunk-comdat.h(date 1594901724581)
+++ gcc/testsuite/g++.dg/lto/virtual-thunk-comdat.h(date 1594901724581)
@@ -0,0 +1,39 @@
+
+class QAccessibleInterface
+{
+protected:
+  virtual ~QAccessibleInterface();
+
+public:
+  virtual bool isValid() const = 0;
+};
+
+class QAccessibleActionInterface
+{
+public:
+  virtual ~QAccessibleActionInterface();
+};
+
+class QAccessibleEditableTextInterface
+{
+public:
+  virtual ~QAccessibleEditableTextInterface();
+
+  virtual void deleteText(const char*) = 0;
+};
+
+class QAccessibleObject : public QAccessibleInterface
+{
+public:
+  bool isValid() const override;
+};
+
+class QAccessibleWidget : public QAccessibleObject, public
QAccessibleActionInterface
+{
+};
+
+class QAccessibleLineEdit : public QAccessibleWidget, public
QAccessibleEditableTextInterface
+{
+public:
+  void deleteText(const char* string) override;
+};
Index: gcc/testsuite/g++.dg/lto/virtual-thunk-comdat_1.C
===
--- gcc/testsuite/g++.dg/lto/virtual-thunk-comdat_1.C  (date 1594903161383)
+++ gcc/testsuite/g++.dg/lto/virtual-thunk-comdat_1.C  (date 1594903161383)
@@ -0,0 +1,3 @@
+#include "virtual-thunk-comdat.h"
+
+int main(int argc, char **argv) { QAccessibleLineEdit lineEdit; }


Re: [PATCH] analyzer: Fix -Wanalyzer-possible-null-argument warning

2020-07-16 Thread Nathan Sidwell

On 7/16/20 9:01 AM, Jonathan Wakely wrote:

On 06/07/20 11:27 +0100, Jonathan Wakely wrote:

On 05/07/20 21:48 -0400, David Malcolm wrote:

On Wed, 2020-07-01 at 18:29 +0100, Jonathan Wakely wrote:

On 30/06/20 17:43 +0100, Jonathan Wakely wrote:

gcc/testsuite/ChangeLog:

* g++.dg/analyzer/pr94028.C: Make operator new non-throwing so
that the compiler doesn't implicitly mark it as returning
non-null.

Fixes these:

FAIL: g++.dg/analyzer/pr94028.C  -std=c++98 (test for excess
errors)
FAIL: g++.dg/analyzer/pr94028.C  -std=c++14 (test for excess
errors)
FAIL: g++.dg/analyzer/pr94028.C  -std=c++17 (test for excess
errors)
FAIL: g++.dg/analyzer/pr94028.C  -std=c++2a (test for excess
errors)


Updated to add PR 96014 to the commit log.

OK for master?


Sorry for not responding to this earlier.

My knowledge of C++ exceptions is a little rusty; I found the addition
of "throw()" to mark the decl as non-throwing to be confusing.


An operator new is required to report allocation failure by throwing
an exception that can be caught by `catch (const std::bad_alloc&)`,
unless it is marked as non-throwing, in which case it reports
allocation failure by returning a null pointer.

I believe the C++ front end adds the returns_nonnull attribute to
operator new unless it is marked non-throwing.

The operator new in this test just calls calloc, which can return
null, but it isn't marked as non-throwing so has the returns_nonnull
attribute. Therefore it has undefined behaviour if calloc ever fails
and returns null. Your analyzer seems to be noticing this, and so
warning, which is nice.

The way to fix it is to either check the return value of calloc and
throw std::bad_alloc() if calloc returned null, or to simply mark the
operator new as non-throwing so that returning null is OK.



Looking in my copy of Stroustrup 4th edition (C++11) p367 it says this
is an empty exception specification, and is equivalent to "noexcept",
and Stroustrup recommends using the latter instead.  Did you use this
syntax for backwards compat with C++98, or is "noexcept" available in
the earlier C++ dialects?


noexcept is not valid in C++98/C++03. But I forgot that throw() is
deprecated in C++17 and removed in C++20, so although G++ still
accepts throw() to be futureproof we should use:

#if __cplusplus < 201103L
# define NOTHROW throw()
#else
# define NOTHROW noexcept
#endif

and then mark it NOTHROW.

Although it would take fewer lines of code to just check what calloc
returns and turn a null pointer into a std::bad_alloc exception.


It looks like I accidentally pushed this patch without approval (when
pushing my own a1a0dc4548979f8a340a7ea71624a52a20e1e0b3 change).

As discussed above, the throw() is not actually valid in C++20. Should
I push this patch to use noexcept instead for C++11 and up?


yes thanks


Tested x86_64-linux:

PASS: g++.dg/analyzer/pr94028.C  -std=c++14  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++14  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++14  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++14 (test for excess errors)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++17 (test for excess errors)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++2a (test for excess errors)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98  (test for warnings, line 22)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98  (test for warnings, line 26)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98  (test for warnings, line 33)
PASS: g++.dg/analyzer/pr94028.C  -std=c++98 (test for excess errors)






--
Nathan Sidwell


Re: [PATCH] c++: Get rid of convert_like* macros.

2020-07-16 Thread Nathan Sidwell

On 7/15/20 6:59 PM, Marek Polacek wrote:

The convert_like* macros were introduced in

2000-03-05  Nathan Sidwell  

 * call.c (convert_like): Macrofy.
 (convert_like_with_context): New macro.

but now we can use overloading so we can do away with the macros.
I've also taken this chance to rename _real to _internal to make it
clear that it should not be called directly.


ok, a nit ...


+/* Wrapper for convert_like_internal that handles creating
+   IMPLICIT_CONV_EXPR.  */
+
+static tree
+convert_like (conversion *convs, tree expr, tree fn, int argnum,
+ bool issue_conversion_warnings,bool c_cast_p,


missing space after comma


+ tsubst_flags_t complain)
+{



+
+/* Convenience wrapper for convert_like.  */
+
+static inline tree
+convert_like (conversion *convs, tree expr, tsubst_flags_t complain)


It's unfortunate the argument ordering is not friendly to using default 
args.  Reordering would be too much churn I suspect.  Let's not go there.



+static inline tree
+convert_like_with_context (conversion *convs, tree expr, tree fn, int argnum,
+  tsubst_flags_t complain)
+{
+  return convert_like (convs, expr, fn, argnum,
+  /*issue_conversion_warnings=*/true,
+  /*c_cast_p=*/false, complain);
+}


nathan


--
Nathan Sidwell


Re: [Patch][Middle-end]Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]

2020-07-16 Thread Victor Rodriguez via Gcc-patches
On Tue, Jul 14, 2020 at 9:52 AM Qing Zhao via Gcc-patches
 wrote:
>
> Hi, Gcc team,
>
> This patch is a follow-up on the previous patch and corresponding discussion:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545101.html 
> 
>
> From the previous round of discussion, the major issues raised were:
>
> A. should be rewritten by using regsets infrastructure.
> B. Put the patch into middle-end instead of x86 backend.
>
> This new patch is rewritten based on the above 2 comments.  The major changes 
> compared to the previous patch are:
>
> 1. Change the names of the option and attribute from
> -mzero-caller-saved-regs=[skip|used-gpr|all-gpr|used|all]  and 
> zero_caller_saved_regs("skip|used-gpr|all-gpr||used|all”)
> to:
> -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]   and  
> zero_call_used_regs("skip|used-gpr|all-gpr||used|all”)
> Add the new option and  new attribute in general.
> 2. The main code generation part is moved from i386 backend to middle-end;
> 3. Add 4 target-hooks;
> 4. Implement these 4 target-hooks on i386 backend.
> 5. On a target that does not implement the target hook, issue error for the 
> new option, issue warning for the new attribute.
>
> The patch is as following:
>
> [PATCH] Add -fzero-call-used-regs=[skip|used-gpr|all-gpr|used|all]
> command-line option and
> zero_call_used_regs("skip|used-gpr|all-gpr||used|all") function attribue:
>
>   1. -fzero-call-used-regs=skip and zero_call_used_regs("skip")
>
>   Don't zero call-used registers upon function return.
>
>   2. -fzero-call-used-regs=used-gpr and zero_call_used_regs("used-gpr")
>
>   Zero used call-used general purpose registers upon function return.
>
>   3. -fzero-call-used-regs=all-gpr and zero_call_used_regs("all-gpr")
>
>   Zero all call-used general purpose registers upon function return.
>
>   4. -fzero-call-used-regs=used and zero_call_used_regs("used")
>
>   Zero used call-used registers upon function return.
>
>   5. -fzero-call-used-regs=all and zero_call_used_regs("all")
>
>   Zero all call-used registers upon function return.
>
> The feature is implemented in middle-end. But currently is only valid on X86.
>
> Tested on x86-64 and aarch64 with bootstrapping GCC trunk, making
> -fzero-call-used-regs=used-gpr, -fzero-call-used-regs=all-gpr
> -fzero-call-used-regs=used, and -fzero-call-used-regs=all enabled
> by default on x86-64.
>
> Please take a look and let me know any more comment?
>
> thanks.
>
> Qing
>
>
> 
>
> gcc/ChangeLog:
>
> 2020-07-13  qing zhao  mailto:qing.z...@oracle.com>>
> 2020-07-13  H.J. Lu mailto:hjl.to...@gmail.com>>
>
> * common.opt: Add new option -fzero-call-used-regs.
> * config/i386/i386.c (ix86_zero_call_used_regno_p): New function.
> (ix86_zero_call_used_regno_mode): Likewise.
> (ix86_zero_all_vector_registers): Likewise.
> (ix86_expand_prologue): Replace gen_prologue_use with
> gen_pro_epilogue_use.
> (TARGET_ZERO_CALL_USED_REGNO_P): Define.
> (TARGET_ZERO_CALL_USED_REGNO_MODE): Define.
> (TARGET_PRO_EPILOGUE_USE): Define.
> (TARGET_ZERO_ALL_VECTOR_REGISTERS): Define.
> * config/i386/i386.md: Replace UNSPECV_PROLOGUE_USE
> with UNSPECV_PRO_EPILOGUE_USE.
> * coretypes.h (enum zero_call_used_regs): New type.
> * doc/extend.texi: Document the new zero_call_used_regs attribute.
> * doc/invoke.texi: Document the new -fzero-call-used-regs option.
> * doc/tm.texi: Regenerate.
> * doc/tm.texi.in (TARGET_ZERO_CALL_USED_REGNO_P): New hook.
> (TARGET_ZERO_CALL_USED_REGNO_MODE): Likewise.
> (TARGET_PRO_EPILOGUE_USE): Likewise.
> (TARGET_ZERO_ALL_VECTOR_REGISTERS): Likewise.
> * function.c (is_live_reg_at_exit): New function.
> (gen_call_used_regs_seq): Likewise.
> (make_epilogue_seq): Call gen_call_used_regs_seq.
> * function.h (is_live_reg_at_exit): Declare.
> * target.def (zero_call_used_regno_p): New hook.
> (zero_call_used_regno_mode): Likewise.
> (pro_epilogue_use): Likewise.
> (zero_all_vector_registers): Likewise.
> * targhooks.c (default_zero_call_used_regno_p): New function.
> (default_zero_call_used_regno_mode): Likewise.
> * targhooks.h (default_zero_call_used_regno_p): Declare.
> (default_zero_call_used_regno_mode): Declare.
> * toplev.c (process_options): Issue errors when -fzero-call-used-regs
> is used on targets that do not support it.
> * tree-core.h (struct tree_decl_with_vis): New field
> zero_call_used_regs_type.
> * tree.h (DECL_ZERO_CALL_USED_REGS): New macro.
>
> gcc/c-family/ChangeLog:
>
> 2020-07-13  qing zhao  mailto:qing.z...@oracle.com>>
> 2020-07-13  H.J. Lu mailto:hjl.to...@gmail.com>>
>
> * c-attribs.c (c_common_attribute_table): Add new attribute
> 

Re: [PATCH] c++: Get rid of convert_like* macros.

2020-07-16 Thread Marek Polacek via Gcc-patches
On Thu, Jul 16, 2020 at 09:16:06AM -0400, Nathan Sidwell wrote:
> On 7/15/20 6:59 PM, Marek Polacek wrote:
> > The convert_like* macros were introduced in
> > 
> > 2000-03-05  Nathan Sidwell  
> > 
> >  * call.c (convert_like): Macrofy.
> >  (convert_like_with_context): New macro.
> > 
> > but now we can use overloading so we can do away with the macros.
> > I've also taken this chance to rename _real to _internal to make it
> > clear that it should not be called directly.
> 
> ok, a nit ...
> 
> > +/* Wrapper for convert_like_internal that handles creating
> > +   IMPLICIT_CONV_EXPR.  */
> > +
> > +static tree
> > +convert_like (conversion *convs, tree expr, tree fn, int argnum,
> > + bool issue_conversion_warnings,bool c_cast_p,
> 
> missing space after comma

Oop, will fix.

> > + tsubst_flags_t complain)
> > +{
> 
> > +
> > +/* Convenience wrapper for convert_like.  */
> > +
> > +static inline tree
> > +convert_like (conversion *convs, tree expr, tsubst_flags_t complain)
> 
> It's unfortunate the argument ordering is not friendly to using default
> args.  Reordering would be too much churn I suspect.  Let's not go there.

Yeah, that was my thinking too.

Thanks,
Marek



Re: [PATCH 1/6] AArch64: Fix bugs in -mcpu=native detection.

2020-07-16 Thread Tamar Christina
Hi Richard,

I have fixed the formatting issues and made it so it checks explicitly
for ':'.

Ok for master, GCC 10, 9 and 8 after some stew?

Thanks,
Tamar

gcc/ChangeLog:

* config/aarch64/driver-aarch64.c (INCLUDE_SET): New.
(parse_field): Use std::string.
(split_words, readline, find_field): New.
(host_detect_local_cpu): Fix truncation issues.

The 07/09/2020 18:31, Richard Sandiford wrote:
> Tamar Christina  writes:
> > Hi Richard,
> >
> > Thanks for the review,
> >
> >> -Original Message-
> >> From: Richard Sandiford 
> >> Sent: Thursday, July 9, 2020 1:35 PM
> >> To: Tamar Christina 
> >> Cc: gcc-patches@gcc.gnu.org; nd ; Richard Earnshaw
> >> ; Marcus Shawcroft
> >> ; Kyrylo Tkachov 
> >> Subject: Re: [PATCH 1/6] AArch64: Fix bugs in -mcpu=native detection.
> >> 
> >> Tamar Christina  writes:
> >> > Hi All,
> >> >
> >> > This patch fixes a couple of issues in AArch64's -mcpu=native processing:
> >> >
> >> > The buffer used to read the lines from /proc/cpuinfo is 128 bytes
> >> > long.  While this was enough in the past with the increase in 
> >> > architecture
> >> extensions it is
> >> > no longer enough.   It results in two bugs:
> >> >
> >> > 1) No option string longer than 127 characters is correctly parsed.  
> >> > Features
> >> >that are supported are silently ignored.
> >> >
> >> > 2) It incorrectly enables features that are not present on the machine:
> >> >   a) It checks for substring matching instead of full word matching.  
> >> > This
> >> makes
> >> >  it incorrectly detect sb support when ssbs is provided instead.
> >> >   b) Due to the truncation at the 127 char border it also incorrectly 
> >> > enables
> >> >  features due to the full feature being cut off and the part that is 
> >> > left
> >> >  accidentally enables something else.
> >> >
> >> > This breaks -mcpu=native detection on some of our newer system.
> >> >
> >> > The patch fixes these issues by reading full lines up to the \n in a 
> >> > string.
> >> > This gives us the full feature line.  Secondly it creates a set from
> >> > this string
> >> > to:
> >> >
> >> >  1) Reduce matching complexity from O(n*m) to O(n*logm).
> >> >  2) Perform whole word matching instead of substring matching.
> >> >
> >> > To make this code somewhat cleaner I also changed from using char* to
> >> > using std::string and std::set.
> >> >
> >> > Note that I have intentionally avoided the use of ifstream and
> >> > stringstream to make it easier to backport.  I have also not change
> >> > the substring matching for the initial line classification as I cannot
> >> > find a documented cpuinfo format which leads me to believe there may
> >> > be kernels out there that require this which may be why the original code
> >> does this.
> >> >
> >> > I also do not want this to break if the kernel adds a new line that is
> >> > long and indents the file by two tabs to keep everything aligned.  In
> >> > short I think an imprecise match is the right thing here.
> >> >
> >> > Test for this is added as the last thing in this series as it requires
> >> > some changes to be made to be able to test this.
> >> >
> >> > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> >> 
> >> Sorry to be awkward.  I know Kyrill's already approved this, but I kind-of
> >> object.
> >> 
> >> I think we should split this into two: fixing the limit bug, and fixing the
> >> complexity.  It's easier to justify backporting the fix for the limit bug 
> >> than the
> >> fix for the complexity.
> >
> > It was never the intention to fix the complexity. The change in complexity 
> > is just
> > simply because I split the feature strings into actual words now. I do so 
> > because
> > in my opinion this is simpler than doing memcmp and checking the the 
> > character
> > after the one you matched is a space or a null character, and then checking 
> > that you are
> > one character away from the previous space or at the start of the line.
> >
> > Do you know of a simpler way to do word matches in C?
> 
> This isn't an anti-C++ thing :-)  I just think any clean-up should
> be separate from the bugfix, and only the bugfix should be backported.
> 
> >> For fixing the limit bug, it seems better to use an obstack to read the 
> >> file
> >> instead.  This should actually be much easier than what the patch does. 
> >> :-)  It
> >> should also be more efficient.
> >> 
> >
> > Sorry.. I genuinely don't understand. I had looked at obstack and the 
> > interface seemed to be
> > more work to me.  I am probably wrong since this interface has zero 
> > documentation
> > but it looks like to use obstack I have to (based on guessing from what 
> > other code are doing)
> >
> > 1. call gcc_obstack_init
> > 2. call obstack_alloc
> > 3. call obstack_grow any time I need a bigger buffer.
> > 4. call obstack_free
> >
> > So I am missing why this is simpler than calling realloc... 
> > But obviously I am missing something.
> 
> Yeah, (1)

[Patch][OG10] omp-low.c: Avoid offload-target lto1 is-missing error by not-privatizing TREE_READONLY vars

2020-07-16 Thread Tobias Burnus

[This is an OpenACC issue but I would not completely surprised if
something similar could occur for OpenMP offloading as well.
However, the patch is for an OpenACC-specific function.]

This issue occurs for libgomp.oacc-fortran/privatized-ref-2.f90, for which
on the device lto1 complains:
lto1: fatal error: /tmp/ccEGJTZN.o: section A.13.1.21 is missing Here,
"A.13" is a TREE_STATIC, TREE_READONLY array generated by the Fortran
front-end and containing the array-constructor values, i.e. RHS of:
array = [(-2*i, i = 1, size(array))] That testcase works on the trunk or
on the OG10 (= devel/omp/gcc-10) branch if one reverts the patch "Re-do
OpenACC private variable resolution"
https://gcc.gnu.org/g:2f4b477223fddb84f66e494eb88d1defbd5e04a2 which is
scheduled but not yet submitted for mainline inclusion. The offloading
variable table contains the variable as "A.13.10" (which works fine) and
the problem-causing patch causes that the code   .UNIQUE (OACC_PRIVATE, 0, 0, 
&parm.9, &A.13);
gets inserted (via the then-added make_oacc_private_marker in omp-low.c).
Here, the decl for 'A.13' does not have a varpool_node entry – and
it is not streamed out as separate entity.
(This IFN_ is then later processed by the target lto1 via omp-offload.c's
execute_oacc_device_lower – where the asm_name "A.13.1" appears.)

[While I do not completely understand why the target LTO does
not contain the symbol, I think the following still makes sense.
(I do understand why the offload var table does not contain it.)]


If the variable is TREE_READONLY, there is no need to pass it
through the variable-privatization bits.

The current check is for VAR_P and TREE_ADDRESSABLE. For the fix,
one could use:
  !TREE_READONLY
or
  !(TREE_READONLY && TREE_STATIC)
or
  !(TREE_READONLY && (TREE_STATIC || DECL_EXTERNAL)
I am not sure what makes more sense. I initially used the first
version and then moved to the last. Thoughts?

Additional comments?
Does it look OK for OG10?

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
omp-low.c: Avoid offload-target lto1 is-missing error by not-privatizing TREE_READONLY vars

gcc/ChangeLog:

	* omp-low.c (oacc_record_private_var_clauses,
	oacc_record_vars_in_bind): Do not privatize read-only static/exernal
	variables.
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 09603635350..bd3866c4d2e 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -9813,7 +9813,9 @@ oacc_record_private_var_clauses (omp_context *ctx, tree clauses)
 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE)
   {
 	tree decl = OMP_CLAUSE_DECL (c);
-	if (VAR_P (decl) && TREE_ADDRESSABLE (decl))
+	if (VAR_P (decl) && TREE_ADDRESSABLE (decl)
+	&& !(TREE_READONLY (decl)
+		 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl
 	  ctx->oacc_addressable_var_decls->safe_push (decl);
   }
 }
@@ -9828,7 +9830,8 @@ oacc_record_vars_in_bind (omp_context *ctx, tree bindvars)
 return;
 
   for (tree v = bindvars; v; v = DECL_CHAIN (v))
-if (VAR_P (v) && TREE_ADDRESSABLE (v))
+if (VAR_P (v) && TREE_ADDRESSABLE (v)
+	&& !(TREE_READONLY (v) && (TREE_STATIC (v) || DECL_EXTERNAL (v
   ctx->oacc_addressable_var_decls->safe_push (v);
 }
 



RE: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3

2020-07-16 Thread xiezhiheng
> -Original Message-
> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
> Sent: Thursday, July 16, 2020 8:42 PM
> To: xiezhiheng 
> Cc: Richard Biener ; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions
> emitted at -O3
> 
> xiezhiheng  writes:
> >> -Original Message-
> >> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
> >> Sent: Tuesday, July 7, 2020 10:08 PM
> >> To: xiezhiheng 
> >> Cc: Richard Biener ;
> gcc-patches@gcc.gnu.org
> >> Subject: Re: [PATCH PR94442] [AArch64] Redundant ldp/stp instructions
> >> emitted at -O3
> >>
> >> xiezhiheng  writes:
> >> >> -Original Message-
> >> >> From: Richard Sandiford [mailto:richard.sandif...@arm.com]
> >> >> Sent: Monday, July 6, 2020 5:31 PM
> >> >> To: xiezhiheng 
> >> >> Cc: Richard Biener ;
> >> gcc-patches@gcc.gnu.org
> >> >> Subject: Re: [PATCH PR94442] [AArch64] Redundant ldp/stp
> instructions
> >> >> emitted at -O3
> >> >>
> >> >> No, this is unfortunately a known bug.  See:
> >> >>
> >> >>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95964
> >> >>
> >> >> (Although the PR is recent, it's been a known bug for longer.)
> >> >>
> >> >> As you say, the difficulty is that the correct attributes depend on what
> >> >> the built-in function does.  Most integer arithmetic is “const”, but
> >> things
> >> >> get more complicated for floating-point arithmetic.
> >> >>
> >> >> The SVE intrinsics use a three stage process:
> >> >>
> >> >> - each function is classified into one of several groups
> >> >> - each group has a set of flags that describe what functions in the
> >> >>   group can do
> >> >> - these flags get converted into attributes based on the current
> >> >>   command-line options
> >> >>
> >> >> I guess we should have something similar for the arm_neon.h built-ins.
> >> >>
> >> >> If you're willing to help fix this, that'd be great.  I think a first
> >> >> step would be to agree a design.
> >> >>
> >> >> Thanks,
> >> >> Richard
> >> >
> >> > I'd like to have a try.
> >>
> >> Great!
> >>
> >> > I have checked the steps in SVE intrinsics.
> >> > It defines a base class "function_base" and derives different classes
> >> > to describe several intrinsics for each.  And each class may
> >> > have its own unique flags described in virtual function 
> >> > "call_properties".
> >> > The specific attributes will be converted from these flags in
> >> > "get_attributes" later.
> >> >
> >> > I find that there are more than 100 classes in total and if I only
> >> > need to classify them into different groups by attributes, maybe
> >> > we does not need so many classes?
> >>
> >> Yeah, I agree.
> >>
> >> Long term, there might be value in defining arm_neon.h in a similar
> >> way to arm_sve.h: i.e. have arm_neon.h defer most of the work to
> >> a special compiler pragma.  But that's going to be a lot of work.
> >>
> >> I think it's possible to make incremental improvements to the current
> >> arm_neon.h implementation without that work being thrown away if we
> >> ever
> >> did switch to a pragma in future.  And the incremental approach seems
> >> more practical.
> >>
> >> > The difficult thing I think is how to classify neon intrinsics into
> >> > different groups.  I'm going to follow up the way in SVE intrinsics
> >> > first now.
> >>
> >> For now I'd suggest just giving a name to each combination of flags
> >> that the intrinsics need, rather than splitting instructions in a
> >> more fine-grained way.  (It's not at all obvious from the final state
> >> of the SVE code, but even there, the idea was to have as few groups as
> >> possible.  I.e. the groups were supposedly only split where necessary.
> >> As you say, there still ended up being a lot of groups in the end…)
> >>
> >> It'd be easier to review if the work was split up into smaller steps.
> >> E.g. maybe one way would be this, with each number being a single
> >> patch:
> >>
> >> (1) (a) Add a flags field to the built-in function definitions
> >> that for now is always zero.
> >> (b) Pick a name N to describe the most conservative set of flags.
> >> (c) Make every built-in function definition use N.
> >>
> >
> > I have finished the first part.
> >
> > (a) I add a new parameter called FLAG to every built-in function macro.
> >
> > (b) I define some flags in aarch64-builtins.c
> > FLAG_NONE for no needed flags
> > FLAG_READ_FPCR for functions will read FPCR register
> > FLAG_RAISE_FP_EXCEPTIONS for functions will raise fp exceptions
> > FLAG_READ_MEMORY for functions will read global memory
> > FLAG_PREFETCH_MEMORY for functions will prefetch data to memory
> > FLAG_WRITE_MEMORY for functions will write global memory
> >
> > FLAG_FP is used for floating-point arithmetic
> > FLAG_ALL is all flags above
> >
> > (c) I add a field in struct aarch64_simd_builtin_datum to record flags
> > for each built-in function.  But the default flags I set for built-in 
> > functions
> > are FLAG_ALL because by

[committed] amdgcn: Handle early debug info in mkoffload

2020-07-16 Thread Andrew Stubbs
This patch adds debug support to mkoffload, similar to what happens in 
lto-wrapper.


Unlike lto-wrapper, we must deal with mismatched architectures and 
mismatched program scope. These are fixed up using manual ELF patching 
because there's no useful support in simple_object (yet). Should this be 
something that other offload targets want to do then that probably ought 
to be changed in future, but it isn't necessary yet.


This is enough to prevent rocgdb choking on malformed debug information 
and debug simple offload testcases; it may be that further adjustment is 
needed.


I have not attempted to make similar changes to the other instance of 
mkoffload as nvptx has no use for debug info.


Andrew
amdgcn: Handle early debug info in mkoffload

Forward the early debug information from the input LTO file to the output
HSACO file, in the same way lto-wrapper does.  This is a little more
complicated, however, because the ELF file containing the debug needs to be
converted from x86_64 to amdgcn, and because the offloaded code will have less
content than the host program the debug info describes.

gcc/ChangeLog:

	* config/gcn/mkoffload.c: Include simple-object.h and elf.h.
	(EM_AMDGPU): New macro.
	(ELFOSABI_AMDGPU_HSA): New macro.
	(ELFABIVERSION_AMDGPU_HSA): New macro.
	(EF_AMDGPU_MACH_AMDGCN_GFX803): New macro.
	(EF_AMDGPU_MACH_AMDGCN_GFX900): New macro.
	(EF_AMDGPU_MACH_AMDGCN_GFX906): New macro.
	(R_AMDGPU_NONE): New macro.
	(R_AMDGPU_ABS32_LO): New macro.
	(R_AMDGPU_ABS32_HI): New macro.
	(R_AMDGPU_ABS64): New macro.
	(R_AMDGPU_REL32): New macro.
	(R_AMDGPU_REL64): New macro.
	(R_AMDGPU_ABS32): New macro.
	(R_AMDGPU_GOTPCREL): New macro.
	(R_AMDGPU_GOTPCREL32_LO): New macro.
	(R_AMDGPU_GOTPCREL32_HI): New macro.
	(R_AMDGPU_REL32_LO): New macro.
	(R_AMDGPU_REL32_HI): New macro.
	(reserved): New macro.
	(R_AMDGPU_RELATIVE64): New macro.
	(gcn_s1_name): Delete global variable.
	(gcn_s2_name): Delete global variable.
	(gcn_o_name): Delete global variable.
	(gcn_cfile_name): Delete global variable.
	(files_to_cleanup): New global variable.
	(offload_abi): New global variable.
	(tool_cleanup): Use files_to_cleanup, not explicit list.
	(copy_early_debug_info): New function.
	(main): New local variables gcn_s1_name, gcn_s2_name, gcn_o_name,
	gcn_cfile_name.
	Create files_to_cleanup obstack.
	Recognize -march options.
	Copy early debug info from input .o files.

diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 0415d945e72..553f25e70df 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -33,31 +33,53 @@
 #include 
 #include "collect-utils.h"
 #include "gomp-constants.h"
+#include "simple-object.h"
+#include "elf.h"
+
+/* These probably won't be in elf.h for a while.  */
+#ifndef EM_AMDGPU
+#define EM_AMDGPU		0xe0;
+
+#define ELFOSABI_AMDGPU_HSA	 64
+#define ELFABIVERSION_AMDGPU_HSA 1
+
+#define EF_AMDGPU_MACH_AMDGCN_GFX803 0x2a
+#define EF_AMDGPU_MACH_AMDGCN_GFX900 0x2c
+#define EF_AMDGPU_MACH_AMDGCN_GFX906 0x2f
+
+#define R_AMDGPU_NONE		0
+#define R_AMDGPU_ABS32_LO	1	/* (S + A) & 0x  */
+#define R_AMDGPU_ABS32_HI	2	/* (S + A) >> 32  */
+#define R_AMDGPU_ABS64		3	/* S + A  */
+#define R_AMDGPU_REL32		4	/* S + A - P  */
+#define R_AMDGPU_REL64		5	/* S + A - P  */
+#define R_AMDGPU_ABS32		6	/* S + A  */
+#define R_AMDGPU_GOTPCREL	7	/* G + GOT + A - P  */
+#define R_AMDGPU_GOTPCREL32_LO	8	/* (G + GOT + A - P) & 0x  */
+#define R_AMDGPU_GOTPCREL32_HI	9	/* (G + GOT + A - P) >> 32  */
+#define R_AMDGPU_REL32_LO	10	/* (S + A - P) & 0x  */
+#define R_AMDGPU_REL32_HI	11	/* (S + A - P) >> 32  */
+#define reserved		12
+#define R_AMDGPU_RELATIVE64	13	/* B + A  */
+#endif
 
 const char tool_name[] = "gcn mkoffload";
 
-/* Files to unlink.  */
-static const char *gcn_s1_name;
-static const char *gcn_s2_name;
-static const char *gcn_o_name;
-static const char *gcn_cfile_name;
 static const char *gcn_dumpbase;
+static struct obstack files_to_cleanup;
 
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
+uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803;  // Default GPU architecture.
 
 /* Delete tempfiles.  */
 
 void
 tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
 {
-  if (gcn_cfile_name)
-maybe_unlink (gcn_cfile_name);
-  if (gcn_s1_name)
-maybe_unlink (gcn_s1_name);
-  if (gcn_s2_name)
-maybe_unlink (gcn_s2_name);
-  if (gcn_o_name)
-maybe_unlink (gcn_o_name);
+  obstack_ptr_grow (&files_to_cleanup, NULL);
+  const char **files = XOBFINISH (&files_to_cleanup, const char **);
+  for (int i = 0; files[i]; i++)
+maybe_unlink (files[i]);
 }
 
 static void
@@ -204,6 +226,180 @@ access_check (const char *name, int mode)
   return access (name, mode);
 }
 
+/* Copy the early-debug-info from the incoming LTO object to a new object
+   that will be linked into the output HSACO file.  The host relocations
+   must be translated into GCN relocations, and any global undefined symbols
+   must be weakened (so as not to have the debug info tr

[PATCH] c++: Variable template and template parameter pack [PR96218]

2020-07-16 Thread Marek Polacek via Gcc-patches
This is DR 2032 which says that the restrictions regarding template
parameter packs and default arguments apply to variable templates as
well, but we weren't detecting that.

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

gcc/cp/ChangeLog:

DR 2032
PR c++/96218
* pt.c (check_default_tmpl_args): Also consider variable
templates.

gcc/testsuite/ChangeLog:

DR 2032
PR c++/96218
* g++.dg/cpp1y/var-templ67.C: New test.
---
 gcc/cp/pt.c  |  5 +++--
 gcc/testsuite/g++.dg/cpp1y/var-templ67.C | 16 
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ67.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4e1c77a6bd7..b74074a092b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5481,14 +5481,15 @@ check_default_tmpl_args (tree decl, tree parms, bool 
is_primary,
   /* Don't complain about an enclosing partial
  specialization.  */
   && parm_level == parms
-  && TREE_CODE (decl) == TYPE_DECL
+  && (TREE_CODE (decl) == TYPE_DECL || VAR_P (decl))
   && i < ntparms - 1
   && template_parameter_pack_p (TREE_VALUE (parm))
   /* A fixed parameter pack will be partially
  instantiated into a fixed length list.  */
   && !fixed_parameter_pack_p (TREE_VALUE (parm)))
{
- /* A primary class template can only have one
+ /* A primary class template, primary variable template
+(DR 2032), or alias template can only have one
 parameter pack, at the end of the template
 parameter list.  */
 
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ67.C 
b/gcc/testsuite/g++.dg/cpp1y/var-templ67.C
new file mode 100644
index 000..f36af39bc19
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ67.C
@@ -0,0 +1,16 @@
+// DR 2032 - Default template-arguments of variable templates
+// PR c++/96218
+// { dg-do compile { target c++14 } }
+
+// [temp.param]/14: If a template-parameter of a class template, variable
+// template, or alias template has a default template-argument, each subsequent
+// template-parameter shall either have a default template-argument supplied or
+// be a template parameter pack.
+template
+T vt; // { dg-error "no default argument" }
+
+// [temp.param]/14: If a template-parameter of a primary class template,
+// primary variable template, or alias template is a template parameter pack,
+// it shall be the last template-parameter.
+template // { dg-error "must be at the end" }
+int vt2;

base-commit: 866c5bfd9c3ebc00913f3a84eb5383b51f2aee16
-- 
2.26.2



[committed,OG10] amdgcn: Support basic DWARF

2020-07-16 Thread Andrew Stubbs

On 29/06/2020 12:05, Andrew Stubbs wrote:
This patch configures the DWARF debug output to match the proposed DWARF 
specification from AMD.  This is already implemented in LLVM and rocgdb 
(out of tree).


This makes no attempt to support CFI, yet, and has some issues with 
vector registers. GCC will need to support some DWARF extensions to make 
those work properly (they're part of the AMD proposal).


This patch is now backported to devel/omp/gcc-10.

Andrew


[committed,OG10] amdgcn: Handle early debug info in mkoffload

2020-07-16 Thread Andrew Stubbs

On 16/07/2020 16:06, Andrew Stubbs wrote:
This patch adds debug support to mkoffload, similar to what happens in 
lto-wrapper.


Unlike lto-wrapper, we must deal with mismatched architectures and 
mismatched program scope. These are fixed up using manual ELF patching 
because there's no useful support in simple_object (yet). Should this be 
something that other offload targets want to do then that probably ought 
to be changed in future, but it isn't necessary yet.


This is enough to prevent rocgdb choking on malformed debug information 
and debug simple offload testcases; it may be that further adjustment is 
needed.


I have not attempted to make similar changes to the other instance of 
mkoffload as nvptx has no use for debug info.


This patch is now backported to devel/omp/gcc-10.

Andrew


[PATCH] coroutines: Correct frame capture of compiler temps [PR95591+4].

2020-07-16 Thread Iain Sandoe
Hello folks,

This is a patch correcting a thinko on my part which turns out to have
quite serious consequences for coroutines.

Sorry it took longer to clean up than I expected.

1/ I am sad that this is (too) late for 10.2 .. 
 .. my advice to distros would be to apply the patch to 10.2… I will certainly
   to that for Darwin.  coroutines is still behind -fcoroutines on 10.x, and the
   code changes are confined to coroutines.cc.

  So .. if there’s a respin .. I would definitely put this forward to add in 
(and
  for my 0.02GBP would probably add it anyway).

2/ it’s quite a large patch (sorry).

master tested on x86_64/powerpc64 Linux, x86_64-darwin

also the 10.2 back-port has been tested in the same configurations against 
10.2rc1.
needs  608832716e27ca356ee38d14ae30b3ab525884ea which is also
coro-specific.

OK for master?

OK for 10.x?
 
thanks,
Iain

* test cases as a text attachment, probably not interesting inline.

—— commit message.


When a full expression contains a co_await (or co_yield), this means
that it might be suspended; which would destroy temporary variables
(on a stack for example).  However the language guarantees that such
temporaries are live until the end of the expression.

In order to preserve this, we 'promote' temporaries where necessary
so that they are saved in the coroutine frame (which allows them to
remain live potentially until the frame is destroyed).  In addition,
sub-expressions that produce control flow (such as TRUTH_AND/OR_IF
or COND_EXPR) must be handled specifically to ensure that await
expressions are properly expanded.

This patch corrects two mistakes in which we were (a) failing to
promote some temporaries and (b) we we failing to sequence DTORs for
the captures properly. This manifests in a number of related (but not
exact duplicate) PRs.

The revised code collects the actions into one place and maps all the
control flow into one form - a benefit of this is that co_returns are
now expanded earlier (which provides an opportunity to address PR95517
in some future patch).

We replace a statement that contains await expression(s) with a bind
scope that has a variable list describing the temporaries that have
been 'promoted' and a statement list that contains a series of cleanup
expressions for each of those.  Where we encounter nested conditional
expressions, these are wrapped in a try-finally block with a guard var
for each sub-expression variable that needs a DTOR.  The guards are all
declared and initialized to false before the first conditional sub-
expression.  The 'finally' block contains a series of if blocks (one
per guard variable) enclosing the relevant DTOR.

Variables listed in a bind scope in this manner are automatically moved
to a coroutine frame version by existing code (so we re-use that rather
than having a separate mechanism).

gcc/cp/ChangeLog:

PR c++/95591
PR c++/95599
PR c++/95823
PR c++/95824
PR c++/95895
* coroutines.cc (struct coro_ret_data): Delete.
(coro_maybe_expand_co_return): Delete.
(co_return_expander): Delete.
(expand_co_returns): Delete.
(co_await_find_in_subtree): Remove unused name.
(build_actor_fn): Remove unused parm, remove handling
for co_return expansion.
(register_await_info): Demote duplicate info message to a
warning.
(coro_make_frame_entry): Move closer to use site.
(struct susp_frame_data): Add fields for final suspend label
and a flag to indicate await expressions with initializers.
(captures_temporary): Delete.
(register_awaits): Remove unused code, update comments.
(find_any_await): New.
(tmp_target_expr_p): New.
(struct interesting): New.
(find_interesting_subtree): New.
(struct var_nest_node): New.
(flatten_await_stmt): New.
(handle_nested_conditionals): New.
(process_conditional): New.
(replace_statement_captures): Rename to...
(maybe_promote_temps): ... this.
(maybe_promote_captured_temps): Delete.
(analyze_expression_awaits): Check for await expressions with
initializers.  Simplify handling for truth-and/or-if.
(expand_one_truth_if): Simplify (map cases that need expansion
to COND_EXPR).
(await_statement_walker): Handle CO_RETURN_EXPR. Simplify the
handling for truth-and/or-if expressions.
(register_local_var_uses): Ensure that we create names in the
implementation namespace.
(morph_fn_to_coro): Add final suspend label to suspend frame
callback data and remove it from the build_actor_fn call.

gcc/testsuite/ChangeLog:

PR c++/95591
PR c++/95599
PR c++/95823
PR c++/95824
PR c++/95895
* g++.dg/coroutines/pr95591.C: New test.
* g++.dg/coroutines/pr95599.C: New test.
* g++.dg/coroutines/pr95823.C: New test.
* g++.dg/coroutine

[committed] c++: Add test for DR 188.

2020-07-16 Thread Marek Polacek via Gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/testsuite/ChangeLog:

DR 188
* g++.dg/DRs/dr188.C: New test.
---
 gcc/testsuite/g++.dg/DRs/dr188.C | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/DRs/dr188.C

diff --git a/gcc/testsuite/g++.dg/DRs/dr188.C b/gcc/testsuite/g++.dg/DRs/dr188.C
new file mode 100644
index 000..f29a9eba1c9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr188.C
@@ -0,0 +1,7 @@
+// DR 188
+// { dg-do compile { target c++11 } }
+// From [diff.expr]p5.
+
+char arr[100];
+// Yields 100 in C++ and sizeof(char*) in C.
+static_assert (sizeof (0, arr) == 100, "");

base-commit: a4f49061b6d921f72b2faf4843144f3c75f828f7
-- 
2.26.2



[PATCH PR95696] regrename creates overlapping register allocations for vliw

2020-07-16 Thread zhongyunde via Gcc-patches
hi,   Insometarget,itislimitedtoissuetwoinsnstogetherwithchangethesameregister,so Imakeapatchtoextendtheliverangeuntiltheendofvliwtoavoidit.(Theinsn73startwithinsn:TI,soitwillbeissuedtogetherwithothersinsnsuntilanewinsnstartwithinsn:TI,suchasinsn71)TheregrenamecanknownthemodeV2VFininsn73needtwosuccessiveregisters,i.e.v2andv3,hereisdumpsnippetbeforetheregrename.(insn:TI7376714(set(reg/v:V2VF37v2[orig:180_62][180])(unspec:V2VF[(reg/v:VHF43v8[orig:210Dest_value][210])(reg/v:VHF43v8[orig:210Dest_value][210])]UNSPEC_HFSQMAG_32X32))"../test_modify.c":57710{hfsqmag_v2vf}(expr_list:REG_DEAD(reg/v:VHF43v8[orig:210Dest_value][210])(expr_list:REG_UNUSED(reg:VHF38v3)(expr_list:REG_STAGE(const_int2[0x2])(expr_list:REG_CYCLE(const_int2[0x2])(expr_list:REG_UNITS(const_int256[0x100])(nil)))(insn71732434(set(reg:VHF43v8[orig:265MEM[(constvfloat32x16*)Src_base_134]][265])(mem:VHF(reg/v/f:DI13a13[orig:207Src_base][207])[1MEM[(constvfloat32x16*)Src_base_134]+0S64A512]))"../test_modify.c":56450{movvhf_internal}(expr_list:REG_STAGE(const_int1[0x1])(expr_list:REG_CYCLE(const_int2[0x2])(nilThen,intheregrename,theinsn71willbetransformedintofollowingcodewithregisterv3,sothereisanconflictbetweeninsn73andinsn71,asbothofthemsetthev3register.Registerv2(2):73[SVEC_REGS]Registerv8(1):71[VEC_ALL_REGS](insn71732434(set(reg:VHF38v3[orig:265MEM[(constvfloat32x16*)Src_base_134]][265])(mem:VHF(reg/v/f:DI13a13[orig:207Src_base][207])[1MEM[(constvfloat32x16*)Src_base_134]+0S64A512]))"../test_modify.c":56450{movvhf_internal}(expr_list:REG_STAGE(const_int1[0x1]) (expr_list:REG_CYCLE(const_int2[0x2]) 随心邮-在微信里收发邮件,及时省电又安心

PR95696.patch
Description: Binary data


Re: [PATCH] coroutines: Correct frame capture of compiler temps [PR95591+4].

2020-07-16 Thread Nathan Sidwell

On 7/16/20 11:56 AM, Iain Sandoe wrote:

Hello folks,


It's unfortunate the original plan of handling lifetime issues in a 
gimple pass didn't work out.



OK for master?

OK for 10.x?


ok, some nits

+struct interesting
+{


not a very good name.  As it's not in an anonumous namespace, it has 
external linkage, and hence ripe for ODR breakage, if some other TU is 
interested about something else :)  Is there a more specific name it 
could have?




+  else if ((tmp_target_expr_p (expr)
+   && !p->temps_used->contains (expr)))


too many parens here.

nathan

--
Nathan Sidwell


[committed] i386: Additional peephole2 to use flags from CMPXCHG more [PR96189]

2020-07-16 Thread Uros Bizjak via Gcc-patches
CMPXCHG instruction sets ZF flag if the values in the destination operand
and EAX register are equal; otherwise the ZF flag is cleared and value
from destination operand is loaded to EAX. Following assembly:

xorl%eax, %eax
lock cmpxchgl   %edx, (%rdi)
testl   %eax, %eax
sete%al

can be optimized by removing the unneeded comparison, since set ZF flag
signals that no update to EAX happened.  This patch adds peephole2
pattern to also handle XOR zeroing and load of -1 by OR.

2020-07-16  Uroš Bizjak  

gcc/ChangeLog:
PR target/96189
* config/i386/sync.md
(peephole2 to remove unneded compare after CMPXCHG):
New pattern, also handle XOR zeroing and load of -1 by OR.

gcc/testsuite/ChangeLog:
PR target/96189
* gcc.target/i386/pr96189-1.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Uros.
diff --git a/gcc/config/i386/sync.md b/gcc/config/i386/sync.md
index d203e9d1ecb..e22109039c1 100644
--- a/gcc/config/i386/sync.md
+++ b/gcc/config/i386/sync.md
@@ -629,6 +629,40 @@
  (set (reg:CCZ FLAGS_REG)
   (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])])
 
+(define_peephole2
+  [(parallel [(set (match_operand:SWI48 0 "register_operand")
+  (match_operand:SWI48 1 "const_int_operand"))
+ (clobber (reg:CC FLAGS_REG))])
+   (parallel [(set (match_operand:SWI 2 "register_operand")
+  (unspec_volatile:SWI
+[(match_operand:SWI 3 "memory_operand")
+ (match_dup 2)
+ (match_operand:SWI 4 "register_operand")
+ (match_operand:SI 5 "const_int_operand")]
+UNSPECV_CMPXCHG))
+ (set (match_dup 3)
+  (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
+ (set (reg:CCZ FLAGS_REG)
+  (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])
+   (set (reg:CCZ FLAGS_REG)
+   (compare:CCZ (match_dup 2)
+(match_dup 1)))]
+  "REGNO (operands[0]) == REGNO (operands[2])"
+  [(parallel [(set (match_dup 0)
+  (match_dup 1))
+ (clobber (reg:CC FLAGS_REG))])
+   (parallel [(set (match_dup 2)
+  (unspec_volatile:SWI
+[(match_dup 3)
+ (match_dup 2)
+ (match_dup 4)
+ (match_dup 5)]
+UNSPECV_CMPXCHG))
+ (set (match_dup 3)
+  (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG))
+ (set (reg:CCZ FLAGS_REG)
+  (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG))])])
+
 ;; For operand 2 nonmemory_operand predicate is used instead of
 ;; register_operand to allow combiner to better optimize atomic
 ;; additions of constants.


Re: [PATCH] testsuite/rs6000: Add option to ignore vect cost model

2020-07-16 Thread Segher Boessenkool
Hi!

On Thu, Jul 16, 2020 at 02:51:23PM +0800, Kewen.Lin wrote:
> In my testing with cost tweaking for vector with length, I found
> two cases below didn't get the expected output.  Since the expected
> instructions reply on the vectorization occurrence, we don't expect
> vectorization gets disabled by cost model.
> 
> To make it not fragile, the fix is to force it without vect cost model.

>From the subject it wasn't clear to me that you just add the flag (not
implement a new option :-) ), and only to two testcases.  Maybe
  rs6000/test: Add -fno-vect-cost-model to conv-vectorize-[12].c
or even
  rs6000/test: Add -fno-vect-cost-model to some tests


Okay for trunk.  Thanks!


Segher


Re: [PATCH] coroutines: Correct frame capture of compiler temps [PR95591+4].

2020-07-16 Thread Iain Sandoe

Nathan Sidwell  wrote:


On 7/16/20 11:56 AM, Iain Sandoe wrote:


It's unfortunate the original plan of handling lifetime issues in a  
gimple pass didn't work out.


I’ve revisited this (on balance every couple of months, I suppose when it  
gets tricky doing
something in the FE).  However, it seems to me that the complexity is  
inherent and all we

would do is to punt that from the FE into the ME.

for example, on the limited tests I made with coro suspend point lowering  
delayed until post
LTO, I ran into issues with loads of pointers to the promise getting  
hoisted out of loops with
suspend points.  Of course, everything is probably fixable - and there’s an  
existing impl that
defers the frame consruction to the ME (noting that there's a comment from  
the authors there

saying that they do end up with some unnecessary frame entries).

some things are easier to analyze in tree-land and some things are def.  
easier when the

code has been flattened.

There’s at least one optimisation of the size of the coroutine frame that I  
think would be
much more difficult (maybe impossible, depending on what information has  
been discarded)

later in the pipeline.

so .. my current estimate remains that it would be “six of one, half a  
dozen of the other”.



+struct interesting
+{


not a very good name.  As it's not in an anonumous namespace, it has  
external linkage, and hence ripe for ODR breakage, if some other TU is  
interested about something else :)  Is there a more specific name it  
could have?

changed to ‘coro_interesting_subtree’.


+  else if ((tmp_target_expr_p (expr)
+   && !p->temps_used->contains (expr)))


too many parens here.

thanks, fixed
pushed to master.
Iain

* for master (at least on Darwin):
  we now get 100% pass on cppcoro
  and 99% on folly  (one expected fail, one to be analyzed).



Re: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts

2020-07-16 Thread Julian Brown
On Thu, 16 Jul 2020 11:35:23 +0200
Thomas Schwinge  wrote:

> Hi Julian!
> 
> Ping.
> 
> On 2020-06-26T11:20:40+0200, I wrote:
> > On 2019-12-17T22:03:47-0800, Julian Brown 
> > wrote:  
> >> This part contains the libgomp runtime support for the
> >> GOMP_MAP_ATTACH and GOMP_MAP_DETACH mapping kinds (etc.), as
> >> introduced by the front-end patches following in this series.  
> >  
> >> --- a/libgomp/target.c
> >> +++ b/libgomp/target.c  
> >  
> >> @@ -1534,6 +1571,18 @@ gomp_unmap_vars_internal (struct
> >> target_mem_desc *tgt, bool do_copyfrom,  
> >
> > This is the code path at the end of a structured OpenACC 'data'
> > construct.
> >  
> >> +  /* We must perform detachments before any copies back to the
> >> host.  */
> >> +  for (i = 0; i < tgt->list_count; i++)
> >> +{
> >> +  splay_tree_key k = tgt->list[i].key;
> >> +
> >> +  if (k != NULL && tgt->list[i].do_detach)
> >> +  gomp_detach_pointer (devicep, aq, k,
> >> tgt->list[i].key->host_start
> >> +   +
> >> tgt->list[i].offset,
> >> +   k->refcount == 1, NULL);
> >> +}  
> >
> > Can you please explain (as a source code comment) the logic for here
> > using 'k->refcount == 1' for the 'bool finalize' parameter of
> > 'gomp_detach_pointer'; this somehow feels "strange"?
[snip]
> > Shouldn't this just always be 'finalize = false' given that there
> > is no 'finalize' semantics for 'detach' on a structured OpenACC
> > 'data' constructs -- at least that's what I remember right now?  

As far as I can tell, forcing finalize there is unnecessary (and as you
point out, conceptually dubious), but I think in practice it's
harmless (at least I haven't figured out a breaking test case). Anyway,
this patch just passes "false" for the finalize argument. I've also
added a test case, though it passes before/after the patch.

OK? Tested with offloading to nvptx.

Julian
>From 31618a79bb3aa0d088030904fff0ad386ddb0999 Mon Sep 17 00:00:00 2001
From: Julian Brown 
Date: Thu, 2 Jul 2020 14:18:20 -0700
Subject: [PATCH] openacc: Remove unnecessary detach finalization

The call to gomp_detach_pointer in gomp_unmap_vars_internal does not
need to force finalization, and doing so may mask mismatched pointer
attachments/detachments. This patch removes the forcing.

2020-07-16  Julian Brown  

libgomp/
	* target.c (gomp_unmap_vars_internal): Remove unnecessary forcing of
	finalization for detach operation.
	* testsuite/libgomp.oacc-c-c++-common/structured-detach-underflow.c:
	New test.
---
 libgomp/target.c  |  2 +-
 .../structured-detach-underflow.c | 24 +++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/structured-detach-underflow.c

diff --git a/libgomp/target.c b/libgomp/target.c
index d6b3572c8d8..00c75fbd885 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1437,7 +1437,7 @@ gomp_unmap_vars_internal (struct target_mem_desc *tgt, bool do_copyfrom,
   if (k != NULL && tgt->list[i].do_detach)
 	gomp_detach_pointer (devicep, aq, k, tgt->list[i].key->host_start
 	 + tgt->list[i].offset,
-			 k->refcount == 1, NULL);
+			 false, NULL);
 }
 
   for (i = 0; i < tgt->list_count; i++)
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/structured-detach-underflow.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/structured-detach-underflow.c
new file mode 100644
index 000..184410137d8
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/structured-detach-underflow.c
@@ -0,0 +1,24 @@
+/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
+
+int main ()
+{
+  struct {
+int *arr;
+  } mystr;
+  int localarr[16];
+  mystr.arr = localarr;
+
+  #pragma acc enter data copyin(mystr, localarr[0:16])
+
+  #pragma acc data copyin(mystr.arr[0:16])
+  {
+#pragma acc exit data detach(mystr.arr)
+/* { dg-output "libgomp: attach count underflow" } */
+  }
+
+  #pragma acc exit data copyout(mystr, localarr[0:16])
+
+  return 0;
+}
+
+/* { dg-shouldfail "" } */
-- 
2.23.0



[PATCH v3] sparc/sparc64: use crtendS.o for default-pie executables [PR96190]

2020-07-16 Thread Sergei Trofimovich via Gcc-patches
From: Sergei Trofimovich 

In --enable-default-pie mode compiler should switch from
using crtend.o to crtendS.o. On sparc it is especially important
because crtend.o contains PIC-unfriendly code.

We use GNU_USER_TARGET_ENDFILE_SPEC as a baseline spec to get
crtendS.o instead of crtend.o in !no-pie mode.

gcc:

2020-07-14  Sergei Trofimovich  

PR target/96190
* config/sparc/linux.h (ENDFILE_SPEC): Use GNU_USER_TARGET_ENDFILE_SPEC
to get crtendS.o for !no-pie mode.
* config/sparc/linux64.h (ENDFILE_SPEC): Ditto.
---
 gcc/config/sparc/linux.h   | 10 ++
 gcc/config/sparc/linux64.h | 10 ++
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h
index 81201e67a2f..63853e60c03 100644
--- a/gcc/config/sparc/linux.h
+++ b/gcc/config/sparc/linux.h
@@ -27,16 +27,10 @@ along with GCC; see the file COPYING3.  If not see
 }  \
   while (0)
 
-/* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
-   the GNU/Linux magical crtend.o file (see crtstuff.c) which
-   provides part of the support for getting C++ file-scope static
-   object constructed before entering `main', followed by a normal
-   GNU/Linux "finalizer" file, `crtn.o'.  */
-
 #undef  ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
-   %{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  GNU_USER_TARGET_ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* -mcpu=native handling only makes sense with compiler running on
a SPARC chip.  */
diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h
index a1a0efd8f28..19ce84d7adb 100644
--- a/gcc/config/sparc/linux64.h
+++ b/gcc/config/sparc/linux64.h
@@ -44,16 +44,10 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_CPU64_DEFAULT_SPEC
 #define ASM_CPU64_DEFAULT_SPEC "-Av9a"
 
-/* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
-   the GNU/Linux magical crtend.o file (see crtstuff.c) which
-   provides part of the support for getting C++ file-scope static
-   object constructed before entering `main', followed by a normal
-   GNU/Linux "finalizer" file, `crtn.o'.  */
-
 #undef ENDFILE_SPEC
 #define ENDFILE_SPEC \
-  "%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s\
-   %{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
+  GNU_USER_TARGET_ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}"
 
 /* The default code model.  */
 #undef SPARC_DEFAULT_CMODEL
-- 
2.27.0



Re: [PATCH v2] sparc/sparc64: use crtendS.o for default-pie executables [PR96190]

2020-07-16 Thread Sergei Trofimovich via Gcc-patches
On Wed, 15 Jul 2020 13:46:12 +0200
Eric Botcazou  wrote:

> > This should be:
> > 
> > PR target/96190
> > * config/sparc/linux.h (ENDFILE_SPEC): Use GNU_USER_TARGET_ENDFILE_SPEC
> > to get crtendS.o for !no-pie mode.
> > * config/sparc/linux64.h(ENDFILE_SPEC): Ditto.  
> 
>   * config/sparc/linux64.h (ENDFILE_SPEC): Ditto.
> 
> > OK for mainline with this change.  You can also put it on the 10 branch
> > after the 10.1 release is out if this is deemed necessary.  
> 
> 10.2

Oh! Sent out v3 with tweaked description as
https://gcc.gnu.org/pipermail/gcc-patches/2020-July/550168.html

I don't have a push access to gcc tree. Should I request one via
https://sourceware.org/cgi-bin/pdw/ps_form.cgi ?

-- 

  Sergei


Re: [PATCH] config/debuginfod.m4: Use PKG_CHECK_MODULES

2020-07-16 Thread Aaron Merey via Gcc-patches
Hi Tom,

Sorry for the delay, I've modified the patch to include config/pkg.m4.

Aaron


Use PKG_CHECK_MODULES to set debuginfod autoconf vars. Also add
pkg.m4 to config/.

ChangeLog:

* config/debuginfod.m4: use PKG_CHECK_MODULES.
* config/pkg.m4: New file.
* configure: Rebuild.
* configure.ac: Remove AC_DEBUGINFOD.

ChangeLog/binutils:

* Makefile.am: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
* Makefile.in: Rebuild.
* configure: Rebuild.
* configure.ac: Include pkg.m4.
* doc/Makefile.in: Rebuild.

ChangeLog/gdb:

* Makefile.in: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
* configure: Rebuild.
* configure.ac: Include pkg.m4.
---
 ChangeLog|   7 +
 binutils/ChangeLog   |   8 +
 binutils/Makefile.am |   6 +-
 binutils/Makefile.in |  12 +-
 binutils/configure   | 369 ---
 binutils/configure.ac|   1 +
 binutils/doc/Makefile.in |   8 +-
 config/debuginfod.m4 |  36 ++--
 config/pkg.m4| 275 +
 configure| 139 +--
 configure.ac |   4 -
 gdb/ChangeLog|   6 +
 gdb/Makefile.in  |   2 +-
 gdb/configure| 365 +++---
 gdb/configure.ac |   3 +-
 15 files changed, 858 insertions(+), 383 deletions(-)
 create mode 100644 config/pkg.m4

diff --git a/ChangeLog b/ChangeLog
index 49e9cf6148..e3a248c5fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-07-16  Aaron Merey  
+
+   * config/debuginfod.m4: use PKG_CHECK_MODULES.
+   * config/pkg.m4: New file.
+   * configure: Rebuild.
+   * configure.ac: Remove AC_DEBUGINFOD.
+
 2020-07-04  Nick Clifton  
 
Binutils 2.35 branch created.
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 708be22cfd..679b22f1f9 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,11 @@
+2020-07-16  Aaron Merey  
+
+   * Makefile.am: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
+   * Makefile.in: Rebuild.
+   * configure: Rebuild.
+   * configure.ac: Include pkg.m4.
+   * doc/Makefile.in: Rebuild.
+
 2020-07-14  Claudiu Zissulescu  
 
* testsuite/binutils-all/arc/double_regs.s: New test.
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index 2ee1196790..fb54653fd3 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -53,7 +53,7 @@ AM_CFLAGS = $(WARN_CFLAGS) $(ZLIBINC)
 AM_CFLAGS_FOR_BUILD = $(WARN_CFLAGS_FOR_BUILD) $(ZLIBINC)
 LIBICONV = @LIBICONV@
 
-LIBDEBUGINFOD = @LIBDEBUGINFOD@
+DEBUGINFOD_LIBS = @DEBUGINFOD_LIBS@
 
 # these two are almost the same program
 AR_PROG=ar
@@ -252,7 +252,7 @@ objcopy_SOURCES = objcopy.c not-strip.c rename.c 
$(WRITE_DEBUG_SRCS) $(BULIBS)
 strings_SOURCES = strings.c $(BULIBS)
 
 readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c $(ELFLIBS)
-readelf_LDADD   = $(LIBINTL) $(LIBCTF_NOBFD) $(LIBIBERTY) $(ZLIB) 
$(LIBDEBUGINFOD)
+readelf_LDADD   = $(LIBINTL) $(LIBCTF_NOBFD) $(LIBIBERTY) $(ZLIB) 
$(DEBUGINFOD_LIBS)
 
 elfedit_SOURCES = elfedit.c version.c $(ELFLIBS)
 elfedit_LDADD = $(LIBINTL) $(LIBIBERTY)
@@ -263,7 +263,7 @@ nm_new_SOURCES = nm.c $(BULIBS)
 
 objdump_SOURCES = objdump.c dwarf.c prdbg.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS)
 EXTRA_objdump_SOURCES = od-xcoff.c
-objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) 
$(LIBIBERTY) $(LIBINTL) $(LIBDEBUGINFOD)
+objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) 
$(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS)
 
 objdump.@OBJEXT@:objdump.c
 if am__fastdepCC
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index 7ef2af4aff..951dd2c6d0 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -139,7 +139,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
$(top_srcdir)/../config/zlib.m4 $(top_srcdir)/../libtool.m4 \
$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-   $(top_srcdir)/../bfd/version.m4 \
+   $(top_srcdir)/../bfd/version.m4 $(top_srcdir)/../config/pkg.m4 \
$(top_srcdir)/../config/debuginfod.m4 \
$(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -423,6 +423,8 @@ CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DATADIRNAME = @DATADIRNAME@
+DEBUGINFOD_CFLAGS = @DEBUGINFOD_CFLAGS@
+DEBUGINFOD_LIBS = @DEBUGINFOD_LIBS@
 DEFS = @DEFS@
 DEMANGLER_NAME = @DEMANGLER_NAME@
 DEPDIR = @DEPDIR@
@@ -454,7 +456,6 @@ LDFLAGS = @LDFLAGS@
 LEX = `if [ -f ../flex/flex ]; then echo ../flex/flex; else echo @LEX@; fi`
 LEXLIB = @LEXLIB@
 LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
-LIBDEBUGINFOD = @LIBDEBUGINFOD@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBINTL_DEP = @LIBINTL_DEP@
@@ -490,6 +491,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
 PACKAGE_URL = @PACKAGE_

Re: [PATCH] config/debuginfod.m4: Use PKG_CHECK_MODULES

2020-07-16 Thread Aaron Merey via Gcc-patches
On Fri, May 8, 2020 at 4:56 PM Tom Tromey  wrote:
>
> > "Aaron" == Aaron Merey via Binutils  writes:
>
> Aaron> * Makefile.in: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
> Aaron> * aclocal.m4: Rebuild.
>
> Instead of inlining pkg.m4 into aclocal.m4, how about making
> config/pkg.m4 and then using m4_include from gdb/acinclude.m4?
> That's what gdb does for other shared m4 code.

Resending the patch for this since my last attempt didn't seem to
properly reply to
Tom's email.
From 7a7ea339a9f1ba879eb0f29ab68cbcb715d11391 Mon Sep 17 00:00:00 2001
From: Aaron Merey 
Date: Thu, 16 Jul 2020 16:02:43 -0400
Subject: [PATCH] config/debuginfod.m4: Use PKG_CHECK_MODULES

Use PKG_CHECK_MODULES to set debuginfod autoconf vars. Also add
pkg.m4 to config/.

ChangeLog:

	* config/debuginfod.m4: use PKG_CHECK_MODULES.
	* config/pkg.m4: New file.
	* configure: Rebuild.
	* configure.ac: Remove AC_DEBUGINFOD.

ChangeLog/binutils:

	* Makefile.am: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
	* Makefile.in: Rebuild.
	* configure: Rebuild.
	* configure.ac: Include pkg.m4.
	* doc/Makefile.in: Rebuild.

ChangeLog/gdb:

	* Makefile.in: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
	* configure: Rebuild.
	* configure.ac: Include pkg.m4.
---
 ChangeLog|   7 +
 binutils/ChangeLog   |   8 +
 binutils/Makefile.am |   6 +-
 binutils/Makefile.in |  12 +-
 binutils/configure   | 369 ---
 binutils/configure.ac|   1 +
 binutils/doc/Makefile.in |   8 +-
 config/debuginfod.m4 |  36 ++--
 config/pkg.m4| 275 +
 configure| 139 +--
 configure.ac |   4 -
 gdb/ChangeLog|   6 +
 gdb/Makefile.in  |   2 +-
 gdb/configure| 365 +++---
 gdb/configure.ac |   3 +-
 15 files changed, 858 insertions(+), 383 deletions(-)
 create mode 100644 config/pkg.m4

diff --git a/ChangeLog b/ChangeLog
index 49e9cf6148..e3a248c5fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-07-16  Aaron Merey  
+
+	* config/debuginfod.m4: use PKG_CHECK_MODULES.
+	* config/pkg.m4: New file.
+	* configure: Rebuild.
+	* configure.ac: Remove AC_DEBUGINFOD.
+
 2020-07-04  Nick Clifton  
 
 	Binutils 2.35 branch created.
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 708be22cfd..679b22f1f9 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,11 @@
+2020-07-16  Aaron Merey  
+
+	* Makefile.am: Replace LIBDEBUGINFOD with DEBUGINFOD_LIBS.
+	* Makefile.in: Rebuild.
+	* configure: Rebuild.
+	* configure.ac: Include pkg.m4.
+	* doc/Makefile.in: Rebuild.
+
 2020-07-14  Claudiu Zissulescu  
 
 	* testsuite/binutils-all/arc/double_regs.s: New test.
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index 2ee1196790..fb54653fd3 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -53,7 +53,7 @@ AM_CFLAGS = $(WARN_CFLAGS) $(ZLIBINC)
 AM_CFLAGS_FOR_BUILD = $(WARN_CFLAGS_FOR_BUILD) $(ZLIBINC)
 LIBICONV = @LIBICONV@
 
-LIBDEBUGINFOD = @LIBDEBUGINFOD@
+DEBUGINFOD_LIBS = @DEBUGINFOD_LIBS@
 
 # these two are almost the same program
 AR_PROG=ar
@@ -252,7 +252,7 @@ objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
 strings_SOURCES = strings.c $(BULIBS)
 
 readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c $(ELFLIBS)
-readelf_LDADD   = $(LIBINTL) $(LIBCTF_NOBFD) $(LIBIBERTY) $(ZLIB) $(LIBDEBUGINFOD)
+readelf_LDADD   = $(LIBINTL) $(LIBCTF_NOBFD) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS)
 
 elfedit_SOURCES = elfedit.c version.c $(ELFLIBS)
 elfedit_LDADD = $(LIBINTL) $(LIBIBERTY)
@@ -263,7 +263,7 @@ nm_new_SOURCES = nm.c $(BULIBS)
 
 objdump_SOURCES = objdump.c dwarf.c prdbg.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS)
 EXTRA_objdump_SOURCES = od-xcoff.c
-objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(LIBDEBUGINFOD)
+objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS)
 
 objdump.@OBJEXT@:objdump.c
 if am__fastdepCC
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index 7ef2af4aff..951dd2c6d0 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -139,7 +139,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
 	$(top_srcdir)/../config/zlib.m4 $(top_srcdir)/../libtool.m4 \
 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-	$(top_srcdir)/../bfd/version.m4 \
+	$(top_srcdir)/../bfd/version.m4 $(top_srcdir)/../config/pkg.m4 \
 	$(top_srcdir)/../config/debuginfod.m4 \
 	$(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -423,6 +423,8 @@ CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DATADIRNAME = @DATADIRNAME@
+DEBUGINFOD_CFLAGS = @DEBUGINFOD_CFLAGS@
+DEBUGINFOD_LIBS = @DEBUGINFOD_LIBS@
 DEFS = @DEFS@
 DEMANGLE

[PING][PATCH] improve validation of attribute arguments (PR c/78666)

2020-07-16 Thread Martin Sebor via Gcc-patches

Ping: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549686.html

(Jeff, I forgot to mention this patch when we spoke earlier today.)

On 7/8/20 6:01 PM, Martin Sebor wrote:

GCC has gotten better at detecting conflicts between various
attributes but it still doesn't do a perfect job of detecting
similar problems due to mismatches between contradictory
arguments to the same attribute.  For example,

   __attribute ((alloc_size (1))) void* allocate (size_t, size_t);

followed by

   __attribute ((alloc_size (2))) void* allocate (size_t, size_t);

is accepted with the former overriding the latter in calls to
the function.  Similar problem exists with a few other attributes
that take arguments.

The attached change adds a new utility function that checks for
such mismatches and issues warnings.  It also adds calls to it
to detect the problem in attributes alloc_align, alloc_size, and
section.  This isn't meant to be a comprehensive fix but rather
a starting point for one.

Tested on x86_64-linux.

Martin

PS I ran into this again while debugging some unrelated changes
and wondering about the behavior in similar situations to mine.
Since the behavior seemed clearly suboptimal I figured I might
as well fix it.

PPS The improved checking triggers warnings in a few calls to
__builtin_has_attribute due to apparent conflicts.  I've xfailed
those in the test since it's a known issue with some existing
attributes that should be fixed at some point.  Valid uses of
the built-in shouldn't trigger diagnostics except for completely
nonsensical arguments.  Unfortunately, the line between valid
and completely nonsensical is a blurry one (GCC either issues
errors, or -Wattributes, or silently ignores some cases
altogether, such as those that are the subject of this patch)
and there is no internal mechanism to control the response.




Re: RFA: Fix combine.c combining a move and a non-move into two non-moves, PR93372

2020-07-16 Thread Segher Boessenkool
On Tue, Jul 14, 2020 at 04:33:42PM -0500, Segher Boessenkool wrote:
> > If combine only did lower-cost combinations (perhaps with
> > Richard Sandifords lower-size-when-tied suggestion), I guess
> > this wouldn't happen. 0:-)
> 
> And we would regress (a LOT).

Like this.  C0 is an unmodified compiler.  C1 is with the single_set
modification to is_just_move I committed a minute ago (84c5396d4bdb).
C2 is with this patch:

-- 8< --
diff --git a/gcc/combine.c b/gcc/combine.c
index 3a81bb6..619ba77 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -939,7 +939,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, rtx_insn 
 
   /* Disallow this combination if both new_cost and old_cost are greater than
  zero, and new_cost is greater than old cost.  */
-  int reject = old_cost > 0 && new_cost > old_cost;
+  int reject = old_cost > 0 && new_cost >= old_cost;
 
   if (dump_file)
 {
-- 8< --

[segher@gcc135 buildall]$ perl sizes.pl --percent C[012]
C0C1C2
   alpha   6045560  100.000%  100.518%
 arc   3529016  100.000%   99.933%
 arm  14173370  100.000%  101.607%
   arm64  12958466  100.000%  100.477%
 c6x   2341205  100.000%  100.154%
csky   3320386  100.000%  100.838%
   h8300   1163584  100.000%  100.331%
i386 0 0 0
ia64  18079744  100.000%  100.857%
m68k   3711195  100.000%  100.327%
  microblaze   4930937  100.000%  100.054%
mips   8403293  100.000%  100.049%
  mips64   6975860  100.000%   99.986%
   nds32   4450951  100.000%   99.992%
   nios2   3641733  100.000%  100.206%
openrisc   4182260  100.000%  100.025%
  parisc   7706299  100.000%  101.500%
parisc64   8677365  100.000%  101.491%
 powerpc  10016575  100.000%  100.001%
   powerpc64  17331518  100.000%   99.974%
 powerpc64le  17331518  100.000%   99.974%
 riscv32 0 0 0
 riscv64 0 0 0
s390  13091897  100.000%  100.396%
  sh   3213207  100.000%  100.031%
 shnommu   1610444  100.000%  100.031%
   sparc   4356641  100.000%  101.521%
 sparc64   6745123  100.000%  101.450%
  x86_64  19663507  100.000%  100.007%
  xtensa   2105610  100.000%  100.425%


Segher


[PATCH] combine: Use single_set for is_just_move

2020-07-16 Thread Segher Boessenkool
Since we now only call is_just_move on the original instructions, we
always have an rtx_insn* (not just a pattern), so we can use single_set
on it.  This makes no detectable difference at all on all thirty Linux
targets I test, but it does help cris, and it is simpler, cleaner code
anyway.

Tested on powerpc64-linux {-m32,-m64}.  Committed.


Segher


2020-07-16  Hans-Peter Nilsson  
Segher Boessenkool  

PR target/93372
* combine.c (is_just_move): Take an rtx_insn* as argument.  Use
single_set on it.
---
 gcc/combine.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/gcc/combine.c b/gcc/combine.c
index b044f29..4fee114 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -2624,15 +2624,16 @@ can_split_parallel_of_n_reg_sets (rtx_insn *insn, int n)
   return true;
 }
 
-/* Return whether X is just a single set, with the source
+/* Return whether X is just a single_set, with the source
a general_operand.  */
 static bool
-is_just_move (rtx x)
+is_just_move (rtx_insn *x)
 {
-  if (INSN_P (x))
-x = PATTERN (x);
+  rtx set = single_set (x);
+  if (!set)
+return false;
 
-  return (GET_CODE (x) == SET && general_operand (SET_SRC (x), VOIDmode));
+  return general_operand (SET_SRC (set), VOIDmode);
 }
 
 /* Callback function to count autoincs.  */
-- 
1.8.3.1



Re: [PATCH] testsuite/rs6000: Add option to ignore vect cost model

2020-07-16 Thread Kewen.Lin via Gcc-patches
Hi,

on 2020/7/17 上午4:31, Segher Boessenkool wrote:
> Hi!
> 
> On Thu, Jul 16, 2020 at 02:51:23PM +0800, Kewen.Lin wrote:
>> In my testing with cost tweaking for vector with length, I found
>> two cases below didn't get the expected output.  Since the expected
>> instructions reply on the vectorization occurrence, we don't expect
>> vectorization gets disabled by cost model.
>>
>> To make it not fragile, the fix is to force it without vect cost model.
> 
> From the subject it wasn't clear to me that you just add the flag (not
> implement a new option :-) ), and only to two testcases.  Maybe
>   rs6000/test: Add -fno-vect-cost-model to conv-vectorize-[12].c

Oh my poor naming skills ;-)  Will fix it with this.

> or even
>   rs6000/test: Add -fno-vect-cost-model to some tests
> 
> 
> Okay for trunk.  Thanks!

Thanks!
Kewen


[PATCH] Add support for dynamic shadow offset

2020-07-16 Thread Harshit Sharma via Gcc-patches
Hi all,

This patch adds support for dynamic shadow offset in ASan stack
instrumentation. It is required by Kernel Address Sanitizer in cases where
the shadow offset address is not known at compile-time as the shadow buffer
may not be allocated during the early boot stages.

I used a callback function __asan_shadow_offset() to allow GCC to determine
the shadow offset at runtime. This option is intended to be triggered by
-fsanitize=kernel-address and can be enabled using --param
asan-use-shadow-offset-callback=1.

I've been working on adding ASan feature to coreboot which is a free
software project aimed at replacing the proprietary BIOS (firmware) found
in most computers. We had a requirement for the dynamic shadow offset
option, so we came up with a GCC patch. You can have a look at the change
at https://review.coreboot.org/c/coreboot/+/42794/13.

I know many people have expressed a desire for dynamic shadow offset in GCC
and this feature is already available in Clang, enabled using -mllvm
-asan-force-dynamic-shadow=true flag. So, I thought it would be a useful
feature to have in the upcoming GCC version.


Thanks,
Harshit

--

Add support for using a callback function to fetch shadow offset address
instead of the fixed value defined at compile-time. This feature is enabled
by setting --param asan-use-shadow-offset-callback=1.

2020-07-16Harshit Sharma

gcc/
* asan.c: Use callback function instead of static shadow offset
* params.opt: Define new parameter

---
 gcc/asan.c | 29 ++---
 gcc/params.opt |  4 
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/gcc/asan.c b/gcc/asan.c
index 9c9aa4cae35..4870f0a0947 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1525,13 +1525,28 @@ asan_emit_stack_protection (rtx base, rtx pbase,
unsigned int alignb,
   TREE_ASM_WRITTEN (decl) = 1;
   TREE_ASM_WRITTEN (id) = 1;
   emit_move_insn (mem, expand_normal (build_fold_addr_expr (decl)));
-  shadow_base = expand_binop (Pmode, lshr_optab, base,
-  gen_int_shift_amount (Pmode, ASAN_SHADOW_SHIFT),
-  NULL_RTX, 1, OPTAB_DIRECT);
-  shadow_base
-= plus_constant (Pmode, shadow_base,
- asan_shadow_offset ()
- + (base_align_bias >> ASAN_SHADOW_SHIFT));
+  if (param_asan_use_shadow_offset_callback) {
+rtx addr, shadow_offset_rtx;
+ret = init_one_libfunc("__asan_shadow_offset");
+addr= convert_memory_address(ptr_mode, base);
+ret = emit_library_call_value(ret, NULL_RTX, LCT_NORMAL, ptr_mode,
+  addr, ptr_mode);
+shadow_offset_rtx = convert_memory_address(Pmode, ret);
+shadow_base = expand_binop (Pmode, lshr_optab, base,
+  gen_int_shift_amount (Pmode, ASAN_SHADOW_SHIFT),
+  NULL_RTX, 1, OPTAB_DIRECT);
+shadow_base = expand_binop (Pmode, add_optab, shadow_base,
+  shadow_offset_rtx, NULL_RTX, 1, OPTAB_LIB_WIDEN);
+shadow_base = plus_constant (Pmode, shadow_base,
+(base_align_bias >> ASAN_SHADOW_SHIFT));
+  } else {
+shadow_base = expand_binop (Pmode, lshr_optab, base,
+  gen_int_shift_amount (Pmode, ASAN_SHADOW_SHIFT),
+  NULL_RTX, 1, OPTAB_DIRECT);
+shadow_base = plus_constant (Pmode, shadow_base,
+asan_shadow_offset ()
++ (base_align_bias >> ASAN_SHADOW_SHIFT));
+  }
   gcc_assert (asan_shadow_set != -1
   && (ASAN_RED_ZONE_SIZE >> ASAN_SHADOW_SHIFT) == 4);
   shadow_mem = gen_rtx_MEM (SImode, shadow_base);
diff --git a/gcc/params.opt b/gcc/params.opt
index e29a44e7712..5fcf9e7f432 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -50,6 +50,10 @@ Enable asan store operations protection.
 Common Joined UInteger Var(param_asan_instrumentation_with_call_threshold)
Init(7000) Param Optimization
 Use callbacks instead of inline code if number of accesses in function
becomes greater or equal to this number.

+-param=asan-use-shadow-offset-callback=
+Common Joined UInteger Var(param_asan_use_shadow_offset_callback) Init(0)
Param Optimization
+Use shadow offset callback function at runtime instead of fixed value at
compile time at the cost of runtime overhead.
+
 -param=asan-memintrin=
 Common Joined UInteger Var(param_asan_memintrin) Init(1) IntegerRange(0,
1) Param Optimization
 Enable asan builtin functions protection.
-- 
2.17.1


Re: [PATCH] x86: Rename VF_AVX512VL_VF1_128_256 to VF1_AVX512ER_128_256

2020-07-16 Thread H.J. Lu via Gcc-patches
On Mon, Jul 13, 2020 at 9:12 AM H.J. Lu  wrote:
>
> On Thu, Jul 9, 2020 at 6:35 AM H.J. Lu  wrote:
> >
> > On Thu, Jul 9, 2020 at 5:04 AM Kirill Yukhin  
> > wrote:
> > >
> > > On 07 июл 09:06, H.J. Lu wrote:
> > > > On Tue, Jul 7, 2020 at 8:56 AM Kirill Yukhin  
> > > > wrote:
> > > > >
> > > > > Hello HJ,
> > > > >
> > > > > On 28 июн 07:19, H.J. Lu via Gcc-patches wrote:
> > > > > > Enable FMA in rsqrt2 expander and fold rsqrtv16sf2 expander 
> > > > > > into
> > > > > > rsqrt2 expander which expands to UNSPEC_RSQRT28 for 
> > > > > > TARGET_AVX512ER.
> > > > > > Although it doesn't show performance change in our workloads, FMA 
> > > > > > can
> > > > > > improve other workloads.
> > > > > >
> > > > > > gcc/
> > > > > >
> > > > > >   PR target/88713
> > > > > >   * config/i386/i386-expand.c (ix86_emit_swsqrtsf): Enable FMA.
> > > > > >   * config/i386/sse.md (VF_AVX512VL_VF1_128_256): New.
> > > > > >   (rsqrt2): Replace VF1_128_256 with 
> > > > > > VF_AVX512VL_VF1_128_256.
> > > > > >   (rsqrtv16sf2): Removed.
> > > > > >
> > > > > > gcc/testsuite/
> > > > > >
> > > > > >   PR target/88713
> > > > > >   * gcc.target/i386/pr88713-1.c: New test.
> > > > > >   * gcc.target/i386/pr88713-2.c: Likewise.
> > > > >
> > > > > So, you've introduced new rsqrt expanders for DF vectors and relaxed
> > > > > condition for V16SF. What I didn't get is why did you change unspec
> > > > > type from RSQRT to RSQRT28 for V16SF expander?
> > > > >
> > > >
> > > > UNSPEC in define_expand is meaningless when the pattern is fully
> > > > expanded by ix86_emit_swsqrtsf.  I believe that UNSPEC in rsqrt2
> > > > expander can be removed.
> > >
> > > Agree.
> >
> > I will leave UNSPEC alone here.
> >
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/i386/pr88713-1.c
> > > @@ -0,0 +1,13 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-O2 -Ofast -mno-avx512f -mfma" } */
> > >
> > > I gues -O2 is useless here (and in -2.c test).
> >
> > Fixed.
> >
> > > Othwerwise LGTM.
> > >
> >
> > This is the patch I am checking in.
> >
>
> Since ix86_emit_swsqrtsf shouldn't be called with DF vector modes, rename
> VF_AVX512VL_VF1_128_256 to VF1_AVX512ER_128_256 and drop DF vector modes.
>

I will check in this patch to fix the regression next Monday if there
are objections.

Thanks.

-- 
H.J.


Re: [PATCH 3/4] libstdc++: Add floating-point std::to_chars implementation

2020-07-16 Thread Patrick Palka via Gcc-patches
On Wed, 15 Jul 2020, Patrick Palka wrote:

> On Tue, 14 Jul 2020, Patrick Palka wrote:
> 
> > This implements the floating-point std::to_chars overloads for float,
> > double and long double.  We use the Ryu library to compute the shortest
> > round-trippable fixed and scientific forms of a number for float, double
> > and long double.  We also use Ryu for performing fixed and scientific
> > formatting of float and double. For formatting long double with an
> > explicit precision argument we use a printf fallback.  Hexadecimal
> > formatting for float, double and long double is implemented from
> > scratch.
> > 
> > The supported long double binary formats are float64 (same as double),
> > float80 (x86 extended precision), float128 and ibm128.
> > 
> > Much of the complexity of the implementation is in computing the exact
> > output length before handing it off to Ryu (which doesn't do bounds
> > checking).  In some cases it's hard to compute the output length before
> > the fact, so in these cases we instead compute an upper bound on the
> > output length and use a sufficiently-sized intermediate buffer (if the
> > output range is smaller than the upper bound).
> > 
> > Another source of complexity is in the general-with-precision formatting
> > mode, where we need to do zero-trimming of the string returned by Ryu, and
> > where we also take care to avoid having to format the string a second
> > time when the general formatting mode resolves to fixed.
> > 
> > Tested on x86_64-pc-linux-gnu, aarch64-unknown-linux-gnu,
> > s390x-ibm-linux-gnu, and powerpc64-unknown-linux-gnu.
> > 
> > libstdc++-v3/ChangeLog:
> > 
> > * acinclude.m4 (libtool_VERSION): Bump to 6:29:0.
> > * config/abi/pre/gnu.ver: Add new exports.
> > * configure: Regenerate.
> > * include/std/charconv (to_chars): Declare the floating-point
> > overloads for float, double and long double.
> > * src/c++17/Makefile.am (sources): Add floating_to_chars.cc.
> > * src/c++17/Makefile.in: Regenerate.
> > * src/c++17/floating_to_chars.cc: New file.
> > * testsuite/20_util/to_chars/long_double.cc: New test.
> > * testsuite/util/testsuite_abi.cc: Add new symbol version.
> 
> Here is v2 of this patch, which fixes a build failure on i386 due to
> __int128 being unavailable, by refactoring the long double binary format
> selection to avoid referring to __int128 when it doesn't exist.  The
> patch also makes the hex formatting for 80-bit long double use uint64_t
> instead of __int128 since the mantissa has exactly 64 bits in this case.

Here's v3 which just makes some minor stylistic adjustments, and most
notably replaces the use of _GLIBCXX_DEBUG with _GLIBCXX_ASSERTIONS
since we just want to enable __glibcxx_assert and not all of debug mode.

-- >8 --

Subject: [PATCH 3/4] libstdc++: Add floating-point std::to_chars
 implementation

This implements the floating-point std::to_chars overloads for float,
double and long double.  We use the Ryu library to compute the shortest
round-trippable fixed and scientific forms of a number for float, double
and long double.  We also use Ryu for performing explicit-precision
fixed and scientific formatting of float and double. For
explicit-precision formatting of long double we fall back to using
printf.  Hexadecimal formatting for float, double and long double is
implemented from scratch.

The supported long double binary formats are binary64, binary80 (x86
80-bit extended precision), binary128 and ibm128.

Much of the complexity of the implementation is in computing the exact
output length before handing it off to Ryu (which doesn't do bounds
checking).  In some cases it's hard to compute the output length
beforehand, so in these cases we instead compute an upper bound on the
output length and use a sufficiently-sized intermediate buffer if
necessary.

Another source of complexity is in the general-with-precision formatting
mode, where we need to do zero-trimming of the string returned by Ryu,
and where we also take care to avoid having to format the string a
second time when the general formatting mode resolves to fixed.

This implementation is non-conforming in a couple of ways:

1. For the shortest hexadecimal formatting, we currently follow the
   Microsoft implementation's approach of being consistent with the
   output of printf's '%a' specifier at the expense of sometimes not
   printing the shortest representation.  For example, the shortest hex
   form of 1.08p+0 is 2.1p-1, but we output the former instead of the
   latter, as does printf.

2. The Ryu routines for doing shortest formatting on types larger than
   binary64 use the __int128 type, and some targets (e.g. i386) have a
   large long double type but lack __int128.  For these targets we make
   the long double to_chars overloads go through the double overloads,
   which means we lose precision in the output.  (The mantissa of long
   double is 64 bits on i386, so I think we could potentially fix this
   by writ

Re: [PATCH] Add TARGET_LOWER_LOCAL_DECL_ALIGNMENT [PR95237]

2020-07-16 Thread Sunil Pandey via Gcc-patches
Any comment on revised patch? At least,  in finish_decl, decl global
attributes are populated.

On Tue, Jul 14, 2020 at 8:37 AM Sunil Pandey  wrote:

> On Sat, Jul 4, 2020 at 9:11 AM Richard Biener
>  wrote:
> >
> > On July 3, 2020 11:16:46 PM GMT+02:00, Jason Merrill 
> wrote:
> > >On 6/29/20 5:00 AM, Richard Biener wrote:
> > >> On Fri, Jun 26, 2020 at 10:11 PM H.J. Lu  wrote:
> > >>>
> > >>> On Thu, Jun 25, 2020 at 1:10 AM Richard Biener
> > >>>  wrote:
> > 
> >  On Thu, Jun 25, 2020 at 2:53 AM Sunil Pandey 
> > >wrote:
> > >
> > > On Wed, Jun 24, 2020 at 12:30 AM Richard Biener
> > >  wrote:
> > >>
> > >> On Tue, Jun 23, 2020 at 5:31 PM Sunil K Pandey via Gcc-patches
> > >>  wrote:
> > >>>
> > >>> From: Sunil K Pandey 
> > >>>
> > >>> Default for this hook is NOP. For x86, in 32 bit mode, this hook
> > >>> sets alignment of long long on stack to 32 bits if preferred
> > >stack
> > >>> boundary is 32 bits.
> > >>>
> > >>>   - This patch fixes
> > >>>  gcc.target/i386/pr69454-2.c
> > >>>  gcc.target/i386/stackalign/longlong-1.c
> > >>>   - Regression test on x86-64, no new fail introduced.
> > >>
> > >> I think the name is badly chosen,
> > >TARGET_LOWER_LOCAL_DECL_ALIGNMENT
> > >
> > > Yes, I can change the target hook name.
> > >
> > >> would be better suited (and then asks for LOCAL_DECL_ALIGNMENT to
> > >be
> > >> renamed to INCREASE_LOCAL_DECL_ALIGNMENT).
> > >
> > > It seems like LOCAL_DECL_ALIGNMENT macro documentation is
> > >incorrect.
> > > It increases as well as decreases alignment based on
> > >condition(-m32
> > > -mpreferred-stack-boundary=2)
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95885
> > >
> > >>
> > >> You're calling it from do_type_align which IMHO is dangerous
> > >since that's
> > >> invoked from FIELD_DECL layout as well.  Instead invoke it from
> > >> layout_decl itself where we do
> > >>
> > >>if (code != FIELD_DECL)
> > >>  /* For non-fields, update the alignment from the type.  */
> > >>  do_type_align (type, decl);
> > >>
> > >> and invoke the hook _after_ do_type_align.  Also avoid
> > >> invoking the hook on globals or hard regs and only
> > >> invoke it on VAR_DECLs, thus only
> > >>
> > >>if (VAR_P (decl) && !is_global_var (decl) &&
> > >!DECL_HARD_REGISTER (decl))
> > >
> > > It seems like decl property is not fully populated at this point
> > >call
> > > to is_global_var (decl) on global variable return false.
> > >
> > > $ cat foo.c
> > > long long x;
> > > int main()
> > > {
> > > if (__alignof__(x) != 8)
> > >__builtin_abort();
> > > return 0;
> > > }
> > >
> > > Breakpoint 1, layout_decl (decl=0x77ffbb40, known_align=0)
> > >  at /local/skpandey/gccwork/gccwork/gcc/gcc/stor-layout.c:674
> > > 674 do_type_align (type, decl);
> > > Missing separate debuginfos, use: dnf debuginfo-install
> > > gmp-6.1.2-10.fc31.x86_64 isl-0.16.1-9.fc31.x86_64
> > > libmpc-1.1.0-4.fc31.x86_64 mpfr-3.1.6-5.fc31.x86_64
> > > zlib-1.2.11-20.fc31.x86_64
> > > (gdb) call debug_tree(decl)
> > >> >  type  > >  size 
> > >  unit-size 
> > >  align:64 warn_if_not_align:0 symtab:0 alias-set -1
> > > canonical-type 0x7fffea801888 precision:64 min  > > 0x7fffea7e8fd8 -9223372036854775808> max  > >0x7fffea806000
> > > 9223372036854775807>
> > >  pointer_to_this >
> > >  DI foo.c:1:11 size  unit-size
> > > 
> > >  align:1 warn_if_not_align:0>
> > >
> > > (gdb) p is_global_var(decl)
> > > $1 = false
> > > (gdb)
> > >
> > >
> > > What about calling hook here
> > >
> > >   603 do_type_align (tree type, tree decl)
> > >   604 {
> > >   605   if (TYPE_ALIGN (type) > DECL_ALIGN (decl))
> > >   606 {
> > >   607   SET_DECL_ALIGN (decl, TYPE_ALIGN (type));
> > >   608   if (TREE_CODE (decl) == FIELD_DECL)
> > >   609 DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
> > >   610   else
> > >   611 /* Lower local decl alignment */
> > >   612 if (VAR_P (decl)
> > >   613 && !is_global_var (decl)
> > >   614 && !DECL_HARD_REGISTER (decl)
> > >   615 && cfun != NULL)
> > >   616   targetm.lower_local_decl_alignment (decl);
> > >   617 }
> > 
> >  But that doesn't change anything (obviously).  layout_decl
> >  is called quite early, too early it looks like.
> > 
> >  Now there doesn't seem to be any other good place where
> >  we are sure to catch the decl before we evaluate things
> >  like __alignof__
> > 
> >  void __attribute__((noipa))
> >  foo (__SIZE_TYPE__ align, long long *p

Re: [PATCH] Enable GCC support for AMX

2020-07-16 Thread Hongyu Wang via Gcc-patches
Update for SAPPHIRERAPIDS and PING

Hongyu Wang  于2020年7月7日周二 上午11:24写道:

>
> Hi Kirill, could you help review this patch?
>
> Hongyu Wang  于2020年7月6日周一 上午9:58写道:
> >
> > Hi:
> >
> > This patch is about to support Intel Advanced Matrix Extensions (AMX)
> > which will be enabled in GLC.
> >
> > AMX is a new 64-bit programming paradigm consisting of two
> > compo nents: a set of 2-dimensional registers (tiles) representing
> > sub-arrays from a larger 2-dimensional memory image,
> > and an accelerator able to operate on tiles
> >
> > Supported instructions are
> >
> > AMX-TILE:ldtilecfg/sttilecfg/tileloadd/tileloaddt1/tilezero/tilerelease
> > AMX-INT8:tdpbssd/tdpbsud/tdpbusd/tdpbuud
> > AMX-BF16:tdpbf16ps
> >
> > The intrinsics adopts constant tile register number as its input parameters.
> >
> > For detailed information, please refer to
> > https://software.intel.com/content/dam/develop/public/us/en/documents/architecture-instruction-set-extensions-programming-reference.pdf
> >
> > Bootstrap ok, regression test on i386/x86 backend is ok.
> >
> > OK for master?
> >
> > gcc/ChangeLog
> >
> > * common/config/i386/i386-common.c (OPTION_MASK_ISA2_AMX_TILE_SET,
> > OPTION_MASK_ISA2_AMX_INT8_SET, OPTION_MASK_ISA2_AMX_BF16_SET,
> > OPTION_MASK_ISA2_AMX_TILE_UNSET,
> > OPTION_MASK_ISA2_AMX_INT8_UNSET, OPTION_MASK_ISA2_AMX_BF16_UNSET):
> > New marcos.
> > (ix86_handle_option): Hanlde -mamx-tile, -mamx-int8, -mamx-bf16.
> > * common/config/i386/i386-cpuinfo.h (processor_types): Add
> > FEATURE_AMX_TILE, FEATURE_AMX_INT8, FEATURE_AMX_BF16.
> > * common/config/i386/cpuinfo.h (XSTATE_TILECFG,
> > XSTATE_TILEDATA, XCR_AMX_ENABLED_MASK): New macro.
> > (get_available_features): Enable AMX features only if
> > their states are suoorited by OSXSAVE.
> > * common/config/i386/i386-isas.h: Add ISA_NAME_TABLE_ENTRY
> > for amx-tile, amx-int8, amx-bf16.
> > * config.gcc: Add amxtileintrin.h, amxint8intrin.h,
> > amxbf16intrin.h to extra headers.
> > * config/i386/amxbf16intrin.h: New file.
> > * config/i386/amxint8intrin.h: Ditto.
> > * config/i386/amxtileintrin.h: Ditto.
> > * config/i386/cpuid.h (bit_AMX_BF16, bit_AMX_TILE, bit_AMX_INT8):
> > New macro.
> > * config/i386/i386-c.c (ix86_target_macros_internal): Define
> > __AMX_TILE__, __AMX_INT8__, AMX_BF16__.
> > * config/i386/i386-options.c (ix86_target_string): Add
> > -mamx-tile, -mamx-int8, -mamx-bf16.
> > (ix86_option_override_internal): Handle AMX-TILE,
> > AMX-INT8, AMX-BF16.
> > * config/i386/i386.h (TARGET_AMX_TILE, TARGET_AMX_TILE_P,
> > TARGET_AMX_INT8, TARGET_AMX_INT8_P, TARGET_AMX_BF16_P,
> > PTA_AMX_TILE, PTA_AMX_INT8, PTA_AMX_BF16): New macros.
> > * config/i386/i386.opt: Add -mamx-tile, -mamx-int8, -mamx-bf16.
> > * config/i386/immintrin.h: Include amxtileintrin.h,
> > amxint8intrin.h, amxbf16intrin.h.
> > * doc/invoke.texi: Document -mamx-tile, -mamx-int8, -mamx-bf16.
> > * doc/extend.texi: Document amx-tile, amx-int8, amx-bf16.
> > * doc/sourcebuild.texi ((Effective-Target Keywords, Other
> > hardware attributes): Document amx_int8, amx_tile, amx_bf16.
> >
> > gcc/testsuite/ChangeLog
> >
> > * lib/target-supports.exp (check_effective_target_amx_tile,
> > check_effective_target_amx_int8,
> > check_effective_target_amx_bf16): New proc.
> > * g++.dg/other/i386-2.C: Add -mamx-tile, -mamx-int8, -mamx-bf16.
> > * g++.dg/other/i386-3.C: Ditto.
> > * gcc.target/i386/sse-12.c: Ditto.
> > * gcc.target/i386/sse-13.c: Ditto.
> > * gcc.target/i386/sse-14.c: Ditto.
> > * gcc.target/i386/sse-22.c: Ditto.
> > * gcc.target/i386/sse-23.c: Ditto.
> > * gcc.target/i386/funcspec-56.inc: Add new target attribute.
> > * gcc.target/i386/amxbf16-asmatt-1.c: New test.
> > * gcc.target/i386/amxint8-asmatt-1.c: Ditto.
> > * gcc.target/i386/amxtile-asmatt-1.c: Ditto.
> > * gcc.target/i386/amxbf16-asmintel-1.c: Ditto.
> > * gcc.target/i386/amxint8-asmintel-1.c: Ditto.
> > * gcc.target/i386/amxtile-asmintel-1.c: Ditto.
> > * gcc.target/i386/amxbf16-asmatt-2.c: Ditto.
> > * gcc.target/i386/amxint8-asmatt-2.c: Ditto.
> > * gcc.target/i386/amxtile-asmatt-2.c: Ditto.
> > * gcc.target/i386/amxbf16-asmintel-2.c: Ditto.
> > * gcc.target/i386/amxint8-asmintel-2.c: Ditto.
> > * gcc.target/i386/amxtile-asmintel-2.c: Ditto.
From c56e576233be156fc6d172a968c3838f6102155d Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Thu, 25 Jul 2019 16:49:36 +0800
Subject: [PATCH] Enable GCC support for AMX-TILE,AMX-INT8,AMX-BF16.

AMX-TILE:ldtilecfg/sttilecfg/tileloadd/tileloaddt1/tilezero/tilerelease
AMX-INT8:tdpbssd/tdpbsud/tdpbusd/tdpbuud
AMX-BF16:tdpbf16ps

gcc/ChangeLog

	* common/config/i386/i386-common.c (OPTION_MASK_ISA2_AMX_TILE_SET,
	OPTION_MASK_ISA2_AMX_INT8_SET, OPTION_MASK_ISA2_AMX_BF16_SET,
	OPTION_MASK_ISA2_AMX_TILE_UNSET,
	OPTION_MASK_ISA2_AMX_INT8_UNSET, OPTION_MAS

Re: [committed] amdgcn: Handle early debug info in mkoffload

2020-07-16 Thread Thomas Schwinge
Hi Andrew!

On 2020-07-16T16:06:49+0100, Andrew Stubbs  wrote:
> This patch adds debug support to mkoffload, similar to what happens in
> lto-wrapper.

Ah, good, it's not as invasive/convoluted as I'd assumed from the verbal
description you'd given.

> Unlike lto-wrapper, we must deal with mismatched architectures and
> mismatched program scope. These are fixed up using manual ELF patching
> because there's no useful support in simple_object (yet). Should this be
> something that other offload targets want to do then that probably ought
> to be changed in future, but it isn't necessary yet.

ACK.

> This is enough to prevent rocgdb choking on malformed debug information
> and debug simple offload testcases

:-)

> it may be that further adjustment is
> needed.
>
> I have not attempted to make similar changes to the other instance of
> mkoffload

ACK.

> as nvptx has no use for debug info.

Specifically, nvptx only supports 'DWARF2_LINENO_DEBUGGING_INFO' (and
that's mostly untested, too).

> --- a/gcc/config/gcn/mkoffload.c
> +++ b/gcc/config/gcn/mkoffload.c
> @@ -33,31 +33,53 @@
>  #include 
>  #include "collect-utils.h"
>  #include "gomp-constants.h"
> +#include "simple-object.h"
> +#include "elf.h"
> +
> +/* These probably won't be in elf.h for a while.  */
> +#ifndef EM_AMDGPU

Nope, it already is.  ;-P

> +#define EM_AMDGPU0xe0;
> +
> +#define ELFOSABI_AMDGPU_HSA   64
> +#define ELFABIVERSION_AMDGPU_HSA 1
> +
> +#define EF_AMDGPU_MACH_AMDGCN_GFX803 0x2a
> +#define EF_AMDGPU_MACH_AMDGCN_GFX900 0x2c
> +#define EF_AMDGPU_MACH_AMDGCN_GFX906 0x2f
> +
> +#define R_AMDGPU_NONE0
> +#define R_AMDGPU_ABS32_LO1   /* (S + A) & 0x  */
> +#define R_AMDGPU_ABS32_HI2   /* (S + A) >> 32  */
> +#define R_AMDGPU_ABS64   3   /* S + A  */
> +#define R_AMDGPU_REL32   4   /* S + A - P  */
> +#define R_AMDGPU_REL64   5   /* S + A - P  */
> +#define R_AMDGPU_ABS32   6   /* S + A  */
> +#define R_AMDGPU_GOTPCREL7   /* G + GOT + A - P  */
> +#define R_AMDGPU_GOTPCREL32_LO   8   /* (G + GOT + A - P) & 
> 0x  */
> +#define R_AMDGPU_GOTPCREL32_HI   9   /* (G + GOT + A - P) >> 32  */
> +#define R_AMDGPU_REL32_LO10  /* (S + A - P) & 0x  */
> +#define R_AMDGPU_REL32_HI11  /* (S + A - P) >> 32  */
> +#define reserved 12

(That's not a useful '#define reserved'?)

> +#define R_AMDGPU_RELATIVE64  13  /* B + A  */
> +#endif

The standard Ubuntu 18.04 '/usr/include/elf.h' as shipped by package
libc6-dev:amd64 in version 2.27-3ubuntu1 contains:

$ grep -n AMDGPU < /usr/include/elf.h
358:#define EM_AMDGPU   224 /* AMD GPU */

..., and thus:

[...]/source-gcc/gcc/config/gcn/mkoffload.c:72:21: error: 
'EF_AMDGPU_MACH_AMDGCN_GFX803' was not declared in this scope
 uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803;  // Default GPU 
architecture.
 ^
[...]/source-gcc/gcc/config/gcn/mkoffload.c: In function 'bool 
copy_early_debug_info(const char*, const char*)':
[...]/source-gcc/gcc/config/gcn/mkoffload.c:290:21: error: 
'ELFOSABI_AMDGPU_HSA' was not declared in this scope
   ehdr.e_ident[7] = ELFOSABI_AMDGPU_HSA;
 ^
[...]/source-gcc/gcc/config/gcn/mkoffload.c:291:21: error: 
'ELFABIVERSION_AMDGPU_HSA' was not declared in this scope
   ehdr.e_ident[8] = ELFABIVERSION_AMDGPU_HSA;
 ^
[...]/source-gcc/gcc/config/gcn/mkoffload.c:334:24: error: 'R_AMDGPU_ABS32' 
was not declared in this scope
reloc->r_info = R_AMDGPU_ABS32;
^
[...]

I've got the canary 'EM_AMDGPU', but not the other '#define's.


> -/* Files to unlink.  */
> -static const char *gcn_s1_name;
> -static const char *gcn_s2_name;
> -static const char *gcn_o_name;
> -static const char *gcn_cfile_name;
>  static const char *gcn_dumpbase;
> +static struct obstack files_to_cleanup;

(Good idea; should do similar in the other 'mkoffload's.)


> +uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX803;  // Default GPU 
> architecture.

For easier later maintenance, shouldn't this be a '#define' (or similar)
done next to where the GCC back end defines its default?


Grüße
 Thomas


>  /* Delete tempfiles.  */
>
>  void
>  tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
>  {
> -  if (gcn_cfile_name)
> -maybe_unlink (gcn_cfile_name);
> -  if (gcn_s1_name)
> -maybe_unlink (gcn_s1_name);
> -  if (gcn_s2_name)
> -maybe_unlink (gcn_s2_name);
> -  if (gcn_o_name)
> -maybe_unlink (gcn_o_name);
> +  obstack_ptr_grow (&files_to_cleanup, NULL);
> +  const char **files = XOBFINISH (&files_to_cleanup, const char **);
> +  for (int i = 0; files[i]; i++)
> +maybe_unlink (files[i]);
>  }
>
>  static void
> @@ -204,6 +226,180 @@ access_check (const char *name, int mode)
>return access (name, mode);
>  }
>
> +/* Copy the early-debug-info from the incoming L