Index: clang/include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticDriverKinds.td +++ clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -368,6 +368,9 @@ def err_drv_ropi_incompatible_with_cxx : Error< "ROPI is not compatible with c++">; +def err_stack_tagging_requires_hardware_feature : Error< + "'-fsanitize=memtag' requires hardware support (+memtag)">; + def warn_target_unsupported_nan2008 : Warning< "ignoring '-mnan=2008' option because the '%0' architecture does not support it">, InGroup; Index: clang/lib/Driver/SanitizerArgs.cpp =================================================================== --- clang/lib/Driver/SanitizerArgs.cpp +++ clang/lib/Driver/SanitizerArgs.cpp @@ -1036,6 +1036,12 @@ Sanitizers.Mask & CFIClasses) << "-fvisibility="; } + + if (Sanitizers.has(SanitizerKind::MemTag) && + std::find(CmdArgs.begin(), CmdArgs.end(), StringRef("+mte")) == + CmdArgs.end()) { + TC.getDriver().Diag(diag::err_stack_tagging_requires_hardware_feature); + } } SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, Index: clang/test/Driver/fsanitize.c =================================================================== --- clang/test/Driver/fsanitize.c +++ clang/test/Driver/fsanitize.c @@ -191,6 +191,13 @@ // RUN: %clang -target x86_64-linux-android -fsanitize=memtag -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-BAD-ARCH // CHECK-SANMT-BAD-ARCH: unsupported option '-fsanitize=memtag' for target +// RUN: %clang -target aarch64-linux -fsanitize=memtag -march=armv8-a+memtag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-MT +// CHECK-SANMT-MT: "-target-feature" "+mte" +// CHECK-SANMT-MT-SAME: "-fsanitize=memtag" + +// RUN: %clang -target aarch64-linux -fsanitize=memtag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANMT-NOMT +// CHECK-SANMT-NOMT: '-fsanitize=memtag' requires hardware support (+memtag) + // RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-use-after-scope %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-SCOPE // RUN: %clang_cl --target=x86_64-windows -fsanitize=address -fsanitize-address-use-after-scope -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-SCOPE // CHECK-USE-AFTER-SCOPE: -cc1{{.*}}-fsanitize-address-use-after-scope