a-tasatt.adb, [...] (Fast_Path): Rewritten to avoid reading potentially uninitialized...
authorArnaud Charlet <charlet@adacore.com>
Thu, 21 Apr 2016 10:21:56 +0000 (10:21 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 21 Apr 2016 10:21:56 +0000 (12:21 +0200)
2016-04-21  Arnaud Charlet  <charlet@adacore.com>

* a-tasatt.adb, a-tasatt.ads (Fast_Path): Rewritten to avoid reading
potentially uninitialized memory.
* sem_ch3.adb: Minor style fix in comment.

From-SVN: r235329

gcc/ada/ChangeLog
gcc/ada/a-tasatt.adb
gcc/ada/a-tasatt.ads
gcc/ada/sem_ch3.adb

index 3e89814..3dcc02d 100644 (file)
@@ -1,5 +1,11 @@
 2016-04-21  Arnaud Charlet  <charlet@adacore.com>
 
+       * a-tasatt.adb, a-tasatt.ads (Fast_Path): Rewritten to avoid reading
+       potentially uninitialized memory.
+       * sem_ch3.adb: Minor style fix in comment.
+
+2016-04-21  Arnaud Charlet  <charlet@adacore.com>
+
        * gnat_rm.texi, gnat_ugn.texi,
        doc/gnat_ugn/gnat_project_manager.rst,
        doc/gnat_ugn/building_executable_programs_with_gnat.rst,
index e0ef9b2..1eb7d59 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---            Copyright (C) 2014, Free Software Foundation, Inc.            --
+--            Copyright (C) 2014-2016, 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- --
@@ -93,6 +93,11 @@ package body Ada.Task_Attributes is
    function To_Attribute is new
      Ada.Unchecked_Conversion (Atomic_Address, Attribute);
 
+   function To_Address is new
+     Ada.Unchecked_Conversion (Attribute, System.Address);
+   function To_Int is new
+     Ada.Unchecked_Conversion (Attribute, Integer);
+
    pragma Warnings (On);
 
    function To_Address is new
@@ -114,9 +119,12 @@ package body Ada.Task_Attributes is
      Ada.Unchecked_Deallocation (Real_Attribute, Real_Attribute_Access);
 
    Fast_Path : constant Boolean :=
-                 Attribute'Size <= Atomic_Address'Size
+                 (Attribute'Size = Integer'Size
+                   and then Attribute'Alignment <= Atomic_Address'Alignment
+                   and then To_Int (Initial_Value) = 0)
+                 or else (Attribute'Size = System.Address'Size
                    and then Attribute'Alignment <= Atomic_Address'Alignment
-                   and then To_Address (Initial_Value) = 0;
+                   and then To_Address (Initial_Value) = System.Null_Address);
    --  If the attribute fits in an Atomic_Address (both size and alignment)
    --  and Initial_Value is 0 (or null), then we will map the attribute
    --  directly into ATCB.Attributes (Index), otherwise we will create
index a3e1f0e..857cdd7 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---            Copyright (C) 2014, Free Software Foundation, Inc.            --
+--            Copyright (C) 2014-2016, 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 --
@@ -42,8 +42,9 @@ generic
 package Ada.Task_Attributes is
 
    --  Note that this package will use an efficient implementation with no
-   --  locks and no extra dynamic memory allocation if Attribute can fit in a
-   --  System.Address type, and Initial_Value is 0 (null for an access type).
+   --  locks and no extra dynamic memory allocation if Attribute is the size
+   --  of either Integer or System.Address, and Initial_Value is 0 (null for
+   --  an access type).
 
    --  Other types and initial values are supported, but will require
    --  the use of locking and a level of indirection (meaning extra dynamic
index cd5fd8f..0560a69 100644 (file)
@@ -3423,7 +3423,7 @@ package body Sem_Ch3 is
 
          if Error_Posted (N) then
 
-            --  Type mismatch or illegal redeclaration, Do not analyze
+            --  Type mismatch or illegal redeclaration; do not analyze
             --  expression to avoid cascaded errors.
 
             T := Find_Type_Of_Object (Object_Definition (N), N);
@@ -3460,7 +3460,7 @@ package body Sem_Ch3 is
       end if;
 
       --  Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
-      --  out some static checks
+      --  out some static checks.
 
       if Ada_Version >= Ada_2005 and then Can_Never_Be_Null (T) then