[PATCH] MIR Serialization: Report an error when machine functions have the same name.

Alex Lorenz arphaman at gmail.com
Fri May 29 10:42:25 PDT 2015


Hi dexonsmith, bogner, bob.wilson,

This patch is based on the patch that connects MIRParser to the machine function analysis pass (http://reviews.llvm.org/D9928).

This patch reports an error when the mir parser encounters a machine function with the name that is the same as the name of a different machine function.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D10130

Files:
  lib/CodeGen/MIRParser/MIRParser.cpp
  test/CodeGen/MIR/machine-function-redefinition-error.mir

Index: lib/CodeGen/MIRParser/MIRParser.cpp
===================================================================
--- lib/CodeGen/MIRParser/MIRParser.cpp
+++ lib/CodeGen/MIRParser/MIRParser.cpp
@@ -42,6 +42,9 @@
   MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
                 LLVMContext &Context);
 
+  /// Return an error at an unknown location with the given message.
+  SMDiagnostic error(const Twine &Msg);
+
   /// Try to parse the optional LLVM module and the machine functions in the MIR
   /// file.
   ///
@@ -51,7 +54,7 @@
   /// Parse the machine function in the current YAML document.
   ///
   /// Return true if an error occurred.
-  bool parseMachineFunction(yaml::Input &In);
+  bool parseMachineFunction(yaml::Input &In, SMDiagnostic &Error);
 
   /// Initialize the machine function to the state that's described in the MIR
   /// file.
@@ -68,6 +71,10 @@
   SM.AddNewSourceBuffer(std::move(Contents), SMLoc());
 }
 
+SMDiagnostic MIRParserImpl::error(const Twine &Msg) {
+  return SM.GetMessage(SMLoc(), SourceMgr::DK_Error, Msg);
+}
+
 static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
   *reinterpret_cast<SMDiagnostic *>(Context) = Diag;
 }
@@ -102,21 +109,28 @@
 
   // Parse the machine functions.
   do {
-    if (parseMachineFunction(In))
+    if (parseMachineFunction(In, Error))
       return nullptr;
     In.nextDocument();
   } while (In.setCurrentDocument());
 
   return M;
 }
 
-bool MIRParserImpl::parseMachineFunction(yaml::Input &In) {
+bool MIRParserImpl::parseMachineFunction(yaml::Input &In, SMDiagnostic &Error) {
   auto MF = llvm::make_unique<yaml::MachineFunction>();
   yaml::yamlize(In, *MF, false);
   if (In.error())
     return true;
   auto FunctionName = MF->Name;
-  Functions.insert(std::make_pair(FunctionName, std::move(MF)));
+  if (!FunctionName.empty()) {
+    if (Functions.find(FunctionName) != Functions.end()) {
+      Error = error(Twine("redefinition of machine function '") + FunctionName +
+                    "'");
+      return true;
+    }
+    Functions.insert(std::make_pair(FunctionName, std::move(MF)));
+  }
   return false;
 }
 
Index: test/CodeGen/MIR/machine-function-redefinition-error.mir
===================================================================
--- /dev/null
+++ test/CodeGen/MIR/machine-function-redefinition-error.mir
@@ -0,0 +1,10 @@
+# RUN: not llc -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
+# This test ensures that the machine function errors are reported correctly.
+
+---
+name:            foo
+...
+---
+# CHECK: error: redefinition of machine function 'foo'
+name:            foo
+...

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10130.26795.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150529/bc60f0d8/attachment.bin>


More information about the llvm-commits mailing list