1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 #![allow(non_camel_case_types, non_snake_case)]
12 use rustc::ty::{self, Ty, TyCtxt};
13 use syntax_pos::{DUMMY_SP, Span};
15 use rustc::hir::def_id::DefId;
16 use rustc::middle::lang_items::LangItem;
21 use traits::BuilderMethods;
23 pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
24 ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
27 pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
28 ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
31 pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
32 ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
35 pub enum IntPredicate {
50 pub enum RealPredicate {
69 pub enum AtomicRmwBinOp {
83 pub enum AtomicOrdering {
88 // Consume, // Not specified yet.
92 SequentiallyConsistent,
95 pub enum SynchronizationScope {
96 // FIXME: figure out if this variant is needed at all.
103 #[derive(Copy, Clone, PartialEq, Debug)]
124 // FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
125 // the HashStable trait. Normally DepGraph::with_task() calls are
126 // hidden behind queries, but CGU creation is a special case in two
127 // ways: (1) it's not a query and (2) CGU are output nodes, so their
128 // Fingerprints are not actually needed. It remains to be clarified
129 // how exactly this case will be handled in the red/green system but
130 // for now we content ourselves with providing a no-op HashStable
131 // implementation for CGUs.
132 mod temp_stable_hash_impls {
133 use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
137 impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
138 fn hash_stable<W: StableHasherResult>(&self,
140 _: &mut StableHasher<W>) {
146 pub fn langcall(tcx: TyCtxt,
151 tcx.lang_items().require(li).unwrap_or_else(|s| {
152 let msg = format!("{} {}", msg, s);
154 Some(span) => tcx.sess.span_fatal(span, &msg[..]),
155 None => tcx.sess.fatal(&msg[..]),
160 // To avoid UB from LLVM, these two functions mask RHS with an
161 // appropriate mask unconditionally (i.e. the fallback behavior for
162 // all shifts). For 32- and 64-bit types, this matches the semantics
163 // of Java. (See related discussion on #1877 and #10183.)
165 pub fn build_unchecked_lshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
170 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
171 // #1877, #10183: Ensure that input is always valid
172 let rhs = shift_mask_rhs(bx, rhs);
176 pub fn build_unchecked_rshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
182 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
183 // #1877, #10183: Ensure that input is always valid
184 let rhs = shift_mask_rhs(bx, rhs);
185 let is_signed = lhs_t.is_signed();
193 fn shift_mask_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
197 let rhs_llty = bx.val_ty(rhs);
198 let shift_val = shift_mask_val(bx, rhs_llty, rhs_llty, false);
199 bx.and(rhs, shift_val)
202 pub fn shift_mask_val<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
208 let kind = bx.type_kind(llty);
210 TypeKind::Integer => {
211 // i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
212 let val = bx.int_width(llty) - 1;
214 bx.const_int(mask_llty, !val as i64)
216 bx.const_uint(mask_llty, val)
219 TypeKind::Vector => {
220 let mask = shift_mask_val(
222 bx.element_type(llty),
223 bx.element_type(mask_llty),
226 bx.vector_splat(bx.vector_length(mask_llty), mask)
228 _ => bug!("shift_mask_val: expected Integer or Vector, found {:?}", kind),