Bug 36282 - [4.7 Regression] Spurious warning "asm declaration ignored due to conflict with previous rename"
Summary: [4.7 Regression] Spurious warning "asm declaration ignored due to conflict wi...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: 4.8.3
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-05-20 19:44 UTC by Denis Vlasenko
Modified: 2014-06-12 12:53 UTC (History)
5 users (show)

See Also:
Host: i386-pc-linux-gnu
Target: i386-pc-linux-gnu
Build: i386-pc-linux-gnu
Known to work: 3.4.6, 4.8.3, 4.9.0
Known to fail: 4.7.2, 4.7.4, 4.8.0
Last reconfirmed: 2013-03-21 00:00:00


Attachments
gcc49-pr36282.patch (1.22 KB, patch)
2014-03-13 14:05 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Denis Vlasenko 2008-05-20 19:44:47 UTC
Just run "gcc -c test.c" on this:

#pragma weak __pthread_initialize
extern void *memcpy (void *__restrict __dest,
       __const void *__restrict __src, int __n)
     __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
extern __typeof (memcpy) memcpy __asm__ ("" "__GI_memcpy") __attribute__ ((visibility ("hidden")));

void f(void) {}

$ gcc -c test.c
test.c:5: warning: asm declaration ignored due to conflict with previous rename

With "#pragma weak __pthread_initialize" line commented out, it does not happen.

$ gcc -v
Using built-in specs.
Target: i386-pc-linux-gnu
Configured with: ../gcc-4.2.1/configure --prefix=/usr/app/gcc-4.2.1 --exec-prefix=/usr/app/gcc-4.2.1 --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/app/gcc-4.2.1/libexec --datadir=/usr/app/gcc-4.2.1/share --sysconfdir=/etc --sharedstatedir=/usr/app/gcc-4.2.1/var/com --localstatedir=/usr/app/gcc-4.2.1/var --libdir=/usr/lib --includedir=/usr/include --infodir=/usr/info --mandir=/usr/man --with-slibdir=/usr/app/gcc-4.2.1/lib --with-local-prefix=/usr/local --with-gxx-include-dir=/usr/app/gcc-4.2.1/include/g++-v3 --enable-languages=c,c++ --without-system-zlib --disable-nls --enable-threads=posix i386-pc-linux-gnu
Thread model: posix
gcc version 4.2.1
Comment 1 Denis Vlasenko 2008-05-20 19:48:02 UTC
Simplified case:

#pragma weak __pthread_initialize
extern void *memcpy(void *dest, const void *src, int n);
extern typeof(memcpy) memcpy asm("__GI_memcpy");

void f(void) {}
Comment 2 Khem Raj 2010-02-17 06:18:15 UTC
this warning also triggers with current head/4.5.0
Comment 3 Bernhard Reutner-Fischer 2013-03-21 18:21:00 UTC
Confirmed.

