Add empty data directive warning

Fixes #516
This commit is contained in:
James Larrowe
2020-05-05 10:27:55 -04:00
parent 12693081c9
commit bdf397bba7
8 changed files with 38 additions and 6 deletions

View File

@@ -10,6 +10,7 @@
#define RGBDS_SECTION_H
#include <stdint.h>
#include <stdbool.h>
#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);

View File

@@ -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,

View File

@@ -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); }

View File

@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#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) {

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File