Skip to content
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

[SR-7148] Compile-time conditionalization of endianness in the compiler should be done by target checking #49696

Open
jckarter opened this issue Mar 8, 2018 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers

Comments

@jckarter
Copy link
Contributor

jckarter commented Mar 8, 2018

Previous ID SR-7148
Radar None
Original Reporter @jckarter
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: 7f26b7e8c0700431c7bacc1871180f85

Issue Description:

IRGen appears to have grown compile-time conditionalizations on host properties, e.g.:

https://github.com/apple/swift/blob/master/lib/IRGen/GenEnum.cpp#L3892

This is not correct if cross-compiling for a target with different endianness than the compiler host. This should check the properties of the target instead of being a #if

@jckarter
Copy link
Contributor Author

jckarter commented Mar 8, 2018

Starter bug hints: Checking endianness can be done given an IRGenModule &IGM by checking IGM.getModule()->getDataLayout().isBigEndian() or .isLittleEndian(), and bit width by IGM.SizeTy == IGM.Int64Ty or IGM.SizeTy == IGM.Int32Ty.

@jckarter
Copy link
Contributor Author

s390x is a big-endian 64-bit target maintained by IBM's Swift team. You should be able to use it as a test target. You can write IRGen tests for cross-compilation by providing a //RUN: line in the test file that specifies a target triple in the command line:

// RUN: %target-swift-frontend -parse-stdlib -emit-ir -target s390x-ibm-linux %s | %FileCheck --check-prefix=BE
// RUN: %target-swift-frontend -parse-stdlib -emit-ir -target x86_64-pc-linux %s | %FileCheck --check-prefix=LE

// BE: this will be checked for in big endian builds
// LE: this will be checked for in little endian builds

Note that I also included -parse-stdlib so the compiler won't try to load the standard library for the target platform, which might not be built on all hosts. You should be able to write tests that don't use anything from Swift's standard library, though.

@swift-ci
Copy link
Contributor

Comment by Tapan Thaker (JIRA)

The places I found occurrences of _LITTLE_ENDIAN_ or _BIG_ENDIAN_ are the following:

  • lib/IRGen/EnumPayload.cpp

  • lib/IRGen/GenEnum.cpp

  • stdlib/public/runtime/Enum.cpp

  • stdlib/public/runtime/EnumImpl.h

  • stdlib/public/stubs/MathStubs.cpp

  • tools/swift-stdlib-tool/swift-stdlib-tool.mm

  • unittests/runtime/Enum.cpp

If I understand correctly, it should be okay to have these macros in the runtime & is a problem only in lib/IRGen

@jckarter
Copy link
Contributor Author

You're correct. The compiler shouldn't change behavior based on host characteristics, but the runtime is compiled for the target(s).

@belkadan
Copy link
Contributor

Resetting assignee on all Starter Bugs last modified in 2018.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants