[llvm] r174381 - Support: ensure proper state in ErrorOr copy ctors before calling 'get'
Meador Inge
meadori at codesourcery.com
Tue Feb 5 07:41:27 PST 2013
Author: meadori
Date: Tue Feb 5 09:41:27 2013
New Revision: 174381
URL: http://llvm.org/viewvc/llvm-project?rev=174381&view=rev
Log:
Support: ensure proper state in ErrorOr copy ctors before calling 'get'
Some paths through the copy constructors for 'ErrorOr' were calling
'get' when 'HasError' and 'IsValid' were not properly initialized.
Depending on what happened to be in memory for those member variables
the asserts in 'get' might incorrectly fire. Fixed by ensuring that
the member variables in question are always initialized before calling
'get'.
Modified:
llvm/trunk/include/llvm/Support/ErrorOr.h
Modified: llvm/trunk/include/llvm/Support/ErrorOr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ErrorOr.h?rev=174381&r1=174380&r2=174381&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ErrorOr.h (original)
+++ llvm/trunk/include/llvm/Support/ErrorOr.h Tue Feb 5 09:41:27 2013
@@ -204,18 +204,17 @@ public:
// Construct an invalid ErrorOr if other is invalid.
if (!Other.IsValid)
return;
+ IsValid = true;
if (!Other.HasError) {
// Get the other value.
- new (get()) storage_type(*Other.get());
HasError = false;
+ new (get()) storage_type(*Other.get());
} else {
// Get other's error.
Error = Other.Error;
HasError = true;
Error->aquire();
}
-
- IsValid = true;
}
ErrorOr &operator =(const ErrorOr &Other) {
@@ -234,11 +233,11 @@ public:
// Construct an invalid ErrorOr if other is invalid.
if (!Other.IsValid)
return;
+ IsValid = true;
if (!Other.HasError) {
// Get the other value.
- IsValid = true;
- new (get()) storage_type(std::move(*Other.get()));
HasError = false;
+ new (get()) storage_type(std::move(*Other.get()));
// Tell other not to do any destruction.
Other.IsValid = false;
} else {
@@ -248,8 +247,6 @@ public:
// Tell other not to do any destruction.
Other.IsValid = false;
}
-
- IsValid = true;
}
ErrorOr &operator =(ErrorOr &&Other) {
More information about the llvm-commits
mailing list