Index: lld/test/ELF/arm-ldrlit-err.s =================================================================== --- lld/test/ELF/arm-ldrlit-err.s +++ lld/test/ELF/arm-ldrlit-err.s @@ -8,6 +8,9 @@ bx lr nop nop + nop + nop + nop .section .text.1, "ax", %progbits .global _start @@ -27,3 +30,4 @@ .balign 4 high: bx lr + nop Index: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp =================================================================== --- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -11167,6 +11167,12 @@ "unexpected token in '.thumb_func' directive")) return true; + // .thumb_func implies .thumb + if (!isThumb()) + SwitchMode(); + + getParser().getStreamer().emitAssemblerFlag(MCAF_Code16); + NextSymbolIsThumb = true; return false; } Index: llvm/test/MC/ARM/thumb_func-implies-thumb.s =================================================================== --- /dev/null +++ llvm/test/MC/ARM/thumb_func-implies-thumb.s @@ -0,0 +1,20 @@ +@ 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