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

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri May 29 11:21:07 PDT 2015


> On 2015-May-29, at 10:48, Alex Lorenz <arphaman at gmail.com> wrote:
> 
> 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.

LGTM.

> 
> 
> 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/
> <D10130.26796.patch>





More information about the llvm-commits mailing list