Opened 8 years ago
Closed 8 years ago
#19 closed defect (fixed)
Functions taking array types and taking pointer types are conflicting overloads
| Reported by: | Rob Schluntz | Owned by: | |
|---|---|---|---|
| Priority: | major | Component: | cfa-cc |
| Version: | 1.0 | Keywords: | include conflicting overload extern C linkage |
| Cc: |
Description
extern "C" {
void fred(int __env[1]);
void fred(int *__env);
}
cfa test3.c
CFA Version 1.0.0 (debug)
test3.c:3 error: conflicting overload of C function fred: C function
with parameters
__env: C pointer to signed int
returning
_retval_fred: Attribute with name: unused
void
Note:
See TracTickets
for help on using tickets.
This is only true of the outermost layer though. If you add just one level, they cease to be equivalent, i.e.,
int **is equivalent toint *[10], but not the same asint (*)[10]orint [10][10]). So you should be careful to only make the outermost array level mangle the same way as a pointer, if you go down this route.And actually, we already do this transformation (but improperly mangle every such array type as a pointer):
It might be that it’s happening too late though. This transformation happens in
FixFunction, which is called fromEnumAndPointerDecayandForallPointerDecayinValidate.cc, butLinkReferenceToTypesis anIndexerthat is run before either of those.As a side note, a while back I added recursion to the
ArrayTypecases inAdjustExprTypeandFixFunctionto make this transformation happen deeply, because multiple subscript operators did not work on multi-dimensional arrays. I could be convinced that this was the wrong thing to do, and that instead,adjustExprTypewas not happening in all of the right places. An alternative would be to just makeManglersmarter about how it handles pointer types that are really array types (and likewise, makeAdjustExprTypeandFixFunctionrecursive onPointerType).The first bar is correctly mangled because
FixFunctionisn’t recursive onPointerType, but as such multiple subscripts do not work:$ cat test.c void fred(int (*x)[10]) { x[0][0]; } $ cfa test.c test.c:1 error: No reasonable alternatives for expression Applying untyped: Name: ?[?] ...to: Applying untyped: Name: ?[?] ...to: Name: x constant expression (0 0: zero_t) constant expression (0 0: zero_t)