Skip to content

Commit 5033dd3

Browse files
committed
CFI: Append debug location to CFI blocks
1 parent 4d215e2 commit 5033dd3

File tree

13 files changed

+114
-37
lines changed

13 files changed

+114
-37
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+1-1
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, None);
542+
self.call(self.type_void(), None, None, builtin_unreachable, &[], None, None, None);
543543
}
544544

545545
// Write results to outputs.

compiler/rustc_codegen_gcc/src/builder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,13 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
598598
catch: Block<'gcc>,
599599
_funclet: Option<&Funclet>,
600600
instance: Option<Instance<'tcx>>,
601+
_dbg_loc: Option<Self::DILocation>,
601602
) -> RValue<'gcc> {
602603
let try_block = self.current_func().new_block("try");
603604

604605
let current_block = self.block;
605606
self.block = try_block;
606-
let call = self.call(typ, fn_attrs, None, func, args, None, instance); // TODO(antoyo): use funclet here?
607+
let call = self.call(typ, fn_attrs, None, func, args, None, instance, None); // TODO(antoyo): use funclet here?
607608
self.block = current_block;
608609

609610
let return_value =
@@ -1673,6 +1674,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
16731674
args: &[RValue<'gcc>],
16741675
funclet: Option<&Funclet>,
16751676
_instance: Option<Instance<'tcx>>,
1677+
_dbg_loc: Option<Self::DILocation>,
16761678
) -> RValue<'gcc> {
16771679
// FIXME(antoyo): remove when having a proper API.
16781680
let gcc_func = unsafe { std::mem::transmute::<RValue<'gcc>, Function<'gcc>>(func) };

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
405405
fn abort(&mut self) {
406406
let func = self.context.get_builtin_function("abort");
407407
let func: RValue<'gcc> = unsafe { std::mem::transmute(func) };
408-
self.call(self.type_void(), None, None, func, &[], None, None);
408+
self.call(self.type_void(), None, None, func, &[], None, None, None);
409409
}
410410

411411
fn assume(&mut self, value: Self::Value) {
@@ -1108,7 +1108,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
11081108
dest: RValue<'gcc>,
11091109
) {
11101110
if bx.sess().panic_strategy() == PanicStrategy::Abort {
1111-
bx.call(bx.type_void(), None, None, try_func, &[data], None, None);
1111+
bx.call(bx.type_void(), None, None, try_func, &[data], None, None, None);
11121112
// Return 0 unconditionally from the intrinsic call;
11131113
// we can never unwind.
11141114
let ret_align = bx.tcx.data_layout.i32_align.abi;
@@ -1182,21 +1182,21 @@ fn codegen_gnu_try<'gcc>(
11821182
let zero = bx.cx.context.new_rvalue_zero(bx.int_type);
11831183
let ptr = bx.cx.context.new_call(None, eh_pointer_builtin, &[zero]);
11841184
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, None);
1185+
bx.call(catch_ty, None, None, catch_func, &[data, ptr], None, None, None);
11861186
bx.ret(bx.const_i32(1));
11871187

11881188
// NOTE: the blocks must be filled before adding the try/catch, otherwise gcc will not
11891189
// generate a try/catch.
11901190
// FIXME(antoyo): add a check in the libgccjit API to prevent this.
11911191
bx.switch_to_block(current_block);
1192-
bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None, None);
1192+
bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None, None, None);
11931193
});
11941194

11951195
let func = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) };
11961196

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

compiler/rustc_codegen_llvm/src/asm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,11 @@ pub(crate) fn inline_asm_call<'ll>(
475475

476476
let call = if !labels.is_empty() {
477477
assert!(catch_funclet.is_none());
478-
bx.callbr(fty, None, None, v, inputs, dest.unwrap(), labels, None, None)
478+
bx.callbr(fty, None, None, v, inputs, dest.unwrap(), labels, None, None, None)
479479
} else if let Some((catch, funclet)) = catch_funclet {
480-
bx.invoke(fty, None, None, v, inputs, dest.unwrap(), catch, funclet, None)
480+
bx.invoke(fty, None, None, v, inputs, dest.unwrap(), catch, funclet, None, None)
481481
} else {
482-
bx.call(fty, None, None, v, inputs, None, None)
482+
bx.call(fty, None, None, v, inputs, None, None, None)
483483
};
484484

485485
// Store mark in a metadata node so we can map LLVM errors

