home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / gcc / bug / 2786 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.4 KB  |  106 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!tera.com!rrh
  3. From: rrh@tera.com (Robert R. Henry)
  4. Subject: sparc va_arg botches some structure passing
  5. Message-ID: <9211172006.AA11270@tera.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 17 Nov 1992 20:06:47 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 93
  12.  
  13. The following program contains a varargs routine,
  14. which is given a 32 bit structure by value in one
  15. of the varargs slots.
  16.  
  17. It is compiled by BOTH gcc2.3.1 and gcc2.2.2, host=sparc, target=sparc.
  18.  
  19. When the resulting code is executed it bus errors at the line marked ``HERE''.
  20. Examining the faulting instruction shows that it is executing
  21.     ld [%o1], %o0
  22. with o1 containing 113.  The value 113 is what the va_arg
  23. should ultimately deliver; there's one too many indirections going on.
  24.  
  25. This situation happens even if the structure actual parameter
  26. is the first actual parameter after the 'op' parameter (so
  27. its unlikely to be a register window alignment problem, altho
  28. one never knows).
  29.  
  30. #include <stdio.h>
  31. #include <stdarg.h>
  32.  
  33. typedef int TERA_Boolean;
  34.  
  35. typedef enum _FullEmptyControl{
  36.     FE_NORMAL = 0     
  37.     ,FE_FUTURE = 2     
  38.     ,FE_SYNC = 3     
  39. } FullEmptyControl;
  40.  
  41. typedef struct _OperationAccessControl{
  42.     int    :27  ;     
  43.     TERA_Boolean fwd_disable   :1  ;     
  44.     FullEmptyControl fe_control   :2  ;     
  45.     TERA_Boolean trap1_disable   :1  ;     
  46.     TERA_Boolean trap0_disable   :1  ;     
  47. } OperationAccessControl;  
  48.  
  49. typedef long long int int64;
  50.  
  51. void encode(int64 *r_result, int op, ...)
  52. {
  53.   static int v[] = {
  54.     0,
  55.     1, 1, 2,
  56.     3, 2, -1
  57.   };
  58.   int64 result;
  59.   int shift_amt = 64;
  60.   int iarg;
  61.   int shift = 0;
  62.   int pass_op;
  63.   unsigned int uarg;
  64.   int type;
  65.   int optype;
  66.   int save_low_offset;
  67.   va_list ap;
  68.   va_start(ap,  op);
  69.  
  70.   for (iarg = 0; v[iarg] >= 0; iarg++){
  71.     switch(v[iarg]){
  72.     case 0:    /* begin */
  73.       printf("begin\n");
  74.       break;
  75.     case 1:    /* reg */
  76.       uarg = va_arg(ap, unsigned int);
  77.       printf("reg %d\n", uarg);
  78.       break;
  79.     case 2:    /* lit */
  80.       printf("lit\n");
  81.       break;
  82.     case 3:    /* UnsOpAC */
  83.       {
  84.     union {
  85.       OperationAccessControl ac;
  86.       int prt;
  87.     } ac_ctrl;
  88.     OperationAccessControl acl;
  89. /* BUS ERROR HERE */
  90.     acl = va_arg(ap, OperationAccessControl);
  91.     printf("oac %d\n", ac_ctrl.prt);
  92.     break;
  93.       }
  94.     default:
  95.       break;
  96.     }
  97.   }
  98. }
  99.  
  100. main()
  101. {
  102.   int64 x;
  103.   encode(&x, 0, 17, 18, 113, 117);
  104. }
  105.  
  106.