Skip to content

Add gcc_jit_lvalue_get_name #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gcc/jit/docs/topics/compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,10 @@ temporary variable:
``LIBGCCJIT_ABI_34`` covers the addition of

* :func:`gcc_jit_context_set_output_ident`

``LIBGCCJIT_ABI_44``
--------------------
``LIBGCCJIT_ABI_44`` covers the addition of a function to get the name
of an lvalue.

* :func:`gcc_jit_lvalue_get_name`
12 changes: 12 additions & 0 deletions gcc/jit/docs/topics/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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_44`; you can test for
its present using

.. code-block:: c

#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name

Global variables
****************

Expand Down
5 changes: 5 additions & 0 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,7 @@ class lvalue : public rvalue
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;
Expand Down Expand Up @@ -1539,6 +1540,8 @@ class param : public lvalue
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;
Expand Down Expand Up @@ -1807,6 +1810,8 @@ class global : public lvalue

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>
Expand Down
16 changes: 16 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4842,6 +4842,22 @@ gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt,
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 ();
}

/* Public entrypoint. See description in libgccjit.h.

After error-checking, this calls the trivial
Expand Down
6 changes: 6 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2236,6 +2236,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);
Expand Down
7 changes: 6 additions & 1 deletion gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,9 @@ LIBGCCJIT_ABI_42 {
LIBGCCJIT_ABI_43{
global:
gcc_jit_type_set_tree_addressable;
} LIBGCCJIT_ABI_42;
} LIBGCCJIT_ABI_42;

LIBGCCJIT_ABI_44{
global:
gcc_jit_lvalue_get_name;
} LIBGCCJIT_ABI_43;
2 changes: 2 additions & 0 deletions gcc/testsuite/jit.dg/test-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down