[google] Backport r175009 from trunk to google/gcc-4_6 (issue4815082)

2011-08-03 Thread Guozhi Wei
Hi

I want to port r175009 from trunk to google/gcc-4_6 since it fixed 3 dejagnu
failures for arm backend.

Tested on x86-64 with
make check-gcc RUNTESTFLAGS="vect.exp"

Tested on arm qemu with
make check-gcc RUNTESTFLAGS="--target_board=arm-sim/thumb/arch=armv7-a vect.exp"
make check-gcc RUNTESTFLAGS="--target_board=arm-sim/arch=armv7-a vect.exp"

OK for google/gcc-4_6?

thanks
Carrot


2011-08-03  Guozhi Wei  

Backport r175009 from trunk.

2011-06-14  Ira Rosen  

* gcc.dg/vect/vect-16.c: Rename to...
* gcc.dg/vect/no-fast-math-vect16.c: ...this.
* gcc.dg/vect/vect-peel-3.c: Adjust misalignment values
for double-word vectors.
* gcc.dg/vect/vect-peel-4.c: Likewise.
* gcc.dg/vect/bb-slp-10.c: Replace vect_hw_misalign with
vect_element_align.
* gcc.dg/vect/vect.exp: Run no-fast-math-* tests with
-fno-fast-math.


Index: gcc.dg/vect/vect-16.c
===
--- gcc.dg/vect/vect-16.c   (revision 177228)
+++ gcc.dg/vect/vect-16.c   (working copy)
@@ -1,38 +0,0 @@
-/* { dg-require-effective-target vect_float } */
-
-#include 
-#include "tree-vect.h"
-
-#define N 16
-#define DIFF 240
-
-__attribute__ ((noinline))
-int main1 ()
-{
-  int i;
-  float b[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
-  float c[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
-  float diff;
-
-  diff = 0;
-  for (i = 0; i < N; i++) {
-diff += (b[i] - c[i]);
-  }
-
-  /* check results:  */
-  if (diff != DIFF)
-abort ();
-
-  return 0;
-}
-
-int main (void)
-{ 
-  check_vect ();
-  
-  return main1 ();
-}
-
-/* Requires fast-math.  */
-/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail 
*-*-* } } } */
-/* { dg-final { cleanup-tree-dump "vect" } } */
Index: gcc.dg/vect/vect-peel-3.c
===
--- gcc.dg/vect/vect-peel-3.c   (revision 177228)
+++ gcc.dg/vect/vect-peel-3.c   (working copy)
@@ -4,9 +4,7 @@
 #include "tree-vect.h"
 
 #define N 128
-#define RES 21888 
-
-/* unaligned store.  */
+#define RES 21640 
 
 int ib[N+10];
 int ia[N+10];
@@ -18,11 +16,11 @@ int main1 ()
   int i, suma = 0, sumb = 0, sumc = 0;
 
   /* ib and ic have same misalignment, we peel to align them.  */
-  for (i = 1; i <= N; i++)
+  for (i = 0; i <= N; i++)
 {
   suma += ia[i];
-  sumb += ib[i+6];
-  sumc += ic[i+2];
+  sumb += ib[i+5];
+  sumc += ic[i+1];
 }
 
   /* check results:  */
Index: gcc.dg/vect/vect-peel-4.c
===
--- gcc.dg/vect/vect-peel-4.c   (revision 177228)
+++ gcc.dg/vect/vect-peel-4.c   (working copy)
@@ -16,13 +16,13 @@ int main1 ()
   /* Don't peel keeping one load and the store aligned.  */
   for (i = 0; i <= N; i++)
 {
-  ia[i] = ib[i] + ib[i+6];
+  ia[i] = ib[i] + ib[i+5];
 }
 
   /* check results:  */
   for (i = 1; i <= N; i++)
 {
-  if (ia[i] != ib[i] + ib[i+6])
+  if (ia[i] != ib[i] + ib[i+5])
 abort ();
 }
 
Index: gcc.dg/vect/bb-slp-10.c
===
--- gcc.dg/vect/bb-slp-10.c (revision 177228)
+++ gcc.dg/vect/bb-slp-10.c (working copy)
@@ -49,7 +49,7 @@ int main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "unsupported alignment in basic block." 1 
"slp" { xfail vect_hw_misalign } } } */
-/* { dg-final { scan-tree-dump-times "basic block vectorized using SLP" 1 
"slp" { target vect_hw_misalign } } } */
+/* { dg-final { scan-tree-dump-times "unsupported alignment in basic block." 1 
"slp" { xfail vect_element_align } } } */
+/* { dg-final { scan-tree-dump-times "basic block vectorized using SLP" 1 
"slp" { target vect_element_align } } } */
 /* { dg-final { cleanup-tree-dump "slp" } } */
   
Index: gcc.dg/vect/vect.exp
===
--- gcc.dg/vect/vect.exp(revision 177228)
+++ gcc.dg/vect/vect.exp(working copy)
@@ -108,6 +108,12 @@ lappend DEFAULT_VECTCFLAGS "-ffast-math"
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-*.\[cS\]]]  \
"" $DEFAULT_VECTCFLAGS
 
+# -fno-fast-math tests
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-fno-fast-math"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-fast-math-*.\[cS\]]]  \
+"" $DEFAULT_VECTCFLAGS
+
 # -fno-math-errno tests
 set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
 lappend DEFAULT_VECTCFLAGS "-fno-math-errno"

--
This patch is available for review at http://codereview.appspot.com/4815082


[Ada] Ada2012 : incomplete types can be used in more contexts

2011-08-03 Thread Arnaud Charlet
This patch allows tagged incomplete types to be used in profiles of entries
and entry bodies, without the presence of a regular with_clause on the package
whose limited view provides those types.
The following must compile quietly:

   gcc -c -gnat12 -gnatws tagged_half_1.adb

---
limited with Half_2;
package Half_1 is

   type Unseen_Ref is access all Half_2.Unseen;

   type Seen is record
  Value : Unseen_Ref;
   end record;

   function foo (Val : Seen) return Half_2.Unseen;
   function bar (Val : Half_2.Unseen) return Seen;

   procedure Baz
 (Val_1 : Half_2.Unseen;
  Val_2 : in out Half_2.Unseen;
  Val_3 : out Half_2.Unseen);

   type Tagged_Unseen_Ref is access all Half_2.Tagged_Unseen;

   type Tagged_Seen is tagged record
  Value : Tagged_Unseen_Ref;
   end record;
end Half_1;
---
with Half_1; use Half_1;
package Half_2 is

   type Unseen is record
  Value : Seen;
   end record;

   type Tagged_Unseen is tagged record
  Value : Tagged_Seen;
   end record;
end Half_2;
---
with Half_2;
package body Half_1 is

   function foo (Val : Seen) return Half_2.Unseen is
   begin
  return Val.Value.all;
   end;

   function bar (Val : Half_2.Unseen) return Seen is
   begin
  return Val.Value;
   end;

   procedure Baz
 (Val_1 : Half_2.Unseen;
  Val_2 : in out Half_2.Unseen;
  Val_3 : out Half_2.Unseen) is
   begin
  Val_3 := Val_2;
  Val_2 := Val_1;
   end;
end Half_1;
---
limited with Half_2;
package Tagged_Half_1 is

   type Tagged_Unseen_Ref is access all Half_2.Tagged_Unseen;

   type Tagged_Seen is tagged record
  Value : Tagged_Unseen_Ref;
   end record;

   function bar (Val : Half_2.Tagged_Unseen) return Tagged_Seen;

   procedure Baz
 (Val_1 : Half_2.Tagged_Unseen;
  Val_2 : in out Half_2.Tagged_Unseen;
  Val_3 : out Half_2.Tagged_Unseen);

   function Faux return Boolean;
end Tagged_Half_1;
---
package body Tagged_Half_1 is
   --  Note that there's no "with Half_2;" here; we're still seeing the limited
   --  view.

   function Faux return Boolean is
   begin
  return False;
   end Faux;

   function bar (Val : Half_2.Tagged_Unseen) return Tagged_Seen is
   begin
  return Result : Tagged_Seen;
   end;

   procedure Baz
 (Val_1 : Half_2.Tagged_Unseen;
  Val_2 : in out Half_2.Tagged_Unseen;
  Val_3 : out Half_2.Tagged_Unseen) is
   begin
  if Faux then
 Baz (Val_1, Val_2, Val_3);
  end if;
   end;

   task T is
  entry E
(Val_1 : Half_2.Tagged_Unseen;
 Val_2 : in out Half_2.Tagged_Unseen;
 Val_3 : out Half_2.Tagged_Unseen);
   end T;

   task body T is
   begin
  select
 accept E
   (Val_1 : Half_2.Tagged_Unseen;
Val_2 : in out Half_2.Tagged_Unseen;
Val_3 : out Half_2.Tagged_Unseen);
  or
 terminate;
  end select;
   end T;

   protected Prot is
  entry E
(Val_1 : Half_2.Tagged_Unseen;
 Val_2 : in out Half_2.Tagged_Unseen;
 Val_3 : out Half_2.Tagged_Unseen);
   end Prot;

   protected body Prot is
  entry E
(Val_1 : Half_2.Tagged_Unseen;
 Val_2 : in out Half_2.Tagged_Unseen;
 Val_3 : out Half_2.Tagged_Unseen) when True is
  begin
 Baz (Val_1, Val_2, Val_3);
  end E;
   end Prot;
end Tagged_Half_1;

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

2011-08-03  Ed Schonberg  

* exp_ch9.adb (Build_Renamed_Formal_Declaration): common procedure for
protected entries and task entries, to build the proper renaming
declaration for entry formals, used in debugging.
* exp_ch2.adb (Expand_Entry_Parameter): handle task and entry
parameters in the same way.

Index: exp_ch9.adb
===
--- exp_ch9.adb (revision 177190)
+++ exp_ch9.adb (working copy)
@@ -170,6 +170,19 @@
--  and Decl is the enclosing synchronized type declaration at whose
--  freeze point the generated body is analyzed.
 
+   function Build_Renamed_Formal_Declaration
+ (New_F  : Entity_Id;
+  Formal : Entity_Id;
+  Comp   : Entity_Id;
+  Renamed_Formal : Node_Id) return Node_Id;
+   --  Create a renaming declaration for a formal, within a protected entry
+   --  body or an accept body. The renamed object is a component of the
+   --  parameter block that is a parameter in the entry call.
+
+   --  In Ada2012,  If the formal is an incomplete tagged type, the renaming
+   --  does not dereference the corresponding component to prevent an illegal
+   --  use of the incomplete type (AI05-0151).
+
procedure Build_Wrapper_Bodies
  (Loc : Source_Ptr;
   Typ : Entity_Id;
@@ -637,10 +650,11 @@
   --  The name of the formal that holds the address of the parameter block
   --  for the call.
 
-  Comp   : Entity_Id;
-  Decl   : Node_Id;
-  Formal : Entity_Id;
-  New_F  : Entity_Id;
+  Comp: Entity_Id;

[Ada] Initialization of class-wide interface objects in VM targets

2011-08-03 Thread Arnaud Charlet
This patch does not change the behavior of native compilers. It
adds missing support in VM targets for declarations of class-wide
interface objects.

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

2011-08-03  Javier Miranda  

* exp_intr.adb
(Expand_Dispatching_Constructor_Call): Disable expansion of
code required for native targets. Done to avoid generating
references to unavailable runtime entities in VM targets.
* exp_ch3.adb
(Expand_N_Object_Declaration): Add missing support to handle
the explicit initialization of class-wide interface objects.
Fix documentation.

Index: exp_intr.adb
===
--- exp_intr.adb(revision 177163)
+++ exp_intr.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -233,6 +233,7 @@
 
  if not Is_Ancestor (Etype (Result_Typ), Etype (Tag_Arg),
  Use_Full_View => True)
+   and then Tagged_Type_Expansion
  then
 --  Obtain the reference to the Ada.Tags service before generating
 --  the Object_Declaration node to ensure that if this service is
Index: exp_ch3.adb
===
--- exp_ch3.adb (revision 177180)
+++ exp_ch3.adb (working copy)
@@ -4477,14 +4477,6 @@
-- Expand_N_Object_Declaration --
-
 
-   --  First we do special processing for objects of a tagged type where this
-   --  is the point at which the type is frozen. The creation of the dispatch
-   --  table and the initialization procedure have to be deferred to this
-   --  point, since we reference previously declared primitive subprograms.
-
-   --  The above comment is in the wrong place, it should be at the proper
-   --  point in this routine ???
-
procedure Expand_N_Object_Declaration (N : Node_Id) is
   Def_Id   : constant Entity_Id  := Defining_Identifier (N);
   Expr : constant Node_Id:= Expression (N);
@@ -4528,6 +4520,12 @@
  return;
   end if;
 
+  --  First we do special processing for objects of a tagged type where
+  --  this is the point at which the type is frozen. The creation of the
+  --  dispatch table and the initialization procedure have to be deferred
+  --  to this point, since we reference previously declared primitive
+  --  subprograms.
+
   --  Force construction of dispatch tables of library level tagged types
 
   if Tagged_Type_Expansion
@@ -4993,11 +4991,33 @@
   Set_Homonym (Defining_Identifier (N), Homonym (Def_Id));
   Exchange_Entities (Defining_Identifier (N), Def_Id);
end;
+
+--  Handle initialization of class-wide interface object in VM
+--  targets
+
+elsif not Tagged_Type_Expansion then
+
+   --  Replace
+   -- CW : I'Class := Obj;
+   --  by
+   -- CW : I'Class;
+   -- CW := I'Class (Obj); [1]
+
+   --  The assignment [1] is later expanded in a dispatching
+   --  call to _assign
+
+   Set_Expression (N, Empty);
+
+   Insert_Action (N,
+ Make_Assignment_Statement (Loc,
+   Name   => New_Reference_To (Def_Id, Loc),
+   Expression => Convert_To (Typ,
+   Relocate_Node (Expr;
 end if;
 
 return;
 
- --  Comment needed here, what case is this???
+ --  Common case of explicit object initialization
 
  else
 --  In most cases, we must check that the initial value meets any


[Ada] merge operation should always clear source

2011-08-03 Thread Arnaud Charlet
The purpose of the Merge operation is to move elements from
a sorted vector (the source) to another sorted vector (the target).
Following the merge, the source container should be empty.  There
was an execution path (when the target was initially empty) in which
the elements of the source were merely copied onto the target,
without also removing the elements from the source.  The fix was
to use the Move operation, instead of Assign, when merging elements
from source onto an emtpy target.

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

2011-08-03  Matthew Heaney  

* a-cobove.adb (Merge): Move source onto target, instead of using Assign

Index: a-cobove.adb
===
--- a-cobove.adb(revision 176998)
+++ a-cobove.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 2004-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- --
@@ -762,7 +762,7 @@
 
   begin
  if Target.Is_Empty then
-Target.Assign (Source);
+Move (Target => Target, Source => Source);
 return;
  end if;
 


[Ada] splice items from first to last

2011-08-03 Thread Arnaud Charlet
When splicing a source list before a position in a target list,
the items must be spliced in order from first to last; otherwise,
(splicing from last to first) the items become reversed as they
are moved to the target.

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

2011-08-03  Matthew Heaney  

* a-cbdlli.adb (Splice): move source items from first to last

Index: a-cbdlli.adb
===
--- a-cbdlli.adb(revision 176998)
+++ a-cbdlli.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 2004-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- --
@@ -1486,10 +1486,9 @@
"attempt to tamper with cursors of Source (list is busy)";
   end if;
 
-  loop
- Insert (Target, Before, Source.Nodes (Source.Last).Element);
- Delete_Last (Source);
- exit when Is_Empty (Source);
+  while not Is_Empty (Source) loop
+ Insert (Target, Before, Source.Nodes (Source.First).Element);
+ Delete_First (Source);
   end loop;
end Splice;
 


[Ada] Disable aggregate expansion in assignments in VM targets

2011-08-03 Thread Arnaud Charlet
This patch does not change the behavior of native compilers. It
disables the frontend expansion of aggregates into assignments
when the type of the aggregate whose size is not known at compile time.

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

2011-08-03  Javier Miranda  

* exp_aggr.adb
(Expand_Record_Aggregate): In VM targets disable the expansion into
assignments of aggregates whose type is not known at compile time.

Index: exp_aggr.adb
===
--- exp_aggr.adb(revision 177086)
+++ exp_aggr.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -5649,7 +5649,9 @@
   --  Gigi doesn't handle properly temporaries of variable size
   --  so we generate it in the front-end
 
-  elsif not Size_Known_At_Compile_Time (Typ) then
+  elsif not Size_Known_At_Compile_Time (Typ)
+and then Tagged_Type_Expansion
+  then
  Convert_To_Assignments (N, Typ);
 
   --  Temporaries for controlled aggregates need to be attached to a


[PATCH, ARM] Generate conditional compares in Thumb2 state

2011-08-03 Thread Jiangning Liu
This patch is to generate more conditional compare instructions in Thumb2
state. Given an example like below,

int f(int i, int j) 
{
  if ( (i == '+') || (j == '-') ) {
return i;
  } else {
return j;
  }
}

Without the patch, compiler generates the following codes,

sub r2, r0, #43
rsbsr3, r2, #0
adc r3, r3, r2
cmp r1, #45
it  eq
orreq   r3, r3, #1
cmp r3, #0
it  eq
moveq   r0, r1
bx  lr

With the patch, compiler can generate conditional jump like below,

cmp r0, #43
it  ne
cmpne   r1, #45
it  ne
movne   r0, r1
bx  lr

The patch is essentially to insert *it* instruction for the following rules
in arm.md,

* cmp_ite0
* cmp_ite1
* cmp_and
* cmp_ior

Tested against arm-none-eabi target and no regression found.

Source code Changelog would be:

2011-07-29  Jiangning Liu  

* config/arm/arm.md (*ior_scc_scc): Enable for Thumb2 as well.
(*ior_scc_scc_cmp): Likewise
(*and_scc_scc): Likewise.
(*and_scc_scc_cmp): Likewise.
(*and_scc_scc_nodom): Likewise.
(*cmp_ite0, *cmp_ite1, *cmp_and, *cmp_ior): Handle Thumb2.

Testsuite Changelog would be:

2011-07-29  Jiangning Liu  

* gcc.target/arm/thumb2-cond-cmp-1.c: New. Make sure conditional 
compare can be generated.
* gcc.target/arm/thumb2-cond-cmp-2.c: Likewise.
* gcc.target/arm/thumb2-cond-cmp-3.c: Likewise.
* gcc.target/arm/thumb2-cond-cmp-4.c: Likewise.

Thanks,
-Jiangning

fix_cond_cmp.patch
Description: Binary data


[Ada] The actual type of a constant discriminated object

2011-08-03 Thread Arnaud Charlet
If a constant object of an unconstrained type with discriminants is initialzed
with an aggregate, the constrained subtype of the aggregate can be used  as the
type of the object, because such an object is immutable. If all components of
the aggregate are static, this allows the back-end to generate no code for the
object declaration.

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

2011-08-03  Ed Schonberg  

* sem_ch3.adb (Analyze_Object_Declaration): if a constant object of an
unconstrained type with discriminants is initialized with an aggregate,
use the constrained subtype of the aggregate as the type of the object,
because it is immutable, and this allows the back-end to generate no
code for the object declaration.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 177187)
+++ sem_ch3.adb (working copy)
@@ -3401,6 +3401,18 @@
  --  It is unclear why this should make it acceptable to gcc. ???
 
  Remove_Side_Effects (E);
+
+  elsif not Is_Constrained (T)
+and then Has_Discriminants (T)
+and then Constant_Present (N)
+and then not Has_Unchecked_Union (T)
+and then Nkind (E) = N_Aggregate
+  then
+ --  If this is a constant declaration of an unconstrained type and
+ --  the initialization is an aggregate, we can use the subtype of the
+ --  aggregate for the declared entity because it is immutable.
+
+ Act_T := Etype (E);
   end if;
 
   --  Check No_Wide_Characters restriction


[Ada] Compiler crash when an aggregate's range choice does not match index type

2011-08-03 Thread Arnaud Charlet
A type mismatch between the bounds of an array aggregate's range choice
and the expected index type causes the compiler to crash or go into an
infinite loop. Although the compiler catches the type resolution error,
and the range is marked as having an error posted, the bounds are not
marked, preventing the compiler from aborting its analysis of the aggregate.
The fix is to record whether errors are posted on any expression or range
choices after their resolution, as a condition for aborting further processing
of the aggregate.

The test below must issue only the following errors when compiled and not
crash or hang the compiler:

  1. package Bad_Aggr_Choice_Crash is
  2.
  3.type Enum is (A, B, C, D, E);
  4.
  5.A1 : array (Enum) of Boolean := (1 .. 3 => False); -- ERROR
   |
 >>> expected type "Enum" defined at line 3
 >>> found type universal integer

  6.
  7.A2 : array (Enum) of Boolean := (A => True, 1 .. 4 => False);  -- ERROR
1 2
 >>> incompatible types in range
 >>> expected type "Enum" defined at line 3
 >>> found type universal integer

  8.
  9. end Bad_Aggr_Choice_Crash;


package Bad_Aggr_Choice_Crash is

   type Enum is (A, B, C, D, E);

   A1 : array (Enum) of Boolean := (1 .. 3 => False); -- ERROR

   A2 : array (Enum) of Boolean := (A => True, 1 .. 4 => False);  -- ERROR

end Bad_Aggr_Choice_Crash;

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

2011-08-03  Gary Dismukes  

* sem_aggr.adb (Analyze_Array_Aggregate): When checking the discrete
choices of a named array aggregate, bail out when any choices are
marked as Errors_Posted.

Index: sem_aggr.adb
===
--- sem_aggr.adb(revision 177178)
+++ sem_aggr.adb(working copy)
@@ -1823,6 +1823,9 @@
 --  Used to keep track of the number of discrete choices in the
 --  current association.
 
+Errors_Posted_On_Choices : Boolean := False;
+--  Keeps track of whether any choices have semantic errors
+
  begin
 --  STEP 2 (A): Check discrete choices validity
 
@@ -1867,6 +1870,14 @@
  Check_Unset_Reference (Choice);
  Check_Non_Static_Context (Choice);
 
+ --  If semantic errors were posted on the choice, then
+ --  record that for possible early return from later
+ --  processing (see handling of enumeration choices).
+
+ if Error_Posted (Choice) then
+Errors_Posted_On_Choices := True;
+ end if;
+
  --  Do not range check a choice. This check is redundant
  --  since this test is already done when we check that the
  --  bounds of the array aggregate are within range.
@@ -2144,13 +2155,12 @@
 and then Compile_Time_Known_Value (Choices_Low)
 and then Compile_Time_Known_Value (Choices_High)
   then
- --  If the bounds have semantic errors, do not attempt
- --  further resolution to prevent cascaded errors.
+ --  If any of the expressions or range bounds in choices
+ --  have semantic errors, then do not attempt further
+ --  resolution, to prevent cascaded errors.
 
- if Error_Posted (Choices_Low)
-   or else Error_Posted (Choices_High)
- then
-return False;
+ if Errors_Posted_On_Choices then
+return Failure;
  end if;
 
  declare


[Ada] Premature freezing when building dispatch tables

2011-08-03 Thread Arnaud Charlet
When a tagged type is frozen, its primitive operations are frozen, and the
profiles of these operations are frozen as well. This patch checks that
these profiles do not include a non-private type with a private unfrozen
subcomponent, and report an error otherwise. Previously the compiler only
flagged unfrozen private types appearing directly in a profile.

Compiling p.adb must yield:

p.ads:13:04: declaration must appear after completion of type "Int"
p.ads:13:04: which is a component of untagged type "Arr" in the profile of
primitive operation "Proc" declared at line 11

package P is

   type Int is private;

   type Arr is array (Positive range <>) of Int;

   type Rec is tagged record
  Res : Integer;
   end record;

   procedure Proc (Result : Rec; Params : Arr);

   N : constant Rec := (Res => 0);

private
   type Int is new Integer;
end P;
---
package body P is

   procedure Proc (Result : Rec; Params : Arr) is begin null; end;

end P;

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

2011-08-03  Ed Schonberg  

* exp_disp.adb (Check_Premature_Freezing): diagnose the presence of a
composite type with an unfrozen subcomponent, in the profile of a
primitive operation.

Index: exp_disp.adb
===
--- exp_disp.adb(revision 177180)
+++ exp_disp.adb(working copy)
@@ -3764,7 +3764,10 @@
   DT_Aggr : constant Elist_Id := New_Elmt_List;
   --  Entities marked with attribute Is_Dispatch_Table_Entity
 
-  procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id);
+  procedure Check_Premature_Freezing
+(Subp: Entity_Id;
+ Tagged_Type : Entity_Id;
+ Typ : Entity_Id);
   --  Verify that all non-tagged types in the profile of a subprogram
   --  are frozen at the point the subprogram is frozen. This enforces
   --  the rule on RM 13.14 (14) as modified by AI05-019. At the point a
@@ -3775,6 +3778,8 @@
   --  Typical violation of the rule involves an object declaration that
   --  freezes a tagged type, when one of its primitive operations has a
   --  type in its profile whose full view has not been analyzed yet.
+  --  More complex cases involve composite types that have one private
+  --  unfrozen subcomponent.
 
   procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
   --  Export the dispatch table DT of tagged type Typ. Required to generate
@@ -3814,10 +3819,15 @@
   -- Check_Premature_Freezing --
   --
 
-  procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id) is
+  procedure Check_Premature_Freezing
+(Subp: Entity_Id;
+ Tagged_Type : Entity_Id;
+ Typ : Entity_Id)
+  is
+ Comp : Entity_Id;
   begin
  if Present (N)
-   and then  Is_Private_Type (Typ)
+   and then Is_Private_Type (Typ)
and then No (Full_View (Typ))
and then not Is_Generic_Type (Typ)
and then not Is_Tagged_Type (Typ)
@@ -3828,8 +3838,26 @@
   ("declaration must appear after completion of type &", N, Typ);
 Error_Msg_NE
   ("\which is an untagged type in the profile of"
-   & " primitive operation & declared#",
-   N, Subp);
+   & " primitive operation & declared#", N, Subp);
+
+ else
+Comp := Private_Component (Typ);
+
+if not Is_Tagged_Type (Typ)
+  and then Present (Comp)
+  and then not Is_Frozen (Comp)
+then
+   Error_Msg_Sloc := Sloc (Subp);
+   Error_Msg_Node_2 := Subp;
+   Error_Msg_Name_1 := Chars (Tagged_Type);
+   Error_Msg_NE
+ ("declaration must appear after completion of type &",
+   N, Comp);
+   Error_Msg_NE
+ ("\which is a component of untagged type& in the profile of"
+   & " primitive & of type % that is frozen by the declaration ",
+   N, Typ);
+end if;
  end if;
   end Check_Premature_Freezing;
 
@@ -4587,11 +4615,11 @@
begin
   F := First_Formal (Prim);
   while Present (F) loop
- Check_Premature_Freezing (Prim, Etype (F));
+ Check_Premature_Freezing (Prim, Typ, Etype (F));
  Next_Formal (F);
   end loop;
 
-  Check_Premature_Freezing (Prim, Etype (Prim));
+  Check_Premature_Freezing (Prim, Typ, Etype (Prim));
end;
 
if Present (Frnodes) then


[Ada] Expansion of selected components that denote discriminants

2011-08-03 Thread Arnaud Charlet
In general a selected component that denotes a discriminant can be replaced
with the corresponding discriminant value if it comes from a constrained type.
However if the discriminant is not static and is an expression with implicit
control, such as a short-circuit operation, copying the value may lead to
anomalies in code coverage.  Nevertheless, if the reference occurs within the
initialization code generated for an object declaration (typically because of
a change of representation in a derived type) the discriminant value must always
be copied from the type, because it may denote the still uninitialized component
of the object itself.

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

2011-08-03  Ed Schonberg  

* exp_ch4.adb (Expand_N_Selected_Component): If the discriminant value
is an integer literal it is always safe to replace the reference. In
addition, if the reference appears in the generated code for an object
declaration it is necessary to copy because otherwise the reference
might be to the uninitilized value of the discriminant of the object
itself.

Index: exp_ch4.adb
===
--- exp_ch4.adb (revision 177233)
+++ exp_ch4.adb (working copy)
@@ -7594,6 +7594,18 @@
   --  unless the context of an assignment can provide size information.
   --  Don't we have a general routine that does this???
 
+  function Is_Subtype_Declaration return Boolean;
+  --  The replacement of a discriminant reference by its value is required
+  --  if this is part of the initialization of an temporary generated by
+  --  a change of representation. This shows up as the construction of a
+  --  discriminant constraint for a subtype declared at the same point as
+  --  the entity in the prefix of the selected component.
+  --  We recognize this case when the context of the reference is:
+  --
+  --   subtype ST is T(Obj.D);
+  --
+  --   The entity for Obj comes from source, and ST has the same sloc.
+
   ---
   -- In_Left_Hand_Side --
   ---
@@ -7607,6 +7619,21 @@
  and then In_Left_Hand_Side (Parent (Comp)));
   end In_Left_Hand_Side;
 
+  -
+  --  Is_Subtype_Declaration --
+  -
+
+  function Is_Subtype_Declaration return Boolean is
+ Par : constant Node_Id := Parent (N);
+
+  begin
+ return
+   Nkind (Par) = N_Index_Or_Discriminant_Constraint
+ and then Nkind (Parent (Parent (Par))) = N_Subtype_Declaration
+ and then Comes_From_Source (Entity (Prefix (N)))
+ and then Sloc (Par) = Sloc (Entity (Prefix (N)));
+  end Is_Subtype_Declaration;
+
--  Start of processing for Expand_N_Selected_Component
 
begin
@@ -7730,9 +7757,19 @@
   --  AND THEN was copied, causing problems for coverage
   --  analysis tools).
 
+  --  However, if the reference is part of the initialization
+  --  code generated for an object declaration, we must use
+  --  the discriminant value from the subtype constraint,
+  --  because the selected component may be a reference to the
+  --  object being initialized, whose discriminant is not yet
+  --  set. This only happens in complex cases involving changes
+  --  or representation.
+
   if Disc = Entity (Selector_Name (N))
 and then (Is_Entity_Name (Dval)
-   or else Is_Static_Expression (Dval))
+  or else Nkind (Dval) = N_Integer_Literal
+  or else Is_Subtype_Declaration
+  or else Is_Static_Expression (Dval))
   then
  --  Here we have the matching discriminant. Check for
  --  the case of a discriminant of a component that is


[Ada] Itype references and generics

2011-08-03 Thread Arnaud Charlet
Itype references are constructed to force the backend to elaborate itypes at
the point of definition, to prevent scope anomalies if the first use of the
itype is within some later nested context. Itypes must not be generated for
formal generic types, and more generally within a generic unit, because the
unit itself is not seen by the backend, and may refer to incomplete types.
The following must compile quietly:

  gcc -c -gnat05 p.adb

---
package body P is
   L: aliased Q.List_Type;

   function Find return access T'Class is
  M : Q.Mark_Type (L'Access);
   begin
  return T((M.Func.all))'Access;
   end Find;
end P;
---
with Q;
package P is
   generic
  type T is tagged private;
   function Find return access T'Class;
end P;
---
package Q is
   type Object is interface;

   type List_Type is tagged null record;

   type Mark_Type (L: access List_Type) is tagged null record;

   function Func (M : Mark_Type) return access Object'Class;
end Q;

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

2011-08-03  Ed Schonberg  

* sem_ch3.adb (Build_Itype_Reference): do not create an itype reference
for an itype created within a generic unit.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 177237)
+++ sem_ch3.adb (working copy)
@@ -8631,8 +8631,15 @@
is
   IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
begin
-  Set_Itype (IR, Ityp);
-  Insert_After (Nod, IR);
+
+  --  Itype references are only created for use by the back-end.
+
+  if Inside_A_Generic then
+ return;
+  else
+ Set_Itype (IR, Ityp);
+ Insert_After (Nod, IR);
+  end if;
end Build_Itype_Reference;
 



[Ada] Clear confusion about -fno-inline in the GNAT UG

2011-08-03 Thread Arnaud Charlet
The GNAT Pro User's Guide reads:

`-fno-inline'
Suppresses all back-end inlining, even if other optimization or inlining 
switches are set. This includes suppression of inlining that results from the 
use of the pragma Inline_Always. Any occurrences of pragma Inline or 
Inline_Always are ignored, and `-gnatn' and `-gnatN' have no effect if this 
switch is present. 

This is confusing because both pragma Inline_Always and -gnatN are front-end 
inlining.  -fno-inline simply suppresses all inlining.

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

2011-08-03  Eric Botcazou  

* gnat_ugn.texi (Switches for gcc): Make it clearer that -fno-inline
suppresses all inlining.

Index: gnat_ugn.texi
===
--- gnat_ugn.texi   (revision 177236)
+++ gnat_ugn.texi   (working copy)
@@ -3961,10 +3961,9 @@
 
 @item -fno-inline
 @cindex @option{-fno-inline} (@command{gcc})
-Suppresses all back-end inlining, even if other optimization or inlining
-switches are set.
-This includes suppression of inlining that results
-from the use of the pragma @code{Inline_Always}.
+Suppresses all inlining, even if other optimization or inlining
+switches are set.  This includes suppression of inlining that
+results from the use of the pragma @code{Inline_Always}.
 Any occurrences of pragma @code{Inline} or @code{Inline_Always}
 are ignored, and @option{-gnatn} and @option{-gnatN} have no
 effect if this switch is present.


Re: [PATCH][2/2][RFC] Fix PR49806, promote/demote binary operations in VRP

2011-08-03 Thread Richard Guenther
On Tue, 2 Aug 2011, Ira Rosen wrote:

> 
> 
> Richard Guenther  wrote on 02/08/2011 04:25:58 PM:
> 
> 
> >
> > Thinking about it it probably makes sense to keep a variant of this
> > in the vectorizer - after all it has quite specific requirements on
> > operand sizes while VRP would probably demote as far as possible
> > (maybe taking PROMOTE_MODE into account).
> >
> > A quick look at your patch reveals
> >
> > +  if (gimple_assign_rhs_code (use_stmt) == CONVERT_EXPR)
> >
> > CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (use_stmt))
> >
> > +  tmp = create_tmp_var (use_type, NULL);
> >
> > create_tmp_reg
> 
> Why? USE_TYPE is neither COMPLEX_TYPE nor VECTOR_TYPE.

Just for making it the common routine to call whenever you expect
SSA names to be created.  Thus, not confuse people with a mix
of create_tmp_var and create_tmp_reg when they are grepping.

Richard.

