[UnitTests] Convert some data layout parsing tests to GTest (#104346)

For now, the testcases are grouped in a single TEST. I'll sort them out
and add more testcases in follow-up commits.
This commit is contained in:
Sergei Barannikov 2024-08-15 10:48:27 +03:00 committed by GitHub
parent fa343be414
commit 845431a54f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 105 additions and 120 deletions

View File

@ -1,5 +0,0 @@
; RUN: not llvm-as %s 2>&1 | FileCheck %s
; CHECK: error: Alignment is neither 0 nor a power of 2
target datalayout = "Fi24"

View File

@ -1,5 +0,0 @@
; RUN: not llvm-as %s 2>&1 | FileCheck %s
; CHECK: error: Invalid ABI alignment, i8 must be naturally aligned
target datalayout = "i8:16"

View File

@ -1,5 +0,0 @@
; RUN: not llvm-as %s 2>&1 | FileCheck %s
; CHECK: error: Alignment is neither 0 nor a power of 2
target datalayout = "S24"

View File

@ -1,4 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "A16777216"
; CHECK: Invalid address space, must be a 24-bit integer

View File

@ -1,4 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
; CHECK: Invalid address space, must be a 24-bit integer
target datalayout = "G16777216"

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:64:64:64:128"
; CHECK: Index width cannot be larger than pointer width

View File

@ -1,4 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
; CHECK: Invalid address space, must be a 24-bit integer
target datalayout = "P16777216"

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "^"
; CHECK: Unknown specifier in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m"
; CHECK: Expected mangling specifier in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m."
; CHECK: Unexpected trailing characters after mangling specifier in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "f"
; CHECK: Missing alignment specification in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = ":32"
; CHECK: Expected token before separator in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:64:16"
; CHECK: Preferred alignment cannot be less than the ABI alignment

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:16:16777216"
; CHECK: Invalid preferred alignment, must be a 16bit integer

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:16777216:16777216"
; CHECK: Invalid ABI alignment, must be a 16bit integer

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i16777216:16:16"
; CHECK: Invalid bit width, must be a 24-bit integer

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:32:32:16"
; CHECK: Preferred alignment cannot be less than the ABI alignment

View File

@ -1,6 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:0:32:32"
; CHECK: Invalid pointer size of 0 bytes

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "m:v"
; CHECK: Unknown mangling in datalayout string

View File

@ -1,6 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:64:24:64"
; CHECK: Pointer ABI alignment must be a power of 2

View File

@ -1,6 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:64:64:24"
; CHECK: Pointer preferred alignment must be a power of 2

View File

@ -1,6 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "v128:0:128"
; CHECK: ABI alignment specification must be >0 for non-aggregate types

View File

@ -1,6 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i32:24:32"
; CHECK: Invalid ABI alignment, must be a power of 2

View File

@ -1,6 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i32:32:24"
; CHECK: Invalid preferred alignment, must be a power of 2

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "n0"
; CHECK: Zero width native integer type in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p16777216:64:64:64"
; CHECK: Invalid address space, must be a 24-bit integer

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "a1:64"
; CHECK: Sized aggregate specification in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "a:"
; CHECK: Trailing separator in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "p:48:52"
; CHECK: number of bits must be a byte width multiple

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "e-p"
; CHECK: Missing size specification for pointer in datalayout string

View File

@ -1,3 +0,0 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "e-p:64"
; CHECK: Missing alignment specification for pointer in datalayout string

View File

@ -19,6 +19,111 @@ using namespace llvm;
namespace {
// TODO: Split into multiple TESTs.
TEST(DataLayoutTest, ParseErrors) {
EXPECT_THAT_EXPECTED(
DataLayout::parse("^"),
FailedWithMessage("Unknown specifier in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("m:v"),
FailedWithMessage("Unknown mangling in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("n0"),
FailedWithMessage("Zero width native integer type in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("p16777216:64:64:64"),
FailedWithMessage("Invalid address space, must be a 24-bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("a1:64"),
FailedWithMessage("Sized aggregate specification in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("a:"),
FailedWithMessage("Trailing separator in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("p:48:52"),
FailedWithMessage("number of bits must be a byte width multiple"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("e-p"),
FailedWithMessage(
"Missing size specification for pointer in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("e-p:64"),
FailedWithMessage(
"Missing alignment specification for pointer in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("m"),
FailedWithMessage("Expected mangling specifier in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("m."),
FailedWithMessage("Unexpected trailing characters after mangling "
"specifier in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("f"),
FailedWithMessage(
"Missing alignment specification in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse(":32"),
FailedWithMessage(
"Expected token before separator in datalayout string"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i64:64:16"),
FailedWithMessage(
"Preferred alignment cannot be less than the ABI alignment"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i64:16:16777216"),
FailedWithMessage(
"Invalid preferred alignment, must be a 16bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i64:16777216:16777216"),
FailedWithMessage("Invalid ABI alignment, must be a 16bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i16777216:16:16"),
FailedWithMessage("Invalid bit width, must be a 24-bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("p:32:32:16"),
FailedWithMessage(
"Preferred alignment cannot be less than the ABI alignment"));
EXPECT_THAT_EXPECTED(DataLayout::parse("p:0:32:32"),
FailedWithMessage("Invalid pointer size of 0 bytes"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("p:64:24:64"),
FailedWithMessage("Pointer ABI alignment must be a power of 2"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("p:64:64:24"),
FailedWithMessage("Pointer preferred alignment must be a power of 2"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("p:64:64:64:128"),
FailedWithMessage("Index width cannot be larger than pointer width"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("v128:0:128"),
FailedWithMessage(
"ABI alignment specification must be >0 for non-aggregate types"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i32:24:32"),
FailedWithMessage("Invalid ABI alignment, must be a power of 2"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i32:32:24"),
FailedWithMessage("Invalid preferred alignment, must be a power of 2"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("A16777216"),
FailedWithMessage("Invalid address space, must be a 24-bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("G16777216"),
FailedWithMessage("Invalid address space, must be a 24-bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("P16777216"),
FailedWithMessage("Invalid address space, must be a 24-bit integer"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("Fi24"),
FailedWithMessage("Alignment is neither 0 nor a power of 2"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("i8:16"),
FailedWithMessage("Invalid ABI alignment, i8 must be naturally aligned"));
EXPECT_THAT_EXPECTED(
DataLayout::parse("S24"),
FailedWithMessage("Alignment is neither 0 nor a power of 2"));
}
TEST(DataLayoutTest, CopyAssignmentInvalidatesStructLayout) {
DataLayout DL1 = cantFail(DataLayout::parse("p:32:32"));
DataLayout DL2 = cantFail(DataLayout::parse("p:64:64"));