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

Alex Lorenz arphaman at gmail.com
Fri May 29 10:48:22 PDT 2015


I just saw that I can remove the check for the empty function's name - it should go into another patch.

The updated patch doesn't check if the function's name is empty.


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,20 +109,25 @@
 
   // 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;
+  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.26796.patch
Type: text/x-patch
Size: 2565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150529/950d361d/attachment.bin>


More information about the llvm-commits mailing list