about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLéo Lanteri Thauvin <leseulartichaut@gmail.com>2023-03-10 13:27:13 +0100
committerLéo Lanteri Thauvin <leseulartichaut@gmail.com>2023-03-12 14:57:38 +0100
commit29b1789a75c988cedb75dbdd8ebd0397a922e174 (patch)
treefad6e0d290858aee812b628edd87e9cf3ebfed93
parent963305bda8723a461afe37ddb7fc6da9f56bf100 (diff)
downloadrust-29b1789a75c988cedb75dbdd8ebd0397a922e174.tar.gz
rust-29b1789a75c988cedb75dbdd8ebd0397a922e174.zip
Allow `#[target_feature]` on `main` and `start` for WASM
-rw-r--r--compiler/rustc_codegen_ssa/src/codegen_attrs.rs3
-rw-r--r--compiler/rustc_hir_analysis/src/lib.rs13
2 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index c62968e5354..8b6bf886b0d 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -242,6 +242,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
                     // Note that this is also allowed if `actually_rustdoc` so
                     // if a target is documenting some wasm-specific code then
                     // it's not spuriously denied.
+                    //
+                    // This exception needs to be kept in sync with allowing
+                    // `#[target_feature]` on `main` and `start`.
                 } else if !tcx.features().target_feature_11 {
                     let mut err = feature_err(
                         &tcx.sess.parse_sess,
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs
index be07bb45846..62abcbbdc9f 100644
--- a/compiler/rustc_hir_analysis/src/lib.rs
+++ b/compiler/rustc_hir_analysis/src/lib.rs
@@ -283,7 +283,11 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
         error = true;
     }
 
-    if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty() {
+    if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty()
+        // Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
+        && !tcx.sess.target.is_like_wasm
+        && !tcx.sess.opts.actually_rustdoc
+    {
         tcx.sess.emit_err(errors::TargetFeatureOnMain { main: main_span });
         error = true;
     }
@@ -378,7 +382,12 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
                             });
                             error = true;
                         }
-                        if attr.has_name(sym::target_feature) {
+                        if attr.has_name(sym::target_feature)
+                            // Calling functions with `#[target_feature]` is
+                            // not unsafe on WASM, see #84988
+                            && !tcx.sess.target.is_like_wasm
+                            && !tcx.sess.opts.actually_rustdoc
+                        {
                             tcx.sess.emit_err(errors::StartTargetFeature {
                                 span: attr.span,
                                 start: start_span,