From ed27b86ba18a1ffed8ae002412250f0765ab3e72 Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Thu, 11 Jan 2018 08:54:26 +0000 Subject: [PATCH] [Ada] Missing diagnostic of categorization dependency This patch modifies the analysis of subprogram bodies to catch a case where a pure subprogram body unit depends on non-pure units. 2018-01-11 Hristian Kirtchev gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Check the categorization of a subprogram body which does not complete a previous declaration. gcc/testsuite/ * gnat.dg/pure_subp_body.adb, gnat.dg/pure_subp_body_pkg.ads: New testcase. From-SVN: r256516 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/sem_ch6.adb | 8 +++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/pure_subp_body.adb | 12 ++++++++++++ gcc/testsuite/gnat.dg/pure_subp_body_pkg.ads | 2 ++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/pure_subp_body.adb create mode 100644 gcc/testsuite/gnat.dg/pure_subp_body_pkg.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 2bc53d7f8dc..fd0a8d33624 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-01-11 Hristian Kirtchev + + * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Check the + categorization of a subprogram body which does not complete a previous + declaration. + 2018-01-11 Hristian Kirtchev * sem_ch10.adb (Check_Private_Child_Unit): Ensure that the enclosing diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 1c0495f6512..186467d9cb3 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -4463,6 +4463,12 @@ package body Sem_Ch6 is Set_First_Entity (Spec_Id, Empty); Set_Last_Entity (Spec_Id, Empty); end if; + + -- Otherwise the body does not complete a previous declaration. Check + -- the categorization of the body against the units it withs. + + else + Validate_Categorization_Dependency (N, Body_Id); end if; Check_Missing_Return; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3bbd01c745e..e5b1c350c78 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-11 Hristian Kirtchev + + * gnat.dg/pure_subp_body.adb, gnat.dg/pure_subp_body_pkg.ads: New + testcase. + 2018-01-11 Bob Duff * gnat.dg/protected_null.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/pure_subp_body.adb b/gcc/testsuite/gnat.dg/pure_subp_body.adb new file mode 100644 index 00000000000..31bf1061d08 --- /dev/null +++ b/gcc/testsuite/gnat.dg/pure_subp_body.adb @@ -0,0 +1,12 @@ +-- { dg-do compile } + +with Pure_Subp_Body_Pkg; + +procedure Pure_Subp_Body with Pure is +begin + null; +end Pure_Subp_Body; + +-- cannot depend on "Pure_Subp_Body_Pkg" (wrong categorization) +-- { dg-error "cannot depend on \"Pure_Subp_Body_Pkg\" \\(wrong categorization\\)" "" { target *-*-* } 3 } +-- { dg-error "pure unit cannot depend on non-pure unit" "non-pure unit" { target *-*-* } 3 } diff --git a/gcc/testsuite/gnat.dg/pure_subp_body_pkg.ads b/gcc/testsuite/gnat.dg/pure_subp_body_pkg.ads new file mode 100644 index 00000000000..b10db0a2f4a --- /dev/null +++ b/gcc/testsuite/gnat.dg/pure_subp_body_pkg.ads @@ -0,0 +1,2 @@ +package Pure_Subp_Body_Pkg is +end Pure_Subp_Body_Pkg;