Opened 8 years ago
Closed 8 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.
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?