OSDN Git Service

[Dominators] Visit affected node candidates found at different root levels
[android-x86/external-llvm.git] / unittests / IR / AsmWriterTest.cpp
1 //===- llvm/unittest/IR/AsmWriter.cpp - AsmWriter 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 //===----------------------------------------------------------------------===//
9 #include "llvm/BinaryFormat/Dwarf.h"
10 #include "llvm/IR/DebugInfoMetadata.h"
11 #include "llvm/IR/Function.h"
12 #include "llvm/IR/IRBuilder.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/MDBuilder.h"
15 #include "llvm/IR/Module.h"
16 #include "gtest/gtest.h"
17
18 using namespace llvm;
19
20 namespace {
21
22 TEST(AsmWriterTest, DebugPrintDetachedInstruction) {
23
24   // PR24852: Ensure that an instruction can be printed even when it
25   // has metadata attached but no parent.
26   LLVMContext Ctx;
27   auto Ty = Type::getInt32Ty(Ctx);
28   auto Undef = UndefValue::get(Ty);
29   std::unique_ptr<BinaryOperator> Add(BinaryOperator::CreateAdd(Undef, Undef));
30   Add->setMetadata(
31       "", MDNode::get(Ctx, {ConstantAsMetadata::get(ConstantInt::get(Ty, 1))}));
32   std::string S;
33   raw_string_ostream OS(S);
34   Add->print(OS);
35   std::size_t r = OS.str().find("<badref> = add i32 undef, undef, !<empty");
36   EXPECT_TRUE(r != std::string::npos);
37 }
38
39 TEST(AsmWriterTest, DumpDIExpression) {
40   LLVMContext Ctx;
41   uint64_t Ops[] = {
42     dwarf::DW_OP_constu, 4,
43     dwarf::DW_OP_minus,
44     dwarf::DW_OP_deref,
45   };
46   DIExpression *Expr = DIExpression::get(Ctx, Ops);
47   std::string S;
48   raw_string_ostream OS(S);
49   Expr->print(OS);
50   EXPECT_EQ("!DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref)",
51             OS.str());
52 }
53
54 }