MC: Diagnose an unexpected token in COFF .section instead of asserting
authorReid Kleckner <reid@kleckner.net>
Mon, 11 Aug 2014 18:34:43 +0000 (18:34 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 11 Aug 2014 18:34:43 +0000 (18:34 +0000)
This can easily arise when trying to assemble and ELF style .section
directive for a COFF object file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215373 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/COFFAsmParser.cpp
test/MC/COFF/section-invalid-flags.s

index 5ecf9e5c64bc1332c6034de8ae05c8cd13c26c60..6f82e6ef3e455d4ab707d413af0765c94bcfd2d7 100644 (file)
@@ -364,6 +364,10 @@ bool COFFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
 
     Flags |= COFF::IMAGE_SCN_LNK_COMDAT;
 
+    if (!getLexer().is(AsmToken::Identifier))
+      return TokError("expected comdat type such as 'discard' or 'largest' "
+                      "after protection bits");
+
     if (parseCOMDATType(Type))
       return true;
 
index 17b1550a904e47cf01efe40b994dd5cc101d6c02..9cdceaf300140fa0b7cac7888c3c2981ebc6ef2a 100644 (file)
@@ -6,3 +6,6 @@
 
 // CHECK: error: conflicting section flags 'b' and 'd'
 .section s_bd,"bd"; .long 1
+
+// CHECK: error: expected comdat type such as 'discard' or 'largest' after protection bits
+.section .stack, "w", @nobits