[clang] Warn when using msan on Android (PR #122540)
Sharjeel Khan via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 14:32:07 PST 2025
https://github.com/Sharjeel-Khan updated https://github.com/llvm/llvm-project/pull/122540
>From c8d2c210a98fe0c96d758d538d50fcc0ca61a9ff Mon Sep 17 00:00:00 2001
From: Sharjeel Khan <sharjeelkhan at google.com>
Date: Fri, 10 Jan 2025 20:07:52 +0000
Subject: [PATCH 1/2] Warn when using msan on Android
Msan is not supported on Android as mentioned in google/sanitizers#1381.
We proactively give the warning saying it is unsupported to fix android/ndk#1958.
---
clang/lib/Driver/SanitizerArgs.cpp | 10 ++++++++++
clang/test/Driver/fsanitize.c | 5 +++++
2 files changed, 15 insertions(+)
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index a0d6919c6dc8d0..04b39d29e7342f 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -530,6 +530,16 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
}
Add &= Supported;
+ // Msan is not supported on Android
+ if ((Add & SanitizerKind::Memory) && TC.getTriple().isAndroid()) {
+ if (DiagnoseErrors) {
+ D.Diag(diag::warn_drv_unsupported_option_for_target)
+ << "-fsanitize=memory" << Triple.str();
+ }
+ DiagnosedKinds |= SanitizerKind::Memory;
+ Add &= ~SanitizerKind::Memory;
+ }
+
// Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
// so we don't error out if -fno-rtti and -fsanitize=undefined were
// passed.
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 1d3caec748d77a..55b51ed29b0e65 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -399,6 +399,11 @@
// RUN: %clang --target=arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN
// CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "pic"
+// RUN: %clang --target=aarch64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
+// RUN: %clang --target=i386-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
+// RUN: %clang --target=x86_64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
+// CHECK-MSAN-ANDROID: ignoring '-fsanitize=memory' option as it is not currently supported for target
+
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=all -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
>From 035c7d9936a33926ccca10d9670879d3b913496e Mon Sep 17 00:00:00 2001
From: Sharjeel Khan <sharjeelkhan at google.com>
Date: Fri, 10 Jan 2025 22:31:33 +0000
Subject: [PATCH 2/2] Fixed format for SanitizerArgs
---
clang/lib/Driver/SanitizerArgs.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 04b39d29e7342f..25bfd5eadae8c9 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -534,7 +534,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
if ((Add & SanitizerKind::Memory) && TC.getTriple().isAndroid()) {
if (DiagnoseErrors) {
D.Diag(diag::warn_drv_unsupported_option_for_target)
- << "-fsanitize=memory" << Triple.str();
+ << "-fsanitize=memory" << Triple.str();
}
DiagnosedKinds |= SanitizerKind::Memory;
Add &= ~SanitizerKind::Memory;
More information about the cfe-commits
mailing list