1 //===- llvm/unittest/IR/AsmWriter.cpp - AsmWriter tests -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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"
20 TEST(AsmWriterTest
, DebugPrintDetachedInstruction
) {
22 // PR24852: Ensure that an instruction can be printed even when it
23 // has metadata attached but no parent.
25 auto Ty
= Type::getInt32Ty(Ctx
);
26 auto Undef
= UndefValue::get(Ty
);
27 std::unique_ptr
<BinaryOperator
> Add(BinaryOperator::CreateAdd(Undef
, Undef
));
29 "", MDNode::get(Ctx
, {ConstantAsMetadata::get(ConstantInt::get(Ty
, 1))}));
31 raw_string_ostream
OS(S
);
33 std::size_t r
= OS
.str().find("<badref> = add i32 undef, undef, !<empty");
34 EXPECT_TRUE(r
!= std::string::npos
);