about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-01 08:09:31 +0000
committerbors <bors@rust-lang.org>2024-08-01 08:09:31 +0000
commit97ac52f579fe1003a162324d448dad43a942b5f5 (patch)
treef8cc6294bb554f1fc41fb47a452923b517f6e6f7
parent70591dc15db32941fe3595fdbf98e58d6975f95e (diff)
parentff1476ca20d1c5e1dbbba39820fc6a12cb71a959 (diff)
downloadrust-97ac52f579fe1003a162324d448dad43a942b5f5.tar.gz
rust-97ac52f579fe1003a162324d448dad43a942b5f5.zip
Auto merge of #128481 - matthiaskrgr:rollup-efa706r, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #128416 (android: Remove libstd hacks for unsupported Android APIs)
 - #128437 (improve bootstrap to allow selecting llvm tools individually)
 - #128450 (Create COFF archives for non-LLVM backends)
 - #128458 (Emit an error if `#[optimize]` is applied to an incompatible item)
 - #128477 (Finish blessing `coverage/mcdc` tests after LLVM 19 upgrade)
 - #128478 (Ignore `use` declaration reformatting in `.git-blame-ignore-revs`.)

r? `@ghost`
`@rustbot` modify labels: rollup
-rw-r--r--.git-blame-ignore-revs2
-rw-r--r--compiler/rustc_codegen_ssa/src/back/archive.rs6
-rw-r--r--compiler/rustc_passes/messages.ftl4
-rw-r--r--compiler/rustc_passes/src/check_attr.rs22
-rw-r--r--compiler/rustc_passes/src/errors.rs4
-rw-r--r--library/std/src/f32.rs2
-rw-r--r--library/std/src/f64.rs2
-rw-r--r--library/std/src/sys/pal/mod.rs18
-rw-r--r--library/std/src/sys/pal/unix/android.rs81
-rw-r--r--library/std/src/sys/pal/unix/mod.rs5
-rw-r--r--src/bootstrap/src/core/build_steps/dist.rs37
-rw-r--r--tests/coverage/mcdc/condition-limit.coverage1
-rw-r--r--tests/coverage/mcdc/if.coverage1
-rw-r--r--tests/coverage/mcdc/inlined_expressions.coverage1
-rw-r--r--tests/coverage/mcdc/nested_if.coverage1
-rw-r--r--tests/coverage/mcdc/non_control_flow.coverage1
-rw-r--r--tests/ui/attributes/optimize.rs28
-rw-r--r--tests/ui/attributes/optimize.stderr20
18 files changed, 122 insertions, 114 deletions
diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
index 663ace48e9e..9fd8054a12e 100644
--- a/.git-blame-ignore-revs
+++ b/.git-blame-ignore-revs
@@ -23,3 +23,5 @@ b2d2184edea578109a48ec3d8decbee5948e8f35
 # test directives migration
 6e48b96692d63a79a14563f27fe5185f122434f8
 ec2cc761bc7067712ecc7734502f703fe3b024c8
+# format use declarations
+84ac80f1921afc243d71fd0caaa4f2838c294102
diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs
index dd950703615..4f93b7b23c6 100644
--- a/compiler/rustc_codegen_ssa/src/back/archive.rs
+++ b/compiler/rustc_codegen_ssa/src/back/archive.rs
@@ -220,11 +220,7 @@ impl<'a> ArArchiveBuilder<'a> {
             "gnu" => ArchiveKind::Gnu,
             "bsd" => ArchiveKind::Bsd,
             "darwin" => ArchiveKind::Darwin,
-            "coff" => {
-                // FIXME: ar_archive_writer doesn't support COFF archives yet.
-                // https://github.com/rust-lang/ar_archive_writer/issues/9
-                ArchiveKind::Gnu
-            }
+            "coff" => ArchiveKind::Coff,
             "aix_big" => ArchiveKind::AixBig,
             kind => {
                 self.sess.dcx().emit_fatal(UnknownArchiveKind { kind });
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl
index bfe0d54e645..1747307a1b2 100644
--- a/compiler/rustc_passes/messages.ftl
+++ b/compiler/rustc_passes/messages.ftl
@@ -542,6 +542,10 @@ passes_only_has_effect_on =
         *[unspecified] (unspecified--this is a compiler bug)
     }
 
+passes_optimize_not_fn_or_closure =
+    attribute should be applied to function or closure
+    .label = not a function or closure
+
 passes_outer_crate_level_attr =
     crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
 
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 3a62ba66b54..86b18570f37 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -124,6 +124,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
                 }
                 [sym::inline] => self.check_inline(hir_id, attr, span, target),
                 [sym::coverage] => self.check_coverage(attr, span, target),
