[llvm] 2d3d2e7 - MIR: Fix parser crash on syntax error on first character
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 18 15:59:16 PST 2021
Author: Matt Arsenault
Date: 2021-02-18T18:59:08-05:00
New Revision: 2d3d2e78d08578f4699cc268b7c292c3ff97e7fe
URL: https://github.com/llvm/llvm-project/commit/2d3d2e78d08578f4699cc268b7c292c3ff97e7fe
DIFF: https://github.com/llvm/llvm-project/commit/2d3d2e78d08578f4699cc268b7c292c3ff97e7fe.diff
LOG: MIR: Fix parser crash on syntax error on first character
This was calling the diagnostic printer before the context member was
initialized.
Added:
llvm/test/CodeGen/MIR/Generic/first-character-parse-error.mir
Modified:
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 2d8613b41311..7dccd5da9c9a 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -51,9 +51,9 @@ namespace llvm {
/// file.
class MIRParserImpl {
SourceMgr SM;
+ LLVMContext &Context;
yaml::Input In;
StringRef Filename;
- LLVMContext &Context;
SlotMapping IRSlots;
std::unique_ptr<PerTargetMIParsingState> Target;
@@ -176,10 +176,11 @@ MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
StringRef Filename, LLVMContext &Context,
std::function<void(Function &)> Callback)
: SM(),
+ Context(Context),
In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))
->getBuffer(),
nullptr, handleYAMLDiag, this),
- Filename(Filename), Context(Context), ProcessIRFunction(Callback) {
+ Filename(Filename), ProcessIRFunction(Callback) {
In.setContext(&In);
}
diff --git a/llvm/test/CodeGen/MIR/Generic/first-character-parse-error.mir b/llvm/test/CodeGen/MIR/Generic/first-character-parse-error.mir
new file mode 100644
index 000000000000..00a01058dc8c
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/Generic/first-character-parse-error.mir
@@ -0,0 +1,14 @@
+:# RUN: not llc -run-pass=none %s -o - 2>&1 | FileCheck %s
+
+# The : before the run comment is syntactically invalid. This used to
+# crash in the SourceMgr diagnostic printer because it was called
+# before the LLVMContext was initialized.
+
+# CHECK: error: YAML:1:1: Unrecognized character while tokenizing.
+
+---
+name: foo
+body: |
+ bb.0:
+
+...
More information about the llvm-commits
mailing list