Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function type comparison tweaks #584

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub const Func = struct {
fn eql(a: *const Func, b: *const Func, a_spec: Specifier, b_spec: Specifier, comp: *const Compilation) bool {
// return type cannot have qualifiers
if (!a.return_type.eql(b.return_type, comp, false)) return false;
if (a.params.len == 0 and b.params.len == 0) return true;

if (a.params.len != b.params.len) {
if (a_spec == .old_style_func or b_spec == .old_style_func) {
Expand All @@ -114,6 +115,7 @@ pub const Func = struct {
}
return true;
}
return false;
}
if ((a_spec == .func) != (b_spec == .func)) return false;
// TODO validate this
Expand Down
6 changes: 6 additions & 0 deletions test/cases/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ int (*return_array_ptr(void))[2] {
return &ARRAY;
}

void no_params(void);
void no_params(int x){}

#define EXPECTED_ERRORS "functions.c:10:12: error: parameter named 'quux' is missing" \
"functions.c:20:14: error: illegal initializer (only variables can be initialized)" \
"functions.c:18:2: warning: non-void function 'foooo' does not return a value [-Wreturn-type]" \
Expand All @@ -85,3 +88,6 @@ int (*return_array_ptr(void))[2] {
"functions.c:50:3: error: parameter has incomplete type 'union Union'" \
"functions.c:53:30: error: parameter has incomplete type 'enum E'" \
"functions.c:55:9: error: parameter has incomplete type 'enum EE'" \
"functions.c:79:6: error: redefinition of 'no_params' with a different type" \
"functions.c:78:6: note: previous definition is here" \

6 changes: 6 additions & 0 deletions test/cases/redefinitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ int f4(int);
int f5(int (*)(), double (*)[3]);
int f5(int (*)(char), double (*)[]); // not compatible since char undergoes default argument promotion

void f6();
void f6(void) {}

void f7(void);
void f7() {}

#define EXPECTED_ERRORS "redefinitions.c:4:5: error: redefinition of 'foo' as different kind of symbol" \
"redefinitions.c:1:5: note: previous definition is here" \
"redefinitions.c:5:5: error: redefinition of 'foo' as different kind of symbol" \
Expand Down
Loading