[Ada] With_clauses for child units that act as specs

2011-09-02 Thread Arnaud Charlet
A child unit given by a subprogram body without a declaration is given a
declaration when it is compiled, to simplify code generation and tools. If
the child unit appears in several with-clauses for the same unit (for example
through with_clauses in various subunits) all with_clauses must refer to the
same file, to prevent binding errors caused by the presence of the generated
subprogram declaration in the ali file.

The following must compile quietly:

   gnatmake -q m

with Q;
procedure M is
begin
   null;
end;
---
package Q is
  procedure S1;
  procedure S2;
end;
---
package body Q is
  procedure S1 is separate;
  procedure S2 is separate;
end;
---
procedure Q.C is
begin
  null;
end;
---
with Q.C;
separate (Q)
procedure S1 is
begin
   null;
end;
---
with Q.C;
separate (Q)
procedure S2 is
begin
   null;
end;

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

2011-09-02  Ed Schonberg  

* sem_ch10.adb (Analyze_With_Clause): If the library unit
is the generated subprogram declaration for a child unit body
that acts as spec, use the original body in the with_clause,
to prevent binding errors.

Index: sem_ch10.adb
===
--- sem_ch10.adb(revision 178381)
+++ sem_ch10.adb(working copy)
@@ -2536,6 +2536,21 @@
  --  Child unit in a with clause
 
  Change_Selected_Component_To_Expanded_Name (Name (N));
