Recover gracefully when deserializing invalid YAML input.

Fixes http://llvm.org/PR16221, http://llvm.org/PR15927
Phabricator: http://llvm-reviews.chandlerc.com/D1236

Patch by Andrew Tulloch!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195016 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexander Kornienko
2013-11-18 15:50:04 +00:00
parent 64409ad8e3
commit 6919bec07f
3 changed files with 152 additions and 61 deletions

View File

@@ -685,16 +685,18 @@ private:
///
class Input : public IO {
public:
// Construct a yaml Input object from a StringRef and optional user-data.
Input(StringRef InputContent, void *Ctxt=NULL);
// Construct a yaml Input object from a StringRef and optional
// user-data. The DiagHandler can be specified to provide
// alternative error reporting.
Input(StringRef InputContent,
void *Ctxt = NULL,
SourceMgr::DiagHandlerTy DiagHandler = NULL,
void *DiagHandlerCtxt = NULL);
~Input();
// Check if there was an syntax or semantic error during parsing.
llvm::error_code error();
// To set alternate error reporting.
void setDiagHandler(llvm::SourceMgr::DiagHandlerTy Handler, void *Ctxt = 0);
static bool classof(const IO *io) { return !io->outputting(); }
private:
@@ -968,8 +970,8 @@ template <typename T>
inline
typename llvm::enable_if_c<has_SequenceTraits<T>::value,Input &>::type
operator>>(Input &yin, T &docSeq) {
yin.setCurrentDocument();
yamlize(yin, docSeq, true);
if (yin.setCurrentDocument())
yamlize(yin, docSeq, true);
return yin;
}