//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "BugDriver.h"
#include "ToolRunner.h"
#include "ListReducer.h"
-#include "llvm/Constant.h"
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Analysis/Verifier.h"
-#include "llvm/Bytecode/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Cloning.h"
BD.Program = ParseInputFile(PrefixOutput.toString());
if (BD.Program == 0) {
- std::cerr << BD.getToolName() << ": Error reading bytecode file '"
+ std::cerr << BD.getToolName() << ": Error reading bitcode file '"
<< PrefixOutput << "'!\n";
exit(1);
}
ReduceCrashingGlobalVariables::TestGlobalVariables(
std::vector<GlobalVariable*>& GVs) {
// Clone the program to try hacking it apart...
- Module *M = CloneModule(BD.getProgram());
+ DenseMap<const Value*, Value*> ValueMap;
+ Module *M = CloneModule(BD.getProgram(), ValueMap);
// Convert list to set for fast lookup...
std::set<GlobalVariable*> GVSet;
for (unsigned i = 0, e = GVs.size(); i != e; ++i) {
- GlobalVariable* CMGV = M->getNamedGlobal(GVs[i]->getName());
+ GlobalVariable* CMGV = cast<GlobalVariable>(ValueMap[GVs[i]]);
assert(CMGV && "Global Variable not in module?!");
GVSet.insert(CMGV);
}
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
(*SI)->removePredecessor(BB);
- if (BB->getTerminator()->getType() != Type::VoidTy)
- BB->getTerminator()->replaceAllUsesWith(
- Constant::getNullValue(BB->getTerminator()->getType()));
+ TerminatorInst *BBTerm = BB->getTerminator();
+
+ if (isa<StructType>(BBTerm->getType()))
+ BBTerm->replaceAllUsesWith(UndefValue::get(BBTerm->getType()));
+ else if (BB->getTerminator()->getType() != Type::VoidTy)
+ BBTerm->replaceAllUsesWith(Constant::getNullValue(BBTerm->getType()));
- // Delete the old terminator instruction...
+ // Replace the old terminator instruction.
BB->getInstList().pop_back();
-
- // Add a new return instruction of the appropriate type...
- const Type *RetTy = BB->getParent()->getReturnType();
- new ReturnInst(RetTy == Type::VoidTy ? 0 :
- Constant::getNullValue(RetTy), BB);
+ new UnreachableInst(BB);
}
// The CFG Simplifier pass may delete one of the basic blocks we are
ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs);
if (GVs.size() < OldSize)
- BD.EmitProgressBytecode("reduced-global-variables");
+ BD.EmitProgressBitcode("reduced-global-variables");
}
}
}
ReduceCrashingFunctions(BD, TestFn).reduceList(Functions);
if (Functions.size() < OldSize)
- BD.EmitProgressBytecode("reduced-function");
+ BD.EmitProgressBitcode("reduced-function");
}
// Attempt to delete entire basic blocks at a time to speed up
}
}
- BD.EmitProgressBytecode("reduced-simplified");
+ BD.EmitProgressBitcode("reduced-simplified");
return false;
}
<< (PassesToRun.size() == 1 ? ": " : "es: ")
<< getPassesString(PassesToRun) << '\n';
- EmitProgressBytecode(ID);
+ EmitProgressBitcode(ID);
return DebugACrash(*this, TestForOptimizerCrash);
}