Skip to content

test: use the clang definition for UNIT{32,64}_MAX #23651

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
Mar 30, 2019

Conversation

compnerd
Copy link
Member

Rather than defining our own type, use the clang definition which is
what Swift actually uses. This repairs the ClangImporter.macros and
ClangImporter.macro_literals tests.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ac90f617fe261860f5c323b3f3bec7ee62c47feb

@@ -10,9 +10,9 @@
#define GL_RGB 0x1907
#define GL_RGBA 0x1908
#define EOF (-1)
#define UINT32_MAX 0xFFFFFFFFU
#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL
#define UINT64_MAX 0xFFFFFFFFFFFFFFFFLL
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh, hm. These were also being tested as edge-case constants with suffixes. Can you leave that in in some form?

Copy link
Member Author

@compnerd compnerd Mar 29, 2019

Choose a reason for hiding this comment

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

The clang definitions do have the suffixes as well:

clang -target x86_64-apple-macosx10.14 -x c -E /dev/null -dM -o - | grep -e __UINT32_MAX__ -e __INT64_MAX__ -e __UINT64_MAX__ 
#define __UINT32_MAX__ 4294967295U
#define __INT64_MAX__ 9223372036854775807LL
#define __UINT64_MAX__ 18446744073709551615ULL

Does the hex vs decimal encoding really matter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see the difference ... you had left __UINT64_MAX__ as a signed value rather than unsigned. Was that intentional? Could've used a comment about that. However, the UINT32_MAX and INT64_MAX values seem identical to me (modulo spelling).

Copy link
Contributor

@jrose-apple jrose-apple Mar 29, 2019

Choose a reason for hiding this comment

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

I think these spellings were copied out of macOS's limits.h (well, not actually that, but somewhere in <sys/*/*.h>). The hex vs. decimal could also make a difference given that Swift could be looking at the spelling of the constant for a hint about the intended type. (It's not currently, but it could.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, actually, now Im not sure how this works on non-Windows. XOR_HIGH is xor-ing a signed and unsigned type, so you should get a signed type. How does that get cast?

error: cannot convert value of type 'Int64' to type 'CUnsignedLongLong' (aka 'UInt64') in coercion

Copy link
Contributor

Choose a reason for hiding this comment

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

Again, it's not typed, so it has to pick what ^ should do. According to the "usual arithmetic conversions", the values can't be represented in the signed type, so the unsigned type should be preferred.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I wasn't very clear. The problem is that UINT32_MAX is suffixed with LL which is going to be promoted to unsigned long long by clang, except on Windows, because Microsoft does not permit that conversion and keeps it as a signed long long we have a type mismatch between the constants.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's important to know, then! I think Clang's behavior is more standards-compliant, but we should be testing that we're consistent with the platform.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, its platform specific. I think that right now, I want to just make it unsigned for the existing tests and then add a specific test to ensure that the LL promotion happens in a target platform specific manner. Much like we did with the anonymous enumerations case :-).

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, that works.

Windows will keep the imported type as `signed long long` rather than
`unsigned long long` as per the Microsoft compiler behaviour.  This
breaks the tests for this case.  Unfortunately, this is one of those
areas which must differ.
@compnerd
Copy link
Member Author

@swift-ci please smoke test

@compnerd
Copy link
Member Author

@swift-ci please smoke test macOS platform

@compnerd compnerd merged commit 7cf4c6b into swiftlang:master Mar 30, 2019
@compnerd compnerd deleted the simon-says branch March 30, 2019 04:16
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.

3 participants