Auto merge of #104862 - saethlin:mir-niche-checks, r= · rust-lang/rust@eaa4669 (original) (raw)

`@@ -572,7 +572,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

`

572

572

`mergeable_succ: bool,

`

573

573

`) -> MergingSucc {

`

574

574

`let span = terminator.source_info.span;

`

575

``

`-

let cond = self.codegen_operand(bx, cond).immediate();

`

``

575

`+

let mut cond = self.codegen_operand(bx, cond).immediate();

`

576

576

`let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1);

`

577

577

``

578

578

`// This case can currently arise only from functions marked

`

`@@ -588,8 +588,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

`

588

588

`return helper.funclet_br(self, bx, target, mergeable_succ);

`

589

589

`}

`

590

590

``

591

``

`-

// Pass the condition through llvm.expect for branch hinting.

`

592

``

`-

let cond = bx.expect(cond, expected);

`

``

591

`+

if bx.tcx().sess.opts.optimize != OptLevel::No {

`

``

592

`+

// Pass the condition through llvm.expect for branch hinting.

`

``

593

`+

cond = bx.expect(cond, expected);

`

``

594

`+

}

`

593

595

``

594

596

`// Create the failure block and the conditional branch to it.

`

595

597

`let lltarget = helper.llbb_with_cleanup(self, target);

`

`@@ -608,30 +610,40 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

`

608

610

`let location = self.get_caller_location(bx, terminator.source_info).immediate();

`

609

611

``

610

612

`// Put together the arguments to the panic entry point.

`

611

``

`-

let (lang_item, args) = match msg {

`

``

613

`+

let (lang_item, args, generic) = match msg {

`

612

614

`AssertKind::BoundsCheck { ref len, ref index } => {

`

613

615

`let len = self.codegen_operand(bx, len).immediate();

`

614

616

`let index = self.codegen_operand(bx, index).immediate();

`

615

617

`` // It's fn panic_bounds_check(index: usize, len: usize),

``

616

618

`` // and #[track_caller] adds an implicit third argument.

``

617

``

`-

(LangItem::PanicBoundsCheck, vec![index, len, location])

`

``

619

`+

(LangItem::PanicBoundsCheck, vec![index, len, location], None)

`

618

620

`}

`

619

621

`AssertKind::MisalignedPointerDereference { ref required, ref found } => {

`

620

622

`let required = self.codegen_operand(bx, required).immediate();

`

621

623

`let found = self.codegen_operand(bx, found).immediate();

`

622

624

`` // It's fn panic_misaligned_pointer_dereference(required: usize, found: usize),

``

623

625

`` // and #[track_caller] adds an implicit third argument.

``

624

``

`-

(LangItem::PanicMisalignedPointerDereference, vec![required, found, location])

`

``

626

`+

(LangItem::PanicMisalignedPointerDereference, vec![required, found, location], None)

`

``

627

`+

}

`

``

628

`+

AssertKind::OccupiedNiche { ref found, ref start, ref end } => {

`

``

629

`+

let found = self.codegen_operand(bx, found);

`

``

630

`+

let generic_arg = ty::GenericArg::from(found.layout.ty);

`

``

631

`+

let found = found.immediate();

`

``

632

`+

let start = self.codegen_operand(bx, start).immediate();

`

``

633

`+

let end = self.codegen_operand(bx, end).immediate();

`

``

634

`` +

// It's fn panic_occupied_niche<T>(found: T, start: T, end: T),

``

``

635

`` +

// and #[track_caller] adds an implicit fourth argument.

``

``

636

`+

(LangItem::PanicOccupiedNiche, vec![found, start, end, location], Some(generic_arg))

`

625

637

`}

`

626

638

` _ => {

`

627

639

`let msg = bx.const_str(msg.description());

`

628

640

`` // It's pub fn panic(expr: &str), with the wide reference being passed

``

629

641

`` // as two arguments, and #[track_caller] adds an implicit third argument.

``

630

``

`-

(LangItem::Panic, vec![msg.0, msg.1, location])

`

``

642

`+

(LangItem::Panic, vec![msg.0, msg.1, location], None)

`

631

643

`}

`

632

644

`};

`

633

645

``

634

``

`-

let (fn_abi, llfn) = common::build_langcall(bx, Some(span), lang_item);

`

``

646

`+

let (fn_abi, llfn) = common::build_langcall(bx, Some(span), lang_item, generic);

`

635

647

``

636

648

`// Codegen the actual panic invoke/call.

`

637

649

`let merging_succ = helper.do_call(self, bx, fn_abi, llfn, &args, None, unwind, &[], false);

`

`@@ -650,7 +662,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

`

650

662

`self.set_debug_loc(bx, terminator.source_info);

`

651

663

``

652

664

`// Obtain the panic entry point.

`

653

``

`-

let (fn_abi, llfn) = common::build_langcall(bx, Some(span), reason.lang_item());

`

``

665

`+

let (fn_abi, llfn) = common::build_langcall(bx, Some(span), reason.lang_item(), None);

`

654

666

``

655

667

`// Codegen the actual panic invoke/call.

`

656

668

`let merging_succ = helper.do_call(

`

`@@ -711,8 +723,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

`

711

723

`let msg = bx.const_str(&msg_str);

`

712

724

``

713

725

`// Obtain the panic entry point.

`

714

``

`-

let (fn_abi, llfn) =

`

715

``

`-

common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind);

`

``

726

`+

let (fn_abi, llfn) = common::build_langcall(

`

``

727

`+

bx,

`

``

728

`+

Some(source_info.span),

`

``

729

`+

LangItem::PanicNounwind,

`

``

730

`+

None,

`

``

731

`+

);

`

716

732

``

717

733

`// Codegen the actual panic invoke/call.

`

718

734

` helper.do_call(

`

`@@ -1586,7 +1602,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

`

1586

1602

``

1587

1603

`self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));

`

1588

1604

``

1589

``

`-

let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, reason.lang_item());

`

``

1605

`+

let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, reason.lang_item(), None);

`

1590

1606

`let fn_ty = bx.fn_decl_backend_type(&fn_abi);

`

1591

1607

``

1592

1608

`let llret = bx.call(fn_ty, None, Some(&fn_abi), fn_ptr, &[], funclet.as_ref());

`