Skip to content

Commit 800bc43

Browse files
committed
fix issue open64-compiler#35 for WHIRL2llvm
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]>
1 parent 17b1d28 commit 800bc43

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

osprey/ir_tools/whirl2llvm.cxx

+8
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ BOOL Run_vsaopt = FALSE; // hack to workaround undefine since
116116
# define Is_True(a, b) ((void)1)
117117
#endif
118118

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

120121
static INT Compiler_Line = 0;
121122
static const char *Compiler_File = NULL;
@@ -4220,6 +4221,13 @@ WHIRL2llvm::WN2llvmSymAct(WN *wn, ACTION act, LVVAL *rhs)
42204221
} // end of GLOBAL_SYMTAB
42214222
case SCLASS_FORMAL: {
42224223
LVALC *arg_addr = nullptr;
4224+
4225+
if (Fix_TY_mtype(WN_type(wn)) != MTYPE_UNKNOWN) {
4226+
PLOC ploc = Get_Input_Parameter_Location(WN_type(wn));
4227+
if (Mload_ty(WN_type(wn)))
4228+
offset = ALIGNMENT_DOWN(offset, PLOC_size(ploc));
4229+
}
4230+
42234231
CONSTSTR var = Adjust_parm_name(varname, offset);
42244232
BOOL on_stack = FALSE;
42254233
TY_IDX parmtype = Find_parm_type(var, &on_stack);

0 commit comments

Comments
 (0)