Browse Source

+ fix for using the function name (as the function's entry point address,
instead of the function result variable, which is already accessible, using
the @Result directive) in inline asm

git-svn-id: trunk@38289 -

nickysn 7 years ago
parent
commit
6c69e10613
3 changed files with 70 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 36 0
      compiler/rautils.pas
  3. 33 0
      tests/test/tasm21.pp

+ 1 - 0
.gitattributes

@@ -12514,6 +12514,7 @@ tests/test/tasm19.pp svneol=native#text/plain
 tests/test/tasm2.inc svneol=native#text/plain
 tests/test/tasm2.inc svneol=native#text/plain
 tests/test/tasm2.pp svneol=native#text/plain
 tests/test/tasm2.pp svneol=native#text/plain
 tests/test/tasm20.pp svneol=native#text/plain
 tests/test/tasm20.pp svneol=native#text/plain
+tests/test/tasm21.pp svneol=native#text/plain
 tests/test/tasm2a.pp svneol=native#text/plain
 tests/test/tasm2a.pp svneol=native#text/plain
 tests/test/tasm3.pp svneol=native#text/plain
 tests/test/tasm3.pp svneol=native#text/plain
 tests/test/tasm4.pp svneol=native#text/plain
 tests/test/tasm4.pp svneol=native#text/plain

+ 36 - 0
compiler/rautils.pas

@@ -1301,6 +1301,42 @@ begin
     end
     end
   else
   else
     searchsym(s,srsym,srsymtable);
     searchsym(s,srsym,srsymtable);
+  { in asm routines, the function result variable, that matches the function
+    name should be avoided, because:
+    1) there's already a @Result directive (even in TP7) that can be used, if
+       you want to access the function result
+    2) there's no other way to disambiguate between the function result variable
+       and the function's address (using asm syntax only)
+
+    This fixes code, such as:
+
+    function test1: word;
+    begin
+      asm
+        mov ax, offset test1
+      end;
+    end;
+
+    and makes it work in a consistent manner as this code:
+
+    procedure test2;
+    begin
+      asm
+        mov ax, offset test2
+      end;
+    end; }
+  if assigned(srsym) and
+     assigned(srsymtable) and
+     (srsym.typ=absolutevarsym) and
+     (vo_is_funcret in tabsolutevarsym(srsym).varoptions) and
+     (srsymtable.symtabletype=localsymtable) and
+     assigned(srsymtable.defowner) and
+     (srsymtable.defowner.typ=procdef) and
+     (tprocdef(srsymtable.defowner).procsym.name=tabsolutevarsym(srsym).Name) then
+    begin
+      srsym:=tprocdef(srsymtable.defowner).procsym;
+      srsymtable:=srsym.Owner;
+    end;
 end;
 end;
 
 
 
 

+ 33 - 0
tests/test/tasm21.pp

@@ -0,0 +1,33 @@
+{ %CPU=i8086 }
+
+{$IFDEF FPC}
+{$MODE TP}
+{$ENDIF}
+program tasm21;
+
+function test1a: word; assembler;
+asm
+  mov ax, offset test1a;
+end;
+
+function test1b: word;
+begin
+  asm
+    mov ax, offset test1b;
+  end;
+end;
+
+procedure test2a; assembler;
+asm
+  mov ax, offset test2a;
+end;
+
+procedure test2b;
+begin
+  asm
+    mov ax, offset test2b;
+  end;
+end;
+
+begin
+end.