compiler/rustc_codegen_llvm/src/builder.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::abi::FnAbiLlvmExt;
3030
use crate::attributes;
3131
use crate::common::Funclet;
3232
use crate::context::CodegenCx;
33+
use crate::llvm::debuginfo::DILocation;
3334
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True};
3435
use crate::type_::Type;
3536
use crate::type_of::LayoutLlvmExt;
@@ -234,6 +235,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
234235
catch: &'ll BasicBlock,
235236
funclet: Option<&Funclet<'ll>>,
236237
instance: Option<Instance<'tcx>>,
238+
dbg_loc: Option<&'ll DILocation>,
237239
) -> &'ll Value {
238240
debug!("invoke {:?} with args ({:?})", llfn, args);
239241

@@ -245,7 +247,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
245247
}
246248

247249
// Emit CFI pointer type membership test
248-
self.cfi_type_test(fn_attrs, fn_abi, instance, llfn);
250+
self.cfi_type_test(fn_attrs, fn_abi, instance, dbg_loc, llfn);
249251

250252
// Emit KCFI operand bundle
251253
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
@@ -1172,6 +1174,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11721174
args: &[&'ll Value],
11731175
funclet: Option<&Funclet<'ll>>,
11741176
instance: Option<Instance<'tcx>>,
1177+
dbg_loc: Option<&'ll DILocation>,
11751178
) -> &'ll Value {
11761179
debug!("call {:?} with args ({:?})", llfn, args);
11771180

@@ -1183,7 +1186,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11831186
}
11841187

11851188
// Emit CFI pointer type membership test
1186-
self.cfi_type_test(fn_attrs, fn_abi, instance, llfn);
1189+
self.cfi_type_test(fn_attrs, fn_abi, instance, dbg_loc, llfn);
11871190

11881191
// Emit KCFI operand bundle
11891192
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
@@ -1414,7 +1417,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
14141417

14151418
pub(crate) fn call_intrinsic(&mut self, intrinsic: &str, args: &[&'ll Value]) -> &'ll Value {
14161419
let (ty, f) = self.cx.get_intrinsic(intrinsic);
1417-
self.call(ty, None, None, f, args, None, None)
1420+
self.call(ty, None, None, f, args, None, None, None)
14181421
}
14191422

14201423
fn call_lifetime_intrinsic(&mut self, intrinsic: &str, ptr: &'ll Value, size: Size) {
@@ -1472,7 +1475,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
14721475
format!("llvm.{instr}.sat.i{int_width}.f{float_width}")
14731476
};
14741477
let f = self.declare_cfn(&name, llvm::UnnamedAddr::No, self.type_func(&[src_ty], dest_ty));
1475-
self.call(self.type_func(&[src_ty], dest_ty), None, None, f, &[val], None, None)
1478+
self.call(self.type_func(&[src_ty], dest_ty), None, None, f, &[val], None, None, None)
14761479
}
14771480

14781481
pub(crate) fn landing_pad(
@@ -1501,6 +1504,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15011504
indirect_dest: &[&'ll BasicBlock],
15021505
funclet: Option<&Funclet<'ll>>,
15031506
instance: Option<Instance<'tcx>>,
1507+
dbg_loc: Option<&'ll DILocation>,
15041508
) -> &'ll Value {
15051509
debug!("invoke {:?} with args ({:?})", llfn, args);
15061510

@@ -1512,7 +1516,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15121516
}
15131517

15141518
// Emit CFI pointer type membership test
1515-
self.cfi_type_test(fn_attrs, fn_abi, instance, llfn);
1519+
self.cfi_type_test(fn_attrs, fn_abi, instance, dbg_loc, llfn);
15161520

15171521
// Emit KCFI operand bundle
15181522
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
@@ -1547,6 +1551,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15471551
fn_attrs: Option<&CodegenFnAttrs>,
15481552
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
15491553
instance: Option<Instance<'tcx>>,
1554+
dbg_loc: Option<&'ll DILocation>,
15501555
llfn: &'ll Value,
15511556
) {
15521557
let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) };
@@ -1582,10 +1587,16 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15821587
self.cond_br(cond, bb_pass, bb_fail);
15831588

15841589
self.switch_to_block(bb_fail);
1590+
if let Some(dbg_loc) = dbg_loc {
1591+
self.set_dbg_loc(dbg_loc);
1592+
}
15851593
self.abort();
15861594
self.unreachable();
15871595

15881596
self.switch_to_block(bb_pass);
1597+
if let Some(dbg_loc) = dbg_loc {
1598+
self.set_dbg_loc(dbg_loc);
1599+
}
15891600
}
15901601
}
15911602

0 commit comments

Comments
 (0)