* ttryfinallynode now inherits from tbinarynode instead of tloopnode, as its

t1 field was always set to tnothingnode

git-svn-id: trunk@40142 -
This commit is contained in:
Jonas Maebe 2018-11-01 13:19:33 +00:00
parent cc44f64920
commit 0cd85d73e4
7 changed files with 17 additions and 52 deletions

View File

@ -44,7 +44,7 @@ interface
ti386tryfinallynode=class(tcgtryfinallynode) ti386tryfinallynode=class(tcgtryfinallynode)
finalizepi: tcgprocinfo; finalizepi: tcgprocinfo;
constructor create(l,r:TNode);override; constructor create(l,r:TNode);override;
constructor create_implicit(l,r,_t1:TNode);override; constructor create_implicit(l,r:TNode);override;
function pass_1: tnode;override; function pass_1: tnode;override;
function simplify(forinline: boolean): tnode;override; function simplify(forinline: boolean): tnode;override;
procedure pass_generate_code;override; procedure pass_generate_code;override;
@ -183,9 +183,9 @@ constructor ti386tryfinallynode.create(l, r: TNode);
include(finalizepi.flags,pi_uses_exceptions); include(finalizepi.flags,pi_uses_exceptions);
end; end;
constructor ti386tryfinallynode.create_implicit(l, r, _t1: TNode); constructor ti386tryfinallynode.create_implicit(l, r: TNode);
begin begin
inherited create_implicit(l, r, _t1); inherited create_implicit(l, r);
if (target_info.system<>system_i386_win32) then if (target_info.system<>system_i386_win32) then
exit; exit;

View File

@ -1183,11 +1183,6 @@ implementation
{ finally code only needed to be executed on exception (-> in { finally code only needed to be executed on exception (-> in
if-branch -> fc_inflowcontrol) } if-branch -> fc_inflowcontrol) }
flowcontrol:=[fc_inflowcontrol]; flowcontrol:=[fc_inflowcontrol];
secondpass(t1);
if flowcontrol<>[fc_inflowcontrol] then
CGMessage(cg_e_control_flow_outside_finally);
if codegenerror then
exit;
if (tf_safecall_exceptions in target_info.flags) and if (tf_safecall_exceptions in target_info.flags) and
(current_procinfo.procdef.proccalloption=pocall_safecall) then (current_procinfo.procdef.proccalloption=pocall_safecall) then
handle_safecall_exception handle_safecall_exception

View File

