]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Remove GNATcheck violations
authorSheri Bernstein <bernstein@adacore.com>
Fri, 1 Dec 2023 01:14:22 +0000 (01:14 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 19 Dec 2023 14:27:50 +0000 (15:27 +0100)
Remove GNATcheck violations by refactoring code and also using
pragma Annotate to exempt them.

gcc/ada/

* libgnat/a-comlin.adb (Argument_Count): Rewrite code so there is
only one return, to remove Improper_Returns violation.
(Command_Name): Add pragma to exempt Improper_Returns violation.

gcc/ada/libgnat/a-comlin.adb

index b95ecd3290c928ed72735cb8d491588d7ed1d015..8a6686181bdd7a8bdf07e0a5ba2ded7b553b0821 100644 (file)
@@ -77,16 +77,11 @@ package body Ada.Command_Line is
 
    function Argument_Count return Natural is
    begin
-      if not Initialized then
-         --  RM A.15 (11)
-         return 0;
-      end if;
-
-      if Remove_Args = null then
-         return Arg_Count - 1;
-      else
-         return Remove_Count;
-      end if;
+      return
+         (if not Initialized then 0  --  RM A.15 (11)
+          elsif Remove_Args = null then Arg_Count - 1
+          else Remove_Count
+         );
    end Argument_Count;
 
    -----------------
@@ -107,6 +102,8 @@ package body Ada.Command_Line is
 
    function Command_Name return String is
    begin
+      pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+                       "early returns for performance");
       if not Initialized then
          return "";
       end if;
@@ -118,6 +115,7 @@ package body Ada.Command_Line is
          Fill_Arg (Arg'Address, 0);
          return Arg;
       end;
+      pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
    end Command_Name;
 
 end Ada.Command_Line;