From 3cb747f4a7e84d016ff715644d52706641cd5751 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 10 Nov 2013 20:20:27 +0000 Subject: [PATCH] * mark the node which is the entry of the user code with a flag * check for uninitialized variables at the node which is marked as the start of the user code git-svn-id: trunk@26014 - --- compiler/nbas.pas | 2 +- compiler/node.pas | 20 ++++++++++++++------ compiler/psub.pas | 32 +++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/compiler/nbas.pas b/compiler/nbas.pas index 5d359140b7..89b3a26a6c 100644 --- a/compiler/nbas.pas +++ b/compiler/nbas.pas @@ -547,7 +547,7 @@ implementation result:=tstatementnode(left).left; tstatementnode(left).left:=nil; { make sure the nf_block_with_exit flag is safeguarded } - result.flags:=result.flags+(flags * [nf_block_with_exit]); + result.flags:=result.flags+(flags*[nf_block_with_exit,nf_usercode_entry]); exit; end; end; diff --git a/compiler/node.pas b/compiler/node.pas index 9ef0d1cc0c..2f8ddaba76 100644 --- a/compiler/node.pas +++ b/compiler/node.pas @@ -207,18 +207,26 @@ interface type { all boolean field of ttree are now collected in flags } tnodeflag = ( - nf_swapable, { tbinop operands can be swaped } - nf_swapped, { tbinop operands are swaped } + { tbinop operands can be swaped } + nf_swapable, + { tbinop operands are swaped } + nf_swapped, nf_error, { general } nf_pass1_done, - nf_write, { Node is written to } - nf_modify, { Node is modified } + { Node is written to } + nf_write, + { Node is modified } + nf_modify, nf_is_funcret, nf_isproperty, nf_processing, - nf_no_lvalue, { Node cannot be assigned to } + { Node cannot be assigned to } + nf_no_lvalue, + { this node is the user code entry, if a node with this flag is removed + during simplify, the flag must be moved to another node } + nf_usercode_entry, { taddrnode } nf_typedaddr, @@ -268,7 +276,7 @@ interface { tloadvmtaddrnode } nf_ignore_for_wpo { we know that this loadvmtaddrnode cannot be used to construct a class instance } - { WARNING: there are now 31 elements in this type, and a set of this + { WARNING: there are now 32 elements in this type, and a set of this type is written to the PPU. So before adding more than 32 elements, either move some flags to specific nodes, or stream a normalset to the ppu diff --git a/compiler/psub.pas b/compiler/psub.pas index 8da8d5ddc7..a0d4fc2d5c 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -37,6 +37,8 @@ interface tcgprocinfo = class(tprocinfo) private procedure CreateInlineInfo; + { returns the node which is the start of the user code, this is needed by the dfa } + function GetUserCode: tnode; procedure maybe_add_constructor_wrapper(var tocode: tnode; withexceptblock: boolean); procedure add_entry_exit_code; procedure setup_tempgen; @@ -1139,6 +1141,30 @@ implementation end; + function searchusercode(var n: tnode; arg: pointer): foreachnoderesult; + begin + if nf_usercode_entry in n.flags then + begin + pnode(arg)^:=n; + result:=fen_norecurse_true + end + else + result:=fen_false; + end; + + + function TCGProcinfo.GetUserCode : tnode; + var + n : tnode; + begin + n:=nil; + foreachnodestatic(code,@searchusercode,@n); + if not(assigned(n)) then + internalerror(2013111001); + result:=n; + end; + + procedure tcgprocinfo.generate_code; var old_current_procinfo : tprocinfo; @@ -1179,6 +1205,10 @@ implementation current_filepos:=entrypos; current_structdef:=procdef.struct; + { store start of user code, it must be a block node, it will be used later one to + check variable lifeness } + include(code.flags,nf_usercode_entry); + { add wrapping code if necessary (initialization of typed constants on some platforms, initing of local variables and out parameters with trashing values, ... } @@ -1270,7 +1300,7 @@ implementation { iterate through life info of the first node } for i:=0 to dfabuilder.nodemap.count-1 do begin - if DFASetIn(code.optinfo^.life,i) then + if DFASetIn(GetUserCode.optinfo^.life,i) then case tnode(dfabuilder.nodemap[i]).nodetype of loadn: begin