Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/44366 )

Change subject: dev: Fix compilation errors
......................................................................

dev: Fix compilation errors

'backing' was initialized after being used.
'buffer' was initialized after its data() was used
by the constructor.

Change-Id: I0f8d0f6efb5d4b7abc5fc6c2c3ecca2c9b0a2eaf
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44366
Reviewed-by: Gabe Black <gabe.bl...@gmail.com>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/dev/reg_bank.hh
M src/dev/reg_bank.test.cc
2 files changed, 27 insertions(+), 7 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/dev/reg_bank.hh b/src/dev/reg_bank.hh
index 7abe02c..5dee49e 100644
--- a/src/dev/reg_bank.hh
+++ b/src/dev/reg_bank.hh
@@ -30,6 +30,8 @@

 #include <algorithm>
 #include <bitset>
+#include <cassert>
+#include <cstdint>
 #include <cstring>
 #include <functional>
 #include <initializer_list>
@@ -432,6 +434,21 @@
         // The buffer's owner is responsible for serializing it.
         void serialize(std::ostream &os) const override {}
         bool unserialize(const std::string &s) override { return true; }
+
+      protected:
+        /**
+ * This method exists so that derived classes that need to initialize
+         * their buffers before they can be set can do so.
+         *
+         * @param buf The pointer to the backing buffer.
+         */
+        void
+        setBuffer(void *buf)
+        {
+            assert(_ptr == nullptr);
+            assert(buf != nullptr);
+            _ptr = buf;
+        }
     };

     // Same as above, but which keeps its storage locally.
@@ -442,8 +459,10 @@
         std::array<uint8_t, BufBytes> buffer;

         RegisterLBuf(const std::string &new_name) :
-            RegisterBuf(new_name, buffer.data(), BufBytes)
-        {}
+            RegisterBuf(new_name, nullptr, BufBytes)
+        {
+            this->setBuffer(buffer.data());
+        }

         void
         serialize(std::ostream &os) const override
diff --git a/src/dev/reg_bank.test.cc b/src/dev/reg_bank.test.cc
index 78fc9e6..088f1f3 100644
--- a/src/dev/reg_bank.test.cc
+++ b/src/dev/reg_bank.test.cc
@@ -244,16 +244,17 @@
   protected:
     static constexpr size_t RegSize = 4;

-    RegisterBankLE::RegisterBuf reg;
-
     std::array<uint8_t, RegSize * 3> buf;
     std::array<uint8_t, RegSize * 3> backing;

+    RegisterBankLE::RegisterBuf reg;
+
   public:
-    RegisterBufTest() : reg("buf_reg", backing.data() + RegSize, RegSize),
-        buf{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc},
+    RegisterBufTest()
+      : buf{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc},
         backing{0x10, 0x20, 0x30, 0x40, 0x50, 0x60,
-                0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0}
+                0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0},
+        reg("buf_reg", backing.data() + RegSize, RegSize)
     {}
 };
 // Needed by C++14 and lower

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44366
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I0f8d0f6efb5d4b7abc5fc6c2c3ecca2c9b0a2eaf
Gerrit-Change-Number: 44366
Gerrit-PatchSet: 3
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to