Skip to content

Commit 978b5f7

Browse files
committed
Port SanitizerMemtagRequiresMte
1 parent 02403ee commit 978b5f7

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtec
1212
use smallvec::SmallVec;
1313

1414
use crate::attributes;
15+
use crate::errors::SanitizerMemtagRequiresMte;
1516
use crate::llvm::AttributePlace::Function;
1617
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
1718
use crate::llvm_util;
@@ -82,7 +83,7 @@ pub fn sanitize_attrs<'ll>(
8283
let mte_feature =
8384
features.iter().map(|s| &s[..]).rfind(|n| ["+mte", "-mte"].contains(&&n[..]));
8485
if let None | Some("-mte") = mte_feature {
85-
cx.tcx.sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`");
86+
cx.tcx.sess.emit_err(SanitizerMemtagRequiresMte);
8687
}
8788

8889
attrs.push(llvm::AttributeKind::SanitizeMemTag.create_attr(cx.llcx));

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ pub(crate) struct LinkageConstOrMutType {
8080
#[primary_span]
8181
pub span: Span,
8282
}
83+
84+
#[derive(SessionDiagnostic)]
85+
#[diag(codegen_llvm::sanitizer_memtag_requires_mte)]
86+
pub(crate) struct SanitizerMemtagRequiresMte;

compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ codegen_llvm_invalid_minimum_alignment =
3333
3434
codegen_llvm_linkage_const_or_mut_type =
3535
must have type `*const T` or `*mut T` due to `#[linkage]` attribute
36+
37+
codegen_llvm_sanitizer_memtag_requires_mte =
38+
`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`

0 commit comments

Comments
 (0)