[compiler-rt] 2d7fd38 - [sanitizers] Remove unneeded MaybeCall*DefaultOptions() and nullptr checks
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 10:18:30 PDT 2020
Author: Fangrui Song
Date: 2020-09-08T10:12:05-07:00
New Revision: 2d7fd38cf7db18edbbfa0e6dfb7454a255171867
URL: https://github.com/llvm/llvm-project/commit/2d7fd38cf7db18edbbfa0e6dfb7454a255171867
DIFF: https://github.com/llvm/llvm-project/commit/2d7fd38cf7db18edbbfa0e6dfb7454a255171867.diff
LOG: [sanitizers] Remove unneeded MaybeCall*DefaultOptions() and nullptr checks
D28596 added SANITIZER_INTERFACE_WEAK_DEF which can guarantee `*_default_options` are always defined.
The weak attributes on the `__{asan,lsan,msan,ubsan}_default_options` declarations can thus be removed.
`MaybeCall*DefaultOptions` no longer need nullptr checks, so their call sites can just be replaced by `__*_default_options`.
Reviewed By: #sanitizers, vitalybuka
Differential Revision: https://reviews.llvm.org/D87175
Added:
Modified:
compiler-rt/lib/asan/asan_flags.cpp
compiler-rt/lib/asan/asan_interface_internal.h
compiler-rt/lib/cfi/cfi.cpp
compiler-rt/lib/hwasan/hwasan.cpp
compiler-rt/lib/lsan/lsan.cpp
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/msan/msan.cpp
compiler-rt/lib/msan/msan_interface_internal.h
compiler-rt/lib/tsan/rtl/tsan_flags.cpp
compiler-rt/lib/ubsan/ubsan_flags.cpp
compiler-rt/lib/ubsan/ubsan_flags.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_flags.cpp b/compiler-rt/lib/asan/asan_flags.cpp
index c5c70eaed737..cb6a89fe32ce 100644
--- a/compiler-rt/lib/asan/asan_flags.cpp
+++ b/compiler-rt/lib/asan/asan_flags.cpp
@@ -26,10 +26,6 @@ namespace __asan {
Flags asan_flags_dont_use_directly; // use via flags().
-static const char *MaybeCallAsanDefaultOptions() {
- return (&__asan_default_options) ? __asan_default_options() : "";
-}
-
static const char *MaybeUseAsanDefaultOptionsCompileDefinition() {
#ifdef ASAN_DEFAULT_OPTIONS
return SANITIZER_STRINGIFY(ASAN_DEFAULT_OPTIONS);
@@ -108,14 +104,14 @@ void InitializeFlags() {
asan_parser.ParseString(asan_compile_def);
// Override from user-specified string.
- const char *asan_default_options = MaybeCallAsanDefaultOptions();
+ const char *asan_default_options = __asan_default_options();
asan_parser.ParseString(asan_default_options);
#if CAN_SANITIZE_UB
- const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
+ const char *ubsan_default_options = __ubsan_default_options();
ubsan_parser.ParseString(ubsan_default_options);
#endif
#if CAN_SANITIZE_LEAKS
- const char *lsan_default_options = __lsan::MaybeCallLsanDefaultOptions();
+ const char *lsan_default_options = __lsan_default_options();
lsan_parser.ParseString(lsan_default_options);
#endif
diff --git a/compiler-rt/lib/asan/asan_interface_internal.h b/compiler-rt/lib/asan/asan_interface_internal.h
index f14cbbcb76a3..3e6e66028874 100644
--- a/compiler-rt/lib/asan/asan_interface_internal.h
+++ b/compiler-rt/lib/asan/asan_interface_internal.h
@@ -173,8 +173,8 @@ extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
- SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
- const char* __asan_default_options();
+ SANITIZER_INTERFACE_ATTRIBUTE
+ const char *__asan_default_options();
SANITIZER_INTERFACE_ATTRIBUTE
extern uptr __asan_shadow_memory_dynamic_address;
diff --git a/compiler-rt/lib/cfi/cfi.cpp b/compiler-rt/lib/cfi/cfi.cpp
index fd48f71643b6..b75c72b215c2 100644
--- a/compiler-rt/lib/cfi/cfi.cpp
+++ b/compiler-rt/lib/cfi/cfi.cpp
@@ -379,7 +379,7 @@ void InitializeFlags() {
__ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
RegisterCommonFlags(&ubsan_parser);
- const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
+ const char *ubsan_default_options = __ubsan_default_options();
ubsan_parser.ParseString(ubsan_default_options);
ubsan_parser.ParseStringFromEnv("UBSAN_OPTIONS");
#endif
diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp
index 11b4d3891bc2..c5322110cb66 100644
--- a/compiler-rt/lib/hwasan/hwasan.cpp
+++ b/compiler-rt/lib/hwasan/hwasan.cpp
@@ -112,7 +112,7 @@ static void InitializeFlags() {
if (__hwasan_default_options)
parser.ParseString(__hwasan_default_options());
#if HWASAN_CONTAINS_UBSAN
- const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
+ const char *ubsan_default_options = __ubsan_default_options();
ubsan_parser.ParseString(ubsan_default_options);
#endif
diff --git a/compiler-rt/lib/lsan/lsan.cpp b/compiler-rt/lib/lsan/lsan.cpp
index 80a6e2fa7016..c8cc045783d4 100644
--- a/compiler-rt/lib/lsan/lsan.cpp
+++ b/compiler-rt/lib/lsan/lsan.cpp
@@ -73,7 +73,7 @@ static void InitializeFlags() {
RegisterCommonFlags(&parser);
// Override from user-specified string.
- const char *lsan_default_options = MaybeCallLsanDefaultOptions();
+ const char *lsan_default_options = __lsan_default_options();
parser.ParseString(lsan_default_options);
parser.ParseStringFromEnv("LSAN_OPTIONS");
diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index 67f85f2f31de..93ce0ddc3d68 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -110,10 +110,6 @@ void InitializeRootRegions() {
root_regions = new (placeholder) InternalMmapVector<RootRegion>();
}
-const char *MaybeCallLsanDefaultOptions() {
- return (&__lsan_default_options) ? __lsan_default_options() : "";
-}
-
void InitCommonLsan() {
InitializeRootRegions();
if (common_flags()->detect_leaks) {
@@ -900,12 +896,11 @@ int __lsan_do_recoverable_leak_check() {
return 0;
}
-#if !SANITIZER_SUPPORTS_WEAK_HOOKS
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-const char * __lsan_default_options() {
+SANITIZER_INTERFACE_WEAK_DEF(const char *, __lsan_default_options, void) {
return "";
}
+#if !SANITIZER_SUPPORTS_WEAK_HOOKS
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
int __lsan_is_turned_off() {
return 0;
diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp
index 3028f79f041c..d651a376789b 100644
--- a/compiler-rt/lib/msan/msan.cpp
+++ b/compiler-rt/lib/msan/msan.cpp
@@ -172,10 +172,9 @@ static void InitializeFlags() {
#endif
// Override from user-specified string.
- if (__msan_default_options)
- parser.ParseString(__msan_default_options());
+ parser.ParseString(__msan_default_options());
#if MSAN_CONTAINS_UBSAN
- const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
+ const char *ubsan_default_options = __ubsan_default_options();
ubsan_parser.ParseString(ubsan_default_options);
#endif
@@ -726,12 +725,9 @@ void __msan_finish_switch_fiber(const void **bottom_old, uptr *size_old) {
}
}
-#if !SANITIZER_SUPPORTS_WEAK_HOOKS
-extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-const char* __msan_default_options() { return ""; }
-} // extern "C"
-#endif
+SANITIZER_INTERFACE_WEAK_DEF(const char *, __msan_default_options, void) {
+ return "";
+}
extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE
diff --git a/compiler-rt/lib/msan/msan_interface_internal.h b/compiler-rt/lib/msan/msan_interface_internal.h
index 17922a888b9c..1edacbc7504f 100644
--- a/compiler-rt/lib/msan/msan_interface_internal.h
+++ b/compiler-rt/lib/msan/msan_interface_internal.h
@@ -129,8 +129,8 @@ void __msan_set_keep_going(int keep_going);
SANITIZER_INTERFACE_ATTRIBUTE
int __msan_set_poison_in_malloc(int do_poison);
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-/* OPTIONAL */ const char* __msan_default_options();
+SANITIZER_INTERFACE_ATTRIBUTE
+const char *__msan_default_options();
// For testing.
SANITIZER_INTERFACE_ATTRIBUTE
diff --git a/compiler-rt/lib/tsan/rtl/tsan_flags.cpp b/compiler-rt/lib/tsan/rtl/tsan_flags.cpp
index 44bf325cd35b..49e4a9c21da9 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_flags.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_flags.cpp
@@ -87,7 +87,7 @@ void InitializeFlags(Flags *f, const char *env, const char *env_option_name) {
// Let a frontend override.
parser.ParseString(__tsan_default_options());
#if TSAN_CONTAINS_UBSAN
- const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
+ const char *ubsan_default_options = __ubsan_default_options();
ubsan_parser.ParseString(ubsan_default_options);
#endif
// Override from command line.
diff --git a/compiler-rt/lib/ubsan/ubsan_flags.cpp b/compiler-rt/lib/ubsan/ubsan_flags.cpp
index 721c2273f133..25cefd46ce27 100644
--- a/compiler-rt/lib/ubsan/ubsan_flags.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_flags.cpp
@@ -21,10 +21,6 @@
namespace __ubsan {
-const char *MaybeCallUbsanDefaultOptions() {
- return (&__ubsan_default_options) ? __ubsan_default_options() : "";
-}
-
static const char *GetFlag(const char *flag) {
// We cannot call getenv() from inside a preinit array initializer
if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
@@ -66,7 +62,7 @@ void InitializeFlags() {
RegisterUbsanFlags(&parser, f);
// Override from user-specified string.
- parser.ParseString(MaybeCallUbsanDefaultOptions());
+ parser.ParseString(__ubsan_default_options());
// Override from environment variable.
parser.ParseStringFromEnv("UBSAN_OPTIONS");
InitializeCommonFlags();
diff --git a/compiler-rt/lib/ubsan/ubsan_flags.h b/compiler-rt/lib/ubsan/ubsan_flags.h
index daa0d7c701e0..c47009bafe53 100644
--- a/compiler-rt/lib/ubsan/ubsan_flags.h
+++ b/compiler-rt/lib/ubsan/ubsan_flags.h
@@ -34,8 +34,6 @@ inline Flags *flags() { return &ubsan_flags; }
void InitializeFlags();
void RegisterUbsanFlags(FlagParser *parser, Flags *f);
-const char *MaybeCallUbsanDefaultOptions();
-
} // namespace __ubsan
extern "C" {
More information about the llvm-commits
mailing list