diff options
| author | bors <bors@rust-lang.org> | 2016-02-14 08:25:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-14 08:25:39 +0000 |
| commit | 86e6e3235ee0df25ce41dcb48a08387125d31d35 (patch) | |
| tree | 1900b9613b5651a8233eb975dd3caeaeccf443e5 /src/test | |
| parent | 9d98390765bbe61ce2a39b40c99ae1a68bb6d1cc (diff) | |
| parent | e5e2cdb9e3aa49ac1e83d6375c324a90e0329b7d (diff) | |
| download | rust-86e6e3235ee0df25ce41dcb48a08387125d31d35.tar.gz rust-86e6e3235ee0df25ce41dcb48a08387125d31d35.zip | |
Auto merge of #31391 - frewsxcv:test, r=alexcrichton
Part of #31185
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-make/llvm-module-pass/Makefile | 14 | ||||
| -rw-r--r-- | src/test/run-make/llvm-module-pass/llvm-pass.so.cc | 55 | ||||
| -rw-r--r-- | src/test/run-make/llvm-module-pass/main.rs | 14 | ||||
| -rw-r--r-- | src/test/run-make/llvm-module-pass/plugin.rs | 26 |
4 files changed, 109 insertions, 0 deletions
diff --git a/src/test/run-make/llvm-module-pass/Makefile b/src/test/run-make/llvm-module-pass/Makefile new file mode 100644 index 00000000000..93c7c4f5001 --- /dev/null +++ b/src/test/run-make/llvm-module-pass/Makefile @@ -0,0 +1,14 @@ +-include ../tools.mk + +# Windows doesn't correctly handle include statements with escaping paths, +# so this test will not get run on Windows. +ifdef IS_WINDOWS +all: +else +all: $(call NATIVE_STATICLIB,llvm-pass) + $(RUSTC) plugin.rs -C prefer-dynamic + $(RUSTC) main.rs + +$(TMPDIR)/libllvm-pass.o: + $(CXX) $(CFLAGS) $(LLVM_CXXFLAGS) -c llvm-pass.so.cc -o $(TMPDIR)/libllvm-pass.o +endif diff --git a/src/test/run-make/llvm-module-pass/llvm-pass.so.cc b/src/test/run-make/llvm-module-pass/llvm-pass.so.cc new file mode 100644 index 00000000000..06b0d6c300c --- /dev/null +++ b/src/test/run-make/llvm-module-pass/llvm-pass.so.cc @@ -0,0 +1,55 @@ +// 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/IR/Module.h" + +using namespace llvm; + +namespace { + + class TestLLVMPass : public ModulePass { + + public: + + static char ID; + TestLLVMPass() : ModulePass(ID) { } + + bool runOnModule(Module &M) override; + + const char *getPassName() const override { + return "Some LLVM pass"; + } + + }; + +} + +bool TestLLVMPass::runOnModule(Module &M) { + // A couple examples of operations that previously caused segmentation faults + // https://github.com/rust-lang/rust/issues/31067 + + for (auto F = M.begin(); F != M.end(); ++F) { + /* code */ + } + + LLVMContext &C = M.getContext(); + IntegerType *Int8Ty = IntegerType::getInt8Ty(C); + PointerType::get(Int8Ty, 0); + return true; +} + +char TestLLVMPass::ID = 0; + +static RegisterPass<TestLLVMPass> RegisterAFLPass( + "some-llvm-pass", "Some LLVM pass"); diff --git a/src/test/run-make/llvm-module-pass/main.rs b/src/test/run-make/llvm-module-pass/main.rs new file mode 100644 index 00000000000..5b5ab94bcef --- /dev/null +++ b/src/test/run-make/llvm-module-pass/main.rs @@ -0,0 +1,14 @@ +// 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. + +#![feature(plugin)] +#![plugin(some_plugin)] + +fn main() {} diff --git a/src/test/run-make/llvm-module-pass/plugin.rs b/src/test/run-make/llvm-module-pass/plugin.rs new file mode 100644 index 00000000000..039de3c7179 --- /dev/null +++ b/src/test/run-make/llvm-module-pass/plugin.rs @@ -0,0 +1,26 @@ +// 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. + +#![feature(plugin_registrar, rustc_private)] +#![crate_type = "dylib"] +#![crate_name = "some_plugin"] + +extern crate rustc; +extern crate rustc_plugin; + +#[link(name = "llvm-pass", kind = "static")] +extern {} + +use rustc_plugin::registry::Registry; + +#[plugin_registrar] +pub fn plugin_registrar(reg: &mut Registry) { + reg.register_llvm_pass("some-llvm-pass"); +} |
