Skip to content

Commit 75f8bdb

Browse files
committed
Merge commit '3270432f4b0583104c8b9b6f695bf97d6bbf3ac2' into sync_cg_clif-2024-05-13
2 parents abb9563 + 3270432 commit 75f8bdb

31 files changed

+481
-166
lines changed

Diff for: compiler/rustc_codegen_cranelift/.github/workflows/abi-cafe.yml

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ jobs:
5151
if: matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
5252
run: rustup set default-host x86_64-pc-windows-gnu
5353

54+
- name: Use x86_64 compiler on macOS
55+
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
56+
run: rustup set default-host x86_64-apple-darwin
57+
58+
- name: Select XCode version
59+
if: matrix.os == 'macos-latest'
60+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
61+
5462
- name: Prepare dependencies
5563
run: ./y.sh prepare
5664

Diff for: compiler/rustc_codegen_cranelift/.github/workflows/main.yml

+16
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,20 @@ jobs:
9898
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
9999
run: rustup set default-host x86_64-pc-windows-gnu
100100

101+
- name: Use x86_64 compiler on macOS
102+
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
103+
run: rustup set default-host x86_64-apple-darwin
104+
101105
- name: Install toolchain and emulator
102106
if: matrix.apt_deps != null
103107
run: |
104108
sudo apt-get update
105109
sudo apt-get install -y ${{ matrix.apt_deps }}
106110
111+
- name: Select XCode version
112+
if: matrix.os == 'macos-latest'
113+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
114+
107115
- name: Prepare dependencies
108116
run: ./y.sh prepare
109117

@@ -230,12 +238,20 @@ jobs:
230238
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
231239
run: rustup set default-host x86_64-pc-windows-gnu
232240

241+
- name: Use x86_64 compiler on macOS
242+
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
243+
run: rustup set default-host x86_64-apple-darwin
244+
233245
- name: Install MinGW toolchain
234246
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
235247
run: |
236248
sudo apt-get update
237249
sudo apt-get install -y gcc-mingw-w64-x86-64
238250
251+
- name: Select XCode version
252+
if: matrix.os == 'macos-latest'
253+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
254+
239255
- name: Prepare dependencies
240256
run: ./y.sh prepare
241257

Diff for: compiler/rustc_codegen_cranelift/.github/workflows/rustc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/cache@v4
2121
with:
2222
path: build/cg_clif
23-
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
23+
key: ${{ runner.os }}-rustc-test-cargo-build-target-${{ hashFiles('rust-toolchain', 'Cargo.lock') }}
2424

2525
- name: Prepare dependencies
2626
run: ./y.sh prepare
@@ -43,7 +43,7 @@ jobs:
4343
uses: actions/cache@v4
4444
with:
4545
path: build/cg_clif
46-
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
46+
key: ${{ runner.os }}-rustc-test-cargo-build-target-${{ hashFiles('rust-toolchain', 'Cargo.lock') }}
4747

4848
- name: Install ripgrep
4949
run: |

Diff for: compiler/rustc_codegen_cranelift/.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
# Build artifacts during normal use
2-
/y.bin
3-
/y.bin.dSYM
4-
/y.exe
5-
/y.pdb
62
/download
73
/build
84
/dist

Diff for: compiler/rustc_codegen_cranelift/build_system/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ path = "main.rs"
1111
unstable-features = [] # for rust-analyzer
1212

1313
# Do not add any dependencies
14+
15+
[profile.dev]
16+
debug = 1

Diff for: compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,16 @@ fn build_clif_sysroot_for_triple(
267267
prefix.to_str().unwrap()
268268
));
269269
}
270+
rustflags.push("-Zunstable-options".to_owned());
271+
for (name, values) in EXTRA_CHECK_CFGS {
272+
rustflags.push(check_cfg_arg(name, *values));
273+
}
270274
compiler.rustflags.extend(rustflags);
271275
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
272276
if channel == "release" {
273277
build_cmd.arg("--release");
274278
}
275-
build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind");
279+
build_cmd.arg("--features").arg("backtrace panic-unwind");
276280
build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
277281
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
278282
if compiler.triple.contains("apple") {
@@ -326,3 +330,34 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
326330

327331
Some(target_libs)
328332
}
333+
334+
// Copied from https://github.com/rust-lang/rust/blob/4fd98a4b1b100f5329c6efae18031791f64372d2/src/bootstrap/src/utils/helpers.rs#L569-L585
335+
/// Create a `--check-cfg` argument invocation for a given name
336+
/// and it's values.
337+
fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
338+
// Creating a string of the values by concatenating each value:
339+
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
340+
let next = match values {
341+
Some(values) => {
342+
let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();
343+
344+
tmp.insert_str(1, "values(");
345+
tmp.push(')');
346+
tmp
347+
}
348+
None => "".to_string(),
349+
};
350+
format!("--check-cfg=cfg({name}{next})")
351+
}
352+
353+
const EXTRA_CHECK_CFGS: &[(&str, Option<&[&str]>)] = &[
354+
("bootstrap", None),
355+
("stdarch_intel_sde", None),
356+
("no_fp_fmt_parse", None),
357+
("no_global_oom_handling", None),
358+
("no_rc", None),
359+
("no_sync", None),
360+
("netbsd10", None),
361+
("backtrace_in_libstd", None),
362+
("target_arch", Some(&["xtensa"])),
363+
];

