[llvm-commits] [llvm] r170970 - /llvm/trunk/include/llvm/Support/YAMLTraits.h
Richard Smith
richard-llvm at metafoo.co.uk
Fri Dec 21 16:31:55 PST 2012
Author: rsmith
Date: Fri Dec 21 18:31:54 2012
New Revision: 170970
URL: http://llvm.org/viewvc/llvm-project?rev=170970&view=rev
Log:
Fix some undefined behavior when parsing YAML input: don't try to compare an
uninitialized value against a default value. Found by -fsanitize=enum.
Modified:
llvm/trunk/include/llvm/Support/YAMLTraits.h
Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=170970&r1=170969&r2=170970&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLTraits.h Fri Dec 21 18:31:54 2012
@@ -360,7 +360,7 @@
template <typename T>
void enumCase(T &Val, const char* Str, const T ConstVal) {
- if ( matchEnumScalar(Str, (Val == ConstVal)) ) {
+ if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
Val = ConstVal;
}
}
@@ -368,14 +368,14 @@
// allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
template <typename T>
void enumCase(T &Val, const char* Str, const uint32_t ConstVal) {
- if ( matchEnumScalar(Str, (Val == static_cast<T>(ConstVal))) ) {
+ if ( matchEnumScalar(Str, outputting() && Val == static_cast<T>(ConstVal)) ) {
Val = ConstVal;
}
}
template <typename T>
void bitSetCase(T &Val, const char* Str, const T ConstVal) {
- if ( bitSetMatch(Str, ((Val & ConstVal) == ConstVal)) ) {
+ if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
Val = Val | ConstVal;
}
}
@@ -383,7 +383,7 @@
// allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
template <typename T>
void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) {
- if ( bitSetMatch(Str, ((Val & ConstVal) == ConstVal)) ) {
+ if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
Val = Val | ConstVal;
}
}
@@ -423,7 +423,7 @@
bool Required) {
void *SaveInfo;
bool UseDefault;
- const bool sameAsDefault = (Val == DefaultValue);
+ const bool sameAsDefault = outputting() && Val == DefaultValue;
if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
SaveInfo) ) {
yamlize(*this, Val, Required);
More information about the llvm-commits
mailing list