1 //===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains "buggy" passes that are used to test bugpoint, to check
11 // that it is narrowing down testcases correctly.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/BasicBlock.h"
16 #include "llvm/IR/Constant.h"
17 #include "llvm/IR/InstVisitor.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/Type.h"
20 #include "llvm/Pass.h"
25 /// CrashOnCalls - This pass is used to test bugpoint. It intentionally
26 /// crashes on any call instructions.
27 class CrashOnCalls : public BasicBlockPass {
29 static char ID; // Pass ID, replacement for typeid
30 CrashOnCalls() : BasicBlockPass(ID) {}
32 void getAnalysisUsage(AnalysisUsage &AU) const override {
36 bool runOnBasicBlock(BasicBlock &BB) override {
37 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
38 if (isa<CallInst>(*I))
46 char CrashOnCalls::ID = 0;
47 static RegisterPass<CrashOnCalls>
48 X("bugpoint-crashcalls",
49 "BugPoint Test Pass - Intentionally crash on CallInsts");
52 /// DeleteCalls - This pass is used to test bugpoint. It intentionally
53 /// deletes some call instructions, "misoptimizing" the program.
54 class DeleteCalls : public BasicBlockPass {
56 static char ID; // Pass ID, replacement for typeid
57 DeleteCalls() : BasicBlockPass(ID) {}
59 bool runOnBasicBlock(BasicBlock &BB) override {
60 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
61 if (CallInst *CI = dyn_cast<CallInst>(I)) {
63 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
64 CI->getParent()->getInstList().erase(CI);
72 char DeleteCalls::ID = 0;
73 static RegisterPass<DeleteCalls>
74 Y("bugpoint-deletecalls",
75 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
78 /// CrashOnDeclFunc - This pass is used to test bugpoint. It intentionally
79 /// crash if the module has an undefined function (ie a function that is
80 /// defined in an external module).
81 class CrashOnDeclFunc : public ModulePass {
83 static char ID; // Pass ID, replacement for typeid
84 CrashOnDeclFunc() : ModulePass(ID) {}
86 bool runOnModule(Module &M) override {
87 for (auto &F : M.functions()) {
88 if (F.isDeclaration())
96 char CrashOnDeclFunc::ID = 0;
97 static RegisterPass<CrashOnDeclFunc>
98 Z("bugpoint-crash-decl-funcs",
99 "BugPoint Test Pass - Intentionally crash on declared functions");