Still the same with gcc version 4.7.2 (Debian 4.7.2-5):
$ cat <<EOF | gcc -x c -c - -o /dev/null
#pragma weak __pthread_initialize
extern void *memcpy(void *dest, const void *src, int n);
extern typeof(memcpy) memcpy asm("__GI_memcpy");
EOF
<stdin>:2:14: warning: conflicting types for built-in function ‘memcpy’ [enabled by default]
<stdin>:3:1: warning: asm declaration ignored due to conflict with previous rename [-Wpragmas]
Comment 4 Bernhard Reutner-Fischer 2013-03-22 12:59:10 UTC
(In reply to comment #3)
> Confirmed.
> 
> Still the same with gcc version 4.7.2 (Debian 4.7.2-5):
> $ cat <<EOF | gcc -x c -c - -o /dev/null
> #pragma weak __pthread_initialize
> extern void *memcpy(void *dest, const void *src, int n);
> extern typeof(memcpy) memcpy asm("__GI_memcpy");
> EOF
> <stdin>:2:14: warning: conflicting types for built-in function ‘memcpy’
> [enabled by default]
> <stdin>:3:1: warning: asm declaration ignored due to conflict with previous
> rename [-Wpragmas]

Works as expected if one provides a decl before the #pragma:

$ cat <<EOF | gcc -fno-builtin -x c -c - -o /dev/null
extern void __pthread_initialize (void);
#pragma weak __pthread_initialize
extern void *memcpy(void *dest, const void *src, int n);
extern typeof(memcpy) memcpy asm("__GI_memcpy");
EOF
$ cat <<EOF | gcc -fno-builtin -x c -c - -o /dev/null
#pragma weak __pthread_initialize
extern void __pthread_initialize (void);
extern void *memcpy(void *dest, const void *src, int n);
extern typeof(memcpy) memcpy asm("__GI_memcpy");
EOF
<stdin>:4:1: warning: asm declaration ignored due to conflict with previous rename [-Wpragmas]

Honza, does that ring a bell, by chance?
Comment 5 Bernhard Reutner-Fischer 2013-03-22 13:06:47 UTC
$ gcc-3.4 -fno-exceptions -fomit-frame-pointer -fno-builtin -S pr36282.c -o ok.s
$ gcc-4.7 -fno-exceptions -fomit-frame-pointer -fno-builtin -S pr36282.c -o nak.s
pr36282.c:3:1: warning: asm declaration ignored due to conflict with previous rename [-Wpragmas]

$ cat pr36282.c 
#pragma weak __pthread_initialize
extern void *memcpy(void *dest, const void *src, int n);
extern typeof(memcpy) memcpy asm("__GI_memcpy");
char *usr(void) {
	char ch[2];
	return memcpy(&ch, "x", 2);
}
$ cat ok.s
	.file	"pr36282.c"
	.section	.rodata
.LC0:
	.string	"x"
	.text
.globl usr
	.type	usr, @function
usr:
.LFB2:
	subq	$24, %rsp
.LCFI0:
	movq	%rsp, %rdi
	movl	$2, %edx
	movl	$.LC0, %esi
	call	__GI_memcpy
	addq	$24, %rsp
	ret
.LFE2:
	.size	usr, .-usr
	.section	.eh_frame,"a",@progbits
.Lframe1:
	.long	.LECIE1-.LSCIE1
.LSCIE1:
	.long	0x0
	.byte	0x1
	.string	""
	.uleb128 0x1
	.sleb128 -8
	.byte	0x10
	.byte	0xc
	.uleb128 0x7
	.uleb128 0x8
	.byte	0x90
	.uleb128 0x1
	.align 8
.LECIE1:
.LSFDE1:
	.long	.LEFDE1-.LASFDE1
.LASFDE1:
	.long	.LASFDE1-.Lframe1
	.quad	.LFB2
	.quad	.LFE2-.LFB2
	.byte	0x4
	.long	.LCFI0-.LFB2
	.byte	0xe
	.uleb128 0x20
	.align 8
.LEFDE1:
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.4.6 (Debian 3.4.6-10)"

$ cat nak.s
	.file	"pr36282.c"
	.section	.rodata
.LC0:
	.string	"x"
	.text
	.globl	usr
	.type	usr, @function
usr:
.LFB0:
	.cfi_startproc
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rsp, %rax
	movl	$2, %edx
	movl	$.LC0, %esi
	movq	%rax, %rdi
	call	memcpy
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	usr, .-usr
	.ident	"GCC: (Debian 4.7.2-5) 4.7.2"
	.section	.note.GNU-stack,"",@progbits
Comment 6 Richard Biener 2013-04-11 07:59:24 UTC
GCC 4.7.3 is being released, adjusting target milestone.
Comment 7 Jakub Jelinek 2014-03-13 14:05:15 UTC
Created attachment 32345 [details]
gcc49-pr36282.patch

Untested fix.  If this turns out to be too expensive (though, I think #pragma weak is rare and the patch should at most double the time to compute DECL_ASSEMBLER_NAME), perhaps we could use some spare bit in decl_with_vis to mean DECL_ASSEMBLER_NAME_SET_P (in addition to the current two tests).  Then we could keep the computed assembler name cached and still pretend the name has not been set, decl_assembler_name would set that bit.  We'd need to handle with care the cases when the bit is unset and say we rename the symbol though, then of course we'd need to first SET_DECL_ASSEMBLER_NAME to NULL.
Comment 8 Jakub Jelinek 2014-03-13 20:56:39 UTC
Author: jakub
Date: Thu Mar 13 20:56:06 2014
New Revision: 208557

URL: http://gcc.gnu.org/viewcvs?rev=208557&root=gcc&view=rev
Log:
	PR middle-end/36282
	* c-pragma.c (apply_pragma_weak): Only look at
	TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) if
	DECL_ASSEMBLER_NAME_SET_P (decl).
	(maybe_apply_pending_pragma_weaks): Exit early if
	vec_safe_is_empty (pending_weaks) rather than only when
	!pending_weaks.
	(maybe_apply_pragma_weak): Likewise.  If !DECL_ASSEMBLER_NAME_SET_P,
	set assembler name back to NULL afterwards.

	* c-c++-common/pr36282-1.c: New test.
	* c-c++-common/pr36282-2.c: New test.
	* c-c++-common/pr36282-3.c: New test.
	* c-c++-common/pr36282-4.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/pr36282-1.c
    trunk/gcc/testsuite/c-c++-common/pr36282-2.c
    trunk/gcc/testsuite/c-c++-common/pr36282-3.c
    trunk/gcc/testsuite/c-c++-common/pr36282-4.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-pragma.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2014-03-13 20:57:27 UTC
Fixed on the trunk.
Comment 10 Jakub Jelinek 2014-04-10 07:48:26 UTC
Author: jakub
Date: Thu Apr 10 07:47:55 2014
New Revision: 209263

URL: http://gcc.gnu.org/viewcvs?rev=209263&root=gcc&view=rev
Log:
	Backport from mainline
	2014-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/36282
	* c-pragma.c (apply_pragma_weak): Only look at
	TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) if
	DECL_ASSEMBLER_NAME_SET_P (decl).
	(maybe_apply_pending_pragma_weaks): Exit early if
	vec_safe_is_empty (pending_weaks) rather than only when
	!pending_weaks.
	(maybe_apply_pragma_weak): Likewise.  If !DECL_ASSEMBLER_NAME_SET_P,
	set assembler name back to NULL afterwards.

	* c-c++-common/pr36282-1.c: New test.
	* c-c++-common/pr36282-2.c: New test.
	* c-c++-common/pr36282-3.c: New test.
	* c-c++-common/pr36282-4.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-1.c
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-2.c
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-3.c
    branches/gcc-4_8-branch/gcc/testsuite/c-c++-common/pr36282-4.c
Modified:
    branches/gcc-4_8-branch/gcc/c-family/ChangeLog
    branches/gcc-4_8-branch/gcc/c-family/c-pragma.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Comment 11 Jakub Jelinek 2014-04-10 08:04:09 UTC
Fixed also for 4.8.3+.
Comment 12 Richard Biener 2014-06-12 12:53:01 UTC
Fixed in 4.8.3
Comment 13 Richard Biener 2014-06-12 12:53:21 UTC
.