[PM] Fix a bunch of bugs I spotted by inspection when working on this
authorChandler Carruth <chandlerc@gmail.com>
Sun, 12 Jan 2014 10:02:02 +0000 (10:02 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 12 Jan 2014 10:02:02 +0000 (10:02 +0000)
code. Copious tests added to cover these cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199039 91177308-0d34-0410-b5e6-96231b3b80d8

test/Other/pass-pipeline-parsing.ll
tools/opt/Passes.cpp

index c7fab01d2bf4da7c1f08a5b0e6e29fe367534359..ba336108c90fb5e77b5b915797763d6fc34a23c7 100644 (file)
 ; 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
 }
index 4a6341d5123757fbdc2d1de65ac95aeb64cb83c2..29be9dee94e042d1dbc48bdf727d110598cecc45 100644 (file)
@@ -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;