summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/LLVMContextTest.cpp
blob: 16cf0745e098c8ad3c47439acaf318e6ed726143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//===- LLVMContextTest.cpp - LLVMContext unit tests -----------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "gtest/gtest.h"
using namespace llvm;

namespace {

TEST(LLVMContextTest, ensureDITypeMap) {
  LLVMContext Context;
  EXPECT_FALSE(Context.hasDITypeMap());
  Context.ensureDITypeMap();
  EXPECT_TRUE(Context.hasDITypeMap());
  Context.destroyDITypeMap();
  EXPECT_FALSE(Context.hasDITypeMap());
}

TEST(LLVMContextTest, getOrInsertDITypeMapping) {
  LLVMContext Context;
  const MDString &S = *MDString::get(Context, "string");

  // Without a type map, this should return null.
  EXPECT_FALSE(Context.getOrInsertDITypeMapping(S));

  // Get the mapping.
  Context.ensureDITypeMap();
  DIType **Mapping = Context.getOrInsertDITypeMapping(S);
  ASSERT_TRUE(Mapping);

  // Create some type and add it to the mapping.
  auto &BT =
      *DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, S.getString());
  *Mapping = &BT;

  // Check that we get it back.
  Mapping = Context.getOrInsertDITypeMapping(S);
  ASSERT_TRUE(Mapping);
  EXPECT_EQ(&BT, *Mapping);

  // Check that it's discarded with the type map.
  Context.destroyDITypeMap();
  EXPECT_FALSE(Context.getOrInsertDITypeMapping(S));

  // And it shouldn't magically reappear...
  Context.ensureDITypeMap();
  EXPECT_FALSE(*Context.getOrInsertDITypeMapping(S));
}

} // end namespace
OpenPOWER on IntegriCloud