[PATCH] D139528: [AsmParser] Check that addrspace fits within 24 bits

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 9 01:54:14 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG247ecc99e431: [AsmParser] Check that addrspace fits within 24 bits (authored by luke, committed by asb).

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: invalid address space, must be a 24-bit integer
+  %y = alloca i32, addrspace(16777216)
+  ret void
+}
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1802,10 +1802,15 @@
       }
       Lex.Lex();
       return false;
-    } else if (Lex.getKind() != lltok::APSInt) {
-      return tokError("expected integer or string constant");
     }
-    return parseUInt32(AddrSpace);
+    if (Lex.getKind() != lltok::APSInt)
+      return tokError("expected integer or string constant");
+    SMLoc Loc = Lex.getLoc();
+    if (parseUInt32(AddrSpace))
+      return true;
+    if (!isUInt<24>(AddrSpace))
+      return error(Loc, "invalid address space, must be a 24-bit integer");
+    return false;
   };
 
   return parseToken(lltok::lparen, "expected '(' in address space") ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139528.481571.patch
Type: text/x-patch
Size: 1260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221209/e25c4bf2/attachment.bin>


More information about the llvm-commits mailing list