Skip to content

Commit fba636a

Browse files
committed
Auto merge of #112814 - antoyo:sync-cg_gcc-2023-06-19, r=bjorn3
Sync rustc_codegen_gcc 2023/06/19 Hi. This is a sync of the rustc_codegen_gcc subtree. Thanks.
2 parents f272fc3 + f78096f commit fba636a

24 files changed

+245
-265
lines changed

Diff for: compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml

+29-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
matrix:
2121
libgccjit_version:
2222
- { gcc: "libgccjit.so", artifacts_branch: "master" }
23-
commands: [
24-
"--test-successful-rustc --nb-parts 2 --current-part 0",
25-
"--test-successful-rustc --nb-parts 2 --current-part 1",
23+
cargo_runner: [
24+
"sde -future -rtm_mode full --",
25+
"",
2626
]
2727

2828
steps:
@@ -36,6 +36,20 @@ jobs:
3636
- name: Install packages
3737
run: sudo apt-get install ninja-build ripgrep
3838

39+
- name: Install Intel Software Development Emulator
40+
if: ${{ matrix.cargo_runner }}
41+
run: |
42+
mkdir intel-sde
43+
cd intel-sde
44+
dir=sde-external-9.14.0-2022-10-25-lin
45+
file=$dir.tar.xz
46+
wget https://downloadmirror.intel.com/751535/$file
47+
tar xvf $file
48+
sudo mkdir /usr/share/intel-sde
49+
sudo cp -r $dir/* /usr/share/intel-sde
50+
sudo ln -s /usr/share/intel-sde/sde /usr/bin/sde
51+
sudo ln -s /usr/share/intel-sde/sde64 /usr/bin/sde64
52+
3953
- name: Download artifact
4054
uses: dawidd6/action-download-artifact@v2
4155
with:
@@ -91,6 +105,10 @@ jobs:
91105
./prepare_build.sh
92106
./build.sh --release --release-sysroot
93107
cargo test
108+
109+
- name: Clean
110+
if: ${{ !matrix.cargo_runner }}
111+
run: |
94112
./clean_all.sh
95113
96114
- name: Prepare dependencies
@@ -107,10 +125,18 @@ jobs:
107125
args: --release
108126

109127
- name: Run tests
128+
if: ${{ !matrix.cargo_runner }}
110129
run: |
111130
./test.sh --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore
112131
113132
- name: Run stdarch tests
133+
if: ${{ !matrix.cargo_runner }}
114134
run: |
115135
cd build_sysroot/sysroot_src/library/stdarch/
116136
CHANNEL=release TARGET=x86_64-unknown-linux-gnu ../../../../cargo.sh test
137+
138+
- name: Run stdarch tests
139+
if: ${{ matrix.cargo_runner }}
140+
run: |
141+
cd build_sysroot/sysroot_src/library/stdarch/
142+
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu ../../../../cargo.sh test -- --skip rtm --skip tbm --skip sse4a

Diff for: compiler/rustc_codegen_gcc/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ benchmarks
2323
tools/llvm-project
2424
tools/llvmint
2525
tools/llvmint-2
26+
# The `llvm` folder is generated by the `tools/generate_intrinsics.py` script to update intrinsics.
27+
llvm

Diff for: compiler/rustc_codegen_gcc/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ dependencies = [
3535
[[package]]
3636
name = "gccjit"
3737
version = "1.0.0"
38-
source = "git+https://github.com/antoyo/gccjit.rs#fe242b7eb26980e6c78859d51c8d4cc1e43381a3"
38+
source = "git+https://github.com/antoyo/gccjit.rs#d6e52626cfc6f487094a5d5ac66302baf3439984"
3939
dependencies = [
4040
"gccjit_sys",
4141
]
4242

4343
[[package]]
4444
name = "gccjit_sys"
4545
version = "0.0.1"
46-
source = "git+https://github.com/antoyo/gccjit.rs#fe242b7eb26980e6c78859d51c8d4cc1e43381a3"
46+
source = "git+https://github.com/antoyo/gccjit.rs#d6e52626cfc6f487094a5d5ac66302baf3439984"
4747
dependencies = [
4848
"libc",
4949
]

Diff for: compiler/rustc_codegen_gcc/Readme.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Using git-subtree with `rustc` requires a patched git to make it work.
193193
The PR that is needed is [here](https://github.com/gitgitgadget/git/pull/493).
194194
Use the following instructions to install it:
195195
196-
```
196+
```bash
197197
git clone [email protected]:tqc/git.git
198198
cd git
199199
git checkout tqc/subtree
@@ -204,6 +204,21 @@ make
204204
cp git-subtree ~/bin
205205
```
206206

207+
Then, do a sync with this command:
208+
209+
```bash
210+
PATH="$HOME/bin:$PATH" ~/bin/git-subtree push -P compiler/rustc_codegen_gcc/ ../rustc_codegen_gcc/ sync_branch_name
211+
cd ../rustc_codegen_gcc
212+
git checkout master
213+
git pull
214+
git checkout sync_branch_name
215+
git merge master
216+
```
217+
218+
TODO: write a script that does the above.
219+
220+
https://rust-lang.zulipchat.com/#narrow/stream/301329-t-devtools/topic/subtree.20madness/near/258877725
221+
207222
### How to use [mem-trace](https://github.com/antoyo/mem-trace)
208223

209224
`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`.

Diff for: compiler/rustc_codegen_gcc/build_sysroot/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ compiler_builtins = "0.1"
99
alloc = { path = "./sysroot_src/library/alloc" }
1010
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
1111
test = { path = "./sysroot_src/library/test" }
12+
proc_macro = { path = "./sysroot_src/library/proc_macro" }
1213

1314
[patch.crates-io]
1415
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }

Diff for: compiler/rustc_codegen_gcc/build_sysroot/prepare_sysroot_src.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ git config user.name || git config user.name "None"
2929

3030
git commit -m "Initial commit" -q
3131
for file in $(ls ../../patches/ | grep -v patcha); do
32-
echo "[GIT] apply" $file
33-
git apply ../../patches/$file
34-
git add -A
35-
git commit --no-gpg-sign -m "Patch $file"
32+
echo "[GIT] apply" $file
33+
git apply ../../patches/$file
34+
git add -A
35+
git commit --no-gpg-sign -m "Patch $file"
3636
done
3737
popd
3838

Diff for: compiler/rustc_codegen_gcc/example/mini_core.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
451451
drop_in_place(to_drop);
452452
}
453453

454+
#[lang = "unpin"]
455+
pub auto trait Unpin {}
456+
454457
#[lang = "deref"]
455458
pub trait Deref {
456459
type Target: ?Sized;
@@ -488,10 +491,23 @@ pub struct Box<T: ?Sized, A: Allocator = Global>(Unique<T>, A);
488491

489492
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
490493

494+
impl<T> Box<T> {
495+
pub fn new(val: T) -> Box<T> {
496+
unsafe {
497+
let size = intrinsics::size_of::<T>();
498+
let ptr = libc::malloc(size);
499+
intrinsics::copy(&val as *const T as *const u8, ptr, size);
500+
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
501+
}
502+
}
503+
}
504+
491505
impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
492506
fn drop(&mut self) {
493-
// inner value is dropped by compiler
494-
libc::free(self.pointer.0 as *mut u8);
507+
// inner value is dropped by compiler.
508+
unsafe {
509+
libc::free(self.0.pointer.0 as *mut u8);
510+
}
495511
}
496512
}
497513

Diff for: compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ fn main() {
168168
world as Box<dyn SomeTrait>;
169169

170170
assert_eq!(intrinsics::bitreverse(0b10101000u8), 0b00010101u8);
171+
assert_eq!(intrinsics::bitreverse(0xddccu16), 0x33bbu16);
172+
assert_eq!(intrinsics::bitreverse(0xffee_ddccu32), 0x33bb77ffu32);
173+
assert_eq!(intrinsics::bitreverse(0x1234_5678_ffee_ddccu64), 0x33bb77ff1e6a2c48u64);
171174

172175
assert_eq!(intrinsics::bswap(0xabu8), 0xabu8);
173176
assert_eq!(intrinsics::bswap(0xddccu16), 0xccddu16);

Diff for: compiler/rustc_codegen_gcc/example/std_example.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn main() {
5858

5959
assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26);
6060
assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7);
61+
assert_eq!(0x1234_5678_ffee_ddcc_1234_5678_ffee_ddccu128.reverse_bits(), 0x33bb77ff1e6a2c4833bb77ff1e6a2c48u128);
6162

6263
let _d = 0i128.checked_div(2i128);
6364
let _d = 0u128.checked_div(2u128);

Diff for: compiler/rustc_codegen_gcc/failing-ui-tests.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ tests/ui/issues/issue-40883.rs
5454
tests/ui/issues/issue-43853.rs
5555
tests/ui/issues/issue-47364.rs
5656
tests/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs
57-
tests/ui/rfc-2091-track-caller/std-panic-locations.rs
58-
tests/ui/rfcs/rfc1857-drop-order.rs
57+
tests/ui/rfcs/rfc-2091-track-caller/std-panic-locations.rs
58+
tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs
5959
tests/ui/simd/issue-17170.rs
6060
tests/ui/simd/issue-39720.rs
6161
tests/ui/simd/issue-89193.rs
@@ -66,3 +66,5 @@ tests/ui/generator/panic-safe.rs
6666
tests/ui/issues/issue-14875.rs
6767
tests/ui/issues/issue-29948.rs
6868
tests/ui/panic-while-printing.rs
69+
tests/ui/enum-discriminant/get_discr.rs
70+
tests/ui/panics/nested_panic_caught.rs

Diff for: compiler/rustc_codegen_gcc/patches/0023-core-Ignore-failing-tests.patch

-49
This file was deleted.

Diff for: compiler/rustc_codegen_gcc/rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-03-02"
2+
channel = "nightly-2023-06-19"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

Diff for: compiler/rustc_codegen_gcc/src/asm.rs

-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
518518
OperandValue::Immediate(op.tmp_var.to_rvalue()).store(self, place);
519519
}
520520
}
521-
522521
}
523522
}
524523

Diff for: compiler/rustc_codegen_gcc/src/attributes.rs

+39
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
use gccjit::FnAttribute;
33
use gccjit::Function;
44
use rustc_attr::InstructionSetAttr;
5+
#[cfg(feature="master")]
6+
use rustc_attr::InlineAttr;
57
use rustc_codegen_ssa::target_features::tied_target_features;
68
use rustc_data_structures::fx::FxHashMap;
79
use rustc_middle::ty;
10+
#[cfg(feature="master")]
11+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
812
use rustc_session::Session;
913
use rustc_span::symbol::sym;
1014
use smallvec::{smallvec, SmallVec};
@@ -67,6 +71,24 @@ fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
6771
}
6872
}
6973

74+
/// Get GCC attribute for the provided inline heuristic.
75+
#[cfg(feature="master")]
76+
#[inline]
77+
fn inline_attr<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, inline: InlineAttr) -> Option<FnAttribute<'gcc>> {
78+
match inline {
79+
InlineAttr::Hint => Some(FnAttribute::Inline),
80+
InlineAttr::Always => Some(FnAttribute::AlwaysInline),
81+
InlineAttr::Never => {
82+
if cx.sess().target.arch != "amdgpu" {
83+
Some(FnAttribute::NoInline)
84+
} else {
85+
None
86+
}
87+
}
88+
InlineAttr::None => None,
89+
}
90+
}
91+
7092
/// Composite function which sets GCC attributes for function depending on its AST (`#[attribute]`)
7193
/// attributes.
7294
pub fn from_fn_attrs<'gcc, 'tcx>(
@@ -77,6 +99,23 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
7799
) {
78100
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
79101

102+
#[cfg(feature="master")]
103+
{
104+
let inline =
105+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
106+
InlineAttr::Never
107+
}
108+
else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
109+
InlineAttr::Hint
110+
}
111+
else {
112+
codegen_fn_attrs.inline
113+
};
114+
if let Some(attr) = inline_attr(cx, inline) {
115+
func.add_attribute(attr);
116+
}
117+
}
118+
80119
let function_features =
81120
codegen_fn_attrs.target_features.iter().map(|features| features.as_str()).collect::<Vec<&str>>();
82121

0 commit comments

Comments
 (0)