-
Notifications
You must be signed in to change notification settings - Fork 242
Address most implicit 64-to-32-bit conversion warnings. #525
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
Conversation
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.
Presume from your commit message you were trying to remove warnings from the 8-bit library code when built in a 64bit system, could you elaborate on what is the driver behind that?
|
|
||
| BOOL | ||
| PRIV(ckd_smul)(PCRE2_SIZE *r, int a, int b) | ||
| PRIV(ckd_smul)(PCRE2_SIZE *r, ptrdiff_t a, ptrdiff_t b) |
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.
the whole point of this function is to make sure those 2 parameters are intso we can check for overflow
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.
Ah, yeah, the hand-coded branch would need reworking. (__builtin_mul_overflow should DTRT regardless.) However, without this change, pcre2test's process_data could in principle pass in a truncated replen, yielding incorrect results. Should it instead bail if replen > INT_MAX?
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.
pcre2test is a test application, AFAIK replen was made a size_t just to avoid having to do a cast, and it is expected never to have a value larger than int either, so a truncation there shouldn't be possible, but feel free to poke at it and prove me wrong.
the call for ckd_smul was indeed how we are making sure that the value of the multiplication is always correct.
FWIW you could NOT build this test application if all you want is the library an want it to be warning free, there is a configure and cmake option for that. You haven't answered my original question so I am still not sure what the end goal is.
src/pcre2_jit_compile.c
Outdated
| } | ||
|
|
||
| static SLJIT_INLINE void allocate_stack(compiler_common *common, int size) | ||
| static SLJIT_INLINE void allocate_stack(compiler_common *common, sljit_uw size) |
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.
probably should had been PCRE2_SIZE but were missed when PCRE2 was created from PCRE1 (which used int for all offsets)
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.
PCRE2_SIZE substituted, thanks!
| __attribute__((no_sanitize_address)) | ||
| #endif | ||
| static sljit_u8* SLJIT_FUNC FF_FUN(sljit_u8 *str_end, sljit_u8 **str_ptr, sljit_uw offs1, sljit_uw offs2, sljit_uw chars) | ||
| static sljit_u8* SLJIT_FUNC FF_FUN(sljit_u8 *str_end, sljit_u8 **str_ptr, sljit_uw offs1, sljit_uw offs2, sljit_u32 chars) |
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.
this should break the 16bit library
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.
Not AFAICT, though I must admit I'd initially focused on the 8-bit one.
zherczeg
left a comment
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.
Please be very careful when changing jit types.
| struct sljit_compiler *compiler; | ||
| int store_bases[RECURSE_TMP_REG_COUNT]; | ||
| int store_offsets[RECURSE_TMP_REG_COUNT]; | ||
| sljit_sw store_offsets[RECURSE_TMP_REG_COUNT]; |
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.
These are intentionally small values.
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.
Without this change, delayed_mem_copy_move's assignment into store_offsets can wind up truncated. Attempting to narrow the type of its store_offset argument instead reveals that three call sites pass in 64-bit values.
src/pcre2_jit_compile.c
Outdated
| /* These values should never be negative, suggesting the use of sljit_u32. | ||
| However, they should also remain (far) below 1 << 31, and (would-be) | ||
| negative *differences* won't otherwise undergo correct sign extension. */ | ||
| sljit_s32 c, charoffset, max = 256, min = READ_CHAR_MAX; |
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.
c can be UINT32_MAX, so this is also a bad change.
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.
Good point. I've scrapped all changes to compile_xclass_matchingpath in favor of formally making read_char's min and max sljit_uw.
Visual Studio and Xcode both issue such warnings by default, and Clang also offers a -Wshorten-64-to-32 option to expose them elsewhere. To address them, harmonize types where practical and add casts as appropriate (first formally capping executables' read request sizes as necessary). NB: detect_repeat in pcre2_jit_compile.c still yields two such warnings that look plausibly legitimate but not so easy to fix. :-/ Signed-off-by: Aaron M. Ucko <[email protected]>
| pcre2_set_depth_limit(pcre2_match_context *, uint32_t); \ | ||
| PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ | ||
| pcre2_set_heap_limit(pcre2_match_context *, uint32_t); \ | ||
| pcre2_set_heap_limit(pcre2_match_context *, PCRE2_SIZE); \ |
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.
API functions cannot be changed, even if they are not the best.
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.
Oops, yeah, I didn't mean to introduce an ABI break. :-/
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.
Ah, right, I'll need to revert the POSIX API changes too.
|
Thanks for the quick feedback! I've force-pushed a largely corrected (and rebased) version and will reply on individual points shortly. AFAICT, some of these changes really should help in corner cases; although the remainder are formalities, the (configuration-dependent) warnings they address could bury other warnings (none here at present, I'm happy to report). I acknowledge that this PR still needs more work. |
|
Thank you Aaron (@ucko) for pushing us to fix these warnings. I have addressed them in PR #655, hopefully. I took a slightly different direction to you on some of the fixes. We now pass with I have not addressed all the warnings generated by Let me know if you are satisfied with the level of warnings suppression on |
|
Thank you for this PR. I think we have now incorporated all the changes here. Many thanks! |
Visual Studio and Xcode both issue such warnings by default, and Clang also offers a
-Wshorten-64-to-32option to expose them elsewhere. To address them, harmonize types where practical and add casts as appropriate (first formally capping executables' read request sizes as necessary). NB:detect_repeatinpcre2_jit_compile.cstill yields two such warnings that look plausibly legitimate but not so easy to fix. :-/