Open john-h-kastner opened 3 years ago
Might #408 help with this? (Just a quick reminder; you're probably more familiar with the details than I am.)
It's definitely relevant, but I don't believe it will fix the issue.
So weird! What codebase actually does this?
This is from libarchive.
typedef dev_t pack_t(int, unsigned long [], const char **);
pack_t *pack_find(const char *);
pack_t pack_native;
But there's now way to define an actual function of this type. E.g., you can't do
pack_t pack_native {
... code here ...
}
because there's no way to name the parameters, is that right? So: Seems a bit useless to make a typedef since you have to hand-write the type anyway.
Also: What is pack_find
doing? Is that returning a pointer to a pack_t
i.e., a function pointer?
pack_native
is declared without the typedef, so, yeah, kind of pointless from that perspective.
dev_t
pack_native(int n, unsigned long numbers[], const char **error)
{
// .......
}
pack_find
and a few other functions return pointers to pack_t
. I suppose that's the real purpose of the typedef.
OK that makes sense. Can we handle pack_find
(now) but it's the other case that we can't?
I don't think it correct for either yet. We do get it correct if the pack_t
typdef is a pointer.
typedef dev_t (*pack_t)(int, unsigned long [], const char **);
but if it's not a pointer like in libarchive, then the typedef is inlined for for pack_find
.
Update on this issue following the merge of #408: Typedef declarations are now represented by a ConstraintVariable
, so the foo
typedef solves and is rewritten to a checked type.
typedef void foo(int*);
// converts to
typedef void foo(_Ptr<int> );
Constraints are still not created between the typedef declaration and subsequent function declarations, so functions bar
and baz
solve exactly as before.
Constraints should be created, right? That is, when I have
foo baz;
void baz(int *a){
a =1;
};
I should create a FVConstraint
for baz
, due to the definition and our new pre-pass that unifies the constraint variable for all declarations/definitions. Then the fact that baz
is also given type foo
, I should equate the foo
constraint variable to baz
's definition's FVConstraint
, right?
Yes, equating foo
and baz
would ensure that functions declared using the typedef solve to the same type. If we do that the only change left would be to not rewrite the declaration foo baz
so that it still uses the typedef instead of expanding it to void baz(int *a : itype(_Ptr<int>));
.
Yes, sounds good to me.
In #505 I stop rewriting the declaration so that the typedef is used. The merger works now because the definition's FVC is used as the constraint target. The FVC for the typedef's declaration is constructed differently (probably a bug). I didn't add any constaints between typedef and declaration. So that's a good reason to keep this open if the current solution is not enough.
I forgot we already had this open issue for function typedefs and it is not a new problem in #505. Then I'm not worried about what #505 does in this case. Thanks.
A more extreme example to test any potential fix for this issue:
typedef int foo1_t(int);
typedef int foo2_t(int);
foo1_t foo_func;
foo2_t foo_func;
int foo_func(int y) { return 1; }
Functions
bar
andbaz
are declared using the same typedef, so their types should be equated and the their pre-declarations should continue to use the typedef.PR #436 address a rewriting error in this example (issue #430), but even after this fix, the typedef is ignored.