Skip to content

[Tests] Re-enable the tests for integer overflow diagnostics #15811

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 2 commits into from
Apr 13, 2018

Conversation

ravikandhadai
Copy link
Contributor

This commit splits up the test suite 'diagnostic_constant_propagation_propagation_int.swift'
into two files one each for 64bit and 32bit architectures.
The tests check the diagnostics for arithmetic and bitwise operations on
'Int' and 'UInt' values. The size of these numeric types depend on the word length of
the target architecture. Most of the tests added in this commit were present
earlier but were xfailed.

@ravikandhadai ravikandhadai added the test suite Area: test suite label Apr 7, 2018
Copy link
Contributor

@devincoughlin devincoughlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. It is great to see these re-enabled and using -verify instead of FileCheck!

See one comment inline about using PTRSIZE instead of enumerating architectures.

@@ -0,0 +1,235 @@
// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify
//
// REQUIRES: CPU=x86_64 || CPU=arm64 || CPU=powerpc64 || CPU=powerpc64le || CPU=s390x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder it might be better to use PTRSIZE=64 and PTRSIZE=32. Pointer size and Int size aren't the same thing -- but this would avoid having to enumerate all 64-bit CPUs

}

do {
// bitwise operations. No overflows canhappen during these operations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo "canhappen"

@@ -0,0 +1,232 @@
// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify
//
// REQUIRES: CPU=i386 || CPU=arm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do || in REQUIRES?! o_O

Copy link
Contributor

@moiseev moiseev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

This commit splits up the test suite 'diagnostic_constant_propagation_propagation_int.swift'
into two files one each for 64bit and 32bit architectures.
The tests check the diagnostics for arithmetic and bitwise operations on
'Int' and 'UInt' values. The size of these numeric types depend on the word length of
the target architecture. Most of the tests added in this commit were present
earlier but were xfailed.
@ravikandhadai
Copy link
Contributor Author

Hi Devin and Max,
Thanks for the comments. I have changed the requires to use PTRSIZE and it seems to work on my system (64bit) and iPhone-i386-simulator. So I have used it instead of checking for specific architectures.

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please smoke test merge

@moiseev
Copy link
Contributor

moiseev commented Apr 13, 2018

@ravikandhadai this is not the real command =)

@moiseev
Copy link
Contributor

moiseev commented Apr 13, 2018

@swift-ci Please smoke test

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please smoke test merge

"Extend test/SILPasses/diagnostic_constant_propagation.swift" by removing
tests from the file that referred to `Int` and `UInt` types.
These tests are dependent on the word length of the architecture and
are covered by the tests in the files
`diagnostic_constant_propagation_int_archXX.swift`.

Also, this commit corrects erroneous references to a radar problem
in the test suties: `diagnostic_constant_propagation_int_archXX.swift`
@moiseev
Copy link
Contributor

moiseev commented Apr 13, 2018

@swift-ci Please smoke test

@ravikandhadai
Copy link
Contributor Author

This pull request now has two commits and I think both the commits pass the test cases. The latest commit removes the requirement on 64bit PTRSIZE for the diagnostic_constant_propagation.swift test suite.
@devincoughlin Can you please review the latest commit and see if it looks good.

@moiseev moiseev merged commit f31dba3 into swiftlang:master Apr 13, 2018
@xedin
Copy link
Contributor

xedin commented Apr 13, 2018

@devincoughlin @moiseev @ravikandhadai Would it be possible to add tests with more complex expressions as well to check that this is not too eager? E.g.

_ = Int16(integerLiteral: 0).magnitude

error: arithmetic operation '65535 + 1' (on unsigned 16-bit integer type) results in an overflow
Int16(integerLiteral: 0).magnitude
                         ^

The problem here is that getter for the magnitude uses ternary operator and one of the branches would become ~0 + 1 which is diagnosed as an overflow here incorrectly.

@ravikandhadai
Copy link
Contributor Author

@xedin Is the branch containing ~0 + 1 actually dead branch that will not be taken? let's catch up to discuss more on this.

@xedin
Copy link
Contributor

xedin commented Apr 14, 2018

@ravikandhadai yes, in this case Int16(integerLiteral: 0) that brach is dead because the check is self < (0 as ${Self}) ? ~base + 1 : base here is the actual code https://github.com/apple/swift/blob/master/stdlib/public/core/Integers.swift.gyb#L3529

@xedin
Copy link
Contributor

xedin commented Apr 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test suite Area: test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants