Skip to content

Commit c1d075a

Browse files
committed
Auto merge of #94545 - ehuss:beta-backports, r=ehuss
[beta] Beta backports * No branch protection metadata unless enabled #93516 * update auto trait lint for PhantomData #94315 * Cargo: * [1.60] Fix term.verbose without quiet, and vice versa (rust-lang/cargo#10436) * [beta] Add common profile validation. (rust-lang/cargo#10413) * Avoid new deprecation warnings from clap 3.1.0 (rust-lang/cargo#10396)
2 parents 0a4f984 + 7eda329 commit c1d075a

File tree

13 files changed

+125
-72
lines changed

13 files changed

+125
-72
lines changed

Cargo.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ dependencies = [
327327
"cargo-test-macro",
328328
"cargo-test-support",
329329
"cargo-util",
330-
"clap 3.0.13",
330+
"clap 3.1.5",
331331
"crates-io",
332332
"crossbeam-utils",
333333
"curl",
@@ -606,17 +606,17 @@ dependencies = [
606606

607607
[[package]]
608608
name = "clap"
609-
version = "3.0.13"
609+
version = "3.1.5"
610610
source = "registry+https://github.com/rust-lang/crates.io-index"
611-
checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e"
611+
checksum = "ced1892c55c910c1219e98d6fc8d71f6bddba7905866ce740066d8bfea859312"
612612
dependencies = [
613613
"atty",
614614
"bitflags",
615615
"indexmap",
616616
"os_str_bytes",
617617
"strsim 0.10.0",
618618
"termcolor",
619-
"textwrap 0.14.2",
619+
"textwrap 0.15.0",
620620
]
621621

622622
[[package]]
@@ -5032,9 +5032,9 @@ dependencies = [
50325032

50335033
[[package]]
50345034
name = "textwrap"
5035-
version = "0.14.2"
5035+
version = "0.15.0"
50365036
source = "registry+https://github.com/rust-lang/crates.io-index"
5037-
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
5037+
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
50385038

50395039
[[package]]
50405040
name = "thiserror"

compiler/rustc_codegen_llvm/src/context.rs

+30-30
Original file line numberDiff line numberDiff line change
@@ -269,36 +269,36 @@ pub unsafe fn create_module<'ll>(
269269
}
270270
}
271271

272-
if sess.target.arch == "aarch64" {
273-
let BranchProtection { bti, pac_ret: pac } = sess.opts.debugging_opts.branch_protection;
274-
275-
llvm::LLVMRustAddModuleFlag(
276-
llmod,
277-
llvm::LLVMModFlagBehavior::Error,
278-
"branch-target-enforcement\0".as_ptr().cast(),
279-
bti.into(),
280-
);
281-
282-
llvm::LLVMRustAddModuleFlag(
283-
llmod,
284-
llvm::LLVMModFlagBehavior::Error,
285-
"sign-return-address\0".as_ptr().cast(),
286-
pac.is_some().into(),
287-
);
288-
let pac_opts = pac.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
289-
llvm::LLVMRustAddModuleFlag(
290-
llmod,
291-
llvm::LLVMModFlagBehavior::Error,
292-
"sign-return-address-all\0".as_ptr().cast(),
293-
pac_opts.leaf.into(),
294-
);
295-
let is_bkey: bool = pac_opts.key != PAuthKey::A;
296-
llvm::LLVMRustAddModuleFlag(
297-
llmod,
298-
llvm::LLVMModFlagBehavior::Error,
299-
"sign-return-address-with-bkey\0".as_ptr().cast(),
300-
is_bkey.into(),
301-
);
272+
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.debugging_opts.branch_protection {
273+
if sess.target.arch != "aarch64" {
274+
sess.err("-Zbranch-protection is only supported on aarch64");
275+
} else {
276+
llvm::LLVMRustAddModuleFlag(
277+
llmod,
278+
llvm::LLVMModFlagBehavior::Error,
279+
"branch-target-enforcement\0".as_ptr().cast(),
280+
bti.into(),
281+
);
282+
llvm::LLVMRustAddModuleFlag(
283+
llmod,
284+
llvm::LLVMModFlagBehavior::Error,
285+
"sign-return-address\0".as_ptr().cast(),
286+
pac_ret.is_some().into(),
287+
);
288+
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
289+
llvm::LLVMRustAddModuleFlag(
290+
llmod,
291+
llvm::LLVMModFlagBehavior::Error,
292+
"sign-return-address-all\0".as_ptr().cast(),
293+
pac_opts.leaf.into(),
294+
);
295+
llvm::LLVMRustAddModuleFlag(
296+
llmod,
297+
llvm::LLVMModFlagBehavior::Error,
298+
"sign-return-address-with-bkey\0".as_ptr().cast(),
299+
u32::from(pac_opts.key == PAuthKey::B),
300+
);
301+
}
302302
}
303303

304304
// Pass on the control-flow protection flags to LLVM (equivalent to `-fcf-protection` in Clang).

compiler/rustc_interface/src/tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,10 @@ fn test_debugging_options_tracking_hash() {
721721
tracked!(binary_dep_depinfo, true);
722722
tracked!(
723723
branch_protection,
724-
BranchProtection { bti: true, pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B }) }
724+
Some(BranchProtection {
725+
bti: true,
726+
pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B })
727+
})
725728
);
726729
tracked!(chalk, true);
727730
tracked!(codegen_backend, Some("abc".to_string()));

