[llvm] r241718 - MIR Parser: Use source locations for MBB naming errors.

Alex Lorenz arphaman at gmail.com
Wed Jul 8 13:22:21 PDT 2015


Author: arphaman
Date: Wed Jul  8 15:22:20 2015
New Revision: 241718

URL: http://llvm.org/viewvc/llvm-project?rev=241718&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h
    llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
    llvm/trunk/lib/CodeGen/MIRPrinter.cpp
    llvm/trunk/test/CodeGen/MIR/machine-basic-block-unknown-name.mir

Modified: llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h?rev=241718&r1=241717&r2=241718&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MIRYamlMapping.h Wed Jul  8 15:22:20 2015
@@ -83,7 +83,7 @@ namespace yaml {
 
 struct MachineBasicBlock {
   unsigned ID;
-  std::string Name;
+  StringValue Name;
   unsigned Alignment = 0;
   bool IsLandingPad = false;
   bool AddressTaken = false;
@@ -97,7 +97,7 @@ template <> struct MappingTraits<Machine
   static void mapping(IO &YamlIO, MachineBasicBlock &MBB) {
     YamlIO.mapRequired("id", MBB.ID);
     YamlIO.mapOptional("name", MBB.Name,
-                       std::string()); // Don't print out an empty name.
+                       StringValue()); // Don't print out an empty name.
     YamlIO.mapOptional("alignment", MBB.Alignment);
     YamlIO.mapOptional("isLandingPad", MBB.IsLandingPad);
     YamlIO.mapOptional("addressTaken", MBB.AddressTaken);

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp?rev=241718&r1=241717&r2=241718&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp Wed Jul  8 15:22:20 2015
@@ -60,6 +60,11 @@ public:
   /// Always returns true.
   bool error(const Twine &Message);
 
+  /// Report an error with the given message at the given location.
+  ///
+  /// Always returns true.
+  bool error(SMLoc Loc, const Twine &Message);
+
   /// Report a given error with the location translated from the location in an
   /// embedded string literal to a location in the MIR file.
   ///
@@ -124,6 +129,12 @@ bool MIRParserImpl::error(const Twine &M
   return true;
 }
 
+bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
+  Context.diagnose(DiagnosticInfoMIRParser(
+      DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
+  return true;
+}
+
 bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
   assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
   reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
@@ -239,12 +250,15 @@ bool MIRParserImpl::initializeMachineFun
   const auto &F = *MF.getFunction();
   for (const auto &YamlMBB : YamlMF.BasicBlocks) {
     const BasicBlock *BB = nullptr;
-    if (!YamlMBB.Name.empty()) {
+    const yaml::StringValue &Name = YamlMBB.Name;
+    if (!Name.Value.empty()) {
       BB = dyn_cast_or_null<BasicBlock>(
-          F.getValueSymbolTable().lookup(YamlMBB.Name));
+          F.getValueSymbolTable().lookup(Name.Value));
       if (!BB)
-        return error(Twine("basic block '") + YamlMBB.Name +
-                     "' is not defined in the function '" + MF.getName() + "'");
+        return error(Name.SourceRange.Start,
+                     Twine("basic block '") + Name.Value +
+                         "' is not defined in the function '" + MF.getName() +
+                         "'");
     }
     auto *MBB = MF.CreateMachineBasicBlock(BB);
     MF.insert(MF.end(), MBB);

Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=241718&r1=241717&r2=241718&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Wed Jul  8 15:22:20 2015
@@ -127,9 +127,9 @@ void MIRPrinter::convert(ModuleSlotTrack
   YamlMBB.ID = (unsigned)MBB.getNumber();
   // TODO: Serialize unnamed BB references.
   if (const auto *BB = MBB.getBasicBlock())
-    YamlMBB.Name = BB->hasName() ? BB->getName() : "<unnamed bb>";
+    YamlMBB.Name.Value = BB->hasName() ? BB->getName() : "<unnamed bb>";
   else
-    YamlMBB.Name = "";
+    YamlMBB.Name.Value = "";
   YamlMBB.Alignment = MBB.getAlignment();
   YamlMBB.AddressTaken = MBB.hasAddressTaken();
   YamlMBB.IsLandingPad = MBB.isLandingPad();

Modified: llvm/trunk/test/CodeGen/MIR/machine-basic-block-unknown-name.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/machine-basic-block-unknown-name.mir?rev=241718&r1=241717&r2=241718&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/machine-basic-block-unknown-name.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/machine-basic-block-unknown-name.mir Wed Jul  8 15:22:20 2015
@@ -13,7 +13,7 @@
 ---
 name:            foo
 body:
-  # CHECK: basic block 'entrie' is not defined in the function 'foo'
+  # CHECK: [[@LINE+2]]:18: basic block 'entrie' is not defined in the function 'foo'
   - id:          0
     name:        entrie
 ...





More information about the llvm-commits mailing list