> Thanks,
> Ira
> 
> 
> >
> > +  if (!types_compatible_p (TREE_TYPE (oprnd0), type)
> > +  || !types_compatible_p (TREE_TYPE (oprnd1), type)
> > +  || (TREE_CODE (oprnd0) != INTEGER_CST
> > +  && TREE_CODE (oprnd1) != INTEGER_CST))
> >
> > it's always the second operand that is constant, you can simplify
> > the code to not handle CST op SSA.
> >
> > +  code = gimple_assign_rhs_code (stmt);
> > +  if (code != LSHIFT_EXPR && code != RSHIFT_EXPR
> > +  && code != BIT_IOR_EXPR && code != BIT_XOR_EXPR && code !=
> > BIT_AND_EXPR)
> > +return false;
> > +
> > +  oprnd0 = gimple_assign_rhs1 (stmt);
> > +  oprnd1 = gimple_assign_rhs2 (stmt);
> > +  type = gimple_expr_type (stmt);
> > +  if (!types_compatible_p (TREE_TYPE (oprnd0), type)
> > +  || !types_compatible_p (TREE_TYPE (oprnd1), type)
> >
> > for shifts the type compatibility check of oprnd1 isn't guaranteed
> > (but do we care?  we only will handle constant shift amounts), for
> > the other operands of the codes you handle they always return true.
> >
> > So I'd simplify the check to
> >
> >   if (TREE_CODE (oprnd0) != SSA_NAME
> >   || TREE_CODE (oprnd1) != INTEGER_CST)
> > return false;
> >
> > Otherwise the patch looks sensible.
> >
> > Richard.
> 
> 

-- 
Richard Guenther 
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer

[Ada] C++ types are limited

2011-08-03 Thread Arnaud Charlet
Ada types with convention CPP_Class are treated as limited types. This change
requires that they are declared with the LIMITED keyword (previously we
already issued a warning in such case). This does not substantially alter
the compiler's treatment of such types, since they were already supposed
to be treated as limited for all practical purposes.

However this does fix some cases where the compiler incorrectly failed to
enforce some of the restrictions associated with limited types. This also
ensures that the use of CPP types does not create violations of the
contract model when a private type has a completion that is a CPP class
(by making it clear on the private view that the type is limited).

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

2011-08-03  Thomas Quinot  

* sem_prag.adb Issue an error (not a warning) when a C++ type does not
have keyword LIMITED.

Index: sem_prag.adb
===
--- sem_prag.adb(revision 177238)
+++ sem_prag.adb(working copy)
@@ -4156,24 +4156,18 @@
  elsif Is_Record_Type (Def_Id)
and then C = Convention_CPP
  then
---  Types treated as CPP classes are treated as limited, but we
---  don't require them to be declared this way. A warning is issued
---  to encourage the user to declare them as limited. This is not
---  an error, for compatibility reasons, because these types have
---  been supported this way for some time.
+--  Types treated as CPP classes must be declared limited (note:
+--  this used to be a warning but there is no real benefit to it
+--  since we did effectively intend to treat the type as limited
+--  anyway).
 
 if not Is_Limited_Type (Def_Id) then
Error_Msg_N
- ("imported 'C'P'P type should be " &
-"explicitly declared limited?",
+ ("imported 'C'P'P type must be limited",
   Get_Pragma_Arg (Arg2));
-   Error_Msg_N
- ("\type will be considered limited",
-  Get_Pragma_Arg (Arg2));
 end if;
 
 Set_Is_CPP_Class (Def_Id);
-Set_Is_Limited_Record (Def_Id);
 
 --  Imported CPP types must not have discriminants (because C++
 --  classes do not have discriminants).
@@ -7053,24 +7047,18 @@
Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
 end if;
 
---  Types treated as CPP classes are treated as limited, but we
---  don't require them to be declared this way. A warning is issued
---  to encourage the user to declare them as limited. This is not
---  an error, for compatibility reasons, because these types have
---  been supported this way for some time.
+--  Types treated as CPP classes must be declared limited (note:
+--  this used to be a warning but there is no real benefit to it
+--  since we did effectively intend to treat the type as limited
+--  anyway).
 
 if not Is_Limited_Type (Typ) then
Error_Msg_N
- ("imported 'C'P'P type should be " &
-"explicitly declared limited?",
+ ("imported 'C'P'P type must be limited",
   Get_Pragma_Arg (Arg1));
-   Error_Msg_N
- ("\type will be considered limited",
-  Get_Pragma_Arg (Arg1));
 end if;
 
 Set_Is_CPP_Class  (Typ);
-Set_Is_Limited_Record (Typ);
 Set_Convention(Typ, Convention_CPP);
 
 --  Imported CPP types must not have discriminants (because C++


[Ada] Null string literals in non-static context

2011-08-03 Thread Arnaud Charlet
The lower bound of a string literal is set to the 'First of the base type of
the index type, when the lower bound of the context type is non-static. This
is problematic if the string is an empty string and the base type is Integer,
because then the uppper bound is not representable. Given that the string is
always converted to the type of the context, simplest is to set lower bound
of literal to 1, as when the context type is String.

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

2011-08-03  Ed Schonberg  

* sem_res.adb (Set_String_Literal_Subtype): if index type is an integer
type, always use 1 as the lower bound or string, even if lower bound of
context is not static, to handle properly null strings in a non-static
context.

Index: sem_res.adb
===
--- sem_res.adb (revision 177237)
+++ sem_res.adb (working copy)
@@ -9906,13 +9906,23 @@
 Index : Node_Id;
 
  begin
-Set_String_Literal_Low_Bound
-  (Subtype_Id,
-   Make_Attribute_Reference (Loc,
- Attribute_Name => Name_First,
- Prefix =>
-   New_Occurrence_Of (Base_Type (Index_Type), Loc)));
-Set_Etype (String_Literal_Low_Bound (Subtype_Id), Index_Type);
+if Is_Integer_Type (Index_Type) then
+   Set_String_Literal_Low_Bound
+ (Subtype_Id, Make_Integer_Literal (Loc, 1));
+
+else
+   --  If the index type is an enumeration type, build bounds
+   --  expression with attributes.
+
+   Set_String_Literal_Low_Bound
+ (Subtype_Id,
+  Make_Attribute_Reference (Loc,
+Attribute_Name => Name_First,
+Prefix =>
+  New_Occurrence_Of (Base_Type (Index_Type), Loc)));
+   Set_Etype (String_Literal_Low_Bound (Subtype_Id), Index_Type);
+end if;
+
 Analyze_And_Resolve (String_Literal_Low_Bound (Subtype_Id));
 
 --  Build bona fide subtype for the string, and wrap it in an


[Ada] Initialize hidden discriminants in extension aggregates

2011-08-03 Thread Arnaud Charlet
If the type of the aggregate is derived, and constrains discriminants
of the parent type, these discriminants are not components of the
aggregate, and must be initialized by the code generated by the
compiler. They are not visible components of the object, but can
become visible with a view conversion to the ancestor.

This patch adds the missing support to the frontend to generate
assignments initializing hidden discriminants in extension
aggregates. The following test must compile and execute
without errors.

package Pkg is
   type ROOT is tagged null record;

   type NT_B1 (D2 : Natural) is new Root with record
  S2 : String(1..D2);
   end record;

   type NT_B2 (D3 : Natural) is new NT_B1 (D2 => 10) with null record;
end;

with Pkg; use Pkg;
procedure Do_Test is
   String10 : String(1..10) := "1234567890";
   G : NT_B2 := (ROOT with D3 => 5, S2   => String10);
   N : Natural;
begin
   N := NT_B1(G).D2;
   if N /= 10 then
 raise Program_Error;
   end if;
end;

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

2011-08-03  Javier Miranda  

* exp_aggr.adb (Init_Hidden_Discriminants): New subprogram of
Build_Record_Aggr_Code.
(Build_Record_Aggr_Code): Add missing support to initialize hidden
discriminants in extension aggregates.

Index: exp_aggr.adb
===
--- exp_aggr.adb(revision 177237)
+++ exp_aggr.adb(working copy)
@@ -1854,6 +1854,11 @@
   --  to finalization list F. Init_Pr conditions the call to the init proc
   --  since it may already be done due to ancestor initialization.
 
+  procedure Init_Hidden_Discriminants (Typ : Entity_Id; List : List_Id);
+  --  If Typ is derived, and constrains discriminants of the parent type,
+  --  these discriminants are not components of the aggregate, and must be
+  --  initialized. The assignments are appended to List.
+
   function Is_Int_Range_Bounds (Bounds : Node_Id) return Boolean;
   --  Check whether Bounds is a range node and its lower and higher bounds
   --  are integers literals.
@@ -2156,6 +2161,56 @@
  return L;
   end Init_Controller;
 
+  ---
+  -- Init_Hidden_Discriminants --
+  ---
+
+  procedure Init_Hidden_Discriminants (Typ : Entity_Id; List : List_Id) is
+ Btype   : Entity_Id;
+ Parent_Type : Entity_Id;
+ Disc: Entity_Id;
+ Discr_Val   : Elmt_Id;
+
+  begin
+ Btype := Base_Type (Typ);
+ while Is_Derived_Type (Btype)
+and then Present (Stored_Constraint (Btype))
+ loop
+Parent_Type := Etype (Btype);
+
+Disc := First_Discriminant (Parent_Type);
+Discr_Val := First_Elmt (Stored_Constraint (Base_Type (Typ)));
+while Present (Discr_Val) loop
+
+   --  Only those discriminants of the parent that are not
+   --  renamed by discriminants of the derived type need to
+   --  be added explicitly.
+
+   if not Is_Entity_Name (Node (Discr_Val))
+ or else Ekind (Entity (Node (Discr_Val))) /= E_Discriminant
+   then
+  Comp_Expr :=
+Make_Selected_Component (Loc,
+  Prefix=> New_Copy_Tree (Target),
+  Selector_Name => New_Occurrence_Of (Disc, Loc));
+
+  Instr :=
+Make_OK_Assignment_Statement (Loc,
+  Name   => Comp_Expr,
+  Expression => New_Copy_Tree (Node (Discr_Val)));
+
+  Set_No_Ctrl_Actions (Instr);
+  Append_To (List, Instr);
+   end if;
+
+   Next_Discriminant (Disc);
+   Next_Elmt (Discr_Val);
+end loop;
+
+Btype := Base_Type (Parent_Type);
+ end loop;
+  end Init_Hidden_Discriminants;
+
   -
   -- Is_Int_Range_Bounds --
   -
@@ -2741,6 +2796,17 @@
 end if;
  end;
 
+ --  Generate assignments of hidden assignments. If the base type is an
+ --  unchecked union, the discriminants are unknown to the back-end and
+ --  absent from a value of the type, so assignments for them are not
+ --  emitted.
+
+ if Has_Discriminants (Typ)
+   and then not Is_Unchecked_Union (Base_Type (Typ))
+ then
+Init_Hidden_Discriminants (Typ, L);
+ end if;
+
   --  Normal case (not an extension aggregate)
 
   else
@@ -2752,60 +2818,8 @@
  if Has_Discriminants (Typ)
and then not Is_Unchecked_Union (Base_Type (Typ))
  then
---  If the type is derived, and constrains discriminants of the
---  parent type, these discriminants are not components of the
-   

[Ada] Minor improvement to traces, to support indented output

2011-08-03 Thread Arnaud Charlet
This makes it easier to follow the stream of log traces while working
on the project manager.
This does not change the normal output or behavior of the builders.

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

2011-08-03  Emmanuel Briot  

* prj-part.adb, prj.adb, prj.ads, prj-nmsc.adb, prj-env.adb:
(Debug_Output): new function.

Index: prj-part.adb
===
--- prj-part.adb(revision 177055)
+++ prj-part.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 2001-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 2001-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- --
@@ -1308,10 +1308,7 @@
   end if;
 
   if Current_Verbosity >= Medium then
- Write_Str  ("Parsing """);
- Write_Str  (Path_Name);
- Write_Char ('"');
- Write_Eol;
+ Debug_Increase_Indent ("Parsing """ & Path_Name & '"');
   end if;
 
   Project_Directory :=
@@ -1882,6 +1879,8 @@
   --  And restore the comment state that was saved
 
   Tree.Restore_And_Free (Project_Comment_State);
+
+  Debug_Decrease_Indent ("Done parsing project");
end Parse_Single_Project;
 
---
@@ -1899,9 +1898,7 @@
 
begin
   if Current_Verbosity = High then
- Write_Str ("Project_Name_From (""");
- Write_Str (Canonical);
- Write_Line (""")");
+ Debug_Output ("Project_Name_From (""" & Canonical & """)");
   end if;
 
   --  If the path name is empty, return No_Name to indicate failure
Index: prj.adb
===
--- prj.adb (revision 176998)
+++ prj.adb (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 2001-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 2001-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- --
@@ -48,6 +48,9 @@
 
The_Empty_String : Name_Id := No_Name;
 
+   Debug_Level : Integer := 0;
+   --  Current indentation level for debug traces.
+
type Cst_String_Access is access constant String;
 
All_Lower_Case_Image : aliased constant String := "lowercase";
@@ -1300,6 +1303,77 @@
   return Count;
end Length;
 
+   --
+   -- Debug_Output --
+   --
+
+   procedure Debug_Output (Str : String) is
+   begin
+  if Current_Verbosity > Default then
+ Write_Line ((1 .. Debug_Level * 2 => ' ') & Str);
+  end if;
+   end Debug_Output;
+
+   --
+   -- Debug_Indent --
+   --
+
+   procedure Debug_Indent is
+   begin
+  if Current_Verbosity = High then
+ Write_Str ((1 .. Debug_Level * 2 => ' '));
+  end if;
+   end Debug_Indent;
+
+   --
+   -- Debug_Output --
+   --
+
+   procedure Debug_Output (Str : String; Str2 : Name_Id) is
+   begin
+  if Current_Verbosity = High then
+ Debug_Indent;
+ Write_Str (Str);
+
+ if Str2 = No_Name then
+Write_Line (" ");
+ else
+Write_Line (" """ & Get_Name_String (Str2) & '"');
+ end if;
+  end if;
+   end Debug_Output;
+
+   ---
+   -- Debug_Increase_Indent --
+   ---
+
+   procedure Debug_Increase_Indent
+ (Str : String := ""; Str2 : Name_Id := No_Name)
+   is
+   begin
+  if Str2 /= No_Name then
+ Debug_Output (Str, Str2);
+  else
+ Debug_Output (Str);
+  end if;
+  Debug_Level := Debug_Level + 1;
+   end Debug_Increase_Indent;
+
+   ---
+   -- Debug_Decrease_Indent --
+   ---
+
+   procedure Debug_Decrease_Indent (Str : String := "") is
+   begin
+  if Debug_Level > 0 then
+ Debug_Level := Debug_Level - 1;
+  end if;
+
+  if Str /= "" then
+ Debug_Output (Str);
+  end if;
+   end Debug_Decrease_Indent;
+
 begin
--  Make sure that the standard config and user projec

[Ada] Remove Target_Name parameter in subprograms

2011-08-03 Thread Arnaud Charlet
In prj.env, several subprograms were taking a Target_Name parameter,
only so that they could initialize the project path if not already done.
We now request that the project path first be initialized. This is slightly
more efficient, but more importantly simplifies the API a bit. It will
also be required for aggregate projects, which should not use the default
project path, only the directories specified in the aggregate project itself.

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

2011-08-03  Emmanuel Briot  

* gnatcmd.adb, make.adb, prj-part.adb, prj-part.ads, prj-makr.adb,
clean.adb, prj-nmsc.adb, prj-pars.adb, prj-conf.adb, prj-env.adb,
prj-env.ads (Prj.Env.Initialize_Default_Project_Path,
Prj.Env.Initialize_Empty): new subprograms
(Get_Env, Find_Project): remove parameter Target_Name.

Index: gnatcmd.adb
===
--- gnatcmd.adb (revision 177131)
+++ gnatcmd.adb (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1996-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1996-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- --
@@ -1365,6 +1365,9 @@
Snames.Initialize;
 
Project_Node_Tree := new Project_Node_Tree_Data;
+   Prj.Env.Initialize_Default_Project_Path
+  (Project_Node_Tree.Project_Path, Target_Name => "");
+
Prj.Tree.Initialize (Project_Node_Tree);
 
Prj.Initialize (Project_Tree);
Index: make.adb
===
--- make.adb(revision 177151)
+++ make.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -6636,6 +6636,9 @@
   --  the command line switches
 
   Project_Node_Tree := new Project_Node_Tree_Data;
+  Prj.Env.Initialize_Default_Project_Path
+ (Project_Node_Tree.Project_Path, Target_Name => "");
+
   Prj.Tree.Initialize (Project_Node_Tree);
 
   --  Override default initialization of Check_Object_Consistency since
Index: prj-part.adb
===
--- prj-part.adb(revision 177240)
+++ prj-part.adb(working copy)
@@ -185,8 +185,7 @@
   Depth : Natural;
   Current_Dir   : String;
   Is_Config_File: Boolean;
-  Flags : Processing_Flags;
-  Target_Name   : String);
+  Flags : Processing_Flags);
--  Parse a project file. This is a recursive procedure: it calls itself for
--  imported and extended projects. When From_Extended is not None, if the
--  project has already been parsed and is an extended project A, return the
@@ -221,8 +220,7 @@
   Depth : Natural;
   Current_Dir   : String;
   Is_Config_File: Boolean;
-  Flags : Processing_Flags;
-  Target_Name   : String);
+  Flags : Processing_Flags);
--  Parse the imported projects that have been stored in table Withs, if
--  any. From_Extended is used for the call to Parse_Single_Project below.
--  When In_Limited is True, the importing path includes at least one
@@ -451,7 +449,7 @@
   Current_Directory  : String := "";
   Is_Config_File : Boolean;
   Flags  : Processing_Flags;
-  Target_Name: String)
+  Target_Name: String := "")
is
   Dummy : Boolean;
   pragma Warnings (Off, Dummy);
@@ -462,6 +460,11 @@
   Path_Name_Id : Path_Name_Type;
 
begin
+  if not Is_Initialized (In_Tree.Project_Path) then
+ Prj.Env.Initialize_Default_Project_Path
+   (In_Tree.Project_Path, Target_Name);
+  end if;
+
   if Real_Project_File_Name = null then
  Real_Project_File_Name := new String'(Project_File_Name);
   end if;
