about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-12-26 13:29:13 -0500
committerGitHub <noreply@github.com>2023-12-26 13:29:13 -0500
commit50e380c8f3e8bad3c6327895a2af8a99b378030b (patch)
tree4bb7cf4538b8dd5ecfbb42855022b50b04c3695f
parente1fadb2c35a6082867a037f012bfdfc5eb686211 (diff)
parentc88b021782aff93102c8d449829a30210d67b2ab (diff)
downloadrust-50e380c8f3e8bad3c6327895a2af8a99b378030b.tar.gz
rust-50e380c8f3e8bad3c6327895a2af8a99b378030b.zip
Rollup merge of #119235 - Urgau:missing-feature-gate-sanitizer-cfi-cfgs, r=Nilstrieb
Add missing feature gate for sanitizer CFI cfgs

Found during the review of https://github.com/rust-lang/rust/pull/118494 in https://github.com/rust-lang/rust/pull/118494#discussion_r1416079288.

cc `@rcvalle`
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs2
-rw-r--r--compiler/rustc_feature/src/unstable.rs2
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--library/std/src/lib.rs1
-rw-r--r--library/std/src/sys/unix/thread_local_dtor.rs2
-rw-r--r--tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.rs9
-rw-r--r--tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.stderr21
-rw-r--r--tests/ui/sanitize/sanitizer-cfi-generalize-pointers-attr-cfg.rs2
-rw-r--r--tests/ui/sanitize/sanitizer-cfi-normalize-integers-attr-cfg.rs2
9 files changed, 41 insertions, 1 deletions
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index 5523543cd4f..4442b67df6e 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -36,6 +36,8 @@ const GATED_CFGS: &[GatedCfg] = &[
     (sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
     (sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
     (sym::relocation_model, sym::cfg_relocation_model, cfg_fn!(cfg_relocation_model)),
+    (sym::sanitizer_cfi_generalize_pointers, sym::cfg_sanitizer_cfi, cfg_fn!(cfg_sanitizer_cfi)),
+    (sym::sanitizer_cfi_normalize_integers, sym::cfg_sanitizer_cfi, cfg_fn!(cfg_sanitizer_cfi)),
 ];
 
 /// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index 60586f54fd5..763bd4fc391 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -371,6 +371,8 @@ declare_features! (
     (unstable, cfg_relocation_model, "1.73.0", Some(114929)),
     /// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
     (unstable, cfg_sanitize, "1.41.0", Some(39699)),
+    /// Allows `cfg(sanitizer_cfi_generalize_pointers)` and `cfg(sanitizer_cfi_normalize_integers)`.
+    (unstable, cfg_sanitizer_cfi, "CURRENT_RUSTC_VERSION", Some(89653)),
     /// Allows `cfg(target_abi = "...")`.
     (unstable, cfg_target_abi, "1.55.0", Some(80970)),
     /// Allows `cfg(target(abi = "..."))`.
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 95106cc64c1..0b44071496e 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -498,6 +498,7 @@ symbols! {
         cfg_panic,
         cfg_relocation_model,
         cfg_sanitize,
+        cfg_sanitizer_cfi,
         cfg_target_abi,
         cfg_target_compact,
         cfg_target_feature,
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 6365366297c..95ee6a9b29c 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -265,6 +265,7 @@
 //
 // Language features:
 // tidy-alphabetical-start
+#![cfg_attr(not(bootstrap), feature(cfg_sanitizer_cfi))]
 #![feature(alloc_error_handler)]
 #![feature(allocator_internals)]
 #![feature(allow_internal_unsafe)]
diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs
index ac85531c372..58f7ab84101 100644
--- a/library/std/src/sys/unix/thread_local_dtor.rs
+++ b/library/std/src/sys/unix/thread_local_dtor.rs
@@ -11,7 +11,7 @@
 // Note, however, that we run on lots older linuxes, as well as cross
 // compiling from a newer linux to an older linux, so we also have a
 // fallback implementation to use as well.
-#[allow(unexpected_cfgs)]
+#[cfg_attr(bootstrap, allow(unexpected_cfgs))]
 #[cfg(any(
     target_os = "linux",
     target_os = "android",
diff --git a/tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.rs b/tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.rs
new file mode 100644
index 00000000000..76d96de750a
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.rs
@@ -0,0 +1,9 @@
+#[cfg(sanitizer_cfi_generalize_pointers)]
+//~^ `cfg(sanitizer_cfi_generalize_pointers)` is experimental
+fn foo() {}
+
+#[cfg(sanitizer_cfi_normalize_integers)]
+//~^ `cfg(sanitizer_cfi_normalize_integers)` is experimental
+fn bar() {}
+
+fn main() {}
diff --git a/tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.stderr b/tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.stderr
new file mode 100644
index 00000000000..8c2a8411c7b
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-cfg-sanitizer_cfi.stderr
@@ -0,0 +1,21 @@
+error[E0658]: `cfg(sanitizer_cfi_generalize_pointers)` is experimental and subject to change
+  --> $DIR/feature-gate-cfg-sanitizer_cfi.rs:1:7
+   |
+LL | #[cfg(sanitizer_cfi_generalize_pointers)]
+   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #89653 <https://github.com/rust-lang/rust/issues/89653> for more information
+   = help: add `#![feature(cfg_sanitizer_cfi)]` to the crate attributes to enable
+
+error[E0658]: `cfg(sanitizer_cfi_normalize_integers)` is experimental and subject to change
+  --> $DIR/feature-gate-cfg-sanitizer_cfi.rs:5:7
+   |
+LL | #[cfg(sanitizer_cfi_normalize_integers)]
+   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #89653 <https://github.com/rust-lang/rust/issues/89653> for more information
+   = help: add `#![feature(cfg_sanitizer_cfi)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/sanitize/sanitizer-cfi-generalize-pointers-attr-cfg.rs b/tests/ui/sanitize/sanitizer-cfi-generalize-pointers-attr-cfg.rs
index 3a0fc143da6..5b8de5c219e 100644
--- a/tests/ui/sanitize/sanitizer-cfi-generalize-pointers-attr-cfg.rs
+++ b/tests/ui/sanitize/sanitizer-cfi-generalize-pointers-attr-cfg.rs
@@ -5,5 +5,7 @@
 // check-pass
 // compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-generalize-pointers
 
+#![feature(cfg_sanitizer_cfi)]
+
 #[cfg(sanitizer_cfi_generalize_pointers)]
 fn main() {}
diff --git a/tests/ui/sanitize/sanitizer-cfi-normalize-integers-attr-cfg.rs b/tests/ui/sanitize/sanitizer-cfi-normalize-integers-attr-cfg.rs
index dafc20162ab..4972ccf3167 100644
--- a/tests/ui/sanitize/sanitizer-cfi-normalize-integers-attr-cfg.rs
+++ b/tests/ui/sanitize/sanitizer-cfi-normalize-integers-attr-cfg.rs
@@ -5,5 +5,7 @@
 // check-pass
 // compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers
 
+#![feature(cfg_sanitizer_cfi)]
+
 #[cfg(sanitizer_cfi_normalize_integers)]
 fn main() {}