translate-c: fix function pointer casting + alignCast and constCast at the same time#24546
Closed
paokitore wants to merge 3 commits into
Closed
translate-c: fix function pointer casting + alignCast and constCast at the same time#24546paokitore wants to merge 3 commits into
paokitore wants to merge 3 commits into
Conversation
Member
Author
|
The previous CI failed with 3 errors and the next one will still fail with 2 errors:
For the other two, I'd say that it's more of the tests' fault. expected: var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(&foo));got: var func_ptr: ?*anyopaque = @as(?*anyopaque, @ptrCast(@volatileCast(@constCast(&foo))));This fail is quite weird because the code expected by the test actually does not compile : So I would say that this is an issue with the test. expected: @as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))got: @as([*c]c_int, @ptrCast(@volatileCast(@constCast(@alignCast(a)))))I just have an extra typedef struct {
int a;
} A;
void main() {
int a = 3;
int *a_ptr = &a;
A *aa_ptr = (A*)a_ptr;
}gets translated to pub const A = extern struct {
a: c_int = @import("std").mem.zeroes(c_int),
};
pub export fn main() void {
var a: c_int = 3;
_ = &a;
var a_ptr: [*c]c_int = &a;
_ = &a_ptr;
var aa_ptr: [*c]A = @as([*c]A, @ptrCast(@alignCast(a_ptr)));
_ = &aa_ptr;
}even though |
Member
|
Closing since we've switched to Aro-based translate-c as of #24497. Contributions to translate-c should now be opened on https://github.com/ziglang/translate-c. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes ziglang/translate-c#45 and another issue I noticed: casting
const void*toint*did not work.Both of those issues are fixed with translate-c, so this PR might be useless though.
examples:
used to translate to:
forgetting a
@constCast.and
the second line used to translate to:
forgetting a
@alignCast.