aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSheri Bernstein <bernstein@adacore.com>2023-08-01 16:36:14 +0000
committerMarc Poulhiès <poulhies@adacore.com>2023-09-05 13:05:11 +0200
commit105891ca1beda7aecb2b637cc62f5c8a3ac49386 (patch)
tree99c79874cb37f833c549af5d9b274e83c6e80687
parent8950360830f0d7f5f356ec447e8493be7b98c2cb (diff)
downloadgcc-105891ca1beda7aecb2b637cc62f5c8a3ac49386.zip
gcc-105891ca1beda7aecb2b637cc62f5c8a3ac49386.tar.gz
gcc-105891ca1beda7aecb2b637cc62f5c8a3ac49386.tar.bz2
ada: Handle GNATcheck violations
For the GNATcheck rule "Improper_Returns", either use pragma Annotate to exempt the violation with the rationale "early returns for performance", or refactor the code by replacing multiple returns by a single return statement with a conditional expression; this is more readable and maintainable, and also conformant with a Highly Recommended design principle of ISO 26262-6. For the GNATcheck rule "Discriminated_Records", use pragma Annotate to exempt the violation with the rationale "only variant records are disallowed". gcc/ada/ * libgnarl/a-reatim.adb (Time_Of): Add pragma to exempt Discriminated_Records. * libgnat/s-imguti.adb (Round, Set_Decimal_Digits): Likewise. * libgnat/s-multip.adb (Number_Of_CPUs): Likewise. * libgnarl/s-tpopsp__posix-foreign.adb (Self): Refactor multiple returns.
-rw-r--r--gcc/ada/libgnarl/a-reatim.adb5
-rw-r--r--gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb10
-rw-r--r--gcc/ada/libgnat/s-imguti.adb10
-rw-r--r--gcc/ada/libgnat/s-multip.adb5
4 files changed, 24 insertions, 6 deletions
diff --git a/gcc/ada/libgnarl/a-reatim.adb b/gcc/ada/libgnarl/a-reatim.adb
index 56a8478..24a7731 100644
--- a/gcc/ada/libgnarl/a-reatim.adb
+++ b/gcc/ada/libgnarl/a-reatim.adb
@@ -307,6 +307,9 @@ is
-- Start of processing for Time_Of
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
+
-- If SC is so far out of range that there is no possibility of the
-- addition of TS getting it back in range, raise an exception right
-- away. That way we don't have to worry about SC values overflowing.
@@ -356,6 +359,8 @@ is
Out_Of_Range;
end if;
end if;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Time_Of;
-----------------
diff --git a/gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb b/gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb
index 4b3e200..ebf0f62 100644
--- a/gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb
+++ b/gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb
@@ -95,12 +95,10 @@ package body Specific is
Result := pthread_getspecific (ATCB_Key);
-- If the key value is Null then it is a non-Ada task
-
- if Result /= System.Null_Address then
- return To_Task_Id (Result);
- else
- return Register_Foreign_Thread;
- end if;
+ return
+ (if Result /= System.Null_Address then To_Task_Id (Result)
+ else Register_Foreign_Thread
+ );
end Self;
end Specific;
diff --git a/gcc/ada/libgnat/s-imguti.adb b/gcc/ada/libgnat/s-imguti.adb
index 4c8cf5f..2e69e63 100644
--- a/gcc/ada/libgnat/s-imguti.adb
+++ b/gcc/ada/libgnat/s-imguti.adb
@@ -119,6 +119,9 @@ package body System.Img_Util is
pragma Assert (Digs'First < Digs'Last);
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
+
-- Nothing to do if rounding past the last digit we have
if N >= LD then
@@ -178,6 +181,8 @@ package body System.Img_Util is
Digits_Before_Point := Digits_Before_Point + 1;
end if;
end if;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Round;
---------
@@ -246,6 +251,9 @@ package body System.Img_Util is
-- Start of processing for Set_Decimal_Digits
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
+
-- Case of exponent given
if Exp > 0 then
@@ -398,6 +406,8 @@ package body System.Img_Util is
end if;
end if;
end if;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Set_Decimal_Digits;
--------------------------------
diff --git a/gcc/ada/libgnat/s-multip.adb b/gcc/ada/libgnat/s-multip.adb
index 372f140..96177f9 100644
--- a/gcc/ada/libgnat/s-multip.adb
+++ b/gcc/ada/libgnat/s-multip.adb
@@ -36,6 +36,9 @@ package body System.Multiprocessors is
function Number_Of_CPUs return CPU is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
+
if CPU'Last = 1 then
return 1;
else
@@ -46,6 +49,8 @@ package body System.Multiprocessors is
return CPU (Gnat_Number_Of_CPUs);
end;
end if;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Number_Of_CPUs;
end System.Multiprocessors;