[PATCH] D61342: [sanitizer_common] Added 64-bit signed flag parser.
Mitch Phillips via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 15:27:23 PDT 2019
hctim updated this revision to Diff 197462.
hctim added a comment.
Added test. Still validating locally, but it can take a while...
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61342/new/
https://reviews.llvm.org/D61342
Files:
compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc
Index: compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc
+++ compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc
@@ -16,6 +16,7 @@
#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "gtest/gtest.h"
+#include <stdint.h>
#include <string.h>
namespace __sanitizer {
@@ -110,6 +111,21 @@
"Invalid value for int option");
}
+TEST(SanitizerCommon, LongLongIntFlags) {
+ s64 InitValue = -5;
+ s64 IntMin = INT64_MIN;
+ s64 IntMax = INT64_MAX;
+ TestFlag(InitValue, "flag_name=0", 0ll);
+ TestFlag(InitValue, "flag_name=42", 42ll);
+ TestFlag(InitValue, "flag_name=-42", -42ll);
+
+ TestFlag(InitValue, "flag_name=-9223372036854775808", IntMin);
+ TestFlag(InitValue, "flag_name=9223372036854775807", IntMax);
+
+ TestFlag(InitValue, "flag_name=-92233720368547758080000", IntMin);
+ TestFlag(InitValue, "flag_name=92233720368547758070000", IntMax);
+}
+
TEST(SanitizerCommon, StrFlags) {
TestFlag("zzz", 0, "zzz");
TestFlag("zzz", "flag_name=", "");
Index: compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_flag_parser.h
@@ -99,6 +99,15 @@
return ok;
}
+template <>
+inline bool FlagHandler<s64>::Parse(const char *value) {
+ const char *value_end;
+ *t_ = internal_simple_strtoll(value, &value_end, 10);
+ bool ok = *value_end == 0;
+ if (!ok) Printf("ERROR: Invalid value for s64 option: '%s'\n", value);
+ return ok;
+}
+
class FlagParser {
static const int kMaxFlags = 200;
struct Flag {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61342.197462.patch
Type: text/x-patch
Size: 1805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190430/648ed10c/attachment.bin>
More information about the llvm-commits
mailing list