From: Piotr Trojanek Date: Fri, 4 Sep 2020 12:51:02 +0000 (+0200) Subject: [Ada] Reject illegal syntax in pragma Contract_Cases X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48d0e61abad5d617205cddb6919c8f4ecc29c229;p=gcc.git [Ada] Reject illegal syntax in pragma Contract_Cases gcc/ada/ * contracts.adb (Analyze_Entry_Or_Subprogram_Contract, Analyze_Subprogram_Body_Stub_Contract): Fix missing references to Subprogram_Variant where similar references to Contract_Cases are present. * sem_prag.adb (Analyze_Contract_Case, Analyze_Variant): Check that aggregate parameter has no expressions. (Analyze_Pragma): Replace Contract_Cases with Subprogram_Variant in a copy-pasted comment. --- diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 20dafad5bff..9e328e248db 100644 --- a/gcc/ada/contracts.adb +++ b/gcc/ada/contracts.adb @@ -668,7 +668,7 @@ package body Contracts is end; end if; - -- Analyze contract-cases and test-cases + -- Analyze contract-cases, subprogram-variant and test-cases Prag := Contract_Test_Cases (Items); while Present (Prag) loop @@ -1432,6 +1432,7 @@ package body Contracts is -- Global -- Postcondition -- Precondition + -- Subprogram_Variant -- Test_Case else diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index 4edb67dff33..1e1a279da2e 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -549,7 +549,11 @@ package body Sem_Prag is pragma Assert (Nkind (CCases) = N_Aggregate); - if Present (Component_Associations (CCases)) then + -- Only CASE_GUARD => CONSEQUENCE clauses are allowed + + if Present (Component_Associations (CCases)) + and then No (Expressions (CCases)) + then -- Ensure that the formal parameters are visible when analyzing all -- clauses. This falls out of the general rule of aspects pertaining @@ -23900,7 +23904,7 @@ package body Sem_Prag is Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); -- Chain the pragma on the contract for further processing by - -- Analyze_Contract_Cases_In_Decl_Part. + -- Analyze_Subprogram_Variant_In_Decl_Part. Add_Contract_Item (N, Defining_Entity (Subp_Decl)); @@ -29048,7 +29052,11 @@ package body Sem_Prag is pragma Assert (Nkind (Variants) = N_Aggregate); - if Present (Component_Associations (Variants)) then + -- Only "change_direction => discrete_expression" clauses are allowed + + if Present (Component_Associations (Variants)) + and then No (Expressions (Variants)) + then -- Ensure that the formal parameters are visible when analyzing all -- clauses. This falls out of the general rule of aspects pertaining