Skip to content

Commit 61d5fa6

Browse files
committed
[WebAssembly] Fix error location for parsed symbol/label operands
The previous code didn't take account for the fact that parseExpression my lex additional tokens - because of this, it's necessary to record the location of the current token ahead of the call. This patch additionally makes use of the fact parseExpression will set its End parameter to the end of the expression. Although this fix could be added independently of D122127, I've opted to make it a child patch in order to ensure the change has some test coverage. Differential Revision: https://reviews.llvm.org/D122128
1 parent 0126375 commit 61d5fa6

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,12 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
671671
} else {
672672
// Assume this identifier is a label.
673673
const MCExpr *Val;
674+
SMLoc Start = Id.getLoc();
674675
SMLoc End;
675676
if (Parser.parseExpression(Val, End))
676677
return error("Cannot parse symbol: ", Lexer.getTok());
677678
Operands.push_back(std::make_unique<WebAssemblyOperand>(
678-
WebAssemblyOperand::Symbol, Id.getLoc(), Id.getEndLoc(),
679+
WebAssemblyOperand::Symbol, Start, End,
679680
WebAssemblyOperand::SymOp{Val}));
680681
if (checkForP2AlignIfLoadStore(Operands, Name))
681682
return true;

llvm/test/MC/WebAssembly/type-checker-errors.s

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ local_tee_type_mismatch:
5454

5555
global_get_missing_globaltype:
5656
.functype global_get_missing_globaltype () -> ()
57-
# FIXME: Error location should be at beginning of operand.
58-
# CHECK: :[[@LINE+1]]:17: error: symbol foo missing .globaltype
57+
# CHECK: :[[@LINE+1]]:14: error: symbol foo missing .globaltype
5958
global.get foo
6059
end_function
6160

@@ -67,8 +66,7 @@ global_get_expected_expression_operand:
6766

6867
global_set_missing_globaltype:
6968
.functype global_set_missing_globaltype () -> ()
70-
# FIXME: Error location should be at beginning of operand.
71-
# CHECK: :[[@LINE+1]]:17: error: symbol foo missing .globaltype
69+
# CHECK: :[[@LINE+1]]:14: error: symbol foo missing .globaltype
7270
global.set foo
7371
end_function
7472

@@ -101,8 +99,7 @@ table_get_expected_expression_operand:
10199

102100
table_get_missing_tabletype:
103101
.functype table_get_missing_tabletype () -> ()
104-
# FIXME: Error location should be at beginning of operand.
105-
# CHECK: :[[@LINE+1]]:16: error: symbol foo missing .tabletype
102+
# CHECK: :[[@LINE+1]]:13: error: symbol foo missing .tabletype
106103
table.get foo
107104
end_function
108105

@@ -129,8 +126,7 @@ table_set_expected_expression_operand:
129126

130127
table_set_missing_tabletype:
131128
.functype table_set_missing_tabletype () -> ()
132-
# FIXME: Error location should be at beginning ofoperand.
133-
# CHECK: :[[@LINE+1]]:16: error: symbol foo missing .tabletype
129+
# CHECK: :[[@LINE+1]]:13: error: symbol foo missing .tabletype
134130
table.set foo
135131
end_function
136132

@@ -170,8 +166,7 @@ table_fill_expected_expression_operand:
170166

171167
table_fill_missing_tabletype:
172168
.functype table_fill_missing_tabletype () -> ()
173-
# FIXME: Error location should be at beginning of operand.
174-
# CHECK: :[[@LINE+1]]:17: error: symbol foo missing .tabletype
169+
# CHECK: :[[@LINE+1]]:14: error: symbol foo missing .tabletype
175170
table.fill foo
176171
end_function
177172

@@ -418,8 +413,7 @@ call_superfluous_value_at_end:
418413

419414
call_missing_functype:
420415
.functype call_missing_functype () -> ()
421-
# FIXME: Error location should be at beginning of operand.
422-
# CHECK: :[[@LINE+1]]:19: error: symbol no_functype missing .functype
416+
# CHECK: :[[@LINE+1]]:8: error: symbol no_functype missing .functype
423417
call no_functype
424418
end_function
425419

@@ -444,8 +438,7 @@ return_call_type_mismatch:
444438

445439
return_call_missing_functype:
446440
.functype return_call_missing_functype () -> ()
447-
# FIXME: Error location should be at beginning of operand.
448-
# CHECK: :[[@LINE+1]]:26: error: symbol no_functype missing .functype
441+
# CHECK: :[[@LINE+1]]:15: error: symbol no_functype missing .functype
449442
return_call no_functype
450443
end_function
451444

@@ -460,8 +453,7 @@ catch_expected_expression_operand:
460453
catch_missing_tagtype:
461454
.functype catch_missing_tagtype () -> ()
462455
try
463-
# FIXME: Error location should be at beginning of operand.
464-
# CHECK: :[[@LINE+1]]:19: error: symbol no_tagtype missing .tagtype
456+
# CHECK: :[[@LINE+1]]:9: error: symbol no_tagtype missing .tagtype
465457
catch no_tagtype
466458
end_try
467459
end_function

0 commit comments

Comments
 (0)