[llvm] c095276 - [JITLink] Fix bug in LinkGraph::createMutableContentBlock overload.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 31 11:24:14 PDT 2023


Author: Lang Hames
Date: 2023-03-31T11:24:06-07:00
New Revision: c0952762f238e6e9e69443dd93a00802be8379a5

URL: https://github.com/llvm/llvm-project/commit/c0952762f238e6e9e69443dd93a00802be8379a5
DIFF: https://github.com/llvm/llvm-project/commit/c0952762f238e6e9e69443dd93a00802be8379a5.diff

LOG: [JITLink] Fix bug in LinkGraph::createMutableContentBlock overload.

Creating zero-filled blocks should use allocateBuffer to allocate the block's
content buffer, rather than allocateContent. (allocateContent interpreted what
would have been the size argument as a single-element ArrayRef and allocated a
single byte).

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
    llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index 365ca500ded4..488156522896 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -1102,7 +1102,7 @@ class LinkGraph {
                                    orc::ExecutorAddr Address,
                                    uint64_t Alignment, uint64_t AlignmentOffset,
                                    bool ZeroInitialize = true) {
-    auto Content = allocateContent(ContentSize);
+    auto Content = allocateBuffer(ContentSize);
     if (ZeroInitialize)
       memset(Content.data(), 0, Content.size());
     return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);

diff  --git a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
index a3cb1b6fd638..ff153f6d4b32 100644
--- a/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
+++ b/llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp
@@ -241,6 +241,15 @@ TEST(LinkGraphTest, ContentAccessAndUpdate) {
                                          orc::ExecutorAddr(0x10000), 8, 0);
 
   EXPECT_TRUE(B2.isContentMutable()) << "Expected B2 content to be mutable";
+  EXPECT_EQ(B2.getSize(), MutableContent.size());
+
+  // Create a mutable content block with initial zero-fill.
+  auto &B3 =
+      G.createMutableContentBlock(Sec, 16, orc::ExecutorAddr(0x2000), 8, 0);
+  EXPECT_TRUE(B3.isContentMutable()) << "Expected B2 content to be mutable";
+  EXPECT_EQ(B3.getSize(), 16U);
+  EXPECT_TRUE(llvm::all_of(B3.getAlreadyMutableContent(),
+                           [](char C) { return C == 0; }));
 }
 
 TEST(LinkGraphTest, MakeExternal) {


        


More information about the llvm-commits mailing list