-
Notifications
You must be signed in to change notification settings - Fork 252
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
c2rust Translation Failure with Enums in Compound Literals #1168
Labels
bug
Something isn't working
Comments
This is not an issue with typedef enum {
b=2
} a;
int main() {
(a){b};
return 0;
} |
This seems to resolve the error: diff --git a/c2rust-transpile/src/translator/literals.rs b/c2rust-transpile/src/translator/literals.rs
index d8eb64db6..861bb1467 100644
--- a/c2rust-transpile/src/translator/literals.rs
+++ b/c2rust-transpile/src/translator/literals.rs
@@ -246,6 +246,10 @@ impl<'c> Translation<'c> {
let id = ids.first().unwrap();
self.convert_expr(ctx.used(), *id)
}
+ CTypeKind::Enum(_) => {
+ let id = ids.first().unwrap();
+ self.convert_expr(ctx.used(), *id)
+ }
CTypeKind::Vector(CQualTypeId { ctype, .. }, len) => {
self.vector_list_initializer(ctx, ids, ctype, len)
} |
Yeaseen
changed the title
c2rust Translation Failure with memcpy Used on Enum Compound Literals
c2rust Translation Failure with Enums in Compound Literals
Dec 4, 2024
Thank you for your response, @fw-immunant Should I give it a try and create a PR for this? |
Yeah, that would be great! Thanks! |
kkysen
pushed a commit
that referenced
this issue
Dec 6, 2024
…#1185) * Fixes #1168. ### Modification: - Suggested changes mentioned in #1168 were added in the `c2rust-transpile/src/translator/literals.rs` file - Added a relevant C program in `tests/enums/src/enum_compound.c` file - Modified `tests/enums/src/test_enums.rs` file to check the correct outputs ### Testing The added test case specifically checks for the correct assignment of enum values in buffer initialization using compound literals. This test has been integrated into the existing test suite and passed successfully, confirming the fix.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
When translating C code that initializes a struct's integer field from an enum using
memcpy
with a compound literal,c2rust
fails, indicating potential unimplemented handling or a bug in translating such memory operations.Source C code
Output by GCC and Clang
godbolt view
Observed Behavior: Transpilation Failure with the following error message
$ c2rust-transpile compile_commands.json -e -o transpiled_code --binary runner Transpiling runner.c error: Failed to translate main: Init list not implemented for Enum(CDeclId(1131))
I think this is related to
memcpy
as the following alternative formemcpy
is correctly handled byc2rust
The text was updated successfully, but these errors were encountered: