[Ada] Work around CodePeer bug by declaring variable
authorGhjuvan Lacambre <lacambre@adacore.com>
Tue, 22 Jun 2021 08:15:36 +0000 (10:15 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 20 Sep 2021 12:31:28 +0000 (12:31 +0000)
gcc/ada/

* atree.adb (Get_32_Bit_Field): Declare result before returning.

gcc/ada/atree.adb

index c7e295b..3be7e03 100644 (file)
@@ -513,8 +513,13 @@ package body Atree is
 
          function Cast is new
            Unchecked_Conversion (Field_Size_32_Bit, Field_Type);
+
+         Result : constant Field_Type := Cast (Get_32_Bit_Val (N, Offset));
+         --  Note: declaring Result here instead of directly returning
+         --  Cast (...) helps CodePeer understand that there are no issues
+         --  around uninitialized variables.
       begin
-         return Cast (Get_32_Bit_Val (N, Offset));
+         return Result;
       end Get_32_Bit_Field;
 
       function Get_32_Bit_Field_With_Default