Re: [PATCH] aarch64: Introduce --param=aarch64-autovec-preference to select autovec preference in backend

2020-11-27 Thread Richard Biener via Gcc-patches
On Thu, Nov 26, 2020 at 6:18 PM Kyrylo Tkachov via Gcc-patches
 wrote:
>
> Hi all,
>
> This is a patch that introduces the aarch64-autovec-preference that can take 
> values from 0 - 4, 0 being the default.
> It can be used to override the autovectorisation preferences in the backend:
> 0 - use default scheme
> 1 - only use Advanced SIMD
> 2 - only use SVE
> 3 - use Advanced SIMD and SVE, prefer Advanced SIMD in the event of a tie (as 
> determined by costs)
> 4 - use Advanced SIMD and SVE, prefer SVE in the event of a tie (as 
> determined by costs)
>
> It can valuable for experimentation when comparing SVE and Advanced SIMD 
> autovectorisation strategies.
>
> It achieves this adjusting the order of the interleaved SVE and Advanced SIMD 
> modes in aarch64_autovectorize_vector_modes.
> It also adjusts aarch64_preferred_simd_mode to use the new comparison 
> function to pick Advanced SIMD or SVE to start with.
>
> Bootstrapped and tested on aarch64-none-linux-gnu.
> Ok for master (since it touches much SVE-related code by Richard I'd feel 
> more comfortable with a second pair of eyes)?

Is this supposed to be used internally or for development purposes?
If users are supposed
to use this then a -m switch would be more appropriate (x86 for example has
-mprefer-vector-width)

Richard.

> Thanks,
> Kyrill
>
> gcc/
> * config/aarch64/aarch64.opt (-param=aarch64-autovec-preference): 
> Define.
> * config/aarch64/aarch64.c (aarch64_override_options_internal):
> Set aarch64_sve_compare_costs to 0 when preferring only Advanced SIMD.
> (aarch64_cmp_autovec_modes): Define.
> (aarch64_preferred_simd_mode): Adjust to use the above.
> (aarch64_autovectorize_vector_modes): Likewise.
> * doc/invoke.texi: Document aarch64-autovec-preference param.


Re: [PATCH] aarch64: Introduce --param=aarch64-autovec-preference to select autovec preference in backend

2020-11-27 Thread Richard Sandiford via Gcc-patches
Richard Biener  writes:
> On Thu, Nov 26, 2020 at 6:18 PM Kyrylo Tkachov via Gcc-patches
>  wrote:
>>
>> Hi all,
>>
>> This is a patch that introduces the aarch64-autovec-preference that can take 
>> values from 0 - 4, 0 being the default.
>> It can be used to override the autovectorisation preferences in the backend:
>> 0 - use default scheme
>> 1 - only use Advanced SIMD
>> 2 - only use SVE
>> 3 - use Advanced SIMD and SVE, prefer Advanced SIMD in the event of a tie 
>> (as determined by costs)
>> 4 - use Advanced SIMD and SVE, prefer SVE in the event of a tie (as 
>> determined by costs)
>>
>> It can valuable for experimentation when comparing SVE and Advanced SIMD 
>> autovectorisation strategies.
>>
>> It achieves this adjusting the order of the interleaved SVE and Advanced 
>> SIMD modes in aarch64_autovectorize_vector_modes.
>> It also adjusts aarch64_preferred_simd_mode to use the new comparison 
>> function to pick Advanced SIMD or SVE to start with.
>>
>> Bootstrapped and tested on aarch64-none-linux-gnu.
>> Ok for master (since it touches much SVE-related code by Richard I'd feel 
>> more comfortable with a second pair of eyes)?

LGTM.

> Is this supposed to be used internally or for development purposes?
> If users are supposed
> to use this then a -m switch would be more appropriate (x86 for example has
> -mprefer-vector-width)

I think it's more production vs. experimentation rather than developer
vs. user.  Users shouldn't have to worry about this kind of thing when
they're doing production builds: specifying -mcpu or -mtune should
be enough to get the right behaviour.  But having a --param like this
that we can point users at is useful for getting feedback or as an
interim workaround until an optimisation bug is fixed.  And like you
say, it's also useful for running experiments for development.

Thanks,
Richard


Re: [committed] libstdc++: Use __libc_single_threaded for locale initialization

2020-11-27 Thread Stephan Bergmann via Gcc-patches

On 24/11/2020 15:59, Jonathan Wakely via Gcc-patches wrote:

Most initialization of locales and facets happens before main() during
startup, when the program is likely to only have one thread. By using
the new __gnu_cxx::__is_single_threaded() function instead of checking
__gthread_active_p() we can avoid using pthread_once or atomics for the
common case.

That said, I'm not sure why we don't just use a local static variable
instead, as __cxa_guard_acquire() already optimizes for the
single-threaded case:

   static const bool init = (_S_initialize_once(), true);

I'll revisit that for GCC 12.

libstdc++-v3/ChangeLog:

* src/c++98/locale.cc (locale::facet::_S_get_c_locale())
(locale::id::_M_id() const): Use __is_single_threaded.
* src/c++98/locale_init.cc (locale::_S_initialize()):
Likewise.

Tested powerpc64le-linux. Committed to trunk.


I now started to get weird crashes when running LibreOffice test code at 
least with Clang -fsanitize=address and latest libstdc++, where the 
Clang ASan machinery SEGVs while it wants to report some malloc/free 
issue.  That goes away when reverting this commit, and I think the root 
cause is that locale::facet::_S_initialize_once() now gets called twice: 
 First during __cxx_global_var_init when the process is still single 
threaded (so


  if (!__gnu_cxx::__is_single_threaded())

in locale::facet::_S_get_c_locale, reading __libc_single_threaded, is 
false, whereas


  if (__gthread_active_p())

would have been true even if the process still only had a single 
thread).  And again after the process has spawned further threads via 
pthread_create (flipping __libc_single_threaded) and calls 
std::ostringstream() -> ... std::locale() -> ..., at which point


  if (!__gnu_cxx::__is_single_threaded())

in locale::facet::_S_get_c_locale is true now.



[Ada] Fix oversignt in genericized package System.Value_R

2020-11-27 Thread Pierre-Marie de Rodat
Pragma Annotate for CodePeer must immediately follow the designated line.

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

gcc/ada/

* libgnat/s-valuer.adb (Scan_Raw_Real): Move pragma Annotate around
and adjust its parameters.diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -428,10 +428,10 @@ package body System.Value_R is
   --  First character can be either a decimal digit or a dot
 
   if Str (Index) in '0' .. '9' then
- After_Point := False;
-
  pragma Annotate
-   (CodePeer, Intentional, "test always true", "defensive code below");
+   (CodePeer, False_Positive, "test always true", "defensive code");
+
+ After_Point := False;
 
  --  If this is a digit it can indicates either the float decimal
  --  part or the base to use.




[Ada] Error in Big_Real comparison

2020-11-27 Thread Pierre-Marie de Rodat
The code would incorrectly compare using absolute values, which was a
left over for another implementation incorrectly carried over.

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

gcc/ada/

* libgnat/a-nbnbre.adb ("=", "<"): Fix.diff --git a/gcc/ada/libgnat/a-nbnbre.adb b/gcc/ada/libgnat/a-nbnbre.adb
--- a/gcc/ada/libgnat/a-nbnbre.adb
+++ b/gcc/ada/libgnat/a-nbnbre.adb
@@ -29,8 +29,6 @@
 --  --
 --
 
---  This is the default version of this package, based on Big_Integers only.
-
 with Ada.Strings.Text_Output.Utils;
 with System.Img_Real; use System.Img_Real;
 
@@ -85,14 +83,16 @@ package body Ada.Numerics.Big_Numbers.Big_Reals is
-
 
function "=" (L, R : Valid_Big_Real) return Boolean is
- (abs L.Num = abs R.Num and then L.Den = R.Den);
+ (L.Num = R.Num and then L.Den = R.Den);
 
-
-- "<" --
-
 
function "<" (L, R : Valid_Big_Real) return Boolean is
- (abs L.Num * R.Den < abs R.Num * L.Den);
+ (L.Num * R.Den < R.Num * L.Den);
+   --  The denominator is guaranteed to be positive since Normalized is
+   --  always called when constructing a Valid_Big_Real
 
--
-- "<=" --




[Ada] Emit error messages for null/generic nonreturning procedures

2020-11-27 Thread Pierre-Marie de Rodat
This commit adds checks for rule 6.5.1 4/3 of the Ada RM which declares
nonreturning procedures and nonreturning generic procedure instances
illegal.

The reason this check is performed in sem_prag.adb rather than in
Check_Returns in sem_ch6.adb is that generic procedure instances won't
have their No_Return flag set yet when Check_Returns is called.

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

gcc/ada/

* sem_prag.adb (Analyze_Pragma): declare new Check_No_Return
function and call it.diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -19670,7 +19670,59 @@ package body Sem_Prag is
 
  --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
 
- when Pragma_No_Return => No_Return : declare
+ when Pragma_No_Return => Prag_No_Return : declare
+
+function Check_No_Return
+   (E : Entity_Id;
+N : Node_Id) return Boolean;
+--  Check rule 6.5.1 4/3 of the Ada Ref Manual. If the rule is
+--  violated, emit an error message and return False, otherwise
+--  return True.
+--  6.5.1 Nonreturning procedures:
+--  4/3 "Aspect No_Return shall not be specified for a null
+--  procedure nor an instance of a generic unit."
+
+-
+-- Check_No_Return --
+-
+
+function Check_No_Return
+   (E : Entity_Id;
+N : Node_Id) return Boolean
+is
+   Ok : Boolean := True;
+begin
+   if Ekind (E) = E_Procedure then
+
+  --  If E is a generic instance, marking it with No_Return is
+  --  forbidden, but having it inherit the No_Return of the
+  --  generic is allowed. We check if E is inheriting its
+  --  No_Return flag from the generic by checking if No_Return
+  --  is already set.
+
+  if Is_Generic_Instance (E) and then not No_Return (E) then
+ Error_Msg_NE
+   ("generic instance & is marked as No_Return", N, E);
+ Error_Msg_NE
+   ("\generic procedure & must be marked No_Return",
+N,
+Generic_Parent (Parent (E)));
+ Ok := False;
+
+  else
+ if Null_Present (Subprogram_Specification (E)) then
+Error_Msg_NE
+  ("null procedure & cannot be marked No_Return",
+   N,
+   E);
+Ok := False;
+ end if;
+  end if;
+   end if;
+
+   return Ok;
+end Check_No_Return;
+
 Arg   : Node_Id;
 E : Entity_Id;
 Found : Boolean;
@@ -19742,7 +19794,9 @@ package body Sem_Prag is
 end if;
  end if;
 
- Set_No_Return (E);
+ if Check_No_Return (E, N) then
+Set_No_Return (E);
+ end if;
 
  --  A pragma that applies to a Ghost entity becomes Ghost
  --  for the purposes of legality checks and removal of
@@ -19781,7 +19835,10 @@ package body Sem_Prag is
 
  --  Set flag on any alias as well
 
- if Is_Overloadable (E) and then Present (Alias (E)) then
+ if Is_Overloadable (E)
+   and then Present (Alias (E))
+   and then Check_No_Return (Alias (E), N)
+ then
 Set_No_Return (Alias (E));
  end if;
 
@@ -19798,6 +19855,7 @@ package body Sem_Prag is
if not Found then
   if Entity (Id) = Current_Scope
 and then From_Aspect_Specification (N)
+and then Check_No_Return (Entity (Id), N)
   then
  Set_No_Return (Entity (Id));
 
@@ -19812,7 +19870,7 @@ package body Sem_Prag is
 
Next (Arg);
 end loop;
- end No_Return;
+ end Prag_No_Return;
 
  -
  -- No_Run_Time --




[Ada] Small tweaks to new implementation of Set_Image_Fixed

2020-11-27 Thread Pierre-Marie de Rodat
This removes a use of the absolute value that could potentially fail
the overflow check and add assertions guarding a second use and the
manipulation of string buffers, the latter for the sake of CodePeer.

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

gcc/ada/

* libgnat/s-imagef.adb (Set_Image_Fixed): Pass the full value
of the quotient to Set_Image_Integer during the first round and
adjust the handling of the minus sign.diff --git a/gcc/ada/libgnat/s-imagef.adb b/gcc/ada/libgnat/s-imagef.adb
--- a/gcc/ada/libgnat/s-imagef.adb
+++ b/gcc/ada/libgnat/s-imagef.adb
@@ -208,15 +208,15 @@ package body System.Image_F is
   --  Number of rounds of scaled divide to be performed
 
   Q : Int;
-  --  Quotient of the scaled divide in this round. Only the first round
-  --  may yield more than Maxdigs digits. The sign is not significant.
+  --  Quotient of the scaled divide in this round. Only the first round may
+  --  yield more than Maxdigs digits and has a significant sign.
 
   Buf : String (1 .. Maxdigs);
   Len : Natural;
   --  Buffer for the image of the quotient
 
-  Digs  : String (1 .. N * Maxdigs + 1);
-  Ndigs : Natural := 0;
+  Digs  : String (1 .. 2 + N * Maxdigs);
+  Ndigs : Natural;
   --  Concatenated image of the successive quotients
 
   Scale : Integer := 0;
@@ -227,10 +227,14 @@ package body System.Image_F is
   --  First two operands of the scaled divide
 
begin
-  --  Set the first character like Image, either minus or space
+  --  Set the first character like Image
 
-  Digs (1) := (if V < 0 then '-' else ' ');
-  Ndigs := 1;
+  if V >= 0 then
+ Digs (1) := ' ';
+ Ndigs := 1;
+  else
+ Ndigs := 0;
+  end if;
 
   for J in 1 .. N loop
  exit when XX = 0;
@@ -239,7 +243,7 @@ package body System.Image_F is
 
  if J = 1 then
 if Q /= 0 then
-   Set_Image_Integer (abs Q, Digs, Ndigs);
+   Set_Image_Integer (Q, Digs, Ndigs);
 end if;
 
 Scale := Scale + D;
@@ -249,16 +253,29 @@ package body System.Image_F is
 YY := 10**Maxdigs;
 
  else
+pragma Assert (-10**Maxdigs < Q and then Q < 10**Maxdigs);
+
 Len := 0;
 Set_Image_Integer (abs Q, Buf, Len);
 
-if Ndigs = 1 then
-   Digs (2 .. Len + 1) := Buf (1 .. Len);
-   Ndigs := Len + 1;
+pragma Assert (1 <= Len and then Len <= Maxdigs);
 
-else
-   --  Pad the output with zeroes up to Maxdigs
+--  If no character but the space has been written, write the
+--  minus if need be, since Set_Image_Integer did not do it.
 
+if Ndigs <= 1 then
+   if Q /= 0 then
+  if Ndigs = 0 then
+ Digs (1) := '-';
+  end if;
+
+  Digs (2 .. Len + 1) := Buf (1 .. Len);
+  Ndigs := Len + 1;
+   end if;
+
+--  Or else pad the output with zeroes up to Maxdigs
+
+else
for K in 1 .. Maxdigs - Len loop
   Digs (Ndigs + K) := '0';
end loop;
@@ -276,7 +293,7 @@ package body System.Image_F is
 
   --  If no digit was output, this is zero
 
-  if Ndigs = 1 then
+  if Ndigs <= 1 then
  Digs (1 .. 2) := " 0";
  Ndigs := 2;
   end if;




[Ada] Optimize magnitude of integer operations for fixed point

2020-11-27 Thread Pierre-Marie de Rodat
In most cases, the common operations for fixed-point types are implemented
by means of corresponding integer operations, in particular multiplication
and division.  Because scaling is required to go back and forth between
the two representations, the expander needs to control the magnitude of
operands in order to avoid a spurious overflow during the computation.

It turns out that this control is suboptimal for the multiplication, thus
leading to operations of an unnecessarily large magnitude in some cases.

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

gcc/ada/

* exp_fixd.adb (Build_Double_Divide): Use the RM size of types and
a more precise estimate for the size of the denominator.
(Build_Double_Divide_Code): Likewise.
(Build_Multiply): Use a more precise estimate for the size of the
result.
(Build_Scaled_Divide):  Use the RM size of types and a more precise
estimate for the size of the numerator.
(Build_Scaled_Divide_Code): Likewise.diff --git a/gcc/ada/exp_fixd.adb b/gcc/ada/exp_fixd.adb
--- a/gcc/ada/exp_fixd.adb
+++ b/gcc/ada/exp_fixd.adb
@@ -448,15 +448,15 @@ package body Exp_Fixd is
  (N   : Node_Id;
   X, Y, Z : Node_Id) return Node_Id
is
-  Y_Size : constant Nat := UI_To_Int (Esize (Etype (Y)));
-  Z_Size : constant Nat := UI_To_Int (Esize (Etype (Z)));
+  Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
+  Z_Size : constant Nat := UI_To_Int (RM_Size (Etype (Z)));
   Expr   : Node_Id;
 
begin
   --  If the denominator fits in Max_Integer_Size bits, we can build the
   --  operations directly without causing any intermediate overflow.
 
-  if 2 * Nat'Max (Y_Size, Z_Size) <= System_Max_Integer_Size then
+  if Y_Size + Z_Size <= System_Max_Integer_Size then
  return Build_Divide (N, X, Build_Multiply (N, Y, Z));
 
   --  Otherwise we use the runtime routine
@@ -516,9 +516,9 @@ package body Exp_Fixd is
is
   Loc: constant Source_Ptr := Sloc (N);
 
-  X_Size : constant Nat := UI_To_Int (Esize (Etype (X)));
-  Y_Size : constant Nat := UI_To_Int (Esize (Etype (Y)));
-  Z_Size : constant Nat := UI_To_Int (Esize (Etype (Z)));
+  X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
+  Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
+  Z_Size : constant Nat := UI_To_Int (RM_Size (Etype (Z)));
 
   QR_Id  : RE_Id;
   QR_Siz : Nat;
@@ -533,7 +533,7 @@ package body Exp_Fixd is
begin
   --  Find type that will allow computation of denominator
 
-  QR_Siz := Nat'Max (X_Size, 2 * Nat'Max (Y_Size, Z_Size));
+  QR_Siz := Nat'Max (X_Size, Y_Size + Z_Size);
 
   if QR_Siz <= 16 then
  QR_Typ := Standard_Integer_16;
@@ -724,10 +724,10 @@ package body Exp_Fixd is
 end;
  end if;
 
- --  Now the result size must be at least twice the longer of
- --  the two sizes, to accommodate all possible results.
+ --  Now the result size must be at least the sum of the two sizes,
+ --  to accommodate all possible results.
 
- Rsize := 2 * Int'Max (Left_Size, Right_Size);
+ Rsize := Left_Size + Right_Size;
 
  if Rsize <= 8 then
 Result_Type := Standard_Integer_8;
@@ -828,15 +828,15 @@ package body Exp_Fixd is
  (N   : Node_Id;
   X, Y, Z : Node_Id) return Node_Id
is
-  X_Size : constant Nat := UI_To_Int (Esize (Etype (X)));
-  Y_Size : constant Nat := UI_To_Int (Esize (Etype (Y)));
+  X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
+  Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
   Expr   : Node_Id;
 
begin
   --  If the numerator fits in Max_Integer_Size bits, we can build the
   --  operations directly without causing any intermediate overflow.
 
-  if 2 * Nat'Max (X_Size, Y_Size) <= System_Max_Integer_Size then
+  if X_Size + Y_Size <= System_Max_Integer_Size then
  return Build_Divide (N, Build_Multiply (N, X, Y), Z);
 
   --  Otherwise we use the runtime routine
@@ -893,9 +893,9 @@ package body Exp_Fixd is
is
   Loc: constant Source_Ptr := Sloc (N);
 
-  X_Size : constant Nat := UI_To_Int (Esize (Etype (X)));
-  Y_Size : constant Nat := UI_To_Int (Esize (Etype (Y)));
-  Z_Size : constant Nat := UI_To_Int (Esize (Etype (Z)));
+  X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
+  Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
+  Z_Size : constant Nat := UI_To_Int (RM_Size (Etype (Z)));
 
   QR_Id  : RE_Id;
   QR_Siz : Nat;
@@ -910,7 +910,7 @@ package body Exp_Fixd is
begin
   --  Find type that will allow computation of numerator
 
-  QR_Siz := Nat'Max (2 * Nat'Max (X_Size, Y_Size), Z_Size);
+  QR_Siz := Nat'Max (X_Size + Y_Size, Z_Size);
 
   if QR_Siz <= 16 then
  QR_Typ := Standard_Integer_16;




[Ada] To_Big_Integer and 128bits integers

2020-11-27 Thread Pierre-Marie de Rodat
Add support for the recently added 128bits integer support in
Big_Integers.To_Big_Integer.

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

gcc/ada/

* libgnat/s-genbig.ads, libgnat/s-genbig.adb (To_Bignum): New
variant taking an Unsigned_128.
* libgnat/a-nbnbin.adb (To_Big_Integer): Add support for 128
bits signed and unsigned types.diff --git a/gcc/ada/libgnat/a-nbnbin.adb b/gcc/ada/libgnat/a-nbnbin.adb
--- a/gcc/ada/libgnat/a-nbnbin.adb
+++ b/gcc/ada/libgnat/a-nbnbin.adb
@@ -177,7 +177,7 @@ package body Ada.Numerics.Big_Numbers.Big_Integers is
   function To_Big_Integer (Arg : Int) return Valid_Big_Integer is
  Result : Big_Integer;
   begin
- Set_Bignum (Result, To_Bignum (Long_Long_Integer (Arg)));
+ Set_Bignum (Result, To_Bignum (Long_Long_Long_Integer (Arg)));
  return Result;
   end To_Big_Integer;
 
@@ -205,7 +205,7 @@ package body Ada.Numerics.Big_Numbers.Big_Integers is
   function To_Big_Integer (Arg : Int) return Valid_Big_Integer is
  Result : Big_Integer;
   begin
- Set_Bignum (Result, To_Bignum (Unsigned_64 (Arg)));
+ Set_Bignum (Result, To_Bignum (Unsigned_128 (Arg)));
  return Result;
   end To_Big_Integer;
 


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
@@ -1193,7 +1193,7 @@ package body System.Generic_Bignums is
   return To_Bignum (Long_Long_Long_Integer (X));
end To_Bignum;
 
-   function To_Bignum (X : Unsigned_64) return Big_Integer is
+   function To_Bignum (X : Unsigned_128) return Big_Integer is
begin
   if X = 0 then
  return Allocate_Big_Integer ((1 .. 0 => <>), False);
@@ -1205,11 +1205,33 @@ package body System.Generic_Bignums is
 
   --  Two word result
 
-  else
+  elsif Shift_Right (X, 32) < 2 ** 32 then
  return Allocate_Big_Integer ((SD (X / Base), SD (X mod Base)), False);
+
+  --  Three or four word result
+
+  else
+ declare
+Vector : Digit_Vector (1 .. 4);
+High   : constant Unsigned_64 := Unsigned_64 (Shift_Right (X, 64));
+Low: constant Unsigned_64 :=
+  Unsigned_64 (X and 16#___#);
+
+ begin
+Vector (1) := SD (High / Base);
+Vector (2) := SD (High mod Base);
+Vector (3) := SD (Low / Base);
+Vector (4) := SD (Low mod Base);
+return Normalize (Vector, False);
+ end;
   end if;
end To_Bignum;
 
+   function To_Bignum (X : Unsigned_64) return Big_Integer is
+   begin
+  return To_Bignum (Unsigned_128 (X));
+   end To_Bignum;
+
---
-- To_String --
---


diff --git a/gcc/ada/libgnat/s-genbig.ads b/gcc/ada/libgnat/s-genbig.ads
--- a/gcc/ada/libgnat/s-genbig.ads
+++ b/gcc/ada/libgnat/s-genbig.ads
@@ -109,6 +109,10 @@ package System.Generic_Bignums is
--  Convert Unsigned_64 to a big integer. No exception can be raised for any
--  input argument.
 
+   function To_Bignum (X : Interfaces.Unsigned_128) return Big_Integer;
+   --  Convert Unsigned_128 to a big integer. No exception can be raised for
+   --  any input argument.
+
function From_Bignum (X : Bignum) return Long_Long_Integer;
--  Convert Bignum to Long_Long_Integer. Constraint_Error raised with
--  appropriate message if value is out of range of Long_Long_Integer.




[Ada] Move down call to Narrow_Large_Operation in Expand_N_Op_Multiply

2020-11-27 Thread Pierre-Marie de Rodat
It can block the transformation of the multiplication by a power of 2
into a shift operation when the context is Universal_Integer and checks
are disabled.

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

gcc/ada/

* exp_ch4.adb (Expand_N_Op_Multiply): Move down block calling
Narrow_Large_Operation if the type is Universal_Integer.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
@@ -9716,16 +9716,6 @@ package body Exp_Ch4 is
  end if;
   end if;
 
-  --  Try to narrow the operation
-
-  if Typ = Universal_Integer then
- Narrow_Large_Operation (N);
-
- if Nkind (N) /= N_Op_Multiply then
-return;
- end if;
-  end if;
-
   --  Convert x * 2 ** y to Shift_Left (x, y). Note that the fact that
   --  Is_Power_Of_2_For_Shift is set means that we know that our left
   --  operand is an integer, as required for this to work.
@@ -9802,6 +9792,16 @@ package body Exp_Ch4 is
  return;
   end if;
 
+  --  Try to narrow the operation
+
+  if Typ = Universal_Integer then
+ Narrow_Large_Operation (N);
+
+ if Nkind (N) /= N_Op_Multiply then
+return;
+ end if;
+  end if;
+
   --  Do required fixup of universal fixed operation
 
   if Typ = Universal_Fixed then




[Ada] Adjust head comment of various subprograms in Exp_Fixd

2020-11-27 Thread Pierre-Marie de Rodat
None of these programs analyzes the resulting node on return any more.

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

gcc/ada/

* exp_fixd.adb (Build_Conversion): Adjust head comment.
(Build_Divide): Likewise.
(Build_Double_Divide): Likewise.
(Build_Multiply): Likewise.
(Build_Rem): Likewise.
(Build_Scaled_Divide): Likewise.diff --git a/gcc/ada/exp_fixd.adb b/gcc/ada/exp_fixd.adb
--- a/gcc/ada/exp_fixd.adb
+++ b/gcc/ada/exp_fixd.adb
@@ -69,7 +69,7 @@ package body Exp_Fixd is
--  Build an expression that converts the expression Expr to type Typ,
--  taking the source location from Sloc (N). If the conversions involve
--  fixed-point types, then the Conversion_OK flag will be set so that the
-   --  resulting conversions do not get re-expanded. On return the resulting
+   --  resulting conversions do not get re-expanded. On return, the resulting
--  node has its Etype set. If Rchk is set, then Do_Range_Check is set
--  in the resulting conversion node. If Trunc is set, then the
--  Float_Truncate flag is set on the conversion, which must be from
@@ -86,7 +86,7 @@ package body Exp_Fixd is
--  two operand types), and both operands are converted to this type. The
--  Etype of the result is also set to this value. The Rounded_Result flag
--  of the result in this case is set from the Rounded_Result flag of node
-   --  N. On return, the resulting node is analyzed and has its Etype set.
+   --  N. On return, the resulting node has its Etype set.
 
