From: Yannick Moy Date: Thu, 31 May 2018 10:45:05 +0000 (+0000) Subject: [Ada] Fix check on placement of multiple loop (in)variant pragmas X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=01f481c77e01414e75fc26adead0d143b27df85d;p=gcc.git [Ada] Fix check on placement of multiple loop (in)variant pragmas Loop (in)variants should appear next to each other, which is checked by GNAT frontend. As statements inserted during expansion may break this contiguity, GNAT recognizes specially such statements which originate in loop pragmas. In some cases, this special treatment was not properly put in place, which lead to spurious errors being issued. 2018-05-31 Yannick Moy gcc/ada/ * sem_prag.adb (Analyze_Pragma.Check_Loop_Pragma_Placement): Inverse order of treatment between nodes recognized as loop pragmas (or generated from one) and block statements. From-SVN: r260996 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index bee06e3e791..e52386f6dfe 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2018-05-31 Yannick Moy + + * sem_prag.adb (Analyze_Pragma.Check_Loop_Pragma_Placement): Inverse + order of treatment between nodes recognized as loop pragmas (or + generated from one) and block statements. + 2018-05-31 Doug Rupp * libgnat/s-osprim__posix2008.adb (Clock): Implement using diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index abab195626b..b75b318d2ef 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -5931,23 +5931,9 @@ package body Sem_Prag is Stmt := First (L); while Present (Stmt) loop - -- Pragmas Loop_Invariant and Loop_Variant may only appear - -- inside a loop or a block housed inside a loop. Inspect - -- the declarations and statements of the block as they may - -- contain the first grouping. - - if Nkind (Stmt) = N_Block_Statement then - HSS := Handled_Statement_Sequence (Stmt); - - Check_Grouping (Declarations (Stmt)); - - if Present (HSS) then - Check_Grouping (Statements (HSS)); - end if; - -- First pragma of the first topmost grouping has been found - elsif Is_Loop_Pragma (Stmt) then + if Is_Loop_Pragma (Stmt) then -- The group and the current pragma are not in the same -- declarative or statement list. @@ -6004,6 +5990,24 @@ package body Sem_Prag is raise Program_Error; end if; + + -- Pragmas Loop_Invariant and Loop_Variant may only appear + -- inside a loop or a block housed inside a loop. Inspect + -- the declarations and statements of the block as they may + -- contain the first grouping. This case follows the one for + -- loop pragmas, as block statements which originate in a + -- loop pragma (and so Is_Loop_Pragma will return True on + -- that block statement) should be treated in the previous + -- case. + + elsif Nkind (Stmt) = N_Block_Statement then + HSS := Handled_Statement_Sequence (Stmt); + + Check_Grouping (Declarations (Stmt)); + + if Present (HSS) then + Check_Grouping (Statements (HSS)); + end if; end if; Next (Stmt);