Opened 8 years ago
Closed 8 years ago
#42 closed defect (fixed)
Generic index
| Reported by: | Thierry Delisle | Owned by: | |
|---|---|---|---|
| Priority: | major | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | Index Generic |
| Cc: |
Description
forall( dtype T )
struct ptr_t {
T * ptr;
};
forall( dtype T | sized( T ) )
T& ?[?]( ptr_t( T ) & this, ptrdiff_t idx ) {
return this.ptr[idx];
}
yields
test.c: In function ‘___operator_index__A0_1_0_0__FRd0_R6sptr_tl__1’:
test.c:22:56: warning: dereferencing ‘void *’ pointer
}
^
test.c:22:5: error: invalid use of void expression
}
Change History (4)
comment:1 by , 8 years ago
| Priority: | blocker → major |
|---|
comment:2 by , 8 years ago
comment:3 by , 8 years ago
This works as a workaround :
forall( dtype T )
struct ptr_t {
T * ptr;
};
forall( dtype T | sized( T ) )
T& ?[?]( ptr_t( T ) & this, ptrdiff_t idx ) {
return ((typeof(this.ptr))this.ptr)[idx];
}
Note:
See TracTickets
for help on using tickets.
I took a quick look at this. Prior to the Box pass, this code looks right:
struct ptr_t { void *__ptr__P2tT_1; }; T *___operator_index__A0_1_0_0__FRd0_R6sptr_tl__1(ptr_t(T ) *__this__R6sptr_t_1, signed long int __idx__l_1){ return ((T *)(&(*__this__R6sptr_t_1).__ptr__P2tT_1[__idx__l_1])); }But the Box pass does not correctly handle this use of subscripting, since ptr_t is dtype-static and has already been monomorphized. If you add the sized(T) assertion to the ptr_t definition, it works since ptr_t is not monomorphized.