Skip to content

Commit

Permalink
Warn when using msan on Android
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sharjeel-Khan committed Jan 10, 2025
1 parent 35e76b6 commit c8d2c21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/fsanitize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8d2c21

Please sign in to comment.