about summary refs log tree commit diff
path: root/src/test/run-make/llvm-pass/llvm-function-pass.so.cc
blob: 4470c400760b872097eed1cba80aaa21c2e8f415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "llvm/Pass.h"
#include "llvm/IR/Function.h"

using namespace llvm;

namespace {

  class TestLLVMPass : public FunctionPass {

  public:

    static char ID;
    TestLLVMPass() : FunctionPass(ID) { }

    bool runOnFunction(Function &F) override;

    const char *getPassName() const override {
      return "Some LLVM pass";
    }

  };

}

bool TestLLVMPass::runOnFunction(Function &F) {
  // A couple examples of operations that previously caused segmentation faults
  // https://github.com/rust-lang/rust/issues/31067

  for (auto N = F.begin(); N != F.end(); ++N) {
    /* code */
  }

  LLVMContext &C = F.getContext();
  IntegerType *Int8Ty  = IntegerType::getInt8Ty(C);
  PointerType::get(Int8Ty, 0);
  return true;
}

char TestLLVMPass::ID = 0;

static RegisterPass<TestLLVMPass> RegisterAFLPass(
  "some-llvm-function-pass", "Some LLVM pass");