Skip to content

Commit c8d2c21

Browse files
committed
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.
1 parent 35e76b6 commit c8d2c21

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,16 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
530530
}
531531
Add &= Supported;
532532

533+
// Msan is not supported on Android
534+
if ((Add & SanitizerKind::Memory) && TC.getTriple().isAndroid()) {
535+
if (DiagnoseErrors) {
536+
D.Diag(diag::warn_drv_unsupported_option_for_target)
537+
<< "-fsanitize=memory" << Triple.str();
538+
}
539+
DiagnosedKinds |= SanitizerKind::Memory;
540+
Add &= ~SanitizerKind::Memory;
541+
}
542+
533543
// Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
534544
// so we don't error out if -fno-rtti and -fsanitize=undefined were
535545
// passed.

clang/test/Driver/fsanitize.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@
399399
// RUN: %clang --target=arm-linux-androideabi %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-NO-ASAN
400400
// CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "pic"
401401

402+
// RUN: %clang --target=aarch64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
403+
// RUN: %clang --target=i386-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
404+
// RUN: %clang --target=x86_64-linux-android -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
405+
// CHECK-MSAN-ANDROID: ignoring '-fsanitize=memory' option as it is not currently supported for target
406+
402407
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
403408
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
404409
// RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=all -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN

0 commit comments

Comments
 (0)