translate-c: Handle typedef'ed void return type for functions.

Fixes #10356
This commit is contained in:
Evan Haas 2022-01-10 11:54:11 -08:00 committed by Andrew Kelley
parent 6d9c02a54f
commit f4b3f1d602
3 changed files with 22 additions and 5 deletions

View File

@ -4824,11 +4824,18 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {
fn isAnyopaque(qt: clang.QualType) bool {
const ty = qt.getTypePtr();
if (ty.getTypeClass() == .Builtin) {
const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
return builtin_ty.getKind() == .Void;
switch (ty.getTypeClass()) {
.Builtin => {
const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
return builtin_ty.getKind() == .Void;
},
.Typedef => {
const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
const typedef_decl = typedef_ty.getDecl();
return isAnyopaque(typedef_decl.getUnderlyingType());
},
else => return false,
}
return false;
}
const FnDeclContext = struct {

View File

@ -1809,4 +1809,14 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
cases.add("Typedef'ed void used as return type. Issue #10356",
\\typedef void V;
\\V foo(V *f) {}
\\int main(void) {
\\ int x = 0;
\\ foo(&x);
\\ return 0;
\\}
, "");
}

View File

@ -814,7 +814,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub const Foo = anyopaque;
,
\\pub extern fn fun(a: ?*Foo) Foo;
\\pub extern fn fun(a: ?*Foo) void;
});
cases.add("duplicate typedef",