public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* How do I print the name of a variable created with create_tmp_var_raw
@ 2020-12-08 18:34 Thomas Koenig
  2020-12-08 19:48 ` Tobias Burnus
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2020-12-08 18:34 UTC (permalink / raw)
  To: gcc, fortran

Hi,

I would like to know the name of a variable created with
create_tmp_var_raw, but it is not clear to my how to do it.

gimple_decl_printable_name sounded like a likely candidate,
but that just returns a null pointer.  Any combination of
IDENTIFIER_POINTER and DECL_NAME that I tried also led to
checking errors or segfaults.

More specifically,

diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index f1c8f0ee17f..11043406840 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -96,7 +96,7 @@ gfc_create_var_np (tree type, const char *prefix)
    tree t;

    t = create_tmp_var_raw (type, prefix);
-
+  dprintf (2, "%s\n", IDENTIFIER_POINTER (DECL_NAME (t)));
    /* No warnings for anonymous variables.  */
    if (prefix == NULL)
      TREE_NO_WARNING (t) = 1;

which I thought should work according to the documentation I've
read resulted in a segfault.

Any pointers? Is there a magic incantation that I am missing?

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I print the name of a variable created with create_tmp_var_raw
  2020-12-08 18:34 How do I print the name of a variable created with create_tmp_var_raw Thomas Koenig
@ 2020-12-08 19:48 ` Tobias Burnus
  2020-12-08 20:39   ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Burnus @ 2020-12-08 19:48 UTC (permalink / raw)
  To: Thomas Koenig, gcc, fortran

Hi Thomas,

On 08.12.20 19:34, Thomas Koenig via Fortran wrote:
> I would like to know the name of a variable created with
> create_tmp_var_raw, but it is not clear to my how to do it.
> ...
>    t = create_tmp_var_raw (type, prefix);
> -
> +  dprintf (2, "%s\n", IDENTIFIER_POINTER (DECL_NAME (t)));

I think that's okay. However:

Do you have a prefix or not?

If there is no prefix, DECL_NAME (t) == NULL.

If there is a prefix, the name is create_tmp_var_name (prefix),
which is (on most systems)   "%s.%d", prefix, tmp_var_id_num++

Otherwise, the D.1234 you see in the dump is mostly the result of
"D.%u", DECL_UID (t).

I hope it helps,

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I print the name of a variable created with create_tmp_var_raw
  2020-12-08 19:48 ` Tobias Burnus
@ 2020-12-08 20:39   ` Thomas Koenig
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Koenig @ 2020-12-08 20:39 UTC (permalink / raw)
  To: Tobias Burnus, gcc, fortran


Hi Tobias,

> On 08.12.20 19:34, Thomas Koenig via Fortran wrote:
>> I would like to know the name of a variable created with
>> create_tmp_var_raw, but it is not clear to my how to do it.
>> ...
>>    t = create_tmp_var_raw (type, prefix);
>> -
>> +  dprintf (2, "%s\n", IDENTIFIER_POINTER (DECL_NAME (t)));
> 
> I think that's okay. However:
> 
> Do you have a prefix or not?
> 
> If there is no prefix, DECL_NAME (t) == NULL.
> 
> If there is a prefix, the name is create_tmp_var_name (prefix),
> which is (on most systems)   "%s.%d", prefix, tmp_var_id_num++
> 
> Otherwise, the D.1234 you see in the dump is mostly the result of
> "D.%u", DECL_UID (t).

Yes, this clears up things.  Thanks!

I am currently trying to figure out better ways of debugging
generated code (PR 90207) and one thing is to make intermediate
variables visible to the debugger, of course under control of
a special flag.  The dot is of course not a good choice beause
gdb will not print a variable called S.0, but maybe a @ will work.

Or, less amitious, sometimes it is hard to see by which path a
certain variable is generated. Being able to set a breakpoint
where a certain variable is being generated can help a lot.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-08 20:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 18:34 How do I print the name of a variable created with create_tmp_var_raw Thomas Koenig
2020-12-08 19:48 ` Tobias Burnus
2020-12-08 20:39   ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).