[llvm] r293847 - Re-submit r293820: Return Error instead of bool from mergeTypeStreams().
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 16:47:10 PST 2017
Author: ruiu
Date: Wed Feb 1 18:47:10 2017
New Revision: 293847
URL: http://llvm.org/viewvc/llvm-project?rev=293847&view=rev
Log:
Re-submit r293820: Return Error instead of bool from mergeTypeStreams().
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h
llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h?rev=293847&r1=293846&r2=293847&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h Wed Feb 1 18:47:10 2017
@@ -13,12 +13,13 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
+#include "llvm/Support/Error.h"
namespace llvm {
namespace codeview {
/// Merges one type stream into another. Returns true on success.
-bool mergeTypeStreams(TypeTableBuilder &DestStream, const CVTypeArray &Types);
+Error mergeTypeStreams(TypeTableBuilder &DestStream, const CVTypeArray &Types);
} // end namespace codeview
} // end namespace llvm
Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp?rev=293847&r1=293846&r2=293847&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp Wed Feb 1 18:47:10 2017
@@ -55,9 +55,7 @@ namespace {
class TypeStreamMerger : public TypeVisitorCallbacks {
public:
TypeStreamMerger(TypeTableBuilder &DestStream)
- : DestStream(DestStream), FieldListBuilder(DestStream) {
- assert(!hadError());
- }
+ : DestStream(DestStream), FieldListBuilder(DestStream) {}
/// TypeVisitorCallbacks overrides.
#define TYPE_RECORD(EnumName, EnumVal, Name) \
@@ -74,12 +72,15 @@ public:
Error visitTypeEnd(CVType &Record) override;
Error visitMemberEnd(CVMemberRecord &Record) override;
- bool mergeStream(const CVTypeArray &Types);
+ Error mergeStream(const CVTypeArray &Types);
private:
template <typename RecordType>
Error visitKnownRecordImpl(RecordType &Record) {
- FoundBadTypeIndex |= !Record.remapTypeIndices(IndexMap);
+ if (!Record.remapTypeIndices(IndexMap))
+ LastError = joinErrors(
+ std::move(*LastError),
+ llvm::make_error<CodeViewError>(cv_error_code::corrupt_record));
IndexMap.push_back(DestStream.writeKnownType(Record));
return Error::success();
}
@@ -94,14 +95,15 @@ private:
template <typename RecordType>
Error visitKnownMemberRecordImpl(RecordType &Record) {
- FoundBadTypeIndex |= !Record.remapTypeIndices(IndexMap);
+ if (!Record.remapTypeIndices(IndexMap))
+ LastError = joinErrors(
+ std::move(*LastError),
+ llvm::make_error<CodeViewError>(cv_error_code::corrupt_record));
FieldListBuilder.writeMemberType(Record);
return Error::success();
}
- bool hadError() { return FoundBadTypeIndex; }
-
- bool FoundBadTypeIndex = false;
+ Optional<Error> LastError;
BumpPtrAllocator Allocator;
@@ -163,9 +165,10 @@ Error TypeStreamMerger::visitUnknownType
return llvm::make_error<CodeViewError>(cv_error_code::corrupt_record);
}
-bool TypeStreamMerger::mergeStream(const CVTypeArray &Types) {
+Error TypeStreamMerger::mergeStream(const CVTypeArray &Types) {
assert(IndexMap.empty());
TypeVisitorCallbackPipeline Pipeline;
+ LastError = Error::success();
TypeDeserializer Deserializer;
Pipeline.addCallbackToPipeline(Deserializer);
@@ -173,15 +176,16 @@ bool TypeStreamMerger::mergeStream(const
CVTypeVisitor Visitor(Pipeline);
- if (auto EC = Visitor.visitTypeStream(Types)) {
- consumeError(std::move(EC));
- return false;
- }
+ if (auto EC = Visitor.visitTypeStream(Types))
+ return EC;
IndexMap.clear();
- return !hadError();
+
+ Error Ret = std::move(*LastError);
+ LastError.reset();
+ return Ret;
}
-bool llvm::codeview::mergeTypeStreams(TypeTableBuilder &DestStream,
- const CVTypeArray &Types) {
+Error llvm::codeview::mergeTypeStreams(TypeTableBuilder &DestStream,
+ const CVTypeArray &Types) {
return TypeStreamMerger(DestStream).mergeStream(Types);
}
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=293847&r1=293846&r2=293847&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Wed Feb 1 18:47:10 2017
@@ -1086,8 +1086,10 @@ void COFFDumper::mergeCodeViewTypes(Type
error(object_error::parse_failed);
}
- if (!mergeTypeStreams(CVTypes, Types))
+ if (auto EC = mergeTypeStreams(CVTypes, Types)) {
+ consumeError(std::move(EC));
return error(object_error::parse_failed);
+ }
}
}
}
More information about the llvm-commits
mailing list