AsmParser: Don't crash on malformed attribute groups
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 9 Dec 2014 18:33:57 +0000 (18:33 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 9 Dec 2014 18:33:57 +0000 (18:33 +0000)
This fixes PR21785.

llvm-svn: 223801

llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/invalid-attrgrp.ll [new file with mode: 0644]

index b0edeb4..a682f97 100644 (file)
@@ -869,7 +869,9 @@ bool LLParser::ParseUnnamedAttrGrp() {
   LocTy AttrGrpLoc = Lex.getLoc();
   Lex.Lex();
 
-  assert(Lex.getKind() == lltok::AttrGrpID);
+  if (Lex.getKind() != lltok::AttrGrpID)
+    return TokError("expected attribute group id");
+
   unsigned VarID = Lex.getUIntVal();
   std::vector<unsigned> unused;
   LocTy BuiltinLoc;
diff --git a/llvm/test/Assembler/invalid-attrgrp.ll b/llvm/test/Assembler/invalid-attrgrp.ll
new file mode 100644 (file)
index 0000000..bf1961a
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+attributes
+; CHECK: expected attribute group id