-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[AVR] Correctly set the pointer address space when constructing pointers to functions #73270
Changes from all commits
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 |
---|---|---|
|
@@ -2166,16 +2166,31 @@ where | |
} | ||
|
||
fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<PointeeInfo> { | ||
match this.ty.kind { | ||
let addr_space_of_ty = |ty: Ty<'tcx>| { | ||
if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA } | ||
}; | ||
|
||
let pointee_info = match this.ty.kind { | ||
ty::RawPtr(mt) if offset.bytes() == 0 => { | ||
cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo { | ||
size: layout.size, | ||
align: layout.align.abi, | ||
safe: None, | ||
address_space: addr_space_of_ty(mt.ty), | ||
}) | ||
} | ||
ty::FnPtr(fn_sig) if offset.bytes() == 0 => { | ||
cx.layout_of(cx.tcx().mk_fn_ptr(fn_sig)).to_result().ok().map(|layout| { | ||
PointeeInfo { | ||
size: layout.size, | ||
align: layout.align.abi, | ||
Comment on lines
+2185
to
+2186
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. FWIW this makes very little sense. This sets the pointee size and alignment of function pointers to be the pointer size and alignment, i.e. on x86-64 this will be size 8 alignment 8, which is just completely wrong -- function pointers do not point to 8-aligned data. Luckily these two fields are, from what I can tell, completely unused if 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. Actually sounds like the entire approach of using |
||
safe: None, | ||
address_space: cx.data_layout().instruction_address_space, | ||
} | ||
}) | ||
} | ||
|
||
ty::Ref(_, ty, mt) if offset.bytes() == 0 => { | ||
let address_space = addr_space_of_ty(ty); | ||
let tcx = cx.tcx(); | ||
let is_freeze = ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env()); | ||
let kind = match mt { | ||
|
@@ -2210,6 +2225,7 @@ where | |
size: layout.size, | ||
align: layout.align.abi, | ||
safe: Some(kind), | ||
address_space, | ||
}) | ||
} | ||
|
||
|
@@ -2254,7 +2270,9 @@ where | |
result = field.to_result().ok().and_then(|field| { | ||
if ptr_end <= field_start + field.size { | ||
// We found the right field, look inside it. | ||
field.pointee_info_at(cx, offset - field_start) | ||
let field_info = | ||
field.pointee_info_at(cx, offset - field_start); | ||
field_info | ||
} else { | ||
None | ||
} | ||
|
@@ -2277,7 +2295,14 @@ where | |
|
||
result | ||
} | ||
} | ||
}; | ||
|
||
debug!( | ||
"pointee_info_at (offset={:?}, type kind: {:?}) => {:?}", | ||
offset, this.ty.kind, pointee_info | ||
); | ||
|
||
pointee_info | ||
} | ||
} | ||
|
||
|
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.
Can’t this just pass
this.ty
tolayout_of
?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.
Good suggestion, I have applied and amended into the original comment.