From 978b5f73e4be94fc99c757b5a66bf297404202f2 Mon Sep 17 00:00:00 2001 From: SLASHLogin Date: Fri, 26 Aug 2022 12:19:10 +0200 Subject: [PATCH] Port SanitizerMemtagRequiresMte --- compiler/rustc_codegen_llvm/src/attributes.rs | 3 ++- compiler/rustc_codegen_llvm/src/errors.rs | 4 ++++ compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index d96da5cc11d..02eef104077 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -12,6 +12,7 @@ use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtec use smallvec::SmallVec; use crate::attributes; +use crate::errors::SanitizerMemtagRequiresMte; use crate::llvm::AttributePlace::Function; use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects}; use crate::llvm_util; @@ -82,7 +83,7 @@ pub fn sanitize_attrs<'ll>( let mte_feature = features.iter().map(|s| &s[..]).rfind(|n| ["+mte", "-mte"].contains(&&n[..])); if let None | Some("-mte") = mte_feature { - cx.tcx.sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`"); + cx.tcx.sess.emit_err(SanitizerMemtagRequiresMte); } attrs.push(llvm::AttributeKind::SanitizeMemTag.create_attr(cx.llcx)); diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index 2661bd3cb99..a652fb4c2a0 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -80,3 +80,7 @@ pub(crate) struct LinkageConstOrMutType { #[primary_span] pub span: Span, } + +#[derive(SessionDiagnostic)] +#[diag(codegen_llvm::sanitizer_memtag_requires_mte)] +pub(crate) struct SanitizerMemtagRequiresMte; diff --git a/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl b/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl index 3804f0dbbfa..e4e1abfe219 100644 --- a/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl +++ b/compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl @@ -33,3 +33,6 @@ codegen_llvm_invalid_minimum_alignment = codegen_llvm_linkage_const_or_mut_type = must have type `*const T` or `*mut T` due to `#[linkage]` attribute + +codegen_llvm_sanitizer_memtag_requires_mte = + `-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`