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.

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

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

index b0edeb40d05d9d43f154d255b7f27bb08988f85f..a682f97ceb2350ed70a5862984b7fcd4ba1fd732 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/test/Assembler/invalid-attrgrp.ll b/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