Program: 149989
Project: 149989
Buggy source:
/** 
 * Generate call and return sequence to invoke a C function through the boot record field specificed by target.  Caller handles parameter passing and expression stack  (setting up args, pushing return, adjusting stack height). <pre> Create a linkage area that's compatible with RS6000 "C" calling conventions. Just before the call, the stack looks like this: hi-mem +-------------------------+  . . . . . . . . |          ...            |                  \ +-------------------------+                   | |          ...            |    \              | +-------------------------+     |             | |       (int val0)        |     |  java       |- java +-------------------------+     |-  operand   |   stack |       (int val1)        |     |    stack    |    frame +-------------------------+     |             | |          ...            |     |             | +-------------------------+     |             | |      (int valN-1)       |     |             | +-------------------------+    /              | |          ...            |                   | +-------------------------+                   | |                         | <-- spot for this frame's callee's return address +-------------------------+                   | |          MI             | <-- this frame's method id +-------------------------+                   | |       saved FP          | <-- this frame's caller's frame +-------------------------+  . . . . . . . . / |      saved JTOC         | +-------------------------+  . . . . . . . . . . . . . . | parameterN-1 save area  | +  \                         \ +-------------------------+     |                         | |          ...            | +   |                         | +-------------------------+     |- register save area for | |  parameter1 save area   | +   |    use by callee        | +-------------------------+     |                         | |  parameter0 save area   | +  /                          |  rs6000 +-------------------------+                               |-  linkage +20 |       TOC save area     | +                             |    area +-------------------------+                               | +16 |       (reserved)        | -    + == used by callee      | +-------------------------+      - == ignored by callee   | +12 |       (reserved)        | -                             | +-------------------------+                               | +8 |       LR save area      | +                             | +-------------------------+                               | +4 |       CR save area      | +                             | +-------------------------+                               | FP ->  +0 |       (backlink)        | -                             | +-------------------------+  . . . . . . . . . . . . . . / Notes: 1. parameters are according to host OS calling convention. 2. space is also reserved on the stack for use by callee as parameter save area 3. parameters are pushed on the java operand stack left to right java conventions) but if callee saves them, they will appear in the parameter save area right to left (C conventions)
 */
private void generateSysCall(int parametersSize,VM_Field target){
  int linkageAreaSize=parametersSize + BYTES_IN_STACKSLOT + (6 * BYTES_IN_STACKSLOT);
  if (VM.BuildFor32Addr) {
    asm.emitSTWU(FP,-linkageAreaSize,FP);
  }
 else {
    asm.emitSTDU(FP,-linkageAreaSize,FP);
  }
  asm.emitSTAddr(JTOC,linkageAreaSize - BYTES_IN_STACKSLOT,FP);
  asm.emitLAddrToc(S0,VM_Entrypoints.the_boot_recordField.getOffset());
  asm.emitLAddrOffset(0,S0,target.getOffset());
  asm.emitLAddrOffset(JTOC,0,BYTES_IN_STACKSLOT);
  asm.emitLAddrOffset(0,0,0);
  asm.emitMTCTR(0);
  asm.emitBCCTRL();
  asm.emitLAddr(JTOC,linkageAreaSize - BYTES_IN_STACKSLOT,FP);
  asm.emitADDI(FP,linkageAreaSize,FP);
}

Fixed version (ground truth):
/** 
 * Generate call and return sequence to invoke a C function through the boot record field specificed by target.  Caller handles parameter passing and expression stack  (setting up args, pushing return, adjusting stack height). <pre> Create a linkage area that's compatible with RS6000 "C" calling conventions. Just before the call, the stack looks like this: hi-mem +-------------------------+  . . . . . . . . |          ...            |                  \ +-------------------------+                   | |          ...            |    \              | +-------------------------+     |             | |       (int val0)        |     |  java       |- java +-------------------------+     |-  operand   |   stack |       (int val1)        |     |    stack    |    frame +-------------------------+     |             | |          ...            |     |             | +-------------------------+     |             | |      (int valN-1)       |     |             | +-------------------------+    /              | |          ...            |                   | +-------------------------+                   | |                         | <-- spot for this frame's callee's return address +-------------------------+                   | |          MI             | <-- this frame's method id +-------------------------+                   | |       saved FP          | <-- this frame's caller's frame +-------------------------+  . . . . . . . . / |      saved JTOC         | +-------------------------+  . . . . . . . . . . . . . . | parameterN-1 save area  | +  \                         \ +-------------------------+     |                         | |          ...            | +   |                         | +-------------------------+     |- register save area for | |  parameter1 save area   | +   |    use by callee        | +-------------------------+     |                         | |  parameter0 save area   | +  /                          |  rs6000 +-------------------------+                               |-  linkage +20 |       TOC save area     | +                             |    area +-------------------------+                               | +16 |       (reserved)        | -    + == used by callee      | +-------------------------+      - == ignored by callee   | +12 |       (reserved)        | -                             | +-------------------------+                               | +8 |       LR save area      | +                             | +-------------------------+                               | +4 |       CR save area      | +                             | +-------------------------+                               | FP ->  +0 |       (backlink)        | -                             | +-------------------------+  . . . . . . . . . . . . . . / Notes: 1. parameters are according to host OS calling convention. 2. space is also reserved on the stack for use by callee as parameter save area 3. parameters are pushed on the java operand stack left to right java conventions) but if callee saves them, they will appear in the parameter save area right to left (C conventions)
 */
private void generateSysCall(int parametersSize,VM_Field target){
  int linkageAreaSize=parametersSize + BYTES_IN_STACKSLOT + (6 * BYTES_IN_STACKSLOT);
  if (VM.BuildFor32Addr) {
    asm.emitSTWU(FP,-linkageAreaSize,FP);
  }
 else {
    asm.emitSTDU(FP,-linkageAreaSize,FP);
  }
  asm.emitSTAddr(JTOC,linkageAreaSize - BYTES_IN_STACKSLOT,FP);
  asm.emitLAddrToc(S0,VM_Entrypoints.the_boot_recordField.getOffset());
  asm.emitLAddrOffset(0,S0,target.getOffset());
  asm.emitLAddrOffset(JTOC,0,Offset.fromInt(BYTES_IN_STACKSLOT));
  asm.emitLAddrOffset(0,0,Offset.fromInt(0));
  asm.emitMTCTR(0);
  asm.emitBCCTRL();
  asm.emitLAddr(JTOC,linkageAreaSize - BYTES_IN_STACKSLOT,FP);
  asm.emitADDI(FP,linkageAreaSize,FP);
}