This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Miscompilation...


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)" : : );
  const void *Ty = 0;
  return bork(Ty, type->precision);
}

const void *foo(tree_type* type) {
  asm("movl $1104150528, (%%esp)" : : );
  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

(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)
        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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]