* Improved warning "Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead.":

- check for procedure and class pointers as well;
  - do not warn if typecasted pointer is passed as parameter or directly assigned to a variable. 

git-svn-id: trunk@9264 -
This commit is contained in:
yury 2007-11-16 13:52:19 +00:00
parent 807a18e109
commit 4e3547c7bf
3 changed files with 9 additions and 4 deletions

View File

@ -497,6 +497,8 @@ implementation
internalerror(200305091);
expr.fileinfo:=fileinfo;
callparaflags:=[];
if expr.nodetype = typeconvn then
ttypeconvnode(expr).warn_pointer_to_signed:=false;
end;
destructor tcallparanode.destroy;

View File

@ -37,6 +37,7 @@ interface
totypedef : tdef;
totypedefderef : tderef;
convtype : tconverttype;
warn_pointer_to_signed: boolean;
constructor create(node : tnode;def:tdef);virtual;
constructor create_explicit(node : tnode;def:tdef);
constructor create_internal(node : tnode;def:tdef);
@ -661,10 +662,6 @@ implementation
muln:
cgmessage1(type_h_convert_mul_operands_to_prevent_overflow,def.gettypename);
end;
{Converting pointers to signed integers is a bad idea. Warn.}
if (node.resultdef<>nil) and (node.resultdef.typ=pointerdef) and
(def.typ=orddef) and (Torddef(def).ordtype in [s8bit,s16bit,s32bit,s64bit]) then
cgmessage(type_w_pointer_to_signed);
end;
@ -1923,6 +1920,8 @@ implementation
((resultdef.typ=orddef) and
(left.resultdef.typ in [pointerdef,procvardef,classrefdef]))) then
begin
{Converting pointers to signed integers is a bad idea. Warn.}
warn_pointer_to_signed:=(resultdef.typ=orddef) and (Torddef(resultdef).ordtype in [s8bit,s16bit,s32bit,s64bit]);
{ Give a warning when sizes don't match, because then info will be lost }
if left.resultdef.size=resultdef.size then
CGMessage(type_h_pointer_to_longint_conv_not_portable)
@ -2687,6 +2686,8 @@ implementation
function ttypeconvnode.pass_1 : tnode;
begin
if warn_pointer_to_signed then
cgmessage(type_w_pointer_to_signed);
result:=nil;
firstpass(left);
if codegenerror then

View File

@ -444,6 +444,8 @@ implementation
inherited create(assignn,l,r);
l.mark_write;
assigntype:=at_normal;
if r.nodetype = typeconvn then
ttypeconvnode(r).warn_pointer_to_signed:=false;
end;