use GEP inbounds for ZST and DST field offsets
For the former, it's fine for `inbounds` offsets to be one-past-the-end, so it's okay even if the ZST is the last field in the layout: > The base pointer has an in bounds address of an allocated object, > which means that it points into an allocated object, or to its end. https://llvm.org/docs/LangRef.html#getelementptr-instruction For the latter, even DST fields must always be inside the layout (or to its end for ZSTs), so using inbounds is also fine there.
This commit is contained in:
parent
7606c13961
commit
8ebd307d2a
3 changed files with 73 additions and 9 deletions
|
@ -104,10 +104,6 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
|
|||
let mut simple = || {
|
||||
let llval = if offset.bytes() == 0 {
|
||||
self.llval
|
||||
} else if field.is_zst() {
|
||||
// FIXME(erikdesjardins): it should be fine to use inbounds for ZSTs too;
|
||||
// keeping this logic for now to preserve previous behavior.
|
||||
bx.ptradd(self.llval, bx.const_usize(offset.bytes()))
|
||||
} else {
|
||||
bx.inbounds_ptradd(self.llval, bx.const_usize(offset.bytes()))
|
||||
};
|
||||
|
@ -168,8 +164,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
|
|||
debug!("struct_field_ptr: DST field offset: {:?}", offset);
|
||||
|
||||
// Adjust pointer.
|
||||
// FIXME(erikdesjardins): should be able to use inbounds here too.
|
||||
let ptr = bx.ptradd(self.llval, offset);
|
||||
let ptr = bx.inbounds_ptradd(self.llval, offset);
|
||||
|
||||
PlaceRef { llval: ptr, llextra: self.llextra, layout: field, align: effective_field_align }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue