Skip to content

Commit fe9691b

Browse files
committed
Fix debug metadata for arrays with negative bounds
For Fortran array with negative bounds, the ACON here is a sptr + offset address constant, sptr is the base symbol representing the array and need not adding the positive offset to the !DIExpression of the array variable.
1 parent 6e41c0b commit fe9691b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/flang2/flang2exe/cgmain.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11669,8 +11669,13 @@ gen_acon_expr(int ilix, LL_Type *expected_type)
1166911669
return make_constval_op(make_int_lltype(ptrbits), val[1], val[0]);
1167011670
}
1167111671
sym_is_refd(sptr);
11672-
process_sptr_offset(sptr, variable_offset_in_aggregate(
11673-
sptr, ACONOFFG(opnd) < 0 ? 0 : ACONOFFG(opnd)));
11672+
/* In case of non-struct, e.g. a Fortran array may have ACON as sptr + offset,
11673+
* the "offset" works with "bound" and "index" together to calculate the
11674+
* addresses of array elements. However, when generating debug metadata, the
11675+
* "offset" is not needed in the !DIExpression of the array variable. The
11676+
* array variable's location always starts from the beginning/first element. */
11677+
idx = (STYPEG(sptr) == ST_ARRAY || ACONOFFG(opnd) < 0) ? 0 : ACONOFFG(opnd);
11678+
process_sptr_offset(sptr, variable_offset_in_aggregate(sptr, idx));
1167411679
idx = ACONOFFG(opnd); /* byte offset */
1167511680

1167611681
ty1 = make_lltype_from_dtype(DT_ADDR);

0 commit comments

Comments
 (0)