[ARM] Prefer indirect calls in minsize mode
[llvm-core.git] / unittests / IR / AsmWriterTest.cpp
blobc7e7bb5c9f0fc4b073f41a2810b5518b1be9e17f
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/IR/IRBuilder.h"
10 #include "llvm/IR/Function.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/MDBuilder.h"
13 #include "llvm/IR/Module.h"
14 #include "gtest/gtest.h"
16 using namespace llvm;
18 namespace {
20 TEST(AsmWriterTest, DebugPrintDetachedInstruction) {
22 // PR24852: Ensure that an instruction can be printed even when it
23 // has metadata attached but no parent.
24 LLVMContext Ctx;
25 auto Ty = Type::getInt32Ty(Ctx);
26 auto Undef = UndefValue::get(Ty);
27 std::unique_ptr<BinaryOperator> Add(BinaryOperator::CreateAdd(Undef, Undef));
28 Add->setMetadata(
29 "", MDNode::get(Ctx, {ConstantAsMetadata::get(ConstantInt::get(Ty, 1))}));
30 std::string S;
31 raw_string_ostream OS(S);
32 Add->print(OS);
33 std::size_t r = OS.str().find("<badref> = add i32 undef, undef, !<empty");
34 EXPECT_TRUE(r != std::string::npos);