diff mbox

[hsa-branch] Append UID to local variable names

Message ID 20161107184011.vjjaa66gu5iivuhc@virgil.suse.cz
State New
Headers show

Commit Message

Martin Jambor Nov. 7, 2016, 6:40 p.m. UTC
Hi,

when looking at stuff to merge to trunk, I have found out that this
patch has slipped thorough the cracks.  It adds the UID to names of
private symbols so that variables with the same name but different
scope, particularly OpenMP re-mapped ones, do not clash.

Committed to the hsa branch, will include it in the merge to trunk
too.

Thanks,

Martin


2016-11-07  Martin Jambor  <mjambor@suse.cz>

	* hsa-gen.c (hsa_get_declaration_name): Append UID to local variable
	names.
---
 gcc/hsa-gen.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index b6e8345..f138434 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -781,7 +781,8 @@  hsa_needs_cvt (BrigType16_t dtype, BrigType16_t stype)
   return false;
 }
 
-/* Return declaration name if exists.  */
+/* Return declaration name if it exists or create one from UID if it does not.
+   If DECL is a local variable, make UID part of its name.  */
 
 const char *
 hsa_get_declaration_name (tree decl)
@@ -789,7 +790,7 @@  hsa_get_declaration_name (tree decl)
   if (!DECL_NAME (decl))
     {
       char buf[64];
-      snprintf (buf, 64, "__hsa_anon_%i", DECL_UID (decl));
+      snprintf (buf, 64, "__hsa_anon_%u", DECL_UID (decl));
       size_t len = strlen (buf);
       char *copy = (char *) obstack_alloc (&hsa_obstack, len + 1);
       memcpy (copy, buf, len + 1);
@@ -808,7 +809,19 @@  hsa_get_declaration_name (tree decl)
   if (name[0] == '*')
     name++;
 
-  return name;
+  if ((TREE_CODE (decl) == VAR_DECL)
+      && decl_function_context (decl))
+    {
+      size_t len = strlen (name);
+      char *buf = (char *) alloca (len + 32);
+      snprintf (buf, len + 32, "%s_%u", name, DECL_UID (decl));
+      len = strlen (buf);
+      char *copy = (char *) obstack_alloc (&hsa_obstack, len + 1);
+      memcpy (copy, buf, len + 1);
+      return copy;
+    }
+  else
+    return name;
 }
 
 /* Lookup or create the associated hsa_symbol structure with a given VAR_DECL