Skip to content

Commit 98f0dc1

Browse files
authored
Merge pull request rust-lang#224 from rust-lang/fix/gep-release-mode
Add CI tests with a sysroot compiled in release mode
2 parents 8ead881 + 908304e commit 98f0dc1

File tree

6 files changed

+146
-21
lines changed

6 files changed

+146
-21
lines changed

.github/workflows/release.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: CI with sysroot compiled in release mode
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
permissions:
8+
contents: read
9+
10+
env:
11+
# Enable backtraces for easier debugging
12+
RUST_BACKTRACE: 1
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
libgccjit_version:
22+
- { gcc: "libgccjit.so", artifacts_branch: "master" }
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- uses: actions/checkout@v2
28+
with:
29+
repository: llvm/llvm-project
30+
path: llvm
31+
32+
- name: Install packages
33+
run: sudo apt-get install ninja-build ripgrep
34+
35+
- name: Download artifact
36+
uses: dawidd6/action-download-artifact@v2
37+
with:
38+
workflow: main.yml
39+
name: ${{ matrix.libgccjit_version.gcc }}
40+
path: gcc-build
41+
repo: antoyo/gcc
42+
branch: ${{ matrix.libgccjit_version.artifacts_branch }}
43+
event: push
44+
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.
45+
46+
- name: Setup path to libgccjit
47+
run: |
48+
echo $(readlink -f gcc-build) > gcc_path
49+
# NOTE: the filename is still libgccjit.so even when the artifact name is different.
50+
ln gcc-build/libgccjit.so gcc-build/libgccjit.so.0
51+
52+
- name: Set env
53+
run: |
54+
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
55+
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
56+
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
57+
58+
- name: Set RUST_COMPILER_RT_ROOT
59+
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
60+
61+
# https://github.com/actions/cache/issues/133
62+
- name: Fixup owner of ~/.cargo/
63+
# Don't remove the trailing /. It is necessary to follow the symlink.
64+
run: sudo chown -R $(whoami):$(id -ng) ~/.cargo/
65+
66+
- name: Cache cargo installed crates
67+
uses: actions/[email protected]
68+
with:
69+
path: ~/.cargo/bin
70+
key: cargo-installed-crates2-ubuntu-latest
71+
72+
- name: Cache cargo registry
73+
uses: actions/cache@v1
74+
with:
75+
path: ~/.cargo/registry
76+
key: ${{ runner.os }}-cargo-registry2-${{ hashFiles('**/Cargo.lock') }}
77+
78+
- name: Cache cargo index
79+
uses: actions/cache@v1
80+
with:
81+
path: ~/.cargo/git
82+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
83+
84+
- name: Cache cargo target dir
85+
uses: actions/[email protected]
86+
with:
87+
path: target
88+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}
89+
90+
- name: Build
91+
run: |
92+
./prepare_build.sh
93+
./build.sh --release --release-sysroot
94+
cargo test
95+
./clean_all.sh
96+
97+
- name: Prepare dependencies
98+
run: |
99+
git config --global user.email "[email protected]"
100+
git config --global user.name "User"
101+
./prepare.sh
102+
103+
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
104+
- name: Compile
105+
uses: actions-rs/[email protected]
106+
with:
107+
command: build
108+
args: --release
109+
110+
- name: Run tests
111+
run: |
112+
./test.sh --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests # --test-libcore # FIXME(antoyo): libcore tests fail.

src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
5757
if env::var("CG_GCCJIT_DUMP_TO_FILE").as_deref() == Ok("1") {
5858
let _ = fs::create_dir("/tmp/gccjit_dumps");
5959
let path = &format!("/tmp/gccjit_dumps/{}.c", module.name);
60+
context.set_debug_info(true);
6061
context.dump_to_file(path, true);
6162
}
6263
context.compile_to_file(OutputKind::ObjectFile, obj_out.to_str().expect("path to str"));

src/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol, supports_
126126
context.add_command_line_option("-fdata-sections");
127127
}
128128

129+
if env::var("CG_GCCJIT_DUMP_TREE_ALL").as_deref() == Ok("1") {
130+
context.add_command_line_option("-fdump-tree-all");
131+
}
129132
if env::var("CG_GCCJIT_DUMP_CODE").as_deref() == Ok("1") {
130133
context.set_dump_code_on_compile(true);
131134
}

src/builder.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -858,26 +858,31 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
858858
}
859859

860860
fn gep(&mut self, _typ: Type<'gcc>, ptr: RValue<'gcc>, indices: &[RValue<'gcc>]) -> RValue<'gcc> {
861-
let mut result = ptr;
861+
let ptr_type = ptr.get_type();
862+
let mut pointee_type = ptr.get_type();
863+
// NOTE: we cannot use array indexing here like in inbounds_gep because array indexing is
864+
// always considered in bounds in GCC (TODO(antoyo): to be verified).
865+
// So, we have to cast to a number.
866+
let mut result = self.context.new_bitcast(None, ptr, self.sizet_type);
867+
// FIXME(antoyo): if there were more than 1 index, this code is probably wrong and would
868+
// require dereferencing the pointer.
862869
for index in indices {
863-
result = self.context.new_array_access(None, result, *index).get_address(None).to_rvalue();
870+
pointee_type = pointee_type.get_pointee().expect("pointee type");
871+
let pointee_size = self.context.new_rvalue_from_int(index.get_type(), pointee_type.get_size() as i32);
872+
result = result + self.gcc_int_cast(*index * pointee_size, self.sizet_type);
864873
}
865-
result
874+
self.context.new_bitcast(None, result, ptr_type)
866875
}
867876

868877
fn inbounds_gep(&mut self, _typ: Type<'gcc>, ptr: RValue<'gcc>, indices: &[RValue<'gcc>]) -> RValue<'gcc> {
869-
// FIXME(antoyo): would be safer if doing the same thing (loop) as gep.
870-
// TODO(antoyo): specify inbounds somehow.
871-
match indices.len() {
872-
1 => {
873-
self.context.new_array_access(None, ptr, indices[0]).get_address(None)
874-
},
875-
2 => {
876-
let array = ptr.dereference(None); // TODO(antoyo): assert that first index is 0?
877-
self.context.new_array_access(None, array, indices[1]).get_address(None)
878-
},
879-
_ => unimplemented!(),
878+
// NOTE: array indexing is always considered in bounds in GCC (TODO(antoyo): to be verified).
879+
let mut indices = indices.into_iter();
880+
let index = indices.next().expect("first index in inbounds_gep");
881+
let mut result = self.context.new_array_access(None, ptr, *index);
882+
for index in indices {
883+
result = self.context.new_array_access(None, result, *index);
880884
}
885+
result.get_address(None)
881886
}
882887

883888
fn struct_gep(&mut self, value_type: Type<'gcc>, ptr: RValue<'gcc>, idx: u64) -> RValue<'gcc> {

src/int.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,22 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
389389
};
390390
self.context.new_comparison(None, op, cmp, self.context.new_rvalue_from_int(self.int_type, limit))
391391
}
392+
else if a_type.get_pointee().is_some() && b_type.get_pointee().is_some() {
393+
// NOTE: gcc cannot compare pointers to different objects, but rustc does that, so cast them to usize.
394+
lhs = self.context.new_bitcast(None, lhs, self.usize_type);
395+
rhs = self.context.new_bitcast(None, rhs, self.usize_type);
396+
self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs)
397+
}
392398
else {
393-
let left_type = lhs.get_type();
394-
let right_type = rhs.get_type();
395-
if left_type != right_type {
399+
if a_type != b_type {
396400
// NOTE: because libgccjit cannot compare function pointers.
397-
if left_type.dyncast_function_ptr_type().is_some() && right_type.dyncast_function_ptr_type().is_some() {
401+
if a_type.dyncast_function_ptr_type().is_some() && b_type.dyncast_function_ptr_type().is_some() {
398402
lhs = self.context.new_cast(None, lhs, self.usize_type.make_pointer());
399403
rhs = self.context.new_cast(None, rhs, self.usize_type.make_pointer());
400404
}
401405
// NOTE: hack because we try to cast a vector type to the same vector type.
402-
else if format!("{:?}", left_type) != format!("{:?}", right_type) {
403-
rhs = self.context.new_cast(None, rhs, left_type);
406+
else if format!("{:?}", a_type) != format!("{:?}", b_type) {
407+
rhs = self.context.new_cast(None, rhs, a_type);
404408
}
405409
}
406410
self.context.new_comparison(None, op.to_gcc_comparison(), lhs, rhs)

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ while [[ $# -gt 0 ]]; do
4444
shift
4545
;;
4646
"--test-rustc")
47-
funcs=(test_rustc)
47+
funcs+=(test_rustc)
4848
shift
4949
;;
5050
"--test-successful-rustc")

0 commit comments

Comments
 (0)