Skip to content

Add LLVM FunctionPass regression test using run-make. #31669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/test/run-make/llvm-module-pass/Makefile

This file was deleted.

17 changes: 17 additions & 0 deletions src/test/run-make/llvm-pass/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-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-function-pass) $(call NATIVE_STATICLIB,llvm-module-pass)
$(RUSTC) plugin.rs -C prefer-dynamic
$(RUSTC) main.rs

$(TMPDIR)/libllvm-function-pass.o:
$(CXX) $(CFLAGS) $(LLVM_CXXFLAGS) -c llvm-function-pass.so.cc -o $(TMPDIR)/libllvm-function-pass.o

$(TMPDIR)/libllvm-module-pass.o:
$(CXX) $(CFLAGS) $(LLVM_CXXFLAGS) -c llvm-module-pass.so.cc -o $(TMPDIR)/libllvm-module-pass.o
endif
56 changes: 56 additions & 0 deletions src/test/run-make/llvm-pass/llvm-function-pass.so.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,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");
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ bool TestLLVMPass::runOnModule(Module &M) {
char TestLLVMPass::ID = 0;

static RegisterPass<TestLLVMPass> RegisterAFLPass(
"some-llvm-pass", "Some LLVM pass");
"some-llvm-module-pass", "Some LLVM pass");
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
extern crate rustc;
extern crate rustc_plugin;

#[link(name = "llvm-pass", kind = "static")]
#[link(name = "llvm-function-pass", kind = "static")]
#[link(name = "llvm-module-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");
reg.register_llvm_pass("some-llvm-function-pass");
reg.register_llvm_pass("some-llvm-module-pass");
}