[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-07-29 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Gaius Mulley  changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--- Comment #17 from Gaius Mulley  ---
Many thanks for the bug report and test code!
Closing now as the patches have been applied to the gcc-13 branch.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-07-29 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #16 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Gaius Mulley
:

https://gcc.gnu.org/g:4fa9afdc9b52cfa9ea16443418de29e0e31b293b

commit r13-7646-g4fa9afdc9b52cfa9ea16443418de29e0e31b293b
Author: Gaius Mulley 
Date:   Sat Jul 29 21:04:26 2023 +0100

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.

(cherry picked from commit bf470895905e9152424076d1630a9d2c60de023b)

Signed-off-by: Gaius Mulley 

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-07-29 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #15 from CVS Commits  ---
The releases/gcc-13 branch has been updated by Gaius Mulley
:

https://gcc.gnu.org/g:3ad40f65a7c89af2f3cb71c06e327ee33a996bd4

commit r13-7644-g3ad40f65a7c89af2f3cb71c06e327ee33a996bd4
Author: Gaius Mulley 
Date:   Sat Jul 29 17:24:38 2023 +0100

PR modula2/110126 variables are reported as unused when referenced by ASM

This patches fixes two problems with the asm statement.
gm2 -Wall -c fooasm3.mod generates an incorrect warning and
gm2 cannot concatenate strings before an ASM statement.
The asm statement now accepts a constant expression (rather than
a string) and it updates the variable read/write use lists as
appropriate.

gcc/m2/ChangeLog:

PR modula2/110126
* gm2-compiler/M2GenGCC.mod (BuildTreeFromInterface): Remove
tokenno parameter.  Use object tok instead of tokenno.
(BuildTrashTreeFromInterface): Use object tok instead of
GetDeclaredMod.
(CodeInline): Remove tokenno from parameter list to
BuildTreeFromInterface.
* gm2-compiler/M2Quads.def (BuildAsmElement): Exported and
defined.
* gm2-compiler/M2Quads.mod (BuildOptimizeOff): Reformatted.
(BuildInline): Reformatted.
(BuildLineNo): Reformatted.
(UseLineNote): Reformatted.
(BuildAsmElement): New procedure.
* gm2-compiler/P0SyntaxCheck.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/P1Build.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/P2Build.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/P3Build.bnf (AsmOperands): Rewrite.
(AsmOperandSpec): Rewrite.
(AsmOutputList): New rule.
(AsmInputList): New rule.
(TrashList): Rewrite.
* gm2-compiler/PCBuild.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/PHBuild.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/SymbolTable.def (PutRegInterface):
Rewrite interface.
(GetRegInterface): Rewrite interface.
* gm2-compiler/SymbolTable.mod (SetFirstUsed): New procedure.
(PutFirstUsed): New procedure.
(PutRegInterface): Rewrite.
(GetRegInterface): Rewrite.

gcc/testsuite/ChangeLog:

PR modula2/110126
* gm2/pim/pass/fooasm3.mod: New test.

(cherry picked from commit 990d10ab23360fef8b5eb6937ac10b4f67f46e2d)

Signed-off-by: Gaius Mulley 

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-07-11 Thread admin--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Thorsten Otto  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|FIXED   |---

--- Comment #14 from Thorsten Otto  ---
And another problem i just encountered. In the following example:

DEFINITION MODULE foo;

PROCEDURE ConWS(str: ARRAY OF CHAR);

END foo.


IMPLEMENTATION MODULE foo;

FROM SYSTEM IMPORT ADR, CARDINAL16, CARDINAL32, INTEGER16, ADDRESS,
INTEGER32, WORD;

FROM StrIO IMPORT WriteString, WriteLn;

TYPE strtmp = ARRAY [0..255] OF CHAR;

PROCEDURE str0(VAR dst: strtmp; src: ARRAY OF CHAR);
VAR i, len: CARDINAL;
BEGIN
  len := HIGH(dst);
  FOR i := 0 TO len DO
dst[i] := src[i];
  END;
END str0;


PROCEDURE trap_1_wl(n: INTEGER16; a: ADDRESS): [ INTEGER32 ];
VAR
retvalue: INTEGER32;
BEGIN
ASM VOLATILE("move.l %2,-(%%sp); move.w %1,-(%%sp); trap #1; addq.l
#6,%%sp; move.l %%d0,%0"
   : "=r"(retvalue)
   : "g"(n), "r"(a)
   : "memory"
);
RETURN retvalue
END trap_1_wl;


PROCEDURE ConWS(str: ARRAY OF CHAR);
VAR s: strtmp;
BEGIN
  str0(s, str);
  trap_1_wl(9, ADR(s));
END ConWS;


END foo.

The call to str0 (in reality supposed to ensure the string is 0-terminated;
just simplified for the example) is now completely eliminated. The assembler
statement is of course only for m68k, but it can even be triggered for other
targets when just producing assembler output.

It does not happen when replacing the call to trap_1_wl eg. by WriteString.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-13 Thread admin--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #13 from Thorsten Otto  ---
Just found a small problem: asm statements without any lists,
like in

ASM("");

now are warned about with "syntax warning, ':' missing"

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-12 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Gaius Mulley  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #12 from Gaius Mulley  ---
Many thanks for the bug report and for testing the patches!
Closing now the patches have been applied.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-12 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #11 from CVS Commits  ---
The master branch has been updated by Gaius Mulley :

https://gcc.gnu.org/g:bf470895905e9152424076d1630a9d2c60de023b

commit r14-1718-gbf470895905e9152424076d1630a9d2c60de023b
Author: Gaius Mulley 
Date:   Mon Jun 12 15:25:39 2023 +0100

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 

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-12 Thread admin--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #10 from Thorsten Otto  ---
Yes, thank you, that seems to work.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-12 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #9 from Gaius Mulley  ---
Created attachment 55309
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55309&action=edit
Proposed fix v2

Here is a proposed fix, please can you test on your code?   It appears to work
with my short examples.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-09 Thread admin--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #8 from Thorsten Otto  ---
And here are examples that trigger the bug:

DEFINITION MODULE BIOS;

FROM SYSTEM IMPORT ADDRESS, CARDINAL32, INTEGER16, INTEGER32;

END BIOS.

IMPLEMENTATION MODULE BIOS;

PROCEDURE trap_13_w(n: INTEGER16): [ INTEGER32 ];
VAR
retvalue: INTEGER32;
BEGIN
ASM VOLATILE(""
   : "=r"(retvalue)
   : "g"(n)
   : "cc", "memory"
);
RETURN retvalue
END trap_13_w;


BEGIN
END BIOS.

The crash disappears when i remove the clobber list from the asm.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-08 Thread admin--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Thorsten Otto  changed:

   What|Removed |Added

 Status|RESOLVED|ASSIGNED
 Resolution|FIXED   |---

--- Comment #7 from Thorsten Otto  ---
Thanks for looking into this.

Unfortunately, with the new patch applied, i now get

cc1gm2: internal compiler error: symbol out of bounds
0x7f4dfde2cbaf __libc_start_call_main
???:0
0x7f4dfde2cc78 __libc_start_main_alias_1
???:0

Have yet to try to create a simple testcase that triggers this bug.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-08 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Gaius Mulley  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #6 from Gaius Mulley  ---
Closing now patch has been applied - thanks for the report!

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-08 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #5 from CVS Commits  ---
The master branch has been updated by Gaius Mulley :

https://gcc.gnu.org/g:990d10ab23360fef8b5eb6937ac10b4f67f46e2d

commit r14-1638-g990d10ab23360fef8b5eb6937ac10b4f67f46e2d
Author: Gaius Mulley 
Date:   Fri Jun 9 00:55:50 2023 +0100

PR modula2/110126 variables are reported as unused when referenced by ASM

This patches fixes two problems with the asm statement.
gm2 -Wall -c fooasm3.mod generates an incorrect warning and
gm2 cannot concatenate strings before an ASM statement.
The asm statement now accepts a constant expression (rather than
a string) and it updates the variable read/write use lists as
appropriate.

gcc/m2/ChangeLog:

PR modula2/110126
* gm2-compiler/M2GenGCC.mod (BuildTreeFromInterface): Remove
tokenno parameter.  Use object tok instead of tokenno.
(BuildTrashTreeFromInterface): Use object tok instead of
GetDeclaredMod.
(CodeInline): Remove tokenno from parameter list to
BuildTreeFromInterface.
* gm2-compiler/M2Quads.def (BuildAsmElement): Exported and
defined.
* gm2-compiler/M2Quads.mod (BuildOptimizeOff): Reformatted.
(BuildInline): Reformatted.
(BuildLineNo): Reformatted.
(UseLineNote): Reformatted.
(BuildAsmElement): New procedure.
* gm2-compiler/P0SyntaxCheck.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/P1Build.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/P2Build.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/P3Build.bnf (AsmOperands): Rewrite.
(AsmOperandSpec): Rewrite.
(AsmOutputList): New rule.
(AsmInputList): New rule.
(TrashList): Rewrite.
* gm2-compiler/PCBuild.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/PHBuild.bnf (AsmOperands): Use
ConstExpression instead of string.
(AsmElement): Use ConstExpression instead of string.
(TrashList): Use ConstExpression instead of string.
* gm2-compiler/SymbolTable.def (PutRegInterface):
Rewrite interface.
(GetRegInterface): Rewrite interface.
* gm2-compiler/SymbolTable.mod (SetFirstUsed): New procedure.
(PutFirstUsed): New procedure.
(PutRegInterface): Rewrite.
(GetRegInterface): Rewrite.

gcc/testsuite/ChangeLog:

PR modula2/110126
* gm2/pim/pass/fooasm3.mod: New test.

Signed-off-by: Gaius Mulley 

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-08 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Gaius Mulley  changed:

   What|Removed |Added

 CC||gaius at gcc dot gnu.org

--- Comment #4 from Gaius Mulley  ---
Created attachment 55285
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55285&action=edit
Proposed fix

Here is a proposed fix.

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-07 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

Gaius Mulley  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2023-06-07
 Ever confirmed|0   |1

--- Comment #3 from Gaius Mulley  ---
Ah yes indeed, so there are two issues:

   (1)  gm2 -Wall -c foo.mod generates an incorrect warning.
   (2)  gm2 cannot concatenate strings before an ASM statement.

will fix - thanks for the report(s)

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-06 Thread admin--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #2 from Thorsten Otto  ---
But even if i rewrite it like that, i still get the warning.

I avoided doing anything machine specific in the first example, but if i
actually do, and use something like:

PROCEDURE test;
BEGIN
  ASM("movl %1,%%eax; addl $1,%%eax; movl %%eax,%0" : "=r"(x) : "0"(x) :
"eax");
END test;

i still get the warning.

BTW, is there a reason why the string in the asm statement can't be
concatenated?

eg. especially if the statement becomes longer, you would usually want to write
it something like

  ASM("movl %1,%%eax;" +
  "addl $1,%%eax;" +
  "movl %%eax,%0"
 : "=r"(x) : "0"(x) : "eax");

[Bug modula2/110126] Variables are reported as unused when only referenced by ASM statements

2023-06-06 Thread gaius at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110126

--- Comment #1 from Gaius Mulley  ---
The procedure test is unreachable, if the module is re-written as:

MODULE fooasm ;

VAR x: INTEGER;

PROCEDURE test;
BEGIN
  ASM("" : : "m"(x));
END test;

BEGIN
   test
END fooasm.


then the assembly output for procedure test in gm2 -S fooasm.mod looks similar
to:

static int x;

void test (void)
{
  asm ("" : : "m"(x));
}