Merge "Calculate max_stashed_blocks correctly for block OTA v3"
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index 3c07f69..b433712 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -2,18 +2,7 @@
 ## Perform configuration steps for sanitizers.
 ##############################################
 
-# Configure SANITIZE_HOST.
-ifdef LOCAL_IS_HOST_MODULE
-ifeq ($(SANITIZE_HOST),true)
-ifneq ($(strip $(LOCAL_CLANG)),false)
-ifneq ($(strip $(LOCAL_ADDRESS_SANITIZER)),false)
-  LOCAL_SANITIZE := address
-endif
-endif
-endif
-endif
-
-my_sanitize := $(LOCAL_SANITIZE)
+my_sanitize := $(strip $(LOCAL_SANITIZE))
 
 # Keep compatibility for LOCAL_ADDRESS_SANITIZER until all targets have moved to
 # `LOCAL_SANITIZE := address`.
@@ -21,11 +10,46 @@
   my_sanitize += address
 endif
 
+# And `LOCAL_SANITIZE := never`.
+ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),false)
+  my_sanitize := never
+endif
+
 # Don't apply sanitizers to NDK code.
 ifdef LOCAL_SDK_VERSION
+  my_sanitize := never
+endif
+
+# Configure SANITIZE_HOST.
+ifdef LOCAL_IS_HOST_MODULE
+  ifeq ($(my_sanitize),)
+    my_sanitize := $(strip $(SANITIZE_HOST))
+
+    # SANTIZIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address.
+    ifeq ($(my_sanitize),true)
+      my_sanitize := address
+    endif
+
+    # SANITIZE_HOST is only in effect if the module is already using clang (host
+    # modules that haven't set `LOCAL_CLANG := false` and device modules that
+    # have set `LOCAL_CLANG := true`.
+    ifneq ($(my_clang),true)
+      my_sanitize :=
+    endif
+  endif
+endif
+
+ifeq ($(my_sanitize),never)
   my_sanitize :=
 endif
 
+# Sanitizers can only be used with clang.
+ifneq ($(my_clang),true)
+  ifneq ($(my_sanitize),)
+    $(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of sanitizers requires LOCAL_CLANG := true)
+  endif
+endif
+
 unknown_sanitizers := $(filter-out address, \
                       $(filter-out undefined,$(my_sanitize)))
 
@@ -34,8 +58,6 @@
 endif
 
 ifneq ($(my_sanitize),)
-  my_clang := true
-
   fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)),
   my_cflags += -fsanitize=$(fsanitize_arg)