Skip to content

Conversation

xdBronch
Copy link
Contributor

fixes #23861, fixes #22766

@alexrp alexrp requested a review from Vexu May 12, 2025 10:23
@xdBronch
Copy link
Contributor Author

failures feel obvious in hindsight but i believe stuff was getting cached so i didnt get any failures locally. this will need a check against the fields natural alignment which i wasnt able to figure out before, would appreciate some guidance there.

@mlugg
Copy link
Member

mlugg commented May 12, 2025

Looks like you want clang::ASTContext::getTypeAlign: https://clang.llvm.org/doxygen/classclang_1_1ASTContext.html#afb825a845dced571b094627bfcae7870
We actually seem to have an unused wrapper for this:

zig/src/zig_clang.cpp

Lines 2463 to 2465 in bc3c50c

unsigned ZigClangASTContext_getTypeAlign(const ZigClangASTContext* self, ZigClangQualType T) {
return reinterpret_cast<const clang::ASTContext *>(self)->getTypeAlign(bitcast(T));
}

You'll just want to add a corresponding declaration on the Zig side here:

zig/src/clang.zig

Lines 164 to 167 in bc3c50c

pub const ASTContext = opaque {
pub const getPointerType = ZigClangASTContext_getPointerType;
extern fn ZigClangASTContext_getPointerType(*const ASTContext, T: QualType) QualType;
};

And use that to get the field type's natural alignment.

juliapaci added a commit to juliapaci/familiar that referenced this pull request Jun 5, 2025
squash before merge, waiting on ziglang/zig#23863 so the tests will pass then ill merge
@xdBronch
Copy link
Contributor Author

apologies for not finishing this, the logic ended being somewhat tedious and i ended up forgetting about it. im going to just close this since its already properly done in https://github.com/ziglang/translate-c + #24432 (comment)

@xdBronch xdBronch closed this Jul 13, 2025
@xdBronch xdBronch deleted the push-ozxrzpypwror branch July 13, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

translate-c fails to perserve field alignment translate c doesnt catch some explicit alignment
2 participants