From 5b67dc94b6b1f9528cb25abc75c93150cb7f92d9 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Thu, 4 Sep 2025 01:29:50 -0400 Subject: [PATCH] Add more test coverage --- src/asm/actions.cpp | 7 +++++-- src/asm/section.cpp | 3 +++ test/asm/fragment-align-mismatch.asm | 2 ++ test/asm/fragment-align-mismatch.err | 4 ++++ test/asm/fragment-literal-outside-section.asm | 1 + test/asm/fragment-literal-outside-section.err | 2 ++ test/asm/invalid-underscore.asm | 1 + test/asm/invalid-underscore.err | 8 +++++--- test/asm/invalid-underscore.out | 1 + test/asm/section-align-large-ofs.asm | 1 + test/asm/section-align-large-ofs.err | 3 +++ test/asm/union-mismatch.asm | 2 ++ test/asm/union-mismatch.err | 4 ++++ 13 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 test/asm/fragment-align-mismatch.asm create mode 100644 test/asm/fragment-align-mismatch.err create mode 100644 test/asm/fragment-literal-outside-section.asm create mode 100644 test/asm/fragment-literal-outside-section.err create mode 100644 test/asm/section-align-large-ofs.asm create mode 100644 test/asm/section-align-large-ofs.err create mode 100644 test/asm/union-mismatch.asm create mode 100644 test/asm/union-mismatch.err diff --git a/src/asm/actions.cpp b/src/asm/actions.cpp index ce3f4f4a..e2637951 100644 --- a/src/asm/actions.cpp +++ b/src/asm/actions.cpp @@ -47,7 +47,9 @@ void act_Elif(int32_t condition) { if (lexer_ReachedELSEBlock()) { fatal("Found `ELIF` after an `ELSE` block"); } - lexer_SetMode(LEXER_SKIP_TO_ENDC); + // This should be redundant, as the lexer will have skipped to `ENDC` since + // an `ELIF` after a taken `IF` needs to not evaluate its condition. + lexer_SetMode(LEXER_SKIP_TO_ENDC); // LCOV_EXCL_LINE } else if (condition) { lexer_RunIFBlock(); } else { @@ -61,7 +63,8 @@ void act_Else() { } if (lexer_RanIFBlock()) { if (lexer_ReachedELSEBlock()) { - fatal("Found `ELSE` after an `ELSE` block"); + // This should be redundant, as the lexer handles this error first. + fatal("Found `ELSE` after an `ELSE` block"); // LCOV_EXCL_LINE } lexer_SetMode(LEXER_SKIP_TO_ENDC); } else { diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 4b663134..4a167f9a 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -406,13 +406,16 @@ static Section *getSection( bank = sectionTypeInfo[type].firstBank; } + // This should be redundant, as the parser guarantees that `AlignmentSpec` will be valid. if (alignOffset >= alignSize) { + // LCOV_EXCL_START error( "Alignment offset (%" PRIu16 ") must be smaller than alignment size (%" PRIu32 ")", alignOffset, alignSize ); alignOffset = 0; + // LCOV_EXCL_STOP } if (org != UINT32_MAX) { diff --git a/test/asm/fragment-align-mismatch.asm b/test/asm/fragment-align-mismatch.asm new file mode 100644 index 00000000..f8766bb5 --- /dev/null +++ b/test/asm/fragment-align-mismatch.asm @@ -0,0 +1,2 @@ +section fragment "aligned", wram0[$c002], align[1] +section fragment "aligned", wram0, align[2] diff --git a/test/asm/fragment-align-mismatch.err b/test/asm/fragment-align-mismatch.err new file mode 100644 index 00000000..00812fd4 --- /dev/null +++ b/test/asm/fragment-align-mismatch.err @@ -0,0 +1,4 @@ +error: Section already declared as fixed at incompatible address $c002 + at fragment-align-mismatch.asm(2) +FATAL: Cannot create section "aligned" (1 error) + at fragment-align-mismatch.asm(2) diff --git a/test/asm/fragment-literal-outside-section.asm b/test/asm/fragment-literal-outside-section.asm new file mode 100644 index 00000000..1c385f56 --- /dev/null +++ b/test/asm/fragment-literal-outside-section.asm @@ -0,0 +1 @@ +dw [[ db 42 ]] diff --git a/test/asm/fragment-literal-outside-section.err b/test/asm/fragment-literal-outside-section.err new file mode 100644 index 00000000..1dac411c --- /dev/null +++ b/test/asm/fragment-literal-outside-section.err @@ -0,0 +1,2 @@ +FATAL: Cannot output fragment literals outside of a `SECTION` + at fragment-literal-outside-section.asm(1) diff --git a/test/asm/invalid-underscore.asm b/test/asm/invalid-underscore.asm index b06a830b..0d4dc85e 100644 --- a/test/asm/invalid-underscore.asm +++ b/test/asm/invalid-underscore.asm @@ -25,6 +25,7 @@ println 0b101010_ println 0o123456_ println 0xabcdef_ println `01230123_ +println 123.456_ ; bad ('_' next to '.') println 1_.618 diff --git a/test/asm/invalid-underscore.err b/test/asm/invalid-underscore.err index 561e13d7..5f7199ac 100644 --- a/test/asm/invalid-underscore.err +++ b/test/asm/invalid-underscore.err @@ -22,8 +22,10 @@ error: Invalid integer constant, trailing '_' at invalid-underscore.asm(26) error: Invalid graphics constant, trailing '_' at invalid-underscore.asm(27) +error: Invalid fixed-point constant, trailing '_' + at invalid-underscore.asm(28) error: Invalid integer constant, trailing '_' - at invalid-underscore.asm(30) -error: Invalid integer constant, '_' after another '_' at invalid-underscore.asm(31) -Assembly aborted with 14 errors! +error: Invalid integer constant, '_' after another '_' + at invalid-underscore.asm(32) +Assembly aborted with 15 errors! diff --git a/test/asm/invalid-underscore.out b/test/asm/invalid-underscore.out index e7942632..60809d3d 100644 --- a/test/asm/invalid-underscore.out +++ b/test/asm/invalid-underscore.out @@ -20,5 +20,6 @@ $2A $A72E $ABCDEF $3355 +$7B74BC $19E35 $2B7CF diff --git a/test/asm/section-align-large-ofs.asm b/test/asm/section-align-large-ofs.asm new file mode 100644 index 00000000..ec74c3cf --- /dev/null +++ b/test/asm/section-align-large-ofs.asm @@ -0,0 +1 @@ +section "test", rom0, align[2, 99] diff --git a/test/asm/section-align-large-ofs.err b/test/asm/section-align-large-ofs.err new file mode 100644 index 00000000..99f7161d --- /dev/null +++ b/test/asm/section-align-large-ofs.err @@ -0,0 +1,3 @@ +error: The absolute alignment offset (99) must be less than alignment size (4) + at section-align-large-ofs.asm(1) +Assembly aborted with 1 error! diff --git a/test/asm/union-mismatch.asm b/test/asm/union-mismatch.asm new file mode 100644 index 00000000..ce0df3b7 --- /dev/null +++ b/test/asm/union-mismatch.asm @@ -0,0 +1,2 @@ +section union "fixed", wram0[$c001] +section union "fixed", wram0, align[1] diff --git a/test/asm/union-mismatch.err b/test/asm/union-mismatch.err new file mode 100644 index 00000000..ee618d2a --- /dev/null +++ b/test/asm/union-mismatch.err @@ -0,0 +1,4 @@ +error: Section already declared as fixed at incompatible address $c001 + at union-mismatch.asm(2) +FATAL: Cannot create section "fixed" (1 error) + at union-mismatch.asm(2)