-
Notifications
You must be signed in to change notification settings - Fork 244
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
StmtExpr dropped during translation (was lseek not translated) #181
Comments
similar (related?) problem: #include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/file.h>
void* pci_map_resource() {
char* path = "/sys/bus/pci/devices/0000:01:00.0/resource0";
int fd = open(path, O_RDWR);
struct stat stat;
fstat(fd, &stat);
return mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
} skips the the function we are actually trying to translate is https://github.com/emmericp/ixy/blob/57679a086343b9ae9d97e059e13a3226482910a6/src/pci.c#L42 which curiously fails for another reason: it skips the the examples included in the posts were checked with https://c2rust.com/ the actual code linked was converted with current c2rust git master (current crates.io release didn't compile) |
There's another place in the code that uses lseek that seemed to be translated properly: https://github.com/emmericp/ixy/blob/57679a086343b9ae9d97e059e13a3226482910a6/src/pci.c#L27 |
We did get a few warnings when transpiling the C code:
Unfortunately, |
Well, looks like we need the stdint.h include for the minimal example on the website, so no minimal example, sorry :( This is the actual code we are trying to translate which lacks the |
I think #define check_err(expr, op) ({\
int64_t result = (int64_t) (expr);\
if ((int64_t) result == -1LL) {\
int err = errno;\
char buf[512];\
strerror_r(err, buf, sizeof(buf));\
fprintf(stderr, "[ERROR] %s:%d %s(): Failed to %s: %s\n", __FILE__, __LINE__, __func__, op, buf);\
exit(err);\
}\
result;\
})
int bar(void) {
return 1;
}
void foo(void) {
check_err(bar(), "afoo");
}
int main(void) {
foo();
} c2rs seems to be ignoring the expanded macro contents for some reason. |
I just translated the minimal example using github master, and it seems fine. What OS are you translating on? I just tried translating ixy on the latest Arch linux, and it fails to translate a |
Could you elaborate on build issues? The crates.io release should compile. |
We've manually fixed the two obvious mistranslations (the fstat and lseek calls linked above), it then starts up fine but doesn't work, so I guess there are more failures that we didn't catch. Basic initialization seems fine, it successfully initializes the device, the link comes up and it reads statistics registers showing correct packet counts. But it doesn't actually retrieve any packets from the NIC which is unfortunately very hard to debug build issues: @ackxolotl |
That's weird, I get an empty |
Well, it turned out that after uninstalling the |
I can also reproduce the build issues on my Mac:
compiling git master works |
I hadn't pushed the latest version to crates.io (did that last night), so the build instructions on github specified a newer rustc nightly version than the crates.io package required. I'm guessing something along those lines was happening. I'll check and see if I can reproduce the install issue on Mac. |
can confirm that it builds fine now on my mac; the log from above is a build i started yesterday evening. we'll retry to translate our C code tomorrow |
I believe that the bug with `check_err` is still there, so don’t be
surprised if it doesn’t work yet. I can reproduce that, so we’ll try to get
that fixed.
|
The |
it's working now, thanks :) And the transpiled code is actually 17% faster than the original C code when compiled with the same LLVM version :O |
Not sure if this is related, but I got a few warnings like this during compilation:
probably caused by the |
We generate extra parens in some cases due to this rust issue: rust-lang/rust#54482 It might be possible to determine it's not necessary in this particular case, but it'd probably require some extra analysis. And |
example:
is translated to
The text was updated successfully, but these errors were encountered: