From bdf397bba7f5acc64202a60e56bf197d64ad098d Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Tue, 5 May 2020 10:27:55 -0400 Subject: [PATCH] Add empty data directive warning Fixes #516 --- include/asm/section.h | 3 ++- include/asm/warning.h | 1 + src/asm/asmy.y | 8 ++++---- src/asm/section.c | 6 +++++- src/asm/warning.c | 4 ++++ test/asm/empty-data-directive.asm | 16 ++++++++++++++++ test/asm/empty-data-directive.err | 6 ++++++ test/asm/empty-data-directive.out | 0 8 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 test/asm/empty-data-directive.asm create mode 100644 test/asm/empty-data-directive.err create mode 100644 test/asm/empty-data-directive.out diff --git a/include/asm/section.h b/include/asm/section.h index 8e4f49e6..6a7f42bd 100644 --- a/include/asm/section.h +++ b/include/asm/section.h @@ -10,6 +10,7 @@ #define RGBDS_SECTION_H #include +#include #include "linkdefs.h" @@ -48,7 +49,7 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset); void out_AbsByte(uint8_t b); void out_AbsByteGroup(uint8_t const *s, int32_t length); -void out_Skip(int32_t skip); +void out_Skip(int32_t skip, bool ds); void out_String(char const *s); void out_RelByte(struct Expression *expr); void out_RelBytes(struct Expression *expr, uint32_t n); diff --git a/include/asm/warning.h b/include/asm/warning.h index d6589be7..145550f5 100644 --- a/include/asm/warning.h +++ b/include/asm/warning.h @@ -17,6 +17,7 @@ enum WarningID { WARNING_ASSERT, WARNING_BUILTIN_ARG, WARNING_DIV, + WARNING_EMPTY_DATA_DIRECTIVE, WARNING_EMPTY_ENTRY, WARNING_LARGE_CONSTANT, WARNING_LONG_STR, diff --git a/src/asm/asmy.y b/src/asm/asmy.y index c3ab1954..015bf4c5 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -995,7 +995,7 @@ endu : T_POP_ENDU { } ; -ds : T_POP_DS uconst { out_Skip($2); } +ds : T_POP_DS uconst { out_Skip($2, true); } | T_POP_DS uconst ',' reloc_8bit { out_RelBytes(&$4, $2); } @@ -1189,7 +1189,7 @@ constlist_8bit : constlist_8bit_entry ; constlist_8bit_entry : /* empty */ { - out_Skip(1); + out_Skip(1, false); nListCountEmpty++; } | reloc_8bit_no_str { out_RelByte(&$1); } @@ -1207,7 +1207,7 @@ constlist_16bit : constlist_16bit_entry ; constlist_16bit_entry : /* empty */ { - out_Skip(2); + out_Skip(2, false); nListCountEmpty++; } | reloc_16bit { out_RelWord(&$1); } @@ -1218,7 +1218,7 @@ constlist_32bit : constlist_32bit_entry ; constlist_32bit_entry : /* empty */ { - out_Skip(4); + out_Skip(4, false); nListCountEmpty++; } | relocexpr { out_RelLong(&$1); } diff --git a/src/asm/section.c b/src/asm/section.c index dd3d2b61..52968fc2 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "asm/fstack.h" #include "asm/main.h" @@ -434,11 +435,14 @@ void out_AbsByteGroup(uint8_t const *s, int32_t length) /* * Skip this many bytes */ -void out_Skip(int32_t skip) +void out_Skip(int32_t skip, bool ds) { checksection(); reserveSpace(skip); + if (!ds && sect_HasData(pCurrentSection->nType)) + warning(WARNING_EMPTY_DATA_DIRECTIVE, "db/dw/dl directive without data in ROM"); + if (!sect_HasData(pCurrentSection->nType)) { growSection(skip); } else if (nUnionDepth > 0) { diff --git a/src/asm/warning.c b/src/asm/warning.c index 4ee419a3..163fe7ba 100644 --- a/src/asm/warning.c +++ b/src/asm/warning.c @@ -31,6 +31,7 @@ static enum WarningState const defaultWarnings[NB_WARNINGS] = { WARNING_ENABLED, /* Assertions */ WARNING_DISABLED, /* Invalid args to builtins */ WARNING_DISABLED, /* Division undefined behavior */ + WARNING_DISABLED, /* `db`, `dw`, or `dl` with no directive in ROM */ WARNING_DISABLED, /* Empty entry in `db`, `dw` or `dl` */ WARNING_DISABLED, /* Constants too large */ WARNING_DISABLED, /* String too long for internal buffers */ @@ -68,6 +69,7 @@ static char const *warningFlags[NB_WARNINGS_ALL] = { "assert", "builtin-args", "div", + "empty-data-directive", "empty-entry", "large-constant", "long-string", @@ -90,6 +92,7 @@ enum MetaWarningCommand { /* Warnings that probably indicate an error */ static uint8_t const _wallCommands[] = { WARNING_BUILTIN_ARG, + WARNING_EMPTY_DATA_DIRECTIVE, WARNING_LARGE_CONSTANT, WARNING_LONG_STR, META_WARNING_DONE @@ -106,6 +109,7 @@ static uint8_t const _wextraCommands[] = { static uint8_t const _weverythingCommands[] = { WARNING_BUILTIN_ARG, WARNING_DIV, + WARNING_EMPTY_DATA_DIRECTIVE, WARNING_EMPTY_ENTRY, WARNING_LARGE_CONSTANT, WARNING_LONG_STR, diff --git a/test/asm/empty-data-directive.asm b/test/asm/empty-data-directive.asm new file mode 100644 index 00000000..06d19db2 --- /dev/null +++ b/test/asm/empty-data-directive.asm @@ -0,0 +1,16 @@ +SECTION "Empty Data Directive in ROM", ROM0 + ds 1 + ds 2 + ds 3 + ds 4 + db + dw + dl +SECTION "Empty Data Directive in HRAM", HRAM + ds 1 + ds 2 + ds 3 + ds 4 + db + dw + dl diff --git a/test/asm/empty-data-directive.err b/test/asm/empty-data-directive.err new file mode 100644 index 00000000..dc4f03db --- /dev/null +++ b/test/asm/empty-data-directive.err @@ -0,0 +1,6 @@ +warning: empty-data-directive.asm(6): [-Wempty-data-directive] + db/dw/dl directive without data in ROM +warning: empty-data-directive.asm(7): [-Wempty-data-directive] + db/dw/dl directive without data in ROM +warning: empty-data-directive.asm(8): [-Wempty-data-directive] + db/dw/dl directive without data in ROM diff --git a/test/asm/empty-data-directive.out b/test/asm/empty-data-directive.out new file mode 100644 index 00000000..e69de29b