[compiler-rt] r303464 - [compiler-rt] Switch handle_<signal> flags from bool to enum.
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri May 19 15:37:16 PDT 2017
Author: vitalybuka
Date: Fri May 19 17:37:16 2017
New Revision: 303464
URL: http://llvm.org/viewvc/llvm-project?rev=303464&view=rev
Log:
[compiler-rt] Switch handle_<signal> flags from bool to enum.
Summary: We are going to make it tri-state and remove allow_user_segv_handler.
Reviewers: eugenis, alekseys, kcc
Subscribers: kubamracek, dberris, llvm-commits
Differential Revision: https://reviews.llvm.org/D33159
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h?rev=303464&r1=303463&r2=303464&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h Fri May 19 17:37:16 2017
@@ -34,24 +34,40 @@ class FlagHandler : public FlagHandlerBa
bool Parse(const char *value) final;
};
-template <>
-inline bool FlagHandler<bool>::Parse(const char *value) {
+inline bool ParseBool(const char *value, bool *b) {
if (internal_strcmp(value, "0") == 0 ||
internal_strcmp(value, "no") == 0 ||
internal_strcmp(value, "false") == 0) {
- *t_ = false;
+ *b = false;
return true;
}
if (internal_strcmp(value, "1") == 0 ||
internal_strcmp(value, "yes") == 0 ||
internal_strcmp(value, "true") == 0) {
- *t_ = true;
+ *b = true;
return true;
}
+ return false;
+}
+
+template <>
+inline bool FlagHandler<bool>::Parse(const char *value) {
+ if (ParseBool(value, t_)) return true;
Printf("ERROR: Invalid value for bool option: '%s'\n", value);
return false;
}
+template <>
+inline bool FlagHandler<HandleSignalMode>::Parse(const char *value) {
+ bool b;
+ if (ParseBool(value, &b)) {
+ *t_ = b ? kHandleSignalYes : kHandleSignalNo;
+ return true;
+ }
+ Printf("ERROR: Invalid value for signal handler option: '%s'\n", value);
+ return false;
+}
+
template <>
inline bool FlagHandler<const char *>::Parse(const char *value) {
*t_ = internal_strdup(value);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=303464&r1=303463&r2=303464&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Fri May 19 17:37:16 2017
@@ -18,6 +18,11 @@
namespace __sanitizer {
+enum HandleSignalMode {
+ kHandleSignalNo,
+ kHandleSignalYes,
+};
+
struct CommonFlags {
#define COMMON_FLAG(Type, Name, DefaultValue, Description) Type Name;
#include "sanitizer_flags.inc"
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=303464&r1=303463&r2=303464&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Fri May 19 17:37:16 2017
@@ -78,16 +78,20 @@ COMMON_FLAG(int, print_module_map, 0,
"OS X only. 0 = don't print, 1 = print only once before process "
"exits, 2 = print after each report.")
COMMON_FLAG(bool, check_printf, true, "Check printf arguments.")
-COMMON_FLAG(bool, handle_segv, true,
- "If set, registers the tool's custom SIGSEGV handler.")
-COMMON_FLAG(bool, handle_sigbus, true,
- "If set, registers the tool's custom SIGBUS handler.")
-COMMON_FLAG(bool, handle_abort, false,
- "If set, registers the tool's custom SIGABRT handler.")
-COMMON_FLAG(bool, handle_sigill, false,
- "If set, registers the tool's custom SIGILL handler.")
-COMMON_FLAG(bool, handle_sigfpe, true,
- "If set, registers the tool's custom SIGFPE handler.")
+#define COMMON_FLAG_HANDLE_SIGNAL_HELP(signal) \
+ "Controls custom tool's " #signal " handler (0 - do not registers the " \
+ "handler, 1 - register the handler). "
+COMMON_FLAG(HandleSignalMode, handle_segv, kHandleSignalYes,
+ COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGSEGV))
+COMMON_FLAG(HandleSignalMode, handle_sigbus, kHandleSignalYes,
+ COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGBUS))
+COMMON_FLAG(HandleSignalMode, handle_abort, kHandleSignalNo,
+ COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGABRT))
+COMMON_FLAG(HandleSignalMode, handle_sigill, kHandleSignalNo,
+ COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGILL))
+COMMON_FLAG(HandleSignalMode, handle_sigfpe, kHandleSignalYes,
+ COMMON_FLAG_HANDLE_SIGNAL_HELP(SIGFPE))
+#undef COMMON_FLAG_HANDLE_SIGNAL_HELP
COMMON_FLAG(bool, allow_user_segv_handler, false,
"If set, allows user to register a SEGV handler even if the tool "
"registers one.")
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc?rev=303464&r1=303463&r2=303464&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc Fri May 19 17:37:16 2017
@@ -67,6 +67,28 @@ TEST(SanitizerCommon, BooleanFlags) {
"Invalid value for bool option: '2'");
EXPECT_DEATH(TestFlag(false, "flag_name=-1", true),
"Invalid value for bool option: '-1'");
+ EXPECT_DEATH(TestFlag(false, "flag_name=on", true),
+ "Invalid value for bool option: 'on'");
+}
+
+TEST(SanitizerCommon, HandleSignalMode) {
+ TestFlag(kHandleSignalNo, "flag_name=1", kHandleSignalYes);
+ TestFlag(kHandleSignalNo, "flag_name=yes", kHandleSignalYes);
+ TestFlag(kHandleSignalNo, "flag_name=true", kHandleSignalYes);
+ TestFlag(kHandleSignalYes, "flag_name=0", kHandleSignalNo);
+ TestFlag(kHandleSignalYes, "flag_name=no", kHandleSignalNo);
+ TestFlag(kHandleSignalYes, "flag_name=false", kHandleSignalNo);
+
+ EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name", kHandleSignalNo),
+ "expected '='");
+ EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=", kHandleSignalNo),
+ "Invalid value for signal handler option: ''");
+ EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=2", kHandleSignalNo),
+ "Invalid value for signal handler option: '2'");
+ EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=-1", kHandleSignalNo),
+ "Invalid value for signal handler option: '-1'");
+ EXPECT_DEATH(TestFlag(kHandleSignalNo, "flag_name=on", kHandleSignalNo),
+ "Invalid value for signal handler option: 'on'");
}
TEST(SanitizerCommon, IntFlags) {
Modified: compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp?rev=303464&r1=303463&r2=303464&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp Fri May 19 17:37:16 2017
@@ -2,7 +2,7 @@
// Defaults to true
// RUN: %clangxx_asan -std=c++11 %s -o %t
// RUN: not %run %t %T/file 2>&1 | FileCheck %s -check-prefix=CHECK-BUS
-// RUN: %env_asan_opts=handle_sigbus=false not --crash %run %t %T/file 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=handle_sigbus=0 not --crash %run %t %T/file 2>&1 | FileCheck %s
// UNSUPPORTED: ios
More information about the llvm-commits
mailing list