From 8c692b1fb7066095f35b4fe57692dddb8a426d87 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Thu, 30 Aug 2018 21:19:35 +0100
Subject: [PATCH] [llvm, ARM] Make .thumb_func imply .thumb.

For compatibility with BINUTILS GAS.
---
 llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index a5fbbbf26be..1801f24279e 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -9475,10 +9475,17 @@ bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
     }
   }
 
+  // For compatibility with GAS assembler, the .thumb_func implies
+  // '.thumb'.
   if (parseToken(AsmToken::EndOfStatement,
-                 "unexpected token in '.thumb_func' directive"))
+                 "unexpected token in '.thumb_func' directive") ||
+      check(!hasThumb(), L, "target does not support Thumb mode"))
     return true;
 
+  if (!isThumb())
+    SwitchMode();
+
+  getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
   NextSymbolIsThumb = true;
   return false;
 }
