Opened 4 years ago

Closed 4 years ago

#42 closed defect (fixed)

Generic index

Reported by: Thierry Delisle Owned by: Rob Schluntz <rschlunt@…>
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 Changed 4 years ago by Thierry Delisle

Priority: blockermajor

comment:2 Changed 4 years ago by Rob Schluntz

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.

comment:3 Changed 4 years ago by Thierry Delisle

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];
}

comment:4 Changed 4 years ago by Rob Schluntz <rschlunt@…>

Owner: set to Rob Schluntz <rschlunt@…>
Resolution: fixed
Status: newclosed

In b95fe40:

Add casts to dtype-static member expressions to prevent loss of type information [fixes #42] [fixes #59]

Note: See TracTickets for help on using tickets.