From b39e22bdc504ba77e2cd385538b6634808cda66e Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 9 Dec 2014 18:33:57 +0000 Subject: [PATCH] AsmParser: Don't crash on malformed attribute groups This fixes PR21785. llvm-svn: 223801 --- llvm/lib/AsmParser/LLParser.cpp | 4 +++- llvm/test/Assembler/invalid-attrgrp.ll | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Assembler/invalid-attrgrp.ll diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index b0edeb4..a682f97 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -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 unused; LocTy BuiltinLoc; diff --git a/llvm/test/Assembler/invalid-attrgrp.ll b/llvm/test/Assembler/invalid-attrgrp.ll new file mode 100644 index 0000000..bf1961aa --- /dev/null +++ b/llvm/test/Assembler/invalid-attrgrp.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +attributes +; CHECK: expected attribute group id -- 2.7.4