blob: f1eeb05b1cb8a906457c86d25693bc9fce374f99 (
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, 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();
DIType **Mapping = Context.getOrInsertODRUniquedType(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.getOrInsertODRUniquedType(S);
ASSERT_TRUE(Mapping);
EXPECT_EQ(&BT, *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
|