[llvm] 61d5fa6 - [WebAssembly] Fix error location for parsed symbol/label operands

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 23 01:53:35 PDT 2022


Author: Alex Bradbury
Date: 2022-03-23T08:53:05Z
New Revision: 61d5fa6b62bbfd788d290537dab073beefb8298b

URL: https://github.com/llvm/llvm-project/commit/61d5fa6b62bbfd788d290537dab073beefb8298b
DIFF: https://github.com/llvm/llvm-project/commit/61d5fa6b62bbfd788d290537dab073beefb8298b.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
    llvm/test/MC/WebAssembly/type-checker-errors.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index aa9b011e50121..8da0a4ccc35a9 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -671,11 +671,12 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
         } else {
           // Assume this identifier is a label.
           const MCExpr *Val;
+          SMLoc Start = Id.getLoc();
           SMLoc End;
           if (Parser.parseExpression(Val, End))
             return error("Cannot parse symbol: ", Lexer.getTok());
           Operands.push_back(std::make_unique<WebAssemblyOperand>(
-              WebAssemblyOperand::Symbol, Id.getLoc(), Id.getEndLoc(),
+              WebAssemblyOperand::Symbol, Start, End,
               WebAssemblyOperand::SymOp{Val}));
           if (checkForP2AlignIfLoadStore(Operands, Name))
             return true;

diff  --git a/llvm/test/MC/WebAssembly/type-checker-errors.s b/llvm/test/MC/WebAssembly/type-checker-errors.s
index 0f890408510cc..1197a49ffa743 100644
--- a/llvm/test/MC/WebAssembly/type-checker-errors.s
+++ b/llvm/test/MC/WebAssembly/type-checker-errors.s
@@ -54,8 +54,7 @@ local_tee_type_mismatch:
 
 global_get_missing_globaltype:
   .functype global_get_missing_globaltype () -> ()
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:17: error: symbol foo missing .globaltype
+# CHECK: :[[@LINE+1]]:14: error: symbol foo missing .globaltype
   global.get foo
   end_function
 
@@ -67,8 +66,7 @@ global_get_expected_expression_operand:
 
 global_set_missing_globaltype:
   .functype global_set_missing_globaltype () -> ()
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:17: error: symbol foo missing .globaltype
+# CHECK: :[[@LINE+1]]:14: error: symbol foo missing .globaltype
   global.set foo
   end_function
 
@@ -101,8 +99,7 @@ table_get_expected_expression_operand:
 
 table_get_missing_tabletype:
   .functype table_get_missing_tabletype () -> ()
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:16: error: symbol foo missing .tabletype
+# CHECK: :[[@LINE+1]]:13: error: symbol foo missing .tabletype
   table.get foo
   end_function
 
@@ -129,8 +126,7 @@ table_set_expected_expression_operand:
 
 table_set_missing_tabletype:
   .functype table_set_missing_tabletype () -> ()
-# FIXME: Error location should be at beginning ofoperand.
-# CHECK: :[[@LINE+1]]:16: error: symbol foo missing .tabletype
+# CHECK: :[[@LINE+1]]:13: error: symbol foo missing .tabletype
   table.set foo
   end_function
 
@@ -170,8 +166,7 @@ table_fill_expected_expression_operand:
 
 table_fill_missing_tabletype:
   .functype table_fill_missing_tabletype () -> ()
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:17: error: symbol foo missing .tabletype
+# CHECK: :[[@LINE+1]]:14: error: symbol foo missing .tabletype
   table.fill foo
   end_function
 
@@ -418,8 +413,7 @@ call_superfluous_value_at_end:
 
 call_missing_functype:
   .functype call_missing_functype () -> ()
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:19: error: symbol no_functype missing .functype
+# CHECK: :[[@LINE+1]]:8: error: symbol no_functype missing .functype
   call no_functype
   end_function
 
@@ -444,8 +438,7 @@ return_call_type_mismatch:
 
 return_call_missing_functype:
   .functype return_call_missing_functype () -> ()
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:26: error: symbol no_functype missing .functype
+# CHECK: :[[@LINE+1]]:15: error: symbol no_functype missing .functype
   return_call no_functype
   end_function
 
@@ -460,8 +453,7 @@ catch_expected_expression_operand:
 catch_missing_tagtype:
   .functype catch_missing_tagtype () -> ()
   try
-# FIXME: Error location should be at beginning of operand.
-# CHECK: :[[@LINE+1]]:19: error: symbol no_tagtype missing .tagtype
+# CHECK: :[[@LINE+1]]:9: error: symbol no_tagtype missing .tagtype
   catch no_tagtype
   end_try
   end_function


        


More information about the llvm-commits mailing list