Skip to content

Commit 86e6e32

Browse files
committed
Auto merge of #31391 - frewsxcv:test, r=alexcrichton
Part of #31185
2 parents 9d98390 + e5e2cdb commit 86e6e32

File tree

6 files changed

+113
-1
lines changed

6 files changed

+113
-1
lines changed

mk/tests.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,8 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
10711071
$$(S) \
10721072
$(3) \
10731073
"$$(LLVM_LIBDIR_RUSTFLAGS_$(3))" \
1074-
"$$(LLVM_ALL_COMPONENTS_$(3))"
1074+
"$$(LLVM_ALL_COMPONENTS_$(3))" \
1075+
"$$(LLVM_CXXFLAGS_$(3))"
10751076
@touch -r [email protected]_time $$@ && rm [email protected]_time
10761077
else
10771078
# FIXME #11094 - The above rule doesn't work right for multiple targets

src/etc/maketest.py

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def convert_path_spec(name, value):
4646
putenv('RUSTC', os.path.abspath(sys.argv[3]))
4747
putenv('TMPDIR', os.path.abspath(sys.argv[4]))
4848
putenv('CC', sys.argv[5] + ' ' + sys.argv[6])
49+
putenv('CFLAGS', sys.argv[6])
4950
putenv('RUSTDOC', os.path.abspath(sys.argv[7]))
5051
filt = sys.argv[8]
5152
putenv('LD_LIB_PATH_ENVVAR', sys.argv[9])
@@ -55,6 +56,7 @@ def convert_path_spec(name, value):
5556
putenv('S', os.path.abspath(sys.argv[13]))
5657
putenv('RUSTFLAGS', sys.argv[15])
5758
putenv('LLVM_COMPONENTS', sys.argv[16])
59+
putenv('LLVM_CXXFLAGS', sys.argv[17])
5860
putenv('PYTHON', sys.executable)
5961
os.putenv('TARGET', target_triple)
6062

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-include ../tools.mk
2+
3+
# Windows doesn't correctly handle include statements with escaping paths,
4+
# so this test will not get run on Windows.
5+
ifdef IS_WINDOWS
6+
all:
7+
else
8+
all: $(call NATIVE_STATICLIB,llvm-pass)
9+
$(RUSTC) plugin.rs -C prefer-dynamic
10+
$(RUSTC) main.rs
11+
12+
$(TMPDIR)/libllvm-pass.o:
13+
$(CXX) $(CFLAGS) $(LLVM_CXXFLAGS) -c llvm-pass.so.cc -o $(TMPDIR)/libllvm-pass.o
14+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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");
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
#![feature(plugin)]
12+
#![plugin(some_plugin)]
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
#![feature(plugin_registrar, rustc_private)]
12+
#![crate_type = "dylib"]
13+
#![crate_name = "some_plugin"]
14+
15+
extern crate rustc;
16+
extern crate rustc_plugin;
17+
18+
#[link(name = "llvm-pass", kind = "static")]
19+
extern {}
20+
21+
use rustc_plugin::registry::Registry;
22+
23+
#[plugin_registrar]
24+
pub fn plugin_registrar(reg: &mut Registry) {
25+
reg.register_llvm_pass("some-llvm-pass");
26+
}

0 commit comments

Comments
 (0)