-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promoteds are statics and statics have a place, not just a value #52597
Changes from all commits
de51143
62581b8
2aab6af
4fba7d3
ac54b74
be92f9d
cbd4274
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -507,14 +507,40 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { | |
// promotes any complex rvalues to constants. | ||
if i == 2 && intrinsic.unwrap().starts_with("simd_shuffle") { | ||
match *arg { | ||
// The shuffle array argument is usually not an explicit constant, | ||
// but specified directly in the code. This means it gets promoted | ||
// and we can then extract the value by evaluating the promoted. | ||
mir::Operand::Copy(mir::Place::Promoted(box(index, ty))) | | ||
mir::Operand::Move(mir::Place::Promoted(box(index, ty))) => { | ||
let param_env = ty::ParamEnv::reveal_all(); | ||
let cid = mir::interpret::GlobalId { | ||
instance: self.instance, | ||
promoted: Some(index), | ||
}; | ||
let c = bx.tcx().const_eval(param_env.and(cid)); | ||
let (llval, ty) = self.simd_shuffle_indices( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SIMD shuffle indices are an array, which usually is specified inline, and not via an explicit constant. so the array is promoted and we need to read it here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. A comment to that effect would be great. |
||
&bx, | ||
terminator.source_info.span, | ||
ty, | ||
c, | ||
); | ||
return OperandRef { | ||
val: Immediate(llval), | ||
layout: bx.cx.layout_of(ty), | ||
}; | ||
|
||
}, | ||
mir::Operand::Copy(_) | | ||
mir::Operand::Move(_) => { | ||
span_bug!(span, "shuffle indices must be constant"); | ||
} | ||
mir::Operand::Constant(ref constant) => { | ||
let c = self.eval_mir_constant(&bx, constant); | ||
let (llval, ty) = self.simd_shuffle_indices( | ||
&bx, | ||
constant, | ||
constant.span, | ||
constant.ty, | ||
c, | ||
); | ||
return OperandRef { | ||
val: Immediate(llval), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use llvm::{ValueRef, LLVMConstInBoundsGEP}; | ||
use llvm::ValueRef; | ||
use rustc::mir::interpret::ConstEvalErr; | ||
use rustc::mir; | ||
use rustc::mir::interpret::ConstValue; | ||
|
@@ -22,14 +22,12 @@ use common::{CodegenCx, C_undef, C_usize}; | |
use builder::{Builder, MemFlags}; | ||
use value::Value; | ||
use type_of::LayoutLlvmExt; | ||
use type_::Type; | ||
use consts; | ||
|
||
use std::fmt; | ||
use std::ptr; | ||
|
||
use super::{FunctionCx, LocalRef}; | ||
use super::constant::{scalar_to_llvm, const_alloc_to_llvm}; | ||
use super::constant::scalar_to_llvm; | ||
use super::place::PlaceRef; | ||
|
||
/// The representation of a Rust value. The enum variant is in fact | ||
|
@@ -139,16 +137,7 @@ impl<'a, 'tcx> OperandRef<'tcx> { | |
OperandValue::Pair(a_llval, b_llval) | ||
}, | ||
ConstValue::ByRef(alloc, offset) => { | ||
let init = const_alloc_to_llvm(bx.cx, alloc); | ||
let base_addr = consts::addr_of(bx.cx, init, layout.align, "byte_str"); | ||
|
||
let llval = unsafe { LLVMConstInBoundsGEP( | ||
consts::bitcast(base_addr, Type::i8p(bx.cx)), | ||
&C_usize(bx.cx, offset.bytes()), | ||
1, | ||
)}; | ||
let llval = consts::bitcast(llval, layout.llvm_type(bx.cx).ptr_to()); | ||
return Ok(PlaceRef::new_sized(llval, layout, alloc.align).load(bx)); | ||
return Ok(PlaceRef::from_const_alloc(bx, layout, alloc, offset).load(bx)); | ||
}, | ||
}; | ||
|
||
|
@@ -409,20 +398,12 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { | |
self.eval_mir_constant(bx, constant) | ||
.and_then(|c| OperandRef::from_const(bx, c)) | ||
.unwrap_or_else(|err| { | ||
match constant.literal { | ||
mir::Literal::Promoted { .. } => { | ||
// this is unreachable as long as runtime | ||
// and compile-time agree on values | ||
// With floats that won't always be true | ||
// so we generate an abort below | ||
}, | ||
mir::Literal::Value { .. } => { | ||
err.report_as_error( | ||
bx.tcx().at(constant.span), | ||
"could not evaluate constant operand", | ||
); | ||
}, | ||
} | ||
err.report_as_error( | ||
bx.tcx().at(constant.span), | ||
"could not evaluate constant operand", | ||
); | ||
// Allow RalfJ to sleep soundly knowing that even refactorings that remove | ||
// the above error (or silence it under some conditions) will not cause UB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
let fnname = bx.cx.get_intrinsic(&("llvm.trap")); | ||
bx.call(fnname, &[], None); | ||
// We've errored, so we don't have to produce working code. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be something like
self.param_env
(minor future hazard if we start deduplicating instances).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR already landed.Does anyone take care of fixing this?^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rustc_codegen_llvm... we don't have a param env, everything is monomorphized