Remove const reference to errorReporter.
Fixes use-after-free ASAN failure.
PiperOrigin-RevId: 204177796
diff --git a/lib/Parser/Lexer.cpp b/lib/Parser/Lexer.cpp
index 8e94560..ffc12c8 100644
--- a/lib/Parser/Lexer.cpp
+++ b/lib/Parser/Lexer.cpp
@@ -31,8 +31,7 @@
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();
diff --git a/lib/Parser/Lexer.h b/lib/Parser/Lexer.h
index 730bbc9..f9cdfb6 100644
--- a/lib/Parser/Lexer.h
+++ b/lib/Parser/Lexer.h
@@ -30,7 +30,7 @@
/// 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 @@
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) {
diff --git a/lib/Parser/Parser.cpp b/lib/Parser/Parser.cpp
index 8c8ffa0..3eff98c 100644
--- a/lib/Parser/Parser.cpp
+++ b/lib/Parser/Parser.cpp
@@ -1660,8 +1660,7 @@
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;