@ -189,10 +189,10 @@ interface
end; end;
ttryexceptnodeclass = class of ttryexceptnode; ttryexceptnodeclass = class of ttryexceptnode;
ttryfinallynode = class(tloopnode) ttryfinallynode = class(tbinarynode)
implicitframe : boolean; implicitframe : boolean;
constructor create(l,r:tnode);virtual;reintroduce; constructor create(l,r:tnode);virtual;reintroduce;
constructor create_implicit(l,r,_t1:tnode);virtual; constructor create_implicit(l,r:tnode);virtual;
function pass_typecheck:tnode;override; function pass_typecheck:tnode;override;
function pass_1 : tnode;override; function pass_1 : tnode;override;
function simplify(forinline:boolean): tnode;override; function simplify(forinline:boolean): tnode;override;
@ -2299,14 +2299,14 @@ implementation
constructor ttryfinallynode.create(l,r:tnode); constructor ttryfinallynode.create(l,r:tnode);
begin begin
inherited create(tryfinallyn,l,r,nil,nil); inherited create(tryfinallyn,l,r);
implicitframe:=false; implicitframe:=false;
end; end;
constructor ttryfinallynode.create_implicit(l,r,_t1:tnode); constructor ttryfinallynode.create_implicit(l,r:tnode);
begin begin
inherited create(tryfinallyn,l,r,_t1,nil); inherited create(tryfinallyn,l,r);
implicitframe:=true; implicitframe:=true;
end; end;
@ -2323,14 +2323,6 @@ implementation
typecheckpass(right); typecheckpass(right);
// "except block" is "used"? (JM) // "except block" is "used"? (JM)
set_varstate(right,vs_readwritten,[vsf_must_be_valid]); set_varstate(right,vs_readwritten,[vsf_must_be_valid]);
{ special finally block only executed when there was an exception }
if assigned(t1) then
begin
typecheckpass(t1);
// "finally block" is "used"? (JM)
set_varstate(t1,vs_readwritten,[vsf_must_be_valid]);
end;
end; end;
@ -2342,9 +2334,6 @@ implementation
firstpass(right); firstpass(right);
if assigned(t1) then
firstpass(t1);
include(current_procinfo.flags,pi_do_call); include(current_procinfo.flags,pi_do_call);
{ pi_uses_exceptions is an information for the optimizer and it { pi_uses_exceptions is an information for the optimizer and it

View File

@ -196,7 +196,7 @@ implementation
result := foreachnode(procmethod,tcallnode(n).funcretnode,f,arg) or result; result := foreachnode(procmethod,tcallnode(n).funcretnode,f,arg) or result;
result := foreachnode(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result; result := foreachnode(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result;
end; end;
ifn, whilerepeatn, forn, tryexceptn, tryfinallyn: ifn, whilerepeatn, forn, tryexceptn:
begin begin
{ not in one statement, won't work because of b- } { not in one statement, won't work because of b- }
result := foreachnode(procmethod,tloopnode(n).t1,f,arg) or result; result := foreachnode(procmethod,tloopnode(n).t1,f,arg) or result;
@ -293,7 +293,7 @@ implementation
result := foreachnodestatic(procmethod,tcallnode(n).funcretnode,f,arg) or result; result := foreachnodestatic(procmethod,tcallnode(n).funcretnode,f,arg) or result;
result := foreachnodestatic(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result; result := foreachnodestatic(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result;
end; end;
ifn, whilerepeatn, forn, tryexceptn, tryfinallyn: ifn, whilerepeatn, forn, tryexceptn:
begin begin
{ not in one statement, won't work because of b- } { not in one statement, won't work because of b- }
result := foreachnodestatic(procmethod,tloopnode(n).t1,f,arg) or result; result := foreachnodestatic(procmethod,tloopnode(n).t1,f,arg) or result;

View File

@ -43,7 +43,7 @@ type
{$endif Test_Double_checksum} {$endif Test_Double_checksum}
const const
CurrentPPUVersion = 202; CurrentPPUVersion = 203;
{ unit flags } { unit flags }
uf_init = $000001; { unit has initialization section } uf_init = $000001; { unit has initialization section }

View File

@ -919,10 +919,7 @@ implementation
final_used:=true; final_used:=true;
current_filepos:=entrypos; current_filepos:=entrypos;
wrappedbody:=ctryfinallynode.create_implicit( wrappedbody:=ctryfinallynode.create_implicit(code,finalcode);
code,
finalcode,
cnothingnode.create);
{ afterconstruction must be called after final_asmnode, because it { afterconstruction must be called after final_asmnode, because it
has to execute after the temps have been finalised in case of a has to execute after the temps have been finalised in case of a
refcounted class (afterconstruction decreases the refcount refcounted class (afterconstruction decreases the refcount

View File

@ -44,7 +44,7 @@ interface
tx64tryfinallynode=class(tcgtryfinallynode) tx64tryfinallynode=class(tcgtryfinallynode)
finalizepi: tcgprocinfo; finalizepi: tcgprocinfo;
constructor create(l,r:TNode);override; constructor create(l,r:TNode);override;
constructor create_implicit(l,r,_t1:TNode);override; constructor create_implicit(l,r:TNode);override;
function simplify(forinline: boolean): tnode;override; function simplify(forinline: boolean): tnode;override;
procedure pass_generate_code;override; procedure pass_generate_code;override;
end; end;
@ -176,9 +176,9 @@ constructor tx64tryfinallynode.create(l, r: TNode);
end; end;
end; end;
constructor tx64tryfinallynode.create_implicit(l, r, _t1: TNode); constructor tx64tryfinallynode.create_implicit(l, r: TNode);
begin begin
inherited create_implicit(l, r, _t1); inherited create_implicit(l, r);
if (target_info.system=system_x86_64_win64) then if (target_info.system=system_x86_64_win64) then
begin begin
if df_generic in current_procinfo.procdef.defoptions then if df_generic in current_procinfo.procdef.defoptions then
@ -254,8 +254,8 @@ procedure tx64tryfinallynode.pass_generate_code;
{ Do not generate a frame that catches exceptions if the only action { Do not generate a frame that catches exceptions if the only action
would be reraising it. Doing so is extremely inefficient with SEH would be reraising it. Doing so is extremely inefficient with SEH
(in contrast with setjmp/longjmp exception handling) } (in contrast with setjmp/longjmp exception handling) }
catch_frame:=implicitframe and ((not has_no_code(t1)) or catch_frame:=implicitframe and
(current_procinfo.procdef.proccalloption=pocall_safecall)); (current_procinfo.procdef.proccalloption=pocall_safecall);
oldflowcontrol:=flowcontrol; oldflowcontrol:=flowcontrol;
flowcontrol:=[fc_inflowcontrol]; flowcontrol:=[fc_inflowcontrol];
@ -458,28 +458,12 @@ procedure tx64tryexceptnode.pass_generate_code;
inc(onnodecount.value); inc(onnodecount.value);
hnode:=tonnode(hnode).left; hnode:=tonnode(hnode).left;
end; end;
{ add 'else' node to the filter list, too }
if assigned(t1) then
begin
hlist.concat(tai_const.create_32bit(-1));
hlist.concat(tai_const.create_rva_sym(lastonlabel));
inc(onnodecount.value);
end;
{ now move filter table to permanent list all at once } { now move filter table to permanent list all at once }
current_procinfo.aktlocaldata.concatlist(hlist); current_procinfo.aktlocaldata.concatlist(hlist);
hlist.free; hlist.free;
end; end;
cg.a_label(current_asmdata.CurrAsmList,lastonlabel); cg.a_label(current_asmdata.CurrAsmList,lastonlabel);
if assigned(t1) then
begin
{ here we don't have to reset flowcontrol }
{ the default and on flowcontrols are handled equal }
secondpass(t1);
cg.g_call(current_asmdata.CurrAsmList,'FPC_DONEEXCEPTION');
if (flowcontrol*[fc_exit,fc_break,fc_continue]<>[]) then
cg.a_jmp_always(current_asmdata.CurrAsmList,endexceptlabel);
end;
exceptflowcontrol:=flowcontrol; exceptflowcontrol:=flowcontrol;
if fc_exit in exceptflowcontrol then if fc_exit in exceptflowcontrol then