compiler/rustc_session/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![feature(derive_default_enum)]
33
#![feature(min_specialization)]
44
#![feature(once_cell)]
5+
#![feature(option_get_or_insert_default)]
56
#![recursion_limit = "256"]
67
#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
78

compiler/rustc_session/src/options.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,10 @@ mod parse {
984984
true
985985
}
986986

987-
crate fn parse_branch_protection(slot: &mut BranchProtection, v: Option<&str>) -> bool {
987+
crate fn parse_branch_protection(slot: &mut Option<BranchProtection>, v: Option<&str>) -> bool {
988988
match v {
989989
Some(s) => {
990+
let slot = slot.get_or_insert_default();
990991
for opt in s.split(',') {
991992
match opt {
992993
"bti" => slot.bti = true,
@@ -1161,7 +1162,7 @@ options! {
11611162
(default: no)"),
11621163
borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED],
11631164
"select which borrowck is used (`mir` or `migrate`) (default: `migrate`)"),
1164-
branch_protection: BranchProtection = (BranchProtection::default(), parse_branch_protection, [TRACKED],
1165+
branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED],
11651166
"set options for branch target identification and pointer authentication on AArch64"),
11661167
cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
11671168
"instrument control-flow architecture protection"),

compiler/rustc_typeck/src/coherence/orphan.rs

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
440440
}
441441

442442
match t.kind() {
443+
ty::Adt(def, substs) if def.is_phantom_data() => substs.super_visit_with(self),
443444
ty::Adt(def, substs) => {
444445
// @lcnr: This is the only place where cycles can happen. We avoid this
445446
// by only visiting each `DefId` once.

src/test/codegen/branch-protection.rs

+29-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Test that the correct module flags are emitted with different branch protection flags.
22

3-
// revisions: bti pac-ret leaf b-key
3+
// revisions: BTI PACRET LEAF BKEY NONE
44
// min-llvm-version: 12.0.0
55
// needs-llvm-components: aarch64
6-
// [bti] compile-flags: -Z branch-protection=bti
7-
// [pac-ret] compile-flags: -Z branch-protection=pac-ret
8-
// [leaf] compile-flags: -Z branch-protection=pac-ret,leaf
9-
// [b-key] compile-flags: -Z branch-protection=pac-ret,b-key
6+
// [BTI] compile-flags: -Z branch-protection=bti
7+
// [PACRET] compile-flags: -Z branch-protection=pac-ret
8+
// [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
9+
// [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
1010
// compile-flags: --target aarch64-unknown-linux-gnu
1111

1212
#![crate_type = "lib"]
@@ -20,22 +20,27 @@ trait Sized { }
2020
pub fn test() {
2121
}
2222

23-
// bti: !"branch-target-enforcement", i32 1
24-
// bti: !"sign-return-address", i32 0
25-
// bti: !"sign-return-address-all", i32 0
26-
// bti: !"sign-return-address-with-bkey", i32 0
27-
28-
// pac-ret: !"branch-target-enforcement", i32 0
29-
// pac-ret: !"sign-return-address", i32 1
30-
// pac-ret: !"sign-return-address-all", i32 0
31-
// pac-ret: !"sign-return-address-with-bkey", i32 0
32-
33-
// leaf: !"branch-target-enforcement", i32 0
34-
// leaf: !"sign-return-address", i32 1
35-
// leaf: !"sign-return-address-all", i32 1
36-
// leaf: !"sign-return-address-with-bkey", i32 0
37-
38-
// b-key: !"branch-target-enforcement", i32 0
39-
// b-key: !"sign-return-address", i32 1
40-
// b-key: !"sign-return-address-all", i32 0
41-
// b-key: !"sign-return-address-with-bkey", i32 1
23+
// BTI: !"branch-target-enforcement", i32 1
24+
// BTI: !"sign-return-address", i32 0
25+
// BTI: !"sign-return-address-all", i32 0
26+
// BTI: !"sign-return-address-with-bkey", i32 0
27+
28+
// PACRET: !"branch-target-enforcement", i32 0
29+
// PACRET: !"sign-return-address", i32 1
30+
// PACRET: !"sign-return-address-all", i32 0
31+
// PACRET: !"sign-return-address-with-bkey", i32 0
32+
33+
// LEAF: !"branch-target-enforcement", i32 0
34+
// LEAF: !"sign-return-address", i32 1
35+
// LEAF: !"sign-return-address-all", i32 1
36+
// LEAF: !"sign-return-address-with-bkey", i32 0
37+
38+
// BKEY: !"branch-target-enforcement", i32 0
39+
// BKEY: !"sign-return-address", i32 1
40+
// BKEY: !"sign-return-address-all", i32 0
41+
// BKEY: !"sign-return-address-with-bkey", i32 1
42+
43+
// NONE-NOT: branch-target-enforcement
44+
// NONE-NOT: sign-return-address
45+
// NONE-NOT: sign-return-address-all
46+
// NONE-NOT: sign-return-address-with-bkey

src/test/ui/auto-traits/suspicious-impls-lint.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(suspicious_auto_trait_impls)]
22

3+
use std::marker::PhantomData;
4+
35
struct MayImplementSendOk<T>(T);
46
unsafe impl<T: Send> Send for MayImplementSendOk<T> {} // ok
57

@@ -31,4 +33,12 @@ unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
3133
//~^ ERROR
3234
//~| WARNING this will change its meaning
3335

36+
pub struct WithPhantomDataNonSend<T, U>(PhantomData<*const T>, U);
37+
unsafe impl<T> Send for WithPhantomDataNonSend<T, i8> {} // ok
38+
39+
pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
40+
unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
41+
//~^ ERROR
42+
//~| WARNING this will change its meaning
43+
3444
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cross-crate traits with a default impl, like `Send`, should not be specialized
2-
--> $DIR/suspicious-impls-lint.rs:7:1
2+
--> $DIR/suspicious-impls-lint.rs:9:1
33
|
44
LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,41 +12,56 @@ LL | #![deny(suspicious_auto_trait_impls)]
1212
= warning: this will change its meaning in a future release!
1313
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
1414
note: try using the same sequence of generic parameters as the struct definition
15-
--> $DIR/suspicious-impls-lint.rs:6:1
15+
--> $DIR/suspicious-impls-lint.rs:8:1
1616
|
1717
LL | struct MayImplementSendErr<T>(T);
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
= note: `&T` is not a generic parameter
2020

2121
error: cross-crate traits with a default impl, like `Send`, should not be specialized
22-
--> $DIR/suspicious-impls-lint.rs:19:1
22+
--> $DIR/suspicious-impls-lint.rs:21:1
2323
|
2424
LL | unsafe impl Send for ContainsVec<i32> {}
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
|
2727
= warning: this will change its meaning in a future release!
2828
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
2929
note: try using the same sequence of generic parameters as the struct definition
30-
--> $DIR/suspicious-impls-lint.rs:18:1
30+
--> $DIR/suspicious-impls-lint.rs:20:1
3131
|
3232
LL | struct ContainsVec<T>(Vec<T>);
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= note: `i32` is not a generic parameter
3535

3636
error: cross-crate traits with a default impl, like `Send`, should not be specialized
37-
--> $DIR/suspicious-impls-lint.rs:30:1
37+
--> $DIR/suspicious-impls-lint.rs:32:1
3838
|
3939
LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4141
|
4242
= warning: this will change its meaning in a future release!
4343
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
4444
note: try using the same sequence of generic parameters as the struct definition
45-
--> $DIR/suspicious-impls-lint.rs:29:1
45+
--> $DIR/suspicious-impls-lint.rs:31:1
4646
|
4747
LL | struct TwoParamsSame<T, U>(T, U);
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4949
= note: `T` is mentioned multiple times
5050

51-
error: aborting due to 3 previous errors
51+
error: cross-crate traits with a default impl, like `Send`, should not be specialized
52+
--> $DIR/suspicious-impls-lint.rs:40:1
53+
|
54+
LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
|
57+
= warning: this will change its meaning in a future release!
58+
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
59+
note: try using the same sequence of generic parameters as the struct definition
60+
--> $DIR/suspicious-impls-lint.rs:39:1
61+
|
62+
LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
63+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64+
= note: `*const T` is not a generic parameter
65+
66+
error: aborting due to 4 previous errors
5267

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: -Zbranch-protection is only supported on aarch64
2+
3+
error: aborting due to previous error
4+
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
// compile-flags: -Z branch-protection=leaf
1+
// revisions: BADFLAGS BADTARGET
2+
// [BADFLAGS] compile-flags: --target=aarch64-unknown-linux-gnu -Zbranch-protection=leaf
3+
// [BADFLAGS] check-fail
4+
// [BADFLAGS] needs-llvm-components: aarch64
5+
// [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti
6+
// [BADTARGET] build-fail
7+
// [BADTARGET] needs-llvm-components: x86
8+
9+
#![crate_type = "lib"]
10+
#![feature(no_core, lang_items)]
11+
#![no_core]
12+
13+
#[lang="sized"]
14+
trait Sized { }

0 commit comments

Comments
 (0)