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

Luke Lau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 05:13:58 PST 2022


luke updated this revision to Diff 481252.
luke marked an inline comment as done.
luke added a comment.

Adjust diagnostic string


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 24bit 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.481252.patch
Type: text/x-patch
Size: 1259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221208/24f21e6b/attachment.bin>


More information about the llvm-commits mailing list