Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 31512fe

Browse files
committed
MIR Parser: Use source locations for MBB naming errors.
This commit changes the type of the field 'Name' in the struct 'yaml::MachineBasicBlock' from 'std::string' to 'yaml::StringValue'. This change allows the MIR parser to report errors related to the MBB name with the proper source locations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241718 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ea64a51 commit 31512fe

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

include/llvm/CodeGen/MIRYamlMapping.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace yaml {
8383

8484
struct MachineBasicBlock {
8585
unsigned ID;
86-
std::string Name;
86+
StringValue Name;
8787
unsigned Alignment = 0;
8888
bool IsLandingPad = false;
8989
bool AddressTaken = false;
@@ -97,7 +97,7 @@ template <> struct MappingTraits<MachineBasicBlock> {
9797
static void mapping(IO &YamlIO, MachineBasicBlock &MBB) {
9898
YamlIO.mapRequired("id", MBB.ID);
9999
YamlIO.mapOptional("name", MBB.Name,
100-
std::string()); // Don't print out an empty name.
100+
StringValue()); // Don't print out an empty name.
101101
YamlIO.mapOptional("alignment", MBB.Alignment);
102102
YamlIO.mapOptional("isLandingPad", MBB.IsLandingPad);
103103
YamlIO.mapOptional("addressTaken", MBB.AddressTaken);

lib/CodeGen/MIRParser/MIRParser.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class MIRParserImpl {
6060
/// Always returns true.
6161
bool error(const Twine &Message);
6262

63+
/// Report an error with the given message at the given location.
64+
///
65+
/// Always returns true.
66+
bool error(SMLoc Loc, const Twine &Message);
67+
6368
/// Report a given error with the location translated from the location in an
6469
/// embedded string literal to a location in the MIR file.
6570
///
@@ -124,6 +129,12 @@ bool MIRParserImpl::error(const Twine &Message) {
124129
return true;
125130
}
126131

132+
bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
133+
Context.diagnose(DiagnosticInfoMIRParser(
134+
DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
135+
return true;
136+
}
137+
127138
bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
128139
assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
129140
reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
@@ -239,12 +250,15 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
239250
const auto &F = *MF.getFunction();
240251
for (const auto &YamlMBB : YamlMF.BasicBlocks) {
241252
const BasicBlock *BB = nullptr;
242-
if (!YamlMBB.Name.empty()) {
253+
const yaml::StringValue &Name = YamlMBB.Name;
254+
if (!Name.Value.empty()) {
243255
BB = dyn_cast_or_null<BasicBlock>(
244-
F.getValueSymbolTable().lookup(YamlMBB.Name));
256+
F.getValueSymbolTable().lookup(Name.Value));
245257
if (!BB)
246-
return error(Twine("basic block '") + YamlMBB.Name +
247-
"' is not defined in the function '" + MF.getName() + "'");
258+
return error(Name.SourceRange.Start,
259+
Twine("basic block '") + Name.Value +
260+
"' is not defined in the function '" + MF.getName() +
261+
"'");
248262
}
249263
auto *MBB = MF.CreateMachineBasicBlock(BB);
250264
MF.insert(MF.end(), MBB);

lib/CodeGen/MIRPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
127127
YamlMBB.ID = (unsigned)MBB.getNumber();
128128
// TODO: Serialize unnamed BB references.
129129
if (const auto *BB = MBB.getBasicBlock())
130-
YamlMBB.Name = BB->hasName() ? BB->getName() : "<unnamed bb>";
130+
YamlMBB.Name.Value = BB->hasName() ? BB->getName() : "<unnamed bb>";
131131
else
132-
YamlMBB.Name = "";
132+
YamlMBB.Name.Value = "";
133133
YamlMBB.Alignment = MBB.getAlignment();
134134
YamlMBB.AddressTaken = MBB.hasAddressTaken();
135135
YamlMBB.IsLandingPad = MBB.isLandingPad();

test/CodeGen/MIR/machine-basic-block-unknown-name.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
---
1414
name: foo
1515
body:
16-
# CHECK: basic block 'entrie' is not defined in the function 'foo'
16+
# CHECK: [[@LINE+2]]:18: basic block 'entrie' is not defined in the function 'foo'
1717
- id: 0
1818
name: entrie
1919
...

0 commit comments

Comments
 (0)