Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / IR / TypesTest.cpp
blob855262fc4e787f0a1f49859b3c49bbe751ca9d14
1 //===- llvm/unittest/IR/TypesTest.cpp - Type unit tests -------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/DerivedTypes.h"
10 #include "llvm/IR/LLVMContext.h"
11 #include "llvm/IR/TypedPointerType.h"
12 #include "gtest/gtest.h"
13 using namespace llvm;
15 namespace {
17 TEST(TypesTest, StructType) {
18 LLVMContext C;
20 // PR13522
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());
25 Struct->setName("");
26 EXPECT_TRUE(Struct->getName().empty());
27 EXPECT_FALSE(Struct->hasName());
30 TEST(TypesTest, LayoutIdenticalEmptyStructs) {
31 LLVMContext C;
33 StructType *Foo = StructType::create(C, "Foo");
34 StructType *Bar = StructType::create(C, "Bar");
35 EXPECT_TRUE(Foo->isLayoutIdentical(Bar));
38 TEST(TypesTest, TargetExtType) {
39 LLVMContext Context;
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.
46 EXPECT_NE(A, Aparam);
49 TEST(TypedPointerType, PrintTest) {
50 std::string Buffer;
51 LLVMContext Context;
52 raw_string_ostream OS(Buffer);
54 Type *I8Ptr = TypedPointerType::get(Type::getInt8Ty(Context), 0);
55 I8Ptr->print(OS);
56 EXPECT_EQ(StringRef(Buffer), ("typedptr(i8, 0)"));
59 } // end anonymous namespace