-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix __builtin_{smulll,saddll}_overflow() usage #2205
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
@swift-ci test |
@swift-ci test linux |
@@ -6442,14 +6442,16 @@ reswtch:switch (ch) { | |||
return true; | |||
} | |||
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { | |||
int64_t number = 0; | |||
long long _number = 0; |
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.
Why the renaming of the number
? That seems gratuitous.
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.
number
is used further down as an int64_t
but that is probably not needed as it only checks for INT32_MAX
later on, I will update.
- Use a variable of type long long variable not int64_t as they may be different sizes. - Fixes "warning: incompatible pointer types passing 'int64_t *' (aka 'long *') to parameter of type 'long long *' [-Wincompatible-pointer-types]"
6c44a37
to
0f6e80a
Compare
@swift-ci test |
@swift-ci test linux |
do { | ||
if (__builtin_smulll_overflow(number, 10, &number) || __builtin_saddll_overflow(number, ch - '0', &number)) { | ||
if (__builtin_smulll_overflow(number, 10, &number) || __builtin_saddll_overflow(number, ch - '0', &number) || number > INT64_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.
Isn't this a tautological comparison? number
is a long long
which is signed. INT64_MAX
is signed. So the value of the condition is always false.
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.
long long
is only defined to be at least 64 bits but could be more if ever ported to other platforms. This is a bit of a nit-picking change but it should make it technically correct.
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 platform(s) currently define it to something other than 64-bit?
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.
I'm okay taking pedantic correctness fixes, since this is code intended to be portable.
@swift-ci please test and merge |
Use a variable of type long long variable not int64_t as they may be
different sizes.
Fixes "warning: incompatible pointer types passing 'int64_t *' (aka 'long *')
to parameter of type 'long long *' [-Wincompatible-pointer-types]"