aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/lib-xref.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2022-04-26 07:16:20 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-30 08:29:03 +0000
commit6a91be29578fa466376cd482d3abed5eb20685b4 (patch)
tree7a573ac16e3111a1521a3642275fce59a68a16ae /gcc/ada/lib-xref.adb
parent507ed659e0110e3cba9aa8bba875768833d7b7ea (diff)
downloadgcc-6a91be29578fa466376cd482d3abed5eb20685b4.zip
gcc-6a91be29578fa466376cd482d3abed5eb20685b4.tar.gz
gcc-6a91be29578fa466376cd482d3abed5eb20685b4.tar.bz2
[Ada] Avoid creating a finalization wrapper block for functions
This patch fixes a bug whereby if a function body has local objects that are finalizable, and has a return statement that requires generation of transient finalizable temps, and there are dynamic-sized objects requiring pushing/popping the (primary) stack at run time, and the function body has exception handlers, then incorrect code is generated. In particular, the transient objects are finalized after they have been deallocated. This can cause seg faults, corrupted heap, and the like. Note that if there are no dynamic-sized objects, then the bug does not occur, because the back end allocates objects of compile-time-known size based on where they are referenced, rather than which local block they are declared in. This patch relies on the fact that an At_End handler and regular exception handlers CAN coexist in the same handled statement sequence, which was not true some years ago. gcc/ada/ * exp_ch7.adb (Wrap_HSS_In_Block): Do not create a new block in the case of function bodies. We include all subprogram bodies, because it's harmless for procedures. We cannot easily avoid creating this block in ALL cases, because some transformations of (e.g.) task bodies end up moving some code such that the wrong exception handlers apply to that code. (Build_Finalizer_Call): Remove code for creating a new block. This was unreachable code, given that Wrap_HSS_In_Block has already done that, but with the above change to Wrap_HSS_In_Block, this code becomes reachable, and triggers essentially the same bug. * exp_ch7.ads: Adjust comment.
Diffstat (limited to 'gcc/ada/lib-xref.adb')
0 files changed, 0 insertions, 0 deletions