mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 16:29:21 +02:00
* fixed evaluating constant expressions consisting of more than one term and
that start with a minus in the intel assembler reader (mantis #15843) git-svn-id: trunk@15041 -
This commit is contained in:
parent
57b67087a8
commit
8542632ebe
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10315,6 +10315,7 @@ tests/webtbs/tw15777d.pp svneol=native#text/plain
|
|||||||
tests/webtbs/tw15777e.pp svneol=native#text/plain
|
tests/webtbs/tw15777e.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw15777f.pp svneol=native#text/plain
|
tests/webtbs/tw15777f.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw15812.pp svneol=native#text/plain
|
tests/webtbs/tw15812.pp svneol=native#text/plain
|
||||||
|
tests/webtbs/tw15843.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw15909.pp svneol=native#text/plain
|
tests/webtbs/tw15909.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1592.pp svneol=native#text/plain
|
tests/webtbs/tw1592.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw15930.pp svneol=native#text/plain
|
tests/webtbs/tw15930.pp svneol=native#text/plain
|
||||||
|
@ -62,7 +62,7 @@ Unit Rax86int;
|
|||||||
function consume(t : tasmtoken):boolean;
|
function consume(t : tasmtoken):boolean;
|
||||||
procedure RecoverConsume(allowcomma:boolean);
|
procedure RecoverConsume(allowcomma:boolean);
|
||||||
procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
|
procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
|
||||||
procedure BuildConstSymbolExpression(needofs,isref:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
|
procedure BuildConstSymbolExpression(needofs,isref,startingminus:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
|
||||||
function BuildConstExpression:aint;
|
function BuildConstExpression:aint;
|
||||||
function BuildRefConstExpression:aint;
|
function BuildRefConstExpression:aint;
|
||||||
procedure BuildReference(oper : tx86operand);
|
procedure BuildReference(oper : tx86operand);
|
||||||
@ -746,7 +746,7 @@ Unit Rax86int;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Procedure tx86intreader.BuildConstSymbolExpression(needofs,isref:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
|
Procedure tx86intreader.BuildConstSymbolExpression(needofs,isref,startingminus:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
|
||||||
var
|
var
|
||||||
tempstr,expr,hs,mangledname : string;
|
tempstr,expr,hs,mangledname : string;
|
||||||
parenlevel : longint;
|
parenlevel : longint;
|
||||||
@ -768,6 +768,8 @@ Unit Rax86int;
|
|||||||
errorflag:=FALSE;
|
errorflag:=FALSE;
|
||||||
tempstr:='';
|
tempstr:='';
|
||||||
expr:='';
|
expr:='';
|
||||||
|
if startingminus then
|
||||||
|
expr:='-';
|
||||||
inexpression:=TRUE;
|
inexpression:=TRUE;
|
||||||
parenlevel:=0;
|
parenlevel:=0;
|
||||||
sym:=nil;
|
sym:=nil;
|
||||||
@ -1116,7 +1118,7 @@ Unit Rax86int;
|
|||||||
hs : string;
|
hs : string;
|
||||||
hssymtyp : TAsmsymtype;
|
hssymtyp : TAsmsymtype;
|
||||||
begin
|
begin
|
||||||
BuildConstSymbolExpression(false,false,l,hs,hssymtyp);
|
BuildConstSymbolExpression(false,false,false,l,hs,hssymtyp);
|
||||||
if hs<>'' then
|
if hs<>'' then
|
||||||
Message(asmr_e_relocatable_symbol_not_allowed);
|
Message(asmr_e_relocatable_symbol_not_allowed);
|
||||||
BuildConstExpression:=l;
|
BuildConstExpression:=l;
|
||||||
@ -1129,7 +1131,7 @@ Unit Rax86int;
|
|||||||
hs : string;
|
hs : string;
|
||||||
hssymtyp : TAsmsymtype;
|
hssymtyp : TAsmsymtype;
|
||||||
begin
|
begin
|
||||||
BuildConstSymbolExpression(false,true,l,hs,hssymtyp);
|
BuildConstSymbolExpression(false,true,false,l,hs,hssymtyp);
|
||||||
if hs<>'' then
|
if hs<>'' then
|
||||||
Message(asmr_e_relocatable_symbol_not_allowed);
|
Message(asmr_e_relocatable_symbol_not_allowed);
|
||||||
BuildRefConstExpression:=l;
|
BuildRefConstExpression:=l;
|
||||||
@ -1429,7 +1431,11 @@ Unit Rax86int;
|
|||||||
begin
|
begin
|
||||||
if not GotPlus and not GotStar then
|
if not GotPlus and not GotStar then
|
||||||
Message(asmr_e_invalid_reference_syntax);
|
Message(asmr_e_invalid_reference_syntax);
|
||||||
BuildConstSymbolExpression(true,true,l,tempstr,tempsymtyp);
|
BuildConstSymbolExpression(true,true,GotPlus and negative,l,tempstr,tempsymtyp);
|
||||||
|
{ already handled by BuildConstSymbolExpression(); must be
|
||||||
|
handled there to avoid [reg-1+1] being interpreted as
|
||||||
|
[reg-(1+1)] }
|
||||||
|
negative:=false;
|
||||||
|
|
||||||
if tempstr<>'' then
|
if tempstr<>'' then
|
||||||
begin
|
begin
|
||||||
@ -1453,12 +1459,7 @@ Unit Rax86int;
|
|||||||
scale:=l;
|
scale:=l;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
Inc(oper.opr.ref.offset,l);
|
||||||
if negative then
|
|
||||||
Dec(oper.opr.ref.offset,l)
|
|
||||||
else
|
|
||||||
Inc(oper.opr.ref.offset,l);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
OPR_LOCAL :
|
OPR_LOCAL :
|
||||||
begin
|
begin
|
||||||
@ -1472,12 +1473,7 @@ Unit Rax86int;
|
|||||||
scale:=l;
|
scale:=l;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
Inc(oper.opr.localsymofs,l);
|
||||||
if negative then
|
|
||||||
Dec(oper.opr.localsymofs,l)
|
|
||||||
else
|
|
||||||
Inc(oper.opr.localsymofs,l);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
GotPlus:=(prevasmtoken=AS_PLUS) or
|
GotPlus:=(prevasmtoken=AS_PLUS) or
|
||||||
@ -1514,7 +1510,7 @@ Unit Rax86int;
|
|||||||
begin
|
begin
|
||||||
if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
|
if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
|
||||||
Message(asmr_e_invalid_operand_type);
|
Message(asmr_e_invalid_operand_type);
|
||||||
BuildConstSymbolExpression(true,false,l,tempstr,tempsymtyp);
|
BuildConstSymbolExpression(true,false,false,l,tempstr,tempsymtyp);
|
||||||
if tempstr<>'' then
|
if tempstr<>'' then
|
||||||
begin
|
begin
|
||||||
oper.opr.typ:=OPR_SYMBOL;
|
oper.opr.typ:=OPR_SYMBOL;
|
||||||
@ -2042,7 +2038,7 @@ Unit Rax86int;
|
|||||||
AS_INTNUM,
|
AS_INTNUM,
|
||||||
AS_ID :
|
AS_ID :
|
||||||
Begin
|
Begin
|
||||||
BuildConstSymbolExpression(false,false,value,asmsym,asmsymtyp);
|
BuildConstSymbolExpression(false,false,false,value,asmsym,asmsymtyp);
|
||||||
if asmsym<>'' then
|
if asmsym<>'' then
|
||||||
begin
|
begin
|
||||||
if constsize<>sizeof(pint) then
|
if constsize<>sizeof(pint) then
|
||||||
|
21
tests/webtbs/tw15843.pp
Normal file
21
tests/webtbs/tw15843.pp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{ %opt=-Cg- }
|
||||||
|
{ %cpu=i386 }
|
||||||
|
|
||||||
|
{$asmmode intel}
|
||||||
|
var
|
||||||
|
a: array[0..3] of byte;
|
||||||
|
l: longint;
|
||||||
|
begin
|
||||||
|
a[0]:=1;
|
||||||
|
a[1]:=2;
|
||||||
|
a[2]:=3;
|
||||||
|
a[2]:=4;
|
||||||
|
asm
|
||||||
|
lea ecx,[a]
|
||||||
|
inc ecx
|
||||||
|
movzx eax, byte ptr[ecx-1+1] // bug in this line (-2)
|
||||||
|
mov [l],eax
|
||||||
|
end;
|
||||||
|
if l<>2 then
|
||||||
|
halt(1);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user