[llvm] [DataLayout] Refactor parsing of "ni" specification (PR #104546)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 01:10:35 PDT 2024


================
@@ -134,6 +134,46 @@ TEST(DataLayout, LayoutStringFormat) {
         FailedWithMessage("empty specification is not allowed"));
 }
 
+TEST(DataLayout, ParseNonIntegralAddrSpace) {
+  for (StringRef Str : {"ni:1", "ni:16777215", "ni:1:16777215"})
+    EXPECT_THAT_EXPECTED(DataLayout::parse(Str), Succeeded());
+
+  for (StringRef Str : {"ni", "ni42", "nix"})
+    EXPECT_THAT_EXPECTED(
+        DataLayout::parse(Str),
+        FailedWithMessage("malformed specification, must be of the form "
+                          "\"ni:<address space>[:<address space>]...\""));
+
+  for (StringRef Str : {"ni:", "ni::42", "ni:42:"})
+    EXPECT_THAT_EXPECTED(DataLayout::parse(Str),
+                         FailedWithMessage("<address space> is required"));
+
+  for (StringRef Str : {"ni:x", "ni:16777216", "ni:42:16777216"})
+    EXPECT_THAT_EXPECTED(
+        DataLayout::parse(Str),
+        FailedWithMessage("<address space> must be a 24-bit integer"));
----------------
nikic wrote:

Why this rather than?
```suggestion
        FailedWithMessage("address space must be a 24-bit integer"));
```
I get what you're going for, but I'm not sure trying to mimic the syntax used in LangRef is particularly helpful for error messages.

https://github.com/llvm/llvm-project/pull/104546


More information about the llvm-commits mailing list