compiler: don't generate code for empty initialization and finalization sections (with help of Florian) (issue #0013482)

git-svn-id: trunk@14543 -
This commit is contained in:
paul 2010-01-05 16:07:37 +00:00
parent 95ccc3ea40
commit 8b27daae2c
2 changed files with 23 additions and 15 deletions

View File

@ -1209,7 +1209,7 @@ implementation
if not current_module.interface_only and (token=_FINALIZATION) then if not current_module.interface_only and (token=_FINALIZATION) then
begin begin
{ set module options } { set module options }
current_module.flags:=current_module.flags or uf_finalize; // current_module.flags:=current_module.flags or uf_finalize;
{ Compile the finalize } { Compile the finalize }
finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable); finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable);
@ -2138,7 +2138,7 @@ implementation
if token=_FINALIZATION then if token=_FINALIZATION then
begin begin
{ set module options } { set module options }
current_module.flags:=current_module.flags or uf_finalize; //current_module.flags:=current_module.flags or uf_finalize;
{ Parse the finalize } { Parse the finalize }
finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable); finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable);
finalize_procinfo.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,'')); finalize_procinfo.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));

View File

@ -207,21 +207,29 @@ implementation
begin begin
{ The library init code is already called and does not { The library init code is already called and does not
need to be in the initfinal table (PFV) } need to be in the initfinal table (PFV) }
if not islibrary then
current_module.flags:=current_module.flags or uf_init;
block:=statement_block(_INITIALIZATION); block:=statement_block(_INITIALIZATION);
end { optimize empty initialization block away }
else if (token=_FINALIZATION) then if (tstatementnode(block).left=nil) then
begin FreeAndNil(block)
if (current_module.flags and uf_finalize)<>0 then
block:=statement_block(_FINALIZATION)
else else
begin if not islibrary then
{ can we allow no INITIALIZATION for DLL ?? current_module.flags:=current_module.flags or uf_init;
I think it should work PM } end
block:=nil; else if token=_FINALIZATION then
exit; begin
end; { when a unit has only a finalization section, we can come to this
point when we try to read the nonh existing initalization section
so we've to check if we are really try to parse the finalization }
if current_procinfo.procdef.proctypeoption=potype_unitfinalize then
begin
block:=statement_block(_FINALIZATION);
{ optimize empty finalization block away }
if (tstatementnode(block).left=nil) then
FreeAndNil(block)
else
if not islibrary then
current_module.flags:=current_module.flags or uf_finalize;
end;
end end
else else
begin begin