Skip to content

Commit af8db75

Browse files
committed
Support libgccjit12
1 parent 70659f7 commit af8db75

File tree

5 files changed

+58
-29
lines changed

5 files changed

+58
-29
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
libgccjit_version:
22-
- { gcc: "libgccjit.so", extra: "", artifacts_branch: "master" }
23-
- { gcc: "libgccjit_without_int128.so", extra: "", artifacts_branch: "master-without-128bit-integers" }
24-
- { gcc: "libgccjit12.so", extra: "--no-default-features", artifacts_branch: "gcc12" }
22+
- { gcc: "libgccjit.so", extra: "", env_extra: "", artifacts_branch: "master" }
23+
- { gcc: "libgccjit_without_int128.so", extra: "", env_extra: "", artifacts_branch: "master-without-128bit-integers" }
24+
- { gcc: "libgccjit12.so", extra: "--no-default-features", env_extra: "TEST_FLAGS='-Cpanic=abort -Zpanic-abort-tests'", artifacts_branch: "gcc12" }
2525
commands: [
2626
"--mini-tests",
2727
"--std-tests",
@@ -120,7 +120,7 @@ jobs:
120120
- name: Build
121121
run: |
122122
./prepare_build.sh
123-
./build.sh ${{ matrix.libgccjit_version.extra }}
123+
${{ matrix.libgccjit_version.env_extra }} ./build.sh ${{ matrix.libgccjit_version.extra }}
124124
cargo test ${{ matrix.libgccjit_version.extra }}
125125
./clean_all.sh
126126
@@ -143,7 +143,7 @@ jobs:
143143

144144
- name: Run tests
145145
run: |
146-
./test.sh --release --clean --build-sysroot ${{ matrix.commands }} ${{ matrix.libgccjit_version.extra }}
146+
${{ matrix.libgccjit_version.env_extra }} ./test.sh --release --clean --build-sysroot ${{ matrix.commands }} ${{ matrix.libgccjit_version.extra }}
147147
148148
duplicates:
149149
runs-on: ubuntu-latest

config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
3838
fi
3939
fi
4040

41-
export RUSTFLAGS="$CG_RUSTFLAGS $linker -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
41+
export RUSTFLAGS="$CG_RUSTFLAGS $linker -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot $TEST_FLAGS"
4242

4343
# FIXME(antoyo): remove once the atomic shim is gone
4444
if [[ `uname` == 'Darwin' ]]; then

src/builder.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use gccjit::{
1313
RValue,
1414
ToRValue,
1515
Type,
16-
UnaryOp, FunctionType,
16+
UnaryOp,
1717
};
1818
use rustc_codegen_ssa::MemFlags;
1919
use rustc_codegen_ssa::common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope};
@@ -476,11 +476,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
476476

477477
self.block.end_with_jump(None, then);
478478

479-
// NOTE: since jumps were added in a place rustc does not expect, the current blocks in the
480-
// state need to be updated.
481-
// FIXME: not sure it's actually needed.
482-
self.switch_to_block(then);
483-
484479
return_value.to_rvalue()
485480
}
486481

@@ -1194,12 +1189,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11941189
aggregate_value
11951190
}
11961191

1197-
fn set_personality_fn(&mut self, personality: RValue<'gcc>) {
1198-
let personality = self.rvalue_as_function(personality);
1192+
fn set_personality_fn(&mut self, _personality: RValue<'gcc>) {
11991193
#[cfg(feature="master")]
1200-
self.current_func().set_personality_function(personality);
1194+
{
1195+
let personality = self.rvalue_as_function(_personality);
1196+
self.current_func().set_personality_function(personality);
1197+
}
12011198
}
12021199

1200+
#[cfg(feature="master")]
12031201
fn cleanup_landing_pad(&mut self, _ty: Type<'gcc>, pers_fn: RValue<'gcc>) -> RValue<'gcc> {
12041202
self.set_personality_fn(pers_fn);
12051203

@@ -1223,16 +1221,33 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12231221
value.to_rvalue()
12241222
}
12251223

