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 "gtest/gtest.h" 12 using namespace llvm; 13 14 namespace { 15 16 TEST(TypesTest, StructType) { 17 LLVMContext C; 18 19 // PR13522 20 StructType *Struct = StructType::create(C, "FooBar"); 21 EXPECT_EQ("FooBar", Struct->getName()); 22 Struct->setName(Struct->getName().substr(0, 3)); 23 EXPECT_EQ("Foo", Struct->getName()); 24 Struct->setName(""); 25 EXPECT_TRUE(Struct->getName().empty()); 26 EXPECT_FALSE(Struct->hasName()); 27 } 28 29 TEST(TypesTest, LayoutIdenticalEmptyStructs) { 30 LLVMContext C; 31 32 StructType *Foo = StructType::create(C, "Foo"); 33 StructType *Bar = StructType::create(C, "Bar"); 34 EXPECT_TRUE(Foo->isLayoutIdentical(Bar)); 35 } 36 37 } // end anonymous namespace 38