function Build_Double_Divide
  (N   : Node_Id;
@@ -94,7 +94,7 @@ package body Exp_Fixd is
--  Returns a node corresponding to the value X/(Y*Z) using the source
--  location from Sloc (N). The division is rounded if the Rounded_Result
--  flag of N is set. The integer types of X, Y, Z may be different. On
-   --  return the resulting node is analyzed, and has its Etype set.
+   --  return, the resulting node has its Etype set.
 
procedure Build_Double_Divide_Code
  (N: Node_Id;
@@ -115,10 +115,9 @@ package body Exp_Fixd is
--  Make_Op_Multiply only in that the Etype of the resulting node is set (to
--  Universal_Real), or they can be integer or fixed-point types. In this
--  case the types need not be the same, and Build_Multiply chooses a type
-   --  long enough to hold the product (i.e. twice the size of the longer of
-   --  the two operand types), and both operands are converted to this type.
-   --  The Etype of the result is also set to this value. On return, the
-   --  resulting node is analyzed and has Etype set.
+   --  long enough to hold the product and both operands are converted to this
+   --  type. The type of the result is also set to this value. On return, the
+   --  resulting node has its Etype set.
 
function Build_Rem (N : Node_Id; L, R : Node_Id) return Node_Id;
--  Builds an N_Op_Rem node from the given left and right operand
@@ -127,7 +126,7 @@ package body Exp_Fixd is
--  operand with the smaller sized type to match the type of the other
--  operand and sets this as the result type. The result is never rounded
--  (rem operations cannot be rounded in any case). On return, the resulting
-   --  node is analyzed and has its Etype set.
+   --  node has its Etype set.
 
function Build_Scaled_Divide
  (N   : Node_Id;
@@ -135,7 +134,7 @@ package body Exp_Fixd is
--  Returns a node corresponding to the value X*Y/Z using the source
--  location from Sloc (N). The division is rounded if the Rounded_Result
--  flag of N is set. The integer types of X, Y, Z may be different. On
-   --  return the resulting node is analyzed and has is Etype set.
+   --  return the resulting node has its Etype set.
 
procedure Build_Scaled_Divide_Code
  (N: Node_Id;




[Ada] Do not compile predefined units with -gnatp in gnatmake

2020-11-27 Thread Pierre-Marie de Rodat
This aligns the behavior of gnatmake with the way the runtime is now
built.

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

gcc/ada/

* make.adb (GNAT_Flag): Change to "-gnatg".
(Compile): Adjust comments accordingly.diff --git a/gcc/ada/make.adb b/gcc/ada/make.adb
--- a/gcc/ada/make.adb
+++ b/gcc/ada/make.adb
@@ -464,7 +464,7 @@ package body Make is
Ada_Flag_1: constant String_Access := new String'("-x");
Ada_Flag_2: constant String_Access := new String'("ada");
AdaSCIL_Flag  : constant String_Access := new String'("adascil");
-   GNAT_Flag : constant String_Access := new String'("-gnatpg");
+   GNAT_Flag : constant String_Access := new String'("-gnatg");
Do_Not_Check_Flag : constant String_Access := new String'("-x");
 
Object_Suffix : constant String := Get_Target_Object_Suffix.all;
@@ -1677,7 +1677,7 @@ package body Make is
  L: File_Name_Type;
  Source_Index : Int;
  Args : Argument_List) return Process_Id;
-  --  Compiles S using Args. If S is a GNAT predefined source "-gnatpg" is
+  --  Compiles S using Args. If S is a GNAT predefined source "-gnatg" is
   --  added to Args. Non blocking call. L corresponds to the expected
   --  library file name. Process_Id of the process spawned to execute the
   --  compilation.
@@ -2027,7 +2027,7 @@ package body Make is
 end loop;
  end;
 
- --  Set -gnatpg for predefined files (for this purpose the renamings
+ --  Set -gnatg for predefined files (for this purpose the renamings
  --  such as Text_IO do not count as predefined). Note that we strip
  --  the directory name from the source file name because the call to
  --  Fname.Is_Predefined_File_Name cannot deal with directory prefixes.




[Ada] Restore general case for folding comparison of static strings

2020-11-27 Thread Pierre-Marie de Rodat
When reorganizing the mechanism which evaluates relational operators and
potentially folds them, the "General case" in routine Eval_Relational_Op
was put into an ELSE branch. This was subtly wrong, because it must be
executed unless the special case in the THEN branch exits with a RETURN
statement.

This patch restores the original behaviour of Eval_Relational_Op, so
that the relational operator is always folded when its operators are
static. This behaviour is asserted in Rewrite_Comparison, which is
called as part of the expansion (without this patch this assertion was
failing).

Finally, to satisfy this assertion we need to re-enable evaluation
within assertion expression, which was dubiously disabled for GNATprove.
(But this can be investigated separately).

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

gcc/ada/

* exp_ch4.adb (Rewrite_Comparison): Add assertion to confirm
that evaluation folds comparisons with static operands; when
folding comparison with non-static operands, the resulting
literal is non-static.
* sem_eval.adb (Eval_Relational_Op): Refactor nested IF
statement for the special case in the THEN branch; move code for
the "general case" out of the ELSE branch.
* sem_res.adb (Resolve_Comparison_Op): Only apply a dubious
special-case for GNATprove in the GNATprove_Mode.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
@@ -14962,6 +14962,14 @@ package body Exp_Ch4 is
  return;
   end if;
 
+  --  If both operands are static, then the comparison has been already
+  --  folded in evaluation.
+
+  pragma Assert
+(not Is_Static_Expression (Left_Opnd (N))
+   or else
+ not Is_Static_Expression (Right_Opnd (N)));
+
   --  Determine the potential outcome of the comparison assuming that the
   --  operands are valid and emit a warning when the comparison evaluates
   --  to True or False only in the presence of invalid values.
@@ -14977,7 +14985,8 @@ package body Exp_Ch4 is
  True_Result  => True_Result,
  False_Result => False_Result);
 
-  --  The outcome is a decisive False or True, rewrite the operator
+  --  The outcome is a decisive False or True, rewrite the operator into a
+  --  non-static literal.
 
   if False_Result or True_Result then
  Rewrite (N,
@@ -14985,6 +14994,7 @@ package body Exp_Ch4 is
  New_Occurrence_Of (Boolean_Literals (True_Result), Sloc (N;
 
  Analyze_And_Resolve (N, Typ);
+ Set_Is_Static_Expression (N, False);
  Warn_On_Known_Condition (N);
   end if;
end Rewrite_Comparison;


diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -3731,83 +3731,81 @@ package body Sem_Eval is
 Raises_Constraint_Error (Right)
  then
 return;
+ end if;
 
  --  OK, we have the case where we may be able to do this fold
 
- else
-Left_Len  := Static_Length (Left);
-Right_Len := Static_Length (Right);
+ Left_Len  := Static_Length (Left);
+ Right_Len := Static_Length (Right);
 
-if Left_Len /= Uint_Minus_1
-  and then Right_Len /= Uint_Minus_1
-  and then Left_Len /= Right_Len
-then
-   --  AI12-0201: comparison of string is static in Ada 202x
+ if Left_Len /= Uint_Minus_1
+   and then Right_Len /= Uint_Minus_1
+   and then Left_Len /= Right_Len
+ then
+--  AI12-0201: comparison of string is static in Ada 202x
 
-   Fold_Uint
- (N,
-  Test (Nkind (N) = N_Op_Ne),
-  Static => Ada_Version >= Ada_2020
-  and then Is_String_Type (Left_Typ));
-   Warn_On_Known_Condition (N);
-   return;
-end if;
+Fold_Uint
+  (N,
+   Test (Nkind (N) = N_Op_Ne),
+   Static => Ada_Version >= Ada_2020
+   and then Is_String_Type (Left_Typ));
+Warn_On_Known_Condition (N);
+return;
  end if;
+  end if;
 
   --  General case
 
-  else
- --  Initialize the value of Is_Static_Expression. The value of Fold
- --  returned by Test_Expression_Is_Foldable is not needed since, even
- --  when some operand is a variable, we can still perform the static
- --  evaluation of the expression in some cases (for example, for a
- --  variable of a subtype of Integer we statically know that any value
- --  stored in such variable is smaller than Integer'Last).
-
- Test_Expression_Is_Foldable
-   (N, Left, Right, Is_Static_Expression, Fold);
-
- --  Comparisons of scalars can give static results.
- 

[Ada] Optimize generation of checks for fixed-point types

2020-11-27 Thread Pierre-Marie de Rodat
This set of changes aimed at optimizing the generation of range and
overflow checks for fixed-point types contains two parts:

  1. a cleanup to the generation of range checks for type conversions
 involving fixed-point types, which is now more clearly deferred
 entirely to after the expansion of the conversions by Exp_Fixd.

  2. a generic improvement to the range computation engine so as to
 take into account the underlying integer ranges of fixed point.

The main effect is to get rid of useless overflow checks in some large
integer types generated for multiplication operations by Exp_Fixd.

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

gcc/ada/

* checks.ads (Determine_Range_To_Discrete): New procedure.
* checks.adb (Apply_Scalar_Range_Check): Call it to determine
a range for the expression when the target type is discrete.
And also apply the tests for discrete types to fixed-point
types when they are treated as integers.
(Apply_Type_Conversion_Checks): Apply checks to conversions
involving fixed-point types when they are treated as integers.
(Determine_Range) : Factor out code into...
(Determine_Range_To_Discrete): ...this new procedure and add
support for fixed-point types when they are treated as integers.
* einfo.ads (Type_High_Bound): Remove obsolete sentence.
(Type_Low_Bound): Likewise.
* exp_ch4.adb (Discrete_Range_Check): Remove obsolete code.
(Real_Range_Check): Likewise.
(Expand_N_Type_Conversion): In case of a no-op conversion, clear
the Do_Range_Check flag on the operand before substituting it.
Remove calls to Real_Range_Check and Discrete_Range_Check that
are not guarded by the Do_Range_Check flag, and an assertion.
* sem_res.adb (Resolve_Type_Conversion): Always apply range
checks in GNATprove mode; in normal mode, use the updated type
of the operand in the test against Universal_Fixed.  Remove
obsolete code setting the Do_Range_Check flag at the end.diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -3258,23 +3258,16 @@ package body Checks is
   end if;
 
   --  Return if we know expression is definitely in the range of the target
-  --  type as determined by Determine_Range. Right now we only do this for
-  --  discrete types, and not fixed-point or floating-point types.
-
-  --  The additional less-precise tests below catch these cases
-
-  --  In GNATprove_Mode, also deal with the case of a conversion from
-  --  floating-point to integer. It is only possible because analysis
-  --  in GNATprove rules out the possibility of a NaN or infinite value.
+  --  type as determined by Determine_Range_To_Discrete. Right now we only
+  --  do this for discrete target types, i.e. neither for fixed-point nor
+  --  for floating-point types. But the additional less precise tests below
+  --  catch these cases.
 
   --  Note: skip this if we are given a source_typ, since the point of
   --  supplying a Source_Typ is to stop us looking at the expression.
   --  We could sharpen this test to be out parameters only ???
 
   if Is_Discrete_Type (Target_Typ)
-and then (Is_Discrete_Type (Etype (Expr))
-   or else (GNATprove_Mode
- and then Is_Floating_Point_Type (Etype (Expr
 and then not Is_Unconstrained_Subscr_Ref
 and then No (Source_Typ)
   then
@@ -3318,35 +3311,8 @@ package body Checks is
 
   --  Otherwise determine range of value
 
-  if Is_Discrete_Type (Etype (Expr)) then
- Determine_Range
-   (Expr, OK, Lo, Hi, Assume_Valid => True);
-
-  --  When converting a float to an integer type, determine the
-  --  range in real first, and then convert the bounds using
-  --  UR_To_Uint which correctly rounds away from zero when
-  --  half way between two integers, as required by normal
-  --  Ada 95 rounding semantics. It is only possible because
-  --  analysis in GNATprove rules out the possibility of a NaN
-  --  or infinite value.
-
-  elsif GNATprove_Mode
-and then Is_Floating_Point_Type (Etype (Expr))
-  then
- declare
-Hir : Ureal;
-Lor : Ureal;
-
- begin
-Determine_Range_R
-  (Expr, OK, Lor, Hir, Assume_Valid => True);
-
-if OK then
-   Lo := UR_To_Uint (Lor);
-   Hi := UR_To_Uint (Hir);
-end if;
- end;
-  end if;
+   

[Ada] Reimplement Ada.Numerics.Big_Numbers.Big_Reals.Float_Conversions

2020-11-27 Thread Pierre-Marie de Rodat
This reimplements the aforementioned generic package according to the
requirements of the Ada 2020 RM, namely that To_Big_Real be exact and
that From_Big_Real use the common floating-point conversion rules,
which are round to nearest, ties to even, in GNAT as per IEEE 754.

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

gcc/ada/

* libgnat/a-nbnbre.adb: Remove clauses for System.Img_Real and
add them for System.Unsigned_Types.
(Float_Conversions.To_Big_Real): Reimplement.
(Float_Conversions.From_Big_Real): Likewise.diff --git a/gcc/ada/libgnat/a-nbnbre.adb b/gcc/ada/libgnat/a-nbnbre.adb
--- a/gcc/ada/libgnat/a-nbnbre.adb
+++ b/gcc/ada/libgnat/a-nbnbre.adb
@@ -30,7 +30,7 @@
 --
 
 with Ada.Strings.Text_Output.Utils;
-with System.Img_Real; use System.Img_Real;
+with System.Unsigned_Types; use System.Unsigned_Types;
 
 package body Ada.Numerics.Big_Numbers.Big_Reals is
 
@@ -122,25 +122,184 @@ package body Ada.Numerics.Big_Numbers.Big_Reals is
   -- To_Big_Real --
   -
 
+  --  We get the fractional representation of the floating-point number by
+  --  multiplying Num'Fraction by 2.0**M, with M the size of the mantissa,
+  --  which gives zero or a number in the range [2.0**(M-1)..2.0**M), which
+  --  means that it is an integer N of M bits. The floating-point number is
+  --  thus equal to N / 2**(M-E) where E is its Num'Exponent.
+
   function To_Big_Real (Arg : Num) return Valid_Big_Real is
- S : String (1 .. Max_Real_Image_Length);
- P : Natural := 0;
+
+ package Conv is new
+   Big_Integers.Unsigned_Conversions (Long_Long_Unsigned);
+
+ A : constant Num'Base := abs (Arg);
+ E : constant Integer  := Num'Exponent (A);
+ F : constant Num'Base := Num'Fraction (A);
+ M : constant Natural  := Num'Machine_Mantissa;
+
+ N, D : Big_Integer;
+
   begin
- --  Use Long_Long_Unsigned'Width - 1 digits = 20 which is sufficient
- --  for the largest floating point format.
+ pragma Assert (Num'Machine_Radix = 2);
+ --  This implementation does not handle radix 16
+
+ pragma Assert (M <= 64);
+ --  This implementation handles only 80-bit IEEE Extended or smaller
+
+ N := Conv.To_Big_Integer (Long_Long_Unsigned (F * 2.0**M));
+
+ --  If E is smaller than M, the denominator is 2**(M-E)
+
+ if E < M then
+D := To_Big_Integer (2) ** (M - E);
+
+ --  Or else, if E is larger than M, multiply the numerator by 2**(E-M)
+
+ elsif E > M then
+N := N * To_Big_Integer (2) ** (E - M);
+D := To_Big_Integer (1);
+
+ --  Otherwise E is equal to M and the result is just N
+
+ else
+D := To_Big_Integer (1);
+ end if;
 
- Set_Image_Real
-   (Long_Long_Float (Arg), S, P, Fore => 1, Aft => 20, Exp => 5);
- return From_String (S (1 .. P));
+ return (if Arg >= 0.0 then N / D else -N / D);
   end To_Big_Real;
 
   ---
   -- From_Big_Real --
   ---
 
+  --  We get the (Frac, Exp) representation of the real number by finding
+  --  the exponent E such that it lies in the range [2.0**(E-1)..2.0**E),
+  --  multiplying the number by 2.0**(M-E) with M the size of the mantissa,
+  --  and converting the result to integer N in the range [2**(M-1)..2**M)
+  --  with rounding to nearest, ties to even, and finally call Num'Compose.
+  --  This does not apply to the zero, for which we return 0.0 early.
+
   function From_Big_Real (Arg : Big_Real) return Num is
+
+ package Conv is new
+   Big_Integers.Unsigned_Conversions (Long_Long_Unsigned);
+
+ M: constant Natural := Num'Machine_Mantissa;
+ One  : constant Big_Real:= To_Real (1);
+ Two  : constant Big_Real:= To_Real (2);
+ Half : constant Big_Real:= One / Two;
+ TwoI : constant Big_Integer := To_Big_Integer (2);
+
+ function Log2_Estimate (V : Big_Real) return Natural;
+ --  Return an integer not larger than Log2 (V) for V >= 1.0
+
+ function Minus_Log2_Estimate (V : Big_Real) return Natural;
+ --  Return an integer not larger than -Log2 (V) for V < 1.0
+
+ ---
+ -- Log2_Estimate --
+ ---
+
+ function Log2_Estimate (V : Big_Real) return Natural is
+Log : Natural  := 1;
+Pow : Big_Real := Two;
+
+ begin
+while V >= Pow loop
+   Pow := Pow * Pow;
+   Log := Log + Log;
+end loop;
+
+return Log / 2;
+ end Log2_Estimate;
+
+ -
+ -- Minus_Log2_Estimate --
+ -
+
+ functi

[Ada] Change parameter from access type to mode out

2020-11-27 Thread Pierre-Marie de Rodat
Replace an access type parameter, which is unusual in the GNAT sources
and more difficult to understand, with a parameter of mode out. Code
cleanup only; behaviour is unaffected.

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

gcc/ada/

* sem_eval.ads (Compile_Time_Compare): Change parameter Diff
from access to mode out.
* sem_eval.adb (Compile_Time_Compare): Adapt body and callers.
* sem_attr.adb (Eval_Attribute): Adapt callers.diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -9138,12 +9138,12 @@ package body Sem_Attr is
  --  comparable, and we can figure out the difference between them.
 
  declare
-Diff : aliased Uint;
+Diff : Uint;
 
  begin
 case
   Compile_Time_Compare
-(Lo_Bound, Hi_Bound, Diff'Access, Assume_Valid => False)
+(Lo_Bound, Hi_Bound, Diff, Assume_Valid => False)
 is
when EQ =>
   Fold_Uint (N, Uint_1, Static);
@@ -9631,7 +9631,7 @@ package body Sem_Attr is
   --
 
   when Attribute_Range_Length => Range_Length : declare
- Diff : aliased Uint;
+ Diff : Uint;
 
   begin
  Set_Bounds;
@@ -9651,7 +9651,7 @@ package body Sem_Attr is
  --  comparable, and we can figure out the difference between them.
 
  case Compile_Time_Compare
-(Lo_Bound, Hi_Bound, Diff'Access, Assume_Valid => False)
+(Lo_Bound, Hi_Bound, Diff, Assume_Valid => False)
  is
 when EQ =>
Fold_Uint (N, Uint_1, Static);


diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -864,21 +864,21 @@ package body Sem_Eval is
  (L, R : Node_Id;
   Assume_Valid : Boolean) return Compare_Result
is
-  Discard : aliased Uint;
+  Discard : Uint;
begin
-  return Compile_Time_Compare (L, R, Discard'Access, Assume_Valid);
+  return Compile_Time_Compare (L, R, Discard, Assume_Valid);
end Compile_Time_Compare;
 
function Compile_Time_Compare
  (L, R : Node_Id;
-  Diff : access Uint;
+  Diff : out Uint;
   Assume_Valid : Boolean;
   Rec  : Boolean := False) return Compare_Result
is
   Ltyp : Entity_Id := Etype (L);
   Rtyp : Entity_Id := Etype (R);
 
-  Discard : aliased Uint;
+  Discard : Uint;
 
   procedure Compare_Decompose
 (N : Node_Id;
@@ -1197,7 +1197,7 @@ package body Sem_Eval is
--  Start of processing for Compile_Time_Compare
 
begin
-  Diff.all := No_Uint;
+  Diff := No_Uint;
 
   --  In preanalysis mode, always return Unknown unless the expression
   --  is static. It is too early to be thinking we know the result of a
@@ -1354,12 +1354,12 @@ package body Sem_Eval is
Hi : constant Uint := Expr_Value (R);
 begin
if Lo < Hi then
-  Diff.all := Hi - Lo;
+  Diff := Hi - Lo;
   return LT;
elsif Lo = Hi then
   return EQ;
else
-  Diff.all := Lo - Hi;
+  Diff := Lo - Hi;
   return GT;
end if;
 end;
@@ -1463,10 +1463,10 @@ package body Sem_Eval is
  and then not Is_Modular_Integer_Type (Rtyp)
then
   if Loffs < Roffs then
- Diff.all := Roffs - Loffs;
+ Diff := Roffs - Loffs;
  return LT;
   else
- Diff.all := Loffs - Roffs;
+ Diff := Loffs - Roffs;
  return GT;
   end if;
end if;
@@ -1492,14 +1492,14 @@ package body Sem_Eval is
 
if LHi < RLo then
   if Single and Assume_Valid then
- Diff.all := RLo - LLo;
+ Diff := RLo - LLo;
   end if;
 
   return LT;
 
elsif RHi < LLo then
   if Single and Assume_Valid then
- Diff.all := LLo - RLo;
+ Diff := LLo - RLo;
   end if;
 
   return GT;
@@ -1562,7 +1562,7 @@ package body Sem_Eval is
 
 if not Is_Generic_Type (Rtyp) then
case Compile_Time_Compare (L, Type_Low_Bound (Rtyp),
-  Discard'Access,
+  Discard,
   Assume_Valid, Rec => True)
is
   when LT => return LT;
@@ -1572,7 +1572,7 @@ package body Sem_Eval is
end case;
 
case Compile_Time_Compare (L, Type_High_Bound (Rtyp),

[Ada] Abort defer mismatch with SJLJ exceptions

2020-11-27 Thread Pierre-Marie de Rodat
Enabling checks in the runtime made a latent bug with the sjlj runtime
visible. We used to handle abort deferral differently between GCC ZCX
and GNAT "Front-End" SJLJ, which is no longer the case with GCC SJLJ, so
remove differences to simplify the code and fix the inconsistency.

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

gcc/ada/

* libgnarl/s-tasren.adb (Local_Complete_Rendezvous): Always call
Defer_Abort.
* libgnat/a-except.adb: Abort does not need to be deferred.
* libgnarl/s-tpobop.adb (Exceptional_Complete_Entry_Body): Abort
never needs to be undeferred here.
* exp_ch11.adb (Expand_Exception_Handlers): Remove difference
between ZCX and SJLJ.
* exp_ch9.adb (Expand_N_Asynchronous_Select): Remove different
handling for sjlj.
* exp_sel.ads, exp_sel.adb (Build_Abort_Block,
Build_Abort_Block_Handler): Ditto.diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -189,7 +189,6 @@ package body Exp_Ch11 is
   Handlrs   : constant List_Id:= Exception_Handlers (HSS);
   Loc   : constant Source_Ptr := Sloc (HSS);
   Handler   : Node_Id;
-  Others_Choice : Boolean;
   Obj_Decl  : Node_Id;
   Next_Handler  : Node_Id;
 
@@ -197,12 +196,6 @@ package body Exp_Ch11 is
   --  This procedure handles the expansion of exception handlers for the
   --  optimization of local raise statements into goto statements.
 
-  procedure Prepend_Call_To_Handler
-(Proc : RE_Id;
- Args : List_Id := No_List);
-  --  Routine to prepend a call to the procedure referenced by Proc at
-  --  the start of the handler code for the current Handler.
-
   procedure Replace_Raise_By_Goto (Raise_S : Node_Id; Goto_L1 : Node_Id);
   --  Raise_S is a raise statement (possibly expanded, and possibly of the
   --  form of a Raise_xxx_Error node with a condition. This procedure is
@@ -850,36 +843,6 @@ package body Exp_Ch11 is
  end;
   end Expand_Local_Exception_Handlers;
 
-  -
-  -- Prepend_Call_To_Handler --
-  -
-
-  procedure Prepend_Call_To_Handler
-(Proc : RE_Id;
- Args : List_Id := No_List)
-  is
- Ent : constant Entity_Id := RTE (Proc);
-
-  begin
- --  If we have no Entity, then we are probably in no run time mode or
- --  some weird error has occurred. In either case do nothing. Note use
- --  of No_Location to hide this code from the debugger, so single
- --  stepping doesn't jump back and forth.
-
- if Present (Ent) then
-declare
-   Call : constant Node_Id :=
-Make_Procedure_Call_Statement (No_Location,
-  Name => New_Occurrence_Of (RTE (Proc), No_Location),
-  Parameter_Associations => Args);
-
-begin
-   Prepend_To (Statements (Handler), Call);
-   Analyze (Call, Suppress => All_Checks);
-end;
- end if;
-  end Prepend_Call_To_Handler;
-
   ---
   -- Replace_Raise_By_Goto --
   ---
@@ -1089,44 +1052,6 @@ package body Exp_Ch11 is
(Statements (Handler), Suppress => All_Checks);
   end;
end if;
-
-   --  For the normal case, we have to worry about the state of
-   --  abort deferral. Generally, we defer abort during runtime
-   --  handling of exceptions. When control is passed to the
-   --  handler, then in the normal case we undefer aborts. In
-   --  any case this entire handling is relevant only if aborts
-   --  are allowed.
-
-   if Abort_Allowed
- and then not ZCX_Exceptions
-   then
-  --  There are some special cases in which we do not do the
-  --  undefer. In particular a finalization (AT END) handler
-  --  wants to operate with aborts still deferred.
-
-  --  We also suppress the call if this is the special handler
-  --  for Abort_Signal, since if we are aborting, we want to
-  --  keep aborts deferred (one abort is enough).
-
-  --  If abort really needs to be deferred the expander must
-  --  add this call explicitly, see
-  --  Expand_N_Asynchronous_Select.
-
-  Others_Choice :=
-Nkind (First (Exception_Choices (Handler))) =
- N_Others_Choice;
-
-  if (Others_Choice
-   or else Entity (First (Exception_Choices (Handler))) /=
- 

[Ada] Assertion_Policy is not a valid assertion policy

2020-11-27 Thread Pierre-Marie de Rodat
The following pragma is currently accepted:

  pragma Assertion_Policy (Assertion_Policy => Ignore);

because of what appears to be a typo in a previous commit on this topic.
With this patch the above pragma is rejected as illegal.

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

gcc/ada/

* sem_prag.adb (Is_Valid_Assertion_Kind): Return False on
"Assertion_Policy"diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31474,7 +31474,6 @@ package body Sem_Prag is
 --  RM defined
 
   Name_Assert
-| Name_Assertion_Policy
 | Name_Static_Predicate
 | Name_Dynamic_Predicate
 | Name_Pre




[Ada] Sync doc and code for pragma Assertion_Policy

2020-11-27 Thread Pierre-Marie de Rodat
In the listing of assertion kinds accepted for pragma Assertion_Policy
some items were wrongly included while other were missing. Now this
listing is synchronized with Sem_Prag.Is_Valid_Assertion_Kind.

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

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst
(Assertion_Policy): Add "Default_Initial_Condition",
"Initial_Condition" and "Subprogram_Variant".
* gnat_rm.texi: Regenerate.diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -444,21 +444,24 @@ Syntax::
 Type_Invariant   |
 Type_Invariant'Class
 
-  ID_ASSERTION_KIND ::= Assertions   |
-Assert_And_Cut   |
-Assume   |
-Contract_Cases   |
-Debug|
-Ghost|
-Invariant|
-Invariant'Class  |
-Loop_Invariant   |
-Loop_Variant |
-Postcondition|
-Precondition |
-Predicate|
-Refined_Post |
-Statement_Assertions
+  ID_ASSERTION_KIND ::= Assertions|
+Assert_And_Cut|
+Assume|
+Contract_Cases|
+Debug |
+Default_Initial_Condition |
+Ghost |
+Initial_Condition |
+Invariant |
+Invariant'Class   |
+Loop_Invariant|
+Loop_Variant  |
+Postcondition |
+Precondition  |
+Predicate |
+Refined_Post  |
+Statement_Assertions  |
+Subprogram_Variant
 
   POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
 


diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -21,7 +21,7 @@
 
 @copying
 @quotation
-GNAT Reference Manual , Nov 19, 2020
+GNAT Reference Manual , Nov 20, 2020
 
 AdaCore
 
@@ -1817,21 +1817,24 @@ RM_ASSERTION_KIND ::= Assert   |
   Type_Invariant   |
   Type_Invariant'Class
 
-ID_ASSERTION_KIND ::= Assertions   |
-  Assert_And_Cut   |
-  Assume   |
-  Contract_Cases   |
-  Debug|
-  Ghost|
-  Invariant|
-  Invariant'Class  |
-  Loop_Invariant   |
-  Loop_Variant |
-  Postcondition|
-  Precondition |
-  Predicate|
-  Refined_Post |
-  Statement_Assertions
+ID_ASSERTION_KIND ::= Assertions|
+  Assert_And_Cut|
+  Assume|
+  Contract_Cases|
+  Debug |
+  Default_Initial_Condition |
+  Ghost |
+  Initial_Condition |
+  Invariant |
+  Invariant'Class   |
+  Loop_Invariant|
+  Loop_Variant  |
+  Postcondition |
+  Precondition  |
+  Predicate |
+  Refined_Post  |
+  Statement_Assertions  |
+  Subprogram_Variant
 
 POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
 @end example




[Ada] Default_Initial_Condition assertion policy is now RM defined

2020-11-27 Thread Pierre-Marie de Rodat
Default_Initial_Condition was created for SPARK, but has been adopted by
Ada 202x, so now it is an RM defined aspect and an assertion policy.

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

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst:
(Assertion_Policy): Move "Default_Initial_Condition" from
ID_ASSERTION_KIND to RM_ASSERTION_KIND section.
* gnat_rm.texi: Regenerate.diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -434,33 +434,33 @@ Syntax::
 
   ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
 
-  RM_ASSERTION_KIND ::= Assert   |
-Static_Predicate |
-Dynamic_Predicate|
-Pre  |
-Pre'Class|
-Post |
-Post'Class   |
-Type_Invariant   |
-Type_Invariant'Class
-
-  ID_ASSERTION_KIND ::= Assertions|
-Assert_And_Cut|
-Assume|
-Contract_Cases|
-Debug |
-Default_Initial_Condition |
-Ghost |
-Initial_Condition |
-Invariant |
-Invariant'Class   |
-Loop_Invariant|
-Loop_Variant  |
-Postcondition |
-Precondition  |
-Predicate |
-Refined_Post  |
-Statement_Assertions  |
+  RM_ASSERTION_KIND ::= Assert|
+Static_Predicate  |
+Dynamic_Predicate |
+Pre   |
+Pre'Class |
+Post  |
+Post'Class|
+Type_Invariant|
+Type_Invariant'Class  |
+Default_Initial_Condition
+
+  ID_ASSERTION_KIND ::= Assertions   |
+Assert_And_Cut   |
+Assume   |
+Contract_Cases   |
+Debug|
+Ghost|
+Initial_Condition|
+Invariant|
+Invariant'Class  |
+Loop_Invariant   |
+Loop_Variant |
+Postcondition|
+Precondition |
+Predicate|
+Refined_Post |
+Statement_Assertions |
 Subprogram_Variant
 
   POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible


diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -1807,33 +1807,33 @@ pragma Assertion_Policy (
 
 ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
 
-RM_ASSERTION_KIND ::= Assert   |
-  Static_Predicate |
-  Dynamic_Predicate|
-  Pre  |
-  Pre'Class|
-  Post |
-  Post'Class   |
-  Type_Invariant   |
-  Type_Invariant'Class
-
-ID_ASSERTION_KIND ::= Assertions|
-  Assert_And_Cut|
-  Assume|
-  Contract_Cases|
-  Debug |
-  Default_Initial_Condition |
-  Ghost |
-  Initial_Condition |
-  Invariant |
-  Invariant'Class   |
-  Loop_Invariant|
-  Loop_Variant  |
-  Postcondition |
-  Precondition  |
-  Predicate |
-  Refined_Post  |
-  Statement_Assertio

[Ada] To_GM_Time returning invalid value for Invalid_Time

2020-11-27 Thread Pierre-Marie de Rodat
Some code currently relies on To_GM_Time returning some reasonable value
in this case rather than e.g. raising an exception and it appears that
Windows returns 1970-01-01 except with second set to -1 (triggering an
exception), while linux returns 1970-01-01 minus 1 second (so 1969-12-31
at 23:59:59). Since the Linux behavior is friendlier, special case the
code to that effect.

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

gcc/ada/

* libgnat/s-os_lib.adb (To_GM_Time): Return valid and consistent
values for Invalid_Time.diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -1365,6 +1365,21 @@ package body System.OS_Lib is
   S  : Integer;
 
begin
+  --  Special case Invalid_Time which is handled differently between
+  --  Windows and Linux: Linux will set to 1 second before 1970-01-01
+  --  while Windows will set the time to 1970-01-01 with Second set to -1,
+  --  which is not a valid value.
+
+  if Date = Invalid_Time then
+ Year   := 1969;
+ Month  := 12;
+ Day:= 31;
+ Hour   := 23;
+ Minute := 59;
+ Second := 59;
+ return;
+  end if;
+
   --  Use the global lock because To_GM_Time is not thread safe
 
   Locked_Processing : begin
@@ -1387,7 +1402,15 @@ package body System.OS_Lib is
 
   Year   := Y + 1900;
   Month  := Mo + 1;
-  Day:= D;
+
+  --  May happen if To_GM_Time fails
+
+  if D = 0 then
+ Day := 1;
+  else
+ Day := D;
+  end if;
+
   Hour   := H;
   Minute := Mn;
   Second := S;




[Ada] Implement AI12-0187 (Stable properties of abstract data types)

2020-11-27 Thread Pierre-Marie de Rodat
This is only an initial implementation, subject to many limitations.
Some interactions with derived types and inheritance are not
implemented.  Other limitations are idenitified in the code with "???"
comments.  However, Stable_Properties and Stable_Properties'Class aspect
specifications are implemented for both types and subprograms and the
associated assertions are generated.

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

gcc/ada/

* snames.ads-tmpl: Define new Name_Stable_Properties Name_Id
value.
* aspects.ads, aspects.adb: Add new Aspect_Stable_Properties
enumeration literal to Aspect_Id type. Add Class_Present
parameter to Find_Aspect and related
functions (Find_Value_Of_Aspect and Has_Aspect).
* sem_util.adb (Has_Nontrivial_Precondition): Fix
previously-latent bug uncovered by adding Class_Present
parameter to Aspect.Find_Aspect. The code was wrong before, but
with the change the bug was more likely to make a user-visible
difference.
* sem_ch6.adb (Analyze_Operator_Symbol): If a string literal
like "abs" or "-" occurs in a Stable_Properties aspect
specification, then it is to be interpreted as an operator
symbol and not as a string literal.
* sem_ch13.ads: Export new Parse_Aspect_Stable_Properties
function, analogous to the existing Parse_Aspect_Aggregate
exported procedure.
* sem_ch13.adb: (Parse_Aspect_Stable_Properties): New function;
analogous to existing Parse_Aspect_Aggregate.
(Validate_Aspect_Stable_Properties): New procedure; analogous to
existing Validate_Aspect_Aggregate. Called from the same case
statement (casing on an Aspect_Id value) where
Validate_Aspect_Aggregate is called.
(Resolve_Aspect_Stable_Properties): New procedure; analogous to
existing Resolve_Aspect_Aggregate. Called from the same two case
statements (each casing on an Aspect_Id value) where
Resolve_Aspect_Aggregate is called.
(Analyze_Aspect_Specifications): Set Has_Delayed_Aspects and
Is_Delayed_Aspect attributes for Aspect_Stable_Properties aspect
specifications.
(Check_Aspect_At_End_Of_Declarations): The syntactic
"expression" for a Stable_Properties aspect specification is not
semantically an expression; it doesn't have a type. Thus, force
T to be empty in this case.
* contracts.adb (Expand_Subprogram_Contract): Add call to new
local procedure,
Expand_Subprogram_Contract.Add_Stable_Property_Contracts, which
generates Postcondition pragmas corresponding to stable property
checks.

patch.diff.gz
Description: application/gzip


[Ada] Do not use 128-bit division for 64-bit fixed-point types

2020-11-27 Thread Pierre-Marie de Rodat
This restricts the use of 128-bit division for fixed-point types to
the cases where there is a 128-bit type in the source code, that is
to say this prevents the compiler from using it for 64-bit types.

This is done mainly for the sake of backward compatibility with earlier
compilers not supporting 128-bit fixed-point types, and because large
division operations generally require specific support routines.

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

gcc/ada/

* exp_fixd.adb (Build_Double_Divide): Only use a 128-bit
division if one of the operands is larger than 64 bits.
(Build_Double_Divide_Code): Likewise.
(Build_Scaled_Divide): Likewise.
(Build_Scaled_Divide_Code): Likewise.diff --git a/gcc/ada/exp_fixd.adb b/gcc/ada/exp_fixd.adb
--- a/gcc/ada/exp_fixd.adb
+++ b/gcc/ada/exp_fixd.adb
@@ -447,15 +447,22 @@ package body Exp_Fixd is
  (N   : Node_Id;
   X, Y, Z : Node_Id) return Node_Id
is
+  X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
   Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
   Z_Size : constant Nat := UI_To_Int (RM_Size (Etype (Z)));
+  D_Size : constant Nat := Y_Size + Z_Size;
+  M_Size : constant Nat := Nat'Max (X_Size, Nat'Max (Y_Size, Z_Size));
   Expr   : Node_Id;
 
begin
   --  If the denominator fits in Max_Integer_Size bits, we can build the
-  --  operations directly without causing any intermediate overflow.
+  --  operations directly without causing any intermediate overflow. But
+  --  for backward compatibility reasons, we use a 128-bit divide only
+  --  if one of the operands is already larger than 64 bits.
 
-  if Y_Size + Z_Size <= System_Max_Integer_Size then
+  if D_Size <= System_Max_Integer_Size
+and then (D_Size <= 64 or else M_Size > 64)
+  then
  return Build_Divide (N, X, Build_Multiply (N, Y, Z));
 
   --  Otherwise we use the runtime routine
@@ -518,6 +525,7 @@ package body Exp_Fixd is
   X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
   Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
   Z_Size : constant Nat := UI_To_Int (RM_Size (Etype (Z)));
+  M_Size : constant Nat := Nat'Max (X_Size, Nat'Max (Y_Size, Z_Size));
 
   QR_Id  : RE_Id;
   QR_Siz : Nat;
@@ -546,17 +554,17 @@ package body Exp_Fixd is
  QR_Typ := Standard_Integer_64;
  QR_Id  := RE_Null;
 
-  elsif QR_Siz <= 128 and then System_Max_Integer_Size = 128 then
- QR_Typ := Standard_Integer_128;
- QR_Id  := RE_Null;
-
-  --  For more than Max_Integer_Size bits, we use the integer defined in
-  --  Interfaces, so that it can be handled by the runtime routine.
+  --  For backward compatibility reasons, we use a 128-bit divide only
+  --  if one of the operands is already larger than 64 bits.
 
-  elsif System_Max_Integer_Size < 128 then
+  elsif System_Max_Integer_Size < 128 or else M_Size <= 64 then
  QR_Typ := RTE (RE_Integer_64);
  QR_Id  := RE_Double_Divide64;
 
+  elsif QR_Siz <= 128 then
+ QR_Typ := Standard_Integer_128;
+ QR_Id  := RE_Null;
+
   else
  QR_Typ := RTE (RE_Integer_128);
  QR_Id  := RE_Double_Divide128;
@@ -571,9 +579,9 @@ package body Exp_Fixd is
   Set_Etype (Qnn, QR_Typ);
   Set_Etype (Rnn, QR_Typ);
 
-  --  Case that we can compute the denominator in Max_Integer_Size bits
+  --  Case where we can compute the denominator in Max_Integer_Size bits
 
-  if QR_Siz <= System_Max_Integer_Size then
+  if QR_Id = RE_Null then
 
  --  Create temporaries for numerator and denominator and set Etypes,
  --  so that New_Occurrence_Of picks them up for Build_xxx calls.
@@ -829,13 +837,20 @@ package body Exp_Fixd is
is
   X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
   Y_Size : constant Nat := UI_To_Int (RM_Size (Etype (Y)));
+  Z_Size : constant Nat := UI_To_Int (RM_Size (Etype (Z)));
+  N_Size : constant Nat := X_Size + Y_Size;
+  M_Size : constant Nat := Nat'Max (X_Size, Nat'Max (Y_Size, Z_Size));
   Expr   : Node_Id;
 
begin
   --  If the numerator fits in Max_Integer_Size bits, we can build the
-  --  operations directly without causing any intermediate overflow.
+  --  operations directly without causing any intermediate overflow. But
+  --  for backward compatibility reasons, we use a 128-bit divide only
+  --  if one of the operands is already larger than 64 bits.
 
-  if X_Size + Y_Size <= System_Max_Integer_Size then
+  if N_Size <= System_Max_Integer_Size
+and then (N_Size <= 64 or else M_Size > 64)
+  then
  return Build_Divide (N, Build_Multiply (N, X, Y), Z);
 
   --  Otherwise we use the runtime routine
@@ -895,6 +910,7 @@ package body Exp_Fixd is
   X_Size : constant Nat := UI_To_Int (RM_Size (Etype (X)));
   Y_Size : constant

[Ada] Do not apply range checks inside generics in GNATprove mode

2020-11-27 Thread Pierre-Marie de Rodat
Similar to what is done for compilation, range checks should not be
applied inside generics during GNATprove analysis. This fixes an
assertion failure in GNATprove.

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

gcc/ada/

* checks.adb (Selected_Range_Checks): Adapt the condition for
applying range checks so that it is not done inside generics.diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -10585,10 +10585,10 @@ package body Checks is
begin
   --  Checks will be applied only when generating code. In GNATprove mode,
   --  we do not apply the checks, but we still call Selected_Range_Checks
-  --  to possibly issue errors on SPARK code when a run-time error can be
-  --  detected at compile time.
+  --  outside of generics to possibly issue errors on SPARK code when a
+  --  run-time error can be detected at compile time.
 
-  if not Expander_Active and not GNATprove_Mode then
+  if Inside_A_Generic or (not GNATprove_Mode and not Expander_Active) then
  return Ret_Result;
   end if;
 




[Ada] Small improvement to System.Value_R.Scan_Raw_Real

2020-11-27 Thread Pierre-Marie de Rodat
This makes System.Value_R.Scan_Raw_Real round the extra digit it returns
to the caller, so that it is precise to the last 'Aft digits for strings
that are the exact representation of a number, i.e. not already rounded.

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

gcc/ada/

* libgnat/s-valuer.adb (Scan_Decimal_Digits): Round Extra.
(Scan_Integral_Digits): Likewise.diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -144,6 +144,9 @@ package body System.Value_R is
   --  Set to True if addition of a digit will cause Value to be superior
   --  to Precision_Limit.
 
+  Precision_Limit_Just_Reached : Boolean := False;
+  --  Set to True if Precision_Limit_Reached was just set to True
+
   Digit : Char_As_Digit;
   --  The current digit
 
@@ -185,11 +188,24 @@ package body System.Value_R is
 
  --  If precision limit has been reached, just ignore any remaining
  --  digits for the computation of Value and Scale, but store the
- --  first in Extra. The scanning should continue only to assess the
- --  validity of the string.
+ --  first in Extra and use the second to round Extra. The scanning
+ --  should continue only to assess the validity of the string.
+
+ if Precision_Limit_Reached then
+if Precision_Limit_Just_Reached then
+   if Digit >= Base / 2 then
+  if Extra = Base - 1 then
+ Extra := 0;
+ Value := Value + 1;
+  else
+ Extra := Extra + 1;
+  end if;
+   end if;
 
- if not Precision_Limit_Reached then
+   Precision_Limit_Just_Reached := False;
+end if;
 
+ else
 --  Trailing '0' digits are ignored until a non-zero digit is found
 
 if Digit = 0 then
@@ -218,7 +234,7 @@ package body System.Value_R is
Temp := Value * Uns (Base) + Uns (Digit);
 
if Value <= Umax
-   or else (Value <= UmaxB and then Temp <= Precision_Limit)
+ or else (Value <= UmaxB and then Temp <= Precision_Limit)
then
   Value := Temp;
   Scale := Scale - 1;
@@ -226,6 +242,7 @@ package body System.Value_R is
else
   Extra := Digit;
   Precision_Limit_Reached := True;
+  Precision_Limit_Just_Reached := True;
end if;
 end if;
  end if;
@@ -289,6 +306,9 @@ package body System.Value_R is
   --  Set to True if addition of a digit will cause Value to be superior
   --  to Precision_Limit.
 
+  Precision_Limit_Just_Reached : Boolean := False;
+  --  Set to True if Precision_Limit_Reached was just set to True
+
   Digit : Char_As_Digit;
   --  The current digit
 
@@ -324,12 +344,25 @@ package body System.Value_R is
 
  --  If precision limit has been reached, just ignore any remaining
  --  digits for the computation of Value, but update Scale and store
- --  the first in Extra. The scanning should continue only to assess
- --  the validity of the string.
+ --  the first in Extra and use the second to round Extra. The scanning
+ --  should continue only to assess the validity of the string.
 
  if Precision_Limit_Reached then
 Scale := Scale + 1;
 
+if Precision_Limit_Just_Reached then
+   if Digit >= Base / 2 then
+  if Extra = Base - 1 then
+ Extra := 0;
+ Value := Value + 1;
+  else
+ Extra := Extra + 1;
+  end if;
+   end if;
+
+   Precision_Limit_Just_Reached := False;
+end if;
+
  else
 Temp := Value * Uns (Base) + Uns (Digit);
 
@@ -341,6 +374,7 @@ package body System.Value_R is
 else
Extra := Digit;
Precision_Limit_Reached := True;
+   Precision_Limit_Just_Reached := True;
Scale := Scale + 1;
 end if;
  end if;




[Ada] Restore access type instead of mode out parameter

2020-11-27 Thread Pierre-Marie de Rodat
Replace an access type parameter, which is unusual in the GNAT sources
and more difficult to understand, with a parameter of mode out. Code
cleanup only; behaviour is unaffected.

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

gcc/ada/

* sem_eval.ads (Compile_Time_Compare): Restore parameter Diff to
be of an access type.
* sem_eval.adb (Compile_Time_Compare): Adapt body and callers.
* sem_attr.adb (Eval_Attribute): Adapt callers.diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -9138,12 +9138,12 @@ package body Sem_Attr is
  --  comparable, and we can figure out the difference between them.
 
  declare
-Diff : Uint;
+Diff : aliased Uint;
 
  begin
 case
   Compile_Time_Compare
-(Lo_Bound, Hi_Bound, Diff, Assume_Valid => False)
+(Lo_Bound, Hi_Bound, Diff'Access, Assume_Valid => False)
 is
when EQ =>
   Fold_Uint (N, Uint_1, Static);
@@ -9631,7 +9631,7 @@ package body Sem_Attr is
   --
 
   when Attribute_Range_Length => Range_Length : declare
- Diff : Uint;
+ Diff : aliased Uint;
 
   begin
  Set_Bounds;
@@ -9651,7 +9651,7 @@ package body Sem_Attr is
  --  comparable, and we can figure out the difference between them.
 
  case Compile_Time_Compare
-(Lo_Bound, Hi_Bound, Diff, Assume_Valid => False)
+(Lo_Bound, Hi_Bound, Diff'Access, Assume_Valid => False)
  is
 when EQ =>
Fold_Uint (N, Uint_1, Static);


diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -864,21 +864,21 @@ package body Sem_Eval is
  (L, R : Node_Id;
   Assume_Valid : Boolean) return Compare_Result
is
-  Discard : Uint;
+  Discard : aliased Uint;
begin
-  return Compile_Time_Compare (L, R, Discard, Assume_Valid);
+  return Compile_Time_Compare (L, R, Discard'Access, Assume_Valid);
end Compile_Time_Compare;
 
function Compile_Time_Compare
  (L, R : Node_Id;
-  Diff : out Uint;
+  Diff : access Uint;
   Assume_Valid : Boolean;
   Rec  : Boolean := False) return Compare_Result
is
   Ltyp : Entity_Id := Etype (L);
   Rtyp : Entity_Id := Etype (R);
 
-  Discard : Uint;
+  Discard : aliased Uint;
 
   procedure Compare_Decompose
 (N : Node_Id;
@@ -1197,7 +1197,7 @@ package body Sem_Eval is
--  Start of processing for Compile_Time_Compare
 
begin
-  Diff := No_Uint;
+  Diff.all := No_Uint;
 
   --  In preanalysis mode, always return Unknown unless the expression
   --  is static. It is too early to be thinking we know the result of a
@@ -1354,12 +1354,12 @@ package body Sem_Eval is
Hi : constant Uint := Expr_Value (R);
 begin
if Lo < Hi then
-  Diff := Hi - Lo;
+  Diff.all := Hi - Lo;
   return LT;
elsif Lo = Hi then
   return EQ;
else
-  Diff := Lo - Hi;
+  Diff.all := Lo - Hi;
   return GT;
end if;
 end;
@@ -1463,10 +1463,10 @@ package body Sem_Eval is
  and then not Is_Modular_Integer_Type (Rtyp)
then
   if Loffs < Roffs then
- Diff := Roffs - Loffs;
+ Diff.all := Roffs - Loffs;
  return LT;
   else
- Diff := Loffs - Roffs;
+ Diff.all := Loffs - Roffs;
  return GT;
   end if;
end if;
@@ -1492,14 +1492,14 @@ package body Sem_Eval is
 
if LHi < RLo then
   if Single and Assume_Valid then
- Diff := RLo - LLo;
+ Diff.all := RLo - LLo;
   end if;
 
   return LT;
 
elsif RHi < LLo then
   if Single and Assume_Valid then
- Diff := LLo - RLo;
+ Diff.all := LLo - RLo;
   end if;
 
   return GT;
@@ -1562,7 +1562,7 @@ package body Sem_Eval is
 
 if not Is_Generic_Type (Rtyp) then
case Compile_Time_Compare (L, Type_Low_Bound (Rtyp),
-  Discard,
+  Discard'Access,
   Assume_Valid, Rec => True)
is
   when LT => return LT;
@@ -1572,7 +1572,7 @@ package body Sem_Eval is
end case;
 
case Compile_Time_Compare (L, Type_High_Bound (Rtyp),

[Ada] Reference before declaration on C392015

2020-11-27 Thread Pierre-Marie de Rodat
When working on LLVM/CCG, we found that the generated tree had a wrong
reference before declaration usage. Fixed for LLVM/CCG. The issue might
still be latent with Modify_Tree_For_C, but this expansion will
disappear in the future, so not worth bothering.

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

gcc/ada/

* exp_ch6.adb (Expand_Call): Properly split
Transform_Function_Array and Modify_Tree_For_C.diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -3656,7 +3656,8 @@ package body Exp_Ch6 is
 --  are passed by pointer in the generated C code, and we cannot
 --  take a pointer from a subprogram call.
 
-elsif Nkind (Parent (Call_Node)) in N_Subprogram_Call
+elsif Modify_Tree_For_C
+  and then Nkind (Parent (Call_Node)) in N_Subprogram_Call
   and then Is_Record_Type (Etype (Func_Id))
 then
declare




[Ada] Wrong compile time evaluation of Shift_Right

2020-11-27 Thread Pierre-Marie de Rodat
When using the Shift_Right operator on negative values (e.g. -1 on a
signed type), the wrong value is incorrectly folded after recent changes
in sem_eval.adb to add compile time evaluation of the shift operators.

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

gcc/ada/

* sem_eval.adb (Fold_Shift): Fix evaluation of Shift_Right on
negative values.diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -4805,6 +4805,8 @@ package body Sem_Eval is
  end if;
   end Check_Elab_Call;
 
+  Modulus : Uint;
+
begin
   if Compile_Time_Known_Value (Left)
 and then Compile_Time_Known_Value (Right)
@@ -4835,19 +4837,34 @@ package body Sem_Eval is
  elsif Op = N_Op_Shift_Right then
 Check_Elab_Call;
 
---  Fold Shift_Right (X, Y) by computing abs X / 2**Y
+--  X >> 0 is a no-op
 
-Fold_Uint
-  (N,
-   abs Expr_Value (Left) / (Uint_2 ** Expr_Value (Right)),
-   Static => Static);
+if Expr_Value (Right) = Uint_0 then
+   Fold_Uint (N, Expr_Value (Left), Static => Static);
+else
+   if Is_Modular_Integer_Type (Typ) then
+  Modulus := Einfo.Modulus (Typ);
+   else
+  Modulus := Uint_2 ** RM_Size (Typ);
+   end if;
+
+   --  Fold X >> Y by computing (X [+ Modulus]) / 2**Y
+   --  Note that after a Shift_Right operation (with Y > 0), the
+   --  result is always positive, even if the original operand was
+   --  negative.
 
+   Fold_Uint
+ (N,
+  (Expr_Value (Left) +
+ (if Expr_Value (Left) >= Uint_0 then Uint_0 else Modulus))
+  / (Uint_2 ** Expr_Value (Right)),
+  Static => Static);
+end if;
  elsif Op = N_Op_Shift_Right_Arithmetic then
 Check_Elab_Call;
 
 declare
Two_Y   : constant Uint := Uint_2 ** Expr_Value (Right);
-   Modulus : Uint;
 begin
if Is_Modular_Integer_Type (Typ) then
   Modulus := Einfo.Modulus (Typ);




[Ada] Small tweaks to couple of Value routines

2020-11-27 Thread Pierre-Marie de Rodat
This fixes a minor oversight in Integer_To_Fixed and restricts the
previous change to System.Value_R.Scan_Raw_Real for the sake of
backward compatibility with earlier conversions of the compiler.

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

gcc/ada/

* libgnat/s-valuef.adb (Integer_To_Fixed): Take into account the
extra digit when scaling up the input.
* libgnat/s-valuer.adb (Scan_Decimal_Digits): Restrict previous
change to fixed-point types.
(Scan_Integral_Digits): Likewise.diff --git a/gcc/ada/libgnat/s-valuef.adb b/gcc/ada/libgnat/s-valuef.adb
--- a/gcc/ada/libgnat/s-valuef.adb
+++ b/gcc/ada/libgnat/s-valuef.adb
@@ -227,8 +227,9 @@ package body System.Value_F is
 Z := N;
 
 for J in 1 .. LS loop
-   if V <= Uns'Last / Uns (B) then
-  V := V * Uns (B);
+   if V <= (Uns'Last - E) / Uns (B) then
+  V := V * Uns (B) + E;
+  E := 0;
else
   Bad_Value (Str);
end if;


diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -188,11 +188,13 @@ package body System.Value_R is
 
  --  If precision limit has been reached, just ignore any remaining
  --  digits for the computation of Value and Scale, but store the
- --  first in Extra and use the second to round Extra. The scanning
- --  should continue only to assess the validity of the string.
+ --  first in Extra and use the second to round Extra if this is for
+ --  a fixed-point type (we skip the rounding for a floating-point
+ --  type to preserve backward compatibility). The scanning should
+ --  continue only to assess the validity of the string.
 
  if Precision_Limit_Reached then
-if Precision_Limit_Just_Reached then
+if Precision_Limit_Just_Reached and then not Floating then
if Digit >= Base / 2 then
   if Extra = Base - 1 then
  Extra := 0;
@@ -343,14 +345,16 @@ package body System.Value_R is
  end if;
 
  --  If precision limit has been reached, just ignore any remaining
- --  digits for the computation of Value, but update Scale and store
- --  the first in Extra and use the second to round Extra. The scanning
- --  should continue only to assess the validity of the string.
+ --  digits for the computation of Value and Scale, but store the
+ --  first in Extra and use the second to round Extra if this is for
+ --  a fixed-point type (we skip the rounding for a floating-point
+ --  type to preserve backward compatibility). The scanning should
+ --  continue only to assess the validity of the string.
 
  if Precision_Limit_Reached then
 Scale := Scale + 1;
 
-if Precision_Limit_Just_Reached then
+if Precision_Limit_Just_Reached and then not Floating then
if Digit >= Base / 2 then
   if Extra = Base - 1 then
  Extra := 0;




Re: [committed obvious][arm] Add test that was missing from old commit [PR91816]

2020-11-27 Thread Christophe Lyon via Gcc-patches
On Fri, 27 Nov 2020 at 02:03, Stam Markianos-Wright
 wrote:
>
> On 26/11/2020 09:01, Christophe Lyon wrote:
> > On Wed, 25 Nov 2020 at 14:24, Stam Markianos-Wright via Gcc-patches
> >  wrote:
> >>
> >> Hi all,
> >>
> >> A while back I submitted GCC10 commit:
> >>
> >>44f77a6dea2f312ee1743f3dde465c1b8453ee13
> >>
> >> for PR91816.
> >>
> >> Turns out I was an idiot and forgot to include the test in the actual
> >> git commit, even my entire patch had been approved.
> >>
> >> Tested that the test still passes on a cross arm-none-eabi and also in a
> >> Cortex A-15 bootstrap with no regressions.
> >>
> >> Submitting this as Obvious to gcc-11 and backporting to gcc-10.
> >>
> >
> > Hi,
> >
> > This new test fails when forcing -mcpu=cortex-m3/4/5/7/33:
> > FAIL: gcc.target/arm/pr91816.c scan-assembler-times beq\\t.L[0-9] 2
> > FAIL: gcc.target/arm/pr91816.c scan-assembler-times beq\\t.Lbcond[0-9] 1
> > FAIL: gcc.target/arm/pr91816.c scan-assembler-times bne\\t.L[0-9] 2
> > FAIL: gcc.target/arm/pr91816.c scan-assembler-times bne\\t.Lbcond[0-9] 1
> >
> > I didn't check manually what is generated, can you have a look?
> >
>
> Oh wow thank you for spotting this!
>
> It looks like the A class target that I had tested had a tendency to
> emit a movw/movt pair, whereas these M class targets would emit a single
> ldr. This resulted in an overall shorter jump for these targets that did
> not trigger the new far-branch code.
>
> The test passes after... doubling it's own size:
>
>
>
>   #define HW3HW2 HW2 HW2 HW2 HW2 HW2 HW2 HW2 HW2 HW2
>   #define HW4HW3 HW3 HW3 HW3 HW3 HW3 HW3 HW3 HW3 HW3
>   #define HW5HW4 HW4 HW4 HW4 HW4 HW4 HW4 HW4 HW4 HW4
> +#define HW6HW5 HW5
>
>   __attribute__((noinline,noclone)) void f1 (int a)
>   {
> @@ -25,7 +26,7 @@ __attribute__((noinline,noclone)) void f2 (int a)
>
>   __attribute__((noinline,noclone)) void f3 (int a)
>   {
> -  if (a) { HW5 }
> +  if (a) { HW6 }
>   }
>
>   __attribute__((noinline,noclone)) void f4 (int a)
> @@ -41,7 +42,7 @@ __attribute__((noinline,noclone)) void f5 (int a)
>
>   __attribute__((noinline,noclone)) void f6 (int a)
>   {
> -  if (a == 1) { HW5 }
> +  if (a == 1) { HW6 }
>   }
>
> But this does effectively double the compilation time of an already
> quite large test. Would that be ok?

I guess that's OK for me.
We can probably increase the timeout value if needed.

>
> Overall this is the edge case testing that the compiler behaves
> correctly with a branch in huge compilation unit, so it would be nice to
> have test coverage of it on as many targets as possible... but also
> kinda rare.
>
> Hope this helps!
>
> Cheers,
> Stam
>
>
>
> > Thanks,
> >
> > Christophe
> >
> >
> >
> >
> >> Thanks,
> >> Stam Markianos-Wright
> >>
> >> gcc/testsuite/ChangeLog:
> >>  PR target/91816
> >>  * gcc.target/arm/pr91816.c: New test.
>


[PATCH] testsuite: i386: Extend effective-target checks for AVX512BW, AVX512DQ

2020-11-27 Thread Rainer Orth
When using the Solaris/x86 assembler with gcc, a couple of testcases
currently FAIL.  Those failures follow two patterns:

FAIL: gcc.target/i386/avx512bw-vpmovb2m-2.c (test for excess errors)
Excess errors:
Assembler: avx512bw-vpmovb2m-2.c
"/var/tmp//ccPh3IRc.s", line 58 : Invalid instruction argument
Near line: "vpmovb2m%zmm0, %k0"

and

FAIL: gcc.target/i386/avx512dq-vreducesd-2.c (test for excess errors)
Excess errors:
Assembler: avx512dq-vreducesd-2.c
"/var/tmp//ccVyU7Bc.s", line 54 : Invalid instruction argument
Near line: "vreducesd   $35, {sae}, %xmm0, %xmm0, %xmm7"

The first only started with

x86: relax mask register constraints

2019-01-04  Jan Beulich  

* config/i386/sse.md
(_cmp3,
[...]

and is strange since even the current Intel 64 and IA-32 Architectures
Software Developer's Manual only lists %k1 for vpmovb2m and related
insns, and indeed the line assembles with %k0 changed to %k1.

The second is due to the use of {sae}: either this is a Solaris as bug
(the do claim AVX512DQ support) or they use a different syntax here:
omitting {sae} lets the line assemble as well.

To avoid those failures, I've extended the avx512bw and avx512dq
effective-target checks to include code snippets that trigger the
generation of those insns.

Tested no i386-pc-solaris2.11 with as (the failures are gone, as
expected) and gas (test results unchanged).

Ok for master?

Rainer

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


2020-11-27  Rainer Orth  

gcc/testsuite:
* lib/target-supports.exp (check_effective_target_avx512dq): Add
_mm512_mask_reduce_round_ps.
(check_effective_target_avx512bw): Check for %k0 support.
Compile with -O2.

# HG changeset patch
# Parent  ad34fb1f08c1a1948aeeb2466cbcd26e49753364
testsuite: i386: Extend effective-target checks for AVX512BW, AVX512DQ

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -8805,6 +8805,10 @@ proc check_effective_target_sha { } {
 proc check_effective_target_avx512dq { } {
 return [check_no_compiler_messages avx512dq object {
 	typedef long long __v8di __attribute__ ((__vector_size__ (64)));
+	typedef float __m512 __attribute__ ((__vector_size__ (64)));
+	typedef float __v16sf __attribute__ ((__vector_size__ (64)));
+	typedef unsigned short __mmask16;
+
 	__v8di
 	_mm512_mask_mullo_epi64 (__v8di __W, __v8di __A, __v8di __B)
 	{
@@ -8813,6 +8817,16 @@ proc check_effective_target_avx512dq { }
 			(__v8di) __W,
 			-1);
 	}
+
+	__m512
+	_mm512_mask_reduce_round_ps (__m512 __W, __mmask16 __U, __m512 __A, int __B,
+ const int __R)
+	{
+	return (__m512) __builtin_ia32_reduceps512_mask_round ((__v16sf) __A,
+   0x23,
+   (__v16sf) __W,
+   0xA6BA, 0x08);
+	}
 } "-mavx512dq" ]
 }
 
@@ -8821,6 +8835,11 @@ proc check_effective_target_avx512bw { }
 return [check_no_compiler_messages avx512bw object {
 	typedef short __v32hi __attribute__ ((__vector_size__ (64)));
 	__v32hi
+	baz (__v32hi a)
+	{
+	return a == 0;
+	}
+	__v32hi
 	_mm512_mask_mulhrs_epi16 (__v32hi __W, __v32hi __A, __v32hi __B)
 	{
 	return (__v32hi) __builtin_ia32_pmulhrsw512_mask ((__v32hi) __A,
@@ -8828,7 +8847,7 @@ proc check_effective_target_avx512bw { }
 			(__v32hi) __W,
 			-1);
 	}
-} "-mavx512bw" ]
+} "-O2 -mavx512bw" ]
 }
 
 # Return 1 if avx512vp2intersect instructions can be compiled.


[Patch] Fortran: -fno-automatic and -fopenacc / recusion check cleanup

2020-11-27 Thread Tobias Burnus

Two fixes – simple, see patch + commit text.

Longer description:

* options:
Background:
- OpenMP, OpenACC and imply that a function is called
concurrently and -frecursive implies recusive. In all those
cases, the code may fail if a local variable is in static memory
instead of stack or heap. – If a user specified 'save', we
can assume/hope that they will deal with it - but with
-fno-automatic (→ 'save' implied), the flags clash.

- Additionally, to avoid placing local arrays in static memory,
for -fopenmp/-fopenacc -frecursive and 'unlimited' stack size
use for const-size arrays is implied.

This patch:
- Handle OpenACC as OpenMP (before it didn't imply -frecursive.


* Recursive run-time check. The current code currently generates:

  subroutine foo()
logical, save :: currently_called = .false.
if (currently_called) error_stop "No recursive but called"
currently_called = .true.
...
... ! Rest of code, which could indirectly call this proc again
...
currently_called = .false.
  end

This works well for recursive calls but less so for concurrency
(→ OpenMP, OpenACC).
As noted above, by default OpenMP/OpenACC implies -frecursive
and, hence, there is no recursive check generated.
The question is what code should be generated for, e.g.
  -fno-automatic -fopenmp or -fopenacc -fmax-stack-var-size=20

In that case, -frecursive is unset. We have two choices:
- Either still always reset, which may not detect concurrent
  use (including recursive + concurrent use) do to a race condition.
- Or avoid resetting the flag
  But then calling the procedure twice (e.g. beginning + end of the
  program) will generate a bogus error.

The current code does the second – at least for -fopenmp.

→ PATCH: Simply use the same condition twice instead of a complicated
  test; do so via: 'if (recurcheckvar == NULL_TREE)'.

Current code:

tree recurcheckvar = NULL_TREE;
...
  if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
  && !is_recursive && !flag_recursive && !sym->attr.artificial)
...  // declare 'recurcheckvar', generate error-message code etc.
...
  /* Reset recursion-check variable.  */
  if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
   && !is_recursive && !flag_openmp && recurcheckvar != NULL_TREE)


Comments? Suggestions? – If not, I will commit it as obvious in the next
days.

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
Fortran: -fno-automatic and -fopenacc / recusion check cleanup

Options: -fopenmp and -fopenacc imply concurrent calls to a
procedure; now also -fopenacc implies -frecursive, disabling
that larger local const-size array variables use static memory.

Run-time recursion check: Always reset the check variable at the
end of the procedure; this avoids a bogus error with -fopenmp
when called twice nonconcurrently/nonrecursively. (Issue requires
using -fno-automatic or -fmax-stack-var-size= to trigger.)

gcc/fortran/ChangeLog:

	PR fortran/98010
	PR fortran/98013
	* options.c (gfc_post_options): Also imply recursive with
	-fopenacc.
	* trans-decl.c (gfc_generate_function_code): Simplify condition.

 gcc/fortran/options.c| 16 +---
 gcc/fortran/trans-decl.c |  3 +--
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index d844fa93115..66be1d586fb 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -407,32 +407,34 @@ gfc_post_options (const char **pfilename)
 
   if (!flag_automatic && flag_max_stack_var_size != -2
   && flag_max_stack_var_size != 0)
 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
 		 flag_max_stack_var_size);
   else if (!flag_automatic && flag_recursive)
 gfc_warning_now (OPT_Woverwrite_recursive, "Flag %<-fno-automatic%> "
 		 "overwrites %<-frecursive%>");
-  else if (!flag_automatic && flag_openmp)
-gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
-		 "%<-fopenmp%>");
+  else if (!flag_automatic && (flag_openmp || flag_openacc))
+gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> "
+		 "implied by %qs", flag_openmp ? "-fopenmp" : "-fopenacc");
   else if (flag_max_stack_var_size != -2 && flag_recursive)
 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
 		 flag_max_stack_var_size);
-  else if (flag_max_stack_var_size != -2 && flag_openmp)
-gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
-		 "implied by %<-fopenmp%>", flag_max_stack_var_size);
+  else if (flag_max_stack_var_size != -2 && (flag_openmp || flag_openacc))
+gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites "
+		 "%<-frecursive%> implied by %qs", flag_max_stack_var_size,
+		 flag_openmp ? "-fopenmp" : "-fopenacc");
 
  

Re: [Patch] OpenACC: Fix integer-type issue with collapse/tile [PR97880]

2020-11-27 Thread Tobias Burnus

Now committed as r11-5489-gf324479caf0ac326534f4fcf72cb12991ccddb3d

Tobias

On 25.11.20 12:00, Tobias Burnus wrote:

Here, the problem was that we were mixing types when calculating
the product of loop-steps, each type was taken from the loop var.

Solution: take the largest type as diff_type and use it everywhere.

And add a missing 'fold_convert' to fix the actual ICE.

Comments? If not, I will commit it later.

Tobias


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


[PATCH] tree-ssanames: Allow non-SSA_NAME arguments to get_range_info

2020-11-27 Thread Jakub Jelinek via Gcc-patches
Hi!

My recent match.pd change required quite a lot of code due to the separate
need to handle INTEGER_CSTs and SSA_NAMEs, and after all, I didn't even
handle one case there, when in x * y / y the x is INTEGER_CST and y is
SSA_NAME.
The following patch allows to simplify it, by allowing non-SSA_NAME argument
to get_range_info, for INTEGER_CSTs it will return VR_RANGE with *min == *max
equal to the constnat, and for non-INTEGER_CST/SSA_NAMEs it will just return
VR_VARYING.

This allows not to simplify just the match.pd, but some other spots too.

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

2020-11-27  Jakub Jelinek  

* tree-ssanames.c (get_range_info): Handle INTEGER_CST by returning
VR_RANGE with both *min and *max set to the wide_int value of the
INTEGER_CST.  Return VR_VARYING for non-SSA_NAMEs.
* match.pd ((t * 2) / 2) -> t): Handle also @0 being INTEGER_CST.
Simplify by calling get_range_info on everything.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Simplify by calling
get_range_info on everything.
* tree-scalar-evolution.c (iv_can_overflow_p): Likewise.

--- gcc/tree-ssanames.c.jj  2020-11-23 17:01:52.002013364 +0100
+++ gcc/tree-ssanames.c 2020-11-26 16:28:10.092549635 +0100
@@ -420,21 +420,30 @@ set_range_info (tree name, const value_r
is used to determine if MIN and MAX are valid values.  */
 
 enum value_range_kind
-get_range_info (const_tree name, wide_int *min, wide_int *max)
+get_range_info (const_tree expr, wide_int *min, wide_int *max)
 {
-  gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
+  gcc_assert (!POINTER_TYPE_P (TREE_TYPE (expr)));
   gcc_assert (min && max);
-  range_info_def *ri = SSA_NAME_RANGE_INFO (name);
+  if (TREE_CODE (expr) == INTEGER_CST)
+{
+  *min = wi::to_wide (expr);
+  *max = *min;
+  return VR_RANGE;
+}
+  if (TREE_CODE (expr) != SSA_NAME)
+return VR_VARYING;
+
+  range_info_def *ri = SSA_NAME_RANGE_INFO (expr);
 
   /* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
  with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision.  */
-  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (name)))
+  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (expr)))
  > 2 * HOST_BITS_PER_WIDE_INT))
 return VR_VARYING;
 
   *min = ri->get_min ();
   *max = ri->get_max ();
-  return SSA_NAME_RANGE_TYPE (name);
+  return SSA_NAME_RANGE_TYPE (expr);
 }
 
 /* Gets range information corresponding to ssa_name NAME and stores it
--- gcc/match.pd.jj 2020-11-26 16:23:55.037394625 +0100
+++ gcc/match.pd2020-11-26 16:42:11.527163758 +0100
@@ -654,42 +654,30 @@ (define_operator_list COND_TERNARY
(if (TYPE_OVERFLOW_UNDEFINED (type))
 @0
 #if GIMPLE
-(if (TREE_CODE (@0) == SSA_NAME
-&& (TREE_CODE (@1) == SSA_NAME || TREE_CODE (@1) == INTEGER_CST))
- (with
-  {
-   bool overflowed = true;
-   wide_int wmin0, wmax0;
-   if (get_range_info (@0, &wmin0, &wmax0) == VR_RANGE)
- {
-   /* If the multiplication can't overflow/wrap around, then
-  it can be optimized too.  */
-   wide_int wmin1, wmax1;
-   wi::overflow_type min_ovf, max_ovf;
-   if (TREE_CODE (@1) == INTEGER_CST)
- {
-   wmin1 = wi::to_wide (@1);
-   wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
-   wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
-   if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
- overflowed = false;
- }
-   else if (get_range_info (@1, &wmin1, &wmax1) == VR_RANGE)
- {
-   wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
-   wi::mul (wmax0, wmax1, TYPE_SIGN (type), &max_ovf);
-   if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
- {
-   wi::mul (wmin0, wmax1, TYPE_SIGN (type), &min_ovf);
-   wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
-   if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
- overflowed = false;
- }
- }
- }
-  }
- (if (!overflowed)
-  @0)))
+(with
+ {
+   bool overflowed = true;
+   wide_int wmin0, wmax0, wmin1, wmax1;
+   if (INTEGRAL_TYPE_P (type)
+  && get_range_info (@0, &wmin0, &wmax0) == VR_RANGE
+  && get_range_info (@1, &wmin1, &wmax1) == VR_RANGE)
+{
+  /* If the multiplication can't overflow/wrap around, then
+ it can be optimized too.  */
+  wi::overflow_type min_ovf, max_ovf;
+  wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
+  wi::mul (wmax0, wmax1, TYPE_SIGN (type), &max_ovf);
+  if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
+{
+  wi::mul (wmin0, wma

[PATCH v2] configury : Fix LEB128 support for non-GNU assemblers.

2020-11-27 Thread Iain Sandoe via Gcc-patches

Hi Folks.

Iain Sandoe via Gcc-patches  wrote:


Rainer Orth  wrote:
maybe this is enough to cover all bases without having to do any  
version or

target checks. (untested)

objdump is not available on quite a few Darwin versions with perfectly
functional
uleb128 - so I don’t want to punt on those for absence of it.  We already
check for
otool elsewhere.

thoughts?


LGTM, with one nit:


[[
if test "x$gcc_cv_objdump" != x; then
if $gcc_cv_objdump --full-contents conftest.o 2>/dev/null \


I'd use $gcc_cv_objdump -s here (maybe adding -j .data), matching the
other equivalent objdump invocations in gcc/configure.


OK - I need to check on compatibility between GNU objdump and LLVM objdump.
(since newer Darwin and GCN will be using the latter).

-s might work OK since we only have one section, but -j is problematic wit
different section naming conventions.


It turns out that ‘-s' is more compatible across the range of LLVM objdump
than —full-contents (which is not accepted by earlier versions).  -j is a  
non-

starter without we make the match more complex.  Perhaps there should
be a section early in configure that checks all the object dumper stuff and
sets some flags that are easier to test (instead of repeating the name  
checks)

—— not for today tho.

I’ve tested the following cases :
1/ as does not accept the leb128 directives
2/ as crashes with len128 directives
3/ as gives wrong output with leb128 directives
4/ as gives right output
  - with GNU objdump
  - with LLVM objdump from Darwin14..Darwin20
  - with Darwin cctools otool on Darwin10.

@Andrew - I don’t expect this to make any difference on GCN - but that does
depend on the target toolset having an objdump in the path.

If there are no futher comments, and assuming that a regstrap is successful  
on

AIX, Solaris (sparc), Linux and Darwin - OK for master?

thanks
Iain



[PATCH] configury : Fix LEB128 support for non-GNU assemblers.

The current configuration test for LEB128 support in the assembler is
(a) specific to GNU assemblers and (b) only checks that the directives
are accepted, not that they give correct output.

The patch extends the asm test to cover one failure case present in
assemblers based off an older version of GAS (where a 64 bit value with
the MSB set presented to a .uleb128 directive causes a fail).

The test is now generalized such that it does not make use of any
specific test for assembler source/version, but checks that the output
is as expected.  We cater for scanning the object with objdump (either
binutils or LLVM) or Darwin otool.

gcc/ChangeLog:

* configure.ac (check leb128 support): Check that assemblers both
accept the LEB128 directives and also give the expected output.
Add a test for uleb128 with the MSB set for a 64 bit value.
* configure: Regenerated.
---
 gcc/configure| 36 
 gcc/configure.ac | 48 ++--
 2 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index e9510d39937..c6fd3819727 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -24000,6 +24000,8 @@ _ACEOF


 # Check if we have .[us]leb128, and support symbol arithmetic with it.
+# Older versions of GAS and some non-GNU assemblers, have a bugs handling
+# these directives, even when they appear to accept them.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .sleb128 and 
.uleb128" >&5
 $as_echo_n "checking assembler for .sleb128 and .uleb128... " >&6; }
 if ${gcc_cv_as_leb128+:} false; then :
@@ -24017,7 +24019,9 @@ fi
 L1:
.uleb128 1280
.sleb128 -1010
-L2:' > conftest.s
+L2:
+   .uleb128 0x8000
+' > conftest.s
 if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
   (eval $ac_try) 2>&5
@@ -24025,22 +24029,22 @@ L2:' > conftest.s
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; }
 then
-   # GAS versions before 2.11 do not support uleb128,
-  # despite appearing to.
-  # ??? There exists an elf-specific test that will crash
-  # the assembler.  Perhaps it's better to figure out whether
-  # arbitrary sections are supported and try the test.
-  as_ver=`$gcc_cv_as --version 2>/dev/null | sed 1q`
-  if echo "$as_ver" | grep GNU > /dev/null; then
-as_vers=`echo $as_ver | sed -n \
-   -e 's,^.*[   ]\([0-9][0-9]*\.[0-9][0-9]*.*\)$,\1,p'`
-as_major=`expr "$as_vers" : '\([0-9]*\)'`
-as_minor=`expr "$as_vers" : '[0-9]*\.\([0-9]*\)'`
-if test $as_major -eq 2 && test $as_minor -lt 11
-then :
-else gcc_cv_as_leb128=yes
-fi
+
+if test "x$gcc_cv_objdump" != x; then
+  if $gcc_cv_objdump -s conftest.o 2>/dev/null \
+ | grep '04800a8e 78808080 80808080 808001' >/dev/null; then
+gcc_cv_as_leb128=yes
+  fi
+elif test "x$gcc_cv_otool" != x; then
+  if $gcc_cv_otool -d con

Re: [PATCH] tree-ssanames: Allow non-SSA_NAME arguments to get_range_info

2020-11-27 Thread Richard Biener
On Fri, 27 Nov 2020, Jakub Jelinek wrote:

> Hi!
> 
> My recent match.pd change required quite a lot of code due to the separate
> need to handle INTEGER_CSTs and SSA_NAMEs, and after all, I didn't even
> handle one case there, when in x * y / y the x is INTEGER_CST and y is
> SSA_NAME.
> The following patch allows to simplify it, by allowing non-SSA_NAME argument
> to get_range_info, for INTEGER_CSTs it will return VR_RANGE with *min == *max
> equal to the constnat, and for non-INTEGER_CST/SSA_NAMEs it will just return
> VR_VARYING.
> 
> This allows not to simplify just the match.pd, but some other spots too.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2020-11-27  Jakub Jelinek  
> 
>   * tree-ssanames.c (get_range_info): Handle INTEGER_CST by returning
>   VR_RANGE with both *min and *max set to the wide_int value of the
>   INTEGER_CST.  Return VR_VARYING for non-SSA_NAMEs.
>   * match.pd ((t * 2) / 2) -> t): Handle also @0 being INTEGER_CST.
>   Simplify by calling get_range_info on everything.
>   * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Simplify by calling
>   get_range_info on everything.
>   * tree-scalar-evolution.c (iv_can_overflow_p): Likewise.
> 
> --- gcc/tree-ssanames.c.jj2020-11-23 17:01:52.002013364 +0100
> +++ gcc/tree-ssanames.c   2020-11-26 16:28:10.092549635 +0100
> @@ -420,21 +420,30 @@ set_range_info (tree name, const value_r
> is used to determine if MIN and MAX are valid values.  */
>  
>  enum value_range_kind
> -get_range_info (const_tree name, wide_int *min, wide_int *max)
> +get_range_info (const_tree expr, wide_int *min, wide_int *max)
>  {
> -  gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
> +  gcc_assert (!POINTER_TYPE_P (TREE_TYPE (expr)));
>gcc_assert (min && max);
> -  range_info_def *ri = SSA_NAME_RANGE_INFO (name);
> +  if (TREE_CODE (expr) == INTEGER_CST)
> +{
> +  *min = wi::to_wide (expr);
> +  *max = *min;
> +  return VR_RANGE;
> +}
> +  if (TREE_CODE (expr) != SSA_NAME)
> +return VR_VARYING;
> +
> +  range_info_def *ri = SSA_NAME_RANGE_INFO (expr);
>  
>/* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
>   with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision.  */
> -  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (name)))
> +  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (expr)))
> > 2 * HOST_BITS_PER_WIDE_INT))
>  return VR_VARYING;
>  
>*min = ri->get_min ();
>*max = ri->get_max ();
> -  return SSA_NAME_RANGE_TYPE (name);
> +  return SSA_NAME_RANGE_TYPE (expr);
>  }
>  
>  /* Gets range information corresponding to ssa_name NAME and stores it
> --- gcc/match.pd.jj   2020-11-26 16:23:55.037394625 +0100
> +++ gcc/match.pd  2020-11-26 16:42:11.527163758 +0100
> @@ -654,42 +654,30 @@ (define_operator_list COND_TERNARY
> (if (TYPE_OVERFLOW_UNDEFINED (type))
>  @0
>  #if GIMPLE
> -(if (TREE_CODE (@0) == SSA_NAME
> -  && (TREE_CODE (@1) == SSA_NAME || TREE_CODE (@1) == INTEGER_CST))
> - (with
> -  {
> - bool overflowed = true;
> - wide_int wmin0, wmax0;
> - if (get_range_info (@0, &wmin0, &wmax0) == VR_RANGE)
> -   {
> - /* If the multiplication can't overflow/wrap around, then
> -it can be optimized too.  */
> - wide_int wmin1, wmax1;
> - wi::overflow_type min_ovf, max_ovf;
> - if (TREE_CODE (@1) == INTEGER_CST)
> -   {
> - wmin1 = wi::to_wide (@1);
> - wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
> - wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
> - if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
> -   overflowed = false;
> -   }
> - else if (get_range_info (@1, &wmin1, &wmax1) == VR_RANGE)
> -   {
> - wi::mul (wmin0, wmin1, TYPE_SIGN (type), &min_ovf);
> - wi::mul (wmax0, wmax1, TYPE_SIGN (type), &max_ovf);
> - if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
> -   {
> - wi::mul (wmin0, wmax1, TYPE_SIGN (type), &min_ovf);
> - wi::mul (wmax0, wmin1, TYPE_SIGN (type), &max_ovf);
> - if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
> -   overflowed = false;
> -   }
> -   }
> -   }
> -  }
> - (if (!overflowed)
> -  @0)))
> +(with
> + {
> +   bool overflowed = true;
> +   wide_int wmin0, wmax0, wmin1, wmax1;
> +   if (INTEGRAL_TYPE_P (type)
> +&& get_range_info (@0, &wmin0, &wmax0) == VR_RANGE
> +&& get_range_info (@1, &wmin1, &wmax1) == VR_RANGE)
> +  {
> +/* If the multiplication can't overflow/wrap around, then
> +   it can be optimized too.  */
> +wi::overflow_type min_ovf, max_ovf;
> +wi::mul (wmin0, wmin1, 

Re: [PATCH] arm: [testsuite] fix lob tests for -mfloat-abi=hard

2020-11-27 Thread Andrea Corallo via Gcc-patches
Andrea Corallo via Gcc-patches  writes:

> "Richard Earnshaw (lists)"  writes:
>
>> On 26/11/2020 13:53, Andrea Corallo via Gcc-patches wrote:
>>> Hi all,
>>> 
>>> I'd like to submit the following simple patch to clean some Low Loop
>>> Overhead test failing on hard float configurations.
>>> 
>>> lob2.c and lob5.c are failing with: "'-mfloat-abi=hard': selected 
>>> processor lacks an FPU".
>>> 
>>> lob3.c and lob5.c got "-mfloat-abi=soft and -mfloat-abi=hard may not
>>> be used together".
>>> 
>>> Okay for trunk?
>>> 
>>> Thanks
>>>   Andrea
>>>   
>>> 
>>
>> I think it would be better to try to do this with suitable
>> require-effective-target rules (or something similar).  Forcing options
>> should generally be a last resort and in particular using -mfpu should
>> really be avoided as we're trying to move away from that.
>>
>> diff --git a/gcc/testsuite/gcc.target/arm/lob4.c
>> b/gcc/testsuite/gcc.target/arm/lob4.c
>> ...
>> -/* { dg-skip-if "avoid conflicting multilib options" { *-*-* } {
>> "-marm" "-mcpu=*" } } */
>> +/* { dg-skip-if "avoid conflicting multilib options" { *-*-* } {
>> "-marm" "-mcpu=*" "-mfloat-abi=hard" } } */
>>  /* { dg-options "-march=armv8.1-m.main -mthumb -O3 --save-temps
>> -mfloat-abi=soft" } */
>>  /* { dg-require-effective-target arm_softfloat } */
>>
>> Why is the effective target arm_softfloat not solving this particular
>> conflict?
>
> Good point,
>
> I see is because we are defining __SOFTFP__ when compiling with
> '-march=armv8.1-m.main+mve -mfloat-abi=hard'.
>
> This sounds like a bug to me, correct?

Hi Richard,

diving into it further I've been explained by a knowledgeable colleague
that '__SOFTFP__' indicates the use of emulated FP operations but says
nothing about the ABI, indeed this last is what we want to check here to
avoid the conflict.

OTOH our selector 'arm_softfloat' IIUC is claimed to select the ABI [1]

"ARM target uses the soft-float ABI with no floating-point instructions
used whatsoever (as selected with -mfloat-abi=soft). "

but is looking at '__SOFTFP__'.

What should be the right fix then?

Should we leave the skip "-mfloat-abi=hard" into the patch and update
the doc of the selector?

Thanks

  Andrea


[1] https://gcc.gnu.org/onlinedocs/gccint/Effective-Target-Keywords.html


Re: [PATCH v2] configury : Fix LEB128 support for non-GNU assemblers.

2020-11-27 Thread Jakub Jelinek via Gcc-patches
On Fri, Nov 27, 2020 at 10:29:53AM +, Iain Sandoe wrote:
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -3114,34 +3114,38 @@ AC_MSG_RESULT($gcc_cv_ld_ro_rw_mix)
>  gcc_AC_INITFINI_ARRAY
> 
>  # Check if we have .[us]leb128, and support symbol arithmetic with it.
> +# Older versions of GAS and some non-GNU assemblers, have a bugs handling

s/a bugs/bugs/

Otherwise LGTM, thanks.

Jakub



[Patch, committed] gfortran.dg/gomp/requires-4.f90: Fix !$omp syntax

2020-11-27 Thread Tobias Burnus

Found when grepping & post commit. There were two !$omp issues in
the testcase – which (currently) do not show up due to the previous
(and intended) errors.

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 6fb9b4c97690c5750e49c32fa2a373a7c66c5d46
Author: Tobias Burnus 
Date:   Fri Nov 27 11:45:14 2020 +0100

gfortran.dg/gomp/requires-4.f90: Fix !$omp clause

gcc/testsuite/
* gfortran.dg/gomp/requires-4.f90: Fix typo in '!$omp' clause.

diff --git a/gcc/testsuite/gfortran.dg/gomp/requires-4.f90 b/gcc/testsuite/gfortran.dg/gomp/requires-4.f90
index 0dc5e69da04..b17aceb898b 100644
--- a/gcc/testsuite/gfortran.dg/gomp/requires-4.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/requires-4.f90
@@ -30,7 +30,7 @@ contains
 !$omp end target
   end subroutine
   subroutine bar
-!$omp requires unified_addres ! { dg-error "must appear in the specification part of a program unit" }
+!$omp requires unified_address ! { dg-error "must appear in the specification part of a program unit" }
   end subroutine bar
 end
 ! { dg-prune-output "not yet supported" }

commit d78e106e95191f44274c8c9ba196abd6fd5ed558
Author: Tobias Burnus 
Date:   Fri Nov 27 11:40:11 2020 +0100

gfortran.dg/gomp/requires-4.f90: Fix !$omp syntax

gcc/testsuite/
* gfortran.dg/gomp/requires-4.f90: Fix '!$omp' syntax.

diff --git a/gcc/testsuite/gfortran.dg/gomp/requires-4.f90 b/gcc/testsuite/gfortran.dg/gomp/requires-4.f90
index e0eb4dbc603..0dc5e69da04 100644
--- a/gcc/testsuite/gfortran.dg/gomp/requires-4.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/requires-4.f90
@@ -26,8 +26,8 @@ program main
 !$omp requires reverse_offload
 contains
   subroutine foo
-!$target
-!$end target
+!$omp target
+!$omp end target
   end subroutine
   subroutine bar
 !$omp requires unified_addres ! { dg-error "must appear in the specification part of a program unit" }


RE: [PATCH] fold-const: Don't consider NaN non-negative [PR97965]

2020-11-27 Thread Roger Sayle

Hi Jakub,
Technically, PR97965 doesn't explicitly mention equality/inequality, but
you're
right, it makes sense to tackle this missed optimization at the same time as
we
fix the wrong-code.

On Thu, Nov 26, 2020, Jakub Jelinek wrote:
>On Thu, Nov 26, 2020 at 01:56:03PM -, Roger Sayle wrote:
>> --- a/gcc/match.pd
>> +++ b/gcc/match.pd
>> @@ -3998,7 +3998,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>>  (cmp @0 { build_real (TREE_TYPE (@1), dconst0); }))
>> /* x != NaN is always true, other ops are always false.  */
>> (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1))
>> -&& ! HONOR_SNANS (@1))
>> +&& ! flag_trapping_math)
>
>Shouldn't this one stay as is for cmp == EQ_EXPR || cmp == NE_EXPR?
>I mean, == or != only raise exceptions on sNaNs, while other simple
comparisons raise on both sNaNs and qNaNs.