1224+
#[cfg(not(feature="master"))]
1225+
fn cleanup_landing_pad(&mut self, _ty: Type<'gcc>, _pers_fn: RValue<'gcc>) -> RValue<'gcc> {
1226+
let field1 = self.context.new_field(None, self.u8_type.make_pointer(), "landing_pad_field_1");
1227+
let field2 = self.context.new_field(None, self.i32_type, "landing_pad_field_1");
1228+
let struct_type = self.context.new_struct_type(None, "landing_pad", &[field1, field2]);
1229+
self.current_func().new_local(None, struct_type.as_type(), "landing_pad")
1230+
.to_rvalue()
1231+
}
1232+
1233+
#[cfg(feature="master")]
12261234
fn resume(&mut self, exn: RValue<'gcc>) {
12271235
// TODO: check if this is normal that we need to dereference the value.
1236+
// NOTE: the type is wrong, so in order to get a pointer for parameter, cast it to a
1237+
// pointer of pointer that is later dereferenced.
1238+
let exn_type = exn.get_type().make_pointer();
1239+
let exn = self.context.new_cast(None, exn, exn_type);
12281240
let exn = exn.dereference(None).to_rvalue();
1229-
let param = self.context.new_parameter(None, exn.get_type(), "exn");
1230-
// TODO(antoyo): should we call __builtin_unwind_resume instead? This might actually be the same.
1231-
let unwind_resume = self.context.new_function(None, FunctionType::Extern, self.type_void(), &[param], "_Unwind_Resume", false);
1241+
let unwind_resume = self.context.get_target_builtin_function("__builtin_unwind_resume");
12321242
self.llbb().add_eval(None, self.context.new_call(None, unwind_resume, &[exn]));
12331243
self.unreachable();
12341244
}
12351245

1246+
#[cfg(not(feature="master"))]
1247+
fn resume(&mut self, _exn: RValue<'gcc>) {
1248+
self.unreachable();
1249+
}
1250+
12361251
fn cleanup_pad(&mut self, _parent: Option<RValue<'gcc>>, _args: &[RValue<'gcc>]) -> Funclet {
12371252
unimplemented!();
12381253
}

src/intrinsic/mod.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod llvm;
22
mod simd;
33

4+
#[cfg(feature="master")]
45
use std::iter;
56

67
use gccjit::{ComparisonOp, Function, RValue, ToRValue, Type, UnaryOp, FunctionType};
@@ -9,16 +10,24 @@ use rustc_codegen_ssa::base::wants_msvc_seh;
910
use rustc_codegen_ssa::common::{IntPredicate, span_invalid_monomorphization_error};
1011
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1112
use rustc_codegen_ssa::mir::place::PlaceRef;
12-
use rustc_codegen_ssa::traits::{ArgAbiMethods, BaseTypeMethods, BuilderMethods, ConstMethods, DerivedTypeMethods, IntrinsicCallMethods, MiscMethods};
13+
use rustc_codegen_ssa::traits::{ArgAbiMethods, BaseTypeMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods};
14+
#[cfg(feature="master")]
15+
use rustc_codegen_ssa::traits::{DerivedTypeMethods, MiscMethods};
1316
use rustc_middle::bug;
1417
use rustc_middle::ty::{self, Instance, Ty};
15-
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf};
18+
use rustc_middle::ty::layout::LayoutOf;
19+
#[cfg(feature="master")]
20+
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
1621
use rustc_span::{Span, Symbol, symbol::kw, sym};
1722
use rustc_target::abi::HasDataLayout;
1823
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
19-
use rustc_target::spec::{abi::Abi, PanicStrategy};
24+
use rustc_target::spec::PanicStrategy;
25+
#[cfg(feature="master")]
26+
use rustc_target::spec::abi::Abi;
2027

21-
use crate::abi::{FnAbiGccExt, GccType};
28+
use crate::abi::GccType;
29+
#[cfg(feature="master")]
30+
use crate::abi::FnAbiGccExt;
2231
use crate::builder::Builder;
2332
use crate::common::{SignType, TypeReflection};
2433
use crate::context::CodegenCx;
@@ -1117,7 +1126,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
11171126
}
11181127
}
11191128

