translate-c: Correctly translate enum init values, addressing #1360#1377
translate-c: Correctly translate enum init values, addressing #1360#1377andrewrk merged 6 commits intoziglang:masterfrom
Conversation
|
Thanks! Please add some test cases, since we will have to fix this in stage2 as well. |
|
@kristate Done :) It's a more minimal example than what was in the original issue, but tests for the same error. |
|
Thanks @mtn! This solves the issue but I think it breaks the case when an integer does not fit in 64 bits. Your PR is useful though because it clearly demonstrates the problem and how it can be solved. I'll leave this open until I get back from vacation in 1 week and then I'll try to fix the >64bit case as well and merge. |
|
Oh right, I didn't look at |
|
I might be wrong, but I think my last commit fixes the issue, and doesn't break on values greater than 64 bits, since it uses APSInt builtins to flip negatives to positives. I can clean up the code before merging, assuming it's correct. |
ecbbebf to
4fd8bcb
Compare
ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.
Clean-up of translate_c.cpp
|
Thanks! |
Fixes #1360
This was literally my first time looking closely at clang or llvm, so there could be a better way of doing things. I think it may also be possible to use a bit mask after grabbing the raw data to deal with the fact that it gets cast (which I think was the whole issue).
Also, I found the compiler pretty easy to understand, which was awesome!