1 //===- llvm/unittest/IR/TypesTest.cpp - Type unit tests -------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/DerivedTypes.h"
10 #include "llvm/IR/LLVMContext.h"
11 #include "llvm/IR/TypedPointerType.h"
12 #include "gtest/gtest.h"
17 TEST(TypesTest
, StructType
) {
21 StructType
*Struct
= StructType::create(C
, "FooBar");
22 EXPECT_EQ("FooBar", Struct
->getName());
23 Struct
->setName(Struct
->getName().substr(0, 3));
24 EXPECT_EQ("Foo", Struct
->getName());
26 EXPECT_TRUE(Struct
->getName().empty());
27 EXPECT_FALSE(Struct
->hasName());
30 TEST(TypesTest
, LayoutIdenticalEmptyStructs
) {
33 StructType
*Foo
= StructType::create(C
, "Foo");
34 StructType
*Bar
= StructType::create(C
, "Bar");
35 EXPECT_TRUE(Foo
->isLayoutIdentical(Bar
));
38 TEST(TypesTest
, TargetExtType
) {
40 Type
*A
= TargetExtType::get(Context
, "typea");
41 Type
*Aparam
= TargetExtType::get(Context
, "typea", {}, {0, 1});
42 Type
*Aparam2
= TargetExtType::get(Context
, "typea", {}, {0, 1});
43 // Opaque types with same parameters are identical...
44 EXPECT_EQ(Aparam
, Aparam2
);
45 // ... but just having the same name is not enough.
49 TEST(TypedPointerType
, PrintTest
) {
52 raw_string_ostream
OS(Buffer
);
54 Type
*I8Ptr
= TypedPointerType::get(Type::getInt8Ty(Context
), 0);
56 EXPECT_EQ(StringRef(Buffer
), ("typedptr(i8, 0)"));
59 } // end anonymous namespace