Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
67c61ce
Remove opts field from CodegenContext
bjorn3 Oct 23, 2025
385590e
Remove SharedEmitter from CodegenContext
bjorn3 Nov 21, 2025
bf5283c
Merge commit '02f889aec5dc9b4e51d4cfd86c67ce5e4a0bbf72'
GuillaumeGomez Dec 20, 2025
9ba3ed5
Move llvm intrinsic call to backend
bjorn3 Sep 18, 2025
0462ce9
Don't assume get_fn is only called from codegen_mir in cg_gcc
bjorn3 Nov 11, 2025
56be08e
Pass Function to Builder::function_call in cg_gcc
bjorn3 Nov 11, 2025
5bcd472
Partially inline get_fn_addr/get_fn in codegen_llvm_intrinsic_call
bjorn3 Nov 10, 2025
ea8f037
Fix compilation of cg_gcc with master feature disabled
bjorn3 Dec 27, 2025
f004b3e
Reduce usage of FnAbi in codegen_llvm_intrinsic_call
bjorn3 Dec 28, 2025
e90414f
Don't compute FnAbi for LLVM intrinsics in backends
bjorn3 Jan 8, 2026
fe0facf
Finish transition from `semitransparent` to `semiopaque` for `rustc_m…
Enselic Jan 1, 2026
c9a063c
Remove `Deref`/`DerefMut` impl for `Providers`.
nnethercote Jan 13, 2026
3e789ed
Stop cloning old `llvmint` repositories to generate intrinsics
GuillaumeGomez Jan 12, 2026
3dc60d0
Simplify intrinsics translation generation script
GuillaumeGomez Jan 12, 2026
c848b28
Ignore `src/intrinsic/old_archs.rs` for typo checks
GuillaumeGomez Jan 12, 2026
40973ef
Merge pull request #823 from GuillaumeGomez/simplify-intrinsics-gener…
GuillaumeGomez Jan 16, 2026
4f59819
Regenerate intrinsics
GuillaumeGomez Jan 16, 2026
2177aa9
Manually include intrinsic conversion that is not present in LLVM files
GuillaumeGomez Jan 16, 2026
9b2d8e5
Merge pull request #824 from GuillaumeGomez/regen-intrinsics
GuillaumeGomez Jan 16, 2026
f11abba
add `simd_splat` intrinsic
folkertdev Jan 18, 2026
e0b87e4
`simd_splat`: custom error in gcc backend for invalid element type
folkertdev Jan 19, 2026
012c460
`c_variadic`: use `Clone` instead of LLVM `va_copy`
folkertdev Dec 27, 2025
56d3294
Rollup merge of #149209 - lto_refactors8, r=jackh726
jhpratt Jan 21, 2026
0cb56dc
abi: add a rust-preserve-none calling convention
nagisa Jan 13, 2026
58156c5
Fix segfault related to __builtin_unreachable with inline asm
antoyo Jan 24, 2026
bcb24ce
Merge pull request #834 from rust-lang/fix/unreachable-segfault
antoyo Jan 24, 2026
87c0c90
Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee
matthiaskrgr Jan 24, 2026
d830637
Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov
bors Jan 25, 2026
81acbae
Add missing intrinsic translation for `llvm.sqrt.f32`
GuillaumeGomez Jan 25, 2026
d3df4bd
Add regression test for <https://github.com/rust-lang/rustc_codegen_g…
GuillaumeGomez Jan 25, 2026
774c8a2
Merge pull request #840 from GuillaumeGomez/sqrt-f32-intrinsic
antoyo Jan 26, 2026
25234f8
Add two new target-specific intrinsics mapping
GuillaumeGomez Jan 26, 2026
436ae1e
Add regression test for `llvm.sqrt.v4f64` and `llvm.smax.v4i32` mapping
GuillaumeGomez Jan 26, 2026
b7728f0
Omit standard copyright notice
xtqqczze Jan 26, 2026
94e2af7
Merge pull request #841 from GuillaumeGomez/more-mapping
antoyo Jan 27, 2026
4a6325d
Set gcc language name and compilation unit name
antoyo Jan 28, 2026
48a52d9
Merge pull request #843 from rust-lang/fix/debuginfo-lang-filename
antoyo Jan 28, 2026
7db4614
Merge branch 'master' into sync_from_rust_2026_01_28
antoyo Jan 28, 2026
49c9b0a
Update to nightly-2026-01-28
antoyo Jan 28, 2026
bd71a5f
Implement new f16/f128 intrinsics and implement dummy va_end
antoyo Jan 28, 2026
ee9967b
Fix clippy warning
antoyo Jan 28, 2026
ff4db77
Fix spelling mistake
antoyo Jan 28, 2026
d299dce
Fix the name of failing UI tests
antoyo Jan 28, 2026
dffd4ab
Ignore failing UI test
antoyo Jan 29, 2026
e828265
Update to nightly-2026-01-30
antoyo Jan 30, 2026
fb32a3f
Update GCC version
antoyo Jan 30, 2026
a049344
Switch to new_array_type_u64
antoyo Jan 30, 2026
e4b7464
Ignore test when 128-bit integers are disabled
antoyo Jan 30, 2026
e4e725a
Convert to inline diagnostics in all codegen backends
bjorn3 Feb 4, 2026
3339b06
Do not require `'static` for obtaining reflection information.
oli-obk Feb 7, 2026
aefb9a9
tests: adapt align-offset.rs for InstCombine improvements in LLVM 23
durin42 Feb 9, 2026
d74b276
Precommit tests for `SliceIndex` method codegen
Kmeakin Oct 18, 2025
625b180
Optimize `SliceIndex::get` impl for `RangeInclusive`
Kmeakin Jul 25, 2025
262cd76
Optimize `SliceIndex<str>` for `RangeInclusive`
Kmeakin Jul 25, 2025
94ff542
Make panic message less confusing
Kmeakin Feb 2, 2026
f8cf68f
Give `into_range` more consistent name
Kmeakin Feb 2, 2026
14527b2
Move target machine factory error reporting into codegen backend
bjorn3 Feb 11, 2026
a75ff82
Remove tm_factory field from CodegenContext
bjorn3 Feb 11, 2026
809af1f
Fix clippy warnings
antoyo Jan 30, 2026
30bd492
Merge pull request #844 from rust-lang/sync_from_rust_2026_01_28
antoyo Feb 11, 2026
dd1b72a
Fix typos and grammar in documentation
him2him2 Feb 10, 2026
740a55f
Merge pull request #849 from him2him2/fix-typos
antoyo Feb 11, 2026
4e244c7
Rollup merge of #150768 - bjorn3:llvm_intrinsic_no_fn_abi, r=wesleywiser
jhpratt Feb 12, 2026
d0b2d84
Rollup merge of #152478 - bjorn3:lto_refactors10, r=wesleywiser
jhpratt Feb 12, 2026
590c1c9
UnsafePinned: implement opsem effects of UnsafeUnpin
RalfJung Jan 19, 2026
0cbe1cc
try to work around rustdoc bug, and other rustdoc adjustments
RalfJung Jan 21, 2026
293e950
Remove SelfProfilerRef from CodegenContext
bjorn3 Feb 12, 2026
5b2cfe3
Merge branch 'master' into sync_from_rust_2026_02_12
antoyo Feb 12, 2026
c2b8abd
Update to nightly-2026-02-13
antoyo Feb 13, 2026
458adbd
Implement fptoint_sat for f16 and f128
antoyo Feb 13, 2026
5577bd7
Add missing -Zjson-target-spec for m68k test
antoyo Feb 13, 2026
27e25ff
Add failing tests
antoyo Feb 13, 2026
e373b93
Fix formatting
antoyo Feb 13, 2026
ec2996c
Add cast from f128 to non-native integer
antoyo Feb 13, 2026
4a6f0be
Add missing -Zjson-target-spec for m68k sysroot build
antoyo Feb 13, 2026
c5cb569
Add cast from f16 to non-native integer
antoyo Feb 13, 2026
1920fb1
Merge pull request #851 from rust-lang/sync_from_rust_2026_02_12
antoyo Feb 13, 2026
2ee28ca
rustc_query_impl: Use `ControlFlow` in `visit_waiters` instead of nes…
petrochenkov Feb 13, 2026
b2a2e18
Merge branch 'master' into sync_from_rust_2026_02_13
antoyo Feb 13, 2026
cd314de
Remove named lifetimes in some `PartialOrd` & `PartialEq` `impl`s
GrigorenkoPV Jul 6, 2025
d29c931
Update to nightly-2026-02-14
antoyo Feb 14, 2026
3fdb366
Fix clippy warning
antoyo Feb 14, 2026
70ae207
Merge pull request #852 from rust-lang/sync_from_rust_2026_02_13
antoyo Feb 14, 2026
6ea369c
Merge commit '70ae207ff5dcd67931c0e67cb62ebceec75a7436' into subtree-…
GuillaumeGomez Feb 14, 2026
27d5b14
Update GCC submodule
GuillaumeGomez Feb 14, 2026
1f94802
Fix libgccjit version
GuillaumeGomez Feb 14, 2026
0318407
Rollup merge of #152622 - GuillaumeGomez:subtree-update_cg_gcc_2026-0…
JonathanBrouwer Feb 14, 2026
6d625cc
Rollup merge of #145024 - Kmeakin:km/optimize-slice-index/v3, r=Mark-…
JonathanBrouwer Feb 14, 2026
33c2a6e
Rollup merge of #151365 - RalfJung:unsafe-unpin-opsem, r=BoxyUwU
JonathanBrouwer Feb 14, 2026
16da3ab
Rollup merge of #152381 - oli-obk:non_static_reflection, r=Mark-Simul…
JonathanBrouwer Feb 14, 2026
96066cb
Rollup merge of #143575 - GrigorenkoPV:unused_lifetimes, r=Mark-Simul…
JonathanBrouwer Feb 14, 2026
e6ca590
Rollup merge of #152404 - durin42:llvm-23-instcombine-shrink-constant…
JonathanBrouwer Feb 14, 2026
7c36d15
Rollup merge of #152582 - petrochenkov:waitvisit, r=TaKO8Ki
JonathanBrouwer Feb 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_codegen_gcc/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"ignorePaths": [
"src/intrinsic/archs.rs",
"src/intrinsic/old_archs.rs",
"src/intrinsic/llvm.rs"
],
"ignoreRegExpList": [
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_gcc/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ jobs:
git config --global user.name "User"
./y.sh prepare
- name: Add more failing tests for GCC without 128-bit integers support
if: ${{ matrix.libgccjit_version.gcc == 'gcc-15-without-int128.deb' }}
run: cat tests/failing-ui-tests-without-128bit-integers.txt >> tests/failing-ui-tests.txt

- name: Run tests
run: |
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/.github/workflows/m68k.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
run: |
./y.sh prepare --only-libcore --cross
./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build -Zjson-target-spec --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
./y.sh clean all
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_gcc/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ dependencies = [

[[package]]
name = "gccjit"
version = "3.1.1"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff80f4d6d0749eab3a69122210b3a1fdd52edb6162781aadd7c4842e26983683"
checksum = "26b73d18b642ce16378af78f89664841d7eeafa113682ff5d14573424eb0232a"
dependencies = [
"gccjit_sys",
]

[[package]]
name = "gccjit_sys"
version = "1.1.2"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f81d901767ddba371a619fa9bba657066a4d3c5607ee69bbb557c1c5ba9bf85"
checksum = "ee689456c013616942d5aef9a84d613cefcc3b335340d036f3650fc1a7459e15"
dependencies = [
"libc",
]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ default = ["master"]
[dependencies]
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
tempfile = "3.20"
gccjit = { version = "3.1.1", features = ["dlopen"] }
gccjit = { version = "3.3.0", features = ["dlopen"] }
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs", branch = "error-dlopen", features = ["dlopen"] }

# Local copy.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ The default configuration (see below in the [Quick start](#quick-start) section)
./y.sh test --release
```

If don't need to test GCC patches you wrote in our GCC fork, then the default configuration should
If you don't need to test GCC patches you wrote in our GCC fork, then the default configuration should
be all you need. You can update the `rustc_codegen_gcc` without worrying about GCC.

### Building with your own GCC version

If you wrote a patch for GCC and want to test it without this backend, you will need
If you wrote a patch for GCC and want to test it with this backend, you will need
to do a few more things.

To build it (most of these instructions come from [here](https://gcc.gnu.org/onlinedocs/jit/internals/index.html), so don't hesitate to take a look there if you encounter an issue):
Expand Down Expand Up @@ -127,7 +127,7 @@ You have to run these commands, in the corresponding order:
$ ./y.sh prepare
$ ./y.sh build --sysroot
```
To check if all is working correctly, run:
To check if all is working correctly, run:

```bash
$ ./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/_typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ seh = "seh"
typ = "typ"

[files]
extend-exclude = ["src/intrinsic/archs.rs"]
extend-exclude = ["src/intrinsic/archs.rs", "src/intrinsic/old_archs.rs"]
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_gcc/build_system/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
}

let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
if config.target.ends_with(".json") {
args.push(&"-Zjson-target-spec");
}

for feature in &config.features {
args.push(&"--features");
args.push(feature);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,10 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
create_dir(projects_path)?;

let nb_parts = args.nb_parts.unwrap_or(0);
if nb_parts > 0 {
if let Some(count) = projects.len().checked_div(nb_parts) {
// We increment the number of tests by one because if this is an odd number, we would skip
// one test.
let count = projects.len() / nb_parts + 1;
let count = count + 1;
let current_part = args.current_part.unwrap();
let start = current_part * count;
// We remove the projects we don't want to test.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/doc/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## How to debug GCC LTO

Run do the command with `-v -save-temps` and then extract the `lto1` line from the output and run that under the debugger.
Run the command with `-v -save-temps` and then extract the `lto1` line from the output and run that under the debugger.

## How to debug stdarch tests that cannot be ran locally
## How to debug stdarch tests that cannot be run locally

First, run the tests normally:

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/doc/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ That can be caused by the fact that you try to compile with `lto = "fat"`, but y

### ld: cannot find crtbegin.o

When compiling an executable with libgccijt, if setting the `*LIBRARY_PATH` variables to the install directory, you will get the following errors:
When compiling an executable with libgccjit, if setting the `*LIBRARY_PATH` variables to the install directory, you will get the following errors:

```
ld: cannot find crtbegin.o: No such file or directory
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/doc/gimple.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You can see the full documentation about what GIMPLE is [here](https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html). In this document we will explain how to generate it.

First, we'll copy the content from `gcc/gcc/testsuite/jit.dg/test-const-attribute.c` into a
file named `local.c` and remove the content we're not interested into:
file named `local.c` and remove the content we're not interested in:

```diff
- /* { dg-do compile { target x86_64-*-* } } */
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/doc/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If you wish to build a custom sysroot, pass the path of your sysroot source to `

### How to use [mem-trace](https://github.com/antoyo/mem-trace)

`rustc` needs to be built without `jemalloc` so that `mem-trace` can overload `malloc` since `jemalloc` is linked statically, so a `LD_PRELOAD`-ed library won't a chance to intercept the calls to `malloc`.
`rustc` needs to be built without `jemalloc` so that `mem-trace` can overload `malloc` since `jemalloc` is linked statically, so a `LD_PRELOAD`-ed library won't have a chance to intercept the calls to `malloc`.

### How to generate GIMPLE

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/libgccjit.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0081ca6631abdfa02bf42bc85aaf507b8a0e6beb
efdd0a7290c22f5438d7c5380105d353ee3e8518
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2025-12-20"
channel = "nightly-2026-02-14"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_gcc/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
}
if dest.is_none() && options.contains(InlineAsmOptions::NORETURN) {
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
let builtin_unreachable: RValue<'gcc> =
unsafe { std::mem::transmute(builtin_unreachable) };
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None);
self.llbb().add_eval(None, self.context.new_call(None, builtin_unreachable, &[]));
}

// Write results to outputs.
Expand Down
39 changes: 22 additions & 17 deletions compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {

#[cfg(not(feature = "master"))]
fn extract_element(&mut self, vec: RValue<'gcc>, idx: RValue<'gcc>) -> RValue<'gcc> {
use crate::context::new_array_type;

let vector_type = vec
.get_type()
.unqualified()
Expand All @@ -1503,7 +1505,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
let element_type = vector_type.get_element_type();
let vec_num_units = vector_type.get_num_units();
let array_type =
self.context.new_array_type(self.location, element_type, vec_num_units as u64);
new_array_type(self.context, self.location, element_type, vec_num_units as u64);
let array = self.context.new_bitcast(self.location, vec, array_type).to_rvalue();
self.context.new_array_access(self.location, array, idx).to_rvalue()
}
Expand Down Expand Up @@ -1871,32 +1873,31 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
// On the other hand, f_max works even if int_ty::MAX is greater than float_ty::MAX. Because
// we're rounding towards zero, we just get float_ty::MAX (which is always an integer).
// This already happens today with u128::MAX = 2^128 - 1 > f32::MAX.
let int_max = |signed: bool, int_width: u64| -> u128 {
fn int_max(signed: bool, int_width: u64) -> u128 {
let shift_amount = 128 - int_width;
if signed { i128::MAX as u128 >> shift_amount } else { u128::MAX >> shift_amount }
};
let int_min = |signed: bool, int_width: u64| -> i128 {
}
fn int_min(signed: bool, int_width: u64) -> i128 {
if signed { i128::MIN >> (128 - int_width) } else { 0 }
};
}

