[llvm] r297454 - [Assembler] Add location info to unary expressions.

Sanne Wouda via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 05:08:22 PST 2017


Author: sanwou01
Date: Fri Mar 10 07:08:20 2017
New Revision: 297454

URL: http://llvm.org/viewvc/llvm-project?rev=297454&view=rev
Log:
[Assembler] Add location info to unary expressions.

Summary:
This is a continuation of D28861.  Add an SMLoc to MCUnaryExpr such that
a better diagnostic can be given in case of an error in later stages of
assembling.

Reviewers: rengolin, grosbach, javed.absar, olista01

Reviewed By: olista01

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D30581

Modified:
    llvm/trunk/include/llvm/MC/MCExpr.h
    llvm/trunk/lib/MC/MCExpr.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/test/MC/AArch64/error-location-post-layout.s
    llvm/trunk/test/MC/ARM/error-location-post-layout.s

Modified: llvm/trunk/include/llvm/MC/MCExpr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCExpr.h?rev=297454&r1=297453&r2=297454&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCExpr.h (original)
+++ llvm/trunk/include/llvm/MC/MCExpr.h Fri Mar 10 07:08:20 2017
@@ -351,30 +351,30 @@ private:
   Opcode Op;
   const MCExpr *Expr;
 
-  MCUnaryExpr(Opcode Op, const MCExpr *Expr)
-      : MCExpr(MCExpr::Unary, SMLoc()), Op(Op), Expr(Expr) {}
+  MCUnaryExpr(Opcode Op, const MCExpr *Expr, SMLoc Loc)
+      : MCExpr(MCExpr::Unary, Loc), Op(Op), Expr(Expr) {}
 
 public:
   /// \name Construction
   /// @{
 
   static const MCUnaryExpr *create(Opcode Op, const MCExpr *Expr,
-                                   MCContext &Ctx);
+                                   MCContext &Ctx, SMLoc Loc = SMLoc());
 
-  static const MCUnaryExpr *createLNot(const MCExpr *Expr, MCContext &Ctx) {
-    return create(LNot, Expr, Ctx);
+  static const MCUnaryExpr *createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
+    return create(LNot, Expr, Ctx, Loc);
   }
 
-  static const MCUnaryExpr *createMinus(const MCExpr *Expr, MCContext &Ctx) {
-    return create(Minus, Expr, Ctx);
+  static const MCUnaryExpr *createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
+    return create(Minus, Expr, Ctx, Loc);
   }
 
-  static const MCUnaryExpr *createNot(const MCExpr *Expr, MCContext &Ctx) {
-    return create(Not, Expr, Ctx);
+  static const MCUnaryExpr *createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
+    return create(Not, Expr, Ctx, Loc);
   }
 
-  static const MCUnaryExpr *createPlus(const MCExpr *Expr, MCContext &Ctx) {
-    return create(Plus, Expr, Ctx);
+  static const MCUnaryExpr *createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
+    return create(Plus, Expr, Ctx, Loc);
   }
 
   /// @}

Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=297454&r1=297453&r2=297454&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Fri Mar 10 07:08:20 2017
@@ -152,8 +152,8 @@ const MCBinaryExpr *MCBinaryExpr::create
 }
 
 const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
-                                       MCContext &Ctx) {
-  return new (Ctx) MCUnaryExpr(Opc, Expr);
+                                       MCContext &Ctx, SMLoc Loc) {
+  return new (Ctx) MCUnaryExpr(Opc, Expr, Loc);
 }
 
 const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) {

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=297454&r1=297453&r2=297454&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Mar 10 07:08:20 2017
@@ -924,7 +924,7 @@ bool AsmParser::parsePrimaryExpr(const M
     Lex(); // Eat the operator.
     if (parsePrimaryExpr(Res, EndLoc))
       return true;
-    Res = MCUnaryExpr::createLNot(Res, getContext());
+    Res = MCUnaryExpr::createLNot(Res, getContext(), FirstTokenLoc);
     return false;
   case AsmToken::Dollar:
   case AsmToken::At:
@@ -1077,19 +1077,19 @@ bool AsmParser::parsePrimaryExpr(const M
     Lex(); // Eat the operator.
     if (parsePrimaryExpr(Res, EndLoc))
       return true;
-    Res = MCUnaryExpr::createMinus(Res, getContext());
+    Res = MCUnaryExpr::createMinus(Res, getContext(), FirstTokenLoc);
     return false;
   case AsmToken::Plus:
     Lex(); // Eat the operator.
     if (parsePrimaryExpr(Res, EndLoc))
       return true;
-    Res = MCUnaryExpr::createPlus(Res, getContext());
+    Res = MCUnaryExpr::createPlus(Res, getContext(), FirstTokenLoc);
     return false;
   case AsmToken::Tilde:
     Lex(); // Eat the operator.
     if (parsePrimaryExpr(Res, EndLoc))
       return true;
-    Res = MCUnaryExpr::createNot(Res, getContext());
+    Res = MCUnaryExpr::createNot(Res, getContext(), FirstTokenLoc);
     return false;
   // MIPS unary expression operators. The lexer won't generate these tokens if
   // MCAsmInfo::HasMipsExpressions is false for the target.

Modified: llvm/trunk/test/MC/AArch64/error-location-post-layout.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/error-location-post-layout.s?rev=297454&r1=297453&r2=297454&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/error-location-post-layout.s (original)
+++ llvm/trunk/test/MC/AArch64/error-location-post-layout.s Fri Mar 10 07:08:20 2017
@@ -1,7 +1,7 @@
 // RUN: not llvm-mc -triple aarch64--none-eabi -filetype obj < %s -o /dev/null 2>&1 | FileCheck %s
 
   .set v1, -undef
-// CHECK: <unknown>:0: error: expression could not be evaluated
+// CHECK: 3:12: error: expression could not be evaluated
 
   .comm common, 4
   .set v3, common

Modified: llvm/trunk/test/MC/ARM/error-location-post-layout.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/error-location-post-layout.s?rev=297454&r1=297453&r2=297454&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/error-location-post-layout.s (original)
+++ llvm/trunk/test/MC/ARM/error-location-post-layout.s Fri Mar 10 07:08:20 2017
@@ -1,7 +1,7 @@
 @ RUN: not llvm-mc -triple armv7a--none-eabi -filetype obj < %s -o /dev/null 2>&1 | FileCheck %s
 
   .set v1, -undef
-@ CHECK: <unknown>:0: error: expression could not be evaluated
+@ CHECK: 3:12: error: expression could not be evaluated
 
   .comm common, 4
   .set v3, common




More information about the llvm-commits mailing list