Skip to content

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

Merged
merged 1 commit into from
May 2, 2019

Conversation

spevans
Copy link
Contributor

@spevans spevans commented May 1, 2019

  • 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]"

@spevans
Copy link
Contributor Author

spevans commented May 1, 2019

@swift-ci test

@spevans
Copy link
Contributor Author

spevans commented May 1, 2019

@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;
Copy link
Member

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.

Copy link
Contributor Author

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]"
@spevans spevans force-pushed the pr_builtin_overflow_fix branch from 6c44a37 to 0f6e80a Compare May 1, 2019 20:13
@spevans
Copy link
Contributor Author

spevans commented May 1, 2019

@swift-ci test

@spevans
Copy link
Contributor Author

spevans commented May 1, 2019

@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) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor

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.

@millenomi
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 9ba604d into swiftlang:master May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants