Skip to content

Commit cd80bb6

Browse files
Auto merge of #143684 - nikic:llvm-21, r=<try>
Update to LLVM 21 Depends on: * [x] llvm/llvm-project#147781 * [x] llvm/llvm-project#147935 * [x] llvm/llvm-project#139443 * [x] llvm/llvm-project#148207 * [x] llvm/llvm-project#148607 r? `@ghost`
2 parents e27f16a + b0b9a3c commit cd80bb6

File tree

10 files changed

+31
-9
lines changed

10 files changed

+31
-9
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
shallow = true
2525
[submodule "src/llvm-project"]
2626
path = src/llvm-project
27-
url = https://github.com/rust-lang/llvm-project.git
28-
branch = rustc/20.1-2025-07-13
27+
url = https://github.com/nikic/llvm-project.git
28+
branch = rust-llvm-21
2929
shallow = true
3030
[submodule "src/doc/embedded-book"]
3131
path = src/doc/embedded-book

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl OwnedTargetMachine {
3939
debug_info_compression: &CStr,
4040
use_emulated_tls: bool,
4141
args_cstr_buff: &[u8],
42+
use_wasm_eh: bool,
4243
) -> Result<Self, LlvmError<'static>> {
4344
assert!(args_cstr_buff.len() > 0);
4445
assert!(
@@ -72,6 +73,7 @@ impl OwnedTargetMachine {
7273
use_emulated_tls,
7374
args_cstr_buff.as_ptr() as *const c_char,
7475
args_cstr_buff.len(),
76+
use_wasm_eh,
7577
)
7678
};
7779

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_codegen_ssa::back::write::{
1515
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
1616
TargetMachineFactoryFn,
1717
};
18+
use rustc_codegen_ssa::base::wants_wasm_eh;
1819
use rustc_codegen_ssa::traits::*;
1920
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, ModuleKind};
2021
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -285,6 +286,8 @@ pub(crate) fn target_machine_factory(
285286
let file_name_display_preference =
286287
sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
287288

289+
let use_wasm_eh = wants_wasm_eh(sess);
290+
288291
Arc::new(move |config: TargetMachineFactoryConfig| {
289292
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
290293
let path = path.unwrap_or_default();
@@ -321,6 +324,7 @@ pub(crate) fn target_machine_factory(
321324
&debuginfo_compression,
322325
use_emulated_tls,
323326
&args_cstr_buff,
327+
use_wasm_eh,
324328
)
325329
})
326330
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ pub(crate) unsafe fn create_module<'ll>(
206206
// LLVM 21 updated the default layout on nvptx: https://github.com/llvm/llvm-project/pull/124961
207207
target_data_layout = target_data_layout.replace("e-p6:32:32-i64", "e-i64");
208208
}
209+
if sess.target.arch == "amdgpu" {
210+
// LLVM 21 adds the address width for address space 8.
211+
// See https://github.com/llvm/llvm-project/pull/139419
212+
target_data_layout = target_data_layout.replace("p8:128:128:128:48", "p8:128:128")
213+
}
209214
}
210215

211216
// Ensure the data-layout values hardcoded remain the defaults.

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ unsafe extern "C" {
24252425
UseEmulatedTls: bool,
24262426
ArgsCstrBuff: *const c_char,
24272427
ArgsCstrBuffLen: usize,
2428+
UseWasmEH: bool,
24282429
) -> *mut TargetMachine;
24292430

24302431
pub(crate) fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine);

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
396396
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
397397
const char *SplitDwarfFile, const char *OutputObjFile,
398398
const char *DebugInfoCompression, bool UseEmulatedTls,
399-
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen) {
399+
const char *ArgsCstrBuff, size_t ArgsCstrBuffLen, bool UseWasmEH) {
400400

401401
auto OptLevel = fromRust(RustOptLevel);
402402
auto RM = fromRust(RustReloc);
@@ -462,6 +462,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
462462
Options.ThreadModel = ThreadModel::Single;
463463
}
464464

465+
if (UseWasmEH)
466+
Options.ExceptionModel = ExceptionHandling::Wasm;
467+
465468
Options.EmitStackSizeSection = EmitStackSizeSection;
466469

467470
if (ArgsCstrBuff != nullptr) {

compiler/rustc_target/src/spec/targets/amdgcn_amd_amdhsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, Target, TargetMetadata,
33
pub(crate) fn target() -> Target {
44
Target {
55
arch: "amdgpu".into(),
6-
data_layout: "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9".into(),
6+
data_layout: "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9".into(),
77
llvm_target: "amdgcn-amd-amdhsa".into(),
88
metadata: TargetMetadata {
99
description: Some("AMD GPU".into()),

src/llvm-project

tests/assembly/sanitizer/kcfi/emit-arity-indicator.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
//@ min-llvm-version: 21.0.0
99

1010
#![crate_type = "lib"]
11+
#![feature(no_core)]
12+
#![no_core]
13+
14+
extern crate minicore;
15+
16+
unsafe extern "C" {
17+
safe fn add(x: i32, y: i32) -> i32;
18+
}
1119

1220
pub fn add_one(x: i32) -> i32 {
1321
// CHECK-LABEL: __cfi__{{.*}}7add_one{{.*}}:
@@ -23,7 +31,7 @@ pub fn add_one(x: i32) -> i32 {
2331
// CHECK-NEXT: nop
2432
// CHECK-NEXT: nop
2533
// CHECK-NEXT: mov ecx, 2628068948
26-
x + 1
34+
add(x, 1)
2735
}
2836

2937
pub fn add_two(x: i32, _y: i32) -> i32 {
@@ -40,7 +48,7 @@ pub fn add_two(x: i32, _y: i32) -> i32 {
4048
// CHECK-NEXT: nop
4149
// CHECK-NEXT: nop
4250
// CHECK-NEXT: mov edx, 2505940310
43-
x + 2
51+
add(x, 2)
4452
}
4553

4654
pub fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
@@ -57,5 +65,5 @@ pub fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
5765
// CHECK-NEXT: nop
5866
// CHECK-NEXT: nop
5967
// CHECK-NEXT: mov edx, 653723426
60-
f(arg) + f(arg)
68+
add(f(arg), f(arg))
6169
}

tests/assembly/wasm_exceptions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ assembly-output: emit-asm
33
//@ compile-flags: -C target-feature=+exception-handling
44
//@ compile-flags: -C panic=unwind
5-
//@ compile-flags: -C llvm-args=-wasm-enable-eh
65

76
#![crate_type = "lib"]
87
#![feature(core_intrinsics)]

0 commit comments

Comments
 (0)