let compute_clamp_bounds_single = |signed: bool, int_width: u64| -> (u128, u128) {
// TODO: rewrite using a generic function with <F: Float>.
let compute_clamp_bounds_half = |signed: bool, int_width: u64| -> (u128, u128) {
let rounded_min =
ieee::Single::from_i128_r(int_min(signed, int_width), Round::TowardZero);
assert_eq!(rounded_min.status, Status::OK);
ieee::Half::from_i128_r(int_min(signed, int_width), Round::TowardZero);
//assert_eq!(rounded_min.status, Status::OK);
let rounded_max =
ieee::Single::from_u128_r(int_max(signed, int_width), Round::TowardZero);
ieee::Half::from_u128_r(int_max(signed, int_width), Round::TowardZero);
assert!(rounded_max.value.is_finite());
(rounded_min.value.to_bits(), rounded_max.value.to_bits())
};
let compute_clamp_bounds_double = |signed: bool, int_width: u64| -> (u128, u128) {
let rounded_min =
ieee::Double::from_i128_r(int_min(signed, int_width), Round::TowardZero);
fn compute_clamp_bounds<F: Float>(signed: bool, int_width: u64) -> (u128, u128) {
let rounded_min = F::from_i128_r(int_min(signed, int_width), Round::TowardZero);
assert_eq!(rounded_min.status, Status::OK);
let rounded_max =
ieee::Double::from_u128_r(int_max(signed, int_width), Round::TowardZero);
let rounded_max = F::from_u128_r(int_max(signed, int_width), Round::TowardZero);
assert!(rounded_max.value.is_finite());
(rounded_min.value.to_bits(), rounded_max.value.to_bits())
};
}
// To implement saturation, we perform the following steps:
//
// 1. Cast val to an integer with fpto[su]i. This may result in undef.
Expand Down Expand Up @@ -1926,15 +1927,19 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {

let float_bits_to_llval = |bx: &mut Self, bits| {
let bits_llval = match float_width {
16 => bx.cx().const_u16(bits as u16),
32 => bx.cx().const_u32(bits as u32),
64 => bx.cx().const_u64(bits as u64),
128 => bx.cx().const_u128(bits),
n => bug!("unsupported float width {}", n),
};
bx.bitcast(bits_llval, float_ty)
};
let (f_min, f_max) = match float_width {
32 => compute_clamp_bounds_single(signed, int_width),
64 => compute_clamp_bounds_double(signed, int_width),
16 => compute_clamp_bounds_half(signed, int_width),
32 => compute_clamp_bounds::<ieee::Single>(signed, int_width),
64 => compute_clamp_bounds::<ieee::Double>(signed, int_width),
128 => compute_clamp_bounds::<ieee::Quad>(signed, int_width),
n => bug!("unsupported float width {}", n),
};
let f_min = float_bits_to_llval(self, f_min);
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_codegen_gcc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::mir::Mutability;
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, PointerArithmetic, Scalar};
use rustc_middle::ty::layout::LayoutOf;

use crate::context::CodegenCx;
use crate::context::{CodegenCx, new_array_type};
use crate::type_of::LayoutGccExt;

impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
Expand All @@ -20,6 +20,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
bytes_in_context(self, bytes)
}

