Skip to content

Commit

Permalink
fix issue open64-compiler#35 for WHIRL2llvm
Browse files Browse the repository at this point in the history
The offset is the distance between the field of struct and the start of struct,
but the parameter just be pushed one time if the parameter just hold one register.
So we need to align down the offset of field to register size.

1. The w2ll will crash if compile the code like that:
```
typedef struct quantum_matrix_struct {
  int rows;
  int cols;
} quantum_matrix;

void
quantum_print_matrix(quantum_matrix m)
{
  int i, j;
  for(i=0; i<m.rows; i++)
  {
    for(j=0; j<m.cols; j++) {
        printf("%d\n", 1);
    }
  }
}
```

2. Error Log:
```
Find_parm_type cannot find
```

Signed-off-by: Zhijin Zeng <[email protected]>
  • Loading branch information
zengdage committed Jan 3, 2024
1 parent 17b1d28 commit 800bc43
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions osprey/ir_tools/whirl2llvm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ BOOL Run_vsaopt = FALSE; // hack to workaround undefine since
# define Is_True(a, b) ((void)1)
#endif

#define ALIGNMENT_DOWN(a, size) (a & (~(size-1)))

static INT Compiler_Line = 0;
static const char *Compiler_File = NULL;
Expand Down Expand Up @@ -4220,6 +4221,13 @@ WHIRL2llvm::WN2llvmSymAct(WN *wn, ACTION act, LVVAL *rhs)
} // end of GLOBAL_SYMTAB
case SCLASS_FORMAL: {
LVALC *arg_addr = nullptr;

if (Fix_TY_mtype(WN_type(wn)) != MTYPE_UNKNOWN) {
PLOC ploc = Get_Input_Parameter_Location(WN_type(wn));
if (Mload_ty(WN_type(wn)))
offset = ALIGNMENT_DOWN(offset, PLOC_size(ploc));
}

CONSTSTR var = Adjust_parm_name(varname, offset);
BOOL on_stack = FALSE;
TY_IDX parmtype = Find_parm_type(var, &on_stack);
Expand Down

0 comments on commit 800bc43

Please sign in to comment.