]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/110126 variables are reported as unused when referenced by ASM fix
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 12 Jun 2023 14:25:39 +0000 (15:25 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 12 Jun 2023 14:25:39 +0000 (15:25 +0100)
This patch fixes the trash list of the asm statement.  It introduces a
separate build procedure for trashed elements.

gcc/m2/ChangeLog:

PR modula2/110126
* gm2-compiler/M2Quads.def (BuildAsmElement): Remove
trash parameter.
(BuildAsmTrash): New procedure.
* gm2-compiler/M2Quads.mod (BuildAsmTrash): New procedure.
(BuildAsmElement): Remove trash parameter.
* gm2-compiler/P3Build.bnf (AsmTrashList): Rewrite.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2Quads.def
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-compiler/P3Build.bnf

index 493111e7c1bce4af7a20c3484920d33a719acb54..fcb59bbcf499146a1812d46b29584ba0c20ffdd0 100644 (file)
@@ -144,7 +144,7 @@ EXPORT QUALIFIED StartBuildDefFile, StartBuildModFile, EndBuildFile,
                  IsAutoPushOn, PushAutoOn, PushAutoOff, PopAuto,
                  PushInConstExpression, PopInConstExpression,
                  IsInConstExpression,
-                 MustCheckOverflow, BuildAsmElement ;
+                 MustCheckOverflow, BuildAsmElement, BuildAsmTrash ;
 
 
 TYPE
@@ -2734,7 +2734,29 @@ PROCEDURE IsInConstExpression () : BOOLEAN ;
                         |------------------|       |------------------|
 *)
 
-PROCEDURE BuildAsmElement (input, output, trash: BOOLEAN) ;
+PROCEDURE BuildAsmElement (input, output: BOOLEAN) ;
+
+
+(*
+   BuildAsmTrash - the stack is expected to contain:
+
+
+                        Entry                      Exit
+                        =====                      ====
+
+                 Ptr ->
+                        +------------------+
+                        | expr | tokpos    |
+                        |------------------|       +------------------+
+                        | CurrentInterface |       | CurrentInterface |
+                        |------------------|       |------------------|
+                        | CurrentAsm       |       | CurrentAsm       |
+                        |------------------|       |------------------|
+                        | n                |       | n                |
+                        |------------------|       |------------------|
+*)
+
+PROCEDURE BuildAsmTrash ;
 
 
 END M2Quads.
index 8639d5e580783e0a8b3baedf5f39b82818974c0c..081e9311ae8a91f50a72626e9d55ad97b27e10ad 100644 (file)
@@ -14421,7 +14421,7 @@ END AddVarientEquality ;
                         |------------------|       |------------------|
 *)
 
-PROCEDURE BuildAsmElement (input, output, trash: BOOLEAN) ;
+PROCEDURE BuildAsmElement (input, output: BOOLEAN) ;
 VAR
    n, str, expr, tokpos,
    CurrentInterface,
@@ -14449,15 +14449,53 @@ BEGIN
       PutRegInterface (tokpos, CurrentInterface, n, name, str, expr,
                        0, NextQuad)
    END ;
-   IF trash
+   PushT (n) ;
+   PushT (CurrentAsm) ;
+   PushT (CurrentInterface)
+END BuildAsmElement ;
+
+
+(*
+   BuildAsmTrash - the stack is expected to contain:
+
+
+                        Entry                      Exit
+                        =====                      ====
+
+                 Ptr ->
+                        +------------------+
+                        | expr | tokpos    |
+                        |------------------|       +------------------+
+                        | CurrentInterface |       | CurrentInterface |
+                        |------------------|       |------------------|
+                        | CurrentAsm       |       | CurrentAsm       |
+                        |------------------|       |------------------|
+                        | n                |       | n                |
+                        |------------------|       |------------------|
+*)
+
+PROCEDURE BuildAsmTrash ;
+VAR
+   n, expr, tokpos,
+   CurrentInterface,
+   CurrentAsm      : CARDINAL ;
+BEGIN
+   PopTtok (expr, tokpos) ;
+   PopT (CurrentInterface) ;
+   PopT (CurrentAsm) ;
+   Assert (IsGnuAsm (CurrentAsm) OR IsGnuAsmVolatile (CurrentAsm)) ;
+   PopT (n) ;
+   INC (n) ;
+   IF CurrentInterface = NulSym
    THEN