Diff for: compiler/rustc_codegen_cranelift/build_system/main.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ fn main() {
147147

148148
let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
149149
(Ok(_), Ok(_), Ok(_)) => None,
150-
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
151-
_ => {
152-
eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set");
150+
(_, Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
151+
vars => {
152+
eprintln!(
153+
"If RUSTC or RUSTDOC is set, both need to be set and in addition CARGO needs to be set: {vars:?}"
154+
);
153155
process::exit(1);
154156
}
155157
};

Diff for: compiler/rustc_codegen_cranelift/build_system/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
7777
),
7878
TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
7979
TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
80-
TestCase::jit_bin("jit.std_example", "example/std_example.rs", ""),
80+
TestCase::jit_bin("jit.std_example", "example/std_example.rs", "arg"),
8181
TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
8282
TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
8383
TestCase::build_bin_and_run(

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

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
never_type,
55
linkage,
66
extern_types,
7+
naked_functions,
78
thread_local,
89
repr_simd,
910
raw_ref_op
@@ -340,6 +341,7 @@ fn main() {
340341
))]
341342
unsafe {
342343
global_asm_test();
344+
naked_test();
343345
}
344346

345347
// Both statics have a reference that points to the same anonymous allocation.
@@ -395,6 +397,14 @@ global_asm! {
395397
"
396398
}
397399

