This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Miscompilation...
- From: Bill Wendling <isanbard at gmail dot com>
- To: Bill Wendling <isanbard at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 8 Apr 2007 21:40:32 -0700
- Subject: Re: Miscompilation...
- References: <279646F3-158B-412E-89DD-5FFED5B8AF5C@gmail.com>
On Apr 8, 2007, at 6:50 PM, Bill Wendling wrote:
Hi all,
This program:
#include <stdio.h>
struct tree_type {
unsigned int precision : 9;
};
void *bork(const void *Ty, unsigned Subpart) {
printf("Subpart == %08x\n", Subpart);
return 0;
}
const void *TConvertType(tree_type* type) {
asm("movl $1104150528, (%%esp)" : : );
This should be
asm("movl $1104150528, 4(%%esp)" : : );
const void *Ty = 0;
return bork(Ty, type->precision);
}
const void *foo(tree_type* type) {
asm("movl $1104150528, (%%esp)" : : );
Same here.
const void *Ty = 0;
unsigned S = type->precision;
return bork(Ty, S);
}
int main()
{
struct tree_type t;
t.precision = 1;
TConvertType(&t);
foo(&t);
return 0;
}
Compiled with "c++ t.c" Should print out:
Subpart == 00000001
Subpart == 00000001
But instead prints out:
Subpart == 8fe50001
Subpart == 00000001
Which means that this outputs:
Subpart == 41d00001
Subpart == 00000001
(on my iMac). The problem seems to be that, in the TConvertType
function passes
"type->precision" as an HI instead of SI to the "bork" function.
The asm code is:
movl $1104150528, (%esp)
And this would be:
movl $1104150528, 4(%esp)
movl $0, -4(%ebp)
movl 8(%ebp), %eax
movzwl (%eax), %eax
andw $511, %ax
movw %ax, 4(%esp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call __Z4borkPKvj
for TConvertType, so the %ax isn't putting a full SI onto the
stack, leaving
garbage in the MSBs of 4(%esp), which "bork" expects to be 0, of
course.
I believe I got the TOT -- .svn/entries says "svn://gcc.gnu.org/svn/
gcc/trunk". Is
this a known problem?
Thanks!
-bw