summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/LLVMContextTest.cpp
blob: 37656a9b83afa0af84564390ed06cd464dd9a2af (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
58
59
60
61
62
63
64
65
//===- 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, enableDebugTypeODRUniquing) {
  LLVMContext Context;
  EXPECT_FALSE(Context.isODRUniquingDebugTypes());
  Context.enableDebugTypeODRUniquing();
  EXPECT_TRUE(Context.isODRUniquingDebugTypes());
  Context.disableDebugTypeODRUniquing();
  EXPECT_FALSE(Context.isODRUniquingDebugTypes());
}

TEST(LLVMContextTest, getOrInsertODRUniquedType) {
  LLVMContext Context;
  MDString &UUID = *MDString::get(Context, "string");

  // Without a type map, this should return null.
  EXPECT_FALSE(DICompositeType::getODRType(
      Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr,
      nullptr, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr));

  // Enable the mapping.  There still shouldn't be a type.
  Context.enableDebugTypeODRUniquing();
  EXPECT_FALSE(DICompositeType::getODRTypeIfExists(Context, UUID));

  // Create some ODR-uniqued type.
  auto &CT = *DICompositeType::getODRType(
      Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr,
      nullptr, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr);
  EXPECT_EQ(UUID.getString(), CT.getIdentifier());

  // Check that we get it back, even if we change a field.
  EXPECT_EQ(&CT, DICompositeType::getODRTypeIfExists(Context, UUID));
  EXPECT_EQ(
      &CT, DICompositeType::getODRType(Context, UUID, dwarf::DW_TAG_class_type,
                                       nullptr, nullptr, 0, nullptr, nullptr, 0,
                                       0, 0, 0, nullptr, 0, nullptr, nullptr));
  EXPECT_EQ(&CT, DICompositeType::getODRType(
                     Context, UUID, dwarf::DW_TAG_class_type,
                     MDString::get(Context, "name"), nullptr, 0, nullptr,
                     nullptr, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr));

  // Check that it's discarded with the type map.
  Context.disableDebugTypeODRUniquing();
  EXPECT_FALSE(DICompositeType::getODRTypeIfExists(Context, UUID));

  // And it shouldn't magically reappear...
  Context.enableDebugTypeODRUniquing();
  EXPECT_FALSE(DICompositeType::getODRTypeIfExists(Context, UUID));
}

} // end namespace
OpenPOWER on IntegriCloud