Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 845e196

Browse files
committed
Make BinaryRef output correctly in case of empty data.
Previously, it would simply output nothing, but it should output an empty string `""`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185894 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b494015 commit 845e196

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

lib/Object/YAML.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ void BinaryRef::writeAsBinary(raw_ostream &OS) const {
4949
}
5050

5151
void BinaryRef::writeAsHex(raw_ostream &OS) const {
52+
if (binary_size() == 0) {
53+
OS << "\"\"";
54+
return;
55+
}
5256
if (DataIsHexString) {
5357
OS.write((const char *)Data.data(), Data.size());
5458
return;

unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ add_subdirectory(Support)
1414
add_subdirectory(Transforms)
1515
add_subdirectory(IR)
1616
add_subdirectory(DebugInfo)
17+
add_subdirectory(Object)

unittests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
LEVEL = ..
1111

1212
PARALLEL_DIRS = ADT ExecutionEngine Support Transforms IR Analysis Bitcode \
13-
DebugInfo
13+
DebugInfo Object
1414

1515
include $(LEVEL)/Makefile.common
1616

unittests/Object/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(LLVM_LINK_COMPONENTS
2+
object
3+
)
4+
5+
add_llvm_unittest(ObjectTests
6+
YAMLTest.cpp
7+
)

unittests/Object/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##===- unittests/IR/Makefile -------------------------------*- Makefile -*-===##
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+
10+
LEVEL = ../..
11+
TESTNAME = Object
12+
LINK_COMPONENTS := object
13+
14+
include $(LEVEL)/Makefile.config
15+
include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest

unittests/Object/YAMLTest.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===- llvm/unittest/Object/YAMLTest.cpp - Tests for Object YAML ----------===//
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+
10+
#include "llvm/Object/YAML.h"
11+
#include "llvm/Support/YAMLTraits.h"
12+
#include "gtest/gtest.h"
13+
14+
using namespace llvm;
15+
16+
namespace {
17+
struct BinaryHolder {
18+
object::yaml::BinaryRef Binary;
19+
};
20+
} // end anonymous namespace
21+
22+
namespace llvm {
23+
namespace yaml {
24+
template <>
25+
struct MappingTraits<BinaryHolder> {
26+
static void mapping(IO &IO, BinaryHolder &BH) {
27+
IO.mapRequired("Binary", BH.Binary);
28+
}
29+
};
30+
} // end namespace yaml
31+
} // end namespace llvm
32+
33+
TEST(ObjectYAML, BinaryRef) {
34+
BinaryHolder BH;
35+
SmallVector<char, 32> Buf;
36+
llvm::raw_svector_ostream OS(Buf);
37+
yaml::Output YOut(OS);
38+
YOut << BH;
39+
EXPECT_NE(OS.str().find("\"\""), StringRef::npos);
40+
}

0 commit comments

Comments
 (0)