]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/llvm-module-pass/llvm-pass.so.cc
Auto merge of #31661 - steveklabnik:rollup, r=steveklabnik
[rust.git] / src / test / run-make / llvm-module-pass / llvm-pass.so.cc
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 #include "llvm/IR/Module.h"
16
17 using namespace llvm;
18
19 namespace {
20
21   class TestLLVMPass : public ModulePass {
22
23   public:
24
25     static char ID;
26     TestLLVMPass() : ModulePass(ID) { }
27
28     bool runOnModule(Module &M) override;
29
30     const char *getPassName() const override {
31       return "Some LLVM pass";
32     }
33
34   };
35
36 }
37
38 bool TestLLVMPass::runOnModule(Module &M) {
39   // A couple examples of operations that previously caused segmentation faults
40   // https://github.com/rust-lang/rust/issues/31067
41
42   for (auto F = M.begin(); F != M.end(); ++F) {
43     /* code */
44   }
45
46   LLVMContext &C = M.getContext();
47   IntegerType *Int8Ty  = IntegerType::getInt8Ty(C);
48   PointerType::get(Int8Ty, 0);
49   return true;
50 }
51
52 char TestLLVMPass::ID = 0;
53
54 static RegisterPass<TestLLVMPass> RegisterAFLPass(
55   "some-llvm-pass", "Some LLVM pass");