Skip to content

Commit 1efffe7

Browse files
committed
LLVMConstInt only allows integer types
1 parent 8f8bee4 commit 1efffe7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

compiler/rustc_codegen_llvm/src/common.rs

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_abi as abi;
55
use rustc_abi::Primitive::Pointer;
66
use rustc_abi::{AddressSpace, HasDataLayout};
77
use rustc_ast::Mutability;
8+
use rustc_codegen_ssa::common::TypeKind;
89
use rustc_codegen_ssa::traits::*;
910
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
1011
use rustc_hir::def_id::DefId;
@@ -146,6 +147,10 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
146147
}
147148

148149
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
150+
debug_assert!(
151+
self.type_kind(t) == TypeKind::Integer,
152+
"only allows integer types in const_int"
153+
);
149154
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
150155
}
151156

@@ -176,10 +181,18 @@ impl<'ll, 'tcx> ConstCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
176181
}
177182

178183
fn const_uint(&self, t: &'ll Type, i: u64) -> &'ll Value {
184+
debug_assert!(
185+
self.type_kind(t) == TypeKind::Integer,
186+
"only allows integer types in const_uint"
187+
);
179188
unsafe { llvm::LLVMConstInt(t, i, False) }
180189
}
181190

182191
fn const_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
192+
debug_assert!(
193+
self.type_kind(t) == TypeKind::Integer,
194+
"only allows integer types in const_uint_big"
195+
);
183196
unsafe {
184197
let words = [u as u64, (u >> 64) as u64];
185198
llvm::LLVMConstIntOfArbitraryPrecision(t, 2, words.as_ptr())

0 commit comments

Comments
 (0)