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
|
//===- 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;
const MDString &S = *MDString::get(Context, "string");
// Without a type map, this should return null.
EXPECT_FALSE(Context.getOrInsertODRUniquedType(S));
// Get the mapping.
Context.enableDebugTypeODRUniquing();
DICompositeType **Mapping = Context.getOrInsertODRUniquedType(S);
ASSERT_TRUE(Mapping);
// Create some type and add it to the mapping.
auto &CT = *DICompositeType::get(Context, dwarf::DW_TAG_class_type, "name",
nullptr, 0, nullptr, nullptr, 0, 0, 0, 0,
nullptr, 0, nullptr, nullptr, S.getString());
ASSERT_EQ(S.getString(), CT.getIdentifier());
*Mapping = &CT;
// Check that we get it back.
Mapping = Context.getOrInsertODRUniquedType(S);
ASSERT_TRUE(Mapping);
EXPECT_EQ(&CT, *Mapping);
// Check that it's discarded with the type map.
Context.disableDebugTypeODRUniquing();
EXPECT_FALSE(Context.getOrInsertODRUniquedType(S));
// And it shouldn't magically reappear...
Context.enableDebugTypeODRUniquing();
EXPECT_FALSE(*Context.getOrInsertODRUniquedType(S));
}
} // end namespace
|