@@ -471,8 +474,7 @@
   Find_Project (In_Tree.Project_Path,

Re: [patch tree-optimization]: Add cleanup code for possible unused statements in binary optimization

2011-08-03 Thread Richard Guenther
On Tue, Aug 2, 2011 at 5:40 PM, Kai Tietz  wrote:
> 2011/8/2 Richard Guenther :
>> On Tue, Aug 2, 2011 at 12:39 PM, Kai Tietz  wrote:
>
> Thanks, yes, I noticed that.  Patch adjusted for cfg_tree.

What about my other comment?

> ChangeLog
>
> 2011-08-02  Kai Tietz  
>
>         * tree-ssa-forwprop.c (simplify_bitwise_binary):
>         Remove possible unused statement after optimization
>       and change result to indicate cfg-tree change.
>       (ssa_forward_propagate_and_combine): Adjust handling for
>       simplify_bitwise_binary call.
>
> 2011-08-02  Kai Tietz  
>
>         * gcc.dg/tree-ssa/forwprop-15.c: Add test for no int casts.
>
> Bootstrapped and regression-tested for all languages (including Ada
> and Obj-C++) on host x86_64-pc-linux-gnu.
> Ok for apply?
>
> Index: gcc/gcc/tree-ssa-forwprop.c
> ===
> --- gcc.orig/gcc/tree-ssa-forwprop.c
> +++ gcc/gcc/tree-ssa-forwprop.c
> @@ -1703,9 +1703,10 @@ simplify_bitwise_binary_1 (enum tree_cod
>  }
>
>  /* Simplify bitwise binary operations.
> -   Return true if a transformation applied, otherwise return false.  */
> +   Returns 1 if there were any changes made, 2 if cfg-cleanup needs to
> +   run.  Else it returns 0.  */
>
> -static bool
> +static int
>  simplify_bitwise_binary (gimple_stmt_iterator *gsi)
>  {
>   gimple stmt = gsi_stmt (*gsi);
> @@ -1716,6 +1717,7 @@ simplify_bitwise_binary (gimple_stmt_ite
>   gimple def1 = NULL, def2 = NULL;
>   tree def1_arg1, def2_arg1;
>   enum tree_code def1_code, def2_code;
> +  bool ischanged = false;
>
>   def1_code = TREE_CODE (arg1);
>   def1_arg1 = arg1;
> @@ -1761,24 +1763,23 @@ simplify_bitwise_binary (gimple_stmt_ite
>       gimple_assign_set_rhs_with_ops_1 (gsi, NOP_EXPR,
>                                        tem, NULL_TREE, NULL_TREE);
>       update_stmt (gsi_stmt (*gsi));
> -      return true;
> +      ischanged = true;
>     }
> -
>   /* For bitwise binary operations apply operand conversions to the
>      binary operation result instead of to the operands.  This allows
>      to combine successive conversions and bitwise binary operations.  */
> -  if (CONVERT_EXPR_CODE_P (def1_code)
> -      && CONVERT_EXPR_CODE_P (def2_code)
> -      && types_compatible_p (TREE_TYPE (def1_arg1), TREE_TYPE (def2_arg1))
> -      /* Make sure that the conversion widens the operands, or has same
> -        precision,  or that it changes the operation to a bitfield
> -        precision.  */
> -      && ((TYPE_PRECISION (TREE_TYPE (def1_arg1))
> -          <= TYPE_PRECISION (TREE_TYPE (arg1)))
> -         || (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (arg1)))
> -             != MODE_INT)
> -         || (TYPE_PRECISION (TREE_TYPE (arg1))
> -             != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (arg1))
> +  else if (CONVERT_EXPR_CODE_P (def1_code)
> +          && CONVERT_EXPR_CODE_P (def2_code)
> +          && types_compatible_p (TREE_TYPE (def1_arg1), TREE_TYPE 
> (def2_arg1))
> +          /* Make sure that the conversion widens the operands, or has same
> +             precision,  or that it changes the operation to a bitfield
> +             precision.  */
> +          && ((TYPE_PRECISION (TREE_TYPE (def1_arg1))
> +               <= TYPE_PRECISION (TREE_TYPE (arg1)))
> +              || (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (arg1)))
> +                  != MODE_INT)
> +              || (TYPE_PRECISION (TREE_TYPE (arg1))
> +                  != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (arg1))
>     {
>       gimple newop;
>       tree tem = create_tmp_reg (TREE_TYPE (def1_arg1),
> @@ -1791,77 +1792,84 @@ simplify_bitwise_binary (gimple_stmt_ite
>       gimple_assign_set_rhs_with_ops_1 (gsi, NOP_EXPR,
>                                        tem, NULL_TREE, NULL_TREE);
>       update_stmt (gsi_stmt (*gsi));
> -      return true;
> +      ischanged = true;
>     }
> -
>   /* (a | CST1) & CST2  ->  (a & CST2) | (CST1 & CST2).  */
> -  if (code == BIT_AND_EXPR
> -      && def1_code == BIT_IOR_EXPR
> -      && TREE_CODE (arg2) == INTEGER_CST
> -      && TREE_CODE (gimple_assign_rhs2 (def1)) == INTEGER_CST)
> +  else if (code == BIT_AND_EXPR
> +          && def1_code == BIT_IOR_EXPR
> +          && TREE_CODE (arg2) == INTEGER_CST
> +          && TREE_CODE (gimple_assign_rhs2 (def1)) == INTEGER_CST)
>     {
>       tree cst = fold_build2 (BIT_AND_EXPR, TREE_TYPE (arg2),
>                              arg2, gimple_assign_rhs2 (def1));
>       tree tem;
>       gimple newop;
>       if (integer_zerop (cst))
> -       {
> -         gimple_assign_set_rhs1 (stmt, def1_arg1);
> -         update_stmt (stmt);
> -         return true;
> +       gimple_assign_set_rhs1 (stmt, def1_arg1);
> +      else
> +        {
> +         tem = create_tmp_reg (TREE_TYPE (arg2), NULL);
> +         newop = gimple_build_assign_with_ops (BIT_AND_EXPR,
> +                                               tem, def1_arg1, arg2);
> +         tem = make_ssa_name (tem, newop);
> +     

[Ada] fix traceback computation stop condition for ppc-aix

2011-08-03 Thread Arnaud Charlet
This change adjusts the traceback stop condition for ppc-aix to stop
at null return addresses, sometimes encountered alone (with the associated
backchain pointer not null) to indicate a toplevel frame. 

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

2011-08-03  Olivier Hainque  

* tracebak.c (STOP_FRAME ppc AIX): Stop at null return address as well.

Index: tracebak.c
===
--- tracebak.c  (revision 176998)
+++ tracebak.c  (working copy)
@@ -219,8 +219,15 @@
 
 #define FRAME_OFFSET(FP) 0
 #define PC_ADJUST -4
-#define STOP_FRAME(CURRENT, TOP_STACK) ((void *) (CURRENT) < (TOP_STACK))
 
+/* Eventhough the base PPC ABI states that a toplevel frame entry
+   should to feature a null backchain, AIX might expose a null return
+   address instead.  */
+
+#define STOP_FRAME(CURRENT, TOP_STACK) \
+  (((void *) (CURRENT) < (TOP_STACK)) \
+   || (CURRENT)->return_address == NULL)
+
 /* The PPC ABI has an interesting specificity: the return address saved by a
function is located in it's caller's frame, and the save operation only
takes place if the function performs a call.


[Ada] Double free in GNAT.Perfect_Hash_Generators.Finalize

2011-08-03 Thread Arnaud Charlet
This change prevents a potential double free in Finalize, which
can cause gnatprfh to crash on some platforms.

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

2011-08-03  Thomas Quinot  

* g-pehage.adb (Finalize): Avoid possible double-free.

Index: g-pehage.adb
===
--- g-pehage.adb(revision 177040)
+++ g-pehage.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
--- Copyright (C) 2002-2010, AdaCore --
+-- Copyright (C) 2002-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- --
@@ -103,7 +103,7 @@
No_Table  : constant Table_Id  := -1;
 
type Word_Type is new String_Access;
-   procedure Free_Word (W : in out Word_Type);
+   procedure Free_Word (W : in out Word_Type) renames Free;
function New_Word (S : String) return Word_Type;
 
procedure Resize_Word (W : in out Word_Type; Len : Natural);
@@ -913,8 +913,14 @@
   --  ones) to avoid memory leaks.
 
   for W in 0 .. WT.Last loop
- Free_Word (WT.Table (W));
+ --  Note: WT.Table (NK) is a temporary variable, do not free it since
+ --  this would cause a double free.
+
+ if W /= NK then
+Free_Word (WT.Table (W));
+ end if;
   end loop;
+
   WT.Release;
   IT.Release;
 
@@ -948,17 +954,6 @@
   Min_Key_Len := 0;
end Finalize;
 
-   ---
-   -- Free_Word --
-   ---
-
-   procedure Free_Word (W : in out Word_Type) is
-   begin
-  if W /= null then
- Free (W);
-  end if;
-   end Free_Word;
-

-- Generate_Mapping_Table --

@@ -1258,6 +1253,11 @@
   --  explicitly initialized to null.
 
   WT.Set_Last (Reduced (NK - 1));
+
+  --  Note: Reduced (0) = NK + 1
+
+  WT.Table (NK) := null;
+
   for W in 0 .. NK - 1 loop
  WT.Table (Reduced (W)) := null;
   end loop;


[Ada] Flatten aggregates with no static bounds and no others choice

2011-08-03 Thread Arnaud Charlet
This patch does not affect the behavior of native compilers. It
extends the cases in which aggregates are internally converted
into purely positional form, which helps the backend of VM
compilers.

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

2011-08-03  Javier Miranda  

* exp_aggr.adb (Flatten): Convert to positional form aggregates whose
low bound is not known at compile time but they have no others choice.
Done because in this case the bounds can be obtained directly from the
aggregate.

Index: exp_aggr.adb
===
--- exp_aggr.adb(revision 177240)
+++ exp_aggr.adb(working copy)
@@ -3825,6 +3825,8 @@
  Lov : Uint;
  Hiv : Uint;
 
+ Others_Present : Boolean := False;
+
   begin
  if Nkind (Original_Node (N)) = N_String_Literal then
 return True;
@@ -3839,8 +3841,44 @@
  Lov := Expr_Value (Lo);
  Hiv := Expr_Value (Hi);
 
+ --  Check if there is an others choice
+
+ if Present (Component_Associations (N)) then
+declare
+   Assoc   : Node_Id;
+   Choice  : Node_Id;
+
+begin
+   Assoc := First (Component_Associations (N));
+   while Present (Assoc) loop
+  Choice := First (Choices (Assoc));
+
+  while Present (Choice) loop
+ if Nkind (Choice) = N_Others_Choice then
+Others_Present := True;
+ end if;
+
+ Next (Choice);
+  end loop;
+
+  Next (Assoc);
+   end loop;
+end;
+ end if;
+
+ --  If the low bound is not known at compile time and others is not
+ --  present we can proceed since the bounds can be obtained from the
+ --  aggregate.
+
+ --  Note: This case is required in VM platforms since their backends
+ --  normalize array indexes in the range 0 .. N-1. Hence, if we do
+ --  not flat an array whose bounds cannot be obtained from the type
+ --  of the index the backend has no way to properly generate the code.
+ --  See ACATS c460010 for an example.
+
  if Hiv < Lov
-   or else not Compile_Time_Known_Value (Blo)
+   or else (not Compile_Time_Known_Value (Blo)
+ and then Others_Present)
  then
 return False;
  end if;


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

2011-08-03 Thread Ilya Enkovich
Ping.

2011/7/26 Ilya Enkovich :
> Hello,
>
> Here is updated patch for tree reassoc phase. Update includes coding
> style fixes, comments update, target hook arguments change. I also
> moved a part of code from rewrite_expr_tree into separate function to
> reuse it in rewrite_expr_tree_parallel for grouping operands with the
> same rank.
>
> Bootstrapped and checked on x86_64-linux.
>
> Ilya
> --
> gcc/
>
> 2011-07-26  Enkovich Ilya  
>
>        PR middle-end/44382
>        * target.def (reassociation_width): New hook.
>
>        * doc/tm.texi.in (reassociation_width): Likewise.
>
>        * doc/tm.texi (reassociation_width): Likewise.
>
>        * doc/invoke.texi (tree-reassoc-width): New param documented.
>
>        * hooks.h (hook_int_uint_mode_1): New default hook.
>
>        * hooks.c (hook_int_uint_mode_1): Likewise.
>
>        * config/i386/i386.h (ix86_tune_indices): Add
>        X86_TUNE_REASSOC_INT_TO_PARALLEL and
>        X86_TUNE_REASSOC_FP_TO_PARALLEL.
>
>        (TARGET_REASSOC_INT_TO_PARALLEL): New.
>        (TARGET_REASSOC_FP_TO_PARALLEL): Likewise.
>
>        * config/i386/i386.c (initial_ix86_tune_features): Add
>        X86_TUNE_REASSOC_INT_TO_PARALLEL and
>        X86_TUNE_REASSOC_FP_TO_PARALLEL.
>
>        (ix86_reassociation_width) implementation of
>        new hook for i386 target.
>
>        * params.def (PARAM_TREE_REASSOC_WIDTH): New param added.
>
>        * tree-ssa-reassoc.c (get_required_cycles): New function.
>        (get_reassociation_width): Likewise.
>        (swap_ops_for_binary_stmt): Likewise.
>        (rewrite_expr_tree_parallel): Likewise.
>
>        (rewrite_expr_tree): Refactored. Part of code moved into
>        swap_ops_for_binary_stmt.
>
>        (reassociate_bb): Now checks reassociation width to be used
>        and call rewrite_expr_tree_parallel instead of rewrite_expr_tree
>        if needed.
>
>        (pass_reassoc): TODO_remove_unused_locals flag added.
>
> gcc/testsuite/
>
> 2011-07-26  Enkovich Ilya  
>
>        * gcc.dg/tree-ssa/pr38533.c (dg-options): Added option
>        --param tree-reassoc-width=1.
>
>        * gcc.dg/tree-ssa/reassoc-24.c: New test.
>        * gcc.dg/tree-ssa/reassoc-25.c: Likewise.
>


[PATCH, gomp]: Unbreak bootstrap on glibc-2.5

2011-08-03 Thread Uros Bizjak
Hello!

We should not call CPU_COUNT when not defined in glibc.

2011-08-03  Uros Bizjak  

* config/linux/proc.c (gomp_cpuset_popcount): Rename from
cpuset_popcount.  No more static.
(gomp_init_num_threads): Update call to cpuset_popcount.
(get_num_procs): Ditto.
* config/linux/affinity.c: Call gomp_cpuset_popcount.
* libgomp.h (gomp_cpuset_popcount): Declare.

Bootstrapped on x86_64-pc-linux-gnu, testing in progress.

OK if it passes?

Uros.
Index: libgomp.h
===
--- libgomp.h   (revision 177229)
+++ libgomp.h   (working copy)
@@ -463,6 +463,10 @@ extern unsigned gomp_resolve_num_threads
 
 /* proc.c (in config/) */
 
+#ifdef HAVE_PTHREAD_AFFINITY_NP
+extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
+#endif
+
 extern void gomp_init_num_threads (void);
 extern unsigned gomp_dynamic_max_threads (void);
 
Index: config/linux/proc.c
===
--- config/linux/proc.c (revision 177229)
+++ config/linux/proc.c (working copy)
@@ -40,8 +40,8 @@
 #endif
 
 #ifdef HAVE_PTHREAD_AFFINITY_NP
-static unsigned long
-cpuset_popcount (cpu_set_t *cpusetp)
+unsigned long
+gomp_cpuset_popcount (cpu_set_t *cpusetp)
 {
 #ifdef CPU_COUNT
   /* glibc 2.6 and above provide a macro for this.  */
@@ -76,7 +76,7 @@ gomp_init_num_threads (void)
   if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset), &cpuset) == 0)
 {
   /* Count only the CPUs this process can use.  */
-  gomp_global_icv.nthreads_var = cpuset_popcount (&cpuset);
+  gomp_global_icv.nthreads_var = gomp_cpuset_popcount (&cpuset);
   if (gomp_global_icv.nthreads_var == 0)
gomp_global_icv.nthreads_var = 1;
   return;
@@ -99,7 +99,7 @@ get_num_procs (void)
   if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset),
  &cpuset) == 0)
{
- int ret = cpuset_popcount (&cpuset);
+ int ret = gomp_cpuset_popcount (&cpuset);
  return ret != 0 ? ret : 1;
}
 }
Index: config/linux/affinity.c
===
--- config/linux/affinity.c (revision 177229)
+++ config/linux/affinity.c (working copy)
@@ -56,7 +56,7 @@ gomp_init_affinity (void)
   CPU_ZERO (&cpusetnew);
   if (gomp_cpu_affinity_len == 0)
 {
-  unsigned long count = CPU_COUNT (&cpuset);
+  unsigned long count = gomp_cpuset_popcount (&cpuset);
   if (count >= 65536)
count = 65536;
   gomp_cpu_affinity = malloc (count * sizeof (unsigned short));


Re: [PATCH, gomp]: Unbreak bootstrap on glibc-2.5

2011-08-03 Thread Jakub Jelinek
On Wed, Aug 03, 2011 at 10:36:47AM +0200, Uros Bizjak wrote:
> We should not call CPU_COUNT when not defined in glibc.

Oops, forgot that old glibcs don't have it.

> 2011-08-03  Uros Bizjak  
> 
>   * config/linux/proc.c (gomp_cpuset_popcount): Rename from
>   cpuset_popcount.  No more static.
>   (gomp_init_num_threads): Update call to cpuset_popcount.
>   (get_num_procs): Ditto.
>   * config/linux/affinity.c: Call gomp_cpuset_popcount.
>   * libgomp.h (gomp_cpuset_popcount): Declare.
> 
> Bootstrapped on x86_64-pc-linux-gnu, testing in progress.
> 
> OK if it passes?

I don't like the prototype in libgomp.h, for one sched.h isn't included
in libgomp.h thus cpu_set_t is not defined type.  Plus it isn't a generic
API, but a Linux private function.
So, IMHO either just don't provide any prototype in a header
and put
extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
into config/linux/affinity.c, or introduce
config/linux/proc.h header containing
#include 
#ifdef HAVE_PTHREAD_AFFINITY_NP
extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
#endif
and
#include "config/linux/proc.h"
in config/linux/{proc.c,affinity.c}.
Ok with those changes, thanks.

Jakub


[Ada] Change of profile for Prj.Part.Parse

2011-08-03 Thread Arnaud Charlet
The new parameter makes it possible, while processing aggregate projects,
to stop the processing as soon as an error is found in one of the
aggregated projects.

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

2011-08-03  Emmanuel Briot  

* prj-part.adb, prj-part.ads, prj-makr.adb, prj-pars.adb, prj-conf.adb,
prj-env.adb (Prj.Part.Parse): change parameter Always_Errout_Finalize
to Errout_Handling.

Index: prj-part.adb
===
--- prj-part.adb(revision 177243)
+++ prj-part.adb(working copy)
@@ -443,7 +443,7 @@
  (In_Tree: Project_Node_Tree_Ref;
   Project: out Project_Node_Id;
   Project_File_Name  : String;
-  Always_Errout_Finalize : Boolean;
+  Errout_Handling: Errout_Mode := Always_Finalize;
   Packages_To_Check  : String_List_Access := All_Packages;
   Store_Comments : Boolean := False;
   Current_Directory  : String := "";
@@ -477,7 +477,10 @@
 Path  => Path_Name_Id);
   Free (Real_Project_File_Name);
 
-  Prj.Err.Initialize;
+  if Errout_Handling /= Never_Finalize then
+ Prj.Err.Initialize;
+  end if;
+
   Prj.Err.Scanner.Set_Comment_As_Token (Store_Comments);
   Prj.Err.Scanner.Set_End_Of_Line_As_Token (Store_Comments);
 
@@ -607,14 +610,23 @@
  Project := Empty_Node;
   end if;
 
-  if No (Project) or else Always_Errout_Finalize then
- Prj.Err.Finalize;
+  case Errout_Handling is
+ when Always_Finalize =>
+Prj.Err.Finalize;
 
- --  Reinitialize to avoid duplicate warnings later on
+--  Reinitialize to avoid duplicate warnings later on
+Prj.Err.Initialize;
 
- Prj.Err.Initialize;
-  end if;
+ when Finalize_If_Error =>
+if No (Project) then
+   Prj.Err.Finalize;
+   Prj.Err.Initialize;
+end if;
 
+ when Never_Finalize =>
+null;
+  end case;
+
exception
   when X : others =>
 
Index: prj-part.ads
===
--- prj-part.ads(revision 177241)
+++ prj-part.ads(working copy)
@@ -29,11 +29,19 @@
 
 package Prj.Part is
 
+   type Errout_Mode is
+ (Always_Finalize,
+  Finalize_If_Error,
+  Never_Finalize);
+   --  Whether Parse should call Errout.Finalize (which prints the error
+   --  messages on stdout). When Never_Finalize is used, Errout is not reset
+   --  either at the beginning of Parse.
+
procedure Parse
  (In_Tree: Project_Node_Tree_Ref;
   Project: out Project_Node_Id;
   Project_File_Name  : String;
-  Always_Errout_Finalize : Boolean;
+  Errout_Handling: Errout_Mode := Always_Finalize;
   Packages_To_Check  : String_List_Access := All_Packages;
   Store_Comments : Boolean := False;
   Current_Directory  : String := "";
Index: prj-makr.adb
===
--- prj-makr.adb(revision 177241)
+++ prj-makr.adb(working copy)
@@ -863,7 +863,7 @@
   (In_Tree=> Tree,
Project=> Project_Node,
Project_File_Name  => Output_Name.all,
-   Always_Errout_Finalize => False,
+   Errout_Handling=> Part.Finalize_If_Error,
Store_Comments => True,
Is_Config_File => False,
Flags  => Flags,
Index: prj-pars.adb
===
--- prj-pars.adb(revision 177241)
+++ prj-pars.adb(working copy)
@@ -72,7 +72,7 @@
 (In_Tree=> Project_Node_Tree,
  Project=> Project_Node,
  Project_File_Name  => Project_File_Name,
- Always_Errout_Finalize => False,
+ Errout_Handling=> Prj.Part.Finalize_If_Error,
  Packages_To_Check  => Packages_To_Check,
  Current_Directory  => Current_Dir,
  Flags  => Flags,
Index: prj-conf.adb
===
--- prj-conf.adb(revision 177241)
+++ prj-conf.adb(working copy)
@@ -1119,7 +1119,7 @@
(In_Tree=> Project_Node_Tree,
 Project=> Config_Project_Node,
 Project_File_Name  => Config_File_Path.all,
-Always_Errout_Finalize => False,
+Errout_Handling=> Prj.Part.Finalize_If_Error,
 Packages_To_Check  => Packages_To_Check,
 Current_Directory  => Current_Directory,
 Is_Config_File => True,
@@ -1212,7 +1212,7 @@
 (In_Tree  

[Ada] New type Prj.Ext.External_References

2011-08-03 Thread Arnaud Charlet
This type was introduced so that we can have two sets of environment
variables when manipulating aggregate projects (one for the aggregate,
one for the aggregated projects).
But we can have more than two project trees, since we have one per
aggregated project. So creating a new type makes it possible to share
it between trees.

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

2011-08-03  Emmanuel Briot  

* prj-proc.adb, prj-ext.adb, prj-ext.ads, makeutl.adb, prj-tree.adb,
prj-tree.ads, gnatcmd.adb, clean.adb (External_References): New type.

Index: prj-proc.adb
===
--- prj-proc.adb(revision 177243)
+++ prj-proc.adb(working copy)
@@ -1065,7 +1065,7 @@
   if Ext_List then
  Value :=
Prj.Ext.Value_Of
- (From_Project_Node_Tree, Name, No_Name);
+ (From_Project_Node_Tree.External, Name, No_Name);
 
  if Value /= No_Name then
 declare
@@ -1171,7 +1171,7 @@
 
  Value :=
Prj.Ext.Value_Of
- (From_Project_Node_Tree, Name, Default);
+ (From_Project_Node_Tree.External, Name, Default);
 
  if Value = No_Name then
 if not Quiet_Output then
Index: prj-ext.adb
===
--- prj-ext.adb (revision 176998)
+++ prj-ext.adb (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 2000-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 2000-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- --
@@ -23,31 +23,65 @@
 --  --
 --
 
+with Ada.Unchecked_Deallocation;
 with Osint;use Osint;
-with Prj.Tree; use Prj.Tree;
 
 package body Prj.Ext is
 
+   
+   -- Initialize --
+   
+
+   procedure Initialize
+ (Self  : out External_References;
+  Copy_From : External_References := No_External_Refs)
+   is
+  N  : Name_To_Name_Ptr;
+  N2 : Name_To_Name_Ptr;
+   begin
+  if Self.Refs = null then
+ Self.Refs := new Name_To_Name_HTable.Instance;
+
+ if Copy_From.Refs /= null then
+N := Name_To_Name_HTable.Get_First (Copy_From.Refs.all);
+while N /= null loop
+   N2 := new Name_To_Name;
+   N2.Key := N.Key;
+   N2.Value := N.Value;
+   Name_To_Name_HTable.Set (Self.Refs.all, N2);
+   N := Name_To_Name_HTable.Get_Next (Copy_From.Refs.all);
+end loop;
+ end if;
+  end if;
+   end Initialize;
+
-
-- Add --
-
 
procedure Add
- (Tree  : Prj.Tree.Project_Node_Tree_Ref;
+ (Self  : External_References;
   External_Name : String;
   Value : String)
is
-  The_Key   : Name_Id;
-  The_Value : Name_Id;
+  N : Name_To_Name_Ptr;
begin
+  N := new Name_To_Name;
+
   Name_Len := Value'Length;
   Name_Buffer (1 .. Name_Len) := Value;
-  The_Value := Name_Find;
+  N.Value := Name_Find;
+
   Name_Len := External_Name'Length;
   Name_Buffer (1 .. Name_Len) := External_Name;
   Canonical_Case_Env_Var_Name (Name_Buffer (1 .. Name_Len));
-  The_Key := Name_Find;
-  Name_To_Name_HTable.Set (Tree.External_References, The_Key, The_Value);
+  N.Key := Name_Find;
+
+  if Current_Verbosity = High then
+ Debug_Output ("Add (" & External_Name & ") is", N.Value);
+  end if;
+
+  Name_To_Name_HTable.Set (Self.Refs.all, N);
end Add;
 
---
@@ -55,7 +89,7 @@
---
 
function Check
- (Tree: Prj.Tree.Project_Node_Tree_Ref;
+ (Self: External_References;
   Declaration : String) return Boolean
is
begin
@@ -63,7 +97,7 @@
  if Declaration (Equal_Pos) = '=' then
 exit when Equal_Pos = Declaration'First;
 Add
-  (Tree  => Tree,
+  (Self  => Self,
External_Name =>
  Declaration (Declaration'First .. Equal_Pos - 1),
Value =>
@@ -79,9 +113,12 @@
-- Reset --
---
 
-   procedure Rese

Re: [Patch, Fortran] PR fortran/49885: Fix automatic character array allocation

2011-08-03 Thread Daniel Kraft
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 08/02/11 22:04, Tobias Burnus wrote:
> Daniel Kraft wrote:
>> No regressions on x86_64-unknown-linux-gnu.  Ok for trunk?
> 
> OK for the trunk and for 4.6 (as it is a regression).

And committed on 4.6 branch as rev. 177249, there also were no
regressions on x86_64-unknown-linux-gnu.

I'll close the PR now.

Yours,
Daniel

- -- 
OpenPGP: 3BA2 3DDB 7758 F010 BDAB 0DCF 527E 79BA A3B5 3998
or use https://safesend.domob.eu/
- --
Done:  Arc-Bar-Cav-Kni-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Mon-Pri
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOORgiAAoJEFJ+ebqjtTmYYAsP/i2U3SaqOMAQe75hg6/e4GaN
6Fq2svUk7wN5ooMN+01zNYKi1igeqOKGyLpEycMJAseZ8bYn6C2KtXWuJdNN+JGl
u2e95FkrkHSwO6a3jGYBSFXeor3/fUsk8TPKEyk12Be61C4p6mlgnCyNj6OadSZs
Okujz3VCFj0FEtoD2FO+JAOtHMuDY/PW8sZR0M8hlJzGme2INpEf5J57/hSQk7EP
X7TSMiy1/i9cmAHS91VGN8PTcRQo6y3vI+PN2ymZ8EAY0WPNeyUQO4Q5NDV9XP1T
yRi6NDGWLDjOReXy0ne80NrZWCUQi8ihMPqa/QXDlsF5h60hkHMqwfXX9rvxw6Kc
jLELEGqP3kTgBZuBfN3wCZwd8FSakc1vBBgfKkOEel3xw1DCa+9fp0Bz+CO9Zc3E
vbLns2GHvJg+hVu495BZlgC16MhbxzJLM4uTMoL4NsR+vazS71w4fSlh2lWvQrQr
CdMILamqsm4MZmc5z6SH7zD2aMWCVt/k7isSfj7kAtvYdXg0xnIxDPBgI28c7oTm
OU/o53es91Y3cj4ISilqooZIEwUKvt+cRJF851j0ZfsVp3iDFlatraHCQGYTM/5s
EyboGV7mpos4BOxx2V5XroviHR2D6t4NRVoZnBgpQUEeAH82oAGAMiQGVMOsYpH4
MIaKxOcSL0G/JVhQb1uF
=FK7V
-END PGP SIGNATURE-



smime.p7s
Description: S/MIME Cryptographic Signature


[Ada] avoid incorrect lower casing of attribute names in some cases

2011-08-03 Thread Arnaud Charlet
The change to Get_Attribute_Index avoids an incorrect lower casing
of the external variable name when using the new "External" attribute in
aggregate projects.

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

2011-08-03  Emmanuel Briot  

* prj-proc.adb, prj-attr.adb, prj-attr.ads (Get_Attribute_Index): do
not systematically lower case attribute indexes that contain no "."
Fix definition of several Naming attributes, which take
a unit name as index and therefore should be case insensitive.
Minor refactoring (reduce length of variable names).

Index: prj-proc.adb
===
--- prj-proc.adb(revision 177248)
+++ prj-proc.adb(working copy)
@@ -458,41 +458,19 @@
-
 
function Get_Attribute_Index
- (Tree  : Project_Node_Tree_Ref;
-  Attr  : Project_Node_Id;
-  Index : Name_Id) return Name_Id
-   is
-  Lower : Boolean;
-
+ (Tree   : Project_Node_Tree_Ref;
+  Attr   : Project_Node_Id;
+  Index  : Name_Id) return Name_Id is
begin
-  if Index = All_Other_Names then
+  if Index = All_Other_Names
+or else not Case_Insensitive (Attr, Tree)
+  then
  return Index;
   end if;
 
   Get_Name_String (Index);
-  Lower := Case_Insensitive (Attr, Tree);
-
-  --  The index is always case insensitive if it does not include any dot.
-  --  ??? Why not use the properties from prj-attr, simply, maybe because
-  --  we don't know whether we have a file as an index?
-
-  if not Lower then
- Lower := True;
-
- for J in 1 .. Name_Len loop
-if Name_Buffer (J) = '.' then
-   Lower := False;
-   exit;
-end if;
- end loop;
-  end if;
-
-  if Lower then
- To_Lower (Name_Buffer (1 .. Name_Len));
- return Name_Find;
-  else
- return Index;
-  end if;
+  To_Lower (Name_Buffer (1 .. Name_Len));
+  return Name_Find;
end Get_Attribute_Index;
 

@@ -1440,7 +1418,7 @@
   procedure Process_Expression
 (Current : Project_Node_Id);
   procedure Process_Expression_For_Associative_Array
-(Current_Item : Project_Node_Id;
+(Current : Project_Node_Id;
  New_Value: Variable_Value);
   procedure Process_Expression_Variable_Decl
 (Current_Item : Project_Node_Id;
@@ -1869,29 +1847,25 @@
   --
 
   procedure Process_Expression_For_Associative_Array
-(Current_Item : Project_Node_Id;
- New_Value: Variable_Value)
+(Current   : Project_Node_Id;
+ New_Value : Variable_Value)
   is
- Current_Item_Name : constant Name_Id :=
-   Name_Of (Current_Item, Node_Tree);
+ Name : constant Name_Id := Name_Of (Current, Node_Tree);
  Current_Location : constant Source_Ptr :=
-   Location_Of (Current_Item, Node_Tree);
+   Location_Of (Current, Node_Tree);
 
  Index_Name : Name_Id :=
-   Associative_Array_Index_Of (Current_Item, Node_Tree);
+   Associative_Array_Index_Of (Current, Node_Tree);
 
  Source_Index : constant Int :=
-   Source_Index_Of (Current_Item, Node_Tree);
+   Source_Index_Of (Current, Node_Tree);
 
- The_Array : Array_Id;
- The_Array_Element : Array_Element_Id := No_Array_Element;
+ The_Array : Array_Id;
+ Elem  : Array_Element_Id := No_Array_Element;
 
   begin
  if Index_Name /= All_Other_Names then
-Index_Name := Get_Attribute_Index
-  (Node_Tree,
-   Current_Item,
-   Associative_Array_Index_Of (Current_Item, Node_Tree));
+Index_Name := Get_Attribute_Index (Node_Tree, Current, Index_Name);
  end if;
 
  --  Look for the array in the appropriate list
@@ -1903,7 +1877,7 @@
  end if;
 
  while The_Array /= No_Array
-   and then In_Tree.Arrays.Table (The_Array).Name /= Current_Item_Name
+   and then In_Tree.Arrays.Table (The_Array).Name /= Name
  loop
 The_Array := In_Tree.Arrays.Table (The_Array).Next;
  end loop;
@@ -1919,7 +1893,7 @@
 
 if Pkg /= No_Package then
In_Tree.Arrays.Table (The_Array) :=
- (Name => Current_Item_Name,
+ (Name => Name,
   Location => Current_Location,
   Value=> No_Array_Element,
   Next => In_Tree.Packages.Table (Pkg).Decl.Arrays);
@@ -1928,7 +1902,7 @@
 
 else
In_Tree.Arrays.Table (The_Array) :=
- (Name => Current_Item_Name,
+ (Name => Name,
   Location => Current_Location,
   Value=> No_Array_Element,

[Ada] Put imported spec in ALI file when body is not found

2011-08-03 Thread Arnaud Charlet
When an imported unit needs a body, bit the body source file cannot be
found, always put the spec file name in the ALI file of the importing
unit. This was done when a configuration pragmas file was available to
the compiler, but not when there was no vonfiguration pragmas file.
This is now done in all cases.
The test is to compile a unit that imports a package that need
completion, when the source of the body cannot be found: the spec file
name should be in the ALI file of the compiled unit.

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

2011-08-03  Vincent Celier  

* fname-uf.adb
(Get_File_Name) If the file cannot be found when there are no config
pragmas file and May_Fail is True, return No_File instead of the file
name, to be consistent.

Index: fname-uf.adb
===
--- fname-uf.adb(revision 176998)
+++ fname-uf.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2007, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -469,10 +469,15 @@
  --  the default GNAT naming scheme. The file does
  --  not exist, but there is no point doing the
  --  second search, because we will end up with the
- --  same file name. Just return the file name.
+ --  same file name. Just return the file name, or No_File
+ --  if May_Fail is True.
 
  elsif SFN_Patterns.Last = 2 then
-return Fnam;
+if May_Fail then
+   return No_File;
+else
+   return Fnam;
+end if;
 
  --  The file does not exist, but there may be other
  --  naming scheme. Keep on searching.


[Ada] Initial steps for convention Ada_Pass_By_Copy/Reference

2011-08-03 Thread Arnaud Charlet
First steps in implementation of convention Ada_Pass_By_Copy/Reference
Not yet complete, not ready for tests.

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

2011-08-03  Robert Dewar  

* repinfo.adb (List_Mechanism): Add handling of
Convention_Ada_Pass_By_XXX.
* sem_mech.adb (Set_Mechanism): Ditto.
* sem_prag.adb (Process_Convention): Add entries for
Convention_Ada_Pass_By_XXX.
* snames.adb-tmpl, snames.ads-tmpl: Ditto.

Index: sem_prag.adb
===
--- sem_prag.adb(revision 177239)
+++ sem_prag.adb(working copy)
@@ -3014,6 +3014,38 @@
 
  Ent := E;
 
+ --  Ada_Pass_By_Copy special checking
+
+ if C = Convention_Ada_Pass_By_Copy then
+if not Is_First_Subtype (E) then
+   Error_Pragma_Arg
+ ("convention `Ada_Pass_By_Copy` only "
+  & "allowed for types", Arg2);
+end if;
+
+if Is_By_Reference_Type (E) then
+   Error_Pragma_Arg
+ ("convention `Ada_Pass_By_Copy` not allowed for "
+  & "by-reference type", Arg1);
+end if;
+ end if;
+
+ --  Ada_Pass_By_Reference special checking
+
+ if C = Convention_Ada_Pass_By_Reference then
+if not Is_First_Subtype (E) then
+   Error_Pragma_Arg
+ ("convention `Ada_Pass_By_Reference` only "
+  & "allowed for types", Arg2);
+end if;
+
+if Is_By_Copy_Type (E) then
+   Error_Pragma_Arg
+ ("convention `Ada_Pass_By_Reference` not allowed for "
+  & "by-copy type", Arg1);
+end if;
+ end if;
+
  --  Go to renamed subprogram if present, since convention applies to
  --  the actual renamed entity, not to the renaming entity. If the
  --  subprogram is inherited, go to parent subprogram.
Index: repinfo.adb
===
--- repinfo.adb (revision 176998)
+++ repinfo.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- --
@@ -665,19 +665,36 @@
   Write_Str ("  convention : ");
 
   case Convention (Ent) is
- when Convention_Ada   => Write_Line ("Ada");
- when Convention_Intrinsic => Write_Line ("InLineinsic");
- when Convention_Entry => Write_Line ("Entry");
- when Convention_Protected => Write_Line ("Protected");
- when Convention_Assembler => Write_Line ("Assembler");
- when Convention_C => Write_Line ("C");
- when Convention_CIL   => Write_Line ("CIL");
- when Convention_COBOL => Write_Line ("COBOL");
- when Convention_CPP   => Write_Line ("C++");
- when Convention_Fortran   => Write_Line ("Fortran");
- when Convention_Java  => Write_Line ("Java");
- when Convention_Stdcall   => Write_Line ("Stdcall");
- when Convention_Stubbed   => Write_Line ("Stubbed");
+ when Convention_Ada   =>
+Write_Line ("Ada");
+ when Convention_Ada_Pass_By_Copy  =>
+Write_Line ("Ada_Pass_By_Copy");
+ when Convention_Ada_Pass_By_Reference =>
+Write_Line ("Ada_Pass_By_Reference");
+ when Convention_Intrinsic =>
+Write_Line ("Intrinsic");
+ when Convention_Entry =>
+Write_Line ("Entry");
+ when Convention_Protected =>
+Write_Line ("Protected");
+ when Convention_Assembler =>
+Write_Line ("Assembler");
+ when Convention_C =>
+Write_Line ("C");
+ when Convention_CIL   =>
+Write_Line ("CIL");
+ when Convention_COBOL =>
+Write_Line ("COBOL");
+ when Convention_CPP   =>
+Write_Line ("C++");
+ when Convention_Fortran   =>
+Write_Line ("Fortran");
+ when Convention_Java  =>
+Write_Line ("Java");
+ when Convention_Stdcall   =>
+Write_Line ("Stdcall");
+ when Convention_Stubbed 

[Ada] Add a link between body and spec scopes in ALFA section of ALI file

2011-08-03 Thread Arnaud Charlet
In order to be able to reconstruct the information in back-ends which do not
have access to all the code, it is necessary that body scopes refer to their
spec scope when different. This has been added to the ALFA scope section of the
ALI file.

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

2011-08-03  Yannick Moy  

* alfa.ads Update format of ALFA section in ALI file in order to add a
mapping from bodies to specs when both are present
(ALFA_Scope_Record): add components for spec file/scope
* get_alfa.adb (Get_ALFA): read the new file/scope for spec when present
* lib-xref-alfa.adb
(Collect_ALFA): after all scopes have been collected, fill in the spec
 information when relevant
* put_alfa.adb (Put_ALFA): write the new file/scope for spec when
present.

Index: alfa.ads
===
--- alfa.ads(revision 177239)
+++ alfa.ads(working copy)
@@ -89,7 +89,7 @@
--  reading of the ALFA information, and means that the ALFA information
--  can stand on its own without needing other parts of the ALI file.
 
-   --FS . scope line type col entity
+   --FS . scope line type col entity (-> spec-file . spec-scope)?
 
--  scope is the ones-origin scope number for the current file (e.g. 2 =
--  reference to the second FS line in this FD block).
@@ -113,6 +113,9 @@
--  entity is the name of the scope entity, with casing in the canonical
--  casing for the source file where it is defined.
 
+   --  spec-file and spec-scope are respectively the file and scope for the
+   --  spec corresponding to the current body scope, when they differ.
+
--  --
--  -- Xref Section --
--  --
@@ -234,6 +237,14 @@
   Scope_Num : Nat;
   --  Set to the scope number for the scope
 
+  Spec_File_Num : Nat;
+  --  Set to the file dependency number for the scope corresponding to the
+  --  spec of the current scope entity, if different, or else 0.
+
+  Spec_Scope_Num : Nat;
+  --  Set to the scope number for the scope corresponding to the spec of
+  --  the current scope entity, if different, or else 0.
+
   Line : Nat;
   --  Line number for the scope
 
Index: put_alfa.adb
===
--- put_alfa.adb(revision 177255)
+++ put_alfa.adb(working copy)
@@ -78,6 +78,16 @@
   Write_Info_Char (S.Scope_Name (N));
end loop;
 
+   if S.Spec_File_Num /= 0 then
+  Write_Info_Char (' ');
+  Write_Info_Char ('-');
+  Write_Info_Char ('>');
+  Write_Info_Char (' ');
+  Write_Info_Nat (S.Spec_File_Num);
+  Write_Info_Char ('.');
+  Write_Info_Nat (S.Spec_Scope_Num);
+   end if;
+
Write_Info_Terminate;
 end;
 
Index: lib-xref-alfa.adb
===
--- lib-xref-alfa.adb   (revision 177255)
+++ lib-xref-alfa.adb   (working copy)
@@ -140,6 +140,9 @@
   's' => True,
   others => False);
 
+   type Entity_Hashed_Range is range 0 .. 255;
+   --  Size of hash table headers
+
---
-- Local Subprograms --
---
@@ -155,6 +158,9 @@
--  Filter table Xrefs to add all references used in ALFA to the table
--  ALFA_Xref_Table.
 
+   function Entity_Hash (E : Entity_Id) return Entity_Hashed_Range;
+   --  Hash function for hash table
+
procedure Traverse_Declarations_Or_Statements  (L : List_Id);
procedure Traverse_Handled_Statement_Sequence  (N : Node_Id);
procedure Traverse_Package_Body(N : Node_Id);
@@ -339,15 +345,17 @@
   --  filled even later, but are initialized to represent an empty range.
 
   ALFA_Scope_Table.Append (
-(Scope_Name   => new String'(Exact_Source_Name (Sloc (E))),
- File_Num => 0,
- Scope_Num=> 0,
- Line => Nat (Get_Logical_Line_Number (Loc)),
- Stype=> Typ,
- Col  => Nat (Get_Column_Number (Loc)),
- From_Xref=> 1,
- To_Xref  => 0,
- Scope_Entity => E));
+(Scope_Name => new String'(Exact_Source_Name (Sloc (E))),
+ File_Num   => 0,
+ Scope_Num  => 0,
+ Spec_File_Num  => 0,
+ Spec_Scope_Num => 0,
+ Line   => Nat (Get_Logical_Line_Number (Loc)),
+ Stype  => Typ,
+ Col=> Nat (Get_Column_Number (Loc)),
+ From_Xref  => 1,
+ To_Xref=> 0,
+ Scope_Entity   => E));
end Add_ALFA_Scope;
 

@@ -367,36 +375,37 @@
  procedure Set_Scope_Num (N : Entity_Id; Num : Nat);
   end Scopes;
 
+  

[Ada] process the External attribute in aggregate projects

2011-08-03 Thread Arnaud Charlet
When processing an aggregate project, the "External" attribute can be
used to modify the environment that is used to parse the aggregated
projects.

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

2011-08-03  Emmanuel Briot  

* prj-proc.adb, prj-ext.adb, prj-ext.ads, prj-env.adb, prj-env.ads,
prj-tree.adb, prj-tree.ads (Initialize_And_Copy, Copy): new subprograms
(Process_Declarative_Items): new parameter Child_Env.

Index: prj-proc.adb
===
--- prj-proc.adb(revision 177252)
+++ prj-proc.adb(working copy)
@@ -131,10 +131,17 @@
   Node_Tree : Project_Node_Tree_Ref;
   Env   : Prj.Tree.Environment;
   Pkg   : Package_Id;
-  Item  : Project_Node_Id);
+  Item  : Project_Node_Id;
+  Child_Env : in out Prj.Tree.Environment;
+  Can_Modify_Child_Env : Boolean);
--  Process declarative items starting with From_Project_Node, and put them
--  in declarations Decl. This is a recursive procedure; it calls itself for
--  a package declaration or a case construction.
+   --  Child_Env is the modified environment after seeing declarations like
+   --  "for External(...) use" or "for Project_Path use" in aggregate projects.
+   --  It should have been initialized first. This environment can only be
+   --  modified if Can_Modify_Child_Env is True, otherwise all the above
+   --  attributes simply have no effect.
 
procedure Recursive_Process
  (In_Tree: Project_Tree_Ref;
@@ -142,13 +149,22 @@
   From_Project_Node  : Project_Node_Id;
   From_Project_Node_Tree : Project_Node_Tree_Ref;
   Env: in out Prj.Tree.Environment;
-  Extended_By: Project_Id);
+  Extended_By: Project_Id;
+  Child_Env  : in out Prj.Tree.Environment;
+  Is_Root_Project: Boolean);
--  Process project with node From_Project_Node in the tree. Do nothing if
--  From_Project_Node is Empty_Node. If project has already been processed,
--  simply return its project id. Otherwise create a new project id, mark it
--  as processed, call itself recursively for all imported projects and a
--  extended project, if any. Then process the declarative items of the
--  project.
+   --  Child_Env is the environment created from an aggregate project (new
+   --  external values or project path), and should be initialized before the
+   --  call.
+   --  Is_Root_Project should be true only for the project that the user
+   --  explicitly loaded. In the context of aggregate projects, only that
+   --  project is allowed to modify the environment that will be used to load
+   --  projects (Child_Env).
 
function Get_Attribute_Index
  (Tree  : Project_Node_Tree_Ref;
@@ -1392,7 +1408,9 @@
   Node_Tree  : Project_Node_Tree_Ref;
   Env: Prj.Tree.Environment;
   Pkg: Package_Id;
-  Item   : Project_Node_Id)
+  Item   : Project_Node_Id;
+  Child_Env  : in out Prj.Tree.Environment;
+  Can_Modify_Child_Env   : Boolean)
is
   procedure Check_Or_Set_Typed_Variable
 (Value   : in out Variable_Value;
@@ -1597,7 +1615,9 @@
   Env=> Env,
   Pkg=> New_Pkg,
   Item   =>
-First_Declarative_Item_Of (Current_Item, Node_Tree));
+First_Declarative_Item_Of (Current_Item, Node_Tree),
+  Child_Env  => Child_Env,
+  Can_Modify_Child_Env   => Can_Modify_Child_Env);
 end;
  end if;
   end Process_Package_Declaration;
@@ -1949,9 +1969,26 @@
  end if;
 
  if Name = Snames.Name_External then
+if Can_Modify_Child_Env then
+   Add (Child_Env.External,
+External_Name => Get_Name_String (Index_Name),
+Value => Get_Name_String (New_Value.Value),
+Source=> From_External_Attribute);
+   Add (Env.External,
+External_Name => Get_Name_String (Index_Name),
+Value => Get_Name_String (New_Value.Value),
+Source=> From_External_Attribute);
+else
+   if Current_Verbosity = High then
+  Debug_Output
+("'for External' has no effect except in root aggregate ("
+ & Get_Name_String (Index_Name) & ")", New_Value.Value);
+   end if;
+end if;
+
+ elsif Name = Snames.Name_Project_Path then
 Debug_Output
-  ("Defined external value ("
-   & Get_Name_String (Index_Name) & ")", New_Va

[Ada] Adapt SPARK restriction to follow modification of SPARK LRM

2011-08-03 Thread Arnaud Charlet
SPARK LRM was modified to allow the names of constants to occur as operands
of concatenation. The SPARK restriction has been updated to reflect this change.

The following now compiles quietly:

pragma Restrictions (SPARK);

procedure Concat is
   subtype Small_Range is Positive range 1 .. 1;
   subtype Small_String is String (Small_Range);
   C : constant Character := 'c';
   X : constant Small_String := Small_String'(others => C);

   procedure Something (Arg : String) is
   begin
  null;
   end Something;
begin
   Something ("with" & X);
end Concat;

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

2011-08-03  Yannick Moy  

* sem_res.adb
(Resolve_Op_Concat_Arg): do not issue a SPARK violation when argument of
concatenation is the name of a constant

Index: sem_res.adb
===
--- sem_res.adb (revision 177254)
+++ sem_res.adb (working copy)
@@ -7774,10 +7774,10 @@
   end if;
 
   --  Concatenation is restricted in SPARK: each operand must be either a
-  --  string literal, a static character expression, or another
-  --  concatenation. Arg cannot be a concatenation here as callers of
-  --  Resolve_Op_Concat_Arg call it separately on each final operand, past
-  --  concatenation operations.
+  --  string literal, the name of a string constant, a static character or
+  --  string expression, or another concatenation. Arg cannot be a
+  --  concatenation here as callers of Resolve_Op_Concat_Arg call it
+  --  separately on each final operand, past concatenation operations.
 
   if Is_Character_Type (Etype (Arg)) then
  if not Is_Static_Expression (Arg) then
@@ -7786,7 +7786,10 @@
  end if;
 
   elsif Is_String_Type (Etype (Arg)) then
- if not Is_Static_Expression (Arg) then
+ if not (Nkind_In (Arg, N_Identifier, N_Expanded_Name)
+  and then Is_Constant_Object (Entity (Arg)))
+   and then not Is_Static_Expression (Arg)
+ then
 Check_SPARK_Restriction
   ("string operand for concatenation should be static", N);
  end if;


[Ada] Unresolved discriminant selector of private overloaded prefix

2011-08-03 Thread Arnaud Charlet
The compiler rejects a selected component naming a discriminant of a private
type when the prefix is overloaded. Prefixes of private types were not being
accounted for in analysis and resolution of an overloaded selected component.

The following test must compile quietly:

procedure Overloaded_Discrim_Selector is

   package Pkg is
  
  type Some_Rec is null record;
   
  function Func (I : Integer) return Some_Rec;

  type Another_Rec (Exists : Boolean := False) is private;  
  
  function Func (I : Integer) return Another_Rec;

   private
  
  type Another_Rec (Exists : Boolean := False) is null record;
  
   end Pkg;

   package body Pkg is
  
  function Func (I : Integer) return Some_Rec is
 S : Some_Rec;
  begin
 return S;
  end Func; 
  
  function Func (I : Integer) return Another_Rec is
 A : Another_Rec ;
  begin
 return A;
  end Func;
  
   end Pkg;
   
   use Pkg;

   B : Boolean := Func (123).Exists;

begin
   null;
end Overloaded_Discrim_Selector;

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

2011-08-03  Gary Dismukes  

* sem_ch4.adb (Analyze_Overloaded_Selected_Component): Consider
prefixes of private types along with records, since the selector may be
a discriminant.
* sem_res.adb (Resolve_Selected_Component): Consider prefixes of
private types along with records, since the selector may be a
discriminant.

Index: sem_res.adb
===
--- sem_res.adb (revision 177258)
+++ sem_res.adb (working copy)
@@ -8378,8 +8378,11 @@
T := It.Typ;
 end if;
 
-if Is_Record_Type (T) then
+--  Locate selected component. For a private prefix the selector
+--  can denote a discriminant.
 
+if Is_Record_Type (T) or else Is_Private_Type (T) then
+
--  The visible components of a class-wide type are those of
--  the root type.
 
Index: sem_ch4.adb
===
--- sem_ch4.adb (revision 177253)
+++ sem_ch4.adb (working copy)
@@ -3127,8 +3127,11 @@
 T := It.Typ;
  end if;
 
- if Is_Record_Type (T) then
+ --  Locate the component. For a private prefix the selector can denote
+ --  a discriminant.
 
+ if Is_Record_Type (T) or else Is_Private_Type (T) then
+
 --  If the prefix is a class-wide type, the visible components are
 --  those of the base type.
 


[Ada] Use TLS to implement Self on Linux

2011-08-03 Thread Arnaud Charlet
This patch provides a generic support to use TLS for the Ada tasking run-time
(file s-tpopsp-tls.adb) and enables this support on several Linux platforms.
More platforms may be switched later.

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

2011-08-03  Arnaud Charlet  

* s-taprop-posix.adb, s-taprop-linux.adb, s-taprop-tru64.adb
(ATCB_Key): Removed, not always used.
* s-tpopsp-posix.adb, s-tpopsp-posix-foreign.adb (ATCB_Key): Moved from
s-taprop-posix.adb.
* s-tpopsp-tls.adb: New file.
* gcc-interface/Makefile.in: Use TLS implementation of s-tpopsp.adb on
x86/x64/ia64/powerpc/sparc Linux.

Index: s-taprop-tru64.adb
===
--- s-taprop-tru64.adb  (revision 176998)
+++ s-taprop-tru64.adb  (working copy)
@@ -6,7 +6,7 @@
 --  --
 --  B o d y --
 --  --
--- Copyright (C) 1992-2009, Free Software Foundation, Inc.  --
+-- Copyright (C) 1992-2011, Free Software Foundation, Inc.  --
 --  --
 -- GNARL 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- --
@@ -77,9 +77,6 @@
--  a time; it is used to execute in mutual exclusion from all other tasks.
--  Used mainly in Single_Lock mode, but also to protect All_Tasks_List
 
-   ATCB_Key : aliased pthread_key_t;
-   --  Key used to find the Ada Task_Id associated with a thread
-
Environment_Task_Id : Task_Id;
--  A variable to hold Task_Id for the environment task
 
Index: s-taprop-linux.adb
===
--- s-taprop-linux.adb  (revision 176998)
+++ s-taprop-linux.adb  (working copy)
@@ -6,7 +6,7 @@
 --  --
 --  B o d y --
 --  --
--- Copyright (C) 1992-2010, Free Software Foundation, Inc.  --
+-- Copyright (C) 1992-2011, Free Software Foundation, Inc.  --
 --  --
 -- GNARL 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- --
@@ -81,9 +81,6 @@
--  a time; it is used to execute in mutual exclusion from all other tasks.
--  Used mainly in Single_Lock mode, but also to protect All_Tasks_List
 
-   ATCB_Key : aliased pthread_key_t;
-   --  Key used to find the Ada Task_Id associated with a thread
-
Environment_Task_Id : Task_Id;
--  A variable to hold Task_Id for the environment task
 
Index: s-tpopsp-posix-foreign.adb
===
--- s-tpopsp-posix-foreign.adb  (revision 176998)
+++ s-tpopsp-posix-foreign.adb  (working copy)
@@ -6,7 +6,7 @@
 --  --
 --B o d y   --
 --  --
--- Copyright (C) 1992-2009, Free Software Foundation, Inc.  --
+-- Copyright (C) 1992-2011, Free Software Foundation, Inc.  --
 --  --
 -- GNARL 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- --
@@ -32,12 +32,12 @@
 --  This is a POSIX version of this package where foreign threads are
 --  recognized.
 
---  Currently, DEC Unix, SCO UnixWare, Solaris pthread, HPUX pthread and
---  GNU/Linux threads use this version.
-
 separate (System.Task_Primitives.Operations)
 package body Specific is
 
+   ATCB_Key : aliased pthread_key_t;
+   --  Key used to find the Ada Task_Id associated with a thread
+

-- Initialize --

Index: s-tpopsp-posix.adb
===
--- s-tpopsp-posix.adb  (revision 176998)
+++ s-tpopsp-posix.adb  (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2009, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-2011, Free Software Foundation, Inc. --
 --  

[Ada] Switch to ZCX on AIX

2011-08-03 Thread Arnaud Charlet
We've had this setting enabled by default in our AdaCore tree for years
now, so enabling this setting here.

Manually tested on powerpc-aix
Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-03  Arnaud Charlet  

* system-aix.ads, system-aix64.ads: Set ZCX_By_Default to True.
* gcc-interface/Makefile.in: Switch to ZCX by default on AIX ports.

Index: system-aix64.ads
===
--- system-aix64.ads(revision 176998)
+++ system-aix64.ads(working copy)
@@ -7,7 +7,7 @@
 -- S p e c  --
 --   (PPC/AIX64 Version)--
 --  --
---Copyright (C) 2009, Free Software Foundation, Inc.--
+--  Copyright (C) 2009-2011, Free Software Foundation, Inc. --
 --  --
 -- This specification is derived from the Ada Reference Manual for use with --
 -- GNAT. The copyright notice above, and the license provisions that follow --
@@ -149,7 +149,7 @@
Always_Compatible_Rep : constant Boolean := True;
Suppress_Standard_Library : constant Boolean := False;
Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default: constant Boolean := False;
-   GCC_ZCX_Support   : constant Boolean := True;  --  Post GCC 4 only
+   ZCX_By_Default: constant Boolean := True;
+   GCC_ZCX_Support   : constant Boolean := True;
 
 end System;
Index: system-aix.ads
===
--- system-aix.ads  (revision 176998)
+++ system-aix.ads  (working copy)
@@ -7,7 +7,7 @@
 -- S p e c  --
 --(AIX/PPC Version) --
 --  --
---  Copyright (C) 1992-2009, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-2011, Free Software Foundation, Inc. --
 --  --
 -- This specification is derived from the Ada Reference Manual for use with --
 -- GNAT. The copyright notice above, and the license provisions that follow --
@@ -149,7 +149,7 @@
Always_Compatible_Rep : constant Boolean := True;
Suppress_Standard_Library : constant Boolean := False;
Use_Ada_Main_Program_Name : constant Boolean := False;
-   ZCX_By_Default: constant Boolean := False;
-   GCC_ZCX_Support   : constant Boolean := True;  --  Post GCC 4 only
+   ZCX_By_Default: constant Boolean := True;
+   GCC_ZCX_Support   : constant Boolean := True;
 
 end System;
Index: gcc-interface/Makefile.in
===
--- gcc-interface/Makefile.in   (revision 177191)
+++ gcc-interface/Makefile.in   (working copy)
@@ -1383,7 +1385,7 @@
   endif
 
   THREADSLIB = -lpthreads
-
+  EH_MECHANISM=-gcc
   TOOLS_TARGET_PAIRS = \
   mlib-tgt-specific.adb

Fix Solaris Ada bootstrap

2011-08-03 Thread Rainer Orth
Two of the latest Ada patches broke bootstrap on Solaris:

In file included from /vol/gcc/src/hg/trunk/local/gcc/ada/link.c:42:0:
./auto-host.h:1829:0: error: "_FILE_OFFSET_BITS" redefined [-Werror]
/var/gcc/regression/trunk/10-gcc/build/./prev-gcc/include-fixed/sys/feature_tests.h:197:0:
 note: this is the location of the previous definition
cc1plus: all warnings being treated as errors

auto-host.h has

/* Number of bits in a file offset, on hosts where this is settable. */
#ifndef USED_FOR_TARGET
#define _FILE_OFFSET_BITS 64
#endif

while  defaults to 32 if undefined.  This can
easily be fixed by including auto-host.h before any system header.

i386-pc-solaris2.10 bootstrap is just in progress, but already past the
point of the previous failure.

Ok for mainline?

Thanks.
Rainer


2011-08-03  Rainer Orth  

* link.c: Include "auto-host.h" before system headers.

diff --git a/gcc/ada/link.c b/gcc/ada/link.c
--- a/gcc/ada/link.c
+++ b/gcc/ada/link.c
@@ -36,12 +36,12 @@
 extern "C" {
 #endif
 
-#include 
-
 #ifdef IN_GCC
 #include "auto-host.h"
 #endif
 
+#include 
+
 /*  objlist_file_supported is set to 1 when the system linker allows*/
 /*  response file, that is a file that contains the list of object files.   */
 /*  This is useful on systems where the command line length is limited, */

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


Re: [PATCH 4/6] Shrink-wrapping

2011-08-03 Thread Alan Modra
On Thu, Jul 28, 2011 at 12:35:46PM +0200, Bernd Schmidt wrote:
[snip]
>   * rtl.h (ANY_RETURN_P): New macro.
[snip]

This patch makes rebuild_jump_labels set JUMP_LABEL appropriately
for return jumps, and fixes sharing for RETURN.  Since ANY_RETURN_P(X)
is defined as ((X) == ret_rtx), RETURNs need to stay shared.
Bootstrapped and regression tested powerpc-linux and powerpc64-linux.
OK to apply?

PR rtl-optimization/49941
* jump.c (mark_jump_label): Comment.
(mark_jump_label_1): Set JUMP_LABEL for return jumps.
* emit-rtl.c (copy_rtx_if_shared_1, copy_insn_1): Leave RETURN shared.
(mark_used_flags): Don't mark RETURN.

Index: gcc/jump.c
===
--- gcc/jump.c  (revision 177084)
+++ gcc/jump.c  (working copy)
@@ -1039,6 +1039,7 @@ sets_cc0_p (const_rtx x)
notes.  If INSN is an INSN or a CALL_INSN or non-target operands of
a JUMP_INSN, and there is at least one CODE_LABEL referenced in
INSN, add a REG_LABEL_OPERAND note containing that label to INSN.
+   For returnjumps, the JUMP_LABEL will also be set as appropriate.
 
Note that two labels separated by a loop-beginning note
must be kept distinct if we have not yet done loop-optimization,
@@ -1081,6 +1082,14 @@ mark_jump_label_1 (rtx x, rtx insn, bool
 case CALL:
   return;
 
+case RETURN:
+  if (is_target)
+   {
+ gcc_assert (JUMP_LABEL (insn) == NULL || JUMP_LABEL (insn) == x);
+ JUMP_LABEL (insn) = x;
+   }
+  return;
+
 case MEM:
   in_mem = true;
   break;
Index: gcc/emit-rtl.c
===
--- gcc/emit-rtl.c  (revision 177084)
+++ gcc/emit-rtl.c  (working copy)
@@ -2724,6 +2724,7 @@ repeat:
 case CODE_LABEL:
 case PC:
 case CC0:
+case RETURN:
 case SCRATCH:
   /* SCRATCH must be shared because they represent distinct values.  */
   return;
@@ -2843,6 +2844,7 @@ repeat:
 case CODE_LABEL:
 case PC:
 case CC0:
+case RETURN:
   return;
 
 case DEBUG_INSN:
@@ -5257,6 +5259,7 @@ copy_insn_1 (rtx orig)
 case CODE_LABEL:
 case PC:
 case CC0:
+case RETURN:
   return orig;
 case CLOBBER:
   if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < 
FIRST_PSEUDO_REGISTER)

-- 
Alan Modra
Australia Development Lab, IBM


Re: [Patch,AVR]: Cleanup libgcc.S

2011-08-03 Thread Georg-Johann Lay
http://gcc.gnu.org/ml/gcc-patches/2011-08/msg00140.html

Weddington, Eric wrote:

>>
>> This patch fixes RCALL/RJMP instructions to other modules by replacing
>> them
>> with XCALL resp. XJMP.
>>
> 
> Hi Johann,
> 
> Do we want to add a binutils bug report for the FIXME that you just added in 
> this patch?

Yes I think so.  libgcc.S would be more efficient and easier to read because
it needed no special treatment of skip bug.

I think avr-libc could take advantage of that feature, too, e.g. getting rid
of relocation truncation issues like #33698.  For avr-libc it's a bit harder,
of course, because many modules need __addsf3 et al. But large routines like
printf stuff could be factored out.

> It should be fairly easy to add SORT to the default linker scripts.
> 
> Eric Weddington

What version?  Is already possible for 2.21?

Johann




[RFC PATCH] Allow user specs files to add self_spec

2011-08-03 Thread Jakub Jelinek
Hi!

I couldn't find a way to add an option in specs, so that it would affect
other specs, like e.g. to make -pie the default if -shared/-static/-pie/-r
isn't passed in specs would require duplicating *startfile/*endfile:
%rename link link_pie_old
*link:
%{shared|static|pie|r:;:-pie} %(link_pie_old)
*endfile:
%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} %{mpc32:crtprec32.o%s} 
%{mpc64:crtprec64.o%s} %{mpc80:crtprec80.o%s} 
%{shared|pie:crtendS.o%s;static|r:crtend.o%s;:crtendS.o%s} crtn.o%s
*startfile:
%{!shared: %{pg|p|profile:gcrt1.o%s; :Scrt1.o%s}} crti.o%s 
%{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;r:crtbegin.o%s;:crtbeginS.o%s}
with all the drawbacks it has - if builtin specs change, it would need
% adjusting, similarly *startfile/*endfile differ for different targets.

With the following patch it is possible to add self_spec like in:

%rename self_spec self_spec_pie_old
*self_spec:
%{shared|static|pie|r:;:-pie} %{fpic|fPIC|fpie|fPIE:;:-fpie} 
*%(self_spec_pie_old)

which introduces the options into further option processing, so -pie gets
matched e.g. in *startfile/*endfile.  I had to move the -fcompare-debug
handling slightly later, because it is remembering the current count of
options and repeating them afterwards.

Tested on x86_64-linux, ok for trunk?

2011-08-03  Jakub Jelinek  

* gcc.c (self_spec): New variable.
(static_specs): Add self_spec.
(main): Call do_self_spec on "self_spec" specs after reading
user specs files.  Move compare_debug handling right after that.

--- gcc/gcc.c.jj2011-07-22 22:15:02.0 +0200
+++ gcc/gcc.c   2011-08-03 12:14:41.0 +0200
@@ -728,6 +728,7 @@ static const char *startfile_prefix_spec
 static const char *sysroot_spec = SYSROOT_SPEC;
 static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
 static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
+static const char *self_spec = "";
 
 /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
There should be no need to override these in target dependent files,
@@ -1215,6 +1216,7 @@ static struct spec_list static_specs[] =
   INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
   INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
   INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec",
&sysroot_hdrs_suffix_spec),
+  INIT_STATIC_SPEC ("self_spec",   &self_spec),
 };
 
 #ifdef EXTRA_SPECS /* additional specs needed */
@@ -6261,48 +6263,6 @@ main (int argc, char **argv)
   for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
 do_self_spec (driver_self_specs[i]);
 
-  if (compare_debug)
-{
-  enum save_temps save;
-
-  if (!compare_debug_second)
-   {
- n_switches_debug_check[1] = n_switches;
- n_switches_alloc_debug_check[1] = n_switches_alloc;
- switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
-n_switches_alloc);
-
- do_self_spec ("%:compare-debug-self-opt()");
- n_switches_debug_check[0] = n_switches;
- n_switches_alloc_debug_check[0] = n_switches_alloc;
- switches_debug_check[0] = switches;
-
- n_switches = n_switches_debug_check[1];
- n_switches_alloc = n_switches_alloc_debug_check[1];
- switches = switches_debug_check[1];
-   }
-
-  /* Avoid crash when computing %j in this early.  */
-  save = save_temps_flag;
-  save_temps_flag = SAVE_TEMPS_NONE;
-
-  compare_debug = -compare_debug;
-  do_self_spec ("%:compare-debug-self-opt()");
-
-  save_temps_flag = save;
-
-  if (!compare_debug_second)
-   {
- n_switches_debug_check[1] = n_switches;
- n_switches_alloc_debug_check[1] = n_switches_alloc;
- switches_debug_check[1] = switches;
- compare_debug = -compare_debug;
- n_switches = n_switches_debug_check[0];
- n_switches_alloc = n_switches_debug_check[0];
- switches = switches_debug_check[0];
-   }
-}
-
   /* If not cross-compiling, look for executables in the standard
  places.  */
   if (*cross_compile == '0')
@@ -6412,6 +6372,58 @@ main (int argc, char **argv)
   read_specs (filename ? filename : uptr->filename, FALSE);
 }
 
+  /* Process any user self specs.  */
+  {
+struct spec_list *sl;
+for (sl = specs; sl; sl = sl->next)
+  if (sl->name_len == sizeof "self_spec" - 1
+ && !strcmp (sl->name, "self_spec"))
+   do_self_spec (*sl->ptr_spec);
+  }
+
+  if (compare_debug)
+{
+  enum save_temps save;
+
+  if (!compare_debug_second)
+   {
+ n_switches_debug_check[1] = n_switches;
+ n_switches_alloc_debug_check[1] = n_switches_alloc;
+ switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
+n_switches_alloc);
+
+ do_self_spec ("%:compare-debug-self-opt()");
+ n_swi

[Ada] Detect array types which belong to ALFA subset

2011-08-03 Thread Arnaud Charlet
Follow-up of previous changes to detect ALFA subset. Deals here with array
types, which should have static bounds and have index/component types in ALFA.

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

2011-08-03  Yannick Moy  

* cstand.adb (Create_Standard): select Universal_Integer as an ALFA type
* sem_ch3.adb (Array_Type_Declaration): detect array types in ALFA
* sem_util.adb, sem_util.ads (Has_Static_Array_Bounds): new function to
detect that an array has static bounds.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 177252)
+++ sem_ch3.adb (working copy)
@@ -4639,6 +4639,7 @@
   Nb_Index  : Nat;
   P : constant Node_Id := Parent (Def);
   Priv  : Entity_Id;
+  T_In_ALFA : Boolean := True;
 
begin
   if Nkind (Def) = N_Constrained_Array_Definition then
@@ -4665,6 +4666,12 @@
 Check_SPARK_Restriction ("subtype mark required", Index);
  end if;
 
+ if Present (Etype (Index))
+   and then not Is_In_ALFA (Etype (Index))
+ then
+T_In_ALFA := False;
+ end if;
+
  --  Add a subtype declaration for each index of private array type
  --  declaration whose etype is also private. For example:
 
@@ -4740,10 +4747,18 @@
 Check_SPARK_Restriction ("subtype mark required", Component_Typ);
  end if;
 
+ if Present (Element_Type)
+   and then not Is_In_ALFA (Element_Type)
+ then
+T_In_ALFA := False;
+ end if;
+
   --  Ada 2005 (AI-230): Access Definition case
 
   else pragma Assert (Present (Access_Definition (Component_Def)));
 
+ T_In_ALFA := False;
+
  --  Indicate that the anonymous access type is created by the
  --  array type declaration.
 
@@ -4820,6 +4835,12 @@
(Implicit_Base, Finalize_Storage_Only
 (Element_Type));
 
+ --  Final check for static bounds on array
+
+ if not Has_Static_Array_Bounds (T) then
+T_In_ALFA := False;
+ end if;
+
   --  Unconstrained array case
 
   else
@@ -4844,6 +4865,7 @@
 
   Set_Component_Type (Base_Type (T), Element_Type);
   Set_Packed_Array_Type (T, Empty);
+  Set_Is_In_ALFA (T, T_In_ALFA);
 
   if Aliased_Present (Component_Definition (Def)) then
  Check_SPARK_Restriction
Index: sem_util.adb
===
--- sem_util.adb(revision 177190)
+++ sem_util.adb(working copy)
@@ -5550,6 +5550,69 @@
   end if;
end Has_Private_Component;
 
+   -
+   -- Has_Static_Array_Bounds --
+   -
+
+   function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
+  Ndims : constant Nat := Number_Dimensions (Typ);
+
+  Index : Node_Id;
+  Low   : Node_Id;
+  High  : Node_Id;
+
+   begin
+  --  Unconstrained types do not have static bounds
+
+  if not Is_Constrained (Typ) then
+ return False;
+  end if;
+
+  --  First treat specially string literals, as the lower bound and length
+  --  of string literals are not stored like those of arrays.
+
+  --  A string literal always has static bounds
+
+  if Ekind (Typ) = E_String_Literal_Subtype then
+ return True;
+  end if;
+
+  --  Treat all dimensions in turn
+
+  Index := First_Index (Typ);
+  for Indx in 1 .. Ndims loop
+
+ --  In case of an erroneous index which is not a discrete type, return
+ --  that the type is not static.
+
+ if not Is_Discrete_Type (Etype (Index))
+   or else Etype (Index) = Any_Type
+ then
+return False;
+ end if;
+
+ Get_Index_Bounds (Index, Low, High);
+
+ if Error_Posted (Low) or else Error_Posted (High) then
+return False;
+ end if;
+
+ if Is_OK_Static_Expression (Low)
+   and then Is_OK_Static_Expression (High)
+ then
+null;
+ else
+return False;
+ end if;
+
+ Next (Index);
+  end loop;
+
+  --  If we fall through the loop, all indexes matched
+
+  return True;
+   end Has_Static_Array_Bounds;
+

-- Has_Stream --

Index: sem_util.ads
===
--- sem_util.ads(revision 177234)
+++ sem_util.ads(working copy)
@@ -624,6 +624,9 @@
--  Check if a type has a (sub)component of a private type that has not
--  yet received a full declaration.
 
+   function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean;
+   --  Return whether an array type has static bounds
+
function Has_Stream (T : Entity_Id) return Boolean;
--  

Re: [PATCH, gomp]: Unbreak bootstrap on glibc-2.5

2011-08-03 Thread Uros Bizjak
On Wed, Aug 3, 2011 at 11:11 AM, Jakub Jelinek  wrote:
> On Wed, Aug 03, 2011 at 10:36:47AM +0200, Uros Bizjak wrote:
>> We should not call CPU_COUNT when not defined in glibc.
>
> Oops, forgot that old glibcs don't have it.

> I don't like the prototype in libgomp.h, for one sched.h isn't included
> in libgomp.h thus cpu_set_t is not defined type.  Plus it isn't a generic
> API, but a Linux private function.
> So, IMHO either just don't provide any prototype in a header
> and put
> extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
> into config/linux/affinity.c, or introduce
> config/linux/proc.h header containing
> #include 
> #ifdef HAVE_PTHREAD_AFFINITY_NP
> extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
> #endif
> and
> #include "config/linux/proc.h"
> in config/linux/{proc.c,affinity.c}.
> Ok with those changes, thanks.

Attached is the patch that was committed to SVN.

2011-08-03  Uros Bizjak  

* config/linux/proc.h: New.
* config/linux/proc.c: Include "proc.h".  Do not include .
(gomp_cpuset_popcount): Rename from cpuset_popcount.  No more static.
(gomp_init_num_threads): Update call to cpuset_popcount.
(get_num_procs): Ditto.
* config/linux/affinity.c (gomp_init_affinity): Call
gomp_cpuset_popcount.

Tested on x86_64-pc-linux-gnu {,-m32}, committed to mainline SVN.

Uros.
Index: config/linux/proc.c
===
--- config/linux/proc.c (revision 177229)
+++ config/linux/proc.c (working copy)
@@ -30,7 +30,7 @@
 #define _GNU_SOURCE 1
 #endif
 #include "libgomp.h"
-#include 
+#include "proc.h"
 #include 
 #include 
 #ifdef HAVE_GETLOADAVG
@@ -40,8 +40,8 @@
 #endif
 
 #ifdef HAVE_PTHREAD_AFFINITY_NP
-static unsigned long
-cpuset_popcount (cpu_set_t *cpusetp)
+unsigned long
+gomp_cpuset_popcount (cpu_set_t *cpusetp)
 {
 #ifdef CPU_COUNT
   /* glibc 2.6 and above provide a macro for this.  */
@@ -76,7 +76,7 @@ gomp_init_num_threads (void)
   if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset), &cpuset) == 0)
 {
   /* Count only the CPUs this process can use.  */
-  gomp_global_icv.nthreads_var = cpuset_popcount (&cpuset);
+  gomp_global_icv.nthreads_var = gomp_cpuset_popcount (&cpuset);
   if (gomp_global_icv.nthreads_var == 0)
gomp_global_icv.nthreads_var = 1;
   return;
@@ -99,7 +99,7 @@ get_num_procs (void)
   if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset),
  &cpuset) == 0)
{
- int ret = cpuset_popcount (&cpuset);
+ int ret = gomp_cpuset_popcount (&cpuset);
  return ret != 0 ? ret : 1;
}
 }
Index: config/linux/proc.h
===
--- config/linux/proc.h (revision 0)
+++ config/linux/proc.h (revision 0)
@@ -0,0 +1,34 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+   Contributed by Uros Bizjak 
+
+   This file is part of the GNU OpenMP Library (libgomp).
+
+   Libgomp 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.
+
+   Libgomp 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.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   .  */
+
+#ifndef GOMP_PROC_H
+#define GOMP_PROC_H 1
+
+#include 
+
+#ifdef HAVE_PTHREAD_AFFINITY_NP
+extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
+#endif
+
+#endif /* GOMP_PROC_H */
Index: config/linux/affinity.c
===
--- config/linux/affinity.c (revision 177229)
+++ config/linux/affinity.c (working copy)
@@ -29,7 +29,7 @@
 #define _GNU_SOURCE 1
 #endif
 #include "libgomp.h"
-#include 
+#include "proc.h"
 #include 
 #include 
 
@@ -56,7 +56,7 @@ gomp_init_affinity (void)
   CPU_ZERO (&cpusetnew);
   if (gomp_cpu_affinity_len == 0)
 {
-  unsigned long count = CPU_COUNT (&cpuset);
+  unsigned long count = gomp_cpuset_popcount (&cpuset);
   if (count >= 65536)
count = 65536;
   gomp_cpu_affinity = malloc (count * sizeof (unsigned short));


Re: [trans-mem] Beginning of refactoring

2011-08-03 Thread Torvald Riegel
This small patch fixes the rollback of the transaction ID as well as
queries for it.

OK for branch?
commit bd83b4594c1f6eee09e0fa7b369557f986291f9b
Author: Torvald Riegel 
Date:   Fri Jul 29 15:19:04 2011 +0200

Fix rollback and queries of transaction ID.

* beginend.cc (GTM::gtm_transaction::rollback): Roll back tx id as well.
* query.cc (_ITM_getTransactionId): There is no active transaction if
the current nesting level is zero.

diff --git a/libitm/beginend.cc b/libitm/beginend.cc
index 9f84404..d336d60 100644
--- a/libitm/beginend.cc
+++ b/libitm/beginend.cc
@@ -298,6 +298,7 @@ GTM::gtm_transaction::rollback (gtm_transaction_cp *cp)
   if (parent_txns.size() > 0)
 {
   jb = parent_txns[0].jb;
+  id = parent_txns[0].id;
   prop = parent_txns[0].prop;
 }
   // Reset the transaction. Do not reset this->state, which is handled by
diff --git a/libitm/query.cc b/libitm/query.cc
index 4905fc6..9a95211 100644
--- a/libitm/query.cc
+++ b/libitm/query.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
Contributed by Richard Henderson .
 
This file is part of the GNU Transactional Memory Library (libitm).
@@ -59,7 +59,7 @@ _ITM_transactionId_t ITM_REGPARM
 _ITM_getTransactionId (void)
 {
   struct gtm_transaction *tx = gtm_tx();
-  return tx ? tx->id : _ITM_noTransactionId;
+  return (tx && (tx->nesting > 0)) ? tx->id : _ITM_noTransactionId;
 }
 
 


[Ada] Default 'Input for array of limited object

2011-08-03 Thread Arnaud Charlet
This change fixes a bug in the generation of the default implementation
of the 'Input stream attribute in Ada 2005 mode for the case of an
unconstrained array of limited objects with a 'Read attribute. The following
compilation must be accepted quietly:

$ gcc -c -gnat05 unc_lim_input.adb

with Ada.Streams; use Ada.Streams;
package Limited_Remote is
   pragma Remote_Types;
   type T is tagged limited private;
   type A is array (Integer range <>) of T;
   procedure R (S : access Root_Stream_Type'Class; V : out A);
   for A'Read use R;
   procedure W (S : access Root_Stream_Type'Class; V : A);
   for A'Write use W;
private
   type T is tagged limited null record;
end Limited_Remote;
with Ada.Streams; use Ada.Streams;
with Limited_Remote;
procedure Unc_Lim_Input (S : access Root_Stream_Type'Class) is
   procedure Do_Stuff (X : Limited_Remote.A) is begin null; end;
begin
   Do_Stuff (Limited_Remote.A'Input (S));
end Unc_Lim_Input;

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

2011-08-03  Thomas Quinot  

* exp_strm.adb (Build_Array_Input_Function): In Ada 2005 mode, when
returning a limited array, use an extended return statement.

Index: exp_strm.adb
===
--- exp_strm.adb(revision 177026)
+++ exp_strm.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -149,7 +149,9 @@
   Decls  : List_Id;
   Ranges : List_Id;
   Stms   : List_Id;
+  Rstmt  : Node_Id;
   Indx   : Node_Id;
+  Odecl  : Node_Id;
 
begin
   Decls := New_List;
@@ -197,13 +199,13 @@
   --  build a subtype indication with the proper bounds.
 
   if Is_Constrained (Stream_Base_Type (Typ)) then
- Append_To (Decls,
+ Odecl :=
Make_Object_Declaration (Loc,
  Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
  Object_Definition =>
-   New_Occurrence_Of (Stream_Base_Type (Typ), Loc)));
+   New_Occurrence_Of (Stream_Base_Type (Typ), Loc));
   else
- Append_To (Decls,
+ Odecl :=
Make_Object_Declaration (Loc,
  Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
  Object_Definition =>
@@ -212,20 +214,35 @@
New_Occurrence_Of (Stream_Base_Type (Typ), Loc),
  Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc,
- Constraints => Ranges;
+ Constraints => Ranges)));
   end if;
 
-  Stms := New_List (
- Make_Attribute_Reference (Loc,
-   Prefix => New_Occurrence_Of (Typ, Loc),
-   Attribute_Name => Name_Read,
-   Expressions => New_List (
- Make_Identifier (Loc, Name_S),
- Make_Identifier (Loc, Name_V))),
+  Rstmt := Make_Attribute_Reference (Loc,
+ Prefix => New_Occurrence_Of (Typ, Loc),
+ Attribute_Name => Name_Read,
+ Expressions=> New_List (
+   Make_Identifier (Loc, Name_S),
+   Make_Identifier (Loc, Name_V)));
 
- Make_Simple_Return_Statement (Loc,
-   Expression => Make_Identifier (Loc, Name_V)));
+  if Ada_Version >= Ada_2005 then
+ Stms := New_List (
+Make_Extended_Return_Statement (Loc,
+  Return_Object_Declarations => New_List (Odecl),
+  Handled_Statement_Sequence =>
+Make_Handled_Sequence_Of_Statements (Loc,
+  New_List (Rstmt;
+  else
+ --  pragma Assert (not Is_Limited_Type (Typ));
+ --  Returning a local object, shouldn't happen in the case of a
+ --  limited type, but currently occurs in DSA stubs in Ada 95 mode???
 
+ Stms := New_List (
+   Odecl,
+   Rstmt,
+   Make_Simple_Return_Statement (Loc,
+ Expression => Make_Identifier (Loc, Name_V)));
+  end if;
+
   Fnam :=
 Make_Defining_Identifier (Loc,
   Chars => Make_TSS_Name_Local (Typ, TSS_Stream_Input));


[Ada] gnatmake with --subdirs= but no -P

2011-08-03 Thread Arnaud Charlet
When gnatmake is invoked with --subdirs= but not with -P, the specified
subdirectory will now be created, if it does exist, and it will be used
as the object directory as if -D had been used.
The test for this is to invoke gnatmake as such:
   gnatmake --subdirs=toto main.adb
The subdirectory toto should be created and should contain ALI and object
files.

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

2011-08-03  Vincent Celier  

* make.adb (Initialize): If --subdirs= is used, but no project file is
specified, attempt to create the specify subdir if it does not already
exist and use it as the object directory as if -D had been specified.

Index: make.adb
===
--- make.adb(revision 177264)
+++ make.adb(working copy)
@@ -61,17 +61,18 @@
 
 with Switch;   use Switch;
 with Switch.M; use Switch.M;
+with Table;
 with Targparm; use Targparm;
-with Table;
 with Tempdir;
 with Types;use Types;
 
+with Ada.Command_Line;  use Ada.Command_Line;
+with Ada.Directories;
 with Ada.Exceptions;use Ada.Exceptions;
-with Ada.Command_Line;  use Ada.Command_Line;
 
+with GNAT.Case_Util;use GNAT.Case_Util;
 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
 with GNAT.Dynamic_HTables;  use GNAT.Dynamic_HTables;
-with GNAT.Case_Util;use GNAT.Case_Util;
 with GNAT.OS_Lib;   use GNAT.OS_Lib;
 
 package body Make is
@@ -5898,6 +5899,10 @@
 
   Prj.Env.Set_Ada_Paths
 (Main_Project, Project_Tree, Use_Include_Path_File);
+  --  (Project => Main_Project,
+  --   In_Tree => Project_Tree,
+  --   Including_Libraries => True,
+  --   Include_Path => Use_Include_Path_File);
 
   --  If switch -C was specified, create a binder mapping file
 
@@ -6729,6 +6734,38 @@
  Make_Failed ("-i and -D cannot be used simultaneously");
   end if;
 
+  --  If --subdirs= is specified, but not -P, this is equivalent to -D,
+  --  except that the directory is created if it does not exist.
+
+  if Prj.Subdirs /= null and then Project_File_Name = null then
+ if Object_Directory_Path /= null then
+Make_Failed ("--subdirs and -D cannot be used simultaneously");
+
+ elsif In_Place_Mode then
+Make_Failed ("--subdirs and -i cannot be used simultaneously");
+
+ else
+if not Is_Directory (Prj.Subdirs.all) then
+   begin
+  Ada.Directories.Create_Path (Prj.Subdirs.all);
+   exception
+  when others =>
+ Make_Failed ("unable to create object directory " &
+  Prj.Subdirs.all);
+   end;
+end if;
+
+Object_Directory_Present := True;
+
+declare
+   Argv : constant String (1 .. Prj.Subdirs'Length) :=
+Prj.Subdirs.all;
+begin
+   Scan_Make_Arg (Env, Argv, And_Save => False);
+end;
+ end if;
+  end if;
+
   --  Deal with -C= switch
 
   if Gnatmake_Mapping_File /= null then


[trans-mem] New TM method: serial-irrevocable on first write

2011-08-03 Thread Torvald Riegel
This adds a new TM method which lets transactions simply read through
without any protection until the first write in the transaction, upon
which the transaction switches to serial-irrevocable mode (thus
isolating all other transactions from uncommitted writes).

This can work well for read-mostly workloads but is too simplistic for
anything else. Nevertheless, it's useful to test the performance of the
upcoming changes to the serial lock implementation, and can be better
than always going to serial mode (which currently is the only
implemented TM method).

OK for branch?
commit a2eefe78d18203c40de0f4b81dc934ff575d8ee5
Author: Torvald Riegel 
Date:   Thu Jul 28 21:21:12 2011 +0200

Add serialirr_onwrite_dispatch and use as new default method, for now.

* retry.cc (GTM::gtm_transaction::decide_begin_dispatch): Use
serialirr_onwrite_dispatch as new default for now.
* method-serial.cc (serialirr_onwrite_dispatch): New.
(GTM::dispatch_serialirr_onwrite): New.
* libitm_i.h: Same.

diff --git a/libitm/libitm_i.h b/libitm/libitm_i.h
index 093fc0e..97f535a 100644
--- a/libitm/libitm_i.h
+++ b/libitm/libitm_i.h
@@ -252,6 +252,7 @@ extern void GTM_fatal (const char *fmt, ...)
 
 extern abi_dispatch *dispatch_serial();
 extern abi_dispatch *dispatch_serialirr();
+extern abi_dispatch *dispatch_serialirr_onwrite();
 
 extern gtm_cacheline_mask gtm_mask_stack(gtm_cacheline *, gtm_cacheline_mask);
 
diff --git a/libitm/method-serial.cc b/libitm/method-serial.cc
index 5912791..430f004 100644
--- a/libitm/method-serial.cc
+++ b/libitm/method-serial.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
Contributed by Richard Henderson .
 
This file is part of the GNU Transactional Memory Library (libitm).
@@ -41,6 +41,10 @@ class serialirr_dispatch : public abi_dispatch
   serialirr_dispatch() : abi_dispatch(false, true, true, false) { }
 
  protected:
+  serialirr_dispatch(bool ro, bool wt, bool uninstrumented,
+  bool closed_nesting) :
+abi_dispatch(ro, wt, uninstrumented, closed_nesting) { }
+
   // Transactional loads and stores simply access memory directly.
   // These methods are static to avoid indirect calls, and will be used by the
   // virtual ABI dispatch methods or by static direct-access methods created
@@ -139,10 +143,65 @@ public:
   serial_dispatch() : abi_dispatch(false, true, false, true) { }
 };
 
+
+// Like serialirr_dispatch but does not requests serial-irrevocable mode until
+// the first write in the transaction. Can be useful for read-mostly workloads
+// and testing, but is likely too simple to be of general purpose.
+class serialirr_onwrite_dispatch : public serialirr_dispatch
+{
+ public:
+  serialirr_onwrite_dispatch() :
+serialirr_dispatch(false, true, false, false) { }
+
+ protected:
+  static void pre_write()
+  {
+gtm_transaction *tx = gtm_tx();
+if (!(tx->state & (gtm_transaction::STATE_SERIAL
+| gtm_transaction::STATE_IRREVOCABLE)))
+  tx->serialirr_mode();
+  }
+
+  // Transactional loads access memory directly.
+  // Transactional stores switch to serial mode first.
+  template  static void store(V* addr, const V value,
+  ls_modifier mod)
+  {
+pre_write();
+serialirr_dispatch::store(addr, value, mod);
+  }
+
+ public:
+  static void memtransfer_static(void *dst, const void* src, size_t size,
+  bool may_overlap, ls_modifier dst_mod, ls_modifier src_mod)
+  {
+pre_write();
+serialirr_dispatch::memtransfer_static(dst, src, size, may_overlap,
+dst_mod, src_mod);
+  }
+
+  static void memset_static(void *dst, int c, size_t size, ls_modifier mod)
+  {
+pre_write();
+serialirr_dispatch::memset_static(dst, c, size, mod);
+  }
+
+  CREATE_DISPATCH_METHODS(virtual, )
+  CREATE_DISPATCH_METHODS_MEM()
+
+  virtual void rollback(gtm_transaction_cp *cp)
+  {
+gtm_transaction *tx = gtm_tx();
+if (tx->state & gtm_transaction::STATE_IRREVOCABLE)
+  abort();
+  }
+};
+
 } // anon namespace
 
 static const serialirr_dispatch o_serialirr_dispatch;
 static const serial_dispatch o_serial_dispatch;
+static const serialirr_onwrite_dispatch o_serialirr_onwrite_dispatch;
 
 abi_dispatch *
 GTM::dispatch_serialirr ()
@@ -156,6 +215,13 @@ GTM::dispatch_serial ()
   return const_cast(&o_serial_dispatch);
 }
 
+abi_dispatch *
+GTM::dispatch_serialirr_onwrite ()
+{
+  return
+  const_cast(&o_serialirr_onwrite_dispatch);
+}
+
 // Put the transaction into serial-irrevocable mode.
 
 void
diff --git a/libitm/retry.cc b/libitm/retry.cc
index 199201a..5b3bf90 100644
--- a/libitm/retry.cc
+++ b/libitm/retry.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
Contributed by Richard Henderson .
 
This file is part of the GNU Transactional Memory Library (libitm).
@@ -87,6 +87,8 @@ GTM::gtm_tr

[trans-mem] Move state from gtm_thread to gtm_transaction

2011-08-03 Thread Torvald Riegel
patch3:
After the previous change to flat nesting by default, checkpoints, and
thus having only a single gtm_transaction object per thread, we can move
the local_tid field to gtm_transaction too. As a result, we don't have
to access gtm_thread in GTM_begin_transaction anymore.

patch4:
A small fix that adds a missing set-up call for gtm_thread. And a
matching test case, which tests that the functions in query.cc work even
if no transaction has been executed so far in this thread.

OK for branch?
commit 33c3c869c7cb986bcca3f3f44b0412278e880a82
Author: Torvald Riegel 
Date:   Fri Jul 29 16:09:05 2011 +0200

Move local_tid from gtm_thread to gtm_transaction.

* config/generic/tls.h (gtm_thread): Move local_tid from here ...
* libitm_i.h (local_tid): ... to here.
* beginend.cc (GTM::gtm_transaction::begin_transaction): Same.
(GTM::gtm_transaction::operator new): Set up gtm_thread if necessary.

diff --git a/libitm/beginend.cc b/libitm/beginend.cc
index d336d60..a16c3f9 100644
--- a/libitm/beginend.cc
+++ b/libitm/beginend.cc
@@ -43,7 +43,7 @@ static _ITM_transactionId_t global_tid;
 void *
 GTM::gtm_transaction::operator new (size_t s)
 {
-  gtm_thread *thr = gtm_thr ();
+  gtm_thread *thr = setup_gtm_thr ();
   void *tx;
 
   assert(s == sizeof(gtm_transaction));
@@ -112,8 +112,6 @@ GTM::gtm_transaction::begin_transaction (uint32_t prop, 
const gtm_jmpbuf *jb)
   if (unlikely(prop & pr_undoLogCode))
 GTM_fatal("pr_undoLogCode not supported");
 
-  gtm_thread *thr = setup_gtm_thr ();
-
   tx = gtm_tx();
   if (tx == NULL)
 {
@@ -214,18 +212,18 @@ GTM::gtm_transaction::begin_transaction (uint32_t prop, 
const gtm_jmpbuf *jb)
 
   // As long as we have not exhausted a previously allocated block of TIDs,
   // we can avoid an atomic operation on a shared cacheline.
-  if (thr->local_tid & (tid_block_size - 1))
-tx->id = thr->local_tid++;
+  if (tx->local_tid & (tid_block_size - 1))
+tx->id = tx->local_tid++;
   else
 {
 #ifdef HAVE_64BIT_SYNC_BUILTINS
   tx->id = __sync_add_and_fetch (&global_tid, tid_block_size);
-  thr->local_tid = tx->id + 1;
+  tx->local_tid = tx->id + 1;
 #else
   pthread_mutex_lock (&global_tid_lock);
   global_tid += tid_block_size;
   tx->id = global_tid;
-  thr->local_tid = tx->id + 1;
+  tx->local_tid = tx->id + 1;
   pthread_mutex_unlock (&global_tid_lock);
 #endif
 }
diff --git a/libitm/config/generic/tls.h b/libitm/config/generic/tls.h
index 82d7c66..8a39b80 100644
--- a/libitm/config/generic/tls.h
+++ b/libitm/config/generic/tls.h
@@ -50,12 +50,6 @@ struct gtm_thread
   void *free_tx[MAX_FREE_TX];
   unsigned free_tx_idx, free_tx_count;
 
-  // In order to reduce cacheline contention on global_tid during
-  // beginTransaction, we allocate a block of 2**N ids to the thread
-  // all at once.  This number is the next value to be allocated from
-  // the block, or 0 % 2**N if no such block is allocated.
-  _ITM_transactionId_t local_tid;
-
   // The value returned by _ITM_getThreadnum to identify this thread.
   // ??? At present, this is densely allocated beginning with 1 and
   // we don't bother filling in this value until it is requested.
diff --git a/libitm/libitm_i.h b/libitm/libitm_i.h
index 97f535a..7d475be 100644
--- a/libitm/libitm_i.h
+++ b/libitm/libitm_i.h
@@ -168,6 +168,12 @@ struct gtm_transaction
   // A bitmask of the above.
   uint32_t state;
 
+  // In order to reduce cacheline contention on global_tid during
+  // beginTransaction, we allocate a block of 2**N ids to the thread
+  // all at once.  This number is the next value to be allocated from
+  // the block, or 0 % 2**N if no such block is allocated.
+  _ITM_transactionId_t local_tid;
+
   // Data used by eh_cpp.c for managing exceptions within the transaction.
   uint32_t cxa_catch_count;
   void *cxa_unthrown;
commit 22c19978ba11c0ae0321449d8809260ab5f97741
Author: Torvald Riegel 
Date:   Fri Jul 29 16:19:41 2011 +0200

Fix missing setup of gtm_thread if no transaction has run yet.

* query.cc (_ITM_getThreadnum): Set up gtm_thread if necessary.
* testsuite/libitm.c/notx.c: New file.

diff --git a/libitm/query.cc b/libitm/query.cc
index 9a95211..02f1813 100644
--- a/libitm/query.cc
+++ b/libitm/query.cc
@@ -67,7 +67,7 @@ int ITM_REGPARM
 _ITM_getThreadnum (void)
 {
   static int global_num;
-  struct gtm_thread *thr = gtm_thr();
+  struct gtm_thread *thr = setup_gtm_thr();
   int num = thr->thread_num;
 
   if (num == 0)
diff --git a/libitm/testsuite/libitm.c/notx.c b/libitm/testsuite/libitm.c/notx.c
new file mode 100644
index 000..92ae3e1
--- /dev/null
+++ b/libitm/testsuite/libitm.c/notx.c
@@ -0,0 +1,36 @@
+/* These tests all check whether initialization happens properly even if no
+   transaction has been used in the current thread yet.  */
+#include 
+#include 
+#include 
+
+static void *test1 (void *dummy __attribute__((unused)))
+{
+  if (_ITM_inTransaction() != outsideTransac

[PATCH] Fix PR49938

2011-08-03 Thread Richard Guenther

This fixes PR49938 by instead of asserting return chrec_dont_know.

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

Richard.

2011-08-03  Richard Guenther  

PR tree-optimization/49938
* tree-scalar-evolution.c (interpret_loop_phi): Gracefully
deal with a POLYNOMIAL_CHREC.

* g++.dg/torture/pr49938.C: New testcase.

Index: gcc/tree-scalar-evolution.c
===
--- gcc/tree-scalar-evolution.c (revision 177242)
+++ gcc/tree-scalar-evolution.c (working copy)
@@ -1642,8 +1642,8 @@ interpret_loop_phi (struct loop *loop, g
   else if (TREE_CODE (res) == POLYNOMIAL_CHREC)
new_init = CHREC_LEFT (res);
   STRIP_USELESS_TYPE_CONVERSION (new_init);
-  gcc_assert (TREE_CODE (new_init) != POLYNOMIAL_CHREC);
-  if (!operand_equal_p (init_cond, new_init, 0))
+  if (TREE_CODE (new_init) == POLYNOMIAL_CHREC
+ || !operand_equal_p (init_cond, new_init, 0))
return chrec_dont_know;
 }
 
Index: gcc/testsuite/g++.dg/torture/pr49938.C
===
--- gcc/testsuite/g++.dg/torture/pr49938.C  (revision 0)
+++ gcc/testsuite/g++.dg/torture/pr49938.C  (revision 0)
@@ -0,0 +1,48 @@
+#include 
+#include 
+typedef unsigned short uint16;
+
+namespace base {
+class StringPiece
+  {
+public:
+   typedef std::size_t size_type;
+   size_type size() const { return length_; }
+   size_type length_;
+  };
+}
+
+namespace net {
+class DNSSECKeySet
+  {
+   bool CheckSignature (const base::StringPiece& name, const
+base::StringPiece& zone, const
+base::StringPiece& signature, uint16 rrtype,
+const std::vector& rrdatas);
+  };
+}
+
+template  class scoped_array
+{
+public: typedef C element_type;
+   explicit scoped_array(C* p = __null):array_(p) {}
+private:   C* array_;
+};
+
+namespace net {
+bool DNSSECKeySet::CheckSignature (const base::StringPiece& name,
+  const base::StringPiece& zone, const 
base::StringPiece& signature,
+  uint16 rrtype, const 
std::vector& rrdatas)
+  {
+   unsigned signed_data_len = 0;
+   for (std::vector::const_iterator i =
+rrdatas.begin();
+i != rrdatas.end(); i++) {
+   signed_data_len += 2;
+   signed_data_len += i->size();
+   }
+   scoped_array signed_data(new unsigned
+   char[signed_data_len]);
+  }
+}
+


[trans-mem] Release transaction objects on thread termination

2011-08-03 Thread Torvald Riegel
This patch removes the per-thread free-list of gtm_transaction objects.
With a single stable gtm_transaction object per thread, it is not
necessary anymore. Furthermore, a destructor function of a pthread TLS
key is used to release a thread's gtm_transaction object when this
thread terminates. This works even when transactions are used in other
TLS key's destructors because the key is initialized whenever a
transaction is used for the first time in a thread (or after a previous
destruction in this thread).
The test for the release doesn't really check that the release happens
(and can't because we do black-box testing), but at least it will
trigger the release twice.

OK for branch?
commit 77fd947e31f5c51c01e3fb833cd1a5e9379c2dc9
Author: Torvald Riegel 
Date:   Fri Jul 29 20:37:30 2011 +0200

Release transaction data on thread termination.

* config/generic/tls.h: Remove the free list for transactions and ...
* beginend.cc (GTM::gtm_transaction::operator new): ... allocate ...
(GTM::gtm_transaction::operator delete): ... and release here.
(thread_exit_handler): New. Delete tx when thread terminates.
(thread_exit_init): New.
(GTM::gtm_transaction::begin_transaction): Set up on-exit handler.
* testsuite/libitm.c/txrelease.c: New file.

diff --git a/libitm/beginend.cc b/libitm/beginend.cc
index a16c3f9..08592a3 100644
--- a/libitm/beginend.cc
+++ b/libitm/beginend.cc
@@ -38,52 +38,58 @@ uint64_t GTM::gtm_spin_count_var = 1000;
 
 static _ITM_transactionId_t global_tid;
 
-/* Allocate a transaction structure.  Reuse an old one if possible.  */
+// Provides a on-thread-exit callback used to release per-thread data.
+static pthread_key_t tx_release_key;
+static pthread_once_t tx_release_once = PTHREAD_ONCE_INIT;
+
+
+/* Allocate a transaction structure.  */
 
 void *
 GTM::gtm_transaction::operator new (size_t s)
 {
-  gtm_thread *thr = setup_gtm_thr ();
   void *tx;
 
   assert(s == sizeof(gtm_transaction));
 
-  if (thr->free_tx_count == 0)
-tx = xmalloc (sizeof (gtm_transaction));
-  else
-{
-  thr->free_tx_count--;
-  tx = thr->free_tx[thr->free_tx_idx];
-  thr->free_tx_idx = (thr->free_tx_idx + 1) % gtm_thread::MAX_FREE_TX;
-}
+  tx = xmalloc (sizeof (gtm_transaction), true);
   memset (tx, 0, sizeof (gtm_transaction));
 
   return tx;
 }
 
-/* Queue a transaction structure for freeing.  We never free the given
-   transaction immediately -- this is a requirement of abortTransaction
-   as the jmpbuf is used immediately after calling this function.  Thus
-   the requirement that this queue be per-thread.  */
+/* Free the given transaction. Raises an error if the transaction is still
+   in use.  */
 
 void
 GTM::gtm_transaction::operator delete(void *tx)
 {
-  gtm_thread *thr = gtm_thr ();
-  unsigned idx
-= (thr->free_tx_idx + thr->free_tx_count) % gtm_thread::MAX_FREE_TX;
+  free(tx);
+}
 
-  if (thr->free_tx_count == gtm_thread::MAX_FREE_TX)
+static void
+thread_exit_handler(void *dummy __attribute__((unused)))
+{
+  gtm_transaction *tx = gtm_tx();
+  if (tx)
 {
-  thr->free_tx_idx = (thr->free_tx_idx + 1) % gtm_thread::MAX_FREE_TX;
-  free (thr->free_tx[idx]);
+  if (tx->nesting > 0)
+GTM_fatal("Thread exit while a transaction is still active.");
+  delete tx;
+  set_gtm_tx(NULL);
 }
-  else
-thr->free_tx_count++;
+  if (pthread_setspecific(tx_release_key, NULL))
+GTM_fatal("Setting tx release TLS key failed.");
+}
 
-  thr->free_tx[idx] = tx;
+static void
+thread_exit_init()
+{
+  if (pthread_key_create(&tx_release_key, thread_exit_handler))
+GTM_fatal("Creating tx release TLS key failed.");
 }
 
+
 #ifndef HAVE_64BIT_SYNC_BUILTINS
 static pthread_mutex_t global_tid_lock = PTHREAD_MUTEX_INITIALIZER;
 #endif
@@ -113,10 +119,17 @@ GTM::gtm_transaction::begin_transaction (uint32_t prop, 
const gtm_jmpbuf *jb)
 GTM_fatal("pr_undoLogCode not supported");
 
   tx = gtm_tx();
-  if (tx == NULL)
+  if (unlikely(tx == NULL))
 {
   tx = new gtm_transaction;
   set_gtm_tx(tx);
+
+  if (pthread_once(&tx_release_once, thread_exit_init))
+GTM_fatal("Initializing tx release TLS key failed.");
+  // Any non-null value is sufficient to trigger releasing of this
+  // transaction when the current thread terminates.
+  if (pthread_setspecific(tx_release_key, tx))
+GTM_fatal("Setting tx release TLS key failed.");
 }
 
   if (tx->nesting > 0)
diff --git a/libitm/config/generic/tls.h b/libitm/config/generic/tls.h
index 8a39b80..3eea204 100644
--- a/libitm/config/generic/tls.h
+++ b/libitm/config/generic/tls.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
Contributed by Richard Henderson .
 
This file is part of the GNU Transactional Memory Library (libitm).
@@ -41,15 +41,6 @@ struct gtm_thread
   abi_dispatch *disp;
 #endif
 
-  // T

Re: [PATCH 4/6] Shrink-wrapping

2011-08-03 Thread Bernd Schmidt
On 08/03/11 12:41, Alan Modra wrote:
> This patch makes rebuild_jump_labels set JUMP_LABEL appropriately
> for return jumps, and fixes sharing for RETURN.  Since ANY_RETURN_P(X)
> is defined as ((X) == ret_rtx), RETURNs need to stay shared.
> Bootstrapped and regression tested powerpc-linux and powerpc64-linux.
> OK to apply?
> 
>   PR rtl-optimization/49941
>   * jump.c (mark_jump_label): Comment.
>   (mark_jump_label_1): Set JUMP_LABEL for return jumps.
>   * emit-rtl.c (copy_rtx_if_shared_1, copy_insn_1): Leave RETURN shared.
>   (mark_used_flags): Don't mark RETURN.

Ok, thanks.


Bernd


Re: C++ PATCH for c++/49813 (__builtin_isinf in constant expression)

2011-08-03 Thread Gabriel Dos Reis
On Mon, Aug 1, 2011 at 1:12 PM, Jason Merrill  wrote:
> Another issue raised in 49813 is that morally_constexpr_builtin_function_p
> was rejecting __builtin_isinf because it has a variadic signature.  I'm
> changing potential_constant_expression_1 to just allow any built-in function
> in a constexpr function; if it doesn't expand to a constant, we'll deal with
> that when we actually expand it.

OK; at the time, I did not form a firm policy about variadic builtins.


Re: [Patch, Fortran] (Coarray) Fix constraint checks for LOCK_TYPE

2011-08-03 Thread Mikael Morin
Hello,

On Tuesday 02 August 2011 18:08:05 Tobias Burnus wrote:
> This patch fixes two issues:
> 
> a) LOCK(coarray%lock_type_comp) is also a coarray.
> 
> b) The following constraint was incompletely checked for: C1302. For
> reference, I also list C1303/C1304.

[...]

> 
> PS: It somehow took me quite some time to understand "subcomponent" even
> though the standard is rather clear about it. 
Is it? It seems I haven't understood the constraint as you did.
And by the way, are there cases of direct components that are not 
subcomponents? I find it hard to distinguish them.

> For reference:
> 
> "1.3.33.3 subcomponent --  direct component that is a
> subobject of the structure (6.4.2)
> 
> "1.3.33.1 direct component -- one of the components, or one of the
> direct components of a nonpointer nonallocatable component (4.5.1)"
> 
and:
> C1302 A named variable of type LOCK TYPE shall be a coarray. A named
> variable with a noncoarray subcomponent of type LOCK TYPE shall be a
> coarray.
> 
So basically, one looks at the components of a structure, and the components 
of all the non-allocatable non-pointer derived type components (and so on 
recursively...).
Among those components, if one has type LOCK_TYPE and is not a coarray, then 
the enclosing variable shall be a coarray (which seems to mean that all 
variables of this type have to be a coarray).
Though variables in the general case can be components, I don't think it is 
the case here as only named variables are involved here.
Does that sound right?
Then, ...

> lock-check.diff
>   2011-08-02  Tobias Burnus  
> 
> PR fortran/18918
> * parse.c (parse_derived): Add lock_type
> checks, improve coarray_comp handling.
> * resolve.c (resolve_allocate_expr,
> resolve_lock_unlock, resolve_symbol): Fix lock_type
> constraint checks.
> 
> 2011-08-02  Tobias Burnus  
> 
> PR fortran/18918
> * gfortran.dg/coarray_lock_1.f90: Update dg-error.
> * gfortran.dg/coarray_lock_3.f90: Fix test.
> * gfortran.dg/coarray_lock_4.f90: New.
> * gfortran.dg/coarray_lock_5.f90: New.
> * gfortran.dg/coarray_lock_6.f90: New.
> 
> diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
> index ba28648..6fca032 100644
> --- a/gcc/fortran/parse.c
> +++ b/gcc/fortran/parse.c
> @@ -2010,7 +2010,7 @@ parse_derived (void)
>gfc_statement st;
>gfc_state_data s;
>gfc_symbol *sym;
> -  gfc_component *c;
> +  gfc_component *c, *lock_comp = NULL;
>  
>accept_statement (ST_DERIVED_DECL);
>push_state (&s, COMP_DERIVED, gfc_new_block);
> @@ -2118,19 +2118,28 @@ endType:
>sym = gfc_current_block ();
>for (c = sym->components; c; c = c->next)
>  {
> +  bool coarray, lock_type, allocatable, pointer;
> +  coarray = lock_type = allocatable = pointer = false;
> +
>/* Look for allocatable components.  */
>if (c->attr.allocatable
>   || (c->ts.type == BT_CLASS && c->attr.class_ok
>   && CLASS_DATA (c)->attr.allocatable)
>   || (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.alloc_comp))
> -   sym->attr.alloc_comp = 1;
> +   {
> + allocatable = true;
> + sym->attr.alloc_comp = 1;
> +   }
>  
>/* Look for pointer components.  */
>if (c->attr.pointer
>   || (c->ts.type == BT_CLASS && c->attr.class_ok
>   && CLASS_DATA (c)->attr.class_pointer)
>   || (c->ts.type == BT_DERIVED && c->ts.u.derived-
>attr.pointer_comp))
> -   sym->attr.pointer_comp = 1;
> +   {
> + pointer = true;
> + sym->attr.pointer_comp = 1;
> +   }
>  
>/* Look for procedure pointer components.  */
>if (c->attr.proc_pointer
> @@ -2140,15 +2149,62 @@ endType:
>  
>/* Looking for coarray components.  */
>if (c->attr.codimension
> - || (c->attr.coarray_comp && !c->attr.pointer && !c-
>attr.allocatable))
> -   sym->attr.coarray_comp = 1;
> + || (c->ts.type == BT_CLASS && c->attr.class_ok
> + && CLASS_DATA (c)->attr.codimension))
> +   {
> + coarray = true;
> + sym->attr.coarray_comp = 1;
> +   }
> + 
> +  if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.codimension)
> +   {
> + coarray = true;
> + if (!pointer && !allocatable)
> +   sym->attr.coarray_comp = 1;
> +   }
>  
>/* Looking for lock_type components.  */
> -  if (c->attr.lock_comp
> - || (sym->ts.type == BT_DERIVED
> +  if ((c->ts.type == BT_DERIVED
>   && c->ts.u.derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
> - && c->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE))
> -   sym->attr.lock_comp = 1;
> + && c->ts.u.derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE)
> + || (c->ts.type == BT_CLASS && c->attr.class_ok
> + && CLASS_DATA (c)->ts.u.derived->from_intmod
> +== INTMOD_ISO_FORTRA

Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Kai Tietz
Hello,

I noticed that I disallowed expansion of ~(X bitwise-binary-ops) for
none-boolean type.  This limitiation isn't necessary and prevented
even some pattern-detections.
I've added 3 new testcases for this to the patch.

ChangeLog

2011-08-03  Kai Tietz  

* tree-ssa-reassoc.c (gimple build_and_add_sum): Add forwarder
declaration and add support for unary-expression.
(remove_visited_stmt_chain): Add forwarder declaration.
(make_new_tmp_statement): New helper function.
(expand_not_bitwise_binary): Likewise.
(break_up_bitwise_combined_stmt): Likeiwise.
(break_up_subtract_bb): Add call to break_up_bitwise_combined_stmt.


ChangeLog

2011-08-03  Kai Tietz  

* gcc.dg/tree-ssa/reassoc-24.c: New test.
* gcc.dg/tree-ssa/reassoc-25.c: New test.
* gcc.dg/tree-ssa/reassoc-26.c: New test.
* gcc.dg/tree-ssa/reassoc-27.c: New test.
* gcc.dg/tree-ssa/reassoc-28.c: New test.
* gcc.dg/tree-ssa/reassoc-29.c: New test.

Bootstrapped and regression tested for all languages (including Ada
and Obj-C++) on host x86_64-pc-linux-gnu.
Ok for apply?

Regards,
Kai

Index: gcc/gcc/tree-ssa-reassoc.c
===
--- gcc.orig/gcc/tree-ssa-reassoc.c
+++ gcc/gcc/tree-ssa-reassoc.c
@@ -41,6 +41,10 @@ along with GCC; see the file COPYING3.
 #include "cfgloop.h"
 #include "flags.h"

+/* Forwarders.  */
+static gimple build_and_add_sum (tree, tree, tree, enum tree_code);
+static void remove_visited_stmt_chain (tree);
+
 /*  This is a simple global reassociation pass.  It is, in part, based
 on the LLVM pass of the same name (They do some things more/less
 than we do, in different orders, etc).
@@ -48,7 +52,9 @@ along with GCC; see the file COPYING3.
 It consists of five steps:

 1. Breaking up subtract operations into addition + negate, where
-it would promote the reassociation of adds.
+it would promote the reassociation of adds.  Additionally breaking
+up combined expression made out of boolean-typed bitwise expressions
+for improving simplification.

 2. Left linearization of the expression trees, so that (A+B)+(C+D)
 becomes (((A+B)+C)+D), which is easier for us to rewrite later.
@@ -554,6 +560,231 @@ get_unary_op (tree name, enum tree_code
   return NULL_TREE;
 }

+/* Create a temorary register expression with type TYPE, tree code CODE, and
+   operands OP1 and OP2.  If REF_DEF is a valid gimple statement, we use its
+   location for new generated temporary.
+   Function returns left-hand-side of new generated temporary register.  */
+static tree
+make_new_tmp_statement (tree type, enum tree_code code, tree op1, tree op2,
+   gimple ref_def)
+{
+  gimple sum;
+  tree tmpvar = create_tmp_reg (type, NULL);
+  add_referenced_var (tmpvar);
+  sum = build_and_add_sum (tmpvar, op1, op2, code);
+  if (ref_def)
+gimple_set_location (sum, gimple_location (ref_def));
+  return gimple_get_lhs (sum);
+}
+
+/* Perfrom on tree LHS with optional definition statement EPXR
+   a logic-not operation.  TYPE is of kind boolean with a 1-bit
+   precision.  */
+static tree
+expand_not_bitwise_binary (tree type, tree lhs, gimple expr)
+{
+  enum tree_code code = ERROR_MARK;
+  tree op1, op2;
+  gimple s1 = NULL, s2 = NULL;
+
+  if (expr && is_gimple_assign (expr))
+code = gimple_assign_rhs_code (expr);
+  else if (TREE_CODE (lhs) == INTEGER_CST)
+return fold_build1 (BIT_NOT_EXPR, type, lhs);
+
+  /* ~(~X) -> X.  */
+  if (code == BIT_NOT_EXPR)
+return gimple_assign_rhs1 (expr);
+  /* Invert comparison if possible, otherwise fall through to
+ default case.  */
+  else if (TREE_CODE_CLASS (code) == tcc_comparison)
+{
+  enum tree_code ncode;
+  ncode = invert_tree_comparison (code,
+ HONOR_NANS (TYPE_MODE (type)));
+  if (ncode != ERROR_MARK)
+   return make_new_tmp_statement (type, ncode,
+  gimple_assign_rhs1 (expr),
+  gimple_assign_rhs2 (expr),
+  expr);
+}
+  /* ~(A & B) -> ~A | ~B.  */
+  else if (code == BIT_AND_EXPR)
+{
+  op1 = gimple_assign_rhs1 (expr);
+  if (TREE_CODE (op1) == SSA_NAME)
+   s1 = SSA_NAME_DEF_STMT (op1);
+  op2 = gimple_assign_rhs2 (expr);
+  if (TREE_CODE (op2) == SSA_NAME)
+   s2 = SSA_NAME_DEF_STMT (op2);
+  op1 = expand_not_bitwise_binary (type, op1, s1);
+  op2 = expand_not_bitwise_binary (type, op2, s2);
+  if (TREE_CODE (op2) == INTEGER_CST && integer_zerop (op2))
+   return op1;
+  else if (TREE_CODE (op2) == INTEGER_CST && integer_all_onesp (op2))
+   return op2;
+  return make_new_tmp_statement (type, BIT_IOR_EXPR, op1, op2, expr);
+}
+  /* ~(A | B) -> ~A & ~B.  */
+  else if (code == BIT_IOR_EXPR)
+{
+  op1 = gimple_assign_rhs1 (expr);
+  if (TREE_

[trans-mem] Test that nested txns started from pure/unsafe code work correctly

2011-08-03 Thread Torvald Riegel
Tests that new transactions can be started from both transaction_pure
and transaction_unsafe code. This also checks proper handling of
reentrant nesting in the serial_lock implementation (reentrant in the
sense that we go from transactional to nontransactional to transactional
code).
This test currently does not compile due to a GCC bug (no bug report
yet).

OK for branch?
commit c1eafd7cfbdb71dadb3ac5f797fb2a596026f1be
Author: Torvald Riegel 
Date:   Mon Aug 1 15:43:05 2011 +0200

Test that nested txns started from pure/unsafe code work correctly.

* testsuite/libitm.c/reentrant.c: New file.

diff --git a/libitm/testsuite/libitm.c/reentrant.c 
b/libitm/testsuite/libitm.c/reentrant.c
new file mode 100644
index 000..aeb9a0e
--- /dev/null
+++ b/libitm/testsuite/libitm.c/reentrant.c
@@ -0,0 +1,64 @@
+/* Tests that new transactions can be started from both transaction_pure and
+   transaction_unsafe code. This also requires proper handling of reentrant
+   nesting in the serial_lock implementation. */
+
+#include 
+#include 
+#include 
+
+int x = 0;
+
+int __attribute__((transaction_pure)) pure(int i)
+{
+  __transaction {
+x++;
+  }
+  if (_ITM_inTransaction() == outsideTransaction)
+abort();
+  return i+1;
+}
+
+int __attribute__((transaction_unsafe)) unsafe(int i)
+{
+  if (_ITM_inTransaction() != inIrrevocableTransaction)
+abort();
+  __transaction {
+x++;
+  }
+  if (_ITM_inTransaction() != inIrrevocableTransaction)
+abort();
+  return i+1;
+}
+
+static void *thread (void *dummy __attribute__((unused)))
+{
+  __transaction {
+pure(1);
+  }
+  __transaction[[relaxed]] {
+unsafe(1);
+  }
+  return 0;
+}
+
+int main()
+{
+  pthread_t pt;
+  int r = 0;
+
+  __transaction {
+r += pure(1) + x;
+  }
+  __transaction[[relaxed]] {
+r += unsafe(1) + x;
+  }
+  if (r != 7)
+abort();
+
+  // Spawn a new thread to check that the serial lock is not held.
+  pthread_create(&pt, NULL, thread, NULL);
+  pthread_join(pt, NULL);
+  if (x != 4)
+abort();
+  return 0;
+}


[trans-mem] Test static constructors inside of transactional code

2011-08-03 Thread Torvald Riegel
Based on recent discussions among the C++ TM specification group, static
constructors should be allowed in transactional (i.e., transaction_safe)
code. GCC should have a wrapper assigment for __cxa_guard_acquire and
__cxa_guard_release, and libitm should implement wrappers that guarantee
atomicity of these constructors wrt the enclosing transaction.

If we find out that supporting and implementing isn't feasible in
practice, GCC should provide a better error message (eg, "static
constructors not allowed in transactional code" instead of complaining
about the __cxa* functions), and we should move this test to the GCC
tests.

OK for branch?
commit 537788ae46aec7fcc45eee5ae56cfe3314a9ef11
Author: Torvald Riegel 
Date:   Wed Aug 3 13:31:46 2011 +0200

Test static constructors inside of transactional code.

* testsuite/libitm.c++/static_ctor.C: New file.

diff --git a/libitm/testsuite/libitm.c++/static_ctor.C 
b/libitm/testsuite/libitm.c++/static_ctor.C
new file mode 100644
index 000..f618f68
--- /dev/null
+++ b/libitm/testsuite/libitm.c++/static_ctor.C
@@ -0,0 +1,38 @@
+// { dg-do run }
+/* Tests static constructors inside of transactional code.  */
+
+#include 
+#include 
+
+int f(int x) __attribute__((noinline,transaction_safe));
+int f(int x)
+{
+  static int y = x;
+  return y*x;
+}
+
+static void *thread (void *dummy __attribute__((unused)))
+{
+  int bar;
+  __transaction { bar = f(10); }
+  if (bar != 100)
+abort();
+  return 0;
+}
+
+int main()
+{
+  int bar;
+
+  // First, initialize y in another thread.
+  pthread_t pt;
+  pthread_create(&pt, NULL, thread, NULL);
+  pthread_join(pt, NULL);
+
+  // Now y should already be initialized.
+  __transaction { bar = f(20); }
+  if (bar != 200)
+abort();
+
+  return 0;
+}


[PATCH] Fix PR49958

2011-08-03 Thread Richard Guenther

This fixes a wrong re-association which can introduce undefined
overflow.  The fix is to perform this only when overflow is known
to wrap.

Bootstrap and regtest pending on x86_64-unknown-linux-gnu.

Richard.

2011-08-03  Richard Guenther  

PR middle-end/49958
* fold-const.c (fold_binary_loc): Only associate
(+ (+ (* a b) c) (* d e)) as (+ (+ (* a b) (* d e)) c) if
overflow wraps.

Index: gcc/fold-const.c
===
--- gcc/fold-const.c(revision 177094)
+++ gcc/fold-const.c(working copy)
@@ -9712,12 +9712,13 @@ fold_binary_loc (location_t loc,
  /* Reassociate (plus (plus (mult) (foo)) (mult)) as
 (plus (plus (mult) (mult)) (foo)) so that we can
 take advantage of the factoring cases below.  */
- if (((TREE_CODE (arg0) == PLUS_EXPR
-   || TREE_CODE (arg0) == MINUS_EXPR)
-  && TREE_CODE (arg1) == MULT_EXPR)
- || ((TREE_CODE (arg1) == PLUS_EXPR
-  || TREE_CODE (arg1) == MINUS_EXPR)
- && TREE_CODE (arg0) == MULT_EXPR))
+ if (TYPE_OVERFLOW_WRAPS (type)
+ && (((TREE_CODE (arg0) == PLUS_EXPR
+   || TREE_CODE (arg0) == MINUS_EXPR)
+  && TREE_CODE (arg1) == MULT_EXPR)
+ || ((TREE_CODE (arg1) == PLUS_EXPR
+  || TREE_CODE (arg1) == MINUS_EXPR)
+ && TREE_CODE (arg0) == MULT_EXPR)))
{
  tree parg0, parg1, parg, marg;
  enum tree_code pcode;
Index: gcc/testsuite/gcc.dg/torture/pr49958.c
===
--- gcc/testsuite/gcc.dg/torture/pr49958.c  (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr49958.c  (revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-options "-fstrict-overflow" } */
+
+extern void abort (void);
+int foo (int i, int j, int o, int m) { return i*o + 1 + j*m > 1; }
+int main()
+{
+  if (foo (- __INT_MAX__ - 1, -1, 1, 1))
+abort ();
+  return 0;
+}


Re: [RFC] Cleanup DW_CFA_GNU_args_size handling

2011-08-03 Thread Georg-Johann Lay
Richard Henderson wrote:
> On 08/01/2011 11:42 AM, Georg-Johann Lay wrote:
>> Is there a specific reason not to define
>> ACCUMULATE_OUTGOING_ARGS on AVR?
> 
> Yes.  So that you can use PUSH.  But as I said in PR49881,
> you probably want to provide -maccumulate-outgoing-args.
> 
> I have a follow-up patch to the last one in that PR...
> 
> 
> r~

PUSH is fine but what about POP?

It's very expensive to pop several bytes, i.e. disabling IRQs, loading and 
storing SP and the like.
Usung store+displacement has not this drawback and as I wrote, come code 
degradations you explained
in PR49881 are artifacts of PR46278, i.e. fake X addressing.

Johann





Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Richard Guenther
On Wed, Aug 3, 2011 at 1:47 PM, Kai Tietz  wrote:
> Hello,
>
> I noticed that I disallowed expansion of ~(X bitwise-binary-ops) for
> none-boolean type.  This limitiation isn't necessary and prevented
> even some pattern-detections.
> I've added 3 new testcases for this to the patch.

You seem to unconditionally expanding operations, that's no good as
nothing will rewrite them back.  For negations we make sure that
we'll process a plus expr chain with the rewritten negates which will
then, at repropagate_negates time, fold the negates back properly.

I don't see this happening for the bitwise stuff at all.

Richard.

> ChangeLog
>
> 2011-08-03  Kai Tietz  
>
>        * tree-ssa-reassoc.c (gimple build_and_add_sum): Add forwarder
>        declaration and add support for unary-expression.
>        (remove_visited_stmt_chain): Add forwarder declaration.
>        (make_new_tmp_statement): New helper function.
>        (expand_not_bitwise_binary): Likewise.
>        (break_up_bitwise_combined_stmt): Likeiwise.
>        (break_up_subtract_bb): Add call to break_up_bitwise_combined_stmt.
>
>
> ChangeLog
>
> 2011-08-03  Kai Tietz  
>
>        * gcc.dg/tree-ssa/reassoc-24.c: New test.
>        * gcc.dg/tree-ssa/reassoc-25.c: New test.
>        * gcc.dg/tree-ssa/reassoc-26.c: New test.
>        * gcc.dg/tree-ssa/reassoc-27.c: New test.
>        * gcc.dg/tree-ssa/reassoc-28.c: New test.
>        * gcc.dg/tree-ssa/reassoc-29.c: New test.
>
> Bootstrapped and regression tested for all languages (including Ada
> and Obj-C++) on host x86_64-pc-linux-gnu.
> Ok for apply?
>
> Regards,
> Kai
>
> Index: gcc/gcc/tree-ssa-reassoc.c
> ===
> --- gcc.orig/gcc/tree-ssa-reassoc.c
> +++ gcc/gcc/tree-ssa-reassoc.c
> @@ -41,6 +41,10 @@ along with GCC; see the file COPYING3.
>  #include "cfgloop.h"
>  #include "flags.h"
>
> +/* Forwarders.  */
> +static gimple build_and_add_sum (tree, tree, tree, enum tree_code);
> +static void remove_visited_stmt_chain (tree);
> +
>  /*  This is a simple global reassociation pass.  It is, in part, based
>     on the LLVM pass of the same name (They do some things more/less
>     than we do, in different orders, etc).
> @@ -48,7 +52,9 @@ along with GCC; see the file COPYING3.
>     It consists of five steps:
>
>     1. Breaking up subtract operations into addition + negate, where
> -    it would promote the reassociation of adds.
> +    it would promote the reassociation of adds.  Additionally breaking
> +    up combined expression made out of boolean-typed bitwise expressions
> +    for improving simplification.
>
>     2. Left linearization of the expression trees, so that (A+B)+(C+D)
>     becomes (((A+B)+C)+D), which is easier for us to rewrite later.
> @@ -554,6 +560,231 @@ get_unary_op (tree name, enum tree_code
>   return NULL_TREE;
>  }
>
> +/* Create a temorary register expression with type TYPE, tree code CODE, and
> +   operands OP1 and OP2.  If REF_DEF is a valid gimple statement, we use its
> +   location for new generated temporary.
> +   Function returns left-hand-side of new generated temporary register.  */
> +static tree
> +make_new_tmp_statement (tree type, enum tree_code code, tree op1, tree op2,
> +                       gimple ref_def)
> +{
> +  gimple sum;
> +  tree tmpvar = create_tmp_reg (type, NULL);
> +  add_referenced_var (tmpvar);
> +  sum = build_and_add_sum (tmpvar, op1, op2, code);
> +  if (ref_def)
> +    gimple_set_location (sum, gimple_location (ref_def));
> +  return gimple_get_lhs (sum);
> +}
> +
> +/* Perfrom on tree LHS with optional definition statement EPXR
> +   a logic-not operation.  TYPE is of kind boolean with a 1-bit
> +   precision.  */
> +static tree
> +expand_not_bitwise_binary (tree type, tree lhs, gimple expr)
> +{
> +  enum tree_code code = ERROR_MARK;
> +  tree op1, op2;
> +  gimple s1 = NULL, s2 = NULL;
> +
> +  if (expr && is_gimple_assign (expr))
> +    code = gimple_assign_rhs_code (expr);
> +  else if (TREE_CODE (lhs) == INTEGER_CST)
> +    return fold_build1 (BIT_NOT_EXPR, type, lhs);
> +
> +  /* ~(~X) -> X.  */
> +  if (code == BIT_NOT_EXPR)
> +    return gimple_assign_rhs1 (expr);
> +  /* Invert comparison if possible, otherwise fall through to
> +     default case.  */
> +  else if (TREE_CODE_CLASS (code) == tcc_comparison)
> +    {
> +      enum tree_code ncode;
> +      ncode = invert_tree_comparison (code,
> +                                     HONOR_NANS (TYPE_MODE (type)));
> +      if (ncode != ERROR_MARK)
> +       return make_new_tmp_statement (type, ncode,
> +                                      gimple_assign_rhs1 (expr),
> +                                      gimple_assign_rhs2 (expr),
> +                                      expr);
> +    }
> +  /* ~(A & B) -> ~A | ~B.  */
> +  else if (code == BIT_AND_EXPR)
> +    {
> +      op1 = gimple_assign_rhs1 (expr);
> +      if (TREE_CODE (op1) == SSA_NAME)
> +       s1 = SSA_NAME_DEF_STMT (op1);
> +      op2 = gimple_as

[RFC PATCH] Add alloc_size attribute to the default operator new and operator new[]

2011-08-03 Thread Jakub Jelinek
Hi!

As mentioned in PR49905, -D_FORTIFY_SOURCE{,=2} handles e.g.
malloc (4) or malloc (16) well, knowing that the resulting pointer
has object size 4 resp. 16, but for new int or new int[4], it currently
doesn't assume anything (i.e. __builtin_object_size (new int, 0) returns
-1).  While I see the C++ standard unfortunately allows redefining
of the new and vector new operators, I wonder if for -D_FORTIFY_SOURCE
we could assume similar properties as for malloc for the object size
checking, i.e. that if these two operators are called with a constant
parameter, the object size allocated is the given size.  I hope there
aren't C++ programs that override the default operator new, allocate fewer
or more bytes and expect that those can be accessed through the pointer
returned by new.  At least -D_FORTIFY_SOURCE=2 is declared to be stricter
than the standard (but -D_FORTIFY_SOURCE=1 is not).  Of course this wouldn't
affect programs not compiled with -D_FORTIFY_SOURCE{,=2}, wouldn't affect
placement new nor any class operator new/new[] (unless it calls the default
operator new/new[]).

Comments?

2011-08-03  Jakub Jelinek  

PR middle-end/49905
* decl.c (cxx_init_decl_processing): Add alloc_size (1) attribute
for operator new and operator new [].

* g++.dg/ext/builtin-object-size3.C: New test.

--- gcc/cp/decl.c.jj2011-07-22 22:14:59.0 +0200
+++ gcc/cp/decl.c   2011-08-03 14:00:48.0 +0200
@@ -3629,6 +3629,7 @@ cxx_init_decl_processing (void)
   current_lang_name = lang_name_cplusplus;
 
   {
+tree newattrs;
 tree newtype, deltype;
 tree ptr_ftype_sizetype;
 tree new_eh_spec;
@@ -3656,7 +3657,11 @@ cxx_init_decl_processing (void)
 else
   new_eh_spec = noexcept_false_spec;
 
-newtype = build_exception_variant (ptr_ftype_sizetype, new_eh_spec);
+newattrs
+  = build_tree_list (get_identifier ("alloc_size"),
+build_tree_list (NULL_TREE, integer_one_node));
+newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
+newtype = build_exception_variant (newtype, new_eh_spec);
 deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
 push_cp_library_fn (NEW_EXPR, newtype);
 push_cp_library_fn (VEC_NEW_EXPR, newtype);
--- gcc/testsuite/g++.dg/ext/builtin-object-size3.C.jj  2011-08-03 
14:06:03.0 +0200
+++ gcc/testsuite/g++.dg/ext/builtin-object-size3.C 2011-08-03 
14:04:21.0 +0200
@@ -0,0 +1,26 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+void baz (int *, int *);
+
+#define MEMCPY(d,s,l) __builtin___memcpy_chk (d, s, l, __builtin_object_size 
(d, 0))
+
+int
+foo ()
+{
+  int *p = new int;
+  int *q = new int[4];
+  MEMCPY (p, "abcdefghijklmnopqrstuvwxyz", sizeof (int));
+  MEMCPY (q, "abcdefghijklmnopqrstuvwxyz", 4 * sizeof (int));
+  baz (p, q);
+}
+
+int
+bar ()
+{
+  int *p = new int;
+  int *q = new int[4];
+  MEMCPY (p, "abcdefghijklmnopqrstuvwxyz", sizeof (int) + 1);  // { 
dg-warning "will always overflow destination buffer" }
+  MEMCPY (q, "abcdefghijklmnopqrstuvwxyz", 4 * sizeof (int) + 1);  // { 
dg-warning "will always overflow destination buffer" }
+  baz (p, q);
+}

Jakub


Re: [RFC PATCH] Add alloc_size attribute to the default operator new and operator new[]

2011-08-03 Thread Richard Guenther
On Wed, Aug 3, 2011 at 2:31 PM, Jakub Jelinek  wrote:
> Hi!
>
> As mentioned in PR49905, -D_FORTIFY_SOURCE{,=2} handles e.g.
> malloc (4) or malloc (16) well, knowing that the resulting pointer
> has object size 4 resp. 16, but for new int or new int[4], it currently
> doesn't assume anything (i.e. __builtin_object_size (new int, 0) returns
> -1).  While I see the C++ standard unfortunately allows redefining
> of the new and vector new operators, I wonder if for -D_FORTIFY_SOURCE
> we could assume similar properties as for malloc for the object size
> checking, i.e. that if these two operators are called with a constant
> parameter, the object size allocated is the given size.  I hope there
> aren't C++ programs that override the default operator new, allocate fewer
> or more bytes and expect that those can be accessed through the pointer
> returned by new.  At least -D_FORTIFY_SOURCE=2 is declared to be stricter
> than the standard (but -D_FORTIFY_SOURCE=1 is not).  Of course this wouldn't
> affect programs not compiled with -D_FORTIFY_SOURCE{,=2}, wouldn't affect
> placement new nor any class operator new/new[] (unless it calls the default
> operator new/new[]).
>
> Comments?

If that's reasonable then adding the malloc attribute should be, too.
Finally.  Please.  Doesn't C++0x maybe "fix" the issue we were
discussing to death?

Richard.

> 2011-08-03  Jakub Jelinek  
>
>        PR middle-end/49905
>        * decl.c (cxx_init_decl_processing): Add alloc_size (1) attribute
>        for operator new and operator new [].
>
>        * g++.dg/ext/builtin-object-size3.C: New test.
>
> --- gcc/cp/decl.c.jj    2011-07-22 22:14:59.0 +0200
> +++ gcc/cp/decl.c       2011-08-03 14:00:48.0 +0200
> @@ -3629,6 +3629,7 @@ cxx_init_decl_processing (void)
>   current_lang_name = lang_name_cplusplus;
>
>   {
> +    tree newattrs;
>     tree newtype, deltype;
>     tree ptr_ftype_sizetype;
>     tree new_eh_spec;
> @@ -3656,7 +3657,11 @@ cxx_init_decl_processing (void)
>     else
>       new_eh_spec = noexcept_false_spec;
>
> -    newtype = build_exception_variant (ptr_ftype_sizetype, new_eh_spec);
> +    newattrs
> +      = build_tree_list (get_identifier ("alloc_size"),
> +                        build_tree_list (NULL_TREE, integer_one_node));
> +    newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
> +    newtype = build_exception_variant (newtype, new_eh_spec);
>     deltype = build_exception_variant (void_ftype_ptr, empty_except_spec);
>     push_cp_library_fn (NEW_EXPR, newtype);
>     push_cp_library_fn (VEC_NEW_EXPR, newtype);
> --- gcc/testsuite/g++.dg/ext/builtin-object-size3.C.jj  2011-08-03 
> 14:06:03.0 +0200
> +++ gcc/testsuite/g++.dg/ext/builtin-object-size3.C     2011-08-03 
> 14:04:21.0 +0200
> @@ -0,0 +1,26 @@
> +// { dg-do compile }
> +// { dg-options "-O2" }
> +
> +void baz (int *, int *);
> +
> +#define MEMCPY(d,s,l) __builtin___memcpy_chk (d, s, l, __builtin_object_size 
> (d, 0))
> +
> +int
> +foo ()
> +{
> +  int *p = new int;
> +  int *q = new int[4];
> +  MEMCPY (p, "abcdefghijklmnopqrstuvwxyz", sizeof (int));
> +  MEMCPY (q, "abcdefghijklmnopqrstuvwxyz", 4 * sizeof (int));
> +  baz (p, q);
> +}
> +
> +int
> +bar ()
> +{
> +  int *p = new int;
> +  int *q = new int[4];
> +  MEMCPY (p, "abcdefghijklmnopqrstuvwxyz", sizeof (int) + 1);          // { 
> dg-warning "will always overflow destination buffer" }
> +  MEMCPY (q, "abcdefghijklmnopqrstuvwxyz", 4 * sizeof (int) + 1);      // { 
> dg-warning "will always overflow destination buffer" }
> +  baz (p, q);
> +}
>
>        Jakub
>


Fix Tru64 UNIX Ada bootstrap

2011-08-03 Thread Rainer Orth
Tru64 UNIX Ada bootstrap was broken, too:

/vol/gcc/src/hg/trunk/solaris/gcc/ada/init.c: In function 'void 
__gnat_error_handler(int, siginfo_t*, void*)':
/vol/gcc/src/hg/trunk/solaris/gcc/ada/init.c:382:50: error: cast from type 
'const char*' to type 'char*' casts away qualifiers [-Werror=cast-qual]
cc1plus: all warnings being treated as errors

Fixed as follows, bootstrap is well beyond the failure now.

Ok for mainline?

Rainer


2011-08-03  Rainer Orth  

* init.c [__alpha__ && __osf__] (__gnat_error_handler): Use
CONST_CAST2.

diff --git a/gcc/ada/init.c b/gcc/ada/init.c
--- a/gcc/ada/init.c
+++ b/gcc/ada/init.c
@@ -379,7 +379,8 @@ __gnat_error_handler (int sig, siginfo_t
 }
 
   recurse = 0;
-  Raise_From_Signal_Handler (exception, (char *) msg);
+  Raise_From_Signal_Handler (exception,
+CONST_CAST2 (char *, const char *, msg));
 }
 
 void

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


Re: [RFC PATCH] Add alloc_size attribute to the default operator new and operator new[]

2011-08-03 Thread Paolo Bonzini

On 08/03/2011 02:46 PM, Richard Guenther wrote:

If that's reasonable then adding the malloc attribute should be, too.


Making aliasing stricter for -D_FORTIFY_SOURCE=2 sounds wrong though.

Paolo



Re: [GCC-MELT-152] [MELT] Add a few tree primitives

2011-08-03 Thread Romain Geissler
Hi

2011/8/2 Basile Starynkevitch :
> On Tue, 2 Aug 2011 19:13:04 +0200
> Romain Geissler  wrote:
>> > You should build MELT in an empty build tree. Please give us the log file 
>> > of your make
>> > (don't use make -j, only a sequential make).
>>
>> Ok, i'll send you that tomorrow. Tell me if you want that i explore this 
>> issue on my configuration.
>
> Yes please. I don't understand why on my system the builds go till 
> melt-stage3 while on
> Pierre's machine it fails before melt-stage2, and we looked together (by IRC) 
> several
> hours.
>
> Cheers
>
> PS Being on vacation, I probably won't MELT much tomorrow :-)
>
>
> --
> Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
> email: basilestarynkevitchnet mobile: +33 6 8501 2359
> 8, rue de la Faiencerie, 92340 Bourg La Reine, France
> *** opinions {are only mine, sont seulement les miennes} ***
>
> --
> Message from the http://groups.google.com/group/gcc-melt group.
> About GCC MELT http://gcc-melt.org/ a high level domain specific language to 
> code extensions to the Gnu Compiler Collection
>

I've made a few changes so that Melt bootstraps. But it still fails at
the final check-melt-runtime for a simple reason: Melt won't load
modules as we don't give it the melt-workdir where all *.so reside.
I realized that all those recent changes had made the melt-modules
directory completely useless as you always look for
my-module.MD5.FLAVOR.so that are in melt-workdir, and bypass the
melt-modules symlinks. I don't really know what exact behavior you are
expecting from the melt-modules, melt-workdir and melt-tempdir
directories so i don't really know how to correct the issue.

Find attached the log for check-melt-runtime, but it might not be
useful, i already gave you the reason of the error.

Romain


Melt-0.9-build.diff
Description: Binary data


Melt-0.9-build.Changelog
Description: Binary data


melt-check-runtime.log
Description: Binary data


Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Michael Matz
Hi,

On Tue, 2 Aug 2011, Kai Tietz wrote:

> this patch improves the ability of reassociation pass to simplifiy
> more complex bitwise-binary
> operations with comparisons.  We break-up for this patch statements
> like (X | Y) != 0 to X != 0 | Y != 0,
> and (X | Y) == 0 to expanded X == 0 & Y == 0.
> Additionally we expand logical-not expressions like ~(A & B) -> ~A |
> ~B, ~(A & B) -> ~A | ~B, and
> ~(A ^ B) -> A ^ ~B.  These expansion are just temporary for this pass
> and getting later by fold
> reversed again back to their original form.

Implement all of this in the normal reassoc machinery that already exists.  
Don't implement your own walker (which btw is superlinear because you 
recurse into both operands).  If no simplifications were possible you have 
to fold back the NOTs into the shorter sequences again, which conveniently 
reassoc already can do for negates and PLUS/MINUS chains.

Hence extend the existing support for arithmetic operations to logical 
operations.


Ciao,
Michael.


Re: Fix Tru64 UNIX Ada bootstrap

2011-08-03 Thread Arnaud Charlet
> Fixed as follows, bootstrap is well beyond the failure now.
> 
> Ok for mainline?

OK, thanks.


Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Kai Tietz
2011/8/3 Michael Matz :
> Hi,
>
> On Tue, 2 Aug 2011, Kai Tietz wrote:
>
>> this patch improves the ability of reassociation pass to simplifiy
>> more complex bitwise-binary
>> operations with comparisons.  We break-up for this patch statements
>> like (X | Y) != 0 to X != 0 | Y != 0,
>> and (X | Y) == 0 to expanded X == 0 & Y == 0.
>> Additionally we expand logical-not expressions like ~(A & B) -> ~A |
>> ~B, ~(A & B) -> ~A | ~B, and
>> ~(A ^ B) -> A ^ ~B.  These expansion are just temporary for this pass
>> and getting later by fold
>> reversed again back to their original form.
>
> Implement all of this in the normal reassoc machinery that already exists.
> Don't implement your own walker (which btw is superlinear because you
> recurse into both operands).  If no simplifications were possible you have
> to fold back the NOTs into the shorter sequences again, which conveniently
> reassoc already can do for negates and PLUS/MINUS chains.
>
> Hence extend the existing support for arithmetic operations to logical
> operations.
>
>
> Ciao,
> Michael.

What you mean by existing machinery for negate expression here?  This
machinery doen't work in this case and additionally doesn't provide
the opportunity to do a complete reassociation rewrite of
bitwise-expression-chains.

Eg: the case (~(a | c) & (b & ~d))  would be expanded (by code in
patch) to ~a & ~c & b & ~d.
This intermediate result is good to inspect doubles, or inverted optimizations.
On rebuilding of tree the result gets transformed (or should) to ~(a |
c | d) & b.
This opportunity is just present because we unwinded the intial tree.
Classical folding pass isn't able to actual detect or do that on
gimpled-trees.

For comparisons it is somewhat the same, just that
bitwise-binary-chain is then for sure boolean-typed.  So as example:
(a == 1 & b != 0) & ~(a <= 1 | b == 0) would be transformed by the
code in patch to a == 1 & b != 0 & a > 1 & b != 0. So the final tree
is able to transform this into a >=1 & b != 0.  Again without
expansion and flattening of bitwise tree, we aren't able to detect and
combine that.

I thought about using the same mechanism as for negate, but it doesn't
work and has major weaknesses for bitwise-binary operations. The
negate logic is here a predicate, but the unwinding and flattening of
bitwise trees isn't a predicate.

Regards,
Kai


[build] Move unwinder to toplevel libgcc (v2)

2011-08-03 Thread Rainer Orth
This is the revised/updated version of the patch originally posted at

[build] Move unwinder to toplevel libgcc
http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01452.html

and reposted as CFT at

http://gcc.gnu.org/ml/gcc-patches/2011-07/msg00201.html

It should incorporate all review comments and a few errors I've noticed
during final review have been corrected.

I've received approval for the Darwin bits, Steve successfully tested on
HP-UX/IA64 and Linux/IA64 at least bootstrapped.  VMS/IA64 approval has
been given conditional on the approval of the other IA64 bits.  I've
also received approval for the libjava parts.

Bootstrapped without regressions (together with the next two, to be
resubmitted shortly: fp-bit and soft-fp moves) on
x86_64-unknown-linux-gnu.

i386-pc-solaris2.10, sparc-sun-solaris2.11, alpha-dec-osf5.1b,
mips-sgi-irix6.5 and i386-apple-darwin9.8.0 bootstraps in progress.
powerpc-apple-darwin9.8.0 currently broken (SIGBUS compiling
c-family/c-pretty-print.c and cp/call.c).

How should we proceed with this patch, especially given the quite
moderate comments from most affected target maintainers?

Thanks.
Rainer


2011-06-12  Rainer Orth  

gcc:
* Makefile.in (UNWIND_H): Remove.
(LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED): Move to
../libgcc/Makefile.in.
(LIBUNWIND, SHLIBUNWIND_LINK, SHLIBUNWIND_INSTALL): Likewise.
(LIBUNWINDDEP): Remove.
(libgcc-support): Remove LIB2ADDEH, $(srcdir)/emutls.c dependencies.
(libgcc.mvars): Remove LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED,
LIBUNWIND, SHLIBUNWIND_LINK, SHLIBUNWIND_INSTALL.
(stmp-int-hdrs): Remove $(UNWIND_H) dependency.
Don't copy $(UNWIND_H).
* config.gcc (ia64*-*-linux*): Remove with_system_libunwind
handling.
* configure.ac (GCC_CHECK_UNWIND_GETIPINFO): Remove.
* aclocal.m4: Regenerate.
* configure: Regenerate.
* emutls.c, unwind-c.c, unwind-compat.c, unwind-compat.h,
unwind-dw2-fde-compat.c, unwind-dw2-fde-glibc.c, unwind-dw2-fde.c,
unwind-dw2-fde.h, unwind-dw2.c, unwind-dw2.h, unwind-generic.h,
unwind-pe.h, unwind-sjlj.c, unwind.inc: Move to ../libgcc.
* unwind-dw2-fde-darwin.c: Move to ../libgcc/config.
* config/arm/libunwind.S, config/arm/pr-support.c,
config/arm/unwind-arm.c, config/arm/unwind-arm.h: Move to
../libgcc/config/arm.
* config/arm/t-bpabi (UNWIND_H, LIB2ADDEH): Remove.
* config/arm/t-symbian (UNWIND_H, LIB2ADDEH): Remove.
* config/frv/t-frv ($(T)frvbegin$(objext)): Use
$(srcdir)/../libgcc to refer to unwind-dw2-fde.h.
($(T)frvend$(objext)): Likewise.
* config/ia64/t-glibc (LIB2ADDEH): Remove.
* config/ia64/t-glibc-libunwind: Move to ../libgcc/config/ia64.
* config/ia64/fde-glibc.c, config/ia64/fde-vms.c,
config/ia64/unwind-ia64.c, config/ia64/unwind-ia64.h: Move to
../libgcc/config/ia64.
* config/ia64/t-hpux (LIB2ADDEH): Remove.
* config/ia64/t-ia64 (LIB2ADDEH): Remove.
* config/ia64/t-vms (LIB2ADDEH): Remove.
* config/ia64/vms.h (UNW_IVMS_MODE,
MD_UNW_COMPATIBLE_PERSONALITY_P): Remove.
* config/picochip/t-picochip (LIB2ADDEH): Remove.
* config/rs6000/aix.h (R_LR, MD_FROB_UPDATE_CONTEXT): Remove.
* config/rs6000/t-darwin (LIB2ADDEH): Remove.
* config/rs6000/darwin-fallback.c: Move to ../libgcc/config/rs6000.
* config/sh/t-sh ($(T)unwind-dw2-Os-4-200.o): Use
$(srcdir)/../libgcc to refer to unwinder sources.
* config/spu/t-spu-elf (LIB2ADDEH): Remove.
* config/t-darwin (LIB2ADDEH): Remove.
* config/t-freebsd (LIB2ADDEH): Remove.
* config/t-libunwind (LIB2ADDEH, LIB2ADDEHSTATIC): Remove.
* config/t-libunwind-elf: Move to ../libgcc/config.
* config/t-linux (LIB2ADDEH): Remove.
* config/t-sol2 (LIB2ADDEH): Remove.
* config/xtensa/t-xtensa (LIB2ADDEH): Remove.
* system.h (MD_FROB_UPDATE_CONTEXT): Poison.

gcc/po:
* EXCLUDES (unwind-c.c, unwind-dw2-fde-darwin.c)
(unwind-dw2-fde-glibc.c, unwind-dw2-fde.c, unwind-dw2-fde.h)
(unwind-dw2.c, unwind-pe.h, unwind-sjlj.c, unwind.h): Remove.

libgcc:
* Makefile.in (LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED): New
variables.
(LIBUNWIND, SHLIBUNWIND_LINK, SHLIBUNWIND_INSTALL): New variables.
(LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED): Add $(srcdir)/emutls.c.
(install-unwind_h): New target.
(all): Depend on it.
* config.host (unwind_header): New variable.
(*-*-freebsd*): Set tmake_file to t-eh-dw2-dip.
(*-*-linux*, frv-*-*linux*, *-*-kfreebsd*-gnu, *-*-knetbsd*-gnu,
*-*-gnu*): Likewise, also for *-*-kopensolaris*-gnu.
(*-*-solaris2*): Add t-eh-dw2-dip to tmake_file.
(arm*-*-linux*): Add arm/t-bpabi 

[PATCH][RFC] Fix PR49957 - build array index differently

2011-08-03 Thread Richard Guenther

This fixes PR49957 by keeping the array index into a multi-dimensional
array in optimal associated form which is ((off + outermost) + ...) + 
innermost) + constant) so that dependence analysis can properly
handle it.  It doesn't work right now because we build the
expression in reverse order, fold thinks it can do some fancy and
the expression is of signed type and thus we know it doesn't overflow
but we also won't re-associate it to a more optimal form.

I tried reversing the loop in gfc_conv_array_ref but that doesn't
work (for example aliasing_dummy_4.f90 ICEs), thus the funny way
of chaining the pluses.

I also don't know if there is maybe another place we build similar
expressions that should be adjusted, too - this one is where
we build the expression for the testcase I looked at.

The patch doesn't make 410.bwaves measurably faster, but at least
it also doesn't get slower.

Bootstrap and regtest is currently running on x86_64-unknown-linux-gnu,
the reversed loop one was ok (well, apart from those 2-3 fails).

Comments?  Any idea why reversing the loop would break?
The ICE I got is

/space/rguenther/src/svn/trunk/gcc/testsuite/gfortran.dg/aliasing_dummy_4.f90: 
In function 'test_f90':
/space/rguenther/src/svn/trunk/gcc/testsuite/gfortran.dg/aliasing_dummy_4.f90:21:0:
 
internal compiler error: in gfc_conv_constant, at 
fortran/trans-const.c:387
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

Thanks,
Richard.

2011-08-03  Richard Guenther  

PR fortran/49957
* trans-array.c (gfc_conv_array_ref): Build the array index
expression in optimally associated order.

* gfortran.dg/vect/O3-pr49957.f: New testcase.

Index: gcc/fortran/trans-array.c
===
--- gcc/fortran/trans-array.c   (revision 177094)
+++ gcc/fortran/trans-array.c   (working copy)
@@ -2634,7 +2634,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
locus * where)
 {
   int n;
-  tree index;
+  tree index, offset, *indexp;
   tree tmp;
   tree stride;
   gfc_se indexse;
@@ -2669,9 +2669,16 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
   return;
 }
 
-  index = gfc_index_zero_node;
+  offset = gfc_conv_array_offset (se->expr);
+  if (TREE_CODE (offset) != INTEGER_CST)
+index = offset;
+  else
+index = gfc_index_zero_node;
 
-  /* Calculate the offsets from all the dimensions.  */
+  indexp = &index;
+
+  /* Calculate the offsets from all the dimensions.  Make sure to associate
+ the final offset so that we form a chain of loop invariant summands.  */
   for (n = 0; n < ar->dimen; n++)
 {
   /* Calculate the index for this dimension.  */
@@ -2740,15 +2747,38 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
   tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
 indexse.expr, stride);
 
-  /* And add it to the total.  */
-  index = fold_build2_loc (input_location, PLUS_EXPR,
-  gfc_array_index_type, index, tmp);
+  /* And add it to the total.  Avoid folding as that re-associates
+ in a non-optimal way.  We want to have constant offsets as
+the outermost addition and the rest of the additions in order
+of the loop depth.  */
+  if (!integer_zerop (index))
+   {
+ if (TREE_CODE (tmp) == INTEGER_CST)
+   {
+ bool reset = indexp == &index;
+ index = fold_build2_loc (input_location, PLUS_EXPR,
+  gfc_array_index_type, index, tmp);
+ if (reset)
+   indexp = &index;
+   }
+ else
+   {
+ *indexp
+   = build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, *indexp, tmp);
+ indexp = &TREE_OPERAND (*indexp, 0);
+   }
+   }
+  else
+   {
+ index = tmp;
+ indexp = &index;
+   }
 }
 
-  tmp = gfc_conv_array_offset (se->expr);
-  if (!integer_zerop (tmp))
+  if (TREE_CODE (offset) == INTEGER_CST)
 index = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, index, tmp);
+gfc_array_index_type, index, offset);
 
   /* Access the calculated element.  */
   tmp = gfc_conv_array_data (se->expr);
Index: gcc/testsuite/gfortran.dg/vect/O3-pr49957.f
===
--- gcc/testsuite/gfortran.dg/vect/O3-pr49957.f (revision 0)
+++ gcc/testsuite/gfortran.dg/vect/O3-pr49957.f (revision 0)
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! { dg-require-effective-target vect_double }
+  subroutine shell(nx,ny,nz)
+  implicit none
+  integer i,j,k,l,nx,ny,nz
+  real*8 q(5,nx,ny),dq(5,nx,ny)
+ do j=1,ny
+do i=1,nx
+   do l=1,5
+  q(l,i,j

Re: Fix Solaris Ada bootstrap

2011-08-03 Thread Arnaud Charlet
> Ok for mainline?
> 
> Thanks.
>   Rainer
> 
> 
> 2011-08-03  Rainer Orth  
> 
>   * link.c: Include "auto-host.h" before system headers.

OK, thanks.


Re: [RFC PATCH] Add alloc_size attribute to the default operator new and operator new[]

2011-08-03 Thread Richard Guenther
On Wed, Aug 3, 2011 at 3:06 PM, Paolo Bonzini  wrote:
> On 08/03/2011 02:46 PM, Richard Guenther wrote:
>>
>> If that's reasonable then adding the malloc attribute should be, too.
>
> Making aliasing stricter for -D_FORTIFY_SOURCE=2 sounds wrong though.

The patch unconditionally adds malloc_size.

Richard.


Re: [RFC PATCH] Add alloc_size attribute to the default operator new and operator new[]

2011-08-03 Thread Jakub Jelinek
On Wed, Aug 03, 2011 at 03:55:39PM +0200, Richard Guenther wrote:
> On Wed, Aug 3, 2011 at 3:06 PM, Paolo Bonzini  wrote:
> > On 08/03/2011 02:46 PM, Richard Guenther wrote:
> >>
> >> If that's reasonable then adding the malloc attribute should be, too.
> >
> > Making aliasing stricter for -D_FORTIFY_SOURCE=2 sounds wrong though.
> 
> The patch unconditionally adds malloc_size.

alloc_size, yeah, unconditionally, on the other side it is used just
by __builtin_object_size which is used (usually) only for
-D_FORTIFY_SOURCE*.

I wanted to separate alloc_size attribute issue from malloc (where I'd
surely prefer also adding it by default and having an option to disable it
for weird C++ sources), because with -D_FORTIFY_SOURCE* or
__builtin_object_size one has to request it specially and/or use extensions
and thus not be that tighly bound by the standard.

Jakub


Re: [RFC] Cleanup DW_CFA_GNU_args_size handling

2011-08-03 Thread Ulrich Weigand
Richard Henderson wrote:

> emit_stack_restore (SAVE_BLOCK, old_stack_level);
> stack_pointer_delta = old_stack_pointer_delta;
> +
> +   /* ??? Is this assert warrented, given emit_stack_restore?
> +  or should we just mark the last insn no matter what?  */
> +   last = get_last_insn ();
> +   set = single_set (last);
> +   gcc_assert (set != NULL);
> +   gcc_assert (SET_DEST (set) == stack_pointer_rtx);

This assert triggers on spu-elf, because our restore_stack_block
pattern emits something else as its last instruction: we restore
a stack backchain link after restoring the stack pointer.

Even if we were to swap the order to restore the backchain first,
like rs6000 does, the assert would still trigger, since we cannot
use stack_pointer_rtx to restore the stack pointer; this is because
on SPU, the stack pointer is a vector register, and the ABI says to
maintain the remaining free stack space in a high slot of that
vector.  Therefore, restore_stack_block uses a vector add into
a register generated via gen_rtx_REG (V4SImode, STACK_POINTER_REGNUM)
instead of just plain stack_pointer_rtx ...

Was this assert intended to impose requirements on target's
restore_stack_block implemtations?  What exactly are those
supposed to be?

Bye,
Ulrich

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


Re: [RFC] Cleanup DW_CFA_GNU_args_size handling

2011-08-03 Thread Georg-Johann Lay
Georg-Johann Lay wrote:
> Richard Henderson wrote:
>> On 08/01/2011 11:42 AM, Georg-Johann Lay wrote:
>>> Is there a specific reason not to define
>>> ACCUMULATE_OUTGOING_ARGS on AVR?
>> Yes.  So that you can use PUSH.  But as I said in PR49881,
>> you probably want to provide -maccumulate-outgoing-args.
>>
>> I have a follow-up patch to the last one in that PR...
>>
>>
>> r~
> 
> PUSH is fine but what about POP?
> 
> It's very expensive to pop several bytes, i.e. disabling IRQs, loading and 
> storing SP and the like.
> Usung store+displacement has not this drawback and as I wrote, come code 
> degradations you explained
> in PR49881 are artifacts of PR46278, i.e. fake X addressing.
> 
> Johann
> 

Tried this test case:

#include 

void foo ()
{
printf ("%d %d %d", 1, 2, 3);
printf ("%d %d %d", 3, 4, 5);
printf ("%d %d %d", 1, 4, 5);
}

Attached the output: The compiler happily pushes onto the stack
but pops only at the end of the function. So in a function with
many such calls that would eat up great deal of RAM. It that
what we want?

RETURN_POPS_ARGS cannot help here.

Johann





    .file   "printf.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
 ;  GNU C (GCC) version 4.7.0 20110803 (experimental) (avr)
 ;  compiled by GNU C version 4.3.2 [gcc-4_3-branch revision 141291], GMP 
version 5.0.1, MPFR version 3.0.0-p8, MPC version 0.8.2
 ;  GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 ;  options passed:  printf.c -Os -fverbose-asm
 ;  options enabled:  -fauto-inc-dec -fbranch-count-reg -fcaller-saves
 ;  -fcombine-stack-adjustments -fcommon -fcompare-elim -fcprop-registers
 ;  -fcrossjumping -fcse-follow-jumps -fdebug-types-section -fdefer-pop
 ;  -fdevirtualize -fearly-inlining -feliminate-unused-debug-types
 ;  -fexpensive-optimizations -fforward-propagate -ffunction-cse -fgcse
 ;  -fgcse-lm -fguess-branch-probability -fident -fif-conversion
 ;  -fif-conversion2 -findirect-inlining -finline -finline-functions
 ;  -finline-functions-called-once -finline-small-functions -fipa-cp
 ;  -fipa-profile -fipa-pure-const -fipa-reference -fipa-sra
 ;  -fira-share-save-slots -fira-share-spill-slots -fivopts
 ;  -fkeep-static-consts -fleading-underscore -fmath-errno
 ;  -fmerge-constants -fmerge-debug-strings -fmove-loop-invariants
 ;  -fomit-frame-pointer -foptimize-register-move -foptimize-sibling-calls
 ;  -fpartial-inlining -fpeephole -fpeephole2 -fprefetch-loop-arrays
 ;  -freg-struct-return -fregmove -freorder-blocks -freorder-functions
 ;  -frerun-cse-after-loop -fsched-critical-path-heuristic
 ;  -fsched-dep-count-heuristic -fsched-group-heuristic -fsched-interblock
 ;  -fsched-last-insn-heuristic -fsched-rank-heuristic -fsched-spec
 ;  -fsched-spec-insn-heuristic -fsched-stalled-insns-dep -fshow-column
 ;  -fsigned-zeros -fsplit-ivs-in-unroller -fsplit-wide-types
 ;  -fstrict-aliasing -fstrict-overflow -fstrict-volatile-bitfields
 ;  -fthread-jumps -ftoplevel-reorder -ftrapping-math -ftree-bit-ccp
 ;  -ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copy-prop
 ;  -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse
 ;  -ftree-forwprop -ftree-fre -ftree-loop-if-convert -ftree-loop-im
 ;  -ftree-loop-ivcanon -ftree-loop-optimize -ftree-parallelize-loops=
 ;  -ftree-phiprop -ftree-pre -ftree-pta -ftree-reassoc -ftree-scev-cprop
 ;  -ftree-sink -ftree-slp-vectorize -ftree-sra -ftree-switch-conversion
 ;  -ftree-ter -ftree-vect-loop-version -ftree-vrp -funit-at-a-time
 ;  -fverbose-asm -fzero-initialized-in-bss

.section.rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d %d %d"
.text
.global foo
.type   foo, @function
foo:
push r14 ;   ;  66  pushqi1/1   [length = 1]
push r15 ;   ;  67  pushqi1/1   [length = 1]
push r16 ;   ;  68  pushqi1/1   [length = 1]
push r17 ;   ;  69  pushqi1/1   [length = 1]
push r28 ;   ;  70  pushqi1/1   [length = 1]
push r29 ;   ;  71  pushqi1/1   [length = 1]
/* prologue: function */
/* frame size = 0 */
/* stack size = 6 */
.L__stack_usage = 6
push __zero_reg__;  5   pushqi1/2   [length = 1]
ldi r24,lo8(3)   ; , ;  82  *reload_inqi[length = 2]
mov r14,r24  ;  tmp42,
push r14 ;  tmp42;  7   pushqi1/1   [length = 1]
push __zero_reg__;  8   pushqi1/2   [length = 1]
ldi r24,lo8(2)   ;  tmp43,   ;  9   *movqi/2[length = 1]
push r24 ;  tmp43;  10  pushqi1/1   [length = 1]
push __zero_reg__;  11  pushqi1/2   [length = 1]
ldi r17,lo8(1)   ;  tmp44,   ;  12  *movqi/2[l

PATCH PR target/47744: [x32] ICE: in reload_cse_simplify_operands, at postreload.c:403

2011-08-03 Thread H.J. Lu
Hi,

I checked in the following testcases for PR target/47744.


H.J.
---
Index: gcc.dg/torture/pr47744-2.c
===
--- gcc.dg/torture/pr47744-2.c  (revision 0)
+++ gcc.dg/torture/pr47744-2.c  (revision 0)
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-std=gnu99" } */
+
+typedef long unsigned int size_t;
+typedef long int ssize_t;
+typedef ssize_t index_type;
+typedef __int128_t GFC_INTEGER_16;
+typedef struct descriptor_dimension
+{
+  index_type _stride;
+  index_type _lbound;
+  index_type _ubound;
+}
+descriptor_dimension;
+typedef struct { GFC_INTEGER_16 *data; size_t offset; index_type dtype; 
descriptor_dimension dim[7];} gfc_array_i16;
+void
+matmul_i16 (gfc_array_i16 * const restrict retarray,
+   gfc_array_i16 * const restrict a,
+   GFC_INTEGER_16 bbase_yn)
+{
+  GFC_INTEGER_16 * restrict dest;
+  index_type rxstride, rystride;
+  index_type x, y, n, count, xcount;
+  GFC_INTEGER_16 * restrict dest_y;
+  GFC_INTEGER_16 s;
+  const GFC_INTEGER_16 * restrict abase_n;
+  rxstride = ((retarray)->dim[0]._stride);
+  rystride = ((retarray)->dim[1]._stride);
+  xcount = ((a)->dim[0]._ubound + 1 - (a)->dim[0]._lbound);
+  dest = retarray->data;
+  dest_y = &dest[y*rystride];
+  for (x = 0; x < xcount; x++)
+dest_y[x] += abase_n[x] * bbase_yn;
+  for (x = 0; x < xcount; x++)
+{
+  for (n = 0; n < count; n++)
+   dest_y[x*rxstride] = (GFC_INTEGER_16) 0;
+}
+}
Index: gcc.dg/torture/pr47744-3.c
===
--- gcc.dg/torture/pr47744-3.c  (revision 0)
+++ gcc.dg/torture/pr47744-3.c  (revision 0)
@@ -0,0 +1,74 @@
+/* { dg-do compile } */
+
+typedef union rtunion_def {
+  struct rtx_def *rtx;
+} rtunion;
+typedef struct rtx_def {
+  unsigned short code;
+  rtunion fld[1];
+} *rtx;
+extern rtx recog_operand[];
+extern rtx *recog_operand_loc[];
+extern int reload_n_operands;
+extern void find_dummy_reload (int, int);
+extern int asm_noperands (rtx);
+extern int n_occurrences (char **);
+char operands_match[10][10];
+void find_reloads (rtx insn, int n_alternatives, int commutative)
+{
+  register int i, j;
+  int noperands;
+  char *constraints[10];
+  int address_reloaded[10];
+  int this_alternative[10];
+  char this_alternative_win[10];
+  int this_alternative_matches[10];
+  int this_alternative_number;
+  rtx body = ((insn)->fld[3].rtx);
+  int operand_mode[10];
+  if (body->code == 1)
+{
+  reload_n_operands = noperands = asm_noperands (body);
+  n_alternatives = n_occurrences (constraints);
+}
+  for (this_alternative_number = 0;
+   this_alternative_number < n_alternatives;
+   this_alternative_number++)
+for (i = 0;
+i < noperands;
+i++)
+  {
+   register char *p = constraints[i];
+   register int win = 0;
+   int badop = 1;
+   int c;
+   register rtx operand = recog_operand[i];
+   int force_reload = 0;
+   this_alternative_win[i] = 0;
+   this_alternative[i] = 1;
+   while (*p && (c = *p++) != ',')
+ switch (c)
+   {
+   case '4':
+ c -= '0';
+ this_alternative_matches[i] = c;
+ if ((c != commutative
+  || i != commutative + 1)
+ && operands_match[c][i])
+   win = this_alternative_win[c];
+ else
+   find_dummy_reload (operand_mode[i], this_alternative[c]);
+ if (! win || force_reload)
+   for (j = 0; j < i; j++)
+ if (this_alternative_matches[j]
+ == this_alternative_matches[i])
+   badop = 1;
+ break;
+   case '<':
+ if (operand->code == 2
+ && ! address_reloaded[i]
+ && operand->fld[0].rtx->code == 3)
+   win = 1;
+   }
+  }
+}
Index: gcc.dg/torture/pr47744-1.c
===
--- gcc.dg/torture/pr47744-1.c  (revision 0)
+++ gcc.dg/torture/pr47744-1.c  (revision 0)
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-fpic" { target fpic } } */
+
+typedef int int32_t;
+static const int init_jk[] = {2,3,4,6};
+ int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const 
int32_t *ipio2)
+{
+ int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
+ double z,fw,f[20],fq[20],q[20];
+ jk = init_jk[prec];
+ jp = jk;
+ jx = nx-1;
+ for (i=0;i<=jk;i++) {
+ for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
+ }
+ for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
+ z = q[j-1]+fw;
+ }
+ n = (int32_t) z;
+ return n&7;
+}
Index: ChangeLog
===
--- ChangeLog   (revision 177270)
+++ ChangeLog   (working copy)
@@ -1,3 +1,10 @@
+2011-08-03  H.J. Lu  
+
+   PR target/47744
+   * gcc.dg/torture/pr4

Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Richard Guenther
On Wed, Aug 3, 2011 at 3:32 PM, Kai Tietz  wrote:
> 2011/8/3 Michael Matz :
>> Hi,
>>
>> On Tue, 2 Aug 2011, Kai Tietz wrote:
>>
>>> this patch improves the ability of reassociation pass to simplifiy
>>> more complex bitwise-binary
>>> operations with comparisons.  We break-up for this patch statements
>>> like (X | Y) != 0 to X != 0 | Y != 0,
>>> and (X | Y) == 0 to expanded X == 0 & Y == 0.
>>> Additionally we expand logical-not expressions like ~(A & B) -> ~A |
>>> ~B, ~(A & B) -> ~A | ~B, and
>>> ~(A ^ B) -> A ^ ~B.  These expansion are just temporary for this pass
>>> and getting later by fold
>>> reversed again back to their original form.
>>
>> Implement all of this in the normal reassoc machinery that already exists.
>> Don't implement your own walker (which btw is superlinear because you
>> recurse into both operands).  If no simplifications were possible you have
>> to fold back the NOTs into the shorter sequences again, which conveniently
>> reassoc already can do for negates and PLUS/MINUS chains.
>>
>> Hence extend the existing support for arithmetic operations to logical
>> operations.
>>
>>
>> Ciao,
>> Michael.
>
> What you mean by existing machinery for negate expression here?  This
> machinery doen't work in this case and additionally doesn't provide
> the opportunity to do a complete reassociation rewrite of
> bitwise-expression-chains.
>
> Eg: the case (~(a | c) & (b & ~d))  would be expanded (by code in
> patch) to ~a & ~c & b & ~d.
> This intermediate result is good to inspect doubles, or inverted 
> optimizations.
> On rebuilding of tree the result gets transformed (or should) to ~(a |
> c | d) & b.

It depends on the context whether a conjunctive or a disjunctive normal
form is what you want.  As you are mixing two operation kinds reassoc
isn't the perfect place to deal with this (yet).

You don't seem to stop when single-use chains end (which is where
reassoc will give up) and even visit stmts multiple times that way.
You need to at least do this "unfolding" in a lot more controlled manner.

Richard.

> This opportunity is just present because we unwinded the intial tree.
> Classical folding pass isn't able to actual detect or do that on
> gimpled-trees.
>
> For comparisons it is somewhat the same, just that
> bitwise-binary-chain is then for sure boolean-typed.  So as example:
> (a == 1 & b != 0) & ~(a <= 1 | b == 0) would be transformed by the
> code in patch to a == 1 & b != 0 & a > 1 & b != 0. So the final tree
> is able to transform this into a >=1 & b != 0.  Again without
> expansion and flattening of bitwise tree, we aren't able to detect and
> combine that.
>
> I thought about using the same mechanism as for negate, but it doesn't
> work and has major weaknesses for bitwise-binary operations. The
> negate logic is here a predicate, but the unwinding and flattening of
> bitwise trees isn't a predicate.
>
> Regards,
> Kai
>


Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Michael Matz
Hi,

On Wed, 3 Aug 2011, Kai Tietz wrote:

> > Implement all of this in the normal reassoc machinery that already 
> > exists. Don't implement your own walker (which btw is superlinear 
> > because you recurse into both operands).  If no simplifications were 
> > possible you have to fold back the NOTs into the shorter sequences 
> > again, which conveniently reassoc already can do for negates and 
> > PLUS/MINUS chains.
> >
> > Hence extend the existing support for arithmetic operations to logical 
> > operations.
> 
> What you mean by existing machinery for negate expression here?

tree-reassoc can handle chains of NEGATE/PLUS/MINUS/MULT/DIV expressions, 
including undistribution (A*X + B*X -> (A+B)*X).  It does have some 
deficiencies with mixed chains (e.g. mixture of PLUS and MULT 
expressions).

Now, in the usual mathematical parlance we have these correspondences:
  NOT == NEGATE
  AND == MULT
  IOR == PLUS
hence, if you extend the existing reassoc machinery to first deal nicely 
with mixed chains and then handle NOT/AND/IOR like their arithmetic 
counterparts you will have improved reassoc for arithmetic operations 
_and_ extended it to also handle logical operation chains.  Without 
hacking a completely different way of walking and collection operands for 
logicals in parallel to the one for arithmetics.

> This machinery doen't work in this case

That's why you have to extend it.

> Eg: the case (~(a | c) & (b & ~d))  would be expanded (by code in
> patch) to ~a & ~c & b & ~d.

That's what I mean with better handling of mixed chains.  -(a+b) is 
already (sometimes) rewritten into -a + -b (see negate_value).  That's 
just slightly different from rewriting ~(a|b) into ~a & ~b.

> This intermediate result is good to inspect doubles, or inverted 
> optimizations. On rebuilding of tree the result gets transformed (or 
> should) to ~(a | c | d) & b.

And that would be done by undistribute_ops_list, if it were properly 
extended.

> This opportunity is just present because we unwinded the intial tree.
> Classical folding pass isn't able to actual detect or do that on
> gimpled-trees.

That's why you do this whole excercise in tree-reassoc, where it indeed 
belongs.  My point is that you should extend the existing means to support 
your operations, instead of implementing a similar-but-different approach 
in parallel.

> I thought about using the same mechanism as for negate, but it doesn't 
> work and has major weaknesses for bitwise-binary operations. The negate 
> logic is here a predicate, but the unwinding and flattening of bitwise 
> trees isn't a predicate.

What you descrive as "flattening" is actually building a normal form.  
reassoc uses a vector of operand extries to hold such normal form (as 
said, not yet dealing with mixed chains).  linearize_expr_tree does the 
flattening, and you would have to extend it (and its associated helper 
routines) to handle mixed chains and then you logical operations.

Once a linearized array of operands (possibly of level two to handle mixed 
chains) exists undistribute_ops_list and optimize_ops_list will optimize 
those operands again, and rewrite_expr_tree will produce statements 
implementing the so optimized operand list.  You will have to extend that 
too for your logical operations (and possibly compares).


Ciao,
Michael.

Re: [RFC] Cleanup DW_CFA_GNU_args_size handling

2011-08-03 Thread H.J. Lu
On Tue, Aug 2, 2011 at 3:32 PM, Richard Henderson  wrote:
> I got Jeff Law to review the reload change on IRC
> and committed the composite patch.
>
> Tested on x86_64, i586, avr, and h8300.  Most other
> tier1 targets ought not be affected, as this patch
> only applies to ACCUMULATE_OUTGOING_ARGS == 0 targets.
>

It may have caused:

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


-- 
H.J.


Re: CFT: [build] Move fp-bit support to toplevel libgcc

2011-08-03 Thread Joseph S. Myers
On Wed, 3 Aug 2011, Rainer Orth wrote:

> * Even worse, there are a couple of formats/targets that do use
>   fp-bit.c, don't yet define QUIET_NAN_NEGATED, but have qnan_msb_set =
>   false: 
> 
>   qnan_msb_setuses fp-bit
> 
>   mips_single_format  false   x
>   spu_single_format   false   x
>   mips_double_format  false   x
>   mips_extended_formatfalse   x
>   mips_quad_formatfalse   x
>   vax_f_formatfalse   00
>   vax_d_formatfalse   00
>   vax_g_formatfalse   00
>   arm_half_format false   ?
> 
>   So such a change would mean a change of behavior for spu and arm
>   targets.

The SPU format doesn't support NaNs, so the value of this field isn't 
particularly meaningful for SPU.  I'm not clear why SPU is actually using 
fp-bit; what functions from fp-bit will actually end up getting used by 
code built for SPU, and how close does fp-bit get to the required 
semantics?

arm_half_format is another no-NaN format, and fp-bit does not provide any 
operations for it (it's a storage format only, not an arithmetic format, 
and conversions are provided by config/arm/fp16.c).  So there should be no 
behavior change for ARM at all (only the definitions for the modes used by 
fp-bit are relevant, and HFmode isn't one of those).

But, yes, any change to avoid defining QUIET_NAN_NEGATED specially would 
best be kept separate.

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


[Ada] Support for controlled objects allocated on the heap for .NET/JVM

2011-08-03 Thread Arnaud Charlet
The following patch adds partial support for controlled objects allocated on
the heap for .NET/JVM compilation environments.

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

2011-08-03  Hristian Kirtchev  

* exp_ch13.adb: Add with and use clause for Targparm;
(Expand_N_Free_Statement): Prevent the generation of a custom
Deallocate on .NET/JVM targets since this requires pools and address
arithmetic.
* exp_ch4.adb (Expand_Allocator_Expression): When compiling for
.NET/JVM targets, attach the newly allocated object to the access
type's finalization collection. Do not generate a call to
Set_Finalize_Address_Ptr on .NET/JVM because this routine does not
exist in the runtime.
(Expand_N_Allocator): When compiling for .NET/JVM targets, do not
create a custom Allocate for object that do not require initialization.
Attach a newly allocated object to the access type's finalization
collection on .NET/JVM.
* exp_ch5.adb (Make_Tag_Ctrl_Assignment): Add special processing for
assignment of controlled types on .NET/JVM. The two hidden pointers
Prev and Next and stored and later restored after the assignment takes
place.
* exp_ch6.adb (Expand_Call): Add local constant Curr_S. Add specialized
kludge for .NET/JVM to recognize a particular piece of code coming from
Heap_Management and change the call to Finalize into Deep_Finalize.
* exp_ch7.adb (Build_Finalization_Collection): Allow the creation of
finalization collections on .NET/JVM only for types derived from
Controlled. Separate the association of storage pools with a collection
and only allow it on non-.NET/JVM targets.
(Make_Attach_Call): New routine.
(Make_Detach_Call): New routine.
(Process_Object_Declarations): Suppress the generation of
build-in-place return object clean up code on .NET/JVM since it uses
pools.
* exp_ch7.ads (Make_Attach_Call): New routine.
(Make_Detach_Call): New routine.
* exp_intr.adb Add with and use clause for Targparm.
(Expand_Unc_Deallocation): Detach a controlled object from a collection
on .NET/JVM targets.
* rtsfind.ads: Add entries RE_Attach, RE_Detach and
RE_Root_Controlled_Ptr to tables RE_Id and RE_Unit_Table.
* snames.ads-tmpl: Add name Name_Prev. Move Name_Prev to the special
names used in finalization.

Index: exp_ch5.adb
===
--- exp_ch5.adb (revision 177275)
+++ exp_ch5.adb (working copy)
@@ -3496,7 +3496,9 @@
   --  Tags are not saved and restored when VM_Target because VM tags are
   --  represented implicitly in objects.
 
-  Tag_Tmp : Entity_Id;
+  Next_Id : Entity_Id;
+  Prev_Id : Entity_Id;
+  Tag_Id  : Entity_Id;
 
begin
   --  Finalize the target of the assignment when controlled
@@ -3535,14 +3537,14 @@
  Typ => Etype (L)));
   end if;
 
-  --  Save the Tag in a local variable Tag_Tmp
+  --  Save the Tag in a local variable Tag_Id
 
   if Save_Tag then
- Tag_Tmp := Make_Temporary (Loc, 'A');
+ Tag_Id := Make_Temporary (Loc, 'A');
 
  Append_To (Res,
Make_Object_Declaration (Loc,
- Defining_Identifier => Tag_Tmp,
+ Defining_Identifier => Tag_Id,
  Object_Definition =>
New_Reference_To (RTE (RE_Tag), Loc),
  Expression =>
@@ -3552,12 +3554,54 @@
  Selector_Name =>
New_Reference_To (First_Tag_Component (T), Loc;
 
-  --  Otherwise Tag_Tmp not used
+  --  Otherwise Tag_Id is not used
 
   else
- Tag_Tmp := Empty;
+ Tag_Id := Empty;
   end if;
 
+  --  Save the Prev and Next fields on .NET/JVM. This is not needed on non
+  --  VM targets since the fields are not part of the object.
+
+  if VM_Target /= No_VM
+and then Is_Controlled (T)
+  then
+ Prev_Id := Make_Temporary (Loc, 'P');
+ Next_Id := Make_Temporary (Loc, 'N');
+
+ --  Generate:
+ --Pnn : Root_Controlled_Ptr := Root_Controlled (L).Prev;
+
+ Append_To (Res,
+   Make_Object_Declaration (Loc,
+ Defining_Identifier => Prev_Id,
+ Object_Definition =>
+   New_Reference_To (RTE (RE_Root_Controlled_Ptr), Loc),
+ Expression =>
+   Make_Selected_Component (Loc,
+ Prefix =>
+   Unchecked_Convert_To
+ (RTE (RE_Root_Controlled), New_Copy_Tree (L)),
+ Selector_Name =>
+   Make_Identifier (Loc, Name_Prev;
+
+ --  Generate:
+ --Nnn : Root_Controlled_Ptr := Root_Controlled (L).Next;
+
+ Append_To (Res,
+   Make_Object_Declaration (

PATCH: Add a testase for PR middle-end/47383

2011-08-03 Thread H.J. Lu
Hi,

I checked in this patch to add a testase for PR middle-end/47383.

H.J.
---
Index: gcc.dg/torture/pr47383.c
===
--- gcc.dg/torture/pr47383.c(revision 0)
+++ gcc.dg/torture/pr47383.c(revision 0)
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+
+static int heap[2*(256 +1+29)+1];
+static int heap_len;
+static int heap_max;
+void 
+__attribute__ ((noinline))
+foo (int elems)
+{
+  int n, m;
+  int max_code = -1;
+  int node = elems;
+  heap_len = 0, heap_max = (2*(256 +1+29)+1);
+  for (n = 0; n < elems; n++)
+heap[++heap_len] = max_code = n;
+  do {
+n = heap[1];
+heap[1] = heap[heap_len--];
+m = heap[1];
+heap[--heap_max] = n;
+heap[--heap_max] = m;
+  } while (heap_len >= 2);
+}
+
+int
+main ()
+{
+  foo (286);
+  return 0;
+}
Index: ChangeLog
===
--- ChangeLog   (revision 177275)
+++ ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2011-08-03  H.J. Lu  
+
+   PR middle-end/47383
+   * gcc.dg/torture/pr47383.c: Likewise.
+
 2011-08-03  Arnaud Charlet  
 
* gnat.dg/specs/debug1.ads: Add missing -margs switch.


[Ada] Tag-indeterminate calls

2011-08-03 Thread Arnaud Charlet
A function call is tag-indeterminate if the function dispatches on result and
if the return type is tagged. This depends on the current view of the type.
Previously the predicate only checked on whether the function was known to
dispatch on result.

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

2011-08-03  Ed Schonberg  

* sem_disp.adb (Is_Tag_Indeterminate): If the return type of the
function is not visibly tagged, this is not a dispatching call and
therfore is not Tag_Indeterminate, even if the function is marked as
dispatching on result.

Index: sem_disp.adb
===
--- sem_disp.adb(revision 177275)
+++ sem_disp.adb(working copy)
@@ -1500,17 +1500,16 @@
  if Present (Tagged_Type) and then Is_Tagged_Type (Tagged_Type) then
 Append_Unique_Elmt (Old_Subp, Primitive_Operations (Tagged_Type));
 
---  If Old_Subp isn't already marked as dispatching then
---  this is the case of an operation of an untagged private
---  type fulfilled by a tagged type that overrides an
---  inherited dispatching operation, so we set the necessary
---  dispatching attributes here.
+--  If Old_Subp isn't already marked as dispatching then this is
+--  the case of an operation of an untagged private type fulfilled
+--  by a tagged type that overrides an inherited dispatching
+--  operation, so we set the necessary dispatching attributes here.
 
 if not Is_Dispatching_Operation (Old_Subp) then
 
--  If the untagged type has no discriminants, and the full
-   --  view is constrained, there will be a spurious mismatch
-   --  of subtypes on the controlling arguments, because the tagged
+   --  view is constrained, there will be a spurious mismatch of
+   --  subtypes on the controlling arguments, because the tagged
--  type is the internal base type introduced in the derivation.
--  Use the original type to verify conformance, rather than the
--  base type.
@@ -1758,9 +1757,9 @@
 
 begin
--  The original corresponding operation of Prim must be an
-   --  operation of a visible ancestor of the dispatching type
-   --  S, and the original corresponding operation of S2 must
-   --  be visible.
+   --  operation of a visible ancestor of the dispatching type S,
+   --  and the original corresponding operation of S2 must be
+   --  visible.
 
Orig_Prim := Original_Corresponding_Operation (Prim);
 
@@ -2026,6 +2025,14 @@
  if not Has_Controlling_Result (Nam) then
 return False;
 
+ --  The function may have a controlling result, but if the return type
+ --  is not visibly tagged, then this is not tag-indeterminate.
+
+ elsif Is_Access_Type (Etype (Nam))
+   and then not Is_Tagged_Type (Designated_Type (Etype (Nam)))
+ then
+return False;
+
  --  An explicit dereference means that the call has already been
  --  expanded and there is no tag to propagate.
 
@@ -2043,7 +2050,9 @@
if Is_Controlling_Actual (Actual)
  and then not Is_Tag_Indeterminate (Actual)
then
-  return False; -- one operand is dispatching
+  --  One operand is dispatching
+
+  return False;
end if;
 
Next_Actual (Actual);
@@ -2066,9 +2075,9 @@
   then
  return True;
 
-  --  In Ada 2005 a function that returns an anonymous access type can
-  --  dispatching, and the dereference of a call to such a function
-  --  is also tag-indeterminate.
+  --  In Ada 2005, a function that returns an anonymous access type can be
+  --  dispatching, and the dereference of a call to such a function can
+  --  also be tag-indeterminate if the call itself is.
 
   elsif Nkind (Orig_Node) = N_Explicit_Dereference
 and then Ada_Version >= Ada_2005


[Ada] Make GNAT.AWK API compatible with Ada 2005.

2011-08-03 Thread Arnaud Charlet
Ada 2005 does not allow returning limited objects from a function. As this
interface should be callable from Ada 95 and Ada 2005 we have changed
the API to return access type instead.

This minor upward compatibility issue is very easy to fix. A ".all" needs
to be added to calls to routines Current_Session and Default_Session.

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

2011-08-03  Pascal Obry  

* g-awk.adb, g-awk.ads: Make GNAT.AWK API compatible with Ada 2005.
(Current_Session): Return a not null access to Session_Type.
(Default_Session): Likewise.

Index: g-awk.adb
===
--- g-awk.adb   (revision 177274)
+++ g-awk.adb   (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
--- Copyright (C) 2000-2010, AdaCore --
+-- Copyright (C) 2000-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- --
@@ -29,11 +29,6 @@
 --  --
 --
 
-pragma Ada_95;
---  This is needed because the pragmas Warnings (Off) in Current_Session and
---  Default_Session (see below) do not work when compiling clients of this
---  package that instantiate generic units herein.
-
 with Ada.Exceptions;
 with Ada.Text_IO;
 with Ada.Strings.Unbounded;
@@ -735,30 +730,18 @@
-- Current_Session --
-
 
-   function Current_Session return Session_Type is
+   function Current_Session return not null access Session_Type is
begin
-  pragma Warnings (Off);
-  return Cur_Session;
-  --  ???The above return statement violates the Ada 2005 rule forbidding
-  --  copying of limited objects (see RM-7.5(2.8/2)). When compiled with
-  --  -gnatg, the compiler gives a warning instead of an error, so we can
-  --  turn it off.
-  pragma Warnings (On);
+  return Cur_Session.Self;
end Current_Session;
 
-
-- Default_Session --
-
 
-   function Default_Session return Session_Type is
+   function Default_Session return not null access Session_Type is
begin
-  pragma Warnings (Off);
-  return Def_Session;
-  --  ???The above return statement violates the Ada 2005 rule forbidding
-  --  copying of limited objects (see RM-7.5(2.8/2)). When compiled with
-  --  -gnatg, the compiler gives a warning instead of an error, so we can
-  --  turn it off.
-  pragma Warnings (On);
+  return Def_Session.Self;
end Default_Session;
 

Index: g-awk.ads
===
--- g-awk.ads   (revision 177281)
+++ g-awk.ads   (working copy)
@@ -229,12 +229,12 @@
--  Set the session to be used by default. This file will be used when the
--  Session parameter in following services is not specified.
 
-   function Current_Session return Session_Type;
+   function Current_Session return not null access Session_Type;
--  Returns the session used by default by all services. This is the
--  latest session specified by Set_Current service or the session
--  provided by default with this implementation.
 
-   function Default_Session return Session_Type;
+   function Default_Session return not null access Session_Type;
--  Returns the default session provided by this package. Note that this is
--  the session return by Current_Session if Set_Current has not been used.
 
@@ -633,6 +633,7 @@
 
type Session_Type is new Ada.Finalization.Limited_Controlled with record
   Data : Session_Data_Access;
+  Self : not null access Session_Type := Session_Type'Unchecked_Access;
end record;
 
procedure Initialize (Session : in out Session_Type);


Re: [patch tree-optimization]: Improve reassociation pass for bitwise-operations

2011-08-03 Thread Kai Tietz
2011/8/3 Michael Matz :
> Hi,
>
> On Wed, 3 Aug 2011, Kai Tietz wrote:
>
>> > Implement all of this in the normal reassoc machinery that already
>> > exists. Don't implement your own walker (which btw is superlinear
>> > because you recurse into both operands).  If no simplifications were
>> > possible you have to fold back the NOTs into the shorter sequences
>> > again, which conveniently reassoc already can do for negates and
>> > PLUS/MINUS chains.
>> >
>> > Hence extend the existing support for arithmetic operations to logical
>> > operations.
>>
>> What you mean by existing machinery for negate expression here?
>
> tree-reassoc can handle chains of NEGATE/PLUS/MINUS/MULT/DIV expressions,
> including undistribution (A*X + B*X -> (A+B)*X).  It does have some
> deficiencies with mixed chains (e.g. mixture of PLUS and MULT
> expressions).
>
> Now, in the usual mathematical parlance we have these correspondences:
>  NOT == NEGATE
>  AND == MULT
>  IOR == PLUS
> hence, if you extend the existing reassoc machinery to first deal nicely
> with mixed chains and then handle NOT/AND/IOR like their arithmetic
> counterparts you will have improved reassoc for arithmetic operations
> _and_ extended it to also handle logical operation chains.  Without
> hacking a completely different way of walking and collection operands for
> logicals in parallel to the one for arithmetics.
>
>> This machinery doen't work in this case
>
> That's why you have to extend it.

The issue about this machinery is that it assumes that the statement
itself gets transformed, but for normalized form of invert of bitwise
operations it is essential to perform invert operation on the
operands, too.

>> Eg: the case (~(a | c) & (b & ~d))  would be expanded (by code in
>> patch) to ~a & ~c & b & ~d.
>
> That's what I mean with better handling of mixed chains.  -(a+b) is
> already (sometimes) rewritten into -a + -b (see negate_value).  That's
> just slightly different from rewriting ~(a|b) into ~a & ~b.

Yes, it affects just one operand. And its weakness is that a (which
might be a more complex statement) doesn't get folded for the negate
operation here.  Eg.  a = 1 - d; c = - (a + b); should become d - b -
1 and optimized form of (d - (b + 1)).

But AFAIR the code the thing is different what break_up_substract
does.  It modifies (a - b) -> a + (-b),  which is for sure worth to
simplify and ease arithmetic plus optimization.  But doesn't match the
point you are talking about.

>> This intermediate result is good to inspect doubles, or inverted
>> optimizations. On rebuilding of tree the result gets transformed (or
>> should) to ~(a | c | d) & b.
>
> And that would be done by undistribute_ops_list, if it were properly
> extended.
>
>> This opportunity is just present because we unwinded the intial tree.
>> Classical folding pass isn't able to actual detect or do that on
>> gimpled-trees.
>
> That's why you do this whole excercise in tree-reassoc, where it indeed
> belongs.  My point is that you should extend the existing means to support
> your operations, instead of implementing a similar-but-different approach
> in parallel.

As I tried to pointed out before is the approach in reassoc only well
working for single statements (not to talk here about non-single-used
statements, which seems to be something my patch needs to handle
better - a Richard said, it might walks statements so multiple times).
 But for an invert the operands and the expression-codes are changing,
too.
As later reassoc pass just walk the tree and combines simliar
operation-codes in its vector by rank, and later optimization just
happens within this range,  it is essential to feed this vector with
proper (normalized) expression-codes.

>> I thought about using the same mechanism as for negate, but it doesn't
>> work and has major weaknesses for bitwise-binary operations. The negate
>> logic is here a predicate, but the unwinding and flattening of bitwise
>> trees isn't a predicate.
>
> What you descrive as "flattening" is actually building a normal form.
> reassoc uses a vector of operand extries to hold such normal form (as
> said, not yet dealing with mixed chains).  linearize_expr_tree does the
> flattening, and you would have to extend it (and its associated helper
> routines) to handle mixed chains and then you logical operations.

Well, it does this in a very limited approach and is strictly bound to
an underlying statement.

> Once a linearized array of operands (possibly of level two to handle mixed
> chains) exists undistribute_ops_list and optimize_ops_list will optimize
> those operands again, and rewrite_expr_tree will produce statements
> implementing the so optimized operand list.  You will have to extend that
> too for your logical operations (and possibly compares).
>
>
> Ciao,
> Michael.

Actually it might be also a way to rewrite reassociation pass in a way
that it just operates on normalized predicated trees made out of the
orignal tree.  Operates on it, and th

[Ada] Improper optimization of range checks

2011-08-03 Thread Arnaud Charlet
Several static evaluation routines use Determine_Range to establish the bounds
of a non-static expression. If overflow cheks are enabled, the range of the
result of unary and binary operations may raise an exception, and cannot be
assumed to evaluate correctly without a run-time check. This patch prevents
unwarranted optimizations on boolean expressions appearing in preconditions
and other contexts.

The following must execute quietly;

   gcc -c -gnato -gnatDG -gnatc add.ads
   grep true gnat.ads.dg

---
package Add is
   function AddTwo (X, Y : Integer) return Integer;
  Pragma Precondition (X + Y <= Integer'Last);
  Pragma Postcondition (AddTwo'Result = X + Y);
end Add;

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

2011-08-03  Ed Schonberg  

* checks.adb (Determine_Range): If a computed bound of an operation is
outside the range of the base type of the expression, and overflow
checks are enabled, the result is unknown and cannot be used for any
subsequent constant folding.
* sem_eval.adb (Compile_Time_Compare): if the bounds of one operand are
unknown, so is the result of the comparison.

Index: checks.adb
===
--- checks.adb  (revision 177274)
+++ checks.adb  (working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -3457,6 +3457,18 @@
   --  the computed expression is in the range Lor .. Hir. We can use this
   --  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 evaluation has failed, at least if checks are enabled.
+
+  if Enable_Overflow_Checks
+and then not Is_Entity_Name (N)
+and then  (Lor < Lo or else Hir > Hi)
+  then
+ OK := False;
+ return;
+  end if;
+
   if OK1 then
 
  --  If the refined value of the low bound is greater than the type
Index: sem_eval.adb
===
--- sem_eval.adb(revision 177274)
+++ sem_eval.adb(working copy)
@@ -6,7 +6,7 @@
 --  --
 -- B o d y  --
 --  --
---  Copyright (C) 1992-2010, Free Software Foundation, Inc. --
+--  Copyright (C) 1992-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- --
@@ -964,6 +964,12 @@
  return Unknown;
   end if;
end if;
+else
+
+   --  If the range of either operand cannot be determined,
+   --  nothing further can be inferred.
+
+   return Unknown;
 end if;
  end;
 


[Ada] Finalization actions during abort

2011-08-03 Thread Arnaud Charlet
This patch reimplements how finalization is carried out during an abort.

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

2011-08-03  Hristian Kirtchev  

* a-except-2005.adb (Raise_From_Controlled_Operation): Add new formal
From_Abort. When finalization was triggered by an abort, propagate
Standard'Abort_Signal rather than Program_Error.
* a-except-2005.ads (Raise_From_Controlled_Operation): Add new formal
From_Abort.
* a-except.adb (Raise_From_Controlled_Operation): Add new formal
From_Abort. When finalization was triggered by an abort, propagate
Standard'Abort_Signal rather than Program_Error.
* a-except.ads:(Raise_From_Controlled_Operation): Add new formal
From_Abort.
* exp_ch7.adb:(Build_Adjust_Or_Finalize_Statements): New local variable
Abort_Id. Update the calls to Build_Object_Declarations and
Build_Raise_Statement to include Abort_Id.
(Build_Adjust_Statements): New local variable Abort_Id. Update the
calls to Build_Object_Declarations and Build_Raise_Statement to include
Abort_Id.
(Build_Finalize_Statements): New local variable Abort_Id. Update the
calls to Build_Object_Declarations and Build_Raise_Statement to include
Abort_Id.
(Build_Components): Create an entity for Abort_Id when exceptions are
allowed on the target.
(Build_Finalizer): New local variable Abort_Id.
(Build_Initialize_Statements): New local variable Abort_Id. Update the
calls to Build_Object_Declarations and Build_Raise_Statement to include
Abort_Id.
(Build_Object_Declarations): Add new formal Abort_Id. Create the
declaration of flag Abort_Id to preserve the original abort status
before finalization code is executed.
(Build_Raise_Statement): Add new formal Abort_Id. Pass Abort_Id to
runtime routine Raise_From_Controlled_Operation.
(Create_Finalizer): Update the call to Build_Raise_Statement to include
Abort_Id. Update the call to Build_Object_Declarations to include
Abort_Id. Update the layout of the finalizer body.
(Make_Handler_For_Ctrl_Operation): Add an actual for From_Abort.
(Process_Transient_Objects): New local variable Abort_Id. Remove the
clunky code to create all flags and objects related to
exception propagation and replace it with a call to
Build_Object_Declarations. Update the call to Build_Raise_Statement to
include Abort_Id.
* exp_ch7.ads (Build_Object_Declarations): Moved from body to spec.
Add new formal Abort_Id and associated comment on its use.
(Build_Raise_Statement): Add new formal Abort_Id and associated comment
on its use.
* exp_intr.adb (Expand_Unc_Deallocation): New local variable Abort_Id.
Remove the clunky code to create all flags and objects related to
exception propagation and replace it with a call to
Build_Object_Declarations. Update the call to Build_Raise_Statement.

Index: exp_ch7.adb
===
--- exp_ch7.adb (revision 177282)
+++ exp_ch7.adb (working copy)
@@ -359,17 +359,6 @@
--  an exception handler, the statements will be wrapped in a block to avoid
--  unwanted interaction with the new At_End handler.
 
-   function Build_Object_Declarations
- (Loc   : Source_Ptr;
-  E_Id  : Entity_Id;
-  Raised_Id : Entity_Id) return List_Id;
-   --  Subsidiary to Make_Deep_Array_Body and Make_Deep_Record_Body. Return a
-   --  list containing the object declarations of the exception occurrence E_Id
-   --  and boolean flag Raised_Id.
-   --
-   --E_Id  : Exception_Occurrence;
-   --Raised_Id : Boolean := False;
-
procedure Build_Record_Deep_Procs (Typ : Entity_Id);
--  Build the deep Initialize/Adjust/Finalize for a record Typ with
--  Has_Component_Component set and store them using the TSS mechanism.
@@ -1088,10 +1077,15 @@
   --  structures right from the start. Entities and lists are created once
   --  it has been established that N has at least one controlled object.
 
+  Abort_Id : Entity_Id := Empty;
+  --  Entity of local flag. The flag is set when finalization is triggered
+  --  by an abort.
+
   Components_Built : Boolean := False;
   --  A flag used to avoid double initialization of entities and lists. If
   --  the flag is set then the following variables have been initialized:
   --
+  --Abort_Id
   --Counter_Id
   --E_Id
   --Finalizer_Decls
@@ -1237,6 +1231,7 @@
 Counter_Typ := Make_Temporary (Loc, 'T');
 
 if Exceptions_OK then
+   Abort_Id  := Make_Temporary (Loc, 'A');
E_Id  := Make_Temporary (Loc, 'E');
Raised_Id := Make_Temporary (Loc, 'R');
 end if;
@@ -

Re: [RFC] Cleanup DW_CFA_GNU_args_size handling

2011-08-03 Thread Richard Henderson
On 08/03/2011 07:07 AM, Georg-Johann Lay wrote:
> #include 
> 
> void foo ()
> {
> printf ("%d %d %d", 1, 2, 3);
> printf ("%d %d %d", 3, 4, 5);
> printf ("%d %d %d", 1, 4, 5);
> }
> 
> Attached the output: The compiler happily pushes onto the stack
> but pops only at the end of the function. So in a function with
> many such calls that would eat up great deal of RAM. It that
> what we want?

Add more printfs and find out.  We'll consume 32 bytes and then
pop it all off in the middle of the function, then start again.

See the use of pending_stack_adjust in expand_call.


r~


[Ada] Extend ALFA marks to more types of nodes

2011-08-03 Thread Arnaud Charlet
Follow-up of work on marking nodes as being in ALFA for formal verification.
Mark more nodes in ALFA when a reasonable translation exists for verification.

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

2011-08-03  Yannick Moy  

* sem_ch11.adb (Analyze_Raise_xxx_Error): do not mark such nodes as not
in ALFA. Instead, they are considered as assertions to prove.
* sem_ch4.adb (Analyze_Conditional_Expression): do not always mark such
nodes as not in ALFA. Instead, include conditional expressions in ALFA
if they have no ELSE part, or if they occur in pre- and postconditions,
where the Condition cannot have side-effects in ALFA
(Analyze_Membership_Op): do not mark such nodes as not in ALFA
(Analyze_Type_Conversion): do not always mark such nodes as not in ALFA.
Instead, include type conversion between scalar types in ALFA.
* sem_ch6.adb (Process_Formals): correctly mark a parameter in ALFA
if-and-only-if its type is in ALFA.

Index: sem_ch4.adb
===
--- sem_ch4.adb (revision 177275)
+++ sem_ch4.adb (working copy)
@@ -1520,11 +1520,23 @@
  return;
   end if;
 
-  Mark_Non_ALFA_Subprogram;
   Check_SPARK_Restriction ("conditional expression is not allowed", N);
 
   Else_Expr := Next (Then_Expr);
 
+  --  In ALFA, conditional expressions are allowed:
+  --* if they have no ELSE part, in which case the expression is
+  --  equivalent to
+  --NOT Condition OR ELSE Then_Expr
+  --* in pre- and postconditions, where the Condition cannot have side-
+  --  effects (in ALFA) and thus the expression is equivalent to
+  --(Condition AND THEN Then_Expr)
+  --  and (NOT Condition AND THEN Then_Expr)
+
+  if Present (Else_Expr) and then not In_Pre_Post_Expression then
+ Mark_Non_ALFA_Subprogram;
+  end if;
+
   if Comes_From_Source (N) then
  Check_Compiler_Unit (N);
   end if;
@@ -2483,8 +2495,6 @@
--  Start of processing for Analyze_Membership_Op
 
begin
-  Mark_Non_ALFA_Subprogram;
-
   Analyze_Expression (L);
 
   if No (R)
@@ -4375,8 +4385,6 @@
   T: Entity_Id;
 
begin
-  Mark_Non_ALFA_Subprogram;
-
   --  If Conversion_OK is set, then the Etype is already set, and the
   --  only processing required is to analyze the expression. This is
   --  used to construct certain "illegal" conversions which are not
@@ -4398,6 +4406,13 @@
   Analyze_Expression (Expr);
   Validate_Remote_Type_Type_Conversion (N);
 
+  --  Type conversion between scalar types are allowed in ALFA. All other
+  --  type conversions are not allowed.
+
+  if not (Is_Scalar_Type (Etype (Expr)) and then Is_Scalar_Type (T)) then
+ Mark_Non_ALFA_Subprogram;
+  end if;
+
   --  Only remaining step is validity checks on the argument. These
   --  are skipped if the conversion does not come from the source.
 
Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 177284)
+++ sem_ch6.adb (working copy)
@@ -8881,13 +8881,12 @@
 
  Set_Etype (Formal, Formal_Type);
 
- --  If the type of a subprogram's formal parameter is not in ALFA,
- --  then the subprogram is not in ALFA.
+ --  The parameter is in ALFA if-and-only-if its type is in ALFA
 
- if Nkind (Parent (First (T))) in N_Subprogram_Specification
-   and then not Is_In_ALFA (Formal_Type)
- then
-Set_Is_In_ALFA (Defining_Entity (Parent (First (T))), False);
+ if Is_In_ALFA (Formal_Type) then
+Set_Is_In_ALFA (Formal);
+ else
+Mark_Non_ALFA_Subprogram;
  end if;
 
  Default := Expression (Param_Spec);
Index: sem_ch11.adb
===
--- sem_ch11.adb(revision 177275)
+++ sem_ch11.adb(working copy)
@@ -602,7 +602,6 @@
--  Start of processing for Analyze_Raise_xxx_Error
 
begin
-  Mark_Non_ALFA_Subprogram;
   Check_SPARK_Restriction ("raise statement is not allowed", N);
 
   if No (Etype (N)) then


Re: [RFC] Cleanup DW_CFA_GNU_args_size handling

2011-08-03 Thread Richard Henderson
On 08/03/2011 07:07 AM, Ulrich Weigand wrote:
> Was this assert intended to impose requirements on target's
> restore_stack_block implemtations?  What exactly are those
> supposed to be?

The assert was not intended to impose requirements, but to figure
out if I needed to do anything special here.

Binutils has no simulator for spu.  Can you file a bug with a 
specific test case and CC me?


r~


Re: [PATCH][RFC] Fix PR49957 - build array index differently

2011-08-03 Thread Richard Guenther
On Wed, 3 Aug 2011, Richard Guenther wrote:

> 
> This fixes PR49957 by keeping the array index into a multi-dimensional
> array in optimal associated form which is ((off + outermost) + ...) + 
> innermost) + constant) so that dependence analysis can properly
> handle it.  It doesn't work right now because we build the
> expression in reverse order, fold thinks it can do some fancy and
> the expression is of signed type and thus we know it doesn't overflow
> but we also won't re-associate it to a more optimal form.
> 
> I tried reversing the loop in gfc_conv_array_ref but that doesn't
> work (for example aliasing_dummy_4.f90 ICEs), thus the funny way
> of chaining the pluses.
> 
> I also don't know if there is maybe another place we build similar
> expressions that should be adjusted, too - this one is where
> we build the expression for the testcase I looked at.
> 
> The patch doesn't make 410.bwaves measurably faster, but at least
> it also doesn't get slower.
> 
> Bootstrap and regtest is currently running on x86_64-unknown-linux-gnu,
> the reversed loop one was ok (well, apart from those 2-3 fails).
> 
> Comments?  Any idea why reversing the loop would break?
> The ICE I got is
> 
> /space/rguenther/src/svn/trunk/gcc/testsuite/gfortran.dg/aliasing_dummy_4.f90:
>  
> In function 'test_f90':
> /space/rguenther/src/svn/trunk/gcc/testsuite/gfortran.dg/aliasing_dummy_4.f90:21:0:
>  
> internal compiler error: in gfc_conv_constant, at 
> fortran/trans-const.c:387
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.

Tobias noticed the testcase is optimized away, fixed.  Also fixed
is another oversight for another loop in 410.bwaves, with constant
first index.

Re-bootstrapping currently.  The previous patch tested ok.

Richard.

2011-08-03  Richard Guenther  

PR fortran/49957
* trans-array.c (gfc_conv_array_ref): Build the array index
expression in optimally associated order.

* gfortran.dg/vect/O3-pr49957.f: New testcase.

Index: gcc/fortran/trans-array.c
===
--- gcc/fortran/trans-array.c   (revision 177094)
+++ gcc/fortran/trans-array.c   (working copy)
@@ -2634,7 +2634,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
locus * where)
 {
   int n;
-  tree index;
+  tree index, offset, *indexp;
   tree tmp;
   tree stride;
   gfc_se indexse;
@@ -2669,9 +2669,16 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
   return;
 }
 
-  index = gfc_index_zero_node;
+  offset = gfc_conv_array_offset (se->expr);
+  if (TREE_CODE (offset) != INTEGER_CST)
+index = offset;
+  else
+index = gfc_index_zero_node;
 
-  /* Calculate the offsets from all the dimensions.  */
+  indexp = &index;
+
+  /* Calculate the offsets from all the dimensions.  Make sure to associate
+ the final offset so that we form a chain of loop invariant summands.  */
   for (n = 0; n < ar->dimen; n++)
 {
   /* Calculate the index for this dimension.  */
@@ -2740,15 +2747,43 @@ gfc_conv_array_ref (gfc_se * se, gfc_arr
   tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
 indexse.expr, stride);
 
-  /* And add it to the total.  */
-  index = fold_build2_loc (input_location, PLUS_EXPR,
-  gfc_array_index_type, index, tmp);
+  /* And add it to the total.  Avoid folding as that re-associates
+ in a non-optimal way.  We want to have constant offsets as
+the outermost addition and the rest of the additions in order
+of the loop depth.  */
+  if (!integer_zerop (index))
+   {
+ if (TREE_CODE (tmp) == INTEGER_CST)
+   {
+ bool reset = indexp == &index;
+ index = fold_build2_loc (input_location, PLUS_EXPR,
+  gfc_array_index_type, index, tmp);
+ if (reset)
+   {
+ if (TREE_CODE (index) == PLUS_EXPR)
+   indexp = &TREE_OPERAND (index, 0);
+ else
+   indexp = &index;
+   }
+   }
+ else
+   {
+ *indexp
+   = build2_loc (input_location, PLUS_EXPR,
+ gfc_array_index_type, *indexp, tmp);
+ indexp = &TREE_OPERAND (*indexp, 0);
+   }
+   }
+  else
+   {
+ index = tmp;
+ indexp = &index;
+   }
 }
 
-  tmp = gfc_conv_array_offset (se->expr);
-  if (!integer_zerop (tmp))
+  if (TREE_CODE (offset) == INTEGER_CST)
 index = fold_build2_loc (input_location, PLUS_EXPR,
-gfc_array_index_type, index, tmp);
+gfc_array_index_type, index, offset);
 
   /* Access the calculated element.  */
   tmp = gfc_conv_array_data (se->expr);
Index: gcc/testsuite/gfortran.dg/vect/O3-pr49957.f

[Ada] Only allow boolean conditional expression in ALFA

2011-08-03 Thread Arnaud Charlet
Previous patch allowed any type of conditional expression in ALFA. Now restrict
this to boolean expressions only. Possibly subject to change later on when
translation from ALFA improves.

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

2011-08-03  Yannick Moy  

* sem_ch4.adb (Analyze_Conditional_Expression): only allow boolean
conditional expression in ALFA.
* sem_res.adb (Resolve_Conditional_Expression): mark non-boolean
expressions as not in ALFA.

Index: sem_res.adb
===
--- sem_res.adb (revision 177275)
+++ sem_res.adb (working copy)
@@ -5860,6 +5860,10 @@
  Append_To (Expressions (N), Error);
   end if;
 
+  if Root_Type (Typ) /= Standard_Boolean then
+ Mark_Non_ALFA_Subprogram;
+  end if;
+
   Set_Etype (N, Typ);
   Eval_Conditional_Expression (N);
end Resolve_Conditional_Expression;
Index: sem_ch4.adb
===
--- sem_ch4.adb (revision 177285)
+++ sem_ch4.adb (working copy)
@@ -1524,15 +1524,21 @@
 
   Else_Expr := Next (Then_Expr);
 
-  --  In ALFA, conditional expressions are allowed:
+  --  In ALFA, boolean conditional expressions are allowed:
   --* if they have no ELSE part, in which case the expression is
   --  equivalent to
+
   --NOT Condition OR ELSE Then_Expr
+
   --* in pre- and postconditions, where the Condition cannot have side-
   --  effects (in ALFA) and thus the expression is equivalent to
+
   --(Condition AND THEN Then_Expr)
   --  and (NOT Condition AND THEN Then_Expr)
 
+  --  Non-boolean conditional expressions are marked as not in ALFA during
+  --  resolution.
+
   if Present (Else_Expr) and then not In_Pre_Post_Expression then
  Mark_Non_ALFA_Subprogram;
   end if;


[Ada] Set_Command_Line: improve handling of grouped switches with parameters

2011-08-03 Thread Arnaud Charlet
The following code should find two switches on the command line: -gnatyL (with
 parameter "1") and -gnatya. Instead, we used to find a single switch -gnatyL
 with parameter "1a".

   Define_Switch (Config, "-gnatyL!");
   Define_Switch (Config, "-gnatya");
   Define_Prefix (Config, "-gnaty");

   Set_Configuration (Cmd, Config);

   set_Command_Line (Cmd, "-gnatyL1a");
   Start (Cmd, Iter, Expanded => True);
   while Has_More (Iter) loop
  Put_Line (Current_Switch (Iter));
  Next (Iter);
   end loop;

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

2011-08-03  Emmanuel Briot  

* g-comlin.adb, g-comlin.ads (Set_Command_Line): ignore the parameter
Getopt_Switches when we have already define a command line
configuration.

Index: g-comlin.adb
===
--- g-comlin.adb(revision 177274)
+++ g-comlin.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- --
@@ -19,10 +19,10 @@
 -- additional permissions described in the GCC Runtime Library Exception,   --
 -- version 3.1, as published by the Free Software Foundation.   --
 --  --
--- You should have received a copy of the GNU General Public License and--
--- a copy of the GCC Runtime Library Exception along with this program; --
--- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see--
--- .  --
+-- In particular,  you can freely  distribute your programs  built with the --
+-- GNAT Pro compiler, including any required library run-time units,  using --
+-- any licensing terms  of your choosing.  See the AdaCore Software License --
+-- for full details.--
 --  --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.  --
@@ -200,7 +200,8 @@
  (Config   : Command_Line_Configuration;
   Section  : String);
--  Iterate over all switches defined in Config, for a specific section.
-   --  Index is set to the index in Config.Switches
+   --  Index is set to the index in Config.Switches.
+   --  Stop iterating when Callback returns False.
 
--
-- Argument --
@@ -1238,6 +1239,10 @@
  Unchecked_Free (Tmp);
   end if;
 
+  if Switch.Switch /= null and then Switch.Switch.all = "*" then
+ Config.Star_Switch := True;
+  end if;
+
   Config.Switches (Config.Switches'Last) := Switch;
end Add;
 
@@ -1592,9 +1597,28 @@
 
  loop
 begin
-   S := Getopt (Switches=> "* " & Getopt_Description,
-Concatenate => False,
-Parser  => Parser);
+   if Cmd.Config /= null then
+  --  Do not use Getopt_Description in this case. Otherwise,
+  --  if we have defined a prefix -gnaty, and two switches
+  --  -gnatya and -gnatyL!, we would have a different behavior
+  --  depending on the order of switches:
+  --  -gnatyL1a   =>  -gnatyL with argument "1a"
+  --  -gnatyaL1   =>  -gnatya and -gnatyL with argument "1"
+  --  This is because the call to Getopt below knows nothing
+  --  about prefixes, and in the first case finds a valid
+  --  switch with arguments, so returns it without analyzing
+  --  the argument. In the second case, the switch matches "*",
+  --  and is then decomposed below.
+
+  S := Getopt (Switches=> "*",
+   Concatenate => False,
+   Parser  => Parser);
+   else
+  S := Getopt (Switches=> "* " & Getopt_Description,
+   Concatenate => False,
+   Parser  => Parser);
+   end if;
+
exit when S = ASCII.NUL;
 
declare
@@ -1761,6 +1785,8 @@
 
  function Analyze_Simple_Switch
(Switc

Selective scheduler fixes

2011-08-03 Thread Alexander Monakov
Hello,

This is a series of selective scheduler bug fixes.  They fix problems that
have been discovered during internal testing, and one patch is necessary as
preparation to predication support in the selective scheduler (predication
patches will be submitted separately later).

I'm sorry that patches come without testcases, but as most of the problems
have been discovered on a patched scheduler, it's virtually impossible to
provide testcases that would fail without a patch and pass with it.

The patches have been bootstrapped and regtested together on x86-64 and ia64
(without java on ia64).  Additionally, a number of tests was done with arm
cross-compiler.  I'll commit approved patches separately.

OK for trunk?

Dmitry Melnik (3):
  Take maximum spec when merging exprs
  Make more insns unique
  Drop an incorrect assert

Sergey Grechanik (5):
  Fix usage of hard_regno_nregs before reload
  Properly loop over all hard regs for mode
  Try successors to find seqno
  Factor out caching logic for INSN_COND
  Only merge deps status for true dependencies

 gcc/sched-deps.c   |   69 +++-
 gcc/sched-int.h|2 +-
 gcc/sel-sched-ir.c |  111 +---
 gcc/sel-sched-ir.h |1 +
 gcc/sel-sched.c|   14 +++---
 5 files changed, 137 insertions(+), 60 deletions(-)



[PATCH 1/8] Take maximum spec when merging exprs

2011-08-03 Thread Alexander Monakov
From: Dmitry Melnik 

EXPR_SPEC is an indicator of the speculativeness of an expression (an
instruction or just an rhs), as it is incremented each time the expression is
moved up across a conditional branch.  When merging expr attributes for
similar exprs available from two destinations of a branch, sel-sched assigns
the minimum of EXPR_SPEC's to the result, effectively making the resulting
expr non-speculative if only one of those exprs was non-speculative.  However,
since we are relying on EXPR_SPEC being a correct indication of expr's
speculativeness when deciding whether it would need a bookkeeping copy, we
really want to avoid that.

The patch changes minimum to maximum, making the code match what was
originally intended.

2011-08-04  Dmitry Melnik  

* sel-sched-ir.c (merge_expr_data): Take maximum spec.

diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index de7629a..5a287d0 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -1810,9 +1810,9 @@ update_speculative_bits (expr_t to, expr_t from, insn_t 
split_point)
 void
 merge_expr_data (expr_t to, expr_t from, insn_t split_point)
 {
-  /* For now, we just set the spec of resulting expr to be minimum of the specs
- of merged exprs.  */
-  if (EXPR_SPEC (to) > EXPR_SPEC (from))
+  /* Choose the maximum of the specs of merged exprs.  This is required
+ for correctness of bookkeeping.  */
+  if (EXPR_SPEC (to) < EXPR_SPEC (from))
 EXPR_SPEC (to) = EXPR_SPEC (from);
 
   if (split_point)


[PATCH 3/8] Fix usage of hard_regno_nregs before reload

2011-08-03 Thread Alexander Monakov
From: Sergey Grechanik 

This fixes one place where hard_regno_nregs is incorrectly guarded by
reload_completed (as if before reload all regs are pseudos).

2011-08-04  Sergey Grechanik  

* sel-sched.c (verify_target_availability): Fix usage of
hard_regno_nregs.

diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c
index 92ba222..e791e4c 100644
--- a/gcc/sel-sched.c
+++ b/gcc/sel-sched.c
@@ -1581,7 +1581,7 @@ verify_target_availability (expr_t expr, regset used_regs,
   regno = expr_dest_regno (expr);
   mode = GET_MODE (EXPR_LHS (expr));
   target_available = EXPR_TARGET_AVAILABLE (expr) == 1;
-  n = reload_completed ? hard_regno_nregs[regno][mode] : 1;
+  n = HARD_REGISTER_NUM_P (regno) ? hard_regno_nregs[regno][mode] : 1;
 
   live_available = hard_available = true;
   for (i = 0; i < n; i++)


[PATCH 4/8] Properly loop over all hard regs for mode

2011-08-03 Thread Alexander Monakov
From: Sergey Grechanik 

There are several places where bitmap_bit_p function is used to test if some
register is in the regset.  We need to take into account the fact that
depending on mode, we need to test multiple hard regs.

2011-08-04  Sergey Grechanik  

* sel-sched-ir.h (register_unavailable_p): Declare.
* sel-sched-ir.c (register_unavailable_p): New.  Use it...
(set_unavailable_target_for_expr): ... here to properly test
availability of a register.
(speculate_expr): Ditto.
* sel-sched.c (substitute_reg_in_expr): Ditto.
(av_set_could_be_blocked_by_bookkeeping_p): Ditto.

diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 8f5cd3f..f22e637 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -1883,7 +1883,7 @@ set_unavailable_target_for_expr (expr_t expr, regset 
lv_set)
   if (EXPR_SEPARABLE_P (expr))
 {
   if (REG_P (EXPR_LHS (expr))
-  && bitmap_bit_p (lv_set, REGNO (EXPR_LHS (expr
+  && register_unavailable_p (lv_set, EXPR_LHS (expr)))
{
  /* If it's an insn like r1 = use (r1, ...), and it exists in
 different forms in each of the av_sets being merged, we can't say
@@ -1904,8 +1904,8 @@ set_unavailable_target_for_expr (expr_t expr, regset 
lv_set)
 miss a unifying code motion along both branches using a renamed
 register, but it won't affect a code correctness since upon
 an actual code motion a bookkeeping code would be generated.  */
- if (bitmap_bit_p (VINSN_REG_USES (EXPR_VINSN (expr)),
-   REGNO (EXPR_LHS (expr
+ if (register_unavailable_p (VINSN_REG_USES (EXPR_VINSN (expr)),
+ EXPR_LHS (expr)))
EXPR_TARGET_AVAILABLE (expr) = -1;
  else
EXPR_TARGET_AVAILABLE (expr) = false;
@@ -1971,8 +1971,8 @@ speculate_expr (expr_t expr, ds_t ds)
 
 /* Do not allow clobbering the address register of speculative
insns.  */
-if (bitmap_bit_p (VINSN_REG_USES (EXPR_VINSN (expr)),
-  expr_dest_regno (expr)))
+if (register_unavailable_p (VINSN_REG_USES (EXPR_VINSN (expr)),
+   expr_dest_reg (expr)))
   {
 EXPR_TARGET_AVAILABLE (expr) = false;
 return 2;
@@ -2026,6 +2026,25 @@ mark_unavailable_targets (av_set_t join_set, av_set_t 
av_set, regset lv_set)
 }
 
 
+/* Returns true if REG (at least partially) is present in REGS.  */
+bool
+register_unavailable_p (regset regs, rtx reg)
+{
+  unsigned regno, end_regno;
+
+  regno = REGNO (reg);
+  if (bitmap_bit_p (regs, regno))
+return true;
+
+  end_regno = END_REGNO (reg);
+
+  while (++regno < end_regno)
+if (bitmap_bit_p (regs, regno))
+  return true;
+
+  return false;
+}
+
 /* Av set functions.  */
 
 /* Add a new element to av set SETP.
diff --git a/gcc/sel-sched-ir.h b/gcc/sel-sched-ir.h
index 838c0d1..c8f8be6 100644
--- a/gcc/sel-sched-ir.h
+++ b/gcc/sel-sched-ir.h
@@ -1573,6 +1573,7 @@ extern void sel_init_global_and_expr (bb_vec_t);
 extern void sel_finish_global_and_expr (void);
 
 extern regset compute_live (insn_t);
+extern bool register_unavailable_p (regset, rtx);
 
 /* Dependence analysis functions.  */
 extern void sel_clear_has_dependence (void);
diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c
index e791e4c..f11faca 100644
--- a/gcc/sel-sched.c
+++ b/gcc/sel-sched.c
@@ -794,8 +794,8 @@ substitute_reg_in_expr (expr_t expr, insn_t insn, bool undo)
  /* Do not allow clobbering the address register of speculative
  insns.  */
  if ((EXPR_SPEC_DONE_DS (expr) & SPECULATIVE)
-  && bitmap_bit_p (VINSN_REG_USES (EXPR_VINSN (expr)),
-  expr_dest_regno (expr)))
+  && register_unavailable_p (VINSN_REG_USES (EXPR_VINSN (expr)),
+expr_dest_reg (expr)))
EXPR_TARGET_AVAILABLE (expr) = false;
 
  return true;
@@ -3631,12 +3631,12 @@ av_set_could_be_blocked_by_bookkeeping_p (av_set_t 
orig_ops, void *static_params
  renaming.  Check with the right register instead.  */
   if (sparams->dest && REG_P (sparams->dest))
 {
-  unsigned regno = REGNO (sparams->dest);
+  rtx reg = sparams->dest;
   vinsn_t failed_vinsn = INSN_VINSN (sparams->failed_insn);
 
-  if (bitmap_bit_p (VINSN_REG_SETS (failed_vinsn), regno)
- || bitmap_bit_p (VINSN_REG_USES (failed_vinsn), regno)
- || bitmap_bit_p (VINSN_REG_CLOBBERS (failed_vinsn), regno))
+  if (register_unavailable_p (VINSN_REG_SETS (failed_vinsn), reg)
+ || register_unavailable_p (VINSN_REG_USES (failed_vinsn), reg)
+ || register_unavailable_p (VINSN_REG_CLOBBERS (failed_vinsn), reg))
return true;
 }
 


[PATCH 5/8] Drop an incorrect assert

2011-08-03 Thread Alexander Monakov
From: Dmitry Melnik 

This fixes a bug caused by trying to initialize BB_AV_SET of a newly generated
jump.  It assumes that jump is only generated in new bb, while it can be
replaced in same BB by try_redirect_by_replacing_jump, if jump was conditional
and was pointing to the same BB by its both edges (this may happen due to
predication, when moving all insns up from a "diamond").

2011-08-04  Dmitry Melnik  

* sel-sched-ir.c (invalidate_av_set): Remove the assert.

diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index f22e637..dd8b3da 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -4284,14 +4284,13 @@ free_lv_sets (void)
   free_lv_set (bb);
 }
 
-/* Initialize an invalid AV_SET for BB.
-   This set will be updated next time compute_av () process BB.  */
+/* Mark AV_SET for BB as invalid, so this set will be updated the next time
+   compute_av() processes BB.  This function is called when creating new basic
+   blocks, as well as for blocks (either new or existing) where new jumps are
+   created when the control flow is being updated.  */
 static void
 invalidate_av_set (basic_block bb)
 {
-  gcc_assert (BB_AV_LEVEL (bb) <= 0
- && BB_AV_SET (bb) == NULL);
-
   BB_AV_LEVEL (bb) = -1;
 }
 


[PATCH 6/8] Try successors to find seqno

2011-08-03 Thread Alexander Monakov
From: Sergey Grechanik 

This patch fixes a problem when new jumps created in
sel_redirect_edge_and_branch_force could not get correct seqnos.

get_seqno_of_a_pred is renamed to get_seqno_for_a_jump.
Implementation-wise, it supports looking at multiple predecessors, and, if
that fails, also at successors.  get_seqno_by_succs is implemented similar to
get_seqno_by_preds.

2011-08-04  Sergey Grechanik  

* sel-sched-ir.c (get_seqno_of_a_pred): Rename to
get_seqno_for_a_jump.  Update the caller.
(get_seqno_by_succs): New.  Use it ...
(get_seqno_for_a_jump): ... here to find a seqno if looking at
predecessors was not sufficient.
(get_seqno_by_preds): Include head in iteration range, exclude insn.

diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index dd8b3da..91f9dd9 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -3940,9 +3940,39 @@ sel_luid_for_non_insn (rtx x)
   return -1;
 }
 
-/* Return seqno of the only predecessor of INSN.  */
+/*  Find the proper seqno for inserting at INSN by successors.
+Return -1 if no successors with positive seqno exist.  */
 static int
-get_seqno_of_a_pred (insn_t insn)
+get_seqno_by_succs (rtx insn)
+{
+  basic_block bb = BLOCK_FOR_INSN (insn);
+  rtx tmp = insn, end = BB_END (bb);
+  int seqno;
+  insn_t succ = NULL;
+  succ_iterator si;
+
+  while (tmp != end)
+{
+  tmp = NEXT_INSN (tmp);
+  if (INSN_P (tmp))
+return INSN_SEQNO (tmp);
+}
+
+  seqno = INT_MAX;
+
+  FOR_EACH_SUCC_1 (succ, si, end, SUCCS_NORMAL)
+if (INSN_SEQNO (succ) > 0)
+  seqno = MIN (seqno, INSN_SEQNO (succ));
+
+  if (seqno == INT_MAX)
+return -1;
+
+  return seqno;
+}
+
+/* Compute seqno for INSN by its preds or succs.  */
+static int
+get_seqno_for_a_jump (insn_t insn)
 {
   int seqno;
 
@@ -3982,14 +4012,24 @@ get_seqno_of_a_pred (insn_t insn)
  int n;
 
  cfg_preds (BLOCK_FOR_INSN (insn), &preds, &n);
- gcc_assert (n == 1);
 
- seqno = INSN_SEQNO (preds[0]);
+ gcc_assert (n > 0);
+ /* For one predecessor, use simple method.  */
+ if (n == 1)
+   seqno = INSN_SEQNO (preds[0]);
+ else
+   seqno = get_seqno_by_preds (insn);
 
  free (preds);
}
 }
 
+  /* We were unable to find a good seqno among preds.  */
+  if (seqno < 0)
+seqno = get_seqno_by_succs (insn);
+
+  gcc_assert (seqno >= 0);
+
   return seqno;
 }
 
@@ -4004,10 +4044,11 @@ get_seqno_by_preds (rtx insn)
   int n, i, seqno;
 
   while (tmp != head)
-if (INSN_P (tmp))
-  return INSN_SEQNO (tmp);
-else
+{
   tmp = PREV_INSN (tmp);
+  if (INSN_P (tmp))
+return INSN_SEQNO (tmp);
+}
 
   cfg_preds (bb, &preds, &n);
   for (i = 0, seqno = -1; i < n; i++)
@@ -4179,7 +4220,7 @@ init_simplejump_data (insn_t insn)
   init_expr (INSN_EXPR (insn), vinsn_create (insn, false), 0,
 REG_BR_PROB_BASE, 0, 0, 0, 0, 0, 0, NULL, true, false, false,
 false, true);
-  INSN_SEQNO (insn) = get_seqno_of_a_pred (insn);
+  INSN_SEQNO (insn) = get_seqno_for_a_jump (insn);
   init_first_time_insn_data (insn);
 }
 


[PATCH 2/8] Make more insns unique

2011-08-03 Thread Alexander Monakov
From: Dmitry Melnik 

This patch prevents duplicating (as bookkeeping code) instructions that are
either volatile or recognized by cannot_copy_insn_p target hook (in addition
to already present restrictions).  This avoids generating incorrect assembler
with duplicate labels on ARM.

2011-08-04  Dmitry Melnik  

* sel-sched-ir.c (init_global_and_expr_for_insn): Forbid copying of
recognized by cannot_copy_insn_p hook and volatile instructions.

diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 5a287d0..8f5cd3f 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -2956,7 +2956,10 @@ init_global_and_expr_for_insn (insn_t insn)
   /* Exception handling insns are always unique.  */
   || (cfun->can_throw_non_call_exceptions && can_throw_internal (insn))
   /* TRAP_IF though have an INSN code is control_flow_insn_p ().  */
-  || control_flow_insn_p (insn))
+  || control_flow_insn_p (insn)
+  || volatile_insn_p (PATTERN (insn))
+  || (targetm.cannot_copy_insn_p
+  && targetm.cannot_copy_insn_p (insn)))
 force_unique_p = true;
   else
 force_unique_p = false;


  1   2   >