[llvm] r296220 - Re-enable BinaryStreamTest.StreamReaderObject.

Daniel Jasper via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 25 00:13:59 PST 2017


On Sat, Feb 25, 2017 at 2:20 AM, Zachary Turner via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: zturner
> Date: Fri Feb 24 19:20:08 2017
> New Revision: 296220
>
> URL: http://llvm.org/viewvc/llvm-project?rev=296220&view=rev
> Log:
> Re-enable BinaryStreamTest.StreamReaderObject.
>
> I had an invalid pointer / size calculation that was causing
> a stack smash.  Should be fixed now.
>
> Modified:
>     llvm/trunk/unittests/DebugInfo/PDB/BinaryStreamTest.cpp
>     llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
>
> Modified: llvm/trunk/unittests/DebugInfo/PDB/BinaryStreamTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/
> DebugInfo/PDB/BinaryStreamTest.cpp?rev=296220&r1=296219&r2=296220&
> view=diff
> ============================================================
> ==================
> --- llvm/trunk/unittests/DebugInfo/PDB/BinaryStreamTest.cpp (original)
> +++ llvm/trunk/unittests/DebugInfo/PDB/BinaryStreamTest.cpp Fri Feb 24
> 19:20:08 2017
> @@ -443,39 +443,33 @@ TEST_F(BinaryStreamTest, StreamReaderEnu
>    }
>  }
>
> -//TEST_F(BinaryStreamTest, StreamReaderObject) {
> -//  struct Foo {
> -//    int X;
> -//    double Y;
> -//    char Z;
> -//  };
> -//
> -//  std::vector<Foo> Foos;
> -//  Foos.push_back({-42, 42.42, 42});
> -//  Foos.push_back({100, 3.1415, -89});
>

Note that this was triggering -Wc++11-narrowing, which I have silenced in
r296249. Please double-check whether that's the right thing to do.


> -//
> -//  std::vector<uint8_t> Bytes;
> -//  Bytes.resize(2 * sizeof(Foo));
> -//  Foo *FPtr = reinterpret_cast<Foo *>(&Bytes[0]);
> -//  Foo *GPtr = FPtr + 1;
> -//
> -//  ::memcpy(FPtr, &Foos[0], sizeof(Foo));
> -//  ::memcpy(GPtr + sizeof(Foo), &Foos[1], sizeof(Foo));
> -//
> -//  initialize(Bytes, 0);
> -//
> -//  for (auto IS : InputStreams) {
> -//    // 1. Reading object pointers.
> -//    BinaryStreamReader Reader(*IS);
> -//    const Foo *FPtrOut = nullptr;
> -//    const Foo *GPtrOut = nullptr;
> -//    ASSERT_NO_ERROR(Reader.readObject(FPtrOut));
> -//    ASSERT_NO_ERROR(Reader.readObject(GPtrOut));
> -//    EXPECT_EQ(0U, Reader.bytesRemaining());
> -//    EXPECT_EQ(0, ::memcmp(FPtr, FPtrOut, sizeof(Foo)));
> -//    EXPECT_EQ(0, ::memcmp(GPtr, GPtrOut, sizeof(Foo)));
> -//  }
> -//}
> +TEST_F(BinaryStreamTest, StreamReaderObject) {
> +  struct Foo {
> +    int X;
> +    double Y;
> +    char Z;
> +  };
> +
> +  std::vector<Foo> Foos;
> +  Foos.push_back({-42, 42.42, 42});
> +  Foos.push_back({100, 3.1415, -89});
> +
> +  const uint8_t *Bytes = reinterpret_cast<const uint8_t *>(&Foos[0]);
> +
> +  initialize(makeArrayRef(Bytes, 2 * sizeof(Foo)), 0);
> +
> +  for (auto IS : InputStreams) {
> +    // 1. Reading object pointers.
> +    BinaryStreamReader Reader(*IS);
> +    const Foo *FPtrOut = nullptr;
> +    const Foo *GPtrOut = nullptr;
> +    ASSERT_NO_ERROR(Reader.readObject(FPtrOut));
> +    ASSERT_NO_ERROR(Reader.readObject(GPtrOut));
> +    EXPECT_EQ(0U, Reader.bytesRemaining());
> +    EXPECT_EQ(0, ::memcmp(&Foos[0], FPtrOut, sizeof(Foo)));
> +    EXPECT_EQ(0, ::memcmp(&Foos[1], GPtrOut, sizeof(Foo)));
> +  }
> +}
>
>  TEST_F(BinaryStreamTest, StreamReaderStrings) {
>    std::vector<uint8_t> Bytes = {'O',  'n', 'e', '\0', 'T', 'w', 'o',
>
> Modified: llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/
> DebugInfo/PDB/MappedBlockStreamTest.cpp?rev=296220&r1=296219&r2=296220&
> view=diff
> ============================================================
> ==================
> --- llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
> (original)
> +++ llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp Fri Feb
> 24 19:20:08 2017
> @@ -37,7 +37,7 @@ public:
>    uint32_t block_size() const { return 1; }
>    uint32_t block_count() const { return Blocks.size(); }
>
> -  endianness getEndian() const { return little; }
> +  endianness getEndian() const override { return little; }
>
>    Error readBytes(uint32_t Offset, uint32_t Size,
>                    ArrayRef<uint8_t> &Buffer) override {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170225/0069a962/attachment.html>


More information about the llvm-commits mailing list