[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:40:37 PST 2022


luke created this revision.
luke added reviewers: kosarev, rampitec, asb, foad, dp.
Herald added subscribers: pmatos, StephenFan, hiraditya, arichardson.
Herald added a project: All.
luke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Address spaces equal or larger than 1 << 24 don't fit and produce an
assertion during debug builds, or worse in release. This causes an error
to be reported during parsing instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139528

Files:
  llvm/lib/AsmParser/LLParser.cpp


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.480854.patch
Type: text/x-patch
Size: 889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221207/8468829f/attachment.bin>


More information about the llvm-commits mailing list