-
Notifications
You must be signed in to change notification settings - Fork 261
use a repeat expression for arrays with a single initializer #1218
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
base: master
Are you sure you want to change the base?
Conversation
Looks like you need to update your CI to use a newer ubuntu version (we usually use
|
I forget exactly why but the latest Ubuntu might've broke something in CI (it did for rav1d recently). |
Ok well maybe I'm also not sure what's up with the azure runners, but it doesn't look like the changes in the PR would cause those errors: Maybe pinning |
I am going to switch us off the Azure runners as soon as I get the time to do so. If you've tested locally and are convinced your change is not the cause of the breakage, that's good enough for me. Feel free to merge without CI passing. And thanks for contributing this improvement! |
dde4256
to
e9e772e
Compare
Quick note @folkertdev : I would like to avoid PR that changes the transpiler AND the CI. Those should be separate PRs. (Testing on this PR is fine but don't feel obliged to try to fix the CI) |
e9e772e
to
d3b0451
Compare
ah, I'll split that out then. I'd just like CI to check my work, not everything runs locally. |
08248b9
to
6e5fd7d
Compare
I misinterpreted what C actually does earlier. The usage of int foo[] = { 0 } is extremely widespread, but at least with modern compilers it is equivalent in practice to int foo[] = { } Anyway, that is not at all similar to So this has now been fixed to still detect the extremely common I ran test file locally and diffed the outputs. I'm not able to run any of the tests though, e.g. this fails
That file does |
@folkertdev, I merged your CI PR #1219 now, so you can rebase this now if you want and hopefully more CI works now. I didn't want to rebase for your in case it messes anything up you might've been working on. |
6e5fd7d
to
6e6acc9
Compare
Well I was playing with more complicated zero initializers (e.g. So let's merge this when CI is happy, and then we'll see if the more complex case comes up. |
Btw, wouldn't something like |
@folkertdev some test like c2rust/tests/items/src/test_fn_attrs.rs Line 24 in 71c95a2
include_str! and check if string contains suitable output)
|
int arr4[16] = {0}; | ||
arr4[15] += 9; | ||
|
||
struct {short; int y;} arr5[1] = { { 1, 2 } }; | ||
arr5[0].y += 9; | ||
|
||
// excess elements | ||
int arr6[2] = { 1, 2, 3 }; | ||
int arr7[0] = { 1234 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add to test_arrays.rs
that these arrays translate as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What actually runs the logic in test_arrays.rs
? just a cargo test
does not seem to do it, the functions in that file appear to never be actually called, and they are not marked #[test]
.
// we'll emit that as [0; 16]. | ||
let len = mk().lit_expr(mk().int_unsuffixed_lit(n as u128)); | ||
Ok(self | ||
.implicit_default_expr(ty, ctx.is_static)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We specifically want zero initialization, not necessarily default initialization, although they are usually the same, and seems to be for all cases in fn implicit_default_expr
. It seems like it doesn't handle struct
s/union
s/enum
s, though, which fn zero_initializer
does, so we probably want to use both and clarify the naming/docs to ensure it's specifically zero.
Yes, it definitely would. I've used it in newer tests like for |
translate
to
instead of a literal with 65535 zeros.
I also simplified the logic. Although https://github.com/GaloisInc/C2Rust/issues/40 is a dead link I believe the second commit is correct.