From: Justin Squirek Date: Mon, 16 Jul 2018 14:11:04 +0000 (+0000) Subject: [Ada] Spurious possible contraint error warning with No_Exception_Propagation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=721500abf2b9d41bea8d2c91277c4ad5ab834db7;p=gcc.git [Ada] Spurious possible contraint error warning with No_Exception_Propagation This patch corrects an issue whereby spurious unhandled exception warnings on integer literals within static if and case expressions would be emitted when the restriction No_Exception_Propagation is enabled. ------------ -- Source -- ------------ -- gnat.adc pragma Restrictions (No_Exception_Propagation); pragma SPARK_Mode (On); -- pack.ads package Pack is procedure Filter (Ret : out Integer); end Pack; -- pack.adb package body Pack is subtype Nat is Integer range 0 .. 10; Default : constant Nat := 1; User_Override : constant Integer := -1; procedure Filter (Ret : out Integer) is Val : constant Nat := (if User_Override in Nat then User_Override else Default); begin Ret := Val; end Filter; end Pack; ---------------------------- -- Compilation and output -- ---------------------------- & gcc -c -gnatp -gnatwa pack.adb 2018-07-16 Justin Squirek gcc/ada/ * sem_eval.adb (Eval_Integer_Literal): Add exception for avoiding checks on expanded literals within if and case expressions. From-SVN: r262714 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a782582543e..6d8572debd0 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-07-16 Justin Squirek + + * sem_eval.adb (Eval_Integer_Literal): Add exception for avoiding + checks on expanded literals within if and case expressions. + 2018-07-16 Hristian Kirtchev * libgnat/s-wchwts.adb (Wide_String_To_String): Use the appropriate diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index a567143f448..ab85879374e 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -2720,16 +2720,23 @@ package body Sem_Eval is -- Start of processing for Eval_Integer_Literal begin - -- If the literal appears in a non-expression context, then it is -- certainly appearing in a non-static context, so check it. This is -- actually a redundant check, since Check_Non_Static_Context would -- check it, but it seems worthwhile to optimize out the call. - -- An exception is made for a literal in an if or case expression + -- Additionally, when the literal appears within an if or case + -- expression it must be checked as well. However, due to the literal + -- appearing within a conditional statement, expansion greatly changes + -- the nature of its context and performing some of the checks within + -- Check_Non_Static_Context on an expanded literal may lead to spurious + -- and misleading warnings. if (Nkind_In (Parent (N), N_If_Expression, N_Case_Expression_Alternative) or else Nkind (Parent (N)) not in N_Subexpr) + and then (not Nkind_In (Parent (N), N_If_Expression, + N_Case_Expression_Alternative) + or else Comes_From_Source (N)) and then not In_Any_Integer_Context then Check_Non_Static_Context (N);