Remove const reference to errorReporter.

Fixes use-after-free ASAN failure.

PiperOrigin-RevId: 204177796
This commit is contained in:
Jacques Pienaar 2018-07-11 13:26:23 -07:00 committed by jpienaar
parent 610e5a57f6
commit 4b6bf08b3b
4 changed files with 14 additions and 12 deletions

View File

@ -31,8 +31,7 @@ static bool isPunct(char c) {
return c == '$' || c == '.' || c == '_' || c == '-';
}
Lexer::Lexer(llvm::SourceMgr &sourceMgr,
const SMDiagnosticHandlerTy &errorReporter)
Lexer::Lexer(llvm::SourceMgr &sourceMgr, SMDiagnosticHandlerTy errorReporter)
: sourceMgr(sourceMgr), errorReporter(errorReporter) {
auto bufferID = sourceMgr.getMainFileID();
curBuffer = sourceMgr.getMemoryBuffer(bufferID)->getBuffer();

View File

@ -30,7 +30,7 @@ namespace mlir {
/// This class breaks up the current file into a token stream.
class Lexer {
llvm::SourceMgr &sourceMgr;
const SMDiagnosticHandlerTy &errorReporter;
const SMDiagnosticHandlerTy errorReporter;
StringRef curBuffer;
const char *curPtr;
@ -38,16 +38,16 @@ class Lexer {
Lexer(const Lexer&) = delete;
void operator=(const Lexer&) = delete;
public:
explicit Lexer(llvm::SourceMgr &sourceMgr,
const SMDiagnosticHandlerTy &errorReporter);
explicit Lexer(llvm::SourceMgr &sourceMgr,
SMDiagnosticHandlerTy errorReporter);
llvm::SourceMgr &getSourceMgr() { return sourceMgr; }
llvm::SourceMgr &getSourceMgr() { return sourceMgr; }
Token lexToken();
Token lexToken();
/// Change the position of the lexer cursor. The next token we lex will start
/// at the designated point in the input.
void resetPointer(const char *newPointer) { curPtr = newPointer; }
/// Change the position of the lexer cursor. The next token we lex will start
/// at the designated point in the input.
void resetPointer(const char *newPointer) { curPtr = newPointer; }
private:
// Helpers.
Token formToken(Token::Kind kind, const char *tokStart) {

View File

@ -1660,8 +1660,7 @@ Module *mlir::parseSourceFile(llvm::SourceMgr &sourceMgr, MLIRContext *context,
std::unique_ptr<Module> module(new Module(context));
ParserState state(sourceMgr, module.get(),
errorReporter ? std::move(errorReporter)
: defaultErrorReporter);
errorReporter ? errorReporter : defaultErrorReporter);
if (ModuleParser(state).parseModule())
return nullptr;

View File

@ -101,3 +101,7 @@ bb42:
}
; -----
#map = (d0) -> (% ; expected-error {{invalid SSA name}}
; -----