[llvm] [MC,ELF] Use loc from the directive for `.abort` (PR #99648)

Dmitriy Chestnykh via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 08:57:49 PDT 2024


https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/99648

>From f7ae5549d4009c2e5fb8efe1d24f1e3217574e98 Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh <dm.chestnykh at gmail.com>
Date: Fri, 19 Jul 2024 16:14:03 +0300
Subject: [PATCH 1/5] [MC,ELF] Use loc from the directive for `.abort`

---
 llvm/lib/MC/MCParser/AsmParser.cpp | 14 ++++++--------
 llvm/test/MC/ELF/abort.s           |  9 +++++++++
 2 files changed, 15 insertions(+), 8 deletions(-)
 create mode 100644 llvm/test/MC/ELF/abort.s

diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index d05712bca73cd..e96c78b771588 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -658,7 +658,7 @@ class AsmParser : public MCAsmParser {
 
   bool parseDirectiveComm(bool IsLocal); // ".comm" and ".lcomm"
 
-  bool parseDirectiveAbort(); // ".abort"
+  bool parseDirectiveAbort(SMLoc DirectiveLoc); // ".abort"
   bool parseDirectiveInclude(); // ".include"
   bool parseDirectiveIncbin(); // ".incbin"
 
@@ -2120,7 +2120,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
     case DK_LCOMM:
       return parseDirectiveComm(/*IsLocal=*/true);
     case DK_ABORT:
-      return parseDirectiveAbort();
+      return parseDirectiveAbort(IDLoc);
     case DK_INCLUDE:
       return parseDirectiveInclude();
     case DK_INCBIN:
@@ -5095,18 +5095,16 @@ bool AsmParser::parseDirectiveComm(bool IsLocal) {
 
 /// parseDirectiveAbort
 ///  ::= .abort [... message ...]
-bool AsmParser::parseDirectiveAbort() {
-  // FIXME: Use loc from directive.
-  SMLoc Loc = getLexer().getLoc();
-
+bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
   StringRef Str = parseStringToEndOfStatement();
   if (parseEOL())
     return true;
 
   if (Str.empty())
-    return Error(Loc, ".abort detected. Assembly stopping.");
+    return Error(DirectiveLoc, ".abort detected. Assembly stopping.");
   else
-    return Error(Loc, ".abort '" + Str + "' detected. Assembly stopping.");
+    return Error(DirectiveLoc,
+                 ".abort '" + Str + "' detected. Assembly stopping.");
   // FIXME: Actually abort assembly here.
 
   return false;
diff --git a/llvm/test/MC/ELF/abort.s b/llvm/test/MC/ELF/abort.s
new file mode 100644
index 0000000000000..808555973cd8d
--- /dev/null
+++ b/llvm/test/MC/ELF/abort.s
@@ -0,0 +1,9 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64 %s 2>&1 -o /dev/null | FileCheck %s
+
+.abort
+// CHECK:      [[#@LINE-1]]:1: error: .abort detected. Assembly stopping.
+// CHECK-NEXT: abort
+
+.abort "abort message"
+// CHECK:      [[#@LINE-1]]:1: error: .abort '"abort message"' detected. Assembly stopping.
+// CHECK-NEXT: abort

>From 96ee18e7de7836a9f50930c12d085f6f557f976d Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh <dm.chestnykh at gmail.com>
Date: Fri, 19 Jul 2024 16:44:29 +0300
Subject: [PATCH 2/5] [MC,ELF] Remove unreachable return

---
 llvm/lib/MC/MCParser/AsmParser.cpp | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index e96c78b771588..4fd912a6701c2 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -5102,12 +5102,9 @@ bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
 
   if (Str.empty())
     return Error(DirectiveLoc, ".abort detected. Assembly stopping.");
-  else
-    return Error(DirectiveLoc,
-                 ".abort '" + Str + "' detected. Assembly stopping.");
-  // FIXME: Actually abort assembly here.
 
-  return false;
+  return Error(DirectiveLoc,
+               ".abort '" + Str + "' detected. Assembly stopping.");
 }
 
 /// parseDirectiveInclude

>From 032e49301341847becf5b6b4b25df1cb74c9cf07 Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh <dm.chestnykh at gmail.com>
Date: Fri, 19 Jul 2024 16:48:08 +0300
Subject: [PATCH 3/5] [MC,ELF] Rewrite directive_abort.s test

---
 llvm/test/MC/AsmParser/directive_abort.s | 13 ++++++++-----
 llvm/test/MC/ELF/abort.s                 |  9 ---------
 2 files changed, 8 insertions(+), 14 deletions(-)
 delete mode 100644 llvm/test/MC/ELF/abort.s

diff --git a/llvm/test/MC/AsmParser/directive_abort.s b/llvm/test/MC/AsmParser/directive_abort.s
index 86e6267a7a1eb..808555973cd8d 100644
--- a/llvm/test/MC/AsmParser/directive_abort.s
+++ b/llvm/test/MC/AsmParser/directive_abort.s
@@ -1,6 +1,9 @@
-# RUN: not llvm-mc -triple i386-unknown-unknown %s 2> %t
-# RUN: FileCheck -input-file %t %s
+// RUN: not llvm-mc -filetype=obj -triple x86_64 %s 2>&1 -o /dev/null | FileCheck %s
 
-# CHECK: error: .abort 'please stop assembing'
-TEST0:
-	.abort       please stop assembing
+.abort
+// CHECK:      [[#@LINE-1]]:1: error: .abort detected. Assembly stopping.
+// CHECK-NEXT: abort
+
+.abort "abort message"
+// CHECK:      [[#@LINE-1]]:1: error: .abort '"abort message"' detected. Assembly stopping.
+// CHECK-NEXT: abort
diff --git a/llvm/test/MC/ELF/abort.s b/llvm/test/MC/ELF/abort.s
deleted file mode 100644
index 808555973cd8d..0000000000000
--- a/llvm/test/MC/ELF/abort.s
+++ /dev/null
@@ -1,9 +0,0 @@
-// RUN: not llvm-mc -filetype=obj -triple x86_64 %s 2>&1 -o /dev/null | FileCheck %s
-
-.abort
-// CHECK:      [[#@LINE-1]]:1: error: .abort detected. Assembly stopping.
-// CHECK-NEXT: abort
-
-.abort "abort message"
-// CHECK:      [[#@LINE-1]]:1: error: .abort '"abort message"' detected. Assembly stopping.
-// CHECK-NEXT: abort

>From d7b993e6e79ea1209c55d0926c7740e66652342b Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh <dm.chestnykh at gmail.com>
Date: Fri, 19 Jul 2024 17:04:34 +0300
Subject: [PATCH 4/5] [MC,ELF] Rectore accidentally removed comment

---
 llvm/lib/MC/MCParser/AsmParser.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 4fd912a6701c2..ab357fec8ae2c 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -5103,6 +5103,7 @@ bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
   if (Str.empty())
     return Error(DirectiveLoc, ".abort detected. Assembly stopping.");
 
+  // FIXME: Actually abort assembly here.
   return Error(DirectiveLoc,
                ".abort '" + Str + "' detected. Assembly stopping.");
 }

>From 082a6d8b25f2215b6206b0a89501a36996da1a88 Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh <dm.chestnykh at gmail.com>
Date: Fri, 19 Jul 2024 18:59:24 +0300
Subject: [PATCH 5/5] [MC,AsmParser] Remove trailing period from the diag
 message

---
 llvm/lib/MC/MCParser/AsmParser.cpp       | 5 ++---
 llvm/test/MC/AsmParser/directive_abort.s | 4 ++--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index ab357fec8ae2c..77e2dcba815bf 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -5101,11 +5101,10 @@ bool AsmParser::parseDirectiveAbort(SMLoc DirectiveLoc) {
     return true;
 
   if (Str.empty())
-    return Error(DirectiveLoc, ".abort detected. Assembly stopping.");
+    return Error(DirectiveLoc, ".abort detected. Assembly stopping");
 
-  // FIXME: Actually abort assembly here.
   return Error(DirectiveLoc,
-               ".abort '" + Str + "' detected. Assembly stopping.");
+               ".abort '" + Str + "' detected. Assembly stopping");
 }
 
 /// parseDirectiveInclude
diff --git a/llvm/test/MC/AsmParser/directive_abort.s b/llvm/test/MC/AsmParser/directive_abort.s
index 808555973cd8d..f4dda229a017b 100644
--- a/llvm/test/MC/AsmParser/directive_abort.s
+++ b/llvm/test/MC/AsmParser/directive_abort.s
@@ -1,9 +1,9 @@
 // RUN: not llvm-mc -filetype=obj -triple x86_64 %s 2>&1 -o /dev/null | FileCheck %s
 
 .abort
-// CHECK:      [[#@LINE-1]]:1: error: .abort detected. Assembly stopping.
+// CHECK:      [[#@LINE-1]]:1: error: .abort detected. Assembly stopping
 // CHECK-NEXT: abort
 
 .abort "abort message"
-// CHECK:      [[#@LINE-1]]:1: error: .abort '"abort message"' detected. Assembly stopping.
+// CHECK:      [[#@LINE-1]]:1: error: .abort '"abort message"' detected. Assembly stopping
 // CHECK-NEXT: abort



More information about the llvm-commits mailing list