[llvm] f876383 - [AsmParser][ARM] Make .thumb_func imply .thumb
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 7 03:13:43 PDT 2021
Author: LemonBoy
Date: 2021-05-07T12:13:36+02:00
New Revision: f87638338464e7ff9396e92e04e3f5702d479d39
URL: https://github.com/llvm/llvm-project/commit/f87638338464e7ff9396e92e04e3f5702d479d39
DIFF: https://github.com/llvm/llvm-project/commit/f87638338464e7ff9396e92e04e3f5702d479d39.diff
LOG: [AsmParser][ARM] Make .thumb_func imply .thumb
GNU as documentation states that a `.thumb_func` directive implies `.thumb`, teach the asm parser to switch mode whenever it's encountered. On the other hand the labeled form, exclusive to Apple's toolchain, doesn't switch mode at all.
Reviewed By: nickdesaulniers, peter.smith
Differential Revision: https://reviews.llvm.org/D101975
Added:
llvm/test/MC/ARM/thumb_func-implies-thumb.s
Modified:
lld/test/ELF/arm-ldrlit-err.s
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
Removed:
################################################################################
diff --git a/lld/test/ELF/arm-ldrlit-err.s b/lld/test/ELF/arm-ldrlit-err.s
index 3ee488f644b26..2543421551042 100644
--- a/lld/test/ELF/arm-ldrlit-err.s
+++ b/lld/test/ELF/arm-ldrlit-err.s
@@ -8,6 +8,9 @@ low:
bx lr
nop
nop
+ nop
+ nop
+ nop
.section .text.1, "ax", %progbits
.global _start
@@ -27,3 +30,4 @@ _start:
.balign 4
high:
bx lr
+ nop
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 6be4270134654..dcd9ec3f7ae76 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -11165,6 +11165,12 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
"unexpected token in '.thumb_func' directive"))
return true;
+ // .thumb_func implies .thumb
+ if (!isThumb())
+ SwitchMode();
+
+ getParser().getStreamer().emitAssemblerFlag(MCAF_Code16);
+
NextSymbolIsThumb = true;
return false;
}
diff --git a/llvm/test/MC/ARM/thumb_func-implies-thumb.s b/llvm/test/MC/ARM/thumb_func-implies-thumb.s
new file mode 100644
index 0000000000000..342cc4a5f0b51
--- /dev/null
+++ b/llvm/test/MC/ARM/thumb_func-implies-thumb.s
@@ -0,0 +1,31 @@
+@ RUN: llvm-mc -triple=armv7-darwin- -show-encoding < %s | FileCheck %s
+.syntax unified
+
+.text
+
+.arm
+@ Ensure the plain form switches mode.
+.thumb_func
+@ CHECK: .code 16
+@ CHECK-LABEL: foo
+foo:
+ bx lr
+
+.arm
+@ Ensure the labeled form doesn't switch mode.
+.thumb_func bar
+@ CHECK-NOT: .code 16
+@ CHECK-LABEL: bar
+bar:
+ bx lr
+
+.arm
+@ Ensure the nop is assembled in thumb mode, even though the baz symbol is
+@ defined later.
+.thumb_func
+nop
+@ CHECK: .code 16
+@ CHECK-NEXT: nop
+@ CHECK-LABEL: baz
+baz:
+ bx lr
More information about the llvm-commits
mailing list