Hi,

Sorry for the very long delay (more than one year O.o).

I finally took time to apply suggestions and to update the patch to be
up-to-date.

Joined to this email.

Cordially.


Le mer. 26 juin 2024 à 17:10, David Malcolm <dmalc...@redhat.com> a écrit :
>
> On Mon, 2024-04-22 at 19:56 +0200, Guillaume Gomez wrote:
> > `param` is also inheriting from `lvalue`. I don't think adding this
> > check is a good idea
> > because it will not evolve nicely if more changes are done in
> > libgccjit.
>
> Sorry for not responding earlier.
>
> I think I agree with Guillaume here.
>
> Looking at the checklist at:
> https://gcc.gnu.org/onlinedocs/jit/internals/index.html#submitting-patches
> the patch is missing:
>
> - a feature macro in libgccjit.h such as
> #define LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name
>
> - documentation for the new C entrypoint
> - documentation for the new ABI tag (see topics/compatibility.rst).
>
> Other than that, the patch looks reasonable to me.
>
> Dave
>
> >
> > Le lun. 22 avr. 2024 à 17:19, Antoni Boucher <boua...@zoho.com> a
> > écrit :
> > >
> > > For your new API endpoint, please add a check like:
> > >
> > >    RETURN_IF_FAIL (lvalue->is_global () || lvalue->is_local (),
> > >                   NULL,
> > >                   NULL,
> > >                   "lvalue should be a variable");
> > >
> > >
> > > Le 2024-04-22 à 09 h 16, Guillaume Gomez a écrit :
> > > > Good point!
> > > >
> > > > New patch attached.
> > > >
> > > > Le lun. 22 avr. 2024 à 15:13, Antoni Boucher <boua...@zoho.com> a
> > > > écrit :
> > > > >
> > > > > Please move the function to be on lvalue since there are no
> > > > > rvalue types
> > > > > that are not lvalues that have a name.
> > > > >
> > > > > Le 2024-04-22 à 09 h 04, Guillaume Gomez a écrit :
> > > > > > Hey Arthur :)
> > > > > >
> > > > > > > Is there any reason for that getter to return a mutable
> > > > > > > pointer to the
> > > > > > > name? Would something like this work instead if you're just
> > > > > > > looking at
> > > > > > > getting the name?
> > > > > > >
> > > > > > > +  virtual string * get_name () const { return NULL; }
> > > > > > >
> > > > > > > With of course adequate modifications to the inheriting
> > > > > > > classes.
> > > > > >
> > > > > > Good catch, thanks!
> > > > > >
> > > > > > Updated the patch and attached the new version to this email.
> > > > > >
> > > > > > Cordially.
> > > > > >
> > > > > > Le lun. 22 avr. 2024 à 11:51, Arthur Cohen
> > > > > > <arthur.co...@embecosm.com> a écrit :
> > > > > > >
> > > > > > > Hey Guillaume :)
> > > > > > >
> > > > > > > On 4/20/24 01:05, Guillaume Gomez wrote:
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I just encountered the need to retrieve the name of an
> > > > > > > > `rvalue` (if
> > > > > > > > there is one) while working on the Rust GCC backend.
> > > > > > > >
> > > > > > > > This patch adds a getter to retrieve the information.
> > > > > > > >
> > > > > > > > Cordially.
> > > > > > >
> > > > > > > >      virtual bool get_wide_int (wide_int *) const {
> > > > > > > > return false; }
> > > > > > > >
> > > > > > > > +  virtual string * get_name () { return NULL; }
> > > > > > > > +
> > > > > > > >    private:
> > > > > > > >      virtual enum precedence get_precedence () const = 0;
> > > > > > >
> > > > > > > Is there any reason for that getter to return a mutable
> > > > > > > pointer to the
> > > > > > > name? Would something like this work instead if you're just
> > > > > > > looking at
> > > > > > > getting the name?
> > > > > > >
> > > > > > > +  virtual string * get_name () const { return NULL; }
> > > > > > >
> > > > > > > With of course adequate modifications to the inheriting
> > > > > > > classes.
> > > > > > >
> > > > > > > Best,
> > > > > > >
> > > > > > > Arthur
> >
>
From e11fd6a5c6d19d212a5bbc1628b8f7b766f8c682 Mon Sep 17 00:00:00 2001
From: Guillaume Gomez <guillaume1.go...@gmail.com>
Date: Fri, 18 Jul 2025 14:40:52 +0200
Subject: [PATCH 1/1] gcc/jit/ChangeLog:

	* jit-recording.h: Add lvalue::get_name method
	* libgccjit.cc (gcc_jit_lvalue_get_name): Likewise
	* libgccjit.h (gcc_jit_lvalue_get_name): Likewise
	* libgccjit.map: Likewise

