-
Notifications
You must be signed in to change notification settings - Fork 271
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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
#include <stdio.h>
#include <string.h>
typedef enum {
b=2
} a;
typedef struct {
int data;
} d_struct;
d_struct d;
int main() {
// Initialize d with the value of `b` using compound literal and memcpy
memcpy(&d.data, &((a){b}), sizeof(a));
printf("Stored enum value: %d\n", d.data);
return 0; }
Output by GCC and Clang
Stored enum value: 2
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 for memcpy
is correctly handled by c2rust
#include <stdio.h>
typedef enum {
b=2
} a;
typedef struct {
int data;
} d_struct;
d_struct d;
int main() {
a tmp = b;
*(int*)&d.data = tmp;
printf("Stored enum value: %d\n", d.data);
return 0; }
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working