This changes a few places in the System.Atomic_Operations packages to
using static expressions, which guarantees that contant folding is done
in the front-end instead of the code generator.

No functional changes.

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

2020-06-03  Eric Botcazou  <ebotca...@adacore.com>

gcc/ada/

        * libgnat/s-atopar.adb (Atomic_Fetch_And_Add): Make use of an
        equivalent static expression.
        (Atomic_Fetch_And_Subtract): Likewise.
        (Is_Lock_Free): Likewise.
        * libgnat/s-atopex.adb (Atomic_Exchange): Likewise.
        (Atomic_Compare_And_Exchange): Likewise.
        (Is_Lock_Free): Likewise.
--- gcc/ada/libgnat/s-atopar.adb
+++ gcc/ada/libgnat/s-atopar.adb
@@ -88,7 +88,7 @@ package body System.Atomic_Operations.Arithmetic is
       pragma Warnings (On);
 
    begin
-      case Item'Size is
+      case Atomic_Type'Size is
          when 8      => return Atomic_Fetch_Add_1 (Item'Address, Value);
          when 16     => return Atomic_Fetch_Add_2 (Item'Address, Value);
          when 32     => return Atomic_Fetch_Add_4 (Item'Address, Value);
@@ -125,7 +125,7 @@ package body System.Atomic_Operations.Arithmetic is
       pragma Warnings (On);
 
    begin
-      case Item'Size is
+      case Atomic_Type'Size is
          when 8      => return Atomic_Fetch_Sub_1 (Item'Address, Value);
          when 16     => return Atomic_Fetch_Sub_2 (Item'Address, Value);
          when 32     => return Atomic_Fetch_Sub_4 (Item'Address, Value);
@@ -139,9 +139,10 @@ package body System.Atomic_Operations.Arithmetic is
    ------------------
 
    function Is_Lock_Free (Item : aliased Atomic_Type) return Boolean is
+      pragma Unreferenced (Item);
       use type Interfaces.C.size_t;
    begin
-      return Boolean (Atomic_Always_Lock_Free (Item'Size / 8));
+      return Boolean (Atomic_Always_Lock_Free (Atomic_Type'Size / 8));
    end Is_Lock_Free;
 
 end System.Atomic_Operations.Arithmetic;

--- gcc/ada/libgnat/s-atopex.adb
+++ gcc/ada/libgnat/s-atopex.adb
@@ -66,7 +66,7 @@ package body System.Atomic_Operations.Exchange is
       pragma Warnings (On);
 
    begin
-      case Item'Size is
+      case Atomic_Type'Size is
          when 8      => return Atomic_Exchange_1 (Item'Address, Value);
          when 16     => return Atomic_Exchange_2 (Item'Address, Value);
          when 32     => return Atomic_Exchange_4 (Item'Address, Value);
@@ -124,7 +124,7 @@ package body System.Atomic_Operations.Exchange is
       pragma Warnings (On);
 
    begin
-      case Item'Size is
+      case Atomic_Type'Size is
          when 8 =>
             return Boolean
               (Atomic_Compare_Exchange_1
@@ -151,9 +151,10 @@ package body System.Atomic_Operations.Exchange is
    ------------------
 
    function Is_Lock_Free (Item : aliased Atomic_Type) return Boolean is
+      pragma Unreferenced (Item);
       use type Interfaces.C.size_t;
    begin
-      return Boolean (Atomic_Always_Lock_Free (Item'Size / 8));
+      return Boolean (Atomic_Always_Lock_Free (Atomic_Type'Size / 8));
    end Is_Lock_Free;
 
 end System.Atomic_Operations.Exchange;

Reply via email to