Add support for literal zero in FnPtrNull rewriter pass#438
Add support for literal zero in FnPtrNull rewriter pass#438
FnPtrNull rewriter pass#438Conversation
This adds LIT checks for a few existing cases at the top and some new tests. The two LIT checks at the bottom are valid code, but I'm not sure if that's the simplest way to rewrite that.
|
Got ast matchers for the null in the three cases in the broken wip commit but I'm trying to find how to get the right After this it should be straightforward to copy the relevant matchers from |
| // REWRITER: fn = (typeof(fn)) { NULL }; | ||
| fn = NULL; |
There was a problem hiding this comment.
I don't think this case is handled correctly if using a define other than NULL. In zlib they use a custom ZNULL define (still just 0), and when running the rewriter on this branch it seems like ZNULL gets replaced by 0. For example:
strm->zalloc = Z_NULL;gets rewritten to
strm->zfree = (typeof(strm->zfree)) { 0 };I'm not sure if that's something we can or care to fix, since it doesn't really have a functional difference.
There was a problem hiding this comment.
The output is totatlly broken rn but that's a good catch about custom NULL macros. What I had in mind would've generated (typeof(f)) { NULL } which wouldn't be the best thing to do. None of this is developer-facing though so I might just have all cases use 0 instead of the corresponding macros.
We previously assumed that initializing, assigning or comparing function pointers with
NULLwould not use an integer literal. @randomPoison hit this issue with zlib so this PR adds support for those cases and new tests. It also takes into account the cases with and without a cast on the zero. I've covered most of the new cases, except comparisons since those interact with AST matchers inFnPtrEqso I'm thinking about the best way to handle them.IA2_ADDRinvocations for null checks #411.