+                [sym::optimize] => self.check_optimize(hir_id, attr, target),
                 [sym::non_exhaustive] => self.check_non_exhaustive(hir_id, attr, span, target),
                 [sym::marker] => self.check_marker(hir_id, attr, span, target),
                 [sym::target_feature] => {
@@ -373,6 +374,27 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
         }
     }
 
+    /// Checks that `#[optimize(..)]` is applied to a function/closure/method,
+    /// or to an impl block or module.
+    fn check_optimize(&self, hir_id: HirId, attr: &Attribute, target: Target) {
+        match target {
+            Target::Fn
+            | Target::Closure
+            | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
+            | Target::Impl
+            | Target::Mod => {}
+
+            _ => {
+                self.tcx.emit_node_span_lint(
+                    UNUSED_ATTRIBUTES,
+                    hir_id,
+                    attr.span,
+                    errors::OptimizeNotFnOrClosure,
+                );
+            }
+        }
+    }
+
     fn check_generic_attr(
         &self,
         hir_id: HirId,
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs
index ff85be109d4..c4f3c8a0d6c 100644
--- a/compiler/rustc_passes/src/errors.rs
+++ b/compiler/rustc_passes/src/errors.rs
@@ -68,6 +68,10 @@ pub struct CoverageNotFnOrClosure {
     pub defn_span: Span,
 }
 
+#[derive(LintDiagnostic)]
+#[diag(passes_optimize_not_fn_or_closure)]
+pub struct OptimizeNotFnOrClosure;
+
 #[derive(Diagnostic)]
 #[diag(passes_should_be_applied_to_fn)]
 pub struct AttrShouldBeAppliedToFn {
diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs
index b3afeca1ed8..12433d25bfa 100644
--- a/library/std/src/f32.rs
+++ b/library/std/src/f32.rs
@@ -574,7 +574,7 @@ impl f32 {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub fn log2(self) -> f32 {
-        crate::sys::log2f32(self)
+        unsafe { intrinsics::log2f32(self) }
     }
 
     /// Returns the base 10 logarithm of the number.
diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs
index c8a709c7768..a343e19173e 100644
--- a/library/std/src/f64.rs
+++ b/library/std/src/f64.rs
@@ -574,7 +574,7 @@ impl f64 {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub fn log2(self) -> f64 {
-        crate::sys::log2f64(self)
+        unsafe { intrinsics::log2f64(self) }
     }
 
     /// Returns the base 10 logarithm of the number.
diff --git a/library/std/src/sys/pal/mod.rs b/library/std/src/sys/pal/mod.rs
index df017624448..9be018c8a53 100644
--- a/library/std/src/sys/pal/mod.rs
+++ b/library/std/src/sys/pal/mod.rs
@@ -76,23 +76,5 @@ cfg_if::cfg_if! {
     }
 }
 
-#[cfg(not(test))]
-cfg_if::cfg_if! {
-    if #[cfg(target_os = "android")] {
-        pub use self::android::log2f32;
-        pub use self::android::log2f64;
-    } else {
-        #[inline]
-        pub fn log2f32(n: f32) -> f32 {
-            unsafe { crate::intrinsics::log2f32(n) }
-        }
-
-        #[inline]
-        pub fn log2f64(n: f64) -> f64 {
-            unsafe { crate::intrinsics::log2f64(n) }
-        }
-    }
-}
-
 #[cfg(not(target_os = "uefi"))]
 pub type RawOsError = i32;
diff --git a/library/std/src/sys/pal/unix/android.rs b/library/std/src/sys/pal/unix/android.rs
deleted file mode 100644
index 0f704994f55..00000000000
--- a/library/std/src/sys/pal/unix/android.rs
+++ /dev/null
@@ -1,81 +0,0 @@
-//! Android ABI-compatibility module
-//!
-//! The ABI of Android has changed quite a bit over time, and std attempts to be
-//! both forwards and backwards compatible as much as possible. We want to
-//! always work with the most recent version of Android, but we also want to
-//! work with older versions of Android for whenever projects need to.
-//!
-//! Our current minimum supported Android version is `android-9`, e.g., Android
-//! with API level 9. We then in theory want to work on that and all future
-//! versions of Android!
-//!
-//! Some of the detection here is done at runtime via `dlopen` and
-//! introspection. Other times no detection is performed at all and we just
-//! provide a fallback implementation as some versions of Android we support
-//! don't have the function.
-//!
-//! You'll find more details below about why each compatibility shim is needed.
-
-#![cfg(target_os = "android")]
-
-use libc::{c_int, sighandler_t};
-
-use super::weak::weak;
-
-// The `log2` and `log2f` functions apparently appeared in android-18, or at
-// least you can see they're not present in the android-17 header [1] and they
-// are present in android-18 [2].
-//
-// [1]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
-//                                       /android-17/arch-arm/usr/include/math.h
-// [2]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
-//                                       /android-18/arch-arm/usr/include/math.h
-//
-// Note that these shims are likely less precise than directly calling `log2`,
-// but hopefully that should be enough for now...
-//
-// Note that mathematically, for any arbitrary `y`:
-//
-//      log_2(x) = log_y(x) / log_y(2)
-//               = log_y(x) / (1 / log_2(y))
-//               = log_y(x) * log_2(y)
-//
-// Hence because `ln` (log_e) is available on all Android we just choose `y = e`
-// and get:
-//
-//      log_2(x) = ln(x) * log_2(e)
-
-#[cfg(not(test))]
-pub fn log2f32(f: f32) -> f32 {
-    f.ln() * crate::f32::consts::LOG2_E
-}
-
-#[cfg(not(test))]
-pub fn log2f64(f: f64) -> f64 {
-    f.ln() * crate::f64::consts::LOG2_E
-}
-
-// Back in the day [1] the `signal` function was just an inline wrapper
-// around `bsd_signal`, but starting in API level android-20 the `signal`
-// symbols was introduced [2]. Finally, in android-21 the API `bsd_signal` was
-// removed [3].
-//
-// Basically this means that if we want to be binary compatible with multiple
-// Android releases (oldest being 9 and newest being 21) then we need to check
-// for both symbols and not actually link against either.
-//
-// [1]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms
-//                                       /android-18/arch-arm/usr/include/signal.h
-// [2]: https://chromium.googlesource.com/android_tools/+/fbd420/ndk_experimental
-//                                       /platforms/android-20/arch-arm
-//                                       /usr/include/signal.h
-// [3]: https://chromium.googlesource.com/android_tools/+/20ee6d/ndk/platforms
-//                                       /android-21/arch-arm/usr/include/signal.h
-pub unsafe fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t {
-    weak!(fn signal(c_int, sighandler_t) -> sighandler_t);
-    weak!(fn bsd_signal(c_int, sighandler_t) -> sighandler_t);
-
-    let f = signal.get().or_else(|| bsd_signal.get());
-    let f = f.expect("neither `signal` nor `bsd_signal` symbols found");
-    f(signum, handler)
-}
diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs
index 3fc51ff59a9..b62129f4cdd 100644
--- a/library/std/src/sys/pal/unix/mod.rs
+++ b/library/std/src/sys/pal/unix/mod.rs
@@ -8,7 +8,6 @@ use crate::io::ErrorKind;
 pub mod weak;
 
 pub mod alloc;
-pub mod android;
 pub mod args;
 pub mod env;
 pub mod fd;
@@ -237,12 +236,8 @@ pub unsafe fn cleanup() {
 }
 
 #[allow(unused_imports)]
-#[cfg(not(target_os = "android"))]
 pub use libc::signal;
 
-#[cfg(target_os = "android")]
-pub use crate::sys::android::signal;
-
 #[inline]
 pub(crate) fn is_interrupted(errno: i32) -> bool {
     errno == libc::EINTR
diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs
index 967ddbc0d34..58f86aa996d 100644
--- a/src/bootstrap/src/core/build_steps/dist.rs
+++ b/src/bootstrap/src/core/build_steps/dist.rs
@@ -2122,8 +2122,13 @@ impl Step for LlvmTools {
 
     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
         let default = should_build_extended_tool(run.builder, "llvm-tools");
-        // FIXME: allow using the names of the tools themselves?
-        run.alias("llvm-tools").default_condition(default)
+
+        let mut run = run.alias("llvm-tools");
+        for tool in LLVM_TOOLS {
+            run = run.alias(tool);
+        }
+
+        run.default_condition(default)
     }
 
     fn make_run(run: RunConfig<'_>) {
@@ -2131,6 +2136,32 @@ impl Step for LlvmTools {
     }
 
     fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
+        fn tools_to_install(paths: &[PathBuf]) -> Vec<&'static str> {
+            let mut tools = vec![];
+
+            for path in paths {
+                let path = path.to_str().unwrap();
+
+                // Include all tools if path is 'llvm-tools'.
+                if path == "llvm-tools" {
+                    return LLVM_TOOLS.to_owned();
+                }
+
+                for tool in LLVM_TOOLS {
+                    if path == *tool {
+                        tools.push(*tool);
+                    }
+                }
+            }
+
+            // If no specific tool is requested, include all tools.
+            if tools.is_empty() {
+                tools = LLVM_TOOLS.to_owned();
+            }
+
+            tools
+        }
+
         let target = self.target;
 
         /* run only if llvm-config isn't used */
@@ -2151,7 +2182,7 @@ impl Step for LlvmTools {
             // Prepare the image directory
             let src_bindir = builder.llvm_out(target).join("bin");
             let dst_bindir = format!("lib/rustlib/{}/bin", target.triple);
-            for tool in LLVM_TOOLS {
+            for tool in tools_to_install(&builder.paths) {
                 let exe = src_bindir.join(exe(tool, target));
                 tarball.add_file(&exe, &dst_bindir, 0o755);
             }
diff --git a/tests/coverage/mcdc/condition-limit.coverage b/tests/coverage/mcdc/condition-limit.coverage
index 4eb87432fab..81e832d6a49 100644
--- a/tests/coverage/mcdc/condition-limit.coverage
+++ b/tests/coverage/mcdc/condition-limit.coverage
@@ -1,6 +1,7 @@
    LL|       |#![feature(coverage_attribute)]
    LL|       |//@ edition: 2021
    LL|       |//@ min-llvm-version: 18
+   LL|       |//@ ignore-llvm-version: 19 - 99
    LL|       |//@ compile-flags: -Zcoverage-options=mcdc
    LL|       |//@ llvm-cov-flags: --show-branches=count --show-mcdc
    LL|       |
diff --git a/tests/coverage/mcdc/if.coverage b/tests/coverage/mcdc/if.coverage
index 91fff073d0c..dc93319950b 100644
--- a/tests/coverage/mcdc/if.coverage
+++ b/tests/coverage/mcdc/if.coverage
@@ -1,6 +1,7 @@
    LL|       |#![feature(coverage_attribute)]
    LL|       |//@ edition: 2021
    LL|       |//@ min-llvm-version: 18
+   LL|       |//@ ignore-llvm-version: 19 - 99
    LL|       |//@ compile-flags: -Zcoverage-options=mcdc
    LL|       |//@ llvm-cov-flags: --show-branches=count --show-mcdc
    LL|       |
diff --git a/tests/coverage/mcdc/inlined_expressions.coverage b/tests/coverage/mcdc/inlined_expressions.coverage
index 5b083d62186..4e4800310c9 100644
--- a/tests/coverage/mcdc/inlined_expressions.coverage
+++ b/tests/coverage/mcdc/inlined_expressions.coverage
@@ -1,6 +1,7 @@
    LL|       |#![feature(coverage_attribute)]
    LL|       |//@ edition: 2021
    LL|       |//@ min-llvm-version: 18
+   LL|       |//@ ignore-llvm-version: 19 - 99
    LL|       |//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
    LL|       |//@ llvm-cov-flags: --show-branches=count --show-mcdc
    LL|       |
diff --git a/tests/coverage/mcdc/nested_if.coverage b/tests/coverage/mcdc/nested_if.coverage
index a273a713a8a..916bb94745d 100644
--- a/tests/coverage/mcdc/nested_if.coverage
+++ b/tests/coverage/mcdc/nested_if.coverage
@@ -1,6 +1,7 @@
    LL|       |#![feature(coverage_attribute)]
    LL|       |//@ edition: 2021
    LL|       |//@ min-llvm-version: 18
+   LL|       |//@ ignore-llvm-version: 19 - 99
    LL|       |//@ compile-flags: -Zcoverage-options=mcdc
    LL|       |//@ llvm-cov-flags: --show-branches=count --show-mcdc
    LL|       |
diff --git a/tests/coverage/mcdc/non_control_flow.coverage b/tests/coverage/mcdc/non_control_flow.coverage
index 6ae796e8ed2..c64f61a153c 100644
--- a/tests/coverage/mcdc/non_control_flow.coverage
+++ b/tests/coverage/mcdc/non_control_flow.coverage
@@ -1,6 +1,7 @@
    LL|       |#![feature(coverage_attribute)]
    LL|       |//@ edition: 2021
    LL|       |//@ min-llvm-version: 18
+   LL|       |//@ ignore-llvm-version: 19 - 99
    LL|       |//@ compile-flags: -Zcoverage-options=mcdc
    LL|       |//@ llvm-cov-flags: --show-branches=count --show-mcdc
    LL|       |
diff --git a/tests/ui/attributes/optimize.rs b/tests/ui/attributes/optimize.rs
new file mode 100644
index 00000000000..b01806165c1
--- /dev/null
+++ b/tests/ui/attributes/optimize.rs
@@ -0,0 +1,28 @@
+#![feature(optimize_attribute)]
+#![feature(stmt_expr_attributes)]
+#![deny(unused_attributes)]
+#![allow(dead_code)]
+
+#[optimize(speed)] //~ ERROR attribute should be applied to function or closure
+struct F;
+
+fn invalid() {
+    #[optimize(speed)] //~ ERROR attribute should be applied to function or closure
+    {
+        1
+    };
+}
+
+#[optimize(speed)]
+fn valid() {}
+
+#[optimize(speed)]
+mod valid_module {}
+
+#[optimize(speed)]
+impl F {}
+
+fn main() {
+    let _ = #[optimize(speed)]
+    (|| 1);
+}
diff --git a/tests/ui/attributes/optimize.stderr b/tests/ui/attributes/optimize.stderr
new file mode 100644
index 00000000000..3c445d73c2e
--- /dev/null
+++ b/tests/ui/attributes/optimize.stderr
@@ -0,0 +1,20 @@
+error: attribute should be applied to function or closure
+  --> $DIR/optimize.rs:6:1
+   |
+LL | #[optimize(speed)]
+   | ^^^^^^^^^^^^^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/optimize.rs:3:9
+   |
+LL | #![deny(unused_attributes)]
+   |         ^^^^^^^^^^^^^^^^^
+
+error: attribute should be applied to function or closure
+  --> $DIR/optimize.rs:10:5
+   |
+LL |     #[optimize(speed)]
+   |     ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+