Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -31,6 +31,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/SaveAndRestore.h" #include #include #include @@ -310,11 +311,9 @@ void ScriptParser::readAsNeeded() { expect("("); - bool Orig = Config->AsNeeded; - Config->AsNeeded = true; + SaveAndRestore Restore(Config->AsNeeded, true); while (!errorCount() && !consume(")")) addFile(unquote(next())); - Config->AsNeeded = Orig; } void ScriptParser::readEntry() { @@ -333,11 +332,9 @@ } void ScriptParser::readGroup() { - bool Orig = InputFile::IsInGroup; - InputFile::IsInGroup = true; + SaveAndRestore Restore(InputFile::IsInGroup, true); readInput(); - InputFile::IsInGroup = Orig; - if (!Orig) + if (!Restore.get()) ++InputFile::NextGroupId; } @@ -939,10 +936,8 @@ Expr ScriptParser::readExpr() { // Our lexer is context-aware. Set the in-expression bit so that // they apply different tokenization rules. - bool Orig = InExpr; - InExpr = true; + SaveAndRestore Restore(InExpr, true); Expr E = readExpr1(readPrimary(), 0); - InExpr = Orig; return E; }