diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2015-01-02 21:28:37 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2015-01-02 21:28:37 +0000 |
commit | 5445e3a45fb91761c7be96a35b9cdc7194881ccd (patch) | |
tree | 547504987ce7b2ff55d399d57d22fe78c3b52327 /lib/sanitizer_common/sanitizer_flags.h | |
parent | ee2d9890ccbda9ef229eeacc8ede3dd365284f4c (diff) |
Revert "Revert r224736: "[Sanitizer] Make CommonFlags immutable after initialization.""
Fix test failures by introducing CommonFlags::CopyFrom() to make sure
compiler doesn't insert memcpy() calls into runtime code.
Original commit message:
Protect CommonFlags singleton by adding const qualifier to
common_flags() accessor. The only ways to modify the flags are
SetCommonFlagsDefaults(), ParseCommonFlagsFromString() and
OverrideCommonFlags() functions, which are only supposed to be
called during initialization.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225088 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_flags.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_flags.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_flags.h b/lib/sanitizer_common/sanitizer_flags.h index f71cf43b2..c39bb7817 100644 --- a/lib/sanitizer_common/sanitizer_flags.h +++ b/lib/sanitizer_common/sanitizer_flags.h @@ -69,11 +69,13 @@ struct CommonFlags { void SetDefaults(); void ParseFromString(const char *str); + + void CopyFrom(const CommonFlags &other); }; // Functions to get/set global CommonFlags shared by all sanitizer runtimes: extern CommonFlags common_flags_dont_use; -inline CommonFlags *common_flags() { +inline const CommonFlags *common_flags() { return &common_flags_dont_use; } @@ -84,6 +86,16 @@ inline void SetCommonFlagsDefaults() { inline void ParseCommonFlagsFromString(const char *str) { common_flags_dont_use.ParseFromString(str); } + +// This function can only be used to setup tool-specific overrides for +// CommonFlags defaults. Generally, it should only be used right after +// SetCommonFlagsDefaults(), but before ParseCommonFlagsFromString(), and +// only during the flags initialization (i.e. before they are used for +// the first time). +inline void OverrideCommonFlags(const CommonFlags &cf) { + common_flags_dont_use.CopyFrom(cf); +} + void PrintFlagDescriptions(); } // namespace __sanitizer |