-      PutRegInterface (tokpos, CurrentInterface, n, name, str, expr,
-                       0, NextQuad)
+      CurrentInterface := MakeRegInterface ()
    END ;
+   PutRegInterface (tokpos, CurrentInterface, n, NulName, NulSym, expr,
+                    0, NextQuad) ;
    PushT (n) ;
    PushT (CurrentAsm) ;
    PushT (CurrentInterface)
-END BuildAsmElement ;
+END BuildAsmTrash ;
 
 
 (*
index 8fbe19111b6a471b5eab4d24dc4f12fa8ecfac30..e3cf96f5b4253d2469d250589033daee7725ee8e 100644 (file)
@@ -126,7 +126,7 @@ FROM M2Quads IMPORT PushT, PopT, PushTF, PopTF, PopNothing, Annotate,
                     BuildRetry,
                     DisplayStack,
                     AddVarientRange, AddVarientEquality,
-                    BuildAsmElement,
+                    BuildAsmElement, BuildAsmTrash,
                     BeginVarient, EndVarient, BeginVarientList, EndVarientList,
                     PushInConstExpression, PopInConstExpression, IsInConstExpression,
                     BuildDefaultFieldAlignment, BuildPragmaField,
@@ -1587,7 +1587,7 @@ AsmOperandName :=  ( NamedOperand
 AsmInputElement := AsmOperandName
                    ConstExpression '(' Expression                          % IF Pass3
                                                                              THEN
-                                                                                BuildAsmElement (TRUE, FALSE, FALSE)
+                                                                                BuildAsmElement (TRUE, FALSE)
                                                                              END
                                                                            %
                                    ')'
@@ -1596,34 +1596,22 @@ AsmInputElement := AsmOperandName
 AsmOutputElement := AsmOperandName
                     ConstExpression '(' Expression                         % IF Pass3
                                                                              THEN
-                                                                                BuildAsmElement (FALSE, TRUE, FALSE)
+                                                                                BuildAsmElement (FALSE, TRUE)
                                                                              END
                                                                            %
                                     ')'
                   =:
 
-AsmTrashList :=                                                            % VAR expr, tokpos  : CARDINAL ; %
+AsmTrashList :=                                                            % VAR expr, tokpos: CARDINAL ; %
                  [ ConstExpression                                         % IF Pass3
                                                                              THEN
-                                                                                PopTtok (expr, tokpos) ;
-                                                                                PushT (NulSym) ;
-                                                                                PushTtok (expr, tokpos) ;
-                                                                                BuildAsmElement (FALSE, FALSE, TRUE) ;
-                                                                                PopTtok (expr, tokpos) ;
-                                                                                PopNothing ;
-                                                                                PushTtok (expr, tokpos) ;
+                                                                                BuildAsmTrash
                                                                              END
 
                                                                            %
                  ] { ',' ConstExpression                                   % IF Pass3
                                                                              THEN
-                                                                                PopTtok (expr, tokpos) ;
-                                                                                PushT (NulSym) ;
-                                                                                PushTtok (expr, tokpos) ;
-                                                                                BuildAsmElement (FALSE, FALSE, TRUE) ;
-                                                                                PopTtok (expr, tokpos) ;
-                                                                                PopNothing ;
-                                                                                PushTtok (expr, tokpos) ;
+                                                                                BuildAsmTrash
                                                                              END
                                                                            %
                    } =: