diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1786,9 +1786,15 @@ AddrSpace = DefaultAS; if (!EatIfPresent(lltok::kw_addrspace)) return false; - return parseToken(lltok::lparen, "expected '(' in address space") || - parseUInt32(AddrSpace) || - parseToken(lltok::rparen, "expected ')' in address space"); + SMLoc loc = Lex.getLoc(); + bool HaveError = parseToken(lltok::lparen, "expected '(' in address space") || + parseUInt32(AddrSpace) || + parseToken(lltok::rparen, "expected ')' in address space"); + if (HaveError) + return true; + if (AddrSpace >= (1 << 24)) + return error(loc, "address space too large to fit in 24 bits"); + return false; } /// parseStringAttribute diff --git a/llvm/test/Assembler/invalid-addrspace.ll b/llvm/test/Assembler/invalid-addrspace.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Assembler/invalid-addrspace.ll @@ -0,0 +1,8 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s +; Check that parser rejects address spaces that are too large to fit in the 24 bits + +define void @f() { +; CHECK: address space too large to fit in 24 bits + %y = alloca i32, addrspace(16777216) + ret void +}