gcc/testsuite/ChangeLog:

	* jit.dg/test-tls.c: Add test for gcc_jit_lvalue_get_name
---
 gcc/jit/docs/topics/compatibility.rst |  7 +++++++
 gcc/jit/docs/topics/expressions.rst   | 12 ++++++++++++
 gcc/jit/jit-recording.h               |  5 +++++
 gcc/jit/libgccjit.cc                  | 16 ++++++++++++++++
 gcc/jit/libgccjit.h                   |  6 ++++++
 gcc/jit/libgccjit.map                 |  5 +++++
 gcc/testsuite/jit.dg/test-tls.c       |  2 ++
 7 files changed, 53 insertions(+)

diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst
index 1c4b81bfff1..da337e0c040 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -453,3 +453,10 @@ temporary variable:
 ``LIBGCCJIT_ABI_34`` covers the addition of
 
  * :func:`gcc_jit_context_set_output_ident`
+
+``LIBGCCJIT_ABI_35``
+--------------------
+``LIBGCCJIT_ABI_35`` covers the addition of a function to get the name
+of an lvalue.
+
+ * :func:`gcc_jit_lvalue_get_name`
diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/expressions.rst
index 5dcb5d10bce..cae28089e9b 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -923,6 +923,18 @@ where the rvalue is computed by reading from the storage area.
 
       #ifdef LIBGCCJIT_HAVE_ALIGNMENT
 
+.. function:: const char *\
+              gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue)
+
+    Returns the name of an lvalue.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_35`; you can test for
+   its present using
+
+   .. code-block:: c
+
+      #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name
+
 Global variables
 ****************
 
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 0ac9245c2df..5a3f6d32fc7 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -1465,6 +1465,7 @@ public:
   void set_register_name (const char *reg_name);
   void set_alignment (unsigned bytes);
   unsigned get_alignment () const { return m_alignment; }
+  virtual string * get_name () const { return NULL; }
 
 protected:
   string *m_link_section;
@@ -1504,6 +1505,8 @@ public:
   const char *access_as_rvalue (reproducer &r) final override;
   const char *access_as_lvalue (reproducer &r) final override;
 
+  string * get_name () const final override { return m_name; }
+
 private:
   string * make_debug_string () final override { return m_name; }
   void write_reproducer (reproducer &r) final override;
@@ -1763,6 +1766,8 @@ public:
 
   void set_rvalue_init (rvalue *val) { m_rvalue_init = val; }
 
+  string * get_name () const final override { return m_name; }
+
 private:
   string * make_debug_string () final override { return m_name; }
   template <typename T>
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 725a5d53d06..e77f22fbe51 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -4655,3 +4655,19 @@ gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt,
   RETURN_IF_FAIL (asm_stmts, ctxt, NULL, "NULL asm_stmts");
   ctxt->add_top_level_asm (loc, asm_stmts);
 }
+
+/* Public entrypoint.  See description in libgccjit.h.
+
+   After error-checking, this calls the trivial
+   gcc::jit::recording::lvalue::get_name method, in jit-recording.h.  */
+
+extern const char *
+gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue)
+{
+  RETURN_NULL_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue");
+  auto name = lvalue->get_name ();
+
+  if (!name)
+    return NULL;
+  return name->c_str ();
+}
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index bc9fcaee245..1913603703b 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -2153,6 +2153,12 @@ gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable,
 				     enum gcc_jit_variable_attribute attribute,
 				     const char* value);
 
+/* Returns the name of the `lvalue`, if any. Returns NULL otherwise.  */
+extern const char *
+gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue);
+
+#define LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name
+
 extern void
 gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
 				  const char* output_ident);
diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
index fcb6e6f2a55..1a5587930d7 100644
--- a/gcc/jit/libgccjit.map
+++ b/gcc/jit/libgccjit.map
@@ -325,3 +325,8 @@ LIBGCCJIT_ABI_34 {
   global:
     gcc_jit_context_set_output_ident;
 } LIBGCCJIT_ABI_33;
+
+LIBGCCJIT_ABI_35{
+  global:
+    gcc_jit_lvalue_get_name;
+} LIBGCCJIT_ABI_34;
diff --git a/gcc/testsuite/jit.dg/test-tls.c b/gcc/testsuite/jit.dg/test-tls.c
index 3b20182ac10..a6a967eac56 100644
--- a/gcc/testsuite/jit.dg/test-tls.c
+++ b/gcc/testsuite/jit.dg/test-tls.c
@@ -28,6 +28,8 @@ create_code (gcc_jit_context *ctxt, void *user_data)
       ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "foo");
   gcc_jit_lvalue_set_tls_model (foo, GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC);
 
+  CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (foo), "foo");
+
   /* Build the test_fn.  */
   gcc_jit_function *test_fn =
     gcc_jit_context_new_function (ctxt, NULL,
-- 
2.50.0

Reply via email to