[compiler-rt] r214258 - [UBSan] Move all runtime flags parsing to ubsan_flags.cc.

Alexey Samsonov vonosmas at gmail.com
Tue Jul 29 16:49:21 PDT 2014


Author: samsonov
Date: Tue Jul 29 18:49:20 2014
New Revision: 214258

URL: http://llvm.org/viewvc/llvm-project?rev=214258&view=rev
Log:
[UBSan] Move all runtime flags parsing to ubsan_flags.cc.

No functionality change.

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
    compiler-rt/trunk/lib/ubsan/ubsan_flags.h
    compiler-rt/trunk/lib/ubsan/ubsan_init.cc

Modified: compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.cc?rev=214258&r1=214257&r2=214258&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cc Tue Jul 29 18:49:20 2014
@@ -17,18 +17,29 @@
 
 namespace __ubsan {
 
+void InitializeCommonFlags() {
+  CommonFlags *cf = common_flags();
+  SetCommonFlagsDefaults(cf);
+  cf->print_summary = false;
+  // Common flags may be overriden in UBSAN_OPTIONS.
+  ParseCommonFlagsFromString(cf, GetEnv("UBSAN_OPTIONS"));
+}
+
 Flags ubsan_flags;
 
+static void ParseFlagsFromString(Flags *f, const char *str) {
+  if (!str)
+    return;
+  ParseFlag(str, &f->print_stacktrace, "print_stacktrace",
+            "Include full stacktrace into an error report");
+}
+
 void InitializeFlags() {
   Flags *f = flags();
   // Default values.
   f->print_stacktrace = false;
-
-  const char *options = GetEnv("UBSAN_OPTIONS");
-  if (options) {
-    ParseFlag(options, &f->print_stacktrace, "print_stacktrace",
-              "Include full stacktrace into an error report");
-  }
+  // Override from environment variable.
+  ParseFlagsFromString(f, GetEnv("UBSAN_OPTIONS"));
 }
 
 }  // namespace __ubsan

Modified: compiler-rt/trunk/lib/ubsan/ubsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.h?rev=214258&r1=214257&r2=214258&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.h Tue Jul 29 18:49:20 2014
@@ -22,6 +22,7 @@ struct Flags {
 extern Flags ubsan_flags;
 inline Flags *flags() { return &ubsan_flags; }
 
+void InitializeCommonFlags();
 void InitializeFlags();
 
 }  // namespace __ubsan

Modified: compiler-rt/trunk/lib/ubsan/ubsan_init.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init.cc?rev=214258&r1=214257&r2=214258&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init.cc Tue Jul 29 18:49:20 2014
@@ -15,7 +15,6 @@
 #include "ubsan_flags.h"
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_flags.h"
 #include "sanitizer_common/sanitizer_mutex.h"
 #include "sanitizer_common/sanitizer_symbolizer.h"
 
@@ -38,11 +37,7 @@ void __ubsan::InitIfNecessary() {
     // common flags. It means, that we are not allowed to *use* common flags
     // in this function.
     SanitizerToolName = "UndefinedBehaviorSanitizer";
-    CommonFlags *cf = common_flags();
-    SetCommonFlagsDefaults(cf);
-    cf->print_summary = false;
-    // Common flags may only be modified via UBSAN_OPTIONS.
-    ParseCommonFlagsFromString(cf, GetEnv("UBSAN_OPTIONS"));
+    InitializeCommonFlags();
     Symbolizer::GetOrInit();
   }
   // Initialize UBSan-specific flags.





More information about the llvm-commits mailing list