1120-
fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(bx: &'b mut Builder<'a, 'gcc, 'tcx>, try_func: RValue<'gcc>, data: RValue<'gcc>, catch_func: RValue<'gcc>, dest: RValue<'gcc>) {
1129+
fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(bx: &'b mut Builder<'a, 'gcc, 'tcx>, try_func: RValue<'gcc>, data: RValue<'gcc>, _catch_func: RValue<'gcc>, dest: RValue<'gcc>) {
11211130
if bx.sess().panic_strategy() == PanicStrategy::Abort {
11221131
bx.call(bx.type_void(), try_func, &[data], None);
11231132
// Return 0 unconditionally from the intrinsic call;
@@ -1129,7 +1138,10 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(bx: &'b mut Builder<'a, 'gcc, 'tcx>, try_fu
11291138
unimplemented!();
11301139
}
11311140
else {
1132-
codegen_gnu_try(bx, try_func, data, catch_func, dest);
1141+
#[cfg(feature="master")]
1142+
codegen_gnu_try(bx, try_func, data, _catch_func, dest);
1143+
#[cfg(not(feature="master"))]
1144+
unimplemented!();
11331145
}
11341146
}
11351147

@@ -1144,6 +1156,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(bx: &'b mut Builder<'a, 'gcc, 'tcx>, try_fu
11441156
// function calling it, and that function may already have other personality
11451157
// functions in play. By calling a shim we're guaranteed that our shim will have
11461158
// the right personality function.
1159+
#[cfg(feature="master")]
11471160
fn codegen_gnu_try<'gcc>(bx: &mut Builder<'_, 'gcc, '_>, try_func: RValue<'gcc>, data: RValue<'gcc>, catch_func: RValue<'gcc>, dest: RValue<'gcc>) {
11481161
//use std::ops::Deref;
11491162
//let cx: &CodegenCx<'gcc, '_> = bx.deref();
@@ -1210,6 +1223,7 @@ fn codegen_gnu_try<'gcc>(bx: &mut Builder<'_, 'gcc, '_>, try_func: RValue<'gcc>,
12101223
// catch exceptions.
12111224
//
12121225
// This function is only generated once and is then cached.
1226+
#[cfg(feature="master")]
12131227
fn get_rust_try_fn<'a, 'gcc, 'tcx>(cx: &'a CodegenCx<'gcc, 'tcx>, codegen: &mut dyn FnMut(Builder<'a, 'gcc, 'tcx>)) -> (Type<'gcc>, Function<'gcc>) {
12141228
if let Some(llfn) = cx.rust_try_fn.get() {
12151229
return llfn;
@@ -1249,6 +1263,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(cx: &'a CodegenCx<'gcc, 'tcx>, codegen: &mut
12491263

12501264
// Helper function to give a Block to a closure to codegen a shim function.
12511265
// This is currently primarily used for the `try` intrinsic functions above.
1266+
#[cfg(feature="master")]
12521267
fn gen_fn<'a, 'gcc, 'tcx>(cx: &'a CodegenCx<'gcc, 'tcx>, name: &str, rust_fn_sig: ty::PolyFnSig<'tcx>, codegen: &mut dyn FnMut(Builder<'a, 'gcc, 'tcx>)) -> (Type<'gcc>, Function<'gcc>) {
12531268
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
12541269
let (typ, _, _, _) = fn_abi.gcc_type(cx);

test.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ function std_tests() {
191191
$RUN_WRAPPER ./target/out/std_example --target $TARGET_TRIPLE
192192

193193
echo "[AOT] subslice-patterns-const-eval"
194-
$RUSTC example/subslice-patterns-const-eval.rs --crate-type bin --target $TARGET_TRIPLE
194+
$RUSTC example/subslice-patterns-const-eval.rs --crate-type bin $TEST_FLAGS --target $TARGET_TRIPLE
195195
$RUN_WRAPPER ./target/out/subslice-patterns-const-eval
196196

197197
echo "[AOT] track-caller-attribute"
198-
$RUSTC example/track-caller-attribute.rs --crate-type bin --target $TARGET_TRIPLE
198+
$RUSTC example/track-caller-attribute.rs --crate-type bin $TEST_FLAGS --target $TARGET_TRIPLE
199199
$RUN_WRAPPER ./target/out/track-caller-attribute
200200

201201
echo "[BUILD] mod_bench"
@@ -338,10 +338,9 @@ function test_rustc() {
338338

339339
git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR, but shouldn't be removed
340340

341-
rm -r src/test/ui/{abi*,extern/,panic-runtime/,panics/,unsized-locals/,proc-macro/,threads-sendsync/,thinlto/,borrowck/,chalkify/bugs/,test*,*lto*.rs,consts/const-float-bits-reject-conv.rs,consts/issue-miri-1910.rs} || true
341+
rm -r src/test/ui/{abi*,extern/,unsized-locals/,proc-macro/,threads-sendsync/,thinlto/,borrowck/,chalkify/bugs/,test*,*lto*.rs,consts/const-float-bits-reject-conv.rs,consts/issue-miri-1910.rs} || true
342342
rm src/test/ui/mir/mir_heavy_promoted.rs # this tests is oom-killed in the CI.
343-
# TODO: re-enable panics tests.
344-
for test in $(rg --files-with-matches "catch_unwind|should_panic|thread|lto" src/test/ui); do
343+
for test in $(rg --files-with-matches "thread|lto" src/test/ui); do
345344
rm $test
346345
done
347346
git checkout src/test/ui/lto/auxiliary/dylib.rs

0 commit comments

Comments
 (0)