[llvm] r199039 - [PM] Fix a bunch of bugs I spotted by inspection when working on this
Chandler Carruth
chandlerc at gmail.com
Sun Jan 12 02:02:02 PST 2014
Author: chandlerc
Date: Sun Jan 12 04:02:02 2014
New Revision: 199039
URL: http://llvm.org/viewvc/llvm-project?rev=199039&view=rev
Log:
[PM] Fix a bunch of bugs I spotted by inspection when working on this
code. Copious tests added to cover these cases.
Modified:
llvm/trunk/test/Other/pass-pipeline-parsing.ll
llvm/trunk/tools/opt/Passes.cpp
Modified: llvm/trunk/test/Other/pass-pipeline-parsing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/pass-pipeline-parsing.ll?rev=199039&r1=199038&r2=199039&view=diff
==============================================================================
--- llvm/trunk/test/Other/pass-pipeline-parsing.ll (original)
+++ llvm/trunk/test/Other/pass-pipeline-parsing.ll Sun Jan 12 04:02:02 2014
@@ -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
}
Modified: llvm/trunk/tools/opt/Passes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/Passes.cpp?rev=199039&r1=199038&r2=199039&view=diff
==============================================================================
--- llvm/trunk/tools/opt/Passes.cpp (original)
+++ llvm/trunk/tools/opt/Passes.cpp Sun Jan 12 04:02:02 2014
@@ -50,7 +50,6 @@ static bool isFunctionPassName(StringRef
}
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(ModulePa
}
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(Fu
// 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(Modu
// 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(Modu
// 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(Modu
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;
More information about the llvm-commits
mailing list