From 74c1d32ce9302a38f259b79334607639f63a7da5 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 8 Feb 2001 13:09:03 +0000 Subject: [PATCH] * fixed web bug #1396: tpointerord is now a cardinal instead of a longint, but added a hack in ncnv so that pointer(-1) still works --- compiler/i386/cpuinfo.pas | 12 ++++++++++-- compiler/ncnv.pas | 26 +++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/compiler/i386/cpuinfo.pas b/compiler/i386/cpuinfo.pas index 711ea63976..9849574af5 100644 --- a/compiler/i386/cpuinfo.pas +++ b/compiler/i386/cpuinfo.pas @@ -37,7 +37,11 @@ Type { this must be an ordinal type with the same size as a pointer } { to allow some dirty type casts for example when using } { tconstsym.value } - TPointerOrd = longint; + { Note: must be unsigned!! Otherwise, ugly code like } + { pointer(-1) will result in a pointer with the value } + { $fffffffffffffff on a 32bit machine if the compiler uses } + { int64 constants internally (JM) } + TPointerOrd = cardinal; Const { Size of native extended type } @@ -48,7 +52,11 @@ Implementation end. { $Log$ - Revision 1.1 2000-10-15 09:39:37 peter + Revision 1.2 2001-02-08 13:09:03 jonas + * fixed web bug 1396: tpointerord is now a cardinal instead of a longint, + but added a hack in ncnv so that pointer(-1) still works + + Revision 1.1 2000/10/15 09:39:37 peter * moved cpu*.pas to i386/ * renamed n386 to common cpunode diff --git a/compiler/ncnv.pas b/compiler/ncnv.pas index 9a86a5b802..95ebe75697 100644 --- a/compiler/ncnv.pas +++ b/compiler/ncnv.pas @@ -96,7 +96,7 @@ implementation {$else newcg} hcodegen, {$endif newcg} - htypechk,pass_1,cpubase; + htypechk,pass_1,cpubase,cpuinfo; function gentypeconvnode(node : tnode;t : pdef) : ttypeconvnode; @@ -657,7 +657,23 @@ implementation first_cord_to_pointer:=nil; if left.nodetype=ordconstn then begin - t:=genpointerconstnode(tordconstnode(left).value,resulttype); + { check if we have a valid pointer constant (JM) } + if (sizeof(tordconstnode) > sizeof(tpointerord)) then + if (sizeof(tpointerord) = 4) then + begin + if (tordconstnode(left).value < low(longint)) or + (tordconstnode(left).value > high(cardinal)) then + CGMessage(parser_e_range_check_error); + end + else if (sizeof(tpointerord) = 8) then + begin + if (tordconstnode(left).value < low(int64)) or + (tordconstnode(left).value > high(qword)) then + CGMessage(parser_e_range_check_error); + end + else + internalerror(2001020801); + t:=genpointerconstnode(tpointerord(tordconstnode(left).value),resulttype); firstpass(t); first_cord_to_pointer:=t; exit; @@ -1203,7 +1219,11 @@ begin end. { $Log$ - Revision 1.16 2000-12-31 11:14:10 jonas + Revision 1.17 2001-02-08 13:09:03 jonas + * fixed web bug 1396: tpointerord is now a cardinal instead of a longint, + but added a hack in ncnv so that pointer(-1) still works + + Revision 1.16 2000/12/31 11:14:10 jonas + implemented/fixed docompare() mathods for all nodes (not tested) + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings and constant strings/chars together