llvm-project
59 строк · 1.8 Кб
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//===----------------------------------------------------------------------===//
8
9#include "llvm/IR/DerivedTypes.h"
10#include "llvm/IR/LLVMContext.h"
11#include "llvm/IR/TypedPointerType.h"
12#include "gtest/gtest.h"
13using namespace llvm;
14
15namespace {
16
17TEST(TypesTest, StructType) {
18LLVMContext C;
19
20// PR13522
21StructType *Struct = StructType::create(C, "FooBar");
22EXPECT_EQ("FooBar", Struct->getName());
23Struct->setName(Struct->getName().substr(0, 3));
24EXPECT_EQ("Foo", Struct->getName());
25Struct->setName("");
26EXPECT_TRUE(Struct->getName().empty());
27EXPECT_FALSE(Struct->hasName());
28}
29
30TEST(TypesTest, LayoutIdenticalEmptyStructs) {
31LLVMContext C;
32
33StructType *Foo = StructType::create(C, "Foo");
34StructType *Bar = StructType::create(C, "Bar");
35EXPECT_TRUE(Foo->isLayoutIdentical(Bar));
36}
37
38TEST(TypesTest, TargetExtType) {
39LLVMContext Context;
40Type *A = TargetExtType::get(Context, "typea");
41Type *Aparam = TargetExtType::get(Context, "typea", {}, {0, 1});
42Type *Aparam2 = TargetExtType::get(Context, "typea", {}, {0, 1});
43// Opaque types with same parameters are identical...
44EXPECT_EQ(Aparam, Aparam2);
45// ... but just having the same name is not enough.
46EXPECT_NE(A, Aparam);
47}
48
49TEST(TypedPointerType, PrintTest) {
50std::string Buffer;
51LLVMContext Context;
52raw_string_ostream OS(Buffer);
53
54Type *I8Ptr = TypedPointerType::get(Type::getInt8Ty(Context), 0);
55I8Ptr->print(OS);
56EXPECT_EQ(StringRef(Buffer), ("typedptr(i8, 0)"));
57}
58
59} // end anonymous namespace
60