From 4c5d5c708591fa878fcba297172da2d51579f908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C4=85dzio=C5=82ka?= Date: Mon, 12 Oct 2020 13:28:00 +0200 Subject: [PATCH] Don't consider difference of invalid labels constant If a label is defined outside of a section, avoid trying to obtain its value. --- src/asm/rpn.c | 4 +++- test/asm/use-label-outside-section.asm | 3 +++ test/asm/use-label-outside-section.err | 5 +++++ test/asm/use-label-outside-section.out | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/asm/use-label-outside-section.asm create mode 100644 test/asm/use-label-outside-section.err create mode 100644 test/asm/use-label-outside-section.out diff --git a/src/asm/rpn.c b/src/asm/rpn.c index bb7aa871..446e0161 100644 --- a/src/asm/rpn.c +++ b/src/asm/rpn.c @@ -307,7 +307,9 @@ bool rpn_IsDiffConstant(struct Expression const *src, struct Symbol const *sym) if (!sym1 || !sym || sym1->type != SYM_LABEL || sym->type != SYM_LABEL) return false; - return sym_GetSection(sym1) == sym_GetSection(sym); + struct Section const *section1 = sym_GetSection(sym1); + struct Section const *section2 = sym_GetSection(sym); + return section1 && (section1 == section2); } static bool isDiffConstant(struct Expression const *src1, diff --git a/test/asm/use-label-outside-section.asm b/test/asm/use-label-outside-section.asm new file mode 100644 index 00000000..73440b5d --- /dev/null +++ b/test/asm/use-label-outside-section.asm @@ -0,0 +1,3 @@ +lab: + PRINTV lab-lab + PRINTT "\n" diff --git a/test/asm/use-label-outside-section.err b/test/asm/use-label-outside-section.err new file mode 100644 index 00000000..893a7012 --- /dev/null +++ b/test/asm/use-label-outside-section.err @@ -0,0 +1,5 @@ +ERROR: use-label-outside-section.asm(1): + Label "lab" created outside of a SECTION +ERROR: use-label-outside-section.asm(2): + Expected constant expression: 'lab' is not constant at assembly time +error: Assembly aborted (2 errors)! diff --git a/test/asm/use-label-outside-section.out b/test/asm/use-label-outside-section.out new file mode 100644 index 00000000..ebfabbe4 --- /dev/null +++ b/test/asm/use-label-outside-section.out @@ -0,0 +1 @@ +$0