Auto merge of #125016 - nicholasbishop:bishop-cb-112, r=tgross35
Update compiler_builtins to 0.1.114
The `weak-intrinsics` feature was removed from compiler_builtins in https://github.com/rust-lang/compiler-builtins/pull/598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.
In https://github.com/rust-lang/compiler-builtins/pull/593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
diff --git a/.github/workflows/abi-cafe.yml b/.github/workflows/abi-cafe.yml
index b7063f3..1ed6f8f 100644
--- a/.github/workflows/abi-cafe.yml
+++ b/.github/workflows/abi-cafe.yml
@@ -55,10 +55,6 @@
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
run: rustup set default-host x86_64-apple-darwin
- - name: Select XCode version
- if: matrix.os == 'macos-latest'
- run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
-
- name: Prepare dependencies
run: ./y.sh prepare
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 1f5a651..a2ae3d6 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -66,6 +66,9 @@
env:
TARGET_TRIPLE: aarch64-unknown-linux-gnu
apt_deps: gcc-aarch64-linux-gnu qemu-user
+ - os: macos-latest
+ env:
+ TARGET_TRIPLE: aarch64-apple-darwin
- os: ubuntu-latest
env:
TARGET_TRIPLE: s390x-unknown-linux-gnu
@@ -108,10 +111,6 @@
sudo apt-get update
sudo apt-get install -y ${{ matrix.apt_deps }}
- - name: Select XCode version
- if: matrix.os == 'macos-latest'
- run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
-
- name: Prepare dependencies
run: ./y.sh prepare
@@ -214,6 +213,9 @@
- os: macos-latest
env:
TARGET_TRIPLE: x86_64-apple-darwin
+ - os: macos-latest
+ env:
+ TARGET_TRIPLE: aarch64-apple-darwin
# cross-compile from Linux to Windows using mingw
- os: ubuntu-latest
env:
@@ -248,10 +250,6 @@
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64
- - name: Select XCode version
- if: matrix.os == 'macos-latest'
- run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
-
- name: Prepare dependencies
run: ./y.sh prepare
@@ -282,7 +280,8 @@
runs-on: ubuntu-latest
timeout-minutes: 10
if: ${{ github.ref == 'refs/heads/master' }}
- needs: [rustfmt, test, bench, dist]
+ # FIXME add the bench job back to the dependency list once rust-lang/rust#125493 gets merged
+ needs: [rustfmt, test, dist]
permissions:
contents: write # for creating the dev tag and release
diff --git a/Cargo.lock b/Cargo.lock
index 33fe52d..efec5db 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16,9 +16,9 @@
[[package]]
name = "anyhow"
-version = "1.0.82"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
+checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "arbitrary"
@@ -46,18 +46,18 @@
[[package]]
name = "cranelift-bforest"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "79b27922a6879b5b5361d0a084cb0b1941bf109a98540addcb932da13b68bed4"
+checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "304c455b28bf56372729acb356afbb55d622f2b0f2f7837aa5e57c138acaac4d"
+checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa"
dependencies = [
"bumpalo",
"cranelift-bforest",
@@ -67,48 +67,49 @@
"cranelift-entity",
"cranelift-isle",
"gimli",
- "hashbrown 0.14.3",
+ "hashbrown 0.14.5",
"log",
"regalloc2",
+ "rustc-hash",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-codegen-meta"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1653c56b99591d07f67c5ca7f9f25888948af3f4b97186bff838d687d666f613"
+checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f5b6a9cf6b6eb820ee3f973a0db313c05dc12d370f37b4fe9630286e1672573f"
+checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da"
[[package]]
name = "cranelift-control"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9d06e6bf30075fb6bed9e034ec046475093392eea1aff90eb5c44c4a033d19a"
+checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa"
dependencies = [
"arbitrary",
]
[[package]]
name = "cranelift-entity"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "29be04f931b73cdb9694874a295027471817f26f26d2f0ebe5454153176b6e3a"
+checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b"
[[package]]
name = "cranelift-frontend"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a07fd7393041d7faa2f37426f5dc7fc04003b70988810e8c063beefeff1cd8f9"
+checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5"
dependencies = [
"cranelift-codegen",
"log",
@@ -118,15 +119,15 @@
[[package]]
name = "cranelift-isle"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f341d7938caa6dff8149dac05bb2b53fc680323826b83b4cf175ab9f5139a3c9"
+checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e"
[[package]]
name = "cranelift-jit"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42733555e06433f1461570e09dbd756dafc228b4dac75c597cdbdc518de07522"
+checksum = "f5c5cfb8bbd3339cd25cca30e7516ff8fe5cb1feeddde6980cc4d5ef34df97bb"
dependencies = [
"anyhow",
"cranelift-codegen",
@@ -144,9 +145,9 @@
[[package]]
name = "cranelift-module"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "84950af02bb85f3da764d53a953b43bb29a732e793d4fe24637a61591be9a024"
+checksum = "7c9b0d4269b36fd858e6d8f20cd4938941186fb831488c361888cb2d6b33a9a6"
dependencies = [
"anyhow",
"cranelift-codegen",
@@ -155,9 +156,9 @@
[[package]]
name = "cranelift-native"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "82af6066e6448d26eeabb7aa26a43f7ff79f8217b06bade4ee6ef230aecc8880"
+checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581"
dependencies = [
"cranelift-codegen",
"libc",
@@ -166,9 +167,9 @@
[[package]]
name = "cranelift-object"
-version = "0.107.0"
+version = "0.109.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00af56107039ed150391df6f753298c7b08f2b6a2e0727d216b5fa599d684d8b"
+checksum = "19e33439ec20db058bc7cc3410f9748ab1ad90a35cef713d625c736f43e3820d"
dependencies = [
"anyhow",
"cranelift-codegen",
@@ -181,9 +182,9 @@
[[package]]
name = "crc32fast"
-version = "1.4.0"
+version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa"
+checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
@@ -202,9 +203,9 @@
[[package]]
name = "gimli"
-version = "0.28.0"
+version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
+checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
dependencies = [
"fallible-iterator",
"indexmap",
@@ -222,9 +223,9 @@
[[package]]
name = "hashbrown"
-version = "0.14.3"
+version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
+checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [
"ahash",
]
@@ -236,20 +237,20 @@
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
- "hashbrown 0.14.3",
+ "hashbrown 0.14.5",
]
[[package]]
name = "libc"
-version = "0.2.153"
+version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
+checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libloading"
-version = "0.8.3"
+version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
+checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
dependencies = [
"cfg-if",
"windows-targets",
@@ -257,9 +258,9 @@
[[package]]
name = "log"
-version = "0.4.21"
+version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
+checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "mach"
@@ -272,18 +273,18 @@
[[package]]
name = "memchr"
-version = "2.7.2"
+version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
+checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "object"
-version = "0.33.0"
+version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d8dd6c0cdf9429bce006e1362bfce61fa1bfd8c898a643ed8d2b471934701d3d"
+checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
dependencies = [
"crc32fast",
- "hashbrown 0.14.3",
+ "hashbrown 0.14.5",
"indexmap",
"memchr",
]
@@ -296,9 +297,9 @@
[[package]]
name = "proc-macro2"
-version = "1.0.81"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
@@ -381,9 +382,9 @@
[[package]]
name = "syn"
-version = "2.0.60"
+version = "2.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
+checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16"
dependencies = [
"proc-macro2",
"quote",
@@ -392,9 +393,9 @@
[[package]]
name = "target-lexicon"
-version = "0.12.14"
+version = "0.12.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
+checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2"
[[package]]
name = "unicode-ident"
@@ -410,10 +411,11 @@
[[package]]
name = "wasmtime-jit-icache-coherence"
-version = "20.0.0"
+version = "22.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a9f93a3289057b26dc75eb84d6e60d7694f7d169c7c09597495de6e016a13ff"
+checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91"
dependencies = [
+ "anyhow",
"cfg-if",
"libc",
"windows-sys",
@@ -452,9 +454,9 @@
[[package]]
name = "windows-targets"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
@@ -468,66 +470,66 @@
[[package]]
name = "windows_aarch64_gnullvm"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
-version = "0.52.5"
+version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "zerocopy"
-version = "0.7.32"
+version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
+checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
-version = "0.7.32"
+version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
+checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
diff --git a/Cargo.toml b/Cargo.toml
index 2015cdb..2969a6c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,15 +8,15 @@
[dependencies]
# These have to be in sync with each other
-cranelift-codegen = { version = "0.107.0", default-features = false, features = ["std", "unwind", "all-arch"] }
-cranelift-frontend = { version = "0.107.0" }
-cranelift-module = { version = "0.107.0" }
-cranelift-native = { version = "0.107.0" }
-cranelift-jit = { version = "0.107.0", optional = true }
-cranelift-object = { version = "0.107.0" }
+cranelift-codegen = { version = "0.109.0", default-features = false, features = ["std", "unwind", "all-arch"] }
+cranelift-frontend = { version = "0.109.0" }
+cranelift-module = { version = "0.109.0" }
+cranelift-native = { version = "0.109.0" }
+cranelift-jit = { version = "0.109.0", optional = true }
+cranelift-object = { version = "0.109.0" }
target-lexicon = "0.12.0"
gimli = { version = "0.28", default-features = false, features = ["write"]}
-object = { version = "0.33", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
+object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
indexmap = "2.0.0"
libloading = { version = "0.8.0", optional = true }
diff --git a/Readme.md b/Readme.md
index 00ea15c..3b3c86a 100644
--- a/Readme.md
+++ b/Readme.md
@@ -70,7 +70,7 @@
|FreeBSD|✅[^no-rustup]|❓|❓|❓|
|AIX|❌[^xcoff]|N/A|N/A|❌[^xcoff]|
|Other unixes|❓|❓|❓|❓|
-|macOS|✅|❌[^apple-silicon]|N/A|N/A|
+|macOS|✅|✅|N/A|N/A|
|Windows|✅[^no-rustup]|❌|N/A|N/A|
✅: Fully supported and tested
@@ -80,7 +80,6 @@
Not all targets are available as rustup component for nightly. See notes in the platform support matrix.
[^xcoff]: XCOFF object file format is not supported.
-[^apple-silicon]: Tracked in [#1248](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1248).
[^no-rustup]: Not available as rustup component for nightly. You can build it yourself.
## Usage
diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs
index ecf303c..75f9f23 100644
--- a/build_system/abi_cafe.rs
+++ b/build_system/abi_cafe.rs
@@ -1,8 +1,7 @@
-use crate::build_sysroot;
use crate::path::Dirs;
use crate::prepare::GitRepo;
use crate::utils::{spawn_and_wait, CargoProject, Compiler};
-use crate::{CodegenBackend, SysrootKind};
+use crate::{build_sysroot, CodegenBackend, SysrootKind};
static ABI_CAFE_REPO: GitRepo = GitRepo::github(
"Gankra",
diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs
index 557e90a..ed8b5b9 100644
--- a/build_system/build_sysroot.rs
+++ b/build_system/build_sysroot.rs
@@ -1,7 +1,6 @@
-use std::env;
-use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
+use std::{env, fs};
use crate::path::{Dirs, RelPath};
use crate::rustc_info::get_file_name;
@@ -267,10 +266,6 @@ fn build_clif_sysroot_for_triple(
prefix.to_str().unwrap()
));
}
- rustflags.push("-Zunstable-options".to_owned());
- for (name, values) in EXTRA_CHECK_CFGS {
- rustflags.push(check_cfg_arg(name, *values));
- }
compiler.rustflags.extend(rustflags);
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
if channel == "release" {
@@ -330,34 +325,3 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
Some(target_libs)
}
-
-// Copied from https://github.com/rust-lang/rust/blob/4fd98a4b1b100f5329c6efae18031791f64372d2/src/bootstrap/src/utils/helpers.rs#L569-L585
-/// Create a `--check-cfg` argument invocation for a given name
-/// and it's values.
-fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
- // Creating a string of the values by concatenating each value:
- // ',values("tvos","watchos")' or '' (nothing) when there are no values.
- let next = match values {
- Some(values) => {
- let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();
-
- tmp.insert_str(1, "values(");
- tmp.push(')');
- tmp
- }
- None => "".to_string(),
- };
- format!("--check-cfg=cfg({name}{next})")
-}
-
-const EXTRA_CHECK_CFGS: &[(&str, Option<&[&str]>)] = &[
- ("bootstrap", None),
- ("stdarch_intel_sde", None),
- ("no_fp_fmt_parse", None),
- ("no_global_oom_handling", None),
- ("no_rc", None),
- ("no_sync", None),
- ("netbsd10", None),
- ("backtrace_in_libstd", None),
- ("target_arch", Some(&["xtensa"])),
-];
diff --git a/build_system/config.rs b/build_system/config.rs
index c31784e..ef540cf 100644
--- a/build_system/config.rs
+++ b/build_system/config.rs
@@ -1,5 +1,4 @@
-use std::fs;
-use std::process;
+use std::{fs, process};
fn load_config_file() -> Vec<(String, Option<String>)> {
fs::read_to_string("config.txt")
diff --git a/build_system/main.rs b/build_system/main.rs
index 7dbf608..9ddeda5 100644
--- a/build_system/main.rs
+++ b/build_system/main.rs
@@ -2,9 +2,8 @@
#![warn(unused_lifetimes)]
#![warn(unreachable_pub)]
-use std::env;
use std::path::PathBuf;
-use std::process;
+use std::{env, process};
use self::utils::Compiler;
diff --git a/build_system/tests.rs b/build_system/tests.rs
index 278f334..afc8a92 100644
--- a/build_system/tests.rs
+++ b/build_system/tests.rs
@@ -3,14 +3,12 @@
use std::path::PathBuf;
use std::process::Command;
-use crate::build_sysroot;
-use crate::config;
use crate::path::{Dirs, RelPath};
use crate::prepare::{apply_patches, GitRepo};
use crate::rustc_info::get_default_sysroot;
use crate::shared_utils::rustflags_from_env;
use crate::utils::{spawn_and_wait, CargoProject, Compiler, LogGroup};
-use crate::{CodegenBackend, SysrootKind};
+use crate::{build_sysroot, config, CodegenBackend, SysrootKind};
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
@@ -329,7 +327,6 @@ pub(crate) fn run_tests(
struct TestRunner<'a> {
is_native: bool,
jit_supported: bool,
- use_unstable_features: bool,
skip_tests: &'a [&'a str],
dirs: Dirs,
target_compiler: Compiler,
@@ -361,15 +358,7 @@ fn new(
&& target_compiler.triple.contains("x86_64")
&& !target_compiler.triple.contains("windows");
- Self {
- is_native,
- jit_supported,
- use_unstable_features,
- skip_tests,
- dirs,
- target_compiler,
- stdlib_source,
- }
+ Self { is_native, jit_supported, skip_tests, dirs, target_compiler, stdlib_source }
}
fn run_testsuite(&self, tests: &[TestCase]) {
@@ -393,31 +382,13 @@ fn run_testsuite(&self, tests: &[TestCase]) {
match *cmd {
TestCaseCmd::Custom { func } => func(self),
TestCaseCmd::BuildLib { source, crate_types } => {
- if self.use_unstable_features {
- self.run_rustc([source, "--crate-type", crate_types]);
- } else {
- self.run_rustc([
- source,
- "--crate-type",
- crate_types,
- "--cfg",
- "no_unstable_features",
- ]);
- }
+ self.run_rustc([source, "--crate-type", crate_types]);
}
TestCaseCmd::BuildBin { source } => {
- if self.use_unstable_features {
- self.run_rustc([source]);
- } else {
- self.run_rustc([source, "--cfg", "no_unstable_features"]);
- }
+ self.run_rustc([source]);
}
TestCaseCmd::BuildBinAndRun { source, args } => {
- if self.use_unstable_features {
- self.run_rustc([source]);
- } else {
- self.run_rustc([source, "--cfg", "no_unstable_features"]);
- }
+ self.run_rustc([source]);
self.run_out_command(
source.split('/').last().unwrap().split('.').next().unwrap(),
args,
@@ -472,7 +443,6 @@ fn rustc_command<I, S>(&self, args: I) -> Command
cmd.arg(&self.target_compiler.triple);
cmd.arg("-Cpanic=abort");
cmd.arg("-Zunstable-options");
- cmd.arg("--check-cfg=cfg(no_unstable_features)");
cmd.arg("--check-cfg=cfg(jit)");
cmd.args(args);
cmd
diff --git a/build_system/utils.rs b/build_system/utils.rs
index 9f95122..3c4b45e 100644
--- a/build_system/utils.rs
+++ b/build_system/utils.rs
@@ -1,9 +1,7 @@
-use std::env;
-use std::fs;
-use std::io;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::sync::atomic::{AtomicBool, Ordering};
+use std::{env, fs, io};
use crate::path::{Dirs, RelPath};
use crate::shared_utils::rustflags_to_cmd_env;
diff --git a/example/alloc_system.rs b/example/alloc_system.rs
index 441f3cd..2884c9c 100644
--- a/example/alloc_system.rs
+++ b/example/alloc_system.rs
@@ -8,8 +8,7 @@
#[cfg(any(windows, unix, target_os = "redox"))]
mod realloc_fallback {
use core::alloc::{GlobalAlloc, Layout};
- use core::cmp;
- use core::ptr;
+ use core::{cmp, ptr};
impl super::System {
pub(crate) unsafe fn realloc_fallback(
&self,
@@ -34,6 +33,7 @@ mod platform {
use core::alloc::{GlobalAlloc, Layout};
use core::ffi::c_void;
use core::ptr;
+
use System;
extern "C" {
fn posix_memalign(memptr: *mut *mut c_void, align: usize, size: usize) -> i32;
@@ -71,6 +71,7 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
#[allow(nonstandard_style)]
mod platform {
use core::alloc::{GlobalAlloc, Layout};
+
use System;
type LPVOID = *mut u8;
type HANDLE = LPVOID;
diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs
index f7edfa9..5479b0c 100644
--- a/example/arbitrary_self_types_pointers_and_wrappers.rs
+++ b/example/arbitrary_self_types_pointers_and_wrappers.rs
@@ -2,10 +2,8 @@
#![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)]
-use std::{
- marker::Unsize,
- ops::{CoerceUnsized, Deref, DispatchFromDyn},
-};
+use std::marker::Unsize;
+use std::ops::{CoerceUnsized, Deref, DispatchFromDyn};
struct Ptr<T: ?Sized>(Box<T>);
diff --git a/example/issue-72793.rs b/example/issue-72793.rs
index 166b006..2e08fbc 100644
--- a/example/issue-72793.rs
+++ b/example/issue-72793.rs
@@ -2,20 +2,23 @@
#![feature(type_alias_impl_trait)]
-trait T {
- type Item;
-}
+mod helper {
+ pub trait T {
+ type Item;
+ }
-type Alias<'a> = impl T<Item = &'a ()>;
+ pub type Alias<'a> = impl T<Item = &'a ()>;
-struct S;
-impl<'a> T for &'a S {
- type Item = &'a ();
-}
+ struct S;
+ impl<'a> T for &'a S {
+ type Item = &'a ();
+ }
-fn filter_positive<'a>() -> Alias<'a> {
- &S
+ pub fn filter_positive<'a>() -> Alias<'a> {
+ &S
+ }
}
+use helper::*;
fn with_positive(fun: impl Fn(Alias<'_>)) {
fun(filter_positive());
diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs
index aab20f6..7d361a9 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -333,12 +333,7 @@ struct ExternTypeWrapper {
#[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))]
test_tls();
- #[cfg(all(
- not(jit),
- not(no_unstable_features),
- target_arch = "x86_64",
- any(target_os = "linux", target_os = "macos")
- ))]
+ #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))]
unsafe {
global_asm_test();
naked_test();
@@ -367,17 +362,12 @@ fn stack_val_align() {
assert_eq!(&a as *const Foo as usize % 8192, 0);
}
-#[cfg(all(
- not(jit),
- not(no_unstable_features),
- target_arch = "x86_64",
- any(target_os = "linux", target_os = "macos")
-))]
+#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))]
extern "C" {
fn global_asm_test();
}
-#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "linux"))]
+#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
global_asm! {
"
.global global_asm_test
@@ -387,7 +377,7 @@ fn stack_val_align() {
"
}
-#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "macos"))]
+#[cfg(all(not(jit), target_arch = "x86_64", target_os = "macos"))]
global_asm! {
"
.global _global_asm_test
@@ -397,7 +387,7 @@ fn stack_val_align() {
"
}
-#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64"))]
+#[cfg(all(not(jit), target_arch = "x86_64"))]
#[naked]
extern "C" fn naked_test() {
unsafe {
diff --git a/example/std_example.rs b/example/std_example.rs
index 7347b2e..e99763e 100644
--- a/example/std_example.rs
+++ b/example/std_example.rs
@@ -3,7 +3,6 @@
coroutines,
stmt_expr_attributes,
coroutine_trait,
- is_sorted,
repr_simd,
tuple_trait,
unboxed_closures
@@ -251,6 +250,9 @@ unsafe fn test_simd() {
test_mm_add_epi8();
test_mm_add_pd();
test_mm_cvtepi8_epi16();
+ #[cfg(not(jit))]
+ test_mm_cvtps_epi32();
+ test_mm_cvttps_epi32();
test_mm_cvtsi128_si64();
test_mm_extract_epi8();
@@ -476,6 +478,41 @@ unsafe fn test_mm256_permutevar8x32_epi32() {
assert_eq_m256i(r, e);
}
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "avx2")]
+#[cfg(not(jit))]
+unsafe fn test_mm_cvtps_epi32() {
+ let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN];
+
+ let float_vec = _mm_loadu_ps(floats.as_ptr());
+ let int_vec = _mm_cvtps_epi32(float_vec);
+
+ let mut ints: [i32; 4] = [0; 4];
+ _mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec);
+
+ // this is very different from `floats.map(|f| f as i32)`!
+ let expected_ints: [i32; 4] = [2, -2, i32::MIN, i32::MIN];
+
+ assert_eq!(ints, expected_ints);
+}
+
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "avx2")]
+unsafe fn test_mm_cvttps_epi32() {
+ let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN];
+
+ let float_vec = _mm_loadu_ps(floats.as_ptr());
+ let int_vec = _mm_cvttps_epi32(float_vec);
+
+ let mut ints: [i32; 4] = [0; 4];
+ _mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec);
+
+ // this is very different from `floats.map(|f| f as i32)`!
+ let expected_ints: [i32; 4] = [1, -2, i32::MIN, i32::MIN];
+
+ assert_eq!(ints, expected_ints);
+}
+
fn test_checked_mul() {
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
assert_eq!(u, None);
diff --git a/patches/0029-stdlib-rawdylib-processprng.patch b/patches/0029-stdlib-rawdylib-processprng.patch
index 6af11e5..584dbdb 100644
--- a/patches/0029-stdlib-rawdylib-processprng.patch
+++ b/patches/0029-stdlib-rawdylib-processprng.patch
@@ -12,7 +12,7 @@
index ad8e01bfa9b..9ca8e4c16ce 100644
--- a/library/std/src/sys/pal/windows/c.rs
+++ b/library/std/src/sys/pal/windows/c.rs
-@@ -323,7 +323,7 @@ pub unsafe fn NtWriteFile(
+@@ -312,7 +312,7 @@ pub unsafe fn NtWriteFile(
// Use raw-dylib to import ProcessPrng as we can't rely on there being an import library.
cfg_if::cfg_if! {
@@ -26,8 +26,8 @@
--- a/library/std/src/sys/pal/windows/rand.rs
+++ b/library/std/src/sys/pal/windows/rand.rs
@@ -2,7 +2,7 @@
- use core::mem;
- use core::ptr;
+
+ use crate::sys::c;
-#[cfg(not(target_vendor = "win7"))]
+#[cfg(any())]
diff --git a/patches/stdlib-lock.toml b/patches/stdlib-lock.toml
index c8c7b45..9ea53e8 100644
--- a/patches/stdlib-lock.toml
+++ b/patches/stdlib-lock.toml
@@ -4,12 +4,12 @@
[[package]]
name = "addr2line"
-version = "0.21.0"
+version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
+checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
dependencies = [
"compiler_builtins",
- "gimli",
+ "gimli 0.29.0",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
]
@@ -134,6 +134,17 @@
]
[[package]]
+name = "gimli"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
+dependencies = [
+ "compiler_builtins",
+ "rustc-std-workspace-alloc",
+ "rustc-std-workspace-core",
+]
+
+[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -147,9 +158,9 @@
[[package]]
name = "hermit-abi"
-version = "0.3.9"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
+checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-alloc",
@@ -189,9 +200,9 @@
[[package]]
name = "object"
-version = "0.32.1"
+version = "0.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
+checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434"
dependencies = [
"compiler_builtins",
"memchr",
@@ -286,9 +297,9 @@
[[package]]
name = "rustc-demangle"
-version = "0.1.23"
+version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
+checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
@@ -396,8 +407,6 @@
"core",
"getopts",
"libc",
- "panic_abort",
- "panic_unwind",
"std",
]
@@ -430,7 +439,7 @@
checksum = "37a19a21a537f635c16c7576f22d0f2f7d63353c1337ad4ce0d8001c7952a25b"
dependencies = [
"compiler_builtins",
- "gimli",
+ "gimli 0.28.1",
"rustc-std-workspace-core",
]
diff --git a/rust-toolchain b/rust-toolchain
index a2ba79c..db9b551 100644
--- a/rust-toolchain
+++ b/rust-toolchain
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2024-05-13"
+channel = "nightly-2024-07-13"
components = ["rust-src", "rustc-dev", "llvm-tools"]
diff --git a/rustfmt.toml b/rustfmt.toml
index 6f4d441..d9e6ac3 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -6,3 +6,5 @@
version = "Two"
use_small_heuristics = "Max"
merge_derives = false
+group_imports = "StdExternalCrate"
+imports_granularity = "Module"
diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh
index 689cda2..f0550c2 100755
--- a/scripts/test_rustc_tests.sh
+++ b/scripts/test_rustc_tests.sh
@@ -34,11 +34,11 @@
# vendor intrinsics
rm tests/ui/asm/x86_64/evex512-implicit-feature.rs # unimplemented AVX512 x86 vendor intrinsic
+rm tests/ui/simd/dont-invalid-bitcast-x86_64.rs # unimplemented llvm.x86.sse41.round.ps
# exotic linkages
-rm tests/ui/issues/issue-33992.rs # unsupported linkages
-rm tests/incremental/hashes/function_interfaces.rs # same
-rm tests/incremental/hashes/statics.rs # same
+rm tests/incremental/hashes/function_interfaces.rs
+rm tests/incremental/hashes/statics.rs
# variadic arguments
rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs
@@ -57,16 +57,23 @@
rm -r tests/run-make/mismatching-target-triples # same
rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't work entirely correctly
rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported
+rm tests/ui/simd/simd-bitmask-notpow2.rs # non-pow-of-2 simd vector sizes
# requires LTO
rm -r tests/run-make/cdylib
-rm -r tests/run-make/issue-14500
-rm -r tests/run-make/issue-64153
rm -r tests/run-make/codegen-options-parsing
rm -r tests/run-make/lto-*
rm -r tests/run-make/reproducible-build-2
-rm -r tests/run-make/issue-109934-lto-debuginfo
rm -r tests/run-make/no-builtins-lto
+rm -r tests/run-make/reachable-extern-fn-available-lto
+
+# coverage instrumentation
+rm tests/ui/consts/precise-drop-with-coverage.rs
+rm tests/ui/issues/issue-85461.rs
+rm -r tests/ui/instrument-coverage/
+
+# missing f16/f128 support
+rm tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs
# optimization tests
# ==================
@@ -74,6 +81,7 @@
rm tests/ui/codegen/init-large-type.rs # same
rm tests/ui/issues/issue-40883.rs # same
rm -r tests/run-make/fmt-write-bloat/ # tests an optimization
+rm tests/ui/statics/const_generics.rs # same
# backend specific tests
# ======================
@@ -85,6 +93,7 @@
rm -r tests/run-make/volatile-intrinsics # same
rm -r tests/run-make/llvm-ident # same
rm -r tests/run-make/no-builtins-attribute # same
+rm -r tests/run-make/pgo-gen-no-imp-symbols # same
rm tests/ui/abi/stack-protector.rs # requires stack protector support
rm -r tests/run-make/emit-stack-sizes # requires support for -Z emit-stack-sizes
rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific
@@ -93,13 +102,15 @@
# requires asm, llvm-ir and/or llvm-bc emit support
# =============================================
rm -r tests/run-make/emit-named-files
-rm -r tests/run-make/issue-30063
rm -r tests/run-make/multiple-emits
rm -r tests/run-make/output-type-permutations
rm -r tests/run-make/emit-to-stdout
rm -r tests/run-make/compressed-debuginfo
rm -r tests/run-make/symbols-include-type-name
-
+rm -r tests/run-make/notify-all-emit-artifacts
+rm -r tests/run-make/reset-codegen-1
+rm -r tests/run-make/inline-always-many-cgu
+rm -r tests/run-make/intrinsic-unreachable
# giving different but possibly correct results
# =============================================
@@ -118,6 +129,7 @@
# ============
rm -r tests/run-make/extern-fn-explicit-align # argument alignment not yet supported
rm -r tests/run-make/panic-abort-eh_frame # .eh_frame emitted with panic=abort
+rm tests/ui/deprecation/deprecated_inline_threshold.rs # missing deprecation warning for -Cinline-threshold
# bugs in the test suite
# ======================
@@ -148,12 +160,12 @@
--- a/src/tools/run-make-support/src/rustdoc.rs
+++ b/src/tools/run-make-support/src/rustdoc.rs
@@ -34,8 +34,6 @@ pub fn bare() -> Self {
- /// Construct a \`rustdoc\` invocation with \`-L \$(TARGET_RPATH_DIR)\` set.
+ #[track_caller]
pub fn new() -> Self {
let mut cmd = setup_common();
-- let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
+- let target_rpath_dir = env_var_os("TARGET_RPATH_DIR");
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
- Self { cmd, stdin: None }
+ Self { cmd }
}
EOF
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index 4bcef15..24cf3f0 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -5,19 +5,20 @@
mod returning;
use std::borrow::Cow;
+use std::mem;
-use cranelift_codegen::ir::SigRef;
+use cranelift_codegen::ir::{ArgumentPurpose, SigRef};
use cranelift_codegen::isa::CallConv;
use cranelift_module::ModuleError;
+use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::TypeVisitableExt;
-use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_session::Session;
use rustc_span::source_map::Spanned;
-use rustc_target::abi::call::{Conv, FnAbi};
+use rustc_target::abi::call::{Conv, FnAbi, PassMode};
use rustc_target::spec::abi::Abi;
use self::pass_mode::*;
@@ -370,9 +371,14 @@ pub(crate) fn codegen_terminator_call<'tcx>(
// Handle special calls like intrinsics and empty drop glue.
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
- let instance =
- ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, fn_args)
- .polymorphize(fx.tcx);
+ let instance = ty::Instance::expect_resolve(
+ fx.tcx,
+ ty::ParamEnv::reveal_all(),
+ def_id,
+ fn_args,
+ source_info.span,
+ )
+ .polymorphize(fx.tcx);
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
if target.is_some() {
@@ -389,7 +395,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
crate::intrinsics::codegen_llvm_intrinsic_call(
fx,
&fx.tcx.symbol_name(instance).name,
- fn_args,
args,
ret_place,
target,
@@ -399,7 +404,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
}
match instance.def {
- InstanceDef::Intrinsic(_) => {
+ InstanceKind::Intrinsic(_) => {
match crate::intrinsics::codegen_intrinsic_call(
fx,
instance,
@@ -412,7 +417,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
Err(instance) => Some(instance),
}
}
- InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) => {
+ InstanceKind::DropGlue(_, None) | ty::InstanceKind::AsyncDropGlueCtorShim(_, None) => {
// empty drop glue - a nop.
let dest = target.expect("Non terminating drop_in_place_real???");
let ret_block = fx.get_block(dest);
@@ -487,6 +492,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
let args = args;
assert_eq!(fn_abi.args.len(), args.len());
+ #[derive(Copy, Clone)]
enum CallTarget {
Direct(FuncRef),
Indirect(SigRef, Value),
@@ -494,12 +500,12 @@ enum CallTarget {
let (func_ref, first_arg_override) = match instance {
// Trait object call
- Some(Instance { def: InstanceDef::Virtual(_, idx), .. }) => {
+ Some(Instance { def: InstanceKind::Virtual(_, idx), .. }) => {
if fx.clif_comments.enabled() {
let nop_inst = fx.bcx.ins().nop();
fx.add_comment(
nop_inst,
- format!("virtual call; self arg pass mode: {:?}", &fn_abi.args[0]),
+ format!("virtual call; self arg pass mode: {:?}", fn_abi.args[0]),
);
}
@@ -532,7 +538,7 @@ enum CallTarget {
};
self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| {
- let call_args = return_ptr
+ let mut call_args = return_ptr
.into_iter()
.chain(first_arg_override.into_iter())
.chain(
@@ -545,40 +551,17 @@ enum CallTarget {
)
.collect::<Vec<Value>>();
- let call_inst = match func_ref {
+ // FIXME: Find a cleaner way to support varargs.
+ if fn_abi.c_variadic {
+ adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args);
+ }
+
+ match func_ref {
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
CallTarget::Indirect(sig, func_ptr) => {
fx.bcx.ins().call_indirect(sig, func_ptr, &call_args)
}
- };
-
- // FIXME find a cleaner way to support varargs
- if fn_sig.c_variadic() {
- if !matches!(fn_sig.abi(), Abi::C { .. }) {
- fx.tcx.dcx().span_fatal(
- source_info.span,
- format!("Variadic call for non-C abi {:?}", fn_sig.abi()),
- );
- }
- let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
- let abi_params = call_args
- .into_iter()
- .map(|arg| {
- let ty = fx.bcx.func.dfg.value_type(arg);
- if !ty.is_int() {
- // FIXME set %al to upperbound on float args once floats are supported
- fx.tcx.dcx().span_fatal(
- source_info.span,
- format!("Non int ty {:?} for variadic call", ty),
- );
- }
- AbiParam::new(ty)
- })
- .collect::<Vec<AbiParam>>();
- fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
}
-
- call_inst
});
if let Some(dest) = target {
@@ -587,17 +570,112 @@ enum CallTarget {
} else {
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
+
+ fn adjust_call_for_c_variadic<'tcx>(
+ fx: &mut FunctionCx<'_, '_, 'tcx>,
+ fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
+ source_info: mir::SourceInfo,
+ target: CallTarget,
+ call_args: &mut Vec<Value>,
+ ) {
+ if fn_abi.conv != Conv::C {
+ fx.tcx.dcx().span_fatal(
+ source_info.span,
+ format!("Variadic call for non-C abi {:?}", fn_abi.conv),
+ );
+ }
+ let sig_ref = match target {
+ CallTarget::Direct(func_ref) => fx.bcx.func.dfg.ext_funcs[func_ref].signature,
+ CallTarget::Indirect(sig_ref, _) => sig_ref,
+ };
+ // `mem::take()` the `params` so that `fx.bcx` can be used below.
+ let mut abi_params = mem::take(&mut fx.bcx.func.dfg.signatures[sig_ref].params);
+
+ // Recalculate the parameters in the signature to ensure the signature contains the variadic arguments.
+ let has_return_arg = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
+ // Drop everything except the return argument (if there is one).
+ abi_params.truncate(if has_return_arg { 1 } else { 0 });
+ // Add the fixed arguments.
+ abi_params.extend(
+ fn_abi.args[..fn_abi.fixed_count as usize]
+ .iter()
+ .flat_map(|arg_abi| arg_abi.get_abi_param(fx.tcx).into_iter()),
+ );
+ let fixed_arg_count = abi_params.len();
+ // Add the variadic arguments.
+ abi_params.extend(
+ fn_abi.args[fn_abi.fixed_count as usize..]
+ .iter()
+ .flat_map(|arg_abi| arg_abi.get_abi_param(fx.tcx).into_iter()),
+ );
+
+ if fx.tcx.sess.target.is_like_osx && fx.tcx.sess.target.arch == "aarch64" {
+ // Add any padding arguments needed for Apple AArch64.
+ // There's no need to pad the argument list unless variadic arguments are actually being
+ // passed.
+ if abi_params.len() > fixed_arg_count {
+ // 128-bit integers take 2 registers, and everything else takes 1.
+ // FIXME: Add support for non-integer types
+ // This relies on the checks below to ensure all arguments are integer types and
+ // that the ABI is "C".
+ // The return argument isn't counted as it goes in its own dedicated register.
+ let integer_registers_used: usize = abi_params
+ [if has_return_arg { 1 } else { 0 }..fixed_arg_count]
+ .iter()
+ .map(|arg| if arg.value_type.bits() == 128 { 2 } else { 1 })
+ .sum();
+ // The ABI uses 8 registers before it starts pushing arguments to the stack. Pad out
+ // the registers if needed to ensure the variadic arguments are passed on the stack.
+ if integer_registers_used < 8 {
+ abi_params.splice(
+ fixed_arg_count..fixed_arg_count,
+ (integer_registers_used..8).map(|_| AbiParam::new(types::I64)),
+ );
+ call_args.splice(
+ fixed_arg_count..fixed_arg_count,
+ (integer_registers_used..8).map(|_| fx.bcx.ins().iconst(types::I64, 0)),
+ );
+ }
+ }
+
+ // `StructArgument` is not currently used by the `aarch64` ABI, and is therefore not
+ // handled when calculating how many padding arguments to use. Assert that this remains
+ // the case.
+ assert!(abi_params.iter().all(|param| matches!(
+ param.purpose,
+ // The only purposes used are `Normal` and `StructReturn`.
+ ArgumentPurpose::Normal | ArgumentPurpose::StructReturn
+ )));
+ }
+
+ // Check all parameters are integers.
+ for param in abi_params.iter() {
+ if !param.value_type.is_int() {
+ // FIXME: Set %al to upperbound on float args once floats are supported.
+ fx.tcx.dcx().span_fatal(
+ source_info.span,
+ format!("Non int ty {:?} for variadic call", param.value_type),
+ );
+ }
+ }
+
+ assert_eq!(abi_params.len(), call_args.len());
+
+ // Put the `AbiParam`s back in the signature.
+ fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
+ }
}
pub(crate) fn codegen_drop<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
source_info: mir::SourceInfo,
drop_place: CPlace<'tcx>,
+ target: BasicBlock,
) {
let ty = drop_place.layout().ty;
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
- if let ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) =
+ if let ty::InstanceKind::DropGlue(_, None) | ty::InstanceKind::AsyncDropGlueCtorShim(_, None) =
drop_instance.def
{
// we don't actually need to drop anything
@@ -620,10 +698,16 @@ pub(crate) fn codegen_drop<'tcx>(
let ptr = ptr.get_addr(fx);
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
+ let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
+ let target_block = fx.get_block(target);
+ let continued = fx.bcx.create_block();
+ fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
+ fx.bcx.switch_to_block(continued);
+
// FIXME(eddyb) perhaps move some of this logic into
// `Instance::resolve_drop_in_place`?
let virtual_drop = Instance {
- def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
+ def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
args: drop_instance.args,
};
let fn_abi =
@@ -659,8 +743,14 @@ pub(crate) fn codegen_drop<'tcx>(
let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx);
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
+ let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
+ let target_block = fx.get_block(target);
+ let continued = fx.bcx.create_block();
+ fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
+ fx.bcx.switch_to_block(continued);
+
let virtual_drop = Instance {
- def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
+ def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
args: drop_instance.args,
};
let fn_abi =
@@ -671,7 +761,7 @@ pub(crate) fn codegen_drop<'tcx>(
fx.bcx.ins().call_indirect(sig, drop_fn, &[data]);
}
_ => {
- assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _)));
+ assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));
let fn_abi =
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty());
@@ -697,4 +787,7 @@ pub(crate) fn codegen_drop<'tcx>(
}
}
}
+
+ let target_block = fx.get_block(target);
+ fx.bcx.ins().jump(target_block, &[]);
}
diff --git a/src/allocator.rs b/src/allocator.rs
index e8af3e8..b4a3825 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -11,15 +11,10 @@
use crate::prelude::*;
/// Returns whether an allocator shim was created
-pub(crate) fn codegen(
- tcx: TyCtxt<'_>,
- module: &mut impl Module,
- unwind_context: &mut UnwindContext,
-) -> bool {
+pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool {
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
codegen_inner(
module,
- unwind_context,
kind,
tcx.alloc_error_handler_kind(()).unwrap(),
tcx.sess.opts.unstable_opts.oom,
@@ -28,8 +23,7 @@ pub(crate) fn codegen(
}
fn codegen_inner(
- module: &mut impl Module,
- unwind_context: &mut UnwindContext,
+ module: &mut dyn Module,
kind: AllocatorKind,
alloc_error_handler_kind: AllocatorKind,
oom_strategy: OomStrategy,
@@ -67,7 +61,6 @@ fn codegen_inner(
};
crate::common::create_wrapper_function(
module,
- unwind_context,
sig,
&global_fn_name(method.name),
&default_fn_name(method.name),
@@ -82,7 +75,6 @@ fn codegen_inner(
};
crate::common::create_wrapper_function(
module,
- unwind_context,
sig,
"__rust_alloc_error_handler",
&alloc_error_handler_name(alloc_error_handler_kind),
diff --git a/src/archive.rs b/src/archive.rs
index 414d3db..1935005 100644
--- a/src/archive.rs
+++ b/src/archive.rs
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use rustc_codegen_ssa::back::archive::{
- get_native_object_symbols, ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder,
+ ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
};
use rustc_session::Session;
@@ -9,17 +9,17 @@
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
- Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols))
+ Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
}
fn create_dll_import_lib(
&self,
- _sess: &Session,
+ sess: &Session,
_lib_name: &str,
_dll_imports: &[rustc_session::cstore::DllImport],
_tmpdir: &Path,
_is_direct_dependency: bool,
) -> PathBuf {
- unimplemented!("creating dll imports is not yet supported");
+ sess.dcx().fatal("raw-dylib is not yet supported by rustc_codegen_cranelift");
}
}
diff --git a/src/base.rs b/src/base.rs
index 8d778f7..9bc7b57 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -5,13 +5,13 @@
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_module::ModuleError;
use rustc_ast::InlineAsmOptions;
+use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::TypeVisitableExt;
-use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
use crate::constant::ConstantCx;
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
@@ -249,9 +249,7 @@ pub(crate) fn compile_fn(
}
// Define debuginfo for function
- let isa = module.isa();
let debug_context = &mut cx.debug_context;
- let unwind_context = &mut cx.unwind_context;
cx.profiler.generic_activity("generate debug info").run(|| {
if let Some(debug_context) = debug_context {
codegened_func.func_debug_cx.unwrap().finalize(
@@ -260,7 +258,6 @@ pub(crate) fn compile_fn(
context,
);
}
- unwind_context.add_function(codegened_func.func_id, &context, isa);
});
}
@@ -494,6 +491,11 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
)
});
}
+ // FIXME(explicit_tail_calls): add support for tail calls to the cranelift backend, once cranelift supports tail calls
+ TerminatorKind::TailCall { fn_span, .. } => span_bug!(
+ *fn_span,
+ "tail calls are not yet supported in `rustc_codegen_cranelift` backend"
+ ),
TerminatorKind::InlineAsm {
template,
operands,
@@ -548,10 +550,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
}
TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
let drop_place = codegen_place(fx, *place);
- crate::abi::codegen_drop(fx, source_info, drop_place);
-
- let target_block = fx.get_block(*target);
- fx.bcx.ins().jump(target_block, &[]);
+ crate::abi::codegen_drop(fx, source_info, drop_place, *target);
}
};
}
@@ -619,22 +618,34 @@ fn codegen_stmt<'tcx>(
Rvalue::UnaryOp(un_op, ref operand) => {
let operand = codegen_operand(fx, operand);
let layout = operand.layout();
- let val = operand.load_scalar(fx);
let res = match un_op {
- UnOp::Not => match layout.ty.kind() {
- ty::Bool => {
- let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
- CValue::by_val(res, layout)
+ UnOp::Not => {
+ let val = operand.load_scalar(fx);
+ match layout.ty.kind() {
+ ty::Bool => {
+ let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
+ CValue::by_val(res, layout)
+ }
+ ty::Uint(_) | ty::Int(_) => {
+ CValue::by_val(fx.bcx.ins().bnot(val), layout)
+ }
+ _ => unreachable!("un op Not for {:?}", layout.ty),
}
- ty::Uint(_) | ty::Int(_) => {
- CValue::by_val(fx.bcx.ins().bnot(val), layout)
+ }
+ UnOp::Neg => {
+ let val = operand.load_scalar(fx);
+ match layout.ty.kind() {
+ ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
+ ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
+ _ => unreachable!("un op Neg for {:?}", layout.ty),
}
- _ => unreachable!("un op Not for {:?}", layout.ty),
- },
- UnOp::Neg => match layout.ty.kind() {
- ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
- ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
- _ => unreachable!("un op Neg for {:?}", layout.ty),
+ }
+ UnOp::PtrMetadata => match layout.abi {
+ Abi::Scalar(_) => CValue::zst(dest_layout),
+ Abi::ScalarPair(_, _) => {
+ CValue::by_val(operand.load_scalar_pair(fx).1, dest_layout)
+ }
+ _ => bug!("Unexpected `PtrToMetadata` operand: {operand:?}"),
},
};
lval.write_cvalue(fx, res);
@@ -668,22 +679,23 @@ fn codegen_stmt<'tcx>(
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer),
ref operand,
to_ty,
- )
- | Rvalue::Cast(
- CastKind::PointerCoercion(PointerCoercion::MutToConstPointer),
- ref operand,
- to_ty,
- )
- | Rvalue::Cast(
- CastKind::PointerCoercion(PointerCoercion::ArrayToPointer),
- ref operand,
- to_ty,
) => {
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
let operand = codegen_operand(fx, operand);
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
}
Rvalue::Cast(
+ CastKind::PointerCoercion(
+ PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
+ ),
+ ..,
+ ) => {
+ bug!(
+ "{:?} is for borrowck, and should never appear in codegen",
+ to_place_and_rval.1
+ );
+ }
+ Rvalue::Cast(
CastKind::IntToInt
| CastKind::FloatToFloat
| CastKind::FloatToInt
@@ -823,9 +835,10 @@ fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
let val = match null_op {
NullOp::SizeOf => layout.size.bytes(),
NullOp::AlignOf => layout.align.abi.bytes(),
- NullOp::OffsetOf(fields) => {
- layout.offset_of_subfield(fx, fields.iter()).bytes()
- }
+ NullOp::OffsetOf(fields) => fx
+ .tcx
+ .offset_of_subfield(ParamEnv::reveal_all(), layout, fields.iter())
+ .bytes(),
NullOp::UbChecks => {
let val = fx.tcx.sess.ub_checks();
let val = CValue::by_val(
@@ -898,7 +911,7 @@ fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
| StatementKind::PlaceMention(..)
| StatementKind::AscribeUserType(..) => {}
- StatementKind::Coverage { .. } => fx.tcx.dcx().fatal("-Zcoverage is unimplemented"),
+ StatementKind::Coverage { .. } => unreachable!(),
StatementKind::Intrinsic(ref intrinsic) => match &**intrinsic {
// We ignore `assume` intrinsics, they are only useful for optimizations
NonDivergingIntrinsic::Assume(_) => {}
diff --git a/src/common.rs b/src/common.rs
index 21d0cd2..0931713 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -247,7 +247,6 @@ pub(crate) fn type_sign(ty: Ty<'_>) -> bool {
pub(crate) fn create_wrapper_function(
module: &mut dyn Module,
- unwind_context: &mut UnwindContext,
sig: Signature,
wrapper_name: &str,
callee_name: &str,
@@ -280,7 +279,6 @@ pub(crate) fn create_wrapper_function(
bcx.finalize();
}
module.define_function(wrapper_func_id, &mut ctx).unwrap();
- unwind_context.add_function(wrapper_func_id, &ctx, module.isa());
}
pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
@@ -395,6 +393,7 @@ pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
// a way to specify stack slot alignment.
size: (size + abi_align - 1) / abi_align * abi_align,
+ align_shift: 4,
});
Pointer::stack_slot(stack_slot)
} else {
@@ -405,6 +404,7 @@ pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
// a way to specify stack slot alignment.
size: (size + align) / abi_align * abi_align,
+ align_shift: 4,
});
let base_ptr = self.bcx.ins().stack_addr(self.pointer_type, stack_slot, 0);
let misalign_offset = self.bcx.ins().urem_imm(base_ptr, i64::from(align));
diff --git a/src/concurrency_limiter.rs b/src/concurrency_limiter.rs
index a73860c..2093b49 100644
--- a/src/concurrency_limiter.rs
+++ b/src/concurrency_limiter.rs
@@ -1,6 +1,7 @@
use std::sync::{Arc, Condvar, Mutex};
use jobserver::HelperThread;
+use rustc_errors::DiagCtxtHandle;
use rustc_session::Session;
// FIXME don't panic when a worker thread panics
@@ -46,7 +47,7 @@ pub(super) fn new(sess: &Session, pending_jobs: usize) -> Self {
}
}
- pub(super) fn acquire(&self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
+ pub(super) fn acquire(&self, dcx: DiagCtxtHandle<'_>) -> ConcurrencyLimiterToken {
let mut state = self.state.lock().unwrap();
loop {
state.assert_invariants();
diff --git a/src/constant.rs b/src/constant.rs
index 64e83e4..0ba163f 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -50,7 +50,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
) -> CValue<'tcx> {
let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) {
let instance = ty::Instance {
- def: ty::InstanceDef::ThreadLocalShim(def_id),
+ def: ty::InstanceKind::ThreadLocalShim(def_id),
args: ty::GenericArgs::empty(),
};
let func_ref = fx.get_function_ref(instance);
@@ -100,7 +100,7 @@ pub(crate) fn codegen_const_value<'tcx>(
assert!(layout.is_sized(), "unsized const value");
if layout.is_zst() {
- return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout);
+ return CValue::zst(layout);
}
match const_val {
@@ -110,7 +110,7 @@ pub(crate) fn codegen_const_value<'tcx>(
if fx.clif_type(layout.ty).is_some() {
return CValue::const_val(fx, layout, int);
} else {
- let raw_val = int.size().truncate(int.assert_bits(int.size()));
+ let raw_val = int.size().truncate(int.to_bits(int.size()));
let val = match int.size().bytes() {
1 => fx.bcx.ins().iconst(types::I8, raw_val as i64),
2 => fx.bcx.ins().iconst(types::I16, raw_val as i64),
@@ -155,7 +155,7 @@ pub(crate) fn codegen_const_value<'tcx>(
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
}
}
- GlobalAlloc::Function(instance) => {
+ GlobalAlloc::Function { instance, .. } => {
let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
let local_func_id =
fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
@@ -351,7 +351,9 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
TodoItem::Alloc(alloc_id) => {
let alloc = match tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(alloc) => alloc,
- GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::VTable(..) => {
+ GlobalAlloc::Function { .. }
+ | GlobalAlloc::Static(_)
+ | GlobalAlloc::VTable(..) => {
unreachable!()
}
};
@@ -383,15 +385,43 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
if let Some(section_name) = section_name {
let (segment_name, section_name) = if tcx.sess.target.is_like_osx {
- let section_name = section_name.as_str();
- if let Some(names) = section_name.split_once(',') {
- names
- } else {
+ // See https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/MCSectionMachO.cpp
+ let mut parts = section_name.as_str().split(',');
+ let Some(segment_name) = parts.next() else {
tcx.dcx().fatal(format!(
"#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma",
section_name
));
+ };
+ let Some(section_name) = parts.next() else {
+ tcx.dcx().fatal(format!(
+ "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma",
+ section_name
+ ));
+ };
+ if section_name.len() > 16 {
+ tcx.dcx().fatal(format!(
+ "#[link_section = \"{}\"] is not valid for macos target: section name bigger than 16 bytes",
+ section_name
+ ));
}
+ let section_type = parts.next().unwrap_or("regular");
+ if section_type != "regular" && section_type != "cstring_literals" {
+ tcx.dcx().fatal(format!(
+ "#[link_section = \"{}\"] is not supported: unsupported section type {}",
+ section_name, section_type,
+ ));
+ }
+ let _attrs = parts.next();
+ if parts.next().is_some() {
+ tcx.dcx().fatal(format!(
+ "#[link_section = \"{}\"] is not valid for macos target: too many components",
+ section_name
+ ));
+ }
+ // FIXME(bytecodealliance/wasmtime#8901) set S_CSTRING_LITERALS section type when
+ // cstring_literals is specified
+ (segment_name, section_name)
} else {
("", section_name.as_str())
};
@@ -415,7 +445,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
let reloc_target_alloc = tcx.global_alloc(alloc_id);
let data_id = match reloc_target_alloc {
- GlobalAlloc::Function(instance) => {
+ GlobalAlloc::Function { instance, .. } => {
assert_eq!(addend, 0);
let func_id =
crate::abi::import_function(tcx, module, instance.polymorphize(tcx));
@@ -501,12 +531,12 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
Ordering::Equal => scalar_int,
Ordering::Less => match ty.kind() {
ty::Uint(_) => ScalarInt::try_from_uint(
- scalar_int.assert_uint(scalar_int.size()),
+ scalar_int.to_uint(scalar_int.size()),
fx.layout_of(*ty).size,
)
.unwrap(),
ty::Int(_) => ScalarInt::try_from_int(
- scalar_int.assert_int(scalar_int.size()),
+ scalar_int.to_int(scalar_int.size()),
fx.layout_of(*ty).size,
)
.unwrap(),
@@ -565,6 +595,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
{
return None;
}
+ TerminatorKind::TailCall { .. } => return None,
TerminatorKind::Call { .. } => {}
}
}
diff --git a/src/debuginfo/object.rs b/src/debuginfo/object.rs
index 65f4c67..1c6e471 100644
--- a/src/debuginfo/object.rs
+++ b/src/debuginfo/object.rs
@@ -39,7 +39,13 @@ fn add_debug_section(
let section_id = self.object.add_section(
segment,
name,
- if id == SectionId::EhFrame { SectionKind::ReadOnlyData } else { SectionKind::Debug },
+ if id == SectionId::DebugStr || id == SectionId::DebugLineStr {
+ SectionKind::DebugString
+ } else if id == SectionId::EhFrame {
+ SectionKind::ReadOnlyData
+ } else {
+ SectionKind::Debug
+ },
);
self.object
.section_mut(section_id)
diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs
index eebd181..ac7dd0b 100644
--- a/src/debuginfo/unwind.rs
+++ b/src/debuginfo/unwind.rs
@@ -1,7 +1,8 @@
//! Unwind info generation (`.eh_frame`)
use cranelift_codegen::ir::Endianness;
-use cranelift_codegen::isa::{unwind::UnwindInfo, TargetIsa};
+use cranelift_codegen::isa::unwind::UnwindInfo;
+use cranelift_codegen::isa::TargetIsa;
use cranelift_object::ObjectProduct;
use gimli::write::{CieId, EhFrame, FrameTable, Section};
use gimli::RunTimeEndian;
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index 394c810..b6fee1b 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -11,8 +11,9 @@
use rustc_codegen_ssa::back::link::ensure_removed;
use rustc_codegen_ssa::back::metadata::create_compressed_metadata_file;
use rustc_codegen_ssa::base::determine_cgu_reuse;
-use rustc_codegen_ssa::errors as ssa_errors;
-use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
+use rustc_codegen_ssa::{
+ errors as ssa_errors, CodegenResults, CompiledModule, CrateInfo, ModuleKind,
+};
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::{par_map, IntoDynSyncSend};
@@ -26,7 +27,9 @@
use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
use crate::debuginfo::TypeDebugContext;
use crate::global_asm::GlobalAsmConfig;
-use crate::{prelude::*, BackendConfig};
+use crate::prelude::*;
+use crate::unwind_module::UnwindModule;
+use crate::BackendConfig;
struct ModuleCodegenResult {
module_regular: CompiledModule,
@@ -288,6 +291,29 @@ fn produce_final_output_artifacts(
}
}
+ if sess.opts.json_artifact_notifications {
+ if codegen_results.modules.len() == 1 {
+ codegen_results.modules[0].for_each_output(|_path, ty| {
+ if sess.opts.output_types.contains_key(&ty) {
+ let descr = ty.shorthand();
+ // for single cgu file is renamed to drop cgu specific suffix
+ // so we regenerate it the same way
+ let path = crate_output.path(ty);
+ sess.dcx().emit_artifact_notification(path.as_path(), descr);
+ }
+ });
+ } else {
+ for module in &codegen_results.modules {
+ module.for_each_output(|path, ty| {
+ if sess.opts.output_types.contains_key(&ty) {
+ let descr = ty.shorthand();
+ sess.dcx().emit_artifact_notification(&path, descr);
+ }
+ });
+ }
+ }
+ }
+
// We leave the following files around by default:
// - #crate#.o
// - #crate#.crate.metadata.o
@@ -295,7 +321,11 @@ fn produce_final_output_artifacts(
// These are used in linking steps and will be cleaned up afterward.
}
-fn make_module(sess: &Session, backend_config: &BackendConfig, name: String) -> ObjectModule {
+fn make_module(
+ sess: &Session,
+ backend_config: &BackendConfig,
+ name: String,
+) -> UnwindModule<ObjectModule> {
let isa = crate::build_isa(sess, backend_config);
let mut builder =
@@ -304,16 +334,15 @@ fn make_module(sess: &Session, backend_config: &BackendConfig, name: String) ->
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
// can easily double the amount of time necessary to perform linking.
builder.per_function_section(sess.opts.unstable_opts.function_sections.unwrap_or(false));
- ObjectModule::new(builder)
+ UnwindModule::new(ObjectModule::new(builder), true)
}
fn emit_cgu(
output_filenames: &OutputFilenames,
prof: &SelfProfilerRef,
name: String,
- module: ObjectModule,
+ module: UnwindModule<ObjectModule>,
debug: Option<DebugContext>,
- unwind_context: UnwindContext,
global_asm_object_file: Option<PathBuf>,
producer: &str,
) -> Result<ModuleCodegenResult, String> {
@@ -323,8 +352,6 @@ fn emit_cgu(
debug.emit(&mut product);
}
- unwind_context.emit(&mut product);
-
let module_regular = emit_module(
output_filenames,
prof,
@@ -471,7 +498,6 @@ fn module_codegen(
let mut cx = crate::CodegenCx::new(
tcx,
- backend_config.clone(),
module.isa(),
tcx.sess.opts.debuginfo != DebugInfo::None,
cgu_name,
@@ -508,13 +534,7 @@ fn module_codegen(
}
}
}
- crate::main_shim::maybe_create_entry_wrapper(
- tcx,
- &mut module,
- &mut cx.unwind_context,
- false,
- cgu.is_primary(),
- );
+ crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, false, cgu.is_primary());
let cgu_name = cgu.name().as_str().to_owned();
@@ -548,7 +568,6 @@ fn module_codegen(
cgu_name,
module,
cx.debug_context,
- cx.unwind_context,
global_asm_object_file,
&producer,
)
@@ -642,13 +661,10 @@ pub(crate) fn run_aot(
});
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
- let mut allocator_unwind_context = UnwindContext::new(allocator_module.isa(), true);
- let created_alloc_shim =
- crate::allocator::codegen(tcx, &mut allocator_module, &mut allocator_unwind_context);
+ let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
let allocator_module = if created_alloc_shim {
- let mut product = allocator_module.finish();
- allocator_unwind_context.emit(&mut product);
+ let product = allocator_module.finish();
match emit_module(
tcx.output_filenames(()),
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index 4b14913..12e860f 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -14,12 +14,12 @@
use rustc_span::Symbol;
use crate::debuginfo::TypeDebugContext;
-use crate::{prelude::*, BackendConfig};
-use crate::{CodegenCx, CodegenMode};
+use crate::prelude::*;
+use crate::unwind_module::UnwindModule;
+use crate::{BackendConfig, CodegenCx, CodegenMode};
struct JitState {
- backend_config: BackendConfig,
- jit_module: JITModule,
+ jit_module: UnwindModule<JITModule>,
}
thread_local! {
@@ -63,7 +63,7 @@ fn create_jit_module(
tcx: TyCtxt<'_>,
backend_config: &BackendConfig,
hotswap: bool,
-) -> (JITModule, CodegenCx) {
+) -> (UnwindModule<JITModule>, CodegenCx) {
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
let isa = crate::build_isa(tcx.sess, backend_config);
@@ -72,17 +72,11 @@ fn create_jit_module(
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info));
jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8);
- let mut jit_module = JITModule::new(jit_builder);
+ let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false);
- let mut cx = crate::CodegenCx::new(
- tcx,
- backend_config.clone(),
- jit_module.isa(),
- false,
- Symbol::intern("dummy_cgu_name"),
- );
+ let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, Symbol::intern("dummy_cgu_name"));
- crate::allocator::codegen(tcx, &mut jit_module, &mut cx.unwind_context);
+ crate::allocator::codegen(tcx, &mut jit_module);
(jit_module, cx)
}
@@ -128,7 +122,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
);
}
CodegenMode::JitLazy => {
- codegen_shim(tcx, &mut cx, &mut cached_context, &mut jit_module, inst)
+ codegen_shim(tcx, &mut cached_context, &mut jit_module, inst)
}
},
MonoItem::Static(def_id) => {
@@ -146,18 +140,11 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
}
- crate::main_shim::maybe_create_entry_wrapper(
- tcx,
- &mut jit_module,
- &mut cx.unwind_context,
- true,
- true,
- );
+ crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, true, true);
tcx.dcx().abort_if_errors();
- jit_module.finalize_definitions().unwrap();
- unsafe { cx.unwind_context.register_jit(&jit_module) };
+ jit_module.finalize_definitions();
println!(
"Rustc codegen cranelift will JIT run the executable, because -Cllvm-args=mode=jit was passed"
@@ -177,12 +164,12 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
call_conv: jit_module.target_config().default_call_conv,
};
let start_func_id = jit_module.declare_function("main", Linkage::Import, &start_sig).unwrap();
- let finalized_start: *const u8 = jit_module.get_finalized_function(start_func_id);
+ let finalized_start: *const u8 = jit_module.module.get_finalized_function(start_func_id);
LAZY_JIT_STATE.with(|lazy_jit_state| {
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
assert!(lazy_jit_state.is_none());
- *lazy_jit_state = Some(JitState { backend_config, jit_module });
+ *lazy_jit_state = Some(JitState { jit_module });
});
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
@@ -268,7 +255,6 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
let lazy_jit_state = lazy_jit_state.as_mut().unwrap();
let jit_module = &mut lazy_jit_state.jit_module;
- let backend_config = lazy_jit_state.backend_config.clone();
let name = tcx.symbol_name(instance).name;
let sig = crate::abi::get_function_sig(
@@ -278,7 +264,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
);
let func_id = jit_module.declare_function(name, Linkage::Export, &sig).unwrap();
- let current_ptr = jit_module.read_got_entry(func_id);
+ let current_ptr = jit_module.module.read_got_entry(func_id);
// If the function's GOT entry has already been updated to point at something other
// than the shim trampoline, don't re-jit but just return the new pointer instead.
@@ -288,11 +274,10 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
return current_ptr;
}
- jit_module.prepare_for_function_redefine(func_id).unwrap();
+ jit_module.module.prepare_for_function_redefine(func_id).unwrap();
let mut cx = crate::CodegenCx::new(
tcx,
- backend_config,
jit_module.isa(),
false,
Symbol::intern("dummy_cgu_name"),
@@ -300,9 +285,8 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
assert!(cx.global_asm.is_empty());
- jit_module.finalize_definitions().unwrap();
- unsafe { cx.unwind_context.register_jit(&jit_module) };
- jit_module.get_finalized_function(func_id)
+ jit_module.finalize_definitions();
+ jit_module.module.get_finalized_function(func_id)
})
})
}
@@ -310,7 +294,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
fn dep_symbol_lookup_fn(
sess: &Session,
crate_info: CrateInfo,
-) -> Box<dyn Fn(&str) -> Option<*const u8>> {
+) -> Box<dyn Fn(&str) -> Option<*const u8> + Send> {
use rustc_middle::middle::dependency_format::Linkage;
let mut dylib_paths = Vec::new();
@@ -362,9 +346,8 @@ fn dep_symbol_lookup_fn(
fn codegen_shim<'tcx>(
tcx: TyCtxt<'tcx>,
- cx: &mut CodegenCx,
cached_context: &mut Context,
- module: &mut JITModule,
+ module: &mut UnwindModule<JITModule>,
inst: Instance<'tcx>,
) {
let pointer_type = module.target_config().pointer_type();
@@ -413,5 +396,4 @@ fn codegen_shim<'tcx>(
trampoline_builder.ins().return_(&ret_vals);
module.define_function(func_id, context).unwrap();
- cx.unwind_context.add_function(func_id, context, module.isa());
}
diff --git a/src/inline_asm.rs b/src/inline_asm.rs
index 2de804f..16edec4 100644
--- a/src/inline_asm.rs
+++ b/src/inline_asm.rs
@@ -4,6 +4,7 @@
use cranelift_codegen::isa::CallConv;
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
+use rustc_hir::LangItem;
use rustc_span::sym;
use rustc_target::asm::*;
use target_lexicon::BinaryFormat;
@@ -45,9 +46,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
// Used by panic_abort on Windows, but uses a syntax which only happens to work with
// asm!() by accident and breaks with the GNU assembler as well as global_asm!() for
// the LLVM backend.
- if template.len() == 1
- && template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string())
- {
+ if template.len() == 1 && template[0] == InlineAsmTemplatePiece::String("int $$0x29".into()) {
fx.bcx.ins().trap(TrapCode::User(1));
return;
}
@@ -112,13 +111,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
);
let sig =
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
- create_wrapper_function(
- fx.module,
- &mut fx.cx.unwind_context,
- sig,
- &wrapper_name,
- symbol.name,
- );
+ create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name);
CInlineAsmOperand::Symbol { symbol: wrapper_name }
} else {
@@ -282,13 +275,7 @@ pub(crate) fn codegen_naked_asm<'tcx>(
);
let sig =
get_function_sig(tcx, module.target_config().default_call_conv, instance);
- create_wrapper_function(
- module,
- &mut cx.unwind_context,
- sig,
- &wrapper_name,
- symbol.name,
- );
+ create_wrapper_function(module, sig, &wrapper_name, symbol.name);
CInlineAsmOperand::Symbol { symbol: wrapper_name }
} else {
@@ -927,7 +914,7 @@ fn call_inline_asm<'tcx>(
fn asm_clif_type<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
match ty.kind() {
// Adapted from https://github.com/rust-lang/rust/blob/f3c66088610c1b80110297c2d9a8b5f9265b013f/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L136-L151
- ty::Adt(adt, args) if Some(adt.did()) == fx.tcx.lang_items().maybe_uninit() => {
+ ty::Adt(adt, args) if fx.tcx.is_lang_item(adt.did(), LangItem::MaybeUninit) => {
let fields = &adt.non_enum_variant().fields;
let ty = fields[FieldIdx::from_u32(1)].ty(fx.tcx, args);
let ty::Adt(ty, args) = ty.kind() else {
diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs
index e50c74b..720a0d8 100644
--- a/src/intrinsics/llvm.rs
+++ b/src/intrinsics/llvm.rs
@@ -6,32 +6,16 @@
pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
- generic_args: GenericArgsRef<'tcx>,
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: Option<BasicBlock>,
span: Span,
) {
if intrinsic.starts_with("llvm.aarch64") {
- return llvm_aarch64::codegen_aarch64_llvm_intrinsic_call(
- fx,
- intrinsic,
- generic_args,
- args,
- ret,
- target,
- );
+ return llvm_aarch64::codegen_aarch64_llvm_intrinsic_call(fx, intrinsic, args, ret, target);
}
if intrinsic.starts_with("llvm.x86") {
- return llvm_x86::codegen_x86_llvm_intrinsic_call(
- fx,
- intrinsic,
- generic_args,
- args,
- ret,
- target,
- span,
- );
+ return llvm_x86::codegen_x86_llvm_intrinsic_call(fx, intrinsic, args, ret, target, span);
}
match intrinsic {
diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs
index e66bcbf..f0fb186 100644
--- a/src/intrinsics/llvm_aarch64.rs
+++ b/src/intrinsics/llvm_aarch64.rs
@@ -6,7 +6,6 @@
pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
- _args: GenericArgsRef<'tcx>,
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: Option<BasicBlock>,
diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs
index 27b55ec..a20faa2 100644
--- a/src/intrinsics/llvm_x86.rs
+++ b/src/intrinsics/llvm_x86.rs
@@ -10,7 +10,6 @@
pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
- _args: GenericArgsRef<'tcx>,
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: Option<BasicBlock>,
@@ -41,7 +40,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
shl rdx, 32
or rax, rdx
"
- .to_string(),
+ .into(),
)],
&[
CInlineAsmOperand::In {
@@ -459,11 +458,20 @@ fn select4(
intrinsic_args!(fx, args => (a); intrinsic);
let a = a.load_scalar(fx);
+ let value = fx.bcx.ins().x86_cvtt2dq(types::I32X4, a);
+ let cvalue = CValue::by_val(value, ret.layout());
+ ret.write_cvalue(fx, cvalue);
+ }
+ "llvm.x86.sse2.cvtps2dq" => {
+ // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_epi32
+ intrinsic_args!(fx, args => (a); intrinsic);
+ let a = a.load_scalar(fx);
+
// Using inline asm instead of fcvt_to_sint_sat as unrepresentable values are turned
// into 0x80000000 for which Cranelift doesn't have a native instruction.
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(format!("cvttps2dq xmm0, xmm0"))],
+ &[InlineAsmTemplatePiece::String("cvtps2dq xmm0, xmm0".into())],
&[CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
_late: true,
@@ -867,7 +875,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(asm.to_string())],
+ &[InlineAsmTemplatePiece::String(asm.into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
@@ -902,11 +910,11 @@ fn select4(
.span_fatal(span, "Index argument for `_mm_cmpestri` is not a constant");
};
- let imm8 = imm8.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", imm8));
+ let imm8 = imm8.to_u8();
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(format!("pcmpestri xmm0, xmm1, {imm8}"))],
+ &[InlineAsmTemplatePiece::String(format!("pcmpestri xmm0, xmm1, {imm8}").into())],
&[
CInlineAsmOperand::In {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -955,11 +963,11 @@ fn select4(
.span_fatal(span, "Index argument for `_mm_cmpestrm` is not a constant");
};
- let imm8 = imm8.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", imm8));
+ let imm8 = imm8.to_u8();
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(format!("pcmpestrm xmm0, xmm1, {imm8}"))],
+ &[InlineAsmTemplatePiece::String(format!("pcmpestrm xmm0, xmm1, {imm8}").into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -1003,11 +1011,11 @@ fn select4(
);
};
- let imm8 = imm8.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", imm8));
+ let imm8 = imm8.to_u8();
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(format!("pclmulqdq xmm0, xmm1, {imm8}"))],
+ &[InlineAsmTemplatePiece::String(format!("pclmulqdq xmm0, xmm1, {imm8}").into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -1040,11 +1048,13 @@ fn select4(
);
};
- let imm8 = imm8.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", imm8));
+ let imm8 = imm8.to_u8();
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(format!("aeskeygenassist xmm0, xmm0, {imm8}"))],
+ &[InlineAsmTemplatePiece::String(
+ format!("aeskeygenassist xmm0, xmm0, {imm8}").into(),
+ )],
&[CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
_late: true,
@@ -1063,7 +1073,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("aesimc xmm0, xmm0".to_string())],
+ &[InlineAsmTemplatePiece::String("aesimc xmm0, xmm0".into())],
&[CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
_late: true,
@@ -1083,7 +1093,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("aesenc xmm0, xmm1".to_string())],
+ &[InlineAsmTemplatePiece::String("aesenc xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -1109,7 +1119,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("aesenclast xmm0, xmm1".to_string())],
+ &[InlineAsmTemplatePiece::String("aesenclast xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -1135,7 +1145,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("aesdec xmm0, xmm1".to_string())],
+ &[InlineAsmTemplatePiece::String("aesdec xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -1161,7 +1171,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("aesdeclast xmm0, xmm1".to_string())],
+ &[InlineAsmTemplatePiece::String("aesdeclast xmm0, xmm1".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
@@ -1195,11 +1205,11 @@ fn select4(
.span_fatal(span, "Func argument for `_mm_sha1rnds4_epu32` is not a constant");
};
- let func = func.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", func));
+ let func = func.to_u8();
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String(format!("sha1rnds4 xmm1, xmm2, {func}"))],
+ &[InlineAsmTemplatePiece::String(format!("sha1rnds4 xmm1, xmm2, {func}").into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1225,7 +1235,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("sha1msg1 xmm1, xmm2".to_string())],
+ &[InlineAsmTemplatePiece::String("sha1msg1 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1251,7 +1261,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("sha1msg2 xmm1, xmm2".to_string())],
+ &[InlineAsmTemplatePiece::String("sha1msg2 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1277,7 +1287,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("sha1nexte xmm1, xmm2".to_string())],
+ &[InlineAsmTemplatePiece::String("sha1nexte xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1304,7 +1314,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("sha256rnds2 xmm1, xmm2".to_string())],
+ &[InlineAsmTemplatePiece::String("sha256rnds2 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1335,7 +1345,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("sha256msg1 xmm1, xmm2".to_string())],
+ &[InlineAsmTemplatePiece::String("sha256msg1 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1361,7 +1371,7 @@ fn select4(
codegen_inline_asm_inner(
fx,
- &[InlineAsmTemplatePiece::String("sha256msg2 xmm1, xmm2".to_string())],
+ &[InlineAsmTemplatePiece::String("sha256msg2 xmm1, xmm2".into())],
&[
CInlineAsmOperand::InOut {
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm1)),
@@ -1416,6 +1426,36 @@ fn select4(
ret.write_cvalue(fx, res);
}
+ "llvm.x86.rdtsc" => {
+ // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_rdtsc&ig_expand=5273
+
+ let res_place = CPlace::new_stack_slot(
+ fx,
+ fx.layout_of(Ty::new_tup(fx.tcx, &[fx.tcx.types.u32, fx.tcx.types.u32])),
+ );
+ let eax_place = res_place.place_field(fx, FieldIdx::new(0));
+ let edx_place = res_place.place_field(fx, FieldIdx::new(1));
+ codegen_inline_asm_inner(
+ fx,
+ &[InlineAsmTemplatePiece::String("rdtsc".into())],
+ &[
+ CInlineAsmOperand::Out {
+ reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
+ late: true,
+ place: Some(eax_place),
+ },
+ CInlineAsmOperand::Out {
+ reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
+ late: true,
+ place: Some(edx_place),
+ },
+ ],
+ InlineAsmOptions::NOSTACK | InlineAsmOptions::NOMEM,
+ );
+ let res = res_place.to_cvalue(fx);
+ ret.write_cvalue_transmute(fx, res);
+ }
+
_ => {
fx.tcx
.dcx()
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs
index cafdc05..b21c559 100644
--- a/src/intrinsics/mod.rs
+++ b/src/intrinsics/mod.rs
@@ -1261,7 +1261,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
}
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained
- // by converting the `InstanceDef::Intrinsic` to an `InstanceDef::Item`.
+ // by converting the `InstanceKind::Intrinsic` to an `InstanceKind::Item`.
_ => {
let intrinsic = fx.tcx.intrinsic(instance.def_id()).unwrap();
if intrinsic.must_be_overridden {
diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs
index b17f191..ca910dc 100644
--- a/src/intrinsics/simd.rs
+++ b/src/intrinsics/simd.rs
@@ -133,6 +133,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
.expect_const()
.eval(fx.tcx, ty::ParamEnv::reveal_all(), span)
.unwrap()
+ .1
.unwrap_branch();
assert_eq!(x.layout(), y.layout());
@@ -146,8 +147,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let total_len = lane_count * 2;
- let indexes =
- idx.iter().map(|idx| idx.unwrap_leaf().try_to_u32().unwrap()).collect::<Vec<u32>>();
+ let indexes = idx.iter().map(|idx| idx.unwrap_leaf().to_u32()).collect::<Vec<u32>>();
for &idx in &indexes {
assert!(u64::from(idx) < total_len, "idx {} out of range 0..{}", idx, total_len);
@@ -281,9 +281,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
fx.tcx.dcx().span_fatal(span, "Index argument for `simd_insert` is not a constant");
};
- let idx: u32 = idx_const
- .try_to_u32()
- .unwrap_or_else(|_| panic!("kind not scalar: {:?}", idx_const));
+ let idx: u32 = idx_const.to_u32();
let (lane_count, _lane_ty) = base.layout().ty.simd_size_and_type(fx.tcx);
if u64::from(idx) >= lane_count {
fx.tcx.dcx().span_fatal(
@@ -329,9 +327,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
return;
};
- let idx = idx_const
- .try_to_u32()
- .unwrap_or_else(|_| panic!("kind not scalar: {:?}", idx_const));
+ let idx = idx_const.to_u32();
let (lane_count, _lane_ty) = v.layout().ty.simd_size_and_type(fx.tcx);
if u64::from(idx) >= lane_count {
fx.tcx.dcx().span_fatal(
diff --git a/src/lib.rs b/src/lib.rs
index 39bbad1..9d46d8d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,13 +1,16 @@
-#![cfg_attr(doc, allow(internal_features))]
-#![cfg_attr(doc, feature(rustdoc_internals))]
-#![cfg_attr(doc, doc(rust_logo))]
-#![feature(rustc_private)]
-// Note: please avoid adding other feature gates where possible
+// tidy-alphabetical-start
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
+#![cfg_attr(doc, allow(internal_features))]
+#![cfg_attr(doc, doc(rust_logo))]
+#![cfg_attr(doc, feature(rustdoc_internals))]
+// Note: please avoid adding other feature gates where possible
+#![feature(rustc_private)]
+// Note: please avoid adding other feature gates where possible
#![warn(rust_2018_idioms)]
-#![warn(unused_lifetimes)]
#![warn(unreachable_pub)]
+#![warn(unused_lifetimes)]
+// tidy-alphabetical-end
extern crate jobserver;
#[macro_use]
@@ -21,7 +24,6 @@
extern crate rustc_incremental;
extern crate rustc_index;
extern crate rustc_metadata;
-extern crate rustc_monomorphize;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
@@ -76,16 +78,16 @@
mod toolchain;
mod trap;
mod unsize;
+mod unwind_module;
mod value_and_place;
mod vtable;
mod prelude {
pub(crate) use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
pub(crate) use cranelift_codegen::ir::function::Function;
- pub(crate) use cranelift_codegen::ir::types;
pub(crate) use cranelift_codegen::ir::{
- AbiParam, Block, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot,
- StackSlotData, StackSlotKind, TrapCode, Type, Value,
+ types, AbiParam, Block, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc,
+ StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value,
};
pub(crate) use cranelift_codegen::Context;
pub(crate) use cranelift_module::{self, DataDescription, FuncId, Linkage, Module};
@@ -95,7 +97,7 @@ mod prelude {
pub(crate) use rustc_middle::mir::{self, *};
pub(crate) use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
pub(crate) use rustc_middle::ty::{
- self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
+ self, FloatTy, Instance, InstanceKind, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
};
pub(crate) use rustc_span::Span;
pub(crate) use rustc_target::abi::{Abi, FieldIdx, Scalar, Size, VariantIdx, FIRST_VARIANT};
@@ -127,22 +129,13 @@ struct CodegenCx {
global_asm: String,
inline_asm_index: Cell<usize>,
debug_context: Option<DebugContext>,
- unwind_context: UnwindContext,
cgu_name: Symbol,
}
impl CodegenCx {
- fn new(
- tcx: TyCtxt<'_>,
- backend_config: BackendConfig,
- isa: &dyn TargetIsa,
- debug_info: bool,
- cgu_name: Symbol,
- ) -> Self {
+ fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, debug_info: bool, cgu_name: Symbol) -> Self {
assert_eq!(pointer_ty(tcx), isa.pointer_type());
- let unwind_context =
- UnwindContext::new(isa, matches!(backend_config.codegen_mode, CodegenMode::Aot));
let debug_context = if debug_info && !tcx.sess.target.options.is_like_windows {
Some(DebugContext::new(tcx, isa, cgu_name.as_str()))
} else {
@@ -155,7 +148,6 @@ fn new(
global_asm: String::new(),
inline_asm_index: Cell::new(0),
debug_context,
- unwind_context,
cgu_name,
}
}
@@ -172,7 +164,7 @@ fn locale_resource(&self) -> &'static str {
}
fn init(&self, sess: &Session) {
- use rustc_session::config::Lto;
+ use rustc_session::config::{InstrumentCoverage, Lto};
match sess.lto() {
Lto::No | Lto::ThinLocal => {}
Lto::Thin | Lto::Fat => {
@@ -180,6 +172,11 @@ fn init(&self, sess: &Session) {
}
}
+ if sess.opts.cg.instrument_coverage() != InstrumentCoverage::No {
+ sess.dcx()
+ .fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
+ }
+
let mut config = self.config.borrow_mut();
if config.is_none() {
let new_config = BackendConfig::from_opts(&sess.opts.cg.llvm_args)
@@ -268,9 +265,9 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
flags_builder.set("enable_verifier", enable_verifier).unwrap();
flags_builder.set("regalloc_checker", enable_verifier).unwrap();
- let preserve_frame_pointer = sess.target.options.frame_pointer
- != rustc_target::spec::FramePointer::MayOmit
- || matches!(sess.opts.cg.force_frame_pointers, Some(true));
+ let mut frame_ptr = sess.target.options.frame_pointer.clone();
+ frame_ptr.ratchet(sess.opts.cg.force_frame_pointers);
+ let preserve_frame_pointer = frame_ptr != rustc_target::spec::FramePointer::MayOmit;
flags_builder
.set("preserve_frame_pointers", if preserve_frame_pointer { "true" } else { "false" })
.unwrap();
diff --git a/src/main_shim.rs b/src/main_shim.rs
index f9a7296..ba20a75 100644
--- a/src/main_shim.rs
+++ b/src/main_shim.rs
@@ -1,9 +1,9 @@
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use rustc_hir::LangItem;
-use rustc_middle::ty::AssocKind;
-use rustc_middle::ty::GenericArg;
+use rustc_middle::ty::{AssocKind, GenericArg};
use rustc_session::config::{sigpipe, EntryFnType};
use rustc_span::symbol::Ident;
+use rustc_span::DUMMY_SP;
use crate::prelude::*;
@@ -11,8 +11,7 @@
/// users main function.
pub(crate) fn maybe_create_entry_wrapper(
tcx: TyCtxt<'_>,
- module: &mut impl Module,
- unwind_context: &mut UnwindContext,
+ module: &mut dyn Module,
is_jit: bool,
is_primary_cgu: bool,
) {
@@ -36,12 +35,11 @@ pub(crate) fn maybe_create_entry_wrapper(
return;
}
- create_entry_fn(tcx, module, unwind_context, main_def_id, is_jit, is_main_fn, sigpipe);
+ create_entry_fn(tcx, module, main_def_id, is_jit, is_main_fn, sigpipe);
fn create_entry_fn(
tcx: TyCtxt<'_>,
- m: &mut impl Module,
- unwind_context: &mut UnwindContext,
+ m: &mut dyn Module,
rust_main_def_id: DefId,
ignore_lang_start_wrapper: bool,
is_main_fn: bool,
@@ -121,6 +119,7 @@ fn create_entry_fn(
ParamEnv::reveal_all(),
report.def_id,
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
+ DUMMY_SP,
)
.polymorphize(tcx);
@@ -146,6 +145,7 @@ fn create_entry_fn(
ParamEnv::reveal_all(),
start_def_id,
tcx.mk_args(&[main_ret_ty.into()]),
+ DUMMY_SP,
)
.polymorphize(tcx);
let start_func_id = import_function(tcx, m, start_instance);
@@ -170,7 +170,5 @@ fn create_entry_fn(
if let Err(err) = m.define_function(cmain_func_id, &mut ctx) {
tcx.dcx().fatal(format!("entry symbol `{entry_name}` defined multiple times: {err}"));
}
-
- unwind_context.add_function(cmain_func_id, &ctx, m.isa());
}
}
diff --git a/src/optimize/peephole.rs b/src/optimize/peephole.rs
index 26327dc..c93fe93 100644
--- a/src/optimize/peephole.rs
+++ b/src/optimize/peephole.rs
@@ -1,6 +1,7 @@
//! Peephole optimizations that can be performed while creating clif ir.
-use cranelift_codegen::ir::{condcodes::IntCC, InstructionData, Opcode, Value, ValueDef};
+use cranelift_codegen::ir::condcodes::IntCC;
+use cranelift_codegen::ir::{InstructionData, Opcode, Value, ValueDef};
use cranelift_frontend::FunctionBuilder;
/// If the given value was produced by the lowering of `Rvalue::Not` return the input and true,
diff --git a/src/unsize.rs b/src/unsize.rs
index 4acbc8a..967aa53 100644
--- a/src/unsize.rs
+++ b/src/unsize.rs
@@ -39,8 +39,7 @@ pub(crate) fn unsized_info<'tcx>(
}
// trait upcasting coercion
- let vptr_entry_idx =
- fx.tcx.vtable_trait_upcasting_coercion_new_vptr_slot((source, target));
+ let vptr_entry_idx = fx.tcx.supertrait_vtable_slot((source, target));
if let Some(entry_idx) = vptr_entry_idx {
let entry_idx = u32::try_from(entry_idx).unwrap();
diff --git a/src/unwind_module.rs b/src/unwind_module.rs
new file mode 100644
index 0000000..b950aaa
--- /dev/null
+++ b/src/unwind_module.rs
@@ -0,0 +1,115 @@
+use cranelift_codegen::control::ControlPlane;
+use cranelift_codegen::ir::{Function, Signature};
+use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa};
+use cranelift_codegen::{Context, FinalizedMachReloc};
+use cranelift_module::{
+ DataDescription, DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleDeclarations,
+ ModuleResult,
+};
+use cranelift_object::{ObjectModule, ObjectProduct};
+
+use crate::UnwindContext;
+
+/// A wrapper around a [Module] which adds any defined function to the [UnwindContext].
+pub(crate) struct UnwindModule<T> {
+ pub(crate) module: T,
+ unwind_context: UnwindContext,
+}
+
+impl<T: Module> UnwindModule<T> {
+ pub(crate) fn new(module: T, pic_eh_frame: bool) -> Self {
+ let unwind_context = UnwindContext::new(module.isa(), pic_eh_frame);
+ UnwindModule { module, unwind_context }
+ }
+}
+
+impl UnwindModule<ObjectModule> {
+ pub(crate) fn finish(self) -> ObjectProduct {
+ let mut product = self.module.finish();
+ self.unwind_context.emit(&mut product);
+ product
+ }
+}
+
+#[cfg(feature = "jit")]
+impl UnwindModule<cranelift_jit::JITModule> {
+ pub(crate) fn finalize_definitions(&mut self) {
+ self.module.finalize_definitions().unwrap();
+ let prev_unwind_context = std::mem::replace(
+ &mut self.unwind_context,
+ UnwindContext::new(self.module.isa(), false),
+ );
+ unsafe { prev_unwind_context.register_jit(&self.module) };
+ }
+}
+
+impl<T: Module> Module for UnwindModule<T> {
+ fn isa(&self) -> &dyn TargetIsa {
+ self.module.isa()
+ }
+
+ fn declarations(&self) -> &ModuleDeclarations {
+ self.module.declarations()
+ }
+
+ fn get_name(&self, name: &str) -> Option<FuncOrDataId> {
+ self.module.get_name(name)
+ }
+
+ fn target_config(&self) -> TargetFrontendConfig {
+ self.module.target_config()
+ }
+
+ fn declare_function(
+ &mut self,
+ name: &str,
+ linkage: Linkage,
+ signature: &Signature,
+ ) -> ModuleResult<FuncId> {
+ self.module.declare_function(name, linkage, signature)
+ }
+
+ fn declare_anonymous_function(&mut self, signature: &Signature) -> ModuleResult<FuncId> {
+ self.module.declare_anonymous_function(signature)
+ }
+
+ fn declare_data(
+ &mut self,
+ name: &str,
+ linkage: Linkage,
+ writable: bool,
+ tls: bool,
+ ) -> ModuleResult<DataId> {
+ self.module.declare_data(name, linkage, writable, tls)
+ }
+
+ fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {
+ self.module.declare_anonymous_data(writable, tls)
+ }
+
+ fn define_function_with_control_plane(
+ &mut self,
+ func: FuncId,
+ ctx: &mut Context,
+ ctrl_plane: &mut ControlPlane,
+ ) -> ModuleResult<()> {
+ self.module.define_function_with_control_plane(func, ctx, ctrl_plane)?;
+ self.unwind_context.add_function(func, ctx, self.module.isa());
+ Ok(())
+ }
+
+ fn define_function_bytes(
+ &mut self,
+ _func_id: FuncId,
+ _func: &Function,
+ _alignment: u64,
+ _bytes: &[u8],
+ _relocs: &[FinalizedMachReloc],
+ ) -> ModuleResult<()> {
+ unimplemented!()
+ }
+
+ fn define_data(&mut self, data_id: DataId, data: &DataDescription) -> ModuleResult<()> {
+ self.module.define_data(data_id, data)
+ }
+}
diff --git a/src/value_and_place.rs b/src/value_and_place.rs
index 4146137..1aa28da 100644
--- a/src/value_and_place.rs
+++ b/src/value_and_place.rs
@@ -95,6 +95,14 @@ pub(crate) fn by_val_pair(
CValue(CValueInner::ByValPair(value, extra), layout)
}
+ /// Create an instance of a ZST
+ ///
+ /// The is represented by a dangling pointer of suitable alignment.
+ pub(crate) fn zst(layout: TyAndLayout<'tcx>) -> CValue<'tcx> {
+ assert!(layout.is_zst());
+ CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout)
+ }
+
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
self.1
}
@@ -319,7 +327,7 @@ pub(crate) fn const_val(
let val = match layout.ty.kind() {
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
- let const_val = const_val.assert_bits(layout.size);
+ let const_val = const_val.to_bits(layout.size);
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
let msb = fx.bcx.ins().iconst(types::I64, (const_val >> 64) as u64 as i64);
fx.bcx.ins().iconcat(lsb, msb)
@@ -331,7 +339,7 @@ pub(crate) fn const_val(
| ty::Ref(..)
| ty::RawPtr(..)
| ty::FnPtr(..) => {
- let raw_val = const_val.size().truncate(const_val.assert_bits(layout.size));
+ let raw_val = const_val.size().truncate(const_val.to_bits(layout.size));
fx.bcx.ins().iconst(clif_ty, raw_val as i64)
}
ty::Float(FloatTy::F32) => {