Commit 72443fb88c

Veikka Tuominen <git@vexu.eu>
2023-03-02 11:48:13
translate-c: handle more wrapper types in `isAnyopaque`
1 parent 0909f47
Changed files (2)
src/translate_c.zig
@@ -4926,6 +4926,22 @@ fn isAnyopaque(qt: clang.QualType) bool {
             const typedef_decl = typedef_ty.getDecl();
             return isAnyopaque(typedef_decl.getUnderlyingType());
         },
+        .Elaborated => {
+            const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty);
+            return isAnyopaque(elaborated_ty.getNamedType().getCanonicalType());
+        },
+        .Decayed => {
+            const decayed_ty = @ptrCast(*const clang.DecayedType, ty);
+            return isAnyopaque(decayed_ty.getDecayedType().getCanonicalType());
+        },
+        .Attributed => {
+            const attributed_ty = @ptrCast(*const clang.AttributedType, ty);
+            return isAnyopaque(attributed_ty.getEquivalentType().getCanonicalType());
+        },
+        .MacroQualified => {
+            const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty);
+            return isAnyopaque(macroqualified_ty.getModifiedType().getCanonicalType());
+        },
         else => return false,
     }
 }
test/translate_c.zig
@@ -3026,7 +3026,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\pub export fn log2(arg_a: u32) c_int {
         \\    var a = arg_a;
         \\    var i: c_int = 0;
-        \\    while (a > @bitCast(c_uint, @as(c_int, 0))) {
+        \\    while (a > @bitCast(u32, @as(c_int, 0))) {
         \\        a >>= @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
         \\    }
         \\    return i;