aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2022-10-17 22:08:37 +0200
committerMarc Poulhiès <poulhies@adacore.com>2022-11-07 09:36:35 +0100
commitdc3208e698b2f424d892d3c9e5d5562ccde9e4cf (patch)
tree0eb9b46113774e074e28f4d0d29f64844926f8cc /gcc
parentd24f279c023051c95b88b8405ac8aa4ebb44b107 (diff)
downloadgcc-dc3208e698b2f424d892d3c9e5d5562ccde9e4cf.zip
gcc-dc3208e698b2f424d892d3c9e5d5562ccde9e4cf.tar.gz
gcc-dc3208e698b2f424d892d3c9e5d5562ccde9e4cf.tar.bz2
ada: Fix performance regression related to references in Refined_State
Recently added call to In_Pragma_Expression caused a performance regression. It might require climbing syntax trees of arbitrarily deep expressions, while previously references within pragmas were detected in bounded time. This patch restores the previous efficiency. However, while the original code only detected references directly within pragma argument associations, now we also detect references inside aggregates, e.g. like those in pragma Refined_State. gcc/ada/ * sem_prag.adb (Non_Significant_Pragma_Reference): Detect references with aggregates; only assign local variables Id and C when necessary.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/sem_prag.adb56
1 files changed, 29 insertions, 27 deletions
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index f33d858..2a3aca8 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31719,43 +31719,45 @@ package body Sem_Prag is
-- Start of processing for Non_Significant_Pragma_Reference
begin
- P := Parent (N);
-
- if Nkind (P) /= N_Pragma_Argument_Association then
+ -- Reference might appear either directly as expression of a pragma
+ -- argument association, e.g. pragma Export (...), or within an
+ -- aggregate with component associations, e.g. pragma Refined_State
+ -- ((... => ...)).
- -- References within pragma Refined_State are not significant. They
- -- can't be recognized using pragma argument number, because they
- -- appear inside refinement clauses that rely on aggregate syntax.
+ P := Parent (N);
+ loop
+ case Nkind (P) is
+ when N_Pragma_Argument_Association =>
+ exit;
+ when N_Aggregate | N_Component_Association =>
+ P := Parent (P);
+ when others =>
+ return False;
+ end case;
+ end loop;
- if In_Pragma_Expression (N, Name_Refined_State) then
- return True;
- end if;
+ AN := Arg_No;
+ if AN = 0 then
return False;
+ end if;
- else
- Id := Get_Pragma_Id (Parent (P));
- C := Sig_Flags (Id);
- AN := Arg_No;
+ Id := Get_Pragma_Id (Parent (P));
+ C := Sig_Flags (Id);
- if AN = 0 then
+ case C is
+ when -1 =>
return False;
- end if;
-
- case C is
- when -1 =>
- return False;
- when 0 =>
- return True;
+ when 0 =>
+ return True;
- when 92 .. 99 =>
- return AN < (C - 90);
+ when 92 .. 99 =>
+ return AN < (C - 90);
- when others =>
- return AN /= C;
- end case;
- end if;
+ when others =>
+ return AN /= C;
+ end case;
end Is_Non_Significant_Pragma_Reference;
------------------------------