Opened 6 years ago
Closed 6 years ago
#59 closed defect (fixed)
Unsized generics have incorrect pointer arithmetic
Reported by: | Thierry Delisle | Owned by: | |
---|---|---|---|
Priority: | major | Component: | cfa-cc |
Version: | 1.0 | Keywords: | |
Cc: |
Description
The following program produces an incorrect result:
#include <fstream> forall(dtype T) struct wrapper{ T * ptr; int size; }; typedef long long int type_t; int main() { type_t a[10]; wrapper(type_t) w = {a, 10}; type_t * start_w = w.ptr; type_t * end_w = w.ptr + w.size; sout | start_w | "+ (" | w.size | "*" | sizeof(type_t) | ") == " | end_w | endl; }
The result should be :
0x7fffb3dc1d50 + (10 * 8) == 0x7fffb3dc1da0
The actual result is :
0x7fffb3dc1d50 + (10 * 8) == 0x7fffb3dc1d5a
(Addresses may vary)
This is because the size of the type is not used.
The problem cause away by adding the "sized" constraint to the generic type.
Possible fixes:
- Disallow pointer arithmetic in this case.
- Somehow get the size.
Change History (2)
comment:1 Changed 6 years ago by
comment:2 Changed 6 years ago by
Owner: | set to Rob Schluntz <rschlunt@…> |
---|---|
Resolution: | → fixed |
Status: | new → closed |
In b95fe40:
Note: See
TracTickets for help on using
tickets.
I think this is related to #42. In both cases, adding a cast fixes the problem.
result:
Perhaps when dtype-static generics are monomorphized, the extra cast should be added to any uses of the dtype member?