+
+ --  If this is a child unit without a spec, and it has benn analyzed
+ --  already, a declaration has been created for it. The with_clause
+ --  must reflect the actual body, and not the generated declaration,
+ --  to prevent spurious binding errors involving an out-of-date spec.
+ --  Note that this can only happen if the unit includes more than one
+ --  with_clause for the child unit (e.g. in separate subunits).
+
+ if Unit_Kind = N_Subprogram_Declaration
+   and then Analyzed (Library_Unit (N))
+   and then not Comes_From_Source (Library_Unit (N))
+ then
+Set_Library_Unit (N,
+   Cunit (Get_Source_Unit (Corresponding_Body (U;
+ end if;
   end if;
 
   --  Restore style checks and restrictions


[Ada] Do not call Callback function when switch is dealt with automatically

2011-09-02 Thread Arnaud Charlet
This patch modifies the behavior of Getopt in GNAT.Command_Line to not call
the Callback function in argument on switches that have been dealt with
automatically.

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

2011-09-02  Johannes Kanig  

* g-comlin.adb (Getopt): Return when switch is dealt with automatically,
instead of calling the callback function

Index: g-comlin.adb
===
--- g-comlin.adb(revision 178381)
+++ g-comlin.adb(working copy)
@@ -3290,11 +3290,14 @@
   with "Expected integer parameter for '"
 & Switch & "'";
   end;
+  return;
 
when Switch_String =>
   Free (Config.Switches (Index).String_Output.all);
   Config.Switches (Index).String_Output.all :=
 new String'(Parameter);
+  return;
+
 end case;
  end if;
 
Index: g-comlin.ads
===
--- g-comlin.ads(revision 178381)
+++ g-comlin.ads(working copy)
@@ -707,7 +707,8 @@
   Callback : Switch_Handler := null;
   Parser   : Opt_Parser := Command_Line_Parser);
--  Similar to the standard Getopt function.
-   --  For each switch found on the command line, this calls Callback.
+   --  For each switch found on the command line, this calls Callback, if the
+   --  switch is not handled automatically.
--
--  The list of valid switches are the ones from the configuration. The
--  switches that were declared through Define_Switch with an Output


[Ada] Improve xref speed for many tagged types

2011-09-02 Thread Arnaud Charlet
This patch improves compilation speed (in particular, speed of generating cross
reference information) when compiling packages with huge numbers of tagged
types and interfaces, with complicated inheritance patterns.  No test is
available -- the problem only occurred for enormous packages.

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

2011-09-02  Bob Duff  

* einfo.adb: (Has_Xref_Entry): Do not call
Implementation_Base_Type. Lib.Xref has been
rewritten to avoid the need for it, and it was costly.
* s-htable.ads,s-htable.adb: (Present,Set_If_Not_Present): New
functions in support of efficient xref.
* lib-xref-alfa.adb: Misc changes related to Key component of
type Xref_Entry.
* lib-xref.adb: (Add_Entry,etc): Speed improvement.
(New_Entry): Call Implementation_Base_Type, because Has_Xref_Entry
no longer does. This is the one place where it is needed.

Index: einfo.adb
===
--- einfo.adb   (revision 178381)
+++ einfo.adb   (working copy)
@@ -1599,7 +1599,7 @@
 
function Has_Xref_Entry (Id : E) return B is
begin
-  return Flag182 (Implementation_Base_Type (Id));
+  return Flag182 (Id);
end Has_Xref_Entry;
 
function Hiding_Loop_Variable (Id : E) return E is
Index: s-htable.adb
===
--- s-htable.adb(revision 178381)
+++ s-htable.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---Copyright (C) 1995-2010, AdaCore  --
+--Copyright (C) 1995-2011, AdaCore  --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -121,6 +121,15 @@
  return Iterator_Ptr;
   end Get_Non_Null;
 
+  -
+  -- Present --
+  -
+
+  function Present (K : Key) return Boolean is
+  begin
+ return Get (K) /= Null_Ptr;
+  end Present;
+
   
   -- Remove --
   
@@ -181,6 +190,32 @@
  Table (Index) := E;
   end Set;
 
+  
+  -- Set_If_Not_Present --
+  
+
+  function Set_If_Not_Present (E : Elmt_Ptr) return Boolean is
+ K : constant Key := Get_Key (E);
+ Index : constant Header_Num := Hash (K);
+ Elmt  : Elmt_Ptr := Table (Index);
+
+  begin
+ loop
+if Elmt = Null_Ptr then
+   Set_Next (E, Table (Index));
+   Table (Index) := E;
+
+   return True;
+
+elsif Equal (Get_Key (Elmt), K) then
+   return False;
+
+else
+   Elmt := Next (Elmt);
+end if;
+ end loop;
+  end Set_If_Not_Present;
+
end Static_HTable;
 
---
Index: s-htable.ads
===
--- s-htable.ads(revision 178381)
+++ s-htable.ads(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- S p e c  --
 --  --
--- Copyright (C) 1995-2010, AdaCore --
+-- Copyright (C) 1995-2011, AdaCore --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -183,6 +183,14 @@
   --  Returns the latest inserted element pointer with the given Key
   --  or null if none.
 
+  function Present (K : Key) return Boolean;
+  --  True if an element whose Get_Key is K is in the table
+
+  function Set_If_Not_Present (E : Elmt_Ptr) return Boolean;
+  --  If Present (Get_Key (E)), returns False. Otherwise, does Set (E), and
+  --  then returns True. Present (Get_Key (E)) is always True afterward,
+  --  and the result True indicates E is newly Set.
+
   procedure Remove (K : Key);
   --  Removes the latest inserted element pointer associated with the
   --  given key if any, does nothing if none.
Index: lib-xref-alfa.adb
===
--- lib-xref-alfa.adb   (revision 178381)
+++ lib-xref-alfa.adb   (working c

[Ada] Optional argument Concatenate for Getopt in GNAT.Command_Line

2011-09-02 Thread Arnaud Charlet
The high-level procedure Getopt did not expose a feature of its lowlevel
counterpart, namely the Concatenate option which modifies the behavior of the
command line parser. This patch adds this option to the high-level interface.

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

2011-09-02  Johannes Kanig  

* g-comlin.adb (Getopt): New optional argument Concatenate to have
similar interface as the other Getopt function.

Index: g-comlin.adb
===
--- g-comlin.adb(revision 178435)
+++ g-comlin.adb(working copy)
@@ -3236,9 +3236,10 @@

 
procedure Getopt
- (Config   : Command_Line_Configuration;
-  Callback : Switch_Handler := null;
-  Parser   : Opt_Parser := Command_Line_Parser)
+ (Config  : Command_Line_Configuration;
+  Callback: Switch_Handler := null;
+  Parser  : Opt_Parser := Command_Line_Parser;
+  Concatenate : Boolean := True)
is
   Getopt_Switches : String_Access;
   C   : Character := ASCII.NUL;
@@ -3373,7 +3374,7 @@
 
   loop
  C := Getopt (Switches=> Getopt_Switches.all,
-  Concatenate => True,
+  Concatenate => Concatenate,
   Parser  => Parser);
 
  if C = '*' then
Index: g-comlin.ads
===
--- g-comlin.ads(revision 178435)
+++ g-comlin.ads(working copy)
@@ -703,9 +703,10 @@
--  switch.
 
procedure Getopt
- (Config   : Command_Line_Configuration;
-  Callback : Switch_Handler := null;
-  Parser   : Opt_Parser := Command_Line_Parser);
+ (Config  : Command_Line_Configuration;
+  Callback: Switch_Handler := null;
+  Parser  : Opt_Parser := Command_Line_Parser;
+  Concatenate : Boolean := True);
--  Similar to the standard Getopt function.
--  For each switch found on the command line, this calls Callback, if the
--  switch is not handled automatically.
@@ -716,6 +717,9 @@
--  variable). This function will in fact never call [Callback] if all
--  switches were handled automatically and there is nothing left to do.
--
+   --  The option Concatenate is identical to the one of the standard Getopt
+   --  function.
+   --
--  This procedure automatically adds -h and --help to the valid switches,
--  to display the help message and raises Exit_From_Command_Line.
--  If an invalid switch is specified on the command line, this procedure


[Ada] Improper node sharing in the expansion of T'range.

2011-09-02 Thread Arnaud Charlet
when rewriting X'range (N) into X'First (N) ..  X'Last (N), the dimension
indicator N must not be shared, if present in the original range. Even though
it is a static constant, its source location may be modified when printing
expanded code under -gnatDL, and node sharing leads to a double modification,
which in large files might generate a source position  that does not correspond
to any source file.

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

2011-09-02  Ed Schonberg  

* sem_attr.adb: (Analyze_Attribute, case 'Range): when expanding
X'range (N) into X'First (N) ..  X'Last (N), do not share the
dimension indicator N, if present. Even though it is a static
constant, its source location may be modified when printing
expanded code under -gnatDL, and node sharing will lead to chaos
in Sprint on large files, by generating a sloc value that does
not correspond to any source file.

Index: sem_attr.adb
===
--- sem_attr.adb(revision 178414)
+++ sem_attr.adb(working copy)
@@ -8871,6 +8871,7 @@
 declare
LB   : Node_Id;
HB   : Node_Id;
+   Dims : List_Id;
 
 begin
if not Is_Entity_Name (P)
@@ -8879,19 +8880,31 @@
   Resolve (P);
end if;
 
+   Dims := Expressions (N);
+
HB :=
  Make_Attribute_Reference (Loc,
Prefix =>
  Duplicate_Subexpr (P, Name_Req => True),
Attribute_Name => Name_Last,
-   Expressions=> Expressions (N));
+   Expressions=> Dims);
 
LB :=
  Make_Attribute_Reference (Loc,
-   Prefix => P,
+   Prefix  => P,
Attribute_Name => Name_First,
-   Expressions=> Expressions (N));
+   Expressions => (Dims));
 
+   --  Do not share the dimension indicator, if present. Even
+   --  though it is a static constant, its source location
+   --  may be modified when printing expanded code and node
+   --  sharing will lead to chaos in Sprint.
+
+   if Present (Dims) then
+  Set_Expressions (LB,
+New_List (New_Copy_Tree (First (Dims;
+   end if;
+
--  If the original was marked as Must_Not_Freeze (see code
--  in Sem_Ch3.Make_Index), then make sure the rewriting
--  does not freeze either.


[Ada] Constraint_Error raised for slice indexed by logical negation with -gnato

2011-09-02 Thread Arnaud Charlet
When overflow checking is enabled, the front end generates range checks
on the indexing of a slice with a bound of the form Boolean'Pos (not X)
that get mistranslated by gigi when optimization is enabled. The checks
should not have been generated in the first place (one is a tautological
full range check and the other redundantly tests that the result of
Boolean'Pos is >= 1), and were only generated because of a missing guard
in Checks.Determine_Range that resulted in a bogus comparison of bounds
against No_Uint.

The following test must compile and execute quietly with -gnato and -O:

$ gnatmake -gnato -O boolean_slice_bound_bug

procedure Boolean_Slice_Bound_Bug is

   procedure Proc (B : Boolean) is
  S : constant String (1 .. 1) := (others => 'X');
   begin
  if S (1 .. Boolean'Pos (not B)) /= "X" then
 raise Program_Error;
  end if;
   end Proc;

begin
   Proc (False);
end Boolean_Slice_Bound_Bug;

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

2011-09-02  Gary Dismukes  

* checks.adb: (Determine_Range): Add test of OK1 to prevent the early
return done when overflow checks are enabled, since comparisons against
Lor and Hir should not be done when OK1 is False.

Index: checks.adb
===
--- checks.adb  (revision 178381)
+++ checks.adb  (working copy)
@@ -3479,10 +3479,11 @@
   --  to restrict the possible range of results.
 
   --  If one of the computed bounds is outside the range of the base type,
-  --  the expression may raise an exception and we better indicate that
+  --  the expression may raise an exception and we had better indicate that
   --  the evaluation has failed, at least if checks are enabled.
 
-  if Enable_Overflow_Checks
+  if OK1
+and then Enable_Overflow_Checks
 and then not Is_Entity_Name (N)
 and then (Lor < Lo or else Hir > Hi)
   then


[Ada] Null access exception for nested build-in-place calls in allocator

2011-09-02 Thread Arnaud Charlet
In the case a class-wide limited (build-in-place) function that returns
a call to another build-in-place function with a controlled result, the
compiler passes null as the value for the implicit finalization master
parameter rather than passing along its own finalization master formal.
This fails a null access check in the case where the class-wide function
is called to initialize an alloctor. The implicit formal must be passed
along if the outer function calls another function (necessarily also
build-in-place) in a return statement.

The following test must compile and execute quietly with -gnat05:

with Ada.Finalization; use Ada.Finalization;

package Ctrlled_BIP_Pkg is

   type Update_Lock is limited new Limited_Controlled with null record;

   function Lock_Updates return Update_Lock;

   type Update_Lock_Access is access all Update_Lock'Class;

end Ctrlled_BIP_Pkg;

package body Ctrlled_BIP_Pkg is

   function Lock_Updates return Update_Lock is
   begin
  return (Limited_Controlled with others => <>);
   end Lock_Updates;

end Ctrlled_BIP_Pkg;


with Ctrlled_BIP_Pkg; use Ctrlled_BIP_Pkg;

procedure Ctrlled_BIP_Bug is

   function Wrapper return Ctrlled_BIP_Pkg.Update_Lock'Class is
   begin
  return Ctrlled_BIP_Pkg.Lock_Updates;
   end Wrapper;

   Lock : Update_Lock_Access;

begin
   Lock := new Update_Lock'Class'(Wrapper);
end Ctrlled_BIP_Bug;

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

2011-09-02  Gary Dismukes  

* exp_ch6.adb (Add_Finalization_Master_Actual_To_Build_In_Place_Call):
Add new formal Master_Exp. When present, add that expression to the
call as an extra actual.
(Make_Build_In_Place_Call_In_Object_Declaration): Add variable
Fmaster_Actual and in the case of a BIP call initializing a return
object of an enclosing BIP function set it to a
new reference to the implicit finalization master
formal of the enclosing function. Fmaster_Actual is
then passed to the new formal Master_Exp on the call to
Add_Finalization_Master_Actual_To_Build_ In_Place_Call. Move
initializations of Enclosing_Func to its declaration.

Index: exp_ch6.adb
===
--- exp_ch6.adb (revision 178433)
+++ exp_ch6.adb (working copy)
@@ -111,13 +111,15 @@
--  Extra_Formal in Subprogram_Call.
 
procedure Add_Finalization_Master_Actual_To_Build_In_Place_Call
- (Func_Call : Node_Id;
-  Func_Id   : Entity_Id;
-  Ptr_Typ   : Entity_Id := Empty);
+ (Func_Call  : Node_Id;
+  Func_Id: Entity_Id;
+  Ptr_Typ: Entity_Id := Empty;
+  Master_Exp : Node_Id   := Empty);
--  Ada 2005 (AI-318-02): If the result type of a build-in-place call needs
--  finalization actions, add an actual parameter which is a pointer to the
-   --  finalization master of the caller. If Ptr_Typ is left Empty, this will
-   --  result in an automatic "null" value for the actual.
+   --  finalization master of the caller. If Master_Exp is not Empty, then that
+   --  will be passed as the actual. Otherwise, if Ptr_Typ is left Empty, this
+   --  will result in an automatic "null" value for the actual.
 
procedure Add_Task_Actuals_To_Build_In_Place_Call
  (Function_Call : Node_Id;
@@ -311,9 +313,10 @@
---
 
procedure Add_Finalization_Master_Actual_To_Build_In_Place_Call
- (Func_Call : Node_Id;
-  Func_Id   : Entity_Id;
-  Ptr_Typ   : Entity_Id := Empty)
+ (Func_Call  : Node_Id;
+  Func_Id: Entity_Id;
+  Ptr_Typ: Entity_Id := Empty;
+  Master_Exp : Node_Id   := Empty)
is
begin
   if not Needs_BIP_Finalization_Master (Func_Id) then
@@ -329,9 +332,16 @@
  Desig_Typ : Entity_Id;
 
   begin
+ --  If there is a finalization master actual, such as the implicit
+ --  finalization master of an enclosing build-in-place function,
+ --  then this must be added as an extra actual of the call.
+
+ if Present (Master_Exp) then
+Actual := Master_Exp;
+
  --  Case where the context does not require an actual master
 
- if No (Ptr_Typ) then
+ elsif No (Ptr_Typ) then
 Actual := Make_Null (Loc);
 
  else
@@ -7561,7 +7571,9 @@
   Ptr_Typ_Decl: Node_Id;
   Def_Id  : Entity_Id;
   New_Expr: Node_Id;
-  Enclosing_Func  : Entity_Id;
+  Enclosing_Func  : constant Entity_Id :=
+  Enclosing_Subprogram (Obj_Def_Id);
+  Fmaster_Actual  : Node_Id := Empty;
   Pass_Caller_Acc : Boolean := False;
 
begin
@@ -7613,8 +7625,6 @@
   if Is_Return_Object (Defining_Identifier (Object_Decl)) then
  Pass_Caller_Acc := True;
 
- Enclosing_Func := Enclosing_Subprogram (Obj_Def_Id);
-
  --  When the enclosing function has a BIP_Alloc_Form formal then we
  --  pass it alon

[Ada] Implement No_Implicit_Aliasing restriction

2011-09-02 Thread Arnaud Charlet
This restriction, which is not required to be partition-wide consistent,
requires an explicit aliased keyword for an object to which 'Access,
'Unchecked_Access, or 'Address is applied, and forbids entirely the
use of the 'Unrestricted_Access attribute for objects.

The following test program tests this restriction

 1. pragma Restrictions (No_Implicit_Aliasing);
 2. procedure NoImplicitAliasing is
 3.OK : aliased Integer;
 4.NOK : Integer;
 5.type R is access all Integer;
 6.RV  : R;
 7.OK1 : Integer;
 8.for OK1'Address use OK'Address;
 9.NOK1 : Integer;
10.for NOK1'Address use NOK'Address;
|
>>> violation of restriction "No_Implicit_Aliasing" at line 1

11. begin
12.RV := OK'access;
13.RV := NOK'access;
 |
>>> violation of restriction "No_Implicit_Aliasing" at line 1
>>> prefix of "Access" attribute must be explicitly aliased

14.RV := OK'unchecked_access;
15.RV := NOK'unchecked_access;
 |
>>> violation of restriction "No_Implicit_Aliasing" at line 1
>>> prefix of "Unchecked_Access" attribute must be explicitly aliased

16.RV := OK'unrestricted_access;
   |
>>> violation of restriction "No_Implicit_Aliasing" at line 1

17.RV := NOK'unrestricted_access;
|
>>> violation of restriction "No_Implicit_Aliasing" at line 1

18. end;

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

2011-09-02  Robert Dewar  

* s-rident.ads: Add new restriction No_Implicit_Aliasing
* sem_attr.adb: (Analyze_Access_Attribute): Deal with
No_Implicit_Aliasing
(Analyze_Attribute, case Address): ditto
(Analyze_Attribute, case Unrestricted_Access): ditto
* sem_util.ads, sem_util.adb: (Is_Aliased_View): Handle
No_Implicit_Aliasing restriction.
* gnat_rm.texi: Add documentation for No_Implicit_Aliasing

Index: gnat_rm.texi
===
--- gnat_rm.texi(revision 178381)
+++ gnat_rm.texi(working copy)
@@ -8988,6 +8988,17 @@
 code is simplified by omitting the otherwise-required global registration
 of exceptions when they are declared.
 
+@item No_Implicit_Aliasing
+@findex No_Implicit_Aliasing
+
+This restriction, which is not required to be partition-wide consistent,
+requires an explicit aliased keyword for an object to which 'Access,
+'Unchecked_Access, or 'Address is applied, and forbids entirely the use of
+the 'Unrestricted_Access attribute for objects. Note: the reason that
+Unrestricted_Access is forbidden is that it would require the prefix
+to be aliased, and in such cases, it can always be replaced by
+the standard attribute Unchecked_Access which is preferable.
+
 @item No_Implicit_Conditionals
 @findex No_Implicit_Conditionals
 This restriction ensures that the generated code does not contain any
Index: sem_attr.adb
===
--- sem_attr.adb(revision 178438)
+++ sem_attr.adb(working copy)
@@ -837,7 +837,13 @@
and then not In_Instance
and then not In_Inlined_Body
  then
-Error_Attr_P ("prefix of % attribute must be aliased");
+if Restriction_Check_Required (No_Implicit_Aliasing) then
+   Error_Attr_P
+ ("prefix of % attribute must be explicitly aliased");
+else
+   Error_Attr_P
+ ("prefix of % attribute must be aliased");
+end if;
  end if;
   end Analyze_Access_Attribute;
 
@@ -2221,12 +2227,20 @@
then
   Set_Address_Taken (Ent);
 
-   --  If we have an address of an object, and the attribute
-   --  comes from source, then set the object as potentially
-   --  source modified. We do this because the resulting address
-   --  can potentially be used to modify the variable and we
-   --  might not detect this, leading to some junk warnings.
+  --  Deal with No_Implicit_Aliasing restriction
 
+  if Restriction_Check_Required (No_Implicit_Aliasing) then
+ if not Is_Aliased_View (P) then
+Check_Restriction (No_Implicit_Aliasing, P);
+ end if;
+  end if;
+
+  --  If we have an address of an object, and the attribute
+  --  comes from source, then set the object as potentially
+  --  source modified. We do this because the resulting address
+  --  can potentially be used to modify the variable and we
+  --  might not detect this, leading to some junk warnings.
+
   Set_Never_Set_In_Source (Ent, False);
 
  

[Ada] Possibly bit aligned objects in assignments

2011-09-02 Thread Arnaud Charlet
If either the target or the expression in an array or record ssignment may be
bit-aligned, the assignment must be expanded into component assignments. The
object (or subcomponent) may be given by an unchecked conversion, in which case
we must examine its expression to determine potential mis-alignment.

The following must execute quietly:
   
gnatmake -gnata -q test_conversion
test_conversion

---
with Packing; use Packing;
with Interfaces; use Interfaces;

procedure Test_Conversion is
   Orig : Table:= (1, (others => (others => (others => 4;
   Dest : Packed_Table;
   
begin
   Convert (Orig, Dest);
   
   pragma Assert (Dest.Data (1) (1, 1) = 4);
end Test_Conversion;
---
with Interfaces; use Interfaces;

package Packing is 
   subtype Index is Integer range 0 .. 32;
   
   type Element is array (1 .. 2, 1 .. 2) of Integer_32;
   
   type Container is array (1 .. 3) of Element;
   pragma Pack (Container);
   
   type Table is
  record
 Padding : Index;
 Data: Container;
  end record;
   
   type Packed_Table is new Table;
   
   for Packed_Table use
  record
 Padding at 0 range 0 ..   5;
 Dataat 0 range 6 .. 12 * 32 + 5;
  end record;
   
   procedure Convert (Value_In : Table; Value_Out : out Packed_Table);
end Packing;
---
package body Packing is
   procedure Convert (Value_In : Table; Value_Out : out Packed_Table) is
   begin
  Value_Out := Packed_Table (Value_In);
   end Convert;
end Packing;

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

2011-09-02  Ed Schonberg  

* exp_util.adb: (Possible_Bit_Aligned_Object): If the object
is an unchecked conversion, apply test to its expression.

Index: exp_util.adb
===
--- exp_util.adb(revision 178438)
+++ exp_util.adb(working copy)
@@ -5687,6 +5687,12 @@
  when N_Slice =>
 return Possible_Bit_Aligned_Component (Prefix (N));
 
+ --  For an unchecked conversion, check whether the expression may
+ --  be bit-aligned.
+
+ when N_Unchecked_Type_Conversion =>
+return Possible_Bit_Aligned_Component (Expression (N));
+
  --  If we have none of the above, it means that we have fallen off the
  --  top testing prefixes recursively, and we now have a stand alone
  --  object, where we don't have a problem.


[Ada] Avoid reporting redundant message on inherited subprogram

2011-09-02 Thread Arnaud Charlet
This patch avoids reporting a redundant error on primitives inherited
from primitives.

  package Test_Pkg is
  type I1 is Interface;
  procedure P (A : I1) is abstract;

  type I2 is interface;
  procedure Q (B : I2) is abstract;

  type DT2 is new I1 and I2 with null record;
  procedure P (X : DT2);
   end;

Command: gcc -c -gnat05 test_pkg.ads
New output:
test_pkg.ads:8:12: type must be declared abstract or "Q" overridden
test_pkg.ads:8:12: "Q" has been inherited from subprogram at line 6

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

2011-09-02  Javier Miranda  

* sem_ch3.adb (Check_Abstract_Overriding): When
traversing the chain of aliased subprograms avoid reporting a
redundant error on the current entity.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 178438)
+++ sem_ch3.adb (working copy)
@@ -9105,9 +9105,16 @@
 begin
E := Subp;
while Present (Alias (E)) loop
-  Error_Msg_Sloc := Sloc (E);
-  Error_Msg_NE
-("\& has been inherited #", T, Subp);
+
+  --  Avoid reporting redundant errors on entities
+  --  inherited from interfaces
+
+  if Sloc (E) /= Sloc (T) then
+ Error_Msg_Sloc := Sloc (E);
+ Error_Msg_NE
+   ("\& has been inherited #", T, Subp);
+  end if;
+
   E := Alias (E);
end loop;
 


Re: Fix PR50260

2011-09-02 Thread Richard Guenther
On Thu, Sep 1, 2011 at 2:41 PM, Michael Matz  wrote:
> Hi,
>
> the last change in ipa-split generated a new use of a previously unused
> PARM_DECL.  When one does this one has to call add_referenced_var.  Not
> doing so can cause segfault when accessing the (not initialized) var
> annotation.  So, fixed with the patch.
>
> I took the opportunity to remove all explicit calls to get_var_ann because
> add_referenced_var is doing so as first thing.  Reviewing the code showed
> one potentially problematic case in tree-ssa-pre.c where a new variable
> was created without calling add_referenced_var.  It's only for
> place-holder SSA names but those can conceivably leak into the program
> stream by being reused during expression generation.
>
> Currently regstrapping on x86_64-linux (without Ada).  Okay for trunk?

Ok.  Time to make get_var_ann private?

Richard.

>
> Ciao,
> Michael.
> --
>        PR middle-end/50260
>        * ipa-split.c (split_function): Call add_referenced_var.
>
>        * tree-ssa-phiopt.c (cond_store_replacement): Don't call get_var_ann.
>        (cond_if_else_store_replacement_1): Ditto.
>        * tree-ssa-pre.c (get_representative_for): Ditto.
>        (create_expression_by_pieces): Ditto.
>        (insert_into_preds_of_block): Ditto.
>        * tree-sra.c (create_access_replacement): Ditto.
>        (get_replaced_param_substitute): Ditto.
>
> testsuite/
>        * gfortran.fortran-torture/compile/pr50260.f90: New test.
>
> Index: ipa-split.c
> ===
> --- ipa-split.c (revision 178408)
> +++ ipa-split.c (working copy)
> @@ -988,6 +988,9 @@ split_function (struct split_point *spli
>        arg = gimple_default_def (cfun, parm);
>        if (!arg)
>          {
> +           /* This parm wasn't used up to now, but is going to be used,
> +              hence register it.  */
> +           add_referenced_var (parm);
>            arg = make_ssa_name (parm, gimple_build_nop ());
>            set_default_def (parm, arg);
>          }
> Index: tree-ssa-phiopt.c
> ===
> --- tree-ssa-phiopt.c   (revision 178408)
> +++ tree-ssa-phiopt.c   (working copy)
> @@ -1269,10 +1269,7 @@ cond_store_replacement (basic_block midd
>   /* 2) Create a temporary where we can store the old content
>         of the memory touched by the store, if we need to.  */
>   if (!condstoretemp || TREE_TYPE (lhs) != TREE_TYPE (condstoretemp))
> -    {
> -      condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
> -      get_var_ann (condstoretemp);
> -    }
> +    condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
>   add_referenced_var (condstoretemp);
>
>   /* 3) Insert a load from the memory of the store to the temporary
> @@ -1355,10 +1352,7 @@ cond_if_else_store_replacement_1 (basic_
>   /* 2) Create a temporary where we can store the old content
>        of the memory touched by the store, if we need to.  */
>   if (!condstoretemp || TREE_TYPE (lhs) != TREE_TYPE (condstoretemp))
> -    {
> -      condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
> -      get_var_ann (condstoretemp);
> -    }
> +    condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
>   add_referenced_var (condstoretemp);
>
>   /* 3) Create a PHI node at the join block, with one argument
> Index: tree-ssa-pre.c
> ===
> --- tree-ssa-pre.c      (revision 178408)
> +++ tree-ssa-pre.c      (working copy)
> @@ -1399,7 +1399,7 @@ get_representative_for (const pre_expr e
>   if (!pretemp || exprtype != TREE_TYPE (pretemp))
>     {
>       pretemp = create_tmp_reg (exprtype, "pretmp");
> -      get_var_ann (pretemp);
> +      add_referenced_var (pretemp);
>     }
>
>   name = make_ssa_name (pretemp, gimple_build_nop ());
> @@ -3178,10 +3178,7 @@ create_expression_by_pieces (basic_block
>   /* Build and insert the assignment of the end result to the temporary
>      that we will return.  */
>   if (!pretemp || exprtype != TREE_TYPE (pretemp))
> -    {
> -      pretemp = create_tmp_reg (exprtype, "pretmp");
> -      get_var_ann (pretemp);
> -    }
> +    pretemp = create_tmp_reg (exprtype, "pretmp");
>
>   temp = pretemp;
>   add_referenced_var (temp);
> @@ -3441,10 +3438,7 @@ insert_into_preds_of_block (basic_block
>
>   /* Now build a phi for the new variable.  */
>   if (!prephitemp || TREE_TYPE (prephitemp) != type)
> -    {
> -      prephitemp = create_tmp_var (type, "prephitmp");
> -      get_var_ann (prephitemp);
> -    }
> +    prephitemp = create_tmp_var (type, "prephitmp");
>
>   temp = prephitemp;
>   add_referenced_var (temp);
> Index: tree-sra.c
> ===
> --- tree-sra.c  (revision 178408)
> +++ tree-sra.c  (working copy)
> @@ -1825,7 +1825,6 @@ create_access_replacement (struct access
>   tree repl;
>
>   repl = create_tmp_var (access->type, "SR");
> -  get_var_ann (re

Re: [PATCH] Remove bogus TYPE_IS_SIZETYPE special-casing in extract_muldiv_1

2011-09-02 Thread Eric Botcazou
> Well, the comment for that folding is totally odd - of _course_
> unsigned sizetype things can overflow (we hid that issue merely
> by pretending all unsigned sizetype constants (yes, only constants)
> are signed.  Huh.)

It's again the special semantics of sizetypes whereby we pretend that they 
don't overflow.  I know your opinion about this, but this is documented:

/* In an INTEGER_TYPE, it means the type represents a size.  We use
   this both for validity checking and to permit optimizations that
   are unsafe for other types.  Note that the C `size_t' type should
   *not* have this flag set.  The `size_t' type is simply a typedef
   for an ordinary integer type that happens to be the type of an
   expression returned by `sizeof'; `size_t' has no special
   properties.  Expressions whose type have TYPE_IS_SIZETYPE set are
   always actual sizes.  */
#define TYPE_IS_SIZETYPE(NODE) \
  (INTEGER_TYPE_CHECK (NODE)->type_common.no_force_blk_flag)

and we rely on these optimizations to simplify size computations in Ada.

> 2011-08-31  Richard Guenther  
>
>   * fold-const.c (extract_muldiv_1): Remove bogus TYPE_IS_SIZETYPE
>   special-casing.

IMO you shouldn't commit this kind of patchlets without the final big patch.

-- 
Eric Botcazou


Re: [C++0x] contiguous bitfields race implementation

2011-09-02 Thread Richard Guenther
On Thu, Sep 1, 2011 at 4:16 PM, Aldy Hernandez  wrote:
>
>> My point is, the middle-end infrastructure makes it possible for this
>> case to appear, and it seems to be easy to handle conservatively.
>> There isn't a need to wait for users to run into an ICE or an assert we
>> put
>> there IMHO.  If I'd be fluent in Ada I'd write you a testcase, but I
>> ain't.
>
> Ughh, this is getting messier.
>
> Ok, I propose keeping track of the field prior (lastfld), calling
> get_inner_reference() and adding DECL_SIZE (or tbitsize if you prefer) to
> calculate maxbits without the padding.
>
> Notice the comment at the top.  We can get rid of yet another call to
> get_inner_reference later.
>
> Is this what you had in mind?

That could work also for the tail-padding re-use case, yes.  Note that
DECL_SIZE of the field is just the last fieds bit-precision, so ..

> BTW, we don't need to round up to the next byte here, do we?

.. rounding up to the next byte cannot hurt (dependent on what the
caller will do with that value).

Note that with all this mess I'll re-iterate some of my initial thoughts.
1) why not do this C++ (or C) specific stuff in the frontends, maybe
at gimplifying/genericization time?  That way you wouldn't need to
worry about middle-end features but you could rely solely on what
C/C++ permit.  It is, after all, C++ _frontend_ semantics that we
enforce here, in the middle-end, which looks out-of-place.
2) all this information we try to re-construct here is sort-of readily
available when we layout the record (thus, from layout_type and
friends).  We should really, really try to preserve it there, rather
than jumping through hoops here (ideally we'd have an
(unused?) FIELD_DECL that covers the whole "bitfield group"
followed by the individual FIELD_DECLS for the bits (yep, they'd
overlap that group FIELD_DECL), and they would refer back to
that group FIELD_DECL)

Is the C++ memory model stuff going to be "ready" for 4.7?

Thanks,
Richard.

> Thanks.
> Aldy
>
>  /* If we found the end of the bit field sequence, include the
>     padding up to the next field...  */
>  if (fld)
>    {
>      tree end_offset, t;
>      HOST_WIDE_INT end_bitpos;
>
>      /* FIXME: Only call get_inner_reference once (at the beginning
>         of the bit region), and use
>         DECL_FIELD_OFFSET+DECL_FIELD_BIT_OFFSET throughout to
>         calculate any subsequent bit offset.  */
>
>      /* Even if the bitfield we access (and thus the whole region) is
>         at a constant offset, the field _following_ the bitregion can
>         be at variable offset.  In this case, do not include any
>         padding.  This is mostly for Ada.  */
>      if (TREE_CODE (DECL_FIELD_OFFSET (fld)) != INTEGER_CST)
>        {
>          get_inner_reference (build3 (COMPONENT_REF,
>                                       TREE_TYPE (exp),
>                                       TREE_OPERAND (exp, 0),
>                                       lastfld, NULL_TREE),
>                               &tbitsize, &end_bitpos, &end_offset,
>                               &tmode, &tunsignedp, &tvolatilep, true);
>
>          /* Calculate the size of the bit region up the last
>             bitfield, excluding any subsequent padding.
>
>             t = (end_byte_off - start_byte_offset) * 8 + end_bit_off */
>          end_offset = end_offset ? end_offset : size_zero_node;
>          t = fold_build2 (PLUS_EXPR, size_type_node,
>                           fold_build2 (MULT_EXPR, size_type_node,
>                                        fold_build2 (MINUS_EXPR,
> size_type_node,
>                                                     end_offset,
>                                                     *byte_offset),
>                                        build_int_cst (size_type_node,
>                                                       BITS_PER_UNIT)),
>                           build_int_cst (size_type_node,
>                                          end_bitpos));
>          /* Add the bitsize of the last field.  */
>          t = fold_build2 (PLUS_EXPR, size_type_node,
>                           t, DECL_SIZE (lastfld));
>
>          *maxbits = tree_low_cst (t, 1);
>          return;
>        }
> ...
> ...
> ...
>


Re: [C++0x] contiguous bitfields race implementation

2011-09-02 Thread Richard Guenther
On Thu, Sep 1, 2011 at 5:19 PM, Jason Merrill  wrote:
> On 09/01/2011 11:10 AM, Aldy Hernandez wrote:
>>>
>>> Basically you can only touch the size of the CLASSTYPE_AS_BASE variant.
>>> For many classes this will be the same as the size of the class itself.
>>
>> All this code is in the middle end, so we're language agnostic.
>>
>> What do we need here, a hook to query the front-end, or is it too late?
>> Or will we have to play it conservative and never touch the padding
>> (regardless of language)?
>
> I think it would make sense to expose this information to the back end
> somehow.  A hook would do the trick: call it type_data_size or type_min_size
> or some such, which in the C++ front end would return TYPE_SIZE
> (CLASSTYPE_AS_BASE (t)) for classes or just TYPE_SIZE for other types.

That's too late to work with LTO, you'd need to store that information
permanently
somewhere.

Maybe move this whole C++ specific bitfield handling where it belongs,
namely to the C++ frontend?

I suggest to always not re-use tail padding for now (I believe if your
parent object is a COMPONENT_REF, thus, x.parent.bitfield,
you can use the TYPE_SIZE vs. field-decl DECL_SIZE discrepance
to decide about whether the tail-padding was reused, but please
double-check that ;)))

Richard.

> Jason
>
>


Re: [PATCH] Make devirtualization use BINFO_VTABLE instead of BINFO_VIRTUALS

2011-09-02 Thread Richard Guenther
On Thu, Sep 1, 2011 at 8:52 PM, Jan Hubicka  wrote:
>> - Nevertheless, this method of devirtualization cannot automatically
>>   de-thunkize this-adjusting thunks and newly direct calls to them
>>   cannot be inlined because the inliner does not have this capability
>>   now.  This is in fact a regression from 4.6, and testcases
>>   ivinline-7.C and ivinline-9.C had to be XFAILed exactly for this
>>   reason.  The size of the memory savings and the fact that we do not
>>   devirtualize that much now make this an acceptable tradeoff, though.
>
> OK, the "dethunkization" was ugly anyway.  I guess we will need to add support
> for handling thunks in inliner but that can go incrementally.
>
>> 2011-08-31  Martin Jambor  
>>
>>       * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta.
>>       * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use
>>       BINFO_VTABLE.  Parameter delta removed, all callers updated.
>>       * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead
>>       BINFO_VTABLE.
>>       * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated
>>       all calls.
>>       * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed
>>       handling of thunk_delta.
>>       * ipa-cp.c (get_indirect_edge_target): Removed parameter delta.
>>       (devirtualization_time_bonus): Do not handle thunk deltas.
>>       (ipcp_discover_new_direct_edges): Likewise.
>>       * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise.
>>       (try_make_edge_direct_simple_call): Likewise.
>>       (try_make_edge_direct_virtual_call): Likewise.
>>       * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise.  Mark
>>       parameter set as unused.
>>       (output_edge_opt_summary): Likewise.  Mark both parameters as unused.
>>       * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise.  Mark
>>       parameter set as unused.
>>       (output_edge_opt_summary): Likewise.  Mark both parameters as unused.
>>       (input_edge_opt_summary): Likewise.
>>       * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream
>>       BINFO_VIRTUALS at all.
>>       * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise.
>>
>>       * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method.
>>       * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call
>>       discovery, xfailed test for inlining.
>>       * testsuite/g++.dg/ipa/ivinline-9.C: Likewise.
>
> The cgraph bits of the patch are OK, but I will leave the gimple-fold bits 
> for Richi's approval.

Ok.

Thanks,
Richard.

> Can't we drop computation of BINFO_VIRTUALS from C++ FE completely now?
>
> Honza
>


Re: [PATCH] Remove bogus TYPE_IS_SIZETYPE special-casing in extract_muldiv_1

2011-09-02 Thread Richard Guenther
On Fri, 2 Sep 2011, Eric Botcazou wrote:

> > Well, the comment for that folding is totally odd - of _course_
> > unsigned sizetype things can overflow (we hid that issue merely
> > by pretending all unsigned sizetype constants (yes, only constants)
> > are signed.  Huh.)
> 
> It's again the special semantics of sizetypes whereby we pretend that they 
> don't overflow.  I know your opinion about this, but this is documented:

But they _do_ overflow as my debugging showed, caused by that exact
same extract_muldiv_1 function here:

case PLUS_EXPR:  case MINUS_EXPR:
  /* See if we can eliminate the operation on both sides.  If we can, 
we
 can return a new PLUS or MINUS.  If we can't, the only remaining
 cases where we can do anything are if the second operand is a
 constant.  */
...
  /* If this was a subtraction, negate OP1 and set it to be an 
addition.
 This simplifies the logic below.  */
  if (tcode == MINUS_EXPR)
{
  tcode = PLUS_EXPR, op1 = negate_expr (op1);

the unconditional negation of op1 for tcode == MINUS_EXPR overflows
all sizetype values (well, all unsigned values).

So you might argue I should have fixed the "bug" here instead
of removing a TYPE_IS_SIZETYPE check (which I very much like to do,
as you know ;)).

> /* In an INTEGER_TYPE, it means the type represents a size.  We use
>this both for validity checking and to permit optimizations that
>are unsafe for other types.  Note that the C `size_t' type should
>*not* have this flag set.  The `size_t' type is simply a typedef
>for an ordinary integer type that happens to be the type of an
>expression returned by `sizeof'; `size_t' has no special
>properties.  Expressions whose type have TYPE_IS_SIZETYPE set are
>always actual sizes.  */
> #define TYPE_IS_SIZETYPE(NODE) \
>   (INTEGER_TYPE_CHECK (NODE)->type_common.no_force_blk_flag)

Well, this only says "and to permit optimizations that are unsafe for 
other types." but it doesn't say what constraints apply to sizetypes.
We can't at the same time possibly introduce overflow and rely
on no overflow at the same time.

> and we rely on these optimizations to simplify size computations in Ada.

Please please add some _testcases_ then that would fail when I test
this kind of patches.

> > 2011-08-31  Richard Guenther  
> >
> > * fold-const.c (extract_muldiv_1): Remove bogus TYPE_IS_SIZETYPE
> > special-casing.
> 
> IMO you shouldn't commit this kind of patchlets without the final big patch.

The patch fixed a real bug (it's just that it is hard (for me) to
produce testcases that involve sizetype computations - it always
requires Ada to expose those bugs).  So, I beg to differ.

Richard.


[Ada] Remove IN parameters from Alfa section in ALI

2011-09-02 Thread Arnaud Charlet
References to IN parameters are not considered in Alfa section, as these will
be translated as constants in the intermediate language for formal
verification.

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

2011-09-02  Yannick Moy  

* lib-xref-alfa.adb (Is_Alfa_Reference): Ignore IN parameters in Alfa
references.

Index: lib-xref-alfa.adb
===
--- lib-xref-alfa.adb   (revision 178438)
+++ lib-xref-alfa.adb   (working copy)
@@ -608,11 +608,20 @@
 --  On non-callable entities, the only references of interest are
 --  reads and writes.
 
-if Ekind (E) in Overloadable_Kind then
-   return Typ = 's';
-else
-   return Typ = 'r' or else Typ = 'm';
-end if;
+case Ekind (E) is
+   when Overloadable_Kind =>
+  return Typ = 's';
+
+   --  References to IN parameters are not considered in Alfa
+   --  section, as these will be translated as constants in the
+   --  intermediate language for formal verification.
+
+   when E_In_Parameter =>
+  return False;
+
+   when others =>
+  return Typ = 'r' or else Typ = 'm';
+end case;
  end Is_Alfa_Reference;
 
  ---


[Ada] New warning for suspicious contracts

2011-09-02 Thread Arnaud Charlet
A contract, either in GNAT syntax (pragma precondition and postcondition) or
Ada 2012 aspect syntax, is suspicious when: for a function, it does not mention
the result; for a function or procedure, it only refers to the pre-state. GNAT
now detects these cases on the following code:

$ gcc -c -gnatc -gnat12 p.ads
p.ads:3:06: warning: postcondition only refers to pre-state
p.ads:3:06: warning: function postcondition does not mention result
p.ads:5:06: warning: postcondition only refers to pre-state
---
 1  package P is
 2 function A_Is_Positive (X : Integer) return Boolean with
 3   Post => X >= 0;
 4 procedure A_Incr (X : in Integer; Y : out Integer) with
 5   Post => X = X + 1;
 6  end P;

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

2011-09-02  Yannick Moy  

* opt.ads (Warn_On_Suspicious_Contract): New warning flag.
* sem_ch3.adb (Analyze_Declarations): Call checker for suspicious
contracts.
* sem_ch6.adb, sem_ch6.ads (Check_Subprogram_Contract): New
procedure looking for suspicious postconditions.
* usage.adb (Usage): New options -gnatw.t and -gnatw.T.
* warnsw.adb (Set_Dot_Warning_Switch): Take into account new
options -gnatw.t and -gnatw.T.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 178440)
+++ sem_ch3.adb (working copy)
@@ -2192,6 +2192,8 @@
   Prag := Next_Pragma (Prag);
end loop;
 
+   Check_Subprogram_Contract (Sent);
+
Prag := Spec_TC_List (Contract (Sent));
while Present (Prag) loop
   Analyze_TC_In_Decl_Part (Prag, Sent);
Index: usage.adb
===
--- usage.adb   (revision 178381)
+++ usage.adb   (working copy)
@@ -484,6 +484,8 @@
Write_Line (".S*  turn off warnings for overridden size clause");
Write_Line ("tturn on warnings for tracking deleted code");
Write_Line ("T*   turn off warnings for tracking deleted code");
+   Write_Line (".t*  turn on warnings for suspicious contract");
+   Write_Line (".T   turn off warnings for suspicious contract");
Write_Line ("u+   turn on warnings for unused entity");
Write_Line ("U*   turn off warnings for unused entity");
Write_Line (".u   turn on warnings for unordered enumeration");
Index: warnsw.adb
===
--- warnsw.adb  (revision 178381)
+++ warnsw.adb  (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1999-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1999-2011, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -143,6 +143,12 @@
  when 'S' =>
 Warn_On_Overridden_Size := False;
 
+ when 't' =>
+Warn_On_Suspicious_Contract := True;
+
+ when 'T' =>
+Warn_On_Suspicious_Contract := False;
+
  when 'u' =>
 Warn_On_Unordered_Enumeration_Type  := True;
 
Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 178411)
+++ sem_ch6.adb (working copy)
@@ -5454,6 +5454,207 @@
   end if;
end Check_Returns;
 
+   ---
+   -- Check_Subprogram_Contract --
+   ---
+
+   procedure Check_Subprogram_Contract (Spec_Id : Entity_Id) is
+
+--Inherited : constant Subprogram_List :=
+--  Inherited_Subprograms (Spec_Id);
+  --  List of subprograms inherited by this subprogram
+
+  Last_Postcondition : Node_Id := Empty;
+  --  Last postcondition on the subprogram, or else Empty if either no
+  --  postcondition or only inherited postconditions.
+
+  Attribute_Result_Mentioned : Boolean := False;
+  --  Whether attribute 'Result is mentioned in a postcondition
+
+  Post_State_Mentioned   : Boolean := False;
+  --  Whether some expression mentioned in a postcondition can have a
+  --  different value in the post-state than in the pre-state.
+
+  function Check_Attr_Result (N : Node_Id) return Traverse_Result;
+  --  Check whether N is a reference to the attribute 'Result, and if so
+  --  set Attribute_Result_Mentioned and return Abandon. Otherwise return
+  --  OK.
+
+  function Check_

[Ada] Program_Unit pragmas in generic units are inherited by instances

2011-09-02 Thread Arnaud Charlet
Pragmas on generic units, if they are not library unit pragmas, are inherited
by each instantiation of the generic. Pragma Convention was omitted from this
processing.

The following must execute quietly:

   gnatmake -q address_test.adb
   address_test

---
with Ada.Text_Io; use Ada.Text_IO;
with Interfaces;
with System.Address_Image;
use System;

procedure Address_Test is

   Addr_1 : System.Address;
   Addr_2 : System.Address;

   generic
  type Item_Type is limited private;
   function Test_Address (Item : in Item_Type) return Interfaces.Unsigned_64;
   pragma Convention (C, Test_Address);

   function Test_Address (Item : in Item_Type) return Interfaces.Unsigned_64 is
   begin
  Addr_2 := Item'Address;
  return 1;
   end;

   type Object_Type is
  record
 Data_01 : Interfaces.Unsigned_64 := 01;
 Data_02 : Interfaces.Unsigned_64 := 02;
  end record;

   type Object_Type_2 is
  record
 Data_01 : Interfaces.Unsigned_64 := 01;
 Data_02 : Interfaces.Unsigned_64 := 02;
 Data_03 : Interfaces.Unsigned_64 := 03;
  end record;

   function Test_Object_Address is new Test_Address (Item_Type => Object_Type);

   Test_Object : Object_Type;

   function Test_Object_2_Address is
  new Test_Address (Item_Type => Object_Type_2);

   Test_Object_2 : Object_Type_2;

   U64 : Interfaces.Unsigned_64 := 666;

begin
   Addr_1 := Test_Object'Address;
   U64 := Test_Object_Address (Item => Test_Object);
   if Addr_1 /= Addr_2 then
  Put_Line ("Test_Object: different addresses");
   end if;

   Addr_1 := Test_Object_2'Address;
   U64 := Test_Object_2_Address (Item => Test_Object_2);
   if Addr_1 /= Addr_2 then
  Put_Line ("Test_Object_2: different addresses");
   end if;
end Address_Test;

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

2011-09-02  Ed Schonberg  

* sem_ch12.adb (Analyze_Subprogram_Instantiation): If the
generic unit is not intrinsic and has an explicit convention,
the instance inherits it.

Index: sem_ch12.adb
===
--- sem_ch12.adb(revision 178398)
+++ sem_ch12.adb(working copy)
@@ -4430,8 +4430,6 @@
  --  for the compilation, we generate the instance body even if it is
  --  not within the main unit.
 
- --  Any other  pragmas might also be inherited ???
-
  if Is_Intrinsic_Subprogram (Gen_Unit) then
 Set_Is_Intrinsic_Subprogram (Anon_Id);
 Set_Is_Intrinsic_Subprogram (Act_Decl_Id);
@@ -4441,6 +4439,17 @@
 end if;
  end if;
 
+ --  Inherit convention from generic unit. Intrinsic convention, as for
+ --  an instance of unchecked conversion, is not inherited because an
+ --  explicit Ada instance has been created.
+
+ if Has_Convention_Pragma (Gen_Unit)
+   and then Convention (Gen_Unit) /= Convention_Intrinsic
+ then
+Set_Convention (Act_Decl_Id, Convention (Gen_Unit));
+Set_Is_Exported (Act_Decl_Id, Is_Exported (Gen_Unit));
+ end if;
+
  Generate_Definition (Act_Decl_Id);
  Set_Contract (Anon_Id, Make_Contract (Sloc (Anon_Id))); -- ??? needed?
  Set_Contract (Act_Decl_Id, Make_Contract (Sloc (Act_Decl_Id)));
@@ -4479,8 +4488,6 @@
 
  Check_Hidden_Child_Unit (N, Gen_Unit, Act_Decl_Id);
 
- --  Subject to change, pending on if other pragmas are inherited ???
-
  Validate_Categorization_Dependency (N, Act_Decl_Id);
 
  if not Is_Intrinsic_Subprogram (Act_Decl_Id) then


[Ada] Perform required checks on discriminants read from streams using 'Input

2011-09-02 Thread Arnaud Charlet
Ada 2012 AI05-0192 is a binding interpretation that makes it clear that when
reading a discriminated value using the Input stream attribute, discriminants
values read from the stream must match any constraint imposed by the subtype
given as the attribute's prefix. These checks are now done by checking each
read discriminant value against the corresponding constrained value of the
subtype immediately after the value is read.

The following test must compile and execute quietly when compiled with -gnat05:


with Ada.Streams;  use Ada.Streams;

procedure AI05_0192_Test is

   package My_Streams is

  type My_Stream_Type is new Root_Stream_Type with record
 Buffer : Stream_Element_Array (1 .. 100);
 Buffer_Index : Stream_Element_Offset := 1;
  end record;

  procedure Read
(Stream : in out My_Stream_Type;
 Item   : out Stream_Element_Array;
 Last   : out Stream_Element_Offset);

  procedure Write
(Stream : in out My_Stream_Type;
 Item   : in Stream_Element_Array);

   end My_Streams;

   package body My_Streams is

  procedure Read
(Stream : in out My_Stream_Type;
 Item   : out Stream_Element_Array;
 Last   : out Stream_Element_Offset)
  is
 Index : Stream_Element_Offset := Item'First;

  begin
 while Index <= Item'Last loop
Item (Index) := Stream.Buffer (Stream.Buffer_Index);
Stream.Buffer_Index := Stream.Buffer_Index + 1;

Index := Index + 1;
 end loop;

 Last := Index - 1;
  end Read;

  procedure Write
(Stream : in out My_Stream_Type;
 Item   : in Stream_Element_Array)
  is
  begin
 Stream.Buffer
   (Stream.Buffer_Index .. Stream.Buffer_Index + Item'Length - 1)
 := Item;

 Stream.Buffer_Index := Stream.Buffer_Index + Item'Length;
  end Write;

   end My_Streams;

   Stream : aliased My_Streams.My_Stream_Type;

   type T1 (D : Natural) is null record;

   type T2_123 is new T1 (123);

   type T2_456 is new T1 (456);

   T1_Obj : T1 := (D => 456);

   type T3_Dbl_Discr (D1, D2 : Natural) is null record;

   type T4_DD is new T3_Dbl_Discr (D1 => 123, D2 => 456);

   type T5_DD is new T3_Dbl_Discr (D1 => 123, D2 => 789);

   T3_DD_Obj : T3_Dbl_Discr := (D1 => 123, D2 => 789);

begin
   T1'Output (Stream'Access, T1_Obj);

   begin
  Stream.Buffer_Index := 1;

  declare
 T1_Obj : T1 := T1'Input (Stream'Access);   -- OK: no exception
  begin
 null;
  end;

   exception
  when others => raise Program_Error;
   end;

   begin
  Stream.Buffer_Index := 1;

  declare
 T1_Obj : T1 := T1 (T2_123'Input (Stream'Access));  -- Constraint_Error
  begin
 null;
 raise Program_Error;
  end;

   exception
  when Constraint_Error =>
 null;
  when others =>
 raise Program_Error;
   end;

   begin
  Stream.Buffer_Index := 1;

  declare
 T1_Obj : T1 := T1 (T2_456'Input (Stream'Access));  -- OK: no exception
  begin
 null;
  end;

   exception
  when others =>
 raise Program_Error;
   end;

   Stream.Buffer_Index := 1;

   T3_Dbl_Discr'Output (Stream'Access, T3_DD_Obj);

   begin
  Stream.Buffer_Index := 1;

  declare
 T3_Obj : T3_Dbl_Discr := T3_Dbl_Discr (T4_DD'Input (Stream'Access)); 
   -- Constraint_Error
  begin
 raise Program_Error;
  end;

   exception
  when Constraint_Error =>
 null;
  when others =>
 raise Program_Error;
   end;

   begin
  Stream.Buffer_Index := 1;

  declare
 T3_Obj : T3_Dbl_Discr := T3_Dbl_Discr (T5_DD'Input (Stream'Access));
   -- OK: no exception
  begin
 null;
  end;

   exception
  when others =>
 raise Program_Error;
   end;
end AI05_0192_Test;

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

2011-09-02  Gary Dismukes  

* exp_attr.adb (Expand_N_Attribute_Reference): Pass the
underlying subtype rather than its base type on the call to
Build_Record_Or_Elementary_Input_Function, so that any
constraints on a discriminated subtype will be available for
doing the check required by AI05-0192.
* exp_strm.adb (Build_Record_Or_Elementary_Input_Function):
If the prefix subtype of the 'Input attribute is a constrained
discriminated subtype, then check each constrained discriminant value
against the corresponding value read from the stream.

Index: exp_attr.adb
===
--- exp_attr.adb(revision 178399)
+++ exp_attr.adb(working copy)
@@ -2531,8 +2531,12 @@
   return;
end if;
 
+   --  Build the type's Input function, passing the subtype rather
+   --  than its base type, because checks are needed in the case o

[Ada] --version and --help in usage of GNAT tools

2011-09-02 Thread Arnaud Charlet
The usage of GNAT tools has been enhanced to include lines for options
--version and --help. The test for this is to invoke a GNAT tool with --help
and to check that there are lines for --version and --help in the output.

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

2011-09-02  Vincent Celier  

* bindusg.adb, clean.adb, gnatchop.adb, gnatfind.adb, gnatlink.adb,
gnatls.adb, gnatname.adb, gnatxref.adb, gprep.adb, makeusg.adb: Add
--version and --help in usage.
* switch.ads, switch.adb (Display_Usage_Version_And_Help): New procedure

Index: gnatchop.adb
===
--- gnatchop.adb(revision 178381)
+++ gnatchop.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1998-2009, Free Software Foundation, Inc. --
+--  Copyright (C) 1998-2011, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -1361,6 +1361,9 @@
  "[-r] [-p] [-q] [-v] [-w] [-x] [--GCC=xx] file [file ...] [dir]");
 
   New_Line;
+
+  Display_Usage_Version_And_Help;
+
   Put_Line
 ("  -c   compilation mode, configuration pragmas " &
  "follow RM rules");
Index: bindusg.adb
===
--- bindusg.adb (revision 178381)
+++ bindusg.adb (working copy)
@@ -25,6 +25,7 @@
 
 with Osint;  use Osint;
 with Output; use Output;
+with Switch; use Switch;
 
 with System.WCh_Con; use System.WCh_Con;
 
@@ -55,6 +56,8 @@
   Write_Eol;
   Write_Eol;
 
+  Display_Usage_Version_And_Help;
+
   --  Line for @response_file
 
   Write_Line ("  @ Get arguments from response file");
Index: makeusg.adb
===
--- makeusg.adb (revision 178381)
+++ makeusg.adb (working copy)
@@ -26,6 +26,7 @@
 with Makeutl;
 with Osint;   use Osint;
 with Output;  use Output;
+with Switch;  use Switch;
 with Usage;
 
 procedure Makeusg is
@@ -51,6 +52,8 @@
Write_Str ("gnatmake switches:");
Write_Eol;
 
+   Display_Usage_Version_And_Help;
+
--  Line for -a
 
Write_Str ("  -a   Consider all files, even readonly ali files");
Index: gnatlink.adb
===
--- gnatlink.adb(revision 178381)
+++ gnatlink.adb(working copy)
@@ -1422,6 +1422,8 @@
   Write_Eol;
   Write_Line ("  mainprog.ali   the ALI file of the main program");
   Write_Eol;
+  Write_Eol;
+  Display_Usage_Version_And_Help;
   Write_Line ("  -fForce object file list to be generated");
   Write_Line ("  -gCompile binder source file with debug information");
   Write_Line ("  -nDo not compile the binder source file");
Index: clean.adb
===
--- clean.adb   (revision 178381)
+++ clean.adb   (working copy)
@@ -1893,6 +1893,8 @@
  Put_Line ("Usage: gnatclean [switches] {[-innn] name}");
  New_Line;
 
+ Display_Usage_Version_And_Help;
+
  Put_Line ("  names is one or more file names from which " &
"the .adb or .ads suffix may be omitted");
  Put_Line ("  names may be omitted if -P is specified");
Index: gprep.adb
===
--- gprep.adb   (revision 178381)
+++ gprep.adb   (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 2002-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 2002-2011, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -808,6 +808,7 @@
   Write_Line ("  deffileName of the definition file");
   Write_Eol;
   Write_Line ("gnatprep switches:");
+  Display_Usage_Version_And_Help;
   Write_Line ("   -b  Replace preprocessor lines by blank lines");
   Write_Line ("   -c  Keep preprocessor lines as comments");
   Write_Line ("   -C  Do symbol replacements within comments");
Index: gnatxref.adb
=

Re: [PATCH] Change vcond to vcond

2011-09-02 Thread Richard Guenther
On Tue, 30 Aug 2011, Richard Guenther wrote:

> On Tue, 30 Aug 2011, Richard Guenther wrote:
> 
> > On Tue, 30 Aug 2011, Uros Bizjak wrote:
> > 
> > > On Tue, Aug 30, 2011 at 11:15 AM, Richard Guenther  
> > > wrote:
> > > 
> > > >> >> > Hmm.  But then I'd have to try emit an insn, right?  Currently
> > > >> >> > the vectorizer simply looks for an optab handler ... the
> > > >> >> > operands are not readily available (but their mode is known).
> > > >> >> > So I'd create some fake regs, setup operands and call GEN_FCN
> > > >> >> > on it?  If it succeds I'd have to delete emitted insns, etc.
> > > >> >> > Or I could add a target hook ...
> > > >> >>
> > > >> >> Hm... indeed, too much complication...
> > > >> >>
> > > >> >> I'd say, let's go with modeless operands and a target hook. IMO, 
> > > >> >> this
> > > >> >> is much more flexible than checking optab for supported modes.
> > > >> >> Existing way is appropriate for single mode patterns, but we have
> > > >> >> interdependent modes here, at least on x86.
> > > >> >>
> > > >> >> The hook would have two input arguments, insn mode and compare mode,
> > > >> >> where the hook returns suggested supported compare mode, or no mode,
> > > >> >> if it really can't handle requested modes.
> > > >> >
> > > >> > I think a two mode vcond pattern is in fact much cleaner than
> > > >> > a one mode + modeless pattern which gen* will complain about and
> > > >> > a target hook.
> > > >>
> > > >> OK, but in this case, do not use mode iterators too much in order to
> > > >> avoid invalid patterns.
> > > >
> > > > I don't see them as "invalid".  They will be unused (maybe combine
> > > > would create them though?), but they have well-defined semantics
> > > > with my proposed documentation.  And x86 can handle them just fine.
> > > 
> > > OK, let's go this way then... We can clean up this later if at all.
> > 
> > Certainly what I prefer (less work for me now) ;)  The smallest
> > number of patterns would probably result from using vcond
> > to cover the same-mode cases and then add the 12 other patterns
> > with the respective integer / float mode variant.  Thus we'd have
> > 15 patterns in total (still much for my taste).
> > 
> > Ideally we could have a mode attribute that would map possibly
> > to an iterator, thus
> > 
> > (define_mode_attr matching [(V4SF ["V4SF" "V4SI"]) (V8HI "V8HI") ...])
> > 
> > or similar.  But I don't feel like adding this sort of mode
> > attr that really is a hidden iterator ... ;)
> > 
> > Thus, the following is the combined patch which bootstrapped and
> > tested ok on x86_64-unknown-linux-gnu with {,-m32} over night,
> > with the documentation for vcond added.
> > 
> > Ok for trunk?
> 
> I'm re-testing with the patterns having an extra condition like
>&& (GET_MODE_NUNITS (mode)
>== GET_MODE_NUNITS (mode))"
> to have the HAVE_vcond* defines easily optimized.
> 
> Ok?

Ping.  I'd like to have approval for the x86 changes.

Thanks,
Richard.

> 2011-08-30  Richard Guenther  
> 
>   PR tree-optimization/27460
>   PR middle-end/29269
>   * doc/md.texi (vcond): Document.
>   * genopinit.c (optabs): Turn vcond{,u}_optab into a conversion
>   optab with two modes.
>   * optabs.h (enum convert_optab_index): Add COI_vcond, COI_vcondu.
>   (enum direct_optab_index): Remove DOI_vcond, DOI_vcondu.
>   (vcond_optab): Adjust.
>   (vcondu_optab): Likewise.
>   (expand_vec_cond_expr_p): Adjust prototype.
>   * optabs.c (get_vcond_icode): Adjust.
>   (expand_vec_cond_expr_p): Likewise.
>   (expand_vec_cond_expr): Likewise.
>   * tree-vect-stmts.c (vect_is_simple_cond): Return the comparison
>   vector type.
>   (vectorizable_condition): Allow differing types for comparison
>   and result.
> 
>   * config/i386/i386.c (ix86_expand_sse_cmp): Use proper mode
>   for the comparison.
>   * config/i386/sse.md (vcond): Split to
>   vcond, vcond,
>   vcond and
>   vcondu.
>   (vcondv2di): Change to vcondv2di.
>   (vconduv2di): Likewise.
>   * config/arm/neon.md (vcond): Change to vcond*.
>   (vcondu): Likewise.
>   * config/ia64/vect.md (vcond): Likewise.
>   (vcondu): Likewise.
>   (vcondv2sf): Likewise.
>   * config/mips/mips-ps-3d.md (vcondv2sf): Likewise.
>   * config/rs6000/paired.md (vcondv2sf): Likewise.
>   * config/rs6000/vector.md (vcond): Likewise.
>   (vcondu): Likewise.
>   * config/spu/spu.md (vcond): Likewise.
>   (vcondu): Likewise.
> 
>   * gcc.dg/vect/vect-cond-7.c: New testcase.
> 
> Index: trunk/gcc/config/arm/neon.md
> ===
> *** trunk.orig/gcc/config/arm/neon.md 2011-08-30 10:53:47.0 +0200
> --- trunk/gcc/config/arm/neon.md  2011-08-30 11:46:51.0 +0200
> ***
> *** 1600,1606 
>   ;; where op3 is <, <=, ==, !=, >= or >.  Operations are performed
>   ;; element-wise.
>   
> ! (define_expand 

[Ada] Restrict SAL library names to Ada identifiers

2011-09-02 Thread Arnaud Charlet
The Project Manager is now checking that the names of Stand-Alone
libraries have the syntax of Ada identifiers, so that the binder
generated files that contains unit and subprogram names derived from the
library name will compile. If this check fails, an error is reported and
the tool terminates its execution.
The test is to invoke gnatmake on a SAL project with a library name such
as "bad-name". An error should be reported by gnatmake and no further
processing should happen.

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

2011-09-02  Vincent Celier  

* prj-nmsc.db: (Check_Stand_Alone_Library): For SALs, allow
only library names with the syntax of Ada identifiers, to avoid errors
when compiling the binder generated files.
* projects.texi: Document restriction on SAL library names

Index: prj-nmsc.adb
===
--- prj-nmsc.adb(revision 178448)
+++ prj-nmsc.adb(working copy)
@@ -82,8 +82,7 @@
   Hash   => Hash,
   Equal  => "=");
--  File name information found in string list attribute (Source_Files or
-   --  Source_List_File). Except is set to True if source is a naming exception
-   --  in the project. Used to check that all referenced files were indeed
+   --  Source_List_File). Used to check that all referenced files were indeed
--  found on the disk.
 
type Unit_Exception is record
@@ -4302,6 +4301,12 @@
is
   Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared;
 
+  Lib_Name: constant Prj.Variable_Value :=
+  Prj.Util.Value_Of
+   (Snames.Name_Library_Name,
+Project.Decl.Attributes,
+Shared);
+
   Lib_Interfaces  : constant Prj.Variable_Value :=
   Prj.Util.Value_Of
 (Snames.Name_Library_Interface,
@@ -4353,7 +4358,45 @@
   --  Library_Interface is defined.
 
   if not Lib_Interfaces.Default then
+
+ --  The name of a stand-alone library needs to have the syntax of an
+ --  Ada identifier.
+
  declare
+Name : constant String := Get_Name_String (Project.Library_Name);
+OK   : Boolean := Is_Letter (Name (Name'First));
+Underline : Boolean := False;
+ begin
+for J in Name'First + 1 .. Name'Last loop
+   exit when not OK;
+
+   if Is_Alphanumeric (Name (J)) then
+  Underline := False;
+
+   elsif Name (J) = '_' then
+  if Underline then
+ OK := False;
+  else
+ Underline := True;
+  end if;
+
+   else
+  OK := False;
+   end if;
+end loop;
+
+OK := OK and then not Underline;
+
+if not OK then
+   Error_Msg
+ (Data.Flags,
+  "Incorrect library name for a Stand-Alone Library",
+  Lib_Name.Location, Project);
+   return;
+end if;
+ end;
+
+ declare
 Interfaces : String_List_Id := Lib_Interfaces.Values;
 Interface_ALIs : String_List_Id := Nil_String;
 Unit   : Name_Id;
Index: projects.texi
===
--- projects.texi   (revision 178446)
+++ projects.texi   (working copy)
@@ -1,6 +1,7 @@
 @set gprconfig GPRconfig
 
 @c -- projects.texi
+@c Copyright (C) 2002-2011, Free Software Foundation, Inc.
 @c This file is shared between the GNAT user's guide and gprbuild. It is not
 @c compilable on its own, you should instead compile the other two manuals.
 @c For that reason, there is no toplevel @menu
@@ -1525,10 +1526,11 @@
 @item @b{Library_Name}:
 @cindex @code{Library_Name}
   This attribute is the name of the library to be built. There is no
-  restriction on the name of a library imposed by the project manager;
-  however, there may be system specific restrictions on the name.
-  In general, it is recommended to stick to alphanumeric characters
-  (and possibly underscores) to help portability.
+  restriction on the name of a library imposed by the project manager, except
+  for stand-alone libraries whose names must follow the syntax of Ada
+  identifiers; however, there may be system specific restrictions on the name.
+  In general, it is recommended to stick to alphanumeric characters (and
+  possibly single underscores) to help portability.
 
 @item @b{Library_Dir}:
 @cindex @code{Library_Dir}
@@ -1749,6 +1751,9 @@
 Ada: they provide a means for minimizing relinking & redeployment of complex
 systems when localized changes are made.
 
+The name of a stand-alone library, specified with attribute
+@code{Library_Name}, must have the syn

New Japanese PO file for 'gcc' (version 4.6.1)

2011-09-02 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'gcc' has been submitted
by the Japanese team of translators.  The file is available at:

http://translationproject.org/latest/gcc/ja.po

(This file, 'gcc-4.6.1.ja.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

http://translationproject.org/latest/gcc/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

http://translationproject.org/domain/gcc.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




[Ada] Wrong subunit source used in extending project

2011-09-02 Thread Arnaud Charlet
When a subunit source file in a project being extended is replaced with
one in the extending project with a different source file name, the
subunit source in the project being extended is still used.
This patch fixes this. The test is to use a subunit source
pkg-execute.adb in a project being extended and a replacing subunit
source pkg-execute.bdy (with the correct declaration in package Naming)
in the extending project and to verify that the correct procedure
Pkg.Execute is executed.

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

2011-09-02  Vincent Celier  

* prj-conf.adb (Add_Default_GNAT_Naming_Scheme): Declare "gcc"
as the compiler driver so Is_Compilable returns True for sources.
* prj-nmsc.adb (Override_Kind): When Kind is Sep, set the source
for the body.

Index: prj-nmsc.adb
===
--- prj-nmsc.adb(revision 178457)
+++ prj-nmsc.adb(working copy)
@@ -6766,8 +6766,13 @@
& " kind=" & Source.Kind'Img);
   end if;
 
-  if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
- Source.Unit.File_Names (Source.Kind) := Source;
+  if Source.Unit /= null then
+ if Source.Kind = Spec then
+Source.Unit.File_Names (Spec) := Source;
+
+ else
+Source.Unit.File_Names (Impl) := Source;
+ end if;
   end if;
end Override_Kind;
 
Index: prj-conf.adb
===
--- prj-conf.adb(revision 178446)
+++ prj-conf.adb(working copy)
@@ -436,6 +436,8 @@
 
  Compiler := Create_Package (Project_Tree, Config_File, "compiler");
  Create_Attribute
+   (Name_Driver, "gcc", "ada", Pkg => Compiler);
+ Create_Attribute
(Name_Language_Kind, "unit_based", "ada", Pkg => Compiler);
  Create_Attribute
(Name_Dependency_Kind, "ALI_File", "ada", Pkg => Compiler);


[Ada] Class-wide pre/postconditions

2011-09-02 Thread Arnaud Charlet
Class-wide pre- and postconditions of a primitive operation of some type T
apply to the overriding operation of any descendant of T. Therefore, any
mention of of a formal of type T in the expression for the condition must be
interpreted as a being of type  T'class. A similar rule applies to access
paremeters. This patch adds the required type conversion to such references.
The following must execute quietly:

gnatmake -q -gnatws -gnat12 -gnata r
r
--
with System.Assertions; use System.Assertions;
with P1.Q1;
procedure R is
   Thing1 : P1.T1;
   Thing2 : P1.Q1.T2;
   Thing3 : aliased P1.Q1.T2;

begin
 P1.P (Thing1);

   begin
 P1.Q1.P (Thing2);
 raise Program_Error;   --  should not reach here
   exception
 when Assert_Failure  => null;
   end;

   --  Test access parameters.

   begin
 P1.Q1.P2 (Thing3'access);
 raise Program_Error;   --  should not reach here
   exception
 when Assert_Failure  => null;
   end;
end R;
---
package P1 is
  type T1 is tagged record
 Value : Integer := 16;
  end record;

  procedure P(X : in out T1) with
Pre'Class => Precond(X'Old),
Post'Class => Postcond(X);

  procedure P2 (X : access T1)
  with
Post'Class => X.all.Value > 0;
  
  function Precond(X : T1) return Boolean;
  function Postcond(X : T1) return Boolean;
end P1;
---
package body P1 is

  procedure P(X : in out T1)  is begin null; end;

  procedure P2 (X : access T1) is
  begin
X.Value := X.Value + 3;
 end P2;

  function Precond(X : T1) return Boolean is begin return True; end;
  function Postcond(X : T1) return Boolean is begin return X.Value < 20; end;
end P1;
---
package P1.Q1 is
  type T2 is new T1 with null record;

  overriding
procedure P(X : in out T2);

  overriding
procedure P2 (X : access T2);
end P1.Q1;
---
package body P1.Q1 is

 --  Overriding procedures that violate inherited postcondition.

 procedure P (X : in out T2) is begin X.Value := 25; end;

 procedure P2 (X : access T2) is
  begin
X.Value := -X.Value + 3;
 end P2;
end P1.Q1;

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

2011-09-02  Ed Schonberg  

* sem_prag.adb (Analyze_PPC_In_Decl_Part): for a class-wide
condition, a reference to a controlling formal must be interpreted
as having the class-wide type (or an access to such) so that the
inherited condition can be properly applied to any overriding
operation (see ARM12 6.6.1 (7)).

Index: sem_prag.adb
===
--- sem_prag.adb(revision 178381)
+++ sem_prag.adb(working copy)
@@ -39,6 +39,7 @@
 with Errout;   use Errout;
 with Exp_Dist; use Exp_Dist;
 with Exp_Util; use Exp_Util;
+with Freeze;   use Freeze;
 with Lib;  use Lib;
 with Lib.Writ; use Lib.Writ;
 with Lib.Xref; use Lib.Xref;
@@ -261,6 +262,99 @@
   Preanalyze_Spec_Expression
 (Get_Pragma_Arg (Arg1), Standard_Boolean);
 
+  if Class_Present (N) then
+ declare
+T   : constant Entity_Id := Find_Dispatching_Type (S);
+
+ACW : Entity_Id := Empty;
+--  Access to T'class, created if there is a controlling formal
+--  that is an access parameter.
+
+function Get_ACW return Entity_Id;
+--  If the expression has a reference to an controlling access
+--  parameter, create an access to T'class for the necessary
+--  conversions if one does not exist.
+
+function Process (N : Node_Id) return Traverse_Result;
+--  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
+--  aspect for a primitive subprogram of a tagged type T, a name
+--  that denotes a formal parameter of type T is interpreted as
+--  having type T'Class. Similarly, a name that denotes a formal
+--  accessparameter of type access-to-T is interpreted as having
+--  type access-to-T'Class. This ensures the expression is well-
+--  defined for a primitive subprogram of a type descended from T.
+
+-
+-- Get_ACW --
+-
+
+function Get_ACW return Entity_Id is
+   Loc  : constant Source_Ptr := Sloc (N);
+   Decl : Node_Id;
+
+begin
+   if No (ACW) then
+  Decl := Make_Full_Type_Declaration (Loc,
+Defining_Identifier => Make_Temporary (Loc, 'T'),
+Type_Definition =>
+   Make_Access_To_Object_Definition (Loc,
+   Subtype_Indication =>
+ New_Occurrence_Of (Class_Wide_Type (T), Loc),
+   All_Present => True));
+
+  Insert_Before (Unit_Declaration_Node (S), Decl);
+  Analyze (Decl);
+  ACW := Defining_Identifier (Decl);
+  Freeze_Before (Unit_Declaration_Node (S), ACW);

[Ada] Wrong initialization of limited class-wide interface objects

2011-09-02 Thread Arnaud Charlet
The code generated by the compiler to handle the initialization of
limited class-wide interface objects initialized by means of an
aggregate erroneously generates a copy of the object (which causes
a runtime exception in the application). After this patch the
following test compiles and executes well.

with Ada.Finalization; use Ada.Finalization;
package Types is
   type Iface is limited interface;

   type User is new Limited_Controlled and Iface with record
 X : Integer := 0;
   end record;

   overriding
   procedure Finalize (Obj : in out User);
end Types;

with GNAT.IO; use GNAT.IO;
package body Types is
   overriding
   procedure Finalize (Obj : in out User) is
   begin
  Put_Line ("Finalize");
   end Finalize;
end Types;

with Ada.Finalization; use Ada.Finalization;
with Types; use Types;
with System.Address_Image; use System;
procedure Demo is
   IW  : Iface'Class := User'(Limited_Controlled with X => 42);
   Str : constant String := Address_Image (IW'Address);
begin
   pragma Assert (Str /= "");
   null;
end Demo;

Command:
  gnatmake -gnata demo.adb -gnat05
Output:
  Finalize

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

2011-09-02  Javier Miranda  

* exp_ch3.adb (Expand_N_Object_Declaration): Do not copy the
initializing expression of a class-wide interface object declaration
if its type is limited.

Index: exp_ch3.adb
===
--- exp_ch3.adb (revision 178456)
+++ exp_ch3.adb (working copy)
@@ -4841,11 +4841,11 @@
 return;
 
  --  Ada 2005 (AI-251): Rewrite the expression that initializes a
- --  class-wide object to ensure that we copy the full object,
- --  unless we are targetting a VM where interfaces are handled by
- --  VM itself. Note that if the root type of Typ is an ancestor
- --  of Expr's type, both types share the same dispatch table and
- --  there is no need to displace the pointer.
+ --  class-wide interface object to ensure that we copy the full
+ --  object, unless we are targetting a VM where interfaces are handled
+ --  by VM itself. Note that if the root type of Typ is an ancestor of
+ --  Expr's type, both types share the same dispatch table and there is
+ --  no need to displace the pointer.
 
  elsif Comes_From_Source (N)
and then Is_Interface (Typ)
@@ -4978,14 +4978,32 @@
 
  --  Copy the object
 
- Insert_Action (N,
-   Make_Object_Declaration (Loc,
- Defining_Identifier => Obj_Id,
- Object_Definition =>
-   New_Occurrence_Of
- (Etype (Object_Definition (N)), Loc),
- Expression => New_Expr));
+ if not Is_Limited_Record (Expr_Typ) then
+Insert_Action (N,
+  Make_Object_Declaration (Loc,
+Defining_Identifier => Obj_Id,
+Object_Definition =>
+  New_Occurrence_Of
+(Etype (Object_Definition (N)), Loc),
+Expression => New_Expr));
 
+ --  Rename limited type object since they cannot be copied
+ --  This case occurs when the initialization expression
+ --  has been previously expanded into a temporary object.
+
+ else pragma Assert (not Comes_From_Source (Expr_Q));
+
+Insert_Action (N,
+  Make_Object_Renaming_Declaration (Loc,
+Defining_Identifier => Obj_Id,
+Subtype_Mark =>
+  New_Occurrence_Of
+(Etype (Object_Definition (N)), Loc),
+Name =>
+  Unchecked_Convert_To
+(Etype (Object_Definition (N)), New_Expr)));
+ end if;
+
  --  Dynamically reference the tag associated with the
  --  interface.
 


[Ada] Improve the function that computes a unique name for Entities

2011-09-02 Thread Arnaud Charlet
The function Unique_Name did not actually compute a unique name for
enumeration literals, because the type to which the literal belongs was not
taken into account. This patch fixes the issue.

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

2011-09-02  Johannes Kanig  

* sem_util.adb (Unique_Name): To obtain a unique name for enumeration
literals, take into account the type name; the type is *not*
the scope for an enumeration literal.

Index: sem_util.adb
===
--- sem_util.adb(revision 178440)
+++ sem_util.adb(working copy)
@@ -12747,6 +12747,8 @@
   then
  return Get_Name_String (Name_Standard) & "__" &
Get_Name_String (Chars (E));
+  elsif Ekind (E) = E_Enumeration_Literal then
+ return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
 
   else
  return Get_Scoped_Name (E);


[Ada] Adjust on limited controlled types

2011-09-02 Thread Arnaud Charlet
a GNAT artifact: Limited_Controlled is declared as an extension of Root_
Controlled, and thus has a useless Adjust operation. This operation should not
be inherited by other limited controlled types. An explicit Adjust for them is
not overriding.

gcc -c -gnat05 lib2.ads

must yield

   lib2.ads:13:04: subprogram "Adjust" is not overriding

---
private with Ada.Finalization;
package Lib2 is
   type Type_A (Value : Integer) is tagged limited private;
private

   use Ada.Finalization;

   type Type_A (Value : Integer) is new Limited_Controlled with record
  Refcount : Natural;
   end record;

   overriding  --  ERROR
   procedure Adjust (Object : in out Type_A);
end Lib2;

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

2011-09-02  Ed Schonberg  

* sem_ch6.adb (Check_Overriding_Indicator): add special check
to reject an overriding indicator on a user-defined Adjust
subprogram for a limited controlled type.

Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 178452)
+++ sem_ch6.adb (working copy)
@@ -4956,6 +4956,20 @@
  ("subprogram & overrides inherited operation #", Spec, Subp);
 end if;
 
+ --  Special-case to fix a GNAT oddity:  Limited_Controlled is declared
+ --  as an extension of Root_Controlled, and thus has a useless Adjust
+ --  operation. This operation should not be inherited by other limited
+ --  controlled types. An explicit Adjust for them is not overriding.
+
+ elsif Must_Override (Spec)
+   and then Chars (Overridden_Subp) = Name_Adjust
+   and then Is_Limited_Type (Etype (First_Formal (Subp)))
+   and then Present (Alias (Overridden_Subp))
+   and then Is_Predefined_File_Name
+ (Unit_File_Name (Get_Source_Unit (Alias (Overridden_Subp
+ then
+Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
+
  elsif Is_Subprogram (Subp) then
 if Is_Init_Proc (Subp) then
null;


[Ada] VMS: fix incompatibility of sendmsg/recvmsg

2011-09-02 Thread Arnaud Charlet
The msghdr structure has changed between vms 7 and 8.
This patch works arounds the incompatibility.

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

2011-09-02  Tristan Gingold  

* g-socthi-vms.adb (c_sendmsg, c_recvmsg): Use unpacked msg if on vms 7

Index: g-socthi-vms.adb
===
--- g-socthi-vms.adb(revision 178406)
+++ g-socthi-vms.adb(working copy)
@@ -42,8 +42,16 @@
pragma Pack (VMS_Msghdr);
--  On VMS 8.x (unlike other platforms), struct msghdr is packed, so a
--  specific derived type is required. This structure was not packed on
-   --  VMS 7.3, so sendmsg and recvmsg fail on earlier VMS versions.
+   --  VMS 7.3.
 
+   function Is_VMS_V7 return Integer;
+   pragma Import (C, Is_VMS_V7, "__gnat_is_vms_v7");
+   --  Helper (defined in init.c) that returns a non-zero value if the VMS
+   --  version is 7.x.
+
+   VMS_V7 : constant Boolean := Is_VMS_V7 /= 0;
+   --  True if VMS version is 7.x.
+
Non_Blocking_Sockets : aliased Fd_Set;
--  When this package is initialized with Process_Blocking_IO set to True,
--  sockets are set in non-blocking mode to avoid blocking the whole process
@@ -295,15 +303,24 @@
is
   Res : C.int;
 
+  Msg_Addr : System.Address;
+
   GNAT_Msg : Msghdr;
   for GNAT_Msg'Address use Msg;
   pragma Import (Ada, GNAT_Msg);
 
-  VMS_Msg : aliased VMS_Msghdr := VMS_Msghdr (GNAT_Msg);
+  VMS_Msg : aliased VMS_Msghdr;
 
begin
+  if VMS_V7 then
+ Msg_Addr := Msg;
+  else
+ VMS_Msg := VMS_Msghdr (GNAT_Msg);
+ Msg_Addr := VMS_Msg'Address;
+  end if;
+
   loop
- Res := Syscall_Recvmsg (S, VMS_Msg'Address, Flags);
+ Res := Syscall_Recvmsg (S, Msg_Addr, Flags);
  exit when SOSC.Thread_Blocking_IO
or else Res /= Failure
or else Non_Blocking_Socket (S)
@@ -311,7 +328,9 @@
  delay Quantum;
   end loop;
 
-  GNAT_Msg := Msghdr (VMS_Msg);
+  if not VMS_V7 then
+ GNAT_Msg := Msghdr (VMS_Msg);
+  end if;
 
   return System.CRTL.ssize_t (Res);
end C_Recvmsg;
@@ -327,15 +346,24 @@
is
   Res : C.int;
 
+  Msg_Addr : System.Address;
+
   GNAT_Msg : Msghdr;
   for GNAT_Msg'Address use Msg;
   pragma Import (Ada, GNAT_Msg);
 
-  VMS_Msg : aliased VMS_Msghdr := VMS_Msghdr (GNAT_Msg);
+  VMS_Msg : aliased VMS_Msghdr;
 
begin
+  if VMS_V7 then
+ Msg_Addr := Msg;
+  else
+ VMS_Msg := VMS_Msghdr (GNAT_Msg);
+ Msg_Addr := VMS_Msg'Address;
+  end if;
+
   loop
- Res := Syscall_Sendmsg (S, VMS_Msg'Address, Flags);
+ Res := Syscall_Sendmsg (S, Msg_Addr, Flags);
  exit when SOSC.Thread_Blocking_IO
or else Res /= Failure
or else Non_Blocking_Socket (S)
@@ -343,7 +371,9 @@
  delay Quantum;
   end loop;
 
-  GNAT_Msg := Msghdr (VMS_Msg);
+  if not VMS_V7 then
+ GNAT_Msg := Msghdr (VMS_Msg);
+  end if;
 
   return System.CRTL.ssize_t (Res);
end C_Sendmsg;


[Ada] Actuals that are function calls returning unconstrained limited types

2011-09-02 Thread Arnaud Charlet
This patch fixes an omission in the code that resolves actuals in a call.
Previous to this patch, and actual in a call that is an overloaded function
call, one of whose interpretations returns an unconstrained limited type may
be resolved incorrectly.
The command

  gnatmake -q -gnat05 main
  main

Must yield

  Create for Type_A

---
with Lib; use Lib;
procedure Main is
   A : Type_A (2);
begin
   Set (A, Create (2));
end Main;
---
private with Ada.Finalization;
package Lib is

   type Type_B (Value : Integer) is tagged limited private;
   function Create (Value : Integer) return Type_B;

   type Type_A (Value : Integer) is tagged limited private;
   function Create (Value : Integer) return Type_A;
   procedure Set (Left : in out Type_A; Right : Type_A);

private
   use Ada.Finalization;

   type Type_B (Value : Integer) is new Limited_Controlled with null record;

   type Natural_A is access Natural;

   type Type_A (Value : Integer) is new Limited_Controlled with record
  Refcount : Natural_A;
   end record;

   overriding
   procedure Initialize (Object : in out Type_A);

   procedure Adjust (Object : in out Type_A);

   overriding
   procedure Finalize (Object : in out Type_A);
end Lib;
---
with Ada.Text_IO;
with System.Storage_Elements;
with Unchecked_Deallocation;

package body Lib is

   use Ada.Text_IO;

   procedure Free is new Unchecked_Deallocation (Natural, Natural_A);


   overriding
   procedure Initialize (Object : in out Type_A) is
   begin
  Object.Refcount := new Natural'(1);
   end Initialize;

   procedure Adjust (Object : in out Type_A) is
   begin
  raise Program_Error with "Never override Adjust for Limited type.";
   end Adjust;

   overriding
   procedure Finalize (Object : in out Type_A) is
  Refcount : Natural_A := Object.Refcount;
   begin
  Object.Refcount := null;  -- Finalize must be idempotent

  if Refcount = null then
 null;
  else
 Refcount.all := Refcount.all - 1;

 if Refcount.all = 0 then
Free (Refcount);
 end if;
  end if;
   end Finalize;

   procedure Set (Left : in out Type_A; Right : Type_A) is
   begin
  if Left.Value /= Right.Value then
 Put_Line
   ("Left.Value, Right.Value : " &
Left.Value'Img &
", " &
Right.Value'Img);
 raise Constraint_Error with "Set : Discriminant Values don't match";
  end if;

  Left.Finalize;

  Left.Refcount := Right.Refcount;
  Left.Refcount.all := Left.Refcount.all + 1;

   end Set;

   function Create (Value : Integer) return Type_A is
   begin
  return R : Type_A (Value) do
 Put_Line ("Create for Type_A");
  end return;
   end Create;

   function Create (Value : Integer) return Type_B is
   begin
  return R : Type_B (Value) do
 Put_Line ("Create for Type_B");
  end return;
   end Create;
end Lib;

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

2011-09-02  Ed Schonberg  

* sem_res.adb (Resolve_Actuals): add missing call to Resolve
for an actual that is a function call returning an unconstrained
limited controlled type.

Index: sem_res.adb
===
--- sem_res.adb (revision 178381)
+++ sem_res.adb (working copy)
@@ -3446,6 +3446,7 @@
   and then (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
 then
Establish_Transient_Scope (A, False);
+   Resolve (A, Etype (F));
 
 --  A small optimization: if one of the actuals is a concatenation
 --  create a block around a procedure call to recover stack space.


[Ada] Change value of the variable Name_Of_Heap_Variable

2011-09-02 Thread Arnaud Charlet
This variable is used in Hi-Lite to group effects that cannot be described
more precisely. The new version 3 of Why, the backend of Hi-Lite, does not
accept variables to start with uppercase letters, so we choose a value which
works with both versions.

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

2011-09-02  Johannes Kanig  

* alfa.ads (Name_Of_Heap_Variable): Change value of the HEAP variable
from "HEAP" to __HEAP Change comment that refers to that variable
* put_alfa.adb: Change comment that refers to that variable

Index: alfa.ads
===
--- alfa.ads(revision 178381)
+++ alfa.ads(working copy)
@@ -91,8 +91,7 @@
 
--FS . scope line type col entity (-> spec-file . spec-scope)?
 
-   --  What is the ? marke here, is it part of the actual syntax, or is
-   --  it a query about a problem, in which case it should be ???
+   --  (The ? mark stands for an optional entry in the syntax)
 
--  scope is the ones-origin scope number for the current file (e.g. 2 =
--  reference to the second FS line in this FD block).
@@ -176,9 +175,9 @@
--s = subprogram reference in a static call
 
--  Special entries for reads and writes to memory reference a special
-   --  variable called "HEAP". These special entries are present in every scope
-   --  where reads and writes to memory are present. Line and column for this
-   --  special variable are always 0.
+   --  variable called "__HEAP". These special entries are present in every
+   --  scope where reads and writes to memory are present. Line and column for
+   --  this special variable are always 0.
 
--Examples: ??? add examples here
 
@@ -336,7 +335,7 @@
-- Constants --
---
 
-   Name_Of_Heap_Variable : constant String := "HEAP";
+   Name_Of_Heap_Variable : constant String := "__HEAP";
--  Name of special variable used in effects to denote reads and writes
--  through explicit dereference.
 
Index: put_alfa.adb
===
--- put_alfa.adb(revision 178398)
+++ put_alfa.adb(working copy)
@@ -151,8 +151,8 @@
   Write_Info_Char (S.Scope_Name (N));
end loop;
 
-   --  Default value of (0,0) is used for the special HEAP variable
-   --  so use another default value.
+   --  Default value of (0,0) is used for the special __HEAP
+   --  variable so use another default value.
 
Entity_Line := 0;
Entity_Col  := 1;


[Ada] Suppress false alarm "postcondition refers only to pre-state"

2011-09-02 Thread Arnaud Charlet
This patch suppresses these false, which can occur when a postcondition
contains a quantified expression.
The following test should compile quietly.
gnatmake -f -gnat2012 -gnatwa t.adb
package T is
   procedure P (S : in out String) with
 Post => (for all C of S => C = C);
end T;
package body T is
   procedure P (S : in out String) is
   begin
  null;
   end P;
end T;

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

2011-09-02  Bob Duff  

* sem_ch6.adb: (Check_Post_State): Suppress warning
"postcondition refers only to pre-state" when the expression has not
yet been analyzed, because it causes false alarms. This can happen when
the postcondition contains a quantified expression, because those are
analyzed later. This is a temporary/partial fix.
(Process_Post_Conditions): Minor: change wording of warning.

Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 178459)
+++ sem_ch6.adb (working copy)
@@ -5551,9 +5551,16 @@
declare
   E : constant Entity_Id := Entity (N);
begin
-  if Is_Entity_Name (N)
-and then Present (E)
-and then Ekind (E) in Assignable_Kind
+  --  ???Quantified expressions get analyzed later, so E can be
+  --  empty at this point. In this case, we suppress the
+  --  warning, just in case E is assignable. It seems better to
+  --  have false negatives than false positives. At some point,
+  --  we should make the warning more accurate, either by
+  --  analyzing quantified expressions earlier, or moving this
+  --  processing later.
+
+  if No (E) or else
+(Is_Entity_Name (N) and then Ekind (E) in Assignable_Kind)
   then
  Found := True;
   end if;
@@ -5627,7 +5634,7 @@
Ignored := Find_Post_State (Arg);
 
if not Post_State_Mentioned then
-  Error_Msg_N ("?postcondition only refers to pre-state",
+  Error_Msg_N ("?postcondition refers only to pre-state",
Prag);
end if;
 end if;


[Ada] Improved messages for use of incomplete type in selected components

2011-09-02 Thread Arnaud Charlet
This patch adds information to illegal uss of incomplete types. If the prefix
of a selected component is an incomplete type, and the completion is found
later in the same unit, an additional error indicates the position of the
full declaration.

  gcc -c -gnat05 obj.adb

must yield:

obj.adb:6:06: no selector "Component" for type "Map_Config_Window_Record'Class" 
defined at obj.ads:4
obj.adb:6:06: premature usage of incomplete type "Map_Config_Window_Record"
obj.adb:6:06: full declaration at line 9
---
package Obj is
  pragma Elaborate_Body;
private
  type Map_Config_Window_Record;
  type Config_T is access all Map_Config_Window_Record'Class;
end Obj;
---
with Ada.Finalization;
package body Obj is

  procedure Trucmuch (C : Config_T) is
  begin
C.Component := 1;
  end Trucmuch;

  type Map_Config_Window_Record is new Ada.Finalization.Controlled with
record
  Component : Integer;
end record;

  procedure Other_Trucmuch (C : Config_T) is
  begin
C.Component := 1;
  end Other_Trucmuch;

end Obj;

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

2011-09-02  Ed Schonberg  

* sinfo.ads, sinfo.adb: New semantic attribute Premature_Use,
present in incomplete type declarations to refine the error
message the full declaration is in the same unit.
* sem_ch4.adb (Analyze_Selected_Component): If the prefix is of
an incomplete type, set the Premature_Use for additional message.
* sem_ch3.adb (Find_Type_Name): If partial view is incomplete
and Premature_Use is set, place additional information at the
point of premature use.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 178460)
+++ sem_ch3.adb (working copy)
@@ -3313,18 +3313,22 @@
  --  Case of initialization present
 
  else
+--  Check restrictions in Ada 83 and SPARK modes
 
---  Not allowed in Ada 83
-
 if not Constant_Present (N) then
 
-   --  A declaration of unconstrained type in SPARK is limited,
-   --  the only exception to this is the admission of declaration
-   --  of constants of type string.
+   --  In SPARK, a declaration of unconstrained type is allowed
+   --  only for constants of type string.
 
+   --  Why no check for Comes_From_Source here, seems wrong ???
+   --  Where is check to differentiate string case ???
+
Check_SPARK_Restriction
- ("declaration of unconstrained type is limited", E);
+ ("declaration of object of unconstrained type not allowed",
+  E);
 
+   --  Unconstrained variables not allowed in Ada 83 mode
+
if Ada_Version = Ada_83
  and then Comes_From_Source (Object_Definition (N))
then
@@ -15056,6 +15060,14 @@
Tag_Mismatch;
 end if;
  end if;
+ if Present (Prev)
+   and then Nkind (Parent (Prev)) = N_Incomplete_Type_Declaration
+   and then Present (Premature_Use (Parent (Prev)))
+ then
+Error_Msg_Sloc := Sloc (N);
+Error_Msg_N
+  ("\full declaration #", Premature_Use (Parent (Prev)));
+ end if;
 
  return New_Id;
   end if;
Index: sinfo.adb
===
--- sinfo.adb   (revision 178401)
+++ sinfo.adb   (working copy)
@@ -2459,6 +2459,14 @@
   return Node3 (N);
end Prefix;
 
+   function Premature_Use
+  (N : Node_Id) return Node_Id is
+   begin
+  pragma Assert (False
+or else NT (N).Nkind = N_Incomplete_Type_Declaration);
+  return Node5 (N);
+   end Premature_Use;
+
function Present_Expr
   (N : Node_Id) return Uint is
begin
@@ -5510,6 +5518,14 @@
   Set_Node3_With_Parent (N, Val);
end Set_Prefix;
 
+   procedure Set_Premature_Use
+  (N : Node_Id; Val : Node_Id) is
+   begin
+  pragma Assert (False
+or else NT (N).Nkind = N_Incomplete_Type_Declaration);
+  Set_Node5 (N, Val);
+   end Set_Premature_Use;
+
procedure Set_Present_Expr
   (N : Node_Id; Val : Uint) is
begin
Index: sinfo.ads
===
--- sinfo.ads   (revision 178401)
+++ sinfo.ads   (working copy)
@@ -1598,6 +1598,12 @@
--package specification. This field is Empty for library bodies (the
--parent spec in this case can be found from the corresponding spec).
 
+   --  Premature_Use (Node5-Sem)
+   --Present in N_Incomplete_Type_Declaration node. Used for improved
+   --error diagnostics: if there is a premature usage of an incomplete
+   --type, a subsequently generated error message indicates the position
+   --of its full declaration.
+
--  Present_Expr (Uint3-Sem)
--Present in an N_Variant node. This has 

[Ada] Improved message for the restriction use of unconstrained type in SPARK

2011-09-02 Thread Arnaud Charlet
When the SPARK restriction mode was set, check that a declaration of 
unconstrained type is allowed only for constants of type string.

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

2011-09-02  Marc Sango  

* sem_ch3.adb (Analyze_Object_Declaration): Change
comment and add additional check to differentiate constant of
type string from others unconstrained type.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 178461)
+++ sem_ch3.adb (working copy)
@@ -3320,13 +3320,12 @@
--  In SPARK, a declaration of unconstrained type is allowed
--  only for constants of type string.
 
-   --  Why no check for Comes_From_Source here, seems wrong ???
-   --  Where is check to differentiate string case ???
+   if Nkind (E) = N_String_Literal then
+  Check_SPARK_Restriction
+("declaration of object of unconstrained type not allowed",
+ E);
+   end if;
 
-   Check_SPARK_Restriction
- ("declaration of object of unconstrained type not allowed",
-  E);
-
--  Unconstrained variables not allowed in Ada 83 mode
 
if Ada_Version = Ada_83


Re: ARM: Emit conditions in push_multi

2011-09-02 Thread Ramana Radhakrishnan
On 1 September 2011 12:50, Bernd Schmidt  wrote:
> Shrink-wrapping tests on ARM had one additional failure, which I could
> track down to a stmfd instruction being emitted where an stmhifd was
> intended. The following patch fixes the testcase; full tests running
> now. Ok?

IIUC this should have been a result of conditionalizing the prologue
saves by the CCFSM state machine in ARM state given that the push
instruction below doesn't have the conditional markers.  In which case
the routines to emit the asm for the VFP registers( vfp_output_fstmfd?
) should also be checked for this issue.

cheers
Ramana


[v3] Fix libstdc++/50268

2011-09-02 Thread Paolo Carlini

Hi,

tested x86_64-linux multilib, will go in 4_6-branch too.

See audit trail for details: in short when std::bitset has been updated 
for constexpr, thus the constructor from unsigned long long marked as 
such, the call to _M_do_sanitize in the body was inadvertently 
completely removed without replacing it with something else compatible 
with constexpr.


Thanks,
Paolo.

/
2011-09-02  Paolo Carlini  
Marc Glisse  

PR libstdc++/50268
* include/std/bitset (struct _Sanitize_val): Add.
(bitset<>::bitset(unsigned long long)): Fix.
* testsuite/23_containers/bitset/cons/50268.cc: New.
Index: include/std/bitset
===
--- include/std/bitset  (revision 178444)
+++ include/std/bitset  (working copy)
@@ -52,11 +52,13 @@
 #include 
 #include 
 
-#define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * sizeof(unsigned long))
+#define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * __SIZEOF_LONG__)
 #define _GLIBCXX_BITSET_WORDS(__n) \
   ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
 
+#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
@@ -657,6 +659,24 @@
   _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { } 
 };
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template
+struct _Sanitize_val
+{
+  static constexpr unsigned long long
+  _S_do_sanitize_val(unsigned long long __val)
+  { return __val; }
+};
+
+  template
+struct _Sanitize_val<_Nb, true>
+{
+  static constexpr unsigned long long
+  _S_do_sanitize_val(unsigned long long __val)
+  { return __val & ~((~static_cast(0)) << _Nb); }
+};
+#endif
+
   /**
*  @brief  The %bitset class represents a @e fixed-size sequence of bits.
*
@@ -822,7 +842,7 @@
   /// Initial bits bitwise-copied from a single word (others set to zero).
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   constexpr bitset(unsigned long long __val) noexcept
-  : _Base(__val) { }
+  : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
 #else
   bitset(unsigned long __val)
   : _Base(__val)
@@ -1513,6 +1533,7 @@
 
 #undef _GLIBCXX_BITSET_WORDS
 #undef _GLIBCXX_BITSET_BITS_PER_WORD
+#undef _GLIBCXX_BITSET_BITS_PER_ULL
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 
Index: testsuite/23_containers/bitset/cons/50268.cc
===
--- testsuite/23_containers/bitset/cons/50268.cc(revision 0)
+++ testsuite/23_containers/bitset/cons/50268.cc(revision 0)
@@ -0,0 +1,84 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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
+// .
+
+#include 
+#include 
+
+// libstdc++/50268
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::bitset<1> b1(3ULL);
+  VERIFY( b1.count() == 1ULL );
+
+  std::bitset<3> b2(30ULL);
+  VERIFY( b2.count() == 2ULL );
+
+  std::bitset<6> b3(300ULL);
+  VERIFY( b3.count() == 3ULL );
+
+  std::bitset<9> b4(3000ULL);
+  VERIFY( b4.count() == 5ULL );
+
+  std::bitset<16> b5(30ULL);
+  VERIFY( b5.count() == 7ULL );
+
+  std::bitset<24> b6(3000ULL);
+  VERIFY( b6.count() == 9ULL );
+
+  std::bitset<32> b7(300ULL);
+  VERIFY( b7.count() == 13ULL );
+
+  std::bitset<37> b8(3ULL);
+  VERIFY( b8.count() == 18ULL );
+
+  std::bitset<40> b9(30ULL);
+  VERIFY( b9.count() == 16ULL );
+
+  std::bitset<45> b10(30ULL);
+  VERIFY( b10.count() == 20ULL );
+
+  std::bitset<64> b11(30ULL);
+  VERIFY( b11.count() == 20ULL );
+
+  std::bitset<100> b12(30ULL);
+  VERIFY( b12.count() == 20ULL );
+
+  std::bitset<200> b13(30ULL);
+  VERIFY( b13.count() == 20ULL );
+
+  std::bitset<45> b14(18446744073709551615ULL);
+  VERIFY( b14.count() == 45ULL );
+
+  std::bitset<64> b15(18446744073709551615ULL);
+  VERIFY( b15.count() == 64ULL );
+
+  std::bitset<100> b16(18446744073709551615ULL);
+  VERIFY( b16.count() == 64ULL );
+
+  std::bitset<200> b17(18446744073709551615ULL);
+  VERIFY( b17.count() == 64ULL );  
+}
+
+int main()
+{
+  test01();
+  return 0;
+}


[PATCH, Atom] Improve AGU stalls avoidance optimization

2011-09-02 Thread Ilya Enkovich
Hello,

Here is a patch which adds few more splits for AGU stalls avoidance on
Atom. It also fixes cost model and detects AGU stalls more
efficiently.

Bootstrapped and checked on x86_64-linux.

Thanks,
Ilya
---
gcc/

2011-09-02  Enkovich Ilya  

* config/i386/i386-protos.h (ix86_lea_outperforms): New.
(ix86_avoid_lea_for_add): Likewise.
(ix86_avoid_lea_for_addr): Likewise.
(ix86_split_lea_for_addr): Likewise.

* config/i386/i386.c (LEA_MAX_STALL): New.
(increase_distance): Likewise.
(insn_defines_reg): Likewise.
(insn_uses_reg_mem): Likewise.
(distance_non_agu_define_in_bb): Likewise.
(distance_agu_use_in_bb): Likewise.
(ix86_lea_outperforms): Likewise.
(ix86_ok_to_clobber_flags): Likewise.
(ix86_avoid_lea_for_add): Likewise.
(ix86_avoid_lea_for_addr): Likewise.
(ix86_split_lea_for_addr): Likewise.
(distance_non_agu_define): Search in pred BBs added.
(distance_agu_use): Search in succ BBs added.
(IX86_LEA_PRIORITY): Value changed from 2 to 0.
(LEA_SEARCH_THRESHOLD): Now depends on LEA_MAX_STALL.
(ix86_lea_for_add_ok): Use ix86_lea_outperforms to make decision.

* config/i386/i386.md: Splits added to transform lea into a
sequence of instructions.


lea.diff
Description: Binary data


Re: [PATCH 11/12] i386: Always use TARGET_DEEP_BRANCH_PREDICTION.

2011-09-02 Thread Jan Hubicka
> While it could be possible to output_set_got such that we can
> individually annotate the instructions, it's simpler to simply
> admit that all processors currently being manufactured do want
> deep branch prediction.  At which point all of the complication
> simply goes away.

Note that most of modern CPUs special case call to next instruction, so 
they will work well with !X86_TUNE_DEEP_BRANCH_PREDICTION code.

Honza
> ---
>  gcc/config/i386/i386.c |  105 +++
>  gcc/config/i386/i386.h |3 -
>  2 files changed, 16 insertions(+), 92 deletions(-)
> 
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 014401b..332e65b 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -55,7 +55,6 @@ along with GCC; see the file COPYING3.  If not see
>  #include "params.h"
>  #include "cselib.h"
>  #include "debug.h"
> -#include "dwarf2out.h"
>  #include "sched-int.h"
>  #include "sbitmap.h"
>  #include "fibheap.h"
> @@ -1847,10 +1846,6 @@ static unsigned int 
> initial_ix86_tune_features[X86_TUNE_LAST] = {
>m_486 | m_PENT | m_ATOM | m_PPRO | m_AMD_MULTIPLE | m_K6
>| m_CORE2I7 | m_GENERIC,
>  
> -  /* X86_TUNE_DEEP_BRANCH_PREDICTION */
> -  m_ATOM | m_PPRO | m_K6_GEODE | m_AMD_MULTIPLE | m_PENT4
> -  | m_CORE2I7 | m_GENERIC,
> -
>/* X86_TUNE_BRANCH_PREDICTION_HINTS: Branch hints were put in P4 based
>   on simulation result. But after P4 was made, no performance benefit
>   was observed with branch hints.  It also increases the code size.
> @@ -8323,31 +8318,11 @@ output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
>  
>xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
>  
> -  if (! TARGET_DEEP_BRANCH_PREDICTION || !flag_pic)
> +  if (!flag_pic)
>  {
>xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
>  
> -  if (!flag_pic)
> - output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
> -  else
> - {
> -   output_asm_insn ("call\t%a2", xops);
> -#ifdef DWARF2_UNWIND_INFO
> -   /* The call to next label acts as a push.  */
> -   if (dwarf2out_do_frame ())
> - {
> -   rtx insn;
> -   start_sequence ();
> -   insn = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
> -  gen_rtx_PLUS (Pmode,
> -stack_pointer_rtx,
> -GEN_INT (-4;
> -   RTX_FRAME_RELATED_P (insn) = 1;
> -   dwarf2out_frame_debug (insn, true);
> -   end_sequence ();
> - }
> -#endif
> - }
> +  output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
>  
>  #if TARGET_MACHO
>/* Output the Mach-O "canonical" label name ("Lxx$pb") here too.  This
> @@ -8358,29 +8333,6 @@ output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
>  
>targetm.asm_out.internal_label (asm_out_file, "L",
> CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
> -
> -  if (flag_pic)
> - {
> -   output_asm_insn ("pop%z0\t%0", xops);
> -#ifdef DWARF2_UNWIND_INFO
> -   /* The pop is a pop and clobbers dest, but doesn't restore it
> -  for unwind info purposes.  */
> -   if (dwarf2out_do_frame ())
> - {
> -   rtx insn;
> -   start_sequence ();
> -   insn = emit_insn (gen_rtx_SET (VOIDmode, dest, const0_rtx));
> -   dwarf2out_frame_debug (insn, true);
> -   insn = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
> -  gen_rtx_PLUS (Pmode,
> -stack_pointer_rtx,
> -GEN_INT (4;
> -   RTX_FRAME_RELATED_P (insn) = 1;
> -   dwarf2out_frame_debug (insn, true);
> -   end_sequence ();
> - }
> -#endif
> - }
>  }
>else
>  {
> @@ -8388,12 +8340,6 @@ output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
>get_pc_thunk_name (name, REGNO (dest));
>pic_labels_used |= 1 << REGNO (dest);
>  
> -#ifdef DWARF2_UNWIND_INFO
> -  /* Ensure all queued register saves are flushed before the
> -  call.  */
> -  if (dwarf2out_do_frame ())
> - dwarf2out_flush_queued_reg_saves ();
> -#endif
>xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
>xops[2] = gen_rtx_MEM (QImode, xops[2]);
>output_asm_insn ("call\t%X2", xops);
> @@ -8408,13 +8354,8 @@ output_set_got (rtx dest, rtx label ATTRIBUTE_UNUSED)
>  #endif
>  }
>  
> -  if (TARGET_MACHO)
> -return "";
> -
> -  if (!flag_pic || TARGET_DEEP_BRANCH_PREDICTION)
> +  if (!TARGET_MACHO)
>  output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
> -  else
> -output_asm_insn ("add%z0\t{%1+[.-%a2], %0|%0, %1+(.-%a2)}", xops);
>  
>return "";
>  }
> @@ -10138,7 +10079,11 @@ ix86_expand_prologue (void)
>   

Re: ARM: Emit conditions in push_multi

2011-09-02 Thread Bernd Schmidt
On 09/02/11 12:35, Ramana Radhakrishnan wrote:
> On 1 September 2011 12:50, Bernd Schmidt  wrote:
>> Shrink-wrapping tests on ARM had one additional failure, which I could
>> track down to a stmfd instruction being emitted where an stmhifd was
>> intended. The following patch fixes the testcase; full tests running
>> now. Ok?
> 
> IIUC this should have been a result of conditionalizing the prologue
> saves by the CCFSM state machine in ARM state

Correct.

> given that the push
> instruction below doesn't have the conditional markers.

Although I'm not sure how you arrived at this? Thumb insns can't be
conditional anyway?

>  In which case
> the routines to emit the asm for the VFP registers( vfp_output_fstmfd?
> ) should also be checked for this issue.

Hmm, ok. I found two more places which looked suspicious. New version,
untested so far. What's "sfmfd"? That doesn't occur in my manual.


Bernd
* config/arm/arm.md (push_multi): Emit predicates.
(push_fp_multi): Likewise.
* config/arm/arm.c (vfp_output_fstmd): Likewise.
Index: gcc/config/arm/arm.c
===
--- gcc/config/arm/arm.c(revision 178135)
+++ gcc/config/arm/arm.c(working copy)
@@ -13084,7 +13096,7 @@ vfp_output_fstmd (rtx * operands)
   int base;
   int i;
 
-  strcpy (pattern, "fstmfdd\t%m0!, {%P1");
+  strcpy (pattern, "fstmfdd%?\t%m0!, {%P1");
   p = strlen (pattern);
 
   gcc_assert (GET_CODE (operands[1]) == REG);
Index: gcc/config/arm/arm.md
===
--- gcc/config/arm/arm.md   (revision 178135)
+++ gcc/config/arm/arm.md   (working copy)
@@ -10581,14 +10581,14 @@ (define_insn "*push_multi"
In Thumb mode always use push, and the assembler will pick
something appropriate.  */
 if (num_saves == 1 && TARGET_ARM)
-  output_asm_insn (\"str\\t%1, [%m0, #-4]!\", operands);
+  output_asm_insn (\"str%?\\t%1, [%m0, #-4]!\", operands);
 else
   {
int i;
char pattern[100];
 
if (TARGET_ARM)
-   strcpy (pattern, \"stmfd\\t%m0!, {%1\");
+   strcpy (pattern, \"stm%(fd%)\\t%m0!, {%1\");
else
strcpy (pattern, \"push\\t{%1\");
 
@@ -10631,7 +10631,7 @@ (define_insn "*push_fp_multi"
   {
 char pattern[100];
 
-sprintf (pattern, \"sfmfd\\t%%1, %d, [%%m0]!\", XVECLEN (operands[2], 0));
+sprintf (pattern, \"sfm%(fd%)\\t%%1, %d, [%%m0]!\", XVECLEN (operands[2], 
0));
 output_asm_insn (pattern, operands);
 return \"\";
   }"


[PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Richard Guenther

This fixes the Ada bootstrap failure introduced by alloca folding.
We now fold alloca (0) to &auto-with-size-zero which confuses us.
I didn't exactly investigate but what I think happens is that we
expand that &auto-with-size-zero to NULL instead of
virtual_stack_dynamic_rtx (see zero-size special-case in
allocate_dynamic_stack_space) and Ada ends up dereferencing the
pointer returned from alloca (0) (something to investigate for
the Ada folks I guess), something which "works" if we just
return a random stack address.

The following patch restores previous behavior by simply not
folding alloca (0).

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

Richard.

2011-09-02  Richard Guenther  

* tree-ssa-ccp.c (fold_builtin_alloca_for_var): Do not
fold alloca (0).
(ccp_fold_stmt): Continue replacing args when folding
alloca fails.

Index: gcc/tree-ssa-ccp.c
===
--- gcc/tree-ssa-ccp.c  (revision 178460)
+++ gcc/tree-ssa-ccp.c  (working copy)
@@ -1702,10 +1687,14 @@ fold_builtin_alloca_for_var (gimple stmt
 
   /* Detect constant argument.  */
   arg = get_constant_value (gimple_call_arg (stmt, 0));
-  if (arg == NULL_TREE || TREE_CODE (arg) != INTEGER_CST
+  if (arg == NULL_TREE
+  || TREE_CODE (arg) != INTEGER_CST
   || !host_integerp (arg, 1))
 return NULL_TREE;
+
   size = TREE_INT_CST_LOW (arg);
+  if (size == 0)
+return NULL_TREE;
 
   /* Heuristic: don't fold large vlas.  */
   threshold = (unsigned HOST_WIDE_INT)PARAM_VALUE (PARAM_LARGE_STACK_FRAME);
@@ -1804,12 +1793,12 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi
 if (gimple_call_alloca_for_var_p (stmt))
   {
 tree new_rhs = fold_builtin_alloca_for_var (stmt);
-bool res;
-if (new_rhs == NULL_TREE)
-  return false;
-res = update_call_from_tree (gsi, new_rhs);
-gcc_assert (res);
-return true;
+if (new_rhs)
+ {
+   bool res = update_call_from_tree (gsi, new_rhs);
+   gcc_assert (res);
+   return true;
+ }
   }
 
/* Propagate into the call arguments.  Compared to replace_uses_in


Re: [PATCH] Change vcond to vcond

2011-09-02 Thread Uros Bizjak
On Fri, Sep 2, 2011 at 11:43 AM, Richard Guenther  wrote:

>> > > >> >> > Hmm.  But then I'd have to try emit an insn, right?  Currently
>> > > >> >> > the vectorizer simply looks for an optab handler ... the
>> > > >> >> > operands are not readily available (but their mode is known).
>> > > >> >> > So I'd create some fake regs, setup operands and call GEN_FCN
>> > > >> >> > on it?  If it succeds I'd have to delete emitted insns, etc.
>> > > >> >> > Or I could add a target hook ...
>> > > >> >>
>> > > >> >> Hm... indeed, too much complication...
>> > > >> >>
>> > > >> >> I'd say, let's go with modeless operands and a target hook. IMO, 
>> > > >> >> this
>> > > >> >> is much more flexible than checking optab for supported modes.
>> > > >> >> Existing way is appropriate for single mode patterns, but we have
>> > > >> >> interdependent modes here, at least on x86.
>> > > >> >>
>> > > >> >> The hook would have two input arguments, insn mode and compare 
>> > > >> >> mode,
>> > > >> >> where the hook returns suggested supported compare mode, or no 
>> > > >> >> mode,
>> > > >> >> if it really can't handle requested modes.
>> > > >> >
>> > > >> > I think a two mode vcond pattern is in fact much cleaner than
>> > > >> > a one mode + modeless pattern which gen* will complain about and
>> > > >> > a target hook.
>> > > >>
>> > > >> OK, but in this case, do not use mode iterators too much in order to
>> > > >> avoid invalid patterns.
>> > > >
>> > > > I don't see them as "invalid".  They will be unused (maybe combine
>> > > > would create them though?), but they have well-defined semantics
>> > > > with my proposed documentation.  And x86 can handle them just fine.
>> > >
>> > > OK, let's go this way then... We can clean up this later if at all.
>> >
>> > Certainly what I prefer (less work for me now) ;)  The smallest
>> > number of patterns would probably result from using vcond
>> > to cover the same-mode cases and then add the 12 other patterns
>> > with the respective integer / float mode variant.  Thus we'd have
>> > 15 patterns in total (still much for my taste).
>> >
>> > Ideally we could have a mode attribute that would map possibly
>> > to an iterator, thus
>> >
>> > (define_mode_attr matching [(V4SF ["V4SF" "V4SI"]) (V8HI "V8HI") ...])
>> >
>> > or similar.  But I don't feel like adding this sort of mode
>> > attr that really is a hidden iterator ... ;)
>> >
>> > Thus, the following is the combined patch which bootstrapped and
>> > tested ok on x86_64-unknown-linux-gnu with {,-m32} over night,
>> > with the documentation for vcond added.
>> >
>> > Ok for trunk?
>>
>> I'm re-testing with the patterns having an extra condition like
>>    && (GET_MODE_NUNITS (mode)
>>        == GET_MODE_NUNITS (mode))"
>> to have the HAVE_vcond* defines easily optimized.
>>
>> Ok?
>
> Ping.  I'd like to have approval for the x86 changes.

OK.

Thanks,
Uros.


[PATCH] Enable IPA-CP on functions with variable number of arguments or type attributes

2011-09-02 Thread Martin Jambor
Hi,

currently IPA-CP switches itself off on functions with are called with
variable number of arguments or on those whose signature cannot be
changed because of type attributes.  This patch turns it on for both,
not changing the parameters of its clones in the latter case.

Whether the function's signature can be changed is determined by
looking at node->local.can_change_signature which is set appropriately
already since my last patch (rev 178386).

This patch also replaces ipa-prop's own node_versionable flag with
inline_summary (node)->versionable.  Frankly, I find it very confusing
that this flag is in the inline summary even though it is set in
ipa-prop (except for thunks - a case we currently never care about
anyway) and used only in ipa-cp.  I also think this is a property of
the node (rather than an inlining parameter) as much as
can_change_signature is - would a patch moving it to node->local be
acceptable?

The patch passes bootstrap and testsuite on x86_64-linux.  It also
successfully LTO-builds 465.tonto where it creates 647 clones (498 of
them replacing the original function completely) without changing the
signature of a single one.  (No change in the run-time on this
benchmark, though).

OK for trunk?

Thanks,

Martin



2011-09-01  Martin Jambor  

* ipa-prop.h (ipa_node_params): Removed fields
called_with_var_arguments and node_versionable.
(ipa_set_called_with_variable_arg): Removed.
(ipa_is_called_with_var_arguments): Likewise.
* ipa-cp.c (ipa_get_lattice): Fixed index check in an assert.
(determine_versionability): Do not check for type attributes and va
builtins.  Record versionability into inline summary.
(initialize_node_lattices): Do not check
ipa_is_called_with_var_arguments.
(propagate_constants_accross_call): Likewise, ignore arguments we do
not have PARM_DECLs for, set variable flag for parameters that were
not passed a value.
(create_specialized_node): Dump info that we cannot change signature.
* ipa-prop.c (ipa_compute_jump_functions): Do not care about variable
number of arguments.
(ipa_make_edge_direct_to_target): Likewise.
(ipa_update_after_lto_read): Likewise.
(ipa_node_duplication_hook): Do not copy called_with_var_arguments flag.
* tree-inline.c (copy_arguments_for_versioning): Copy PARM_DECLs if
they were remapped.

* testsuite/gcc.dg/ipa/ipcp-3.c: New test.

Index: src/gcc/ipa-cp.c
===
--- src.orig/gcc/ipa-cp.c
+++ src/gcc/ipa-cp.c
@@ -221,7 +221,7 @@ static struct ipcp_value *values_topo;
 static inline struct ipcp_lattice *
 ipa_get_lattice (struct ipa_node_params *info, int i)
 {
-  gcc_assert (i >= 0 && i <= ipa_get_param_count (info));
+  gcc_assert (i >= 0 && i < ipa_get_param_count (info));
   gcc_checking_assert (!info->ipcp_orig_node);
   gcc_checking_assert (info->lattices);
   return &(info->lattices[i]);
@@ -360,7 +360,6 @@ print_all_lattices (FILE * f, bool dump_
 static void
 determine_versionability (struct cgraph_node *node)
 {
-  struct cgraph_edge *edge;
   const char *reason = NULL;
 
   /* There are a number of generic reasons functions cannot be versioned.  We
@@ -369,32 +368,15 @@ determine_versionability (struct cgraph_
   if (node->alias || node->thunk.thunk_p)
 reason = "alias or thunk";
   else if (!inline_summary (node)->versionable)
-reason = "inliner claims it is so";
-  else if (TYPE_ATTRIBUTES (TREE_TYPE (node->decl)))
-reason = "there are type attributes";
+reason = "not a tree_versionable_function";
   else if (cgraph_function_body_availability (node) <= AVAIL_OVERWRITABLE)
 reason = "insufficient body availability";
-  else
-/* Removing arguments doesn't work if the function takes varargs
-   or use __builtin_apply_args.
-   FIXME: handle this together with can_change_signature flag.  */
-for (edge = node->callees; edge; edge = edge->next_callee)
-  {
-   tree t = edge->callee->decl;
-   if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
-   && (DECL_FUNCTION_CODE (t) == BUILT_IN_APPLY_ARGS
-   || DECL_FUNCTION_CODE (t) == BUILT_IN_VA_START))
- {
-   reason = "prohibitive builtins called";
-   break;
- };
-  }
 
   if (reason && dump_file && !node->alias && !node->thunk.thunk_p)
 fprintf (dump_file, "Function %s/%i is not versionable, reason: %s.\n",
 cgraph_node_name (node), node->uid, reason);
 
-  IPA_NODE_REF (node)->node_versionable = (reason == NULL);
+  inline_summary (node)->versionable = (reason == NULL);
 }
 
 /* Return true if it is at all technically possible to create clones of a
@@ -403,7 +385,7 @@ determine_versionability (struct cgraph_
 static bool
 ipcp_versionable_function_p (struct cgraph_node *node)
 {
-  return IPA_NODE_REF (node)->node_versionable;
+  return inline_summar

Re: [PATCH, PR 49886] Prevent fnsplit from changing signature when there are type attributes

2011-09-02 Thread Martin Jambor
Hi,

On Wed, Aug 31, 2011 at 09:33:03AM +0200, Richard Guenther wrote:
> On Tue, Aug 30, 2011 at 6:50 PM, Martin Jambor  wrote:
> > Ping.  Re-bootstrapped and re-tested yesterday on x86_64-linux.
> 
> Ok.  Does this also apply (maybe in modifed form) to the 4.6 branch?
> 

Below is a modified patch for the 4.6 branch.  It already has the fix
for PR 50260 that my trunk patch introduced and its testcase.  It also
makes ipa-split test for type attributes itself rather than doing it
in ipa-inline-analysis.c because there is no such file in 4.6 and I
did not want to change meaning of flags on the branch.

Bootstrapped and tested on x86_64-linux, OK for the branch?

Thanks,

Martin



2011-09-01  Martin Jambor  

PR middle-end/49886
* ipa-split.c (split_function): Do not skip any arguments if
can_change_signature is set or there are function type attributes.

* testsuite/gcc.c-torture/execute/pr49886.c: New testcase.
* testsuite/gfortran.fortran-torture/compile/pr50260.f90: Likewise.

Index: gcc/testsuite/gcc.c-torture/execute/pr49886.c
===
--- gcc/testsuite/gcc.c-torture/execute/pr49886.c   (revision 0)
+++ gcc/testsuite/gcc.c-torture/execute/pr49886.c   (revision 0)
@@ -0,0 +1,100 @@
+struct PMC {
+unsigned flags;
+};
+
+typedef struct Pcc_cell
+{
+struct PMC *p;
+long bla;
+long type;
+} Pcc_cell;
+
+int gi;
+int cond;
+
+extern void abort ();
+extern void never_ever(int interp, struct PMC *pmc)
+  __attribute__((noinline,noclone));
+
+void never_ever (int interp, struct PMC *pmc)
+{
+  abort ();
+}
+
+static void mark_cell(int * interp, Pcc_cell *c)
+  __attribute__((__nonnull__(1)));
+
+static void
+mark_cell(int * interp, Pcc_cell *c)
+{
+  if (!cond)
+return;
+
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<18)))
+never_ever(gi + 1, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<17)))
+never_ever(gi + 2, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<16)))
+never_ever(gi + 3, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<15)))
+never_ever(gi + 4, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<14)))
+never_ever(gi + 5, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<13)))
+never_ever(gi + 6, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<12)))
+never_ever(gi + 7, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<11)))
+never_ever(gi + 8, c->p);
+  if (c && c->type == 4 && c->p
+  && !(c->p->flags & (1<<10)))
+never_ever(gi + 9, c->p);
+}
+
+static void
+foo(int * interp, Pcc_cell *c)
+{
+  mark_cell(interp, c);
+}
+
+static struct Pcc_cell *
+__attribute__((noinline,noclone))
+getnull(void)
+{
+  return (struct Pcc_cell *) 0;
+}
+
+
+int main()
+{
+  int i;
+
+  cond = 1;
+  for (i = 0; i < 100; i++)
+foo (&gi, getnull ());
+  return 0;
+}
+
+
+void
+bar_1 (int * interp, Pcc_cell *c)
+{
+  c->bla += 1;
+  mark_cell(interp, c);
+}
+
+void
+bar_2 (int * interp, Pcc_cell *c)
+{
+  c->bla += 2;
+  mark_cell(interp, c);
+}
+
Index: gcc/testsuite/gfortran.fortran-torture/compile/pr50260.f90
===
--- gcc/testsuite/gfortran.fortran-torture/compile/pr50260.f90  (revision 0)
+++ gcc/testsuite/gfortran.fortran-torture/compile/pr50260.f90  (revision 0)
@@ -0,0 +1,48 @@
+MODULE cp_parser_methods
+  INTEGER, PARAMETER :: default_string_length=80
+  INTEGER, PARAMETER :: default_path_length=250
+  TYPE ilist_type
+ LOGICAL  :: in_use
+  END TYPE ilist_type
+  TYPE cp_parser_type
+ CHARACTER(LEN=default_path_length) :: ifn
+ INTEGER:: icol,icol1,icol2
+ TYPE(ilist_type), POINTER  :: ilist
+  END TYPE cp_parser_type
+  TYPE cp_error_type
+  END TYPE cp_error_type
+CONTAINS
+  FUNCTION cts(i) RESULT(res)
+CHARACTER(len=6) :: res
+  END FUNCTION cts
+  FUNCTION parser_location(parser,error) RESULT(res)
+TYPE(cp_parser_type), POINTER:: parser
+TYPE(cp_error_type), INTENT(inout)   :: error
+CHARACTER(len=default_path_length+default_string_length)   :: res
+LOGICAL  :: failure
+IF (.NOT. failure) THEN
+   res="file:'"//TRIM(parser%ifn)//"' line:"//cts(parser%icol)
+END IF
+  END FUNCTION parser_location
+  SUBROUTINE parser_get_integer(parser,at_end, error)
+TYPE(cp_parser_type), POINTER:: parser
+TYPE(cp_error_type), INTENT(inout)   :: error
+LOGICAL  :: failure, my_at_end
+IF (.NOT.failure) THEN
+   IF (.NOT.parser%ilist%in_use) THEN
+  CALL cp_assert("A"// TRIM(parser_location(parser,error)))
+   END IF
+END IF
+  END

[PATCH][Ada][C][C++] sizetypes no longer sign-extend

2011-09-02 Thread Richard Guenther

This patch makes us no longer treat unsigned sizetypes as sign-extending
which has caused trouble in the past (see the tree-ssa-ccp.c workarounds
removed below).

Most frontend specific changes below deal with the fact that overflow
behavior, as reported from size_binop, changes as unsigned sizetypes
now no longer overflow at SSIZETYPE_MAX but at USIZETYPE_MAX.  Diagnostics
expect warnings when overflow at half of the address-space occurs,
and Ada needs to pay special attention to its "negative" offsets,
all host_integerp (..., 1) checks have to be adjusted.

The patch bootstraps ok on x86_64-unknown-linux-gnu with all languages
enabled and tests with the following FAILs with {,-m32}:

Running target unix//-m32
FAIL: g++.dg/tree-ssa/pr19807.C scan-tree-dump-times optimized "\\+ 
0x0f*;" 1

still need to figure out how to properly quote that regexp for TCL
scanning for the various (sizetype)-1U printings ...

Running target unix/{,-m32}
FAIL: gcc.dg/pr42611.c  (test for errors, line 17)
FAIL: gcc.dg/pr42611.c (test for excess errors)

another missed overflow check, looking at it now

Running target unix/
FAIL: gnat.dg/array11.adb  (test for warnings, line 12)
FAIL: gnat.dg/object_overflow.adb  (test for warnings, line 8)

Running target unix//-m32
FAIL: gnat.dg/array11.adb  (test for warnings, line 12)
FAIL: gnat.dg/frame_overflow.adb  (test for errors, line 17)
FAIL: gnat.dg/frame_overflow.adb  (test for errors, line 24)
FAIL: gnat.dg/object_overflow.adb  (test for warnings, line 8)

probably similar, I pushed back Ada diagnostic tests for now,
but will look at them after resolving the above remaining FAIL.

Thus, I think the patch is ready to get review, adjustments, esp.
for the Ada pieces are welcome.

Thanks,
Richard.

2011-09-02  Richard Guenther  

* fold-const.c (div_if_zero_remainder): sizetypes no longer
sign-extend.
(int_const_binop_1): New worker for int_const_binop with
overflowable parameter.  Pass it through
to force_fit_type_double.
(int_const_binop): Wrap around int_const_binop_1 with overflowable
equal to one.
(size_binop_loc): Call int_const_binop_1 with overflowable equal
to minus one, forcing overflow detection for even unsigned types.
(fold_binary_loc): Call try_move_mult_to_index with signed offset.
* stor-layout.c (initialize_sizetypes): sizetypes no longer
sign-extend.
* tree-ssa-ccp.c (bit_value_unop_1): Likewise.
(bit_value_binop_1): Likewise.
* tree.c (double_int_to_tree): Likewise.
(double_int_fits_to_tree_p): Likewise.
(force_fit_type_double): Likewise.
(host_integerp): Likewise.
(int_fits_type_p): Likewise.
* varasm.c (assemble_variable): Adjust check for too large
variables by making sure the MSB of the size is not set.
(output_constructor_regular_field): Sign-extend the field-offset
to cater for negative offsets produced by the Ada frontend.
* omp-low.c (extract_omp_for_data): Convert the loop step to
signed for pointer adjustments.

c/
* c-decl.c (grokdeclarator): Properly check for sizes that
cover more than half of the address-space.

cp/
* decl.c (grokdeclarator): Properly check for sizes that
cover more than half of the address-space.

ada/
* gcc-interface/utils.c (rest_of_record_type_compilation): Check
for positive offsets with MSB not set.
(shift_unc_components_for_thin_pointers): Drop overflow bit
on negative offsets.

* g++.dg/tree-ssa/pr19807.C: Adjust.

Index: trunk/gcc/fold-const.c
===
*** trunk.orig/gcc/fold-const.c 2011-09-01 09:12:28.0 +0200
--- trunk/gcc/fold-const.c  2011-09-02 14:01:05.0 +0200
*** div_if_zero_remainder (enum tree_code co
*** 194,202 
   does the correct thing for POINTER_PLUS_EXPR where we want
   a signed division.  */
uns = TYPE_UNSIGNED (TREE_TYPE (arg2));
-   if (TREE_CODE (TREE_TYPE (arg2)) == INTEGER_TYPE
-   && TYPE_IS_SIZETYPE (TREE_TYPE (arg2)))
- uns = false;
  
quo = double_int_divmod (tree_to_double_int (arg1),
   tree_to_double_int (arg2),
--- 194,199 
*** int_binop_types_match_p (enum tree_code
*** 938,945 
 to produce a new constant.  Return NULL_TREE if we don't know how
 to evaluate CODE at compile-time.  */
  
! tree
! int_const_binop (enum tree_code code, const_tree arg1, const_tree arg2)
  {
double_int op1, op2, res, tmp;
tree t;
--- 935,943 
 to produce a new constant.  Return NULL_TREE if we don't know how
 to evaluate CODE at compile-time.  */
  
! static tree
! int_const_binop_1 (enum tree_code code, const_tree arg1, const_tree arg2,
!  int overflowable)
  {
double_int op1, op2, res, tmp;
tree t;

Re: [C++0x] contiguous bitfields race implementation

2011-09-02 Thread Aldy Hernandez



Note that with all this mess I'll re-iterate some of my initial thoughts.
1) why not do this C++ (or C) specific stuff in the frontends, maybe
at gimplifying/genericization time?  That way you wouldn't need to
worry about middle-end features but you could rely solely on what
C/C++ permit.  It is, after all, C++ _frontend_ semantics that we
enforce here, in the middle-end, which looks out-of-place.


The front-end, really?  After all this going back and forth?  After you 
were all so worried about Ada, and now you're ditching it in favor of 
handling only C++?



Is the C++ memory model stuff going to be "ready" for 4.7?


No, not if you expect me rewrite things every day.


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Arnaud Charlet
> This fixes the Ada bootstrap failure introduced by alloca folding.
> We now fold alloca (0) to &auto-with-size-zero which confuses us.
> I didn't exactly investigate but what I think happens is that we
> expand that &auto-with-size-zero to NULL instead of
> virtual_stack_dynamic_rtx (see zero-size special-case in
> allocate_dynamic_stack_space) and Ada ends up dereferencing the
> pointer returned from alloca (0) (something to investigate for
> the Ada folks I guess), something which "works" if we just
> return a random stack address.

Thanks!

In Ada, it's quite natural to end up with a dynamically sized object of
size 0. For instance, if you declare an array with a dynamic bound:

   Table : Unit_Table (1 .. Last_Unit);

and Last_Unit happens to be 0 at run-time

Arno


Re: [PATCH Atom][PR middle-end/44382] Tree reassociation improvement

2011-09-02 Thread Uros Bizjak
On Thu, Sep 1, 2011 at 12:27 PM, Ilya Enkovich  wrote:
>>
>> this seems to not allow cycles_best to drop with lower width, but
>> that it can't should be an implementation detail of get_required_cycles.
>> To make it not so, can you add a comment before the loop, like
>>
>>  /* get_required_cycles is monotonically increasing with lower width
>>     so we can perform a binary search for the minimal width that still
>>     results in the optimal cycle count.  */
>>
>
> Fixed. Thanks!
>
>>
>> With the above change the non-x86 specifc parts are ok.  Please get
>> approval for them from a x86 maintainer.
>>
>
> Could please someone review x86 part?

I assume that you need to split tune attribute to int and FP part to
handle reassociation for other targets, since Atom handles both in the
same way.

Please also describe function return value in the comment (and perhaps
in documentation, too).

OK with this addition.

Thanks,
Uros.


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Richard Guenther
On Fri, 2 Sep 2011, Arnaud Charlet wrote:

> > This fixes the Ada bootstrap failure introduced by alloca folding.
> > We now fold alloca (0) to &auto-with-size-zero which confuses us.
> > I didn't exactly investigate but what I think happens is that we
> > expand that &auto-with-size-zero to NULL instead of
> > virtual_stack_dynamic_rtx (see zero-size special-case in
> > allocate_dynamic_stack_space) and Ada ends up dereferencing the
> > pointer returned from alloca (0) (something to investigate for
> > the Ada folks I guess), something which "works" if we just
> > return a random stack address.
> 
> Thanks!
> 
> In Ada, it's quite natural to end up with a dynamically sized object of
> size 0. For instance, if you declare an array with a dynamic bound:
> 
>Table : Unit_Table (1 .. Last_Unit);
> 
> and Last_Unit happens to be 0 at run-time

But are we expected to read/store from the storage?  I'd have
expected that alloca (0) returning NULL shouldn't break
anything at runtime ...

Richard.


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Arnaud Charlet
> > In Ada, it's quite natural to end up with a dynamically sized object of
> > size 0. For instance, if you declare an array with a dynamic bound:
> > 
> >Table : Unit_Table (1 .. Last_Unit);
> > 
> > and Last_Unit happens to be 0 at run-time
> 
> But are we expected to read/store from the storage?

No, that shouldn't happen, although you can e.g. reference Table'Address
and expect it to be non null.

> I'd have
> expected that alloca (0) returning NULL shouldn't break
> anything at runtime ...

Not sure exactly what failed here, probably something relatively subtle
(perhaps related to passing this variable or a "slice" of this variable
to another procedure).

Arno


Re: [PATCH, PR 49886] Prevent fnsplit from changing signature when there are type attributes

2011-09-02 Thread Richard Guenther
On Fri, Sep 2, 2011 at 2:42 PM, Martin Jambor  wrote:
> Hi,
>
> On Wed, Aug 31, 2011 at 09:33:03AM +0200, Richard Guenther wrote:
>> On Tue, Aug 30, 2011 at 6:50 PM, Martin Jambor  wrote:
>> > Ping.  Re-bootstrapped and re-tested yesterday on x86_64-linux.
>>
>> Ok.  Does this also apply (maybe in modifed form) to the 4.6 branch?
>>
>
> Below is a modified patch for the 4.6 branch.  It already has the fix
> for PR 50260 that my trunk patch introduced and its testcase.  It also
> makes ipa-split test for type attributes itself rather than doing it
> in ipa-inline-analysis.c because there is no such file in 4.6 and I
> did not want to change meaning of flags on the branch.
>
> Bootstrapped and tested on x86_64-linux, OK for the branch?

Ok.

Thanks,
Richard.

> Thanks,
>
> Martin
>
>
>
> 2011-09-01  Martin Jambor  
>
>        PR middle-end/49886
>        * ipa-split.c (split_function): Do not skip any arguments if
>        can_change_signature is set or there are function type attributes.
>
>        * testsuite/gcc.c-torture/execute/pr49886.c: New testcase.
>        * testsuite/gfortran.fortran-torture/compile/pr50260.f90: Likewise.
>
> Index: gcc/testsuite/gcc.c-torture/execute/pr49886.c
> ===
> --- gcc/testsuite/gcc.c-torture/execute/pr49886.c       (revision 0)
> +++ gcc/testsuite/gcc.c-torture/execute/pr49886.c       (revision 0)
> @@ -0,0 +1,100 @@
> +struct PMC {
> +    unsigned flags;
> +};
> +
> +typedef struct Pcc_cell
> +{
> +    struct PMC *p;
> +    long bla;
> +    long type;
> +} Pcc_cell;
> +
> +int gi;
> +int cond;
> +
> +extern void abort ();
> +extern void never_ever(int interp, struct PMC *pmc)
> +  __attribute__((noinline,noclone));
> +
> +void never_ever (int interp, struct PMC *pmc)
> +{
> +  abort ();
> +}
> +
> +static void mark_cell(int * interp, Pcc_cell *c)
> +  __attribute__((__nonnull__(1)));
> +
> +static void
> +mark_cell(int * interp, Pcc_cell *c)
> +{
> +  if (!cond)
> +    return;
> +
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<18)))
> +    never_ever(gi + 1, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<17)))
> +    never_ever(gi + 2, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<16)))
> +    never_ever(gi + 3, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<15)))
> +    never_ever(gi + 4, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<14)))
> +    never_ever(gi + 5, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<13)))
> +    never_ever(gi + 6, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<12)))
> +    never_ever(gi + 7, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<11)))
> +    never_ever(gi + 8, c->p);
> +  if (c && c->type == 4 && c->p
> +      && !(c->p->flags & (1<<10)))
> +    never_ever(gi + 9, c->p);
> +}
> +
> +static void
> +foo(int * interp, Pcc_cell *c)
> +{
> +  mark_cell(interp, c);
> +}
> +
> +static struct Pcc_cell *
> +__attribute__((noinline,noclone))
> +getnull(void)
> +{
> +  return (struct Pcc_cell *) 0;
> +}
> +
> +
> +int main()
> +{
> +  int i;
> +
> +  cond = 1;
> +  for (i = 0; i < 100; i++)
> +    foo (&gi, getnull ());
> +  return 0;
> +}
> +
> +
> +void
> +bar_1 (int * interp, Pcc_cell *c)
> +{
> +  c->bla += 1;
> +  mark_cell(interp, c);
> +}
> +
> +void
> +bar_2 (int * interp, Pcc_cell *c)
> +{
> +  c->bla += 2;
> +  mark_cell(interp, c);
> +}
> +
> Index: gcc/testsuite/gfortran.fortran-torture/compile/pr50260.f90
> ===
> --- gcc/testsuite/gfortran.fortran-torture/compile/pr50260.f90  (revision 0)
> +++ gcc/testsuite/gfortran.fortran-torture/compile/pr50260.f90  (revision 0)
> @@ -0,0 +1,48 @@
> +MODULE cp_parser_methods
> +  INTEGER, PARAMETER :: default_string_length=80
> +  INTEGER, PARAMETER :: default_path_length=250
> +  TYPE ilist_type
> +     LOGICAL                              :: in_use
> +  END TYPE ilist_type
> +  TYPE cp_parser_type
> +     CHARACTER(LEN=default_path_length)             :: ifn
> +     INTEGER                                        :: icol,icol1,icol2
> +     TYPE(ilist_type), POINTER                      :: ilist
> +  END TYPE cp_parser_type
> +  TYPE cp_error_type
> +  END TYPE cp_error_type
> +CONTAINS
> +  FUNCTION cts(i) RESULT(res)
> +    CHARACTER(len=6)                         :: res
> +  END FUNCTION cts
> +  FUNCTION parser_location(parser,error) RESULT(res)
> +    TYPE(cp_parser_type), POINTER            :: parser
> +    TYPE(cp_error_type), INTENT(inout)       :: error
> +    CHARACTER(len=default_path_length+default_string_length)       :: res
> +    LOGICAL                                  :: failure
> +    IF (.NOT. failure) THEN
> +       res="file:'"//TRIM(parser%ifn)//"' line:"//cts(parser%icol)
> +    END IF
> +  END FUNCTION parser_location
> +  SUBROUTINE pa

Re: [C++0x] contiguous bitfields race implementation

2011-09-02 Thread Richard Guenther
On Fri, Sep 2, 2011 at 2:49 PM, Aldy Hernandez  wrote:
>
>> Note that with all this mess I'll re-iterate some of my initial thoughts.
>> 1) why not do this C++ (or C) specific stuff in the frontends, maybe
>> at gimplifying/genericization time?  That way you wouldn't need to
>> worry about middle-end features but you could rely solely on what
>> C/C++ permit.  It is, after all, C++ _frontend_ semantics that we
>> enforce here, in the middle-end, which looks out-of-place.
>
> The front-end, really?  After all this going back and forth?

Well, I'm fine with handling it in the middle-end if it's correct there.

> After you were
> all so worried about Ada, and now you're ditching it in favor of handling
> only C++?

I'm just showing you a possible solution for where you'd not need to
worry ;)  Consider LTOing an Ada and a C++ module - you need to
enable the C++ memory model at link-time so it is in effect when we
process bit-fields.  That will automatically enable it for the Ada pieces, too.

>> Is the C++ memory model stuff going to be "ready" for 4.7?
>
> No, not if you expect me rewrite things every day.

I don't expect you to rewrite things every day.

Don't read every comment I make as a definite decision and order to
you.  I am a mere mortal, too, and the bitfield thing is, I must admit,
still partially a mystery to myself (which is why I keep asking questions
instead of simply providing you with definite answers).  After all I pushed
back my idea of lowering bitfield accesses somewhere on GIMPLE and
I'm not sure if I get back to it for 4.7.  And I definitely would consider
2) for that work.

Btw, it would be nice if I weren't the only one reading your updated
patches :/  I'm just punching holes where I see them and hope I and
you learn something in that process.

Richard.


Re: [PATCH Atom][PR middle-end/44382] Tree reassociation improvement

2011-09-02 Thread Richard Guenther
On Fri, Sep 2, 2011 at 2:52 PM, Uros Bizjak  wrote:
> On Thu, Sep 1, 2011 at 12:27 PM, Ilya Enkovich  wrote:
>>>
>>> this seems to not allow cycles_best to drop with lower width, but
>>> that it can't should be an implementation detail of get_required_cycles.
>>> To make it not so, can you add a comment before the loop, like
>>>
>>>  /* get_required_cycles is monotonically increasing with lower width
>>>     so we can perform a binary search for the minimal width that still
>>>     results in the optimal cycle count.  */
>>>
>>
>> Fixed. Thanks!
>>
>>>
>>> With the above change the non-x86 specifc parts are ok.  Please get
>>> approval for them from a x86 maintainer.
>>>
>>
>> Could please someone review x86 part?
>
> I assume that you need to split tune attribute to int and FP part to
> handle reassociation for other targets, since Atom handles both in the
> same way.
>
> Please also describe function return value in the comment (and perhaps
> in documentation, too).
>
> OK with this addition.

Btw, I would expect integer add and integer multiply to have different
settings for some targets which would mean splitting this up even
further ...

Richard.

> Thanks,
> Uros.
>


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Robert Dewar

On 9/2/2011 8:52 AM, Arnaud Charlet wrote:


Thanks!

In Ada, it's quite natural to end up with a dynamically sized object of
size 0. For instance, if you declare an array with a dynamic bound:

Table : Unit_Table (1 .. Last_Unit);

and Last_Unit happens to be 0 at run-time

Arno


But isn't it odd that we would dereference such an address?


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Richard Guenther
On Fri, 2 Sep 2011, Arnaud Charlet wrote:

> > > In Ada, it's quite natural to end up with a dynamically sized object of
> > > size 0. For instance, if you declare an array with a dynamic bound:
> > > 
> > >Table : Unit_Table (1 .. Last_Unit);
> > > 
> > > and Last_Unit happens to be 0 at run-time
> > 
> > But are we expected to read/store from the storage?
> 
> No, that shouldn't happen, although you can e.g. reference Table'Address
> and expect it to be non null.

Ah, ok.  That we'd definitely broke.

> > I'd have
> > expected that alloca (0) returning NULL shouldn't break
> > anything at runtime ...
> 
> Not sure exactly what failed here, probably something relatively subtle
> (perhaps related to passing this variable or a "slice" of this variable
> to another procedure).

Hm, maybe we've expanded a block-move of size zero in some funny way.
The bootstrap fail can probably be reproduced with

Index: gcc/explow.c
===
--- gcc/explow.c(revision 178465)
+++ gcc/explow.c(working copy)
@@ -1159,7 +1159,7 @@ allocate_dynamic_stack_space (rtx size,
  to since we can't dereference it.  But return a reasonable
  address anyway.  */
   if (size == const0_rtx)
-return virtual_stack_dynamic_rtx;
+return const0_rtx;
 
   /* Otherwise, show we're calling alloca or equivalent.  */
   cfun->calls_alloca = 1;

Richard.


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Robert Dewar

On 9/2/2011 8:58 AM, Arnaud Charlet wrote:

In Ada, it's quite natural to end up with a dynamically sized object of
size 0. For instance, if you declare an array with a dynamic bound:

Table : Unit_Table (1 .. Last_Unit);

and Last_Unit happens to be 0 at run-time


But are we expected to read/store from the storage?


No, that shouldn't happen, although you can e.g. reference Table'Address
and expect it to be non null.


Actually I am not sure of this, I discussed this with Bob, Address
is defined as the pointing to the first storage unit allocated for
an object. Not clear what this means when the object has no storage
units. This is a gap in the RM. Bob's view is that it must return
some random valid address (what exactly *is* a valid address?)



I'd have
expected that alloca (0) returning NULL shouldn't break
anything at runtime ...


Not sure exactly what failed here, probably something relatively subtle
(perhaps related to passing this variable or a "slice" of this variable
to another procedure).


But that wouldn't cause a dereference, however, it might cause an
explicit test that the argument was not null, and perhaps that's
what is causing the trouble.

For example, if you have something like

type S is aliased array (1 .. N);
type P is access all S;
B : S;

procedure Q is (A : not null Astring) is
begin
   null;
end;

Q (B'Access);

Then there will be an explicit check that B is not null






Arno




Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Richard Guenther
On Fri, 2 Sep 2011, Robert Dewar wrote:

> On 9/2/2011 8:58 AM, Arnaud Charlet wrote:
> > > > In Ada, it's quite natural to end up with a dynamically sized object of
> > > > size 0. For instance, if you declare an array with a dynamic bound:
> > > > 
> > > > Table : Unit_Table (1 .. Last_Unit);
> > > > 
> > > > and Last_Unit happens to be 0 at run-time
> > > 
> > > But are we expected to read/store from the storage?
> > 
> > No, that shouldn't happen, although you can e.g. reference Table'Address
> > and expect it to be non null.
> 
> Actually I am not sure of this, I discussed this with Bob, Address
> is defined as the pointing to the first storage unit allocated for
> an object. Not clear what this means when the object has no storage
> units. This is a gap in the RM. Bob's view is that it must return
> some random valid address (what exactly *is* a valid address?)
> > 
> > > I'd have
> > > expected that alloca (0) returning NULL shouldn't break
> > > anything at runtime ...
> > 
> > Not sure exactly what failed here, probably something relatively subtle
> > (perhaps related to passing this variable or a "slice" of this variable
> > to another procedure).
> 
> But that wouldn't cause a dereference, however, it might cause an
> explicit test that the argument was not null, and perhaps that's
> what is causing the trouble.
> 
> For example, if you have something like
> 
> type S is aliased array (1 .. N);
> type P is access all S;
> B : S;
> 
> procedure Q is (A : not null Astring) is
> begin
>null;
> end;
> 
> Q (B'Access);
> 
> Then there will be an explicit check that B is not null

The bootstrap failure showed NULL pointer dereferences (which
probably easily points to the affected part of the RTS).

Richard.


Re: [PATCH] Remove bogus TYPE_IS_SIZETYPE special-casing in extract_muldiv_1

2011-09-02 Thread Eric Botcazou
> But they _do_ overflow as my debugging showed, caused by that exact
> same extract_muldiv_1 function here:
>
> case PLUS_EXPR:  case MINUS_EXPR:
>   /* See if we can eliminate the operation on both sides.  If we can,
> we
>  can return a new PLUS or MINUS.  If we can't, the only remaining
>  cases where we can do anything are if the second operand is a
>  constant.  */
> ...
>   /* If this was a subtraction, negate OP1 and set it to be an
> addition.
>  This simplifies the logic below.  */
>   if (tcode == MINUS_EXPR)
> {
>   tcode = PLUS_EXPR, op1 = negate_expr (op1);
>
> the unconditional negation of op1 for tcode == MINUS_EXPR overflows
> all sizetype values (well, all unsigned values).

Only if sizetypes are no longer sign-extended, though; otherwise, I don't see 
the problem (and we certainly never detected one).  Does something really go 
wrong with the unpatched compiler?

> Please please add some _testcases_ then that would fail when I test
> this kind of patches.

Performance testcases are hard to extract beforehand.  It's only when you have 
a regression that you really start to dig.

> The patch fixed a real bug (it's just that it is hard (for me) to
> produce testcases that involve sizetype computations - it always
> requires Ada to expose those bugs).  So, I beg to differ.

Well, on the one hand you ask for testcases in difficult cases, and on the 
other hand you don't provide one when you already have something at hand.

The elimination of the sign-extension for sizetypes is probably a progress 
overall, although this will very likely cause a few problems in Ada.  But 
removing working code (albeit admittedly hard to grasp) without testcases or 
real experiments is a different thing.

-- 
Eric Botcazou


[v3] Improve std::bitset::all

2011-09-02 Thread Paolo Carlini

Hi,

tested x86_64-linux multilib, a nice improvement joint work with Marc. 
Mainline only of course.


Thanks,
Paolo.

/
2011-09-02  Paolo Carlini  
Marc Glisse  

* include/std/bitset (_Base_bitset<>::_M_are_all_aux): Remove.
(_Base_bitset<>::_M_are_all): Add.
(bitset<>::all): Use the latter, improve implementation.
Index: include/std/bitset
===
--- include/std/bitset  (revision 178463)
+++ include/std/bitset  (working copy)
@@ -185,15 +185,17 @@
return true;
   }
 
-  size_t
-  _M_are_all_aux() const _GLIBCXX_NOEXCEPT
-  {
-   for (size_t __i = 0; __i < _Nw - 1; __i++)
- if (_M_w[__i] != ~static_cast<_WordT>(0))
-   return 0;
-   return ((_Nw - 1) * _GLIBCXX_BITSET_BITS_PER_WORD
-   + __builtin_popcountl(_M_hiword()));
-  }
+  template
+bool
+_M_are_all() const _GLIBCXX_NOEXCEPT
+{
+ for (size_t __i = 0; __i < _Nw - 1; __i++)
+   if (_M_w[__i] != ~static_cast<_WordT>(0))
+ return false;
+ return _M_hiword() == (~static_cast<_WordT>(0)
+>> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
+- _Nb));
+   }
 
   bool
   _M_is_any() const _GLIBCXX_NOEXCEPT
@@ -460,9 +462,11 @@
   _M_is_equal(const _Base_bitset<1>& __x) const _GLIBCXX_NOEXCEPT
   { return _M_w == __x._M_w; }
 
-  size_t
-  _M_are_all_aux() const _GLIBCXX_NOEXCEPT
-  { return __builtin_popcountl(_M_w); }
+  template
+bool
+_M_are_all() const _GLIBCXX_NOEXCEPT
+{ return _M_w == (~static_cast<_WordT>(0)
+ >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
 
   bool
   _M_is_any() const _GLIBCXX_NOEXCEPT
@@ -605,9 +609,10 @@
   _M_is_equal(const _Base_bitset<0>&) const _GLIBCXX_NOEXCEPT
   { return true; }
 
-  size_t
-  _M_are_all_aux() const _GLIBCXX_NOEXCEPT
-  { return 0; }
+  template
+bool
+_M_are_all() const _GLIBCXX_NOEXCEPT
+{ return true; }
 
   bool
   _M_is_any() const _GLIBCXX_NOEXCEPT
@@ -1312,7 +1317,7 @@
*/
   bool
   all() const _GLIBCXX_NOEXCEPT
-  { return this->_M_are_all_aux() == _Nb; }
+  { return this->template _M_are_all<_Nb>(); }
 
   /**
*  @brief Tests whether any of the bits are on.


Re: [PATCH] Remove bogus TYPE_IS_SIZETYPE special-casing in extract_muldiv_1

2011-09-02 Thread Richard Guenther
On Fri, 2 Sep 2011, Eric Botcazou wrote:

> > But they _do_ overflow as my debugging showed, caused by that exact
> > same extract_muldiv_1 function here:
> >
> > case PLUS_EXPR:  case MINUS_EXPR:
> >   /* See if we can eliminate the operation on both sides.  If we can,
> > we
> >  can return a new PLUS or MINUS.  If we can't, the only remaining
> >  cases where we can do anything are if the second operand is a
> >  constant.  */
> > ...
> >   /* If this was a subtraction, negate OP1 and set it to be an
> > addition.
> >  This simplifies the logic below.  */
> >   if (tcode == MINUS_EXPR)
> > {
> >   tcode = PLUS_EXPR, op1 = negate_expr (op1);
> >
> > the unconditional negation of op1 for tcode == MINUS_EXPR overflows
> > all sizetype values (well, all unsigned values).
> 
> Only if sizetypes are no longer sign-extended, though; otherwise, I don't see 
> the problem (and we certainly never detected one).  Does something really go 
> wrong with the unpatched compiler?

Well, even when sign-extended there is a constant you can't negate
without overflow.  I would start digging for a testcase with
such case - but as said, testcases involving TYPE_IS_SIZETYPE are
very hard to generate for me.

> > Please please add some _testcases_ then that would fail when I test
> > this kind of patches.
> 
> Performance testcases are hard to extract beforehand.  It's only when you 
> have 
> a regression that you really start to dig.

Well, but I'd expect you can have a set of Ada types, a function that
returns just its size and some scan-tree-dumps that check those sizes
are folded to a constant.  Or to just N statements.

I at least did verify that the case producing the error still folds
to a constant size, even after my patch.

> > The patch fixed a real bug (it's just that it is hard (for me) to
> > produce testcases that involve sizetype computations - it always
> > requires Ada to expose those bugs).  So, I beg to differ.
> 
> Well, on the one hand you ask for testcases in difficult cases, and on the 
> other hand you don't provide one when you already have something at hand.
> 
> The elimination of the sign-extension for sizetypes is probably a progress 
> overall, although this will very likely cause a few problems in Ada.  But 
> removing working code (albeit admittedly hard to grasp) without testcases or 
> real experiments is a different thing.

It definitely makes it easier to later point to this patch causing issues
compared to lumping all the "fixes" into the final patch, which, btw.
I just sent out.

If you insist I can revert the patch and apply it together with the
sign-extension change.

Richard.


Re: [PATCH] Make devirtualization use BINFO_VTABLE instead of BINFO_VIRTUALS

2011-09-02 Thread Martin Jambor
Hi,

On Thu, Sep 01, 2011 at 08:52:30PM +0200, Jan Hubicka wrote:
> > - Nevertheless, this method of devirtualization cannot automatically
> >   de-thunkize this-adjusting thunks and newly direct calls to them
> >   cannot be inlined because the inliner does not have this capability
> >   now.  This is in fact a regression from 4.6, and testcases
> >   ivinline-7.C and ivinline-9.C had to be XFAILed exactly for this
> >   reason.  The size of the memory savings and the fact that we do not
> >   devirtualize that much now make this an acceptable tradeoff, though.
> 
> OK, the "dethunkization" was ugly anyway.  I guess we will need to add support
> for handling thunks in inliner but that can go incrementally.

Do we actually have the offsets and indices necessary for
de-thunkization available somewhere in the middle end structures (with
BINFO_VIRTUALs being freed in free_lang_data now)?

> 
> > 2011-08-31  Martin Jambor  
> > 
> > * cgraph.h (cgraph_indirect_call_info): Removed field thunk_delta.
> > * gimple-fold.c (gimple_get_virt_method_for_binfo): Rewritten to use
> > BINFO_VTABLE.  Parameter delta removed, all callers updated.
> > * tree.c (free_lang_data_in_binfo): Clear BINFO_VIRTUALs instead
> > BINFO_VTABLE.
> > * cgraph.c (cgraph_make_edge_direct): Removed parameter delta, updated
> > all calls.
> > * cgraphunit.c (cgraph_redirect_edge_call_stmt_to_callee): Removed
> > handling of thunk_delta.
> > * ipa-cp.c (get_indirect_edge_target): Removed parameter delta.
> > (devirtualization_time_bonus): Do not handle thunk deltas.
> > (ipcp_discover_new_direct_edges): Likewise.
> > * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise.
> > (try_make_edge_direct_simple_call): Likewise.
> > (try_make_edge_direct_virtual_call): Likewise.
> > * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise.  Mark
> > parameter set as unused.
> > (output_edge_opt_summary): Likewise.  Mark both parameters as unused.
> > * lto-cgraph.c (output_cgraph_opt_summary_p): Likewise.  Mark
> > parameter set as unused.
> > (output_edge_opt_summary): Likewise.  Mark both parameters as unused.
> > (input_edge_opt_summary): Likewise.
> > * lto-streamer-out.c (lto_output_ts_binfo_tree_pointers): Do not stream
> > BINFO_VIRTUALS at all.
> > * lto-streamer-in.c (lto_input_ts_binfo_tree_pointers): Likewise.
> > 
> > * testsuite/g++.dg/ipa/devirt-3.C: Added a distraction method.
> > * testsuite/g++.dg/ipa/ivinline-7.C: Added a test for direct call
> > discovery, xfailed test for inlining.
> > * testsuite/g++.dg/ipa/ivinline-9.C: Likewise.
> 
> The cgraph bits of the patch are OK, but I will leave the gimple-fold bits 
> for Richi's approval.
> Can't we drop computation of BINFO_VIRTUALS from C++ FE completely now?
> 

I do not think so.  I do not really understand the FE but it seems
to me it is used internally to accumulate what needs to be in the VMT
which is then itself produced by iterating the list in
build_vtbl_initializer.  But I might be wrong. 

I have just committed the patch, thanks,

Martin


Re: [Patch, C] options generation and language count

2011-09-02 Thread Joseph S. Myers
On Thu, 1 Sep 2011, Gary Funck wrote:

> +# MAX_LANG is the maximum number of languages that can be defined.
> +# Its value is extracted from the value of CL_PARAMS in opts.h
> +# and is passed on the command line as '-v max_lang=...'.
> +if (n_langs > max_lang) {
> +  print "Error: the number of defined languages (" n_langs ") " \
> +"exceeds the maximum supported by this implementation " \
> + "(" max_lang ")" > "/dev/stderr"
> +  exit 2

Are you sure this /dev/stderr reference is portable?

I think this is trying to be too clever and you should just generate 
#if/#error in the output just like all the other error checks, and so not 
need to extract a value from a header with awk at all.

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


Re: [PATCH] Make devirtualization use BINFO_VTABLE instead of BINFO_VIRTUALS

2011-09-02 Thread Jan Hubicka
> Hi,
> 
> On Thu, Sep 01, 2011 at 08:52:30PM +0200, Jan Hubicka wrote:
> > > - Nevertheless, this method of devirtualization cannot automatically
> > >   de-thunkize this-adjusting thunks and newly direct calls to them
> > >   cannot be inlined because the inliner does not have this capability
> > >   now.  This is in fact a regression from 4.6, and testcases
> > >   ivinline-7.C and ivinline-9.C had to be XFAILed exactly for this
> > >   reason.  The size of the memory savings and the fact that we do not
> > >   devirtualize that much now make this an acceptable tradeoff, though.
> > 
> > OK, the "dethunkization" was ugly anyway.  I guess we will need to add 
> > support
> > for handling thunks in inliner but that can go incrementally.
> 
> Do we actually have the offsets and indices necessary for
> de-thunkization available somewhere in the middle end structures (with
> BINFO_VIRTUALs being freed in free_lang_data now)?

They live in cgraph, at least for thunks that has been finalized in current 
compilation
unit.  I wonder how much we care about de-thunkizing calls into other 
compilation unit,
but then C++ FE can just add the thunks into callgraph, too.

Honza


Re: [PATCH Atom][PR middle-end/44382] Tree reassociation improvement

2011-09-02 Thread Ilya Enkovich
2011/9/2 Richard Guenther :
>On Fri, Sep 2, 2011 at 2:52 PM, Uros Bizjak  wrote:
>>
>> I assume that you need to split tune attribute to int and FP part to
>> handle reassociation for other targets, since Atom handles both in the
>> same way.
>>
>> Please also describe function return value in the comment (and perhaps
>> in documentation, too).
>>
>> OK with this addition.
>
> Btw, I would expect integer add and integer multiply to have different
> settings for some targets which would mean splitting this up even
> further ...

Which tune attributes are meant here? Is it X86_TUNE_REASSOC_* flags
or new command line param?

Thanks,
Ilya
>
> Richard.
>
>> Thanks,
>> Uros.
>>
>


[PATCH] Print unsigned host-wide-int fitting INTEGER_CSTs regularly

2011-09-02 Thread Richard Guenther

without resorting to hex printing of both high/low values.

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

Richard.

2011-09-02  Richard Guenther  

* pretty-print.h (pp_unsigned_wide_integer): New.
* tree-pretty-print.c (dump_generic_node): Print unsigned
host-wide-int fitting INTEGER_CSTs with pp_unsigned_wide_integer.

Index: gcc/pretty-print.h
===
--- gcc/pretty-print.h  (revision 178465)
+++ gcc/pretty-print.h  (working copy)
@@ -276,6 +276,8 @@ struct pretty_print_info
 }\
   while (0)
 #define pp_decimal_int(PP, I)  pp_scalar (PP, "%d", I)
+#define pp_unsigned_wide_integer(PP, I) \
+   pp_scalar (PP, HOST_WIDE_INT_PRINT_UNSIGNED, (unsigned HOST_WIDE_INT) I)
 #define pp_wide_integer(PP, I) \
pp_scalar (PP, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) I)
 #define pp_widest_integer(PP, I) \
Index: gcc/tree-pretty-print.c
===
--- gcc/tree-pretty-print.c (revision 178465)
+++ gcc/tree-pretty-print.c (working copy)
@@ -1002,7 +1002,11 @@ dump_generic_node (pretty_printer *buffe
  pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
  pp_string (buffer, "B"); /* pseudo-unit */
}
-  else if (! host_integerp (node, 0))
+  else if (host_integerp (node, 0))
+   pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
+  else if (host_integerp (node, 1))
+   pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
+  else
{
  tree val = node;
  unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
@@ -1021,8 +1025,6 @@ dump_generic_node (pretty_printer *buffe
   (unsigned HOST_WIDE_INT) high, low);
  pp_string (buffer, pp_buffer (buffer)->digit_buffer);
}
-  else
-   pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
   break;
 
 case REAL_CST:


[v3] Trivial formatting fixes to

2011-09-02 Thread Paolo Carlini

Hi,

noticed over the last day or so, committed to mainline.

Paolo.

//
2011-09-02  Paolo Carlini  

* include/std/bitset: Trivial formatting fixes.
Index: include/std/bitset
===
--- include/std/bitset  (revision 178473)
+++ include/std/bitset  (working copy)
@@ -94,19 +94,19 @@
 #endif
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichword(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
   { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichbyte(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
   { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
   { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
   static _GLIBCXX_CONSTEXPR _WordT
-  _S_maskbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
   { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
   _WordT&
@@ -389,19 +389,19 @@
   { }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichword(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
   { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichbyte(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
   { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
   {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
   static _GLIBCXX_CONSTEXPR _WordT
-  _S_maskbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
   { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
   _WordT&
@@ -533,19 +533,19 @@
   { }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichword(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
   { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichbyte(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
   { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
   static _GLIBCXX_CONSTEXPR size_t
-  _S_whichbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
   {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
   static _GLIBCXX_CONSTEXPR _WordT
-  _S_maskbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+  _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
   { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
   // This would normally give access to the data.  The bounds-checking
@@ -650,17 +650,17 @@
 {
   typedef unsigned long _WordT;
 
-  static void 
+  static void
   _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
   { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
 };
 
   template<>
 struct _Sanitize<0>
-{ 
+{
   typedef unsigned long _WordT;
 
-  static void 
+  static void
   _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { } 
 };
 
@@ -1364,7 +1364,7 @@
*  @sa  _Find_first
*/
   size_t
-  _Find_next(size_t __prev ) const _GLIBCXX_NOEXCEPT
+  _Find_next(size_t __prev) const _GLIBCXX_NOEXCEPT
   { return this->_M_do_find_next(__prev, _Nb); }
 };
 


Re: [PATCH][Ada][C][C++] sizetypes no longer sign-extend

2011-09-02 Thread Joseph S. Myers
On Fri, 2 Sep 2011, Richard Guenther wrote:

>   * c-decl.c (grokdeclarator): Properly check for sizes that
>   cover more than half of the address-space.

The C front-end changes are OK.

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


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Robert Dewar

On 9/2/2011 9:16 AM, Richard Guenther wrote:


The bootstrap failure showed NULL pointer dereferences (which
probably easily points to the affected part of the RTS).


Might be interesting to pursue, but we don't know that the null
pointers being dereferenced are in fact the ones returned by
alloca. May not be worth the effort.


Re: [PATCH Atom][PR middle-end/44382] Tree reassociation improvement

2011-09-02 Thread Richard Guenther
On Fri, Sep 2, 2011 at 3:45 PM, Ilya Enkovich  wrote:
> 2011/9/2 Richard Guenther :
>>On Fri, Sep 2, 2011 at 2:52 PM, Uros Bizjak  wrote:
>>>
>>> I assume that you need to split tune attribute to int and FP part to
>>> handle reassociation for other targets, since Atom handles both in the
>>> same way.
>>>
>>> Please also describe function return value in the comment (and perhaps
>>> in documentation, too).
>>>
>>> OK with this addition.
>>
>> Btw, I would expect integer add and integer multiply to have different
>> settings for some targets which would mean splitting this up even
>> further ...
>
> Which tune attributes are meant here? Is it X86_TUNE_REASSOC_* flags
> or new command line param?

The X86_TUNE_REASSOC_* flags.  The setting surely depends on the
number of available execution units and/or whether the instructions
are pipelined or not.

Richard.


Re: [PATCH] Enable IPA-CP on functions with variable number of arguments or type attributes

2011-09-02 Thread Richard Guenther
On Fri, Sep 2, 2011 at 2:27 PM, Martin Jambor  wrote:
> Hi,
>
> currently IPA-CP switches itself off on functions with are called with
> variable number of arguments or on those whose signature cannot be
> changed because of type attributes.  This patch turns it on for both,
> not changing the parameters of its clones in the latter case.
>
> Whether the function's signature can be changed is determined by
> looking at node->local.can_change_signature which is set appropriately
> already since my last patch (rev 178386).
>
> This patch also replaces ipa-prop's own node_versionable flag with
> inline_summary (node)->versionable.  Frankly, I find it very confusing
> that this flag is in the inline summary even though it is set in
> ipa-prop (except for thunks - a case we currently never care about
> anyway) and used only in ipa-cp.  I also think this is a property of
> the node (rather than an inlining parameter) as much as
> can_change_signature is - would a patch moving it to node->local be
> acceptable?

I think so, or even node->global?

> The patch passes bootstrap and testsuite on x86_64-linux.  It also
> successfully LTO-builds 465.tonto where it creates 647 clones (498 of
> them replacing the original function completely) without changing the
> signature of a single one.  (No change in the run-time on this
> benchmark, though).
>
> OK for trunk?

Ok.

Thanks,
Richard.

> Thanks,
>
> Martin
>
>
>
> 2011-09-01  Martin Jambor  
>
>        * ipa-prop.h (ipa_node_params): Removed fields
>        called_with_var_arguments and node_versionable.
>        (ipa_set_called_with_variable_arg): Removed.
>        (ipa_is_called_with_var_arguments): Likewise.
>        * ipa-cp.c (ipa_get_lattice): Fixed index check in an assert.
>        (determine_versionability): Do not check for type attributes and va
>        builtins.  Record versionability into inline summary.
>        (initialize_node_lattices): Do not check
>        ipa_is_called_with_var_arguments.
>        (propagate_constants_accross_call): Likewise, ignore arguments we do
>        not have PARM_DECLs for, set variable flag for parameters that were
>        not passed a value.
>        (create_specialized_node): Dump info that we cannot change signature.
>        * ipa-prop.c (ipa_compute_jump_functions): Do not care about variable
>        number of arguments.
>        (ipa_make_edge_direct_to_target): Likewise.
>        (ipa_update_after_lto_read): Likewise.
>        (ipa_node_duplication_hook): Do not copy called_with_var_arguments 
> flag.
>        * tree-inline.c (copy_arguments_for_versioning): Copy PARM_DECLs if
>        they were remapped.
>
>        * testsuite/gcc.dg/ipa/ipcp-3.c: New test.
>
> Index: src/gcc/ipa-cp.c
> ===
> --- src.orig/gcc/ipa-cp.c
> +++ src/gcc/ipa-cp.c
> @@ -221,7 +221,7 @@ static struct ipcp_value *values_topo;
>  static inline struct ipcp_lattice *
>  ipa_get_lattice (struct ipa_node_params *info, int i)
>  {
> -  gcc_assert (i >= 0 && i <= ipa_get_param_count (info));
> +  gcc_assert (i >= 0 && i < ipa_get_param_count (info));
>   gcc_checking_assert (!info->ipcp_orig_node);
>   gcc_checking_assert (info->lattices);
>   return &(info->lattices[i]);
> @@ -360,7 +360,6 @@ print_all_lattices (FILE * f, bool dump_
>  static void
>  determine_versionability (struct cgraph_node *node)
>  {
> -  struct cgraph_edge *edge;
>   const char *reason = NULL;
>
>   /* There are a number of generic reasons functions cannot be versioned.  We
> @@ -369,32 +368,15 @@ determine_versionability (struct cgraph_
>   if (node->alias || node->thunk.thunk_p)
>     reason = "alias or thunk";
>   else if (!inline_summary (node)->versionable)
> -    reason = "inliner claims it is so";
> -  else if (TYPE_ATTRIBUTES (TREE_TYPE (node->decl)))
> -    reason = "there are type attributes";
> +    reason = "not a tree_versionable_function";
>   else if (cgraph_function_body_availability (node) <= AVAIL_OVERWRITABLE)
>     reason = "insufficient body availability";
> -  else
> -    /* Removing arguments doesn't work if the function takes varargs
> -       or use __builtin_apply_args.
> -       FIXME: handle this together with can_change_signature flag.  */
> -    for (edge = node->callees; edge; edge = edge->next_callee)
> -      {
> -       tree t = edge->callee->decl;
> -       if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
> -           && (DECL_FUNCTION_CODE (t) == BUILT_IN_APPLY_ARGS
> -               || DECL_FUNCTION_CODE (t) == BUILT_IN_VA_START))
> -         {
> -           reason = "prohibitive builtins called";
> -           break;
> -         };
> -      }
>
>   if (reason && dump_file && !node->alias && !node->thunk.thunk_p)
>     fprintf (dump_file, "Function %s/%i is not versionable, reason: %s.\n",
>             cgraph_node_name (node), node->uid, reason);
>
> -  IPA_NODE_REF (node)->node_versionable = (reason == NULL);
> +  inline_summary (node)->versionable = (reason == NULL);
>

Re: [C++0x] contiguous bitfields race implementation

2011-09-02 Thread Jason Merrill

On 09/02/2011 04:53 AM, Richard Guenther wrote:

On Thu, Sep 1, 2011 at 5:19 PM, Jason Merrill  wrote:

I think it would make sense to expose this information to the back end
somehow.  A hook would do the trick: call it type_data_size or type_min_size
or some such, which in the C++ front end would return TYPE_SIZE
(CLASSTYPE_AS_BASE (t)) for classes or just TYPE_SIZE for other types.


That's too late to work with LTO, you'd need to store that information
permanently somewhere.


OK.


Maybe move this whole C++ specific bitfield handling where it belongs,
namely to the C++ frontend?


I don't think that is the way to go; C is adopting the same memory 
model, and this is the only sane thing to do with bit-fields.



I suggest to always not re-use tail padding for now (I believe if your
parent object is a COMPONENT_REF, thus, x.parent.bitfield,
you can use the TYPE_SIZE vs. field-decl DECL_SIZE discrepancy
to decide about whether the tail-padding was reused, but please
double-check that ;)))


But you don't always have a COMPONENT_REF; you still need to avoid 
touching the tail padding when you just have a pointer to the type 
because it might be a base sub-object.


I wonder what would break if C++ just set TYPE_SIZE to the as-base size?

Jason


Re: [PATCH Atom][PR middle-end/44382] Tree reassociation improvement

2011-09-02 Thread Ilya Enkovich
2011/9/2 Richard Guenther :
> On Fri, Sep 2, 2011 at 3:45 PM, Ilya Enkovich  wrote:
>> 2011/9/2 Richard Guenther :
>>>On Fri, Sep 2, 2011 at 2:52 PM, Uros Bizjak  wrote:

 I assume that you need to split tune attribute to int and FP part to
 handle reassociation for other targets, since Atom handles both in the
 same way.

 Please also describe function return value in the comment (and perhaps
 in documentation, too).

 OK with this addition.
>>>
>>> Btw, I would expect integer add and integer multiply to have different
>>> settings for some targets which would mean splitting this up even
>>> further ...
>>
>> Which tune attributes are meant here? Is it X86_TUNE_REASSOC_* flags
>> or new command line param?
>
> The X86_TUNE_REASSOC_* flags.  The setting surely depends on the
> number of available execution units and/or whether the instructions
> are pipelined or not.

Now I'm not sure it is a good idea to use these tune flags at all
because we may need a plenty of them. We have a lot of types including
vector ones and a variety of opcodes. Any combination may require
delicate tuning. Some sort of separate table would suit better here.
Though I doubt we should introduce it right now filled with 1s.

Ilya

>
> Richard.
>


Re: [PATCH] Enable IPA-CP on functions with variable number of arguments or type attributes

2011-09-02 Thread Jan Hubicka
> On Fri, Sep 2, 2011 at 2:27 PM, Martin Jambor  wrote:
> > Hi,
> >
> > currently IPA-CP switches itself off on functions with are called with
> > variable number of arguments or on those whose signature cannot be
> > changed because of type attributes.  This patch turns it on for both,
> > not changing the parameters of its clones in the latter case.
> >
> > Whether the function's signature can be changed is determined by
> > looking at node->local.can_change_signature which is set appropriately
> > already since my last patch (rev 178386).
> >
> > This patch also replaces ipa-prop's own node_versionable flag with
> > inline_summary (node)->versionable.  Frankly, I find it very confusing
> > that this flag is in the inline summary even though it is set in
> > ipa-prop (except for thunks - a case we currently never care about
> > anyway) and used only in ipa-cp.  I also think this is a property of
> > the node (rather than an inlining parameter) as much as
> > can_change_signature is - would a patch moving it to node->local be
> > acceptable?
> 
> I think so, or even node->global?

It is function local property, so node->local.
I did the same with can_change_signature, so this is fine with me.  They ended 
up in inline
summaries only becuase they used to be computed there.

Honza


Re: [PATCH][Ada][C][C++] sizetypes no longer sign-extend

2011-09-02 Thread Richard Guenther
On Fri, 2 Sep 2011, Richard Guenther wrote:

> 
> This patch makes us no longer treat unsigned sizetypes as sign-extending
> which has caused trouble in the past (see the tree-ssa-ccp.c workarounds
> removed below).
> 
> Most frontend specific changes below deal with the fact that overflow
> behavior, as reported from size_binop, changes as unsigned sizetypes
> now no longer overflow at SSIZETYPE_MAX but at USIZETYPE_MAX.  Diagnostics
> expect warnings when overflow at half of the address-space occurs,
> and Ada needs to pay special attention to its "negative" offsets,
> all host_integerp (..., 1) checks have to be adjusted.
> 
> The patch bootstraps ok on x86_64-unknown-linux-gnu with all languages
> enabled and tests with the following FAILs with {,-m32}:
> 
> Running target unix//-m32
> FAIL: g++.dg/tree-ssa/pr19807.C scan-tree-dump-times optimized "\\+ 
> 0x0f*;" 1
> 
> still need to figure out how to properly quote that regexp for TCL
> scanning for the various (sizetype)-1U printings ...
> 
> Running target unix/{,-m32}
> FAIL: gcc.dg/pr42611.c  (test for errors, line 17)
> FAIL: gcc.dg/pr42611.c (test for excess errors)
> 
> another missed overflow check, looking at it now
> 
> Running target unix/
> FAIL: gnat.dg/array11.adb  (test for warnings, line 12)
> FAIL: gnat.dg/object_overflow.adb  (test for warnings, line 8)
> 
> Running target unix//-m32
> FAIL: gnat.dg/array11.adb  (test for warnings, line 12)
> FAIL: gnat.dg/frame_overflow.adb  (test for errors, line 17)
> FAIL: gnat.dg/frame_overflow.adb  (test for errors, line 24)
> FAIL: gnat.dg/object_overflow.adb  (test for warnings, line 8)
> 
> probably similar, I pushed back Ada diagnostic tests for now,
> but will look at them after resolving the above remaining FAIL.

gnat.dg/array11.adb and gnat.dg/object_overflow.adb are fixed
by the following.  Not sure what type to test TYPE_UNSIGNED on
though.  Possibly needs adjustment in c-comment.c:complete_array_type
to use ssize_int (-1) for the array[] = {...} case.

Comments?

Thanks,
Richard.

Index: trunk/gcc/stor-layout.c
===
--- trunk.orig/gcc/stor-layout.c2011-09-02 16:23:33.0 +0200
+++ trunk/gcc/stor-layout.c 2011-09-02 16:19:12.0 +0200
@@ -1959,16 +1959,14 @@ layout_type (tree type)
if (integer_zerop (element_size))
  length = size_zero_node;
 
-   /* The computation should happen in the original type so
+   /* The computation should happen in the original signedness so
   that (possible) negative values are handled appropriately.  */
else
  length
= fold_convert (sizetype,
-   fold_build2 (PLUS_EXPR, TREE_TYPE (lb),
-build_int_cst (TREE_TYPE (lb), 1),
-fold_build2 (MINUS_EXPR,
- TREE_TYPE (lb),
- ub, lb)));
+   size_binop (PLUS_EXPR,
+   build_int_cst (TREE_TYPE (lb), 1),
+   size_binop (MINUS_EXPR, ub, lb)));
 
TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
   fold_convert (bitsizetype,
Index: trunk/gcc/ada/gcc-interface/utils.c
===
--- trunk.orig/gcc/ada/gcc-interface/utils.c2011-09-02 16:23:33.0 
+0200
+++ trunk/gcc/ada/gcc-interface/utils.c 2011-09-02 16:22:20.0 +0200
@@ -1248,7 +1248,7 @@ copy_type (tree type)
   return new_type;
 }
 
-/* Return a subtype of sizetype with range MIN to MAX and whose
+/* Return a subtype of [s]sizetype with range MIN to MAX and whose
TYPE_INDEX_TYPE is INDEX.  GNAT_NODE is used for the position
of the associated TYPE_DECL.  */
 
@@ -1256,7 +1256,8 @@ tree
 create_index_type (tree min, tree max, tree index, Node_Id gnat_node)
 {
   /* First build a type for the desired range.  */
-  tree type = build_nonshared_range_type (sizetype, min, max);
+  tree type = build_nonshared_range_type (TYPE_UNSIGNED (index)
+ ? sizetype : ssizetype, min, max);
 
   /* Then set the index type.  */
   SET_TYPE_INDEX_TYPE (type, index);


Re: [C++0x] contiguous bitfields race implementation

2011-09-02 Thread Richard Guenther
On Fri, Sep 2, 2011 at 4:10 PM, Jason Merrill  wrote:
> On 09/02/2011 04:53 AM, Richard Guenther wrote:
>>
>> On Thu, Sep 1, 2011 at 5:19 PM, Jason Merrill  wrote:
>>>
>>> I think it would make sense to expose this information to the back end
>>> somehow.  A hook would do the trick: call it type_data_size or
>>> type_min_size
>>> or some such, which in the C++ front end would return TYPE_SIZE
>>> (CLASSTYPE_AS_BASE (t)) for classes or just TYPE_SIZE for other types.
>>
>> That's too late to work with LTO, you'd need to store that information
>> permanently somewhere.
>
> OK.
>
>> Maybe move this whole C++ specific bitfield handling where it belongs,
>> namely to the C++ frontend?
>
> I don't think that is the way to go; C is adopting the same memory model,
> and this is the only sane thing to do with bit-fields.
>
>> I suggest to always not re-use tail padding for now (I believe if your
>> parent object is a COMPONENT_REF, thus, x.parent.bitfield,
>> you can use the TYPE_SIZE vs. field-decl DECL_SIZE discrepancy
>> to decide about whether the tail-padding was reused, but please
>> double-check that ;)))
>
> But you don't always have a COMPONENT_REF; you still need to avoid touching
> the tail padding when you just have a pointer to the type because it might
> be a base sub-object.
>
> I wonder what would break if C++ just set TYPE_SIZE to the as-base size?

Good question.  Probably argument passing, as the as-base size wouldn't
get a proper mode assigned form layout_type then(?) for small structs?

Maybe worth a try ...

Richard.

> Jason
>


[ARM] PR target/49030: ICE in get_arm_condition_code

2011-09-02 Thread Richard Sandiford
CC_NCV rightly only allows GE(U) and LT(U).  GT(U) and LE(U) have to
implemented by reversing the condition.  This is handled correctly when
the condition is first expanded, but nothing stops later optimisers from
producing invalid forms.

This patch makes arm_comparison_operator check that the condition
is acceptable.  Tested on arm-linux-gnueabi.  OK to install?

Richard


gcc/
* config/arm/arm-protos.h (maybe_get_arm_condition_code): Declare.
* config/arm/arm.c (maybe_get_arm_condition_code): New function,
reusing the old code from get_arm_condition_code.  Return ARM_NV
for invalid comparison codes.
(get_arm_condition_code): Redefine in terms of
maybe_get_arm_condition_code.
* config/arm/predicates.md (arm_comparison_operator): Use
maybe_get_arm_condition_code.

gcc/testsuite/
* gcc.dg/torture/pr49030.c: New test.

Index: gcc/config/arm/arm-protos.h
===
--- gcc/config/arm/arm-protos.h 2011-09-02 15:46:44.013865635 +0100
+++ gcc/config/arm/arm-protos.h 2011-09-02 15:56:35.749477269 +0100
@@ -184,6 +184,7 @@ extern int is_called_in_ARM_mode (tree);
 #endif
 extern int thumb_shiftable_const (unsigned HOST_WIDE_INT);
 #ifdef RTX_CODE
+extern enum arm_cond_code maybe_get_arm_condition_code (rtx);
 extern void thumb1_final_prescan_insn (rtx);
 extern void thumb2_final_prescan_insn (rtx);
 extern const char *thumb_load_double_from_address (rtx *);
Index: gcc/config/arm/arm.c
===
--- gcc/config/arm/arm.c2011-09-02 15:46:44.013865635 +0100
+++ gcc/config/arm/arm.c2011-09-02 15:56:35.756477252 +0100
@@ -17595,10 +17595,10 @@ arm_elf_asm_destructor (rtx symbol, int 
decremented/zeroed by arm_asm_output_opcode as the insns are output.  */
 
 /* Returns the index of the ARM condition code string in
-   `arm_condition_codes'.  COMPARISON should be an rtx like
-   `(eq (...) (...))'.  */
-static enum arm_cond_code
-get_arm_condition_code (rtx comparison)
+   `arm_condition_codes', or ARM_NV if the comparison is invalid.
+   COMPARISON should be an rtx like `(eq (...) (...))'.  */
+enum arm_cond_code
+maybe_get_arm_condition_code (rtx comparison)
 {
   enum machine_mode mode = GET_MODE (XEXP (comparison, 0));
   enum arm_cond_code code;
@@ -17622,11 +17622,11 @@ get_arm_condition_code (rtx comparison)
 case CC_DLTUmode: code = ARM_CC;
 
 dominance:
-  gcc_assert (comp_code == EQ || comp_code == NE);
-
   if (comp_code == EQ)
return ARM_INVERSE_CONDITION_CODE (code);
-  return code;
+  if (comp_code == NE)
+   return code;
+  return ARM_NV;
 
 case CC_NOOVmode:
   switch (comp_code)
@@ -17635,7 +17635,7 @@ get_arm_condition_code (rtx comparison)
case EQ: return ARM_EQ;
case GE: return ARM_PL;
case LT: return ARM_MI;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CC_Zmode:
@@ -17643,7 +17643,7 @@ get_arm_condition_code (rtx comparison)
{
case NE: return ARM_NE;
case EQ: return ARM_EQ;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CC_Nmode:
@@ -17651,7 +17651,7 @@ get_arm_condition_code (rtx comparison)
{
case NE: return ARM_MI;
case EQ: return ARM_PL;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CCFPEmode:
@@ -17676,7 +17676,7 @@ get_arm_condition_code (rtx comparison)
  /* UNEQ and LTGT do not have a representation.  */
case UNEQ: /* Fall through.  */
case LTGT: /* Fall through.  */
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CC_SWPmode:
@@ -17692,7 +17692,7 @@ get_arm_condition_code (rtx comparison)
case GTU: return ARM_CC;
case LEU: return ARM_CS;
case LTU: return ARM_HI;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CC_Cmode:
@@ -17700,7 +17700,7 @@ get_arm_condition_code (rtx comparison)
{
case LTU: return ARM_CS;
case GEU: return ARM_CC;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CC_CZmode:
@@ -17712,7 +17712,7 @@ get_arm_condition_code (rtx comparison)
case GTU: return ARM_HI;
case LEU: return ARM_LS;
case LTU: return ARM_CC;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CC_NCVmode:
@@ -17722,7 +17722,7 @@ get_arm_condition_code (rtx comparison)
case LT: return ARM_LT;
case GEU: return ARM_CS;
case LTU: return ARM_CC;
-   default: gcc_unreachable ();
+   default: return ARM_NV;
}
 
 case CCmode:
@@ -17738,13 +17738,22 @@ get_arm_condition_code (rtx comparison)
case GTU: return ARM_HI;
case LEU: return ARM_LS;

Ping: PR 50113/50061: Fix ABI breakage from emit_library_call_value_1 patch

2011-09-02 Thread Richard Sandiford
Ping for this patch to emit_library_call_value_1:

http://gcc.gnu.org/ml/gcc-patches/2011-08/msg00735.html

which fixes a bootstrap failure on MIPS since:

http://gcc.gnu.org/ml/gcc-patches/2011-06/msg02341.html

Tested on mips64-linux-gnu, mips-sgi-irix6.5 (by Rainer) and
on both big and little-endian ARM (by Julian).

Richard


[PATCH] Store jump functions in a VECtor

2011-09-02 Thread Martin Jambor
Hi,

when I submitted the new IPA-CP a few months ago Honza requested that
I store the jump_functions in a VECtor rather than an array in which
they are now.  The patch below does exactly that.

The last remaining such request is to rename
ipa_check_create_node_params to "something else."  I guess I'll leave
this to the next weekend when we'll see each other.

I hope I got the ggc stuff right and a GTY marker does not need to be
added somewhere.  On the other hand, the patch passes bootstrap and
testsuite on x86_64-linux and I have successfully LTO-built Firefox
with it (which was able to display some complicated pages).

OK for trunk?

Thanks,

Martin


2011-09-02  Martin Jambor  

* ipa-prop.h (ipa_jump_func_t): New typedef.
(struct ipa_edge_args): Removed field argument_count, field
jump_functions turned into a vector.
(ipa_set_cs_argument_count): Removed.
(ipa_get_cs_argument_count): Updated to work on vectors.
(ipa_get_ith_jump_func): Likewise.
* ipa-prop.c (ipa_count_arguments): Removed.
(compute_scalar_jump_functions): Use ipa_get_ith_jump_func to access
jump functions.  Update caller.
(compute_pass_through_member_ptrs): Likewise.
(compute_cst_member_ptr_arguments): Likewise.
(ipa_compute_jump_functions_for_edge): Get number of arguments from
the statement, allocate vector.
(ipa_compute_jump_functions): Do not call ipa_count_arguments.
(duplicate_ipa_jump_func_array): Removed.
(ipa_edge_duplication_hook): Use VEC_copy, do not copy argument count.
(ipa_read_node_info): Allocate vector.


Index: src/gcc/ipa-prop.c
===
--- src.orig/gcc/ipa-prop.c
+++ src/gcc/ipa-prop.c
@@ -143,25 +143,6 @@ ipa_initialize_node_params (struct cgrap
 }
 }
 
-/* Count number of arguments callsite CS has and store it in
-   ipa_edge_args structure corresponding to this callsite.  */
-
-static void
-ipa_count_arguments (struct cgraph_edge *cs)
-{
-  gimple stmt;
-  int arg_num;
-
-  stmt = cs->call_stmt;
-  gcc_assert (is_gimple_call (stmt));
-  arg_num = gimple_call_num_args (stmt);
-  if (VEC_length (ipa_edge_args_t, ipa_edge_args_vector)
-  <= (unsigned) cgraph_edge_max_uid)
-VEC_safe_grow_cleared (ipa_edge_args_t, gc,
-  ipa_edge_args_vector, cgraph_edge_max_uid + 1);
-  ipa_set_cs_argument_count (IPA_EDGE_REF (cs), arg_num);
-}
-
 /* Print the jump functions associated with call graph edge CS to file F.  */
 
 static void
@@ -696,7 +677,7 @@ compute_known_type_jump_func (tree op, s
 
 static void
 compute_scalar_jump_functions (struct ipa_node_params *info,
-  struct ipa_jump_func *functions,
+  struct ipa_edge_args *args,
   gimple call)
 {
   tree arg;
@@ -704,12 +685,13 @@ compute_scalar_jump_functions (struct ip
 
   for (num = 0; num < gimple_call_num_args (call); num++)
 {
+  struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, num);
   arg = gimple_call_arg (call, num);
 
   if (is_gimple_ip_invariant (arg))
{
- functions[num].type = IPA_JF_CONST;
- functions[num].value.constant = arg;
+ jfunc->type = IPA_JF_CONST;
+ jfunc->value.constant = arg;
}
   else if (TREE_CODE (arg) == SSA_NAME)
{
@@ -718,26 +700,24 @@ compute_scalar_jump_functions (struct ip
  int index = ipa_get_param_decl_index (info, SSA_NAME_VAR (arg));
 
  if (index >= 0
- && !detect_type_change_ssa (arg, call, &functions[num]))
+ && !detect_type_change_ssa (arg, call, jfunc))
{
- functions[num].type = IPA_JF_PASS_THROUGH;
- functions[num].value.pass_through.formal_id = index;
- functions[num].value.pass_through.operation = NOP_EXPR;
+ jfunc->type = IPA_JF_PASS_THROUGH;
+ jfunc->value.pass_through.formal_id = index;
+ jfunc->value.pass_through.operation = NOP_EXPR;
}
}
  else
{
  gimple stmt = SSA_NAME_DEF_STMT (arg);
  if (is_gimple_assign (stmt))
-   compute_complex_assign_jump_func (info, &functions[num],
- call, stmt, arg);
+   compute_complex_assign_jump_func (info, jfunc, call, stmt, arg);
  else if (gimple_code (stmt) == GIMPLE_PHI)
-   compute_complex_ancestor_jump_func (info, &functions[num],
-   call, stmt);
+   compute_complex_ancestor_jump_func (info, jfunc, call, stmt);
}
}
   else
-   compute_known_type_jump_func (arg, &functions[num], call);
+   compute_known_type_jump_func (arg, jfunc, call);
 }
 }
 
@@ -821,7 +801

Re: Vector shuffling

2011-09-02 Thread Joseph S. Myers
On Fri, 2 Sep 2011, Artem Shinkarov wrote:

> +  /* Avoid C_MAYBE_CONST_EXPRs inside VEC_SHUFFLE_EXPR.  */
> +  tmp = c_fully_fold (v0, false, &maybe_const);
> +  v0 = save_expr (tmp);
> +  wrap &= maybe_const;

I suppose you need this save_expr because of the two-argument case, but 
shouldn't need it otherwise.

> +  if (!two_arguments)
> +{
> +  tmp = c_fully_fold (v1, false, &maybe_const);
> +  v1 = save_expr (tmp);

And you shouldn't need this save_expr at all.

> +  tmp = c_fully_fold (mask, false, &maybe_const);
> +  mask = save_expr (tmp);

Or this one.

> +/* Helper function to read arguments of builtins which are interfaces
> +   for the middle-end nodes like COMPLEX_EXPR, VEC_SHUFLE_EXPR and

Spelling of SHUFFLE.

> +   others. The name of the builtin is passed using BNAME parameter.

Two spaces after ".".

> +   Function returns true if there were no errors while parsing and
> +   stores the arguments in EXPR_LIST*/

".  " at end of comment.

> +static bool
> +c_parser_get_builtin_args (c_parser *  parser, const char *  bname, 
> +VEC(tree,gc) **  expr_list)

No spaces after "*".

> +  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
> +{
> +  error_at (loc, "cannot take address of %<%s%>", bname);

%qs is a simpler form of %<%s%>.

> @@ -6461,6 +6500,35 @@ c_parser_postfix_expression (c_parser *p

Should also convert __builtin_choose_expr and __builtin_complex to use the 
new helper.

> + if (! c_parser_get_builtin_args (parser, 

No space after "!".

> +   {
> + error_at (loc, "%<__builtin_shuffle%> wrong number of 
> arguments");

"wrong number of arguments to %<__builtin_shuffle%>".

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


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Michael Matz
Hi,

On Fri, 2 Sep 2011, Robert Dewar wrote:

> On 9/2/2011 9:16 AM, Richard Guenther wrote:
> 
> Might be interesting to pursue, but we don't know that the null pointers 
> being dereferenced are in fact the ones returned by alloca. May not be 
> worth the effort.

Given the nature of the work-around which makes Ada work again it's fairly 
sure that the Ada frontend does emit accesses to an alloca'ed area of 
memory even if its size is zero.  I.e. definitely a real bug.


Ciao,
Michael.


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Arnaud Charlet
> Given the nature of the work-around which makes Ada work again it's fairly
> sure that the Ada frontend does emit accesses to an alloca'ed area of
> memory even if its size is zero.  I.e. definitely a real bug.

Well, it's not clear whether it's the Ada frontend or the middle which is
emitting these, and until we have more info, it's hard to know whether it's
a real bug. Although sounds like there might indeed potentially be an issue.
I guess valgrind would detect and report this kind of issue?

Arno


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Robert Dewar

On 9/2/2011 11:47 AM, Michael Matz wrote:

Hi,

On Fri, 2 Sep 2011, Robert Dewar wrote:


On 9/2/2011 9:16 AM, Richard Guenther wrote:

Might be interesting to pursue, but we don't know that the null pointers
being dereferenced are in fact the ones returned by alloca. May not be
worth the effort.


Given the nature of the work-around which makes Ada work again it's fairly
sure that the Ada frontend does emit accesses to an alloca'ed area of
memory even if its size is zero.  I.e. definitely a real bug.


maybe so, but I gave a scenario (there are others) in which exceptions
are legitimately raised without deferencing the pointer. Once an
exception is raised all sorts of funny things can happen (e.g.
tasks silently terminating fi they have no top level exception
handler), so you can't make that direct conclusion.

I guess if you made alloca(0) return a junk non-derefencable
address, *that* would be definitive.



Ciao,
Michael.




Re: [ARM] PR target/49030: ICE in get_arm_condition_code

2011-09-02 Thread Chung-Lin Tang
Hi Richard, this looks very similar to this patch, originally for LP:689887:
http://gcc.gnu.org/ml/gcc-patches/2011-01/msg00794.html
Apart from your additional handling in the dominance modes cases.

I remember that last patch was held down because Thumb-2 native
bootstrap failed. Did you try that test?

Thanks,
Chung-Lin

On 2011/9/2 11:01 PM, Richard Sandiford wrote:
> CC_NCV rightly only allows GE(U) and LT(U).  GT(U) and LE(U) have to
> implemented by reversing the condition.  This is handled correctly when
> the condition is first expanded, but nothing stops later optimisers from
> producing invalid forms.
> 
> This patch makes arm_comparison_operator check that the condition
> is acceptable.  Tested on arm-linux-gnueabi.  OK to install?
> 
> Richard
> 
> 
> gcc/
>   * config/arm/arm-protos.h (maybe_get_arm_condition_code): Declare.
>   * config/arm/arm.c (maybe_get_arm_condition_code): New function,
>   reusing the old code from get_arm_condition_code.  Return ARM_NV
>   for invalid comparison codes.
>   (get_arm_condition_code): Redefine in terms of
>   maybe_get_arm_condition_code.
>   * config/arm/predicates.md (arm_comparison_operator): Use
>   maybe_get_arm_condition_code.
> 
> gcc/testsuite/
>   * gcc.dg/torture/pr49030.c: New test.
> 
> Index: gcc/config/arm/arm-protos.h
> ===
> --- gcc/config/arm/arm-protos.h   2011-09-02 15:46:44.013865635 +0100
> +++ gcc/config/arm/arm-protos.h   2011-09-02 15:56:35.749477269 +0100
> @@ -184,6 +184,7 @@ extern int is_called_in_ARM_mode (tree);
>  #endif
>  extern int thumb_shiftable_const (unsigned HOST_WIDE_INT);
>  #ifdef RTX_CODE
> +extern enum arm_cond_code maybe_get_arm_condition_code (rtx);
>  extern void thumb1_final_prescan_insn (rtx);
>  extern void thumb2_final_prescan_insn (rtx);
>  extern const char *thumb_load_double_from_address (rtx *);
> Index: gcc/config/arm/arm.c
> ===
> --- gcc/config/arm/arm.c  2011-09-02 15:46:44.013865635 +0100
> +++ gcc/config/arm/arm.c  2011-09-02 15:56:35.756477252 +0100
> @@ -17595,10 +17595,10 @@ arm_elf_asm_destructor (rtx symbol, int 
> decremented/zeroed by arm_asm_output_opcode as the insns are output.  */
>  
>  /* Returns the index of the ARM condition code string in
> -   `arm_condition_codes'.  COMPARISON should be an rtx like
> -   `(eq (...) (...))'.  */
> -static enum arm_cond_code
> -get_arm_condition_code (rtx comparison)
> +   `arm_condition_codes', or ARM_NV if the comparison is invalid.
> +   COMPARISON should be an rtx like `(eq (...) (...))'.  */
> +enum arm_cond_code
> +maybe_get_arm_condition_code (rtx comparison)
>  {
>enum machine_mode mode = GET_MODE (XEXP (comparison, 0));
>enum arm_cond_code code;
> @@ -17622,11 +17622,11 @@ get_arm_condition_code (rtx comparison)
>  case CC_DLTUmode: code = ARM_CC;
>  
>  dominance:
> -  gcc_assert (comp_code == EQ || comp_code == NE);
> -
>if (comp_code == EQ)
>   return ARM_INVERSE_CONDITION_CODE (code);
> -  return code;
> +  if (comp_code == NE)
> + return code;
> +  return ARM_NV;
>  
>  case CC_NOOVmode:
>switch (comp_code)
> @@ -17635,7 +17635,7 @@ get_arm_condition_code (rtx comparison)
>   case EQ: return ARM_EQ;
>   case GE: return ARM_PL;
>   case LT: return ARM_MI;
> - default: gcc_unreachable ();
> + default: return ARM_NV;
>   }
>  
>  case CC_Zmode:
> @@ -17643,7 +17643,7 @@ get_arm_condition_code (rtx comparison)
>   {
>   case NE: return ARM_NE;
>   case EQ: return ARM_EQ;
> - default: gcc_unreachable ();
> + default: return ARM_NV;
>   }
>  
>  case CC_Nmode:
> @@ -17651,7 +17651,7 @@ get_arm_condition_code (rtx comparison)
>   {
>   case NE: return ARM_MI;
>   case EQ: return ARM_PL;
> - default: gcc_unreachable ();
> + default: return ARM_NV;
>   }
>  
>  case CCFPEmode:
> @@ -17676,7 +17676,7 @@ get_arm_condition_code (rtx comparison)
> /* UNEQ and LTGT do not have a representation.  */
>   case UNEQ: /* Fall through.  */
>   case LTGT: /* Fall through.  */
> - default: gcc_unreachable ();
> + default: return ARM_NV;
>   }
>  
>  case CC_SWPmode:
> @@ -17692,7 +17692,7 @@ get_arm_condition_code (rtx comparison)
>   case GTU: return ARM_CC;
>   case LEU: return ARM_CS;
>   case LTU: return ARM_HI;
> - default: gcc_unreachable ();
> + default: return ARM_NV;
>   }
>  
>  case CC_Cmode:
> @@ -17700,7 +17700,7 @@ get_arm_condition_code (rtx comparison)
>   {
>   case LTU: return ARM_CS;
>   case GEU: return ARM_CC;
> - default: gcc_unreachable ();
> + default: return ARM_NV;
>   }
>  
>  case CC_CZmode:
> @@ -17712,7 +17712,7 @@ get_arm_condition_code (rtx comparison)
>   case GTU: return ARM_HI;
>   case LEU: return ARM_L

Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Michael Matz
Hi,

On Fri, 2 Sep 2011, Arnaud Charlet wrote:

> > Given the nature of the work-around which makes Ada work again it's fairly
> > sure that the Ada frontend does emit accesses to an alloca'ed area of
> > memory even if its size is zero.  I.e. definitely a real bug.
> 
> Well, it's not clear whether it's the Ada frontend or the middle which is
> emitting these, and until we have more info, it's hard to know whether it's
> a real bug. Although sounds like there might indeed potentially be an issue.
> I guess valgrind would detect and report this kind of issue?

Only the null pointer access, but that already trivial segfaults, not need 
for valgrind.  invalid stack accesses aren't reported by valgrind as such, 
because the stack is usually initialized and writable.  Just apply the 
test patch from Richi (returning const0_rtx from 
allocate_dynamic_stack_space for the size=0 case) and investigate.


Ciao,
Michael.


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Eric Botcazou
> This fixes the Ada bootstrap failure introduced by alloca folding.
> We now fold alloca (0) to &auto-with-size-zero which confuses us.
> I didn't exactly investigate but what I think happens is that we
> expand that &auto-with-size-zero to NULL instead of
> virtual_stack_dynamic_rtx (see zero-size special-case in
> allocate_dynamic_stack_space) and Ada ends up dereferencing the
> pointer returned from alloca (0) (something to investigate for
> the Ada folks I guess), something which "works" if we just
> return a random stack address.

This looks more convoluted than that though: AFAICS the miscompilation is 
introduced by reload which spills a pseudo to a stack slot that is already 
taken by something else:

(insn 1523 1522 1524 184 (set (reg:SI 404 [ D.7515 ])
(mem/s/j/c:SI (plus:SI (reg/f:SI 20 frame)
(const_int -32 [0xffe0])) [49 
FRAME.261.last_unit+0 S4 
A64])) /home/eric/gnat/gnat-head/src/gcc/ada/lib-writ.adb:545 50 
{*movsi_internal}

[...]

(insn 1527 1526 1528 185 (set (reg/f:SI 581 [ pretmp.679 ])
(mem/s/f/j/c:SI (plus:SI (reg/f:SI 20 frame)
(const_int -4 [0xfffc])) [49 
FRAME.261.with_flags.141+0 S4 A32])) 50 {*movsi_internal}
 (nil))

and pseudo 404 is spilled to the location of FRAME.261.with_flags.141:

(insn 1523 1522 3296 185 (set (reg:SI 1 dx)
(mem/s/j/c:SI (plus:SI (reg/f:SI 6 bp)
(const_int -56 [0xffc8])) [49 
FRAME.261.last_unit+0 S4 
A64])) /home/eric/gnat/gnat-head/src/gcc/ada/lib-writ.adb:545 50 
{*movsi_internal}
 (nil))

(insn 3296 1523 1524 185 (set (mem/c:SI (plus:SI (reg/f:SI 6 bp)
(const_int -28 [0xffe4])) [68 %sfp+-4 S4 A32])
(reg:SI 1 dx)) /home/eric/gnat/gnat-head/src/gcc/ada/lib-writ.adb:545 
50 {*movsi_internal}
 (nil))

[...]

(insn 1527 1526 1528 186 (set (reg/f:SI 4 si [orig:581 pretmp.679 ] [581])
(mem/s/f/j/c:SI (plus:SI (reg/f:SI 6 bp)
(const_int -28 [0xffe4])) [49 
FRAME.261.with_flags.141+0 S4 A32])) 50 {*movsi_internal}
 (nil))

so accessing the With_Flags array (which is not empty) yields a SEGV because 
the base pointer is equal to Last_Unit (i.e. 2).  In other words, the GIMPLE 
code looks legitimate and the bug is very likely in the stack slot allocation 
code (maybe triggered by the newly created zero-sized arrays).

In any case, thanks for fixing the bootstrap failure.

-- 
Eric Botcazou


Re: Vector shuffling

2011-09-02 Thread Artem Shinkarov
On Fri, Sep 2, 2011 at 4:41 PM, Joseph S. Myers  wrote:
> On Fri, 2 Sep 2011, Artem Shinkarov wrote:
>
>> +  /* Avoid C_MAYBE_CONST_EXPRs inside VEC_SHUFFLE_EXPR.  */
>> +  tmp = c_fully_fold (v0, false, &maybe_const);
>> +  v0 = save_expr (tmp);
>> +  wrap &= maybe_const;
>
> I suppose you need this save_expr because of the two-argument case, but
> shouldn't need it otherwise.
>
>> +  if (!two_arguments)
>> +    {
>> +      tmp = c_fully_fold (v1, false, &maybe_const);
>> +      v1 = save_expr (tmp);
>
> And you shouldn't need this save_expr at all.
>
>> +  tmp = c_fully_fold (mask, false, &maybe_const);
>> +  mask = save_expr (tmp);
>
> Or this one.

Joseph, I don't understand this comment. I have 2 or 3 arguments in
the VEC_SHUFFLE_EXPR and any of them can be C_MAYBE_CONST_EXPR, so I
need to wrap mask (the last argument) to avoid the following failure:

#define vector(elcount, type)  \
 __attribute__((vector_size((elcount)*sizeof(type type

extern int p, q, v, r;
int main ()
{
  vector (4, int) i0 = {argc, 1,2,3};
  vector (4, int) i1 = {argc, 1, argc, 3};
  vector (4, int) imask = {0,3,2,1};
  vector (4, int) extmask = {p,q,r,v};
  i2 = __builtin_shuffle (i0, (p,q)? imask:extmask);
  return 0;
}

and the same failure would happen if __builtin_shuffle expression will
be in the following form:
i2 = __builtin_shuffle (i0, (p,q)? imask:extmask, i2);

All the rest -- agreed, and is fixed already.


Thanks,
Artem.

>> +/* Helper function to read arguments of builtins which are interfaces
>> +   for the middle-end nodes like COMPLEX_EXPR, VEC_SHUFLE_EXPR and
>
> Spelling of SHUFFLE.
>
>> +   others. The name of the builtin is passed using BNAME parameter.
>
> Two spaces after ".".
>
>> +   Function returns true if there were no errors while parsing and
>> +   stores the arguments in EXPR_LIST*/
>
> ".  " at end of comment.
>
>> +static bool
>> +c_parser_get_builtin_args (c_parser *  parser, const char *  bname,
>> +                        VEC(tree,gc) **  expr_list)
>
> No spaces after "*".
>
>> +  if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
>> +    {
>> +      error_at (loc, "cannot take address of %<%s%>", bname);
>
> %qs is a simpler form of %<%s%>.
>
>> @@ -6461,6 +6500,35 @@ c_parser_postfix_expression (c_parser *p
>
> Should also convert __builtin_choose_expr and __builtin_complex to use the
> new helper.
>
>> +         if (! c_parser_get_builtin_args (parser,
>
> No space after "!".
>
>> +           {
>> +             error_at (loc, "%<__builtin_shuffle%> wrong number of 
>> arguments");
>
> "wrong number of arguments to %<__builtin_shuffle%>".
>
> --
> Joseph S. Myers
> jos...@codesourcery.com
>


Re: [PATCH] Store jump functions in a VECtor

2011-09-02 Thread Jan Hubicka
> 2011-09-02  Martin Jambor  
> 
>   * ipa-prop.h (ipa_jump_func_t): New typedef.
>   (struct ipa_edge_args): Removed field argument_count, field
>   jump_functions turned into a vector.
>   (ipa_set_cs_argument_count): Removed.
>   (ipa_get_cs_argument_count): Updated to work on vectors.
>   (ipa_get_ith_jump_func): Likewise.
>   * ipa-prop.c (ipa_count_arguments): Removed.
>   (compute_scalar_jump_functions): Use ipa_get_ith_jump_func to access
>   jump functions.  Update caller.
>   (compute_pass_through_member_ptrs): Likewise.
>   (compute_cst_member_ptr_arguments): Likewise.
>   (ipa_compute_jump_functions_for_edge): Get number of arguments from
>   the statement, allocate vector.
>   (ipa_compute_jump_functions): Do not call ipa_count_arguments.
>   (duplicate_ipa_jump_func_array): Removed.
>   (ipa_edge_duplication_hook): Use VEC_copy, do not copy argument count.
>   (ipa_read_node_info): Allocate vector.

OK,
thanks!


Re: [Patch, C] options generation and language count

2011-09-02 Thread Gary Funck
On 09/02/11 13:42:32, Joseph S. Myers wrote:
> [..] you should just generate #if/#error in the output [...]

OK, take two, attached.  (Confirmed that the #if works for
the (<, ==, >) relationships between n_langs and the max.
number of languages supported.)

- Gary

2011-09-02  Gary Funck 

* opts.c (print_specific_help): Fix off-by-one compare in
assertion check.
* opts.h (CL_PARAMS, CL_WARNING, CL_OPTIMIZATION, CL_DRIVER,
CL_TARGET, CL_COMMON, CL_JOINED, CL_SEPARATE, CL_UNDOCUMENTED):
Increase by +5 to allow for more languages.
* optc-gen.awk: Generate #if that ensures that the number of
languages is within the implementation-defined limit.

Index: gcc/ChangeLog
===
--- gcc/ChangeLog   (revision 178389)
+++ gcc/ChangeLog   (working copy)
@@ -1,3 +1,13 @@
+2011-09-02  Gary Funck 
+
+   * opts.c (print_specific_help): Fix off-by-one compare in
+   assertion check.
+   * opts.h (CL_PARAMS, CL_WARNING, CL_OPTIMIZATION, CL_DRIVER,
+   CL_TARGET, CL_COMMON, CL_JOINED, CL_SEPARATE, CL_UNDOCUMENTED):
+   Increase by +5 to allow for more languages.
+   * optc-gen.awk: Generate #if that ensures that the number of
+   languages is within the implementation-defined limit.
+
 2011-08-31  Richard Sandiford  
 
* config/i386/i386.md: Use (match_test ...) for attribute tests.
Index: gcc/opts.c
===
--- gcc/opts.c  (revision 178389)
+++ gcc/opts.c  (working copy)
@@ -1125,7 +1125,7 @@ print_specific_help (unsigned int includ
 
   /* Sanity check: Make sure that we do not have more
  languages than we have bits available to enumerate them.  */
-  gcc_assert ((1U << cl_lang_count) < CL_MIN_OPTION_CLASS);
+  gcc_assert ((1U << cl_lang_count) <= CL_MIN_OPTION_CLASS);
 
   /* If we have not done so already, obtain
  the desired maximum width of the output.  */
Index: gcc/opts.h
===
--- gcc/opts.h  (revision 178389)
+++ gcc/opts.h  (working copy)
@@ -127,12 +127,12 @@ extern const unsigned int cl_options_cou
 extern const char *const lang_names[];
 extern const unsigned int cl_lang_count;
 
-#define CL_PARAMS   (1U << 11) /* Fake entry.  Used to display 
--param info with --help.  */
-#define CL_WARNING (1U << 12) /* Enables an (optional) warning 
message.  */
-#define CL_OPTIMIZATION(1U << 13) /* Enables an (optional) 
optimization.  */
-#define CL_DRIVER  (1U << 14) /* Driver option.  */
-#define CL_TARGET  (1U << 15) /* Target-specific option.  */
-#define CL_COMMON  (1U << 16) /* Language-independent.  */
+#define CL_PARAMS   (1U << 16) /* Fake entry.  Used to display 
--param info with --help.  */
+#define CL_WARNING (1U << 17) /* Enables an (optional) warning 
message.  */
+#define CL_OPTIMIZATION(1U << 18) /* Enables an (optional) 
optimization.  */
+#define CL_DRIVER  (1U << 19) /* Driver option.  */
+#define CL_TARGET  (1U << 20) /* Target-specific option.  */
+#define CL_COMMON  (1U << 21) /* Language-independent.  */
 
 #define CL_MIN_OPTION_CLASSCL_PARAMS
 #define CL_MAX_OPTION_CLASSCL_COMMON
@@ -142,9 +142,9 @@ extern const unsigned int cl_lang_count;
This distinction is important because --help will not list options
which only have these higher bits set.  */
 
-#define CL_JOINED  (1U << 17) /* If takes joined argument.  */
-#define CL_SEPARATE(1U << 18) /* If takes a separate argument.  */
-#define CL_UNDOCUMENTED(1U << 19) /* Do not output with 
--help.  */
+#define CL_JOINED  (1U << 22) /* If takes joined argument.  */
+#define CL_SEPARATE(1U << 23) /* If takes a separate argument.  */
+#define CL_UNDOCUMENTED(1U << 24) /* Do not output with 
--help.  */
 
 /* Flags for an enumerated option argument.  */
 #define CL_ENUM_CANONICAL  (1 << 0) /* Canonical for this value.  */
Index: gcc/optc-gen.awk
===
--- gcc/optc-gen.awk(revision 178389)
+++ gcc/optc-gen.awk(working copy)
@@ -169,6 +169,9 @@ for (i = 0; i < n_langs; i++) {
 
 print "  0\n};\n"
 print "const unsigned int cl_options_count = N_OPTS;\n"
+print "#if (1U << " n_langs ") > CL_MIN_OPTION_CLASS"
+print "  #error the number of languages exceeds the implementation limit"
+print "#endif"
 print "const unsigned int cl_lang_count = " n_langs ";\n"
 
 print "const struct cl_option cl_options[] =\n{"


Re: Fix PR50260

2011-09-02 Thread Michael Matz
Hi,

On Fri, 2 Sep 2011, Richard Guenther wrote:

> > Currently regstrapping on x86_64-linux (without Ada).  Okay for trunk?
> 
> Ok.  Time to make get_var_ann private?

Yes.  Should the regstrap succeed on x86_64-linux I'll commit this 
variant of the patch (hunks in tree-flow.h, tree-flow-inline.h and 
tree-dfa.c are new, otherwise the same patch).


Ciao,
Michael.
-- 
PR middle-end/50260
* ipa-split.c (split_function): Call add_referenced_var.

* tree-ssa-phiopt.c (cond_store_replacement): Don't call get_var_ann.
(cond_if_else_store_replacement_1): Ditto.
* tree-ssa-pre.c (get_representative_for): Ditto.
(create_expression_by_pieces): Ditto.
(insert_into_preds_of_block): Ditto.
* tree-sra.c (create_access_replacement): Ditto.
(get_replaced_param_substitute): Ditto.

* tree-flow.h (get_var_ann): Don't declare.
* tree-flow-inline.h (get_var_ann): Remove.
(set_is_used): Use var_ann, not get_var_ann.
* tree-dfa.c (add_referenced_var): Inline body of get_var_ann.

testsuite/
* gfortran.fortran-torture/compile/pr50260.f90: New test.

Index: ipa-split.c
===
--- ipa-split.c (revision 178408)
+++ ipa-split.c (working copy)
@@ -988,6 +988,9 @@ split_function (struct split_point *spli
arg = gimple_default_def (cfun, parm);
if (!arg)
  {
+   /* This parm wasn't used up to now, but is going to be used,
+  hence register it.  */
+   add_referenced_var (parm);
arg = make_ssa_name (parm, gimple_build_nop ());
set_default_def (parm, arg);
  }
Index: tree-ssa-phiopt.c
===
--- tree-ssa-phiopt.c   (revision 178408)
+++ tree-ssa-phiopt.c   (working copy)
@@ -1269,10 +1269,7 @@ cond_store_replacement (basic_block midd
   /* 2) Create a temporary where we can store the old content
 of the memory touched by the store, if we need to.  */
   if (!condstoretemp || TREE_TYPE (lhs) != TREE_TYPE (condstoretemp))
-{
-  condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
-  get_var_ann (condstoretemp);
-}
+condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
   add_referenced_var (condstoretemp);
 
   /* 3) Insert a load from the memory of the store to the temporary
@@ -1355,10 +1352,7 @@ cond_if_else_store_replacement_1 (basic_
   /* 2) Create a temporary where we can store the old content
of the memory touched by the store, if we need to.  */
   if (!condstoretemp || TREE_TYPE (lhs) != TREE_TYPE (condstoretemp))
-{
-  condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
-  get_var_ann (condstoretemp);
-}
+condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
   add_referenced_var (condstoretemp);
 
   /* 3) Create a PHI node at the join block, with one argument
Index: tree-ssa-pre.c
===
--- tree-ssa-pre.c  (revision 178408)
+++ tree-ssa-pre.c  (working copy)
@@ -1399,7 +1399,7 @@ get_representative_for (const pre_expr e
   if (!pretemp || exprtype != TREE_TYPE (pretemp))
 {
   pretemp = create_tmp_reg (exprtype, "pretmp");
-  get_var_ann (pretemp);
+  add_referenced_var (pretemp);
 }
 
   name = make_ssa_name (pretemp, gimple_build_nop ());
@@ -3178,10 +3178,7 @@ create_expression_by_pieces (basic_block
   /* Build and insert the assignment of the end result to the temporary
  that we will return.  */
   if (!pretemp || exprtype != TREE_TYPE (pretemp))
-{
-  pretemp = create_tmp_reg (exprtype, "pretmp");
-  get_var_ann (pretemp);
-}
+pretemp = create_tmp_reg (exprtype, "pretmp");
 
   temp = pretemp;
   add_referenced_var (temp);
@@ -3441,10 +3438,7 @@ insert_into_preds_of_block (basic_block
 
   /* Now build a phi for the new variable.  */
   if (!prephitemp || TREE_TYPE (prephitemp) != type)
-{
-  prephitemp = create_tmp_var (type, "prephitmp");
-  get_var_ann (prephitemp);
-}
+prephitemp = create_tmp_var (type, "prephitmp");
 
   temp = prephitemp;
   add_referenced_var (temp);
Index: tree-sra.c
===
--- tree-sra.c  (revision 178408)
+++ tree-sra.c  (working copy)
@@ -1825,7 +1825,6 @@ create_access_replacement (struct access
   tree repl;
 
   repl = create_tmp_var (access->type, "SR");
-  get_var_ann (repl);
   add_referenced_var (repl);
   if (rename)
 mark_sym_for_renaming (repl);
@@ -4106,7 +4105,6 @@ get_replaced_param_substitute (struct ip
   DECL_NAME (repl) = get_identifier (pretty_name);
   obstack_free (&name_obstack, pretty_name);
 
-  get_var_ann (repl);
   add_referenced_var (repl);
   adj->new_ssa_base = repl;
 }
Index: testsuite/gfortran.fortran-torture/compile/pr50260.f90
==

Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Eric Botcazou
> so accessing the With_Flags array (which is not empty) yields a SEGV
> because the base pointer is equal to Last_Unit (i.e. 2).  In other words,
> the GIMPLE code looks legitimate and the bug is very likely in the stack
> slot allocation code (maybe triggered by the newly created zero-sized
> arrays).

And this is the real fix.  Richard, do you want me to apply (part of it)?


* cfgexpand.c (add_stack_var): Assert that the alignment is not zero.
* tree-ssa-ccp.c (fold_builtin_alloca_for_var): Force BITS_PER_UNIT
alignment at least on the new variable.


-- 
Eric Botcazou
Index: cfgexpand.c
===
--- cfgexpand.c	(revision 178422)
+++ cfgexpand.c	(working copy)
@@ -271,6 +271,8 @@ add_stack_var (tree decl)
   if (v->size == 0)
 v->size = 1;
   v->alignb = align_local_variable (SSAVAR (decl));
+  /* An alignment of zero can mightily confuse us later.  */
+  gcc_assert (v->alignb != 0);
 
   /* All variables are initially in their own partition.  */
   v->representative = stack_vars_num;
Index: tree-ssa-ccp.c
===
--- tree-ssa-ccp.c	(revision 178422)
+++ tree-ssa-ccp.c	(working copy)
@@ -1722,6 +1722,8 @@ fold_builtin_alloca_for_var (gimple stmt
   elem_type = build_nonstandard_integer_type (BITS_PER_UNIT, 1);
   n_elem = size * 8 / BITS_PER_UNIT;
   align = MIN (size * 8, BIGGEST_ALIGNMENT);
+  if (align < BITS_PER_UNIT)
+align = BITS_PER_UNIT;
   array_type = build_array_type_nelts (elem_type, n_elem);
   var = create_tmp_var (array_type, NULL);
   DECL_ALIGN (var) = align;


[RFC, WIP] tree-ssa-strlen optimization pass

2011-09-02 Thread Jakub Jelinek
Hi!

The following patch contains a WIP implementation of a new pass,
which attempts to track C string lengths and perform various
optimizations using that information.

Optimizations it currently performs:
1) optimizing away strlen calls, if the string length is known
   at that point already (either constant or some expression)
2) replacement of strcpy calls with memcpy if the string length
   of the source is known
3) replacement of strcat with either memcpy (if source length
   is known) or strcpy (if not), if the destination length
   before the call is known
   - over the years I've seen way too much spaghetti code
   doing many strcat calls to the same string one after another
During bootstrap/regtest (excluding the newly added testcases)
1) hits 184 times on x86_64-linux, 182 tmes on i686-linux,
2) hits 158 times on x86_64 and 159 times on i686,
3) into memcpy hits 33 times and 3) into strcpy 2 times.

Example from gcc sources that is optimized:
  filename = (char *) alloca (strlen (module_name) + strlen (MODULE_EXTENSION)
  + 1);
  strcpy (filename, module_name);
  strcat (filename, MODULE_EXTENSION);
which can be optimized into
  filename = (char *) alloca ((tmp1 = strlen (module_name)) + (tmp2 = strlen 
(MODULE_EXTENSION))
  + 1);
  memcpy (filename, module_name, tmp1 + 1);
  memcpy (filename + tmp1, MODULE_EXTENSION, tmp2 + 1);

Some further optimizations I'm currently considering for the pass:
- handle *p = 0; stores like memcpy (p, "", 1)
  - lame coders often do *p = 0; strcat (p, str1); strcat (p, str2);
- if a memcpy call (either original or strcpy/strcat transformed into it)
  copies known src string length + 1 and the immediately following
  .MEM use (or possibly non-immediately if there are only non-aliasing
  ones?) is a strcpy/(or to be optimized strcat or non-zero length memcpy)
  call which overwrites the final '\0', decrease the memcpy size by one
- if source length for strcpy isn't known and the destination length
  is needed for optimizations, for -fhosted, glibc and with stpcpy
  compatible prototype in headers consider transforming that strcpy
  into stpcpy and use result - dst as string length (and see whether
  following optimizations are able to optimize series of unknown
  source length strcpy+strcat into a chain of stpcpy calls)
- similarly if string length of strcat destination isn't known but is
  helpful for optimization consider optimizing strcat into strlen+stpcpy

Any comments related to the implementation, or examples of real-world
lame C string length code sequences that would be nice to optimize
will be greatly appreciated.

The patch has been bootstrapped/regtested on x86_64-linux and i686-linux,
no regressions, but I'm not proposing it for trunk yet (would like to
implement at least a few of the above mentioned optimizations), just am
posting it early as a pass preview.

2011-09-02  Jakub Jelinek  

* common.opt: Add -ftree-strlen option.
* Makefile.in (OBJS): Add tree-ssa-strlen.o.
(tree-sssa-strlen.o): Add dependencies.
* opts.c (default_options_table): Enable -ftree-strlen
by default at -O2 if not -Os.
* passes.c (init_optimization_passes): Add pass_strlen
after pass_object_sizes.
* timevar.def (TV_TREE_STRLEN): New timevar.
* tree-pass.h (pass_strlen): Declare.
* tree-ssa-strlen.c: New file.

* gcc.dg/strlenopt-1.c: New test.
* gcc.dg/strlenopt-2.c: New test.
* gcc.dg/strlenopt-3.c: New test.
* gcc.dg/strlenopt.h: New file.

--- gcc/common.opt.jj   2011-08-26 18:41:44.0 +0200
+++ gcc/common.opt  2011-08-30 10:57:36.0 +0200
@@ -1953,6 +1953,10 @@ ftree-fre
 Common Report Var(flag_tree_fre) Optimization
 Enable Full Redundancy Elimination (FRE) on trees
 
+ftree-strlen
+Common Report Var(flag_tree_strlen) Optimization
+Enable string length optimizations on trees
+
 ftree-loop-distribution
 Common Report Var(flag_tree_loop_distribution) Optimization
 Enable loop distribution on trees
--- gcc/Makefile.in.jj  2011-08-26 18:41:44.0 +0200
+++ gcc/Makefile.in 2011-09-02 15:43:02.0 +0200
@@ -1472,6 +1472,7 @@ OBJS = \
tree-ssa-reassoc.o \
tree-ssa-sccvn.o \
tree-ssa-sink.o \
+   tree-ssa-strlen.o \
tree-ssa-structalias.o \
tree-ssa-ter.o \
tree-ssa-threadedge.o \
@@ -3157,6 +3158,9 @@ tree-ssa-ccp.o : tree-ssa-ccp.c $(TREE_F
$(TREE_DUMP_H) $(BASIC_BLOCK_H) $(TREE_PASS_H) langhooks.h \
tree-ssa-propagate.h value-prof.h $(FLAGS_H) $(TARGET_H) 
$(DIAGNOSTIC_CORE_H) \
$(DBGCNT_H) tree-pretty-print.h gimple-pretty-print.h gimple-fold.h
+tree-ssa-strlen.o : tree-ssa-strlen.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+   $(TREE_FLOW_H) $(TREE_PASS_H) domwalk.h alloc-pool.h tree-ssa-propagate.h \
+   gimple-pretty-print.h
 tree-sra.o : tree-sra.c $(CONFIG_H) $(SYSTEM_H) coretypes.h alloc-pool.h \
$(TM_H) $(T

Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Eric Botcazou
> And this is the real fix.  Richard, do you want me to apply (part of it)?

In fact I'd even propose to revert the fold_builtin_alloca_for_var part of 
your patch and apply mine entirely, as eliminating alloca (0) early looks a 
interesting simplification.  What do you think?

-- 
Eric Botcazou


Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread H.J. Lu
On Fri, Sep 2, 2011 at 9:40 AM, Eric Botcazou  wrote:
>> so accessing the With_Flags array (which is not empty) yields a SEGV
>> because the base pointer is equal to Last_Unit (i.e. 2).  In other words,
>> the GIMPLE code looks legitimate and the bug is very likely in the stack
>> slot allocation code (maybe triggered by the newly created zero-sized
>> arrays).
>
> And this is the real fix.  Richard, do you want me to apply (part of it)?
>
>
>        * cfgexpand.c (add_stack_var): Assert that the alignment is not zero.
>        * tree-ssa-ccp.c (fold_builtin_alloca_for_var): Force BITS_PER_UNIT
>        alignment at least on the new variable.
>

Will this also fix:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50251

Thanks.

-- 
H.J.


Re: [RFC, WIP] tree-ssa-strlen optimization pass

2011-09-02 Thread Paolo Carlini

Hi,

Any comments related to the implementation, or examples of real-world
lame C string length code sequences that would be nice to optimize
will be greatly appreciated.
I'm only wondering how hard would be taking care more consistently of 
the wchar_t counterparts of all these library functions. I don't think 
user code using those is so uncommon, at least now that 
internationalization is taken more and more seriously.


Paolo.


[lra] reverting a patch

2011-09-02 Thread Vladimir Makarov
  My previous patch for preference of smaller # of registers involved 
in reloads broke some tests from spec2000 on i686 because LRA started to 
use MMX registers.  I am working on a fix for this but unfortunately 
fixing it is not easy and will take some time, so I am reverting my 
previous patch.


2011-09-02  Vladimir Makarov 

Revert:
2011-08-26  Vladimir Makarov 
* lra-constraints.c (best_reload_nregs): New variable.
(process_alt_operands): Add preferences for smaller hard registers
involved.  Increase reject for all failed non registers.

* lra-eliminations.c (mark_not_eliminable): Add check on hard
register before looping on eliminations.



Re: [PATCH] Fix Ada bootstrap failure

2011-09-02 Thread Tom de Vries
On 09/02/2011 07:13 PM, H.J. Lu wrote:
> On Fri, Sep 2, 2011 at 9:40 AM, Eric Botcazou  wrote:
>>> so accessing the With_Flags array (which is not empty) yields a SEGV
>>> because the base pointer is equal to Last_Unit (i.e. 2).  In other words,
>>> the GIMPLE code looks legitimate and the bug is very likely in the stack
>>> slot allocation code (maybe triggered by the newly created zero-sized
>>> arrays).
>>
>> And this is the real fix.  Richard, do you want me to apply (part of it)?
>>
>>
>>* cfgexpand.c (add_stack_var): Assert that the alignment is not zero.
>>* tree-ssa-ccp.c (fold_builtin_alloca_for_var): Force BITS_PER_UNIT
>>alignment at least on the new variable.
>>
> 
> Will this also fix:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50251
> 
> Thanks.
> 

I don't think so. The alloca there has an argument of 24 and an aligment of 128
bits.

Furthermore, the bug report lists a test-case that triggers without vla and 
alloca.

Thanks,
- Tom


Re: Propagate BB predicates in ipa-inline-analysis

2011-09-02 Thread Ulrich Weigand
Jan Hubicka wrote:

>   (edge_execution_predicate): Rewrite as...
>   (set_cond_stmt_execution_predicate): ... this function; handle
>   __builtin_constant_p.

This causes ICEs when building recent Linux kernels with the
CONFIG_TRACE_BRANCH_PROFLING option.  This reduced test case:

static inline __attribute__((always_inline)) int f (unsigned int n, unsigned 
int size)
{
 return (__builtin_constant_p (size != 0 && n > ~0 / size)
 ? !!(size != 0 && n > ~0 / size)
 : ({ static unsigned int count[2] = { 0, 0 };
  int r = !!(size != 0 && n > ~0 / size);
  count[r]++;
  r; }));
}

int g (unsigned int size)
{
 return f (size / 4096, 4);
}

built with -O2 (on i386) on current mainline results in:

/home/uweigand/test.i:15:1: internal compiler error: tree check: expected 
ssa_name, have integer_cst in set_cond_stmt_execution_predicate, at 
ipa-inline-analysis.c:1190

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  ulrich.weig...@de.ibm.com


Fix C6X FP insn scheduling

2011-09-02 Thread Bernd Schmidt
Scheduling floating point insns is broken on C6X; unfortunately in a way
that the simulator doesn't detect.

We let the sched DFA pick a valid schedule, and later on we try to
reconstruct a valid unit assignment. This does not work if an insn has
multiple units it can choose, and that insn's reservation spans multiple
cycles. FP insns match both of these conditions.

The following patch fixes it, by using the previously added
collapse-ndfa option and some special functional units, and querying CPU
units at the end of each cycle.


Bernd
* config/c6x/c6x.md (collapse-ndfa, no-comb-vect): New
automata_options.
(d1, l1, s1, m1, d2, l2, s2, m2): Changed to define_query_cpu_unit.
(l1w, s1w, l2w, s2w): Define in the main automaton.
(fps1, fpl1, adddps1, adddpl1, fps2, fpl2, adddps2, adddpl2): New
units.
* config/c6x/c6x.c (c6x_sched_insn_info): Add unit_mask member.
(c6x_unit_names): Add the new units.
(c6x_unit_codes): New static array.
(UNIT_QID_D1, UNIT_QID_L1, UNIT_QID_S1, UNIT_QID_M1, UNIT_QID_FPS1,
UNIT_QID_FPL1, UNIT_QID_ADDDPS1, UNIT_QID_ADDDPL1,
UNIT_QID_SIDE_OFFSET): New macros.
(RESERVATION_S2): Adjust value.
(c6x_option_override): Compute c6x_unit_codes.
(assign_reservations): Take the unit_mask of the last instruction
into account.  Detect floating point reservations by looking for
the new units.  Don't assign reservations if the field is already
nonzero.
(struct c6x_sched_context): Add member prev_cycle_state_ctx.
(init_sched_state): Initialize it.
(c6x_clear_sched_context): Free it.
(insn_set_clock): Clear reservation.
(prev_cycle_state): New static variable.
(c6x_init_sched_context): Save it.
(c6x_sched_init): Allocate space for it and clear it.
(c6x_sched_dfa_pre_cycle_insn): New static function.
(c6x_dfa_new_cycle): Save state at the start of a new cycle.
(c6x_variable_issue): Only record units in the unit_mask that
were not set at the start of the cycle.
(c6x_variable_issue): Compute and store the unit_mask from the
current state.
(reorg_split_calls): Ensure the new information remains correct.
(TARGET_SCHED_DFA_NEW_CYCLE, TARGET_SCHED_CLEAR_SCHED_CONTEXT,
TARGET_SCHED_DFA_PRE_CYCLE_INSN): Define.
* config/c6x/c6x.h (CPU_UNITS_QUERY): Define.
* config/c6x/c6x-sched.md.in (fp4_ls_N__CROSS_, adddp_ls_N__CROSS_):
Add special reservations.
* config/c6x/c6x-sched.md: Regenerate.

Index: gcc/config/c6x/c6x-sched.md.in
===
--- gcc/config/c6x/c6x-sched.md.in  (revision 178293)
+++ gcc/config/c6x/c6x-sched.md.in  (working copy)
@@ -178,14 +178,14 @@ (define_insn_reservation "fp4_ls_N__CROS
(and (eq_attr "cross" "_CROSS_")
(and (eq_attr "units" "ls")
 (eq_attr "dest_regfile" "_RF_"
-  "(s_N__CUNIT_,nothing*2,s_N_w)|(l_N__CUNIT_,nothing*2,l_N_w)")
+  "(fps_N_+s_N__CUNIT_,nothing*2,s_N_w)|(fpl_N_+l_N__CUNIT_,nothing*2,l_N_w)")
 
 (define_insn_reservation "adddp_ls_N__CROSS_" 7
   (and (eq_attr "type" "adddp")
(and (eq_attr "cross" "_CROSS_")
(and (eq_attr "units" "ls")
 (eq_attr "dest_regfile" "_RF_"
-  "((s_N__CUNIT_)*2,nothing*3,s_N_w*2)|((l_N__CUNIT_)*2,nothing*3,l_N_w*2)")
+  
"(adddps_N_+(s_N__CUNIT_)*2,nothing*3,s_N_w*2)|(adddpl_N_+(l_N__CUNIT_)*2,nothing*3,l_N_w*2)")
 
 (define_insn_reservation "single_dls_N__CROSS_" 1
   (and (eq_attr "type" "single")
Index: gcc/config/c6x/c6x.md
===
--- gcc/config/c6x/c6x.md   (revision 178293)
+++ gcc/config/c6x/c6x.md   (working copy)
@@ -242,21 +242,27 @@ (define_attr "units"
]
(const_string "unknown")))
 
-(define_automaton 
"c6x_1,c6x_w1,c6x_2,c6x_w2,c6x_m1,c6x_m2,c6x_t1,c6x_t2,c6x_branch")
+(define_automaton "c6x_1,c6x_2,c6x_m1,c6x_m2,c6x_t1,c6x_t2,c6x_branch")
+(automata_option "no-comb-vect")
 (automata_option "ndfa")
+(automata_option "collapse-ndfa")
 
-(define_cpu_unit "d1,l1,s1" "c6x_1")
+(define_query_cpu_unit "d1,l1,s1" "c6x_1")
 (define_cpu_unit "x1" "c6x_1")
-(define_cpu_unit "l1w,s1w" "c6x_w1")
-(define_cpu_unit "m1" "c6x_m1")
+(define_cpu_unit "l1w,s1w" "c6x_1")
+(define_query_cpu_unit "m1" "c6x_m1")
 (define_cpu_unit "m1w" "c6x_m1")
 (define_cpu_unit "t1" "c6x_t1")
-(define_cpu_unit "d2,l2,s2" "c6x_2")
+(define_query_cpu_unit "d2,l2,s2" "c6x_2")
 (define_cpu_unit "x2" "c6x_2")
-(define_cpu_unit "l2w,s2w" "c6x_w2")
-(define_cpu_unit "m2" "c6x_m2")
+(define_cpu_unit "l2w,s2w" "c6x_2")
+(define_query_cpu_unit "m2" "c6x_m2")
 (define_cpu_unit "m2w" "c6x_m2")
 (define_cpu_unit "t2" "c6x_t2")
+;; A special set of units used to identify specific reservations, rather than
+;; just units.
+(define_query_cpu_unit "fps1,f

Re: [RFC, WIP] tree-ssa-strlen optimization pass

2011-09-02 Thread Jakub Jelinek
On Fri, Sep 02, 2011 at 07:14:58PM +0200, Paolo Carlini wrote:
> >Any comments related to the implementation, or examples of real-world
> >lame C string length code sequences that would be nice to optimize
> >will be greatly appreciated.
> I'm only wondering how hard would be taking care more consistently
> of the wchar_t counterparts of all these library functions. I don't
> think user code using those is so uncommon, at least now that
> internationalization is taken more and more seriously.

I'm fairly sure it is much less common than the narrow versions,
we don't even handle wprintf and wscanf attributes.

Tracking not just char strings, but also wchar_t (or either char, or
wchar_t) would complicate the pass somewhat, but I'm more worried that it
would not be stressed enough in real-world code and thus would be less
tested than would be desirable.  Plus it is very premature when none of the
wcs* builtins are actually handled in builtins.c and we don't have
infrastructure for that.

Jakub


Re: Fix PR50260

2011-09-02 Thread Michael Matz
Hi,

On Fri, 2 Sep 2011, Michael Matz wrote:

> Hi,
> 
> On Fri, 2 Sep 2011, Richard Guenther wrote:
> 
> > > Currently regstrapping on x86_64-linux (without Ada).  Okay for trunk?
> > 
> > Ok.  Time to make get_var_ann private?
> 
> Yes.  Should the regstrap succeed on x86_64-linux I'll commit this 
> variant of the patch (hunks in tree-flow.h, tree-flow-inline.h and 
> tree-dfa.c are new, otherwise the same patch).

As I feared the call to get_var_ann in set_is_used right now really is 
still needed, privatizing it hence isn't that straight forward.  For now 
I've committed the PR50260 fix without that cleanup as r178489 to fix 
bootstrap for some platforms.


Ciao,
Michael.

  1   2   >