diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2020-09-04 14:51:02 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-10-23 04:25:04 -0400 |
commit | 48d0e61abad5d617205cddb6919c8f4ecc29c229 (patch) | |
tree | 909784bf7803a364eaee448688a29990289c7d9a | |
parent | 973c7b7e5460866099ba3904ae29808674604f0e (diff) | |
download | gcc-48d0e61abad5d617205cddb6919c8f4ecc29c229.zip gcc-48d0e61abad5d617205cddb6919c8f4ecc29c229.tar.gz gcc-48d0e61abad5d617205cddb6919c8f4ecc29c229.tar.bz2 |
[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.
-rw-r--r-- | gcc/ada/contracts.adb | 3 | ||||
-rw-r--r-- | gcc/ada/sem_prag.adb | 14 |
2 files changed, 13 insertions, 4 deletions
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb index 20dafad..9e328e2 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 4edb67d..1e1a279 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 |