(original) (raw)

bug/000755 000765 000000 00000000000 12413372400 012124 5ustar00tylerwheel000000 000000 bug/a.bc000644 000765 000000 00000001544 12413372351 012663 0ustar00tylerwheel000000 000000 BC��! � � �#�A�I29�� %�b�EB� B�28I 2D$H �!#�R� !r$�b���@��� 2" d�"��"ㄡ�L�� ��L$s`P � �#��@a�C�03���f=�C8�ÌB�yxs�q ���3 B��Ρf0=�C8���=�C=�=�x�tp{yH�ppzpvx�p q �8�D��8 a �P,%0P(�B83P 3P 3P 3P 3P 3P 3P �4��3��3�C3d 2�p���,C � R%��1bpF B0�0K�3�� B`� P4( �ƈ�`@ B0q0K�5#�`f �]c�A�`��p��`� �,�A֠l 7A�2 L@ڰ` D`c���aB� N� �@ 7k� � F��,�3K�� ��d �,�1K�P ��g �,A1�q��� B63 �pI�D~� o-0 ��H#Թ1����Ñ�>0 �H�̀_���t�1��D3�AR8�/8͠_B��tMm�!0O} G�D>��N��P�'` �O4����CNS !0�~ R�D3��5$��H#Ը ImBb�� 0�=1QQc1��<5m R��0D�p$� CtH�D~� �� �0�ˁ �9�)1U�b �,�m*C-P�a�\W�N� N3D�Y���& �a�,7� �?Dcbug/Test.cpp000644 000765 000000 00000005613 12413372365 013566 0ustar00tylerwheel000000 000000 #include "llvm/Pass.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/IR/Module.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Transforms/Utils/Cloning.h" #include using namespace llvm; class TestPass : public ModulePass { public: static char ID; TestPass() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { for (Module::iterator fit = M.begin(), fite = M.end(); fit != fite; ++fit) { Function *F = fit; Function *CloneF = createFunctionClone(F, M); std::set Is = getInstructions(F); evaluateFunction(CloneF, M); validateFunctionBody(F, Is); CloneF->eraseFromParent(); } return false; } private: // Return all instructions in the given Function. std::set getInstructions(Function *F) { std::set Is; for (Function::iterator bbit = F->begin(), bbite = F->end(); bbit != bbite; ++bbit) { BasicBlock *BB = bbit; for (BasicBlock::iterator it = BB->begin(), ite = BB->end(); it != ite; ++it) { Instruction *I = it; Is.insert(I); } } return Is; } // Assert that the given Function's instructions is equal to the given set. void validateFunctionBody(Function *F, const std::set &Is) { std::set CurrIs = getInstructions(F); std:📐:iterator a = CurrIs.begin(), b = Is.begin(); // Compare the two sets. while (a != CurrIs.end()) { if (b == Is.end() || *a != *b) assert(false); ++a; ++b; } } // JIT and evaluate the given function. void evaluateFunction(Function *F, Module &M) { std::string errStr; InitializeNativeTarget(); ExecutionEngine *EE = ExecutionEngine::create(&M, false, &errStr); if (EE == NULL) { errs() << "Could not create execution engine: " << errStr << "\n"; assert(false); } std::vector args; for (unsigned i = 0; i < F->arg_size(); i++) { GenericValue gv; gv.IntVal = APInt(32, 0); args.push_back(gv); } // Execute the function GenericValue v = EE->runFunction(F, args); } // Return a clone of the given function. Function *createFunctionClone(Function *F, Module &M) { ValueToValueMapTy argVmap; SmallVector returns; Function *CloneF = Function::Create(F->getFunctionType(), GlobalVariable::ExternalLinkage, "", &M); Function::arg_iterator DestI = CloneF->arg_begin(); for (Function::const_arg_iterator J = F->arg_begin(); J != F->arg_end(); ++J) { DestI->setName(J->getName()); argVmap[J] = DestI++; } CloneFunctionInto(CloneF, F, argVmap, true, returns); return CloneF; } }; char TestPass::ID = 0; static RegisterPass X("test", "Bug test pass", false, false);