From 122f5fe12e69bf66d89d22b639e162f63f6a95a9 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 4 Nov 2019 03:34:18 +0100 Subject: [PATCH] Prevent creating labels outside of sections This doesn't make sense, and causes RGBLINK to misbehave --- src/asm/symbol.c | 4 ++++ test/asm/label-macro-arg.out | 3 +++ test/asm/label-outside-section.asm | 4 ++++ test/asm/label-outside-section.out | 4 ++++ test/asm/line-continuation-whitespace.out | 3 +++ test/asm/line-continuation.out | 3 +++ test/asm/macro-@.out | 2 ++ test/asm/pops-restore-no-section.out | 2 ++ 8 files changed, 25 insertions(+) create mode 100644 test/asm/label-outside-section.asm create mode 100644 test/asm/label-outside-section.out diff --git a/src/asm/symbol.c b/src/asm/symbol.c index b62349ef..5fd08ed2 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -634,6 +634,10 @@ void sym_AddReloc(char *tzSym) nsym->pScope = scope; nsym->pSection = pCurrentSection; + /* Labels need to be assigned a section, except PC */ + if (!pCurrentSection && strcmp(tzSym, "@")) + yyerror("Label \"%s\" created outside of a SECTION", + tzSym); updateSymbolFilename(nsym); } diff --git a/test/asm/label-macro-arg.out b/test/asm/label-macro-arg.out index 6a76e93f..f0e94c5d 100644 --- a/test/asm/label-macro-arg.out +++ b/test/asm/label-macro-arg.out @@ -1,3 +1,6 @@ +ERROR: label-macro-arg.asm(45) -> label-macro-arg.asm::test_char(31): + Label "sizeof_" created outside of a SECTION +while expanding symbol "VAR_DEF" ERROR: label-macro-arg.asm(45) -> label-macro-arg.asm::test_char(31): Macro 'something' not defined $5 diff --git a/test/asm/label-outside-section.asm b/test/asm/label-outside-section.asm new file mode 100644 index 00000000..e0bc2772 --- /dev/null +++ b/test/asm/label-outside-section.asm @@ -0,0 +1,4 @@ +bad: +SECTION "Test", ROM0 +good: + PRINTT "OK!\n" diff --git a/test/asm/label-outside-section.out b/test/asm/label-outside-section.out new file mode 100644 index 00000000..757b3b6d --- /dev/null +++ b/test/asm/label-outside-section.out @@ -0,0 +1,4 @@ +ERROR: label-outside-section.asm(1): + Label "bad" created outside of a SECTION +error: Assembly aborted (1 errors)! +OK! diff --git a/test/asm/line-continuation-whitespace.out b/test/asm/line-continuation-whitespace.out index e69de29b..83122438 100644 --- a/test/asm/line-continuation-whitespace.out +++ b/test/asm/line-continuation-whitespace.out @@ -0,0 +1,3 @@ +ERROR: line-continuation-whitespace.asm(7): + Label "foo" created outside of a SECTION +error: Assembly aborted (1 errors)! diff --git a/test/asm/line-continuation.out b/test/asm/line-continuation.out index e69de29b..4da7e2c1 100644 --- a/test/asm/line-continuation.out +++ b/test/asm/line-continuation.out @@ -0,0 +1,3 @@ +ERROR: line-continuation.asm(7): + Label "foo" created outside of a SECTION +error: Assembly aborted (1 errors)! diff --git a/test/asm/macro-@.out b/test/asm/macro-@.out index d31f4c95..1284eecb 100644 --- a/test/asm/macro-@.out +++ b/test/asm/macro-@.out @@ -1,2 +1,4 @@ +ERROR: macro-@.asm(1): + Label "foo" created outside of a SECTION ERROR: macro-@.asm(1): Macro '@' not defined diff --git a/test/asm/pops-restore-no-section.out b/test/asm/pops-restore-no-section.out index 3a0e1cbe..4eac4442 100644 --- a/test/asm/pops-restore-no-section.out +++ b/test/asm/pops-restore-no-section.out @@ -1,2 +1,4 @@ +ERROR: pops-restore-no-section.asm(9): + Label "DisallowedContent" created outside of a SECTION ERROR: pops-restore-no-section.asm(10): Code generation before SECTION directive