From: Sheri Bernstein <bernst...@adacore.com> 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnarl/a-reatim.adb | 5 +++++ gcc/ada/libgnarl/s-tpopsp__posix-foreign.adb | 10 ++++------ gcc/ada/libgnat/s-imguti.adb | 10 ++++++++++ gcc/ada/libgnat/s-multip.adb | 5 +++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gcc/ada/libgnarl/a-reatim.adb b/gcc/ada/libgnarl/a-reatim.adb index 56a84789729..24a77311f9d 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 4b3e200150d..ebf0f622db0 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 4c8cf5f3295..2e69e630c8a 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 372f1407dbf..96177f9fc41 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; -- 2.40.0