From b95b42740926b283d9ef7e93056d6aa1c9062e12 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 30 Aug 2017 20:40:36 +0000 Subject: [PATCH] [IR] Don't print "!DIExpression() = !DIExpression()" when dumping Now that we print DIExpressions inline everywhere, we don't need to print them once as an operand and again as a value. This is only really visible when calling dump() or print() directly on a DIExpression during debugging. llvm-svn: 312168 --- llvm/lib/IR/AsmWriter.cpp | 2 +- llvm/unittests/IR/AsmWriterTest.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 1cd6dd0ddff4..3443c6a3d78a 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -3592,7 +3592,7 @@ static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, /* FromValue */ true); auto *N = dyn_cast(&MD); - if (OnlyAsOperand || !N) + if (OnlyAsOperand || !N || isa(MD)) return; OS << " = "; diff --git a/llvm/unittests/IR/AsmWriterTest.cpp b/llvm/unittests/IR/AsmWriterTest.cpp index 55c2a70e21f5..9ad55237b5c0 100644 --- a/llvm/unittests/IR/AsmWriterTest.cpp +++ b/llvm/unittests/IR/AsmWriterTest.cpp @@ -6,6 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" @@ -34,4 +36,19 @@ TEST(AsmWriterTest, DebugPrintDetachedInstruction) { EXPECT_TRUE(r != std::string::npos); } +TEST(AsmWriterTest, DumpDIExpression) { + LLVMContext Ctx; + uint64_t Ops[] = { + dwarf::DW_OP_constu, 4, + dwarf::DW_OP_minus, + dwarf::DW_OP_deref, + }; + DIExpression *Expr = DIExpression::get(Ctx, Ops); + std::string S; + raw_string_ostream OS(S); + Expr->print(OS); + EXPECT_EQ("!DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref)", + OS.str()); +} + }