1 //===- llvm/unittest/VMCore/DerivedTypesTest.cpp - Types unit tests -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "../lib/VMCore/LLVMContextImpl.h"
12 #include "llvm/DerivedTypes.h"
13 #include "llvm/LLVMContext.h"
14 #include "llvm/Constants.h"
15 #include "llvm/Support/ValueHandle.h"
20 static void PR7658() {
26 OpaqueType
*o1
= OpaqueType::get(ctx
);
27 PointerType
*p1
= PointerType::get(o1
, 0);
29 std::vector
<const Type
*> t1
;
30 t1
.push_back(IntegerType::get(ctx
, 32));
32 NullPtr
= ConstantPointerNull::get(p1
);
33 OpaqueType
*o2
= OpaqueType::get (ctx
);
34 PointerType
*p2
= PointerType::get (o2
, 0);
38 StructType
*s1
= StructType::get(ctx
, t1
);
40 o1
->refineAbstractTypeTo(s1
);
41 o2
->refineAbstractTypeTo(h1
.get()); // h1 = { i32, \2*, \2* }
45 OpaqueType
*o3
= OpaqueType::get(ctx
);
46 PointerType
*p3
= PointerType::get(o3
, 0); // p3 = opaque*
48 std::vector
<const Type
*> t2
;
49 t2
.push_back(IntegerType::get(ctx
, 32));
52 std::vector
<Constant
*> v2
;
53 v2
.push_back(ConstantInt::get(IntegerType::get(ctx
, 32), 14));
54 v2
.push_back(ConstantPointerNull::get(p3
));
56 OpaqueType
*o4
= OpaqueType::get(ctx
);
58 PointerType
*p4
= PointerType::get(o4
, 0);
60 v2
.push_back(ConstantPointerNull::get(p4
));
63 WeakVH CS
= ConstantStruct::getAnon(ctx
, v2
, false); // { i32 14, opaque* null, opaque* null}
65 StructType
*s2
= StructType::get(ctx
, t2
);
67 o3
->refineAbstractTypeTo(s2
);
68 o4
->refineAbstractTypeTo(h2
.get());
72 TEST(OpaqueTypeTest
, RegisterWithContext
) {
74 LLVMContextImpl
*pImpl
= C
.pImpl
;
76 // 1 refers to the AlwaysOpaqueTy allocated in the Context's constructor and
77 // destroyed in the destructor.
78 EXPECT_EQ(1u, pImpl
->OpaqueTypes
.size());
80 PATypeHolder Type
= OpaqueType::get(C
);
81 EXPECT_EQ(2u, pImpl
->OpaqueTypes
.size());
83 EXPECT_EQ(1u, pImpl
->OpaqueTypes
.size());