aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/libgnarl
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 /gcc/ada/libgnarl
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.
Diffstat (limited to 'gcc/ada/libgnarl')
-rw-r--r--gcc/ada/libgnarl/a-reatim.adb5
-rw-r--r--gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb10
2 files changed, 9 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;