[PATCH] D139528: [AsmParser] Check that addrspace fits within 24 bits
Luke Lau via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 04:43:44 PST 2022
luke updated this revision to Diff 480855.
luke added a comment.
Adding tests that were forgotten
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139528/new/
https://reviews.llvm.org/D139528
Files:
llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/invalid-addrspace.ll
Index: llvm/test/Assembler/invalid-addrspace.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139528.480855.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221207/52165519/attachment.bin>
More information about the llvm-commits
mailing list