From: Gaius Mulley Date: Mon, 12 Jun 2023 14:25:39 +0000 (+0100) Subject: PR modula2/110126 variables are reported as unused when referenced by ASM fix X-Git-Tag: basepoints/gcc-15~8421 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf470895905e9152424076d1630a9d2c60de023b;p=thirdparty%2Fgcc.git PR modula2/110126 variables are reported as unused when referenced by ASM fix 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 --- diff --git a/gcc/m2/gm2-compiler/M2Quads.def b/gcc/m2/gm2-compiler/M2Quads.def index 493111e7c1bc..fcb59bbcf499 100644 --- a/gcc/m2/gm2-compiler/M2Quads.def +++ b/gcc/m2/gm2-compiler/M2Quads.def @@ -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. diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod index 8639d5e58078..081e9311ae8a 100644 --- a/gcc/m2/gm2-compiler/M2Quads.mod +++ b/gcc/m2/gm2-compiler/M2Quads.mod @@ -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 ; (* diff --git a/gcc/m2/gm2-compiler/P3Build.bnf b/gcc/m2/gm2-compiler/P3Build.bnf index 8fbe19111b6a..e3cf96f5b425 100644 --- a/gcc/m2/gm2-compiler/P3Build.bnf +++ b/gcc/m2/gm2-compiler/P3Build.bnf @@ -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 % } =: