From 6fe647ee3dd194e7ccbf230782da0c42134245be Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Fri, 22 Oct 2021 10:32:47 +0300 Subject: [PATCH] * moved the default procedure CurrRaiseLabel to the end of the procedure, not at the exit label. This fixes problems when using units with finalization code that contain classes with class destructors in branchful WebAssembly exceptions mode. --- compiler/wasm32/cpupi.pas | 2 -- compiler/wasm32/hlcgcpu.pas | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/wasm32/cpupi.pas b/compiler/wasm32/cpupi.pas index 8deb18eeb4..0db46688c8 100644 --- a/compiler/wasm32/cpupi.pas +++ b/compiler/wasm32/cpupi.pas @@ -353,8 +353,6 @@ implementation list.concat(taicpu.op_none(a_end_block)); thlcgwasm(hlcg).decblock; inherited generate_exit_label(list); - if ts_wasm_bf_exceptions in current_settings.targetswitches then - hlcg.a_label(list,CurrRaiseLabel); end; procedure tcpuprocinfo.postprocess_code; diff --git a/compiler/wasm32/hlcgcpu.pas b/compiler/wasm32/hlcgcpu.pas index 4ccd3bbf4f..10e43447e7 100644 --- a/compiler/wasm32/hlcgcpu.pas +++ b/compiler/wasm32/hlcgcpu.pas @@ -2191,10 +2191,16 @@ implementation inherited; list.concat(taicpu.op_none(a_block)); incblock; + list.concat(taicpu.op_none(a_block)); + incblock; end; procedure thlcgwasm.gen_exit_code(list: TAsmList); begin + list.concat(taicpu.op_none(a_end_block)); + thlcgwasm(hlcg).decblock; + if ts_wasm_bf_exceptions in current_settings.targetswitches then + a_label(list,tcpuprocinfo(current_procinfo).CurrRaiseLabel); if fevalstackheight<>0 then {$ifdef DEBUG_WASMSTACK} list.concat(tai_comment.Create(strpnew('!!! values remaining on stack at end of block !!!')));