add warning for arithmetic on untyped pointers

git-svn-id: trunk@4823 -
This commit is contained in:
micha 2006-10-07 19:34:16 +00:00
parent 0c669fbad0
commit 5f353d6fef
4 changed files with 26 additions and 23 deletions

View File

@ -1183,10 +1183,16 @@ implementation
if (cs_extsyntax in aktmoduleswitches) then
begin
if is_voidpointer(right.resulttype.def) then
begin
if is_untyped_addrnode(right) then
CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
inserttypeconv(right,left.resulttype)
else if is_voidpointer(left.resulttype.def) then
end else if is_voidpointer(left.resulttype.def) then
begin
if is_untyped_addrnode(left) then
CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
inserttypeconv(left,right.resulttype)
else if not(equal_defs(ld,rd)) then
end else if not(equal_defs(ld,rd)) then
IncompatibleTypes(ld,rd);
end
else
@ -1202,22 +1208,6 @@ implementation
resulttype:=sinttype;
exit;
end;
addn:
begin
if (cs_extsyntax in aktmoduleswitches) then
begin
if is_voidpointer(right.resulttype.def) then
inserttypeconv(right,left.resulttype)
else if is_voidpointer(left.resulttype.def) then
inserttypeconv(left,right.resulttype)
else if not(equal_defs(ld,rd)) then
IncompatibleTypes(ld,rd);
end
else
CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
resulttype:=sinttype;
exit;
end;
else
CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
end;
@ -1459,13 +1449,16 @@ implementation
if not(cs_extsyntax in aktmoduleswitches) or
(not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
if (ld.deftype=pointerdef) and
(tpointerdef(ld).pointertype.def.size>1) then
if (ld.deftype=pointerdef) then
begin
if is_untyped_addrnode(left) then
CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
if (tpointerdef(ld).pointertype.def.size>1) then
begin
right:=caddnode.create(muln,right,
cordconstnode.create(tpointerdef(ld).pointertype.def.size,sinttype,true));
end
else
end else
if is_zero_based_array(ld) and
(tarraydef(ld).elementtype.def.size>1) then
begin

View File

@ -1520,6 +1520,8 @@ implementation
if convtype in [tc_equal,tc_not_possible] then
begin
left.resulttype:=resulttype;
if (nf_explicit in flags) and (left.nodetype = addrn) then
include(left.flags, nf_typedaddr);
result:=left;
left:=nil;
exit;

View File

@ -425,6 +425,7 @@ interface
function is_constboolnode(p : tnode) : boolean;
function is_constenumnode(p : tnode) : boolean;
function is_constwidecharnode(p : tnode) : boolean;
function is_untyped_addrnode(p: tnode): boolean;
implementation
@ -628,6 +629,11 @@ implementation
is_constenumnode:=(p.nodetype=ordconstn) and (p.resulttype.def.deftype=enumdef);
end;
function is_untyped_addrnode(p: tnode): boolean;
begin
is_untyped_addrnode:=(p.nodetype=addrn) and not (nf_typedaddr in p.flags);
end;
{****************************************************************************
TNODE
****************************************************************************}

View File

@ -265,11 +265,13 @@ implementation
else
if s='FPC' then begin
aktmodeswitches:=fpcmodeswitches;
include(aktlocalswitches, cs_typed_addresses);
{ TODO: enable this for 2.3/2.9 }
// include(aktlocalswitches, cs_typed_addresses);
end else
if s='OBJFPC' then begin
aktmodeswitches:=objfpcmodeswitches;
include(aktlocalswitches, cs_typed_addresses);
{ TODO: enable this for 2.3/2.9 }
// include(aktlocalswitches, cs_typed_addresses);
end else
if s='GPC' then
aktmodeswitches:=gpcmodeswitches