add a #include
[llvm/stm8.git] / unittests / VMCore / DerivedTypesTest.cpp
blobd0ba0264aac54c1533658789848079324765786a
1 //===- llvm/unittest/VMCore/DerivedTypesTest.cpp - Types unit tests -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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"
16 using namespace llvm;
18 namespace {
20 static void PR7658() {
21 LLVMContext ctx;
23 WeakVH NullPtr;
24 PATypeHolder h1;
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));
31 t1.push_back(p1);
32 NullPtr = ConstantPointerNull::get(p1);
33 OpaqueType *o2 = OpaqueType::get (ctx);
34 PointerType *p2 = PointerType::get (o2, 0);
35 t1.push_back(p2);
38 StructType *s1 = StructType::get(ctx, t1);
39 h1 = s1;
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));
50 t2.push_back(p3);
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);
59 t2.push_back(p4);
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);
66 PATypeHolder h2(s2);
67 o3->refineAbstractTypeTo(s2);
68 o4->refineAbstractTypeTo(h2.get());
72 TEST(OpaqueTypeTest, RegisterWithContext) {
73 LLVMContext C;
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());
85 PR7658();
88 } // namespace