pub fn const_u16(&self, i: u16) -> RValue<'gcc> {
self.const_uint(self.type_u16(), i as u64)
}

fn global_string(&self, string: &str) -> LValue<'gcc> {
// TODO(antoyo): handle non-null-terminated strings.
let string = self.context.new_string_literal(string);
Expand Down Expand Up @@ -55,7 +59,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
0 => {
let context = &cx.context;
let byte_type = context.new_type::<u64>();
let typ = context.new_array_type(None, byte_type, bytes.len() as u64 / 8);
let typ = new_array_type(context, None, byte_type, bytes.len() as u64 / 8);
let elements: Vec<_> = bytes
.chunks_exact(8)
.map(|arr| {
Expand All @@ -76,7 +80,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
4 => {
let context = &cx.context;
let byte_type = context.new_type::<u32>();
let typ = context.new_array_type(None, byte_type, bytes.len() as u64 / 4);
let typ = new_array_type(context, None, byte_type, bytes.len() as u64 / 4);
let elements: Vec<_> = bytes
.chunks_exact(4)
.map(|arr| {
Expand All @@ -95,7 +99,7 @@ pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) ->
_ => {
let context = cx.context;
let byte_type = context.new_type::<u8>();
let typ = context.new_array_type(None, byte_type, bytes.len() as u64);
let typ = new_array_type(context, None, byte_type, bytes.len() as u64);
let elements: Vec<_> = bytes
.iter()
.map(|&byte| context.new_rvalue_from_int(byte_type, byte as i32))
Expand Down
25 changes: 23 additions & 2 deletions compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use rustc_middle::ty::layout::{
};
use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
use rustc_session::Session;
#[cfg(feature = "master")]
use rustc_session::config::DebugInfo;
use rustc_span::source_map::respan;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi};
Expand Down Expand Up @@ -145,6 +147,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
supports_f64_type: bool,
supports_f128_type: bool,
) -> Self {
#[cfg(feature = "master")]
if tcx.sess.opts.debuginfo != DebugInfo::None {
context.set_filename(codegen_unit.name().as_str());
}

let create_type = |ctype, rust_type| {
let layout = tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(rust_type))
Expand Down Expand Up @@ -194,8 +201,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

// TODO(antoyo): re-enable the alignment when libgccjit fixed the issue in
// gcc_jit_context_new_array_constructor (it should not use reinterpret_cast).
let i128_type = context.new_array_type(None, i64_type, 2)/*.get_aligned(i128_align)*/;
let u128_type = context.new_array_type(None, u64_type, 2)/*.get_aligned(u128_align)*/;
let i128_type = new_array_type(context, None, i64_type, 2)/*.get_aligned(i128_align)*/;
let u128_type = new_array_type(context, None, u64_type, 2)/*.get_aligned(u128_align)*/;
(i128_type, u128_type)
};

Expand Down Expand Up @@ -601,3 +608,17 @@ fn to_gcc_tls_mode(tls_model: TlsModel) -> gccjit::TlsModel {
TlsModel::Emulated => gccjit::TlsModel::GlobalDynamic,
}
}

pub fn new_array_type<'gcc>(
context: &'gcc Context<'gcc>,
location: Option<Location<'gcc>>,
typ: Type<'gcc>,
size: u64,
) -> Type<'gcc> {
#[cfg(feature = "master")]
{
context.new_array_type_u64(location, typ, size)
}
#[cfg(not(feature = "master"))]
context.new_array_type(location, typ, size)
}
15 changes: 12 additions & 3 deletions compiler/rustc_codegen_gcc/src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
fn float_to_int_cast(
&self,
signed: bool,
value: RValue<'gcc>,
mut value: RValue<'gcc>,
dest_typ: Type<'gcc>,
) -> RValue<'gcc> {
let value_type = value.get_type();
Expand All @@ -951,16 +951,22 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}

debug_assert!(dest_typ.dyncast_array().is_some());
let (dest_type, param_type) = match self.type_kind(value_type) {
TypeKind::Half => (Some(self.float_type), self.float_type),
_ => (None, value_type),
};
let name_suffix = match self.type_kind(value_type) {
// cSpell:disable
TypeKind::Float => "sfti",
// Since we will cast Half to a float, we use sfti for both.
TypeKind::Half | TypeKind::Float => "sfti",
TypeKind::Double => "dfti",
TypeKind::FP128 => "tfti",
// cSpell:enable
kind => panic!("cannot cast a {:?} to non-native integer", kind),
};
let sign = if signed { "" } else { "uns" };
let func_name = format!("__fix{}{}", sign, name_suffix);
let param = self.context.new_parameter(None, value_type, "n");
let param = self.context.new_parameter(None, param_type, "n");
let func = self.context.new_function(
None,
FunctionType::Extern,
Expand All @@ -969,6 +975,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
func_name,
false,
);
if let Some(dest_type) = dest_type {
value = self.context.new_cast(None, value, dest_type);
}
self.context.new_call(None, func, &[value])
}

Expand Down
Loading
Loading