Skip to content

Commit 3c4ee27

Browse files
maurerGuillaumeGomez
authored andcommitted
CFI: Use Instance at callsites
We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances.
1 parent d1e26db commit 3c4ee27

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
539539
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
540540
let builtin_unreachable: RValue<'gcc> =
541541
unsafe { std::mem::transmute(builtin_unreachable) };
542-
self.call(self.type_void(), None, None, builtin_unreachable, &[], None);
542+
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None);
543543
}
544544

545545
// Write results to outputs.

src/builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::ty::layout::{
2525
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
2626
TyAndLayout,
2727
};
28-
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
28+
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt, Instance};
2929
use rustc_span::def_id::DefId;
3030
use rustc_span::Span;
3131
use rustc_target::abi::{
@@ -592,12 +592,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
592592
then: Block<'gcc>,
593593
catch: Block<'gcc>,
594594
_funclet: Option<&Funclet>,
595+
instance: Option<Instance<'tcx>>,
595596
) -> RValue<'gcc> {
596597
let try_block = self.current_func().new_block("try");
597598

598599
let current_block = self.block;
599600
self.block = try_block;
600-
let call = self.call(typ, fn_attrs, None, func, args, None); // TODO(antoyo): use funclet here?
601+
let call = self.call(typ, fn_attrs, None, func, args, None, instance); // TODO(antoyo): use funclet here?
601602
self.block = current_block;
602603

603604
let return_value =
@@ -1667,6 +1668,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
16671668
func: RValue<'gcc>,
16681669
args: &[RValue<'gcc>],
16691670
funclet: Option<&Funclet>,
1671+
_instance: Option<Instance<'tcx>>,
16701672
) -> RValue<'gcc> {
16711673
// FIXME(antoyo): remove when having a proper API.
16721674
let gcc_func = unsafe { std::mem::transmute(func) };

src/intrinsic/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
138138
func,
139139
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
140140
None,
141+
None,
141142
)
142143
}
143144
sym::likely => self.expect(args[0].immediate(), true),
@@ -406,7 +407,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
406407
fn abort(&mut self) {
407408
let func = self.context.get_builtin_function("abort");
408409
let func: RValue<'gcc> = unsafe { std::mem::transmute(func) };
409-
self.call(self.type_void(), None, None, func, &[], None);
410+
self.call(self.type_void(), None, None, func, &[], None, None);
410411
}
411412

412413
fn assume(&mut self, value: Self::Value) {
@@ -1108,7 +1109,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
11081109
dest: RValue<'gcc>,
11091110
) {
11101111
if bx.sess().panic_strategy() == PanicStrategy::Abort {
1111-
bx.call(bx.type_void(), None, None, try_func, &[data], None);
1112+
bx.call(bx.type_void(), None, None, try_func, &[data], None, None);
11121113
// Return 0 unconditionally from the intrinsic call;
11131114
// we can never unwind.
11141115
let ret_align = bx.tcx.data_layout.i32_align.abi;
@@ -1182,21 +1183,21 @@ fn codegen_gnu_try<'gcc>(
11821183
let zero = bx.cx.context.new_rvalue_zero(bx.int_type);
11831184
let ptr = bx.cx.context.new_call(None, eh_pointer_builtin, &[zero]);
11841185
let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void());
1185-
bx.call(catch_ty, None, None, catch_func, &[data, ptr], None);
1186+
bx.call(catch_ty, None, None, catch_func, &[data, ptr], None, None);
11861187
bx.ret(bx.const_i32(1));
11871188

11881189
// NOTE: the blocks must be filled before adding the try/catch, otherwise gcc will not
11891190
// generate a try/catch.
11901191
// FIXME(antoyo): add a check in the libgccjit API to prevent this.
11911192
bx.switch_to_block(current_block);
1192-
bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None);
1193+
bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None, None);
11931194
});
11941195

11951196
let func = unsafe { std::mem::transmute(func) };
11961197

11971198
// Note that no invoke is used here because by definition this function
11981199
// can't panic (that's what it's catching).
1199-
let ret = bx.call(llty, None, None, func, &[try_func, data, catch_func], None);
1200+
let ret = bx.call(llty, None, None, func, &[try_func, data, catch_func], None, None);
12001201
let i32_align = bx.tcx().data_layout.i32_align.abi;
12011202
bx.store(ret, dest, i32_align);
12021203
}

0 commit comments

Comments
 (0)