[fpc-devel] AVR assembler code consistency checking

Christo christo.crause at gmail.com
Sat Jan 27 09:18:20 CET 2018


cOn Tue, 2018-01-23 at 21:57 +0100, Florian Klämpfl wrote:
> Just make a zip of the test programs. If they should fail during compilation, add a { %fail }
> comment as the first line, this tells the test runner, that the program must cause a
> compilation
> failure. If the test is useless, but should compile, add a { %norun }

Attached please find updated code for ConcatInstruction (raavr.patch) and some test cases in
tests.zip. The one test, tbs614.pp contains a list of all instructions with what I consider
permutations of valid parameters, all of which I think should successfully compile. The other 3
tests are for bug reports I've submitted. 

One issue I've noticed is that in rautils.pas TOprRec.val is defined as word for AVR.  This
creates a problem with interpreting large constants or negative constants.  This is probably a
corner case because most of the time offsets in code will be calculated by the linker, but it in
principle a user could specify a jmp with a user specified constant instead of referencing a
label. The consequence of this is that negative numbers are incorrectly casted as absolute
values (bug 32946) and also very large valid constants are silently truncated. If it is accepted
that user specified constants are allowed for these cases, the val field of TOprRec should be
expanded to a larger type, probably a longint.

Another issue I've noticed is the case:   ldd r20, z+0 where the instruction is internally
represented as ldd r20, z which is of course invalid syntax. I haven't had time to dig too
deeply into this case since this seems like a very unlikely scenario to crop up (but it is a
valid instruction according to the AVR instruction manual).

The webtbf32261.pp test check that a constant is not misinterpreted as a register,
while webtbs29758.pp check that accessing a procedure parameter via type cast passes the
consistency check.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.zip
Type: application/zip
Size: 1762 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180127/0e971d06/attachment.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: raavr.patch
Type: text/x-patch
Size: 21809 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180127/0e971d06/attachment.bin>


More information about the fpc-devel mailing list