]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/llvm-pass/llvm-module-pass.so.cc
b3ee0c1a6c10bb2b909161c6e13d49171e287a6b
[rust.git] / src / test / run-make-fulldeps / llvm-pass / llvm-module-pass.so.cc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "llvm/IR/Module.h"
6
7 using namespace llvm;
8
9 namespace {
10
11   class TestLLVMPass : public ModulePass {
12
13   public:
14
15     static char ID;
16     TestLLVMPass() : ModulePass(ID) { }
17
18     bool runOnModule(Module &M) override;
19
20     StringRef getPassName() const override {
21       return "Some LLVM pass";
22     }
23
24   };
25
26 }
27
28 bool TestLLVMPass::runOnModule(Module &M) {
29   // A couple examples of operations that previously caused segmentation faults
30   // https://github.com/rust-lang/rust/issues/31067
31
32   for (auto F = M.begin(); F != M.end(); ++F) {
33     /* code */
34   }
35
36   LLVMContext &C = M.getContext();
37   IntegerType *Int8Ty  = IntegerType::getInt8Ty(C);
38   PointerType::get(Int8Ty, 0);
39   return true;
40 }
41
42 char TestLLVMPass::ID = 0;
43
44 static RegisterPass<TestLLVMPass> RegisterAFLPass(
45   "some-llvm-module-pass", "Some LLVM pass");