400+
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64"))]
401+
#[naked]
402+
extern "C" fn naked_test() {
403+
unsafe {
404+
asm!("ret", options(noreturn));
405+
}
406+
}
407+
398408
#[repr(C)]
399409
enum c_void {
400410
_1,

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

+29
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ struct I64X2(i64, i64);
210210
#[allow(improper_ctypes_definitions)]
211211
extern "C" fn foo(_a: I64X2) {}
212212

213+
#[cfg(target_arch = "x86_64")]
214+
#[target_feature(enable = "sse4.2")]
215+
#[cfg(not(jit))]
216+
unsafe fn test_crc32() {
217+
assert!(is_x86_feature_detected!("sse4.2"));
218+
219+
let a = 42u32;
220+
let b = 0xdeadbeefu64;
221+
222+
assert_eq!(_mm_crc32_u8(a, b as u8), 4135334616);
223+
assert_eq!(_mm_crc32_u16(a, b as u16), 1200687288);
224+
assert_eq!(_mm_crc32_u32(a, b as u32), 2543798776);
225+
assert_eq!(_mm_crc32_u64(a as u64, b as u64), 241952147);
226+
}
227+
213228
#[cfg(target_arch = "x86_64")]
214229
#[target_feature(enable = "sse2")]
215230
unsafe fn test_simd() {
@@ -244,10 +259,14 @@ unsafe fn test_simd() {
244259

245260
test_mm256_shuffle_epi8();
246261
test_mm256_permute2x128_si256();
262+
test_mm256_permutevar8x32_epi32();
247263

248264
#[rustfmt::skip]
249265
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
250266
assert_eq!(mask1, 1);
267+
268+
#[cfg(not(jit))]
269+
test_crc32();
251270
}
252271

253272
#[cfg(target_arch = "x86_64")]
@@ -447,6 +466,16 @@ unsafe fn test_mm256_permute2x128_si256() {
447466
assert_eq_m256i(r, e);
448467
}
449468

469+
#[cfg(target_arch = "x86_64")]
470+
#[target_feature(enable = "avx2")]
471+
unsafe fn test_mm256_permutevar8x32_epi32() {
472+
let a = _mm256_setr_epi32(100, 200, 300, 400, 500, 600, 700, 800);
473+
let idx = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0);
474+
let r = _mm256_setr_epi32(800, 700, 600, 500, 400, 300, 200, 100);
475+
let e = _mm256_permutevar8x32_epi32(a, idx);
476+
assert_eq_m256i(r, e);
477+
}
478+
450479
fn test_checked_mul() {
451480
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
452481
assert_eq!(u, None);

Diff for: compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
4242

4343
[[package]]
4444
name = "cc"
45-
version = "1.0.90"
45+
version = "1.0.97"
4646
source = "registry+https://github.com/rust-lang/crates.io-index"
47-
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
47+
checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
4848

4949
[[package]]
5050
name = "cfg-if"

Diff for: compiler/rustc_codegen_cranelift/rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-04-23"
2+
channel = "nightly-2024-05-13"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

Diff for: compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ rm tests/incremental/hashes/statics.rs # same
4444
rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs
4545
rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support
4646
rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support
47+
rm tests/ui/delegation/fn-header.rs
4748

4849
# unsized locals
4950
rm -r tests/run-pass-valgrind/unsized-locals
@@ -87,6 +88,7 @@ rm -r tests/run-make/no-builtins-attribute # same
8788
rm tests/ui/abi/stack-protector.rs # requires stack protector support
8889
rm -r tests/run-make/emit-stack-sizes # requires support for -Z emit-stack-sizes
8990
rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific
91+
rm -r tests/run-make/print-to-output # requires --print relocation-models
9092

9193
# requires asm, llvm-ir and/or llvm-bc emit support
9294
# =============================================
@@ -151,7 +153,7 @@ index 9607ff02f96..b7d97caf9a2 100644
151153
let mut cmd = setup_common();
152154
- let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
153155
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
154-
Self { cmd }
156+
Self { cmd, stdin: None }
155157
}
156158
157159
EOF

Diff for: compiler/rustc_codegen_cranelift/src/abi/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
412412
Err(instance) => Some(instance),
413413
}
414414
}
415-
InstanceDef::DropGlue(_, None) => {
415+
InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) => {
416416
// empty drop glue - a nop.
417417
let dest = target.expect("Non terminating drop_in_place_real???");
418418
let ret_block = fx.get_block(dest);
@@ -597,7 +597,9 @@ pub(crate) fn codegen_drop<'tcx>(
597597
let ty = drop_place.layout().ty;
598598
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
599599

600-
if let ty::InstanceDef::DropGlue(_, None) = drop_instance.def {
600+
if let ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) =
601+
drop_instance.def
602+
{
601603
// we don't actually need to drop anything
602604
} else {
603605
match ty.kind() {

Diff for: compiler/rustc_codegen_cranelift/src/base.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
66
use cranelift_module::ModuleError;
77
use rustc_ast::InlineAsmOptions;
88
use rustc_index::IndexVec;
9+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
910
use rustc_middle::ty::adjustment::PointerCoercion;
1011
use rustc_middle::ty::layout::FnAbiOf;
1112
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -14,6 +15,7 @@ use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphizat
1415

1516
use crate::constant::ConstantCx;
1617
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
18+
use crate::inline_asm::codegen_naked_asm;
1719
use crate::prelude::*;
1820
use crate::pretty_clif::CommentWriter;
1921

@@ -32,7 +34,7 @@ pub(crate) fn codegen_fn<'tcx>(
3234
cached_func: Function,
3335
module: &mut dyn Module,
3436
instance: Instance<'tcx>,
35-
) -> CodegenedFunction {
37+
) -> Option<CodegenedFunction> {
3638
debug_assert!(!instance.args.has_infer());
3739

3840
let symbol_name = tcx.symbol_name(instance).name.to_string();
@@ -48,6 +50,37 @@ pub(crate) fn codegen_fn<'tcx>(
4850
String::from_utf8_lossy(&buf).into_owned()
4951
});
5052

53+
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
54+
assert_eq!(mir.basic_blocks.len(), 1);
55+
assert!(mir.basic_blocks[START_BLOCK].statements.is_empty());
56+
57+
match &mir.basic_blocks[START_BLOCK].terminator().kind {
58+
TerminatorKind::InlineAsm {
59+
template,
60+
operands,
61+
options,
62+
line_spans: _,
63+
targets: _,
64+
unwind: _,
65+
} => {
66+
codegen_naked_asm(
67+
tcx,
68+
cx,
69+
module,
70+
instance,
71+
mir.basic_blocks[START_BLOCK].terminator().source_info.span,
72+
&symbol_name,
73+
template,
74+
operands,
75+
*options,
76+
);
77+
}
78+
_ => unreachable!(),
79+
}
80+
81+
return None;
82+
}
83+
5184
// Declare function
5285
let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance);
5386
let func_id = module.declare_function(&symbol_name, Linkage::Local, &sig).unwrap();
@@ -128,7 +161,7 @@ pub(crate) fn codegen_fn<'tcx>(
128161
// Verify function
129162
verify_func(tcx, &clif_comments, &func);
130163

131-
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
164+
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
132165
}
133166

134167
pub(crate) fn compile_fn(

0 commit comments

Comments
 (0)