pro64-contrib
[Top] [All Lists]

Question concerning function calls and pointers in Whirl

To: "Pro64 Contrib" <pro64-contrib@xxxxxxxxxxx>, "Benedict. Gaster@St. Com" <benedict.gaster@xxxxxx>
Subject: Question concerning function calls and pointers in Whirl
From: "Benedict R. Gaster" <benedict.gaster@xxxxxx>
Date: Wed, 20 Jun 2001 15:41:27 +0100
Importance: Normal
Sender: owner-pro64-contrib@xxxxxxxxxxx
Hello!

Consider a target with the following byte sizes for C base types:

  sizeof(int) = sizeof(long) = sizeof(char *) = 4
  sizeof(long long) = 64


These target requirements are expressed and implemented in
./gccfe/gnu/config/TARGET/target.h:

  ...
  #define BITS_PER_UNIT 8
  #define BITS_PER_WORD 32
  #define UNITS_PER_WORD 4
  #define POINTER_SIZE 32
  #define INT_TYPE_SIZE 32
  #define LONG_TYPE_SIZE 32
  #define LONG_LONG_TYPE_SIZE 64
  #define CHAR_TYPE_SIZE 8
  ...

and ./common/com/TARGET/config_targ.[h|cxx]:

    ...
    Pointer_Size   = 4;
    Pointer_Mtype  = WHIRL_Mtype_A_On ? MTYPE_A4 : MTYPE_U4;
    Pointer_type   = Pointer_Mtype;
    Pointer_Mtype2 = MTYPE_U4;
    Pointer_type2  = MTYPE_U4;
    ...

So compiling the following simple program:

  int printf(char *, ...);

  int main(void)
  {
    printf("Hello World\n");
    return 0;
  }

we might expect to get the following Whirl output:

 LOC 0 0 source files:  1
"/home/afra/users/benedict/dev/pro64/hello.c"
 LOC 1 3 int main(void)
 LOC 1 4 {
FUNC_ENTRY <1,20,main>
BODY
 BLOCK
 END_BLOCK
 BLOCK
 END_BLOCK
 BLOCK
 PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END
 LOC 1 5        printf("Hello World\n");
   U4LDA 0 <1,22,(13_bytes)_"Hello_World\n\000"> T<31,anon_ptr.,4>
  U4PARM 2 T<28,anon_ptr.,4> #  by_value
 VCALL 126 <1,21,printf> # flags 0x7e
 LOC 1 6
 LOC 1 7        return 0;
  I4INTCONST 0 (0x0)
 I4RETURN_VAL
 END_BLOCK

however the actual output we currently get is:

 LOC 0 0 source files:  1
"/home/afra/users/benedict/dev/pro64/hello.c"
 LOC 1 3 int main(void)
 LOC 1 4 {
FUNC_ENTRY <1,20,main>
BODY
 BLOCK
 END_BLOCK
 BLOCK
 END_BLOCK
 BLOCK
 PRAGMA 0 120 <null-st> 0 (0x0) # PREAMBLE_END
 LOC 1 5        printf("Hello World\n");
   U4LDA 0 <1,22,(13_bytes)_"Hello_World\n\000"> T<31,anon_ptr.,4>
  U4PARM 2 T<28,anon_ptr.,8> #  by_value *!!!!**** this has changed to 8
****!!!!*
 VCALL 126 <1,21,printf> # flags 0x7e
 LOC 1 6
 LOC 1 7        return 0;
  I4INTCONST 0 (0x0)
 I4RETURN_VAL
 END_BLOCK

Here here the argument to the Whirl node VCALL is still U4PARM, as expected,
but its type now has a size of 8 bytes, rather than 4!

This seems to only happen when passing pointers to a function and not when
passing unsigned integers, for example, as can be seen in the following:

  int bar(unsigned int);

   ...
  bar(x);
   ...

which gives:

    ...
   U4U4LDID 0 <2,1,x> T<8,.predef_U4,4>
  U4PARM 2 T<8,.predef_U4,4> #  by_value
 VCALL 126 <1,21,bar> # flags 0x7e
    ...

Have we just missed something silly or something more nasty?

thanks for any help,

ben.


<Prev in Thread] Current Thread [Next in Thread>