llvm.org GIT mirror llvm / 9bb9b31
Fix incorrect formatting of DataRefImpl members in operator<< function Changed format specifiers to use format macro constant for pointer type. Moved width part of format specifier in the correct place for formatting members a and b. Added a unit test to confirm the output. Differential Revision: https://reviews.llvm.org/D28957 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295173 91177308-0d34-0410-b5e6-96231b3b80d8 David Bozier 3 years ago
3 changed file(s) with 38 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1515
1616 #include "llvm/Object/Binary.h"
1717 #include "llvm/Support/Format.h"
18 #include
1819 #include
1920
2021 namespace llvm {
3233
3334 template
3435 OStream& operator<<(OStream &OS, const DataRefImpl &D) {
35 OS << "(" << format("0x%x8", D.p) << " (" << format("0x%x8", D.d.a) << ", " << format("0x%x8", D.d.b) << "))";
36 OS << "(" << format("0x%08" PRIxPTR, D.p) << " (" << format("0x%08x", D.d.a)
37 << ", " << format("0x%08x", D.d.b) << "))";
3638 return OS;
3739 }
3840
33
44 add_llvm_unittest(ObjectTests
55 SymbolSizeTest.cpp
6 SymbolicFileTest.cpp
67 )
78
0 //===- SymbolicFileTest.cpp - Tests for SymbolicFile.cpp ------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Object/SymbolicFile.h"
10 #include "llvm/Support/raw_ostream.h"
11 #include "gtest/gtest.h"
12 #include
13
14 TEST(Object, DataRefImplOstream) {
15 std::string s;
16 llvm::raw_string_ostream OS(s);
17 llvm::object::DataRefImpl Data;
18 Data.d.a = 0xeeee0000;
19 Data.d.b = 0x0000ffff;
20
21 static_assert(sizeof Data.p == sizeof(uint64_t) ||
22 sizeof Data.p == sizeof(uint32_t),
23 "Test expected pointer type to be 32 or 64-bit.");
24
25 char const *Expected = sizeof Data.p == sizeof(uint64_t)
26 ? "(0xffffeeee0000 (0xeeee0000, 0x0000ffff))"
27 : "(0xeeee0000 (0xeeee0000, 0x0000ffff))";
28
29 OS << Data;
30 OS.flush();
31
32 EXPECT_EQ(Expected, s);
33 }