Skip to content

Commit ebdecf5

Browse files
committed
[ASM] Fix undefined symbol in define symbol
1 parent 4c84a0b commit ebdecf5

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

driver/asm_directive.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ Error AsmDirective::defineSymbol(
197197
context.value.clear();
198198
return setError(scan, error);
199199
}
200-
if (context.reportUndefined && context.value.isUndefined())
201-
return setError(symbol, UNDEFINED_SYMBOL);
200+
if (context.reportUndefined && error.getError() == UNDEFINED_SYMBOL)
201+
return setError(error);
202202

203203
setErrorIf(symbol, context.symbols.internSymbol(context.value.getUnsigned(), symbol, variable));
204204
return getError();

test/driver/test_asm_formatter.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,41 @@ z80:9:1: error: Duplicate label: "var1"
144144
)");
145145
}
146146

147+
void test_undefined() {
148+
PREP_ASM(mc6809::AsmMc6809, MotorolaDirective);
149+
150+
driver.setUpperHex(true);
151+
152+
ASM("mc6809",
153+
R"( org $1000
154+
label1: lda #0 ; comment
155+
label2: bra label1 comment
156+
lda #1 * comment
157+
)",
158+
R"( 1000 : org $1000
159+
1000 : 86 00 label1: lda #0 ; comment
160+
1002 : 20 FC label2: bra label1 comment
161+
mc6809:4:25: error: Undefined symbol: "comment"
162+
1004 : 86 00 lda #1 * comment
163+
)");
164+
165+
driver.clearSymbols();
166+
167+
ASM("mc6809",
168+
R"( org $1000
169+
label1: equ $1000 ; comment
170+
label2: equ label1 comment
171+
label3: equ 1 * comment
172+
)",
173+
R"( 1000 : org $1000
174+
1000 : =1000 label1: equ $1000 ; comment
175+
1000 : =1000 label2: equ label1 comment
176+
mc6809:4:25: error: Undefined symbol: "comment"
177+
1000 : =0 label3: equ 1 * comment
178+
)");
179+
180+
}
181+
147182
void test_switch_cpu() {
148183
mc6809::AsmMc6809 asm6809;
149184
MotorolaDirective dir6809(asm6809);
@@ -363,6 +398,7 @@ void run_tests() {
363398
RUN_TEST(test_symbols_mc6809);
364399
RUN_TEST(test_symbols_ins8060);
365400
RUN_TEST(test_symbols_z80);
401+
RUN_TEST(test_undefined);
366402
RUN_TEST(test_switch_cpu);
367403
RUN_TEST(test_list_radix);
368404
RUN_TEST(test_function);

0 commit comments

Comments
 (0)