This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/12108] New: wrong code generated in the presence of asm("...")
- From: "anton at mips dot complang dot tuwien dot ac dot at" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Aug 2003 09:57:55 -0000
- Subject: [Bug c/12108] New: wrong code generated in the presence of asm("...")
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12108
Summary: wrong code generated in the presence of asm("...")
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: anton at mips dot complang dot tuwien dot ac dot at
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: hppa-linux
The 3.3.2 version is the one distributed with Debian.
Also shows up on gcc-3.2 on hppa2.0n-hp-hpux11.00, but not on
gcc-2.95.2 on hppa2.0n-hp-hpux11.00, nor on a number of non-hppa
platforms.
Command line:
gcc -o conftest -g -O2 conftest.c -L/lib/pa1.1/
conftest.c is:
int foo(int);
main()
{
exit(foo(0)!=16);
}
int foo(int x)
{
if (x) {
label1:
asm(".skip 16"); /* or ".space 16" or somesuch */
label2:
}
return (&&label2)-(&&label1);
}
(The purpose of this program is a test for autoconf: test if .skip
works as we expect).
This program crashes, because the code in the asm statement is
executed even though x is 0.
A small variation is to insert some code before label1:
int foo(int);
main()
{
exit(foo(0)!=16);
}
int y;
int foo(int x)
{
if (x) {
y++;
label1:
asm(".skip 16"); /* or ".space 16" or somesuch */
label2:
}
return (&&label2)-(&&label1);
}
This time the program finishes, but produces the wrong result, because
(interpreting the disassembled code) "&&label1" is computed as if it was
placed before the "y++":
(gdb) disass foo
Dump of assembler code for function foo:
;;; File: conftest.c
;;; if (x) {
0x2648 <foo>: cmpib,= 0,%r26,0x266c <foo+36>
0x264c <foo+4>: addil L'0,%dp,%r1
;;; y++;
0x2650 <foo+8>: ldw 0x20(%r1),%r19
0x2654 <foo+12>: ldo 1(%r19),%r19
0x2658 <foo+16>: stw %r19,0x20(%r1)
;;; asm(".skip 16"); /* or ".space 16" or somesuch */
0x265c <foo+20>: break 0,0
0x2660 <foo+24>: break 0,0
0x2664 <foo+28>: break 0,0
0x2668 <foo+32>: break 0,0
;;; return (&&label2)-(&&label1);
0x266c <foo+36>: ldil L'0x2000,%ret0
0x2670 <foo+40>: ldil L'0x2000,%r19
0x2674 <foo+44>: ldo 0x650(%r19),%r19
0x2678 <foo+48>: ldo 0x66c(%ret0),%ret0
;;; }
0x267c <foo+52>: bv %r0(%rp)
0x2680 <foo+56>: sub %ret0,%r19,%ret0
0x2684 <foo+60>: break 0,0
I.e., &&label1 (%r19 at the end) is computed as 0x2650, but it should
be 0x265c.