summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/YAMLTraits.cpp
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-11-28 04:44:13 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-11-28 04:44:13 +0000
commitc54281be4f5d948504be604d8b2368e2f495c469 (patch)
tree6a5ae891c56f010a52c640eab66e637cd7221c85 /llvm/lib/Support/YAMLTraits.cpp
parent4cf2c89883717c481619946c68e14709c9613e90 (diff)
downloadbcm5719-llvm-c54281be4f5d948504be604d8b2368e2f495c469.tar.gz
bcm5719-llvm-c54281be4f5d948504be604d8b2368e2f495c469.zip
Improve error handling in YAML parsing
Some scanner errors were not checked and reported by the parser. Fix PR30934 Patch by: Serge Guelton <serge.guelton@telecom-bretagne.eu> Differential Revision: https://reviews.llvm.org/D26419 llvm-svn: 288014
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 75fac20a8ed..ccd0f45a514 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -112,7 +112,7 @@ bool Input::mapTag(StringRef Tag, bool Default) {
}
void Input::beginMapping() {
- if (EC)
+ if (hasError())
return;
// CurrentNode can be null if the document is empty.
MapHNode *MN = dyn_cast_or_null<MapHNode>(CurrentNode);
@@ -124,7 +124,7 @@ void Input::beginMapping() {
bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault,
void *&SaveInfo) {
UseDefault = false;
- if (EC)
+ if (hasError())
return false;
// CurrentNode is null for empty documents, which is an error in case required
@@ -159,7 +159,7 @@ void Input::postflightKey(void *saveInfo) {
}
void Input::endMapping() {
- if (EC)
+ if (hasError())
return;
// CurrentNode can be null if the document is empty.
MapHNode *MN = dyn_cast_or_null<MapHNode>(CurrentNode);
@@ -196,7 +196,7 @@ void Input::endSequence() {
}
bool Input::preflightElement(unsigned Index, void *&SaveInfo) {
- if (EC)
+ if (hasError())
return false;
if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
SaveInfo = CurrentNode;
@@ -213,7 +213,7 @@ void Input::postflightElement(void *SaveInfo) {
unsigned Input::beginFlowSequence() { return beginSequence(); }
bool Input::preflightFlowElement(unsigned index, void *&SaveInfo) {
- if (EC)
+ if (hasError())
return false;
if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
SaveInfo = CurrentNode;
@@ -271,7 +271,7 @@ bool Input::beginBitSetScalar(bool &DoClear) {
}
bool Input::bitSetMatch(const char *Str, bool) {
- if (EC)
+ if (hasError())
return false;
if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
unsigned Index = 0;
@@ -293,7 +293,7 @@ bool Input::bitSetMatch(const char *Str, bool) {
}
void Input::endBitSetScalar() {
- if (EC)
+ if (hasError())
return;
if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
assert(BitValuesUsed.size() == SQ->Entries.size());
@@ -321,6 +321,8 @@ void Input::setError(HNode *hnode, const Twine &message) {
this->setError(hnode->_node, message);
}
+bool Input::hasError() const { return EC || Strm->failed(); }
+
void Input::setError(Node *node, const Twine &message) {
Strm->printError(node, message);
EC = make_error_code(errc::invalid_argument);
@@ -342,7 +344,7 @@ std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) {
auto SQHNode = llvm::make_unique<SequenceHNode>(N);
for (Node &SN : *SQ) {
auto Entry = this->createHNodes(&SN);
- if (EC)
+ if (hasError())
break;
SQHNode->Entries.push_back(std::move(Entry));
}
@@ -363,7 +365,7 @@ std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) {
KeyStr = StringStorage.str().copy(StringAllocator);
}
auto ValueHNode = this->createHNodes(KVN.getValue());
- if (EC)
+ if (hasError())
break;
mapHNode->Mapping[KeyStr] = std::move(ValueHNode);
}
OpenPOWER on IntegriCloud