[llvm] r218012 - ARM: use a more precise check for MachO

Saleem Abdulrasool compnerd at compnerd.org
Wed Sep 17 20:49:55 PDT 2014


Author: compnerd
Date: Wed Sep 17 22:49:55 2014
New Revision: 218012

URL: http://llvm.org/viewvc/llvm-project?rev=218012&view=rev
Log:
ARM: use a more precise check for MachO

Rather than relying on support for a specific directive to determine if we are
targeting MachO, explicitly check the output format.

As an additional bonus, cleanup the caret diagnostic for the non-MachO case and
avoid the spurious error caused by not discarding the statement.

Added:
    llvm/trunk/test/MC/ARM/directive-thumb_func.s
Modified:
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=218012&r1=218011&r2=218012&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Wed Sep 17 22:49:55 2014
@@ -8473,12 +8473,12 @@ void ARMAsmParser::onLabelParsed(MCSymbo
 /// parseDirectiveThumbFunc
 ///  ::= .thumbfunc symbol_name
 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
-  const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
-  bool isMachO = MAI->hasSubsectionsViaSymbols();
+  const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
+  bool IsMachO = Format == MCObjectFileInfo::IsMachO;
 
   // Darwin asm has (optionally) function name after .thumb_func direction
   // ELF doesn't
-  if (isMachO) {
+  if (IsMachO) {
     const AsmToken &Tok = Parser.getTok();
     if (Tok.isNot(AsmToken::EndOfStatement)) {
       if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
@@ -8495,7 +8495,8 @@ bool ARMAsmParser::parseDirectiveThumbFu
   }
 
   if (getLexer().isNot(AsmToken::EndOfStatement)) {
-    Error(L, "unexpected token in directive");
+    Error(Parser.getTok().getLoc(), "unexpected token in directive");
+    Parser.eatToEndOfStatement();
     return false;
   }
 

Added: llvm/trunk/test/MC/ARM/directive-thumb_func.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/directive-thumb_func.s?rev=218012&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/directive-thumb_func.s (added)
+++ llvm/trunk/test/MC/ARM/directive-thumb_func.s Wed Sep 17 22:49:55 2014
@@ -0,0 +1,22 @@
+@ RUN: not llvm-mc -triple armv7-eabi -filetype asm -o /dev/null %s 2>&1 \
+@ RUN:    | FileCheck %s -check-prefix CHECK-EABI
+
+@ NOTE: this test ensures that both forms are accepted for MachO
+@ RUN: llvm-mc -triple armv7-darwin -filetype asm -o /dev/null %s
+
+	.syntax unified
+
+	.thumb_func
+no_suffix:
+	bx lr
+
+	.thumb_func suffix
+suffix:
+	bx lr
+
+// CHECK-EABI: error: unexpected token in directive
+// CHECK-EABI: 	.thumb_func suffix
+// CHECK-EABI:              ^
+
+// CHECK-EABI-NOT: error: invalid instruction
+





More information about the llvm-commits mailing list