1 #![allow(non_camel_case_types, non_snake_case)]
3 use rustc::session::Session;
4 use rustc::ty::{Ty, TyCtxt};
5 use rustc_errors::struct_span_err;
10 use rustc::middle::lang_items::LangItem;
11 use rustc_hir::def_id::DefId;
13 use crate::traits::BuilderMethods;
16 use rustc_error_codes::*;
18 pub enum IntPredicate {
32 pub enum RealPredicate {
51 pub enum AtomicRmwBinOp {
65 pub enum AtomicOrdering {
70 // Consume, // Not specified yet.
74 SequentiallyConsistent,
77 pub enum SynchronizationScope {
78 // FIXME: figure out if this variant is needed at all.
85 #[derive(Copy, Clone, PartialEq, Debug)]
106 // FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
107 // the HashStable trait. Normally DepGraph::with_task() calls are
108 // hidden behind queries, but CGU creation is a special case in two
109 // ways: (1) it's not a query and (2) CGU are output nodes, so their
110 // Fingerprints are not actually needed. It remains to be clarified
111 // how exactly this case will be handled in the red/green system but
112 // for now we content ourselves with providing a no-op HashStable
113 // implementation for CGUs.
114 mod temp_stable_hash_impls {
115 use crate::ModuleCodegen;
116 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
118 impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
119 fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) {
125 pub fn langcall(tcx: TyCtxt<'_>, span: Option<Span>, msg: &str, li: LangItem) -> DefId {
126 tcx.lang_items().require(li).unwrap_or_else(|s| {
127 let msg = format!("{} {}", msg, s);
129 Some(span) => tcx.sess.span_fatal(span, &msg[..]),
130 None => tcx.sess.fatal(&msg[..]),
135 // To avoid UB from LLVM, these two functions mask RHS with an
136 // appropriate mask unconditionally (i.e., the fallback behavior for
137 // all shifts). For 32- and 64-bit types, this matches the semantics
138 // of Java. (See related discussion on #1877 and #10183.)
140 pub fn build_unchecked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
145 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
146 // #1877, #10183: Ensure that input is always valid
147 let rhs = shift_mask_rhs(bx, rhs);
151 pub fn build_unchecked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
157 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
158 // #1877, #10183: Ensure that input is always valid
159 let rhs = shift_mask_rhs(bx, rhs);
160 let is_signed = lhs_t.is_signed();
161 if is_signed { bx.ashr(lhs, rhs) } else { bx.lshr(lhs, rhs) }
164 fn shift_mask_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
168 let rhs_llty = bx.val_ty(rhs);
169 let shift_val = shift_mask_val(bx, rhs_llty, rhs_llty, false);
170 bx.and(rhs, shift_val)
173 pub fn shift_mask_val<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
179 let kind = bx.type_kind(llty);
181 TypeKind::Integer => {
182 // i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
183 let val = bx.int_width(llty) - 1;
185 bx.const_int(mask_llty, !val as i64)
187 bx.const_uint(mask_llty, val)
190 TypeKind::Vector => {
192 shift_mask_val(bx, bx.element_type(llty), bx.element_type(mask_llty), invert);
193 bx.vector_splat(bx.vector_length(mask_llty), mask)
195 _ => bug!("shift_mask_val: expected Integer or Vector, found {:?}", kind),
199 pub fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) {
200 struct_span_err!(a, b, E0511, "{}", c).emit();