From ffcba8010b8b38b0cb68935f7f4d28531892b2be Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 1 Feb 2016 23:46:02 -0500 Subject: [PATCH] Add LLVM ModulePass regression test using run-make. Part of #31185 --- mk/tests.mk | 3 +- src/etc/maketest.py | 1 + src/test/run-make/llvm-module-pass/Makefile | 8 +++ .../run-make/llvm-module-pass/llvm-pass.so.cc | 55 +++++++++++++++++++ src/test/run-make/llvm-module-pass/main.rs | 14 +++++ src/test/run-make/llvm-module-pass/plugin.rs | 26 +++++++++ 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/test/run-make/llvm-module-pass/Makefile create mode 100644 src/test/run-make/llvm-module-pass/llvm-pass.so.cc create mode 100644 src/test/run-make/llvm-module-pass/main.rs create mode 100644 src/test/run-make/llvm-module-pass/plugin.rs diff --git a/mk/tests.mk b/mk/tests.mk index 19587a28d5594..2cc1a612cc9f3 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -1048,7 +1048,8 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \ $$(S) \ $(3) \ "$$(LLVM_LIBDIR_RUSTFLAGS_$(3))" \ - "$$(LLVM_ALL_COMPONENTS_$(3))" + "$$(LLVM_ALL_COMPONENTS_$(3))" \ + "$$(LLVM_CXXFLAGS_$(3))" @touch -r $$@.start_time $$@ && rm $$@.start_time else # FIXME #11094 - The above rule doesn't work right for multiple targets diff --git a/src/etc/maketest.py b/src/etc/maketest.py index 34c2cdbef3538..275785f874605 100644 --- a/src/etc/maketest.py +++ b/src/etc/maketest.py @@ -55,6 +55,7 @@ def convert_path_spec(name, value): putenv('S', os.path.abspath(sys.argv[13])) putenv('RUSTFLAGS', sys.argv[15]) putenv('LLVM_COMPONENTS', sys.argv[16]) +putenv('LLVM_CXXFLAGS', sys.argv[17]) putenv('PYTHON', sys.executable) os.putenv('TARGET', target_triple) 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 0000000000000..188b1f72e39b2 --- /dev/null +++ b/src/test/run-make/llvm-module-pass/Makefile @@ -0,0 +1,8 @@ +-include ../tools.mk + +all: $(call NATIVE_STATICLIB,llvm-pass) + $(RUSTC) plugin.rs -C prefer-dynamic + $(RUSTC) main.rs + +$(TMPDIR)/libllvm-pass.o: + $(CXX) $(LLVM_CXXFLAGS) -c llvm-pass.so.cc -o $(TMPDIR)/libllvm-pass.o 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 0000000000000..8723f24569775 --- /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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include +#include +#include + +#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); + llvm::Type *i = PointerType::get(Int8Ty, 0); + return true; +} + +char TestLLVMPass::ID = 0; + +static RegisterPass 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 0000000000000..5b5ab94bcef02 --- /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 or the MIT license +// , 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 0000000000000..039de3c717961 --- /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 or the MIT license +// , 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"); +}