frankpfenning / C0

C0 Language
4 stars 0 forks source link

Implicit declarations of structs cause C compilation to fail #57

Closed frankpfenning closed 8 years ago

frankpfenning commented 10 years ago

Enrique Naudon from 15-411, Fall 2013, reported the following bug, where gcc on the output of the C0 compiler fails. The issue is that that an implicit declaration of a struct in a parameter list has entirely local scope. If cc0 generated an struct declaration at the beginning of the file (or the companion header file), it would compile correctly without warning or error.

//test error

int bar(struct wrapper *foo);

struct wrapper {
  struct s *undef;
};

int main()
{
  struct wrapper *blah = alloc(struct wrapper);

  return bar(blah);
}

struct s {
  int a;
};

int bar(struct wrapper *foo)
{
  foo->undef->a = 10;

  return foo->undef->a;
}
robsimmons commented 8 years ago

Should be fixed in revision 525, by redundantly re-declaring all structs that appear in parameter lists before the functions, which gives them global scope.