aboutsummaryrefslogtreecommitdiff
path: root/gcc/langhooks.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-03-25 09:18:33 +0100
committerJakub Jelinek <jakub@redhat.com>2020-03-25 09:18:33 +0100
commit158cccea0d097d9f181bf4e35fdeb97865c960f7 (patch)
treee30b193d875bdb9d77fe1964f4d38352ec848990 /gcc/langhooks.c
parentf1154b4d3c54e83d493cc66d1a30c410b9b3108a (diff)
downloadgcc-158cccea0d097d9f181bf4e35fdeb97865c960f7.zip
gcc-158cccea0d097d9f181bf4e35fdeb97865c960f7.tar.gz
gcc-158cccea0d097d9f181bf4e35fdeb97865c960f7.tar.bz2
middle-end: Avoid using DECL_UID in ASM_FORMAT_PRIVATE_NAME [PR94223]
As mentioned in the PR, we don't guarantee DECL_UID to be the same between corresponding decls in -g and -g0 builds, -g can create more decls and all that is guaranteed is that the DECL_UIDs of the corresponding decls compare the same. The following testcase gets a -fcompare-debug failure because these functions use DECL_UID as the number in ASM_FORMAT_PRIVATE_NAME. The patch fixes it by using just a sequential number there instead. I don't think this can be called during PCH writing, this only happens for non-public decls and the C/C++ FEs shouldn't mangling those at that point (furthermore C++ FE uses a different set_decl_assembler_name hook and this one is something only the gimplifier calls on C.NNNN temporaries. 2020-03-25 Jakub Jelinek <jakub@redhat.com> PR c++/94223 * langhooks.c (lhd_set_decl_assembler_name): Use a static ulong counter instead of DECL_UID. * lto-lang.c (lto_set_decl_assembler_name): Use a static ulong counter instead of DECL_UID. * g++.dg/opt/pr94223.C: New test.
Diffstat (limited to 'gcc/langhooks.c')
-rw-r--r--gcc/langhooks.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index 640bd01..5e3216d 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -160,16 +160,17 @@ lhd_set_decl_assembler_name (tree decl)
Can't use just the variable's own name for a variable whose scope
is less than the whole compilation. Concatenate a distinguishing
- number - we use the DECL_UID. */
+ number. */
if (TREE_PUBLIC (decl) || DECL_FILE_SCOPE_P (decl))
id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
else
{
const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
+ static unsigned long num;
char *label;
- ASM_FORMAT_PRIVATE_NAME (label, name, DECL_UID (decl));
+ ASM_FORMAT_PRIVATE_NAME (label, name, num++);
id = get_identifier (label);
}