Skip to content

Commit

Permalink
Auto merge of rust-lang#127513 - nikic:llvm-19, r=<try>
Browse files Browse the repository at this point in the history
Update to LLVM 19

Related changes:
 * rust-lang#127605
 * rust-lang#127613
 * rust-lang#127654
 * rust-lang#128141
 * llvm/llvm-project#98933

try-job: dist-x86_64-apple
try-job: dist-apple-various
try-job: x86_64-apple-1
try-job: x86_64-apple-2
try-job: dist-aarch64-apple
try-job: aarch64-apple
  • Loading branch information
bors committed Jul 25, 2024
2 parents 004e155 + fe8592d commit 0e4626e
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
shallow = true
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/18.1-2024-05-19
url = https://github.com/nikic/llvm-project.git
branch = rust-llvm-19
shallow = true
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
Expand Down
31 changes: 28 additions & 3 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_codegen_ssa::traits::*;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFunctionEntry};
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::config::{FunctionReturn, OptLevel};
use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey, PacRet};
use rustc_span::symbol::sym;
use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtector};
use smallvec::SmallVec;
Expand Down Expand Up @@ -407,8 +407,33 @@ pub fn from_fn_attrs<'ll, 'tcx>(
// And it is a module-level attribute, so the alternative is pulling naked functions into new LLVM modules.
// Otherwise LLVM's "naked" functions come with endbr prefixes per https://github.com/rust-lang/rust/issues/98768
to_add.push(AttributeKind::NoCfCheck.create_attr(cx.llcx));
// Need this for AArch64.
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
if llvm_util::get_version() < (19, 0, 0) {
// Prior to LLVM 19, branch-target-enforcement was disabled by setting the attribute to
// the string "false". Now it is disabled by absence of the attribute.
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
}
} else if llvm_util::get_version() >= (19, 0, 0) {
// For non-naked functions, set branch protection attributes on aarch64.
if let Some(BranchProtection { bti, pac_ret }) =
cx.sess().opts.unstable_opts.branch_protection
{
assert!(cx.sess().target.arch == "aarch64");
if bti {
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
}
if let Some(PacRet { leaf, key }) = pac_ret {
to_add.push(llvm::CreateAttrStringValue(
cx.llcx,
"sign-return-address",
if leaf { "all" } else { "non-leaf" },
));
to_add.push(llvm::CreateAttrStringValue(
cx.llcx,
"sign-return-address-key",
if key == PAuthKey::A { "a_key" } else { "b_key" },
));
}
}
}
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR)
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR_ZEROED)
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,11 +1557,12 @@ LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {

extern "C" LLVMValueRef
LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
#if LLVM_VERSION_GE(18, 0)
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
return wrap(llvm::Intrinsic::getDeclaration(
unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
#else
report_fatal_error("LLVM 18.0 is required for mcdc intrinsic functions");
report_fatal_error(
"The instrprof_mcdc_condbitmap_update only exists in LLVM 18");
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
45 changes: 45 additions & 0 deletions tests/codegen/branch-protection-old-llvm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Test that the correct module flags are emitted with different branch protection flags.

//@ revisions: BTI PACRET LEAF BKEY NONE
//@ needs-llvm-components: aarch64
//@ [BTI] compile-flags: -Z branch-protection=bti
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret
//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ ignore-llvm-version: 19 - 99

#![crate_type = "lib"]
#![feature(no_core, lang_items)]
#![no_core]

#[lang = "sized"]
trait Sized {}

// A basic test function.
pub fn test() {}

// BTI: !"branch-target-enforcement", i32 1
// BTI: !"sign-return-address", i32 0
// BTI: !"sign-return-address-all", i32 0
// BTI: !"sign-return-address-with-bkey", i32 0

// PACRET: !"branch-target-enforcement", i32 0
// PACRET: !"sign-return-address", i32 1
// PACRET: !"sign-return-address-all", i32 0
// PACRET: !"sign-return-address-with-bkey", i32 0

// LEAF: !"branch-target-enforcement", i32 0
// LEAF: !"sign-return-address", i32 1
// LEAF: !"sign-return-address-all", i32 1
// LEAF: !"sign-return-address-with-bkey", i32 0

// BKEY: !"branch-target-enforcement", i32 0
// BKEY: !"sign-return-address", i32 1
// BKEY: !"sign-return-address-all", i32 0
// BKEY: !"sign-return-address-with-bkey", i32 1

// NONE-NOT: branch-target-enforcement
// NONE-NOT: sign-return-address
// NONE-NOT: sign-return-address-all
// NONE-NOT: sign-return-address-with-bkey
10 changes: 10 additions & 0 deletions tests/codegen/branch-protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ min-llvm-version: 19

#![crate_type = "lib"]
#![feature(no_core, lang_items)]
Expand All @@ -16,23 +17,32 @@
trait Sized {}

// A basic test function.
// CHECK: @test(){{.*}} [[ATTR:#[0-9]+]] {
#[no_mangle]
pub fn test() {}

// BTI: attributes [[ATTR]] = {{.*}} "branch-target-enforcement"
// BTI: !"branch-target-enforcement", i32 1
// BTI: !"sign-return-address", i32 0
// BTI: !"sign-return-address-all", i32 0
// BTI: !"sign-return-address-with-bkey", i32 0

// PACRET: attributes [[ATTR]] = {{.*}} "sign-return-address"="non-leaf"
// PACRET-SAME: "sign-return-address-key"="a_key"
// PACRET: !"branch-target-enforcement", i32 0
// PACRET: !"sign-return-address", i32 1
// PACRET: !"sign-return-address-all", i32 0
// PACRET: !"sign-return-address-with-bkey", i32 0

// LEAF: attributes [[ATTR]] = {{.*}} "sign-return-address"="all"
// LEAF-SAME: "sign-return-address-key"="a_key"
// LEAF: !"branch-target-enforcement", i32 0
// LEAF: !"sign-return-address", i32 1
// LEAF: !"sign-return-address-all", i32 1
// LEAF: !"sign-return-address-with-bkey", i32 0

// BKEY: attributes [[ATTR]] = {{.*}} "sign-return-address"="non-leaf"
// BKEY-SAME: "sign-return-address-key"="b_key"
// BKEY: !"branch-target-enforcement", i32 0
// BKEY: !"sign-return-address", i32 1
// BKEY: !"sign-return-address-all", i32 0
Expand Down
1 change: 1 addition & 0 deletions tests/coverage/mcdc/condition-limit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ min-llvm-version: 18
//@ ignore-llvm-version: 19 - 99
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
1 change: 1 addition & 0 deletions tests/coverage/mcdc/if.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ min-llvm-version: 18
//@ ignore-llvm-version: 19 - 99
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
1 change: 1 addition & 0 deletions tests/coverage/mcdc/inlined_expressions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ min-llvm-version: 18
//@ ignore-llvm-version: 19 - 99
//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
1 change: 1 addition & 0 deletions tests/coverage/mcdc/nested_if.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ min-llvm-version: 18
//@ ignore-llvm-version: 19 - 99
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
1 change: 1 addition & 0 deletions tests/coverage/mcdc/non_control_flow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ min-llvm-version: 18
//@ ignore-llvm-version: 19 - 99
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
6 changes: 4 additions & 2 deletions tests/crashes/121444.rs → tests/ui/abi/large-byval-align.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//@ known-bug: #121444
//@ compile-flags: -Copt-level=0
//@ edition:2021
//@ only-x86_64
//@ ignore-windows
//@ min-llvm-version: 19
//@ build-pass

#[repr(align(536870912))]
pub struct A(i64);

#[allow(improper_ctypes_definitions)]
pub extern "C" fn foo(x: A) {}

fn main() {
Expand Down

0 comments on commit 0e4626e

Please sign in to comment.