These polymoprhic types don't appear to be copied anywhere. Rather than
trying to reason about what it means to copy a polymoprhic base without
copying the derived part, disable copies. This also avoids a potential
double-free if a recorindg::string object does somehow get copied (it
owns a pointer to dynamically allocated memory, but the implicit copy
constructor will just make shallow copies).

Tested x86_64-linux with --enable-languages=c,c++,jit --enable-host-shared

OK for trunk?

-- >8 --

gcc/jit/ChangeLog:

        * jit-recording.h (recording::memento): Define copy constructor
        and copy assignment operator as deleted.
        (recording::string): Likewise.
        (recording::string::c_str): Add const qualifier.
---
 gcc/jit/jit-recording.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 0dfb42f2676..8610ea988bd 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -405,6 +405,9 @@ public:
   virtual void write_reproducer (reproducer &r) = 0;
   virtual location *dyn_cast_location () { return NULL; }
 
+  memento (const memento&) = delete;
+  memento& operator= (const memento&) = delete;
+
 protected:
   memento (context *ctxt)
   : m_ctxt (ctxt),
@@ -436,13 +439,16 @@ public:
   string (context *ctxt, const char *text, bool escaped);
   ~string ();
 
-  const char *c_str () { return m_buffer; }
+  const char *c_str () const { return m_buffer; }
 
   static string * from_printf (context *ctxt, const char *fmt, ...)
     GNU_PRINTF(2, 3);
 
   void replay_into (replayer *) final override {}
 
+  string (const string&) = delete;
+  string& operator= (const string&) = delete;
+
 private:
   string * make_debug_string () final override;
   void write_reproducer (reproducer &r) final override;
-- 
2.36.1

Reply via email to