diff --git a/test/Other/pass-pipeline-parsing.ll b/test/Other/pass-pipeline-parsing.ll index c7fab01d2bf..ba336108c90 100644 --- a/test/Other/pass-pipeline-parsing.ll +++ b/test/Other/pass-pipeline-parsing.ll @@ -55,6 +55,56 @@ ; CHECK-MIXED-FP-AND-MP: Running module pass: NoOpModulePass ; CHECK-MIXED-FP-AND-MP: Finished module pass manager +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='no-op-module)' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED1 +; CHECK-UNBALANCED1: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='module(no-op-module))' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED2 +; CHECK-UNBALANCED2: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='module(no-op-module' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED3 +; CHECK-UNBALANCED3: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='no-op-function)' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED4 +; CHECK-UNBALANCED4: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='function(no-op-function))' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED5 +; CHECK-UNBALANCED5: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='function(function(no-op-function)))' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED6 +; CHECK-UNBALANCED6: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='function(no-op-function' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED7 +; CHECK-UNBALANCED7: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='function(function(no-op-function)' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED8 +; CHECK-UNBALANCED8: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='no-op-module,)' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED9 +; CHECK-UNBALANCED9: unable to parse pass pipeline description + +; RUN: not opt -disable-output -debug-pass-manager \ +; RUN: -passes='no-op-function,)' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED10 +; CHECK-UNBALANCED10: unable to parse pass pipeline description + define void @f() { ret void } diff --git a/tools/opt/Passes.cpp b/tools/opt/Passes.cpp index 4a6341d5123..29be9dee94e 100644 --- a/tools/opt/Passes.cpp +++ b/tools/opt/Passes.cpp @@ -50,7 +50,6 @@ static bool isFunctionPassName(StringRef Name) { } static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) { - assert(isModulePassName(Name)); if (Name == "no-op-module") { MPM.addPass(NoOpModulePass()); return true; @@ -59,7 +58,6 @@ static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) { } static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) { - assert(isFunctionPassName(Name)); if (Name == "no-op-function") { FPM.addPass(NoOpFunctionPass()); return true; @@ -76,9 +74,10 @@ static bool parseFunctionPassPipeline(FunctionPassManager &FPM, // Parse the inner pipeline inte the nested manager. PipelineText = PipelineText.substr(strlen("function(")); - if (!parseFunctionPassPipeline(NestedFPM, PipelineText)) + if (!parseFunctionPassPipeline(NestedFPM, PipelineText) || + PipelineText.empty()) return false; - assert(!PipelineText.empty() && PipelineText[0] == ')'); + assert(PipelineText[0] == ')'); PipelineText = PipelineText.substr(1); // Add the nested pass manager with the appropriate adaptor. @@ -109,9 +108,10 @@ static bool parseModulePassPipeline(ModulePassManager &MPM, // Parse the inner pipeline into the nested manager. PipelineText = PipelineText.substr(strlen("module(")); - if (!parseModulePassPipeline(NestedMPM, PipelineText)) + if (!parseModulePassPipeline(NestedMPM, PipelineText) || + PipelineText.empty()) return false; - assert(!PipelineText.empty() && PipelineText[0] == ')'); + assert(PipelineText[0] == ')'); PipelineText = PipelineText.substr(1); // Now add the nested manager as a module pass. @@ -121,9 +121,10 @@ static bool parseModulePassPipeline(ModulePassManager &MPM, // Parse the inner pipeline inte the nested manager. PipelineText = PipelineText.substr(strlen("function(")); - if (!parseFunctionPassPipeline(NestedFPM, PipelineText)) + if (!parseFunctionPassPipeline(NestedFPM, PipelineText) || + PipelineText.empty()) return false; - assert(!PipelineText.empty() && PipelineText[0] == ')'); + assert(PipelineText[0] == ')'); PipelineText = PipelineText.substr(1); // Add the nested pass manager with the appropriate adaptor. @@ -151,23 +152,24 @@ static bool parseModulePassPipeline(ModulePassManager &MPM, bool llvm::parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText) { // Look at the first entry to figure out which layer to start parsing at. if (PipelineText.startswith("module(")) - return parseModulePassPipeline(MPM, PipelineText); + return parseModulePassPipeline(MPM, PipelineText) && PipelineText.empty(); if (PipelineText.startswith("function(")) { FunctionPassManager FPM; - if (!parseFunctionPassPipeline(FPM, PipelineText)) + if (!parseFunctionPassPipeline(FPM, PipelineText) || !PipelineText.empty()) return false; MPM.addPass(createModuleToFunctionPassAdaptor(FPM)); return true; } // This isn't a direct pass manager name, look for the end of a pass name. - StringRef FirstName = PipelineText.substr(0, PipelineText.find_first_of(",")); + StringRef FirstName = + PipelineText.substr(0, PipelineText.find_first_of(",)")); if (isModulePassName(FirstName)) - return parseModulePassPipeline(MPM, PipelineText); + return parseModulePassPipeline(MPM, PipelineText) && PipelineText.empty(); if (isFunctionPassName(FirstName)) { FunctionPassManager FPM; - if (!parseFunctionPassPipeline(FPM, PipelineText)) + if (!parseFunctionPassPipeline(FPM, PipelineText) || !PipelineText.empty()) return false; MPM.addPass(createModuleToFunctionPassAdaptor(FPM)); return true;