[llvm] r185894 - Make BinaryRef output correctly in case of empty data.

Sean Silva silvas at purdue.edu
Mon Jul 8 17:54:47 PDT 2013


Author: silvas
Date: Mon Jul  8 19:54:46 2013
New Revision: 185894

URL: http://llvm.org/viewvc/llvm-project?rev=185894&view=rev
Log:
Make BinaryRef output correctly in case of empty data.

Previously, it would simply output nothing, but it should output an
empty string `""`.

Added:
    llvm/trunk/unittests/Object/
    llvm/trunk/unittests/Object/CMakeLists.txt
    llvm/trunk/unittests/Object/Makefile
      - copied, changed from r185888, llvm/trunk/unittests/Makefile
    llvm/trunk/unittests/Object/YAMLTest.cpp
Modified:
    llvm/trunk/lib/Object/YAML.cpp
    llvm/trunk/unittests/CMakeLists.txt
    llvm/trunk/unittests/Makefile

Modified: llvm/trunk/lib/Object/YAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/YAML.cpp?rev=185894&r1=185893&r2=185894&view=diff
==============================================================================
--- llvm/trunk/lib/Object/YAML.cpp (original)
+++ llvm/trunk/lib/Object/YAML.cpp Mon Jul  8 19:54:46 2013
@@ -49,6 +49,10 @@ void BinaryRef::writeAsBinary(raw_ostrea
 }
 
 void BinaryRef::writeAsHex(raw_ostream &OS) const {
+  if (binary_size() == 0) {
+    OS << "\"\"";
+    return;
+  }
   if (DataIsHexString) {
     OS.write((const char *)Data.data(), Data.size());
     return;

Modified: llvm/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CMakeLists.txt?rev=185894&r1=185893&r2=185894&view=diff
==============================================================================
--- llvm/trunk/unittests/CMakeLists.txt (original)
+++ llvm/trunk/unittests/CMakeLists.txt Mon Jul  8 19:54:46 2013
@@ -14,3 +14,4 @@ add_subdirectory(Support)
 add_subdirectory(Transforms)
 add_subdirectory(IR)
 add_subdirectory(DebugInfo)
+add_subdirectory(Object)

Modified: llvm/trunk/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Makefile?rev=185894&r1=185893&r2=185894&view=diff
==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Makefile Mon Jul  8 19:54:46 2013
@@ -10,7 +10,7 @@
 LEVEL = ..
 
 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms IR Analysis Bitcode \
-								DebugInfo
+		DebugInfo Object
 
 include $(LEVEL)/Makefile.common
 

Added: llvm/trunk/unittests/Object/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/CMakeLists.txt?rev=185894&view=auto
==============================================================================
--- llvm/trunk/unittests/Object/CMakeLists.txt (added)
+++ llvm/trunk/unittests/Object/CMakeLists.txt Mon Jul  8 19:54:46 2013
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  object
+  )
+
+add_llvm_unittest(ObjectTests
+  YAMLTest.cpp
+  )

Copied: llvm/trunk/unittests/Object/Makefile (from r185888, llvm/trunk/unittests/Makefile)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/Makefile?p2=llvm/trunk/unittests/Object/Makefile&p1=llvm/trunk/unittests/Makefile&r1=185888&r2=185894&rev=185894&view=diff
==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Object/Makefile Mon Jul  8 19:54:46 2013
@@ -1,4 +1,4 @@
-##===- unittests/Makefile ----------------------------------*- Makefile -*-===##
+##===- unittests/IR/Makefile -------------------------------*- Makefile -*-===##
 #
 #                     The LLVM Compiler Infrastructure
 #
@@ -7,12 +7,9 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ..
+LEVEL = ../..
+TESTNAME = Object
+LINK_COMPONENTS := object
 
-PARALLEL_DIRS = ADT ExecutionEngine Support Transforms IR Analysis Bitcode \
-								DebugInfo
-
-include $(LEVEL)/Makefile.common
-
-clean::
-	$(Verb) $(RM) -f *Tests
+include $(LEVEL)/Makefile.config
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest

Added: llvm/trunk/unittests/Object/YAMLTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Object/YAMLTest.cpp?rev=185894&view=auto
==============================================================================
--- llvm/trunk/unittests/Object/YAMLTest.cpp (added)
+++ llvm/trunk/unittests/Object/YAMLTest.cpp Mon Jul  8 19:54:46 2013
@@ -0,0 +1,40 @@
+//===- llvm/unittest/Object/YAMLTest.cpp - Tests for Object YAML ----------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/YAML.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+struct BinaryHolder {
+  object::yaml::BinaryRef Binary;
+};
+} // end anonymous namespace
+
+namespace llvm {
+namespace yaml {
+template <>
+struct MappingTraits<BinaryHolder> {
+  static void mapping(IO &IO, BinaryHolder &BH) {
+    IO.mapRequired("Binary", BH.Binary);
+  }
+};
+} // end namespace yaml
+} // end namespace llvm
+
+TEST(ObjectYAML, BinaryRef) {
+  BinaryHolder BH;
+  SmallVector<char, 32> Buf;
+  llvm::raw_svector_ostream OS(Buf);
+  yaml::Output YOut(OS);
+  YOut << BH;
+  EXPECT_NE(OS.str().find("\"\""), StringRef::npos);
+}





More information about the llvm-commits mailing list