Skip to content

liberal itypes for prototypes (with no def) #402

@mwhicks1

Description

@mwhicks1

Suppose we have the code

int *foo(int *a) {
 a = (int *)5;
 return a;
}
void bar(int x) {
  int *p = &x;
  int *q = foo(p);
}

Using liberalized itypes (the current 3c behavior), this translates to

int *foo(int *a : itype(_Ptr<int>)) : itype(_Ptr<int>) {
 a = (int *)5;
 return a;
}
void bar(int x) {
  _Ptr<int> p = &x;
  _Ptr<int> q = foo(p);
}

Now suppose that we didn’t have the definition of foo, but just the prototype.

int *foo(int *a);

void bar(int x) {
  int *p = &x;
  int *q = foo(p);
}

The result is that 3c makes no changes -- all pointers are left as WILD. This is because foo is not given a liberal itype, and its WILDness propagates to bar.

But this behavior seems incongruous. The reason that we treat the prototype pessimistically (i.e., all its parameters are WILD) is that we don’t have the definition to know what it does. But in the first example we do have the definition and know perfectly well what it does ---it’s unsafe! Despite that unsafety, we give it an itype anyway, since doing so facilitates more rapid conversion.

So I think that we should extend this principle to prototypes. If we have a prototype with no definition, but it is within a file that occurs within the base-dir, then we should convert it to have an itype.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions