Fix Conversion Warnings with Conservative Marking - #1385
Conversation
No clang diagnostics errors during compilation
tobil4sk
left a comment
There was a problem hiding this comment.
Seems like a good change. I've also got some WIP local fixes to help get rid of some unrelated warnings in other files, I'm hoping we can eventually have cleaner code and enable warnings more globally.
| void *lastWatch = 0; | ||
| bool isWatch = false; | ||
| uintptr_t lastWatch{}; | ||
| bool isWatch{false}; |
There was a problem hiding this comment.
This seems excessive for bools, is it intended?
There was a problem hiding this comment.
Got rid of the false since thats what bools default to.
| int z = 0; | ||
| #endif | ||
| printf("but got alloc type=%d, enclosing=%d nurs=%d o=%d\n",x,y,z,sgCheckInternalOffset); | ||
| printf("but got alloc type=%d, enclosing=%d nurs=%d o=%d\n", x, y, z, static_cast<int>(sgCheckInternalOffset)); |
There was a problem hiding this comment.
Here we probably want to change the format specifier, rather than casting to int
There was a problem hiding this comment.
I did that because I wasn't sure how uintptr_t worked with printf, turns out you're supposed to use some magic PRIdPTR macro.
| hx::localCount++; | ||
| #endif | ||
| MemType mem = sGlobalAlloc->GetMemType(vptr); | ||
| MemType mem{ sGlobalAlloc->GetMemType(potentialObject) }; |
There was a problem hiding this comment.
Here the braces also seem unnecessary, since it is MemType -> MemType
There was a problem hiding this comment.
I agree but I also don't like mixing and matching the initialisation syntaxes, so I decided to go with this one for all of them.
There was a problem hiding this comment.
I understand the need for this syntax when converting between types initialisation, but using it in universally makes the code less natural and less readable imo. However if it's just limited to this marking function then I guess that's fine.
There was a problem hiding this comment.
I think ideally I'd rather use auto for all this stuff, e.g.
auto pos = size_t{ potentialObject & IMMIX_BLOCK_BASE_MARK };
auto mem = sGlobalAlloc->GetMemType(potentialObject)
I think that's consistent and I can align the variable names which I like, but I can't remember if this is C++11 or 14. Stuff around bracket initialisation changed in 14.
After a comment in #1339 this is the first of probably a few PRs where I'm going through the IMMIX GC with all of clangs conversion warnings set to errors and fixing them up.
In this case I've gone through the conservative marking function and what it calls to make them compile even if you enable all of clangs warnings as errors. There are a few things going on here.
uintptr_tis used instead ofsize_tfor pointer manipulation. As of C++11 this type is the standard sanctioned way for pointer editing.For reference below is the clang pragma I used to enable all the warnings as errors, I put these just inside the
MarkConservativefunction with a pragma pop at the end of the function to limit them to just that function and what it calls.