diff --git a/src/asm/output.c b/src/asm/output.c index e7c1902a..ed643df7 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -1,7 +1,7 @@ /* * This file is part of RGBDS. * - * Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors. + * Copyright (c) 1997-2019, Carsten Sorensen and RGBDS contributors. * * SPDX-License-Identifier: MIT */ @@ -655,7 +655,7 @@ void out_SetCurrentSection(struct Section *pSect) fatalerror("Cannot change the section within a UNION"); pCurrentSection = pSect; - nPC = pSect->nPC; + nPC = (pSect != NULL) ? pSect->nPC : 0; pPCSymbol->nValue = nPC; pPCSymbol->pSection = pCurrentSection; diff --git a/test/asm/pops-no-pushed-sections.asm b/test/asm/pops-no-pushed-sections.asm new file mode 100644 index 00000000..4150a093 --- /dev/null +++ b/test/asm/pops-no-pushed-sections.asm @@ -0,0 +1 @@ +POPS diff --git a/test/asm/pops-no-pushed-sections.out b/test/asm/pops-no-pushed-sections.out new file mode 100644 index 00000000..4f8c06c1 --- /dev/null +++ b/test/asm/pops-no-pushed-sections.out @@ -0,0 +1,2 @@ +ERROR: pops-no-pushed-sections.asm(1): + No entries in the section stack diff --git a/test/asm/pops-no-pushed-sections.out.pipe b/test/asm/pops-no-pushed-sections.out.pipe new file mode 100644 index 00000000..9e3a0bf8 --- /dev/null +++ b/test/asm/pops-no-pushed-sections.out.pipe @@ -0,0 +1,2 @@ +ERROR: -(1): + No entries in the section stack diff --git a/test/asm/pops-restore-no-section.asm b/test/asm/pops-restore-no-section.asm new file mode 100644 index 00000000..c6fef881 --- /dev/null +++ b/test/asm/pops-restore-no-section.asm @@ -0,0 +1,10 @@ +PUSHS + +SECTION "Test", ROM0 +SomeContent: + db 1, 2, 3, 4, 5, 6, 7, 8, 9 + +POPS + +DisallowedContent: + db 0 diff --git a/test/asm/pops-restore-no-section.out b/test/asm/pops-restore-no-section.out new file mode 100644 index 00000000..3a0e1cbe --- /dev/null +++ b/test/asm/pops-restore-no-section.out @@ -0,0 +1,2 @@ +ERROR: pops-restore-no-section.asm(10): + Code generation before SECTION directive diff --git a/test/asm/pops-restore-no-section.out.pipe b/test/asm/pops-restore-no-section.out.pipe new file mode 100644 index 00000000..b0a3984a --- /dev/null +++ b/test/asm/pops-restore-no-section.out.pipe @@ -0,0 +1,2 @@ +ERROR: -(10): + Code generation before SECTION directive diff --git a/test/asm/pushs-outside-section.asm b/test/asm/pushs-outside-section.asm new file mode 100644 index 00000000..8226722c --- /dev/null +++ b/test/asm/pushs-outside-section.asm @@ -0,0 +1,2 @@ +PUSHS +POPS diff --git a/test/asm/pushs-outside-section.out b/test/asm/pushs-outside-section.out new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/pushs-outside-section.out.pipe b/test/asm/pushs-outside-section.out.pipe new file mode 100644 index 00000000..e69de29b