mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-03 10:29:37 +01:00
* proper initialised/used warnings for variables used
in complex with-statements + tests git-svn-id: trunk@6024 -
This commit is contained in:
parent
fc0bb654c1
commit
f2b07704b5
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -5665,6 +5665,8 @@ tests/tbf/tb0192.pp svneol=native#text/plain
|
||||
tests/tbf/tb0193.pp svneol=native#text/plain
|
||||
tests/tbf/tb0194.pp svneol=native#text/plain
|
||||
tests/tbf/tb0195.pp svneol=native#text/plain
|
||||
tests/tbf/tb0196.pp svneol=native#text/plain
|
||||
tests/tbf/tb0197.pp svneol=native#text/plain
|
||||
tests/tbf/ub0115.pp svneol=native#text/plain
|
||||
tests/tbf/ub0149.pp svneol=native#text/plain
|
||||
tests/tbf/ub0158a.pp svneol=native#text/plain
|
||||
@ -6186,6 +6188,7 @@ tests/tbs/tb0521.pp svneol=native#text/plain
|
||||
tests/tbs/tb0522.pp svneol=native#text/plain
|
||||
tests/tbs/tb0523.pp svneol=native#text/plain
|
||||
tests/tbs/tb0524.pp svneol=native#text/x-pascal
|
||||
tests/tbs/tb0525.pp svneol=native#text/plain
|
||||
tests/tbs/ub0060.pp svneol=native#text/plain
|
||||
tests/tbs/ub0069.pp svneol=native#text/plain
|
||||
tests/tbs/ub0119.pp svneol=native#text/plain
|
||||
|
||||
@ -775,7 +775,7 @@ implementation
|
||||
{ vs_read_not_warned -> ... }
|
||||
(vs_none,vs_read_not_warned,vs_read,vs_read,vs_read_not_warned,vs_read_not_warned,vs_readwritten,vs_readwritten),
|
||||
{ vs_referred_not_inited }
|
||||
(vs_none,vs_referred_not_inited,vs_read,vs_read,vs_read,vs_referred_not_inited,vs_readwritten,vs_readwritten),
|
||||
(vs_none,vs_referred_not_inited,vs_read,vs_read,vs_read_not_warned,vs_referred_not_inited,vs_written,vs_readwritten),
|
||||
{ vs_written -> ... }
|
||||
(vs_none,vs_written,vs_written,vs_readwritten,vs_readwritten,vs_written,vs_written,vs_readwritten),
|
||||
{ vs_readwritten -> ... }
|
||||
@ -791,6 +791,14 @@ implementation
|
||||
while assigned(p) do
|
||||
begin
|
||||
case p.nodetype of
|
||||
derefn:
|
||||
begin
|
||||
if (tderefnode(p).left.nodetype=temprefn) and
|
||||
assigned(ttemprefnode(tderefnode(p).left).tempinfo^.withnode) then
|
||||
p:=ttemprefnode(tderefnode(p).left).tempinfo^.withnode
|
||||
else
|
||||
break;
|
||||
end;
|
||||
typeconvn :
|
||||
begin
|
||||
case ttypeconvnode(p).convtype of
|
||||
|
||||
@ -104,10 +104,11 @@ interface
|
||||
typedefderef : tderef;
|
||||
temptype : ttemptype;
|
||||
owner : ttempcreatenode;
|
||||
withnode : tnode;
|
||||
location : tlocation;
|
||||
may_be_in_reg : boolean;
|
||||
valid : boolean;
|
||||
nextref_set_hookoncopy_nil : boolean;
|
||||
location : tlocation;
|
||||
end;
|
||||
|
||||
{ a node which will create a (non)persistent temp of a given type with a given }
|
||||
@ -123,10 +124,12 @@ interface
|
||||
{ freeing it. In this last case, you must use only one reference }
|
||||
{ to it and *not* generate a ttempdeletenode }
|
||||
constructor create(_typedef: tdef; _size: aint; _temptype: ttemptype;allowreg:boolean); virtual;
|
||||
constructor create_withnode(_typedef: tdef; _size: aint; _temptype: ttemptype; allowreg:boolean; withnode: tnode); virtual;
|
||||
constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
|
||||
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
||||
procedure buildderefimpl;override;
|
||||
procedure derefimpl;override;
|
||||
procedure derefnode;override;
|
||||
function dogetcopy: tnode; override;
|
||||
function pass_1 : tnode; override;
|
||||
function pass_typecheck: tnode; override;
|
||||
@ -632,7 +635,8 @@ implementation
|
||||
fillchar(tempinfo^,sizeof(tempinfo^),0);
|
||||
tempinfo^.typedef := _typedef;
|
||||
tempinfo^.temptype := _temptype;
|
||||
tempinfo^.owner:=self;
|
||||
tempinfo^.owner := self;
|
||||
tempinfo^.withnode := nil;
|
||||
tempinfo^.may_be_in_reg:=
|
||||
allowreg and
|
||||
{ temp must fit a single register }
|
||||
@ -647,6 +651,13 @@ implementation
|
||||
(not tpointerdef(_typedef).pointeddef.needs_inittable));
|
||||
end;
|
||||
|
||||
constructor ttempcreatenode.create_withnode(_typedef: tdef; _size: aint; _temptype: ttemptype; allowreg:boolean; withnode: tnode);
|
||||
begin
|
||||
self.create(_typedef,_size,_temptype,allowreg);
|
||||
tempinfo^.withnode:=withnode.getcopy;
|
||||
end;
|
||||
|
||||
|
||||
function ttempcreatenode.dogetcopy: tnode;
|
||||
var
|
||||
n: ttempcreatenode;
|
||||
@ -659,6 +670,10 @@ implementation
|
||||
n.tempinfo^.owner:=n;
|
||||
n.tempinfo^.typedef := tempinfo^.typedef;
|
||||
n.tempinfo^.temptype := tempinfo^.temptype;
|
||||
if assigned(tempinfo^.withnode) then
|
||||
n.tempinfo^.withnode := tempinfo^.withnode.getcopy
|
||||
else
|
||||
n.tempinfo^.withnode := nil;
|
||||
|
||||
{ when the tempinfo has already a hookoncopy then it is not
|
||||
reset by a tempdeletenode }
|
||||
@ -686,6 +701,7 @@ implementation
|
||||
ppufile.getderef(tempinfo^.typedefderef);
|
||||
tempinfo^.temptype := ttemptype(ppufile.getbyte);
|
||||
tempinfo^.owner:=self;
|
||||
tempinfo^.withnode:=ppuloadnode(ppufile);
|
||||
end;
|
||||
|
||||
|
||||
@ -696,27 +712,44 @@ implementation
|
||||
ppufile.putbyte(byte(tempinfo^.may_be_in_reg));
|
||||
ppufile.putderef(tempinfo^.typedefderef);
|
||||
ppufile.putbyte(byte(tempinfo^.temptype));
|
||||
ppuwritenode(ppufile,tempinfo^.withnode);
|
||||
end;
|
||||
|
||||
|
||||
procedure ttempcreatenode.buildderefimpl;
|
||||
begin
|
||||
inherited buildderefimpl;
|
||||
tempinfo^.typedefderef.build(tempinfo^.typedef);
|
||||
if assigned(tempinfo^.withnode) then
|
||||
tempinfo^.withnode.buildderefimpl;
|
||||
end;
|
||||
|
||||
|
||||
procedure ttempcreatenode.derefimpl;
|
||||
begin
|
||||
inherited derefimpl;
|
||||
tempinfo^.typedef:=tdef(tempinfo^.typedefderef.resolve);
|
||||
if assigned(tempinfo^.withnode) then
|
||||
tempinfo^.withnode.derefimpl;
|
||||
end;
|
||||
|
||||
|
||||
procedure ttempcreatenode.derefnode;
|
||||
begin
|
||||
inherited derefnode;
|
||||
if assigned(tempinfo^.withnode) then
|
||||
tempinfo^.withnode.derefnode;
|
||||
end;
|
||||
|
||||
|
||||
function ttempcreatenode.pass_1 : tnode;
|
||||
begin
|
||||
result := nil;
|
||||
expectloc:=LOC_VOID;
|
||||
if (tempinfo^.typedef.needs_inittable) then
|
||||
include(current_procinfo.flags,pi_needs_implicit_finally);
|
||||
result := nil;
|
||||
expectloc:=LOC_VOID;
|
||||
if (tempinfo^.typedef.needs_inittable) then
|
||||
include(current_procinfo.flags,pi_needs_implicit_finally);
|
||||
if assigned(tempinfo^.withnode) then
|
||||
firstpass(tempinfo^.withnode);
|
||||
end;
|
||||
|
||||
|
||||
@ -725,6 +758,8 @@ implementation
|
||||
result := nil;
|
||||
{ a tempcreatenode doesn't have a resultdef, only temprefnodes do }
|
||||
resultdef := voidtype;
|
||||
if assigned(tempinfo^.withnode) then
|
||||
typecheckpass(tempinfo^.withnode);
|
||||
end;
|
||||
|
||||
|
||||
@ -734,6 +769,7 @@ implementation
|
||||
inherited docompare(p) and
|
||||
(ttempcreatenode(p).size = size) and
|
||||
(ttempcreatenode(p).tempinfo^.may_be_in_reg = tempinfo^.may_be_in_reg) and
|
||||
(ttempcreatenode(p).tempinfo^.withnode.isequal(tempinfo^.withnode)) and
|
||||
equal_defs(ttempcreatenode(p).tempinfo^.typedef,tempinfo^.typedef);
|
||||
end;
|
||||
|
||||
@ -818,6 +854,7 @@ implementation
|
||||
var
|
||||
temp : ttempcreatenode;
|
||||
begin
|
||||
inherited derefnode;
|
||||
temp:=ttempcreatenode(nodeppuidxget(tempidx));
|
||||
if temp.nodetype<>tempcreaten then
|
||||
internalerror(200311075);
|
||||
|
||||
@ -56,6 +56,7 @@ interface
|
||||
getprocvardefderef : tderef;
|
||||
constructor create(l : tnode);virtual;
|
||||
constructor create_internal(l : tnode); virtual;
|
||||
constructor create_internal_nomark(l : tnode); virtual;
|
||||
constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
|
||||
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
||||
procedure mark_write;override;
|
||||
@ -64,6 +65,8 @@ interface
|
||||
function dogetcopy : tnode;override;
|
||||
function pass_1 : tnode;override;
|
||||
function pass_typecheck:tnode;override;
|
||||
private
|
||||
mark_read_written: boolean;
|
||||
end;
|
||||
taddrnodeclass = class of taddrnode;
|
||||
|
||||
@ -275,6 +278,7 @@ implementation
|
||||
begin
|
||||
inherited create(addrn,l);
|
||||
getprocvardef:=nil;
|
||||
mark_read_written := true;
|
||||
end;
|
||||
|
||||
|
||||
@ -285,6 +289,13 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
constructor taddrnode.create_internal_nomark(l : tnode);
|
||||
begin
|
||||
self.create_internal(l);
|
||||
mark_read_written := false;
|
||||
end;
|
||||
|
||||
|
||||
constructor taddrnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
|
||||
begin
|
||||
inherited ppuload(t,ppufile);
|
||||
@ -445,17 +456,21 @@ implementation
|
||||
CGMessage(type_e_variable_id_expected);
|
||||
end;
|
||||
|
||||
{ this is like the function addr }
|
||||
inc(parsing_para_level);
|
||||
{ This is actually only "read", but treat it nevertheless as }
|
||||
{ modified due to the possible use of pointers }
|
||||
{ To avoid false positives regarding "uninitialised" }
|
||||
{ warnings when using arrays, perform it in two steps }
|
||||
set_varstate(left,vs_written,[]);
|
||||
{ vsf_must_be_valid so it doesn't get changed into }
|
||||
{ vsf_referred_not_inited }
|
||||
set_varstate(left,vs_read,[vsf_must_be_valid]);
|
||||
dec(parsing_para_level);
|
||||
if (mark_read_written) then
|
||||
begin
|
||||
{ this is like the function addr }
|
||||
inc(parsing_para_level);
|
||||
|
||||
{ This is actually only "read", but treat it nevertheless as }
|
||||
{ modified due to the possible use of pointers }
|
||||
{ To avoid false positives regarding "uninitialised" }
|
||||
{ warnings when using arrays, perform it in two steps }
|
||||
set_varstate(left,vs_written,[]);
|
||||
{ vsf_must_be_valid so it doesn't get changed into }
|
||||
{ vsf_referred_not_inited }
|
||||
set_varstate(left,vs_read,[vsf_must_be_valid]);
|
||||
dec(parsing_para_level);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ type
|
||||
{$endif Test_Double_checksum}
|
||||
|
||||
const
|
||||
CurrentPPUVersion=73;
|
||||
CurrentPPUVersion=74;
|
||||
|
||||
{ buffer sizes }
|
||||
maxentrysize = 1024;
|
||||
|
||||
@ -526,7 +526,7 @@ implementation
|
||||
else
|
||||
hdef:=tpointerdef.create(p.resultdef);
|
||||
{ load address of the value in a temp }
|
||||
tempnode:=ctempcreatenode.create(hdef,sizeof(aint),tt_persistent,true);
|
||||
tempnode:=ctempcreatenode.create_withnode(hdef,sizeof(aint),tt_persistent,true,p);
|
||||
typecheckpass(tempnode);
|
||||
valuenode:=p;
|
||||
refnode:=ctemprefnode.create(tempnode);
|
||||
@ -535,7 +535,7 @@ implementation
|
||||
is not done implicitly }
|
||||
if not hasimplicitderef then
|
||||
begin
|
||||
valuenode:=caddrnode.create_internal(valuenode);
|
||||
valuenode:=caddrnode.create_internal_nomark(valuenode);
|
||||
refnode:=cderefnode.create(refnode);
|
||||
fillchar(refnode.fileinfo,sizeof(tfileposinfo),0);
|
||||
end;
|
||||
|
||||
21
tests/tbf/tb0196.pp
Normal file
21
tests/tbf/tb0196.pp
Normal file
@ -0,0 +1,21 @@
|
||||
{ %norun }
|
||||
{ %fail }
|
||||
{ %opt=-Sen }
|
||||
|
||||
type
|
||||
tr = record
|
||||
x, y: longint;
|
||||
end;
|
||||
ta = array[1..10] of tr;
|
||||
|
||||
var
|
||||
a: ta;
|
||||
i: longint;
|
||||
begin
|
||||
for i := low(a) to high(a) do
|
||||
with a[i] do
|
||||
begin
|
||||
x:=i*2;
|
||||
y:=i+5;
|
||||
end;
|
||||
end.
|
||||
21
tests/tbf/tb0197.pp
Normal file
21
tests/tbf/tb0197.pp
Normal file
@ -0,0 +1,21 @@
|
||||
{ %norun }
|
||||
{ %fail }
|
||||
{ %opt=-Sew }
|
||||
|
||||
type
|
||||
tr = record
|
||||
x, y: longint;
|
||||
end;
|
||||
ta = array[1..10] of tr;
|
||||
|
||||
var
|
||||
a: ta;
|
||||
i: longint;
|
||||
begin
|
||||
for i := low(a) to high(a) do
|
||||
with a[i] do
|
||||
begin
|
||||
x:=i*2+y;
|
||||
y:=i+5;
|
||||
end;
|
||||
end.
|
||||
20
tests/tbs/tb0525.pp
Normal file
20
tests/tbs/tb0525.pp
Normal file
@ -0,0 +1,20 @@
|
||||
{ %norun }
|
||||
{ %opt=-Sen }
|
||||
|
||||
type
|
||||
tr = record
|
||||
x, y: longint;
|
||||
end;
|
||||
ta = array[1..10] of tr;
|
||||
|
||||
var
|
||||
a: ta;
|
||||
i: longint;
|
||||
begin
|
||||
for i := low(a) to high(a) do
|
||||
with a[i] do
|
||||
begin
|
||||
x:=i*2;
|
||||
y:=i+5+x;
|
||||
end;
|
||||
end.
|
||||
Loading…
Reference in New Issue
Block a user