The case to be careful of here is that (x == qNaN) can still raise/trap if x
is a sNaN.
Hence, the full condition should include:

&& (!flag_trapping_math
|| ((cmp == EQ_EXPR || cmp == NE_EXPR)
&& !tree_expr_maybe_signaling_nan_p (@1)
&& !tree_expr_maybe_signaling_nan_p (@0)))

Note: I repeat tree_expr_maybe_signaling_nan_p here for symmetry, though
because
we know @1 is a NaN, this could have been written as
!tree_expr_signaling_nan_p (@1).

>> --- a/gcc/simplify-rtx.c
>> +++ b/gcc/simplify-rtx.c
>> @@ -5732,12 +5732,13 @@ simplify_const_relational_operation (enum
rtx_code code,
>>if (REAL_VALUE_ISNAN (*d0) || REAL_VALUE_ISNAN (*d1))
>>  switch (code)
>>{
>> +  case NE:
>> +return flag_trapping_math ? 0 : const_true_rtx;
>
> And here too (for NE and would need moving EQ later too.

Yep/Agreed.  These cases become:

case NE:
if (flag_trapping_math
&& (REAL_VALUE_ISSIGNALING_NAN (*d0)
|| REAL_VALUE_ISSIGANLING_NAN (*d1)))
  return 0;
return const_true_rtx;

case EQ:
if (flag_trapping_math
&& (REAL_VALUE_ISSIGNALING_NAN (*d0)
|| REAL_VALUE_ISSIGANLING_NAN (*d1)))
  return 0;
return const0_rtx;


A revised patch is attached (which I've confirmed compiles but
haven't regression tested).

Many thanks again.

Roger
--

&& (!flag_trapping_math
|| ((cmp == EQ_EXPR || cmp == NE_EXPR)
&& !tree_expr_maybe_signaling_nan_p (@1)
&& !tree_expr_maybe_signaling_nan_p (@0)))

case NE:
if (flag_trapping_math
&& (REAL_VALUE_ISSIGNALING_NAN (*d0)
|| REAL_VALUE_ISSIGANLING_NAN (*d1)))
  return 0;
return const_true_rtx;

case EQ:
if (flag_trapping_math
&& (REAL_VALUE_ISSIGNALING_NAN (*d0)
|| REAL_VALUE_ISSIGANLING_NAN (*d1)))
  return 0;
return const0_rtx;



Re: [PATCH v2 01/31] PR target/58901: reload: Handle SUBREG of MEM with a mode-dependent address

2020-11-27 Thread Ulrich Weigand via Gcc-patches
On Tue, Nov 24, 2020 at 06:19:41AM +, Maciej W. Rozycki wrote: 

>  NB I find the reindentation resulting in `push_reload' awful, just as I 
> do either version of the massive logical expression involved.  Perhaps we 
> could factor these out into `static inline' functions sometime, and then 
> have them split into individual returns within?

I'm generally hesitant to do a lot of changes to the reload code base
at this stage.  The strategy rather is to move all remaining targets
over to LRA and then simply delete reload :-)

Given that you're modernizing the vax target, I'm wondering if you
shouldn't rather go all the way and move it over to LRA as well,
then you wouldn't be affected by any remaining reload deficiencies.
(The major hurdle so far was that LRA doesn't support CC0, but it
looks like you're removing that anyway ...)

> +  && (strict_low
> +   || (subreg_lowpart_p (in)
> +   && (CONSTANT_P (SUBREG_REG (in))
> +   || GET_CODE (SUBREG_REG (in)) == PLUS
> +   || strict_low

If we do this, then that "|| strict_low" clause is now redundant. 

> +   && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER
> +   && reg_equiv_mem (REGNO (SUBREG_REG (in)))
> +   && (mode_dependent_address_p
> +   (XEXP (reg_equiv_mem (REGNO (SUBREG_REG (in))), 0),
> +MEM_ADDR_SPACE (reg_equiv_mem (REGNO (SUBREG_REG (in)

I guess this is not incorrect, but I'm wondering if it would be
*complete* -- there are other cases where reload replaces a pseudo
with a MEM even where reg_equiv_mem is null.

That said, if it fixes the test suite errors you're seeing, it would
probably be OK to go with just this minimal change -- unless we can
just move to LRA as mentioned above.

Bye,
Ulrich

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


RE: [PATCH] fold-const: Don't consider NaN non-negative [PR97965]

2020-11-27 Thread Roger Sayle

Doh! Wrong patch2.txt file.  Sorry.

-Original Message-
From: Roger Sayle  
Sent: 27 November 2020 10:52
To: 'Jakub Jelinek' ; 'Joseph S. Myers'

Cc: 'Richard Biener' ; 'gcc-patches@gcc.gnu.org'

Subject: RE: [PATCH] fold-const: Don't consider NaN non-negative [PR97965]


Hi Jakub,
Technically, PR97965 doesn't explicitly mention equality/inequality, but
you're right, it makes sense to tackle this missed optimization at the same
time as we fix the wrong-code.

On Thu, Nov 26, 2020, Jakub Jelinek wrote:
>On Thu, Nov 26, 2020 at 01:56:03PM -, Roger Sayle wrote:
>> --- a/gcc/match.pd
>> +++ b/gcc/match.pd
>> @@ -3998,7 +3998,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>>  (cmp @0 { build_real (TREE_TYPE (@1), dconst0); }))
>> /* x != NaN is always true, other ops are always false.  */
>> (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1))
>> -&& ! HONOR_SNANS (@1))
>> +&& ! flag_trapping_math)
>
>Shouldn't this one stay as is for cmp == EQ_EXPR || cmp == NE_EXPR?
>I mean, == or != only raise exceptions on sNaNs, while other simple
comparisons raise on both sNaNs and qNaNs.

The case to be careful of here is that (x == qNaN) can still raise/trap if x
is a sNaN.
Hence, the full condition should include:

&& (!flag_trapping_math
|| ((cmp == EQ_EXPR || cmp == NE_EXPR)
&& !tree_expr_maybe_signaling_nan_p (@1)
&& !tree_expr_maybe_signaling_nan_p (@0)))

Note: I repeat tree_expr_maybe_signaling_nan_p here for symmetry, though
because we know @1 is a NaN, this could have been written as
!tree_expr_signaling_nan_p (@1).

>> --- a/gcc/simplify-rtx.c
>> +++ b/gcc/simplify-rtx.c
>> @@ -5732,12 +5732,13 @@ simplify_const_relational_operation (enum
rtx_code code,
>>if (REAL_VALUE_ISNAN (*d0) || REAL_VALUE_ISNAN (*d1))
>>  switch (code)
>>{
>> +  case NE:
>> +return flag_trapping_math ? 0 : const_true_rtx;
>
> And here too (for NE and would need moving EQ later too.

Yep/Agreed.  These cases become:

case NE:
if (flag_trapping_math
&& (REAL_VALUE_ISSIGNALING_NAN (*d0)
|| REAL_VALUE_ISSIGANLING_NAN (*d1)))
  return 0;
return const_true_rtx;

case EQ:
if (flag_trapping_math
&& (REAL_VALUE_ISSIGNALING_NAN (*d0)
|| REAL_VALUE_ISSIGANLING_NAN (*d1)))
  return 0;
return const0_rtx;


A revised patch is attached (which I've confirmed compiles but haven't
regression tested).

Many thanks again.

Roger
--

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 632a241a964..b76e80c02a3 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12007,8 +12007,8 @@ fold_binary_loc (location_t loc, enum tree_code code, 
tree type,
   strict_overflow_p = false;
   if (code == GE_EXPR
  && (integer_zerop (arg1)
- || (! HONOR_NANS (arg0)
- && real_zerop (arg1)))
+ || (real_zerop (arg1)
+ && !tree_expr_maybe_nan_p (arg0)))
  && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))
{
  if (strict_overflow_p)
@@ -12024,7 +12024,10 @@ fold_binary_loc (location_t loc, enum tree_code code, 
tree type,
   /* Convert ABS_EXPR < 0 to false.  */
   strict_overflow_p = false;
   if (code == LT_EXPR
- && (integer_zerop (arg1) || real_zerop (arg1))
+ && (integer_zerop (arg1)
+ || (real_zerop (arg1)
+ && (!flag_trapping_math
+ || !tree_expr_maybe_nan_p (arg0
  && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))
{
  if (strict_overflow_p)
diff --git a/gcc/match.pd b/gcc/match.pd
index b6dfc24af88..ef1bfb42d12 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4037,7 +4037,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (cmp @0 { build_real (TREE_TYPE (@1), dconst0); }))
/* x != NaN is always true, other ops are always false.  */
(if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1))
-   && ! HONOR_SNANS (@1))
+   && (!flag_trapping_math
+   || ((cmp == EQ_EXPR || cmp == NE_EXPR)
+   && !tree_expr_maybe_signaling_nan_p (@1)
+   && !tree_expr_maybe_signaling_nan_p (@0
 { constant_boolean_node (cmp == NE_EXPR, type); })
/* Fold comparisons against infinity.  */
(if (REAL_VALUE_ISINF (TREE_REAL_CST (@1))
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 47e7aebda8a..dd97a353bff 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -5732,20 +5732,31 @@ simplify_const_relational_operation (enum rtx_code code,
   if (REAL_VALUE_ISNAN (*d0) || REAL_VALUE_ISNAN (*d1))
switch (code)
  {
+ case NE:
+   if (flag_trapping_math
+   && (REAL_VALUE_ISSIGNALING_NAN (*d0)
+   || REAL_VALUE_ISSIGNALING_NAN (*d1)))
+ return 0;
+   return const_true_rtx;
  case UNEQ:
  case UNLT:
  case UNGT:
  case UNLE:
  c

Re: [committed] libstdc++: Use __libc_single_threaded for locale initialization

2020-11-27 Thread Jonathan Wakely via Gcc-patches

On 27/11/20 09:43 +0100, Stephan Bergmann via Libstdc++ wrote:

On 24/11/2020 15:59, Jonathan Wakely via Gcc-patches wrote:

Most initialization of locales and facets happens before main() during
startup, when the program is likely to only have one thread. By using
the new __gnu_cxx::__is_single_threaded() function instead of checking
__gthread_active_p() we can avoid using pthread_once or atomics for the
common case.

That said, I'm not sure why we don't just use a local static variable
instead, as __cxa_guard_acquire() already optimizes for the
single-threaded case:

  static const bool init = (_S_initialize_once(), true);

I'll revisit that for GCC 12.

libstdc++-v3/ChangeLog:

* src/c++98/locale.cc (locale::facet::_S_get_c_locale())
(locale::id::_M_id() const): Use __is_single_threaded.
* src/c++98/locale_init.cc (locale::_S_initialize()):
Likewise.

Tested powerpc64le-linux. Committed to trunk.


I now started to get weird crashes when running LibreOffice test code 
at least with Clang -fsanitize=address and latest libstdc++, where the 
Clang ASan machinery SEGVs while it wants to report some malloc/free 
issue.  That goes away when reverting this commit, and I think the 
root cause is that locale::facet::_S_initialize_once() now gets called 
twice:  First during __cxx_global_var_init when the process is still 
single threaded (so


 if (!__gnu_cxx::__is_single_threaded())

in locale::facet::_S_get_c_locale, reading __libc_single_threaded, is 
false, whereas


 if (__gthread_active_p())

would have been true even if the process still only had a single 
thread).  And again after the process has spawned further threads via 
pthread_create (flipping __libc_single_threaded) and calls 
std::ostringstream() -> ... std::locale() -> ..., at which point


 if (!__gnu_cxx::__is_single_threaded())

in locale::facet::_S_get_c_locale is true now.


Gah, yes, that's broken. Sorry. I'm reverting that part and testing
it now.

I still think we should just use local static variables here and let
the runtime do the initialization and optimize it for single-threaded,
but I'll leave that for GCC 12. There might be some reason that wasn't
done originally, maybe so the library could be built with
-fno-threadsafe-statics (which I don't think we should support) or
maybe just because it predates the threadsafe-static code working
well.



[PATCH] tree-optimization/98024 - fix rnflow regression

2020-11-27 Thread Richard Biener
The change to make PRE insertion iterate less had a typo in checking
successors RPO state.  Fixing this exposes that regular PRE insertion
when facing a value that is the same on all edges inserts an
assignment in place of a PHI node but fails to set up things so that
this insertion is not repeated (it correctly does not return
'new_stuff').  But with the new iteration scheme this causes us
to repeatedly insert such assignment and change AVAIL_OUT over to
the newly inserted expression.  The fix is to treat this as PHI
and insert into PHI_GEN, avoiding repetitive insertion.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2020-11-27  Richard Biener  

PR tree-optimization/98024
* tree-ssa-pre.c (insert): Fix successor RPO order check.
(do_pre_regular_insertion): When inserting an assignment
in place of an all-same-value PHI still record that into
PHI_GEN.
---
 gcc/tree-ssa-pre.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index e25cec7ffa1..a17a09af990 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -3471,6 +3471,7 @@ do_pre_regular_insertion (basic_block block, basic_block 
dom,
  add_to_value (val, newe);
  bitmap_value_replace_in_set (AVAIL_OUT (block), newe);
  bitmap_insert_into_set (NEW_SETS (block), newe);
+ bitmap_insert_into_set (PHI_GEN (block), newe);
}
}
 }
@@ -3808,13 +3809,14 @@ insert (void)
|= bitmap_value_replace_in_set (AVAIL_OUT (block), expr);
}
  /* We need to iterate if AVAIL_OUT of an already processed
-block source.  */
+block source changed.  */
  if (avail_out_changed && !changed)
{
  edge_iterator ei;
  edge e;
  FOR_EACH_EDGE (e, ei, block->succs)
-   if (bb_rpo[e->src->index] < idx)
+   if (e->dest->index != EXIT_BLOCK
+   && bb_rpo[e->dest->index] < idx)
  changed = true;
}
 
-- 
2.26.2


RE: [PATCH] aarch64: Introduce --param=aarch64-autovec-preference to select autovec preference in backend

2020-11-27 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Richard Sandiford 
> Sent: 27 November 2020 08:29
> To: Richard Biener 
> Cc: Kyrylo Tkachov ; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] aarch64: Introduce --param=aarch64-autovec-
> preference to select autovec preference in backend
> 
> Richard Biener  writes:
> > On Thu, Nov 26, 2020 at 6:18 PM Kyrylo Tkachov via Gcc-patches
> >  wrote:
> >>
> >> Hi all,
> >>
> >> This is a patch that introduces the aarch64-autovec-preference that can
> take values from 0 - 4, 0 being the default.
> >> It can be used to override the autovectorisation preferences in the
> backend:
> >> 0 - use default scheme
> >> 1 - only use Advanced SIMD
> >> 2 - only use SVE
> >> 3 - use Advanced SIMD and SVE, prefer Advanced SIMD in the event of a
> tie (as determined by costs)
> >> 4 - use Advanced SIMD and SVE, prefer SVE in the event of a tie (as
> determined by costs)
> >>
> >> It can valuable for experimentation when comparing SVE and Advanced
> SIMD autovectorisation strategies.
> >>
> >> It achieves this adjusting the order of the interleaved SVE and Advanced
> SIMD modes in aarch64_autovectorize_vector_modes.
> >> It also adjusts aarch64_preferred_simd_mode to use the new comparison
> function to pick Advanced SIMD or SVE to start with.
> >>
> >> Bootstrapped and tested on aarch64-none-linux-gnu.
> >> Ok for master (since it touches much SVE-related code by Richard I'd feel
> more comfortable with a second pair of eyes)?
> 
> LGTM.

Thanks, I've pushed it to master.
It also applies cleanly and bootstrap and testing on GCC 10 branch looks ok.
Is it okay to backport it there as well?

> 
> > Is this supposed to be used internally or for development purposes?
> > If users are supposed
> > to use this then a -m switch would be more appropriate (x86 for example
> has
> > -mprefer-vector-width)
> 
> I think it's more production vs. experimentation rather than developer
> vs. user.  Users shouldn't have to worry about this kind of thing when
> they're doing production builds: specifying -mcpu or -mtune should
> be enough to get the right behaviour.  But having a --param like this
> that we can point users at is useful for getting feedback or as an
> interim workaround until an optimisation bug is fixed.  And like you
> say, it's also useful for running experiments for development.

Indeed. I think eventually the compiler should be smart enough to transparently 
pick and mix SVE and Advanced SIMD
for a given -mcpu/-mtune, I wouldn't want production users to view this param 
as a long-term recommendation.

Thanks,
Kyrill

> 
> Thanks,
> Richard


Re: [PATCH] testsuite: i386: Extend effective-target checks for AVX512BW, AVX512DQ

2020-11-27 Thread Uros Bizjak via Gcc-patches
On Fri, Nov 27, 2020 at 11:08 AM Rainer Orth
 wrote:
>
> When using the Solaris/x86 assembler with gcc, a couple of testcases
> currently FAIL.  Those failures follow two patterns:
>
> FAIL: gcc.target/i386/avx512bw-vpmovb2m-2.c (test for excess errors)
> Excess errors:
> Assembler: avx512bw-vpmovb2m-2.c
> "/var/tmp//ccPh3IRc.s", line 58 : Invalid instruction argument
> Near line: "vpmovb2m%zmm0, %k0"
>
> and
>
> FAIL: gcc.target/i386/avx512dq-vreducesd-2.c (test for excess errors)
> Excess errors:
> Assembler: avx512dq-vreducesd-2.c
> "/var/tmp//ccVyU7Bc.s", line 54 : Invalid instruction argument
> Near line: "vreducesd   $35, {sae}, %xmm0, %xmm0, %xmm7"
>
> The first only started with
>
> x86: relax mask register constraints
>
> 2019-01-04  Jan Beulich  
>
> * config/i386/sse.md
> (_cmp3,
> [...]
>
> and is strange since even the current Intel 64 and IA-32 Architectures
> Software Developer's Manual only lists %k1 for vpmovb2m and related
> insns, and indeed the line assembles with %k0 changed to %k1.

This is a bug in the assembler. SDE just indexes registers in this
way, and %k0 can be assembled without problems:

  0:   62 f2 7e 48 29 c0   vpmovb2m %zmm0,%k0

>
> The second is due to the use of {sae}: either this is a Solaris as bug
> (the do claim AVX512DQ support) or they use a different syntax here:
> omitting {sae} lets the line assemble as well.
>
> To avoid those failures, I've extended the avx512bw and avx512dq
> effective-target checks to include code snippets that trigger the
> generation of those insns.
>
> Tested no i386-pc-solaris2.11 with as (the failures are gone, as
> expected) and gas (test results unchanged).
>
> Ok for master?

I think we should not change the tests. These are clear bugs in the
assembler, so they should be fixed in the assembler, not papered over
in the testsuite.

Uros.


Re: [PATCH] testsuite: i386: Extend effective-target checks for AVX512BW, AVX512DQ

2020-11-27 Thread Rainer Orth
Hi Uros,

> On Fri, Nov 27, 2020 at 11:08 AM Rainer Orth
>  wrote:
>>
>> When using the Solaris/x86 assembler with gcc, a couple of testcases
>> currently FAIL.  Those failures follow two patterns:
>>
>> FAIL: gcc.target/i386/avx512bw-vpmovb2m-2.c (test for excess errors)
>> Excess errors:
>> Assembler: avx512bw-vpmovb2m-2.c
>> "/var/tmp//ccPh3IRc.s", line 58 : Invalid instruction argument
>> Near line: "vpmovb2m%zmm0, %k0"
>>
>> and
>>
>> FAIL: gcc.target/i386/avx512dq-vreducesd-2.c (test for excess errors)
>> Excess errors:
>> Assembler: avx512dq-vreducesd-2.c
>> "/var/tmp//ccVyU7Bc.s", line 54 : Invalid instruction argument
>> Near line: "vreducesd   $35, {sae}, %xmm0, %xmm0, %xmm7"
>>
>> The first only started with
>>
>> x86: relax mask register constraints
>>
>> 2019-01-04  Jan Beulich  
>>
>> * config/i386/sse.md
>> (_cmp3,
>> [...]
>>
>> and is strange since even the current Intel 64 and IA-32 Architectures
>> Software Developer's Manual only lists %k1 for vpmovb2m and related
>> insns, and indeed the line assembles with %k0 changed to %k1.
>
> This is a bug in the assembler. SDE just indexes registers in this
> way, and %k0 can be assembled without problems:
>
>   0:   62 f2 7e 48 29 c0   vpmovb2m %zmm0,%k0

the SDM is confusingly expressed in this point.  Oh well...

>> The second is due to the use of {sae}: either this is a Solaris as bug
>> (the do claim AVX512DQ support) or they use a different syntax here:
>> omitting {sae} lets the line assemble as well.
>>
>> To avoid those failures, I've extended the avx512bw and avx512dq
>> effective-target checks to include code snippets that trigger the
>> generation of those insns.
>>
>> Tested no i386-pc-solaris2.11 with as (the failures are gone, as
>> expected) and gas (test results unchanged).
>>
>> Ok for master?
>
> I think we should not change the tests. These are clear bugs in the
> assembler, so they should be fixed in the assembler, not papered over
> in the testsuite.

Even if this happens, it will take some time until it reaches the field.
Besides, isn't it better to avoid lots of noise from failing tests with
a testsuite-only change that does no harm to working assemblers?

Rainer

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


Re: [committed] libstdc++: Use __libc_single_threaded for locale initialization

2020-11-27 Thread Jonathan Wakely via Gcc-patches

On 27/11/20 11:15 +, Jonathan Wakely wrote:

On 27/11/20 09:43 +0100, Stephan Bergmann via Libstdc++ wrote:

On 24/11/2020 15:59, Jonathan Wakely via Gcc-patches wrote:

Most initialization of locales and facets happens before main() during
startup, when the program is likely to only have one thread. By using
the new __gnu_cxx::__is_single_threaded() function instead of checking
__gthread_active_p() we can avoid using pthread_once or atomics for the
common case.

That said, I'm not sure why we don't just use a local static variable
instead, as __cxa_guard_acquire() already optimizes for the
single-threaded case:

 static const bool init = (_S_initialize_once(), true);

I'll revisit that for GCC 12.

libstdc++-v3/ChangeLog:

* src/c++98/locale.cc (locale::facet::_S_get_c_locale())
(locale::id::_M_id() const): Use __is_single_threaded.
* src/c++98/locale_init.cc (locale::_S_initialize()):
Likewise.

Tested powerpc64le-linux. Committed to trunk.


I now started to get weird crashes when running LibreOffice test 
code at least with Clang -fsanitize=address and latest libstdc++, 
where the Clang ASan machinery SEGVs while it wants to report some 
malloc/free issue.  That goes away when reverting this commit, and I 
think the root cause is that locale::facet::_S_initialize_once() now 
gets called twice:  First during __cxx_global_var_init when the 
process is still single threaded (so


if (!__gnu_cxx::__is_single_threaded())

in locale::facet::_S_get_c_locale, reading __libc_single_threaded, 
is false, whereas


if (__gthread_active_p())

would have been true even if the process still only had a single 
thread).  And again after the process has spawned further threads 
via pthread_create (flipping __libc_single_threaded) and calls 
std::ostringstream() -> ... std::locale() -> ..., at which point


if (!__gnu_cxx::__is_single_threaded())

in locale::facet::_S_get_c_locale is true now.


Gah, yes, that's broken. Sorry. I'm reverting that part and testing
it now.

I still think we should just use local static variables here and let
the runtime do the initialization and optimize it for single-threaded,
but I'll leave that for GCC 12. There might be some reason that wasn't
done originally, maybe so the library could be built with
-fno-threadsafe-statics (which I don't think we should support) or
maybe just because it predates the threadsafe-static code working
well.


Fixed with this patch, tested powerp64le-linux (glibc 2.32).

Pushed to trunk.

Thanks for the testing and bug report, as always.


commit 0d7d69ca4a8c05d883e07ee42058c9c6b0c72370
Author: Jonathan Wakely 
Date:   Fri Nov 27 11:00:15 2020

libstdc++: Partially revert r11-5314

The changes in r11-5314 are broken, because it means we don't use
__gthread_once for the first few initializations, but after the program
becomes multi-threaded we will repeat the initialization, using
__gthread_once once this time. This leads to memory errors.

The use of __is_single_threaded() in locale::id::_M_id() is OK, because
the side effects are the same either way.

libstdc++-v3/ChangeLog:

* src/c++98/locale.cc (locale::facet::_S_get_c_locale()):
Revert change to use __is_single_threaded.
* src/c++98/locale_init.cc (locale::_S_initialize()):
Likewise.

diff --git a/libstdc++-v3/src/c++98/locale.cc b/libstdc++-v3/src/c++98/locale.cc
index 9b3fc3515152..4c1612cc5dca 100644
--- a/libstdc++-v3/src/c++98/locale.cc
+++ b/libstdc++-v3/src/c++98/locale.cc
@@ -214,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   locale::facet::_S_get_c_locale()
   {
 #ifdef __GTHREADS
-if (!__gnu_cxx::__is_single_threaded())
+if (__gthread_active_p())
   __gthread_once(&_S_once, _S_initialize_once);
 else
 #endif
diff --git a/libstdc++-v3/src/c++98/locale_init.cc b/libstdc++-v3/src/c++98/locale_init.cc
index fc8416ba01a6..c3841ccbd3c9 100644
--- a/libstdc++-v3/src/c++98/locale_init.cc
+++ b/libstdc++-v3/src/c++98/locale_init.cc
@@ -320,7 +320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   locale::_S_initialize()
   {
 #ifdef __GTHREADS
-if (!__gnu_cxx::__is_single_threaded())
+if (__gthread_active_p())
   __gthread_once(&_S_once, _S_initialize_once);
 #endif
 if (!_S_classic)


[PATCH][pushed] changelog: allow flexible "cherry picked" format.

2020-11-27 Thread Martin Liška

It handles the following:
(cherry picked from commit c0c7270cc4efd896fe99f8ad5409dbef089a407f (testsuite 
changes only))

contrib/ChangeLog:

* gcc-changelog/git_commit.py: Use regex for cherry pick prefix.
* gcc-changelog/test_email.py: Test it.
* gcc-changelog/test_patches.txt: Likewise.
---
 contrib/gcc-changelog/git_commit.py| 20 +++-
 contrib/gcc-changelog/test_email.py|  2 ++
 contrib/gcc-changelog/test_patches.txt |  2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/contrib/gcc-changelog/git_commit.py 
b/contrib/gcc-changelog/git_commit.py
index 5f856660bb3..d0ac23c22aa 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -158,11 +158,11 @@ end_of_location_regex = re.compile(r'[\[<(:]')
 item_empty_regex = re.compile(r'\t(\* \S+ )?\(\S+\):\s*$')
 item_parenthesis_regex = re.compile(r'\t(\*|\(\S+\):)')
 revert_regex = re.compile(r'This reverts commit (?P\w+).$')
+cherry_pick_regex = re.compile(r'cherry picked from commit (?P\w+)')
 
 LINE_LIMIT = 100

 TAB_WIDTH = 8
 CO_AUTHORED_BY_PREFIX = 'co-authored-by: '
-CHERRY_PICK_PREFIX = '(cherry picked from commit '
 
 REVIEW_PREFIXES = ('reviewed-by: ', 'reviewed-on: ', 'signed-off-by: ',

'acked-by: ', 'tested-by: ', 'reported-by: ',
@@ -422,14 +422,16 @@ class GitCommit:
 continue
 elif lowered_line.startswith(REVIEW_PREFIXES):
 continue
-elif line.startswith(CHERRY_PICK_PREFIX):
-commit = line[len(CHERRY_PICK_PREFIX):].rstrip(')')
-if self.cherry_pick_commit:
-self.errors.append(Error('multiple cherry pick lines',
- line))
-else:
-self.cherry_pick_commit = commit
-continue
+else:
+m = cherry_pick_regex.search(line)
+if m:
+commit = m.group('hash')
+if self.cherry_pick_commit:
+msg = 'multiple cherry pick lines'
+self.errors.append(Error(msg, line))
+else:
+self.cherry_pick_commit = commit
+continue
 
 # ChangeLog name will be deduced later

 if not last_entry:
diff --git a/contrib/gcc-changelog/test_email.py 
b/contrib/gcc-changelog/test_email.py
index e38c3e52158..579194cdc24 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -355,6 +355,8 @@ class TestGccChangelog(unittest.TestCase):
 def test_backport(self):
 email = self.from_patch_glob('0001-asan-fix-RTX-emission.patch')
 assert not email.errors
+expected_hash = '8cff672cb9a132d3d3158c2edfc9a64b55292b80'
+assert email.cherry_pick_commit == expected_hash
 assert len(email.changelog_entries) == 1
 entry = list(email.to_changelog_entries())[0][1]
 assert entry.startswith('2020-06-11  Martin Liska  ')
diff --git a/contrib/gcc-changelog/test_patches.txt 
b/contrib/gcc-changelog/test_patches.txt
index 37f49c851ec..9e9c5cd893f 100644
--- a/contrib/gcc-changelog/test_patches.txt
+++ b/contrib/gcc-changelog/test_patches.txt
@@ -3145,7 +3145,7 @@ gcc/ChangeLog:
by using Pmode instead of ptr_mode.
 
 Co-Authored-By: Jakub Jelinek 

-(cherry picked from commit 8cff672cb9a132d3d3158c2edfc9a64b55292b80)
+(cherry picked from commit 8cff672cb9a132d3d3158c2edfc9a64b55292b80 (only 
part))
 ---
  gcc/asan.c | 1 +
  1 file changed, 1 insertion(+)
--
2.29.2



Re: [PATCH] aarch64: Introduce --param=aarch64-autovec-preference to select autovec preference in backend

2020-11-27 Thread Richard Sandiford via Gcc-patches
Kyrylo Tkachov  writes:
>> -Original Message-
>> From: Richard Sandiford 
>> Sent: 27 November 2020 08:29
>> To: Richard Biener 
>> Cc: Kyrylo Tkachov ; gcc-patches@gcc.gnu.org
>> Subject: Re: [PATCH] aarch64: Introduce --param=aarch64-autovec-
>> preference to select autovec preference in backend
>> 
>> Richard Biener  writes:
>> > On Thu, Nov 26, 2020 at 6:18 PM Kyrylo Tkachov via Gcc-patches
>> >  wrote:
>> >>
>> >> Hi all,
>> >>
>> >> This is a patch that introduces the aarch64-autovec-preference that can
>> take values from 0 - 4, 0 being the default.
>> >> It can be used to override the autovectorisation preferences in the
>> backend:
>> >> 0 - use default scheme
>> >> 1 - only use Advanced SIMD
>> >> 2 - only use SVE
>> >> 3 - use Advanced SIMD and SVE, prefer Advanced SIMD in the event of a
>> tie (as determined by costs)
>> >> 4 - use Advanced SIMD and SVE, prefer SVE in the event of a tie (as
>> determined by costs)
>> >>
>> >> It can valuable for experimentation when comparing SVE and Advanced
>> SIMD autovectorisation strategies.
>> >>
>> >> It achieves this adjusting the order of the interleaved SVE and Advanced
>> SIMD modes in aarch64_autovectorize_vector_modes.
>> >> It also adjusts aarch64_preferred_simd_mode to use the new comparison
>> function to pick Advanced SIMD or SVE to start with.
>> >>
>> >> Bootstrapped and tested on aarch64-none-linux-gnu.
>> >> Ok for master (since it touches much SVE-related code by Richard I'd feel
>> more comfortable with a second pair of eyes)?
>> 
>> LGTM.
>
> Thanks, I've pushed it to master.
> It also applies cleanly and bootstrap and testing on GCC 10 branch looks ok.
> Is it okay to backport it there as well?

OK from my POV, thanks.

Richard


[C++ patch] Re: Free more of CFG in release_function_body

2020-11-27 Thread Jan Hubicka
> > On Wed, Nov 25, 2020 at 3:11 PM Jan Hubicka  wrote:
> > >
> > > > On Tue, 24 Nov 2020, Jan Hubicka wrote:
> > > >
> > > > > Hi,
> > > > > at the end of processing function body we loop over basic blocks and
> > > > > free all edges while we do not free the rest.  I think this is 
> > > > > leftover
> > > > > from time eges was not garbage collected and we was not using 
> > > > > ggc_free.
> > > > > It makes more sense to free all associated structures (which is
> > > > > importnat for WPA memory footprint).
> > > > >
> > > > > Bootstrapped/regtested x86_64-linux, OK?
> > > >
> > > > OK.
> > >
> > > Unforutnately the patch does not surive LTO bootstrap.  The problem is
> > > that we keep DECL_INITIAL that points to blocks and blocks points to
> > > var_decls and these points to SSA_NAMES that points to statements and
> > > those points to basic blocks.
> > 
> > VAR_DECLs point to SSA_NAMEs?  It's the other way around.  We for sure
> > free SSA_NAMEs (well, maybe not explicitely with ggc_free).
> 
> I am going to debug this more carefully now.  I think it was VAR_DECL
> with variadic type pointing to SSA_NAME.  Should be easy to reduct with
> gcac compiler.

Hi,
it turns out that the pointers to statements leaks through saved scopes
in C++ FE.  Scopes seems to point to internal blocks of functions even
after we finish their compiling.

This patch adds code to free pointers.  I tried to clear saved_blocks
but it breaks since C++ finalization uses them, but it does not look
into previous class levels.

Patch lto-bootstraps/regtestes x86_64-linux with all languages. OK?

Honza

* cfg.c (free_block): Call ggc_free on BB itself.

* cp-tre.eh (cp_tree_c_finish_parsing): Declare.
* semantics.c (finish_translation_unit): Call finish_parsing
* tree.c (cp_tree_c_finish_parsing): New function.
diff --git a/gcc/cfg.c b/gcc/cfg.c
index 529b6ed2105..e8bd1456c9f 100644
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -102,8 +102,7 @@ free_block (basic_block bb)
bb->succs = NULL;
vec_free (bb->preds);
bb->preds = NULL;
-   /* Do not free BB itself yet since we leak pointers to dead statements
-  that points to dead basic blocks.  */
+   ggc_free (bb);
 }
 
 /* Free the memory associated with the CFG in FN.  */
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 021de76e142..665d171d9b0 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7986,6 +7986,8 @@ struct uid_sensitive_constexpr_evaluation_checker
   bool evaluation_restricted_p () const;
 };
 
+void cp_tree_c_finish_parsing ();
+
 /* In cp-ubsan.c */
 extern void cp_ubsan_maybe_instrument_member_call (tree);
 extern void cp_ubsan_instrument_member_accesses (tree *);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5ff70ff4844..e9d17c21985 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3094,6 +3094,7 @@ finish_translation_unit (void)
   "%<#pragma omp end declare target%>");
   scope_chain->omp_declare_target_attribute = 0;
 }
+  cp_tree_c_finish_parsing ();
 }
 
 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 28e591086b3..e63d383c0a3 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -5844,6 +5844,19 @@ maybe_warn_zero_as_null_pointer_constant (tree expr, 
location_t loc)
   return false;
 }
 
+/* Release memory we no longer need after parsing.  */
+void
+cp_tree_c_finish_parsing ()
+{
+  saved_scope *chain = scope_chain;
+  while (chain)
+{
+  chain->x_previous_class_level = NULL;
+  chain = chain->prev;
+}
+  deleted_copy_types = NULL;
+}
+
 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
 /* Complain that some language-specific thing hanging off a tree
node has been accessed improperly.  */


[committed] libstdc++: Fix -Wrange-loop-construct warnings in filesystem tests

2020-11-27 Thread Jonathan Wakely via Gcc-patches
Many tests do `for (const path& p : test_paths)` where test_paths is an
array of strings. To avoid -Wrange-loop-construct warnings the loop
variable should be an object, not a reference bound to a temporary.

Tested powerpc64le-linux and x86_64-w64-mingw32, pushed to trunk.


commit 4a7c7999086756b9d630ed6036eb7fdce69bb5cd
Author: Jonathan Wakely 
Date:   Fri Nov 27 12:15:44 2020

libstdc++: Fix -Wrange-loop-construct warnings in filesystem tests

Many tests do `for (const path& p : test_paths)` where test_paths is an
array of strings. To avoid -Wrange-loop-construct warnings the loop
variable should be an object, not a reference bound to a temporary.

libstdc++-v3/ChangeLog:

* testsuite/27_io/filesystem/operations/absolute.cc: Avoid
-Wrange-loop-construct warning.
* testsuite/27_io/filesystem/path/append/source.cc: Likewise.
* testsuite/27_io/filesystem/path/assign/copy.cc: Likewise.
* testsuite/27_io/filesystem/path/compare/path.cc: Likewise.
* testsuite/27_io/filesystem/path/construct/copy.cc: Likewise.
* testsuite/27_io/filesystem/path/decompose/extension.cc:
Likewise.
* testsuite/27_io/filesystem/path/decompose/filename.cc:
Likewise.
* testsuite/27_io/filesystem/path/decompose/parent_path.cc:
Likewise.
* testsuite/27_io/filesystem/path/decompose/relative_path.cc:
Likewise.
* testsuite/27_io/filesystem/path/decompose/root_directory.cc:
Likewise.
* testsuite/27_io/filesystem/path/decompose/root_path.cc:
Likewise.
* testsuite/27_io/filesystem/path/itr/traversal.cc: Likewise.
* testsuite/27_io/filesystem/path/modifiers/remove_filename.cc:
Likewise.
* testsuite/27_io/filesystem/path/modifiers/replace_extension.cc:
Likewise.
* testsuite/27_io/filesystem/path/modifiers/replace_filename.cc:
Likewise.
* testsuite/27_io/filesystem/path/nonmember/append.cc: Likewise.
* testsuite/27_io/filesystem/path/nonmember/cmp.cc: Likewise.
* testsuite/27_io/filesystem/path/nonmember/cmp_c++20.cc:
Likewise.
* testsuite/27_io/filesystem/path/nonmember/hash_value.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_extension.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_filename.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_parent_path.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_relative_path.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_root_directory.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_root_name.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_root_path.cc:
Likewise.
* testsuite/27_io/filesystem/path/query/has_stem.cc: Likewise.
* testsuite/27_io/filesystem/path/query/is_relative.cc: Likewise.
* testsuite/experimental/filesystem/operations/absolute.cc:
Likewise.
* testsuite/experimental/filesystem/path/assign/copy.cc: Likewise.
* testsuite/experimental/filesystem/path/compare/path.cc:
Likewise.
* testsuite/experimental/filesystem/path/construct/copy.cc:
Likewise.
* testsuite/experimental/filesystem/path/decompose/extension.cc:
Likewise.
* testsuite/experimental/filesystem/path/decompose/filename.cc:
Likewise.
* testsuite/experimental/filesystem/path/decompose/parent_path.cc:
Likewise.
* testsuite/experimental/filesystem/path/decompose/relative_path.cc:
Likewise.
* 
testsuite/experimental/filesystem/path/decompose/root_directory.cc:
Likewise.
* testsuite/experimental/filesystem/path/decompose/root_path.cc:
Likewise.
* testsuite/experimental/filesystem/path/itr/traversal.cc:
Likewise.
* 
testsuite/experimental/filesystem/path/modifiers/remove_filename.cc:
Likewise.
* 
testsuite/experimental/filesystem/path/modifiers/replace_extension.cc:
Likewise.
* 
testsuite/experimental/filesystem/path/modifiers/replace_filename.cc:
Likewise.
* testsuite/experimental/filesystem/path/nonmember/hash_value.cc:
Likewise.
* testsuite/experimental/filesystem/path/query/has_extension.cc:
Likewise.
* testsuite/experimental/filesystem/path/query/has_filename.cc:
Likewise.
* testsuite/experimental/filesystem/path/query/has_parent_path.cc:
Likewise.
* testsu

[PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread H.J. Lu via Gcc-patches
PR other/98027
* doc/install: Default to --enable-cet=auto.
---
 gcc/doc/install.texi | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 5f879ca4cea..021c347cc09 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -2259,11 +2259,10 @@ instrumentation, see @option{-fcf-protection} option.  
When
 to add @option{-fcf-protection} and, if needed, other target
 specific options to a set of building options.
 
-The option is disabled by default.  When @code{--enable-cet=auto}
-is used, it is enabled on Linux/x86 if target binutils
-supports @code{Intel CET} instructions and disabled otherwise.
-In this case the target libraries are configured to get additional
-@option{-fcf-protection} option.
+@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
+target binutils supports @code{Intel CET} instructions and disabled
+otherwise.  In this case, the target libraries are configured to get
+additional @option{-fcf-protection} option.
 
 @item --with-riscv-attribute=@samp{yes}, @samp{no} or @samp{default}
 Generate RISC-V attribute by default, in order to record extra build
-- 
2.28.0



Re: Decompose OpenACC 'kernels' constructs into parts, a sequence of compute constructs

2020-11-27 Thread Thomas Schwinge
Hi!

On 2020-11-13T23:22:30+0100, I wrote:
> [...] I've pushed to master branch [...] commit
> e898ce7997733c29dcab9c3c62ca102c7f9fa6eb "Decompose OpenACC 'kernels'
> constructs into parts, a sequence of compute constructs", see attached.
>
>> There's more work to be done there, and we're aware of a number of TODO
>> items, but nevertheless: it's a good first step.

> --- /dev/null
> +++ b/gcc/omp-oacc-kernels-decompose.cc

> +/* Eliminate any binds directly inside BIND by adding their statements to
> +   BIND (i.e., modifying it in place), excluding binds that hold only an
> +   OMP_FOR loop and associated setup/cleanup code.  Recurse into binds but
> +   not other statements.  Return a chain of the local variables of eliminated
> +   binds, i.e., the local variables found in nested binds.  If
> +   INCLUDE_TOPLEVEL_VARS is true, this also includes the variables belonging
> +   to BIND itself. */
> +
> +static tree
> +flatten_binds (gbind *bind, bool include_toplevel_vars = false)
> +{
> +  tree vars = NULL, last_var = NULL;
> +
> +  if (include_toplevel_vars)
> +{
> +  vars = gimple_bind_vars (bind);
> +  last_var = vars;
> +}
> +
> +  gimple_seq new_body = NULL;
> +  gimple_seq body_sequence = gimple_bind_body (bind);
> +  gimple_stmt_iterator gsi, gsi_n;
> +  for (gsi = gsi_start (body_sequence); !gsi_end_p (gsi); gsi = gsi_n)
> +{
> +  /* Advance the iterator here because otherwise it would be invalidated
> +  by moving statements below.  */
> +  gsi_n = gsi;
> +  gsi_next (&gsi_n);
> +
> +  gimple *stmt = gsi_stmt (gsi);
> +  /* Flatten bind statements, except the ones that contain only an
> +  OpenACC for loop.  */
> +  if (gimple_code (stmt) == GIMPLE_BIND
> +   && !top_level_omp_for_in_stmt (stmt))
> + {
> +   gbind *inner_bind = as_a  (stmt);
> +   /* Flatten recursively, and collect all variables.  */
> +   tree inner_vars = flatten_binds (inner_bind, true);
> +   gimple_seq inner_sequence = gimple_bind_body (inner_bind);
> +   gcc_assert (gimple_code (inner_sequence) != GIMPLE_BIND
> +   || top_level_omp_for_in_stmt (inner_sequence));

First, this gives rise to the ICE documented in
'c-c++-common/goacc/kernels-decompose-ice-2.c': 'inner_sequence' is
'NULL' in this case (which is valid, meaning no statements in
'GIMPLE_BIND'), but 'gimple_code' then attempts to dereference 'NULL';
SIGSEGV.

Second, it seems strange to examine only the first statement of inner
'GIMPLE_BIND' (via 'inner_sequence' being a 'typedef gimple *gimple_seq'),
so I changed that to examine all statements contained therein, which I
suppose must've been the intention here.  (This also conveniently fixes
the ICE mentioned above.)

I've pushed "In 'gcc/omp-oacc-kernels-decompose.cc:flatten_binds', don't
choke on empty GIMPLE sequence" to master branch in commit
4b5726fda653d11f882fb9a112e4cffa12f7ed61, see attached.


Grüße
 Thomas


> +   gimple_seq_add_seq (&new_body, inner_sequence);
> +   /* Find the last variable; we will append others to it.  */
> +   while (last_var != NULL && TREE_CHAIN (last_var) != NULL)
> + last_var = TREE_CHAIN (last_var);
> +   if (last_var != NULL)
> + {
> +   TREE_CHAIN (last_var) = inner_vars;
> +   last_var = inner_vars;
> + }
> +   else
> + {
> +   vars = inner_vars;
> +   last_var = vars;
> + }
> + }
> +  else
> + gimple_seq_add_stmt (&new_body, stmt);
> +}
> +
> +  /* Put the possibly transformed body back into the bind.  */
> +  gimple_bind_set_body (bind, new_body);
> +  return vars;
> +}

> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
> @@ -0,0 +1,16 @@
> +/* Test OpenACC 'kernels' construct decomposition.  */
> +
> +/* { dg-additional-options "-fopenacc-kernels=decompose" } */
> +/* { dg-ice "TODO" }
> +   { dg-prune-output "during GIMPLE pass: omp_oacc_kernels_decompose" } */
> +
> +/* Reduced from 'kernels-decompose-ice-1.c'.  */
> +
> +int
> +main ()
> +{
> +#pragma acc kernels
> +  {
> +int i;
> +  }
> +}


-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
>From 4b5726fda653d11f882fb9a112e4cffa12f7ed61 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Fri, 27 Nov 2020 11:54:50 +0100
Subject: [PATCH] In 'gcc/omp-oacc-kernels-decompose.cc:flatten_binds', don't
 choke on empty GIMPLE sequence

Also, instead of just examining the first statement of inner 'GIMPLE_BIND' (via
'inner_sequence' being a 'typedef gimple *gimple_seq'), in fact examine all
statements contained therein, which I suppose must've been the intention here.

This "fixes" the testcase 'c-c++-common/goacc/kernels-decompose-ice-2.c' (which
now runs into the same ICE as 'c-c++-common/goacc/kernels-decompose-ice-1.c',
etc.).

	gcc/
	* omp-oacc-kernels

Re: [PATCH 1/7] arm: Auto-vectorization for MVE: vand

2020-11-27 Thread Andre Vieira (lists) via Gcc-patches

Hi Christophe,

On 26/11/2020 15:31, Christophe Lyon wrote:

Hi Andre,

Thanks for the quick feedback.

On Wed, 25 Nov 2020 at 18:17, Andre Simoes Dias Vieira
 wrote:

Hi Christophe,

Thanks for these! See some inline comments.

On 25/11/2020 13:54, Christophe Lyon via Gcc-patches wrote:

This patch enables MVE vandq instructions for auto-vectorization.  MVE
vandq insns in mve.md are modified to use 'and' instead of unspec
expression to support and3.  The and3 expander is added to
vec-common.md

2020-11-12  Christophe Lyon  

   gcc/
   * gcc/config/arm/iterators.md (supf): Remove VANDQ_S and VANDQ_U.
   (VANQ): Remove.
   * config/arm/mve.md (mve_vandq_u): New entry for vand
   instruction using expression and.
   (mve_vandq_s): New expander.
   * config/arm/neon.md (and3): Renamed into and3_neon.
   * config/arm/unspecs.md (VANDQ_S, VANDQ_U): Remove.
   * config/arm/vec-common.md (and3): New expander.

   gcc/testsuite/
   * gcc.target/arm/simd/mve-vand.c: New test.
---
   gcc/config/arm/iterators.md  |  4 +---
   gcc/config/arm/mve.md| 20 
   gcc/config/arm/neon.md   |  2 +-
   gcc/config/arm/unspecs.md|  2 --
   gcc/config/arm/vec-common.md | 15 
   gcc/testsuite/gcc.target/arm/simd/mve-vand.c | 34 

   6 files changed, 66 insertions(+), 11 deletions(-)
   create mode 100644 gcc/testsuite/gcc.target/arm/simd/mve-vand.c

diff --git a/gcc/config/arm/iterators.md b/gcc/config/arm/iterators.md
index 592af35..72039e4 100644
--- a/gcc/config/arm/iterators.md
+++ b/gcc/config/arm/iterators.md
@@ -1232,8 +1232,7 @@ (define_int_attr supf [(VCVTQ_TO_F_S "s") (VCVTQ_TO_F_U "u") 
(VREV16Q_S "s")
  (VADDLVQ_P_U "u") (VCMPNEQ_U "u") (VCMPNEQ_S "s")
  (VABDQ_M_S "s") (VABDQ_M_U "u") (VABDQ_S "s")
  (VABDQ_U "u") (VADDQ_N_S "s") (VADDQ_N_U "u")
-(VADDVQ_P_S "s") (VADDVQ_P_U "u") (VANDQ_S "s")
-(VANDQ_U "u") (VBICQ_S "s") (VBICQ_U "u")
+(VADDVQ_P_S "s") (VADDVQ_P_U "u") (VBICQ_S "s") (VBICQ_U 
"u")
  (VBRSRQ_N_S "s") (VBRSRQ_N_U "u") (VCADDQ_ROT270_S "s")
  (VCADDQ_ROT270_U "u") (VCADDQ_ROT90_S "s")
  (VCMPEQQ_S "s") (VCMPEQQ_U "u") (VCADDQ_ROT90_U "u")
@@ -1501,7 +1500,6 @@ (define_int_iterator VABDQ [VABDQ_S VABDQ_U])
   (define_int_iterator VADDQ_N [VADDQ_N_S VADDQ_N_U])
   (define_int_iterator VADDVAQ [VADDVAQ_S VADDVAQ_U])
   (define_int_iterator VADDVQ_P [VADDVQ_P_U VADDVQ_P_S])
-(define_int_iterator VANDQ [VANDQ_U VANDQ_S])
   (define_int_iterator VBICQ [VBICQ_S VBICQ_U])
   (define_int_iterator VBRSRQ_N [VBRSRQ_N_U VBRSRQ_N_S])
   (define_int_iterator VCADDQ_ROT270 [VCADDQ_ROT270_S VCADDQ_ROT270_U])
diff --git a/gcc/config/arm/mve.md b/gcc/config/arm/mve.md
index ecbaaa9..975eb7d 100644
--- a/gcc/config/arm/mve.md
+++ b/gcc/config/arm/mve.md
@@ -894,17 +894,27 @@ (define_insn "mve_vaddvq_p_"
   ;;
   ;; [vandq_u, vandq_s])
   ;;
-(define_insn "mve_vandq_"
+;; signed and unsigned versions are the same: define the unsigned
+;; insn, and use an expander for the signed one as we still reference
+;; both names from arm_mve.h.
+(define_insn "mve_vandq_u"
 [
  (set (match_operand:MVE_2 0 "s_register_operand" "=w")
- (unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "w")
-(match_operand:MVE_2 2 "s_register_operand" "w")]
-  VANDQ))
+ (and:MVE_2 (match_operand:MVE_2 1 "s_register_operand" "w")
+(match_operand:MVE_2 2 "s_register_operand" "w")))

The predicate on the second operand is more restrictive than the one in
expand 'neon_inv_logic_op2'. This should still work with immediates, or
well I checked for integers, it generates a loop as such:


Right, thanks for catching it.


  vldrw.32q3, [r0]
  vldr.64 d4, .L8
  vldr.64 d5, .L8+8
  vandq3, q3, q2
  vstrw.32q3, [r2]

MVE does support vand's with immediates, just like NEON, I suspect you
could just copy the way Neon handles these, possibly worth the little
extra effort. You can use dest[i] = a[i] & ~1 as a testcase.
If you don't it might still be worth expanding the test to make sure
other immediates-types combinations don't trigger an ICE?

I'm not sure I understand why it loads it in two 64-bit chunks and not
do a single load or not just do something like a vmov or vbic immediate.
Anyhow that's a worry for another day I guess..

Do you mean something like the attached (on top of this patch)?
I dislike the code duplication in mve_vandq_u which would
become a copy of and3_neon.

Hi Christophe,

Yeah that's what I meant. I agree with the code duplication. The reason 
we still use separate ones is because of the difference in supported 
modes. Maybe the right way around tha

Re: OpenACC 'kernels' testsuite failures

2020-11-27 Thread Thomas Schwinge
Hi David!

On 2020-11-24T15:29:17-0500, David Edelsohn via Gcc-patches 
 wrote:
> On Tue, Nov 24, 2020 at 5:19 AM Thomas Schwinge  
> wrote:
>> On 2020-11-21T10:50:10-0500, David Edelsohn  wrote:
>> > I see
>> >
>> > "during GIMPLE pass: omplower"
>> >
>> > message for kernels-decompose-ice-2.c.  kernels-decompose-ice-1.c
>> > explicitly prunes that output, but kernels-decompose-ice-2.c does not.
>> > Is there a reason that the second testcase does not prune that output
>> > or can we add it?
>>
>> So, the expectation (as verified by my x86_64-pc-linux-gnu and
>> powerpc64le-unknown-linux-gnu testing) is that
>> 'c-c++-common/goacc/kernels-decompose-ice-1.c' (currently) runs into an
>> ICE "during GIMPLE pass: omplower", and
>> 'c-c++-common/goacc/kernels-decompose-ice-2.c' (currently) runs into an
>> ICE "during GIMPLE pass: omp_oacc_kernels_decompose".
>>
>> Now, you're reporting that for the latter testcase you're instead also
>> seeing an ICE "during GIMPLE pass: omplower".  Can you please show the
>> full ICE report/backtrace, so that we verify that it's not yet another
>> separate issue?

On gcc119 ('uname -a': "AIX power8-aix 2 7 00F9C1964C00"), I've now also
reproduced the issue.

>> Maybe the AIX system configuration (ABI?)
>> mandates/causes some slight difference in how front ends set attributes
>> such as 'TREE_ADDRESSABLE' on DECLs, which 'omp_oacc_kernels_decompose'
>> (currently) is sensitive to (hence the ICEs).

That's not the case; the input into 'omp_oacc_kernels_decompose' seems to
be exactly the same as on other systems.

> The error messages reported on AIX are:
>
> Executing on host: /tmp/GCC/gcc/xgcc -B/tmp/GCC/gcc/ 
> /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
> -fdiagnostics-plain-output   -fopenacc -fopenacc-kernels=decompose -S -o 
> kernels-decompose-ice-2.s(timeout = 300)
> spawn -ignore SIGHUP /tmp/GCC/gcc/xgcc -B/tmp/GCC/gcc/ 
> /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
>  -fdiagnostics-plain-output -fopenacc -fopenacc-kernels=decompose -S -o 
> kernels-decompose-ice-2.s
> during GIMPLE pass: omplower
> /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:
>  In function 'main':
> /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:13:9:
> internal compiler error: in lower_omp_target, at omp-low.c:12216

That's indeed the location of the 'gcc_assert' responsible for the
'omplower' ICE, which currently is expected, if we don't run into the
'omp_oacc_kernels_decompose' ICE first.  It's still strange however, why
we're seeing this "for AIX" (not better classified) only: I suppose it
isn't a feature "of AIX" that it can dereference a 'NULL' pointer ;-) --
which is what seems to be happening here:

742   gimple_seq inner_sequence = gimple_bind_body (inner_bind);
(gdb) next
743   gcc_assert (gimple_code (inner_sequence) != GIMPLE_BIND
(gdb) print inner_sequence
$1 = (gimple_seq) 0x0
(gdb) next
745   gimple_seq_add_seq (&new_body, inner_sequence);

So we have 'inner_sequence == NULL', and yet the 'next' didn't trigger a
SIGSEGV in:

static inline enum gimple_code
gimple_code (const gimple *g)
{
  return g->code;
}

Strange, isn't it?


However: this issue should now (indirectly) be fixed via "In
'gcc/omp-oacc-kernels-decompose.cc:flatten_binds', don't choke on empty
GIMPLE sequence" that I've just pushed to master branch in commit
4b5726fda653d11f882fb9a112e4cffa12f7ed61.


> during GIMPLE pass: omplower
> /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:
>  In function 'main':
> /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:13:9:
> internal compiler error: in lower_omp_target, at omp-low.c:12216
> ranges offset out of range

That last line actually comes from here:

libbacktrace/dwarf.c:  error_callback (data, "ranges offset out of 
range", 0);


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


Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread Richard Biener
OK.

On Fri, 27 Nov 2020, H.J. Lu wrote:

>   PR other/98027
>   * doc/install: Default to --enable-cet=auto.
> ---
>  gcc/doc/install.texi | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> index 5f879ca4cea..021c347cc09 100644
> --- a/gcc/doc/install.texi
> +++ b/gcc/doc/install.texi
> @@ -2259,11 +2259,10 @@ instrumentation, see @option{-fcf-protection} option. 
>  When
>  to add @option{-fcf-protection} and, if needed, other target
>  specific options to a set of building options.
>  
> -The option is disabled by default.  When @code{--enable-cet=auto}
> -is used, it is enabled on Linux/x86 if target binutils
> -supports @code{Intel CET} instructions and disabled otherwise.
> -In this case the target libraries are configured to get additional
> -@option{-fcf-protection} option.
> +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
> +target binutils supports @code{Intel CET} instructions and disabled
> +otherwise.  In this case, the target libraries are configured to get
> +additional @option{-fcf-protection} option.
>  
>  @item --with-riscv-attribute=@samp{yes}, @samp{no} or @samp{default}
>  Generate RISC-V attribute by default, in order to record extra build
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend


Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread H.J. Lu via Gcc-patches
On Fri, Nov 27, 2020 at 6:24 AM Richard Biener  wrote:
>
> OK.
>
> On Fri, 27 Nov 2020, H.J. Lu wrote:
>
> >   PR other/98027
> >   * doc/install: Default to --enable-cet=auto.
> > ---
> >  gcc/doc/install.texi | 9 -
> >  1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> > index 5f879ca4cea..021c347cc09 100644
> > --- a/gcc/doc/install.texi
> > +++ b/gcc/doc/install.texi
> > @@ -2259,11 +2259,10 @@ instrumentation, see @option{-fcf-protection} 
> > option.  When
> >  to add @option{-fcf-protection} and, if needed, other target
> >  specific options to a set of building options.
> >
> > -The option is disabled by default.  When @code{--enable-cet=auto}
> > -is used, it is enabled on Linux/x86 if target binutils
> > -supports @code{Intel CET} instructions and disabled otherwise.
> > -In this case the target libraries are configured to get additional
> > -@option{-fcf-protection} option.
> > +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
> > +target binutils supports @code{Intel CET} instructions and disabled
> > +otherwise.  In this case, the target libraries are configured to get
> > +additional @option{-fcf-protection} option.
> >
> >  @item --with-riscv-attribute=@samp{yes}, @samp{no} or @samp{default}
> >  Generate RISC-V attribute by default, in order to record extra build
> >
>

OK for backport to GCC 10?

-- 
H.J.


Re: [PATCH v2] Add if-chain to switch conversion pass.

2020-11-27 Thread Martin Liška

On 11/20/20 3:37 PM, Richard Biener wrote:

On Fri, Nov 20, 2020 at 9:57 AM Martin Liška  wrote:


On 11/19/20 3:46 PM, Richard Biener wrote:

OK, so can you send an updated patch?


+  tree pos_one = build_int_cst (type, 1);
+  if (!left->m_has_forward_bb
+ && !right->m_has_forward_bb
+ && left->m_case_bb == right->m_case_bb)
+   {
+ tree next = int_const_binop (PLUS_EXPR, left->get_high (), pos_one);
+ if (tree_int_cst_equal (next, right->get_low ()))

can you please avoid tree arithmetic here and use wide_ints?

   if (wi::eq (wi::to_wide (right->get_low) - wi::to_wide
(left->get_high), wi::one (TYPE_PRECISION (type))

?

+  info.record_phi_mapping (info.m_true_edge,
+  &info.m_true_edge_phi_mapping);
+  info.record_phi_mapping (info.m_false_edge,
+  &info.m_false_edge_phi_mapping);

you still have this edge mapping stuff, can't you recover the actual
PHI arguments from the PHIs during code generation?  I see you removed
the restriction for all-same values, good.

+unsigned int
+pass_if_to_switch::execute (function *fun)
+{
+  auto_vec all_candidates;
+  hash_map conditions_in_bbs;
+
+  basic_block bb;
+  FOR_EACH_BB_FN (bb, fun)
+find_conditions (bb, &conditions_in_bbs);
+

if we didn't find any suitable conditions we can early out

+  free_dominance_info (CDI_DOMINATORS);
+
+  if (!all_candidates.is_empty ())
+mark_virtual_operands_for_renaming (fun);

please do not free dominator info when you did nothing
(all_candidates.is_empty ()).

+ gcond *cond = chain->m_entries[0]->m_cond;
+ expanded_location loc = expand_location (gimple_location (cond));
+ if (dump_file)
+   {
+ fprintf (dump_file, "Condition chain (at %s:%d) with %d BBs "
+  "transformed into a switch statement.\n",
+  loc.file, loc.line,
+  chain->m_entries.length ());
+   }

if you use dump_enabled_p () and dump_printf_loc you can
use 'cond' as location itself.

Otherwise looks OK.


Hello.

I fixed all the notes except the PHI mapping map. It's really not simple
to reconstruct PHI nodes during code-gen. Once a BB is removed in transform 
phase,
I would need to investigate which PHIs have "holes" (missing PHI argument).

Moreover, I do the very similar thing in 
gcc/tree-switch-conversion.c::record_phi_operand_mapping.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
And I run SPEC2006 benchmarks, it has done 413 transformations.

Martin



Thanks,
Richard.


Sure.

Martin


>From 9d36dec1109ff9dc6c3a707f976c952c2cd1ddbb Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Fri, 28 Aug 2020 10:26:13 +0200
Subject: [PATCH] Add if-chain to switch conversion pass.

gcc/ChangeLog:

	PR tree-optimization/14799
	PR ipa/88702
	* Makefile.in: Add gimple-if-to-switch.o.
	* dbgcnt.def (DEBUG_COUNTER): Add new debug counter.
	* passes.def: Include new pass_if_to_switch pass.
	* timevar.def (TV_TREE_IF_TO_SWITCH): New timevar.
	* tree-pass.h (make_pass_if_to_switch): New.
	* tree-ssa-reassoc.c (struct operand_entry): Move to the header.
	(dump_range_entry): Move to header file.
	(debug_range_entry): Likewise.
	(no_side_effect_bb): Make it global.
	* tree-switch-conversion.h (simple_cluster::simple_cluster):
	Add inline for couple of functions in order to prevent error
	about multiple defined symbols.
	* gimple-if-to-switch.cc: New file.
	* tree-ssa-reassoc.h: New file.

gcc/testsuite/ChangeLog:

	PR tree-optimization/14799
	PR ipa/88702
	* gcc.dg/tree-ssa/pr96480.c: Disable if-to-switch conversion.
	* gcc.dg/tree-ssa/reassoc-32.c: Likewise.
	* g++.dg/tree-ssa/if-to-switch-1.C: New test.
	* gcc.dg/tree-ssa/if-to-switch-1.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-2.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-3.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-4.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-5.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-6.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-7.c: New test.
	* gcc.dg/tree-ssa/if-to-switch-8.c: New test.
---
 gcc/Makefile.in   |   1 +
 gcc/dbgcnt.def|   1 +
 gcc/gimple-if-to-switch.cc| 566 ++
 gcc/passes.def|   1 +
 .../g++.dg/tree-ssa/if-to-switch-1.C  |  25 +
 .../gcc.dg/tree-ssa/if-to-switch-1.c  |  35 ++
 .../gcc.dg/tree-ssa/if-to-switch-2.c  |  11 +
 .../gcc.dg/tree-ssa/if-to-switch-3.c  |  11 +
 .../gcc.dg/tree-ssa/if-to-switch-4.c  |  36 ++
 .../gcc.dg/tree-ssa/if-to-switch-5.c  |  12 +
 .../gcc.dg/tree-ssa/if-to-switch-6.c  |  42 ++
 .../gcc.dg/tree-ssa/if-to-switch-7.c  |  25 +
 .../gcc.dg/tree-ssa/if-to-switch-8.c  |  27 +
 gcc/testsuite/gcc.dg/tree-ssa/pr96480.c   |   2 +-
 gcc/testsuite/gcc.dg/tree-ssa/reass

Re: [PATCH 0/3] Enable PGO/LTO build for binutils+gdb

2020-11-27 Thread Martin Liška

On 10/29/20 8:11 PM, H.J. Lu wrote:

Add the --enable-pgo-build[=lto] configure option.  When binutils+gdb
is not built together with GCC, --enable-pgo-build enables the PGO build:


I would like to support the patch. It significantly speeds up gas for free
(based on my measurements).

Thanks,
Martin


Re: [PATCH 1/7] arm: Auto-vectorization for MVE: vand

2020-11-27 Thread Christophe Lyon via Gcc-patches
On Fri, 27 Nov 2020 at 15:13, Andre Vieira (lists)
 wrote:
>
> Hi Christophe,
>
> On 26/11/2020 15:31, Christophe Lyon wrote:
> > Hi Andre,
> >
> > Thanks for the quick feedback.
> >
> > On Wed, 25 Nov 2020 at 18:17, Andre Simoes Dias Vieira
> >  wrote:
> >> Hi Christophe,
> >>
> >> Thanks for these! See some inline comments.
> >>
> >> On 25/11/2020 13:54, Christophe Lyon via Gcc-patches wrote:
> >>> This patch enables MVE vandq instructions for auto-vectorization.  MVE
> >>> vandq insns in mve.md are modified to use 'and' instead of unspec
> >>> expression to support and3.  The and3 expander is added to
> >>> vec-common.md
> >>>
> >>> 2020-11-12  Christophe Lyon  
> >>>
> >>>gcc/
> >>>* gcc/config/arm/iterators.md (supf): Remove VANDQ_S and VANDQ_U.
> >>>(VANQ): Remove.
> >>>* config/arm/mve.md (mve_vandq_u): New entry for vand
> >>>instruction using expression and.
> >>>(mve_vandq_s): New expander.
> >>>* config/arm/neon.md (and3): Renamed into and3_neon.
> >>>* config/arm/unspecs.md (VANDQ_S, VANDQ_U): Remove.
> >>>* config/arm/vec-common.md (and3): New expander.
> >>>
> >>>gcc/testsuite/
> >>>* gcc.target/arm/simd/mve-vand.c: New test.
> >>> ---
> >>>gcc/config/arm/iterators.md  |  4 +---
> >>>gcc/config/arm/mve.md| 20 
> >>>gcc/config/arm/neon.md   |  2 +-
> >>>gcc/config/arm/unspecs.md|  2 --
> >>>gcc/config/arm/vec-common.md | 15 
> >>>gcc/testsuite/gcc.target/arm/simd/mve-vand.c | 34 
> >>> 
> >>>6 files changed, 66 insertions(+), 11 deletions(-)
> >>>create mode 100644 gcc/testsuite/gcc.target/arm/simd/mve-vand.c
> >>>
> >>> diff --git a/gcc/config/arm/iterators.md b/gcc/config/arm/iterators.md
> >>> index 592af35..72039e4 100644
> >>> --- a/gcc/config/arm/iterators.md
> >>> +++ b/gcc/config/arm/iterators.md
> >>> @@ -1232,8 +1232,7 @@ (define_int_attr supf [(VCVTQ_TO_F_S "s") 
> >>> (VCVTQ_TO_F_U "u") (VREV16Q_S "s")
> >>>   (VADDLVQ_P_U "u") (VCMPNEQ_U "u") (VCMPNEQ_S "s")
> >>>   (VABDQ_M_S "s") (VABDQ_M_U "u") (VABDQ_S "s")
> >>>   (VABDQ_U "u") (VADDQ_N_S "s") (VADDQ_N_U "u")
> >>> -(VADDVQ_P_S "s") (VADDVQ_P_U "u") (VANDQ_S "s")
> >>> -(VANDQ_U "u") (VBICQ_S "s") (VBICQ_U "u")
> >>> +(VADDVQ_P_S "s") (VADDVQ_P_U "u") (VBICQ_S "s") 
> >>> (VBICQ_U "u")
> >>>   (VBRSRQ_N_S "s") (VBRSRQ_N_U "u") (VCADDQ_ROT270_S 
> >>> "s")
> >>>   (VCADDQ_ROT270_U "u") (VCADDQ_ROT90_S "s")
> >>>   (VCMPEQQ_S "s") (VCMPEQQ_U "u") (VCADDQ_ROT90_U "u")
> >>> @@ -1501,7 +1500,6 @@ (define_int_iterator VABDQ [VABDQ_S VABDQ_U])
> >>>(define_int_iterator VADDQ_N [VADDQ_N_S VADDQ_N_U])
> >>>(define_int_iterator VADDVAQ [VADDVAQ_S VADDVAQ_U])
> >>>(define_int_iterator VADDVQ_P [VADDVQ_P_U VADDVQ_P_S])
> >>> -(define_int_iterator VANDQ [VANDQ_U VANDQ_S])
> >>>(define_int_iterator VBICQ [VBICQ_S VBICQ_U])
> >>>(define_int_iterator VBRSRQ_N [VBRSRQ_N_U VBRSRQ_N_S])
> >>>(define_int_iterator VCADDQ_ROT270 [VCADDQ_ROT270_S VCADDQ_ROT270_U])
> >>> diff --git a/gcc/config/arm/mve.md b/gcc/config/arm/mve.md
> >>> index ecbaaa9..975eb7d 100644
> >>> --- a/gcc/config/arm/mve.md
> >>> +++ b/gcc/config/arm/mve.md
> >>> @@ -894,17 +894,27 @@ (define_insn "mve_vaddvq_p_"
> >>>;;
> >>>;; [vandq_u, vandq_s])
> >>>;;
> >>> -(define_insn "mve_vandq_"
> >>> +;; signed and unsigned versions are the same: define the unsigned
> >>> +;; insn, and use an expander for the signed one as we still reference
> >>> +;; both names from arm_mve.h.
> >>> +(define_insn "mve_vandq_u"
> >>>  [
> >>>   (set (match_operand:MVE_2 0 "s_register_operand" "=w")
> >>> - (unspec:MVE_2 [(match_operand:MVE_2 1 "s_register_operand" "w")
> >>> -(match_operand:MVE_2 2 "s_register_operand" "w")]
> >>> -  VANDQ))
> >>> + (and:MVE_2 (match_operand:MVE_2 1 "s_register_operand" "w")
> >>> +(match_operand:MVE_2 2 "s_register_operand" "w")))
> >> The predicate on the second operand is more restrictive than the one in
> >> expand 'neon_inv_logic_op2'. This should still work with immediates, or
> >> well I checked for integers, it generates a loop as such:
> >>
> > Right, thanks for catching it.
> >
> >>   vldrw.32q3, [r0]
> >>   vldr.64 d4, .L8
> >>   vldr.64 d5, .L8+8
> >>   vandq3, q3, q2
> >>   vstrw.32q3, [r2]
> >>
> >> MVE does support vand's with immediates, just like NEON, I suspect you
> >> could just copy the way Neon handles these, possibly worth the little
> >> extra effort. You can use dest[i] = a[i] & ~1 as a testcase.
> >> If you don't it might still be worth expan

Re: [patch, fortran] Correct fndecls for some library functions

2020-11-27 Thread Tobias Burnus

Hi Thomas,

On 25.11.20 12:58, Tobias Burnus wrote:

On 15.11.20 18:52, Thomas Koenig via Fortran wrote:

+#define ADD_CHAR(c) do { *fp++ = c; *fp++ = ' '; } while(0)
...
+  ADD_CHAR ('.');  /* Function return.  */

Shouldn't this be ".c" instead of ". " as neither global memory is
read nor written to?

+  if (expr->rank == 0)
...
+  else
+ADD_CHAR ('w');  /* Return value is a descriptor.  */

shouldn't this be "o"?

Scratch that - as it is an array descriptor, "w" is correct – the bounds
etc. are not reset.

Otherwise, it looks good to me.


Tobias

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


Re: OpenACC 'kernels' testsuite failures

2020-11-27 Thread David Edelsohn via Gcc-patches
Hi, Thomas

Actually, yes, AIX does allow dereference of a NULL pointer.

Thanks, David

On Fri, Nov 27, 2020 at 9:15 AM Thomas Schwinge  wrote:
>
> Hi David!
>
> On 2020-11-24T15:29:17-0500, David Edelsohn via Gcc-patches 
>  wrote:
> > On Tue, Nov 24, 2020 at 5:19 AM Thomas Schwinge  
> > wrote:
> >> On 2020-11-21T10:50:10-0500, David Edelsohn  wrote:
> >> > I see
> >> >
> >> > "during GIMPLE pass: omplower"
> >> >
> >> > message for kernels-decompose-ice-2.c.  kernels-decompose-ice-1.c
> >> > explicitly prunes that output, but kernels-decompose-ice-2.c does not.
> >> > Is there a reason that the second testcase does not prune that output
> >> > or can we add it?
> >>
> >> So, the expectation (as verified by my x86_64-pc-linux-gnu and
> >> powerpc64le-unknown-linux-gnu testing) is that
> >> 'c-c++-common/goacc/kernels-decompose-ice-1.c' (currently) runs into an
> >> ICE "during GIMPLE pass: omplower", and
> >> 'c-c++-common/goacc/kernels-decompose-ice-2.c' (currently) runs into an
> >> ICE "during GIMPLE pass: omp_oacc_kernels_decompose".
> >>
> >> Now, you're reporting that for the latter testcase you're instead also
> >> seeing an ICE "during GIMPLE pass: omplower".  Can you please show the
> >> full ICE report/backtrace, so that we verify that it's not yet another
> >> separate issue?
>
> On gcc119 ('uname -a': "AIX power8-aix 2 7 00F9C1964C00"), I've now also
> reproduced the issue.
>
> >> Maybe the AIX system configuration (ABI?)
> >> mandates/causes some slight difference in how front ends set attributes
> >> such as 'TREE_ADDRESSABLE' on DECLs, which 'omp_oacc_kernels_decompose'
> >> (currently) is sensitive to (hence the ICEs).
>
> That's not the case; the input into 'omp_oacc_kernels_decompose' seems to
> be exactly the same as on other systems.
>
> > The error messages reported on AIX are:
> >
> > Executing on host: /tmp/GCC/gcc/xgcc -B/tmp/GCC/gcc/ 
> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
> > -fdiagnostics-plain-output   -fopenacc -fopenacc-kernels=decompose -S 
> > -o kernels-decompose-ice-2.s(timeout = 300)
> > spawn -ignore SIGHUP /tmp/GCC/gcc/xgcc -B/tmp/GCC/gcc/ 
> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
> >  -fdiagnostics-plain-output -fopenacc -fopenacc-kernels=decompose -S -o 
> > kernels-decompose-ice-2.s
> > during GIMPLE pass: omplower
> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:
> >  In function 'main':
> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:13:9:
> > internal compiler error: in lower_omp_target, at omp-low.c:12216
>
> That's indeed the location of the 'gcc_assert' responsible for the
> 'omplower' ICE, which currently is expected, if we don't run into the
> 'omp_oacc_kernels_decompose' ICE first.  It's still strange however, why
> we're seeing this "for AIX" (not better classified) only: I suppose it
> isn't a feature "of AIX" that it can dereference a 'NULL' pointer ;-) --
> which is what seems to be happening here:
>
> 742   gimple_seq inner_sequence = gimple_bind_body 
> (inner_bind);
> (gdb) next
> 743   gcc_assert (gimple_code (inner_sequence) != GIMPLE_BIND
> (gdb) print inner_sequence
> $1 = (gimple_seq) 0x0
> (gdb) next
> 745   gimple_seq_add_seq (&new_body, inner_sequence);
>
> So we have 'inner_sequence == NULL', and yet the 'next' didn't trigger a
> SIGSEGV in:
>
> static inline enum gimple_code
> gimple_code (const gimple *g)
> {
>   return g->code;
> }
>
> Strange, isn't it?
>
>
> However: this issue should now (indirectly) be fixed via "In
> 'gcc/omp-oacc-kernels-decompose.cc:flatten_binds', don't choke on empty
> GIMPLE sequence" that I've just pushed to master branch in commit
> 4b5726fda653d11f882fb9a112e4cffa12f7ed61.
>
>
> > during GIMPLE pass: omplower
> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:
> >  In function 'main':
> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:13:9:
> > internal compiler error: in lower_omp_target, at omp-low.c:12216
> > ranges offset out of range
>
> That last line actually comes from here:
>
> libbacktrace/dwarf.c:  error_callback (data, "ranges offset out of 
> range", 0);
>
>
> 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


[committed] libstdc++: Refactor dejagnu effective-target checks

2020-11-27 Thread Jonathan Wakely via Gcc-patches
This introduces two new procs to replace boilerplate in the
effective-target checks.

libstdc++-v3/ChangeLog:

* testsuite/lib/libstdc++.exp (v3_try_preprocess): Define
new proc to preprocess a chunk of code.
(v3_check_preprocessor_condition): Define new proc to test
a preprocessor condition depending on GCC or libstdc++ macros.
(check_v3_target_debug_mode, check_v3_target_normal_mode):
Use v3_try_preprocess.
(check_v3_target_normal_namespace)
(check_v3_target_parallel_mode, check_v3_target_cstdint)
(check_v3_target_cmath, check_v3_target_atomic_builtins)
(check_v3_target_gthreads, check_v3_target_gthreads_timed)
(check_v3_target_sleep, check_v3_target_sched_yield)
(check_v3_target_string_conversions, check_v3_target_swprintf)
(check_v3_target_binary_io, check_v3_target_nprocs): Use
v3_check_preprocessor_condition.
(check_effective_target_cxx11): Likewise.
(check_effective_target_random_device): Likewise.
(check_effective_target_tbb-backend): Likewise.
(check_effective_target_futex): Likewise.
(check_v3_target_little_endian) Call check_effective_target_le.
(check_effective_target_atomic-builtins): New proc to define
new effective-target keyword.
(check_effective_target_gthreads-timed): Likewise.

Tested powerpc64le-linux, sparc-solaris2.11, powerpc-aix (with no
changes to test results, i.e. the same set are UNSUPPORTED).

Committed to trunk.

commit e8f83fa4fcf4f7e97046ef6b521b78dcd25c95b7
Author: Jonathan Wakely 
Date:   Fri Nov 27 00:21:52 2020

libstdc++: Refactor dejagnu effective-target checks

This introduces two new procs to replace boilerplate in the
effective-target checks.

libstdc++-v3/ChangeLog:

* testsuite/lib/libstdc++.exp (v3_try_preprocess): Define
new proc to preprocess a chunk of code.
(v3_check_preprocessor_condition): Define new proc to test
a preprocessor condition depending on GCC or libstdc++ macros.
(check_v3_target_debug_mode, check_v3_target_normal_mode):
Use v3_try_preprocess.
(check_v3_target_normal_namespace)
(check_v3_target_parallel_mode, check_v3_target_cstdint)
(check_v3_target_cmath, check_v3_target_atomic_builtins)
(check_v3_target_gthreads, check_v3_target_gthreads_timed)
(check_v3_target_sleep, check_v3_target_sched_yield)
(check_v3_target_string_conversions, check_v3_target_swprintf)
(check_v3_target_binary_io, check_v3_target_nprocs): Use
v3_check_preprocessor_condition.
(check_effective_target_cxx11): Likewise.
(check_effective_target_random_device): Likewise.
(check_effective_target_tbb-backend): Likewise.
(check_effective_target_futex): Likewise.
(check_v3_target_little_endian) Call check_effective_target_le.
(check_effective_target_atomic-builtins): New proc to define
new effective-target keyword.
(check_effective_target_gthreads-timed): Likewise.

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index b94116ff4ea5..e000dba968f7 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -945,85 +945,97 @@ proc check_v3_target_namedlocale { args } {
 }]
 }
 
+# Returns 1 if the tokens in CODE can be preprocessed successfully using FLAGS,
+# returns 0 otherwise.
+proc v3_try_preprocess { name code flags } {
+global tool
+global cxxflags
+
+# Set up and preprocess a C++ translation unit.
+set src $name[pid].cc
+
+set f [open $src "w"]
+puts $f $code
+close $f
+
+set cxxflags_saved $cxxflags
+set cxxflags "$flags"
+
+set lines [v3_target_compile $src /dev/null preprocess ""]
+set cxxflags $cxxflags_saved
+file delete $src
+
+if [string match "" $lines] {
+   verbose "v3_try_preprocess $name: preprocessing passed" 3
+   # No error message, preprocessing succeeded.
+   return 1
+}
+verbose "v3_try_preprocess $name: preprocessing failed" 2
+return 0
+}
+
+# Return 1 if COND evaluates to true in the preprocessor, 0 otherwise.
+# The  config header is included.
+proc v3_check_preprocessor_condition { name cond } {
+global cxxflags
+global DEFAULT_CXXFLAGS
+
+set code "
+   #include 
+   #if ! ($cond)
+   #error '$cond' is false
+   #endif
+   "
+set flags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
+
+return [v3_try_preprocess name $code $flags]
+}
+
+# Return 1 if Debug Mode is active, 0 otherwise.
 proc check_v3_target_debug_mode { } {
+global cxxflags
 return [check_v3_target_prop_cached et_debug_mode {
-   global tool
-   # Set up and preprocess a C++ test program that depends
-   # on

Re: [00/23] Make fwprop use an on-the-side RTL SSA representation

2020-11-27 Thread Michael Matz
Hello,

On Thu, 26 Nov 2020, Richard Sandiford via Gcc-patches wrote:

> >> The aim is only to provide a different view of existing RTL instructions.
> >> Unlike gimple, and unlike (IIRC) the old RTL SSA project from way back,
> >> the new framework isn't a “native” SSA representation.  This means that
> >> all inputs to a phi node for a register R are also definitions of
> >> register R; no move operation is “hidden” in the phi node.
> > Hmm, I'm trying to parse what the last phrase means.  Does it mean that
> > the "hidden copy" problem for out-of-ssa is avoided?  And if so, how is
> > that maintained over time.  Things like copy-prop will tend to introduce
> > those issues even if they didn't originally exist.
> 
> Yeah, the phi nodes simply say which definition of register R provides
> the value of R on a particular incoming edge.  That definition will
> itself be a phi node for R, an artificial definition of R created by DF
> (e.g. for incoming function arguments or for EH data registers), or an
> actual instruction that sets R.
> 
> In other words, the SSA form is a purely on-the-side thing and the
> underlying RTL instructions are maintained in the same way as normal.
> The SSA form can be deleted at any time without performing a separate
> out-of-ssa step.  In that respect it's different from cfglayout,
> for example.

Hmm, I don't see how that answers Jeffs question, if I got it correctly.  
If I didn't get it correctly let me ask my own version of the question :)

(I haven't studied your implementation in detail, if I had maybe answers 
to the below would become obvious, sorry if so :) )
 
So, you're saying that in your implementation the operands of PHIs can be 
PHIs and real defs.  Further you say nothing about any restriction in RTL 
instruction moving and/or propagation.  So, then let's start with one of 
the prime examples of SSA deconstruction problems, the lost swap, and how 
it comes to be: we start with a swap:

  x = ..., y = ...
  if (cond)
tmp=x, x=y, y=tmp

(1) into SSA:

  x0 = ..., y0 = ...
  if (cond)
tmp = x0, x1=y0, y1=tmp;
  x2 = PHI(x0,x1),  y2 = PHI(y0,y1)

(2) copy-prop:

  x0 = ..., y0 = ...
  if (cond)
;
  x2 = PHI(x0,y0),  y2 = PHI(y0,x0)

Now you're also saying that the SSA form can simply be deleted without any 
consideration of the parallel copy nature, i.e. no real out-of-ssa phase.  
In the above example that would lead to wrong code, so that can't be it.  
So what in your representation avoids either (1) or (2)?  Do these 
restrictions also work if the above crucial code is within a loop (and 
hence the inputs to PHIs are the PHIs themself, which is the actual 
canonical variant of the lost-copy and swap problems).


Ciao,
Michael.


Re: OpenACC 'kernels' testsuite failures

2020-11-27 Thread Thomas Schwinge
Hi David!

On 2020-11-27T10:47:17-0500, David Edelsohn  wrote:
> Actually, yes, AIX does allow dereference of a NULL pointer.

Oh.  That's not what I expected!  Heh.

Anyway, that then indeed completely explains what was going on here --
which is good.  :-)


Grüße
 Thomas


> On Fri, Nov 27, 2020 at 9:15 AM Thomas Schwinge  
> wrote:
>>
>> Hi David!
>>
>> On 2020-11-24T15:29:17-0500, David Edelsohn via Gcc-patches 
>>  wrote:
>> > On Tue, Nov 24, 2020 at 5:19 AM Thomas Schwinge  
>> > wrote:
>> >> On 2020-11-21T10:50:10-0500, David Edelsohn  wrote:
>> >> > I see
>> >> >
>> >> > "during GIMPLE pass: omplower"
>> >> >
>> >> > message for kernels-decompose-ice-2.c.  kernels-decompose-ice-1.c
>> >> > explicitly prunes that output, but kernels-decompose-ice-2.c does not.
>> >> > Is there a reason that the second testcase does not prune that output
>> >> > or can we add it?
>> >>
>> >> So, the expectation (as verified by my x86_64-pc-linux-gnu and
>> >> powerpc64le-unknown-linux-gnu testing) is that
>> >> 'c-c++-common/goacc/kernels-decompose-ice-1.c' (currently) runs into an
>> >> ICE "during GIMPLE pass: omplower", and
>> >> 'c-c++-common/goacc/kernels-decompose-ice-2.c' (currently) runs into an
>> >> ICE "during GIMPLE pass: omp_oacc_kernels_decompose".
>> >>
>> >> Now, you're reporting that for the latter testcase you're instead also
>> >> seeing an ICE "during GIMPLE pass: omplower".  Can you please show the
>> >> full ICE report/backtrace, so that we verify that it's not yet another
>> >> separate issue?
>>
>> On gcc119 ('uname -a': "AIX power8-aix 2 7 00F9C1964C00"), I've now also
>> reproduced the issue.
>>
>> >> Maybe the AIX system configuration (ABI?)
>> >> mandates/causes some slight difference in how front ends set attributes
>> >> such as 'TREE_ADDRESSABLE' on DECLs, which 'omp_oacc_kernels_decompose'
>> >> (currently) is sensitive to (hence the ICEs).
>>
>> That's not the case; the input into 'omp_oacc_kernels_decompose' seems to
>> be exactly the same as on other systems.
>>
>> > The error messages reported on AIX are:
>> >
>> > Executing on host: /tmp/GCC/gcc/xgcc -B/tmp/GCC/gcc/ 
>> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
>> > -fdiagnostics-plain-output   -fopenacc -fopenacc-kernels=decompose -S 
>> > -o kernels-decompose-ice-2.s(timeout = 300)
>> > spawn -ignore SIGHUP /tmp/GCC/gcc/xgcc -B/tmp/GCC/gcc/ 
>> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c
>> >  -fdiagnostics-plain-output -fopenacc -fopenacc-kernels=decompose -S -o 
>> > kernels-decompose-ice-2.s
>> > during GIMPLE pass: omplower
>> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:
>> >  In function 'main':
>> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:13:9:
>> > internal compiler error: in lower_omp_target, at omp-low.c:12216
>>
>> That's indeed the location of the 'gcc_assert' responsible for the
>> 'omplower' ICE, which currently is expected, if we don't run into the
>> 'omp_oacc_kernels_decompose' ICE first.  It's still strange however, why
>> we're seeing this "for AIX" (not better classified) only: I suppose it
>> isn't a feature "of AIX" that it can dereference a 'NULL' pointer ;-) --
>> which is what seems to be happening here:
>>
>> 742   gimple_seq inner_sequence = gimple_bind_body 
>> (inner_bind);
>> (gdb) next
>> 743   gcc_assert (gimple_code (inner_sequence) != GIMPLE_BIND
>> (gdb) print inner_sequence
>> $1 = (gimple_seq) 0x0
>> (gdb) next
>> 745   gimple_seq_add_seq (&new_body, inner_sequence);
>>
>> So we have 'inner_sequence == NULL', and yet the 'next' didn't trigger a
>> SIGSEGV in:
>>
>> static inline enum gimple_code
>> gimple_code (const gimple *g)
>> {
>>   return g->code;
>> }
>>
>> Strange, isn't it?
>>
>>
>> However: this issue should now (indirectly) be fixed via "In
>> 'gcc/omp-oacc-kernels-decompose.cc:flatten_binds', don't choke on empty
>> GIMPLE sequence" that I've just pushed to master branch in commit
>> 4b5726fda653d11f882fb9a112e4cffa12f7ed61.
>>
>>
>> > during GIMPLE pass: omplower
>> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:
>> >  In function 'main':
>> > /nasfarm/edelsohn/src/src/gcc/testsuite/c-c++-common/goacc/kernels-decompose-ice-2.c:13:9:
>> > internal compiler error: in lower_omp_target, at omp-low.c:12216
>> > ranges offset out of range
>>
>> That last line actually comes from here:
>>
>> libbacktrace/dwarf.c:  error_callback (data, "ranges offset out of 
>> range", 0);
>>
>>
>> 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
-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / G

OpenMP patch ping

2020-11-27 Thread Tobias Burnus

OpenMP-related patch pings:

Kwok's:
* Re: [PATCH] openmp: Implicit 'declare target' for C++ static initializers
  https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559624.html
* RFC:
  Nested declare target support
  https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559758.html

Chung-Lin's:
* [PATCH v2, OpenMP 5, C++] Implement implicit mapping of this[:1] (PR92120)
  https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558975.html

My:
* [Patch] OpenMP: C/C++ parse 'omp allocate'
  https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559930.html

If you have a comment to Julian's
* Re: [PATCH] nvptx: Cache stacks block for OpenMP kernel launch
  https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559044.html

Tobias

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


[RFC] Decrease default timeout for libstdc++ tests to 6 minutes

2020-11-27 Thread Jonathan Wakely via Gcc-patches

The default for the GCC testsuite is 300, i.e. 5 minutes, which is the
same as the DejaGnu default.

Libstdc++ overrides this to 600, i.e. 10 minutes.

This seems ridiculously long. If any test takes that long on modern
hardware, something is wrong. We've seen this a lot recently with
buggy tests, and waiting for them to FAIL is tedious.

I've already made libstdc++.exp respect the user's setting in
~/.dejagnurc or the global site.exp file. This means anybody testing
on slow simulators or old hardware can choose their own timeout.

I've added dg-timeout-factor to the slowest std::regex tests and have
a patch to do it for the PSTL tests, which both take far too long to
compile. That means you can choose a sensible timeout appropriate for
most tests (e.g. 60 seconds) and not get spurious failures from the
few dozen tests which are just very slow.

I'd like to change the default to 6 minutes. If that goes well, I'd
like to lower it even further.

The main benefit of this will be that buggy tests which hang will get
killed sooner, so we waste less time waiting for the inevitable
timeout.


Here's the proposed patch for completeness:

--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -248,7 +248,7 @@ proc libstdc++_init { testfile } {
 # Set the default timeout for v3 tests.
 # You can override this in ~/.dejagnurc or a .exp file named by $DEJAGNU.
 if {![info exists tool_timeout]} {
-  set tool_timeout 600
+  set tool_timeout 360
 }

 # Default settings.



Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread Gerald Pfeifer
On Fri, 27 Nov 2020, H.J. Lu via Gcc-patches wrote:
> +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
> +target binutils supports @code{Intel CET} instructions and disabled
> +otherwise.  In this case, the target libraries are configured to get
> +additional @option{-fcf-protection} option.

Does that refer to the Linux kernel or GNU/Linux?

THe last sentence does not appear complete.  What do you want to say?

"...target libraries are built with @option{-fcf-protection}"?

On Fri, 27 Nov 2020, H.J. Lu via Gcc-patches wrote:
> OK for backport to GCC 10?

Yes, once we have resolved the above.

Gerald


[PATCH] gcc-changelog: Add libstdc++-v3/testsuite to wildcard prefixes

2020-11-27 Thread Jonathan Wakely via Gcc-patches
This allows using "testsuite/*" in libstdc++-v3/ChangeLog entries, which
was one of the original motivations for adding wildcard support in the
first place:
https://gcc.gnu.org/pipermail/gcc/2020-June/232719.html

contrib/ChangeLog:

* gcc-changelog/git_commit.py (wildcard_prefixes): Add libstdc++
testsuite directory.

OK to push?

This still doesn't actually meet my needs, because I'd like to be able
to do:

* testsuite/foo/*: Something for foo tests.
* testsuite/bar/baz/*: Something for baz tests.

So it would be nice if wildcards worked for any directory below a
wildcard prefix (as long as the directory actually exists).

It also seems that I can't have a commit where all changes are
described by a wildcard entry. It seems to require a non-wildcard one
too. But that means I can't make changes to hundreds of tests without
also making some other change, or doing something like:

* testsuite/foo/foo-1.cc: A specific change.
* testsuite/*: Likewise.

I suppose I can live with the latter, but it would still be nice if
this worked:

* testsuite/foo/foo-1.cc: A specific change.
* testsuite/foo/*: Likewise.
* testsuite/bar/baz/*: Likewise.

i.e. sub-directories below a wildcard prefix.


commit 5cdb6541a49f1ac716a3f1be281c9487d9b198c5
Author: Jonathan Wakely 
Date:   Fri Nov 27 16:00:58 2020

gcc-changelog: Add libstdc++-v3/testsuite to wildcard prefixes

This allows using "testsuite/*" in libstdc++-v3/ChangeLog entries, which
was one of the original motivations for adding wildcard support in the
first place:
https://gcc.gnu.org/pipermail/gcc/2020-June/232719.html

contrib/ChangeLog:

* gcc-changelog/git_commit.py (wildcard_prefixes): Add libstdc++
testsuite directory.

diff --git a/contrib/gcc-changelog/git_commit.py 
b/contrib/gcc-changelog/git_commit.py
index d0ac23c22aa4..3ebc6fd305e0 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -138,7 +138,8 @@ ignored_prefixes = {
 
 wildcard_prefixes = {
 'gcc/testsuite/',
-'libstdc++-v3/doc/html/'
+'libstdc++-v3/doc/html/',
+'libstdc++-v3/testsuite/'
 }
 
 misc_files = {


Re: [00/23] Make fwprop use an on-the-side RTL SSA representation

2020-11-27 Thread Richard Sandiford via Gcc-patches
Michael Matz  writes:
> Hello,
>
> On Thu, 26 Nov 2020, Richard Sandiford via Gcc-patches wrote:
>
>> >> The aim is only to provide a different view of existing RTL instructions.
>> >> Unlike gimple, and unlike (IIRC) the old RTL SSA project from way back,
>> >> the new framework isn't a “native” SSA representation.  This means that
>> >> all inputs to a phi node for a register R are also definitions of
>> >> register R; no move operation is “hidden” in the phi node.
>> > Hmm, I'm trying to parse what the last phrase means.  Does it mean that
>> > the "hidden copy" problem for out-of-ssa is avoided?  And if so, how is
>> > that maintained over time.  Things like copy-prop will tend to introduce
>> > those issues even if they didn't originally exist.
>> 
>> Yeah, the phi nodes simply say which definition of register R provides
>> the value of R on a particular incoming edge.  That definition will
>> itself be a phi node for R, an artificial definition of R created by DF
>> (e.g. for incoming function arguments or for EH data registers), or an
>> actual instruction that sets R.
>> 
>> In other words, the SSA form is a purely on-the-side thing and the
>> underlying RTL instructions are maintained in the same way as normal.
>> The SSA form can be deleted at any time without performing a separate
>> out-of-ssa step.  In that respect it's different from cfglayout,
>> for example.
>
> Hmm, I don't see how that answers Jeffs question, if I got it correctly.  
> If I didn't get it correctly let me ask my own version of the question :)
>
> (I haven't studied your implementation in detail, if I had maybe answers 
> to the below would become obvious, sorry if so :) )
>  
> So, you're saying that in your implementation the operands of PHIs can be 
> PHIs and real defs.

Specifically real defs of the same register (or memory, for memory phis).

> Further you say nothing about any restriction in RTL 
> instruction moving and/or propagation.

The RTL SSA form doesn't add any extra restrictions beyond those that apply
to non-SSA RTL passes.  But it also doesn't take any restrictions away.
In other words, the changes that RTL SSA passes make to RTL instructions
are the same as those that non-SSA RTL passes would make.  The SSA form
is just there to make it easier to process use-def chains (and also
to process live ranges, to a limited extent).

> So, then let's start with one of 
> the prime examples of SSA deconstruction problems, the lost swap, and how 
> it comes to be: we start with a swap:
>
>   x = ..., y = ...
>   if (cond)
> tmp=x, x=y, y=tmp
>
> (1) into SSA:
>
>   x0 = ..., y0 = ...
>   if (cond)
> tmp = x0, x1=y0, y1=tmp;
>   x2 = PHI(x0,x1),  y2 = PHI(y0,y1)
>
> (2) copy-prop:
>
>   x0 = ..., y0 = ...
>   if (cond)
> ;
>   x2 = PHI(x0,y0),  y2 = PHI(y0,x0)

So the point is that this isn't what the RTL would look like even
when using RTL SSA.  Putting y0 in x2 PHI and x0 in the y2 PHI is
representationally invalid.

Like I say, this isn't a “native” SSA form: it's just using SSA
constructs to represent dataflow in normal RTL.

> Now you're also saying that the SSA form can simply be deleted without any 
> consideration of the parallel copy nature, i.e. no real out-of-ssa phase.  
> In the above example that would lead to wrong code, so that can't be it.  
> So what in your representation avoids either (1) or (2)?  Do these 
> restrictions also work if the above crucial code is within a loop (and 
> hence the inputs to PHIs are the PHIs themself, which is the actual 
> canonical variant of the lost-copy and swap problems).

Hope the above answers this.  Using the notation above, every input
to an xn PHI always has the form xi.

I don't think it's worth having a native SSA form in RTL given that
we already have one in gimple.  It would just lose some low-level
details that are (IMO) important for RTL, and that distinguish RTL
from gimple, such as the need for a temporary register in your swap
example.

Thanks,
Richard


Re: [PING] [PATCH] libstdc++: Pretty printers for std::_Bit_reference, std::_Bit_iterator and std::_Bit_const_iterator

2020-11-27 Thread Jonathan Wakely via Gcc-patches

On 25/11/20 15:05 +0100, Michael Weghorn via Libstdc++ wrote:

I'd like to ping for this patch:
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553870.html


Thanks, I'll take another look next week.



Michael

On 11/10/2020 19.22, Michael Weghorn via Gcc-patches wrote:

On 22/09/2020 12.04, Jonathan Wakely wrote:

On 14/09/20 16:49 +0200, Michael Weghorn via Libstdc++ wrote:

Hi,

the attached patch implements pretty printers relevant for iteration
over std::vector, thus handling the TODO
added in commit 36d0dada6773d7fd7c5ace64c90e723930a3b81e
("Have std::vector printer's iterator return bool for vector",
2019-06-19):

   TODO add printer for vector's _Bit_iterator and
_Bit_const_iterator

Tested on x86_64-pc-linux-gnu (Debian testing).

I haven't filed any copyright assignment for GCC yet, but I'm happy to
do so when pointed to the right place.


Thanks for the patch! I'll send you the form to start the copyuright
assignment process.




Thanks! The copyright assignment is done now. Is there anything else to
do from my side at the moment?







Fortran: With OpenACC, ignore OpenMP's cond comp sentinels

2020-11-27 Thread Tobias Burnus

'!' starts in Fortran a comment (+ fixed-form variants)
OpenACC defines as sentinel "!$acc" (likewise)
But OpenMP has two: Besides "!$omp" there is additionally
"!$ " (with space) to permit conditional compilation.

Currently, -fopenacc also executes the '!$ ' code, which I
think does not make sense.

Hence, this patch ignores it.
Comments? If not, I intent to commit it in the next days

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
Fortran: With OpenACC, ignore OpenMP's cond comp sentinels

gcc/fortran/ChangeLog:

	PR fortran/98011
	* scanner.c (skip_free_comments): If only -fopenacc but not -fopenmp
	is used, ignore OpenMP's conditional compilation sentinels.

gcc/testsuite/ChangeLog:

	PR fortran/98011
	* gfortran.dg/goacc/sentinel-free-form.f95: Update as OpenMP's "!$ "
	conditional compilation sentinels are now ignored.

 gcc/fortran/scanner.c  | 23 --
 .../gfortran.dg/goacc/sentinel-free-form.f95   |  7 +--
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index fd11f5a244a..b70728d6bd1 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -899,21 +899,14 @@ skip_free_comments (void)
 		if (next_char () == '$')
 		  {
 		c = next_char ();
-		  if (c == 'a' || c == 'A')
-			{
-			  if (skip_free_oacc_sentinel (start, old_loc))
-			return false;
-			  gfc_current_locus = old_loc;
-			  next_char();
-			  c = next_char();
-			}
-		  if (continue_flag || c == ' ' || c == '\t')
-			{
-			  gfc_current_locus = old_loc;
-			  next_char();
-			  openacc_flag = 0;
-			  return true;
-			}
+		if (c == 'a' || c == 'A')
+		  {
+			if (skip_free_oacc_sentinel (start, old_loc))
+			  return false;
+			gfc_current_locus = old_loc;
+			next_char();
+			c = next_char();
+		  }
 		  }
 		gfc_current_locus = old_loc;
 	  }
diff --git a/gcc/testsuite/gfortran.dg/goacc/sentinel-free-form.f95 b/gcc/testsuite/gfortran.dg/goacc/sentinel-free-form.f95
index 1a3189cb34e..00dac667ef1 100644
--- a/gcc/testsuite/gfortran.dg/goacc/sentinel-free-form.f95
+++ b/gcc/testsuite/gfortran.dg/goacc/sentinel-free-form.f95
@@ -10,7 +10,10 @@ program test
   x = 0.0 !$acc parallel ! comment
   ! sentinel must appear as a single word
   ! $acc parallel ! comment
-  !$ acc parallel ! { dg-error "Unclassifiable statement" }
+
+  ! note that '!$ ' is OpenMP's conditional compilation sentinel
+  !$ acc ignored_due_to_space  ! comment
+
   ! directive lines must have space after sentinel
   !$accparallel ! { dg-warning "followed by a space" }
   do i = 1,10


Re: Fortran: With OpenACC, ignore OpenMP's cond comp sentinels

2020-11-27 Thread Jakub Jelinek via Gcc-patches
On Fri, Nov 27, 2020 at 06:18:46PM +0100, Tobias Burnus wrote:
> '!' starts in Fortran a comment (+ fixed-form variants)
> OpenACC defines as sentinel "!$acc" (likewise)
> But OpenMP has two: Besides "!$omp" there is additionally
> "!$ " (with space) to permit conditional compilation.
> 
> Currently, -fopenacc also executes the '!$ ' code, which I
> think does not make sense.
> 
> Hence, this patch ignores it.
> Comments? If not, I intent to commit it in the next days

Depends on what does the OpenACC standard say.
If it has similar wording to OpenMP that '!$ ' stands for OpenACC
conditional compilation, then the patch is incorrect, if it is silent on
that, then the patch is correct.

What about fixed-form parsing?  Does it also recognize the conditional
compilation in OpenACC or not?  Tests should cover that too, I guess
including -fopenmp -fopenacc goacc-gomp test that would test that it still
works (both free form and fixed form).

Jakub



[PATCH] testsuite/i386: Fix XOP and FMA4 checking functions [PR98036].

2020-11-27 Thread Uros Bizjak via Gcc-patches
Add missing returns and remove unnecessary postfix increments.

2020-11-27  Uroš Bizjak  

PR testsuite/98036

gcc/testsuite/
* gcc.target/i386/fma4-256-maccXX.c (check_maccps):
Remove unnecessary postfix increment on a returned variable.
(check_maccpd): Ditto.
* gcc.target/i386/fma4-256-msubXX.c (check_msubps): Ditto.
(check_msubpd): Ditto.
* gcc.target/i386/fma4-256-nmaccXX.c (check_nmaccps): Ditto.
(check_nmaccpd): Ditto.
* gcc.target/i386/fma4-256-nmsubXX.c (check_nmsubps): Ditto.
(check_nmsubpd): Ditto.
* gcc.target/i386/fma4-maccXX.c (check_maccps): Ditto.
(check_maccpd): Ditto.
(check_maccss): Ditto.
(check_maccsd): Ditto.
* gcc.target/i386/fma4-msubXX.c (check_msubps): Ditto.
(check_msubpd): Ditto.
(check_msubss): Ditto.
(check_msubsd): Ditto.
* gcc.target/i386/fma4-nmaccXX.c (check_nmaccps): Ditto.
(check_nmaccpd): Ditto.
(check_nmaccss): Ditto.
(check_nmaccsd): Ditto.
* gcc.target/i386/fma4-nmsubXX.c (check_nmsubps): Ditto.
(check_nmsubpd): Ditto.
(check_nmsubss): Ditto.
(check_nmsubsd): Ditto.
* gcc.target/i386/xop-haddX.c (check_sbyte2word): Add missing return.
(check_sbyte2dword):
Remove unnecessary postfix increment on a returned value.
(check_sbyte2qword): Ditto.
(check_sword2dword): Add missing return.
(check_sword2qword):
Remove unnecessary postfix increment on a returned value.
(check_dword2qword): Add missing return.
* gcc.target/i386/xop-hadduX.c (check_byte2word): Add missing return.
(check_byte2dword):
Remove unnecessary postfix increment on a returned value.
(check_byte2qword): Ditto.
(check_word2dword): Add missing return.
(check_word2qword):
Remove unnecessary postfix increment on a returned value.
(check_word2qword): Add missing return.
* gcc.target/i386/xop-hsubX.c (check_sbyte2word): Add missing return.
(check_sword2dword): Ditto.
(check_sword2qword): Ditto.

Tested on x86_64-linux-gnu {,-m32}.

Pushed to mainline.

Uros.
diff --git a/gcc/testsuite/gcc.target/i386/fma4-256-maccXX.c 
b/gcc/testsuite/gcc.target/i386/fma4-256-maccXX.c
index 134200af72a..ee0ddf171f4 100644
--- a/gcc/testsuite/gcc.target/i386/fma4-256-maccXX.c
+++ b/gcc/testsuite/gcc.target/i386/fma4-256-maccXX.c
@@ -17,7 +17,6 @@ union
   double d[NUM * 4];
 } dst, res, src1, src2, src3;
 
-
 /* Note that in macc*,msub*,mnmacc* and mnsub* instructions, the intermdediate 
product is not rounded, only the addition is rounded. */
 
@@ -56,7 +55,7 @@ check_maccps ()
if (dst.f[i + j] != res.f[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static int
@@ -70,7 +69,7 @@ check_maccpd ()
if (dst.d[i + j] != res.d[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static void
diff --git a/gcc/testsuite/gcc.target/i386/fma4-256-msubXX.c 
b/gcc/testsuite/gcc.target/i386/fma4-256-msubXX.c
index d6cafb4d542..0251eb2bce9 100644
--- a/gcc/testsuite/gcc.target/i386/fma4-256-msubXX.c
+++ b/gcc/testsuite/gcc.target/i386/fma4-256-msubXX.c
@@ -55,7 +55,7 @@ check_msubps ()
if (dst.f[i + j] != res.f[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static int
@@ -69,7 +69,7 @@ check_msubpd ()
if (dst.d[i + j] != res.d[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static void
@@ -92,5 +92,4 @@ fma4_test (void)
   
   if (check_msubpd ()) 
 abort ();
-  
 }
diff --git a/gcc/testsuite/gcc.target/i386/fma4-256-nmaccXX.c 
b/gcc/testsuite/gcc.target/i386/fma4-256-nmaccXX.c
index 261f302f2f7..d9671f3da43 100644
--- a/gcc/testsuite/gcc.target/i386/fma4-256-nmaccXX.c
+++ b/gcc/testsuite/gcc.target/i386/fma4-256-nmaccXX.c
@@ -55,7 +55,7 @@ check_nmaccps ()
if (dst.f[i + j] != res.f[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static int
@@ -69,7 +69,7 @@ check_nmaccpd ()
if (dst.d[i + j] != res.d[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static void
@@ -92,5 +92,4 @@ fma4_test (void)
   
   if (check_nmaccpd ()) 
 abort ();
-
 }
diff --git a/gcc/testsuite/gcc.target/i386/fma4-256-nmsubXX.c 
b/gcc/testsuite/gcc.target/i386/fma4-256-nmsubXX.c
index ccbdf0e9d6f..385cd950b97 100644
--- a/gcc/testsuite/gcc.target/i386/fma4-256-nmsubXX.c
+++ b/gcc/testsuite/gcc.target/i386/fma4-256-nmsubXX.c
@@ -55,7 +55,7 @@ check_nmsubps ()
if (dst.f[i + j] != res.f[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static int
@@ -69,7 +69,7 @@ check_nmsubpd ()
if (dst.d[i + j] != res.d[i + j]) 
  check_fails++;
   }
-  return check_fails++;
+  return check_fails;
 }
 
 static void
@@ -92,5 +92,4 @@ fma4_test (void)
   
   if (check_nmsubpd (&dst.y[i], &src1.d[i * 2

Re: [PATCH] libstdc++: Add support for C++20 barriers

2020-11-27 Thread Jonathan Wakely via Gcc-patches

On 20/11/20 16:30 -0800, Thomas Rodgers wrote:

From: Thomas Rodgers 

Should include all discussion on and off list to date.


Most of the comments in
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558090.html
still apply to this version.


Adds 

libstdc++/ChangeLog:

* include/Makefile.am (std_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/std/barrier: New file.
* include/std/version: Add __cpp_lib_barrier feature test macro.
* testsuite/30_thread/barrier/1.cc: New test.
* testsuite/30_thread/barrier/2.cc: Likewise.
* testsuite/30_thread/barrier/arrive_and_drop.cc: Likewise.
* testsuite/30_thread/barrier/arrive_and_wait.cc: Likewise.
* testsuite/30_thread/barrier/arrive.cc: Likewise.
* testsuite/30_thread/barrier/completion.cc: Likewise.
* testsuite/30_thread/barrier/max.cc: Likewise.
---
libstdc++-v3/include/Makefile.am  |   1 +
libstdc++-v3/include/Makefile.in  |   1 +
libstdc++-v3/include/std/barrier  | 258 ++
libstdc++-v3/include/std/version  |   3 +
.../testsuite/30_threads/barrier/1.cc |  27 ++
.../testsuite/30_threads/barrier/2.cc |  27 ++
.../testsuite/30_threads/barrier/arrive.cc|  51 
.../30_threads/barrier/arrive_and_drop.cc |  49 
.../30_threads/barrier/arrive_and_wait.cc |  51 
.../30_threads/barrier/completion.cc  |  54 
.../testsuite/30_threads/barrier/max.cc   |  44 +++
11 files changed, 566 insertions(+)
create mode 100644 libstdc++-v3/include/std/barrier
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/1.cc
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/2.cc
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive.cc
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive_and_drop.cc
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive_and_wait.cc
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/completion.cc
create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/max.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index ca413b8fdfe..a20dd461fd1 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -30,6 +30,7 @@ std_headers = \
${std_srcdir}/any \
${std_srcdir}/array \
${std_srcdir}/atomic \
+   ${std_srcdir}/barrier \
${std_srcdir}/bit \
${std_srcdir}/bitset \
${std_srcdir}/charconv \


The new header should also be added to include/precompiled/stdc++.h
and doc/doxygen/user.cfg.in


diff --git a/libstdc++-v3/include/std/barrier b/libstdc++-v3/include/std/barrier
new file mode 100644
index 000..a6cc6a058dd
--- /dev/null
+++ b/libstdc++-v3/include/std/barrier
@@ -0,0 +1,258 @@
+//  -*- C++ -*-
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// This implementation is based on libcxx/include/barrier
+//===-- barrier.h --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---===//


This file doesn't have the usual @file doxygen block.


+
+#ifndef _GLIBCXX_BARRIER
+#define _GLIBCXX_BARRIER 1
+
+#pragma GCC system_header
+
+#if __cplusplus > 201703L
+#include 
+
+#if defined(_GLIBCXX_HAS_GTHREADS)


This doesn't match the condition used in . I've
added _GLIBCXX_HAVE_ATOMIC_WAIT so it could check that.


+#define __cpp_lib_barrier 201907L
+#include 
+#include 


This is already included by 

I suggest:

#if __cplusplus > 201703L
#include 
#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT
#include 
...
#define __cpp_lib_barrier 201907L

We should only define the __cpp_lib macro after including all other
headers, otherwise we advertise to those headers that the feature
exists, but it hasn't been defined yet. Nothing is trying to use
barrier in the rest of the library yet, but that could change.


+#include 
+
+#include 
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_

Re: More new AIX errors

2020-11-27 Thread David Edelsohn via Gcc-patches
On Thu, Nov 26, 2020 at 6:02 PM Jonathan Wakely  wrote:
>
> On 26/11/20 22:33 +, Jonathan Wakely wrote:
> >On 26/11/20 15:33 -0500, David Edelsohn via Libstdc++ wrote:
> >>Hi, Jonathan
> >>
> >>Thanks for the recent fixes.  I still see a few errors that have crept
> >>in on AIX.  All the same:
> >>
> >>FAIL: 17_intro/headers/c++2020/all_no_rtti.cc (test for excess errors)
> >>FAIL: 17_intro/headers/c++2020/all_pedantic_errors.cc (test for excess 
> >>errors)
> >>FAIL: 17_intro/headers/c++2020/operator_names.cc (test for excess errors)
> >>FAIL: 17_intro/headers/c++2020/stdc++.cc (test for excess errors)
> >>FAIL: 17_intro/headers/c++2020/stdc++_multiple_inclusion.cc (test for
> >>excess errors)
> >>
> >>/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/latch:64: error:
> >>'notify_all' is not a member of 'std::__atomic_impl'
> >>/tmp/GCC/powerpc-ibm-aix7.2.3.0/libstdc++-v3/include/latch:75: error:
> >>'__atomic_wait' is not a member of 'std'; did you mean
> >>'__atomic_val_t'?
> >>
> >>Can you take a look when you have a moment?
> >
> >I think that was caused by r11-5436 which added  to the
> >precompiled header , and  incorrectly assumes
> >that the atomic waiting functions are always available. They're not
> >available for the gthr-single.h multilib on AIX.
> >
> >I'm testing the fix now.
>
> And here it is. Committed to trunk.

That fixed it!

Thanks, David


Re: [07/23] Add a class that multiplexes two pointer types

2020-11-27 Thread Richard Sandiford via Gcc-patches
Richard Sandiford via Gcc-patches  writes:
> One thing I'd deliberately tried to avoid was converting integers
> “back” to pointers, because that seemed like a more dangerous thing.
> That's why:
>
>>> +template
>>> +inline T2 *
>>> +pointer_mux::second_or_null () const
>>> +{
>>> +  // Micro optimization that's effective as of GCC 11: compute the value
>>> +  // of the second pointer as an integer and test that, so that the integer
>>> +  // result can be reused as the pointer and so that all computation can
>>> +  // happen before a branch on null.  This reduces the number of branches
>>> +  // needed for loops.
>>> +  return uintptr_t (m_ptr - 1) & 1 ? nullptr : known_second ();
>>> +}
>
> is written in a somewhat indirect way.

Gah, I really should learn to read my own quotes.  In my head this was
still using integer operations, but I take your point that the final form
is probably invalid.  I'll try to achieve the same effect in some other way.

Thanks,
Richard


Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread H.J. Lu via Gcc-patches
On Fri, Nov 27, 2020 at 8:22 AM Gerald Pfeifer  wrote:
>
> On Fri, 27 Nov 2020, H.J. Lu via Gcc-patches wrote:
> > +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
> > +target binutils supports @code{Intel CET} instructions and disabled
> > +otherwise.  In this case, the target libraries are configured to get
> > +additional @option{-fcf-protection} option.
>
> Does that refer to the Linux kernel or GNU/Linux?
>
> THe last sentence does not appear complete.  What do you want to say?
>
> "...target libraries are built with @option{-fcf-protection}"?

The new wording is

---
@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
target binutils supports @code{Intel CET} instructions and disabled
otherwise.  In this case, the target libraries are configured to get
additional @option{-fcf-protection} option.
---

On Linux/x86, if binutils supports CET, target libraries will be compiled
with -fcf-protection}.

> On Fri, 27 Nov 2020, H.J. Lu via Gcc-patches wrote:
> > OK for backport to GCC 10?
>
> Yes, once we have resolved the above.
>
> Gerald



-- 
H.J.


[PATCH] testsuite: Correct check_effective_target_hwaddress_exec

2020-11-27 Thread Matthew Malcomson via Gcc-patches
Hello,

-

This test should ensure that we can compile with hwasan, that such a compiled
binary runs as expected, *and* that we're running on a kernel which implements
the capability to ignore the top bytes of pointers in syscalls.

It was expected that a basic test of `int main(void) { return 0; }` would check
this, since there is a check called during `__hwasan_init` in libhwasan to
ensure that the kernel we're running on provides a `prctl` to request the
relaxed ABI.

Unfortunately, the check in libhwasan has a bug in it, and does not correctly
fail when the kernel feature is not around.  This means that check is not
automatically provided by the runtime.

The sanitizer runtime will be fixed but would like to install this fix here in
case fixing the library is not quick enough for the release (and so that people
running the testsuite do not see spurious errors in the meantime).

Tested by running testsuite on an AArch64 machine with and without the required
kernel.
Observed that the test does indeed fail when the kernel feature is unavailable
and pass when the feature is available.

Note that this test is directly targetting AArch64 by using `prctl` numbers
specific to it.  That's unfortunate, but once the runtime fix has gone in we
will be able to remove that requirement.

Ok for trunk?

gcc/testsuite/ChangeLog:

* lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Fix
check for correct kernel version.



### Attachment also inlined for ease of reply###


diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp
index 
892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2
 100644
--- a/gcc/testsuite/lib/hwasan-dg.exp
+++ b/gcc/testsuite/lib/hwasan-dg.exp
@@ -41,7 +41,24 @@ proc check_effective_target_fsanitize_hwaddress {} {
 
 proc check_effective_target_hwaddress_exec {} {
 if ![check_runtime hwaddress_exec {
-   int main (void) { return 0; }
+   #ifdef __cplusplus
+   extern "C" {
+   #endif
+   extern int prctl(int, unsigned long, unsigned long, unsigned long, 
unsigned long);
+   #ifdef __cplusplus
+   }
+   #endif
+   int main (void) {
+   #define PR_SET_TAGGED_ADDR_CTRL 55
+   #define PR_GET_TAGGED_ADDR_CTRL 56
+   #define PR_TAGGED_ADDR_ENABLE (1UL << 0)
+ if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1)
+   return 1;
+ if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 
-1
+ || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))
+   return 1;
+ return 0;
+   }
 }] {
return 0;
 }

diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp
index 
892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2
 100644
--- a/gcc/testsuite/lib/hwasan-dg.exp
+++ b/gcc/testsuite/lib/hwasan-dg.exp
@@ -41,7 +41,24 @@ proc check_effective_target_fsanitize_hwaddress {} {
 
 proc check_effective_target_hwaddress_exec {} {
 if ![check_runtime hwaddress_exec {
-   int main (void) { return 0; }
+   #ifdef __cplusplus
+   extern "C" {
+   #endif
+   extern int prctl(int, unsigned long, unsigned long, unsigned long, 
unsigned long);
+   #ifdef __cplusplus
+   }
+   #endif
+   int main (void) {
+   #define PR_SET_TAGGED_ADDR_CTRL 55
+   #define PR_GET_TAGGED_ADDR_CTRL 56
+   #define PR_TAGGED_ADDR_ENABLE (1UL << 0)
+ if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1)
+   return 1;
+ if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 
-1
+ || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))
+   return 1;
+ return 0;
+   }
 }] {
return 0;
 }



Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread Matthias Klose
On 11/27/20 3:54 PM, H.J. Lu via Gcc-patches wrote:
> On Fri, Nov 27, 2020 at 6:24 AM Richard Biener  wrote:
>>
>> OK.
>>
>> On Fri, 27 Nov 2020, H.J. Lu wrote:
>>
>>>   PR other/98027
>>>   * doc/install: Default to --enable-cet=auto.
>>> ---
>>>  gcc/doc/install.texi | 9 -
>>>  1 file changed, 4 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
>>> index 5f879ca4cea..021c347cc09 100644
>>> --- a/gcc/doc/install.texi
>>> +++ b/gcc/doc/install.texi
>>> @@ -2259,11 +2259,10 @@ instrumentation, see @option{-fcf-protection} 
>>> option.  When
>>>  to add @option{-fcf-protection} and, if needed, other target
>>>  specific options to a set of building options.
>>>
>>> -The option is disabled by default.  When @code{--enable-cet=auto}
>>> -is used, it is enabled on Linux/x86 if target binutils
>>> -supports @code{Intel CET} instructions and disabled otherwise.
>>> -In this case the target libraries are configured to get additional
>>> -@option{-fcf-protection} option.
>>> +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
>>> +target binutils supports @code{Intel CET} instructions and disabled
>>> +otherwise.  In this case, the target libraries are configured to get
>>> +additional @option{-fcf-protection} option.
>>>
>>>  @item --with-riscv-attribute=@samp{yes}, @samp{no} or @samp{default}
>>>  Generate RISC-V attribute by default, in order to record extra build
>>>
>>
> 
> OK for backport to GCC 10?

I only found that because of failing package builds in a test rebuild. See
PR98025. Is it safe to backport that, if it breaks the ABI of a runtime library
shipped with GCC 10?

Matthias


Re: [PATCH v2 01/31] PR target/58901: reload: Handle SUBREG of MEM with a mode-dependent address

2020-11-27 Thread Maciej W. Rozycki
On Fri, 27 Nov 2020, Ulrich Weigand wrote:

> >  NB I find the reindentation resulting in `push_reload' awful, just as I 
> > do either version of the massive logical expression involved.  Perhaps we 
> > could factor these out into `static inline' functions sometime, and then 
> > have them split into individual returns within?
> 
> I'm generally hesitant to do a lot of changes to the reload code base
> at this stage.  The strategy rather is to move all remaining targets
> over to LRA and then simply delete reload :-)
> 
> Given that you're modernizing the vax target, I'm wondering if you
> shouldn't rather go all the way and move it over to LRA as well,
> then you wouldn't be affected by any remaining reload deficiencies.
> (The major hurdle so far was that LRA doesn't support CC0, but it
> looks like you're removing that anyway ...)

 I considered moving to LRA, but decided to make one step at a time, 
especially given the number of issues the VAX port has been suffering 
from.  For example there are cases evident from regression test failures 
where new pseudos are created past-reload.  That would require tracking 
down, and I think switching to LRA would best be made with cleaner test 
results so as not to introduce another variable into the picture.

 So I would consider it GCC 12 material, so that we have an actual release 
with the VAX port converted to MODE_CC, but still using reload.  I think 
it could make some backports easier too if NetBSD people wanted to do it.

> > +  && (strict_low
> > + || (subreg_lowpart_p (in)
> > + && (CONSTANT_P (SUBREG_REG (in))
> > + || GET_CODE (SUBREG_REG (in)) == PLUS
> > + || strict_low
> 
> If we do this, then that "|| strict_low" clause is now redundant. 

 Oh!  I noticed the redundancy (which was in the way of the extra 
condition I was about to add) and rewrote the expression so as to remove 
it, and looks like I then left the line in place.  Maybe I didn't save the 
final change in the editor or something.  Sigh!  Thanks for spotting it.

> > + && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER
> > + && reg_equiv_mem (REGNO (SUBREG_REG (in)))
> > + && (mode_dependent_address_p
> > + (XEXP (reg_equiv_mem (REGNO (SUBREG_REG (in))), 0),
> > +  MEM_ADDR_SPACE (reg_equiv_mem (REGNO (SUBREG_REG (in)
> 
> I guess this is not incorrect, but I'm wondering if it would be
> *complete* -- there are other cases where reload replaces a pseudo
> with a MEM even where reg_equiv_mem is null.

 I wasn't aware of that.  What would be the usual scenario?

> That said, if it fixes the test suite errors you're seeing, it would
> probably be OK to go with just this minimal change -- unless we can
> just move to LRA as mentioned above.

 I've looked through the test results and indeed these suspicious ICEs 
remain:

.../gcc/testsuite/gcc.dg/pr83623.c:13:1: internal compiler error: in 
change_address_1, at emit-rtl.c:2275
.../gcc/testsuite/gcc.dg/torture/vshuf-main.inc:27:1: internal compiler error: 
in change_address_1, at emit-rtl.c:2275

corresponding to:

FAIL: gcc.dg/pr83623.c (internal compiler error)
FAIL: gcc.dg/pr83623.c (test for excess errors)
FAIL: gcc.dg/torture/vshuf-v16qi.c   -O2  (internal compiler error)
FAIL: gcc.dg/torture/vshuf-v16qi.c   -O2  (test for excess errors)

I'll investigate.

  Maciej


Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread H.J. Lu via Gcc-patches
On Fri, Nov 27, 2020 at 11:02 AM Matthias Klose  wrote:
>
> On 11/27/20 3:54 PM, H.J. Lu via Gcc-patches wrote:
> > On Fri, Nov 27, 2020 at 6:24 AM Richard Biener  wrote:
> >>
> >> OK.
> >>
> >> On Fri, 27 Nov 2020, H.J. Lu wrote:
> >>
> >>>   PR other/98027
> >>>   * doc/install: Default to --enable-cet=auto.
> >>> ---
> >>>  gcc/doc/install.texi | 9 -
> >>>  1 file changed, 4 insertions(+), 5 deletions(-)
> >>>
> >>> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
> >>> index 5f879ca4cea..021c347cc09 100644
> >>> --- a/gcc/doc/install.texi
> >>> +++ b/gcc/doc/install.texi
> >>> @@ -2259,11 +2259,10 @@ instrumentation, see @option{-fcf-protection} 
> >>> option.  When
> >>>  to add @option{-fcf-protection} and, if needed, other target
> >>>  specific options to a set of building options.
> >>>
> >>> -The option is disabled by default.  When @code{--enable-cet=auto}
> >>> -is used, it is enabled on Linux/x86 if target binutils
> >>> -supports @code{Intel CET} instructions and disabled otherwise.
> >>> -In this case the target libraries are configured to get additional
> >>> -@option{-fcf-protection} option.
> >>> +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
> >>> +target binutils supports @code{Intel CET} instructions and disabled
> >>> +otherwise.  In this case, the target libraries are configured to get
> >>> +additional @option{-fcf-protection} option.
> >>>
> >>>  @item --with-riscv-attribute=@samp{yes}, @samp{no} or @samp{default}
> >>>  Generate RISC-V attribute by default, in order to record extra build
> >>>
> >>
> >
> > OK for backport to GCC 10?
>
> I only found that because of failing package builds in a test rebuild. See
> PR98025. Is it safe to backport that, if it breaks the ABI of a runtime 
> library

libphobos has some CET issues which have been fixed in GCC 11.

> shipped with GCC 10?
>

It is just a documentation change.


-- 
H.J.


Re: [RFC] Decrease default timeout for libstdc++ tests to 6 minutes

2020-11-27 Thread Christophe Lyon via Gcc-patches
On Fri, 27 Nov 2020 at 17:13, Jonathan Wakely via Gcc-patches
 wrote:
>
> The default for the GCC testsuite is 300, i.e. 5 minutes, which is the
> same as the DejaGnu default.
>
> Libstdc++ overrides this to 600, i.e. 10 minutes.
>
> This seems ridiculously long. If any test takes that long on modern
> hardware, something is wrong. We've seen this a lot recently with
> buggy tests, and waiting for them to FAIL is tedious.
>
> I've already made libstdc++.exp respect the user's setting in
> ~/.dejagnurc or the global site.exp file. This means anybody testing
> on slow simulators or old hardware can choose their own timeout.
>
> I've added dg-timeout-factor to the slowest std::regex tests and have
> a patch to do it for the PSTL tests, which both take far too long to
> compile. That means you can choose a sensible timeout appropriate for
> most tests (e.g. 60 seconds) and not get spurious failures from the
> few dozen tests which are just very slow.
>
> I'd like to change the default to 6 minutes. If that goes well, I'd
> like to lower it even further.
>
> The main benefit of this will be that buggy tests which hang will get
> killed sooner, so we waste less time waiting for the inevitable
> timeout.
>

I think that's a good idea, I did have problems sometimes when
many tests timed out, causing the whole 'make check' to be
killed before completion by our compute farm management system.

Thanks

Christophe

>
> Here's the proposed patch for completeness:
>
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -248,7 +248,7 @@ proc libstdc++_init { testfile } {
>   # Set the default timeout for v3 tests.
>   # You can override this in ~/.dejagnurc or a .exp file named by 
> $DEJAGNU.
>   if {![info exists tool_timeout]} {
> -  set tool_timeout 600
> +  set tool_timeout 360
>   }
>
>   # Default settings.
>


Re: [PATCH] INSTALL: Default to --enable-cet=auto

2020-11-27 Thread Iain Buclaw via Gcc-patches
Excerpts from H.J. Lu's message of November 27, 2020 8:28 pm:
> On Fri, Nov 27, 2020 at 11:02 AM Matthias Klose  wrote:
>>
>> On 11/27/20 3:54 PM, H.J. Lu via Gcc-patches wrote:
>> > On Fri, Nov 27, 2020 at 6:24 AM Richard Biener  wrote:
>> >>
>> >> OK.
>> >>
>> >> On Fri, 27 Nov 2020, H.J. Lu wrote:
>> >>
>> >>>   PR other/98027
>> >>>   * doc/install: Default to --enable-cet=auto.
>> >>> ---
>> >>>  gcc/doc/install.texi | 9 -
>> >>>  1 file changed, 4 insertions(+), 5 deletions(-)
>> >>>
>> >>> diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
>> >>> index 5f879ca4cea..021c347cc09 100644
>> >>> --- a/gcc/doc/install.texi
>> >>> +++ b/gcc/doc/install.texi
>> >>> @@ -2259,11 +2259,10 @@ instrumentation, see @option{-fcf-protection} 
>> >>> option.  When
>> >>>  to add @option{-fcf-protection} and, if needed, other target
>> >>>  specific options to a set of building options.
>> >>>
>> >>> -The option is disabled by default.  When @code{--enable-cet=auto}
>> >>> -is used, it is enabled on Linux/x86 if target binutils
>> >>> -supports @code{Intel CET} instructions and disabled otherwise.
>> >>> -In this case the target libraries are configured to get additional
>> >>> -@option{-fcf-protection} option.
>> >>> +@code{--enable-cet=auto} is default.  CET is enabled on Linux/x86 if
>> >>> +target binutils supports @code{Intel CET} instructions and disabled
>> >>> +otherwise.  In this case, the target libraries are configured to get
>> >>> +additional @option{-fcf-protection} option.
>> >>>
>> >>>  @item --with-riscv-attribute=@samp{yes}, @samp{no} or @samp{default}
>> >>>  Generate RISC-V attribute by default, in order to record extra build
>> >>>
>> >>
>> >
>> > OK for backport to GCC 10?
>>
>> I only found that because of failing package builds in a test rebuild. See
>> PR98025. Is it safe to backport that, if it breaks the ABI of a runtime 
>> library
> 
> libphobos has some CET issues which have been fixed in GCC 11.
> 

There's still a remaining issue (see PR 98025) that I'm about to push a
fix for.

>> shipped with GCC 10?
>>
> 
> It is just a documentation change.
> 

I don't think the backport is necessary, as it is default disabled in
GCC 10.  It was only at the beginning of the GCC 11 development cycle
that it got changed to default auto.

Iain.


[committed] d: Add float and double overloads for all core.math intrinsics

2020-11-27 Thread Iain Buclaw via Gcc-patches
Hi,

For the math intrinsics: cos, fabs, ldexp, rint, rndtol, and sin, new
overloads have been added to the core.math module for matching float and
double types.  These have been implemented in the compiler.

A recent change to dump_function_to_file started triggering some
scan-tree-dump tests to FAIL, these have been adjusted as well when
updating the test.

Bootstrapped and regression tested on x86_64-linux-gnu with -mx32/-m32,
committed to mainline.

Regards
Iain.

---
gcc/d/ChangeLog:

* intrinsics.cc (maybe_expand_intrinsic): Handle new intrinsics.
* intrinsics.def (INTRINSIC_COS): Add float and double overloads.
(INTRINSIC_FABS): Likewise.
(INTRINSIC_LDEXP): Likewise.
(INTRINSIC_RINT): Likewise.
(INTRINSIC_RNDTOL): Likewise.
(INTRINSIC_SIN): Likewise.
(INTRINSIC_TOPREC): Adjust signature.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 5e4492c4.

gcc/testsuite/ChangeLog:

* gdc.dg/intrinsics.d: Adjust patterns in scan-tree-dump.
---
 gcc/d/intrinsics.cc   |  12 
 gcc/d/intrinsics.def  |  20 --
 gcc/testsuite/gdc.dg/intrinsics.d |  92 +++-
 libphobos/libdruntime/MERGE   |   2 +-
 libphobos/libdruntime/core/math.d | 113 +-
 5 files changed, 151 insertions(+), 88 deletions(-)

diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index a7de91019a4..4196ed3c552 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -814,10 +814,14 @@ maybe_expand_intrinsic (tree callexp)
 case INTRINSIC_CEIL:
 case INTRINSIC_CEILF:
 case INTRINSIC_CEILL:
+case INTRINSIC_COS:
+case INTRINSIC_COSF:
 case INTRINSIC_COSL:
 case INTRINSIC_EXP:
 case INTRINSIC_EXP2:
 case INTRINSIC_EXPM1:
+case INTRINSIC_FABS:
+case INTRINSIC_FABSF:
 case INTRINSIC_FABSL:
 case INTRINSIC_FLOOR:
 case INTRINSIC_FLOORF:
@@ -828,9 +832,15 @@ maybe_expand_intrinsic (tree callexp)
 case INTRINSIC_LOG:
 case INTRINSIC_LOG10:
 case INTRINSIC_LOG2:
+case INTRINSIC_RINT:
+case INTRINSIC_RINTF:
 case INTRINSIC_RINTL:
+case INTRINSIC_RNDTOL:
+case INTRINSIC_RNDTOLF:
 case INTRINSIC_RNDTOLL:
 case INTRINSIC_ROUND:
+case INTRINSIC_SIN:
+case INTRINSIC_SINF:
 case INTRINSIC_SINL:
 case INTRINSIC_SQRT:
 case INTRINSIC_SQRTF:
@@ -844,6 +854,8 @@ maybe_expand_intrinsic (tree callexp)
 
 case INTRINSIC_FMAX:
 case INTRINSIC_FMIN:
+case INTRINSIC_LDEXP:
+case INTRINSIC_LDEXPF:
 case INTRINSIC_LDEXPL:
   code = intrinsic_decls[intrinsic].built_in;
   gcc_assert (code != BUILT_IN_NONE);
diff --git a/gcc/d/intrinsics.def b/gcc/d/intrinsics.def
index 5b8cb712264..c05a6662865 100644
--- a/gcc/d/intrinsics.def
+++ b/gcc/d/intrinsics.def
@@ -93,22 +93,34 @@ DEF_D_BUILTIN (NEGSL, NONE, "negs", "core.checkedint", 
"FNaNbNiNflKbZl")
 
 /* core.math intrinsics.  */
 
+DEF_D_BUILTIN (COSF, COSF, "cos", "core.math", "FNaNbNiNffZf")
+DEF_D_BUILTIN (COS, COS, "cos", "core.math", "FNaNbNiNfdZd")
 DEF_D_BUILTIN (COSL, COSL, "cos", "core.math", "FNaNbNiNfeZe")
+DEF_D_BUILTIN (FABSF, FABSL, "fabs", "core.math", "FNaNbNiNffZf")
+DEF_D_BUILTIN (FABS, FABS, "fabs", "core.math", "FNaNbNiNfdZd")
 DEF_D_BUILTIN (FABSL, FABSL, "fabs", "core.math", "FNaNbNiNfeZe")
+DEF_D_BUILTIN (LDEXPF, LDEXPF, "ldexp", "core.math", "FNaNbNiNffiZf")
+DEF_D_BUILTIN (LDEXP, LDEXP, "ldexp", "core.math", "FNaNbNiNfdiZd")
 DEF_D_BUILTIN (LDEXPL, LDEXPL, "ldexp", "core.math", "FNaNbNiNfeiZe")
+DEF_D_BUILTIN (RINTF, RINTF, "rint", "core.math", "FNaNbNiNffZf")
+DEF_D_BUILTIN (RINT, RINT, "rint", "core.math", "FNaNbNiNfdZd")
 DEF_D_BUILTIN (RINTL, RINTL, "rint", "core.math", "FNaNbNiNfeZe")
 
-/* Not sure if `llroundl' stands as a good replacement for the expected
+/* Not sure if `llround{f,l}' stands as a good replacement for the expected
behavior of `rndtol()'.  */
+DEF_D_BUILTIN (RNDTOLF, LLROUNDF, "rndtol", "core.math", "FNaNbNiNffZl")
+DEF_D_BUILTIN (RNDTOL, LLROUND, "rndtol", "core.math", "FNaNbNiNfdZl")
 DEF_D_BUILTIN (RNDTOLL, LLROUNDL, "rndtol", "core.math", "FNaNbNiNfeZl")
 
+DEF_D_BUILTIN (SINF, SINF, "sin", "core.math", "FNaNbNiNffZf")
+DEF_D_BUILTIN (SIN, SIN, "sin", "core.math", "FNaNbNiNfdZd")
 DEF_D_BUILTIN (SINL, SINL, "sin", "core.math", "FNaNbNiNfeZe")
 DEF_D_BUILTIN (SQRTF, SQRTF, "sqrt", "core.math", "FNaNbNiNffZf")
 DEF_D_BUILTIN (SQRT, SQRT, "sqrt", "core.math", "FNaNbNiNfdZd")
 DEF_D_BUILTIN (SQRTL, SQRTL, "sqrt", "core.math", "FNaNbNiNfeZe")
-DEF_D_BUILTIN (TOPRECF, NONE, "toPrec", "core.math", "FNaNbNffZI1T")
-DEF_D_BUILTIN (TOPREC, NONE, "toPrec", "core.math", "FNaNbNfdZI1T")
-DEF_D_BUILTIN (TOPRECL, NONE, "toPrec", "core.math", "FNaNbNfeZI1T")
+DEF_D_BUILTIN (TOPRECF, NONE, "toPrec", "core.math", "FfZI1T")
+DEF_D_BUILTIN (TOPREC, NONE, "toPrec", "core.math", "FdZI1T")
+DEF_D_BUILTIN (TOPRECL, NONE, "toPrec", "core.math", "FeZI1T")
 
 /* std.math intrin

[committed] libphobos: Merge upstream phobos 38873fe6e.

2020-11-27 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D standard library with upstream phobos 38873fe6e,
adding support for FreeBSD/x86 53-bit precision reals, and removing all
support code and tests for the extern(Pascal) calling convention.

Bootstrapped and regression tested on x86_64-linux-gnu with -mx32/-m32,
committed to mainline.

Regards
Iain.

---
libphobos/ChangeLog:

* src/MERGE: Merge upstream phobos 38873fe6e.
---
 libphobos/src/MERGE   |  2 +-
 libphobos/src/std/complex.d   | 20 --
 libphobos/src/std/conv.d  | 26 +--
 .../src/std/internal/math/gammafunction.d |  7 ++
 libphobos/src/std/math.d  | 72 ---
 libphobos/src/std/traits.d|  6 +-
 6 files changed, 92 insertions(+), 41 deletions(-)

diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index de86ff5b65b..cd620c9c362 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-7948e096735adbc09da789fc28feadce24b0
+38873fe6ee70fe8e2b7a41b7c3663e090e27d61b
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/std/complex.d b/libphobos/src/std/complex.d
index b0780512ed3..8e488db4162 100644
--- a/libphobos/src/std/complex.d
+++ b/libphobos/src/std/complex.d
@@ -832,8 +832,13 @@ Complex!T sin(T)(Complex!T z)  @safe pure nothrow @nogc
 @safe pure nothrow unittest
 {
 static import std.math;
+import std.math : feqrel;
 assert(sin(complex(0.0)) == 0.0);
-assert(sin(complex(2.0L, 0)) == std.math.sin(2.0L));
+assert(sin(complex(2.0, 0)) == std.math.sin(2.0));
+auto c1 = sin(complex(2.0L, 0));
+auto c2 = complex(std.math.sin(2.0L), 0);
+assert(feqrel(c1.re, c2.re) >= real.mant_dig - 1 &&
+feqrel(c1.im, c2.im) >= real.mant_dig - 1);
 }
 
 
@@ -849,17 +854,20 @@ Complex!T cos(T)(Complex!T z)  @safe pure nothrow @nogc
 ///
 @safe pure nothrow unittest
 {
-import std.complex;
-import std.math;
+static import std.math;
+import std.math : feqrel;
 assert(cos(complex(0.0)) == 1.0);
-assert(cos(complex(1.3L)) == std.math.cos(1.3L));
+assert(cos(complex(1.3)) == std.math.cos(1.3));
 auto c1 = cos(complex(0, 5.2L));
-auto c2 = cosh(5.2L);
+auto c2 = complex(std.math.cosh(5.2L), 0.0L);
 assert(feqrel(c1.re, c2.re) >= real.mant_dig - 1 &&
 feqrel(c1.im, c2.im) >= real.mant_dig - 1);
+auto c3 = cos(complex(1.3L));
+auto c4 = complex(std.math.cos(1.3L), 0.0L);
+assert(feqrel(c3.re, c4.re) >= real.mant_dig - 1 &&
+feqrel(c3.im, c4.im) >= real.mant_dig - 1);
 }
 
-
 /**
 Params: y = A real number.
 Returns: The value of cos(y) + i sin(y).
diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d
index eaee62f2413..743d203b2bb 100644
--- a/libphobos/src/std/conv.d
+++ b/libphobos/src/std/conv.d
@@ -1629,6 +1629,8 @@ private void testIntegralToFloating(Integral, Floating)()
 
 private void testFloatingToIntegral(Floating, Integral)()
 {
+import std.math : floatTraits, RealFormat;
+
 bool convFails(Source, Target, E)(Source src)
 {
 try
@@ -1660,18 +1662,23 @@ private void testFloatingToIntegral(Floating, 
Integral)()
 {
 a = -a; // -Integral.min not representable as an Integral
 assert(convFails!(Floating, Integral, ConvOverflowException)(a)
-|| Floating.sizeof <= Integral.sizeof);
+|| Floating.sizeof <= Integral.sizeof
+|| floatTraits!Floating.realFormat == 
RealFormat.ieeeExtended53);
 }
 a = 0.0 + Integral.min;
 assert(to!Integral(a) == Integral.min);
 --a; // no more representable as an Integral
 assert(convFails!(Floating, Integral, ConvOverflowException)(a)
-|| Floating.sizeof <= Integral.sizeof);
+|| Floating.sizeof <= Integral.sizeof
+|| floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
 a = 0.0 + Integral.max;
-assert(to!Integral(a) == Integral.max || Floating.sizeof <= 
Integral.sizeof);
+assert(to!Integral(a) == Integral.max
+|| Floating.sizeof <= Integral.sizeof
+|| floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
 ++a; // no more representable as an Integral
 assert(convFails!(Floating, Integral, ConvOverflowException)(a)
-|| Floating.sizeof <= Integral.sizeof);
+|| Floating.sizeof <= Integral.sizeof
+|| floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
 // convert a value with a fractional part
 a = 3.14;
 assert(to!Integral(a) == 3);
@@ -3016,7 +3023,9 @@ if (isInputRange!Source && 
isSomeChar!(ElementType!Source) && !is(Source == enum
 @system unittest
 {
 // @system because strtod is not @safe.
-static if (real.mant_dig == 53)
+import std.math : floatTraits, RealFormat;
+
+static if (floatTraits!real.realFormat == RealFo

[committed] libphobos: Merge upstream druntime d37ef985.

2020-11-27 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D runtime library with upstream druntime
d37ef985, adding support for FreeBSD/x86 53-bit precision reals,
updating bindings for FreeBSD 12.x, and removing all support code and
tests for the extern(Pascal) calling convention.

Bootstrapped and regression tested on x86_64-linux-gnu with -mx32/-m32,
committed to mainline.

Regards
Iain.

---
libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime d37ef985.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES_FREEBSD): Add
core/sys/freebsd/config.d
* libdruntime/Makefile.in: Regenerate.
---
 libphobos/libdruntime/MERGE   |  2 +-
 libphobos/libdruntime/Makefile.am | 20 ++--
 libphobos/libdruntime/Makefile.in | 23 ++---
 libphobos/libdruntime/core/demangle.d | 15 +--
 libphobos/libdruntime/core/internal/convert.d | 11 ++-
 .../libdruntime/core/sys/freebsd/config.d | 24 +
 .../libdruntime/core/sys/freebsd/sys/event.d  | 35 +--
 .../libdruntime/core/sys/freebsd/sys/mount.d  | 14 ++-
 libphobos/libdruntime/core/sys/posix/dirent.d | 33 +--
 .../libdruntime/core/sys/posix/sys/stat.d | 94 ++-
 .../libdruntime/core/sys/posix/sys/types.d| 19 +++-
 libphobos/libdruntime/rt/critical_.d  |  2 +-
 libphobos/libdruntime/rt/dmain2.d | 21 +
 13 files changed, 214 insertions(+), 99 deletions(-)
 create mode 100644 libphobos/libdruntime/core/sys/freebsd/config.d

diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 91154eebdc9..6b65a44e6d2 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-5e4492c45172110b035591f5961b9f9f5adf6f13
+d37ef985a97eb446371ab4b2315a52b87233fbf3
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/druntime repository.
diff --git a/libphobos/libdruntime/Makefile.am 
b/libphobos/libdruntime/Makefile.am
index 4136642beeb..4798bdf777d 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -237,16 +237,16 @@ DRUNTIME_DSOURCES_DRAGONFLYBSD = 
core/sys/dragonflybsd/dlfcn.d \
core/sys/dragonflybsd/sys/mman.d core/sys/dragonflybsd/sys/socket.d \
core/sys/dragonflybsd/time.d
 
-DRUNTIME_DSOURCES_FREEBSD = core/sys/freebsd/dlfcn.d \
-   core/sys/freebsd/execinfo.d core/sys/freebsd/netinet/in_.d \
-   core/sys/freebsd/pthread_np.d core/sys/freebsd/string.d \
-   core/sys/freebsd/sys/_bitset.d core/sys/freebsd/sys/_cpuset.d \
-   core/sys/freebsd/sys/cdefs.d core/sys/freebsd/sys/elf.d \
-   core/sys/freebsd/sys/elf32.d core/sys/freebsd/sys/elf64.d \
-   core/sys/freebsd/sys/elf_common.d core/sys/freebsd/sys/event.d \
-   core/sys/freebsd/sys/link_elf.d core/sys/freebsd/sys/mman.d \
-   core/sys/freebsd/sys/mount.d core/sys/freebsd/time.d \
-   core/sys/freebsd/unistd.d
+DRUNTIME_DSOURCES_FREEBSD = core/sys/freebsd/config.d \
+   core/sys/freebsd/dlfcn.d core/sys/freebsd/execinfo.d \
+   core/sys/freebsd/netinet/in_.d core/sys/freebsd/pthread_np.d \
+   core/sys/freebsd/string.d core/sys/freebsd/sys/_bitset.d \
+   core/sys/freebsd/sys/_cpuset.d core/sys/freebsd/sys/cdefs.d \
+   core/sys/freebsd/sys/elf.d core/sys/freebsd/sys/elf32.d \
+   core/sys/freebsd/sys/elf64.d core/sys/freebsd/sys/elf_common.d \
+   core/sys/freebsd/sys/event.d core/sys/freebsd/sys/link_elf.d \
+   core/sys/freebsd/sys/mman.d core/sys/freebsd/sys/mount.d \
+   core/sys/freebsd/time.d core/sys/freebsd/unistd.d
 
 DRUNTIME_DSOURCES_LINUX = core/sys/linux/config.d \
core/sys/linux/dlfcn.d core/sys/linux/elf.d core/sys/linux/epoll.d \
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index d0bb3242c4f..0b895142a13 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -299,7 +299,7 @@ am__objects_7 = core/sys/dragonflybsd/dlfcn.lo \
 am__objects_9 = core/sys/bionic/fcntl.lo core/sys/bionic/string.lo \
core/sys/bionic/unistd.lo
 @DRUNTIME_OS_ANDROID_TRUE@am__objects_10 = $(am__objects_9)
-am__objects_11 = core/sys/freebsd/dlfcn.lo \
+am__objects_11 = core/sys/freebsd/config.lo core/sys/freebsd/dlfcn.lo \
core/sys/freebsd/execinfo.lo core/sys/freebsd/netinet/in_.lo \
core/sys/freebsd/pthread_np.lo core/sys/freebsd/string.lo \
core/sys/freebsd/sys/_bitset.lo \
@@ -861,16 +861,16 @@ DRUNTIME_DSOURCES_DRAGONFLYBSD = 
core/sys/dragonflybsd/dlfcn.d \
core/sys/dragonflybsd/sys/mman.d core/sys/dragonflybsd/sys/socket.d \
core/sys/dragonflybsd/time.d
 
-DRUNTIME_DSOURCES_FREEBSD = core/sys/freebsd/dlfcn.d \
-   core/sys/freebsd/execinfo.d core/sys/freebsd/netinet/in_.d \
-   core/sys/freebsd/pthread_np.d core/sys/freebsd/string.d \
-   core/sys/freebsd/sys/_bitset.d core/sys/freebsd/sys/_cpuset.d \
-   core/sys/freebsd/sys/cdefs.d core/sys/freebsd/sys/elf.d \
- 

[committed] d: Merge upstream dmd db0df3f7e.

2020-11-27 Thread Iain Buclaw via Gcc-patches
Hi,

This patch merges the D front-end with upstream DMD db0df3f7e, removing
all support code and tests for the extern(Pascal) calling convention.

Bootstrapped and regression tested on x86_64-linux-gnu with -mx32/-m32,
committed to mainline.

Regards
Iain.

---
gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd db0df3f7e.
* types.cc (TypeVisitor::visit (TypeFunction *)): Remove LINKpascal.
---
 gcc/d/dmd/MERGE   |   2 +-
 gcc/d/dmd/dmangle.c   |   2 -
 gcc/d/dmd/globals.h   |   1 -
 gcc/d/dmd/hdrgen.c|   2 -
 gcc/d/dmd/idgen.c |   1 -
 gcc/d/dmd/json.c  |   3 -
 gcc/d/dmd/parse.c |   4 +-
 gcc/d/types.cc|   1 -
 gcc/testsuite/gdc.test/compilable/callconv.d  |  20 -
 gcc/testsuite/gdc.test/compilable/test17419.d |   2 -
 .../gdc.test/fail_compilation/fail18970.d |   4 +-
 gcc/testsuite/gdc.test/runnable/dhry.d| 927 --
 gcc/testsuite/gdc.test/runnable/nested.d  |   9 -
 gcc/testsuite/gdc.test/runnable/test4.d   |  12 -
 14 files changed, 4 insertions(+), 986 deletions(-)
 delete mode 100644 gcc/testsuite/gdc.test/runnable/dhry.d

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index b00cb8262a7..453c5e8fd9c 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-b6a779e49a3bba8be6272e6730e14cbb6293ef77
+db0df3f7e6f2570f81d6c91ba173daa23361ea7b
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dmangle.c b/gcc/d/dmd/dmangle.c
index ea63bf3acf0..8f869266871 100644
--- a/gcc/d/dmd/dmangle.c
+++ b/gcc/d/dmd/dmangle.c
@@ -223,7 +223,6 @@ public:
 case LINKd: mc = 'F';   break;
 case LINKc: mc = 'U';   break;
 case LINKwindows:   mc = 'W';   break;
-case LINKpascal:mc = 'V';   break;
 case LINKcpp:   mc = 'R';   break;
 case LINKobjc:  mc = 'Y';   break;
 default:
@@ -415,7 +414,6 @@ public:
 
 case LINKc:
 case LINKwindows:
-case LINKpascal:
 case LINKobjc:
 buf->writestring(d->ident->toChars());
 return;
diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h
index 9d6e1ec37a9..6aff9b4b079 100644
--- a/gcc/d/dmd/globals.h
+++ b/gcc/d/dmd/globals.h
@@ -310,7 +310,6 @@ enum LINK
 LINKc,
 LINKcpp,
 LINKwindows,
-LINKpascal,
 LINKobjc,
 LINKsystem
 };
diff --git a/gcc/d/dmd/hdrgen.c b/gcc/d/dmd/hdrgen.c
index 22ae9c8253e..fd4d16241c4 100644
--- a/gcc/d/dmd/hdrgen.c
+++ b/gcc/d/dmd/hdrgen.c
@@ -1271,7 +1271,6 @@ public:
 case LINKc: p = "C";break;
 case LINKcpp:   p = "C++";  break;
 case LINKwindows:   p = "Windows";  break;
-case LINKpascal:p = "Pascal";   break;
 case LINKobjc:  p = "Objective-C";  break;
 default:
 assert(0);
@@ -3367,7 +3366,6 @@ const char *linkageToChars(LINK linkage)
 case LINKc: return "C";
 case LINKcpp:   return "C++";
 case LINKwindows:   return "Windows";
-case LINKpascal:return "Pascal";
 case LINKobjc:  return "Objective-C";
 case LINKsystem:return "System";
 default:assert(0);
diff --git a/gcc/d/dmd/idgen.c b/gcc/d/dmd/idgen.c
index a6267c515de..16f3b5f29ec 100644
--- a/gcc/d/dmd/idgen.c
+++ b/gcc/d/dmd/idgen.c
@@ -145,7 +145,6 @@ Msgtable msgtable[] =
 { "C", NULL },
 { "D", NULL },
 { "Windows", NULL },
-{ "Pascal", NULL },
 { "System", NULL },
 { "Objective", NULL },
 
diff --git a/gcc/d/dmd/json.c b/gcc/d/dmd/json.c
index 7da127eab54..802de81c4c2 100644
--- a/gcc/d/dmd/json.c
+++ b/gcc/d/dmd/json.c
@@ -323,9 +323,6 @@ public:
 case LINKwindows:
 property(name, "windows");
 break;
-case LINKpascal:
-property(name, "pascal");
-break;
 default:
 assert(false);
 }
diff --git a/gcc/d/dmd/parse.c b/gcc/d/dmd/parse.c
index d1017ac462c..3e4dd066c31 100644
--- a/gcc/d/dmd/parse.c
+++ b/gcc/d/dmd/parse.c
@@ -1294,8 +1294,6 @@ LINK Parser::parseLinkage(Identifiers **pidents, 
CPPMANGLE *pcppmangle, bool *pc
 nextToken();
 if (id == Id::Windows)
 link = LINKwindows;
-else if (id == Id::Pascal)
-link = LINKpascal;
 else if (id == Id::D)
 link = LINKd;
 else if (id == Id::C)
@@ -1399,7 +1397,7 @@ LINK Parser::parseLinkage(Identifiers **pidents, 
CPPMANGLE *pcppmangle

[committed] libphobos: Fix segfault at run-time when using custom Fibers (PR 98025)

2020-11-27 Thread Iain Buclaw via Gcc-patches
Hi,

When libphobos is configured with --enable-cet, this adds extra fields
to the Fiber class to support the ucontext_t fallback implementation.
These fields get omitted when compiling user code unless they also used
`-fversion=CET' to build their project, which resulted in data being
overwritten from within swapcontext().

On reviewing the ucontext_t definitions, it was found that the shadow
stack fields were missing, and the struct size didn't match up on X32.
This has been fixed in upstream druntime and merged down here.

Bootstrapped and regression tested on x86_64-linux-gnu with -mx32/-m32,
committed to mainline.

Regards
Iain.

---
libphobos/ChangeLog:

PR d/98025
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac (DCFG_ENABLE_CET): Substitute.
* libdruntime/MERGE: Merge upstream druntime 0fe7974c.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/core/thread.d: Import gcc.config.
(class Fiber): Add ucontext_t fields when GNU_Enable_CET is true.
* libdruntime/gcc/config.d.in (GNU_Enable_CET): Define.
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
---
 libphobos/Makefile.in   |  1 +
 libphobos/configure | 16 +---
 libphobos/configure.ac  | 11 ---
 libphobos/libdruntime/MERGE |  2 +-
 libphobos/libdruntime/Makefile.in   |  1 +
 libphobos/libdruntime/core/sys/posix/ucontext.d |  6 --
 libphobos/libdruntime/core/thread.d | 10 ++
 libphobos/libdruntime/gcc/config.d.in   |  3 +++
 libphobos/src/Makefile.in   |  1 +
 libphobos/testsuite/Makefile.in |  1 +
 10 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/libphobos/Makefile.in b/libphobos/Makefile.in
index f692b2f719e..a1395929819 100644
--- a/libphobos/Makefile.in
+++ b/libphobos/Makefile.in
@@ -217,6 +217,7 @@ CPPFLAGS = @CPPFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DCFG_ARM_EABI_UNWINDER = @DCFG_ARM_EABI_UNWINDER@
 DCFG_DLPI_TLS_MODID = @DCFG_DLPI_TLS_MODID@
+DCFG_ENABLE_CET = @DCFG_ENABLE_CET@
 DCFG_HAVE_64BIT_ATOMICS = @DCFG_HAVE_64BIT_ATOMICS@
 DCFG_HAVE_ATOMIC_BUILTINS = @DCFG_HAVE_ATOMIC_BUILTINS@
 DCFG_HAVE_LIBATOMIC = @DCFG_HAVE_LIBATOMIC@
diff --git a/libphobos/configure b/libphobos/configure
index 6d8461febf9..77a3125cbd6 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -722,6 +722,7 @@ LIBTOOL
 CFLAGS_FOR_BUILD
 CC_FOR_BUILD
 AR
+DCFG_ENABLE_CET
 CET_DFLAGS
 CET_FLAGS
 RANLIB
@@ -5652,11 +5653,20 @@ fi
 
 
 # To ensure that runtime code for CET is compiled in, add in D version flags.
-if test "$enable_cet" = yes; then
+if test x$enable_cet = xyes; then :
+
   CET_DFLAGS="$CET_FLAGS -fversion=CET"
+  DCFG_ENABLE_CET=true
+
+else
+
+  CET_DFLAGS=
+  DCFG_ENABLE_CET=false
 
 fi
 
+
+
 # This should be inherited in the recursive make, but ensure it is defined.
 test "$AR" || AR=ar
 
@@ -11744,7 +11754,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11747 "configure"
+#line 11757 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11850,7 +11860,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11853 "configure"
+#line 11863 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/libphobos/configure.ac b/libphobos/configure.ac
index 60aee3ffe8b..2d51e465a15 100644
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -69,10 +69,15 @@ AC_PROG_MAKE_SET
 GCC_CET_FLAGS(CET_FLAGS)
 AC_SUBST(CET_FLAGS)
 # To ensure that runtime code for CET is compiled in, add in D version flags.
-if test "$enable_cet" = yes; then
+AS_IF([test x$enable_cet = xyes], [
   CET_DFLAGS="$CET_FLAGS -fversion=CET"
-  AC_SUBST(CET_DFLAGS)
-fi
+  DCFG_ENABLE_CET=true
+], [
+  CET_DFLAGS=
+  DCFG_ENABLE_CET=false
+])
+AC_SUBST(CET_DFLAGS)
+AC_SUBST(DCFG_ENABLE_CET)
 
 # This should be inherited in the recursive make, but ensure it is defined.
 test "$AR" || AR=ar
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index 6b65a44e6d2..7162844b9b6 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-d37ef985a97eb446371ab4b2315a52b87233fbf3
+0fe7974cf53b75db59461de2a3d6e53ce933d297
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/druntime repository.
diff --git a/libphobos/libdruntime/Makefile.in 
b/libphobos/libdruntime/Makefile.in
index 0b895142a13..99ee8b92afa 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -577,6 +577,7 @@ CPPFLAGS = @CPPFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DCFG_ARM_EABI_UNWINDER = @DCFG_ARM_EABI_UNWINDER@
 DCFG_DLPI_TLS_MODID = @DCFG_DLPI_TLS_MODID@
+DCFG_ENABLE_CET = @DCFG_ENABLE_CET@

Re: [PATCH] fold-const: Don't consider NaN non-negative [PR97965]

2020-11-27 Thread Joseph Myers
On Thu, 26 Nov 2020, Richard Biener wrote:

> Is copysign (x, NaN) supposed to be well-defined?  We'd stop folding

copysign with NaN arguments (including sNaN) is well-defined and copies 
the sign bit without raising any exceptions.

> this then, no?  I think the ABS_EXPR < 0 to false folding is
> simply incomplete and should first check whether the operands are
> ordered?  That said, NaN is nonnegative but NaN < 0 isn't false(?)

Comparisons involving NaN with < <= > >= == all return false.

For example, with -fno-trapping-math, it's valid to fold fabs (anything) < 
0 to false (preserving any side effects from evaluating "anything"), but 
it's not valid to fold fabs (anything) >= 0 to true, because NaN < 0 and 
NaN >= 0 are both false.  With -ftrapping-math, neither can be folded if 
the argument might be a NaN.

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


RE: [PATCH] fold-const: Don't consider NaN non-negative [PR97965]

2020-11-27 Thread Joseph Myers
On Thu, 26 Nov 2020, Roger Sayle wrote:

> NaNs have a sign-bit, so copyexpr (and negate and ABS_EXPR) are 
> well-defined, and it's reasonable for nonnegative_p to reflect this.  
> IMHO, the true bug is that we can't fold away (any) comparisons against 
> NaN when flag_trapping_math, irrespective of qNaN, -qNaN, sNaN or -sNaN.

I think the comment documenting the semantics of any function mentioning 
"nonnegative" needs to say explicitly which of at least three possible 
things it means, and then callers should be checked to see if that matches 
the semantics they want.

1. !(argument < 0)

2. argument >= 0

3. !signbit(argument)

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


Re: [PATCH v2 01/31] PR target/58901: reload: Handle SUBREG of MEM with a mode-dependent address

2020-11-27 Thread Maciej W. Rozycki
On Fri, 27 Nov 2020, Maciej W. Rozycki wrote:

> > That said, if it fixes the test suite errors you're seeing, it would
> > probably be OK to go with just this minimal change -- unless we can
> > just move to LRA as mentioned above.
> 
>  I've looked through the test results and indeed these suspicious ICEs 
> remain:
> 
> .../gcc/testsuite/gcc.dg/pr83623.c:13:1: internal compiler error: in 
> change_address_1, at emit-rtl.c:2275
> .../gcc/testsuite/gcc.dg/torture/vshuf-main.inc:27:1: internal compiler 
> error: in change_address_1, at emit-rtl.c:2275

 I've double-checked these and this:

> corresponding to:
> 
> FAIL: gcc.dg/pr83623.c (internal compiler error)
> FAIL: gcc.dg/pr83623.c (test for excess errors)

comes from this insn:

(insn 17 14 145 (set (reg:SI 1 %r1)
(zero_extract:SI (mem/c:SI (symbol_ref:SI ("x") ) [1 x+0 S4 A128])
(const_int 16 [0x10])
(const_int 16 [0x10]))) ".../gcc/testsuite/gcc.dg/pr83623.c":12:9 
101 {*vax.md:805}
 (nil))

and this:

> FAIL: gcc.dg/torture/vshuf-v16qi.c   -O2  (internal compiler error)
> FAIL: gcc.dg/torture/vshuf-v16qi.c   -O2  (test for excess errors)

likewise:

(insn 83 82 84 (set (reg:SI 5 %r5 [84])
(zero_extract:SI (mem/c:SI (symbol_ref:SI ("b") ) [0 b+0 S4 A128])
(const_int 8 [0x8])
(const_int 16 [0x10]))) 
".../gcc/testsuite/gcc.dg/torture/vshuf-main.inc":28:1 101 {*vax.md:805}
 (nil))

So these are not related (and addressed with 22/31 BTW).

 I'll make the "|| strict_low" update then and push this change along with 
the rest once all the verification has completed, presumably this coming 
Monday.

 Thanks for your review!

  Maciej


[PATCH v3 01/31] PR target/58901: reload: Handle SUBREG of MEM with a mode-dependent address

2020-11-27 Thread Maciej W. Rozycki
From: Matt Thomas 

Fix an ICE with the handling of RTL expressions like:

(subreg:QI (mem/c:SI (plus:SI (plus:SI (mult:SI (reg/v:SI 0 %r0 [orig:67 i ] 
[67])
(const_int 4 [0x4]))
(reg/v/f:SI 7 %r7 [orig:59 doacross ] [59]))
(const_int 40 [0x28])) [1 MEM[(unsigned int *)doacross_63 + 40B + 
i_106 * 4]+0 S4 A32]) 0)

that causes the compilation of libgomp to fail:

during RTL pass: reload
.../libgomp/ordered.c: In function 'GOMP_doacross_wait':
.../libgomp/ordered.c:507:1: internal compiler error: in change_address_1, at 
emit-rtl.c:2275
  507 | }
  | ^
0x10a3462b change_address_1
.../gcc/emit-rtl.c:2275
0x10a353a7 adjust_address_1(rtx_def*, machine_mode, poly_int<1u, long>, int, 
int, int, poly_int<1u, long>)
.../gcc/emit-rtl.c:2409
0x10ae2993 alter_subreg(rtx_def**, bool)
.../gcc/final.c:3368
0x10ae25cf cleanup_subreg_operands(rtx_insn*)
.../gcc/final.c:3322
0x110922a3 reload(rtx_insn*, int)
.../gcc/reload1.c:1232
0x10de2bf7 do_reload
.../gcc/ira.c:5812
0x10de3377 execute
.../gcc/ira.c:5986

in a `vax-netbsdelf' build, where an attempt is made to change the mode
of the contained memory reference to the mode of the containing SUBREG.
Such RTL expressions are produced by the VAX shift and rotate patterns
(`ashift', `ashiftrt', `rotate', `rotatert') where the count operand
always has the QI mode regardless of the mode, either SI or DI, of the
datum shifted or rotated.

Such a mode change cannot work where the memory reference uses the
indexed addressing mode, where a multiplier is implied that in the VAX
ISA depends on the width of the memory access requested and therefore
changing the machine mode would change the address calculation as well.

Avoid the attempt then by forcing the reload of any SUBREGs containing
a mode-dependent memory reference, also fixing these regressions:

FAIL: gcc.c-torture/compile/pr46883.c   -Os  (internal compiler error)
FAIL: gcc.c-torture/compile/pr46883.c   -Os  (test for excess errors)
FAIL: gcc.c-torture/execute/20120808-1.c   -O2  (internal compiler error)
FAIL: gcc.c-torture/execute/20120808-1.c   -O2  (test for excess errors)
FAIL: gcc.c-torture/execute/20120808-1.c   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions  (internal compiler 
error)
FAIL: gcc.c-torture/execute/20120808-1.c   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions  (test for excess 
errors)
FAIL: gcc.c-torture/execute/20120808-1.c   -O3 -g  (internal compiler error)
FAIL: gcc.c-torture/execute/20120808-1.c   -O3 -g  (test for excess errors)
FAIL: gcc.c-torture/execute/20120808-1.c   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  (internal compiler error)
FAIL: gcc.c-torture/execute/20120808-1.c   -O2 -flto -fno-use-linker-plugin 
-flto-partition=none  (test for excess errors)
FAIL: gcc.c-torture/execute/20120808-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  (internal compiler error)
FAIL: gcc.c-torture/execute/20120808-1.c   -O2 -flto -fuse-linker-plugin 
-fno-fat-lto-objects  (test for excess errors)
FAIL: gcc.dg/20050629-1.c (internal compiler error)
FAIL: gcc.dg/20050629-1.c (test for excess errors)
FAIL: c-c++-common/torture/pr53505.c   -Os  (internal compiler error)
FAIL: c-c++-common/torture/pr53505.c   -Os  (test for excess errors)
FAIL: gfortran.dg/coarray_failed_images_1.f08   -Os  (internal compiler error)
FAIL: gfortran.dg/coarray_stopped_images_1.f08   -Os  (internal compiler error)

With test case #0 included it causes a reload with:

(insn 15 14 16 4 (set (reg:SI 31)
(ashift:SI (const_int 1 [0x1])
(subreg:QI (reg:SI 30 [ MEM[(int *)s_8(D) + 4B + _5 * 4] ]) 0))) 
"pr58901-0.c":15:12 94 {ashlsi3}
 (expr_list:REG_DEAD (reg:SI 30 [ MEM[(int *)s_8(D) + 4B + _5 * 4] ])
(nil)))

as follows:

Reloads for insn # 15
Reload 0: reload_in (SI) = (reg:SI 30 [ MEM[(int *)s_8(D) + 4B + _5 * 4] ])
ALL_REGS, RELOAD_FOR_INPUT (opnum = 2)
reload_in_reg: (reg:SI 30 [ MEM[(int *)s_8(D) + 4B + _5 * 4] ])
reload_reg_rtx: (reg:SI 5 %r5)

resulting in:

(insn 37 14 15 4 (set (reg:SI 5 %r5)
(mem/c:SI (plus:SI (plus:SI (mult:SI (reg/v:SI 1 %r1 [orig:25 i ] [25])
(const_int 4 [0x4]))
(reg/v/f:SI 4 %r4 [orig:29 s ] [29]))
(const_int 4 [0x4])) [1 MEM[(int *)s_8(D) + 4B + _5 * 4]+0 S4 
A32])) "pr58901-0.c":15:12 12 {movsi_2}
 (nil))
(insn 15 37 16 4 (set (reg:SI 2 %r2 [31])
(ashift:SI (const_int 1 [0x1])
(reg:QI 5 %r5))) "pr58901-0.c":15:12 94 {ashlsi3}
 (nil))

and assembly like:

.L3:
movl 4(%r4)[%r1],%r5
ashl %r5,$1,%r2
xorl2 %r2,%r0
incl %r1
cmpl %r1,%r3
jneq .L3

produced for the loop, providing optimization has been enabled.  

Likewise with test case #1 the reload of:

(insn 17 16 18 4 (set (reg:SI 34)
(and:SI (subre

PING^1 Re: [PATCH v2] C-family : Add attribute 'unavailable'.

2020-11-27 Thread Iain Sandoe

Hi

I believe this version addressed Joseph’s and Richard’s comment, but it
C++ review.

thanks
Iain



Iain Sandoe  wrote:


Joseph Myers  wrote:


This patch seems to be missing documentation for the new attribute in
extend.texi.


Apologies, for that omission, revised patch includes the documentation and
also addresses Richi’s comments.

documentation patch tested with “make pdf” and visual inspection of the  
output.


OK now?
thanks
Iain

—— commit message.

If an interface is marked 'deprecated' then, presumably, at some point it
will be withdrawn and no longer available.  The 'unavailable' attribute
makes it possible to mark up interfaces to indicate this status.  It is  
used
quite extensively in some codebases where a single set of headers can be  
used

to permit code generation for multiple system versions.

From a configuration perspective, it also allows a compile test to  
determine

that an interface is missing - rather than requiring a link test.

The implementation follows the pattern of attribute deprecated, but  
produces

an error (where deprecation produces a warning).

This attribute has been implemented in clang for some years.

gcc/c-family/ChangeLog:

* c-attribs.c (handle_unavailable_attribute): New.

gcc/c/ChangeLog:

* c-decl.c (enum deprecated_states): Add unavailable state.
(merge_decls): Copy unavailability.
(quals_from_declspecs): Handle unavailable case.
(start_decl): Amend the logic handling suppression of nested
deprecation states to include unavailability.
(smallest_type_quals_location): Amend comment.
(grokdeclarator): Handle the unavailable deprecation state.
(declspecs_add_type): Set TREE_UNAVAILABLE from the decl specs.
* c-tree.h (struct c_declspecs): Add unavailable_p.
* c-typeck.c (build_component_ref): Handle unavailability.
(build_external_ref): Likewise.

gcc/cp/ChangeLog:

* call.c (build_over_call): Handle unavailable state in addition to
deprecation.
* class.c (type_build_ctor_call): Likewise.
(type_build_dtor_call): Likewise.
* cp-tree.h: Rename cp_warn_deprecated_use to
cp_handle_deprecated_or_unavailable.
* decl.c (duplicate_decls): Merge unavailability.
(grokdeclarator): Handle unavailability in addition to deprecation.
(type_is_unavailable): New.
(grokparms): Handle unavailability in addition to deprecation.
* decl.h (enum deprecated_states): Add
UNAVAILABLE_DEPRECATED_SUPPRESS.
* decl2.c (cplus_decl_attributes): Propagate unavailability to
templates.
(cp_warn_deprecated_use): Rename to ...
(cp_handle_deprecated_or_unavailable): ... this and amend to handle
the unavailable case. It remains a warning in the case of deprecation
but becomes an error in the case of unavailability.
(cp_warn_deprecated_use_scopes): Handle unavailability.
(mark_used): Likewise.
* parser.c (cp_parser_template_name): Likewise.
(cp_parser_template_argument): Likewise.
(cp_parser_parameter_declaration_list): Likewise.
* typeck.c (build_class_member_access_expr): Likewise.
(finish_class_member_access_expr): Likewise.
* typeck2.c (build_functional_cast_1): Likewise.

gcc/ChangeLog:

* doc/extend.texi: Document unavailable attribute.
* print-tree.c (print_node): Handle unavailable attribute.
* tree-core.h (struct tree_base): Add a bit to carry unavailability.
* tree.c (error_unavailable_use): New.
* tree.h (TREE_UNAVAILABLE): New.
(error_unavailable_use): New.

gcc/objc/ChangeLog:

* objc-act.c (objc_add_property_declaration): Register unavailable
attribute.
(maybe_make_artificial_property_decl): Set available.
(objc_maybe_build_component_ref): Generalise to the method prototype
to count availability.
(objc_build_class_component_ref): Likewise.
(build_private_template): Likewise.
(objc_decl_method_attributes): Handle unavailable attribute.
(lookup_method_in_hash_lists): Amend comments.
(objc_finish_message_expr): Handle unavailability in addition to
deprecation.
(start_class): Likewise.
(finish_class): Likewise.
(lookup_protocol): Likewise.
(objc_declare_protocol): Likewise.
(start_protocol): Register unavailable attribute.
(really_start_method): Likewise.
(objc_gimplify_property_ref): Emit error on encountering an
unavailable entity (and a warning for a deprecated one).

gcc/testsuite/ChangeLog:

* g++.dg/ext/attr-unavailable-1.C: New test.
* g++.dg/ext/attr-unavailable-2.C: New test.
* g++.dg/ext/attr-unavailable-3.C: New test.
* g++.dg/ext/attr-unavailable-4.C: New test.
* g++.dg/ext/attr-unavailable-5.C: New test.
* g++.dg/ext/attr-unava

PING^1 Re: [PATCH] C++ : Add the -stdlib= option.

2020-11-27 Thread Iain Sandoe

Hi Folks,

this patch needs C++ review

thanks
Iain

Iain Sandoe  wrote:

resending - the first & second attempt didn’t seem to make it to  
gcc-patches.


Hi

This option allows the user to specify alternate C++ runtime libraries,
for example when a platform uses libc++ as the installed C++ runtime.

It is the same spelling as a clang option that allows that to use  
libstdc++.


I have had this patch for some time now (more than a year) on Darwin
branches.

For Darwin [>=11] (and I expect modern FreeBSD) the fact that the installed
C++ runtime is libc++ means conflicts can and do occur when using G++.

I expect that the facility will also be useful for folks who regularly  
try to
ensure that GCC and clang stay compatible, it is a credit to that effort  
that

the replacement is pretty much “drop in”.

Testing:

The patch applies without regression on *darwin* and x86_64-linux-gnu.

That doesn’t say much about whether it does what’s intended, of course,
and testing in-tree is not a viable option (it would need a lot of work,  
not

to mention the fact that it depends on an external source base).  So I’ve
tested this quite extensively on x86 Darwin and Linux.

It’s a lot easier to use an LLVM branch >= 9 for this since there is a
missing __cxa symbol before that (I originally used LLVM-7 for ‘reasons’).
Since coroutines was committed to GCC we have a  header
where the libc++ implementation is still using the 
version, so that one needs to  account for this.

Here’s an LLVM-9 tree with an added  header (as an example)
https://github.com/iains/llvm-project/tree/9.0.1-gcc-stdlib
(in case someone wants to try this out in the near future; I don’t think  
that

LLVM-10 will be much different, at least the coroutine header is unchanged
there)

I’ve used this ‘in anger’ on Darwin to build a toolset which includes a  
number

of C++ heavy applications (e.g. LLVM, cmake, etc) and it allowed some of
these to work effectively where it had not been possible before.

One can also do an “installed test” of g++
for that there are (a relatively modest number of) test fails.
AFAICT, there is nothing significant there - some tests fail because the  
output
isn’t expecting to see libc++ __1 inline namespace, some fail because  
libc++

(as per current branches) doesn’t allow use with GCC + std=c++98, some
are warning diagnostics etc.

[how compatible libc++ is, is somewhat independent of the patch itself; but
it seems “very compatible” is a starting assessment].

phew… description longer than patch, it seems.

OK for master?
thanks
Iain

—— commit message

This option allows the user to specify alternate C++ runtime libraries,
for example when a platform uses libc++ as the installed C++ runtime.

We introduce the command line option: -stdlib= which is the user-facing
mechanism to select the C++ runtime to be used when compiling and linking
code.  This is the same option spelling as that used by clang to allow the
use of libstdc++.

The availability (and thus function) of the option are a configure-time
choice using the configuration control:
--with-gxx-libcxx-include-dir=

Specification of the path for the libc++ headers, enables the -stdlib=
option (using the path as given), default values are set when the path
is unconfigured.

If --with-gxx-libcxx-include-dir is given together with --with-sysroot=,
then we test to see if the include path starts with the sysroot and, if so,
record the sysroot-relative component as the local path.  At runtime, we
prepend the sysroot that is actually active.

At link time, we use the C++ runtime in force and (if that is libc++) also
append the libc++abi ABI library. As for other cases, if a target sets the
name pointer for the ABI library to NULL the G++ driver will omit it from
the link line.

gcc/ChangeLog:

* configure.ac: Add gxx-libcxx-include-dir handled
in the same way as the regular cxx header directory.
* Makefile.in: Regenerated.
* config.in: Likewise.
* configure: Likewise.
* cppdefault.c: Pick up libc++ headers if the option
is enabled.
* incpath.c (add_standard_paths): Allow for multiple
c++ header include path variants.
* doc/invoke.texi: Document the -stdlib= option.

gcc/c-family/ChangeLog:

* c.opt: Add -stdlib= option and enumerations for
libstdc++ and libc++.

gcc/cp/ChangeLog:

* g++spec.c (LIBCXX, LIBCXX_PROFILE, LIBCXX_STATIC): New.
(LIBCXXABI, LIBCXXABI_PROFILE, LIBCXXABI_STATIC): New.
(lang_specific_driver): Allow selection amongst multiple
c++ libraries to be added to the link command.
---
gcc/Makefile.in |  6 +
gcc/c-family/c.opt  | 14 +++
gcc/config.in   |  6 +
gcc/configure   | 57 +++--
gcc/configure.ac| 44 ++
gcc/cp/g++spec.c| 53 ++---
gcc/cppdefault.c|  5 
gcc/doc/invoke.texi | 11 +

Re: [PATCH] [WIP] openmp: Add OpenMP 5.0 task detach clause support

2020-11-27 Thread Kwok Cheung Yeung

Hello

This is an updated version of the WIP patch for task detach support. Any 
comments would be welcome!


On 11/11/2020 7:06 pm, Kwok Cheung Yeung wrote:

- No error checking at the front-end.


The detach clause is now parsed properly in C, C++ and Fortran, and will raise 
an error if the syntax is incorrect or if the event variable is of the wrong type.


- The memory for the event is not mapped on the target. This means that if 
omp_fulfill_event is called from an 'omp target' section with a target that does 
not share memory with the host, the event will not be fulfilled (and a segfault 
will probably occur).


I was thinking of something along the lines of:

#pragma omp task detach (event)
{
}

#pragma omp target
{
  omp_fulfill_event (event);
}

Would something like this be expected to work? I cannot find many examples of 
the detach clause online, and none of them use any offloading constructs.


- The tasks awaiting event fulfillment currently wait until there are no other 
runnable tasks left. A better approach would be to poll (without blocking) the 
waiting tasks whenever any task completes, immediately removing any now-complete 
tasks and requeuing any dependent tasks.


This has now been implemented. On every iteration of the main loop in 
gomp_barrier_handle_tasks, it first checks to see if any tasks in the detach 
queue have a fulfilled completion event, and if so it will remove the task and 
requeue any dependent tasks.


Thanks

Kwok
From 3611024b39ea5b264ec2fd35ffa64360861052af Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung 
Date: Fri, 27 Nov 2020 11:59:12 -0800
Subject: [PATCH] openmp: Add support for the OpenMP 5.0 task detach clause

2020-11-27  Kwok Cheung Yeung  

gcc/
* builtin-types.def (BT_PTR_SIZED_INT): New primitive type.
(BT_FN_PSINT_VOID): New function type.
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT): Rename
to...
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PSINT):
...this.  Add extra argument.
* gimplify.c (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_DETACH.
(gimplify_adjust_omp_clauses): Likewise.
* omp-builtins.def (BUILT_IN_GOMP_TASK): Change function type to
BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PSINT.
(BUILT_IN_GOMP_NEW_EVENT): New.
* omp-expand.c (expand_task_call): Add detach argument when generating
call to GOMP_task.
* omp-low.c (scan_sharing_clauses): Setup data environment for detach
clause.
(lower_detach_clause): New.
(lower_omp_taskreg): Call lower_detach_clause for detach clause.  Add
Gimple statements generated for detach clause.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DETACH.
* tree-pretty-print.c (dump_omp_clause): Handle OMP_CLAUSE_DETACH.
* tree.c (omp_clause_num_ops): Add entry for OMP_CLAUSE_DETACH.
(omp_clause_code_name): Add entry for OMP_CLAUSE_DETACH.
(walk_tree_1): Handle OMP_CLAUSE_DETACH.
* tree.h (OMP_CLAUSE_DETACH_EXPR): New.

gcc/c-family/
* c-pragma.h (pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_DETACH.
Redefine PRAGMA_OACC_CLAUSE_DETACH.

gcc/c/
* c-parser.c (c_parser_omp_clause_detach): New.
(c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH clause.
(OMP_TASK_CLAUSE_MASK): Add mask for PRAGMA_OMP_CLAUSE_DETACH.
* c-typeck.c (c_finish_omp_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH
clause.

gcc/cp/
* parser.c (cp_parser_omp_clause_detach): New.
(cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH.
(OMP_TASK_CLAUSE_MASK): Add mask for PRAGMA_OMP_CLAUSE_DETACH.
* semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_DETACH clause.

gcc/fortran/
* dump-parse-tree.c (show_omp_clauses): Handle detach clause.
* frontend-passes.c (gfc_code_walker): Walk detach expression.
* gfortran.h (struct gfc_omp_clauses): Add detach field.
(gfc_c_intptr_kind): New.
* openmp.c (gfc_free_omp_clauses): Free detach clause.
(gfc_match_omp_detach): New.
(enum omp_mask1): Add OMP_CLAUSE_DETACH.
(enum omp_mask2): Remove OMP_CLAUSE_DETACH.
(gfc_match_omp_clauses): Handle OMP_CLAUSE_DETACH for OpenMP.
(OMP_TASK_CLAUSES): Add OMP_CLAUSE_DETACH.
* trans-openmp.c (gfc_trans_omp_clauses): Handle detach clause.
* trans-types.c (gfc_c_intptr_kind): New.
(gfc_init_kinds): Initialize gfc_c_intptr_kind.
* types.def (BT_PTR_SIZED_INT): New type.
(BT_FN_PSINT_VOID): New function type.
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT): Rename
to...
(BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PSINT):
...this.  Add extra argument.

libgomp/
* fortran.c (omp_fulfill_event_): New.
* libgomp.h

PING Re: [PATCH] openmp: Implicit 'declare target' for C++ static initializers

2020-11-27 Thread Kwok Cheung Yeung

Hello

This patch still needs review.

Thanks

Kwok

On 19/11/2020 6:07 pm, Kwok Cheung Yeung wrote:

On 29/10/2020 10:03 am, Jakub Jelinek wrote:

I'm actually not sure how this can work correctly.
Let's say we have
int foo () { return 1; }
int bar () { return 2; }
int baz () { return 3; }
int qux () { return 4; }
int a = foo ();
int b = bar ();
int c = baz ();
int *d = &c;
int e = qux ();
int f = e + 1;
int *g = &f;
#pragma omp declare target to (b, d, g)
So, for the implicit declare target discovery, a is not declare target to,
nor is foo, and everything else is; b, d, g explicitly, c because it is
referenced in initializer of b, f because it is mentioned in initializer of
g and e because it is mentioned in initializer of f.
Haven't checked if the new function you've added is called before or after
analyze_function calls omp_discover_implicit_declare_target, but I don't
really see how it can work when it is not inside of that function, so that
discovery of new static vars that are implicitly declare target to doesn't
result in marking of its dynamic initializers too.  Perhaps we need a
langhook for that.  But if it is a separate function, either it is called
before the other discovery and will ignore static initializers for vars
that will only be marked as implicit declare target to later, or it is done
afterwards, but then it would really need to duplicate everything what the
other function does, otherwise it woiuldn't discover everything.



I have added a new langhook GET_DECL_INIT that by default returns the 
DECL_INITIAL of a variable declaration, but for C++ can also return the dynamic 
initializer if present. omp_discover_implicit_declare_target and 
omp_discover_declare_target_var_r have been changed to use the new langhook 
instead of using DECL_INITIAL.


The dynamic initializer information is stored in a new variable 
dynamic_initializers. The information is originally stored in static_aggregates, 
but this is nulled by calling prune_vars_needing_no_initialization in 
c_parse_final_cleanups. I copy the information into a separate variable before 
it is discarded - this avoids any potential problems that may be caused by 
trying to change the way that static_aggregates currently works.


With this, all the functions and variables in your example are marked correctly:

foo ()
...

__attribute__((omp declare target))
bar ()
...

__attribute__((omp declare target))
baz ()
...

__attribute__((omp declare target))
qux ()
...

.offload_var_table:
     .quad   g
     .quad   8
     .quad   d
     .quad   8
     .quad   b
     .quad   4
     .quad   c
     .quad   4
     .quad   f
     .quad   4
     .quad   e
     .quad   4

Your example is now a compile test in g++.dg/gomp/.


Anyway, that is one thing, the other is even if the implicit declare target
discovery handles those correctly, the question is what should we do
afterwards.  Because the C++ FE normally creates a single function that
performs the dynamic initialization of the TUs variables.  But that function
shouldn't be really declare target to, it initializes not only (explicit or
implicit) declare target to variables, but also host only variables.
So we'll probably need to create next to that host only TU constructor
also a device only constructor function that will only initialize the
declare target to variables.


Even without this patch, G++ currently accepts something like

int foo() { return 1; }
int x = foo();
#pragma omp declare target to(x)

but will not generate the device-side initializer for x, even though x is now 
present on the device. So this part of the implementation is broken with or 
without the patch.


Given that my patch doesn't make the current situation any worse, can I commit 
this portion of it to trunk for now, and leave device-side dynamic 
initialization for later?


Bootstrapped on x86_64 with no offloading, G++ testsuite ran with no 
regressions, and no regressions in the libgomp testsuite with Nvidia offloading.


Thanks,

Kwok


Re: Fortran: With OpenACC, ignore OpenMP's cond comp sentinels [PR98011]

2020-11-27 Thread Tobias Burnus

On 27.11.20 18:31, Jakub Jelinek via Fortran wrote:

Depends on what does the OpenACC standard say.
If it has similar wording to OpenMP that '!$ ' stands ...


It only has '!$acc' (free) and !$acc + c$acc + *$acc (fixed).
cf. 
https://www.openacc.org/sites/default/files/inline-images/Specification/OpenACC-3.1-final.pdf
(2.1 Directive Form)


.. if it is silent on that, then the patch is correct.

What about fixed-form parsing?


Missed that somehow. I have now added two fixed-form testcases
(goacc + goacc-gomp) and a free one (goacc-gomp).

Thanks,

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
Fortran: With OpenACC, ignore OpenMP's cond comp sentinels

gcc/fortran/ChangeLog:

	PR fortran/98011
	* scanner.c (skip_free_comments, skip_fixed_comments): If only
	-fopenacc but not -fopenmp is used, ignore OpenMP's conditional
	compilation sentinels. Fix indentation, use 'else if' for readability.

gcc/testsuite/ChangeLog:

	PR fortran/98011
	* gfortran.dg/goacc/sentinel-free-form.f95:
	* gfortran.dg/goacc-gomp/fixed-1.f: New test.
	* gfortran.dg/goacc-gomp/free-1.f: New test.
	* gfortran.dg/goacc/fixed-5.f: New test.

 gcc/fortran/scanner.c  | 32 +++--
 gcc/testsuite/gfortran.dg/goacc-gomp/fixed-1.f | 81 ++
 gcc/testsuite/gfortran.dg/goacc-gomp/free-1.f90| 34 +
 gcc/testsuite/gfortran.dg/goacc/fixed-5.f  | 30 
 .../gfortran.dg/goacc/sentinel-free-form.f95   |  7 +-
 5 files changed, 161 insertions(+), 23 deletions(-)

diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index fd11f5a244a..304ae2d8d6a 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -899,21 +899,14 @@ skip_free_comments (void)
 		if (next_char () == '$')
 		  {
 		c = next_char ();
-		  if (c == 'a' || c == 'A')
-			{
-			  if (skip_free_oacc_sentinel (start, old_loc))
-			return false;
-			  gfc_current_locus = old_loc;
-			  next_char();
-			  c = next_char();
-			}
-		  if (continue_flag || c == ' ' || c == '\t')
-			{
-			  gfc_current_locus = old_loc;
-			  next_char();
-			  openacc_flag = 0;
-			  return true;
-			}
+		if (c == 'a' || c == 'A')
+		  {
+			if (skip_free_oacc_sentinel (start, old_loc))
+			  return false;
+			gfc_current_locus = old_loc;
+			next_char();
+			c = next_char();
+		  }
 		  }
 		gfc_current_locus = old_loc;
 	  }
@@ -1076,8 +1069,7 @@ skip_fixed_comments (void)
 		}
 	  gfc_current_locus = start;
 	}
-
-	  if (flag_openacc && !(flag_openmp || flag_openmp_simd))
+	  else if (flag_openacc && !(flag_openmp || flag_openmp_simd))
 	{
 	  if (next_char () == '$')
 		{
@@ -1087,13 +1079,10 @@ skip_fixed_comments (void)
 		  if (skip_fixed_oacc_sentinel (&start))
 			return;
 		}
-		  else
-		goto check_for_digits;
 		}
 	  gfc_current_locus = start;
 	}
-
-	  if (flag_openacc || flag_openmp || flag_openmp_simd)
+	  else if (flag_openacc || flag_openmp || flag_openmp_simd)
 	{
 	  if (next_char () == '$')
 		{
@@ -1120,6 +1109,7 @@ skip_fixed_comments (void)
 	  gcc_unreachable ();
 check_for_digits:
 	  {
+	/* Required for OpenMP's conditional compilation sentinel. */
 	int digit_seen = 0;
 
 	for (col = 3; col < 6; col++, c = next_char ())
diff --git a/gcc/testsuite/gfortran.dg/goacc-gomp/fixed-1.f b/gcc/testsuite/gfortran.dg/goacc-gomp/fixed-1.f
new file mode 100644
index 000..b6bab4ce902
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc-gomp/fixed-1.f
@@ -0,0 +1,81 @@
+! { dg-additional-options "-fdump-tree-original -Wunused-variable" }
+  implicit none
+  integer :: a,b,c,d,e,f,g,h,i,j,k,ll
+
+c$bogus
+!$bogus
+*$bogus
+
+c$ bogus
+!$ bogus
+*$ bogus
+
+c$a23 bogus
+!$ a  bogus
+*$12a bogus
+
+! The following should be parsed as OpenMP conditional sentinel
+! If not, expect a unused-variable warning
+
+c$a = 1
+!$b = 2
+*$c = 3
+
+c$ 1  d = 4
+!$ 22 e = 5
+*$34  f = 6
+
+c$g = 
+c$   *7
+!$ 2  h =
+*$   & 8
+*$ 3  i
+!$   & = 9
+
+c$j
+*$   &= 
+c$   *10
+!$ 5  k
+*$   * =
+c$   & 1
+*$   & 1
+*$9 9 ll
+!$   & =
+!$   *  12
+
+c$ bogus
+!$ bogus
+*$ bogus
+
+c$bogus
+!$bogus
+*$bogus
+
+c$ acc bogus
+!$ acc bogus
+*$ acc bogus
+
+c$ omp bogus
+!$ omp bogus
+*$ omp bogus
+  end
+
+!{ dg-final { scan-tree-dump-times "a = 1;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "b = 2;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "c = 3;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "d = 4;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "e = 5;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "f = 6;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "g = 7;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "h = 8;" 1 "original" } }
+!{ dg-final { scan-tree-dump-times "i = 9;" 1 "original" } }
+!{ dg-f

preprocessor: Fix #line overflow check [PR97602]

2020-11-27 Thread Joseph Myers
The preprocessor check for overflow (of linenum_type = unsigned int)
when reading the line number in a #line directive is incomplete; it
checks "reg < reg_prev" which doesn't cover all cases where
multiplying by 10 overflowed.  Fix this by checking for overflow
before rather than after it occurs (using essentially the same logic
as used by e.g. glibc printf when reading width and precision values
from strings).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Applied to 
mainline.

libcpp/
2020-11-27  Joseph Myers  

PR preprocessor/97602
* directives.c (strtolinenum): Check for overflow before it
occurs.  Correct comment.

gcc/testsuite/
2020-11-27  Joseph Myers  

PR preprocessor/97602
* gcc.dg/cpp/line9.c, gcc.dg/cpp/line10.c: New tests.

diff --git a/gcc/testsuite/gcc.dg/cpp/line10.c 
b/gcc/testsuite/gcc.dg/cpp/line10.c
new file mode 100644
index 000..9f5f0799847
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/line10.c
@@ -0,0 +1,5 @@
+/* Test #line overflow checks: bug 97602.  */
+/* { dg-do preprocess } */
+/* { dg-options "-pedantic" } */
+
+#line 4294967296 /* { dg-warning "line number out of range" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/line9.c b/gcc/testsuite/gcc.dg/cpp/line9.c
new file mode 100644
index 000..8060aff204d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/line9.c
@@ -0,0 +1,5 @@
+/* Test #line overflow checks: bug 97602.  */
+/* { dg-do preprocess } */
+/* { dg-options "-pedantic" } */
+
+#line 50 /* { dg-warning "line number out of range" } */
diff --git a/libcpp/directives.c b/libcpp/directives.c
index fa66b5c5f71..75115600e3a 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -915,12 +915,11 @@ read_flag (cpp_reader *pfile, unsigned int last)
 /* Subroutine of do_line and do_linemarker.  Convert a number in STR,
of length LEN, to binary; store it in NUMP, and return false if the
number was well-formed, true if not. WRAPPED is set to true if the
-   number did not fit into 'unsigned long'.  */
+   number did not fit into 'linenum_type'.  */
 static bool
 strtolinenum (const uchar *str, size_t len, linenum_type *nump, bool *wrapped)
 {
   linenum_type reg = 0;
-  linenum_type reg_prev = 0;
 
   uchar c;
   *wrapped = false;
@@ -929,11 +928,12 @@ strtolinenum (const uchar *str, size_t len, linenum_type 
*nump, bool *wrapped)
   c = *str++;
   if (!ISDIGIT (c))
return true;
+  if (reg > ((linenum_type) -1) / 10)
+   *wrapped = true;
   reg *= 10;
-  reg += c - '0';
-  if (reg < reg_prev) 
+  if (reg > ((linenum_type) -1) - (c - '0'))
*wrapped = true;
-  reg_prev = reg;
+  reg += c - '0';
 }
   *nump = reg;
   return false;

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


  1   2   >