Skip to content

Commit 7bdf705

Browse files
committed
Avoid ICE when is_val_statically_known is not of a supported type
1 parent af08c64 commit 7bdf705

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ impl<'ll> CodegenCx<'ll, '_> {
909909
ifn!("llvm.is.constant.isize", fn(t_isize) -> i1);
910910
ifn!("llvm.is.constant.f32", fn(t_f32) -> i1);
911911
ifn!("llvm.is.constant.f64", fn(t_f64) -> i1);
912+
ifn!("llvm.is.constant.ptr", fn(ptr) -> i1);
912913

913914
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
914915
ifn!("llvm.eh.typeid.for", fn(ptr) -> t_i32);

compiler/rustc_codegen_llvm/src/intrinsic.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,18 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
119119
sym::likely => {
120120
self.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(true)])
121121
}
122-
sym::is_val_statically_known => self.call_intrinsic(
123-
&format!("llvm.is.constant.{:?}", args[0].layout.immediate_llvm_type(self.cx)),
124-
&[args[0].immediate()],
125-
),
122+
sym::is_val_statically_known => {
123+
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
124+
match self.type_kind(intrinsic_type) {
125+
TypeKind::Pointer | TypeKind::Integer | TypeKind::Float | TypeKind::Double => {
126+
self.call_intrinsic(
127+
&format!("llvm.is.constant.{:?}", intrinsic_type),
128+
&[args[0].immediate()],
129+
)
130+
}
131+
_ => self.const_bool(false),
132+
}
133+
}
126134
sym::unlikely => self
127135
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
128136
kw::Try => {

0 commit comments

Comments
 (0)