shithub: rgbds

Download patch

ref: 645473e336e389db6bacad12eef38c9d86119638
parent: 781a65ee498cf810d74168d43934407d60edd666
parent: bdf397bba7f5acc64202a60e56bf197d64ad098d
author: Eldred Habert <[email protected]>
date: Wed May 6 12:25:03 EDT 2020

Merge pull request #518 from JL2210/warn-parameterless-dx

Add empty data directive warning

--- a/include/asm/section.h
+++ b/include/asm/section.h
@@ -10,6 +10,7 @@
 #define RGBDS_SECTION_H
 
 #include <stdint.h>
+#include <stdbool.h>
 
 #include "linkdefs.h"
 
@@ -48,7 +49,7 @@
 
 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);
--- a/include/asm/warning.h
+++ b/include/asm/warning.h
@@ -17,6 +17,7 @@
 	WARNING_ASSERT,
 	WARNING_BUILTIN_ARG,
 	WARNING_DIV,
+	WARNING_EMPTY_DATA_DIRECTIVE,
 	WARNING_EMPTY_ENTRY,
 	WARNING_LARGE_CONSTANT,
 	WARNING_LONG_STR,
--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -995,7 +995,7 @@
 		}
 ;
 
-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_entry : /* empty */ {
-			out_Skip(1);
+			out_Skip(1, false);
 			nListCountEmpty++;
 		}
 		| reloc_8bit_no_str	{ out_RelByte(&$1); }
@@ -1207,7 +1207,7 @@
 ;
 
 constlist_16bit_entry : /* empty */ {
-			out_Skip(2);
+			out_Skip(2, false);
 			nListCountEmpty++;
 		}
 		| reloc_16bit	{ out_RelWord(&$1); }
@@ -1218,7 +1218,7 @@
 ;
 
 constlist_32bit_entry : /* empty */ {
-			out_Skip(4);
+			out_Skip(4, false);
 			nListCountEmpty++;
 		}
 		| relocexpr	{ out_RelLong(&$1); }
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -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,10 +435,13 @@
 /*
  * 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);
--- a/src/asm/warning.c
+++ b/src/asm/warning.c
@@ -31,6 +31,7 @@
 	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 @@
 	"assert",
 	"builtin-args",
 	"div",
+	"empty-data-directive",
 	"empty-entry",
 	"large-constant",
 	"long-string",
@@ -90,6 +92,7 @@
 /* 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 _weverythingCommands[] = {
 	WARNING_BUILTIN_ARG,
 	WARNING_DIV,
+	WARNING_EMPTY_DATA_DIRECTIVE,
 	WARNING_EMPTY_ENTRY,
 	WARNING_LARGE_CONSTANT,
 	WARNING_LONG_STR,
--- /dev/null
+++ b/test/asm/empty-data-directive.asm
@@ -1,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
--- /dev/null
+++ b/test/asm/empty-data-directive.err
@@ -1,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