Skip to content

Commit b3dcbc2

Browse files
committed
Avoid some boolean argument footguns
1 parent 1e57df1 commit b3dcbc2

File tree

1 file changed

+26
-10
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+26
-10
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::MemFlags;
1212
use rustc_ast as ast;
1313
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1414
use rustc_hir::lang_items::LangItem;
15-
use rustc_middle::mir::{self, AssertKind, SwitchTargets, UnwindTerminateReason};
15+
use rustc_middle::mir::{self, AssertKind, BasicBlock, SwitchTargets, UnwindTerminateReason};
1616
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
1717
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1818
use rustc_middle::ty::{self, Instance, Ty};
@@ -832,8 +832,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
832832
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
833833

834834
let mut llargs = Vec::with_capacity(arg_count);
835-
let ret_dest =
836-
self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs, true, true);
835+
let ret_dest = self.make_return_dest(
836+
bx,
837+
destination,
838+
&fn_abi.ret,
839+
&mut llargs,
840+
intrinsic,
841+
Some(target),
842+
);
837843
assert_eq!(llargs, []);
838844
if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
839845
location.val.store(bx, tmp);
@@ -854,8 +860,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
854860
destination,
855861
&fn_abi.ret,
856862
&mut llargs,
857-
true,
858-
target.is_some(),
863+
Some(intrinsic),
864+
target,
859865
);
860866
let dest = match ret_dest {
861867
_ if fn_abi.ret.is_indirect() => llargs[0],
@@ -919,7 +925,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
919925

920926
let mut llargs = Vec::with_capacity(arg_count);
921927
let destination = target.as_ref().map(|&target| {
922-
(self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs, false, true), target)
928+
(
929+
self.make_return_dest(
930+
bx,
931+
destination,
932+
&fn_abi.ret,
933+
&mut llargs,
934+
None,
935+
Some(target),
936+
),
937+
target,
938+
)
923939
});
924940

925941
// Split the rust-call tupled arguments off.
@@ -1652,10 +1668,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16521668
dest: mir::Place<'tcx>,
16531669
fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
16541670
llargs: &mut Vec<Bx::Value>,
1655-
is_intrinsic: bool,
1656-
has_target: bool,
1671+
intrinsic: Option<ty::IntrinsicDef>,
1672+
target: Option<BasicBlock>,
16571673
) -> ReturnDest<'tcx, Bx::Value> {
1658-
if !has_target {
1674+
if target.is_none() {
16591675
return ReturnDest::Nothing;
16601676
}
16611677
// If the return is ignored, we can just return a do-nothing `ReturnDest`.
@@ -1676,7 +1692,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16761692
tmp.storage_live(bx);
16771693
llargs.push(tmp.llval);
16781694
ReturnDest::IndirectOperand(tmp, index)
1679-
} else if is_intrinsic {
1695+
} else if intrinsic.is_some() {
16801696
// Currently, intrinsics always need a location to store
16811697
// the result, so we create a temporary `alloca` for the
16821698
// result.

0 commit comments

Comments
 (0)