Correct ubsan feature actions
Some of the ubsan features were applied to the incorrect actions.
This fixes it.
Fixes: 290872153
Test: Unit tests
Change-Id: Ib2ca60be80ee85b50866ec3e63fa165d39477966
diff --git a/cc_toolchain_features.bzl b/cc_toolchain_features.bzl
index c46f8e0..629a7d8 100644
--- a/cc_toolchain_features.bzl
+++ b/cc_toolchain_features.bzl
@@ -1900,6 +1900,12 @@
)
return features
+minimal_runtime_flags = [
+ "-fsanitize-minimal-runtime",
+ "-fno-sanitize-trap=integer,undefined",
+ "-fno-sanitize-recover=integer,undefined",
+]
+
def _get_ubsan_features(target_os, libclang_rt_ubsan_minimal):
if target_os in [_oses.Windows, _oses.Darwin]:
return []
@@ -1930,7 +1936,7 @@
],
),
flag_set(
- actions = _actions.compile,
+ actions = _actions.c_and_cpp_compile,
flag_groups = [
flag_group(
flags = [
@@ -2047,7 +2053,7 @@
enabled = target_os not in [_oses.LinuxBionic, _oses.Android],
flag_sets = [
flag_set(
- actions = _actions.compile,
+ actions = _actions.c_and_cpp_compile,
flag_groups = [
flag_group(
flags = [
@@ -2079,14 +2085,10 @@
enabled = False,
flag_sets = [
flag_set(
- actions = ALL_UBSAN_ACTIONS,
+ actions = _actions.c_and_cpp_compile,
flag_groups = [
flag_group(
- flags = [
- "-fsanitize-minimal-runtime",
- "-fno-sanitize-trap=integer,undefined",
- "-fno-sanitize-recover=integer,undefined",
- ],
+ flags = minimal_runtime_flags,
),
],
),
@@ -2102,7 +2104,7 @@
# TODO(b/119329758): If this bug is fixed, this shouldn't be
# needed anymore
flag_set(
- actions = _actions.compile,
+ actions = _actions.c_and_cpp_compile,
flag_groups = [
flag_group(
flags = [
@@ -2117,7 +2119,7 @@
# TODO(b/171275751): If this bug is fixed, this shouldn't be
# needed anymore
flag_set(
- actions = _actions.compile,
+ actions = _actions.c_and_cpp_compile,
flag_groups = [
flag_group(
flags = [
diff --git a/cc_toolchain_features_ubsan_test.bzl b/cc_toolchain_features_ubsan_test.bzl
index b3ffc26..b0c1c85 100644
--- a/cc_toolchain_features_ubsan_test.bzl
+++ b/cc_toolchain_features_ubsan_test.bzl
@@ -28,6 +28,7 @@
":cc_toolchain_features.bzl",
"int_overflow_ignorelist_filename",
"int_overflow_ignorelist_path",
+ "minimal_runtime_flags",
)
compile_action_mnemonic = "CppCompile"
@@ -53,6 +54,9 @@
test_srcs = [
"foo.cpp",
"bar.c",
+]
+
+all_test_srcs = test_srcs + [
"baz.s",
"blah.S",
]
@@ -95,7 +99,7 @@
test_name = name + "_test"
native.cc_binary(
name = name,
- srcs = test_srcs,
+ srcs = all_test_srcs,
features = ["ubsan_undefined"], # Just pick one; doesn't matter which
tags = ["manual"],
)
@@ -672,6 +676,26 @@
return test_names
+def _test_minimal_runtime_flags_added_to_compilation():
+ name = "minimal_runtime_flags_added_to_compilation"
+
+ native.cc_binary(
+ name = name,
+ srcs = test_srcs,
+ features = ["ubsan_undefined"],
+ tags = ["manual"],
+ )
+
+ test_name = name + "_test"
+ action_flags_present_only_for_mnemonic_test(
+ name = test_name,
+ target_under_test = name,
+ mnemonics = [compile_action_mnemonic],
+ expected_flags = minimal_runtime_flags,
+ )
+
+ return test_name
+
def _exclude_rt_test_for_os_arch(target_name, os, arch, flag):
test_name = "%s_%s_test" % (
target_name,
@@ -825,6 +849,7 @@
_test_ubsan_unsupported_non_bionic_checks_not_disabled_when_android(),
_test_ubsan_unsupported_non_bionic_checks_not_disabled_when_no_ubsan(),
_test_ubsan_link_runtime_when_not_bionic_or_musl(),
+ _test_minimal_runtime_flags_added_to_compilation(),
# TODO(b/274924237): Uncomment after Darwin and Windows have toolchains
# _test_undefined_flag_absent_when_windows_or_darwin(),
]