[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 06:16:14 PDT 2024
https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/99648
None
>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] [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
More information about the llvm-commits
mailing list